@univerjs/sheets-ui
Version:
UniverSheet normal ui-plugin-sheets
1 lines • 874 kB
JavaScript
"use strict";var ad=Object.defineProperty;var ld=(n,o,e)=>o in n?ad(n,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[o]=e;var E=(n,o,e)=>ld(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"),_=require("@univerjs/ui"),V=require("react"),ve=require("@univerjs/docs"),K=require("@univerjs/engine-formula"),b=require("react/jsx-runtime"),j=require("@univerjs/design"),de=require("rxjs/operators"),cd=require("@univerjs/telemetry");function yo(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 wi=[10,400],zi="RANGE_SELECTOR_COMPONENT_KEY",Mo="EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY";var ue=(n=>(n.MAIN="__SpreadsheetRender__",n.ROW="__SpreadsheetRowHeader__",n.COLUMN="__SpreadsheetColumnHeader__",n.LEFT_TOP="__SpreadsheetLeftTopPlaceholder__",n))(ue||{});const Es=0,Jr=1,mt=10,dd=11,Ts=12,dr={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}},ur={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}},Ei=a.createInterceptorKey("rangeMovePermissionCheck"),Ti=a.createInterceptorKey("rangeFillPermissionCheck");var Xi=(n=>(n[n.FORMULA_EDITOR_SHOW=100]="FORMULA_EDITOR_SHOW",n[n.MARK_SELECTION=1e4]="MARK_SELECTION",n))(Xi||{});function gt(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 ud{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 un(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=un(o,e),s=t&&rr(o,t);return{rangeWithCoord:i,primaryWithCoord:s,style:r}}function rr(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 ys="__SpreadsheetHelperSelectionTempRect",hd=35;class Ma{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(Ce,a.Quantity.OPTIONAL))==null?void 0:l.interceptor.fetchThroughInterceptors(Ei)(!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 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),I=Te({range:{startRow:g,endRow:S,startColumn:f,endColumn:p},primary:v,style:null},this._skeleton),w=this._skeleton.getNoMergeCellWithCoordByIndex(g,f),R=this._skeleton.getNoMergeCellWithCoordByIndex(S,p),P=(w==null?void 0:w.startY)||0,y=(R==null?void 0:R.endY)||0,M=(w==null?void 0:w.startX)||0,x=(R==null?void 0:R.endX)||0;(A=this._helperSelection)==null||A.transformByState({left:M,top:P,width:x-M,height:y-P}),this._targetSelection={...I.rangeWithCoord},this._control.selectionMoving$.next(I.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:f,startColumn:p,endRow:v,endColumn:C}=this._control.model;let I=0,w=0;g<f?I-=1:g>v&&(I+=1),S<p?w-=1:S>C&&(w+=1),this._relativeSelectionPositionRow=f-g+I,this._relativeSelectionPositionColumn=p-S+w,this._relativeSelectionRowLength=v-f,this._relativeSelectionColumnLength=C-p;const R=this._control.currentStyle,P=this._getScale();this.isHelperSelection&&(this._helperSelection=new T.Rect(ys,{stroke:R.stroke,strokeWidth:R.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 N;if(this._disabled)return;const{offsetX:A,offsetY:D}=x;if(((N=this._injector.get(Ce,a.Quantity.OPTIONAL))==null?void 0:N.interceptor.fetchThroughInterceptors(Ei)(!1,null))===!1)return;const{x:H,y:W}=r.getCoordRelativeToViewport(T.Vector2.FromArray([A,D]));this._controlMoving(H,W),r.setCursor(T.CURSOR_TYPE.MOVE),M.scrolling(H,W,()=>{this._controlMoving(H,W)})}),this._scenePointerUpSub=r.onPointerUp$.subscribeEvent(()=>{var A,D,k,H;(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),(H=(k=this._selectionHooks).selectionMoveEnd)==null||H.call(k)})}_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),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===T.CURSOR_TYPE.NORTH_WEST_RESIZE?(this._relativeSelectionPositionRow=p,this._relativeSelectionPositionColumn=v):e===T.CURSOR_TYPE.NORTH_RESIZE?this._relativeSelectionPositionRow=p:e===T.CURSOR_TYPE.NORTH_EAST_RESIZE?this._relativeSelectionPositionRow=p: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),I=t.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN);C.startScroll(l,c,I),this._scrollTimer=C,t.disableObjectsEvent(),this._scenePointerMoveSub=t.onPointerMove$.subscribeEvent(w=>{const{offsetX:R,offsetY:P}=w,{x:y,y:M}=t.getCoordRelativeToViewport(T.Vector2.FromArray([R,P]));this._widgetMoving(y,M,e),t.setCursor(e),C.scrolling(y,M,()=>{this._widgetMoving(y,M,e)})}),this._scenePointerUpSub=t.onPointerUp$.subscribeEvent(()=>{var R,P,y;const w=this._scene;w.resetCursor(),this._clearObserverEvent(),w.enableObjectsEvent(),(R=this._scrollTimer)==null||R.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,f=u;t===T.CURSOR_TYPE.NORTH_WEST_RESIZE?(h=d,g=u,S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn):t===T.CURSOR_TYPE.NORTH_RESIZE?(h=d,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength):t===T.CURSOR_TYPE.NORTH_EAST_RESIZE?(h=d,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,f=u):t===T.CURSOR_TYPE.WEST_RESIZE?(h=this._relativeSelectionPositionRow,g=u,S=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,f=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,f=this._relativeSelectionPositionColumn):t===T.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),I=Te({range:p,primary:v,style:null},this._skeleton);this._targetSelection={...I.rangeWithCoord},this._control.updateRangeBySelectionWithCoord(I),this._control.selectionScaling$.next(this._targetSelection)}_initialAutoFill(){const{fillControl:o}=this._control;o.onPointerEnter$.subscribeEvent(e=>{this._injector.get(Ce).interceptor.fetchThroughInterceptors(Ti)(!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,k,H;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,f=this._relativeSelectionPositionColumn,p=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,v=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength,C=!1,I=!0;if((d<f||d>v)&&c>=S&&c<=p){const W=this._fillRuler(d,f,v,this._relativeSelectionColumnLength,g);f=W.startRowOrColumn,v=W.endRowOrColumn,C=W.isLighten,I=!1}else if((c<S||c>p)&&d>=f&&d<=v){const W=this._fillRuler(c,S,p,this._relativeSelectionRowLength,h);S=W.startRowOrColumn,p=W.endRowOrColumn,C=W.isLighten}else if(Math.abs(this._startOffsetX-u.x-r.x)/2>Math.abs(this._startOffsetY-u.y-r.y)){const W=this._fillRuler(d,f,v,this._relativeSelectionColumnLength,g);f=W.startRowOrColumn,v=W.endRowOrColumn,C=W.isLighten,I=!1}else{const W=this._fillRuler(c,S,p,this._relativeSelectionRowLength,h);S=W.startRowOrColumn,p=W.endRowOrColumn,C=W.isLighten}const w=this._skeleton.getNoMergeCellWithCoordByIndex(S,f),R=this._skeleton.getNoMergeCellWithCoordByIndex(p,v),P=(w==null?void 0:w.startY)||0,y=(R==null?void 0:R.endY)||0,M=(w==null?void 0:w.startX)||0,x=(R==null?void 0:R.endX)||0;C?this._controlHandler((W,N)=>{const U=new a.ColorKit(this._fillControlColors[N]).lighten(hd).toRgbString();W.setProps({fill:U})}):this._controlHandler((W,N)=>{W.setProps({fill:this._fillControlColors[N]})});const A=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();S===p&&I===!0||f===v&&I===!1?(D=this._helperSelection)==null||D.hide():((k=this._helperSelection)==null||k.transformByState({left:M-A/2,top:P-A/2,width:x-M,height:y-P}),(H=this._helperSelection)==null||H.show()),this._targetSelection={startY:P,endY:y,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(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,f=g==null?void 0:g.strokeWidth;const p=gt(this._themeService);S==null&&(S=p.stroke),f==null&&(f=p.strokeWidth);const v=this._getScale();f/=v;const C=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/v,I=new a.ColorKit(S).darken(2).toRgbString();this.isHelperSelection&&(this._helperSelection=new T.Rect(ys,{stroke:I,strokeWidth:f+C/2}),r.addObject(this._helperSelection)),this._activeViewport=r.getActiveViewportByCoord(T.Vector2.FromArray([e,t]));const w=r.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN),R=T.ScrollTimer.create(r,this._activeViewport.viewportKey===T.SHEET_VIEWPORT_KEY.VIEW_MAIN?T.ScrollTimerType.ALL:T.ScrollTimerType.NONE);R.startScroll(s,l,w),this._scrollTimer=R,r.disableObjectsEvent(),this._controlHandler(P=>{this._fillControlColors.push(P.fill)}),this._scenePointerMoveSub=r.onPointerMove$.subscribeEvent(P=>{var W;const{offsetX:y,offsetY:M}=P,x=r.getActiveViewportByCoord(T.Vector2.FromArray([y,M]));if(!this._injector.get(Ce).interceptor.fetchThroughInterceptors(Ti)(!1,{x:o.offsetX,y:o.offsetY,skeleton:this._skeleton,scene:this._scene}))return;const{x:D,y:k}=r.getCoordRelativeToViewport(T.Vector2.FromArray([y,M]));this._autoFillMoving(D,k),r.setCursor(T.CURSOR_TYPE.CROSSHAIR);const H=this._targetSelection;if(w&&x&&((W=this._activeViewport)==null?void 0:W.viewportKey)!==(x==null?void 0:x.viewportKey)){let N;H.startRow!==c?(R.scrollTimerType=T.ScrollTimerType.Y,N={...H,endRow:H.startRow}):H.endRow!==u?(R.scrollTimerType=T.ScrollTimerType.Y,N={...H,startRow:H.endRow}):H.startColumn!==d?(R.scrollTimerType=T.ScrollTimerType.X,N={...H,endColumn:H.startColumn}):(R.scrollTimerType=T.ScrollTimerType.X,N={...H,startColumn:H.endColumn}),this._isSelectionInViewport(N,x)&&(this._viewportMainScrollBarNeedResetPosition(R.scrollTimerType,this._activeViewport.viewportKey,x.viewportKey)&&w.scrollToBarPos({x:R.scrollTimerType===T.ScrollTimerType.X?0:void 0,y:R.scrollTimerType===T.ScrollTimerType.Y?0:void 0}),this._activeViewport=x)}R.scrolling(D,k,()=>{this._autoFillMoving(D,k)})}),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 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 yi=(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))(yi||{});const Ms=.3;class hr 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=gt(this._themeService),this._currentStyle=gt(this._themeService),this._selectionRenderModel=new ud;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,Jr),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],dd)}_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 Ma(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=T.FIX_ONE_PIXEL_BLUR_OFFSET/g,{startX:v,startY:C,endX:I,endY:w}=this._selectionRenderModel;if(this.leftControl.transformByState({height:w-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:w-C,left:I-v-S+p,width:u,strokeWidth:f,top:-f/2+p}),this.rightControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.topControl.transformByState({width:I-v+u,top:-S+p,left:-S+p,height:u,strokeWidth:f}),this.topControl.setProps({fill:r,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.bottomControl.transformByState({width:I-v+u,top:w-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 R=t.strokeWidth*2/g;this.dashedRect.transformByState({height:w-C,width:I-v,strokeWidth:R,left:-R/2+p,top:-R/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 R={fill:r,stroke:s,strokeScaleEnabled:!1},P={width:d-h,height:d-h,left:I-v-d/2+h/2-p,top:w-C-d/2+h/2-p,strokeWidth:h};this._autoFillControl.setProps(R),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,I,w,R,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(),(f=this._rowHeaderBackground)==null||f.dispose(),(p=this._columnHeaderBackground)==null||p.dispose(),(v=this._columnHeaderBorder)==null||v.dispose(),(C=this._columnHeaderGroup)==null||C.dispose(),(I=this._topLeftWidget)==null||I.dispose(),(w=this._topCenterWidget)==null||w.dispose(),(R=this._topRightWidget)==null||R.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:f=c.columnHeaderStroke}=e;let{rowHeaderStrokeWidth:p=c.rowHeaderStrokeWidth,columnHeaderStrokeWidth:v=c.columnHeaderStrokeWidth}=e;p/=d,v/=d;const C=this._rowHeaderWidth,I=this._columnHeaderHeight;if(this._highlightHeader&&I>0){let w=S;l===a.RANGE_TYPE.COLUMN&&(w=new a.ColorKit(u).setAlpha(Ms).toString()),this._columnHeaderBackground.setProps({fill:w}),this._columnHeaderBackground.resize(i-t,I),this._columnHeaderBorder.setProps({fill:f}),this._columnHeaderBorder.transformByState({width:i-t,height:v,top:I-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 w=h;l===a.RANGE_TYPE.ROW&&(w=new a.ColorKit(u).setAlpha(Ms).toString()),this._rowHeaderBackground.setProps({fill:w}),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 I={left:S-t-p,top:g-r,width:i-S+p*2,height:f-g};I.width<0&&(I.width=0,I.height=0),this._backgroundControlMiddleRight.transformByState(I);const w={left:-p,top:f-r,width:i-t+p*2,height:s-f+p};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: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,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 md 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 Ce=a.createIdentifier("univer.sheet.selection-render-service");class Yi 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:Ei,RANGE_FILL_PERMISSION_CHECK:Ti}));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 hr(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(Jr)||t.addLayer(new md(t,[],Jr))}getSkeleton(){return this._skeleton}getSelectionDataWithStyle(){const e=this._selectionControls,[t,r]=this._skeleton.getLocation();return e.map(i=>{const s=i.getValue();return s.rangeWithCoord.sheetId=r,s.rangeWithCoord.unitId=t,s})}getSelectionControls(){return this._selectionControls}_addSelectionControlByModelData(e){var l;const t=this._skeleton,r=(l=e.style)!=null?l:gt(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 f,p;let c=0,d=0,u=s,h=l;this._scrollTimer=T.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(T.Vector2.FromArray([s,l]));this._scenePointerMoveSub=g.onPointerMove$.subscribeEvent(v=>{var H,W,N,U,L,z,B,F,X;const{offsetX:C,offsetY:I}=v,{x:w,y:R}=g.getCoordRelativeToViewport(T.Vector2.FromArray([C,I]));this._movingHandler(w,R,t,r);let P=w,y=R;const M=this.getActiveSelectionControl(),x=this._getFreeze(),A=M==null?void 0:M.model,D=(H=g.getActiveViewportByCoord(T.Vector2.FromArray([C,I])))!=null?H:this._getViewportByCell(A==null?void 0:A.endRow,A==null?void 0:A.endColumn);if((()=>{if(!S||!D||!e)return!1;const G=[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 G.includes(S.viewportKey)&&G.includes(D.viewportKey)})()){if(!S||!D||!e)return!1;const G=u<e.left&&w>e.left||u>e.left&&w<e.left,te=h<e.top&&R>e.top||h>e.top&&R<e.top;G&&(c+=1),te&&(d+=1);const Q=S.viewportKey,ie=D.viewportKey;if(Q===T.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP)I<e.top&&((W=A==null?void 0:A.endRow)!=null?W:0)<((N=x==null?void 0:x.startRow)!=null?N:0)?y=e.top:te&&d%2===1&&e.scrollToViewportPos({viewportScrollY:0});else if(Q===T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT)C<e.left&&((U=A==null?void 0:A.endColumn)!=null?U:0)<((L=x==null?void 0:x.startColumn)!=null?L:0)?P=e.left:G&&c%2===1&&e.scrollToViewportPos({viewportScrollX:0});else if(Q===ie){let Z=!1,Y=!1;Q===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP?(Z=!0,Y=!0):Q===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP?Y=!0:Q===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT&&(Z=!0),((z=A==null?void 0:A.endRow)!=null?z:0)>((B=x==null?void 0:x.startRow)!=null?B:0)&&(Y=!1),((F=A==null?void 0:A.endColumn)!=null?F:0)>((X=x==null?voi