@univerjs/sheets-ui 0.6.0-nightly.202502171606 → 0.6.0-nightly.202502181606

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/umd/index.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(y,Q){typeof exports=="object"&&typeof module<"u"?Q(exports,require("@univerjs/docs-ui"),require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("react"),require("rxjs"),require("@univerjs/sheets"),require("@univerjs/docs"),require("@univerjs/engine-formula"),require("@univerjs/engine-numfmt"),require("@univerjs/design"),require("react/jsx-runtime"),require("@univerjs/telemetry"),require("rxjs/operators")):typeof define=="function"&&define.amd?define(["exports","@univerjs/docs-ui","@univerjs/core","@univerjs/engine-render","@univerjs/ui","react","rxjs","@univerjs/sheets","@univerjs/docs","@univerjs/engine-formula","@univerjs/engine-numfmt","@univerjs/design","react/jsx-runtime","@univerjs/telemetry","rxjs/operators"],Q):(y=typeof globalThis<"u"?globalThis:y||self,Q(y.UniverSheetsUi={},y.UniverDocsUi,y.UniverCore,y.UniverEngineRender,y.UniverUi,y.React,y.rxjs,y.UniverSheets,y.UniverDocs,y.UniverEngineFormula,y.UniverEngineNumfmt,y.UniverDesign,y.React,y.UniverTelemetry,y.rxjs.operators))})(this,function(y,Q,a,P,_,L,A,m,Ee,q,vd,K,I,_d,Ys){"use strict";var lv=Object.defineProperty;var cv=(y,Q,a)=>Q in y?lv(y,Q,{enumerable:!0,configurable:!0,writable:!0,value:a}):y[Q]=a;var T=(y,Q,a)=>cv(y,typeof Q!="symbol"?Q+"":Q,a);function ki(i,o){if(i==null)return;const e=o.getRenderById(i);if(e==null)return;const{mainComponent:t,scene:n,engine:r,components:s}=e,l=t,c=s.get(Q.DOCS_VIEW_KEY.BACKGROUND);return{document:l,docBackground:c,scene:n,engine:r}}const jo=[10,400],Go="RANGE_SELECTOR_COMPONENT_KEY",Vi="EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY";var he=(i=>(i.MAIN="__SpreadsheetRender__",i.ROW="__SpreadsheetRowHeader__",i.COLUMN="__SpreadsheetColumnHeader__",i.LEFT_TOP="__SpreadsheetLeftTopPlaceholder__",i))(he||{});const js=0,Wi=1,St=10,Id=11,Gs=12,Li={id:"sheet.command.set-row-header-width",type:a.CommandType.COMMAND,handler:async(i,o)=>{if(!o)return!1;const e=i.get(P.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:n,size:r}=o,s=e.getRenderById(t);if(s){e.getRenderById(t).with(y.SheetSkeletonManagerService).setRowHeaderSize(s,n,r);const{components:c}=s,d=c.get(he.ROW);d&&d.setCustomHeader({headerStyle:{size:r}})}return!0}},Ui={id:"sheet.command.set-col-header-height",type:a.CommandType.COMMAND,handler:async(i,o)=>{if(!o)return!1;const e=i.get(P.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:n,size:r}=o,s=e.getRenderById(t);if(s){e.getRenderById(t).with(y.SheetSkeletonManagerService).setColumnHeaderSize(s,n,r);const{components:c}=s,d=c.get(he.COLUMN);d&&d.setCustomHeader({headerStyle:{size:r}})}return!0}},Zo=a.createInterceptorKey("rangeMovePermissionCheck"),Ko=a.createInterceptorKey("rangeFillPermissionCheck");var qo=(i=>(i[i.FORMULA_EDITOR_SHOW=100]="FORMULA_EDITOR_SHOW",i[i.MARK_SELECTION=1e4]="MARK_SELECTION",i))(qo||{});function gt(i){const o=i.getCurrentTheme(),e=new a.ColorKit(o.primaryColor).setAlpha(.07).toRgbString();return{strokeWidth:1,stroke:o.primaryColor,fill:e,widgets:{},widgetSize:6,widgetStrokeWidth:1,widgetStroke:o.colorWhite,autofillSize:6,autofillStrokeWidth:1,autofillStroke:o.colorWhite,rowHeaderFill:e,rowHeaderStroke:o.primaryColor,rowHeaderStrokeWidth:1,columnHeaderFill:e,columnHeaderStroke:o.primaryColor,columnHeaderStrokeWidth:1,expandCornerSize:40}}class bd{constructor(){T(this,"_startColumn",-1);T(this,"_startRow",-1);T(this,"_endColumn",-1);T(this,"_endRow",-1);T(this,"_startX",0);T(this,"_startY",0);T(this,"_endX",0);T(this,"_endY",0);T(this,"_primary");T(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(o){const{startColumn:e,startRow:t,endColumn:n,endRow:r}=this,{startColumn:s,startRow:l,endColumn:c,endRow:d}=o;return e===s&&t===l&&n===c&&r===d}isInclude(o){const{startColumn:e,startRow:t,endColumn:n,endRow:r}=this,{startColumn:s,startRow:l,endColumn:c,endRow:d}=o;return!(c<e||s>n||l>r||d<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(o){this._rangeType=o}getValue(){return{rangeWithCoord:this.getRange(),primaryWithCoord:this._primary}}setValue(o,e){const{startColumn:t,startRow:n,endColumn:r,endRow:s,startX:l,startY:c,endX:d,endY:u,rangeType:h}=o;this._startColumn=t,this._startRow=n,this._endColumn=r,this._endRow=s,this._startX=l,this._startY=c,this._endX=d,this._endY=u,h!==void 0&&(this._rangeType=h),e!==void 0&&this.setCurrentCell(e)}setCurrentCell(o){this._primary=o}clearCurrentCell(){this._primary=null}}function rn(i,o){const{startRow:e,startColumn:t,endRow:n,endColumn:r,rangeType:s}=o,l=n<e?n:e,c=n<e?e:n,d=r<t?r:t,u=r<t?t:r,h=i.getNoMergeCellWithCoordByIndex(l,d),S=i.getNoMergeCellWithCoordByIndex(c,u);return{startRow:e,startColumn:t,endRow:n,endColumn:r,rangeType:s,startY:(h==null?void 0:h.startY)||0,endY:(S==null?void 0:S.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(S==null?void 0:S.endX)||0}}function Me(i,o){const{range:e,primary:t,style:n}=i,r=rn(o,e),s=t&&xn(o,t);return{rangeWithCoord:r,primaryWithCoord:s,style:n}}function xn(i,o){const{actualRow:e,actualColumn:t,isMerged:n,isMergedMainCell:r,startRow:s,startColumn:l,endRow:c,endColumn:d}=o,u=i.getNoMergeCellWithCoordByIndex(e,t),h=i.getNoMergeCellWithCoordByIndex(s,l),S=i.getNoMergeCellWithCoordByIndex(c,d);return{actualRow:e,actualColumn:t,isMerged:n,isMergedMainCell:r,startX:u.startX,startY:u.startY,endX:u.endX,endY:u.endY,mergeInfo:{startRow:s,startColumn:l,endRow:c,endColumn:d,startY:(h==null?void 0:h.startY)||0,endY:(S==null?void 0:S.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(S==null?void 0:S.endX)||0}}}const Zs="__SpreadsheetHelperSelectionTempRect",Ed=35;class Ks{constructor(o,e){T(this,"_startOffsetX",0);T(this,"_startOffsetY",0);T(this,"_relativeSelectionPositionRow",0);T(this,"_relativeSelectionPositionColumn",0);T(this,"_relativeSelectionRowLength",0);T(this,"_relativeSelectionColumnLength",0);T(this,"_scenePointerMoveSub");T(this,"_scenePointerUpSub");T(this,"_helperSelection");T(this,"_scrollTimer");T(this,"_activeViewport");T(this,"_targetSelection",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});T(this,"_isInMergeState",!1);T(this,"_fillControlColors",[]);T(this,"_skeleton");T(this,"_scene");T(this,"_themeService");T(this,"_injector");T(this,"_selectionHooks");this._control=o,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 o,e;(o=this._scrollTimer)==null||o.dispose(),this._fillControlColors=[],this._clearObserverEvent(),(e=this._helperSelection)==null||e.dispose()}_getFreeze(){var t,n;return(n=(t=this._injector.get(P.IRenderManagerService).withCurrentTypeOfUnit(a.UniverInstanceType.UNIVER_SHEET,y.SheetSkeletonManagerService))==null?void 0:t.getCurrentParam())==null?void 0:n.skeleton.getWorksheetConfig().freeze}_isSelectionInViewport(o,e){const t=this._getFreeze()||{startRow:-1,startColumn:-1,xSplit:0,ySplit:0};switch(e.viewportKey){case P.SHEET_VIEWPORT_KEY.VIEW_MAIN:return o.endRow>=t.startRow&&o.endColumn>=t.startColumn;case P.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP:case P.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT:return o.endColumn>=t.startColumn&&o.startRow<t.startRow;case P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT:case P.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM:return o.endRow>=t.startRow&&o.startColumn<t.startColumn;case P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP:case P.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT:case P.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP:case P.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP:return o.startRow<t.startRow&&o.startColumn<t.startColumn}}_clearObserverEvent(){var o,e;(o=this._scenePointerMoveSub)==null||o.unsubscribe(),(e=this._scenePointerUpSub)==null||e.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null}_initialControl(){const{leftControl:o,rightControl:e,topControl:t,bottomControl:n}=this._control;[o,e,t,n].forEach(r=>{r.onPointerEnter$.subscribeEvent(()=>{var l;((l=this._injector.get(Ce,a.Quantity.OPTIONAL))==null?void 0:l.interceptor.fetchThroughInterceptors(Zo)(!1,null))!==!1&&r.setCursor(P.CURSOR_TYPE.MOVE)}),r.onPointerLeave$.subscribeEvent(()=>{r.resetCursor()}),r.onPointerDown$.subscribeEvent(this._controlPointerDownHandler.bind(this))})}_controlMoving(o,e){var D;const t=this._scene,n=t.getScrollXYInfoByViewport(P.Vector2.FromArray([o,e])),{scaleX:r,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(o,e,r,s,n),{row:c,column:d}=l,u=this._skeleton.getRowCount()-1,h=this._skeleton.getColumnCount()-1;let S=Math.max(0,c+this._relativeSelectionPositionRow),g=S+this._relativeSelectionRowLength;g>u&&(g=u,g-S<this._relativeSelectionRowLength&&(S=g-this._relativeSelectionRowLength));let f=Math.max(0,d+this._relativeSelectionPositionColumn),p=f+this._relativeSelectionColumnLength;p>h&&(p=h,p-f<this._relativeSelectionColumnLength&&(f=p-this._relativeSelectionColumnLength));const C=this._skeleton.worksheet.getCellInfoInMergeData(S,f),b=Me({range:{startRow:S,endRow:g,startColumn:f,endColumn:p},primary:C,style:null},this._skeleton),E=this._skeleton.getNoMergeCellWithCoordByIndex(S,f),w=this._skeleton.getNoMergeCellWithCoordByIndex(g,p),R=(E==null?void 0:E.startY)||0,M=(w==null?void 0:w.endY)||0,O=(E==null?void 0:E.startX)||0,N=(w==null?void 0:w.endX)||0;(D=this._helperSelection)==null||D.transformByState({left:O,top:R,width:N-O,height:M-R}),this._targetSelection={...b.rangeWithCoord},this._control.selectionMoving$.next(b.rangeWithCoord)}_controlPointerDownHandler(o){const{offsetX:e,offsetY:t}=o,n=this._scene,r=n.getCoordRelativeToViewport(P.Vector2.FromArray([e,t])),{x:s,y:l}=r,c=n.getScrollXYInfoByViewport(r),{scaleX:d,scaleY:u}=n.getAncestorScale(),h=this._skeleton.getCellIndexByOffset(s,l,d,u,c);this._startOffsetX=s,this._startOffsetY=l;const{row:S,column:g}=h,{startRow:f,startColumn:p,endRow:C,endColumn:v}=this._control.model;let b=0,E=0;S<f?b-=1:S>C&&(b+=1),g<p?E-=1:g>v&&(E+=1),this._relativeSelectionPositionRow=f-S+b,this._relativeSelectionPositionColumn=p-g+E,this._relativeSelectionRowLength=C-f,this._relativeSelectionColumnLength=v-p;const w=this._control.currentStyle,R=this._getScale();this.isHelperSelection&&(this._helperSelection=new P.Rect(Zs,{stroke:w.stroke,strokeWidth:w.strokeWidth/R}),n.addObject(this._helperSelection));const M=n.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN),O=P.ScrollTimer.create(n);this._scrollTimer=O,O.startScroll(s,l,M),n.disableObjectsEvent(),this._scenePointerMoveSub=n.onPointerMove$.subscribeEvent(N=>{var W;const{offsetX:D,offsetY:H}=N;if(((W=this._injector.get(Ce,a.Quantity.OPTIONAL))==null?void 0:W.interceptor.fetchThroughInterceptors(Zo)(!1,null))===!1)return;const{x:V,y:U}=n.getCoordRelativeToViewport(P.Vector2.FromArray([D,H]));this._controlMoving(V,U),n.setCursor(P.CURSOR_TYPE.MOVE),O.scrolling(V,U,()=>{this._controlMoving(V,U)})}),this._scenePointerUpSub=n.onPointerUp$.subscribeEvent(()=>{var D,H,k,V;(D=this._helperSelection)==null||D.dispose();const N=this._scene;N.resetCursor(),this._clearObserverEvent(),N.enableObjectsEvent(),(H=this._scrollTimer)==null||H.dispose(),this._control.selectionMoveEnd$.next(this._targetSelection),(V=(k=this._selectionHooks).selectionMoveEnd)==null||V.call(k)})}_initialWidget(){const{topLeftWidget:o,topCenterWidget:e,topRightWidget:t,middleLeftWidget:n,middleRightWidget:r,bottomLeftWidget:s,bottomCenterWidget:l,bottomRightWidget:c}=this._control,d=[P.CURSOR_TYPE.NORTH_WEST_RESIZE,P.CURSOR_TYPE.NORTH_RESIZE,P.CURSOR_TYPE.NORTH_EAST_RESIZE,P.CURSOR_TYPE.WEST_RESIZE,P.CURSOR_TYPE.EAST_RESIZE,P.CURSOR_TYPE.SOUTH_WEST_RESIZE,P.CURSOR_TYPE.SOUTH_RESIZE,P.CURSOR_TYPE.SOUTH_EAST_RESIZE];[o,e,t,n,r,s,l,c].forEach((u,h)=>{u.onPointerEnter$.subscribeEvent(()=>{u.setCursor(d[h])}),u.onPointerLeave$.subscribeEvent(()=>{u.resetCursor()}),u.onPointerDown$.subscribeEvent(S=>{this._widgetPointerDownEvent(S,d[h])})})}_widgetPointerDownEvent(o,e){const t=this._scene,{offsetX:n,offsetY:r}=o,s=t.getCoordRelativeToViewport(P.Vector2.FromArray([n,r])),{x:l,y:c}=s;this._startOffsetX=n,this._startOffsetY=r;const{startRow:d,startColumn:u,endRow:h,endColumn:S}=this._control.model,g=Math.min(d,h),f=Math.min(u,S),p=Math.max(d,h),C=Math.max(u,S);this._relativeSelectionPositionRow=g,this._relativeSelectionPositionColumn=f,this._relativeSelectionRowLength=p-g,this._relativeSelectionColumnLength=C-f,e===P.CURSOR_TYPE.NORTH_WEST_RESIZE?(this._relativeSelectionPositionRow=p,this._relativeSelectionPositionColumn=C):e===P.CURSOR_TYPE.NORTH_RESIZE?this._relativeSelectionPositionRow=p:e===P.CURSOR_TYPE.NORTH_EAST_RESIZE?this._relativeSelectionPositionRow=p:e===P.CURSOR_TYPE.WEST_RESIZE?this._relativeSelectionPositionColumn=C:e===P.CURSOR_TYPE.SOUTH_WEST_RESIZE?this._relativeSelectionPositionColumn=C:e===P.CURSOR_TYPE.SOUTH_RESIZE&&(this._relativeSelectionPositionRow=g);const v=P.ScrollTimer.create(t),b=t.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN);v.startScroll(l,c,b),this._scrollTimer=v,t.disableObjectsEvent(),this._scenePointerMoveSub=t.onPointerMove$.subscribeEvent(E=>{const{offsetX:w,offsetY:R}=E,{x:M,y:O}=t.getCoordRelativeToViewport(P.Vector2.FromArray([w,R]));this._widgetMoving(M,O,e),t.setCursor(e),v.scrolling(M,O,()=>{this._widgetMoving(M,O,e)})}),this._scenePointerUpSub=t.onPointerUp$.subscribeEvent(()=>{var w,R,M;const E=this._scene;E.resetCursor(),this._clearObserverEvent(),E.enableObjectsEvent(),(w=this._scrollTimer)==null||w.dispose(),this._control.selectionScaled$.next(this._targetSelection),(M=(R=this._selectionHooks).selectionMoveEnd)==null||M.call(R)})}_widgetMoving(o,e,t){const n=this._scene,r=n.getScrollXYInfoByViewport(P.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:s,scaleY:l}=n.getAncestorScale(),c=this._skeleton.getCellIndexByOffset(o,e,s,l,r),{row:d,column:u}=c;let h=this._relativeSelectionPositionRow,S=this._relativeSelectionPositionColumn,g=d,f=u;t===P.CURSOR_TYPE.NORTH_WEST_RESIZE?(h=d,S=u,g=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn):t===P.CURSOR_TYPE.NORTH_RESIZE?(h=d,S=this._relativeSelectionPositionColumn,g=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength):t===P.CURSOR_TYPE.NORTH_EAST_RESIZE?(h=d,S=this._relativeSelectionPositionColumn,g=this._relativeSelectionPositionRow,f=u):t===P.CURSOR_TYPE.WEST_RESIZE?(h=this._relativeSelectionPositionRow,S=u,g=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,f=this._relativeSelectionPositionColumn):t===P.CURSOR_TYPE.EAST_RESIZE?g=this._relativeSelectionPositionRow+this._relativeSelectionRowLength:t===P.CURSOR_TYPE.SOUTH_WEST_RESIZE?(h=this._relativeSelectionPositionRow,S=u,g=d,f=this._relativeSelectionPositionColumn):t===P.CURSOR_TYPE.SOUTH_RESIZE&&(h=this._relativeSelectionPositionRow,S=this._relativeSelectionPositionColumn,g=d,f=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength);const p=this._swapPositions(h,S,g,f),C=this._skeleton.getCellWithMergeInfoByIndex(h,S),b=Me({range:p,primary:C,style:null},this._skeleton);this._targetSelection={...b.rangeWithCoord},this._control.updateRangeBySelectionWithCoord(b),this._control.selectionScaling$.next(this._targetSelection)}_initialAutoFill(){const{fillControl:o}=this._control;o.onPointerEnter$.subscribeEvent(e=>{this._injector.get(Ce).interceptor.fetchThroughInterceptors(Ko)(!1,{x:e.offsetX,y:e.offsetY,skeleton:this._skeleton,scene:this._scene})&&o.setCursor(P.CURSOR_TYPE.CROSSHAIR)}),o.onPointerLeave$.subscribeEvent(()=>{o.resetCursor()}),o.onPointerDown$.subscribeEvent(this._autoFillForPointerdown.bind(this))}_autoFillMoving(o,e){var H,k,V;const t=this._scene,n=t.getViewportScrollXY(this._activeViewport),{scaleX:r,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(o,e,r,s,n),{row:c,column:d}=l,u=t.getCoordRelativeToViewport(P.Vector2.FromArray([o,e])),h=this._skeleton.getRowCount()-1,S=this._skeleton.getColumnCount()-1;let g=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn,p=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,C=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength,v=!1,b=!0;if((d<f||d>C)&&c>=g&&c<=p){const U=this._fillRuler(d,f,C,this._relativeSelectionColumnLength,S);f=U.startRowOrColumn,C=U.endRowOrColumn,v=U.isLighten,b=!1}else if((c<g||c>p)&&d>=f&&d<=C){const U=this._fillRuler(c,g,p,this._relativeSelectionRowLength,h);g=U.startRowOrColumn,p=U.endRowOrColumn,v=U.isLighten}else if(Math.abs(this._startOffsetX-u.x-n.x)/2>Math.abs(this._startOffsetY-u.y-n.y)){const U=this._fillRuler(d,f,C,this._relativeSelectionColumnLength,S);f=U.startRowOrColumn,C=U.endRowOrColumn,v=U.isLighten,b=!1}else{const U=this._fillRuler(c,g,p,this._relativeSelectionRowLength,h);g=U.startRowOrColumn,p=U.endRowOrColumn,v=U.isLighten}const E=this._skeleton.getNoMergeCellWithCoordByIndex(g,f),w=this._skeleton.getNoMergeCellWithCoordByIndex(p,C),R=(E==null?void 0:E.startY)||0,M=(w==null?void 0:w.endY)||0,O=(E==null?void 0:E.startX)||0,N=(w==null?void 0:w.endX)||0;v?this._controlHandler((U,W)=>{const B=new a.ColorKit(this._fillControlColors[W]).lighten(Ed).toRgbString();U.setProps({fill:B})}):this._controlHandler((U,W)=>{U.setProps({fill:this._fillControlColors[W]})});const D=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();g===p&&b===!0||f===C&&b===!1?(H=this._helperSelection)==null||H.hide():((k=this._helperSelection)==null||k.transformByState({left:O-D/2,top:R-D/2,width:N-O,height:M-R}),(V=this._helperSelection)==null||V.show()),this._targetSelection={startY:R,endY:M,startX:O,endX:N,startRow:g,endRow:p,startColumn:f,endColumn:C},this._control.selectionFilling$.next(this._targetSelection)}_autoFillForPointerdown(o){const{offsetX:e,offsetY:t}=o,n=this._scene,r=n.getCoordRelativeToViewport(P.Vector2.FromArray([e,t])),{x:s,y:l}=r;this._startOffsetX=s,this._startOffsetY=l;const{startRow:c,startColumn:d,endRow:u,endColumn:h}=this._control.model;this._isInMergeState=this._hasMergeInRange(c,d,u,h),this._relativeSelectionPositionRow=c,this._relativeSelectionPositionColumn=d,this._relativeSelectionRowLength=u-c,this._relativeSelectionColumnLength=h-d;const S=this._control.currentStyle;let g=S==null?void 0:S.stroke,f=S==null?void 0:S.strokeWidth;const p=gt(this._themeService);g==null&&(g=p.stroke),f==null&&(f=p.strokeWidth);const C=this._getScale();f/=C;const v=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/C,b=new a.ColorKit(g).darken(2).toRgbString();this.isHelperSelection&&(this._helperSelection=new P.Rect(Zs,{stroke:b,strokeWidth:f+v/2}),n.addObject(this._helperSelection)),this._activeViewport=n.getActiveViewportByCoord(P.Vector2.FromArray([e,t]));const E=n.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN),w=P.ScrollTimer.create(n,this._activeViewport.viewportKey===P.SHEET_VIEWPORT_KEY.VIEW_MAIN?P.ScrollTimerType.ALL:P.ScrollTimerType.NONE);w.startScroll(s,l,E),this._scrollTimer=w,n.disableObjectsEvent(),this._controlHandler(R=>{this._fillControlColors.push(R.fill)}),this._scenePointerMoveSub=n.onPointerMove$.subscribeEvent(R=>{var U;const{offsetX:M,offsetY:O}=R,N=n.getActiveViewportByCoord(P.Vector2.FromArray([M,O]));if(!this._injector.get(Ce).interceptor.fetchThroughInterceptors(Ko)(!1,{x:o.offsetX,y:o.offsetY,skeleton:this._skeleton,scene:this._scene}))return;const{x:H,y:k}=n.getCoordRelativeToViewport(P.Vector2.FromArray([M,O]));this._autoFillMoving(H,k),n.setCursor(P.CURSOR_TYPE.CROSSHAIR);const V=this._targetSelection;if(E&&N&&((U=this._activeViewport)==null?void 0:U.viewportKey)!==(N==null?void 0:N.viewportKey)){let W;V.startRow!==c?(w.scrollTimerType=P.ScrollTimerType.Y,W={...V,endRow:V.startRow}):V.endRow!==u?(w.scrollTimerType=P.ScrollTimerType.Y,W={...V,startRow:V.endRow}):V.startColumn!==d?(w.scrollTimerType=P.ScrollTimerType.X,W={...V,endColumn:V.startColumn}):(w.scrollTimerType=P.ScrollTimerType.X,W={...V,startColumn:V.endColumn}),this._isSelectionInViewport(W,N)&&(E.scrollToBarPos({x:w.scrollTimerType===P.ScrollTimerType.X?0:void 0,y:w.scrollTimerType===P.ScrollTimerType.Y?0:void 0}),this._activeViewport=N)}w.scrolling(H,k,()=>{this._autoFillMoving(H,k)})}),this._scenePointerUpSub=n.onPointerUp$.subscribeEvent(()=>{var M,O;(M=this._helperSelection)==null||M.dispose();const R=this._scene;R.resetCursor(),this._clearObserverEvent(),R.enableObjectsEvent(),(O=this._scrollTimer)==null||O.dispose(),this._control.refreshSelectionFilled(this._targetSelection),this._isInMergeState=!1,this._controlHandler((N,D)=>{N.setProps({fill:this._fillControlColors[D]})}),this._fillControlColors=[]})}_hasMergeInRange(o,e,t,n){return this._skeleton.worksheet.getMergedCellRange(o,e,t,n).length>0}_swapPositions(o,e,t,n){const r=Math.min(o,t),s=Math.min(e,n),l=Math.max(o,t),c=Math.max(e,n);return{startRow:r,startColumn:s,endRow:l,endColumn:c}}_controlHandler(o){const{leftControl:e,rightControl:t,topControl:n,bottomControl:r,backgroundControlTop:s,backgroundControlMiddleLeft:l,backgroundControlMiddleRight:c,backgroundControlBottom:d,fillControl:u}=this._control,h=[e,t,n,r,s,l,c,d,u];for(let S=0,g=h.length;S<g;S++){const f=h[S];o(f,S)}}_fillRuler(o,e,t,n,r){let s=!1;if(o<e)if(this._isInMergeState&&o<e){const l=e-o,c=n+1,d=Math.ceil(l/c);let u=e-d*c;u<0&&(u=e-(d-1)*c),e=u}else e=o;else if(o>=e&&o<=t)s=!0,this._isInMergeState||(t=o);else if(this._isInMergeState&&o>t){const l=o-t,c=n+1,d=Math.ceil(l/c);let u=t+d*c;u>r&&(u=t+(d-1)*c),t=u}else t=o;return{rowOrColumn:o,startRowOrColumn:e,endRowOrColumn:t,isLighten:s}}_getScale(){const{scaleX:o,scaleY:e}=this._scene.getAncestorScale();return Math.max(o,e)}}var Qo=(i=>(i.Selection="__SpreadsheetSelectionShape__",i.top="__SpreadsheetSelectionTopControl__",i.bottom="__SpreadsheetSelectionBottomControl__",i.left="__SpreadsheetSelectionShapeLeftControl__",i.right="__SpreadsheetSelectionShapeRightControl__",i.backgroundTop="__SpreadsheetSelectionBackgroundControlTop__",i.backgroundMiddleLeft="__SpreadsheetSelectionBackgroundControlMiddleLeft__",i.backgroundMiddleRight="__SpreadsheetSelectionBackgroundControlMiddleRight__",i.backgroundBottom="__SpreadsheetSelectionBackgroundControlBottom__",i.fill="__SpreadsheetSelectionFillControl__",i.fillTopLeft="__SpreadsheetSelectionFillControlTopLeft__",i.fillBottomRight="__SpreadsheetSelectionFillControlBottomRight__",i.fillTopLeftInner="__SpreadsheetSelectionFillControlTopLeftInner__",i.fillBottomRightInner="__SpreadsheetSelectionFillControlBottomRightInner__",i.lineMain="__SpreadsheetDragLineMainControl__",i.lineContent="__SpreadsheetDragLineContentControl__",i.line="__SpreadsheetDragLineControl__",i.dash="__SpreadsheetDragDashControl__",i.rowHeaderBackground="__SpreadSheetSelectionRowHeaderBackground__",i.rowHeaderBorder="__SpreadSheetSelectionRowHeaderBorder__",i.rowHeaderGroup="__SpreadSheetSelectionRowHeaderGroup__",i.columnHeaderBackground="__SpreadSheetSelectionColumnHeaderBackground__",i.columnHeaderBorder="__SpreadSheetSelectionColumnHeaderBorder__",i.columnHeaderGroup="__SpreadSheetSelectionColumnHeaderGroup__",i.topLeftWidget="__SpreadSheetSelectionTopLeftWidget__",i.topCenterWidget="__SpreadSheetSelectionTopCenterWidget__",i.topRightWidget="__SpreadSheetSelectionTopRightWidget__",i.middleLeftWidget="__SpreadSheetSelectionMiddleLeftWidget__",i.middleRightWidget="__SpreadSheetSelectionMiddleRightWidget__",i.bottomLeftWidget="__SpreadSheetSelectionBottomLeftWidget__",i.bottomCenterWidget="__SpreadSheetSelectionBottomCenterWidget__",i.bottomRightWidget="__SpreadSheetSelectionBottomRightWidget__",i))(Qo||{});const qs=.3;class Fn extends a.Disposable{constructor(e,t,n,r){var s,l,c,d;super();T(this,"_isHelperSelection",!0);T(this,"_enableAutoFill",!0);T(this,"_showAutoFill",!1);T(this,"_highlightHeader",!0);T(this,"_selectionRenderModel");T(this,"_leftBorder");T(this,"_rightBorder");T(this,"_topBorder");T(this,"_bottomBorder");T(this,"_backgroundControlTop");T(this,"_backgroundControlBottom");T(this,"_backgroundControlMiddleLeft");T(this,"_backgroundControlMiddleRight");T(this,"_autoFillControl");T(this,"_selectionShapeGroup");T(this,"_rowHeaderBackground");T(this,"_rowHeaderBorder");T(this,"_rowHeaderGroup");T(this,"_columnHeaderBackground");T(this,"_columnHeaderBorder");T(this,"_columnHeaderGroup");T(this,"_dashedRect");T(this,"_topLeftWidget");T(this,"_topCenterWidget");T(this,"_topRightWidget");T(this,"_middleLeftWidget");T(this,"_middleRightWidget");T(this,"_bottomLeftWidget");T(this,"_bottomCenterWidget");T(this,"_bottomRightWidget");T(this,"_defaultStyle");T(this,"_currentStyle");T(this,"_rowHeaderWidth",0);T(this,"_columnHeaderHeight",0);T(this,"_widgetRects",[]);T(this,"_controlExtension");T(this,"_dispose$",new A.BehaviorSubject(this));T(this,"dispose$",this._dispose$.asObservable());T(this,"selectionMoving$",new A.Subject);T(this,"selectionMoveEnd$",new A.Subject);T(this,"selectionScaling$",new A.Subject);T(this,"selectionScaled$",new A.Subject);T(this,"selectionFilling$",new A.Subject);T(this,"_selectionFilled$",new A.Subject);T(this,"selectionFilled$",this._selectionFilled$.asObservable());T(this,"_antLineOffset",0);T(this,"_antRequestNewFrame",-1);this._scene=e,this._zIndex=t,this._themeService=n,this._enableAutoFill=(s=r==null?void 0:r.enableAutoFill)!=null?s:!0,this._highlightHeader=(l=r==null?void 0:r.highlightHeader)!=null?l:!0,this._rowHeaderWidth=(c=r==null?void 0:r.rowHeaderWidth)!=null?c:0,this._columnHeaderHeight=(d=r==null?void 0:r.columnHeaderHeight)!=null?d:0,this._initializeSheetBody(),this._initialHeader()}_initializeSheetBody(){this._defaultStyle=gt(this._themeService),this._currentStyle=gt(this._themeService),this._selectionRenderModel=new bd;const e=this._zIndex;this._leftBorder=new P.Rect("__SpreadsheetSelectionShapeLeftControl__"+e,{zIndex:e}),this._rightBorder=new P.Rect("__SpreadsheetSelectionShapeRightControl__"+e,{zIndex:e}),this._topBorder=new P.Rect("__SpreadsheetSelectionTopControl__"+e,{zIndex:e}),this._bottomBorder=new P.Rect("__SpreadsheetSelectionBottomControl__"+e,{zIndex:e}),this._backgroundControlTop=new P.Rect("__SpreadsheetSelectionBackgroundControlTop__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlBottom=new P.Rect("__SpreadsheetSelectionBackgroundControlBottom__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleLeft=new P.Rect("__SpreadsheetSelectionBackgroundControlMiddleLeft__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleRight=new P.Rect("__SpreadsheetSelectionBackgroundControlMiddleRight__"+e,{zIndex:e-1,evented:!1}),this._autoFillControl=new P.Rect("__SpreadsheetSelectionFillControl__"+e,{zIndex:e+1}),this._autoFillControl.hide(),this._dashedRect=new P.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 P.Group("__SpreadsheetSelectionShape__"+e,...t,...this._widgetRects),this._selectionShapeGroup.hide(),this._selectionShapeGroup.evented=!1,this._selectionShapeGroup.zIndex=e;const n=this.getScene();n.addObject(this._selectionShapeGroup,Wi),this.disposeWithMe(a.toDisposable(n.onTransformChange$.subscribeEvent(r=>{r.type===P.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&(this._updateLayoutOfSelectionControl(this._currentStyle),this._updateControlCoord())})))}_initialHeader(){const e=this._zIndex;this._rowHeaderBackground=new P.Rect("__SpreadSheetSelectionRowHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderBorder=new P.Rect("__SpreadSheetSelectionRowHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderGroup=new P.Group("__SpreadSheetSelectionRowHeaderGroup__"+e,this._rowHeaderBackground,this._rowHeaderBorder),this._rowHeaderGroup.hide(),this._rowHeaderGroup.evented=!1,this._rowHeaderGroup.zIndex=e,this._columnHeaderBackground=new P.Rect("__SpreadSheetSelectionColumnHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderBorder=new P.Rect("__SpreadSheetSelectionColumnHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderGroup=new P.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],Id)}_initialWidget(){const e=this._zIndex;return this._topLeftWidget=new P.Rect("__SpreadSheetSelectionTopLeftWidget__"+e,{zIndex:e+1}),this._topCenterWidget=new P.Rect("__SpreadSheetSelectionTopCenterWidget__"+e,{zIndex:e+1}),this._topRightWidget=new P.Rect("__SpreadSheetSelectionTopRightWidget__"+e,{zIndex:e+1}),this._middleLeftWidget=new P.Rect("__SpreadSheetSelectionMiddleLeftWidget__"+e,{zIndex:e+1}),this._middleRightWidget=new P.Rect("__SpreadSheetSelectionMiddleRightWidget__"+e,{zIndex:e+1}),this._bottomLeftWidget=new P.Rect("__SpreadSheetSelectionBottomLeftWidget__"+e,{zIndex:e+1}),this._bottomCenterWidget=new P.Rect("__SpreadSheetSelectionBottomCenterWidget__"+e,{zIndex:e+1}),this._bottomRightWidget=new P.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 Ks(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:n,widgets:r,autofillStroke:s,strokeDash:l,isAnimationDash:c}=t;let d=t.autofillSize,u=t.strokeWidth,h=t.autofillStrokeWidth;const S=this._getScale(),g=(u+m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH)/2/S;u/=S,d/=S,h/=S<1?1:S;const f=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/S,p=P.FIX_ONE_PIXEL_BLUR_OFFSET/S,{startX:C,startY:v,endX:b,endY:E}=this._selectionRenderModel;if(this.leftControl.transformByState({height:E-v,left:-g+p,width:u,strokeWidth:f,top:-f/2+p}),this.leftControl.setProps({fill:n,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.rightControl.transformByState({height:E-v,left:b-C-g+p,width:u,strokeWidth:f,top:-f/2+p}),this.rightControl.setProps({fill:n,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.topControl.transformByState({width:b-C+u,top:-g+p,left:-g+p,height:u,strokeWidth:f}),this.topControl.setProps({fill:n,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.bottomControl.transformByState({width:b-C+u,top:E-v-g+p,height:u,left:-g+p,strokeWidth:f}),this.bottomControl.setProps({fill:n,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),l==null)this.dashedRect.hide(),this._stopAntLineAnimation();else{const w=t.strokeWidth*2/S;this.dashedRect.transformByState({height:E-v,width:b-C,strokeWidth:w,left:-w/2+p,top:-w/2+p}),this.dashedRect.setProps({strokeDashArray:[0,l/S]}),this._stopAntLineAnimation(),c!==!1&&this._startAntLineAnimation(),this.dashedRect.show()}if(this._showAutoFill=this._showAutoFill&&this._enableAutoFill,this._showAutoFill&&!this._hasWidgets(r)){const w={fill:n,stroke:s,strokeScaleEnabled:!1},R={width:d-h,height:d-h,left:b-C-d/2+h/2-p,top:E-v-d/2+h/2-p,strokeWidth:h};this._autoFillControl.setProps(w),this._autoFillControl.transformByState(R),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,n=0,r,s){this._rowHeaderWidth=t,this._columnHeaderHeight=n,this.updateRangeBySelectionWithCoord({rangeWithCoord:e,primaryWithCoord:s,style:r}),r&&this.updateStyle(r)}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,n,r,s,l,c,d,u,h,S,g,f,p,C,v,b,E,w,R,M,O,N,D,H;(e=this._leftBorder)==null||e.dispose(),(t=this._rightBorder)==null||t.dispose(),(n=this._topBorder)==null||n.dispose(),(r=this._bottomBorder)==null||r.dispose(),(s=this._backgroundControlTop)==null||s.dispose(),(l=this._backgroundControlMiddleLeft)==null||l.dispose(),(c=this._backgroundControlMiddleRight)==null||c.dispose(),(d=this._backgroundControlBottom)==null||d.dispose(),this._autoFillControl.dispose(),(u=this._selectionShapeGroup)==null||u.dispose(),(h=this._rowHeaderBackground)==null||h.dispose(),(S=this._rowHeaderBorder)==null||S.dispose(),(g=this._rowHeaderGroup)==null||g.dispose(),(f=this._rowHeaderBackground)==null||f.dispose(),(p=this._columnHeaderBackground)==null||p.dispose(),(C=this._columnHeaderBorder)==null||C.dispose(),(v=this._columnHeaderGroup)==null||v.dispose(),(b=this._topLeftWidget)==null||b.dispose(),(E=this._topCenterWidget)==null||E.dispose(),(w=this._topRightWidget)==null||w.dispose(),(R=this._middleLeftWidget)==null||R.dispose(),(M=this._middleRightWidget)==null||M.dispose(),(O=this._bottomLeftWidget)==null||O.dispose(),(N=this._bottomCenterWidget)==null||N.dispose(),(D=this._bottomRightWidget)==null||D.dispose(),(H=this._controlExtension)==null||H.dispose(),super.dispose(),this._dispose$.next(this),this._dispose$.complete()}getCurrentCellInfo(){const e=this.model.currentCell;if(e){let t;if(e.isMerged){const n=e.mergeInfo;t={startRow:n.startRow,endRow:n.endRow,startColumn:n.startColumn,endColumn:n.endColumn,startX:n.startX,endX:n.endX,startY:n.startY,endY:n.endY}}else{const{actualRow:n,actualColumn:r,startX:s,endX:l,startY:c,endY:d}=e;t={startRow:n,endRow:n,startColumn:r,endColumn:r,startX:s,endX:l,startY:c,endY:d}}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:n,endX:r,endY:s,rangeType:l}=this._selectionRenderModel,c=this._currentStyle,d=this._getScale(),{stroke:u,rowHeaderFill:h=c.rowHeaderFill,rowHeaderStroke:S=c.rowHeaderStroke,columnHeaderFill:g=c.columnHeaderFill,columnHeaderStroke:f=c.columnHeaderStroke}=e;let{rowHeaderStrokeWidth:p=c.rowHeaderStrokeWidth,columnHeaderStrokeWidth:C=c.columnHeaderStrokeWidth}=e;p/=d,C/=d;const v=this._rowHeaderWidth,b=this._columnHeaderHeight;if(this._highlightHeader&&b>0){let E=g;l===a.RANGE_TYPE.COLUMN&&(E=new a.ColorKit(u).setAlpha(qs).toString()),this._columnHeaderBackground.setProps({fill:E}),this._columnHeaderBackground.resize(r-t,b),this._columnHeaderBorder.setProps({fill:f}),this._columnHeaderBorder.transformByState({width:r-t,height:C,top:b-C+1/d}),this._columnHeaderGroup.show(),this._columnHeaderGroup.translate(t,0)}else this._columnHeaderGroup.hide();if(this._columnHeaderGroup.makeDirty(!0),this._highlightHeader&&v>0){let E=h;l===a.RANGE_TYPE.ROW&&(E=new a.ColorKit(u).setAlpha(qs).toString()),this._rowHeaderBackground.setProps({fill:E}),this._rowHeaderBackground.resize(v,s-n),this._rowHeaderBorder.setProps({fill:S}),this._rowHeaderBorder.transformByState({width:p,height:s-n,left:v-p+1/d}),this._rowHeaderGroup.show(),this._rowHeaderGroup.translate(0,n)}else this._rowHeaderGroup.hide();this._rowHeaderGroup.makeDirty(!0)}_updateBackgroundControl(e){const{startX:t,startY:n,endX:r,endY:s}=this._selectionRenderModel,l=this._getScale(),{fill:c=e.fill}=e;let{strokeWidth:d}=e;d/=l;const u=this._selectionRenderModel.highlightToSelection();if(!u){this._backgroundControlTop.resize(r-t,s-n),this._backgroundControlTop.setProps({fill:c}),this._backgroundControlBottom.resize(0,0),this._backgroundControlMiddleLeft.resize(0,0),this._backgroundControlMiddleRight.resize(0,0);return}const{startX:h,startY:S,endX:g,endY:f}=u,p=d/2,C={left:-p,top:-p,width:r-t+p*2,height:S-n+p};C.height<0&&(C.width=0,C.height=0),this._backgroundControlTop.transformByState(C);const v={left:-p,top:S-n,width:h-t+p,height:f-S};v.width<0&&(v.width=0,v.height=0),this._backgroundControlMiddleLeft.transformByState(v);const b={left:g-t-p,top:S-n,width:r-g+p*2,height:f-S};b.width<0&&(b.width=0,b.height=0),this._backgroundControlMiddleRight.transformByState(b);const E={left:-p,top:f-n,width:r-t+p*2,height:s-f+p};E.height<0&&(E.width=0,E.height=0),this._backgroundControlBottom.transformByState(E),this._backgroundControlTop.setProps({fill:c}),this._backgroundControlMiddleLeft.setProps({fill:c}),this._backgroundControlMiddleRight.setProps({fill:c}),this._backgroundControlBottom.setProps({fill:c})}_updateWidgets(e){const{startX:t,startY:n,endX:r,endY:s}=this._selectionRenderModel,{stroke:l=e.stroke,widgets:c=e.widgets,widgetStroke:d=e.widgetStroke}=e,u=this._getScale();let{widgetSize:h,widgetStrokeWidth:S}=e;h/=u,S/=u;const g={left:-h/2+S/2,center:(r-t)/2-h/2+S/2,right:r-t-h/2+S/2,top:-h/2,middle:(s-n)/2-h/2,bottom:s-n-h/2+S/2},f=h-S;this._widgetRects.forEach(p=>{p.setProps({fill:l,stroke:d})}),c.tl===!0?(this._topLeftWidget.transformByState({height:f,width:f,left:g.left,top:g.top,strokeWidth:S}),this._topLeftWidget.show()):this._topLeftWidget.hide(),c.tc===!0?(this._topCenterWidget.transformByState({height:f,width:f,left:g.center,top:g.top,strokeWidth:S}),this._topCenterWidget.show()):this._topCenterWidget.hide(),c.tr===!0?(this._topRightWidget.transformByState({height:f,width:f,left:g.right,top:g.top,strokeWidth:S}),this._topRightWidget.show()):this._topRightWidget.hide(),c.ml===!0?(this._middleLeftWidget.transformByState({height:f,width:f,left:g.left,top:g.middle,strokeWidth:S}),this._middleLeftWidget.show()):this._middleLeftWidget.hide(),c.mr===!0?(this._middleRightWidget.transformByState({height:f,width:f,left:g.right,top:g.middle,strokeWidth:S}),this._middleRightWidget.show()):this._middleRightWidget.hide(),c.bl===!0?(this._bottomLeftWidget.transformByState({height:f,width:f,left:g.left,top:g.bottom,strokeWidth:S}),this._bottomLeftWidget.show()):this._bottomLeftWidget.hide(),c.bc===!0?(this._bottomCenterWidget.transformByState({height:f,width:f,left:g.center,top:g.bottom,strokeWidth:S}),this._bottomCenterWidget.show()):this._bottomCenterWidget.hide(),c.br===!0?(this._bottomRightWidget.transformByState({height:f,width:f,left:g.right,top:g.bottom,strokeWidth:S}),this._bottomRightWidget.show()):this._bottomRightWidget.hide()}_hasWidgets(e){if(e==null)return!1;const t=Object.keys(e);if(t.length===0)return!1;for(const n of t)if(e[n]===!0)return!0;return!1}_getScale(){const{scaleX:e,scaleY:t}=this._scene.getAncestorScale();return Math.max(e,t)}_stopAntLineAnimation(){this._antLineOffset=0,P.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=P.requestNewFrame(()=>{this._startAntLineAnimation()})}}class Td extends P.Layer{render(o,e=!1){const t=a.Tools.now();return super.render(o,e),this._afterRender(t),this}_afterRender(o){this.scene.getEngine().renderFrameTimeMetric$.next(["selectionLayer",a.Tools.now()-o])}}const Ce=a.createIdentifier("univer.sheet.selection-render-service");class Jo extends a.Disposable{constructor(e,t,n,r,s){super();T(this,"_downObserver");T(this,"_scenePointerMoveSub");T(this,"_scenePointerUpSub");T(this,"_controlFillConfig$",new A.BehaviorSubject(null));T(this,"controlFillConfig$",this._controlFillConfig$.asObservable());T(this,"_selectionControls",[]);T(this,"_startRangeWhenPointerDown",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});T(this,"_activeControlIndex",-1);T(this,"_startViewportPosX",0);T(this,"_startViewportPosY",0);T(this,"_scrollTimer");T(this,"_cancelDownSubscription");T(this,"_cancelUpSubscription");T(this,"_skeleton");T(this,"_scene");T(this,"_highlightHeader",!0);T(this,"_rangeType",a.RANGE_TYPE.NORMAL);T(this,"_selectionStyle");T(this,"_remainLastEnabled",!1);T(this,"_skipLastEnabled",!1);T(this,"_singleSelectionEnabled",!1);T(this,"_selectionMoveEnd$",new A.BehaviorSubject([]));T(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());T(this,"_selectionMoving$",new A.Subject);T(this,"selectionMoving$",this._selectionMoving$.asObservable());T(this,"_selectionMoveStart$",new A.Subject);T(this,"selectionMoveStart$",this._selectionMoveStart$.asObservable());T(this,"_selectionMoving",!1);T(this,"_selectionTheme");T(this,"_activeViewport");T(this,"interceptor",new a.InterceptorManager({RANGE_MOVE_PERMISSION_CHECK:Zo,RANGE_FILL_PERMISSION_CHECK:Ko}));T(this,"_escapeShortcutDisposable",null);this._injector=e,this._themeService=t,this._shortcutService=n,this._sheetSkeletonManagerService=r,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,n){const r=this.getSelectionControls().length,{rowHeaderWidth:s,columnHeaderHeight:l}=t,c=new Fn(e,r,this._selectionTheme,{highlightHeader:this._highlightHeader,rowHeaderWidth:s,columnHeaderHeight:l});this._selectionControls.push(c);const d=Me(n,t);return c.updateRangeBySelectionWithCoord(d,t),c.setControlExtension({skeleton:t,scene:e,themeService:this._selectionTheme,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),c}resetSelectionsByModelData(e){const t=this.getSelectionControls(),n=this._skeleton;if(!(!t||!n)){for(let r=0,s=e.length;r<s;r++){const l=e[r],c=Me(l,this._skeleton),d=t[r];d?d.updateRangeBySelectionWithCoord(c,n):this.isSelectionEnabled()&&this.newSelectionControl(this._scene,n,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,n){this._skeleton=e,this._scene=t,this._activeViewport=n||(t==null?void 0:t.getViewports()[0]),t.findLayerByZIndex(Wi)||t.addLayer(new Td(t,[],Wi))}getSkeleton(){return this._skeleton}getSelectionDataWithStyle(){const e=this._selectionControls,[t,n]=this._skeleton.getLocation();return e.map(r=>{const s=r.getValue();return s.rangeWithCoord.sheetId=n,s.rangeWithCoord.unitId=t,s})}getSelectionControls(){return this._selectionControls}_addSelectionControlByModelData(e){var l;const t=this._skeleton,n=(l=e.style)!=null?l:gt(this._selectionTheme),r=this._scene;return e.style=n,this.newSelectionControl(r,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.getCurrentParam())==null?void 0:t.skeleton.getWorksheetConfig().freeze}_getViewportByCell(e,t){if(e===void 0||t===void 0)return null;const n=this._getFreeze();if(!n||n.startRow<=0&&n.startColumn<=0)return this._scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e>n.startRow&&t>n.startColumn)return this._scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e<=n.startRow&&t<=n.startColumn)return this._scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP);if(e<=n.startRow&&t>n.startColumn)return this._scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(e>n.startRow&&t<=n.startColumn)return this._scene.getViewport(P.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,n,r=P.ScrollTimerType.ALL,s,l){var f,p;let c=0,d=0,u=s,h=l;this._scrollTimer=P.ScrollTimer.create(this._scene,r),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 S=this._scene,g=S.getActiveViewportByCoord(P.Vector2.FromArray([s,l]));this._scenePointerMoveSub=S.onPointerMove$.subscribeEvent(C=>{var V,U,W,B,F,z,x,X,Y;const{offsetX:v,offsetY:b}=C,{x:E,y:w}=S.getCoordRelativeToViewport(P.Vector2.FromArray([v,b]));this._movingHandler(E,w,t,n);let R=E,M=w;const O=this.getActiveSelectionControl(),N=this._getFreeze(),D=O==null?void 0:O.model,H=(V=S.getActiveViewportByCoord(P.Vector2.FromArray([v,b])))!=null?V:this._getViewportByCell(D==null?void 0:D.endRow,D==null?void 0:D.endColumn);if((()=>{if(!g||!H||!e)return!1;const J=[P.SHEET_VIEWPORT_KEY.VIEW_MAIN,P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,P.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT];return J.includes(g.viewportKey)&&J.includes(H.viewportKey)})()){if(!g||!H||!e)return!1;const J=u<e.left&&E>e.left||u>e.left&&E<e.left,ie=h<e.top&&w>e.top||h>e.top&&w<e.top;J&&(c+=1),ie&&(d+=1);const $=g.viewportKey,re=H.viewportKey;if($===P.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP)b<e.top&&((U=D==null?void 0:D.endRow)!=null?U:0)<((W=N==null?void 0:N.startRow)!=null?W:0)?M=e.top:ie&&d%2===1&&e.scrollToViewportPos({viewportScrollY:0});else if($===P.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT)v<e.left&&((B=D==null?void 0:D.endColumn)!=null?B:0)<((F=N==null?void 0:N.startColumn)!=null?F:0)?R=e.left:J&&c%2===1&&e.scrollToViewportPos({viewportScrollX:0});else if($===re){let ae=!1,j=!1;$===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP?(ae=!0,j=!0):$===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP?j=!0:$===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT&&(ae=!0),((z=D==null?void 0:D.endRow)!=null?z:0)>((x=N==null?void 0:N.startRow)!=null?x:0)&&(j=!1),((X=D==null?void 0:D.endColumn)!=null?X:0)>((Y=N==null?void 0:N.startColumn)!=null?Y:0)&&(ae=!1),ae&&(R=e.left),j&&(M=e.top)}else{const ae={x:g.scrollX,y:g.scrollY},j={x:H.scrollX,y:H.scrollY},G=ae.x!==j.x&&J&&c%2===1,Z=ae.y!==j.y&&ie&&d%2===1;(G||Z)&&(e.scrollToBarPos({x:G?ae.x:void 0,y:Z?ae.y:void 0}),G||(R=e.left),Z||(M=e.top)),($===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&re===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||re===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&$===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)&&(R=e.left),($===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&re===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||re===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&$===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP)&&(M=e.top)}u=E,h=w}this._scrollTimer.scrolling(R,M,()=>{this._movingHandler(E,w,t,n)})})}attachSelectionWithCoord(e){return Me(e,this._skeleton)}attachPrimaryWithCoord(e){return xn(this._skeleton,e)}getSelectionCellByPosition(e,t){return this.getCellWithCoordByOffset(e,t)}getCellWithCoordByOffset(e,t,n){const r=this._scene,s=n!=null?n:this._skeleton,l=r.getViewportScrollXY(r.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:c,scaleY:d}=r.getAncestorScale();return s.getCellWithCoordByOffset(e,t,c,d,l)}_movingHandler(e,t,n,r){var R,M,O,N,D;const s=this._skeleton,l=this._scene,[c,d]=s.getLocation(),u={startRow:(R=n==null?void 0:n.model.startRow)!=null?R:-1,endRow:(M=n==null?void 0:n.model.endRow)!=null?M:-1,startColumn:(O=n==null?void 0:n.model.startColumn)!=null?O:-1,endColumn:(N=n==null?void 0:n.model.endColumn)!=null?N:-1,unitId:c,sheetId:d},h=l.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN),S=(D=this._getViewportByCell(u.endRow,u.endColumn))!=null?D:h,g=l.getScrollXYInfoByViewport(P.Vector2.FromArray([this._startViewportPosX,this._startViewportPosY]),S),{scaleX:f,scaleY:p}=l.getAncestorScale();r===a.RANGE_TYPE.ROW?e=Number.POSITIVE_INFINITY:r===a.RANGE_TYPE.COLUMN&&(t=Number.POSITIVE_INFINITY);const C=this._skeleton.getCellByOffset(e,t,f,p,g);if(!C)return;let v={startRow:Math.min(C.startRow,this._startRangeWhenPointerDown.startRow),startColumn:Math.min(C.startColumn,this._startRangeWhenPointerDown.startColumn),endRow:Math.max(C.endRow,this._startRangeWhenPointerDown.endRow),endColumn:Math.max(C.endColumn,this._startRangeWhenPointerDown.endColumn)};this._shouldDetectMergedCells&&(v=s.expandRangeByMerge(v));const E=Me({range:v,primary:void 0,style:null},s);E.rangeWithCoord.unitId=c,E.rangeWithCoord.sheetId=d,E.rangeWithCoord.rangeType=r;const w=u.startRow!==v.startRow||u.startColumn!==v.startColumn||u.endRow!==v.endRow||u.endColumn!==v.endColumn;n!=null&&w&&(n.updateRangeBySelectionWithCoord(E),this._selectionMoving$.next(this.getSelectionDataWithStyle()))}_clearUpdatingListeners(){var t,n,r,s,l;this._scene.enableObjectsEvent(),(t=this._scenePointerMoveSub)==null||t.unsubscribe(),this._scenePointerMoveSub=null,(n=this._scenePointerUpSub)==null||n.unsubscribe(),this._scenePointerUpSub=null,(r=this._cancelDownSubscription)==null||r.unsubscribe(),this._cancelDownSubscription=null,(s=this._cancelUpSubscription)==null||s.unsubscribe(),this._cancelUpSubscription=null,(l=this._scrollTimer)==null||l.dispose()}_addEndingListeners(){var n,r,s;const e=this._scene,t=(n=e.getEngine())==null?void 0:n.activeScene;!t||t===e||((r=this._cancelDownSubscription)==null||r.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,n,r,s){const l=this._skeleton;if(l==null)return null;if(this._shouldDetectMergedCells){const v=l==null?void 0:l.getCellWithCoordByOffset(e,t,n,r,s,{firstMatch:!0});if(!v)return;const b=a.convertCellToRange(v);return{primaryWithCoord:v,rangeWithCoord:b}}const{row:c,column:d}=l.getCellIndexByOffset(e,t,n,r,s),u=l.getNoMergeCellWithCoordByIndex(c,d),{startX:h,startY:S,endX:g,endY:f}=u,p={startY:S,endY:f,startX:h,endX:g,startRow:c,endRow:c,startColumn:d,endColumn:d};return{primaryWithCoord:{mergeInfo:p,actualRow:c,actualColumn:d,isMerged:!1,isMergedMainCell:!1,startY:S,endY:f,startX:h,endX:g},rangeWithCoord:p}}_checkClearPreviousControls(e){this.getSelectionControls().length!==0&&(!e.ctrlKey&&!e.shiftKey&&!this._remainLastEnabled||this._singleSelectionEnabled&&!e.shiftKey)&&this._clearAllSelectionControls()}_makeSelectionByTwoCells(e,t,n,r,s){const{actualRow:l,actualColumn:c,mergeInfo:d}=e;this._startRangeWhenPointerDown={...e.mergeInfo};const u=Math.min(l,t.startRow,d.startRow),h=Math.max(l,t.endRow,d.endRow),S=Math.min(c,t.startColumn,d.startColumn),g=Math.max(c,t.endColumn,d.endColumn),p={range:n.expandRangeByMerge({startRow:u,startColumn:S,endRow:h,endColumn:g}),primary:null,style:null},C=Me(p,n);s.updateRangeBySelectionWithCoord(C)}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 $o(i){return{range:{startRow:0,startColumn:0,endRow:i.getRowCount()-1,endColumn:i.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL},primary:Bi(i).primary,style:null}}function Bi(i){return Qs(i,{startRow:0,startColumn:0,endRow:0,endColumn:0})}function Qs(i,o){const e=i.worksheet.getCellInfoInMergeData(o.startRow,o.startColumn),t=i.worksheet.getCellInfoInMergeData(o.endRow,o.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 wd=Object.defineProperty,yd=Object.getOwnPropertyDescriptor,Pd=(i,o,e,t)=>{for(var n=t>1?void 0:t?yd(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&wd(o,e,n),n},Js=(i,o)=>(e,t)=>o(e,t,i);y.SheetSkeletonManagerService=class extends a.Disposable{constructor(e,t,n){super();T(this,"_sheetId","");T(this,"_sheetSkeletonParamStore",new Map);T(this,"_currentSkeleton$",new A.BehaviorSubject(null));T(this,"currentSkeleton$",this._currentSkeleton$.asObservable());T(this,"_currentSkeletonBefore$",new A.BehaviorSubject(null));T(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._context=e,this._injector=t,this._sheetSkService=n,this.disposeWithMe(()=>{this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._sheetSkeletonParamStore.forEach(r=>this.disposeSkeleton(r.sheetId)),this._sheetSkeletonParamStore.clear()}),this._initRemoveSheet()}_initRemoveSheet(){this.disposeWithMe(this._context.unit.sheetDisposed$.subscribe(e=>{this.disposeSkeleton(e.getSheetId())}))}getCurrentSkeleton(){var e;return(e=this.getCurrentParam())==null?void 0:e.skeleton}getCurrent(){return this.getCurrentParam()}getCurrentParam(){return this._getSkeletonParam(this._sheetId)}getSkeleton(e){return this._getSkeleton(e)}getSkeletonParam(e){return this._getSkeletonParam(e)}getWorksheetSkeleton(e){return this.getSkeletonParam(e)}getUnitSkeleton(e,t){const n=this._getSkeletonParam(t);return n!=null&&(n.unitId=e),n}setCurrent(e){this._setCurrent(e.sheetId)}setSkeletonParam(e,t){this._sheetSkService.setSkeleton(t.unitId,e,t.skeleton),this._sheetSkeletonParamStore.set(e,t)}_setCurrent(e){this._sheetId=e;const t=this._getSkeletonParam(e),n=this._context.unitId;if(t!=null)this.reCalculate(t);else{const l=this._context.unit.getSheetBySheetId(e);if(l==null)return;const c=this._context.scene,d=this._buildSkeleton(l,c);this.setSkeletonParam(e,{unitId:n,sheetId:e,skeleton:d,dirty:!1})}const r=this._getSkeletonParam(e);this._currentSkeletonBefore$.next(r),this._currentSkeleton$.next(r)}reCalculate(e){e||(e=this.getCurrentParam()),e!=null&&(e.dirty&&(e.skeleton.makeDirty(!0),e.dirty=!1),e.skeleton.calculate())}makeDirty(e,t=!0){const n=this._getSkeletonParam(e.sheetId);n!=null&&(n.dirty=t)}getOrCreateSkeleton(e){return this.ensureSkeleton(e.sheetId)}ensureSkeleton(e){const t=this._getSkeletonParam(e);if(t)return t.skeleton;const r=this._context.unit.getSheetBySheetId(e);if(!r)return;const s=this._buildSkeleton(r);return this.setSkeletonParam(e,{unitId:this._context.unitId,sheetId:e,skeleton:s,dirty:!1}),s}disposeSkeleton(e){const t=this.getSkeletonParam(e);t&&(t.skeleton.dispose(),this._sheetSkeletonParamStore.delete(e),this._sheetSkService.deleteSkeleton(t.unitId,e))}attachRangeWithCoord(e){const t=this.getCurrentSkeleton();return t?rn(t,e):null}_getSkeletonParam(e){return this._sheetSkeletonParamStore.get(e)}_getSkeleton(e){const t=this._getSkeletonParam(e);return t?t.skeleton:null}_buildSkeleton(e,t){return this._injector.createInstance(P.SpreadsheetSkeleton,e,this._context.unit.getStyles())}setColumnHeaderSize(e,t,n){var u;if(!e)return;const r=(u=this.getWorksheetSkeleton(t))==null?void 0:u.skeleton;if(!r)return;r.columnHeaderHeight=n,e.scene.getViewports()[0].top=n,e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({height:n}),e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({height:n}),e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({top:n}),e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({top:n}),e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({height:n});const s=e==null?void 0:e.with(m.SheetsSelectionsService),l=e==null?void 0:e.with(Ce),c=s.getCurrentSelections();l.resetSelectionsByModelData(c);const d=this.getUnitSkeleton(e.unitId,t);d&&(d.commandId=Ui.id,this._currentSkeleton$.next(d))}setRowHeaderSize(e,t,n){var f;const r=(f=this.getWorksheetSkeleton(t))==null?void 0:f.skeleton;if(!e||!r)return;r.rowHeaderWidth=n;const s=e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).width||46,l=n-s,c=e.scene.getViewports()[0].left;e.scene.getViewports()[0].left=c+l,e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({width:n}),e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({width:n}),e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({left:n});const d=e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).left||0;e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({left:d+l}),e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({width:n});const u=e==null?void 0:e.with(m.SheetsSelectionsService),h=e==null?void 0:e.with(Ce),S=u.getCurrentSelections();h.resetSelectionsByModelData(S);const g=this.getCurrent();g&&(g.commandId=Li.id,this._currentSkeleton$.next(g))}},y.SheetSkeletonManagerService=Pd([Js(1,a.Inject(a.Injector)),Js(2,a.Inject(m.SheetSkeletonService))],y.SheetSkeletonManagerService);function nt(){const i=_.useDependency(a.IUniverInstanceService),o=_.useObservable(()=>i.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]);return o!=null?o:null}function Md(i){return _.useObservable(()=>{var e;return(e=i==null?void 0:i.activeSheet$)!=null?e:A.of(null)},void 0,void 0,[i])}function Rd(){const i=_.useDependency(a.IUniverInstanceService);return _.useObservable(()=>A.merge([i.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET),i.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET)]).pipe(A.map(()=>i.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET)),A.startWith(i.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET))),[],void 0,[i])}const Od="SheetUI";var er=(i=>(i.FILTER_PANEL_EMBED_POINT="filter-panel-embed-point",i.SHEETS_FOOTER="sheets-footer",i.FORMULA_AUX="formula-aux",i))(er||{}),Ad=Object.defineProperty,Nd=Object.getOwnPropertyDescriptor,Dd=(i,o,e,t)=>{for(var n=t>1?void 0:t?Nd(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&Ad(o,e,n),n},xi=(i,o)=>(e,t)=>o(e,t,i);const tr=["ff","fs","tr","tb"];y.AutoHeightController=class extends a.Disposable{constructor(o,e,t,n){super(),this._renderManagerService=o,this._sheetInterceptorService=e,this._selectionManagerService=t,this._univerInstanceService=n,this._initialize()}getUndoRedoParamsOfAutoHeight(o){const{_univerInstanceService:e}=this,t=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),n=t.getActiveSheet(),r=t.getUnitId(),s=n.getSheetId(),l=this._renderManagerService.getRenderById(r).with(y.SheetSkeletonManagerService);if(!s||!l.getCurrentParam())return{redos:[],undos:[]};const{skeleton:c}=l.getCurrentParam(),d=c.calculateAutoHeightInRange(o),u={subUnitId:s,unitId:r,rowsAutoHeightInfo:d},h=m.SetWorksheetRowAutoHeightMutationFactory(u,n);return{undos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:h}],redos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:u}]}}_initialize(){const{_sheetInterceptorService:o,_selectionManagerService:e}=this;this.disposeWithMe(o.interceptCommand({getMutations:t=>{if(t.id===m.SetRangeValuesCommand.id){const n=t.params;return this.getUndoRedoParamsOfAutoHeight(n.range)}return{redos:[],undos:[]}}})),this.disposeWithMe(o.interceptCommand({getMutations:t=>t.id!==m.SetWorksheetRowIsAutoHeightCommand.id?{redos:[],undos:[]}:this.getUndoRedoParamsOfAutoHeight(t.params.ranges)})),this.disposeWithMe(o.interceptCommand({getMutations:t=>{var r,s;if(t.id!==m.SetStyleCommand.id)return{redos:[],undos:[]};if(!tr.includes((r=t.params)==null?void 0:r.style.type))return{redos:[],undos:[]};const n=(s=e.getCurrentSelections())==null?void 0:s.map(l=>l.range);return n!=null&&n.length?this.getUndoRedoParamsOfAutoHeight(n):{redos:[],undos:[]}}})),this.disposeWithMe(o.interceptAfterCommand({getMutations:t=>{if(t.id===m.MoveRangeCommand.id){const n=t.params;return this.getUndoRedoParamsOfAutoHeight([n.fromRange,n.toRange])}if(t.id===m.ReorderRangeCommand.id){const n=t.params;return this.getUndoRedoParamsOfAutoHeight([n.range])}return{redos:[],undos:[]}}}))}},y.AutoHeightController=Dd([xi(0,P.IRenderManagerService),xi(1,a.Inject(m.SheetInterceptorService)),xi(2,a.Inject(m.SheetsSelectionsService)),xi(3,a.Inject(a.IUniverInstanceService))],y.AutoHeightController);function sn(i,o,e,t){const n=o.get(a.IUniverInstanceService),r=e?n.getUnit(e,a.UniverInstanceType.UNIVER_SHEET):n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=t?r==null?void 0:r.getSheetBySheetId(t):r==null?void 0:r.getActiveSheet();if(!s)return null;const{startRow:l,endRow:c,startColumn:d,endColumn:u}=i,h=[],S=[];for(let g=l;g<=c;g++)s.getRowFiltered(g)||h.push(g);for(let g=d;g<=u;g++)S.push(g);return{rows:h,cols:S}}function ft(i){const{rows:o,cols:e}=i;return{startRow:o[0],endRow:o[o.length-1],startColumn:e[0],endColumn:e[e.length-1]}}function Mt(i){let o=[],e=[];const t=[];return i.forEach(n=>{o=o.concat(n.rows),e=e.concat(n.cols)}),o=Array.from(new Set(o)).sort((n,r)=>n-r),e=Array.from(new Set(e)).sort((n,r)=>n-r),i.forEach(n=>{t.push({startRow:o.findIndex(r=>r===n.rows[0]),endRow:o.findIndex(r=>r===n.rows[n.rows.length-1]),startColumn:e.findIndex(r=>r===n.cols[0]),endColumn:e.findIndex(r=>r===n.cols[n.cols.length-1])})}),{ranges:t,mapFunc:(n,r)=>({row:o[n],col:e[r]})}}function Hd(i){const o=new a.ObjectMatrix;return i.forEach(e=>{const{rows:t,cols:n}=e;t.forEach(r=>{n.forEach(s=>{o.setValue(r,s,{v:null,p:null,f:null,si:null,custom:null})})})}),o.getData()}const nr={零:0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9},Fi=["零","一","二","三","四","五","六","七","八","九"],$s=["","万","亿","万亿","亿亿"],kd=["","十","百","千"],ea={十:{value:10,secUnit:!1},百:{value:100,secUnit:!1},千:{value:1e3,secUnit:!1},万:{value:1e4,secUnit:!0},亿:{value:1e8,secUnit:!0}};function it(i){if(!i)return 0;let o=0,e=0,t=0,n=!1;const r=i.split("");for(let s=0;s<r.length;s++){const l=nr[r[s]];if(typeof l<"u")t=l,s===r.length-1&&(e+=t);else{const c=ea[r[s]],d=c.value;n=c.secUnit,n?(e=(e+t)*d,o+=e,e=0):e+=t*d,t=0}}return o+e}function Vd(i){let o="",e="",t=0,n=!0;for(;i>0;){const r=i%10;r===0?n||(n=!0,e=Fi[r]+e):(n=!1,o=Fi[r],o+=kd[t],e=o+e),t++,i=Math.floor(i/10)}return e}function Wd(i){let o=0,e="",t="",n=!1;if(i===0)return Fi[0];for(;i>0;){const r=i%1e4;n&&(t=Fi[0]+t),e=Vd(r),e+=r!==0?$s[o]:$s[0],t=e+t,n=r<1e3&&r>0,i=Math.floor(i/1e4),o++}return t}function Ld(i){if(!i)return!1;let o=!0;if(i)if(i.length===1)i==="日"||i in nr?o=!0:o=!1;else{const e=i.split("");for(let t=0;t<e.length;t++)if(!(e[t]in nr||e[t]in ea)){o=!1;break}}return o}function zi(i){if(!i)return{isExtendNumber:!1};const o=/0|([1-9]+[0-9]*)/g,e=o.test(i);if(e){const t=i.match(o);if(t&&t.length>0){const n=t[t.length-1],r=i.lastIndexOf(n),s=i.substr(0,r),l=i.substr(r+n.length);return{isExtendNumber:!0,matchTxt:Number(n),beforeTxt:s,afterTxt:l}}return{isExtendNumber:!1}}return{isExtendNumber:e}}function Ud(i){let o;return i.length===2&&(i==="周一"||i==="周二"||i==="周三"||i==="周四"||i==="周五"||i==="周六"||i==="周日")?o=!0:o=!1,o}function Bd(i){let o;return i.length===3&&(i==="星期一"||i==="星期二"||i==="星期三"||i==="星期四"||i==="星期五"||i==="星期六"||i==="星期日")?o=!0:o=!1,o}function xd(i,o){let e=0;for(let t=0;t<i.length&&i[t]<o;t++)e++;return e}function zn(i){let o=!0;const e=i[1]-i[0];for(let t=1;t<i.length;t++)if(i[t]-i[t-1]!==e){o=!1;break}return o}function Fd(i,o,e){const t=[],n=Math.floor(o/i),r=o%i;let s=0;if(n>0){for(let l=0;l<n;l++)for(let c=0;c<e.length;c++)t[e[c]+l*i]=s,s++;for(let l=0;l<e.length&&e[l]<r;l++)t[e[l]+i*n]=s,s++}else for(let l=0;l<e.length&&e[l]<r;l++)t[e[l]]=s,s++;return t}function Rt(i,o){const e=[];for(let t=1;t<=o;t++){const n=(t-1)%i.length,r=a.Tools.deepClone(i[n]);Ot(r),e.push({v:null,s:null,p:null,f:null,si:null,t:null,...r})}return e}function zd(i,o){var t;const e=[];for(let n=1;n<=o;n++){const r=(n-1)%i.length,s={s:(t=i[r])==null?void 0:t.s};e.push(s)}return e}function Xd(i){let o=!0;const e=i[1]/i[0];for(let t=1;t<i.length;t++)if(i[t]/i[t-1]!==e){o=!1;break}return o}function Yd(i){const o=[];for(let e=1;e<=i;e++)o.push(e);return o}function Xi(i,o,e){var r,s,l,c;const t=[],n=[];for(let d=0;d<i.length;d++)n.push(Number((r=i[d])==null?void 0:r.v));if(i.length>2&&Xd(n))for(let d=1;d<=o;d++){const u=(d-1)%i.length,h=a.Tools.deepClone(i[u]);Ot(h);const S=Number((s=i[i.length-1])==null?void 0:s.v)*(Number((l=i[1])==null?void 0:l.v)/Number((c=i[0])==null?void 0:c.v))**d;h&&(oa(h)&&(h.v=S),t.push(h))}else{const d=Yd(i.length);for(let u=1;u<=o;u++){const h=(u-1)%i.length,S=a.Tools.deepClone(i[h]);Ot(S);const g=e===a.Direction.DOWN||e===a.Direction.RIGHT,f=jd(i.length+u,n,d,g);S&&(oa(S)&&(S.v=f),t.push(S))}}return t}function jd(i,o,e,t=!0){function n(h){let S=0;for(let g=0;g<h.length;g++)S+=h[g];return S/h.length}const r=n(e),s=n(o);let l=0,c=0;for(let h=0;h<e.length;h++)l+=(e[h]-r)*(o[h]-s),c+=(e[h]-r)*(e[h]-r);let d;c===0?d=t?1:-1:d=l/c;const u=s-d*r;return Math.round((u+d*i)*1e5)/1e5}function ta(i,o,e){var r;const t=[],n=/0|([1-9]+[0-9]*)/g;for(let s=1;s<=o;s++){const l=(s-1)%i.length,c=a.Tools.deepClone(i[l]);Ot(c);const d=`${(r=i[i.length-1])==null?void 0:r.v}`,u=d==null?void 0:d.match(n),h=u==null?void 0:u[u.length-1],S=Math.abs(Number(h)+e*s);if(!d||!h)continue;const g=d.lastIndexOf(h),f=d.substr(0,g)+S.toString()+d.substr(g+h.length);c&&(c.v=f,t.push(c))}return t}function an(i,o,e,t=0){var l,c;const n=[["日","一","二","三","四","五","六"],["周日","周一","周二","周三","周四","周五","周六"],["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]];if(t>=n.length)return[];const r=n[t],s=[];for(let d=1;d<=o;d++){const u=(d-1)%i.length,h=a.Tools.deepClone(i[u]);Ot(h);let S=0;if(((l=i[i.length-1])==null?void 0:l.v)===r[0])S=7+e*d;else{const f=`${(c=i[i.length-1])==null?void 0:c.v}`;if(f){const p=f.substr(f.length-1,1);S=it(p)+e*d}}S<0&&(S=Math.ceil(Math.abs(S)/7)*7+S);const g=S%7;h&&(h.v=r[g],s.push(h))}return s}function na(i,o,e){var n;const t=[];for(let r=1;r<=o;r++){const s=(r-1)%i.length,l=a.Tools.deepClone(i[s]);Ot(l);const c=`${(n=i[i.length-1])==null?void 0:n.v}`,d=it(c)+e*r;let u;d<=0?u="零":u=Wd(d),l&&(l.v=u,t.push(l))}return t}const Xn={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 Gd(i){let o=!1;return Object.keys(Xn).forEach(e=>{Xn[e].includes(i)&&(o=!0)}),o}function ir(i){let o="";const e=[];return Object.keys(Xn).forEach(t=>{Xn[t].includes(i)&&(o=t,e.push(...Xn[t]))}),{name:o,series:e}}function ia(i,o,e,t){var s;const n=t.length,r=[];for(let l=1;l<=o;l++){const c=(l-1)%i.length,d=a.Tools.deepClone(i[c]);Ot(d);const u=`${(s=i[i.length-1])==null?void 0:s.v}`;let h=t.indexOf(u)+e*l;h<0&&(h+=Math.abs(e)*n);const S=h%n;d&&(d.v=t[S],r.push(d))}return r}function Zd(i,o){const e=[];let t;if(o.startRow<i.startRow)t=a.Direction.UP;else if(o.endRow>i.endRow)t=a.Direction.DOWN;else if(o.startColumn<i.startColumn)t=a.Direction.LEFT;else if(o.endColumn>i.endColumn)t=a.Direction.RIGHT;else return[];if(t===a.Direction.DOWN||t===a.Direction.UP){const n=i.endRow-i.startRow+1,r=o.endRow-o.startRow+1,s=Math.floor(r/n),l=r%n,c={startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:i.endColumn-i.startColumn};if(t===a.Direction.DOWN){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:i.startRow+(d+1)*n,col:i.startColumn},relativeRange:c});l>0&&e.push({repeatStartCell:{row:i.startRow+(s+1)*n,col:i.startColumn},relativeRange:{startRow:0,startColumn:0,endRow:l-1,endColumn:i.endColumn-i.startColumn}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:i.startRow-(d+1)*n,col:i.startColumn},relativeRange:c});l>0&&e.push({repeatStartCell:{row:i.startRow-(s+1)*n,col:i.startColumn},relativeRange:{startRow:n-l,endRow:n-1,startColumn:0,endColumn:i.endColumn-i.startColumn}})}}if(t===a.Direction.RIGHT||t===a.Direction.LEFT){const n=i.endColumn-i.startColumn+1,r=o.endColumn-o.startColumn+1,s=Math.floor(r/n),l=r%n,c={startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:i.endColumn-i.startColumn};if(t===a.Direction.RIGHT){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:i.startRow,col:i.startColumn+(d+1)*n},relativeRange:c});l>0&&e.push({repeatStartCell:{row:i.startRow,col:i.startColumn+(s+1)*n},relativeRange:{startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:l-1}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:i.startRow,col:i.startColumn-(d+1)*n},relativeRange:c});l>0&&e.push({repeatStartCell:{row:i.startRow,col:i.startColumn-(s+1)*n},relativeRange:{startRow:0,startColumn:n-l,endRow:i.endRow-i.startRow,endColumn:n-1}})}}return e}function oa(i){return!(a.isFormulaString(i.f)||a.isFormulaId(i.si)||i.t===a.CellValueType.BOOLEAN)}function Ot(i){i&&"custom"in i&&delete i.custom}var ln=(i=>(i.Append="APPEND",i.Default="DEFAULT",i.Only="ONLY",i))(ln||{}),Ie=(i=>(i.NUMBER="number",i.DATE="date",i.EXTEND_NUMBER="extendNumber",i.CHN_NUMBER="chnNumber",i.CHN_WEEK2="chnWeek2",i.CHN_WEEK3="chnWeek3",i.LOOP_SERIES="loopSeries",i.FORMULA="formula",i.OTHER="other",i))(Ie||{}),le=(i=>(i.COPY="COPY",i.SERIES="SERIES",i.ONLY_FORMAT="ONLY_FORMAT",i.NO_FORMAT="NO_FORMAT",i))(le||{});const Kd={type:Ie.DATE,priority:1100,match:(i,o)=>{var e;if(i!=null&&i.f||i!=null&&i.si)return!1;if((typeof(i==null?void 0:i.v)=="number"||(i==null?void 0:i.t)===a.CellValueType.NUMBER)&&i.s){if(typeof i.s=="string"){const n=o.get(a.IUniverInstanceService).getFocusedUnit().getStyles().get(i.s),r=(e=n==null?void 0:n.n)==null?void 0:e.pattern;if(r)return a.numfmt.getInfo(r).isDate}else if(i.s.n&&a.numfmt.getInfo(i.s.n.pattern).isDate)return!0}return!1},isContinue:(i,o)=>i.type===Ie.DATE,applyFunctions:{[le.SERIES]:(i,o,e)=>{const{data:t}=i;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),Xi(t,o,e).reverse()):Xi(t,o,e)}}},qd={type:Ie.NUMBER,priority:1e3,match:i=>typeof(i==null?void 0:i.v)=="number"||(i==null?void 0:i.t)===a.CellValueType.NUMBER,isContinue:(i,o)=>i.type===Ie.NUMBER,applyFunctions:{[le.SERIES]:(i,o,e)=>{const{data:t}=i;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),Xi(t,o,e).reverse()):Xi(t,o,e)}}},ra={type:Ie.OTHER,priority:0,match:()=>!0,isContinue:(i,o)=>i.type===Ie.OTHER},Qd={type:Ie.EXTEND_NUMBER,priority:900,match:i=>zi(`${i==null?void 0:i.v}`||"").isExtendNumber,isContinue:(i,o)=>{var e;if(i.type===Ie.EXTEND_NUMBER){const{beforeTxt:t,afterTxt:n}=zi(`${(e=i.cellData)==null?void 0:e.v}`||""),{beforeTxt:r,afterTxt:s}=zi(`${o==null?void 0:o.v}`||"");if(t===r&&n===s)return!0}return!1},applyFunctions:{[le.SERIES]:(i,o,e)=>{var l;const{data:t}=i,n=e===a.Direction.UP||e===a.Direction.LEFT;let r;if(t.length===1)return r=n?-1:1,We(ta(t,o,r),n);const s=[];for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`;d&&s.push(Number(zi(d).matchTxt))}return n&&(t.reverse(),s.reverse()),zn(s)?(r=s[1]-s[0],We(ta(t,o,r),n)):Rt(t,o)}}},Jd={type:Ie.CHN_NUMBER,priority:830,match:i=>!!Ld(`${i==null?void 0:i.v}`||""),isContinue:(i,o)=>i.type===Ie.CHN_NUMBER,applyFunctions:{[le.SERIES]:(i,o,e)=>{var c,d,u;const{data:t}=i,n=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){const h=`${(c=t[0])==null?void 0:c.v}`;let S;return n?S=-1:S=1,h&&(h==="日"||it(h)<7)?We(an(t,o,S),n):We(na(t,o,S),n)}let r=!1;for(let h=0;h<t.length;h++)if(((d=t[h])==null?void 0:d.v)==="日"){r=!0;break}const s=[];let l=0;for(let h=0;h<t.length;h++){const S=`${(u=t[h])==null?void 0:u.v}`;S==="日"?h===0?s.push(0):(l++,s.push(l*7)):r&&it(S)>0&&it(S)<7?s.push(it(S)+l*7):s.push(it(S))}if(n&&(t.reverse(),s.reverse()),zn(s)){if(r||s[s.length-1]<6&&s[0]>0||s[0]<6&&s[s.length-1]>0){const S=s[1]-s[0];return We(an(t,o,S),n)}const h=s[1]-s[0];return We(na(t,o,h),n)}return Rt(t,o)}}},$d={type:Ie.CHN_WEEK2,priority:820,match:i=>!!Ud(`${i==null?void 0:i.v}`||""),isContinue:(i,o)=>i.type===Ie.CHN_WEEK2,applyFunctions:{[le.SERIES]:(i,o,e)=>{var l;const{data:t}=i,n=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let c;return n?c=-1:c=1,We(an(t,o,c,1),n)}const r=[];let s=0;for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`,u=d==null?void 0:d.substr(d.length-1,1);d==="周日"?c===0?r.push(0):(s++,r.push(s*7)):r.push(it(u)+s*7)}if(n&&(t.reverse(),r.reverse()),zn(r)){const c=r[1]-r[0];return We(an(t,o,c,1),n)}return Rt(t,o)}}},eu={type:Ie.CHN_WEEK3,priority:810,match:i=>Bd(`${i==null?void 0:i.v}`||""),isContinue:(i,o)=>i.type===Ie.CHN_WEEK3,applyFunctions:{[le.SERIES]:(i,o,e)=>{var l;const{data:t}=i,n=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let c;return n?c=-1:c=1,We(an(t,o,c,2),n)}const r=[];let s=0;for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`;if(d){const u=d.substr(d.length-1,1);d==="星期日"?c===0?r.push(0):(s++,r.push(s*7)):r.push(it(u)+s*7)}}if(n&&(t.reverse(),r.reverse()),zn(r)){const c=r[1]-r[0];return We(an(t,o,c,2),n)}return Rt(t,o)}}},tu={type:Ie.LOOP_SERIES,priority:800,match:i=>Gd(`${i==null?void 0:i.v}`||""),isContinue:(i,o)=>{var e;return i.type===Ie.LOOP_SERIES?ir(`${(e=i.cellData)==null?void 0:e.v}`||"").name===ir(`${o==null?void 0:o.v}`||"").name:!1},applyFunctions:{[le.SERIES]:(i,o,e)=>{var c,d;const{data:t}=i,n=e===a.Direction.LEFT||e===a.Direction.UP,{series:r}=ir(`${(c=t[0])==null?void 0:c.v}`||"");if(t.length===1){let u;return n?u=-1:u=1,We(ia(t,o,u,r),n)}const s=[];let l=0;for(let u=0;u<t.length;u++){const h=`${(d=t[u])==null?void 0:d.v}`;h&&(h===r[0]?u===0?s.push(0):(l++,s.push(l*r.length)):s.push(r.indexOf(h)+l*7))}if(n&&(t.reverse(),s.reverse()),zn(s)){const u=s[1]-s[0];return We(ia(t,o,u,r),n)}return Rt(t,o)}}};function We(i,o){return o?i.reverse():i}var nu=Object.defineProperty,iu=Object.getOwnPropertyDescriptor,ou=(i,o,e,t)=>{for(var n=t>1?void 0:t?iu(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&nu(o,e,n),n},cn=(i,o)=>(e,t)=>o(e,t,i);y.AutoFillService=class extends a.Disposable{constructor(e,t,n,r,s,l){super();T(this,"_rules",[]);T(this,"_hooks",[]);T(this,"_applyType$",new A.BehaviorSubject(le.SERIES));T(this,"_isFillingStyle",!0);T(this,"_prevUndos",[]);T(this,"_autoFillLocation$",new A.BehaviorSubject(null));T(this,"autoFillLocation$",this._autoFillLocation$.asObservable());T(this,"_showMenu$",new A.BehaviorSubject(!1));T(this,"showMenu$",this._showMenu$.asObservable());T(this,"_direction",a.Direction.DOWN);T(this,"applyType$",this._applyType$.asObservable());T(this,"_menu$",new A.BehaviorSubject([{label:"autoFill.copy",value:le.COPY,disable:!1},{label:"autoFill.series",value:le.SERIES,disable:!1},{label:"autoFill.formatOnly",value:le.ONLY_FORMAT,disable:!1},{label:"autoFill.noFormat",value:le.NO_FORMAT,disable:!1}]));T(this,"menu$",this._menu$.asObservable());this._commandService=e,this._undoRedoService=t,this._renderManagerService=n,this._univerInstanceService=r,this._selectionManagerService=s,this._injector=l,this._init()}_init(){this._rules=[Kd,qd,Qd,Jd,$d,eu,tu,ra].sort((e,t)=>t.priority-e.priority),this._isFillingStyle=!0}_getOneByPriority(e){return e.length<=0?[]:[e.reduce((n,r)=>(r.priority||0)>(n.priority||0)?r:n,e[0])]}_initPrevUndo(){this._prevUndos=[]}async triggerAutoFill(e,t,n,r){var g;if(n.startColumn===r.startColumn&&n.startRow===r.startRow&&n.endColumn===r.endColumn&&n.endRow===r.endRow)return!1;if(r.endColumn<n.endColumn&&r.endColumn>n.startColumn)return this._commandService.executeCommand(dn.id,{clearRange:{startRow:r.startRow,endRow:r.endRow,startColumn:r.endColumn+1,endColumn:n.endColumn},selectionRange:r});if(r.endRow<n.endRow&&r.endRow>n.startRow)return this._commandService.executeCommand(dn.id,{clearRange:{startRow:r.endRow+1,endRow:n.endRow,startColumn:r.startColumn,endColumn:r.endColumn},selectionRange:r});const s={startRow:r.startRow,endRow:r.endRow,startColumn:r.startColumn,endColumn:r.endColumn};let l=null;if(r.startRow<n.startRow)l=a.Direction.UP,s.endRow=n.startRow-1;else if(r.endRow>n.endRow)l=a.Direction.DOWN,s.startRow=n.endRow+1;else if(r.startColumn<n.startColumn)l=a.Direction.LEFT,s.endColumn=n.startColumn-1;else if(r.endColumn>n.endColumn)l=a.Direction.RIGHT,s.startColumn=n.endColumn+1;else return!1;this.direction=l;const c=this._injector.invoke(f=>sn(n,f)),d=this._injector.invoke(f=>sn(s,f));if(!c||!d)return!1;this.autoFillLocation={source:c,target:d,unitId:e,subUnitId:t};const u=[];this.getActiveHooks().forEach(f=>{var C;const p=(C=f==null?void 0:f.onBeforeFillData)==null?void 0:C.call(f,{source:c,target:d,unitId:e,subUnitId:t},l);p&&u.unshift(p)}),this._initPrevUndo();for(let f=0;f<u.length;f++){const p=this.menu.find(C=>C.value===u[f]);if(p&&!p.disable)return this.fillData(u[f])}const S=(g=this.menu.find(f=>f.disable===!1))==null?void 0:g.value;return S?this.fillData(S):!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=ln.Append),this._hooks.push(e),a.toDisposable(()=>{const t=this._hooks.findIndex(n=>n===e);t>-1&&this._hooks.splice(t,1)})}registerRule(e){if(this._rules.find(n=>n.type===e.type))throw new Error(`Registry rule failed, type '${e.type}' already exist!`);const t=this._rules.findIndex(n=>n.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:n,subUnitId:r}=this.autoFillLocation||{};if(!e||!t||!n||!r)return[];const s=this._hooks.filter(u=>{var h;return!((h=u.disable)!=null&&h.call(u,{source:e,target:t,unitId:n,subUnitId:r},this._direction,this.applyType))}),l=s.filter(u=>u.type===ln.Only);if(l.length>0)return this._getOneByPriority(l);const c=this._getOneByPriority(s.filter(u=>u.type===ln.Default)),d=s.filter(u=>u.type===ln.Append)||[];return[...c,...d]}get applyType(){return this._applyType$.getValue()}set applyType(e){this._applyType$.next(e)}get menu(){return this._menu$.getValue()}get direction(){return this._direction}set direction(e){this._direction=e}isFillingStyle(){return this._isFillingStyle}setFillingStyle(e){this._isFillingStyle=e}get autoFillLocation(){return this._autoFillLocation$.getValue()}set autoFillLocation(e){this._autoFillLocation$.next(e)}setDisableApplyType(e,t){this._menu$.next(this._menu$.getValue().map(n=>n.value===e?{...n,disable:t}:n))}setShowMenu(e){this._showMenu$.next(e)}fillData(e){var v,b,E;this.applyType=e;const{source:t,target:n,unitId:r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId(),subUnitId:s=(v=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:v.getSheetId()}=this.autoFillLocation||{};if(!t||!n||!r||!s)return!1;const l=this.direction;this._prevUndos.length>0&&this._prevUndos.forEach(w=>{this._commandService.syncExecuteCommand(w.id,w.params)}),this._prevUndos=[];const c=a.Rectangle.union(ft(t),ft(n)),d=this.getActiveHooks(),u=this._univerInstanceService.getUnit(r,a.UniverInstanceType.UNIVER_SHEET);this._commandService.syncExecuteCommand(m.SetSelectionsOperation.id,{selections:[{primary:{...(E=(b=this._selectionManagerService.getCurrentLastSelection())==null?void 0:b.primary)!=null?E:c},range:{...c,rangeType:a.RANGE_TYPE.NORMAL}}],unitId:r,subUnitId:s});const h=[],S=[];d.forEach(w=>{var O;const{undos:R,redos:M}=((O=w.onFillData)==null?void 0:O.call(w,{source:t,target:n,unitId:r,subUnitId:s},l,e))||{};R&&h.push(...R),M&&S.push(...M)});const g=S.every(w=>this._commandService.syncExecuteCommand(w.id,w.params)),f=[];e!==le.NO_FORMAT&&S.forEach(w=>{if(w.id===m.SetRangeValuesMutation.id){const{cellValue:R}=w.params;new a.ObjectMatrix(R).forValue((O,N,D)=>{const H=Object.keys(u.getStyles().get(D==null?void 0:D.s)||{});(D!=null&&D.p||H.length&&tr.some(k=>H.includes(k)))&&f.push({startRow:O,endRow:O,startColumn:N,endColumn:N})})}});const p=this._getAutoHeightUndoRedos(r,s,f);return p.redos.every(w=>this._commandService.syncExecuteCommand(w.id,w.params))&&(h.push(...p.undos),S.push(...p.redos)),g&&(this._prevUndos=h,this._undoRedoService.pushUndoRedo({unitID:r,undoMutations:h,redoMutations:S})),d.forEach(w=>{var R;(R=w.onAfterFillData)==null||R.call(w,{source:t,target:n,unitId:r,subUnitId:s},l,e)}),this.setShowMenu(!0),!0}_getAutoHeightUndoRedos(e,t,n){var h,S;const r=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(y.SheetSkeletonManagerService),s=(S=r==null?void 0:r.getCurrentParam())==null?void 0:S.skeleton;if(!s)return{redos:[],undos:[]};const l=s.calculateAutoHeightInRange(n),c={subUnitId:t,unitId:e,rowsAutoHeightInfo:l},d=s.worksheet,u=m.SetWorksheetRowAutoHeightMutationFactory(c,d);return{undos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:u}],redos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:c}]}}},y.AutoFillService=ou([cn(0,a.ICommandService),cn(1,a.IUndoRedoService),cn(2,P.IRenderManagerService),cn(3,a.Inject(a.IUniverInstanceService)),cn(4,a.Inject(m.SheetsSelectionsService)),cn(5,a.Inject(a.Injector))],y.AutoFillService);const pt=a.createIdentifier("univer.auto-fill-service"),Ct={type:a.CommandType.COMMAND,id:"sheet.command.auto-fill",handler:async(i,o)=>{const e=i.get(pt),t=i.get(a.IUniverInstanceService),{sourceRange:n,targetRange:r}=o,s=m.getSheetCommandTarget(t);if(!s)return!1;const{subUnitId:l,unitId:c}=s;return e.triggerAutoFill(c,l,n,r)}},dn={id:"sheet.command.auto-clear-content",type:a.CommandType.COMMAND,handler:async(i,o)=>{const e=i.get(a.IUniverInstanceService),t=i.get(a.ICommandService),n=i.get(a.IUndoRedoService),r=i.get(m.SheetInterceptorService),s=m.getSheetCommandTarget(e);if(!s)return!1;const{unitId:l,subUnitId:c}=s,{clearRange:d,selectionRange:u}=o,h={subUnitId:c,unitId:l,cellValue:m.generateNullCellValue([d])},S=m.SetRangeValuesUndoMutationFactory(i,h),{startColumn:g,startRow:f}=u,p={selections:[{primary:{startColumn:g,startRow:f,endColumn:g,endRow:f,actualRow:f,actualColumn:g,isMerged:!1,isMergedMainCell:!1},range:{...u}}],unitId:l,subUnitId:c};if(t.executeCommand(m.SetSelectionsOperation.id,p),t.syncExecuteCommand(m.SetRangeValuesMutation.id,h)){const v=r.afterCommandExecute({id:m.SetRangeValuesMutation.id,params:h});return a.sequenceExecute(v.redos,t),n.pushUndoRedo({unitID:l,undoMutations:[{id:m.SetRangeValuesMutation.id,params:S},...v.undos],redoMutations:[{id:m.SetRangeValuesMutation.id,params:h},...v.redos]}),!0}return!1}},Yn={id:"sheet.command.refill",type:a.CommandType.COMMAND,handler:async(i,o)=>i.get(pt).fillData(o.type)};var ru=Object.defineProperty,su=Object.getOwnPropertyDescriptor,au=(i,o,e,t)=>{for(var n=t>1?void 0:t?su(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&ru(o,e,n),n},At=(i,o)=>(e,t)=>o(e,t,i);y.EditorBridgeService=class extends a.Disposable{constructor(e,t,n,r,s,l,c){super();T(this,"_editorUnitId",a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);T(this,"_editorIsDirty",!1);T(this,"_isDisabled",!1);T(this,"_visible",{visible:!1,eventType:P.DeviceInputEventType.Dblclick,unitId:""});T(this,"_currentEditCell",null);T(this,"_currentEditCellState",null);T(this,"_currentEditCellLayout",null);T(this,"_currentEditCellState$",new A.BehaviorSubject(null));T(this,"currentEditCellState$",this._currentEditCellState$.asObservable());T(this,"_currentEditCellLayout$",new A.BehaviorSubject(null));T(this,"currentEditCellLayout$",this._currentEditCellLayout$.asObservable());T(this,"currentEditCell$",this._currentEditCellState$.pipe(A.switchMap(e=>this._currentEditCellLayout$.pipe(A.map(t=>e&&t?{...e,...t}:null)))));T(this,"_visible$",new A.BehaviorSubject(this._visible));T(this,"visible$",this._visible$.asObservable());T(this,"_afterVisible$",new A.BehaviorSubject(this._visible));T(this,"afterVisible$",this._afterVisible$.asObservable());T(this,"_forceKeepVisible$",new A.BehaviorSubject(!1));T(this,"forceKeepVisible$",this._forceKeepVisible$.asObservable());this._sheetInterceptorService=e,this._renderManagerService=t,this._themeService=n,this._univerInstanceService=r,this._editorService=s,this._refSelectionsService=l,this._contextService=c,this.disposeWithMe(a.toDisposable(()=>{this._currentEditCellState$.complete(),this._currentEditCell=null})),this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).subscribe(d=>{var u;d.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:n,scaleY:r,canvasOffset:s,...l}=e;this._currentEditCellState=l,this._currentEditCellLayout={position:t,scaleX:n,scaleY:r,canvasOffset:s},this._currentEditCellState$.next(this._currentEditCellState),this._currentEditCellLayout$.next(this._currentEditCellLayout)}refreshEditCellPosition(e){var M;const t=this._currentEditCell;if(t==null)return;const n=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET);if(!n)return;const r=(M=n.with(y.SheetSkeletonManagerService).getSkeletonParam(t.sheetId))==null?void 0:M.skeleton,s=n.with(Ce);if(!r||!this._currentEditCellState)return;const{primary:l,unitId:c,sheetId:d,scene:u,engine:h}=t,S=xn(r,l);if(S==null)return;const g=a.convertCellToRange(S),f=Q.getCanvasOffsetByEngine(h);let{startX:p,startY:C,endX:v,endY:b}=g;const{scaleX:E,scaleY:w}=u.getAncestorScale(),R=u.getViewportScrollXY(s.getViewPort());p=P.convertTransformToOffsetX(p,E,R),C=P.convertTransformToOffsetY(C,w,R),v=P.convertTransformToOffsetX(v,E,R),b=P.convertTransformToOffsetY(b,w,R),e&&this._currentEditCellLayout&&(v=v-p+this._currentEditCellLayout.position.startX,b=b-C+this._currentEditCellLayout.position.startY,p=this._currentEditCellLayout.position.startX,C=this._currentEditCellLayout.position.startY),this._currentEditCellLayout={position:{startX:p,startY:C,endX:v,endY:b},canvasOffset:f,scaleX:E,scaleY:w},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:n,canvasOffset:r,scaleX:s,scaleY:l,...c}=t;this._currentEditCellState=c,this._currentEditCellLayout={position:n,canvasOffset:r,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}updateEditLocation(e,t){this._currentEditCellState&&(this._currentEditCellState={...this._currentEditCellState,row:e,column:t})}getLatestEditCellState(){var U,W,B;const e=this._currentEditCell;if(e==null)return;const t=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET);if(!t)return;const n=t.with(y.SheetSkeletonManagerService).getCurrentSkeleton(),r=t.with(Ce);if(!n)return;const{primary:s,unitId:l,sheetId:c,scene:d,engine:u}=e,{startRow:h,startColumn:S}=s,g=xn(n,s);if(g==null)return;const f=a.convertCellToRange(g),p=Q.getCanvasOffsetByEngine(u);let{startX:C,startY:v,endX:b,endY:E}=f;const{scaleX:w,scaleY:R}=d.getAncestorScale(),M=d.getViewportScrollXY(r.getViewPort());C=P.convertTransformToOffsetX(C,w,M),v=P.convertTransformToOffsetY(v,R,M),b=P.convertTransformToOffsetX(b,w,M),E=P.convertTransformToOffsetY(E,R,M);const O=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),N=O.getActiveSheet();if(!N)return;const D={workbook:O,worksheet:N,unitId:O.getUnitId(),subUnitId:N.getSheetId(),row:h,col:S,origin:N.getCellRaw(h,S)};let H;const k=this._sheetInterceptorService.writeCellInterceptor.fetchThroughInterceptors(m.BEFORE_CELL_EDIT)(N.getCell(h,S),D);H=k&&n.getCellDocumentModelWithFormula(k);const V=(U=H==null?void 0:H.documentModel)==null?void 0:U.documentStyle.renderConfig;if(V!=null&&(V.cellValueType=a.CellValueType.STRING),!H||H.documentModel==null){const F=n.getBlankCellDocumentModel(k);if(H!=null){const{verticalAlign:z,horizontalAlign:x,wrapStrategy:X,textRotation:Y,fill:J}=H,{centerAngle:ie,vertexAngle:$}=P.convertTextRotation(Y);F.documentModel.documentStyle.renderConfig={...V,verticalAlign:z,horizontalAlign:x,wrapStrategy:X,background:{rgb:J},centerAngle:ie,vertexAngle:$}}H=F}if(H.fill=H.fill||"#fff",(W=H.documentModel)==null||W.setZoomRatio(Math.max(w,R)),(k==null?void 0:k.isInArrayFormulaRange)===!0){const F=(B=H.documentModel)==null?void 0:B.getBody();F&&(F.textRuns=[{st:0,ed:F.dataStream.length-2,ts:{cl:{rgb:this._themeService.getCurrentTheme().textColorSecondary}}}])}return{position:{startX:C,startY:v,endX:b,endY:E},scaleX:w,scaleY:R,canvasOffset:p,row:h,column:S,unitId:l,sheetId:c,documentLayoutObject:H,editorUnitId:this._editorUnitId,isInArrayFormulaRange:k==null?void 0:k.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}},y.EditorBridgeService=au([At(0,a.Inject(m.SheetInterceptorService)),At(1,P.IRenderManagerService),At(2,a.Inject(a.ThemeService)),At(3,a.IUniverInstanceService),At(4,Q.IEditorService),At(5,m.IRefSelectionsService),At(6,a.IContextService)],y.EditorBridgeService);const ge=a.createIdentifier("univer.sheet-editor-bridge.service"),ve={id:"sheet.operation.set-cell-edit-visible",type:a.CommandType.OPERATION,handler:(i,o)=>o?(i.get(ge).changeVisible(o),!0):!1},jn={id:"sheet.operation.set-cell-edit-visible-f2",type:a.CommandType.OPERATION,handler:(i,o)=>{const e=i.get(a.ICommandService),n=i.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);return n?(e.syncExecuteCommand(ve.id,{...o,unitId:n.getUnitId()}),!0):!1}},Nt={id:"sheet.operation.set-cell-edit-visible-arrow",type:a.CommandType.OPERATION,handler:()=>!0},un={id:"sheet.command.change-zoom-ratio",type:a.CommandType.COMMAND,handler:(i,o)=>{if(!o)return!1;const e=i.get(a.IUniverInstanceService),t=m.getSheetCommandTarget(e);if(!t)return!1;const{worksheet:n,subUnitId:r,unitId:s}=t,{delta:l,reset:c}=o;let d=c?100:Math.round((n.getConfig().zoomRatio+l)*100);d=Math.max(jo[0],d),d=Math.min(jo[1],d);const u=d/100,S=i.get(ge).isVisible();return(S.unitId===s||S.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&S.visible?!1:i.get(a.ICommandService).executeCommand(Le.id,{unitId:s,subUnitId:r,zoomRatio:u})}},hn={id:"sheet.command.set-zoom-ratio",type:a.CommandType.COMMAND,handler:(i,o)=>{if(!o)return!1;const{unitId:e,subUnitId:t,zoomRatio:n}=o,s=i.get(ge).isVisible();return(s.unitId===e||s.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&s.visible?!1:i.get(a.ICommandService).executeCommand(Le.id,{unitId:e,subUnitId:t,zoomRatio:n})}};function lu(i){return typeof i.isMainScene>"u"}function ze(i,o){const e=i instanceof a.Workbook?i:i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!e)return null;const t=e.getUnitId();let n,r,s,l;if(lu(o)){const S=o.getRenderById(t);if(S==null)return null;n=S.components,n=S.components,r=S.mainComponent,s=S.scene,l=S.engine}else n=o.components,r=o.mainComponent,s=o.scene,l=o.engine;if(!n||!r)return null;const c=r,d=n.get(he.ROW),u=n.get(he.COLUMN),h=n.get(he.LEFT_TOP);return{spreadsheet:c,spreadsheetRowHeader:d,spreadsheetColumnHeader:u,spreadsheetLeftTopPlaceholder:h,scene:s,engine:l}}function or(i,o,e,t){const{startX:n,startY:r,endX:s,endY:l}=t.getCellWithCoordByIndex(i,o);return{startX:n,startY:r,endX:s,endY:l}}function Ke(i,o,e,t,n,r){const s=e.getCoordRelativeToViewport(P.Vector2.FromArray([i,o])),{x:l,y:c}=s,d=e.getScrollXYInfoByViewport(s,n),{scaleX:u,scaleY:h}=e.getAncestorScale(),S=t.getCellIndexByOffset(l,c,u,h,d,{closeFirst:r}),{row:g,column:f}=S,p=t.getNoMergeCellWithCoordByIndex(g,f),{startX:C,startY:v,endX:b,endY:E}=p;return{startX:C,startY:v,endX:b,endY:E,row:g,column:f}}function Gn(i,o,e,t){const n=e.getCoordRelativeToViewport(P.Vector2.FromArray([i,o])),r=e.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN),s=e.getScrollXYInfoByViewport(n,r),{scaleX:l,scaleY:c}=e.getAncestorScale(),{x:d,y:u}=s,h=i/l+d,S=o/c+u;return{x:h,y:S}}var cu=Object.defineProperty,du=Object.getOwnPropertyDescriptor,uu=(i,o,e,t)=>{for(var n=t>1?void 0:t?du(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&cu(o,e,n),n},Yi=(i,o)=>(e,t)=>o(e,t,i);let Zn=class extends a.Disposable{constructor(o,e,t,n,r){super();T(this,"_zoom");this._context=o,this._sheetSkeletonManagerService=e,this._commandService=t,this._contextService=n,this._editorBridgeService=r,this._initSkeletonListener(),this._initZoomEventListener()}updateZoom(o,e){const t=this._context.unit.getSheetBySheetId(o);return t?(t.getConfig().zoomRatio=e,t===this._context.unit.getActiveSheet()&&this._updateViewZoom(e),!0):!1}_initZoomEventListener(){const o=this._getSheetObject().scene;this.disposeWithMe(o.onMouseWheel$.subscribeEvent(e=>{if(!e.ctrlKey||!this._contextService.getContextValue(a.FOCUSING_SHEET))return;if(this._editorBridgeService){const d=this._editorBridgeService.isVisible();if((d.unitId===this._context.unitId||d.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&d.visible)return}const t=Math.abs(e.deltaX);let n=t<40?.2:t<80?.4:.2;n*=e.deltaY>0?-1:1,o.scaleX<1&&(n/=2);const r=this._context.unit,s=r.getActiveSheet();if(!s)return;const l=s.getZoomRatio();let c=+Number.parseFloat(`${l+n}`).toFixed(1);c=c>=4?4:c<=.1?.1:c,this._commandService.executeCommand(hn.id,{zoomRatio:Math.round(c*10)/10,unitId:r.getUnitId(),subUnitId:s.getSheetId()}),e.preventDefault()}))}_initSkeletonListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(o=>{if(o==null)return;const t=this._context.unit.getActiveSheet();if(!t)return;const n=t.getZoomRatio()||1;this._zoom!==n&&this._updateViewZoom(n),this._zoom=n}))}_updateViewZoom(o){const e=this._getSheetObject();e==null||e.scene.scale(o,o),e==null||e.spreadsheet.makeForceDirty()}_getSheetObject(){return ze(this._context.unit,this._context)}};Zn=uu([Yi(1,a.Inject(y.SheetSkeletonManagerService)),Yi(2,a.ICommandService),Yi(3,a.IContextService),Yi(4,a.Optional(ge))],Zn);const Le={id:"sheet.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(i,o)=>{const t=i.get(P.IRenderManagerService).getRenderById(o.unitId);return t?t.with(Zn).updateZoom(o.subUnitId,o.zoomRatio):!1}};var hu=Object.defineProperty,mu=Object.getOwnPropertyDescriptor,Su=(i,o,e,t)=>{for(var n=t>1?void 0:t?mu(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&hu(o,e,n),n},rr=(i,o)=>(e,t)=>o(e,t,i);const sa="univer-sheet-main-canvas";y.SheetsRenderService=class extends a.RxDisposable{constructor(e,t,n){super();T(this,"_skeletonChangeMutations",new Set);this._contextService=e,this._instanceSrv=t,this._renderManagerService=n,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(A.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(A.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(n=>{n.unitId===t&&(n.engine.getCanvas().setId(`${sa}_${t}`),n.engine.getCanvas().getContext().setId(`${sa}_${t}`))}),this._renderManagerService.createRender(t)}_disposeRenderer(e){const t=e.getUnitId();this._renderManagerService.removeRender(t)}_initContextListener(){this.disposeWithMe(this._contextService.subscribeContextValue$(P.RENDER_RAW_FORMULA_KEY).pipe(A.distinctUntilChanged()).subscribe(()=>{this._renderManagerService.getRenderAll().forEach(e=>{e.mainComponent instanceof P.Spreadsheet&&e.mainComponent.makeForceDirty(!0)})}))}},y.SheetsRenderService=Su([rr(0,a.IContextService),rr(1,a.IUniverInstanceService),rr(2,P.IRenderManagerService)],y.SheetsRenderService);var gu=Object.defineProperty,fu=Object.getOwnPropertyDescriptor,pu=(i,o,e,t)=>{for(var n=t>1?void 0:t?fu(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&gu(o,e,n),n},Dt=(i,o)=>(e,t)=>o(e,t,i);y.AutoFillController=class extends a.Disposable{constructor(e,t,n,r,s,l,c){super();T(this,"_beforeApplyData",[]);T(this,"_currentLocation",null);T(this,"_copyData",[]);T(this,"_defaultHook");this._univerInstanceService=e,this._commandService=t,this._autoFillService=n,this._editorBridgeService=r,this._renderManagerService=s,this._injector=l,this._sheetsRenderService=c,this._defaultHook={id:"default",type:ln.Default,priority:0,onBeforeFillData:(d,u)=>this._presetAndCacheData(d,u),onFillData:(d,u,h)=>this._fillData(d,u,h)},this._init()}_init(){this._initDefaultHook(),this._initSelectionControlFillChanged(),this._initQuitListener(),this._initSkeletonChange()}_initSkeletonChange(){this.disposeWithMe(this._sheetsRenderService.registerSkeletonChangingMutations(Ct.id))}_initDefaultHook(){this.disposeWithMe(this._autoFillService.addHook(this._defaultHook))}_initQuitListener(){const e=[ve.id,dn.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,n)=>{var c,d;const r=n==null?void 0:n.fromCollab,s=n==null?void 0:n.fromSync,l=n==null?void 0:n.fromFormula;e.includes(t.id)&&!r&&!s&&!l&&t.params.trigger!==Ct.id&&t.params.trigger!==Yn.id&&this._quit(),t.id===m.RemoveSheetMutation.id&&t.params.unitId===((c=this._currentLocation)==null?void 0:c.unitId)&&t.params.subUnitId===((d=this._currentLocation)==null?void 0:d.subUnitId)&&this._quit()})),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{var n;t.getUnitId()===((n=this._currentLocation)==null?void 0:n.unitId)&&this._quit()}))}_quit(){this._currentLocation=null,this._beforeApplyData=[],this._copyData=[],this._autoFillService.setShowMenu(!1)}_initSelectionControlFillChanged(){const e=new a.DisposableCollection,t=()=>{e.dispose();const n=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET);if(!n)return;n.with(Ce).getSelectionControls().forEach(l=>{e.add(l.selectionFilled$.subscribe(c=>{if(c==null||c.startColumn===-1||c.startRow===-1||c.endColumn===-1||c.endRow===-1)return;const d={startColumn:l.model.startColumn,endColumn:l.model.endColumn,startRow:l.model.startRow,endRow:l.model.endRow},u={startColumn:c.startColumn,endColumn:c.endColumn,startRow:c.startRow,endRow:c.endRow};this._commandService.executeCommand(Ct.id,{sourceRange:d,targetRange:u})})),e.add(l.fillControl.onDblclick$.subscribeEvent(()=>{const c={startColumn:l.model.startColumn,endColumn:l.model.endColumn,startRow:l.model.startRow,endRow:l.model.endRow};this._handleDbClickFill(c)})),e.add(l.fillControl.onPointerDown$.subscribeEvent(()=>{this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(ve.id,{visible:!1,eventType:P.DeviceInputEventType.PointerDown,unitId:n.unitId})}))})};t(),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{n.id===m.SetSelectionsOperation.id&&t()})),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(()=>t()))}_handleDbClickFill(e){const t=this._detectFillRange(e);t.endRow<=e.endRow||this._commandService.executeCommand(Ct.id,{sourceRange:e,targetRange:t})}_detectFillRange(e){var S,g,f,p,C,v;const{startRow:t,endRow:n,startColumn:r,endColumn:s}=e,l=(S=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET))==null?void 0:S.getActiveSheet();if(!l)return e;const c=l.getCellMatrix(),d=l.getMaxRows()-1,u=l.getMaxColumns()-1;let h=n;if(r>0&&((g=c.getValue(t,r-1))==null?void 0:g.v)!=null){let b=t;for(;((f=c.getValue(b,r-1))==null?void 0:f.v)!=null&&b<d;)b+=1;h=b-1}else if(s<u&&((p=c.getValue(n,s+1))==null?void 0:p.v)!=null){let b=t;for(;((C=c.getValue(b,s+1))==null?void 0:C.v)!=null&&b<d;)b+=1;h=b-1}for(let b=n+1;b<=h;b++)for(let E=r;E<=s;E++)if(((v=c.getValue(b,E))==null?void 0:v.v)!=null){h=b-1;break}return{startColumn:r,endColumn:s,startRow:t,endRow:h}}_getApplyData(e,t,n,r,s,l=!0){const c=[],d=Math.floor(n/t),u=n%t,h=this._autoFillService.getRules();if(!l&&s===le.ONLY_FORMAT)return console.error("ERROR: only format can not be applied when hasStyle is false"),[];const S={};h.forEach(g=>{S[g.type]=[]}),h.forEach(g=>{const{type:f,applyFunctions:p={}}=g,C=e[f];C&&C.forEach(v=>{const b=xd(v.index,u),E=v.index.length*d+b,w=this._applyFunctions(v,E,r,s,p,e),R=Fd(t,n,v.index);S[f].push({data:w,index:R})})});for(let g=0;g<n;g++)h.forEach(f=>{const{type:p}=f,C=S[p];for(let v=0;v<C.length;v++)g in C[v].index&&c.push(C[v].data[C[v].index[g]])});return c}_applyFunctions(e,t,n,r,s,l){const{data:c}=e,d=n===a.Direction.UP||n===a.Direction.LEFT;if(r===le.COPY){const u=s==null?void 0:s[le.COPY];return u?u(e,t,n,l):(d&&c.reverse(),Rt(c,t))}if(r===le.SERIES){const u=s==null?void 0:s[le.SERIES];return u?u(e,t,n,l):(d&&c.reverse(),s!=null&&s[le.COPY]?s[le.COPY](e,t,n,l):Rt(c,t))}if(r===le.ONLY_FORMAT){const u=s==null?void 0:s[le.ONLY_FORMAT];return u?u(e,t,n,l):zd(c,t)}}_getCopyData(e,t){const n=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!n)throw new Error("No active sheet found");const r=n.getCellMatrix(),s=this._autoFillService.getRules(),l=[],c=t===a.Direction.DOWN||t===a.Direction.UP;let d,u;return c?(d=e.cols,u=e.rows):(d=e.rows,u=e.cols),d.forEach(h=>{const S=this._getEmptyCopyDataPiece(),g={type:void 0,cellData:void 0};u.forEach(f=>{let p;c?p=r.getValue(f,h):p=r.getValue(h,f);const{type:C,isContinue:v}=s.find(b=>b.match(p,this._injector))||ra;if(v(g,p)){const b=S[C],E=b[b.length-1];E.data.push(p),E.index.push(f-u[0])}else{const b=S[C];b?b.push({data:[p],index:[f-u[0]]}):S[C]=[{data:[p],index:[f-u[0]]}]}g.type=C,g.cellData=p}),l.push(S)}),l}_getEmptyCopyDataPiece(){const e={};return this._autoFillService.getRules().forEach(t=>{e[t.type]=[]}),e}_getMergeApplyData(e,t,n,r){const s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!s)throw new Error("No active sheet found");const l=[];for(let c=e.startRow;c<=e.endRow;c++)for(let d=e.startColumn;d<=e.endColumn;d++){const{isMergedMainCell:u,startRow:h,startColumn:S,endRow:g,endColumn:f}=s.getCellInfoInMergeData(c,d);if(u){if(n===a.Direction.DOWN){let p=h+r,C=g+r;for(;C<=t.endRow;)l.push({startRow:p,startColumn:S,endRow:C,endColumn:f}),p+=r,C+=r}else if(n===a.Direction.UP){let p=h-r,C=g-r;for(;p>=t.startRow;)l.push({startRow:p,startColumn:S,endRow:C,endColumn:f}),p-=r,C-=r}else if(n===a.Direction.RIGHT){let p=S+r,C=f+r;for(;C<=t.endColumn;)l.push({startRow:h,startColumn:p,endRow:g,endColumn:C}),p+=r,C+=r}else if(n===a.Direction.LEFT){let p=S-r,C=f-r;for(;p>=t.startColumn;)l.push({startRow:h,startColumn:p,endRow:g,endColumn:C}),p-=r,C-=r}}}return l}_presetAndCacheData(e,t){const{source:n,target:r}=e,s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!s)throw new Error("No active sheet found");const l=s.getCellMatrix(),c=[];return r.rows.forEach(d=>{const u=[];r.cols.forEach(h=>{u.push(a.Tools.deepClone(l.getValue(d,h)))}),c.push(u)}),this._beforeApplyData=c,this._copyData=this._getCopyData(n,t),this._currentLocation=e,this._shouldDisableSeries(this._copyData)?(this._autoFillService.setDisableApplyType(le.SERIES,!0),le.COPY):(this._autoFillService.setDisableApplyType(le.SERIES,!1),this._getPreferredApplyType(this._copyData))}_fillData(e,t,n){var U,W;const r=[],s=[];let l=!0;n===le.NO_FORMAT&&(l=!1,n=le.SERIES);const{source:c,target:d,unitId:u,subUnitId:h}=e;if(!c||!d||t==null)return{undos:r,redos:s};const S=ft(c),g=ft(d),{cols:f,rows:p}=d,{cols:C,rows:v}=c,b=this._copyData;let E;t===a.Direction.DOWN||t===a.Direction.UP?E=v.length:E=C.length;const w=[];if(t===a.Direction.DOWN||t===a.Direction.UP){const B=p.length,F=[];f.forEach((z,x)=>{const X=b[x],Y=this._getApplyData(X,E,B,t,n,l);F.push(Y)});for(let z=0;z<F[0].length;z++){const x=[];for(let X=0;X<F.length;X++)x.push({s:null,...F[X][z]});w.push(x)}}else{const B=f.length;p.forEach((F,z)=>{const x=b[z],X=this._getApplyData(x,E,B,t,n,l),Y=[];for(let J=0;J<X.length;J++)Y.push({s:null,...X[J]});w.push(Y)})}let R=[];const M=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getStyles();if(l?(R=this._getMergeApplyData(S,g,t,E),w.forEach(B=>{B.forEach(F=>{F&&M&&M&&(F.s=M.getStyleByCell(F))})})):w.forEach((B,F)=>{B.forEach((z,x)=>{z&&M&&(z.s=M.getStyleByCell(this._beforeApplyData[F][x])||null)})}),n===le.ONLY_FORMAT&&w.forEach((B,F)=>{B.forEach((z,x)=>{if(z){const X=this._beforeApplyData[F][x]||{};z.f=X.f,z.si=X.si,z.t=X.t,z.v=X.v}})}),l){const B=[],F=(W=(U=this._univerInstanceService.getUniverSheetInstance(u))==null?void 0:U.getSheetBySheetId(h))==null?void 0:W.getMergeData();F&&F.forEach(X=>{a.Rectangle.intersects(X,g)&&B.push(X)});const z={unitId:u,subUnitId:h,ranges:B},x=this._injector.invoke(m.RemoveMergeUndoMutationFactory,z);B.length&&(s.push({id:m.RemoveWorksheetMergeMutation.id,params:z}),r.unshift({id:m.AddWorksheetMergeMutation.id,params:x}))}const O={subUnitId:h,unitId:u,cellValue:Hd([d])},N=this._injector.invoke(m.SetRangeValuesUndoMutationFactory,O);s.push({id:m.SetRangeValuesMutation.id,params:O}),r.unshift({id:m.SetRangeValuesMutation.id,params:N});const D=new a.ObjectMatrix;p.forEach((B,F)=>{f.forEach((z,x)=>{w[F][x]&&D.setValue(B,z,w[F][x])})});const H=D.getMatrix(),k={subUnitId:h,unitId:u,cellValue:H},V=this._injector.invoke(m.SetRangeValuesUndoMutationFactory,k);if(this._autoFillService.getActiveHooks().forEach(B=>{var F;(F=B.onBeforeSubmit)==null||F.call(B,e,t,n,H)}),r.unshift({id:m.SetRangeValuesMutation.id,params:V}),s.push({id:m.SetRangeValuesMutation.id,params:k}),R!=null&&R.length){const B=m.getAddMergeMutationRangeByType(R),F={unitId:u,subUnitId:h,ranges:B},z=this._injector.invoke(m.AddMergeUndoMutationFactory,F);r.unshift({id:m.RemoveWorksheetMergeMutation.id,params:z}),s.push({id:m.AddWorksheetMergeMutation.id,params:F})}return{undos:r,redos:s}}_shouldDisableSeries(e){return e.every(t=>Object.keys(t).every(n=>{var r;return((r=t[n])==null?void 0:r.length)===0||[Ie.OTHER,Ie.FORMULA].includes(n)}))}_getPreferredApplyType(e){return e.every(n=>Object.keys(n).every(r=>{var s,l;return((s=n[r])==null?void 0:s.length)===0||((l=n[r])==null?void 0:l.length)===1&&n[r][0].data.length===1&&Ie.NUMBER===r}))?le.COPY:le.SERIES}},y.AutoFillController=pu([Dt(0,a.IUniverInstanceService),Dt(1,a.ICommandService),Dt(2,pt),Dt(3,ge),Dt(4,P.IRenderManagerService),Dt(5,a.Inject(a.Injector)),Dt(6,a.Inject(y.SheetsRenderService))],y.AutoFillController);var Cu=Object.defineProperty,vu=Object.getOwnPropertyDescriptor,_u=(i,o,e,t)=>{for(var n=t>1?void 0:t?vu(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&Cu(o,e,n),n},sr=(i,o)=>(e,t)=>o(e,t,i);y.CellCustomRenderController=class extends a.Disposable{constructor(e,t,n,r){super();T(this,"_enterActiveRender");this._context=e,this._sheetSkeletonManagerService=t,this._renderManagerService=n,this._permissionService=r,this._initEventBinding()}_initEventBinding(){const e=new a.DisposableCollection,t=this._context.unit,n=r=>{if(e.dispose(),!r)return;const s=this._context.unitId,{skeleton:l}=r,c=this._renderManagerService.getRenderById(s);if(c&&c.mainComponent){const d=c.mainComponent,u=g=>{const{offsetX:f,offsetY:p}=g,C=c.scene,v=t.getActiveSheet();if(!v)return;const b=C.getActiveViewportByCoord(P.Vector2.FromArray([f,p]));if(!b)return;const{scaleX:E,scaleY:w}=C.getAncestorScale(),R={x:b.viewportScrollX,y:b.viewportScrollY},M=l.getCellIndexByOffset(f,p,E,w,R),O=l.worksheet.getMergedCell(M.row,M.column),N={actualRow:O?O.startRow:M.row,actualCol:O?O.startColumn:M.column,mergeCell:O,row:M.row,col:M.column};if(!N||!l)return;const D=v.getCell(N.actualRow,N.actualCol);if(!D)return;const H=D.customRender;if(!(H!=null&&H.length))return;const k=N.actualRow,V=N.actualCol,U=H.sort(a.sortRules),W=v.getSheetId(),B={data:D,style:l.getStyles().getStyleByCell(D),primaryWithCoord:l.getCellWithCoordByIndex(N.actualRow,N.actualCol),unitId:s,subUnitId:W,row:k,col:V,workbook:t,worksheet:v},F={x:R.x+f/E,y:R.y+p/w},z=U.find(x=>{var X;return(X=x.isHit)==null?void 0:X.call(x,F,B)});if(z)return[z,B]},h=d.onPointerDown$.subscribeEvent(g=>{var p,C,v,b;const f=u(g);if(f){const[E,w]=f,{row:R,col:M,worksheet:O,unitId:N,subUnitId:D}=w;if(!((p=this._permissionService.composePermission([new m.WorkbookEditablePermission(N).id,new m.WorksheetEditPermission(N,D).id]))==null?void 0:p.every(V=>V.value)))return!1;const k=(v=(C=O.getCell(R,M))==null?void 0:C.selectionProtection)==null?void 0:v[0];if((k==null?void 0:k[m.UnitAction.Edit])===!1)return!1;(b=E.onPointerDown)==null||b.call(E,w,g)}}),S=a.fromEventSubject(d.onPointerMove$).pipe(A.throttleTime(30)).subscribe(g=>{var p,C,v,b,E,w;const f=u(g);if(f){const[R,M]=f;this._enterActiveRender?this._enterActiveRender.render!==R&&((C=(p=this._enterActiveRender.render).onPointerLeave)==null||C.call(p,this._enterActiveRender.cellContext,g),this._enterActiveRender={render:R,cellContext:M},(v=R.onPointerEnter)==null||v.call(R,M,g)):(this._enterActiveRender={render:R,cellContext:M},(b=R.onPointerEnter)==null||b.call(R,M,g))}else this._enterActiveRender&&((w=(E=this._enterActiveRender.render).onPointerLeave)==null||w.call(E,this._enterActiveRender.cellContext,g),this._enterActiveRender=null)});h&&e.add(h),S&&e.add(S)}};this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(n)),n(this._sheetSkeletonManagerService.getCurrentParam()),this.disposeWithMe(e)}},y.CellCustomRenderController=_u([sr(1,a.Inject(y.SheetSkeletonManagerService)),sr(2,P.IRenderManagerService),sr(3,a.IPermissionService)],y.CellCustomRenderController);class ar extends a.Disposable{constructor(){super(...arguments);T(this,"rangesStack",[]);T(this,"selectedRangeWorksheet","")}}var Iu=Object.defineProperty,bu=Object.getOwnPropertyDescriptor,Eu=(i,o,e,t)=>{for(var n=t>1?void 0:t?bu(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&Iu(o,e,n),n},aa=(i,o)=>(e,t)=>o(e,t,i);let mn=class{constructor(i,o){T(this,"_current",null);T(this,"_shortcutParam",[]);this._univerInstanceService=i,this._localeService=o}dispose(){this._shortcutParam=[]}getCurrentBySearch(i){return this._getCurrentBySearch(i)}getCurrent(){return this._getCurrentBySearch(this._current)}addOrUpdate(i){const o=this._getCurrentBySearch({unitId:i.unitId,sheetId:i.sheetId,keycode:i.keycode});if(o!=null){const e=this._shortcutParam.indexOf(o);this._shortcutParam.splice(e,1)}return this._shortcutParam.push(i),o}remove(i){if(i==null)return;const o=this._getCurrentBySearch(i);if(o==null)return;const e=this._shortcutParam.indexOf(o);return this._shortcutParam.splice(e,1)[0]}_getCurrentBySearch(i){return i==null?void 0:this._shortcutParam.find(e=>e.unitId===i.unitId&&e.sheetId===i.sheetId&&e.keycode===i.keycode)}};mn=Eu([aa(0,a.IUniverInstanceService),aa(1,a.Inject(a.LocaleService))],mn);var ji=(i=>(i.MergeAll="mergeAll",i.MergeVertical="mergeVertical",i.MergeHorizontal="mergeHorizontal",i))(ji||{});function vt(i,o,e,t,n=!0,r=1,s=!0){let l={...i};t==null&&(t={startRow:0,endRow:e.getRowCount()-1,startColumn:0,endColumn:e.getColumnCount()-1});let c;switch(o){case a.Direction.UP:for(c=i.startRow-r;c>-1&&!e.getRowVisible(c);)c-=1;c>=t.startRow?(l.startRow=c,l.endRow=c):s&&(l.startRow=t.endRow,l.endRow=t.endRow,n&&(l=vt(l,a.Direction.LEFT,e,t,!1)));break;case a.Direction.DOWN:for(c=i.endRow+r;c<e.getRowCount()&&!e.getRowVisible(c);)c+=1;c<=t.endRow?(l.startRow=c,l.endRow=c):s&&(l.startRow=t.startRow,l.endRow=t.startRow,n&&(l=vt(l,a.Direction.RIGHT,e,t,!1)));break;case a.Direction.LEFT:for(c=i.startColumn-r;c>-1&&!e.getColVisible(c);)c-=1;c>=t.startColumn?(l.startColumn=c,l.endColumn=c):s&&(l.startColumn=t.endColumn,l.endColumn=t.endColumn,n&&(l=vt(l,a.Direction.UP,e,t,!1)));break;case a.Direction.RIGHT:for(c=i.endColumn+r;c<e.getColumnCount()&&!e.getColVisible(c);)c+=1;c<=t.endColumn?(l.startColumn=c,l.endColumn=c):s&&(l.startColumn=t.startColumn,l.endColumn=t.startColumn,n&&(l=vt(l,a.Direction.DOWN,e,t,!1)));break}return l}function lr(i,o,e){const t={...i},{startRow:n,startColumn:r,endRow:s,endColumn:l}=Kn(i,o,e);let c=qn(e,n,r,s,l).hasValue,d=!0,u=!0;for(;u;){if(a.Direction.UP===o){let h=t.startRow-1;for(;h>-1&&!e.getRowVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:S,matrix:g}=qn(e,h,t.startColumn,h,t.endColumn);if(c&&!S&&!d){u=!1;break}else{if(g.getLength()!==0){let f=h;g.forValue(p=>{f=Math.min(p,f)}),t.startRow=f}else t.startRow=h;if(t.endRow=t.startRow,!c&&S){u=!1;break}c=S,d=!1}}if(a.Direction.DOWN===o){let h=t.endRow+1;for(;h<e.getRowCount()&&!e.getRowVisible(h);)h+=1;if(h===e.getRowCount()){u=!1;break}const{hasValue:S,matrix:g}=qn(e,h,t.startColumn,h,t.endColumn);if(c&&!S&&!d){u=!1;break}else{if(g.getLength()!==0){let f=h;g.forValue((p,C,v)=>{f=Math.max(p+(v.rowSpan||1)-1,f)}),t.endRow=f}else t.endRow=h;if(t.startRow=t.endRow,!c&&S){u=!1;break}c=S,d=!1}}if(a.Direction.LEFT===o){let h=t.startColumn-1;for(;h>-1&&!e.getColVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:S,matrix:g}=qn(e,t.startRow,h,t.endRow,h);if(c&&!S&&!d){u=!1;break}else{if(g.getLength()!==0){let f=h;g.forValue((p,C)=>{f=Math.min(C,f)}),t.startColumn=f}else t.startColumn=h;if(t.endColumn=t.startColumn,!c&&S){u=!1;break}c=S,d=!1}}if(a.Direction.RIGHT===o){let h=t.endColumn+1;for(;h<e.getColumnCount()&&!e.getColVisible(h);)h+=1;if(h===e.getColumnCount()){u=!1;break}const{hasValue:S,matrix:g}=qn(e,t.startRow,h,t.endRow,h);if(c&&!S&&!d){u=!1;break}else{if(g.getLength()!==0){let f=h;g.forValue((p,C,v)=>{f=Math.max(C+(v.colSpan||1)-1,f)}),t.endColumn=f}else t.endColumn=h;if(t.startColumn=t.endColumn,!c&&S){u=!1;break}c=S,d=!1}}}return m.alignToMergedCellsBorders(t,e,!0)}function la(i,o,e){return vt(i,o,e,void 0,!1,1,!1)}function Tu(i,o,e){const t=lr(i,o,e);return m.alignToMergedCellsBorders(a.Rectangle.union(t,i),e,!0)}function wu(i,o,e){const t=la(i,o,e),n={startRow:Math.min(i.startRow,t.startRow),startColumn:Math.min(i.startColumn,t.startColumn),endRow:Math.max(i.endRow,t.endRow),endColumn:Math.max(i.endColumn,t.endColumn)};return m.alignToMergedCellsBorders(a.Rectangle.union(i,n),e)}function yu(i,o,e,t){const n=a.getReverseDirection(e),r=lr(Kn(i,n,t),e,t);return e===a.Direction.UP&&r.startRow<=i.startRow?m.alignToMergedCellsBorders({...o,startColumn:i.startColumn,endColumn:i.endColumn},t,!0):e===a.Direction.DOWN&&r.endRow>=i.endRow?m.alignToMergedCellsBorders({...o,startColumn:i.startColumn,endColumn:i.endColumn},t,!0):e===a.Direction.LEFT&&r.startColumn<=i.startColumn?m.alignToMergedCellsBorders({...o,startRow:i.startRow,endRow:i.endRow},t,!0):e===a.Direction.RIGHT&&r.endColumn>=i.endColumn?m.alignToMergedCellsBorders({...o,startRow:i.startRow,endRow:i.endRow},t,!0):a.Rectangle.union(a.Rectangle.clone(o),r)}function Pu(i,o,e){const t=a.getReverseDirection(o),n=Kn(i,t,e),r=Kn(i,o,e),s=la(n,o,e);return m.alignToMergedCellsBorders(a.Rectangle.union(r,s),e,!1)}function ca(i){return{startRow:0,startColumn:0,endRow:i.getRowCount()-1,endColumn:i.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL}}function Kn(i,o,e){let t;switch(o){case a.Direction.UP:t={startRow:i.startRow,startColumn:i.startColumn,endRow:i.startRow,endColumn:i.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.DOWN:t={startRow:i.endRow,startColumn:i.startColumn,endRow:i.endRow,endColumn:i.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.LEFT:t={startRow:i.startRow,startColumn:i.startColumn,endRow:i.endRow,endColumn:i.startColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.RIGHT:t={startRow:i.startRow,startColumn:i.endColumn,endRow:i.endRow,endColumn:i.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;default:throw new Error("Invalid direction")}return m.alignToMergedCellsBorders(t,e,!1)}function qn(i,o,e,t,n){let r=!1;const s=i.getMatrixWithMergedCells(o,e,t,n).forValue((l,c,d)=>{if(Ru(d))return r=!0,!1});return{hasValue:r,matrix:s}}function cr(i,o,e){const t=a.Rectangle.clone(i);if(o==null)return t;switch(e){case a.Direction.UP:case a.Direction.DOWN:t.startColumn=t.endColumn=o.actualColumn;break;case a.Direction.LEFT:case a.Direction.RIGHT:t.startRow=t.endRow=o.actualRow;break}return t}function Mu(i,o,e){var l,c,d,u;const{primary:t,range:n}=i,r=a.Rectangle.clone(n);switch(o){case a.Direction.UP:case a.Direction.DOWN:r.startRow=(l=t==null?void 0:t.startRow)!=null?l:n.startRow,r.endRow=(c=t==null?void 0:t.endRow)!=null?c:n.startRow;break;case a.Direction.LEFT:case a.Direction.RIGHT:r.startColumn=(d=t==null?void 0:t.startColumn)!=null?d:n.startColumn,r.endColumn=(u=t==null?void 0:t.endColumn)!=null?u:n.startColumn;break}const s=Kn(r,o,e);switch(o){case a.Direction.DOWN:return n.startRow<s.startRow;case a.Direction.UP:return n.endRow>s.endRow;case a.Direction.LEFT:return s.endColumn<n.endColumn;case a.Direction.RIGHT:return s.startColumn>n.startColumn}}function da(i,o){let e=i[0].startRow,t=i[0].endRow;i.forEach(r=>{const{startRow:s,endRow:l}=r;e=Math.min(e,s),t=Math.max(t,l)});const n=new Array(t-e+1).fill(!1);return o.forEach(r=>{const{startRow:s,endRow:l}=r;for(let c=Math.max(s,e);c<=Math.min(l,t);c++)n[c-e]=!0}),i.every(r=>{const{startRow:s,endRow:l}=r;for(let c=s;c<=l;c++)if(!n[c-e])return!1;return!0})}function ua(i,o){let e=i[0].startColumn,t=i[0].endColumn;i.forEach(r=>{const{startColumn:s,endColumn:l}=r;e=Math.min(e,s),t=Math.max(t,l)});const n=new Array(t-e+1).fill(!1);return o.forEach(r=>{const{startColumn:s,endColumn:l}=r;for(let c=Math.max(s,e);c<=Math.min(l,t);c++)n[c-e]=!0}),i.every(r=>{const{startColumn:s,endColumn:l}=r;for(let c=s;c<=l;c++)if(!n[c-e])return!1;return!0})}function dr(i,o){return o?i==="mergeAll"?o.filter(e=>!(e.startRow===e.endRow&&e.startColumn===e.endColumn)):i==="mergeVertical"?o.filter(e=>e.startRow!==e.endRow):i==="mergeHorizontal"?o.filter(e=>e.startColumn!==e.endColumn):o:null}function Ru(i){return i.v!==void 0&&i.v!==null&&i.v!==""||i.p!==void 0}var qe=(i=>(i[i.moveStopeOne=0]="moveStopeOne",i[i.moveGap=1]="moveGap",i[i.moveStepPage=2]="moveStepPage",i[i.moveStepEnd=3]="moveStepEnd",i))(qe||{});const Ae={id:"sheet.command.move-selection",type:a.CommandType.COMMAND,handler:(i,o)=>{if(!o)return!1;const e=m.getSheetCommandTarget(i.get(a.IUniverInstanceService));if(!e)return!1;const{workbook:t,worksheet:n}=e,r=m.getSelectionsService(i,o.fromCurrentSelection).getCurrentLastSelection();if(!r)return!1;const{direction:s,jumpOver:l,extra:c}=o,{range:d,primary:u}=r,h=cr(d,u,s),S=l===1?lr(h,s,n):vt(h,s,n),g=m.getCellAtRowCol(S.startRow,S.startColumn,n);if(a.Rectangle.equals(g,h))return!1;const f=t.getUnitId();i.get(mn).remove({unitId:f,sheetId:n.getSheetId(),keycode:_.KeyCode.TAB});const p=[{range:a.Rectangle.clone(g),primary:{startRow:g.startRow,startColumn:g.startColumn,endRow:g.endRow,endColumn:g.endColumn,actualRow:S.startRow,actualColumn:S.startColumn,isMerged:g.isMerged,isMergedMainCell:g.startRow===S.startRow&&g.startColumn===S.startColumn}}];return i.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:t.getUnitId(),subUnitId:n.getSheetId(),selections:p,type:m.SelectionMoveType.MOVE_END,extra:c,reveal:!0})}},Qe={id:"sheet.command.move-selection-enter-tab",type:a.CommandType.COMMAND,handler:(i,o)=>{var B;if(!o)return!1;const e=m.getSheetCommandTarget(i.get(a.IUniverInstanceService));if(!e)return!1;const{workbook:t,worksheet:n}=e,r=m.getSelectionsService(i),{direction:s,keycode:l}=o,c=s===a.Direction.LEFT||s===a.Direction.UP,d=r.getCurrentSelections().concat(),u=d.findIndex(F=>F.primary),h=d[u];if(!h)return!1;const S=c?-1:1,g=u+S!==d.length?d[u+S]:d[0],f=d.findIndex(F=>F===g),p=t.getUnitId(),C=n.getSheetId();if(!h)return!1;const{range:v}=h,b=h.primary;let E=cr(v,b,s);const w=i.get(mn),R=w.getCurrentBySearch({unitId:p,sheetId:C,keycode:_.KeyCode.TAB});let M;const{startRow:O,endRow:N,startColumn:D,endColumn:H}=v,k=c?b.startRow===O&&b.startColumn===D:b.endRow===N&&b.endColumn===H;if(a.Rectangle.equals(v,b)){if(l===_.KeyCode.TAB)R==null&&w.addOrUpdate({unitId:p,sheetId:C,keycode:_.KeyCode.TAB,selection:h});else{const x=R==null?void 0:R.selection;if(x!=null){const{range:X,primary:Y}=x;E=cr(X,Y,s)}w.remove({unitId:p,sheetId:C,keycode:_.KeyCode.TAB})}const F=vt(E,s,n),z=m.getCellAtRowCol(F.startRow,F.startColumn,n);if(a.Rectangle.equals(z,E))return!1;M={range:a.Rectangle.clone(z),primary:{startRow:z.startRow,startColumn:z.startColumn,endRow:z.endRow,endColumn:z.endColumn,actualRow:F.startRow,actualColumn:F.startColumn,isMerged:z.isMerged,isMergedMainCell:z.startRow===F.startRow&&z.startColumn===F.startColumn}}}else{w.remove({unitId:p,sheetId:C,keycode:_.KeyCode.TAB});const F=a.Tools.deepClone(b),z=k?g.range:vt({startRow:F.startRow,startColumn:F.startColumn,endRow:F.endRow,endColumn:F.endColumn},s,n,{startRow:O,endRow:N,startColumn:D,endColumn:H}),x=k&&c,X=x?m.getCellAtRowCol(z.endRow,z.endColumn,n):m.getCellAtRowCol(z.startRow,z.startColumn,n);M={range:k?g.range:a.Rectangle.clone(v),primary:{startRow:X.startRow,startColumn:X.startColumn,endRow:X.endRow,endColumn:X.endColumn,actualRow:x?X.startRow:z.startRow,actualColumn:x?X.startColumn:z.startColumn,isMerged:X.isMerged,isMergedMainCell:X.startRow===z.startRow&&X.startColumn===z.startColumn},style:k?g.style:h.style}}k?(d[u].primary=null,d[f]=M,r.setSelections(p,C,[],m.SelectionMoveType.MOVE_END)):d[u]=M;const V=i.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:p,subUnitId:C,type:m.SelectionMoveType.MOVE_END,selections:d,reveal:!0,extra:o.extra}),W=(B=i.get(P.IRenderManagerService).getRenderById(p))==null?void 0:B.with(Ce);return W==null||W.refreshSelectionMoveEnd(),V}},De={id:"sheet.command.expand-selection",type:a.CommandType.COMMAND,handler:(i,o)=>{if(!o)return!1;const e=m.getSheetCommandTarget(i.get(a.IUniverInstanceService));if(!e)return!1;const{worksheet:t,unitId:n,subUnitId:r}=e,s=m.getSelectionsService(i).getCurrentLastSelection();if(!s)return!1;const{range:l,primary:c}=s,{jumpOver:d,direction:u,extra:h}=o,g=Mu(s,u,t)?d===1?yu(l,{...a.Rectangle.clone(c),rangeType:a.RANGE_TYPE.NORMAL},u,t):Pu(l,u,t):d===1?Tu(l,u,t):wu(l,u,t);return g.rangeType=s.range.rangeType,a.Rectangle.equals(g,l)?!1:i.get(a.ICommandService).syncExecuteCommand(m.SetSelectionsOperation.id,{unitId:n,subUnitId:r,type:m.SelectionMoveType.ONLY_SET,selections:[{range:g,primary:c}],extra:h})}},Gi={id:"sheet.command.select-all",type:a.CommandType.COMMAND,handler:async(i,o={expandToGapFirst:!0,loop:!1})=>{const e=m.getSheetCommandTarget(i.get(a.IUniverInstanceService));if(!e)return!1;const t=m.getSelectionsService(i).getCurrentLastSelection();if(!t)return!1;const n=i.get(ar),{worksheet:r,unitId:s,subUnitId:l}=e,c=`${s}|${l}`;c!==n.selectedRangeWorksheet&&(n.rangesStack=[],n.selectedRangeWorksheet=c);const d=r.getMaxRows(),u=r.getMaxColumns(),{expandToGapFirst:h,loop:S}=o,{range:g,primary:f}=t,p=g.endColumn===u-1&&g.endRow===d-1&&g.startRow===0&&g.startColumn===0;n.rangesStack.some(v=>a.Rectangle.equals(v,g))||(n.rangesStack=[],n.rangesStack.push(g));let C;if(p)if(S){if(n.rangesStack.findIndex(b=>a.Rectangle.equals(b,g))!==n.rangesStack.length-1)return!1;C=n.rangesStack[0]}else return!1;else h?(C=m.expandToContinuousRange(g,{left:!0,right:!0,up:!0,down:!0},r),a.Rectangle.equals(C,g)&&(C=ca(r))):C=ca(r);return n.rangesStack.some(v=>a.Rectangle.equals(v,C))||n.rangesStack.push(C),i.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:s,subUnitId:l,reveal:!0,selections:[{range:C,primary:f}]})}};var Ou=Object.defineProperty,Au=Object.getOwnPropertyDescriptor,Nu=(i,o,e,t)=>{for(var n=t>1?void 0:t?Au(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&Ou(o,e,n),n},Du=(i,o)=>(e,t)=>o(e,t,i);y.SheetScrollManagerService=class{constructor(o,e){T(this,"_scrollStateMap",new Map);T(this,"_rawScrollInfo$",new A.BehaviorSubject(null));T(this,"rawScrollInfo$",this._rawScrollInfo$.asObservable());T(this,"validViewportScrollInfo$",new A.BehaviorSubject(null));T(this,"_searchParamForScroll",null);this._context=o,this._sheetSkeletonManagerService=e}dispose(){this._rawScrollInfo$.complete()}calcViewportScrollFromRowColOffset(o){if(!o)return{viewportScrollX:0,viewportScrollY:0};let{sheetViewStartColumn:e,sheetViewStartRow:t,offsetX:n,offsetY:r}=o;t=t||0,r=r||0;const s=this._sheetSkeletonManagerService.getCurrentSkeleton(),l=(s==null?void 0:s.rowHeightAccumulation[t-1])||0,d=((s==null?void 0:s.columnWidthAccumulation[e-1])||0)+n,u=l+r;return{viewportScrollX:d,viewportScrollY:u}}setSearchParam(o){this._searchParamForScroll=o}getScrollStateByParam(o){return this._getCurrentScroll(o)}getCurrentScrollState(){return this._getCurrentScroll(this._searchParamForScroll)}setValidScrollState(o){this._setScrollState(o)}emitRawScrollParam(o){this._emitRawScroll(o)}setValidScrollStateToCurrSheet(o){if(this._searchParamForScroll==null)return;this._setScrollState({...this._searchParamForScroll,...o});const e=this._searchParamForScroll.sheetId,t=this._sheetSkeletonManagerService.getSkeleton(e);t&&t.setScroll(o.viewportScrollX,o.viewportScrollY)}clear(){this._searchParamForScroll!=null&&this._clearByParamAndNotify(this._searchParamForScroll)}_setScrollState(o){const{unitId:e,sheetId:t,sheetViewStartColumn:n,sheetViewStartRow:r,offsetX:s,offsetY:l}=o;this._scrollStateMap.has(e)||this._scrollStateMap.set(e,new Map);const c=this._scrollStateMap.get(e),d={sheetViewStartRow:r,sheetViewStartColumn:n,offsetX:s,offsetY:l};c.set(t,d)}_clearByParamAndNotify(o){this._setScrollState({...o,sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0}),this._emitRawScroll({sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0})}_getCurrentScroll(o){var s;const e={sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0};if(o==null)return e;const{unitId:t,sheetId:n}=o;return((s=this._scrollStateMap.get(t))==null?void 0:s.get(n))||e}_emitRawScroll(o){this._rawScrollInfo$.next(o)}},y.SheetScrollManagerService=Nu([Du(1,a.Inject(y.SheetSkeletonManagerService))],y.SheetScrollManagerService);const Xe={id:"sheet.operation.set-scroll",type:a.CommandType.OPERATION,handler:(i,o)=>{if(!o)return!1;const{unitId:e,sheetId:t,offsetX:n,offsetY:r,sheetViewStartColumn:s,sheetViewStartRow:l}=o;return i.get(P.IRenderManagerService).getRenderById(e).with(y.SheetScrollManagerService).emitRawScrollParam({unitId:e,sheetId:t,offsetX:n,offsetY:r,sheetViewStartRow:l,sheetViewStartColumn:s}),!0}},Sn={id:"sheet.command.set-scroll-relative",type:a.CommandType.COMMAND,handler:async(i,o)=>{const e=i.get(a.ICommandService),t=i.get(a.IUniverInstanceService),n=i.get(P.IRenderManagerService),r=m.getSheetCommandTarget(t);if(!r)return!1;const{unitId:s,subUnitId:l}=r,d=n.getRenderById(s).with(y.SheetScrollManagerService).getCurrentScrollState(),{offsetX:u=0,offsetY:h=0}=o||{},{sheetViewStartRow:S=0,sheetViewStartColumn:g=0,offsetX:f=0,offsetY:p=0}=d||{};return e.executeCommand(Xe.id,{unitId:s,sheetId:l,sheetViewStartRow:S,sheetViewStartColumn:g,offsetX:f+u,offsetY:p+h})}},Ye={id:"sheet.command.scroll-view",type:a.CommandType.COMMAND,handler:(i,o)=>{if(!o)return!1;const e=i.get(a.IUniverInstanceService),t=i.get(P.IRenderManagerService),n=m.getSheetCommandTarget(e);if(!n)return!1;const{workbook:r,worksheet:s,unitId:l}=n,d=t.getRenderById(l).with(y.SheetScrollManagerService).getCurrentScrollState();if(!s)return!1;const{sheetViewStartRow:u,sheetViewStartColumn:h,offsetX:S,offsetY:g}=o,{sheetViewStartColumn:f,sheetViewStartRow:p,offsetX:C,offsetY:v}=d||{},{xSplit:b,ySplit:E}=n.worksheet.getConfig().freeze;return i.get(a.ICommandService).syncExecuteCommand(Xe.id,{unitId:r.getUnitId(),sheetId:s.getSheetId(),sheetViewStartRow:u!=null?u:p!=null?p:0+E,sheetViewStartColumn:h!=null?h:f!=null?f:0+b,offsetX:S!=null?S:C,offsetY:g!=null?g:v})}},ur={id:"sheet.command.scroll-to-cell",type:a.CommandType.COMMAND,handler:(i,o)=>{const e=i.get(a.IUniverInstanceService);return i.get(P.IRenderManagerService).getRenderById(e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(y.SheetsScrollRenderController).scrollToRange(o.range,o.forceTop,o.forceLeft)}},Hu={id:"sheet.command.scroll-view-reset",type:a.CommandType.COMMAND,handler:async i=>{const o=i.get(a.IUniverInstanceService),e=m.getSheetCommandTarget(o);if(!e)return!1;const{subUnitId:t,unitId:n}=e;return i.get(a.ICommandService).executeCommand(Xe.id,{unitId:n,sheetId:t,sheetViewStartRow:0,sheetViewStartColumn:0})}};var ku=Object.defineProperty,Vu=Object.getOwnPropertyDescriptor,Wu=(i,o,e,t)=>{for(var n=t>1?void 0:t?Vu(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&ku(o,e,n),n},gn=(i,o)=>(e,t)=>o(e,t,i);Ae.id,Qe.id;const Lu=3;y.SheetsScrollRenderController=class extends a.Disposable{constructor(o,e,t,n,r,s,l){super(),this._context=o,this._injector=e,this._sheetSkeletonManagerService=t,this._contextService=n,this._commandService=r,this._renderManagerService=s,this._scrollManagerService=l,this._initCommandListener(),this._wheelEventListener(),this._scrollBarEventListener(),this._initSkeletonListener()}_wheelEventListener(){const{scene:o}=this._context;if(!o)return;const e=o.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN);e&&this.disposeWithMe(o.onMouseWheel$.subscribeEvent((t,n)=>{if(t.ctrlKey||!this._contextService.getContextValue(a.FOCUSING_SHEET))return;let r=0,s=0;r=t.deltaX,t.shiftKey?r=(t.deltaY||t.deltaX)*Lu:s=t.deltaY,this._commandService.executeCommand(Sn.id,{offsetX:r,offsetY:s}),this._context.scene.makeDirty(!0);const l=e.limitedScroll(e.scrollX+r,e.scrollY+s);l&&!l.isLimitedX&&!l.isLimitedY&&(t.preventDefault(),o.getParent().classType===P.RENDER_CLASS_TYPE.SCENE_VIEWER&&n.stopPropagation()),e.isWheelPreventDefaultX&&e.isWheelPreventDefaultY&&t.preventDefault()}))}_scrollBarEventListener(){const{scene:o}=this._context;if(o==null)return;const e=o.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN);e&&(this.disposeWithMe(a.toDisposable(this._scrollManagerService.rawScrollInfo$.subscribe(t=>{var g;const n=(g=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:g.skeleton;if(!n)return;if(t==null){e.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});return}const{sheetViewStartRow:r,sheetViewStartColumn:s,offsetX:l,offsetY:c}=t,{startX:d,startY:u}=n.getCellWithCoordByIndex(r,s,!1),h=d+l,S=u+c;e.scrollToViewportPos({viewportScrollX:h,viewportScrollY:S})}))),this.disposeWithMe(e.onScrollAfter$.subscribeEvent(t=>{var p;const n=(p=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:p.skeleton;if(n==null||t.isTrigger===!1)return;const r=this._getSheetObject();if(n==null||r==null)return;const{viewportScrollX:s,viewportScrollY:l,scrollX:c,scrollY:d}=t,{row:u,column:h,rowOffset:S,columnOffset:g}=n.getOffsetRelativeToRowCol(s,l),f={sheetViewStartRow:u,sheetViewStartColumn:h,offsetX:g,offsetY:S,viewportScrollX:s,viewportScrollY:l,scrollX:c,scrollY:d};this._scrollManagerService.setValidScrollStateToCurrSheet(f),this._scrollManagerService.validViewportScrollInfo$.next({...f,viewportScrollX:s,viewportScrollY:l,scrollX:c,scrollY:d})})),this.disposeWithMe(e.onScrollByBar$.subscribeEvent(t=>{var S;const n=(S=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:S.skeleton;if(n==null||t.isTrigger===!1)return;const r=this._getSheetObject();if(n==null||r==null)return;const{viewportScrollX:s=0,viewportScrollY:l=0}=t;this._getFreeze();const{row:c,column:d,rowOffset:u,columnOffset:h}=n.getOffsetRelativeToRowCol(s,l);this._commandService.executeCommand(Ye.id,{sheetViewStartRow:c,sheetViewStartColumn:d,offsetX:h,offsetY:u})})))}_initSkeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeletonBefore$.subscribe(o=>{if(o==null)return;const e={unitId:o.unitId,sheetId:o.sheetId};if(this._scrollManagerService.setSearchParam(e),!this._getSheetObject())return;const n=this._scrollManagerService.getScrollStateByParam(e),{viewportScrollX:r,viewportScrollY:s}=this._scrollManagerService.calcViewportScrollFromRowColOffset(n);n&&this._updateViewportScroll(r,s)})))}_updateViewportScroll(o=0,e=0){const t=this._getSheetObject();if(!t)return;const n=t.scene,r=n.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN),s=n.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT),l=n.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM),c=n.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT),d=n.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);r&&(r.viewportScrollX=o,r.viewportScrollY=e),l&&(l.viewportScrollY=e),s&&(s.viewportScrollX=o),c&&(c.viewportScrollY=e),d&&(d.viewportScrollX=o)}scrollToRange(o,e,t){let{endRow:n,endColumn:r,startColumn:s,startRow:l}=o;const c=this._getViewportBounding();if(o.rangeType===a.RANGE_TYPE.ROW?(s=0,r=0):o.rangeType===a.RANGE_TYPE.COLUMN&&(l=0,n=0),c&&!e&&!t){const d=c.startRow>n?l:n,u=c.startColumn>r?s:r;return this._scrollToCell(d,u)}else return this._scrollToCell(l,s,e,t)}scrollToCell(o,e){const t=this._context.unit.getActiveSheet(),{ySplit:n,xSplit:r}=t.getFreeze();return this._commandService.syncExecuteCommand(Ye.id,{sheetViewStartRow:o-n,sheetViewStartColumn:e-r,offsetX:0,offsetY:0})}_initCommandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(o=>{switch(o.id){case m.SetSelectionsOperation.id:{const e=o.params;e.unitId===this._context.unitId&&e.reveal&&this._scrollToSelection()}break;case m.ScrollToCellOperation.id:{const e=o.params;if(e.unitId===this._context.unitId){const t=e.range;this.scrollToRange(t)}}break;case De.id:{const e=o.params;this._scrollToSelectionForExpand(e)}break}}))}_scrollToSelectionForExpand(o){setTimeout(()=>{const e=this._getSelectionsService().getCurrentLastSelection();if(e==null)return;const{startRow:t,startColumn:n,endRow:r,endColumn:s}=e.range,l=this._getViewportBounding();if(l==null)return;const{startRow:c,startColumn:d,endRow:u,endColumn:h}=l;let S=0,g=0;t>c?S=r:r<u?S=t:S=c,n>d?g=s:s<h?g=n:g=d,o.direction===a.Direction.DOWN?S=r:o.direction===a.Direction.UP?S=t:o.direction===a.Direction.RIGHT?g=s:o.direction===a.Direction.LEFT&&(g=n),this._scrollToCell(S,g)},0)}_getFreeze(){var e;const o=(e=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:e.skeleton.getWorksheetConfig();if(o!=null)return o.freeze}_updateSceneSize(o){var h;if(o==null)return;const{unitId:e}=this._context,{skeleton:t}=o,n=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.scene;if(t==null||n==null)return;const{rowTotalHeight:r,columnTotalWidth:s,rowHeaderWidthAndMarginLeft:l,columnHeaderHeightAndMarginTop:c}=t;this._context.unit.getActiveSheet()&&(n==null||n.transformByState({width:l+s,height:c+r}))}_getSheetObject(){return ze(this._context.unit,this._context)}_scrollToSelectionByDirection(o){const e=this._getViewportBounding();if(e==null)return!1;const{startRow:t,startColumn:n,endRow:r,endColumn:s}=e;let l=0,c=0;const{startRow:d,startColumn:u,endRow:h,endColumn:S}=o;d>=t&&(l=h),h<=r&&(l=d),u>=n&&(c=S),S<=s&&(c=u),this._scrollToCell(l,c)}_scrollToSelection(o=!0){var d;const e=this._getSelectionsService().getCurrentLastSelection();if(!e)return;const{startRow:t,startColumn:n,actualRow:r,actualColumn:s}=(d=e.primary)!=null?d:e.range,l=o&&r!=null?r:t,c=o&&s!=null?s:n;this._scrollToCell(l,c)}_getSelectionsService(){return m.getSelectionsService(this._injector)}_getViewportBounding(){var r,s;const o=(r=this._getSheetObject())==null?void 0:r.scene;if(o==null)return;const e=o.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e==null)return;const t=(s=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:s.skeleton;if(t==null)return;const n=e.calcViewportInfo();return t.getRangeByViewBound(n.viewBound)}_scrollToCell(o,e,t=!1,n=!1){var H,k,V;const{rowHeightAccumulation:r,columnWidthAccumulation:s}=(H=this._sheetSkeletonManagerService.getCurrentSkeleton())!=null?H:{};if(r==null||s==null)return!1;const l=(k=this._getSheetObject())==null?void 0:k.scene;if(l==null)return!1;const c=l.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(c==null)return!1;const d=(V=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:V.skeleton;if(d==null)return!1;const u=this._context.unit.getActiveSheet();if(!u)return!1;o=a.Tools.clamp(o,0,r.length-1),e=a.Tools.clamp(e,0,s.length-1);const{startColumn:h,startRow:S,ySplit:g,xSplit:f}=u.getFreeze(),p=this._getViewportBounding();if(p==null)return!1;const{startRow:C,startColumn:v,endRow:b,endColumn:E}=p;let w,R;if(o>=S&&e>=h-g&&(o<=C&&(w=o,t=!0),o>=b)){const U=r[o]-c.height;for(let W=C;W<=o&&(w=W+1,!(r[W]>=U));W++);}if(e>=h&&o>=S-g&&(e<=v&&(R=e,n=!0),e>=E)){const U=s[e]-c.width;for(let W=v;W<=e&&(R=W+1,!(s[W]>=U));W++);}if(w===void 0&&R===void 0)return!1;let{offsetX:M,offsetY:O,sheetViewStartRow:N,sheetViewStartColumn:D}=this._scrollManagerService.getCurrentScrollState()||{};if(w=w?Math.min(w,o):N+g,R=R?Math.min(R,e):D+f,n){M=0,R=e;const U=d.getHiddenColumnsInRange({startColumn:R-f,endColumn:R});R=R-U.length}if(t){O=0,w=o;const U=d.getHiddenRowsInRange({startRow:w-g,endRow:w});w=w-U.length}return this._commandService.syncExecuteCommand(Ye.id,{sheetViewStartRow:Math.max(0,w-g),sheetViewStartColumn:Math.max(0,R-f),offsetX:M,offsetY:O})}},y.SheetsScrollRenderController=Wu([gn(1,a.Inject(a.Injector)),gn(2,a.Inject(y.SheetSkeletonManagerService)),gn(3,a.IContextService),gn(4,a.ICommandService),gn(5,P.IRenderManagerService),gn(6,a.Inject(y.SheetScrollManagerService))],y.SheetsScrollRenderController);const hr={id:"sheet.operation.scroll-to-range",type:a.CommandType.OPERATION,handler:(i,o)=>{if(!o)return!1;const e=i.get(a.IUniverInstanceService);return i.get(P.IRenderManagerService).getRenderById(e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(y.SheetsScrollRenderController).scrollToRange(o.range,o.forceTop,o.forceLeft)}};class ha{constructor(){T(this,"_state",null);T(this,"_rect",null);T(this,"_state$",new A.BehaviorSubject(null));T(this,"state$",this._state$.asObservable());T(this,"_rect$",new A.BehaviorSubject(null));T(this,"rect$",this._rect$.asObservable());T(this,"_focus",!1);T(this,"_focus$",new A.BehaviorSubject(this._focus));T(this,"focus$",this._focus$.asObservable())}dispose(){this._state$.complete(),this._state=null,this._rect$.complete(),this._rect=null}setState(o){this._state=o,this._refresh(o)}getRect(){return this._rect}setRect(o){this._rect=o,this._rect$.next(o)}getState(){return this._state}setFocus(o=!1){this._focus=o,this._focus$.next(o)}_refresh(o){this._state$.next(o)}}const Qn=a.createIdentifier("univer.sheet-cell-editor-manager.service"),ma={sheetFooterBarHeight:"36",sheetContainer:"univer-sheet-container"};var Uu=Object.defineProperty,Bu=Object.getOwnPropertyDescriptor,xu=(i,o,e,t)=>{for(var n=t>1?void 0:t?Bu(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&Uu(o,e,n),n},fn=(i,o)=>(e,t)=>o(e,t,i);const Sa=5,ga=2;y.SheetCellEditorResizeService=class extends a.Disposable{constructor(o,e,t,n,r,s,l){super(),this._context=o,this._layoutService=e,this._cellEditorManagerService=t,this._editorBridgeService=n,this._renderManagerService=r,this._sheetSkeletonManagerService=s,this._univerInstanceService=l}fitTextSize(o){var D,H,k,V;const e=this._editorBridgeService.getEditCellState();if(!e)return;const{position:t,documentLayoutObject:n,canvasOffset:r,scaleX:s,scaleY:l}=e,{startX:c,startY:d,endX:u,endY:h}=t,S=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);if(S==null)return;const g=this._getEditorSkeleton();if(!g)return;const f=this._predictingSize(t,r,g,n,s,l);if(!f)return;let{actualWidth:p,actualHeight:C}=f;const{verticalAlign:v,horizontalAlign:b,paddingData:E,fill:w}=n;p=p+((D=E.l)!=null?D:0)+((H=E.r)!=null?H:0),C=C+((k=E.t)!=null?k:0)+((V=E.b)!=null?V:0);let R=u-c,M=h-d;R<p&&(R=Math.ceil(p)),M<C&&(M=Math.ceil(C));let O=0;v===a.VerticalAlign.MIDDLE?O=(M-C)/2/l:v===a.VerticalAlign.TOP?O=E.t||0:O=(M-C)/l;let N=0;b===a.HorizontalAlign.CENTER?N=(R-p)/2/s:b===a.HorizontalAlign.RIGHT?N=(R-p)/s:N=E.l||0,O=O<(E.t||0)?E.t||0:O,N=N<(E.l||0)?E.l||0:N,S.updateDocumentDataMargin({t:O,l:N}),g.calculate(),this._editAreaProcessing(R,M,t,r,w,s,l,b,o)}_predictingSize(o,e,t,n,r=1,s=1){const{startX:l,endX:c}=o,{textRotation:d,wrapStrategy:u,paddingData:h}=n,S=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC),{vertexAngle:g}=P.convertTextRotation(d);if(u===a.WrapStrategy.WRAP&&g===0){S==null||S.updateDocumentDataPageSize(c-l),S==null||S.updateDocumentDataMargin({l:h.l,t:h.t}),t.calculate();const{actualWidth:v,actualHeight:b}=t.getActualSize();return{actualWidth:v*r,actualHeight:b*s}}const f=this._getEditorMaxSize(o,e,n.horizontalAlign);if(!f)return;S==null||S.updateDocumentDataPageSize(f.width/r),t.calculate();const p=t.getActualSize();let C=c-l;return C<p.actualWidth*r+Sa*r&&(C=p.actualWidth*r+Sa*r),S==null||S.updateDocumentDataPageSize(C/r),S==null||S.updateDocumentRenderConfig({horizontalAlign:a.HorizontalAlign.UNSPECIFIED,cellValueType:void 0}),{actualWidth:p.actualWidth*r,actualHeight:p.actualHeight*s}}_getEditorMaxSize(o,e,t){if(this._getEditorObject()==null)return;function r(b){return Number.parseInt(b.replace("px",""))}const l=this._context.engine.getCanvasElement(),c=l.getBoundingClientRect(),d=r(l.style.width),{width:u}=c,h=u/d,{startX:S,startY:g,endX:f}=o,p=this._context.engine.width,C=document.body.clientHeight-g-Number.parseFloat(ma.sheetFooterBarHeight)-e.top-ga*2;let v=u-S;if(t===a.HorizontalAlign.CENTER){const b=p-f,E=S;v=f-S+Math.min(E,b)*2}else t===a.HorizontalAlign.RIGHT&&(v=f);return{height:C,width:v-ga,scaleAdjust:h}}_editAreaProcessing(o,e,t,n,r,s=1,l=1,c,d){var W;const u=this._getEditorObject();if(u==null)return;const S=this._context.engine.getCanvasElement();let{startX:g,startY:f}=t;const{document:p,scene:C,engine:v}=u,b=C.getViewport(Q.VIEWPORT_KEY.VIEW_MAIN),E=this._getEditorMaxSize(t,n,c),{height:w,width:R,scaleAdjust:M}=E;let O=e,N=b==null?void 0:b.getScrollBar();O>w?(N==null?b&&new P.ScrollBar(b,{enableHorizontal:!1,barSize:8}):b==null||b.resetCanvasSizeAndUpdateScroll(),b==null||b.scrollToViewportPos({viewportScrollY:O-w}),O=w):(N=null,(W=b==null?void 0:b.getScrollBar())==null||W.dispose()),o+=(N==null?void 0:N.barSize)||0,o>R&&(o=R),this._addBackground(C,o/s,e/l,r);const{scaleX:D,scaleY:H}=C.getPrecisionScale();C.transformByState({width:o*M/s,height:e*M/l,scaleX:s*M,scaleY:l*M}),p.resize(o*M/s,e*M/l),setTimeout(()=>{v.resizeBySize(P.fixLineWidthByScale(o,D),P.fixLineWidthByScale(O,H)),d==null||d()},0);const k=this._layoutService.getContentElement().getBoundingClientRect(),V=S.getBoundingClientRect();g=g*M+(V.left-k.left),f=f*M+(V.top-k.top);const U=t.endX-t.startX;c===a.HorizontalAlign.RIGHT?g+=(U-o)*M:c===a.HorizontalAlign.CENTER&&(g+=(U-o*M)/2),this._cellEditorManagerService.setState({startX:g,startY:f,endX:o*M+g,endY:O*M+f,show:!0})}_addBackground(o,e,t,n){const r="_backgroundRectHelperColor_",s=o.getObject(r);s==null&&n==null||(s==null?o.addObjects([new P.Rect(r,{width:e,height:t,fill:n,evented:!1})],Q.DOCS_COMPONENT_MAIN_LAYER_INDEX):n==null?s.dispose():(s.setProps({fill:n}),s.transformByState({width:e,height:t})))}resizeCellEditor(o){var M;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 n=(M=this._sheetSkeletonManagerService.getSkeletonParam(t.sheetId))==null?void 0:M.skeleton;if(!n)return;const{row:r,column:s,scaleX:l,scaleY:c,position:d,canvasOffset:u,documentLayoutObject:h}=t,{horizontalAlign:S}=h,g=this._getEditorMaxSize(d,u,S);if(!g)return;const{height:f,width:p,scaleAdjust:C}=g,v=n.getCellWithCoordByIndex(r,s),b=Math.min((v.mergeInfo.endY-v.mergeInfo.startY)*c,f)*C,E=Math.min((v.mergeInfo.endX-v.mergeInfo.startX)*l,p)*C,w=e.endY-e.startY,R=e.endX-e.startX;if(w!==b||R!==E){if(this._editorBridgeService.refreshEditCellPosition(!0),!this._getEditorSkeleton())return;this.fitTextSize(o)}}_getEditorObject(){return ki(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}_getEditorSkeleton(){var o;return(o=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:o.with(Ee.DocSkeletonManagerService).getSkeleton()}},y.SheetCellEditorResizeService=xu([fn(1,_.ILayoutService),fn(2,Qn),fn(3,ge),fn(4,P.IRenderManagerService),fn(5,a.Inject(y.SheetSkeletonManagerService)),fn(6,a.IUniverInstanceService)],y.SheetCellEditorResizeService);function mr(i){return i.getContextValue(a.FOCUSING_SHEET)}function ce(i){return i.getContextValue(a.FOCUSING_SHEET)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!i.getContextValue(a.EDITOR_ACTIVATED)&&!i.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function fa(i){return i.getContextValue(a.FOCUSING_SHEET)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!i.getContextValue(a.EDITOR_ACTIVATED)&&!i.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function Fu(i){return i.getContextValue(a.FOCUSING_SHEET)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&i.getContextValue(a.EDITOR_ACTIVATED)}function zu(i){return i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&i.getContextValue(a.EDITOR_ACTIVATED)}function pa(i){return i.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function Xu(i){return i.getContextValue(a.FOCUSING_SHEET)&&i.getContextValue(a.EDITOR_ACTIVATED)&&i.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function Jn(i){return i.getContextValue(a.FOCUSING_SHEET)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&i.getContextValue(a.EDITOR_ACTIVATED)&&!i.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&!i.getContextValue(a.FOCUSING_EDITOR_STANDALONE)}const Ca=[_.KeyCode.ARROW_DOWN,_.KeyCode.ARROW_UP,_.KeyCode.ARROW_LEFT,_.KeyCode.ARROW_RIGHT],Yu=[_.KeyCode.ENTER,_.KeyCode.TAB,...Ca];function va(){const i=[];for(const o of Ca)i.push({id:Nt.id,binding:o,preconditions:e=>Jn(e),staticParameters:{visible:!1,eventType:P.DeviceInputEventType.Keyboard,keycode:o,isShift:!1}}),i.push({id:Nt.id,binding:o|_.MetaKeys.SHIFT,preconditions:e=>Jn(e),staticParameters:{visible:!1,eventType:P.DeviceInputEventType.Keyboard,keycode:o,isShift:!0}});return i}const _a={id:jn.id,binding:_.KeyCode.F2,description:"shortcut.sheet.start-editing",group:"4_sheet-edit",preconditions:ce,staticParameters:{visible:!0,eventType:P.DeviceInputEventType.Keyboard,keycode:_.KeyCode.F2}},Ia={id:ve.id,binding:_.KeyCode.ENTER,description:"shortcut.sheet.toggle-editing",group:"4_sheet-edit",preconditions:i=>Jn(i),staticParameters:{visible:!1,eventType:P.DeviceInputEventType.Keyboard,keycode:_.KeyCode.ENTER}},ba={id:ve.id,binding:_.KeyCode.TAB,preconditions:i=>Jn(i),staticParameters:{visible:!1,eventType:P.DeviceInputEventType.Keyboard,keycode:_.KeyCode.TAB}},Ea={id:ve.id,binding:_.KeyCode.ESC,description:"shortcut.sheet.abort-editing",group:"4_sheet-edit",preconditions:i=>Jn(i),staticParameters:{visible:!1,eventType:P.DeviceInputEventType.Keyboard,keycode:_.KeyCode.ESC}},Ta={id:Q.BreakLineCommand.id,description:"shortcut.sheet.break-line",group:"4_sheet-edit",preconditions:i=>Fu(i),binding:_.KeyCode.ENTER|_.MetaKeys.ALT},wa={id:Q.DeleteLeftCommand.id,preconditions:i=>zu(i)||pa(i),binding:_.KeyCode.BACKSPACE},ya={id:ve.id,description:"shortcut.sheet.delete-and-start-editing",group:"4_sheet-edit",preconditions:i=>ce(i)&&!pa(i),binding:_.KeyCode.BACKSPACE,staticParameters:{visible:!0,eventType:P.DeviceInputEventType.Keyboard,keycode:_.KeyCode.BACKSPACE}};function ju(i){return i.startsWith("'")}function Gu(i){return i.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","%":"%","-":"-",".":".",":":":","/":"/","+":"+","@":"@","&":"&","*":"*","#":"#","=":"=",">":">","<":"<","$":"$",""":'"',"'":"'","(":"(",")":")"," ":" ",",":",","!":"!","?":"?",";":";","[":"[","]":"]","{":"{","}":"}"},Sr={true:"TRUE",false:"FALSE"};function Ku(i){return[a.LocaleType.ZH_CN,a.LocaleType.ZH_TW].includes(i)}function qu(i,o,e,t){let n=i;if(Ku(e)){if(i.startsWith("'")||i.startsWith("'"))return`'${i.slice(1)}`;n=Qu(n)}if(n.startsWith("="))return Ju(i,n,o,t);const r=n.toLowerCase();return Sr[r]?Sr[r]:a.numfmt.parseValue(n)==null?i:n}function Qu(i){const o=/['"].*?['"]/g,e=[],t=i.split(o);i.replace(o,r=>(e.push(r),""));let n=t.join("").split("").map(th).join("");return e.forEach((r,s)=>{n=n.slice(0,s*2)+r+n.slice((s+1)*2)}),n}function Ju(i,o,e,t){const n=e.sequenceNodesBuilder(o);if(!n)return i;let r=o,s=0;return n.forEach((l,c)=>{if(typeof l=="object"){const d=l.token;if(Sr[d.toLowerCase()]){const u=l.startIndex+s+1,h=l.endIndex+s+2;r=pn(d.toLocaleUpperCase(),r,u,h)}else if(l.nodeType===q.sequenceNodeType.FUNCTION&&$u(d,t,n,c)||l.nodeType===q.sequenceNodeType.REFERENCE){const u=d.indexOf("!");if(u>-1){const h=d.substring(u+1),S=l.startIndex+s+(u+1)+1,g=l.endIndex+s+2;r=pn(h.toLocaleUpperCase(),r,S,g)}else{const h=l.startIndex+s+1,S=l.endIndex+s+2;r=pn(d.toLocaleUpperCase(),r,h,S)}}else if(d.startsWith('"')&&d.endsWith('"')||d.startsWith("'")&&d.endsWith("'")){const u=l.startIndex+s+2,h=l.endIndex+s+1;r=pn(i.slice(u,h),r,u,h)}else if(l.nodeType!==q.sequenceNodeType.ARRAY){const u=a.numfmt.parseValue(d);if(u==null){const h=l.startIndex+s+1,S=l.endIndex+s+2;r=pn(i.slice(h,S),r,h,S)}else if(typeof u.v=="number"&&(u.z===void 0||!a.numfmt.isDate(u.z))){const h=`${u.v}`,S=l.startIndex+s+1,g=l.endIndex+s+2,{processedString:f,offset:p}=nh(d,h);r=pn(f,r,S,g),s+=p}}}}),r}function $u(i,o,e,t){const n=o.getDescriptions();return e[t+1]!==q.matchToken.OPEN_BRACKET?!1:n.get(eh(i).toLocaleUpperCase())!==void 0}function eh(i){const o=/^@+/;return i.replace(o,"")}function th(i){return Zu[i]||i}function pn(i,o,e,t){return o.substring(0,e)+i+o.substring(t)}function nh(i,o){var s,l;const e=((s=i.match(/^\s*/))==null?void 0:s[0])||"",t=((l=i.match(/\s*$/))==null?void 0:l[0])||"",n=e+o+t,r=n.length-i.length;return{processedString:n,offset:r}}const Pa="range_selector",Ma=i=>i.includes(Pa);var ih=Object.defineProperty,oh=Object.getOwnPropertyDescriptor,rh=(i,o,e,t)=>{for(var n=t>1?void 0:t?oh(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&ih(o,e,n),n},Re=(i,o)=>(e,t)=>o(e,t,i);const Ra=-1e3;y.EditingRenderController=class extends a.Disposable{constructor(e,t,n,r,s,l,c,d,u,h,S,g,f,p,C,v){super();T(this,"_cursorChange",0);T(this,"_isUnitEditing",!1);T(this,"_workbookSelections");T(this,"_d");T(this,"_cursorTimeout");this._context=e,this._undoRedoService=n,this._contextService=r,this._renderManagerService=s,this._editorBridgeService=l,this._cellEditorManagerService=c,this._lexerTreeBuilder=d,this._functionService=u,this._textSelectionManagerService=h,this._commandService=S,this._localService=g,this._editorService=f,this._sheetCellEditorResizeService=p,this._univerInstanceService=C,this._sheetInterceptorService=v,this._workbookSelections=t.getWorkbookSelections(this._context.unitId),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(b=>{(b==null?void 0:b.getUnitId())===this._context.unitId?this._d=this._init():(this._disposeCurrent(),this._isUnitEditing&&(this._handleEditorInvisible({visible:!1,eventType:P.DeviceInputEventType.Keyboard,keycode:_.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),e.add(()=>{clearTimeout(this._cursorTimeout)}),this._cursorTimeout=setTimeout(()=>{this._cursorStateListener(e)},1e3),e}_initEditorVisibilityListener(){this.disposeWithMe(this._editorBridgeService.visible$.pipe(A.distinctUntilChanged((e,t)=>e.visible===t.visible)).subscribe(e=>{(e.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY||e.unitId===a.DOCS_NORMAL_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 n=this._editorBridgeService.getEditCellState(),r=this._editorBridgeService.getCurrentEditorId();if(!n||!r)return;this._sheetCellEditorResizeService.fitTextSize()}}))}_initialCursorSync(e){e.add(this._cellEditorManagerService.focus$.pipe(A.filter(t=>!!t)).subscribe(()=>{var n;const t=(n=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_DOC))==null?void 0:n.with(Q.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(n=>{if(t.has(n.id)){switch(n.id){case m.MoveRowsMutation.id:case m.MoveColsMutation.id:case m.RemoveColMutation.id:case m.RemoveRowMutation.id:case m.InsertColMutation.id:case m.InsertRowMutation.id:{const r=this._editorBridgeService.getEditLocation();if(!r)break;const s={startRow:r.row,startColumn:r.column,endRow:r.row,endColumn:r.column},l=m.adjustRangeOnMutation(s,n);if(!l)break;const c=l.startRow,d=l.startColumn;this._editorBridgeService.updateEditLocation(c,d);break}}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 b,E;if(t==null||this._editorBridgeService.isForceKeepVisible())return;const n=this._editorBridgeService.getEditCellState();if(n==null)return;const{position:r,documentLayoutObject:s,scaleX:l,editorUnitId:c}=n;if(this._contextService.getContextValue(a.FOCUSING_EDITOR_STANDALONE))return;const d=this._getDocumentDataModel();if(d==null)return;const{startX:u,endX:h}=r,{textRotation:S,wrapStrategy:g,documentModel:f}=s,{vertexAngle:p}=P.convertTextRotation(S);g===a.WrapStrategy.WRAP&&p===0&&d.updateDocumentDataPageSize((h-u)/l),this._commandService.syncExecuteCommand(Q.ReplaceSnapshotCommand.id,{unitId:c,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 C=(b=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:b.with(Q.DocSelectionRenderService),v=(E=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:E.with(Q.DocSelectionRenderService);(C!=null&&C.canFocusing||v!=null&&v.canFocusing)&&(this._univerInstanceService.setCurrentUnitForType(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),C==null||C.activate(Ra,Ra,!0))}))}_commandExecutedListener(e){e.add(this._commandService.onCommandExecuted(n=>{if(n.id===Ee.RichTextEditingMutation.id){const r=n.params,{unitId:s}=r;if(!this._isCurrentSheetFocused()||Ma(s)||(this._editorBridgeService.changeEditorDirty(!0),!this._editorBridgeService.isVisible().visible))return;s===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._sheetCellEditorResizeService.fitTextSize()}}));const t=[Nt.id];e.add(this._commandService.onCommandExecuted(n=>{if(t.includes(n.id)){const r=n.params,{keycode:s,isShift:l}=r;if(s!=null&&(this._cursorChange===2||this._contextService.getContextValue(a.FOCUSING_FX_BAR_EDITOR))){this._moveInEditor(s,l);return}this._commandService.syncExecuteCommand(ve.id,r)}n.id===jn.id&&(this._cursorChange=2)}))}_handleEditorVisible(e){var g,f,p;const{eventType:t,keycode:n}=e;this._cursorChange=t===P.DeviceInputEventType.PointerDown||t===P.DeviceInputEventType.Dblclick?2:1;const r=this._editorBridgeService.getEditLocation();if(r==null)return;this._commandService.syncExecuteCommand(hr.id,{range:{startRow:r.row,startColumn:r.column,endRow:r.row,endColumn:r.column}}),this._editorBridgeService.refreshEditCellPosition(!1);const{unitId:s,isInArrayFormulaRange:l=!1}=r,c=this._getEditorObject();if(c==null)return;const{document:d,scene:u}=c;this._contextService.setContextValue(a.EDITOR_ACTIVATED,!0);const h=this._getDocumentDataModel(),S=this._getEditorSkeleton(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(!(!S||!h)){if(this._sheetCellEditorResizeService.fitTextSize(()=>{const C=u.getViewport(Q.VIEWPORT_KEY.VIEW_MAIN);C==null||C.scrollToViewportPos({viewportScrollX:Number.POSITIVE_INFINITY,viewportScrollY:Number.POSITIVE_INFINITY})}),t===P.DeviceInputEventType.Keyboard&&n===_.KeyCode.F2){d.makeDirty(),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}]);const C=((f=(g=h.getBody())==null?void 0:g.dataStream.length)!=null?f:2)-2;this._textSelectionManagerService.replaceDocRanges([{startOffset:C,endOffset:C}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})}else if(t===P.DeviceInputEventType.Keyboard||t===P.DeviceInputEventType.Dblclick&&l)this._emptyDocumentDataModel(h.getSnapshot().documentStyle,!!l),d.makeDirty(),(n===_.KeyCode.BACKSPACE||t===P.DeviceInputEventType.Dblclick)&&(S.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===P.DeviceInputEventType.Dblclick){if(this._contextService.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA))return;const C=h.getBody().dataStream.length-2||0;this._textSelectionManagerService.replaceDocRanges([{startOffset:C,endOffset:C}])}(p=this._renderManagerService.getRenderById(s))==null||p.scene.resetCursor()}}async _handleEditorInvisible(e){const t=this._editorBridgeService.getEditCellState(),n=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),r=a.Tools.deepClone(n==null?void 0:n.getSnapshot());let{keycode:s}=e;if(this._cursorChange=0,this._exitInput(e),t==null)return;this._editorBridgeService.getEditorDirty()===!1&&(s=_.KeyCode.ESC);const d=this._context.unit.getActiveSheet(),u=this._context.unitId,h=d.getSheetId(),{unitId:S,sheetId:g}=t;if(u===S&&g!==h&&await this._commandService.executeCommand(m.SetWorksheetActivateCommand.id,{subUnitId:g,unitId:S}),s===_.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:g,selections:f}));return}r&&await this._submitCellData(r),this._moveCursor(s)}_getEditorObject(){return ki(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:n,sheetId:r,row:s,column:l}=t,c=this._context.unit;let d=c.getActiveSheet();if(!c.getSheetBySheetId(r))return;d=c.getActiveSheet();const h=sh({...d.getCellRaw(s,l)||{}},e,this._lexerTreeBuilder,this._localService,this._functionService,c.getStyles());if(!h)return;const S=await this._sheetInterceptorService.onWriteCell(c,d,s,l,h);S!==d.getCellRaw(s,l)&&this._commandService.executeCommand(m.SetRangeValuesCommand.id,{subUnitId:r,unitId:n,range:{startRow:s,startColumn:l,endRow:s,endColumn:l},value:S})}_exitInput(e){var r;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();(r=t==null?void 0:t.scene.getViewport(Q.VIEWPORT_KEY.VIEW_MAIN))==null||r.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});const n=this._editorBridgeService.getCurrentEditorId();n==null||!this._editorService.isSheetEditor(n)||(this._undoRedoService.clearUndoRedo(n),this._undoRedoService.clearUndoRedo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))}_moveCursor(e){if(e==null||!Yu.includes(e))return;let t=a.Direction.LEFT;switch(e){case _.KeyCode.ENTER:t=a.Direction.DOWN;break;case _.KeyCode.TAB:t=a.Direction.RIGHT;break;case _.KeyCode.ARROW_DOWN:t=a.Direction.DOWN;break;case _.KeyCode.ARROW_UP:t=a.Direction.UP;break;case _.KeyCode.ARROW_LEFT:t=a.Direction.LEFT;break;case _.KeyCode.ARROW_RIGHT:t=a.Direction.RIGHT;break}e===_.KeyCode.ENTER||e===_.KeyCode.TAB?this._commandService.executeCommand(Qe.id,{keycode:e,direction:t}):this._commandService.executeCommand(Ae.id,{direction:t})}_cursorStateListener(e){const t=this._getEditorObject();if(!(t!=null&&t.document))return;const{document:n}=t;e.add(a.toDisposable(n.onPointerDown$.subscribeEvent(()=>{this._cursorChange===1&&(this._cursorChange=2)})))}_moveInEditor(e,t){let n=a.Direction.LEFT;e===_.KeyCode.ARROW_DOWN?n=a.Direction.DOWN:e===_.KeyCode.ARROW_UP?n=a.Direction.UP:e===_.KeyCode.ARROW_RIGHT&&(n=a.Direction.RIGHT),t?this._commandService.executeCommand(Q.MoveSelectionOperation.id,{direction:n}):this._commandService.executeCommand(Q.MoveCursorOperation.id,{direction:n})}_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(Ee.DocSkeletonManagerService).getSkeleton()}_getEditorViewModel(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(Ee.DocSkeletonManagerService).getViewModel()}_emptyDocumentDataModel(e,t){const n=(l,c)=>{const d=a.Tools.deepClone(l.getSnapshot()),u=this._getEditorViewModel(l.getUnitId());u!=null&&(ah(d.body,t),c&&(d.documentStyle=e),d.drawings={},d.drawingsOrder=[],l.reset(d),u.reset(l))},r=this._getDocumentDataModel();r&&n(r,!0);const s=this._univerInstanceService.getUnit(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);s&&n(s)}},y.EditingRenderController=rh([Re(1,a.Inject(m.SheetsSelectionsService)),Re(2,a.IUndoRedoService),Re(3,a.IContextService),Re(4,P.IRenderManagerService),Re(5,ge),Re(6,Qn),Re(7,a.Inject(q.LexerTreeBuilder)),Re(8,q.IFunctionService),Re(9,a.Inject(Ee.DocSelectionManagerService)),Re(10,a.ICommandService),Re(11,a.Inject(a.LocaleService)),Re(12,Q.IEditorService),Re(13,a.Inject(y.SheetCellEditorResizeService)),Re(14,a.IUniverInstanceService),Re(15,a.Inject(m.SheetInterceptorService))],y.EditingRenderController);function sh(i,o,e,t,n,r){var h,S,g;if((o==null?void 0:o.body)==null)return null;const{body:s}=o;i.t=void 0;const l=s.dataStream;let d=l.substring(l.length-2,l.length)===a.DEFAULT_EMPTY_DOCUMENT_VALUE?l.substring(0,l.length-2):l;const u=t.getCurrentLocale();if(d=qu(d,e,u,n),(h=o.drawingsOrder)!=null&&h.length)i.v="",i.f=null,i.si=null,i.p=o,i.t=a.CellValueType.STRING;else if(i.s&&((g=(S=r==null?void 0:r.get(i.s))==null?void 0:S.n)==null?void 0:g.pattern)===vd.DEFAULT_TEXT_FORMAT){i.v=d,i.f=null,i.si=null,i.p=null,i.t=a.CellValueType.STRING,gr(s)&&s.dataStream!==`\r
1
+ (function(y,Q){typeof exports=="object"&&typeof module<"u"?Q(exports,require("@univerjs/docs-ui"),require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("react"),require("rxjs"),require("@univerjs/sheets"),require("@univerjs/docs"),require("@univerjs/engine-formula"),require("@univerjs/engine-numfmt"),require("@univerjs/design"),require("react/jsx-runtime"),require("@univerjs/telemetry"),require("rxjs/operators")):typeof define=="function"&&define.amd?define(["exports","@univerjs/docs-ui","@univerjs/core","@univerjs/engine-render","@univerjs/ui","react","rxjs","@univerjs/sheets","@univerjs/docs","@univerjs/engine-formula","@univerjs/engine-numfmt","@univerjs/design","react/jsx-runtime","@univerjs/telemetry","rxjs/operators"],Q):(y=typeof globalThis<"u"?globalThis:y||self,Q(y.UniverSheetsUi={},y.UniverDocsUi,y.UniverCore,y.UniverEngineRender,y.UniverUi,y.React,y.rxjs,y.UniverSheets,y.UniverDocs,y.UniverEngineFormula,y.UniverEngineNumfmt,y.UniverDesign,y.React,y.UniverTelemetry,y.rxjs.operators))})(this,function(y,Q,a,P,_,L,A,m,Ee,q,vd,K,I,_d,Ys){"use strict";var lv=Object.defineProperty;var cv=(y,Q,a)=>Q in y?lv(y,Q,{enumerable:!0,configurable:!0,writable:!0,value:a}):y[Q]=a;var T=(y,Q,a)=>cv(y,typeof Q!="symbol"?Q+"":Q,a);function ki(i,o){if(i==null)return;const e=o.getRenderById(i);if(e==null)return;const{mainComponent:t,scene:n,engine:r,components:s}=e,l=t,c=s.get(Q.DOCS_VIEW_KEY.BACKGROUND);return{document:l,docBackground:c,scene:n,engine:r}}const jo=[10,400],Go="RANGE_SELECTOR_COMPONENT_KEY",Vi="EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY";var he=(i=>(i.MAIN="__SpreadsheetRender__",i.ROW="__SpreadsheetRowHeader__",i.COLUMN="__SpreadsheetColumnHeader__",i.LEFT_TOP="__SpreadsheetLeftTopPlaceholder__",i))(he||{});const js=0,Wi=1,St=10,Id=11,Gs=12,Li={id:"sheet.command.set-row-header-width",type:a.CommandType.COMMAND,handler:async(i,o)=>{if(!o)return!1;const e=i.get(P.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:n,size:r}=o,s=e.getRenderById(t);if(s){e.getRenderById(t).with(y.SheetSkeletonManagerService).setRowHeaderSize(s,n,r);const{components:c}=s,d=c.get(he.ROW);d&&d.setCustomHeader({headerStyle:{size:r}})}return!0}},Ui={id:"sheet.command.set-col-header-height",type:a.CommandType.COMMAND,handler:async(i,o)=>{if(!o)return!1;const e=i.get(P.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:n,size:r}=o,s=e.getRenderById(t);if(s){e.getRenderById(t).with(y.SheetSkeletonManagerService).setColumnHeaderSize(s,n,r);const{components:c}=s,d=c.get(he.COLUMN);d&&d.setCustomHeader({headerStyle:{size:r}})}return!0}},Zo=a.createInterceptorKey("rangeMovePermissionCheck"),Ko=a.createInterceptorKey("rangeFillPermissionCheck");var qo=(i=>(i[i.FORMULA_EDITOR_SHOW=100]="FORMULA_EDITOR_SHOW",i[i.MARK_SELECTION=1e4]="MARK_SELECTION",i))(qo||{});function gt(i){const o=i.getCurrentTheme(),e=new a.ColorKit(o.primaryColor).setAlpha(.07).toRgbString();return{strokeWidth:1,stroke:o.primaryColor,fill:e,widgets:{},widgetSize:6,widgetStrokeWidth:1,widgetStroke:o.colorWhite,autofillSize:6,autofillStrokeWidth:1,autofillStroke:o.colorWhite,rowHeaderFill:e,rowHeaderStroke:o.primaryColor,rowHeaderStrokeWidth:1,columnHeaderFill:e,columnHeaderStroke:o.primaryColor,columnHeaderStrokeWidth:1,expandCornerSize:40}}class bd{constructor(){T(this,"_startColumn",-1);T(this,"_startRow",-1);T(this,"_endColumn",-1);T(this,"_endRow",-1);T(this,"_startX",0);T(this,"_startY",0);T(this,"_endX",0);T(this,"_endY",0);T(this,"_primary");T(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(o){const{startColumn:e,startRow:t,endColumn:n,endRow:r}=this,{startColumn:s,startRow:l,endColumn:c,endRow:d}=o;return e===s&&t===l&&n===c&&r===d}isInclude(o){const{startColumn:e,startRow:t,endColumn:n,endRow:r}=this,{startColumn:s,startRow:l,endColumn:c,endRow:d}=o;return!(c<e||s>n||l>r||d<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(o){this._rangeType=o}getValue(){return{rangeWithCoord:this.getRange(),primaryWithCoord:this._primary}}setValue(o,e){const{startColumn:t,startRow:n,endColumn:r,endRow:s,startX:l,startY:c,endX:d,endY:u,rangeType:h}=o;this._startColumn=t,this._startRow=n,this._endColumn=r,this._endRow=s,this._startX=l,this._startY=c,this._endX=d,this._endY=u,h!==void 0&&(this._rangeType=h),e!==void 0&&this.setCurrentCell(e)}setCurrentCell(o){this._primary=o}clearCurrentCell(){this._primary=null}}function rn(i,o){const{startRow:e,startColumn:t,endRow:n,endColumn:r,rangeType:s}=o,l=n<e?n:e,c=n<e?e:n,d=r<t?r:t,u=r<t?t:r,h=i.getNoMergeCellWithCoordByIndex(l,d),S=i.getNoMergeCellWithCoordByIndex(c,u);return{startRow:e,startColumn:t,endRow:n,endColumn:r,rangeType:s,startY:(h==null?void 0:h.startY)||0,endY:(S==null?void 0:S.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(S==null?void 0:S.endX)||0}}function Me(i,o){const{range:e,primary:t,style:n}=i,r=rn(o,e),s=t&&xn(o,t);return{rangeWithCoord:r,primaryWithCoord:s,style:n}}function xn(i,o){const{actualRow:e,actualColumn:t,isMerged:n,isMergedMainCell:r,startRow:s,startColumn:l,endRow:c,endColumn:d}=o,u=i.getNoMergeCellWithCoordByIndex(e,t),h=i.getNoMergeCellWithCoordByIndex(s,l),S=i.getNoMergeCellWithCoordByIndex(c,d);return{actualRow:e,actualColumn:t,isMerged:n,isMergedMainCell:r,startX:u.startX,startY:u.startY,endX:u.endX,endY:u.endY,mergeInfo:{startRow:s,startColumn:l,endRow:c,endColumn:d,startY:(h==null?void 0:h.startY)||0,endY:(S==null?void 0:S.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(S==null?void 0:S.endX)||0}}}const Zs="__SpreadsheetHelperSelectionTempRect",Ed=35;class Ks{constructor(o,e){T(this,"_startOffsetX",0);T(this,"_startOffsetY",0);T(this,"_relativeSelectionPositionRow",0);T(this,"_relativeSelectionPositionColumn",0);T(this,"_relativeSelectionRowLength",0);T(this,"_relativeSelectionColumnLength",0);T(this,"_scenePointerMoveSub");T(this,"_scenePointerUpSub");T(this,"_helperSelection");T(this,"_scrollTimer");T(this,"_activeViewport");T(this,"_targetSelection",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});T(this,"_isInMergeState",!1);T(this,"_fillControlColors",[]);T(this,"_skeleton");T(this,"_scene");T(this,"_themeService");T(this,"_injector");T(this,"_selectionHooks");this._control=o,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 o,e;(o=this._scrollTimer)==null||o.dispose(),this._fillControlColors=[],this._clearObserverEvent(),(e=this._helperSelection)==null||e.dispose()}_getFreeze(){var t,n;return(n=(t=this._injector.get(P.IRenderManagerService).withCurrentTypeOfUnit(a.UniverInstanceType.UNIVER_SHEET,y.SheetSkeletonManagerService))==null?void 0:t.getCurrentParam())==null?void 0:n.skeleton.getWorksheetConfig().freeze}_isSelectionInViewport(o,e){const t=this._getFreeze()||{startRow:-1,startColumn:-1,xSplit:0,ySplit:0};switch(e.viewportKey){case P.SHEET_VIEWPORT_KEY.VIEW_MAIN:return o.endRow>=t.startRow&&o.endColumn>=t.startColumn;case P.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP:case P.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT:return o.endColumn>=t.startColumn&&o.startRow<t.startRow;case P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT:case P.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM:return o.endRow>=t.startRow&&o.startColumn<t.startColumn;case P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP:case P.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT:case P.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP:case P.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP:return o.startRow<t.startRow&&o.startColumn<t.startColumn}}_clearObserverEvent(){var o,e;(o=this._scenePointerMoveSub)==null||o.unsubscribe(),(e=this._scenePointerUpSub)==null||e.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null}_initialControl(){const{leftControl:o,rightControl:e,topControl:t,bottomControl:n}=this._control;[o,e,t,n].forEach(r=>{r.onPointerEnter$.subscribeEvent(()=>{var l;((l=this._injector.get(Ce,a.Quantity.OPTIONAL))==null?void 0:l.interceptor.fetchThroughInterceptors(Zo)(!1,null))!==!1&&r.setCursor(P.CURSOR_TYPE.MOVE)}),r.onPointerLeave$.subscribeEvent(()=>{r.resetCursor()}),r.onPointerDown$.subscribeEvent(this._controlPointerDownHandler.bind(this))})}_controlMoving(o,e){var D;const t=this._scene,n=t.getScrollXYInfoByViewport(P.Vector2.FromArray([o,e])),{scaleX:r,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(o,e,r,s,n),{row:c,column:d}=l,u=this._skeleton.getRowCount()-1,h=this._skeleton.getColumnCount()-1;let S=Math.max(0,c+this._relativeSelectionPositionRow),g=S+this._relativeSelectionRowLength;g>u&&(g=u,g-S<this._relativeSelectionRowLength&&(S=g-this._relativeSelectionRowLength));let f=Math.max(0,d+this._relativeSelectionPositionColumn),p=f+this._relativeSelectionColumnLength;p>h&&(p=h,p-f<this._relativeSelectionColumnLength&&(f=p-this._relativeSelectionColumnLength));const C=this._skeleton.worksheet.getCellInfoInMergeData(S,f),b=Me({range:{startRow:S,endRow:g,startColumn:f,endColumn:p},primary:C,style:null},this._skeleton),E=this._skeleton.getNoMergeCellWithCoordByIndex(S,f),w=this._skeleton.getNoMergeCellWithCoordByIndex(g,p),R=(E==null?void 0:E.startY)||0,M=(w==null?void 0:w.endY)||0,O=(E==null?void 0:E.startX)||0,N=(w==null?void 0:w.endX)||0;(D=this._helperSelection)==null||D.transformByState({left:O,top:R,width:N-O,height:M-R}),this._targetSelection={...b.rangeWithCoord},this._control.selectionMoving$.next(b.rangeWithCoord)}_controlPointerDownHandler(o){const{offsetX:e,offsetY:t}=o,n=this._scene,r=n.getCoordRelativeToViewport(P.Vector2.FromArray([e,t])),{x:s,y:l}=r,c=n.getScrollXYInfoByViewport(r),{scaleX:d,scaleY:u}=n.getAncestorScale(),h=this._skeleton.getCellIndexByOffset(s,l,d,u,c);this._startOffsetX=s,this._startOffsetY=l;const{row:S,column:g}=h,{startRow:f,startColumn:p,endRow:C,endColumn:v}=this._control.model;let b=0,E=0;S<f?b-=1:S>C&&(b+=1),g<p?E-=1:g>v&&(E+=1),this._relativeSelectionPositionRow=f-S+b,this._relativeSelectionPositionColumn=p-g+E,this._relativeSelectionRowLength=C-f,this._relativeSelectionColumnLength=v-p;const w=this._control.currentStyle,R=this._getScale();this.isHelperSelection&&(this._helperSelection=new P.Rect(Zs,{stroke:w.stroke,strokeWidth:w.strokeWidth/R}),n.addObject(this._helperSelection));const M=n.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN),O=P.ScrollTimer.create(n);this._scrollTimer=O,O.startScroll(s,l,M),n.disableObjectsEvent(),this._scenePointerMoveSub=n.onPointerMove$.subscribeEvent(N=>{var W;const{offsetX:D,offsetY:H}=N;if(((W=this._injector.get(Ce,a.Quantity.OPTIONAL))==null?void 0:W.interceptor.fetchThroughInterceptors(Zo)(!1,null))===!1)return;const{x:V,y:U}=n.getCoordRelativeToViewport(P.Vector2.FromArray([D,H]));this._controlMoving(V,U),n.setCursor(P.CURSOR_TYPE.MOVE),O.scrolling(V,U,()=>{this._controlMoving(V,U)})}),this._scenePointerUpSub=n.onPointerUp$.subscribeEvent(()=>{var D,H,k,V;(D=this._helperSelection)==null||D.dispose();const N=this._scene;N.resetCursor(),this._clearObserverEvent(),N.enableObjectsEvent(),(H=this._scrollTimer)==null||H.dispose(),this._control.selectionMoveEnd$.next(this._targetSelection),(V=(k=this._selectionHooks).selectionMoveEnd)==null||V.call(k)})}_initialWidget(){const{topLeftWidget:o,topCenterWidget:e,topRightWidget:t,middleLeftWidget:n,middleRightWidget:r,bottomLeftWidget:s,bottomCenterWidget:l,bottomRightWidget:c}=this._control,d=[P.CURSOR_TYPE.NORTH_WEST_RESIZE,P.CURSOR_TYPE.NORTH_RESIZE,P.CURSOR_TYPE.NORTH_EAST_RESIZE,P.CURSOR_TYPE.WEST_RESIZE,P.CURSOR_TYPE.EAST_RESIZE,P.CURSOR_TYPE.SOUTH_WEST_RESIZE,P.CURSOR_TYPE.SOUTH_RESIZE,P.CURSOR_TYPE.SOUTH_EAST_RESIZE];[o,e,t,n,r,s,l,c].forEach((u,h)=>{u.onPointerEnter$.subscribeEvent(()=>{u.setCursor(d[h])}),u.onPointerLeave$.subscribeEvent(()=>{u.resetCursor()}),u.onPointerDown$.subscribeEvent(S=>{this._widgetPointerDownEvent(S,d[h])})})}_widgetPointerDownEvent(o,e){const t=this._scene,{offsetX:n,offsetY:r}=o,s=t.getCoordRelativeToViewport(P.Vector2.FromArray([n,r])),{x:l,y:c}=s;this._startOffsetX=n,this._startOffsetY=r;const{startRow:d,startColumn:u,endRow:h,endColumn:S}=this._control.model,g=Math.min(d,h),f=Math.min(u,S),p=Math.max(d,h),C=Math.max(u,S);this._relativeSelectionPositionRow=g,this._relativeSelectionPositionColumn=f,this._relativeSelectionRowLength=p-g,this._relativeSelectionColumnLength=C-f,e===P.CURSOR_TYPE.NORTH_WEST_RESIZE?(this._relativeSelectionPositionRow=p,this._relativeSelectionPositionColumn=C):e===P.CURSOR_TYPE.NORTH_RESIZE?this._relativeSelectionPositionRow=p:e===P.CURSOR_TYPE.NORTH_EAST_RESIZE?this._relativeSelectionPositionRow=p:e===P.CURSOR_TYPE.WEST_RESIZE?this._relativeSelectionPositionColumn=C:e===P.CURSOR_TYPE.SOUTH_WEST_RESIZE?this._relativeSelectionPositionColumn=C:e===P.CURSOR_TYPE.SOUTH_RESIZE&&(this._relativeSelectionPositionRow=g);const v=P.ScrollTimer.create(t),b=t.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN);v.startScroll(l,c,b),this._scrollTimer=v,t.disableObjectsEvent(),this._scenePointerMoveSub=t.onPointerMove$.subscribeEvent(E=>{const{offsetX:w,offsetY:R}=E,{x:M,y:O}=t.getCoordRelativeToViewport(P.Vector2.FromArray([w,R]));this._widgetMoving(M,O,e),t.setCursor(e),v.scrolling(M,O,()=>{this._widgetMoving(M,O,e)})}),this._scenePointerUpSub=t.onPointerUp$.subscribeEvent(()=>{var w,R,M;const E=this._scene;E.resetCursor(),this._clearObserverEvent(),E.enableObjectsEvent(),(w=this._scrollTimer)==null||w.dispose(),this._control.selectionScaled$.next(this._targetSelection),(M=(R=this._selectionHooks).selectionMoveEnd)==null||M.call(R)})}_widgetMoving(o,e,t){const n=this._scene,r=n.getScrollXYInfoByViewport(P.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:s,scaleY:l}=n.getAncestorScale(),c=this._skeleton.getCellIndexByOffset(o,e,s,l,r),{row:d,column:u}=c;let h=this._relativeSelectionPositionRow,S=this._relativeSelectionPositionColumn,g=d,f=u;t===P.CURSOR_TYPE.NORTH_WEST_RESIZE?(h=d,S=u,g=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn):t===P.CURSOR_TYPE.NORTH_RESIZE?(h=d,S=this._relativeSelectionPositionColumn,g=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength):t===P.CURSOR_TYPE.NORTH_EAST_RESIZE?(h=d,S=this._relativeSelectionPositionColumn,g=this._relativeSelectionPositionRow,f=u):t===P.CURSOR_TYPE.WEST_RESIZE?(h=this._relativeSelectionPositionRow,S=u,g=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,f=this._relativeSelectionPositionColumn):t===P.CURSOR_TYPE.EAST_RESIZE?g=this._relativeSelectionPositionRow+this._relativeSelectionRowLength:t===P.CURSOR_TYPE.SOUTH_WEST_RESIZE?(h=this._relativeSelectionPositionRow,S=u,g=d,f=this._relativeSelectionPositionColumn):t===P.CURSOR_TYPE.SOUTH_RESIZE&&(h=this._relativeSelectionPositionRow,S=this._relativeSelectionPositionColumn,g=d,f=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength);const p=this._swapPositions(h,S,g,f),C=this._skeleton.getCellWithMergeInfoByIndex(h,S),b=Me({range:p,primary:C,style:null},this._skeleton);this._targetSelection={...b.rangeWithCoord},this._control.updateRangeBySelectionWithCoord(b),this._control.selectionScaling$.next(this._targetSelection)}_initialAutoFill(){const{fillControl:o}=this._control;o.onPointerEnter$.subscribeEvent(e=>{this._injector.get(Ce).interceptor.fetchThroughInterceptors(Ko)(!1,{x:e.offsetX,y:e.offsetY,skeleton:this._skeleton,scene:this._scene})&&o.setCursor(P.CURSOR_TYPE.CROSSHAIR)}),o.onPointerLeave$.subscribeEvent(()=>{o.resetCursor()}),o.onPointerDown$.subscribeEvent(this._autoFillForPointerdown.bind(this))}_autoFillMoving(o,e){var H,k,V;const t=this._scene,n=t.getViewportScrollXY(this._activeViewport),{scaleX:r,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(o,e,r,s,n),{row:c,column:d}=l,u=t.getCoordRelativeToViewport(P.Vector2.FromArray([o,e])),h=this._skeleton.getRowCount()-1,S=this._skeleton.getColumnCount()-1;let g=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn,p=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,C=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength,v=!1,b=!0;if((d<f||d>C)&&c>=g&&c<=p){const U=this._fillRuler(d,f,C,this._relativeSelectionColumnLength,S);f=U.startRowOrColumn,C=U.endRowOrColumn,v=U.isLighten,b=!1}else if((c<g||c>p)&&d>=f&&d<=C){const U=this._fillRuler(c,g,p,this._relativeSelectionRowLength,h);g=U.startRowOrColumn,p=U.endRowOrColumn,v=U.isLighten}else if(Math.abs(this._startOffsetX-u.x-n.x)/2>Math.abs(this._startOffsetY-u.y-n.y)){const U=this._fillRuler(d,f,C,this._relativeSelectionColumnLength,S);f=U.startRowOrColumn,C=U.endRowOrColumn,v=U.isLighten,b=!1}else{const U=this._fillRuler(c,g,p,this._relativeSelectionRowLength,h);g=U.startRowOrColumn,p=U.endRowOrColumn,v=U.isLighten}const E=this._skeleton.getNoMergeCellWithCoordByIndex(g,f),w=this._skeleton.getNoMergeCellWithCoordByIndex(p,C),R=(E==null?void 0:E.startY)||0,M=(w==null?void 0:w.endY)||0,O=(E==null?void 0:E.startX)||0,N=(w==null?void 0:w.endX)||0;v?this._controlHandler((U,W)=>{const B=new a.ColorKit(this._fillControlColors[W]).lighten(Ed).toRgbString();U.setProps({fill:B})}):this._controlHandler((U,W)=>{U.setProps({fill:this._fillControlColors[W]})});const D=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();g===p&&b===!0||f===C&&b===!1?(H=this._helperSelection)==null||H.hide():((k=this._helperSelection)==null||k.transformByState({left:O-D/2,top:R-D/2,width:N-O,height:M-R}),(V=this._helperSelection)==null||V.show()),this._targetSelection={startY:R,endY:M,startX:O,endX:N,startRow:g,endRow:p,startColumn:f,endColumn:C},this._control.selectionFilling$.next(this._targetSelection)}_autoFillForPointerdown(o){const{offsetX:e,offsetY:t}=o,n=this._scene,r=n.getCoordRelativeToViewport(P.Vector2.FromArray([e,t])),{x:s,y:l}=r;this._startOffsetX=s,this._startOffsetY=l;const{startRow:c,startColumn:d,endRow:u,endColumn:h}=this._control.model;this._isInMergeState=this._hasMergeInRange(c,d,u,h),this._relativeSelectionPositionRow=c,this._relativeSelectionPositionColumn=d,this._relativeSelectionRowLength=u-c,this._relativeSelectionColumnLength=h-d;const S=this._control.currentStyle;let g=S==null?void 0:S.stroke,f=S==null?void 0:S.strokeWidth;const p=gt(this._themeService);g==null&&(g=p.stroke),f==null&&(f=p.strokeWidth);const C=this._getScale();f/=C;const v=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/C,b=new a.ColorKit(g).darken(2).toRgbString();this.isHelperSelection&&(this._helperSelection=new P.Rect(Zs,{stroke:b,strokeWidth:f+v/2}),n.addObject(this._helperSelection)),this._activeViewport=n.getActiveViewportByCoord(P.Vector2.FromArray([e,t]));const E=n.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN),w=P.ScrollTimer.create(n,this._activeViewport.viewportKey===P.SHEET_VIEWPORT_KEY.VIEW_MAIN?P.ScrollTimerType.ALL:P.ScrollTimerType.NONE);w.startScroll(s,l,E),this._scrollTimer=w,n.disableObjectsEvent(),this._controlHandler(R=>{this._fillControlColors.push(R.fill)}),this._scenePointerMoveSub=n.onPointerMove$.subscribeEvent(R=>{var U;const{offsetX:M,offsetY:O}=R,N=n.getActiveViewportByCoord(P.Vector2.FromArray([M,O]));if(!this._injector.get(Ce).interceptor.fetchThroughInterceptors(Ko)(!1,{x:o.offsetX,y:o.offsetY,skeleton:this._skeleton,scene:this._scene}))return;const{x:H,y:k}=n.getCoordRelativeToViewport(P.Vector2.FromArray([M,O]));this._autoFillMoving(H,k),n.setCursor(P.CURSOR_TYPE.CROSSHAIR);const V=this._targetSelection;if(E&&N&&((U=this._activeViewport)==null?void 0:U.viewportKey)!==(N==null?void 0:N.viewportKey)){let W;V.startRow!==c?(w.scrollTimerType=P.ScrollTimerType.Y,W={...V,endRow:V.startRow}):V.endRow!==u?(w.scrollTimerType=P.ScrollTimerType.Y,W={...V,startRow:V.endRow}):V.startColumn!==d?(w.scrollTimerType=P.ScrollTimerType.X,W={...V,endColumn:V.startColumn}):(w.scrollTimerType=P.ScrollTimerType.X,W={...V,startColumn:V.endColumn}),this._isSelectionInViewport(W,N)&&(E.scrollToBarPos({x:w.scrollTimerType===P.ScrollTimerType.X?0:void 0,y:w.scrollTimerType===P.ScrollTimerType.Y?0:void 0}),this._activeViewport=N)}w.scrolling(H,k,()=>{this._autoFillMoving(H,k)})}),this._scenePointerUpSub=n.onPointerUp$.subscribeEvent(()=>{var M,O;(M=this._helperSelection)==null||M.dispose();const R=this._scene;R.resetCursor(),this._clearObserverEvent(),R.enableObjectsEvent(),(O=this._scrollTimer)==null||O.dispose(),this._control.refreshSelectionFilled(this._targetSelection),this._isInMergeState=!1,this._controlHandler((N,D)=>{N.setProps({fill:this._fillControlColors[D]})}),this._fillControlColors=[]})}_hasMergeInRange(o,e,t,n){return this._skeleton.worksheet.getMergedCellRange(o,e,t,n).length>0}_swapPositions(o,e,t,n){const r=Math.min(o,t),s=Math.min(e,n),l=Math.max(o,t),c=Math.max(e,n);return{startRow:r,startColumn:s,endRow:l,endColumn:c}}_controlHandler(o){const{leftControl:e,rightControl:t,topControl:n,bottomControl:r,backgroundControlTop:s,backgroundControlMiddleLeft:l,backgroundControlMiddleRight:c,backgroundControlBottom:d,fillControl:u}=this._control,h=[e,t,n,r,s,l,c,d,u];for(let S=0,g=h.length;S<g;S++){const f=h[S];o(f,S)}}_fillRuler(o,e,t,n,r){let s=!1;if(o<e)if(this._isInMergeState&&o<e){const l=e-o,c=n+1,d=Math.ceil(l/c);let u=e-d*c;u<0&&(u=e-(d-1)*c),e=u}else e=o;else if(o>=e&&o<=t)s=!0,this._isInMergeState||(t=o);else if(this._isInMergeState&&o>t){const l=o-t,c=n+1,d=Math.ceil(l/c);let u=t+d*c;u>r&&(u=t+(d-1)*c),t=u}else t=o;return{rowOrColumn:o,startRowOrColumn:e,endRowOrColumn:t,isLighten:s}}_getScale(){const{scaleX:o,scaleY:e}=this._scene.getAncestorScale();return Math.max(o,e)}}var Qo=(i=>(i.Selection="__SpreadsheetSelectionShape__",i.top="__SpreadsheetSelectionTopControl__",i.bottom="__SpreadsheetSelectionBottomControl__",i.left="__SpreadsheetSelectionShapeLeftControl__",i.right="__SpreadsheetSelectionShapeRightControl__",i.backgroundTop="__SpreadsheetSelectionBackgroundControlTop__",i.backgroundMiddleLeft="__SpreadsheetSelectionBackgroundControlMiddleLeft__",i.backgroundMiddleRight="__SpreadsheetSelectionBackgroundControlMiddleRight__",i.backgroundBottom="__SpreadsheetSelectionBackgroundControlBottom__",i.fill="__SpreadsheetSelectionFillControl__",i.fillTopLeft="__SpreadsheetSelectionFillControlTopLeft__",i.fillBottomRight="__SpreadsheetSelectionFillControlBottomRight__",i.fillTopLeftInner="__SpreadsheetSelectionFillControlTopLeftInner__",i.fillBottomRightInner="__SpreadsheetSelectionFillControlBottomRightInner__",i.lineMain="__SpreadsheetDragLineMainControl__",i.lineContent="__SpreadsheetDragLineContentControl__",i.line="__SpreadsheetDragLineControl__",i.dash="__SpreadsheetDragDashControl__",i.rowHeaderBackground="__SpreadSheetSelectionRowHeaderBackground__",i.rowHeaderBorder="__SpreadSheetSelectionRowHeaderBorder__",i.rowHeaderGroup="__SpreadSheetSelectionRowHeaderGroup__",i.columnHeaderBackground="__SpreadSheetSelectionColumnHeaderBackground__",i.columnHeaderBorder="__SpreadSheetSelectionColumnHeaderBorder__",i.columnHeaderGroup="__SpreadSheetSelectionColumnHeaderGroup__",i.topLeftWidget="__SpreadSheetSelectionTopLeftWidget__",i.topCenterWidget="__SpreadSheetSelectionTopCenterWidget__",i.topRightWidget="__SpreadSheetSelectionTopRightWidget__",i.middleLeftWidget="__SpreadSheetSelectionMiddleLeftWidget__",i.middleRightWidget="__SpreadSheetSelectionMiddleRightWidget__",i.bottomLeftWidget="__SpreadSheetSelectionBottomLeftWidget__",i.bottomCenterWidget="__SpreadSheetSelectionBottomCenterWidget__",i.bottomRightWidget="__SpreadSheetSelectionBottomRightWidget__",i))(Qo||{});const qs=.3;class Fn extends a.Disposable{constructor(e,t,n,r){var s,l,c,d;super();T(this,"_isHelperSelection",!0);T(this,"_enableAutoFill",!0);T(this,"_showAutoFill",!1);T(this,"_highlightHeader",!0);T(this,"_selectionRenderModel");T(this,"_leftBorder");T(this,"_rightBorder");T(this,"_topBorder");T(this,"_bottomBorder");T(this,"_backgroundControlTop");T(this,"_backgroundControlBottom");T(this,"_backgroundControlMiddleLeft");T(this,"_backgroundControlMiddleRight");T(this,"_autoFillControl");T(this,"_selectionShapeGroup");T(this,"_rowHeaderBackground");T(this,"_rowHeaderBorder");T(this,"_rowHeaderGroup");T(this,"_columnHeaderBackground");T(this,"_columnHeaderBorder");T(this,"_columnHeaderGroup");T(this,"_dashedRect");T(this,"_topLeftWidget");T(this,"_topCenterWidget");T(this,"_topRightWidget");T(this,"_middleLeftWidget");T(this,"_middleRightWidget");T(this,"_bottomLeftWidget");T(this,"_bottomCenterWidget");T(this,"_bottomRightWidget");T(this,"_defaultStyle");T(this,"_currentStyle");T(this,"_rowHeaderWidth",0);T(this,"_columnHeaderHeight",0);T(this,"_widgetRects",[]);T(this,"_controlExtension");T(this,"_dispose$",new A.BehaviorSubject(this));T(this,"dispose$",this._dispose$.asObservable());T(this,"selectionMoving$",new A.Subject);T(this,"selectionMoveEnd$",new A.Subject);T(this,"selectionScaling$",new A.Subject);T(this,"selectionScaled$",new A.Subject);T(this,"selectionFilling$",new A.Subject);T(this,"_selectionFilled$",new A.Subject);T(this,"selectionFilled$",this._selectionFilled$.asObservable());T(this,"_antLineOffset",0);T(this,"_antRequestNewFrame",-1);this._scene=e,this._zIndex=t,this._themeService=n,this._enableAutoFill=(s=r==null?void 0:r.enableAutoFill)!=null?s:!0,this._highlightHeader=(l=r==null?void 0:r.highlightHeader)!=null?l:!0,this._rowHeaderWidth=(c=r==null?void 0:r.rowHeaderWidth)!=null?c:0,this._columnHeaderHeight=(d=r==null?void 0:r.columnHeaderHeight)!=null?d:0,this._initializeSheetBody(),this._initialHeader()}_initializeSheetBody(){this._defaultStyle=gt(this._themeService),this._currentStyle=gt(this._themeService),this._selectionRenderModel=new bd;const e=this._zIndex;this._leftBorder=new P.Rect("__SpreadsheetSelectionShapeLeftControl__"+e,{zIndex:e}),this._rightBorder=new P.Rect("__SpreadsheetSelectionShapeRightControl__"+e,{zIndex:e}),this._topBorder=new P.Rect("__SpreadsheetSelectionTopControl__"+e,{zIndex:e}),this._bottomBorder=new P.Rect("__SpreadsheetSelectionBottomControl__"+e,{zIndex:e}),this._backgroundControlTop=new P.Rect("__SpreadsheetSelectionBackgroundControlTop__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlBottom=new P.Rect("__SpreadsheetSelectionBackgroundControlBottom__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleLeft=new P.Rect("__SpreadsheetSelectionBackgroundControlMiddleLeft__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleRight=new P.Rect("__SpreadsheetSelectionBackgroundControlMiddleRight__"+e,{zIndex:e-1,evented:!1}),this._autoFillControl=new P.Rect("__SpreadsheetSelectionFillControl__"+e,{zIndex:e+1}),this._autoFillControl.hide(),this._dashedRect=new P.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 P.Group("__SpreadsheetSelectionShape__"+e,...t,...this._widgetRects),this._selectionShapeGroup.hide(),this._selectionShapeGroup.evented=!1,this._selectionShapeGroup.zIndex=e;const n=this.getScene();n.addObject(this._selectionShapeGroup,Wi),this.disposeWithMe(a.toDisposable(n.onTransformChange$.subscribeEvent(r=>{r.type===P.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&(this._updateLayoutOfSelectionControl(this._currentStyle),this._updateControlCoord())})))}_initialHeader(){const e=this._zIndex;this._rowHeaderBackground=new P.Rect("__SpreadSheetSelectionRowHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderBorder=new P.Rect("__SpreadSheetSelectionRowHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderGroup=new P.Group("__SpreadSheetSelectionRowHeaderGroup__"+e,this._rowHeaderBackground,this._rowHeaderBorder),this._rowHeaderGroup.hide(),this._rowHeaderGroup.evented=!1,this._rowHeaderGroup.zIndex=e,this._columnHeaderBackground=new P.Rect("__SpreadSheetSelectionColumnHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderBorder=new P.Rect("__SpreadSheetSelectionColumnHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderGroup=new P.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],Id)}_initialWidget(){const e=this._zIndex;return this._topLeftWidget=new P.Rect("__SpreadSheetSelectionTopLeftWidget__"+e,{zIndex:e+1}),this._topCenterWidget=new P.Rect("__SpreadSheetSelectionTopCenterWidget__"+e,{zIndex:e+1}),this._topRightWidget=new P.Rect("__SpreadSheetSelectionTopRightWidget__"+e,{zIndex:e+1}),this._middleLeftWidget=new P.Rect("__SpreadSheetSelectionMiddleLeftWidget__"+e,{zIndex:e+1}),this._middleRightWidget=new P.Rect("__SpreadSheetSelectionMiddleRightWidget__"+e,{zIndex:e+1}),this._bottomLeftWidget=new P.Rect("__SpreadSheetSelectionBottomLeftWidget__"+e,{zIndex:e+1}),this._bottomCenterWidget=new P.Rect("__SpreadSheetSelectionBottomCenterWidget__"+e,{zIndex:e+1}),this._bottomRightWidget=new P.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 Ks(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:n,widgets:r,autofillStroke:s,strokeDash:l,isAnimationDash:c}=t;let d=t.autofillSize,u=t.strokeWidth,h=t.autofillStrokeWidth;const S=this._getScale(),g=(u+m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH)/2/S;u/=S,d/=S,h/=S<1?1:S;const f=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/S,p=P.FIX_ONE_PIXEL_BLUR_OFFSET/S,{startX:C,startY:v,endX:b,endY:E}=this._selectionRenderModel;if(this.leftControl.transformByState({height:E-v,left:-g+p,width:u,strokeWidth:f,top:-f/2+p}),this.leftControl.setProps({fill:n,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.rightControl.transformByState({height:E-v,left:b-C-g+p,width:u,strokeWidth:f,top:-f/2+p}),this.rightControl.setProps({fill:n,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.topControl.transformByState({width:b-C+u,top:-g+p,left:-g+p,height:u,strokeWidth:f}),this.topControl.setProps({fill:n,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.bottomControl.transformByState({width:b-C+u,top:E-v-g+p,height:u,left:-g+p,strokeWidth:f}),this.bottomControl.setProps({fill:n,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),l==null)this.dashedRect.hide(),this._stopAntLineAnimation();else{const w=t.strokeWidth*2/S;this.dashedRect.transformByState({height:E-v,width:b-C,strokeWidth:w,left:-w/2+p,top:-w/2+p}),this.dashedRect.setProps({strokeDashArray:[0,l/S]}),this._stopAntLineAnimation(),c!==!1&&this._startAntLineAnimation(),this.dashedRect.show()}if(this._showAutoFill=this._showAutoFill&&this._enableAutoFill,this._showAutoFill&&!this._hasWidgets(r)){const w={fill:n,stroke:s,strokeScaleEnabled:!1},R={width:d-h,height:d-h,left:b-C-d/2+h/2-p,top:E-v-d/2+h/2-p,strokeWidth:h};this._autoFillControl.setProps(w),this._autoFillControl.transformByState(R),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,n=0,r,s){this._rowHeaderWidth=t,this._columnHeaderHeight=n,this.updateRangeBySelectionWithCoord({rangeWithCoord:e,primaryWithCoord:s,style:r}),r&&this.updateStyle(r)}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,n,r,s,l,c,d,u,h,S,g,f,p,C,v,b,E,w,R,M,O,N,D,H;(e=this._leftBorder)==null||e.dispose(),(t=this._rightBorder)==null||t.dispose(),(n=this._topBorder)==null||n.dispose(),(r=this._bottomBorder)==null||r.dispose(),(s=this._backgroundControlTop)==null||s.dispose(),(l=this._backgroundControlMiddleLeft)==null||l.dispose(),(c=this._backgroundControlMiddleRight)==null||c.dispose(),(d=this._backgroundControlBottom)==null||d.dispose(),this._autoFillControl.dispose(),(u=this._selectionShapeGroup)==null||u.dispose(),(h=this._rowHeaderBackground)==null||h.dispose(),(S=this._rowHeaderBorder)==null||S.dispose(),(g=this._rowHeaderGroup)==null||g.dispose(),(f=this._rowHeaderBackground)==null||f.dispose(),(p=this._columnHeaderBackground)==null||p.dispose(),(C=this._columnHeaderBorder)==null||C.dispose(),(v=this._columnHeaderGroup)==null||v.dispose(),(b=this._topLeftWidget)==null||b.dispose(),(E=this._topCenterWidget)==null||E.dispose(),(w=this._topRightWidget)==null||w.dispose(),(R=this._middleLeftWidget)==null||R.dispose(),(M=this._middleRightWidget)==null||M.dispose(),(O=this._bottomLeftWidget)==null||O.dispose(),(N=this._bottomCenterWidget)==null||N.dispose(),(D=this._bottomRightWidget)==null||D.dispose(),(H=this._controlExtension)==null||H.dispose(),super.dispose(),this._dispose$.next(this),this._dispose$.complete()}getCurrentCellInfo(){const e=this.model.currentCell;if(e){let t;if(e.isMerged){const n=e.mergeInfo;t={startRow:n.startRow,endRow:n.endRow,startColumn:n.startColumn,endColumn:n.endColumn,startX:n.startX,endX:n.endX,startY:n.startY,endY:n.endY}}else{const{actualRow:n,actualColumn:r,startX:s,endX:l,startY:c,endY:d}=e;t={startRow:n,endRow:n,startColumn:r,endColumn:r,startX:s,endX:l,startY:c,endY:d}}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:n,endX:r,endY:s,rangeType:l}=this._selectionRenderModel,c=this._currentStyle,d=this._getScale(),{stroke:u,rowHeaderFill:h=c.rowHeaderFill,rowHeaderStroke:S=c.rowHeaderStroke,columnHeaderFill:g=c.columnHeaderFill,columnHeaderStroke:f=c.columnHeaderStroke}=e;let{rowHeaderStrokeWidth:p=c.rowHeaderStrokeWidth,columnHeaderStrokeWidth:C=c.columnHeaderStrokeWidth}=e;p/=d,C/=d;const v=this._rowHeaderWidth,b=this._columnHeaderHeight;if(this._highlightHeader&&b>0){let E=g;l===a.RANGE_TYPE.COLUMN&&(E=new a.ColorKit(u).setAlpha(qs).toString()),this._columnHeaderBackground.setProps({fill:E}),this._columnHeaderBackground.resize(r-t,b),this._columnHeaderBorder.setProps({fill:f}),this._columnHeaderBorder.transformByState({width:r-t,height:C,top:b-C+1/d}),this._columnHeaderGroup.show(),this._columnHeaderGroup.translate(t,0)}else this._columnHeaderGroup.hide();if(this._columnHeaderGroup.makeDirty(!0),this._highlightHeader&&v>0){let E=h;l===a.RANGE_TYPE.ROW&&(E=new a.ColorKit(u).setAlpha(qs).toString()),this._rowHeaderBackground.setProps({fill:E}),this._rowHeaderBackground.resize(v,s-n),this._rowHeaderBorder.setProps({fill:S}),this._rowHeaderBorder.transformByState({width:p,height:s-n,left:v-p+1/d}),this._rowHeaderGroup.show(),this._rowHeaderGroup.translate(0,n)}else this._rowHeaderGroup.hide();this._rowHeaderGroup.makeDirty(!0)}_updateBackgroundControl(e){const{startX:t,startY:n,endX:r,endY:s}=this._selectionRenderModel,l=this._getScale(),{fill:c=e.fill}=e;let{strokeWidth:d}=e;d/=l;const u=this._selectionRenderModel.highlightToSelection();if(!u){this._backgroundControlTop.resize(r-t,s-n),this._backgroundControlTop.setProps({fill:c}),this._backgroundControlBottom.resize(0,0),this._backgroundControlMiddleLeft.resize(0,0),this._backgroundControlMiddleRight.resize(0,0);return}const{startX:h,startY:S,endX:g,endY:f}=u,p=d/2,C={left:-p,top:-p,width:r-t+p*2,height:S-n+p};C.height<0&&(C.width=0,C.height=0),this._backgroundControlTop.transformByState(C);const v={left:-p,top:S-n,width:h-t+p,height:f-S};v.width<0&&(v.width=0,v.height=0),this._backgroundControlMiddleLeft.transformByState(v);const b={left:g-t-p,top:S-n,width:r-g+p*2,height:f-S};b.width<0&&(b.width=0,b.height=0),this._backgroundControlMiddleRight.transformByState(b);const E={left:-p,top:f-n,width:r-t+p*2,height:s-f+p};E.height<0&&(E.width=0,E.height=0),this._backgroundControlBottom.transformByState(E),this._backgroundControlTop.setProps({fill:c}),this._backgroundControlMiddleLeft.setProps({fill:c}),this._backgroundControlMiddleRight.setProps({fill:c}),this._backgroundControlBottom.setProps({fill:c})}_updateWidgets(e){const{startX:t,startY:n,endX:r,endY:s}=this._selectionRenderModel,{stroke:l=e.stroke,widgets:c=e.widgets,widgetStroke:d=e.widgetStroke}=e,u=this._getScale();let{widgetSize:h,widgetStrokeWidth:S}=e;h/=u,S/=u;const g={left:-h/2+S/2,center:(r-t)/2-h/2+S/2,right:r-t-h/2+S/2,top:-h/2,middle:(s-n)/2-h/2,bottom:s-n-h/2+S/2},f=h-S;this._widgetRects.forEach(p=>{p.setProps({fill:l,stroke:d})}),c.tl===!0?(this._topLeftWidget.transformByState({height:f,width:f,left:g.left,top:g.top,strokeWidth:S}),this._topLeftWidget.show()):this._topLeftWidget.hide(),c.tc===!0?(this._topCenterWidget.transformByState({height:f,width:f,left:g.center,top:g.top,strokeWidth:S}),this._topCenterWidget.show()):this._topCenterWidget.hide(),c.tr===!0?(this._topRightWidget.transformByState({height:f,width:f,left:g.right,top:g.top,strokeWidth:S}),this._topRightWidget.show()):this._topRightWidget.hide(),c.ml===!0?(this._middleLeftWidget.transformByState({height:f,width:f,left:g.left,top:g.middle,strokeWidth:S}),this._middleLeftWidget.show()):this._middleLeftWidget.hide(),c.mr===!0?(this._middleRightWidget.transformByState({height:f,width:f,left:g.right,top:g.middle,strokeWidth:S}),this._middleRightWidget.show()):this._middleRightWidget.hide(),c.bl===!0?(this._bottomLeftWidget.transformByState({height:f,width:f,left:g.left,top:g.bottom,strokeWidth:S}),this._bottomLeftWidget.show()):this._bottomLeftWidget.hide(),c.bc===!0?(this._bottomCenterWidget.transformByState({height:f,width:f,left:g.center,top:g.bottom,strokeWidth:S}),this._bottomCenterWidget.show()):this._bottomCenterWidget.hide(),c.br===!0?(this._bottomRightWidget.transformByState({height:f,width:f,left:g.right,top:g.bottom,strokeWidth:S}),this._bottomRightWidget.show()):this._bottomRightWidget.hide()}_hasWidgets(e){if(e==null)return!1;const t=Object.keys(e);if(t.length===0)return!1;for(const n of t)if(e[n]===!0)return!0;return!1}_getScale(){const{scaleX:e,scaleY:t}=this._scene.getAncestorScale();return Math.max(e,t)}_stopAntLineAnimation(){this._antLineOffset=0,P.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=P.requestNewFrame(()=>{this._startAntLineAnimation()})}}class Td extends P.Layer{render(o,e=!1){const t=a.Tools.now();return super.render(o,e),this._afterRender(t),this}_afterRender(o){this.scene.getEngine().renderFrameTimeMetric$.next(["selectionLayer",a.Tools.now()-o])}}const Ce=a.createIdentifier("univer.sheet.selection-render-service");class Jo extends a.Disposable{constructor(e,t,n,r,s){super();T(this,"_downObserver");T(this,"_scenePointerMoveSub");T(this,"_scenePointerUpSub");T(this,"_controlFillConfig$",new A.BehaviorSubject(null));T(this,"controlFillConfig$",this._controlFillConfig$.asObservable());T(this,"_selectionControls",[]);T(this,"_startRangeWhenPointerDown",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});T(this,"_activeControlIndex",-1);T(this,"_startViewportPosX",0);T(this,"_startViewportPosY",0);T(this,"_scrollTimer");T(this,"_cancelDownSubscription");T(this,"_cancelUpSubscription");T(this,"_skeleton");T(this,"_scene");T(this,"_highlightHeader",!0);T(this,"_rangeType",a.RANGE_TYPE.NORMAL);T(this,"_selectionStyle");T(this,"_remainLastEnabled",!1);T(this,"_skipLastEnabled",!1);T(this,"_singleSelectionEnabled",!1);T(this,"_selectionMoveEnd$",new A.BehaviorSubject([]));T(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());T(this,"_selectionMoving$",new A.Subject);T(this,"selectionMoving$",this._selectionMoving$.asObservable());T(this,"_selectionMoveStart$",new A.Subject);T(this,"selectionMoveStart$",this._selectionMoveStart$.asObservable());T(this,"_selectionMoving",!1);T(this,"_selectionTheme");T(this,"_activeViewport");T(this,"interceptor",new a.InterceptorManager({RANGE_MOVE_PERMISSION_CHECK:Zo,RANGE_FILL_PERMISSION_CHECK:Ko}));T(this,"_escapeShortcutDisposable",null);this._injector=e,this._themeService=t,this._shortcutService=n,this._sheetSkeletonManagerService=r,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,n){const r=this.getSelectionControls().length,{rowHeaderWidth:s,columnHeaderHeight:l}=t,c=new Fn(e,r,this._selectionTheme,{highlightHeader:this._highlightHeader,rowHeaderWidth:s,columnHeaderHeight:l});this._selectionControls.push(c);const d=Me(n,t);return c.updateRangeBySelectionWithCoord(d,t),c.setControlExtension({skeleton:t,scene:e,themeService:this._selectionTheme,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),c}resetSelectionsByModelData(e){const t=this.getSelectionControls(),n=this._skeleton;if(!(!t||!n)){for(let r=0,s=e.length;r<s;r++){const l=e[r],c=Me(l,this._skeleton),d=t[r];d?d.updateRangeBySelectionWithCoord(c,n):this.isSelectionEnabled()&&this.newSelectionControl(this._scene,n,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,n){this._skeleton=e,this._scene=t,this._activeViewport=n||(t==null?void 0:t.getViewports()[0]),t.findLayerByZIndex(Wi)||t.addLayer(new Td(t,[],Wi))}getSkeleton(){return this._skeleton}getSelectionDataWithStyle(){const e=this._selectionControls,[t,n]=this._skeleton.getLocation();return e.map(r=>{const s=r.getValue();return s.rangeWithCoord.sheetId=n,s.rangeWithCoord.unitId=t,s})}getSelectionControls(){return this._selectionControls}_addSelectionControlByModelData(e){var l;const t=this._skeleton,n=(l=e.style)!=null?l:gt(this._selectionTheme),r=this._scene;return e.style=n,this.newSelectionControl(r,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.getCurrentParam())==null?void 0:t.skeleton.getWorksheetConfig().freeze}_getViewportByCell(e,t){if(e===void 0||t===void 0)return null;const n=this._getFreeze();if(!n||n.startRow<=0&&n.startColumn<=0)return this._scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e>n.startRow&&t>n.startColumn)return this._scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e<=n.startRow&&t<=n.startColumn)return this._scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP);if(e<=n.startRow&&t>n.startColumn)return this._scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(e>n.startRow&&t<=n.startColumn)return this._scene.getViewport(P.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,n,r=P.ScrollTimerType.ALL,s,l){var f,p;let c=0,d=0,u=s,h=l;this._scrollTimer=P.ScrollTimer.create(this._scene,r),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 S=this._scene,g=S.getActiveViewportByCoord(P.Vector2.FromArray([s,l]));this._scenePointerMoveSub=S.onPointerMove$.subscribeEvent(C=>{var V,U,W,B,F,z,x,X,Y;const{offsetX:v,offsetY:b}=C,{x:E,y:w}=S.getCoordRelativeToViewport(P.Vector2.FromArray([v,b]));this._movingHandler(E,w,t,n);let R=E,M=w;const O=this.getActiveSelectionControl(),N=this._getFreeze(),D=O==null?void 0:O.model,H=(V=S.getActiveViewportByCoord(P.Vector2.FromArray([v,b])))!=null?V:this._getViewportByCell(D==null?void 0:D.endRow,D==null?void 0:D.endColumn);if((()=>{if(!g||!H||!e)return!1;const J=[P.SHEET_VIEWPORT_KEY.VIEW_MAIN,P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,P.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT];return J.includes(g.viewportKey)&&J.includes(H.viewportKey)})()){if(!g||!H||!e)return!1;const J=u<e.left&&E>e.left||u>e.left&&E<e.left,ie=h<e.top&&w>e.top||h>e.top&&w<e.top;J&&(c+=1),ie&&(d+=1);const $=g.viewportKey,re=H.viewportKey;if($===P.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP)b<e.top&&((U=D==null?void 0:D.endRow)!=null?U:0)<((W=N==null?void 0:N.startRow)!=null?W:0)?M=e.top:ie&&d%2===1&&e.scrollToViewportPos({viewportScrollY:0});else if($===P.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT)v<e.left&&((B=D==null?void 0:D.endColumn)!=null?B:0)<((F=N==null?void 0:N.startColumn)!=null?F:0)?R=e.left:J&&c%2===1&&e.scrollToViewportPos({viewportScrollX:0});else if($===re){let ae=!1,j=!1;$===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP?(ae=!0,j=!0):$===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP?j=!0:$===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT&&(ae=!0),((z=D==null?void 0:D.endRow)!=null?z:0)>((x=N==null?void 0:N.startRow)!=null?x:0)&&(j=!1),((X=D==null?void 0:D.endColumn)!=null?X:0)>((Y=N==null?void 0:N.startColumn)!=null?Y:0)&&(ae=!1),ae&&(R=e.left),j&&(M=e.top)}else{const ae={x:g.scrollX,y:g.scrollY},j={x:H.scrollX,y:H.scrollY},G=ae.x!==j.x&&J&&c%2===1,Z=ae.y!==j.y&&ie&&d%2===1;(G||Z)&&(e.scrollToBarPos({x:G?ae.x:void 0,y:Z?ae.y:void 0}),G||(R=e.left),Z||(M=e.top)),($===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&re===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||re===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&$===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)&&(R=e.left),($===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&re===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||re===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&$===P.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP)&&(M=e.top)}u=E,h=w}this._scrollTimer.scrolling(R,M,()=>{this._movingHandler(E,w,t,n)})})}attachSelectionWithCoord(e){return Me(e,this._skeleton)}attachPrimaryWithCoord(e){return xn(this._skeleton,e)}getSelectionCellByPosition(e,t){return this.getCellWithCoordByOffset(e,t)}getCellWithCoordByOffset(e,t,n){const r=this._scene,s=n!=null?n:this._skeleton,l=r.getViewportScrollXY(r.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:c,scaleY:d}=r.getAncestorScale();return s.getCellWithCoordByOffset(e,t,c,d,l)}_movingHandler(e,t,n,r){var R,M,O,N,D;const s=this._skeleton,l=this._scene,[c,d]=s.getLocation(),u={startRow:(R=n==null?void 0:n.model.startRow)!=null?R:-1,endRow:(M=n==null?void 0:n.model.endRow)!=null?M:-1,startColumn:(O=n==null?void 0:n.model.startColumn)!=null?O:-1,endColumn:(N=n==null?void 0:n.model.endColumn)!=null?N:-1,unitId:c,sheetId:d},h=l.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN),S=(D=this._getViewportByCell(u.endRow,u.endColumn))!=null?D:h,g=l.getScrollXYInfoByViewport(P.Vector2.FromArray([this._startViewportPosX,this._startViewportPosY]),S),{scaleX:f,scaleY:p}=l.getAncestorScale();r===a.RANGE_TYPE.ROW?e=Number.POSITIVE_INFINITY:r===a.RANGE_TYPE.COLUMN&&(t=Number.POSITIVE_INFINITY);const C=this._skeleton.getCellByOffset(e,t,f,p,g);if(!C)return;let v={startRow:Math.min(C.startRow,this._startRangeWhenPointerDown.startRow),startColumn:Math.min(C.startColumn,this._startRangeWhenPointerDown.startColumn),endRow:Math.max(C.endRow,this._startRangeWhenPointerDown.endRow),endColumn:Math.max(C.endColumn,this._startRangeWhenPointerDown.endColumn)};this._shouldDetectMergedCells&&(v=s.expandRangeByMerge(v));const E=Me({range:v,primary:void 0,style:null},s);E.rangeWithCoord.unitId=c,E.rangeWithCoord.sheetId=d,E.rangeWithCoord.rangeType=r;const w=u.startRow!==v.startRow||u.startColumn!==v.startColumn||u.endRow!==v.endRow||u.endColumn!==v.endColumn;n!=null&&w&&(n.updateRangeBySelectionWithCoord(E),this._selectionMoving$.next(this.getSelectionDataWithStyle()))}_clearUpdatingListeners(){var t,n,r,s,l;this._scene.enableObjectsEvent(),(t=this._scenePointerMoveSub)==null||t.unsubscribe(),this._scenePointerMoveSub=null,(n=this._scenePointerUpSub)==null||n.unsubscribe(),this._scenePointerUpSub=null,(r=this._cancelDownSubscription)==null||r.unsubscribe(),this._cancelDownSubscription=null,(s=this._cancelUpSubscription)==null||s.unsubscribe(),this._cancelUpSubscription=null,(l=this._scrollTimer)==null||l.dispose()}_addEndingListeners(){var n,r,s;const e=this._scene,t=(n=e.getEngine())==null?void 0:n.activeScene;!t||t===e||((r=this._cancelDownSubscription)==null||r.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,n,r,s){const l=this._skeleton;if(l==null)return null;if(this._shouldDetectMergedCells){const v=l==null?void 0:l.getCellWithCoordByOffset(e,t,n,r,s,{firstMatch:!0});if(!v)return;const b=a.convertCellToRange(v);return{primaryWithCoord:v,rangeWithCoord:b}}const{row:c,column:d}=l.getCellIndexByOffset(e,t,n,r,s),u=l.getNoMergeCellWithCoordByIndex(c,d),{startX:h,startY:S,endX:g,endY:f}=u,p={startY:S,endY:f,startX:h,endX:g,startRow:c,endRow:c,startColumn:d,endColumn:d};return{primaryWithCoord:{mergeInfo:p,actualRow:c,actualColumn:d,isMerged:!1,isMergedMainCell:!1,startY:S,endY:f,startX:h,endX:g},rangeWithCoord:p}}_checkClearPreviousControls(e){this.getSelectionControls().length!==0&&(!e.ctrlKey&&!e.shiftKey&&!this._remainLastEnabled||this._singleSelectionEnabled&&!e.shiftKey)&&this._clearAllSelectionControls()}_makeSelectionByTwoCells(e,t,n,r,s){const{actualRow:l,actualColumn:c,mergeInfo:d}=e;this._startRangeWhenPointerDown={...e.mergeInfo};const u=Math.min(l,t.startRow,d.startRow),h=Math.max(l,t.endRow,d.endRow),S=Math.min(c,t.startColumn,d.startColumn),g=Math.max(c,t.endColumn,d.endColumn),p={range:n.expandRangeByMerge({startRow:u,startColumn:S,endRow:h,endColumn:g}),primary:null,style:null},C=Me(p,n);s.updateRangeBySelectionWithCoord(C)}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 $o(i){return{range:{startRow:0,startColumn:0,endRow:i.getRowCount()-1,endColumn:i.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL},primary:Bi(i).primary,style:null}}function Bi(i){return Qs(i,{startRow:0,startColumn:0,endRow:0,endColumn:0})}function Qs(i,o){const e=i.worksheet.getCellInfoInMergeData(o.startRow,o.startColumn),t=i.worksheet.getCellInfoInMergeData(o.endRow,o.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 wd=Object.defineProperty,yd=Object.getOwnPropertyDescriptor,Pd=(i,o,e,t)=>{for(var n=t>1?void 0:t?yd(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&wd(o,e,n),n},Js=(i,o)=>(e,t)=>o(e,t,i);y.SheetSkeletonManagerService=class extends a.Disposable{constructor(e,t,n){super();T(this,"_sheetId","");T(this,"_sheetSkeletonParamStore",new Map);T(this,"_currentSkeleton$",new A.BehaviorSubject(null));T(this,"currentSkeleton$",this._currentSkeleton$.asObservable());T(this,"_currentSkeletonBefore$",new A.BehaviorSubject(null));T(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._context=e,this._injector=t,this._sheetSkService=n,this.disposeWithMe(()=>{this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._sheetSkeletonParamStore.forEach(r=>this.disposeSkeleton(r.sheetId)),this._sheetSkeletonParamStore.clear()}),this._initRemoveSheet()}_initRemoveSheet(){this.disposeWithMe(this._context.unit.sheetDisposed$.subscribe(e=>{this.disposeSkeleton(e.getSheetId())}))}getCurrentSkeleton(){var e;return(e=this.getCurrentParam())==null?void 0:e.skeleton}getCurrent(){return this.getCurrentParam()}getCurrentParam(){return this._getSkeletonParam(this._sheetId)}getSkeleton(e){return this._getSkeleton(e)}getSkeletonParam(e){return this._getSkeletonParam(e)}getWorksheetSkeleton(e){return this.getSkeletonParam(e)}getUnitSkeleton(e,t){const n=this._getSkeletonParam(t);return n!=null&&(n.unitId=e),n}setCurrent(e){this._setCurrent(e.sheetId)}setSkeletonParam(e,t){this._sheetSkService.setSkeleton(t.unitId,e,t.skeleton),this._sheetSkeletonParamStore.set(e,t)}_setCurrent(e){this._sheetId=e;const t=this._getSkeletonParam(e),n=this._context.unitId;if(t!=null)this.reCalculate(t);else{const l=this._context.unit.getSheetBySheetId(e);if(l==null)return;const c=this._context.scene,d=this._buildSkeleton(l,c);this.setSkeletonParam(e,{unitId:n,sheetId:e,skeleton:d,dirty:!1})}const r=this._getSkeletonParam(e);this._currentSkeletonBefore$.next(r),this._currentSkeleton$.next(r)}reCalculate(e){e||(e=this.getCurrentParam()),e!=null&&(e.dirty&&(e.skeleton.makeDirty(!0),e.dirty=!1),e.skeleton.calculate())}makeDirty(e,t=!0){const n=this._getSkeletonParam(e.sheetId);n!=null&&(n.dirty=t)}getOrCreateSkeleton(e){return this.ensureSkeleton(e.sheetId)}ensureSkeleton(e){const t=this._getSkeletonParam(e);if(t)return t.skeleton;const r=this._context.unit.getSheetBySheetId(e);if(!r)return;const s=this._buildSkeleton(r);return this.setSkeletonParam(e,{unitId:this._context.unitId,sheetId:e,skeleton:s,dirty:!1}),s}disposeSkeleton(e){const t=this.getSkeletonParam(e);t&&(t.skeleton.dispose(),this._sheetSkeletonParamStore.delete(e),this._sheetSkService.deleteSkeleton(t.unitId,e))}attachRangeWithCoord(e){const t=this.getCurrentSkeleton();return t?rn(t,e):null}_getSkeletonParam(e){return this._sheetSkeletonParamStore.get(e)}_getSkeleton(e){const t=this._getSkeletonParam(e);return t?t.skeleton:null}_buildSkeleton(e,t){return this._injector.createInstance(P.SpreadsheetSkeleton,e,this._context.unit.getStyles())}setColumnHeaderSize(e,t,n){var u;if(!e)return;const r=(u=this.getWorksheetSkeleton(t))==null?void 0:u.skeleton;if(!r)return;r.columnHeaderHeight=n,e.scene.getViewports()[0].top=n,e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({height:n}),e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({height:n}),e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({top:n}),e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({top:n}),e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({height:n});const s=e==null?void 0:e.with(m.SheetsSelectionsService),l=e==null?void 0:e.with(Ce),c=s.getCurrentSelections();l.resetSelectionsByModelData(c);const d=this.getUnitSkeleton(e.unitId,t);d&&(d.commandId=Ui.id,this._currentSkeleton$.next(d))}setRowHeaderSize(e,t,n){var f;const r=(f=this.getWorksheetSkeleton(t))==null?void 0:f.skeleton;if(!e||!r)return;r.rowHeaderWidth=n;const s=e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).width||46,l=n-s,c=e.scene.getViewports()[0].left;e.scene.getViewports()[0].left=c+l,e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({width:n}),e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({width:n}),e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({left:n});const d=e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).left||0;e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({left:d+l}),e.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({width:n});const u=e==null?void 0:e.with(m.SheetsSelectionsService),h=e==null?void 0:e.with(Ce),S=u.getCurrentSelections();h.resetSelectionsByModelData(S);const g=this.getCurrent();g&&(g.commandId=Li.id,this._currentSkeleton$.next(g))}},y.SheetSkeletonManagerService=Pd([Js(1,a.Inject(a.Injector)),Js(2,a.Inject(m.SheetSkeletonService))],y.SheetSkeletonManagerService);function nt(){const i=_.useDependency(a.IUniverInstanceService),o=_.useObservable(()=>i.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]);return o!=null?o:null}function Md(i){return _.useObservable(()=>{var e;return(e=i==null?void 0:i.activeSheet$)!=null?e:A.of(null)},void 0,void 0,[i])}function Rd(){const i=_.useDependency(a.IUniverInstanceService);return _.useObservable(()=>A.merge([i.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET),i.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET)]).pipe(A.map(()=>i.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET)),A.startWith(i.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET))),[],void 0,[i])}const Od="SheetUI";var er=(i=>(i.FILTER_PANEL_EMBED_POINT="filter-panel-embed-point",i.SHEETS_FOOTER="sheets-footer",i.FORMULA_AUX="formula-aux",i))(er||{}),Ad=Object.defineProperty,Nd=Object.getOwnPropertyDescriptor,Dd=(i,o,e,t)=>{for(var n=t>1?void 0:t?Nd(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&Ad(o,e,n),n},xi=(i,o)=>(e,t)=>o(e,t,i);const tr=["ff","fs","tr","tb"];y.AutoHeightController=class extends a.Disposable{constructor(o,e,t,n){super(),this._renderManagerService=o,this._sheetInterceptorService=e,this._selectionManagerService=t,this._univerInstanceService=n,this._initialize()}getUndoRedoParamsOfAutoHeight(o){const{_univerInstanceService:e}=this,t=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),n=t.getActiveSheet(),r=t.getUnitId(),s=n.getSheetId(),l=this._renderManagerService.getRenderById(r).with(y.SheetSkeletonManagerService);if(!s||!l.getCurrentParam())return{redos:[],undos:[]};const{skeleton:c}=l.getCurrentParam(),d=c.calculateAutoHeightInRange(o),u={subUnitId:s,unitId:r,rowsAutoHeightInfo:d},h=m.SetWorksheetRowAutoHeightMutationFactory(u,n);return{undos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:h}],redos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:u}]}}_initialize(){const{_sheetInterceptorService:o,_selectionManagerService:e}=this;this.disposeWithMe(o.interceptCommand({getMutations:t=>{if(t.id===m.SetRangeValuesCommand.id){const n=t.params;return this.getUndoRedoParamsOfAutoHeight(n.range)}return{redos:[],undos:[]}}})),this.disposeWithMe(o.interceptCommand({getMutations:t=>t.id!==m.SetWorksheetRowIsAutoHeightCommand.id?{redos:[],undos:[]}:this.getUndoRedoParamsOfAutoHeight(t.params.ranges)})),this.disposeWithMe(o.interceptCommand({getMutations:t=>{var r,s;if(t.id!==m.SetStyleCommand.id)return{redos:[],undos:[]};if(!tr.includes((r=t.params)==null?void 0:r.style.type))return{redos:[],undos:[]};const n=(s=e.getCurrentSelections())==null?void 0:s.map(l=>l.range);return n!=null&&n.length?this.getUndoRedoParamsOfAutoHeight(n):{redos:[],undos:[]}}})),this.disposeWithMe(o.interceptAfterCommand({getMutations:t=>{if(t.id===m.MoveRangeCommand.id){const n=t.params;return this.getUndoRedoParamsOfAutoHeight([n.fromRange,n.toRange])}if(t.id===m.ReorderRangeCommand.id){const n=t.params;return this.getUndoRedoParamsOfAutoHeight([n.range])}return{redos:[],undos:[]}}}))}},y.AutoHeightController=Dd([xi(0,P.IRenderManagerService),xi(1,a.Inject(m.SheetInterceptorService)),xi(2,a.Inject(m.SheetsSelectionsService)),xi(3,a.Inject(a.IUniverInstanceService))],y.AutoHeightController);function sn(i,o,e,t){const n=o.get(a.IUniverInstanceService),r=e?n.getUnit(e,a.UniverInstanceType.UNIVER_SHEET):n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=t?r==null?void 0:r.getSheetBySheetId(t):r==null?void 0:r.getActiveSheet();if(!s)return null;const{startRow:l,endRow:c,startColumn:d,endColumn:u}=i,h=[],S=[];for(let g=l;g<=c;g++)s.getRowFiltered(g)||h.push(g);for(let g=d;g<=u;g++)S.push(g);return{rows:h,cols:S}}function ft(i){const{rows:o,cols:e}=i;return{startRow:o[0],endRow:o[o.length-1],startColumn:e[0],endColumn:e[e.length-1]}}function Mt(i){let o=[],e=[];const t=[];return i.forEach(n=>{o=o.concat(n.rows),e=e.concat(n.cols)}),o=Array.from(new Set(o)).sort((n,r)=>n-r),e=Array.from(new Set(e)).sort((n,r)=>n-r),i.forEach(n=>{t.push({startRow:o.findIndex(r=>r===n.rows[0]),endRow:o.findIndex(r=>r===n.rows[n.rows.length-1]),startColumn:e.findIndex(r=>r===n.cols[0]),endColumn:e.findIndex(r=>r===n.cols[n.cols.length-1])})}),{ranges:t,mapFunc:(n,r)=>({row:o[n],col:e[r]})}}function Hd(i){const o=new a.ObjectMatrix;return i.forEach(e=>{const{rows:t,cols:n}=e;t.forEach(r=>{n.forEach(s=>{o.setValue(r,s,{v:null,p:null,f:null,si:null,custom:null})})})}),o.getData()}const nr={零:0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9},Fi=["零","一","二","三","四","五","六","七","八","九"],$s=["","万","亿","万亿","亿亿"],kd=["","十","百","千"],ea={十:{value:10,secUnit:!1},百:{value:100,secUnit:!1},千:{value:1e3,secUnit:!1},万:{value:1e4,secUnit:!0},亿:{value:1e8,secUnit:!0}};function it(i){if(!i)return 0;let o=0,e=0,t=0,n=!1;const r=i.split("");for(let s=0;s<r.length;s++){const l=nr[r[s]];if(typeof l<"u")t=l,s===r.length-1&&(e+=t);else{const c=ea[r[s]],d=c.value;n=c.secUnit,n?(e=(e+t)*d,o+=e,e=0):e+=t*d,t=0}}return o+e}function Vd(i){let o="",e="",t=0,n=!0;for(;i>0;){const r=i%10;r===0?n||(n=!0,e=Fi[r]+e):(n=!1,o=Fi[r],o+=kd[t],e=o+e),t++,i=Math.floor(i/10)}return e}function Wd(i){let o=0,e="",t="",n=!1;if(i===0)return Fi[0];for(;i>0;){const r=i%1e4;n&&(t=Fi[0]+t),e=Vd(r),e+=r!==0?$s[o]:$s[0],t=e+t,n=r<1e3&&r>0,i=Math.floor(i/1e4),o++}return t}function Ld(i){if(!i)return!1;let o=!0;if(i)if(i.length===1)i==="日"||i in nr?o=!0:o=!1;else{const e=i.split("");for(let t=0;t<e.length;t++)if(!(e[t]in nr||e[t]in ea)){o=!1;break}}return o}function zi(i){if(!i)return{isExtendNumber:!1};const o=/0|([1-9]+[0-9]*)/g,e=o.test(i);if(e){const t=i.match(o);if(t&&t.length>0){const n=t[t.length-1],r=i.lastIndexOf(n),s=i.substr(0,r),l=i.substr(r+n.length);return{isExtendNumber:!0,matchTxt:Number(n),beforeTxt:s,afterTxt:l}}return{isExtendNumber:!1}}return{isExtendNumber:e}}function Ud(i){let o;return i.length===2&&(i==="周一"||i==="周二"||i==="周三"||i==="周四"||i==="周五"||i==="周六"||i==="周日")?o=!0:o=!1,o}function Bd(i){let o;return i.length===3&&(i==="星期一"||i==="星期二"||i==="星期三"||i==="星期四"||i==="星期五"||i==="星期六"||i==="星期日")?o=!0:o=!1,o}function xd(i,o){let e=0;for(let t=0;t<i.length&&i[t]<o;t++)e++;return e}function zn(i){let o=!0;const e=i[1]-i[0];for(let t=1;t<i.length;t++)if(i[t]-i[t-1]!==e){o=!1;break}return o}function Fd(i,o,e){const t=[],n=Math.floor(o/i),r=o%i;let s=0;if(n>0){for(let l=0;l<n;l++)for(let c=0;c<e.length;c++)t[e[c]+l*i]=s,s++;for(let l=0;l<e.length&&e[l]<r;l++)t[e[l]+i*n]=s,s++}else for(let l=0;l<e.length&&e[l]<r;l++)t[e[l]]=s,s++;return t}function Rt(i,o){const e=[];for(let t=1;t<=o;t++){const n=(t-1)%i.length,r=a.Tools.deepClone(i[n]);Ot(r),e.push({v:null,s:null,p:null,f:null,si:null,t:null,...r})}return e}function zd(i,o){var t;const e=[];for(let n=1;n<=o;n++){const r=(n-1)%i.length,s={s:(t=i[r])==null?void 0:t.s};e.push(s)}return e}function Xd(i){let o=!0;const e=i[1]/i[0];for(let t=1;t<i.length;t++)if(i[t]/i[t-1]!==e){o=!1;break}return o}function Yd(i){const o=[];for(let e=1;e<=i;e++)o.push(e);return o}function Xi(i,o,e){var r,s,l,c;const t=[],n=[];for(let d=0;d<i.length;d++)n.push(Number((r=i[d])==null?void 0:r.v));if(i.length>2&&Xd(n))for(let d=1;d<=o;d++){const u=(d-1)%i.length,h=a.Tools.deepClone(i[u]);Ot(h);const S=Number((s=i[i.length-1])==null?void 0:s.v)*(Number((l=i[1])==null?void 0:l.v)/Number((c=i[0])==null?void 0:c.v))**d;h&&(oa(h)&&(h.v=S),t.push(h))}else{const d=Yd(i.length);for(let u=1;u<=o;u++){const h=(u-1)%i.length,S=a.Tools.deepClone(i[h]);Ot(S);const g=e===a.Direction.DOWN||e===a.Direction.RIGHT,f=jd(i.length+u,n,d,g);S&&(oa(S)&&(S.v=f),t.push(S))}}return t}function jd(i,o,e,t=!0){function n(h){let S=0;for(let g=0;g<h.length;g++)S+=h[g];return S/h.length}const r=n(e),s=n(o);let l=0,c=0;for(let h=0;h<e.length;h++)l+=(e[h]-r)*(o[h]-s),c+=(e[h]-r)*(e[h]-r);let d;c===0?d=t?1:-1:d=l/c;const u=s-d*r;return Math.round((u+d*i)*1e5)/1e5}function ta(i,o,e){var r;const t=[],n=/0|([1-9]+[0-9]*)/g;for(let s=1;s<=o;s++){const l=(s-1)%i.length,c=a.Tools.deepClone(i[l]);Ot(c);const d=`${(r=i[i.length-1])==null?void 0:r.v}`,u=d==null?void 0:d.match(n),h=u==null?void 0:u[u.length-1],S=Math.abs(Number(h)+e*s);if(!d||!h)continue;const g=d.lastIndexOf(h),f=d.substr(0,g)+S.toString()+d.substr(g+h.length);c&&(c.v=f,t.push(c))}return t}function an(i,o,e,t=0){var l,c;const n=[["日","一","二","三","四","五","六"],["周日","周一","周二","周三","周四","周五","周六"],["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]];if(t>=n.length)return[];const r=n[t],s=[];for(let d=1;d<=o;d++){const u=(d-1)%i.length,h=a.Tools.deepClone(i[u]);Ot(h);let S=0;if(((l=i[i.length-1])==null?void 0:l.v)===r[0])S=7+e*d;else{const f=`${(c=i[i.length-1])==null?void 0:c.v}`;if(f){const p=f.substr(f.length-1,1);S=it(p)+e*d}}S<0&&(S=Math.ceil(Math.abs(S)/7)*7+S);const g=S%7;h&&(h.v=r[g],s.push(h))}return s}function na(i,o,e){var n;const t=[];for(let r=1;r<=o;r++){const s=(r-1)%i.length,l=a.Tools.deepClone(i[s]);Ot(l);const c=`${(n=i[i.length-1])==null?void 0:n.v}`,d=it(c)+e*r;let u;d<=0?u="零":u=Wd(d),l&&(l.v=u,t.push(l))}return t}const Xn={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 Gd(i){let o=!1;return Object.keys(Xn).forEach(e=>{Xn[e].includes(i)&&(o=!0)}),o}function ir(i){let o="";const e=[];return Object.keys(Xn).forEach(t=>{Xn[t].includes(i)&&(o=t,e.push(...Xn[t]))}),{name:o,series:e}}function ia(i,o,e,t){var s;const n=t.length,r=[];for(let l=1;l<=o;l++){const c=(l-1)%i.length,d=a.Tools.deepClone(i[c]);Ot(d);const u=`${(s=i[i.length-1])==null?void 0:s.v}`;let h=t.indexOf(u)+e*l;h<0&&(h+=Math.abs(e)*n);const S=h%n;d&&(d.v=t[S],r.push(d))}return r}function Zd(i,o){const e=[];let t;if(o.startRow<i.startRow)t=a.Direction.UP;else if(o.endRow>i.endRow)t=a.Direction.DOWN;else if(o.startColumn<i.startColumn)t=a.Direction.LEFT;else if(o.endColumn>i.endColumn)t=a.Direction.RIGHT;else return[];if(t===a.Direction.DOWN||t===a.Direction.UP){const n=i.endRow-i.startRow+1,r=o.endRow-o.startRow+1,s=Math.floor(r/n),l=r%n,c={startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:i.endColumn-i.startColumn};if(t===a.Direction.DOWN){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:i.startRow+(d+1)*n,col:i.startColumn},relativeRange:c});l>0&&e.push({repeatStartCell:{row:i.startRow+(s+1)*n,col:i.startColumn},relativeRange:{startRow:0,startColumn:0,endRow:l-1,endColumn:i.endColumn-i.startColumn}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:i.startRow-(d+1)*n,col:i.startColumn},relativeRange:c});l>0&&e.push({repeatStartCell:{row:i.startRow-(s+1)*n,col:i.startColumn},relativeRange:{startRow:n-l,endRow:n-1,startColumn:0,endColumn:i.endColumn-i.startColumn}})}}if(t===a.Direction.RIGHT||t===a.Direction.LEFT){const n=i.endColumn-i.startColumn+1,r=o.endColumn-o.startColumn+1,s=Math.floor(r/n),l=r%n,c={startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:i.endColumn-i.startColumn};if(t===a.Direction.RIGHT){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:i.startRow,col:i.startColumn+(d+1)*n},relativeRange:c});l>0&&e.push({repeatStartCell:{row:i.startRow,col:i.startColumn+(s+1)*n},relativeRange:{startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:l-1}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:i.startRow,col:i.startColumn-(d+1)*n},relativeRange:c});l>0&&e.push({repeatStartCell:{row:i.startRow,col:i.startColumn-(s+1)*n},relativeRange:{startRow:0,startColumn:n-l,endRow:i.endRow-i.startRow,endColumn:n-1}})}}return e}function oa(i){return!(a.isFormulaString(i.f)||a.isFormulaId(i.si)||i.t===a.CellValueType.BOOLEAN)}function Ot(i){i&&"custom"in i&&delete i.custom}var ln=(i=>(i.Append="APPEND",i.Default="DEFAULT",i.Only="ONLY",i))(ln||{}),Ie=(i=>(i.NUMBER="number",i.DATE="date",i.EXTEND_NUMBER="extendNumber",i.CHN_NUMBER="chnNumber",i.CHN_WEEK2="chnWeek2",i.CHN_WEEK3="chnWeek3",i.LOOP_SERIES="loopSeries",i.FORMULA="formula",i.OTHER="other",i))(Ie||{}),le=(i=>(i.COPY="COPY",i.SERIES="SERIES",i.ONLY_FORMAT="ONLY_FORMAT",i.NO_FORMAT="NO_FORMAT",i))(le||{});const Kd={type:Ie.DATE,priority:1100,match:(i,o)=>{var e;if(i!=null&&i.f||i!=null&&i.si)return!1;if((typeof(i==null?void 0:i.v)=="number"||(i==null?void 0:i.t)===a.CellValueType.NUMBER)&&i.s){if(typeof i.s=="string"){const n=o.get(a.IUniverInstanceService).getFocusedUnit().getStyles().get(i.s),r=(e=n==null?void 0:n.n)==null?void 0:e.pattern;if(r)return a.numfmt.getInfo(r).isDate}else if(i.s.n&&a.numfmt.getInfo(i.s.n.pattern).isDate)return!0}return!1},isContinue:(i,o)=>i.type===Ie.DATE,applyFunctions:{[le.SERIES]:(i,o,e)=>{const{data:t}=i;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),Xi(t,o,e).reverse()):Xi(t,o,e)}}},qd={type:Ie.NUMBER,priority:1e3,match:i=>typeof(i==null?void 0:i.v)=="number"||(i==null?void 0:i.t)===a.CellValueType.NUMBER,isContinue:(i,o)=>i.type===Ie.NUMBER,applyFunctions:{[le.SERIES]:(i,o,e)=>{const{data:t}=i;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),Xi(t,o,e).reverse()):Xi(t,o,e)}}},ra={type:Ie.OTHER,priority:0,match:()=>!0,isContinue:(i,o)=>i.type===Ie.OTHER},Qd={type:Ie.EXTEND_NUMBER,priority:900,match:i=>zi(`${i==null?void 0:i.v}`||"").isExtendNumber,isContinue:(i,o)=>{var e;if(i.type===Ie.EXTEND_NUMBER){const{beforeTxt:t,afterTxt:n}=zi(`${(e=i.cellData)==null?void 0:e.v}`||""),{beforeTxt:r,afterTxt:s}=zi(`${o==null?void 0:o.v}`||"");if(t===r&&n===s)return!0}return!1},applyFunctions:{[le.SERIES]:(i,o,e)=>{var l;const{data:t}=i,n=e===a.Direction.UP||e===a.Direction.LEFT;let r;if(t.length===1)return r=n?-1:1,We(ta(t,o,r),n);const s=[];for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`;d&&s.push(Number(zi(d).matchTxt))}return n&&(t.reverse(),s.reverse()),zn(s)?(r=s[1]-s[0],We(ta(t,o,r),n)):Rt(t,o)}}},Jd={type:Ie.CHN_NUMBER,priority:830,match:i=>!!Ld(`${i==null?void 0:i.v}`||""),isContinue:(i,o)=>i.type===Ie.CHN_NUMBER,applyFunctions:{[le.SERIES]:(i,o,e)=>{var c,d,u;const{data:t}=i,n=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){const h=`${(c=t[0])==null?void 0:c.v}`;let S;return n?S=-1:S=1,h&&(h==="日"||it(h)<7)?We(an(t,o,S),n):We(na(t,o,S),n)}let r=!1;for(let h=0;h<t.length;h++)if(((d=t[h])==null?void 0:d.v)==="日"){r=!0;break}const s=[];let l=0;for(let h=0;h<t.length;h++){const S=`${(u=t[h])==null?void 0:u.v}`;S==="日"?h===0?s.push(0):(l++,s.push(l*7)):r&&it(S)>0&&it(S)<7?s.push(it(S)+l*7):s.push(it(S))}if(n&&(t.reverse(),s.reverse()),zn(s)){if(r||s[s.length-1]<6&&s[0]>0||s[0]<6&&s[s.length-1]>0){const S=s[1]-s[0];return We(an(t,o,S),n)}const h=s[1]-s[0];return We(na(t,o,h),n)}return Rt(t,o)}}},$d={type:Ie.CHN_WEEK2,priority:820,match:i=>!!Ud(`${i==null?void 0:i.v}`||""),isContinue:(i,o)=>i.type===Ie.CHN_WEEK2,applyFunctions:{[le.SERIES]:(i,o,e)=>{var l;const{data:t}=i,n=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let c;return n?c=-1:c=1,We(an(t,o,c,1),n)}const r=[];let s=0;for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`,u=d==null?void 0:d.substr(d.length-1,1);d==="周日"?c===0?r.push(0):(s++,r.push(s*7)):r.push(it(u)+s*7)}if(n&&(t.reverse(),r.reverse()),zn(r)){const c=r[1]-r[0];return We(an(t,o,c,1),n)}return Rt(t,o)}}},eu={type:Ie.CHN_WEEK3,priority:810,match:i=>Bd(`${i==null?void 0:i.v}`||""),isContinue:(i,o)=>i.type===Ie.CHN_WEEK3,applyFunctions:{[le.SERIES]:(i,o,e)=>{var l;const{data:t}=i,n=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let c;return n?c=-1:c=1,We(an(t,o,c,2),n)}const r=[];let s=0;for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`;if(d){const u=d.substr(d.length-1,1);d==="星期日"?c===0?r.push(0):(s++,r.push(s*7)):r.push(it(u)+s*7)}}if(n&&(t.reverse(),r.reverse()),zn(r)){const c=r[1]-r[0];return We(an(t,o,c,2),n)}return Rt(t,o)}}},tu={type:Ie.LOOP_SERIES,priority:800,match:i=>Gd(`${i==null?void 0:i.v}`||""),isContinue:(i,o)=>{var e;return i.type===Ie.LOOP_SERIES?ir(`${(e=i.cellData)==null?void 0:e.v}`||"").name===ir(`${o==null?void 0:o.v}`||"").name:!1},applyFunctions:{[le.SERIES]:(i,o,e)=>{var c,d;const{data:t}=i,n=e===a.Direction.LEFT||e===a.Direction.UP,{series:r}=ir(`${(c=t[0])==null?void 0:c.v}`||"");if(t.length===1){let u;return n?u=-1:u=1,We(ia(t,o,u,r),n)}const s=[];let l=0;for(let u=0;u<t.length;u++){const h=`${(d=t[u])==null?void 0:d.v}`;h&&(h===r[0]?u===0?s.push(0):(l++,s.push(l*r.length)):s.push(r.indexOf(h)+l*7))}if(n&&(t.reverse(),s.reverse()),zn(s)){const u=s[1]-s[0];return We(ia(t,o,u,r),n)}return Rt(t,o)}}};function We(i,o){return o?i.reverse():i}var nu=Object.defineProperty,iu=Object.getOwnPropertyDescriptor,ou=(i,o,e,t)=>{for(var n=t>1?void 0:t?iu(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&nu(o,e,n),n},cn=(i,o)=>(e,t)=>o(e,t,i);y.AutoFillService=class extends a.Disposable{constructor(e,t,n,r,s,l){super();T(this,"_rules",[]);T(this,"_hooks",[]);T(this,"_applyType$",new A.BehaviorSubject(le.SERIES));T(this,"_isFillingStyle",!0);T(this,"_prevUndos",[]);T(this,"_autoFillLocation$",new A.BehaviorSubject(null));T(this,"autoFillLocation$",this._autoFillLocation$.asObservable());T(this,"_showMenu$",new A.BehaviorSubject(!1));T(this,"showMenu$",this._showMenu$.asObservable());T(this,"_direction",a.Direction.DOWN);T(this,"applyType$",this._applyType$.asObservable());T(this,"_menu$",new A.BehaviorSubject([{label:"autoFill.copy",value:le.COPY,disable:!1},{label:"autoFill.series",value:le.SERIES,disable:!1},{label:"autoFill.formatOnly",value:le.ONLY_FORMAT,disable:!1},{label:"autoFill.noFormat",value:le.NO_FORMAT,disable:!1}]));T(this,"menu$",this._menu$.asObservable());this._commandService=e,this._undoRedoService=t,this._renderManagerService=n,this._univerInstanceService=r,this._selectionManagerService=s,this._injector=l,this._init()}_init(){this._rules=[Kd,qd,Qd,Jd,$d,eu,tu,ra].sort((e,t)=>t.priority-e.priority),this._isFillingStyle=!0}_getOneByPriority(e){return e.length<=0?[]:[e.reduce((n,r)=>(r.priority||0)>(n.priority||0)?r:n,e[0])]}_initPrevUndo(){this._prevUndos=[]}async triggerAutoFill(e,t,n,r){var g;if(n.startColumn===r.startColumn&&n.startRow===r.startRow&&n.endColumn===r.endColumn&&n.endRow===r.endRow)return!1;if(r.endColumn<n.endColumn&&r.endColumn>n.startColumn)return this._commandService.executeCommand(dn.id,{clearRange:{startRow:r.startRow,endRow:r.endRow,startColumn:r.endColumn+1,endColumn:n.endColumn},selectionRange:r});if(r.endRow<n.endRow&&r.endRow>n.startRow)return this._commandService.executeCommand(dn.id,{clearRange:{startRow:r.endRow+1,endRow:n.endRow,startColumn:r.startColumn,endColumn:r.endColumn},selectionRange:r});const s={startRow:r.startRow,endRow:r.endRow,startColumn:r.startColumn,endColumn:r.endColumn};let l=null;if(r.startRow<n.startRow)l=a.Direction.UP,s.endRow=n.startRow-1;else if(r.endRow>n.endRow)l=a.Direction.DOWN,s.startRow=n.endRow+1;else if(r.startColumn<n.startColumn)l=a.Direction.LEFT,s.endColumn=n.startColumn-1;else if(r.endColumn>n.endColumn)l=a.Direction.RIGHT,s.startColumn=n.endColumn+1;else return!1;this.direction=l;const c=this._injector.invoke(f=>sn(n,f)),d=this._injector.invoke(f=>sn(s,f));if(!c||!d)return!1;this.autoFillLocation={source:c,target:d,unitId:e,subUnitId:t};const u=[];this.getActiveHooks().forEach(f=>{var C;const p=(C=f==null?void 0:f.onBeforeFillData)==null?void 0:C.call(f,{source:c,target:d,unitId:e,subUnitId:t},l);p&&u.unshift(p)}),this._initPrevUndo();for(let f=0;f<u.length;f++){const p=this.menu.find(C=>C.value===u[f]);if(p&&!p.disable)return this.fillData(u[f])}const S=(g=this.menu.find(f=>f.disable===!1))==null?void 0:g.value;return S?this.fillData(S):!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=ln.Append),this._hooks.push(e),a.toDisposable(()=>{const t=this._hooks.findIndex(n=>n===e);t>-1&&this._hooks.splice(t,1)})}registerRule(e){if(this._rules.find(n=>n.type===e.type))throw new Error(`Registry rule failed, type '${e.type}' already exist!`);const t=this._rules.findIndex(n=>n.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:n,subUnitId:r}=this.autoFillLocation||{};if(!e||!t||!n||!r)return[];const s=this._hooks.filter(u=>{var h;return!((h=u.disable)!=null&&h.call(u,{source:e,target:t,unitId:n,subUnitId:r},this._direction,this.applyType))}),l=s.filter(u=>u.type===ln.Only);if(l.length>0)return this._getOneByPriority(l);const c=this._getOneByPriority(s.filter(u=>u.type===ln.Default)),d=s.filter(u=>u.type===ln.Append)||[];return[...c,...d]}get applyType(){return this._applyType$.getValue()}set applyType(e){this._applyType$.next(e)}get menu(){return this._menu$.getValue()}get direction(){return this._direction}set direction(e){this._direction=e}isFillingStyle(){return this._isFillingStyle}setFillingStyle(e){this._isFillingStyle=e}get autoFillLocation(){return this._autoFillLocation$.getValue()}set autoFillLocation(e){this._autoFillLocation$.next(e)}setDisableApplyType(e,t){this._menu$.next(this._menu$.getValue().map(n=>n.value===e?{...n,disable:t}:n))}setShowMenu(e){this._showMenu$.next(e)}fillData(e){var v,b,E;this.applyType=e;const{source:t,target:n,unitId:r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId(),subUnitId:s=(v=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:v.getSheetId()}=this.autoFillLocation||{};if(!t||!n||!r||!s)return!1;const l=this.direction;this._prevUndos.length>0&&this._prevUndos.forEach(w=>{this._commandService.syncExecuteCommand(w.id,w.params)}),this._prevUndos=[];const c=a.Rectangle.union(ft(t),ft(n)),d=this.getActiveHooks(),u=this._univerInstanceService.getUnit(r,a.UniverInstanceType.UNIVER_SHEET);this._commandService.syncExecuteCommand(m.SetSelectionsOperation.id,{selections:[{primary:{...(E=(b=this._selectionManagerService.getCurrentLastSelection())==null?void 0:b.primary)!=null?E:c},range:{...c,rangeType:a.RANGE_TYPE.NORMAL}}],unitId:r,subUnitId:s});const h=[],S=[];d.forEach(w=>{var O;const{undos:R,redos:M}=((O=w.onFillData)==null?void 0:O.call(w,{source:t,target:n,unitId:r,subUnitId:s},l,e))||{};R&&h.push(...R),M&&S.push(...M)});const g=S.every(w=>this._commandService.syncExecuteCommand(w.id,w.params)),f=[];e!==le.NO_FORMAT&&S.forEach(w=>{if(w.id===m.SetRangeValuesMutation.id){const{cellValue:R}=w.params;new a.ObjectMatrix(R).forValue((O,N,D)=>{const H=Object.keys(u.getStyles().get(D==null?void 0:D.s)||{});(D!=null&&D.p||H.length&&tr.some(k=>H.includes(k)))&&f.push({startRow:O,endRow:O,startColumn:N,endColumn:N})})}});const p=this._getAutoHeightUndoRedos(r,s,f);return p.redos.every(w=>this._commandService.syncExecuteCommand(w.id,w.params))&&(h.push(...p.undos),S.push(...p.redos)),g&&(this._prevUndos=h,this._undoRedoService.pushUndoRedo({unitID:r,undoMutations:h,redoMutations:S})),d.forEach(w=>{var R;(R=w.onAfterFillData)==null||R.call(w,{source:t,target:n,unitId:r,subUnitId:s},l,e)}),this.setShowMenu(!0),!0}_getAutoHeightUndoRedos(e,t,n){var h,S;const r=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(y.SheetSkeletonManagerService),s=(S=r==null?void 0:r.getCurrentParam())==null?void 0:S.skeleton;if(!s)return{redos:[],undos:[]};const l=s.calculateAutoHeightInRange(n),c={subUnitId:t,unitId:e,rowsAutoHeightInfo:l},d=s.worksheet,u=m.SetWorksheetRowAutoHeightMutationFactory(c,d);return{undos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:u}],redos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:c}]}}},y.AutoFillService=ou([cn(0,a.ICommandService),cn(1,a.IUndoRedoService),cn(2,P.IRenderManagerService),cn(3,a.Inject(a.IUniverInstanceService)),cn(4,a.Inject(m.SheetsSelectionsService)),cn(5,a.Inject(a.Injector))],y.AutoFillService);const pt=a.createIdentifier("univer.auto-fill-service"),Ct={type:a.CommandType.COMMAND,id:"sheet.command.auto-fill",handler:async(i,o)=>{const e=i.get(pt),t=i.get(a.IUniverInstanceService),{sourceRange:n,targetRange:r}=o,s=m.getSheetCommandTarget(t);if(!s)return!1;const{subUnitId:l,unitId:c}=s;return e.triggerAutoFill(c,l,n,r)}},dn={id:"sheet.command.auto-clear-content",type:a.CommandType.COMMAND,handler:async(i,o)=>{const e=i.get(a.IUniverInstanceService),t=i.get(a.ICommandService),n=i.get(a.IUndoRedoService),r=i.get(m.SheetInterceptorService),s=m.getSheetCommandTarget(e);if(!s)return!1;const{unitId:l,subUnitId:c}=s,{clearRange:d,selectionRange:u}=o,h={subUnitId:c,unitId:l,cellValue:m.generateNullCellValue([d])},S=m.SetRangeValuesUndoMutationFactory(i,h),{startColumn:g,startRow:f}=u,p={selections:[{primary:{startColumn:g,startRow:f,endColumn:g,endRow:f,actualRow:f,actualColumn:g,isMerged:!1,isMergedMainCell:!1},range:{...u}}],unitId:l,subUnitId:c};if(t.executeCommand(m.SetSelectionsOperation.id,p),t.syncExecuteCommand(m.SetRangeValuesMutation.id,h)){const v=r.afterCommandExecute({id:m.SetRangeValuesMutation.id,params:h});return a.sequenceExecute(v.redos,t),n.pushUndoRedo({unitID:l,undoMutations:[{id:m.SetRangeValuesMutation.id,params:S},...v.undos],redoMutations:[{id:m.SetRangeValuesMutation.id,params:h},...v.redos]}),!0}return!1}},Yn={id:"sheet.command.refill",type:a.CommandType.COMMAND,handler:async(i,o)=>i.get(pt).fillData(o.type)};var ru=Object.defineProperty,su=Object.getOwnPropertyDescriptor,au=(i,o,e,t)=>{for(var n=t>1?void 0:t?su(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&ru(o,e,n),n},At=(i,o)=>(e,t)=>o(e,t,i);y.EditorBridgeService=class extends a.Disposable{constructor(e,t,n,r,s,l,c){super();T(this,"_editorUnitId",a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);T(this,"_editorIsDirty",!1);T(this,"_isDisabled",!1);T(this,"_visible",{visible:!1,eventType:P.DeviceInputEventType.Dblclick,unitId:""});T(this,"_currentEditCell",null);T(this,"_currentEditCellState",null);T(this,"_currentEditCellLayout",null);T(this,"_currentEditCellState$",new A.BehaviorSubject(null));T(this,"currentEditCellState$",this._currentEditCellState$.asObservable());T(this,"_currentEditCellLayout$",new A.BehaviorSubject(null));T(this,"currentEditCellLayout$",this._currentEditCellLayout$.asObservable());T(this,"currentEditCell$",this._currentEditCellState$.pipe(A.switchMap(e=>this._currentEditCellLayout$.pipe(A.map(t=>e&&t?{...e,...t}:null)))));T(this,"_visible$",new A.BehaviorSubject(this._visible));T(this,"visible$",this._visible$.asObservable());T(this,"_afterVisible$",new A.BehaviorSubject(this._visible));T(this,"afterVisible$",this._afterVisible$.asObservable());T(this,"_forceKeepVisible$",new A.BehaviorSubject(!1));T(this,"forceKeepVisible$",this._forceKeepVisible$.asObservable());this._sheetInterceptorService=e,this._renderManagerService=t,this._themeService=n,this._univerInstanceService=r,this._editorService=s,this._refSelectionsService=l,this._contextService=c,this.disposeWithMe(a.toDisposable(()=>{this._currentEditCellState$.complete(),this._currentEditCell=null})),this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).subscribe(d=>{var u;d.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:n,scaleY:r,canvasOffset:s,...l}=e;this._currentEditCellState=l,this._currentEditCellLayout={position:t,scaleX:n,scaleY:r,canvasOffset:s},this._currentEditCellState$.next(this._currentEditCellState),this._currentEditCellLayout$.next(this._currentEditCellLayout)}refreshEditCellPosition(e){var M;const t=this._currentEditCell;if(t==null)return;const n=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET);if(!n)return;const r=(M=n.with(y.SheetSkeletonManagerService).getSkeletonParam(t.sheetId))==null?void 0:M.skeleton,s=n.with(Ce);if(!r||!this._currentEditCellState)return;const{primary:l,unitId:c,sheetId:d,scene:u,engine:h}=t,S=xn(r,l);if(S==null)return;const g=a.convertCellToRange(S),f=Q.getCanvasOffsetByEngine(h);let{startX:p,startY:C,endX:v,endY:b}=g;const{scaleX:E,scaleY:w}=u.getAncestorScale(),R=u.getViewportScrollXY(s.getViewPort());p=P.convertTransformToOffsetX(p,E,R),C=P.convertTransformToOffsetY(C,w,R),v=P.convertTransformToOffsetX(v,E,R),b=P.convertTransformToOffsetY(b,w,R),e&&this._currentEditCellLayout&&(v=v-p+this._currentEditCellLayout.position.startX,b=b-C+this._currentEditCellLayout.position.startY,p=this._currentEditCellLayout.position.startX,C=this._currentEditCellLayout.position.startY),this._currentEditCellLayout={position:{startX:p,startY:C,endX:v,endY:b},canvasOffset:f,scaleX:E,scaleY:w},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:n,canvasOffset:r,scaleX:s,scaleY:l,...c}=t;this._currentEditCellState=c,this._currentEditCellLayout={position:n,canvasOffset:r,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}updateEditLocation(e,t){this._currentEditCellState&&(this._currentEditCellState={...this._currentEditCellState,row:e,column:t})}getLatestEditCellState(){var U,W,B;const e=this._currentEditCell;if(e==null)return;const t=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET);if(!t)return;const n=t.with(y.SheetSkeletonManagerService).getCurrentSkeleton(),r=t.with(Ce);if(!n)return;const{primary:s,unitId:l,sheetId:c,scene:d,engine:u}=e,{startRow:h,startColumn:S}=s,g=xn(n,s);if(g==null)return;const f=a.convertCellToRange(g),p=Q.getCanvasOffsetByEngine(u);let{startX:C,startY:v,endX:b,endY:E}=f;const{scaleX:w,scaleY:R}=d.getAncestorScale(),M=d.getViewportScrollXY(r.getViewPort());C=P.convertTransformToOffsetX(C,w,M),v=P.convertTransformToOffsetY(v,R,M),b=P.convertTransformToOffsetX(b,w,M),E=P.convertTransformToOffsetY(E,R,M);const O=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),N=O.getActiveSheet();if(!N)return;const D={workbook:O,worksheet:N,unitId:O.getUnitId(),subUnitId:N.getSheetId(),row:h,col:S,origin:N.getCellRaw(h,S)};let H;const k=this._sheetInterceptorService.writeCellInterceptor.fetchThroughInterceptors(m.BEFORE_CELL_EDIT)(N.getCell(h,S),D);H=k&&n.getCellDocumentModelWithFormula(k);const V=(U=H==null?void 0:H.documentModel)==null?void 0:U.documentStyle.renderConfig;if(V!=null&&(V.cellValueType=a.CellValueType.STRING),!H||H.documentModel==null){const F=n.getBlankCellDocumentModel(k);if(H!=null){const{verticalAlign:z,horizontalAlign:x,wrapStrategy:X,textRotation:Y,fill:J}=H,{centerAngle:ie,vertexAngle:$}=P.convertTextRotation(Y);F.documentModel.documentStyle.renderConfig={...V,verticalAlign:z,horizontalAlign:x,wrapStrategy:X,background:{rgb:J},centerAngle:ie,vertexAngle:$}}H=F}if(H.fill=H.fill||"#fff",(W=H.documentModel)==null||W.setZoomRatio(Math.max(w,R)),(k==null?void 0:k.isInArrayFormulaRange)===!0){const F=(B=H.documentModel)==null?void 0:B.getBody();F&&(F.textRuns=[{st:0,ed:F.dataStream.length-2,ts:{cl:{rgb:this._themeService.getCurrentTheme().textColorSecondary}}}])}return{position:{startX:C,startY:v,endX:b,endY:E},scaleX:w,scaleY:R,canvasOffset:p,row:h,column:S,unitId:l,sheetId:c,documentLayoutObject:H,editorUnitId:this._editorUnitId,isInArrayFormulaRange:k==null?void 0:k.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}},y.EditorBridgeService=au([At(0,a.Inject(m.SheetInterceptorService)),At(1,P.IRenderManagerService),At(2,a.Inject(a.ThemeService)),At(3,a.IUniverInstanceService),At(4,Q.IEditorService),At(5,m.IRefSelectionsService),At(6,a.IContextService)],y.EditorBridgeService);const ge=a.createIdentifier("univer.sheet-editor-bridge.service"),ve={id:"sheet.operation.set-cell-edit-visible",type:a.CommandType.OPERATION,handler:(i,o)=>o?(i.get(ge).changeVisible(o),!0):!1},jn={id:"sheet.operation.set-cell-edit-visible-f2",type:a.CommandType.OPERATION,handler:(i,o)=>{const e=i.get(a.ICommandService),n=i.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);return n?(e.syncExecuteCommand(ve.id,{...o,unitId:n.getUnitId()}),!0):!1}},Nt={id:"sheet.operation.set-cell-edit-visible-arrow",type:a.CommandType.OPERATION,handler:()=>!0},un={id:"sheet.command.change-zoom-ratio",type:a.CommandType.COMMAND,handler:(i,o)=>{if(!o)return!1;const e=i.get(a.IUniverInstanceService),t=m.getSheetCommandTarget(e);if(!t)return!1;const{worksheet:n,subUnitId:r,unitId:s}=t,{delta:l,reset:c}=o;let d=c?100:Math.round((n.getConfig().zoomRatio+l)*100);d=Math.max(jo[0],d),d=Math.min(jo[1],d);const u=d/100,S=i.get(ge).isVisible();return(S.unitId===s||S.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&S.visible?!1:i.get(a.ICommandService).executeCommand(Le.id,{unitId:s,subUnitId:r,zoomRatio:u})}},hn={id:"sheet.command.set-zoom-ratio",type:a.CommandType.COMMAND,handler:(i,o)=>{if(!o)return!1;const{unitId:e,subUnitId:t,zoomRatio:n}=o,s=i.get(ge).isVisible();return(s.unitId===e||s.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&s.visible?!1:i.get(a.ICommandService).executeCommand(Le.id,{unitId:e,subUnitId:t,zoomRatio:n})}};function lu(i){return typeof i.isMainScene>"u"}function ze(i,o){const e=i instanceof a.Workbook?i:i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!e)return null;const t=e.getUnitId();let n,r,s,l;if(lu(o)){const S=o.getRenderById(t);if(S==null)return null;n=S.components,n=S.components,r=S.mainComponent,s=S.scene,l=S.engine}else n=o.components,r=o.mainComponent,s=o.scene,l=o.engine;if(!n||!r)return null;const c=r,d=n.get(he.ROW),u=n.get(he.COLUMN),h=n.get(he.LEFT_TOP);return{spreadsheet:c,spreadsheetRowHeader:d,spreadsheetColumnHeader:u,spreadsheetLeftTopPlaceholder:h,scene:s,engine:l}}function or(i,o,e,t){const{startX:n,startY:r,endX:s,endY:l}=t.getCellWithCoordByIndex(i,o);return{startX:n,startY:r,endX:s,endY:l}}function Ke(i,o,e,t,n,r){const s=e.getCoordRelativeToViewport(P.Vector2.FromArray([i,o])),{x:l,y:c}=s,d=e.getScrollXYInfoByViewport(s,n),{scaleX:u,scaleY:h}=e.getAncestorScale(),S=t.getCellIndexByOffset(l,c,u,h,d,{closeFirst:r}),{row:g,column:f}=S,p=t.getNoMergeCellWithCoordByIndex(g,f),{startX:C,startY:v,endX:b,endY:E}=p;return{startX:C,startY:v,endX:b,endY:E,row:g,column:f}}function Gn(i,o,e,t){const n=e.getCoordRelativeToViewport(P.Vector2.FromArray([i,o])),r=e.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN),s=e.getScrollXYInfoByViewport(n,r),{scaleX:l,scaleY:c}=e.getAncestorScale(),{x:d,y:u}=s,h=i/l+d,S=o/c+u;return{x:h,y:S}}var cu=Object.defineProperty,du=Object.getOwnPropertyDescriptor,uu=(i,o,e,t)=>{for(var n=t>1?void 0:t?du(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&cu(o,e,n),n},Yi=(i,o)=>(e,t)=>o(e,t,i);let Zn=class extends a.Disposable{constructor(o,e,t,n,r){super();T(this,"_zoom");this._context=o,this._sheetSkeletonManagerService=e,this._commandService=t,this._contextService=n,this._editorBridgeService=r,this._initSkeletonListener(),this._initZoomEventListener()}updateZoom(o,e){const t=this._context.unit.getSheetBySheetId(o);return t?(t.getConfig().zoomRatio=e,t===this._context.unit.getActiveSheet()&&this._updateViewZoom(e),!0):!1}_initZoomEventListener(){const o=this._getSheetObject().scene;this.disposeWithMe(o.onMouseWheel$.subscribeEvent(e=>{if(!e.ctrlKey||!this._contextService.getContextValue(a.FOCUSING_SHEET))return;if(this._editorBridgeService){const d=this._editorBridgeService.isVisible();if((d.unitId===this._context.unitId||d.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&d.visible)return}const t=Math.abs(e.deltaX);let n=t<40?.2:t<80?.4:.2;n*=e.deltaY>0?-1:1,o.scaleX<1&&(n/=2);const r=this._context.unit,s=r.getActiveSheet();if(!s)return;const l=s.getZoomRatio();let c=+Number.parseFloat(`${l+n}`).toFixed(1);c=c>=4?4:c<=.1?.1:c,this._commandService.executeCommand(hn.id,{zoomRatio:Math.round(c*10)/10,unitId:r.getUnitId(),subUnitId:s.getSheetId()}),e.preventDefault()}))}_initSkeletonListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(o=>{if(o==null)return;const t=this._context.unit.getActiveSheet();if(!t)return;const n=t.getZoomRatio()||1;this._zoom!==n&&this._updateViewZoom(n),this._zoom=n}))}_updateViewZoom(o){const e=this._getSheetObject();e==null||e.scene.scale(o,o),e==null||e.spreadsheet.makeForceDirty()}_getSheetObject(){return ze(this._context.unit,this._context)}};Zn=uu([Yi(1,a.Inject(y.SheetSkeletonManagerService)),Yi(2,a.ICommandService),Yi(3,a.IContextService),Yi(4,a.Optional(ge))],Zn);const Le={id:"sheet.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(i,o)=>{const t=i.get(P.IRenderManagerService).getRenderById(o.unitId);return t?t.with(Zn).updateZoom(o.subUnitId,o.zoomRatio):!1}};var hu=Object.defineProperty,mu=Object.getOwnPropertyDescriptor,Su=(i,o,e,t)=>{for(var n=t>1?void 0:t?mu(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&hu(o,e,n),n},rr=(i,o)=>(e,t)=>o(e,t,i);const sa="univer-sheet-main-canvas";y.SheetsRenderService=class extends a.RxDisposable{constructor(e,t,n){super();T(this,"_skeletonChangeMutations",new Set);this._contextService=e,this._instanceSrv=t,this._renderManagerService=n,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(A.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(A.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(n=>{n.unitId===t&&(n.engine.getCanvas().setId(`${sa}_${t}`),n.engine.getCanvas().getContext().setId(`${sa}_${t}`))}),this._renderManagerService.createRender(t)}_disposeRenderer(e){const t=e.getUnitId();this._renderManagerService.removeRender(t)}_initContextListener(){this.disposeWithMe(this._contextService.subscribeContextValue$(P.RENDER_RAW_FORMULA_KEY).pipe(A.distinctUntilChanged()).subscribe(()=>{this._renderManagerService.getRenderAll().forEach(e=>{e.mainComponent instanceof P.Spreadsheet&&e.mainComponent.makeForceDirty(!0)})}))}},y.SheetsRenderService=Su([rr(0,a.IContextService),rr(1,a.IUniverInstanceService),rr(2,P.IRenderManagerService)],y.SheetsRenderService);var gu=Object.defineProperty,fu=Object.getOwnPropertyDescriptor,pu=(i,o,e,t)=>{for(var n=t>1?void 0:t?fu(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&gu(o,e,n),n},Dt=(i,o)=>(e,t)=>o(e,t,i);y.AutoFillController=class extends a.Disposable{constructor(e,t,n,r,s,l,c){super();T(this,"_beforeApplyData",[]);T(this,"_currentLocation",null);T(this,"_copyData",[]);T(this,"_defaultHook");this._univerInstanceService=e,this._commandService=t,this._autoFillService=n,this._editorBridgeService=r,this._renderManagerService=s,this._injector=l,this._sheetsRenderService=c,this._defaultHook={id:"default",type:ln.Default,priority:0,onBeforeFillData:(d,u)=>this._presetAndCacheData(d,u),onFillData:(d,u,h)=>this._fillData(d,u,h)},this._init()}_init(){this._initDefaultHook(),this._initSelectionControlFillChanged(),this._initQuitListener(),this._initSkeletonChange()}_initSkeletonChange(){this.disposeWithMe(this._sheetsRenderService.registerSkeletonChangingMutations(Ct.id))}_initDefaultHook(){this.disposeWithMe(this._autoFillService.addHook(this._defaultHook))}_initQuitListener(){const e=[ve.id,dn.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,n)=>{var c,d;const r=n==null?void 0:n.fromCollab,s=n==null?void 0:n.fromSync,l=n==null?void 0:n.fromFormula;e.includes(t.id)&&!r&&!s&&!l&&t.params.trigger!==Ct.id&&t.params.trigger!==Yn.id&&this._quit(),t.id===m.RemoveSheetMutation.id&&t.params.unitId===((c=this._currentLocation)==null?void 0:c.unitId)&&t.params.subUnitId===((d=this._currentLocation)==null?void 0:d.subUnitId)&&this._quit()})),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{var n;t.getUnitId()===((n=this._currentLocation)==null?void 0:n.unitId)&&this._quit()}))}_quit(){this._currentLocation=null,this._beforeApplyData=[],this._copyData=[],this._autoFillService.setShowMenu(!1)}_initSelectionControlFillChanged(){const e=new a.DisposableCollection,t=()=>{e.dispose();const n=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET);if(!n)return;n.with(Ce).getSelectionControls().forEach(l=>{e.add(l.selectionFilled$.subscribe(c=>{if(c==null||c.startColumn===-1||c.startRow===-1||c.endColumn===-1||c.endRow===-1)return;const d={startColumn:l.model.startColumn,endColumn:l.model.endColumn,startRow:l.model.startRow,endRow:l.model.endRow},u={startColumn:c.startColumn,endColumn:c.endColumn,startRow:c.startRow,endRow:c.endRow};this._commandService.executeCommand(Ct.id,{sourceRange:d,targetRange:u})})),e.add(l.fillControl.onDblclick$.subscribeEvent(()=>{const c={startColumn:l.model.startColumn,endColumn:l.model.endColumn,startRow:l.model.startRow,endRow:l.model.endRow};this._handleDbClickFill(c)})),e.add(l.fillControl.onPointerDown$.subscribeEvent(()=>{this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(ve.id,{visible:!1,eventType:P.DeviceInputEventType.PointerDown,unitId:n.unitId})}))})};t(),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{n.id===m.SetSelectionsOperation.id&&t()})),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(()=>t()))}_handleDbClickFill(e){const t=this._detectFillRange(e);t.endRow<=e.endRow||this._commandService.executeCommand(Ct.id,{sourceRange:e,targetRange:t})}_detectFillRange(e){var S,g,f,p,C,v;const{startRow:t,endRow:n,startColumn:r,endColumn:s}=e,l=(S=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET))==null?void 0:S.getActiveSheet();if(!l)return e;const c=l.getCellMatrix(),d=l.getMaxRows()-1,u=l.getMaxColumns()-1;let h=n;if(r>0&&((g=c.getValue(t,r-1))==null?void 0:g.v)!=null){let b=t;for(;((f=c.getValue(b,r-1))==null?void 0:f.v)!=null&&b<d;)b+=1;h=b-1}else if(s<u&&((p=c.getValue(n,s+1))==null?void 0:p.v)!=null){let b=t;for(;((C=c.getValue(b,s+1))==null?void 0:C.v)!=null&&b<d;)b+=1;h=b-1}for(let b=n+1;b<=h;b++)for(let E=r;E<=s;E++)if(((v=c.getValue(b,E))==null?void 0:v.v)!=null){h=b-1;break}return{startColumn:r,endColumn:s,startRow:t,endRow:h}}_getApplyData(e,t,n,r,s,l=!0){const c=[],d=Math.floor(n/t),u=n%t,h=this._autoFillService.getRules();if(!l&&s===le.ONLY_FORMAT)return console.error("ERROR: only format can not be applied when hasStyle is false"),[];const S={};h.forEach(g=>{S[g.type]=[]}),h.forEach(g=>{const{type:f,applyFunctions:p={}}=g,C=e[f];C&&C.forEach(v=>{const b=xd(v.index,u),E=v.index.length*d+b,w=this._applyFunctions(v,E,r,s,p,e),R=Fd(t,n,v.index);S[f].push({data:w,index:R})})});for(let g=0;g<n;g++)h.forEach(f=>{const{type:p}=f,C=S[p];for(let v=0;v<C.length;v++)g in C[v].index&&c.push(C[v].data[C[v].index[g]])});return c}_applyFunctions(e,t,n,r,s,l){const{data:c}=e,d=n===a.Direction.UP||n===a.Direction.LEFT;if(r===le.COPY){const u=s==null?void 0:s[le.COPY];return u?u(e,t,n,l):(d&&c.reverse(),Rt(c,t))}if(r===le.SERIES){const u=s==null?void 0:s[le.SERIES];return u?u(e,t,n,l):(d&&c.reverse(),s!=null&&s[le.COPY]?s[le.COPY](e,t,n,l):Rt(c,t))}if(r===le.ONLY_FORMAT){const u=s==null?void 0:s[le.ONLY_FORMAT];return u?u(e,t,n,l):zd(c,t)}}_getCopyData(e,t){const n=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!n)throw new Error("No active sheet found");const r=n.getCellMatrix(),s=this._autoFillService.getRules(),l=[],c=t===a.Direction.DOWN||t===a.Direction.UP;let d,u;return c?(d=e.cols,u=e.rows):(d=e.rows,u=e.cols),d.forEach(h=>{const S=this._getEmptyCopyDataPiece(),g={type:void 0,cellData:void 0};u.forEach(f=>{let p;c?p=r.getValue(f,h):p=r.getValue(h,f);const{type:C,isContinue:v}=s.find(b=>b.match(p,this._injector))||ra;if(v(g,p)){const b=S[C],E=b[b.length-1];E.data.push(p),E.index.push(f-u[0])}else{const b=S[C];b?b.push({data:[p],index:[f-u[0]]}):S[C]=[{data:[p],index:[f-u[0]]}]}g.type=C,g.cellData=p}),l.push(S)}),l}_getEmptyCopyDataPiece(){const e={};return this._autoFillService.getRules().forEach(t=>{e[t.type]=[]}),e}_getMergeApplyData(e,t,n,r){const s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!s)throw new Error("No active sheet found");const l=[];for(let c=e.startRow;c<=e.endRow;c++)for(let d=e.startColumn;d<=e.endColumn;d++){const{isMergedMainCell:u,startRow:h,startColumn:S,endRow:g,endColumn:f}=s.getCellInfoInMergeData(c,d);if(u){if(n===a.Direction.DOWN){let p=h+r,C=g+r;for(;C<=t.endRow;)l.push({startRow:p,startColumn:S,endRow:C,endColumn:f}),p+=r,C+=r}else if(n===a.Direction.UP){let p=h-r,C=g-r;for(;p>=t.startRow;)l.push({startRow:p,startColumn:S,endRow:C,endColumn:f}),p-=r,C-=r}else if(n===a.Direction.RIGHT){let p=S+r,C=f+r;for(;C<=t.endColumn;)l.push({startRow:h,startColumn:p,endRow:g,endColumn:C}),p+=r,C+=r}else if(n===a.Direction.LEFT){let p=S-r,C=f-r;for(;p>=t.startColumn;)l.push({startRow:h,startColumn:p,endRow:g,endColumn:C}),p-=r,C-=r}}}return l}_presetAndCacheData(e,t){const{source:n,target:r}=e,s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!s)throw new Error("No active sheet found");const l=s.getCellMatrix(),c=[];return r.rows.forEach(d=>{const u=[];r.cols.forEach(h=>{u.push(a.Tools.deepClone(l.getValue(d,h)))}),c.push(u)}),this._beforeApplyData=c,this._copyData=this._getCopyData(n,t),this._currentLocation=e,this._shouldDisableSeries(this._copyData)?(this._autoFillService.setDisableApplyType(le.SERIES,!0),le.COPY):(this._autoFillService.setDisableApplyType(le.SERIES,!1),this._getPreferredApplyType(this._copyData))}_fillData(e,t,n){var U,W;const r=[],s=[];let l=!0;n===le.NO_FORMAT&&(l=!1,n=le.SERIES);const{source:c,target:d,unitId:u,subUnitId:h}=e;if(!c||!d||t==null)return{undos:r,redos:s};const S=ft(c),g=ft(d),{cols:f,rows:p}=d,{cols:C,rows:v}=c,b=this._copyData;let E;t===a.Direction.DOWN||t===a.Direction.UP?E=v.length:E=C.length;const w=[];if(t===a.Direction.DOWN||t===a.Direction.UP){const B=p.length,F=[];f.forEach((z,x)=>{const X=b[x],Y=this._getApplyData(X,E,B,t,n,l);F.push(Y)});for(let z=0;z<F[0].length;z++){const x=[];for(let X=0;X<F.length;X++)x.push({s:null,...F[X][z]});w.push(x)}}else{const B=f.length;p.forEach((F,z)=>{const x=b[z],X=this._getApplyData(x,E,B,t,n,l),Y=[];for(let J=0;J<X.length;J++)Y.push({s:null,...X[J]});w.push(Y)})}let R=[];const M=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getStyles();if(l?(R=this._getMergeApplyData(S,g,t,E),w.forEach(B=>{B.forEach(F=>{F&&M&&M&&(F.s=M.getStyleByCell(F))})})):w.forEach((B,F)=>{B.forEach((z,x)=>{z&&M&&(z.s=M.getStyleByCell(this._beforeApplyData[F][x])||null)})}),n===le.ONLY_FORMAT&&w.forEach((B,F)=>{B.forEach((z,x)=>{if(z){const X=this._beforeApplyData[F][x]||{};z.f=X.f,z.si=X.si,z.t=X.t,z.v=X.v}})}),l){const B=[],F=(W=(U=this._univerInstanceService.getUniverSheetInstance(u))==null?void 0:U.getSheetBySheetId(h))==null?void 0:W.getMergeData();F&&F.forEach(X=>{a.Rectangle.intersects(X,g)&&B.push(X)});const z={unitId:u,subUnitId:h,ranges:B},x=this._injector.invoke(m.RemoveMergeUndoMutationFactory,z);B.length&&(s.push({id:m.RemoveWorksheetMergeMutation.id,params:z}),r.unshift({id:m.AddWorksheetMergeMutation.id,params:x}))}const O={subUnitId:h,unitId:u,cellValue:Hd([d])},N=this._injector.invoke(m.SetRangeValuesUndoMutationFactory,O);s.push({id:m.SetRangeValuesMutation.id,params:O}),r.unshift({id:m.SetRangeValuesMutation.id,params:N});const D=new a.ObjectMatrix;p.forEach((B,F)=>{f.forEach((z,x)=>{w[F][x]&&D.setValue(B,z,w[F][x])})});const H=D.getMatrix(),k={subUnitId:h,unitId:u,cellValue:H},V=this._injector.invoke(m.SetRangeValuesUndoMutationFactory,k);if(this._autoFillService.getActiveHooks().forEach(B=>{var F;(F=B.onBeforeSubmit)==null||F.call(B,e,t,n,H)}),r.unshift({id:m.SetRangeValuesMutation.id,params:V}),s.push({id:m.SetRangeValuesMutation.id,params:k}),R!=null&&R.length){const B=m.getAddMergeMutationRangeByType(R),F={unitId:u,subUnitId:h,ranges:B},z=this._injector.invoke(m.AddMergeUndoMutationFactory,F);r.unshift({id:m.RemoveWorksheetMergeMutation.id,params:z}),s.push({id:m.AddWorksheetMergeMutation.id,params:F})}return{undos:r,redos:s}}_shouldDisableSeries(e){return e.every(t=>Object.keys(t).every(n=>{var r;return((r=t[n])==null?void 0:r.length)===0||[Ie.OTHER,Ie.FORMULA].includes(n)}))}_getPreferredApplyType(e){return e.every(n=>Object.keys(n).every(r=>{var s,l;return((s=n[r])==null?void 0:s.length)===0||((l=n[r])==null?void 0:l.length)===1&&n[r][0].data.length===1&&Ie.NUMBER===r}))?le.COPY:le.SERIES}},y.AutoFillController=pu([Dt(0,a.IUniverInstanceService),Dt(1,a.ICommandService),Dt(2,pt),Dt(3,ge),Dt(4,P.IRenderManagerService),Dt(5,a.Inject(a.Injector)),Dt(6,a.Inject(y.SheetsRenderService))],y.AutoFillController);var Cu=Object.defineProperty,vu=Object.getOwnPropertyDescriptor,_u=(i,o,e,t)=>{for(var n=t>1?void 0:t?vu(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&Cu(o,e,n),n},sr=(i,o)=>(e,t)=>o(e,t,i);y.CellCustomRenderController=class extends a.Disposable{constructor(e,t,n,r){super();T(this,"_enterActiveRender");this._context=e,this._sheetSkeletonManagerService=t,this._renderManagerService=n,this._permissionService=r,this._initEventBinding()}_initEventBinding(){const e=new a.DisposableCollection,t=this._context.unit,n=r=>{if(e.dispose(),!r)return;const s=this._context.unitId,{skeleton:l}=r,c=this._renderManagerService.getRenderById(s);if(c&&c.mainComponent){const d=c.mainComponent,u=g=>{const{offsetX:f,offsetY:p}=g,C=c.scene,v=t.getActiveSheet();if(!v)return;const b=C.getActiveViewportByCoord(P.Vector2.FromArray([f,p]));if(!b)return;const{scaleX:E,scaleY:w}=C.getAncestorScale(),R={x:b.viewportScrollX,y:b.viewportScrollY},M=l.getCellIndexByOffset(f,p,E,w,R),O=l.worksheet.getMergedCell(M.row,M.column),N={actualRow:O?O.startRow:M.row,actualCol:O?O.startColumn:M.column,mergeCell:O,row:M.row,col:M.column};if(!N||!l)return;const D=v.getCell(N.actualRow,N.actualCol);if(!D)return;const H=D.customRender;if(!(H!=null&&H.length))return;const k=N.actualRow,V=N.actualCol,U=H.sort(a.sortRules),W=v.getSheetId(),B={data:D,style:l.getStyles().getStyleByCell(D),primaryWithCoord:l.getCellWithCoordByIndex(N.actualRow,N.actualCol),unitId:s,subUnitId:W,row:k,col:V,workbook:t,worksheet:v},F={x:R.x+f/E,y:R.y+p/w},z=U.find(x=>{var X;return(X=x.isHit)==null?void 0:X.call(x,F,B)});if(z)return[z,B]},h=d.onPointerDown$.subscribeEvent(g=>{var p,C,v,b;const f=u(g);if(f){const[E,w]=f,{row:R,col:M,worksheet:O,unitId:N,subUnitId:D}=w;if(!((p=this._permissionService.composePermission([new m.WorkbookEditablePermission(N).id,new m.WorksheetEditPermission(N,D).id]))==null?void 0:p.every(V=>V.value)))return!1;const k=(v=(C=O.getCell(R,M))==null?void 0:C.selectionProtection)==null?void 0:v[0];if((k==null?void 0:k[m.UnitAction.Edit])===!1)return!1;(b=E.onPointerDown)==null||b.call(E,w,g)}}),S=a.fromEventSubject(d.onPointerMove$).pipe(A.throttleTime(30)).subscribe(g=>{var p,C,v,b,E,w;const f=u(g);if(f){const[R,M]=f;this._enterActiveRender?this._enterActiveRender.render!==R&&((C=(p=this._enterActiveRender.render).onPointerLeave)==null||C.call(p,this._enterActiveRender.cellContext,g),this._enterActiveRender={render:R,cellContext:M},(v=R.onPointerEnter)==null||v.call(R,M,g)):(this._enterActiveRender={render:R,cellContext:M},(b=R.onPointerEnter)==null||b.call(R,M,g))}else this._enterActiveRender&&((w=(E=this._enterActiveRender.render).onPointerLeave)==null||w.call(E,this._enterActiveRender.cellContext,g),this._enterActiveRender=null)});h&&e.add(h),S&&e.add(S)}};this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(n)),n(this._sheetSkeletonManagerService.getCurrentParam()),this.disposeWithMe(e)}},y.CellCustomRenderController=_u([sr(1,a.Inject(y.SheetSkeletonManagerService)),sr(2,P.IRenderManagerService),sr(3,a.IPermissionService)],y.CellCustomRenderController);class ar extends a.Disposable{constructor(){super(...arguments);T(this,"rangesStack",[]);T(this,"selectedRangeWorksheet","")}}var Iu=Object.defineProperty,bu=Object.getOwnPropertyDescriptor,Eu=(i,o,e,t)=>{for(var n=t>1?void 0:t?bu(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&Iu(o,e,n),n},aa=(i,o)=>(e,t)=>o(e,t,i);let mn=class{constructor(i,o){T(this,"_current",null);T(this,"_shortcutParam",[]);this._univerInstanceService=i,this._localeService=o}dispose(){this._shortcutParam=[]}getCurrentBySearch(i){return this._getCurrentBySearch(i)}getCurrent(){return this._getCurrentBySearch(this._current)}addOrUpdate(i){const o=this._getCurrentBySearch({unitId:i.unitId,sheetId:i.sheetId,keycode:i.keycode});if(o!=null){const e=this._shortcutParam.indexOf(o);this._shortcutParam.splice(e,1)}return this._shortcutParam.push(i),o}remove(i){if(i==null)return;const o=this._getCurrentBySearch(i);if(o==null)return;const e=this._shortcutParam.indexOf(o);return this._shortcutParam.splice(e,1)[0]}_getCurrentBySearch(i){return i==null?void 0:this._shortcutParam.find(e=>e.unitId===i.unitId&&e.sheetId===i.sheetId&&e.keycode===i.keycode)}};mn=Eu([aa(0,a.IUniverInstanceService),aa(1,a.Inject(a.LocaleService))],mn);var ji=(i=>(i.MergeAll="mergeAll",i.MergeVertical="mergeVertical",i.MergeHorizontal="mergeHorizontal",i))(ji||{});function vt(i,o,e,t,n=!0,r=1,s=!0){let l={...i};t==null&&(t={startRow:0,endRow:e.getRowCount()-1,startColumn:0,endColumn:e.getColumnCount()-1});let c;switch(o){case a.Direction.UP:for(c=i.startRow-r;c>-1&&!e.getRowVisible(c);)c-=1;c>=t.startRow?(l.startRow=c,l.endRow=c):s&&(l.startRow=t.endRow,l.endRow=t.endRow,n&&(l=vt(l,a.Direction.LEFT,e,t,!1)));break;case a.Direction.DOWN:for(c=i.endRow+r;c<e.getRowCount()&&!e.getRowVisible(c);)c+=1;c<=t.endRow?(l.startRow=c,l.endRow=c):s&&(l.startRow=t.startRow,l.endRow=t.startRow,n&&(l=vt(l,a.Direction.RIGHT,e,t,!1)));break;case a.Direction.LEFT:for(c=i.startColumn-r;c>-1&&!e.getColVisible(c);)c-=1;c>=t.startColumn?(l.startColumn=c,l.endColumn=c):s&&(l.startColumn=t.endColumn,l.endColumn=t.endColumn,n&&(l=vt(l,a.Direction.UP,e,t,!1)));break;case a.Direction.RIGHT:for(c=i.endColumn+r;c<e.getColumnCount()&&!e.getColVisible(c);)c+=1;c<=t.endColumn?(l.startColumn=c,l.endColumn=c):s&&(l.startColumn=t.startColumn,l.endColumn=t.startColumn,n&&(l=vt(l,a.Direction.DOWN,e,t,!1)));break}return l}function lr(i,o,e){const t={...i},{startRow:n,startColumn:r,endRow:s,endColumn:l}=Kn(i,o,e);let c=qn(e,n,r,s,l).hasValue,d=!0,u=!0;for(;u;){if(a.Direction.UP===o){let h=t.startRow-1;for(;h>-1&&!e.getRowVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:S,matrix:g}=qn(e,h,t.startColumn,h,t.endColumn);if(c&&!S&&!d){u=!1;break}else{if(g.getLength()!==0){let f=h;g.forValue(p=>{f=Math.min(p,f)}),t.startRow=f}else t.startRow=h;if(t.endRow=t.startRow,!c&&S){u=!1;break}c=S,d=!1}}if(a.Direction.DOWN===o){let h=t.endRow+1;for(;h<e.getRowCount()&&!e.getRowVisible(h);)h+=1;if(h===e.getRowCount()){u=!1;break}const{hasValue:S,matrix:g}=qn(e,h,t.startColumn,h,t.endColumn);if(c&&!S&&!d){u=!1;break}else{if(g.getLength()!==0){let f=h;g.forValue((p,C,v)=>{f=Math.max(p+(v.rowSpan||1)-1,f)}),t.endRow=f}else t.endRow=h;if(t.startRow=t.endRow,!c&&S){u=!1;break}c=S,d=!1}}if(a.Direction.LEFT===o){let h=t.startColumn-1;for(;h>-1&&!e.getColVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:S,matrix:g}=qn(e,t.startRow,h,t.endRow,h);if(c&&!S&&!d){u=!1;break}else{if(g.getLength()!==0){let f=h;g.forValue((p,C)=>{f=Math.min(C,f)}),t.startColumn=f}else t.startColumn=h;if(t.endColumn=t.startColumn,!c&&S){u=!1;break}c=S,d=!1}}if(a.Direction.RIGHT===o){let h=t.endColumn+1;for(;h<e.getColumnCount()&&!e.getColVisible(h);)h+=1;if(h===e.getColumnCount()){u=!1;break}const{hasValue:S,matrix:g}=qn(e,t.startRow,h,t.endRow,h);if(c&&!S&&!d){u=!1;break}else{if(g.getLength()!==0){let f=h;g.forValue((p,C,v)=>{f=Math.max(C+(v.colSpan||1)-1,f)}),t.endColumn=f}else t.endColumn=h;if(t.startColumn=t.endColumn,!c&&S){u=!1;break}c=S,d=!1}}}return m.alignToMergedCellsBorders(t,e,!0)}function la(i,o,e){return vt(i,o,e,void 0,!1,1,!1)}function Tu(i,o,e){const t=lr(i,o,e);return m.alignToMergedCellsBorders(a.Rectangle.union(t,i),e,!0)}function wu(i,o,e){const t=la(i,o,e),n={startRow:Math.min(i.startRow,t.startRow),startColumn:Math.min(i.startColumn,t.startColumn),endRow:Math.max(i.endRow,t.endRow),endColumn:Math.max(i.endColumn,t.endColumn)};return m.alignToMergedCellsBorders(a.Rectangle.union(i,n),e)}function yu(i,o,e,t){const n=a.getReverseDirection(e),r=lr(Kn(i,n,t),e,t);return e===a.Direction.UP&&r.startRow<=i.startRow?m.alignToMergedCellsBorders({...o,startColumn:i.startColumn,endColumn:i.endColumn},t,!0):e===a.Direction.DOWN&&r.endRow>=i.endRow?m.alignToMergedCellsBorders({...o,startColumn:i.startColumn,endColumn:i.endColumn},t,!0):e===a.Direction.LEFT&&r.startColumn<=i.startColumn?m.alignToMergedCellsBorders({...o,startRow:i.startRow,endRow:i.endRow},t,!0):e===a.Direction.RIGHT&&r.endColumn>=i.endColumn?m.alignToMergedCellsBorders({...o,startRow:i.startRow,endRow:i.endRow},t,!0):a.Rectangle.union(a.Rectangle.clone(o),r)}function Pu(i,o,e){const t=a.getReverseDirection(o),n=Kn(i,t,e),r=Kn(i,o,e),s=la(n,o,e);return m.alignToMergedCellsBorders(a.Rectangle.union(r,s),e,!1)}function ca(i){return{startRow:0,startColumn:0,endRow:i.getRowCount()-1,endColumn:i.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL}}function Kn(i,o,e){let t;switch(o){case a.Direction.UP:t={startRow:i.startRow,startColumn:i.startColumn,endRow:i.startRow,endColumn:i.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.DOWN:t={startRow:i.endRow,startColumn:i.startColumn,endRow:i.endRow,endColumn:i.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.LEFT:t={startRow:i.startRow,startColumn:i.startColumn,endRow:i.endRow,endColumn:i.startColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.RIGHT:t={startRow:i.startRow,startColumn:i.endColumn,endRow:i.endRow,endColumn:i.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;default:throw new Error("Invalid direction")}return m.alignToMergedCellsBorders(t,e,!1)}function qn(i,o,e,t,n){let r=!1;const s=i.getMatrixWithMergedCells(o,e,t,n).forValue((l,c,d)=>{if(Ru(d))return r=!0,!1});return{hasValue:r,matrix:s}}function cr(i,o,e){const t=a.Rectangle.clone(i);if(o==null)return t;switch(e){case a.Direction.UP:case a.Direction.DOWN:t.startColumn=t.endColumn=o.actualColumn;break;case a.Direction.LEFT:case a.Direction.RIGHT:t.startRow=t.endRow=o.actualRow;break}return t}function Mu(i,o,e){var l,c,d,u;const{primary:t,range:n}=i,r=a.Rectangle.clone(n);switch(o){case a.Direction.UP:case a.Direction.DOWN:r.startRow=(l=t==null?void 0:t.startRow)!=null?l:n.startRow,r.endRow=(c=t==null?void 0:t.endRow)!=null?c:n.startRow;break;case a.Direction.LEFT:case a.Direction.RIGHT:r.startColumn=(d=t==null?void 0:t.startColumn)!=null?d:n.startColumn,r.endColumn=(u=t==null?void 0:t.endColumn)!=null?u:n.startColumn;break}const s=Kn(r,o,e);switch(o){case a.Direction.DOWN:return n.startRow<s.startRow;case a.Direction.UP:return n.endRow>s.endRow;case a.Direction.LEFT:return s.endColumn<n.endColumn;case a.Direction.RIGHT:return s.startColumn>n.startColumn}}function da(i,o){let e=i[0].startRow,t=i[0].endRow;i.forEach(r=>{const{startRow:s,endRow:l}=r;e=Math.min(e,s),t=Math.max(t,l)});const n=new Array(t-e+1).fill(!1);return o.forEach(r=>{const{startRow:s,endRow:l}=r;for(let c=Math.max(s,e);c<=Math.min(l,t);c++)n[c-e]=!0}),i.every(r=>{const{startRow:s,endRow:l}=r;for(let c=s;c<=l;c++)if(!n[c-e])return!1;return!0})}function ua(i,o){let e=i[0].startColumn,t=i[0].endColumn;i.forEach(r=>{const{startColumn:s,endColumn:l}=r;e=Math.min(e,s),t=Math.max(t,l)});const n=new Array(t-e+1).fill(!1);return o.forEach(r=>{const{startColumn:s,endColumn:l}=r;for(let c=Math.max(s,e);c<=Math.min(l,t);c++)n[c-e]=!0}),i.every(r=>{const{startColumn:s,endColumn:l}=r;for(let c=s;c<=l;c++)if(!n[c-e])return!1;return!0})}function dr(i,o){return o?i==="mergeAll"?o.filter(e=>!(e.startRow===e.endRow&&e.startColumn===e.endColumn)):i==="mergeVertical"?o.filter(e=>e.startRow!==e.endRow):i==="mergeHorizontal"?o.filter(e=>e.startColumn!==e.endColumn):o:null}function Ru(i){return i.v!==void 0&&i.v!==null&&i.v!==""||i.p!==void 0}var qe=(i=>(i[i.moveStopeOne=0]="moveStopeOne",i[i.moveGap=1]="moveGap",i[i.moveStepPage=2]="moveStepPage",i[i.moveStepEnd=3]="moveStepEnd",i))(qe||{});const Ae={id:"sheet.command.move-selection",type:a.CommandType.COMMAND,handler:(i,o)=>{if(!o)return!1;const e=m.getSheetCommandTarget(i.get(a.IUniverInstanceService));if(!e)return!1;const{workbook:t,worksheet:n}=e,r=m.getSelectionsService(i,o.fromCurrentSelection).getCurrentLastSelection();if(!r)return!1;const{direction:s,jumpOver:l,extra:c}=o,{range:d,primary:u}=r,h=cr(d,u,s),S=l===1?lr(h,s,n):vt(h,s,n),g=m.getCellAtRowCol(S.startRow,S.startColumn,n);if(a.Rectangle.equals(g,h))return!1;const f=t.getUnitId();i.get(mn).remove({unitId:f,sheetId:n.getSheetId(),keycode:_.KeyCode.TAB});const p=[{range:a.Rectangle.clone(g),primary:{startRow:g.startRow,startColumn:g.startColumn,endRow:g.endRow,endColumn:g.endColumn,actualRow:S.startRow,actualColumn:S.startColumn,isMerged:g.isMerged,isMergedMainCell:g.startRow===S.startRow&&g.startColumn===S.startColumn}}];return i.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:t.getUnitId(),subUnitId:n.getSheetId(),selections:p,type:m.SelectionMoveType.MOVE_END,extra:c,reveal:!0})}},Qe={id:"sheet.command.move-selection-enter-tab",type:a.CommandType.COMMAND,handler:(i,o)=>{var B;if(!o)return!1;const e=m.getSheetCommandTarget(i.get(a.IUniverInstanceService));if(!e)return!1;const{workbook:t,worksheet:n}=e,r=m.getSelectionsService(i),{direction:s,keycode:l}=o,c=s===a.Direction.LEFT||s===a.Direction.UP,d=r.getCurrentSelections().concat(),u=d.findIndex(F=>F.primary),h=d[u];if(!h)return!1;const S=c?-1:1,g=u+S!==d.length?d[u+S]:d[0],f=d.findIndex(F=>F===g),p=t.getUnitId(),C=n.getSheetId();if(!h)return!1;const{range:v}=h,b=h.primary;let E=cr(v,b,s);const w=i.get(mn),R=w.getCurrentBySearch({unitId:p,sheetId:C,keycode:_.KeyCode.TAB});let M;const{startRow:O,endRow:N,startColumn:D,endColumn:H}=v,k=c?b.startRow===O&&b.startColumn===D:b.endRow===N&&b.endColumn===H;if(a.Rectangle.equals(v,b)){if(l===_.KeyCode.TAB)R==null&&w.addOrUpdate({unitId:p,sheetId:C,keycode:_.KeyCode.TAB,selection:h});else{const x=R==null?void 0:R.selection;if(x!=null){const{range:X,primary:Y}=x;E=cr(X,Y,s)}w.remove({unitId:p,sheetId:C,keycode:_.KeyCode.TAB})}const F=vt(E,s,n),z=m.getCellAtRowCol(F.startRow,F.startColumn,n);if(a.Rectangle.equals(z,E))return!1;M={range:a.Rectangle.clone(z),primary:{startRow:z.startRow,startColumn:z.startColumn,endRow:z.endRow,endColumn:z.endColumn,actualRow:F.startRow,actualColumn:F.startColumn,isMerged:z.isMerged,isMergedMainCell:z.startRow===F.startRow&&z.startColumn===F.startColumn}}}else{w.remove({unitId:p,sheetId:C,keycode:_.KeyCode.TAB});const F=a.Tools.deepClone(b),z=k?g.range:vt({startRow:F.startRow,startColumn:F.startColumn,endRow:F.endRow,endColumn:F.endColumn},s,n,{startRow:O,endRow:N,startColumn:D,endColumn:H}),x=k&&c,X=x?m.getCellAtRowCol(z.endRow,z.endColumn,n):m.getCellAtRowCol(z.startRow,z.startColumn,n);M={range:k?g.range:a.Rectangle.clone(v),primary:{startRow:X.startRow,startColumn:X.startColumn,endRow:X.endRow,endColumn:X.endColumn,actualRow:x?X.startRow:z.startRow,actualColumn:x?X.startColumn:z.startColumn,isMerged:X.isMerged,isMergedMainCell:X.startRow===z.startRow&&X.startColumn===z.startColumn},style:k?g.style:h.style}}k?(d[u].primary=null,d[f]=M,r.setSelections(p,C,[],m.SelectionMoveType.MOVE_END)):d[u]=M;const V=i.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:p,subUnitId:C,type:m.SelectionMoveType.MOVE_END,selections:d,reveal:!0,extra:o.extra}),W=(B=i.get(P.IRenderManagerService).getRenderById(p))==null?void 0:B.with(Ce);return W==null||W.refreshSelectionMoveEnd(),V}},De={id:"sheet.command.expand-selection",type:a.CommandType.COMMAND,handler:(i,o)=>{if(!o)return!1;const e=m.getSheetCommandTarget(i.get(a.IUniverInstanceService));if(!e)return!1;const{worksheet:t,unitId:n,subUnitId:r}=e,s=m.getSelectionsService(i).getCurrentLastSelection();if(!s)return!1;const{range:l,primary:c}=s,{jumpOver:d,direction:u,extra:h}=o,g=Mu(s,u,t)?d===1?yu(l,{...a.Rectangle.clone(c),rangeType:a.RANGE_TYPE.NORMAL},u,t):Pu(l,u,t):d===1?Tu(l,u,t):wu(l,u,t);return g.rangeType=s.range.rangeType,a.Rectangle.equals(g,l)?!1:i.get(a.ICommandService).syncExecuteCommand(m.SetSelectionsOperation.id,{unitId:n,subUnitId:r,type:m.SelectionMoveType.ONLY_SET,selections:[{range:g,primary:c}],extra:h})}},Gi={id:"sheet.command.select-all",type:a.CommandType.COMMAND,handler:async(i,o={expandToGapFirst:!0,loop:!1})=>{const e=m.getSheetCommandTarget(i.get(a.IUniverInstanceService));if(!e)return!1;const t=m.getSelectionsService(i).getCurrentLastSelection();if(!t)return!1;const n=i.get(ar),{worksheet:r,unitId:s,subUnitId:l}=e,c=`${s}|${l}`;c!==n.selectedRangeWorksheet&&(n.rangesStack=[],n.selectedRangeWorksheet=c);const d=r.getMaxRows(),u=r.getMaxColumns(),{expandToGapFirst:h,loop:S}=o,{range:g,primary:f}=t,p=g.endColumn===u-1&&g.endRow===d-1&&g.startRow===0&&g.startColumn===0;n.rangesStack.some(v=>a.Rectangle.equals(v,g))||(n.rangesStack=[],n.rangesStack.push(g));let C;if(p)if(S){if(n.rangesStack.findIndex(b=>a.Rectangle.equals(b,g))!==n.rangesStack.length-1)return!1;C=n.rangesStack[0]}else return!1;else h?(C=m.expandToContinuousRange(g,{left:!0,right:!0,up:!0,down:!0},r),a.Rectangle.equals(C,g)&&(C=ca(r))):C=ca(r);return n.rangesStack.some(v=>a.Rectangle.equals(v,C))||n.rangesStack.push(C),i.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:s,subUnitId:l,reveal:!0,selections:[{range:C,primary:f}]})}};var Ou=Object.defineProperty,Au=Object.getOwnPropertyDescriptor,Nu=(i,o,e,t)=>{for(var n=t>1?void 0:t?Au(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&Ou(o,e,n),n},Du=(i,o)=>(e,t)=>o(e,t,i);y.SheetScrollManagerService=class{constructor(o,e){T(this,"_scrollStateMap",new Map);T(this,"_rawScrollInfo$",new A.BehaviorSubject(null));T(this,"rawScrollInfo$",this._rawScrollInfo$.asObservable());T(this,"validViewportScrollInfo$",new A.BehaviorSubject(null));T(this,"_searchParamForScroll",null);this._context=o,this._sheetSkeletonManagerService=e}dispose(){this._rawScrollInfo$.complete()}calcViewportScrollFromRowColOffset(o){if(!o)return{viewportScrollX:0,viewportScrollY:0};let{sheetViewStartColumn:e,sheetViewStartRow:t,offsetX:n,offsetY:r}=o;t=t||0,r=r||0;const s=this._sheetSkeletonManagerService.getCurrentSkeleton(),l=(s==null?void 0:s.rowHeightAccumulation[t-1])||0,d=((s==null?void 0:s.columnWidthAccumulation[e-1])||0)+n,u=l+r;return{viewportScrollX:d,viewportScrollY:u}}setSearchParam(o){this._searchParamForScroll=o}getScrollStateByParam(o){return this._getCurrentScroll(o)}getCurrentScrollState(){return this._getCurrentScroll(this._searchParamForScroll)}setValidScrollState(o){this._setScrollState(o)}emitRawScrollParam(o){this._emitRawScroll(o)}setValidScrollStateToCurrSheet(o){if(this._searchParamForScroll==null)return;this._setScrollState({...this._searchParamForScroll,...o});const e=this._searchParamForScroll.sheetId,t=this._sheetSkeletonManagerService.getSkeleton(e);t&&t.setScroll(o.viewportScrollX,o.viewportScrollY)}clear(){this._searchParamForScroll!=null&&this._clearByParamAndNotify(this._searchParamForScroll)}_setScrollState(o){const{unitId:e,sheetId:t,sheetViewStartColumn:n,sheetViewStartRow:r,offsetX:s,offsetY:l}=o;this._scrollStateMap.has(e)||this._scrollStateMap.set(e,new Map);const c=this._scrollStateMap.get(e),d={sheetViewStartRow:r,sheetViewStartColumn:n,offsetX:s,offsetY:l};c.set(t,d)}_clearByParamAndNotify(o){this._setScrollState({...o,sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0}),this._emitRawScroll({sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0})}_getCurrentScroll(o){var s;const e={sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0};if(o==null)return e;const{unitId:t,sheetId:n}=o;return((s=this._scrollStateMap.get(t))==null?void 0:s.get(n))||e}_emitRawScroll(o){this._rawScrollInfo$.next(o)}},y.SheetScrollManagerService=Nu([Du(1,a.Inject(y.SheetSkeletonManagerService))],y.SheetScrollManagerService);const Xe={id:"sheet.operation.set-scroll",type:a.CommandType.OPERATION,handler:(i,o)=>{if(!o)return!1;const{unitId:e,sheetId:t,offsetX:n,offsetY:r,sheetViewStartColumn:s,sheetViewStartRow:l}=o;return i.get(P.IRenderManagerService).getRenderById(e).with(y.SheetScrollManagerService).emitRawScrollParam({unitId:e,sheetId:t,offsetX:n,offsetY:r,sheetViewStartRow:l,sheetViewStartColumn:s}),!0}},Sn={id:"sheet.command.set-scroll-relative",type:a.CommandType.COMMAND,handler:async(i,o)=>{const e=i.get(a.ICommandService),t=i.get(a.IUniverInstanceService),n=i.get(P.IRenderManagerService),r=m.getSheetCommandTarget(t);if(!r)return!1;const{unitId:s,subUnitId:l}=r,d=n.getRenderById(s).with(y.SheetScrollManagerService).getCurrentScrollState(),{offsetX:u=0,offsetY:h=0}=o||{},{sheetViewStartRow:S=0,sheetViewStartColumn:g=0,offsetX:f=0,offsetY:p=0}=d||{};return e.executeCommand(Xe.id,{unitId:s,sheetId:l,sheetViewStartRow:S,sheetViewStartColumn:g,offsetX:f+u,offsetY:p+h})}},Ye={id:"sheet.command.scroll-view",type:a.CommandType.COMMAND,handler:(i,o)=>{if(!o)return!1;const e=i.get(a.IUniverInstanceService),t=i.get(P.IRenderManagerService),n=m.getSheetCommandTarget(e);if(!n)return!1;const{workbook:r,worksheet:s,unitId:l}=n,d=t.getRenderById(l).with(y.SheetScrollManagerService).getCurrentScrollState();if(!s)return!1;const{sheetViewStartRow:u,sheetViewStartColumn:h,offsetX:S,offsetY:g}=o,{sheetViewStartColumn:f,sheetViewStartRow:p,offsetX:C,offsetY:v}=d||{},{xSplit:b,ySplit:E}=n.worksheet.getConfig().freeze;return i.get(a.ICommandService).syncExecuteCommand(Xe.id,{unitId:r.getUnitId(),sheetId:s.getSheetId(),sheetViewStartRow:u!=null?u:p!=null?p:0+E,sheetViewStartColumn:h!=null?h:f!=null?f:0+b,offsetX:S!=null?S:C,offsetY:g!=null?g:v})}},ur={id:"sheet.command.scroll-to-cell",type:a.CommandType.COMMAND,handler:(i,o)=>{const e=i.get(a.IUniverInstanceService);return i.get(P.IRenderManagerService).getRenderById(e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(y.SheetsScrollRenderController).scrollToRange(o.range,o.forceTop,o.forceLeft)}},Hu={id:"sheet.command.scroll-view-reset",type:a.CommandType.COMMAND,handler:async i=>{const o=i.get(a.IUniverInstanceService),e=m.getSheetCommandTarget(o);if(!e)return!1;const{subUnitId:t,unitId:n}=e;return i.get(a.ICommandService).executeCommand(Xe.id,{unitId:n,sheetId:t,sheetViewStartRow:0,sheetViewStartColumn:0})}};var ku=Object.defineProperty,Vu=Object.getOwnPropertyDescriptor,Wu=(i,o,e,t)=>{for(var n=t>1?void 0:t?Vu(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&ku(o,e,n),n},gn=(i,o)=>(e,t)=>o(e,t,i);Ae.id,Qe.id;const Lu=3;y.SheetsScrollRenderController=class extends a.Disposable{constructor(o,e,t,n,r,s,l){super(),this._context=o,this._injector=e,this._sheetSkeletonManagerService=t,this._contextService=n,this._commandService=r,this._renderManagerService=s,this._scrollManagerService=l,this._initCommandListener(),this._wheelEventListener(),this._scrollBarEventListener(),this._initSkeletonListener()}_wheelEventListener(){const{scene:o}=this._context;if(!o)return;const e=o.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN);e&&this.disposeWithMe(o.onMouseWheel$.subscribeEvent((t,n)=>{if(t.ctrlKey||!this._contextService.getContextValue(a.FOCUSING_SHEET))return;let r=0,s=0;r=t.deltaX,t.shiftKey?r=(t.deltaY||t.deltaX)*Lu:s=t.deltaY,this._commandService.executeCommand(Sn.id,{offsetX:r,offsetY:s}),this._context.scene.makeDirty(!0);const l=e.limitedScroll(e.scrollX+r,e.scrollY+s);l&&!l.isLimitedX&&!l.isLimitedY&&(t.preventDefault(),o.getParent().classType===P.RENDER_CLASS_TYPE.SCENE_VIEWER&&n.stopPropagation()),e.isWheelPreventDefaultX&&e.isWheelPreventDefaultY&&t.preventDefault()}))}_scrollBarEventListener(){const{scene:o}=this._context;if(o==null)return;const e=o.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN);e&&(this.disposeWithMe(a.toDisposable(this._scrollManagerService.rawScrollInfo$.subscribe(t=>{var g;const n=(g=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:g.skeleton;if(!n)return;if(t==null){e.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});return}const{sheetViewStartRow:r,sheetViewStartColumn:s,offsetX:l,offsetY:c}=t,{startX:d,startY:u}=n.getCellWithCoordByIndex(r,s,!1),h=d+l,S=u+c;e.scrollToViewportPos({viewportScrollX:h,viewportScrollY:S})}))),this.disposeWithMe(e.onScrollAfter$.subscribeEvent(t=>{var p;const n=(p=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:p.skeleton;if(n==null||t.isTrigger===!1)return;const r=this._getSheetObject();if(n==null||r==null)return;const{viewportScrollX:s,viewportScrollY:l,scrollX:c,scrollY:d}=t,{row:u,column:h,rowOffset:S,columnOffset:g}=n.getOffsetRelativeToRowCol(s,l),f={sheetViewStartRow:u,sheetViewStartColumn:h,offsetX:g,offsetY:S,viewportScrollX:s,viewportScrollY:l,scrollX:c,scrollY:d};this._scrollManagerService.setValidScrollStateToCurrSheet(f),this._scrollManagerService.validViewportScrollInfo$.next({...f,viewportScrollX:s,viewportScrollY:l,scrollX:c,scrollY:d})})),this.disposeWithMe(e.onScrollByBar$.subscribeEvent(t=>{var S;const n=(S=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:S.skeleton;if(n==null||t.isTrigger===!1)return;const r=this._getSheetObject();if(n==null||r==null)return;const{viewportScrollX:s=0,viewportScrollY:l=0}=t;this._getFreeze();const{row:c,column:d,rowOffset:u,columnOffset:h}=n.getOffsetRelativeToRowCol(s,l);this._commandService.executeCommand(Ye.id,{sheetViewStartRow:c,sheetViewStartColumn:d,offsetX:h,offsetY:u})})))}_initSkeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeletonBefore$.subscribe(o=>{if(o==null)return;const e={unitId:o.unitId,sheetId:o.sheetId};if(this._scrollManagerService.setSearchParam(e),!this._getSheetObject())return;const n=this._scrollManagerService.getScrollStateByParam(e),{viewportScrollX:r,viewportScrollY:s}=this._scrollManagerService.calcViewportScrollFromRowColOffset(n);n&&this._updateViewportScroll(r,s)})))}_updateViewportScroll(o=0,e=0){const t=this._getSheetObject();if(!t)return;const n=t.scene,r=n.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN),s=n.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT),l=n.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM),c=n.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT),d=n.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);r&&(r.viewportScrollX=o,r.viewportScrollY=e),l&&(l.viewportScrollY=e),s&&(s.viewportScrollX=o),c&&(c.viewportScrollY=e),d&&(d.viewportScrollX=o)}scrollToRange(o,e,t){let{endRow:n,endColumn:r,startColumn:s,startRow:l}=o;const c=this._getViewportBounding();if(o.rangeType===a.RANGE_TYPE.ROW?(s=0,r=0):o.rangeType===a.RANGE_TYPE.COLUMN&&(l=0,n=0),c&&!e&&!t){const d=c.startRow>n?l:n,u=c.startColumn>r?s:r;return this._scrollToCell(d,u)}else return this._scrollToCell(l,s,e,t)}scrollToCell(o,e){const t=this._context.unit.getActiveSheet(),{ySplit:n,xSplit:r}=t.getFreeze();return this._commandService.syncExecuteCommand(Ye.id,{sheetViewStartRow:o-n,sheetViewStartColumn:e-r,offsetX:0,offsetY:0})}_initCommandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(o=>{switch(o.id){case m.SetSelectionsOperation.id:{const e=o.params;e.unitId===this._context.unitId&&e.reveal&&this._scrollToSelection()}break;case m.ScrollToCellOperation.id:{const e=o.params;if(e.unitId===this._context.unitId){const t=e.range;this.scrollToRange(t)}}break;case De.id:{const e=o.params;this._scrollToSelectionForExpand(e)}break}}))}_scrollToSelectionForExpand(o){setTimeout(()=>{const e=this._getSelectionsService().getCurrentLastSelection();if(e==null)return;const{startRow:t,startColumn:n,endRow:r,endColumn:s}=e.range,l=this._getViewportBounding();if(l==null)return;const{startRow:c,startColumn:d,endRow:u,endColumn:h}=l;let S=0,g=0;t>c?S=r:r<u?S=t:S=c,n>d?g=s:s<h?g=n:g=d,o.direction===a.Direction.DOWN?S=r:o.direction===a.Direction.UP?S=t:o.direction===a.Direction.RIGHT?g=s:o.direction===a.Direction.LEFT&&(g=n),this._scrollToCell(S,g)},0)}_getFreeze(){var e;const o=(e=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:e.skeleton.getWorksheetConfig();if(o!=null)return o.freeze}_updateSceneSize(o){var h;if(o==null)return;const{unitId:e}=this._context,{skeleton:t}=o,n=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.scene;if(t==null||n==null)return;const{rowTotalHeight:r,columnTotalWidth:s,rowHeaderWidthAndMarginLeft:l,columnHeaderHeightAndMarginTop:c}=t;this._context.unit.getActiveSheet()&&(n==null||n.transformByState({width:l+s,height:c+r}))}_getSheetObject(){return ze(this._context.unit,this._context)}_scrollToSelectionByDirection(o){const e=this._getViewportBounding();if(e==null)return!1;const{startRow:t,startColumn:n,endRow:r,endColumn:s}=e;let l=0,c=0;const{startRow:d,startColumn:u,endRow:h,endColumn:S}=o;d>=t&&(l=h),h<=r&&(l=d),u>=n&&(c=S),S<=s&&(c=u),this._scrollToCell(l,c)}_scrollToSelection(o=!0){var d;const e=this._getSelectionsService().getCurrentLastSelection();if(!e)return;const{startRow:t,startColumn:n,actualRow:r,actualColumn:s}=(d=e.primary)!=null?d:e.range,l=o&&r!=null?r:t,c=o&&s!=null?s:n;this._scrollToCell(l,c)}_getSelectionsService(){return m.getSelectionsService(this._injector)}_getViewportBounding(){var r,s;const o=(r=this._getSheetObject())==null?void 0:r.scene;if(o==null)return;const e=o.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e==null)return;const t=(s=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:s.skeleton;if(t==null)return;const n=e.calcViewportInfo();return t.getRangeByViewBound(n.viewBound)}_scrollToCell(o,e,t=!1,n=!1){var H,k,V;const{rowHeightAccumulation:r,columnWidthAccumulation:s}=(H=this._sheetSkeletonManagerService.getCurrentSkeleton())!=null?H:{};if(r==null||s==null)return!1;const l=(k=this._getSheetObject())==null?void 0:k.scene;if(l==null)return!1;const c=l.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(c==null)return!1;const d=(V=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:V.skeleton;if(d==null)return!1;const u=this._context.unit.getActiveSheet();if(!u)return!1;o=a.Tools.clamp(o,0,r.length-1),e=a.Tools.clamp(e,0,s.length-1);const{startColumn:h,startRow:S,ySplit:g,xSplit:f}=u.getFreeze(),p=this._getViewportBounding();if(p==null)return!1;const{startRow:C,startColumn:v,endRow:b,endColumn:E}=p;let w,R;if(o>=S&&e>=h-g&&(o<=C&&(w=o,t=!0),o>=b)){const U=r[o]-c.height;for(let W=C;W<=o&&(w=W+1,!(r[W]>=U));W++);}if(e>=h&&o>=S-g&&(e<=v&&(R=e,n=!0),e>=E)){const U=s[e]-c.width;for(let W=v;W<=e&&(R=W+1,!(s[W]>=U));W++);}if(w===void 0&&R===void 0)return!1;let{offsetX:M,offsetY:O,sheetViewStartRow:N,sheetViewStartColumn:D}=this._scrollManagerService.getCurrentScrollState()||{};if(w=w?Math.min(w,o):N+g,R=R?Math.min(R,e):D+f,n){M=0,R=e;const U=d.getHiddenColumnsInRange({startColumn:R-f,endColumn:R});R=R-U.length}if(t){O=0,w=o;const U=d.getHiddenRowsInRange({startRow:w-g,endRow:w});w=w-U.length}return this._commandService.syncExecuteCommand(Ye.id,{sheetViewStartRow:Math.max(0,w-g),sheetViewStartColumn:Math.max(0,R-f),offsetX:M,offsetY:O})}},y.SheetsScrollRenderController=Wu([gn(1,a.Inject(a.Injector)),gn(2,a.Inject(y.SheetSkeletonManagerService)),gn(3,a.IContextService),gn(4,a.ICommandService),gn(5,P.IRenderManagerService),gn(6,a.Inject(y.SheetScrollManagerService))],y.SheetsScrollRenderController);const hr={id:"sheet.operation.scroll-to-range",type:a.CommandType.OPERATION,handler:(i,o)=>{if(!o)return!1;const e=i.get(a.IUniverInstanceService);return i.get(P.IRenderManagerService).getRenderById(e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(y.SheetsScrollRenderController).scrollToRange(o.range,o.forceTop,o.forceLeft)}};class ha{constructor(){T(this,"_state",null);T(this,"_rect",null);T(this,"_state$",new A.BehaviorSubject(null));T(this,"state$",this._state$.asObservable());T(this,"_rect$",new A.BehaviorSubject(null));T(this,"rect$",this._rect$.asObservable());T(this,"_focus",!1);T(this,"_focus$",new A.BehaviorSubject(this._focus));T(this,"focus$",this._focus$.asObservable())}dispose(){this._state$.complete(),this._state=null,this._rect$.complete(),this._rect=null}setState(o){this._state=o,this._refresh(o)}getRect(){return this._rect}setRect(o){this._rect=o,this._rect$.next(o)}getState(){return this._state}setFocus(o=!1){this._focus=o,this._focus$.next(o)}_refresh(o){this._state$.next(o)}}const Qn=a.createIdentifier("univer.sheet-cell-editor-manager.service"),ma={sheetFooterBarHeight:"36",sheetContainer:"univer-sheet-container"};var Uu=Object.defineProperty,Bu=Object.getOwnPropertyDescriptor,xu=(i,o,e,t)=>{for(var n=t>1?void 0:t?Bu(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&Uu(o,e,n),n},fn=(i,o)=>(e,t)=>o(e,t,i);const Sa=5,ga=2;y.SheetCellEditorResizeService=class extends a.Disposable{constructor(o,e,t,n,r,s,l){super(),this._context=o,this._layoutService=e,this._cellEditorManagerService=t,this._editorBridgeService=n,this._renderManagerService=r,this._sheetSkeletonManagerService=s,this._univerInstanceService=l}fitTextSize(o){var D,H,k,V;const e=this._editorBridgeService.getEditCellState();if(!e)return;const{position:t,documentLayoutObject:n,canvasOffset:r,scaleX:s,scaleY:l}=e,{startX:c,startY:d,endX:u,endY:h}=t,S=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);if(S==null)return;const g=this._getEditorSkeleton();if(!g)return;const f=this._predictingSize(t,r,g,n,s,l);if(!f)return;let{actualWidth:p,actualHeight:C}=f;const{verticalAlign:v,horizontalAlign:b,paddingData:E,fill:w}=n;p=p+((D=E.l)!=null?D:0)+((H=E.r)!=null?H:0),C=C+((k=E.t)!=null?k:0)+((V=E.b)!=null?V:0);let R=u-c,M=h-d;R<p&&(R=Math.ceil(p)),M<C&&(M=Math.ceil(C));let O=0;v===a.VerticalAlign.MIDDLE?O=(M-C)/2/l:v===a.VerticalAlign.TOP?O=E.t||0:O=(M-C)/l;let N=0;b===a.HorizontalAlign.CENTER?N=(R-p)/2/s:b===a.HorizontalAlign.RIGHT?N=(R-p)/s:N=E.l||0,O=O<(E.t||0)?E.t||0:O,N=N<(E.l||0)?E.l||0:N,S.updateDocumentDataMargin({t:O,l:N}),g.calculate(),this._editAreaProcessing(R,M,t,r,w,s,l,b,o)}_predictingSize(o,e,t,n,r=1,s=1){const{startX:l,endX:c}=o,{textRotation:d,wrapStrategy:u,paddingData:h}=n,S=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC),{vertexAngle:g}=P.convertTextRotation(d);if(u===a.WrapStrategy.WRAP&&g===0){S==null||S.updateDocumentDataPageSize(c-l),S==null||S.updateDocumentDataMargin({l:h.l,t:h.t}),t.calculate();const{actualWidth:v,actualHeight:b}=t.getActualSize();return{actualWidth:v*r,actualHeight:b*s}}const f=this._getEditorMaxSize(o,e,n.horizontalAlign);if(!f)return;S==null||S.updateDocumentDataPageSize(f.width/r),t.calculate();const p=t.getActualSize();let C=c-l;return C<p.actualWidth*r+Sa*r&&(C=p.actualWidth*r+Sa*r),S==null||S.updateDocumentDataPageSize(C/r),S==null||S.updateDocumentRenderConfig({horizontalAlign:a.HorizontalAlign.UNSPECIFIED,cellValueType:void 0}),{actualWidth:p.actualWidth*r,actualHeight:p.actualHeight*s}}_getEditorMaxSize(o,e,t){if(this._getEditorObject()==null)return;function r(b){return Number.parseInt(b.replace("px",""))}const l=this._context.engine.getCanvasElement(),c=l.getBoundingClientRect(),d=r(l.style.width),{width:u}=c,h=u/d,{startX:S,startY:g,endX:f}=o,p=this._context.engine.width,C=document.body.clientHeight-g-Number.parseFloat(ma.sheetFooterBarHeight)-e.top-ga*2;let v=u-S;if(t===a.HorizontalAlign.CENTER){const b=p-f,E=S;v=f-S+Math.min(E,b)*2}else t===a.HorizontalAlign.RIGHT&&(v=f);return{height:C,width:v-ga,scaleAdjust:h}}_editAreaProcessing(o,e,t,n,r,s=1,l=1,c,d){var W;const u=this._getEditorObject();if(u==null)return;const S=this._context.engine.getCanvasElement();let{startX:g,startY:f}=t;const{document:p,scene:C,engine:v}=u,b=C.getViewport(Q.VIEWPORT_KEY.VIEW_MAIN),E=this._getEditorMaxSize(t,n,c),{height:w,width:R,scaleAdjust:M}=E;let O=e,N=b==null?void 0:b.getScrollBar();O>w?(N==null?b&&new P.ScrollBar(b,{enableHorizontal:!1,barSize:8}):b==null||b.resetCanvasSizeAndUpdateScroll(),b==null||b.scrollToViewportPos({viewportScrollY:O-w}),O=w):(N=null,(W=b==null?void 0:b.getScrollBar())==null||W.dispose()),o+=(N==null?void 0:N.barSize)||0,o>R&&(o=R),this._addBackground(C,o/s,e/l,r);const{scaleX:D,scaleY:H}=C.getPrecisionScale();C.transformByState({width:o*M/s,height:e*M/l,scaleX:s*M,scaleY:l*M}),p.resize(o*M/s,e*M/l),setTimeout(()=>{v.resizeBySize(P.fixLineWidthByScale(o,D),P.fixLineWidthByScale(O,H)),d==null||d()},0);const k=this._layoutService.getContentElement().getBoundingClientRect(),V=S.getBoundingClientRect();g=g*M+(V.left-k.left),f=f*M+(V.top-k.top);const U=t.endX-t.startX;c===a.HorizontalAlign.RIGHT?g+=(U-o)*M:c===a.HorizontalAlign.CENTER&&(g+=(U-o*M)/2),this._cellEditorManagerService.setState({startX:g,startY:f,endX:o*M+g,endY:O*M+f,show:!0})}_addBackground(o,e,t,n){const r="_backgroundRectHelperColor_",s=o.getObject(r);s==null&&n==null||(s==null?o.addObjects([new P.Rect(r,{width:e,height:t,fill:n,evented:!1})],Q.DOCS_COMPONENT_MAIN_LAYER_INDEX):n==null?s.dispose():(s.setProps({fill:n}),s.transformByState({width:e,height:t})))}resizeCellEditor(o){var M;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 n=(M=this._sheetSkeletonManagerService.getSkeletonParam(t.sheetId))==null?void 0:M.skeleton;if(!n)return;const{row:r,column:s,scaleX:l,scaleY:c,position:d,canvasOffset:u,documentLayoutObject:h}=t,{horizontalAlign:S}=h,g=this._getEditorMaxSize(d,u,S);if(!g)return;const{height:f,width:p,scaleAdjust:C}=g,v=n.getCellWithCoordByIndex(r,s),b=Math.min((v.mergeInfo.endY-v.mergeInfo.startY)*c,f)*C,E=Math.min((v.mergeInfo.endX-v.mergeInfo.startX)*l,p)*C,w=e.endY-e.startY,R=e.endX-e.startX;if(w!==b||R!==E){if(this._editorBridgeService.refreshEditCellPosition(!0),!this._getEditorSkeleton())return;this.fitTextSize(o)}}_getEditorObject(){return ki(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}_getEditorSkeleton(){var o;return(o=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:o.with(Ee.DocSkeletonManagerService).getSkeleton()}},y.SheetCellEditorResizeService=xu([fn(1,_.ILayoutService),fn(2,Qn),fn(3,ge),fn(4,P.IRenderManagerService),fn(5,a.Inject(y.SheetSkeletonManagerService)),fn(6,a.IUniverInstanceService)],y.SheetCellEditorResizeService);function mr(i){return i.getContextValue(a.FOCUSING_SHEET)}function ce(i){return i.getContextValue(a.FOCUSING_SHEET)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!i.getContextValue(a.EDITOR_ACTIVATED)&&!i.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function fa(i){return i.getContextValue(a.FOCUSING_SHEET)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!i.getContextValue(a.EDITOR_ACTIVATED)&&!i.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function Fu(i){return i.getContextValue(a.FOCUSING_SHEET)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&i.getContextValue(a.EDITOR_ACTIVATED)}function zu(i){return i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&i.getContextValue(a.EDITOR_ACTIVATED)}function pa(i){return i.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function Xu(i){return i.getContextValue(a.FOCUSING_SHEET)&&i.getContextValue(a.EDITOR_ACTIVATED)&&i.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function Jn(i){return i.getContextValue(a.FOCUSING_SHEET)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&i.getContextValue(a.EDITOR_ACTIVATED)&&!i.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&!i.getContextValue(a.FOCUSING_EDITOR_STANDALONE)}const Ca=[_.KeyCode.ARROW_DOWN,_.KeyCode.ARROW_UP,_.KeyCode.ARROW_LEFT,_.KeyCode.ARROW_RIGHT],Yu=[_.KeyCode.ENTER,_.KeyCode.TAB,...Ca];function va(){const i=[];for(const o of Ca)i.push({id:Nt.id,binding:o,preconditions:e=>Jn(e),staticParameters:{visible:!1,eventType:P.DeviceInputEventType.Keyboard,keycode:o,isShift:!1}}),i.push({id:Nt.id,binding:o|_.MetaKeys.SHIFT,preconditions:e=>Jn(e),staticParameters:{visible:!1,eventType:P.DeviceInputEventType.Keyboard,keycode:o,isShift:!0}});return i}const _a={id:jn.id,binding:_.KeyCode.F2,description:"shortcut.sheet.start-editing",group:"4_sheet-edit",preconditions:ce,staticParameters:{visible:!0,eventType:P.DeviceInputEventType.Keyboard,keycode:_.KeyCode.F2}},Ia={id:ve.id,binding:_.KeyCode.ENTER,description:"shortcut.sheet.toggle-editing",group:"4_sheet-edit",preconditions:i=>Jn(i),staticParameters:{visible:!1,eventType:P.DeviceInputEventType.Keyboard,keycode:_.KeyCode.ENTER}},ba={id:ve.id,binding:_.KeyCode.TAB,preconditions:i=>Jn(i),staticParameters:{visible:!1,eventType:P.DeviceInputEventType.Keyboard,keycode:_.KeyCode.TAB}},Ea={id:ve.id,binding:_.KeyCode.ESC,description:"shortcut.sheet.abort-editing",group:"4_sheet-edit",preconditions:i=>Jn(i),staticParameters:{visible:!1,eventType:P.DeviceInputEventType.Keyboard,keycode:_.KeyCode.ESC}},Ta={id:Q.BreakLineCommand.id,description:"shortcut.sheet.break-line",group:"4_sheet-edit",preconditions:i=>Fu(i),binding:_.KeyCode.ENTER|_.MetaKeys.ALT},wa={id:Q.DeleteLeftCommand.id,preconditions:i=>zu(i)||pa(i),binding:_.KeyCode.BACKSPACE},ya={id:ve.id,description:"shortcut.sheet.delete-and-start-editing",group:"4_sheet-edit",preconditions:i=>ce(i)&&!pa(i),binding:_.KeyCode.BACKSPACE,staticParameters:{visible:!0,eventType:P.DeviceInputEventType.Keyboard,keycode:_.KeyCode.BACKSPACE}};function ju(i){return i.startsWith("'")}function Gu(i){return i.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","%":"%","-":"-",".":".",":":":","/":"/","+":"+","@":"@","&":"&","*":"*","#":"#","=":"=",">":">","<":"<","$":"$",""":'"',"'":"'","(":"(",")":")"," ":" ",",":",","!":"!","?":"?",";":";","[":"[","]":"]","{":"{","}":"}"},Sr={true:"TRUE",false:"FALSE"};function Ku(i){return[a.LocaleType.ZH_CN,a.LocaleType.ZH_TW].includes(i)}function qu(i,o,e,t){let n=i;if(Ku(e)){if(i.startsWith("'")||i.startsWith("'"))return`'${i.slice(1)}`;n=Qu(n)}if(n.startsWith("="))return Ju(i,n,o,t);const r=n.toLowerCase();return Sr[r]?Sr[r]:a.numfmt.parseValue(n)==null?i:n}function Qu(i){const o=/['"].*?['"]/g,e=[],t=i.split(o);i.replace(o,r=>(e.push(r),""));let n=t.join("").split("").map(th).join("");return e.forEach((r,s)=>{n=n.slice(0,s*2)+r+n.slice((s+1)*2)}),n}function Ju(i,o,e,t){const n=e.sequenceNodesBuilder(o);if(!n)return i;let r=o,s=0;return n.forEach((l,c)=>{if(typeof l=="object"){const d=l.token;if(Sr[d.toLowerCase()]){const u=l.startIndex+s+1,h=l.endIndex+s+2;r=pn(d.toLocaleUpperCase(),r,u,h)}else if(l.nodeType===q.sequenceNodeType.FUNCTION&&$u(d,t,n,c)||l.nodeType===q.sequenceNodeType.REFERENCE){const u=d.indexOf("!");if(u>-1){const h=d.substring(u+1),S=l.startIndex+s+(u+1)+1,g=l.endIndex+s+2;r=pn(h.toLocaleUpperCase(),r,S,g)}else{const h=l.startIndex+s+1,S=l.endIndex+s+2;r=pn(d.toLocaleUpperCase(),r,h,S)}}else if(d.startsWith('"')&&d.endsWith('"')||d.startsWith("'")&&d.endsWith("'")){const u=l.startIndex+s+2,h=l.endIndex+s+1;r=pn(i.slice(u,h),r,u,h)}else if(l.nodeType!==q.sequenceNodeType.ARRAY){const u=a.numfmt.parseValue(d);if(u==null){const h=l.startIndex+s+1,S=l.endIndex+s+2;r=pn(i.slice(h,S),r,h,S)}else if(typeof u.v=="number"&&(u.z===void 0||!a.numfmt.isDate(u.z))){const h=`${u.v}`,S=l.startIndex+s+1,g=l.endIndex+s+2,{processedString:f,offset:p}=nh(d,h);r=pn(f,r,S,g),s+=p}}}}),r}function $u(i,o,e,t){const n=o.getDescriptions();return e[t+1]!==q.matchToken.OPEN_BRACKET?!1:n.get(eh(i).toLocaleUpperCase())!==void 0}function eh(i){const o=/^@+/;return i.replace(o,"")}function th(i){return Zu[i]||i}function pn(i,o,e,t){return o.substring(0,e)+i+o.substring(t)}function nh(i,o){var s,l;const e=((s=i.match(/^\s*/))==null?void 0:s[0])||"",t=((l=i.match(/\s*$/))==null?void 0:l[0])||"",n=e+o+t,r=n.length-i.length;return{processedString:n,offset:r}}const Pa="range_selector",Ma=i=>i.includes(Pa);var ih=Object.defineProperty,oh=Object.getOwnPropertyDescriptor,rh=(i,o,e,t)=>{for(var n=t>1?void 0:t?oh(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&ih(o,e,n),n},Re=(i,o)=>(e,t)=>o(e,t,i);const Ra=-1e3;y.EditingRenderController=class extends a.Disposable{constructor(e,t,n,r,s,l,c,d,u,h,S,g,f,p,C,v){super();T(this,"_cursorChange",0);T(this,"_isUnitEditing",!1);T(this,"_workbookSelections");T(this,"_d");T(this,"_cursorTimeout");this._context=e,this._undoRedoService=n,this._contextService=r,this._renderManagerService=s,this._editorBridgeService=l,this._cellEditorManagerService=c,this._lexerTreeBuilder=d,this._functionService=u,this._textSelectionManagerService=h,this._commandService=S,this._localService=g,this._editorService=f,this._sheetCellEditorResizeService=p,this._univerInstanceService=C,this._sheetInterceptorService=v,this._workbookSelections=t.getWorkbookSelections(this._context.unitId),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(b=>{(b==null?void 0:b.getUnitId())===this._context.unitId?this._d=this._init():(this._disposeCurrent(),this._isUnitEditing&&(this._handleEditorInvisible({visible:!1,eventType:P.DeviceInputEventType.Keyboard,keycode:_.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),e.add(()=>{clearTimeout(this._cursorTimeout)}),this._cursorTimeout=setTimeout(()=>{this._cursorStateListener(e)},1e3),e}_initEditorVisibilityListener(){this.disposeWithMe(this._editorBridgeService.visible$.pipe(A.distinctUntilChanged((e,t)=>e.visible===t.visible)).subscribe(e=>{(e.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY||e.unitId===a.DOCS_NORMAL_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 n=this._editorBridgeService.getEditCellState(),r=this._editorBridgeService.getCurrentEditorId();if(!n||!r)return;this._sheetCellEditorResizeService.fitTextSize()}}))}_initialCursorSync(e){e.add(this._cellEditorManagerService.focus$.pipe(A.filter(t=>!!t)).subscribe(()=>{var n;const t=(n=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_DOC))==null?void 0:n.with(Q.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(n=>{if(t.has(n.id)){switch(n.id){case m.MoveRowsMutation.id:case m.MoveColsMutation.id:case m.RemoveColMutation.id:case m.RemoveRowMutation.id:case m.InsertColMutation.id:case m.InsertRowMutation.id:{const r=this._editorBridgeService.getEditLocation();if(!r)break;const s={startRow:r.row,startColumn:r.column,endRow:r.row,endColumn:r.column},l=m.adjustRangeOnMutation(s,n);if(!l)break;const c=l.startRow,d=l.startColumn;this._editorBridgeService.updateEditLocation(c,d);break}}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 b,E;if(t==null||this._editorBridgeService.isForceKeepVisible())return;const n=this._editorBridgeService.getEditCellState();if(n==null)return;const{position:r,documentLayoutObject:s,scaleX:l,editorUnitId:c}=n;if(this._contextService.getContextValue(a.FOCUSING_EDITOR_STANDALONE))return;const d=this._getDocumentDataModel();if(d==null)return;const{startX:u,endX:h}=r,{textRotation:S,wrapStrategy:g,documentModel:f}=s,{vertexAngle:p}=P.convertTextRotation(S);g===a.WrapStrategy.WRAP&&p===0&&d.updateDocumentDataPageSize((h-u)/l),this._commandService.syncExecuteCommand(Q.ReplaceSnapshotCommand.id,{unitId:c,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 C=(b=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:b.with(Q.DocSelectionRenderService),v=(E=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:E.with(Q.DocSelectionRenderService);(C!=null&&C.canFocusing||v!=null&&v.canFocusing)&&(this._univerInstanceService.setCurrentUnitForType(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),C==null||C.activate(Ra,Ra,!0))}))}_commandExecutedListener(e){e.add(this._commandService.onCommandExecuted(n=>{if(n.id===Ee.RichTextEditingMutation.id){const r=n.params,{unitId:s}=r;if(!this._isCurrentSheetFocused()||Ma(s)||(this._editorBridgeService.changeEditorDirty(!0),!this._editorBridgeService.isVisible().visible))return;s===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._sheetCellEditorResizeService.fitTextSize()}}));const t=[Nt.id];e.add(this._commandService.onCommandExecuted(n=>{if(t.includes(n.id)){const r=n.params,{keycode:s,isShift:l}=r;if(s!=null&&(this._cursorChange===2||this._contextService.getContextValue(a.FOCUSING_FX_BAR_EDITOR))){this._moveInEditor(s,l);return}this._commandService.syncExecuteCommand(ve.id,r)}n.id===jn.id&&(this._cursorChange=2)}))}_handleEditorVisible(e){var g,f,p;const{eventType:t,keycode:n}=e;this._cursorChange=t===P.DeviceInputEventType.PointerDown||t===P.DeviceInputEventType.Dblclick?2:1;const r=this._editorBridgeService.getEditLocation();if(r==null)return;this._commandService.syncExecuteCommand(hr.id,{range:{startRow:r.row,startColumn:r.column,endRow:r.row,endColumn:r.column}}),this._editorBridgeService.refreshEditCellPosition(!1);const{unitId:s,isInArrayFormulaRange:l=!1}=r,c=this._getEditorObject();if(c==null)return;const{document:d,scene:u}=c;this._contextService.setContextValue(a.EDITOR_ACTIVATED,!0);const h=this._getDocumentDataModel(),S=this._getEditorSkeleton(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(!(!S||!h)){if(this._sheetCellEditorResizeService.fitTextSize(()=>{const C=u.getViewport(Q.VIEWPORT_KEY.VIEW_MAIN);C==null||C.scrollToViewportPos({viewportScrollX:Number.POSITIVE_INFINITY,viewportScrollY:Number.POSITIVE_INFINITY})}),t===P.DeviceInputEventType.Keyboard&&n===_.KeyCode.F2){d.makeDirty(),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}]);const C=((f=(g=h.getBody())==null?void 0:g.dataStream.length)!=null?f:2)-2;this._textSelectionManagerService.replaceDocRanges([{startOffset:C,endOffset:C}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})}else if(t===P.DeviceInputEventType.Keyboard||t===P.DeviceInputEventType.Dblclick&&l)this._emptyDocumentDataModel(h.getSnapshot().documentStyle,!!l),d.makeDirty(),(n===_.KeyCode.BACKSPACE||t===P.DeviceInputEventType.Dblclick)&&(S.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===P.DeviceInputEventType.Dblclick){if(this._contextService.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA))return;const C=h.getBody().dataStream.length-2||0;this._textSelectionManagerService.replaceDocRanges([{startOffset:C,endOffset:C}])}(p=this._renderManagerService.getRenderById(s))==null||p.scene.resetCursor()}}async _handleEditorInvisible(e){const t=this._editorBridgeService.getEditCellState(),n=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),r=a.Tools.deepClone(n==null?void 0:n.getSnapshot());let{keycode:s}=e;if(this._cursorChange=0,this._exitInput(e),t==null)return;this._editorBridgeService.getEditorDirty()===!1&&(s=_.KeyCode.ESC);const d=this._context.unit.getActiveSheet(),u=this._context.unitId,h=d.getSheetId(),{unitId:S,sheetId:g}=t;if(u===S&&g!==h&&await this._commandService.executeCommand(m.SetWorksheetActivateCommand.id,{subUnitId:g,unitId:S}),s===_.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:g,selections:f}));return}r&&await this._submitCellData(r),this._moveCursor(s)}_getEditorObject(){return ki(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:n,sheetId:r,row:s,column:l}=t,c=this._context.unit;let d=c.getActiveSheet();if(!c.getSheetBySheetId(r))return;d=c.getActiveSheet();const h=sh({...d.getCellRaw(s,l)||{}},e,this._lexerTreeBuilder,this._localService,this._functionService,c.getStyles());if(!h)return;const S=await this._sheetInterceptorService.onWriteCell(c,d,s,l,h);S!==d.getCellRaw(s,l)&&this._commandService.executeCommand(m.SetRangeValuesCommand.id,{subUnitId:r,unitId:n,range:{startRow:s,startColumn:l,endRow:s,endColumn:l},value:S})}_exitInput(e){var r;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();(r=t==null?void 0:t.scene.getViewport(Q.VIEWPORT_KEY.VIEW_MAIN))==null||r.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});const n=this._editorBridgeService.getCurrentEditorId();n==null||!this._editorService.isSheetEditor(n)||(this._undoRedoService.clearUndoRedo(n),this._undoRedoService.clearUndoRedo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))}_moveCursor(e){if(e==null||!Yu.includes(e))return;let t=a.Direction.LEFT;switch(e){case _.KeyCode.ENTER:t=a.Direction.DOWN;break;case _.KeyCode.TAB:t=a.Direction.RIGHT;break;case _.KeyCode.ARROW_DOWN:t=a.Direction.DOWN;break;case _.KeyCode.ARROW_UP:t=a.Direction.UP;break;case _.KeyCode.ARROW_LEFT:t=a.Direction.LEFT;break;case _.KeyCode.ARROW_RIGHT:t=a.Direction.RIGHT;break}e===_.KeyCode.ENTER||e===_.KeyCode.TAB?this._commandService.executeCommand(Qe.id,{keycode:e,direction:t}):this._commandService.executeCommand(Ae.id,{direction:t})}_cursorStateListener(e){const t=this._getEditorObject();if(!(t!=null&&t.document))return;const{document:n}=t;e.add(a.toDisposable(n.onPointerDown$.subscribeEvent(()=>{this._cursorChange===1&&(this._cursorChange=2)})))}_moveInEditor(e,t){let n=a.Direction.LEFT;e===_.KeyCode.ARROW_DOWN?n=a.Direction.DOWN:e===_.KeyCode.ARROW_UP?n=a.Direction.UP:e===_.KeyCode.ARROW_RIGHT&&(n=a.Direction.RIGHT),t?this._commandService.executeCommand(Q.MoveSelectionOperation.id,{direction:n}):this._commandService.executeCommand(Q.MoveCursorOperation.id,{direction:n})}_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(Ee.DocSkeletonManagerService).getSkeleton()}_getEditorViewModel(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(Ee.DocSkeletonManagerService).getViewModel()}_emptyDocumentDataModel(e,t){const n=(l,c)=>{const d=a.Tools.deepClone(l.getSnapshot()),u=this._getEditorViewModel(l.getUnitId());u!=null&&(ah(d.body,t),c&&(d.documentStyle=e),d.drawings={},d.drawingsOrder=[],l.reset(d),u.reset(l))},r=this._getDocumentDataModel();r&&n(r,!0);const s=this._univerInstanceService.getUnit(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);s&&n(s)}},y.EditingRenderController=rh([Re(1,a.Inject(m.SheetsSelectionsService)),Re(2,a.IUndoRedoService),Re(3,a.IContextService),Re(4,P.IRenderManagerService),Re(5,ge),Re(6,Qn),Re(7,a.Inject(q.LexerTreeBuilder)),Re(8,q.IFunctionService),Re(9,a.Inject(Ee.DocSelectionManagerService)),Re(10,a.ICommandService),Re(11,a.Inject(a.LocaleService)),Re(12,Q.IEditorService),Re(13,a.Inject(y.SheetCellEditorResizeService)),Re(14,a.IUniverInstanceService),Re(15,a.Inject(m.SheetInterceptorService))],y.EditingRenderController);function sh(i,o,e,t,n,r){var h,S,g;if((o==null?void 0:o.body)==null)return null;const{body:s}=o;i.t=void 0;const l=s.dataStream;let d=l.substring(l.length-2,l.length)===a.DEFAULT_EMPTY_DOCUMENT_VALUE?l.substring(0,l.length-2):l;const u=t.getCurrentLocale();if(d=qu(d,e,u,n),(h=o.drawingsOrder)!=null&&h.length)i.v="",i.f=null,i.si=null,i.p=o,i.t=a.CellValueType.STRING;else if(i.s&&vd.isTextFormat((g=(S=r==null?void 0:r.get(i.s))==null?void 0:S.n)==null?void 0:g.pattern)){i.v=d,i.f=null,i.si=null,i.p=null,i.t=a.CellValueType.STRING,gr(s)&&s.dataStream!==`\r
2
2
  `&&(i.p=o);const f=Oa(o);f&&(i.s=f)}else if(a.isFormulaString(d)){if(i.f===d)return null;const f=e.checkIfAddBracket(d);for(let p=0;p<f;p++)d+=q.matchToken.CLOSE_BRACKET;i.f=d,i.si=null,i.v=null,i.p=null}else if(ju(d)){const f=Gu(d);i.v=f,i.f=null,i.si=null,i.p=null,i.t=a.CellValueType.FORCE_STRING}else if(gr(s))s.dataStream===`\r
3
3
  `?(i.v="",i.f=null,i.si=null,i.p=null):(i.p=o,i.v=null,i.f=null,i.si=null);else{if(d===""&&i.v==null&&i.p==null)return null;i.v=d,i.f=null,i.si=null,i.p=null;const f=Oa(o);f&&(i.s=f)}return i}function gr(i){const{textRuns:o=[],paragraphs:e=[],customRanges:t,customBlocks:n=[]}=i,r=i.dataStream.replace(/(\r\n)+$/,""),s=["va"];return o.filter(l=>l.st<r.length).some(l=>{var d;return!!(l.ts&&Object.keys(l.ts).some(u=>s.includes(u)))||Object.keys((d=l.ts)!=null?d:{}).length&&l.ed-l.st<r.length})||e.some(l=>l.bullet)||e.length>=2||!!(t!=null&&t.length)||n.length>0}function Oa(i){const{body:o}=i;if(!o)return null;const{textRuns:e=[]}=o;let t={};const n=o.dataStream.replace(`\r
4
4
  `,"");return e.forEach(r=>{const{st:s,ed:l,ts:c}=r;l-s>=n.length&&(t={...t,...c})}),Object.keys(t).length?t:null}function ah(i,o=!1){i.dataStream=a.DEFAULT_EMPTY_DOCUMENT_VALUE,i.textRuns!=null&&(i.textRuns.length===1&&!o?(i.textRuns[0].st=0,i.textRuns[0].ed=1):i.textRuns=void 0),i.paragraphs!=null&&(i.paragraphs=[{startIndex:0}]),i.sectionBreaks!=null&&(i.sectionBreaks=void 0),i.tables!=null&&(i.tables=void 0),i.customRanges!=null&&(i.customRanges=void 0),i.customBlocks!=null&&(i.customBlocks=void 0)}var lh=Object.defineProperty,ch=Object.getOwnPropertyDescriptor,dh=(i,o,e,t)=>{for(var n=t>1?void 0:t?ch(o,e):o,r=i.length-1,s;r>=0;r--)(s=i[r])&&(n=(t?s(o,e,n):s(n))||n);return t&&n&&lh(o,e,n),n},fr=(i,o)=>(e,t)=>o(e,t,i);const Aa=qo.MARK_SELECTION,Ht=a.createIdentifier("univer.mark-selection-service");y.MarkSelectionService=class extends a.Disposable{constructor(e,t,n){super();T(this,"_shapeMap",new Map);this._currentService=e,this._renderManagerService=t,this._themeService=n}addShape(e,t=[],n=Aa){var d;const r=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=(d=r.getActiveSheet())==null?void 0:d.getSheetId();if(!s)return null;const l=a.Tools.generateRandomId(),c={selection:e,subUnitId:s,unitId:r.getUnitId(),zIndex:n,control:null,exits:t};return this._shapeMap.set(l,c),this.refreshShapes(),l}addShapeWithNoFresh(e,t=[],n=Aa){var c;const r=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=(c=r.getActiveSheet())==null?void 0:c.getSheetId();if(!s)return null;const l=a.Tools.generateRandomId();return this._shapeMap.set(l,{selection:e,subUnitId:s,unitId:r.getUnitId(),zIndex:n,control:null,exits:t}),l}refreshShapes(){var r;const e=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!e)return;const t=e.getUnitId(),n=(r=e.getActiveSheet())==null?void 0:r.getSheetId();this._shapeMap.forEach(s=>{var E;const{unitId:l,subUnitId:c,selection:d,control:u,zIndex:h}=s;if(u==null||u.dispose(),l!==t||c!==n)return;const S=this._renderManagerService.getRenderById(l);if(!S)return;const g=(E=this._renderManagerService.withCurrentTypeOfUnit(a.UniverInstanceType.UNIVER_SHEET,y.SheetSkeletonManagerService))==null?void 0:E.getCurrentSkeleton();if(!g)return;const{scene:f}=S,{rowHeaderWidth:p,columnHeaderHeight:C}=g,v=new Fn(f,h,this._themeService,{enableAutoFill:!1,highlightHeader:!1,rowHeaderWidth:p,columnHeaderHeight:C}),b=Me(d,g);v.updateRangeBySelectionWithCoord(b),s.control=v})}getShapeMap(){return this._shapeMap}removeShape(e){const t=this._shapeMap.get(e);if(!t)return;const{control:n}=t;n==null||n.dispose(),this._shapeMap.delete(e)}removeAllShapes(){for(const e of this._shapeMap.values()){const{control:t}=e;t==null||t.dispose()}this._shapeMap.clear()}},y.MarkSelectionService=dh([fr(0,a.IUniverInstanceService),fr(1,P.IRenderManagerService),fr(2,a.Inject(a.ThemeService))],y.MarkSelectionService);function Na(i){return{strokeWidth:1.5,stroke:i.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 Sh(i){const o=i.match(/data-copy-id="([^\s]+)"/);return o&&o[1]?o[1]:null}class gh{constructor(){T(this,"_cache",new a.LRUMap(uh))}set(o,e){this._cache.set(o,e)}get(o){return this._cache.get(o)}del(o){this._cache.delete(o)}clear(){this._cache.clear()}clearWithUnitId(o){this._cache.forEach((e,t)=>{e.unitId===o&&this._cache.delete(t)})}}function Zi(i,o){const e=o!=null?o:i.style,t={},n=i.tagName.toLowerCase();switch(n){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=n==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}return fh(e,t),t}function fh(i,o){if(i instanceof CSSStyleDeclaration)for(let e=0;e<i.length;e++){const t=i[e],n=i.getPropertyValue(t);Da(t,n,o)}else for(const e in i){const t=i[e];Da(e,t,o)}}function Da(i,o,e){switch(i){case"font-family":e.ff=o;break;case"font-size":{const t=Number.parseInt(o);Number.isNaN(t)||(o.endsWith("pt")?e.fs=t:o.endsWith("px")&&(e.fs=t*.75));break}case"font-style":o==="italic"&&(e.it=a.BooleanNumber.TRUE);break;case"font-weight":{(Number(o)>400||o==="bold")&&(e.bl=a.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(o)?e.ul={s:a.BooleanNumber.TRUE}:/overline/.test(o)?e.ol={s:a.BooleanNumber.TRUE}:/line-through/.test(o)&&(e.st={s:a.BooleanNumber.TRUE});break}case"color":{try{const t=new a.ColorKit(o);t.isValid&&(e.cl={rgb:t.toRgbString()})}catch{}break}case"background-color":{const t=new a.ColorKit(o),n=t.isValid?t.toRgbString():"";n!==_.DEFAULT_BACKGROUND_COLOR_RGB&&n!==_.DEFAULT_BACKGROUND_COLOR_RGBA&&(e.bg={rgb:n});break}}}function ph(i){const o=document.createElement("body");return o.innerHTML=i,o}function Ha(i){const o=i.style,e={};for(let t=0;t<o.length;t++){const n=o[t],r=o.getPropertyValue(n);switch(n){case"margin-top":{const s=Number.parseInt(r);e.spaceAbove={v:/pt/.test(r)?P.ptToPixel(s):s};break}case"margin-bottom":{const s=Number.parseInt(r);e.spaceBelow={v:/pt/.test(r)?P.ptToPixel(s):s};break}case"line-height":{const s=Number.parseFloat(r);e.lineSpacing=s;break}}}return Object.getOwnPropertyNames(e).length?e:null}function pr(i,o){const e=[];for(let t=0,n=i.length;t<n;t++)i[t]===a.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});return e}function ka(i,o,e){var s,l,c;const t=o.length,r=((s=e==null?void 0:e.length)!=null?s:0)===1&&e[0].st===0&&e[0].ed===t;return i.p?r&&((c=(l=i.p.body)==null?void 0:l.textRuns)!=null&&c.length)?(i.p.body.textRuns=[],{...i,s:e[0].ts}):i:r?{...i,s:e[0].ts}:i}const Va=["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 Wa(i,o){const e=i.tagName.toLowerCase();return typeof o=="string"?e===o:Array.isArray(o)?o.some(t=>t===e):o(i)}const zo=class zo{constructor(o){T(this,"_styleMap",new Map);T(this,"_styleCache",new Map);T(this,"_styleRules",[]);T(this,"_afterProcessRules",[]);T(this,"_dom",null);T(this,"_getCurrentSkeleton");this._getCurrentSkeleton=o.getCurrentSkeleton}static use(o){if(this._pluginList.includes(o))throw new Error(`Univer paste plugin ${o.name} already added`);this._pluginList.push(o)}convert(o){const e=zo._pluginList.find(p=>p.checkPasteType(o));e&&(this._styleRules=[...e.stylesRules],this._afterProcessRules=[...e.afterProcessRules]);const t=new a.ObjectMatrix;this._dom=ph(o);const n=this._dom.querySelector("style");if(n){const p=document.createElement("div"),C=p.attachShadow({mode:"open"});document.body.appendChild(p),C.appendChild(n);for(const v of n.sheet.cssRules){const b=v,E=b.selectorText,w=b.style;this._styleMap.set(E,w)}n.remove(),p.remove()}const r={dataStream:"",textRuns:[]},s=[],l=[],c=o.match(/<table\b[^>]*>([\s\S]*?)<\/table>/gi),d=[];this.process(null,this._dom.childNodes,r,d);const{paragraphs:u,dataStream:h,textRuns:S,payloads:g,customRanges:f}=r;if(u){const p=u.map(C=>C.startIndex+1);p.unshift(0);for(let C=0;C<p.length;C++){let v;if(C===p.length-1){if(v=`${h.substring(p[C])}\r