@univerjs/sheets-ui
Version:
UniverSheet normal ui-plugin-sheets
1 lines • 887 kB
JavaScript
"use strict";var Sd=Object.defineProperty;var fd=(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)=>fd(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"),y=require("@univerjs/engine-render"),A=require("rxjs"),I=require("@univerjs/ui"),ve=require("@univerjs/docs"),W=require("react"),G=require("@univerjs/engine-formula"),b=require("react/jsx-runtime"),z=require("@univerjs/design"),le=require("rxjs/operators"),pd=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,Sr={id:"sheet.command.set-row-header-width",type:a.CommandType.COMMAND,handler:async(n,o)=>{if(!o)return!1;const e=n.get(y.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(y.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 ye(n,o){const{range:e,primary:t,style:r}=n,i=Sn(o,e),s=t&&lr(o,t);return{rangeWithCoord:i,primaryWithCoord:s,style:r}}function lr(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=y.withCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET,exports.SheetSkeletonManagerService,this._injector.get(a.IUniverInstanceService),this._injector.get(y.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 y.SHEET_VIEWPORT_KEY.VIEW_MAIN:return o.endRow>=t.startRow&&o.endColumn>=t.startColumn;case y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP:case y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT:return o.endColumn>=t.startColumn&&o.startRow<t.startRow;case y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT:case y.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM:return o.endRow>=t.startRow&&o.startColumn<t.startColumn;case y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP:case y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT:case y.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP:case y.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(Ce,a.Quantity.OPTIONAL))==null?void 0:l.interceptor.fetchThroughInterceptors(Oi)(!1,null))!==!1&&i.setCursor(y.CURSOR_TYPE.MOVE)}),i.onPointerLeave$.subscribeEvent(()=>{i.resetCursor()}),i.onPointerDown$.subscribeEvent(this._controlPointerDownHandler.bind(this))})}_controlMoving(o,e){var O;const t=this._scene,r=t.getScrollXYInfoByViewport(y.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 f=Math.max(0,d+this._relativeSelectionPositionColumn),p=f+this._relativeSelectionColumnLength;p>h&&(p=h,p-f<this._relativeSelectionColumnLength&&(f=p-this._relativeSelectionColumnLength));const v=this._skeleton.worksheet.getCellInfoInMergeData(g,f),_=ye({range:{startRow:g,endRow:S,startColumn:f,endColumn:p},primary:v,style:null},this._skeleton),R=this._skeleton.getNoMergeCellWithCoordByIndex(g,f),w=this._skeleton.getNoMergeCellWithCoordByIndex(S,p),P=(R==null?void 0:R.startY)||0,T=(w==null?void 0:w.endY)||0,M=(R==null?void 0:R.startX)||0,x=(w==null?void 0:w.endX)||0;(O=this._helperSelection)==null||O.transformByState({left:M,top:P,width:x-M,height:T-P}),this._targetSelection={..._.rangeWithCoord},this._control.selectionMoving$.next(_.rangeWithCoord)}_controlPointerDownHandler(o){const{offsetX:e,offsetY:t}=o,r=this._scene,i=r.getCoordRelativeToViewport(y.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:f,startColumn:p,endRow:v,endColumn:C}=this._control.model;let _=0,R=0;g<f?_-=1:g>v&&(_+=1),S<p?R-=1:S>C&&(R+=1),this._relativeSelectionPositionRow=f-g+_,this._relativeSelectionPositionColumn=p-S+R,this._relativeSelectionRowLength=v-f,this._relativeSelectionColumnLength=C-p;const w=this._control.currentStyle,P=this._getScale();this.isHelperSelection&&(this._helperSelection=new y.Rect(Ds,{stroke:w.stroke,strokeWidth:w.strokeWidth/P}),r.addObject(this._helperSelection));const T=r.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN),M=y.ScrollTimer.create(r);this._scrollTimer=M,M.startScroll(s,l,T),r.disableObjectsEvent(),this._scenePointerMoveSub=r.onPointerMove$.subscribeEvent(x=>{var V;if(this._disabled)return;const{offsetX:O,offsetY:D}=x;if(((V=this._injector.get(Ce,a.Quantity.OPTIONAL))==null?void 0:V.interceptor.fetchThroughInterceptors(Oi)(!1,null))===!1)return;const{x:k,y:H}=r.getCoordRelativeToViewport(y.Vector2.FromArray([O,D]));this._controlMoving(k,H),r.setCursor(y.CURSOR_TYPE.MOVE),M.scrolling(k,H,()=>{this._controlMoving(k,H)})}),this._scenePointerUpSub=r.onPointerUp$.subscribeEvent(()=>{var O,D,N,k;(O=this._helperSelection)==null||O.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=[y.CURSOR_TYPE.NORTH_WEST_RESIZE,y.CURSOR_TYPE.NORTH_RESIZE,y.CURSOR_TYPE.NORTH_EAST_RESIZE,y.CURSOR_TYPE.WEST_RESIZE,y.CURSOR_TYPE.EAST_RESIZE,y.CURSOR_TYPE.SOUTH_WEST_RESIZE,y.CURSOR_TYPE.SOUTH_RESIZE,y.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(y.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),f=Math.min(u,g),p=Math.max(d,h),v=Math.max(u,g);this._relativeSelectionPositionRow=S,this._relativeSelectionPositionColumn=f,this._relativeSelectionRowLength=p-S,this._relativeSelectionColumnLength=v-f,e===y.CURSOR_TYPE.NORTH_WEST_RESIZE?(this._relativeSelectionPositionRow=p,this._relativeSelectionPositionColumn=v):e===y.CURSOR_TYPE.NORTH_RESIZE?this._relativeSelectionPositionRow=p:e===y.CURSOR_TYPE.NORTH_EAST_RESIZE?this._relativeSelectionPositionRow=p:e===y.CURSOR_TYPE.WEST_RESIZE?this._relativeSelectionPositionColumn=v:e===y.CURSOR_TYPE.SOUTH_WEST_RESIZE?this._relativeSelectionPositionColumn=v:e===y.CURSOR_TYPE.SOUTH_RESIZE&&(this._relativeSelectionPositionRow=S);const C=y.ScrollTimer.create(t),_=t.getViewport(y.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:T,y:M}=t.getCoordRelativeToViewport(y.Vector2.FromArray([w,P]));this._widgetMoving(T,M,e),t.setCursor(e),C.scrolling(T,M,()=>{this._widgetMoving(T,M,e)})}),this._scenePointerUpSub=t.onPointerUp$.subscribeEvent(()=>{var w,P,T;const R=this._scene;R.resetCursor(),this._clearObserverEvent(),R.enableObjectsEvent(),(w=this._scrollTimer)==null||w.dispose(),this._control.selectionScaled$.next(this._targetSelection),(T=(P=this._selectionHooks).selectionMoveEnd)==null||T.call(P)})}_widgetMoving(o,e,t){const r=this._scene,i=r.getScrollXYInfoByViewport(y.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,f=u;t===y.CURSOR_TYPE.NORTH_WEST_RESIZE?(h=d,g=u,S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn):t===y.CURSOR_TYPE.NORTH_RESIZE?(h=d,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength):t===y.CURSOR_TYPE.NORTH_EAST_RESIZE?(h=d,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,f=u):t===y.CURSOR_TYPE.WEST_RESIZE?(h=this._relativeSelectionPositionRow,g=u,S=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,f=this._relativeSelectionPositionColumn):t===y.CURSOR_TYPE.EAST_RESIZE?S=this._relativeSelectionPositionRow+this._relativeSelectionRowLength:t===y.CURSOR_TYPE.SOUTH_WEST_RESIZE?(h=this._relativeSelectionPositionRow,g=u,S=d,f=this._relativeSelectionPositionColumn):t===y.CURSOR_TYPE.SOUTH_RESIZE&&(h=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,S=d,f=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength);const p=this._swapPositions(h,g,S,f),v=this._skeleton.getCellWithMergeInfoByIndex(h,g),_=ye({range:p,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(Ce).interceptor.fetchThroughInterceptors(Ai)(!1,{x:e.offsetX,y:e.offsetY,skeleton:this._skeleton,scene:this._scene})&&o.setCursor(y.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(y.Vector2.FromArray([o,e])),h=this._skeleton.getRowCount()-1,g=this._skeleton.getColumnCount()-1;let S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn,p=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,v=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength,C=!1,_=!0;if((d<f||d>v)&&c>=S&&c<=p){const H=this._fillRuler(d,f,v,this._relativeSelectionColumnLength,g);f=H.startRowOrColumn,v=H.endRowOrColumn,C=H.isLighten,_=!1}else if((c<S||c>p)&&d>=f&&d<=v){const H=this._fillRuler(c,S,p,this._relativeSelectionRowLength,h);S=H.startRowOrColumn,p=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,f,v,this._relativeSelectionColumnLength,g);f=H.startRowOrColumn,v=H.endRowOrColumn,C=H.isLighten,_=!1}else{const H=this._fillRuler(c,S,p,this._relativeSelectionRowLength,h);S=H.startRowOrColumn,p=H.endRowOrColumn,C=H.isLighten}const R=this._skeleton.getNoMergeCellWithCoordByIndex(S,f),w=this._skeleton.getNoMergeCellWithCoordByIndex(p,v),P=(R==null?void 0:R.startY)||0,T=(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 U=new a.ColorKit(this._fillControlColors[V]).lighten(Id).toRgbString();H.setProps({fill:U})}):this._controlHandler((H,V)=>{H.setProps({fill:this._fillControlColors[V]})});const O=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();S===p&&_===!0||f===v&&_===!1?(D=this._helperSelection)==null||D.hide():((N=this._helperSelection)==null||N.transformByState({left:M-O/2,top:P-O/2,width:x-M,height:T-P}),(k=this._helperSelection)==null||k.show()),this._targetSelection={startY:P,endY:T,startX:M,endX:x,startRow:S,endRow:p,startColumn:f,endColumn:v},this._control.selectionFilling$.next(this._targetSelection)}_autoFillForPointerdown(o){const{offsetX:e,offsetY:t}=o,r=this._scene,i=r.getCoordRelativeToViewport(y.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,f=g==null?void 0:g.strokeWidth;const p=nt(this._themeService);S==null&&(S=p.stroke),f==null&&(f=p.strokeWidth);const v=this._getScale();f/=v;const C=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/v,_=new a.ColorKit(S).darken(2).toRgbString();this.isHelperSelection&&(this._helperSelection=new y.Rect(Ds,{stroke:_,strokeWidth:f+C/2}),r.addObject(this._helperSelection)),this._activeViewport=r.getActiveViewportByCoord(y.Vector2.FromArray([e,t]));const R=r.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN),w=y.ScrollTimer.create(r,this._activeViewport.viewportKey===y.SHEET_VIEWPORT_KEY.VIEW_MAIN?y.ScrollTimerType.ALL:y.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:T,offsetY:M}=P,x=r.getActiveViewportByCoord(y.Vector2.FromArray([T,M]));if(!this._injector.get(Ce).interceptor.fetchThroughInterceptors(Ai)(!1,{x:o.offsetX,y:o.offsetY,skeleton:this._skeleton,scene:this._scene}))return;const{x:D,y:N}=r.getCoordRelativeToViewport(y.Vector2.FromArray([T,M]));this._autoFillMoving(D,N),r.setCursor(y.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=y.ScrollTimerType.Y,V={...k,endRow:k.startRow}):k.endRow!==u?(w.scrollTimerType=y.ScrollTimerType.Y,V={...k,startRow:k.endRow}):k.startColumn!==d?(w.scrollTimerType=y.ScrollTimerType.X,V={...k,endColumn:k.startColumn}):(w.scrollTimerType=y.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===y.ScrollTimerType.X?0:void 0,y:w.scrollTimerType===y.ScrollTimerType.Y?0:void 0}),this._activeViewport=x)}w.scrolling(D,N,()=>{this._autoFillMoving(D,N)})}),this._scenePointerUpSub=r.onPointerUp$.subscribeEvent(()=>{var T,M;(T=this._helperSelection)==null||T.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,O)=>{x.setProps({fill:this._fillControlColors[O]})}),this._fillControlColors=[]})}_viewportMainScrollBarNeedResetPosition(o,e,t){return o===y.ScrollTimerType.X&&(e===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||e===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP)&&(t===y.SHEET_VIEWPORT_KEY.VIEW_MAIN||t===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP)||o===y.ScrollTimerType.Y&&(e===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||e===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP)&&(t===y.SHEET_VIEWPORT_KEY.VIEW_MAIN||t===y.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 f=h[g];o(f,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 pr 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 A.BehaviorSubject(this));E(this,"dispose$",this._dispose$.asObservable());E(this,"selectionMoving$",new A.Subject);E(this,"selectionMoveEnd$",new A.Subject);E(this,"selectionScaling$",new A.Subject);E(this,"selectionScaled$",new A.Subject);E(this,"selectionFilling$",new A.Subject);E(this,"_selectionFilled$",new A.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 y.Rect("__SpreadsheetSelectionShapeLeftControl__"+e,{zIndex:e}),this._rightBorder=new y.Rect("__SpreadsheetSelectionShapeRightControl__"+e,{zIndex:e}),this._topBorder=new y.Rect("__SpreadsheetSelectionTopControl__"+e,{zIndex:e}),this._bottomBorder=new y.Rect("__SpreadsheetSelectionBottomControl__"+e,{zIndex:e}),this._backgroundControlTop=new y.Rect("__SpreadsheetSelectionBackgroundControlTop__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlBottom=new y.Rect("__SpreadsheetSelectionBackgroundControlBottom__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleLeft=new y.Rect("__SpreadsheetSelectionBackgroundControlMiddleLeft__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleRight=new y.Rect("__SpreadsheetSelectionBackgroundControlMiddleRight__"+e,{zIndex:e-1,evented:!1}),this._autoFillControl=new y.Rect("__SpreadsheetSelectionFillControl__"+e,{zIndex:e+1}),this._autoFillControl.hide(),this._dashedRect=new y.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 y.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===y.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&(this._updateLayoutOfSelectionControl(this._currentStyle),this._updateControlCoord())})))}_initialHeader(){const e=this._zIndex;this._rowHeaderBackground=new y.Rect("__SpreadSheetSelectionRowHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderBorder=new y.Rect("__SpreadSheetSelectionRowHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderGroup=new y.Group("__SpreadSheetSelectionRowHeaderGroup__"+e,this._rowHeaderBackground,this._rowHeaderBorder),this._rowHeaderGroup.hide(),this._rowHeaderGroup.evented=!1,this._rowHeaderGroup.zIndex=e,this._columnHeaderBackground=new y.Rect("__SpreadSheetSelectionColumnHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderBorder=new y.Rect("__SpreadSheetSelectionColumnHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderGroup=new y.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 y.Rect("__SpreadSheetSelectionTopLeftWidget__"+e,{zIndex:e+1}),this._topCenterWidget=new y.Rect("__SpreadSheetSelectionTopCenterWidget__"+e,{zIndex:e+1}),this._topRightWidget=new y.Rect("__SpreadSheetSelectionTopRightWidget__"+e,{zIndex:e+1}),this._middleLeftWidget=new y.Rect("__SpreadSheetSelectionMiddleLeftWidget__"+e,{zIndex:e+1}),this._middleRightWidget=new y.Rect("__SpreadSheetSelectionMiddleRightWidget__"+e,{zIndex:e+1}),this._bottomLeftWidget=new y.Rect("__SpreadSheetSelectionBottomLeftWidget__"+e,{zIndex:e+1}),this._bottomCenterWidget=new y.Rect("__SpreadSheetSelectionBottomCenterWidget__"+e,{zIndex:e+1}),this._bottomRightWidget=new y.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 f=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/g,p=y.FIX_ONE_PIXEL_BLUR_OFFSET/g,{startX:v,startY:C,endX:_,endY:R}=this._selectionRenderModel;if(this.leftControl.transformByState({height:R-C,left:-S+p,width:u,strokeWidth:f,top:-f/2+p}),this.leftControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.rightControl.transformByState({height:R-C,left:_-v-S+p,width:u,strokeWidth:f,top:-f/2+p}),this.rightControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.topControl.transformByState({width:_-v+u,top:-S+p,left:-S+p,height:u,strokeWidth:f}),this.topControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.bottomControl.transformByState({width:_-v+u,top:R-C-S+p,height:u,left:-S+p,strokeWidth:f}),this.bottomControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),l==null)this.dashedRect.hide(),this._stopAntLineAnimation();else{const w=t.strokeWidth*2/g;this.dashedRect.transformByState({height:R-C,width:_-v,strokeWidth:w,left:-w/2+p,top:-w/2+p}),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-p,top:R-C-d/2+h/2-p,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,f,p,v,C,_,R,w,P,T,M,x,O,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(),(f=this._rowHeaderBackground)==null||f.dispose(),(p=this._columnHeaderBackground)==null||p.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(),(T=this._middleRightWidget)==null||T.dispose(),(M=this._bottomLeftWidget)==null||M.dispose(),(x=this._bottomCenterWidget)==null||x.dispose(),(O=this._bottomRightWidget)==null||O.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:f=c.columnHeaderStroke}=e;let{rowHeaderStrokeWidth:p=c.rowHeaderStrokeWidth,columnHeaderStrokeWidth:v=c.columnHeaderStrokeWidth}=e;p/=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:f}),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:p,height:s-r,left:C-p+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:f}=u,p=d/2,v={left:-p,top:-p,width:i-t+p*2,height:g-r+p};v.height<0&&(v.width=0,v.height=0),this._backgroundControlTop.transformByState(v);const C={left:-p,top:g-r,width:h-t+p,height:f-g};C.width<0&&(C.width=0,C.height=0),this._backgroundControlMiddleLeft.transformByState(C);const _={left:S-t-p,top:g-r,width:i-S+p*2,height:f-g};_.width<0&&(_.width=0,_.height=0),this._backgroundControlMiddleRight.transformByState(_);const R={left:-p,top:f-r,width:i-t+p*2,height:s-f+p};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},f=h-g;this._widgetRects.forEach(p=>{p.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 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,y.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=y.requestNewFrame(()=>{this._startAntLineAnimation()})}}class _d extends y.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 Qi extends a.Disposable{constructor(e,t,r,i,s){super();E(this,"_downObserver");E(this,"_scenePointerMoveSub");E(this,"_scenePointerUpSub");E(this,"_controlFillConfig$",new A.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 A.BehaviorSubject([]));E(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());E(this,"_selectionMoving$",new A.Subject);E(this,"selectionMoving$",this._selectionMoving$.asObservable());E(this,"_selectionMoveStart$",new A.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 pr(e,i,this._selectionTheme,{highlightHeader:this._highlightHeader,rowHeaderWidth:s,columnHeaderHeight:l});this._selectionControls.push(c);const d=ye(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=ye(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(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e>r.startRow&&t>r.startColumn)return this._scene.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e<=r.startRow&&t<=r.startColumn)return this._scene.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP);if(e<=r.startRow&&t>r.startColumn)return this._scene.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(e>r.startRow&&t<=r.startColumn)return this._scene.getViewport(y.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=y.ScrollTimerType.ALL,s,l){var f,p;let c=0,d=0,u=s,h=l;this._scrollTimer=y.ScrollTimer.create(this._scene,i),this._scrollTimer.startScroll((f=e==null?void 0:e.left)!=null?f:0,(p=e==null?void 0:e.top)!=null?p:0,e);const g=this._scene,S=g.getActiveViewportByCoord(y.Vector2.FromArray([s,l]));this._scenePointerMoveSub=g.onPointerMove$.subscribeEvent(v=>{var k,H,V,U,L,B,F,j,X;const{offsetX:C,offsetY:_}=v,{x:R,y:w}=g.getCoordRelativeToViewport(y.Vector2.FromArray([C,_]));this._movingHandler(R,w,t,r);let P=R,T=w;const M=this.getActiveSelectionControl(),x=this._getFreeze(),O=M==null?void 0:M.model,D=(k=g.getActiveViewportByCoord(y.Vector2.FromArray([C,_])))!=null?k:this._getViewportByCell(O==null?void 0:O.endRow,O==null?void 0:O.endColumn);if((()=>{if(!S||!D||!e)return!1;const K=[y.SHEET_VIEWPORT_KEY.VIEW_MAIN,y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,y.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===y.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP)_<e.top&&((H=O==null?void 0:O.endRow)!=null?H:0)<((V=x==null?void 0:x.startRow)!=null?V:0)?T=e.top:re&&d%2===1&&e.scrollToViewportPos({viewportScrollY:0});else if(oe===y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT)C<e.left&&((U=O==null?void 0:O.endColumn)!=null?U:0)<((L=x==null?void 0:x.startColumn)!=null?L:0)?P=e.left:K&&c%2===1&&e.scrollToViewportPos({viewportScrollX:0});else if(oe===ae){let Z=!1,Y=!1;oe===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP?(Z=!0,Y=!0):oe===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP?Y=!0:oe===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT&&(Z=!0),((B=O==null?void 0:O.endRow)!=null?B:0)>((F=x==null?void 0:x.startRow)!=null?F:0)&&(Y=!1),((j=O==n