@univerjs/sheets-ui 0.15.0-insiders.20260106-79b11f9 → 0.15.0-insiders.20260107-3441c7a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Sd=Object.defineProperty;var pd=(n,o,e)=>o in n?Sd(n,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[o]=e;var E=(n,o,e)=>pd(n,typeof o!="symbol"?o+"":o,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const J=require("@univerjs/docs-ui"),a=require("@univerjs/core"),m=require("@univerjs/sheets"),T=require("@univerjs/engine-render"),O=require("rxjs"),I=require("@univerjs/ui"),_e=require("@univerjs/docs"),W=require("react"),G=require("@univerjs/engine-formula"),b=require("react/jsx-runtime"),z=require("@univerjs/design"),le=require("rxjs/operators"),fd=require("@univerjs/telemetry");function xo(n,o){if(n==null)return;const e=o.getRenderById(n);if(e==null)return;const{mainComponent:t,scene:r,engine:i,components:s}=e,l=t,c=s.get(J.DOCS_VIEW_KEY.BACKGROUND);return{document:l,docBackground:c,scene:r,engine:i}}const xi=[10,400],Ki="RANGE_SELECTOR_COMPONENT_KEY",Oo="EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY";var ue=(n=>(n.MAIN="__SpreadsheetRender__",n.ROW="__SpreadsheetRowHeader__",n.COLUMN="__SpreadsheetColumnHeader__",n.LEFT_TOP="__SpreadsheetLeftTopPlaceholder__",n))(ue||{});const Os=0,eo=1,St=10,vd=11,As=12,pr={id:"sheet.command.set-row-header-width",type:a.CommandType.COMMAND,handler:async(n,o)=>{if(!o)return!1;const e=n.get(T.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:r,size:i}=o,s=e.getRenderById(t);if(s){e.getRenderById(t).with(exports.SheetSkeletonManagerService).setRowHeaderSize(s,r,i);const{components:c}=s,d=c.get(ue.ROW);d&&d.setCustomHeader({headerStyle:{size:i}},r)}return!0}},fr={id:"sheet.command.set-col-header-height",type:a.CommandType.COMMAND,handler:async(n,o)=>{if(!o)return!1;const e=n.get(T.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:r,size:i}=o,s=e.getRenderById(t);if(s){e.getRenderById(t).with(exports.SheetSkeletonManagerService).setColumnHeaderSize(s,r,i);const{components:c}=s,d=c.get(ue.COLUMN);d&&d.setCustomHeader({headerStyle:{size:i}},r)}return!0}},Oi=a.createInterceptorKey("rangeMovePermissionCheck"),Ai=a.createInterceptorKey("rangeFillPermissionCheck");var qi=(n=>(n[n.FORMULA_EDITOR_SHOW=100]="FORMULA_EDITOR_SHOW",n[n.MARK_SELECTION=1e4]="MARK_SELECTION",n))(qi||{});function nt(n){const o=n.getColorFromTheme("primary.600"),e=n.getColorFromTheme("white"),t=new a.ColorKit(o).setAlpha(.07).toRgbString();return{strokeWidth:1,stroke:o,fill:t,widgets:{},widgetSize:6,widgetStrokeWidth:1,widgetStroke:e,autofillSize:6,autofillStrokeWidth:1,autofillStroke:e,rowHeaderFill:t,rowHeaderStroke:o,rowHeaderStrokeWidth:1,columnHeaderFill:t,columnHeaderStroke:o,columnHeaderStrokeWidth:1,expandCornerSize:40}}class Cd{constructor(){E(this,"_startColumn",-1);E(this,"_startRow",-1);E(this,"_endColumn",-1);E(this,"_endRow",-1);E(this,"_startX",0);E(this,"_startY",0);E(this,"_endX",0);E(this,"_endY",0);E(this,"_primary");E(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:r,endRow:i}=this,{startColumn:s,startRow:l,endColumn:c,endRow:d}=o;return e===s&&t===l&&r===c&&i===d}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:r,endColumn:i,endRow:s,startX:l,startY:c,endX:d,endY:u,rangeType:h}=o;this._startColumn=t,this._startRow=r,this._endColumn=i,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 Sn(n,o){const{startRow:e,startColumn:t,endRow:r,endColumn:i,rangeType:s}=o,l=r<e?r:e,c=r<e?e:r,d=i<t?i:t,u=i<t?t:i,h=n.getNoMergeCellWithCoordByIndex(l,d),g=n.getNoMergeCellWithCoordByIndex(c,u);return{startRow:e,startColumn:t,endRow:r,endColumn:i,rangeType:s,startY:(h==null?void 0:h.startY)||0,endY:(g==null?void 0:g.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(g==null?void 0:g.endX)||0}}function Te(n,o){const{range:e,primary:t,style:r}=n,i=Sn(o,e),s=t&&cr(o,t);return{rangeWithCoord:i,primaryWithCoord:s,style:r}}function cr(n,o){const{actualRow:e,actualColumn:t,isMerged:r,isMergedMainCell:i,startRow:s,startColumn:l,endRow:c,endColumn:d}=o,u=n.getNoMergeCellWithCoordByIndex(e,t),h=n.getNoMergeCellWithCoordByIndex(s,l),g=n.getNoMergeCellWithCoordByIndex(c,d);return{actualRow:e,actualColumn:t,isMerged:r,isMergedMainCell:i,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:(g==null?void 0:g.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(g==null?void 0:g.endX)||0}}}const Ds="__SpreadsheetHelperSelectionTempRect",Id=35;class La{constructor(o,e){E(this,"_startOffsetX",0);E(this,"_startOffsetY",0);E(this,"_relativeSelectionPositionRow",0);E(this,"_relativeSelectionPositionColumn",0);E(this,"_relativeSelectionRowLength",0);E(this,"_relativeSelectionColumnLength",0);E(this,"_scenePointerMoveSub");E(this,"_scenePointerUpSub");E(this,"_disabled",!1);E(this,"_helperSelection");E(this,"_scrollTimer");E(this,"_activeViewport");E(this,"_targetSelection",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});E(this,"_isInMergeState",!1);E(this,"_fillControlColors",[]);E(this,"_skeleton");E(this,"_scene");E(this,"_themeService");E(this,"_injector");E(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()}setDisabled(o){this._disabled=o}_getFreeze(){var e,t;return(t=(e=T.withCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET,exports.SheetSkeletonManagerService,this._injector.get(a.IUniverInstanceService),this._injector.get(T.IRenderManagerService)))==null?void 0:e.getCurrentParam())==null?void 0:t.skeleton.getWorksheetConfig().freeze}_isSelectionInViewport(o,e){const t=this._getFreeze()||{startRow:-1,startColumn:-1};switch(e.viewportKey){case T.SHEET_VIEWPORT_KEY.VIEW_MAIN:return o.endRow>=t.startRow&&o.endColumn>=t.startColumn;case T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP:case T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT:return o.endColumn>=t.startColumn&&o.startRow<t.startRow;case T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT:case T.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM:return o.endRow>=t.startRow&&o.startColumn<t.startColumn;case T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP:case T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT:case T.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP:case T.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:r}=this._control;[o,e,t,r].forEach(i=>{i.onPointerEnter$.subscribeEvent(()=>{var l;((l=this._injector.get(ve,a.Quantity.OPTIONAL))==null?void 0:l.interceptor.fetchThroughInterceptors(Oi)(!1,null))!==!1&&i.setCursor(T.CURSOR_TYPE.MOVE)}),i.onPointerLeave$.subscribeEvent(()=>{i.resetCursor()}),i.onPointerDown$.subscribeEvent(this._controlPointerDownHandler.bind(this))})}_controlMoving(o,e){var A;const t=this._scene,r=t.getScrollXYInfoByViewport(T.Vector2.FromArray([o,e])),{scaleX:i,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(o,e,i,s,r),{row:c,column:d}=l,u=this._skeleton.getRowCount()-1,h=this._skeleton.getColumnCount()-1;let g=Math.max(0,c+this._relativeSelectionPositionRow),S=g+this._relativeSelectionRowLength;S>u&&(S=u,S-g<this._relativeSelectionRowLength&&(g=S-this._relativeSelectionRowLength));let p=Math.max(0,d+this._relativeSelectionPositionColumn),f=p+this._relativeSelectionColumnLength;f>h&&(f=h,f-p<this._relativeSelectionColumnLength&&(p=f-this._relativeSelectionColumnLength));const v=this._skeleton.worksheet.getCellInfoInMergeData(g,p),_=Te({range:{startRow:g,endRow:S,startColumn:p,endColumn:f},primary:v,style:null},this._skeleton),R=this._skeleton.getNoMergeCellWithCoordByIndex(g,p),w=this._skeleton.getNoMergeCellWithCoordByIndex(S,f),P=(R==null?void 0:R.startY)||0,y=(w==null?void 0:w.endY)||0,M=(R==null?void 0:R.startX)||0,x=(w==null?void 0:w.endX)||0;(A=this._helperSelection)==null||A.transformByState({left:M,top:P,width:x-M,height:y-P}),this._targetSelection={..._.rangeWithCoord},this._control.selectionMoving$.next(_.rangeWithCoord)}_controlPointerDownHandler(o){const{offsetX:e,offsetY:t}=o,r=this._scene,i=r.getCoordRelativeToViewport(T.Vector2.FromArray([e,t])),{x:s,y:l}=i,c=r.getScrollXYInfoByViewport(i),{scaleX:d,scaleY:u}=r.getAncestorScale(),h=this._skeleton.getCellIndexByOffset(s,l,d,u,c);this._startOffsetX=s,this._startOffsetY=l;const{row:g,column:S}=h,{startRow:p,startColumn:f,endRow:v,endColumn:C}=this._control.model;let _=0,R=0;g<p?_-=1:g>v&&(_+=1),S<f?R-=1:S>C&&(R+=1),this._relativeSelectionPositionRow=p-g+_,this._relativeSelectionPositionColumn=f-S+R,this._relativeSelectionRowLength=v-p,this._relativeSelectionColumnLength=C-f;const w=this._control.currentStyle,P=this._getScale();this.isHelperSelection&&(this._helperSelection=new T.Rect(Ds,{stroke:w.stroke,strokeWidth:w.strokeWidth/P}),r.addObject(this._helperSelection));const y=r.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN),M=T.ScrollTimer.create(r);this._scrollTimer=M,M.startScroll(s,l,y),r.disableObjectsEvent(),this._scenePointerMoveSub=r.onPointerMove$.subscribeEvent(x=>{var V;if(this._disabled)return;const{offsetX:A,offsetY:D}=x;if(((V=this._injector.get(ve,a.Quantity.OPTIONAL))==null?void 0:V.interceptor.fetchThroughInterceptors(Oi)(!1,null))===!1)return;const{x:k,y:H}=r.getCoordRelativeToViewport(T.Vector2.FromArray([A,D]));this._controlMoving(k,H),r.setCursor(T.CURSOR_TYPE.MOVE),M.scrolling(k,H,()=>{this._controlMoving(k,H)})}),this._scenePointerUpSub=r.onPointerUp$.subscribeEvent(()=>{var A,D,N,k;(A=this._helperSelection)==null||A.dispose();const x=this._scene;x.resetCursor(),this._clearObserverEvent(),x.enableObjectsEvent(),(D=this._scrollTimer)==null||D.dispose(),this._control.selectionMoveEnd$.next(this._targetSelection),(k=(N=this._selectionHooks).selectionMoveEnd)==null||k.call(N)})}_initialWidget(){const{topLeftWidget:o,topCenterWidget:e,topRightWidget:t,middleLeftWidget:r,middleRightWidget:i,bottomLeftWidget:s,bottomCenterWidget:l,bottomRightWidget:c}=this._control,d=[T.CURSOR_TYPE.NORTH_WEST_RESIZE,T.CURSOR_TYPE.NORTH_RESIZE,T.CURSOR_TYPE.NORTH_EAST_RESIZE,T.CURSOR_TYPE.WEST_RESIZE,T.CURSOR_TYPE.EAST_RESIZE,T.CURSOR_TYPE.SOUTH_WEST_RESIZE,T.CURSOR_TYPE.SOUTH_RESIZE,T.CURSOR_TYPE.SOUTH_EAST_RESIZE];[o,e,t,r,i,s,l,c].forEach((u,h)=>{u.onPointerEnter$.subscribeEvent(()=>{u.setCursor(d[h])}),u.onPointerLeave$.subscribeEvent(()=>{u.resetCursor()}),u.onPointerDown$.subscribeEvent(g=>{this._widgetPointerDownEvent(g,d[h])})})}_widgetPointerDownEvent(o,e){const t=this._scene,{offsetX:r,offsetY:i}=o,s=t.getCoordRelativeToViewport(T.Vector2.FromArray([r,i])),{x:l,y:c}=s;this._startOffsetX=r,this._startOffsetY=i;const{startRow:d,startColumn:u,endRow:h,endColumn:g}=this._control.model,S=Math.min(d,h),p=Math.min(u,g),f=Math.max(d,h),v=Math.max(u,g);this._relativeSelectionPositionRow=S,this._relativeSelectionPositionColumn=p,this._relativeSelectionRowLength=f-S,this._relativeSelectionColumnLength=v-p,e===T.CURSOR_TYPE.NORTH_WEST_RESIZE?(this._relativeSelectionPositionRow=f,this._relativeSelectionPositionColumn=v):e===T.CURSOR_TYPE.NORTH_RESIZE?this._relativeSelectionPositionRow=f:e===T.CURSOR_TYPE.NORTH_EAST_RESIZE?this._relativeSelectionPositionRow=f:e===T.CURSOR_TYPE.WEST_RESIZE?this._relativeSelectionPositionColumn=v:e===T.CURSOR_TYPE.SOUTH_WEST_RESIZE?this._relativeSelectionPositionColumn=v:e===T.CURSOR_TYPE.SOUTH_RESIZE&&(this._relativeSelectionPositionRow=S);const C=T.ScrollTimer.create(t),_=t.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN);C.startScroll(l,c,_),this._scrollTimer=C,t.disableObjectsEvent(),this._scenePointerMoveSub=t.onPointerMove$.subscribeEvent(R=>{const{offsetX:w,offsetY:P}=R,{x:y,y:M}=t.getCoordRelativeToViewport(T.Vector2.FromArray([w,P]));this._widgetMoving(y,M,e),t.setCursor(e),C.scrolling(y,M,()=>{this._widgetMoving(y,M,e)})}),this._scenePointerUpSub=t.onPointerUp$.subscribeEvent(()=>{var w,P,y;const R=this._scene;R.resetCursor(),this._clearObserverEvent(),R.enableObjectsEvent(),(w=this._scrollTimer)==null||w.dispose(),this._control.selectionScaled$.next(this._targetSelection),(y=(P=this._selectionHooks).selectionMoveEnd)==null||y.call(P)})}_widgetMoving(o,e,t){const r=this._scene,i=r.getScrollXYInfoByViewport(T.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:s,scaleY:l}=r.getAncestorScale(),c=this._skeleton.getCellIndexByOffset(o,e,s,l,i),{row:d,column:u}=c;let h=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,S=d,p=u;t===T.CURSOR_TYPE.NORTH_WEST_RESIZE?(h=d,g=u,S=this._relativeSelectionPositionRow,p=this._relativeSelectionPositionColumn):t===T.CURSOR_TYPE.NORTH_RESIZE?(h=d,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,p=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength):t===T.CURSOR_TYPE.NORTH_EAST_RESIZE?(h=d,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,p=u):t===T.CURSOR_TYPE.WEST_RESIZE?(h=this._relativeSelectionPositionRow,g=u,S=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,p=this._relativeSelectionPositionColumn):t===T.CURSOR_TYPE.EAST_RESIZE?S=this._relativeSelectionPositionRow+this._relativeSelectionRowLength:t===T.CURSOR_TYPE.SOUTH_WEST_RESIZE?(h=this._relativeSelectionPositionRow,g=u,S=d,p=this._relativeSelectionPositionColumn):t===T.CURSOR_TYPE.SOUTH_RESIZE&&(h=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,S=d,p=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength);const f=this._swapPositions(h,g,S,p),v=this._skeleton.getCellWithMergeInfoByIndex(h,g),_=Te({range:f,primary:v,style:null},this._skeleton);this._targetSelection={..._.rangeWithCoord},this._control.updateRangeBySelectionWithCoord(_),this._control.selectionScaling$.next(this._targetSelection)}_initialAutoFill(){const{fillControl:o}=this._control;o.onPointerEnter$.subscribeEvent(e=>{this._injector.get(ve).interceptor.fetchThroughInterceptors(Ai)(!1,{x:e.offsetX,y:e.offsetY,skeleton:this._skeleton,scene:this._scene})&&o.setCursor(T.CURSOR_TYPE.CROSSHAIR)}),o.onPointerLeave$.subscribeEvent(()=>{o.resetCursor()}),o.onPointerDown$.subscribeEvent(this._autoFillForPointerdown.bind(this))}_autoFillMoving(o,e){var D,N,k;const t=this._scene,r=t.getViewportScrollXY(this._activeViewport),{scaleX:i,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(o,e,i,s,r),{row:c,column:d}=l,u=t.getCoordRelativeToViewport(T.Vector2.FromArray([o,e])),h=this._skeleton.getRowCount()-1,g=this._skeleton.getColumnCount()-1;let S=this._relativeSelectionPositionRow,p=this._relativeSelectionPositionColumn,f=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,v=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength,C=!1,_=!0;if((d<p||d>v)&&c>=S&&c<=f){const H=this._fillRuler(d,p,v,this._relativeSelectionColumnLength,g);p=H.startRowOrColumn,v=H.endRowOrColumn,C=H.isLighten,_=!1}else if((c<S||c>f)&&d>=p&&d<=v){const H=this._fillRuler(c,S,f,this._relativeSelectionRowLength,h);S=H.startRowOrColumn,f=H.endRowOrColumn,C=H.isLighten}else if(Math.abs(this._startOffsetX-u.x-r.x)/2>Math.abs(this._startOffsetY-u.y-r.y)){const H=this._fillRuler(d,p,v,this._relativeSelectionColumnLength,g);p=H.startRowOrColumn,v=H.endRowOrColumn,C=H.isLighten,_=!1}else{const H=this._fillRuler(c,S,f,this._relativeSelectionRowLength,h);S=H.startRowOrColumn,f=H.endRowOrColumn,C=H.isLighten}const R=this._skeleton.getNoMergeCellWithCoordByIndex(S,p),w=this._skeleton.getNoMergeCellWithCoordByIndex(f,v),P=(R==null?void 0:R.startY)||0,y=(w==null?void 0:w.endY)||0,M=(R==null?void 0:R.startX)||0,x=(w==null?void 0:w.endX)||0;C?this._controlHandler((H,V)=>{const L=new a.ColorKit(this._fillControlColors[V]).lighten(Id).toRgbString();H.setProps({fill:L})}):this._controlHandler((H,V)=>{H.setProps({fill:this._fillControlColors[V]})});const A=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();S===f&&_===!0||p===v&&_===!1?(D=this._helperSelection)==null||D.hide():((N=this._helperSelection)==null||N.transformByState({left:M-A/2,top:P-A/2,width:x-M,height:y-P}),(k=this._helperSelection)==null||k.show()),this._targetSelection={startY:P,endY:y,startX:M,endX:x,startRow:S,endRow:f,startColumn:p,endColumn:v},this._control.selectionFilling$.next(this._targetSelection)}_autoFillForPointerdown(o){const{offsetX:e,offsetY:t}=o,r=this._scene,i=r.getCoordRelativeToViewport(T.Vector2.FromArray([e,t])),{x:s,y:l}=i;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 g=this._control.currentStyle;let S=g==null?void 0:g.stroke,p=g==null?void 0:g.strokeWidth;const f=nt(this._themeService);S==null&&(S=f.stroke),p==null&&(p=f.strokeWidth);const v=this._getScale();p/=v;const C=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/v,_=new a.ColorKit(S).darken(2).toRgbString();this.isHelperSelection&&(this._helperSelection=new T.Rect(Ds,{stroke:_,strokeWidth:p+C/2}),r.addObject(this._helperSelection)),this._activeViewport=r.getActiveViewportByCoord(T.Vector2.FromArray([e,t]));const R=r.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN),w=T.ScrollTimer.create(r,this._activeViewport.viewportKey===T.SHEET_VIEWPORT_KEY.VIEW_MAIN?T.ScrollTimerType.ALL:T.ScrollTimerType.NONE);w.startScroll(s,l,R),this._scrollTimer=w,r.disableObjectsEvent(),this._controlHandler(P=>{this._fillControlColors.push(P.fill)}),this._scenePointerMoveSub=r.onPointerMove$.subscribeEvent(P=>{var H;const{offsetX:y,offsetY:M}=P,x=r.getActiveViewportByCoord(T.Vector2.FromArray([y,M]));if(!this._injector.get(ve).interceptor.fetchThroughInterceptors(Ai)(!1,{x:o.offsetX,y:o.offsetY,skeleton:this._skeleton,scene:this._scene}))return;const{x:D,y:N}=r.getCoordRelativeToViewport(T.Vector2.FromArray([y,M]));this._autoFillMoving(D,N),r.setCursor(T.CURSOR_TYPE.CROSSHAIR);const k=this._targetSelection;if(R&&x&&((H=this._activeViewport)==null?void 0:H.viewportKey)!==(x==null?void 0:x.viewportKey)){let V;k.startRow!==c?(w.scrollTimerType=T.ScrollTimerType.Y,V={...k,endRow:k.startRow}):k.endRow!==u?(w.scrollTimerType=T.ScrollTimerType.Y,V={...k,startRow:k.endRow}):k.startColumn!==d?(w.scrollTimerType=T.ScrollTimerType.X,V={...k,endColumn:k.startColumn}):(w.scrollTimerType=T.ScrollTimerType.X,V={...k,startColumn:k.endColumn}),this._isSelectionInViewport(V,x)&&(this._viewportMainScrollBarNeedResetPosition(w.scrollTimerType,this._activeViewport.viewportKey,x.viewportKey)&&R.scrollToBarPos({x:w.scrollTimerType===T.ScrollTimerType.X?0:void 0,y:w.scrollTimerType===T.ScrollTimerType.Y?0:void 0}),this._activeViewport=x)}w.scrolling(D,N,()=>{this._autoFillMoving(D,N)})}),this._scenePointerUpSub=r.onPointerUp$.subscribeEvent(()=>{var y,M;(y=this._helperSelection)==null||y.dispose();const P=this._scene;P.resetCursor(),this._clearObserverEvent(),P.enableObjectsEvent(),(M=this._scrollTimer)==null||M.dispose(),this._control.refreshSelectionFilled(this._targetSelection),this._isInMergeState=!1,this._controlHandler((x,A)=>{x.setProps({fill:this._fillControlColors[A]})}),this._fillControlColors=[]})}_viewportMainScrollBarNeedResetPosition(o,e,t){return o===T.ScrollTimerType.X&&(e===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||e===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP)&&(t===T.SHEET_VIEWPORT_KEY.VIEW_MAIN||t===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP)||o===T.ScrollTimerType.Y&&(e===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||e===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP)&&(t===T.SHEET_VIEWPORT_KEY.VIEW_MAIN||t===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)}_hasMergeInRange(o,e,t,r){return this._skeleton.worksheet.getMergedCellRange(o,e,t,r).length>0}_swapPositions(o,e,t,r){const i=Math.min(o,t),s=Math.min(e,r),l=Math.max(o,t),c=Math.max(e,r);return{startRow:i,startColumn:s,endRow:l,endColumn:c}}_controlHandler(o){const{leftControl:e,rightControl:t,topControl:r,bottomControl:i,backgroundControlTop:s,backgroundControlMiddleLeft:l,backgroundControlMiddleRight:c,backgroundControlBottom:d,fillControl:u}=this._control,h=[e,t,r,i,s,l,c,d,u];for(let g=0,S=h.length;g<S;g++){const p=h[g];o(p,g)}}_fillRuler(o,e,t,r,i){let s=!1;if(o<e)if(this._isInMergeState&&o<e){const l=e-o,c=r+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=r+1,d=Math.ceil(l/c);let u=t+d*c;u>i&&(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 Di=(n=>(n.Selection="__SpreadsheetSelectionShape__",n.top="__SpreadsheetSelectionTopControl__",n.bottom="__SpreadsheetSelectionBottomControl__",n.left="__SpreadsheetSelectionShapeLeftControl__",n.right="__SpreadsheetSelectionShapeRightControl__",n.backgroundTop="__SpreadsheetSelectionBackgroundControlTop__",n.backgroundMiddleLeft="__SpreadsheetSelectionBackgroundControlMiddleLeft__",n.backgroundMiddleRight="__SpreadsheetSelectionBackgroundControlMiddleRight__",n.backgroundBottom="__SpreadsheetSelectionBackgroundControlBottom__",n.fill="__SpreadsheetSelectionFillControl__",n.fillTopLeft="__SpreadsheetSelectionFillControlTopLeft__",n.fillBottomRight="__SpreadsheetSelectionFillControlBottomRight__",n.fillTopLeftInner="__SpreadsheetSelectionFillControlTopLeftInner__",n.fillBottomRightInner="__SpreadsheetSelectionFillControlBottomRightInner__",n.lineMain="__SpreadsheetDragLineMainControl__",n.lineContent="__SpreadsheetDragLineContentControl__",n.line="__SpreadsheetDragLineControl__",n.dash="__SpreadsheetDragDashControl__",n.rowHeaderBackground="__SpreadSheetSelectionRowHeaderBackground__",n.rowHeaderBorder="__SpreadSheetSelectionRowHeaderBorder__",n.rowHeaderGroup="__SpreadSheetSelectionRowHeaderGroup__",n.columnHeaderBackground="__SpreadSheetSelectionColumnHeaderBackground__",n.columnHeaderBorder="__SpreadSheetSelectionColumnHeaderBorder__",n.columnHeaderGroup="__SpreadSheetSelectionColumnHeaderGroup__",n.topLeftWidget="__SpreadSheetSelectionTopLeftWidget__",n.topCenterWidget="__SpreadSheetSelectionTopCenterWidget__",n.topRightWidget="__SpreadSheetSelectionTopRightWidget__",n.middleLeftWidget="__SpreadSheetSelectionMiddleLeftWidget__",n.middleRightWidget="__SpreadSheetSelectionMiddleRightWidget__",n.bottomLeftWidget="__SpreadSheetSelectionBottomLeftWidget__",n.bottomCenterWidget="__SpreadSheetSelectionBottomCenterWidget__",n.bottomRightWidget="__SpreadSheetSelectionBottomRightWidget__",n))(Di||{});const Ns=.3;class vr extends a.Disposable{constructor(e,t,r,i){var s,l,c,d;super();E(this,"_isHelperSelection",!0);E(this,"_enableAutoFill",!0);E(this,"_showAutoFill",!1);E(this,"_highlightHeader",!0);E(this,"_selectionRenderModel");E(this,"_leftBorder");E(this,"_rightBorder");E(this,"_topBorder");E(this,"_bottomBorder");E(this,"_backgroundControlTop");E(this,"_backgroundControlBottom");E(this,"_backgroundControlMiddleLeft");E(this,"_backgroundControlMiddleRight");E(this,"_autoFillControl");E(this,"_selectionShapeGroup");E(this,"_rowHeaderBackground");E(this,"_rowHeaderBorder");E(this,"_rowHeaderGroup");E(this,"_columnHeaderBackground");E(this,"_columnHeaderBorder");E(this,"_columnHeaderGroup");E(this,"_dashedRect");E(this,"_topLeftWidget");E(this,"_topCenterWidget");E(this,"_topRightWidget");E(this,"_middleLeftWidget");E(this,"_middleRightWidget");E(this,"_bottomLeftWidget");E(this,"_bottomCenterWidget");E(this,"_bottomRightWidget");E(this,"_defaultStyle");E(this,"_currentStyle");E(this,"_rowHeaderWidth",0);E(this,"_columnHeaderHeight",0);E(this,"_widgetRects",[]);E(this,"_controlExtension");E(this,"_dispose$",new O.BehaviorSubject(this));E(this,"dispose$",this._dispose$.asObservable());E(this,"selectionMoving$",new O.Subject);E(this,"selectionMoveEnd$",new O.Subject);E(this,"selectionScaling$",new O.Subject);E(this,"selectionScaled$",new O.Subject);E(this,"selectionFilling$",new O.Subject);E(this,"_selectionFilled$",new O.Subject);E(this,"selectionFilled$",this._selectionFilled$.asObservable());E(this,"_antLineOffset",0);E(this,"_antRequestNewFrame",-1);this._scene=e,this._zIndex=t,this._themeService=r,this._enableAutoFill=(s=i==null?void 0:i.enableAutoFill)!=null?s:!0,this._highlightHeader=(l=i==null?void 0:i.highlightHeader)!=null?l:!0,this._rowHeaderWidth=(c=i==null?void 0:i.rowHeaderWidth)!=null?c:0,this._columnHeaderHeight=(d=i==null?void 0:i.columnHeaderHeight)!=null?d:0,this._initializeSheetBody(),this._initialHeader()}_initializeSheetBody(){this._defaultStyle=nt(this._themeService),this._currentStyle=nt(this._themeService),this._selectionRenderModel=new Cd;const e=this._zIndex;this._leftBorder=new T.Rect("__SpreadsheetSelectionShapeLeftControl__"+e,{zIndex:e}),this._rightBorder=new T.Rect("__SpreadsheetSelectionShapeRightControl__"+e,{zIndex:e}),this._topBorder=new T.Rect("__SpreadsheetSelectionTopControl__"+e,{zIndex:e}),this._bottomBorder=new T.Rect("__SpreadsheetSelectionBottomControl__"+e,{zIndex:e}),this._backgroundControlTop=new T.Rect("__SpreadsheetSelectionBackgroundControlTop__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlBottom=new T.Rect("__SpreadsheetSelectionBackgroundControlBottom__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleLeft=new T.Rect("__SpreadsheetSelectionBackgroundControlMiddleLeft__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleRight=new T.Rect("__SpreadsheetSelectionBackgroundControlMiddleRight__"+e,{zIndex:e-1,evented:!1}),this._autoFillControl=new T.Rect("__SpreadsheetSelectionFillControl__"+e,{zIndex:e+1}),this._autoFillControl.hide(),this._dashedRect=new T.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 T.Group("__SpreadsheetSelectionShape__"+e,...t,...this._widgetRects),this._selectionShapeGroup.hide(),this._selectionShapeGroup.evented=!1,this._selectionShapeGroup.zIndex=e;const r=this.getScene();r.addObject(this._selectionShapeGroup,eo),this.disposeWithMe(a.toDisposable(r.onTransformChange$.subscribeEvent(i=>{i.type===T.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&(this._updateLayoutOfSelectionControl(this._currentStyle),this._updateControlCoord())})))}_initialHeader(){const e=this._zIndex;this._rowHeaderBackground=new T.Rect("__SpreadSheetSelectionRowHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderBorder=new T.Rect("__SpreadSheetSelectionRowHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderGroup=new T.Group("__SpreadSheetSelectionRowHeaderGroup__"+e,this._rowHeaderBackground,this._rowHeaderBorder),this._rowHeaderGroup.hide(),this._rowHeaderGroup.evented=!1,this._rowHeaderGroup.zIndex=e,this._columnHeaderBackground=new T.Rect("__SpreadSheetSelectionColumnHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderBorder=new T.Rect("__SpreadSheetSelectionColumnHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderGroup=new T.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],vd)}_initialWidget(){const e=this._zIndex;return this._topLeftWidget=new T.Rect("__SpreadSheetSelectionTopLeftWidget__"+e,{zIndex:e+1}),this._topCenterWidget=new T.Rect("__SpreadSheetSelectionTopCenterWidget__"+e,{zIndex:e+1}),this._topRightWidget=new T.Rect("__SpreadSheetSelectionTopRightWidget__"+e,{zIndex:e+1}),this._middleLeftWidget=new T.Rect("__SpreadSheetSelectionMiddleLeftWidget__"+e,{zIndex:e+1}),this._middleRightWidget=new T.Rect("__SpreadSheetSelectionMiddleRightWidget__"+e,{zIndex:e+1}),this._bottomLeftWidget=new T.Rect("__SpreadSheetSelectionBottomLeftWidget__"+e,{zIndex:e+1}),this._bottomCenterWidget=new T.Rect("__SpreadSheetSelectionBottomCenterWidget__"+e,{zIndex:e+1}),this._bottomRightWidget=new T.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 La(this,e)}setControlExtensionDisable(e){this._controlExtension&&this._controlExtension.setDisabled(e)}setEvent(e){this.leftControl.evented=e,this.rightControl.evented=e,this.topControl.evented=e,this.bottomControl.evented=e}refreshSelectionFilled(e){this._selectionFilled$.next(e)}_updateLayoutOfSelectionControl(e){e&&(this.currentStyle=Object.assign({},this._defaultStyle,e));const t=this.currentStyle,{stroke:r,widgets:i,autofillStroke:s,strokeDash:l,isAnimationDash:c}=t;let d=t.autofillSize,u=t.strokeWidth,h=t.autofillStrokeWidth;const g=this._getScale(),S=(u+m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH)/2/g;u/=g,d/=g,h/=g<1?1:g;const p=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/g,f=T.FIX_ONE_PIXEL_BLUR_OFFSET/g,{startX:v,startY:C,endX:_,endY:R}=this._selectionRenderModel;if(this.leftControl.transformByState({height:R-C,left:-S+f,width:u,strokeWidth:p,top:-p/2+f}),this.leftControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.rightControl.transformByState({height:R-C,left:_-v-S+f,width:u,strokeWidth:p,top:-p/2+f}),this.rightControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.topControl.transformByState({width:_-v+u,top:-S+f,left:-S+f,height:u,strokeWidth:p}),this.topControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.bottomControl.transformByState({width:_-v+u,top:R-C-S+f,height:u,left:-S+f,strokeWidth:p}),this.bottomControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),l==null)this.dashedRect.hide(),this._stopAntLineAnimation();else{const w=t.strokeWidth*2/g;this.dashedRect.transformByState({height:R-C,width:_-v,strokeWidth:w,left:-w/2+f,top:-w/2+f}),this.dashedRect.setProps({strokeDashArray:[0,l/g]}),this._stopAntLineAnimation(),c!==!1&&this._startAntLineAnimation(),this.dashedRect.show()}if(this._showAutoFill=this._showAutoFill&&this._enableAutoFill,this._showAutoFill&&!this._hasWidgets(i)){const w={fill:r,stroke:s,strokeScaleEnabled:!1},P={width:d-h,height:d-h,left:_-v-d/2+h/2-f,top:R-C-d/2+h/2-f,strokeWidth:h};this._autoFillControl.setProps(w),this._autoFillControl.transformByState(P),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.rowHeaderWidth,this._columnHeaderHeight=t.columnHeaderHeight),this._selectionRenderModel.setValue(e.rangeWithCoord,e.primaryWithCoord),this._showAutoFill=e.primaryWithCoord!==null,this._updateLayoutOfSelectionControl(e.style),this._updateControlCoord()}update(e,t=0,r=0,i,s){this._rowHeaderWidth=t,this._columnHeaderHeight=r,this.updateRangeBySelectionWithCoord({rangeWithCoord:e,primaryWithCoord:s,style:i}),i&&this.updateStyle(i)}updateCurrCell(e){this._showAutoFill=e!==null,this._selectionRenderModel.setCurrentCell(e)}clearHighlight(){this._showAutoFill=!1,this._selectionRenderModel.clearCurrentCell(),this._updateLayoutOfSelectionControl(this._currentStyle)}getScene(){return this._scene}dispose(){var e,t,r,i,s,l,c,d,u,h,g,S,p,f,v,C,_,R,w,P,y,M,x,A,D;(e=this._leftBorder)==null||e.dispose(),(t=this._rightBorder)==null||t.dispose(),(r=this._topBorder)==null||r.dispose(),(i=this._bottomBorder)==null||i.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(),(g=this._rowHeaderBorder)==null||g.dispose(),(S=this._rowHeaderGroup)==null||S.dispose(),(p=this._rowHeaderBackground)==null||p.dispose(),(f=this._columnHeaderBackground)==null||f.dispose(),(v=this._columnHeaderBorder)==null||v.dispose(),(C=this._columnHeaderGroup)==null||C.dispose(),(_=this._topLeftWidget)==null||_.dispose(),(R=this._topCenterWidget)==null||R.dispose(),(w=this._topRightWidget)==null||w.dispose(),(P=this._middleLeftWidget)==null||P.dispose(),(y=this._middleRightWidget)==null||y.dispose(),(M=this._bottomLeftWidget)==null||M.dispose(),(x=this._bottomCenterWidget)==null||x.dispose(),(A=this._bottomRightWidget)==null||A.dispose(),(D=this._controlExtension)==null||D.dispose(),super.dispose(),this._dispose$.next(this),this._dispose$.complete()}getCurrentCellInfo(){const e=this.model.currentCell;if(e){let t;if(e.isMerged){const r=e.mergeInfo;t={startRow:r.startRow,endRow:r.endRow,startColumn:r.startColumn,endColumn:r.endColumn,startX:r.startX,endX:r.endX,startY:r.startY,endY:r.endY}}else{const{actualRow:r,actualColumn:i,startX:s,endX:l,startY:c,endY:d}=e;t={startRow:r,endRow:r,startColumn:i,endColumn:i,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:r,endX:i,endY:s,rangeType:l}=this._selectionRenderModel,c=this._currentStyle,d=this._getScale(),{stroke:u,rowHeaderFill:h=c.rowHeaderFill,rowHeaderStroke:g=c.rowHeaderStroke,columnHeaderFill:S=c.columnHeaderFill,columnHeaderStroke:p=c.columnHeaderStroke}=e;let{rowHeaderStrokeWidth:f=c.rowHeaderStrokeWidth,columnHeaderStrokeWidth:v=c.columnHeaderStrokeWidth}=e;f/=d,v/=d;const C=this._rowHeaderWidth,_=this._columnHeaderHeight;if(this._highlightHeader&&_>0){let R=S;l===a.RANGE_TYPE.COLUMN&&(R=new a.ColorKit(u).setAlpha(Ns).toString()),this._columnHeaderBackground.setProps({fill:R}),this._columnHeaderBackground.resize(i-t,_),this._columnHeaderBorder.setProps({fill:p}),this._columnHeaderBorder.transformByState({width:i-t,height:v,top:_-v+1/d}),this._columnHeaderGroup.show(),this._columnHeaderGroup.translate(t,0)}else this._columnHeaderGroup.hide();if(this._columnHeaderGroup.makeDirty(!0),this._highlightHeader&&C>0){let R=h;l===a.RANGE_TYPE.ROW&&(R=new a.ColorKit(u).setAlpha(Ns).toString()),this._rowHeaderBackground.setProps({fill:R}),this._rowHeaderBackground.resize(C,s-r),this._rowHeaderBorder.setProps({fill:g}),this._rowHeaderBorder.transformByState({width:f,height:s-r,left:C-f+1/d}),this._rowHeaderGroup.show(),this._rowHeaderGroup.translate(0,r)}else this._rowHeaderGroup.hide();this._rowHeaderGroup.makeDirty(!0)}_updateBackgroundControl(e){const{startX:t,startY:r,endX:i,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(i-t,s-r),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:g,endX:S,endY:p}=u,f=d/2,v={left:-f,top:-f,width:i-t+f*2,height:g-r+f};v.height<0&&(v.width=0,v.height=0),this._backgroundControlTop.transformByState(v);const C={left:-f,top:g-r,width:h-t+f,height:p-g};C.width<0&&(C.width=0,C.height=0),this._backgroundControlMiddleLeft.transformByState(C);const _={left:S-t-f,top:g-r,width:i-S+f*2,height:p-g};_.width<0&&(_.width=0,_.height=0),this._backgroundControlMiddleRight.transformByState(_);const R={left:-f,top:p-r,width:i-t+f*2,height:s-p+f};R.height<0&&(R.width=0,R.height=0),this._backgroundControlBottom.transformByState(R),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:r,endX:i,endY:s}=this._selectionRenderModel,{stroke:l=e.stroke,widgets:c=e.widgets,widgetStroke:d=e.widgetStroke}=e,u=this._getScale();let{widgetSize:h,widgetStrokeWidth:g}=e;h/=u,g/=u;const S={left:-h/2+g/2,center:(i-t)/2-h/2+g/2,right:i-t-h/2+g/2,top:-h/2,middle:(s-r)/2-h/2,bottom:s-r-h/2+g/2},p=h-g;this._widgetRects.forEach(f=>{f.setProps({fill:l,stroke:d})}),c.tl===!0?(this._topLeftWidget.transformByState({height:p,width:p,left:S.left,top:S.top,strokeWidth:g}),this._topLeftWidget.show()):this._topLeftWidget.hide(),c.tc===!0?(this._topCenterWidget.transformByState({height:p,width:p,left:S.center,top:S.top,strokeWidth:g}),this._topCenterWidget.show()):this._topCenterWidget.hide(),c.tr===!0?(this._topRightWidget.transformByState({height:p,width:p,left:S.right,top:S.top,strokeWidth:g}),this._topRightWidget.show()):this._topRightWidget.hide(),c.ml===!0?(this._middleLeftWidget.transformByState({height:p,width:p,left:S.left,top:S.middle,strokeWidth:g}),this._middleLeftWidget.show()):this._middleLeftWidget.hide(),c.mr===!0?(this._middleRightWidget.transformByState({height:p,width:p,left:S.right,top:S.middle,strokeWidth:g}),this._middleRightWidget.show()):this._middleRightWidget.hide(),c.bl===!0?(this._bottomLeftWidget.transformByState({height:p,width:p,left:S.left,top:S.bottom,strokeWidth:g}),this._bottomLeftWidget.show()):this._bottomLeftWidget.hide(),c.bc===!0?(this._bottomCenterWidget.transformByState({height:p,width:p,left:S.center,top:S.bottom,strokeWidth:g}),this._bottomCenterWidget.show()):this._bottomCenterWidget.hide(),c.br===!0?(this._bottomRightWidget.transformByState({height:p,width:p,left:S.right,top:S.bottom,strokeWidth:g}),this._bottomRightWidget.show()):this._bottomRightWidget.hide()}_hasWidgets(e){if(e==null)return!1;const t=Object.keys(e);if(t.length===0)return!1;for(const r of t)if(e[r]===!0)return!0;return!1}_getScale(){const{scaleX:e,scaleY:t}=this._scene.getAncestorScale();return Math.max(e,t)}_stopAntLineAnimation(){this._antLineOffset=0,T.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=T.requestNewFrame(()=>{this._startAntLineAnimation()})}}class _d extends T.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 ve=a.createIdentifier("univer.sheet.selection-render-service");class Qi extends a.Disposable{constructor(e,t,r,i,s){super();E(this,"_downObserver");E(this,"_scenePointerMoveSub");E(this,"_scenePointerUpSub");E(this,"_controlFillConfig$",new O.BehaviorSubject(null));E(this,"controlFillConfig$",this._controlFillConfig$.asObservable());E(this,"_selectionControls",[]);E(this,"_startRangeWhenPointerDown",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});E(this,"_activeControlIndex",-1);E(this,"_startViewportPosX",0);E(this,"_startViewportPosY",0);E(this,"_scrollTimer");E(this,"_cancelDownSubscription");E(this,"_cancelUpSubscription");E(this,"_skeleton");E(this,"_scene");E(this,"_highlightHeader",!0);E(this,"_rangeType",a.RANGE_TYPE.NORMAL);E(this,"_selectionStyle");E(this,"_remainLastEnabled",!1);E(this,"_skipLastEnabled",!1);E(this,"_singleSelectionEnabled",!1);E(this,"_selectionMoveEnd$",new O.BehaviorSubject([]));E(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());E(this,"_selectionMoving$",new O.Subject);E(this,"selectionMoving$",this._selectionMoving$.asObservable());E(this,"_selectionMoveStart$",new O.Subject);E(this,"selectionMoveStart$",this._selectionMoveStart$.asObservable());E(this,"_selectionMoving",!1);E(this,"_selectionTheme");E(this,"_activeViewport");E(this,"interceptor",new a.InterceptorManager({RANGE_MOVE_PERMISSION_CHECK:Oi,RANGE_FILL_PERMISSION_CHECK:Ai}));E(this,"_escapeShortcutDisposable",null);this._injector=e,this._themeService=t,this._shortcutService=r,this._sheetSkeletonManagerService=i,this.contextService=s,this._initSelectionThemeFromThemeService(),this._initMoving()}get selectionMoving(){return this._selectionMoving}get _shouldDetectMergedCells(){return this._rangeType===a.RANGE_TYPE.NORMAL}_initMoving(){this.disposeWithMe(this._selectionMoving$.subscribe(()=>{this._selectionMoving=!0})),this.disposeWithMe(this._selectionMoveEnd$.subscribe(()=>{this._selectionMoving=!1}))}_setSelectionStyle(e){this._selectionStyle=e}getViewPort(){return this._activeViewport}setSingleSelectionEnabled(e=!1){this._singleSelectionEnabled=e}newSelectionControl(e,t,r){const i=this.getSelectionControls().length,{rowHeaderWidth:s,columnHeaderHeight:l}=t,c=new vr(e,i,this._selectionTheme,{highlightHeader:this._highlightHeader,rowHeaderWidth:s,columnHeaderHeight:l});this._selectionControls.push(c);const d=Te(r,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(),r=this._skeleton;if(!(!t||!r)){for(let i=0,s=e.length;i<s;i++){const l=e[i],c=Te(l,this._skeleton),d=t[i];d?d.updateRangeBySelectionWithCoord(c,r):this.isSelectionEnabled()&&this.newSelectionControl(this._scene,r,l)}e.length<t.length&&t.splice(e.length).forEach(s=>s.dispose())}}refreshSelectionMoveStart(){this._selectionMoveStart$.next(this.getSelectionDataWithStyle())}refreshSelectionMoveEnd(){this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}_initSelectionThemeFromThemeService(){const e=this._themeService.getCurrentTheme();this._selectionTheme=new a.ThemeService,this._selectionTheme.setTheme(e)}setSelectionTheme(e){this._selectionTheme.setTheme(e)}_changeRuntime(e,t,r){this._skeleton=e,this._scene=t,this._activeViewport=r||(t==null?void 0:t.getViewports()[0]),t.findLayerByZIndex(eo)||t.addLayer(new _d(t,[],eo))}getSkeleton(){return this._skeleton}getSelectionDataWithStyle(){const e=this._selectionControls;if(this._skeleton.worksheet){const[t,r]=this._skeleton.getLocation();return e.map(i=>{const s=i.getValue();return s.rangeWithCoord.sheetId=r,s.rangeWithCoord.unitId=t,s})}return[]}getSelectionControls(){return this._selectionControls}_addSelectionControlByModelData(e){var l;const t=this._skeleton,r=(l=e.style)!=null?l:nt(this._selectionTheme),i=this._scene;return e.style=r,this.newSelectionControl(i,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 r=this._getFreeze();if(!r||r.startRow<=0&&r.startColumn<=0)return this._scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e>r.startRow&&t>r.startColumn)return this._scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e<=r.startRow&&t<=r.startColumn)return this._scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP);if(e<=r.startRow&&t>r.startColumn)return this._scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(e>r.startRow&&t<=r.startColumn)return this._scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)}getActiveRange(){const e=this.getSelectionControls(),t=e&&e[e.length-1].model;return t&&{startRow:t.startRow,startColumn:t.startColumn,endRow:t.endRow,endColumn:t.endColumn}}setActiveSelectionIndex(e){this._activeControlIndex=e}resetActiveSelectionIndex(){this._activeControlIndex=-1}getActiveSelectionControl(){const e=this.getSelectionControls();if(e)return this._activeControlIndex<0?e[e.length-1]:e[this._activeControlIndex]}endSelection(){var e;this._clearUpdatingListeners(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),(e=this._escapeShortcutDisposable)==null||e.dispose(),this._escapeShortcutDisposable=null}_reset(){var e;this._clearAllSelectionControls(),(e=this._downObserver)==null||e.unsubscribe(),this._downObserver=null}_setupPointerMoveListener(e,t,r,i=T.ScrollTimerType.ALL,s,l){var p,f;let c=0,d=0,u=s,h=l;this._scrollTimer=T.ScrollTimer.create(this._scene,i),this._scrollTimer.startScroll((p=e==null?void 0:e.left)!=null?p:0,(f=e==null?void 0:e.top)!=null?f:0,e);const g=this._scene,S=g.getActiveViewportByCoord(T.Vector2.FromArray([s,l]));this._scenePointerMoveSub=g.onPointerMove$.subscribeEvent(v=>{var k,H,V,L,U,B,F,j,X;const{offsetX:C,offsetY:_}=v,{x:R,y:w}=g.getCoordRelativeToViewport(T.Vector2.FromArray([C,_]));this._movingHandler(R,w,t,r);let P=R,y=w;const M=this.getActiveSelectionControl(),x=this._getFreeze(),A=M==null?void 0:M.model,D=(k=g.getActiveViewportByCoord(T.Vector2.FromArray([C,_])))!=null?k:this._getViewportByCell(A==null?void 0:A.endRow,A==null?void 0:A.endColumn);if((()=>{if(!S||!D||!e)return!1;const K=[T.SHEET_VIEWPORT_KEY.VIEW_MAIN,T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT];return K.includes(S.viewportKey)&&K.includes(D.viewportKey)})()){if(!S||!D||!e)return!1;const K=u<e.left&&R>e.left||u>e.left&&R<e.left,re=h<e.top&&w>e.top||h>e.top&&w<e.top;K&&(c+=1),re&&(d+=1);const oe=S.viewportKey,ae=D.viewportKey;if(oe===T.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP)_<e.top&&((H=A==null?void 0:A.endRow)!=null?H:0)<((V=x==null?void 0:x.startRow)!=null?V:0)?y=e.top:re&&d%2===1&&e.scrollToViewportPos({viewportScrollY:0});else if(oe===T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT)C<e.left&&((L=A==null?void 0:A.endColumn)!=null?L:0)<((U=x==null?void 0:x.startColumn)!=null?U:0)?P=e.left:K&&c%2===1&&e.scrollToViewportPos({viewportScrollX:0});else if(oe===ae){let Z=!1,Y=!1;oe===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP?(Z=!0,Y=!0):oe===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP?Y=!0:oe===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT&&(Z=!0),((B=A==null?void 0:A.endRow)!=null?B:0)>((F=x==null?void 0:x.startRow)!=null?F:0)&&(Y=!1),((j=A==null?void 0:A.endColumn)!=null?j:0)>((X=x==null?void 0:x.startColumn)!=null?X:0)&&(Z=!1),Z&&(P=e.left),Y&&(y=e.top)}else{const Z={x:S.scrollX,y:S.scrollY},Y={x:D.scrollX,y:D.scrollY},q=Z.x!==Y.x&&K&&c%2===1,ne=Z.y!==Y.y&&re&&d%2===1;(q||ne)&&(e.scrollToBarPos({x:q?Z.x:void 0,y:ne?Z.y:void 0}),q||(P=e.left),ne||(y=e.top)),(oe===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&ae===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||ae===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&oe===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)&&(P=e.left),(oe===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&ae===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||ae===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&oe===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP)&&(y=e.top)}u=R,h=w}this._scrollTimer.scrolling(P,y,()=>{this._movingHandler(R,w,t,r)})})}attachSelectionWithCoord(e){return Te(e,this._skeleton)}attachPrimaryWithCoord(e){return cr(this._skeleton,e)}getSelectionCellByPosition(e,t){return this.getCellWithCoordByOffset(e,t)}getCellWithCoordByOffset(e,t,r){const i=this._scene,s=r!=null?r:this._skeleton,l=i.getViewportScrollXY(i.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:c,scaleY:d}=i.getAncestorScale();return s.getCellWithCoordByOffset(e,t,c,d,l)}_movingHandler(e,t,r,i){var P,y,M,x,A;const s=this._skeleton,l=this._scene,[c,d]=s.getLocation(),u={startRow:(P=r==null?void 0:r.model.startRow)!=null?P:-1,endRow:(y=r==null?void 0:r.model.endRow)!=null?y:-1,startColumn:(M=r==null?void 0:r.model.startColumn)!=null?M:-1,endColumn:(x=r==null?void 0:r.model.endColumn)!=null?x:-1},h=l.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=(A=this._getViewportByCell(u.endRow,u.endColumn))!=null?A:h,S=l.getScrollXYInfoByViewport(T.Vector2.FromArray([this._startViewportPosX,this._startViewportPosY]),g),{scaleX:p,scaleY:f}=l.getAncestorScale();i===a.RANGE_TYPE.ROW?e=Number.POSITIVE_INFINITY:i===a.RANGE_TYPE.COLUMN&&(t=Number.POSITIVE_INFINITY);const v=this._skeleton.getCellByOffset(e,t,p,f,S);if(!v)return;let C={startRow:Math.min(v.startRow,this._startRangeWhenPointerDown.startRow),startColumn:Math.min(v.startColumn,this._startRangeWhenPointerDown.startColumn),endRow:Math.max(v.endRow,this._startRangeWhenPointerDown.endRow),endColumn:Math.max(v.endColumn,this._startRangeWhenPointerDown.endColumn)};this._shouldDetectMergedCells&&(C=s.expandRangeByMerge(C,this.inRefSelectionMode()));const R=Te({range:C,primary:void 0,style:null},s);R.rangeWithCoord.unitId=c,R.rangeWithCoord.sheetId=d,R.rangeWithCoord.rangeType=i;const w=u.startRow!==C.startRow||u.startColumn!==C.startColumn||u.endRow!==C.endRow||u.endColumn!==C.endColumn;r!=null&&w&&(r.updateRangeBySelectionWithCoord(R),this._selectionMoving$.next(this.getSelectionDataWithStyle()))}_clearUpdatingListeners(){var t,r,i,s,l;this._scene.enableObjectsEvent(),(t=this._scenePointerMoveSub)==null||t.unsubscribe(),this._scenePointerMoveSub=null,(r=this._scenePointerUpSub)==null||r.unsubscribe(),this._scenePointerUpSub=null,(i=this._cancelDownSubscription)==null||i.unsubscribe(),this._cancelDownSubscription=null,(s=this._cancelUpSubscription)==null||s.unsubscribe(),this._cancelUpSubscription=null,(l=this._scrollTimer)==null||l.dispose()}_addEndingListeners(){var r,i,s;const e=this._scene,t=(r=e.getEngine())==null?void 0:r.activeScene;!t||t===e||((i=this._cancelDownSubscription)==null||i.unsubscribe(),this._cancelDownSubscription=null,(s=this._cancelUpSubscription)==null||s.unsubscribe(),this._cancelUpSubscription=null,this._cancelDownSubscription=t.onPointerDown$.subscribeEvent(()=>this._clearUpdatingListeners()),this._cancelUpSubscription=t.onPointerUp$.subscribeEvent(()=>this._clearUpdatingListeners()))}_getSelectionWithCoordByOffset(e,t,r,i,s){const l=this._skeleton;if(l==null)return null;if(this._shouldDetectMergedCells){const C=l==null?void 0:l.getCellWithCoordByOffset(e,t,r,i,s,{firstMatch:!0});if(!C)return;const _=a.convertCellToRange(C);return{primaryWithCoord:C,rangeWithCoord:_}}const{row:c,column:d}=l.getCellIndexByOffset(e,t,r,i,s),u=l.getNoMergeCellWithCoordByIndex(c,d),{startX:h,startY:g,endX:S,endY:p}=u,f={startY:g,endY:p,startX:h,endX:S,startRow:c,endRow:c,startColumn:d,endColumn:d};return{primaryWithCoord:{mergeInfo:f,actualRow:c,actualColumn:d,isMerged:!1,isMergedMainCell:!1,startY:g,endY:p,startX:h,endX:S},rangeWithCoord:f}}_checkClearPreviousControls(e){this.getSelectionControls().length!==0&&(!e.ctrlKey&&!e.shiftKey&&!this._remainLastEnabled||this._singleSelectionEnabled&&!e.shiftKey)&&this._clearAllSelectionControls()}_makeSelectionByTwoCells(e,t,r,i,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),g=Math.min(c,t.startColumn,d.startColumn),S=Math.max(c,t.endColumn,d.endColumn),f={range:r.expandRangeByMerge({startRow:u,startColumn:g,endRow:h,endColumn:S}),primary:m.convertPrimaryWithCoordToPrimary(e),style:null},v=Te(f,r);s.updateRangeBySelectionWithCoord(v)}isSelectionEnabled(){return this.contextService.getContextValue(m.SELECTIONS_ENABLED)}isSelectionDisabled(){return this.contextService.getContextValue(m.SELECTIONS_ENABLED)===!1}inRefSelectionMode(){return this.contextService.getContextValue(m.REF_SELECTIONS_ENABLED)}}function Ji(n){return{range:{startRow:0,startColumn:0,endRow:n.getRowCount()-1,endColumn:n.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL},primary:Ao(n).primary,style:null}}function Ao(n){return Ua(n,{startRow:0,startColumn:0,endRow:0,endColumn:0})}function Ua(n,o){const e=n.worksheet.getCellInfoInMergeData(o.startRow,o.startColumn),t=n.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 bd=Object.getOwnPropertyDescriptor,Rd=(n,o,e,t)=>{for(var r=t>1?void 0:t?bd(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},ks=(n,o)=>(e,t)=>o(e,t,n);exports.SheetSkeletonManagerService=class extends a.Disposable{constructor(e,t,r){super();E(this,"_sheetId","");E(this,"_sheetSkeletonParamStore",new Map);E(this,"_currentSkeleton$",new O.BehaviorSubject(null));E(this,"currentSkeleton$",this._currentSkeleton$.asObservable());E(this,"_currentSkeletonBefore$",new O.BehaviorSubject(null));E(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._context=e,this._injector=t,this._sheetSkService=r,this.disposeWithMe(()=>{this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._sheetSkeletonParamStore.forEach(i=>this.disposeSkeleton(i.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 r=this._getSkeletonParam(t);return r!=null&&(r.unitId=e),r}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),r=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:r,sheetId:e,skeleton:d,dirty:!1})}const i=this._getSkeletonParam(e);this._currentSkeletonBefore$.next(i),this._currentSkeleton$.next(i)}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 r=this._getSkeletonParam(e.sheetId);r!=null&&(r.dirty=t)}getOrCreateSkeleton(e){return this.ensureSkeleton(e.sheetId)}ensureSkeleton(e){const t=this._getSkeletonParam(e);if(t)return t.skeleton;const i=this._context.unit.getSheetBySheetId(e);if(!i)return;const s=this._buildSkeleton(i);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?Sn(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(T.SpreadsheetSkeleton,e,this._context.unit.getStyles())}setColumnHeaderSize(e,t,r){var u;if(!e)return;const i=(u=this.getWorksheetSkeleton(t))==null?void 0:u.skeleton;if(!i)return;i.columnHeaderHeight=r,e.scene.getViewports()[0].top=r,e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({height:r}),e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({height:r}),e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({top:r}),e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({top:r}),e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({height:r});const s=e==null?void 0:e.with(m.SheetsSelectionsService),l=e==null?void 0:e.with(ve),c=s.getCurrentSelections();l.resetSelectionsByModelData(c);const d=this.getUnitSkeleton(e.unitId,t);d&&(d.commandId=fr.id,this._currentSkeleton$.next(d))}setRowHeaderSize(e,t,r){var p;const i=(p=this.getWorksheetSkeleton(t))==null?void 0:p.skeleton;if(!e||!i)return;i.rowHeaderWidth=r;const s=e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).width||46,l=r-s,c=e.scene.getViewports()[0].left;e.scene.getViewports()[0].left=c+l,e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({width:r}),e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({width:r}),e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({left:r});const d=e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).left||0;e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({left:d+l}),e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({width:r});const u=e==null?void 0:e.with(m.SheetsSelectionsService),h=e==null?void 0:e.with(ve),g=u.getCurrentSelections();h.resetSelectionsByModelData(g);const S=this.getCurrent();S&&(S.commandId=pr.id,this._currentSkeleton$.next(S))}};exports.SheetSkeletonManagerService=Rd([ks(1,a.Inject(a.Injector)),ks(2,a.Inject(m.SheetSkeletonService))],exports.SheetSkeletonManagerService);var wd=Object.getOwnPropertyDescriptor,Ed=(n,o,e,t)=>{for(var r=t>1?void 0:t?wd(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Gn=(n,o)=>(e,t)=>o(e,t,n);const Ba=["ff","fs","tr","tb"];exports.AutoHeightController=class extends a.Disposable{constructor(o,e,t,r,i){super(),this._renderManagerService=o,this._sheetInterceptorService=e,this._selectionManagerService=t,this._univerInstanceService=r,this._configService=i,this._initialize()}_processLazyAutoHeight(o,e,t,r){if(r!=null&&r.length){const i={id:m.MarkDirtyRowAutoHeightMutation.id,params:{unitId:e,subUnitId:t,ranges:r,id:a.generateRandomId()},options:{onlyLocal:!0}},s={id:m.CancelMarkDirtyRowAutoHeightMutation.id,params:{unitId:e,subUnitId:t,id:i.params.id},options:{onlyLocal:!0}};return{redos:[...o.redos,i],undos:[...o.undos,s]}}return o}getUndoRedoParamsOfAutoHeight(o,e,t){const{_univerInstanceService:r}=this,i=r.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=i.getUnitId();let l=i.getActiveSheet(),c=l.getSheetId();if(e){const f=m.getSheetCommandTarget(r,{unitId:s,subUnitId:e});f&&(l=f.worksheet,c=l.getSheetId())}const u=this._renderManagerService.getRenderById(s).with(exports.SheetSkeletonManagerService).ensureSkeleton(c);if(!u)return{redos:[],undos:[]};const g=u.calculateAutoHeightInRange(o,t).filter(f=>{const{row:v,autoHeight:C}=f;return!(!C||l.getRowHeight(v)===C)});if(g.length===0)return{redos:[],undos:[]};const S={subUnitId:c,unitId:s,rowsAutoHeightInfo:g},p=m.SetWorksheetRowAutoHeightMutationFactory(S,l);return{undos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:p}],redos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:S}]}}_initialize(){this.disposeWithMe(this._sheetInterceptorService.interceptAutoHeight({getMutations:o=>{const{unitId:e,subUnitId:t,ranges:r,autoHeightRanges:i,lazyAutoHeightRanges:s,cellHeights:l}=o,c=this.getUndoRedoParamsOfAutoHeight(i!=null?i:r,t,l);return this._processLazyAutoHeight(c,e,t,s)}}))}};exports.AutoHeightController=Ed([Gn(0,T.IRenderManagerService),Gn(1,a.Inject(m.SheetInterceptorService)),Gn(2,a.Inject(m.SheetsSelectionsService)),Gn(3,a.Inject(a.IUniverInstanceService)),Gn(4,a.IConfigService)],exports.AutoHeightController);function pt(n){const{rows:o,cols:e}=n;return{startRow:o[0],endRow:o[o.length-1],startColumn:e[0],endColumn:e[e.length-1]}}function ft(n){let o=[],e=[];const t=[];return n.forEach(r=>{o=o.concat(r.rows),e=e.concat(r.cols)}),o=Array.from(new Set(o)).sort((r,i)=>r-i),e=Array.from(new Set(e)).sort((r,i)=>r-i),n.forEach(r=>{t.push({startRow:o.findIndex(i=>i===r.rows[0]),endRow:o.findIndex(i=>i===r.rows[r.rows.length-1]),startColumn:e.findIndex(i=>i===r.cols[0]),endColumn:e.findIndex(i=>i===r.cols[r.cols.length-1])})}),{ranges:t,mapFunc:(r,i)=>({row:o[r],col:e[i]})}}function yd(n){const o=new a.ObjectMatrix;return n.forEach(e=>{const{rows:t,cols:r}=e;t.forEach(i=>{r.forEach(s=>{o.setValue(i,s,{v:null,p:null,f:null,si:null,custom:null})})})}),o.getData()}const Ni={零:0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9},to=["零","一","二","三","四","五","六","七","八","九"],Hs=["","万","亿","万亿","亿亿"],Td=["","十","百","千"],Fa={十:{value:10,secUnit:!1},百:{value:100,secUnit:!1},千:{value:1e3,secUnit:!1},万:{value:1e4,secUnit:!0},亿:{value:1e8,secUnit:!0}};function tt(n){if(!n)return 0;let o=0,e=0,t=0,r=!1;const i=n.split("");for(let s=0;s<i.length;s++){const l=Ni[i[s]];if(typeof l<"u")t=l,s===i.length-1&&(e+=t);else{const c=Fa[i[s]],d=c.value;r=c.secUnit,r?(e=(e+t)*d,o+=e,e=0):e+=t*d,t=0}}return o+e}function Md(n){let o="",e="",t=0,r=!0;for(;n>0;){const i=n%10;i===0?r||(r=!0,e=to[i]+e):(r=!1,o=to[i],o+=Td[t],e=o+e),t++,n=Math.floor(n/10)}return e}function Pd(n){let o=0,e="",t="",r=!1;if(n===0)return to[0];for(;n>0;){const i=n%1e4;r&&(t=to[0]+t),e=Md(i),e+=i!==0?Hs[o]:Hs[0],t=e+t,r=i<1e3&&i>0,n=Math.floor(n/1e4),o++}return t}function xd(n){if(!n)return!1;let o=!0;if(n)if(n.length===1)n==="日"||n in Ni?o=!0:o=!1;else{const e=n.split("");for(let t=0;t<e.length;t++)if(!(e[t]in Ni||e[t]in Fa)){o=!1;break}}return o}function Ur(n){if(!n)return{isExtendNumber:!1};const o=/0|([1-9]+[0-9]*)/g,e=o.test(n);if(e){const t=n.match(o);if(t&&t.length>0){const r=t[t.length-1],i=n.lastIndexOf(r),s=n.substr(0,i),l=n.substr(i+r.length);return{isExtendNumber:!0,matchTxt:Number(r),beforeTxt:s,afterTxt:l}}return{isExtendNumber:!1}}return{isExtendNumber:e}}function Od(n){let o;return n.length===2&&(n==="周一"||n==="周二"||n==="周三"||n==="周四"||n==="周五"||n==="周六"||n==="周日")?o=!0:o=!1,o}function Ad(n){let o;return n.length===3&&(n==="星期一"||n==="星期二"||n==="星期三"||n==="星期四"||n==="星期五"||n==="星期六"||n==="星期日")?o=!0:o=!1,o}function Dd(n,o){let e=0;for(let t=0;t<n.length&&n[t]<o;t++)e++;return e}function Cr(n){let o=!0;const e=n[1]-n[0];for(let t=1;t<n.length;t++)if(n[t]-n[t-1]!==e){o=!1;break}return o}function Nd(n,o,e){const t=[],r=Math.floor(o/n),i=o%n;let s=0;if(r>0){for(let l=0;l<r;l++)for(let c=0;c<e.length;c++)t[e[c]+l*n]=s,s++;for(let l=0;l<e.length&&e[l]<i;l++)t[e[l]+n*r]=s,s++}else for(let l=0;l<e.length&&e[l]<i;l++)t[e[l]]=s,s++;return t}function Ht(n,o){const e=[];for(let t=1;t<=o;t++){const r=(t-1)%n.length,i=a.Tools.deepClone(n[r]);Vt(i),e.push({v:null,s:null,p:null,f:null,si:null,t:null,...i})}return e}function kd(n,o){var t;const e=[];for(let r=1;r<=o;r++){const i=(r-1)%n.length,s={s:(t=n[i])==null?void 0:t.s};e.push(s)}return e}function Hd(n){let o=!0;const e=n[1]/n[0];for(let t=1;t<n.length;t++)if(n[t]/n[t-1]!==e){o=!1;break}return o}function Vd(n){const o=[];for(let e=1;e<=n;e++)o.push(e);return o}function no(n,o,e){var i,s,l,c;const t=[],r=[];for(let d=0;d<n.length;d++)r.push(Number((i=n[d])==null?void 0:i.v));if(n.length>2&&Hd(r))for(let d=1;d<=o;d++){const u=(d-1)%n.length,h=a.Tools.deepClone(n[u]);Vt(h);const g=Number((s=n[n.length-1])==null?void 0:s.v)*(Number((l=n[1])==null?void 0:l.v)/Number((c=n[0])==null?void 0:c.v))**d;h&&(Us(h)&&(h.v=g),t.push(h))}else{const d=Vd(n.length);for(let u=1;u<=o;u++){const h=(u-1)%n.length,g=a.Tools.deepClone(n[h]);Vt(g);const S=e===a.Direction.DOWN||e===a.Direction.RIGHT,p=Wd(n.length+u,r,d,S);g&&(Us(g)&&(g.v=p),t.push(g))}}return t}function Wd(n,o,e,t=!0){function r(h){let g=0;for(let S=0;S<h.length;S++)g+=h[S];return g/h.length}const i=r(e),s=r(o);let l=0,c=0;for(let h=0;h<e.length;h++)l+=(e[h]-i)*(o[h]-s),c+=(e[h]-i)*(e[h]-i);let d;c===0?d=t?1:-1:d=l/c;const u=s-d*i;return Math.round((u+d*n)*1e5)/1e5}function Vs(n,o,e){var i;const t=[],r=/0|([1-9]+[0-9]*)/g;for(let s=1;s<=o;s++){const l=(s-1)%n.length,c=a.Tools.deepClone(n[l]);Vt(c);const d=`${(i=n[n.length-1])==null?void 0:i.v}`;if(!d)continue;const u=d==null?void 0:d.match(r),h=u==null?void 0:u[u.length-1];if(!h)continue;const g=Math.abs(Number(h)+e*s),S=d.lastIndexOf(h),p=d.substr(0,S)+g.toString()+d.substr(S+h.length);c&&(c.v=p,t.push(c))}return t}function pn(n,o,e,t=0){var l,c;const r=[["日","一","二","三","四","五","六"],["周日","周一","周二","周三","周四","周五","周六"],["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]];if(t>=r.length)return[];const i=r[t],s=[];for(let d=1;d<=o;d++){const u=(d-1)%n.length,h=a.Tools.deepClone(n[u]);Vt(h);let g=0;if(((l=n[n.length-1])==null?void 0:l.v)===i[0])g=7+e*d;else{const p=`${(c=n[n.length-1])==null?void 0:c.v}`;if(p){const f=p.substr(p.length-1,1);g=tt(f)+e*d}}g<0&&(g=Math.ceil(Math.abs(g)/7)*7+g);const S=g%7;h&&(h.v=i[S],s.push(h))}return s}function Ws(n,o,e){var r;const t=[];for(let i=1;i<=o;i++){const s=(i-1)%n.length,l=a.Tools.deepClone(n[s]);Vt(l);const c=`${(r=n[n.length-1])==null?void 0:r.v}`,d=tt(c)+e*i;let u;d<=0?u="零":u=Pd(d),l&&(l.v=u,t.push(l))}return t}const ir={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 Ld(n){let o=!1;return Object.keys(ir).forEach(e=>{ir[e].includes(n)&&(o=!0)}),o}function zo(n){let o="";const e=[];return Object.keys(ir).forEach(t=>{ir[t].includes(n)&&(o=t,e.push(...ir[t]))}),{name:o,series:e}}function Ls(n,o,e,t){var s;const r=t.length,i=[];for(let l=1;l<=o;l++){const c=(l-1)%n.length,d=a.Tools.deepClone(n[c]);Vt(d);const u=`${(s=n[n.length-1])==null?void 0:s.v}`;let h=t.indexOf(u)+e*l;h<0&&(h+=Math.abs(e)*r);const g=h%r;d&&(d.v=t[g],i.push(d))}return i}function Ud(n,o){const e=[];let t;if(o.startRow<n.startRow)t=a.Direction.UP;else if(o.endRow>n.endRow)t=a.Direction.DOWN;else if(o.startColumn<n.startColumn)t=a.Direction.LEFT;else if(o.endColumn>n.endColumn)t=a.Direction.RIGHT;else return[];if(t===a.Direction.DOWN||t===a.Direction.UP){const r=n.endRow-n.startRow+1,i=o.endRow-o.startRow+1,s=Math.floor(i/r),l=i%r,c={startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:n.endColumn-n.startColumn};if(t===a.Direction.DOWN){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow+(d+1)*r,col:n.startColumn},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow+(s+1)*r,col:n.startColumn},relativeRange:{startRow:0,startColumn:0,endRow:l-1,endColumn:n.endColumn-n.startColumn}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow-(d+1)*r,col:n.startColumn},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow-(s+1)*r,col:n.startColumn},relativeRange:{startRow:r-l,endRow:r-1,startColumn:0,endColumn:n.endColumn-n.startColumn}})}}if(t===a.Direction.RIGHT||t===a.Direction.LEFT){const r=n.endColumn-n.startColumn+1,i=o.endColumn-o.startColumn+1,s=Math.floor(i/r),l=i%r,c={startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:n.endColumn-n.startColumn};if(t===a.Direction.RIGHT){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow,col:n.startColumn+(d+1)*r},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow,col:n.startColumn+(s+1)*r},relativeRange:{startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:l-1}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow,col:n.startColumn-(d+1)*r},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow,col:n.startColumn-(s+1)*r},relativeRange:{startRow:0,startColumn:r-l,endRow:n.endRow-n.startRow,endColumn:r-1}})}}return e}function Us(n){return!(a.isFormulaString(n.f)||a.isFormulaId(n.si)||n.t===a.CellValueType.BOOLEAN)}function Vt(n){n&&"custom"in n&&delete n.custom}var an=(n=>(n.Append="APPEND",n.Default="DEFAULT",n.Only="ONLY",n))(an||{}),Ce=(n=>(n.NUMBER="number",n.DATE="date",n.EXTEND_NUMBER="extendNumber",n.CHN_NUMBER="chnNumber",n.CHN_WEEK2="chnWeek2",n.CHN_WEEK3="chnWeek3",n.LOOP_SERIES="loopSeries",n.FORMULA="formula",n.OTHER="other",n))(Ce||{}),se=(n=>(n.COPY="COPY",n.SERIES="SERIES",n.ONLY_FORMAT="ONLY_FORMAT",n.NO_FORMAT="NO_FORMAT",n))(se||{});const Bd={type:Ce.DATE,priority:1100,match:(n,o)=>{var e;if(n!=null&&n.f||n!=null&&n.si)return!1;if((typeof(n==null?void 0:n.v)=="number"||(n==null?void 0:n.t)===a.CellValueType.NUMBER)&&n.s){if(typeof n.s=="string"){const r=o.get(a.IUniverInstanceService).getFocusedUnit().getStyles().get(n.s),i=(e=r==null?void 0:r.n)==null?void 0:e.pattern;if(i)return a.numfmt.getFormatInfo(i).isDate}else if(n.s.n&&a.numfmt.getFormatInfo(n.s.n.pattern).isDate)return!0}return!1},isContinue:(n,o)=>n.type===Ce.DATE,applyFunctions:{[se.SERIES]:(n,o,e)=>{const{data:t}=n;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),no(t,o,e).reverse()):no(t,o,e)}}},Fd={type:Ce.NUMBER,priority:1e3,match:n=>typeof(n==null?void 0:n.v)=="number"||(n==null?void 0:n.t)===a.CellValueType.NUMBER,isContinue:(n,o)=>n.type===Ce.NUMBER,applyFunctions:{[se.SERIES]:(n,o,e)=>{const{data:t}=n;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),no(t,o,e).reverse()):no(t,o,e)}}},ja={type:Ce.OTHER,priority:0,match:()=>!0,isContinue:(n,o)=>n.type===Ce.OTHER},jd={type:Ce.EXTEND_NUMBER,priority:900,match:n=>Ur(`${n==null?void 0:n.v}`||"").isExtendNumber,isContinue:(n,o)=>{var e;if(n.type===Ce.EXTEND_NUMBER){const{beforeTxt:t,afterTxt:r}=Ur(`${(e=n.cellData)==null?void 0:e.v}`||""),{beforeTxt:i,afterTxt:s}=Ur(`${o==null?void 0:o.v}`||"");if(t===i&&r===s)return!0}return!1},applyFunctions:{[se.SERIES]:(n,o,e)=>{var l;const{data:t}=n,r=e===a.Direction.UP||e===a.Direction.LEFT;let i;if(t.length===1)return i=r?-1:1,De(Vs(t,o,i),r);const s=[];for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`;d&&s.push(Number(Ur(d).matchTxt))}return r&&(t.reverse(),s.reverse()),Cr(s)?(i=s[1]-s[0],De(Vs(t,o,i),r)):Ht(t,o)}}},zd={type:Ce.CHN_NUMBER,priority:830,match:n=>!!xd(`${n==null?void 0:n.v}`||""),isContinue:(n,o)=>n.type===Ce.CHN_NUMBER,applyFunctions:{[se.SERIES]:(n,o,e)=>{var c,d,u;const{data:t}=n,r=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){const h=`${(c=t[0])==null?void 0:c.v}`;let g;return r?g=-1:g=1,h&&(h==="日"||tt(h)<7)?De(pn(t,o,g),r):De(Ws(t,o,g),r)}let i=!1;for(let h=0;h<t.length;h++)if(((d=t[h])==null?void 0:d.v)==="日"){i=!0;break}const s=[];let l=0;for(let h=0;h<t.length;h++){const g=`${(u=t[h])==null?void 0:u.v}`;g==="日"?h===0?s.push(0):(l++,s.push(l*7)):i&&tt(g)>0&&tt(g)<7?s.push(tt(g)+l*7):s.push(tt(g))}if(r&&(t.reverse(),s.reverse()),Cr(s)){if(i||s[s.length-1]<6&&s[0]>0||s[0]<6&&s[s.length-1]>0){const g=s[1]-s[0];return De(pn(t,o,g),r)}const h=s[1]-s[0];return De(Ws(t,o,h),r)}return Ht(t,o)}}},Xd={type:Ce.CHN_WEEK2,priority:820,match:n=>!!Od(`${n==null?void 0:n.v}`||""),isContinue:(n,o)=>n.type===Ce.CHN_WEEK2,applyFunctions:{[se.SERIES]:(n,o,e)=>{var l;const{data:t}=n,r=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let c;return r?c=-1:c=1,De(pn(t,o,c,1),r)}const i=[];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?i.push(0):(s++,i.push(s*7)):i.push(tt(u)+s*7)}if(r&&(t.reverse(),i.reverse()),Cr(i)){const c=i[1]-i[0];return De(pn(t,o,c,1),r)}return Ht(t,o)}}},Yd={type:Ce.CHN_WEEK3,priority:810,match:n=>Ad(`${n==null?void 0:n.v}`||""),isContinue:(n,o)=>n.type===Ce.CHN_WEEK3,applyFunctions:{[se.SERIES]:(n,o,e)=>{var l;const{data:t}=n,r=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let c;return r?c=-1:c=1,De(pn(t,o,c,2),r)}const i=[];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?i.push(0):(s++,i.push(s*7)):i.push(tt(u)+s*7)}}if(r&&(t.reverse(),i.reverse()),Cr(i)){const c=i[1]-i[0];return De(pn(t,o,c,2),r)}return Ht(t,o)}}},Zd={type:Ce.LOOP_SERIES,priority:800,match:n=>Ld(`${n==null?void 0:n.v}`||""),isContinue:(n,o)=>{var e;return n.type===Ce.LOOP_SERIES?zo(`${(e=n.cellData)==null?void 0:e.v}`||"").name===zo(`${o==null?void 0:o.v}`||"").name:!1},applyFunctions:{[se.SERIES]:(n,o,e)=>{var c,d;const{data:t}=n,r=e===a.Direction.LEFT||e===a.Direction.UP,{series:i}=zo(`${(c=t[0])==null?void 0:c.v}`||"");if(t.length===1){let u;return r?u=-1:u=1,De(Ls(t,o,u,i),r)}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===i[0]?u===0?s.push(0):(l++,s.push(l*i.length)):s.push(i.indexOf(h)+l*7))}if(r&&(t.reverse(),s.reverse()),Cr(s)){const u=s[1]-s[0];return De(Ls(t,o,u,i),r)}return Ht(t,o)}}};function De(n,o){return o?n.reverse():n}var Gd=Object.getOwnPropertyDescriptor,Kd=(n,o,e,t)=>{for(var r=t>1?void 0:t?Gd(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Jt=(n,o)=>(e,t)=>o(e,t,n);exports.AutoFillService=class extends a.Disposable{constructor(e,t,r,i,s,l){super();E(this,"_rules",[]);E(this,"_hooks",[]);E(this,"_applyType$",new O.BehaviorSubject(se.SERIES));E(this,"_isFillingStyle",!0);E(this,"_prevUndos",[]);E(this,"_autoFillLocation$",new O.BehaviorSubject(null));E(this,"autoFillLocation$",this._autoFillLocation$.asObservable());E(this,"_showMenu$",new O.BehaviorSubject(!1));E(this,"showMenu$",this._showMenu$.asObservable());E(this,"_direction",a.Direction.DOWN);E(this,"applyType$",this._applyType$.asObservable());E(this,"_menu$",new O.BehaviorSubject([{label:"autoFill.copy",value:se.COPY,disable:!1},{label:"autoFill.series",value:se.SERIES,disable:!1},{label:"autoFill.formatOnly",value:se.ONLY_FORMAT,disable:!1},{label:"autoFill.noFormat",value:se.NO_FORMAT,disable:!1}]));E(this,"menu$",this._menu$.asObservable());this._commandService=e,this._undoRedoService=t,this._renderManagerService=r,this._univerInstanceService=i,this._selectionManagerService=s,this._injector=l,this._init()}_init(){this._rules=[Bd,Fd,jd,zd,Xd,Yd,Zd,ja].sort((e,t)=>t.priority-e.priority),this._isFillingStyle=!0}_getOneByPriority(e){return e.length<=0?[]:[e.reduce((r,i)=>(i.priority||0)>(r.priority||0)?i:r,e[0])]}_initPrevUndo(){this._prevUndos=[]}async triggerAutoFill(e,t,r,i,s){var p;if(r.startColumn===i.startColumn&&r.startRow===i.startRow&&r.endColumn===i.endColumn&&r.endRow===i.endRow)return!1;if(i.endColumn<r.endColumn&&i.endColumn>r.startColumn)return this._commandService.executeCommand(fn.id,{clearRange:{startRow:i.startRow,endRow:i.endRow,startColumn:i.endColumn+1,endColumn:r.endColumn},selectionRange:i});if(i.endRow<r.endRow&&i.endRow>r.startRow)return this._commandService.executeCommand(fn.id,{clearRange:{startRow:i.endRow+1,endRow:r.endRow,startColumn:i.startColumn,endColumn:i.endColumn},selectionRange:i});const l={startRow:i.startRow,endRow:i.endRow,startColumn:i.startColumn,endColumn:i.endColumn};let c=null;if(i.startRow<r.startRow)c=a.Direction.UP,l.endRow=r.startRow-1;else if(i.endRow>r.endRow)c=a.Direction.DOWN,l.startRow=r.endRow+1;else if(i.startColumn<r.startColumn)c=a.Direction.LEFT,l.endColumn=r.startColumn-1;else if(i.endColumn>r.endColumn)c=a.Direction.RIGHT,l.startColumn=r.endColumn+1;else return!1;this.direction=c;const d=this._injector.invoke(f=>m.rangeToDiscreteRange(r,f)),u=this._injector.invoke(f=>m.rangeToDiscreteRange(l,f));if(!d||!u)return!1;this.autoFillLocation={source:d,target:u,unitId:e,subUnitId:t};const h=[];if(this.getActiveHooks().forEach(f=>{var C;const v=(C=f==null?void 0:f.onBeforeFillData)==null?void 0:C.call(f,{source:d,target:u,unitId:e,subUnitId:t},c);v&&h.unshift(v)}),this._initPrevUndo(),s)return this.fillData(s);for(let f=0;f<h.length;f++){const v=this.menu.find(C=>C.value===h[f]);if(v&&!v.disable)return this.fillData(h[f])}const S=(p=this.menu.find(f=>f.disable===!1))==null?void 0:p.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=an.Append),this._hooks.push(e),a.toDisposable(()=>{const t=this._hooks.findIndex(r=>r===e);t>-1&&this._hooks.splice(t,1)})}registerRule(e){if(this._rules.find(r=>r.type===e.type))throw new Error(`Registry rule failed, type '${e.type}' already exist!`);const t=this._rules.findIndex(r=>r.priority<e.priority);this._rules.splice(t===-1?this._rules.length:t,0,e)}getRules(){return this._rules}getAllHooks(){return this._hooks}getActiveHooks(){const{source:e,target:t,unitId:r,subUnitId:i}=this.autoFillLocation||{};if(!e||!t||!r||!i)return[];const s=this._hooks.filter(u=>{var h;return!((h=u.disable)!=null&&h.call(u,{source:e,target:t,unitId:r,subUnitId:i},this._direction,this.applyType))}),l=s.filter(u=>u.type===an.Only);if(l.length>0)return this._getOneByPriority(l);const c=this._getOneByPriority(s.filter(u=>u.type===an.Default)),d=s.filter(u=>u.type===an.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(r=>r.value===e?{...r,disable:t}:r))}setShowMenu(e){this._showMenu$.next(e)}fillData(e){var w,P,y;this.applyType=e;const t=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),r=t==null?void 0:t.getUnitId(),i=(w=t==null?void 0:t.getActiveSheet())==null?void 0:w.getSheetId(),{source:s,target:l,unitId:c=r,subUnitId:d=i}=this.autoFillLocation||{};if(!s||!l||!c||!d)return!1;const u=this.direction;this._prevUndos.length>0&&this._prevUndos.forEach(M=>{this._commandService.syncExecuteCommand(M.id,M.params)}),this._prevUndos=[];const h=a.Rectangle.union(pt(s),pt(l)),g=this.getActiveHooks(),S=this._univerInstanceService.getUnit(c,a.UniverInstanceType.UNIVER_SHEET);c===r&&d===i&&this._commandService.syncExecuteCommand(m.SetSelectionsOperation.id,{selections:[{primary:{...(y=(P=this._selectionManagerService.getCurrentLastSelection())==null?void 0:P.primary)!=null?y:h},range:{...h,rangeType:a.RANGE_TYPE.NORMAL}}],unitId:c,subUnitId:d});const p=[],f=[];g.forEach(M=>{var D;const{undos:x,redos:A}=((D=M.onFillData)==null?void 0:D.call(M,{source:s,target:l,unitId:c,subUnitId:d},u,e))||{};x&&p.push(...x),A&&f.push(...A)});const v=f.every(M=>this._commandService.syncExecuteCommand(M.id,M.params)),C=[];e!==se.NO_FORMAT&&f.forEach(M=>{if(M.id===m.SetRangeValuesMutation.id){const{cellValue:x}=M.params;new a.ObjectMatrix(x).forValue((D,N,k)=>{const H=Object.keys(S.getStyles().get(k==null?void 0:k.s)||{});(k!=null&&k.p||H.length&&Ba.some(V=>H.includes(V)))&&C.push({startRow:D,endRow:D,startColumn:N,endColumn:N})})}});const _=this._getAutoHeightUndoRedos(c,d,C);return _.redos.every(M=>this._commandService.syncExecuteCommand(M.id,M.params))&&(p.push(..._.undos),f.push(..._.redos)),v&&(this._prevUndos=p,this._undoRedoService.pushUndoRedo({unitID:c,undoMutations:p,redoMutations:f})),g.forEach(M=>{var x;(x=M.onAfterFillData)==null||x.call(M,{source:s,target:l,unitId:c,subUnitId:d},u,e)}),this.setShowMenu(!0),!0}_getAutoHeightUndoRedos(e,t,r){var h,g;const i=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(exports.SheetSkeletonManagerService),s=(g=i==null?void 0:i.getCurrentParam())==null?void 0:g.skeleton;if(!s)return{redos:[],undos:[]};const l=s.calculateAutoHeightInRange(r),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}]}}};exports.AutoFillService=Kd([Jt(0,a.ICommandService),Jt(1,a.IUndoRedoService),Jt(2,T.IRenderManagerService),Jt(3,a.Inject(a.IUniverInstanceService)),Jt(4,a.Inject(m.SheetsSelectionsService)),Jt(5,a.Inject(a.Injector))],exports.AutoFillService);const vt=a.createIdentifier("univer.auto-fill-service"),ht={type:a.CommandType.COMMAND,id:"sheet.command.auto-fill",handler:async(n,o)=>{const e=n.get(vt),t=n.get(a.IUniverInstanceService),{sourceRange:r,targetRange:i,applyType:s}=o,l=m.getSheetCommandTarget(t,o);if(!l)return!1;const{subUnitId:c,unitId:d}=l;return e.triggerAutoFill(d,c,r,i,s)}},fn={id:"sheet.command.auto-clear-content",type:a.CommandType.COMMAND,handler:async(n,o)=>{const e=n.get(a.IUniverInstanceService),t=n.get(a.ICommandService),r=n.get(a.IUndoRedoService),i=n.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])},g=m.SetRangeValuesUndoMutationFactory(n,h),{startColumn:S,startRow:p}=u,f={selections:[{primary:{startColumn:S,startRow:p,endColumn:S,endRow:p,actualRow:p,actualColumn:S,isMerged:!1,isMergedMainCell:!1},range:{...u}}],unitId:l,subUnitId:c};if(t.executeCommand(m.SetSelectionsOperation.id,f),t.syncExecuteCommand(m.SetRangeValuesMutation.id,h)){const C=i.afterCommandExecute({id:m.SetRangeValuesMutation.id,params:h});return a.sequenceExecute(C.redos,t),r.pushUndoRedo({unitID:l,undoMutations:[{id:m.SetRangeValuesMutation.id,params:g},...C.undos],redoMutations:[{id:m.SetRangeValuesMutation.id,params:h},...C.redos]}),!0}return!1}};function $i(n){return n.getContextValue(a.FOCUSING_SHEET)}function ie(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function za(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function qd(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function es(n){return n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function Do(n){return n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function Qd(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.EDITOR_ACTIVATED)&&n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function vn(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&!n.getContextValue(a.FOCUSING_EDITOR_STANDALONE)}var Jd=Object.getOwnPropertyDescriptor,$d=(n,o,e,t)=>{for(var r=t>1?void 0:t?Jd(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Xo=(n,o)=>(e,t)=>o(e,t,n);const Bs=qi.MARK_SELECTION,jt=a.createIdentifier("univer.mark-selection-service");exports.MarkSelectionService=class extends a.Disposable{constructor(e,t,r){super();E(this,"_shapeMap",new Map);this._currentService=e,this._renderManagerService=t,this._themeService=r}addShape(e,t=[],r=Bs){var d;const i=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=(d=i.getActiveSheet())==null?void 0:d.getSheetId();if(!s)return null;const l=a.generateRandomId(),c={selection:e,subUnitId:s,unitId:i.getUnitId(),zIndex:r,control:null,exits:t};return this._shapeMap.set(l,c),this.refreshShapes(),l}addShapeWithNoFresh(e,t=[],r=Bs){var c;const i=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=(c=i.getActiveSheet())==null?void 0:c.getSheetId();if(!s)return null;const l=a.generateRandomId();return this._shapeMap.set(l,{selection:e,subUnitId:s,unitId:i.getUnitId(),zIndex:r,control:null,exits:t}),l}refreshShapes(){var i;const e=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!e)return;const t=e.getUnitId(),r=(i=e.getActiveSheet())==null?void 0:i.getSheetId();this._shapeMap.forEach(s=>{const{unitId:l,subUnitId:c,selection:d,control:u,zIndex:h}=s;if(u==null||u.dispose(),l!==t||c!==r)return;const g=this._renderManagerService.getRenderById(l);if(!g)return;const S=g.with(exports.SheetSkeletonManagerService).getCurrentSkeleton();if(!S)return;const{scene:p}=g,{rowHeaderWidth:f,columnHeaderHeight:v}=S,C=new vr(p,h,this._themeService,{enableAutoFill:!1,highlightHeader:!1,rowHeaderWidth:f,columnHeaderHeight:v}),_=Te(d,S);C.updateRangeBySelectionWithCoord(_),s.control=C})}getShapeMap(){return this._shapeMap}removeShape(e){const t=this._shapeMap.get(e);if(!t)return;const{control:r}=t;r==null||r.dispose(),this._shapeMap.delete(e)}removeAllShapes(){for(const e of this._shapeMap.values()){const{control:t}=e;t==null||t.dispose()}this._shapeMap.clear()}};exports.MarkSelectionService=$d([Xo(0,a.IUniverInstanceService),Xo(1,T.IRenderManagerService),Xo(2,a.Inject(a.ThemeService))],exports.MarkSelectionService);function Xa(n){return{strokeWidth:1.5,stroke:n.getColorFromTheme("primary.600"),fill:"rgba(178, 178, 178, 0.10)",widgets:{},strokeDash:8}}function eu(n){if(n==null)return n;const o={};return n.p!==void 0&&(o.p=n.p===null?null:a.cloneValue(n.p)),n.s!==void 0&&(n.s===null||typeof n.s=="string"?o.s=n.s:o.s=a.cloneValue(n.s)),n.v!==void 0&&(o.v=n.v),n.t!==void 0&&(o.t=n.t),n.f!==void 0&&(o.f=n.f),n.ref!==void 0&&(o.ref=n.ref),n.xf!==void 0&&(o.xf=n.xf),n.si!==void 0&&(o.si=n.si),n.custom!==void 0&&(o.custom=n.custom===null?null:a.cloneValue(n.custom)),n.rowSpan!==void 0&&(o.rowSpan=n.rowSpan),n.colSpan!==void 0&&(o.colSpan=n.colSpan),n.plain!==void 0&&(o.plain=n.plain),o}const tu=10,nu=6;function ru(){return a.generateRandomId(nu)}function ou(n){const o=n.match(/data-copy-id="([^\s]+)"/);return o&&o[1]?o[1]:null}class iu{constructor(){E(this,"_cache",new a.LRUMap(tu));E(this,"_lastCopyId$",new O.BehaviorSubject(null));E(this,"lastCopyId$",this._lastCopyId$.asObservable())}set(o,e){this._cache.set(o,e),this._lastCopyId$.next(o)}get(o){return this._cache.get(o)}del(o){this._cache.delete(o),this._lastCopyId$.getValue()===o&&this._lastCopyId$.next(null)}clear(){this._cache.clear(),this._lastCopyId$.next(null)}clearWithUnitId(o){this._cache.forEach((e,t)=>{e.unitId===o&&this._cache.delete(t)})}getLastCopyId(){return this._lastCopyId$.getValue()}}function ro(n,o){const e=o!=null?o:n.style,t={},r=n.tagName.toLowerCase();switch(r){case"b":case"em":case"strong":{t.bl=a.BooleanNumber.TRUE;break}case"s":{t.st={s:a.BooleanNumber.TRUE};break}case"u":{t.ul={s:a.BooleanNumber.TRUE};break}case"i":{t.it=a.BooleanNumber.TRUE;break}case"sub":case"sup":{t.va=r==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}return su(e,t),t}function su(n,o){if(n instanceof CSSStyleDeclaration)for(let e=0;e<n.length;e++){const t=n[e],r=n.getPropertyValue(t);Fs(t,r,o)}else for(const e in n){const t=n[e];Fs(e,t,o)}}function Fs(n,o,e){switch(n){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);t.isValid&&(e.bg={rgb:t.toRgbString()});break}}}function au(n){const o=document.createElement("body");return o.innerHTML=n,o}function Ya(n){const o=n.style,e={};for(let t=0;t<o.length;t++){const r=o[t],i=o.getPropertyValue(r);switch(r){case"margin-top":{const s=Number.parseInt(i);e.spaceAbove={v:/pt/.test(i)?T.ptToPixel(s):s};break}case"margin-bottom":{const s=Number.parseInt(i);e.spaceBelow={v:/pt/.test(i)?T.ptToPixel(s):s};break}case"line-height":{const s=Number.parseFloat(i);e.lineSpacing=s;break}}}return Object.getOwnPropertyNames(e).length?e:null}function Yo(n,o){const e=[];for(let t=0,r=n.length;t<r;t++)n[t]===a.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});return e}function js(n,o,e){var s,l,c;const t=o.length,i=((s=e==null?void 0:e.length)!=null?s:0)===1&&e[0].st===0&&e[0].ed===t;return n.p?i&&((c=(l=n.p.body)==null?void 0:l.textRuns)!=null&&c.length)?(n.p.body.textRuns=[],{...n,s:e[0].ts}):n:i?{...n,s:e[0].ts}:n}const zs=["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 Xs(n,o){const e=n.tagName.toLowerCase();return typeof o=="string"?e===o:Array.isArray(o)?o.some(t=>t===e):o(n)}const Po=class Po{constructor(o){E(this,"_styleMap",new Map);E(this,"_styleCache",new Map);E(this,"_styleRules",[]);E(this,"_afterProcessRules",[]);E(this,"_dom",null);E(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=Po._pluginList.find(f=>f.checkPasteType(o));e&&(this._styleRules=[...e.stylesRules],this._afterProcessRules=[...e.afterProcessRules]);const t=new a.ObjectMatrix;this._dom=au(o);const r=this._dom.querySelector("style");if(r){const f=document.createElement("div"),v=f.attachShadow({mode:"open"});document.body.appendChild(f),v.appendChild(r);for(const C of r.sheet.cssRules){const _=C,R=_.selectorText,w=_.style;this._styleMap.set(R,w)}r.remove(),f.remove()}const i={dataStream:"",textRuns:[]},s=[],l=[],c=o.match(/<table\b[^>]*>([\s\S]*?)<\/table>/gi),d=[];this.process(null,this._dom.childNodes,i,d);const{paragraphs:u,dataStream:h,textRuns:g,payloads:S,customRanges:p}=i;if(u){const f=u.map(v=>v.startIndex+1);f.unshift(0);for(let v=0;v<f.length;v++){let C;if(v===f.length-1){if(C=`${h.substring(f[v])}\r
1
+ "use strict";var Sd=Object.defineProperty;var pd=(n,o,e)=>o in n?Sd(n,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[o]=e;var E=(n,o,e)=>pd(n,typeof o!="symbol"?o+"":o,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const J=require("@univerjs/docs-ui"),a=require("@univerjs/core"),m=require("@univerjs/sheets"),T=require("@univerjs/engine-render"),O=require("rxjs"),I=require("@univerjs/ui"),_e=require("@univerjs/docs"),W=require("react"),G=require("@univerjs/engine-formula"),b=require("react/jsx-runtime"),z=require("@univerjs/design"),le=require("rxjs/operators"),fd=require("@univerjs/telemetry");function xo(n,o){if(n==null)return;const e=o.getRenderById(n);if(e==null)return;const{mainComponent:t,scene:r,engine:i,components:s}=e,l=t,c=s.get(J.DOCS_VIEW_KEY.BACKGROUND);return{document:l,docBackground:c,scene:r,engine:i}}const xi=[10,400],Ki="RANGE_SELECTOR_COMPONENT_KEY",Oo="EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY";var ue=(n=>(n.MAIN="__SpreadsheetRender__",n.ROW="__SpreadsheetRowHeader__",n.COLUMN="__SpreadsheetColumnHeader__",n.LEFT_TOP="__SpreadsheetLeftTopPlaceholder__",n))(ue||{});const Os=0,eo=1,St=10,vd=11,As=12,pr={id:"sheet.command.set-row-header-width",type:a.CommandType.COMMAND,handler:async(n,o)=>{if(!o)return!1;const e=n.get(T.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:r,size:i}=o,s=e.getRenderById(t);if(s){e.getRenderById(t).with(exports.SheetSkeletonManagerService).setRowHeaderSize(s,r,i);const{components:c}=s,d=c.get(ue.ROW);d&&d.setCustomHeader({headerStyle:{size:i}},r)}return!0}},fr={id:"sheet.command.set-col-header-height",type:a.CommandType.COMMAND,handler:async(n,o)=>{if(!o)return!1;const e=n.get(T.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:r,size:i}=o,s=e.getRenderById(t);if(s){e.getRenderById(t).with(exports.SheetSkeletonManagerService).setColumnHeaderSize(s,r,i);const{components:c}=s,d=c.get(ue.COLUMN);d&&d.setCustomHeader({headerStyle:{size:i}},r)}return!0}},Oi=a.createInterceptorKey("rangeMovePermissionCheck"),Ai=a.createInterceptorKey("rangeFillPermissionCheck");var qi=(n=>(n[n.FORMULA_EDITOR_SHOW=100]="FORMULA_EDITOR_SHOW",n[n.MARK_SELECTION=1e4]="MARK_SELECTION",n))(qi||{});function nt(n){const o=n.getColorFromTheme("primary.600"),e=n.getColorFromTheme("white"),t=new a.ColorKit(o).setAlpha(.07).toRgbString();return{strokeWidth:1,stroke:o,fill:t,widgets:{},widgetSize:6,widgetStrokeWidth:1,widgetStroke:e,autofillSize:6,autofillStrokeWidth:1,autofillStroke:e,rowHeaderFill:t,rowHeaderStroke:o,rowHeaderStrokeWidth:1,columnHeaderFill:t,columnHeaderStroke:o,columnHeaderStrokeWidth:1,expandCornerSize:40}}class Cd{constructor(){E(this,"_startColumn",-1);E(this,"_startRow",-1);E(this,"_endColumn",-1);E(this,"_endRow",-1);E(this,"_startX",0);E(this,"_startY",0);E(this,"_endX",0);E(this,"_endY",0);E(this,"_primary");E(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:r,endRow:i}=this,{startColumn:s,startRow:l,endColumn:c,endRow:d}=o;return e===s&&t===l&&r===c&&i===d}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:r,endColumn:i,endRow:s,startX:l,startY:c,endX:d,endY:u,rangeType:h}=o;this._startColumn=t,this._startRow=r,this._endColumn=i,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 Sn(n,o){const{startRow:e,startColumn:t,endRow:r,endColumn:i,rangeType:s}=o,l=r<e?r:e,c=r<e?e:r,d=i<t?i:t,u=i<t?t:i,h=n.getNoMergeCellWithCoordByIndex(l,d),g=n.getNoMergeCellWithCoordByIndex(c,u);return{startRow:e,startColumn:t,endRow:r,endColumn:i,rangeType:s,startY:(h==null?void 0:h.startY)||0,endY:(g==null?void 0:g.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(g==null?void 0:g.endX)||0}}function Te(n,o){const{range:e,primary:t,style:r}=n,i=Sn(o,e),s=t&&cr(o,t);return{rangeWithCoord:i,primaryWithCoord:s,style:r}}function cr(n,o){const{actualRow:e,actualColumn:t,isMerged:r,isMergedMainCell:i,startRow:s,startColumn:l,endRow:c,endColumn:d}=o,u=n.getNoMergeCellWithCoordByIndex(e,t),h=n.getNoMergeCellWithCoordByIndex(s,l),g=n.getNoMergeCellWithCoordByIndex(c,d);return{actualRow:e,actualColumn:t,isMerged:r,isMergedMainCell:i,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:(g==null?void 0:g.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(g==null?void 0:g.endX)||0}}}const Ds="__SpreadsheetHelperSelectionTempRect",Id=35;class La{constructor(o,e){E(this,"_startOffsetX",0);E(this,"_startOffsetY",0);E(this,"_relativeSelectionPositionRow",0);E(this,"_relativeSelectionPositionColumn",0);E(this,"_relativeSelectionRowLength",0);E(this,"_relativeSelectionColumnLength",0);E(this,"_scenePointerMoveSub");E(this,"_scenePointerUpSub");E(this,"_disabled",!1);E(this,"_helperSelection");E(this,"_scrollTimer");E(this,"_activeViewport");E(this,"_targetSelection",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});E(this,"_isInMergeState",!1);E(this,"_fillControlColors",[]);E(this,"_skeleton");E(this,"_scene");E(this,"_themeService");E(this,"_injector");E(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()}setDisabled(o){this._disabled=o}_getFreeze(){var e,t;return(t=(e=T.withCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET,exports.SheetSkeletonManagerService,this._injector.get(a.IUniverInstanceService),this._injector.get(T.IRenderManagerService)))==null?void 0:e.getCurrentParam())==null?void 0:t.skeleton.getWorksheetConfig().freeze}_isSelectionInViewport(o,e){const t=this._getFreeze()||{startRow:-1,startColumn:-1};switch(e.viewportKey){case T.SHEET_VIEWPORT_KEY.VIEW_MAIN:return o.endRow>=t.startRow&&o.endColumn>=t.startColumn;case T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP:case T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT:return o.endColumn>=t.startColumn&&o.startRow<t.startRow;case T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT:case T.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM:return o.endRow>=t.startRow&&o.startColumn<t.startColumn;case T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP:case T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT:case T.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP:case T.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:r}=this._control;[o,e,t,r].forEach(i=>{i.onPointerEnter$.subscribeEvent(()=>{var l;((l=this._injector.get(ve,a.Quantity.OPTIONAL))==null?void 0:l.interceptor.fetchThroughInterceptors(Oi)(!1,null))!==!1&&i.setCursor(T.CURSOR_TYPE.MOVE)}),i.onPointerLeave$.subscribeEvent(()=>{i.resetCursor()}),i.onPointerDown$.subscribeEvent(this._controlPointerDownHandler.bind(this))})}_controlMoving(o,e){var A;const t=this._scene,r=t.getScrollXYInfoByViewport(T.Vector2.FromArray([o,e])),{scaleX:i,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(o,e,i,s,r),{row:c,column:d}=l,u=this._skeleton.getRowCount()-1,h=this._skeleton.getColumnCount()-1;let g=Math.max(0,c+this._relativeSelectionPositionRow),S=g+this._relativeSelectionRowLength;S>u&&(S=u,S-g<this._relativeSelectionRowLength&&(g=S-this._relativeSelectionRowLength));let p=Math.max(0,d+this._relativeSelectionPositionColumn),f=p+this._relativeSelectionColumnLength;f>h&&(f=h,f-p<this._relativeSelectionColumnLength&&(p=f-this._relativeSelectionColumnLength));const v=this._skeleton.worksheet.getCellInfoInMergeData(g,p),_=Te({range:{startRow:g,endRow:S,startColumn:p,endColumn:f},primary:v,style:null},this._skeleton),R=this._skeleton.getNoMergeCellWithCoordByIndex(g,p),w=this._skeleton.getNoMergeCellWithCoordByIndex(S,f),P=(R==null?void 0:R.startY)||0,y=(w==null?void 0:w.endY)||0,M=(R==null?void 0:R.startX)||0,x=(w==null?void 0:w.endX)||0;(A=this._helperSelection)==null||A.transformByState({left:M,top:P,width:x-M,height:y-P}),this._targetSelection={..._.rangeWithCoord},this._control.selectionMoving$.next(_.rangeWithCoord)}_controlPointerDownHandler(o){const{offsetX:e,offsetY:t}=o,r=this._scene,i=r.getCoordRelativeToViewport(T.Vector2.FromArray([e,t])),{x:s,y:l}=i,c=r.getScrollXYInfoByViewport(i),{scaleX:d,scaleY:u}=r.getAncestorScale(),h=this._skeleton.getCellIndexByOffset(s,l,d,u,c);this._startOffsetX=s,this._startOffsetY=l;const{row:g,column:S}=h,{startRow:p,startColumn:f,endRow:v,endColumn:C}=this._control.model;let _=0,R=0;g<p?_-=1:g>v&&(_+=1),S<f?R-=1:S>C&&(R+=1),this._relativeSelectionPositionRow=p-g+_,this._relativeSelectionPositionColumn=f-S+R,this._relativeSelectionRowLength=v-p,this._relativeSelectionColumnLength=C-f;const w=this._control.currentStyle,P=this._getScale();this.isHelperSelection&&(this._helperSelection=new T.Rect(Ds,{stroke:w.stroke,strokeWidth:w.strokeWidth/P}),r.addObject(this._helperSelection));const y=r.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN),M=T.ScrollTimer.create(r);this._scrollTimer=M,M.startScroll(s,l,y),r.disableObjectsEvent(),this._scenePointerMoveSub=r.onPointerMove$.subscribeEvent(x=>{var V;if(this._disabled)return;const{offsetX:A,offsetY:D}=x;if(((V=this._injector.get(ve,a.Quantity.OPTIONAL))==null?void 0:V.interceptor.fetchThroughInterceptors(Oi)(!1,null))===!1)return;const{x:k,y:H}=r.getCoordRelativeToViewport(T.Vector2.FromArray([A,D]));this._controlMoving(k,H),r.setCursor(T.CURSOR_TYPE.MOVE),M.scrolling(k,H,()=>{this._controlMoving(k,H)})}),this._scenePointerUpSub=r.onPointerUp$.subscribeEvent(()=>{var A,D,N,k;(A=this._helperSelection)==null||A.dispose();const x=this._scene;x.resetCursor(),this._clearObserverEvent(),x.enableObjectsEvent(),(D=this._scrollTimer)==null||D.dispose(),this._control.selectionMoveEnd$.next(this._targetSelection),(k=(N=this._selectionHooks).selectionMoveEnd)==null||k.call(N)})}_initialWidget(){const{topLeftWidget:o,topCenterWidget:e,topRightWidget:t,middleLeftWidget:r,middleRightWidget:i,bottomLeftWidget:s,bottomCenterWidget:l,bottomRightWidget:c}=this._control,d=[T.CURSOR_TYPE.NORTH_WEST_RESIZE,T.CURSOR_TYPE.NORTH_RESIZE,T.CURSOR_TYPE.NORTH_EAST_RESIZE,T.CURSOR_TYPE.WEST_RESIZE,T.CURSOR_TYPE.EAST_RESIZE,T.CURSOR_TYPE.SOUTH_WEST_RESIZE,T.CURSOR_TYPE.SOUTH_RESIZE,T.CURSOR_TYPE.SOUTH_EAST_RESIZE];[o,e,t,r,i,s,l,c].forEach((u,h)=>{u.onPointerEnter$.subscribeEvent(()=>{u.setCursor(d[h])}),u.onPointerLeave$.subscribeEvent(()=>{u.resetCursor()}),u.onPointerDown$.subscribeEvent(g=>{this._widgetPointerDownEvent(g,d[h])})})}_widgetPointerDownEvent(o,e){const t=this._scene,{offsetX:r,offsetY:i}=o,s=t.getCoordRelativeToViewport(T.Vector2.FromArray([r,i])),{x:l,y:c}=s;this._startOffsetX=r,this._startOffsetY=i;const{startRow:d,startColumn:u,endRow:h,endColumn:g}=this._control.model,S=Math.min(d,h),p=Math.min(u,g),f=Math.max(d,h),v=Math.max(u,g);this._relativeSelectionPositionRow=S,this._relativeSelectionPositionColumn=p,this._relativeSelectionRowLength=f-S,this._relativeSelectionColumnLength=v-p,e===T.CURSOR_TYPE.NORTH_WEST_RESIZE?(this._relativeSelectionPositionRow=f,this._relativeSelectionPositionColumn=v):e===T.CURSOR_TYPE.NORTH_RESIZE?this._relativeSelectionPositionRow=f:e===T.CURSOR_TYPE.NORTH_EAST_RESIZE?this._relativeSelectionPositionRow=f:e===T.CURSOR_TYPE.WEST_RESIZE?this._relativeSelectionPositionColumn=v:e===T.CURSOR_TYPE.SOUTH_WEST_RESIZE?this._relativeSelectionPositionColumn=v:e===T.CURSOR_TYPE.SOUTH_RESIZE&&(this._relativeSelectionPositionRow=S);const C=T.ScrollTimer.create(t),_=t.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN);C.startScroll(l,c,_),this._scrollTimer=C,t.disableObjectsEvent(),this._scenePointerMoveSub=t.onPointerMove$.subscribeEvent(R=>{const{offsetX:w,offsetY:P}=R,{x:y,y:M}=t.getCoordRelativeToViewport(T.Vector2.FromArray([w,P]));this._widgetMoving(y,M,e),t.setCursor(e),C.scrolling(y,M,()=>{this._widgetMoving(y,M,e)})}),this._scenePointerUpSub=t.onPointerUp$.subscribeEvent(()=>{var w,P,y;const R=this._scene;R.resetCursor(),this._clearObserverEvent(),R.enableObjectsEvent(),(w=this._scrollTimer)==null||w.dispose(),this._control.selectionScaled$.next(this._targetSelection),(y=(P=this._selectionHooks).selectionMoveEnd)==null||y.call(P)})}_widgetMoving(o,e,t){const r=this._scene,i=r.getScrollXYInfoByViewport(T.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:s,scaleY:l}=r.getAncestorScale(),c=this._skeleton.getCellIndexByOffset(o,e,s,l,i),{row:d,column:u}=c;let h=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,S=d,p=u;t===T.CURSOR_TYPE.NORTH_WEST_RESIZE?(h=d,g=u,S=this._relativeSelectionPositionRow,p=this._relativeSelectionPositionColumn):t===T.CURSOR_TYPE.NORTH_RESIZE?(h=d,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,p=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength):t===T.CURSOR_TYPE.NORTH_EAST_RESIZE?(h=d,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,p=u):t===T.CURSOR_TYPE.WEST_RESIZE?(h=this._relativeSelectionPositionRow,g=u,S=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,p=this._relativeSelectionPositionColumn):t===T.CURSOR_TYPE.EAST_RESIZE?S=this._relativeSelectionPositionRow+this._relativeSelectionRowLength:t===T.CURSOR_TYPE.SOUTH_WEST_RESIZE?(h=this._relativeSelectionPositionRow,g=u,S=d,p=this._relativeSelectionPositionColumn):t===T.CURSOR_TYPE.SOUTH_RESIZE&&(h=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,S=d,p=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength);const f=this._swapPositions(h,g,S,p),v=this._skeleton.getCellWithMergeInfoByIndex(h,g),_=Te({range:f,primary:v,style:null},this._skeleton);this._targetSelection={..._.rangeWithCoord},this._control.updateRangeBySelectionWithCoord(_),this._control.selectionScaling$.next(this._targetSelection)}_initialAutoFill(){const{fillControl:o}=this._control;o.onPointerEnter$.subscribeEvent(e=>{this._injector.get(ve).interceptor.fetchThroughInterceptors(Ai)(!1,{x:e.offsetX,y:e.offsetY,skeleton:this._skeleton,scene:this._scene})&&o.setCursor(T.CURSOR_TYPE.CROSSHAIR)}),o.onPointerLeave$.subscribeEvent(()=>{o.resetCursor()}),o.onPointerDown$.subscribeEvent(this._autoFillForPointerdown.bind(this))}_autoFillMoving(o,e){var D,N,k;const t=this._scene,r=t.getViewportScrollXY(this._activeViewport),{scaleX:i,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(o,e,i,s,r),{row:c,column:d}=l,u=t.getCoordRelativeToViewport(T.Vector2.FromArray([o,e])),h=this._skeleton.getRowCount()-1,g=this._skeleton.getColumnCount()-1;let S=this._relativeSelectionPositionRow,p=this._relativeSelectionPositionColumn,f=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,v=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength,C=!1,_=!0;if((d<p||d>v)&&c>=S&&c<=f){const H=this._fillRuler(d,p,v,this._relativeSelectionColumnLength,g);p=H.startRowOrColumn,v=H.endRowOrColumn,C=H.isLighten,_=!1}else if((c<S||c>f)&&d>=p&&d<=v){const H=this._fillRuler(c,S,f,this._relativeSelectionRowLength,h);S=H.startRowOrColumn,f=H.endRowOrColumn,C=H.isLighten}else if(Math.abs(this._startOffsetX-u.x-r.x)/2>Math.abs(this._startOffsetY-u.y-r.y)){const H=this._fillRuler(d,p,v,this._relativeSelectionColumnLength,g);p=H.startRowOrColumn,v=H.endRowOrColumn,C=H.isLighten,_=!1}else{const H=this._fillRuler(c,S,f,this._relativeSelectionRowLength,h);S=H.startRowOrColumn,f=H.endRowOrColumn,C=H.isLighten}const R=this._skeleton.getNoMergeCellWithCoordByIndex(S,p),w=this._skeleton.getNoMergeCellWithCoordByIndex(f,v),P=(R==null?void 0:R.startY)||0,y=(w==null?void 0:w.endY)||0,M=(R==null?void 0:R.startX)||0,x=(w==null?void 0:w.endX)||0;C?this._controlHandler((H,V)=>{const L=new a.ColorKit(this._fillControlColors[V]).lighten(Id).toRgbString();H.setProps({fill:L})}):this._controlHandler((H,V)=>{H.setProps({fill:this._fillControlColors[V]})});const A=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();S===f&&_===!0||p===v&&_===!1?(D=this._helperSelection)==null||D.hide():((N=this._helperSelection)==null||N.transformByState({left:M-A/2,top:P-A/2,width:x-M,height:y-P}),(k=this._helperSelection)==null||k.show()),this._targetSelection={startY:P,endY:y,startX:M,endX:x,startRow:S,endRow:f,startColumn:p,endColumn:v},this._control.selectionFilling$.next(this._targetSelection)}_autoFillForPointerdown(o){const{offsetX:e,offsetY:t}=o,r=this._scene,i=r.getCoordRelativeToViewport(T.Vector2.FromArray([e,t])),{x:s,y:l}=i;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 g=this._control.currentStyle;let S=g==null?void 0:g.stroke,p=g==null?void 0:g.strokeWidth;const f=nt(this._themeService);S==null&&(S=f.stroke),p==null&&(p=f.strokeWidth);const v=this._getScale();p/=v;const C=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/v,_=new a.ColorKit(S).darken(2).toRgbString();this.isHelperSelection&&(this._helperSelection=new T.Rect(Ds,{stroke:_,strokeWidth:p+C/2}),r.addObject(this._helperSelection)),this._activeViewport=r.getActiveViewportByCoord(T.Vector2.FromArray([e,t]));const R=r.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN),w=T.ScrollTimer.create(r,this._activeViewport.viewportKey===T.SHEET_VIEWPORT_KEY.VIEW_MAIN?T.ScrollTimerType.ALL:T.ScrollTimerType.NONE);w.startScroll(s,l,R),this._scrollTimer=w,r.disableObjectsEvent(),this._controlHandler(P=>{this._fillControlColors.push(P.fill)}),this._scenePointerMoveSub=r.onPointerMove$.subscribeEvent(P=>{var H;const{offsetX:y,offsetY:M}=P,x=r.getActiveViewportByCoord(T.Vector2.FromArray([y,M]));if(!this._injector.get(ve).interceptor.fetchThroughInterceptors(Ai)(!1,{x:o.offsetX,y:o.offsetY,skeleton:this._skeleton,scene:this._scene}))return;const{x:D,y:N}=r.getCoordRelativeToViewport(T.Vector2.FromArray([y,M]));this._autoFillMoving(D,N),r.setCursor(T.CURSOR_TYPE.CROSSHAIR);const k=this._targetSelection;if(R&&x&&((H=this._activeViewport)==null?void 0:H.viewportKey)!==(x==null?void 0:x.viewportKey)){let V;k.startRow!==c?(w.scrollTimerType=T.ScrollTimerType.Y,V={...k,endRow:k.startRow}):k.endRow!==u?(w.scrollTimerType=T.ScrollTimerType.Y,V={...k,startRow:k.endRow}):k.startColumn!==d?(w.scrollTimerType=T.ScrollTimerType.X,V={...k,endColumn:k.startColumn}):(w.scrollTimerType=T.ScrollTimerType.X,V={...k,startColumn:k.endColumn}),this._isSelectionInViewport(V,x)&&(this._viewportMainScrollBarNeedResetPosition(w.scrollTimerType,this._activeViewport.viewportKey,x.viewportKey)&&R.scrollToBarPos({x:w.scrollTimerType===T.ScrollTimerType.X?0:void 0,y:w.scrollTimerType===T.ScrollTimerType.Y?0:void 0}),this._activeViewport=x)}w.scrolling(D,N,()=>{this._autoFillMoving(D,N)})}),this._scenePointerUpSub=r.onPointerUp$.subscribeEvent(()=>{var y,M;(y=this._helperSelection)==null||y.dispose();const P=this._scene;P.resetCursor(),this._clearObserverEvent(),P.enableObjectsEvent(),(M=this._scrollTimer)==null||M.dispose(),this._control.refreshSelectionFilled(this._targetSelection),this._isInMergeState=!1,this._controlHandler((x,A)=>{x.setProps({fill:this._fillControlColors[A]})}),this._fillControlColors=[]})}_viewportMainScrollBarNeedResetPosition(o,e,t){return o===T.ScrollTimerType.X&&(e===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||e===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP)&&(t===T.SHEET_VIEWPORT_KEY.VIEW_MAIN||t===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP)||o===T.ScrollTimerType.Y&&(e===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||e===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP)&&(t===T.SHEET_VIEWPORT_KEY.VIEW_MAIN||t===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)}_hasMergeInRange(o,e,t,r){return this._skeleton.worksheet.getMergedCellRange(o,e,t,r).length>0}_swapPositions(o,e,t,r){const i=Math.min(o,t),s=Math.min(e,r),l=Math.max(o,t),c=Math.max(e,r);return{startRow:i,startColumn:s,endRow:l,endColumn:c}}_controlHandler(o){const{leftControl:e,rightControl:t,topControl:r,bottomControl:i,backgroundControlTop:s,backgroundControlMiddleLeft:l,backgroundControlMiddleRight:c,backgroundControlBottom:d,fillControl:u}=this._control,h=[e,t,r,i,s,l,c,d,u];for(let g=0,S=h.length;g<S;g++){const p=h[g];o(p,g)}}_fillRuler(o,e,t,r,i){let s=!1;if(o<e)if(this._isInMergeState&&o<e){const l=e-o,c=r+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=r+1,d=Math.ceil(l/c);let u=t+d*c;u>i&&(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 Di=(n=>(n.Selection="__SpreadsheetSelectionShape__",n.top="__SpreadsheetSelectionTopControl__",n.bottom="__SpreadsheetSelectionBottomControl__",n.left="__SpreadsheetSelectionShapeLeftControl__",n.right="__SpreadsheetSelectionShapeRightControl__",n.backgroundTop="__SpreadsheetSelectionBackgroundControlTop__",n.backgroundMiddleLeft="__SpreadsheetSelectionBackgroundControlMiddleLeft__",n.backgroundMiddleRight="__SpreadsheetSelectionBackgroundControlMiddleRight__",n.backgroundBottom="__SpreadsheetSelectionBackgroundControlBottom__",n.fill="__SpreadsheetSelectionFillControl__",n.fillTopLeft="__SpreadsheetSelectionFillControlTopLeft__",n.fillBottomRight="__SpreadsheetSelectionFillControlBottomRight__",n.fillTopLeftInner="__SpreadsheetSelectionFillControlTopLeftInner__",n.fillBottomRightInner="__SpreadsheetSelectionFillControlBottomRightInner__",n.lineMain="__SpreadsheetDragLineMainControl__",n.lineContent="__SpreadsheetDragLineContentControl__",n.line="__SpreadsheetDragLineControl__",n.dash="__SpreadsheetDragDashControl__",n.rowHeaderBackground="__SpreadSheetSelectionRowHeaderBackground__",n.rowHeaderBorder="__SpreadSheetSelectionRowHeaderBorder__",n.rowHeaderGroup="__SpreadSheetSelectionRowHeaderGroup__",n.columnHeaderBackground="__SpreadSheetSelectionColumnHeaderBackground__",n.columnHeaderBorder="__SpreadSheetSelectionColumnHeaderBorder__",n.columnHeaderGroup="__SpreadSheetSelectionColumnHeaderGroup__",n.topLeftWidget="__SpreadSheetSelectionTopLeftWidget__",n.topCenterWidget="__SpreadSheetSelectionTopCenterWidget__",n.topRightWidget="__SpreadSheetSelectionTopRightWidget__",n.middleLeftWidget="__SpreadSheetSelectionMiddleLeftWidget__",n.middleRightWidget="__SpreadSheetSelectionMiddleRightWidget__",n.bottomLeftWidget="__SpreadSheetSelectionBottomLeftWidget__",n.bottomCenterWidget="__SpreadSheetSelectionBottomCenterWidget__",n.bottomRightWidget="__SpreadSheetSelectionBottomRightWidget__",n))(Di||{});const Ns=.3;class vr extends a.Disposable{constructor(e,t,r,i){var s,l,c,d;super();E(this,"_isHelperSelection",!0);E(this,"_enableAutoFill",!0);E(this,"_showAutoFill",!1);E(this,"_highlightHeader",!0);E(this,"_selectionRenderModel");E(this,"_leftBorder");E(this,"_rightBorder");E(this,"_topBorder");E(this,"_bottomBorder");E(this,"_backgroundControlTop");E(this,"_backgroundControlBottom");E(this,"_backgroundControlMiddleLeft");E(this,"_backgroundControlMiddleRight");E(this,"_autoFillControl");E(this,"_selectionShapeGroup");E(this,"_rowHeaderBackground");E(this,"_rowHeaderBorder");E(this,"_rowHeaderGroup");E(this,"_columnHeaderBackground");E(this,"_columnHeaderBorder");E(this,"_columnHeaderGroup");E(this,"_dashedRect");E(this,"_topLeftWidget");E(this,"_topCenterWidget");E(this,"_topRightWidget");E(this,"_middleLeftWidget");E(this,"_middleRightWidget");E(this,"_bottomLeftWidget");E(this,"_bottomCenterWidget");E(this,"_bottomRightWidget");E(this,"_defaultStyle");E(this,"_currentStyle");E(this,"_rowHeaderWidth",0);E(this,"_columnHeaderHeight",0);E(this,"_widgetRects",[]);E(this,"_controlExtension");E(this,"_dispose$",new O.BehaviorSubject(this));E(this,"dispose$",this._dispose$.asObservable());E(this,"selectionMoving$",new O.Subject);E(this,"selectionMoveEnd$",new O.Subject);E(this,"selectionScaling$",new O.Subject);E(this,"selectionScaled$",new O.Subject);E(this,"selectionFilling$",new O.Subject);E(this,"_selectionFilled$",new O.Subject);E(this,"selectionFilled$",this._selectionFilled$.asObservable());E(this,"_antLineOffset",0);E(this,"_antRequestNewFrame",-1);this._scene=e,this._zIndex=t,this._themeService=r,this._enableAutoFill=(s=i==null?void 0:i.enableAutoFill)!=null?s:!0,this._highlightHeader=(l=i==null?void 0:i.highlightHeader)!=null?l:!0,this._rowHeaderWidth=(c=i==null?void 0:i.rowHeaderWidth)!=null?c:0,this._columnHeaderHeight=(d=i==null?void 0:i.columnHeaderHeight)!=null?d:0,this._initializeSheetBody(),this._initialHeader()}_initializeSheetBody(){this._defaultStyle=nt(this._themeService),this._currentStyle=nt(this._themeService),this._selectionRenderModel=new Cd;const e=this._zIndex;this._leftBorder=new T.Rect("__SpreadsheetSelectionShapeLeftControl__"+e,{zIndex:e}),this._rightBorder=new T.Rect("__SpreadsheetSelectionShapeRightControl__"+e,{zIndex:e}),this._topBorder=new T.Rect("__SpreadsheetSelectionTopControl__"+e,{zIndex:e}),this._bottomBorder=new T.Rect("__SpreadsheetSelectionBottomControl__"+e,{zIndex:e}),this._backgroundControlTop=new T.Rect("__SpreadsheetSelectionBackgroundControlTop__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlBottom=new T.Rect("__SpreadsheetSelectionBackgroundControlBottom__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleLeft=new T.Rect("__SpreadsheetSelectionBackgroundControlMiddleLeft__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleRight=new T.Rect("__SpreadsheetSelectionBackgroundControlMiddleRight__"+e,{zIndex:e-1,evented:!1}),this._autoFillControl=new T.Rect("__SpreadsheetSelectionFillControl__"+e,{zIndex:e+1}),this._autoFillControl.hide(),this._dashedRect=new T.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 T.Group("__SpreadsheetSelectionShape__"+e,...t,...this._widgetRects),this._selectionShapeGroup.hide(),this._selectionShapeGroup.evented=!1,this._selectionShapeGroup.zIndex=e;const r=this.getScene();r.addObject(this._selectionShapeGroup,eo),this.disposeWithMe(a.toDisposable(r.onTransformChange$.subscribeEvent(i=>{i.type===T.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&(this._updateLayoutOfSelectionControl(this._currentStyle),this._updateControlCoord())})))}_initialHeader(){const e=this._zIndex;this._rowHeaderBackground=new T.Rect("__SpreadSheetSelectionRowHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderBorder=new T.Rect("__SpreadSheetSelectionRowHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderGroup=new T.Group("__SpreadSheetSelectionRowHeaderGroup__"+e,this._rowHeaderBackground,this._rowHeaderBorder),this._rowHeaderGroup.hide(),this._rowHeaderGroup.evented=!1,this._rowHeaderGroup.zIndex=e,this._columnHeaderBackground=new T.Rect("__SpreadSheetSelectionColumnHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderBorder=new T.Rect("__SpreadSheetSelectionColumnHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderGroup=new T.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],vd)}_initialWidget(){const e=this._zIndex;return this._topLeftWidget=new T.Rect("__SpreadSheetSelectionTopLeftWidget__"+e,{zIndex:e+1}),this._topCenterWidget=new T.Rect("__SpreadSheetSelectionTopCenterWidget__"+e,{zIndex:e+1}),this._topRightWidget=new T.Rect("__SpreadSheetSelectionTopRightWidget__"+e,{zIndex:e+1}),this._middleLeftWidget=new T.Rect("__SpreadSheetSelectionMiddleLeftWidget__"+e,{zIndex:e+1}),this._middleRightWidget=new T.Rect("__SpreadSheetSelectionMiddleRightWidget__"+e,{zIndex:e+1}),this._bottomLeftWidget=new T.Rect("__SpreadSheetSelectionBottomLeftWidget__"+e,{zIndex:e+1}),this._bottomCenterWidget=new T.Rect("__SpreadSheetSelectionBottomCenterWidget__"+e,{zIndex:e+1}),this._bottomRightWidget=new T.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 La(this,e)}setControlExtensionDisable(e){this._controlExtension&&this._controlExtension.setDisabled(e)}setEvent(e){this.leftControl.evented=e,this.rightControl.evented=e,this.topControl.evented=e,this.bottomControl.evented=e}refreshSelectionFilled(e){this._selectionFilled$.next(e)}_updateLayoutOfSelectionControl(e){e&&(this.currentStyle=Object.assign({},this._defaultStyle,e));const t=this.currentStyle,{stroke:r,widgets:i,autofillStroke:s,strokeDash:l,isAnimationDash:c}=t;let d=t.autofillSize,u=t.strokeWidth,h=t.autofillStrokeWidth;const g=this._getScale(),S=(u+m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH)/2/g;u/=g,d/=g,h/=g<1?1:g;const p=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/g,f=T.FIX_ONE_PIXEL_BLUR_OFFSET/g,{startX:v,startY:C,endX:_,endY:R}=this._selectionRenderModel;if(this.leftControl.transformByState({height:R-C,left:-S+f,width:u,strokeWidth:p,top:-p/2+f}),this.leftControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.rightControl.transformByState({height:R-C,left:_-v-S+f,width:u,strokeWidth:p,top:-p/2+f}),this.rightControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.topControl.transformByState({width:_-v+u,top:-S+f,left:-S+f,height:u,strokeWidth:p}),this.topControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.bottomControl.transformByState({width:_-v+u,top:R-C-S+f,height:u,left:-S+f,strokeWidth:p}),this.bottomControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),l==null)this.dashedRect.hide(),this._stopAntLineAnimation();else{const w=t.strokeWidth*2/g;this.dashedRect.transformByState({height:R-C,width:_-v,strokeWidth:w,left:-w/2+f,top:-w/2+f}),this.dashedRect.setProps({strokeDashArray:[0,l/g]}),this._stopAntLineAnimation(),c!==!1&&this._startAntLineAnimation(),this.dashedRect.show()}if(this._showAutoFill=this._showAutoFill&&this._enableAutoFill,this._showAutoFill&&!this._hasWidgets(i)){const w={fill:r,stroke:s,strokeScaleEnabled:!1},P={width:d-h,height:d-h,left:_-v-d/2+h/2-f,top:R-C-d/2+h/2-f,strokeWidth:h};this._autoFillControl.setProps(w),this._autoFillControl.transformByState(P),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.rowHeaderWidth,this._columnHeaderHeight=t.columnHeaderHeight),this._selectionRenderModel.setValue(e.rangeWithCoord,e.primaryWithCoord),this._showAutoFill=e.primaryWithCoord!==null,this._updateLayoutOfSelectionControl(e.style),this._updateControlCoord()}update(e,t=0,r=0,i,s){this._rowHeaderWidth=t,this._columnHeaderHeight=r,this.updateRangeBySelectionWithCoord({rangeWithCoord:e,primaryWithCoord:s,style:i}),i&&this.updateStyle(i)}updateCurrCell(e){this._showAutoFill=e!==null,this._selectionRenderModel.setCurrentCell(e)}clearHighlight(){this._showAutoFill=!1,this._selectionRenderModel.clearCurrentCell(),this._updateLayoutOfSelectionControl(this._currentStyle)}getScene(){return this._scene}dispose(){var e,t,r,i,s,l,c,d,u,h,g,S,p,f,v,C,_,R,w,P,y,M,x,A,D;(e=this._leftBorder)==null||e.dispose(),(t=this._rightBorder)==null||t.dispose(),(r=this._topBorder)==null||r.dispose(),(i=this._bottomBorder)==null||i.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(),(g=this._rowHeaderBorder)==null||g.dispose(),(S=this._rowHeaderGroup)==null||S.dispose(),(p=this._rowHeaderBackground)==null||p.dispose(),(f=this._columnHeaderBackground)==null||f.dispose(),(v=this._columnHeaderBorder)==null||v.dispose(),(C=this._columnHeaderGroup)==null||C.dispose(),(_=this._topLeftWidget)==null||_.dispose(),(R=this._topCenterWidget)==null||R.dispose(),(w=this._topRightWidget)==null||w.dispose(),(P=this._middleLeftWidget)==null||P.dispose(),(y=this._middleRightWidget)==null||y.dispose(),(M=this._bottomLeftWidget)==null||M.dispose(),(x=this._bottomCenterWidget)==null||x.dispose(),(A=this._bottomRightWidget)==null||A.dispose(),(D=this._controlExtension)==null||D.dispose(),super.dispose(),this._dispose$.next(this),this._dispose$.complete()}getCurrentCellInfo(){const e=this.model.currentCell;if(e){let t;if(e.isMerged){const r=e.mergeInfo;t={startRow:r.startRow,endRow:r.endRow,startColumn:r.startColumn,endColumn:r.endColumn,startX:r.startX,endX:r.endX,startY:r.startY,endY:r.endY}}else{const{actualRow:r,actualColumn:i,startX:s,endX:l,startY:c,endY:d}=e;t={startRow:r,endRow:r,startColumn:i,endColumn:i,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:r,endX:i,endY:s,rangeType:l}=this._selectionRenderModel,c=this._currentStyle,d=this._getScale(),{stroke:u,rowHeaderFill:h=c.rowHeaderFill,rowHeaderStroke:g=c.rowHeaderStroke,columnHeaderFill:S=c.columnHeaderFill,columnHeaderStroke:p=c.columnHeaderStroke}=e;let{rowHeaderStrokeWidth:f=c.rowHeaderStrokeWidth,columnHeaderStrokeWidth:v=c.columnHeaderStrokeWidth}=e;f/=d,v/=d;const C=this._rowHeaderWidth,_=this._columnHeaderHeight;if(this._highlightHeader&&_>0){let R=S;l===a.RANGE_TYPE.COLUMN&&(R=new a.ColorKit(u).setAlpha(Ns).toString()),this._columnHeaderBackground.setProps({fill:R}),this._columnHeaderBackground.resize(i-t,_),this._columnHeaderBorder.setProps({fill:p}),this._columnHeaderBorder.transformByState({width:i-t,height:v,top:_-v+1/d}),this._columnHeaderGroup.show(),this._columnHeaderGroup.translate(t,0)}else this._columnHeaderGroup.hide();if(this._columnHeaderGroup.makeDirty(!0),this._highlightHeader&&C>0){let R=h;l===a.RANGE_TYPE.ROW&&(R=new a.ColorKit(u).setAlpha(Ns).toString()),this._rowHeaderBackground.setProps({fill:R}),this._rowHeaderBackground.resize(C,s-r),this._rowHeaderBorder.setProps({fill:g}),this._rowHeaderBorder.transformByState({width:f,height:s-r,left:C-f+1/d}),this._rowHeaderGroup.show(),this._rowHeaderGroup.translate(0,r)}else this._rowHeaderGroup.hide();this._rowHeaderGroup.makeDirty(!0)}_updateBackgroundControl(e){const{startX:t,startY:r,endX:i,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(i-t,s-r),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:g,endX:S,endY:p}=u,f=d/2,v={left:-f,top:-f,width:i-t+f*2,height:g-r+f};v.height<0&&(v.width=0,v.height=0),this._backgroundControlTop.transformByState(v);const C={left:-f,top:g-r,width:h-t+f,height:p-g};C.width<0&&(C.width=0,C.height=0),this._backgroundControlMiddleLeft.transformByState(C);const _={left:S-t-f,top:g-r,width:i-S+f*2,height:p-g};_.width<0&&(_.width=0,_.height=0),this._backgroundControlMiddleRight.transformByState(_);const R={left:-f,top:p-r,width:i-t+f*2,height:s-p+f};R.height<0&&(R.width=0,R.height=0),this._backgroundControlBottom.transformByState(R),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:r,endX:i,endY:s}=this._selectionRenderModel,{stroke:l=e.stroke,widgets:c=e.widgets,widgetStroke:d=e.widgetStroke}=e,u=this._getScale();let{widgetSize:h,widgetStrokeWidth:g}=e;h/=u,g/=u;const S={left:-h/2+g/2,center:(i-t)/2-h/2+g/2,right:i-t-h/2+g/2,top:-h/2,middle:(s-r)/2-h/2,bottom:s-r-h/2+g/2},p=h-g;this._widgetRects.forEach(f=>{f.setProps({fill:l,stroke:d})}),c.tl===!0?(this._topLeftWidget.transformByState({height:p,width:p,left:S.left,top:S.top,strokeWidth:g}),this._topLeftWidget.show()):this._topLeftWidget.hide(),c.tc===!0?(this._topCenterWidget.transformByState({height:p,width:p,left:S.center,top:S.top,strokeWidth:g}),this._topCenterWidget.show()):this._topCenterWidget.hide(),c.tr===!0?(this._topRightWidget.transformByState({height:p,width:p,left:S.right,top:S.top,strokeWidth:g}),this._topRightWidget.show()):this._topRightWidget.hide(),c.ml===!0?(this._middleLeftWidget.transformByState({height:p,width:p,left:S.left,top:S.middle,strokeWidth:g}),this._middleLeftWidget.show()):this._middleLeftWidget.hide(),c.mr===!0?(this._middleRightWidget.transformByState({height:p,width:p,left:S.right,top:S.middle,strokeWidth:g}),this._middleRightWidget.show()):this._middleRightWidget.hide(),c.bl===!0?(this._bottomLeftWidget.transformByState({height:p,width:p,left:S.left,top:S.bottom,strokeWidth:g}),this._bottomLeftWidget.show()):this._bottomLeftWidget.hide(),c.bc===!0?(this._bottomCenterWidget.transformByState({height:p,width:p,left:S.center,top:S.bottom,strokeWidth:g}),this._bottomCenterWidget.show()):this._bottomCenterWidget.hide(),c.br===!0?(this._bottomRightWidget.transformByState({height:p,width:p,left:S.right,top:S.bottom,strokeWidth:g}),this._bottomRightWidget.show()):this._bottomRightWidget.hide()}_hasWidgets(e){if(e==null)return!1;const t=Object.keys(e);if(t.length===0)return!1;for(const r of t)if(e[r]===!0)return!0;return!1}_getScale(){const{scaleX:e,scaleY:t}=this._scene.getAncestorScale();return Math.max(e,t)}_stopAntLineAnimation(){this._antLineOffset=0,T.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=T.requestNewFrame(()=>{this._startAntLineAnimation()})}}class _d extends T.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 ve=a.createIdentifier("univer.sheet.selection-render-service");class Qi extends a.Disposable{constructor(e,t,r,i,s){super();E(this,"_downObserver");E(this,"_scenePointerMoveSub");E(this,"_scenePointerUpSub");E(this,"_controlFillConfig$",new O.BehaviorSubject(null));E(this,"controlFillConfig$",this._controlFillConfig$.asObservable());E(this,"_selectionControls",[]);E(this,"_startRangeWhenPointerDown",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});E(this,"_activeControlIndex",-1);E(this,"_startViewportPosX",0);E(this,"_startViewportPosY",0);E(this,"_scrollTimer");E(this,"_cancelDownSubscription");E(this,"_cancelUpSubscription");E(this,"_skeleton");E(this,"_scene");E(this,"_highlightHeader",!0);E(this,"_rangeType",a.RANGE_TYPE.NORMAL);E(this,"_selectionStyle");E(this,"_remainLastEnabled",!1);E(this,"_skipLastEnabled",!1);E(this,"_singleSelectionEnabled",!1);E(this,"_selectionMoveEnd$",new O.BehaviorSubject([]));E(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());E(this,"_selectionMoving$",new O.Subject);E(this,"selectionMoving$",this._selectionMoving$.asObservable());E(this,"_selectionMoveStart$",new O.Subject);E(this,"selectionMoveStart$",this._selectionMoveStart$.asObservable());E(this,"_selectionMoving",!1);E(this,"_selectionTheme");E(this,"_activeViewport");E(this,"interceptor",new a.InterceptorManager({RANGE_MOVE_PERMISSION_CHECK:Oi,RANGE_FILL_PERMISSION_CHECK:Ai}));E(this,"_escapeShortcutDisposable",null);this._injector=e,this._themeService=t,this._shortcutService=r,this._sheetSkeletonManagerService=i,this.contextService=s,this._initSelectionThemeFromThemeService(),this._initMoving()}get selectionMoving(){return this._selectionMoving}get _shouldDetectMergedCells(){return this._rangeType===a.RANGE_TYPE.NORMAL}_initMoving(){this.disposeWithMe(this._selectionMoving$.subscribe(()=>{this._selectionMoving=!0})),this.disposeWithMe(this._selectionMoveEnd$.subscribe(()=>{this._selectionMoving=!1}))}_setSelectionStyle(e){this._selectionStyle=e}getViewPort(){return this._activeViewport}setSingleSelectionEnabled(e=!1){this._singleSelectionEnabled=e}newSelectionControl(e,t,r){const i=this.getSelectionControls().length,{rowHeaderWidth:s,columnHeaderHeight:l}=t,c=new vr(e,i,this._selectionTheme,{highlightHeader:this._highlightHeader,rowHeaderWidth:s,columnHeaderHeight:l});this._selectionControls.push(c);const d=Te(r,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(),r=this._skeleton;if(!(!t||!r)){for(let i=0,s=e.length;i<s;i++){const l=e[i],c=Te(l,this._skeleton),d=t[i];d?d.updateRangeBySelectionWithCoord(c,r):this.isSelectionEnabled()&&this.newSelectionControl(this._scene,r,l)}e.length<t.length&&t.splice(e.length).forEach(s=>s.dispose())}}refreshSelectionMoveStart(){this._selectionMoveStart$.next(this.getSelectionDataWithStyle())}refreshSelectionMoveEnd(){this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}_initSelectionThemeFromThemeService(){const e=this._themeService.getCurrentTheme();this._selectionTheme=new a.ThemeService,this._selectionTheme.setTheme(e)}setSelectionTheme(e){this._selectionTheme.setTheme(e)}_changeRuntime(e,t,r){this._skeleton=e,this._scene=t,this._activeViewport=r||(t==null?void 0:t.getViewports()[0]),t.findLayerByZIndex(eo)||t.addLayer(new _d(t,[],eo))}getSkeleton(){return this._skeleton}getSelectionDataWithStyle(){const e=this._selectionControls;if(this._skeleton.worksheet){const[t,r]=this._skeleton.getLocation();return e.map(i=>{const s=i.getValue();return s.rangeWithCoord.sheetId=r,s.rangeWithCoord.unitId=t,s})}return[]}getSelectionControls(){return this._selectionControls}_addSelectionControlByModelData(e){var l;const t=this._skeleton,r=(l=e.style)!=null?l:nt(this._selectionTheme),i=this._scene;return e.style=r,this.newSelectionControl(i,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 r=this._getFreeze();if(!r||r.startRow<=0&&r.startColumn<=0)return this._scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e>r.startRow&&t>r.startColumn)return this._scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e<=r.startRow&&t<=r.startColumn)return this._scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP);if(e<=r.startRow&&t>r.startColumn)return this._scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(e>r.startRow&&t<=r.startColumn)return this._scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)}getActiveRange(){const e=this.getSelectionControls(),t=e&&e[e.length-1].model;return t&&{startRow:t.startRow,startColumn:t.startColumn,endRow:t.endRow,endColumn:t.endColumn}}setActiveSelectionIndex(e){this._activeControlIndex=e}resetActiveSelectionIndex(){this._activeControlIndex=-1}getActiveSelectionControl(){const e=this.getSelectionControls();if(e)return this._activeControlIndex<0?e[e.length-1]:e[this._activeControlIndex]}endSelection(){var e;this._clearUpdatingListeners(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),(e=this._escapeShortcutDisposable)==null||e.dispose(),this._escapeShortcutDisposable=null}_reset(){var e;this._clearAllSelectionControls(),(e=this._downObserver)==null||e.unsubscribe(),this._downObserver=null}_setupPointerMoveListener(e,t,r,i=T.ScrollTimerType.ALL,s,l){var p,f;let c=0,d=0,u=s,h=l;this._scrollTimer=T.ScrollTimer.create(this._scene,i),this._scrollTimer.startScroll((p=e==null?void 0:e.left)!=null?p:0,(f=e==null?void 0:e.top)!=null?f:0,e);const g=this._scene,S=g.getActiveViewportByCoord(T.Vector2.FromArray([s,l]));this._scenePointerMoveSub=g.onPointerMove$.subscribeEvent(v=>{var k,H,V,L,U,B,F,j,X;const{offsetX:C,offsetY:_}=v,{x:R,y:w}=g.getCoordRelativeToViewport(T.Vector2.FromArray([C,_]));this._movingHandler(R,w,t,r);let P=R,y=w;const M=this.getActiveSelectionControl(),x=this._getFreeze(),A=M==null?void 0:M.model,D=(k=g.getActiveViewportByCoord(T.Vector2.FromArray([C,_])))!=null?k:this._getViewportByCell(A==null?void 0:A.endRow,A==null?void 0:A.endColumn);if((()=>{if(!S||!D||!e)return!1;const K=[T.SHEET_VIEWPORT_KEY.VIEW_MAIN,T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT];return K.includes(S.viewportKey)&&K.includes(D.viewportKey)})()){if(!S||!D||!e)return!1;const K=u<e.left&&R>e.left||u>e.left&&R<e.left,re=h<e.top&&w>e.top||h>e.top&&w<e.top;K&&(c+=1),re&&(d+=1);const oe=S.viewportKey,ae=D.viewportKey;if(oe===T.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP)_<e.top&&((H=A==null?void 0:A.endRow)!=null?H:0)<((V=x==null?void 0:x.startRow)!=null?V:0)?y=e.top:re&&d%2===1&&e.scrollToViewportPos({viewportScrollY:0});else if(oe===T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT)C<e.left&&((L=A==null?void 0:A.endColumn)!=null?L:0)<((U=x==null?void 0:x.startColumn)!=null?U:0)?P=e.left:K&&c%2===1&&e.scrollToViewportPos({viewportScrollX:0});else if(oe===ae){let Z=!1,Y=!1;oe===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP?(Z=!0,Y=!0):oe===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP?Y=!0:oe===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT&&(Z=!0),((B=A==null?void 0:A.endRow)!=null?B:0)>((F=x==null?void 0:x.startRow)!=null?F:0)&&(Y=!1),((j=A==null?void 0:A.endColumn)!=null?j:0)>((X=x==null?void 0:x.startColumn)!=null?X:0)&&(Z=!1),Z&&(P=e.left),Y&&(y=e.top)}else{const Z={x:S.scrollX,y:S.scrollY},Y={x:D.scrollX,y:D.scrollY},q=Z.x!==Y.x&&K&&c%2===1,ne=Z.y!==Y.y&&re&&d%2===1;(q||ne)&&(e.scrollToBarPos({x:q?Z.x:void 0,y:ne?Z.y:void 0}),q||(P=e.left),ne||(y=e.top)),(oe===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&ae===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||ae===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&oe===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)&&(P=e.left),(oe===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&ae===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||ae===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&oe===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP)&&(y=e.top)}u=R,h=w}this._scrollTimer.scrolling(P,y,()=>{this._movingHandler(R,w,t,r)})})}attachSelectionWithCoord(e){return Te(e,this._skeleton)}attachPrimaryWithCoord(e){return cr(this._skeleton,e)}getSelectionCellByPosition(e,t){return this.getCellWithCoordByOffset(e,t)}getCellWithCoordByOffset(e,t,r){const i=this._scene,s=r!=null?r:this._skeleton,l=i.getViewportScrollXY(i.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:c,scaleY:d}=i.getAncestorScale();return s.getCellWithCoordByOffset(e-l.x,t-l.y,c,d,l)}_movingHandler(e,t,r,i){var P,y,M,x,A;const s=this._skeleton,l=this._scene,[c,d]=s.getLocation(),u={startRow:(P=r==null?void 0:r.model.startRow)!=null?P:-1,endRow:(y=r==null?void 0:r.model.endRow)!=null?y:-1,startColumn:(M=r==null?void 0:r.model.startColumn)!=null?M:-1,endColumn:(x=r==null?void 0:r.model.endColumn)!=null?x:-1},h=l.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=(A=this._getViewportByCell(u.endRow,u.endColumn))!=null?A:h,S=l.getScrollXYInfoByViewport(T.Vector2.FromArray([this._startViewportPosX,this._startViewportPosY]),g),{scaleX:p,scaleY:f}=l.getAncestorScale();i===a.RANGE_TYPE.ROW?e=Number.POSITIVE_INFINITY:i===a.RANGE_TYPE.COLUMN&&(t=Number.POSITIVE_INFINITY);const v=this._skeleton.getCellByOffset(e,t,p,f,S);if(!v)return;let C={startRow:Math.min(v.startRow,this._startRangeWhenPointerDown.startRow),startColumn:Math.min(v.startColumn,this._startRangeWhenPointerDown.startColumn),endRow:Math.max(v.endRow,this._startRangeWhenPointerDown.endRow),endColumn:Math.max(v.endColumn,this._startRangeWhenPointerDown.endColumn)};this._shouldDetectMergedCells&&(C=s.expandRangeByMerge(C,this.inRefSelectionMode()));const R=Te({range:C,primary:void 0,style:null},s);R.rangeWithCoord.unitId=c,R.rangeWithCoord.sheetId=d,R.rangeWithCoord.rangeType=i;const w=u.startRow!==C.startRow||u.startColumn!==C.startColumn||u.endRow!==C.endRow||u.endColumn!==C.endColumn;r!=null&&w&&(r.updateRangeBySelectionWithCoord(R),this._selectionMoving$.next(this.getSelectionDataWithStyle()))}_clearUpdatingListeners(){var t,r,i,s,l;this._scene.enableObjectsEvent(),(t=this._scenePointerMoveSub)==null||t.unsubscribe(),this._scenePointerMoveSub=null,(r=this._scenePointerUpSub)==null||r.unsubscribe(),this._scenePointerUpSub=null,(i=this._cancelDownSubscription)==null||i.unsubscribe(),this._cancelDownSubscription=null,(s=this._cancelUpSubscription)==null||s.unsubscribe(),this._cancelUpSubscription=null,(l=this._scrollTimer)==null||l.dispose()}_addEndingListeners(){var r,i,s;const e=this._scene,t=(r=e.getEngine())==null?void 0:r.activeScene;!t||t===e||((i=this._cancelDownSubscription)==null||i.unsubscribe(),this._cancelDownSubscription=null,(s=this._cancelUpSubscription)==null||s.unsubscribe(),this._cancelUpSubscription=null,this._cancelDownSubscription=t.onPointerDown$.subscribeEvent(()=>this._clearUpdatingListeners()),this._cancelUpSubscription=t.onPointerUp$.subscribeEvent(()=>this._clearUpdatingListeners()))}_getSelectionWithCoordByOffset(e,t,r,i,s){const l=this._skeleton;if(l==null)return null;if(this._shouldDetectMergedCells){const C=l==null?void 0:l.getCellWithCoordByOffset(e,t,r,i,s,{firstMatch:!0});if(!C)return;const _=a.convertCellToRange(C);return{primaryWithCoord:C,rangeWithCoord:_}}const{row:c,column:d}=l.getCellIndexByOffset(e,t,r,i,s),u=l.getNoMergeCellWithCoordByIndex(c,d),{startX:h,startY:g,endX:S,endY:p}=u,f={startY:g,endY:p,startX:h,endX:S,startRow:c,endRow:c,startColumn:d,endColumn:d};return{primaryWithCoord:{mergeInfo:f,actualRow:c,actualColumn:d,isMerged:!1,isMergedMainCell:!1,startY:g,endY:p,startX:h,endX:S},rangeWithCoord:f}}_checkClearPreviousControls(e){this.getSelectionControls().length!==0&&(!e.ctrlKey&&!e.shiftKey&&!this._remainLastEnabled||this._singleSelectionEnabled&&!e.shiftKey)&&this._clearAllSelectionControls()}_makeSelectionByTwoCells(e,t,r,i,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),g=Math.min(c,t.startColumn,d.startColumn),S=Math.max(c,t.endColumn,d.endColumn),f={range:r.expandRangeByMerge({startRow:u,startColumn:g,endRow:h,endColumn:S}),primary:m.convertPrimaryWithCoordToPrimary(e),style:null},v=Te(f,r);s.updateRangeBySelectionWithCoord(v)}isSelectionEnabled(){return this.contextService.getContextValue(m.SELECTIONS_ENABLED)}isSelectionDisabled(){return this.contextService.getContextValue(m.SELECTIONS_ENABLED)===!1}inRefSelectionMode(){return this.contextService.getContextValue(m.REF_SELECTIONS_ENABLED)}}function Ji(n){return{range:{startRow:0,startColumn:0,endRow:n.getRowCount()-1,endColumn:n.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL},primary:Ao(n).primary,style:null}}function Ao(n){return Ua(n,{startRow:0,startColumn:0,endRow:0,endColumn:0})}function Ua(n,o){const e=n.worksheet.getCellInfoInMergeData(o.startRow,o.startColumn),t=n.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 bd=Object.getOwnPropertyDescriptor,Rd=(n,o,e,t)=>{for(var r=t>1?void 0:t?bd(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},ks=(n,o)=>(e,t)=>o(e,t,n);exports.SheetSkeletonManagerService=class extends a.Disposable{constructor(e,t,r){super();E(this,"_sheetId","");E(this,"_sheetSkeletonParamStore",new Map);E(this,"_currentSkeleton$",new O.BehaviorSubject(null));E(this,"currentSkeleton$",this._currentSkeleton$.asObservable());E(this,"_currentSkeletonBefore$",new O.BehaviorSubject(null));E(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._context=e,this._injector=t,this._sheetSkService=r,this.disposeWithMe(()=>{this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._sheetSkeletonParamStore.forEach(i=>this.disposeSkeleton(i.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 r=this._getSkeletonParam(t);return r!=null&&(r.unitId=e),r}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),r=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:r,sheetId:e,skeleton:d,dirty:!1})}const i=this._getSkeletonParam(e);this._currentSkeletonBefore$.next(i),this._currentSkeleton$.next(i)}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 r=this._getSkeletonParam(e.sheetId);r!=null&&(r.dirty=t)}getOrCreateSkeleton(e){return this.ensureSkeleton(e.sheetId)}ensureSkeleton(e){const t=this._getSkeletonParam(e);if(t)return t.skeleton;const i=this._context.unit.getSheetBySheetId(e);if(!i)return;const s=this._buildSkeleton(i);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?Sn(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(T.SpreadsheetSkeleton,e,this._context.unit.getStyles())}setColumnHeaderSize(e,t,r){var u;if(!e)return;const i=(u=this.getWorksheetSkeleton(t))==null?void 0:u.skeleton;if(!i)return;i.columnHeaderHeight=r,e.scene.getViewports()[0].top=r,e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({height:r}),e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({height:r}),e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({top:r}),e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({top:r}),e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({height:r});const s=e==null?void 0:e.with(m.SheetsSelectionsService),l=e==null?void 0:e.with(ve),c=s.getCurrentSelections();l.resetSelectionsByModelData(c);const d=this.getUnitSkeleton(e.unitId,t);d&&(d.commandId=fr.id,this._currentSkeleton$.next(d))}setRowHeaderSize(e,t,r){var p;const i=(p=this.getWorksheetSkeleton(t))==null?void 0:p.skeleton;if(!e||!i)return;i.rowHeaderWidth=r;const s=e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).width||46,l=r-s,c=e.scene.getViewports()[0].left;e.scene.getViewports()[0].left=c+l,e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({width:r}),e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({width:r}),e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({left:r});const d=e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).left||0;e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({left:d+l}),e.scene.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({width:r});const u=e==null?void 0:e.with(m.SheetsSelectionsService),h=e==null?void 0:e.with(ve),g=u.getCurrentSelections();h.resetSelectionsByModelData(g);const S=this.getCurrent();S&&(S.commandId=pr.id,this._currentSkeleton$.next(S))}};exports.SheetSkeletonManagerService=Rd([ks(1,a.Inject(a.Injector)),ks(2,a.Inject(m.SheetSkeletonService))],exports.SheetSkeletonManagerService);var wd=Object.getOwnPropertyDescriptor,Ed=(n,o,e,t)=>{for(var r=t>1?void 0:t?wd(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Gn=(n,o)=>(e,t)=>o(e,t,n);const Ba=["ff","fs","tr","tb"];exports.AutoHeightController=class extends a.Disposable{constructor(o,e,t,r,i){super(),this._renderManagerService=o,this._sheetInterceptorService=e,this._selectionManagerService=t,this._univerInstanceService=r,this._configService=i,this._initialize()}_processLazyAutoHeight(o,e,t,r){if(r!=null&&r.length){const i={id:m.MarkDirtyRowAutoHeightMutation.id,params:{unitId:e,subUnitId:t,ranges:r,id:a.generateRandomId()},options:{onlyLocal:!0}},s={id:m.CancelMarkDirtyRowAutoHeightMutation.id,params:{unitId:e,subUnitId:t,id:i.params.id},options:{onlyLocal:!0}};return{redos:[...o.redos,i],undos:[...o.undos,s]}}return o}getUndoRedoParamsOfAutoHeight(o,e,t){const{_univerInstanceService:r}=this,i=r.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=i.getUnitId();let l=i.getActiveSheet(),c=l.getSheetId();if(e){const f=m.getSheetCommandTarget(r,{unitId:s,subUnitId:e});f&&(l=f.worksheet,c=l.getSheetId())}const u=this._renderManagerService.getRenderById(s).with(exports.SheetSkeletonManagerService).ensureSkeleton(c);if(!u)return{redos:[],undos:[]};const g=u.calculateAutoHeightInRange(o,t).filter(f=>{const{row:v,autoHeight:C}=f;return!(!C||l.getRowHeight(v)===C)});if(g.length===0)return{redos:[],undos:[]};const S={subUnitId:c,unitId:s,rowsAutoHeightInfo:g},p=m.SetWorksheetRowAutoHeightMutationFactory(S,l);return{undos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:p}],redos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:S}]}}_initialize(){this.disposeWithMe(this._sheetInterceptorService.interceptAutoHeight({getMutations:o=>{const{unitId:e,subUnitId:t,ranges:r,autoHeightRanges:i,lazyAutoHeightRanges:s,cellHeights:l}=o,c=this.getUndoRedoParamsOfAutoHeight(i!=null?i:r,t,l);return this._processLazyAutoHeight(c,e,t,s)}}))}};exports.AutoHeightController=Ed([Gn(0,T.IRenderManagerService),Gn(1,a.Inject(m.SheetInterceptorService)),Gn(2,a.Inject(m.SheetsSelectionsService)),Gn(3,a.Inject(a.IUniverInstanceService)),Gn(4,a.IConfigService)],exports.AutoHeightController);function pt(n){const{rows:o,cols:e}=n;return{startRow:o[0],endRow:o[o.length-1],startColumn:e[0],endColumn:e[e.length-1]}}function ft(n){let o=[],e=[];const t=[];return n.forEach(r=>{o=o.concat(r.rows),e=e.concat(r.cols)}),o=Array.from(new Set(o)).sort((r,i)=>r-i),e=Array.from(new Set(e)).sort((r,i)=>r-i),n.forEach(r=>{t.push({startRow:o.findIndex(i=>i===r.rows[0]),endRow:o.findIndex(i=>i===r.rows[r.rows.length-1]),startColumn:e.findIndex(i=>i===r.cols[0]),endColumn:e.findIndex(i=>i===r.cols[r.cols.length-1])})}),{ranges:t,mapFunc:(r,i)=>({row:o[r],col:e[i]})}}function yd(n){const o=new a.ObjectMatrix;return n.forEach(e=>{const{rows:t,cols:r}=e;t.forEach(i=>{r.forEach(s=>{o.setValue(i,s,{v:null,p:null,f:null,si:null,custom:null})})})}),o.getData()}const Ni={零:0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9},to=["零","一","二","三","四","五","六","七","八","九"],Hs=["","万","亿","万亿","亿亿"],Td=["","十","百","千"],Fa={十:{value:10,secUnit:!1},百:{value:100,secUnit:!1},千:{value:1e3,secUnit:!1},万:{value:1e4,secUnit:!0},亿:{value:1e8,secUnit:!0}};function tt(n){if(!n)return 0;let o=0,e=0,t=0,r=!1;const i=n.split("");for(let s=0;s<i.length;s++){const l=Ni[i[s]];if(typeof l<"u")t=l,s===i.length-1&&(e+=t);else{const c=Fa[i[s]],d=c.value;r=c.secUnit,r?(e=(e+t)*d,o+=e,e=0):e+=t*d,t=0}}return o+e}function Md(n){let o="",e="",t=0,r=!0;for(;n>0;){const i=n%10;i===0?r||(r=!0,e=to[i]+e):(r=!1,o=to[i],o+=Td[t],e=o+e),t++,n=Math.floor(n/10)}return e}function Pd(n){let o=0,e="",t="",r=!1;if(n===0)return to[0];for(;n>0;){const i=n%1e4;r&&(t=to[0]+t),e=Md(i),e+=i!==0?Hs[o]:Hs[0],t=e+t,r=i<1e3&&i>0,n=Math.floor(n/1e4),o++}return t}function xd(n){if(!n)return!1;let o=!0;if(n)if(n.length===1)n==="日"||n in Ni?o=!0:o=!1;else{const e=n.split("");for(let t=0;t<e.length;t++)if(!(e[t]in Ni||e[t]in Fa)){o=!1;break}}return o}function Ur(n){if(!n)return{isExtendNumber:!1};const o=/0|([1-9]+[0-9]*)/g,e=o.test(n);if(e){const t=n.match(o);if(t&&t.length>0){const r=t[t.length-1],i=n.lastIndexOf(r),s=n.substr(0,i),l=n.substr(i+r.length);return{isExtendNumber:!0,matchTxt:Number(r),beforeTxt:s,afterTxt:l}}return{isExtendNumber:!1}}return{isExtendNumber:e}}function Od(n){let o;return n.length===2&&(n==="周一"||n==="周二"||n==="周三"||n==="周四"||n==="周五"||n==="周六"||n==="周日")?o=!0:o=!1,o}function Ad(n){let o;return n.length===3&&(n==="星期一"||n==="星期二"||n==="星期三"||n==="星期四"||n==="星期五"||n==="星期六"||n==="星期日")?o=!0:o=!1,o}function Dd(n,o){let e=0;for(let t=0;t<n.length&&n[t]<o;t++)e++;return e}function Cr(n){let o=!0;const e=n[1]-n[0];for(let t=1;t<n.length;t++)if(n[t]-n[t-1]!==e){o=!1;break}return o}function Nd(n,o,e){const t=[],r=Math.floor(o/n),i=o%n;let s=0;if(r>0){for(let l=0;l<r;l++)for(let c=0;c<e.length;c++)t[e[c]+l*n]=s,s++;for(let l=0;l<e.length&&e[l]<i;l++)t[e[l]+n*r]=s,s++}else for(let l=0;l<e.length&&e[l]<i;l++)t[e[l]]=s,s++;return t}function Ht(n,o){const e=[];for(let t=1;t<=o;t++){const r=(t-1)%n.length,i=a.Tools.deepClone(n[r]);Vt(i),e.push({v:null,s:null,p:null,f:null,si:null,t:null,...i})}return e}function kd(n,o){var t;const e=[];for(let r=1;r<=o;r++){const i=(r-1)%n.length,s={s:(t=n[i])==null?void 0:t.s};e.push(s)}return e}function Hd(n){let o=!0;const e=n[1]/n[0];for(let t=1;t<n.length;t++)if(n[t]/n[t-1]!==e){o=!1;break}return o}function Vd(n){const o=[];for(let e=1;e<=n;e++)o.push(e);return o}function no(n,o,e){var i,s,l,c;const t=[],r=[];for(let d=0;d<n.length;d++)r.push(Number((i=n[d])==null?void 0:i.v));if(n.length>2&&Hd(r))for(let d=1;d<=o;d++){const u=(d-1)%n.length,h=a.Tools.deepClone(n[u]);Vt(h);const g=Number((s=n[n.length-1])==null?void 0:s.v)*(Number((l=n[1])==null?void 0:l.v)/Number((c=n[0])==null?void 0:c.v))**d;h&&(Us(h)&&(h.v=g),t.push(h))}else{const d=Vd(n.length);for(let u=1;u<=o;u++){const h=(u-1)%n.length,g=a.Tools.deepClone(n[h]);Vt(g);const S=e===a.Direction.DOWN||e===a.Direction.RIGHT,p=Wd(n.length+u,r,d,S);g&&(Us(g)&&(g.v=p),t.push(g))}}return t}function Wd(n,o,e,t=!0){function r(h){let g=0;for(let S=0;S<h.length;S++)g+=h[S];return g/h.length}const i=r(e),s=r(o);let l=0,c=0;for(let h=0;h<e.length;h++)l+=(e[h]-i)*(o[h]-s),c+=(e[h]-i)*(e[h]-i);let d;c===0?d=t?1:-1:d=l/c;const u=s-d*i;return Math.round((u+d*n)*1e5)/1e5}function Vs(n,o,e){var i;const t=[],r=/0|([1-9]+[0-9]*)/g;for(let s=1;s<=o;s++){const l=(s-1)%n.length,c=a.Tools.deepClone(n[l]);Vt(c);const d=`${(i=n[n.length-1])==null?void 0:i.v}`;if(!d)continue;const u=d==null?void 0:d.match(r),h=u==null?void 0:u[u.length-1];if(!h)continue;const g=Math.abs(Number(h)+e*s),S=d.lastIndexOf(h),p=d.substr(0,S)+g.toString()+d.substr(S+h.length);c&&(c.v=p,t.push(c))}return t}function pn(n,o,e,t=0){var l,c;const r=[["日","一","二","三","四","五","六"],["周日","周一","周二","周三","周四","周五","周六"],["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]];if(t>=r.length)return[];const i=r[t],s=[];for(let d=1;d<=o;d++){const u=(d-1)%n.length,h=a.Tools.deepClone(n[u]);Vt(h);let g=0;if(((l=n[n.length-1])==null?void 0:l.v)===i[0])g=7+e*d;else{const p=`${(c=n[n.length-1])==null?void 0:c.v}`;if(p){const f=p.substr(p.length-1,1);g=tt(f)+e*d}}g<0&&(g=Math.ceil(Math.abs(g)/7)*7+g);const S=g%7;h&&(h.v=i[S],s.push(h))}return s}function Ws(n,o,e){var r;const t=[];for(let i=1;i<=o;i++){const s=(i-1)%n.length,l=a.Tools.deepClone(n[s]);Vt(l);const c=`${(r=n[n.length-1])==null?void 0:r.v}`,d=tt(c)+e*i;let u;d<=0?u="零":u=Pd(d),l&&(l.v=u,t.push(l))}return t}const ir={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 Ld(n){let o=!1;return Object.keys(ir).forEach(e=>{ir[e].includes(n)&&(o=!0)}),o}function zo(n){let o="";const e=[];return Object.keys(ir).forEach(t=>{ir[t].includes(n)&&(o=t,e.push(...ir[t]))}),{name:o,series:e}}function Ls(n,o,e,t){var s;const r=t.length,i=[];for(let l=1;l<=o;l++){const c=(l-1)%n.length,d=a.Tools.deepClone(n[c]);Vt(d);const u=`${(s=n[n.length-1])==null?void 0:s.v}`;let h=t.indexOf(u)+e*l;h<0&&(h+=Math.abs(e)*r);const g=h%r;d&&(d.v=t[g],i.push(d))}return i}function Ud(n,o){const e=[];let t;if(o.startRow<n.startRow)t=a.Direction.UP;else if(o.endRow>n.endRow)t=a.Direction.DOWN;else if(o.startColumn<n.startColumn)t=a.Direction.LEFT;else if(o.endColumn>n.endColumn)t=a.Direction.RIGHT;else return[];if(t===a.Direction.DOWN||t===a.Direction.UP){const r=n.endRow-n.startRow+1,i=o.endRow-o.startRow+1,s=Math.floor(i/r),l=i%r,c={startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:n.endColumn-n.startColumn};if(t===a.Direction.DOWN){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow+(d+1)*r,col:n.startColumn},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow+(s+1)*r,col:n.startColumn},relativeRange:{startRow:0,startColumn:0,endRow:l-1,endColumn:n.endColumn-n.startColumn}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow-(d+1)*r,col:n.startColumn},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow-(s+1)*r,col:n.startColumn},relativeRange:{startRow:r-l,endRow:r-1,startColumn:0,endColumn:n.endColumn-n.startColumn}})}}if(t===a.Direction.RIGHT||t===a.Direction.LEFT){const r=n.endColumn-n.startColumn+1,i=o.endColumn-o.startColumn+1,s=Math.floor(i/r),l=i%r,c={startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:n.endColumn-n.startColumn};if(t===a.Direction.RIGHT){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow,col:n.startColumn+(d+1)*r},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow,col:n.startColumn+(s+1)*r},relativeRange:{startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:l-1}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow,col:n.startColumn-(d+1)*r},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow,col:n.startColumn-(s+1)*r},relativeRange:{startRow:0,startColumn:r-l,endRow:n.endRow-n.startRow,endColumn:r-1}})}}return e}function Us(n){return!(a.isFormulaString(n.f)||a.isFormulaId(n.si)||n.t===a.CellValueType.BOOLEAN)}function Vt(n){n&&"custom"in n&&delete n.custom}var an=(n=>(n.Append="APPEND",n.Default="DEFAULT",n.Only="ONLY",n))(an||{}),Ce=(n=>(n.NUMBER="number",n.DATE="date",n.EXTEND_NUMBER="extendNumber",n.CHN_NUMBER="chnNumber",n.CHN_WEEK2="chnWeek2",n.CHN_WEEK3="chnWeek3",n.LOOP_SERIES="loopSeries",n.FORMULA="formula",n.OTHER="other",n))(Ce||{}),se=(n=>(n.COPY="COPY",n.SERIES="SERIES",n.ONLY_FORMAT="ONLY_FORMAT",n.NO_FORMAT="NO_FORMAT",n))(se||{});const Bd={type:Ce.DATE,priority:1100,match:(n,o)=>{var e;if(n!=null&&n.f||n!=null&&n.si)return!1;if((typeof(n==null?void 0:n.v)=="number"||(n==null?void 0:n.t)===a.CellValueType.NUMBER)&&n.s){if(typeof n.s=="string"){const r=o.get(a.IUniverInstanceService).getFocusedUnit().getStyles().get(n.s),i=(e=r==null?void 0:r.n)==null?void 0:e.pattern;if(i)return a.numfmt.getFormatInfo(i).isDate}else if(n.s.n&&a.numfmt.getFormatInfo(n.s.n.pattern).isDate)return!0}return!1},isContinue:(n,o)=>n.type===Ce.DATE,applyFunctions:{[se.SERIES]:(n,o,e)=>{const{data:t}=n;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),no(t,o,e).reverse()):no(t,o,e)}}},Fd={type:Ce.NUMBER,priority:1e3,match:n=>typeof(n==null?void 0:n.v)=="number"||(n==null?void 0:n.t)===a.CellValueType.NUMBER,isContinue:(n,o)=>n.type===Ce.NUMBER,applyFunctions:{[se.SERIES]:(n,o,e)=>{const{data:t}=n;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),no(t,o,e).reverse()):no(t,o,e)}}},ja={type:Ce.OTHER,priority:0,match:()=>!0,isContinue:(n,o)=>n.type===Ce.OTHER},jd={type:Ce.EXTEND_NUMBER,priority:900,match:n=>Ur(`${n==null?void 0:n.v}`||"").isExtendNumber,isContinue:(n,o)=>{var e;if(n.type===Ce.EXTEND_NUMBER){const{beforeTxt:t,afterTxt:r}=Ur(`${(e=n.cellData)==null?void 0:e.v}`||""),{beforeTxt:i,afterTxt:s}=Ur(`${o==null?void 0:o.v}`||"");if(t===i&&r===s)return!0}return!1},applyFunctions:{[se.SERIES]:(n,o,e)=>{var l;const{data:t}=n,r=e===a.Direction.UP||e===a.Direction.LEFT;let i;if(t.length===1)return i=r?-1:1,De(Vs(t,o,i),r);const s=[];for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`;d&&s.push(Number(Ur(d).matchTxt))}return r&&(t.reverse(),s.reverse()),Cr(s)?(i=s[1]-s[0],De(Vs(t,o,i),r)):Ht(t,o)}}},zd={type:Ce.CHN_NUMBER,priority:830,match:n=>!!xd(`${n==null?void 0:n.v}`||""),isContinue:(n,o)=>n.type===Ce.CHN_NUMBER,applyFunctions:{[se.SERIES]:(n,o,e)=>{var c,d,u;const{data:t}=n,r=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){const h=`${(c=t[0])==null?void 0:c.v}`;let g;return r?g=-1:g=1,h&&(h==="日"||tt(h)<7)?De(pn(t,o,g),r):De(Ws(t,o,g),r)}let i=!1;for(let h=0;h<t.length;h++)if(((d=t[h])==null?void 0:d.v)==="日"){i=!0;break}const s=[];let l=0;for(let h=0;h<t.length;h++){const g=`${(u=t[h])==null?void 0:u.v}`;g==="日"?h===0?s.push(0):(l++,s.push(l*7)):i&&tt(g)>0&&tt(g)<7?s.push(tt(g)+l*7):s.push(tt(g))}if(r&&(t.reverse(),s.reverse()),Cr(s)){if(i||s[s.length-1]<6&&s[0]>0||s[0]<6&&s[s.length-1]>0){const g=s[1]-s[0];return De(pn(t,o,g),r)}const h=s[1]-s[0];return De(Ws(t,o,h),r)}return Ht(t,o)}}},Xd={type:Ce.CHN_WEEK2,priority:820,match:n=>!!Od(`${n==null?void 0:n.v}`||""),isContinue:(n,o)=>n.type===Ce.CHN_WEEK2,applyFunctions:{[se.SERIES]:(n,o,e)=>{var l;const{data:t}=n,r=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let c;return r?c=-1:c=1,De(pn(t,o,c,1),r)}const i=[];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?i.push(0):(s++,i.push(s*7)):i.push(tt(u)+s*7)}if(r&&(t.reverse(),i.reverse()),Cr(i)){const c=i[1]-i[0];return De(pn(t,o,c,1),r)}return Ht(t,o)}}},Yd={type:Ce.CHN_WEEK3,priority:810,match:n=>Ad(`${n==null?void 0:n.v}`||""),isContinue:(n,o)=>n.type===Ce.CHN_WEEK3,applyFunctions:{[se.SERIES]:(n,o,e)=>{var l;const{data:t}=n,r=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let c;return r?c=-1:c=1,De(pn(t,o,c,2),r)}const i=[];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?i.push(0):(s++,i.push(s*7)):i.push(tt(u)+s*7)}}if(r&&(t.reverse(),i.reverse()),Cr(i)){const c=i[1]-i[0];return De(pn(t,o,c,2),r)}return Ht(t,o)}}},Zd={type:Ce.LOOP_SERIES,priority:800,match:n=>Ld(`${n==null?void 0:n.v}`||""),isContinue:(n,o)=>{var e;return n.type===Ce.LOOP_SERIES?zo(`${(e=n.cellData)==null?void 0:e.v}`||"").name===zo(`${o==null?void 0:o.v}`||"").name:!1},applyFunctions:{[se.SERIES]:(n,o,e)=>{var c,d;const{data:t}=n,r=e===a.Direction.LEFT||e===a.Direction.UP,{series:i}=zo(`${(c=t[0])==null?void 0:c.v}`||"");if(t.length===1){let u;return r?u=-1:u=1,De(Ls(t,o,u,i),r)}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===i[0]?u===0?s.push(0):(l++,s.push(l*i.length)):s.push(i.indexOf(h)+l*7))}if(r&&(t.reverse(),s.reverse()),Cr(s)){const u=s[1]-s[0];return De(Ls(t,o,u,i),r)}return Ht(t,o)}}};function De(n,o){return o?n.reverse():n}var Gd=Object.getOwnPropertyDescriptor,Kd=(n,o,e,t)=>{for(var r=t>1?void 0:t?Gd(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Jt=(n,o)=>(e,t)=>o(e,t,n);exports.AutoFillService=class extends a.Disposable{constructor(e,t,r,i,s,l){super();E(this,"_rules",[]);E(this,"_hooks",[]);E(this,"_applyType$",new O.BehaviorSubject(se.SERIES));E(this,"_isFillingStyle",!0);E(this,"_prevUndos",[]);E(this,"_autoFillLocation$",new O.BehaviorSubject(null));E(this,"autoFillLocation$",this._autoFillLocation$.asObservable());E(this,"_showMenu$",new O.BehaviorSubject(!1));E(this,"showMenu$",this._showMenu$.asObservable());E(this,"_direction",a.Direction.DOWN);E(this,"applyType$",this._applyType$.asObservable());E(this,"_menu$",new O.BehaviorSubject([{label:"autoFill.copy",value:se.COPY,disable:!1},{label:"autoFill.series",value:se.SERIES,disable:!1},{label:"autoFill.formatOnly",value:se.ONLY_FORMAT,disable:!1},{label:"autoFill.noFormat",value:se.NO_FORMAT,disable:!1}]));E(this,"menu$",this._menu$.asObservable());this._commandService=e,this._undoRedoService=t,this._renderManagerService=r,this._univerInstanceService=i,this._selectionManagerService=s,this._injector=l,this._init()}_init(){this._rules=[Bd,Fd,jd,zd,Xd,Yd,Zd,ja].sort((e,t)=>t.priority-e.priority),this._isFillingStyle=!0}_getOneByPriority(e){return e.length<=0?[]:[e.reduce((r,i)=>(i.priority||0)>(r.priority||0)?i:r,e[0])]}_initPrevUndo(){this._prevUndos=[]}async triggerAutoFill(e,t,r,i,s){var p;if(r.startColumn===i.startColumn&&r.startRow===i.startRow&&r.endColumn===i.endColumn&&r.endRow===i.endRow)return!1;if(i.endColumn<r.endColumn&&i.endColumn>r.startColumn)return this._commandService.executeCommand(fn.id,{clearRange:{startRow:i.startRow,endRow:i.endRow,startColumn:i.endColumn+1,endColumn:r.endColumn},selectionRange:i});if(i.endRow<r.endRow&&i.endRow>r.startRow)return this._commandService.executeCommand(fn.id,{clearRange:{startRow:i.endRow+1,endRow:r.endRow,startColumn:i.startColumn,endColumn:i.endColumn},selectionRange:i});const l={startRow:i.startRow,endRow:i.endRow,startColumn:i.startColumn,endColumn:i.endColumn};let c=null;if(i.startRow<r.startRow)c=a.Direction.UP,l.endRow=r.startRow-1;else if(i.endRow>r.endRow)c=a.Direction.DOWN,l.startRow=r.endRow+1;else if(i.startColumn<r.startColumn)c=a.Direction.LEFT,l.endColumn=r.startColumn-1;else if(i.endColumn>r.endColumn)c=a.Direction.RIGHT,l.startColumn=r.endColumn+1;else return!1;this.direction=c;const d=this._injector.invoke(f=>m.rangeToDiscreteRange(r,f)),u=this._injector.invoke(f=>m.rangeToDiscreteRange(l,f));if(!d||!u)return!1;this.autoFillLocation={source:d,target:u,unitId:e,subUnitId:t};const h=[];if(this.getActiveHooks().forEach(f=>{var C;const v=(C=f==null?void 0:f.onBeforeFillData)==null?void 0:C.call(f,{source:d,target:u,unitId:e,subUnitId:t},c);v&&h.unshift(v)}),this._initPrevUndo(),s)return this.fillData(s);for(let f=0;f<h.length;f++){const v=this.menu.find(C=>C.value===h[f]);if(v&&!v.disable)return this.fillData(h[f])}const S=(p=this.menu.find(f=>f.disable===!1))==null?void 0:p.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=an.Append),this._hooks.push(e),a.toDisposable(()=>{const t=this._hooks.findIndex(r=>r===e);t>-1&&this._hooks.splice(t,1)})}registerRule(e){if(this._rules.find(r=>r.type===e.type))throw new Error(`Registry rule failed, type '${e.type}' already exist!`);const t=this._rules.findIndex(r=>r.priority<e.priority);this._rules.splice(t===-1?this._rules.length:t,0,e)}getRules(){return this._rules}getAllHooks(){return this._hooks}getActiveHooks(){const{source:e,target:t,unitId:r,subUnitId:i}=this.autoFillLocation||{};if(!e||!t||!r||!i)return[];const s=this._hooks.filter(u=>{var h;return!((h=u.disable)!=null&&h.call(u,{source:e,target:t,unitId:r,subUnitId:i},this._direction,this.applyType))}),l=s.filter(u=>u.type===an.Only);if(l.length>0)return this._getOneByPriority(l);const c=this._getOneByPriority(s.filter(u=>u.type===an.Default)),d=s.filter(u=>u.type===an.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(r=>r.value===e?{...r,disable:t}:r))}setShowMenu(e){this._showMenu$.next(e)}fillData(e){var w,P,y;this.applyType=e;const t=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),r=t==null?void 0:t.getUnitId(),i=(w=t==null?void 0:t.getActiveSheet())==null?void 0:w.getSheetId(),{source:s,target:l,unitId:c=r,subUnitId:d=i}=this.autoFillLocation||{};if(!s||!l||!c||!d)return!1;const u=this.direction;this._prevUndos.length>0&&this._prevUndos.forEach(M=>{this._commandService.syncExecuteCommand(M.id,M.params)}),this._prevUndos=[];const h=a.Rectangle.union(pt(s),pt(l)),g=this.getActiveHooks(),S=this._univerInstanceService.getUnit(c,a.UniverInstanceType.UNIVER_SHEET);c===r&&d===i&&this._commandService.syncExecuteCommand(m.SetSelectionsOperation.id,{selections:[{primary:{...(y=(P=this._selectionManagerService.getCurrentLastSelection())==null?void 0:P.primary)!=null?y:h},range:{...h,rangeType:a.RANGE_TYPE.NORMAL}}],unitId:c,subUnitId:d});const p=[],f=[];g.forEach(M=>{var D;const{undos:x,redos:A}=((D=M.onFillData)==null?void 0:D.call(M,{source:s,target:l,unitId:c,subUnitId:d},u,e))||{};x&&p.push(...x),A&&f.push(...A)});const v=f.every(M=>this._commandService.syncExecuteCommand(M.id,M.params)),C=[];e!==se.NO_FORMAT&&f.forEach(M=>{if(M.id===m.SetRangeValuesMutation.id){const{cellValue:x}=M.params;new a.ObjectMatrix(x).forValue((D,N,k)=>{const H=Object.keys(S.getStyles().get(k==null?void 0:k.s)||{});(k!=null&&k.p||H.length&&Ba.some(V=>H.includes(V)))&&C.push({startRow:D,endRow:D,startColumn:N,endColumn:N})})}});const _=this._getAutoHeightUndoRedos(c,d,C);return _.redos.every(M=>this._commandService.syncExecuteCommand(M.id,M.params))&&(p.push(..._.undos),f.push(..._.redos)),v&&(this._prevUndos=p,this._undoRedoService.pushUndoRedo({unitID:c,undoMutations:p,redoMutations:f})),g.forEach(M=>{var x;(x=M.onAfterFillData)==null||x.call(M,{source:s,target:l,unitId:c,subUnitId:d},u,e)}),this.setShowMenu(!0),!0}_getAutoHeightUndoRedos(e,t,r){var h,g;const i=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(exports.SheetSkeletonManagerService),s=(g=i==null?void 0:i.getCurrentParam())==null?void 0:g.skeleton;if(!s)return{redos:[],undos:[]};const l=s.calculateAutoHeightInRange(r),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}]}}};exports.AutoFillService=Kd([Jt(0,a.ICommandService),Jt(1,a.IUndoRedoService),Jt(2,T.IRenderManagerService),Jt(3,a.Inject(a.IUniverInstanceService)),Jt(4,a.Inject(m.SheetsSelectionsService)),Jt(5,a.Inject(a.Injector))],exports.AutoFillService);const vt=a.createIdentifier("univer.auto-fill-service"),ht={type:a.CommandType.COMMAND,id:"sheet.command.auto-fill",handler:async(n,o)=>{const e=n.get(vt),t=n.get(a.IUniverInstanceService),{sourceRange:r,targetRange:i,applyType:s}=o,l=m.getSheetCommandTarget(t,o);if(!l)return!1;const{subUnitId:c,unitId:d}=l;return e.triggerAutoFill(d,c,r,i,s)}},fn={id:"sheet.command.auto-clear-content",type:a.CommandType.COMMAND,handler:async(n,o)=>{const e=n.get(a.IUniverInstanceService),t=n.get(a.ICommandService),r=n.get(a.IUndoRedoService),i=n.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])},g=m.SetRangeValuesUndoMutationFactory(n,h),{startColumn:S,startRow:p}=u,f={selections:[{primary:{startColumn:S,startRow:p,endColumn:S,endRow:p,actualRow:p,actualColumn:S,isMerged:!1,isMergedMainCell:!1},range:{...u}}],unitId:l,subUnitId:c};if(t.executeCommand(m.SetSelectionsOperation.id,f),t.syncExecuteCommand(m.SetRangeValuesMutation.id,h)){const C=i.afterCommandExecute({id:m.SetRangeValuesMutation.id,params:h});return a.sequenceExecute(C.redos,t),r.pushUndoRedo({unitID:l,undoMutations:[{id:m.SetRangeValuesMutation.id,params:g},...C.undos],redoMutations:[{id:m.SetRangeValuesMutation.id,params:h},...C.redos]}),!0}return!1}};function $i(n){return n.getContextValue(a.FOCUSING_SHEET)}function ie(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function za(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function qd(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function es(n){return n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function Do(n){return n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function Qd(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.EDITOR_ACTIVATED)&&n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function vn(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&!n.getContextValue(a.FOCUSING_EDITOR_STANDALONE)}var Jd=Object.getOwnPropertyDescriptor,$d=(n,o,e,t)=>{for(var r=t>1?void 0:t?Jd(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Xo=(n,o)=>(e,t)=>o(e,t,n);const Bs=qi.MARK_SELECTION,jt=a.createIdentifier("univer.mark-selection-service");exports.MarkSelectionService=class extends a.Disposable{constructor(e,t,r){super();E(this,"_shapeMap",new Map);this._currentService=e,this._renderManagerService=t,this._themeService=r}addShape(e,t=[],r=Bs){var d;const i=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=(d=i.getActiveSheet())==null?void 0:d.getSheetId();if(!s)return null;const l=a.generateRandomId(),c={selection:e,subUnitId:s,unitId:i.getUnitId(),zIndex:r,control:null,exits:t};return this._shapeMap.set(l,c),this.refreshShapes(),l}addShapeWithNoFresh(e,t=[],r=Bs){var c;const i=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=(c=i.getActiveSheet())==null?void 0:c.getSheetId();if(!s)return null;const l=a.generateRandomId();return this._shapeMap.set(l,{selection:e,subUnitId:s,unitId:i.getUnitId(),zIndex:r,control:null,exits:t}),l}refreshShapes(){var i;const e=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!e)return;const t=e.getUnitId(),r=(i=e.getActiveSheet())==null?void 0:i.getSheetId();this._shapeMap.forEach(s=>{const{unitId:l,subUnitId:c,selection:d,control:u,zIndex:h}=s;if(u==null||u.dispose(),l!==t||c!==r)return;const g=this._renderManagerService.getRenderById(l);if(!g)return;const S=g.with(exports.SheetSkeletonManagerService).getCurrentSkeleton();if(!S)return;const{scene:p}=g,{rowHeaderWidth:f,columnHeaderHeight:v}=S,C=new vr(p,h,this._themeService,{enableAutoFill:!1,highlightHeader:!1,rowHeaderWidth:f,columnHeaderHeight:v}),_=Te(d,S);C.updateRangeBySelectionWithCoord(_),s.control=C})}getShapeMap(){return this._shapeMap}removeShape(e){const t=this._shapeMap.get(e);if(!t)return;const{control:r}=t;r==null||r.dispose(),this._shapeMap.delete(e)}removeAllShapes(){for(const e of this._shapeMap.values()){const{control:t}=e;t==null||t.dispose()}this._shapeMap.clear()}};exports.MarkSelectionService=$d([Xo(0,a.IUniverInstanceService),Xo(1,T.IRenderManagerService),Xo(2,a.Inject(a.ThemeService))],exports.MarkSelectionService);function Xa(n){return{strokeWidth:1.5,stroke:n.getColorFromTheme("primary.600"),fill:"rgba(178, 178, 178, 0.10)",widgets:{},strokeDash:8}}function eu(n){if(n==null)return n;const o={};return n.p!==void 0&&(o.p=n.p===null?null:a.cloneValue(n.p)),n.s!==void 0&&(n.s===null||typeof n.s=="string"?o.s=n.s:o.s=a.cloneValue(n.s)),n.v!==void 0&&(o.v=n.v),n.t!==void 0&&(o.t=n.t),n.f!==void 0&&(o.f=n.f),n.ref!==void 0&&(o.ref=n.ref),n.xf!==void 0&&(o.xf=n.xf),n.si!==void 0&&(o.si=n.si),n.custom!==void 0&&(o.custom=n.custom===null?null:a.cloneValue(n.custom)),n.rowSpan!==void 0&&(o.rowSpan=n.rowSpan),n.colSpan!==void 0&&(o.colSpan=n.colSpan),n.plain!==void 0&&(o.plain=n.plain),o}const tu=10,nu=6;function ru(){return a.generateRandomId(nu)}function ou(n){const o=n.match(/data-copy-id="([^\s]+)"/);return o&&o[1]?o[1]:null}class iu{constructor(){E(this,"_cache",new a.LRUMap(tu));E(this,"_lastCopyId$",new O.BehaviorSubject(null));E(this,"lastCopyId$",this._lastCopyId$.asObservable())}set(o,e){this._cache.set(o,e),this._lastCopyId$.next(o)}get(o){return this._cache.get(o)}del(o){this._cache.delete(o),this._lastCopyId$.getValue()===o&&this._lastCopyId$.next(null)}clear(){this._cache.clear(),this._lastCopyId$.next(null)}clearWithUnitId(o){this._cache.forEach((e,t)=>{e.unitId===o&&this._cache.delete(t)})}getLastCopyId(){return this._lastCopyId$.getValue()}}function ro(n,o){const e=o!=null?o:n.style,t={},r=n.tagName.toLowerCase();switch(r){case"b":case"em":case"strong":{t.bl=a.BooleanNumber.TRUE;break}case"s":{t.st={s:a.BooleanNumber.TRUE};break}case"u":{t.ul={s:a.BooleanNumber.TRUE};break}case"i":{t.it=a.BooleanNumber.TRUE;break}case"sub":case"sup":{t.va=r==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}return su(e,t),t}function su(n,o){if(n instanceof CSSStyleDeclaration)for(let e=0;e<n.length;e++){const t=n[e],r=n.getPropertyValue(t);Fs(t,r,o)}else for(const e in n){const t=n[e];Fs(e,t,o)}}function Fs(n,o,e){switch(n){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);t.isValid&&(e.bg={rgb:t.toRgbString()});break}}}function au(n){const o=document.createElement("body");return o.innerHTML=n,o}function Ya(n){const o=n.style,e={};for(let t=0;t<o.length;t++){const r=o[t],i=o.getPropertyValue(r);switch(r){case"margin-top":{const s=Number.parseInt(i);e.spaceAbove={v:/pt/.test(i)?T.ptToPixel(s):s};break}case"margin-bottom":{const s=Number.parseInt(i);e.spaceBelow={v:/pt/.test(i)?T.ptToPixel(s):s};break}case"line-height":{const s=Number.parseFloat(i);e.lineSpacing=s;break}}}return Object.getOwnPropertyNames(e).length?e:null}function Yo(n,o){const e=[];for(let t=0,r=n.length;t<r;t++)n[t]===a.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});return e}function js(n,o,e){var s,l,c;const t=o.length,i=((s=e==null?void 0:e.length)!=null?s:0)===1&&e[0].st===0&&e[0].ed===t;return n.p?i&&((c=(l=n.p.body)==null?void 0:l.textRuns)!=null&&c.length)?(n.p.body.textRuns=[],{...n,s:e[0].ts}):n:i?{...n,s:e[0].ts}:n}const zs=["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 Xs(n,o){const e=n.tagName.toLowerCase();return typeof o=="string"?e===o:Array.isArray(o)?o.some(t=>t===e):o(n)}const Po=class Po{constructor(o){E(this,"_styleMap",new Map);E(this,"_styleCache",new Map);E(this,"_styleRules",[]);E(this,"_afterProcessRules",[]);E(this,"_dom",null);E(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=Po._pluginList.find(f=>f.checkPasteType(o));e&&(this._styleRules=[...e.stylesRules],this._afterProcessRules=[...e.afterProcessRules]);const t=new a.ObjectMatrix;this._dom=au(o);const r=this._dom.querySelector("style");if(r){const f=document.createElement("div"),v=f.attachShadow({mode:"open"});document.body.appendChild(f),v.appendChild(r);for(const C of r.sheet.cssRules){const _=C,R=_.selectorText,w=_.style;this._styleMap.set(R,w)}r.remove(),f.remove()}const i={dataStream:"",textRuns:[]},s=[],l=[],c=o.match(/<table\b[^>]*>([\s\S]*?)<\/table>/gi),d=[];this.process(null,this._dom.childNodes,i,d);const{paragraphs:u,dataStream:h,textRuns:g,payloads:S,customRanges:p}=i;if(u){const f=u.map(v=>v.startIndex+1);f.unshift(0);for(let v=0;v<f.length;v++){let C;if(v===f.length-1){if(C=`${h.substring(f[v])}\r
2
2
  `,C===`\r
3
3
  `)continue}else C=`${h.substring(f[v],f[v+1]-1)}\r
4
4
  `;const _=[];g==null||g.forEach(y=>{y.st>=f[v]&&y.ed<=f[v+1]&&_.push({st:y.st-f[v],ed:y.ed-f[v],ts:y.ts})});const R=[];p==null||p.forEach(y=>{y.startIndex>=f[v]&&y.endIndex<=f[v+1]&&R.push({...y,startIndex:y.startIndex-f[v],endIndex:y.endIndex-f[v]})});const w=this._generateDocumentDataModelSnapshot({body:{dataStream:C,textRuns:_,paragraphs:Yo(C),customRanges:R}}),P=Object.keys(t.getMatrix()).length===0;t.setValue(P?0:t.getLength(),0,{v:C,p:w}),s.push({})}}else if(h){const f=`${h}\r
package/lib/es/index.js CHANGED
@@ -1697,7 +1697,7 @@ class Om extends ae {
1697
1697
  }
1698
1698
  getCellWithCoordByOffset(t, r, o) {
1699
1699
  const i = this._scene, s = o != null ? o : this._skeleton, l = i.getViewportScrollXY(i.getViewport(z.VIEW_MAIN)), { scaleX: a, scaleY: c } = i.getAncestorScale();
1700
- return s.getCellWithCoordByOffset(t, r, a, c, l);
1700
+ return s.getCellWithCoordByOffset(t - l.x, r - l.y, a, c, l);
1701
1701
  }
1702
1702
  /**
1703
1703
  * When mousedown and mouseup need to go to the coordination and undo stack, when mousemove does not need to go to the coordination and undo stack
package/lib/index.js CHANGED
@@ -1697,7 +1697,7 @@ class Om extends ae {
1697
1697
  }
1698
1698
  getCellWithCoordByOffset(t, r, o) {
1699
1699
  const i = this._scene, s = o != null ? o : this._skeleton, l = i.getViewportScrollXY(i.getViewport(z.VIEW_MAIN)), { scaleX: a, scaleY: c } = i.getAncestorScale();
1700
- return s.getCellWithCoordByOffset(t, r, a, c, l);
1700
+ return s.getCellWithCoordByOffset(t - l.x, r - l.y, a, c, l);
1701
1701
  }
1702
1702
  /**
1703
1703
  * When mousedown and mouseup need to go to the coordination and undo stack, when mousemove does not need to go to the coordination and undo stack
package/lib/umd/index.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(E,q){typeof exports=="object"&&typeof module<"u"?q(exports,require("@univerjs/docs-ui"),require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-render"),require("rxjs"),require("@univerjs/ui"),require("@univerjs/docs"),require("react"),require("@univerjs/engine-formula"),require("react/jsx-runtime"),require("@univerjs/design"),require("rxjs/operators"),require("@univerjs/telemetry")):typeof define=="function"&&define.amd?define(["exports","@univerjs/docs-ui","@univerjs/core","@univerjs/sheets","@univerjs/engine-render","rxjs","@univerjs/ui","@univerjs/docs","react","@univerjs/engine-formula","react/jsx-runtime","@univerjs/design","rxjs/operators","@univerjs/telemetry"],q):(E=typeof globalThis<"u"?globalThis:E||self,q(E.UniverSheetsUi={},E.UniverDocsUi,E.UniverCore,E.UniverSheets,E.UniverEngineRender,E.rxjs,E.UniverUi,E.UniverDocs,E.React,E.UniverEngineFormula,E.React,E.UniverDesign,E.rxjs.operators,E.UniverTelemetry))})(this,(function(E,q,a,m,M,D,I,be,x,K,b,Y,ce,ud){"use strict";var wp=Object.defineProperty;var Ep=(E,q,a)=>q in E?wp(E,q,{enumerable:!0,configurable:!0,writable:!0,value:a}):E[q]=a;var T=(E,q,a)=>Ep(E,typeof q!="symbol"?q+"":q,a);function Ui(n,o){if(n==null)return;const e=o.getRenderById(n);if(e==null)return;const{mainComponent:t,scene:i,engine:r,components:s}=e,l=t,c=s.get(q.DOCS_VIEW_KEY.BACKGROUND);return{document:l,docBackground:c,scene:i,engine:r}}const Yo=[10,400],jo="RANGE_SELECTOR_COMPONENT_KEY",Bi="EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY";var ue=(n=>(n.MAIN="__SpreadsheetRender__",n.ROW="__SpreadsheetRowHeader__",n.COLUMN="__SpreadsheetColumnHeader__",n.LEFT_TOP="__SpreadsheetLeftTopPlaceholder__",n))(ue||{});const Ds=0,Fi=1,st=10,hd=11,Ns=12,Kn={id:"sheet.command.set-row-header-width",type:a.CommandType.COMMAND,handler:async(n,o)=>{if(!o)return!1;const e=n.get(M.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:i,size:r}=o,s=e.getRenderById(t);if(s){e.getRenderById(t).with(E.SheetSkeletonManagerService).setRowHeaderSize(s,i,r);const{components:c}=s,d=c.get(ue.ROW);d&&d.setCustomHeader({headerStyle:{size:r}},i)}return!0}},qn={id:"sheet.command.set-col-header-height",type:a.CommandType.COMMAND,handler:async(n,o)=>{if(!o)return!1;const e=n.get(M.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:i,size:r}=o,s=e.getRenderById(t);if(s){e.getRenderById(t).with(E.SheetSkeletonManagerService).setColumnHeaderSize(s,i,r);const{components:c}=s,d=c.get(ue.COLUMN);d&&d.setCustomHeader({headerStyle:{size:r}},i)}return!0}},Zo=a.createInterceptorKey("rangeMovePermissionCheck"),Go=a.createInterceptorKey("rangeFillPermissionCheck");var Ko=(n=>(n[n.FORMULA_EDITOR_SHOW=100]="FORMULA_EDITOR_SHOW",n[n.MARK_SELECTION=1e4]="MARK_SELECTION",n))(Ko||{});function qe(n){const o=n.getColorFromTheme("primary.600"),e=n.getColorFromTheme("white"),t=new a.ColorKit(o).setAlpha(.07).toRgbString();return{strokeWidth:1,stroke:o,fill:t,widgets:{},widgetSize:6,widgetStrokeWidth:1,widgetStroke:e,autofillSize:6,autofillStrokeWidth:1,autofillStroke:e,rowHeaderFill:t,rowHeaderStroke:o,rowHeaderStrokeWidth:1,columnHeaderFill:t,columnHeaderStroke:o,columnHeaderStrokeWidth:1,expandCornerSize:40}}class md{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:i,endRow:r}=this,{startColumn:s,startRow:l,endColumn:c,endRow:d}=o;return e===s&&t===l&&i===c&&r===d}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:i,endColumn:r,endRow:s,startX:l,startY:c,endX:d,endY:u,rangeType:h}=o;this._startColumn=t,this._startRow=i,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 Jt(n,o){const{startRow:e,startColumn:t,endRow:i,endColumn:r,rangeType:s}=o,l=i<e?i:e,c=i<e?e:i,d=r<t?r:t,u=r<t?t:r,h=n.getNoMergeCellWithCoordByIndex(l,d),g=n.getNoMergeCellWithCoordByIndex(c,u);return{startRow:e,startColumn:t,endRow:i,endColumn:r,rangeType:s,startY:(h==null?void 0:h.startY)||0,endY:(g==null?void 0:g.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(g==null?void 0:g.endX)||0}}function Re(n,o){const{range:e,primary:t,style:i}=n,r=Jt(o,e),s=t&&Qn(o,t);return{rangeWithCoord:r,primaryWithCoord:s,style:i}}function Qn(n,o){const{actualRow:e,actualColumn:t,isMerged:i,isMergedMainCell:r,startRow:s,startColumn:l,endRow:c,endColumn:d}=o,u=n.getNoMergeCellWithCoordByIndex(e,t),h=n.getNoMergeCellWithCoordByIndex(s,l),g=n.getNoMergeCellWithCoordByIndex(c,d);return{actualRow:e,actualColumn:t,isMerged:i,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:(g==null?void 0:g.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(g==null?void 0:g.endX)||0}}}const ks="__SpreadsheetHelperSelectionTempRect",gd=35;class Hs{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,"_disabled",!1);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()}setDisabled(o){this._disabled=o}_getFreeze(){var e,t;return(t=(e=M.withCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET,E.SheetSkeletonManagerService,this._injector.get(a.IUniverInstanceService),this._injector.get(M.IRenderManagerService)))==null?void 0:e.getCurrentParam())==null?void 0:t.skeleton.getWorksheetConfig().freeze}_isSelectionInViewport(o,e){const t=this._getFreeze()||{startRow:-1,startColumn:-1};switch(e.viewportKey){case M.SHEET_VIEWPORT_KEY.VIEW_MAIN:return o.endRow>=t.startRow&&o.endColumn>=t.startColumn;case M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP:case M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT:return o.endColumn>=t.startColumn&&o.startRow<t.startRow;case M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT:case M.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM:return o.endRow>=t.startRow&&o.startColumn<t.startColumn;case M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP:case M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT:case M.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP:case M.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:i}=this._control;[o,e,t,i].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(M.CURSOR_TYPE.MOVE)}),r.onPointerLeave$.subscribeEvent(()=>{r.resetCursor()}),r.onPointerDown$.subscribeEvent(this._controlPointerDownHandler.bind(this))})}_controlMoving(o,e){var N;const t=this._scene,i=t.getScrollXYInfoByViewport(M.Vector2.FromArray([o,e])),{scaleX:r,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(o,e,r,s,i),{row:c,column:d}=l,u=this._skeleton.getRowCount()-1,h=this._skeleton.getColumnCount()-1;let g=Math.max(0,c+this._relativeSelectionPositionRow),S=g+this._relativeSelectionRowLength;S>u&&(S=u,S-g<this._relativeSelectionRowLength&&(g=S-this._relativeSelectionRowLength));let f=Math.max(0,d+this._relativeSelectionPositionColumn),v=f+this._relativeSelectionColumnLength;v>h&&(v=h,v-f<this._relativeSelectionColumnLength&&(f=v-this._relativeSelectionColumnLength));const p=this._skeleton.worksheet.getCellInfoInMergeData(g,f),_=Re({range:{startRow:g,endRow:S,startColumn:f,endColumn:v},primary:p,style:null},this._skeleton),w=this._skeleton.getNoMergeCellWithCoordByIndex(g,f),y=this._skeleton.getNoMergeCellWithCoordByIndex(S,v),O=(w==null?void 0:w.startY)||0,R=(y==null?void 0:y.endY)||0,P=(w==null?void 0:w.startX)||0,A=(y==null?void 0:y.endX)||0;(N=this._helperSelection)==null||N.transformByState({left:P,top:O,width:A-P,height:R-O}),this._targetSelection={..._.rangeWithCoord},this._control.selectionMoving$.next(_.rangeWithCoord)}_controlPointerDownHandler(o){const{offsetX:e,offsetY:t}=o,i=this._scene,r=i.getCoordRelativeToViewport(M.Vector2.FromArray([e,t])),{x:s,y:l}=r,c=i.getScrollXYInfoByViewport(r),{scaleX:d,scaleY:u}=i.getAncestorScale(),h=this._skeleton.getCellIndexByOffset(s,l,d,u,c);this._startOffsetX=s,this._startOffsetY=l;const{row:g,column:S}=h,{startRow:f,startColumn:v,endRow:p,endColumn:C}=this._control.model;let _=0,w=0;g<f?_-=1:g>p&&(_+=1),S<v?w-=1:S>C&&(w+=1),this._relativeSelectionPositionRow=f-g+_,this._relativeSelectionPositionColumn=v-S+w,this._relativeSelectionRowLength=p-f,this._relativeSelectionColumnLength=C-v;const y=this._control.currentStyle,O=this._getScale();this.isHelperSelection&&(this._helperSelection=new M.Rect(ks,{stroke:y.stroke,strokeWidth:y.strokeWidth/O}),i.addObject(this._helperSelection));const R=i.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN),P=M.ScrollTimer.create(i);this._scrollTimer=P,P.startScroll(s,l,R),i.disableObjectsEvent(),this._scenePointerMoveSub=i.onPointerMove$.subscribeEvent(A=>{var L;if(this._disabled)return;const{offsetX:N,offsetY:k}=A;if(((L=this._injector.get(Ce,a.Quantity.OPTIONAL))==null?void 0:L.interceptor.fetchThroughInterceptors(Zo)(!1,null))===!1)return;const{x:V,y:W}=i.getCoordRelativeToViewport(M.Vector2.FromArray([N,k]));this._controlMoving(V,W),i.setCursor(M.CURSOR_TYPE.MOVE),P.scrolling(V,W,()=>{this._controlMoving(V,W)})}),this._scenePointerUpSub=i.onPointerUp$.subscribeEvent(()=>{var N,k,H,V;(N=this._helperSelection)==null||N.dispose();const A=this._scene;A.resetCursor(),this._clearObserverEvent(),A.enableObjectsEvent(),(k=this._scrollTimer)==null||k.dispose(),this._control.selectionMoveEnd$.next(this._targetSelection),(V=(H=this._selectionHooks).selectionMoveEnd)==null||V.call(H)})}_initialWidget(){const{topLeftWidget:o,topCenterWidget:e,topRightWidget:t,middleLeftWidget:i,middleRightWidget:r,bottomLeftWidget:s,bottomCenterWidget:l,bottomRightWidget:c}=this._control,d=[M.CURSOR_TYPE.NORTH_WEST_RESIZE,M.CURSOR_TYPE.NORTH_RESIZE,M.CURSOR_TYPE.NORTH_EAST_RESIZE,M.CURSOR_TYPE.WEST_RESIZE,M.CURSOR_TYPE.EAST_RESIZE,M.CURSOR_TYPE.SOUTH_WEST_RESIZE,M.CURSOR_TYPE.SOUTH_RESIZE,M.CURSOR_TYPE.SOUTH_EAST_RESIZE];[o,e,t,i,r,s,l,c].forEach((u,h)=>{u.onPointerEnter$.subscribeEvent(()=>{u.setCursor(d[h])}),u.onPointerLeave$.subscribeEvent(()=>{u.resetCursor()}),u.onPointerDown$.subscribeEvent(g=>{this._widgetPointerDownEvent(g,d[h])})})}_widgetPointerDownEvent(o,e){const t=this._scene,{offsetX:i,offsetY:r}=o,s=t.getCoordRelativeToViewport(M.Vector2.FromArray([i,r])),{x:l,y:c}=s;this._startOffsetX=i,this._startOffsetY=r;const{startRow:d,startColumn:u,endRow:h,endColumn:g}=this._control.model,S=Math.min(d,h),f=Math.min(u,g),v=Math.max(d,h),p=Math.max(u,g);this._relativeSelectionPositionRow=S,this._relativeSelectionPositionColumn=f,this._relativeSelectionRowLength=v-S,this._relativeSelectionColumnLength=p-f,e===M.CURSOR_TYPE.NORTH_WEST_RESIZE?(this._relativeSelectionPositionRow=v,this._relativeSelectionPositionColumn=p):e===M.CURSOR_TYPE.NORTH_RESIZE?this._relativeSelectionPositionRow=v:e===M.CURSOR_TYPE.NORTH_EAST_RESIZE?this._relativeSelectionPositionRow=v:e===M.CURSOR_TYPE.WEST_RESIZE?this._relativeSelectionPositionColumn=p:e===M.CURSOR_TYPE.SOUTH_WEST_RESIZE?this._relativeSelectionPositionColumn=p:e===M.CURSOR_TYPE.SOUTH_RESIZE&&(this._relativeSelectionPositionRow=S);const C=M.ScrollTimer.create(t),_=t.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN);C.startScroll(l,c,_),this._scrollTimer=C,t.disableObjectsEvent(),this._scenePointerMoveSub=t.onPointerMove$.subscribeEvent(w=>{const{offsetX:y,offsetY:O}=w,{x:R,y:P}=t.getCoordRelativeToViewport(M.Vector2.FromArray([y,O]));this._widgetMoving(R,P,e),t.setCursor(e),C.scrolling(R,P,()=>{this._widgetMoving(R,P,e)})}),this._scenePointerUpSub=t.onPointerUp$.subscribeEvent(()=>{var y,O,R;const w=this._scene;w.resetCursor(),this._clearObserverEvent(),w.enableObjectsEvent(),(y=this._scrollTimer)==null||y.dispose(),this._control.selectionScaled$.next(this._targetSelection),(R=(O=this._selectionHooks).selectionMoveEnd)==null||R.call(O)})}_widgetMoving(o,e,t){const i=this._scene,r=i.getScrollXYInfoByViewport(M.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:s,scaleY:l}=i.getAncestorScale(),c=this._skeleton.getCellIndexByOffset(o,e,s,l,r),{row:d,column:u}=c;let h=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,S=d,f=u;t===M.CURSOR_TYPE.NORTH_WEST_RESIZE?(h=d,g=u,S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn):t===M.CURSOR_TYPE.NORTH_RESIZE?(h=d,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength):t===M.CURSOR_TYPE.NORTH_EAST_RESIZE?(h=d,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,f=u):t===M.CURSOR_TYPE.WEST_RESIZE?(h=this._relativeSelectionPositionRow,g=u,S=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,f=this._relativeSelectionPositionColumn):t===M.CURSOR_TYPE.EAST_RESIZE?S=this._relativeSelectionPositionRow+this._relativeSelectionRowLength:t===M.CURSOR_TYPE.SOUTH_WEST_RESIZE?(h=this._relativeSelectionPositionRow,g=u,S=d,f=this._relativeSelectionPositionColumn):t===M.CURSOR_TYPE.SOUTH_RESIZE&&(h=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,S=d,f=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength);const v=this._swapPositions(h,g,S,f),p=this._skeleton.getCellWithMergeInfoByIndex(h,g),_=Re({range:v,primary:p,style:null},this._skeleton);this._targetSelection={..._.rangeWithCoord},this._control.updateRangeBySelectionWithCoord(_),this._control.selectionScaling$.next(this._targetSelection)}_initialAutoFill(){const{fillControl:o}=this._control;o.onPointerEnter$.subscribeEvent(e=>{this._injector.get(Ce).interceptor.fetchThroughInterceptors(Go)(!1,{x:e.offsetX,y:e.offsetY,skeleton:this._skeleton,scene:this._scene})&&o.setCursor(M.CURSOR_TYPE.CROSSHAIR)}),o.onPointerLeave$.subscribeEvent(()=>{o.resetCursor()}),o.onPointerDown$.subscribeEvent(this._autoFillForPointerdown.bind(this))}_autoFillMoving(o,e){var k,H,V;const t=this._scene,i=t.getViewportScrollXY(this._activeViewport),{scaleX:r,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(o,e,r,s,i),{row:c,column:d}=l,u=t.getCoordRelativeToViewport(M.Vector2.FromArray([o,e])),h=this._skeleton.getRowCount()-1,g=this._skeleton.getColumnCount()-1;let S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn,v=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,p=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength,C=!1,_=!0;if((d<f||d>p)&&c>=S&&c<=v){const W=this._fillRuler(d,f,p,this._relativeSelectionColumnLength,g);f=W.startRowOrColumn,p=W.endRowOrColumn,C=W.isLighten,_=!1}else if((c<S||c>v)&&d>=f&&d<=p){const W=this._fillRuler(c,S,v,this._relativeSelectionRowLength,h);S=W.startRowOrColumn,v=W.endRowOrColumn,C=W.isLighten}else if(Math.abs(this._startOffsetX-u.x-i.x)/2>Math.abs(this._startOffsetY-u.y-i.y)){const W=this._fillRuler(d,f,p,this._relativeSelectionColumnLength,g);f=W.startRowOrColumn,p=W.endRowOrColumn,C=W.isLighten,_=!1}else{const W=this._fillRuler(c,S,v,this._relativeSelectionRowLength,h);S=W.startRowOrColumn,v=W.endRowOrColumn,C=W.isLighten}const w=this._skeleton.getNoMergeCellWithCoordByIndex(S,f),y=this._skeleton.getNoMergeCellWithCoordByIndex(v,p),O=(w==null?void 0:w.startY)||0,R=(y==null?void 0:y.endY)||0,P=(w==null?void 0:w.startX)||0,A=(y==null?void 0:y.endX)||0;C?this._controlHandler((W,L)=>{const U=new a.ColorKit(this._fillControlColors[L]).lighten(gd).toRgbString();W.setProps({fill:U})}):this._controlHandler((W,L)=>{W.setProps({fill:this._fillControlColors[L]})});const N=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();S===v&&_===!0||f===p&&_===!1?(k=this._helperSelection)==null||k.hide():((H=this._helperSelection)==null||H.transformByState({left:P-N/2,top:O-N/2,width:A-P,height:R-O}),(V=this._helperSelection)==null||V.show()),this._targetSelection={startY:O,endY:R,startX:P,endX:A,startRow:S,endRow:v,startColumn:f,endColumn:p},this._control.selectionFilling$.next(this._targetSelection)}_autoFillForPointerdown(o){const{offsetX:e,offsetY:t}=o,i=this._scene,r=i.getCoordRelativeToViewport(M.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 g=this._control.currentStyle;let S=g==null?void 0:g.stroke,f=g==null?void 0:g.strokeWidth;const v=qe(this._themeService);S==null&&(S=v.stroke),f==null&&(f=v.strokeWidth);const p=this._getScale();f/=p;const C=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/p,_=new a.ColorKit(S).darken(2).toRgbString();this.isHelperSelection&&(this._helperSelection=new M.Rect(ks,{stroke:_,strokeWidth:f+C/2}),i.addObject(this._helperSelection)),this._activeViewport=i.getActiveViewportByCoord(M.Vector2.FromArray([e,t]));const w=i.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN),y=M.ScrollTimer.create(i,this._activeViewport.viewportKey===M.SHEET_VIEWPORT_KEY.VIEW_MAIN?M.ScrollTimerType.ALL:M.ScrollTimerType.NONE);y.startScroll(s,l,w),this._scrollTimer=y,i.disableObjectsEvent(),this._controlHandler(O=>{this._fillControlColors.push(O.fill)}),this._scenePointerMoveSub=i.onPointerMove$.subscribeEvent(O=>{var W;const{offsetX:R,offsetY:P}=O,A=i.getActiveViewportByCoord(M.Vector2.FromArray([R,P]));if(!this._injector.get(Ce).interceptor.fetchThroughInterceptors(Go)(!1,{x:o.offsetX,y:o.offsetY,skeleton:this._skeleton,scene:this._scene}))return;const{x:k,y:H}=i.getCoordRelativeToViewport(M.Vector2.FromArray([R,P]));this._autoFillMoving(k,H),i.setCursor(M.CURSOR_TYPE.CROSSHAIR);const V=this._targetSelection;if(w&&A&&((W=this._activeViewport)==null?void 0:W.viewportKey)!==(A==null?void 0:A.viewportKey)){let L;V.startRow!==c?(y.scrollTimerType=M.ScrollTimerType.Y,L={...V,endRow:V.startRow}):V.endRow!==u?(y.scrollTimerType=M.ScrollTimerType.Y,L={...V,startRow:V.endRow}):V.startColumn!==d?(y.scrollTimerType=M.ScrollTimerType.X,L={...V,endColumn:V.startColumn}):(y.scrollTimerType=M.ScrollTimerType.X,L={...V,startColumn:V.endColumn}),this._isSelectionInViewport(L,A)&&(this._viewportMainScrollBarNeedResetPosition(y.scrollTimerType,this._activeViewport.viewportKey,A.viewportKey)&&w.scrollToBarPos({x:y.scrollTimerType===M.ScrollTimerType.X?0:void 0,y:y.scrollTimerType===M.ScrollTimerType.Y?0:void 0}),this._activeViewport=A)}y.scrolling(k,H,()=>{this._autoFillMoving(k,H)})}),this._scenePointerUpSub=i.onPointerUp$.subscribeEvent(()=>{var R,P;(R=this._helperSelection)==null||R.dispose();const O=this._scene;O.resetCursor(),this._clearObserverEvent(),O.enableObjectsEvent(),(P=this._scrollTimer)==null||P.dispose(),this._control.refreshSelectionFilled(this._targetSelection),this._isInMergeState=!1,this._controlHandler((A,N)=>{A.setProps({fill:this._fillControlColors[N]})}),this._fillControlColors=[]})}_viewportMainScrollBarNeedResetPosition(o,e,t){return o===M.ScrollTimerType.X&&(e===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||e===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP)&&(t===M.SHEET_VIEWPORT_KEY.VIEW_MAIN||t===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP)||o===M.ScrollTimerType.Y&&(e===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||e===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP)&&(t===M.SHEET_VIEWPORT_KEY.VIEW_MAIN||t===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)}_hasMergeInRange(o,e,t,i){return this._skeleton.worksheet.getMergedCellRange(o,e,t,i).length>0}_swapPositions(o,e,t,i){const r=Math.min(o,t),s=Math.min(e,i),l=Math.max(o,t),c=Math.max(e,i);return{startRow:r,startColumn:s,endRow:l,endColumn:c}}_controlHandler(o){const{leftControl:e,rightControl:t,topControl:i,bottomControl:r,backgroundControlTop:s,backgroundControlMiddleLeft:l,backgroundControlMiddleRight:c,backgroundControlBottom:d,fillControl:u}=this._control,h=[e,t,i,r,s,l,c,d,u];for(let g=0,S=h.length;g<S;g++){const f=h[g];o(f,g)}}_fillRuler(o,e,t,i,r){let s=!1;if(o<e)if(this._isInMergeState&&o<e){const l=e-o,c=i+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=i+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=(n=>(n.Selection="__SpreadsheetSelectionShape__",n.top="__SpreadsheetSelectionTopControl__",n.bottom="__SpreadsheetSelectionBottomControl__",n.left="__SpreadsheetSelectionShapeLeftControl__",n.right="__SpreadsheetSelectionShapeRightControl__",n.backgroundTop="__SpreadsheetSelectionBackgroundControlTop__",n.backgroundMiddleLeft="__SpreadsheetSelectionBackgroundControlMiddleLeft__",n.backgroundMiddleRight="__SpreadsheetSelectionBackgroundControlMiddleRight__",n.backgroundBottom="__SpreadsheetSelectionBackgroundControlBottom__",n.fill="__SpreadsheetSelectionFillControl__",n.fillTopLeft="__SpreadsheetSelectionFillControlTopLeft__",n.fillBottomRight="__SpreadsheetSelectionFillControlBottomRight__",n.fillTopLeftInner="__SpreadsheetSelectionFillControlTopLeftInner__",n.fillBottomRightInner="__SpreadsheetSelectionFillControlBottomRightInner__",n.lineMain="__SpreadsheetDragLineMainControl__",n.lineContent="__SpreadsheetDragLineContentControl__",n.line="__SpreadsheetDragLineControl__",n.dash="__SpreadsheetDragDashControl__",n.rowHeaderBackground="__SpreadSheetSelectionRowHeaderBackground__",n.rowHeaderBorder="__SpreadSheetSelectionRowHeaderBorder__",n.rowHeaderGroup="__SpreadSheetSelectionRowHeaderGroup__",n.columnHeaderBackground="__SpreadSheetSelectionColumnHeaderBackground__",n.columnHeaderBorder="__SpreadSheetSelectionColumnHeaderBorder__",n.columnHeaderGroup="__SpreadSheetSelectionColumnHeaderGroup__",n.topLeftWidget="__SpreadSheetSelectionTopLeftWidget__",n.topCenterWidget="__SpreadSheetSelectionTopCenterWidget__",n.topRightWidget="__SpreadSheetSelectionTopRightWidget__",n.middleLeftWidget="__SpreadSheetSelectionMiddleLeftWidget__",n.middleRightWidget="__SpreadSheetSelectionMiddleRightWidget__",n.bottomLeftWidget="__SpreadSheetSelectionBottomLeftWidget__",n.bottomCenterWidget="__SpreadSheetSelectionBottomCenterWidget__",n.bottomRightWidget="__SpreadSheetSelectionBottomRightWidget__",n))(qo||{});const Vs=.3;class Jn extends a.Disposable{constructor(e,t,i,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 D.BehaviorSubject(this));T(this,"dispose$",this._dispose$.asObservable());T(this,"selectionMoving$",new D.Subject);T(this,"selectionMoveEnd$",new D.Subject);T(this,"selectionScaling$",new D.Subject);T(this,"selectionScaled$",new D.Subject);T(this,"selectionFilling$",new D.Subject);T(this,"_selectionFilled$",new D.Subject);T(this,"selectionFilled$",this._selectionFilled$.asObservable());T(this,"_antLineOffset",0);T(this,"_antRequestNewFrame",-1);this._scene=e,this._zIndex=t,this._themeService=i,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=qe(this._themeService),this._currentStyle=qe(this._themeService),this._selectionRenderModel=new md;const e=this._zIndex;this._leftBorder=new M.Rect("__SpreadsheetSelectionShapeLeftControl__"+e,{zIndex:e}),this._rightBorder=new M.Rect("__SpreadsheetSelectionShapeRightControl__"+e,{zIndex:e}),this._topBorder=new M.Rect("__SpreadsheetSelectionTopControl__"+e,{zIndex:e}),this._bottomBorder=new M.Rect("__SpreadsheetSelectionBottomControl__"+e,{zIndex:e}),this._backgroundControlTop=new M.Rect("__SpreadsheetSelectionBackgroundControlTop__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlBottom=new M.Rect("__SpreadsheetSelectionBackgroundControlBottom__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleLeft=new M.Rect("__SpreadsheetSelectionBackgroundControlMiddleLeft__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleRight=new M.Rect("__SpreadsheetSelectionBackgroundControlMiddleRight__"+e,{zIndex:e-1,evented:!1}),this._autoFillControl=new M.Rect("__SpreadsheetSelectionFillControl__"+e,{zIndex:e+1}),this._autoFillControl.hide(),this._dashedRect=new M.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 M.Group("__SpreadsheetSelectionShape__"+e,...t,...this._widgetRects),this._selectionShapeGroup.hide(),this._selectionShapeGroup.evented=!1,this._selectionShapeGroup.zIndex=e;const i=this.getScene();i.addObject(this._selectionShapeGroup,Fi),this.disposeWithMe(a.toDisposable(i.onTransformChange$.subscribeEvent(r=>{r.type===M.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&(this._updateLayoutOfSelectionControl(this._currentStyle),this._updateControlCoord())})))}_initialHeader(){const e=this._zIndex;this._rowHeaderBackground=new M.Rect("__SpreadSheetSelectionRowHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderBorder=new M.Rect("__SpreadSheetSelectionRowHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderGroup=new M.Group("__SpreadSheetSelectionRowHeaderGroup__"+e,this._rowHeaderBackground,this._rowHeaderBorder),this._rowHeaderGroup.hide(),this._rowHeaderGroup.evented=!1,this._rowHeaderGroup.zIndex=e,this._columnHeaderBackground=new M.Rect("__SpreadSheetSelectionColumnHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderBorder=new M.Rect("__SpreadSheetSelectionColumnHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderGroup=new M.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],hd)}_initialWidget(){const e=this._zIndex;return this._topLeftWidget=new M.Rect("__SpreadSheetSelectionTopLeftWidget__"+e,{zIndex:e+1}),this._topCenterWidget=new M.Rect("__SpreadSheetSelectionTopCenterWidget__"+e,{zIndex:e+1}),this._topRightWidget=new M.Rect("__SpreadSheetSelectionTopRightWidget__"+e,{zIndex:e+1}),this._middleLeftWidget=new M.Rect("__SpreadSheetSelectionMiddleLeftWidget__"+e,{zIndex:e+1}),this._middleRightWidget=new M.Rect("__SpreadSheetSelectionMiddleRightWidget__"+e,{zIndex:e+1}),this._bottomLeftWidget=new M.Rect("__SpreadSheetSelectionBottomLeftWidget__"+e,{zIndex:e+1}),this._bottomCenterWidget=new M.Rect("__SpreadSheetSelectionBottomCenterWidget__"+e,{zIndex:e+1}),this._bottomRightWidget=new M.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 Hs(this,e)}setControlExtensionDisable(e){this._controlExtension&&this._controlExtension.setDisabled(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:i,widgets:r,autofillStroke:s,strokeDash:l,isAnimationDash:c}=t;let d=t.autofillSize,u=t.strokeWidth,h=t.autofillStrokeWidth;const g=this._getScale(),S=(u+m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH)/2/g;u/=g,d/=g,h/=g<1?1:g;const f=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/g,v=M.FIX_ONE_PIXEL_BLUR_OFFSET/g,{startX:p,startY:C,endX:_,endY:w}=this._selectionRenderModel;if(this.leftControl.transformByState({height:w-C,left:-S+v,width:u,strokeWidth:f,top:-f/2+v}),this.leftControl.setProps({fill:i,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.rightControl.transformByState({height:w-C,left:_-p-S+v,width:u,strokeWidth:f,top:-f/2+v}),this.rightControl.setProps({fill:i,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.topControl.transformByState({width:_-p+u,top:-S+v,left:-S+v,height:u,strokeWidth:f}),this.topControl.setProps({fill:i,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.bottomControl.transformByState({width:_-p+u,top:w-C-S+v,height:u,left:-S+v,strokeWidth:f}),this.bottomControl.setProps({fill:i,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),l==null)this.dashedRect.hide(),this._stopAntLineAnimation();else{const y=t.strokeWidth*2/g;this.dashedRect.transformByState({height:w-C,width:_-p,strokeWidth:y,left:-y/2+v,top:-y/2+v}),this.dashedRect.setProps({strokeDashArray:[0,l/g]}),this._stopAntLineAnimation(),c!==!1&&this._startAntLineAnimation(),this.dashedRect.show()}if(this._showAutoFill=this._showAutoFill&&this._enableAutoFill,this._showAutoFill&&!this._hasWidgets(r)){const y={fill:i,stroke:s,strokeScaleEnabled:!1},O={width:d-h,height:d-h,left:_-p-d/2+h/2-v,top:w-C-d/2+h/2-v,strokeWidth:h};this._autoFillControl.setProps(y),this._autoFillControl.transformByState(O),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.rowHeaderWidth,this._columnHeaderHeight=t.columnHeaderHeight),this._selectionRenderModel.setValue(e.rangeWithCoord,e.primaryWithCoord),this._showAutoFill=e.primaryWithCoord!==null,this._updateLayoutOfSelectionControl(e.style),this._updateControlCoord()}update(e,t=0,i=0,r,s){this._rowHeaderWidth=t,this._columnHeaderHeight=i,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,i,r,s,l,c,d,u,h,g,S,f,v,p,C,_,w,y,O,R,P,A,N,k;(e=this._leftBorder)==null||e.dispose(),(t=this._rightBorder)==null||t.dispose(),(i=this._topBorder)==null||i.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(),(g=this._rowHeaderBorder)==null||g.dispose(),(S=this._rowHeaderGroup)==null||S.dispose(),(f=this._rowHeaderBackground)==null||f.dispose(),(v=this._columnHeaderBackground)==null||v.dispose(),(p=this._columnHeaderBorder)==null||p.dispose(),(C=this._columnHeaderGroup)==null||C.dispose(),(_=this._topLeftWidget)==null||_.dispose(),(w=this._topCenterWidget)==null||w.dispose(),(y=this._topRightWidget)==null||y.dispose(),(O=this._middleLeftWidget)==null||O.dispose(),(R=this._middleRightWidget)==null||R.dispose(),(P=this._bottomLeftWidget)==null||P.dispose(),(A=this._bottomCenterWidget)==null||A.dispose(),(N=this._bottomRightWidget)==null||N.dispose(),(k=this._controlExtension)==null||k.dispose(),super.dispose(),this._dispose$.next(this),this._dispose$.complete()}getCurrentCellInfo(){const e=this.model.currentCell;if(e){let t;if(e.isMerged){const i=e.mergeInfo;t={startRow:i.startRow,endRow:i.endRow,startColumn:i.startColumn,endColumn:i.endColumn,startX:i.startX,endX:i.endX,startY:i.startY,endY:i.endY}}else{const{actualRow:i,actualColumn:r,startX:s,endX:l,startY:c,endY:d}=e;t={startRow:i,endRow:i,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:i,endX:r,endY:s,rangeType:l}=this._selectionRenderModel,c=this._currentStyle,d=this._getScale(),{stroke:u,rowHeaderFill:h=c.rowHeaderFill,rowHeaderStroke:g=c.rowHeaderStroke,columnHeaderFill:S=c.columnHeaderFill,columnHeaderStroke:f=c.columnHeaderStroke}=e;let{rowHeaderStrokeWidth:v=c.rowHeaderStrokeWidth,columnHeaderStrokeWidth:p=c.columnHeaderStrokeWidth}=e;v/=d,p/=d;const C=this._rowHeaderWidth,_=this._columnHeaderHeight;if(this._highlightHeader&&_>0){let w=S;l===a.RANGE_TYPE.COLUMN&&(w=new a.ColorKit(u).setAlpha(Vs).toString()),this._columnHeaderBackground.setProps({fill:w}),this._columnHeaderBackground.resize(r-t,_),this._columnHeaderBorder.setProps({fill:f}),this._columnHeaderBorder.transformByState({width:r-t,height:p,top:_-p+1/d}),this._columnHeaderGroup.show(),this._columnHeaderGroup.translate(t,0)}else this._columnHeaderGroup.hide();if(this._columnHeaderGroup.makeDirty(!0),this._highlightHeader&&C>0){let w=h;l===a.RANGE_TYPE.ROW&&(w=new a.ColorKit(u).setAlpha(Vs).toString()),this._rowHeaderBackground.setProps({fill:w}),this._rowHeaderBackground.resize(C,s-i),this._rowHeaderBorder.setProps({fill:g}),this._rowHeaderBorder.transformByState({width:v,height:s-i,left:C-v+1/d}),this._rowHeaderGroup.show(),this._rowHeaderGroup.translate(0,i)}else this._rowHeaderGroup.hide();this._rowHeaderGroup.makeDirty(!0)}_updateBackgroundControl(e){const{startX:t,startY:i,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-i),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:g,endX:S,endY:f}=u,v=d/2,p={left:-v,top:-v,width:r-t+v*2,height:g-i+v};p.height<0&&(p.width=0,p.height=0),this._backgroundControlTop.transformByState(p);const C={left:-v,top:g-i,width:h-t+v,height:f-g};C.width<0&&(C.width=0,C.height=0),this._backgroundControlMiddleLeft.transformByState(C);const _={left:S-t-v,top:g-i,width:r-S+v*2,height:f-g};_.width<0&&(_.width=0,_.height=0),this._backgroundControlMiddleRight.transformByState(_);const w={left:-v,top:f-i,width:r-t+v*2,height:s-f+v};w.height<0&&(w.width=0,w.height=0),this._backgroundControlBottom.transformByState(w),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:i,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:g}=e;h/=u,g/=u;const S={left:-h/2+g/2,center:(r-t)/2-h/2+g/2,right:r-t-h/2+g/2,top:-h/2,middle:(s-i)/2-h/2,bottom:s-i-h/2+g/2},f=h-g;this._widgetRects.forEach(v=>{v.setProps({fill:l,stroke:d})}),c.tl===!0?(this._topLeftWidget.transformByState({height:f,width:f,left:S.left,top:S.top,strokeWidth:g}),this._topLeftWidget.show()):this._topLeftWidget.hide(),c.tc===!0?(this._topCenterWidget.transformByState({height:f,width:f,left:S.center,top:S.top,strokeWidth:g}),this._topCenterWidget.show()):this._topCenterWidget.hide(),c.tr===!0?(this._topRightWidget.transformByState({height:f,width:f,left:S.right,top:S.top,strokeWidth:g}),this._topRightWidget.show()):this._topRightWidget.hide(),c.ml===!0?(this._middleLeftWidget.transformByState({height:f,width:f,left:S.left,top:S.middle,strokeWidth:g}),this._middleLeftWidget.show()):this._middleLeftWidget.hide(),c.mr===!0?(this._middleRightWidget.transformByState({height:f,width:f,left:S.right,top:S.middle,strokeWidth:g}),this._middleRightWidget.show()):this._middleRightWidget.hide(),c.bl===!0?(this._bottomLeftWidget.transformByState({height:f,width:f,left:S.left,top:S.bottom,strokeWidth:g}),this._bottomLeftWidget.show()):this._bottomLeftWidget.hide(),c.bc===!0?(this._bottomCenterWidget.transformByState({height:f,width:f,left:S.center,top:S.bottom,strokeWidth:g}),this._bottomCenterWidget.show()):this._bottomCenterWidget.hide(),c.br===!0?(this._bottomRightWidget.transformByState({height:f,width:f,left:S.right,top:S.bottom,strokeWidth:g}),this._bottomRightWidget.show()):this._bottomRightWidget.hide()}_hasWidgets(e){if(e==null)return!1;const t=Object.keys(e);if(t.length===0)return!1;for(const i of t)if(e[i]===!0)return!0;return!1}_getScale(){const{scaleX:e,scaleY:t}=this._scene.getAncestorScale();return Math.max(e,t)}_stopAntLineAnimation(){this._antLineOffset=0,M.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=M.requestNewFrame(()=>{this._startAntLineAnimation()})}}class Sd extends M.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 Qo extends a.Disposable{constructor(e,t,i,r,s){super();T(this,"_downObserver");T(this,"_scenePointerMoveSub");T(this,"_scenePointerUpSub");T(this,"_controlFillConfig$",new D.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 D.BehaviorSubject([]));T(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());T(this,"_selectionMoving$",new D.Subject);T(this,"selectionMoving$",this._selectionMoving$.asObservable());T(this,"_selectionMoveStart$",new D.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:Go}));T(this,"_escapeShortcutDisposable",null);this._injector=e,this._themeService=t,this._shortcutService=i,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,i){const r=this.getSelectionControls().length,{rowHeaderWidth:s,columnHeaderHeight:l}=t,c=new Jn(e,r,this._selectionTheme,{highlightHeader:this._highlightHeader,rowHeaderWidth:s,columnHeaderHeight:l});this._selectionControls.push(c);const d=Re(i,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(),i=this._skeleton;if(!(!t||!i)){for(let r=0,s=e.length;r<s;r++){const l=e[r],c=Re(l,this._skeleton),d=t[r];d?d.updateRangeBySelectionWithCoord(c,i):this.isSelectionEnabled()&&this.newSelectionControl(this._scene,i,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,i){this._skeleton=e,this._scene=t,this._activeViewport=i||(t==null?void 0:t.getViewports()[0]),t.findLayerByZIndex(Fi)||t.addLayer(new Sd(t,[],Fi))}getSkeleton(){return this._skeleton}getSelectionDataWithStyle(){const e=this._selectionControls;if(this._skeleton.worksheet){const[t,i]=this._skeleton.getLocation();return e.map(r=>{const s=r.getValue();return s.rangeWithCoord.sheetId=i,s.rangeWithCoord.unitId=t,s})}return[]}getSelectionControls(){return this._selectionControls}_addSelectionControlByModelData(e){var l;const t=this._skeleton,i=(l=e.style)!=null?l:qe(this._selectionTheme),r=this._scene;return e.style=i,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 i=this._getFreeze();if(!i||i.startRow<=0&&i.startColumn<=0)return this._scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e>i.startRow&&t>i.startColumn)return this._scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e<=i.startRow&&t<=i.startColumn)return this._scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP);if(e<=i.startRow&&t>i.startColumn)return this._scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(e>i.startRow&&t<=i.startColumn)return this._scene.getViewport(M.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,i,r=M.ScrollTimerType.ALL,s,l){var f,v;let c=0,d=0,u=s,h=l;this._scrollTimer=M.ScrollTimer.create(this._scene,r),this._scrollTimer.startScroll((f=e==null?void 0:e.left)!=null?f:0,(v=e==null?void 0:e.top)!=null?v:0,e);const g=this._scene,S=g.getActiveViewportByCoord(M.Vector2.FromArray([s,l]));this._scenePointerMoveSub=g.onPointerMove$.subscribeEvent(p=>{var V,W,L,U,B,F,z,X,j;const{offsetX:C,offsetY:_}=p,{x:w,y}=g.getCoordRelativeToViewport(M.Vector2.FromArray([C,_]));this._movingHandler(w,y,t,i);let O=w,R=y;const P=this.getActiveSelectionControl(),A=this._getFreeze(),N=P==null?void 0:P.model,k=(V=g.getActiveViewportByCoord(M.Vector2.FromArray([C,_])))!=null?V:this._getViewportByCell(N==null?void 0:N.endRow,N==null?void 0:N.endColumn);if((()=>{if(!S||!k||!e)return!1;const Q=[M.SHEET_VIEWPORT_KEY.VIEW_MAIN,M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT];return Q.includes(S.viewportKey)&&Q.includes(k.viewportKey)})()){if(!S||!k||!e)return!1;const Q=u<e.left&&w>e.left||u>e.left&&w<e.left,oe=h<e.top&&y>e.top||h>e.top&&y<e.top;Q&&(c+=1),oe&&(d+=1);const re=S.viewportKey,le=k.viewportKey;if(re===M.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP)_<e.top&&((W=N==null?void 0:N.endRow)!=null?W:0)<((L=A==null?void 0:A.startRow)!=null?L:0)?R=e.top:oe&&d%2===1&&e.scrollToViewportPos({viewportScrollY:0});else if(re===M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT)C<e.left&&((U=N==null?void 0:N.endColumn)!=null?U:0)<((B=A==null?void 0:A.startColumn)!=null?B:0)?O=e.left:Q&&c%2===1&&e.scrollToViewportPos({viewportScrollX:0});else if(re===le){let G=!1,Z=!1;re===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP?(G=!0,Z=!0):re===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP?Z=!0:re===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT&&(G=!0),((F=N==null?void 0:N.endRow)!=null?F:0)>((z=A==null?void 0:A.startRow)!=null?z:0)&&(Z=!1),((X=N==null?void 0:N.endColumn)!=null?X:0)>((j=A==null?void 0:A.startColumn)!=null?j:0)&&(G=!1),G&&(O=e.left),Z&&(R=e.top)}else{const G={x:S.scrollX,y:S.scrollY},Z={x:k.scrollX,y:k.scrollY},J=G.x!==Z.x&&Q&&c%2===1,ie=G.y!==Z.y&&oe&&d%2===1;(J||ie)&&(e.scrollToBarPos({x:J?G.x:void 0,y:ie?G.y:void 0}),J||(O=e.left),ie||(R=e.top)),(re===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&le===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||le===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&re===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)&&(O=e.left),(re===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&le===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||le===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&re===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP)&&(R=e.top)}u=w,h=y}this._scrollTimer.scrolling(O,R,()=>{this._movingHandler(w,y,t,i)})})}attachSelectionWithCoord(e){return Re(e,this._skeleton)}attachPrimaryWithCoord(e){return Qn(this._skeleton,e)}getSelectionCellByPosition(e,t){return this.getCellWithCoordByOffset(e,t)}getCellWithCoordByOffset(e,t,i){const r=this._scene,s=i!=null?i:this._skeleton,l=r.getViewportScrollXY(r.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:c,scaleY:d}=r.getAncestorScale();return s.getCellWithCoordByOffset(e,t,c,d,l)}_movingHandler(e,t,i,r){var O,R,P,A,N;const s=this._skeleton,l=this._scene,[c,d]=s.getLocation(),u={startRow:(O=i==null?void 0:i.model.startRow)!=null?O:-1,endRow:(R=i==null?void 0:i.model.endRow)!=null?R:-1,startColumn:(P=i==null?void 0:i.model.startColumn)!=null?P:-1,endColumn:(A=i==null?void 0:i.model.endColumn)!=null?A:-1},h=l.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=(N=this._getViewportByCell(u.endRow,u.endColumn))!=null?N:h,S=l.getScrollXYInfoByViewport(M.Vector2.FromArray([this._startViewportPosX,this._startViewportPosY]),g),{scaleX:f,scaleY:v}=l.getAncestorScale();r===a.RANGE_TYPE.ROW?e=Number.POSITIVE_INFINITY:r===a.RANGE_TYPE.COLUMN&&(t=Number.POSITIVE_INFINITY);const p=this._skeleton.getCellByOffset(e,t,f,v,S);if(!p)return;let C={startRow:Math.min(p.startRow,this._startRangeWhenPointerDown.startRow),startColumn:Math.min(p.startColumn,this._startRangeWhenPointerDown.startColumn),endRow:Math.max(p.endRow,this._startRangeWhenPointerDown.endRow),endColumn:Math.max(p.endColumn,this._startRangeWhenPointerDown.endColumn)};this._shouldDetectMergedCells&&(C=s.expandRangeByMerge(C,this.inRefSelectionMode()));const w=Re({range:C,primary:void 0,style:null},s);w.rangeWithCoord.unitId=c,w.rangeWithCoord.sheetId=d,w.rangeWithCoord.rangeType=r;const y=u.startRow!==C.startRow||u.startColumn!==C.startColumn||u.endRow!==C.endRow||u.endColumn!==C.endColumn;i!=null&&y&&(i.updateRangeBySelectionWithCoord(w),this._selectionMoving$.next(this.getSelectionDataWithStyle()))}_clearUpdatingListeners(){var t,i,r,s,l;this._scene.enableObjectsEvent(),(t=this._scenePointerMoveSub)==null||t.unsubscribe(),this._scenePointerMoveSub=null,(i=this._scenePointerUpSub)==null||i.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 i,r,s;const e=this._scene,t=(i=e.getEngine())==null?void 0:i.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,i,r,s){const l=this._skeleton;if(l==null)return null;if(this._shouldDetectMergedCells){const C=l==null?void 0:l.getCellWithCoordByOffset(e,t,i,r,s,{firstMatch:!0});if(!C)return;const _=a.convertCellToRange(C);return{primaryWithCoord:C,rangeWithCoord:_}}const{row:c,column:d}=l.getCellIndexByOffset(e,t,i,r,s),u=l.getNoMergeCellWithCoordByIndex(c,d),{startX:h,startY:g,endX:S,endY:f}=u,v={startY:g,endY:f,startX:h,endX:S,startRow:c,endRow:c,startColumn:d,endColumn:d};return{primaryWithCoord:{mergeInfo:v,actualRow:c,actualColumn:d,isMerged:!1,isMergedMainCell:!1,startY:g,endY:f,startX:h,endX:S},rangeWithCoord:v}}_checkClearPreviousControls(e){this.getSelectionControls().length!==0&&(!e.ctrlKey&&!e.shiftKey&&!this._remainLastEnabled||this._singleSelectionEnabled&&!e.shiftKey)&&this._clearAllSelectionControls()}_makeSelectionByTwoCells(e,t,i,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),g=Math.min(c,t.startColumn,d.startColumn),S=Math.max(c,t.endColumn,d.endColumn),v={range:i.expandRangeByMerge({startRow:u,startColumn:g,endRow:h,endColumn:S}),primary:m.convertPrimaryWithCoordToPrimary(e),style:null},p=Re(v,i);s.updateRangeBySelectionWithCoord(p)}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 Jo(n){return{range:{startRow:0,startColumn:0,endRow:n.getRowCount()-1,endColumn:n.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL},primary:zi(n).primary,style:null}}function zi(n){return Ws(n,{startRow:0,startColumn:0,endRow:0,endColumn:0})}function Ws(n,o){const e=n.worksheet.getCellInfoInMergeData(o.startRow,o.startColumn),t=n.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 fd=Object.getOwnPropertyDescriptor,vd=(n,o,e,t)=>{for(var i=t>1?void 0:t?fd(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},Ls=(n,o)=>(e,t)=>o(e,t,n);E.SheetSkeletonManagerService=class extends a.Disposable{constructor(e,t,i){super();T(this,"_sheetId","");T(this,"_sheetSkeletonParamStore",new Map);T(this,"_currentSkeleton$",new D.BehaviorSubject(null));T(this,"currentSkeleton$",this._currentSkeleton$.asObservable());T(this,"_currentSkeletonBefore$",new D.BehaviorSubject(null));T(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._context=e,this._injector=t,this._sheetSkService=i,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 i=this._getSkeletonParam(t);return i!=null&&(i.unitId=e),i}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),i=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:i,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 i=this._getSkeletonParam(e.sheetId);i!=null&&(i.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?Jt(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(M.SpreadsheetSkeleton,e,this._context.unit.getStyles())}setColumnHeaderSize(e,t,i){var u;if(!e)return;const r=(u=this.getWorksheetSkeleton(t))==null?void 0:u.skeleton;if(!r)return;r.columnHeaderHeight=i,e.scene.getViewports()[0].top=i,e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({height:i}),e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({height:i}),e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({top:i}),e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({top:i}),e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({height:i});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=qn.id,this._currentSkeleton$.next(d))}setRowHeaderSize(e,t,i){var f;const r=(f=this.getWorksheetSkeleton(t))==null?void 0:f.skeleton;if(!e||!r)return;r.rowHeaderWidth=i;const s=e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).width||46,l=i-s,c=e.scene.getViewports()[0].left;e.scene.getViewports()[0].left=c+l,e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({width:i}),e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({width:i}),e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({left:i});const d=e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).left||0;e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({left:d+l}),e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({width:i});const u=e==null?void 0:e.with(m.SheetsSelectionsService),h=e==null?void 0:e.with(Ce),g=u.getCurrentSelections();h.resetSelectionsByModelData(g);const S=this.getCurrent();S&&(S.commandId=Kn.id,this._currentSkeleton$.next(S))}},E.SheetSkeletonManagerService=vd([Ls(1,a.Inject(a.Injector)),Ls(2,a.Inject(m.SheetSkeletonService))],E.SheetSkeletonManagerService);var pd=Object.getOwnPropertyDescriptor,Cd=(n,o,e,t)=>{for(var i=t>1?void 0:t?pd(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},$n=(n,o)=>(e,t)=>o(e,t,n);const xs=["ff","fs","tr","tb"];E.AutoHeightController=class extends a.Disposable{constructor(o,e,t,i,r){super(),this._renderManagerService=o,this._sheetInterceptorService=e,this._selectionManagerService=t,this._univerInstanceService=i,this._configService=r,this._initialize()}_processLazyAutoHeight(o,e,t,i){if(i!=null&&i.length){const r={id:m.MarkDirtyRowAutoHeightMutation.id,params:{unitId:e,subUnitId:t,ranges:i,id:a.generateRandomId()},options:{onlyLocal:!0}},s={id:m.CancelMarkDirtyRowAutoHeightMutation.id,params:{unitId:e,subUnitId:t,id:r.params.id},options:{onlyLocal:!0}};return{redos:[...o.redos,r],undos:[...o.undos,s]}}return o}getUndoRedoParamsOfAutoHeight(o,e,t){const{_univerInstanceService:i}=this,r=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=r.getUnitId();let l=r.getActiveSheet(),c=l.getSheetId();if(e){const v=m.getSheetCommandTarget(i,{unitId:s,subUnitId:e});v&&(l=v.worksheet,c=l.getSheetId())}const u=this._renderManagerService.getRenderById(s).with(E.SheetSkeletonManagerService).ensureSkeleton(c);if(!u)return{redos:[],undos:[]};const g=u.calculateAutoHeightInRange(o,t).filter(v=>{const{row:p,autoHeight:C}=v;return!(!C||l.getRowHeight(p)===C)});if(g.length===0)return{redos:[],undos:[]};const S={subUnitId:c,unitId:s,rowsAutoHeightInfo:g},f=m.SetWorksheetRowAutoHeightMutationFactory(S,l);return{undos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:f}],redos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:S}]}}_initialize(){this.disposeWithMe(this._sheetInterceptorService.interceptAutoHeight({getMutations:o=>{const{unitId:e,subUnitId:t,ranges:i,autoHeightRanges:r,lazyAutoHeightRanges:s,cellHeights:l}=o,c=this.getUndoRedoParamsOfAutoHeight(r!=null?r:i,t,l);return this._processLazyAutoHeight(c,e,t,s)}}))}},E.AutoHeightController=Cd([$n(0,M.IRenderManagerService),$n(1,a.Inject(m.SheetInterceptorService)),$n(2,a.Inject(m.SheetsSelectionsService)),$n(3,a.Inject(a.IUniverInstanceService)),$n(4,a.IConfigService)],E.AutoHeightController);function at(n){const{rows:o,cols:e}=n;return{startRow:o[0],endRow:o[o.length-1],startColumn:e[0],endColumn:e[e.length-1]}}function lt(n){let o=[],e=[];const t=[];return n.forEach(i=>{o=o.concat(i.rows),e=e.concat(i.cols)}),o=Array.from(new Set(o)).sort((i,r)=>i-r),e=Array.from(new Set(e)).sort((i,r)=>i-r),n.forEach(i=>{t.push({startRow:o.findIndex(r=>r===i.rows[0]),endRow:o.findIndex(r=>r===i.rows[i.rows.length-1]),startColumn:e.findIndex(r=>r===i.cols[0]),endColumn:e.findIndex(r=>r===i.cols[i.cols.length-1])})}),{ranges:t,mapFunc:(i,r)=>({row:o[i],col:e[r]})}}function Id(n){const o=new a.ObjectMatrix;return n.forEach(e=>{const{rows:t,cols:i}=e;t.forEach(r=>{i.forEach(s=>{o.setValue(r,s,{v:null,p:null,f:null,si:null,custom:null})})})}),o.getData()}const $o={零:0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9},Xi=["零","一","二","三","四","五","六","七","八","九"],Us=["","万","亿","万亿","亿亿"],_d=["","十","百","千"],Bs={十:{value:10,secUnit:!1},百:{value:100,secUnit:!1},千:{value:1e3,secUnit:!1},万:{value:1e4,secUnit:!0},亿:{value:1e8,secUnit:!0}};function Qe(n){if(!n)return 0;let o=0,e=0,t=0,i=!1;const r=n.split("");for(let s=0;s<r.length;s++){const l=$o[r[s]];if(typeof l<"u")t=l,s===r.length-1&&(e+=t);else{const c=Bs[r[s]],d=c.value;i=c.secUnit,i?(e=(e+t)*d,o+=e,e=0):e+=t*d,t=0}}return o+e}function bd(n){let o="",e="",t=0,i=!0;for(;n>0;){const r=n%10;r===0?i||(i=!0,e=Xi[r]+e):(i=!1,o=Xi[r],o+=_d[t],e=o+e),t++,n=Math.floor(n/10)}return e}function wd(n){let o=0,e="",t="",i=!1;if(n===0)return Xi[0];for(;n>0;){const r=n%1e4;i&&(t=Xi[0]+t),e=bd(r),e+=r!==0?Us[o]:Us[0],t=e+t,i=r<1e3&&r>0,n=Math.floor(n/1e4),o++}return t}function Ed(n){if(!n)return!1;let o=!0;if(n)if(n.length===1)n==="日"||n in $o?o=!0:o=!1;else{const e=n.split("");for(let t=0;t<e.length;t++)if(!(e[t]in $o||e[t]in Bs)){o=!1;break}}return o}function Yi(n){if(!n)return{isExtendNumber:!1};const o=/0|([1-9]+[0-9]*)/g,e=o.test(n);if(e){const t=n.match(o);if(t&&t.length>0){const i=t[t.length-1],r=n.lastIndexOf(i),s=n.substr(0,r),l=n.substr(r+i.length);return{isExtendNumber:!0,matchTxt:Number(i),beforeTxt:s,afterTxt:l}}return{isExtendNumber:!1}}return{isExtendNumber:e}}function yd(n){let o;return n.length===2&&(n==="周一"||n==="周二"||n==="周三"||n==="周四"||n==="周五"||n==="周六"||n==="周日")?o=!0:o=!1,o}function Td(n){let o;return n.length===3&&(n==="星期一"||n==="星期二"||n==="星期三"||n==="星期四"||n==="星期五"||n==="星期六"||n==="星期日")?o=!0:o=!1,o}function Rd(n,o){let e=0;for(let t=0;t<n.length&&n[t]<o;t++)e++;return e}function ei(n){let o=!0;const e=n[1]-n[0];for(let t=1;t<n.length;t++)if(n[t]-n[t-1]!==e){o=!1;break}return o}function Md(n,o,e){const t=[],i=Math.floor(o/n),r=o%n;let s=0;if(i>0){for(let l=0;l<i;l++)for(let c=0;c<e.length;c++)t[e[c]+l*n]=s,s++;for(let l=0;l<e.length&&e[l]<r;l++)t[e[l]+n*i]=s,s++}else for(let l=0;l<e.length&&e[l]<r;l++)t[e[l]]=s,s++;return t}function wt(n,o){const e=[];for(let t=1;t<=o;t++){const i=(t-1)%n.length,r=a.Tools.deepClone(n[i]);Et(r),e.push({v:null,s:null,p:null,f:null,si:null,t:null,...r})}return e}function Pd(n,o){var t;const e=[];for(let i=1;i<=o;i++){const r=(i-1)%n.length,s={s:(t=n[r])==null?void 0:t.s};e.push(s)}return e}function Od(n){let o=!0;const e=n[1]/n[0];for(let t=1;t<n.length;t++)if(n[t]/n[t-1]!==e){o=!1;break}return o}function Ad(n){const o=[];for(let e=1;e<=n;e++)o.push(e);return o}function ji(n,o,e){var r,s,l,c;const t=[],i=[];for(let d=0;d<n.length;d++)i.push(Number((r=n[d])==null?void 0:r.v));if(n.length>2&&Od(i))for(let d=1;d<=o;d++){const u=(d-1)%n.length,h=a.Tools.deepClone(n[u]);Et(h);const g=Number((s=n[n.length-1])==null?void 0:s.v)*(Number((l=n[1])==null?void 0:l.v)/Number((c=n[0])==null?void 0:c.v))**d;h&&(Ys(h)&&(h.v=g),t.push(h))}else{const d=Ad(n.length);for(let u=1;u<=o;u++){const h=(u-1)%n.length,g=a.Tools.deepClone(n[h]);Et(g);const S=e===a.Direction.DOWN||e===a.Direction.RIGHT,f=Dd(n.length+u,i,d,S);g&&(Ys(g)&&(g.v=f),t.push(g))}}return t}function Dd(n,o,e,t=!0){function i(h){let g=0;for(let S=0;S<h.length;S++)g+=h[S];return g/h.length}const r=i(e),s=i(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*n)*1e5)/1e5}function Fs(n,o,e){var r;const t=[],i=/0|([1-9]+[0-9]*)/g;for(let s=1;s<=o;s++){const l=(s-1)%n.length,c=a.Tools.deepClone(n[l]);Et(c);const d=`${(r=n[n.length-1])==null?void 0:r.v}`;if(!d)continue;const u=d==null?void 0:d.match(i),h=u==null?void 0:u[u.length-1];if(!h)continue;const g=Math.abs(Number(h)+e*s),S=d.lastIndexOf(h),f=d.substr(0,S)+g.toString()+d.substr(S+h.length);c&&(c.v=f,t.push(c))}return t}function $t(n,o,e,t=0){var l,c;const i=[["日","一","二","三","四","五","六"],["周日","周一","周二","周三","周四","周五","周六"],["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]];if(t>=i.length)return[];const r=i[t],s=[];for(let d=1;d<=o;d++){const u=(d-1)%n.length,h=a.Tools.deepClone(n[u]);Et(h);let g=0;if(((l=n[n.length-1])==null?void 0:l.v)===r[0])g=7+e*d;else{const f=`${(c=n[n.length-1])==null?void 0:c.v}`;if(f){const v=f.substr(f.length-1,1);g=Qe(v)+e*d}}g<0&&(g=Math.ceil(Math.abs(g)/7)*7+g);const S=g%7;h&&(h.v=r[S],s.push(h))}return s}function zs(n,o,e){var i;const t=[];for(let r=1;r<=o;r++){const s=(r-1)%n.length,l=a.Tools.deepClone(n[s]);Et(l);const c=`${(i=n[n.length-1])==null?void 0:i.v}`,d=Qe(c)+e*r;let u;d<=0?u="零":u=wd(d),l&&(l.v=u,t.push(l))}return t}const ti={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 Nd(n){let o=!1;return Object.keys(ti).forEach(e=>{ti[e].includes(n)&&(o=!0)}),o}function er(n){let o="";const e=[];return Object.keys(ti).forEach(t=>{ti[t].includes(n)&&(o=t,e.push(...ti[t]))}),{name:o,series:e}}function Xs(n,o,e,t){var s;const i=t.length,r=[];for(let l=1;l<=o;l++){const c=(l-1)%n.length,d=a.Tools.deepClone(n[c]);Et(d);const u=`${(s=n[n.length-1])==null?void 0:s.v}`;let h=t.indexOf(u)+e*l;h<0&&(h+=Math.abs(e)*i);const g=h%i;d&&(d.v=t[g],r.push(d))}return r}function kd(n,o){const e=[];let t;if(o.startRow<n.startRow)t=a.Direction.UP;else if(o.endRow>n.endRow)t=a.Direction.DOWN;else if(o.startColumn<n.startColumn)t=a.Direction.LEFT;else if(o.endColumn>n.endColumn)t=a.Direction.RIGHT;else return[];if(t===a.Direction.DOWN||t===a.Direction.UP){const i=n.endRow-n.startRow+1,r=o.endRow-o.startRow+1,s=Math.floor(r/i),l=r%i,c={startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:n.endColumn-n.startColumn};if(t===a.Direction.DOWN){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow+(d+1)*i,col:n.startColumn},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow+(s+1)*i,col:n.startColumn},relativeRange:{startRow:0,startColumn:0,endRow:l-1,endColumn:n.endColumn-n.startColumn}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow-(d+1)*i,col:n.startColumn},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow-(s+1)*i,col:n.startColumn},relativeRange:{startRow:i-l,endRow:i-1,startColumn:0,endColumn:n.endColumn-n.startColumn}})}}if(t===a.Direction.RIGHT||t===a.Direction.LEFT){const i=n.endColumn-n.startColumn+1,r=o.endColumn-o.startColumn+1,s=Math.floor(r/i),l=r%i,c={startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:n.endColumn-n.startColumn};if(t===a.Direction.RIGHT){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow,col:n.startColumn+(d+1)*i},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow,col:n.startColumn+(s+1)*i},relativeRange:{startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:l-1}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow,col:n.startColumn-(d+1)*i},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow,col:n.startColumn-(s+1)*i},relativeRange:{startRow:0,startColumn:i-l,endRow:n.endRow-n.startRow,endColumn:i-1}})}}return e}function Ys(n){return!(a.isFormulaString(n.f)||a.isFormulaId(n.si)||n.t===a.CellValueType.BOOLEAN)}function Et(n){n&&"custom"in n&&delete n.custom}var en=(n=>(n.Append="APPEND",n.Default="DEFAULT",n.Only="ONLY",n))(en||{}),Ie=(n=>(n.NUMBER="number",n.DATE="date",n.EXTEND_NUMBER="extendNumber",n.CHN_NUMBER="chnNumber",n.CHN_WEEK2="chnWeek2",n.CHN_WEEK3="chnWeek3",n.LOOP_SERIES="loopSeries",n.FORMULA="formula",n.OTHER="other",n))(Ie||{}),ae=(n=>(n.COPY="COPY",n.SERIES="SERIES",n.ONLY_FORMAT="ONLY_FORMAT",n.NO_FORMAT="NO_FORMAT",n))(ae||{});const Hd={type:Ie.DATE,priority:1100,match:(n,o)=>{var e;if(n!=null&&n.f||n!=null&&n.si)return!1;if((typeof(n==null?void 0:n.v)=="number"||(n==null?void 0:n.t)===a.CellValueType.NUMBER)&&n.s){if(typeof n.s=="string"){const i=o.get(a.IUniverInstanceService).getFocusedUnit().getStyles().get(n.s),r=(e=i==null?void 0:i.n)==null?void 0:e.pattern;if(r)return a.numfmt.getFormatInfo(r).isDate}else if(n.s.n&&a.numfmt.getFormatInfo(n.s.n.pattern).isDate)return!0}return!1},isContinue:(n,o)=>n.type===Ie.DATE,applyFunctions:{[ae.SERIES]:(n,o,e)=>{const{data:t}=n;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),ji(t,o,e).reverse()):ji(t,o,e)}}},Vd={type:Ie.NUMBER,priority:1e3,match:n=>typeof(n==null?void 0:n.v)=="number"||(n==null?void 0:n.t)===a.CellValueType.NUMBER,isContinue:(n,o)=>n.type===Ie.NUMBER,applyFunctions:{[ae.SERIES]:(n,o,e)=>{const{data:t}=n;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),ji(t,o,e).reverse()):ji(t,o,e)}}},js={type:Ie.OTHER,priority:0,match:()=>!0,isContinue:(n,o)=>n.type===Ie.OTHER},Wd={type:Ie.EXTEND_NUMBER,priority:900,match:n=>Yi(`${n==null?void 0:n.v}`||"").isExtendNumber,isContinue:(n,o)=>{var e;if(n.type===Ie.EXTEND_NUMBER){const{beforeTxt:t,afterTxt:i}=Yi(`${(e=n.cellData)==null?void 0:e.v}`||""),{beforeTxt:r,afterTxt:s}=Yi(`${o==null?void 0:o.v}`||"");if(t===r&&i===s)return!0}return!1},applyFunctions:{[ae.SERIES]:(n,o,e)=>{var l;const{data:t}=n,i=e===a.Direction.UP||e===a.Direction.LEFT;let r;if(t.length===1)return r=i?-1:1,ke(Fs(t,o,r),i);const s=[];for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`;d&&s.push(Number(Yi(d).matchTxt))}return i&&(t.reverse(),s.reverse()),ei(s)?(r=s[1]-s[0],ke(Fs(t,o,r),i)):wt(t,o)}}},Ld={type:Ie.CHN_NUMBER,priority:830,match:n=>!!Ed(`${n==null?void 0:n.v}`||""),isContinue:(n,o)=>n.type===Ie.CHN_NUMBER,applyFunctions:{[ae.SERIES]:(n,o,e)=>{var c,d,u;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){const h=`${(c=t[0])==null?void 0:c.v}`;let g;return i?g=-1:g=1,h&&(h==="日"||Qe(h)<7)?ke($t(t,o,g),i):ke(zs(t,o,g),i)}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 g=`${(u=t[h])==null?void 0:u.v}`;g==="日"?h===0?s.push(0):(l++,s.push(l*7)):r&&Qe(g)>0&&Qe(g)<7?s.push(Qe(g)+l*7):s.push(Qe(g))}if(i&&(t.reverse(),s.reverse()),ei(s)){if(r||s[s.length-1]<6&&s[0]>0||s[0]<6&&s[s.length-1]>0){const g=s[1]-s[0];return ke($t(t,o,g),i)}const h=s[1]-s[0];return ke(zs(t,o,h),i)}return wt(t,o)}}},xd={type:Ie.CHN_WEEK2,priority:820,match:n=>!!yd(`${n==null?void 0:n.v}`||""),isContinue:(n,o)=>n.type===Ie.CHN_WEEK2,applyFunctions:{[ae.SERIES]:(n,o,e)=>{var l;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let c;return i?c=-1:c=1,ke($t(t,o,c,1),i)}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(Qe(u)+s*7)}if(i&&(t.reverse(),r.reverse()),ei(r)){const c=r[1]-r[0];return ke($t(t,o,c,1),i)}return wt(t,o)}}},Ud={type:Ie.CHN_WEEK3,priority:810,match:n=>Td(`${n==null?void 0:n.v}`||""),isContinue:(n,o)=>n.type===Ie.CHN_WEEK3,applyFunctions:{[ae.SERIES]:(n,o,e)=>{var l;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let c;return i?c=-1:c=1,ke($t(t,o,c,2),i)}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(Qe(u)+s*7)}}if(i&&(t.reverse(),r.reverse()),ei(r)){const c=r[1]-r[0];return ke($t(t,o,c,2),i)}return wt(t,o)}}},Bd={type:Ie.LOOP_SERIES,priority:800,match:n=>Nd(`${n==null?void 0:n.v}`||""),isContinue:(n,o)=>{var e;return n.type===Ie.LOOP_SERIES?er(`${(e=n.cellData)==null?void 0:e.v}`||"").name===er(`${o==null?void 0:o.v}`||"").name:!1},applyFunctions:{[ae.SERIES]:(n,o,e)=>{var c,d;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP,{series:r}=er(`${(c=t[0])==null?void 0:c.v}`||"");if(t.length===1){let u;return i?u=-1:u=1,ke(Xs(t,o,u,r),i)}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(i&&(t.reverse(),s.reverse()),ei(s)){const u=s[1]-s[0];return ke(Xs(t,o,u,r),i)}return wt(t,o)}}};function ke(n,o){return o?n.reverse():n}var Fd=Object.getOwnPropertyDescriptor,zd=(n,o,e,t)=>{for(var i=t>1?void 0:t?Fd(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},tn=(n,o)=>(e,t)=>o(e,t,n);E.AutoFillService=class extends a.Disposable{constructor(e,t,i,r,s,l){super();T(this,"_rules",[]);T(this,"_hooks",[]);T(this,"_applyType$",new D.BehaviorSubject(ae.SERIES));T(this,"_isFillingStyle",!0);T(this,"_prevUndos",[]);T(this,"_autoFillLocation$",new D.BehaviorSubject(null));T(this,"autoFillLocation$",this._autoFillLocation$.asObservable());T(this,"_showMenu$",new D.BehaviorSubject(!1));T(this,"showMenu$",this._showMenu$.asObservable());T(this,"_direction",a.Direction.DOWN);T(this,"applyType$",this._applyType$.asObservable());T(this,"_menu$",new D.BehaviorSubject([{label:"autoFill.copy",value:ae.COPY,disable:!1},{label:"autoFill.series",value:ae.SERIES,disable:!1},{label:"autoFill.formatOnly",value:ae.ONLY_FORMAT,disable:!1},{label:"autoFill.noFormat",value:ae.NO_FORMAT,disable:!1}]));T(this,"menu$",this._menu$.asObservable());this._commandService=e,this._undoRedoService=t,this._renderManagerService=i,this._univerInstanceService=r,this._selectionManagerService=s,this._injector=l,this._init()}_init(){this._rules=[Hd,Vd,Wd,Ld,xd,Ud,Bd,js].sort((e,t)=>t.priority-e.priority),this._isFillingStyle=!0}_getOneByPriority(e){return e.length<=0?[]:[e.reduce((i,r)=>(r.priority||0)>(i.priority||0)?r:i,e[0])]}_initPrevUndo(){this._prevUndos=[]}async triggerAutoFill(e,t,i,r,s){var f;if(i.startColumn===r.startColumn&&i.startRow===r.startRow&&i.endColumn===r.endColumn&&i.endRow===r.endRow)return!1;if(r.endColumn<i.endColumn&&r.endColumn>i.startColumn)return this._commandService.executeCommand(nn.id,{clearRange:{startRow:r.startRow,endRow:r.endRow,startColumn:r.endColumn+1,endColumn:i.endColumn},selectionRange:r});if(r.endRow<i.endRow&&r.endRow>i.startRow)return this._commandService.executeCommand(nn.id,{clearRange:{startRow:r.endRow+1,endRow:i.endRow,startColumn:r.startColumn,endColumn:r.endColumn},selectionRange:r});const l={startRow:r.startRow,endRow:r.endRow,startColumn:r.startColumn,endColumn:r.endColumn};let c=null;if(r.startRow<i.startRow)c=a.Direction.UP,l.endRow=i.startRow-1;else if(r.endRow>i.endRow)c=a.Direction.DOWN,l.startRow=i.endRow+1;else if(r.startColumn<i.startColumn)c=a.Direction.LEFT,l.endColumn=i.startColumn-1;else if(r.endColumn>i.endColumn)c=a.Direction.RIGHT,l.startColumn=i.endColumn+1;else return!1;this.direction=c;const d=this._injector.invoke(v=>m.rangeToDiscreteRange(i,v)),u=this._injector.invoke(v=>m.rangeToDiscreteRange(l,v));if(!d||!u)return!1;this.autoFillLocation={source:d,target:u,unitId:e,subUnitId:t};const h=[];if(this.getActiveHooks().forEach(v=>{var C;const p=(C=v==null?void 0:v.onBeforeFillData)==null?void 0:C.call(v,{source:d,target:u,unitId:e,subUnitId:t},c);p&&h.unshift(p)}),this._initPrevUndo(),s)return this.fillData(s);for(let v=0;v<h.length;v++){const p=this.menu.find(C=>C.value===h[v]);if(p&&!p.disable)return this.fillData(h[v])}const S=(f=this.menu.find(v=>v.disable===!1))==null?void 0:f.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=en.Append),this._hooks.push(e),a.toDisposable(()=>{const t=this._hooks.findIndex(i=>i===e);t>-1&&this._hooks.splice(t,1)})}registerRule(e){if(this._rules.find(i=>i.type===e.type))throw new Error(`Registry rule failed, type '${e.type}' already exist!`);const t=this._rules.findIndex(i=>i.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:i,subUnitId:r}=this.autoFillLocation||{};if(!e||!t||!i||!r)return[];const s=this._hooks.filter(u=>{var h;return!((h=u.disable)!=null&&h.call(u,{source:e,target:t,unitId:i,subUnitId:r},this._direction,this.applyType))}),l=s.filter(u=>u.type===en.Only);if(l.length>0)return this._getOneByPriority(l);const c=this._getOneByPriority(s.filter(u=>u.type===en.Default)),d=s.filter(u=>u.type===en.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(i=>i.value===e?{...i,disable:t}:i))}setShowMenu(e){this._showMenu$.next(e)}fillData(e){var y,O,R;this.applyType=e;const t=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),i=t==null?void 0:t.getUnitId(),r=(y=t==null?void 0:t.getActiveSheet())==null?void 0:y.getSheetId(),{source:s,target:l,unitId:c=i,subUnitId:d=r}=this.autoFillLocation||{};if(!s||!l||!c||!d)return!1;const u=this.direction;this._prevUndos.length>0&&this._prevUndos.forEach(P=>{this._commandService.syncExecuteCommand(P.id,P.params)}),this._prevUndos=[];const h=a.Rectangle.union(at(s),at(l)),g=this.getActiveHooks(),S=this._univerInstanceService.getUnit(c,a.UniverInstanceType.UNIVER_SHEET);c===i&&d===r&&this._commandService.syncExecuteCommand(m.SetSelectionsOperation.id,{selections:[{primary:{...(R=(O=this._selectionManagerService.getCurrentLastSelection())==null?void 0:O.primary)!=null?R:h},range:{...h,rangeType:a.RANGE_TYPE.NORMAL}}],unitId:c,subUnitId:d});const f=[],v=[];g.forEach(P=>{var k;const{undos:A,redos:N}=((k=P.onFillData)==null?void 0:k.call(P,{source:s,target:l,unitId:c,subUnitId:d},u,e))||{};A&&f.push(...A),N&&v.push(...N)});const p=v.every(P=>this._commandService.syncExecuteCommand(P.id,P.params)),C=[];e!==ae.NO_FORMAT&&v.forEach(P=>{if(P.id===m.SetRangeValuesMutation.id){const{cellValue:A}=P.params;new a.ObjectMatrix(A).forValue((k,H,V)=>{const W=Object.keys(S.getStyles().get(V==null?void 0:V.s)||{});(V!=null&&V.p||W.length&&xs.some(L=>W.includes(L)))&&C.push({startRow:k,endRow:k,startColumn:H,endColumn:H})})}});const _=this._getAutoHeightUndoRedos(c,d,C);return _.redos.every(P=>this._commandService.syncExecuteCommand(P.id,P.params))&&(f.push(..._.undos),v.push(..._.redos)),p&&(this._prevUndos=f,this._undoRedoService.pushUndoRedo({unitID:c,undoMutations:f,redoMutations:v})),g.forEach(P=>{var A;(A=P.onAfterFillData)==null||A.call(P,{source:s,target:l,unitId:c,subUnitId:d},u,e)}),this.setShowMenu(!0),!0}_getAutoHeightUndoRedos(e,t,i){var h,g;const r=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(E.SheetSkeletonManagerService),s=(g=r==null?void 0:r.getCurrentParam())==null?void 0:g.skeleton;if(!s)return{redos:[],undos:[]};const l=s.calculateAutoHeightInRange(i),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}]}}},E.AutoFillService=zd([tn(0,a.ICommandService),tn(1,a.IUndoRedoService),tn(2,M.IRenderManagerService),tn(3,a.Inject(a.IUniverInstanceService)),tn(4,a.Inject(m.SheetsSelectionsService)),tn(5,a.Inject(a.Injector))],E.AutoFillService);const ct=a.createIdentifier("univer.auto-fill-service"),dt={type:a.CommandType.COMMAND,id:"sheet.command.auto-fill",handler:async(n,o)=>{const e=n.get(ct),t=n.get(a.IUniverInstanceService),{sourceRange:i,targetRange:r,applyType:s}=o,l=m.getSheetCommandTarget(t,o);if(!l)return!1;const{subUnitId:c,unitId:d}=l;return e.triggerAutoFill(d,c,i,r,s)}},nn={id:"sheet.command.auto-clear-content",type:a.CommandType.COMMAND,handler:async(n,o)=>{const e=n.get(a.IUniverInstanceService),t=n.get(a.ICommandService),i=n.get(a.IUndoRedoService),r=n.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])},g=m.SetRangeValuesUndoMutationFactory(n,h),{startColumn:S,startRow:f}=u,v={selections:[{primary:{startColumn:S,startRow:f,endColumn:S,endRow:f,actualRow:f,actualColumn:S,isMerged:!1,isMergedMainCell:!1},range:{...u}}],unitId:l,subUnitId:c};if(t.executeCommand(m.SetSelectionsOperation.id,v),t.syncExecuteCommand(m.SetRangeValuesMutation.id,h)){const C=r.afterCommandExecute({id:m.SetRangeValuesMutation.id,params:h});return a.sequenceExecute(C.redos,t),i.pushUndoRedo({unitID:l,undoMutations:[{id:m.SetRangeValuesMutation.id,params:g},...C.undos],redoMutations:[{id:m.SetRangeValuesMutation.id,params:h},...C.redos]}),!0}return!1}};function tr(n){return n.getContextValue(a.FOCUSING_SHEET)}function se(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function Zs(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function Xd(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function nr(n){return n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function Zi(n){return n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function Yd(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.EDITOR_ACTIVATED)&&n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function on(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&!n.getContextValue(a.FOCUSING_EDITOR_STANDALONE)}var jd=Object.getOwnPropertyDescriptor,Zd=(n,o,e,t)=>{for(var i=t>1?void 0:t?jd(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},ir=(n,o)=>(e,t)=>o(e,t,n);const Gs=Ko.MARK_SELECTION,yt=a.createIdentifier("univer.mark-selection-service");E.MarkSelectionService=class extends a.Disposable{constructor(e,t,i){super();T(this,"_shapeMap",new Map);this._currentService=e,this._renderManagerService=t,this._themeService=i}addShape(e,t=[],i=Gs){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.generateRandomId(),c={selection:e,subUnitId:s,unitId:r.getUnitId(),zIndex:i,control:null,exits:t};return this._shapeMap.set(l,c),this.refreshShapes(),l}addShapeWithNoFresh(e,t=[],i=Gs){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.generateRandomId();return this._shapeMap.set(l,{selection:e,subUnitId:s,unitId:r.getUnitId(),zIndex:i,control:null,exits:t}),l}refreshShapes(){var r;const e=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!e)return;const t=e.getUnitId(),i=(r=e.getActiveSheet())==null?void 0:r.getSheetId();this._shapeMap.forEach(s=>{const{unitId:l,subUnitId:c,selection:d,control:u,zIndex:h}=s;if(u==null||u.dispose(),l!==t||c!==i)return;const g=this._renderManagerService.getRenderById(l);if(!g)return;const S=g.with(E.SheetSkeletonManagerService).getCurrentSkeleton();if(!S)return;const{scene:f}=g,{rowHeaderWidth:v,columnHeaderHeight:p}=S,C=new Jn(f,h,this._themeService,{enableAutoFill:!1,highlightHeader:!1,rowHeaderWidth:v,columnHeaderHeight:p}),_=Re(d,S);C.updateRangeBySelectionWithCoord(_),s.control=C})}getShapeMap(){return this._shapeMap}removeShape(e){const t=this._shapeMap.get(e);if(!t)return;const{control:i}=t;i==null||i.dispose(),this._shapeMap.delete(e)}removeAllShapes(){for(const e of this._shapeMap.values()){const{control:t}=e;t==null||t.dispose()}this._shapeMap.clear()}},E.MarkSelectionService=Zd([ir(0,a.IUniverInstanceService),ir(1,M.IRenderManagerService),ir(2,a.Inject(a.ThemeService))],E.MarkSelectionService);function Ks(n){return{strokeWidth:1.5,stroke:n.getColorFromTheme("primary.600"),fill:"rgba(178, 178, 178, 0.10)",widgets:{},strokeDash:8}}function Gd(n){if(n==null)return n;const o={};return n.p!==void 0&&(o.p=n.p===null?null:a.cloneValue(n.p)),n.s!==void 0&&(n.s===null||typeof n.s=="string"?o.s=n.s:o.s=a.cloneValue(n.s)),n.v!==void 0&&(o.v=n.v),n.t!==void 0&&(o.t=n.t),n.f!==void 0&&(o.f=n.f),n.ref!==void 0&&(o.ref=n.ref),n.xf!==void 0&&(o.xf=n.xf),n.si!==void 0&&(o.si=n.si),n.custom!==void 0&&(o.custom=n.custom===null?null:a.cloneValue(n.custom)),n.rowSpan!==void 0&&(o.rowSpan=n.rowSpan),n.colSpan!==void 0&&(o.colSpan=n.colSpan),n.plain!==void 0&&(o.plain=n.plain),o}const Kd=10,qd=6;function Qd(){return a.generateRandomId(qd)}function Jd(n){const o=n.match(/data-copy-id="([^\s]+)"/);return o&&o[1]?o[1]:null}class $d{constructor(){T(this,"_cache",new a.LRUMap(Kd));T(this,"_lastCopyId$",new D.BehaviorSubject(null));T(this,"lastCopyId$",this._lastCopyId$.asObservable())}set(o,e){this._cache.set(o,e),this._lastCopyId$.next(o)}get(o){return this._cache.get(o)}del(o){this._cache.delete(o),this._lastCopyId$.getValue()===o&&this._lastCopyId$.next(null)}clear(){this._cache.clear(),this._lastCopyId$.next(null)}clearWithUnitId(o){this._cache.forEach((e,t)=>{e.unitId===o&&this._cache.delete(t)})}getLastCopyId(){return this._lastCopyId$.getValue()}}function Gi(n,o){const e=o!=null?o:n.style,t={},i=n.tagName.toLowerCase();switch(i){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=i==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}return eu(e,t),t}function eu(n,o){if(n instanceof CSSStyleDeclaration)for(let e=0;e<n.length;e++){const t=n[e],i=n.getPropertyValue(t);qs(t,i,o)}else for(const e in n){const t=n[e];qs(e,t,o)}}function qs(n,o,e){switch(n){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);t.isValid&&(e.bg={rgb:t.toRgbString()});break}}}function tu(n){const o=document.createElement("body");return o.innerHTML=n,o}function Qs(n){const o=n.style,e={};for(let t=0;t<o.length;t++){const i=o[t],r=o.getPropertyValue(i);switch(i){case"margin-top":{const s=Number.parseInt(r);e.spaceAbove={v:/pt/.test(r)?M.ptToPixel(s):s};break}case"margin-bottom":{const s=Number.parseInt(r);e.spaceBelow={v:/pt/.test(r)?M.ptToPixel(s):s};break}case"line-height":{const s=Number.parseFloat(r);e.lineSpacing=s;break}}}return Object.getOwnPropertyNames(e).length?e:null}function or(n,o){const e=[];for(let t=0,i=n.length;t<i;t++)n[t]===a.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});return e}function Js(n,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 n.p?r&&((c=(l=n.p.body)==null?void 0:l.textRuns)!=null&&c.length)?(n.p.body.textRuns=[],{...n,s:e[0].ts}):n:r?{...n,s:e[0].ts}:n}const $s=["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 ea(n,o){const e=n.tagName.toLowerCase();return typeof o=="string"?e===o:Array.isArray(o)?o.some(t=>t===e):o(n)}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(v=>v.checkPasteType(o));e&&(this._styleRules=[...e.stylesRules],this._afterProcessRules=[...e.afterProcessRules]);const t=new a.ObjectMatrix;this._dom=tu(o);const i=this._dom.querySelector("style");if(i){const v=document.createElement("div"),p=v.attachShadow({mode:"open"});document.body.appendChild(v),p.appendChild(i);for(const C of i.sheet.cssRules){const _=C,w=_.selectorText,y=_.style;this._styleMap.set(w,y)}i.remove(),v.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:g,payloads:S,customRanges:f}=r;if(u){const v=u.map(p=>p.startIndex+1);v.unshift(0);for(let p=0;p<v.length;p++){let C;if(p===v.length-1){if(C=`${h.substring(v[p])}\r
1
+ (function(E,q){typeof exports=="object"&&typeof module<"u"?q(exports,require("@univerjs/docs-ui"),require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-render"),require("rxjs"),require("@univerjs/ui"),require("@univerjs/docs"),require("react"),require("@univerjs/engine-formula"),require("react/jsx-runtime"),require("@univerjs/design"),require("rxjs/operators"),require("@univerjs/telemetry")):typeof define=="function"&&define.amd?define(["exports","@univerjs/docs-ui","@univerjs/core","@univerjs/sheets","@univerjs/engine-render","rxjs","@univerjs/ui","@univerjs/docs","react","@univerjs/engine-formula","react/jsx-runtime","@univerjs/design","rxjs/operators","@univerjs/telemetry"],q):(E=typeof globalThis<"u"?globalThis:E||self,q(E.UniverSheetsUi={},E.UniverDocsUi,E.UniverCore,E.UniverSheets,E.UniverEngineRender,E.rxjs,E.UniverUi,E.UniverDocs,E.React,E.UniverEngineFormula,E.React,E.UniverDesign,E.rxjs.operators,E.UniverTelemetry))})(this,(function(E,q,a,m,M,D,I,be,x,K,b,Y,ce,ud){"use strict";var wp=Object.defineProperty;var Ep=(E,q,a)=>q in E?wp(E,q,{enumerable:!0,configurable:!0,writable:!0,value:a}):E[q]=a;var T=(E,q,a)=>Ep(E,typeof q!="symbol"?q+"":q,a);function Ui(n,o){if(n==null)return;const e=o.getRenderById(n);if(e==null)return;const{mainComponent:t,scene:i,engine:r,components:s}=e,l=t,c=s.get(q.DOCS_VIEW_KEY.BACKGROUND);return{document:l,docBackground:c,scene:i,engine:r}}const Yo=[10,400],jo="RANGE_SELECTOR_COMPONENT_KEY",Bi="EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY";var ue=(n=>(n.MAIN="__SpreadsheetRender__",n.ROW="__SpreadsheetRowHeader__",n.COLUMN="__SpreadsheetColumnHeader__",n.LEFT_TOP="__SpreadsheetLeftTopPlaceholder__",n))(ue||{});const Ds=0,Fi=1,st=10,hd=11,Ns=12,Kn={id:"sheet.command.set-row-header-width",type:a.CommandType.COMMAND,handler:async(n,o)=>{if(!o)return!1;const e=n.get(M.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:i,size:r}=o,s=e.getRenderById(t);if(s){e.getRenderById(t).with(E.SheetSkeletonManagerService).setRowHeaderSize(s,i,r);const{components:c}=s,d=c.get(ue.ROW);d&&d.setCustomHeader({headerStyle:{size:r}},i)}return!0}},qn={id:"sheet.command.set-col-header-height",type:a.CommandType.COMMAND,handler:async(n,o)=>{if(!o)return!1;const e=n.get(M.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:i,size:r}=o,s=e.getRenderById(t);if(s){e.getRenderById(t).with(E.SheetSkeletonManagerService).setColumnHeaderSize(s,i,r);const{components:c}=s,d=c.get(ue.COLUMN);d&&d.setCustomHeader({headerStyle:{size:r}},i)}return!0}},Zo=a.createInterceptorKey("rangeMovePermissionCheck"),Go=a.createInterceptorKey("rangeFillPermissionCheck");var Ko=(n=>(n[n.FORMULA_EDITOR_SHOW=100]="FORMULA_EDITOR_SHOW",n[n.MARK_SELECTION=1e4]="MARK_SELECTION",n))(Ko||{});function qe(n){const o=n.getColorFromTheme("primary.600"),e=n.getColorFromTheme("white"),t=new a.ColorKit(o).setAlpha(.07).toRgbString();return{strokeWidth:1,stroke:o,fill:t,widgets:{},widgetSize:6,widgetStrokeWidth:1,widgetStroke:e,autofillSize:6,autofillStrokeWidth:1,autofillStroke:e,rowHeaderFill:t,rowHeaderStroke:o,rowHeaderStrokeWidth:1,columnHeaderFill:t,columnHeaderStroke:o,columnHeaderStrokeWidth:1,expandCornerSize:40}}class md{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:i,endRow:r}=this,{startColumn:s,startRow:l,endColumn:c,endRow:d}=o;return e===s&&t===l&&i===c&&r===d}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:i,endColumn:r,endRow:s,startX:l,startY:c,endX:d,endY:u,rangeType:h}=o;this._startColumn=t,this._startRow=i,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 Jt(n,o){const{startRow:e,startColumn:t,endRow:i,endColumn:r,rangeType:s}=o,l=i<e?i:e,c=i<e?e:i,d=r<t?r:t,u=r<t?t:r,h=n.getNoMergeCellWithCoordByIndex(l,d),g=n.getNoMergeCellWithCoordByIndex(c,u);return{startRow:e,startColumn:t,endRow:i,endColumn:r,rangeType:s,startY:(h==null?void 0:h.startY)||0,endY:(g==null?void 0:g.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(g==null?void 0:g.endX)||0}}function Re(n,o){const{range:e,primary:t,style:i}=n,r=Jt(o,e),s=t&&Qn(o,t);return{rangeWithCoord:r,primaryWithCoord:s,style:i}}function Qn(n,o){const{actualRow:e,actualColumn:t,isMerged:i,isMergedMainCell:r,startRow:s,startColumn:l,endRow:c,endColumn:d}=o,u=n.getNoMergeCellWithCoordByIndex(e,t),h=n.getNoMergeCellWithCoordByIndex(s,l),g=n.getNoMergeCellWithCoordByIndex(c,d);return{actualRow:e,actualColumn:t,isMerged:i,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:(g==null?void 0:g.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(g==null?void 0:g.endX)||0}}}const ks="__SpreadsheetHelperSelectionTempRect",gd=35;class Hs{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,"_disabled",!1);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()}setDisabled(o){this._disabled=o}_getFreeze(){var e,t;return(t=(e=M.withCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET,E.SheetSkeletonManagerService,this._injector.get(a.IUniverInstanceService),this._injector.get(M.IRenderManagerService)))==null?void 0:e.getCurrentParam())==null?void 0:t.skeleton.getWorksheetConfig().freeze}_isSelectionInViewport(o,e){const t=this._getFreeze()||{startRow:-1,startColumn:-1};switch(e.viewportKey){case M.SHEET_VIEWPORT_KEY.VIEW_MAIN:return o.endRow>=t.startRow&&o.endColumn>=t.startColumn;case M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP:case M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT:return o.endColumn>=t.startColumn&&o.startRow<t.startRow;case M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT:case M.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM:return o.endRow>=t.startRow&&o.startColumn<t.startColumn;case M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP:case M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT:case M.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP:case M.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:i}=this._control;[o,e,t,i].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(M.CURSOR_TYPE.MOVE)}),r.onPointerLeave$.subscribeEvent(()=>{r.resetCursor()}),r.onPointerDown$.subscribeEvent(this._controlPointerDownHandler.bind(this))})}_controlMoving(o,e){var N;const t=this._scene,i=t.getScrollXYInfoByViewport(M.Vector2.FromArray([o,e])),{scaleX:r,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(o,e,r,s,i),{row:c,column:d}=l,u=this._skeleton.getRowCount()-1,h=this._skeleton.getColumnCount()-1;let g=Math.max(0,c+this._relativeSelectionPositionRow),S=g+this._relativeSelectionRowLength;S>u&&(S=u,S-g<this._relativeSelectionRowLength&&(g=S-this._relativeSelectionRowLength));let f=Math.max(0,d+this._relativeSelectionPositionColumn),v=f+this._relativeSelectionColumnLength;v>h&&(v=h,v-f<this._relativeSelectionColumnLength&&(f=v-this._relativeSelectionColumnLength));const p=this._skeleton.worksheet.getCellInfoInMergeData(g,f),_=Re({range:{startRow:g,endRow:S,startColumn:f,endColumn:v},primary:p,style:null},this._skeleton),w=this._skeleton.getNoMergeCellWithCoordByIndex(g,f),y=this._skeleton.getNoMergeCellWithCoordByIndex(S,v),O=(w==null?void 0:w.startY)||0,R=(y==null?void 0:y.endY)||0,P=(w==null?void 0:w.startX)||0,A=(y==null?void 0:y.endX)||0;(N=this._helperSelection)==null||N.transformByState({left:P,top:O,width:A-P,height:R-O}),this._targetSelection={..._.rangeWithCoord},this._control.selectionMoving$.next(_.rangeWithCoord)}_controlPointerDownHandler(o){const{offsetX:e,offsetY:t}=o,i=this._scene,r=i.getCoordRelativeToViewport(M.Vector2.FromArray([e,t])),{x:s,y:l}=r,c=i.getScrollXYInfoByViewport(r),{scaleX:d,scaleY:u}=i.getAncestorScale(),h=this._skeleton.getCellIndexByOffset(s,l,d,u,c);this._startOffsetX=s,this._startOffsetY=l;const{row:g,column:S}=h,{startRow:f,startColumn:v,endRow:p,endColumn:C}=this._control.model;let _=0,w=0;g<f?_-=1:g>p&&(_+=1),S<v?w-=1:S>C&&(w+=1),this._relativeSelectionPositionRow=f-g+_,this._relativeSelectionPositionColumn=v-S+w,this._relativeSelectionRowLength=p-f,this._relativeSelectionColumnLength=C-v;const y=this._control.currentStyle,O=this._getScale();this.isHelperSelection&&(this._helperSelection=new M.Rect(ks,{stroke:y.stroke,strokeWidth:y.strokeWidth/O}),i.addObject(this._helperSelection));const R=i.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN),P=M.ScrollTimer.create(i);this._scrollTimer=P,P.startScroll(s,l,R),i.disableObjectsEvent(),this._scenePointerMoveSub=i.onPointerMove$.subscribeEvent(A=>{var L;if(this._disabled)return;const{offsetX:N,offsetY:k}=A;if(((L=this._injector.get(Ce,a.Quantity.OPTIONAL))==null?void 0:L.interceptor.fetchThroughInterceptors(Zo)(!1,null))===!1)return;const{x:V,y:W}=i.getCoordRelativeToViewport(M.Vector2.FromArray([N,k]));this._controlMoving(V,W),i.setCursor(M.CURSOR_TYPE.MOVE),P.scrolling(V,W,()=>{this._controlMoving(V,W)})}),this._scenePointerUpSub=i.onPointerUp$.subscribeEvent(()=>{var N,k,H,V;(N=this._helperSelection)==null||N.dispose();const A=this._scene;A.resetCursor(),this._clearObserverEvent(),A.enableObjectsEvent(),(k=this._scrollTimer)==null||k.dispose(),this._control.selectionMoveEnd$.next(this._targetSelection),(V=(H=this._selectionHooks).selectionMoveEnd)==null||V.call(H)})}_initialWidget(){const{topLeftWidget:o,topCenterWidget:e,topRightWidget:t,middleLeftWidget:i,middleRightWidget:r,bottomLeftWidget:s,bottomCenterWidget:l,bottomRightWidget:c}=this._control,d=[M.CURSOR_TYPE.NORTH_WEST_RESIZE,M.CURSOR_TYPE.NORTH_RESIZE,M.CURSOR_TYPE.NORTH_EAST_RESIZE,M.CURSOR_TYPE.WEST_RESIZE,M.CURSOR_TYPE.EAST_RESIZE,M.CURSOR_TYPE.SOUTH_WEST_RESIZE,M.CURSOR_TYPE.SOUTH_RESIZE,M.CURSOR_TYPE.SOUTH_EAST_RESIZE];[o,e,t,i,r,s,l,c].forEach((u,h)=>{u.onPointerEnter$.subscribeEvent(()=>{u.setCursor(d[h])}),u.onPointerLeave$.subscribeEvent(()=>{u.resetCursor()}),u.onPointerDown$.subscribeEvent(g=>{this._widgetPointerDownEvent(g,d[h])})})}_widgetPointerDownEvent(o,e){const t=this._scene,{offsetX:i,offsetY:r}=o,s=t.getCoordRelativeToViewport(M.Vector2.FromArray([i,r])),{x:l,y:c}=s;this._startOffsetX=i,this._startOffsetY=r;const{startRow:d,startColumn:u,endRow:h,endColumn:g}=this._control.model,S=Math.min(d,h),f=Math.min(u,g),v=Math.max(d,h),p=Math.max(u,g);this._relativeSelectionPositionRow=S,this._relativeSelectionPositionColumn=f,this._relativeSelectionRowLength=v-S,this._relativeSelectionColumnLength=p-f,e===M.CURSOR_TYPE.NORTH_WEST_RESIZE?(this._relativeSelectionPositionRow=v,this._relativeSelectionPositionColumn=p):e===M.CURSOR_TYPE.NORTH_RESIZE?this._relativeSelectionPositionRow=v:e===M.CURSOR_TYPE.NORTH_EAST_RESIZE?this._relativeSelectionPositionRow=v:e===M.CURSOR_TYPE.WEST_RESIZE?this._relativeSelectionPositionColumn=p:e===M.CURSOR_TYPE.SOUTH_WEST_RESIZE?this._relativeSelectionPositionColumn=p:e===M.CURSOR_TYPE.SOUTH_RESIZE&&(this._relativeSelectionPositionRow=S);const C=M.ScrollTimer.create(t),_=t.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN);C.startScroll(l,c,_),this._scrollTimer=C,t.disableObjectsEvent(),this._scenePointerMoveSub=t.onPointerMove$.subscribeEvent(w=>{const{offsetX:y,offsetY:O}=w,{x:R,y:P}=t.getCoordRelativeToViewport(M.Vector2.FromArray([y,O]));this._widgetMoving(R,P,e),t.setCursor(e),C.scrolling(R,P,()=>{this._widgetMoving(R,P,e)})}),this._scenePointerUpSub=t.onPointerUp$.subscribeEvent(()=>{var y,O,R;const w=this._scene;w.resetCursor(),this._clearObserverEvent(),w.enableObjectsEvent(),(y=this._scrollTimer)==null||y.dispose(),this._control.selectionScaled$.next(this._targetSelection),(R=(O=this._selectionHooks).selectionMoveEnd)==null||R.call(O)})}_widgetMoving(o,e,t){const i=this._scene,r=i.getScrollXYInfoByViewport(M.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:s,scaleY:l}=i.getAncestorScale(),c=this._skeleton.getCellIndexByOffset(o,e,s,l,r),{row:d,column:u}=c;let h=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,S=d,f=u;t===M.CURSOR_TYPE.NORTH_WEST_RESIZE?(h=d,g=u,S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn):t===M.CURSOR_TYPE.NORTH_RESIZE?(h=d,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength):t===M.CURSOR_TYPE.NORTH_EAST_RESIZE?(h=d,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,f=u):t===M.CURSOR_TYPE.WEST_RESIZE?(h=this._relativeSelectionPositionRow,g=u,S=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,f=this._relativeSelectionPositionColumn):t===M.CURSOR_TYPE.EAST_RESIZE?S=this._relativeSelectionPositionRow+this._relativeSelectionRowLength:t===M.CURSOR_TYPE.SOUTH_WEST_RESIZE?(h=this._relativeSelectionPositionRow,g=u,S=d,f=this._relativeSelectionPositionColumn):t===M.CURSOR_TYPE.SOUTH_RESIZE&&(h=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,S=d,f=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength);const v=this._swapPositions(h,g,S,f),p=this._skeleton.getCellWithMergeInfoByIndex(h,g),_=Re({range:v,primary:p,style:null},this._skeleton);this._targetSelection={..._.rangeWithCoord},this._control.updateRangeBySelectionWithCoord(_),this._control.selectionScaling$.next(this._targetSelection)}_initialAutoFill(){const{fillControl:o}=this._control;o.onPointerEnter$.subscribeEvent(e=>{this._injector.get(Ce).interceptor.fetchThroughInterceptors(Go)(!1,{x:e.offsetX,y:e.offsetY,skeleton:this._skeleton,scene:this._scene})&&o.setCursor(M.CURSOR_TYPE.CROSSHAIR)}),o.onPointerLeave$.subscribeEvent(()=>{o.resetCursor()}),o.onPointerDown$.subscribeEvent(this._autoFillForPointerdown.bind(this))}_autoFillMoving(o,e){var k,H,V;const t=this._scene,i=t.getViewportScrollXY(this._activeViewport),{scaleX:r,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(o,e,r,s,i),{row:c,column:d}=l,u=t.getCoordRelativeToViewport(M.Vector2.FromArray([o,e])),h=this._skeleton.getRowCount()-1,g=this._skeleton.getColumnCount()-1;let S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn,v=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,p=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength,C=!1,_=!0;if((d<f||d>p)&&c>=S&&c<=v){const W=this._fillRuler(d,f,p,this._relativeSelectionColumnLength,g);f=W.startRowOrColumn,p=W.endRowOrColumn,C=W.isLighten,_=!1}else if((c<S||c>v)&&d>=f&&d<=p){const W=this._fillRuler(c,S,v,this._relativeSelectionRowLength,h);S=W.startRowOrColumn,v=W.endRowOrColumn,C=W.isLighten}else if(Math.abs(this._startOffsetX-u.x-i.x)/2>Math.abs(this._startOffsetY-u.y-i.y)){const W=this._fillRuler(d,f,p,this._relativeSelectionColumnLength,g);f=W.startRowOrColumn,p=W.endRowOrColumn,C=W.isLighten,_=!1}else{const W=this._fillRuler(c,S,v,this._relativeSelectionRowLength,h);S=W.startRowOrColumn,v=W.endRowOrColumn,C=W.isLighten}const w=this._skeleton.getNoMergeCellWithCoordByIndex(S,f),y=this._skeleton.getNoMergeCellWithCoordByIndex(v,p),O=(w==null?void 0:w.startY)||0,R=(y==null?void 0:y.endY)||0,P=(w==null?void 0:w.startX)||0,A=(y==null?void 0:y.endX)||0;C?this._controlHandler((W,L)=>{const U=new a.ColorKit(this._fillControlColors[L]).lighten(gd).toRgbString();W.setProps({fill:U})}):this._controlHandler((W,L)=>{W.setProps({fill:this._fillControlColors[L]})});const N=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();S===v&&_===!0||f===p&&_===!1?(k=this._helperSelection)==null||k.hide():((H=this._helperSelection)==null||H.transformByState({left:P-N/2,top:O-N/2,width:A-P,height:R-O}),(V=this._helperSelection)==null||V.show()),this._targetSelection={startY:O,endY:R,startX:P,endX:A,startRow:S,endRow:v,startColumn:f,endColumn:p},this._control.selectionFilling$.next(this._targetSelection)}_autoFillForPointerdown(o){const{offsetX:e,offsetY:t}=o,i=this._scene,r=i.getCoordRelativeToViewport(M.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 g=this._control.currentStyle;let S=g==null?void 0:g.stroke,f=g==null?void 0:g.strokeWidth;const v=qe(this._themeService);S==null&&(S=v.stroke),f==null&&(f=v.strokeWidth);const p=this._getScale();f/=p;const C=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/p,_=new a.ColorKit(S).darken(2).toRgbString();this.isHelperSelection&&(this._helperSelection=new M.Rect(ks,{stroke:_,strokeWidth:f+C/2}),i.addObject(this._helperSelection)),this._activeViewport=i.getActiveViewportByCoord(M.Vector2.FromArray([e,t]));const w=i.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN),y=M.ScrollTimer.create(i,this._activeViewport.viewportKey===M.SHEET_VIEWPORT_KEY.VIEW_MAIN?M.ScrollTimerType.ALL:M.ScrollTimerType.NONE);y.startScroll(s,l,w),this._scrollTimer=y,i.disableObjectsEvent(),this._controlHandler(O=>{this._fillControlColors.push(O.fill)}),this._scenePointerMoveSub=i.onPointerMove$.subscribeEvent(O=>{var W;const{offsetX:R,offsetY:P}=O,A=i.getActiveViewportByCoord(M.Vector2.FromArray([R,P]));if(!this._injector.get(Ce).interceptor.fetchThroughInterceptors(Go)(!1,{x:o.offsetX,y:o.offsetY,skeleton:this._skeleton,scene:this._scene}))return;const{x:k,y:H}=i.getCoordRelativeToViewport(M.Vector2.FromArray([R,P]));this._autoFillMoving(k,H),i.setCursor(M.CURSOR_TYPE.CROSSHAIR);const V=this._targetSelection;if(w&&A&&((W=this._activeViewport)==null?void 0:W.viewportKey)!==(A==null?void 0:A.viewportKey)){let L;V.startRow!==c?(y.scrollTimerType=M.ScrollTimerType.Y,L={...V,endRow:V.startRow}):V.endRow!==u?(y.scrollTimerType=M.ScrollTimerType.Y,L={...V,startRow:V.endRow}):V.startColumn!==d?(y.scrollTimerType=M.ScrollTimerType.X,L={...V,endColumn:V.startColumn}):(y.scrollTimerType=M.ScrollTimerType.X,L={...V,startColumn:V.endColumn}),this._isSelectionInViewport(L,A)&&(this._viewportMainScrollBarNeedResetPosition(y.scrollTimerType,this._activeViewport.viewportKey,A.viewportKey)&&w.scrollToBarPos({x:y.scrollTimerType===M.ScrollTimerType.X?0:void 0,y:y.scrollTimerType===M.ScrollTimerType.Y?0:void 0}),this._activeViewport=A)}y.scrolling(k,H,()=>{this._autoFillMoving(k,H)})}),this._scenePointerUpSub=i.onPointerUp$.subscribeEvent(()=>{var R,P;(R=this._helperSelection)==null||R.dispose();const O=this._scene;O.resetCursor(),this._clearObserverEvent(),O.enableObjectsEvent(),(P=this._scrollTimer)==null||P.dispose(),this._control.refreshSelectionFilled(this._targetSelection),this._isInMergeState=!1,this._controlHandler((A,N)=>{A.setProps({fill:this._fillControlColors[N]})}),this._fillControlColors=[]})}_viewportMainScrollBarNeedResetPosition(o,e,t){return o===M.ScrollTimerType.X&&(e===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||e===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP)&&(t===M.SHEET_VIEWPORT_KEY.VIEW_MAIN||t===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP)||o===M.ScrollTimerType.Y&&(e===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||e===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP)&&(t===M.SHEET_VIEWPORT_KEY.VIEW_MAIN||t===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)}_hasMergeInRange(o,e,t,i){return this._skeleton.worksheet.getMergedCellRange(o,e,t,i).length>0}_swapPositions(o,e,t,i){const r=Math.min(o,t),s=Math.min(e,i),l=Math.max(o,t),c=Math.max(e,i);return{startRow:r,startColumn:s,endRow:l,endColumn:c}}_controlHandler(o){const{leftControl:e,rightControl:t,topControl:i,bottomControl:r,backgroundControlTop:s,backgroundControlMiddleLeft:l,backgroundControlMiddleRight:c,backgroundControlBottom:d,fillControl:u}=this._control,h=[e,t,i,r,s,l,c,d,u];for(let g=0,S=h.length;g<S;g++){const f=h[g];o(f,g)}}_fillRuler(o,e,t,i,r){let s=!1;if(o<e)if(this._isInMergeState&&o<e){const l=e-o,c=i+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=i+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=(n=>(n.Selection="__SpreadsheetSelectionShape__",n.top="__SpreadsheetSelectionTopControl__",n.bottom="__SpreadsheetSelectionBottomControl__",n.left="__SpreadsheetSelectionShapeLeftControl__",n.right="__SpreadsheetSelectionShapeRightControl__",n.backgroundTop="__SpreadsheetSelectionBackgroundControlTop__",n.backgroundMiddleLeft="__SpreadsheetSelectionBackgroundControlMiddleLeft__",n.backgroundMiddleRight="__SpreadsheetSelectionBackgroundControlMiddleRight__",n.backgroundBottom="__SpreadsheetSelectionBackgroundControlBottom__",n.fill="__SpreadsheetSelectionFillControl__",n.fillTopLeft="__SpreadsheetSelectionFillControlTopLeft__",n.fillBottomRight="__SpreadsheetSelectionFillControlBottomRight__",n.fillTopLeftInner="__SpreadsheetSelectionFillControlTopLeftInner__",n.fillBottomRightInner="__SpreadsheetSelectionFillControlBottomRightInner__",n.lineMain="__SpreadsheetDragLineMainControl__",n.lineContent="__SpreadsheetDragLineContentControl__",n.line="__SpreadsheetDragLineControl__",n.dash="__SpreadsheetDragDashControl__",n.rowHeaderBackground="__SpreadSheetSelectionRowHeaderBackground__",n.rowHeaderBorder="__SpreadSheetSelectionRowHeaderBorder__",n.rowHeaderGroup="__SpreadSheetSelectionRowHeaderGroup__",n.columnHeaderBackground="__SpreadSheetSelectionColumnHeaderBackground__",n.columnHeaderBorder="__SpreadSheetSelectionColumnHeaderBorder__",n.columnHeaderGroup="__SpreadSheetSelectionColumnHeaderGroup__",n.topLeftWidget="__SpreadSheetSelectionTopLeftWidget__",n.topCenterWidget="__SpreadSheetSelectionTopCenterWidget__",n.topRightWidget="__SpreadSheetSelectionTopRightWidget__",n.middleLeftWidget="__SpreadSheetSelectionMiddleLeftWidget__",n.middleRightWidget="__SpreadSheetSelectionMiddleRightWidget__",n.bottomLeftWidget="__SpreadSheetSelectionBottomLeftWidget__",n.bottomCenterWidget="__SpreadSheetSelectionBottomCenterWidget__",n.bottomRightWidget="__SpreadSheetSelectionBottomRightWidget__",n))(qo||{});const Vs=.3;class Jn extends a.Disposable{constructor(e,t,i,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 D.BehaviorSubject(this));T(this,"dispose$",this._dispose$.asObservable());T(this,"selectionMoving$",new D.Subject);T(this,"selectionMoveEnd$",new D.Subject);T(this,"selectionScaling$",new D.Subject);T(this,"selectionScaled$",new D.Subject);T(this,"selectionFilling$",new D.Subject);T(this,"_selectionFilled$",new D.Subject);T(this,"selectionFilled$",this._selectionFilled$.asObservable());T(this,"_antLineOffset",0);T(this,"_antRequestNewFrame",-1);this._scene=e,this._zIndex=t,this._themeService=i,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=qe(this._themeService),this._currentStyle=qe(this._themeService),this._selectionRenderModel=new md;const e=this._zIndex;this._leftBorder=new M.Rect("__SpreadsheetSelectionShapeLeftControl__"+e,{zIndex:e}),this._rightBorder=new M.Rect("__SpreadsheetSelectionShapeRightControl__"+e,{zIndex:e}),this._topBorder=new M.Rect("__SpreadsheetSelectionTopControl__"+e,{zIndex:e}),this._bottomBorder=new M.Rect("__SpreadsheetSelectionBottomControl__"+e,{zIndex:e}),this._backgroundControlTop=new M.Rect("__SpreadsheetSelectionBackgroundControlTop__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlBottom=new M.Rect("__SpreadsheetSelectionBackgroundControlBottom__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleLeft=new M.Rect("__SpreadsheetSelectionBackgroundControlMiddleLeft__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleRight=new M.Rect("__SpreadsheetSelectionBackgroundControlMiddleRight__"+e,{zIndex:e-1,evented:!1}),this._autoFillControl=new M.Rect("__SpreadsheetSelectionFillControl__"+e,{zIndex:e+1}),this._autoFillControl.hide(),this._dashedRect=new M.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 M.Group("__SpreadsheetSelectionShape__"+e,...t,...this._widgetRects),this._selectionShapeGroup.hide(),this._selectionShapeGroup.evented=!1,this._selectionShapeGroup.zIndex=e;const i=this.getScene();i.addObject(this._selectionShapeGroup,Fi),this.disposeWithMe(a.toDisposable(i.onTransformChange$.subscribeEvent(r=>{r.type===M.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&(this._updateLayoutOfSelectionControl(this._currentStyle),this._updateControlCoord())})))}_initialHeader(){const e=this._zIndex;this._rowHeaderBackground=new M.Rect("__SpreadSheetSelectionRowHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderBorder=new M.Rect("__SpreadSheetSelectionRowHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderGroup=new M.Group("__SpreadSheetSelectionRowHeaderGroup__"+e,this._rowHeaderBackground,this._rowHeaderBorder),this._rowHeaderGroup.hide(),this._rowHeaderGroup.evented=!1,this._rowHeaderGroup.zIndex=e,this._columnHeaderBackground=new M.Rect("__SpreadSheetSelectionColumnHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderBorder=new M.Rect("__SpreadSheetSelectionColumnHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderGroup=new M.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],hd)}_initialWidget(){const e=this._zIndex;return this._topLeftWidget=new M.Rect("__SpreadSheetSelectionTopLeftWidget__"+e,{zIndex:e+1}),this._topCenterWidget=new M.Rect("__SpreadSheetSelectionTopCenterWidget__"+e,{zIndex:e+1}),this._topRightWidget=new M.Rect("__SpreadSheetSelectionTopRightWidget__"+e,{zIndex:e+1}),this._middleLeftWidget=new M.Rect("__SpreadSheetSelectionMiddleLeftWidget__"+e,{zIndex:e+1}),this._middleRightWidget=new M.Rect("__SpreadSheetSelectionMiddleRightWidget__"+e,{zIndex:e+1}),this._bottomLeftWidget=new M.Rect("__SpreadSheetSelectionBottomLeftWidget__"+e,{zIndex:e+1}),this._bottomCenterWidget=new M.Rect("__SpreadSheetSelectionBottomCenterWidget__"+e,{zIndex:e+1}),this._bottomRightWidget=new M.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 Hs(this,e)}setControlExtensionDisable(e){this._controlExtension&&this._controlExtension.setDisabled(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:i,widgets:r,autofillStroke:s,strokeDash:l,isAnimationDash:c}=t;let d=t.autofillSize,u=t.strokeWidth,h=t.autofillStrokeWidth;const g=this._getScale(),S=(u+m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH)/2/g;u/=g,d/=g,h/=g<1?1:g;const f=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/g,v=M.FIX_ONE_PIXEL_BLUR_OFFSET/g,{startX:p,startY:C,endX:_,endY:w}=this._selectionRenderModel;if(this.leftControl.transformByState({height:w-C,left:-S+v,width:u,strokeWidth:f,top:-f/2+v}),this.leftControl.setProps({fill:i,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.rightControl.transformByState({height:w-C,left:_-p-S+v,width:u,strokeWidth:f,top:-f/2+v}),this.rightControl.setProps({fill:i,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.topControl.transformByState({width:_-p+u,top:-S+v,left:-S+v,height:u,strokeWidth:f}),this.topControl.setProps({fill:i,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.bottomControl.transformByState({width:_-p+u,top:w-C-S+v,height:u,left:-S+v,strokeWidth:f}),this.bottomControl.setProps({fill:i,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),l==null)this.dashedRect.hide(),this._stopAntLineAnimation();else{const y=t.strokeWidth*2/g;this.dashedRect.transformByState({height:w-C,width:_-p,strokeWidth:y,left:-y/2+v,top:-y/2+v}),this.dashedRect.setProps({strokeDashArray:[0,l/g]}),this._stopAntLineAnimation(),c!==!1&&this._startAntLineAnimation(),this.dashedRect.show()}if(this._showAutoFill=this._showAutoFill&&this._enableAutoFill,this._showAutoFill&&!this._hasWidgets(r)){const y={fill:i,stroke:s,strokeScaleEnabled:!1},O={width:d-h,height:d-h,left:_-p-d/2+h/2-v,top:w-C-d/2+h/2-v,strokeWidth:h};this._autoFillControl.setProps(y),this._autoFillControl.transformByState(O),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.rowHeaderWidth,this._columnHeaderHeight=t.columnHeaderHeight),this._selectionRenderModel.setValue(e.rangeWithCoord,e.primaryWithCoord),this._showAutoFill=e.primaryWithCoord!==null,this._updateLayoutOfSelectionControl(e.style),this._updateControlCoord()}update(e,t=0,i=0,r,s){this._rowHeaderWidth=t,this._columnHeaderHeight=i,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,i,r,s,l,c,d,u,h,g,S,f,v,p,C,_,w,y,O,R,P,A,N,k;(e=this._leftBorder)==null||e.dispose(),(t=this._rightBorder)==null||t.dispose(),(i=this._topBorder)==null||i.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(),(g=this._rowHeaderBorder)==null||g.dispose(),(S=this._rowHeaderGroup)==null||S.dispose(),(f=this._rowHeaderBackground)==null||f.dispose(),(v=this._columnHeaderBackground)==null||v.dispose(),(p=this._columnHeaderBorder)==null||p.dispose(),(C=this._columnHeaderGroup)==null||C.dispose(),(_=this._topLeftWidget)==null||_.dispose(),(w=this._topCenterWidget)==null||w.dispose(),(y=this._topRightWidget)==null||y.dispose(),(O=this._middleLeftWidget)==null||O.dispose(),(R=this._middleRightWidget)==null||R.dispose(),(P=this._bottomLeftWidget)==null||P.dispose(),(A=this._bottomCenterWidget)==null||A.dispose(),(N=this._bottomRightWidget)==null||N.dispose(),(k=this._controlExtension)==null||k.dispose(),super.dispose(),this._dispose$.next(this),this._dispose$.complete()}getCurrentCellInfo(){const e=this.model.currentCell;if(e){let t;if(e.isMerged){const i=e.mergeInfo;t={startRow:i.startRow,endRow:i.endRow,startColumn:i.startColumn,endColumn:i.endColumn,startX:i.startX,endX:i.endX,startY:i.startY,endY:i.endY}}else{const{actualRow:i,actualColumn:r,startX:s,endX:l,startY:c,endY:d}=e;t={startRow:i,endRow:i,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:i,endX:r,endY:s,rangeType:l}=this._selectionRenderModel,c=this._currentStyle,d=this._getScale(),{stroke:u,rowHeaderFill:h=c.rowHeaderFill,rowHeaderStroke:g=c.rowHeaderStroke,columnHeaderFill:S=c.columnHeaderFill,columnHeaderStroke:f=c.columnHeaderStroke}=e;let{rowHeaderStrokeWidth:v=c.rowHeaderStrokeWidth,columnHeaderStrokeWidth:p=c.columnHeaderStrokeWidth}=e;v/=d,p/=d;const C=this._rowHeaderWidth,_=this._columnHeaderHeight;if(this._highlightHeader&&_>0){let w=S;l===a.RANGE_TYPE.COLUMN&&(w=new a.ColorKit(u).setAlpha(Vs).toString()),this._columnHeaderBackground.setProps({fill:w}),this._columnHeaderBackground.resize(r-t,_),this._columnHeaderBorder.setProps({fill:f}),this._columnHeaderBorder.transformByState({width:r-t,height:p,top:_-p+1/d}),this._columnHeaderGroup.show(),this._columnHeaderGroup.translate(t,0)}else this._columnHeaderGroup.hide();if(this._columnHeaderGroup.makeDirty(!0),this._highlightHeader&&C>0){let w=h;l===a.RANGE_TYPE.ROW&&(w=new a.ColorKit(u).setAlpha(Vs).toString()),this._rowHeaderBackground.setProps({fill:w}),this._rowHeaderBackground.resize(C,s-i),this._rowHeaderBorder.setProps({fill:g}),this._rowHeaderBorder.transformByState({width:v,height:s-i,left:C-v+1/d}),this._rowHeaderGroup.show(),this._rowHeaderGroup.translate(0,i)}else this._rowHeaderGroup.hide();this._rowHeaderGroup.makeDirty(!0)}_updateBackgroundControl(e){const{startX:t,startY:i,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-i),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:g,endX:S,endY:f}=u,v=d/2,p={left:-v,top:-v,width:r-t+v*2,height:g-i+v};p.height<0&&(p.width=0,p.height=0),this._backgroundControlTop.transformByState(p);const C={left:-v,top:g-i,width:h-t+v,height:f-g};C.width<0&&(C.width=0,C.height=0),this._backgroundControlMiddleLeft.transformByState(C);const _={left:S-t-v,top:g-i,width:r-S+v*2,height:f-g};_.width<0&&(_.width=0,_.height=0),this._backgroundControlMiddleRight.transformByState(_);const w={left:-v,top:f-i,width:r-t+v*2,height:s-f+v};w.height<0&&(w.width=0,w.height=0),this._backgroundControlBottom.transformByState(w),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:i,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:g}=e;h/=u,g/=u;const S={left:-h/2+g/2,center:(r-t)/2-h/2+g/2,right:r-t-h/2+g/2,top:-h/2,middle:(s-i)/2-h/2,bottom:s-i-h/2+g/2},f=h-g;this._widgetRects.forEach(v=>{v.setProps({fill:l,stroke:d})}),c.tl===!0?(this._topLeftWidget.transformByState({height:f,width:f,left:S.left,top:S.top,strokeWidth:g}),this._topLeftWidget.show()):this._topLeftWidget.hide(),c.tc===!0?(this._topCenterWidget.transformByState({height:f,width:f,left:S.center,top:S.top,strokeWidth:g}),this._topCenterWidget.show()):this._topCenterWidget.hide(),c.tr===!0?(this._topRightWidget.transformByState({height:f,width:f,left:S.right,top:S.top,strokeWidth:g}),this._topRightWidget.show()):this._topRightWidget.hide(),c.ml===!0?(this._middleLeftWidget.transformByState({height:f,width:f,left:S.left,top:S.middle,strokeWidth:g}),this._middleLeftWidget.show()):this._middleLeftWidget.hide(),c.mr===!0?(this._middleRightWidget.transformByState({height:f,width:f,left:S.right,top:S.middle,strokeWidth:g}),this._middleRightWidget.show()):this._middleRightWidget.hide(),c.bl===!0?(this._bottomLeftWidget.transformByState({height:f,width:f,left:S.left,top:S.bottom,strokeWidth:g}),this._bottomLeftWidget.show()):this._bottomLeftWidget.hide(),c.bc===!0?(this._bottomCenterWidget.transformByState({height:f,width:f,left:S.center,top:S.bottom,strokeWidth:g}),this._bottomCenterWidget.show()):this._bottomCenterWidget.hide(),c.br===!0?(this._bottomRightWidget.transformByState({height:f,width:f,left:S.right,top:S.bottom,strokeWidth:g}),this._bottomRightWidget.show()):this._bottomRightWidget.hide()}_hasWidgets(e){if(e==null)return!1;const t=Object.keys(e);if(t.length===0)return!1;for(const i of t)if(e[i]===!0)return!0;return!1}_getScale(){const{scaleX:e,scaleY:t}=this._scene.getAncestorScale();return Math.max(e,t)}_stopAntLineAnimation(){this._antLineOffset=0,M.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=M.requestNewFrame(()=>{this._startAntLineAnimation()})}}class Sd extends M.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 Qo extends a.Disposable{constructor(e,t,i,r,s){super();T(this,"_downObserver");T(this,"_scenePointerMoveSub");T(this,"_scenePointerUpSub");T(this,"_controlFillConfig$",new D.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 D.BehaviorSubject([]));T(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());T(this,"_selectionMoving$",new D.Subject);T(this,"selectionMoving$",this._selectionMoving$.asObservable());T(this,"_selectionMoveStart$",new D.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:Go}));T(this,"_escapeShortcutDisposable",null);this._injector=e,this._themeService=t,this._shortcutService=i,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,i){const r=this.getSelectionControls().length,{rowHeaderWidth:s,columnHeaderHeight:l}=t,c=new Jn(e,r,this._selectionTheme,{highlightHeader:this._highlightHeader,rowHeaderWidth:s,columnHeaderHeight:l});this._selectionControls.push(c);const d=Re(i,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(),i=this._skeleton;if(!(!t||!i)){for(let r=0,s=e.length;r<s;r++){const l=e[r],c=Re(l,this._skeleton),d=t[r];d?d.updateRangeBySelectionWithCoord(c,i):this.isSelectionEnabled()&&this.newSelectionControl(this._scene,i,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,i){this._skeleton=e,this._scene=t,this._activeViewport=i||(t==null?void 0:t.getViewports()[0]),t.findLayerByZIndex(Fi)||t.addLayer(new Sd(t,[],Fi))}getSkeleton(){return this._skeleton}getSelectionDataWithStyle(){const e=this._selectionControls;if(this._skeleton.worksheet){const[t,i]=this._skeleton.getLocation();return e.map(r=>{const s=r.getValue();return s.rangeWithCoord.sheetId=i,s.rangeWithCoord.unitId=t,s})}return[]}getSelectionControls(){return this._selectionControls}_addSelectionControlByModelData(e){var l;const t=this._skeleton,i=(l=e.style)!=null?l:qe(this._selectionTheme),r=this._scene;return e.style=i,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 i=this._getFreeze();if(!i||i.startRow<=0&&i.startColumn<=0)return this._scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e>i.startRow&&t>i.startColumn)return this._scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e<=i.startRow&&t<=i.startColumn)return this._scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP);if(e<=i.startRow&&t>i.startColumn)return this._scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(e>i.startRow&&t<=i.startColumn)return this._scene.getViewport(M.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,i,r=M.ScrollTimerType.ALL,s,l){var f,v;let c=0,d=0,u=s,h=l;this._scrollTimer=M.ScrollTimer.create(this._scene,r),this._scrollTimer.startScroll((f=e==null?void 0:e.left)!=null?f:0,(v=e==null?void 0:e.top)!=null?v:0,e);const g=this._scene,S=g.getActiveViewportByCoord(M.Vector2.FromArray([s,l]));this._scenePointerMoveSub=g.onPointerMove$.subscribeEvent(p=>{var V,W,L,U,B,F,z,X,j;const{offsetX:C,offsetY:_}=p,{x:w,y}=g.getCoordRelativeToViewport(M.Vector2.FromArray([C,_]));this._movingHandler(w,y,t,i);let O=w,R=y;const P=this.getActiveSelectionControl(),A=this._getFreeze(),N=P==null?void 0:P.model,k=(V=g.getActiveViewportByCoord(M.Vector2.FromArray([C,_])))!=null?V:this._getViewportByCell(N==null?void 0:N.endRow,N==null?void 0:N.endColumn);if((()=>{if(!S||!k||!e)return!1;const Q=[M.SHEET_VIEWPORT_KEY.VIEW_MAIN,M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT];return Q.includes(S.viewportKey)&&Q.includes(k.viewportKey)})()){if(!S||!k||!e)return!1;const Q=u<e.left&&w>e.left||u>e.left&&w<e.left,oe=h<e.top&&y>e.top||h>e.top&&y<e.top;Q&&(c+=1),oe&&(d+=1);const re=S.viewportKey,le=k.viewportKey;if(re===M.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP)_<e.top&&((W=N==null?void 0:N.endRow)!=null?W:0)<((L=A==null?void 0:A.startRow)!=null?L:0)?R=e.top:oe&&d%2===1&&e.scrollToViewportPos({viewportScrollY:0});else if(re===M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT)C<e.left&&((U=N==null?void 0:N.endColumn)!=null?U:0)<((B=A==null?void 0:A.startColumn)!=null?B:0)?O=e.left:Q&&c%2===1&&e.scrollToViewportPos({viewportScrollX:0});else if(re===le){let G=!1,Z=!1;re===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP?(G=!0,Z=!0):re===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP?Z=!0:re===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT&&(G=!0),((F=N==null?void 0:N.endRow)!=null?F:0)>((z=A==null?void 0:A.startRow)!=null?z:0)&&(Z=!1),((X=N==null?void 0:N.endColumn)!=null?X:0)>((j=A==null?void 0:A.startColumn)!=null?j:0)&&(G=!1),G&&(O=e.left),Z&&(R=e.top)}else{const G={x:S.scrollX,y:S.scrollY},Z={x:k.scrollX,y:k.scrollY},J=G.x!==Z.x&&Q&&c%2===1,ie=G.y!==Z.y&&oe&&d%2===1;(J||ie)&&(e.scrollToBarPos({x:J?G.x:void 0,y:ie?G.y:void 0}),J||(O=e.left),ie||(R=e.top)),(re===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&le===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||le===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&re===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)&&(O=e.left),(re===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&le===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||le===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&re===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP)&&(R=e.top)}u=w,h=y}this._scrollTimer.scrolling(O,R,()=>{this._movingHandler(w,y,t,i)})})}attachSelectionWithCoord(e){return Re(e,this._skeleton)}attachPrimaryWithCoord(e){return Qn(this._skeleton,e)}getSelectionCellByPosition(e,t){return this.getCellWithCoordByOffset(e,t)}getCellWithCoordByOffset(e,t,i){const r=this._scene,s=i!=null?i:this._skeleton,l=r.getViewportScrollXY(r.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:c,scaleY:d}=r.getAncestorScale();return s.getCellWithCoordByOffset(e-l.x,t-l.y,c,d,l)}_movingHandler(e,t,i,r){var O,R,P,A,N;const s=this._skeleton,l=this._scene,[c,d]=s.getLocation(),u={startRow:(O=i==null?void 0:i.model.startRow)!=null?O:-1,endRow:(R=i==null?void 0:i.model.endRow)!=null?R:-1,startColumn:(P=i==null?void 0:i.model.startColumn)!=null?P:-1,endColumn:(A=i==null?void 0:i.model.endColumn)!=null?A:-1},h=l.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=(N=this._getViewportByCell(u.endRow,u.endColumn))!=null?N:h,S=l.getScrollXYInfoByViewport(M.Vector2.FromArray([this._startViewportPosX,this._startViewportPosY]),g),{scaleX:f,scaleY:v}=l.getAncestorScale();r===a.RANGE_TYPE.ROW?e=Number.POSITIVE_INFINITY:r===a.RANGE_TYPE.COLUMN&&(t=Number.POSITIVE_INFINITY);const p=this._skeleton.getCellByOffset(e,t,f,v,S);if(!p)return;let C={startRow:Math.min(p.startRow,this._startRangeWhenPointerDown.startRow),startColumn:Math.min(p.startColumn,this._startRangeWhenPointerDown.startColumn),endRow:Math.max(p.endRow,this._startRangeWhenPointerDown.endRow),endColumn:Math.max(p.endColumn,this._startRangeWhenPointerDown.endColumn)};this._shouldDetectMergedCells&&(C=s.expandRangeByMerge(C,this.inRefSelectionMode()));const w=Re({range:C,primary:void 0,style:null},s);w.rangeWithCoord.unitId=c,w.rangeWithCoord.sheetId=d,w.rangeWithCoord.rangeType=r;const y=u.startRow!==C.startRow||u.startColumn!==C.startColumn||u.endRow!==C.endRow||u.endColumn!==C.endColumn;i!=null&&y&&(i.updateRangeBySelectionWithCoord(w),this._selectionMoving$.next(this.getSelectionDataWithStyle()))}_clearUpdatingListeners(){var t,i,r,s,l;this._scene.enableObjectsEvent(),(t=this._scenePointerMoveSub)==null||t.unsubscribe(),this._scenePointerMoveSub=null,(i=this._scenePointerUpSub)==null||i.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 i,r,s;const e=this._scene,t=(i=e.getEngine())==null?void 0:i.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,i,r,s){const l=this._skeleton;if(l==null)return null;if(this._shouldDetectMergedCells){const C=l==null?void 0:l.getCellWithCoordByOffset(e,t,i,r,s,{firstMatch:!0});if(!C)return;const _=a.convertCellToRange(C);return{primaryWithCoord:C,rangeWithCoord:_}}const{row:c,column:d}=l.getCellIndexByOffset(e,t,i,r,s),u=l.getNoMergeCellWithCoordByIndex(c,d),{startX:h,startY:g,endX:S,endY:f}=u,v={startY:g,endY:f,startX:h,endX:S,startRow:c,endRow:c,startColumn:d,endColumn:d};return{primaryWithCoord:{mergeInfo:v,actualRow:c,actualColumn:d,isMerged:!1,isMergedMainCell:!1,startY:g,endY:f,startX:h,endX:S},rangeWithCoord:v}}_checkClearPreviousControls(e){this.getSelectionControls().length!==0&&(!e.ctrlKey&&!e.shiftKey&&!this._remainLastEnabled||this._singleSelectionEnabled&&!e.shiftKey)&&this._clearAllSelectionControls()}_makeSelectionByTwoCells(e,t,i,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),g=Math.min(c,t.startColumn,d.startColumn),S=Math.max(c,t.endColumn,d.endColumn),v={range:i.expandRangeByMerge({startRow:u,startColumn:g,endRow:h,endColumn:S}),primary:m.convertPrimaryWithCoordToPrimary(e),style:null},p=Re(v,i);s.updateRangeBySelectionWithCoord(p)}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 Jo(n){return{range:{startRow:0,startColumn:0,endRow:n.getRowCount()-1,endColumn:n.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL},primary:zi(n).primary,style:null}}function zi(n){return Ws(n,{startRow:0,startColumn:0,endRow:0,endColumn:0})}function Ws(n,o){const e=n.worksheet.getCellInfoInMergeData(o.startRow,o.startColumn),t=n.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 fd=Object.getOwnPropertyDescriptor,vd=(n,o,e,t)=>{for(var i=t>1?void 0:t?fd(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},Ls=(n,o)=>(e,t)=>o(e,t,n);E.SheetSkeletonManagerService=class extends a.Disposable{constructor(e,t,i){super();T(this,"_sheetId","");T(this,"_sheetSkeletonParamStore",new Map);T(this,"_currentSkeleton$",new D.BehaviorSubject(null));T(this,"currentSkeleton$",this._currentSkeleton$.asObservable());T(this,"_currentSkeletonBefore$",new D.BehaviorSubject(null));T(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._context=e,this._injector=t,this._sheetSkService=i,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 i=this._getSkeletonParam(t);return i!=null&&(i.unitId=e),i}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),i=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:i,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 i=this._getSkeletonParam(e.sheetId);i!=null&&(i.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?Jt(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(M.SpreadsheetSkeleton,e,this._context.unit.getStyles())}setColumnHeaderSize(e,t,i){var u;if(!e)return;const r=(u=this.getWorksheetSkeleton(t))==null?void 0:u.skeleton;if(!r)return;r.columnHeaderHeight=i,e.scene.getViewports()[0].top=i,e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({height:i}),e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({height:i}),e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({top:i}),e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({top:i}),e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({height:i});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=qn.id,this._currentSkeleton$.next(d))}setRowHeaderSize(e,t,i){var f;const r=(f=this.getWorksheetSkeleton(t))==null?void 0:f.skeleton;if(!e||!r)return;r.rowHeaderWidth=i;const s=e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).width||46,l=i-s,c=e.scene.getViewports()[0].left;e.scene.getViewports()[0].left=c+l,e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({width:i}),e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({width:i}),e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({left:i});const d=e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).left||0;e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({left:d+l}),e.scene.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({width:i});const u=e==null?void 0:e.with(m.SheetsSelectionsService),h=e==null?void 0:e.with(Ce),g=u.getCurrentSelections();h.resetSelectionsByModelData(g);const S=this.getCurrent();S&&(S.commandId=Kn.id,this._currentSkeleton$.next(S))}},E.SheetSkeletonManagerService=vd([Ls(1,a.Inject(a.Injector)),Ls(2,a.Inject(m.SheetSkeletonService))],E.SheetSkeletonManagerService);var pd=Object.getOwnPropertyDescriptor,Cd=(n,o,e,t)=>{for(var i=t>1?void 0:t?pd(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},$n=(n,o)=>(e,t)=>o(e,t,n);const xs=["ff","fs","tr","tb"];E.AutoHeightController=class extends a.Disposable{constructor(o,e,t,i,r){super(),this._renderManagerService=o,this._sheetInterceptorService=e,this._selectionManagerService=t,this._univerInstanceService=i,this._configService=r,this._initialize()}_processLazyAutoHeight(o,e,t,i){if(i!=null&&i.length){const r={id:m.MarkDirtyRowAutoHeightMutation.id,params:{unitId:e,subUnitId:t,ranges:i,id:a.generateRandomId()},options:{onlyLocal:!0}},s={id:m.CancelMarkDirtyRowAutoHeightMutation.id,params:{unitId:e,subUnitId:t,id:r.params.id},options:{onlyLocal:!0}};return{redos:[...o.redos,r],undos:[...o.undos,s]}}return o}getUndoRedoParamsOfAutoHeight(o,e,t){const{_univerInstanceService:i}=this,r=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=r.getUnitId();let l=r.getActiveSheet(),c=l.getSheetId();if(e){const v=m.getSheetCommandTarget(i,{unitId:s,subUnitId:e});v&&(l=v.worksheet,c=l.getSheetId())}const u=this._renderManagerService.getRenderById(s).with(E.SheetSkeletonManagerService).ensureSkeleton(c);if(!u)return{redos:[],undos:[]};const g=u.calculateAutoHeightInRange(o,t).filter(v=>{const{row:p,autoHeight:C}=v;return!(!C||l.getRowHeight(p)===C)});if(g.length===0)return{redos:[],undos:[]};const S={subUnitId:c,unitId:s,rowsAutoHeightInfo:g},f=m.SetWorksheetRowAutoHeightMutationFactory(S,l);return{undos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:f}],redos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:S}]}}_initialize(){this.disposeWithMe(this._sheetInterceptorService.interceptAutoHeight({getMutations:o=>{const{unitId:e,subUnitId:t,ranges:i,autoHeightRanges:r,lazyAutoHeightRanges:s,cellHeights:l}=o,c=this.getUndoRedoParamsOfAutoHeight(r!=null?r:i,t,l);return this._processLazyAutoHeight(c,e,t,s)}}))}},E.AutoHeightController=Cd([$n(0,M.IRenderManagerService),$n(1,a.Inject(m.SheetInterceptorService)),$n(2,a.Inject(m.SheetsSelectionsService)),$n(3,a.Inject(a.IUniverInstanceService)),$n(4,a.IConfigService)],E.AutoHeightController);function at(n){const{rows:o,cols:e}=n;return{startRow:o[0],endRow:o[o.length-1],startColumn:e[0],endColumn:e[e.length-1]}}function lt(n){let o=[],e=[];const t=[];return n.forEach(i=>{o=o.concat(i.rows),e=e.concat(i.cols)}),o=Array.from(new Set(o)).sort((i,r)=>i-r),e=Array.from(new Set(e)).sort((i,r)=>i-r),n.forEach(i=>{t.push({startRow:o.findIndex(r=>r===i.rows[0]),endRow:o.findIndex(r=>r===i.rows[i.rows.length-1]),startColumn:e.findIndex(r=>r===i.cols[0]),endColumn:e.findIndex(r=>r===i.cols[i.cols.length-1])})}),{ranges:t,mapFunc:(i,r)=>({row:o[i],col:e[r]})}}function Id(n){const o=new a.ObjectMatrix;return n.forEach(e=>{const{rows:t,cols:i}=e;t.forEach(r=>{i.forEach(s=>{o.setValue(r,s,{v:null,p:null,f:null,si:null,custom:null})})})}),o.getData()}const $o={零:0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9},Xi=["零","一","二","三","四","五","六","七","八","九"],Us=["","万","亿","万亿","亿亿"],_d=["","十","百","千"],Bs={十:{value:10,secUnit:!1},百:{value:100,secUnit:!1},千:{value:1e3,secUnit:!1},万:{value:1e4,secUnit:!0},亿:{value:1e8,secUnit:!0}};function Qe(n){if(!n)return 0;let o=0,e=0,t=0,i=!1;const r=n.split("");for(let s=0;s<r.length;s++){const l=$o[r[s]];if(typeof l<"u")t=l,s===r.length-1&&(e+=t);else{const c=Bs[r[s]],d=c.value;i=c.secUnit,i?(e=(e+t)*d,o+=e,e=0):e+=t*d,t=0}}return o+e}function bd(n){let o="",e="",t=0,i=!0;for(;n>0;){const r=n%10;r===0?i||(i=!0,e=Xi[r]+e):(i=!1,o=Xi[r],o+=_d[t],e=o+e),t++,n=Math.floor(n/10)}return e}function wd(n){let o=0,e="",t="",i=!1;if(n===0)return Xi[0];for(;n>0;){const r=n%1e4;i&&(t=Xi[0]+t),e=bd(r),e+=r!==0?Us[o]:Us[0],t=e+t,i=r<1e3&&r>0,n=Math.floor(n/1e4),o++}return t}function Ed(n){if(!n)return!1;let o=!0;if(n)if(n.length===1)n==="日"||n in $o?o=!0:o=!1;else{const e=n.split("");for(let t=0;t<e.length;t++)if(!(e[t]in $o||e[t]in Bs)){o=!1;break}}return o}function Yi(n){if(!n)return{isExtendNumber:!1};const o=/0|([1-9]+[0-9]*)/g,e=o.test(n);if(e){const t=n.match(o);if(t&&t.length>0){const i=t[t.length-1],r=n.lastIndexOf(i),s=n.substr(0,r),l=n.substr(r+i.length);return{isExtendNumber:!0,matchTxt:Number(i),beforeTxt:s,afterTxt:l}}return{isExtendNumber:!1}}return{isExtendNumber:e}}function yd(n){let o;return n.length===2&&(n==="周一"||n==="周二"||n==="周三"||n==="周四"||n==="周五"||n==="周六"||n==="周日")?o=!0:o=!1,o}function Td(n){let o;return n.length===3&&(n==="星期一"||n==="星期二"||n==="星期三"||n==="星期四"||n==="星期五"||n==="星期六"||n==="星期日")?o=!0:o=!1,o}function Rd(n,o){let e=0;for(let t=0;t<n.length&&n[t]<o;t++)e++;return e}function ei(n){let o=!0;const e=n[1]-n[0];for(let t=1;t<n.length;t++)if(n[t]-n[t-1]!==e){o=!1;break}return o}function Md(n,o,e){const t=[],i=Math.floor(o/n),r=o%n;let s=0;if(i>0){for(let l=0;l<i;l++)for(let c=0;c<e.length;c++)t[e[c]+l*n]=s,s++;for(let l=0;l<e.length&&e[l]<r;l++)t[e[l]+n*i]=s,s++}else for(let l=0;l<e.length&&e[l]<r;l++)t[e[l]]=s,s++;return t}function wt(n,o){const e=[];for(let t=1;t<=o;t++){const i=(t-1)%n.length,r=a.Tools.deepClone(n[i]);Et(r),e.push({v:null,s:null,p:null,f:null,si:null,t:null,...r})}return e}function Pd(n,o){var t;const e=[];for(let i=1;i<=o;i++){const r=(i-1)%n.length,s={s:(t=n[r])==null?void 0:t.s};e.push(s)}return e}function Od(n){let o=!0;const e=n[1]/n[0];for(let t=1;t<n.length;t++)if(n[t]/n[t-1]!==e){o=!1;break}return o}function Ad(n){const o=[];for(let e=1;e<=n;e++)o.push(e);return o}function ji(n,o,e){var r,s,l,c;const t=[],i=[];for(let d=0;d<n.length;d++)i.push(Number((r=n[d])==null?void 0:r.v));if(n.length>2&&Od(i))for(let d=1;d<=o;d++){const u=(d-1)%n.length,h=a.Tools.deepClone(n[u]);Et(h);const g=Number((s=n[n.length-1])==null?void 0:s.v)*(Number((l=n[1])==null?void 0:l.v)/Number((c=n[0])==null?void 0:c.v))**d;h&&(Ys(h)&&(h.v=g),t.push(h))}else{const d=Ad(n.length);for(let u=1;u<=o;u++){const h=(u-1)%n.length,g=a.Tools.deepClone(n[h]);Et(g);const S=e===a.Direction.DOWN||e===a.Direction.RIGHT,f=Dd(n.length+u,i,d,S);g&&(Ys(g)&&(g.v=f),t.push(g))}}return t}function Dd(n,o,e,t=!0){function i(h){let g=0;for(let S=0;S<h.length;S++)g+=h[S];return g/h.length}const r=i(e),s=i(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*n)*1e5)/1e5}function Fs(n,o,e){var r;const t=[],i=/0|([1-9]+[0-9]*)/g;for(let s=1;s<=o;s++){const l=(s-1)%n.length,c=a.Tools.deepClone(n[l]);Et(c);const d=`${(r=n[n.length-1])==null?void 0:r.v}`;if(!d)continue;const u=d==null?void 0:d.match(i),h=u==null?void 0:u[u.length-1];if(!h)continue;const g=Math.abs(Number(h)+e*s),S=d.lastIndexOf(h),f=d.substr(0,S)+g.toString()+d.substr(S+h.length);c&&(c.v=f,t.push(c))}return t}function $t(n,o,e,t=0){var l,c;const i=[["日","一","二","三","四","五","六"],["周日","周一","周二","周三","周四","周五","周六"],["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]];if(t>=i.length)return[];const r=i[t],s=[];for(let d=1;d<=o;d++){const u=(d-1)%n.length,h=a.Tools.deepClone(n[u]);Et(h);let g=0;if(((l=n[n.length-1])==null?void 0:l.v)===r[0])g=7+e*d;else{const f=`${(c=n[n.length-1])==null?void 0:c.v}`;if(f){const v=f.substr(f.length-1,1);g=Qe(v)+e*d}}g<0&&(g=Math.ceil(Math.abs(g)/7)*7+g);const S=g%7;h&&(h.v=r[S],s.push(h))}return s}function zs(n,o,e){var i;const t=[];for(let r=1;r<=o;r++){const s=(r-1)%n.length,l=a.Tools.deepClone(n[s]);Et(l);const c=`${(i=n[n.length-1])==null?void 0:i.v}`,d=Qe(c)+e*r;let u;d<=0?u="零":u=wd(d),l&&(l.v=u,t.push(l))}return t}const ti={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 Nd(n){let o=!1;return Object.keys(ti).forEach(e=>{ti[e].includes(n)&&(o=!0)}),o}function er(n){let o="";const e=[];return Object.keys(ti).forEach(t=>{ti[t].includes(n)&&(o=t,e.push(...ti[t]))}),{name:o,series:e}}function Xs(n,o,e,t){var s;const i=t.length,r=[];for(let l=1;l<=o;l++){const c=(l-1)%n.length,d=a.Tools.deepClone(n[c]);Et(d);const u=`${(s=n[n.length-1])==null?void 0:s.v}`;let h=t.indexOf(u)+e*l;h<0&&(h+=Math.abs(e)*i);const g=h%i;d&&(d.v=t[g],r.push(d))}return r}function kd(n,o){const e=[];let t;if(o.startRow<n.startRow)t=a.Direction.UP;else if(o.endRow>n.endRow)t=a.Direction.DOWN;else if(o.startColumn<n.startColumn)t=a.Direction.LEFT;else if(o.endColumn>n.endColumn)t=a.Direction.RIGHT;else return[];if(t===a.Direction.DOWN||t===a.Direction.UP){const i=n.endRow-n.startRow+1,r=o.endRow-o.startRow+1,s=Math.floor(r/i),l=r%i,c={startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:n.endColumn-n.startColumn};if(t===a.Direction.DOWN){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow+(d+1)*i,col:n.startColumn},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow+(s+1)*i,col:n.startColumn},relativeRange:{startRow:0,startColumn:0,endRow:l-1,endColumn:n.endColumn-n.startColumn}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow-(d+1)*i,col:n.startColumn},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow-(s+1)*i,col:n.startColumn},relativeRange:{startRow:i-l,endRow:i-1,startColumn:0,endColumn:n.endColumn-n.startColumn}})}}if(t===a.Direction.RIGHT||t===a.Direction.LEFT){const i=n.endColumn-n.startColumn+1,r=o.endColumn-o.startColumn+1,s=Math.floor(r/i),l=r%i,c={startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:n.endColumn-n.startColumn};if(t===a.Direction.RIGHT){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow,col:n.startColumn+(d+1)*i},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow,col:n.startColumn+(s+1)*i},relativeRange:{startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:l-1}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow,col:n.startColumn-(d+1)*i},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow,col:n.startColumn-(s+1)*i},relativeRange:{startRow:0,startColumn:i-l,endRow:n.endRow-n.startRow,endColumn:i-1}})}}return e}function Ys(n){return!(a.isFormulaString(n.f)||a.isFormulaId(n.si)||n.t===a.CellValueType.BOOLEAN)}function Et(n){n&&"custom"in n&&delete n.custom}var en=(n=>(n.Append="APPEND",n.Default="DEFAULT",n.Only="ONLY",n))(en||{}),Ie=(n=>(n.NUMBER="number",n.DATE="date",n.EXTEND_NUMBER="extendNumber",n.CHN_NUMBER="chnNumber",n.CHN_WEEK2="chnWeek2",n.CHN_WEEK3="chnWeek3",n.LOOP_SERIES="loopSeries",n.FORMULA="formula",n.OTHER="other",n))(Ie||{}),ae=(n=>(n.COPY="COPY",n.SERIES="SERIES",n.ONLY_FORMAT="ONLY_FORMAT",n.NO_FORMAT="NO_FORMAT",n))(ae||{});const Hd={type:Ie.DATE,priority:1100,match:(n,o)=>{var e;if(n!=null&&n.f||n!=null&&n.si)return!1;if((typeof(n==null?void 0:n.v)=="number"||(n==null?void 0:n.t)===a.CellValueType.NUMBER)&&n.s){if(typeof n.s=="string"){const i=o.get(a.IUniverInstanceService).getFocusedUnit().getStyles().get(n.s),r=(e=i==null?void 0:i.n)==null?void 0:e.pattern;if(r)return a.numfmt.getFormatInfo(r).isDate}else if(n.s.n&&a.numfmt.getFormatInfo(n.s.n.pattern).isDate)return!0}return!1},isContinue:(n,o)=>n.type===Ie.DATE,applyFunctions:{[ae.SERIES]:(n,o,e)=>{const{data:t}=n;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),ji(t,o,e).reverse()):ji(t,o,e)}}},Vd={type:Ie.NUMBER,priority:1e3,match:n=>typeof(n==null?void 0:n.v)=="number"||(n==null?void 0:n.t)===a.CellValueType.NUMBER,isContinue:(n,o)=>n.type===Ie.NUMBER,applyFunctions:{[ae.SERIES]:(n,o,e)=>{const{data:t}=n;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),ji(t,o,e).reverse()):ji(t,o,e)}}},js={type:Ie.OTHER,priority:0,match:()=>!0,isContinue:(n,o)=>n.type===Ie.OTHER},Wd={type:Ie.EXTEND_NUMBER,priority:900,match:n=>Yi(`${n==null?void 0:n.v}`||"").isExtendNumber,isContinue:(n,o)=>{var e;if(n.type===Ie.EXTEND_NUMBER){const{beforeTxt:t,afterTxt:i}=Yi(`${(e=n.cellData)==null?void 0:e.v}`||""),{beforeTxt:r,afterTxt:s}=Yi(`${o==null?void 0:o.v}`||"");if(t===r&&i===s)return!0}return!1},applyFunctions:{[ae.SERIES]:(n,o,e)=>{var l;const{data:t}=n,i=e===a.Direction.UP||e===a.Direction.LEFT;let r;if(t.length===1)return r=i?-1:1,ke(Fs(t,o,r),i);const s=[];for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`;d&&s.push(Number(Yi(d).matchTxt))}return i&&(t.reverse(),s.reverse()),ei(s)?(r=s[1]-s[0],ke(Fs(t,o,r),i)):wt(t,o)}}},Ld={type:Ie.CHN_NUMBER,priority:830,match:n=>!!Ed(`${n==null?void 0:n.v}`||""),isContinue:(n,o)=>n.type===Ie.CHN_NUMBER,applyFunctions:{[ae.SERIES]:(n,o,e)=>{var c,d,u;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){const h=`${(c=t[0])==null?void 0:c.v}`;let g;return i?g=-1:g=1,h&&(h==="日"||Qe(h)<7)?ke($t(t,o,g),i):ke(zs(t,o,g),i)}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 g=`${(u=t[h])==null?void 0:u.v}`;g==="日"?h===0?s.push(0):(l++,s.push(l*7)):r&&Qe(g)>0&&Qe(g)<7?s.push(Qe(g)+l*7):s.push(Qe(g))}if(i&&(t.reverse(),s.reverse()),ei(s)){if(r||s[s.length-1]<6&&s[0]>0||s[0]<6&&s[s.length-1]>0){const g=s[1]-s[0];return ke($t(t,o,g),i)}const h=s[1]-s[0];return ke(zs(t,o,h),i)}return wt(t,o)}}},xd={type:Ie.CHN_WEEK2,priority:820,match:n=>!!yd(`${n==null?void 0:n.v}`||""),isContinue:(n,o)=>n.type===Ie.CHN_WEEK2,applyFunctions:{[ae.SERIES]:(n,o,e)=>{var l;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let c;return i?c=-1:c=1,ke($t(t,o,c,1),i)}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(Qe(u)+s*7)}if(i&&(t.reverse(),r.reverse()),ei(r)){const c=r[1]-r[0];return ke($t(t,o,c,1),i)}return wt(t,o)}}},Ud={type:Ie.CHN_WEEK3,priority:810,match:n=>Td(`${n==null?void 0:n.v}`||""),isContinue:(n,o)=>n.type===Ie.CHN_WEEK3,applyFunctions:{[ae.SERIES]:(n,o,e)=>{var l;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let c;return i?c=-1:c=1,ke($t(t,o,c,2),i)}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(Qe(u)+s*7)}}if(i&&(t.reverse(),r.reverse()),ei(r)){const c=r[1]-r[0];return ke($t(t,o,c,2),i)}return wt(t,o)}}},Bd={type:Ie.LOOP_SERIES,priority:800,match:n=>Nd(`${n==null?void 0:n.v}`||""),isContinue:(n,o)=>{var e;return n.type===Ie.LOOP_SERIES?er(`${(e=n.cellData)==null?void 0:e.v}`||"").name===er(`${o==null?void 0:o.v}`||"").name:!1},applyFunctions:{[ae.SERIES]:(n,o,e)=>{var c,d;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP,{series:r}=er(`${(c=t[0])==null?void 0:c.v}`||"");if(t.length===1){let u;return i?u=-1:u=1,ke(Xs(t,o,u,r),i)}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(i&&(t.reverse(),s.reverse()),ei(s)){const u=s[1]-s[0];return ke(Xs(t,o,u,r),i)}return wt(t,o)}}};function ke(n,o){return o?n.reverse():n}var Fd=Object.getOwnPropertyDescriptor,zd=(n,o,e,t)=>{for(var i=t>1?void 0:t?Fd(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},tn=(n,o)=>(e,t)=>o(e,t,n);E.AutoFillService=class extends a.Disposable{constructor(e,t,i,r,s,l){super();T(this,"_rules",[]);T(this,"_hooks",[]);T(this,"_applyType$",new D.BehaviorSubject(ae.SERIES));T(this,"_isFillingStyle",!0);T(this,"_prevUndos",[]);T(this,"_autoFillLocation$",new D.BehaviorSubject(null));T(this,"autoFillLocation$",this._autoFillLocation$.asObservable());T(this,"_showMenu$",new D.BehaviorSubject(!1));T(this,"showMenu$",this._showMenu$.asObservable());T(this,"_direction",a.Direction.DOWN);T(this,"applyType$",this._applyType$.asObservable());T(this,"_menu$",new D.BehaviorSubject([{label:"autoFill.copy",value:ae.COPY,disable:!1},{label:"autoFill.series",value:ae.SERIES,disable:!1},{label:"autoFill.formatOnly",value:ae.ONLY_FORMAT,disable:!1},{label:"autoFill.noFormat",value:ae.NO_FORMAT,disable:!1}]));T(this,"menu$",this._menu$.asObservable());this._commandService=e,this._undoRedoService=t,this._renderManagerService=i,this._univerInstanceService=r,this._selectionManagerService=s,this._injector=l,this._init()}_init(){this._rules=[Hd,Vd,Wd,Ld,xd,Ud,Bd,js].sort((e,t)=>t.priority-e.priority),this._isFillingStyle=!0}_getOneByPriority(e){return e.length<=0?[]:[e.reduce((i,r)=>(r.priority||0)>(i.priority||0)?r:i,e[0])]}_initPrevUndo(){this._prevUndos=[]}async triggerAutoFill(e,t,i,r,s){var f;if(i.startColumn===r.startColumn&&i.startRow===r.startRow&&i.endColumn===r.endColumn&&i.endRow===r.endRow)return!1;if(r.endColumn<i.endColumn&&r.endColumn>i.startColumn)return this._commandService.executeCommand(nn.id,{clearRange:{startRow:r.startRow,endRow:r.endRow,startColumn:r.endColumn+1,endColumn:i.endColumn},selectionRange:r});if(r.endRow<i.endRow&&r.endRow>i.startRow)return this._commandService.executeCommand(nn.id,{clearRange:{startRow:r.endRow+1,endRow:i.endRow,startColumn:r.startColumn,endColumn:r.endColumn},selectionRange:r});const l={startRow:r.startRow,endRow:r.endRow,startColumn:r.startColumn,endColumn:r.endColumn};let c=null;if(r.startRow<i.startRow)c=a.Direction.UP,l.endRow=i.startRow-1;else if(r.endRow>i.endRow)c=a.Direction.DOWN,l.startRow=i.endRow+1;else if(r.startColumn<i.startColumn)c=a.Direction.LEFT,l.endColumn=i.startColumn-1;else if(r.endColumn>i.endColumn)c=a.Direction.RIGHT,l.startColumn=i.endColumn+1;else return!1;this.direction=c;const d=this._injector.invoke(v=>m.rangeToDiscreteRange(i,v)),u=this._injector.invoke(v=>m.rangeToDiscreteRange(l,v));if(!d||!u)return!1;this.autoFillLocation={source:d,target:u,unitId:e,subUnitId:t};const h=[];if(this.getActiveHooks().forEach(v=>{var C;const p=(C=v==null?void 0:v.onBeforeFillData)==null?void 0:C.call(v,{source:d,target:u,unitId:e,subUnitId:t},c);p&&h.unshift(p)}),this._initPrevUndo(),s)return this.fillData(s);for(let v=0;v<h.length;v++){const p=this.menu.find(C=>C.value===h[v]);if(p&&!p.disable)return this.fillData(h[v])}const S=(f=this.menu.find(v=>v.disable===!1))==null?void 0:f.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=en.Append),this._hooks.push(e),a.toDisposable(()=>{const t=this._hooks.findIndex(i=>i===e);t>-1&&this._hooks.splice(t,1)})}registerRule(e){if(this._rules.find(i=>i.type===e.type))throw new Error(`Registry rule failed, type '${e.type}' already exist!`);const t=this._rules.findIndex(i=>i.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:i,subUnitId:r}=this.autoFillLocation||{};if(!e||!t||!i||!r)return[];const s=this._hooks.filter(u=>{var h;return!((h=u.disable)!=null&&h.call(u,{source:e,target:t,unitId:i,subUnitId:r},this._direction,this.applyType))}),l=s.filter(u=>u.type===en.Only);if(l.length>0)return this._getOneByPriority(l);const c=this._getOneByPriority(s.filter(u=>u.type===en.Default)),d=s.filter(u=>u.type===en.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(i=>i.value===e?{...i,disable:t}:i))}setShowMenu(e){this._showMenu$.next(e)}fillData(e){var y,O,R;this.applyType=e;const t=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),i=t==null?void 0:t.getUnitId(),r=(y=t==null?void 0:t.getActiveSheet())==null?void 0:y.getSheetId(),{source:s,target:l,unitId:c=i,subUnitId:d=r}=this.autoFillLocation||{};if(!s||!l||!c||!d)return!1;const u=this.direction;this._prevUndos.length>0&&this._prevUndos.forEach(P=>{this._commandService.syncExecuteCommand(P.id,P.params)}),this._prevUndos=[];const h=a.Rectangle.union(at(s),at(l)),g=this.getActiveHooks(),S=this._univerInstanceService.getUnit(c,a.UniverInstanceType.UNIVER_SHEET);c===i&&d===r&&this._commandService.syncExecuteCommand(m.SetSelectionsOperation.id,{selections:[{primary:{...(R=(O=this._selectionManagerService.getCurrentLastSelection())==null?void 0:O.primary)!=null?R:h},range:{...h,rangeType:a.RANGE_TYPE.NORMAL}}],unitId:c,subUnitId:d});const f=[],v=[];g.forEach(P=>{var k;const{undos:A,redos:N}=((k=P.onFillData)==null?void 0:k.call(P,{source:s,target:l,unitId:c,subUnitId:d},u,e))||{};A&&f.push(...A),N&&v.push(...N)});const p=v.every(P=>this._commandService.syncExecuteCommand(P.id,P.params)),C=[];e!==ae.NO_FORMAT&&v.forEach(P=>{if(P.id===m.SetRangeValuesMutation.id){const{cellValue:A}=P.params;new a.ObjectMatrix(A).forValue((k,H,V)=>{const W=Object.keys(S.getStyles().get(V==null?void 0:V.s)||{});(V!=null&&V.p||W.length&&xs.some(L=>W.includes(L)))&&C.push({startRow:k,endRow:k,startColumn:H,endColumn:H})})}});const _=this._getAutoHeightUndoRedos(c,d,C);return _.redos.every(P=>this._commandService.syncExecuteCommand(P.id,P.params))&&(f.push(..._.undos),v.push(..._.redos)),p&&(this._prevUndos=f,this._undoRedoService.pushUndoRedo({unitID:c,undoMutations:f,redoMutations:v})),g.forEach(P=>{var A;(A=P.onAfterFillData)==null||A.call(P,{source:s,target:l,unitId:c,subUnitId:d},u,e)}),this.setShowMenu(!0),!0}_getAutoHeightUndoRedos(e,t,i){var h,g;const r=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(E.SheetSkeletonManagerService),s=(g=r==null?void 0:r.getCurrentParam())==null?void 0:g.skeleton;if(!s)return{redos:[],undos:[]};const l=s.calculateAutoHeightInRange(i),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}]}}},E.AutoFillService=zd([tn(0,a.ICommandService),tn(1,a.IUndoRedoService),tn(2,M.IRenderManagerService),tn(3,a.Inject(a.IUniverInstanceService)),tn(4,a.Inject(m.SheetsSelectionsService)),tn(5,a.Inject(a.Injector))],E.AutoFillService);const ct=a.createIdentifier("univer.auto-fill-service"),dt={type:a.CommandType.COMMAND,id:"sheet.command.auto-fill",handler:async(n,o)=>{const e=n.get(ct),t=n.get(a.IUniverInstanceService),{sourceRange:i,targetRange:r,applyType:s}=o,l=m.getSheetCommandTarget(t,o);if(!l)return!1;const{subUnitId:c,unitId:d}=l;return e.triggerAutoFill(d,c,i,r,s)}},nn={id:"sheet.command.auto-clear-content",type:a.CommandType.COMMAND,handler:async(n,o)=>{const e=n.get(a.IUniverInstanceService),t=n.get(a.ICommandService),i=n.get(a.IUndoRedoService),r=n.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])},g=m.SetRangeValuesUndoMutationFactory(n,h),{startColumn:S,startRow:f}=u,v={selections:[{primary:{startColumn:S,startRow:f,endColumn:S,endRow:f,actualRow:f,actualColumn:S,isMerged:!1,isMergedMainCell:!1},range:{...u}}],unitId:l,subUnitId:c};if(t.executeCommand(m.SetSelectionsOperation.id,v),t.syncExecuteCommand(m.SetRangeValuesMutation.id,h)){const C=r.afterCommandExecute({id:m.SetRangeValuesMutation.id,params:h});return a.sequenceExecute(C.redos,t),i.pushUndoRedo({unitID:l,undoMutations:[{id:m.SetRangeValuesMutation.id,params:g},...C.undos],redoMutations:[{id:m.SetRangeValuesMutation.id,params:h},...C.redos]}),!0}return!1}};function tr(n){return n.getContextValue(a.FOCUSING_SHEET)}function se(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function Zs(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function Xd(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function nr(n){return n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function Zi(n){return n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function Yd(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.EDITOR_ACTIVATED)&&n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function on(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&!n.getContextValue(a.FOCUSING_EDITOR_STANDALONE)}var jd=Object.getOwnPropertyDescriptor,Zd=(n,o,e,t)=>{for(var i=t>1?void 0:t?jd(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},ir=(n,o)=>(e,t)=>o(e,t,n);const Gs=Ko.MARK_SELECTION,yt=a.createIdentifier("univer.mark-selection-service");E.MarkSelectionService=class extends a.Disposable{constructor(e,t,i){super();T(this,"_shapeMap",new Map);this._currentService=e,this._renderManagerService=t,this._themeService=i}addShape(e,t=[],i=Gs){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.generateRandomId(),c={selection:e,subUnitId:s,unitId:r.getUnitId(),zIndex:i,control:null,exits:t};return this._shapeMap.set(l,c),this.refreshShapes(),l}addShapeWithNoFresh(e,t=[],i=Gs){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.generateRandomId();return this._shapeMap.set(l,{selection:e,subUnitId:s,unitId:r.getUnitId(),zIndex:i,control:null,exits:t}),l}refreshShapes(){var r;const e=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!e)return;const t=e.getUnitId(),i=(r=e.getActiveSheet())==null?void 0:r.getSheetId();this._shapeMap.forEach(s=>{const{unitId:l,subUnitId:c,selection:d,control:u,zIndex:h}=s;if(u==null||u.dispose(),l!==t||c!==i)return;const g=this._renderManagerService.getRenderById(l);if(!g)return;const S=g.with(E.SheetSkeletonManagerService).getCurrentSkeleton();if(!S)return;const{scene:f}=g,{rowHeaderWidth:v,columnHeaderHeight:p}=S,C=new Jn(f,h,this._themeService,{enableAutoFill:!1,highlightHeader:!1,rowHeaderWidth:v,columnHeaderHeight:p}),_=Re(d,S);C.updateRangeBySelectionWithCoord(_),s.control=C})}getShapeMap(){return this._shapeMap}removeShape(e){const t=this._shapeMap.get(e);if(!t)return;const{control:i}=t;i==null||i.dispose(),this._shapeMap.delete(e)}removeAllShapes(){for(const e of this._shapeMap.values()){const{control:t}=e;t==null||t.dispose()}this._shapeMap.clear()}},E.MarkSelectionService=Zd([ir(0,a.IUniverInstanceService),ir(1,M.IRenderManagerService),ir(2,a.Inject(a.ThemeService))],E.MarkSelectionService);function Ks(n){return{strokeWidth:1.5,stroke:n.getColorFromTheme("primary.600"),fill:"rgba(178, 178, 178, 0.10)",widgets:{},strokeDash:8}}function Gd(n){if(n==null)return n;const o={};return n.p!==void 0&&(o.p=n.p===null?null:a.cloneValue(n.p)),n.s!==void 0&&(n.s===null||typeof n.s=="string"?o.s=n.s:o.s=a.cloneValue(n.s)),n.v!==void 0&&(o.v=n.v),n.t!==void 0&&(o.t=n.t),n.f!==void 0&&(o.f=n.f),n.ref!==void 0&&(o.ref=n.ref),n.xf!==void 0&&(o.xf=n.xf),n.si!==void 0&&(o.si=n.si),n.custom!==void 0&&(o.custom=n.custom===null?null:a.cloneValue(n.custom)),n.rowSpan!==void 0&&(o.rowSpan=n.rowSpan),n.colSpan!==void 0&&(o.colSpan=n.colSpan),n.plain!==void 0&&(o.plain=n.plain),o}const Kd=10,qd=6;function Qd(){return a.generateRandomId(qd)}function Jd(n){const o=n.match(/data-copy-id="([^\s]+)"/);return o&&o[1]?o[1]:null}class $d{constructor(){T(this,"_cache",new a.LRUMap(Kd));T(this,"_lastCopyId$",new D.BehaviorSubject(null));T(this,"lastCopyId$",this._lastCopyId$.asObservable())}set(o,e){this._cache.set(o,e),this._lastCopyId$.next(o)}get(o){return this._cache.get(o)}del(o){this._cache.delete(o),this._lastCopyId$.getValue()===o&&this._lastCopyId$.next(null)}clear(){this._cache.clear(),this._lastCopyId$.next(null)}clearWithUnitId(o){this._cache.forEach((e,t)=>{e.unitId===o&&this._cache.delete(t)})}getLastCopyId(){return this._lastCopyId$.getValue()}}function Gi(n,o){const e=o!=null?o:n.style,t={},i=n.tagName.toLowerCase();switch(i){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=i==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}return eu(e,t),t}function eu(n,o){if(n instanceof CSSStyleDeclaration)for(let e=0;e<n.length;e++){const t=n[e],i=n.getPropertyValue(t);qs(t,i,o)}else for(const e in n){const t=n[e];qs(e,t,o)}}function qs(n,o,e){switch(n){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);t.isValid&&(e.bg={rgb:t.toRgbString()});break}}}function tu(n){const o=document.createElement("body");return o.innerHTML=n,o}function Qs(n){const o=n.style,e={};for(let t=0;t<o.length;t++){const i=o[t],r=o.getPropertyValue(i);switch(i){case"margin-top":{const s=Number.parseInt(r);e.spaceAbove={v:/pt/.test(r)?M.ptToPixel(s):s};break}case"margin-bottom":{const s=Number.parseInt(r);e.spaceBelow={v:/pt/.test(r)?M.ptToPixel(s):s};break}case"line-height":{const s=Number.parseFloat(r);e.lineSpacing=s;break}}}return Object.getOwnPropertyNames(e).length?e:null}function or(n,o){const e=[];for(let t=0,i=n.length;t<i;t++)n[t]===a.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});return e}function Js(n,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 n.p?r&&((c=(l=n.p.body)==null?void 0:l.textRuns)!=null&&c.length)?(n.p.body.textRuns=[],{...n,s:e[0].ts}):n:r?{...n,s:e[0].ts}:n}const $s=["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 ea(n,o){const e=n.tagName.toLowerCase();return typeof o=="string"?e===o:Array.isArray(o)?o.some(t=>t===e):o(n)}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(v=>v.checkPasteType(o));e&&(this._styleRules=[...e.stylesRules],this._afterProcessRules=[...e.afterProcessRules]);const t=new a.ObjectMatrix;this._dom=tu(o);const i=this._dom.querySelector("style");if(i){const v=document.createElement("div"),p=v.attachShadow({mode:"open"});document.body.appendChild(v),p.appendChild(i);for(const C of i.sheet.cssRules){const _=C,w=_.selectorText,y=_.style;this._styleMap.set(w,y)}i.remove(),v.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:g,payloads:S,customRanges:f}=r;if(u){const v=u.map(p=>p.startIndex+1);v.unshift(0);for(let p=0;p<v.length;p++){let C;if(p===v.length-1){if(C=`${h.substring(v[p])}\r
2
2
  `,C===`\r
3
3
  `)continue}else C=`${h.substring(v[p],v[p+1]-1)}\r
4
4
  `;const _=[];g==null||g.forEach(R=>{R.st>=v[p]&&R.ed<=v[p+1]&&_.push({st:R.st-v[p],ed:R.ed-v[p],ts:R.ts})});const w=[];f==null||f.forEach(R=>{R.startIndex>=v[p]&&R.endIndex<=v[p+1]&&w.push({...R,startIndex:R.startIndex-v[p],endIndex:R.endIndex-v[p]})});const y=this._generateDocumentDataModelSnapshot({body:{dataStream:C,textRuns:_,paragraphs:or(C),customRanges:w}}),O=Object.keys(t.getMatrix()).length===0;t.setValue(O?0:t.getLength(),0,{v:C,p:y}),s.push({})}}else if(h){const v=`${h}\r
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-ui",
3
- "version": "0.15.0-insiders.20260106-79b11f9",
3
+ "version": "0.15.0-insiders.20260107-3441c7a",
4
4
  "private": false,
5
5
  "description": "UniverSheet normal ui-plugin-sheets",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -66,15 +66,15 @@
66
66
  "dependencies": {
67
67
  "@univerjs/icons": "^1.1.0",
68
68
  "@univerjs/protocol": "0.1.48",
69
- "@univerjs/core": "0.15.0-insiders.20260106-79b11f9",
70
- "@univerjs/design": "0.15.0-insiders.20260106-79b11f9",
71
- "@univerjs/engine-formula": "0.15.0-insiders.20260106-79b11f9",
72
- "@univerjs/engine-render": "0.15.0-insiders.20260106-79b11f9",
73
- "@univerjs/sheets": "0.15.0-insiders.20260106-79b11f9",
74
- "@univerjs/docs": "0.15.0-insiders.20260106-79b11f9",
75
- "@univerjs/telemetry": "0.15.0-insiders.20260106-79b11f9",
76
- "@univerjs/ui": "0.15.0-insiders.20260106-79b11f9",
77
- "@univerjs/docs-ui": "0.15.0-insiders.20260106-79b11f9"
69
+ "@univerjs/core": "0.15.0-insiders.20260107-3441c7a",
70
+ "@univerjs/docs": "0.15.0-insiders.20260107-3441c7a",
71
+ "@univerjs/docs-ui": "0.15.0-insiders.20260107-3441c7a",
72
+ "@univerjs/engine-formula": "0.15.0-insiders.20260107-3441c7a",
73
+ "@univerjs/engine-render": "0.15.0-insiders.20260107-3441c7a",
74
+ "@univerjs/design": "0.15.0-insiders.20260107-3441c7a",
75
+ "@univerjs/telemetry": "0.15.0-insiders.20260107-3441c7a",
76
+ "@univerjs/ui": "0.15.0-insiders.20260107-3441c7a",
77
+ "@univerjs/sheets": "0.15.0-insiders.20260107-3441c7a"
78
78
  },
79
79
  "devDependencies": {
80
80
  "postcss": "^8.5.6",
@@ -85,7 +85,7 @@
85
85
  "vite": "^7.3.0",
86
86
  "vitest": "^4.0.16",
87
87
  "@univerjs-infra/shared": "0.15.0",
88
- "@univerjs/themes": "0.15.0-insiders.20260106-79b11f9"
88
+ "@univerjs/themes": "0.15.0-insiders.20260107-3441c7a"
89
89
  },
90
90
  "scripts": {
91
91
  "test": "vitest run",