@univerjs/sheets-ui 0.6.0-nightly.202502041606 → 0.6.0-nightly.202502051606

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,4 +1,4 @@
1
- "use strict";var hd=Object.defineProperty;var md=(n,i,e)=>i in n?hd(n,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[i]=e;var R=(n,i,e)=>md(n,typeof i!="symbol"?i+"":i,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const J=require("@univerjs/docs-ui"),a=require("@univerjs/core"),w=require("@univerjs/engine-render"),E=require("@univerjs/ui"),V=require("react"),O=require("rxjs"),m=require("@univerjs/sheets"),be=require("@univerjs/docs"),G=require("@univerjs/engine-formula"),gd=require("@univerjs/engine-numfmt"),K=require("@univerjs/design"),_=require("react/jsx-runtime"),Sd=require("@univerjs/telemetry"),Ba=require("rxjs/operators");function Ei(n,i){if(n==null)return;const e=i.getRenderById(n);if(e==null)return;const{mainComponent:t,scene:r,engine:o,components:s}=e,l=t,d=s.get(J.DOCS_VIEW_KEY.BACKGROUND);return{document:l,docBackground:d,scene:r,engine:o}}const Ao=[10,400],ss="RANGE_SELECTOR_COMPONENT_KEY",Ti="EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY";var he=(n=>(n.MAIN="__SpreadsheetRender__",n.ROW="__SpreadsheetRowHeader__",n.COLUMN="__SpreadsheetColumnHeader__",n.LEFT_TOP="__SpreadsheetLeftTopPlaceholder__",n))(he||{});const Ws=0,Qr=1,bt=10,fd=11,Us=12,wi={id:"sheet.command.set-row-header-width",type:a.CommandType.COMMAND,handler:async(n,i)=>{if(!i)return!1;const e=n.get(w.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:r,size:o}=i,s=e.getRenderById(t);if(s){e.getRenderById(t).with(exports.SheetSkeletonManagerService).setRowHeaderSize(s,r,o);const{components:d}=s,c=d.get(he.ROW);c&&c.setCustomHeader({headerStyle:{size:o}})}return!0}},yi={id:"sheet.command.set-col-header-height",type:a.CommandType.COMMAND,handler:async(n,i)=>{if(!i)return!1;const e=n.get(w.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:r,size:o}=i,s=e.getRenderById(t);if(s){e.getRenderById(t).with(exports.SheetSkeletonManagerService).setColumnHeaderSize(s,r,o);const{components:d}=s,c=d.get(he.COLUMN);c&&c.setCustomHeader({headerStyle:{size:o}})}return!0}},No=a.createInterceptorKey("rangeMovePermissionCheck"),Do=a.createInterceptorKey("rangeFillPermissionCheck");var as=(n=>(n[n.FORMULA_EDITOR_SHOW=100]="FORMULA_EDITOR_SHOW",n[n.MARK_SELECTION=1e4]="MARK_SELECTION",n))(as||{});function Rt(n){const i=n.getCurrentTheme(),e=new a.ColorKit(i.primaryColor).setAlpha(.07).toRgbString();return{strokeWidth:1,stroke:i.primaryColor,fill:e,widgets:{},widgetSize:6,widgetStrokeWidth:1,widgetStroke:i.colorWhite,autofillSize:6,autofillStrokeWidth:1,autofillStroke:i.colorWhite,rowHeaderFill:e,rowHeaderStroke:i.primaryColor,rowHeaderStrokeWidth:1,columnHeaderFill:e,columnHeaderStroke:i.primaryColor,columnHeaderStrokeWidth:1,expandCornerSize:40}}class pd{constructor(){R(this,"_startColumn",-1);R(this,"_startRow",-1);R(this,"_endColumn",-1);R(this,"_endRow",-1);R(this,"_startX",0);R(this,"_startY",0);R(this,"_endX",0);R(this,"_endY",0);R(this,"_primary");R(this,"_rangeType",a.RANGE_TYPE.NORMAL)}get startColumn(){return this._startColumn}get startRow(){return this._startRow}get endColumn(){return this._endColumn}get endRow(){return this._endRow}get startX(){return this._startX}get startY(){return this._startY}get endX(){return this._endX}get endY(){return this._endY}get currentCell(){return this._primary}get rangeType(){return this._rangeType}isEqual(i){const{startColumn:e,startRow:t,endColumn:r,endRow:o}=this,{startColumn:s,startRow:l,endColumn:d,endRow:c}=i;return e===s&&t===l&&r===d&&o===c}isInclude(i){const{startColumn:e,startRow:t,endColumn:r,endRow:o}=this,{startColumn:s,startRow:l,endColumn:d,endRow:c}=i;return!(d<e||s>r||l>o||c<t)}highlightToSelection(){if(this._primary)return a.convertCellToRange(this._primary)}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._primary}getRangeType(){return this._rangeType}setRangeType(i){this._rangeType=i}getValue(){return{rangeWithCoord:this.getRange(),primaryWithCoord:this._primary}}setValue(i,e){const{startColumn:t,startRow:r,endColumn:o,endRow:s,startX:l,startY:d,endX:c,endY:u,rangeType:h}=i;this._startColumn=t,this._startRow=r,this._endColumn=o,this._endRow=s,this._startX=l,this._startY=d,this._endX=c,this._endY=u,h!==void 0&&(this._rangeType=h),e!==void 0&&this.setCurrentCell(e)}setCurrentCell(i){this._primary=i}clearCurrentCell(){this._primary=null}}function In(n,i){const{startRow:e,startColumn:t,endRow:r,endColumn:o,rangeType:s}=i,l=r<e?r:e,d=r<e?e:r,c=o<t?o:t,u=o<t?t:o,h=n.getNoMergeCellPositionByIndex(l,c),g=n.getNoMergeCellPositionByIndex(d,u);return{startRow:e,startColumn:t,endRow:r,endColumn:o,rangeType:s,startY:(h==null?void 0:h.startY)||0,endY:(g==null?void 0:g.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(g==null?void 0:g.endX)||0}}function Me(n,i){const{range:e,primary:t,style:r}=n,o=In(i,e),s=t&&Qn(i,t);return{rangeWithCoord:o,primaryWithCoord:s,style:r}}function Qn(n,i){const{actualRow:e,actualColumn:t,isMerged:r,isMergedMainCell:o,startRow:s,startColumn:l,endRow:d,endColumn:c}=i,u=n.getNoMergeCellPositionByIndex(e,t),h=n.getNoMergeCellPositionByIndex(s,l),g=n.getNoMergeCellPositionByIndex(d,c);return{actualRow:e,actualColumn:t,isMerged:r,isMergedMainCell:o,startX:u.startX,startY:u.startY,endX:u.endX,endY:u.endY,mergeInfo:{startRow:s,startColumn:l,endRow:d,endColumn:c,startY:(h==null?void 0:h.startY)||0,endY:(g==null?void 0:g.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(g==null?void 0:g.endX)||0}}}const Ls="__SpreadsheetHelperSelectionTempRect",vd=35;class Fa{constructor(i,e){R(this,"_startOffsetX",0);R(this,"_startOffsetY",0);R(this,"_relativeSelectionPositionRow",0);R(this,"_relativeSelectionPositionColumn",0);R(this,"_relativeSelectionRowLength",0);R(this,"_relativeSelectionColumnLength",0);R(this,"_scenePointerMoveSub");R(this,"_scenePointerUpSub");R(this,"_helperSelection");R(this,"_scrollTimer");R(this,"_activeViewport");R(this,"_targetSelection",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});R(this,"_isInMergeState",!1);R(this,"_fillControlColors",[]);R(this,"_skeleton");R(this,"_scene");R(this,"_themeService");R(this,"_injector");R(this,"_selectionHooks");this._control=i,this._skeleton=e.skeleton,this._scene=e.scene,this._themeService=e.themeService,this._injector=e.injector,this._selectionHooks=e.selectionHooks,this._initialControl(),this._initialWidget(),this._initialAutoFill(),this._control.dispose$.subscribe(()=>{this.dispose()})}get isHelperSelection(){return this._control.isHelperSelection}dispose(){var i,e;(i=this._scrollTimer)==null||i.dispose(),this._fillControlColors=[],this._clearObserverEvent(),(e=this._helperSelection)==null||e.dispose()}_getFreeze(){var t,r;return(r=(t=this._injector.get(w.IRenderManagerService).withCurrentTypeOfUnit(a.UniverInstanceType.UNIVER_SHEET,exports.SheetSkeletonManagerService))==null?void 0:t.getCurrent())==null?void 0:r.skeleton.getWorksheetConfig().freeze}_isSelectionInViewport(i,e){const t=this._getFreeze()||{startRow:-1,startColumn:-1,xSplit:0,ySplit:0};switch(e.viewportKey){case w.SHEET_VIEWPORT_KEY.VIEW_MAIN:return i.endRow>=t.startRow&&i.endColumn>=t.startColumn;case w.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP:case w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT:return i.endColumn>=t.startColumn&&i.startRow<t.startRow;case w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT:case w.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM:return i.endRow>=t.startRow&&i.startColumn<t.startColumn;case w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP:case w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT:case w.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP:case w.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP:return i.startRow<t.startRow&&i.startColumn<t.startColumn}}_clearObserverEvent(){var i,e;(i=this._scenePointerMoveSub)==null||i.unsubscribe(),(e=this._scenePointerUpSub)==null||e.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null}_initialControl(){const{leftControl:i,rightControl:e,topControl:t,bottomControl:r}=this._control;[i,e,t,r].forEach(o=>{o.onPointerEnter$.subscribeEvent(()=>{var l;((l=this._injector.get(ve,a.Quantity.OPTIONAL))==null?void 0:l.interceptor.fetchThroughInterceptors(No)(!1,null))!==!1&&o.setCursor(w.CURSOR_TYPE.MOVE)}),o.onPointerLeave$.subscribeEvent(()=>{o.resetCursor()}),o.onPointerDown$.subscribeEvent(this._controlPointerDownHandler.bind(this))})}_controlMoving(i,e){var A;const t=this._scene,r=t.getScrollXYInfoByViewport(w.Vector2.FromArray([i,e])),{scaleX:o,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(i,e,o,s,r),{row:d,column:c}=l,u=this._skeleton.getRowCount()-1,h=this._skeleton.getColumnCount()-1;let g=Math.max(0,d+this._relativeSelectionPositionRow),S=g+this._relativeSelectionRowLength;S>u&&(S=u,S-g<this._relativeSelectionRowLength&&(g=S-this._relativeSelectionRowLength));let f=Math.max(0,c+this._relativeSelectionPositionColumn),p=f+this._relativeSelectionColumnLength;p>h&&(p=h,p-f<this._relativeSelectionColumnLength&&(f=p-this._relativeSelectionColumnLength));const v=this._skeleton.worksheet.getCellInfoInMergeData(g,f),I=Me({range:{startRow:g,endRow:S,startColumn:f,endColumn:p},primary:v,style:null},this._skeleton),b=this._skeleton.getNoMergeCellPositionByIndex(g,f),T=this._skeleton.getNoMergeCellPositionByIndex(S,p),M=(b==null?void 0:b.startY)||0,y=(T==null?void 0:T.endY)||0,P=(b==null?void 0:b.startX)||0,x=(T==null?void 0:T.endX)||0;(A=this._helperSelection)==null||A.transformByState({left:P,top:M,width:x-P,height:y-M}),this._targetSelection={...I.rangeWithCoord},this._control.selectionMoving$.next(I.rangeWithCoord)}_controlPointerDownHandler(i){const{offsetX:e,offsetY:t}=i,r=this._scene,o=r.getCoordRelativeToViewport(w.Vector2.FromArray([e,t])),{x:s,y:l}=o,d=r.getScrollXYInfoByViewport(o),{scaleX:c,scaleY:u}=r.getAncestorScale(),h=this._skeleton.getCellIndexByOffset(s,l,c,u,d);this._startOffsetX=s,this._startOffsetY=l;const{row:g,column:S}=h,{startRow:f,startColumn:p,endRow:v,endColumn:C}=this._control.model;let I=0,b=0;g<f?I-=1:g>v&&(I+=1),S<p?b-=1:S>C&&(b+=1),this._relativeSelectionPositionRow=f-g+I,this._relativeSelectionPositionColumn=p-S+b,this._relativeSelectionRowLength=v-f,this._relativeSelectionColumnLength=C-p;const T=this._control.currentStyle,M=this._getScale();this.isHelperSelection&&(this._helperSelection=new w.Rect(Ls,{stroke:T.stroke,strokeWidth:T.strokeWidth/M}),r.addObject(this._helperSelection));const y=r.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN),P=w.ScrollTimer.create(r);this._scrollTimer=P,P.startScroll(s,l,y),r.disableObjectsEvent(),this._scenePointerMoveSub=r.onPointerMove$.subscribeEvent(x=>{var k;const{offsetX:A,offsetY:N}=x;if(((k=this._injector.get(ve,a.Quantity.OPTIONAL))==null?void 0:k.interceptor.fetchThroughInterceptors(No)(!1,null))===!1)return;const{x:H,y:W}=r.getCoordRelativeToViewport(w.Vector2.FromArray([A,N]));this._controlMoving(H,W),r.setCursor(w.CURSOR_TYPE.MOVE),P.scrolling(H,W,()=>{this._controlMoving(H,W)})}),this._scenePointerUpSub=r.onPointerUp$.subscribeEvent(()=>{var A,N,D,H;(A=this._helperSelection)==null||A.dispose();const x=this._scene;x.resetCursor(),this._clearObserverEvent(),x.enableObjectsEvent(),(N=this._scrollTimer)==null||N.dispose(),this._control.selectionMoveEnd$.next(this._targetSelection),(H=(D=this._selectionHooks).selectionMoveEnd)==null||H.call(D)})}_initialWidget(){const{topLeftWidget:i,topCenterWidget:e,topRightWidget:t,middleLeftWidget:r,middleRightWidget:o,bottomLeftWidget:s,bottomCenterWidget:l,bottomRightWidget:d}=this._control,c=[w.CURSOR_TYPE.NORTH_WEST_RESIZE,w.CURSOR_TYPE.NORTH_RESIZE,w.CURSOR_TYPE.NORTH_EAST_RESIZE,w.CURSOR_TYPE.WEST_RESIZE,w.CURSOR_TYPE.EAST_RESIZE,w.CURSOR_TYPE.SOUTH_WEST_RESIZE,w.CURSOR_TYPE.SOUTH_RESIZE,w.CURSOR_TYPE.SOUTH_EAST_RESIZE];[i,e,t,r,o,s,l,d].forEach((u,h)=>{u.onPointerEnter$.subscribeEvent(()=>{u.setCursor(c[h])}),u.onPointerLeave$.subscribeEvent(()=>{u.resetCursor()}),u.onPointerDown$.subscribeEvent(g=>{this._widgetPointerDownEvent(g,c[h])})})}_widgetPointerDownEvent(i,e){const t=this._scene,{offsetX:r,offsetY:o}=i,s=t.getCoordRelativeToViewport(w.Vector2.FromArray([r,o])),{x:l,y:d}=s;this._startOffsetX=r,this._startOffsetY=o;const{startRow:c,startColumn:u,endRow:h,endColumn:g}=this._control.model,S=Math.min(c,h),f=Math.min(u,g),p=Math.max(c,h),v=Math.max(u,g);this._relativeSelectionPositionRow=S,this._relativeSelectionPositionColumn=f,this._relativeSelectionRowLength=p-S,this._relativeSelectionColumnLength=v-f,e===w.CURSOR_TYPE.NORTH_WEST_RESIZE?(this._relativeSelectionPositionRow=p,this._relativeSelectionPositionColumn=v):e===w.CURSOR_TYPE.NORTH_RESIZE?this._relativeSelectionPositionRow=p:e===w.CURSOR_TYPE.NORTH_EAST_RESIZE?this._relativeSelectionPositionRow=p:e===w.CURSOR_TYPE.WEST_RESIZE?this._relativeSelectionPositionColumn=v:e===w.CURSOR_TYPE.SOUTH_WEST_RESIZE?this._relativeSelectionPositionColumn=v:e===w.CURSOR_TYPE.SOUTH_RESIZE&&(this._relativeSelectionPositionRow=S);const C=w.ScrollTimer.create(t),I=t.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);C.startScroll(l,d,I),this._scrollTimer=C,t.disableObjectsEvent(),this._scenePointerMoveSub=t.onPointerMove$.subscribeEvent(b=>{const{offsetX:T,offsetY:M}=b,{x:y,y:P}=t.getCoordRelativeToViewport(w.Vector2.FromArray([T,M]));this._widgetMoving(y,P,e),t.setCursor(e),C.scrolling(y,P,()=>{this._widgetMoving(y,P,e)})}),this._scenePointerUpSub=t.onPointerUp$.subscribeEvent(()=>{var T,M,y;const b=this._scene;b.resetCursor(),this._clearObserverEvent(),b.enableObjectsEvent(),(T=this._scrollTimer)==null||T.dispose(),this._control.selectionScaled$.next(this._targetSelection),(y=(M=this._selectionHooks).selectionMoveEnd)==null||y.call(M)})}_widgetMoving(i,e,t){const r=this._scene,o=r.getScrollXYInfoByViewport(w.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:s,scaleY:l}=r.getAncestorScale(),d=this._skeleton.getCellIndexByOffset(i,e,s,l,o),{row:c,column:u}=d;let h=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,S=c,f=u;t===w.CURSOR_TYPE.NORTH_WEST_RESIZE?(h=c,g=u,S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn):t===w.CURSOR_TYPE.NORTH_RESIZE?(h=c,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength):t===w.CURSOR_TYPE.NORTH_EAST_RESIZE?(h=c,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,f=u):t===w.CURSOR_TYPE.WEST_RESIZE?(h=this._relativeSelectionPositionRow,g=u,S=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,f=this._relativeSelectionPositionColumn):t===w.CURSOR_TYPE.EAST_RESIZE?S=this._relativeSelectionPositionRow+this._relativeSelectionRowLength:t===w.CURSOR_TYPE.SOUTH_WEST_RESIZE?(h=this._relativeSelectionPositionRow,g=u,S=c,f=this._relativeSelectionPositionColumn):t===w.CURSOR_TYPE.SOUTH_RESIZE&&(h=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,S=c,f=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength);const p=this._swapPositions(h,g,S,f),v=this._skeleton.getCellWithMergeInfoByIndex(h,g),I=Me({range:p,primary:v,style:null},this._skeleton);this._targetSelection={...I.rangeWithCoord},this._control.updateRangeBySelectionWithCoord(I),this._control.selectionScaling$.next(this._targetSelection)}_initialAutoFill(){const{fillControl:i}=this._control;i.onPointerEnter$.subscribeEvent(e=>{this._injector.get(ve).interceptor.fetchThroughInterceptors(Do)(!1,{x:e.offsetX,y:e.offsetY,skeleton:this._skeleton,scene:this._scene})&&i.setCursor(w.CURSOR_TYPE.CROSSHAIR)}),i.onPointerLeave$.subscribeEvent(()=>{i.resetCursor()}),i.onPointerDown$.subscribeEvent(this._autoFillForPointerdown.bind(this))}_autoFillMoving(i,e){var N,D,H;const t=this._scene,r=t.getViewportScrollXY(this._activeViewport),{scaleX:o,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(i,e,o,s,r),{row:d,column:c}=l,u=t.getCoordRelativeToViewport(w.Vector2.FromArray([i,e])),h=this._skeleton.getRowCount()-1,g=this._skeleton.getColumnCount()-1;let S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn,p=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,v=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength,C=!1,I=!0;if((c<f||c>v)&&d>=S&&d<=p){const W=this._fillRuler(c,f,v,this._relativeSelectionColumnLength,g);f=W.startRowOrColumn,v=W.endRowOrColumn,C=W.isLighten,I=!1}else if((d<S||d>p)&&c>=f&&c<=v){const W=this._fillRuler(d,S,p,this._relativeSelectionRowLength,h);S=W.startRowOrColumn,p=W.endRowOrColumn,C=W.isLighten}else if(Math.abs(this._startOffsetX-u.x-r.x)/2>Math.abs(this._startOffsetY-u.y-r.y)){const W=this._fillRuler(c,f,v,this._relativeSelectionColumnLength,g);f=W.startRowOrColumn,v=W.endRowOrColumn,C=W.isLighten,I=!1}else{const W=this._fillRuler(d,S,p,this._relativeSelectionRowLength,h);S=W.startRowOrColumn,p=W.endRowOrColumn,C=W.isLighten}const b=this._skeleton.getNoMergeCellPositionByIndex(S,f),T=this._skeleton.getNoMergeCellPositionByIndex(p,v),M=(b==null?void 0:b.startY)||0,y=(T==null?void 0:T.endY)||0,P=(b==null?void 0:b.startX)||0,x=(T==null?void 0:T.endX)||0;C?this._controlHandler((W,k)=>{const U=new a.ColorKit(this._fillControlColors[k]).lighten(vd).toRgbString();W.setProps({fill:U})}):this._controlHandler((W,k)=>{W.setProps({fill:this._fillControlColors[k]})});const A=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();S===p&&I===!0||f===v&&I===!1?(N=this._helperSelection)==null||N.hide():((D=this._helperSelection)==null||D.transformByState({left:P-A/2,top:M-A/2,width:x-P,height:y-M}),(H=this._helperSelection)==null||H.show()),this._targetSelection={startY:M,endY:y,startX:P,endX:x,startRow:S,endRow:p,startColumn:f,endColumn:v},this._control.selectionFilling$.next(this._targetSelection)}_autoFillForPointerdown(i){const{offsetX:e,offsetY:t}=i,r=this._scene,o=r.getCoordRelativeToViewport(w.Vector2.FromArray([e,t])),{x:s,y:l}=o;this._startOffsetX=s,this._startOffsetY=l;const{startRow:d,startColumn:c,endRow:u,endColumn:h}=this._control.model;this._isInMergeState=this._hasMergeInRange(d,c,u,h),this._relativeSelectionPositionRow=d,this._relativeSelectionPositionColumn=c,this._relativeSelectionRowLength=u-d,this._relativeSelectionColumnLength=h-c;const g=this._control.currentStyle;let S=g==null?void 0:g.stroke,f=g==null?void 0:g.strokeWidth;const p=Rt(this._themeService);S==null&&(S=p.stroke),f==null&&(f=p.strokeWidth);const v=this._getScale();f/=v;const C=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/v,I=new a.ColorKit(S).darken(2).toRgbString();this.isHelperSelection&&(this._helperSelection=new w.Rect(Ls,{stroke:I,strokeWidth:f+C/2}),r.addObject(this._helperSelection)),this._activeViewport=r.getActiveViewportByCoord(w.Vector2.FromArray([e,t]));const b=r.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN),T=w.ScrollTimer.create(r,this._activeViewport.viewportKey===w.SHEET_VIEWPORT_KEY.VIEW_MAIN?w.ScrollTimerType.ALL:w.ScrollTimerType.NONE);T.startScroll(s,l,b),this._scrollTimer=T,r.disableObjectsEvent(),this._controlHandler(M=>{this._fillControlColors.push(M.fill)}),this._scenePointerMoveSub=r.onPointerMove$.subscribeEvent(M=>{var W;const{offsetX:y,offsetY:P}=M,x=r.getActiveViewportByCoord(w.Vector2.FromArray([y,P]));if(!this._injector.get(ve).interceptor.fetchThroughInterceptors(Do)(!1,{x:i.offsetX,y:i.offsetY,skeleton:this._skeleton,scene:this._scene}))return;const{x:N,y:D}=r.getCoordRelativeToViewport(w.Vector2.FromArray([y,P]));this._autoFillMoving(N,D),r.setCursor(w.CURSOR_TYPE.CROSSHAIR);const H=this._targetSelection;if(b&&x&&((W=this._activeViewport)==null?void 0:W.viewportKey)!==(x==null?void 0:x.viewportKey)){let k;H.startRow!==d?(T.scrollTimerType=w.ScrollTimerType.Y,k={...H,endRow:H.startRow}):H.endRow!==u?(T.scrollTimerType=w.ScrollTimerType.Y,k={...H,startRow:H.endRow}):H.startColumn!==c?(T.scrollTimerType=w.ScrollTimerType.X,k={...H,endColumn:H.startColumn}):(T.scrollTimerType=w.ScrollTimerType.X,k={...H,startColumn:H.endColumn}),this._isSelectionInViewport(k,x)&&(b.scrollToBarPos({x:T.scrollTimerType===w.ScrollTimerType.X?0:void 0,y:T.scrollTimerType===w.ScrollTimerType.Y?0:void 0}),this._activeViewport=x)}T.scrolling(N,D,()=>{this._autoFillMoving(N,D)})}),this._scenePointerUpSub=r.onPointerUp$.subscribeEvent(()=>{var y,P;(y=this._helperSelection)==null||y.dispose();const M=this._scene;M.resetCursor(),this._clearObserverEvent(),M.enableObjectsEvent(),(P=this._scrollTimer)==null||P.dispose(),this._control.refreshSelectionFilled(this._targetSelection),this._isInMergeState=!1,this._controlHandler((x,A)=>{x.setProps({fill:this._fillControlColors[A]})}),this._fillControlColors=[]})}_hasMergeInRange(i,e,t,r){return this._skeleton.worksheet.getMergedCellRange(i,e,t,r).length>0}_swapPositions(i,e,t,r){const o=Math.min(i,t),s=Math.min(e,r),l=Math.max(i,t),d=Math.max(e,r);return{startRow:o,startColumn:s,endRow:l,endColumn:d}}_controlHandler(i){const{leftControl:e,rightControl:t,topControl:r,bottomControl:o,backgroundControlTop:s,backgroundControlMiddleLeft:l,backgroundControlMiddleRight:d,backgroundControlBottom:c,fillControl:u}=this._control,h=[e,t,r,o,s,l,d,c,u];for(let g=0,S=h.length;g<S;g++){const f=h[g];i(f,g)}}_fillRuler(i,e,t,r,o){let s=!1;if(i<e)if(this._isInMergeState&&i<e){const l=e-i,d=r+1,c=Math.ceil(l/d);let u=e-c*d;u<0&&(u=e-(c-1)*d),e=u}else e=i;else if(i>=e&&i<=t)s=!0,this._isInMergeState||(t=i);else if(this._isInMergeState&&i>t){const l=i-t,d=r+1,c=Math.ceil(l/d);let u=t+c*d;u>o&&(u=t+(c-1)*d),t=u}else t=i;return{rowOrColumn:i,startRowOrColumn:e,endRowOrColumn:t,isLighten:s}}_getScale(){const{scaleX:i,scaleY:e}=this._scene.getAncestorScale();return Math.max(i,e)}}var Ho=(n=>(n.Selection="__SpreadsheetSelectionShape__",n.top="__SpreadsheetSelectionTopControl__",n.bottom="__SpreadsheetSelectionBottomControl__",n.left="__SpreadsheetSelectionShapeLeftControl__",n.right="__SpreadsheetSelectionShapeRightControl__",n.backgroundTop="__SpreadsheetSelectionBackgroundControlTop__",n.backgroundMiddleLeft="__SpreadsheetSelectionBackgroundControlMiddleLeft__",n.backgroundMiddleRight="__SpreadsheetSelectionBackgroundControlMiddleRight__",n.backgroundBottom="__SpreadsheetSelectionBackgroundControlBottom__",n.fill="__SpreadsheetSelectionFillControl__",n.fillTopLeft="__SpreadsheetSelectionFillControlTopLeft__",n.fillBottomRight="__SpreadsheetSelectionFillControlBottomRight__",n.fillTopLeftInner="__SpreadsheetSelectionFillControlTopLeftInner__",n.fillBottomRightInner="__SpreadsheetSelectionFillControlBottomRightInner__",n.lineMain="__SpreadsheetDragLineMainControl__",n.lineContent="__SpreadsheetDragLineContentControl__",n.line="__SpreadsheetDragLineControl__",n.dash="__SpreadsheetDragDashControl__",n.rowHeaderBackground="__SpreadSheetSelectionRowHeaderBackground__",n.rowHeaderBorder="__SpreadSheetSelectionRowHeaderBorder__",n.rowHeaderGroup="__SpreadSheetSelectionRowHeaderGroup__",n.columnHeaderBackground="__SpreadSheetSelectionColumnHeaderBackground__",n.columnHeaderBorder="__SpreadSheetSelectionColumnHeaderBorder__",n.columnHeaderGroup="__SpreadSheetSelectionColumnHeaderGroup__",n.topLeftWidget="__SpreadSheetSelectionTopLeftWidget__",n.topCenterWidget="__SpreadSheetSelectionTopCenterWidget__",n.topRightWidget="__SpreadSheetSelectionTopRightWidget__",n.middleLeftWidget="__SpreadSheetSelectionMiddleLeftWidget__",n.middleRightWidget="__SpreadSheetSelectionMiddleRightWidget__",n.bottomLeftWidget="__SpreadSheetSelectionBottomLeftWidget__",n.bottomCenterWidget="__SpreadSheetSelectionBottomCenterWidget__",n.bottomRightWidget="__SpreadSheetSelectionBottomRightWidget__",n))(Ho||{});const Bs=.3;class lr extends a.Disposable{constructor(e,t,r,o){var s,l,d,c;super();R(this,"_isHelperSelection",!0);R(this,"_enableAutoFill",!0);R(this,"_showAutoFill",!1);R(this,"_highlightHeader",!0);R(this,"_selectionRenderModel");R(this,"_leftBorder");R(this,"_rightBorder");R(this,"_topBorder");R(this,"_bottomBorder");R(this,"_backgroundControlTop");R(this,"_backgroundControlBottom");R(this,"_backgroundControlMiddleLeft");R(this,"_backgroundControlMiddleRight");R(this,"_autoFillControl");R(this,"_selectionShapeGroup");R(this,"_rowHeaderBackground");R(this,"_rowHeaderBorder");R(this,"_rowHeaderGroup");R(this,"_columnHeaderBackground");R(this,"_columnHeaderBorder");R(this,"_columnHeaderGroup");R(this,"_dashedRect");R(this,"_topLeftWidget");R(this,"_topCenterWidget");R(this,"_topRightWidget");R(this,"_middleLeftWidget");R(this,"_middleRightWidget");R(this,"_bottomLeftWidget");R(this,"_bottomCenterWidget");R(this,"_bottomRightWidget");R(this,"_defaultStyle");R(this,"_currentStyle");R(this,"_rowHeaderWidth",0);R(this,"_columnHeaderHeight",0);R(this,"_widgetRects",[]);R(this,"_controlExtension");R(this,"_dispose$",new O.BehaviorSubject(this));R(this,"dispose$",this._dispose$.asObservable());R(this,"selectionMoving$",new O.Subject);R(this,"selectionMoveEnd$",new O.Subject);R(this,"selectionScaling$",new O.Subject);R(this,"selectionScaled$",new O.Subject);R(this,"selectionFilling$",new O.Subject);R(this,"_selectionFilled$",new O.Subject);R(this,"selectionFilled$",this._selectionFilled$.asObservable());R(this,"_antLineOffset",0);R(this,"_antRequestNewFrame",-1);this._scene=e,this._zIndex=t,this._themeService=r,this._enableAutoFill=(s=o==null?void 0:o.enableAutoFill)!=null?s:!0,this._highlightHeader=(l=o==null?void 0:o.highlightHeader)!=null?l:!0,this._rowHeaderWidth=(d=o==null?void 0:o.rowHeaderWidth)!=null?d:0,this._columnHeaderHeight=(c=o==null?void 0:o.columnHeaderHeight)!=null?c:0,this._initializeSheetBody(),this._initialHeader()}_initializeSheetBody(){this._defaultStyle=Rt(this._themeService),this._currentStyle=Rt(this._themeService),this._selectionRenderModel=new pd;const e=this._zIndex;this._leftBorder=new w.Rect("__SpreadsheetSelectionShapeLeftControl__"+e,{zIndex:e}),this._rightBorder=new w.Rect("__SpreadsheetSelectionShapeRightControl__"+e,{zIndex:e}),this._topBorder=new w.Rect("__SpreadsheetSelectionTopControl__"+e,{zIndex:e}),this._bottomBorder=new w.Rect("__SpreadsheetSelectionBottomControl__"+e,{zIndex:e}),this._backgroundControlTop=new w.Rect("__SpreadsheetSelectionBackgroundControlTop__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlBottom=new w.Rect("__SpreadsheetSelectionBackgroundControlBottom__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleLeft=new w.Rect("__SpreadsheetSelectionBackgroundControlMiddleLeft__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleRight=new w.Rect("__SpreadsheetSelectionBackgroundControlMiddleRight__"+e,{zIndex:e-1,evented:!1}),this._autoFillControl=new w.Rect("__SpreadsheetSelectionFillControl__"+e,{zIndex:e+1}),this._autoFillControl.hide(),this._dashedRect=new w.DashedRect("__SpreadsheetDragDashControl__"+e,{zIndex:e+2,evented:!1,stroke:"#fff"});const t=[this._autoFillControl,this._leftBorder,this._rightBorder,this._topBorder,this._bottomBorder,this._backgroundControlTop,this._backgroundControlMiddleLeft,this._backgroundControlMiddleRight,this._backgroundControlBottom,this._dashedRect];this._widgetRects=this._initialWidget(),this._selectionShapeGroup=new w.Group("__SpreadsheetSelectionShape__"+e,...t,...this._widgetRects),this._selectionShapeGroup.hide(),this._selectionShapeGroup.evented=!1,this._selectionShapeGroup.zIndex=e;const r=this.getScene();r.addObject(this._selectionShapeGroup,Qr),this.disposeWithMe(a.toDisposable(r.onTransformChange$.subscribeEvent(o=>{o.type===w.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&(this._updateLayoutOfSelectionControl(this._currentStyle),this._updateControlCoord())})))}_initialHeader(){const e=this._zIndex;this._rowHeaderBackground=new w.Rect("__SpreadSheetSelectionRowHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderBorder=new w.Rect("__SpreadSheetSelectionRowHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderGroup=new w.Group("__SpreadSheetSelectionRowHeaderGroup__"+e,this._rowHeaderBackground,this._rowHeaderBorder),this._rowHeaderGroup.hide(),this._rowHeaderGroup.evented=!1,this._rowHeaderGroup.zIndex=e,this._columnHeaderBackground=new w.Rect("__SpreadSheetSelectionColumnHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderBorder=new w.Rect("__SpreadSheetSelectionColumnHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderGroup=new w.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],fd)}_initialWidget(){const e=this._zIndex;return this._topLeftWidget=new w.Rect("__SpreadSheetSelectionTopLeftWidget__"+e,{zIndex:e+1}),this._topCenterWidget=new w.Rect("__SpreadSheetSelectionTopCenterWidget__"+e,{zIndex:e+1}),this._topRightWidget=new w.Rect("__SpreadSheetSelectionTopRightWidget__"+e,{zIndex:e+1}),this._middleLeftWidget=new w.Rect("__SpreadSheetSelectionMiddleLeftWidget__"+e,{zIndex:e+1}),this._middleRightWidget=new w.Rect("__SpreadSheetSelectionMiddleRightWidget__"+e,{zIndex:e+1}),this._bottomLeftWidget=new w.Rect("__SpreadSheetSelectionBottomLeftWidget__"+e,{zIndex:e+1}),this._bottomCenterWidget=new w.Rect("__SpreadSheetSelectionBottomCenterWidget__"+e,{zIndex:e+1}),this._bottomRightWidget=new w.Rect("__SpreadSheetSelectionBottomRightWidget__"+e,{zIndex:e+1}),[this._topLeftWidget,this._topCenterWidget,this._topRightWidget,this._middleLeftWidget,this._middleRightWidget,this._bottomLeftWidget,this._bottomCenterWidget,this._bottomRightWidget]}get zIndex(){return this._zIndex}get leftControl(){return this._leftBorder}get rightControl(){return this._rightBorder}get topControl(){return this._topBorder}get bottomControl(){return this._bottomBorder}get fillControl(){return this._autoFillControl}get backgroundControlTop(){return this._backgroundControlTop}get backgroundControlBottom(){return this._backgroundControlBottom}get backgroundControlMiddleLeft(){return this._backgroundControlMiddleLeft}get backgroundControlMiddleRight(){return this._backgroundControlMiddleRight}get selectionShape(){return this._selectionShapeGroup}get columnHeaderGroup(){return this._columnHeaderGroup}get rowHeaderGroup(){return this._rowHeaderGroup}get selectionShapeGroup(){return this._selectionShapeGroup}get model(){return this._selectionRenderModel}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 themeService(){return this._themeService}get selectionModel(){return this._selectionRenderModel}set selectionModel(e){this._selectionRenderModel=e}get currentStyle(){return this._currentStyle}set currentStyle(e){this._currentStyle=e}get dashedRect(){return this._dashedRect}get isHelperSelection(){return this._isHelperSelection}get rowHeaderWidth(){return this._rowHeaderWidth}set rowHeaderWidth(e){this._rowHeaderWidth=e}get columnHeaderHeight(){return this._columnHeaderHeight}set columnHeaderHeight(e){this._columnHeaderHeight=e}setControlExtension(e){this._controlExtension=new Fa(this,e)}setEvent(e){this.leftControl.evented=e,this.rightControl.evented=e,this.topControl.evented=e,this.bottomControl.evented=e}refreshSelectionFilled(e){this._selectionFilled$.next(e)}_updateLayoutOfSelectionControl(e){e&&(this.currentStyle=Object.assign({},this._defaultStyle,e));const t=this.currentStyle,{stroke:r,widgets:o,autofillStroke:s,strokeDash:l,isAnimationDash:d}=t;let c=t.autofillSize,u=t.strokeWidth,h=t.autofillStrokeWidth;const g=this._getScale(),S=(u+m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH)/2/g;u/=g,c/=g,h/=g<1?1:g;const f=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/g,p=w.FIX_ONE_PIXEL_BLUR_OFFSET/g,{startX:v,startY:C,endX:I,endY:b}=this._selectionRenderModel;if(this.leftControl.transformByState({height:b-C,left:-S+p,width:u,strokeWidth:f,top:-f/2+p}),this.leftControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.rightControl.transformByState({height:b-C,left:I-v-S+p,width:u,strokeWidth:f,top:-f/2+p}),this.rightControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.topControl.transformByState({width:I-v+u,top:-S+p,left:-S+p,height:u,strokeWidth:f}),this.topControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.bottomControl.transformByState({width:I-v+u,top:b-C-S+p,height:u,left:-S+p,strokeWidth:f}),this.bottomControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),l==null)this.dashedRect.hide(),this._stopAntLineAnimation();else{const T=t.strokeWidth*2/g;this.dashedRect.transformByState({height:b-C,width:I-v,strokeWidth:T,left:-T/2+p,top:-T/2+p}),this.dashedRect.setProps({strokeDashArray:[0,l/g]}),this._stopAntLineAnimation(),d!==!1&&this._startAntLineAnimation(),this.dashedRect.show()}if(this._showAutoFill=this._showAutoFill&&this._enableAutoFill,this._showAutoFill&&!this._hasWidgets(o)){const T={fill:r,stroke:s,strokeScaleEnabled:!1},M={width:c-h,height:c-h,left:I-v-c/2+h/2-p,top:b-C-c/2+h/2-p,strokeWidth:h};this._autoFillControl.setProps(T),this._autoFillControl.transformByState(M),this._autoFillControl.show()}else this._autoFillControl.hide();this._updateBackgroundControl(t),this._updateHeaderBackground(t),this._updateWidgets(t)}_updateControlCoord(){const{startX:e,startY:t}=this._selectionRenderModel;this.selectionShapeGroup.show(),this.selectionShapeGroup.translate(e,t),this.selectionShapeGroup.makeDirtyNoDebounce(!0)}updateStyle(e){this._updateLayoutOfSelectionControl(e),this._updateControlCoord()}updateRange(e,t){this._selectionRenderModel.setValue(e,t),this._showAutoFill=t!==null,this._updateLayoutOfSelectionControl(),this._updateControlCoord()}updateRangeBySelectionWithCoord(e,t){t&&(this._rowHeaderWidth=t.getWorksheetConfig().rowHeader.width,this._columnHeaderHeight=t.getWorksheetConfig().columnHeader.height),this._selectionRenderModel.setValue(e.rangeWithCoord,e.primaryWithCoord),this._showAutoFill=e.primaryWithCoord!==null,this._updateLayoutOfSelectionControl(e.style),this._updateControlCoord()}update(e,t=0,r=0,o,s){this._rowHeaderWidth=t,this._columnHeaderHeight=r,this.updateRangeBySelectionWithCoord({rangeWithCoord:e,primaryWithCoord:s,style:o}),o&&this.updateStyle(o)}updateCurrCell(e){this._showAutoFill=e!==null,this._selectionRenderModel.setCurrentCell(e)}clearHighlight(){this._showAutoFill=!1,this._selectionRenderModel.clearCurrentCell(),this._updateLayoutOfSelectionControl(this._currentStyle)}getScene(){return this._scene}dispose(){var e,t,r,o,s,l,d,c,u,h,g,S,f,p,v,C,I,b,T,M,y,P,x,A,N;(e=this._leftBorder)==null||e.dispose(),(t=this._rightBorder)==null||t.dispose(),(r=this._topBorder)==null||r.dispose(),(o=this._bottomBorder)==null||o.dispose(),(s=this._backgroundControlTop)==null||s.dispose(),(l=this._backgroundControlMiddleLeft)==null||l.dispose(),(d=this._backgroundControlMiddleRight)==null||d.dispose(),(c=this._backgroundControlBottom)==null||c.dispose(),this._autoFillControl.dispose(),(u=this._selectionShapeGroup)==null||u.dispose(),(h=this._rowHeaderBackground)==null||h.dispose(),(g=this._rowHeaderBorder)==null||g.dispose(),(S=this._rowHeaderGroup)==null||S.dispose(),(f=this._rowHeaderBackground)==null||f.dispose(),(p=this._columnHeaderBackground)==null||p.dispose(),(v=this._columnHeaderBorder)==null||v.dispose(),(C=this._columnHeaderGroup)==null||C.dispose(),(I=this._topLeftWidget)==null||I.dispose(),(b=this._topCenterWidget)==null||b.dispose(),(T=this._topRightWidget)==null||T.dispose(),(M=this._middleLeftWidget)==null||M.dispose(),(y=this._middleRightWidget)==null||y.dispose(),(P=this._bottomLeftWidget)==null||P.dispose(),(x=this._bottomCenterWidget)==null||x.dispose(),(A=this._bottomRightWidget)==null||A.dispose(),(N=this._controlExtension)==null||N.dispose(),super.dispose(),this._dispose$.next(this),this._dispose$.complete()}getCurrentCellInfo(){const e=this.model.currentCell;if(e){let t;if(e.isMerged){const r=e.mergeInfo;t={startRow:r.startRow,endRow:r.endRow,startColumn:r.startColumn,endColumn:r.endColumn,startX:r.startX,endX:r.endX,startY:r.startY,endY:r.endY}}else{const{actualRow:r,actualColumn:o,startX:s,endX:l,startY:d,endY:c}=e;t={startRow:r,endRow:r,startColumn:o,endColumn:o,startX:s,endX:l,startY:d,endY:c}}return t}}getValue(){return{...this._selectionRenderModel.getValue(),style:this._currentStyle}}getRange(){return this._selectionRenderModel.getValue().rangeWithCoord}enableHelperSelection(){this._isHelperSelection=!0}disableHelperSelection(){this._isHelperSelection=!1}_updateHeaderBackground(e){const{startX:t,startY:r,endX:o,endY:s,rangeType:l}=this._selectionRenderModel,d=this._currentStyle,c=this._getScale(),{stroke:u,rowHeaderFill:h=d.rowHeaderFill,rowHeaderStroke:g=d.rowHeaderStroke,columnHeaderFill:S=d.columnHeaderFill,columnHeaderStroke:f=d.columnHeaderStroke}=e;let{rowHeaderStrokeWidth:p=d.rowHeaderStrokeWidth,columnHeaderStrokeWidth:v=d.columnHeaderStrokeWidth}=e;p/=c,v/=c;const C=this._rowHeaderWidth,I=this._columnHeaderHeight;if(this._highlightHeader&&I>0){let b=S;l===a.RANGE_TYPE.COLUMN&&(b=new a.ColorKit(u).setAlpha(Bs).toString()),this._columnHeaderBackground.setProps({fill:b}),this._columnHeaderBackground.resize(o-t,I),this._columnHeaderBorder.setProps({fill:f}),this._columnHeaderBorder.transformByState({width:o-t,height:v,top:I-v+1/c}),this._columnHeaderGroup.show(),this._columnHeaderGroup.translate(t,0)}else this._columnHeaderGroup.hide();if(this._columnHeaderGroup.makeDirty(!0),this._highlightHeader&&C>0){let b=h;l===a.RANGE_TYPE.ROW&&(b=new a.ColorKit(u).setAlpha(Bs).toString()),this._rowHeaderBackground.setProps({fill:b}),this._rowHeaderBackground.resize(C,s-r),this._rowHeaderBorder.setProps({fill:g}),this._rowHeaderBorder.transformByState({width:p,height:s-r,left:C-p+1/c}),this._rowHeaderGroup.show(),this._rowHeaderGroup.translate(0,r)}else this._rowHeaderGroup.hide();this._rowHeaderGroup.makeDirty(!0)}_updateBackgroundControl(e){const{startX:t,startY:r,endX:o,endY:s}=this._selectionRenderModel,l=this._getScale(),{fill:d=e.fill}=e;let{strokeWidth:c}=e;c/=l;const u=this._selectionRenderModel.highlightToSelection();if(!u){this._backgroundControlTop.resize(o-t,s-r),this._backgroundControlTop.setProps({fill:d}),this._backgroundControlBottom.resize(0,0),this._backgroundControlMiddleLeft.resize(0,0),this._backgroundControlMiddleRight.resize(0,0);return}const{startX:h,startY:g,endX:S,endY:f}=u,p=c/2,v={left:-p,top:-p,width:o-t+p*2,height:g-r+p};v.height<0&&(v.width=0,v.height=0),this._backgroundControlTop.transformByState(v);const C={left:-p,top:g-r,width:h-t+p,height:f-g};C.width<0&&(C.width=0,C.height=0),this._backgroundControlMiddleLeft.transformByState(C);const I={left:S-t-p,top:g-r,width:o-S+p*2,height:f-g};I.width<0&&(I.width=0,I.height=0),this._backgroundControlMiddleRight.transformByState(I);const b={left:-p,top:f-r,width:o-t+p*2,height:s-f+p};b.height<0&&(b.width=0,b.height=0),this._backgroundControlBottom.transformByState(b),this._backgroundControlTop.setProps({fill:d}),this._backgroundControlMiddleLeft.setProps({fill:d}),this._backgroundControlMiddleRight.setProps({fill:d}),this._backgroundControlBottom.setProps({fill:d})}_updateWidgets(e){const{startX:t,startY:r,endX:o,endY:s}=this._selectionRenderModel,{stroke:l=e.stroke,widgets:d=e.widgets,widgetStroke:c=e.widgetStroke}=e,u=this._getScale();let{widgetSize:h,widgetStrokeWidth:g}=e;h/=u,g/=u;const S={left:-h/2+g/2,center:(o-t)/2-h/2+g/2,right:o-t-h/2+g/2,top:-h/2,middle:(s-r)/2-h/2,bottom:s-r-h/2+g/2},f=h-g;this._widgetRects.forEach(p=>{p.setProps({fill:l,stroke:c})}),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 t=Object.keys(e);if(t.length===0)return!1;for(const r of t)if(e[r]===!0)return!0;return!1}_getScale(){const{scaleX:e,scaleY:t}=this._scene.getAncestorScale();return Math.max(e,t)}_stopAntLineAnimation(){this._antLineOffset=0,w.cancelRequestFrame(this._antRequestNewFrame)}_startAntLineAnimation(){const e=this._getScale();this._antLineOffset+=.6/e,this._antLineOffset>160/e&&(this._antLineOffset=0),this.dashedRect.setProps({strokeDashOffset:-this._antLineOffset}),this._antRequestNewFrame=w.requestNewFrame(()=>{this._startAntLineAnimation()})}}class Cd extends w.Layer{render(i,e=!1){const t=a.Tools.now();return super.render(i,e),this._afterRender(t),this}_afterRender(i){this.scene.getEngine().renderFrameTimeMetric$.next(["selectionLayer",a.Tools.now()-i])}}const ve=a.createIdentifier("univer.sheet.selection-render-service");class ls extends a.Disposable{constructor(e,t,r,o,s){super();R(this,"_downObserver");R(this,"_scenePointerMoveSub");R(this,"_scenePointerUpSub");R(this,"_controlFillConfig$",new O.BehaviorSubject(null));R(this,"controlFillConfig$",this._controlFillConfig$.asObservable());R(this,"_selectionControls",[]);R(this,"_startRangeWhenPointerDown",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});R(this,"_activeControlIndex",-1);R(this,"_startViewportPosX",0);R(this,"_startViewportPosY",0);R(this,"_scrollTimer");R(this,"_cancelDownSubscription");R(this,"_cancelUpSubscription");R(this,"_skeleton");R(this,"_scene");R(this,"_highlightHeader",!0);R(this,"_rangeType",a.RANGE_TYPE.NORMAL);R(this,"_selectionStyle");R(this,"_remainLastEnabled",!1);R(this,"_skipLastEnabled",!1);R(this,"_singleSelectionEnabled",!1);R(this,"_selectionMoveEnd$",new O.BehaviorSubject([]));R(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());R(this,"_selectionMoving$",new O.Subject);R(this,"selectionMoving$",this._selectionMoving$.asObservable());R(this,"_selectionMoveStart$",new O.Subject);R(this,"selectionMoveStart$",this._selectionMoveStart$.asObservable());R(this,"_selectionMoving",!1);R(this,"_selectionTheme");R(this,"_activeViewport");R(this,"interceptor",new a.InterceptorManager({RANGE_MOVE_PERMISSION_CHECK:No,RANGE_FILL_PERMISSION_CHECK:Do}));R(this,"_escapeShortcutDisposable",null);this._injector=e,this._themeService=t,this._shortcutService=r,this._sheetSkeletonManagerService=o,this.contextService=s,this._initSelectionThemeFromThemeService(),this._initMoving()}get selectionMoving(){return this._selectionMoving}get _shouldDetectMergedCells(){return this._rangeType===a.RANGE_TYPE.NORMAL}_initMoving(){this.disposeWithMe(this._selectionMoving$.subscribe(()=>{this._selectionMoving=!0})),this.disposeWithMe(this._selectionMoveEnd$.subscribe(()=>{this._selectionMoving=!1}))}_setSelectionStyle(e){this._selectionStyle=e}getViewPort(){return this._activeViewport}setSingleSelectionEnabled(e=!1){this._singleSelectionEnabled=e}newSelectionControl(e,t,r){const o=this.getSelectionControls().length,{rowHeaderWidth:s,columnHeaderHeight:l}=t,d=new lr(e,o,this._selectionTheme,{highlightHeader:this._highlightHeader,rowHeaderWidth:s,columnHeaderHeight:l});this._selectionControls.push(d);const c=Me(r,t);return d.updateRangeBySelectionWithCoord(c,t),d.setControlExtension({skeleton:t,scene:e,themeService:this._selectionTheme,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),d}resetSelectionsByModelData(e){const t=this.getSelectionControls(),r=this._skeleton;if(!(!t||!r)){for(let o=0,s=e.length;o<s;o++){const l=e[o],d=Me(l,this._skeleton),c=t[o];c?c.updateRangeBySelectionWithCoord(d,r):this.isSelectionEnabled()&&this.newSelectionControl(this._scene,r,l)}e.length<t.length&&t.splice(e.length).forEach(s=>s.dispose())}}refreshSelectionMoveStart(){this._selectionMoveStart$.next(this.getSelectionDataWithStyle())}refreshSelectionMoveEnd(){this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}_initSelectionThemeFromThemeService(){const e=this._themeService.getCurrentTheme();this._selectionTheme=new a.ThemeService,this._selectionTheme.setTheme(e)}setSelectionTheme(e){this._selectionTheme.setTheme(e)}_changeRuntime(e,t,r){this._skeleton=e,this._scene=t,this._activeViewport=r||(t==null?void 0:t.getViewports()[0]),t.findLayerByZIndex(Qr)||t.addLayer(new Cd(t,[],Qr))}getSkeleton(){return this._skeleton}getSelectionDataWithStyle(){const e=this._selectionControls,[t,r]=this._skeleton.getLocation();return e.map(o=>{const s=o.getValue();return s.rangeWithCoord.sheetId=r,s.rangeWithCoord.unitId=t,s})}getSelectionControls(){return this._selectionControls}_addSelectionControlByModelData(e){var l;const t=this._skeleton,r=(l=e.style)!=null?l:Rt(this._selectionTheme),o=this._scene;return e.style=r,this.newSelectionControl(o,t,e)}_clearAllSelectionControls(){const e=this._selectionControls;for(const t of e)t.dispose();this._selectionControls.length=0}_getFreeze(){var t;return(t=this._sheetSkeletonManagerService.getCurrent())==null?void 0:t.skeleton.getWorksheetConfig().freeze}_getViewportByCell(e,t){if(e===void 0||t===void 0)return null;const r=this._getFreeze();if(!r||r.startRow<=0&&r.startColumn<=0)return this._scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e>r.startRow&&t>r.startColumn)return this._scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e<=r.startRow&&t<=r.startColumn)return this._scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP);if(e<=r.startRow&&t>r.startColumn)return this._scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(e>r.startRow&&t<=r.startColumn)return this._scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)}getActiveRange(){const e=this.getSelectionControls(),t=e&&e[e.length-1].model;return t&&{startRow:t.startRow,startColumn:t.startColumn,endRow:t.endRow,endColumn:t.endColumn}}setActiveSelectionIndex(e){this._activeControlIndex=e}resetActiveSelectionIndex(){this._activeControlIndex=-1}getActiveSelectionControl(){const e=this.getSelectionControls();if(e)return this._activeControlIndex<0?e[e.length-1]:e[this._activeControlIndex]}endSelection(){var e;this._clearUpdatingListeners(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),(e=this._escapeShortcutDisposable)==null||e.dispose(),this._escapeShortcutDisposable=null}_reset(){var e;this._clearAllSelectionControls(),(e=this._downObserver)==null||e.unsubscribe(),this._downObserver=null}_setupPointerMoveListener(e,t,r,o=w.ScrollTimerType.ALL,s,l){var f,p;let d=0,c=0,u=s,h=l;this._scrollTimer=w.ScrollTimer.create(this._scene,o),this._scrollTimer.startScroll((f=e==null?void 0:e.left)!=null?f:0,(p=e==null?void 0:e.top)!=null?p:0,e);const g=this._scene,S=g.getActiveViewportByCoord(w.Vector2.FromArray([s,l]));this._scenePointerMoveSub=g.onPointerMove$.subscribeEvent(v=>{var H,W,k,U,B,F,L,z,X;const{offsetX:C,offsetY:I}=v,{x:b,y:T}=g.getCoordRelativeToViewport(w.Vector2.FromArray([C,I]));this._movingHandler(b,T,t,r);let M=b,y=T;const P=this.getActiveSelectionControl(),x=this._getFreeze(),A=P==null?void 0:P.model,N=(H=g.getActiveViewportByCoord(w.Vector2.FromArray([C,I])))!=null?H:this._getViewportByCell(A==null?void 0:A.endRow,A==null?void 0:A.endColumn);if((()=>{if(!S||!N||!e)return!1;const Z=[w.SHEET_VIEWPORT_KEY.VIEW_MAIN,w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,w.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT];return Z.includes(S.viewportKey)&&Z.includes(N.viewportKey)})()){if(!S||!N||!e)return!1;const Z=u<e.left&&b>e.left||u>e.left&&b<e.left,re=h<e.top&&T>e.top||h>e.top&&T<e.top;Z&&(d+=1),re&&(c+=1);const Q=S.viewportKey,oe=N.viewportKey;if(Q===w.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP)I<e.top&&((W=A==null?void 0:A.endRow)!=null?W:0)<((k=x==null?void 0:x.startRow)!=null?k:0)?y=e.top:re&&c%2===1&&e.scrollToViewportPos({viewportScrollY:0});else if(Q===w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT)C<e.left&&((U=A==null?void 0:A.endColumn)!=null?U:0)<((B=x==null?void 0:x.startColumn)!=null?B:0)?M=e.left:Z&&d%2===1&&e.scrollToViewportPos({viewportScrollX:0});else if(Q===oe){let $=!1,j=!1;Q===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP?($=!0,j=!0):Q===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP?j=!0:Q===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT&&($=!0),((F=A==null?void 0:A.endRow)!=null?F:0)>((L=x==null?void 0:x.startRow)!=null?L:0)&&(j=!1),((z=A==null?void 0:A.endColumn)!=null?z:0)>((X=x==null?void 0:x.startColumn)!=null?X:0)&&($=!1),$&&(M=e.left),j&&(y=e.top)}else{const $={x:S.scrollX,y:S.scrollY},j={x:N.scrollX,y:N.scrollY},Y=$.x!==j.x&&Z&&d%2===1,q=$.y!==j.y&&re&&c%2===1;(Y||q)&&(e.scrollToBarPos({x:Y?$.x:void 0,y:q?$.y:void 0}),Y||(M=e.left),q||(y=e.top)),(Q===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&oe===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||oe===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&Q===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)&&(M=e.left),(Q===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&oe===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||oe===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&Q===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP)&&(y=e.top)}u=b,h=T}this._scrollTimer.scrolling(M,y,()=>{this._movingHandler(b,T,t,r)})})}attachSelectionWithCoord(e){return Me(e,this._skeleton)}attachPrimaryWithCoord(e){return Qn(this._skeleton,e)}getSelectionCellByPosition(e,t){return this.getCellWithCoordByOffset(e,t)}getCellWithCoordByOffset(e,t,r){const o=this._scene,s=r!=null?r:this._skeleton,l=o.getViewportScrollXY(o.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:d,scaleY:c}=o.getAncestorScale();return s.getCellWithCoordByOffset(e,t,d,c,l)}_movingHandler(e,t,r,o){var M,y,P,x,A;const s=this._skeleton,l=this._scene,[d,c]=s.getLocation(),u={startRow:(M=r==null?void 0:r.model.startRow)!=null?M:-1,endRow:(y=r==null?void 0:r.model.endRow)!=null?y:-1,startColumn:(P=r==null?void 0:r.model.startColumn)!=null?P:-1,endColumn:(x=r==null?void 0:r.model.endColumn)!=null?x:-1,unitId:d,sheetId:c},h=l.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=(A=this._getViewportByCell(u.endRow,u.endColumn))!=null?A:h,S=l.getScrollXYInfoByViewport(w.Vector2.FromArray([this._startViewportPosX,this._startViewportPosY]),g),{scaleX:f,scaleY:p}=l.getAncestorScale();o===a.RANGE_TYPE.ROW?e=Number.POSITIVE_INFINITY:o===a.RANGE_TYPE.COLUMN&&(t=Number.POSITIVE_INFINITY);const v=this._skeleton.getCellByOffset(e,t,f,p,S);if(!v)return;let C={startRow:Math.min(v.startRow,this._startRangeWhenPointerDown.startRow),startColumn:Math.min(v.startColumn,this._startRangeWhenPointerDown.startColumn),endRow:Math.max(v.endRow,this._startRangeWhenPointerDown.endRow),endColumn:Math.max(v.endColumn,this._startRangeWhenPointerDown.endColumn)};this._shouldDetectMergedCells&&(C=s.expandRangeByMerge(C));const b=Me({range:C,primary:void 0,style:null},s);b.rangeWithCoord.unitId=d,b.rangeWithCoord.sheetId=c,b.rangeWithCoord.rangeType=o;const T=u.startRow!==C.startRow||u.startColumn!==C.startColumn||u.endRow!==C.endRow||u.endColumn!==C.endColumn;r!=null&&T&&(r.updateRangeBySelectionWithCoord(b),this._selectionMoving$.next(this.getSelectionDataWithStyle()))}_clearUpdatingListeners(){var t,r,o,s,l;this._scene.enableObjectsEvent(),(t=this._scenePointerMoveSub)==null||t.unsubscribe(),this._scenePointerMoveSub=null,(r=this._scenePointerUpSub)==null||r.unsubscribe(),this._scenePointerUpSub=null,(o=this._cancelDownSubscription)==null||o.unsubscribe(),this._cancelDownSubscription=null,(s=this._cancelUpSubscription)==null||s.unsubscribe(),this._cancelUpSubscription=null,(l=this._scrollTimer)==null||l.dispose()}_addEndingListeners(){var r,o,s;const e=this._scene,t=(r=e.getEngine())==null?void 0:r.activeScene;!t||t===e||((o=this._cancelDownSubscription)==null||o.unsubscribe(),this._cancelDownSubscription=null,(s=this._cancelUpSubscription)==null||s.unsubscribe(),this._cancelUpSubscription=null,this._cancelDownSubscription=t.onPointerDown$.subscribeEvent(()=>this._clearUpdatingListeners()),this._cancelUpSubscription=t.onPointerUp$.subscribeEvent(()=>this._clearUpdatingListeners()))}_getSelectionWithCoordByOffset(e,t,r,o,s){const l=this._skeleton;if(l==null)return null;if(this._shouldDetectMergedCells){const C=l==null?void 0:l.getCellWithCoordByOffset(e,t,r,o,s,{firstMatch:!0});if(!C)return;const I=a.convertCellToRange(C);return{primaryWithCoord:C,rangeWithCoord:I}}const{row:d,column:c}=l.getCellIndexByOffset(e,t,r,o,s),u=l.getNoMergeCellPositionByIndex(d,c),{startX:h,startY:g,endX:S,endY:f}=u,p={startY:g,endY:f,startX:h,endX:S,startRow:d,endRow:d,startColumn:c,endColumn:c};return{primaryWithCoord:{mergeInfo:p,actualRow:d,actualColumn:c,isMerged:!1,isMergedMainCell:!1,startY:g,endY:f,startX:h,endX:S},rangeWithCoord:p}}_checkClearPreviousControls(e){this.getSelectionControls().length!==0&&(!e.ctrlKey&&!e.shiftKey&&!this._remainLastEnabled||this._singleSelectionEnabled&&!e.shiftKey)&&this._clearAllSelectionControls()}_makeSelectionByTwoCells(e,t,r,o,s){const{actualRow:l,actualColumn:d,mergeInfo:c}=e;this._startRangeWhenPointerDown={...e.mergeInfo};const u=Math.min(l,t.startRow,c.startRow),h=Math.max(l,t.endRow,c.endRow),g=Math.min(d,t.startColumn,c.startColumn),S=Math.max(d,t.endColumn,c.endColumn),p={range:r.expandRangeByMerge({startRow:u,startColumn:g,endRow:h,endColumn:S}),primary:null,style:null},v=Me(p,r);s.updateRangeBySelectionWithCoord(v)}isSelectionEnabled(){return this.contextService.getContextValue(m.SELECTIONS_ENABLED)}isSelectionDisabled(){return this.contextService.getContextValue(m.SELECTIONS_ENABLED)===!1}inRefSelectionMode(){return this.contextService.getContextValue(m.REF_SELECTIONS_ENABLED)}}function cs(n){return{range:{startRow:0,startColumn:0,endRow:n.getRowCount()-1,endColumn:n.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL},primary:Mi(n).primary,style:null}}function Mi(n){return ja(n,{startRow:0,startColumn:0,endRow:0,endColumn:0})}function ja(n,i){const e=n.worksheet.getCellInfoInMergeData(i.startRow,i.startColumn),t=n.worksheet.getCellInfoInMergeData(i.endRow,i.endColumn);return{range:{startRow:e.startRow,startColumn:e.startColumn,endRow:t.endRow,endColumn:t.endColumn,rangeType:a.RANGE_TYPE.NORMAL},primary:{actualRow:e.startRow,actualColumn:e.startColumn,startRow:e.startRow,startColumn:e.startColumn,endRow:e.endRow,endColumn:e.endColumn,isMerged:e.isMerged,isMergedMainCell:e.isMergedMainCell},style:null}}var _d=Object.defineProperty,Id=Object.getOwnPropertyDescriptor,bd=(n,i,e,t)=>{for(var r=t>1?void 0:t?Id(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&_d(i,e,r),r},Rd=(n,i)=>(e,t)=>i(e,t,n);exports.SheetSkeletonManagerService=class extends a.Disposable{constructor(e,t){super();R(this,"_currentSkeletonSearchParam",{sheetId:""});R(this,"_sheetSkeletonParam",[]);R(this,"_currentSkeleton$",new O.BehaviorSubject(null));R(this,"currentSkeleton$",this._currentSkeleton$.asObservable());R(this,"_currentSkeletonBefore$",new O.BehaviorSubject(null));R(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._context=e,this._injector=t,this.disposeWithMe(()=>{this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._sheetSkeletonParam=[]}),this._initRemoveSheet()}_initRemoveSheet(){this.disposeWithMe(this._context.unit.sheetDisposed$.subscribe(e=>{this.disposeSkeleton({sheetId:e.getSheetId()})}))}getCurrentSkeleton(){var e;return(e=this.getCurrent())==null?void 0:e.skeleton}getCurrent(){return this._getSkeleton(this._currentSkeletonSearchParam)}getWorksheetSkeleton(e){return this._getSkeleton({sheetId:e})}getUnitSkeleton(e,t){const r=this._getSkeleton({sheetId:t});return r!=null&&(r.unitId=e),r}setCurrent(e){this._setCurrent(e)}_setCurrent(e){const t=this._getSkeleton(e),r=this._context.unitId;if(t!=null)this._reCalculate(t);else{const{sheetId:l}=e,c=this._context.unit.getSheetBySheetId(e.sheetId);if(c==null)return;const u=this._buildSkeleton(c);this._sheetSkeletonParam.push({unitId:r,sheetId:l,skeleton:u,dirty:!1})}this._currentSkeletonSearchParam=e;const o=this._currentSkeletonSearchParam.sheetId,s=this.getUnitSkeleton(r,o);this._currentSkeletonBefore$.next(s),this._currentSkeleton$.next(s)}reCalculate(){const e=this.getCurrent();e!=null&&this._reCalculate(e)}_reCalculate(e){e.dirty&&(e.skeleton.makeDirty(!0),e.dirty=!1),e.skeleton.calculate()}makeDirty(e,t=!0){const r=this._getSkeleton(e);r!=null&&(r.dirty=t)}getOrCreateSkeleton(e){const t=this._getSkeleton(e);if(t)return t.skeleton;const o=this._context.unit.getSheetBySheetId(e.sheetId);if(!o)return;const s=this._buildSkeleton(o);return this._sheetSkeletonParam.push({unitId:this._context.unitId,sheetId:e.sheetId,skeleton:s,dirty:!1}),s}disposeSkeleton(e){const t=this._sheetSkeletonParam.findIndex(r=>r.sheetId===e.sheetId);t>-1&&(this._sheetSkeletonParam[t].skeleton.dispose(),this._sheetSkeletonParam.splice(t,1))}attachRangeWithCoord(e){const t=this.getCurrentSkeleton();return t?In(t,e):null}_getSkeleton(e){const t=this._sheetSkeletonParam.find(r=>r.sheetId===e.sheetId);return t!=null&&(t.commandId=e.commandId),t}_buildSkeleton(e){return this._injector.createInstance(w.SpreadsheetSkeleton,e,this._context.unit.getStyles())}setColumnHeaderSize(e,t,r){var u;if(!e)return;const o=(u=this.getWorksheetSkeleton(t))==null?void 0:u.skeleton;if(!o)return;o.columnHeaderHeight=r,e.scene.getViewports()[0].top=r,e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({height:r}),e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({height:r}),e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({top:r}),e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({top:r}),e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({height:r});const s=e==null?void 0:e.with(m.SheetsSelectionsService),l=e==null?void 0:e.with(ve),d=s.getCurrentSelections();l.resetSelectionsByModelData(d);const c=this.getUnitSkeleton(e.unitId,t);c&&(c.commandId=yi.id,this._currentSkeleton$.next(c))}setRowHeaderSize(e,t,r){var f;const o=(f=this.getWorksheetSkeleton(t))==null?void 0:f.skeleton;if(!e||!o)return;o.rowHeaderWidth=r;const s=e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).width||46,l=r-s,d=e.scene.getViewports()[0].left;e.scene.getViewports()[0].left=d+l,e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({width:r}),e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({width:r}),e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({left:r});const c=e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).left||0;e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({left:c+l}),e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({width:r});const u=e==null?void 0:e.with(m.SheetsSelectionsService),h=e==null?void 0:e.with(ve),g=u.getCurrentSelections();h.resetSelectionsByModelData(g);const S=this.getCurrent();S&&(S.commandId=wi.id,this._currentSkeleton$.next(S))}};exports.SheetSkeletonManagerService=bd([Rd(1,a.Inject(a.Injector))],exports.SheetSkeletonManagerService);function Je(){const n=a.useDependency(a.IUniverInstanceService),i=E.useObservable(()=>n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]);return i!=null?i:null}function Ed(n){return E.useObservable(()=>{var e;return(e=n==null?void 0:n.activeSheet$)!=null?e:O.of(null)},void 0,void 0,[n])}function Td(){const n=a.useDependency(a.IUniverInstanceService);return E.useObservable(()=>O.merge([n.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET),n.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET)]).pipe(O.map(()=>n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET)),O.startWith(n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET))),[],void 0,[n])}function wd(){const n=a.useDependency(w.IRenderManagerService),i=Je(),{sheetSkeletonManagerService:e}=V.useMemo(()=>{if(i){const t=n.getRenderById(i.getUnitId());return{sheetSkeletonManagerService:t==null?void 0:t.with(exports.SheetSkeletonManagerService)}}return{sheetSkeletonManagerService:null}},[i,n]);return e}const yd="SheetUI";var ds=(n=>(n.FILTER_PANEL_EMBED_POINT="filter-panel-embed-point",n.SHEETS_FOOTER="sheets-footer",n.FORMULA_AUX="formula-aux",n))(ds||{}),Md=Object.defineProperty,Pd=Object.getOwnPropertyDescriptor,Od=(n,i,e,t)=>{for(var r=t>1?void 0:t?Pd(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Md(i,e,r),r},Hr=(n,i)=>(e,t)=>i(e,t,n);const us=["ff","fs","tr","tb"];exports.AutoHeightController=class extends a.Disposable{constructor(i,e,t,r){super(),this._renderManagerService=i,this._sheetInterceptorService=e,this._selectionManagerService=t,this._univerInstanceService=r,this._initialize()}getUndoRedoParamsOfAutoHeight(i){const{_univerInstanceService:e}=this,t=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),r=t.getActiveSheet(),o=t.getUnitId(),s=r.getSheetId(),l=this._renderManagerService.getRenderById(o).with(exports.SheetSkeletonManagerService);if(!s||!l.getCurrent())return{redos:[],undos:[]};const{skeleton:d}=l.getCurrent(),c=d.calculateAutoHeightInRange(i),u={subUnitId:s,unitId:o,rowsAutoHeightInfo:c},h=m.SetWorksheetRowAutoHeightMutationFactory(u,r);return{undos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:h}],redos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:u}]}}_initialize(){const{_sheetInterceptorService:i,_selectionManagerService:e}=this;this.disposeWithMe(i.interceptCommand({getMutations:t=>{if(t.id===m.SetRangeValuesCommand.id){const r=t.params;return this.getUndoRedoParamsOfAutoHeight(r.range)}return{redos:[],undos:[]}}})),this.disposeWithMe(i.interceptCommand({getMutations:t=>t.id!==m.SetWorksheetRowIsAutoHeightCommand.id?{redos:[],undos:[]}:this.getUndoRedoParamsOfAutoHeight(t.params.ranges)})),this.disposeWithMe(i.interceptCommand({getMutations:t=>{var o,s;if(t.id!==m.SetStyleCommand.id)return{redos:[],undos:[]};if(!us.includes((o=t.params)==null?void 0:o.style.type))return{redos:[],undos:[]};const r=(s=e.getCurrentSelections())==null?void 0:s.map(l=>l.range);return r!=null&&r.length?this.getUndoRedoParamsOfAutoHeight(r):{redos:[],undos:[]}}})),this.disposeWithMe(i.interceptAfterCommand({getMutations:t=>{if(t.id===m.MoveRangeCommand.id){const r=t.params;return this.getUndoRedoParamsOfAutoHeight([r.fromRange,r.toRange])}if(t.id===m.ReorderRangeCommand.id){const r=t.params;return this.getUndoRedoParamsOfAutoHeight([r.range])}return{redos:[],undos:[]}}}))}};exports.AutoHeightController=Od([Hr(0,w.IRenderManagerService),Hr(1,a.Inject(m.SheetInterceptorService)),Hr(2,a.Inject(m.SheetsSelectionsService)),Hr(3,a.Inject(a.IUniverInstanceService))],exports.AutoHeightController);function gn(n,i,e,t){const r=i.get(a.IUniverInstanceService),o=e?r.getUnit(e,a.UniverInstanceType.UNIVER_SHEET):r.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=t?o==null?void 0:o.getSheetBySheetId(t):o==null?void 0:o.getActiveSheet();if(!s)return null;const{startRow:l,endRow:d,startColumn:c,endColumn:u}=n,h=[],g=[];for(let S=l;S<=d;S++)s.getRowFiltered(S)||h.push(S);for(let S=c;S<=u;S++)g.push(S);return{rows:h,cols:g}}function Et(n){const{rows:i,cols:e}=n;return{startRow:i[0],endRow:i[i.length-1],startColumn:e[0],endColumn:e[e.length-1]}}function Kt(n){let i=[],e=[];const t=[];return n.forEach(r=>{i=i.concat(r.rows),e=e.concat(r.cols)}),i=Array.from(new Set(i)).sort((r,o)=>r-o),e=Array.from(new Set(e)).sort((r,o)=>r-o),n.forEach(r=>{t.push({startRow:i.findIndex(o=>o===r.rows[0]),endRow:i.findIndex(o=>o===r.rows[r.rows.length-1]),startColumn:e.findIndex(o=>o===r.cols[0]),endColumn:e.findIndex(o=>o===r.cols[r.cols.length-1])})}),{ranges:t,mapFunc:(r,o)=>({row:i[r],col:e[o]})}}function xd(n){const i=new a.ObjectMatrix;return n.forEach(e=>{const{rows:t,cols:r}=e;t.forEach(o=>{r.forEach(s=>{i.setValue(o,s,{v:null,p:null,f:null,si:null,custom:null})})})}),i.getData()}const ko={零:0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9},Jr=["零","一","二","三","四","五","六","七","八","九"],Fs=["","万","亿","万亿","亿亿"],Ad=["","十","百","千"],za={十:{value:10,secUnit:!1},百:{value:100,secUnit:!1},千:{value:1e3,secUnit:!1},万:{value:1e4,secUnit:!0},亿:{value:1e8,secUnit:!0}};function ut(n){if(!n)return 0;let i=0,e=0,t=0,r=!1;const o=n.split("");for(let s=0;s<o.length;s++){const l=ko[o[s]];if(typeof l<"u")t=l,s===o.length-1&&(e+=t);else{const d=za[o[s]],c=d.value;r=d.secUnit,r?(e=(e+t)*c,i+=e,e=0):e+=t*c,t=0}}return i+e}function Nd(n){let i="",e="",t=0,r=!0;for(;n>0;){const o=n%10;o===0?r||(r=!0,e=Jr[o]+e):(r=!1,i=Jr[o],i+=Ad[t],e=i+e),t++,n=Math.floor(n/10)}return e}function Dd(n){let i=0,e="",t="",r=!1;if(n===0)return Jr[0];for(;n>0;){const o=n%1e4;r&&(t=Jr[0]+t),e=Nd(o),e+=o!==0?Fs[i]:Fs[0],t=e+t,r=o<1e3&&o>0,n=Math.floor(n/1e4),i++}return t}function Hd(n){if(!n)return!1;let i=!0;if(n)if(n.length===1)n==="日"||n in ko?i=!0:i=!1;else{const e=n.split("");for(let t=0;t<e.length;t++)if(!(e[t]in ko||e[t]in za)){i=!1;break}}return i}function kr(n){if(!n)return{isExtendNumber:!1};const i=/0|([1-9]+[0-9]*)/g,e=i.test(n);if(e){const t=n.match(i);if(t&&t.length>0){const r=t[t.length-1],o=n.lastIndexOf(r),s=n.substr(0,o),l=n.substr(o+r.length);return{isExtendNumber:!0,matchTxt:Number(r),beforeTxt:s,afterTxt:l}}return{isExtendNumber:!1}}return{isExtendNumber:e}}function kd(n){let i;return n.length===2&&(n==="周一"||n==="周二"||n==="周三"||n==="周四"||n==="周五"||n==="周六"||n==="周日")?i=!0:i=!1,i}function Vd(n){let i;return n.length===3&&(n==="星期一"||n==="星期二"||n==="星期三"||n==="星期四"||n==="星期五"||n==="星期六"||n==="星期日")?i=!0:i=!1,i}function Wd(n,i){let e=0;for(let t=0;t<n.length&&n[t]<i;t++)e++;return e}function cr(n){let i=!0;const e=n[1]-n[0];for(let t=1;t<n.length;t++)if(n[t]-n[t-1]!==e){i=!1;break}return i}function Ud(n,i,e){const t=[],r=Math.floor(i/n),o=i%n;let s=0;if(r>0){for(let l=0;l<r;l++)for(let d=0;d<e.length;d++)t[e[d]+l*n]=s,s++;for(let l=0;l<e.length&&e[l]<o;l++)t[e[l]+n*r]=s,s++}else for(let l=0;l<e.length&&e[l]<o;l++)t[e[l]]=s,s++;return t}function jt(n,i){const e=[];for(let t=1;t<=i;t++){const r=(t-1)%n.length,o=a.Tools.deepClone(n[r]);zt(o),e.push({v:null,s:null,p:null,f:null,si:null,t:null,...o})}return e}function Ld(n,i){var t;const e=[];for(let r=1;r<=i;r++){const o=(r-1)%n.length,s={s:(t=n[o])==null?void 0:t.s};e.push(s)}return e}function Bd(n){let i=!0;const e=n[1]/n[0];for(let t=1;t<n.length;t++)if(n[t]/n[t-1]!==e){i=!1;break}return i}function Fd(n){const i=[];for(let e=1;e<=n;e++)i.push(e);return i}function $r(n,i,e){var o,s,l,d;const t=[],r=[];for(let c=0;c<n.length;c++)r.push(Number((o=n[c])==null?void 0:o.v));if(n.length>2&&Bd(r))for(let c=1;c<=i;c++){const u=(c-1)%n.length,h=a.Tools.deepClone(n[u]);zt(h);const g=Number((s=n[n.length-1])==null?void 0:s.v)*(Number((l=n[1])==null?void 0:l.v)/Number((d=n[0])==null?void 0:d.v))**c;h&&(Ys(h)&&(h.v=g),t.push(h))}else{const c=Fd(n.length);for(let u=1;u<=i;u++){const h=(u-1)%n.length,g=a.Tools.deepClone(n[h]);zt(g);const S=e===a.Direction.DOWN||e===a.Direction.RIGHT,f=jd(n.length+u,r,c,S);g&&(Ys(g)&&(g.v=f),t.push(g))}}return t}function jd(n,i,e,t=!0){function r(h){let g=0;for(let S=0;S<h.length;S++)g+=h[S];return g/h.length}const o=r(e),s=r(i);let l=0,d=0;for(let h=0;h<e.length;h++)l+=(e[h]-o)*(i[h]-s),d+=(e[h]-o)*(e[h]-o);let c;d===0?c=t?1:-1:c=l/d;const u=s-c*o;return Math.round((u+c*n)*1e5)/1e5}function js(n,i,e){var o;const t=[],r=/0|([1-9]+[0-9]*)/g;for(let s=1;s<=i;s++){const l=(s-1)%n.length,d=a.Tools.deepClone(n[l]);zt(d);const c=`${(o=n[n.length-1])==null?void 0:o.v}`,u=c==null?void 0:c.match(r),h=u==null?void 0:u[u.length-1],g=Math.abs(Number(h)+e*s);if(!c||!h)continue;const S=c.lastIndexOf(h),f=c.substr(0,S)+g.toString()+c.substr(S+h.length);d&&(d.v=f,t.push(d))}return t}function bn(n,i,e,t=0){var l,d;const r=[["日","一","二","三","四","五","六"],["周日","周一","周二","周三","周四","周五","周六"],["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]];if(t>=r.length)return[];const o=r[t],s=[];for(let c=1;c<=i;c++){const u=(c-1)%n.length,h=a.Tools.deepClone(n[u]);zt(h);let g=0;if(((l=n[n.length-1])==null?void 0:l.v)===o[0])g=7+e*c;else{const f=`${(d=n[n.length-1])==null?void 0:d.v}`;if(f){const p=f.substr(f.length-1,1);g=ut(p)+e*c}}g<0&&(g=Math.ceil(Math.abs(g)/7)*7+g);const S=g%7;h&&(h.v=o[S],s.push(h))}return s}function zs(n,i,e){var r;const t=[];for(let o=1;o<=i;o++){const s=(o-1)%n.length,l=a.Tools.deepClone(n[s]);zt(l);const d=`${(r=n[n.length-1])==null?void 0:r.v}`,c=ut(d)+e*o;let u;c<=0?u="零":u=Dd(c),l&&(l.v=u,t.push(l))}return t}const Zn={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 zd(n){let i=!1;return Object.keys(Zn).forEach(e=>{Zn[e].includes(n)&&(i=!0)}),i}function Fi(n){let i="";const e=[];return Object.keys(Zn).forEach(t=>{Zn[t].includes(n)&&(i=t,e.push(...Zn[t]))}),{name:i,series:e}}function Xs(n,i,e,t){var s;const r=t.length,o=[];for(let l=1;l<=i;l++){const d=(l-1)%n.length,c=a.Tools.deepClone(n[d]);zt(c);const u=`${(s=n[n.length-1])==null?void 0:s.v}`;let h=t.indexOf(u)+e*l;h<0&&(h+=Math.abs(e)*r);const g=h%r;c&&(c.v=t[g],o.push(c))}return o}function Xd(n,i){const e=[];let t;if(i.startRow<n.startRow)t=a.Direction.UP;else if(i.endRow>n.endRow)t=a.Direction.DOWN;else if(i.startColumn<n.startColumn)t=a.Direction.LEFT;else if(i.endColumn>n.endColumn)t=a.Direction.RIGHT;else return[];if(t===a.Direction.DOWN||t===a.Direction.UP){const r=n.endRow-n.startRow+1,o=i.endRow-i.startRow+1,s=Math.floor(o/r),l=o%r,d={startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:n.endColumn-n.startColumn};if(t===a.Direction.DOWN){for(let c=0;c<s;c++)e.push({repeatStartCell:{row:n.startRow+(c+1)*r,col:n.startColumn},relativeRange:d});l>0&&e.push({repeatStartCell:{row:n.startRow+(s+1)*r,col:n.startColumn},relativeRange:{startRow:0,startColumn:0,endRow:l-1,endColumn:n.endColumn-n.startColumn}})}else{for(let c=0;c<s;c++)e.push({repeatStartCell:{row:n.startRow-(c+1)*r,col:n.startColumn},relativeRange:d});l>0&&e.push({repeatStartCell:{row:n.startRow-(s+1)*r,col:n.startColumn},relativeRange:{startRow:r-l,endRow:r-1,startColumn:0,endColumn:n.endColumn-n.startColumn}})}}if(t===a.Direction.RIGHT||t===a.Direction.LEFT){const r=n.endColumn-n.startColumn+1,o=i.endColumn-i.startColumn+1,s=Math.floor(o/r),l=o%r,d={startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:n.endColumn-n.startColumn};if(t===a.Direction.RIGHT){for(let c=0;c<s;c++)e.push({repeatStartCell:{row:n.startRow,col:n.startColumn+(c+1)*r},relativeRange:d});l>0&&e.push({repeatStartCell:{row:n.startRow,col:n.startColumn+(s+1)*r},relativeRange:{startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:l-1}})}else{for(let c=0;c<s;c++)e.push({repeatStartCell:{row:n.startRow,col:n.startColumn-(c+1)*r},relativeRange:d});l>0&&e.push({repeatStartCell:{row:n.startRow,col:n.startColumn-(s+1)*r},relativeRange:{startRow:0,startColumn:r-l,endRow:n.endRow-n.startRow,endColumn:r-1}})}}return e}function Ys(n){return!(a.isFormulaString(n.f)||a.isFormulaId(n.si)||n.t===a.CellValueType.BOOLEAN)}function zt(n){n&&"custom"in n&&delete n.custom}var hn=(n=>(n.Append="APPEND",n.Default="DEFAULT",n.Only="ONLY",n))(hn||{}),_e=(n=>(n.NUMBER="number",n.DATE="date",n.EXTEND_NUMBER="extendNumber",n.CHN_NUMBER="chnNumber",n.CHN_WEEK2="chnWeek2",n.CHN_WEEK3="chnWeek3",n.LOOP_SERIES="loopSeries",n.FORMULA="formula",n.OTHER="other",n))(_e||{}),ae=(n=>(n.COPY="COPY",n.SERIES="SERIES",n.ONLY_FORMAT="ONLY_FORMAT",n.NO_FORMAT="NO_FORMAT",n))(ae||{});const Yd={type:_e.DATE,priority:1100,match:(n,i)=>{var e;if(n!=null&&n.f||n!=null&&n.si)return!1;if((typeof(n==null?void 0:n.v)=="number"||(n==null?void 0:n.t)===a.CellValueType.NUMBER)&&n.s){if(typeof n.s=="string"){const r=i.get(a.IUniverInstanceService).getFocusedUnit().getStyles().get(n.s),o=(e=r==null?void 0:r.n)==null?void 0:e.pattern;if(o)return a.numfmt.getInfo(o).isDate}else if(n.s.n&&a.numfmt.getInfo(n.s.n.pattern).isDate)return!0}return!1},isContinue:(n,i)=>n.type===_e.DATE,applyFunctions:{[ae.SERIES]:(n,i,e)=>{const{data:t}=n;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),$r(t,i,e).reverse()):$r(t,i,e)}}},Gd={type:_e.NUMBER,priority:1e3,match:n=>typeof(n==null?void 0:n.v)=="number"||(n==null?void 0:n.t)===a.CellValueType.NUMBER,isContinue:(n,i)=>n.type===_e.NUMBER,applyFunctions:{[ae.SERIES]:(n,i,e)=>{const{data:t}=n;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),$r(t,i,e).reverse()):$r(t,i,e)}}},Xa={type:_e.OTHER,priority:0,match:()=>!0,isContinue:(n,i)=>n.type===_e.OTHER},Zd={type:_e.EXTEND_NUMBER,priority:900,match:n=>kr(`${n==null?void 0:n.v}`||"").isExtendNumber,isContinue:(n,i)=>{var e;if(n.type===_e.EXTEND_NUMBER){const{beforeTxt:t,afterTxt:r}=kr(`${(e=n.cellData)==null?void 0:e.v}`||""),{beforeTxt:o,afterTxt:s}=kr(`${i==null?void 0:i.v}`||"");if(t===o&&r===s)return!0}return!1},applyFunctions:{[ae.SERIES]:(n,i,e)=>{var l;const{data:t}=n,r=e===a.Direction.UP||e===a.Direction.LEFT;let o;if(t.length===1)return o=r?-1:1,Ue(js(t,i,o),r);const s=[];for(let d=0;d<t.length;d++){const c=`${(l=t[d])==null?void 0:l.v}`;c&&s.push(Number(kr(c).matchTxt))}return r&&(t.reverse(),s.reverse()),cr(s)?(o=s[1]-s[0],Ue(js(t,i,o),r)):jt(t,i)}}},Kd={type:_e.CHN_NUMBER,priority:830,match:n=>!!Hd(`${n==null?void 0:n.v}`||""),isContinue:(n,i)=>n.type===_e.CHN_NUMBER,applyFunctions:{[ae.SERIES]:(n,i,e)=>{var d,c,u;const{data:t}=n,r=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){const h=`${(d=t[0])==null?void 0:d.v}`;let g;return r?g=-1:g=1,h&&(h==="日"||ut(h)<7)?Ue(bn(t,i,g),r):Ue(zs(t,i,g),r)}let o=!1;for(let h=0;h<t.length;h++)if(((c=t[h])==null?void 0:c.v)==="日"){o=!0;break}const s=[];let l=0;for(let h=0;h<t.length;h++){const g=`${(u=t[h])==null?void 0:u.v}`;g==="日"?h===0?s.push(0):(l++,s.push(l*7)):o&&ut(g)>0&&ut(g)<7?s.push(ut(g)+l*7):s.push(ut(g))}if(r&&(t.reverse(),s.reverse()),cr(s)){if(o||s[s.length-1]<6&&s[0]>0||s[0]<6&&s[s.length-1]>0){const g=s[1]-s[0];return Ue(bn(t,i,g),r)}const h=s[1]-s[0];return Ue(zs(t,i,h),r)}return jt(t,i)}}},qd={type:_e.CHN_WEEK2,priority:820,match:n=>!!kd(`${n==null?void 0:n.v}`||""),isContinue:(n,i)=>n.type===_e.CHN_WEEK2,applyFunctions:{[ae.SERIES]:(n,i,e)=>{var l;const{data:t}=n,r=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let d;return r?d=-1:d=1,Ue(bn(t,i,d,1),r)}const o=[];let s=0;for(let d=0;d<t.length;d++){const c=`${(l=t[d])==null?void 0:l.v}`,u=c==null?void 0:c.substr(c.length-1,1);c==="周日"?d===0?o.push(0):(s++,o.push(s*7)):o.push(ut(u)+s*7)}if(r&&(t.reverse(),o.reverse()),cr(o)){const d=o[1]-o[0];return Ue(bn(t,i,d,1),r)}return jt(t,i)}}},Qd={type:_e.CHN_WEEK3,priority:810,match:n=>Vd(`${n==null?void 0:n.v}`||""),isContinue:(n,i)=>n.type===_e.CHN_WEEK3,applyFunctions:{[ae.SERIES]:(n,i,e)=>{var l;const{data:t}=n,r=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let d;return r?d=-1:d=1,Ue(bn(t,i,d,2),r)}const o=[];let s=0;for(let d=0;d<t.length;d++){const c=`${(l=t[d])==null?void 0:l.v}`;if(c){const u=c.substr(c.length-1,1);c==="星期日"?d===0?o.push(0):(s++,o.push(s*7)):o.push(ut(u)+s*7)}}if(r&&(t.reverse(),o.reverse()),cr(o)){const d=o[1]-o[0];return Ue(bn(t,i,d,2),r)}return jt(t,i)}}},Jd={type:_e.LOOP_SERIES,priority:800,match:n=>zd(`${n==null?void 0:n.v}`||""),isContinue:(n,i)=>{var e;return n.type===_e.LOOP_SERIES?Fi(`${(e=n.cellData)==null?void 0:e.v}`||"").name===Fi(`${i==null?void 0:i.v}`||"").name:!1},applyFunctions:{[ae.SERIES]:(n,i,e)=>{var d,c;const{data:t}=n,r=e===a.Direction.LEFT||e===a.Direction.UP,{series:o}=Fi(`${(d=t[0])==null?void 0:d.v}`||"");if(t.length===1){let u;return r?u=-1:u=1,Ue(Xs(t,i,u,o),r)}const s=[];let l=0;for(let u=0;u<t.length;u++){const h=`${(c=t[u])==null?void 0:c.v}`;h&&(h===o[0]?u===0?s.push(0):(l++,s.push(l*o.length)):s.push(o.indexOf(h)+l*7))}if(r&&(t.reverse(),s.reverse()),cr(s)){const u=s[1]-s[0];return Ue(Xs(t,i,u,o),r)}return jt(t,i)}}};function Ue(n,i){return i?n.reverse():n}var $d=Object.defineProperty,eu=Object.getOwnPropertyDescriptor,tu=(n,i,e,t)=>{for(var r=t>1?void 0:t?eu(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&$d(i,e,r),r},rn=(n,i)=>(e,t)=>i(e,t,n);exports.AutoFillService=class extends a.Disposable{constructor(e,t,r,o,s,l){super();R(this,"_rules",[]);R(this,"_hooks",[]);R(this,"_applyType$",new O.BehaviorSubject(ae.SERIES));R(this,"_isFillingStyle",!0);R(this,"_prevUndos",[]);R(this,"_autoFillLocation$",new O.BehaviorSubject(null));R(this,"autoFillLocation$",this._autoFillLocation$.asObservable());R(this,"_showMenu$",new O.BehaviorSubject(!1));R(this,"showMenu$",this._showMenu$.asObservable());R(this,"_direction",a.Direction.DOWN);R(this,"applyType$",this._applyType$.asObservable());R(this,"_menu$",new O.BehaviorSubject([{label:"autoFill.copy",value:ae.COPY,disable:!1},{label:"autoFill.series",value:ae.SERIES,disable:!1},{label:"autoFill.formatOnly",value:ae.ONLY_FORMAT,disable:!1},{label:"autoFill.noFormat",value:ae.NO_FORMAT,disable:!1}]));R(this,"menu$",this._menu$.asObservable());this._commandService=e,this._undoRedoService=t,this._renderManagerService=r,this._univerInstanceService=o,this._selectionManagerService=s,this._injector=l,this._init()}_init(){this._rules=[Yd,Gd,Zd,Kd,qd,Qd,Jd,Xa].sort((e,t)=>t.priority-e.priority),this._isFillingStyle=!0}_getOneByPriority(e){return e.length<=0?[]:[e.reduce((r,o)=>(o.priority||0)>(r.priority||0)?o:r,e[0])]}_initPrevUndo(){this._prevUndos=[]}async triggerAutoFill(e,t,r,o){var S;if(r.startColumn===o.startColumn&&r.startRow===o.startRow&&r.endColumn===o.endColumn&&r.endRow===o.endRow)return!1;if(o.endColumn<r.endColumn&&o.endColumn>r.startColumn)return this._commandService.executeCommand(Rn.id,{clearRange:{startRow:o.startRow,endRow:o.endRow,startColumn:o.endColumn+1,endColumn:r.endColumn},selectionRange:o});if(o.endRow<r.endRow&&o.endRow>r.startRow)return this._commandService.executeCommand(Rn.id,{clearRange:{startRow:o.endRow+1,endRow:r.endRow,startColumn:o.startColumn,endColumn:o.endColumn},selectionRange:o});const s={startRow:o.startRow,endRow:o.endRow,startColumn:o.startColumn,endColumn:o.endColumn};let l=null;if(o.startRow<r.startRow)l=a.Direction.UP,s.endRow=r.startRow-1;else if(o.endRow>r.endRow)l=a.Direction.DOWN,s.startRow=r.endRow+1;else if(o.startColumn<r.startColumn)l=a.Direction.LEFT,s.endColumn=r.startColumn-1;else if(o.endColumn>r.endColumn)l=a.Direction.RIGHT,s.startColumn=r.endColumn+1;else return!1;this.direction=l;const d=this._injector.invoke(f=>gn(r,f)),c=this._injector.invoke(f=>gn(s,f));if(!d||!c)return!1;this.autoFillLocation={source:d,target:c,unitId:e,subUnitId:t};const u=[];this.getActiveHooks().forEach(f=>{var v;const p=(v=f==null?void 0:f.onBeforeFillData)==null?void 0:v.call(f,{source:d,target:c,unitId:e,subUnitId:t},l);p&&u.unshift(p)}),this._initPrevUndo();for(let f=0;f<u.length;f++){const p=this.menu.find(v=>v.value===u[f]);if(p&&!p.disable)return this.fillData(u[f])}const g=(S=this.menu.find(f=>f.disable===!1))==null?void 0:S.value;return g?this.fillData(g):!1}addHook(e){if(this._hooks.find(t=>t.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=hn.Append),this._hooks.push(e),a.toDisposable(()=>{const t=this._hooks.findIndex(r=>r===e);t>-1&&this._hooks.splice(t,1)})}registerRule(e){if(this._rules.find(r=>r.type===e.type))throw new Error(`Registry rule failed, type '${e.type}' already exist!`);const t=this._rules.findIndex(r=>r.priority<e.priority);this._rules.splice(t===-1?this._rules.length:t,0,e)}getRules(){return this._rules}getAllHooks(){return this._hooks}getActiveHooks(){const{source:e,target:t,unitId:r,subUnitId:o}=this.autoFillLocation||{};if(!e||!t||!r||!o)return[];const s=this._hooks.filter(u=>{var h;return!((h=u.disable)!=null&&h.call(u,{source:e,target:t,unitId:r,subUnitId:o},this._direction,this.applyType))}),l=s.filter(u=>u.type===hn.Only);if(l.length>0)return this._getOneByPriority(l);const d=this._getOneByPriority(s.filter(u=>u.type===hn.Default)),c=s.filter(u=>u.type===hn.Append)||[];return[...d,...c]}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,t){this._menu$.next(this._menu$.getValue().map(r=>r.value===e?{...r,disable:t}:r))}setShowMenu(e){this._showMenu$.next(e)}fillData(e){var C,I,b;this.applyType=e;const{source:t,target:r,unitId:o=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId(),subUnitId:s=(C=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:C.getSheetId()}=this.autoFillLocation||{};if(!t||!r||!o||!s)return!1;const l=this.direction;this._prevUndos.length>0&&this._prevUndos.forEach(T=>{this._commandService.syncExecuteCommand(T.id,T.params)}),this._prevUndos=[];const d=a.Rectangle.union(Et(t),Et(r)),c=this.getActiveHooks(),u=this._univerInstanceService.getUnit(o,a.UniverInstanceType.UNIVER_SHEET);this._commandService.syncExecuteCommand(m.SetSelectionsOperation.id,{selections:[{primary:{...(b=(I=this._selectionManagerService.getCurrentLastSelection())==null?void 0:I.primary)!=null?b:d},range:{...d,rangeType:a.RANGE_TYPE.NORMAL}}],unitId:o,subUnitId:s});const h=[],g=[];c.forEach(T=>{var P;const{undos:M,redos:y}=((P=T.onFillData)==null?void 0:P.call(T,{source:t,target:r,unitId:o,subUnitId:s},l,e))||{};M&&h.push(...M),y&&g.push(...y)});const S=g.every(T=>this._commandService.syncExecuteCommand(T.id,T.params)),f=[];e!==ae.NO_FORMAT&&g.forEach(T=>{if(T.id===m.SetRangeValuesMutation.id){const{cellValue:M}=T.params;new a.ObjectMatrix(M).forValue((P,x,A)=>{const N=Object.keys(u.getStyles().get(A==null?void 0:A.s)||{});(A!=null&&A.p||N.length&&us.some(D=>N.includes(D)))&&f.push({startRow:P,endRow:P,startColumn:x,endColumn:x})})}});const p=this._getAutoHeightUndoRedos(o,s,f);return p.redos.every(T=>this._commandService.syncExecuteCommand(T.id,T.params))&&(h.push(...p.undos),g.push(...p.redos)),S&&(this._prevUndos=h,this._undoRedoService.pushUndoRedo({unitID:o,undoMutations:h,redoMutations:g})),c.forEach(T=>{var M;(M=T.onAfterFillData)==null||M.call(T,{source:t,target:r,unitId:o,subUnitId:s},l,e)}),this.setShowMenu(!0),!0}_getAutoHeightUndoRedos(e,t,r){var h,g;const o=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(exports.SheetSkeletonManagerService),s=(g=o==null?void 0:o.getCurrent())==null?void 0:g.skeleton;if(!s)return{redos:[],undos:[]};const l=s.calculateAutoHeightInRange(r),d={subUnitId:t,unitId:e,rowsAutoHeightInfo:l},c=s.worksheet,u=m.SetWorksheetRowAutoHeightMutationFactory(d,c);return{undos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:u}],redos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:d}]}}};exports.AutoFillService=tu([rn(0,a.ICommandService),rn(1,a.IUndoRedoService),rn(2,w.IRenderManagerService),rn(3,a.Inject(a.IUniverInstanceService)),rn(4,a.Inject(m.SheetsSelectionsService)),rn(5,a.Inject(a.Injector))],exports.AutoFillService);const Tt=a.createIdentifier("univer.auto-fill-service"),_t={type:a.CommandType.COMMAND,id:"sheet.command.auto-fill",handler:async(n,i)=>{const e=n.get(Tt),t=n.get(a.IUniverInstanceService),{sourceRange:r,targetRange:o}=i,s=m.getSheetCommandTarget(t);if(!s)return!1;const{subUnitId:l,unitId:d}=s;return e.triggerAutoFill(d,l,r,o)}},Rn={id:"sheet.command.auto-clear-content",type:a.CommandType.COMMAND,handler:async(n,i)=>{const e=n.get(a.IUniverInstanceService),t=n.get(a.ICommandService),r=n.get(a.IUndoRedoService),o=n.get(m.SheetInterceptorService),s=m.getSheetCommandTarget(e);if(!s)return!1;const{unitId:l,subUnitId:d}=s,{clearRange:c,selectionRange:u}=i,h={subUnitId:d,unitId:l,cellValue:m.generateNullCellValue([c])},g=m.SetRangeValuesUndoMutationFactory(n,h),{startColumn:S,startRow:f}=u,p={selections:[{primary:{startColumn:S,startRow:f,endColumn:S,endRow:f,actualRow:f,actualColumn:S,isMerged:!1,isMergedMainCell:!1},range:{...u}}],unitId:l,subUnitId:d};if(t.executeCommand(m.SetSelectionsOperation.id,p),t.syncExecuteCommand(m.SetRangeValuesMutation.id,h)){const C=o.afterCommandExecute({id:m.SetRangeValuesMutation.id,params:h});return a.sequenceExecute(C.redos,t),r.pushUndoRedo({unitID:l,undoMutations:[{id:m.SetRangeValuesMutation.id,params:g},...C.undos],redoMutations:[{id:m.SetRangeValuesMutation.id,params:h},...C.redos]}),!0}return!1}},dr={id:"sheet.command.refill",type:a.CommandType.COMMAND,handler:async(n,i)=>n.get(Tt).fillData(i.type)};var nu=Object.defineProperty,ru=Object.getOwnPropertyDescriptor,iu=(n,i,e,t)=>{for(var r=t>1?void 0:t?ru(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&nu(i,e,r),r},Pt=(n,i)=>(e,t)=>i(e,t,n);exports.EditorBridgeService=class extends a.Disposable{constructor(e,t,r,o,s,l,d){super();R(this,"_editorUnitId",a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);R(this,"_editorIsDirty",!1);R(this,"_isDisabled",!1);R(this,"_visible",{visible:!1,eventType:w.DeviceInputEventType.Dblclick,unitId:""});R(this,"_currentEditCell",null);R(this,"_currentEditCellState",null);R(this,"_currentEditCellLayout",null);R(this,"_currentEditCellState$",new O.BehaviorSubject(null));R(this,"currentEditCellState$",this._currentEditCellState$.asObservable());R(this,"_currentEditCellLayout$",new O.BehaviorSubject(null));R(this,"currentEditCellLayout$",this._currentEditCellLayout$.asObservable());R(this,"currentEditCell$",this._currentEditCellState$.pipe(O.switchMap(e=>this._currentEditCellLayout$.pipe(O.map(t=>e&&t?{...e,...t}:null)))));R(this,"_visible$",new O.BehaviorSubject(this._visible));R(this,"visible$",this._visible$.asObservable());R(this,"_afterVisible$",new O.BehaviorSubject(this._visible));R(this,"afterVisible$",this._afterVisible$.asObservable());R(this,"_forceKeepVisible$",new O.BehaviorSubject(!1));R(this,"forceKeepVisible$",this._forceKeepVisible$.asObservable());this._sheetInterceptorService=e,this._renderManagerService=t,this._themeService=r,this._univerInstanceService=o,this._editorService=s,this._refSelectionsService=l,this._contextService=d,this.disposeWithMe(a.toDisposable(()=>{this._currentEditCellState$.complete(),this._currentEditCell=null})),this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).subscribe(c=>{var u;c.getUnitId()===((u=this._currentEditCellState)==null?void 0:u.unitId)&&this._clearCurrentEditCellState()})}refreshEditCellState(){const e=this.getLatestEditCellState();if(!e){this._currentEditCellState=null,this._currentEditCellLayout=null,this._currentEditCellState$.next(null),this._currentEditCellLayout$.next(null);return}const{position:t,scaleX:r,scaleY:o,canvasOffset:s,...l}=e;this._currentEditCellState=l,this._currentEditCellLayout={position:t,scaleX:r,scaleY:o,canvasOffset:s},this._currentEditCellState$.next(this._currentEditCellState),this._currentEditCellLayout$.next(this._currentEditCellLayout)}refreshEditCellPosition(e){var y;const t=this._currentEditCell;if(t==null)return;const r=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET);if(!r)return;const o=(y=r.with(exports.SheetSkeletonManagerService).getWorksheetSkeleton(t.sheetId))==null?void 0:y.skeleton,s=r.with(ve);if(!o||!this._currentEditCellState)return;const{primary:l,unitId:d,sheetId:c,scene:u,engine:h}=t,g=Qn(o,l);if(g==null)return;const S=a.convertCellToRange(g),f=J.getCanvasOffsetByEngine(h);let{startX:p,startY:v,endX:C,endY:I}=S;const{scaleX:b,scaleY:T}=u.getAncestorScale(),M=u.getViewportScrollXY(s.getViewPort());p=o.convertTransformToOffsetX(p,b,M),v=o.convertTransformToOffsetY(v,T,M),C=o.convertTransformToOffsetX(C,b,M),I=o.convertTransformToOffsetY(I,T,M),e&&this._currentEditCellLayout&&(C=C-p+this._currentEditCellLayout.position.startX,I=I-v+this._currentEditCellLayout.position.startY,p=this._currentEditCellLayout.position.startX,v=this._currentEditCellLayout.position.startY),this._currentEditCellLayout={position:{startX:p,startY:v,endX:C,endY:I},canvasOffset:f,scaleX:b,scaleY:T},this._currentEditCellLayout$.next(this._currentEditCellLayout)}setEditCell(e){this._currentEditCell=e,this._editorService.getFocusEditor()||(this._editorService.focus(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._contextService.setContextValue(a.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(a.FOCUSING_EDITOR_STANDALONE,!1));const t=this.getLatestEditCellState();if(!t){this._currentEditCellState=t,this._currentEditCellLayout=t,this._currentEditCellState$.next(t),this._currentEditCellLayout$.next(t);return}const{position:r,canvasOffset:o,scaleX:s,scaleY:l,...d}=t;this._currentEditCellState=d,this._currentEditCellLayout={position:r,canvasOffset:o,scaleX:s,scaleY:l},this._currentEditCellState$.next(this._currentEditCellState),this._currentEditCellLayout$.next(this._currentEditCellLayout)}_clearCurrentEditCellState(){this._currentEditCellState=null,this._currentEditCellState$.next(null),this._currentEditCellLayout=null,this._currentEditCellLayout$.next(null)}getEditCellState(){return this._currentEditCellState==null||this._currentEditCellLayout==null?null:{...this._currentEditCellState,...this._currentEditCellLayout}}getEditCellLayout(){return this._currentEditCellLayout}getEditLocation(){return this._currentEditCellState}getLatestEditCellState(){var W,k,U;const e=this._currentEditCell;if(e==null)return;const t=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET);if(!t)return;const r=t.with(exports.SheetSkeletonManagerService).getCurrentSkeleton(),o=t.with(ve);if(!r)return;const{primary:s,unitId:l,sheetId:d,scene:c,engine:u}=e,{startRow:h,startColumn:g}=s,S=Qn(r,s);if(S==null)return;const f=a.convertCellToRange(S),p=J.getCanvasOffsetByEngine(u);let{startX:v,startY:C,endX:I,endY:b}=f;const{scaleX:T,scaleY:M}=c.getAncestorScale(),y=c.getViewportScrollXY(o.getViewPort());v=r.convertTransformToOffsetX(v,T,y),C=r.convertTransformToOffsetY(C,M,y),I=r.convertTransformToOffsetX(I,T,y),b=r.convertTransformToOffsetY(b,M,y);const P=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),x=P.getActiveSheet();if(!x)return;const A={workbook:P,worksheet:x,unitId:P.getUnitId(),subUnitId:x.getSheetId(),row:h,col:g,origin:x.getCellRaw(h,g)};let N;const D=this._sheetInterceptorService.writeCellInterceptor.fetchThroughInterceptors(m.BEFORE_CELL_EDIT)(x.getCell(h,g),A);N=D&&r.getCellDocumentModelWithFormula(D);const H=(W=N==null?void 0:N.documentModel)==null?void 0:W.documentStyle.renderConfig;if(H!=null&&(H.cellValueType=a.CellValueType.STRING),!N||N.documentModel==null){const B=r.getBlankCellDocumentModel(D);if(N!=null){const{verticalAlign:F,horizontalAlign:L,wrapStrategy:z,textRotation:X,fill:Z}=N,{centerAngle:re,vertexAngle:Q}=w.convertTextRotation(X);B.documentModel.documentStyle.renderConfig={...H,verticalAlign:F,horizontalAlign:L,wrapStrategy:z,background:{rgb:Z},centerAngle:re,vertexAngle:Q}}N=B}if(N.fill=N.fill||"#fff",(k=N.documentModel)==null||k.setZoomRatio(Math.max(T,M)),(D==null?void 0:D.isInArrayFormulaRange)===!0){const B=(U=N.documentModel)==null?void 0:U.getBody();B&&(B.textRuns=[{st:0,ed:B.dataStream.length-2,ts:{cl:{rgb:this._themeService.getCurrentTheme().textColorSecondary}}}])}return{position:{startX:v,startY:C,endX:I,endY:b},scaleX:T,scaleY:M,canvasOffset:p,row:h,column:g,unitId:l,sheetId:d,documentLayoutObject:N,editorUnitId:this._editorUnitId,isInArrayFormulaRange:D==null?void 0:D.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._forceKeepVisible$.next(!0)}disableForceKeepVisible(){this._forceKeepVisible$.next(!1)}isForceKeepVisible(){return this._forceKeepVisible$.getValue()}changeEditorDirty(e){this._editorIsDirty=e}getEditorDirty(){return this._editorIsDirty}};exports.EditorBridgeService=iu([Pt(0,a.Inject(m.SheetInterceptorService)),Pt(1,w.IRenderManagerService),Pt(2,a.Inject(a.ThemeService)),Pt(3,a.IUniverInstanceService),Pt(4,J.IEditorService),Pt(5,m.IRefSelectionsService),Pt(6,a.IContextService)],exports.EditorBridgeService);const Se=a.createIdentifier("univer.sheet-editor-bridge.service"),Te={id:"sheet.operation.set-cell-edit-visible",type:a.CommandType.OPERATION,handler:(n,i)=>i?(n.get(Se).changeVisible(i),!0):!1},ur={id:"sheet.operation.set-cell-edit-visible-f2",type:a.CommandType.OPERATION,handler:(n,i)=>{const e=n.get(a.ICommandService),r=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);return r?(e.syncExecuteCommand(Te.id,{...i,unitId:r.getUnitId()}),!0):!1}},Xt={id:"sheet.operation.set-cell-edit-visible-arrow",type:a.CommandType.OPERATION,handler:()=>!0},An={id:"sheet.command.change-zoom-ratio",type:a.CommandType.COMMAND,handler:(n,i)=>{if(!i)return!1;const e=n.get(a.IUniverInstanceService),t=m.getSheetCommandTarget(e);if(!t)return!1;const{worksheet:r,subUnitId:o,unitId:s}=t,{delta:l,reset:d}=i;let c=d?100:Math.round((r.getConfig().zoomRatio+l)*100);c=Math.max(Ao[0],c),c=Math.min(Ao[1],c);const u=c/100,g=n.get(Se).isVisible();return(g.unitId===s||g.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&g.visible?!1:n.get(a.ICommandService).executeCommand(Le.id,{unitId:s,subUnitId:o,zoomRatio:u})}},Nn={id:"sheet.command.set-zoom-ratio",type:a.CommandType.COMMAND,handler:async(n,i)=>{if(!i)return!1;const{unitId:e,subUnitId:t,zoomRatio:r}=i,s=n.get(Se).isVisible();return(s.unitId===e||s.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&s.visible?!1:n.get(a.ICommandService).executeCommand(Le.id,{unitId:e,subUnitId:t,zoomRatio:r})}};function ou(n){return typeof n.isMainScene>"u"}function Ye(n,i){const e=n instanceof a.Workbook?n:n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!e)return null;const t=e.getUnitId();let r,o,s,l;if(ou(i)){const g=i.getRenderById(t);if(g==null)return null;r=g.components,r=g.components,o=g.mainComponent,s=g.scene,l=g.engine}else r=i.components,o=i.mainComponent,s=i.scene,l=i.engine;if(!r||!o)return null;const d=o,c=r.get(he.ROW),u=r.get(he.COLUMN),h=r.get(he.LEFT_TOP);return{spreadsheet:d,spreadsheetRowHeader:c,spreadsheetColumnHeader:u,spreadsheetLeftTopPlaceholder:h,scene:s,engine:l}}function Vo(n,i,e,t){const{startX:r,startY:o,endX:s,endY:l}=t.getCellWithCoordByIndex(n,i);return{startX:r,startY:o,endX:s,endY:l}}function qe(n,i,e,t,r,o){const s=e.getCoordRelativeToViewport(w.Vector2.FromArray([n,i])),{x:l,y:d}=s,c=e.getScrollXYInfoByViewport(s,r),{scaleX:u,scaleY:h}=e.getAncestorScale(),g=t.getCellIndexByOffset(l,d,u,h,c,{closeFirst:o}),{row:S,column:f}=g,p=t.getNoMergeCellPositionByIndex(S,f),{startX:v,startY:C,endX:I,endY:b}=p;return{startX:v,startY:C,endX:I,endY:b,row:S,column:f}}function Kn(n,i,e,t){const r=e.getCoordRelativeToViewport(w.Vector2.FromArray([n,i])),o=e.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN),s=e.getScrollXYInfoByViewport(r,o),{scaleX:l,scaleY:d}=e.getAncestorScale(),{x:c,y:u}=s,h=n/l+c,g=i/d+u;return{x:h,y:g}}var su=Object.defineProperty,au=Object.getOwnPropertyDescriptor,lu=(n,i,e,t)=>{for(var r=t>1?void 0:t?au(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&su(i,e,r),r},Vr=(n,i)=>(e,t)=>i(e,t,n);let Jn=class extends a.Disposable{constructor(i,e,t,r,o){super();R(this,"_zoom");this._context=i,this._sheetSkeletonManagerService=e,this._commandService=t,this._contextService=r,this._editorBridgeService=o,this._initSkeletonListener(),this._initZoomEventListener()}updateZoom(i,e){const t=this._context.unit.getSheetBySheetId(i);return t?(t.getConfig().zoomRatio=e,t===this._context.unit.getActiveSheet()&&this._updateViewZoom(e),!0):!1}_initZoomEventListener(){const i=this._getSheetObject().scene;this.disposeWithMe(i.onMouseWheel$.subscribeEvent(e=>{if(!e.ctrlKey||!this._contextService.getContextValue(a.FOCUSING_SHEET))return;if(this._editorBridgeService){const c=this._editorBridgeService.isVisible();if((c.unitId===this._context.unitId||c.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&c.visible)return}const t=Math.abs(e.deltaX);let r=t<40?.2:t<80?.4:.2;r*=e.deltaY>0?-1:1,i.scaleX<1&&(r/=2);const o=this._context.unit,s=o.getActiveSheet();if(!s)return;const l=s.getZoomRatio();let d=+Number.parseFloat(`${l+r}`).toFixed(1);d=d>=4?4:d<=.1?.1:d,this._commandService.executeCommand(Nn.id,{zoomRatio:Math.round(d*10)/10,unitId:o.getUnitId(),subUnitId:s.getSheetId()}),e.preventDefault()}))}_initSkeletonListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeletonBefore$.subscribe(i=>{if(i==null)return;const t=this._context.unit.getActiveSheet();if(!t)return;const r=t.getZoomRatio()||1;this._zoom!==r&&this._updateViewZoom(r),this._zoom=r}))}_updateViewZoom(i){const e=this._getSheetObject();e==null||e.scene.scale(i,i),e==null||e.spreadsheet.makeForceDirty()}_getSheetObject(){return Ye(this._context.unit,this._context)}};Jn=lu([Vr(1,a.Inject(exports.SheetSkeletonManagerService)),Vr(2,a.ICommandService),Vr(3,a.IContextService),Vr(4,a.Optional(Se))],Jn);const Le={id:"sheet.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(n,i)=>{const t=n.get(w.IRenderManagerService).getRenderById(i.unitId);return t?t.with(Jn).updateZoom(i.subUnitId,i.zoomRatio):!1}};var cu=Object.defineProperty,du=Object.getOwnPropertyDescriptor,uu=(n,i,e,t)=>{for(var r=t>1?void 0:t?du(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&cu(i,e,r),r},ji=(n,i)=>(e,t)=>i(e,t,n);const Gs="univer-sheet-main-canvas";exports.SheetsRenderService=class extends a.RxDisposable{constructor(e,t,r){super();R(this,"_skeletonChangeMutations",new Set);this._contextService=e,this._instanceSrv=t,this._renderManagerService=r,Promise.resolve().then(()=>this._init())}registerSkeletonChangingMutations(e){return this._skeletonChangeMutations.has(e)?a.toDisposable(()=>{}):(this._skeletonChangeMutations.add(e),a.toDisposable(()=>this._skeletonChangeMutations.delete(e)))}checkMutationShouldTriggerRerender(e){return this._skeletonChangeMutations.has(e)}_init(){this._initWorkbookListener(),this._initContextListener()}_initWorkbookListener(){this._instanceSrv.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET).pipe(O.takeUntil(this.dispose$)).subscribe(e=>this._createRenderer(e)),this._instanceSrv.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(e=>this._createRenderer(e)),this._instanceSrv.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).pipe(O.takeUntil(this.dispose$)).subscribe(e=>this._disposeRenderer(e))}_createRenderer(e){const t=e.getUnitId();this._renderManagerService.created$.subscribe(r=>{r.unitId===t&&(r.engine.getCanvas().setId(`${Gs}_${t}`),r.engine.getCanvas().getContext().setId(`${Gs}_${t}`))}),this._renderManagerService.createRender(t),this._renderManagerService.setCurrent(t)}_disposeRenderer(e){const t=e.getUnitId();this._renderManagerService.removeRender(t)}_initContextListener(){this.disposeWithMe(this._contextService.subscribeContextValue$(w.RENDER_RAW_FORMULA_KEY).pipe(O.distinctUntilChanged()).subscribe(()=>{this._renderManagerService.getRenderAll().forEach(e=>{e.mainComponent instanceof w.Spreadsheet&&e.mainComponent.makeForceDirty(!0)})}))}};exports.SheetsRenderService=uu([ji(0,a.IContextService),ji(1,a.IUniverInstanceService),ji(2,w.IRenderManagerService)],exports.SheetsRenderService);var hu=Object.defineProperty,mu=Object.getOwnPropertyDescriptor,gu=(n,i,e,t)=>{for(var r=t>1?void 0:t?mu(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&hu(i,e,r),r},Ot=(n,i)=>(e,t)=>i(e,t,n);exports.AutoFillController=class extends a.Disposable{constructor(e,t,r,o,s,l,d){super();R(this,"_beforeApplyData",[]);R(this,"_currentLocation",null);R(this,"_copyData",[]);R(this,"_defaultHook");this._univerInstanceService=e,this._commandService=t,this._autoFillService=r,this._editorBridgeService=o,this._renderManagerService=s,this._injector=l,this._sheetsRenderService=d,this._defaultHook={id:"default",type:hn.Default,priority:0,onBeforeFillData:(c,u)=>this._presetAndCacheData(c,u),onFillData:(c,u,h)=>this._fillData(c,u,h)},this._init()}_init(){this._initDefaultHook(),this._onSelectionControlFillChanged(),this._initQuitListener(),this._initSkeletonChange()}_initSkeletonChange(){this.disposeWithMe(this._sheetsRenderService.registerSkeletonChangingMutations(_t.id))}_initDefaultHook(){this.disposeWithMe(this._autoFillService.addHook(this._defaultHook))}_initQuitListener(){const e=[Te.id,Rn.id,m.SetRangeValuesCommand.id,Le.id,m.SetWorksheetActiveOperation.id,m.MoveRangeMutation.id,m.RemoveRowMutation.id,m.RemoveColMutation.id,m.InsertRowMutation.id,m.InsertColMutation.id,m.MoveRowsMutation.id,m.MoveColsMutation.id,m.SetWorksheetColWidthMutation.id,m.SetWorksheetRowHeightMutation.id,m.SetRangeValuesMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted((t,r)=>{var d,c;const o=r==null?void 0:r.fromCollab,s=r==null?void 0:r.fromSync,l=r==null?void 0:r.fromFormula;e.includes(t.id)&&!o&&!s&&!l&&t.params.trigger!==_t.id&&t.params.trigger!==dr.id&&this._quit(),t.id===m.RemoveSheetMutation.id&&t.params.unitId===((d=this._currentLocation)==null?void 0:d.unitId)&&t.params.subUnitId===((c=this._currentLocation)==null?void 0:c.subUnitId)&&this._quit()})),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{var r;t.getUnitId()===((r=this._currentLocation)==null?void 0:r.unitId)&&this._quit()}))}_quit(){this._currentLocation=null,this._beforeApplyData=[],this._copyData=[],this._autoFillService.setShowMenu(!1)}_onSelectionControlFillChanged(){const e=new a.DisposableCollection,t=r=>{r.dispose();const o=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET);if(!o)return;o.with(ve).getSelectionControls().forEach(d=>{r.add(a.toDisposable(d.selectionFilled$.subscribe(c=>{if(c==null||c.startColumn===-1||c.startRow===-1||c.endColumn===-1||c.endRow===-1)return;const u={startColumn:d.model.startColumn,endColumn:d.model.endColumn,startRow:d.model.startRow,endRow:d.model.endRow},h={startColumn:c.startColumn,endColumn:c.endColumn,startRow:c.startRow,endRow:c.endRow};this._commandService.executeCommand(_t.id,{sourceRange:u,targetRange:h})}))),r.add(a.toDisposable(d.fillControl.onDblclick$.subscribeEvent(()=>{const c={startColumn:d.model.startColumn,endColumn:d.model.endColumn,startRow:d.model.startRow,endRow:d.model.endRow};this._handleDbClickFill(c)}))),r.add(a.toDisposable(d.fillControl.onPointerDown$.subscribeEvent(()=>{this._editorBridgeService.isVisible().visible&&this._editorBridgeService.changeVisible({visible:!1,eventType:w.DeviceInputEventType.PointerDown,unitId:o.unitId})})))})};t(e),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{r.id===m.SetSelectionsOperation.id&&t(e)}))}_handleDbClickFill(e){const t=this._detectFillRange(e);t.endRow<=e.endRow||this._commandService.executeCommand(_t.id,{sourceRange:e,targetRange:t})}_detectFillRange(e){var g,S,f,p,v,C;const{startRow:t,endRow:r,startColumn:o,endColumn:s}=e,l=(g=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET))==null?void 0:g.getActiveSheet();if(!l)return e;const d=l.getCellMatrix(),c=l.getMaxRows()-1,u=l.getMaxColumns()-1;let h=r;if(o>0&&((S=d.getValue(t,o-1))==null?void 0:S.v)!=null){let I=t;for(;((f=d.getValue(I,o-1))==null?void 0:f.v)!=null&&I<c;)I+=1;h=I-1}else if(s<u&&((p=d.getValue(r,s+1))==null?void 0:p.v)!=null){let I=t;for(;((v=d.getValue(I,s+1))==null?void 0:v.v)!=null&&I<c;)I+=1;h=I-1}for(let I=r+1;I<=h;I++)for(let b=o;b<=s;b++)if(((C=d.getValue(I,b))==null?void 0:C.v)!=null){h=I-1;break}return{startColumn:o,endColumn:s,startRow:t,endRow:h}}_getApplyData(e,t,r,o,s,l=!0){const d=[],c=Math.floor(r/t),u=r%t,h=this._autoFillService.getRules();if(!l&&s===ae.ONLY_FORMAT)return console.error("ERROR: only format can not be applied when hasStyle is false"),[];const g={};h.forEach(S=>{g[S.type]=[]}),h.forEach(S=>{const{type:f,applyFunctions:p={}}=S,v=e[f];v&&v.forEach(C=>{const I=Wd(C.index,u),b=C.index.length*c+I,T=this._applyFunctions(C,b,o,s,p,e),M=Ud(t,r,C.index);g[f].push({data:T,index:M})})});for(let S=0;S<r;S++)h.forEach(f=>{const{type:p}=f,v=g[p];for(let C=0;C<v.length;C++)S in v[C].index&&d.push(v[C].data[v[C].index[S]])});return d}_applyFunctions(e,t,r,o,s,l){const{data:d}=e,c=r===a.Direction.UP||r===a.Direction.LEFT;if(o===ae.COPY){const u=s==null?void 0:s[ae.COPY];return u?u(e,t,r,l):(c&&d.reverse(),jt(d,t))}if(o===ae.SERIES){const u=s==null?void 0:s[ae.SERIES];return u?u(e,t,r,l):(c&&d.reverse(),s!=null&&s[ae.COPY]?s[ae.COPY](e,t,r,l):jt(d,t))}if(o===ae.ONLY_FORMAT){const u=s==null?void 0:s[ae.ONLY_FORMAT];return u?u(e,t,r,l):Ld(d,t)}}_getCopyData(e,t){const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!r)throw new Error("No active sheet found");const o=r.getCellMatrix(),s=this._autoFillService.getRules(),l=[],d=t===a.Direction.DOWN||t===a.Direction.UP;let c,u;return d?(c=e.cols,u=e.rows):(c=e.rows,u=e.cols),c.forEach(h=>{const g=this._getEmptyCopyDataPiece(),S={type:void 0,cellData:void 0};u.forEach(f=>{let p;d?p=o.getValue(f,h):p=o.getValue(h,f);const{type:v,isContinue:C}=s.find(I=>I.match(p,this._injector))||Xa;if(C(S,p)){const I=g[v],b=I[I.length-1];b.data.push(p),b.index.push(f-u[0])}else{const I=g[v];I?I.push({data:[p],index:[f-u[0]]}):g[v]=[{data:[p],index:[f-u[0]]}]}S.type=v,S.cellData=p}),l.push(g)}),l}_getEmptyCopyDataPiece(){const e={};return this._autoFillService.getRules().forEach(t=>{e[t.type]=[]}),e}_getMergeApplyData(e,t,r,o){const s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!s)throw new Error("No active sheet found");const l=[];for(let d=e.startRow;d<=e.endRow;d++)for(let c=e.startColumn;c<=e.endColumn;c++){const{isMergedMainCell:u,startRow:h,startColumn:g,endRow:S,endColumn:f}=s.getCellInfoInMergeData(d,c);if(u){if(r===a.Direction.DOWN){let p=h+o,v=S+o;for(;v<=t.endRow;)l.push({startRow:p,startColumn:g,endRow:v,endColumn:f}),p+=o,v+=o}else if(r===a.Direction.UP){let p=h-o,v=S-o;for(;p>=t.startRow;)l.push({startRow:p,startColumn:g,endRow:v,endColumn:f}),p-=o,v-=o}else if(r===a.Direction.RIGHT){let p=g+o,v=f+o;for(;v<=t.endColumn;)l.push({startRow:h,startColumn:p,endRow:S,endColumn:v}),p+=o,v+=o}else if(r===a.Direction.LEFT){let p=g-o,v=f-o;for(;p>=t.startColumn;)l.push({startRow:h,startColumn:p,endRow:S,endColumn:v}),p-=o,v-=o}}}return l}_presetAndCacheData(e,t){const{source:r,target:o}=e,s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!s)throw new Error("No active sheet found");const l=s.getCellMatrix(),d=[];return o.rows.forEach(c=>{const u=[];o.cols.forEach(h=>{u.push(a.Tools.deepClone(l.getValue(c,h)))}),d.push(u)}),this._beforeApplyData=d,this._copyData=this._getCopyData(r,t),this._currentLocation=e,this._shouldDisableSeries(this._copyData)?(this._autoFillService.setDisableApplyType(ae.SERIES,!0),ae.COPY):(this._autoFillService.setDisableApplyType(ae.SERIES,!1),this._getPreferredApplyType(this._copyData))}_fillData(e,t,r){var W,k;const o=[],s=[];let l=!0;r===ae.NO_FORMAT&&(l=!1,r=ae.SERIES);const{source:d,target:c,unitId:u,subUnitId:h}=e;if(!d||!c||t==null)return{undos:o,redos:s};const g=Et(d),S=Et(c),{cols:f,rows:p}=c,{cols:v,rows:C}=d,I=this._copyData;let b;t===a.Direction.DOWN||t===a.Direction.UP?b=C.length:b=v.length;const T=[];if(t===a.Direction.DOWN||t===a.Direction.UP){const U=p.length,B=[];f.forEach((F,L)=>{const z=I[L],X=this._getApplyData(z,b,U,t,r,l);B.push(X)});for(let F=0;F<B[0].length;F++){const L=[];for(let z=0;z<B.length;z++)L.push({s:null,...B[z][F]});T.push(L)}}else{const U=f.length;p.forEach((B,F)=>{const L=I[F],z=this._getApplyData(L,b,U,t,r,l),X=[];for(let Z=0;Z<z.length;Z++)X.push({s:null,...z[Z]});T.push(X)})}let M=[];const y=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getStyles();if(l?(M=this._getMergeApplyData(g,S,t,b),T.forEach(U=>{U.forEach(B=>{B&&y&&y&&(B.s=y.getStyleByCell(B))})})):T.forEach((U,B)=>{U.forEach((F,L)=>{F&&y&&(F.s=y.getStyleByCell(this._beforeApplyData[B][L])||null)})}),r===ae.ONLY_FORMAT&&T.forEach((U,B)=>{U.forEach((F,L)=>{if(F){const z=this._beforeApplyData[B][L]||{};F.f=z.f,F.si=z.si,F.t=z.t,F.v=z.v}})}),l){const U=[],B=(k=(W=this._univerInstanceService.getUniverSheetInstance(u))==null?void 0:W.getSheetBySheetId(h))==null?void 0:k.getMergeData();B&&B.forEach(z=>{a.Rectangle.intersects(z,S)&&U.push(z)});const F={unitId:u,subUnitId:h,ranges:U},L=this._injector.invoke(m.RemoveMergeUndoMutationFactory,F);U.length&&(s.push({id:m.RemoveWorksheetMergeMutation.id,params:F}),o.unshift({id:m.AddWorksheetMergeMutation.id,params:L}))}const P={subUnitId:h,unitId:u,cellValue:xd([c])},x=this._injector.invoke(m.SetRangeValuesUndoMutationFactory,P);s.push({id:m.SetRangeValuesMutation.id,params:P}),o.unshift({id:m.SetRangeValuesMutation.id,params:x});const A=new a.ObjectMatrix;p.forEach((U,B)=>{f.forEach((F,L)=>{T[B][L]&&A.setValue(U,F,T[B][L])})});const N=A.getMatrix(),D={subUnitId:h,unitId:u,cellValue:N},H=this._injector.invoke(m.SetRangeValuesUndoMutationFactory,D);if(this._autoFillService.getActiveHooks().forEach(U=>{var B;(B=U.onBeforeSubmit)==null||B.call(U,e,t,r,N)}),o.unshift({id:m.SetRangeValuesMutation.id,params:H}),s.push({id:m.SetRangeValuesMutation.id,params:D}),M!=null&&M.length){const U=m.getAddMergeMutationRangeByType(M),B={unitId:u,subUnitId:h,ranges:U},F=this._injector.invoke(m.AddMergeUndoMutationFactory,B);o.unshift({id:m.RemoveWorksheetMergeMutation.id,params:F}),s.push({id:m.AddWorksheetMergeMutation.id,params:B})}return{undos:o,redos:s}}_shouldDisableSeries(e){return e.every(t=>Object.keys(t).every(r=>{var o;return((o=t[r])==null?void 0:o.length)===0||[_e.OTHER,_e.FORMULA].includes(r)}))}_getPreferredApplyType(e){return e.every(r=>Object.keys(r).every(o=>{var s,l;return((s=r[o])==null?void 0:s.length)===0||((l=r[o])==null?void 0:l.length)===1&&r[o][0].data.length===1&&_e.NUMBER===o}))?ae.COPY:ae.SERIES}};exports.AutoFillController=gu([Ot(0,a.IUniverInstanceService),Ot(1,a.ICommandService),Ot(2,Tt),Ot(3,Se),Ot(4,w.IRenderManagerService),Ot(5,a.Inject(a.Injector)),Ot(6,a.Inject(exports.SheetsRenderService))],exports.AutoFillController);var Su=Object.defineProperty,fu=Object.getOwnPropertyDescriptor,pu=(n,i,e,t)=>{for(var r=t>1?void 0:t?fu(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Su(i,e,r),r},zi=(n,i)=>(e,t)=>i(e,t,n);exports.CellCustomRenderController=class extends a.Disposable{constructor(e,t,r,o){super();R(this,"_enterActiveRender");this._context=e,this._sheetSkeletonManagerService=t,this._renderManagerService=r,this._permissionService=o,this._initEventBinding()}_initEventBinding(){const e=new a.DisposableCollection,t=this._context.unit,r=o=>{if(e.dispose(),!o)return;const s=this._context.unitId,{skeleton:l}=o,d=this._renderManagerService.getRenderById(s);if(d&&d.mainComponent){const c=d.mainComponent,u=S=>{const{offsetX:f,offsetY:p}=S,v=d.scene,C=t.getActiveSheet();if(!C)return;const I=v.getActiveViewportByCoord(w.Vector2.FromArray([f,p]));if(!I)return;const{scaleX:b,scaleY:T}=v.getAncestorScale(),M={x:I.viewportScrollX,y:I.viewportScrollY},y=l.getCellIndexByOffset(f,p,b,T,M),P=l.worksheet.getMergedCell(y.row,y.column),x={actualRow:P?P.startRow:y.row,actualCol:P?P.startColumn:y.column,mergeCell:P,row:y.row,col:y.column};if(!x||!l)return;const A=C.getCell(x.actualRow,x.actualCol);if(!A)return;const N=A.customRender;if(!(N!=null&&N.length))return;const D=x.actualRow,H=x.actualCol,W=N.sort(a.sortRules),k=C.getSheetId(),U={data:A,style:l.getsStyles().getStyleByCell(A),primaryWithCoord:l.getCellWithCoordByIndex(x.actualRow,x.actualCol),unitId:s,subUnitId:k,row:D,col:H,workbook:t,worksheet:C},B={x:M.x+f/b,y:M.y+p/T},F=W.find(L=>{var z;return(z=L.isHit)==null?void 0:z.call(L,B,U)});if(F)return[F,U]},h=c.onPointerDown$.subscribeEvent(S=>{var p,v,C,I;const f=u(S);if(f){const[b,T]=f,{row:M,col:y,worksheet:P,unitId:x,subUnitId:A}=T;if(!((p=this._permissionService.composePermission([new m.WorkbookEditablePermission(x).id,new m.WorksheetEditPermission(x,A).id]))==null?void 0:p.every(H=>H.value)))return!1;const D=(C=(v=P.getCell(M,y))==null?void 0:v.selectionProtection)==null?void 0:C[0];if((D==null?void 0:D[m.UnitAction.Edit])===!1)return!1;(I=b.onPointerDown)==null||I.call(b,T,S)}}),g=a.fromEventSubject(c.onPointerMove$).pipe(O.throttleTime(30)).subscribe(S=>{var p,v,C,I,b,T;const f=u(S);if(f){const[M,y]=f;this._enterActiveRender?this._enterActiveRender.render!==M&&((v=(p=this._enterActiveRender.render).onPointerLeave)==null||v.call(p,this._enterActiveRender.cellContext,S),this._enterActiveRender={render:M,cellContext:y},(C=M.onPointerEnter)==null||C.call(M,y,S)):(this._enterActiveRender={render:M,cellContext:y},(I=M.onPointerEnter)==null||I.call(M,y,S))}else this._enterActiveRender&&((T=(b=this._enterActiveRender.render).onPointerLeave)==null||T.call(b,this._enterActiveRender.cellContext,S),this._enterActiveRender=null)});h&&e.add(h),g&&e.add(g)}};this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(r)),r(this._sheetSkeletonManagerService.getCurrent()),this.disposeWithMe(e)}};exports.CellCustomRenderController=pu([zi(1,a.Inject(exports.SheetSkeletonManagerService)),zi(2,w.IRenderManagerService),zi(3,a.IPermissionService)],exports.CellCustomRenderController);class hs extends a.Disposable{constructor(){super(...arguments);R(this,"rangesStack",[]);R(this,"selectedRangeWorksheet","")}}var vu=Object.defineProperty,Cu=Object.getOwnPropertyDescriptor,_u=(n,i,e,t)=>{for(var r=t>1?void 0:t?Cu(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&vu(i,e,r),r},Zs=(n,i)=>(e,t)=>i(e,t,n);let En=class{constructor(n,i){R(this,"_current",null);R(this,"_shortcutParam",[]);this._univerInstanceService=n,this._localeService=i}dispose(){this._shortcutParam=[]}getCurrentBySearch(n){return this._getCurrentBySearch(n)}getCurrent(){return this._getCurrentBySearch(this._current)}addOrUpdate(n){const i=this._getCurrentBySearch({unitId:n.unitId,sheetId:n.sheetId,keycode:n.keycode});if(i!=null){const e=this._shortcutParam.indexOf(i);this._shortcutParam.splice(e,1)}return this._shortcutParam.push(n),i}remove(n){if(n==null)return;const i=this._getCurrentBySearch(n);if(i==null)return;const e=this._shortcutParam.indexOf(i);return this._shortcutParam.splice(e,1)[0]}_getCurrentBySearch(n){return n==null?void 0:this._shortcutParam.find(e=>e.unitId===n.unitId&&e.sheetId===n.sheetId&&e.keycode===n.keycode)}};En=_u([Zs(0,a.IUniverInstanceService),Zs(1,a.Inject(a.LocaleService))],En);var Pi=(n=>(n.MergeAll="mergeAll",n.MergeVertical="mergeVertical",n.MergeHorizontal="mergeHorizontal",n))(Pi||{});function It(n,i,e,t,r=!0,o=1,s=!0){let l={...n};t==null&&(t={startRow:0,endRow:e.getRowCount()-1,startColumn:0,endColumn:e.getColumnCount()-1});let d;switch(i){case a.Direction.UP:for(d=n.startRow-o;d>-1&&!e.getRowVisible(d);)d-=1;d>=t.startRow?(l.startRow=d,l.endRow=d):s&&(l.startRow=t.endRow,l.endRow=t.endRow,r&&(l=It(l,a.Direction.LEFT,e,t,!1)));break;case a.Direction.DOWN:for(d=n.endRow+o;d<e.getRowCount()&&!e.getRowVisible(d);)d+=1;d<=t.endRow?(l.startRow=d,l.endRow=d):s&&(l.startRow=t.startRow,l.endRow=t.startRow,r&&(l=It(l,a.Direction.RIGHT,e,t,!1)));break;case a.Direction.LEFT:for(d=n.startColumn-o;d>-1&&!e.getColVisible(d);)d-=1;d>=t.startColumn?(l.startColumn=d,l.endColumn=d):s&&(l.startColumn=t.endColumn,l.endColumn=t.endColumn,r&&(l=It(l,a.Direction.UP,e,t,!1)));break;case a.Direction.RIGHT:for(d=n.endColumn+o;d<e.getColumnCount()&&!e.getColVisible(d);)d+=1;d<=t.endColumn?(l.startColumn=d,l.endColumn=d):s&&(l.startColumn=t.startColumn,l.endColumn=t.startColumn,r&&(l=It(l,a.Direction.DOWN,e,t,!1)));break}return l}function ms(n,i,e){const t={...n},{startRow:r,startColumn:o,endRow:s,endColumn:l}=$n(n,i,e);let d=Un(e,r,o,s,l).hasValue,c=!0,u=!0;for(;u;){if(a.Direction.UP===i){let h=t.startRow-1;for(;h>-1&&!e.getRowVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:g,matrix:S}=Un(e,h,t.startColumn,h,t.endColumn);if(d&&!g&&!c){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue(p=>{f=Math.min(p,f)}),t.startRow=f}else t.startRow=h;if(t.endRow=t.startRow,!d&&g){u=!1;break}d=g,c=!1}}if(a.Direction.DOWN===i){let h=t.endRow+1;for(;h<e.getRowCount()&&!e.getRowVisible(h);)h+=1;if(h===e.getRowCount()){u=!1;break}const{hasValue:g,matrix:S}=Un(e,h,t.startColumn,h,t.endColumn);if(d&&!g&&!c){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((p,v,C)=>{f=Math.max(p+(C.rowSpan||1)-1,f)}),t.endRow=f}else t.endRow=h;if(t.startRow=t.endRow,!d&&g){u=!1;break}d=g,c=!1}}if(a.Direction.LEFT===i){let h=t.startColumn-1;for(;h>-1&&!e.getColVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:g,matrix:S}=Un(e,t.startRow,h,t.endRow,h);if(d&&!g&&!c){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((p,v)=>{f=Math.min(v,f)}),t.startColumn=f}else t.startColumn=h;if(t.endColumn=t.startColumn,!d&&g){u=!1;break}d=g,c=!1}}if(a.Direction.RIGHT===i){let h=t.endColumn+1;for(;h<e.getColumnCount()&&!e.getColVisible(h);)h+=1;if(h===e.getColumnCount()){u=!1;break}const{hasValue:g,matrix:S}=Un(e,t.startRow,h,t.endRow,h);if(d&&!g&&!c){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((p,v,C)=>{f=Math.max(v+(C.colSpan||1)-1,f)}),t.endColumn=f}else t.endColumn=h;if(t.startColumn=t.endColumn,!d&&g){u=!1;break}d=g,c=!1}}}return m.alignToMergedCellsBorders(t,e,!0)}function Ya(n,i,e){return It(n,i,e,void 0,!1,1,!1)}function Iu(n,i,e){const t=ms(n,i,e);return m.alignToMergedCellsBorders(a.Rectangle.union(t,n),e,!0)}function bu(n,i,e){const t=Ya(n,i,e),r={startRow:Math.min(n.startRow,t.startRow),startColumn:Math.min(n.startColumn,t.startColumn),endRow:Math.max(n.endRow,t.endRow),endColumn:Math.max(n.endColumn,t.endColumn)};return m.alignToMergedCellsBorders(a.Rectangle.union(n,r),e)}function Ru(n,i,e,t){const r=a.getReverseDirection(e),o=ms($n(n,r,t),e,t);return e===a.Direction.UP&&o.startRow<=n.startRow?m.alignToMergedCellsBorders({...i,startColumn:n.startColumn,endColumn:n.endColumn},t,!0):e===a.Direction.DOWN&&o.endRow>=n.endRow?m.alignToMergedCellsBorders({...i,startColumn:n.startColumn,endColumn:n.endColumn},t,!0):e===a.Direction.LEFT&&o.startColumn<=n.startColumn?m.alignToMergedCellsBorders({...i,startRow:n.startRow,endRow:n.endRow},t,!0):e===a.Direction.RIGHT&&o.endColumn>=n.endColumn?m.alignToMergedCellsBorders({...i,startRow:n.startRow,endRow:n.endRow},t,!0):a.Rectangle.union(a.Rectangle.clone(i),o)}function Eu(n,i,e){const t=a.getReverseDirection(i),r=$n(n,t,e),o=$n(n,i,e),s=Ya(r,i,e);return m.alignToMergedCellsBorders(a.Rectangle.union(o,s),e,!1)}function Ks(n){return{startRow:0,startColumn:0,endRow:n.getRowCount()-1,endColumn:n.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL}}function $n(n,i,e){let t;switch(i){case a.Direction.UP:t={startRow:n.startRow,startColumn:n.startColumn,endRow:n.startRow,endColumn:n.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.DOWN:t={startRow:n.endRow,startColumn:n.startColumn,endRow:n.endRow,endColumn:n.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.LEFT:t={startRow:n.startRow,startColumn:n.startColumn,endRow:n.endRow,endColumn:n.startColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.RIGHT:t={startRow:n.startRow,startColumn:n.endColumn,endRow:n.endRow,endColumn:n.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;default:throw new Error("Invalid direction")}return m.alignToMergedCellsBorders(t,e,!1)}function Un(n,i,e,t,r){let o=!1;const s=n.getMatrixWithMergedCells(i,e,t,r).forValue((l,d,c)=>{if(wu(c))return o=!0,!1});return{hasValue:o,matrix:s}}function Wo(n,i,e){const t=a.Rectangle.clone(n);if(i==null)return t;switch(e){case a.Direction.UP:case a.Direction.DOWN:t.startColumn=t.endColumn=i.actualColumn;break;case a.Direction.LEFT:case a.Direction.RIGHT:t.startRow=t.endRow=i.actualRow;break}return t}function Tu(n,i,e){var l,d,c,u;const{primary:t,range:r}=n,o=a.Rectangle.clone(r);switch(i){case a.Direction.UP:case a.Direction.DOWN:o.startRow=(l=t==null?void 0:t.startRow)!=null?l:r.startRow,o.endRow=(d=t==null?void 0:t.endRow)!=null?d:r.startRow;break;case a.Direction.LEFT:case a.Direction.RIGHT:o.startColumn=(c=t==null?void 0:t.startColumn)!=null?c:r.startColumn,o.endColumn=(u=t==null?void 0:t.endColumn)!=null?u:r.startColumn;break}const s=$n(o,i,e);switch(i){case a.Direction.DOWN:return r.startRow<s.startRow;case a.Direction.UP:return r.endRow>s.endRow;case a.Direction.LEFT:return s.endColumn<r.endColumn;case a.Direction.RIGHT:return s.startColumn>r.startColumn}}function Ga(n,i){let e=n[0].startRow,t=n[0].endRow;n.forEach(o=>{const{startRow:s,endRow:l}=o;e=Math.min(e,s),t=Math.max(t,l)});const r=new Array(t-e+1).fill(!1);return i.forEach(o=>{const{startRow:s,endRow:l}=o;for(let d=Math.max(s,e);d<=Math.min(l,t);d++)r[d-e]=!0}),n.every(o=>{const{startRow:s,endRow:l}=o;for(let d=s;d<=l;d++)if(!r[d-e])return!1;return!0})}function Za(n,i){let e=n[0].startColumn,t=n[0].endColumn;n.forEach(o=>{const{startColumn:s,endColumn:l}=o;e=Math.min(e,s),t=Math.max(t,l)});const r=new Array(t-e+1).fill(!1);return i.forEach(o=>{const{startColumn:s,endColumn:l}=o;for(let d=Math.max(s,e);d<=Math.min(l,t);d++)r[d-e]=!0}),n.every(o=>{const{startColumn:s,endColumn:l}=o;for(let d=s;d<=l;d++)if(!r[d-e])return!1;return!0})}function gs(n,i){return i?n==="mergeAll"?i.filter(e=>!(e.startRow===e.endRow&&e.startColumn===e.endColumn)):n==="mergeVertical"?i.filter(e=>e.startRow!==e.endRow):n==="mergeHorizontal"?i.filter(e=>e.startColumn!==e.endColumn):i:null}function wu(n){return n.v!==void 0&&n.v!==null&&n.v!==""||n.p!==void 0}var $e=(n=>(n[n.moveStopeOne=0]="moveStopeOne",n[n.moveGap=1]="moveGap",n[n.moveStepPage=2]="moveStepPage",n[n.moveStepEnd=3]="moveStepEnd",n))($e||{});const xe={id:"sheet.command.move-selection",type:a.CommandType.COMMAND,handler:(n,i)=>{if(!i)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{workbook:t,worksheet:r}=e,o=m.getSelectionsService(n,i.fromCurrentSelection).getCurrentLastSelection();if(!o)return!1;const{direction:s,jumpOver:l,extra:d}=i,{range:c,primary:u}=o,h=Wo(c,u,s),g=l===1?ms(h,s,r):It(h,s,r),S=m.getCellAtRowCol(g.startRow,g.startColumn,r);if(a.Rectangle.equals(S,h))return!1;const f=t.getUnitId();n.get(En).remove({unitId:f,sheetId:r.getSheetId(),keycode:E.KeyCode.TAB});const p=[{range:a.Rectangle.clone(S),primary:{startRow:S.startRow,startColumn:S.startColumn,endRow:S.endRow,endColumn:S.endColumn,actualRow:g.startRow,actualColumn:g.startColumn,isMerged:S.isMerged,isMergedMainCell:S.startRow===g.startRow&&S.startColumn===g.startColumn}}];return n.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:t.getUnitId(),subUnitId:r.getSheetId(),selections:p,type:m.SelectionMoveType.MOVE_END,extra:d})}},et={id:"sheet.command.move-selection-enter-tab",type:a.CommandType.COMMAND,handler:(n,i)=>{var U;if(!i)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{workbook:t,worksheet:r}=e,o=m.getSelectionsService(n),{direction:s,keycode:l}=i,d=s===a.Direction.LEFT||s===a.Direction.UP,c=o.getCurrentSelections().concat(),u=c.findIndex(B=>B.primary),h=c[u];if(!h)return!1;const g=d?-1:1,S=u+g!==c.length?c[u+g]:c[0],f=c.findIndex(B=>B===S),p=t.getUnitId(),v=r.getSheetId();if(!h)return!1;const{range:C}=h,I=h.primary;let b=Wo(C,I,s);const T=n.get(En),M=T.getCurrentBySearch({unitId:p,sheetId:v,keycode:E.KeyCode.TAB});let y;const{startRow:P,endRow:x,startColumn:A,endColumn:N}=C,D=d?I.startRow===P&&I.startColumn===A:I.endRow===x&&I.endColumn===N;if(a.Rectangle.equals(C,I)){if(l===E.KeyCode.TAB)M==null&&T.addOrUpdate({unitId:p,sheetId:v,keycode:E.KeyCode.TAB,selection:h});else{const L=M==null?void 0:M.selection;if(L!=null){const{range:z,primary:X}=L;b=Wo(z,X,s)}T.remove({unitId:p,sheetId:v,keycode:E.KeyCode.TAB})}const B=It(b,s,r),F=m.getCellAtRowCol(B.startRow,B.startColumn,r);if(a.Rectangle.equals(F,b))return!1;y={range:a.Rectangle.clone(F),primary:{startRow:F.startRow,startColumn:F.startColumn,endRow:F.endRow,endColumn:F.endColumn,actualRow:B.startRow,actualColumn:B.startColumn,isMerged:F.isMerged,isMergedMainCell:F.startRow===B.startRow&&F.startColumn===B.startColumn}}}else{T.remove({unitId:p,sheetId:v,keycode:E.KeyCode.TAB});const B=a.Tools.deepClone(I),F=D?S.range:It({startRow:B.startRow,startColumn:B.startColumn,endRow:B.endRow,endColumn:B.endColumn},s,r,{startRow:P,endRow:x,startColumn:A,endColumn:N}),L=D&&d,z=L?m.getCellAtRowCol(F.endRow,F.endColumn,r):m.getCellAtRowCol(F.startRow,F.startColumn,r);y={range:D?S.range:a.Rectangle.clone(C),primary:{startRow:z.startRow,startColumn:z.startColumn,endRow:z.endRow,endColumn:z.endColumn,actualRow:L?z.startRow:F.startRow,actualColumn:L?z.startColumn:F.startColumn,isMerged:z.isMerged,isMergedMainCell:z.startRow===F.startRow&&z.startColumn===F.startColumn},style:D?S.style:h.style}}D?(c[u].primary=null,c[f]=y,o.setSelections(p,v,[],m.SelectionMoveType.MOVE_END)):c[u]=y;const H=n.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:p,subUnitId:v,type:m.SelectionMoveType.MOVE_END,selections:c,extra:i.extra}),k=(U=n.get(w.IRenderManagerService).getRenderById(p))==null?void 0:U.with(ve);return k==null||k.refreshSelectionMoveEnd(),H}},He={id:"sheet.command.expand-selection",type:a.CommandType.COMMAND,handler:(n,i)=>{if(!i)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{worksheet:t,unitId:r,subUnitId:o}=e,s=m.getSelectionsService(n).getCurrentLastSelection();if(!s)return!1;const{range:l,primary:d}=s,{jumpOver:c,direction:u,extra:h}=i,S=Tu(s,u,t)?c===1?Ru(l,{...a.Rectangle.clone(d),rangeType:a.RANGE_TYPE.NORMAL},u,t):Eu(l,u,t):c===1?Iu(l,u,t):bu(l,u,t);return S.rangeType=s.range.rangeType,a.Rectangle.equals(S,l)?!1:n.get(a.ICommandService).syncExecuteCommand(m.SetSelectionsOperation.id,{unitId:r,subUnitId:o,type:m.SelectionMoveType.ONLY_SET,selections:[{range:S,primary:d}],extra:h})}},Oi={id:"sheet.command.select-all",type:a.CommandType.COMMAND,handler:async(n,i={expandToGapFirst:!0,loop:!1})=>{const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const t=m.getSelectionsService(n).getCurrentLastSelection();if(!t)return!1;const r=n.get(hs),{worksheet:o,unitId:s,subUnitId:l}=e,d=`${s}|${l}`;d!==r.selectedRangeWorksheet&&(r.rangesStack=[],r.selectedRangeWorksheet=d);const c=o.getMaxRows(),u=o.getMaxColumns(),{expandToGapFirst:h,loop:g}=i,{range:S,primary:f}=t,p=S.endColumn===u-1&&S.endRow===c-1&&S.startRow===0&&S.startColumn===0;r.rangesStack.some(C=>a.Rectangle.equals(C,S))||(r.rangesStack=[],r.rangesStack.push(S));let v;if(p)if(g){if(r.rangesStack.findIndex(I=>a.Rectangle.equals(I,S))!==r.rangesStack.length-1)return!1;v=r.rangesStack[0]}else return!1;else h?(v=m.expandToContinuousRange(S,{left:!0,right:!0,up:!0,down:!0},o),a.Rectangle.equals(v,S)&&(v=Ks(o))):v=Ks(o);return r.rangesStack.some(C=>a.Rectangle.equals(C,v))||r.rangesStack.push(v),n.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:s,subUnitId:l,selections:[{range:v,primary:f}]})}};var yu=Object.defineProperty,Mu=Object.getOwnPropertyDescriptor,Pu=(n,i,e,t)=>{for(var r=t>1?void 0:t?Mu(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&yu(i,e,r),r},Ou=(n,i)=>(e,t)=>i(e,t,n);exports.SheetScrollManagerService=class{constructor(i,e){R(this,"_scrollStateMap",new Map);R(this,"_rawScrollInfo$",new O.BehaviorSubject(null));R(this,"rawScrollInfo$",this._rawScrollInfo$.asObservable());R(this,"validViewportScrollInfo$",new O.BehaviorSubject(null));R(this,"_searchParamForScroll",null);this._context=i,this._sheetSkeletonManagerService=e}dispose(){this._rawScrollInfo$.complete()}setSearchParam(i){this._searchParamForScroll=i}setSearchParamAndRefresh(i){this._searchParamForScroll=i,this._scrollStateNext(i)}getScrollStateByParam(i){return this._getCurrentScroll(i)}getCurrentScrollState(){return this._getCurrentScroll(this._searchParamForScroll)}setScrollInfoAndEmitEvent(i){this._setScrollState(i),this._scrollStateNext(i)}setScrollStateToCurrSheet(i){this._searchParamForScroll!=null&&this._setScrollState({...this._searchParamForScroll,...i})}clear(){this._searchParamForScroll!=null&&this._clearByParamAndNotify(this._searchParamForScroll)}calcViewportScrollFromRowColOffset(i){if(!i)return{viewportScrollX:0,viewportScrollY:0};let{sheetViewStartColumn:e,sheetViewStartRow:t,offsetX:r,offsetY:o}=i;t=t||0,o=o||0;const s=this._sheetSkeletonManagerService.getCurrentSkeleton(),l=(s==null?void 0:s.rowHeightAccumulation[t-1])||0,c=((s==null?void 0:s.columnWidthAccumulation[e-1])||0)+r,u=l+o;return{viewportScrollX:c,viewportScrollY:u}}_setScrollState(i){const{unitId:e,sheetId:t,sheetViewStartColumn:r,sheetViewStartRow:o,offsetX:s,offsetY:l}=i;this._scrollStateMap.has(e)||this._scrollStateMap.set(e,new Map);const d=this._scrollStateMap.get(e),c={sheetViewStartRow:o,sheetViewStartColumn:r,offsetX:s,offsetY:l};d.set(t,c)}_clearByParamAndNotify(i){this._setScrollState({...i,sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0}),this._scrollStateNext(i)}_getCurrentScroll(i){var s;const e={sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0};if(i==null)return e;const{unitId:t,sheetId:r}=i;return((s=this._scrollStateMap.get(t))==null?void 0:s.get(r))||e}_scrollStateNext(i){const e=this._getCurrentScroll(i);this._rawScrollInfo$.next(e)}};exports.SheetScrollManagerService=Pu([Ou(1,a.Inject(exports.SheetSkeletonManagerService))],exports.SheetScrollManagerService);const Fe={id:"sheet.operation.set-scroll",type:a.CommandType.OPERATION,handler:(n,i)=>{if(!i)return!1;const{unitId:e,sheetId:t,offsetX:r,offsetY:o,sheetViewStartColumn:s,sheetViewStartRow:l}=i;return n.get(w.IRenderManagerService).getRenderById(e).with(exports.SheetScrollManagerService).setScrollInfoAndEmitEvent({unitId:e,sheetId:t,offsetX:r,offsetY:o,sheetViewStartRow:l,sheetViewStartColumn:s}),!0}},Tn={id:"sheet.command.set-scroll-relative",type:a.CommandType.COMMAND,handler:async(n,i)=>{const e=n.get(a.ICommandService),t=n.get(a.IUniverInstanceService),r=n.get(w.IRenderManagerService),o=m.getSheetCommandTarget(t);if(!o)return!1;const{unitId:s,subUnitId:l}=o,c=r.getRenderById(s).with(exports.SheetScrollManagerService).getCurrentScrollState(),{offsetX:u=0,offsetY:h=0}=i||{},{sheetViewStartRow:g=0,sheetViewStartColumn:S=0,offsetX:f=0,offsetY:p=0}=c||{};return e.executeCommand(Fe.id,{unitId:s,sheetId:l,sheetViewStartRow:g,sheetViewStartColumn:S,offsetX:f+u,offsetY:p+h})}},je={id:"sheet.command.scroll-view",type:a.CommandType.COMMAND,handler:(n,i)=>{if(!i)return!1;const e=n.get(a.IUniverInstanceService),t=n.get(w.IRenderManagerService),r=m.getSheetCommandTarget(e);if(!r)return!1;const{workbook:o,worksheet:s,unitId:l}=r,c=t.getRenderById(l).with(exports.SheetScrollManagerService).getCurrentScrollState();if(!s)return!1;const{sheetViewStartRow:u,sheetViewStartColumn:h,offsetX:g,offsetY:S}=i,{sheetViewStartColumn:f,sheetViewStartRow:p,offsetX:v,offsetY:C}=c||{},{xSplit:I,ySplit:b}=r.worksheet.getConfig().freeze;return n.get(a.ICommandService).syncExecuteCommand(Fe.id,{unitId:o.getUnitId(),sheetId:s.getSheetId(),sheetViewStartRow:u!=null?u:p!=null?p:0+b,sheetViewStartColumn:h!=null?h:f!=null?f:0+I,offsetX:g!=null?g:v,offsetY:S!=null?S:C})}},Ss={id:"sheet.command.scroll-to-cell",type:a.CommandType.COMMAND,handler:(n,i)=>{const e=n.get(a.IUniverInstanceService);return n.get(w.IRenderManagerService).getRenderById(e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(exports.SheetsScrollRenderController).scrollToRange(i.range,i.forceTop,i.forceLeft)}},xu={id:"sheet.command.scroll-view-reset",type:a.CommandType.COMMAND,handler:async n=>{const i=n.get(a.IUniverInstanceService),e=m.getSheetCommandTarget(i);if(!e)return!1;const{subUnitId:t,unitId:r}=e;return n.get(a.ICommandService).executeCommand(Fe.id,{unitId:r,sheetId:t,sheetViewStartRow:0,sheetViewStartColumn:0})}};var Au=Object.defineProperty,Nu=Object.getOwnPropertyDescriptor,Du=(n,i,e,t)=>{for(var r=t>1?void 0:t?Nu(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Au(i,e,r),r},on=(n,i)=>(e,t)=>i(e,t,n);const Hu=[xe.id,et.id],ku=3;exports.SheetsScrollRenderController=class extends a.Disposable{constructor(i,e,t,r,o,s,l){super(),this._context=i,this._injector=e,this._sheetSkeletonManagerService=t,this._contextService=r,this._commandService=o,this._renderManagerService=s,this._scrollManagerService=l,this._initCommandListener(),this._wheelEventListener(),this._scrollBarEventListener(),this._initSkeletonListener()}_wheelEventListener(){const{scene:i}=this._context;if(!i)return;const e=i.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);e&&this.disposeWithMe(i.onMouseWheel$.subscribeEvent((t,r)=>{if(t.ctrlKey||!this._contextService.getContextValue(a.FOCUSING_SHEET))return;let o=0,s=0;const l=e.limitedScroll();o=t.deltaX,t.shiftKey?o=(t.deltaY||t.deltaX)*ku:s=t.deltaY,this._commandService.executeCommand(Tn.id,{offsetX:o,offsetY:s}),this._context.scene.makeDirty(!0),l&&!l.isLimitedX&&!l.isLimitedY&&(t.preventDefault(),i.getParent().classType===w.RENDER_CLASS_TYPE.SCENE_VIEWER&&r.stopPropagation()),e.isWheelPreventDefaultX&&e.isWheelPreventDefaultY&&t.preventDefault()}))}_scrollBarEventListener(){const{scene:i}=this._context;if(i==null)return;const e=i.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);e&&(this.disposeWithMe(a.toDisposable(this._scrollManagerService.rawScrollInfo$.subscribe(t=>{var S;const r=(S=this._sheetSkeletonManagerService.getCurrent())==null?void 0:S.skeleton;if(!r)return;if(t==null){e.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});return}const{sheetViewStartRow:o,sheetViewStartColumn:s,offsetX:l,offsetY:d}=t,{startX:c,startY:u}=r.getCellWithCoordByIndex(o,s,!1),h=c+l,g=u+d;e.scrollToViewportPos({viewportScrollX:h,viewportScrollY:g})}))),this.disposeWithMe(e.onScrollAfter$.subscribeEvent(t=>{var p;const r=(p=this._sheetSkeletonManagerService.getCurrent())==null?void 0:p.skeleton;if(r==null||t.isTrigger===!1)return;const o=this._getSheetObject();if(r==null||o==null)return;const{viewportScrollX:s,viewportScrollY:l,scrollX:d,scrollY:c}=t,{row:u,column:h,rowOffset:g,columnOffset:S}=r.getDecomposedOffset(s,l),f={sheetViewStartRow:u,sheetViewStartColumn:h,offsetX:S,offsetY:g};this._scrollManagerService.setScrollStateToCurrSheet(f),this._scrollManagerService.validViewportScrollInfo$.next({...f,viewportScrollX:s,viewportScrollY:l,scrollX:d,scrollY:c})})),this.disposeWithMe(e.onScrollByBar$.subscribeEvent(t=>{var g;const r=(g=this._sheetSkeletonManagerService.getCurrent())==null?void 0:g.skeleton;if(r==null||t.isTrigger===!1)return;const o=this._getSheetObject();if(r==null||o==null)return;const{viewportScrollX:s=0,viewportScrollY:l=0}=t,{row:d,column:c,rowOffset:u,columnOffset:h}=r.getDecomposedOffset(s,l);this._commandService.executeCommand(je.id,{sheetViewStartRow:d,sheetViewStartColumn:c,offsetX:h,offsetY:u})})))}_initSkeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeletonBefore$.subscribe(i=>{if(i==null)return;const e={unitId:i.unitId,sheetId:i.sheetId};this._scrollManagerService.setSearchParam(e);const t=this._getSheetObject();if(!t)return;const o=t.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN),s=this._scrollManagerService.getScrollStateByParam(e),{viewportScrollX:l,viewportScrollY:d}=this._scrollManagerService.calcViewportScrollFromRowColOffset(s);o&&(s?(o.viewportScrollX=l,o.viewportScrollY=d):(o.viewportScrollX=0,o.viewportScrollY=0),this._updateSceneSize(i))})))}scrollToRange(i,e,t){let{endRow:r,endColumn:o,startColumn:s,startRow:l}=i;const d=this._getViewportBounding();if(i.rangeType===a.RANGE_TYPE.ROW?(s=0,o=0):i.rangeType===a.RANGE_TYPE.COLUMN&&(l=0,r=0),d&&!e&&!t){const c=d.startRow>r?l:r,u=d.startColumn>o?s:o;return this._scrollToCell(c,u)}else return this._scrollToCell(l,s,e,t)}scrollToCell(i,e){const t=this._context.unit.getActiveSheet(),{ySplit:r,xSplit:o}=t.getFreeze();return this._commandService.syncExecuteCommand(je.id,{sheetViewStartRow:i-r,sheetViewStartColumn:e-o,offsetX:0,offsetY:0})}_initCommandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(Hu.includes(i.id))this._scrollToSelection();else if(i.id===m.ScrollToCellOperation.id){const e=i.params;this.scrollToRange(e)}else if(i.id===He.id){const e=i.params;this._scrollToSelectionForExpand(e)}else i.id===m.SetSelectionsOperation.id&&i.params.reveal&&this._scrollToSelection()}))}_scrollToSelectionForExpand(i){setTimeout(()=>{const e=this._getSelectionsService().getCurrentLastSelection();if(e==null)return;const{startRow:t,startColumn:r,endRow:o,endColumn:s}=e.range,l=this._getViewportBounding();if(l==null)return;const{startRow:d,startColumn:c,endRow:u,endColumn:h}=l;let g=0,S=0;t>d?g=o:o<u?g=t:g=d,r>c?S=s:s<h?S=r:S=c,i.direction===a.Direction.DOWN?g=o:i.direction===a.Direction.UP?g=t:i.direction===a.Direction.RIGHT?S=s:i.direction===a.Direction.LEFT&&(S=r),this._scrollToCell(g,S)},0)}_getFreeze(){var e;const i=(e=this._sheetSkeletonManagerService.getCurrent())==null?void 0:e.skeleton.getWorksheetConfig();if(i!=null)return i.freeze}_updateSceneSize(i){var g;if(i==null)return;const{unitId:e}=this._context,{skeleton:t}=i,r=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.scene;if(t==null||r==null)return;const{rowTotalHeight:o,columnTotalWidth:s,rowHeaderWidthAndMarginLeft:l,columnHeaderHeightAndMarginTop:d}=t,u=this._context.unit.getActiveSheet();if(!u)return;const h=u.getZoomRatio()||1;r==null||r.setScaleValue(h,h),r==null||r.transformByState({width:l+s,height:d+o})}_getSheetObject(){return Ye(this._context.unit,this._context)}_scrollToSelectionByDirection(i){const e=this._getViewportBounding();if(e==null)return!1;const{startRow:t,startColumn:r,endRow:o,endColumn:s}=e;let l=0,d=0;const{startRow:c,startColumn:u,endRow:h,endColumn:g}=i;c>=t&&(l=h),h<=o&&(l=c),u>=r&&(d=g),g<=s&&(d=u),this._scrollToCell(l,d)}_scrollToSelection(i=!0){var c;const e=this._getSelectionsService().getCurrentLastSelection();if(!e)return;const{startRow:t,startColumn:r,actualRow:o,actualColumn:s}=(c=e.primary)!=null?c:e.range,l=i&&o!=null?o:t,d=i&&s!=null?s:r;this._scrollToCell(l,d)}_getSelectionsService(){return m.getSelectionsService(this._injector)}_getViewportBounding(){var o,s;const i=(o=this._getSheetObject())==null?void 0:o.scene;if(i==null)return;const e=i.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e==null)return;const t=(s=this._sheetSkeletonManagerService.getCurrent())==null?void 0:s.skeleton;if(t==null)return;const r=e.calcViewportInfo();return t.getRangeByViewBound(r.viewBound)}_scrollToCell(i,e,t=!1,r=!1){var N,D,H,W;const{rowHeightAccumulation:o,columnWidthAccumulation:s}=(D=(N=this._sheetSkeletonManagerService.getCurrent())==null?void 0:N.skeleton)!=null?D:{};if(o==null||s==null)return!1;const l=(H=this._getSheetObject())==null?void 0:H.scene;if(l==null)return!1;const d=l.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(d==null)return!1;const c=(W=this._sheetSkeletonManagerService.getCurrent())==null?void 0:W.skeleton;if(c==null)return!1;const u=this._context.unit.getActiveSheet();if(!u)return!1;i=a.Tools.clamp(i,0,o.length-1),e=a.Tools.clamp(e,0,s.length-1);const{startColumn:h,startRow:g,ySplit:S,xSplit:f}=u.getFreeze(),p=this._getViewportBounding();if(p==null)return!1;const{startRow:v,startColumn:C,endRow:I,endColumn:b}=p;c.getVisibleRangeByViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);let T,M;if(i>=g&&e>=h-S&&(i<=v&&(T=i,t=!0),i>=I)){const k=o[i]-d.height;for(let U=v;U<=i&&(T=U+1,!(o[U]>=k));U++);}if(e>=h&&i>=g-S&&(e<=C&&(M=e,r=!0),e>=b)){const k=s[e]-d.width;for(let U=C;U<=e&&(M=U+1,!(s[U]>=k));U++);}if(T===void 0&&M===void 0)return!1;let{offsetX:y,offsetY:P,sheetViewStartRow:x,sheetViewStartColumn:A}=this._scrollManagerService.getCurrentScrollState()||{};if(T=T?Math.min(T,i):x+S,M=M?Math.min(M,e):A+f,r){y=0,M=e;const k=c.getHiddenColumnsInRange({startColumn:M-f,endColumn:M});M=M-k.length}if(t){P=0,T=i;const k=c.getHiddenRowsInRange({startRow:T-S,endRow:T});T=T-k.length}return this._commandService.syncExecuteCommand(je.id,{sheetViewStartRow:Math.max(0,T-S),sheetViewStartColumn:Math.max(0,M-f),offsetX:y,offsetY:P})}};exports.SheetsScrollRenderController=Du([on(1,a.Inject(a.Injector)),on(2,a.Inject(exports.SheetSkeletonManagerService)),on(3,a.IContextService),on(4,a.ICommandService),on(5,w.IRenderManagerService),on(6,a.Inject(exports.SheetScrollManagerService))],exports.SheetsScrollRenderController);const fs={id:"sheet.operation.scroll-to-range",type:a.CommandType.OPERATION,handler:(n,i)=>{if(!i)return!1;const e=n.get(a.IUniverInstanceService);return n.get(w.IRenderManagerService).getRenderById(e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(exports.SheetsScrollRenderController).scrollToRange(i.range,i.forceTop,i.forceLeft)}};class Ka{constructor(){R(this,"_state",null);R(this,"_rect",null);R(this,"_state$",new O.BehaviorSubject(null));R(this,"state$",this._state$.asObservable());R(this,"_rect$",new O.BehaviorSubject(null));R(this,"rect$",this._rect$.asObservable());R(this,"_focus",!1);R(this,"_focus$",new O.BehaviorSubject(this._focus));R(this,"focus$",this._focus$.asObservable())}dispose(){this._state$.complete(),this._state=null,this._rect$.complete(),this._rect=null}setState(i){this._state=i,this._refresh(i)}getRect(){return this._rect}setRect(i){this._rect=i,this._rect$.next(i)}getState(){return this._state}setFocus(i=!1){this._focus=i,this._focus$.next(i)}_refresh(i){this._state$.next(i)}}const hr=a.createIdentifier("univer.sheet-cell-editor-manager.service"),Vu="36",Wu="univer-sheet-container",qa={sheetFooterBarHeight:Vu,sheetContainer:Wu};var Uu=Object.defineProperty,Lu=Object.getOwnPropertyDescriptor,Bu=(n,i,e,t)=>{for(var r=t>1?void 0:t?Lu(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Uu(i,e,r),r},sn=(n,i)=>(e,t)=>i(e,t,n);const qs=5,Qs=2;exports.SheetCellEditorResizeService=class extends a.Disposable{constructor(i,e,t,r,o,s,l){super(),this._context=i,this._layoutService=e,this._cellEditorManagerService=t,this._editorBridgeService=r,this._renderManagerService=o,this._sheetSkeletonManagerService=s,this._univerInstanceService=l}fitTextSize(i){var A,N,D,H;const e=this._editorBridgeService.getEditCellState();if(!e)return;const{position:t,documentLayoutObject:r,canvasOffset:o,scaleX:s,scaleY:l}=e,{startX:d,startY:c,endX:u,endY:h}=t,g=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);if(g==null)return;const S=this._getEditorSkeleton();if(!S)return;const f=this._predictingSize(t,o,S,r,s,l);if(!f)return;let{actualWidth:p,actualHeight:v}=f;const{verticalAlign:C,horizontalAlign:I,paddingData:b,fill:T}=r;p=p+((A=b.l)!=null?A:0)+((N=b.r)!=null?N:0),v=v+((D=b.t)!=null?D:0)+((H=b.b)!=null?H:0);let M=u-d,y=h-c;M<p&&(M=Math.ceil(p)),y<v&&(y=Math.ceil(v));let P=0;C===a.VerticalAlign.MIDDLE?P=(y-v)/2/l:C===a.VerticalAlign.TOP?P=b.t||0:P=(y-v)/l;let x=0;I===a.HorizontalAlign.CENTER?x=(M-p)/2/s:I===a.HorizontalAlign.RIGHT?x=(M-p)/s:x=b.l||0,P=P<(b.t||0)?b.t||0:P,x=x<(b.l||0)?b.l||0:x,g.updateDocumentDataMargin({t:P,l:x}),S.calculate(),this._editAreaProcessing(M,y,t,o,T,s,l,I,i)}_predictingSize(i,e,t,r,o=1,s=1){const{startX:l,endX:d}=i,{textRotation:c,wrapStrategy:u,paddingData:h}=r,g=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC),{vertexAngle:S}=w.convertTextRotation(c);if(u===a.WrapStrategy.WRAP&&S===0){g==null||g.updateDocumentDataPageSize(d-l),g==null||g.updateDocumentDataMargin({l:h.l,t:h.t}),t.calculate();const{actualWidth:C,actualHeight:I}=t.getActualSize();return{actualWidth:C*o,actualHeight:I*s}}const f=this._getEditorMaxSize(i,e,r.horizontalAlign);if(!f)return;g==null||g.updateDocumentDataPageSize(f.width/o),t.calculate();const p=t.getActualSize();let v=d-l;return v<p.actualWidth*o+qs*o&&(v=p.actualWidth*o+qs*o),g==null||g.updateDocumentDataPageSize(v/o),g==null||g.updateDocumentRenderConfig({horizontalAlign:a.HorizontalAlign.UNSPECIFIED,cellValueType:void 0}),{actualWidth:p.actualWidth*o,actualHeight:p.actualHeight*s}}_getEditorMaxSize(i,e,t){if(this._getEditorObject()==null)return;function o(I){return Number.parseInt(I.replace("px",""))}const l=this._context.engine.getCanvasElement(),d=l.getBoundingClientRect(),c=o(l.style.width),{width:u}=d,h=u/c,{startX:g,startY:S,endX:f}=i,p=this._context.engine.width,v=document.body.clientHeight-S-Number.parseFloat(qa.sheetFooterBarHeight)-e.top-Qs*2;let C=u-g;if(t===a.HorizontalAlign.CENTER){const I=p-f,b=g;C=f-g+Math.min(b,I)*2}else t===a.HorizontalAlign.RIGHT&&(C=f);return{height:v,width:C-Qs,scaleAdjust:h}}_editAreaProcessing(i,e,t,r,o,s=1,l=1,d,c){var k;const u=this._getEditorObject();if(u==null)return;const g=this._context.engine.getCanvasElement();let{startX:S,startY:f}=t;const{document:p,scene:v,engine:C}=u,I=v.getViewport(J.VIEWPORT_KEY.VIEW_MAIN),b=this._getEditorMaxSize(t,r,d),{height:T,width:M,scaleAdjust:y}=b;let P=e,x=I==null?void 0:I.getScrollBar();P>T?(x==null?I&&new w.ScrollBar(I,{enableHorizontal:!1,barSize:8}):I==null||I.resetCanvasSizeAndUpdateScroll(),I==null||I.scrollToViewportPos({viewportScrollY:P-T}),P=T):(x=null,(k=I==null?void 0:I.getScrollBar())==null||k.dispose()),i+=(x==null?void 0:x.barSize)||0,i>M&&(i=M),this._addBackground(v,i/s,e/l,o);const{scaleX:A,scaleY:N}=v.getPrecisionScale();v.transformByState({width:i*y/s,height:e*y/l,scaleX:s*y,scaleY:l*y}),p.resize(i*y/s,e*y/l),setTimeout(()=>{C.resizeBySize(w.fixLineWidthByScale(i,A),w.fixLineWidthByScale(P,N)),c==null||c()},0);const D=this._layoutService.getContentElement().getBoundingClientRect(),H=g.getBoundingClientRect();S=S*y+(H.left-D.left),f=f*y+(H.top-D.top);const W=t.endX-t.startX;d===a.HorizontalAlign.RIGHT?S+=(W-i)*y:d===a.HorizontalAlign.CENTER&&(S+=(W-i*y)/2),this._cellEditorManagerService.setState({startX:S,startY:f,endX:i*y+S,endY:P*y+f,show:!0})}_addBackground(i,e,t,r){const o="_backgroundRectHelperColor_",s=i.getObject(o);s==null&&r==null||(s==null?i.addObjects([new w.Rect(o,{width:e,height:t,fill:r,evented:!1})],J.DOCS_COMPONENT_MAIN_LAYER_INDEX):r==null?s.dispose():(s.setProps({fill:r}),s.transformByState({width:e,height:t})))}resizeCellEditor(i){var y;const e=this._cellEditorManagerService.getState();if(!e||!this._editorBridgeService.isVisible().visible)return;this._editorBridgeService.refreshEditCellPosition(!0);const t=this._editorBridgeService.getEditCellState();if(!t)return;const r=(y=this._sheetSkeletonManagerService.getWorksheetSkeleton(t.sheetId))==null?void 0:y.skeleton;if(!r)return;const{row:o,column:s,scaleX:l,scaleY:d,position:c,canvasOffset:u,documentLayoutObject:h}=t,{horizontalAlign:g}=h,S=this._getEditorMaxSize(c,u,g);if(!S)return;const{height:f,width:p,scaleAdjust:v}=S,C=r.getCellWithCoordByIndex(o,s),I=Math.min((C.mergeInfo.endY-C.mergeInfo.startY)*d,f)*v,b=Math.min((C.mergeInfo.endX-C.mergeInfo.startX)*l,p)*v,T=e.endY-e.startY,M=e.endX-e.startX;if(T!==I||M!==b){if(this._editorBridgeService.refreshEditCellPosition(!0),!this._getEditorSkeleton())return;this.fitTextSize(i)}}_getEditorObject(){return Ei(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}_getEditorSkeleton(){var i;return(i=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:i.with(be.DocSkeletonManagerService).getSkeleton()}};exports.SheetCellEditorResizeService=Bu([sn(1,E.ILayoutService),sn(2,hr),sn(3,Se),sn(4,w.IRenderManagerService),sn(5,a.Inject(exports.SheetSkeletonManagerService)),sn(6,a.IUniverInstanceService)],exports.SheetCellEditorResizeService);function ps(n){return n.getContextValue(a.FOCUSING_SHEET)}function le(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function Qa(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function Fu(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function ju(n){return n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function Ja(n){return n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function zu(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.EDITOR_ACTIVATED)&&n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function er(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&!n.getContextValue(a.FOCUSING_EDITOR_STANDALONE)}const $a=[E.KeyCode.ARROW_DOWN,E.KeyCode.ARROW_UP,E.KeyCode.ARROW_LEFT,E.KeyCode.ARROW_RIGHT],Xu=[E.KeyCode.ENTER,E.KeyCode.TAB,...$a];function el(){const n=[];for(const i of $a)n.push({id:Xt.id,binding:i,preconditions:e=>er(e),staticParameters:{visible:!1,eventType:w.DeviceInputEventType.Keyboard,keycode:i,isShift:!1}}),n.push({id:Xt.id,binding:i|E.MetaKeys.SHIFT,preconditions:e=>er(e),staticParameters:{visible:!1,eventType:w.DeviceInputEventType.Keyboard,keycode:i,isShift:!0}});return n}const tl={id:ur.id,binding:E.KeyCode.F2,description:"shortcut.sheet.start-editing",group:"4_sheet-edit",preconditions:le,staticParameters:{visible:!0,eventType:w.DeviceInputEventType.Keyboard,keycode:E.KeyCode.F2}},nl={id:Te.id,binding:E.KeyCode.ENTER,description:"shortcut.sheet.toggle-editing",group:"4_sheet-edit",preconditions:n=>er(n),staticParameters:{visible:!1,eventType:w.DeviceInputEventType.Keyboard,keycode:E.KeyCode.ENTER}},rl={id:Te.id,binding:E.KeyCode.TAB,preconditions:n=>er(n),staticParameters:{visible:!1,eventType:w.DeviceInputEventType.Keyboard,keycode:E.KeyCode.TAB}},il={id:Te.id,binding:E.KeyCode.ESC,description:"shortcut.sheet.abort-editing",group:"4_sheet-edit",preconditions:n=>er(n),staticParameters:{visible:!1,eventType:w.DeviceInputEventType.Keyboard,keycode:E.KeyCode.ESC}},ol={id:J.BreakLineCommand.id,description:"shortcut.sheet.break-line",group:"4_sheet-edit",preconditions:n=>Fu(n),binding:E.KeyCode.ENTER|E.MetaKeys.ALT},sl={id:J.DeleteLeftCommand.id,preconditions:n=>ju(n)||Ja(n),binding:E.KeyCode.BACKSPACE},al={id:Te.id,description:"shortcut.sheet.delete-and-start-editing",group:"4_sheet-edit",preconditions:n=>le(n)&&!Ja(n),binding:E.KeyCode.BACKSPACE,staticParameters:{visible:!0,eventType:w.DeviceInputEventType.Keyboard,keycode:E.KeyCode.BACKSPACE}};function Yu(n){return n.startsWith("'")}function Gu(n){return n.slice(1)}const Zu={"0":"0","1":"1","2":"2","3":"3","4":"4","5":"5","6":"6","7":"7","8":"8","9":"9",A:"A",B:"B",C:"C",D:"D",E:"E",F:"F",G:"G",H:"H",I:"I",J:"J",K:"K",L:"L",M:"M",N:"N",O:"O",P:"P",Q:"Q",R:"R",S:"S",T:"T",U:"U",V:"V",W:"W",X:"X",Y:"Y",Z:"Z",a:"a",b:"b",c:"c",d:"d",e:"e",f:"f",g:"g",h:"h",i:"i",j:"j",k:"k",l:"l",m:"m",n:"n",o:"o",p:"p",q:"q",r:"r",s:"s",t:"t",u:"u",v:"v",w:"w",x:"x",y:"y",z:"z","%":"%","-":"-",".":".",":":":","/":"/","+":"+","@":"@","&":"&","*":"*","#":"#","=":"=",">":">","<":"<","$":"$",""":'"',"'":"'","(":"(",")":")"," ":" ",",":",","!":"!","?":"?",";":";","[":"[","]":"]","{":"{","}":"}"},Uo={true:"TRUE",false:"FALSE"};function Ku(n){return[a.LocaleType.ZH_CN,a.LocaleType.ZH_TW].includes(n)}function qu(n,i,e,t){let r=n;if(Ku(e)){if(n.startsWith("'")||n.startsWith("'"))return`'${n.slice(1)}`;r=Qu(r)}if(r.startsWith("="))return Ju(n,r,i,t);const o=r.toLowerCase();return Uo[o]?Uo[o]:a.numfmt.parseValue(r)==null?n:r}function Qu(n){const i=/['"].*?['"]/g,e=[],t=n.split(i);n.replace(i,o=>(e.push(o),""));let r=t.join("").split("").map(th).join("");return e.forEach((o,s)=>{r=r.slice(0,s*2)+o+r.slice((s+1)*2)}),r}function Ju(n,i,e,t){const r=e.sequenceNodesBuilder(i);if(!r)return n;let o=i,s=0;return r.forEach((l,d)=>{if(typeof l=="object"){const c=l.token;if(Uo[c.toLowerCase()]){const u=l.startIndex+s+1,h=l.endIndex+s+2;o=an(c.toLocaleUpperCase(),o,u,h)}else if(l.nodeType===G.sequenceNodeType.FUNCTION&&$u(c,t,r,d)||l.nodeType===G.sequenceNodeType.REFERENCE){const u=c.indexOf("!");if(u>-1){const h=c.substring(u+1),g=l.startIndex+s+(u+1)+1,S=l.endIndex+s+2;o=an(h.toLocaleUpperCase(),o,g,S)}else{const h=l.startIndex+s+1,g=l.endIndex+s+2;o=an(c.toLocaleUpperCase(),o,h,g)}}else if(c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'")){const u=l.startIndex+s+2,h=l.endIndex+s+1;o=an(n.slice(u,h),o,u,h)}else if(l.nodeType!==G.sequenceNodeType.ARRAY){const u=a.numfmt.parseValue(c);if(u==null){const h=l.startIndex+s+1,g=l.endIndex+s+2;o=an(n.slice(h,g),o,h,g)}else if(typeof u.v=="number"&&(u.z===void 0||!a.numfmt.isDate(u.z))){const h=`${u.v}`,g=l.startIndex+s+1,S=l.endIndex+s+2,{processedString:f,offset:p}=nh(c,h);o=an(f,o,g,S),s+=p}}}}),o}function $u(n,i,e,t){const r=i.getDescriptions();return e[t+1]!==G.matchToken.OPEN_BRACKET?!1:r.get(eh(n).toLocaleUpperCase())!==void 0}function eh(n){const i=/^@+/;return n.replace(i,"")}function th(n){return Zu[n]||n}function an(n,i,e,t){return i.substring(0,e)+n+i.substring(t)}function nh(n,i){var s,l;const e=((s=n.match(/^\s*/))==null?void 0:s[0])||"",t=((l=n.match(/\s*$/))==null?void 0:l[0])||"",r=e+i+t,o=r.length-n.length;return{processedString:r,offset:o}}const ll="range_selector",cl=n=>n.includes(ll);var rh=Object.defineProperty,ih=Object.getOwnPropertyDescriptor,oh=(n,i,e,t)=>{for(var r=t>1?void 0:t?ih(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&rh(i,e,r),r},ye=(n,i)=>(e,t)=>i(e,t,n);const Js=-1e3;exports.EditingRenderController=class extends a.Disposable{constructor(e,t,r,o,s,l,d,c,u,h,g,S,f,p,v,C){super();R(this,"_cursorChange",0);R(this,"_isUnitEditing",!1);R(this,"_workbookSelections");R(this,"_d");R(this,"_cursorTimeout");this._context=e,this._undoRedoService=r,this._contextService=o,this._renderManagerService=s,this._editorBridgeService=l,this._cellEditorManagerService=d,this._lexerTreeBuilder=c,this._functionService=u,this._textSelectionManagerService=h,this._commandService=g,this._localService=S,this._editorService=f,this._sheetCellEditorResizeService=p,this._univerInstanceService=v,this._sheetInterceptorService=C,this._workbookSelections=t.getWorkbookSelections(this._context.unitId),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(I=>{(I==null?void 0:I.getUnitId())===this._context.unitId?this._d=this._init():(this._disposeCurrent(),this._isUnitEditing&&(this._handleEditorInvisible({visible:!1,eventType:w.DeviceInputEventType.Keyboard,keycode:E.KeyCode.ESC,unitId:this._context.unitId}),this._isUnitEditing=!1))})),this._initEditorVisibilityListener()}dispose(){super.dispose(),this._disposeCurrent()}_disposeCurrent(){var e;(e=this._d)==null||e.dispose(),this._d=null}_init(){const e=new a.DisposableCollection;return this._subscribeToCurrentCell(e),this._initialCursorSync(e),this._listenEditorFocus(e),this._commandExecutedListener(e),this._initSkeletonListener(e),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{clearTimeout(this._cursorTimeout)})),this._cursorTimeout=setTimeout(()=>{this._cursorStateListener(e)},1e3),e}_initEditorVisibilityListener(){this.disposeWithMe(this._editorBridgeService.visible$.pipe(O.distinctUntilChanged((e,t)=>e.visible===t.visible)).subscribe(e=>{(e.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY||e.unitId===this._context.unitId)&&e.visible?(this._isUnitEditing=!0,this._handleEditorVisible(e)):this._isUnitEditing&&(this._handleEditorInvisible(e),this._isUnitEditing=!1)}))}_listenEditorFocus(e){const t=this._getEditorObject();t&&e.add(t.document.onPointerDown$.subscribeEvent(()=>{if(this._isUnitEditing&&this._editorBridgeService.isVisible()){const r=this._editorBridgeService.getEditCellState(),o=this._editorBridgeService.getCurrentEditorId();if(!r||!o)return;this._sheetCellEditorResizeService.fitTextSize()}}))}_initialCursorSync(e){e.add(this._cellEditorManagerService.focus$.pipe(O.filter(t=>!!t)).subscribe(()=>{var r;const t=(r=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_DOC))==null?void 0:r.with(J.DocSelectionRenderService);t&&t.sync()}))}_initSkeletonListener(e){const t=new Set(m.COMMAND_LISTENER_SKELETON_CHANGE);t.delete(m.SetWorksheetActiveOperation.id),e.add(this._commandService.onCommandExecuted(r=>{t.has(r.id)&&this._sheetCellEditorResizeService.resizeCellEditor(()=>{this._textSelectionManagerService.refreshSelection({unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})})}))}_subscribeToCurrentCell(e){e.add(this._editorBridgeService.currentEditCellState$.subscribe(t=>{var I,b;if(t==null||this._editorBridgeService.isForceKeepVisible())return;const r=this._editorBridgeService.getEditCellState();if(r==null)return;const{position:o,documentLayoutObject:s,scaleX:l,editorUnitId:d}=r;if(this._contextService.getContextValue(a.FOCUSING_EDITOR_STANDALONE))return;const c=this._getDocumentDataModel();if(c==null)return;const{startX:u,endX:h}=o,{textRotation:g,wrapStrategy:S,documentModel:f}=s,{vertexAngle:p}=w.convertTextRotation(g);S===a.WrapStrategy.WRAP&&p===0&&c.updateDocumentDataPageSize((h-u)/l),this._commandService.syncExecuteCommand(J.ReplaceSnapshotCommand.id,{unitId:d,snapshot:f.getSnapshot()}),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!0),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});const v=(I=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:I.with(J.DocSelectionRenderService),C=(b=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:b.with(J.DocSelectionRenderService);(v!=null&&v.canFocusing||C!=null&&C.canFocusing)&&(this._univerInstanceService.setCurrentUnitForType(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),v==null||v.activate(Js,Js,!0))}))}_commandExecutedListener(e){e.add(this._commandService.onCommandExecuted(r=>{if(r.id===be.RichTextEditingMutation.id){const o=r.params,{unitId:s}=o;if(!this._isCurrentSheetFocused()||cl(s)||(this._editorBridgeService.changeEditorDirty(!0),!this._editorBridgeService.isVisible().visible))return;s===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._sheetCellEditorResizeService.fitTextSize()}}));const t=[Xt.id];e.add(this._commandService.onCommandExecuted(r=>{if(t.includes(r.id)){const o=r.params,{keycode:s,isShift:l}=o;if(s!=null&&(this._cursorChange===2||this._contextService.getContextValue(a.FOCUSING_FX_BAR_EDITOR))){this._moveInEditor(s,l);return}this._editorBridgeService.changeVisible(o)}r.id===ur.id&&(this._cursorChange=2)}))}_handleEditorVisible(e){var S,f,p;const{eventType:t,keycode:r}=e;this._cursorChange=t===w.DeviceInputEventType.PointerDown||t===w.DeviceInputEventType.Dblclick?2:1;const o=this._editorBridgeService.getEditLocation();if(o==null)return;this._commandService.syncExecuteCommand(fs.id,{range:{startRow:o.row,startColumn:o.column,endRow:o.row,endColumn:o.column}}),this._editorBridgeService.refreshEditCellPosition(!1);const{unitId:s,isInArrayFormulaRange:l=!1}=o,d=this._getEditorObject();if(d==null)return;const{document:c,scene:u}=d;this._contextService.setContextValue(a.EDITOR_ACTIVATED,!0);const h=this._getDocumentDataModel(),g=this._getEditorSkeleton(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(!(!g||!h)){if(this._sheetCellEditorResizeService.fitTextSize(()=>{const v=u.getViewport(J.VIEWPORT_KEY.VIEW_MAIN);v==null||v.scrollToViewportPos({viewportScrollX:Number.POSITIVE_INFINITY,viewportScrollY:Number.POSITIVE_INFINITY})}),t===w.DeviceInputEventType.Keyboard&&r===E.KeyCode.F2){c.makeDirty(),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}]);const v=((f=(S=h.getBody())==null?void 0:S.dataStream.length)!=null?f:2)-2;this._textSelectionManagerService.replaceDocRanges([{startOffset:v,endOffset:v}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})}else if(t===w.DeviceInputEventType.Keyboard||t===w.DeviceInputEventType.Dblclick&&l)this._emptyDocumentDataModel(h.getSnapshot().documentStyle,!!l),c.makeDirty(),(r===E.KeyCode.BACKSPACE||t===w.DeviceInputEventType.Dblclick)&&(g.calculate(),this._editorBridgeService.changeEditorDirty(!0)),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});else if(t===w.DeviceInputEventType.Dblclick){if(this._contextService.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA))return;const v=h.getBody().dataStream.length-2||0;this._textSelectionManagerService.replaceDocRanges([{startOffset:v,endOffset:v}])}(p=this._renderManagerService.getRenderById(s))==null||p.scene.resetCursor()}}async _handleEditorInvisible(e){const t=this._editorBridgeService.getEditCellState(),r=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),o=a.Tools.deepClone(r==null?void 0:r.getSnapshot());let{keycode:s}=e;if(this._cursorChange=0,this._exitInput(e),t==null)return;this._editorBridgeService.getEditorDirty()===!1&&(s=E.KeyCode.ESC);const c=this._context.unit.getActiveSheet(),u=this._context.unitId,h=c.getSheetId(),{unitId:g,sheetId:S}=t;if(u===g&&S!==h&&await this._commandService.executeCommand(m.SetWorksheetActivateCommand.id,{subUnitId:S,unitId:g}),s===E.KeyCode.ESC){this._editorBridgeService.isForceKeepVisible()&&this._editorBridgeService.disableForceKeepVisible();const f=this._workbookSelections.getCurrentSelections();f&&(this._contextService.setContextValue(m.REF_SELECTIONS_ENABLED,!1),this._commandService.syncExecuteCommand(m.SetSelectionsOperation.id,{unitId:this._context.unit.getUnitId(),subUnitId:S,selections:f}));return}o&&await this._submitCellData(o),this._moveCursor(s)}_getEditorObject(){return Ei(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}submitCellData(e){return this._submitCellData(e.getSnapshot())}async _submitCellData(e){const t=this._editorBridgeService.getEditCellState();if(t==null)return;const{unitId:r,sheetId:o,row:s,column:l}=t,d=this._context.unit;let c=d.getActiveSheet();if(!d.getSheetBySheetId(o))return;c=d.getActiveSheet();const h=sh({...c.getCellRaw(s,l)||{}},e,this._lexerTreeBuilder,this._localService,this._functionService,d.getStyles());if(!h)return;const g=await this._sheetInterceptorService.onWriteCell(d,c,s,l,h);g!==c.getCellRaw(s,l)&&this._commandService.executeCommand(m.SetRangeValuesCommand.id,{subUnitId:o,unitId:r,range:{startRow:s,startColumn:l,endRow:s,endColumn:l},value:g})}_exitInput(e){var o;this._contextService.setContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA,!1),this._contextService.setContextValue(a.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!1),this._contextService.setContextValue(a.FOCUSING_FX_BAR_EDITOR,!1),this._cellEditorManagerService.setState({show:e.visible});const t=this._getEditorObject();(o=t==null?void 0:t.scene.getViewport(J.VIEWPORT_KEY.VIEW_MAIN))==null||o.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});const r=this._editorBridgeService.getCurrentEditorId();r==null||!this._editorService.isSheetEditor(r)||(this._undoRedoService.clearUndoRedo(r),this._undoRedoService.clearUndoRedo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))}_moveCursor(e){if(e==null||!Xu.includes(e))return;let t=a.Direction.LEFT;switch(e){case E.KeyCode.ENTER:t=a.Direction.DOWN;break;case E.KeyCode.TAB:t=a.Direction.RIGHT;break;case E.KeyCode.ARROW_DOWN:t=a.Direction.DOWN;break;case E.KeyCode.ARROW_UP:t=a.Direction.UP;break;case E.KeyCode.ARROW_LEFT:t=a.Direction.LEFT;break;case E.KeyCode.ARROW_RIGHT:t=a.Direction.RIGHT;break}e===E.KeyCode.ENTER||e===E.KeyCode.TAB?this._commandService.executeCommand(et.id,{keycode:e,direction:t}):this._commandService.executeCommand(xe.id,{direction:t})}_cursorStateListener(e){const t=this._getEditorObject();if(!(t!=null&&t.document))return;const{document:r}=t;e.add(a.toDisposable(r.onPointerDown$.subscribeEvent(()=>{this._cursorChange===1&&(this._cursorChange=2)})))}_moveInEditor(e,t){let r=a.Direction.LEFT;e===E.KeyCode.ARROW_DOWN?r=a.Direction.DOWN:e===E.KeyCode.ARROW_UP?r=a.Direction.UP:e===E.KeyCode.ARROW_RIGHT&&(r=a.Direction.RIGHT),t?this._commandService.executeCommand(J.MoveSelectionOperation.id,{direction:r}):this._commandService.executeCommand(J.MoveCursorOperation.id,{direction:r})}_getDocumentDataModel(){return this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC)}_isCurrentSheetFocused(){var e;return((e=this._univerInstanceService.getFocusedUnit())==null?void 0:e.getUnitId())===this._context.unitId}_getEditorSkeleton(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(be.DocSkeletonManagerService).getSkeleton()}_getEditorViewModel(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(be.DocSkeletonManagerService).getViewModel()}_emptyDocumentDataModel(e,t){const r=(l,d)=>{const c=a.Tools.deepClone(l.getSnapshot()),u=this._getEditorViewModel(l.getUnitId());u!=null&&(ah(c.body,t),d&&(c.documentStyle=e),c.drawings={},c.drawingsOrder=[],l.reset(c),u.reset(l))},o=this._getDocumentDataModel();o&&r(o,!0);const s=this._univerInstanceService.getUnit(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);s&&r(s)}};exports.EditingRenderController=oh([ye(1,a.Inject(m.SheetsSelectionsService)),ye(2,a.IUndoRedoService),ye(3,a.IContextService),ye(4,w.IRenderManagerService),ye(5,Se),ye(6,hr),ye(7,a.Inject(G.LexerTreeBuilder)),ye(8,G.IFunctionService),ye(9,a.Inject(be.DocSelectionManagerService)),ye(10,a.ICommandService),ye(11,a.Inject(a.LocaleService)),ye(12,J.IEditorService),ye(13,a.Inject(exports.SheetCellEditorResizeService)),ye(14,a.IUniverInstanceService),ye(15,a.Inject(m.SheetInterceptorService))],exports.EditingRenderController);function sh(n,i,e,t,r,o){var h,g,S;if((i==null?void 0:i.body)==null)return null;const{body:s}=i;n.t=void 0;const l=s.dataStream;let c=l.substring(l.length-2,l.length)===a.DEFAULT_EMPTY_DOCUMENT_VALUE?l.substring(0,l.length-2):l;const u=t.getCurrentLocale();if(c=qu(c,e,u,r),(h=i.drawingsOrder)!=null&&h.length)n.v="",n.f=null,n.si=null,n.p=i,n.t=a.CellValueType.STRING;else if(n.s&&((S=(g=o==null?void 0:o.get(n.s))==null?void 0:g.n)==null?void 0:S.pattern)===gd.DEFAULT_TEXT_FORMAT){n.v=c,n.f=null,n.si=null,n.p=null,n.t=a.CellValueType.STRING,Lo(s)&&s.dataStream!==`\r
1
+ "use strict";var hd=Object.defineProperty;var md=(n,i,e)=>i in n?hd(n,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[i]=e;var R=(n,i,e)=>md(n,typeof i!="symbol"?i+"":i,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const J=require("@univerjs/docs-ui"),a=require("@univerjs/core"),w=require("@univerjs/engine-render"),E=require("@univerjs/ui"),V=require("react"),O=require("rxjs"),m=require("@univerjs/sheets"),be=require("@univerjs/docs"),G=require("@univerjs/engine-formula"),gd=require("@univerjs/engine-numfmt"),K=require("@univerjs/design"),_=require("react/jsx-runtime"),Sd=require("@univerjs/telemetry"),Ba=require("rxjs/operators");function Ei(n,i){if(n==null)return;const e=i.getRenderById(n);if(e==null)return;const{mainComponent:t,scene:r,engine:o,components:s}=e,l=t,d=s.get(J.DOCS_VIEW_KEY.BACKGROUND);return{document:l,docBackground:d,scene:r,engine:o}}const Ao=[10,400],ss="RANGE_SELECTOR_COMPONENT_KEY",Ti="EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY";var he=(n=>(n.MAIN="__SpreadsheetRender__",n.ROW="__SpreadsheetRowHeader__",n.COLUMN="__SpreadsheetColumnHeader__",n.LEFT_TOP="__SpreadsheetLeftTopPlaceholder__",n))(he||{});const Ws=0,Qr=1,bt=10,fd=11,Us=12,wi={id:"sheet.command.set-row-header-width",type:a.CommandType.COMMAND,handler:async(n,i)=>{if(!i)return!1;const e=n.get(w.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:r,size:o}=i,s=e.getRenderById(t);if(s){e.getRenderById(t).with(exports.SheetSkeletonManagerService).setRowHeaderSize(s,r,o);const{components:d}=s,c=d.get(he.ROW);c&&c.setCustomHeader({headerStyle:{size:o}})}return!0}},yi={id:"sheet.command.set-col-header-height",type:a.CommandType.COMMAND,handler:async(n,i)=>{if(!i)return!1;const e=n.get(w.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:r,size:o}=i,s=e.getRenderById(t);if(s){e.getRenderById(t).with(exports.SheetSkeletonManagerService).setColumnHeaderSize(s,r,o);const{components:d}=s,c=d.get(he.COLUMN);c&&c.setCustomHeader({headerStyle:{size:o}})}return!0}},No=a.createInterceptorKey("rangeMovePermissionCheck"),Do=a.createInterceptorKey("rangeFillPermissionCheck");var as=(n=>(n[n.FORMULA_EDITOR_SHOW=100]="FORMULA_EDITOR_SHOW",n[n.MARK_SELECTION=1e4]="MARK_SELECTION",n))(as||{});function Rt(n){const i=n.getCurrentTheme(),e=new a.ColorKit(i.primaryColor).setAlpha(.07).toRgbString();return{strokeWidth:1,stroke:i.primaryColor,fill:e,widgets:{},widgetSize:6,widgetStrokeWidth:1,widgetStroke:i.colorWhite,autofillSize:6,autofillStrokeWidth:1,autofillStroke:i.colorWhite,rowHeaderFill:e,rowHeaderStroke:i.primaryColor,rowHeaderStrokeWidth:1,columnHeaderFill:e,columnHeaderStroke:i.primaryColor,columnHeaderStrokeWidth:1,expandCornerSize:40}}class pd{constructor(){R(this,"_startColumn",-1);R(this,"_startRow",-1);R(this,"_endColumn",-1);R(this,"_endRow",-1);R(this,"_startX",0);R(this,"_startY",0);R(this,"_endX",0);R(this,"_endY",0);R(this,"_primary");R(this,"_rangeType",a.RANGE_TYPE.NORMAL)}get startColumn(){return this._startColumn}get startRow(){return this._startRow}get endColumn(){return this._endColumn}get endRow(){return this._endRow}get startX(){return this._startX}get startY(){return this._startY}get endX(){return this._endX}get endY(){return this._endY}get currentCell(){return this._primary}get rangeType(){return this._rangeType}isEqual(i){const{startColumn:e,startRow:t,endColumn:r,endRow:o}=this,{startColumn:s,startRow:l,endColumn:d,endRow:c}=i;return e===s&&t===l&&r===d&&o===c}isInclude(i){const{startColumn:e,startRow:t,endColumn:r,endRow:o}=this,{startColumn:s,startRow:l,endColumn:d,endRow:c}=i;return!(d<e||s>r||l>o||c<t)}highlightToSelection(){if(this._primary)return a.convertCellToRange(this._primary)}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._primary}getRangeType(){return this._rangeType}setRangeType(i){this._rangeType=i}getValue(){return{rangeWithCoord:this.getRange(),primaryWithCoord:this._primary}}setValue(i,e){const{startColumn:t,startRow:r,endColumn:o,endRow:s,startX:l,startY:d,endX:c,endY:u,rangeType:h}=i;this._startColumn=t,this._startRow=r,this._endColumn=o,this._endRow=s,this._startX=l,this._startY=d,this._endX=c,this._endY=u,h!==void 0&&(this._rangeType=h),e!==void 0&&this.setCurrentCell(e)}setCurrentCell(i){this._primary=i}clearCurrentCell(){this._primary=null}}function In(n,i){const{startRow:e,startColumn:t,endRow:r,endColumn:o,rangeType:s}=i,l=r<e?r:e,d=r<e?e:r,c=o<t?o:t,u=o<t?t:o,h=n.getNoMergeCellPositionByIndex(l,c),g=n.getNoMergeCellPositionByIndex(d,u);return{startRow:e,startColumn:t,endRow:r,endColumn:o,rangeType:s,startY:(h==null?void 0:h.startY)||0,endY:(g==null?void 0:g.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(g==null?void 0:g.endX)||0}}function Me(n,i){const{range:e,primary:t,style:r}=n,o=In(i,e),s=t&&Qn(i,t);return{rangeWithCoord:o,primaryWithCoord:s,style:r}}function Qn(n,i){const{actualRow:e,actualColumn:t,isMerged:r,isMergedMainCell:o,startRow:s,startColumn:l,endRow:d,endColumn:c}=i,u=n.getNoMergeCellPositionByIndex(e,t),h=n.getNoMergeCellPositionByIndex(s,l),g=n.getNoMergeCellPositionByIndex(d,c);return{actualRow:e,actualColumn:t,isMerged:r,isMergedMainCell:o,startX:u.startX,startY:u.startY,endX:u.endX,endY:u.endY,mergeInfo:{startRow:s,startColumn:l,endRow:d,endColumn:c,startY:(h==null?void 0:h.startY)||0,endY:(g==null?void 0:g.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(g==null?void 0:g.endX)||0}}}const Ls="__SpreadsheetHelperSelectionTempRect",vd=35;class Fa{constructor(i,e){R(this,"_startOffsetX",0);R(this,"_startOffsetY",0);R(this,"_relativeSelectionPositionRow",0);R(this,"_relativeSelectionPositionColumn",0);R(this,"_relativeSelectionRowLength",0);R(this,"_relativeSelectionColumnLength",0);R(this,"_scenePointerMoveSub");R(this,"_scenePointerUpSub");R(this,"_helperSelection");R(this,"_scrollTimer");R(this,"_activeViewport");R(this,"_targetSelection",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});R(this,"_isInMergeState",!1);R(this,"_fillControlColors",[]);R(this,"_skeleton");R(this,"_scene");R(this,"_themeService");R(this,"_injector");R(this,"_selectionHooks");this._control=i,this._skeleton=e.skeleton,this._scene=e.scene,this._themeService=e.themeService,this._injector=e.injector,this._selectionHooks=e.selectionHooks,this._initialControl(),this._initialWidget(),this._initialAutoFill(),this._control.dispose$.subscribe(()=>{this.dispose()})}get isHelperSelection(){return this._control.isHelperSelection}dispose(){var i,e;(i=this._scrollTimer)==null||i.dispose(),this._fillControlColors=[],this._clearObserverEvent(),(e=this._helperSelection)==null||e.dispose()}_getFreeze(){var t,r;return(r=(t=this._injector.get(w.IRenderManagerService).withCurrentTypeOfUnit(a.UniverInstanceType.UNIVER_SHEET,exports.SheetSkeletonManagerService))==null?void 0:t.getCurrent())==null?void 0:r.skeleton.getWorksheetConfig().freeze}_isSelectionInViewport(i,e){const t=this._getFreeze()||{startRow:-1,startColumn:-1,xSplit:0,ySplit:0};switch(e.viewportKey){case w.SHEET_VIEWPORT_KEY.VIEW_MAIN:return i.endRow>=t.startRow&&i.endColumn>=t.startColumn;case w.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP:case w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT:return i.endColumn>=t.startColumn&&i.startRow<t.startRow;case w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT:case w.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM:return i.endRow>=t.startRow&&i.startColumn<t.startColumn;case w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP:case w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT:case w.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP:case w.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP:return i.startRow<t.startRow&&i.startColumn<t.startColumn}}_clearObserverEvent(){var i,e;(i=this._scenePointerMoveSub)==null||i.unsubscribe(),(e=this._scenePointerUpSub)==null||e.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null}_initialControl(){const{leftControl:i,rightControl:e,topControl:t,bottomControl:r}=this._control;[i,e,t,r].forEach(o=>{o.onPointerEnter$.subscribeEvent(()=>{var l;((l=this._injector.get(ve,a.Quantity.OPTIONAL))==null?void 0:l.interceptor.fetchThroughInterceptors(No)(!1,null))!==!1&&o.setCursor(w.CURSOR_TYPE.MOVE)}),o.onPointerLeave$.subscribeEvent(()=>{o.resetCursor()}),o.onPointerDown$.subscribeEvent(this._controlPointerDownHandler.bind(this))})}_controlMoving(i,e){var A;const t=this._scene,r=t.getScrollXYInfoByViewport(w.Vector2.FromArray([i,e])),{scaleX:o,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(i,e,o,s,r),{row:d,column:c}=l,u=this._skeleton.getRowCount()-1,h=this._skeleton.getColumnCount()-1;let g=Math.max(0,d+this._relativeSelectionPositionRow),S=g+this._relativeSelectionRowLength;S>u&&(S=u,S-g<this._relativeSelectionRowLength&&(g=S-this._relativeSelectionRowLength));let f=Math.max(0,c+this._relativeSelectionPositionColumn),p=f+this._relativeSelectionColumnLength;p>h&&(p=h,p-f<this._relativeSelectionColumnLength&&(f=p-this._relativeSelectionColumnLength));const v=this._skeleton.worksheet.getCellInfoInMergeData(g,f),I=Me({range:{startRow:g,endRow:S,startColumn:f,endColumn:p},primary:v,style:null},this._skeleton),b=this._skeleton.getNoMergeCellPositionByIndex(g,f),T=this._skeleton.getNoMergeCellPositionByIndex(S,p),M=(b==null?void 0:b.startY)||0,y=(T==null?void 0:T.endY)||0,P=(b==null?void 0:b.startX)||0,x=(T==null?void 0:T.endX)||0;(A=this._helperSelection)==null||A.transformByState({left:P,top:M,width:x-P,height:y-M}),this._targetSelection={...I.rangeWithCoord},this._control.selectionMoving$.next(I.rangeWithCoord)}_controlPointerDownHandler(i){const{offsetX:e,offsetY:t}=i,r=this._scene,o=r.getCoordRelativeToViewport(w.Vector2.FromArray([e,t])),{x:s,y:l}=o,d=r.getScrollXYInfoByViewport(o),{scaleX:c,scaleY:u}=r.getAncestorScale(),h=this._skeleton.getCellIndexByOffset(s,l,c,u,d);this._startOffsetX=s,this._startOffsetY=l;const{row:g,column:S}=h,{startRow:f,startColumn:p,endRow:v,endColumn:C}=this._control.model;let I=0,b=0;g<f?I-=1:g>v&&(I+=1),S<p?b-=1:S>C&&(b+=1),this._relativeSelectionPositionRow=f-g+I,this._relativeSelectionPositionColumn=p-S+b,this._relativeSelectionRowLength=v-f,this._relativeSelectionColumnLength=C-p;const T=this._control.currentStyle,M=this._getScale();this.isHelperSelection&&(this._helperSelection=new w.Rect(Ls,{stroke:T.stroke,strokeWidth:T.strokeWidth/M}),r.addObject(this._helperSelection));const y=r.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN),P=w.ScrollTimer.create(r);this._scrollTimer=P,P.startScroll(s,l,y),r.disableObjectsEvent(),this._scenePointerMoveSub=r.onPointerMove$.subscribeEvent(x=>{var k;const{offsetX:A,offsetY:N}=x;if(((k=this._injector.get(ve,a.Quantity.OPTIONAL))==null?void 0:k.interceptor.fetchThroughInterceptors(No)(!1,null))===!1)return;const{x:H,y:W}=r.getCoordRelativeToViewport(w.Vector2.FromArray([A,N]));this._controlMoving(H,W),r.setCursor(w.CURSOR_TYPE.MOVE),P.scrolling(H,W,()=>{this._controlMoving(H,W)})}),this._scenePointerUpSub=r.onPointerUp$.subscribeEvent(()=>{var A,N,D,H;(A=this._helperSelection)==null||A.dispose();const x=this._scene;x.resetCursor(),this._clearObserverEvent(),x.enableObjectsEvent(),(N=this._scrollTimer)==null||N.dispose(),this._control.selectionMoveEnd$.next(this._targetSelection),(H=(D=this._selectionHooks).selectionMoveEnd)==null||H.call(D)})}_initialWidget(){const{topLeftWidget:i,topCenterWidget:e,topRightWidget:t,middleLeftWidget:r,middleRightWidget:o,bottomLeftWidget:s,bottomCenterWidget:l,bottomRightWidget:d}=this._control,c=[w.CURSOR_TYPE.NORTH_WEST_RESIZE,w.CURSOR_TYPE.NORTH_RESIZE,w.CURSOR_TYPE.NORTH_EAST_RESIZE,w.CURSOR_TYPE.WEST_RESIZE,w.CURSOR_TYPE.EAST_RESIZE,w.CURSOR_TYPE.SOUTH_WEST_RESIZE,w.CURSOR_TYPE.SOUTH_RESIZE,w.CURSOR_TYPE.SOUTH_EAST_RESIZE];[i,e,t,r,o,s,l,d].forEach((u,h)=>{u.onPointerEnter$.subscribeEvent(()=>{u.setCursor(c[h])}),u.onPointerLeave$.subscribeEvent(()=>{u.resetCursor()}),u.onPointerDown$.subscribeEvent(g=>{this._widgetPointerDownEvent(g,c[h])})})}_widgetPointerDownEvent(i,e){const t=this._scene,{offsetX:r,offsetY:o}=i,s=t.getCoordRelativeToViewport(w.Vector2.FromArray([r,o])),{x:l,y:d}=s;this._startOffsetX=r,this._startOffsetY=o;const{startRow:c,startColumn:u,endRow:h,endColumn:g}=this._control.model,S=Math.min(c,h),f=Math.min(u,g),p=Math.max(c,h),v=Math.max(u,g);this._relativeSelectionPositionRow=S,this._relativeSelectionPositionColumn=f,this._relativeSelectionRowLength=p-S,this._relativeSelectionColumnLength=v-f,e===w.CURSOR_TYPE.NORTH_WEST_RESIZE?(this._relativeSelectionPositionRow=p,this._relativeSelectionPositionColumn=v):e===w.CURSOR_TYPE.NORTH_RESIZE?this._relativeSelectionPositionRow=p:e===w.CURSOR_TYPE.NORTH_EAST_RESIZE?this._relativeSelectionPositionRow=p:e===w.CURSOR_TYPE.WEST_RESIZE?this._relativeSelectionPositionColumn=v:e===w.CURSOR_TYPE.SOUTH_WEST_RESIZE?this._relativeSelectionPositionColumn=v:e===w.CURSOR_TYPE.SOUTH_RESIZE&&(this._relativeSelectionPositionRow=S);const C=w.ScrollTimer.create(t),I=t.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);C.startScroll(l,d,I),this._scrollTimer=C,t.disableObjectsEvent(),this._scenePointerMoveSub=t.onPointerMove$.subscribeEvent(b=>{const{offsetX:T,offsetY:M}=b,{x:y,y:P}=t.getCoordRelativeToViewport(w.Vector2.FromArray([T,M]));this._widgetMoving(y,P,e),t.setCursor(e),C.scrolling(y,P,()=>{this._widgetMoving(y,P,e)})}),this._scenePointerUpSub=t.onPointerUp$.subscribeEvent(()=>{var T,M,y;const b=this._scene;b.resetCursor(),this._clearObserverEvent(),b.enableObjectsEvent(),(T=this._scrollTimer)==null||T.dispose(),this._control.selectionScaled$.next(this._targetSelection),(y=(M=this._selectionHooks).selectionMoveEnd)==null||y.call(M)})}_widgetMoving(i,e,t){const r=this._scene,o=r.getScrollXYInfoByViewport(w.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:s,scaleY:l}=r.getAncestorScale(),d=this._skeleton.getCellIndexByOffset(i,e,s,l,o),{row:c,column:u}=d;let h=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,S=c,f=u;t===w.CURSOR_TYPE.NORTH_WEST_RESIZE?(h=c,g=u,S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn):t===w.CURSOR_TYPE.NORTH_RESIZE?(h=c,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength):t===w.CURSOR_TYPE.NORTH_EAST_RESIZE?(h=c,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,f=u):t===w.CURSOR_TYPE.WEST_RESIZE?(h=this._relativeSelectionPositionRow,g=u,S=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,f=this._relativeSelectionPositionColumn):t===w.CURSOR_TYPE.EAST_RESIZE?S=this._relativeSelectionPositionRow+this._relativeSelectionRowLength:t===w.CURSOR_TYPE.SOUTH_WEST_RESIZE?(h=this._relativeSelectionPositionRow,g=u,S=c,f=this._relativeSelectionPositionColumn):t===w.CURSOR_TYPE.SOUTH_RESIZE&&(h=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,S=c,f=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength);const p=this._swapPositions(h,g,S,f),v=this._skeleton.getCellWithMergeInfoByIndex(h,g),I=Me({range:p,primary:v,style:null},this._skeleton);this._targetSelection={...I.rangeWithCoord},this._control.updateRangeBySelectionWithCoord(I),this._control.selectionScaling$.next(this._targetSelection)}_initialAutoFill(){const{fillControl:i}=this._control;i.onPointerEnter$.subscribeEvent(e=>{this._injector.get(ve).interceptor.fetchThroughInterceptors(Do)(!1,{x:e.offsetX,y:e.offsetY,skeleton:this._skeleton,scene:this._scene})&&i.setCursor(w.CURSOR_TYPE.CROSSHAIR)}),i.onPointerLeave$.subscribeEvent(()=>{i.resetCursor()}),i.onPointerDown$.subscribeEvent(this._autoFillForPointerdown.bind(this))}_autoFillMoving(i,e){var N,D,H;const t=this._scene,r=t.getViewportScrollXY(this._activeViewport),{scaleX:o,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(i,e,o,s,r),{row:d,column:c}=l,u=t.getCoordRelativeToViewport(w.Vector2.FromArray([i,e])),h=this._skeleton.getRowCount()-1,g=this._skeleton.getColumnCount()-1;let S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn,p=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,v=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength,C=!1,I=!0;if((c<f||c>v)&&d>=S&&d<=p){const W=this._fillRuler(c,f,v,this._relativeSelectionColumnLength,g);f=W.startRowOrColumn,v=W.endRowOrColumn,C=W.isLighten,I=!1}else if((d<S||d>p)&&c>=f&&c<=v){const W=this._fillRuler(d,S,p,this._relativeSelectionRowLength,h);S=W.startRowOrColumn,p=W.endRowOrColumn,C=W.isLighten}else if(Math.abs(this._startOffsetX-u.x-r.x)/2>Math.abs(this._startOffsetY-u.y-r.y)){const W=this._fillRuler(c,f,v,this._relativeSelectionColumnLength,g);f=W.startRowOrColumn,v=W.endRowOrColumn,C=W.isLighten,I=!1}else{const W=this._fillRuler(d,S,p,this._relativeSelectionRowLength,h);S=W.startRowOrColumn,p=W.endRowOrColumn,C=W.isLighten}const b=this._skeleton.getNoMergeCellPositionByIndex(S,f),T=this._skeleton.getNoMergeCellPositionByIndex(p,v),M=(b==null?void 0:b.startY)||0,y=(T==null?void 0:T.endY)||0,P=(b==null?void 0:b.startX)||0,x=(T==null?void 0:T.endX)||0;C?this._controlHandler((W,k)=>{const U=new a.ColorKit(this._fillControlColors[k]).lighten(vd).toRgbString();W.setProps({fill:U})}):this._controlHandler((W,k)=>{W.setProps({fill:this._fillControlColors[k]})});const A=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();S===p&&I===!0||f===v&&I===!1?(N=this._helperSelection)==null||N.hide():((D=this._helperSelection)==null||D.transformByState({left:P-A/2,top:M-A/2,width:x-P,height:y-M}),(H=this._helperSelection)==null||H.show()),this._targetSelection={startY:M,endY:y,startX:P,endX:x,startRow:S,endRow:p,startColumn:f,endColumn:v},this._control.selectionFilling$.next(this._targetSelection)}_autoFillForPointerdown(i){const{offsetX:e,offsetY:t}=i,r=this._scene,o=r.getCoordRelativeToViewport(w.Vector2.FromArray([e,t])),{x:s,y:l}=o;this._startOffsetX=s,this._startOffsetY=l;const{startRow:d,startColumn:c,endRow:u,endColumn:h}=this._control.model;this._isInMergeState=this._hasMergeInRange(d,c,u,h),this._relativeSelectionPositionRow=d,this._relativeSelectionPositionColumn=c,this._relativeSelectionRowLength=u-d,this._relativeSelectionColumnLength=h-c;const g=this._control.currentStyle;let S=g==null?void 0:g.stroke,f=g==null?void 0:g.strokeWidth;const p=Rt(this._themeService);S==null&&(S=p.stroke),f==null&&(f=p.strokeWidth);const v=this._getScale();f/=v;const C=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/v,I=new a.ColorKit(S).darken(2).toRgbString();this.isHelperSelection&&(this._helperSelection=new w.Rect(Ls,{stroke:I,strokeWidth:f+C/2}),r.addObject(this._helperSelection)),this._activeViewport=r.getActiveViewportByCoord(w.Vector2.FromArray([e,t]));const b=r.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN),T=w.ScrollTimer.create(r,this._activeViewport.viewportKey===w.SHEET_VIEWPORT_KEY.VIEW_MAIN?w.ScrollTimerType.ALL:w.ScrollTimerType.NONE);T.startScroll(s,l,b),this._scrollTimer=T,r.disableObjectsEvent(),this._controlHandler(M=>{this._fillControlColors.push(M.fill)}),this._scenePointerMoveSub=r.onPointerMove$.subscribeEvent(M=>{var W;const{offsetX:y,offsetY:P}=M,x=r.getActiveViewportByCoord(w.Vector2.FromArray([y,P]));if(!this._injector.get(ve).interceptor.fetchThroughInterceptors(Do)(!1,{x:i.offsetX,y:i.offsetY,skeleton:this._skeleton,scene:this._scene}))return;const{x:N,y:D}=r.getCoordRelativeToViewport(w.Vector2.FromArray([y,P]));this._autoFillMoving(N,D),r.setCursor(w.CURSOR_TYPE.CROSSHAIR);const H=this._targetSelection;if(b&&x&&((W=this._activeViewport)==null?void 0:W.viewportKey)!==(x==null?void 0:x.viewportKey)){let k;H.startRow!==d?(T.scrollTimerType=w.ScrollTimerType.Y,k={...H,endRow:H.startRow}):H.endRow!==u?(T.scrollTimerType=w.ScrollTimerType.Y,k={...H,startRow:H.endRow}):H.startColumn!==c?(T.scrollTimerType=w.ScrollTimerType.X,k={...H,endColumn:H.startColumn}):(T.scrollTimerType=w.ScrollTimerType.X,k={...H,startColumn:H.endColumn}),this._isSelectionInViewport(k,x)&&(b.scrollToBarPos({x:T.scrollTimerType===w.ScrollTimerType.X?0:void 0,y:T.scrollTimerType===w.ScrollTimerType.Y?0:void 0}),this._activeViewport=x)}T.scrolling(N,D,()=>{this._autoFillMoving(N,D)})}),this._scenePointerUpSub=r.onPointerUp$.subscribeEvent(()=>{var y,P;(y=this._helperSelection)==null||y.dispose();const M=this._scene;M.resetCursor(),this._clearObserverEvent(),M.enableObjectsEvent(),(P=this._scrollTimer)==null||P.dispose(),this._control.refreshSelectionFilled(this._targetSelection),this._isInMergeState=!1,this._controlHandler((x,A)=>{x.setProps({fill:this._fillControlColors[A]})}),this._fillControlColors=[]})}_hasMergeInRange(i,e,t,r){return this._skeleton.worksheet.getMergedCellRange(i,e,t,r).length>0}_swapPositions(i,e,t,r){const o=Math.min(i,t),s=Math.min(e,r),l=Math.max(i,t),d=Math.max(e,r);return{startRow:o,startColumn:s,endRow:l,endColumn:d}}_controlHandler(i){const{leftControl:e,rightControl:t,topControl:r,bottomControl:o,backgroundControlTop:s,backgroundControlMiddleLeft:l,backgroundControlMiddleRight:d,backgroundControlBottom:c,fillControl:u}=this._control,h=[e,t,r,o,s,l,d,c,u];for(let g=0,S=h.length;g<S;g++){const f=h[g];i(f,g)}}_fillRuler(i,e,t,r,o){let s=!1;if(i<e)if(this._isInMergeState&&i<e){const l=e-i,d=r+1,c=Math.ceil(l/d);let u=e-c*d;u<0&&(u=e-(c-1)*d),e=u}else e=i;else if(i>=e&&i<=t)s=!0,this._isInMergeState||(t=i);else if(this._isInMergeState&&i>t){const l=i-t,d=r+1,c=Math.ceil(l/d);let u=t+c*d;u>o&&(u=t+(c-1)*d),t=u}else t=i;return{rowOrColumn:i,startRowOrColumn:e,endRowOrColumn:t,isLighten:s}}_getScale(){const{scaleX:i,scaleY:e}=this._scene.getAncestorScale();return Math.max(i,e)}}var Ho=(n=>(n.Selection="__SpreadsheetSelectionShape__",n.top="__SpreadsheetSelectionTopControl__",n.bottom="__SpreadsheetSelectionBottomControl__",n.left="__SpreadsheetSelectionShapeLeftControl__",n.right="__SpreadsheetSelectionShapeRightControl__",n.backgroundTop="__SpreadsheetSelectionBackgroundControlTop__",n.backgroundMiddleLeft="__SpreadsheetSelectionBackgroundControlMiddleLeft__",n.backgroundMiddleRight="__SpreadsheetSelectionBackgroundControlMiddleRight__",n.backgroundBottom="__SpreadsheetSelectionBackgroundControlBottom__",n.fill="__SpreadsheetSelectionFillControl__",n.fillTopLeft="__SpreadsheetSelectionFillControlTopLeft__",n.fillBottomRight="__SpreadsheetSelectionFillControlBottomRight__",n.fillTopLeftInner="__SpreadsheetSelectionFillControlTopLeftInner__",n.fillBottomRightInner="__SpreadsheetSelectionFillControlBottomRightInner__",n.lineMain="__SpreadsheetDragLineMainControl__",n.lineContent="__SpreadsheetDragLineContentControl__",n.line="__SpreadsheetDragLineControl__",n.dash="__SpreadsheetDragDashControl__",n.rowHeaderBackground="__SpreadSheetSelectionRowHeaderBackground__",n.rowHeaderBorder="__SpreadSheetSelectionRowHeaderBorder__",n.rowHeaderGroup="__SpreadSheetSelectionRowHeaderGroup__",n.columnHeaderBackground="__SpreadSheetSelectionColumnHeaderBackground__",n.columnHeaderBorder="__SpreadSheetSelectionColumnHeaderBorder__",n.columnHeaderGroup="__SpreadSheetSelectionColumnHeaderGroup__",n.topLeftWidget="__SpreadSheetSelectionTopLeftWidget__",n.topCenterWidget="__SpreadSheetSelectionTopCenterWidget__",n.topRightWidget="__SpreadSheetSelectionTopRightWidget__",n.middleLeftWidget="__SpreadSheetSelectionMiddleLeftWidget__",n.middleRightWidget="__SpreadSheetSelectionMiddleRightWidget__",n.bottomLeftWidget="__SpreadSheetSelectionBottomLeftWidget__",n.bottomCenterWidget="__SpreadSheetSelectionBottomCenterWidget__",n.bottomRightWidget="__SpreadSheetSelectionBottomRightWidget__",n))(Ho||{});const Bs=.3;class lr extends a.Disposable{constructor(e,t,r,o){var s,l,d,c;super();R(this,"_isHelperSelection",!0);R(this,"_enableAutoFill",!0);R(this,"_showAutoFill",!1);R(this,"_highlightHeader",!0);R(this,"_selectionRenderModel");R(this,"_leftBorder");R(this,"_rightBorder");R(this,"_topBorder");R(this,"_bottomBorder");R(this,"_backgroundControlTop");R(this,"_backgroundControlBottom");R(this,"_backgroundControlMiddleLeft");R(this,"_backgroundControlMiddleRight");R(this,"_autoFillControl");R(this,"_selectionShapeGroup");R(this,"_rowHeaderBackground");R(this,"_rowHeaderBorder");R(this,"_rowHeaderGroup");R(this,"_columnHeaderBackground");R(this,"_columnHeaderBorder");R(this,"_columnHeaderGroup");R(this,"_dashedRect");R(this,"_topLeftWidget");R(this,"_topCenterWidget");R(this,"_topRightWidget");R(this,"_middleLeftWidget");R(this,"_middleRightWidget");R(this,"_bottomLeftWidget");R(this,"_bottomCenterWidget");R(this,"_bottomRightWidget");R(this,"_defaultStyle");R(this,"_currentStyle");R(this,"_rowHeaderWidth",0);R(this,"_columnHeaderHeight",0);R(this,"_widgetRects",[]);R(this,"_controlExtension");R(this,"_dispose$",new O.BehaviorSubject(this));R(this,"dispose$",this._dispose$.asObservable());R(this,"selectionMoving$",new O.Subject);R(this,"selectionMoveEnd$",new O.Subject);R(this,"selectionScaling$",new O.Subject);R(this,"selectionScaled$",new O.Subject);R(this,"selectionFilling$",new O.Subject);R(this,"_selectionFilled$",new O.Subject);R(this,"selectionFilled$",this._selectionFilled$.asObservable());R(this,"_antLineOffset",0);R(this,"_antRequestNewFrame",-1);this._scene=e,this._zIndex=t,this._themeService=r,this._enableAutoFill=(s=o==null?void 0:o.enableAutoFill)!=null?s:!0,this._highlightHeader=(l=o==null?void 0:o.highlightHeader)!=null?l:!0,this._rowHeaderWidth=(d=o==null?void 0:o.rowHeaderWidth)!=null?d:0,this._columnHeaderHeight=(c=o==null?void 0:o.columnHeaderHeight)!=null?c:0,this._initializeSheetBody(),this._initialHeader()}_initializeSheetBody(){this._defaultStyle=Rt(this._themeService),this._currentStyle=Rt(this._themeService),this._selectionRenderModel=new pd;const e=this._zIndex;this._leftBorder=new w.Rect("__SpreadsheetSelectionShapeLeftControl__"+e,{zIndex:e}),this._rightBorder=new w.Rect("__SpreadsheetSelectionShapeRightControl__"+e,{zIndex:e}),this._topBorder=new w.Rect("__SpreadsheetSelectionTopControl__"+e,{zIndex:e}),this._bottomBorder=new w.Rect("__SpreadsheetSelectionBottomControl__"+e,{zIndex:e}),this._backgroundControlTop=new w.Rect("__SpreadsheetSelectionBackgroundControlTop__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlBottom=new w.Rect("__SpreadsheetSelectionBackgroundControlBottom__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleLeft=new w.Rect("__SpreadsheetSelectionBackgroundControlMiddleLeft__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleRight=new w.Rect("__SpreadsheetSelectionBackgroundControlMiddleRight__"+e,{zIndex:e-1,evented:!1}),this._autoFillControl=new w.Rect("__SpreadsheetSelectionFillControl__"+e,{zIndex:e+1}),this._autoFillControl.hide(),this._dashedRect=new w.DashedRect("__SpreadsheetDragDashControl__"+e,{zIndex:e+2,evented:!1,stroke:"#fff"});const t=[this._autoFillControl,this._leftBorder,this._rightBorder,this._topBorder,this._bottomBorder,this._backgroundControlTop,this._backgroundControlMiddleLeft,this._backgroundControlMiddleRight,this._backgroundControlBottom,this._dashedRect];this._widgetRects=this._initialWidget(),this._selectionShapeGroup=new w.Group("__SpreadsheetSelectionShape__"+e,...t,...this._widgetRects),this._selectionShapeGroup.hide(),this._selectionShapeGroup.evented=!1,this._selectionShapeGroup.zIndex=e;const r=this.getScene();r.addObject(this._selectionShapeGroup,Qr),this.disposeWithMe(a.toDisposable(r.onTransformChange$.subscribeEvent(o=>{o.type===w.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&(this._updateLayoutOfSelectionControl(this._currentStyle),this._updateControlCoord())})))}_initialHeader(){const e=this._zIndex;this._rowHeaderBackground=new w.Rect("__SpreadSheetSelectionRowHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderBorder=new w.Rect("__SpreadSheetSelectionRowHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderGroup=new w.Group("__SpreadSheetSelectionRowHeaderGroup__"+e,this._rowHeaderBackground,this._rowHeaderBorder),this._rowHeaderGroup.hide(),this._rowHeaderGroup.evented=!1,this._rowHeaderGroup.zIndex=e,this._columnHeaderBackground=new w.Rect("__SpreadSheetSelectionColumnHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderBorder=new w.Rect("__SpreadSheetSelectionColumnHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderGroup=new w.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],fd)}_initialWidget(){const e=this._zIndex;return this._topLeftWidget=new w.Rect("__SpreadSheetSelectionTopLeftWidget__"+e,{zIndex:e+1}),this._topCenterWidget=new w.Rect("__SpreadSheetSelectionTopCenterWidget__"+e,{zIndex:e+1}),this._topRightWidget=new w.Rect("__SpreadSheetSelectionTopRightWidget__"+e,{zIndex:e+1}),this._middleLeftWidget=new w.Rect("__SpreadSheetSelectionMiddleLeftWidget__"+e,{zIndex:e+1}),this._middleRightWidget=new w.Rect("__SpreadSheetSelectionMiddleRightWidget__"+e,{zIndex:e+1}),this._bottomLeftWidget=new w.Rect("__SpreadSheetSelectionBottomLeftWidget__"+e,{zIndex:e+1}),this._bottomCenterWidget=new w.Rect("__SpreadSheetSelectionBottomCenterWidget__"+e,{zIndex:e+1}),this._bottomRightWidget=new w.Rect("__SpreadSheetSelectionBottomRightWidget__"+e,{zIndex:e+1}),[this._topLeftWidget,this._topCenterWidget,this._topRightWidget,this._middleLeftWidget,this._middleRightWidget,this._bottomLeftWidget,this._bottomCenterWidget,this._bottomRightWidget]}get zIndex(){return this._zIndex}get leftControl(){return this._leftBorder}get rightControl(){return this._rightBorder}get topControl(){return this._topBorder}get bottomControl(){return this._bottomBorder}get fillControl(){return this._autoFillControl}get backgroundControlTop(){return this._backgroundControlTop}get backgroundControlBottom(){return this._backgroundControlBottom}get backgroundControlMiddleLeft(){return this._backgroundControlMiddleLeft}get backgroundControlMiddleRight(){return this._backgroundControlMiddleRight}get selectionShape(){return this._selectionShapeGroup}get columnHeaderGroup(){return this._columnHeaderGroup}get rowHeaderGroup(){return this._rowHeaderGroup}get selectionShapeGroup(){return this._selectionShapeGroup}get model(){return this._selectionRenderModel}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 themeService(){return this._themeService}get selectionModel(){return this._selectionRenderModel}set selectionModel(e){this._selectionRenderModel=e}get currentStyle(){return this._currentStyle}set currentStyle(e){this._currentStyle=e}get dashedRect(){return this._dashedRect}get isHelperSelection(){return this._isHelperSelection}get rowHeaderWidth(){return this._rowHeaderWidth}set rowHeaderWidth(e){this._rowHeaderWidth=e}get columnHeaderHeight(){return this._columnHeaderHeight}set columnHeaderHeight(e){this._columnHeaderHeight=e}setControlExtension(e){this._controlExtension=new Fa(this,e)}setEvent(e){this.leftControl.evented=e,this.rightControl.evented=e,this.topControl.evented=e,this.bottomControl.evented=e}refreshSelectionFilled(e){this._selectionFilled$.next(e)}_updateLayoutOfSelectionControl(e){e&&(this.currentStyle=Object.assign({},this._defaultStyle,e));const t=this.currentStyle,{stroke:r,widgets:o,autofillStroke:s,strokeDash:l,isAnimationDash:d}=t;let c=t.autofillSize,u=t.strokeWidth,h=t.autofillStrokeWidth;const g=this._getScale(),S=(u+m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH)/2/g;u/=g,c/=g,h/=g<1?1:g;const f=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/g,p=w.FIX_ONE_PIXEL_BLUR_OFFSET/g,{startX:v,startY:C,endX:I,endY:b}=this._selectionRenderModel;if(this.leftControl.transformByState({height:b-C,left:-S+p,width:u,strokeWidth:f,top:-f/2+p}),this.leftControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.rightControl.transformByState({height:b-C,left:I-v-S+p,width:u,strokeWidth:f,top:-f/2+p}),this.rightControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.topControl.transformByState({width:I-v+u,top:-S+p,left:-S+p,height:u,strokeWidth:f}),this.topControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.bottomControl.transformByState({width:I-v+u,top:b-C-S+p,height:u,left:-S+p,strokeWidth:f}),this.bottomControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),l==null)this.dashedRect.hide(),this._stopAntLineAnimation();else{const T=t.strokeWidth*2/g;this.dashedRect.transformByState({height:b-C,width:I-v,strokeWidth:T,left:-T/2+p,top:-T/2+p}),this.dashedRect.setProps({strokeDashArray:[0,l/g]}),this._stopAntLineAnimation(),d!==!1&&this._startAntLineAnimation(),this.dashedRect.show()}if(this._showAutoFill=this._showAutoFill&&this._enableAutoFill,this._showAutoFill&&!this._hasWidgets(o)){const T={fill:r,stroke:s,strokeScaleEnabled:!1},M={width:c-h,height:c-h,left:I-v-c/2+h/2-p,top:b-C-c/2+h/2-p,strokeWidth:h};this._autoFillControl.setProps(T),this._autoFillControl.transformByState(M),this._autoFillControl.show()}else this._autoFillControl.hide();this._updateBackgroundControl(t),this._updateHeaderBackground(t),this._updateWidgets(t)}_updateControlCoord(){const{startX:e,startY:t}=this._selectionRenderModel;this.selectionShapeGroup.show(),this.selectionShapeGroup.translate(e,t),this.selectionShapeGroup.makeDirtyNoDebounce(!0)}updateStyle(e){this._updateLayoutOfSelectionControl(e),this._updateControlCoord()}updateRange(e,t){this._selectionRenderModel.setValue(e,t),this._showAutoFill=t!==null,this._updateLayoutOfSelectionControl(),this._updateControlCoord()}updateRangeBySelectionWithCoord(e,t){t&&(this._rowHeaderWidth=t.getWorksheetConfig().rowHeader.width,this._columnHeaderHeight=t.getWorksheetConfig().columnHeader.height),this._selectionRenderModel.setValue(e.rangeWithCoord,e.primaryWithCoord),this._showAutoFill=e.primaryWithCoord!==null,this._updateLayoutOfSelectionControl(e.style),this._updateControlCoord()}update(e,t=0,r=0,o,s){this._rowHeaderWidth=t,this._columnHeaderHeight=r,this.updateRangeBySelectionWithCoord({rangeWithCoord:e,primaryWithCoord:s,style:o}),o&&this.updateStyle(o)}updateCurrCell(e){this._showAutoFill=e!==null,this._selectionRenderModel.setCurrentCell(e)}clearHighlight(){this._showAutoFill=!1,this._selectionRenderModel.clearCurrentCell(),this._updateLayoutOfSelectionControl(this._currentStyle)}getScene(){return this._scene}dispose(){var e,t,r,o,s,l,d,c,u,h,g,S,f,p,v,C,I,b,T,M,y,P,x,A,N;(e=this._leftBorder)==null||e.dispose(),(t=this._rightBorder)==null||t.dispose(),(r=this._topBorder)==null||r.dispose(),(o=this._bottomBorder)==null||o.dispose(),(s=this._backgroundControlTop)==null||s.dispose(),(l=this._backgroundControlMiddleLeft)==null||l.dispose(),(d=this._backgroundControlMiddleRight)==null||d.dispose(),(c=this._backgroundControlBottom)==null||c.dispose(),this._autoFillControl.dispose(),(u=this._selectionShapeGroup)==null||u.dispose(),(h=this._rowHeaderBackground)==null||h.dispose(),(g=this._rowHeaderBorder)==null||g.dispose(),(S=this._rowHeaderGroup)==null||S.dispose(),(f=this._rowHeaderBackground)==null||f.dispose(),(p=this._columnHeaderBackground)==null||p.dispose(),(v=this._columnHeaderBorder)==null||v.dispose(),(C=this._columnHeaderGroup)==null||C.dispose(),(I=this._topLeftWidget)==null||I.dispose(),(b=this._topCenterWidget)==null||b.dispose(),(T=this._topRightWidget)==null||T.dispose(),(M=this._middleLeftWidget)==null||M.dispose(),(y=this._middleRightWidget)==null||y.dispose(),(P=this._bottomLeftWidget)==null||P.dispose(),(x=this._bottomCenterWidget)==null||x.dispose(),(A=this._bottomRightWidget)==null||A.dispose(),(N=this._controlExtension)==null||N.dispose(),super.dispose(),this._dispose$.next(this),this._dispose$.complete()}getCurrentCellInfo(){const e=this.model.currentCell;if(e){let t;if(e.isMerged){const r=e.mergeInfo;t={startRow:r.startRow,endRow:r.endRow,startColumn:r.startColumn,endColumn:r.endColumn,startX:r.startX,endX:r.endX,startY:r.startY,endY:r.endY}}else{const{actualRow:r,actualColumn:o,startX:s,endX:l,startY:d,endY:c}=e;t={startRow:r,endRow:r,startColumn:o,endColumn:o,startX:s,endX:l,startY:d,endY:c}}return t}}getValue(){return{...this._selectionRenderModel.getValue(),style:this._currentStyle}}getRange(){return this._selectionRenderModel.getValue().rangeWithCoord}enableHelperSelection(){this._isHelperSelection=!0}disableHelperSelection(){this._isHelperSelection=!1}_updateHeaderBackground(e){const{startX:t,startY:r,endX:o,endY:s,rangeType:l}=this._selectionRenderModel,d=this._currentStyle,c=this._getScale(),{stroke:u,rowHeaderFill:h=d.rowHeaderFill,rowHeaderStroke:g=d.rowHeaderStroke,columnHeaderFill:S=d.columnHeaderFill,columnHeaderStroke:f=d.columnHeaderStroke}=e;let{rowHeaderStrokeWidth:p=d.rowHeaderStrokeWidth,columnHeaderStrokeWidth:v=d.columnHeaderStrokeWidth}=e;p/=c,v/=c;const C=this._rowHeaderWidth,I=this._columnHeaderHeight;if(this._highlightHeader&&I>0){let b=S;l===a.RANGE_TYPE.COLUMN&&(b=new a.ColorKit(u).setAlpha(Bs).toString()),this._columnHeaderBackground.setProps({fill:b}),this._columnHeaderBackground.resize(o-t,I),this._columnHeaderBorder.setProps({fill:f}),this._columnHeaderBorder.transformByState({width:o-t,height:v,top:I-v+1/c}),this._columnHeaderGroup.show(),this._columnHeaderGroup.translate(t,0)}else this._columnHeaderGroup.hide();if(this._columnHeaderGroup.makeDirty(!0),this._highlightHeader&&C>0){let b=h;l===a.RANGE_TYPE.ROW&&(b=new a.ColorKit(u).setAlpha(Bs).toString()),this._rowHeaderBackground.setProps({fill:b}),this._rowHeaderBackground.resize(C,s-r),this._rowHeaderBorder.setProps({fill:g}),this._rowHeaderBorder.transformByState({width:p,height:s-r,left:C-p+1/c}),this._rowHeaderGroup.show(),this._rowHeaderGroup.translate(0,r)}else this._rowHeaderGroup.hide();this._rowHeaderGroup.makeDirty(!0)}_updateBackgroundControl(e){const{startX:t,startY:r,endX:o,endY:s}=this._selectionRenderModel,l=this._getScale(),{fill:d=e.fill}=e;let{strokeWidth:c}=e;c/=l;const u=this._selectionRenderModel.highlightToSelection();if(!u){this._backgroundControlTop.resize(o-t,s-r),this._backgroundControlTop.setProps({fill:d}),this._backgroundControlBottom.resize(0,0),this._backgroundControlMiddleLeft.resize(0,0),this._backgroundControlMiddleRight.resize(0,0);return}const{startX:h,startY:g,endX:S,endY:f}=u,p=c/2,v={left:-p,top:-p,width:o-t+p*2,height:g-r+p};v.height<0&&(v.width=0,v.height=0),this._backgroundControlTop.transformByState(v);const C={left:-p,top:g-r,width:h-t+p,height:f-g};C.width<0&&(C.width=0,C.height=0),this._backgroundControlMiddleLeft.transformByState(C);const I={left:S-t-p,top:g-r,width:o-S+p*2,height:f-g};I.width<0&&(I.width=0,I.height=0),this._backgroundControlMiddleRight.transformByState(I);const b={left:-p,top:f-r,width:o-t+p*2,height:s-f+p};b.height<0&&(b.width=0,b.height=0),this._backgroundControlBottom.transformByState(b),this._backgroundControlTop.setProps({fill:d}),this._backgroundControlMiddleLeft.setProps({fill:d}),this._backgroundControlMiddleRight.setProps({fill:d}),this._backgroundControlBottom.setProps({fill:d})}_updateWidgets(e){const{startX:t,startY:r,endX:o,endY:s}=this._selectionRenderModel,{stroke:l=e.stroke,widgets:d=e.widgets,widgetStroke:c=e.widgetStroke}=e,u=this._getScale();let{widgetSize:h,widgetStrokeWidth:g}=e;h/=u,g/=u;const S={left:-h/2+g/2,center:(o-t)/2-h/2+g/2,right:o-t-h/2+g/2,top:-h/2,middle:(s-r)/2-h/2,bottom:s-r-h/2+g/2},f=h-g;this._widgetRects.forEach(p=>{p.setProps({fill:l,stroke:c})}),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 t=Object.keys(e);if(t.length===0)return!1;for(const r of t)if(e[r]===!0)return!0;return!1}_getScale(){const{scaleX:e,scaleY:t}=this._scene.getAncestorScale();return Math.max(e,t)}_stopAntLineAnimation(){this._antLineOffset=0,w.cancelRequestFrame(this._antRequestNewFrame)}_startAntLineAnimation(){const e=this._getScale();this._antLineOffset+=.6/e,this._antLineOffset>160/e&&(this._antLineOffset=0),this.dashedRect.setProps({strokeDashOffset:-this._antLineOffset}),this._antRequestNewFrame=w.requestNewFrame(()=>{this._startAntLineAnimation()})}}class Cd extends w.Layer{render(i,e=!1){const t=a.Tools.now();return super.render(i,e),this._afterRender(t),this}_afterRender(i){this.scene.getEngine().renderFrameTimeMetric$.next(["selectionLayer",a.Tools.now()-i])}}const ve=a.createIdentifier("univer.sheet.selection-render-service");class ls extends a.Disposable{constructor(e,t,r,o,s){super();R(this,"_downObserver");R(this,"_scenePointerMoveSub");R(this,"_scenePointerUpSub");R(this,"_controlFillConfig$",new O.BehaviorSubject(null));R(this,"controlFillConfig$",this._controlFillConfig$.asObservable());R(this,"_selectionControls",[]);R(this,"_startRangeWhenPointerDown",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});R(this,"_activeControlIndex",-1);R(this,"_startViewportPosX",0);R(this,"_startViewportPosY",0);R(this,"_scrollTimer");R(this,"_cancelDownSubscription");R(this,"_cancelUpSubscription");R(this,"_skeleton");R(this,"_scene");R(this,"_highlightHeader",!0);R(this,"_rangeType",a.RANGE_TYPE.NORMAL);R(this,"_selectionStyle");R(this,"_remainLastEnabled",!1);R(this,"_skipLastEnabled",!1);R(this,"_singleSelectionEnabled",!1);R(this,"_selectionMoveEnd$",new O.BehaviorSubject([]));R(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());R(this,"_selectionMoving$",new O.Subject);R(this,"selectionMoving$",this._selectionMoving$.asObservable());R(this,"_selectionMoveStart$",new O.Subject);R(this,"selectionMoveStart$",this._selectionMoveStart$.asObservable());R(this,"_selectionMoving",!1);R(this,"_selectionTheme");R(this,"_activeViewport");R(this,"interceptor",new a.InterceptorManager({RANGE_MOVE_PERMISSION_CHECK:No,RANGE_FILL_PERMISSION_CHECK:Do}));R(this,"_escapeShortcutDisposable",null);this._injector=e,this._themeService=t,this._shortcutService=r,this._sheetSkeletonManagerService=o,this.contextService=s,this._initSelectionThemeFromThemeService(),this._initMoving()}get selectionMoving(){return this._selectionMoving}get _shouldDetectMergedCells(){return this._rangeType===a.RANGE_TYPE.NORMAL}_initMoving(){this.disposeWithMe(this._selectionMoving$.subscribe(()=>{this._selectionMoving=!0})),this.disposeWithMe(this._selectionMoveEnd$.subscribe(()=>{this._selectionMoving=!1}))}_setSelectionStyle(e){this._selectionStyle=e}getViewPort(){return this._activeViewport}setSingleSelectionEnabled(e=!1){this._singleSelectionEnabled=e}newSelectionControl(e,t,r){const o=this.getSelectionControls().length,{rowHeaderWidth:s,columnHeaderHeight:l}=t,d=new lr(e,o,this._selectionTheme,{highlightHeader:this._highlightHeader,rowHeaderWidth:s,columnHeaderHeight:l});this._selectionControls.push(d);const c=Me(r,t);return d.updateRangeBySelectionWithCoord(c,t),d.setControlExtension({skeleton:t,scene:e,themeService:this._selectionTheme,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),d}resetSelectionsByModelData(e){const t=this.getSelectionControls(),r=this._skeleton;if(!(!t||!r)){for(let o=0,s=e.length;o<s;o++){const l=e[o],d=Me(l,this._skeleton),c=t[o];c?c.updateRangeBySelectionWithCoord(d,r):this.isSelectionEnabled()&&this.newSelectionControl(this._scene,r,l)}e.length<t.length&&t.splice(e.length).forEach(s=>s.dispose())}}refreshSelectionMoveStart(){this._selectionMoveStart$.next(this.getSelectionDataWithStyle())}refreshSelectionMoveEnd(){this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}_initSelectionThemeFromThemeService(){const e=this._themeService.getCurrentTheme();this._selectionTheme=new a.ThemeService,this._selectionTheme.setTheme(e)}setSelectionTheme(e){this._selectionTheme.setTheme(e)}_changeRuntime(e,t,r){this._skeleton=e,this._scene=t,this._activeViewport=r||(t==null?void 0:t.getViewports()[0]),t.findLayerByZIndex(Qr)||t.addLayer(new Cd(t,[],Qr))}getSkeleton(){return this._skeleton}getSelectionDataWithStyle(){const e=this._selectionControls,[t,r]=this._skeleton.getLocation();return e.map(o=>{const s=o.getValue();return s.rangeWithCoord.sheetId=r,s.rangeWithCoord.unitId=t,s})}getSelectionControls(){return this._selectionControls}_addSelectionControlByModelData(e){var l;const t=this._skeleton,r=(l=e.style)!=null?l:Rt(this._selectionTheme),o=this._scene;return e.style=r,this.newSelectionControl(o,t,e)}_clearAllSelectionControls(){const e=this._selectionControls;for(const t of e)t.dispose();this._selectionControls.length=0}_getFreeze(){var t;return(t=this._sheetSkeletonManagerService.getCurrent())==null?void 0:t.skeleton.getWorksheetConfig().freeze}_getViewportByCell(e,t){if(e===void 0||t===void 0)return null;const r=this._getFreeze();if(!r||r.startRow<=0&&r.startColumn<=0)return this._scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e>r.startRow&&t>r.startColumn)return this._scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e<=r.startRow&&t<=r.startColumn)return this._scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP);if(e<=r.startRow&&t>r.startColumn)return this._scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(e>r.startRow&&t<=r.startColumn)return this._scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)}getActiveRange(){const e=this.getSelectionControls(),t=e&&e[e.length-1].model;return t&&{startRow:t.startRow,startColumn:t.startColumn,endRow:t.endRow,endColumn:t.endColumn}}setActiveSelectionIndex(e){this._activeControlIndex=e}resetActiveSelectionIndex(){this._activeControlIndex=-1}getActiveSelectionControl(){const e=this.getSelectionControls();if(e)return this._activeControlIndex<0?e[e.length-1]:e[this._activeControlIndex]}endSelection(){var e;this._clearUpdatingListeners(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),(e=this._escapeShortcutDisposable)==null||e.dispose(),this._escapeShortcutDisposable=null}_reset(){var e;this._clearAllSelectionControls(),(e=this._downObserver)==null||e.unsubscribe(),this._downObserver=null}_setupPointerMoveListener(e,t,r,o=w.ScrollTimerType.ALL,s,l){var f,p;let d=0,c=0,u=s,h=l;this._scrollTimer=w.ScrollTimer.create(this._scene,o),this._scrollTimer.startScroll((f=e==null?void 0:e.left)!=null?f:0,(p=e==null?void 0:e.top)!=null?p:0,e);const g=this._scene,S=g.getActiveViewportByCoord(w.Vector2.FromArray([s,l]));this._scenePointerMoveSub=g.onPointerMove$.subscribeEvent(v=>{var H,W,k,U,B,F,L,z,X;const{offsetX:C,offsetY:I}=v,{x:b,y:T}=g.getCoordRelativeToViewport(w.Vector2.FromArray([C,I]));this._movingHandler(b,T,t,r);let M=b,y=T;const P=this.getActiveSelectionControl(),x=this._getFreeze(),A=P==null?void 0:P.model,N=(H=g.getActiveViewportByCoord(w.Vector2.FromArray([C,I])))!=null?H:this._getViewportByCell(A==null?void 0:A.endRow,A==null?void 0:A.endColumn);if((()=>{if(!S||!N||!e)return!1;const Z=[w.SHEET_VIEWPORT_KEY.VIEW_MAIN,w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,w.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT];return Z.includes(S.viewportKey)&&Z.includes(N.viewportKey)})()){if(!S||!N||!e)return!1;const Z=u<e.left&&b>e.left||u>e.left&&b<e.left,re=h<e.top&&T>e.top||h>e.top&&T<e.top;Z&&(d+=1),re&&(c+=1);const Q=S.viewportKey,oe=N.viewportKey;if(Q===w.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP)I<e.top&&((W=A==null?void 0:A.endRow)!=null?W:0)<((k=x==null?void 0:x.startRow)!=null?k:0)?y=e.top:re&&c%2===1&&e.scrollToViewportPos({viewportScrollY:0});else if(Q===w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT)C<e.left&&((U=A==null?void 0:A.endColumn)!=null?U:0)<((B=x==null?void 0:x.startColumn)!=null?B:0)?M=e.left:Z&&d%2===1&&e.scrollToViewportPos({viewportScrollX:0});else if(Q===oe){let $=!1,j=!1;Q===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP?($=!0,j=!0):Q===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP?j=!0:Q===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT&&($=!0),((F=A==null?void 0:A.endRow)!=null?F:0)>((L=x==null?void 0:x.startRow)!=null?L:0)&&(j=!1),((z=A==null?void 0:A.endColumn)!=null?z:0)>((X=x==null?void 0:x.startColumn)!=null?X:0)&&($=!1),$&&(M=e.left),j&&(y=e.top)}else{const $={x:S.scrollX,y:S.scrollY},j={x:N.scrollX,y:N.scrollY},Y=$.x!==j.x&&Z&&d%2===1,q=$.y!==j.y&&re&&c%2===1;(Y||q)&&(e.scrollToBarPos({x:Y?$.x:void 0,y:q?$.y:void 0}),Y||(M=e.left),q||(y=e.top)),(Q===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&oe===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||oe===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&Q===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)&&(M=e.left),(Q===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&oe===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||oe===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&Q===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP)&&(y=e.top)}u=b,h=T}this._scrollTimer.scrolling(M,y,()=>{this._movingHandler(b,T,t,r)})})}attachSelectionWithCoord(e){return Me(e,this._skeleton)}attachPrimaryWithCoord(e){return Qn(this._skeleton,e)}getSelectionCellByPosition(e,t){return this.getCellWithCoordByOffset(e,t)}getCellWithCoordByOffset(e,t,r){const o=this._scene,s=r!=null?r:this._skeleton,l=o.getViewportScrollXY(o.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:d,scaleY:c}=o.getAncestorScale();return s.getCellWithCoordByOffset(e,t,d,c,l)}_movingHandler(e,t,r,o){var M,y,P,x,A;const s=this._skeleton,l=this._scene,[d,c]=s.getLocation(),u={startRow:(M=r==null?void 0:r.model.startRow)!=null?M:-1,endRow:(y=r==null?void 0:r.model.endRow)!=null?y:-1,startColumn:(P=r==null?void 0:r.model.startColumn)!=null?P:-1,endColumn:(x=r==null?void 0:r.model.endColumn)!=null?x:-1,unitId:d,sheetId:c},h=l.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=(A=this._getViewportByCell(u.endRow,u.endColumn))!=null?A:h,S=l.getScrollXYInfoByViewport(w.Vector2.FromArray([this._startViewportPosX,this._startViewportPosY]),g),{scaleX:f,scaleY:p}=l.getAncestorScale();o===a.RANGE_TYPE.ROW?e=Number.POSITIVE_INFINITY:o===a.RANGE_TYPE.COLUMN&&(t=Number.POSITIVE_INFINITY);const v=this._skeleton.getCellByOffset(e,t,f,p,S);if(!v)return;let C={startRow:Math.min(v.startRow,this._startRangeWhenPointerDown.startRow),startColumn:Math.min(v.startColumn,this._startRangeWhenPointerDown.startColumn),endRow:Math.max(v.endRow,this._startRangeWhenPointerDown.endRow),endColumn:Math.max(v.endColumn,this._startRangeWhenPointerDown.endColumn)};this._shouldDetectMergedCells&&(C=s.expandRangeByMerge(C));const b=Me({range:C,primary:void 0,style:null},s);b.rangeWithCoord.unitId=d,b.rangeWithCoord.sheetId=c,b.rangeWithCoord.rangeType=o;const T=u.startRow!==C.startRow||u.startColumn!==C.startColumn||u.endRow!==C.endRow||u.endColumn!==C.endColumn;r!=null&&T&&(r.updateRangeBySelectionWithCoord(b),this._selectionMoving$.next(this.getSelectionDataWithStyle()))}_clearUpdatingListeners(){var t,r,o,s,l;this._scene.enableObjectsEvent(),(t=this._scenePointerMoveSub)==null||t.unsubscribe(),this._scenePointerMoveSub=null,(r=this._scenePointerUpSub)==null||r.unsubscribe(),this._scenePointerUpSub=null,(o=this._cancelDownSubscription)==null||o.unsubscribe(),this._cancelDownSubscription=null,(s=this._cancelUpSubscription)==null||s.unsubscribe(),this._cancelUpSubscription=null,(l=this._scrollTimer)==null||l.dispose()}_addEndingListeners(){var r,o,s;const e=this._scene,t=(r=e.getEngine())==null?void 0:r.activeScene;!t||t===e||((o=this._cancelDownSubscription)==null||o.unsubscribe(),this._cancelDownSubscription=null,(s=this._cancelUpSubscription)==null||s.unsubscribe(),this._cancelUpSubscription=null,this._cancelDownSubscription=t.onPointerDown$.subscribeEvent(()=>this._clearUpdatingListeners()),this._cancelUpSubscription=t.onPointerUp$.subscribeEvent(()=>this._clearUpdatingListeners()))}_getSelectionWithCoordByOffset(e,t,r,o,s){const l=this._skeleton;if(l==null)return null;if(this._shouldDetectMergedCells){const C=l==null?void 0:l.getCellWithCoordByOffset(e,t,r,o,s,{firstMatch:!0});if(!C)return;const I=a.convertCellToRange(C);return{primaryWithCoord:C,rangeWithCoord:I}}const{row:d,column:c}=l.getCellIndexByOffset(e,t,r,o,s),u=l.getNoMergeCellPositionByIndex(d,c),{startX:h,startY:g,endX:S,endY:f}=u,p={startY:g,endY:f,startX:h,endX:S,startRow:d,endRow:d,startColumn:c,endColumn:c};return{primaryWithCoord:{mergeInfo:p,actualRow:d,actualColumn:c,isMerged:!1,isMergedMainCell:!1,startY:g,endY:f,startX:h,endX:S},rangeWithCoord:p}}_checkClearPreviousControls(e){this.getSelectionControls().length!==0&&(!e.ctrlKey&&!e.shiftKey&&!this._remainLastEnabled||this._singleSelectionEnabled&&!e.shiftKey)&&this._clearAllSelectionControls()}_makeSelectionByTwoCells(e,t,r,o,s){const{actualRow:l,actualColumn:d,mergeInfo:c}=e;this._startRangeWhenPointerDown={...e.mergeInfo};const u=Math.min(l,t.startRow,c.startRow),h=Math.max(l,t.endRow,c.endRow),g=Math.min(d,t.startColumn,c.startColumn),S=Math.max(d,t.endColumn,c.endColumn),p={range:r.expandRangeByMerge({startRow:u,startColumn:g,endRow:h,endColumn:S}),primary:null,style:null},v=Me(p,r);s.updateRangeBySelectionWithCoord(v)}isSelectionEnabled(){return this.contextService.getContextValue(m.SELECTIONS_ENABLED)}isSelectionDisabled(){return this.contextService.getContextValue(m.SELECTIONS_ENABLED)===!1}inRefSelectionMode(){return this.contextService.getContextValue(m.REF_SELECTIONS_ENABLED)}}function cs(n){return{range:{startRow:0,startColumn:0,endRow:n.getRowCount()-1,endColumn:n.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL},primary:Mi(n).primary,style:null}}function Mi(n){return ja(n,{startRow:0,startColumn:0,endRow:0,endColumn:0})}function ja(n,i){const e=n.worksheet.getCellInfoInMergeData(i.startRow,i.startColumn),t=n.worksheet.getCellInfoInMergeData(i.endRow,i.endColumn);return{range:{startRow:e.startRow,startColumn:e.startColumn,endRow:t.endRow,endColumn:t.endColumn,rangeType:a.RANGE_TYPE.NORMAL},primary:{actualRow:e.startRow,actualColumn:e.startColumn,startRow:e.startRow,startColumn:e.startColumn,endRow:e.endRow,endColumn:e.endColumn,isMerged:e.isMerged,isMergedMainCell:e.isMergedMainCell},style:null}}var _d=Object.defineProperty,Id=Object.getOwnPropertyDescriptor,bd=(n,i,e,t)=>{for(var r=t>1?void 0:t?Id(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&_d(i,e,r),r},Rd=(n,i)=>(e,t)=>i(e,t,n);exports.SheetSkeletonManagerService=class extends a.Disposable{constructor(e,t){super();R(this,"_currentSkeletonSearchParam",{sheetId:""});R(this,"_sheetSkeletonParam",[]);R(this,"_currentSkeleton$",new O.BehaviorSubject(null));R(this,"currentSkeleton$",this._currentSkeleton$.asObservable());R(this,"_currentSkeletonBefore$",new O.BehaviorSubject(null));R(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._context=e,this._injector=t,this.disposeWithMe(()=>{this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._sheetSkeletonParam=[]}),this._initRemoveSheet()}_initRemoveSheet(){this.disposeWithMe(this._context.unit.sheetDisposed$.subscribe(e=>{this.disposeSkeleton({sheetId:e.getSheetId()})}))}getCurrentSkeleton(){var e;return(e=this.getCurrent())==null?void 0:e.skeleton}getCurrent(){return this._getSkeleton(this._currentSkeletonSearchParam)}getWorksheetSkeleton(e){return this._getSkeleton({sheetId:e})}getUnitSkeleton(e,t){const r=this._getSkeleton({sheetId:t});return r!=null&&(r.unitId=e),r}setCurrent(e){this._setCurrent(e)}_setCurrent(e){const t=this._getSkeleton(e),r=this._context.unitId;if(t!=null)this._reCalculate(t);else{const{sheetId:l}=e,c=this._context.unit.getSheetBySheetId(e.sheetId);if(c==null)return;const u=this._buildSkeleton(c);this._sheetSkeletonParam.push({unitId:r,sheetId:l,skeleton:u,dirty:!1})}this._currentSkeletonSearchParam=e;const o=this._currentSkeletonSearchParam.sheetId,s=this.getUnitSkeleton(r,o);this._currentSkeletonBefore$.next(s),this._currentSkeleton$.next(s)}reCalculate(){const e=this.getCurrent();e!=null&&this._reCalculate(e)}_reCalculate(e){e.dirty&&(e.skeleton.makeDirty(!0),e.dirty=!1),e.skeleton.calculate()}makeDirty(e,t=!0){const r=this._getSkeleton(e);r!=null&&(r.dirty=t)}getOrCreateSkeleton(e){const t=this._getSkeleton(e);if(t)return t.skeleton;const o=this._context.unit.getSheetBySheetId(e.sheetId);if(!o)return;const s=this._buildSkeleton(o);return this._sheetSkeletonParam.push({unitId:this._context.unitId,sheetId:e.sheetId,skeleton:s,dirty:!1}),s}disposeSkeleton(e){const t=this._sheetSkeletonParam.findIndex(r=>r.sheetId===e.sheetId);t>-1&&(this._sheetSkeletonParam[t].skeleton.dispose(),this._sheetSkeletonParam.splice(t,1))}attachRangeWithCoord(e){const t=this.getCurrentSkeleton();return t?In(t,e):null}_getSkeleton(e){const t=this._sheetSkeletonParam.find(r=>r.sheetId===e.sheetId);return t!=null&&(t.commandId=e.commandId),t}_buildSkeleton(e){return this._injector.createInstance(w.SpreadsheetSkeleton,e,this._context.unit.getStyles())}setColumnHeaderSize(e,t,r){var u;if(!e)return;const o=(u=this.getWorksheetSkeleton(t))==null?void 0:u.skeleton;if(!o)return;o.columnHeaderHeight=r,e.scene.getViewports()[0].top=r,e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({height:r}),e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({height:r}),e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({top:r}),e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({top:r}),e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({height:r});const s=e==null?void 0:e.with(m.SheetsSelectionsService),l=e==null?void 0:e.with(ve),d=s.getCurrentSelections();l.resetSelectionsByModelData(d);const c=this.getUnitSkeleton(e.unitId,t);c&&(c.commandId=yi.id,this._currentSkeleton$.next(c))}setRowHeaderSize(e,t,r){var f;const o=(f=this.getWorksheetSkeleton(t))==null?void 0:f.skeleton;if(!e||!o)return;o.rowHeaderWidth=r;const s=e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).width||46,l=r-s,d=e.scene.getViewports()[0].left;e.scene.getViewports()[0].left=d+l,e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({width:r}),e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({width:r}),e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({left:r});const c=e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).left||0;e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({left:c+l}),e.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({width:r});const u=e==null?void 0:e.with(m.SheetsSelectionsService),h=e==null?void 0:e.with(ve),g=u.getCurrentSelections();h.resetSelectionsByModelData(g);const S=this.getCurrent();S&&(S.commandId=wi.id,this._currentSkeleton$.next(S))}};exports.SheetSkeletonManagerService=bd([Rd(1,a.Inject(a.Injector))],exports.SheetSkeletonManagerService);function Je(){const n=a.useDependency(a.IUniverInstanceService),i=E.useObservable(()=>n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]);return i!=null?i:null}function Ed(n){return E.useObservable(()=>{var e;return(e=n==null?void 0:n.activeSheet$)!=null?e:O.of(null)},void 0,void 0,[n])}function Td(){const n=a.useDependency(a.IUniverInstanceService);return E.useObservable(()=>O.merge([n.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET),n.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET)]).pipe(O.map(()=>n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET)),O.startWith(n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET))),[],void 0,[n])}function wd(){const n=a.useDependency(w.IRenderManagerService),i=Je(),{sheetSkeletonManagerService:e}=V.useMemo(()=>{if(i){const t=n.getRenderById(i.getUnitId());return{sheetSkeletonManagerService:t==null?void 0:t.with(exports.SheetSkeletonManagerService)}}return{sheetSkeletonManagerService:null}},[i,n]);return e}const yd="SheetUI";var ds=(n=>(n.FILTER_PANEL_EMBED_POINT="filter-panel-embed-point",n.SHEETS_FOOTER="sheets-footer",n.FORMULA_AUX="formula-aux",n))(ds||{}),Md=Object.defineProperty,Pd=Object.getOwnPropertyDescriptor,Od=(n,i,e,t)=>{for(var r=t>1?void 0:t?Pd(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Md(i,e,r),r},Hr=(n,i)=>(e,t)=>i(e,t,n);const us=["ff","fs","tr","tb"];exports.AutoHeightController=class extends a.Disposable{constructor(i,e,t,r){super(),this._renderManagerService=i,this._sheetInterceptorService=e,this._selectionManagerService=t,this._univerInstanceService=r,this._initialize()}getUndoRedoParamsOfAutoHeight(i){const{_univerInstanceService:e}=this,t=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),r=t.getActiveSheet(),o=t.getUnitId(),s=r.getSheetId(),l=this._renderManagerService.getRenderById(o).with(exports.SheetSkeletonManagerService);if(!s||!l.getCurrent())return{redos:[],undos:[]};const{skeleton:d}=l.getCurrent(),c=d.calculateAutoHeightInRange(i),u={subUnitId:s,unitId:o,rowsAutoHeightInfo:c},h=m.SetWorksheetRowAutoHeightMutationFactory(u,r);return{undos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:h}],redos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:u}]}}_initialize(){const{_sheetInterceptorService:i,_selectionManagerService:e}=this;this.disposeWithMe(i.interceptCommand({getMutations:t=>{if(t.id===m.SetRangeValuesCommand.id){const r=t.params;return this.getUndoRedoParamsOfAutoHeight(r.range)}return{redos:[],undos:[]}}})),this.disposeWithMe(i.interceptCommand({getMutations:t=>t.id!==m.SetWorksheetRowIsAutoHeightCommand.id?{redos:[],undos:[]}:this.getUndoRedoParamsOfAutoHeight(t.params.ranges)})),this.disposeWithMe(i.interceptCommand({getMutations:t=>{var o,s;if(t.id!==m.SetStyleCommand.id)return{redos:[],undos:[]};if(!us.includes((o=t.params)==null?void 0:o.style.type))return{redos:[],undos:[]};const r=(s=e.getCurrentSelections())==null?void 0:s.map(l=>l.range);return r!=null&&r.length?this.getUndoRedoParamsOfAutoHeight(r):{redos:[],undos:[]}}})),this.disposeWithMe(i.interceptAfterCommand({getMutations:t=>{if(t.id===m.MoveRangeCommand.id){const r=t.params;return this.getUndoRedoParamsOfAutoHeight([r.fromRange,r.toRange])}if(t.id===m.ReorderRangeCommand.id){const r=t.params;return this.getUndoRedoParamsOfAutoHeight([r.range])}return{redos:[],undos:[]}}}))}};exports.AutoHeightController=Od([Hr(0,w.IRenderManagerService),Hr(1,a.Inject(m.SheetInterceptorService)),Hr(2,a.Inject(m.SheetsSelectionsService)),Hr(3,a.Inject(a.IUniverInstanceService))],exports.AutoHeightController);function gn(n,i,e,t){const r=i.get(a.IUniverInstanceService),o=e?r.getUnit(e,a.UniverInstanceType.UNIVER_SHEET):r.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=t?o==null?void 0:o.getSheetBySheetId(t):o==null?void 0:o.getActiveSheet();if(!s)return null;const{startRow:l,endRow:d,startColumn:c,endColumn:u}=n,h=[],g=[];for(let S=l;S<=d;S++)s.getRowFiltered(S)||h.push(S);for(let S=c;S<=u;S++)g.push(S);return{rows:h,cols:g}}function Et(n){const{rows:i,cols:e}=n;return{startRow:i[0],endRow:i[i.length-1],startColumn:e[0],endColumn:e[e.length-1]}}function Kt(n){let i=[],e=[];const t=[];return n.forEach(r=>{i=i.concat(r.rows),e=e.concat(r.cols)}),i=Array.from(new Set(i)).sort((r,o)=>r-o),e=Array.from(new Set(e)).sort((r,o)=>r-o),n.forEach(r=>{t.push({startRow:i.findIndex(o=>o===r.rows[0]),endRow:i.findIndex(o=>o===r.rows[r.rows.length-1]),startColumn:e.findIndex(o=>o===r.cols[0]),endColumn:e.findIndex(o=>o===r.cols[r.cols.length-1])})}),{ranges:t,mapFunc:(r,o)=>({row:i[r],col:e[o]})}}function xd(n){const i=new a.ObjectMatrix;return n.forEach(e=>{const{rows:t,cols:r}=e;t.forEach(o=>{r.forEach(s=>{i.setValue(o,s,{v:null,p:null,f:null,si:null,custom:null})})})}),i.getData()}const ko={零:0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9},Jr=["零","一","二","三","四","五","六","七","八","九"],Fs=["","万","亿","万亿","亿亿"],Ad=["","十","百","千"],za={十:{value:10,secUnit:!1},百:{value:100,secUnit:!1},千:{value:1e3,secUnit:!1},万:{value:1e4,secUnit:!0},亿:{value:1e8,secUnit:!0}};function ut(n){if(!n)return 0;let i=0,e=0,t=0,r=!1;const o=n.split("");for(let s=0;s<o.length;s++){const l=ko[o[s]];if(typeof l<"u")t=l,s===o.length-1&&(e+=t);else{const d=za[o[s]],c=d.value;r=d.secUnit,r?(e=(e+t)*c,i+=e,e=0):e+=t*c,t=0}}return i+e}function Nd(n){let i="",e="",t=0,r=!0;for(;n>0;){const o=n%10;o===0?r||(r=!0,e=Jr[o]+e):(r=!1,i=Jr[o],i+=Ad[t],e=i+e),t++,n=Math.floor(n/10)}return e}function Dd(n){let i=0,e="",t="",r=!1;if(n===0)return Jr[0];for(;n>0;){const o=n%1e4;r&&(t=Jr[0]+t),e=Nd(o),e+=o!==0?Fs[i]:Fs[0],t=e+t,r=o<1e3&&o>0,n=Math.floor(n/1e4),i++}return t}function Hd(n){if(!n)return!1;let i=!0;if(n)if(n.length===1)n==="日"||n in ko?i=!0:i=!1;else{const e=n.split("");for(let t=0;t<e.length;t++)if(!(e[t]in ko||e[t]in za)){i=!1;break}}return i}function kr(n){if(!n)return{isExtendNumber:!1};const i=/0|([1-9]+[0-9]*)/g,e=i.test(n);if(e){const t=n.match(i);if(t&&t.length>0){const r=t[t.length-1],o=n.lastIndexOf(r),s=n.substr(0,o),l=n.substr(o+r.length);return{isExtendNumber:!0,matchTxt:Number(r),beforeTxt:s,afterTxt:l}}return{isExtendNumber:!1}}return{isExtendNumber:e}}function kd(n){let i;return n.length===2&&(n==="周一"||n==="周二"||n==="周三"||n==="周四"||n==="周五"||n==="周六"||n==="周日")?i=!0:i=!1,i}function Vd(n){let i;return n.length===3&&(n==="星期一"||n==="星期二"||n==="星期三"||n==="星期四"||n==="星期五"||n==="星期六"||n==="星期日")?i=!0:i=!1,i}function Wd(n,i){let e=0;for(let t=0;t<n.length&&n[t]<i;t++)e++;return e}function cr(n){let i=!0;const e=n[1]-n[0];for(let t=1;t<n.length;t++)if(n[t]-n[t-1]!==e){i=!1;break}return i}function Ud(n,i,e){const t=[],r=Math.floor(i/n),o=i%n;let s=0;if(r>0){for(let l=0;l<r;l++)for(let d=0;d<e.length;d++)t[e[d]+l*n]=s,s++;for(let l=0;l<e.length&&e[l]<o;l++)t[e[l]+n*r]=s,s++}else for(let l=0;l<e.length&&e[l]<o;l++)t[e[l]]=s,s++;return t}function jt(n,i){const e=[];for(let t=1;t<=i;t++){const r=(t-1)%n.length,o=a.Tools.deepClone(n[r]);zt(o),e.push({v:null,s:null,p:null,f:null,si:null,t:null,...o})}return e}function Ld(n,i){var t;const e=[];for(let r=1;r<=i;r++){const o=(r-1)%n.length,s={s:(t=n[o])==null?void 0:t.s};e.push(s)}return e}function Bd(n){let i=!0;const e=n[1]/n[0];for(let t=1;t<n.length;t++)if(n[t]/n[t-1]!==e){i=!1;break}return i}function Fd(n){const i=[];for(let e=1;e<=n;e++)i.push(e);return i}function $r(n,i,e){var o,s,l,d;const t=[],r=[];for(let c=0;c<n.length;c++)r.push(Number((o=n[c])==null?void 0:o.v));if(n.length>2&&Bd(r))for(let c=1;c<=i;c++){const u=(c-1)%n.length,h=a.Tools.deepClone(n[u]);zt(h);const g=Number((s=n[n.length-1])==null?void 0:s.v)*(Number((l=n[1])==null?void 0:l.v)/Number((d=n[0])==null?void 0:d.v))**c;h&&(Ys(h)&&(h.v=g),t.push(h))}else{const c=Fd(n.length);for(let u=1;u<=i;u++){const h=(u-1)%n.length,g=a.Tools.deepClone(n[h]);zt(g);const S=e===a.Direction.DOWN||e===a.Direction.RIGHT,f=jd(n.length+u,r,c,S);g&&(Ys(g)&&(g.v=f),t.push(g))}}return t}function jd(n,i,e,t=!0){function r(h){let g=0;for(let S=0;S<h.length;S++)g+=h[S];return g/h.length}const o=r(e),s=r(i);let l=0,d=0;for(let h=0;h<e.length;h++)l+=(e[h]-o)*(i[h]-s),d+=(e[h]-o)*(e[h]-o);let c;d===0?c=t?1:-1:c=l/d;const u=s-c*o;return Math.round((u+c*n)*1e5)/1e5}function js(n,i,e){var o;const t=[],r=/0|([1-9]+[0-9]*)/g;for(let s=1;s<=i;s++){const l=(s-1)%n.length,d=a.Tools.deepClone(n[l]);zt(d);const c=`${(o=n[n.length-1])==null?void 0:o.v}`,u=c==null?void 0:c.match(r),h=u==null?void 0:u[u.length-1],g=Math.abs(Number(h)+e*s);if(!c||!h)continue;const S=c.lastIndexOf(h),f=c.substr(0,S)+g.toString()+c.substr(S+h.length);d&&(d.v=f,t.push(d))}return t}function bn(n,i,e,t=0){var l,d;const r=[["日","一","二","三","四","五","六"],["周日","周一","周二","周三","周四","周五","周六"],["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]];if(t>=r.length)return[];const o=r[t],s=[];for(let c=1;c<=i;c++){const u=(c-1)%n.length,h=a.Tools.deepClone(n[u]);zt(h);let g=0;if(((l=n[n.length-1])==null?void 0:l.v)===o[0])g=7+e*c;else{const f=`${(d=n[n.length-1])==null?void 0:d.v}`;if(f){const p=f.substr(f.length-1,1);g=ut(p)+e*c}}g<0&&(g=Math.ceil(Math.abs(g)/7)*7+g);const S=g%7;h&&(h.v=o[S],s.push(h))}return s}function zs(n,i,e){var r;const t=[];for(let o=1;o<=i;o++){const s=(o-1)%n.length,l=a.Tools.deepClone(n[s]);zt(l);const d=`${(r=n[n.length-1])==null?void 0:r.v}`,c=ut(d)+e*o;let u;c<=0?u="零":u=Dd(c),l&&(l.v=u,t.push(l))}return t}const Zn={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 zd(n){let i=!1;return Object.keys(Zn).forEach(e=>{Zn[e].includes(n)&&(i=!0)}),i}function Fi(n){let i="";const e=[];return Object.keys(Zn).forEach(t=>{Zn[t].includes(n)&&(i=t,e.push(...Zn[t]))}),{name:i,series:e}}function Xs(n,i,e,t){var s;const r=t.length,o=[];for(let l=1;l<=i;l++){const d=(l-1)%n.length,c=a.Tools.deepClone(n[d]);zt(c);const u=`${(s=n[n.length-1])==null?void 0:s.v}`;let h=t.indexOf(u)+e*l;h<0&&(h+=Math.abs(e)*r);const g=h%r;c&&(c.v=t[g],o.push(c))}return o}function Xd(n,i){const e=[];let t;if(i.startRow<n.startRow)t=a.Direction.UP;else if(i.endRow>n.endRow)t=a.Direction.DOWN;else if(i.startColumn<n.startColumn)t=a.Direction.LEFT;else if(i.endColumn>n.endColumn)t=a.Direction.RIGHT;else return[];if(t===a.Direction.DOWN||t===a.Direction.UP){const r=n.endRow-n.startRow+1,o=i.endRow-i.startRow+1,s=Math.floor(o/r),l=o%r,d={startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:n.endColumn-n.startColumn};if(t===a.Direction.DOWN){for(let c=0;c<s;c++)e.push({repeatStartCell:{row:n.startRow+(c+1)*r,col:n.startColumn},relativeRange:d});l>0&&e.push({repeatStartCell:{row:n.startRow+(s+1)*r,col:n.startColumn},relativeRange:{startRow:0,startColumn:0,endRow:l-1,endColumn:n.endColumn-n.startColumn}})}else{for(let c=0;c<s;c++)e.push({repeatStartCell:{row:n.startRow-(c+1)*r,col:n.startColumn},relativeRange:d});l>0&&e.push({repeatStartCell:{row:n.startRow-(s+1)*r,col:n.startColumn},relativeRange:{startRow:r-l,endRow:r-1,startColumn:0,endColumn:n.endColumn-n.startColumn}})}}if(t===a.Direction.RIGHT||t===a.Direction.LEFT){const r=n.endColumn-n.startColumn+1,o=i.endColumn-i.startColumn+1,s=Math.floor(o/r),l=o%r,d={startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:n.endColumn-n.startColumn};if(t===a.Direction.RIGHT){for(let c=0;c<s;c++)e.push({repeatStartCell:{row:n.startRow,col:n.startColumn+(c+1)*r},relativeRange:d});l>0&&e.push({repeatStartCell:{row:n.startRow,col:n.startColumn+(s+1)*r},relativeRange:{startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:l-1}})}else{for(let c=0;c<s;c++)e.push({repeatStartCell:{row:n.startRow,col:n.startColumn-(c+1)*r},relativeRange:d});l>0&&e.push({repeatStartCell:{row:n.startRow,col:n.startColumn-(s+1)*r},relativeRange:{startRow:0,startColumn:r-l,endRow:n.endRow-n.startRow,endColumn:r-1}})}}return e}function Ys(n){return!(a.isFormulaString(n.f)||a.isFormulaId(n.si)||n.t===a.CellValueType.BOOLEAN)}function zt(n){n&&"custom"in n&&delete n.custom}var hn=(n=>(n.Append="APPEND",n.Default="DEFAULT",n.Only="ONLY",n))(hn||{}),_e=(n=>(n.NUMBER="number",n.DATE="date",n.EXTEND_NUMBER="extendNumber",n.CHN_NUMBER="chnNumber",n.CHN_WEEK2="chnWeek2",n.CHN_WEEK3="chnWeek3",n.LOOP_SERIES="loopSeries",n.FORMULA="formula",n.OTHER="other",n))(_e||{}),ae=(n=>(n.COPY="COPY",n.SERIES="SERIES",n.ONLY_FORMAT="ONLY_FORMAT",n.NO_FORMAT="NO_FORMAT",n))(ae||{});const Yd={type:_e.DATE,priority:1100,match:(n,i)=>{var e;if(n!=null&&n.f||n!=null&&n.si)return!1;if((typeof(n==null?void 0:n.v)=="number"||(n==null?void 0:n.t)===a.CellValueType.NUMBER)&&n.s){if(typeof n.s=="string"){const r=i.get(a.IUniverInstanceService).getFocusedUnit().getStyles().get(n.s),o=(e=r==null?void 0:r.n)==null?void 0:e.pattern;if(o)return a.numfmt.getInfo(o).isDate}else if(n.s.n&&a.numfmt.getInfo(n.s.n.pattern).isDate)return!0}return!1},isContinue:(n,i)=>n.type===_e.DATE,applyFunctions:{[ae.SERIES]:(n,i,e)=>{const{data:t}=n;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),$r(t,i,e).reverse()):$r(t,i,e)}}},Gd={type:_e.NUMBER,priority:1e3,match:n=>typeof(n==null?void 0:n.v)=="number"||(n==null?void 0:n.t)===a.CellValueType.NUMBER,isContinue:(n,i)=>n.type===_e.NUMBER,applyFunctions:{[ae.SERIES]:(n,i,e)=>{const{data:t}=n;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),$r(t,i,e).reverse()):$r(t,i,e)}}},Xa={type:_e.OTHER,priority:0,match:()=>!0,isContinue:(n,i)=>n.type===_e.OTHER},Zd={type:_e.EXTEND_NUMBER,priority:900,match:n=>kr(`${n==null?void 0:n.v}`||"").isExtendNumber,isContinue:(n,i)=>{var e;if(n.type===_e.EXTEND_NUMBER){const{beforeTxt:t,afterTxt:r}=kr(`${(e=n.cellData)==null?void 0:e.v}`||""),{beforeTxt:o,afterTxt:s}=kr(`${i==null?void 0:i.v}`||"");if(t===o&&r===s)return!0}return!1},applyFunctions:{[ae.SERIES]:(n,i,e)=>{var l;const{data:t}=n,r=e===a.Direction.UP||e===a.Direction.LEFT;let o;if(t.length===1)return o=r?-1:1,Ue(js(t,i,o),r);const s=[];for(let d=0;d<t.length;d++){const c=`${(l=t[d])==null?void 0:l.v}`;c&&s.push(Number(kr(c).matchTxt))}return r&&(t.reverse(),s.reverse()),cr(s)?(o=s[1]-s[0],Ue(js(t,i,o),r)):jt(t,i)}}},Kd={type:_e.CHN_NUMBER,priority:830,match:n=>!!Hd(`${n==null?void 0:n.v}`||""),isContinue:(n,i)=>n.type===_e.CHN_NUMBER,applyFunctions:{[ae.SERIES]:(n,i,e)=>{var d,c,u;const{data:t}=n,r=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){const h=`${(d=t[0])==null?void 0:d.v}`;let g;return r?g=-1:g=1,h&&(h==="日"||ut(h)<7)?Ue(bn(t,i,g),r):Ue(zs(t,i,g),r)}let o=!1;for(let h=0;h<t.length;h++)if(((c=t[h])==null?void 0:c.v)==="日"){o=!0;break}const s=[];let l=0;for(let h=0;h<t.length;h++){const g=`${(u=t[h])==null?void 0:u.v}`;g==="日"?h===0?s.push(0):(l++,s.push(l*7)):o&&ut(g)>0&&ut(g)<7?s.push(ut(g)+l*7):s.push(ut(g))}if(r&&(t.reverse(),s.reverse()),cr(s)){if(o||s[s.length-1]<6&&s[0]>0||s[0]<6&&s[s.length-1]>0){const g=s[1]-s[0];return Ue(bn(t,i,g),r)}const h=s[1]-s[0];return Ue(zs(t,i,h),r)}return jt(t,i)}}},qd={type:_e.CHN_WEEK2,priority:820,match:n=>!!kd(`${n==null?void 0:n.v}`||""),isContinue:(n,i)=>n.type===_e.CHN_WEEK2,applyFunctions:{[ae.SERIES]:(n,i,e)=>{var l;const{data:t}=n,r=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let d;return r?d=-1:d=1,Ue(bn(t,i,d,1),r)}const o=[];let s=0;for(let d=0;d<t.length;d++){const c=`${(l=t[d])==null?void 0:l.v}`,u=c==null?void 0:c.substr(c.length-1,1);c==="周日"?d===0?o.push(0):(s++,o.push(s*7)):o.push(ut(u)+s*7)}if(r&&(t.reverse(),o.reverse()),cr(o)){const d=o[1]-o[0];return Ue(bn(t,i,d,1),r)}return jt(t,i)}}},Qd={type:_e.CHN_WEEK3,priority:810,match:n=>Vd(`${n==null?void 0:n.v}`||""),isContinue:(n,i)=>n.type===_e.CHN_WEEK3,applyFunctions:{[ae.SERIES]:(n,i,e)=>{var l;const{data:t}=n,r=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let d;return r?d=-1:d=1,Ue(bn(t,i,d,2),r)}const o=[];let s=0;for(let d=0;d<t.length;d++){const c=`${(l=t[d])==null?void 0:l.v}`;if(c){const u=c.substr(c.length-1,1);c==="星期日"?d===0?o.push(0):(s++,o.push(s*7)):o.push(ut(u)+s*7)}}if(r&&(t.reverse(),o.reverse()),cr(o)){const d=o[1]-o[0];return Ue(bn(t,i,d,2),r)}return jt(t,i)}}},Jd={type:_e.LOOP_SERIES,priority:800,match:n=>zd(`${n==null?void 0:n.v}`||""),isContinue:(n,i)=>{var e;return n.type===_e.LOOP_SERIES?Fi(`${(e=n.cellData)==null?void 0:e.v}`||"").name===Fi(`${i==null?void 0:i.v}`||"").name:!1},applyFunctions:{[ae.SERIES]:(n,i,e)=>{var d,c;const{data:t}=n,r=e===a.Direction.LEFT||e===a.Direction.UP,{series:o}=Fi(`${(d=t[0])==null?void 0:d.v}`||"");if(t.length===1){let u;return r?u=-1:u=1,Ue(Xs(t,i,u,o),r)}const s=[];let l=0;for(let u=0;u<t.length;u++){const h=`${(c=t[u])==null?void 0:c.v}`;h&&(h===o[0]?u===0?s.push(0):(l++,s.push(l*o.length)):s.push(o.indexOf(h)+l*7))}if(r&&(t.reverse(),s.reverse()),cr(s)){const u=s[1]-s[0];return Ue(Xs(t,i,u,o),r)}return jt(t,i)}}};function Ue(n,i){return i?n.reverse():n}var $d=Object.defineProperty,eu=Object.getOwnPropertyDescriptor,tu=(n,i,e,t)=>{for(var r=t>1?void 0:t?eu(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&$d(i,e,r),r},rn=(n,i)=>(e,t)=>i(e,t,n);exports.AutoFillService=class extends a.Disposable{constructor(e,t,r,o,s,l){super();R(this,"_rules",[]);R(this,"_hooks",[]);R(this,"_applyType$",new O.BehaviorSubject(ae.SERIES));R(this,"_isFillingStyle",!0);R(this,"_prevUndos",[]);R(this,"_autoFillLocation$",new O.BehaviorSubject(null));R(this,"autoFillLocation$",this._autoFillLocation$.asObservable());R(this,"_showMenu$",new O.BehaviorSubject(!1));R(this,"showMenu$",this._showMenu$.asObservable());R(this,"_direction",a.Direction.DOWN);R(this,"applyType$",this._applyType$.asObservable());R(this,"_menu$",new O.BehaviorSubject([{label:"autoFill.copy",value:ae.COPY,disable:!1},{label:"autoFill.series",value:ae.SERIES,disable:!1},{label:"autoFill.formatOnly",value:ae.ONLY_FORMAT,disable:!1},{label:"autoFill.noFormat",value:ae.NO_FORMAT,disable:!1}]));R(this,"menu$",this._menu$.asObservable());this._commandService=e,this._undoRedoService=t,this._renderManagerService=r,this._univerInstanceService=o,this._selectionManagerService=s,this._injector=l,this._init()}_init(){this._rules=[Yd,Gd,Zd,Kd,qd,Qd,Jd,Xa].sort((e,t)=>t.priority-e.priority),this._isFillingStyle=!0}_getOneByPriority(e){return e.length<=0?[]:[e.reduce((r,o)=>(o.priority||0)>(r.priority||0)?o:r,e[0])]}_initPrevUndo(){this._prevUndos=[]}async triggerAutoFill(e,t,r,o){var S;if(r.startColumn===o.startColumn&&r.startRow===o.startRow&&r.endColumn===o.endColumn&&r.endRow===o.endRow)return!1;if(o.endColumn<r.endColumn&&o.endColumn>r.startColumn)return this._commandService.executeCommand(Rn.id,{clearRange:{startRow:o.startRow,endRow:o.endRow,startColumn:o.endColumn+1,endColumn:r.endColumn},selectionRange:o});if(o.endRow<r.endRow&&o.endRow>r.startRow)return this._commandService.executeCommand(Rn.id,{clearRange:{startRow:o.endRow+1,endRow:r.endRow,startColumn:o.startColumn,endColumn:o.endColumn},selectionRange:o});const s={startRow:o.startRow,endRow:o.endRow,startColumn:o.startColumn,endColumn:o.endColumn};let l=null;if(o.startRow<r.startRow)l=a.Direction.UP,s.endRow=r.startRow-1;else if(o.endRow>r.endRow)l=a.Direction.DOWN,s.startRow=r.endRow+1;else if(o.startColumn<r.startColumn)l=a.Direction.LEFT,s.endColumn=r.startColumn-1;else if(o.endColumn>r.endColumn)l=a.Direction.RIGHT,s.startColumn=r.endColumn+1;else return!1;this.direction=l;const d=this._injector.invoke(f=>gn(r,f)),c=this._injector.invoke(f=>gn(s,f));if(!d||!c)return!1;this.autoFillLocation={source:d,target:c,unitId:e,subUnitId:t};const u=[];this.getActiveHooks().forEach(f=>{var v;const p=(v=f==null?void 0:f.onBeforeFillData)==null?void 0:v.call(f,{source:d,target:c,unitId:e,subUnitId:t},l);p&&u.unshift(p)}),this._initPrevUndo();for(let f=0;f<u.length;f++){const p=this.menu.find(v=>v.value===u[f]);if(p&&!p.disable)return this.fillData(u[f])}const g=(S=this.menu.find(f=>f.disable===!1))==null?void 0:S.value;return g?this.fillData(g):!1}addHook(e){if(this._hooks.find(t=>t.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=hn.Append),this._hooks.push(e),a.toDisposable(()=>{const t=this._hooks.findIndex(r=>r===e);t>-1&&this._hooks.splice(t,1)})}registerRule(e){if(this._rules.find(r=>r.type===e.type))throw new Error(`Registry rule failed, type '${e.type}' already exist!`);const t=this._rules.findIndex(r=>r.priority<e.priority);this._rules.splice(t===-1?this._rules.length:t,0,e)}getRules(){return this._rules}getAllHooks(){return this._hooks}getActiveHooks(){const{source:e,target:t,unitId:r,subUnitId:o}=this.autoFillLocation||{};if(!e||!t||!r||!o)return[];const s=this._hooks.filter(u=>{var h;return!((h=u.disable)!=null&&h.call(u,{source:e,target:t,unitId:r,subUnitId:o},this._direction,this.applyType))}),l=s.filter(u=>u.type===hn.Only);if(l.length>0)return this._getOneByPriority(l);const d=this._getOneByPriority(s.filter(u=>u.type===hn.Default)),c=s.filter(u=>u.type===hn.Append)||[];return[...d,...c]}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,t){this._menu$.next(this._menu$.getValue().map(r=>r.value===e?{...r,disable:t}:r))}setShowMenu(e){this._showMenu$.next(e)}fillData(e){var C,I,b;this.applyType=e;const{source:t,target:r,unitId:o=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId(),subUnitId:s=(C=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:C.getSheetId()}=this.autoFillLocation||{};if(!t||!r||!o||!s)return!1;const l=this.direction;this._prevUndos.length>0&&this._prevUndos.forEach(T=>{this._commandService.syncExecuteCommand(T.id,T.params)}),this._prevUndos=[];const d=a.Rectangle.union(Et(t),Et(r)),c=this.getActiveHooks(),u=this._univerInstanceService.getUnit(o,a.UniverInstanceType.UNIVER_SHEET);this._commandService.syncExecuteCommand(m.SetSelectionsOperation.id,{selections:[{primary:{...(b=(I=this._selectionManagerService.getCurrentLastSelection())==null?void 0:I.primary)!=null?b:d},range:{...d,rangeType:a.RANGE_TYPE.NORMAL}}],unitId:o,subUnitId:s});const h=[],g=[];c.forEach(T=>{var P;const{undos:M,redos:y}=((P=T.onFillData)==null?void 0:P.call(T,{source:t,target:r,unitId:o,subUnitId:s},l,e))||{};M&&h.push(...M),y&&g.push(...y)});const S=g.every(T=>this._commandService.syncExecuteCommand(T.id,T.params)),f=[];e!==ae.NO_FORMAT&&g.forEach(T=>{if(T.id===m.SetRangeValuesMutation.id){const{cellValue:M}=T.params;new a.ObjectMatrix(M).forValue((P,x,A)=>{const N=Object.keys(u.getStyles().get(A==null?void 0:A.s)||{});(A!=null&&A.p||N.length&&us.some(D=>N.includes(D)))&&f.push({startRow:P,endRow:P,startColumn:x,endColumn:x})})}});const p=this._getAutoHeightUndoRedos(o,s,f);return p.redos.every(T=>this._commandService.syncExecuteCommand(T.id,T.params))&&(h.push(...p.undos),g.push(...p.redos)),S&&(this._prevUndos=h,this._undoRedoService.pushUndoRedo({unitID:o,undoMutations:h,redoMutations:g})),c.forEach(T=>{var M;(M=T.onAfterFillData)==null||M.call(T,{source:t,target:r,unitId:o,subUnitId:s},l,e)}),this.setShowMenu(!0),!0}_getAutoHeightUndoRedos(e,t,r){var h,g;const o=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(exports.SheetSkeletonManagerService),s=(g=o==null?void 0:o.getCurrent())==null?void 0:g.skeleton;if(!s)return{redos:[],undos:[]};const l=s.calculateAutoHeightInRange(r),d={subUnitId:t,unitId:e,rowsAutoHeightInfo:l},c=s.worksheet,u=m.SetWorksheetRowAutoHeightMutationFactory(d,c);return{undos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:u}],redos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:d}]}}};exports.AutoFillService=tu([rn(0,a.ICommandService),rn(1,a.IUndoRedoService),rn(2,w.IRenderManagerService),rn(3,a.Inject(a.IUniverInstanceService)),rn(4,a.Inject(m.SheetsSelectionsService)),rn(5,a.Inject(a.Injector))],exports.AutoFillService);const Tt=a.createIdentifier("univer.auto-fill-service"),_t={type:a.CommandType.COMMAND,id:"sheet.command.auto-fill",handler:async(n,i)=>{const e=n.get(Tt),t=n.get(a.IUniverInstanceService),{sourceRange:r,targetRange:o}=i,s=m.getSheetCommandTarget(t);if(!s)return!1;const{subUnitId:l,unitId:d}=s;return e.triggerAutoFill(d,l,r,o)}},Rn={id:"sheet.command.auto-clear-content",type:a.CommandType.COMMAND,handler:async(n,i)=>{const e=n.get(a.IUniverInstanceService),t=n.get(a.ICommandService),r=n.get(a.IUndoRedoService),o=n.get(m.SheetInterceptorService),s=m.getSheetCommandTarget(e);if(!s)return!1;const{unitId:l,subUnitId:d}=s,{clearRange:c,selectionRange:u}=i,h={subUnitId:d,unitId:l,cellValue:m.generateNullCellValue([c])},g=m.SetRangeValuesUndoMutationFactory(n,h),{startColumn:S,startRow:f}=u,p={selections:[{primary:{startColumn:S,startRow:f,endColumn:S,endRow:f,actualRow:f,actualColumn:S,isMerged:!1,isMergedMainCell:!1},range:{...u}}],unitId:l,subUnitId:d};if(t.executeCommand(m.SetSelectionsOperation.id,p),t.syncExecuteCommand(m.SetRangeValuesMutation.id,h)){const C=o.afterCommandExecute({id:m.SetRangeValuesMutation.id,params:h});return a.sequenceExecute(C.redos,t),r.pushUndoRedo({unitID:l,undoMutations:[{id:m.SetRangeValuesMutation.id,params:g},...C.undos],redoMutations:[{id:m.SetRangeValuesMutation.id,params:h},...C.redos]}),!0}return!1}},dr={id:"sheet.command.refill",type:a.CommandType.COMMAND,handler:async(n,i)=>n.get(Tt).fillData(i.type)};var nu=Object.defineProperty,ru=Object.getOwnPropertyDescriptor,iu=(n,i,e,t)=>{for(var r=t>1?void 0:t?ru(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&nu(i,e,r),r},Pt=(n,i)=>(e,t)=>i(e,t,n);exports.EditorBridgeService=class extends a.Disposable{constructor(e,t,r,o,s,l,d){super();R(this,"_editorUnitId",a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);R(this,"_editorIsDirty",!1);R(this,"_isDisabled",!1);R(this,"_visible",{visible:!1,eventType:w.DeviceInputEventType.Dblclick,unitId:""});R(this,"_currentEditCell",null);R(this,"_currentEditCellState",null);R(this,"_currentEditCellLayout",null);R(this,"_currentEditCellState$",new O.BehaviorSubject(null));R(this,"currentEditCellState$",this._currentEditCellState$.asObservable());R(this,"_currentEditCellLayout$",new O.BehaviorSubject(null));R(this,"currentEditCellLayout$",this._currentEditCellLayout$.asObservable());R(this,"currentEditCell$",this._currentEditCellState$.pipe(O.switchMap(e=>this._currentEditCellLayout$.pipe(O.map(t=>e&&t?{...e,...t}:null)))));R(this,"_visible$",new O.BehaviorSubject(this._visible));R(this,"visible$",this._visible$.asObservable());R(this,"_afterVisible$",new O.BehaviorSubject(this._visible));R(this,"afterVisible$",this._afterVisible$.asObservable());R(this,"_forceKeepVisible$",new O.BehaviorSubject(!1));R(this,"forceKeepVisible$",this._forceKeepVisible$.asObservable());this._sheetInterceptorService=e,this._renderManagerService=t,this._themeService=r,this._univerInstanceService=o,this._editorService=s,this._refSelectionsService=l,this._contextService=d,this.disposeWithMe(a.toDisposable(()=>{this._currentEditCellState$.complete(),this._currentEditCell=null})),this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).subscribe(c=>{var u;c.getUnitId()===((u=this._currentEditCellState)==null?void 0:u.unitId)&&this._clearCurrentEditCellState()})}refreshEditCellState(){const e=this.getLatestEditCellState();if(!e){this._currentEditCellState=null,this._currentEditCellLayout=null,this._currentEditCellState$.next(null),this._currentEditCellLayout$.next(null);return}const{position:t,scaleX:r,scaleY:o,canvasOffset:s,...l}=e;this._currentEditCellState=l,this._currentEditCellLayout={position:t,scaleX:r,scaleY:o,canvasOffset:s},this._currentEditCellState$.next(this._currentEditCellState),this._currentEditCellLayout$.next(this._currentEditCellLayout)}refreshEditCellPosition(e){var y;const t=this._currentEditCell;if(t==null)return;const r=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET);if(!r)return;const o=(y=r.with(exports.SheetSkeletonManagerService).getWorksheetSkeleton(t.sheetId))==null?void 0:y.skeleton,s=r.with(ve);if(!o||!this._currentEditCellState)return;const{primary:l,unitId:d,sheetId:c,scene:u,engine:h}=t,g=Qn(o,l);if(g==null)return;const S=a.convertCellToRange(g),f=J.getCanvasOffsetByEngine(h);let{startX:p,startY:v,endX:C,endY:I}=S;const{scaleX:b,scaleY:T}=u.getAncestorScale(),M=u.getViewportScrollXY(s.getViewPort());p=o.convertTransformToOffsetX(p,b,M),v=o.convertTransformToOffsetY(v,T,M),C=o.convertTransformToOffsetX(C,b,M),I=o.convertTransformToOffsetY(I,T,M),e&&this._currentEditCellLayout&&(C=C-p+this._currentEditCellLayout.position.startX,I=I-v+this._currentEditCellLayout.position.startY,p=this._currentEditCellLayout.position.startX,v=this._currentEditCellLayout.position.startY),this._currentEditCellLayout={position:{startX:p,startY:v,endX:C,endY:I},canvasOffset:f,scaleX:b,scaleY:T},this._currentEditCellLayout$.next(this._currentEditCellLayout)}setEditCell(e){this._currentEditCell=e,this._editorService.getFocusEditor()||(this._editorService.focus(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._contextService.setContextValue(a.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(a.FOCUSING_EDITOR_STANDALONE,!1));const t=this.getLatestEditCellState();if(!t){this._currentEditCellState=t,this._currentEditCellLayout=t,this._currentEditCellState$.next(t),this._currentEditCellLayout$.next(t);return}const{position:r,canvasOffset:o,scaleX:s,scaleY:l,...d}=t;this._currentEditCellState=d,this._currentEditCellLayout={position:r,canvasOffset:o,scaleX:s,scaleY:l},this._currentEditCellState$.next(this._currentEditCellState),this._currentEditCellLayout$.next(this._currentEditCellLayout)}_clearCurrentEditCellState(){this._currentEditCellState=null,this._currentEditCellState$.next(null),this._currentEditCellLayout=null,this._currentEditCellLayout$.next(null)}getEditCellState(){return this._currentEditCellState==null||this._currentEditCellLayout==null?null:{...this._currentEditCellState,...this._currentEditCellLayout}}getEditCellLayout(){return this._currentEditCellLayout}getEditLocation(){return this._currentEditCellState}getLatestEditCellState(){var W,k,U;const e=this._currentEditCell;if(e==null)return;const t=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET);if(!t)return;const r=t.with(exports.SheetSkeletonManagerService).getCurrentSkeleton(),o=t.with(ve);if(!r)return;const{primary:s,unitId:l,sheetId:d,scene:c,engine:u}=e,{startRow:h,startColumn:g}=s,S=Qn(r,s);if(S==null)return;const f=a.convertCellToRange(S),p=J.getCanvasOffsetByEngine(u);let{startX:v,startY:C,endX:I,endY:b}=f;const{scaleX:T,scaleY:M}=c.getAncestorScale(),y=c.getViewportScrollXY(o.getViewPort());v=r.convertTransformToOffsetX(v,T,y),C=r.convertTransformToOffsetY(C,M,y),I=r.convertTransformToOffsetX(I,T,y),b=r.convertTransformToOffsetY(b,M,y);const P=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),x=P.getActiveSheet();if(!x)return;const A={workbook:P,worksheet:x,unitId:P.getUnitId(),subUnitId:x.getSheetId(),row:h,col:g,origin:x.getCellRaw(h,g)};let N;const D=this._sheetInterceptorService.writeCellInterceptor.fetchThroughInterceptors(m.BEFORE_CELL_EDIT)(x.getCell(h,g),A);N=D&&r.getCellDocumentModelWithFormula(D);const H=(W=N==null?void 0:N.documentModel)==null?void 0:W.documentStyle.renderConfig;if(H!=null&&(H.cellValueType=a.CellValueType.STRING),!N||N.documentModel==null){const B=r.getBlankCellDocumentModel(D);if(N!=null){const{verticalAlign:F,horizontalAlign:L,wrapStrategy:z,textRotation:X,fill:Z}=N,{centerAngle:re,vertexAngle:Q}=w.convertTextRotation(X);B.documentModel.documentStyle.renderConfig={...H,verticalAlign:F,horizontalAlign:L,wrapStrategy:z,background:{rgb:Z},centerAngle:re,vertexAngle:Q}}N=B}if(N.fill=N.fill||"#fff",(k=N.documentModel)==null||k.setZoomRatio(Math.max(T,M)),(D==null?void 0:D.isInArrayFormulaRange)===!0){const B=(U=N.documentModel)==null?void 0:U.getBody();B&&(B.textRuns=[{st:0,ed:B.dataStream.length-2,ts:{cl:{rgb:this._themeService.getCurrentTheme().textColorSecondary}}}])}return{position:{startX:v,startY:C,endX:I,endY:b},scaleX:T,scaleY:M,canvasOffset:p,row:h,column:g,unitId:l,sheetId:d,documentLayoutObject:N,editorUnitId:this._editorUnitId,isInArrayFormulaRange:D==null?void 0:D.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._forceKeepVisible$.next(!0)}disableForceKeepVisible(){this._forceKeepVisible$.next(!1)}isForceKeepVisible(){return this._forceKeepVisible$.getValue()}changeEditorDirty(e){this._editorIsDirty=e}getEditorDirty(){return this._editorIsDirty}};exports.EditorBridgeService=iu([Pt(0,a.Inject(m.SheetInterceptorService)),Pt(1,w.IRenderManagerService),Pt(2,a.Inject(a.ThemeService)),Pt(3,a.IUniverInstanceService),Pt(4,J.IEditorService),Pt(5,m.IRefSelectionsService),Pt(6,a.IContextService)],exports.EditorBridgeService);const Se=a.createIdentifier("univer.sheet-editor-bridge.service"),Te={id:"sheet.operation.set-cell-edit-visible",type:a.CommandType.OPERATION,handler:(n,i)=>i?(n.get(Se).changeVisible(i),!0):!1},ur={id:"sheet.operation.set-cell-edit-visible-f2",type:a.CommandType.OPERATION,handler:(n,i)=>{const e=n.get(a.ICommandService),r=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);return r?(e.syncExecuteCommand(Te.id,{...i,unitId:r.getUnitId()}),!0):!1}},Xt={id:"sheet.operation.set-cell-edit-visible-arrow",type:a.CommandType.OPERATION,handler:()=>!0},An={id:"sheet.command.change-zoom-ratio",type:a.CommandType.COMMAND,handler:(n,i)=>{if(!i)return!1;const e=n.get(a.IUniverInstanceService),t=m.getSheetCommandTarget(e);if(!t)return!1;const{worksheet:r,subUnitId:o,unitId:s}=t,{delta:l,reset:d}=i;let c=d?100:Math.round((r.getConfig().zoomRatio+l)*100);c=Math.max(Ao[0],c),c=Math.min(Ao[1],c);const u=c/100,g=n.get(Se).isVisible();return(g.unitId===s||g.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&g.visible?!1:n.get(a.ICommandService).executeCommand(Le.id,{unitId:s,subUnitId:o,zoomRatio:u})}},Nn={id:"sheet.command.set-zoom-ratio",type:a.CommandType.COMMAND,handler:async(n,i)=>{if(!i)return!1;const{unitId:e,subUnitId:t,zoomRatio:r}=i,s=n.get(Se).isVisible();return(s.unitId===e||s.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&s.visible?!1:n.get(a.ICommandService).executeCommand(Le.id,{unitId:e,subUnitId:t,zoomRatio:r})}};function ou(n){return typeof n.isMainScene>"u"}function Ye(n,i){const e=n instanceof a.Workbook?n:n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!e)return null;const t=e.getUnitId();let r,o,s,l;if(ou(i)){const g=i.getRenderById(t);if(g==null)return null;r=g.components,r=g.components,o=g.mainComponent,s=g.scene,l=g.engine}else r=i.components,o=i.mainComponent,s=i.scene,l=i.engine;if(!r||!o)return null;const d=o,c=r.get(he.ROW),u=r.get(he.COLUMN),h=r.get(he.LEFT_TOP);return{spreadsheet:d,spreadsheetRowHeader:c,spreadsheetColumnHeader:u,spreadsheetLeftTopPlaceholder:h,scene:s,engine:l}}function Vo(n,i,e,t){const{startX:r,startY:o,endX:s,endY:l}=t.getCellWithCoordByIndex(n,i);return{startX:r,startY:o,endX:s,endY:l}}function qe(n,i,e,t,r,o){const s=e.getCoordRelativeToViewport(w.Vector2.FromArray([n,i])),{x:l,y:d}=s,c=e.getScrollXYInfoByViewport(s,r),{scaleX:u,scaleY:h}=e.getAncestorScale(),g=t.getCellIndexByOffset(l,d,u,h,c,{closeFirst:o}),{row:S,column:f}=g,p=t.getNoMergeCellPositionByIndex(S,f),{startX:v,startY:C,endX:I,endY:b}=p;return{startX:v,startY:C,endX:I,endY:b,row:S,column:f}}function Kn(n,i,e,t){const r=e.getCoordRelativeToViewport(w.Vector2.FromArray([n,i])),o=e.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN),s=e.getScrollXYInfoByViewport(r,o),{scaleX:l,scaleY:d}=e.getAncestorScale(),{x:c,y:u}=s,h=n/l+c,g=i/d+u;return{x:h,y:g}}var su=Object.defineProperty,au=Object.getOwnPropertyDescriptor,lu=(n,i,e,t)=>{for(var r=t>1?void 0:t?au(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&su(i,e,r),r},Vr=(n,i)=>(e,t)=>i(e,t,n);let Jn=class extends a.Disposable{constructor(i,e,t,r,o){super();R(this,"_zoom");this._context=i,this._sheetSkeletonManagerService=e,this._commandService=t,this._contextService=r,this._editorBridgeService=o,this._initSkeletonListener(),this._initZoomEventListener()}updateZoom(i,e){const t=this._context.unit.getSheetBySheetId(i);return t?(t.getConfig().zoomRatio=e,t===this._context.unit.getActiveSheet()&&this._updateViewZoom(e),!0):!1}_initZoomEventListener(){const i=this._getSheetObject().scene;this.disposeWithMe(i.onMouseWheel$.subscribeEvent(e=>{if(!e.ctrlKey||!this._contextService.getContextValue(a.FOCUSING_SHEET))return;if(this._editorBridgeService){const c=this._editorBridgeService.isVisible();if((c.unitId===this._context.unitId||c.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&c.visible)return}const t=Math.abs(e.deltaX);let r=t<40?.2:t<80?.4:.2;r*=e.deltaY>0?-1:1,i.scaleX<1&&(r/=2);const o=this._context.unit,s=o.getActiveSheet();if(!s)return;const l=s.getZoomRatio();let d=+Number.parseFloat(`${l+r}`).toFixed(1);d=d>=4?4:d<=.1?.1:d,this._commandService.executeCommand(Nn.id,{zoomRatio:Math.round(d*10)/10,unitId:o.getUnitId(),subUnitId:s.getSheetId()}),e.preventDefault()}))}_initSkeletonListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeletonBefore$.subscribe(i=>{if(i==null)return;const t=this._context.unit.getActiveSheet();if(!t)return;const r=t.getZoomRatio()||1;this._zoom!==r&&this._updateViewZoom(r),this._zoom=r}))}_updateViewZoom(i){const e=this._getSheetObject();e==null||e.scene.scale(i,i),e==null||e.spreadsheet.makeForceDirty()}_getSheetObject(){return Ye(this._context.unit,this._context)}};Jn=lu([Vr(1,a.Inject(exports.SheetSkeletonManagerService)),Vr(2,a.ICommandService),Vr(3,a.IContextService),Vr(4,a.Optional(Se))],Jn);const Le={id:"sheet.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(n,i)=>{const t=n.get(w.IRenderManagerService).getRenderById(i.unitId);return t?t.with(Jn).updateZoom(i.subUnitId,i.zoomRatio):!1}};var cu=Object.defineProperty,du=Object.getOwnPropertyDescriptor,uu=(n,i,e,t)=>{for(var r=t>1?void 0:t?du(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&cu(i,e,r),r},ji=(n,i)=>(e,t)=>i(e,t,n);const Gs="univer-sheet-main-canvas";exports.SheetsRenderService=class extends a.RxDisposable{constructor(e,t,r){super();R(this,"_skeletonChangeMutations",new Set);this._contextService=e,this._instanceSrv=t,this._renderManagerService=r,Promise.resolve().then(()=>this._init())}registerSkeletonChangingMutations(e){return this._skeletonChangeMutations.has(e)?a.toDisposable(()=>{}):(this._skeletonChangeMutations.add(e),a.toDisposable(()=>this._skeletonChangeMutations.delete(e)))}checkMutationShouldTriggerRerender(e){return this._skeletonChangeMutations.has(e)}_init(){this._initWorkbookListener(),this._initContextListener()}_initWorkbookListener(){this._instanceSrv.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET).pipe(O.takeUntil(this.dispose$)).subscribe(e=>this._createRenderer(e)),this._instanceSrv.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(e=>this._createRenderer(e)),this._instanceSrv.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).pipe(O.takeUntil(this.dispose$)).subscribe(e=>this._disposeRenderer(e)),this.disposeWithMe(this._instanceSrv.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(e=>{e&&this._renderManagerService.setCurrent(e.getUnitId())}))}_createRenderer(e){const t=e.getUnitId();this._renderManagerService.created$.subscribe(r=>{r.unitId===t&&(r.engine.getCanvas().setId(`${Gs}_${t}`),r.engine.getCanvas().getContext().setId(`${Gs}_${t}`))}),this._renderManagerService.createRender(t)}_disposeRenderer(e){const t=e.getUnitId();this._renderManagerService.removeRender(t)}_initContextListener(){this.disposeWithMe(this._contextService.subscribeContextValue$(w.RENDER_RAW_FORMULA_KEY).pipe(O.distinctUntilChanged()).subscribe(()=>{this._renderManagerService.getRenderAll().forEach(e=>{e.mainComponent instanceof w.Spreadsheet&&e.mainComponent.makeForceDirty(!0)})}))}};exports.SheetsRenderService=uu([ji(0,a.IContextService),ji(1,a.IUniverInstanceService),ji(2,w.IRenderManagerService)],exports.SheetsRenderService);var hu=Object.defineProperty,mu=Object.getOwnPropertyDescriptor,gu=(n,i,e,t)=>{for(var r=t>1?void 0:t?mu(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&hu(i,e,r),r},Ot=(n,i)=>(e,t)=>i(e,t,n);exports.AutoFillController=class extends a.Disposable{constructor(e,t,r,o,s,l,d){super();R(this,"_beforeApplyData",[]);R(this,"_currentLocation",null);R(this,"_copyData",[]);R(this,"_defaultHook");this._univerInstanceService=e,this._commandService=t,this._autoFillService=r,this._editorBridgeService=o,this._renderManagerService=s,this._injector=l,this._sheetsRenderService=d,this._defaultHook={id:"default",type:hn.Default,priority:0,onBeforeFillData:(c,u)=>this._presetAndCacheData(c,u),onFillData:(c,u,h)=>this._fillData(c,u,h)},this._init()}_init(){this._initDefaultHook(),this._onSelectionControlFillChanged(),this._initQuitListener(),this._initSkeletonChange()}_initSkeletonChange(){this.disposeWithMe(this._sheetsRenderService.registerSkeletonChangingMutations(_t.id))}_initDefaultHook(){this.disposeWithMe(this._autoFillService.addHook(this._defaultHook))}_initQuitListener(){const e=[Te.id,Rn.id,m.SetRangeValuesCommand.id,Le.id,m.SetWorksheetActiveOperation.id,m.MoveRangeMutation.id,m.RemoveRowMutation.id,m.RemoveColMutation.id,m.InsertRowMutation.id,m.InsertColMutation.id,m.MoveRowsMutation.id,m.MoveColsMutation.id,m.SetWorksheetColWidthMutation.id,m.SetWorksheetRowHeightMutation.id,m.SetRangeValuesMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted((t,r)=>{var d,c;const o=r==null?void 0:r.fromCollab,s=r==null?void 0:r.fromSync,l=r==null?void 0:r.fromFormula;e.includes(t.id)&&!o&&!s&&!l&&t.params.trigger!==_t.id&&t.params.trigger!==dr.id&&this._quit(),t.id===m.RemoveSheetMutation.id&&t.params.unitId===((d=this._currentLocation)==null?void 0:d.unitId)&&t.params.subUnitId===((c=this._currentLocation)==null?void 0:c.subUnitId)&&this._quit()})),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{var r;t.getUnitId()===((r=this._currentLocation)==null?void 0:r.unitId)&&this._quit()}))}_quit(){this._currentLocation=null,this._beforeApplyData=[],this._copyData=[],this._autoFillService.setShowMenu(!1)}_onSelectionControlFillChanged(){const e=new a.DisposableCollection,t=r=>{r.dispose();const o=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET);if(!o)return;o.with(ve).getSelectionControls().forEach(d=>{r.add(a.toDisposable(d.selectionFilled$.subscribe(c=>{if(c==null||c.startColumn===-1||c.startRow===-1||c.endColumn===-1||c.endRow===-1)return;const u={startColumn:d.model.startColumn,endColumn:d.model.endColumn,startRow:d.model.startRow,endRow:d.model.endRow},h={startColumn:c.startColumn,endColumn:c.endColumn,startRow:c.startRow,endRow:c.endRow};this._commandService.executeCommand(_t.id,{sourceRange:u,targetRange:h})}))),r.add(a.toDisposable(d.fillControl.onDblclick$.subscribeEvent(()=>{const c={startColumn:d.model.startColumn,endColumn:d.model.endColumn,startRow:d.model.startRow,endRow:d.model.endRow};this._handleDbClickFill(c)}))),r.add(a.toDisposable(d.fillControl.onPointerDown$.subscribeEvent(()=>{this._editorBridgeService.isVisible().visible&&this._editorBridgeService.changeVisible({visible:!1,eventType:w.DeviceInputEventType.PointerDown,unitId:o.unitId})})))})};t(e),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{r.id===m.SetSelectionsOperation.id&&t(e)}))}_handleDbClickFill(e){const t=this._detectFillRange(e);t.endRow<=e.endRow||this._commandService.executeCommand(_t.id,{sourceRange:e,targetRange:t})}_detectFillRange(e){var g,S,f,p,v,C;const{startRow:t,endRow:r,startColumn:o,endColumn:s}=e,l=(g=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET))==null?void 0:g.getActiveSheet();if(!l)return e;const d=l.getCellMatrix(),c=l.getMaxRows()-1,u=l.getMaxColumns()-1;let h=r;if(o>0&&((S=d.getValue(t,o-1))==null?void 0:S.v)!=null){let I=t;for(;((f=d.getValue(I,o-1))==null?void 0:f.v)!=null&&I<c;)I+=1;h=I-1}else if(s<u&&((p=d.getValue(r,s+1))==null?void 0:p.v)!=null){let I=t;for(;((v=d.getValue(I,s+1))==null?void 0:v.v)!=null&&I<c;)I+=1;h=I-1}for(let I=r+1;I<=h;I++)for(let b=o;b<=s;b++)if(((C=d.getValue(I,b))==null?void 0:C.v)!=null){h=I-1;break}return{startColumn:o,endColumn:s,startRow:t,endRow:h}}_getApplyData(e,t,r,o,s,l=!0){const d=[],c=Math.floor(r/t),u=r%t,h=this._autoFillService.getRules();if(!l&&s===ae.ONLY_FORMAT)return console.error("ERROR: only format can not be applied when hasStyle is false"),[];const g={};h.forEach(S=>{g[S.type]=[]}),h.forEach(S=>{const{type:f,applyFunctions:p={}}=S,v=e[f];v&&v.forEach(C=>{const I=Wd(C.index,u),b=C.index.length*c+I,T=this._applyFunctions(C,b,o,s,p,e),M=Ud(t,r,C.index);g[f].push({data:T,index:M})})});for(let S=0;S<r;S++)h.forEach(f=>{const{type:p}=f,v=g[p];for(let C=0;C<v.length;C++)S in v[C].index&&d.push(v[C].data[v[C].index[S]])});return d}_applyFunctions(e,t,r,o,s,l){const{data:d}=e,c=r===a.Direction.UP||r===a.Direction.LEFT;if(o===ae.COPY){const u=s==null?void 0:s[ae.COPY];return u?u(e,t,r,l):(c&&d.reverse(),jt(d,t))}if(o===ae.SERIES){const u=s==null?void 0:s[ae.SERIES];return u?u(e,t,r,l):(c&&d.reverse(),s!=null&&s[ae.COPY]?s[ae.COPY](e,t,r,l):jt(d,t))}if(o===ae.ONLY_FORMAT){const u=s==null?void 0:s[ae.ONLY_FORMAT];return u?u(e,t,r,l):Ld(d,t)}}_getCopyData(e,t){const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!r)throw new Error("No active sheet found");const o=r.getCellMatrix(),s=this._autoFillService.getRules(),l=[],d=t===a.Direction.DOWN||t===a.Direction.UP;let c,u;return d?(c=e.cols,u=e.rows):(c=e.rows,u=e.cols),c.forEach(h=>{const g=this._getEmptyCopyDataPiece(),S={type:void 0,cellData:void 0};u.forEach(f=>{let p;d?p=o.getValue(f,h):p=o.getValue(h,f);const{type:v,isContinue:C}=s.find(I=>I.match(p,this._injector))||Xa;if(C(S,p)){const I=g[v],b=I[I.length-1];b.data.push(p),b.index.push(f-u[0])}else{const I=g[v];I?I.push({data:[p],index:[f-u[0]]}):g[v]=[{data:[p],index:[f-u[0]]}]}S.type=v,S.cellData=p}),l.push(g)}),l}_getEmptyCopyDataPiece(){const e={};return this._autoFillService.getRules().forEach(t=>{e[t.type]=[]}),e}_getMergeApplyData(e,t,r,o){const s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!s)throw new Error("No active sheet found");const l=[];for(let d=e.startRow;d<=e.endRow;d++)for(let c=e.startColumn;c<=e.endColumn;c++){const{isMergedMainCell:u,startRow:h,startColumn:g,endRow:S,endColumn:f}=s.getCellInfoInMergeData(d,c);if(u){if(r===a.Direction.DOWN){let p=h+o,v=S+o;for(;v<=t.endRow;)l.push({startRow:p,startColumn:g,endRow:v,endColumn:f}),p+=o,v+=o}else if(r===a.Direction.UP){let p=h-o,v=S-o;for(;p>=t.startRow;)l.push({startRow:p,startColumn:g,endRow:v,endColumn:f}),p-=o,v-=o}else if(r===a.Direction.RIGHT){let p=g+o,v=f+o;for(;v<=t.endColumn;)l.push({startRow:h,startColumn:p,endRow:S,endColumn:v}),p+=o,v+=o}else if(r===a.Direction.LEFT){let p=g-o,v=f-o;for(;p>=t.startColumn;)l.push({startRow:h,startColumn:p,endRow:S,endColumn:v}),p-=o,v-=o}}}return l}_presetAndCacheData(e,t){const{source:r,target:o}=e,s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!s)throw new Error("No active sheet found");const l=s.getCellMatrix(),d=[];return o.rows.forEach(c=>{const u=[];o.cols.forEach(h=>{u.push(a.Tools.deepClone(l.getValue(c,h)))}),d.push(u)}),this._beforeApplyData=d,this._copyData=this._getCopyData(r,t),this._currentLocation=e,this._shouldDisableSeries(this._copyData)?(this._autoFillService.setDisableApplyType(ae.SERIES,!0),ae.COPY):(this._autoFillService.setDisableApplyType(ae.SERIES,!1),this._getPreferredApplyType(this._copyData))}_fillData(e,t,r){var W,k;const o=[],s=[];let l=!0;r===ae.NO_FORMAT&&(l=!1,r=ae.SERIES);const{source:d,target:c,unitId:u,subUnitId:h}=e;if(!d||!c||t==null)return{undos:o,redos:s};const g=Et(d),S=Et(c),{cols:f,rows:p}=c,{cols:v,rows:C}=d,I=this._copyData;let b;t===a.Direction.DOWN||t===a.Direction.UP?b=C.length:b=v.length;const T=[];if(t===a.Direction.DOWN||t===a.Direction.UP){const U=p.length,B=[];f.forEach((F,L)=>{const z=I[L],X=this._getApplyData(z,b,U,t,r,l);B.push(X)});for(let F=0;F<B[0].length;F++){const L=[];for(let z=0;z<B.length;z++)L.push({s:null,...B[z][F]});T.push(L)}}else{const U=f.length;p.forEach((B,F)=>{const L=I[F],z=this._getApplyData(L,b,U,t,r,l),X=[];for(let Z=0;Z<z.length;Z++)X.push({s:null,...z[Z]});T.push(X)})}let M=[];const y=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getStyles();if(l?(M=this._getMergeApplyData(g,S,t,b),T.forEach(U=>{U.forEach(B=>{B&&y&&y&&(B.s=y.getStyleByCell(B))})})):T.forEach((U,B)=>{U.forEach((F,L)=>{F&&y&&(F.s=y.getStyleByCell(this._beforeApplyData[B][L])||null)})}),r===ae.ONLY_FORMAT&&T.forEach((U,B)=>{U.forEach((F,L)=>{if(F){const z=this._beforeApplyData[B][L]||{};F.f=z.f,F.si=z.si,F.t=z.t,F.v=z.v}})}),l){const U=[],B=(k=(W=this._univerInstanceService.getUniverSheetInstance(u))==null?void 0:W.getSheetBySheetId(h))==null?void 0:k.getMergeData();B&&B.forEach(z=>{a.Rectangle.intersects(z,S)&&U.push(z)});const F={unitId:u,subUnitId:h,ranges:U},L=this._injector.invoke(m.RemoveMergeUndoMutationFactory,F);U.length&&(s.push({id:m.RemoveWorksheetMergeMutation.id,params:F}),o.unshift({id:m.AddWorksheetMergeMutation.id,params:L}))}const P={subUnitId:h,unitId:u,cellValue:xd([c])},x=this._injector.invoke(m.SetRangeValuesUndoMutationFactory,P);s.push({id:m.SetRangeValuesMutation.id,params:P}),o.unshift({id:m.SetRangeValuesMutation.id,params:x});const A=new a.ObjectMatrix;p.forEach((U,B)=>{f.forEach((F,L)=>{T[B][L]&&A.setValue(U,F,T[B][L])})});const N=A.getMatrix(),D={subUnitId:h,unitId:u,cellValue:N},H=this._injector.invoke(m.SetRangeValuesUndoMutationFactory,D);if(this._autoFillService.getActiveHooks().forEach(U=>{var B;(B=U.onBeforeSubmit)==null||B.call(U,e,t,r,N)}),o.unshift({id:m.SetRangeValuesMutation.id,params:H}),s.push({id:m.SetRangeValuesMutation.id,params:D}),M!=null&&M.length){const U=m.getAddMergeMutationRangeByType(M),B={unitId:u,subUnitId:h,ranges:U},F=this._injector.invoke(m.AddMergeUndoMutationFactory,B);o.unshift({id:m.RemoveWorksheetMergeMutation.id,params:F}),s.push({id:m.AddWorksheetMergeMutation.id,params:B})}return{undos:o,redos:s}}_shouldDisableSeries(e){return e.every(t=>Object.keys(t).every(r=>{var o;return((o=t[r])==null?void 0:o.length)===0||[_e.OTHER,_e.FORMULA].includes(r)}))}_getPreferredApplyType(e){return e.every(r=>Object.keys(r).every(o=>{var s,l;return((s=r[o])==null?void 0:s.length)===0||((l=r[o])==null?void 0:l.length)===1&&r[o][0].data.length===1&&_e.NUMBER===o}))?ae.COPY:ae.SERIES}};exports.AutoFillController=gu([Ot(0,a.IUniverInstanceService),Ot(1,a.ICommandService),Ot(2,Tt),Ot(3,Se),Ot(4,w.IRenderManagerService),Ot(5,a.Inject(a.Injector)),Ot(6,a.Inject(exports.SheetsRenderService))],exports.AutoFillController);var Su=Object.defineProperty,fu=Object.getOwnPropertyDescriptor,pu=(n,i,e,t)=>{for(var r=t>1?void 0:t?fu(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Su(i,e,r),r},zi=(n,i)=>(e,t)=>i(e,t,n);exports.CellCustomRenderController=class extends a.Disposable{constructor(e,t,r,o){super();R(this,"_enterActiveRender");this._context=e,this._sheetSkeletonManagerService=t,this._renderManagerService=r,this._permissionService=o,this._initEventBinding()}_initEventBinding(){const e=new a.DisposableCollection,t=this._context.unit,r=o=>{if(e.dispose(),!o)return;const s=this._context.unitId,{skeleton:l}=o,d=this._renderManagerService.getRenderById(s);if(d&&d.mainComponent){const c=d.mainComponent,u=S=>{const{offsetX:f,offsetY:p}=S,v=d.scene,C=t.getActiveSheet();if(!C)return;const I=v.getActiveViewportByCoord(w.Vector2.FromArray([f,p]));if(!I)return;const{scaleX:b,scaleY:T}=v.getAncestorScale(),M={x:I.viewportScrollX,y:I.viewportScrollY},y=l.getCellIndexByOffset(f,p,b,T,M),P=l.worksheet.getMergedCell(y.row,y.column),x={actualRow:P?P.startRow:y.row,actualCol:P?P.startColumn:y.column,mergeCell:P,row:y.row,col:y.column};if(!x||!l)return;const A=C.getCell(x.actualRow,x.actualCol);if(!A)return;const N=A.customRender;if(!(N!=null&&N.length))return;const D=x.actualRow,H=x.actualCol,W=N.sort(a.sortRules),k=C.getSheetId(),U={data:A,style:l.getsStyles().getStyleByCell(A),primaryWithCoord:l.getCellWithCoordByIndex(x.actualRow,x.actualCol),unitId:s,subUnitId:k,row:D,col:H,workbook:t,worksheet:C},B={x:M.x+f/b,y:M.y+p/T},F=W.find(L=>{var z;return(z=L.isHit)==null?void 0:z.call(L,B,U)});if(F)return[F,U]},h=c.onPointerDown$.subscribeEvent(S=>{var p,v,C,I;const f=u(S);if(f){const[b,T]=f,{row:M,col:y,worksheet:P,unitId:x,subUnitId:A}=T;if(!((p=this._permissionService.composePermission([new m.WorkbookEditablePermission(x).id,new m.WorksheetEditPermission(x,A).id]))==null?void 0:p.every(H=>H.value)))return!1;const D=(C=(v=P.getCell(M,y))==null?void 0:v.selectionProtection)==null?void 0:C[0];if((D==null?void 0:D[m.UnitAction.Edit])===!1)return!1;(I=b.onPointerDown)==null||I.call(b,T,S)}}),g=a.fromEventSubject(c.onPointerMove$).pipe(O.throttleTime(30)).subscribe(S=>{var p,v,C,I,b,T;const f=u(S);if(f){const[M,y]=f;this._enterActiveRender?this._enterActiveRender.render!==M&&((v=(p=this._enterActiveRender.render).onPointerLeave)==null||v.call(p,this._enterActiveRender.cellContext,S),this._enterActiveRender={render:M,cellContext:y},(C=M.onPointerEnter)==null||C.call(M,y,S)):(this._enterActiveRender={render:M,cellContext:y},(I=M.onPointerEnter)==null||I.call(M,y,S))}else this._enterActiveRender&&((T=(b=this._enterActiveRender.render).onPointerLeave)==null||T.call(b,this._enterActiveRender.cellContext,S),this._enterActiveRender=null)});h&&e.add(h),g&&e.add(g)}};this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(r)),r(this._sheetSkeletonManagerService.getCurrent()),this.disposeWithMe(e)}};exports.CellCustomRenderController=pu([zi(1,a.Inject(exports.SheetSkeletonManagerService)),zi(2,w.IRenderManagerService),zi(3,a.IPermissionService)],exports.CellCustomRenderController);class hs extends a.Disposable{constructor(){super(...arguments);R(this,"rangesStack",[]);R(this,"selectedRangeWorksheet","")}}var vu=Object.defineProperty,Cu=Object.getOwnPropertyDescriptor,_u=(n,i,e,t)=>{for(var r=t>1?void 0:t?Cu(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&vu(i,e,r),r},Zs=(n,i)=>(e,t)=>i(e,t,n);let En=class{constructor(n,i){R(this,"_current",null);R(this,"_shortcutParam",[]);this._univerInstanceService=n,this._localeService=i}dispose(){this._shortcutParam=[]}getCurrentBySearch(n){return this._getCurrentBySearch(n)}getCurrent(){return this._getCurrentBySearch(this._current)}addOrUpdate(n){const i=this._getCurrentBySearch({unitId:n.unitId,sheetId:n.sheetId,keycode:n.keycode});if(i!=null){const e=this._shortcutParam.indexOf(i);this._shortcutParam.splice(e,1)}return this._shortcutParam.push(n),i}remove(n){if(n==null)return;const i=this._getCurrentBySearch(n);if(i==null)return;const e=this._shortcutParam.indexOf(i);return this._shortcutParam.splice(e,1)[0]}_getCurrentBySearch(n){return n==null?void 0:this._shortcutParam.find(e=>e.unitId===n.unitId&&e.sheetId===n.sheetId&&e.keycode===n.keycode)}};En=_u([Zs(0,a.IUniverInstanceService),Zs(1,a.Inject(a.LocaleService))],En);var Pi=(n=>(n.MergeAll="mergeAll",n.MergeVertical="mergeVertical",n.MergeHorizontal="mergeHorizontal",n))(Pi||{});function It(n,i,e,t,r=!0,o=1,s=!0){let l={...n};t==null&&(t={startRow:0,endRow:e.getRowCount()-1,startColumn:0,endColumn:e.getColumnCount()-1});let d;switch(i){case a.Direction.UP:for(d=n.startRow-o;d>-1&&!e.getRowVisible(d);)d-=1;d>=t.startRow?(l.startRow=d,l.endRow=d):s&&(l.startRow=t.endRow,l.endRow=t.endRow,r&&(l=It(l,a.Direction.LEFT,e,t,!1)));break;case a.Direction.DOWN:for(d=n.endRow+o;d<e.getRowCount()&&!e.getRowVisible(d);)d+=1;d<=t.endRow?(l.startRow=d,l.endRow=d):s&&(l.startRow=t.startRow,l.endRow=t.startRow,r&&(l=It(l,a.Direction.RIGHT,e,t,!1)));break;case a.Direction.LEFT:for(d=n.startColumn-o;d>-1&&!e.getColVisible(d);)d-=1;d>=t.startColumn?(l.startColumn=d,l.endColumn=d):s&&(l.startColumn=t.endColumn,l.endColumn=t.endColumn,r&&(l=It(l,a.Direction.UP,e,t,!1)));break;case a.Direction.RIGHT:for(d=n.endColumn+o;d<e.getColumnCount()&&!e.getColVisible(d);)d+=1;d<=t.endColumn?(l.startColumn=d,l.endColumn=d):s&&(l.startColumn=t.startColumn,l.endColumn=t.startColumn,r&&(l=It(l,a.Direction.DOWN,e,t,!1)));break}return l}function ms(n,i,e){const t={...n},{startRow:r,startColumn:o,endRow:s,endColumn:l}=$n(n,i,e);let d=Un(e,r,o,s,l).hasValue,c=!0,u=!0;for(;u;){if(a.Direction.UP===i){let h=t.startRow-1;for(;h>-1&&!e.getRowVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:g,matrix:S}=Un(e,h,t.startColumn,h,t.endColumn);if(d&&!g&&!c){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue(p=>{f=Math.min(p,f)}),t.startRow=f}else t.startRow=h;if(t.endRow=t.startRow,!d&&g){u=!1;break}d=g,c=!1}}if(a.Direction.DOWN===i){let h=t.endRow+1;for(;h<e.getRowCount()&&!e.getRowVisible(h);)h+=1;if(h===e.getRowCount()){u=!1;break}const{hasValue:g,matrix:S}=Un(e,h,t.startColumn,h,t.endColumn);if(d&&!g&&!c){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((p,v,C)=>{f=Math.max(p+(C.rowSpan||1)-1,f)}),t.endRow=f}else t.endRow=h;if(t.startRow=t.endRow,!d&&g){u=!1;break}d=g,c=!1}}if(a.Direction.LEFT===i){let h=t.startColumn-1;for(;h>-1&&!e.getColVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:g,matrix:S}=Un(e,t.startRow,h,t.endRow,h);if(d&&!g&&!c){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((p,v)=>{f=Math.min(v,f)}),t.startColumn=f}else t.startColumn=h;if(t.endColumn=t.startColumn,!d&&g){u=!1;break}d=g,c=!1}}if(a.Direction.RIGHT===i){let h=t.endColumn+1;for(;h<e.getColumnCount()&&!e.getColVisible(h);)h+=1;if(h===e.getColumnCount()){u=!1;break}const{hasValue:g,matrix:S}=Un(e,t.startRow,h,t.endRow,h);if(d&&!g&&!c){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((p,v,C)=>{f=Math.max(v+(C.colSpan||1)-1,f)}),t.endColumn=f}else t.endColumn=h;if(t.startColumn=t.endColumn,!d&&g){u=!1;break}d=g,c=!1}}}return m.alignToMergedCellsBorders(t,e,!0)}function Ya(n,i,e){return It(n,i,e,void 0,!1,1,!1)}function Iu(n,i,e){const t=ms(n,i,e);return m.alignToMergedCellsBorders(a.Rectangle.union(t,n),e,!0)}function bu(n,i,e){const t=Ya(n,i,e),r={startRow:Math.min(n.startRow,t.startRow),startColumn:Math.min(n.startColumn,t.startColumn),endRow:Math.max(n.endRow,t.endRow),endColumn:Math.max(n.endColumn,t.endColumn)};return m.alignToMergedCellsBorders(a.Rectangle.union(n,r),e)}function Ru(n,i,e,t){const r=a.getReverseDirection(e),o=ms($n(n,r,t),e,t);return e===a.Direction.UP&&o.startRow<=n.startRow?m.alignToMergedCellsBorders({...i,startColumn:n.startColumn,endColumn:n.endColumn},t,!0):e===a.Direction.DOWN&&o.endRow>=n.endRow?m.alignToMergedCellsBorders({...i,startColumn:n.startColumn,endColumn:n.endColumn},t,!0):e===a.Direction.LEFT&&o.startColumn<=n.startColumn?m.alignToMergedCellsBorders({...i,startRow:n.startRow,endRow:n.endRow},t,!0):e===a.Direction.RIGHT&&o.endColumn>=n.endColumn?m.alignToMergedCellsBorders({...i,startRow:n.startRow,endRow:n.endRow},t,!0):a.Rectangle.union(a.Rectangle.clone(i),o)}function Eu(n,i,e){const t=a.getReverseDirection(i),r=$n(n,t,e),o=$n(n,i,e),s=Ya(r,i,e);return m.alignToMergedCellsBorders(a.Rectangle.union(o,s),e,!1)}function Ks(n){return{startRow:0,startColumn:0,endRow:n.getRowCount()-1,endColumn:n.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL}}function $n(n,i,e){let t;switch(i){case a.Direction.UP:t={startRow:n.startRow,startColumn:n.startColumn,endRow:n.startRow,endColumn:n.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.DOWN:t={startRow:n.endRow,startColumn:n.startColumn,endRow:n.endRow,endColumn:n.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.LEFT:t={startRow:n.startRow,startColumn:n.startColumn,endRow:n.endRow,endColumn:n.startColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.RIGHT:t={startRow:n.startRow,startColumn:n.endColumn,endRow:n.endRow,endColumn:n.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;default:throw new Error("Invalid direction")}return m.alignToMergedCellsBorders(t,e,!1)}function Un(n,i,e,t,r){let o=!1;const s=n.getMatrixWithMergedCells(i,e,t,r).forValue((l,d,c)=>{if(wu(c))return o=!0,!1});return{hasValue:o,matrix:s}}function Wo(n,i,e){const t=a.Rectangle.clone(n);if(i==null)return t;switch(e){case a.Direction.UP:case a.Direction.DOWN:t.startColumn=t.endColumn=i.actualColumn;break;case a.Direction.LEFT:case a.Direction.RIGHT:t.startRow=t.endRow=i.actualRow;break}return t}function Tu(n,i,e){var l,d,c,u;const{primary:t,range:r}=n,o=a.Rectangle.clone(r);switch(i){case a.Direction.UP:case a.Direction.DOWN:o.startRow=(l=t==null?void 0:t.startRow)!=null?l:r.startRow,o.endRow=(d=t==null?void 0:t.endRow)!=null?d:r.startRow;break;case a.Direction.LEFT:case a.Direction.RIGHT:o.startColumn=(c=t==null?void 0:t.startColumn)!=null?c:r.startColumn,o.endColumn=(u=t==null?void 0:t.endColumn)!=null?u:r.startColumn;break}const s=$n(o,i,e);switch(i){case a.Direction.DOWN:return r.startRow<s.startRow;case a.Direction.UP:return r.endRow>s.endRow;case a.Direction.LEFT:return s.endColumn<r.endColumn;case a.Direction.RIGHT:return s.startColumn>r.startColumn}}function Ga(n,i){let e=n[0].startRow,t=n[0].endRow;n.forEach(o=>{const{startRow:s,endRow:l}=o;e=Math.min(e,s),t=Math.max(t,l)});const r=new Array(t-e+1).fill(!1);return i.forEach(o=>{const{startRow:s,endRow:l}=o;for(let d=Math.max(s,e);d<=Math.min(l,t);d++)r[d-e]=!0}),n.every(o=>{const{startRow:s,endRow:l}=o;for(let d=s;d<=l;d++)if(!r[d-e])return!1;return!0})}function Za(n,i){let e=n[0].startColumn,t=n[0].endColumn;n.forEach(o=>{const{startColumn:s,endColumn:l}=o;e=Math.min(e,s),t=Math.max(t,l)});const r=new Array(t-e+1).fill(!1);return i.forEach(o=>{const{startColumn:s,endColumn:l}=o;for(let d=Math.max(s,e);d<=Math.min(l,t);d++)r[d-e]=!0}),n.every(o=>{const{startColumn:s,endColumn:l}=o;for(let d=s;d<=l;d++)if(!r[d-e])return!1;return!0})}function gs(n,i){return i?n==="mergeAll"?i.filter(e=>!(e.startRow===e.endRow&&e.startColumn===e.endColumn)):n==="mergeVertical"?i.filter(e=>e.startRow!==e.endRow):n==="mergeHorizontal"?i.filter(e=>e.startColumn!==e.endColumn):i:null}function wu(n){return n.v!==void 0&&n.v!==null&&n.v!==""||n.p!==void 0}var $e=(n=>(n[n.moveStopeOne=0]="moveStopeOne",n[n.moveGap=1]="moveGap",n[n.moveStepPage=2]="moveStepPage",n[n.moveStepEnd=3]="moveStepEnd",n))($e||{});const xe={id:"sheet.command.move-selection",type:a.CommandType.COMMAND,handler:(n,i)=>{if(!i)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{workbook:t,worksheet:r}=e,o=m.getSelectionsService(n,i.fromCurrentSelection).getCurrentLastSelection();if(!o)return!1;const{direction:s,jumpOver:l,extra:d}=i,{range:c,primary:u}=o,h=Wo(c,u,s),g=l===1?ms(h,s,r):It(h,s,r),S=m.getCellAtRowCol(g.startRow,g.startColumn,r);if(a.Rectangle.equals(S,h))return!1;const f=t.getUnitId();n.get(En).remove({unitId:f,sheetId:r.getSheetId(),keycode:E.KeyCode.TAB});const p=[{range:a.Rectangle.clone(S),primary:{startRow:S.startRow,startColumn:S.startColumn,endRow:S.endRow,endColumn:S.endColumn,actualRow:g.startRow,actualColumn:g.startColumn,isMerged:S.isMerged,isMergedMainCell:S.startRow===g.startRow&&S.startColumn===g.startColumn}}];return n.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:t.getUnitId(),subUnitId:r.getSheetId(),selections:p,type:m.SelectionMoveType.MOVE_END,extra:d})}},et={id:"sheet.command.move-selection-enter-tab",type:a.CommandType.COMMAND,handler:(n,i)=>{var U;if(!i)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{workbook:t,worksheet:r}=e,o=m.getSelectionsService(n),{direction:s,keycode:l}=i,d=s===a.Direction.LEFT||s===a.Direction.UP,c=o.getCurrentSelections().concat(),u=c.findIndex(B=>B.primary),h=c[u];if(!h)return!1;const g=d?-1:1,S=u+g!==c.length?c[u+g]:c[0],f=c.findIndex(B=>B===S),p=t.getUnitId(),v=r.getSheetId();if(!h)return!1;const{range:C}=h,I=h.primary;let b=Wo(C,I,s);const T=n.get(En),M=T.getCurrentBySearch({unitId:p,sheetId:v,keycode:E.KeyCode.TAB});let y;const{startRow:P,endRow:x,startColumn:A,endColumn:N}=C,D=d?I.startRow===P&&I.startColumn===A:I.endRow===x&&I.endColumn===N;if(a.Rectangle.equals(C,I)){if(l===E.KeyCode.TAB)M==null&&T.addOrUpdate({unitId:p,sheetId:v,keycode:E.KeyCode.TAB,selection:h});else{const L=M==null?void 0:M.selection;if(L!=null){const{range:z,primary:X}=L;b=Wo(z,X,s)}T.remove({unitId:p,sheetId:v,keycode:E.KeyCode.TAB})}const B=It(b,s,r),F=m.getCellAtRowCol(B.startRow,B.startColumn,r);if(a.Rectangle.equals(F,b))return!1;y={range:a.Rectangle.clone(F),primary:{startRow:F.startRow,startColumn:F.startColumn,endRow:F.endRow,endColumn:F.endColumn,actualRow:B.startRow,actualColumn:B.startColumn,isMerged:F.isMerged,isMergedMainCell:F.startRow===B.startRow&&F.startColumn===B.startColumn}}}else{T.remove({unitId:p,sheetId:v,keycode:E.KeyCode.TAB});const B=a.Tools.deepClone(I),F=D?S.range:It({startRow:B.startRow,startColumn:B.startColumn,endRow:B.endRow,endColumn:B.endColumn},s,r,{startRow:P,endRow:x,startColumn:A,endColumn:N}),L=D&&d,z=L?m.getCellAtRowCol(F.endRow,F.endColumn,r):m.getCellAtRowCol(F.startRow,F.startColumn,r);y={range:D?S.range:a.Rectangle.clone(C),primary:{startRow:z.startRow,startColumn:z.startColumn,endRow:z.endRow,endColumn:z.endColumn,actualRow:L?z.startRow:F.startRow,actualColumn:L?z.startColumn:F.startColumn,isMerged:z.isMerged,isMergedMainCell:z.startRow===F.startRow&&z.startColumn===F.startColumn},style:D?S.style:h.style}}D?(c[u].primary=null,c[f]=y,o.setSelections(p,v,[],m.SelectionMoveType.MOVE_END)):c[u]=y;const H=n.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:p,subUnitId:v,type:m.SelectionMoveType.MOVE_END,selections:c,extra:i.extra}),k=(U=n.get(w.IRenderManagerService).getRenderById(p))==null?void 0:U.with(ve);return k==null||k.refreshSelectionMoveEnd(),H}},He={id:"sheet.command.expand-selection",type:a.CommandType.COMMAND,handler:(n,i)=>{if(!i)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{worksheet:t,unitId:r,subUnitId:o}=e,s=m.getSelectionsService(n).getCurrentLastSelection();if(!s)return!1;const{range:l,primary:d}=s,{jumpOver:c,direction:u,extra:h}=i,S=Tu(s,u,t)?c===1?Ru(l,{...a.Rectangle.clone(d),rangeType:a.RANGE_TYPE.NORMAL},u,t):Eu(l,u,t):c===1?Iu(l,u,t):bu(l,u,t);return S.rangeType=s.range.rangeType,a.Rectangle.equals(S,l)?!1:n.get(a.ICommandService).syncExecuteCommand(m.SetSelectionsOperation.id,{unitId:r,subUnitId:o,type:m.SelectionMoveType.ONLY_SET,selections:[{range:S,primary:d}],extra:h})}},Oi={id:"sheet.command.select-all",type:a.CommandType.COMMAND,handler:async(n,i={expandToGapFirst:!0,loop:!1})=>{const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const t=m.getSelectionsService(n).getCurrentLastSelection();if(!t)return!1;const r=n.get(hs),{worksheet:o,unitId:s,subUnitId:l}=e,d=`${s}|${l}`;d!==r.selectedRangeWorksheet&&(r.rangesStack=[],r.selectedRangeWorksheet=d);const c=o.getMaxRows(),u=o.getMaxColumns(),{expandToGapFirst:h,loop:g}=i,{range:S,primary:f}=t,p=S.endColumn===u-1&&S.endRow===c-1&&S.startRow===0&&S.startColumn===0;r.rangesStack.some(C=>a.Rectangle.equals(C,S))||(r.rangesStack=[],r.rangesStack.push(S));let v;if(p)if(g){if(r.rangesStack.findIndex(I=>a.Rectangle.equals(I,S))!==r.rangesStack.length-1)return!1;v=r.rangesStack[0]}else return!1;else h?(v=m.expandToContinuousRange(S,{left:!0,right:!0,up:!0,down:!0},o),a.Rectangle.equals(v,S)&&(v=Ks(o))):v=Ks(o);return r.rangesStack.some(C=>a.Rectangle.equals(C,v))||r.rangesStack.push(v),n.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:s,subUnitId:l,selections:[{range:v,primary:f}]})}};var yu=Object.defineProperty,Mu=Object.getOwnPropertyDescriptor,Pu=(n,i,e,t)=>{for(var r=t>1?void 0:t?Mu(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&yu(i,e,r),r},Ou=(n,i)=>(e,t)=>i(e,t,n);exports.SheetScrollManagerService=class{constructor(i,e){R(this,"_scrollStateMap",new Map);R(this,"_rawScrollInfo$",new O.BehaviorSubject(null));R(this,"rawScrollInfo$",this._rawScrollInfo$.asObservable());R(this,"validViewportScrollInfo$",new O.BehaviorSubject(null));R(this,"_searchParamForScroll",null);this._context=i,this._sheetSkeletonManagerService=e}dispose(){this._rawScrollInfo$.complete()}setSearchParam(i){this._searchParamForScroll=i}setSearchParamAndRefresh(i){this._searchParamForScroll=i,this._scrollStateNext(i)}getScrollStateByParam(i){return this._getCurrentScroll(i)}getCurrentScrollState(){return this._getCurrentScroll(this._searchParamForScroll)}setScrollInfoAndEmitEvent(i){this._setScrollState(i),this._scrollStateNext(i)}setScrollStateToCurrSheet(i){this._searchParamForScroll!=null&&this._setScrollState({...this._searchParamForScroll,...i})}clear(){this._searchParamForScroll!=null&&this._clearByParamAndNotify(this._searchParamForScroll)}calcViewportScrollFromRowColOffset(i){if(!i)return{viewportScrollX:0,viewportScrollY:0};let{sheetViewStartColumn:e,sheetViewStartRow:t,offsetX:r,offsetY:o}=i;t=t||0,o=o||0;const s=this._sheetSkeletonManagerService.getCurrentSkeleton(),l=(s==null?void 0:s.rowHeightAccumulation[t-1])||0,c=((s==null?void 0:s.columnWidthAccumulation[e-1])||0)+r,u=l+o;return{viewportScrollX:c,viewportScrollY:u}}_setScrollState(i){const{unitId:e,sheetId:t,sheetViewStartColumn:r,sheetViewStartRow:o,offsetX:s,offsetY:l}=i;this._scrollStateMap.has(e)||this._scrollStateMap.set(e,new Map);const d=this._scrollStateMap.get(e),c={sheetViewStartRow:o,sheetViewStartColumn:r,offsetX:s,offsetY:l};d.set(t,c)}_clearByParamAndNotify(i){this._setScrollState({...i,sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0}),this._scrollStateNext(i)}_getCurrentScroll(i){var s;const e={sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0};if(i==null)return e;const{unitId:t,sheetId:r}=i;return((s=this._scrollStateMap.get(t))==null?void 0:s.get(r))||e}_scrollStateNext(i){const e=this._getCurrentScroll(i);this._rawScrollInfo$.next(e)}};exports.SheetScrollManagerService=Pu([Ou(1,a.Inject(exports.SheetSkeletonManagerService))],exports.SheetScrollManagerService);const Fe={id:"sheet.operation.set-scroll",type:a.CommandType.OPERATION,handler:(n,i)=>{if(!i)return!1;const{unitId:e,sheetId:t,offsetX:r,offsetY:o,sheetViewStartColumn:s,sheetViewStartRow:l}=i;return n.get(w.IRenderManagerService).getRenderById(e).with(exports.SheetScrollManagerService).setScrollInfoAndEmitEvent({unitId:e,sheetId:t,offsetX:r,offsetY:o,sheetViewStartRow:l,sheetViewStartColumn:s}),!0}},Tn={id:"sheet.command.set-scroll-relative",type:a.CommandType.COMMAND,handler:async(n,i)=>{const e=n.get(a.ICommandService),t=n.get(a.IUniverInstanceService),r=n.get(w.IRenderManagerService),o=m.getSheetCommandTarget(t);if(!o)return!1;const{unitId:s,subUnitId:l}=o,c=r.getRenderById(s).with(exports.SheetScrollManagerService).getCurrentScrollState(),{offsetX:u=0,offsetY:h=0}=i||{},{sheetViewStartRow:g=0,sheetViewStartColumn:S=0,offsetX:f=0,offsetY:p=0}=c||{};return e.executeCommand(Fe.id,{unitId:s,sheetId:l,sheetViewStartRow:g,sheetViewStartColumn:S,offsetX:f+u,offsetY:p+h})}},je={id:"sheet.command.scroll-view",type:a.CommandType.COMMAND,handler:(n,i)=>{if(!i)return!1;const e=n.get(a.IUniverInstanceService),t=n.get(w.IRenderManagerService),r=m.getSheetCommandTarget(e);if(!r)return!1;const{workbook:o,worksheet:s,unitId:l}=r,c=t.getRenderById(l).with(exports.SheetScrollManagerService).getCurrentScrollState();if(!s)return!1;const{sheetViewStartRow:u,sheetViewStartColumn:h,offsetX:g,offsetY:S}=i,{sheetViewStartColumn:f,sheetViewStartRow:p,offsetX:v,offsetY:C}=c||{},{xSplit:I,ySplit:b}=r.worksheet.getConfig().freeze;return n.get(a.ICommandService).syncExecuteCommand(Fe.id,{unitId:o.getUnitId(),sheetId:s.getSheetId(),sheetViewStartRow:u!=null?u:p!=null?p:0+b,sheetViewStartColumn:h!=null?h:f!=null?f:0+I,offsetX:g!=null?g:v,offsetY:S!=null?S:C})}},Ss={id:"sheet.command.scroll-to-cell",type:a.CommandType.COMMAND,handler:(n,i)=>{const e=n.get(a.IUniverInstanceService);return n.get(w.IRenderManagerService).getRenderById(e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(exports.SheetsScrollRenderController).scrollToRange(i.range,i.forceTop,i.forceLeft)}},xu={id:"sheet.command.scroll-view-reset",type:a.CommandType.COMMAND,handler:async n=>{const i=n.get(a.IUniverInstanceService),e=m.getSheetCommandTarget(i);if(!e)return!1;const{subUnitId:t,unitId:r}=e;return n.get(a.ICommandService).executeCommand(Fe.id,{unitId:r,sheetId:t,sheetViewStartRow:0,sheetViewStartColumn:0})}};var Au=Object.defineProperty,Nu=Object.getOwnPropertyDescriptor,Du=(n,i,e,t)=>{for(var r=t>1?void 0:t?Nu(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Au(i,e,r),r},on=(n,i)=>(e,t)=>i(e,t,n);const Hu=[xe.id,et.id],ku=3;exports.SheetsScrollRenderController=class extends a.Disposable{constructor(i,e,t,r,o,s,l){super(),this._context=i,this._injector=e,this._sheetSkeletonManagerService=t,this._contextService=r,this._commandService=o,this._renderManagerService=s,this._scrollManagerService=l,this._initCommandListener(),this._wheelEventListener(),this._scrollBarEventListener(),this._initSkeletonListener()}_wheelEventListener(){const{scene:i}=this._context;if(!i)return;const e=i.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);e&&this.disposeWithMe(i.onMouseWheel$.subscribeEvent((t,r)=>{if(t.ctrlKey||!this._contextService.getContextValue(a.FOCUSING_SHEET))return;let o=0,s=0;const l=e.limitedScroll();o=t.deltaX,t.shiftKey?o=(t.deltaY||t.deltaX)*ku:s=t.deltaY,this._commandService.executeCommand(Tn.id,{offsetX:o,offsetY:s}),this._context.scene.makeDirty(!0),l&&!l.isLimitedX&&!l.isLimitedY&&(t.preventDefault(),i.getParent().classType===w.RENDER_CLASS_TYPE.SCENE_VIEWER&&r.stopPropagation()),e.isWheelPreventDefaultX&&e.isWheelPreventDefaultY&&t.preventDefault()}))}_scrollBarEventListener(){const{scene:i}=this._context;if(i==null)return;const e=i.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);e&&(this.disposeWithMe(a.toDisposable(this._scrollManagerService.rawScrollInfo$.subscribe(t=>{var S;const r=(S=this._sheetSkeletonManagerService.getCurrent())==null?void 0:S.skeleton;if(!r)return;if(t==null){e.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});return}const{sheetViewStartRow:o,sheetViewStartColumn:s,offsetX:l,offsetY:d}=t,{startX:c,startY:u}=r.getCellWithCoordByIndex(o,s,!1),h=c+l,g=u+d;e.scrollToViewportPos({viewportScrollX:h,viewportScrollY:g})}))),this.disposeWithMe(e.onScrollAfter$.subscribeEvent(t=>{var p;const r=(p=this._sheetSkeletonManagerService.getCurrent())==null?void 0:p.skeleton;if(r==null||t.isTrigger===!1)return;const o=this._getSheetObject();if(r==null||o==null)return;const{viewportScrollX:s,viewportScrollY:l,scrollX:d,scrollY:c}=t,{row:u,column:h,rowOffset:g,columnOffset:S}=r.getDecomposedOffset(s,l),f={sheetViewStartRow:u,sheetViewStartColumn:h,offsetX:S,offsetY:g};this._scrollManagerService.setScrollStateToCurrSheet(f),this._scrollManagerService.validViewportScrollInfo$.next({...f,viewportScrollX:s,viewportScrollY:l,scrollX:d,scrollY:c})})),this.disposeWithMe(e.onScrollByBar$.subscribeEvent(t=>{var g;const r=(g=this._sheetSkeletonManagerService.getCurrent())==null?void 0:g.skeleton;if(r==null||t.isTrigger===!1)return;const o=this._getSheetObject();if(r==null||o==null)return;const{viewportScrollX:s=0,viewportScrollY:l=0}=t,{row:d,column:c,rowOffset:u,columnOffset:h}=r.getDecomposedOffset(s,l);this._commandService.executeCommand(je.id,{sheetViewStartRow:d,sheetViewStartColumn:c,offsetX:h,offsetY:u})})))}_initSkeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeletonBefore$.subscribe(i=>{if(i==null)return;const e={unitId:i.unitId,sheetId:i.sheetId};this._scrollManagerService.setSearchParam(e);const t=this._getSheetObject();if(!t)return;const o=t.scene.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN),s=this._scrollManagerService.getScrollStateByParam(e),{viewportScrollX:l,viewportScrollY:d}=this._scrollManagerService.calcViewportScrollFromRowColOffset(s);o&&(s?(o.viewportScrollX=l,o.viewportScrollY=d):(o.viewportScrollX=0,o.viewportScrollY=0),this._updateSceneSize(i))})))}scrollToRange(i,e,t){let{endRow:r,endColumn:o,startColumn:s,startRow:l}=i;const d=this._getViewportBounding();if(i.rangeType===a.RANGE_TYPE.ROW?(s=0,o=0):i.rangeType===a.RANGE_TYPE.COLUMN&&(l=0,r=0),d&&!e&&!t){const c=d.startRow>r?l:r,u=d.startColumn>o?s:o;return this._scrollToCell(c,u)}else return this._scrollToCell(l,s,e,t)}scrollToCell(i,e){const t=this._context.unit.getActiveSheet(),{ySplit:r,xSplit:o}=t.getFreeze();return this._commandService.syncExecuteCommand(je.id,{sheetViewStartRow:i-r,sheetViewStartColumn:e-o,offsetX:0,offsetY:0})}_initCommandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(Hu.includes(i.id))this._scrollToSelection();else if(i.id===m.ScrollToCellOperation.id){const e=i.params;this.scrollToRange(e)}else if(i.id===He.id){const e=i.params;this._scrollToSelectionForExpand(e)}else i.id===m.SetSelectionsOperation.id&&i.params.reveal&&this._scrollToSelection()}))}_scrollToSelectionForExpand(i){setTimeout(()=>{const e=this._getSelectionsService().getCurrentLastSelection();if(e==null)return;const{startRow:t,startColumn:r,endRow:o,endColumn:s}=e.range,l=this._getViewportBounding();if(l==null)return;const{startRow:d,startColumn:c,endRow:u,endColumn:h}=l;let g=0,S=0;t>d?g=o:o<u?g=t:g=d,r>c?S=s:s<h?S=r:S=c,i.direction===a.Direction.DOWN?g=o:i.direction===a.Direction.UP?g=t:i.direction===a.Direction.RIGHT?S=s:i.direction===a.Direction.LEFT&&(S=r),this._scrollToCell(g,S)},0)}_getFreeze(){var e;const i=(e=this._sheetSkeletonManagerService.getCurrent())==null?void 0:e.skeleton.getWorksheetConfig();if(i!=null)return i.freeze}_updateSceneSize(i){var g;if(i==null)return;const{unitId:e}=this._context,{skeleton:t}=i,r=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.scene;if(t==null||r==null)return;const{rowTotalHeight:o,columnTotalWidth:s,rowHeaderWidthAndMarginLeft:l,columnHeaderHeightAndMarginTop:d}=t,u=this._context.unit.getActiveSheet();if(!u)return;const h=u.getZoomRatio()||1;r==null||r.setScaleValue(h,h),r==null||r.transformByState({width:l+s,height:d+o})}_getSheetObject(){return Ye(this._context.unit,this._context)}_scrollToSelectionByDirection(i){const e=this._getViewportBounding();if(e==null)return!1;const{startRow:t,startColumn:r,endRow:o,endColumn:s}=e;let l=0,d=0;const{startRow:c,startColumn:u,endRow:h,endColumn:g}=i;c>=t&&(l=h),h<=o&&(l=c),u>=r&&(d=g),g<=s&&(d=u),this._scrollToCell(l,d)}_scrollToSelection(i=!0){var c;const e=this._getSelectionsService().getCurrentLastSelection();if(!e)return;const{startRow:t,startColumn:r,actualRow:o,actualColumn:s}=(c=e.primary)!=null?c:e.range,l=i&&o!=null?o:t,d=i&&s!=null?s:r;this._scrollToCell(l,d)}_getSelectionsService(){return m.getSelectionsService(this._injector)}_getViewportBounding(){var o,s;const i=(o=this._getSheetObject())==null?void 0:o.scene;if(i==null)return;const e=i.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e==null)return;const t=(s=this._sheetSkeletonManagerService.getCurrent())==null?void 0:s.skeleton;if(t==null)return;const r=e.calcViewportInfo();return t.getRangeByViewBound(r.viewBound)}_scrollToCell(i,e,t=!1,r=!1){var N,D,H,W;const{rowHeightAccumulation:o,columnWidthAccumulation:s}=(D=(N=this._sheetSkeletonManagerService.getCurrent())==null?void 0:N.skeleton)!=null?D:{};if(o==null||s==null)return!1;const l=(H=this._getSheetObject())==null?void 0:H.scene;if(l==null)return!1;const d=l.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(d==null)return!1;const c=(W=this._sheetSkeletonManagerService.getCurrent())==null?void 0:W.skeleton;if(c==null)return!1;const u=this._context.unit.getActiveSheet();if(!u)return!1;i=a.Tools.clamp(i,0,o.length-1),e=a.Tools.clamp(e,0,s.length-1);const{startColumn:h,startRow:g,ySplit:S,xSplit:f}=u.getFreeze(),p=this._getViewportBounding();if(p==null)return!1;const{startRow:v,startColumn:C,endRow:I,endColumn:b}=p;c.getVisibleRangeByViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);let T,M;if(i>=g&&e>=h-S&&(i<=v&&(T=i,t=!0),i>=I)){const k=o[i]-d.height;for(let U=v;U<=i&&(T=U+1,!(o[U]>=k));U++);}if(e>=h&&i>=g-S&&(e<=C&&(M=e,r=!0),e>=b)){const k=s[e]-d.width;for(let U=C;U<=e&&(M=U+1,!(s[U]>=k));U++);}if(T===void 0&&M===void 0)return!1;let{offsetX:y,offsetY:P,sheetViewStartRow:x,sheetViewStartColumn:A}=this._scrollManagerService.getCurrentScrollState()||{};if(T=T?Math.min(T,i):x+S,M=M?Math.min(M,e):A+f,r){y=0,M=e;const k=c.getHiddenColumnsInRange({startColumn:M-f,endColumn:M});M=M-k.length}if(t){P=0,T=i;const k=c.getHiddenRowsInRange({startRow:T-S,endRow:T});T=T-k.length}return this._commandService.syncExecuteCommand(je.id,{sheetViewStartRow:Math.max(0,T-S),sheetViewStartColumn:Math.max(0,M-f),offsetX:y,offsetY:P})}};exports.SheetsScrollRenderController=Du([on(1,a.Inject(a.Injector)),on(2,a.Inject(exports.SheetSkeletonManagerService)),on(3,a.IContextService),on(4,a.ICommandService),on(5,w.IRenderManagerService),on(6,a.Inject(exports.SheetScrollManagerService))],exports.SheetsScrollRenderController);const fs={id:"sheet.operation.scroll-to-range",type:a.CommandType.OPERATION,handler:(n,i)=>{if(!i)return!1;const e=n.get(a.IUniverInstanceService);return n.get(w.IRenderManagerService).getRenderById(e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(exports.SheetsScrollRenderController).scrollToRange(i.range,i.forceTop,i.forceLeft)}};class Ka{constructor(){R(this,"_state",null);R(this,"_rect",null);R(this,"_state$",new O.BehaviorSubject(null));R(this,"state$",this._state$.asObservable());R(this,"_rect$",new O.BehaviorSubject(null));R(this,"rect$",this._rect$.asObservable());R(this,"_focus",!1);R(this,"_focus$",new O.BehaviorSubject(this._focus));R(this,"focus$",this._focus$.asObservable())}dispose(){this._state$.complete(),this._state=null,this._rect$.complete(),this._rect=null}setState(i){this._state=i,this._refresh(i)}getRect(){return this._rect}setRect(i){this._rect=i,this._rect$.next(i)}getState(){return this._state}setFocus(i=!1){this._focus=i,this._focus$.next(i)}_refresh(i){this._state$.next(i)}}const hr=a.createIdentifier("univer.sheet-cell-editor-manager.service"),Vu="36",Wu="univer-sheet-container",qa={sheetFooterBarHeight:Vu,sheetContainer:Wu};var Uu=Object.defineProperty,Lu=Object.getOwnPropertyDescriptor,Bu=(n,i,e,t)=>{for(var r=t>1?void 0:t?Lu(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Uu(i,e,r),r},sn=(n,i)=>(e,t)=>i(e,t,n);const qs=5,Qs=2;exports.SheetCellEditorResizeService=class extends a.Disposable{constructor(i,e,t,r,o,s,l){super(),this._context=i,this._layoutService=e,this._cellEditorManagerService=t,this._editorBridgeService=r,this._renderManagerService=o,this._sheetSkeletonManagerService=s,this._univerInstanceService=l}fitTextSize(i){var A,N,D,H;const e=this._editorBridgeService.getEditCellState();if(!e)return;const{position:t,documentLayoutObject:r,canvasOffset:o,scaleX:s,scaleY:l}=e,{startX:d,startY:c,endX:u,endY:h}=t,g=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);if(g==null)return;const S=this._getEditorSkeleton();if(!S)return;const f=this._predictingSize(t,o,S,r,s,l);if(!f)return;let{actualWidth:p,actualHeight:v}=f;const{verticalAlign:C,horizontalAlign:I,paddingData:b,fill:T}=r;p=p+((A=b.l)!=null?A:0)+((N=b.r)!=null?N:0),v=v+((D=b.t)!=null?D:0)+((H=b.b)!=null?H:0);let M=u-d,y=h-c;M<p&&(M=Math.ceil(p)),y<v&&(y=Math.ceil(v));let P=0;C===a.VerticalAlign.MIDDLE?P=(y-v)/2/l:C===a.VerticalAlign.TOP?P=b.t||0:P=(y-v)/l;let x=0;I===a.HorizontalAlign.CENTER?x=(M-p)/2/s:I===a.HorizontalAlign.RIGHT?x=(M-p)/s:x=b.l||0,P=P<(b.t||0)?b.t||0:P,x=x<(b.l||0)?b.l||0:x,g.updateDocumentDataMargin({t:P,l:x}),S.calculate(),this._editAreaProcessing(M,y,t,o,T,s,l,I,i)}_predictingSize(i,e,t,r,o=1,s=1){const{startX:l,endX:d}=i,{textRotation:c,wrapStrategy:u,paddingData:h}=r,g=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC),{vertexAngle:S}=w.convertTextRotation(c);if(u===a.WrapStrategy.WRAP&&S===0){g==null||g.updateDocumentDataPageSize(d-l),g==null||g.updateDocumentDataMargin({l:h.l,t:h.t}),t.calculate();const{actualWidth:C,actualHeight:I}=t.getActualSize();return{actualWidth:C*o,actualHeight:I*s}}const f=this._getEditorMaxSize(i,e,r.horizontalAlign);if(!f)return;g==null||g.updateDocumentDataPageSize(f.width/o),t.calculate();const p=t.getActualSize();let v=d-l;return v<p.actualWidth*o+qs*o&&(v=p.actualWidth*o+qs*o),g==null||g.updateDocumentDataPageSize(v/o),g==null||g.updateDocumentRenderConfig({horizontalAlign:a.HorizontalAlign.UNSPECIFIED,cellValueType:void 0}),{actualWidth:p.actualWidth*o,actualHeight:p.actualHeight*s}}_getEditorMaxSize(i,e,t){if(this._getEditorObject()==null)return;function o(I){return Number.parseInt(I.replace("px",""))}const l=this._context.engine.getCanvasElement(),d=l.getBoundingClientRect(),c=o(l.style.width),{width:u}=d,h=u/c,{startX:g,startY:S,endX:f}=i,p=this._context.engine.width,v=document.body.clientHeight-S-Number.parseFloat(qa.sheetFooterBarHeight)-e.top-Qs*2;let C=u-g;if(t===a.HorizontalAlign.CENTER){const I=p-f,b=g;C=f-g+Math.min(b,I)*2}else t===a.HorizontalAlign.RIGHT&&(C=f);return{height:v,width:C-Qs,scaleAdjust:h}}_editAreaProcessing(i,e,t,r,o,s=1,l=1,d,c){var k;const u=this._getEditorObject();if(u==null)return;const g=this._context.engine.getCanvasElement();let{startX:S,startY:f}=t;const{document:p,scene:v,engine:C}=u,I=v.getViewport(J.VIEWPORT_KEY.VIEW_MAIN),b=this._getEditorMaxSize(t,r,d),{height:T,width:M,scaleAdjust:y}=b;let P=e,x=I==null?void 0:I.getScrollBar();P>T?(x==null?I&&new w.ScrollBar(I,{enableHorizontal:!1,barSize:8}):I==null||I.resetCanvasSizeAndUpdateScroll(),I==null||I.scrollToViewportPos({viewportScrollY:P-T}),P=T):(x=null,(k=I==null?void 0:I.getScrollBar())==null||k.dispose()),i+=(x==null?void 0:x.barSize)||0,i>M&&(i=M),this._addBackground(v,i/s,e/l,o);const{scaleX:A,scaleY:N}=v.getPrecisionScale();v.transformByState({width:i*y/s,height:e*y/l,scaleX:s*y,scaleY:l*y}),p.resize(i*y/s,e*y/l),setTimeout(()=>{C.resizeBySize(w.fixLineWidthByScale(i,A),w.fixLineWidthByScale(P,N)),c==null||c()},0);const D=this._layoutService.getContentElement().getBoundingClientRect(),H=g.getBoundingClientRect();S=S*y+(H.left-D.left),f=f*y+(H.top-D.top);const W=t.endX-t.startX;d===a.HorizontalAlign.RIGHT?S+=(W-i)*y:d===a.HorizontalAlign.CENTER&&(S+=(W-i*y)/2),this._cellEditorManagerService.setState({startX:S,startY:f,endX:i*y+S,endY:P*y+f,show:!0})}_addBackground(i,e,t,r){const o="_backgroundRectHelperColor_",s=i.getObject(o);s==null&&r==null||(s==null?i.addObjects([new w.Rect(o,{width:e,height:t,fill:r,evented:!1})],J.DOCS_COMPONENT_MAIN_LAYER_INDEX):r==null?s.dispose():(s.setProps({fill:r}),s.transformByState({width:e,height:t})))}resizeCellEditor(i){var y;const e=this._cellEditorManagerService.getState();if(!e||!this._editorBridgeService.isVisible().visible)return;this._editorBridgeService.refreshEditCellPosition(!0);const t=this._editorBridgeService.getEditCellState();if(!t)return;const r=(y=this._sheetSkeletonManagerService.getWorksheetSkeleton(t.sheetId))==null?void 0:y.skeleton;if(!r)return;const{row:o,column:s,scaleX:l,scaleY:d,position:c,canvasOffset:u,documentLayoutObject:h}=t,{horizontalAlign:g}=h,S=this._getEditorMaxSize(c,u,g);if(!S)return;const{height:f,width:p,scaleAdjust:v}=S,C=r.getCellWithCoordByIndex(o,s),I=Math.min((C.mergeInfo.endY-C.mergeInfo.startY)*d,f)*v,b=Math.min((C.mergeInfo.endX-C.mergeInfo.startX)*l,p)*v,T=e.endY-e.startY,M=e.endX-e.startX;if(T!==I||M!==b){if(this._editorBridgeService.refreshEditCellPosition(!0),!this._getEditorSkeleton())return;this.fitTextSize(i)}}_getEditorObject(){return Ei(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}_getEditorSkeleton(){var i;return(i=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:i.with(be.DocSkeletonManagerService).getSkeleton()}};exports.SheetCellEditorResizeService=Bu([sn(1,E.ILayoutService),sn(2,hr),sn(3,Se),sn(4,w.IRenderManagerService),sn(5,a.Inject(exports.SheetSkeletonManagerService)),sn(6,a.IUniverInstanceService)],exports.SheetCellEditorResizeService);function ps(n){return n.getContextValue(a.FOCUSING_SHEET)}function le(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function Qa(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function Fu(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function ju(n){return n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function Ja(n){return n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function zu(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.EDITOR_ACTIVATED)&&n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function er(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&!n.getContextValue(a.FOCUSING_EDITOR_STANDALONE)}const $a=[E.KeyCode.ARROW_DOWN,E.KeyCode.ARROW_UP,E.KeyCode.ARROW_LEFT,E.KeyCode.ARROW_RIGHT],Xu=[E.KeyCode.ENTER,E.KeyCode.TAB,...$a];function el(){const n=[];for(const i of $a)n.push({id:Xt.id,binding:i,preconditions:e=>er(e),staticParameters:{visible:!1,eventType:w.DeviceInputEventType.Keyboard,keycode:i,isShift:!1}}),n.push({id:Xt.id,binding:i|E.MetaKeys.SHIFT,preconditions:e=>er(e),staticParameters:{visible:!1,eventType:w.DeviceInputEventType.Keyboard,keycode:i,isShift:!0}});return n}const tl={id:ur.id,binding:E.KeyCode.F2,description:"shortcut.sheet.start-editing",group:"4_sheet-edit",preconditions:le,staticParameters:{visible:!0,eventType:w.DeviceInputEventType.Keyboard,keycode:E.KeyCode.F2}},nl={id:Te.id,binding:E.KeyCode.ENTER,description:"shortcut.sheet.toggle-editing",group:"4_sheet-edit",preconditions:n=>er(n),staticParameters:{visible:!1,eventType:w.DeviceInputEventType.Keyboard,keycode:E.KeyCode.ENTER}},rl={id:Te.id,binding:E.KeyCode.TAB,preconditions:n=>er(n),staticParameters:{visible:!1,eventType:w.DeviceInputEventType.Keyboard,keycode:E.KeyCode.TAB}},il={id:Te.id,binding:E.KeyCode.ESC,description:"shortcut.sheet.abort-editing",group:"4_sheet-edit",preconditions:n=>er(n),staticParameters:{visible:!1,eventType:w.DeviceInputEventType.Keyboard,keycode:E.KeyCode.ESC}},ol={id:J.BreakLineCommand.id,description:"shortcut.sheet.break-line",group:"4_sheet-edit",preconditions:n=>Fu(n),binding:E.KeyCode.ENTER|E.MetaKeys.ALT},sl={id:J.DeleteLeftCommand.id,preconditions:n=>ju(n)||Ja(n),binding:E.KeyCode.BACKSPACE},al={id:Te.id,description:"shortcut.sheet.delete-and-start-editing",group:"4_sheet-edit",preconditions:n=>le(n)&&!Ja(n),binding:E.KeyCode.BACKSPACE,staticParameters:{visible:!0,eventType:w.DeviceInputEventType.Keyboard,keycode:E.KeyCode.BACKSPACE}};function Yu(n){return n.startsWith("'")}function Gu(n){return n.slice(1)}const Zu={"0":"0","1":"1","2":"2","3":"3","4":"4","5":"5","6":"6","7":"7","8":"8","9":"9",A:"A",B:"B",C:"C",D:"D",E:"E",F:"F",G:"G",H:"H",I:"I",J:"J",K:"K",L:"L",M:"M",N:"N",O:"O",P:"P",Q:"Q",R:"R",S:"S",T:"T",U:"U",V:"V",W:"W",X:"X",Y:"Y",Z:"Z",a:"a",b:"b",c:"c",d:"d",e:"e",f:"f",g:"g",h:"h",i:"i",j:"j",k:"k",l:"l",m:"m",n:"n",o:"o",p:"p",q:"q",r:"r",s:"s",t:"t",u:"u",v:"v",w:"w",x:"x",y:"y",z:"z","%":"%","-":"-",".":".",":":":","/":"/","+":"+","@":"@","&":"&","*":"*","#":"#","=":"=",">":">","<":"<","$":"$",""":'"',"'":"'","(":"(",")":")"," ":" ",",":",","!":"!","?":"?",";":";","[":"[","]":"]","{":"{","}":"}"},Uo={true:"TRUE",false:"FALSE"};function Ku(n){return[a.LocaleType.ZH_CN,a.LocaleType.ZH_TW].includes(n)}function qu(n,i,e,t){let r=n;if(Ku(e)){if(n.startsWith("'")||n.startsWith("'"))return`'${n.slice(1)}`;r=Qu(r)}if(r.startsWith("="))return Ju(n,r,i,t);const o=r.toLowerCase();return Uo[o]?Uo[o]:a.numfmt.parseValue(r)==null?n:r}function Qu(n){const i=/['"].*?['"]/g,e=[],t=n.split(i);n.replace(i,o=>(e.push(o),""));let r=t.join("").split("").map(th).join("");return e.forEach((o,s)=>{r=r.slice(0,s*2)+o+r.slice((s+1)*2)}),r}function Ju(n,i,e,t){const r=e.sequenceNodesBuilder(i);if(!r)return n;let o=i,s=0;return r.forEach((l,d)=>{if(typeof l=="object"){const c=l.token;if(Uo[c.toLowerCase()]){const u=l.startIndex+s+1,h=l.endIndex+s+2;o=an(c.toLocaleUpperCase(),o,u,h)}else if(l.nodeType===G.sequenceNodeType.FUNCTION&&$u(c,t,r,d)||l.nodeType===G.sequenceNodeType.REFERENCE){const u=c.indexOf("!");if(u>-1){const h=c.substring(u+1),g=l.startIndex+s+(u+1)+1,S=l.endIndex+s+2;o=an(h.toLocaleUpperCase(),o,g,S)}else{const h=l.startIndex+s+1,g=l.endIndex+s+2;o=an(c.toLocaleUpperCase(),o,h,g)}}else if(c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'")){const u=l.startIndex+s+2,h=l.endIndex+s+1;o=an(n.slice(u,h),o,u,h)}else if(l.nodeType!==G.sequenceNodeType.ARRAY){const u=a.numfmt.parseValue(c);if(u==null){const h=l.startIndex+s+1,g=l.endIndex+s+2;o=an(n.slice(h,g),o,h,g)}else if(typeof u.v=="number"&&(u.z===void 0||!a.numfmt.isDate(u.z))){const h=`${u.v}`,g=l.startIndex+s+1,S=l.endIndex+s+2,{processedString:f,offset:p}=nh(c,h);o=an(f,o,g,S),s+=p}}}}),o}function $u(n,i,e,t){const r=i.getDescriptions();return e[t+1]!==G.matchToken.OPEN_BRACKET?!1:r.get(eh(n).toLocaleUpperCase())!==void 0}function eh(n){const i=/^@+/;return n.replace(i,"")}function th(n){return Zu[n]||n}function an(n,i,e,t){return i.substring(0,e)+n+i.substring(t)}function nh(n,i){var s,l;const e=((s=n.match(/^\s*/))==null?void 0:s[0])||"",t=((l=n.match(/\s*$/))==null?void 0:l[0])||"",r=e+i+t,o=r.length-n.length;return{processedString:r,offset:o}}const ll="range_selector",cl=n=>n.includes(ll);var rh=Object.defineProperty,ih=Object.getOwnPropertyDescriptor,oh=(n,i,e,t)=>{for(var r=t>1?void 0:t?ih(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&rh(i,e,r),r},ye=(n,i)=>(e,t)=>i(e,t,n);const Js=-1e3;exports.EditingRenderController=class extends a.Disposable{constructor(e,t,r,o,s,l,d,c,u,h,g,S,f,p,v,C){super();R(this,"_cursorChange",0);R(this,"_isUnitEditing",!1);R(this,"_workbookSelections");R(this,"_d");R(this,"_cursorTimeout");this._context=e,this._undoRedoService=r,this._contextService=o,this._renderManagerService=s,this._editorBridgeService=l,this._cellEditorManagerService=d,this._lexerTreeBuilder=c,this._functionService=u,this._textSelectionManagerService=h,this._commandService=g,this._localService=S,this._editorService=f,this._sheetCellEditorResizeService=p,this._univerInstanceService=v,this._sheetInterceptorService=C,this._workbookSelections=t.getWorkbookSelections(this._context.unitId),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(I=>{(I==null?void 0:I.getUnitId())===this._context.unitId?this._d=this._init():(this._disposeCurrent(),this._isUnitEditing&&(this._handleEditorInvisible({visible:!1,eventType:w.DeviceInputEventType.Keyboard,keycode:E.KeyCode.ESC,unitId:this._context.unitId}),this._isUnitEditing=!1))})),this._initEditorVisibilityListener()}dispose(){super.dispose(),this._disposeCurrent()}_disposeCurrent(){var e;(e=this._d)==null||e.dispose(),this._d=null}_init(){const e=new a.DisposableCollection;return this._subscribeToCurrentCell(e),this._initialCursorSync(e),this._listenEditorFocus(e),this._commandExecutedListener(e),this._initSkeletonListener(e),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{clearTimeout(this._cursorTimeout)})),this._cursorTimeout=setTimeout(()=>{this._cursorStateListener(e)},1e3),e}_initEditorVisibilityListener(){this.disposeWithMe(this._editorBridgeService.visible$.pipe(O.distinctUntilChanged((e,t)=>e.visible===t.visible)).subscribe(e=>{(e.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY||e.unitId===this._context.unitId)&&e.visible?(this._isUnitEditing=!0,this._handleEditorVisible(e)):this._isUnitEditing&&(this._handleEditorInvisible(e),this._isUnitEditing=!1)}))}_listenEditorFocus(e){const t=this._getEditorObject();t&&e.add(t.document.onPointerDown$.subscribeEvent(()=>{if(this._isUnitEditing&&this._editorBridgeService.isVisible()){const r=this._editorBridgeService.getEditCellState(),o=this._editorBridgeService.getCurrentEditorId();if(!r||!o)return;this._sheetCellEditorResizeService.fitTextSize()}}))}_initialCursorSync(e){e.add(this._cellEditorManagerService.focus$.pipe(O.filter(t=>!!t)).subscribe(()=>{var r;const t=(r=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_DOC))==null?void 0:r.with(J.DocSelectionRenderService);t&&t.sync()}))}_initSkeletonListener(e){const t=new Set(m.COMMAND_LISTENER_SKELETON_CHANGE);t.delete(m.SetWorksheetActiveOperation.id),e.add(this._commandService.onCommandExecuted(r=>{t.has(r.id)&&this._sheetCellEditorResizeService.resizeCellEditor(()=>{this._textSelectionManagerService.refreshSelection({unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})})}))}_subscribeToCurrentCell(e){e.add(this._editorBridgeService.currentEditCellState$.subscribe(t=>{var I,b;if(t==null||this._editorBridgeService.isForceKeepVisible())return;const r=this._editorBridgeService.getEditCellState();if(r==null)return;const{position:o,documentLayoutObject:s,scaleX:l,editorUnitId:d}=r;if(this._contextService.getContextValue(a.FOCUSING_EDITOR_STANDALONE))return;const c=this._getDocumentDataModel();if(c==null)return;const{startX:u,endX:h}=o,{textRotation:g,wrapStrategy:S,documentModel:f}=s,{vertexAngle:p}=w.convertTextRotation(g);S===a.WrapStrategy.WRAP&&p===0&&c.updateDocumentDataPageSize((h-u)/l),this._commandService.syncExecuteCommand(J.ReplaceSnapshotCommand.id,{unitId:d,snapshot:f.getSnapshot()}),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!0),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});const v=(I=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:I.with(J.DocSelectionRenderService),C=(b=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:b.with(J.DocSelectionRenderService);(v!=null&&v.canFocusing||C!=null&&C.canFocusing)&&(this._univerInstanceService.setCurrentUnitForType(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),v==null||v.activate(Js,Js,!0))}))}_commandExecutedListener(e){e.add(this._commandService.onCommandExecuted(r=>{if(r.id===be.RichTextEditingMutation.id){const o=r.params,{unitId:s}=o;if(!this._isCurrentSheetFocused()||cl(s)||(this._editorBridgeService.changeEditorDirty(!0),!this._editorBridgeService.isVisible().visible))return;s===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._sheetCellEditorResizeService.fitTextSize()}}));const t=[Xt.id];e.add(this._commandService.onCommandExecuted(r=>{if(t.includes(r.id)){const o=r.params,{keycode:s,isShift:l}=o;if(s!=null&&(this._cursorChange===2||this._contextService.getContextValue(a.FOCUSING_FX_BAR_EDITOR))){this._moveInEditor(s,l);return}this._editorBridgeService.changeVisible(o)}r.id===ur.id&&(this._cursorChange=2)}))}_handleEditorVisible(e){var S,f,p;const{eventType:t,keycode:r}=e;this._cursorChange=t===w.DeviceInputEventType.PointerDown||t===w.DeviceInputEventType.Dblclick?2:1;const o=this._editorBridgeService.getEditLocation();if(o==null)return;this._commandService.syncExecuteCommand(fs.id,{range:{startRow:o.row,startColumn:o.column,endRow:o.row,endColumn:o.column}}),this._editorBridgeService.refreshEditCellPosition(!1);const{unitId:s,isInArrayFormulaRange:l=!1}=o,d=this._getEditorObject();if(d==null)return;const{document:c,scene:u}=d;this._contextService.setContextValue(a.EDITOR_ACTIVATED,!0);const h=this._getDocumentDataModel(),g=this._getEditorSkeleton(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(!(!g||!h)){if(this._sheetCellEditorResizeService.fitTextSize(()=>{const v=u.getViewport(J.VIEWPORT_KEY.VIEW_MAIN);v==null||v.scrollToViewportPos({viewportScrollX:Number.POSITIVE_INFINITY,viewportScrollY:Number.POSITIVE_INFINITY})}),t===w.DeviceInputEventType.Keyboard&&r===E.KeyCode.F2){c.makeDirty(),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}]);const v=((f=(S=h.getBody())==null?void 0:S.dataStream.length)!=null?f:2)-2;this._textSelectionManagerService.replaceDocRanges([{startOffset:v,endOffset:v}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})}else if(t===w.DeviceInputEventType.Keyboard||t===w.DeviceInputEventType.Dblclick&&l)this._emptyDocumentDataModel(h.getSnapshot().documentStyle,!!l),c.makeDirty(),(r===E.KeyCode.BACKSPACE||t===w.DeviceInputEventType.Dblclick)&&(g.calculate(),this._editorBridgeService.changeEditorDirty(!0)),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});else if(t===w.DeviceInputEventType.Dblclick){if(this._contextService.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA))return;const v=h.getBody().dataStream.length-2||0;this._textSelectionManagerService.replaceDocRanges([{startOffset:v,endOffset:v}])}(p=this._renderManagerService.getRenderById(s))==null||p.scene.resetCursor()}}async _handleEditorInvisible(e){const t=this._editorBridgeService.getEditCellState(),r=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),o=a.Tools.deepClone(r==null?void 0:r.getSnapshot());let{keycode:s}=e;if(this._cursorChange=0,this._exitInput(e),t==null)return;this._editorBridgeService.getEditorDirty()===!1&&(s=E.KeyCode.ESC);const c=this._context.unit.getActiveSheet(),u=this._context.unitId,h=c.getSheetId(),{unitId:g,sheetId:S}=t;if(u===g&&S!==h&&await this._commandService.executeCommand(m.SetWorksheetActivateCommand.id,{subUnitId:S,unitId:g}),s===E.KeyCode.ESC){this._editorBridgeService.isForceKeepVisible()&&this._editorBridgeService.disableForceKeepVisible();const f=this._workbookSelections.getCurrentSelections();f&&(this._contextService.setContextValue(m.REF_SELECTIONS_ENABLED,!1),this._commandService.syncExecuteCommand(m.SetSelectionsOperation.id,{unitId:this._context.unit.getUnitId(),subUnitId:S,selections:f}));return}o&&await this._submitCellData(o),this._moveCursor(s)}_getEditorObject(){return Ei(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}submitCellData(e){return this._submitCellData(e.getSnapshot())}async _submitCellData(e){const t=this._editorBridgeService.getEditCellState();if(t==null)return;const{unitId:r,sheetId:o,row:s,column:l}=t,d=this._context.unit;let c=d.getActiveSheet();if(!d.getSheetBySheetId(o))return;c=d.getActiveSheet();const h=sh({...c.getCellRaw(s,l)||{}},e,this._lexerTreeBuilder,this._localService,this._functionService,d.getStyles());if(!h)return;const g=await this._sheetInterceptorService.onWriteCell(d,c,s,l,h);g!==c.getCellRaw(s,l)&&this._commandService.executeCommand(m.SetRangeValuesCommand.id,{subUnitId:o,unitId:r,range:{startRow:s,startColumn:l,endRow:s,endColumn:l},value:g})}_exitInput(e){var o;this._contextService.setContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA,!1),this._contextService.setContextValue(a.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!1),this._contextService.setContextValue(a.FOCUSING_FX_BAR_EDITOR,!1),this._cellEditorManagerService.setState({show:e.visible});const t=this._getEditorObject();(o=t==null?void 0:t.scene.getViewport(J.VIEWPORT_KEY.VIEW_MAIN))==null||o.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});const r=this._editorBridgeService.getCurrentEditorId();r==null||!this._editorService.isSheetEditor(r)||(this._undoRedoService.clearUndoRedo(r),this._undoRedoService.clearUndoRedo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))}_moveCursor(e){if(e==null||!Xu.includes(e))return;let t=a.Direction.LEFT;switch(e){case E.KeyCode.ENTER:t=a.Direction.DOWN;break;case E.KeyCode.TAB:t=a.Direction.RIGHT;break;case E.KeyCode.ARROW_DOWN:t=a.Direction.DOWN;break;case E.KeyCode.ARROW_UP:t=a.Direction.UP;break;case E.KeyCode.ARROW_LEFT:t=a.Direction.LEFT;break;case E.KeyCode.ARROW_RIGHT:t=a.Direction.RIGHT;break}e===E.KeyCode.ENTER||e===E.KeyCode.TAB?this._commandService.executeCommand(et.id,{keycode:e,direction:t}):this._commandService.executeCommand(xe.id,{direction:t})}_cursorStateListener(e){const t=this._getEditorObject();if(!(t!=null&&t.document))return;const{document:r}=t;e.add(a.toDisposable(r.onPointerDown$.subscribeEvent(()=>{this._cursorChange===1&&(this._cursorChange=2)})))}_moveInEditor(e,t){let r=a.Direction.LEFT;e===E.KeyCode.ARROW_DOWN?r=a.Direction.DOWN:e===E.KeyCode.ARROW_UP?r=a.Direction.UP:e===E.KeyCode.ARROW_RIGHT&&(r=a.Direction.RIGHT),t?this._commandService.executeCommand(J.MoveSelectionOperation.id,{direction:r}):this._commandService.executeCommand(J.MoveCursorOperation.id,{direction:r})}_getDocumentDataModel(){return this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC)}_isCurrentSheetFocused(){var e;return((e=this._univerInstanceService.getFocusedUnit())==null?void 0:e.getUnitId())===this._context.unitId}_getEditorSkeleton(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(be.DocSkeletonManagerService).getSkeleton()}_getEditorViewModel(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(be.DocSkeletonManagerService).getViewModel()}_emptyDocumentDataModel(e,t){const r=(l,d)=>{const c=a.Tools.deepClone(l.getSnapshot()),u=this._getEditorViewModel(l.getUnitId());u!=null&&(ah(c.body,t),d&&(c.documentStyle=e),c.drawings={},c.drawingsOrder=[],l.reset(c),u.reset(l))},o=this._getDocumentDataModel();o&&r(o,!0);const s=this._univerInstanceService.getUnit(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);s&&r(s)}};exports.EditingRenderController=oh([ye(1,a.Inject(m.SheetsSelectionsService)),ye(2,a.IUndoRedoService),ye(3,a.IContextService),ye(4,w.IRenderManagerService),ye(5,Se),ye(6,hr),ye(7,a.Inject(G.LexerTreeBuilder)),ye(8,G.IFunctionService),ye(9,a.Inject(be.DocSelectionManagerService)),ye(10,a.ICommandService),ye(11,a.Inject(a.LocaleService)),ye(12,J.IEditorService),ye(13,a.Inject(exports.SheetCellEditorResizeService)),ye(14,a.IUniverInstanceService),ye(15,a.Inject(m.SheetInterceptorService))],exports.EditingRenderController);function sh(n,i,e,t,r,o){var h,g,S;if((i==null?void 0:i.body)==null)return null;const{body:s}=i;n.t=void 0;const l=s.dataStream;let c=l.substring(l.length-2,l.length)===a.DEFAULT_EMPTY_DOCUMENT_VALUE?l.substring(0,l.length-2):l;const u=t.getCurrentLocale();if(c=qu(c,e,u,r),(h=i.drawingsOrder)!=null&&h.length)n.v="",n.f=null,n.si=null,n.p=i,n.t=a.CellValueType.STRING;else if(n.s&&((S=(g=o==null?void 0:o.get(n.s))==null?void 0:g.n)==null?void 0:S.pattern)===gd.DEFAULT_TEXT_FORMAT){n.v=c,n.f=null,n.si=null,n.p=null,n.t=a.CellValueType.STRING,Lo(s)&&s.dataStream!==`\r
2
2
  `&&(n.p=i);const f=$s(i);f&&(n.s=f)}else if(a.isFormulaString(c)){if(n.f===c)return null;const f=e.checkIfAddBracket(c);for(let p=0;p<f;p++)c+=G.matchToken.CLOSE_BRACKET;n.f=c,n.si=null,n.v=null,n.p=null}else if(Yu(c)){const f=Gu(c);n.v=f,n.f=null,n.si=null,n.p=null,n.t=a.CellValueType.FORCE_STRING}else if(Lo(s))s.dataStream===`\r
3
3
  `?(n.v="",n.f=null,n.si=null,n.p=null):(n.p=i,n.v=null,n.f=null,n.si=null);else{if(c===""&&n.v==null&&n.p==null)return null;n.v=c,n.f=null,n.si=null,n.p=null;const f=$s(i);f&&(n.s=f)}return n}function Lo(n){const{textRuns:i=[],paragraphs:e=[],customRanges:t,customBlocks:r=[]}=n,o=n.dataStream.replace(/(\r\n)+$/,""),s=["va"];return i.filter(l=>l.st<o.length).some(l=>{var c;return!!(l.ts&&Object.keys(l.ts).some(u=>s.includes(u)))||Object.keys((c=l.ts)!=null?c:{}).length&&l.ed-l.st<o.length})||e.some(l=>l.bullet)||e.length>=2||!!(t!=null&&t.length)||r.length>0}function $s(n){const{body:i}=n;if(!i)return null;const{textRuns:e=[]}=i;let t={};const r=i.dataStream.replace(`\r
4
4
  `,"");return e.forEach(o=>{const{st:s,ed:l,ts:d}=o;l-s>=r.length&&(t={...t,...d})}),Object.keys(t).length?t:null}function ah(n,i=!1){n.dataStream=a.DEFAULT_EMPTY_DOCUMENT_VALUE,n.textRuns!=null&&(n.textRuns.length===1&&!i?(n.textRuns[0].st=0,n.textRuns[0].ed=1):n.textRuns=void 0),n.paragraphs!=null&&(n.paragraphs=[{startIndex:0}]),n.sectionBreaks!=null&&(n.sectionBreaks=void 0),n.tables!=null&&(n.tables=void 0),n.customRanges!=null&&(n.customRanges=void 0),n.customBlocks!=null&&(n.customBlocks=void 0)}var lh=Object.defineProperty,ch=Object.getOwnPropertyDescriptor,dh=(n,i,e,t)=>{for(var r=t>1?void 0:t?ch(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&lh(i,e,r),r},Xi=(n,i)=>(e,t)=>i(e,t,n);const ea=as.MARK_SELECTION,qt=a.createIdentifier("univer.mark-selection-service");exports.MarkSelectionService=class extends a.Disposable{constructor(e,t,r){super();R(this,"_shapeMap",new Map);this._currentService=e,this._renderManagerService=t,this._themeService=r}addShape(e,t=[],r=ea){var c;const o=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=(c=o.getActiveSheet())==null?void 0:c.getSheetId();if(!s)return null;const l=a.Tools.generateRandomId(),d={selection:e,subUnitId:s,unitId:o.getUnitId(),zIndex:r,control:null,exits:t};return this._shapeMap.set(l,d),this.refreshShapes(),l}addShapeWithNoFresh(e,t=[],r=ea){var d;const o=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=(d=o.getActiveSheet())==null?void 0:d.getSheetId();if(!s)return null;const l=a.Tools.generateRandomId();return this._shapeMap.set(l,{selection:e,subUnitId:s,unitId:o.getUnitId(),zIndex:r,control:null,exits:t}),l}refreshShapes(){var o;const e=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!e)return;const t=e.getUnitId(),r=(o=e.getActiveSheet())==null?void 0:o.getSheetId();this._shapeMap.forEach(s=>{var b;const{unitId:l,subUnitId:d,selection:c,control:u,zIndex:h}=s;if(u==null||u.dispose(),l!==t||d!==r)return;const g=this._renderManagerService.getRenderById(l);if(!g)return;const S=(b=this._renderManagerService.withCurrentTypeOfUnit(a.UniverInstanceType.UNIVER_SHEET,exports.SheetSkeletonManagerService))==null?void 0:b.getCurrentSkeleton();if(!S)return;const{scene:f}=g,{rowHeaderWidth:p,columnHeaderHeight:v}=S,C=new lr(f,h,this._themeService,{enableAutoFill:!1,highlightHeader:!1,rowHeaderWidth:p,columnHeaderHeight:v}),I=Me(c,S);C.updateRangeBySelectionWithCoord(I),s.control=C})}getShapeMap(){return this._shapeMap}removeShape(e){const t=this._shapeMap.get(e);if(!t)return;const{control:r}=t;r==null||r.dispose(),this._shapeMap.delete(e)}removeAllShapes(){for(const e of this._shapeMap.values()){const{control:t}=e;t==null||t.dispose()}this._shapeMap.clear()}};exports.MarkSelectionService=dh([Xi(0,a.IUniverInstanceService),Xi(1,w.IRenderManagerService),Xi(2,a.Inject(a.ThemeService))],exports.MarkSelectionService);function dl(n){return{strokeWidth:1.5,stroke:n.getCurrentTheme().primaryColor,fill:"rgba(178, 178, 178, 0.10)",widgets:{},strokeDash:8}}const uh=10,hh=6;function mh(){return a.Tools.generateRandomId(hh)}function gh(n){const i=n.match(/data-copy-id="([^\s]+)"/);return i&&i[1]?i[1]:null}class Sh{constructor(){R(this,"_cache",new a.LRUMap(uh))}set(i,e){this._cache.set(i,e)}get(i){return this._cache.get(i)}del(i){this._cache.delete(i)}clear(){this._cache.clear()}clearWithUnitId(i){this._cache.forEach((e,t)=>{e.unitId===i&&this._cache.delete(t)})}}function ei(n,i){const e=i!=null?i:n.style,t={},r=n.tagName.toLowerCase();switch(r){case"b":case"em":case"strong":{t.bl=a.BooleanNumber.TRUE;break}case"s":{t.st={s:a.BooleanNumber.TRUE};break}case"u":{t.ul={s:a.BooleanNumber.TRUE};break}case"i":{t.it=a.BooleanNumber.TRUE;break}case"sub":case"sup":{t.va=r==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}return fh(e,t),t}function fh(n,i){if(n instanceof CSSStyleDeclaration)for(let e=0;e<n.length;e++){const t=n[e],r=n.getPropertyValue(t);ta(t,r,i)}else for(const e in n){const t=n[e];ta(e,t,i)}}function ta(n,i,e){switch(n){case"font-family":e.ff=i;break;case"font-size":{const t=Number.parseInt(i);Number.isNaN(t)||(i.endsWith("pt")?e.fs=t:i.endsWith("px")&&(e.fs=t*.75));break}case"font-style":i==="italic"&&(e.it=a.BooleanNumber.TRUE);break;case"font-weight":{(Number(i)>400||i==="bold")&&(e.bl=a.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(i)?e.ul={s:a.BooleanNumber.TRUE}:/overline/.test(i)?e.ol={s:a.BooleanNumber.TRUE}:/line-through/.test(i)&&(e.st={s:a.BooleanNumber.TRUE});break}case"color":{try{const t=new a.ColorKit(i);t.isValid&&(e.cl={rgb:t.toRgbString()})}catch{}break}case"background-color":{const t=new a.ColorKit(i),r=t.isValid?t.toRgbString():"";r!==E.DEFAULT_BACKGROUND_COLOR_RGB&&r!==E.DEFAULT_BACKGROUND_COLOR_RGBA&&(e.bg={rgb:r});break}}}function ph(n){const i=document.createElement("body");return i.innerHTML=n,i}function ul(n){const i=n.style,e={};for(let t=0;t<i.length;t++){const r=i[t],o=i.getPropertyValue(r);switch(r){case"margin-top":{const s=Number.parseInt(o);e.spaceAbove={v:/pt/.test(o)?w.ptToPixel(s):s};break}case"margin-bottom":{const s=Number.parseInt(o);e.spaceBelow={v:/pt/.test(o)?w.ptToPixel(s):s};break}case"line-height":{const s=Number.parseFloat(o);e.lineSpacing=s;break}}}return Object.getOwnPropertyNames(e).length?e:null}function Yi(n,i){const e=[];for(let t=0,r=n.length;t<r;t++)n[t]===a.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});return e}function na(n,i,e){var s,l,d;const t=i.length,o=((s=e==null?void 0:e.length)!=null?s:0)===1&&e[0].st===0&&e[0].ed===t;return n.p?o&&((d=(l=n.p.body)==null?void 0:l.textRuns)!=null&&d.length)?(n.p.body.textRuns=[],{...n,s:e[0].ts}):n:o?{...n,s:e[0].ts}:n}const ra=["color","background","font-size","text-align","vertical-align","font-weight","font-style","font-family","text-decoration","white-space","word-wrap","border-left","border-right","border-top","border-bottom","--data-rotate"];function ia(n,i){const e=n.tagName.toLowerCase();return typeof i=="string"?e===i:Array.isArray(i)?i.some(t=>t===e):i(n)}const Ri=class Ri{constructor(i){R(this,"_styleMap",new Map);R(this,"_styleCache",new Map);R(this,"_styleRules",[]);R(this,"_afterProcessRules",[]);R(this,"_dom",null);R(this,"_getCurrentSkeleton");this._getCurrentSkeleton=i.getCurrentSkeleton}static use(i){if(this._pluginList.includes(i))throw new Error(`Univer paste plugin ${i.name} already added`);this._pluginList.push(i)}convert(i){const e=Ri._pluginList.find(p=>p.checkPasteType(i));e&&(this._styleRules=[...e.stylesRules],this._afterProcessRules=[...e.afterProcessRules]);const t=new a.ObjectMatrix;this._dom=ph(i);const r=this._dom.querySelector("style");if(r){const p=document.createElement("div"),v=p.attachShadow({mode:"open"});document.body.appendChild(p),v.appendChild(r);for(const C of r.sheet.cssRules){const I=C,b=I.selectorText,T=I.style;this._styleMap.set(b,T)}r.remove(),p.remove()}const o={dataStream:"",textRuns:[]},s=[],l=[],d=i.match(/<table\b[^>]*>([\s\S]*?)<\/table>/gi),c=[];this.process(null,this._dom.childNodes,o,c);const{paragraphs:u,dataStream:h,textRuns:g,payloads:S,customRanges:f}=o;if(u){const p=u.map(v=>v.startIndex+1);p.unshift(0);for(let v=0;v<p.length;v++){let C;if(v===p.length-1){if(C=`${h.substring(p[v])}\r
@@ -9,7 +9,7 @@
9
9
  `,g={...u,body:{dataStream:h,textRuns:d.textRuns,paragraphs:Yi(h)}};c==null||c.reset(g),o=c==null?void 0:c.getSnapshot(),r=d.dataStream}else r=_h(i.innerHTML.replace(/[\r\n]/g,""));return{cellText:r,cellRichStyle:o}}_generateDocumentDataModelSnapshot(i){var l;const e=this._getCurrentSkeleton();if(e==null)return null;const{skeleton:t}=e,r=(l=t.getBlankCellDocumentModel())==null?void 0:l.documentModel,s={...r==null?void 0:r.getSnapshot(),...i};return r==null||r.reset(s),r==null?void 0:r.getSnapshot()}process(i,e,t,r){var o,s,l;for(const d of e)if(d.nodeName.toLowerCase()==="table")r.push({index:((o=t==null?void 0:t.paragraphs)==null?void 0:o.length)||0});else if(d.nodeType===Node.TEXT_NODE){if(((s=d.nodeValue)==null?void 0:s.trim())==="")continue;const c=(l=d.nodeValue)==null?void 0:l.replace(/[\r\n]/g,"");let u;i&&this._styleCache.has(i)&&(u=this._styleCache.get(i));const h={dataStream:"",textRuns:[]};t.dataStream+=c,h.dataStream+=c,u&&Object.getOwnPropertyNames(u).length&&(t.textRuns.push({st:t.dataStream.length-c.length,ed:t.dataStream.length,ts:u}),h.textRuns.push({st:t.dataStream.length-c.length,ed:t.dataStream.length,ts:u}))}else{if(a.skipParseTagNames.includes(d.nodeName.toLowerCase()))continue;if(d.nodeName.toLowerCase()==="br")t.paragraphs||(t.paragraphs=[]),t.paragraphs.push({startIndex:t.dataStream.length}),t.dataStream+="\r";else if(d.nodeType===Node.ELEMENT_NODE){if(d.nodeName==="STYLE")continue;const c=d,u=this._processBeforeLink(c,{body:t}),h=i?this._styleCache.get(i):{},g=this._styleRules.find(({filter:v})=>ia(d,v)),S=g?g.getStyle(d):ei(d);this._styleCache.set(d,{...h,...S});const{childNodes:f}=d;this.process(d,f,t,r);const p=this._afterProcessRules.find(({filter:v})=>ia(d,v));p&&p.handler(t,d),this._processAfterLink(c,{body:t},u)}}}_processBeforeLink(i,e){return e.body.dataStream.length}_processAfterLink(i,e,t){var s,l;const r=e.body,o=i;o.tagName.toUpperCase()==="A"&&(r.customRanges=(s=r.customRanges)!=null?s:[],r.customRanges.push({startIndex:t,endIndex:r.dataStream.length-1,rangeId:(l=o.dataset.rangeid)!=null?l:a.generateRandomId(),rangeType:a.CustomRangeType.HYPERLINK,properties:{url:o.href}}))}dispose(){this._dom=null,this._styleCache.clear(),this._styleMap.clear()}};R(Ri,"_pluginList",[]);let wn=Ri;function vh(n){const i=/<tr([\s\S]*?)>([\s\S]*?)<\/tr>/gi,e=n.matchAll(i);if(!e)return{rowProperties:[],rowCount:0};const r=Array.from(e).map(o=>hl(o[1])).map(o=>{if(!o.height){const s=o.style,l=s&&s.match(/height\s*:\s*(\d+(\.\d+)?)px/);o.height=`${l?Number.parseInt(l[1],10):a.DEFAULT_WORKSHEET_ROW_HEIGHT}`}return o});return{rowProperties:r,rowCount:r.length}}function oa(n){const i={};return n.split(";").forEach(t=>{const[r,o]=t.split(":");i[r]=o}),i}function hl(n){if(!n)return{};const i={},e=/([\w-]+)\s*=\s*(?:(['"])([^'"]*)\2|(\S+))/g;let t;for(;(t=e.exec(n))!==null;){const[,r,,o,s]=t,l=o!==void 0?o:s;i[r]=l}return i}function Ch(n){const i=/<colgroup([\s\S]*?)>(.*?)<\/colgroup>/,e=n.match(i),t=/<col([\s\S]*?)>/g;let r;if(e!=null&&e[2]?r=e[2].matchAll(t):r=n.matchAll(t),!r)return null;const o=Array.from(r).map(l=>hl(l[1])),s=[];return o.forEach(l=>{const d=Number(l.span);if(d)for(let c=0;c<d;c++){const u={...l};delete u.span,s.push(u)}else s.push(l)}),s}function _h(n){const i={"&lt;":"<","&gt;":">","&amp;":"&","&quot;":'"',"&#39;":"'","&nbsp;":" "};return n.replace(/&lt;|&gt;|&amp;|&quot;|&#39;|&nbsp;|<br>/g,e=>i[e])}function sa(n,i){if(!n||!i)return null;const e=new RegExp(`(${i}\\s*:\\s*[^;]+);`,"i"),t=n.match(e);return t?t[1]:null}function Ih(n,i,e,t){const{rowSpan:r,colSpan:o,rowIndex:s,colSetValueIndex:l}=t;for(let d=s;d<s+r;d++)for(let c=l;c<l+o;c++)d===s&&c===l?n.setValue(d,c,{...e,style:i}):n.setValue(d,c,{style:i})}const bh={name:"univer-doc-paste-plugin-lark",checkPasteType(n){return/lark-record-clipboard/i.test(n)},stylesRules:[{filter:["s"],getStyle(n){const i=ei(n);return{st:{s:a.BooleanNumber.TRUE},...i}}}],afterProcessRules:[{filter(n){return n.tagName==="DIV"&&/ace-line/i.test(n.className)},handler(n){n.paragraphs==null&&(n.paragraphs=[]),n.paragraphs.push({startIndex:n.dataStream.length}),n.dataStream+="\r"}}]},Rh={name:"univer-doc-paste-plugin-univer",checkPasteType(n){return/UniverNormal/i.test(n)},stylesRules:[],afterProcessRules:[{filter(n){return n.tagName==="P"&&/UniverNormal/i.test(n.className)},handler(n,i){n.paragraphs==null&&(n.paragraphs=[]);const e={startIndex:n.dataStream.length},t=ul(i);t&&(e.paragraphStyle=t),n.paragraphs.push(e),n.dataStream+="\r"}}]},Eh={name:"univer-doc-paste-plugin-word",checkPasteType(n){return/word|mso/i.test(n)},stylesRules:[{filter:["b"],getStyle(n){const i=ei(n);return{bl:a.BooleanNumber.TRUE,...i}}}],afterProcessRules:[{filter(n){return n.tagName==="P"&&/mso/i.test(n.className)},handler(n,i){n.paragraphs==null&&(n.paragraphs=[]);const e={startIndex:n.dataStream.length},t=ul(i);t&&(e.paragraphStyle=t),n.paragraphs.push(e),n.dataStream+="\r"}}]};var Ct=(n=>(n.COPY="COPY",n.CUT="CUT",n))(Ct||{});function Th(n,i,e,t,r){const o=e.map(c=>{var u;return(u=c.onCopyRow)==null?void 0:u.call(c,n)}).filter(c=>!!c),s=vs(o),l=Cs(s),d=i.map(c=>{if(!r.has(`${n}-${c}`)){const u=t.getValue(n,c);if(u!=null&&u.rowSpan&&(u!=null&&u.colSpan))for(let h=n;h<n+u.rowSpan;h++)for(let g=c;g<c+u.colSpan;g++)r.add(`${h}-${g}`);return wh(n,c,e,t)}return null}).filter(c=>!!c).join("");return`<tr${l}>${d}</tr>`}function wh(n,i,e,t){const r=t.getValue(n,i),o=e.map(c=>{var u;return(u=c.onCopyCellStyle)==null?void 0:u.call(c,n,i,r==null?void 0:r.rowSpan,r==null?void 0:r.colSpan)}).filter(c=>!!c),s=vs(o),l=Cs(s),d=e.reduce((c,u)=>{var h;return c||((h=u.onCopyCellContent)==null?void 0:h.call(u,n,i))||""},"");return`<td${l}>${d}</td>`}function yh(n,i){return`<colgroup>${n.map(t=>{const r=i.map(l=>{var d;return(d=l.onCopyColumn)==null?void 0:d.call(l,t)}).filter(l=>!!l),o=vs(r);return`<col ${Cs(o)}>`}).join("")}</colgroup>`}function vs(n){return n.reduce((i,e)=>(Object.keys(e).forEach(r=>{i[r]?i[r]+=`;${e[r]}`:i[r]=e[r]}),i),{})}function Cs(n){return Object.keys(n).reduce((i,e)=>(i+=` ${e}="${n[e]}"`,i),"")}class Mh{convert(i,e,t){const{cols:r,rows:o}=e;if(!r.length)return"";const s=yh(r,t),l=[],d=new Set;return o.forEach(u=>{l.push(Th(u,r,t,i,d))}),`<google-sheets-html-origin><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none">${s}
10
10
  <tbody>${l.join("")}</tbody></table>`}}const Ph=(n,i,e=!1)=>{const t=h=>h.endRow-h.startRow+1,r=h=>h.endColumn-h.startColumn+1,o=t(i)%t(n),s=r(i)%r(n),l={startRow:0,endRow:t(n)-1,startColumn:0,endColumn:r(n)-1},d=Math.floor(t(i)/t(n)),c=Math.floor(r(i)/r(n)),u=[];if(!o&&!s)for(let h=1;h<=d;h++)for(let g=1;g<=c;g++){const S=t(n)*(h-1),f=r(n)*(g-1),p={startRow:S+i.startRow,endRow:S+i.startRow,startColumn:f+i.startColumn,endColumn:f+i.startColumn};u.push({repeatRelativeRange:l,startRange:p})}else if(!o&&s&&!e)for(let h=1;h<=d;h++){const g=t(n)*(h-1),S=0,f={startRow:g+i.startRow,endRow:g+i.startRow,startColumn:S+i.startColumn,endColumn:S+i.startColumn};u.push({repeatRelativeRange:l,startRange:f})}else if(o&&!s&&!e)for(let h=1;h<=c;h++){const S=r(n)*(h-1),f={startRow:0+i.startRow,endRow:0+i.startRow,startColumn:S+i.startColumn,endColumn:S+i.startColumn};u.push({repeatRelativeRange:l,startRange:f})}else{const h={startRow:i.startRow,endRow:i.startRow,startColumn:i.startColumn,endColumn:i.startColumn};u.push({startRange:h,repeatRelativeRange:l})}return u};function aa(n){return n?[/<td[^>]*class=".*?xl.*?"[^>]*>/i,/xmlns:x="urn:schemas-microsoft-com:office:excel"/i,/ProgId="Excel.Sheet"/i,/xmlns:o="urn:schemas-microsoft-com:office:office"/i,/@mso-|mso-excel/i,/<x:ExcelWorkbook>/i].some(e=>e.test(n)):!1}function Oh(...n){if(n.length===1)return n[0];const i=new a.ObjectMatrix;return n.forEach(e=>{e&&new a.ObjectMatrix(e).forValue((r,o,s)=>{i.setValue(r,o,{...i.getValue(r,o),...s})})}),i.getMatrix()}function xh(n,i){return n.id===i.id&&n.params.unitId===i.params.unitId&&n.params.subUnitId===i.params.subUnitId}function Bo(n){const i=[];for(let e=0;e<n.length;){let t=1;if(n[e].id===m.SetRangeValuesMutation.id){const r=n[e],o=[r];for(;e+t<n.length&&xh(r,n[e+t]);)o.push(n[e+t]),t+=1;const s=Oh(...o.map(l=>l.params.cellValue||{}));i.push({...r,params:{...r.params,cellValue:s}})}else i.push(n[e]);e+=t}return i}function Gi(n,i){const{startRow:e,endRow:t,startColumn:r,endColumn:o}=n;for(let s=e;s<=t;s++)for(let l=r;l<=o;l++)if(i.rows.includes(s)&&i.cols.includes(l))return!0}function la(n,i){const{startRow:e,endRow:t,startColumn:r,endColumn:o}=i;for(let s=e;s<=t;s++)if(!n.rows.includes(s))return!1;for(let s=r;s<=o;s++)if(!n.cols.includes(s))return!1;return!0}function Ah(n){const i=n.trim().split(`
11
11
  `);let e="<table>";return i.forEach(t=>{const r=t.split(" ");e+="<tr>",r.forEach(o=>{e+=`<td>${o}</td>`}),e+="</tr>"}),e+="</table>",e}var Nh=Object.defineProperty,Dh=Object.getOwnPropertyDescriptor,Hh=(n,i,e,t)=>{for(var r=t>1?void 0:t?Dh(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Nh(i,e,r),r},Oe=(n,i)=>(e,t)=>i(e,t,n);const ge={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",SPECIAL_PASTE_FORMULA:"special-paste-formula"},kh={[E.FILE_PNG_CLIPBOARD_MIME_TYPE]:"png",[E.FILE__JPEG_CLIPBOARD_MIME_TYPE]:"jpg",[E.FILE__WEBP_CLIPBOARD_MIME_TYPE]:"webp",[E.FILE__BMP_CLIPBOARD_MIME_TYPE]:"bmp"};wn.use(Eh);wn.use(bh);wn.use(Rh);const Ge=a.createIdentifier("sheet.clipboard-service");exports.SheetClipboardService=class extends a.Disposable{constructor(e,t,r,o,s,l,d,c,u,h,g,S,f,p){super();R(this,"_clipboardHooks",[]);R(this,"_clipboardHooks$",new O.BehaviorSubject([]));R(this,"clipboardHooks$",this._clipboardHooks$.asObservable());R(this,"_htmlToUSM");R(this,"_usmToHtml");R(this,"_copyContentCache");R(this,"_copyMarkId",null);R(this,"_pasteOptionsCache$",new O.BehaviorSubject(null));R(this,"pasteOptionsCache$",this._pasteOptionsCache$.asObservable());R(this,"_showMenu$",new O.Subject);R(this,"showMenu$",this._showMenu$.asObservable());this._logService=e,this._univerInstanceService=t,this._selectionManagerService=r,this._clipboardInterfaceService=o,this._undoRedoService=s,this._commandService=l,this._markSelectionService=d,this._notificationService=c,this._platformService=u,this._renderManagerService=h,this._themeService=g,this._localeService=S,this._errorService=f,this._injector=p,this._htmlToUSM=new wn({getCurrentSkeleton:()=>{var v;return(v=this._renderManagerService.withCurrentTypeOfUnit(a.UniverInstanceType.UNIVER_SHEET,exports.SheetSkeletonManagerService))==null?void 0:v.getCurrent()}}),this._usmToHtml=new Mh,this._copyContentCache=new Sh,this.disposeWithMe(this._htmlToUSM),this._initUnitDisposed()}setShowMenu(e){this._showMenu$.next(e)}copyContentCache(){return this._copyContentCache}generateCopyContent(e,t,r){return this._generateCopyContent(e,t,r,this._clipboardHooks)}async copy(e=Ct.COPY){const t=this._selectionManagerService.getCurrentLastSelection();if(!t)return!1;const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),o=r.getActiveSheet();if(!o)return!1;const s=this._clipboardHooks,l=r.getUnitId(),d=o.getSheetId();s.forEach(v=>{var C;return(C=v.onBeforeCopy)==null?void 0:C.call(v,l,d,t.range,e)});const c=this.generateCopyContent(l,d,t.range);if(s.forEach(v=>{var C;return(C=v.onAfterCopy)==null?void 0:C.call(v)}),!c)return!1;const{html:u,plain:h,matrixFragment:g,copyId:S,discreteRange:f}=c;this._copyContentCache.set(S,{unitId:r.getUnitId(),subUnitId:o.getSheetId(),range:f,matrix:g,copyType:e}),await this._clipboardInterfaceService.write(h,u),this._markSelectionService.removeAllShapes();const p=dl(this._themeService);return this._copyMarkId=this._markSelectionService.addShape({...t,style:p}),!0}async cut(){return this.copy(Ct.CUT)}async paste(e,t=ge.DEFAULT_PASTE){const r=e.types,o=r.indexOf(E.PLAIN_TEXT_CLIPBOARD_MIME_TYPE)!==-1?await e.getType(E.PLAIN_TEXT_CLIPBOARD_MIME_TYPE).then(c=>c&&c.text()):"",s=r.indexOf(E.HTML_CLIPBOARD_MIME_TYPE)!==-1?await e.getType(E.HTML_CLIPBOARD_MIME_TYPE).then(c=>c&&c.text()):"",l=aa(s),d=r.findIndex(c=>E.imageMimeTypeSet.has(c));if(d!==-1&&!l){const c=r[d],u=await e.getType(c);if(u){const h=new File([u],`clipboard-image.${kh[c]}`,{type:c});return this._pasteFiles([h],t)}}return s?(this._platformService.isWindows&&l&&this._notificationService.show({type:"warning",title:this._localeService.t("clipboard.shortCutNotify.title"),content:this._localeService.t("clipboard.shortCutNotify.useShortCutInstead")}),this._pasteHTML(s,t)):o?this._pastePlainText(o,t):(this._logService.error("[SheetClipboardService]","No valid data on clipboard"),!1)}async legacyPaste(e,t,r){const o=aa(e!=null?e:"");return r&&!o?this._pasteFiles(r,ge.DEFAULT_PASTE):e?this._pasteHTML(e,ge.DEFAULT_PASTE):t?/[\n\t]/.test(t)?this._pasteHTML(Ah(t),ge.DEFAULT_PASTE):this._pastePlainText(t,ge.DEFAULT_PASTE):this._pasteUnrecognized()}rePasteWithPasteType(e){const t=this._pasteOptionsCache$.getValue();if(!t)return!1;const r=this._injector.get(a.IUndoRedoService),o=r.pitchTopUndoElement();o&&a.sequenceExecute(o.undoMutations,this._commandService)&&r.popUndoToRedo();const{cellMatrix:s,rowProperties:l=[],colProperties:d=[],source:c,target:u}=t;return this._pasteUSM({cellMatrix:s,colProperties:d,rowProperties:l},u,ge[e],c),!0}updatePasteOptionsCache(e){this._pasteOptionsCache$.next(e)}addClipboardHook(e){if(this._clipboardHooks.findIndex(r=>r.id===e.id)!==-1)return this._logService.error("[SheetClipboardService]","hook already exists",e.id),{dispose:()=>{}};const t=this._clipboardHooks.findIndex(r=>{const o=r.priority||0;return(e.priority||0)<o});return this._clipboardHooks.splice(t!==-1?t:this._clipboardHooks.length,0,e),this._notifyClipboardHook(),a.toDisposable(()=>{const r=this._clipboardHooks.indexOf(e);r>-1&&(this._clipboardHooks.splice(r,1),this._notifyClipboardHook())})}getClipboardHooks(){return this._clipboardHooks}_generateCopyContent(e,t,r,o){const s=this._univerInstanceService.getUniverSheetInstance(e),l=s==null?void 0:s.getSheetBySheetId(t);if(!s||!l)return null;const d=o.reduce((M,y)=>{var x;const P=(x=y.getFilteredOutRows)==null?void 0:x.call(y,r);return P==null||P.forEach(A=>M.add(A)),M},new Set),{startColumn:c,startRow:u,endColumn:h,endRow:g}=r,S=l.getMatrixWithMergedCells(u,c,g,h,a.CellModeEnum.Both),f=new a.ObjectMatrix;let p=u;const v=new a.ObjectMatrix,C={rows:[],cols:[]};for(let M=u;M<=g;M++)if(!d.has(M)){C.rows.push(M);for(let y=c;y<=h;y++){const P=S.getValue(M,y);if(P){const x=a.Tools.deepClone(P);v.setValue(p-u,y-c,{...Ln(),...x}),delete x.displayV,f.setValue(p-u,y-c,{...Ln(),...x})}else v.setValue(p-u,y-c,Ln()),f.setValue(p-u,y-c,Ln()),S.setValue(M,y,Ln())}p+=1}for(let M=c;M<=h;M++)C.cols.push(M);let I=this._usmToHtml.convert(S,C,o);const b=ml(v),T=mh();return I=I.replace(/(<[a-z]+)/,(M,y)=>`${y} data-copy-id="${T}"`),{copyId:T,plain:b,html:I,matrixFragment:f,discreteRange:C}}_notifyClipboardHook(){this._clipboardHooks$.next(this._clipboardHooks)}async _executePaste(e){const t=this._getPastingTarget();if(!t.subUnitId||!t.selection)return!1;const r=this._injector.invoke(S=>gn(t.selection.range,S,t.unitId,t.subUnitId));if(!r)return!1;const{unitId:o,subUnitId:s}=t,l=this._clipboardHooks,d=[];if(l.some(S=>{var f;return d.push(S)&&((f=S.onBeforePaste)==null?void 0:f.call(S,{unitId:o,subUnitId:s,range:r}))===!1}))return d.forEach(S=>{var f;return(f=S.onAfterPaste)==null?void 0:f.call(S,!1)}),!1;const u=[],h=[];d.forEach(S=>{const f=e(S,{unitId:o,subUnitId:s,range:r});f&&(u.push(...f.redos),h.push(...f.undos))});const g=u.every(S=>this._commandService.executeCommand(S.id,S.params));return g&&this._undoRedoService.pushUndoRedo({unitID:this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId(),undoMutations:h,redoMutations:u}),g}async _pasteFiles(e,t){return this._executePaste((r,o)=>{var s;return(s=r.onPasteFiles)==null?void 0:s.call(r,o,e,{pasteType:t})})}async _pastePlainText(e,t){return this._executePaste((r,o)=>{var s;return(s=r.onPastePlainText)==null?void 0:s.call(r,o,e,{pasteType:t})})}_pasteUnrecognized(){return this._executePaste((e,t)=>{var r;return(r=e.onPasteUnrecognized)==null?void 0:r.call(e,t)})}async _pasteHTML(e,t){const r=gh(e);return r&&this._copyContentCache.get(r)?this._pasteInternal(r,t):this._pasteExternal(e,t)}async _pasteExternal(e,t){var h;const{rowProperties:r,colProperties:o,cellMatrix:s}=this._htmlToUSM.convert(e);if(!s)return!1;const l=this._getPastedRange(s);if(!l)return!1;const d=(h=this._univerInstanceService.getUniverSheetInstance(l.unitId))==null?void 0:h.getSheetBySheetId(l.subUnitId);if(!d)return!1;const c=d==null?void 0:d.getMergeData();return c.length&&c.some(S=>Gi(S,l.pastedRange)&&!la(l.pastedRange,S))?(this._errorService.emit(this._localeService.t("clipboard.paste.overlappingMergedCells")),!1):this._pasteUSM({rowProperties:r,colProperties:o,cellMatrix:s},l,t)}async _pasteInternal(e,t){var y,P;const r=a.Tools.deepClone(this._copyContentCache.get(e)),{range:o,matrix:s,unitId:l,subUnitId:d}=r||{};if(!s||!r||!o||!l||!d||!s||!r)return!1;const c=(y=this._univerInstanceService.getUniverSheetInstance(l))==null?void 0:y.getStyles();s.forValue((x,A,N)=>{if(typeof N.s=="string"){const D=a.Tools.deepClone(N);D.s=c==null?void 0:c.getStyleByCell(N),s.setValue(x,A,D)}if(N.colSpan||N.rowSpan)for(let D=0;D<N.rowSpan;D++)for(let H=0;H<N.colSpan;H++){if(D===0&&H===0)continue;const W=x+D,k=A+H;s.setValue(W,k,{s:c==null?void 0:c.getStyleByCell(N)})}});const u=this._getPastedRange(s);if(!u)return!1;const h=(P=this._univerInstanceService.getUniverSheetInstance(u.unitId))==null?void 0:P.getSheetBySheetId(u.subUnitId);if(!h)return!1;const g=h==null?void 0:h.getMergeData();if(g&&g.some(A=>Gi(A,u.pastedRange)&&!la(u.pastedRange,A)))return this._errorService.emit(this._localeService.t("clipboard.paste.overlappingMergedCells")),!1;const S=this._univerInstanceService.getUnit(l);if(!S)return!1;const f=S.getSheetBySheetId(d);if(!f)return!1;const p=f.getColumnManager(),v=f.getRowManager(),C=f.getConfig().defaultColumnWidth,I=f.getConfig().defaultRowHeight,b=[],T=[];if(o.cols.forEach(x=>{const A=p.getColumnOrCreate(x);b.push({width:`${A.w||C}`})}),o.rows.forEach(x=>{const A=v.getRowOrCreate(x),{ah:N=I,h:D=I}=A,H=Math.max(N,D);T.push({height:`${H}`})}),r.copyType===Ct.CUT){const x=u.pastedRange.rows[0],A=o.rows[o.rows.length-1]-o.rows[0]+x;u.pastedRange.rows=Array.from(new Array(A+1).keys()).slice(x)}const M=this._pasteUSM({cellMatrix:s,colProperties:b,rowProperties:T},u,t,{range:o,unitId:r.unitId,subUnitId:r.subUnitId,copyType:r.copyType,copyId:e});return r.copyType===Ct.CUT&&(this._copyContentCache.set(e,{...r,matrix:null}),this._copyMarkId&&this._markSelectionService.removeShape(this._copyMarkId),this._copyMarkId=null),M}_pasteUSM(e,t,r,o){const{rowProperties:s,colProperties:l,cellMatrix:d}=e,{unitId:c,subUnitId:u,pastedRange:h}=t,g=h.cols.length,S=this._clipboardHooks,f=[];if(S.some(P=>{var x;return f.push(P)&&((x=P.onBeforePaste)==null?void 0:x.call(P,{unitId:c,subUnitId:u,range:h}))===!1}))return f.forEach(P=>{var x;return(x=P.onAfterPaste)==null?void 0:x.call(P,!1)}),!1;if(!d)return!1;const v=o?{unitId:o.unitId,subUnitId:o.subUnitId,range:o.range}:null,C={copyType:(o==null?void 0:o.copyType)||Ct.COPY,copyId:o==null?void 0:o.copyId,pasteType:r};let I=[],b=[];const T=f.filter(P=>!P.specialPasteInfo&&P.id!==ge.DEFAULT_PASTE||r===P.id);T.forEach(P=>{var N,D,H;if(s){const W=(N=P.onPasteRows)==null?void 0:N.call(P,{range:h,unitId:c,subUnitId:u},s,{pasteType:r});W&&(I.push(...W.redos),b.push(...W.undos))}const x=(D=P.onPasteColumns)==null?void 0:D.call(P,{range:h,unitId:c,subUnitId:u},l||new Array(g).map(()=>({})),{pasteType:r});x&&(I.push(...x.redos),b.push(...x.undos));const A=(H=P.onPasteCells)==null?void 0:H.call(P,v,{range:h,unitId:c,subUnitId:u},d,C);A&&(I.push(...A.redos),b.push(...A.undos))});const M=this._getSetSelectionOperation(c,u,h,d,r);M&&I.push(M),I=Bo(I),b=Bo(b),b.push({id:m.SetWorksheetActiveOperation.id,params:{unitId:t.unitId,subUnitId:t.subUnitId}}),this._logService.log("[SheetClipboardService]","pasting mutations",{undoMutationsInfo:b,redoMutationsInfo:I});const y=I.every(P=>this._commandService.syncExecuteCommand(P.id,P.params));return y&&(this._undoRedoService.pushUndoRedo({unitID:c,undoMutations:b,redoMutations:I}),this.updatePasteOptionsCache({target:{pastedRange:h,unitId:c,subUnitId:u},cellMatrix:d,rowProperties:s,colProperties:l,pasteType:r,source:o}),this.setShowMenu(!0)),T.forEach(P=>{var x;return(x=P.onAfterPaste)==null?void 0:x.call(P,y)}),y}_getSetSelectionOperation(e,t,r,o,s){var M;const l=(M=this._univerInstanceService.getUniverSheetInstance(e))==null?void 0:M.getSheetBySheetId(t);if(!l)return null;const{rows:d,cols:c}=r,u=d[0],h=c[0],g=d[d.length-1],S=c[c.length-1],f={startRow:u,endRow:u,startColumn:h,endColumn:h},p=m.getPrimaryForRange(f,l),v=o.getValue(0,0),C=(v==null?void 0:v.rowSpan)||1,I=(v==null?void 0:v.colSpan)||1;if((s===ge.DEFAULT_PASTE||s===ge.SPECIAL_PASTE_BESIDES_BORDER||s===ge.SPECIAL_PASTE_FORMAT)&&(C>1||I>1)){const y={startRow:u,endRow:u+C-1,startColumn:h,endColumn:h+I-1};p.startRow=y.startRow,p.endRow=y.endRow,p.startColumn=y.startColumn,p.endColumn=y.endColumn,p.isMerged=!0,p.isMergedMainCell=!0}const T={unitId:e,subUnitId:t,selections:[{range:{startRow:u,endRow:g,startColumn:h,endColumn:S},primary:p,style:null}]};return{id:m.SetSelectionsOperation.id,params:T}}_getPastingTarget(){const e=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),t=e.getActiveSheet(),r=this._selectionManagerService.getCurrentLastSelection();return{unitId:e.getUnitId(),subUnitId:t==null?void 0:t.getSheetId(),selection:r}}_transformPastedData(e,t,r){const o=this._getPastingTarget(),{selection:s,unitId:l,subUnitId:d}=o;if(!d||!s)return null;const c=this._injector.invoke(D=>gn(s.range,D,l,d));if(!c)return null;const{ranges:[u],mapFunc:h}=Kt([c]),{startRow:g,startColumn:S,endRow:f,endColumn:p}=u,v=f-g+1,C=p-S+1,I=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),b=I==null?void 0:I.getActiveSheet();if(!b)return null;const M=b.getMergeData().filter(D=>c.rows.includes(D.startRow)&&c.cols.includes(D.startColumn)),y=M[0];let P=0,x=0,A=0,N=0;if(y&&(P=y.startRow,x=y.startColumn,A=y.endRow,N=y.endColumn),v%e===0&&C%t===0)if(M.length>0&&(v!==e||C!==t))if(P===c.rows[0]&&x===c.cols[0]&&A===c.rows[v-1]&&N===c.cols[C-1])if(Lh(r))for(let H=0;H<v;H++)for(let W=0;W<C;W++){const k=r.getValue(H%e,W%t);k&&r.setValue(H,W,k)}else r.forValue((H,W,k)=>{k.s=null,delete k.colSpan,delete k.rowSpan});else for(let D=0;D<v;D++)for(let H=0;H<C;H++){const W=r.getValue(D%e,H%t);W&&r.setValue(D,H,W)}else for(let D=0;D<v;D++)for(let H=0;H<C;H++){const W=r.getValue(D%e,H%t);W&&r.setValue(D,H,W)}else if(M.length>0){const{row:D,col:H}=h(g,S);if(this._topLeftCellsMatch(e,t,{topRow:D,leftCol:H})){const k=this._expandOrShrinkRowsCols(l,d,c,t,e);c.rows=k.rows,c.cols=k.cols}else{if(f>y.endRow||p>y.endColumn)return null;r.forValue((k,U,B)=>{B.s=null,delete B.colSpan,delete B.rowSpan})}}else{const D=this._expandOrShrinkRowsCols(l,d,c,t,e);c.rows=D.rows,c.cols=D.cols}return{pastedRange:c,unitId:l,subUnitId:d}}_getPastedRange(e){var b;const t=this._getPastingTarget(),{selection:r,unitId:o,subUnitId:s}=t;if(!s||!r)return null;const l=this._injector.invoke(T=>gn(r.range,T,o,s));if(!l)return null;const{startColumn:d,endColumn:c,startRow:u,endRow:h}=e.getDataRange(),g=h-u+1,S=c-d+1;if(g<=0||S<=0)return null;const f=l.rows.length,p=l.cols.length,v=(b=this._univerInstanceService.getUniverSheetInstance(o))==null?void 0:b.getSheetBySheetId(s);if(!v)return null;const C=v==null?void 0:v.getMergeData();if(f%g===0&&p%S===0&&!(C==null?void 0:C.some(M=>Gi(M,l)))){for(let M=0;M<f;M++)for(let y=0;y<p;y++){const P=e.getValue(M%g,y%S);P&&e.setValue(M,y,P)}return{pastedRange:l,unitId:o,subUnitId:s}}const I=this._expandOrShrinkRowsCols(o,s,l,S,g);return l.rows=I.rows,l.cols=I.cols,{pastedRange:l,unitId:o,subUnitId:s}}_expandOrShrinkRowsCols(e,t,r,o,s){const{rows:l,cols:d}=r,c=this._univerInstanceService.getUniverSheetInstance(e),u=c==null?void 0:c.getSheetBySheetId(t);let h,g;if(l.length>=s)h=l.slice(0,s);else{h=l.slice(0);let S=l[l.length-1]+1;for(;h.length<s;)u.getRowFiltered(S)||h.push(S),S++}if(d.length>=o)g=d.slice(0,o);else{g=d.slice(0);let S=d[d.length-1]+1;for(;g.length<o;)g.push(S),S++}return{rows:h,cols:g}}_topLeftCellsMatch(e,t,r){const o=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=o==null?void 0:o.getActiveSheet();if(!s)return!1;const{topRow:l,leftCol:d}=r,c=Wh(l+e-1,d,d+t-1,s),u=Uh(d+t-1,l,l+e-1,s);return!c&&!u}removeMarkSelection(){this._copyMarkId&&(this._markSelectionService.removeShape(this._copyMarkId),this._copyMarkId=null)}_initUnitDisposed(){this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).subscribe(e=>{e&&this.copyContentCache().clearWithUnitId(e.getUnitId())}))}disposePasteOptionsCache(){this.setShowMenu(!1),this.updatePasteOptionsCache(null)}};exports.SheetClipboardService=Hh([Oe(0,a.ILogService),Oe(1,a.IUniverInstanceService),Oe(2,a.Inject(m.SheetsSelectionsService)),Oe(3,E.IClipboardInterfaceService),Oe(4,a.IUndoRedoService),Oe(5,a.ICommandService),Oe(6,qt),Oe(7,E.INotificationService),Oe(8,E.IPlatformService),Oe(9,w.IRenderManagerService),Oe(10,a.Inject(a.ThemeService)),Oe(11,a.Inject(a.LocaleService)),Oe(12,a.Inject(a.ErrorService)),Oe(13,a.Inject(a.Injector))],exports.SheetClipboardService);function ml(n){let i="";const e=n.getLength();return n.forRow((t,r)=>{const o=[];r.forEach(s=>{const l=n.getValue(t,s);if(l){const d=Vh(l);o.push(d)}}),i+=o.join(" "),t!==e-1&&(i+=`
12
- `)}),i}function Vh(n){return a.isNotNullOrUndefined(n.displayV)?n.displayV:a.extractPureTextFromCell(n)}function Wh(n,i,e,t){return t.getMergeData().some(r=>r.startRow<=n&&n<r.endRow&&i<=r.startColumn&&r.startColumn<=e)}function Uh(n,i,e,t){return t.getMergeData().some(r=>r.startColumn<=n&&n<r.endColumn&&i<=r.startRow&&r.startRow<=e)}function Lh(n){let i=0;return n.forValue((e,t,r)=>{if(r&&i++,i>1)return!1}),i>1}function Ln(){return{p:null,v:null,s:null,f:null,si:null,t:null}}const _s=998,ze={id:E.CopyCommand.id,name:"sheet.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:_s,preconditions:ps,handler:async n=>n.get(Ge).copy()},Is={id:E.CutCommand.id,name:"sheet.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:_s,preconditions:ps,handler:async n=>n.get(Ge).cut()},Xe={id:E.PasteCommand.id,type:a.CommandType.COMMAND,multi:!0,name:"sheet.command.paste",priority:_s,preconditions:ps,handler:async(n,i)=>{const t=await n.get(E.IClipboardInterfaceService).read(),r=n.get(Ge);return t.length!==0?r.paste(t[0],i==null?void 0:i.value):!1}},ti={id:E.SheetPasteShortKeyCommandName,type:a.CommandType.COMMAND,handler:async(n,i)=>{const e=n.get(Ge),{htmlContent:t,textContent:r,files:o}=i;return e.legacyPaste(t,r,o),!0}},Sn={id:"sheet.command.paste-value",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Xe.id,{value:ge.SPECIAL_PASTE_VALUE})},fn={id:"sheet.command.paste-format",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Xe.id,{value:ge.SPECIAL_PASTE_FORMAT})},Vt={id:"sheet.command.paste-col-width",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Xe.id,{value:ge.SPECIAL_PASTE_COL_WIDTH})},pn={id:"sheet.command.paste-besides-border",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Xe.id,{value:ge.SPECIAL_PASTE_BESIDES_BORDER})},gl={id:"sheet.command.optional-paste",type:a.CommandType.COMMAND,handler:async(n,{type:i})=>n.get(Ge).rePasteWithPasteType(i)},mr={id:"sheet.command.hide-row-confirm",type:a.CommandType.COMMAND,handler:async n=>{var d;const e=(d=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:d.map(c=>c.range);if(!(e!=null&&e.length))return!1;const t=n.get(a.ICommandService),r=n.get(a.IUniverInstanceService),o=m.getSheetCommandTarget(r);if(!o)return!1;const{worksheet:s}=o,l=s.getVisibleRows();if(Ga(l,e)){const c=n.get(E.IConfirmService),u=n.get(a.LocaleService);return await c.confirm({id:"sheet.confirm.hide-row",title:{title:u.t("info.problem")},children:{title:u.t("rightClick.hideAllRowsAlert")},cancelText:u.t("button.cancel"),confirmText:u.t("button.confirm")}),!1}return await t.executeCommand(m.SetRowHiddenCommand.id),!0}},gr={id:"sheet.command.hide-col-confirm",type:a.CommandType.COMMAND,handler:async n=>{var d;const e=(d=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:d.map(c=>c.range);if(!(e!=null&&e.length))return!1;const t=n.get(a.ICommandService),r=n.get(a.IUniverInstanceService),o=m.getSheetCommandTarget(r);if(!o)return!1;const{worksheet:s}=o,l=s.getVisibleCols();if(Za(l,e)){const c=n.get(E.IConfirmService),u=n.get(a.LocaleService);return await c.confirm({id:"sheet.confirm.hide-col",title:{title:u.t("info.problem")},children:{title:u.t("rightClick.hideAllColumnsAlert")},cancelText:u.t("button.cancel"),confirmText:u.t("button.confirm")}),!1}return await t.executeCommand(m.SetColHiddenCommand.id),!0}},Qt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-bold",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatBoldCommand.id):i.executeCommand(m.SetBoldCommand.id)}},Jt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-italic",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatItalicCommand.id):i.executeCommand(m.SetItalicCommand.id)}},$t={type:a.CommandType.COMMAND,id:"sheet.command.set-range-underline",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatUnderlineCommand.id):i.executeCommand(m.SetUnderlineCommand.id)}},en={type:a.CommandType.COMMAND,id:"sheet.command.set-range-stroke",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatStrikethroughCommand.id):i.executeCommand(m.SetStrikeThroughCommand.id)}},bs={type:a.CommandType.COMMAND,id:"sheet.command.set-range-subscript",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatSubscriptCommand.id):!1}},Rs={type:a.CommandType.COMMAND,id:"sheet.command.set-range-superscript",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatSuperscriptCommand.id):!1}},Sr={type:a.CommandType.COMMAND,id:"sheet.command.set-range-fontsize",handler:async(n,i)=>{const e=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(J.SetInlineFormatFontSizeCommand.id,i):e.executeCommand(m.SetFontSizeCommand.id,i)}},fr={type:a.CommandType.COMMAND,id:"sheet.command.set-range-font-family",handler:async(n,i)=>{const e=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(J.SetInlineFormatFontFamilyCommand.id,i):e.executeCommand(m.SetFontFamilyCommand.id,i)}},yn={type:a.CommandType.COMMAND,id:"sheet.command.set-range-text-color",handler:async(n,i)=>{const e=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(J.SetInlineFormatTextColorCommand.id,i):e.executeCommand(m.SetTextColorCommand.id,i)}},Es={type:a.CommandType.COMMAND,id:"sheet.command.reset-range-text-color",handler:async n=>{const i=n.get(a.ICommandService),t=n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED),r=n.get(a.ThemeService);return t?i.executeCommand(J.SetInlineFormatTextColorCommand.id,{value:null}):i.executeCommand(m.SetTextColorCommand.id,{value:r.getCurrentTheme().textColor})}};var Bh=Object.defineProperty,Fh=Object.getOwnPropertyDescriptor,jh=(n,i,e,t)=>{for(var r=t>1?void 0:t?Fh(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Bh(i,e,r),r},ln=(n,i)=>(e,t)=>i(e,t,n),De=(n=>(n[n.OFF=0]="OFF",n[n.ONCE=1]="ONCE",n[n.INFINITE=2]="INFINITE",n))(De||{});const tt=a.createIdentifier("univer.format-painter-service");let ni=class extends a.Disposable{constructor(i,e,t,r,o,s){super();R(this,"status$");R(this,"_selectionFormat");R(this,"_markId",null);R(this,"_status$");R(this,"_defaultHook",null);R(this,"_extendHooks",[]);this._selectionManagerService=i,this._themeService=e,this._markSelectionService=t,this._logService=r,this._commandService=o,this._undoRedoService=s,this._status$=new O.BehaviorSubject(0),this.status$=this._status$.asObservable(),this._selectionFormat={styles:new a.ObjectMatrix,merges:[]}}addHook(i){var e,t,r;i.isDefaultHook&&((e=i.priority)!=null?e:0)>((r=(t=this._defaultHook)==null?void 0:t.priority)!=null?r:-1)?this._defaultHook=i:(this._extendHooks.push(i),this._extendHooks.sort((o,s)=>(o.priority||0)-(s.priority||0)))}getHooks(){return this._defaultHook?[this._defaultHook,...this._extendHooks]:this._extendHooks}setStatus(i){this._updateRangeMark(i),this._status$.next(i),this.getHooks().forEach(t=>{t.onStatusChange!==void 0&&t.onStatusChange(i)})}getStatus(){return this._status$.getValue()}setSelectionFormat(i){this._selectionFormat=i}getSelectionFormat(){return this._selectionFormat}applyFormatPainter(i,e,t){const r=this.getHooks(),o=[],s=[];r.forEach(d=>{if(d.onApply!==void 0){const c=d.onApply(i,e,t,this._selectionFormat);c&&(o.push(...c.redos),s.push(...c.undos))}});for(const d of r)if(d.onBeforeApply!==void 0&&!d.onBeforeApply({unitId:i,subUnitId:e,range:t,redoMutationsInfo:o,format:this._selectionFormat,undoMutationsInfo:s}))return!1;this._logService.log("[FormatPainterService]","apply mutations",{undoMutationsInfo:s,redoMutationsInfo:o});const l=o.every(d=>this._commandService.executeCommand(d.id,d.params));return l&&this._undoRedoService.pushUndoRedo({unitID:i,undoMutations:s,redoMutations:o}),l}_updateRangeMark(i){if(this._markSelectionService.removeAllShapes(),i!==0){const e=this._selectionManagerService.getCurrentLastSelection();if(e){const t=dl(this._themeService);i===2?this._markId=this._markSelectionService.addShape({...e,style:t}):this._markId=this._markSelectionService.addShape({...e,style:t},[m.SetRangeValuesMutation.id])}}}};ni=jh([ln(0,a.Inject(m.SheetsSelectionsService)),ln(1,a.Inject(a.ThemeService)),ln(2,qt),ln(3,a.ILogService),ln(4,a.ICommandService),ln(5,a.IUndoRedoService)],ni);const pr={id:"sheet.operation.set-format-painter",type:a.CommandType.OPERATION,handler:(n,i)=>i?(n.get(tt).setStatus(i.status),!0):!1},xi={type:a.CommandType.COMMAND,id:"sheet.command.set-infinite-format-painter",handler:async n=>{const e=n.get(tt).getStatus();let t;return e!==De.OFF?t=De.OFF:t=De.INFINITE,n.get(a.ICommandService).executeCommand(pr.id,{status:t})}},Dn={type:a.CommandType.COMMAND,id:"sheet.command.set-once-format-painter",handler:async n=>{const e=n.get(tt).getStatus();let t;return e!==De.OFF?t=De.OFF:t=De.ONCE,n.get(a.ICommandService).executeCommand(pr.id,{status:t})}},vr={type:a.CommandType.COMMAND,id:"sheet.command.apply-format-painter",handler:async(n,i)=>n.get(tt).applyFormatPainter(i.unitId,i.subUnitId,i.range)},ht={type:a.CommandType.COMMAND,id:"sheet.command.set-selection-frozen",handler:async(n,i)=>{const{type:e}=i||{},t=n.get(a.IUniverInstanceService),r=n.get(a.IUndoRedoService),o=m.getSheetCommandTarget(t);if(!o)return!1;const{unitId:s,subUnitId:l}=o,d=n.get(a.ICommandService),u=n.get(m.SheetsSelectionsService).getCurrentSelections();if(!u)return!1;const h=u[(u==null?void 0:u.length)-1],{range:g}=h,f=n.get(w.IRenderManagerService).getRenderById(s).with(exports.SheetScrollManagerService),{sheetViewStartRow:p=0,sheetViewStartColumn:v=0}=f.getCurrentScrollState()||{};let C,I,b,T;const{startRow:M,startColumn:y,rangeType:P}=g;if(P===a.RANGE_TYPE.ROW||e===1)C=M,b=M-p,I=-1,T=0;else if(P===a.RANGE_TYPE.COLUMN||e===2)C=-1,b=0,I=y,T=y-v;else if(P===a.RANGE_TYPE.NORMAL)C=M,b=M-p,I=y,T=y-v;else return!1;const x={unitId:s,subUnitId:l,startRow:C,startColumn:I,xSplit:I>0?Math.max(1,T):T,ySplit:C>0?Math.max(1,b):b},A=m.SetFrozenMutationFactory(n,x);return d.syncExecuteCommand(m.SetFrozenMutation.id,x)&&r.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetFrozenMutation.id,params:A}],redoMutations:[{id:m.SetFrozenMutation.id,params:x}]}),!0}},Cr={type:a.CommandType.COMMAND,id:"sheet.command.set-row-frozen",handler:async n=>(n.get(a.ICommandService).executeCommand(ht.id,{type:1}),!0)},_r={type:a.CommandType.COMMAND,id:"sheet.command.set-col-frozen",handler:async n=>(n.get(a.ICommandService).executeCommand(ht.id,{type:2}),!0)};var zh=Object.defineProperty,Xh=Object.getOwnPropertyDescriptor,Yh=(n,i,e,t)=>{for(var r=t>1?void 0:t?Xh(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&zh(i,e,r),r},ca=(n,i)=>(e,t)=>i(e,t,n);const Gh=(n,i)=>{const{unitId:e,subUnitId:t,ranges:r}=n,o={},s=i.getColumnManager();for(let l=0;l<r.length;l++){const d=r[l];for(let c=d.startColumn;c<d.endColumn+1;c++){const u=s.getColumnOrCreate(c);o[c]=u.w}}return{unitId:e,subUnitId:t,ranges:r,colWidth:o}};exports.AutoWidthController=class extends a.Disposable{constructor(i,e){super(),this._renderManagerService=i,this._univerInstanceService=e}getUndoRedoParamsOfColWidth(i){const e={redos:[],undos:[]},{_univerInstanceService:t}=this,r=m.getSheetCommandTarget(t);if(!r)return e;const{unitId:o,subUnitId:s,worksheet:l}=r,d=this._renderManagerService.getRenderById(o).with(exports.SheetSkeletonManagerService);if(!d.getCurrent())return e;const{skeleton:c}=d.getCurrent(),u=c.calculateAutoWidthInRange(i.ranges),h={};for(const{col:f,width:p}of u)h[f]=p;const g={subUnitId:s,unitId:o,ranges:i.ranges,colWidth:h},S=Gh(g,l);return{undos:[{id:m.SetWorksheetColWidthMutation.id,params:S}],redos:[{id:m.SetWorksheetColWidthMutation.id,params:g}]}}};exports.AutoWidthController=Yh([ca(0,w.IRenderManagerService),ca(1,a.Inject(a.IUniverInstanceService))],exports.AutoWidthController);const Ir={type:a.CommandType.COMMAND,id:"sheet.command.set-col-auto-width",handler:(n,i)=>{const e=n.get(a.ICommandService),t=n.get(a.IUndoRedoService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(o,i);if(!s)return!1;const{unitId:l,subUnitId:d}=s;let c=[];if(i!=null&&i.ranges)c=[...i.ranges];else{const f=r.getCurrentSelections();for(let p=0;p<f.length;p++)c.push(f[p].range)}if(!(c!=null&&c.length))return!1;const u={unitId:l,subUnitId:d,ranges:c},{redos:h,undos:g}=n.get(exports.AutoWidthController).getUndoRedoParamsOfColWidth(u);return a.sequenceExecute([...h],e).result?(t.pushUndoRedo({unitID:l,undoMutations:[...g],redoMutations:[...h]}),!0):!1}},Hn="UI_PLUGIN_SHEETS",br=`${Hn}_COLOR_PICKER_COMPONENT`,Ai=`${Hn}_FONT_FAMILY_COMPONENT`,Ni=`${Hn}_FONT_FAMILY_ITEM_COMPONENT`,Di=`${Hn}_FONT_SIZE_COMPONENT`,Hi=`${Hn}_MENU_ITEM_INPUT_COMPONENT`,Zh="univer-sheets-ui-context-menu-input",Kh="univer-sheets-ui-context-menu-input-container",qh="univer-sheets-ui-context-menu-input-number",Zi={sheetsUiContextMenuInput:Zh,sheetsUiContextMenuInputContainer:Kh,sheetsUiContextMenuInputNumber:qh},Sl=n=>{const{prefix:i,suffix:e,value:t,onChange:r,min:o=Number.MIN_SAFE_INTEGER,max:s=Number.MAX_SAFE_INTEGER}=n,l=a.useDependency(a.LocaleService),d=a.useDependency(E.IContextMenuService),[c,u]=V.useState(),h=S=>{var f;u(S==null?void 0:S.toString()),r((f=S==null?void 0:S.toString())!=null?f:"")};V.useEffect(()=>{d.visible||u(t)},[d.visible]),V.useEffect(()=>{u(t)},[t]);function g(S){S.key==="Backspace"&&S.stopPropagation()}return _.jsxs("div",{className:Zi.sheetsUiContextMenuInput,children:[l.t(i),_.jsx("span",{className:Zi.sheetsUiContextMenuInputContainer,onClick:S=>S.stopPropagation(),children:_.jsx(K.InputNumber,{className:Zi.sheetsUiContextMenuInputNumber,value:Number(c),precision:0,onKeyDown:g,onChange:h,min:o,max:s})}),l.t(e)]})};function Qh(n){return n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(O.switchMap(i=>i?i.activeSheet$.pipe(O.map(e=>e?{workbook:i,worksheet:e}:null)):O.of(null)))}function Pe(n,i,e){return Qh(n).pipe(O.switchMap(t=>t?e(t):O.of(i)))}function fl(n,i){const e=n.get(a.IUniverInstanceService),t=n.get(m.IExclusiveRangeService),r=n.get(m.SheetsSelectionsService);return e.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(O.switchMap(s=>s?O.combineLatest([r.selectionMoveEnd$,s.activeSheet$]).pipe(O.switchMap(([l,d])=>{if(!d||l.length===0)return O.of(!1);const c=t.getInterestGroupId(l);if(i){const u=c.filter(h=>i.has(h));return O.of(u.length>0)}else return O.of(c.length>0)})):O.of(!1)))}function tn(n,i,e){return O.combineLatest([i,fl(n,e)]).pipe(O.map(([t,r])=>t||r))}function te(n,i={},e=!1){var u;const r=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),o=n.get(a.UserManagerService),s=n.has(Se)?n.get(Se):null,d=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_FX_BAR_EDITOR),c=(u=s==null?void 0:s.visible$)!=null?u:O.of(null);return O.combineLatest([o.currentUser$,r,c,d]).pipe(O.switchMap(([h,g,S,f])=>!g||S!=null&&S.visible&&S.unitId===g.getUnitId()&&!e||f&&!e?O.of(!0):g.activeSheet$.pipe(O.switchMap(p=>{if(!p)return O.of(!0);const v=n.get(m.SheetsSelectionsService),C=n.get(m.RangeProtectionRuleModel),I=n.get(m.WorksheetProtectionRuleModel),T=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_COMMON_DRAWINGS).pipe(O.startWith(!1));return O.combineLatest([v.selectionMoveEnd$,T]).pipe(O.switchMap(([M,y])=>{if(y)return O.of(!0);const P=g.getUnitId(),x=p.getSheetId(),A=n.get(a.IPermissionService),{workbookTypes:N=[m.WorkbookEditablePermission],worksheetTypes:D,rangeTypes:H}=i,W=[];if(N==null||N.forEach(F=>{W.push(new F(P).id)}),D==null||D.forEach(F=>{W.push(new F(P,x).id)}),I.getRule(P,x))return A.composePermission$(W).pipe(O.map(F=>F.some(L=>L.value===!1)));const U=M==null?void 0:M.map(F=>F.range),B=C.getSubunitRuleList(P,x).filter(F=>U==null?void 0:U.some(L=>F.ranges.some(z=>a.Rectangle.intersects(L,z))));return H==null||H.forEach(F=>{B.forEach(L=>{W.push(new F(P,x,L.permissionId).id)})}),A.composePermission$(W).pipe(O.map(F=>F.some(L=>L.value===!1)))}))}))))}function ki(n){const i=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(m.RangeProtectionRuleModel),r=n.get(a.IPermissionService);return O.merge(e.selectionMoveEnd$,r.permissionPointUpdate$.pipe(O.debounceTime(100))).pipe(O.map(()=>{var h;const o=(h=e.getCurrentLastSelection())==null?void 0:h.range;if(!o)return!0;const s=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),l=s==null?void 0:s.getActiveSheet();if(!s||!l)return!0;const d=s.getUnitId(),c=l.getSheetId(),u=[new m.WorkbookEditablePermission(d).id,new m.WorksheetEditPermission(d,c).id];return t.getSubunitRuleList(d,c).filter(g=>g.ranges.some(S=>a.Rectangle.intersects(o,S))).forEach(g=>{u.push(new m.RangeProtectionPermissionEditPoint(d,c,g.permissionId).id)}),r.composePermission(u).some(g=>g.value===!1)}))}function pl(n,i){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.RangeProtectionRuleModel),o=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,o.permissionPointUpdate$.pipe(O.debounceTime(100))).pipe(O.map(()=>{var g;const s=(g=t.getCurrentLastSelection())==null?void 0:g.range;if(!s)return!0;const l=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d=l==null?void 0:l.getActiveSheet();if(!l||!d)return!0;const c=l.getUnitId(),u=d.getSheetId(),h=[new m.WorkbookEditablePermission(c).id,new m.WorksheetEditPermission(c,u).id];return r.getSubunitRuleList(c,u).filter(S=>i==="row"?S.ranges.some(f=>s.endRow>f.startRow&&s.endRow<=f.endRow):S.ranges.some(f=>s.endColumn>f.startColumn&&s.endColumn<=f.endColumn)).forEach(S=>{h.push(new m.RangeProtectionPermissionEditPoint(c,u,S.permissionId).id)}),o.composePermission(h).some(S=>S.value===!1)}))}function vl(n,i){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.RangeProtectionRuleModel),o=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,o.permissionPointUpdate$.pipe(O.debounceTime(100))).pipe(O.map(()=>{var g;const s=(g=t.getCurrentLastSelection())==null?void 0:g.range;if(!s)return!0;const l=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d=l==null?void 0:l.getActiveSheet();if(!l||!d)return!0;const c=l.getUnitId(),u=d.getSheetId(),h=[new m.WorkbookEditablePermission(c).id,new m.WorksheetEditPermission(c,u).id];return r.getSubunitRuleList(c,u).filter(S=>i==="row"?S.ranges.some(f=>s.startRow>f.startRow&&s.startRow<=f.endRow):S.ranges.some(f=>s.startColumn>f.startColumn&&s.startColumn<=f.endColumn)).forEach(S=>{h.push(new m.RangeProtectionPermissionEditPoint(c,u,S.permissionId).id)}),o.composePermission(h).some(S=>S.value===!1)}))}function Cl(n,i){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.RangeProtectionRuleModel),o=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,o.permissionPointUpdate$.pipe(O.debounceTime(100))).pipe(O.map(()=>{var S;const s=(S=t.getCurrentLastSelection())==null?void 0:S.range;if(!s)return!0;const l=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d=l==null?void 0:l.getActiveSheet();if(!l||!d)return!0;const c=l.getUnitId(),u=d.getSheetId(),h=[new m.WorkbookEditablePermission(c).id,new m.WorksheetEditPermission(c,u).id],g=a.Tools.deepClone(s);return i==="row"?(g.startColumn=0,g.endColumn=d.getColumnCount()-1):(g.startRow=0,g.endRow=d.getRowCount()-1),r.getSubunitRuleList(c,u).filter(f=>f.ranges.some(p=>a.Rectangle.intersects(g,p))).forEach(f=>{h.push(new m.RangeProtectionPermissionEditPoint(c,u,f.permissionId).id)}),o.composePermission(h).some(f=>f.value===!1)}))}function Vi(n,i){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.RangeProtectionRuleModel),o=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,o.permissionPointUpdate$.pipe(O.debounceTime(100))).pipe(O.map(()=>{var S;const s=(S=t.getCurrentLastSelection())==null?void 0:S.range;if(!s)return!0;const l=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d=l==null?void 0:l.getActiveSheet();if(!l||!d)return!0;const c=l.getUnitId(),u=d.getSheetId(),h=[new m.WorkbookEditablePermission(c).id,new m.WorksheetEditPermission(c,u).id],g=a.Tools.deepClone(s);return i==="row"?g.endRow=d.getRowCount()-1:g.endColumn=d.getColumnCount()-1,r.getSubunitRuleList(c,u).filter(f=>f.ranges.some(p=>a.Rectangle.intersects(g,p))).forEach(f=>{h.push(new m.RangeProtectionPermissionEditPoint(c,u,f.permissionId).id)}),o.composePermission(h).some(f=>f.value===!1)}))}function kn(n,i){const t=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(m.WorksheetProtectionRuleModel),o=n.get(m.RangeProtectionRuleModel),s=n.get(a.IPermissionService),l=n.get(a.UserManagerService);return O.combineLatest([l.currentUser$,t]).pipe(O.switchMap(([d,c])=>c?c.activeSheet$.pipe(O.switchMap(u=>{if(!u)return O.of(!0);const h=c.getUnitId(),g=[];return i.forEach(f=>g.push(new f(h).id)),s.composePermission$(g).pipe(O.map(f=>f.every(p=>p.value===!0))).pipe(O.map(f=>{if(!f)return!0;const p=u.getSheetId(),v=r.getRule(h,p),C=o.getSubunitRuleList(h,p);return!!(v||C.length)}))})):O.of(!0)))}var _l=(n=>(n.ROW_HEADER_CONTEXT_MENU="ROW_HEADER_CONTEXT_MENU",n.COL_HEADER_CONTEXT_MENU="COL_HEADER_CONTEXT_MENU",n.SHEET_BAR="SHEET_BAR",n.SHEET_FOOTER="SHEET_FOOTER",n))(_l||{});function Jh(n){const i=n.get(tt);return{id:Dn.id,subId:xi.id,type:E.MenuItemType.BUTTON,icon:"BrushSingle",title:"Format Painter",tooltip:"toolbar.formatPainter",activated$:new O.Observable(e=>{let t=!1;const r=i.status$.subscribe(o=>{t=o!==De.OFF,e.next(t)});return e.next(t),()=>{r.unsubscribe()}}),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetCopyPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0)}}function $h(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(a.IContextService),r=n.get(m.SheetsSelectionsService);return{id:Qt.id,type:E.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:Pe(e,!1,({worksheet:o})=>new O.Observable(s=>{var u;const l=i.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const p=(S=r.getCurrentLastSelection())==null?void 0:S.primary;let v=a.FontWeight.NORMAL;if(p!=null){const C=o.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getFontWeight()}s.next(v===a.FontWeight.BOLD)}if((g===be.SetTextSelectionsOperation.id||g===J.SetInlineFormatCommand.id)&&t.getContextValue(a.EDITOR_ACTIVATED)&&t.getContextValue(a.FOCUSING_SHEET)){const p=Er(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.bl;s.next(v===a.BooleanNumber.TRUE)}}),d=(u=r.getCurrentLastSelection())==null?void 0:u.primary;if(!o){s.next(!1);return}let c=a.FontWeight.NORMAL;if(d!=null){const h=o.getRange(d.startRow,d.startColumn);c=h==null?void 0:h.getFontWeight()}return s.next(c===a.FontWeight.BOLD),l.dispose})),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function em(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService);return{id:Jt.id,type:E.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:Pe(e,!1,({worksheet:o})=>new O.Observable(s=>{var u;const l=i.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const p=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let v=a.FontItalic.NORMAL;if(p!=null){const C=o.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getFontStyle()}s.next(v===a.FontItalic.ITALIC)}if((g===be.SetTextSelectionsOperation.id||g===J.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const p=Er(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.it;s.next(v===a.BooleanNumber.TRUE)}}),d=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let c=a.FontItalic.NORMAL;if(d!=null){const h=o.getRange(d.startRow,d.startColumn);c=h==null?void 0:h.getFontStyle()}return s.next(c===a.FontItalic.ITALIC),l.dispose})),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function tm(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService);return{id:$t.id,type:E.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",activated$:Pe(e,!1,({worksheet:o})=>new O.Observable(s=>{var u;const l=i.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const p=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let v;if(p!=null){const C=o.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getUnderline()}s.next(!!(v&&v.s))}if((g===be.SetTextSelectionsOperation.id||g===J.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const p=Er(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.ul;s.next((v==null?void 0:v.s)===a.BooleanNumber.TRUE)}}),d=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let c;if(d!=null){const h=o.getRange(d.startRow,d.startColumn);c=h==null?void 0:h.getUnderline()}return s.next(!!(c&&c.s)),l.dispose})),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function nm(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService);return{id:en.id,type:E.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:Pe(e,!1,({worksheet:o})=>new O.Observable(s=>{var u;const l=i.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const p=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let v;if(p!=null){const C=o.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getStrikeThrough()}s.next(!!(v&&v.s))}if((g===be.SetTextSelectionsOperation.id||g===J.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const p=Er(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.st;s.next((v==null?void 0:v.s)===a.BooleanNumber.TRUE)}}),d=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let c;if(d!=null){const h=o.getRange(d.startRow,d.startColumn);c=h==null?void 0:h.getStrikeThrough()}return s.next(!!(c&&c.s)),l.dispose})),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function rm(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=a.DEFAULT_STYLES.ff;return{id:fr.id,tooltip:"toolbar.font",type:E.MenuItemType.SELECTOR,label:Ai,selections:E.FONT_FAMILY_LIST.map(o=>({label:{name:Ni,hoverable:!0},value:o.value})),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),value$:Pe(e,r,({worksheet:o})=>new O.Observable(s=>{var u;const l=i.onCommandExecuted(h=>{var p;const g=h.id;if(g!==m.SetRangeValuesMutation.id&&g!==m.SetSelectionsOperation.id&&g!==m.SetWorksheetActiveOperation.id)return;const S=(p=t.getCurrentLastSelection())==null?void 0:p.primary;let f;if(S!=null){const v=o.getRange(S.startRow,S.startColumn);f=v==null?void 0:v.getFontFamily()}s.next(f!=null?f:r)}),d=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let c;if(d!=null){const h=o.getRange(d.startRow,d.startColumn);c=h==null?void 0:h.getFontFamily()}return s.next(c!=null?c:r),l.dispose})),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function im(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService),o=a.DEFAULT_STYLES.fs,s=te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0);return{id:Sr.id,type:E.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Di,props:{min:1,max:400,disabled$:s}},selections:E.FONT_SIZE_LIST,disabled$:s,value$:Pe(e,o,({worksheet:l})=>new O.Observable(d=>{var g;const c=i.onCommandExecuted(S=>{var p,v;const f=S.id;if(f===m.SetRangeValuesMutation.id||f===m.SetSelectionsOperation.id||f===m.SetWorksheetActiveOperation.id){const C=(p=t.getCurrentLastSelection())==null?void 0:p.primary;let I;if(C!=null){const b=l.getRange(C.startRow,C.startColumn);I=b==null?void 0:b.getFontSize()}d.next(I!=null?I:o)}if((f===be.SetTextSelectionsOperation.id||f===J.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const C=Er(n);if(C==null)return;const I=(v=C.ts)==null?void 0:v.fs;d.next(I!=null?I:o)}}),u=(g=t.getCurrentLastSelection())==null?void 0:g.primary;let h;if(u!=null){const S=l.getRange(u.startRow,u.startColumn);h=S==null?void 0:S.getFontSize()}return d.next(h!=null?h:o),c.dispose})),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function om(n){return{id:Es.id,type:E.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function sm(n){const i=n.get(a.ICommandService),e=n.get(a.ThemeService);return{id:yn.id,icon:"FontColor",tooltip:"toolbar.textColor.main",type:E.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:br,hoverable:!1}}],value$:new O.Observable(t=>{const r=e.getCurrentTheme().textColor,o=i.onCommandExecuted(s=>{if(s.id===yn.id){const l=s.params.value;t.next(l!=null?l:r)}});return t.next(r),o.dispose}),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0)}}function am(n){return{id:m.ResetBackgroundColorCommand.id,type:E.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function lm(n){const i=n.get(a.ICommandService),e=n.get(a.ThemeService);return{id:m.SetBackgroundColorCommand.id,tooltip:"toolbar.fillColor.main",type:E.MenuItemType.BUTTON_SELECTOR,icon:"PaintBucket",selections:[{label:{name:br,hoverable:!1}}],value$:new O.Observable(t=>{const r=e.getCurrentTheme().primaryColor,o=i.onCommandExecuted(s=>{if(s.id===m.SetBackgroundColorCommand.id){const l=s.params.value;t.next(l!=null?l:r)}});return t.next(r),o.dispose}),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const da=[{label:"align.left",icon:"LeftJustifyingSingle",value:a.HorizontalAlign.LEFT},{label:"align.center",icon:"HorizontallySingle",value:a.HorizontalAlign.CENTER},{label:"align.right",icon:"RightJustifyingSingle",value:a.HorizontalAlign.RIGHT}];function cm(n){const i=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=a.HorizontalAlign.LEFT;return{id:m.SetHorizontalTextAlignCommand.id,icon:da[0].icon,tooltip:"toolbar.horizontalAlignMode.main",type:E.MenuItemType.SELECTOR,selections:da,value$:Pe(i,t,({worksheet:r})=>new O.Observable(o=>{var c;const s=n.get(a.ICommandService).onCommandExecuted(u=>{var f;const h=u.id;if(h!==m.SetHorizontalTextAlignCommand.id&&h!==m.SetSelectionsOperation.id&&h!==m.SetWorksheetActiveOperation.id)return;const g=(f=e.getCurrentLastSelection())==null?void 0:f.primary;let S;if(g!=null){const p=r.getRange(g.startRow,g.startColumn);S=p==null?void 0:p.getHorizontalAlignment()}o.next(S!=null?S:t)}),l=(c=e.getCurrentLastSelection())==null?void 0:c.primary;let d;if(l!=null){const u=r.getRange(l.startRow,l.startColumn);d=u==null?void 0:u.getHorizontalAlignment()}return o.next(d!=null?d:t),s.dispose})),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const ua=[{label:"align.top",icon:"AlignTopSingle",value:a.VerticalAlign.TOP},{label:"align.middle",icon:"VerticalCenterSingle",value:a.VerticalAlign.MIDDLE},{label:"align.bottom",icon:"AlignBottomSingle",value:a.VerticalAlign.BOTTOM}];function dm(n){const i=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=a.VerticalAlign.BOTTOM;return{id:m.SetVerticalTextAlignCommand.id,icon:ua[2].icon,tooltip:"toolbar.verticalAlignMode.main",type:E.MenuItemType.SELECTOR,selections:ua,value$:Pe(i,t,({worksheet:r})=>new O.Observable(o=>{var c;const s=n.get(a.ICommandService).onCommandExecuted(u=>{var f;const h=u.id;if(h!==m.SetVerticalTextAlignCommand.id&&h!==m.SetSelectionsOperation.id&&h!==m.SetWorksheetActiveOperation.id)return;const g=(f=e.getCurrentLastSelection())==null?void 0:f.primary;let S;if(g!=null){const p=r.getRange(g.startRow,g.startColumn);S=p==null?void 0:p.getVerticalAlignment()}o.next(S!=null?S:t)}),l=(c=e.getCurrentLastSelection())==null?void 0:c.primary;let d;if(l!=null){const u=r.getRange(l.startRow,l.startColumn);d=u==null?void 0:u.getVerticalAlignment()}return o.next(d!=null?d:t),s.dispose})),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const ha=[{label:"textWrap.overflow",icon:"OverflowSingle",value:a.WrapStrategy.OVERFLOW},{label:"textWrap.wrap",icon:"AutowrapSingle",value:a.WrapStrategy.WRAP},{label:"textWrap.clip",icon:"TruncationSingle",value:a.WrapStrategy.CLIP}];function um(n){const i=n.get(m.SheetsSelectionsService),e=n.get(a.IUniverInstanceService),t=a.WrapStrategy.OVERFLOW;return{id:m.SetTextWrapCommand.id,tooltip:"toolbar.textWrapMode.main",icon:ha[0].icon,type:E.MenuItemType.SELECTOR,selections:ha,value$:Pe(e,t,({worksheet:r})=>new O.Observable(o=>{var c;const s=n.get(a.ICommandService).onCommandExecuted(u=>{var f;const h=u.id;if(h!==m.SetTextWrapCommand.id&&h!==m.SetSelectionsOperation.id&&h!==m.SetWorksheetActiveOperation.id)return;const g=(f=i.getCurrentLastSelection())==null?void 0:f.primary;let S;if(g!=null){const p=r.getRange(g.startRow,g.startColumn);S=p==null?void 0:p.getWrapStrategy()}o.next(S!=null?S:t)}),l=(c=i.getCurrentLastSelection())==null?void 0:c.primary;let d;if(l!=null){const u=r.getRange(l.startRow,l.startColumn);d=u==null?void 0:u.getWrapStrategy()}return o.next(d!=null?d:t),s.dispose})),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const ma=[{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 hm(n){const i=n.get(m.SheetsSelectionsService),e=n.get(a.IUniverInstanceService),t=0;return{id:m.SetTextRotationCommand.id,tooltip:"toolbar.textRotateMode.main",icon:ma[0].icon,type:E.MenuItemType.SELECTOR,selections:ma,value$:Pe(e,t,({worksheet:r})=>new O.Observable(o=>{var c,u;const s=n.get(a.ICommandService).onCommandExecuted(h=>{var p,v;const g=h.id;if(g!==m.SetTextRotationCommand.id&&g!==m.SetSelectionsOperation.id&&g!==m.SetWorksheetActiveOperation.id)return;const S=(p=i.getCurrentLastSelection())==null?void 0:p.primary;let f;if(S!=null){const C=r.getRange(S.startRow,S.startColumn);f=C==null?void 0:C.getTextRotation()}(f==null?void 0:f.v)===a.BooleanNumber.TRUE?o.next("v"):o.next((v=f&&f.a)!=null?v:t)}),l=(c=i.getCurrentLastSelection())==null?void 0:c.primary;let d;if(l!=null){const h=r.getRange(l.startRow,l.startColumn);d=h==null?void 0:h.getTextRotation()}return(d==null?void 0:d.v)===a.BooleanNumber.TRUE?o.next("v"):o.next((u=d&&d.a)!=null?u:t),s.dispose})),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Rr(n){return new O.Observable(e=>e.next(!n.get(E.IClipboardInterfaceService).supportClipboard))}function vn(n){return{id:ze.name,commandId:ze.id,type:E.MenuItemType.BUTTON,title:"rightClick.copy",icon:"Copy",disabled$:te(n,{workbookTypes:[m.WorkbookCopyPermission],worksheetTypes:[m.WorksheetCopyPermission],rangeTypes:[m.RangeProtectionPermissionViewPoint]}),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Ki(n){return{id:Xe.name,commandId:Xe.id,type:E.MenuItemType.BUTTON,title:"rightClick.paste",icon:"PasteSpecial",disabled$:Rr(n).pipe(O.combineLatestWith(te(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission,m.WorksheetSetCellValuePermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([i,e])=>i||e)),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const qn="sheet.menu.paste-special";function qi(n){return{id:qn,type:E.MenuItemType.SUBITEMS,icon:"PasteSpecial",title:"rightClick.pasteSpecial",hidden$:tn(n,E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET))}}function Qi(n){return{id:Sn.id,type:E.MenuItemType.BUTTON,title:"rightClick.pasteValue",disabled$:Rr(n).pipe(O.combineLatestWith(te(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellValuePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([i,e])=>i||e)),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Ji(n){return{id:fn.id,type:E.MenuItemType.BUTTON,title:"rightClick.pasteFormat",disabled$:Rr(n).pipe(O.combineLatestWith(te(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellStylePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([i,e])=>i||e)),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function $i(n){return{id:Vt.id,type:E.MenuItemType.BUTTON,title:"rightClick.pasteColWidth",disabled$:Rr(n).pipe(O.combineLatestWith(te(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetColumnStylePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([i,e])=>i||e))}}function eo(n){return{id:pn.id,type:E.MenuItemType.BUTTON,title:"rightClick.pasteBesidesBorder",disabled$:Rr(n).pipe(O.combineLatestWith(te(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission,m.WorksheetSetCellValuePermission,m.WorksheetSetRowStylePermission,m.WorksheetSetColumnStylePermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([i,e])=>i||e)),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function mm(n){return{id:m.SetWorksheetRowIsAutoHeightCommand.id,type:E.MenuItemType.BUTTON,icon:"AutoHeight",title:"rightClick.fitContent",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function gm(n){return{id:Ir.id,type:E.MenuItemType.BUTTON,icon:"AutoWidth",title:"rightClick.fitContent",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Il="sheet.menu.sheet-frozen";function Sm(n){return{id:Il,type:E.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Fo="sheet.header-menu.sheet-frozen";function ga(n){return{id:Fo,type:E.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function to(n){return{id:ht.id,type:E.MenuItemType.BUTTON,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function fm(n){return{id:Cr.id,type:E.MenuItemType.BUTTON,title:"rightClick.freezeRow",icon:"FreezeRowSingle",hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function pm(n){return{id:_r.id,type:E.MenuItemType.BUTTON,title:"rightClick.freezeCol",icon:"FreezeColumnSingle",hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function no(n){return{id:m.CancelFrozenCommand.id,type:E.MenuItemType.BUTTON,title:"rightClick.cancelFreeze",icon:"CancelFreezeSingle",hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function vm(n){return{id:mr.id,type:E.MenuItemType.BUTTON,icon:"Hide",title:"rightClick.hideSelectedRow",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Cm(n){return{id:gr.id,type:E.MenuItemType.BUTTON,icon:"Hide",title:"rightClick.hideSelectedColumn",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function _m(n){const i=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=[m.SetSelectionsOperation,m.SetRowHiddenMutation,m.SetRowVisibleMutation].map(o=>o.id);return{id:m.SetSelectedRowsVisibleCommand.id,type:E.MenuItemType.BUTTON,title:"rightClick.showHideRow",hidden$:Pe(i,!0,({worksheet:o})=>new O.Observable(s=>{function l(){var u;const c=(u=e.getCurrentSelections())==null?void 0:u.map(h=>h.range).filter(h=>h.rangeType===a.RANGE_TYPE.ROW);return!!(c!=null&&c.some(h=>{for(let g=h.startRow;g<=h.endRow;g++)if(!o.getRowRawVisible(g))return!0;return!1}))}const d=t.onCommandExecuted(c=>{r.findIndex(u=>u===c.id)!==-1&&s.next(!l())});return s.next(!l()),()=>d.dispose()})),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetRowStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Im(n){const i=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=[m.SetSelectionsOperation,m.SetColHiddenMutation,m.SetColVisibleMutation].map(o=>o.id);return{id:m.SetSelectedColsVisibleCommand.id,type:E.MenuItemType.BUTTON,title:"rightClick.showHideColumn",hidden$:Pe(i,!0,({worksheet:o})=>new O.Observable(s=>{function l(){var u;const c=(u=e.getCurrentSelections())==null?void 0:u.map(h=>h.range).filter(h=>h.rangeType===a.RANGE_TYPE.COLUMN);return!c||c.length===0?!1:!!c.some(h=>{for(let g=h.startColumn;g<=h.endColumn;g++)if(!o.getColVisible(g))return!0;return!1})}const d=t.onCommandExecuted(c=>{r.findIndex(u=>u===c.id)!==-1&&s.next(!l())});return s.next(!l()),()=>d.dispose()})),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetColumnStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function bm(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=0;return{id:m.SetRowHeightCommand.id,type:E.MenuItemType.BUTTON,icon:"AdjustHeight",label:{name:Hi,props:{prefix:"rightClick.rowHeight",suffix:"px",min:2,max:1e3}},value$:Pe(e,r,({worksheet:o})=>new O.Observable(s=>{function l(){var h;const c=(h=t.getCurrentLastSelection())==null?void 0:h.primary,u=c?o.getRowHeight(c.startRow):r;s.next(u)}const d=i.onCommandExecuted(c=>{const u=c.id;if(u===m.SetRangeValuesMutation.id||u===m.SetSelectionsOperation.id||u===m.SetWorksheetRowIsAutoHeightMutation.id)return l()});return l(),d.dispose})),hidden$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetRowStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Rm(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=0;return{id:m.SetColWidthCommand.id,type:E.MenuItemType.BUTTON,icon:"AdjustWidth",label:{name:Hi,props:{prefix:"rightClick.columnWidth",suffix:"px",min:2,max:1e3}},value$:Pe(e,r,({worksheet:o})=>new O.Observable(s=>{function l(){var h;const c=(h=t.getCurrentLastSelection())==null?void 0:h.primary;let u=r;c!=null&&(u=o.getColumnWidth(c.startColumn)),s.next(u)}const d=i.onCommandExecuted(c=>{const u=c.id;if(u===m.SetRangeValuesMutation.id||u===m.SetSelectionsOperation.id||u===m.SetWorksheetColWidthMutation.id)return l()});return l(),d.dispose})),hidden$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Er(n){var d;const i=n.get(a.IUniverInstanceService),e=n.get(be.DocSelectionManagerService),t=i.getUniverDocInstance(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),r=e.getActiveTextRange();if(t==null||r==null)return null;const o=(d=t.getBody())==null?void 0:d.textRuns;if(o==null)return;const{startOffset:s}=r;return o.find(({st:c,ed:u})=>s>=c&&s<=u)}var Em=Object.defineProperty,Tm=Object.getOwnPropertyDescriptor,wm=(n,i,e,t)=>{for(var r=t>1?void 0:t?Tm(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Em(i,e,r),r},xt=(n,i)=>(e,t)=>i(e,t,n);const ym="__SpreadsheetFreezeRowMainName__",bl="__SpreadsheetFreezeRowHeaderName__",Mm="__SpreadsheetFreezeColumnMainName__",Rl="__SpreadsheetFreezeColumnHeaderName__",ro=2,Pm=.01,Bn=a.createInterceptorKey("freezePermissionCheck");exports.HeaderFreezeRenderController=class extends a.Disposable{constructor(e,t,r,o,s,l,d,c){super();R(this,"_rowFreezeHeaderRect");R(this,"_rowFreezeMainRect");R(this,"_columnFreezeHeaderRect");R(this,"_columnFreezeMainRect");R(this,"_freezeDownSubs");R(this,"_freezePointerEnterSubs");R(this,"_freezePointerLeaveSubs");R(this,"_scenePointerMoveSub");R(this,"_scenePointerUpSub");R(this,"_changeToRow",-1);R(this,"_changeToColumn",-1);R(this,"_changeToOffsetX",0);R(this,"_changeToOffsetY",0);R(this,"_activeViewport",null);R(this,"_freezeNormalHeaderColor","");R(this,"_freezeNormalMainColor","");R(this,"_freezeActiveColor","");R(this,"_freezeHoverColor","");R(this,"_lastFreeze");R(this,"interceptor",new a.InterceptorManager({FREEZE_PERMISSION_CHECK:Bn}));this._context=e,this._sheetSkeletonManagerService=t,this._commandService=r,this._selectionManagerService=o,this._scrollManagerService=s,this._themeService=l,this._sheetInterceptorService=d,this._injector=c,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._themeChangeListener(),this._interceptorCommands(),this._bindViewportScroll(),this._zoomRefresh()}_createFreeze(e=0,t){var x;const r=t!=null?t:this._getFreeze();if(r==null)return null;const o=(x=this._sheetSkeletonManagerService.getCurrent())==null?void 0:x.skeleton,{startRow:s,startColumn:l}=r,d=this._getPositionByIndex(s,l);if(d==null||o==null)return null;const c=this._getSheetObject(),u=c.engine,h=(u==null?void 0:u.width)||0,g=(u==null?void 0:u.height)||0,S=c.scene,{startX:f,startY:p}=d,{rowTotalHeight:v,columnTotalWidth:C,rowHeaderWidthAndMarginLeft:I,columnHeaderHeightAndMarginTop:b}=o,T=h>C+I?h:C+b,M=g>v+b?g:v+b;this._changeToRow=s,this._changeToColumn=l,this._changeToOffsetX=f,this._changeToOffsetY=p;const y=Math.max(S.scaleX,S.scaleY);let P=ro/(y<1?1:y);if(e===0){(s===-1||s===0)&&(P=P*2);const A=P;this._rowFreezeHeaderRect=new w.Rect(bl,{fill:this._freezeNormalHeaderColor,width:I,height:P,left:0,top:p-A,zIndex:3});let N=this._freezeNormalHeaderColor;(s===-1||s===0)&&(N=this._freezeNormalMainColor),this._rowFreezeMainRect=new w.Rect(ym,{fill:N,width:T*2/y,height:P,left:I,top:p-A,zIndex:3}),S.addObjects([this._rowFreezeHeaderRect,this._rowFreezeMainRect],bt)}else{(l===-1||l===0)&&(P=P*2);const A=P;this._columnFreezeHeaderRect=new w.Rect(Rl,{fill:this._freezeNormalHeaderColor,width:P,height:b,left:f-A,top:0,zIndex:3});let N=this._freezeNormalHeaderColor;(l===-1||l===0)&&(N=this._freezeNormalMainColor),this._columnFreezeMainRect=new w.Rect(Mm,{fill:N,width:P,height:M*2/y,left:f-A,top:b,zIndex:3}),S.addObjects([this._columnFreezeHeaderRect,this._columnFreezeMainRect],bt)}this._eventBinding(e)}_eventBinding(e=0){let t=this._rowFreezeHeaderRect,r=this._rowFreezeMainRect;e===1&&(t=this._columnFreezeHeaderRect,r=this._columnFreezeMainRect);const o=this._getSheetObject();if(o==null)return;const{scene:s}=o;if(this._freezePointerEnterSubs=new O.Subscription,this._freezePointerLeaveSubs=new O.Subscription,this._freezeDownSubs=new O.Subscription,r){const c=r.onPointerEnter$.subscribeEvent(()=>{if(!this.interceptor.fetchThroughInterceptors(Bn)(!0,null))return!1;t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),s.setCursor(w.CURSOR_TYPE.GRAB)});this._freezePointerEnterSubs.add(c);const u=r.onPointerLeave$.subscribeEvent(()=>{t==null||t.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),s.resetCursor()});this._freezePointerLeaveSubs.add(u)}if(t){const c=t.onPointerEnter$.subscribeEvent(()=>{if(!this.interceptor.fetchThroughInterceptors(Bn)(!0,null))return!1;t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),s.setCursor(w.CURSOR_TYPE.GRAB)});this._freezePointerEnterSubs.add(c);const u=t.onPointerLeave$.subscribeEvent(()=>{t==null||t.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),s.resetCursor()});this._freezePointerLeaveSubs.add(u)}const l=t==null?void 0:t.onPointerDown$.subscribeEvent(c=>{this._freezeDown(c,t,r,e)});l&&this._freezeDownSubs.add(l);const d=r==null?void 0:r.onPointerDown$.subscribeEvent(c=>{this._freezeDown(c,t,r,e)});d&&this._freezeDownSubs.add(d)}_getCurrentLastVisible(){var C,I,b,T,M,y,P;const e=this._getSheetObject();if(e==null)return;const t=(C=this._sheetSkeletonManagerService.getCurrent())==null?void 0:C.skeleton;if(t==null)return;const r=e.scene,o=Math.max(r.scaleX,r.scaleY),s=this._scrollManagerService.getCurrentScrollState(),l=(e.engine.height-t.columnHeaderHeight)/o,d=(e.engine.width-t.rowHeaderWidth)/o,c=(I=s==null?void 0:s.sheetViewStartRow)!=null?I:0,u=c===0?-((b=s==null?void 0:s.offsetY)!=null?b:0):t.rowHeightAccumulation[c-1]-((T=s==null?void 0:s.offsetY)!=null?T:0);let h=0,g=!1;for(let x=c,A=t.rowHeightAccumulation.length;x<A;x++)if(t.rowHeightAccumulation[x]-u>l){h=x,g=!0;break}g||(h=t.rowHeightAccumulation.length-1);const S=(M=s==null?void 0:s.sheetViewStartColumn)!=null?M:0,f=S===0?-((y=s==null?void 0:s.offsetX)!=null?y:0):t.columnWidthAccumulation[S-1]-((P=s==null?void 0:s.offsetX)!=null?P:0);let p=0,v=!1;for(let x=S,A=t.columnWidthAccumulation.length;x<A;x++)if(t.columnWidthAccumulation[x]-f>d){p=x,v=!0;break}return v||(p=t.columnWidthAccumulation.length-1),{lastRow:h,lastColumn:p}}_getActiveViewport(e){var r;const t=(r=this._getSheetObject())==null?void 0:r.scene.getViewports();return t&&t.find(o=>o.isHit(new w.Vector2(e.offsetX,e.offsetY)))||null}_freezeDown(e,t,r,o=0){var f;const s=(f=this._sheetSkeletonManagerService.getCurrent())==null?void 0:f.skeleton;if(s==null)return;const l=this._getSheetObject();if(l==null)return;if(!this.interceptor.fetchThroughInterceptors(Bn)(!0,null))return!1;const{scene:c}=l;c.setCursor(w.CURSOR_TYPE.GRABBING),c.disableObjectsEvent();const u=this._getCurrentLastVisible(),h=u===void 0?Number.POSITIVE_INFINITY:s.rowHeightAccumulation[u.lastRow],g=u===void 0?Number.POSITIVE_INFINITY:s.columnWidthAccumulation[u.lastColumn-1]+s.rowHeaderWidth;this._activeViewport=null;const S=this._getFreeze();S&&(this._changeToColumn=S.startColumn,this._changeToRow=S.startRow),this._scenePointerMoveSub=c.onPointerMove$.subscribeEvent(p=>{var P,x,A,N;const v=this._getActiveViewport(p),{startX:C,startY:I,row:b,column:T}=qe(p.offsetX,p.offsetY,c,s,v||void 0,!0);if(!this.interceptor.fetchThroughInterceptors(Bn)(!0,null))return!1;c.setCursor(w.CURSOR_TYPE.GRABBING);const y=ro/Math.max(c.scaleX,c.scaleY);o===0?((P=t.transformByState({top:Math.min(I,h)-y/2}))==null||P.setProps({fill:this._freezeActiveColor}),(x=r.transformByState({top:Math.min(I,h)-y/2}))==null||x.setProps({fill:this._freezeNormalHeaderColor}),this._changeToRow=u===void 0?b:Math.min(b,u.lastRow),this._changeToOffsetY=Math.min(I,h),this._activeViewport=v):((A=t.transformByState({left:Math.min(C,g)-y/2}))==null||A.setProps({fill:this._freezeActiveColor}),(N=r.transformByState({left:Math.min(C,g)-y/2}))==null||N.setProps({fill:this._freezeNormalHeaderColor}),this._changeToColumn=u===void 0?T:Math.min(T,u.lastColumn),this._changeToOffsetX=C,this._activeViewport=v)}),this._scenePointerUpSub=c.onPointerUp$.subscribeEvent(()=>{var D,H;c.resetCursor(),c.enableObjectsEvent(),this._clearObserverEvent();const{rowHeaderWidthAndMarginLeft:p,columnHeaderHeightAndMarginTop:v}=s;o===0&&(this._changeToRow===0||this._changeToRow===-1)||o===1&&(this._changeToColumn===0||this._changeToColumn===-1)?(t.setProps({fill:this._freezeNormalHeaderColor}),r.setProps({fill:this._freezeNormalMainColor})):(t==null||t.setProps({fill:this._freezeNormalHeaderColor}),r==null||r.setProps({fill:this._freezeNormalHeaderColor}));const C=ro/Math.max(c.scaleX,c.scaleY);o===0?(this._changeToRow===0||this._changeToRow===-1)&&(t.transformByState({top:v-C}),r.transformByState({top:v-C})):(this._changeToColumn===0||this._changeToColumn===-1)&&(t.transformByState({left:p-C}),r.transformByState({left:p-C}));const I=this._scrollManagerService.getCurrentScrollState()||{sheetViewStartRow:0,sheetViewStartColumn:0},{sheetViewStartRow:b,sheetViewStartColumn:T}=I;if(T==null||b==null)return;const M=this._context.unit,y=M.getActiveSheet();if(!y)return;const P=(D=y.getConfig())==null?void 0:D.freeze;let x=(P==null?void 0:P.xSplit)||0,A=(P==null?void 0:P.ySplit)||0;const N=(H=this._activeViewport)==null?void 0:H.viewportKey;o===0&&(!N||N===w.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP||N===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP||N===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||N===w.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP?A=this._changeToRow-(P.startRow-P.ySplit):A=this._changeToRow-b,A=A<0?0:A),o===1&&(!N||N===w.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP||N===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP||N===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||N===w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT?x=this._changeToColumn-(P.startColumn-P.xSplit):x=this._changeToColumn-T,x=x<0?0:x),this._commandService.executeCommand(m.SetFrozenCommand.id,{startRow:A===0?-1:this._changeToRow,startColumn:x===0?-1:this._changeToColumn,ySplit:A,xSplit:x,unitId:M.getUnitId(),subUnitId:y.getSheetId()})})}_getViewports(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e,r=t.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT),o=t.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT),s=t.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP),l=t.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM),d=t.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP),c=t.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN),u=t.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP),h=t.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT),g=t.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(!(r==null||o==null||s==null||l==null||d==null||c==null||u==null||h==null||g==null))return{viewMain:c,viewMainLeftTop:u,viewMainLeft:h,viewMainTop:g,viewColumnLeft:r,viewColumnRight:o,viewRowTop:s,viewRowBottom:l,viewLeftTop:d}}_bindViewportScroll(){const e=this._getViewports();if(!e)return;const{viewRowBottom:t,viewColumnRight:r,viewMainLeft:o,viewMainTop:s}=e;this.disposeWithMe(this._scrollManagerService.validViewportScrollInfo$.subscribe(l=>{if(!l)return;const{scrollX:d,scrollY:c,viewportScrollX:u,viewportScrollY:h}=l;t.isActive&&t.updateScrollVal({scrollY:c,viewportScrollY:h}),r.isActive&&r.updateScrollVal({scrollX:d,viewportScrollX:u}),o.isActive&&o.updateScrollVal({scrollY:c,viewportScrollY:h}),s.isActive&&s.updateScrollVal({scrollX:d,viewportScrollX:u})}))}_updateViewport(e=-1,t=-1,r=0,o=0,s=3){var x;const l=(x=this._sheetSkeletonManagerService.getCurrent())==null?void 0:x.skeleton;if(l==null)return;const{rowHeaderWidthAndMarginLeft:d,columnHeaderHeightAndMarginTop:c}=l,u=this._getViewports();if(!u)return;const{viewMain:h,viewMainLeftTop:g,viewMainLeft:S,viewMainTop:f,viewColumnLeft:p,viewColumnRight:v,viewRowTop:C,viewRowBottom:I,viewLeftTop:b}=u;v.resizeWhenFreezeChange({left:d,top:0,height:c,right:0}),I.resizeWhenFreezeChange({left:0,top:c,bottom:0,width:d}),b.resizeWhenFreezeChange({left:0,top:0,width:d,height:c});let T=!0,M=!0;g.enable(),(e===-1||e===0)&&(T=!1),(t===-1||t===0)&&(M=!1);const y=l.getNoMergeCellPositionByIndexWithNoHeader(e-r,t-o),P=l.getNoMergeCellPositionByIndexWithNoHeader(e,t);if(g.disable(),f.disable(),S.disable(),C.disable(),p.disable(),g.resetPadding(),f.resetPadding(),S.resetPadding(),C.resetPadding(),p.resetPadding(),T===!1&&M===!1)h.resizeWhenFreezeChange({left:d,top:c,bottom:0,right:0}),h.resetPadding();else if(T===!0&&M===!1){const A=P.startY-y.startY;h.resizeWhenFreezeChange({left:d,top:c+A,bottom:0,right:0}),h.setPadding({startY:y.startY,endY:P.startY,startX:0,endX:0}),s&2&&this._commandService.executeCommand(je.id,{sheetViewStartRow:0,offsetY:0}),f.resizeWhenFreezeChange({left:d,top:c,height:A,right:0}),f.updateScrollVal({viewportScrollY:y.startY,rawScrollX:h.scrollX,viewportScrollX:h.viewportScrollX}),C.resizeWhenFreezeChange({left:0,top:c,width:d,height:A}),C.updateScrollVal({viewportScrollY:y.startY}),I.resizeWhenFreezeChange({left:0,top:c+A,bottom:0,width:d}),f.enable(),C.enable()}else if(T===!1&&M===!0){const A=P.startX-y.startX;h.resizeWhenFreezeChange({left:d+A,top:c,bottom:0,right:0}),h.setPadding({startX:y.startX,endX:P.startX,startY:0,endY:0}),s&1&&this._commandService.executeCommand(je.id,{sheetViewStartColumn:0,offsetX:0}),S.resizeWhenFreezeChange({left:d,top:c,width:A,bottom:0,right:0}),S.updateScrollVal({viewportScrollX:y.startX,rawScrollY:h.scrollY,viewportScrollY:h.viewportScrollY}),p.resizeWhenFreezeChange({left:d,top:0,width:A,height:c}),p.updateScrollVal({viewportScrollX:y.startX}),v.resizeWhenFreezeChange({left:d+A,top:0,height:c,right:0}),S.enable(),p.enable()}else{const A=P.startX-y.startX,N=P.startY-y.startY;h.resizeWhenFreezeChange({left:d+A,top:c+N,bottom:0,right:0}),h.setPadding({startY:y.startY,endY:P.startY,startX:y.startX,endX:P.startX}),s&&this._commandService.executeCommand(je.id,{...s&1?{sheetViewStartColumn:0,offsetX:0}:null,...s&2?{sheetViewStartRow:0,offsetY:0}:null}),S.resizeWhenFreezeChange({left:d,top:c+N,width:A,bottom:0}),S.updateScrollVal({viewportScrollX:y.startX,rawScrollY:h.scrollY,viewportScrollY:h.viewportScrollY}),f.resizeWhenFreezeChange({left:d+A,top:c,height:N,right:0}),f.updateScrollVal({viewportScrollY:y.startY,rawScrollX:h.scrollX,viewportScrollX:h.viewportScrollX}),g.resizeWhenFreezeChange({left:d,top:c,width:A,height:N}),g.updateScrollVal({viewportScrollX:y.startX,viewportScrollY:y.startY}),C.resizeWhenFreezeChange({left:0,top:c,width:d,height:N}),C.updateScrollVal({viewportScrollY:y.startY}),I.resizeWhenFreezeChange({left:0,top:c+N,bottom:0,width:d}),p.resizeWhenFreezeChange({left:d,top:0,width:A,height:c}),p.updateScrollVal({viewportScrollX:y.startX}),v.resizeWhenFreezeChange({left:d+A,top:0,height:c,right:0}),g.enable(),f.enable(),S.enable(),C.enable(),p.enable()}}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(e=>{[m.SetWorksheetActiveOperation.id,m.InsertRangeMoveDownCommand.id,m.InsertRangeMoveRightCommand.id].includes((e==null?void 0:e.commandId)||"")&&this._refreshCurrent()})))}_refreshCurrent(){const t=this._context.unit.getActiveSheet();if(!t)return;const r=t.getConfig().freeze,{startRow:o=-1,startColumn:s=-1,ySplit:l=0,xSplit:d=0}=r;this._refreshFreeze(o,s,l,d,0)}_themeChangeListener(){this._themeChange(this._themeService.getCurrentTheme()),this.disposeWithMe(this._themeService.currentTheme$.subscribe(e=>{this._clearFreeze(),this._themeChange(e),this._refreshCurrent()}))}_themeChange(e){this._freezeNormalHeaderColor=e.grey400,this._freezeNormalMainColor=new a.ColorKit(e.grey400).setAlpha(Pm).toRgbString(),this._freezeActiveColor=e.primaryColor,this._freezeHoverColor=e.grey500}_interceptorCommands(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{const t={redos:[],undos:[]},r=this._getFreeze();if(!r)return t;const o=s=>{const l=this._context.unit,d=l.getUnitId(),c=l.getActiveSheet();if(!c)return t;const u=c.getSheetId();this._refreshFreeze(s.startRow,s.startColumn,s.ySplit,s.xSplit,0);const h={...s,unitId:d,subUnitId:u,resetScroll:!1},g=m.SetFrozenMutationFactory(this._injector,h);return{undos:[{id:m.SetFrozenMutation.id,params:g}],redos:[{id:m.SetFrozenMutation.id,params:h}]}};if(e.id===m.InsertRowCommand.id){const s=e.params,{range:l,direction:d}=s,c=l.endRow-l.startRow+1;if(l.startRow+1<r.startRow||l.startRow+1===r.startRow&&d===a.Direction.UP){const u={...r,startRow:Math.max(1,r.startRow+c),ySplit:Math.max(1,r.ySplit+c)};return o(u)}}if(e.id===m.InsertColCommand.id){const s=e.params,{range:l,direction:d}=s,c=l.endColumn-l.startColumn+1;if(l.startColumn+1<r.startColumn||l.startColumn+1===r.startColumn&&d===a.Direction.LEFT){const u={...r,startColumn:Math.max(1,r.startColumn+c),xSplit:Math.max(1,r.xSplit+c)};return o(u)}}if(e.id===m.MoveColsCommand.id){const s=this._selectionManagerService.getCurrentSelections(),{fromRange:{startColumn:l},toRange:{startColumn:d}}=e.params,c=s==null?void 0:s.filter(C=>C.range.rangeType===a.RANGE_TYPE.COLUMN&&C.range.startColumn<=l&&l<=C.range.endColumn);if(!(c!=null&&c.length))return t;const u=c[0].range,h={...u,startColumn:d,endColumn:d+u.endColumn-u.startColumn};if(!r||r.startColumn<=0||u.startColumn>=r.startColumn&&h.startColumn>=r.startColumn||u.startColumn===h.startColumn||u.endColumn<r.startColumn&&h.startColumn<r.startColumn)return t;const g=u.endColumn-u.startColumn+1,S=Math.max(Math.min(r.startColumn,u.endColumn+1)-u.startColumn,0);let f,p;h.startColumn>=r.startColumn?(f=Math.max(r.startColumn-S,1),p=Math.max(r.xSplit-S,1)):(f=r.startColumn+g-S,p=r.xSplit+g-S);const v={...r,startColumn:f,xSplit:p};return o(v)}if(e.id===m.MoveRowsCommand.id){const s=this._selectionManagerService.getCurrentSelections(),{fromRange:{startRow:l},toRange:{startRow:d}}=e.params,c=s==null?void 0:s.filter(C=>C.range.rangeType===a.RANGE_TYPE.ROW&&C.range.startRow<=l&&l<=C.range.endRow);if(!(c!=null&&c.length))return t;const u=c[0].range,h={...u,startRow:d,endRow:d+u.endRow-u.startRow};if(!r||r.startRow<=0||u.startRow>=r.startRow&&h.startRow>=r.startRow||u.startRow===h.startRow||u.endRow<r.startRow&&h.startRow<r.startRow)return t;const g=u.endRow-u.startRow+1,S=Math.max(Math.min(r.startRow,u.endRow+1)-u.startRow,0);let f,p;h.startRow>=r.startRow?(f=Math.max(r.startRow-S,1),p=Math.max(r.ySplit-S,1)):(f=r.startRow+g-S,p=r.ySplit+g-S);const v={...r,startRow:f,ySplit:p};return o(v)}if(e.id===m.RemoveColCommand.id||e.id===m.RemoveRowCommand.id){const s=e.params,l=s.range;if(l.rangeType===a.RANGE_TYPE.COLUMN&&l.startColumn<r.startColumn){const d=Math.min(r.startColumn,l.endColumn+1)-l.startColumn,c={...r,startColumn:Math.max(1,r.startColumn-d),xSplit:Math.max(1,r.xSplit-d)};return o(c)}if(s.range.rangeType===a.RANGE_TYPE.ROW&&l.startRow<r.startRow){const d=Math.min(r.startRow,l.endRow+1)-l.startRow,c={...r,startRow:Math.max(1,r.startRow-d),ySplit:Math.max(1,r.ySplit-d)};return o(c)}}return t}}))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{switch(e.id){case m.SetFrozenMutation.id:case Le.id:{const t=this._lastFreeze,r=this._context.unit,o=r.getActiveSheet(),s=e.params,{unitId:l,subUnitId:d}=s;if(!(l===r.getUnitId()&&d===(o==null?void 0:o.getSheetId())))return;const c=o.getConfig().freeze;if(this._lastFreeze=c,c==null)return;let u=0;const{startRow:h=-1,startColumn:g=-1,ySplit:S=0,xSplit:f=0}=c;(!t||t.startRow!==h||t.ySplit!==S)&&(u|=2),(!t||t.startColumn!==g||t.xSplit!==f)&&(u|=1),s.resetScroll===!1&&(u=0),this._refreshFreeze(h,g,S,f,u)}break;case m.SetWorksheetRowHeightMutation.id:{const t=this._getFreeze(),r=t&&e.params.ranges.some(o=>o.startRow<t.startRow);e.params&&r&&this._refreshCurrent()}break;case m.SetWorksheetColWidthMutation.id:{const t=this._getFreeze();e.params&&t&&e.params.ranges.some(r=>r.startColumn<t.startColumn)&&this._refreshCurrent()}break;case m.SetWorksheetRowAutoHeightMutation.id:{const t=e.params,r=this._getFreeze();if(r&&r.startRow>-1&&t.rowsAutoHeightInfo.some(o=>o.row<r.startRow)){const o=this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._refreshCurrent(),setTimeout(()=>{o.unsubscribe()})})}}break;case m.SetColHiddenMutation.id:case m.SetColVisibleMutation.id:{const t=e.params,r=this._getFreeze(),o=t.ranges;r&&r.startColumn>-1&&o.some(s=>s.startColumn<r.startColumn)&&this._refreshCurrent()}break;case m.SetRowHiddenMutation.id:case m.SetRowVisibleMutation.id:{const t=e.params,r=this._getFreeze(),o=t.ranges;r&&r.startRow>-1&&o.some(s=>s.startRow<r.startRow)&&this._refreshCurrent()}break;case wi.id:case yi.id:this._refreshCurrent()}}))}_zoomRefresh(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;t.onTransformChange$.subscribeEvent(r=>{r.type===w.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&this._refreshCurrent()})}_clearObserverEvent(){var t,r;this._getSheetObject()!=null&&((t=this._scenePointerMoveSub)==null||t.unsubscribe(),(r=this._scenePointerUpSub)==null||r.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null)}_clearFreeze(){var t,r,o,s,l,d;(t=this._rowFreezeHeaderRect)==null||t.dispose(),(r=this._rowFreezeMainRect)==null||r.dispose(),(o=this._columnFreezeHeaderRect)==null||o.dispose(),(s=this._columnFreezeMainRect)==null||s.dispose(),this._getSheetObject()!=null&&([this._freezeDownSubs,this._freezePointerEnterSubs,this._freezePointerLeaveSubs].forEach(c=>{c==null||c.unsubscribe()}),this._freezeDownSubs=null,this._freezePointerEnterSubs=null,this._freezePointerLeaveSubs=null,(l=this._scenePointerMoveSub)==null||l.unsubscribe(),(d=this._scenePointerUpSub)==null||d.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null)}_getPositionByIndex(e,t){var c;if(this._getSheetObject()==null)return;const o=(c=this._sheetSkeletonManagerService.getCurrent())==null?void 0:c.skeleton,s=o==null?void 0:o.getNoMergeCellPositionByIndex(e,t);if(o==null)return;if(s!=null&&(!isNaN(s.endX)||!isNaN(s.endY)))return s;const{rowHeaderWidthAndMarginLeft:l,columnHeaderHeightAndMarginTop:d}=o;return{startX:l,endX:l,startY:d,endY:d}}_getFreeze(){var t;const e=(t=this._sheetSkeletonManagerService.getCurrent())==null?void 0:t.skeleton.getWorksheetConfig();if(e!=null)return e.freeze}_getSheetObject(){return Ye(this._context.unit,this._context)}_refreshFreeze(e,t,r,o,s){var d;const l={startRow:e,startColumn:t,ySplit:r,xSplit:o};this._clearFreeze(),this._createFreeze(0,l),this._createFreeze(1,l),this._updateViewport(e,t,r,o,s),(d=this._getSheetObject())==null||d.spreadsheet.makeForceDirty()}};exports.HeaderFreezeRenderController=wm([xt(1,a.Inject(exports.SheetSkeletonManagerService)),xt(2,a.ICommandService),xt(3,a.Inject(m.SheetsSelectionsService)),xt(4,a.Inject(exports.SheetScrollManagerService)),xt(5,a.Inject(a.ThemeService)),xt(6,a.Inject(m.SheetInterceptorService)),xt(7,a.Inject(a.Injector))],exports.HeaderFreezeRenderController);function Om(n){const i=n.get(m.SheetsSelectionsService),e=n.get(m.RangeProtectionRuleModel),t=n.get(a.IUniverInstanceService),r=n.get(m.MergeCellController),o=t.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET);return O.combineLatest([i.selectionMoveEnd$,o.pipe(O.map(s=>{var l;return(l=s==null?void 0:s.getUnitId())!=null?l:""})),o.pipe(O.switchMap(s=>{var l;return(l=s==null?void 0:s.activeSheet$)!=null?l:O.of(null)}))]).pipe(O.map(([s,l,d])=>{if(!d||!s||s.length===0)return!1;const c=d.getSheetId(),u=s.map(S=>S.range);if(r.interceptor.fetchThroughInterceptors(m.MERGE_CELL_INTERCEPTOR_CHECK)(!1,u))return!0;const g=e.getSubunitRuleList(l,c).map(S=>S.ranges).flat();if(s.length<2){const S=s[0].range;return g.some(p=>a.Rectangle.intersects(p,S)&&!a.Rectangle.contains(p,S))}for(let S=0;S<s.length;S++)for(let f=S+1;f<s.length;f++)if(a.Rectangle.intersects(s[S].range,s[f].range))return!0;return!1}))}function El(n,i){return!!tr(n,i,a.RANGE_TYPE.ROW)}function Tl(n,i){return!!tr(n,i,a.RANGE_TYPE.COLUMN)}function tr(n,i,e){return n.find(r=>{const o=r.range,{startRow:s,endRow:l,startColumn:d,endColumn:c,rangeType:u}=o;return u===a.RANGE_TYPE.ALL||u===a.RANGE_TYPE.NORMAL?!1:u===e&&(e===a.RANGE_TYPE.COLUMN&&d<=i&&i<=c||e===a.RANGE_TYPE.ROW&&s<=i&&i<=l)})}var xm=Object.defineProperty,Am=Object.getOwnPropertyDescriptor,Nm=(n,i,e,t)=>{for(var r=t>1?void 0:t?Am(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&xm(i,e,r),r},io=(n,i)=>(e,t)=>i(e,t,n);const Dm="__SpreadsheetHeaderMoveControllerBackground__",Hm="__SpreadsheetHeaderMoveControllerShapeLine__",km="rgba(0, 0, 0, 0.1)",Vm="rgb(119, 119, 119)",Wm=4,oo=a.createInterceptorKey("headerMovePermissionCheck");exports.HeaderMoveRenderController=class extends a.Disposable{constructor(e,t,r,o){super();R(this,"_startOffsetX",Number.NEGATIVE_INFINITY);R(this,"_startOffsetY",Number.NEGATIVE_INFINITY);R(this,"_moveHelperBackgroundShape");R(this,"_moveHelperLineShape");R(this,"_headerPointerDownSubs");R(this,"_headerPointerMoveSubs");R(this,"_headerPointerLeaveSubs");R(this,"_dragHeaderMoveSub");R(this,"_scenePointerUpSub");R(this,"_scrollTimer");R(this,"_changeFromColumn",-1);R(this,"_changeFromRow",-1);R(this,"_changeToColumn",-1);R(this,"_changeToRow",-1);R(this,"interceptor",new a.InterceptorManager({HEADER_MOVE_PERMISSION_CHECK:oo}));R(this,"_workbookSelections");this._context=e,this._sheetSkeletonManagerService=r,this._commandService=o,this._workbookSelections=t.getWorkbookSelections(this._context.unitId),this._init()}dispose(){var e,t,r,o,s,l,d,c;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(t=this._moveHelperLineShape)==null||t.dispose(),(r=this._headerPointerMoveSubs)==null||r.unsubscribe(),(o=this._headerPointerLeaveSubs)==null||o.unsubscribe(),(s=this._headerPointerDownSubs)==null||s.unsubscribe(),this._headerPointerMoveSubs=null,this._headerPointerLeaveSubs=null,this._headerPointerDownSubs=null,(l=this._dragHeaderMoveSub)==null||l.unsubscribe(),(d=this._scenePointerUpSub)==null||d.unsubscribe(),this._dragHeaderMoveSub=null,this._scenePointerUpSub=null,(c=this._scrollTimer)==null||c.dispose()}_init(){this._initialRowOrColumn(a.RANGE_TYPE.ROW),this._initialRowOrColumn(a.RANGE_TYPE.COLUMN)}_initialRowOrColumn(e=a.RANGE_TYPE.ROW){const t=this._context.components.get(he.COLUMN),r=this._context.components.get(he.ROW),o=this._context.scene,s=e===a.RANGE_TYPE.ROW?r:t,l=u=>{var I,b;const h=(I=this._sheetSkeletonManagerService.getCurrent())==null?void 0:I.skeleton;if(h==null)return;const g=(b=this._workbookSelections.getCurrentLastSelection())==null?void 0:b.range;if(!g||!this.interceptor.fetchThroughInterceptors(oo)(!1,g))return;const f=this._workbookSelections.getCurrentSelections(),{row:p,column:v}=qe(u.offsetX,u.offsetY,o,h);if(!tr(f,e===a.RANGE_TYPE.ROW?p:v,e)){o.resetCursor();return}o.setCursor(w.CURSOR_TYPE.GRAB)},d=()=>{var u,h;(u=this._moveHelperBackgroundShape)==null||u.hide(),(h=this._moveHelperLineShape)==null||h.hide(),o.resetCursor()},c=(u,h)=>{var W,k;if(h.isStopPropagation)return;const g=(W=this._sheetSkeletonManagerService.getCurrent())==null?void 0:W.skeleton;if(g==null)return;const S=(k=this._workbookSelections.getCurrentLastSelection())==null?void 0:k.range;if(!S||!this.interceptor.fetchThroughInterceptors(oo)(!1,S))return;const{offsetX:p,offsetY:v}=u,C=o.getCoordRelativeToViewport(w.Vector2.FromArray([p,v])),{x:I,y:b}=C;this._startOffsetX=I,this._startOffsetY=b;const{row:T,column:M}=qe(u.offsetX,u.offsetY,o,g);let y;e===a.RANGE_TYPE.ROW?(this._changeFromRow=T,y=w.ScrollTimerType.Y):(this._changeFromColumn=M,y=w.ScrollTimerType.X);const P=this._workbookSelections.getCurrentSelections(),x=tr(P,e===a.RANGE_TYPE.ROW?T:M,e);if(!x)return;const A=o.getScrollXYInfoByViewport(w.Vector2.FromArray([this._startOffsetX,this._startOffsetY]));this._newBackgroundAndLine(),o.setCursor(w.CURSOR_TYPE.GRABBING),o.disableObjectsEvent();let N=!1,D;const H=()=>{if(N)return;D=w.ScrollTimer.create(o,y),this._scrollTimer=D;const U=o.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);D.startScroll(I,b,U),N=!0};this._dragHeaderMoveSub=o.onPointerMove$.subscribeEvent(U=>{H();const{offsetX:B,offsetY:F}=U,{x:L,y:z}=o.getCoordRelativeToViewport(w.Vector2.FromArray([B,F]));this._rowColumnMoving(L,z,x,A,e),D.scrolling(L,z,()=>{this._rowColumnMoving(L,z,x,A,e)})}),this._scenePointerUpSub=o.onPointerUp$.subscribeEvent(()=>{var B,F,L;this._disposeBackgroundAndLine(),o.resetCursor(),o.enableObjectsEvent(),this._clearObserverEvent(),(B=this._scrollTimer)==null||B.dispose();const U=this._workbookSelections.getCurrentSelections();if(e===a.RANGE_TYPE.ROW){if(this._changeFromRow!==this._changeToRow&&this._changeToRow!==-1){const X=(F=((U==null?void 0:U.filter(Z=>Z.range.rangeType===a.RANGE_TYPE.ROW&&Z.range.startRow<=this._changeFromRow&&this._changeFromRow<=Z.range.endRow))||[])[0])==null?void 0:F.range;X&&this._commandService.executeCommand(m.MoveRowsCommand.id,{fromRange:X,toRange:{...X,startRow:this._changeToRow,endRow:this._changeToRow+X.endRow-X.startRow}})}this._changeToRow=this._changeFromRow=-1}else{if(this._changeFromColumn!==this._changeToColumn&&this._changeToColumn!==-1){const X=(L=((U==null?void 0:U.filter(Z=>Z.range.rangeType===a.RANGE_TYPE.COLUMN&&Z.range.startColumn<=this._changeFromColumn&&this._changeFromColumn<=Z.range.endColumn))||[])[0])==null?void 0:L.range;X&&this._commandService.executeCommand(m.MoveColsCommand.id,{fromRange:X,toRange:{...X,startColumn:this._changeToColumn,endColumn:this._changeToColumn+X.endColumn-X.startColumn}})}this._changeToColumn=this._changeFromColumn=-1}})};this._headerPointerMoveSubs=new O.Subscription,this._headerPointerMoveSubs.add(s.onPointerMove$.subscribeEvent(l)),this._headerPointerLeaveSubs=new O.Subscription,this._headerPointerLeaveSubs.add(s==null?void 0:s.onPointerLeave$.subscribeEvent(d)),this._headerPointerDownSubs=new O.Subscription,this._headerPointerDownSubs.add(s==null?void 0:s.onPointerDown$.subscribeEvent(c))}_rowColumnMoving(e,t,r,o,s){var z,X,Z,re,Q,oe,$;const l=this._context.scene,d=(z=this._sheetSkeletonManagerService.getCurrent())==null?void 0:z.skeleton;if(d==null)return;const{rowHeaderWidth:c,columnHeaderHeight:u,rowTotalHeight:h,columnTotalWidth:g}=d,S=l.getViewportScrollXY(l.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:f,scaleY:p}=l.getAncestorScale(),v=d.getCellIndexByOffset(e,t,f,p,S),{row:C,column:I}=v,b=d.getNoMergeCellPositionByIndex(C,I),{startX:T,startY:M,endX:y,endY:P}=b,x=this._sheetSkeletonManagerService.attachRangeWithCoord(r.range);if(x==null)return;const A=Math.max(f,f),{startX:N,endX:D,startY:H,endY:W,startRow:k,startColumn:U,endRow:B,endColumn:F}=x;s===a.RANGE_TYPE.ROW?(X=this._moveHelperBackgroundShape)==null||X.transformByState({height:W-H,width:g+c,left:0,top:H+(t-this._startOffsetY)/A+S.y-o.y}):(Z=this._moveHelperBackgroundShape)==null||Z.transformByState({height:h+u,width:D-N,left:N+(e-this._startOffsetX)/A+S.x-o.x,top:0}),(re=this._moveHelperBackgroundShape)==null||re.show();const L=Wm/A;if(s===a.RANGE_TYPE.ROW){let j=0;if(C<=k)j=M-L/2,this._changeToRow=C;else if(C>B)j=P-L/2,this._changeToRow=C+1;else return;(Q=this._moveHelperLineShape)==null||Q.transformByState({height:L,width:g,left:c,top:j})}else{let j=0;if(I<=U)j=T-L/2,this._changeToColumn=I;else if(I>F)j=y-L/2,this._changeToColumn=I+1;else return;(oe=this._moveHelperLineShape)==null||oe.transformByState({height:h,width:L,left:j,top:u})}($=this._moveHelperLineShape)==null||$.show()}_clearObserverEvent(){var e,t;(e=this._dragHeaderMoveSub)==null||e.unsubscribe(),(t=this._scenePointerUpSub)==null||t.unsubscribe(),this._dragHeaderMoveSub=null,this._scenePointerUpSub=null}_newBackgroundAndLine(){const e=this._context.scene;this._moveHelperBackgroundShape=new w.Rect(Dm,{fill:km,evented:!1,zIndex:100}),this._moveHelperLineShape=new w.Rect(Hm,{fill:Vm,evented:!1,zIndex:100}),e.addObjects([this._moveHelperBackgroundShape,this._moveHelperLineShape],bt)}_disposeBackgroundAndLine(){var e,t;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(t=this._moveHelperLineShape)==null||t.dispose()}};exports.HeaderMoveRenderController=Nm([io(1,a.Inject(m.SheetsSelectionsService)),io(2,a.Inject(exports.SheetSkeletonManagerService)),io(3,a.ICommandService)],exports.HeaderMoveRenderController);var jo=(n=>(n[n.VERTICAL=0]="VERTICAL",n[n.HORIZONTAL=1]="HORIZONTAL",n))(jo||{});const Um="rgba(120, 120, 120, 0.01)",so="rgb(68, 71, 70)",Yn=12,Lm=44,zo=4;class Sa extends w.Shape{constructor(e,t){super(e,t);R(this,"_size",Yn);R(this,"_color",so);R(this,"_mode",0);this.setShapeProps(t)}get size(){return this._size}get mode(){return this._mode}get color(){return this._color}_draw(e){const t=this.getScene();if(!t)return;const{scaleX:r,scaleY:o}=t.getAncestorScale(),s=Math.max(r,o),l=Yn/s,d=zo/s;let{width:c,height:u}=this,h=0,g=0;this.mode===0?(c=d,h=l-d):(u=d,g=l-d),w.Rect.drawWith(e,{width:this.width,height:this.height,left:0,top:0,fill:Um}),w.Rect.drawWith(e,{width:c,height:u,fill:so,radius:d}),e.save(),e.transform(1,0,0,1,h,g),w.Rect.drawWith(e,{width:c,height:u,fill:so,radius:d}),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:Yn,height:this.size}):this.transformByState({width:this.size,height:Yn}),this}}var Bm=Object.defineProperty,Fm=Object.getOwnPropertyDescriptor,jm=(n,i,e,t)=>{for(var r=t>1?void 0:t?Fm(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Bm(i,e,r),r},ao=(n,i)=>(e,t)=>i(e,t,n);const zm="__SpreadsheetHeaderResizeControllerShapeRow__",Xm="__SpreadsheetHeaderResizeControllerShapeColumn__",fa="__SpreadsheetHeaderResizeControllerShapeHelper__",pa="rgb(199, 199, 199)",Ym=2,lo=a.createInterceptorKey("headerResizePermissionCheck");exports.HeaderResizeRenderController=class extends a.Disposable{constructor(e,t,r,o){super();R(this,"_currentRow",0);R(this,"_currentColumn",0);R(this,"_rowResizeRect");R(this,"_columnResizeRect");R(this,"_headerPointerSubs");R(this,"_scenePointerMoveSub");R(this,"_scenePointerUpSub");R(this,"_resizeHelperShape");R(this,"_startOffsetX",Number.POSITIVE_INFINITY);R(this,"_startOffsetY",Number.POSITIVE_INFINITY);R(this,"interceptor",new a.InterceptorManager({HEADER_RESIZE_PERMISSION_CHECK:lo}));this._context=e,this._sheetSkeletonManagerService=t,this._selectionManagerService=r,this._commandService=o,this._init()}dispose(){var e,t,r;(e=this._rowResizeRect)==null||e.dispose(),this._rowResizeRect=null,(t=this._columnResizeRect)==null||t.dispose(),this._columnResizeRect=null,(r=this._headerPointerSubs)==null||r.unsubscribe(),this._headerPointerSubs=null}_init(){const e=this._context.scene;this._rowResizeRect=new Sa(zm,{visible:!1,mode:jo.HORIZONTAL,zIndex:100}),this._columnResizeRect=new Sa(Xm,{visible:!1,mode:jo.VERTICAL,zIndex:100}),e.addObjects([this._rowResizeRect,this._columnResizeRect],bt),this._initialHover(0),this._initialHover(1),this._initialHoverResize(0),this._initialHoverResize(1)}_initialHover(e=0){const t=this._context.components.get(he.COLUMN),r=this._context.components.get(he.ROW),o=this._context.scene,s=e===0?r:t,l=(c,u)=>{var h,g;(h=this._rowResizeRect)==null||h.hide(),(g=this._columnResizeRect)==null||g.hide()},d=(c,u)=>{var A;const h=(A=this._sheetSkeletonManagerService.getCurrent())==null?void 0:A.skeleton;if(h==null||this._rowResizeRect==null||this._columnResizeRect==null)return;const{rowHeaderWidth:g,columnHeaderHeight:S}=h,{startX:f,startY:p,endX:v,endY:C,row:I,column:b}=qe(c.offsetX,c.offsetY,o,h),T=Kn(c.offsetX,c.offsetY,o),{scaleX:M,scaleY:y}=o.getAncestorScale(),P=Math.max(M,y),x=Yn/P;if(e===0){let N=p-x/2;if(T.y<=p+x/2&&T.y>=p)this._currentRow=I-1;else if(T.y>=C-x/2&&T.y<=C)this._currentRow=I,N=C-x/2;else{this._rowResizeRect.hide();return}if(this._currentRow===-1)return;if(!this.interceptor.fetchThroughInterceptors(lo)(null,{row:this._currentRow}))return!1;const H=Math.min(Lm,g/3);this._rowResizeRect.transformByState({left:g/2-H/2,top:N}),this._rowResizeRect.setShapeProps({size:H}),this._rowResizeRect.show()}else{let N=f-x/2;if(T.x<=f+x/2&&T.x>=f)this._currentColumn=b-1;else if(T.x>=v-x/2&&T.x<=v)this._currentColumn=b,N=v-x/2;else{this._columnResizeRect.hide();return}if(this._currentColumn===-1)return;if(!this.interceptor.fetchThroughInterceptors(lo)(null,{col:this._currentColumn}))return!1;const H=S*.7;this._columnResizeRect.transformByState({left:N,top:S/2-H/2}),this._columnResizeRect.setShapeProps({size:H}),this._columnResizeRect.show()}};this._headerPointerSubs=new O.Subscription,this._headerPointerSubs.add(s==null?void 0:s.onPointerMove$.subscribeEvent(d)),this._headerPointerSubs.add(s==null?void 0:s.onPointerLeave$.subscribeEvent(l))}_initialHoverResize(e=0){const t=this._context.scene,r=e===0?this._rowResizeRect:this._columnResizeRect;r!=null&&(this.disposeWithMe(r.onPointerEnter$.subscribeEvent(()=>{r!=null&&(r.show(),t.setCursor(e===0?w.CURSOR_TYPE.ROW_RESIZE:w.CURSOR_TYPE.COLUMN_RESIZE))})),this.disposeWithMe(r.onPointerLeave$.subscribeEvent(()=>{r!=null&&(r.hide(),t.resetCursor())})),this.disposeWithMe(r.onPointerDown$.subscribeEvent(o=>{var F,L,z,X,Z,re,Q;const s=(F=this._sheetSkeletonManagerService.getCurrent())==null?void 0:F.skeleton;if(s==null)return;const l=this._context.scene,d=l.getEngine(),c=(d==null?void 0:d.height)||0,u=(d==null?void 0:d.width)||0,h=l.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=(((z=(L=h==null?void 0:h.getScrollBar())==null?void 0:L.horizonScrollTrack)==null?void 0:z.height)||0)+10,S=(((Z=(X=h==null?void 0:h.getScrollBar())==null?void 0:X.verticalScrollTrack)==null?void 0:Z.width)||0)+10,f=Kn(o.offsetX,o.offsetY,l),{scaleX:p,scaleY:v}=l.getAncestorScale();this._startOffsetX=f.x,this._startOffsetY=f.y;const C=s.getOffsetByPositionX(this._currentColumn),I=s.getOffsetByPositionY(this._currentRow),b=s.getNoMergeCellPositionByIndex(this._currentRow,this._currentColumn);let T=!1,M=0,y=0;const{columnTotalWidth:P,rowHeaderWidth:x,rowTotalHeight:A,columnHeaderHeight:N}=s,D=u>P+x?u:P+x,H=c>A+N?c:A+N,W=Math.max(p,v),k=zo/W;e===0?this._resizeHelperShape=new w.Rect(fa,{width:D,height:k,fill:pa,left:0,top:I-k/2}):this._resizeHelperShape=new w.Rect(fa,{width:k,height:H,fill:pa,left:C-k/2,top:0});const U=((re=this._columnResizeRect)==null?void 0:re.left)||0,B=((Q=this._rowResizeRect)==null?void 0:Q.top)||0;l.addObject(this._resizeHelperShape,bt),l.disableObjectsEvent(),this._scenePointerMoveSub=l.onPointerMove$.subscribeEvent(oe=>{var se,Ce,Ee,Mt,nt,Dr;const $=l.getCoordRelativeToViewport(w.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),j=l.getScrollXYInfoByViewport($,h),Y=Kn(oe.offsetX,oe.offsetY,l),{x:q,y:ee}=Y,{scaleX:de,scaleY:me}=l.getAncestorScale(),ce=Math.max(de,me),ie=zo/ce;M=q-this._startOffsetX-ie/2,y=ee-this._startOffsetY-ie/2,Math.abs(e===0?y:M)>=Ym&&(T=!0),e===0?(y>c-g+j.y-b.startY&&(y=c-g+j.y-b.startY),y<-(b.endY-b.startY)+2&&(y=-(b.endY-b.startY)+2),T&&((se=this._resizeHelperShape)==null||se.transformByState({top:I+y}),(Ce=this._rowResizeRect)==null||Ce.transformByState({top:B+y+ie/2}),(Ee=this._rowResizeRect)==null||Ee.show(),l.setCursor(w.CURSOR_TYPE.ROW_RESIZE))):(M>u-S+j.x-b.startX&&(M=u-S+j.x-b.startX),M<-(b.endX-b.startX)+2&&(M=-(b.endX-b.startX)+2),T&&((Mt=this._resizeHelperShape)==null||Mt.transformByState({left:C+M}),(nt=this._columnResizeRect)==null||nt.transformByState({left:U+M+ie/2}),(Dr=this._columnResizeRect)==null||Dr.show(),l.setCursor(w.CURSOR_TYPE.COLUMN_RESIZE)))}),this._scenePointerUpSub=l.onPointerUp$.subscribeEvent(oe=>{var j,Y,q;const $=this._context.scene;this._clearObserverEvent(),(j=this._resizeHelperShape)==null||j.dispose(),this._resizeHelperShape=null,$.enableObjectsEvent(),T&&($.resetCursor(),(Y=this._rowResizeRect)==null||Y.hide(),(q=this._columnResizeRect)==null||q.hide(),e===0?this._commandService.executeCommand(m.DeltaRowHeightCommand.id,{deltaY:y,anchorRow:this._currentRow}):this._commandService.executeCommand(m.DeltaColumnWidthCommand.id,{deltaX:M,anchorCol:this._currentColumn}))})})),this.disposeWithMe(r.onDblclick$.subscribeEvent(()=>{var h,g,S;this._context.scene.resetCursor();const s=(h=this._sheetSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(!s)return;const l=0,d=0,c=s.worksheet.getRowCount()-1||0,u=s.worksheet.getColumnCount()-1||0;switch(e){case 1:{const f=this._selectionManagerService.getCurrentSelections(),p=[];for(let v=0;v<f.length;v++){const C=f[v];C.range.rangeType===a.RANGE_TYPE.COLUMN&&this._currentColumn<=C.range.endColumn&&this._currentColumn>=C.range.startColumn&&p.push({startColumn:C.range.startColumn,endColumn:C.range.endColumn,startRow:l,endRow:c})}p.length===0&&p.push({startColumn:this._currentColumn,endColumn:this._currentColumn,startRow:l,endRow:c}),this._commandService.executeCommand(Ir.id,{ranges:p}),(g=this._columnResizeRect)==null||g.hide();break}case 0:this._commandService.executeCommand(m.SetWorksheetRowIsAutoHeightCommand.id,{ranges:[{startRow:this._currentRow,endRow:this._currentRow,startColumn:d,endColumn:u}]}),(S=this._rowResizeRect)==null||S.hide();break}})))}_clearObserverEvent(){var e,t;(e=this._scenePointerMoveSub)==null||e.unsubscribe(),(t=this._scenePointerUpSub)==null||t.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null}};exports.HeaderResizeRenderController=jm([ao(1,a.Inject(exports.SheetSkeletonManagerService)),ao(2,a.Inject(m.SheetsSelectionsService)),ao(3,a.ICommandService)],exports.HeaderResizeRenderController);var Gm=Object.defineProperty,Zm=Object.getOwnPropertyDescriptor,Km=(n,i,e,t)=>{for(var r=t>1?void 0:t?Zm(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Gm(i,e,r),r},Wr=(n,i)=>(e,t)=>i(e,t,n);const qm=60;exports.SheetRenderController=class extends a.RxDisposable{constructor(e,t,r,o,s){super();R(this,"_renderFrameTimeMetric",null);R(this,"_renderFrameTags",{});R(this,"_afterRenderMetric$",new O.Subject);this._context=e,this._sheetSkeletonManagerService=t,this._sheetRenderService=r,this._commandService=o,this._telemetryService=s,this._addNewRender(),this._initRenderMetricSubscriber()}_addNewRender(){const{scene:e,engine:t,unit:r}=this._context;this._addComponent(r),this._initRerenderScheduler(),this._initCommandListener();const o=this._context.unit.getActiveSheet();if(!o)throw new Error("No active sheet found");const s=o.getSheetId();this._sheetSkeletonManagerService.setCurrent({sheetId:s}),t.runRenderLoop(()=>e.render())}_initRenderMetricSubscriber(){if(!this._telemetryService)return;const{engine:e}=this._context;e.beginFrame$.subscribe(()=>{this._renderFrameTimeMetric=null,this._renderFrameTags={}}),e.endFrame$.subscribe(()=>{this._renderFrameTimeMetric&&Object.keys(this._renderFrameTimeMetric).filter(o=>o.startsWith(w.SHEET_EXTENSION_PREFIX)).length>0&&this._afterRenderMetric$.next({frameTimeMetric:this._renderFrameTimeMetric,tags:this._renderFrameTags})}),e.renderFrameTimeMetric$.subscribe(([r,o])=>{this._renderFrameTimeMetric||(this._renderFrameTimeMetric={}),this._renderFrameTimeMetric[r]||(this._renderFrameTimeMetric[r]=[]),this._renderFrameTimeMetric[r].push(Math.round(o*100)/100)}),e.renderFrameTags$.subscribe(([r,o])=>{this._renderFrameTags[r]=o});const t=[];this._afterRenderMetric$.pipe(O.withLatestFrom(e.endFrame$)).subscribe(([r,o])=>{t.push({FPS:o.FPS,elapsedTime:o.elapsedTime,frameTime:Math.round(o.frameTime*100)/100,...r.frameTimeMetric,...r.tags}),t.length>qm&&(this._renderMetricCapture(t),t.length=0)})}_renderMetricCapture(e){const t=e;if(t.length===0)return;const r=g=>{let S=0;const p=Object.entries(g).filter(([C,I])=>Array.isArray(I)).map(([C])=>C).reduce((C,I)=>{const b=g[I].reduce((T,M)=>T+M,0);return C[I]=b,C},{});return Object.keys(g).filter(C=>C.startsWith(w.SHEET_EXTENSION_PREFIX)).forEach(C=>{S+=p[C]}),{...p,extensionTotal:S}},o=e.map(g=>({...g,...r(g)})),l=(g=>Object.entries(g[0]).filter(([p,v])=>!["elapsedTime"].includes(p)).filter(([p,v])=>typeof v=="number").map(([p])=>p).reduce((p,v)=>{const C=g.map(M=>M[v]),I=Math.max(...C),b=Math.min(...C),T=C.reduce((M,y)=>M+y,0)/C.length;return p[v]={max:Math.round(I*100)/100,min:Math.round(b*100)/100,avg:Math.round(T*100)/100},p},{}))(o),d=t[t.length-1].elapsedTime,c=this._context.unit.getActiveSheet().getSheetId(),u=this._context.unit.getUnitId(),h={sheetId:c,unitId:u,elapsedTimeToStart:d,...l};this._telemetryService.capture("sheet_render_cost",h)}_addComponent(e){const{scene:t,components:r}=this._context,o=e.getActiveSheet(),s=new w.Spreadsheet(he.MAIN);this._addViewport(o);const l=new w.SpreadsheetRowHeader(he.ROW),d=new w.SpreadsheetColumnHeader(he.COLUMN),c=new w.Rect(he.LEFT_TOP,{zIndex:2,left:-1,top:-1,fill:"rgb(248, 249, 250)",stroke:"rgb(217, 217, 217)",strokeWidth:1});this._context.mainComponent=s,r.set(he.MAIN,s),r.set(he.ROW,l),r.set(he.COLUMN,d),r.set(he.LEFT_TOP,c),t.addObjects([s],Ws),t.addObjects([l,d,c],bt),t.enableLayerCache(Ws,bt)}_initViewports(e,t,r){const l=new w.Viewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN,e,{left:t.width,top:r.height,bottom:0,right:0,isWheelPreventDefaultX:!0,allowCache:!0,bufferEdgeX:100,bufferEdgeY:100}),d=new w.Viewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:0,bufferEdgeY:0}),c=new w.Viewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:0,bufferEdgeY:100}),u=new w.Viewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:100,bufferEdgeY:0}),h=new w.Viewport(w.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP,e,{active:!1,isWheelPreventDefaultX:!0}),g=new w.Viewport(w.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM,e,{left:0,top:r.height,bottom:0,width:t.width,isWheelPreventDefaultX:!0}),S=new w.Viewport(w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT,e,{active:!1,isWheelPreventDefaultX:!0}),f=new w.Viewport(w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT,e,{left:t.width,top:0,height:r.height,right:0,isWheelPreventDefaultX:!0}),p=new w.Viewport(w.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP,e,{left:0,top:0,width:t.width,height:r.height,isWheelPreventDefaultX:!0});return{viewMain:l,viewLeftTop:p,viewMainLeftTop:d,viewMainLeft:c,viewMainTop:u,viewColumnLeft:S,viewRowTop:h,viewRowBottom:g,viewColumnRight:f}}_addViewport(e){const t=this._context.scene,{rowHeader:r,columnHeader:o}=e.getConfig(),{viewMain:s}=this._initViewports(t,r,o);return new w.ScrollBar(s),t.attachControl(),s}_initRerenderScheduler(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(!e)return null;const{skeleton:t,sheetId:r}=e,o=this._context.unit,s=o==null?void 0:o.getSheetBySheetId(r);if(o==null||s==null)return;const{mainComponent:l,components:d}=this._context,c=l,u=d.get(he.ROW),h=d.get(he.COLUMN),g=d.get(he.LEFT_TOP),{rowHeaderWidth:S,columnHeaderHeight:f}=t;c==null||c.updateSkeleton(t),u==null||u.updateSkeleton(t),h==null||h.updateSkeleton(t),g==null||g.transformByState({width:S,height:f});const p=this._context.scene.getObject(bl);p&&p.transformByState({top:f-p.height});const v=this._context.scene.getObject(Rl);v&&v.transformByState({height:f})}))}_initCommandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{const{unit:t}=this._context,{id:r}=e;if(m.COMMAND_LISTENER_SKELETON_CHANGE.includes(r)||this._sheetRenderService.checkMutationShouldTriggerRerender(r)){const o=e.params,{unitId:s,subUnitId:l}=o,d=t.getActiveSheet();if(!d)return;const c=this._context.unitId,u=d.getSheetId();if(s!==c||l!==u)return;this._sheetSkeletonManagerService.makeDirty({sheetId:u,commandId:r},!0),this._sheetSkeletonManagerService.setCurrent({sheetId:u,commandId:r})}else m.COMMAND_LISTENER_VALUE_CHANGE.includes(r)&&this._sheetSkeletonManagerService.reCalculate();e.type===a.CommandType.MUTATION&&this._markUnitDirty(e)}))}_markUnitDirty(e){const{mainComponent:t,scene:r}=this._context;if(e.id===G.SetFormulaCalculationNotificationMutation.id&&e.params.stageInfo!=null||(t&&t.makeDirty(),r.makeDirty(),!e.params))return;const o=e.params,s=this._spreadsheetViewports(r);if(e.id===m.SetRangeValuesMutation.id&&o.cellValue){const l=this._cellValueToRange(o.cellValue),d=this._rangeToBounds([l]);this._markViewportDirty(s,d),t.setDirtyArea(d)}if(e.id===m.MoveRangeMutation.id&&o.from&&o.to){const l=o.fromRange||this._cellValueToRange(o.from.value),d=o.toRange||this._cellValueToRange(o.to.value),c=this._rangeToBounds([l,d]);this._markViewportDirty(s,c),t.setDirtyArea(c)}}_cellValueToRange(e){let t=0,r=0,o=0,s=0;for(const[h,g]of Object.entries(e)){for(const S in g)t>Number(S)&&(t=Number(S)),r<Number(S)&&(r=Number(S));o>Number(h)&&(o=Number(h)),s<Number(h)&&(s=Number(h))}return{startRow:o,endRow:s,startColumn:t,endColumn:r}}_rangeToBounds(e){const t=this._sheetSkeletonManagerService.getCurrent().skeleton,{rowHeightAccumulation:r,columnWidthAccumulation:o,rowHeaderWidth:s,columnHeaderHeight:l}=t,d=[];for(const c of e){const{startRow:u,endRow:h,startColumn:g,endColumn:S}=c,f=u===0?0:r[u-1]+l,p=r[h]+l,v=g===0?0:o[g-1]+s,C=o[S]+s;d.push({top:f,left:v,bottom:p,right:C,width:C-v,height:p-f})}return d}_markViewportDirty(e,t){const r=e.filter(o=>o.isActive&&o.cacheBound);for(const o of r)for(const s of t)a.Rectangle.hasIntersectionBetweenTwoRect(o.cacheBound,s)&&o.markDirty(!0)}_spreadsheetViewports(e){return e.getViewports().filter(t=>["viewMain","viewMainLeftTop","viewMainTop","viewMainLeft"].includes(t.viewportKey))}};exports.SheetRenderController=Km([Wr(1,a.Inject(exports.SheetSkeletonManagerService)),Wr(2,a.Inject(exports.SheetsRenderService)),Wr(3,a.ICommandService),Wr(4,a.Optional(Sd.ITelemetryService))],exports.SheetRenderController);var Ve=function(){return Ve=Object.assign||function(n){for(var i,e=1,t=arguments.length;e<t;e++){i=arguments[e];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(n[r]=i[r])}return n},Ve.apply(this,arguments)},Qm=function(n,i){var e={};for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&i.indexOf(t)<0&&(e[t]=n[t]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,t=Object.getOwnPropertySymbols(n);r<t.length;r++)i.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(n,t[r])&&(e[t[r]]=n[t[r]]);return e},Re=V.forwardRef(function(n,i){var e=n.icon,t=n.id,r=n.className,o=n.extend,s=Qm(n,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(t," ").concat(r||"").trim(),d=V.useRef("_".concat(eg()));return wl(e,"".concat(t),{defIds:e.defIds,idSuffix:d.current},Ve({ref:i,className:l},s),o)});function wl(n,i,e,t,r){return V.createElement(n.tag,Ve(Ve({key:i},Jm(n,e,r)),t),($m(n,e).children||[]).map(function(o,s){return wl(o,"".concat(i,"-").concat(n.tag,"-").concat(s),e,void 0,r)}))}function Jm(n,i,e){var t=Ve({},n.attrs);e!=null&&e.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=e.colorChannel1);var r=i.defIds;return!r||r.length===0||(n.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+i.idSuffix),Object.entries(t).forEach(function(o){var s=o[0],l=o[1];typeof l=="string"&&(t[s]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(i.idSuffix,")")))})),t}function $m(n,i){var e,t=i.defIds;return!t||t.length===0?n:n.tag==="defs"&&(!((e=n.children)===null||e===void 0)&&e.length)?Ve(Ve({},n),{children:n.children.map(function(r){return typeof r.attrs.id=="string"&&t&&t.indexOf(r.attrs.id)>-1?Ve(Ve({},r),{attrs:Ve(Ve({},r.attrs),{id:r.attrs.id+i.idSuffix})}):r})}):n}function eg(){return Math.random().toString(36).substring(2,8)}Re.displayName="UniverIcon";var tg={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"}}]},yl=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"autofill",ref:i,icon:tg}))});yl.displayName="Autofill";var ng={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},mt=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"check-mark-single",ref:i,icon:ng}))});mt.displayName="CheckMarkSingle";var rg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.71274 2.86421C3.47843 2.6299 3.09853 2.6299 2.86421 2.86421C2.6299 3.09853 2.6299 3.47843 2.86421 3.71274L7.15154 8.00007L2.86421 12.2874C2.6299 12.5217 2.6299 12.9016 2.86421 13.1359C3.09853 13.3702 3.47843 13.3702 3.71274 13.1359L8.00007 8.84859L12.2874 13.1359C12.5217 13.3702 12.9016 13.3702 13.1359 13.1359C13.3702 12.9016 13.3702 12.5217 13.1359 12.2874L8.84859 8.00007L13.1359 3.71274C13.3702 3.47843 13.3702 3.09853 13.1359 2.86421C12.9016 2.6299 12.5217 2.6299 12.2874 2.86421L8.00007 7.15154L3.71274 2.86421Z"}}]},Ml=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"close-single",ref:i,icon:rg}))});Ml.displayName="CloseSingle";var ig={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"g",attrs:{fill:"currentColor",clipPath:"url(#convert-single_clip0_911_593)"},children:[{tag:"path",attrs:{d:"M2.44766.848145C1.564.848145.847656 1.56449.847656 2.44814V6.44814C.847656 7.3318 1.564 8.04814 2.44766 8.04814H6.44766C7.33131 8.04814 8.04766 7.3318 8.04766 6.44814V2.44814C8.04766 1.56449 7.33131.848145 6.44766.848145H2.44766zM2.04766 6.44814V5.04824H3.84775V6.84814H2.44766C2.22674 6.84814 2.04766 6.66906 2.04766 6.44814zM2.04766 3.84824H3.84775V2.04814H2.44766C2.22674 2.04814 2.04766 2.22723 2.04766 2.44814V3.84824zM5.04775 6.84814V5.04824H6.84766V6.44814C6.84766 6.66906 6.66857 6.84814 6.44766 6.84814H5.04775zM5.04775 3.84824H6.84766V2.44814C6.84766 2.22723 6.66857 2.04814 6.44766 2.04814H5.04775V3.84824zM9.55215 7.95166C8.66849 7.95166 7.95215 8.668 7.95215 9.55166V13.5517C7.95215 14.4353 8.66849 15.1517 9.55215 15.1517L11.5522 15.1517 13.5521 15.1517C14.4358 15.1517 15.1521 14.4353 15.1521 13.5517L15.1521 11.5518 15.1521 9.55166C15.1521 8.668 14.4358 7.95166 13.5521 7.95166H9.55215zM13.9521 10.9518V9.55166C13.9521 9.33075 13.7731 9.15166 13.5521 9.15166H12.1522V10.9518H13.9521zM10.9522 10.9518V9.15166H9.55215C9.33123 9.15166 9.15215 9.33075 9.15215 9.55166V10.9518H10.9522zM9.15215 12.1518H10.9522V13.9517H9.55215C9.33123 13.9517 9.15215 13.7726 9.15215 13.5517V12.1518zM12.1522 12.1518H13.9521V13.5517C13.9521 13.7726 13.7731 13.9517 13.5521 13.9517H12.1522V12.1518z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{d:"M9.62158 2.44912C9.62158 2.11775 9.89021 1.84912 10.2216 1.84912H12.7516C13.6352 1.84912 14.3516 2.56547 14.3516 3.44912V5.9791C14.3516 6.31047 14.0829 6.5791 13.7516 6.5791 13.4202 6.5791 13.1516 6.31047 13.1516 5.9791V3.44912C13.1516 3.22821 12.9725 3.04912 12.7516 3.04912H10.2216C9.89021 3.04912 9.62158 2.78049 9.62158 2.44912zM5.77871 14.1507C6.11008 14.1507 6.37871 13.8821 6.37871 13.5507 6.37871 13.2193 6.11008 12.9507 5.77871 12.9507L3.24873 12.9507C3.02782 12.9507 2.84873 12.7716 2.84873 12.5507L2.84873 10.0207C2.84873 9.68933 2.5801 9.4207 2.24873 9.4207 1.91736 9.4207 1.64873 9.68933 1.64873 10.0207L1.64873 12.5507C1.64873 13.4343 2.36507 14.1507 3.24873 14.1507H5.77871z"}}]},{tag:"defs",attrs:{},children:[{tag:"clipPath",attrs:{id:"convert-single_clip0_911_593"},children:[{tag:"path",attrs:{fill:"#fff",d:"M0 0H16V16H0z"}}]}]}],defIds:["convert-single_clip0_911_593"]},Pl=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"convert-single",ref:i,icon:ig}))});Pl.displayName="ConvertSingle";var og={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.3313 1.4667C5.3313 1.13533 5.59993.866699 5.9313.866699H10.069C10.4004.866699 10.669 1.13533 10.669 1.4667 10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667zM1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443 14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443zM6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928 9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171 10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778 9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539 9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263 6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539 5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778 6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Wi=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"delete-single",ref:i,icon:og}))});Wi.displayName="DeleteSingle";var sg={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"}}]}]},Xo=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"dropdown-single",ref:i,icon:sg}))});Xo.displayName="DropdownSingle";var ag={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M15 8C15 11.866 11.866 15 8 15C4.13401 15 1 11.866 1 8C1 4.13401 4.13401 1 8 1C11.866 1 15 4.13401 15 8ZM10.3097 5.69014C10.544 5.92445 10.544 6.30435 10.3097 6.53867L8.84843 7.9999L10.3099 9.46137C10.5442 9.69569 10.5442 10.0756 10.3099 10.3099C10.0756 10.5442 9.69569 10.5442 9.46137 10.3099L7.9999 8.84843L6.53842 10.3099C6.30411 10.5442 5.92421 10.5442 5.6899 10.3099C5.45558 10.0756 5.45558 9.69569 5.6899 9.46137L7.15137 7.9999L5.69014 6.53867C5.45583 6.30435 5.45583 5.92445 5.69014 5.69014C5.92445 5.45583 6.30435 5.45583 6.53867 5.69014L7.9999 7.15137L9.46113 5.69014C9.69544 5.45583 10.0753 5.45583 10.3097 5.69014Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ts=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"error-single",ref:i,icon:ag}))});Ts.displayName="ErrorSingle";var lg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.28096 4.6541C1.57489 4.50109 1.93721 4.61533 2.09022 4.90926C2.27315 5.26067 2.55999 5.60455 2.94829 5.92278C4.04628 6.82266 5.87505 7.44865 7.99828 7.44865C10.1215 7.44865 11.9503 6.82267 13.0482 5.92279C13.4366 5.60455 13.7234 5.26067 13.9063 4.90927C14.0594 4.61533 14.4217 4.50109 14.7156 4.65409C15.0095 4.8071 15.1238 5.16941 14.9708 5.46334C14.6995 5.98445 14.2981 6.44997 13.8089 6.8509C13.7298 6.91575 13.6481 6.97914 13.564 7.041L15.2245 8.70153C15.4588 8.93585 15.4588 9.31575 15.2245 9.55006C14.9902 9.78438 14.6103 9.78438 14.376 9.55006L12.5041 7.67822C11.8977 7.97568 11.2181 8.21208 10.4884 8.37706L11.0996 10.6581C11.1853 10.9782 10.9954 11.3072 10.6753 11.393C10.3552 11.4787 10.0262 11.2888 9.94045 10.9687L9.29949 8.57652C8.8758 8.62404 8.44081 8.64865 7.99828 8.64865C7.55276 8.64865 7.11487 8.62371 6.68846 8.57555L6.04723 10.9687C5.96147 11.2888 5.63247 11.4788 5.31239 11.393C4.99231 11.3073 4.80236 10.9783 4.88812 10.6582L5.49983 8.37516C4.7743 8.2105 4.09843 7.9752 3.49498 7.67947L1.62436 9.55009C1.39005 9.78441 1.01015 9.78441 0.775835 9.5501C0.54152 9.31578 0.541518 8.93588 0.775832 8.70157L2.43478 7.04261C2.34987 6.98024 2.26746 6.91632 2.18764 6.8509C1.69842 6.44997 1.29706 5.98445 1.0258 5.46335C0.872791 5.16942 0.987031 4.80711 1.28096 4.6541Z"}}]},Ol=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"eyelash-single",ref:i,icon:lg}))});Ol.displayName="EyelashSingle";var cg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M6.06409 5.53454C5.93592 5.53454 5.84083 5.41567 5.86897 5.29063L5.95442 4.9109C6.05444 4.48178 6.23806 4.11547 6.51182 3.81952 6.81082 3.49628 7.25398 3.35405 7.79738 3.35405 7.99847 3.35405 8.21359 3.37775 8.44188 3.42245 8.46089 3.42617 8.47974 3.43006 8.49846 3.4341 8.7099 3.4798 8.93698 3.38478 9.02031 3.18514L9.24767 2.6404C9.33457 2.43219 9.23178 2.19404 9.01582 2.12874 8.98358 2.11899 8.95028 2.10912 8.91591 2.09914 8.62745 2.01631 8.28392 1.97217 7.88074 1.97217 6.82015 1.97217 6.02714 2.23936 5.4746 2.7444 4.90987 3.26069 4.50889 3.99917 4.28413 4.9762L2.83703 11.1909C2.76126 11.5286 2.666 11.8917 2.54844 12.2812 2.42975 12.6734 2.2873 13.0595 2.12221 13.4373 1.95577 13.8159 1.76813 14.1762 1.55955 14.5171 1.49345 14.6251 1.42515 14.7282 1.35467 14.8263 1.26508 14.9509 1.3347 15.133 1.48655 15.1554 2.13635 15.2509 2.8179 15.0763 3.18197 14.5296 3.32661 14.3124 3.46779 14.0646 3.60509 13.7851 3.96635 13.0497 4.30522 12.0103 4.61867 10.6574L5.469 7.01534C5.49013 6.92483 5.57082 6.86081 5.66376 6.86081H7.62478C7.8097 6.86081 7.97051 6.73405 8.01371 6.55425L8.14014 6.02798C8.20057 5.77642 8.00992 5.53454 7.75121 5.53454H6.06409zM14.3211 5.72037L12.5124 7.96963 11.4089 5.77754C11.3422 5.63012 11.1954 5.5354 11.0336 5.5354H10.3129C10.0085 5.5354 9.80921 5.85428 9.9427 6.1279L11.4089 9.05502 8.79783 12.1493C8.56587 12.4158 8.75519 12.8315 9.10855 12.8315H9.68607C9.80672 12.8315 9.9605 12.7822 10.0388 12.6904L12.1108 10.2648 13.1176 12.561C13.1786 12.7231 13.333 12.8315 13.5061 12.8315H14.3C14.5831 12.8315 14.7417 12.6175 14.6426 12.3524L13.1728 9.28628C13.1728 9.28628 15.4009 6.45542 15.6013 6.17892 15.7966 5.90929 15.6023 5.5354 15.2693 5.5354H14.6661C14.5275 5.5354 14.4333 5.58887 14.3211 5.72037z"}}]},xl=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"fx-single",ref:i,icon:cg}))});xl.displayName="FxSingle";var dg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M6.4833 1.65005C6.4833 1.31868 6.21467 1.05005 5.8833 1.05005C5.55193 1.05005 5.2833 1.31868 5.2833 1.65005V5.28345H1.65029C1.31892 5.28345 1.05029 5.55208 1.05029 5.88345C1.05029 6.21482 1.31892 6.48345 1.65029 6.48345H5.2833V9.51684H1.65029C1.31892 9.51684 1.05029 9.78547 1.05029 10.1168C1.05029 10.4482 1.31892 10.7168 1.65029 10.7168H5.2833V14.35C5.2833 14.6814 5.55193 14.95 5.8833 14.95C6.21467 14.95 6.4833 14.6814 6.4833 14.35V10.7168H9.5167V14.35C9.5167 14.6814 9.78533 14.95 10.1167 14.95C10.4481 14.95 10.7167 14.6814 10.7167 14.35V10.7168H14.3503C14.6817 10.7168 14.9503 10.4482 14.9503 10.1168C14.9503 9.78547 14.6817 9.51685 14.3503 9.51685H10.7167V6.48345H14.3503C14.6817 6.48345 14.9503 6.21482 14.9503 5.88345C14.9503 5.55208 14.6817 5.28345 14.3503 5.28345H10.7167V1.65005C10.7167 1.31868 10.4481 1.05005 10.1167 1.05005C9.78533 1.05005 9.5167 1.31868 9.5167 1.65005V5.28345L6.4833 5.28345V1.65005ZM6.4833 6.48345V9.51684L9.5167 9.51685V6.48345L6.4833 6.48345Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.0498 3.65005C1.0498 2.21411 2.21386 1.05005 3.6498 1.05005H12.3498C13.7857 1.05005 14.9498 2.21411 14.9498 3.65005V12.3501C14.9498 13.786 13.7857 14.95 12.3498 14.95H3.6498C2.21386 14.95 1.0498 13.786 1.0498 12.35V3.65005ZM3.6498 2.25005C2.87661 2.25005 2.2498 2.87685 2.2498 3.65005V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V3.65005C13.7498 2.87685 13.123 2.25005 12.3498 2.25005H3.6498Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Al=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"hide-gridlines",ref:i,icon:dg}))});Al.displayName="HideGridlines";var ug={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},ws=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"increase-single",ref:i,icon:ug}))});ws.displayName="IncreaseSingle";var hg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.62402 7.72905C2.58427 7.72905 2.55205 7.76127 2.55205 7.80102V13.6782C2.55205 13.7179 2.58427 13.7502 2.62402 13.7502H13.3755C13.4152 13.7502 13.4474 13.7179 13.4474 13.6782V7.80102C13.4474 7.76127 13.4152 7.72905 13.3755 7.72905H2.62402ZM1.35205 7.80102C1.35205 7.09853 1.92153 6.52905 2.62402 6.52905H13.3755C14.0779 6.52905 14.6474 7.09853 14.6474 7.80102V13.6782C14.6474 14.3807 14.0779 14.9502 13.3755 14.9502H2.62402C1.92153 14.9502 1.35205 14.3807 1.35205 13.6782V7.80102Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M8 2.25005C6.69847 2.25003 5.64336 3.30513 5.64336 4.60666V7.12895C5.64336 7.46032 5.37473 7.72895 5.04336 7.72895 4.71199 7.72895 4.44336 7.46032 4.44336 7.12895V4.60666C4.44336 2.64239 6.04451 1.05565 8.00879 1.05566M8 2.25005L8.00879 1.05566 8 2.25005zM8.00879 1.05566L8 2.25005C9.30154 2.25003 10.3567 3.30513 10.3567 4.60666V7.12895C10.3567 7.46032 10.6253 7.72895 10.9567 7.72895 11.288 7.72895 11.5567 7.46032 11.5567 7.12895V4.60666C11.5567 2.64239 9.97306 1.05565 8.00879 1.05566zM8.00039 9.4668C8.33176 9.4668 8.60039 9.73543 8.60039 10.0668V12.0827C8.60039 12.4141 8.33176 12.6827 8.00039 12.6827 7.66902 12.6827 7.40039 12.4141 7.40039 12.0827V10.0668C7.40039 9.73543 7.66902 9.4668 8.00039 9.4668z",fillRule:"evenodd",clipRule:"evenodd"}}]},ys=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"lock-single",ref:i,icon:hg}))});ys.displayName="LockSingle";var mg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M11.3536 6.14645C11.5488 6.34171 11.5488 6.65829 11.3536 6.85355L8.35355 9.85355C8.15829 10.0488 7.84171 10.0488 7.64645 9.85355L4.64645 6.85355C4.45118 6.65829 4.45118 6.34171 4.64645 6.14645C4.84171 5.95118 5.15829 5.95118 5.35355 6.14645L8 8.79289L10.6464 6.14645C10.8417 5.95118 11.1583 5.95118 11.3536 6.14645Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Mn=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"more-down-single",ref:i,icon:mg}))});Mn.displayName="MoreDownSingle";var gg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.90913 3.57564C6.14345 3.34132 6.52335 3.34132 6.75766 3.57564L10.7577 7.57564C10.992 7.80995 10.992 8.18985 10.7577 8.42417L6.75766 12.4242C6.52335 12.6585 6.14345 12.6585 5.90913 12.4242C5.67482 12.1899 5.67482 11.81 5.90913 11.5756L9.48487 7.9999L5.90913 4.42417C5.67482 4.18985 5.67482 3.80995 5.90913 3.57564Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Yo=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"more-single",ref:i,icon:gg}))});Yo.displayName="MoreSingle";var Sg={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"}}]}]},Nl=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"paint-bucket",ref:i,icon:Sg}))});Nl.displayName="PaintBucket";var fg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_1138",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_1138)"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M7.74692 9.12463C7.74692 9.46018 8.01893 9.73219 8.35448 9.73219H11.4933C11.8288 9.73219 12.1009 9.46018 12.1009 9.12463 12.1009 8.78909 11.8288 8.51707 11.4933 8.51707H8.35448C8.01893 8.51707 7.74692 8.78909 7.74692 9.12463zM10.8636 10.8523C10.8636 11.1879 10.5915 11.4599 10.256 11.4599H8.35448C8.01893 11.4599 7.74692 11.1879 7.74692 10.8523 7.74692 10.5168 8.01893 10.2447 8.35448 10.2447H10.256C10.5915 10.2447 10.8636 10.5168 10.8636 10.8523z"}},{tag:"path",attrs:{fill:"currentColor",d:"M5.4791 1.98268C5.47913 1.71529 5.87912 1.49854 6.37252 1.49854C6.86593 1.49854 7.26592 1.71529 7.26595 1.98268H7.62187C8.22277 1.98268 8.72459 2.39534 8.84412 2.9452H9.39563C10.0856 2.9452 10.6449 3.48923 10.6449 4.16032V6.00569H12.1261C13.161 6.00569 14 6.82174 14 7.82838V11.334C14 11.8174 13.8025 12.281 13.4511 12.6228L12.0693 13.9647C11.7179 14.3065 11.2412 14.4985 10.7442 14.4985H7.91116C7.05024 14.4985 6.32492 14.0431 6.10535 13.2737H3.34925C2.6593 13.2737 2.09998 12.7297 2.09998 12.0586V4.16032C2.09998 3.48923 2.6593 2.9452 3.34925 2.9452H3.90107C4.0206 2.39534 4.52241 1.98268 5.12332 1.98268H5.4791ZM3.97249 4.16032H3.24925L3.24925 12.0586H6.03725V7.82838C6.03725 6.82174 6.87623 6.00569 7.91116 6.00569H9.49563V4.16032H8.7727C8.58289 4.59611 8.13909 4.90183 7.62187 4.90183H5.12332C4.6061 4.90183 4.1623 4.59611 3.97249 4.16032ZM5.12332 2.89403H7.62187C7.79436 2.89403 7.93419 3.03003 7.93419 3.19781V3.68671C7.93419 3.85448 7.79436 3.99049 7.62187 3.99049H5.12332C4.95083 3.99049 4.811 3.85448 4.811 3.68671V3.19781C4.811 3.03003 4.95083 2.89403 5.12332 2.89403ZM7.91116 7.11157C7.56618 7.11157 7.28652 7.38359 7.28652 7.71913V12.7851C7.28652 13.1206 7.56618 13.3927 7.91116 13.3927H10.7442C10.8401 13.3927 10.9337 13.3712 11.0182 13.3311C11.1373 13.2746 11.1859 13.1423 11.1859 13.0134V12.0066C11.1859 11.8724 11.2978 11.7636 11.4358 11.7636H12.4709C12.6034 11.7636 12.7394 11.7163 12.7975 11.6004C12.8388 11.5182 12.8608 11.4272 12.8608 11.334V7.71913C12.8608 7.38359 12.5811 7.11157 12.2362 7.11157H7.91116Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},Dl=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"paste-special",ref:i,icon:fg}))});Dl.displayName="PasteSpecial";var pg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.785 6.77762C5.78908 6.7777 5.79316 6.77774 5.79725 6.77774C5.80134 6.77774 5.80543 6.7777 5.8095 6.77762H10.0184C10.0225 6.7777 10.0266 6.77774 10.0307 6.77774C10.0347 6.77774 10.0388 6.7777 10.0429 6.77762H13.6638V7.63727C13.6638 7.96864 13.9324 8.23727 14.2638 8.23727C14.5951 8.23727 14.8638 7.96864 14.8638 7.63727V3.9999C14.8638 2.56395 13.6997 1.39989 12.2637 1.3999L3.56389 1.39999C2.12797 1.40001 0.96393 2.56405 0.96392 3.99998L0.963867 11.6666C0.963857 13.1025 2.12792 14.2666 3.56387 14.2666H8.0542C8.38557 14.2666 8.6542 13.9979 8.6542 13.6666C8.6542 13.3352 8.38557 13.0666 8.0542 13.0666H3.56387C2.79067 13.0666 2.16386 12.4398 2.16387 11.6666L2.1639 6.77762H5.785ZM6.39725 2.59996L9.43065 2.59993V5.57762H6.39725V2.59996ZM5.19725 5.57762V2.59998L3.56391 2.59999C2.79072 2.6 2.16393 3.22679 2.16392 3.99998L2.16391 5.57762H5.19725ZM13.6638 5.57762V3.9999C13.6638 3.2267 13.037 2.59989 12.2638 2.5999L10.6307 2.59992V5.57762H13.6638Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M14.1223 10.2333V10.7496C14.7087 10.9869 15.1223 11.5618 15.1223 12.2333V12.8999C15.1223 13.7836 14.406 14.4999 13.5223 14.4999H11.5223C10.6387 14.4999 9.92235 13.7836 9.92235 12.8999V12.2333C9.92235 11.5618 10.336 10.9869 10.9223 10.7496V10.2333C10.9223 9.34961 11.6387 8.63328 12.5223 8.63328C13.406 8.63328 14.1223 9.34961 14.1223 10.2333ZM11.1223 12.2333C11.1223 12.0124 11.3014 11.8333 11.5223 11.8333H13.5223C13.7433 11.8333 13.9223 12.0124 13.9223 12.2333V12.8999C13.9223 13.1209 13.7433 13.2999 13.5223 13.2999H11.5223C11.3014 13.2999 11.1223 13.1209 11.1223 12.8999V12.2333ZM12.9223 10.2333V10.6333H12.1223V10.2333C12.1223 10.0124 12.3014 9.83328 12.5223 9.83328C12.7433 9.83328 12.9223 10.0124 12.9223 10.2333Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Hl=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"protect-single",ref:i,icon:pg}))});Hl.displayName="ProtectSingle";var vg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M15 8C15 11.866 11.866 15 8 15C4.13401 15 1 11.866 1 8C1 4.13401 4.13401 1 8 1C11.866 1 15 4.13401 15 8ZM8.00008 12.3671C8.46031 12.3671 8.83342 11.994 8.83342 11.5338C8.83342 11.0735 8.46031 10.7004 8.00008 10.7004C7.53985 10.7004 7.16675 11.0735 7.16675 11.5338C7.16675 11.994 7.53985 12.3671 8.00008 12.3671ZM8.5999 4.4335C8.5999 4.10213 8.33127 3.8335 7.9999 3.8335C7.66853 3.8335 7.3999 4.10213 7.3999 4.4335V9.36683C7.3999 9.6982 7.66853 9.96683 7.9999 9.96683C8.33127 9.96683 8.5999 9.6982 8.5999 9.36683V4.4335Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Go=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"warning-single",ref:i,icon:vg}))});Go.displayName="WarningSingle";var Cg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.6551 1.98906C11.7476 1.08113 10.2757 1.08149 9.3686 1.98987L4.82542 6.53955C4.75087 6.61421 4.69336 6.70411 4.65682 6.80309L3.2461 10.625C3.16506 10.8446 3.21909 11.0912 3.3845 11.2568C3.54991 11.4224 3.79651 11.4767 4.01616 11.3959L7.85031 9.98517C7.94979 9.94856 8.04014 9.89077 8.11508 9.81579L12.6552 5.27327C13.5618 4.36621 13.5618 2.89607 12.6551 1.98906ZM10.2177 2.83779C10.6562 2.39869 11.3677 2.39851 11.8064 2.8374C12.2447 3.27584 12.2447 3.9865 11.8065 4.42497L7.3392 8.89457L4.82213 9.82068L5.74706 7.31487L10.2177 2.83779Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.79238 13.2999C1.46101 13.2999 1.19238 13.5685 1.19238 13.8999C1.19238 14.2313 1.46101 14.4999 1.79238 14.4999H14.4924C14.8238 14.4999 15.0924 14.2313 15.0924 13.8999C15.0924 13.5685 14.8238 13.2999 14.4924 13.2999H1.79238Z"}}]},Ms=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"write-single",ref:i,icon:Cg}))});Ms.displayName="WriteSingle";function _g(n,i){if(n.length!==i.length)return!1;const e=n.sort((r,o)=>r.id.localeCompare(o.id)),t=i.sort((r,o)=>r.id.localeCompare(o.id));return e.every((r,o)=>{var s,l;return((s=r.subject)==null?void 0:s.userID)===((l=t[o].subject)==null?void 0:l.userID)&&r.role===t[o].role})}function kl(n,i){return i.some(e=>Ig(n,e))}function Ig(n,i){const{startRow:e,startColumn:t,endColumn:r,endRow:o}=i,s=n.getMatrixWithMergedCells(e,t,o,r);let l=!1;return s.forValue((d,c,u)=>{if(u&&(d!==e||c!==t)&&n.cellHasValue(u))return l=!0,!1}),l}function Vl(n,i,e,t){const r=[],o=[],s=e.getSheetId();return t.forEach(l=>{const d=bg(e,l),c={unitId:i,subUnitId:s,cellValue:d.getData()},u=m.SetRangeValuesUndoMutationFactory(n,c);r.push({id:m.SetRangeValuesMutation.id,params:u}),o.push({id:m.SetRangeValuesMutation.id,params:c})}),{undos:r,redos:o}}function bg(n,i){const{startRow:e,startColumn:t,endColumn:r,endRow:o}=i,s=n.getMatrixWithMergedCells(e,t,o,r,a.CellModeEnum.Intercepted),l=new a.ObjectMatrix;let d=null;return s.forValue((c,u,h)=>{var g,S,f,p;h&&c>=e&&u>=t&&(!d&&n.cellHasValue(h)&&(h.v!==""||((p=(f=(S=(g=h.p)==null?void 0:g.body)==null?void 0:S.dataStream)==null?void 0:f.length)!=null?p:0)>2)&&(d=h),l.setValue(c,u,null))}),l.setValue(e,t,d),l}function Rg(n,i,e,t){const r=e.getActiveViewportByCoord(w.Vector2.FromArray([n,i]));if(!r)return;const{scaleX:o,scaleY:s}=e.getAncestorScale(),l={x:r.viewportScrollX,y:r.viewportScrollY},d=t.getCellIndexByOffset(n,i,o,s,l),c=t.worksheet.getMergedCell(d.row,d.column);return{actualRow:c?c.startRow:d.row,actualCol:c?c.startColumn:d.column,mergeCell:c,row:d.row,col:d.column}}function va(n,i,e,t){const r=t.getFreeze();if(!r||r.startRow<=0&&r.startColumn<=0||n>=r.startRow&&i>=r.startColumn)return e.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(n<r.startRow&&i<r.startColumn)return e.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP);if(n<r.startRow&&i>=r.startColumn)return e.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(n>=r.startRow&&i<r.startColumn)return e.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)}function Eg(n,i,e,t){const r=Ca(n.left,n.top,i,e,t),o=Ca(n.right,n.bottom,i,e,t);return{left:r.x,top:r.y,right:o.x,bottom:o.y}}function Ca(n,i,e,t,r){const{scaleX:o,scaleY:s}=e.getAncestorScale(),l=e.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!l)return{x:n,y:i};const d=r.getFreeze(),{startColumn:c,startRow:u,xSplit:h,ySplit:g}=d,S=t.getNoMergeCellPositionByIndexWithNoHeader(u-g,c-h),f=t.getNoMergeCellPositionByIndexWithNoHeader(u,c),{rowHeaderWidth:p,columnHeaderHeight:v}=t,C=f.startX-S.startX,I=f.startY-S.startY,{top:b,left:T,viewportScrollX:M,viewportScrollY:y}=l;let P;n>T?P=(n-M)*o:P=(C+p-(T-n))*o;let x;return i>b?x=(i-y)*s:x=(I+v-(b-i))*o,{x:P,y:x}}function Wl(n,i,e,t,r){let o=t,s=r;e.overflowCache.forValue((c,u,h)=>{h.startRow<=o&&h.endRow>=o&&h.startColumn<=s&&h.endColumn>=s&&(s=u,o=c)});const l=e.getCellWithCoordByIndex(o,s);return{unitId:n.getUnitId(),subUnitId:i.getSheetId(),workbook:n,worksheet:i,row:l.actualRow,col:l.actualColumn}}function Ul(n,i,e,t,r,o){const{scene:s}=n,l=i.getUnitId(),{skeleton:d,sheetId:c}=t,u=Rg(r,o,s,d);if(!u)return null;let{actualCol:h,actualRow:g}=u;const S={unitId:l,subUnitId:c,workbook:i,worksheet:e,row:g,col:h};d.overflowCache.forValue((y,P,x)=>{x.startRow<=g&&x.endRow>=g&&x.startColumn<=h&&x.endColumn>=h&&(h=P,g=y)});const f=d.getCellWithCoordByIndex(g,h),p=Wl(i,e,d,g,h);let v;f.mergeInfo?v=f.mergeInfo:v={startRow:p.row,endRow:p.row,startColumn:p.col,endColumn:p.col};const C=s.getActiveViewportByCoord(w.Vector2.FromArray([r,o]));if(!C)return;const{scaleX:I,scaleY:b}=s.getAncestorScale(),T={x:C.viewportScrollX,y:C.viewportScrollY};return{position:{startX:(d.getOffsetByPositionX(v.startColumn-1)-T.x)*I,endX:(d.getOffsetByPositionX(v.endColumn)-T.x)*I,startY:(d.getOffsetByPositionY(v.startRow-1)-T.y)*b,endY:(d.getOffsetByPositionY(v.endRow)-T.y)*b},location:S,overflowLocation:p}}const wt={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge",handler:async(n,i)=>{const e=n.get(a.ICommandService),t=n.get(a.IUndoRedoService),r=n.get(a.IUniverInstanceService),o=n.get(E.IConfirmService),s=n.get(a.LocaleService),l=i.unitId,d=i.subUnitId,c=i.selections,u=m.getAddMergeMutationRangeByType(c,i.value),h=r.getUniverSheetInstance(l).getSheetBySheetId(d),g=[],S=[],f=kl(h,u);if(f&&!i.defaultMerge&&!await o.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 p={unitId:l,subUnitId:d,ranges:a.Tools.deepClone(u)},v={unitId:l,subUnitId:d,ranges:a.Tools.deepClone(u)},C=m.RemoveMergeUndoMutationFactory(n,p),I=m.AddMergeUndoMutationFactory(n,v);if(C.ranges.length>0&&g.push({id:m.RemoveWorksheetMergeMutation.id,params:C}),g.push({id:m.AddWorksheetMergeMutation.id,params:v}),S.push({id:m.RemoveWorksheetMergeMutation.id,params:I}),C.ranges.length>0&&S.push({id:m.AddWorksheetMergeMutation.id,params:C}),f){const x=Vl(n,l,h,u);g.unshift(...x.redos),S.push(...x.undos)}const b=m.AddMergeRedoSelectionsOperationFactory(n,i,u);b&&g.push(b);const T=m.AddMergeUndoSelectionsOperationFactory(n,i);T&&S.push(T);const y=n.get(m.SheetInterceptorService).onCommandExecute({id:wt.id,params:{unitId:l,subUnitId:d,ranges:u}});return g.push(...y.redos),S.push(...y.undos),a.sequenceExecute(g,e).result?(t.pushUndoRedo({unitID:l,undoMutations:S,redoMutations:g}),!0):!1}},Ps={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-all",handler:async n=>{var u;const i=n.get(a.ICommandService),t=(u=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:u.map(h=>h.range),r=gs(Pi.MergeAll,t);if(!(r!=null&&r.length))return!1;const s=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;const l=s.getActiveSheet();if(!l)return!1;const d=s.getUnitId(),c=l.getSheetId();return i.executeCommand(wt.id,{selections:r,unitId:d,subUnitId:c})}},Os={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-vertical",handler:async n=>{var u;const i=n.get(a.ICommandService),t=(u=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:u.map(h=>h.range),r=gs(Pi.MergeVertical,t);if(!(r!=null&&r.length))return!1;const s=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;const l=s.getActiveSheet();if(!l)return!1;const d=s.getUnitId(),c=l.getSheetId();return i.executeCommand(wt.id,{value:a.Dimension.COLUMNS,selections:r,unitId:d,subUnitId:c})}},xs={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-horizontal",handler:async n=>{var u;const i=n.get(a.ICommandService),t=(u=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:u.map(h=>h.range),r=gs(Pi.MergeHorizontal,t);if(!(r!=null&&r.length))return!1;const s=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;const l=s.getActiveSheet();if(!l)return!1;const d=s.getUnitId(),c=l.getSheetId();return i.executeCommand(wt.id,{value:a.Dimension.ROWS,selections:r,unitId:d,subUnitId:c})}},Vn={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-move-left-confirm",handler:async n=>{const i=n.get(E.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=r.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(o);if(!l)return!1;const{worksheet:d}=l;let c=s[0].range;if(!c)return!1;c={...c,endColumn:d.getColumnCount()-1};const u=S=>S.endRow-S.startRow;return!d.getMergeData().find(S=>{const f=a.Rectangle.getIntersects(S,c);return f?u(S)>u(f):!1})||await i.confirm({id:Vn.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.DeleteRangeMoveLeftCommand.id):!0}},Yt={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-move-up-confirm",handler:async n=>{const i=n.get(E.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=r.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(o);if(!l)return!1;const{worksheet:d}=l;let c=s[0].range;if(!c)return!1;c={...c,endRow:d.getRowCount()-1};for(let S=c.startRow;S<=c.endRow;S++)if(d.getRowFiltered(S)&&await i.confirm({id:Yt.id,title:{title:t.t("filter.confirm.error")},children:{title:t.t("filter.confirm.notAllowedToInsertRange")},confirmText:t.t("button.confirm")}))return!1;const u=S=>S.endColumn-S.startColumn;return!d.getMergeData().find(S=>{const f=a.Rectangle.getIntersects(S,c);return f?u(S)>u(f):!1})||await i.confirm({id:Yt.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.DeleteRangeMoveUpCommand.id):!0}},Gt={type:a.CommandType.COMMAND,id:"sheet.command.insert-range-move-down-confirm",handler:async n=>{const i=n.get(E.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=r.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(o);if(!l)return!1;const{worksheet:d}=l;let c=s[0].range;if(!c)return!1;c={...c,endRow:d.getRowCount()-1};for(let S=c.startRow;S<=c.endRow;S++)if(d.getRowFiltered(S)&&await i.confirm({id:Gt.id,title:{title:t.t("filter.confirm.error")},children:{title:t.t("filter.confirm.notAllowedToInsertRange")},confirmText:t.t("button.confirm")}))return!1;const u=S=>S.endColumn-S.startColumn;return!d.getMergeData().find(S=>{const f=a.Rectangle.getIntersects(S,c);return f?u(S)>u(f):!1})||await i.confirm({id:Gt.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.InsertRangeMoveDownCommand.id):!0}},Wn={type:a.CommandType.COMMAND,id:"sheet.command.insert-range-move-right-confirm",handler:async n=>{const i=n.get(E.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=r.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(o);if(!l)return!1;const{worksheet:d}=l;let c=s[0].range;if(!c)return!1;c={...c,endColumn:d.getColumnCount()-1};const u=S=>S.endRow-S.startRow;return!d.getMergeData().find(S=>{const f=a.Rectangle.getIntersects(S,c);return f?u(S)>u(f):!1})||await i.confirm({id:Wn.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.InsertRangeMoveRightCommand.id):!0}};var Ll=(n=>(n[n.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",n[n.UNIVER_DOC=1]="UNIVER_DOC",n[n.UNIVER_SHEET=2]="UNIVER_SHEET",n[n.UNIVER_SLIDE=3]="UNIVER_SLIDE",n[n.UNIVER_PROJECT=4]="UNIVER_PROJECT",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(Ll||{}),ne=(n=>(n[n.View=0]="View",n[n.Edit=1]="Edit",n[n.ManageCollaborator=2]="ManageCollaborator",n[n.Print=3]="Print",n[n.Duplicate=4]="Duplicate",n[n.Comment=5]="Comment",n[n.Copy=6]="Copy",n[n.Share=7]="Share",n[n.Export=8]="Export",n[n.MoveWorksheet=9]="MoveWorksheet",n[n.DeleteWorksheet=10]="DeleteWorksheet",n[n.HideWorksheet=11]="HideWorksheet",n[n.RenameWorksheet=12]="RenameWorksheet",n[n.CreateWorksheet=13]="CreateWorksheet",n[n.SetWorksheetStyle=14]="SetWorksheetStyle",n[n.EditWorksheetCell=15]="EditWorksheetCell",n[n.InsertHyperlink=16]="InsertHyperlink",n[n.Sort=17]="Sort",n[n.Filter=18]="Filter",n[n.PivotTable=19]="PivotTable",n[n.FloatImg=20]="FloatImg",n[n.History=21]="History",n[n.RwHgtClWdt=22]="RwHgtClWdt",n[n.ViemRwHgtClWdt=23]="ViemRwHgtClWdt",n[n.ViewFilter=24]="ViewFilter",n[n.MoveSheet=25]="MoveSheet",n[n.DeleteSheet=26]="DeleteSheet",n[n.HideSheet=27]="HideSheet",n[n.CopySheet=28]="CopySheet",n[n.RenameSheet=29]="RenameSheet",n[n.CreateSheet=30]="CreateSheet",n[n.SelectProtectedCells=31]="SelectProtectedCells",n[n.SelectUnProtectedCells=32]="SelectUnProtectedCells",n[n.SetCellStyle=33]="SetCellStyle",n[n.SetCellValue=34]="SetCellValue",n[n.SetRowStyle=35]="SetRowStyle",n[n.SetColumnStyle=36]="SetColumnStyle",n[n.InsertRow=37]="InsertRow",n[n.InsertColumn=38]="InsertColumn",n[n.DeleteRow=39]="DeleteRow",n[n.DeleteColumn=40]="DeleteColumn",n[n.EditExtraObject=41]="EditExtraObject",n[n.Delete=42]="Delete",n[n.RecoverHistory=43]="RecoverHistory",n[n.ViewHistory=44]="ViewHistory",n[n.CreatePermissionObject=45]="CreatePermissionObject",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(ne||{}),Ne=(n=>(n[n.Reader=0]="Reader",n[n.Editor=1]="Editor",n[n.Owner=2]="Owner",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(Ne||{}),dt=(n=>(n[n.Unkonwn=0]="Unkonwn",n[n.Workbook=1]="Workbook",n[n.Worksheet=2]="Worksheet",n[n.SelectRange=3]="SelectRange",n[n.Document=4]="Document",n[n.Slide=5]="Slide",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(dt||{}),Ke=(n=>(n[n.SomeCollaborator=0]="SomeCollaborator",n[n.AllCollaborator=1]="AllCollaborator",n[n.OneSelf=2]="OneSelf",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(Ke||{});const nr="UNIVER_SHEET_PERMISSION_PANEL",ri="UNIVER_SHEET_PERMISSION_USER_PART",As="UNIVER_SHEET_PERMISSION_BACKGROUND",Bl="UNIVER_SHEET_PERMISSION_USER_DIALOG",Fl="UNIVER_SHEET_PERMISSION_DIALOG",ii="UNIVER_SHEET_PERMISSION_USER_DIALOG_ID",oi="UNIVER_SHEET_PERMISSION_DIALOG_ID",Ur={[ne.Copy]:"Copy",[ne.SetCellStyle]:"SetCellStyle",[ne.SetCellValue]:"SetCellValue",[ne.SetRowStyle]:"SetRowStyle",[ne.SetColumnStyle]:"SetColumnStyle",[ne.InsertRow]:"InsertRow",[ne.InsertColumn]:"InsertColumn",[ne.InsertHyperlink]:"InsertHyperlink",[ne.DeleteRow]:"DeleteRow",[ne.DeleteColumn]:"DeleteColumn",[ne.Sort]:"Sort",[ne.Filter]:"Filter",[ne.PivotTable]:"PivotTable",[ne.EditExtraObject]:"EditExtraObject"},Tg=[ne.Copy,ne.SetCellStyle,ne.SetCellValue,ne.SetRowStyle,ne.SetColumnStyle,ne.InsertRow,ne.InsertColumn,ne.InsertHyperlink,ne.DeleteRow,ne.DeleteColumn,ne.Sort,ne.Filter,ne.PivotTable,ne.EditExtraObject,ne.View],jl="sheet-permission-menu-icon",wg="sheet-permission-delete-icon",yg="sheet-permission-edit-icon",Mg="sheet-permission-check-icon",zl="sheet-permission-lock-icon",Pg={unitId:"",subUnitId:"",permissionId:"",unitType:m.UnitObject.SelectRange,id:"",ranges:[],viewState:m.ViewStateEnum.OthersCanView,editState:m.EditStateEnum.OnlyMe};class Pn{constructor(){R(this,"_rule",Pg);R(this,"_visible",!1)}setVisible(i){this._visible=i}getVisible(){return this._visible}reset(){this.setVisible(!1)}}class yt{constructor(){R(this,"_userList",[]);R(this,"_oldCollaboratorList",[]);R(this,"_selectUserList",[]);R(this,"_selectUserList$",new O.BehaviorSubject(this._selectUserList));R(this,"selectUserList$",this._selectUserList$.asObservable())}get userList(){return this._userList}setCanEditUserList(i){this._userList=i}reset(){this._userList=[],this._oldCollaboratorList=[],this._selectUserList=[],this._selectUserList$.next([])}get oldCollaboratorList(){return this._oldCollaboratorList}setOldCollaboratorList(i){this._oldCollaboratorList=i}get selectUserList(){return this._selectUserList}setSelectUserList(i){this._selectUserList=i,this._selectUserList$.next(i)}}const Qe={type:a.CommandType.OPERATION,id:"sheet-permission.operation.openPanel",async handler(n,i={}){const e=n.get(E.ISidebarService),t=n.get(Pn),r=n.get(yt),{showDetail:o=!0,fromSheetBar:s=!1,rule:l,oldRule:d}=i,c={header:{title:"permission.panel.title"},children:{label:nr,showDetail:o,fromSheetBar:s,rule:l,oldRule:d},width:330,onClose:()=>{t.reset(),r.reset()}};return t.setVisible(!0),e.open(c),!0}},Tr={type:a.CommandType.COMMAND,id:"sheet.command.add-range-protection-from-toolbar",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{showDetail:!0}),!0}},Wt={type:a.CommandType.COMMAND,id:"sheet.command.add-range-protection-from-context-menu",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{showDetail:!0}),!0}},Ut={type:a.CommandType.COMMAND,id:"sheet.command.view-sheet-permission-from-context-menu",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{showDetail:!1}),!0}},wr={type:a.CommandType.COMMAND,id:"sheet.command.add-range-protection-from-sheet-bar",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{fromSheetBar:!0,showDetail:!0}),!0}},yr={type:a.CommandType.COMMAND,id:"sheet.command.view-sheet-permission-from-sheet-bar",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{showDetail:!1}),!0}},Lt={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-protection-from-context-menu",async handler(n){var h;const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(a.IUndoRedoService),r=n.get(m.SheetsSelectionsService),o=n.get(m.WorksheetProtectionRuleModel),s=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),l=s.getActiveSheet(),d=s.getUnitId(),c=l.getSheetId(),u=o.getRule(d,c);if(u!=null&&u.permissionId)return i.executeCommand(m.DeleteWorksheetProtectionCommand.id,{unitId:d,subUnitId:c,rule:u});{const g=(h=r.getCurrentLastSelection())==null?void 0:h.range;if(!g)return!1;const p=n.get(m.RangeProtectionRuleModel).getSubunitRuleList(d,c).find(v=>v.ranges.some(C=>a.Rectangle.intersects(C,g)));if(p){const v={unitId:d,subUnitId:c,ruleIds:[p.id]};return await i.executeCommand(m.DeleteRangeProtectionMutation.id,v)&&t.pushUndoRedo({unitID:d,redoMutations:[{id:m.DeleteRangeProtectionMutation.id,params:v}],undoMutations:[{id:m.AddRangeProtectionMutation.id,params:{unitId:d,subUnitId:c,rules:[p]}}]}),!0}else return!1}}},Bt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-protection-from-context-menu",async handler(n){var u;const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.WorksheetProtectionRuleModel),o=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=o.getActiveSheet(),l=o.getUnitId(),d=s.getSheetId(),c=r.getRule(l,d);if(c!=null&&c.permissionId){const h={...c,unitId:l,subUnitId:d,ranges:[]};return await i.executeCommand(Qe.id,{showDetail:!0,rule:a.Tools.deepClone(h),oldRule:a.Tools.deepClone(h)}),!0}else{const h=(u=t.getCurrentLastSelection())==null?void 0:u.range;if(!h)return!1;const f=n.get(m.RangeProtectionRuleModel).getSubunitRuleList(l,d).find(p=>{var v;return(v=p==null?void 0:p.ranges)==null?void 0:v.some(C=>a.Rectangle.intersects(C,h))});if(f){const p={...f,unitId:l,subUnitId:d};return await i.executeCommand(Qe.id,{showDetail:!0,rule:a.Tools.deepClone(p),oldRule:a.Tools.deepClone(p)}),!0}else return!1}}},On={id:"sheet.command.remove-row-confirm",type:a.CommandType.COMMAND,handler:async(n,i)=>{var c;const e=n.get(m.SheetsSelectionsService);let t=i==null?void 0:i.range;if(t||(t=(c=e.getCurrentLastSelection())==null?void 0:c.range),!t)return!1;const r=n.get(a.ICommandService),o=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(o);if(!s)return!1;const{worksheet:l}=s,d=l.getVisibleRows();if(Ga(d,[t])){const u=n.get(E.IConfirmService),h=n.get(a.LocaleService);return await u.confirm({id:"sheet.confirm.remove-row",title:{title:h.t("info.problem")},children:{title:h.t("rightClick.deleteAllRowsAlert")},cancelText:h.t("button.cancel"),confirmText:h.t("button.confirm")}),!1}return await r.executeCommand(m.RemoveRowCommand.id,{range:t}),!0}},xn={id:"sheet.command.remove-col-confirm",type:a.CommandType.COMMAND,handler:async(n,i)=>{var c;const e=n.get(m.SheetsSelectionsService);let t=i==null?void 0:i.range;if(t||(t=(c=e.getCurrentLastSelection())==null?void 0:c.range),!t)return!1;const r=n.get(a.ICommandService),o=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(o);if(!s)return!1;const{worksheet:l}=s,d=l.getVisibleCols();if(Za(d,[t])){const u=n.get(E.IConfirmService),h=n.get(a.LocaleService);return await u.confirm({id:"sheet.confirm.remove-col",title:{title:h.t("info.problem")},children:{title:h.t("rightClick.deleteAllColumnsAlert")},cancelText:h.t("button.cancel"),confirmText:h.t("button.confirm")}),!1}return await r.executeCommand(m.RemoveColCommand.id,{range:t}),!0}},Mr={id:"sheet.command.remove-sheet-confirm",type:a.CommandType.COMMAND,handler:async(n,i)=>{const{subUnitId:e}=i,t=n.get(E.IConfirmService),r=n.get(a.ICommandService),o=n.get(a.LocaleService);return await t.confirm({id:"sheet.confirm.remove-sheet",title:{title:o.t("sheetConfig.deleteSheet")},children:{title:o.t("sheetConfig.deleteSheetContent")},cancelText:o.t("button.cancel"),confirmText:o.t("button.confirm")})?(await r.executeCommand(m.RemoveSheetCommand.id,{subUnitId:e}),!0):!1}},nn=a.createIdentifier("univer.sheetbar-service");class Xl extends a.Disposable{constructor(){super();R(this,"renameId$");R(this,"removeId$");R(this,"scroll$");R(this,"scrollX$");R(this,"addSheet$");R(this,"_renameId$");R(this,"_removeId$");R(this,"_scroll$");R(this,"_scrollX$");R(this,"_addSheet$");R(this,"_currentHandler",null);this._renameId$=new O.Subject,this.renameId$=this._renameId$.asObservable(),this._removeId$=new O.Subject,this.removeId$=this._removeId$.asObservable(),this._scroll$=new O.Subject,this.scroll$=this._scroll$.asObservable(),this._scrollX$=new O.Subject,this.scrollX$=this._scrollX$.asObservable(),this._addSheet$=new O.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,a.toDisposable(()=>{this._currentHandler=null})}}const Pr={id:"ui-sheet.command.show-menu-list",type:a.CommandType.OPERATION,handler:async n=>(n.get(nn).triggerSheetBarMenu(),!0)},Or={type:a.CommandType.COMMAND,id:"sheet.command.delete-worksheet-protection-from-sheet-bar",async handler(n,i){if(!i)return!1;const e=n.get(a.ICommandService),t=n.get(a.IUndoRedoService),r=n.get(m.WorksheetProtectionRuleModel),s=n.get(a.IUniverInstanceService).getCurrentUnitForType(Ll.UNIVER_SHEET),l=s==null?void 0:s.getActiveSheet(),d=s.getUnitId();if(!l)return!1;const c=l.getSheetId(),u=r.getRule(d,c);if(await e.executeCommand(m.DeleteWorksheetProtectionCommand.id,{unitId:d,subUnitId:c})){const g=[{id:m.DeleteWorksheetProtectionCommand.id,params:{unitId:d,subUnitId:c}}],S=[{id:m.AddWorksheetProtectionCommand.id,params:{unitId:d,rule:u}}];t.pushUndoRedo({unitID:d,redoMutations:g,undoMutations:S})}return!0}},xr={type:a.CommandType.COMMAND,id:"sheet.command.change-sheet-protection-from-sheet-bar",async handler(n){return await n.get(a.ICommandService).executeCommand("sheet-permission.operation.openDialog"),!0}},Ui={id:"sheet.operation.set-activate-cell-edit",type:a.CommandType.OPERATION,handler:(n,i)=>(n.get(Se).setEditCell(i),!0)},Ar={id:"sheet.operation.rename-sheet",type:a.CommandType.OPERATION,handler:async(n,i)=>{const e=n.get(nn);return i&&e.setRenameId(i.subUnitId),!0}},Ns={type:a.CommandType.OPERATION,id:"sheet-permission.operation.openDialog",async handler(n,i){const e=n.get(E.IDialogService);return e.close("DESKTOP_FIND_REPLACE_DIALOG"),e.open({id:oi,title:{title:"permission.dialog.allowedPermissionType"},children:{label:Fl},width:393,destroyOnClose:!0,onClose:()=>e.close(oi)}),!0}},rr="DefinedNameContainer",Li={id:"sidebar.operation.defined-name",type:a.CommandType.COMMAND,handler:async(n,i)=>{const e=n.get(E.ISidebarService);n.get(J.IEditorService);const t=n.get(a.LocaleService),r=n.get(a.IUniverInstanceService);if(!m.getSheetCommandTarget(r))return!1;switch(i.value){case"open":e.open({id:rr,header:{title:t.t("definedName.featureTitle")},children:{label:rr},onClose:()=>{},width:333});break;case"close":default:e.close();break}return!0}},Og=()=>_.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[_.jsx("path",{d:"M0.98999 1.08218H-0.0100098V0.0821838H0.98999V1.08218Z",fill:"black"}),_.jsx("path",{d:"M5.78992 1.08218H2.78992V0.0821838H5.78992V1.08218Z",fill:"black"}),_.jsx("path",{d:"M7.58984 1.08218H8.58984V0.0821838H7.58984V1.08218Z",fill:"black"}),_.jsx("path",{d:"M14.9152 1.08218H13.9152V0.0821838H14.9152V1.08218Z",fill:"black"}),_.jsx("path",{d:"M16.7151 1.08218H19.7151V0.0821838H16.7151V1.08218Z",fill:"black"}),_.jsx("path",{d:"M22.515 1.08218H21.515V0.0821838H22.515V1.08218Z",fill:"black"}),_.jsx("path",{d:"M27.8405 1.08218H28.8405V0.0821838H27.8405V1.08218Z",fill:"black"}),_.jsx("path",{d:"M33.6404 1.08218H30.6404V0.0821838H33.6404V1.08218Z",fill:"black"}),_.jsx("path",{d:"M35.4403 1.08218H36.4403V0.0821838H35.4403V1.08218Z",fill:"black"}),_.jsx("path",{d:"M42.7657 1.08218H41.7657V0.0821838H42.7657V1.08218Z",fill:"black"}),_.jsx("path",{d:"M44.5657 1.08218H47.5657V0.0821838H44.5657V1.08218Z",fill:"black"}),_.jsx("path",{d:"M50.3656 1.08218H49.3656V0.0821838H50.3656V1.08218Z",fill:"black"}),_.jsx("path",{d:"M55.691 1.08218H56.691V0.0821838H55.691V1.08218Z",fill:"black"}),_.jsx("path",{d:"M61.491 1.08218H58.491V0.0821838H61.491V1.08218Z",fill:"black"}),_.jsx("path",{d:"M63.2909 1.08218H64.2909V0.0821838H63.2909V1.08218Z",fill:"black"}),_.jsx("path",{d:"M70.6163 1.08218H69.6163V0.0821838H70.6163V1.08218Z",fill:"black"}),_.jsx("path",{d:"M72.4163 1.08218H75.4163V0.0821838H72.4163V1.08218Z",fill:"black"}),_.jsx("path",{d:"M78.2162 1.08218H77.2162V0.0821838H78.2162V1.08218Z",fill:"black"}),_.jsx("path",{d:"M83.5416 1.08218H84.5416V0.0821838H83.5416V1.08218Z",fill:"black"}),_.jsx("path",{d:"M89.3416 1.08218H86.3416V0.0821838H89.3416V1.08218Z",fill:"black"}),_.jsx("path",{d:"M91.1415 1.08218H92.1415V0.0821838H91.1415V1.08218Z",fill:"black"}),_.jsx("path",{d:"M98.4669 1.08218H97.4669V0.0821838H98.4669V1.08218Z",fill:"black"}),_.jsx("path",{d:"M100.267 1.08218H103.267V0.0821838H100.267V1.08218Z",fill:"black"}),_.jsx("path",{d:"M106.067 1.08218H105.067V0.0821838H106.067V1.08218Z",fill:"black"}),_.jsx("path",{d:"M111.392 1.08218H112.392V0.0821838H111.392V1.08218Z",fill:"black"}),_.jsx("path",{d:"M117.192 1.08218H114.192V0.0821838H117.192V1.08218Z",fill:"black"}),_.jsx("path",{d:"M118.992 1.08218H119.992V0.0821838H118.992V1.08218Z",fill:"black"})]}),xg=()=>_.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[_.jsx("path",{d:"M-0.0100098 1.15771H0.98999V0.157715H-0.0100098V1.15771Z",fill:"black"}),_.jsx("path",{d:"M2.78992 1.15771H5.78992V0.157715H2.78992V1.15771Z",fill:"black"}),_.jsx("path",{d:"M8.58984 1.15771H7.58984V0.157715H8.58984V1.15771Z",fill:"black"}),_.jsx("path",{d:"M10.3899 1.15771H11.3899V0.157715H10.3899V1.15771Z",fill:"black"}),_.jsx("path",{d:"M19.0903 1.15771H18.0903V0.157715H19.0903V1.15771Z",fill:"black"}),_.jsx("path",{d:"M20.8903 1.15771H23.8903V0.157715H20.8903V1.15771Z",fill:"black"}),_.jsx("path",{d:"M26.6902 1.15771H25.6902V0.157715H26.6902V1.15771Z",fill:"black"}),_.jsx("path",{d:"M28.4902 1.15771H29.4902V0.157715H28.4902V1.15771Z",fill:"black"}),_.jsx("path",{d:"M37.1907 1.15771H36.1907V0.157715H37.1907V1.15771Z",fill:"black"}),_.jsx("path",{d:"M38.9906 1.15771H41.9906V0.157715H38.9906V1.15771Z",fill:"black"}),_.jsx("path",{d:"M44.7905 1.15771H43.7905V0.157715H44.7905V1.15771Z",fill:"black"}),_.jsx("path",{d:"M46.5906 1.15771H47.5906V0.157715H46.5906V1.15771Z",fill:"black"}),_.jsx("path",{d:"M55.291 1.15771H54.291V0.157715H55.291V1.15771Z",fill:"black"}),_.jsx("path",{d:"M57.0909 1.15771H60.0909V0.157715H57.0909V1.15771Z",fill:"black"}),_.jsx("path",{d:"M62.8909 1.15771H61.8909V0.157715H62.8909V1.15771Z",fill:"black"}),_.jsx("path",{d:"M64.6909 1.15771H65.6909V0.157715H64.6909V1.15771Z",fill:"black"}),_.jsx("path",{d:"M73.3914 1.15771H72.3914V0.157715H73.3914V1.15771Z",fill:"black"}),_.jsx("path",{d:"M75.1913 1.15771H78.1913V0.157715H75.1913V1.15771Z",fill:"black"}),_.jsx("path",{d:"M80.9912 1.15771H79.9912V0.157715H80.9912V1.15771Z",fill:"black"}),_.jsx("path",{d:"M82.7913 1.15771H83.7913V0.157715H82.7913V1.15771Z",fill:"black"}),_.jsx("path",{d:"M91.4917 1.15771H90.4917V0.157715H91.4917V1.15771Z",fill:"black"}),_.jsx("path",{d:"M93.2916 1.15771H96.2916V0.157715H93.2916V1.15771Z",fill:"black"}),_.jsx("path",{d:"M99.0916 1.15771H98.0916V0.157715H99.0916V1.15771Z",fill:"black"}),_.jsx("path",{d:"M100.892 1.15771H101.892V0.157715H100.892V1.15771Z",fill:"black"}),_.jsx("path",{d:"M109.592 1.15771H108.592V0.157715H109.592V1.15771Z",fill:"black"}),_.jsx("path",{d:"M111.392 1.15771H114.392V0.157715H111.392V1.15771Z",fill:"black"}),_.jsx("path",{d:"M117.192 1.15771H116.192V0.157715H117.192V1.15771Z",fill:"black"}),_.jsx("path",{d:"M118.992 1.15771H119.992V0.157715H118.992V1.15771Z",fill:"black"})]}),Ag=()=>_.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[_.jsx("path",{d:"M-0.00842285 1.22449H2.99158V0.224487H-0.00842285V1.22449Z",fill:"black"}),_.jsx("path",{d:"M6.14941 1.22449H9.14941V0.224487H6.14941V1.22449Z",fill:"black"}),_.jsx("path",{d:"M15.3073 1.22449H12.3073V0.224487H15.3073V1.22449Z",fill:"black"}),_.jsx("path",{d:"M18.4651 1.22449H21.4651V0.224487H18.4651V1.22449Z",fill:"black"}),_.jsx("path",{d:"M27.6229 1.22449H24.6229V0.224487H27.6229V1.22449Z",fill:"black"}),_.jsx("path",{d:"M30.7808 1.22449H33.7808V0.224487H30.7808V1.22449Z",fill:"black"}),_.jsx("path",{d:"M39.9386 1.22449H36.9386V0.224487H39.9386V1.22449Z",fill:"black"}),_.jsx("path",{d:"M43.0964 1.22449H46.0964V0.224487H43.0964V1.22449Z",fill:"black"}),_.jsx("path",{d:"M52.2543 1.22449H49.2543V0.224487H52.2543V1.22449Z",fill:"black"}),_.jsx("path",{d:"M55.4121 1.22449H58.4121V0.224487H55.4121V1.22449Z",fill:"black"}),_.jsx("path",{d:"M64.5699 1.22449H61.5699V0.224487H64.5699V1.22449Z",fill:"black"}),_.jsx("path",{d:"M67.7278 1.22449H70.7278V0.224487H67.7278V1.22449Z",fill:"black"}),_.jsx("path",{d:"M76.8856 1.22449H73.8856V0.224487H76.8856V1.22449Z",fill:"black"}),_.jsx("path",{d:"M80.0435 1.22449H83.0435V0.224487H80.0435V1.22449Z",fill:"black"}),_.jsx("path",{d:"M89.2013 1.22449H86.2013V0.224487H89.2013V1.22449Z",fill:"black"}),_.jsx("path",{d:"M92.3591 1.22449H95.3591V0.224487H92.3591V1.22449Z",fill:"black"}),_.jsx("path",{d:"M101.517 1.22449H98.517V0.224487H101.517V1.22449Z",fill:"black"}),_.jsx("path",{d:"M104.675 1.22449H107.675V0.224487H104.675V1.22449Z",fill:"black"}),_.jsx("path",{d:"M113.833 1.22449H110.833V0.224487H113.833V1.22449Z",fill:"black"}),_.jsx("path",{d:"M116.99 1.22449H119.99V0.224487H116.99V1.22449Z",fill:"black"})]}),Ng=()=>_.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[_.jsx("path",{d:"M-0.00976562 1.65707H0.990234V0.657074H-0.00976562V1.65707Z",fill:"black"}),_.jsx("path",{d:"M2.32361 1.65707H3.32361V0.657074H2.32361V1.65707Z",fill:"black"}),_.jsx("path",{d:"M5.65698 1.65707H4.65698V0.657074H5.65698V1.65707Z",fill:"black"}),_.jsx("path",{d:"M6.99036 1.65707H7.99036V0.657074H6.99036V1.65707Z",fill:"black"}),_.jsx("path",{d:"M10.3237 1.65707H9.32373V0.657074H10.3237V1.65707Z",fill:"black"}),_.jsx("path",{d:"M11.6571 1.65707H12.6571V0.657074H11.6571V1.65707Z",fill:"black"}),_.jsx("path",{d:"M14.9905 1.65707H13.9905V0.657074H14.9905V1.65707Z",fill:"black"}),_.jsx("path",{d:"M16.3239 1.65707H17.3239V0.657074H16.3239V1.65707Z",fill:"black"}),_.jsx("path",{d:"M19.6572 1.65707H18.6572V0.657074H19.6572V1.65707Z",fill:"black"}),_.jsx("path",{d:"M20.9906 1.65707H21.9906V0.657074H20.9906V1.65707Z",fill:"black"}),_.jsx("path",{d:"M24.324 1.65707H23.324V0.657074H24.324V1.65707Z",fill:"black"}),_.jsx("path",{d:"M25.6573 1.65707H26.6573V0.657074H25.6573V1.65707Z",fill:"black"}),_.jsx("path",{d:"M28.9907 1.65707H27.9907V0.657074H28.9907V1.65707Z",fill:"black"}),_.jsx("path",{d:"M30.3241 1.65707H31.3241V0.657074H30.3241V1.65707Z",fill:"black"}),_.jsx("path",{d:"M33.6575 1.65707H32.6575V0.657074H33.6575V1.65707Z",fill:"black"}),_.jsx("path",{d:"M34.9908 1.65707H35.9908V0.657074H34.9908V1.65707Z",fill:"black"}),_.jsx("path",{d:"M38.3242 1.65707H37.3242V0.657074H38.3242V1.65707Z",fill:"black"}),_.jsx("path",{d:"M39.6576 1.65707H40.6576V0.657074H39.6576V1.65707Z",fill:"black"}),_.jsx("path",{d:"M42.991 1.65707H41.991V0.657074H42.991V1.65707Z",fill:"black"}),_.jsx("path",{d:"M44.3243 1.65707H45.3243V0.657074H44.3243V1.65707Z",fill:"black"}),_.jsx("path",{d:"M47.6577 1.65707H46.6577V0.657074H47.6577V1.65707Z",fill:"black"}),_.jsx("path",{d:"M48.9911 1.65707H49.9911V0.657074H48.9911V1.65707Z",fill:"black"}),_.jsx("path",{d:"M52.3245 1.65707H51.3245V0.657074H52.3245V1.65707Z",fill:"black"}),_.jsx("path",{d:"M53.6578 1.65707H54.6578V0.657074H53.6578V1.65707Z",fill:"black"}),_.jsx("path",{d:"M56.9912 1.65707H55.9912V0.657074H56.9912V1.65707Z",fill:"black"}),_.jsx("path",{d:"M58.3246 1.65707H59.3246V0.657074H58.3246V1.65707Z",fill:"black"}),_.jsx("path",{d:"M61.658 1.65707H60.658V0.657074H61.658V1.65707Z",fill:"black"}),_.jsx("path",{d:"M62.9913 1.65707H63.9913V0.657074H62.9913V1.65707Z",fill:"black"}),_.jsx("path",{d:"M66.3247 1.65707H65.3247V0.657074H66.3247V1.65707Z",fill:"black"}),_.jsx("path",{d:"M67.6581 1.65707H68.6581V0.657074H67.6581V1.65707Z",fill:"black"}),_.jsx("path",{d:"M70.9915 1.65707H69.9915V0.657074H70.9915V1.65707Z",fill:"black"}),_.jsx("path",{d:"M72.3248 1.65707H73.3248V0.657074H72.3248V1.65707Z",fill:"black"}),_.jsx("path",{d:"M75.6582 1.65707H74.6582V0.657074H75.6582V1.65707Z",fill:"black"}),_.jsx("path",{d:"M76.9916 1.65707H77.9916V0.657074H76.9916V1.65707Z",fill:"black"}),_.jsx("path",{d:"M80.325 1.65707H79.325V0.657074H80.325V1.65707Z",fill:"black"}),_.jsx("path",{d:"M81.6583 1.65707H82.6583V0.657074H81.6583V1.65707Z",fill:"black"}),_.jsx("path",{d:"M84.9917 1.65707H83.9917V0.657074H84.9917V1.65707Z",fill:"black"}),_.jsx("path",{d:"M86.3251 1.65707H87.3251V0.657074H86.3251V1.65707Z",fill:"black"}),_.jsx("path",{d:"M89.6584 1.65707H88.6584V0.657074H89.6584V1.65707Z",fill:"black"}),_.jsx("path",{d:"M90.9918 1.65707H91.9918V0.657074H90.9918V1.65707Z",fill:"black"}),_.jsx("path",{d:"M94.3252 1.65707H93.3252V0.657074H94.3252V1.65707Z",fill:"black"}),_.jsx("path",{d:"M95.6586 1.65707H96.6586V0.657074H95.6586V1.65707Z",fill:"black"}),_.jsx("path",{d:"M98.9919 1.65707H97.9919V0.657074H98.9919V1.65707Z",fill:"black"}),_.jsx("path",{d:"M100.325 1.65707H101.325V0.657074H100.325V1.65707Z",fill:"black"}),_.jsx("path",{d:"M103.659 1.65707H102.659V0.657074H103.659V1.65707Z",fill:"black"}),_.jsx("path",{d:"M104.992 1.65707H105.992V0.657074H104.992V1.65707Z",fill:"black"}),_.jsx("path",{d:"M108.325 1.65707H107.325V0.657074H108.325V1.65707Z",fill:"black"}),_.jsx("path",{d:"M109.659 1.65707H110.659V0.657074H109.659V1.65707Z",fill:"black"}),_.jsx("path",{d:"M112.992 1.65707H111.992V0.657074H112.992V1.65707Z",fill:"black"}),_.jsx("path",{d:"M114.325 1.65707H115.325V0.657074H114.325V1.65707Z",fill:"black"}),_.jsx("path",{d:"M117.659 1.65707H116.659V0.657074H117.659V1.65707Z",fill:"black"}),_.jsx("path",{d:"M118.992 1.65707H119.992V0.657074H118.992V1.65707Z",fill:"black"})]}),Dg=()=>_.jsx("svg",{width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:_.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 2.42035H-0.0090332V0.420349H119.991V2.42035Z",fill:"black"})}),Hg=()=>_.jsxs("svg",{width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[_.jsx("path",{d:"M-0.0100098 2.47614H1.98999V0.476135H-0.0100098V2.47614Z",fill:"black"}),_.jsx("path",{d:"M3.99014 2.47614H9.99014V0.476135H3.99014V2.47614Z",fill:"black"}),_.jsx("path",{d:"M13.9901 2.47614H11.9901V0.476135H13.9901V2.47614Z",fill:"black"}),_.jsx("path",{d:"M21.1904 2.47614H23.1904V0.476135H21.1904V2.47614Z",fill:"black"}),_.jsx("path",{d:"M31.1906 2.47614H25.1906V0.476135H31.1906V2.47614Z",fill:"black"}),_.jsx("path",{d:"M33.1906 2.47614H35.1906V0.476135H33.1906V2.47614Z",fill:"black"}),_.jsx("path",{d:"M44.3909 2.47614H42.3909V0.476135H44.3909V2.47614Z",fill:"black"}),_.jsx("path",{d:"M46.391 2.47614H52.391V0.476135H46.391V2.47614Z",fill:"black"}),_.jsx("path",{d:"M56.391 2.47614H54.391V0.476135H56.391V2.47614Z",fill:"black"}),_.jsx("path",{d:"M63.5913 2.47614H65.5913V0.476135H63.5913V2.47614Z",fill:"black"}),_.jsx("path",{d:"M73.5915 2.47614H67.5915V0.476135H73.5915V2.47614Z",fill:"black"}),_.jsx("path",{d:"M75.5915 2.47614H77.5915V0.476135H75.5915V2.47614Z",fill:"black"}),_.jsx("path",{d:"M86.7917 2.47614H84.7917V0.476135H86.7917V2.47614Z",fill:"black"}),_.jsx("path",{d:"M88.7919 2.47614H94.7919V0.476135H88.7919V2.47614Z",fill:"black"}),_.jsx("path",{d:"M98.7919 2.47614H96.7919V0.476135H98.7919V2.47614Z",fill:"black"}),_.jsx("path",{d:"M105.992 2.47614H107.992V0.476135H105.992V2.47614Z",fill:"black"}),_.jsx("path",{d:"M115.992 2.47614H109.992V0.476135H115.992V2.47614Z",fill:"black"}),_.jsx("path",{d:"M117.992 2.47614H119.992V0.476135H117.992V2.47614Z",fill:"black"})]}),kg=()=>_.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[_.jsx("path",{d:"M-0.0100098 2.00415H1.98999V0.00415039H-0.0100098V2.00415Z",fill:"black"}),_.jsx("path",{d:"M3.99014 2.00415H9.99014V0.00415039H3.99014V2.00415Z",fill:"black"}),_.jsx("path",{d:"M13.9901 2.00415H11.9901V0.00415039H13.9901V2.00415Z",fill:"black"}),_.jsx("path",{d:"M15.9901 2.00415H17.9901V0.00415039H15.9901V2.00415Z",fill:"black"}),_.jsx("path",{d:"M27.4905 2.00415H25.4905V0.00415039H27.4905V2.00415Z",fill:"black"}),_.jsx("path",{d:"M29.4906 2.00415H35.4906V0.00415039H29.4906V2.00415Z",fill:"black"}),_.jsx("path",{d:"M39.4906 2.00415H37.4906V0.00415039H39.4906V2.00415Z",fill:"black"}),_.jsx("path",{d:"M41.4906 2.00415H43.4906V0.00415039H41.4906V2.00415Z",fill:"black"}),_.jsx("path",{d:"M52.991 2.00415H50.991V0.00415039H52.991V2.00415Z",fill:"black"}),_.jsx("path",{d:"M54.9911 2.00415H60.9911V0.00415039H54.9911V2.00415Z",fill:"black"}),_.jsx("path",{d:"M64.9911 2.00415H62.9911V0.00415039H64.9911V2.00415Z",fill:"black"}),_.jsx("path",{d:"M66.9911 2.00415H68.9911V0.00415039H66.9911V2.00415Z",fill:"black"}),_.jsx("path",{d:"M78.4915 2.00415H76.4915V0.00415039H78.4915V2.00415Z",fill:"black"}),_.jsx("path",{d:"M80.4916 2.00415H86.4916V0.00415039H80.4916V2.00415Z",fill:"black"}),_.jsx("path",{d:"M90.4916 2.00415H88.4916V0.00415039H90.4916V2.00415Z",fill:"black"}),_.jsx("path",{d:"M92.4916 2.00415H94.4916V0.00415039H92.4916V2.00415Z",fill:"black"}),_.jsx("path",{d:"M103.992 2.00415H101.992V0.00415039H103.992V2.00415Z",fill:"black"}),_.jsx("path",{d:"M105.992 2.00415H111.992V0.00415039H105.992V2.00415Z",fill:"black"}),_.jsx("path",{d:"M115.992 2.00415H113.992V0.00415039H115.992V2.00415Z",fill:"black"}),_.jsx("path",{d:"M117.992 2.00415H119.992V0.00415039H117.992V2.00415Z",fill:"black"})]}),Vg=()=>_.jsxs("svg",{width:"118",height:"3",viewBox:"0 0 118 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[_.jsx("path",{d:"M-0.00854492 2.94815H1.99146V0.948151H-0.00854492V2.94815Z",fill:"black"}),_.jsx("path",{d:"M6.09668 2.94815H8.09668V0.948151H6.09668V2.94815Z",fill:"black"}),_.jsx("path",{d:"M14.2019 2.94815H12.2019V0.948151H14.2019V2.94815Z",fill:"black"}),_.jsx("path",{d:"M18.3071 2.94815H20.3071V0.948151H18.3071V2.94815Z",fill:"black"}),_.jsx("path",{d:"M26.4124 2.94815H24.4124V0.948151H26.4124V2.94815Z",fill:"black"}),_.jsx("path",{d:"M30.5176 2.94815H32.5176V0.948151H30.5176V2.94815Z",fill:"black"}),_.jsx("path",{d:"M38.6228 2.94815H36.6228V0.948151H38.6228V2.94815Z",fill:"black"}),_.jsx("path",{d:"M42.728 2.94815H44.728V0.948151H42.728V2.94815Z",fill:"black"}),_.jsx("path",{d:"M50.8333 2.94815H48.8333V0.948151H50.8333V2.94815Z",fill:"black"}),_.jsx("path",{d:"M54.9385 2.94815H56.9385V0.948151H54.9385V2.94815Z",fill:"black"}),_.jsx("path",{d:"M63.0437 2.94815H61.0437V0.948151H63.0437V2.94815Z",fill:"black"}),_.jsx("path",{d:"M67.1489 2.94815H69.1489V0.948151H67.1489V2.94815Z",fill:"black"}),_.jsx("path",{d:"M75.2542 2.94815H73.2542V0.948151H75.2542V2.94815Z",fill:"black"}),_.jsx("path",{d:"M79.3594 2.94815H81.3594V0.948151H79.3594V2.94815Z",fill:"black"}),_.jsx("path",{d:"M87.4645 2.94815H85.4645V0.948151H87.4645V2.94815Z",fill:"black"}),_.jsx("path",{d:"M91.5697 2.94815H93.5697V0.948151H91.5697V2.94815Z",fill:"black"}),_.jsx("path",{d:"M99.6749 2.94815H97.6749V0.948151H99.6749V2.94815Z",fill:"black"}),_.jsx("path",{d:"M103.78 2.94815H105.78V0.948151H103.78V2.94815Z",fill:"black"}),_.jsx("path",{d:"M111.885 2.94815H109.885V0.948151H111.885V2.94815Z",fill:"black"}),_.jsx("path",{d:"M115.991 2.94815H117.991V0.948151H115.991V2.94815Z",fill:"black"})]}),Wg=()=>_.jsx("svg",{width:"120",height:"4",viewBox:"0 0 120 4",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:_.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 3.86215H-0.0090332V0.862152H119.991V3.86215Z",fill:"black"})}),_a=()=>_.jsx("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:_.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 1.15668H-0.0090332V0.156677H119.991V1.15668Z",fill:"black"})});function Ia(n){const{type:i=a.BorderStyleTypes.THIN}=n;switch(i){case a.BorderStyleTypes.DASH_DOT:return _.jsx(Og,{});case a.BorderStyleTypes.DASH_DOT_DOT:return _.jsx(xg,{});case a.BorderStyleTypes.DASHED:return _.jsx(Ag,{});case a.BorderStyleTypes.HAIR:return _.jsx(Ng,{});case a.BorderStyleTypes.MEDIUM:return _.jsx(Dg,{});case a.BorderStyleTypes.MEDIUM_DASH_DOT:return _.jsx(Hg,{});case a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT:return _.jsx(kg,{});case a.BorderStyleTypes.MEDIUM_DASHED:return _.jsx(Vg,{});case a.BorderStyleTypes.THICK:return _.jsx(Wg,{});case a.BorderStyleTypes.THIN:return _.jsx(_a,{});default:return _.jsx(_a,{})}}const Ug="univer-ui-plugin-sheets-border-panel",Lg="univer-ui-plugin-sheets-border-panel-position",Bg="univer-ui-plugin-sheets-border-panel-position-item",Fg="univer-ui-plugin-sheets-border-panel-position-item-active",jg="univer-ui-plugin-sheets-border-panel-styles",zg="univer-ui-plugin-sheets-border-panel-board",Xg="univer-ui-plugin-sheets-border-panel-button",Yg="univer-ui-plugin-sheets-border-panel-more-icon",Be={uiPluginSheetsBorderPanel:Ug,uiPluginSheetsBorderPanelPosition:Lg,uiPluginSheetsBorderPanelPositionItem:Bg,uiPluginSheetsBorderPanelPositionItemActive:Fg,uiPluginSheetsBorderPanelStyles:jg,uiPluginSheetsBorderPanelBoard:zg,uiPluginSheetsBorderPanelButton:Xg,uiPluginSheetsBorderPanelMoreIcon:Yg},Ds=`${Hn}_BORDER_PANEL_COMPONENT`,Yl=[{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:"HorizontalBorder",value:"horizontal"},{label:"borderLine.borderVertical",icon:"VerticalBorder",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"}],Gg=[{label:a.BorderStyleTypes.THIN,value:a.BorderStyleTypes.THIN},{label:a.BorderStyleTypes.HAIR,value:a.BorderStyleTypes.HAIR},{label:a.BorderStyleTypes.DOTTED,value:a.BorderStyleTypes.DOTTED},{label:a.BorderStyleTypes.DASHED,value:a.BorderStyleTypes.DASHED},{label:a.BorderStyleTypes.DASH_DOT,value:a.BorderStyleTypes.DASH_DOT},{label:a.BorderStyleTypes.DASH_DOT_DOT,value:a.BorderStyleTypes.DASH_DOT_DOT},{label:a.BorderStyleTypes.MEDIUM,value:a.BorderStyleTypes.MEDIUM},{label:a.BorderStyleTypes.MEDIUM_DASHED,value:a.BorderStyleTypes.MEDIUM_DASHED},{label:a.BorderStyleTypes.MEDIUM_DASH_DOT,value:a.BorderStyleTypes.MEDIUM_DASH_DOT},{label:a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT,value:a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT},{label:a.BorderStyleTypes.THICK,value:a.BorderStyleTypes.THICK}];function Gl(n){var d;const i=a.useDependency(E.ComponentManager),e=a.useDependency(m.BorderStyleManagerService),{onChange:t,value:r}=n;function o(c,u){t==null||t({...r,[u]:c})}function s(c){const u=i.get(c);return u&&_.jsx(u,{extend:{colorChannel1:"rgb(var(--primary-color))"}})}function l(c){c.stopPropagation()}return _.jsxs("section",{className:Be.uiPluginSheetsBorderPanel,children:[_.jsx("div",{className:Be.uiPluginSheetsBorderPanelPosition,children:Yl.map(c=>_.jsx("div",{className:e.getBorderInfo().type===c.value?`
12
+ `)}),i}function Vh(n){return a.isNotNullOrUndefined(n.displayV)?n.displayV:a.extractPureTextFromCell(n)}function Wh(n,i,e,t){return t.getMergeData().some(r=>r.startRow<=n&&n<r.endRow&&i<=r.startColumn&&r.startColumn<=e)}function Uh(n,i,e,t){return t.getMergeData().some(r=>r.startColumn<=n&&n<r.endColumn&&i<=r.startRow&&r.startRow<=e)}function Lh(n){let i=0;return n.forValue((e,t,r)=>{if(r&&i++,i>1)return!1}),i>1}function Ln(){return{p:null,v:null,s:null,f:null,si:null,t:null}}const _s=998,ze={id:E.CopyCommand.id,name:"sheet.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:_s,preconditions:ps,handler:async n=>n.get(Ge).copy()},Is={id:E.CutCommand.id,name:"sheet.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:_s,preconditions:ps,handler:async n=>n.get(Ge).cut()},Xe={id:E.PasteCommand.id,type:a.CommandType.COMMAND,multi:!0,name:"sheet.command.paste",priority:_s,preconditions:ps,handler:async(n,i)=>{const t=await n.get(E.IClipboardInterfaceService).read(),r=n.get(Ge);return t.length!==0?r.paste(t[0],i==null?void 0:i.value):!1}},ti={id:E.SheetPasteShortKeyCommandName,type:a.CommandType.COMMAND,handler:async(n,i)=>{const e=n.get(Ge),{htmlContent:t,textContent:r,files:o}=i;return e.legacyPaste(t,r,o),!0}},Sn={id:"sheet.command.paste-value",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Xe.id,{value:ge.SPECIAL_PASTE_VALUE})},fn={id:"sheet.command.paste-format",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Xe.id,{value:ge.SPECIAL_PASTE_FORMAT})},Vt={id:"sheet.command.paste-col-width",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Xe.id,{value:ge.SPECIAL_PASTE_COL_WIDTH})},pn={id:"sheet.command.paste-besides-border",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Xe.id,{value:ge.SPECIAL_PASTE_BESIDES_BORDER})},gl={id:"sheet.command.optional-paste",type:a.CommandType.COMMAND,handler:async(n,{type:i})=>n.get(Ge).rePasteWithPasteType(i)},mr={id:"sheet.command.hide-row-confirm",type:a.CommandType.COMMAND,handler:async n=>{var d;const e=(d=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:d.map(c=>c.range);if(!(e!=null&&e.length))return!1;const t=n.get(a.ICommandService),r=n.get(a.IUniverInstanceService),o=m.getSheetCommandTarget(r);if(!o)return!1;const{worksheet:s}=o,l=s.getVisibleRows();if(Ga(l,e)){const c=n.get(E.IConfirmService),u=n.get(a.LocaleService);return await c.confirm({id:"sheet.confirm.hide-row",title:{title:u.t("info.problem")},children:{title:u.t("rightClick.hideAllRowsAlert")},cancelText:u.t("button.cancel"),confirmText:u.t("button.confirm")}),!1}return await t.executeCommand(m.SetRowHiddenCommand.id),!0}},gr={id:"sheet.command.hide-col-confirm",type:a.CommandType.COMMAND,handler:async n=>{var d;const e=(d=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:d.map(c=>c.range);if(!(e!=null&&e.length))return!1;const t=n.get(a.ICommandService),r=n.get(a.IUniverInstanceService),o=m.getSheetCommandTarget(r);if(!o)return!1;const{worksheet:s}=o,l=s.getVisibleCols();if(Za(l,e)){const c=n.get(E.IConfirmService),u=n.get(a.LocaleService);return await c.confirm({id:"sheet.confirm.hide-col",title:{title:u.t("info.problem")},children:{title:u.t("rightClick.hideAllColumnsAlert")},cancelText:u.t("button.cancel"),confirmText:u.t("button.confirm")}),!1}return await t.executeCommand(m.SetColHiddenCommand.id),!0}},Qt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-bold",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatBoldCommand.id):i.executeCommand(m.SetBoldCommand.id)}},Jt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-italic",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatItalicCommand.id):i.executeCommand(m.SetItalicCommand.id)}},$t={type:a.CommandType.COMMAND,id:"sheet.command.set-range-underline",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatUnderlineCommand.id):i.executeCommand(m.SetUnderlineCommand.id)}},en={type:a.CommandType.COMMAND,id:"sheet.command.set-range-stroke",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatStrikethroughCommand.id):i.executeCommand(m.SetStrikeThroughCommand.id)}},bs={type:a.CommandType.COMMAND,id:"sheet.command.set-range-subscript",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatSubscriptCommand.id):!1}},Rs={type:a.CommandType.COMMAND,id:"sheet.command.set-range-superscript",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand(J.SetInlineFormatSuperscriptCommand.id):!1}},Sr={type:a.CommandType.COMMAND,id:"sheet.command.set-range-fontsize",handler:async(n,i)=>{const e=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(J.SetInlineFormatFontSizeCommand.id,i):e.executeCommand(m.SetFontSizeCommand.id,i)}},fr={type:a.CommandType.COMMAND,id:"sheet.command.set-range-font-family",handler:async(n,i)=>{const e=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(J.SetInlineFormatFontFamilyCommand.id,i):e.executeCommand(m.SetFontFamilyCommand.id,i)}},yn={type:a.CommandType.COMMAND,id:"sheet.command.set-range-text-color",handler:async(n,i)=>{const e=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(J.SetInlineFormatTextColorCommand.id,i):e.executeCommand(m.SetTextColorCommand.id,i)}},Es={type:a.CommandType.COMMAND,id:"sheet.command.reset-range-text-color",handler:async n=>{const i=n.get(a.ICommandService),t=n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED),r=n.get(a.ThemeService);return t?i.executeCommand(J.SetInlineFormatTextColorCommand.id,{value:null}):i.executeCommand(m.SetTextColorCommand.id,{value:r.getCurrentTheme().textColor})}};var Bh=Object.defineProperty,Fh=Object.getOwnPropertyDescriptor,jh=(n,i,e,t)=>{for(var r=t>1?void 0:t?Fh(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Bh(i,e,r),r},ln=(n,i)=>(e,t)=>i(e,t,n),De=(n=>(n[n.OFF=0]="OFF",n[n.ONCE=1]="ONCE",n[n.INFINITE=2]="INFINITE",n))(De||{});const tt=a.createIdentifier("univer.format-painter-service");let ni=class extends a.Disposable{constructor(i,e,t,r,o,s){super();R(this,"status$");R(this,"_selectionFormat");R(this,"_markId",null);R(this,"_status$");R(this,"_defaultHook",null);R(this,"_extendHooks",[]);this._selectionManagerService=i,this._themeService=e,this._markSelectionService=t,this._logService=r,this._commandService=o,this._undoRedoService=s,this._status$=new O.BehaviorSubject(0),this.status$=this._status$.asObservable(),this._selectionFormat={styles:new a.ObjectMatrix,merges:[]}}addHook(i){var e,t,r;i.isDefaultHook&&((e=i.priority)!=null?e:0)>((r=(t=this._defaultHook)==null?void 0:t.priority)!=null?r:-1)?this._defaultHook=i:(this._extendHooks.push(i),this._extendHooks.sort((o,s)=>(o.priority||0)-(s.priority||0)))}getHooks(){return this._defaultHook?[this._defaultHook,...this._extendHooks]:this._extendHooks}setStatus(i){this._updateRangeMark(i),this._status$.next(i),this.getHooks().forEach(t=>{t.onStatusChange!==void 0&&t.onStatusChange(i)})}getStatus(){return this._status$.getValue()}setSelectionFormat(i){this._selectionFormat=i}getSelectionFormat(){return this._selectionFormat}applyFormatPainter(i,e,t){const r=this.getHooks(),o=[],s=[];r.forEach(d=>{if(d.onApply!==void 0){const c=d.onApply(i,e,t,this._selectionFormat);c&&(o.push(...c.redos),s.push(...c.undos))}});for(const d of r)if(d.onBeforeApply!==void 0&&!d.onBeforeApply({unitId:i,subUnitId:e,range:t,redoMutationsInfo:o,format:this._selectionFormat,undoMutationsInfo:s}))return!1;this._logService.log("[FormatPainterService]","apply mutations",{undoMutationsInfo:s,redoMutationsInfo:o});const l=o.every(d=>this._commandService.executeCommand(d.id,d.params));return l&&this._undoRedoService.pushUndoRedo({unitID:i,undoMutations:s,redoMutations:o}),l}_updateRangeMark(i){if(this._markSelectionService.removeAllShapes(),i!==0){const e=this._selectionManagerService.getCurrentLastSelection();if(e){const t=dl(this._themeService);i===2?this._markId=this._markSelectionService.addShape({...e,style:t}):this._markId=this._markSelectionService.addShape({...e,style:t},[m.SetRangeValuesMutation.id])}}}};ni=jh([ln(0,a.Inject(m.SheetsSelectionsService)),ln(1,a.Inject(a.ThemeService)),ln(2,qt),ln(3,a.ILogService),ln(4,a.ICommandService),ln(5,a.IUndoRedoService)],ni);const pr={id:"sheet.operation.set-format-painter",type:a.CommandType.OPERATION,handler:(n,i)=>i?(n.get(tt).setStatus(i.status),!0):!1},xi={type:a.CommandType.COMMAND,id:"sheet.command.set-infinite-format-painter",handler:async n=>{const e=n.get(tt).getStatus();let t;return e!==De.OFF?t=De.OFF:t=De.INFINITE,n.get(a.ICommandService).executeCommand(pr.id,{status:t})}},Dn={type:a.CommandType.COMMAND,id:"sheet.command.set-once-format-painter",handler:async n=>{const e=n.get(tt).getStatus();let t;return e!==De.OFF?t=De.OFF:t=De.ONCE,n.get(a.ICommandService).executeCommand(pr.id,{status:t})}},vr={type:a.CommandType.COMMAND,id:"sheet.command.apply-format-painter",handler:async(n,i)=>n.get(tt).applyFormatPainter(i.unitId,i.subUnitId,i.range)},ht={type:a.CommandType.COMMAND,id:"sheet.command.set-selection-frozen",handler:async(n,i)=>{const{type:e}=i||{},t=n.get(a.IUniverInstanceService),r=n.get(a.IUndoRedoService),o=m.getSheetCommandTarget(t);if(!o)return!1;const{unitId:s,subUnitId:l}=o,d=n.get(a.ICommandService),u=n.get(m.SheetsSelectionsService).getCurrentSelections();if(!u)return!1;const h=u[(u==null?void 0:u.length)-1],{range:g}=h,f=n.get(w.IRenderManagerService).getRenderById(s).with(exports.SheetScrollManagerService),{sheetViewStartRow:p=0,sheetViewStartColumn:v=0}=f.getCurrentScrollState()||{};let C,I,b,T;const{startRow:M,startColumn:y,rangeType:P}=g;if(P===a.RANGE_TYPE.ROW||e===1)C=M,b=M-p,I=-1,T=0;else if(P===a.RANGE_TYPE.COLUMN||e===2)C=-1,b=0,I=y,T=y-v;else if(P===a.RANGE_TYPE.NORMAL)C=M,b=M-p,I=y,T=y-v;else return!1;const x={unitId:s,subUnitId:l,startRow:C,startColumn:I,xSplit:I>0?Math.max(1,T):T,ySplit:C>0?Math.max(1,b):b},A=m.SetFrozenMutationFactory(n,x);return d.syncExecuteCommand(m.SetFrozenMutation.id,x)&&r.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetFrozenMutation.id,params:A}],redoMutations:[{id:m.SetFrozenMutation.id,params:x}]}),!0}},Cr={type:a.CommandType.COMMAND,id:"sheet.command.set-row-frozen",handler:async n=>(n.get(a.ICommandService).executeCommand(ht.id,{type:1}),!0)},_r={type:a.CommandType.COMMAND,id:"sheet.command.set-col-frozen",handler:async n=>(n.get(a.ICommandService).executeCommand(ht.id,{type:2}),!0)};var zh=Object.defineProperty,Xh=Object.getOwnPropertyDescriptor,Yh=(n,i,e,t)=>{for(var r=t>1?void 0:t?Xh(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&zh(i,e,r),r},ca=(n,i)=>(e,t)=>i(e,t,n);const Gh=(n,i)=>{const{unitId:e,subUnitId:t,ranges:r}=n,o={},s=i.getColumnManager();for(let l=0;l<r.length;l++){const d=r[l];for(let c=d.startColumn;c<d.endColumn+1;c++){const u=s.getColumnOrCreate(c);o[c]=u.w}}return{unitId:e,subUnitId:t,ranges:r,colWidth:o}};exports.AutoWidthController=class extends a.Disposable{constructor(i,e){super(),this._renderManagerService=i,this._univerInstanceService=e}getUndoRedoParamsOfColWidth(i){const e={redos:[],undos:[]},{_univerInstanceService:t}=this,r=m.getSheetCommandTarget(t);if(!r)return e;const{unitId:o,subUnitId:s,worksheet:l}=r,d=this._renderManagerService.getRenderById(o).with(exports.SheetSkeletonManagerService);if(!d.getCurrent())return e;const{skeleton:c}=d.getCurrent(),u=c.calculateAutoWidthInRange(i.ranges),h={};for(const{col:f,width:p}of u)h[f]=p;const g={subUnitId:s,unitId:o,ranges:i.ranges,colWidth:h},S=Gh(g,l);return{undos:[{id:m.SetWorksheetColWidthMutation.id,params:S}],redos:[{id:m.SetWorksheetColWidthMutation.id,params:g}]}}};exports.AutoWidthController=Yh([ca(0,w.IRenderManagerService),ca(1,a.Inject(a.IUniverInstanceService))],exports.AutoWidthController);const Ir={type:a.CommandType.COMMAND,id:"sheet.command.set-col-auto-width",handler:(n,i)=>{const e=n.get(a.ICommandService),t=n.get(a.IUndoRedoService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(o,i);if(!s)return!1;const{unitId:l,subUnitId:d}=s;let c=[];if(i!=null&&i.ranges)c=[...i.ranges];else{const f=r.getCurrentSelections();for(let p=0;p<f.length;p++)c.push(f[p].range)}if(!(c!=null&&c.length))return!1;const u={unitId:l,subUnitId:d,ranges:c},{redos:h,undos:g}=n.get(exports.AutoWidthController).getUndoRedoParamsOfColWidth(u);return a.sequenceExecute([...h],e).result?(t.pushUndoRedo({unitID:l,undoMutations:[...g],redoMutations:[...h]}),!0):!1}},Hn="UI_PLUGIN_SHEETS",br=`${Hn}_COLOR_PICKER_COMPONENT`,Ai=`${Hn}_FONT_FAMILY_COMPONENT`,Ni=`${Hn}_FONT_FAMILY_ITEM_COMPONENT`,Di=`${Hn}_FONT_SIZE_COMPONENT`,Hi=`${Hn}_MENU_ITEM_INPUT_COMPONENT`,Zh="univer-sheets-ui-context-menu-input",Kh="univer-sheets-ui-context-menu-input-container",qh="univer-sheets-ui-context-menu-input-number",Zi={sheetsUiContextMenuInput:Zh,sheetsUiContextMenuInputContainer:Kh,sheetsUiContextMenuInputNumber:qh},Sl=n=>{const{prefix:i,suffix:e,value:t,onChange:r,min:o=Number.MIN_SAFE_INTEGER,max:s=Number.MAX_SAFE_INTEGER}=n,l=a.useDependency(a.LocaleService),d=a.useDependency(E.IContextMenuService),[c,u]=V.useState(),h=S=>{var f;u(S==null?void 0:S.toString()),r((f=S==null?void 0:S.toString())!=null?f:"")};V.useEffect(()=>{d.visible||u(t)},[d.visible]),V.useEffect(()=>{u(t)},[t]);function g(S){S.key==="Backspace"&&S.stopPropagation()}return _.jsxs("div",{className:Zi.sheetsUiContextMenuInput,children:[l.t(i),_.jsx("span",{className:Zi.sheetsUiContextMenuInputContainer,onClick:S=>S.stopPropagation(),children:_.jsx(K.InputNumber,{className:Zi.sheetsUiContextMenuInputNumber,value:Number(c),precision:0,onKeyDown:g,onChange:h,min:o,max:s})}),l.t(e)]})};function Qh(n){return n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(O.switchMap(i=>i?i.activeSheet$.pipe(O.map(e=>e?{workbook:i,worksheet:e}:null)):O.of(null)))}function Pe(n,i,e){return Qh(n).pipe(O.switchMap(t=>t?e(t):O.of(i)))}function fl(n,i){const e=n.get(a.IUniverInstanceService),t=n.get(m.IExclusiveRangeService),r=n.get(m.SheetsSelectionsService);return e.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(O.switchMap(s=>s?O.combineLatest([r.selectionMoveEnd$,s.activeSheet$]).pipe(O.switchMap(([l,d])=>{if(!d||l.length===0)return O.of(!1);const c=t.getInterestGroupId(l);if(i){const u=c.filter(h=>i.has(h));return O.of(u.length>0)}else return O.of(c.length>0)})):O.of(!1)))}function tn(n,i,e){return O.combineLatest([i,fl(n,e)]).pipe(O.map(([t,r])=>t||r))}function te(n,i={},e=!1){var u;const r=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),o=n.get(a.UserManagerService),s=n.has(Se)?n.get(Se):null,d=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_FX_BAR_EDITOR),c=(u=s==null?void 0:s.visible$)!=null?u:O.of(null);return O.combineLatest([o.currentUser$,r,c,d]).pipe(O.switchMap(([h,g,S,f])=>!g||S!=null&&S.visible&&S.unitId===g.getUnitId()&&!e||f&&!e?O.of(!0):g.activeSheet$.pipe(O.switchMap(p=>{if(!p)return O.of(!0);const v=n.get(m.SheetsSelectionsService),C=n.get(m.RangeProtectionRuleModel),I=n.get(m.WorksheetProtectionRuleModel),T=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_COMMON_DRAWINGS).pipe(O.startWith(!1));return O.combineLatest([v.selectionMoveEnd$,T]).pipe(O.switchMap(([M,y])=>{if(y)return O.of(!0);const P=g.getUnitId(),x=p.getSheetId(),A=n.get(a.IPermissionService),{workbookTypes:N=[m.WorkbookEditablePermission],worksheetTypes:D,rangeTypes:H}=i,W=[];if(N==null||N.forEach(F=>{W.push(new F(P).id)}),D==null||D.forEach(F=>{W.push(new F(P,x).id)}),I.getRule(P,x))return A.composePermission$(W).pipe(O.map(F=>F.some(L=>L.value===!1)));const U=M==null?void 0:M.map(F=>F.range),B=C.getSubunitRuleList(P,x).filter(F=>U==null?void 0:U.some(L=>F.ranges.some(z=>a.Rectangle.intersects(L,z))));return H==null||H.forEach(F=>{B.forEach(L=>{W.push(new F(P,x,L.permissionId).id)})}),A.composePermission$(W).pipe(O.map(F=>F.some(L=>L.value===!1)))}))}))))}function ki(n){const i=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(m.RangeProtectionRuleModel),r=n.get(a.IPermissionService);return O.merge(e.selectionMoveEnd$,r.permissionPointUpdate$.pipe(O.debounceTime(100))).pipe(O.map(()=>{var h;const o=(h=e.getCurrentLastSelection())==null?void 0:h.range;if(!o)return!0;const s=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),l=s==null?void 0:s.getActiveSheet();if(!s||!l)return!0;const d=s.getUnitId(),c=l.getSheetId(),u=[new m.WorkbookEditablePermission(d).id,new m.WorksheetEditPermission(d,c).id];return t.getSubunitRuleList(d,c).filter(g=>g.ranges.some(S=>a.Rectangle.intersects(o,S))).forEach(g=>{u.push(new m.RangeProtectionPermissionEditPoint(d,c,g.permissionId).id)}),r.composePermission(u).some(g=>g.value===!1)}))}function pl(n,i){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.RangeProtectionRuleModel),o=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,o.permissionPointUpdate$.pipe(O.debounceTime(100))).pipe(O.map(()=>{var g;const s=(g=t.getCurrentLastSelection())==null?void 0:g.range;if(!s)return!0;const l=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d=l==null?void 0:l.getActiveSheet();if(!l||!d)return!0;const c=l.getUnitId(),u=d.getSheetId(),h=[new m.WorkbookEditablePermission(c).id,new m.WorksheetEditPermission(c,u).id];return r.getSubunitRuleList(c,u).filter(S=>i==="row"?S.ranges.some(f=>s.endRow>f.startRow&&s.endRow<=f.endRow):S.ranges.some(f=>s.endColumn>f.startColumn&&s.endColumn<=f.endColumn)).forEach(S=>{h.push(new m.RangeProtectionPermissionEditPoint(c,u,S.permissionId).id)}),o.composePermission(h).some(S=>S.value===!1)}))}function vl(n,i){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.RangeProtectionRuleModel),o=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,o.permissionPointUpdate$.pipe(O.debounceTime(100))).pipe(O.map(()=>{var g;const s=(g=t.getCurrentLastSelection())==null?void 0:g.range;if(!s)return!0;const l=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d=l==null?void 0:l.getActiveSheet();if(!l||!d)return!0;const c=l.getUnitId(),u=d.getSheetId(),h=[new m.WorkbookEditablePermission(c).id,new m.WorksheetEditPermission(c,u).id];return r.getSubunitRuleList(c,u).filter(S=>i==="row"?S.ranges.some(f=>s.startRow>f.startRow&&s.startRow<=f.endRow):S.ranges.some(f=>s.startColumn>f.startColumn&&s.startColumn<=f.endColumn)).forEach(S=>{h.push(new m.RangeProtectionPermissionEditPoint(c,u,S.permissionId).id)}),o.composePermission(h).some(S=>S.value===!1)}))}function Cl(n,i){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.RangeProtectionRuleModel),o=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,o.permissionPointUpdate$.pipe(O.debounceTime(100))).pipe(O.map(()=>{var S;const s=(S=t.getCurrentLastSelection())==null?void 0:S.range;if(!s)return!0;const l=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d=l==null?void 0:l.getActiveSheet();if(!l||!d)return!0;const c=l.getUnitId(),u=d.getSheetId(),h=[new m.WorkbookEditablePermission(c).id,new m.WorksheetEditPermission(c,u).id],g=a.Tools.deepClone(s);return i==="row"?(g.startColumn=0,g.endColumn=d.getColumnCount()-1):(g.startRow=0,g.endRow=d.getRowCount()-1),r.getSubunitRuleList(c,u).filter(f=>f.ranges.some(p=>a.Rectangle.intersects(g,p))).forEach(f=>{h.push(new m.RangeProtectionPermissionEditPoint(c,u,f.permissionId).id)}),o.composePermission(h).some(f=>f.value===!1)}))}function Vi(n,i){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.RangeProtectionRuleModel),o=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,o.permissionPointUpdate$.pipe(O.debounceTime(100))).pipe(O.map(()=>{var S;const s=(S=t.getCurrentLastSelection())==null?void 0:S.range;if(!s)return!0;const l=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d=l==null?void 0:l.getActiveSheet();if(!l||!d)return!0;const c=l.getUnitId(),u=d.getSheetId(),h=[new m.WorkbookEditablePermission(c).id,new m.WorksheetEditPermission(c,u).id],g=a.Tools.deepClone(s);return i==="row"?g.endRow=d.getRowCount()-1:g.endColumn=d.getColumnCount()-1,r.getSubunitRuleList(c,u).filter(f=>f.ranges.some(p=>a.Rectangle.intersects(g,p))).forEach(f=>{h.push(new m.RangeProtectionPermissionEditPoint(c,u,f.permissionId).id)}),o.composePermission(h).some(f=>f.value===!1)}))}function kn(n,i){const t=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(m.WorksheetProtectionRuleModel),o=n.get(m.RangeProtectionRuleModel),s=n.get(a.IPermissionService),l=n.get(a.UserManagerService);return O.combineLatest([l.currentUser$,t]).pipe(O.switchMap(([d,c])=>c?c.activeSheet$.pipe(O.switchMap(u=>{if(!u)return O.of(!0);const h=c.getUnitId(),g=[];return i.forEach(f=>g.push(new f(h).id)),s.composePermission$(g).pipe(O.map(f=>f.every(p=>p.value===!0))).pipe(O.map(f=>{if(!f)return!0;const p=u.getSheetId(),v=r.getRule(h,p),C=o.getSubunitRuleList(h,p);return!!(v||C.length)}))})):O.of(!0)))}var _l=(n=>(n.ROW_HEADER_CONTEXT_MENU="ROW_HEADER_CONTEXT_MENU",n.COL_HEADER_CONTEXT_MENU="COL_HEADER_CONTEXT_MENU",n.SHEET_BAR="SHEET_BAR",n.SHEET_FOOTER="SHEET_FOOTER",n))(_l||{});function Jh(n){const i=n.get(tt);return{id:Dn.id,subId:xi.id,type:E.MenuItemType.BUTTON,icon:"BrushSingle",title:"Format Painter",tooltip:"toolbar.formatPainter",activated$:new O.Observable(e=>{let t=!1;const r=i.status$.subscribe(o=>{t=o!==De.OFF,e.next(t)});return e.next(t),()=>{r.unsubscribe()}}),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetCopyPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0)}}function $h(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(a.IContextService),r=n.get(m.SheetsSelectionsService);return{id:Qt.id,type:E.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:Pe(e,!1,({worksheet:o})=>new O.Observable(s=>{var u;const l=i.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const p=(S=r.getCurrentLastSelection())==null?void 0:S.primary;let v=a.FontWeight.NORMAL;if(p!=null){const C=o.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getFontWeight()}s.next(v===a.FontWeight.BOLD)}if((g===be.SetTextSelectionsOperation.id||g===J.SetInlineFormatCommand.id)&&t.getContextValue(a.EDITOR_ACTIVATED)&&t.getContextValue(a.FOCUSING_SHEET)){const p=Er(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.bl;s.next(v===a.BooleanNumber.TRUE)}}),d=(u=r.getCurrentLastSelection())==null?void 0:u.primary;if(!o){s.next(!1);return}let c=a.FontWeight.NORMAL;if(d!=null){const h=o.getRange(d.startRow,d.startColumn);c=h==null?void 0:h.getFontWeight()}return s.next(c===a.FontWeight.BOLD),l.dispose})),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function em(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService);return{id:Jt.id,type:E.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:Pe(e,!1,({worksheet:o})=>new O.Observable(s=>{var u;const l=i.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const p=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let v=a.FontItalic.NORMAL;if(p!=null){const C=o.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getFontStyle()}s.next(v===a.FontItalic.ITALIC)}if((g===be.SetTextSelectionsOperation.id||g===J.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const p=Er(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.it;s.next(v===a.BooleanNumber.TRUE)}}),d=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let c=a.FontItalic.NORMAL;if(d!=null){const h=o.getRange(d.startRow,d.startColumn);c=h==null?void 0:h.getFontStyle()}return s.next(c===a.FontItalic.ITALIC),l.dispose})),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function tm(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService);return{id:$t.id,type:E.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",activated$:Pe(e,!1,({worksheet:o})=>new O.Observable(s=>{var u;const l=i.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const p=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let v;if(p!=null){const C=o.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getUnderline()}s.next(!!(v&&v.s))}if((g===be.SetTextSelectionsOperation.id||g===J.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const p=Er(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.ul;s.next((v==null?void 0:v.s)===a.BooleanNumber.TRUE)}}),d=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let c;if(d!=null){const h=o.getRange(d.startRow,d.startColumn);c=h==null?void 0:h.getUnderline()}return s.next(!!(c&&c.s)),l.dispose})),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function nm(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService);return{id:en.id,type:E.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:Pe(e,!1,({worksheet:o})=>new O.Observable(s=>{var u;const l=i.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const p=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let v;if(p!=null){const C=o.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getStrikeThrough()}s.next(!!(v&&v.s))}if((g===be.SetTextSelectionsOperation.id||g===J.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const p=Er(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.st;s.next((v==null?void 0:v.s)===a.BooleanNumber.TRUE)}}),d=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let c;if(d!=null){const h=o.getRange(d.startRow,d.startColumn);c=h==null?void 0:h.getStrikeThrough()}return s.next(!!(c&&c.s)),l.dispose})),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function rm(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=a.DEFAULT_STYLES.ff;return{id:fr.id,tooltip:"toolbar.font",type:E.MenuItemType.SELECTOR,label:Ai,selections:E.FONT_FAMILY_LIST.map(o=>({label:{name:Ni,hoverable:!0},value:o.value})),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),value$:Pe(e,r,({worksheet:o})=>new O.Observable(s=>{var u;const l=i.onCommandExecuted(h=>{var p;const g=h.id;if(g!==m.SetRangeValuesMutation.id&&g!==m.SetSelectionsOperation.id&&g!==m.SetWorksheetActiveOperation.id)return;const S=(p=t.getCurrentLastSelection())==null?void 0:p.primary;let f;if(S!=null){const v=o.getRange(S.startRow,S.startColumn);f=v==null?void 0:v.getFontFamily()}s.next(f!=null?f:r)}),d=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let c;if(d!=null){const h=o.getRange(d.startRow,d.startColumn);c=h==null?void 0:h.getFontFamily()}return s.next(c!=null?c:r),l.dispose})),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function im(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService),o=a.DEFAULT_STYLES.fs,s=te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0);return{id:Sr.id,type:E.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Di,props:{min:1,max:400,disabled$:s}},selections:E.FONT_SIZE_LIST,disabled$:s,value$:Pe(e,o,({worksheet:l})=>new O.Observable(d=>{var g;const c=i.onCommandExecuted(S=>{var p,v;const f=S.id;if(f===m.SetRangeValuesMutation.id||f===m.SetSelectionsOperation.id||f===m.SetWorksheetActiveOperation.id){const C=(p=t.getCurrentLastSelection())==null?void 0:p.primary;let I;if(C!=null){const b=l.getRange(C.startRow,C.startColumn);I=b==null?void 0:b.getFontSize()}d.next(I!=null?I:o)}if((f===be.SetTextSelectionsOperation.id||f===J.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const C=Er(n);if(C==null)return;const I=(v=C.ts)==null?void 0:v.fs;d.next(I!=null?I:o)}}),u=(g=t.getCurrentLastSelection())==null?void 0:g.primary;let h;if(u!=null){const S=l.getRange(u.startRow,u.startColumn);h=S==null?void 0:S.getFontSize()}return d.next(h!=null?h:o),c.dispose})),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function om(n){return{id:Es.id,type:E.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function sm(n){const i=n.get(a.ICommandService),e=n.get(a.ThemeService);return{id:yn.id,icon:"FontColor",tooltip:"toolbar.textColor.main",type:E.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:br,hoverable:!1}}],value$:new O.Observable(t=>{const r=e.getCurrentTheme().textColor,o=i.onCommandExecuted(s=>{if(s.id===yn.id){const l=s.params.value;t.next(l!=null?l:r)}});return t.next(r),o.dispose}),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0)}}function am(n){return{id:m.ResetBackgroundColorCommand.id,type:E.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function lm(n){const i=n.get(a.ICommandService),e=n.get(a.ThemeService);return{id:m.SetBackgroundColorCommand.id,tooltip:"toolbar.fillColor.main",type:E.MenuItemType.BUTTON_SELECTOR,icon:"PaintBucket",selections:[{label:{name:br,hoverable:!1}}],value$:new O.Observable(t=>{const r=e.getCurrentTheme().primaryColor,o=i.onCommandExecuted(s=>{if(s.id===m.SetBackgroundColorCommand.id){const l=s.params.value;t.next(l!=null?l:r)}});return t.next(r),o.dispose}),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const da=[{label:"align.left",icon:"LeftJustifyingSingle",value:a.HorizontalAlign.LEFT},{label:"align.center",icon:"HorizontallySingle",value:a.HorizontalAlign.CENTER},{label:"align.right",icon:"RightJustifyingSingle",value:a.HorizontalAlign.RIGHT}];function cm(n){const i=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=a.HorizontalAlign.LEFT;return{id:m.SetHorizontalTextAlignCommand.id,icon:da[0].icon,tooltip:"toolbar.horizontalAlignMode.main",type:E.MenuItemType.SELECTOR,selections:da,value$:Pe(i,t,({worksheet:r})=>new O.Observable(o=>{var c;const s=n.get(a.ICommandService).onCommandExecuted(u=>{var f;const h=u.id;if(h!==m.SetHorizontalTextAlignCommand.id&&h!==m.SetSelectionsOperation.id&&h!==m.SetWorksheetActiveOperation.id)return;const g=(f=e.getCurrentLastSelection())==null?void 0:f.primary;let S;if(g!=null){const p=r.getRange(g.startRow,g.startColumn);S=p==null?void 0:p.getHorizontalAlignment()}o.next(S!=null?S:t)}),l=(c=e.getCurrentLastSelection())==null?void 0:c.primary;let d;if(l!=null){const u=r.getRange(l.startRow,l.startColumn);d=u==null?void 0:u.getHorizontalAlignment()}return o.next(d!=null?d:t),s.dispose})),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const ua=[{label:"align.top",icon:"AlignTopSingle",value:a.VerticalAlign.TOP},{label:"align.middle",icon:"VerticalCenterSingle",value:a.VerticalAlign.MIDDLE},{label:"align.bottom",icon:"AlignBottomSingle",value:a.VerticalAlign.BOTTOM}];function dm(n){const i=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=a.VerticalAlign.BOTTOM;return{id:m.SetVerticalTextAlignCommand.id,icon:ua[2].icon,tooltip:"toolbar.verticalAlignMode.main",type:E.MenuItemType.SELECTOR,selections:ua,value$:Pe(i,t,({worksheet:r})=>new O.Observable(o=>{var c;const s=n.get(a.ICommandService).onCommandExecuted(u=>{var f;const h=u.id;if(h!==m.SetVerticalTextAlignCommand.id&&h!==m.SetSelectionsOperation.id&&h!==m.SetWorksheetActiveOperation.id)return;const g=(f=e.getCurrentLastSelection())==null?void 0:f.primary;let S;if(g!=null){const p=r.getRange(g.startRow,g.startColumn);S=p==null?void 0:p.getVerticalAlignment()}o.next(S!=null?S:t)}),l=(c=e.getCurrentLastSelection())==null?void 0:c.primary;let d;if(l!=null){const u=r.getRange(l.startRow,l.startColumn);d=u==null?void 0:u.getVerticalAlignment()}return o.next(d!=null?d:t),s.dispose})),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const ha=[{label:"textWrap.overflow",icon:"OverflowSingle",value:a.WrapStrategy.OVERFLOW},{label:"textWrap.wrap",icon:"AutowrapSingle",value:a.WrapStrategy.WRAP},{label:"textWrap.clip",icon:"TruncationSingle",value:a.WrapStrategy.CLIP}];function um(n){const i=n.get(m.SheetsSelectionsService),e=n.get(a.IUniverInstanceService),t=a.WrapStrategy.OVERFLOW;return{id:m.SetTextWrapCommand.id,tooltip:"toolbar.textWrapMode.main",icon:ha[0].icon,type:E.MenuItemType.SELECTOR,selections:ha,value$:Pe(e,t,({worksheet:r})=>new O.Observable(o=>{var c;const s=n.get(a.ICommandService).onCommandExecuted(u=>{var f;const h=u.id;if(h!==m.SetTextWrapCommand.id&&h!==m.SetSelectionsOperation.id&&h!==m.SetWorksheetActiveOperation.id)return;const g=(f=i.getCurrentLastSelection())==null?void 0:f.primary;let S;if(g!=null){const p=r.getRange(g.startRow,g.startColumn);S=p==null?void 0:p.getWrapStrategy()}o.next(S!=null?S:t)}),l=(c=i.getCurrentLastSelection())==null?void 0:c.primary;let d;if(l!=null){const u=r.getRange(l.startRow,l.startColumn);d=u==null?void 0:u.getWrapStrategy()}return o.next(d!=null?d:t),s.dispose})),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const ma=[{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 hm(n){const i=n.get(m.SheetsSelectionsService),e=n.get(a.IUniverInstanceService),t=0;return{id:m.SetTextRotationCommand.id,tooltip:"toolbar.textRotateMode.main",icon:ma[0].icon,type:E.MenuItemType.SELECTOR,selections:ma,value$:Pe(e,t,({worksheet:r})=>new O.Observable(o=>{var c,u;const s=n.get(a.ICommandService).onCommandExecuted(h=>{var p,v;const g=h.id;if(g!==m.SetTextRotationCommand.id&&g!==m.SetSelectionsOperation.id&&g!==m.SetWorksheetActiveOperation.id)return;const S=(p=i.getCurrentLastSelection())==null?void 0:p.primary;let f;if(S!=null){const C=r.getRange(S.startRow,S.startColumn);f=C==null?void 0:C.getTextRotation()}(f==null?void 0:f.v)===a.BooleanNumber.TRUE?o.next("v"):o.next((v=f&&f.a)!=null?v:t)}),l=(c=i.getCurrentLastSelection())==null?void 0:c.primary;let d;if(l!=null){const h=r.getRange(l.startRow,l.startColumn);d=h==null?void 0:h.getTextRotation()}return(d==null?void 0:d.v)===a.BooleanNumber.TRUE?o.next("v"):o.next((u=d&&d.a)!=null?u:t),s.dispose})),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Rr(n){return new O.Observable(e=>e.next(!n.get(E.IClipboardInterfaceService).supportClipboard))}function vn(n){return{id:ze.name,commandId:ze.id,type:E.MenuItemType.BUTTON,title:"rightClick.copy",icon:"Copy",disabled$:te(n,{workbookTypes:[m.WorkbookCopyPermission],worksheetTypes:[m.WorksheetCopyPermission],rangeTypes:[m.RangeProtectionPermissionViewPoint]}),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Ki(n){return{id:Xe.name,commandId:Xe.id,type:E.MenuItemType.BUTTON,title:"rightClick.paste",icon:"PasteSpecial",disabled$:Rr(n).pipe(O.combineLatestWith(te(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission,m.WorksheetSetCellValuePermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([i,e])=>i||e)),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const qn="sheet.menu.paste-special";function qi(n){return{id:qn,type:E.MenuItemType.SUBITEMS,icon:"PasteSpecial",title:"rightClick.pasteSpecial",hidden$:tn(n,E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET))}}function Qi(n){return{id:Sn.id,type:E.MenuItemType.BUTTON,title:"rightClick.pasteValue",disabled$:Rr(n).pipe(O.combineLatestWith(te(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellValuePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([i,e])=>i||e)),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Ji(n){return{id:fn.id,type:E.MenuItemType.BUTTON,title:"rightClick.pasteFormat",disabled$:Rr(n).pipe(O.combineLatestWith(te(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellStylePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([i,e])=>i||e)),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function $i(n){return{id:Vt.id,type:E.MenuItemType.BUTTON,title:"rightClick.pasteColWidth",disabled$:Rr(n).pipe(O.combineLatestWith(te(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetColumnStylePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([i,e])=>i||e))}}function eo(n){return{id:pn.id,type:E.MenuItemType.BUTTON,title:"rightClick.pasteBesidesBorder",disabled$:Rr(n).pipe(O.combineLatestWith(te(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission,m.WorksheetSetCellValuePermission,m.WorksheetSetRowStylePermission,m.WorksheetSetColumnStylePermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([i,e])=>i||e)),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function mm(n){return{id:m.SetWorksheetRowIsAutoHeightCommand.id,type:E.MenuItemType.BUTTON,icon:"AutoHeight",title:"rightClick.fitContent",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function gm(n){return{id:Ir.id,type:E.MenuItemType.BUTTON,icon:"AutoWidth",title:"rightClick.fitContent",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Il="sheet.menu.sheet-frozen";function Sm(n){return{id:Il,type:E.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Fo="sheet.header-menu.sheet-frozen";function ga(n){return{id:Fo,type:E.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function to(n){return{id:ht.id,type:E.MenuItemType.BUTTON,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function fm(n){return{id:Cr.id,type:E.MenuItemType.BUTTON,title:"rightClick.freezeRow",icon:"FreezeRowSingle",hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function pm(n){return{id:_r.id,type:E.MenuItemType.BUTTON,title:"rightClick.freezeCol",icon:"FreezeColumnSingle",hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function no(n){return{id:m.CancelFrozenCommand.id,type:E.MenuItemType.BUTTON,title:"rightClick.cancelFreeze",icon:"CancelFreezeSingle",hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function vm(n){return{id:mr.id,type:E.MenuItemType.BUTTON,icon:"Hide",title:"rightClick.hideSelectedRow",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Cm(n){return{id:gr.id,type:E.MenuItemType.BUTTON,icon:"Hide",title:"rightClick.hideSelectedColumn",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:E.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function _m(n){const i=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=[m.SetSelectionsOperation,m.SetRowHiddenMutation,m.SetRowVisibleMutation].map(o=>o.id);return{id:m.SetSelectedRowsVisibleCommand.id,type:E.MenuItemType.BUTTON,title:"rightClick.showHideRow",hidden$:Pe(i,!0,({worksheet:o})=>new O.Observable(s=>{function l(){var u;const c=(u=e.getCurrentSelections())==null?void 0:u.map(h=>h.range).filter(h=>h.rangeType===a.RANGE_TYPE.ROW);return!!(c!=null&&c.some(h=>{for(let g=h.startRow;g<=h.endRow;g++)if(!o.getRowRawVisible(g))return!0;return!1}))}const d=t.onCommandExecuted(c=>{r.findIndex(u=>u===c.id)!==-1&&s.next(!l())});return s.next(!l()),()=>d.dispose()})),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetRowStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Im(n){const i=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=[m.SetSelectionsOperation,m.SetColHiddenMutation,m.SetColVisibleMutation].map(o=>o.id);return{id:m.SetSelectedColsVisibleCommand.id,type:E.MenuItemType.BUTTON,title:"rightClick.showHideColumn",hidden$:Pe(i,!0,({worksheet:o})=>new O.Observable(s=>{function l(){var u;const c=(u=e.getCurrentSelections())==null?void 0:u.map(h=>h.range).filter(h=>h.rangeType===a.RANGE_TYPE.COLUMN);return!c||c.length===0?!1:!!c.some(h=>{for(let g=h.startColumn;g<=h.endColumn;g++)if(!o.getColVisible(g))return!0;return!1})}const d=t.onCommandExecuted(c=>{r.findIndex(u=>u===c.id)!==-1&&s.next(!l())});return s.next(!l()),()=>d.dispose()})),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetColumnStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function bm(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=0;return{id:m.SetRowHeightCommand.id,type:E.MenuItemType.BUTTON,icon:"AdjustHeight",label:{name:Hi,props:{prefix:"rightClick.rowHeight",suffix:"px",min:2,max:1e3}},value$:Pe(e,r,({worksheet:o})=>new O.Observable(s=>{function l(){var h;const c=(h=t.getCurrentLastSelection())==null?void 0:h.primary,u=c?o.getRowHeight(c.startRow):r;s.next(u)}const d=i.onCommandExecuted(c=>{const u=c.id;if(u===m.SetRangeValuesMutation.id||u===m.SetSelectionsOperation.id||u===m.SetWorksheetRowIsAutoHeightMutation.id)return l()});return l(),d.dispose})),hidden$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetRowStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Rm(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=0;return{id:m.SetColWidthCommand.id,type:E.MenuItemType.BUTTON,icon:"AdjustWidth",label:{name:Hi,props:{prefix:"rightClick.columnWidth",suffix:"px",min:2,max:1e3}},value$:Pe(e,r,({worksheet:o})=>new O.Observable(s=>{function l(){var h;const c=(h=t.getCurrentLastSelection())==null?void 0:h.primary;let u=r;c!=null&&(u=o.getColumnWidth(c.startColumn)),s.next(u)}const d=i.onCommandExecuted(c=>{const u=c.id;if(u===m.SetRangeValuesMutation.id||u===m.SetSelectionsOperation.id||u===m.SetWorksheetColWidthMutation.id)return l()});return l(),d.dispose})),hidden$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Er(n){var d;const i=n.get(a.IUniverInstanceService),e=n.get(be.DocSelectionManagerService),t=i.getUniverDocInstance(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),r=e.getActiveTextRange();if(t==null||r==null)return null;const o=(d=t.getBody())==null?void 0:d.textRuns;if(o==null)return;const{startOffset:s}=r;return o.find(({st:c,ed:u})=>s>=c&&s<=u)}var Em=Object.defineProperty,Tm=Object.getOwnPropertyDescriptor,wm=(n,i,e,t)=>{for(var r=t>1?void 0:t?Tm(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Em(i,e,r),r},xt=(n,i)=>(e,t)=>i(e,t,n);const ym="__SpreadsheetFreezeRowMainName__",bl="__SpreadsheetFreezeRowHeaderName__",Mm="__SpreadsheetFreezeColumnMainName__",Rl="__SpreadsheetFreezeColumnHeaderName__",ro=2,Pm=.01,Bn=a.createInterceptorKey("freezePermissionCheck");exports.HeaderFreezeRenderController=class extends a.Disposable{constructor(e,t,r,o,s,l,d,c){super();R(this,"_rowFreezeHeaderRect");R(this,"_rowFreezeMainRect");R(this,"_columnFreezeHeaderRect");R(this,"_columnFreezeMainRect");R(this,"_freezeDownSubs");R(this,"_freezePointerEnterSubs");R(this,"_freezePointerLeaveSubs");R(this,"_scenePointerMoveSub");R(this,"_scenePointerUpSub");R(this,"_changeToRow",-1);R(this,"_changeToColumn",-1);R(this,"_changeToOffsetX",0);R(this,"_changeToOffsetY",0);R(this,"_activeViewport",null);R(this,"_freezeNormalHeaderColor","");R(this,"_freezeNormalMainColor","");R(this,"_freezeActiveColor","");R(this,"_freezeHoverColor","");R(this,"_lastFreeze");R(this,"interceptor",new a.InterceptorManager({FREEZE_PERMISSION_CHECK:Bn}));this._context=e,this._sheetSkeletonManagerService=t,this._commandService=r,this._selectionManagerService=o,this._scrollManagerService=s,this._themeService=l,this._sheetInterceptorService=d,this._injector=c,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._themeChangeListener(),this._interceptorCommands(),this._bindViewportScroll(),this._zoomRefresh()}_createFreeze(e=0,t){var x;const r=t!=null?t:this._getFreeze();if(r==null)return null;const o=(x=this._sheetSkeletonManagerService.getCurrent())==null?void 0:x.skeleton,{startRow:s,startColumn:l}=r,d=this._getPositionByIndex(s,l);if(d==null||o==null)return null;const c=this._getSheetObject(),u=c.engine,h=(u==null?void 0:u.width)||0,g=(u==null?void 0:u.height)||0,S=c.scene,{startX:f,startY:p}=d,{rowTotalHeight:v,columnTotalWidth:C,rowHeaderWidthAndMarginLeft:I,columnHeaderHeightAndMarginTop:b}=o,T=h>C+I?h:C+b,M=g>v+b?g:v+b;this._changeToRow=s,this._changeToColumn=l,this._changeToOffsetX=f,this._changeToOffsetY=p;const y=Math.max(S.scaleX,S.scaleY);let P=ro/(y<1?1:y);if(e===0){(s===-1||s===0)&&(P=P*2);const A=P;this._rowFreezeHeaderRect=new w.Rect(bl,{fill:this._freezeNormalHeaderColor,width:I,height:P,left:0,top:p-A,zIndex:3});let N=this._freezeNormalHeaderColor;(s===-1||s===0)&&(N=this._freezeNormalMainColor),this._rowFreezeMainRect=new w.Rect(ym,{fill:N,width:T*2/y,height:P,left:I,top:p-A,zIndex:3}),S.addObjects([this._rowFreezeHeaderRect,this._rowFreezeMainRect],bt)}else{(l===-1||l===0)&&(P=P*2);const A=P;this._columnFreezeHeaderRect=new w.Rect(Rl,{fill:this._freezeNormalHeaderColor,width:P,height:b,left:f-A,top:0,zIndex:3});let N=this._freezeNormalHeaderColor;(l===-1||l===0)&&(N=this._freezeNormalMainColor),this._columnFreezeMainRect=new w.Rect(Mm,{fill:N,width:P,height:M*2/y,left:f-A,top:b,zIndex:3}),S.addObjects([this._columnFreezeHeaderRect,this._columnFreezeMainRect],bt)}this._eventBinding(e)}_eventBinding(e=0){let t=this._rowFreezeHeaderRect,r=this._rowFreezeMainRect;e===1&&(t=this._columnFreezeHeaderRect,r=this._columnFreezeMainRect);const o=this._getSheetObject();if(o==null)return;const{scene:s}=o;if(this._freezePointerEnterSubs=new O.Subscription,this._freezePointerLeaveSubs=new O.Subscription,this._freezeDownSubs=new O.Subscription,r){const c=r.onPointerEnter$.subscribeEvent(()=>{if(!this.interceptor.fetchThroughInterceptors(Bn)(!0,null))return!1;t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),s.setCursor(w.CURSOR_TYPE.GRAB)});this._freezePointerEnterSubs.add(c);const u=r.onPointerLeave$.subscribeEvent(()=>{t==null||t.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),s.resetCursor()});this._freezePointerLeaveSubs.add(u)}if(t){const c=t.onPointerEnter$.subscribeEvent(()=>{if(!this.interceptor.fetchThroughInterceptors(Bn)(!0,null))return!1;t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),s.setCursor(w.CURSOR_TYPE.GRAB)});this._freezePointerEnterSubs.add(c);const u=t.onPointerLeave$.subscribeEvent(()=>{t==null||t.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),s.resetCursor()});this._freezePointerLeaveSubs.add(u)}const l=t==null?void 0:t.onPointerDown$.subscribeEvent(c=>{this._freezeDown(c,t,r,e)});l&&this._freezeDownSubs.add(l);const d=r==null?void 0:r.onPointerDown$.subscribeEvent(c=>{this._freezeDown(c,t,r,e)});d&&this._freezeDownSubs.add(d)}_getCurrentLastVisible(){var C,I,b,T,M,y,P;const e=this._getSheetObject();if(e==null)return;const t=(C=this._sheetSkeletonManagerService.getCurrent())==null?void 0:C.skeleton;if(t==null)return;const r=e.scene,o=Math.max(r.scaleX,r.scaleY),s=this._scrollManagerService.getCurrentScrollState(),l=(e.engine.height-t.columnHeaderHeight)/o,d=(e.engine.width-t.rowHeaderWidth)/o,c=(I=s==null?void 0:s.sheetViewStartRow)!=null?I:0,u=c===0?-((b=s==null?void 0:s.offsetY)!=null?b:0):t.rowHeightAccumulation[c-1]-((T=s==null?void 0:s.offsetY)!=null?T:0);let h=0,g=!1;for(let x=c,A=t.rowHeightAccumulation.length;x<A;x++)if(t.rowHeightAccumulation[x]-u>l){h=x,g=!0;break}g||(h=t.rowHeightAccumulation.length-1);const S=(M=s==null?void 0:s.sheetViewStartColumn)!=null?M:0,f=S===0?-((y=s==null?void 0:s.offsetX)!=null?y:0):t.columnWidthAccumulation[S-1]-((P=s==null?void 0:s.offsetX)!=null?P:0);let p=0,v=!1;for(let x=S,A=t.columnWidthAccumulation.length;x<A;x++)if(t.columnWidthAccumulation[x]-f>d){p=x,v=!0;break}return v||(p=t.columnWidthAccumulation.length-1),{lastRow:h,lastColumn:p}}_getActiveViewport(e){var r;const t=(r=this._getSheetObject())==null?void 0:r.scene.getViewports();return t&&t.find(o=>o.isHit(new w.Vector2(e.offsetX,e.offsetY)))||null}_freezeDown(e,t,r,o=0){var f;const s=(f=this._sheetSkeletonManagerService.getCurrent())==null?void 0:f.skeleton;if(s==null)return;const l=this._getSheetObject();if(l==null)return;if(!this.interceptor.fetchThroughInterceptors(Bn)(!0,null))return!1;const{scene:c}=l;c.setCursor(w.CURSOR_TYPE.GRABBING),c.disableObjectsEvent();const u=this._getCurrentLastVisible(),h=u===void 0?Number.POSITIVE_INFINITY:s.rowHeightAccumulation[u.lastRow],g=u===void 0?Number.POSITIVE_INFINITY:s.columnWidthAccumulation[u.lastColumn-1]+s.rowHeaderWidth;this._activeViewport=null;const S=this._getFreeze();S&&(this._changeToColumn=S.startColumn,this._changeToRow=S.startRow),this._scenePointerMoveSub=c.onPointerMove$.subscribeEvent(p=>{var P,x,A,N;const v=this._getActiveViewport(p),{startX:C,startY:I,row:b,column:T}=qe(p.offsetX,p.offsetY,c,s,v||void 0,!0);if(!this.interceptor.fetchThroughInterceptors(Bn)(!0,null))return!1;c.setCursor(w.CURSOR_TYPE.GRABBING);const y=ro/Math.max(c.scaleX,c.scaleY);o===0?((P=t.transformByState({top:Math.min(I,h)-y/2}))==null||P.setProps({fill:this._freezeActiveColor}),(x=r.transformByState({top:Math.min(I,h)-y/2}))==null||x.setProps({fill:this._freezeNormalHeaderColor}),this._changeToRow=u===void 0?b:Math.min(b,u.lastRow),this._changeToOffsetY=Math.min(I,h),this._activeViewport=v):((A=t.transformByState({left:Math.min(C,g)-y/2}))==null||A.setProps({fill:this._freezeActiveColor}),(N=r.transformByState({left:Math.min(C,g)-y/2}))==null||N.setProps({fill:this._freezeNormalHeaderColor}),this._changeToColumn=u===void 0?T:Math.min(T,u.lastColumn),this._changeToOffsetX=C,this._activeViewport=v)}),this._scenePointerUpSub=c.onPointerUp$.subscribeEvent(()=>{var D,H;c.resetCursor(),c.enableObjectsEvent(),this._clearObserverEvent();const{rowHeaderWidthAndMarginLeft:p,columnHeaderHeightAndMarginTop:v}=s;o===0&&(this._changeToRow===0||this._changeToRow===-1)||o===1&&(this._changeToColumn===0||this._changeToColumn===-1)?(t.setProps({fill:this._freezeNormalHeaderColor}),r.setProps({fill:this._freezeNormalMainColor})):(t==null||t.setProps({fill:this._freezeNormalHeaderColor}),r==null||r.setProps({fill:this._freezeNormalHeaderColor}));const C=ro/Math.max(c.scaleX,c.scaleY);o===0?(this._changeToRow===0||this._changeToRow===-1)&&(t.transformByState({top:v-C}),r.transformByState({top:v-C})):(this._changeToColumn===0||this._changeToColumn===-1)&&(t.transformByState({left:p-C}),r.transformByState({left:p-C}));const I=this._scrollManagerService.getCurrentScrollState()||{sheetViewStartRow:0,sheetViewStartColumn:0},{sheetViewStartRow:b,sheetViewStartColumn:T}=I;if(T==null||b==null)return;const M=this._context.unit,y=M.getActiveSheet();if(!y)return;const P=(D=y.getConfig())==null?void 0:D.freeze;let x=(P==null?void 0:P.xSplit)||0,A=(P==null?void 0:P.ySplit)||0;const N=(H=this._activeViewport)==null?void 0:H.viewportKey;o===0&&(!N||N===w.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP||N===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP||N===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||N===w.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP?A=this._changeToRow-(P.startRow-P.ySplit):A=this._changeToRow-b,A=A<0?0:A),o===1&&(!N||N===w.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP||N===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP||N===w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||N===w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT?x=this._changeToColumn-(P.startColumn-P.xSplit):x=this._changeToColumn-T,x=x<0?0:x),this._commandService.executeCommand(m.SetFrozenCommand.id,{startRow:A===0?-1:this._changeToRow,startColumn:x===0?-1:this._changeToColumn,ySplit:A,xSplit:x,unitId:M.getUnitId(),subUnitId:y.getSheetId()})})}_getViewports(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e,r=t.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT),o=t.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT),s=t.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP),l=t.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM),d=t.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP),c=t.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN),u=t.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP),h=t.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT),g=t.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(!(r==null||o==null||s==null||l==null||d==null||c==null||u==null||h==null||g==null))return{viewMain:c,viewMainLeftTop:u,viewMainLeft:h,viewMainTop:g,viewColumnLeft:r,viewColumnRight:o,viewRowTop:s,viewRowBottom:l,viewLeftTop:d}}_bindViewportScroll(){const e=this._getViewports();if(!e)return;const{viewRowBottom:t,viewColumnRight:r,viewMainLeft:o,viewMainTop:s}=e;this.disposeWithMe(this._scrollManagerService.validViewportScrollInfo$.subscribe(l=>{if(!l)return;const{scrollX:d,scrollY:c,viewportScrollX:u,viewportScrollY:h}=l;t.isActive&&t.updateScrollVal({scrollY:c,viewportScrollY:h}),r.isActive&&r.updateScrollVal({scrollX:d,viewportScrollX:u}),o.isActive&&o.updateScrollVal({scrollY:c,viewportScrollY:h}),s.isActive&&s.updateScrollVal({scrollX:d,viewportScrollX:u})}))}_updateViewport(e=-1,t=-1,r=0,o=0,s=3){var x;const l=(x=this._sheetSkeletonManagerService.getCurrent())==null?void 0:x.skeleton;if(l==null)return;const{rowHeaderWidthAndMarginLeft:d,columnHeaderHeightAndMarginTop:c}=l,u=this._getViewports();if(!u)return;const{viewMain:h,viewMainLeftTop:g,viewMainLeft:S,viewMainTop:f,viewColumnLeft:p,viewColumnRight:v,viewRowTop:C,viewRowBottom:I,viewLeftTop:b}=u;v.resizeWhenFreezeChange({left:d,top:0,height:c,right:0}),I.resizeWhenFreezeChange({left:0,top:c,bottom:0,width:d}),b.resizeWhenFreezeChange({left:0,top:0,width:d,height:c});let T=!0,M=!0;g.enable(),(e===-1||e===0)&&(T=!1),(t===-1||t===0)&&(M=!1);const y=l.getNoMergeCellPositionByIndexWithNoHeader(e-r,t-o),P=l.getNoMergeCellPositionByIndexWithNoHeader(e,t);if(g.disable(),f.disable(),S.disable(),C.disable(),p.disable(),g.resetPadding(),f.resetPadding(),S.resetPadding(),C.resetPadding(),p.resetPadding(),T===!1&&M===!1)h.resizeWhenFreezeChange({left:d,top:c,bottom:0,right:0}),h.resetPadding();else if(T===!0&&M===!1){const A=P.startY-y.startY;h.resizeWhenFreezeChange({left:d,top:c+A,bottom:0,right:0}),h.setPadding({startY:y.startY,endY:P.startY,startX:0,endX:0}),s&2&&this._commandService.executeCommand(je.id,{sheetViewStartRow:0,offsetY:0}),f.resizeWhenFreezeChange({left:d,top:c,height:A,right:0}),f.updateScrollVal({viewportScrollY:y.startY,rawScrollX:h.scrollX,viewportScrollX:h.viewportScrollX}),C.resizeWhenFreezeChange({left:0,top:c,width:d,height:A}),C.updateScrollVal({viewportScrollY:y.startY}),I.resizeWhenFreezeChange({left:0,top:c+A,bottom:0,width:d}),f.enable(),C.enable()}else if(T===!1&&M===!0){const A=P.startX-y.startX;h.resizeWhenFreezeChange({left:d+A,top:c,bottom:0,right:0}),h.setPadding({startX:y.startX,endX:P.startX,startY:0,endY:0}),s&1&&this._commandService.executeCommand(je.id,{sheetViewStartColumn:0,offsetX:0}),S.resizeWhenFreezeChange({left:d,top:c,width:A,bottom:0,right:0}),S.updateScrollVal({viewportScrollX:y.startX,rawScrollY:h.scrollY,viewportScrollY:h.viewportScrollY}),p.resizeWhenFreezeChange({left:d,top:0,width:A,height:c}),p.updateScrollVal({viewportScrollX:y.startX}),v.resizeWhenFreezeChange({left:d+A,top:0,height:c,right:0}),S.enable(),p.enable()}else{const A=P.startX-y.startX,N=P.startY-y.startY;h.resizeWhenFreezeChange({left:d+A,top:c+N,bottom:0,right:0}),h.setPadding({startY:y.startY,endY:P.startY,startX:y.startX,endX:P.startX}),s&&this._commandService.executeCommand(je.id,{...s&1?{sheetViewStartColumn:0,offsetX:0}:null,...s&2?{sheetViewStartRow:0,offsetY:0}:null}),S.resizeWhenFreezeChange({left:d,top:c+N,width:A,bottom:0}),S.updateScrollVal({viewportScrollX:y.startX,rawScrollY:h.scrollY,viewportScrollY:h.viewportScrollY}),f.resizeWhenFreezeChange({left:d+A,top:c,height:N,right:0}),f.updateScrollVal({viewportScrollY:y.startY,rawScrollX:h.scrollX,viewportScrollX:h.viewportScrollX}),g.resizeWhenFreezeChange({left:d,top:c,width:A,height:N}),g.updateScrollVal({viewportScrollX:y.startX,viewportScrollY:y.startY}),C.resizeWhenFreezeChange({left:0,top:c,width:d,height:N}),C.updateScrollVal({viewportScrollY:y.startY}),I.resizeWhenFreezeChange({left:0,top:c+N,bottom:0,width:d}),p.resizeWhenFreezeChange({left:d,top:0,width:A,height:c}),p.updateScrollVal({viewportScrollX:y.startX}),v.resizeWhenFreezeChange({left:d+A,top:0,height:c,right:0}),g.enable(),f.enable(),S.enable(),C.enable(),p.enable()}}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(e=>{[m.SetWorksheetActiveOperation.id,m.InsertRangeMoveDownCommand.id,m.InsertRangeMoveRightCommand.id].includes((e==null?void 0:e.commandId)||"")&&this._refreshCurrent()})))}_refreshCurrent(){const t=this._context.unit.getActiveSheet();if(!t)return;const r=t.getConfig().freeze,{startRow:o=-1,startColumn:s=-1,ySplit:l=0,xSplit:d=0}=r;this._refreshFreeze(o,s,l,d,0)}_themeChangeListener(){this._themeChange(this._themeService.getCurrentTheme()),this.disposeWithMe(this._themeService.currentTheme$.subscribe(e=>{this._clearFreeze(),this._themeChange(e),this._refreshCurrent()}))}_themeChange(e){this._freezeNormalHeaderColor=e.grey400,this._freezeNormalMainColor=new a.ColorKit(e.grey400).setAlpha(Pm).toRgbString(),this._freezeActiveColor=e.primaryColor,this._freezeHoverColor=e.grey500}_interceptorCommands(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{const t={redos:[],undos:[]},r=this._getFreeze();if(!r)return t;const o=s=>{const l=this._context.unit,d=l.getUnitId(),c=l.getActiveSheet();if(!c)return t;const u=c.getSheetId();this._refreshFreeze(s.startRow,s.startColumn,s.ySplit,s.xSplit,0);const h={...s,unitId:d,subUnitId:u,resetScroll:!1},g=m.SetFrozenMutationFactory(this._injector,h);return{undos:[{id:m.SetFrozenMutation.id,params:g}],redos:[{id:m.SetFrozenMutation.id,params:h}]}};if(e.id===m.InsertRowCommand.id){const s=e.params,{range:l,direction:d}=s,c=l.endRow-l.startRow+1;if(l.startRow+1<r.startRow||l.startRow+1===r.startRow&&d===a.Direction.UP){const u={...r,startRow:Math.max(1,r.startRow+c),ySplit:Math.max(1,r.ySplit+c)};return o(u)}}if(e.id===m.InsertColCommand.id){const s=e.params,{range:l,direction:d}=s,c=l.endColumn-l.startColumn+1;if(l.startColumn+1<r.startColumn||l.startColumn+1===r.startColumn&&d===a.Direction.LEFT){const u={...r,startColumn:Math.max(1,r.startColumn+c),xSplit:Math.max(1,r.xSplit+c)};return o(u)}}if(e.id===m.MoveColsCommand.id){const s=this._selectionManagerService.getCurrentSelections(),{fromRange:{startColumn:l},toRange:{startColumn:d}}=e.params,c=s==null?void 0:s.filter(C=>C.range.rangeType===a.RANGE_TYPE.COLUMN&&C.range.startColumn<=l&&l<=C.range.endColumn);if(!(c!=null&&c.length))return t;const u=c[0].range,h={...u,startColumn:d,endColumn:d+u.endColumn-u.startColumn};if(!r||r.startColumn<=0||u.startColumn>=r.startColumn&&h.startColumn>=r.startColumn||u.startColumn===h.startColumn||u.endColumn<r.startColumn&&h.startColumn<r.startColumn)return t;const g=u.endColumn-u.startColumn+1,S=Math.max(Math.min(r.startColumn,u.endColumn+1)-u.startColumn,0);let f,p;h.startColumn>=r.startColumn?(f=Math.max(r.startColumn-S,1),p=Math.max(r.xSplit-S,1)):(f=r.startColumn+g-S,p=r.xSplit+g-S);const v={...r,startColumn:f,xSplit:p};return o(v)}if(e.id===m.MoveRowsCommand.id){const s=this._selectionManagerService.getCurrentSelections(),{fromRange:{startRow:l},toRange:{startRow:d}}=e.params,c=s==null?void 0:s.filter(C=>C.range.rangeType===a.RANGE_TYPE.ROW&&C.range.startRow<=l&&l<=C.range.endRow);if(!(c!=null&&c.length))return t;const u=c[0].range,h={...u,startRow:d,endRow:d+u.endRow-u.startRow};if(!r||r.startRow<=0||u.startRow>=r.startRow&&h.startRow>=r.startRow||u.startRow===h.startRow||u.endRow<r.startRow&&h.startRow<r.startRow)return t;const g=u.endRow-u.startRow+1,S=Math.max(Math.min(r.startRow,u.endRow+1)-u.startRow,0);let f,p;h.startRow>=r.startRow?(f=Math.max(r.startRow-S,1),p=Math.max(r.ySplit-S,1)):(f=r.startRow+g-S,p=r.ySplit+g-S);const v={...r,startRow:f,ySplit:p};return o(v)}if(e.id===m.RemoveColCommand.id||e.id===m.RemoveRowCommand.id){const s=e.params,l=s.range;if(l.rangeType===a.RANGE_TYPE.COLUMN&&l.startColumn<r.startColumn){const d=Math.min(r.startColumn,l.endColumn+1)-l.startColumn,c={...r,startColumn:Math.max(1,r.startColumn-d),xSplit:Math.max(1,r.xSplit-d)};return o(c)}if(s.range.rangeType===a.RANGE_TYPE.ROW&&l.startRow<r.startRow){const d=Math.min(r.startRow,l.endRow+1)-l.startRow,c={...r,startRow:Math.max(1,r.startRow-d),ySplit:Math.max(1,r.ySplit-d)};return o(c)}}return t}}))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{switch(e.id){case m.SetFrozenMutation.id:case Le.id:{const t=this._lastFreeze,r=this._context.unit,o=r.getActiveSheet(),s=e.params,{unitId:l,subUnitId:d}=s;if(!(l===r.getUnitId()&&d===(o==null?void 0:o.getSheetId())))return;const c=o.getConfig().freeze;if(this._lastFreeze=c,c==null)return;let u=0;const{startRow:h=-1,startColumn:g=-1,ySplit:S=0,xSplit:f=0}=c;(!t||t.startRow!==h||t.ySplit!==S)&&(u|=2),(!t||t.startColumn!==g||t.xSplit!==f)&&(u|=1),s.resetScroll===!1&&(u=0),this._refreshFreeze(h,g,S,f,u)}break;case m.SetWorksheetRowHeightMutation.id:{const t=this._getFreeze(),r=t&&e.params.ranges.some(o=>o.startRow<t.startRow);e.params&&r&&this._refreshCurrent()}break;case m.SetWorksheetColWidthMutation.id:{const t=this._getFreeze();e.params&&t&&e.params.ranges.some(r=>r.startColumn<t.startColumn)&&this._refreshCurrent()}break;case m.SetWorksheetRowAutoHeightMutation.id:{const t=e.params,r=this._getFreeze();if(r&&r.startRow>-1&&t.rowsAutoHeightInfo.some(o=>o.row<r.startRow)){const o=this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._refreshCurrent(),setTimeout(()=>{o.unsubscribe()})})}}break;case m.SetColHiddenMutation.id:case m.SetColVisibleMutation.id:{const t=e.params,r=this._getFreeze(),o=t.ranges;r&&r.startColumn>-1&&o.some(s=>s.startColumn<r.startColumn)&&this._refreshCurrent()}break;case m.SetRowHiddenMutation.id:case m.SetRowVisibleMutation.id:{const t=e.params,r=this._getFreeze(),o=t.ranges;r&&r.startRow>-1&&o.some(s=>s.startRow<r.startRow)&&this._refreshCurrent()}break;case wi.id:case yi.id:this._refreshCurrent()}}))}_zoomRefresh(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;t.onTransformChange$.subscribeEvent(r=>{r.type===w.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&this._refreshCurrent()})}_clearObserverEvent(){var t,r;this._getSheetObject()!=null&&((t=this._scenePointerMoveSub)==null||t.unsubscribe(),(r=this._scenePointerUpSub)==null||r.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null)}_clearFreeze(){var t,r,o,s,l,d;(t=this._rowFreezeHeaderRect)==null||t.dispose(),(r=this._rowFreezeMainRect)==null||r.dispose(),(o=this._columnFreezeHeaderRect)==null||o.dispose(),(s=this._columnFreezeMainRect)==null||s.dispose(),this._getSheetObject()!=null&&([this._freezeDownSubs,this._freezePointerEnterSubs,this._freezePointerLeaveSubs].forEach(c=>{c==null||c.unsubscribe()}),this._freezeDownSubs=null,this._freezePointerEnterSubs=null,this._freezePointerLeaveSubs=null,(l=this._scenePointerMoveSub)==null||l.unsubscribe(),(d=this._scenePointerUpSub)==null||d.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null)}_getPositionByIndex(e,t){var c;if(this._getSheetObject()==null)return;const o=(c=this._sheetSkeletonManagerService.getCurrent())==null?void 0:c.skeleton,s=o==null?void 0:o.getNoMergeCellPositionByIndex(e,t);if(o==null)return;if(s!=null&&(!isNaN(s.endX)||!isNaN(s.endY)))return s;const{rowHeaderWidthAndMarginLeft:l,columnHeaderHeightAndMarginTop:d}=o;return{startX:l,endX:l,startY:d,endY:d}}_getFreeze(){var t;const e=(t=this._sheetSkeletonManagerService.getCurrent())==null?void 0:t.skeleton.getWorksheetConfig();if(e!=null)return e.freeze}_getSheetObject(){return Ye(this._context.unit,this._context)}_refreshFreeze(e,t,r,o,s){var d;const l={startRow:e,startColumn:t,ySplit:r,xSplit:o};this._clearFreeze(),this._createFreeze(0,l),this._createFreeze(1,l),this._updateViewport(e,t,r,o,s),(d=this._getSheetObject())==null||d.spreadsheet.makeForceDirty()}};exports.HeaderFreezeRenderController=wm([xt(1,a.Inject(exports.SheetSkeletonManagerService)),xt(2,a.ICommandService),xt(3,a.Inject(m.SheetsSelectionsService)),xt(4,a.Inject(exports.SheetScrollManagerService)),xt(5,a.Inject(a.ThemeService)),xt(6,a.Inject(m.SheetInterceptorService)),xt(7,a.Inject(a.Injector))],exports.HeaderFreezeRenderController);function Om(n){const i=n.get(m.SheetsSelectionsService),e=n.get(m.RangeProtectionRuleModel),t=n.get(a.IUniverInstanceService),r=n.get(m.MergeCellController),o=t.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET);return O.combineLatest([i.selectionMoveEnd$,o.pipe(O.map(s=>{var l;return(l=s==null?void 0:s.getUnitId())!=null?l:""})),o.pipe(O.switchMap(s=>{var l;return(l=s==null?void 0:s.activeSheet$)!=null?l:O.of(null)}))]).pipe(O.map(([s,l,d])=>{if(!d||!s||s.length===0)return!1;const c=d.getSheetId(),u=s.map(S=>S.range);if(r.interceptor.fetchThroughInterceptors(m.MERGE_CELL_INTERCEPTOR_CHECK)(!1,u))return!0;const g=e.getSubunitRuleList(l,c).map(S=>S.ranges).flat();if(s.length<2){const S=s[0].range;return g.some(p=>a.Rectangle.intersects(p,S)&&!a.Rectangle.contains(p,S))}for(let S=0;S<s.length;S++)for(let f=S+1;f<s.length;f++)if(a.Rectangle.intersects(s[S].range,s[f].range))return!0;return!1}))}function El(n,i){return!!tr(n,i,a.RANGE_TYPE.ROW)}function Tl(n,i){return!!tr(n,i,a.RANGE_TYPE.COLUMN)}function tr(n,i,e){return n.find(r=>{const o=r.range,{startRow:s,endRow:l,startColumn:d,endColumn:c,rangeType:u}=o;return u===a.RANGE_TYPE.ALL||u===a.RANGE_TYPE.NORMAL?!1:u===e&&(e===a.RANGE_TYPE.COLUMN&&d<=i&&i<=c||e===a.RANGE_TYPE.ROW&&s<=i&&i<=l)})}var xm=Object.defineProperty,Am=Object.getOwnPropertyDescriptor,Nm=(n,i,e,t)=>{for(var r=t>1?void 0:t?Am(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&xm(i,e,r),r},io=(n,i)=>(e,t)=>i(e,t,n);const Dm="__SpreadsheetHeaderMoveControllerBackground__",Hm="__SpreadsheetHeaderMoveControllerShapeLine__",km="rgba(0, 0, 0, 0.1)",Vm="rgb(119, 119, 119)",Wm=4,oo=a.createInterceptorKey("headerMovePermissionCheck");exports.HeaderMoveRenderController=class extends a.Disposable{constructor(e,t,r,o){super();R(this,"_startOffsetX",Number.NEGATIVE_INFINITY);R(this,"_startOffsetY",Number.NEGATIVE_INFINITY);R(this,"_moveHelperBackgroundShape");R(this,"_moveHelperLineShape");R(this,"_headerPointerDownSubs");R(this,"_headerPointerMoveSubs");R(this,"_headerPointerLeaveSubs");R(this,"_dragHeaderMoveSub");R(this,"_scenePointerUpSub");R(this,"_scrollTimer");R(this,"_changeFromColumn",-1);R(this,"_changeFromRow",-1);R(this,"_changeToColumn",-1);R(this,"_changeToRow",-1);R(this,"interceptor",new a.InterceptorManager({HEADER_MOVE_PERMISSION_CHECK:oo}));R(this,"_workbookSelections");this._context=e,this._sheetSkeletonManagerService=r,this._commandService=o,this._workbookSelections=t.getWorkbookSelections(this._context.unitId),this._init()}dispose(){var e,t,r,o,s,l,d,c;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(t=this._moveHelperLineShape)==null||t.dispose(),(r=this._headerPointerMoveSubs)==null||r.unsubscribe(),(o=this._headerPointerLeaveSubs)==null||o.unsubscribe(),(s=this._headerPointerDownSubs)==null||s.unsubscribe(),this._headerPointerMoveSubs=null,this._headerPointerLeaveSubs=null,this._headerPointerDownSubs=null,(l=this._dragHeaderMoveSub)==null||l.unsubscribe(),(d=this._scenePointerUpSub)==null||d.unsubscribe(),this._dragHeaderMoveSub=null,this._scenePointerUpSub=null,(c=this._scrollTimer)==null||c.dispose()}_init(){this._initialRowOrColumn(a.RANGE_TYPE.ROW),this._initialRowOrColumn(a.RANGE_TYPE.COLUMN)}_initialRowOrColumn(e=a.RANGE_TYPE.ROW){const t=this._context.components.get(he.COLUMN),r=this._context.components.get(he.ROW),o=this._context.scene,s=e===a.RANGE_TYPE.ROW?r:t,l=u=>{var I,b;const h=(I=this._sheetSkeletonManagerService.getCurrent())==null?void 0:I.skeleton;if(h==null)return;const g=(b=this._workbookSelections.getCurrentLastSelection())==null?void 0:b.range;if(!g||!this.interceptor.fetchThroughInterceptors(oo)(!1,g))return;const f=this._workbookSelections.getCurrentSelections(),{row:p,column:v}=qe(u.offsetX,u.offsetY,o,h);if(!tr(f,e===a.RANGE_TYPE.ROW?p:v,e)){o.resetCursor();return}o.setCursor(w.CURSOR_TYPE.GRAB)},d=()=>{var u,h;(u=this._moveHelperBackgroundShape)==null||u.hide(),(h=this._moveHelperLineShape)==null||h.hide(),o.resetCursor()},c=(u,h)=>{var W,k;if(h.isStopPropagation)return;const g=(W=this._sheetSkeletonManagerService.getCurrent())==null?void 0:W.skeleton;if(g==null)return;const S=(k=this._workbookSelections.getCurrentLastSelection())==null?void 0:k.range;if(!S||!this.interceptor.fetchThroughInterceptors(oo)(!1,S))return;const{offsetX:p,offsetY:v}=u,C=o.getCoordRelativeToViewport(w.Vector2.FromArray([p,v])),{x:I,y:b}=C;this._startOffsetX=I,this._startOffsetY=b;const{row:T,column:M}=qe(u.offsetX,u.offsetY,o,g);let y;e===a.RANGE_TYPE.ROW?(this._changeFromRow=T,y=w.ScrollTimerType.Y):(this._changeFromColumn=M,y=w.ScrollTimerType.X);const P=this._workbookSelections.getCurrentSelections(),x=tr(P,e===a.RANGE_TYPE.ROW?T:M,e);if(!x)return;const A=o.getScrollXYInfoByViewport(w.Vector2.FromArray([this._startOffsetX,this._startOffsetY]));this._newBackgroundAndLine(),o.setCursor(w.CURSOR_TYPE.GRABBING),o.disableObjectsEvent();let N=!1,D;const H=()=>{if(N)return;D=w.ScrollTimer.create(o,y),this._scrollTimer=D;const U=o.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);D.startScroll(I,b,U),N=!0};this._dragHeaderMoveSub=o.onPointerMove$.subscribeEvent(U=>{H();const{offsetX:B,offsetY:F}=U,{x:L,y:z}=o.getCoordRelativeToViewport(w.Vector2.FromArray([B,F]));this._rowColumnMoving(L,z,x,A,e),D.scrolling(L,z,()=>{this._rowColumnMoving(L,z,x,A,e)})}),this._scenePointerUpSub=o.onPointerUp$.subscribeEvent(()=>{var B,F,L;this._disposeBackgroundAndLine(),o.resetCursor(),o.enableObjectsEvent(),this._clearObserverEvent(),(B=this._scrollTimer)==null||B.dispose();const U=this._workbookSelections.getCurrentSelections();if(e===a.RANGE_TYPE.ROW){if(this._changeFromRow!==this._changeToRow&&this._changeToRow!==-1){const X=(F=((U==null?void 0:U.filter(Z=>Z.range.rangeType===a.RANGE_TYPE.ROW&&Z.range.startRow<=this._changeFromRow&&this._changeFromRow<=Z.range.endRow))||[])[0])==null?void 0:F.range;X&&this._commandService.executeCommand(m.MoveRowsCommand.id,{fromRange:X,toRange:{...X,startRow:this._changeToRow,endRow:this._changeToRow+X.endRow-X.startRow}})}this._changeToRow=this._changeFromRow=-1}else{if(this._changeFromColumn!==this._changeToColumn&&this._changeToColumn!==-1){const X=(L=((U==null?void 0:U.filter(Z=>Z.range.rangeType===a.RANGE_TYPE.COLUMN&&Z.range.startColumn<=this._changeFromColumn&&this._changeFromColumn<=Z.range.endColumn))||[])[0])==null?void 0:L.range;X&&this._commandService.executeCommand(m.MoveColsCommand.id,{fromRange:X,toRange:{...X,startColumn:this._changeToColumn,endColumn:this._changeToColumn+X.endColumn-X.startColumn}})}this._changeToColumn=this._changeFromColumn=-1}})};this._headerPointerMoveSubs=new O.Subscription,this._headerPointerMoveSubs.add(s.onPointerMove$.subscribeEvent(l)),this._headerPointerLeaveSubs=new O.Subscription,this._headerPointerLeaveSubs.add(s==null?void 0:s.onPointerLeave$.subscribeEvent(d)),this._headerPointerDownSubs=new O.Subscription,this._headerPointerDownSubs.add(s==null?void 0:s.onPointerDown$.subscribeEvent(c))}_rowColumnMoving(e,t,r,o,s){var z,X,Z,re,Q,oe,$;const l=this._context.scene,d=(z=this._sheetSkeletonManagerService.getCurrent())==null?void 0:z.skeleton;if(d==null)return;const{rowHeaderWidth:c,columnHeaderHeight:u,rowTotalHeight:h,columnTotalWidth:g}=d,S=l.getViewportScrollXY(l.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:f,scaleY:p}=l.getAncestorScale(),v=d.getCellIndexByOffset(e,t,f,p,S),{row:C,column:I}=v,b=d.getNoMergeCellPositionByIndex(C,I),{startX:T,startY:M,endX:y,endY:P}=b,x=this._sheetSkeletonManagerService.attachRangeWithCoord(r.range);if(x==null)return;const A=Math.max(f,f),{startX:N,endX:D,startY:H,endY:W,startRow:k,startColumn:U,endRow:B,endColumn:F}=x;s===a.RANGE_TYPE.ROW?(X=this._moveHelperBackgroundShape)==null||X.transformByState({height:W-H,width:g+c,left:0,top:H+(t-this._startOffsetY)/A+S.y-o.y}):(Z=this._moveHelperBackgroundShape)==null||Z.transformByState({height:h+u,width:D-N,left:N+(e-this._startOffsetX)/A+S.x-o.x,top:0}),(re=this._moveHelperBackgroundShape)==null||re.show();const L=Wm/A;if(s===a.RANGE_TYPE.ROW){let j=0;if(C<=k)j=M-L/2,this._changeToRow=C;else if(C>B)j=P-L/2,this._changeToRow=C+1;else return;(Q=this._moveHelperLineShape)==null||Q.transformByState({height:L,width:g,left:c,top:j})}else{let j=0;if(I<=U)j=T-L/2,this._changeToColumn=I;else if(I>F)j=y-L/2,this._changeToColumn=I+1;else return;(oe=this._moveHelperLineShape)==null||oe.transformByState({height:h,width:L,left:j,top:u})}($=this._moveHelperLineShape)==null||$.show()}_clearObserverEvent(){var e,t;(e=this._dragHeaderMoveSub)==null||e.unsubscribe(),(t=this._scenePointerUpSub)==null||t.unsubscribe(),this._dragHeaderMoveSub=null,this._scenePointerUpSub=null}_newBackgroundAndLine(){const e=this._context.scene;this._moveHelperBackgroundShape=new w.Rect(Dm,{fill:km,evented:!1,zIndex:100}),this._moveHelperLineShape=new w.Rect(Hm,{fill:Vm,evented:!1,zIndex:100}),e.addObjects([this._moveHelperBackgroundShape,this._moveHelperLineShape],bt)}_disposeBackgroundAndLine(){var e,t;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(t=this._moveHelperLineShape)==null||t.dispose()}};exports.HeaderMoveRenderController=Nm([io(1,a.Inject(m.SheetsSelectionsService)),io(2,a.Inject(exports.SheetSkeletonManagerService)),io(3,a.ICommandService)],exports.HeaderMoveRenderController);var jo=(n=>(n[n.VERTICAL=0]="VERTICAL",n[n.HORIZONTAL=1]="HORIZONTAL",n))(jo||{});const Um="rgba(120, 120, 120, 0.01)",so="rgb(68, 71, 70)",Yn=12,Lm=44,zo=4;class Sa extends w.Shape{constructor(e,t){super(e,t);R(this,"_size",Yn);R(this,"_color",so);R(this,"_mode",0);this.setShapeProps(t)}get size(){return this._size}get mode(){return this._mode}get color(){return this._color}_draw(e){const t=this.getScene();if(!t)return;const{scaleX:r,scaleY:o}=t.getAncestorScale(),s=Math.max(r,o),l=Yn/s,d=zo/s;let{width:c,height:u}=this,h=0,g=0;this.mode===0?(c=d,h=l-d):(u=d,g=l-d),w.Rect.drawWith(e,{width:this.width,height:this.height,left:0,top:0,fill:Um}),w.Rect.drawWith(e,{width:c,height:u,fill:so,radius:d}),e.save(),e.transform(1,0,0,1,h,g),w.Rect.drawWith(e,{width:c,height:u,fill:so,radius:d}),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:Yn,height:this.size}):this.transformByState({width:this.size,height:Yn}),this}}var Bm=Object.defineProperty,Fm=Object.getOwnPropertyDescriptor,jm=(n,i,e,t)=>{for(var r=t>1?void 0:t?Fm(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Bm(i,e,r),r},ao=(n,i)=>(e,t)=>i(e,t,n);const zm="__SpreadsheetHeaderResizeControllerShapeRow__",Xm="__SpreadsheetHeaderResizeControllerShapeColumn__",fa="__SpreadsheetHeaderResizeControllerShapeHelper__",pa="rgb(199, 199, 199)",Ym=2,lo=a.createInterceptorKey("headerResizePermissionCheck");exports.HeaderResizeRenderController=class extends a.Disposable{constructor(e,t,r,o){super();R(this,"_currentRow",0);R(this,"_currentColumn",0);R(this,"_rowResizeRect");R(this,"_columnResizeRect");R(this,"_headerPointerSubs");R(this,"_scenePointerMoveSub");R(this,"_scenePointerUpSub");R(this,"_resizeHelperShape");R(this,"_startOffsetX",Number.POSITIVE_INFINITY);R(this,"_startOffsetY",Number.POSITIVE_INFINITY);R(this,"interceptor",new a.InterceptorManager({HEADER_RESIZE_PERMISSION_CHECK:lo}));this._context=e,this._sheetSkeletonManagerService=t,this._selectionManagerService=r,this._commandService=o,this._init()}dispose(){var e,t,r;(e=this._rowResizeRect)==null||e.dispose(),this._rowResizeRect=null,(t=this._columnResizeRect)==null||t.dispose(),this._columnResizeRect=null,(r=this._headerPointerSubs)==null||r.unsubscribe(),this._headerPointerSubs=null}_init(){const e=this._context.scene;this._rowResizeRect=new Sa(zm,{visible:!1,mode:jo.HORIZONTAL,zIndex:100}),this._columnResizeRect=new Sa(Xm,{visible:!1,mode:jo.VERTICAL,zIndex:100}),e.addObjects([this._rowResizeRect,this._columnResizeRect],bt),this._initialHover(0),this._initialHover(1),this._initialHoverResize(0),this._initialHoverResize(1)}_initialHover(e=0){const t=this._context.components.get(he.COLUMN),r=this._context.components.get(he.ROW),o=this._context.scene,s=e===0?r:t,l=(c,u)=>{var h,g;(h=this._rowResizeRect)==null||h.hide(),(g=this._columnResizeRect)==null||g.hide()},d=(c,u)=>{var A;const h=(A=this._sheetSkeletonManagerService.getCurrent())==null?void 0:A.skeleton;if(h==null||this._rowResizeRect==null||this._columnResizeRect==null)return;const{rowHeaderWidth:g,columnHeaderHeight:S}=h,{startX:f,startY:p,endX:v,endY:C,row:I,column:b}=qe(c.offsetX,c.offsetY,o,h),T=Kn(c.offsetX,c.offsetY,o),{scaleX:M,scaleY:y}=o.getAncestorScale(),P=Math.max(M,y),x=Yn/P;if(e===0){let N=p-x/2;if(T.y<=p+x/2&&T.y>=p)this._currentRow=I-1;else if(T.y>=C-x/2&&T.y<=C)this._currentRow=I,N=C-x/2;else{this._rowResizeRect.hide();return}if(this._currentRow===-1)return;if(!this.interceptor.fetchThroughInterceptors(lo)(null,{row:this._currentRow}))return!1;const H=Math.min(Lm,g/3);this._rowResizeRect.transformByState({left:g/2-H/2,top:N}),this._rowResizeRect.setShapeProps({size:H}),this._rowResizeRect.show()}else{let N=f-x/2;if(T.x<=f+x/2&&T.x>=f)this._currentColumn=b-1;else if(T.x>=v-x/2&&T.x<=v)this._currentColumn=b,N=v-x/2;else{this._columnResizeRect.hide();return}if(this._currentColumn===-1)return;if(!this.interceptor.fetchThroughInterceptors(lo)(null,{col:this._currentColumn}))return!1;const H=S*.7;this._columnResizeRect.transformByState({left:N,top:S/2-H/2}),this._columnResizeRect.setShapeProps({size:H}),this._columnResizeRect.show()}};this._headerPointerSubs=new O.Subscription,this._headerPointerSubs.add(s==null?void 0:s.onPointerMove$.subscribeEvent(d)),this._headerPointerSubs.add(s==null?void 0:s.onPointerLeave$.subscribeEvent(l))}_initialHoverResize(e=0){const t=this._context.scene,r=e===0?this._rowResizeRect:this._columnResizeRect;r!=null&&(this.disposeWithMe(r.onPointerEnter$.subscribeEvent(()=>{r!=null&&(r.show(),t.setCursor(e===0?w.CURSOR_TYPE.ROW_RESIZE:w.CURSOR_TYPE.COLUMN_RESIZE))})),this.disposeWithMe(r.onPointerLeave$.subscribeEvent(()=>{r!=null&&(r.hide(),t.resetCursor())})),this.disposeWithMe(r.onPointerDown$.subscribeEvent(o=>{var F,L,z,X,Z,re,Q;const s=(F=this._sheetSkeletonManagerService.getCurrent())==null?void 0:F.skeleton;if(s==null)return;const l=this._context.scene,d=l.getEngine(),c=(d==null?void 0:d.height)||0,u=(d==null?void 0:d.width)||0,h=l.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=(((z=(L=h==null?void 0:h.getScrollBar())==null?void 0:L.horizonScrollTrack)==null?void 0:z.height)||0)+10,S=(((Z=(X=h==null?void 0:h.getScrollBar())==null?void 0:X.verticalScrollTrack)==null?void 0:Z.width)||0)+10,f=Kn(o.offsetX,o.offsetY,l),{scaleX:p,scaleY:v}=l.getAncestorScale();this._startOffsetX=f.x,this._startOffsetY=f.y;const C=s.getOffsetByPositionX(this._currentColumn),I=s.getOffsetByPositionY(this._currentRow),b=s.getNoMergeCellPositionByIndex(this._currentRow,this._currentColumn);let T=!1,M=0,y=0;const{columnTotalWidth:P,rowHeaderWidth:x,rowTotalHeight:A,columnHeaderHeight:N}=s,D=u>P+x?u:P+x,H=c>A+N?c:A+N,W=Math.max(p,v),k=zo/W;e===0?this._resizeHelperShape=new w.Rect(fa,{width:D,height:k,fill:pa,left:0,top:I-k/2}):this._resizeHelperShape=new w.Rect(fa,{width:k,height:H,fill:pa,left:C-k/2,top:0});const U=((re=this._columnResizeRect)==null?void 0:re.left)||0,B=((Q=this._rowResizeRect)==null?void 0:Q.top)||0;l.addObject(this._resizeHelperShape,bt),l.disableObjectsEvent(),this._scenePointerMoveSub=l.onPointerMove$.subscribeEvent(oe=>{var se,Ce,Ee,Mt,nt,Dr;const $=l.getCoordRelativeToViewport(w.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),j=l.getScrollXYInfoByViewport($,h),Y=Kn(oe.offsetX,oe.offsetY,l),{x:q,y:ee}=Y,{scaleX:de,scaleY:me}=l.getAncestorScale(),ce=Math.max(de,me),ie=zo/ce;M=q-this._startOffsetX-ie/2,y=ee-this._startOffsetY-ie/2,Math.abs(e===0?y:M)>=Ym&&(T=!0),e===0?(y>c-g+j.y-b.startY&&(y=c-g+j.y-b.startY),y<-(b.endY-b.startY)+2&&(y=-(b.endY-b.startY)+2),T&&((se=this._resizeHelperShape)==null||se.transformByState({top:I+y}),(Ce=this._rowResizeRect)==null||Ce.transformByState({top:B+y+ie/2}),(Ee=this._rowResizeRect)==null||Ee.show(),l.setCursor(w.CURSOR_TYPE.ROW_RESIZE))):(M>u-S+j.x-b.startX&&(M=u-S+j.x-b.startX),M<-(b.endX-b.startX)+2&&(M=-(b.endX-b.startX)+2),T&&((Mt=this._resizeHelperShape)==null||Mt.transformByState({left:C+M}),(nt=this._columnResizeRect)==null||nt.transformByState({left:U+M+ie/2}),(Dr=this._columnResizeRect)==null||Dr.show(),l.setCursor(w.CURSOR_TYPE.COLUMN_RESIZE)))}),this._scenePointerUpSub=l.onPointerUp$.subscribeEvent(oe=>{var j,Y,q;const $=this._context.scene;this._clearObserverEvent(),(j=this._resizeHelperShape)==null||j.dispose(),this._resizeHelperShape=null,$.enableObjectsEvent(),T&&($.resetCursor(),(Y=this._rowResizeRect)==null||Y.hide(),(q=this._columnResizeRect)==null||q.hide(),e===0?this._commandService.executeCommand(m.DeltaRowHeightCommand.id,{deltaY:y,anchorRow:this._currentRow}):this._commandService.executeCommand(m.DeltaColumnWidthCommand.id,{deltaX:M,anchorCol:this._currentColumn}))})})),this.disposeWithMe(r.onDblclick$.subscribeEvent(()=>{var h,g,S;this._context.scene.resetCursor();const s=(h=this._sheetSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(!s)return;const l=0,d=0,c=s.worksheet.getRowCount()-1||0,u=s.worksheet.getColumnCount()-1||0;switch(e){case 1:{const f=this._selectionManagerService.getCurrentSelections(),p=[];for(let v=0;v<f.length;v++){const C=f[v];C.range.rangeType===a.RANGE_TYPE.COLUMN&&this._currentColumn<=C.range.endColumn&&this._currentColumn>=C.range.startColumn&&p.push({startColumn:C.range.startColumn,endColumn:C.range.endColumn,startRow:l,endRow:c})}p.length===0&&p.push({startColumn:this._currentColumn,endColumn:this._currentColumn,startRow:l,endRow:c}),this._commandService.executeCommand(Ir.id,{ranges:p}),(g=this._columnResizeRect)==null||g.hide();break}case 0:this._commandService.executeCommand(m.SetWorksheetRowIsAutoHeightCommand.id,{ranges:[{startRow:this._currentRow,endRow:this._currentRow,startColumn:d,endColumn:u}]}),(S=this._rowResizeRect)==null||S.hide();break}})))}_clearObserverEvent(){var e,t;(e=this._scenePointerMoveSub)==null||e.unsubscribe(),(t=this._scenePointerUpSub)==null||t.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null}};exports.HeaderResizeRenderController=jm([ao(1,a.Inject(exports.SheetSkeletonManagerService)),ao(2,a.Inject(m.SheetsSelectionsService)),ao(3,a.ICommandService)],exports.HeaderResizeRenderController);var Gm=Object.defineProperty,Zm=Object.getOwnPropertyDescriptor,Km=(n,i,e,t)=>{for(var r=t>1?void 0:t?Zm(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=(t?s(i,e,r):s(r))||r);return t&&r&&Gm(i,e,r),r},Wr=(n,i)=>(e,t)=>i(e,t,n);const qm=60;exports.SheetRenderController=class extends a.RxDisposable{constructor(e,t,r,o,s){super();R(this,"_renderFrameTimeMetric",null);R(this,"_renderFrameTags",{});R(this,"_afterRenderMetric$",new O.Subject);this._context=e,this._sheetSkeletonManagerService=t,this._sheetRenderService=r,this._commandService=o,this._telemetryService=s,this._addNewRender(),this._initRenderMetricSubscriber()}_addNewRender(){const{scene:e,engine:t,unit:r}=this._context;this._addComponent(r),this._initRerenderScheduler(),this._initCommandListener();const o=this._context.unit.getActiveSheet();if(!o)throw new Error("No active sheet found");const s=o.getSheetId();this._sheetSkeletonManagerService.setCurrent({sheetId:s});const l=()=>e.render();this.disposeWithMe(this._context.activated$.subscribe(d=>{d?t.runRenderLoop(l):t.stopRenderLoop(l)}))}_initRenderMetricSubscriber(){if(!this._telemetryService)return;const{engine:e}=this._context;e.beginFrame$.subscribe(()=>{this._renderFrameTimeMetric=null,this._renderFrameTags={}}),e.endFrame$.subscribe(()=>{this._renderFrameTimeMetric&&Object.keys(this._renderFrameTimeMetric).filter(o=>o.startsWith(w.SHEET_EXTENSION_PREFIX)).length>0&&this._afterRenderMetric$.next({frameTimeMetric:this._renderFrameTimeMetric,tags:this._renderFrameTags})}),e.renderFrameTimeMetric$.subscribe(([r,o])=>{this._renderFrameTimeMetric||(this._renderFrameTimeMetric={}),this._renderFrameTimeMetric[r]||(this._renderFrameTimeMetric[r]=[]),this._renderFrameTimeMetric[r].push(Math.round(o*100)/100)}),e.renderFrameTags$.subscribe(([r,o])=>{this._renderFrameTags[r]=o});const t=[];this._afterRenderMetric$.pipe(O.withLatestFrom(e.endFrame$)).subscribe(([r,o])=>{t.push({FPS:o.FPS,elapsedTime:o.elapsedTime,frameTime:Math.round(o.frameTime*100)/100,...r.frameTimeMetric,...r.tags}),t.length>qm&&(this._renderMetricCapture(t),t.length=0)})}_renderMetricCapture(e){const t=e;if(t.length===0)return;const r=g=>{let S=0;const p=Object.entries(g).filter(([C,I])=>Array.isArray(I)).map(([C])=>C).reduce((C,I)=>{const b=g[I].reduce((T,M)=>T+M,0);return C[I]=b,C},{});return Object.keys(g).filter(C=>C.startsWith(w.SHEET_EXTENSION_PREFIX)).forEach(C=>{S+=p[C]}),{...p,extensionTotal:S}},o=e.map(g=>({...g,...r(g)})),l=(g=>Object.entries(g[0]).filter(([p,v])=>!["elapsedTime"].includes(p)).filter(([p,v])=>typeof v=="number").map(([p])=>p).reduce((p,v)=>{const C=g.map(M=>M[v]),I=Math.max(...C),b=Math.min(...C),T=C.reduce((M,y)=>M+y,0)/C.length;return p[v]={max:Math.round(I*100)/100,min:Math.round(b*100)/100,avg:Math.round(T*100)/100},p},{}))(o),d=t[t.length-1].elapsedTime,c=this._context.unit.getActiveSheet().getSheetId(),u=this._context.unit.getUnitId(),h={sheetId:c,unitId:u,elapsedTimeToStart:d,...l};this._telemetryService.capture("sheet_render_cost",h)}_addComponent(e){const{scene:t,components:r}=this._context,o=e.getActiveSheet(),s=new w.Spreadsheet(he.MAIN);this._addViewport(o);const l=new w.SpreadsheetRowHeader(he.ROW),d=new w.SpreadsheetColumnHeader(he.COLUMN),c=new w.Rect(he.LEFT_TOP,{zIndex:2,left:-1,top:-1,fill:"rgb(248, 249, 250)",stroke:"rgb(217, 217, 217)",strokeWidth:1});this._context.mainComponent=s,r.set(he.MAIN,s),r.set(he.ROW,l),r.set(he.COLUMN,d),r.set(he.LEFT_TOP,c),t.addObjects([s],Ws),t.addObjects([l,d,c],bt),t.enableLayerCache(Ws,bt)}_initViewports(e,t,r){const l=new w.Viewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN,e,{left:t.width,top:r.height,bottom:0,right:0,isWheelPreventDefaultX:!0,allowCache:!0,bufferEdgeX:100,bufferEdgeY:100}),d=new w.Viewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:0,bufferEdgeY:0}),c=new w.Viewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:0,bufferEdgeY:100}),u=new w.Viewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:100,bufferEdgeY:0}),h=new w.Viewport(w.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP,e,{active:!1,isWheelPreventDefaultX:!0}),g=new w.Viewport(w.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM,e,{left:0,top:r.height,bottom:0,width:t.width,isWheelPreventDefaultX:!0}),S=new w.Viewport(w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT,e,{active:!1,isWheelPreventDefaultX:!0}),f=new w.Viewport(w.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT,e,{left:t.width,top:0,height:r.height,right:0,isWheelPreventDefaultX:!0}),p=new w.Viewport(w.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP,e,{left:0,top:0,width:t.width,height:r.height,isWheelPreventDefaultX:!0});return{viewMain:l,viewLeftTop:p,viewMainLeftTop:d,viewMainLeft:c,viewMainTop:u,viewColumnLeft:S,viewRowTop:h,viewRowBottom:g,viewColumnRight:f}}_addViewport(e){const t=this._context.scene,{rowHeader:r,columnHeader:o}=e.getConfig(),{viewMain:s}=this._initViewports(t,r,o);return new w.ScrollBar(s),t.attachControl(),s}_initRerenderScheduler(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(!e)return null;const{skeleton:t,sheetId:r}=e,o=this._context.unit,s=o==null?void 0:o.getSheetBySheetId(r);if(o==null||s==null)return;const{mainComponent:l,components:d}=this._context,c=l,u=d.get(he.ROW),h=d.get(he.COLUMN),g=d.get(he.LEFT_TOP),{rowHeaderWidth:S,columnHeaderHeight:f}=t;c==null||c.updateSkeleton(t),u==null||u.updateSkeleton(t),h==null||h.updateSkeleton(t),g==null||g.transformByState({width:S,height:f});const p=this._context.scene.getObject(bl);p&&p.transformByState({top:f-p.height});const v=this._context.scene.getObject(Rl);v&&v.transformByState({height:f})}))}_initCommandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{const{unit:t}=this._context,{id:r}=e;if(m.COMMAND_LISTENER_SKELETON_CHANGE.includes(r)||this._sheetRenderService.checkMutationShouldTriggerRerender(r)){const o=e.params,{unitId:s,subUnitId:l}=o,d=t.getActiveSheet();if(!d)return;const c=this._context.unitId,u=d.getSheetId();if(s!==c||l!==u)return;this._sheetSkeletonManagerService.makeDirty({sheetId:u,commandId:r},!0),this._sheetSkeletonManagerService.setCurrent({sheetId:u,commandId:r})}else m.COMMAND_LISTENER_VALUE_CHANGE.includes(r)&&this._sheetSkeletonManagerService.reCalculate();e.type===a.CommandType.MUTATION&&this._markUnitDirty(e)}))}_markUnitDirty(e){const{mainComponent:t,scene:r}=this._context;if(e.id===G.SetFormulaCalculationNotificationMutation.id&&e.params.stageInfo!=null||(t&&t.makeDirty(),r.makeDirty(),!e.params))return;const o=e.params,s=this._spreadsheetViewports(r);if(e.id===m.SetRangeValuesMutation.id&&o.cellValue){const l=this._cellValueToRange(o.cellValue),d=this._rangeToBounds([l]);this._markViewportDirty(s,d),t.setDirtyArea(d)}if(e.id===m.MoveRangeMutation.id&&o.from&&o.to){const l=o.fromRange||this._cellValueToRange(o.from.value),d=o.toRange||this._cellValueToRange(o.to.value),c=this._rangeToBounds([l,d]);this._markViewportDirty(s,c),t.setDirtyArea(c)}}_cellValueToRange(e){let t=0,r=0,o=0,s=0;for(const[h,g]of Object.entries(e)){for(const S in g)t>Number(S)&&(t=Number(S)),r<Number(S)&&(r=Number(S));o>Number(h)&&(o=Number(h)),s<Number(h)&&(s=Number(h))}return{startRow:o,endRow:s,startColumn:t,endColumn:r}}_rangeToBounds(e){const t=this._sheetSkeletonManagerService.getCurrent().skeleton,{rowHeightAccumulation:r,columnWidthAccumulation:o,rowHeaderWidth:s,columnHeaderHeight:l}=t,d=[];for(const c of e){const{startRow:u,endRow:h,startColumn:g,endColumn:S}=c,f=u===0?0:r[u-1]+l,p=r[h]+l,v=g===0?0:o[g-1]+s,C=o[S]+s;d.push({top:f,left:v,bottom:p,right:C,width:C-v,height:p-f})}return d}_markViewportDirty(e,t){const r=e.filter(o=>o.isActive&&o.cacheBound);for(const o of r)for(const s of t)a.Rectangle.hasIntersectionBetweenTwoRect(o.cacheBound,s)&&o.markDirty(!0)}_spreadsheetViewports(e){return e.getViewports().filter(t=>["viewMain","viewMainLeftTop","viewMainTop","viewMainLeft"].includes(t.viewportKey))}};exports.SheetRenderController=Km([Wr(1,a.Inject(exports.SheetSkeletonManagerService)),Wr(2,a.Inject(exports.SheetsRenderService)),Wr(3,a.ICommandService),Wr(4,a.Optional(Sd.ITelemetryService))],exports.SheetRenderController);var Ve=function(){return Ve=Object.assign||function(n){for(var i,e=1,t=arguments.length;e<t;e++){i=arguments[e];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(n[r]=i[r])}return n},Ve.apply(this,arguments)},Qm=function(n,i){var e={};for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&i.indexOf(t)<0&&(e[t]=n[t]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,t=Object.getOwnPropertySymbols(n);r<t.length;r++)i.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(n,t[r])&&(e[t[r]]=n[t[r]]);return e},Re=V.forwardRef(function(n,i){var e=n.icon,t=n.id,r=n.className,o=n.extend,s=Qm(n,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(t," ").concat(r||"").trim(),d=V.useRef("_".concat(eg()));return wl(e,"".concat(t),{defIds:e.defIds,idSuffix:d.current},Ve({ref:i,className:l},s),o)});function wl(n,i,e,t,r){return V.createElement(n.tag,Ve(Ve({key:i},Jm(n,e,r)),t),($m(n,e).children||[]).map(function(o,s){return wl(o,"".concat(i,"-").concat(n.tag,"-").concat(s),e,void 0,r)}))}function Jm(n,i,e){var t=Ve({},n.attrs);e!=null&&e.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=e.colorChannel1);var r=i.defIds;return!r||r.length===0||(n.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+i.idSuffix),Object.entries(t).forEach(function(o){var s=o[0],l=o[1];typeof l=="string"&&(t[s]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(i.idSuffix,")")))})),t}function $m(n,i){var e,t=i.defIds;return!t||t.length===0?n:n.tag==="defs"&&(!((e=n.children)===null||e===void 0)&&e.length)?Ve(Ve({},n),{children:n.children.map(function(r){return typeof r.attrs.id=="string"&&t&&t.indexOf(r.attrs.id)>-1?Ve(Ve({},r),{attrs:Ve(Ve({},r.attrs),{id:r.attrs.id+i.idSuffix})}):r})}):n}function eg(){return Math.random().toString(36).substring(2,8)}Re.displayName="UniverIcon";var tg={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"}}]},yl=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"autofill",ref:i,icon:tg}))});yl.displayName="Autofill";var ng={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},mt=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"check-mark-single",ref:i,icon:ng}))});mt.displayName="CheckMarkSingle";var rg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.71274 2.86421C3.47843 2.6299 3.09853 2.6299 2.86421 2.86421C2.6299 3.09853 2.6299 3.47843 2.86421 3.71274L7.15154 8.00007L2.86421 12.2874C2.6299 12.5217 2.6299 12.9016 2.86421 13.1359C3.09853 13.3702 3.47843 13.3702 3.71274 13.1359L8.00007 8.84859L12.2874 13.1359C12.5217 13.3702 12.9016 13.3702 13.1359 13.1359C13.3702 12.9016 13.3702 12.5217 13.1359 12.2874L8.84859 8.00007L13.1359 3.71274C13.3702 3.47843 13.3702 3.09853 13.1359 2.86421C12.9016 2.6299 12.5217 2.6299 12.2874 2.86421L8.00007 7.15154L3.71274 2.86421Z"}}]},Ml=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"close-single",ref:i,icon:rg}))});Ml.displayName="CloseSingle";var ig={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"g",attrs:{fill:"currentColor",clipPath:"url(#convert-single_clip0_911_593)"},children:[{tag:"path",attrs:{d:"M2.44766.848145C1.564.848145.847656 1.56449.847656 2.44814V6.44814C.847656 7.3318 1.564 8.04814 2.44766 8.04814H6.44766C7.33131 8.04814 8.04766 7.3318 8.04766 6.44814V2.44814C8.04766 1.56449 7.33131.848145 6.44766.848145H2.44766zM2.04766 6.44814V5.04824H3.84775V6.84814H2.44766C2.22674 6.84814 2.04766 6.66906 2.04766 6.44814zM2.04766 3.84824H3.84775V2.04814H2.44766C2.22674 2.04814 2.04766 2.22723 2.04766 2.44814V3.84824zM5.04775 6.84814V5.04824H6.84766V6.44814C6.84766 6.66906 6.66857 6.84814 6.44766 6.84814H5.04775zM5.04775 3.84824H6.84766V2.44814C6.84766 2.22723 6.66857 2.04814 6.44766 2.04814H5.04775V3.84824zM9.55215 7.95166C8.66849 7.95166 7.95215 8.668 7.95215 9.55166V13.5517C7.95215 14.4353 8.66849 15.1517 9.55215 15.1517L11.5522 15.1517 13.5521 15.1517C14.4358 15.1517 15.1521 14.4353 15.1521 13.5517L15.1521 11.5518 15.1521 9.55166C15.1521 8.668 14.4358 7.95166 13.5521 7.95166H9.55215zM13.9521 10.9518V9.55166C13.9521 9.33075 13.7731 9.15166 13.5521 9.15166H12.1522V10.9518H13.9521zM10.9522 10.9518V9.15166H9.55215C9.33123 9.15166 9.15215 9.33075 9.15215 9.55166V10.9518H10.9522zM9.15215 12.1518H10.9522V13.9517H9.55215C9.33123 13.9517 9.15215 13.7726 9.15215 13.5517V12.1518zM12.1522 12.1518H13.9521V13.5517C13.9521 13.7726 13.7731 13.9517 13.5521 13.9517H12.1522V12.1518z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{d:"M9.62158 2.44912C9.62158 2.11775 9.89021 1.84912 10.2216 1.84912H12.7516C13.6352 1.84912 14.3516 2.56547 14.3516 3.44912V5.9791C14.3516 6.31047 14.0829 6.5791 13.7516 6.5791 13.4202 6.5791 13.1516 6.31047 13.1516 5.9791V3.44912C13.1516 3.22821 12.9725 3.04912 12.7516 3.04912H10.2216C9.89021 3.04912 9.62158 2.78049 9.62158 2.44912zM5.77871 14.1507C6.11008 14.1507 6.37871 13.8821 6.37871 13.5507 6.37871 13.2193 6.11008 12.9507 5.77871 12.9507L3.24873 12.9507C3.02782 12.9507 2.84873 12.7716 2.84873 12.5507L2.84873 10.0207C2.84873 9.68933 2.5801 9.4207 2.24873 9.4207 1.91736 9.4207 1.64873 9.68933 1.64873 10.0207L1.64873 12.5507C1.64873 13.4343 2.36507 14.1507 3.24873 14.1507H5.77871z"}}]},{tag:"defs",attrs:{},children:[{tag:"clipPath",attrs:{id:"convert-single_clip0_911_593"},children:[{tag:"path",attrs:{fill:"#fff",d:"M0 0H16V16H0z"}}]}]}],defIds:["convert-single_clip0_911_593"]},Pl=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"convert-single",ref:i,icon:ig}))});Pl.displayName="ConvertSingle";var og={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.3313 1.4667C5.3313 1.13533 5.59993.866699 5.9313.866699H10.069C10.4004.866699 10.669 1.13533 10.669 1.4667 10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667zM1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443 14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443zM6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928 9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171 10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778 9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539 9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263 6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539 5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778 6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Wi=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"delete-single",ref:i,icon:og}))});Wi.displayName="DeleteSingle";var sg={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"}}]}]},Xo=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"dropdown-single",ref:i,icon:sg}))});Xo.displayName="DropdownSingle";var ag={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M15 8C15 11.866 11.866 15 8 15C4.13401 15 1 11.866 1 8C1 4.13401 4.13401 1 8 1C11.866 1 15 4.13401 15 8ZM10.3097 5.69014C10.544 5.92445 10.544 6.30435 10.3097 6.53867L8.84843 7.9999L10.3099 9.46137C10.5442 9.69569 10.5442 10.0756 10.3099 10.3099C10.0756 10.5442 9.69569 10.5442 9.46137 10.3099L7.9999 8.84843L6.53842 10.3099C6.30411 10.5442 5.92421 10.5442 5.6899 10.3099C5.45558 10.0756 5.45558 9.69569 5.6899 9.46137L7.15137 7.9999L5.69014 6.53867C5.45583 6.30435 5.45583 5.92445 5.69014 5.69014C5.92445 5.45583 6.30435 5.45583 6.53867 5.69014L7.9999 7.15137L9.46113 5.69014C9.69544 5.45583 10.0753 5.45583 10.3097 5.69014Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ts=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"error-single",ref:i,icon:ag}))});Ts.displayName="ErrorSingle";var lg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.28096 4.6541C1.57489 4.50109 1.93721 4.61533 2.09022 4.90926C2.27315 5.26067 2.55999 5.60455 2.94829 5.92278C4.04628 6.82266 5.87505 7.44865 7.99828 7.44865C10.1215 7.44865 11.9503 6.82267 13.0482 5.92279C13.4366 5.60455 13.7234 5.26067 13.9063 4.90927C14.0594 4.61533 14.4217 4.50109 14.7156 4.65409C15.0095 4.8071 15.1238 5.16941 14.9708 5.46334C14.6995 5.98445 14.2981 6.44997 13.8089 6.8509C13.7298 6.91575 13.6481 6.97914 13.564 7.041L15.2245 8.70153C15.4588 8.93585 15.4588 9.31575 15.2245 9.55006C14.9902 9.78438 14.6103 9.78438 14.376 9.55006L12.5041 7.67822C11.8977 7.97568 11.2181 8.21208 10.4884 8.37706L11.0996 10.6581C11.1853 10.9782 10.9954 11.3072 10.6753 11.393C10.3552 11.4787 10.0262 11.2888 9.94045 10.9687L9.29949 8.57652C8.8758 8.62404 8.44081 8.64865 7.99828 8.64865C7.55276 8.64865 7.11487 8.62371 6.68846 8.57555L6.04723 10.9687C5.96147 11.2888 5.63247 11.4788 5.31239 11.393C4.99231 11.3073 4.80236 10.9783 4.88812 10.6582L5.49983 8.37516C4.7743 8.2105 4.09843 7.9752 3.49498 7.67947L1.62436 9.55009C1.39005 9.78441 1.01015 9.78441 0.775835 9.5501C0.54152 9.31578 0.541518 8.93588 0.775832 8.70157L2.43478 7.04261C2.34987 6.98024 2.26746 6.91632 2.18764 6.8509C1.69842 6.44997 1.29706 5.98445 1.0258 5.46335C0.872791 5.16942 0.987031 4.80711 1.28096 4.6541Z"}}]},Ol=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"eyelash-single",ref:i,icon:lg}))});Ol.displayName="EyelashSingle";var cg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M6.06409 5.53454C5.93592 5.53454 5.84083 5.41567 5.86897 5.29063L5.95442 4.9109C6.05444 4.48178 6.23806 4.11547 6.51182 3.81952 6.81082 3.49628 7.25398 3.35405 7.79738 3.35405 7.99847 3.35405 8.21359 3.37775 8.44188 3.42245 8.46089 3.42617 8.47974 3.43006 8.49846 3.4341 8.7099 3.4798 8.93698 3.38478 9.02031 3.18514L9.24767 2.6404C9.33457 2.43219 9.23178 2.19404 9.01582 2.12874 8.98358 2.11899 8.95028 2.10912 8.91591 2.09914 8.62745 2.01631 8.28392 1.97217 7.88074 1.97217 6.82015 1.97217 6.02714 2.23936 5.4746 2.7444 4.90987 3.26069 4.50889 3.99917 4.28413 4.9762L2.83703 11.1909C2.76126 11.5286 2.666 11.8917 2.54844 12.2812 2.42975 12.6734 2.2873 13.0595 2.12221 13.4373 1.95577 13.8159 1.76813 14.1762 1.55955 14.5171 1.49345 14.6251 1.42515 14.7282 1.35467 14.8263 1.26508 14.9509 1.3347 15.133 1.48655 15.1554 2.13635 15.2509 2.8179 15.0763 3.18197 14.5296 3.32661 14.3124 3.46779 14.0646 3.60509 13.7851 3.96635 13.0497 4.30522 12.0103 4.61867 10.6574L5.469 7.01534C5.49013 6.92483 5.57082 6.86081 5.66376 6.86081H7.62478C7.8097 6.86081 7.97051 6.73405 8.01371 6.55425L8.14014 6.02798C8.20057 5.77642 8.00992 5.53454 7.75121 5.53454H6.06409zM14.3211 5.72037L12.5124 7.96963 11.4089 5.77754C11.3422 5.63012 11.1954 5.5354 11.0336 5.5354H10.3129C10.0085 5.5354 9.80921 5.85428 9.9427 6.1279L11.4089 9.05502 8.79783 12.1493C8.56587 12.4158 8.75519 12.8315 9.10855 12.8315H9.68607C9.80672 12.8315 9.9605 12.7822 10.0388 12.6904L12.1108 10.2648 13.1176 12.561C13.1786 12.7231 13.333 12.8315 13.5061 12.8315H14.3C14.5831 12.8315 14.7417 12.6175 14.6426 12.3524L13.1728 9.28628C13.1728 9.28628 15.4009 6.45542 15.6013 6.17892 15.7966 5.90929 15.6023 5.5354 15.2693 5.5354H14.6661C14.5275 5.5354 14.4333 5.58887 14.3211 5.72037z"}}]},xl=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"fx-single",ref:i,icon:cg}))});xl.displayName="FxSingle";var dg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M6.4833 1.65005C6.4833 1.31868 6.21467 1.05005 5.8833 1.05005C5.55193 1.05005 5.2833 1.31868 5.2833 1.65005V5.28345H1.65029C1.31892 5.28345 1.05029 5.55208 1.05029 5.88345C1.05029 6.21482 1.31892 6.48345 1.65029 6.48345H5.2833V9.51684H1.65029C1.31892 9.51684 1.05029 9.78547 1.05029 10.1168C1.05029 10.4482 1.31892 10.7168 1.65029 10.7168H5.2833V14.35C5.2833 14.6814 5.55193 14.95 5.8833 14.95C6.21467 14.95 6.4833 14.6814 6.4833 14.35V10.7168H9.5167V14.35C9.5167 14.6814 9.78533 14.95 10.1167 14.95C10.4481 14.95 10.7167 14.6814 10.7167 14.35V10.7168H14.3503C14.6817 10.7168 14.9503 10.4482 14.9503 10.1168C14.9503 9.78547 14.6817 9.51685 14.3503 9.51685H10.7167V6.48345H14.3503C14.6817 6.48345 14.9503 6.21482 14.9503 5.88345C14.9503 5.55208 14.6817 5.28345 14.3503 5.28345H10.7167V1.65005C10.7167 1.31868 10.4481 1.05005 10.1167 1.05005C9.78533 1.05005 9.5167 1.31868 9.5167 1.65005V5.28345L6.4833 5.28345V1.65005ZM6.4833 6.48345V9.51684L9.5167 9.51685V6.48345L6.4833 6.48345Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.0498 3.65005C1.0498 2.21411 2.21386 1.05005 3.6498 1.05005H12.3498C13.7857 1.05005 14.9498 2.21411 14.9498 3.65005V12.3501C14.9498 13.786 13.7857 14.95 12.3498 14.95H3.6498C2.21386 14.95 1.0498 13.786 1.0498 12.35V3.65005ZM3.6498 2.25005C2.87661 2.25005 2.2498 2.87685 2.2498 3.65005V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V3.65005C13.7498 2.87685 13.123 2.25005 12.3498 2.25005H3.6498Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Al=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"hide-gridlines",ref:i,icon:dg}))});Al.displayName="HideGridlines";var ug={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},ws=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"increase-single",ref:i,icon:ug}))});ws.displayName="IncreaseSingle";var hg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.62402 7.72905C2.58427 7.72905 2.55205 7.76127 2.55205 7.80102V13.6782C2.55205 13.7179 2.58427 13.7502 2.62402 13.7502H13.3755C13.4152 13.7502 13.4474 13.7179 13.4474 13.6782V7.80102C13.4474 7.76127 13.4152 7.72905 13.3755 7.72905H2.62402ZM1.35205 7.80102C1.35205 7.09853 1.92153 6.52905 2.62402 6.52905H13.3755C14.0779 6.52905 14.6474 7.09853 14.6474 7.80102V13.6782C14.6474 14.3807 14.0779 14.9502 13.3755 14.9502H2.62402C1.92153 14.9502 1.35205 14.3807 1.35205 13.6782V7.80102Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M8 2.25005C6.69847 2.25003 5.64336 3.30513 5.64336 4.60666V7.12895C5.64336 7.46032 5.37473 7.72895 5.04336 7.72895 4.71199 7.72895 4.44336 7.46032 4.44336 7.12895V4.60666C4.44336 2.64239 6.04451 1.05565 8.00879 1.05566M8 2.25005L8.00879 1.05566 8 2.25005zM8.00879 1.05566L8 2.25005C9.30154 2.25003 10.3567 3.30513 10.3567 4.60666V7.12895C10.3567 7.46032 10.6253 7.72895 10.9567 7.72895 11.288 7.72895 11.5567 7.46032 11.5567 7.12895V4.60666C11.5567 2.64239 9.97306 1.05565 8.00879 1.05566zM8.00039 9.4668C8.33176 9.4668 8.60039 9.73543 8.60039 10.0668V12.0827C8.60039 12.4141 8.33176 12.6827 8.00039 12.6827 7.66902 12.6827 7.40039 12.4141 7.40039 12.0827V10.0668C7.40039 9.73543 7.66902 9.4668 8.00039 9.4668z",fillRule:"evenodd",clipRule:"evenodd"}}]},ys=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"lock-single",ref:i,icon:hg}))});ys.displayName="LockSingle";var mg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M11.3536 6.14645C11.5488 6.34171 11.5488 6.65829 11.3536 6.85355L8.35355 9.85355C8.15829 10.0488 7.84171 10.0488 7.64645 9.85355L4.64645 6.85355C4.45118 6.65829 4.45118 6.34171 4.64645 6.14645C4.84171 5.95118 5.15829 5.95118 5.35355 6.14645L8 8.79289L10.6464 6.14645C10.8417 5.95118 11.1583 5.95118 11.3536 6.14645Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Mn=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"more-down-single",ref:i,icon:mg}))});Mn.displayName="MoreDownSingle";var gg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.90913 3.57564C6.14345 3.34132 6.52335 3.34132 6.75766 3.57564L10.7577 7.57564C10.992 7.80995 10.992 8.18985 10.7577 8.42417L6.75766 12.4242C6.52335 12.6585 6.14345 12.6585 5.90913 12.4242C5.67482 12.1899 5.67482 11.81 5.90913 11.5756L9.48487 7.9999L5.90913 4.42417C5.67482 4.18985 5.67482 3.80995 5.90913 3.57564Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Yo=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"more-single",ref:i,icon:gg}))});Yo.displayName="MoreSingle";var Sg={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"}}]}]},Nl=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"paint-bucket",ref:i,icon:Sg}))});Nl.displayName="PaintBucket";var fg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_1138",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_1138)"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M7.74692 9.12463C7.74692 9.46018 8.01893 9.73219 8.35448 9.73219H11.4933C11.8288 9.73219 12.1009 9.46018 12.1009 9.12463 12.1009 8.78909 11.8288 8.51707 11.4933 8.51707H8.35448C8.01893 8.51707 7.74692 8.78909 7.74692 9.12463zM10.8636 10.8523C10.8636 11.1879 10.5915 11.4599 10.256 11.4599H8.35448C8.01893 11.4599 7.74692 11.1879 7.74692 10.8523 7.74692 10.5168 8.01893 10.2447 8.35448 10.2447H10.256C10.5915 10.2447 10.8636 10.5168 10.8636 10.8523z"}},{tag:"path",attrs:{fill:"currentColor",d:"M5.4791 1.98268C5.47913 1.71529 5.87912 1.49854 6.37252 1.49854C6.86593 1.49854 7.26592 1.71529 7.26595 1.98268H7.62187C8.22277 1.98268 8.72459 2.39534 8.84412 2.9452H9.39563C10.0856 2.9452 10.6449 3.48923 10.6449 4.16032V6.00569H12.1261C13.161 6.00569 14 6.82174 14 7.82838V11.334C14 11.8174 13.8025 12.281 13.4511 12.6228L12.0693 13.9647C11.7179 14.3065 11.2412 14.4985 10.7442 14.4985H7.91116C7.05024 14.4985 6.32492 14.0431 6.10535 13.2737H3.34925C2.6593 13.2737 2.09998 12.7297 2.09998 12.0586V4.16032C2.09998 3.48923 2.6593 2.9452 3.34925 2.9452H3.90107C4.0206 2.39534 4.52241 1.98268 5.12332 1.98268H5.4791ZM3.97249 4.16032H3.24925L3.24925 12.0586H6.03725V7.82838C6.03725 6.82174 6.87623 6.00569 7.91116 6.00569H9.49563V4.16032H8.7727C8.58289 4.59611 8.13909 4.90183 7.62187 4.90183H5.12332C4.6061 4.90183 4.1623 4.59611 3.97249 4.16032ZM5.12332 2.89403H7.62187C7.79436 2.89403 7.93419 3.03003 7.93419 3.19781V3.68671C7.93419 3.85448 7.79436 3.99049 7.62187 3.99049H5.12332C4.95083 3.99049 4.811 3.85448 4.811 3.68671V3.19781C4.811 3.03003 4.95083 2.89403 5.12332 2.89403ZM7.91116 7.11157C7.56618 7.11157 7.28652 7.38359 7.28652 7.71913V12.7851C7.28652 13.1206 7.56618 13.3927 7.91116 13.3927H10.7442C10.8401 13.3927 10.9337 13.3712 11.0182 13.3311C11.1373 13.2746 11.1859 13.1423 11.1859 13.0134V12.0066C11.1859 11.8724 11.2978 11.7636 11.4358 11.7636H12.4709C12.6034 11.7636 12.7394 11.7163 12.7975 11.6004C12.8388 11.5182 12.8608 11.4272 12.8608 11.334V7.71913C12.8608 7.38359 12.5811 7.11157 12.2362 7.11157H7.91116Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},Dl=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"paste-special",ref:i,icon:fg}))});Dl.displayName="PasteSpecial";var pg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.785 6.77762C5.78908 6.7777 5.79316 6.77774 5.79725 6.77774C5.80134 6.77774 5.80543 6.7777 5.8095 6.77762H10.0184C10.0225 6.7777 10.0266 6.77774 10.0307 6.77774C10.0347 6.77774 10.0388 6.7777 10.0429 6.77762H13.6638V7.63727C13.6638 7.96864 13.9324 8.23727 14.2638 8.23727C14.5951 8.23727 14.8638 7.96864 14.8638 7.63727V3.9999C14.8638 2.56395 13.6997 1.39989 12.2637 1.3999L3.56389 1.39999C2.12797 1.40001 0.96393 2.56405 0.96392 3.99998L0.963867 11.6666C0.963857 13.1025 2.12792 14.2666 3.56387 14.2666H8.0542C8.38557 14.2666 8.6542 13.9979 8.6542 13.6666C8.6542 13.3352 8.38557 13.0666 8.0542 13.0666H3.56387C2.79067 13.0666 2.16386 12.4398 2.16387 11.6666L2.1639 6.77762H5.785ZM6.39725 2.59996L9.43065 2.59993V5.57762H6.39725V2.59996ZM5.19725 5.57762V2.59998L3.56391 2.59999C2.79072 2.6 2.16393 3.22679 2.16392 3.99998L2.16391 5.57762H5.19725ZM13.6638 5.57762V3.9999C13.6638 3.2267 13.037 2.59989 12.2638 2.5999L10.6307 2.59992V5.57762H13.6638Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M14.1223 10.2333V10.7496C14.7087 10.9869 15.1223 11.5618 15.1223 12.2333V12.8999C15.1223 13.7836 14.406 14.4999 13.5223 14.4999H11.5223C10.6387 14.4999 9.92235 13.7836 9.92235 12.8999V12.2333C9.92235 11.5618 10.336 10.9869 10.9223 10.7496V10.2333C10.9223 9.34961 11.6387 8.63328 12.5223 8.63328C13.406 8.63328 14.1223 9.34961 14.1223 10.2333ZM11.1223 12.2333C11.1223 12.0124 11.3014 11.8333 11.5223 11.8333H13.5223C13.7433 11.8333 13.9223 12.0124 13.9223 12.2333V12.8999C13.9223 13.1209 13.7433 13.2999 13.5223 13.2999H11.5223C11.3014 13.2999 11.1223 13.1209 11.1223 12.8999V12.2333ZM12.9223 10.2333V10.6333H12.1223V10.2333C12.1223 10.0124 12.3014 9.83328 12.5223 9.83328C12.7433 9.83328 12.9223 10.0124 12.9223 10.2333Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Hl=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"protect-single",ref:i,icon:pg}))});Hl.displayName="ProtectSingle";var vg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M15 8C15 11.866 11.866 15 8 15C4.13401 15 1 11.866 1 8C1 4.13401 4.13401 1 8 1C11.866 1 15 4.13401 15 8ZM8.00008 12.3671C8.46031 12.3671 8.83342 11.994 8.83342 11.5338C8.83342 11.0735 8.46031 10.7004 8.00008 10.7004C7.53985 10.7004 7.16675 11.0735 7.16675 11.5338C7.16675 11.994 7.53985 12.3671 8.00008 12.3671ZM8.5999 4.4335C8.5999 4.10213 8.33127 3.8335 7.9999 3.8335C7.66853 3.8335 7.3999 4.10213 7.3999 4.4335V9.36683C7.3999 9.6982 7.66853 9.96683 7.9999 9.96683C8.33127 9.96683 8.5999 9.6982 8.5999 9.36683V4.4335Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Go=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"warning-single",ref:i,icon:vg}))});Go.displayName="WarningSingle";var Cg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.6551 1.98906C11.7476 1.08113 10.2757 1.08149 9.3686 1.98987L4.82542 6.53955C4.75087 6.61421 4.69336 6.70411 4.65682 6.80309L3.2461 10.625C3.16506 10.8446 3.21909 11.0912 3.3845 11.2568C3.54991 11.4224 3.79651 11.4767 4.01616 11.3959L7.85031 9.98517C7.94979 9.94856 8.04014 9.89077 8.11508 9.81579L12.6552 5.27327C13.5618 4.36621 13.5618 2.89607 12.6551 1.98906ZM10.2177 2.83779C10.6562 2.39869 11.3677 2.39851 11.8064 2.8374C12.2447 3.27584 12.2447 3.9865 11.8065 4.42497L7.3392 8.89457L4.82213 9.82068L5.74706 7.31487L10.2177 2.83779Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.79238 13.2999C1.46101 13.2999 1.19238 13.5685 1.19238 13.8999C1.19238 14.2313 1.46101 14.4999 1.79238 14.4999H14.4924C14.8238 14.4999 15.0924 14.2313 15.0924 13.8999C15.0924 13.5685 14.8238 13.2999 14.4924 13.2999H1.79238Z"}}]},Ms=V.forwardRef(function(n,i){return V.createElement(Re,Object.assign({},n,{id:"write-single",ref:i,icon:Cg}))});Ms.displayName="WriteSingle";function _g(n,i){if(n.length!==i.length)return!1;const e=n.sort((r,o)=>r.id.localeCompare(o.id)),t=i.sort((r,o)=>r.id.localeCompare(o.id));return e.every((r,o)=>{var s,l;return((s=r.subject)==null?void 0:s.userID)===((l=t[o].subject)==null?void 0:l.userID)&&r.role===t[o].role})}function kl(n,i){return i.some(e=>Ig(n,e))}function Ig(n,i){const{startRow:e,startColumn:t,endColumn:r,endRow:o}=i,s=n.getMatrixWithMergedCells(e,t,o,r);let l=!1;return s.forValue((d,c,u)=>{if(u&&(d!==e||c!==t)&&n.cellHasValue(u))return l=!0,!1}),l}function Vl(n,i,e,t){const r=[],o=[],s=e.getSheetId();return t.forEach(l=>{const d=bg(e,l),c={unitId:i,subUnitId:s,cellValue:d.getData()},u=m.SetRangeValuesUndoMutationFactory(n,c);r.push({id:m.SetRangeValuesMutation.id,params:u}),o.push({id:m.SetRangeValuesMutation.id,params:c})}),{undos:r,redos:o}}function bg(n,i){const{startRow:e,startColumn:t,endColumn:r,endRow:o}=i,s=n.getMatrixWithMergedCells(e,t,o,r,a.CellModeEnum.Intercepted),l=new a.ObjectMatrix;let d=null;return s.forValue((c,u,h)=>{var g,S,f,p;h&&c>=e&&u>=t&&(!d&&n.cellHasValue(h)&&(h.v!==""||((p=(f=(S=(g=h.p)==null?void 0:g.body)==null?void 0:S.dataStream)==null?void 0:f.length)!=null?p:0)>2)&&(d=h),l.setValue(c,u,null))}),l.setValue(e,t,d),l}function Rg(n,i,e,t){const r=e.getActiveViewportByCoord(w.Vector2.FromArray([n,i]));if(!r)return;const{scaleX:o,scaleY:s}=e.getAncestorScale(),l={x:r.viewportScrollX,y:r.viewportScrollY},d=t.getCellIndexByOffset(n,i,o,s,l),c=t.worksheet.getMergedCell(d.row,d.column);return{actualRow:c?c.startRow:d.row,actualCol:c?c.startColumn:d.column,mergeCell:c,row:d.row,col:d.column}}function va(n,i,e,t){const r=t.getFreeze();if(!r||r.startRow<=0&&r.startColumn<=0||n>=r.startRow&&i>=r.startColumn)return e.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(n<r.startRow&&i<r.startColumn)return e.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP);if(n<r.startRow&&i>=r.startColumn)return e.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(n>=r.startRow&&i<r.startColumn)return e.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)}function Eg(n,i,e,t){const r=Ca(n.left,n.top,i,e,t),o=Ca(n.right,n.bottom,i,e,t);return{left:r.x,top:r.y,right:o.x,bottom:o.y}}function Ca(n,i,e,t,r){const{scaleX:o,scaleY:s}=e.getAncestorScale(),l=e.getViewport(w.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!l)return{x:n,y:i};const d=r.getFreeze(),{startColumn:c,startRow:u,xSplit:h,ySplit:g}=d,S=t.getNoMergeCellPositionByIndexWithNoHeader(u-g,c-h),f=t.getNoMergeCellPositionByIndexWithNoHeader(u,c),{rowHeaderWidth:p,columnHeaderHeight:v}=t,C=f.startX-S.startX,I=f.startY-S.startY,{top:b,left:T,viewportScrollX:M,viewportScrollY:y}=l;let P;n>T?P=(n-M)*o:P=(C+p-(T-n))*o;let x;return i>b?x=(i-y)*s:x=(I+v-(b-i))*o,{x:P,y:x}}function Wl(n,i,e,t,r){let o=t,s=r;e.overflowCache.forValue((c,u,h)=>{h.startRow<=o&&h.endRow>=o&&h.startColumn<=s&&h.endColumn>=s&&(s=u,o=c)});const l=e.getCellWithCoordByIndex(o,s);return{unitId:n.getUnitId(),subUnitId:i.getSheetId(),workbook:n,worksheet:i,row:l.actualRow,col:l.actualColumn}}function Ul(n,i,e,t,r,o){const{scene:s}=n,l=i.getUnitId(),{skeleton:d,sheetId:c}=t,u=Rg(r,o,s,d);if(!u)return null;let{actualCol:h,actualRow:g}=u;const S={unitId:l,subUnitId:c,workbook:i,worksheet:e,row:g,col:h};d.overflowCache.forValue((y,P,x)=>{x.startRow<=g&&x.endRow>=g&&x.startColumn<=h&&x.endColumn>=h&&(h=P,g=y)});const f=d.getCellWithCoordByIndex(g,h),p=Wl(i,e,d,g,h);let v;f.mergeInfo?v=f.mergeInfo:v={startRow:p.row,endRow:p.row,startColumn:p.col,endColumn:p.col};const C=s.getActiveViewportByCoord(w.Vector2.FromArray([r,o]));if(!C)return;const{scaleX:I,scaleY:b}=s.getAncestorScale(),T={x:C.viewportScrollX,y:C.viewportScrollY};return{position:{startX:(d.getOffsetByPositionX(v.startColumn-1)-T.x)*I,endX:(d.getOffsetByPositionX(v.endColumn)-T.x)*I,startY:(d.getOffsetByPositionY(v.startRow-1)-T.y)*b,endY:(d.getOffsetByPositionY(v.endRow)-T.y)*b},location:S,overflowLocation:p}}const wt={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge",handler:async(n,i)=>{const e=n.get(a.ICommandService),t=n.get(a.IUndoRedoService),r=n.get(a.IUniverInstanceService),o=n.get(E.IConfirmService),s=n.get(a.LocaleService),l=i.unitId,d=i.subUnitId,c=i.selections,u=m.getAddMergeMutationRangeByType(c,i.value),h=r.getUniverSheetInstance(l).getSheetBySheetId(d),g=[],S=[],f=kl(h,u);if(f&&!i.defaultMerge&&!await o.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 p={unitId:l,subUnitId:d,ranges:a.Tools.deepClone(u)},v={unitId:l,subUnitId:d,ranges:a.Tools.deepClone(u)},C=m.RemoveMergeUndoMutationFactory(n,p),I=m.AddMergeUndoMutationFactory(n,v);if(C.ranges.length>0&&g.push({id:m.RemoveWorksheetMergeMutation.id,params:C}),g.push({id:m.AddWorksheetMergeMutation.id,params:v}),S.push({id:m.RemoveWorksheetMergeMutation.id,params:I}),C.ranges.length>0&&S.push({id:m.AddWorksheetMergeMutation.id,params:C}),f){const x=Vl(n,l,h,u);g.unshift(...x.redos),S.push(...x.undos)}const b=m.AddMergeRedoSelectionsOperationFactory(n,i,u);b&&g.push(b);const T=m.AddMergeUndoSelectionsOperationFactory(n,i);T&&S.push(T);const y=n.get(m.SheetInterceptorService).onCommandExecute({id:wt.id,params:{unitId:l,subUnitId:d,ranges:u}});return g.push(...y.redos),S.push(...y.undos),a.sequenceExecute(g,e).result?(t.pushUndoRedo({unitID:l,undoMutations:S,redoMutations:g}),!0):!1}},Ps={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-all",handler:async n=>{var u;const i=n.get(a.ICommandService),t=(u=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:u.map(h=>h.range),r=gs(Pi.MergeAll,t);if(!(r!=null&&r.length))return!1;const s=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;const l=s.getActiveSheet();if(!l)return!1;const d=s.getUnitId(),c=l.getSheetId();return i.executeCommand(wt.id,{selections:r,unitId:d,subUnitId:c})}},Os={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-vertical",handler:async n=>{var u;const i=n.get(a.ICommandService),t=(u=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:u.map(h=>h.range),r=gs(Pi.MergeVertical,t);if(!(r!=null&&r.length))return!1;const s=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;const l=s.getActiveSheet();if(!l)return!1;const d=s.getUnitId(),c=l.getSheetId();return i.executeCommand(wt.id,{value:a.Dimension.COLUMNS,selections:r,unitId:d,subUnitId:c})}},xs={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-horizontal",handler:async n=>{var u;const i=n.get(a.ICommandService),t=(u=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:u.map(h=>h.range),r=gs(Pi.MergeHorizontal,t);if(!(r!=null&&r.length))return!1;const s=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;const l=s.getActiveSheet();if(!l)return!1;const d=s.getUnitId(),c=l.getSheetId();return i.executeCommand(wt.id,{value:a.Dimension.ROWS,selections:r,unitId:d,subUnitId:c})}},Vn={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-move-left-confirm",handler:async n=>{const i=n.get(E.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=r.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(o);if(!l)return!1;const{worksheet:d}=l;let c=s[0].range;if(!c)return!1;c={...c,endColumn:d.getColumnCount()-1};const u=S=>S.endRow-S.startRow;return!d.getMergeData().find(S=>{const f=a.Rectangle.getIntersects(S,c);return f?u(S)>u(f):!1})||await i.confirm({id:Vn.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.DeleteRangeMoveLeftCommand.id):!0}},Yt={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-move-up-confirm",handler:async n=>{const i=n.get(E.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=r.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(o);if(!l)return!1;const{worksheet:d}=l;let c=s[0].range;if(!c)return!1;c={...c,endRow:d.getRowCount()-1};for(let S=c.startRow;S<=c.endRow;S++)if(d.getRowFiltered(S)&&await i.confirm({id:Yt.id,title:{title:t.t("filter.confirm.error")},children:{title:t.t("filter.confirm.notAllowedToInsertRange")},confirmText:t.t("button.confirm")}))return!1;const u=S=>S.endColumn-S.startColumn;return!d.getMergeData().find(S=>{const f=a.Rectangle.getIntersects(S,c);return f?u(S)>u(f):!1})||await i.confirm({id:Yt.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.DeleteRangeMoveUpCommand.id):!0}},Gt={type:a.CommandType.COMMAND,id:"sheet.command.insert-range-move-down-confirm",handler:async n=>{const i=n.get(E.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=r.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(o);if(!l)return!1;const{worksheet:d}=l;let c=s[0].range;if(!c)return!1;c={...c,endRow:d.getRowCount()-1};for(let S=c.startRow;S<=c.endRow;S++)if(d.getRowFiltered(S)&&await i.confirm({id:Gt.id,title:{title:t.t("filter.confirm.error")},children:{title:t.t("filter.confirm.notAllowedToInsertRange")},confirmText:t.t("button.confirm")}))return!1;const u=S=>S.endColumn-S.startColumn;return!d.getMergeData().find(S=>{const f=a.Rectangle.getIntersects(S,c);return f?u(S)>u(f):!1})||await i.confirm({id:Gt.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.InsertRangeMoveDownCommand.id):!0}},Wn={type:a.CommandType.COMMAND,id:"sheet.command.insert-range-move-right-confirm",handler:async n=>{const i=n.get(E.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=r.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(o);if(!l)return!1;const{worksheet:d}=l;let c=s[0].range;if(!c)return!1;c={...c,endColumn:d.getColumnCount()-1};const u=S=>S.endRow-S.startRow;return!d.getMergeData().find(S=>{const f=a.Rectangle.getIntersects(S,c);return f?u(S)>u(f):!1})||await i.confirm({id:Wn.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.InsertRangeMoveRightCommand.id):!0}};var Ll=(n=>(n[n.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",n[n.UNIVER_DOC=1]="UNIVER_DOC",n[n.UNIVER_SHEET=2]="UNIVER_SHEET",n[n.UNIVER_SLIDE=3]="UNIVER_SLIDE",n[n.UNIVER_PROJECT=4]="UNIVER_PROJECT",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(Ll||{}),ne=(n=>(n[n.View=0]="View",n[n.Edit=1]="Edit",n[n.ManageCollaborator=2]="ManageCollaborator",n[n.Print=3]="Print",n[n.Duplicate=4]="Duplicate",n[n.Comment=5]="Comment",n[n.Copy=6]="Copy",n[n.Share=7]="Share",n[n.Export=8]="Export",n[n.MoveWorksheet=9]="MoveWorksheet",n[n.DeleteWorksheet=10]="DeleteWorksheet",n[n.HideWorksheet=11]="HideWorksheet",n[n.RenameWorksheet=12]="RenameWorksheet",n[n.CreateWorksheet=13]="CreateWorksheet",n[n.SetWorksheetStyle=14]="SetWorksheetStyle",n[n.EditWorksheetCell=15]="EditWorksheetCell",n[n.InsertHyperlink=16]="InsertHyperlink",n[n.Sort=17]="Sort",n[n.Filter=18]="Filter",n[n.PivotTable=19]="PivotTable",n[n.FloatImg=20]="FloatImg",n[n.History=21]="History",n[n.RwHgtClWdt=22]="RwHgtClWdt",n[n.ViemRwHgtClWdt=23]="ViemRwHgtClWdt",n[n.ViewFilter=24]="ViewFilter",n[n.MoveSheet=25]="MoveSheet",n[n.DeleteSheet=26]="DeleteSheet",n[n.HideSheet=27]="HideSheet",n[n.CopySheet=28]="CopySheet",n[n.RenameSheet=29]="RenameSheet",n[n.CreateSheet=30]="CreateSheet",n[n.SelectProtectedCells=31]="SelectProtectedCells",n[n.SelectUnProtectedCells=32]="SelectUnProtectedCells",n[n.SetCellStyle=33]="SetCellStyle",n[n.SetCellValue=34]="SetCellValue",n[n.SetRowStyle=35]="SetRowStyle",n[n.SetColumnStyle=36]="SetColumnStyle",n[n.InsertRow=37]="InsertRow",n[n.InsertColumn=38]="InsertColumn",n[n.DeleteRow=39]="DeleteRow",n[n.DeleteColumn=40]="DeleteColumn",n[n.EditExtraObject=41]="EditExtraObject",n[n.Delete=42]="Delete",n[n.RecoverHistory=43]="RecoverHistory",n[n.ViewHistory=44]="ViewHistory",n[n.CreatePermissionObject=45]="CreatePermissionObject",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(ne||{}),Ne=(n=>(n[n.Reader=0]="Reader",n[n.Editor=1]="Editor",n[n.Owner=2]="Owner",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(Ne||{}),dt=(n=>(n[n.Unkonwn=0]="Unkonwn",n[n.Workbook=1]="Workbook",n[n.Worksheet=2]="Worksheet",n[n.SelectRange=3]="SelectRange",n[n.Document=4]="Document",n[n.Slide=5]="Slide",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(dt||{}),Ke=(n=>(n[n.SomeCollaborator=0]="SomeCollaborator",n[n.AllCollaborator=1]="AllCollaborator",n[n.OneSelf=2]="OneSelf",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(Ke||{});const nr="UNIVER_SHEET_PERMISSION_PANEL",ri="UNIVER_SHEET_PERMISSION_USER_PART",As="UNIVER_SHEET_PERMISSION_BACKGROUND",Bl="UNIVER_SHEET_PERMISSION_USER_DIALOG",Fl="UNIVER_SHEET_PERMISSION_DIALOG",ii="UNIVER_SHEET_PERMISSION_USER_DIALOG_ID",oi="UNIVER_SHEET_PERMISSION_DIALOG_ID",Ur={[ne.Copy]:"Copy",[ne.SetCellStyle]:"SetCellStyle",[ne.SetCellValue]:"SetCellValue",[ne.SetRowStyle]:"SetRowStyle",[ne.SetColumnStyle]:"SetColumnStyle",[ne.InsertRow]:"InsertRow",[ne.InsertColumn]:"InsertColumn",[ne.InsertHyperlink]:"InsertHyperlink",[ne.DeleteRow]:"DeleteRow",[ne.DeleteColumn]:"DeleteColumn",[ne.Sort]:"Sort",[ne.Filter]:"Filter",[ne.PivotTable]:"PivotTable",[ne.EditExtraObject]:"EditExtraObject"},Tg=[ne.Copy,ne.SetCellStyle,ne.SetCellValue,ne.SetRowStyle,ne.SetColumnStyle,ne.InsertRow,ne.InsertColumn,ne.InsertHyperlink,ne.DeleteRow,ne.DeleteColumn,ne.Sort,ne.Filter,ne.PivotTable,ne.EditExtraObject,ne.View],jl="sheet-permission-menu-icon",wg="sheet-permission-delete-icon",yg="sheet-permission-edit-icon",Mg="sheet-permission-check-icon",zl="sheet-permission-lock-icon",Pg={unitId:"",subUnitId:"",permissionId:"",unitType:m.UnitObject.SelectRange,id:"",ranges:[],viewState:m.ViewStateEnum.OthersCanView,editState:m.EditStateEnum.OnlyMe};class Pn{constructor(){R(this,"_rule",Pg);R(this,"_visible",!1)}setVisible(i){this._visible=i}getVisible(){return this._visible}reset(){this.setVisible(!1)}}class yt{constructor(){R(this,"_userList",[]);R(this,"_oldCollaboratorList",[]);R(this,"_selectUserList",[]);R(this,"_selectUserList$",new O.BehaviorSubject(this._selectUserList));R(this,"selectUserList$",this._selectUserList$.asObservable())}get userList(){return this._userList}setCanEditUserList(i){this._userList=i}reset(){this._userList=[],this._oldCollaboratorList=[],this._selectUserList=[],this._selectUserList$.next([])}get oldCollaboratorList(){return this._oldCollaboratorList}setOldCollaboratorList(i){this._oldCollaboratorList=i}get selectUserList(){return this._selectUserList}setSelectUserList(i){this._selectUserList=i,this._selectUserList$.next(i)}}const Qe={type:a.CommandType.OPERATION,id:"sheet-permission.operation.openPanel",async handler(n,i={}){const e=n.get(E.ISidebarService),t=n.get(Pn),r=n.get(yt),{showDetail:o=!0,fromSheetBar:s=!1,rule:l,oldRule:d}=i,c={header:{title:"permission.panel.title"},children:{label:nr,showDetail:o,fromSheetBar:s,rule:l,oldRule:d},width:330,onClose:()=>{t.reset(),r.reset()}};return t.setVisible(!0),e.open(c),!0}},Tr={type:a.CommandType.COMMAND,id:"sheet.command.add-range-protection-from-toolbar",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{showDetail:!0}),!0}},Wt={type:a.CommandType.COMMAND,id:"sheet.command.add-range-protection-from-context-menu",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{showDetail:!0}),!0}},Ut={type:a.CommandType.COMMAND,id:"sheet.command.view-sheet-permission-from-context-menu",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{showDetail:!1}),!0}},wr={type:a.CommandType.COMMAND,id:"sheet.command.add-range-protection-from-sheet-bar",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{fromSheetBar:!0,showDetail:!0}),!0}},yr={type:a.CommandType.COMMAND,id:"sheet.command.view-sheet-permission-from-sheet-bar",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{showDetail:!1}),!0}},Lt={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-protection-from-context-menu",async handler(n){var h;const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(a.IUndoRedoService),r=n.get(m.SheetsSelectionsService),o=n.get(m.WorksheetProtectionRuleModel),s=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),l=s.getActiveSheet(),d=s.getUnitId(),c=l.getSheetId(),u=o.getRule(d,c);if(u!=null&&u.permissionId)return i.executeCommand(m.DeleteWorksheetProtectionCommand.id,{unitId:d,subUnitId:c,rule:u});{const g=(h=r.getCurrentLastSelection())==null?void 0:h.range;if(!g)return!1;const p=n.get(m.RangeProtectionRuleModel).getSubunitRuleList(d,c).find(v=>v.ranges.some(C=>a.Rectangle.intersects(C,g)));if(p){const v={unitId:d,subUnitId:c,ruleIds:[p.id]};return await i.executeCommand(m.DeleteRangeProtectionMutation.id,v)&&t.pushUndoRedo({unitID:d,redoMutations:[{id:m.DeleteRangeProtectionMutation.id,params:v}],undoMutations:[{id:m.AddRangeProtectionMutation.id,params:{unitId:d,subUnitId:c,rules:[p]}}]}),!0}else return!1}}},Bt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-protection-from-context-menu",async handler(n){var u;const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.WorksheetProtectionRuleModel),o=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=o.getActiveSheet(),l=o.getUnitId(),d=s.getSheetId(),c=r.getRule(l,d);if(c!=null&&c.permissionId){const h={...c,unitId:l,subUnitId:d,ranges:[]};return await i.executeCommand(Qe.id,{showDetail:!0,rule:a.Tools.deepClone(h),oldRule:a.Tools.deepClone(h)}),!0}else{const h=(u=t.getCurrentLastSelection())==null?void 0:u.range;if(!h)return!1;const f=n.get(m.RangeProtectionRuleModel).getSubunitRuleList(l,d).find(p=>{var v;return(v=p==null?void 0:p.ranges)==null?void 0:v.some(C=>a.Rectangle.intersects(C,h))});if(f){const p={...f,unitId:l,subUnitId:d};return await i.executeCommand(Qe.id,{showDetail:!0,rule:a.Tools.deepClone(p),oldRule:a.Tools.deepClone(p)}),!0}else return!1}}},On={id:"sheet.command.remove-row-confirm",type:a.CommandType.COMMAND,handler:async(n,i)=>{var c;const e=n.get(m.SheetsSelectionsService);let t=i==null?void 0:i.range;if(t||(t=(c=e.getCurrentLastSelection())==null?void 0:c.range),!t)return!1;const r=n.get(a.ICommandService),o=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(o);if(!s)return!1;const{worksheet:l}=s,d=l.getVisibleRows();if(Ga(d,[t])){const u=n.get(E.IConfirmService),h=n.get(a.LocaleService);return await u.confirm({id:"sheet.confirm.remove-row",title:{title:h.t("info.problem")},children:{title:h.t("rightClick.deleteAllRowsAlert")},cancelText:h.t("button.cancel"),confirmText:h.t("button.confirm")}),!1}return await r.executeCommand(m.RemoveRowCommand.id,{range:t}),!0}},xn={id:"sheet.command.remove-col-confirm",type:a.CommandType.COMMAND,handler:async(n,i)=>{var c;const e=n.get(m.SheetsSelectionsService);let t=i==null?void 0:i.range;if(t||(t=(c=e.getCurrentLastSelection())==null?void 0:c.range),!t)return!1;const r=n.get(a.ICommandService),o=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(o);if(!s)return!1;const{worksheet:l}=s,d=l.getVisibleCols();if(Za(d,[t])){const u=n.get(E.IConfirmService),h=n.get(a.LocaleService);return await u.confirm({id:"sheet.confirm.remove-col",title:{title:h.t("info.problem")},children:{title:h.t("rightClick.deleteAllColumnsAlert")},cancelText:h.t("button.cancel"),confirmText:h.t("button.confirm")}),!1}return await r.executeCommand(m.RemoveColCommand.id,{range:t}),!0}},Mr={id:"sheet.command.remove-sheet-confirm",type:a.CommandType.COMMAND,handler:async(n,i)=>{const{subUnitId:e}=i,t=n.get(E.IConfirmService),r=n.get(a.ICommandService),o=n.get(a.LocaleService);return await t.confirm({id:"sheet.confirm.remove-sheet",title:{title:o.t("sheetConfig.deleteSheet")},children:{title:o.t("sheetConfig.deleteSheetContent")},cancelText:o.t("button.cancel"),confirmText:o.t("button.confirm")})?(await r.executeCommand(m.RemoveSheetCommand.id,{subUnitId:e}),!0):!1}},nn=a.createIdentifier("univer.sheetbar-service");class Xl extends a.Disposable{constructor(){super();R(this,"renameId$");R(this,"removeId$");R(this,"scroll$");R(this,"scrollX$");R(this,"addSheet$");R(this,"_renameId$");R(this,"_removeId$");R(this,"_scroll$");R(this,"_scrollX$");R(this,"_addSheet$");R(this,"_currentHandler",null);this._renameId$=new O.Subject,this.renameId$=this._renameId$.asObservable(),this._removeId$=new O.Subject,this.removeId$=this._removeId$.asObservable(),this._scroll$=new O.Subject,this.scroll$=this._scroll$.asObservable(),this._scrollX$=new O.Subject,this.scrollX$=this._scrollX$.asObservable(),this._addSheet$=new O.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,a.toDisposable(()=>{this._currentHandler=null})}}const Pr={id:"ui-sheet.command.show-menu-list",type:a.CommandType.OPERATION,handler:async n=>(n.get(nn).triggerSheetBarMenu(),!0)},Or={type:a.CommandType.COMMAND,id:"sheet.command.delete-worksheet-protection-from-sheet-bar",async handler(n,i){if(!i)return!1;const e=n.get(a.ICommandService),t=n.get(a.IUndoRedoService),r=n.get(m.WorksheetProtectionRuleModel),s=n.get(a.IUniverInstanceService).getCurrentUnitForType(Ll.UNIVER_SHEET),l=s==null?void 0:s.getActiveSheet(),d=s.getUnitId();if(!l)return!1;const c=l.getSheetId(),u=r.getRule(d,c);if(await e.executeCommand(m.DeleteWorksheetProtectionCommand.id,{unitId:d,subUnitId:c})){const g=[{id:m.DeleteWorksheetProtectionCommand.id,params:{unitId:d,subUnitId:c}}],S=[{id:m.AddWorksheetProtectionCommand.id,params:{unitId:d,rule:u}}];t.pushUndoRedo({unitID:d,redoMutations:g,undoMutations:S})}return!0}},xr={type:a.CommandType.COMMAND,id:"sheet.command.change-sheet-protection-from-sheet-bar",async handler(n){return await n.get(a.ICommandService).executeCommand("sheet-permission.operation.openDialog"),!0}},Ui={id:"sheet.operation.set-activate-cell-edit",type:a.CommandType.OPERATION,handler:(n,i)=>(n.get(Se).setEditCell(i),!0)},Ar={id:"sheet.operation.rename-sheet",type:a.CommandType.OPERATION,handler:async(n,i)=>{const e=n.get(nn);return i&&e.setRenameId(i.subUnitId),!0}},Ns={type:a.CommandType.OPERATION,id:"sheet-permission.operation.openDialog",async handler(n,i){const e=n.get(E.IDialogService);return e.close("DESKTOP_FIND_REPLACE_DIALOG"),e.open({id:oi,title:{title:"permission.dialog.allowedPermissionType"},children:{label:Fl},width:393,destroyOnClose:!0,onClose:()=>e.close(oi)}),!0}},rr="DefinedNameContainer",Li={id:"sidebar.operation.defined-name",type:a.CommandType.COMMAND,handler:async(n,i)=>{const e=n.get(E.ISidebarService);n.get(J.IEditorService);const t=n.get(a.LocaleService),r=n.get(a.IUniverInstanceService);if(!m.getSheetCommandTarget(r))return!1;switch(i.value){case"open":e.open({id:rr,header:{title:t.t("definedName.featureTitle")},children:{label:rr},onClose:()=>{},width:333});break;case"close":default:e.close();break}return!0}},Og=()=>_.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[_.jsx("path",{d:"M0.98999 1.08218H-0.0100098V0.0821838H0.98999V1.08218Z",fill:"black"}),_.jsx("path",{d:"M5.78992 1.08218H2.78992V0.0821838H5.78992V1.08218Z",fill:"black"}),_.jsx("path",{d:"M7.58984 1.08218H8.58984V0.0821838H7.58984V1.08218Z",fill:"black"}),_.jsx("path",{d:"M14.9152 1.08218H13.9152V0.0821838H14.9152V1.08218Z",fill:"black"}),_.jsx("path",{d:"M16.7151 1.08218H19.7151V0.0821838H16.7151V1.08218Z",fill:"black"}),_.jsx("path",{d:"M22.515 1.08218H21.515V0.0821838H22.515V1.08218Z",fill:"black"}),_.jsx("path",{d:"M27.8405 1.08218H28.8405V0.0821838H27.8405V1.08218Z",fill:"black"}),_.jsx("path",{d:"M33.6404 1.08218H30.6404V0.0821838H33.6404V1.08218Z",fill:"black"}),_.jsx("path",{d:"M35.4403 1.08218H36.4403V0.0821838H35.4403V1.08218Z",fill:"black"}),_.jsx("path",{d:"M42.7657 1.08218H41.7657V0.0821838H42.7657V1.08218Z",fill:"black"}),_.jsx("path",{d:"M44.5657 1.08218H47.5657V0.0821838H44.5657V1.08218Z",fill:"black"}),_.jsx("path",{d:"M50.3656 1.08218H49.3656V0.0821838H50.3656V1.08218Z",fill:"black"}),_.jsx("path",{d:"M55.691 1.08218H56.691V0.0821838H55.691V1.08218Z",fill:"black"}),_.jsx("path",{d:"M61.491 1.08218H58.491V0.0821838H61.491V1.08218Z",fill:"black"}),_.jsx("path",{d:"M63.2909 1.08218H64.2909V0.0821838H63.2909V1.08218Z",fill:"black"}),_.jsx("path",{d:"M70.6163 1.08218H69.6163V0.0821838H70.6163V1.08218Z",fill:"black"}),_.jsx("path",{d:"M72.4163 1.08218H75.4163V0.0821838H72.4163V1.08218Z",fill:"black"}),_.jsx("path",{d:"M78.2162 1.08218H77.2162V0.0821838H78.2162V1.08218Z",fill:"black"}),_.jsx("path",{d:"M83.5416 1.08218H84.5416V0.0821838H83.5416V1.08218Z",fill:"black"}),_.jsx("path",{d:"M89.3416 1.08218H86.3416V0.0821838H89.3416V1.08218Z",fill:"black"}),_.jsx("path",{d:"M91.1415 1.08218H92.1415V0.0821838H91.1415V1.08218Z",fill:"black"}),_.jsx("path",{d:"M98.4669 1.08218H97.4669V0.0821838H98.4669V1.08218Z",fill:"black"}),_.jsx("path",{d:"M100.267 1.08218H103.267V0.0821838H100.267V1.08218Z",fill:"black"}),_.jsx("path",{d:"M106.067 1.08218H105.067V0.0821838H106.067V1.08218Z",fill:"black"}),_.jsx("path",{d:"M111.392 1.08218H112.392V0.0821838H111.392V1.08218Z",fill:"black"}),_.jsx("path",{d:"M117.192 1.08218H114.192V0.0821838H117.192V1.08218Z",fill:"black"}),_.jsx("path",{d:"M118.992 1.08218H119.992V0.0821838H118.992V1.08218Z",fill:"black"})]}),xg=()=>_.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[_.jsx("path",{d:"M-0.0100098 1.15771H0.98999V0.157715H-0.0100098V1.15771Z",fill:"black"}),_.jsx("path",{d:"M2.78992 1.15771H5.78992V0.157715H2.78992V1.15771Z",fill:"black"}),_.jsx("path",{d:"M8.58984 1.15771H7.58984V0.157715H8.58984V1.15771Z",fill:"black"}),_.jsx("path",{d:"M10.3899 1.15771H11.3899V0.157715H10.3899V1.15771Z",fill:"black"}),_.jsx("path",{d:"M19.0903 1.15771H18.0903V0.157715H19.0903V1.15771Z",fill:"black"}),_.jsx("path",{d:"M20.8903 1.15771H23.8903V0.157715H20.8903V1.15771Z",fill:"black"}),_.jsx("path",{d:"M26.6902 1.15771H25.6902V0.157715H26.6902V1.15771Z",fill:"black"}),_.jsx("path",{d:"M28.4902 1.15771H29.4902V0.157715H28.4902V1.15771Z",fill:"black"}),_.jsx("path",{d:"M37.1907 1.15771H36.1907V0.157715H37.1907V1.15771Z",fill:"black"}),_.jsx("path",{d:"M38.9906 1.15771H41.9906V0.157715H38.9906V1.15771Z",fill:"black"}),_.jsx("path",{d:"M44.7905 1.15771H43.7905V0.157715H44.7905V1.15771Z",fill:"black"}),_.jsx("path",{d:"M46.5906 1.15771H47.5906V0.157715H46.5906V1.15771Z",fill:"black"}),_.jsx("path",{d:"M55.291 1.15771H54.291V0.157715H55.291V1.15771Z",fill:"black"}),_.jsx("path",{d:"M57.0909 1.15771H60.0909V0.157715H57.0909V1.15771Z",fill:"black"}),_.jsx("path",{d:"M62.8909 1.15771H61.8909V0.157715H62.8909V1.15771Z",fill:"black"}),_.jsx("path",{d:"M64.6909 1.15771H65.6909V0.157715H64.6909V1.15771Z",fill:"black"}),_.jsx("path",{d:"M73.3914 1.15771H72.3914V0.157715H73.3914V1.15771Z",fill:"black"}),_.jsx("path",{d:"M75.1913 1.15771H78.1913V0.157715H75.1913V1.15771Z",fill:"black"}),_.jsx("path",{d:"M80.9912 1.15771H79.9912V0.157715H80.9912V1.15771Z",fill:"black"}),_.jsx("path",{d:"M82.7913 1.15771H83.7913V0.157715H82.7913V1.15771Z",fill:"black"}),_.jsx("path",{d:"M91.4917 1.15771H90.4917V0.157715H91.4917V1.15771Z",fill:"black"}),_.jsx("path",{d:"M93.2916 1.15771H96.2916V0.157715H93.2916V1.15771Z",fill:"black"}),_.jsx("path",{d:"M99.0916 1.15771H98.0916V0.157715H99.0916V1.15771Z",fill:"black"}),_.jsx("path",{d:"M100.892 1.15771H101.892V0.157715H100.892V1.15771Z",fill:"black"}),_.jsx("path",{d:"M109.592 1.15771H108.592V0.157715H109.592V1.15771Z",fill:"black"}),_.jsx("path",{d:"M111.392 1.15771H114.392V0.157715H111.392V1.15771Z",fill:"black"}),_.jsx("path",{d:"M117.192 1.15771H116.192V0.157715H117.192V1.15771Z",fill:"black"}),_.jsx("path",{d:"M118.992 1.15771H119.992V0.157715H118.992V1.15771Z",fill:"black"})]}),Ag=()=>_.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[_.jsx("path",{d:"M-0.00842285 1.22449H2.99158V0.224487H-0.00842285V1.22449Z",fill:"black"}),_.jsx("path",{d:"M6.14941 1.22449H9.14941V0.224487H6.14941V1.22449Z",fill:"black"}),_.jsx("path",{d:"M15.3073 1.22449H12.3073V0.224487H15.3073V1.22449Z",fill:"black"}),_.jsx("path",{d:"M18.4651 1.22449H21.4651V0.224487H18.4651V1.22449Z",fill:"black"}),_.jsx("path",{d:"M27.6229 1.22449H24.6229V0.224487H27.6229V1.22449Z",fill:"black"}),_.jsx("path",{d:"M30.7808 1.22449H33.7808V0.224487H30.7808V1.22449Z",fill:"black"}),_.jsx("path",{d:"M39.9386 1.22449H36.9386V0.224487H39.9386V1.22449Z",fill:"black"}),_.jsx("path",{d:"M43.0964 1.22449H46.0964V0.224487H43.0964V1.22449Z",fill:"black"}),_.jsx("path",{d:"M52.2543 1.22449H49.2543V0.224487H52.2543V1.22449Z",fill:"black"}),_.jsx("path",{d:"M55.4121 1.22449H58.4121V0.224487H55.4121V1.22449Z",fill:"black"}),_.jsx("path",{d:"M64.5699 1.22449H61.5699V0.224487H64.5699V1.22449Z",fill:"black"}),_.jsx("path",{d:"M67.7278 1.22449H70.7278V0.224487H67.7278V1.22449Z",fill:"black"}),_.jsx("path",{d:"M76.8856 1.22449H73.8856V0.224487H76.8856V1.22449Z",fill:"black"}),_.jsx("path",{d:"M80.0435 1.22449H83.0435V0.224487H80.0435V1.22449Z",fill:"black"}),_.jsx("path",{d:"M89.2013 1.22449H86.2013V0.224487H89.2013V1.22449Z",fill:"black"}),_.jsx("path",{d:"M92.3591 1.22449H95.3591V0.224487H92.3591V1.22449Z",fill:"black"}),_.jsx("path",{d:"M101.517 1.22449H98.517V0.224487H101.517V1.22449Z",fill:"black"}),_.jsx("path",{d:"M104.675 1.22449H107.675V0.224487H104.675V1.22449Z",fill:"black"}),_.jsx("path",{d:"M113.833 1.22449H110.833V0.224487H113.833V1.22449Z",fill:"black"}),_.jsx("path",{d:"M116.99 1.22449H119.99V0.224487H116.99V1.22449Z",fill:"black"})]}),Ng=()=>_.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[_.jsx("path",{d:"M-0.00976562 1.65707H0.990234V0.657074H-0.00976562V1.65707Z",fill:"black"}),_.jsx("path",{d:"M2.32361 1.65707H3.32361V0.657074H2.32361V1.65707Z",fill:"black"}),_.jsx("path",{d:"M5.65698 1.65707H4.65698V0.657074H5.65698V1.65707Z",fill:"black"}),_.jsx("path",{d:"M6.99036 1.65707H7.99036V0.657074H6.99036V1.65707Z",fill:"black"}),_.jsx("path",{d:"M10.3237 1.65707H9.32373V0.657074H10.3237V1.65707Z",fill:"black"}),_.jsx("path",{d:"M11.6571 1.65707H12.6571V0.657074H11.6571V1.65707Z",fill:"black"}),_.jsx("path",{d:"M14.9905 1.65707H13.9905V0.657074H14.9905V1.65707Z",fill:"black"}),_.jsx("path",{d:"M16.3239 1.65707H17.3239V0.657074H16.3239V1.65707Z",fill:"black"}),_.jsx("path",{d:"M19.6572 1.65707H18.6572V0.657074H19.6572V1.65707Z",fill:"black"}),_.jsx("path",{d:"M20.9906 1.65707H21.9906V0.657074H20.9906V1.65707Z",fill:"black"}),_.jsx("path",{d:"M24.324 1.65707H23.324V0.657074H24.324V1.65707Z",fill:"black"}),_.jsx("path",{d:"M25.6573 1.65707H26.6573V0.657074H25.6573V1.65707Z",fill:"black"}),_.jsx("path",{d:"M28.9907 1.65707H27.9907V0.657074H28.9907V1.65707Z",fill:"black"}),_.jsx("path",{d:"M30.3241 1.65707H31.3241V0.657074H30.3241V1.65707Z",fill:"black"}),_.jsx("path",{d:"M33.6575 1.65707H32.6575V0.657074H33.6575V1.65707Z",fill:"black"}),_.jsx("path",{d:"M34.9908 1.65707H35.9908V0.657074H34.9908V1.65707Z",fill:"black"}),_.jsx("path",{d:"M38.3242 1.65707H37.3242V0.657074H38.3242V1.65707Z",fill:"black"}),_.jsx("path",{d:"M39.6576 1.65707H40.6576V0.657074H39.6576V1.65707Z",fill:"black"}),_.jsx("path",{d:"M42.991 1.65707H41.991V0.657074H42.991V1.65707Z",fill:"black"}),_.jsx("path",{d:"M44.3243 1.65707H45.3243V0.657074H44.3243V1.65707Z",fill:"black"}),_.jsx("path",{d:"M47.6577 1.65707H46.6577V0.657074H47.6577V1.65707Z",fill:"black"}),_.jsx("path",{d:"M48.9911 1.65707H49.9911V0.657074H48.9911V1.65707Z",fill:"black"}),_.jsx("path",{d:"M52.3245 1.65707H51.3245V0.657074H52.3245V1.65707Z",fill:"black"}),_.jsx("path",{d:"M53.6578 1.65707H54.6578V0.657074H53.6578V1.65707Z",fill:"black"}),_.jsx("path",{d:"M56.9912 1.65707H55.9912V0.657074H56.9912V1.65707Z",fill:"black"}),_.jsx("path",{d:"M58.3246 1.65707H59.3246V0.657074H58.3246V1.65707Z",fill:"black"}),_.jsx("path",{d:"M61.658 1.65707H60.658V0.657074H61.658V1.65707Z",fill:"black"}),_.jsx("path",{d:"M62.9913 1.65707H63.9913V0.657074H62.9913V1.65707Z",fill:"black"}),_.jsx("path",{d:"M66.3247 1.65707H65.3247V0.657074H66.3247V1.65707Z",fill:"black"}),_.jsx("path",{d:"M67.6581 1.65707H68.6581V0.657074H67.6581V1.65707Z",fill:"black"}),_.jsx("path",{d:"M70.9915 1.65707H69.9915V0.657074H70.9915V1.65707Z",fill:"black"}),_.jsx("path",{d:"M72.3248 1.65707H73.3248V0.657074H72.3248V1.65707Z",fill:"black"}),_.jsx("path",{d:"M75.6582 1.65707H74.6582V0.657074H75.6582V1.65707Z",fill:"black"}),_.jsx("path",{d:"M76.9916 1.65707H77.9916V0.657074H76.9916V1.65707Z",fill:"black"}),_.jsx("path",{d:"M80.325 1.65707H79.325V0.657074H80.325V1.65707Z",fill:"black"}),_.jsx("path",{d:"M81.6583 1.65707H82.6583V0.657074H81.6583V1.65707Z",fill:"black"}),_.jsx("path",{d:"M84.9917 1.65707H83.9917V0.657074H84.9917V1.65707Z",fill:"black"}),_.jsx("path",{d:"M86.3251 1.65707H87.3251V0.657074H86.3251V1.65707Z",fill:"black"}),_.jsx("path",{d:"M89.6584 1.65707H88.6584V0.657074H89.6584V1.65707Z",fill:"black"}),_.jsx("path",{d:"M90.9918 1.65707H91.9918V0.657074H90.9918V1.65707Z",fill:"black"}),_.jsx("path",{d:"M94.3252 1.65707H93.3252V0.657074H94.3252V1.65707Z",fill:"black"}),_.jsx("path",{d:"M95.6586 1.65707H96.6586V0.657074H95.6586V1.65707Z",fill:"black"}),_.jsx("path",{d:"M98.9919 1.65707H97.9919V0.657074H98.9919V1.65707Z",fill:"black"}),_.jsx("path",{d:"M100.325 1.65707H101.325V0.657074H100.325V1.65707Z",fill:"black"}),_.jsx("path",{d:"M103.659 1.65707H102.659V0.657074H103.659V1.65707Z",fill:"black"}),_.jsx("path",{d:"M104.992 1.65707H105.992V0.657074H104.992V1.65707Z",fill:"black"}),_.jsx("path",{d:"M108.325 1.65707H107.325V0.657074H108.325V1.65707Z",fill:"black"}),_.jsx("path",{d:"M109.659 1.65707H110.659V0.657074H109.659V1.65707Z",fill:"black"}),_.jsx("path",{d:"M112.992 1.65707H111.992V0.657074H112.992V1.65707Z",fill:"black"}),_.jsx("path",{d:"M114.325 1.65707H115.325V0.657074H114.325V1.65707Z",fill:"black"}),_.jsx("path",{d:"M117.659 1.65707H116.659V0.657074H117.659V1.65707Z",fill:"black"}),_.jsx("path",{d:"M118.992 1.65707H119.992V0.657074H118.992V1.65707Z",fill:"black"})]}),Dg=()=>_.jsx("svg",{width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:_.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 2.42035H-0.0090332V0.420349H119.991V2.42035Z",fill:"black"})}),Hg=()=>_.jsxs("svg",{width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[_.jsx("path",{d:"M-0.0100098 2.47614H1.98999V0.476135H-0.0100098V2.47614Z",fill:"black"}),_.jsx("path",{d:"M3.99014 2.47614H9.99014V0.476135H3.99014V2.47614Z",fill:"black"}),_.jsx("path",{d:"M13.9901 2.47614H11.9901V0.476135H13.9901V2.47614Z",fill:"black"}),_.jsx("path",{d:"M21.1904 2.47614H23.1904V0.476135H21.1904V2.47614Z",fill:"black"}),_.jsx("path",{d:"M31.1906 2.47614H25.1906V0.476135H31.1906V2.47614Z",fill:"black"}),_.jsx("path",{d:"M33.1906 2.47614H35.1906V0.476135H33.1906V2.47614Z",fill:"black"}),_.jsx("path",{d:"M44.3909 2.47614H42.3909V0.476135H44.3909V2.47614Z",fill:"black"}),_.jsx("path",{d:"M46.391 2.47614H52.391V0.476135H46.391V2.47614Z",fill:"black"}),_.jsx("path",{d:"M56.391 2.47614H54.391V0.476135H56.391V2.47614Z",fill:"black"}),_.jsx("path",{d:"M63.5913 2.47614H65.5913V0.476135H63.5913V2.47614Z",fill:"black"}),_.jsx("path",{d:"M73.5915 2.47614H67.5915V0.476135H73.5915V2.47614Z",fill:"black"}),_.jsx("path",{d:"M75.5915 2.47614H77.5915V0.476135H75.5915V2.47614Z",fill:"black"}),_.jsx("path",{d:"M86.7917 2.47614H84.7917V0.476135H86.7917V2.47614Z",fill:"black"}),_.jsx("path",{d:"M88.7919 2.47614H94.7919V0.476135H88.7919V2.47614Z",fill:"black"}),_.jsx("path",{d:"M98.7919 2.47614H96.7919V0.476135H98.7919V2.47614Z",fill:"black"}),_.jsx("path",{d:"M105.992 2.47614H107.992V0.476135H105.992V2.47614Z",fill:"black"}),_.jsx("path",{d:"M115.992 2.47614H109.992V0.476135H115.992V2.47614Z",fill:"black"}),_.jsx("path",{d:"M117.992 2.47614H119.992V0.476135H117.992V2.47614Z",fill:"black"})]}),kg=()=>_.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[_.jsx("path",{d:"M-0.0100098 2.00415H1.98999V0.00415039H-0.0100098V2.00415Z",fill:"black"}),_.jsx("path",{d:"M3.99014 2.00415H9.99014V0.00415039H3.99014V2.00415Z",fill:"black"}),_.jsx("path",{d:"M13.9901 2.00415H11.9901V0.00415039H13.9901V2.00415Z",fill:"black"}),_.jsx("path",{d:"M15.9901 2.00415H17.9901V0.00415039H15.9901V2.00415Z",fill:"black"}),_.jsx("path",{d:"M27.4905 2.00415H25.4905V0.00415039H27.4905V2.00415Z",fill:"black"}),_.jsx("path",{d:"M29.4906 2.00415H35.4906V0.00415039H29.4906V2.00415Z",fill:"black"}),_.jsx("path",{d:"M39.4906 2.00415H37.4906V0.00415039H39.4906V2.00415Z",fill:"black"}),_.jsx("path",{d:"M41.4906 2.00415H43.4906V0.00415039H41.4906V2.00415Z",fill:"black"}),_.jsx("path",{d:"M52.991 2.00415H50.991V0.00415039H52.991V2.00415Z",fill:"black"}),_.jsx("path",{d:"M54.9911 2.00415H60.9911V0.00415039H54.9911V2.00415Z",fill:"black"}),_.jsx("path",{d:"M64.9911 2.00415H62.9911V0.00415039H64.9911V2.00415Z",fill:"black"}),_.jsx("path",{d:"M66.9911 2.00415H68.9911V0.00415039H66.9911V2.00415Z",fill:"black"}),_.jsx("path",{d:"M78.4915 2.00415H76.4915V0.00415039H78.4915V2.00415Z",fill:"black"}),_.jsx("path",{d:"M80.4916 2.00415H86.4916V0.00415039H80.4916V2.00415Z",fill:"black"}),_.jsx("path",{d:"M90.4916 2.00415H88.4916V0.00415039H90.4916V2.00415Z",fill:"black"}),_.jsx("path",{d:"M92.4916 2.00415H94.4916V0.00415039H92.4916V2.00415Z",fill:"black"}),_.jsx("path",{d:"M103.992 2.00415H101.992V0.00415039H103.992V2.00415Z",fill:"black"}),_.jsx("path",{d:"M105.992 2.00415H111.992V0.00415039H105.992V2.00415Z",fill:"black"}),_.jsx("path",{d:"M115.992 2.00415H113.992V0.00415039H115.992V2.00415Z",fill:"black"}),_.jsx("path",{d:"M117.992 2.00415H119.992V0.00415039H117.992V2.00415Z",fill:"black"})]}),Vg=()=>_.jsxs("svg",{width:"118",height:"3",viewBox:"0 0 118 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[_.jsx("path",{d:"M-0.00854492 2.94815H1.99146V0.948151H-0.00854492V2.94815Z",fill:"black"}),_.jsx("path",{d:"M6.09668 2.94815H8.09668V0.948151H6.09668V2.94815Z",fill:"black"}),_.jsx("path",{d:"M14.2019 2.94815H12.2019V0.948151H14.2019V2.94815Z",fill:"black"}),_.jsx("path",{d:"M18.3071 2.94815H20.3071V0.948151H18.3071V2.94815Z",fill:"black"}),_.jsx("path",{d:"M26.4124 2.94815H24.4124V0.948151H26.4124V2.94815Z",fill:"black"}),_.jsx("path",{d:"M30.5176 2.94815H32.5176V0.948151H30.5176V2.94815Z",fill:"black"}),_.jsx("path",{d:"M38.6228 2.94815H36.6228V0.948151H38.6228V2.94815Z",fill:"black"}),_.jsx("path",{d:"M42.728 2.94815H44.728V0.948151H42.728V2.94815Z",fill:"black"}),_.jsx("path",{d:"M50.8333 2.94815H48.8333V0.948151H50.8333V2.94815Z",fill:"black"}),_.jsx("path",{d:"M54.9385 2.94815H56.9385V0.948151H54.9385V2.94815Z",fill:"black"}),_.jsx("path",{d:"M63.0437 2.94815H61.0437V0.948151H63.0437V2.94815Z",fill:"black"}),_.jsx("path",{d:"M67.1489 2.94815H69.1489V0.948151H67.1489V2.94815Z",fill:"black"}),_.jsx("path",{d:"M75.2542 2.94815H73.2542V0.948151H75.2542V2.94815Z",fill:"black"}),_.jsx("path",{d:"M79.3594 2.94815H81.3594V0.948151H79.3594V2.94815Z",fill:"black"}),_.jsx("path",{d:"M87.4645 2.94815H85.4645V0.948151H87.4645V2.94815Z",fill:"black"}),_.jsx("path",{d:"M91.5697 2.94815H93.5697V0.948151H91.5697V2.94815Z",fill:"black"}),_.jsx("path",{d:"M99.6749 2.94815H97.6749V0.948151H99.6749V2.94815Z",fill:"black"}),_.jsx("path",{d:"M103.78 2.94815H105.78V0.948151H103.78V2.94815Z",fill:"black"}),_.jsx("path",{d:"M111.885 2.94815H109.885V0.948151H111.885V2.94815Z",fill:"black"}),_.jsx("path",{d:"M115.991 2.94815H117.991V0.948151H115.991V2.94815Z",fill:"black"})]}),Wg=()=>_.jsx("svg",{width:"120",height:"4",viewBox:"0 0 120 4",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:_.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 3.86215H-0.0090332V0.862152H119.991V3.86215Z",fill:"black"})}),_a=()=>_.jsx("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:_.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 1.15668H-0.0090332V0.156677H119.991V1.15668Z",fill:"black"})});function Ia(n){const{type:i=a.BorderStyleTypes.THIN}=n;switch(i){case a.BorderStyleTypes.DASH_DOT:return _.jsx(Og,{});case a.BorderStyleTypes.DASH_DOT_DOT:return _.jsx(xg,{});case a.BorderStyleTypes.DASHED:return _.jsx(Ag,{});case a.BorderStyleTypes.HAIR:return _.jsx(Ng,{});case a.BorderStyleTypes.MEDIUM:return _.jsx(Dg,{});case a.BorderStyleTypes.MEDIUM_DASH_DOT:return _.jsx(Hg,{});case a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT:return _.jsx(kg,{});case a.BorderStyleTypes.MEDIUM_DASHED:return _.jsx(Vg,{});case a.BorderStyleTypes.THICK:return _.jsx(Wg,{});case a.BorderStyleTypes.THIN:return _.jsx(_a,{});default:return _.jsx(_a,{})}}const Ug="univer-ui-plugin-sheets-border-panel",Lg="univer-ui-plugin-sheets-border-panel-position",Bg="univer-ui-plugin-sheets-border-panel-position-item",Fg="univer-ui-plugin-sheets-border-panel-position-item-active",jg="univer-ui-plugin-sheets-border-panel-styles",zg="univer-ui-plugin-sheets-border-panel-board",Xg="univer-ui-plugin-sheets-border-panel-button",Yg="univer-ui-plugin-sheets-border-panel-more-icon",Be={uiPluginSheetsBorderPanel:Ug,uiPluginSheetsBorderPanelPosition:Lg,uiPluginSheetsBorderPanelPositionItem:Bg,uiPluginSheetsBorderPanelPositionItemActive:Fg,uiPluginSheetsBorderPanelStyles:jg,uiPluginSheetsBorderPanelBoard:zg,uiPluginSheetsBorderPanelButton:Xg,uiPluginSheetsBorderPanelMoreIcon:Yg},Ds=`${Hn}_BORDER_PANEL_COMPONENT`,Yl=[{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:"HorizontalBorder",value:"horizontal"},{label:"borderLine.borderVertical",icon:"VerticalBorder",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"}],Gg=[{label:a.BorderStyleTypes.THIN,value:a.BorderStyleTypes.THIN},{label:a.BorderStyleTypes.HAIR,value:a.BorderStyleTypes.HAIR},{label:a.BorderStyleTypes.DOTTED,value:a.BorderStyleTypes.DOTTED},{label:a.BorderStyleTypes.DASHED,value:a.BorderStyleTypes.DASHED},{label:a.BorderStyleTypes.DASH_DOT,value:a.BorderStyleTypes.DASH_DOT},{label:a.BorderStyleTypes.DASH_DOT_DOT,value:a.BorderStyleTypes.DASH_DOT_DOT},{label:a.BorderStyleTypes.MEDIUM,value:a.BorderStyleTypes.MEDIUM},{label:a.BorderStyleTypes.MEDIUM_DASHED,value:a.BorderStyleTypes.MEDIUM_DASHED},{label:a.BorderStyleTypes.MEDIUM_DASH_DOT,value:a.BorderStyleTypes.MEDIUM_DASH_DOT},{label:a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT,value:a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT},{label:a.BorderStyleTypes.THICK,value:a.BorderStyleTypes.THICK}];function Gl(n){var d;const i=a.useDependency(E.ComponentManager),e=a.useDependency(m.BorderStyleManagerService),{onChange:t,value:r}=n;function o(c,u){t==null||t({...r,[u]:c})}function s(c){const u=i.get(c);return u&&_.jsx(u,{extend:{colorChannel1:"rgb(var(--primary-color))"}})}function l(c){c.stopPropagation()}return _.jsxs("section",{className:Be.uiPluginSheetsBorderPanel,children:[_.jsx("div",{className:Be.uiPluginSheetsBorderPanelPosition,children:Yl.map(c=>_.jsx("div",{className:e.getBorderInfo().type===c.value?`
13
13
  ${Be.uiPluginSheetsBorderPanelPositionItemActive}
14
14
  ${Be.uiPluginSheetsBorderPanelPositionItem}
15
15
  `:Be.uiPluginSheetsBorderPanelPositionItem,onClick:u=>{u.stopPropagation(),o(c.value,"type")},children:s(c.icon)},c.value))}),_.jsxs("div",{className:Be.uiPluginSheetsBorderPanelStyles,children:[_.jsx("div",{children:_.jsx(K.DropdownLegacy,{align:{offset:[0,18]},overlay:_.jsx("section",{className:Be.uiPluginSheetsBorderPanelBoard,onClick:l,children:_.jsx(K.ColorPicker,{onChange:c=>o(c,"color")})}),children:_.jsxs("a",{className:Be.uiPluginSheetsBorderPanelButton,onClick:l,children:[_.jsx(Nl,{extend:{colorChannel1:(d=r==null?void 0:r.color)!=null?d:"rgb(var(--primary-color))"}}),_.jsx("span",{className:Be.uiPluginSheetsBorderPanelMoreIcon,children:_.jsx(Mn,{})})]})})}),_.jsx("div",{children:_.jsx(K.DropdownLegacy,{align:{offset:[0,18]},overlay:_.jsx("section",{onClick:l,children:_.jsx(K.Menu,{children:Gg.map(c=>_.jsx(K.MenuItem,{eventKey:c.value.toString(),onClick:()=>o(c.value,"style"),children:_.jsx(Ia,{type:c.value})},c.value))})}),children:_.jsxs("a",{className:Be.uiPluginSheetsBorderPanelButton,onClick:l,children:[_.jsx(Ia,{type:a.BorderStyleTypes.THIN}),_.jsx("span",{className:Be.uiPluginSheetsBorderPanelMoreIcon,children:_.jsx(Mn,{})})]})})})]})]})}function Zl(n){var i,e,t="";if(typeof n=="string"||typeof n=="number")t+=n;else if(typeof n=="object")if(Array.isArray(n)){var r=n.length;for(i=0;i<r;i++)n[i]&&(e=Zl(n[i]))&&(t&&(t+=" "),t+=e)}else for(e in n)n[e]&&(t&&(t+=" "),t+=e);return t}function pe(){for(var n,i,e=0,t="",r=arguments.length;e<r;e++)(n=arguments[e])&&(i=Zl(n))&&(t&&(t+=" "),t+=i);return t}const Zg="univer-defined-name",Kg="univer-defined-name-overlay",qg="univer-defined-name-overlay-container",Qg="univer-defined-name-overlay-item",Jg="univer-defined-name-overlay-item-name",$g="univer-defined-name-overlay-item-name-for-sheet",eS="univer-defined-name-overlay-item-formula",tS="univer-defined-name-overlay-manager",nS="univer-defined-name-overlay-manager-title",rS="univer-defined-name-overlay-manager-content",iS="univer-defined-name-container",oS="univer-defined-name-container-scroll",sS="univer-defined-name-container-addButton",aS="univer-defined-name-container-addButton-text",lS="univer-defined-name-container-item",cS="univer-defined-name-container-item-name",dS="univer-defined-name-container-item-name-for-sheet",uS="univer-defined-name-container-item-formula-or-refString",hS="univer-defined-name-container-item-update",mS="univer-defined-name-container-item-delete",gS="univer-defined-name-container-item-show",SS="univer-defined-name-input",fS="univer-defined-name-input-formula-selector-text-wrap",pS="univer-defined-name-input-text-editor-container",vS="univer-defined-name-input-validation",CS="univer-defined-name-input-disable",we={definedName:Zg,definedNameOverlay:Kg,definedNameOverlayContainer:qg,definedNameOverlayItem:Qg,definedNameOverlayItemName:Jg,definedNameOverlayItemNameForSheet:$g,definedNameOverlayItemFormula:eS,definedNameOverlayManager:tS,definedNameOverlayManagerTitle:nS,definedNameOverlayManagerContent:rS,definedNameContainer:iS,definedNameContainerScroll:oS,definedNameContainerAddButton:sS,definedNameContainerAddButtonText:aS,definedNameContainerItem:lS,definedNameContainerItemName:cS,definedNameContainerItemNameForSheet:dS,definedNameContainerItemFormulaOrRefString:uS,definedNameContainerItemUpdate:hS,definedNameContainerItemDelete:mS,definedNameContainerItemShow:gS,definedNameInput:SS,definedNameInputFormulaSelectorTextWrap:fS,definedNameInputTextEditorContainer:pS,definedNameInputValidation:vS,definedNameInputDisable:CS},co={width:"100%"},ba=n=>{const{inputId:i,state:e=!1,type:t="range",confirm:r,cancel:o,name:s,formulaOrRefString:l,comment:d="",localSheetId:c=m.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,hidden:u=!1,id:h}=n,S=a.useDependency(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),f=a.useDependency(a.LocaleService),p=a.useDependency(G.IDefinedNamesService),v=a.useDependency(G.IFunctionService),C=a.useDependency(G.LexerTreeBuilder),I=a.useDependency(E.ComponentManager),b=V.useMemo(()=>I.get(ss),[]),T=V.useMemo(()=>I.get(Ti),[]);if(S==null)return;const M=V.useMemo(()=>S.getUnitId(),[]),y=V.useMemo(()=>S.getActiveSheet().getSheetId(),[]),[P,x]=V.useState(s),[A,N]=V.useState(l),[D,H]=V.useState(d),[W,k]=V.useState(c),[U,B]=V.useState(""),[F,L]=V.useState(t),[z,X]=V.useState(!0),Z=V.useRef({}),[re,Q]=V.useState(!1),oe=[{label:f.t("definedName.scopeWorkbook"),value:m.SCOPE_WORKBOOK_VALUE_DEFINED_NAME}],$=ie=>!G.isReferenceStrings(ie);V.useEffect(()=>{Q(!1)},[y]),V.useEffect(()=>{X(!0),x(s),H(d),k(c);let ie=l;l.substring(0,1)===G.operatorToken.EQUALS?L("formula"):$(l)?(L("formula"),ie=G.operatorToken.EQUALS+l):L("range"),N(ie),B("")},[e]),S.getSheetOrders().forEach(ie=>{const se=S.getSheetBySheetId(ie);oe.push({label:(se==null?void 0:se.getName())||"",value:ie})});const j=ie=>{N(ie)},Y=ie=>{N(ie||"")},q=()=>{if(P.length===0){B(f.t("definedName.nameEmpty"));return}if(p.getValueByName(M,P)!=null&&(h==null||h.length===0)){B(f.t("definedName.nameDuplicate"));return}if(!a.Tools.isValidParameter(P)||G.isReferenceStringWithEffectiveColumn(P)||!a.Tools.isStartValidPosition(P)&&!w.hasCJKText(P.substring(0,1))){B(f.t("definedName.nameInvalid"));return}if(S.getSheetOrders().map(Ce=>{var Ee;return((Ee=S.getSheetBySheetId(Ce))==null?void 0:Ee.getName())||""}).includes(P)){B(f.t("definedName.nameSheetConflict"));return}if(A.length===0){B(f.t("definedName.formulaOrRefStringEmpty"));return}if(!z){B(f.t("definedName.formulaOrRefStringInvalid"));return}if(v.hasExecutor(P.toUpperCase())){B(f.t("definedName.nameConflict"));return}const se=S.getActiveSheet().getName();r&&r({id:h||"",name:P,formulaOrRefString:C.convertRefersToAbsolute(A,a.AbsoluteRefType.ALL,a.AbsoluteRefType.ALL,se),comment:D,localSheetId:W})},ee=ie=>{const se=ie;se==="formula"?l[0]===G.operatorToken.EQUALS?N(l):N(`${G.operatorToken.EQUALS}`):l[0]===G.operatorToken.EQUALS?N(""):N(l),L(se)},de=V.useRef({}),[me,ce]=V.useState(!1);return E.useSidebarClick(ie=>{var Ce;const se=(Ce=Z.current)==null?void 0:Ce.handleOutClick;se&&se(ie,()=>Q(!1))}),E.useSidebarClick(ie=>{var Ce;const se=(Ce=de.current)==null?void 0:Ce.handleOutClick;se&&se(ie,()=>ce(!1))}),_.jsxs("div",{className:we.definedNameInput,style:{display:e?"block":"none"},children:[_.jsx("div",{children:_.jsx(K.Input,{placeholder:f.t("definedName.inputNamePlaceholder"),value:P,allowClear:!0,onChange:x,affixWrapperStyle:co})}),_.jsx("div",{children:_.jsxs(K.RadioGroup,{value:F,onChange:ee,children:[_.jsx(K.Radio,{value:"range",children:f.t("definedName.ratioRange")}),_.jsx(K.Radio,{value:"formula",children:f.t("definedName.ratioFormula")})]})}),F==="range"?b&&_.jsx(b,{unitId:M,subUnitId:y,initValue:A,onChange:j,isFocus:re,onFocus:()=>Q(!0),actions:Z.current,isSupportAcrossSheet:!0}):T&&_.jsx(T,{initValue:A,unitId:M,subUnitId:y,isFocus:me,isSupportAcrossSheet:!0,onChange:(ie="")=>{Y(ie||"")},onVerify:ie=>{X(ie)},onFocus:()=>ce(!0),actions:de.current}),_.jsx("div",{children:_.jsx(K.Select,{style:co,value:W,options:oe,onChange:k})}),_.jsx("div",{children:_.jsx(K.Input,{affixWrapperStyle:co,placeholder:f.t("definedName.inputCommentPlaceholder"),value:D,onChange:H})}),_.jsxs("div",{style:{display:U.length===0?"none":"flex"},className:we.definedNameInputValidation,children:[_.jsx("span",{children:U}),_.jsx(Ts,{})]}),_.jsxs("div",{children:[_.jsx(K.Button,{onClick:()=>{o&&o()},children:f.t("definedName.cancel")}),_.jsx(K.Button,{style:{marginLeft:15},type:"primary",onClick:q,children:f.t("definedName.confirm")})]})]})},Kl=()=>{const n=a.useDependency(a.ICommandService),e=a.useDependency(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),t=a.useDependency(a.LocaleService),r=a.useDependency(G.IDefinedNamesService),o=a.useDependency(m.SheetsSelectionsService);if(e==null)return;const s=e.getUnitId(),l=()=>{const D=r.getDefinedNameMap(s);return D?Array.from(Object.values(D)):[]},[d,c]=V.useState(!1),[u,h]=V.useState(l()),[g,S]=V.useState(null),[f,p]=V.useState();V.useEffect(()=>{const D=r.update$.subscribe(()=>{h(l())});return()=>{D.unsubscribe()}},[]);const v=D=>{const{name:H,formulaOrRefString:W,comment:k,localSheetId:U,hidden:B}=D;let F=D.id;if(F==null||F.length===0)F=a.Tools.generateRandomId(10),n.executeCommand(m.InsertDefinedNameCommand.id,{id:F,unitId:s,name:H,formulaOrRefString:W,comment:k,localSheetId:U,hidden:B});else{const L={id:F,unitId:s,name:H,formulaOrRefString:W,comment:k,localSheetId:U,hidden:B};n.executeCommand(m.SetDefinedNameCommand.id,L)}c(!1),S(null)},C=D=>{p(D)};function I(){p(null)}function b(D){const H=r.getValueById(s,D);n.executeCommand(m.RemoveDefinedNameCommand.id,{...H,unitId:s}),p(null)}const T=async D=>{const{formulaOrRefString:H,id:W}=D,k=r.getWorksheetByRef(s,H);if(!k)return;k.isSheetHidden()&&await n.executeCommand(m.SetWorksheetShowCommand.id,{unitId:s,subUnitId:k.getSheetId()}),r.focusRange(s,W)},M=()=>{const D=u.length+1,H=t.t("definedName.defaultName")+D;if(r.getValueByName(s,H)==null)return H;let W=D+1;for(;;){const k=t.t("definedName.defaultName")+W;if(r.getValueByName(s,k)==null)return k;W++}},y=()=>{var k;const D=(k=e.getActiveSheet())==null?void 0:k.getName();if(!D)return"";const H=o.getCurrentSelections();return H==null?"":H.map(U=>G.serializeRangeWithSheet(D,U.range)).join(",")},P=()=>{c(!1),S(null)},x=()=>{c(!0),S(null)},A=D=>{c(!1),S(D)},N=D=>{const H=e.getSheetBySheetId(D);return H==null?"":H.getName()};return _.jsx("div",{className:we.definedNameContainer,children:_.jsxs("div",{className:we.definedNameContainerScroll,children:[_.jsxs("div",{children:[_.jsxs("div",{onClick:x,className:we.definedNameContainerAddButton,style:{display:d?"none":"flex"},children:[_.jsx(ws,{}),_.jsx("span",{className:we.definedNameContainerAddButtonText,children:t.t("definedName.addButton")})]}),d&&_.jsx(ba,{confirm:v,cancel:P,state:d,inputId:"insertDefinedName",name:M(),formulaOrRefString:y()})]},"insertDefinedName"),u.map((D,H)=>_.jsxs("div",{children:[_.jsxs("div",{onClick:()=>{T(D)},className:we.definedNameContainerItem,style:{display:D.id===g?"none":"flex"},children:[_.jsxs("div",{title:D.comment,children:[_.jsxs("div",{className:we.definedNameContainerItemName,children:[D.name,_.jsx("span",{className:we.definedNameContainerItemNameForSheet,children:D.localSheetId===m.SCOPE_WORKBOOK_VALUE_DEFINED_NAME||D.localSheetId==null?"":N(D.localSheetId)})]}),_.jsx("div",{className:we.definedNameContainerItemFormulaOrRefString,children:D.formulaOrRefString})]}),_.jsx(K.Tooltip,{title:t.t("definedName.updateButton"),placement:"top",children:_.jsx("div",{className:pe(we.definedNameContainerItemUpdate,we.definedNameContainerItemShow),onClick:()=>{A(D.id)},children:_.jsx(mt,{})})}),_.jsx(K.Tooltip,{title:t.t("definedName.deleteButton"),placement:"top",children:_.jsx("div",{className:pe(we.definedNameContainerItemDelete,we.definedNameContainerItemShow),onClick:()=>{C(D.id)},children:_.jsx(Wi,{})})})]}),_.jsx(K.Confirm,{visible:f===D.id,onClose:I,onConfirm:()=>{b(D.id)},children:t.t("definedName.deleteConfirmText")}),D.id===g&&_.jsx(ba,{confirm:v,cancel:P,state:D.id===g,id:D.id,inputId:D.id+H,name:D.name,formulaOrRefString:D.formulaOrRefString,comment:D.comment,localSheetId:D.localSheetId})]},H))]})})},_S="univer-count-bar",IS={countBar:_S},bS=[50,75,100,125,150,175,200,400];function RS(){const n=a.useDependency(a.ICommandService),i=a.useDependency(a.IUniverInstanceService),e=Je(),t=a.useDependency(Se),r=a.useObservable(t.visible$),o=V.useCallback(()=>{if(!e)return 100;const u=e.getActiveSheet(),h=u&&u.getZoomRatio()*100||100;return Math.round(h)},[e]),[s,l]=V.useState(()=>o());V.useEffect(()=>(l(o()),n.onCommandExecuted(h=>{if(h.id===Le.id||h.id===m.SetWorksheetActiveOperation.id){const g=o();l(g)}}).dispose),[n,o]);function d(u){l(u);const h=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),g=h==null?void 0:h.getActiveSheet();if(g==null)return;const S=u/100;n.executeCommand(Nn.id,{unitId:h.getUnitId(),subUnitId:g.getSheetId(),zoomRatio:S})}const c=(r==null?void 0:r.visible)&&(r.unitId===(e==null?void 0:e.getUnitId())||r.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);return _.jsx(K.Slider,{disabled:c,min:Ao[0],value:s,shortcuts:bS,onChange:d})}function ES(n){return _.jsx("section",{className:IS.countBar,children:_.jsx(RS,{})})}function ql(n,i){const e=a.useDependency(Se);return V.useMemo(()=>({keyCodes:[{keyCode:E.KeyCode.ENTER},{keyCode:E.KeyCode.ESC},{keyCode:E.KeyCode.TAB}],handler:r=>{(r===E.KeyCode.ENTER||r===E.KeyCode.ESC||r===E.KeyCode.TAB)&&(e.disableForceKeepVisible(),e.changeVisible({visible:!1,eventType:w.DeviceInputEventType.Keyboard,keycode:r,unitId:i}))}}),[e,i])}const TS="univer-editor-container",wS="univer-editor-input",yS="univer-sheet-embedding-formula-editor-wrap",Ra={editorContainer:TS,editorInput:wS,sheetEmbeddingFormulaEditorWrap:yS},si=-1e3,Ea={width:0,height:0,top:si,left:si},MS=()=>{const[n,i]=V.useState({...Ea}),e=a.useDependency(hr),t=a.useDependency(J.IEditorService),r=a.useDependency(a.IContextService),o=a.useDependency(E.ComponentManager),s=a.useDependency(Se),l=E.useObservable(s.visible$),d=a.useDependency(a.ICommandService),c=V.useRef(0),u=E.useObservable(()=>r.subscribeContextValue$(E.DISABLE_AUTO_FOCUS_KEY),!1,void 0,[r,E.DISABLE_AUTO_FOCUS_KEY]),h=o.get(Ti),g=s.getEditLocation();V.useEffect(()=>{const v=e.state$.subscribe(C=>{if(C==null)return;const{startX:I=si,startY:b=si,endX:T=0,endY:M=0,show:y=!1}=C;if(!y)i({...Ea});else{i({width:T-I,height:M-b,left:I,top:b});const P=t.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(P==null)return;const{left:x,top:A,width:N,height:D}=P.getBoundingClientRect();e.setRect({left:x,top:A,width:N,height:D})}});return()=>{v.unsubscribe()}},[]),V.useEffect(()=>{u||e.setFocus(!0)},[u,n]);const S=E.useEvent(()=>{s.isVisible().visible&&s.changeVisible({visible:!1,eventType:w.DeviceInputEventType.PointerUp,unitId:g.unitId})});E.useSidebarClick(S);const f=ql(c,g==null?void 0:g.unitId),p=E.useEvent((v,C)=>{d.executeCommand(Xt.id,{keycode:v,visible:!1,eventType:w.DeviceInputEventType.Keyboard,isShift:C===E.MetaKeys.SHIFT||C===(E.MetaKeys.CTRL_COMMAND|E.MetaKeys.SHIFT),unitId:g==null?void 0:g.unitId})});return _.jsx("div",{className:Ra.editorContainer,style:{left:n.left,top:n.top,width:n.width,height:n.height},children:h&&_.jsx(h,{editorId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,className:Ra.editorInput,initValue:"",onChange:()=>{},isFocus:l==null?void 0:l.visible,unitId:g==null?void 0:g.unitId,subUnitId:g==null?void 0:g.sheetId,keyboradEventConfig:f,onMoveInEditor:p,isSupportAcrossSheet:!0,resetSelectionOnBlur:!1,isSingle:!1,autoScrollbar:!1,onFormulaSelectingChange:v=>{c.current=v,v?s.enableForceKeepVisible():s.disableForceKeepVisible()},disableSelectionOnClick:!0,disableContextMenu:!1})})};class PS{constructor(){R(this,"_position",null);R(this,"_position$",new O.BehaviorSubject(null));R(this,"position$",this._position$.asObservable());R(this,"_focus",!1);R(this,"_focus$",new O.BehaviorSubject(this._focus));R(this,"focus$",this._focus$.asObservable());R(this,"_fxBtnClick$",new O.Subject);R(this,"fxBtnClick$",this._fxBtnClick$.asObservable());R(this,"_foldBtnStatus$",new O.Subject);R(this,"foldBtnStatus$",this._foldBtnStatus$.asObservable())}dispose(){this._position$.complete(),this._focus$.complete(),this._position=null,this._focus=!1}setPosition(i){this._position=i,this._refresh(i)}getPosition(){return this._position}setFocus(i=!1){this._focus=i,this._focus$.next(i)}handleFxBtnClick(i){this._fxBtnClick$.next(i)}handleFoldBtnClick(i){this._foldBtnStatus$.next(i)}_refresh(i){this._position$.next(i)}}const Nr=a.createIdentifier("univer.sheet-formula-editor-manager.service");function OS(n){const i=a.useDependency(a.ICommandService),e=a.useDependency(a.LocaleService),t=a.useDependency(G.IDefinedNamesService),r=a.useDependency(a.IUniverInstanceService),o=a.useDependency(E.ISidebarService),l=r.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId(),d=()=>{const S=t.getDefinedNameMap(l);return S?Array.from(Object.values(S)):[]},[c,u]=V.useState(d());V.useEffect(()=>{const S=t.update$.subscribe(()=>{u(d())});return()=>{S.unsubscribe()}},[]),V.useEffect(()=>{const S=o.sidebarOptions$.subscribe(f=>{f.id===rr&&(f.visible||setTimeout(()=>{o.sidebarOptions$.next({visible:!1})}))});return()=>{S.unsubscribe()}},[]);const h=()=>{i.executeCommand(Li.id,{value:"open"})},g=async S=>{const{formulaOrRefString:f,id:p}=S,v=t.getWorksheetByRef(l,f);if(!v)return;v.isSheetHidden()&&await i.executeCommand(m.SetWorksheetShowCommand.id,{unitId:l,subUnitId:v.getSheetId()}),t.focusRange(l,p)};return _.jsxs("div",{className:"univer-w-[300px]",children:[_.jsx("ul",{className:`