UNPKG

@univerjs/sheets-ui

Version:

UniverSheet normal ui-plugin-sheets

1 lines • 886 kB
(function(E,q){typeof exports=="object"&&typeof module<"u"?q(exports,require("@univerjs/docs-ui"),require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-render"),require("rxjs"),require("@univerjs/ui"),require("@univerjs/docs"),require("react"),require("@univerjs/engine-formula"),require("react/jsx-runtime"),require("@univerjs/design"),require("rxjs/operators"),require("@univerjs/telemetry")):typeof define=="function"&&define.amd?define(["exports","@univerjs/docs-ui","@univerjs/core","@univerjs/sheets","@univerjs/engine-render","rxjs","@univerjs/ui","@univerjs/docs","react","@univerjs/engine-formula","react/jsx-runtime","@univerjs/design","rxjs/operators","@univerjs/telemetry"],q):(E=typeof globalThis<"u"?globalThis:E||self,q(E.UniverSheetsUi={},E.UniverDocsUi,E.UniverCore,E.UniverSheets,E.UniverEngineRender,E.rxjs,E.UniverUi,E.UniverDocs,E.React,E.UniverEngineFormula,E.React,E.UniverDesign,E.rxjs.operators,E.UniverTelemetry))})(this,(function(E,q,a,m,R,A,I,be,x,K,_,Y,ce,ud){"use strict";var wp=Object.defineProperty;var Ep=(E,q,a)=>q in E?wp(E,q,{enumerable:!0,configurable:!0,writable:!0,value:a}):E[q]=a;var y=(E,q,a)=>Ep(E,typeof q!="symbol"?q+"":q,a);function Ui(n,o){if(n==null)return;const e=o.getRenderById(n);if(e==null)return;const{mainComponent:t,scene:i,engine:r,components:s}=e,l=t,c=s.get(q.DOCS_VIEW_KEY.BACKGROUND);return{document:l,docBackground:c,scene:i,engine:r}}const Yo=[10,400],jo="RANGE_SELECTOR_COMPONENT_KEY",Bi="EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY";var he=(n=>(n.MAIN="__SpreadsheetRender__",n.ROW="__SpreadsheetRowHeader__",n.COLUMN="__SpreadsheetColumnHeader__",n.LEFT_TOP="__SpreadsheetLeftTopPlaceholder__",n))(he||{});const Ds=0,Fi=1,st=10,hd=11,Ns=12,Kn={id:"sheet.command.set-row-header-width",type:a.CommandType.COMMAND,handler:async(n,o)=>{if(!o)return!1;const e=n.get(R.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:i,size:r}=o,s=e.getRenderById(t);if(s){e.getRenderById(t).with(E.SheetSkeletonManagerService).setRowHeaderSize(s,i,r);const{components:c}=s,d=c.get(he.ROW);d&&d.setCustomHeader({headerStyle:{size:r}},i)}return!0}},qn={id:"sheet.command.set-col-header-height",type:a.CommandType.COMMAND,handler:async(n,o)=>{if(!o)return!1;const e=n.get(R.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:i,size:r}=o,s=e.getRenderById(t);if(s){e.getRenderById(t).with(E.SheetSkeletonManagerService).setColumnHeaderSize(s,i,r);const{components:c}=s,d=c.get(he.COLUMN);d&&d.setCustomHeader({headerStyle:{size:r}},i)}return!0}},Zo=a.createInterceptorKey("rangeMovePermissionCheck"),Go=a.createInterceptorKey("rangeFillPermissionCheck");var Ko=(n=>(n[n.FORMULA_EDITOR_SHOW=100]="FORMULA_EDITOR_SHOW",n[n.MARK_SELECTION=1e4]="MARK_SELECTION",n))(Ko||{});function qe(n){const o=n.getColorFromTheme("primary.600"),e=n.getColorFromTheme("white"),t=new a.ColorKit(o).setAlpha(.07).toRgbString();return{strokeWidth:1,stroke:o,fill:t,widgets:{},widgetSize:6,widgetStrokeWidth:1,widgetStroke:e,autofillSize:6,autofillStrokeWidth:1,autofillStroke:e,rowHeaderFill:t,rowHeaderStroke:o,rowHeaderStrokeWidth:1,columnHeaderFill:t,columnHeaderStroke:o,columnHeaderStrokeWidth:1,expandCornerSize:40}}class md{constructor(){y(this,"_startColumn",-1);y(this,"_startRow",-1);y(this,"_endColumn",-1);y(this,"_endRow",-1);y(this,"_startX",0);y(this,"_startY",0);y(this,"_endX",0);y(this,"_endY",0);y(this,"_primary");y(this,"_rangeType",a.RANGE_TYPE.NORMAL)}get startColumn(){return this._startColumn}get startRow(){return this._startRow}get endColumn(){return this._endColumn}get endRow(){return this._endRow}get startX(){return this._startX}get startY(){return this._startY}get endX(){return this._endX}get endY(){return this._endY}get currentCell(){return this._primary}get rangeType(){return this._rangeType}isEqual(o){const{startColumn:e,startRow:t,endColumn:i,endRow:r}=this,{startColumn:s,startRow:l,endColumn:c,endRow:d}=o;return e===s&&t===l&&i===c&&r===d}highlightToSelection(){if(this._primary)return a.convertCellToRange(this._primary)}getRange(){return{startColumn:this._startColumn,startRow:this._startRow,endColumn:this._endColumn,endRow:this._endRow,startX:this._startX,startY:this._startY,endX:this._endX,endY:this._endY,rangeType:this.rangeType}}getCell(){return this._primary}getRangeType(){return this._rangeType}setRangeType(o){this._rangeType=o}getValue(){return{rangeWithCoord:this.getRange(),primaryWithCoord:this._primary}}setValue(o,e){const{startColumn:t,startRow:i,endColumn:r,endRow:s,startX:l,startY:c,endX:d,endY:u,rangeType:h}=o;this._startColumn=t,this._startRow=i,this._endColumn=r,this._endRow=s,this._startX=l,this._startY=c,this._endX=d,this._endY=u,h!==void 0&&(this._rangeType=h),e!==void 0&&this.setCurrentCell(e)}setCurrentCell(o){this._primary=o}clearCurrentCell(){this._primary=null}}function Jt(n,o){const{startRow:e,startColumn:t,endRow:i,endColumn:r,rangeType:s}=o,l=i<e?i:e,c=i<e?e:i,d=r<t?r:t,u=r<t?t:r,h=n.getNoMergeCellWithCoordByIndex(l,d),g=n.getNoMergeCellWithCoordByIndex(c,u);return{startRow:e,startColumn:t,endRow:i,endColumn:r,rangeType:s,startY:(h==null?void 0:h.startY)||0,endY:(g==null?void 0:g.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(g==null?void 0:g.endX)||0}}function Re(n,o){const{range:e,primary:t,style:i}=n,r=Jt(o,e),s=t&&Qn(o,t);return{rangeWithCoord:r,primaryWithCoord:s,style:i}}function Qn(n,o){const{actualRow:e,actualColumn:t,isMerged:i,isMergedMainCell:r,startRow:s,startColumn:l,endRow:c,endColumn:d}=o,u=n.getNoMergeCellWithCoordByIndex(e,t),h=n.getNoMergeCellWithCoordByIndex(s,l),g=n.getNoMergeCellWithCoordByIndex(c,d);return{actualRow:e,actualColumn:t,isMerged:i,isMergedMainCell:r,startX:u.startX,startY:u.startY,endX:u.endX,endY:u.endY,mergeInfo:{startRow:s,startColumn:l,endRow:c,endColumn:d,startY:(h==null?void 0:h.startY)||0,endY:(g==null?void 0:g.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(g==null?void 0:g.endX)||0}}}const ks="__SpreadsheetHelperSelectionTempRect",gd=35;class Hs{constructor(o,e){y(this,"_startOffsetX",0);y(this,"_startOffsetY",0);y(this,"_relativeSelectionPositionRow",0);y(this,"_relativeSelectionPositionColumn",0);y(this,"_relativeSelectionRowLength",0);y(this,"_relativeSelectionColumnLength",0);y(this,"_scenePointerMoveSub");y(this,"_scenePointerUpSub");y(this,"_disabled",!1);y(this,"_helperSelection");y(this,"_scrollTimer");y(this,"_activeViewport");y(this,"_targetSelection",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});y(this,"_isInMergeState",!1);y(this,"_fillControlColors",[]);y(this,"_skeleton");y(this,"_scene");y(this,"_themeService");y(this,"_injector");y(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=R.withCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET,E.SheetSkeletonManagerService,this._injector.get(a.IUniverInstanceService),this._injector.get(R.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 R.SHEET_VIEWPORT_KEY.VIEW_MAIN:return o.endRow>=t.startRow&&o.endColumn>=t.startColumn;case R.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP:case R.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT:return o.endColumn>=t.startColumn&&o.startRow<t.startRow;case R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT:case R.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM:return o.endRow>=t.startRow&&o.startColumn<t.startColumn;case R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP:case R.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT:case R.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP:case R.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP:return o.startRow<t.startRow&&o.startColumn<t.startColumn}}_clearObserverEvent(){var o,e;(o=this._scenePointerMoveSub)==null||o.unsubscribe(),(e=this._scenePointerUpSub)==null||e.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null}_initialControl(){const{leftControl:o,rightControl:e,topControl:t,bottomControl:i}=this._control;[o,e,t,i].forEach(r=>{r.onPointerEnter$.subscribeEvent(()=>{var l;((l=this._injector.get(Ce,a.Quantity.OPTIONAL))==null?void 0:l.interceptor.fetchThroughInterceptors(Zo)(!1,null))!==!1&&r.setCursor(R.CURSOR_TYPE.MOVE)}),r.onPointerLeave$.subscribeEvent(()=>{r.resetCursor()}),r.onPointerDown$.subscribeEvent(this._controlPointerDownHandler.bind(this))})}_controlMoving(o,e){var N;const t=this._scene,i=t.getScrollXYInfoByViewport(R.Vector2.FromArray([o,e])),{scaleX:r,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(o,e,r,s,i),{row:c,column:d}=l,u=this._skeleton.getRowCount()-1,h=this._skeleton.getColumnCount()-1;let g=Math.max(0,c+this._relativeSelectionPositionRow),S=g+this._relativeSelectionRowLength;S>u&&(S=u,S-g<this._relativeSelectionRowLength&&(g=S-this._relativeSelectionRowLength));let f=Math.max(0,d+this._relativeSelectionPositionColumn),v=f+this._relativeSelectionColumnLength;v>h&&(v=h,v-f<this._relativeSelectionColumnLength&&(f=v-this._relativeSelectionColumnLength));const p=this._skeleton.worksheet.getCellInfoInMergeData(g,f),b=Re({range:{startRow:g,endRow:S,startColumn:f,endColumn:v},primary:p,style:null},this._skeleton),w=this._skeleton.getNoMergeCellWithCoordByIndex(g,f),T=this._skeleton.getNoMergeCellWithCoordByIndex(S,v),P=(w==null?void 0:w.startY)||0,M=(T==null?void 0:T.endY)||0,O=(w==null?void 0:w.startX)||0,D=(T==null?void 0:T.endX)||0;(N=this._helperSelection)==null||N.transformByState({left:O,top:P,width:D-O,height:M-P}),this._targetSelection={...b.rangeWithCoord},this._control.selectionMoving$.next(b.rangeWithCoord)}_controlPointerDownHandler(o){const{offsetX:e,offsetY:t}=o,i=this._scene,r=i.getCoordRelativeToViewport(R.Vector2.FromArray([e,t])),{x:s,y:l}=r,c=i.getScrollXYInfoByViewport(r),{scaleX:d,scaleY:u}=i.getAncestorScale(),h=this._skeleton.getCellIndexByOffset(s,l,d,u,c);this._startOffsetX=s,this._startOffsetY=l;const{row:g,column:S}=h,{startRow:f,startColumn:v,endRow:p,endColumn:C}=this._control.model;let b=0,w=0;g<f?b-=1:g>p&&(b+=1),S<v?w-=1:S>C&&(w+=1),this._relativeSelectionPositionRow=f-g+b,this._relativeSelectionPositionColumn=v-S+w,this._relativeSelectionRowLength=p-f,this._relativeSelectionColumnLength=C-v;const T=this._control.currentStyle,P=this._getScale();this.isHelperSelection&&(this._helperSelection=new R.Rect(ks,{stroke:T.stroke,strokeWidth:T.strokeWidth/P}),i.addObject(this._helperSelection));const M=i.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN),O=R.ScrollTimer.create(i);this._scrollTimer=O,O.startScroll(s,l,M),i.disableObjectsEvent(),this._scenePointerMoveSub=i.onPointerMove$.subscribeEvent(D=>{var L;if(this._disabled)return;const{offsetX:N,offsetY:k}=D;if(((L=this._injector.get(Ce,a.Quantity.OPTIONAL))==null?void 0:L.interceptor.fetchThroughInterceptors(Zo)(!1,null))===!1)return;const{x:V,y:W}=i.getCoordRelativeToViewport(R.Vector2.FromArray([N,k]));this._controlMoving(V,W),i.setCursor(R.CURSOR_TYPE.MOVE),O.scrolling(V,W,()=>{this._controlMoving(V,W)})}),this._scenePointerUpSub=i.onPointerUp$.subscribeEvent(()=>{var N,k,H,V;(N=this._helperSelection)==null||N.dispose();const D=this._scene;D.resetCursor(),this._clearObserverEvent(),D.enableObjectsEvent(),(k=this._scrollTimer)==null||k.dispose(),this._control.selectionMoveEnd$.next(this._targetSelection),(V=(H=this._selectionHooks).selectionMoveEnd)==null||V.call(H)})}_initialWidget(){const{topLeftWidget:o,topCenterWidget:e,topRightWidget:t,middleLeftWidget:i,middleRightWidget:r,bottomLeftWidget:s,bottomCenterWidget:l,bottomRightWidget:c}=this._control,d=[R.CURSOR_TYPE.NORTH_WEST_RESIZE,R.CURSOR_TYPE.NORTH_RESIZE,R.CURSOR_TYPE.NORTH_EAST_RESIZE,R.CURSOR_TYPE.WEST_RESIZE,R.CURSOR_TYPE.EAST_RESIZE,R.CURSOR_TYPE.SOUTH_WEST_RESIZE,R.CURSOR_TYPE.SOUTH_RESIZE,R.CURSOR_TYPE.SOUTH_EAST_RESIZE];[o,e,t,i,r,s,l,c].forEach((u,h)=>{u.onPointerEnter$.subscribeEvent(()=>{u.setCursor(d[h])}),u.onPointerLeave$.subscribeEvent(()=>{u.resetCursor()}),u.onPointerDown$.subscribeEvent(g=>{this._widgetPointerDownEvent(g,d[h])})})}_widgetPointerDownEvent(o,e){const t=this._scene,{offsetX:i,offsetY:r}=o,s=t.getCoordRelativeToViewport(R.Vector2.FromArray([i,r])),{x:l,y:c}=s;this._startOffsetX=i,this._startOffsetY=r;const{startRow:d,startColumn:u,endRow:h,endColumn:g}=this._control.model,S=Math.min(d,h),f=Math.min(u,g),v=Math.max(d,h),p=Math.max(u,g);this._relativeSelectionPositionRow=S,this._relativeSelectionPositionColumn=f,this._relativeSelectionRowLength=v-S,this._relativeSelectionColumnLength=p-f,e===R.CURSOR_TYPE.NORTH_WEST_RESIZE?(this._relativeSelectionPositionRow=v,this._relativeSelectionPositionColumn=p):e===R.CURSOR_TYPE.NORTH_RESIZE?this._relativeSelectionPositionRow=v:e===R.CURSOR_TYPE.NORTH_EAST_RESIZE?this._relativeSelectionPositionRow=v:e===R.CURSOR_TYPE.WEST_RESIZE?this._relativeSelectionPositionColumn=p:e===R.CURSOR_TYPE.SOUTH_WEST_RESIZE?this._relativeSelectionPositionColumn=p:e===R.CURSOR_TYPE.SOUTH_RESIZE&&(this._relativeSelectionPositionRow=S);const C=R.ScrollTimer.create(t),b=t.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN);C.startScroll(l,c,b),this._scrollTimer=C,t.disableObjectsEvent(),this._scenePointerMoveSub=t.onPointerMove$.subscribeEvent(w=>{const{offsetX:T,offsetY:P}=w,{x:M,y:O}=t.getCoordRelativeToViewport(R.Vector2.FromArray([T,P]));this._widgetMoving(M,O,e),t.setCursor(e),C.scrolling(M,O,()=>{this._widgetMoving(M,O,e)})}),this._scenePointerUpSub=t.onPointerUp$.subscribeEvent(()=>{var T,P,M;const w=this._scene;w.resetCursor(),this._clearObserverEvent(),w.enableObjectsEvent(),(T=this._scrollTimer)==null||T.dispose(),this._control.selectionScaled$.next(this._targetSelection),(M=(P=this._selectionHooks).selectionMoveEnd)==null||M.call(P)})}_widgetMoving(o,e,t){const i=this._scene,r=i.getScrollXYInfoByViewport(R.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:s,scaleY:l}=i.getAncestorScale(),c=this._skeleton.getCellIndexByOffset(o,e,s,l,r),{row:d,column:u}=c;let h=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,S=d,f=u;t===R.CURSOR_TYPE.NORTH_WEST_RESIZE?(h=d,g=u,S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn):t===R.CURSOR_TYPE.NORTH_RESIZE?(h=d,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength):t===R.CURSOR_TYPE.NORTH_EAST_RESIZE?(h=d,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,f=u):t===R.CURSOR_TYPE.WEST_RESIZE?(h=this._relativeSelectionPositionRow,g=u,S=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,f=this._relativeSelectionPositionColumn):t===R.CURSOR_TYPE.EAST_RESIZE?S=this._relativeSelectionPositionRow+this._relativeSelectionRowLength:t===R.CURSOR_TYPE.SOUTH_WEST_RESIZE?(h=this._relativeSelectionPositionRow,g=u,S=d,f=this._relativeSelectionPositionColumn):t===R.CURSOR_TYPE.SOUTH_RESIZE&&(h=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,S=d,f=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength);const v=this._swapPositions(h,g,S,f),p=this._skeleton.getCellWithMergeInfoByIndex(h,g),b=Re({range:v,primary:p,style:null},this._skeleton);this._targetSelection={...b.rangeWithCoord},this._control.updateRangeBySelectionWithCoord(b),this._control.selectionScaling$.next(this._targetSelection)}_initialAutoFill(){const{fillControl:o}=this._control;o.onPointerEnter$.subscribeEvent(e=>{this._injector.get(Ce).interceptor.fetchThroughInterceptors(Go)(!1,{x:e.offsetX,y:e.offsetY,skeleton:this._skeleton,scene:this._scene})&&o.setCursor(R.CURSOR_TYPE.CROSSHAIR)}),o.onPointerLeave$.subscribeEvent(()=>{o.resetCursor()}),o.onPointerDown$.subscribeEvent(this._autoFillForPointerdown.bind(this))}_autoFillMoving(o,e){var k,H,V;const t=this._scene,i=t.getViewportScrollXY(this._activeViewport),{scaleX:r,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(o,e,r,s,i),{row:c,column:d}=l,u=t.getCoordRelativeToViewport(R.Vector2.FromArray([o,e])),h=this._skeleton.getRowCount()-1,g=this._skeleton.getColumnCount()-1;let S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn,v=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,p=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength,C=!1,b=!0;if((d<f||d>p)&&c>=S&&c<=v){const W=this._fillRuler(d,f,p,this._relativeSelectionColumnLength,g);f=W.startRowOrColumn,p=W.endRowOrColumn,C=W.isLighten,b=!1}else if((c<S||c>v)&&d>=f&&d<=p){const W=this._fillRuler(c,S,v,this._relativeSelectionRowLength,h);S=W.startRowOrColumn,v=W.endRowOrColumn,C=W.isLighten}else if(Math.abs(this._startOffsetX-u.x-i.x)/2>Math.abs(this._startOffsetY-u.y-i.y)){const W=this._fillRuler(d,f,p,this._relativeSelectionColumnLength,g);f=W.startRowOrColumn,p=W.endRowOrColumn,C=W.isLighten,b=!1}else{const W=this._fillRuler(c,S,v,this._relativeSelectionRowLength,h);S=W.startRowOrColumn,v=W.endRowOrColumn,C=W.isLighten}const w=this._skeleton.getNoMergeCellWithCoordByIndex(S,f),T=this._skeleton.getNoMergeCellWithCoordByIndex(v,p),P=(w==null?void 0:w.startY)||0,M=(T==null?void 0:T.endY)||0,O=(w==null?void 0:w.startX)||0,D=(T==null?void 0:T.endX)||0;C?this._controlHandler((W,L)=>{const B=new a.ColorKit(this._fillControlColors[L]).lighten(gd).toRgbString();W.setProps({fill:B})}):this._controlHandler((W,L)=>{W.setProps({fill:this._fillControlColors[L]})});const N=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();S===v&&b===!0||f===p&&b===!1?(k=this._helperSelection)==null||k.hide():((H=this._helperSelection)==null||H.transformByState({left:O-N/2,top:P-N/2,width:D-O,height:M-P}),(V=this._helperSelection)==null||V.show()),this._targetSelection={startY:P,endY:M,startX:O,endX:D,startRow:S,endRow:v,startColumn:f,endColumn:p},this._control.selectionFilling$.next(this._targetSelection)}_autoFillForPointerdown(o){const{offsetX:e,offsetY:t}=o,i=this._scene,r=i.getCoordRelativeToViewport(R.Vector2.FromArray([e,t])),{x:s,y:l}=r;this._startOffsetX=s,this._startOffsetY=l;const{startRow:c,startColumn:d,endRow:u,endColumn:h}=this._control.model;this._isInMergeState=this._hasMergeInRange(c,d,u,h),this._relativeSelectionPositionRow=c,this._relativeSelectionPositionColumn=d,this._relativeSelectionRowLength=u-c,this._relativeSelectionColumnLength=h-d;const g=this._control.currentStyle;let S=g==null?void 0:g.stroke,f=g==null?void 0:g.strokeWidth;const v=qe(this._themeService);S==null&&(S=v.stroke),f==null&&(f=v.strokeWidth);const p=this._getScale();f/=p;const C=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/p,b=new a.ColorKit(S).darken(2).toRgbString();this.isHelperSelection&&(this._helperSelection=new R.Rect(ks,{stroke:b,strokeWidth:f+C/2}),i.addObject(this._helperSelection)),this._activeViewport=i.getActiveViewportByCoord(R.Vector2.FromArray([e,t]));const w=i.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN),T=R.ScrollTimer.create(i,this._activeViewport.viewportKey===R.SHEET_VIEWPORT_KEY.VIEW_MAIN?R.ScrollTimerType.ALL:R.ScrollTimerType.NONE);T.startScroll(s,l,w),this._scrollTimer=T,i.disableObjectsEvent(),this._controlHandler(P=>{this._fillControlColors.push(P.fill)}),this._scenePointerMoveSub=i.onPointerMove$.subscribeEvent(P=>{var W;const{offsetX:M,offsetY:O}=P,D=i.getActiveViewportByCoord(R.Vector2.FromArray([M,O]));if(!this._injector.get(Ce).interceptor.fetchThroughInterceptors(Go)(!1,{x:o.offsetX,y:o.offsetY,skeleton:this._skeleton,scene:this._scene}))return;const{x:k,y:H}=i.getCoordRelativeToViewport(R.Vector2.FromArray([M,O]));this._autoFillMoving(k,H),i.setCursor(R.CURSOR_TYPE.CROSSHAIR);const V=this._targetSelection;if(w&&D&&((W=this._activeViewport)==null?void 0:W.viewportKey)!==(D==null?void 0:D.viewportKey)){let L;V.startRow!==c?(T.scrollTimerType=R.ScrollTimerType.Y,L={...V,endRow:V.startRow}):V.endRow!==u?(T.scrollTimerType=R.ScrollTimerType.Y,L={...V,startRow:V.endRow}):V.startColumn!==d?(T.scrollTimerType=R.ScrollTimerType.X,L={...V,endColumn:V.startColumn}):(T.scrollTimerType=R.ScrollTimerType.X,L={...V,startColumn:V.endColumn}),this._isSelectionInViewport(L,D)&&(this._viewportMainScrollBarNeedResetPosition(T.scrollTimerType,this._activeViewport.viewportKey,D.viewportKey)&&w.scrollToBarPos({x:T.scrollTimerType===R.ScrollTimerType.X?0:void 0,y:T.scrollTimerType===R.ScrollTimerType.Y?0:void 0}),this._activeViewport=D)}T.scrolling(k,H,()=>{this._autoFillMoving(k,H)})}),this._scenePointerUpSub=i.onPointerUp$.subscribeEvent(()=>{var M,O;(M=this._helperSelection)==null||M.dispose();const P=this._scene;P.resetCursor(),this._clearObserverEvent(),P.enableObjectsEvent(),(O=this._scrollTimer)==null||O.dispose(),this._control.refreshSelectionFilled(this._targetSelection),this._isInMergeState=!1,this._controlHandler((D,N)=>{D.setProps({fill:this._fillControlColors[N]})}),this._fillControlColors=[]})}_viewportMainScrollBarNeedResetPosition(o,e,t){return o===R.ScrollTimerType.X&&(e===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||e===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP)&&(t===R.SHEET_VIEWPORT_KEY.VIEW_MAIN||t===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP)||o===R.ScrollTimerType.Y&&(e===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||e===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP)&&(t===R.SHEET_VIEWPORT_KEY.VIEW_MAIN||t===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)}_hasMergeInRange(o,e,t,i){return this._skeleton.worksheet.getMergedCellRange(o,e,t,i).length>0}_swapPositions(o,e,t,i){const r=Math.min(o,t),s=Math.min(e,i),l=Math.max(o,t),c=Math.max(e,i);return{startRow:r,startColumn:s,endRow:l,endColumn:c}}_controlHandler(o){const{leftControl:e,rightControl:t,topControl:i,bottomControl:r,backgroundControlTop:s,backgroundControlMiddleLeft:l,backgroundControlMiddleRight:c,backgroundControlBottom:d,fillControl:u}=this._control,h=[e,t,i,r,s,l,c,d,u];for(let g=0,S=h.length;g<S;g++){const f=h[g];o(f,g)}}_fillRuler(o,e,t,i,r){let s=!1;if(o<e)if(this._isInMergeState&&o<e){const l=e-o,c=i+1,d=Math.ceil(l/c);let u=e-d*c;u<0&&(u=e-(d-1)*c),e=u}else e=o;else if(o>=e&&o<=t)s=!0,this._isInMergeState||(t=o);else if(this._isInMergeState&&o>t){const l=o-t,c=i+1,d=Math.ceil(l/c);let u=t+d*c;u>r&&(u=t+(d-1)*c),t=u}else t=o;return{rowOrColumn:o,startRowOrColumn:e,endRowOrColumn:t,isLighten:s}}_getScale(){const{scaleX:o,scaleY:e}=this._scene.getAncestorScale();return Math.max(o,e)}}var qo=(n=>(n.Selection="__SpreadsheetSelectionShape__",n.top="__SpreadsheetSelectionTopControl__",n.bottom="__SpreadsheetSelectionBottomControl__",n.left="__SpreadsheetSelectionShapeLeftControl__",n.right="__SpreadsheetSelectionShapeRightControl__",n.backgroundTop="__SpreadsheetSelectionBackgroundControlTop__",n.backgroundMiddleLeft="__SpreadsheetSelectionBackgroundControlMiddleLeft__",n.backgroundMiddleRight="__SpreadsheetSelectionBackgroundControlMiddleRight__",n.backgroundBottom="__SpreadsheetSelectionBackgroundControlBottom__",n.fill="__SpreadsheetSelectionFillControl__",n.fillTopLeft="__SpreadsheetSelectionFillControlTopLeft__",n.fillBottomRight="__SpreadsheetSelectionFillControlBottomRight__",n.fillTopLeftInner="__SpreadsheetSelectionFillControlTopLeftInner__",n.fillBottomRightInner="__SpreadsheetSelectionFillControlBottomRightInner__",n.lineMain="__SpreadsheetDragLineMainControl__",n.lineContent="__SpreadsheetDragLineContentControl__",n.line="__SpreadsheetDragLineControl__",n.dash="__SpreadsheetDragDashControl__",n.rowHeaderBackground="__SpreadSheetSelectionRowHeaderBackground__",n.rowHeaderBorder="__SpreadSheetSelectionRowHeaderBorder__",n.rowHeaderGroup="__SpreadSheetSelectionRowHeaderGroup__",n.columnHeaderBackground="__SpreadSheetSelectionColumnHeaderBackground__",n.columnHeaderBorder="__SpreadSheetSelectionColumnHeaderBorder__",n.columnHeaderGroup="__SpreadSheetSelectionColumnHeaderGroup__",n.topLeftWidget="__SpreadSheetSelectionTopLeftWidget__",n.topCenterWidget="__SpreadSheetSelectionTopCenterWidget__",n.topRightWidget="__SpreadSheetSelectionTopRightWidget__",n.middleLeftWidget="__SpreadSheetSelectionMiddleLeftWidget__",n.middleRightWidget="__SpreadSheetSelectionMiddleRightWidget__",n.bottomLeftWidget="__SpreadSheetSelectionBottomLeftWidget__",n.bottomCenterWidget="__SpreadSheetSelectionBottomCenterWidget__",n.bottomRightWidget="__SpreadSheetSelectionBottomRightWidget__",n))(qo||{});const Vs=.3;class Jn extends a.Disposable{constructor(e,t,i,r){var s,l,c,d;super();y(this,"_isHelperSelection",!0);y(this,"_enableAutoFill",!0);y(this,"_showAutoFill",!1);y(this,"_highlightHeader",!0);y(this,"_selectionRenderModel");y(this,"_leftBorder");y(this,"_rightBorder");y(this,"_topBorder");y(this,"_bottomBorder");y(this,"_backgroundControlTop");y(this,"_backgroundControlBottom");y(this,"_backgroundControlMiddleLeft");y(this,"_backgroundControlMiddleRight");y(this,"_autoFillControl");y(this,"_selectionShapeGroup");y(this,"_rowHeaderBackground");y(this,"_rowHeaderBorder");y(this,"_rowHeaderGroup");y(this,"_columnHeaderBackground");y(this,"_columnHeaderBorder");y(this,"_columnHeaderGroup");y(this,"_dashedRect");y(this,"_topLeftWidget");y(this,"_topCenterWidget");y(this,"_topRightWidget");y(this,"_middleLeftWidget");y(this,"_middleRightWidget");y(this,"_bottomLeftWidget");y(this,"_bottomCenterWidget");y(this,"_bottomRightWidget");y(this,"_defaultStyle");y(this,"_currentStyle");y(this,"_rowHeaderWidth",0);y(this,"_columnHeaderHeight",0);y(this,"_widgetRects",[]);y(this,"_controlExtension");y(this,"_dispose$",new A.BehaviorSubject(this));y(this,"dispose$",this._dispose$.asObservable());y(this,"selectionMoving$",new A.Subject);y(this,"selectionMoveEnd$",new A.Subject);y(this,"selectionScaling$",new A.Subject);y(this,"selectionScaled$",new A.Subject);y(this,"selectionFilling$",new A.Subject);y(this,"_selectionFilled$",new A.Subject);y(this,"selectionFilled$",this._selectionFilled$.asObservable());y(this,"_antLineOffset",0);y(this,"_antRequestNewFrame",-1);this._scene=e,this._zIndex=t,this._themeService=i,this._enableAutoFill=(s=r==null?void 0:r.enableAutoFill)!=null?s:!0,this._highlightHeader=(l=r==null?void 0:r.highlightHeader)!=null?l:!0,this._rowHeaderWidth=(c=r==null?void 0:r.rowHeaderWidth)!=null?c:0,this._columnHeaderHeight=(d=r==null?void 0:r.columnHeaderHeight)!=null?d:0,this._initializeSheetBody(),this._initialHeader()}_initializeSheetBody(){this._defaultStyle=qe(this._themeService),this._currentStyle=qe(this._themeService),this._selectionRenderModel=new md;const e=this._zIndex;this._leftBorder=new R.Rect("__SpreadsheetSelectionShapeLeftControl__"+e,{zIndex:e}),this._rightBorder=new R.Rect("__SpreadsheetSelectionShapeRightControl__"+e,{zIndex:e}),this._topBorder=new R.Rect("__SpreadsheetSelectionTopControl__"+e,{zIndex:e}),this._bottomBorder=new R.Rect("__SpreadsheetSelectionBottomControl__"+e,{zIndex:e}),this._backgroundControlTop=new R.Rect("__SpreadsheetSelectionBackgroundControlTop__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlBottom=new R.Rect("__SpreadsheetSelectionBackgroundControlBottom__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleLeft=new R.Rect("__SpreadsheetSelectionBackgroundControlMiddleLeft__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleRight=new R.Rect("__SpreadsheetSelectionBackgroundControlMiddleRight__"+e,{zIndex:e-1,evented:!1}),this._autoFillControl=new R.Rect("__SpreadsheetSelectionFillControl__"+e,{zIndex:e+1}),this._autoFillControl.hide(),this._dashedRect=new R.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 R.Group("__SpreadsheetSelectionShape__"+e,...t,...this._widgetRects),this._selectionShapeGroup.hide(),this._selectionShapeGroup.evented=!1,this._selectionShapeGroup.zIndex=e;const i=this.getScene();i.addObject(this._selectionShapeGroup,Fi),this.disposeWithMe(a.toDisposable(i.onTransformChange$.subscribeEvent(r=>{r.type===R.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&(this._updateLayoutOfSelectionControl(this._currentStyle),this._updateControlCoord())})))}_initialHeader(){const e=this._zIndex;this._rowHeaderBackground=new R.Rect("__SpreadSheetSelectionRowHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderBorder=new R.Rect("__SpreadSheetSelectionRowHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderGroup=new R.Group("__SpreadSheetSelectionRowHeaderGroup__"+e,this._rowHeaderBackground,this._rowHeaderBorder),this._rowHeaderGroup.hide(),this._rowHeaderGroup.evented=!1,this._rowHeaderGroup.zIndex=e,this._columnHeaderBackground=new R.Rect("__SpreadSheetSelectionColumnHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderBorder=new R.Rect("__SpreadSheetSelectionColumnHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderGroup=new R.Group("__SpreadSheetSelectionColumnHeaderGroup__"+e,this._columnHeaderBackground,this._columnHeaderBorder),this._columnHeaderGroup.hide(),this._columnHeaderGroup.evented=!1,this._columnHeaderGroup.zIndex=e,this.getScene().addObjects([this._rowHeaderGroup,this._columnHeaderGroup],hd)}_initialWidget(){const e=this._zIndex;return this._topLeftWidget=new R.Rect("__SpreadSheetSelectionTopLeftWidget__"+e,{zIndex:e+1}),this._topCenterWidget=new R.Rect("__SpreadSheetSelectionTopCenterWidget__"+e,{zIndex:e+1}),this._topRightWidget=new R.Rect("__SpreadSheetSelectionTopRightWidget__"+e,{zIndex:e+1}),this._middleLeftWidget=new R.Rect("__SpreadSheetSelectionMiddleLeftWidget__"+e,{zIndex:e+1}),this._middleRightWidget=new R.Rect("__SpreadSheetSelectionMiddleRightWidget__"+e,{zIndex:e+1}),this._bottomLeftWidget=new R.Rect("__SpreadSheetSelectionBottomLeftWidget__"+e,{zIndex:e+1}),this._bottomCenterWidget=new R.Rect("__SpreadSheetSelectionBottomCenterWidget__"+e,{zIndex:e+1}),this._bottomRightWidget=new R.Rect("__SpreadSheetSelectionBottomRightWidget__"+e,{zIndex:e+1}),[this._topLeftWidget,this._topCenterWidget,this._topRightWidget,this._middleLeftWidget,this._middleRightWidget,this._bottomLeftWidget,this._bottomCenterWidget,this._bottomRightWidget]}get zIndex(){return this._zIndex}get leftControl(){return this._leftBorder}get rightControl(){return this._rightBorder}get topControl(){return this._topBorder}get bottomControl(){return this._bottomBorder}get fillControl(){return this._autoFillControl}get backgroundControlTop(){return this._backgroundControlTop}get backgroundControlBottom(){return this._backgroundControlBottom}get backgroundControlMiddleLeft(){return this._backgroundControlMiddleLeft}get backgroundControlMiddleRight(){return this._backgroundControlMiddleRight}get selectionShape(){return this._selectionShapeGroup}get columnHeaderGroup(){return this._columnHeaderGroup}get rowHeaderGroup(){return this._rowHeaderGroup}get selectionShapeGroup(){return this._selectionShapeGroup}get model(){return this._selectionRenderModel}get topLeftWidget(){return this._topLeftWidget}get topCenterWidget(){return this._topCenterWidget}get topRightWidget(){return this._topRightWidget}get middleLeftWidget(){return this._middleLeftWidget}get middleRightWidget(){return this._middleRightWidget}get bottomLeftWidget(){return this._bottomLeftWidget}get bottomCenterWidget(){return this._bottomCenterWidget}get bottomRightWidget(){return this._bottomRightWidget}get themeService(){return this._themeService}get selectionModel(){return this._selectionRenderModel}set selectionModel(e){this._selectionRenderModel=e}get currentStyle(){return this._currentStyle}set currentStyle(e){this._currentStyle=e}get dashedRect(){return this._dashedRect}get isHelperSelection(){return this._isHelperSelection}get rowHeaderWidth(){return this._rowHeaderWidth}set rowHeaderWidth(e){this._rowHeaderWidth=e}get columnHeaderHeight(){return this._columnHeaderHeight}set columnHeaderHeight(e){this._columnHeaderHeight=e}setControlExtension(e){this._controlExtension=new Hs(this,e)}setControlExtensionDisable(e){this._controlExtension&&this._controlExtension.setDisabled(e)}setEvent(e){this.leftControl.evented=e,this.rightControl.evented=e,this.topControl.evented=e,this.bottomControl.evented=e}refreshSelectionFilled(e){this._selectionFilled$.next(e)}_updateLayoutOfSelectionControl(e){e&&(this.currentStyle=Object.assign({},this._defaultStyle,e));const t=this.currentStyle,{stroke:i,widgets:r,autofillStroke:s,strokeDash:l,isAnimationDash:c}=t;let d=t.autofillSize,u=t.strokeWidth,h=t.autofillStrokeWidth;const g=this._getScale(),S=(u+m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH)/2/g;u/=g,d/=g,h/=g<1?1:g;const f=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/g,v=R.FIX_ONE_PIXEL_BLUR_OFFSET/g,{startX:p,startY:C,endX:b,endY:w}=this._selectionRenderModel;if(this.leftControl.transformByState({height:w-C,left:-S+v,width:u,strokeWidth:f,top:-f/2+v}),this.leftControl.setProps({fill:i,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.rightControl.transformByState({height:w-C,left:b-p-S+v,width:u,strokeWidth:f,top:-f/2+v}),this.rightControl.setProps({fill:i,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.topControl.transformByState({width:b-p+u,top:-S+v,left:-S+v,height:u,strokeWidth:f}),this.topControl.setProps({fill:i,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.bottomControl.transformByState({width:b-p+u,top:w-C-S+v,height:u,left:-S+v,strokeWidth:f}),this.bottomControl.setProps({fill:i,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),l==null)this.dashedRect.hide(),this._stopAntLineAnimation();else{const T=t.strokeWidth*2/g;this.dashedRect.transformByState({height:w-C,width:b-p,strokeWidth:T,left:-T/2+v,top:-T/2+v}),this.dashedRect.setProps({strokeDashArray:[0,l/g]}),this._stopAntLineAnimation(),c!==!1&&this._startAntLineAnimation(),this.dashedRect.show()}if(this._showAutoFill=this._showAutoFill&&this._enableAutoFill,this._showAutoFill&&!this._hasWidgets(r)){const T={fill:i,stroke:s,strokeScaleEnabled:!1},P={width:d-h,height:d-h,left:b-p-d/2+h/2-v,top:w-C-d/2+h/2-v,strokeWidth:h};this._autoFillControl.setProps(T),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,i=0,r,s){this._rowHeaderWidth=t,this._columnHeaderHeight=i,this.updateRangeBySelectionWithCoord({rangeWithCoord:e,primaryWithCoord:s,style:r}),r&&this.updateStyle(r)}updateCurrCell(e){this._showAutoFill=e!==null,this._selectionRenderModel.setCurrentCell(e)}clearHighlight(){this._showAutoFill=!1,this._selectionRenderModel.clearCurrentCell(),this._updateLayoutOfSelectionControl(this._currentStyle)}getScene(){return this._scene}dispose(){var e,t,i,r,s,l,c,d,u,h,g,S,f,v,p,C,b,w,T,P,M,O,D,N,k;(e=this._leftBorder)==null||e.dispose(),(t=this._rightBorder)==null||t.dispose(),(i=this._topBorder)==null||i.dispose(),(r=this._bottomBorder)==null||r.dispose(),(s=this._backgroundControlTop)==null||s.dispose(),(l=this._backgroundControlMiddleLeft)==null||l.dispose(),(c=this._backgroundControlMiddleRight)==null||c.dispose(),(d=this._backgroundControlBottom)==null||d.dispose(),this._autoFillControl.dispose(),(u=this._selectionShapeGroup)==null||u.dispose(),(h=this._rowHeaderBackground)==null||h.dispose(),(g=this._rowHeaderBorder)==null||g.dispose(),(S=this._rowHeaderGroup)==null||S.dispose(),(f=this._rowHeaderBackground)==null||f.dispose(),(v=this._columnHeaderBackground)==null||v.dispose(),(p=this._columnHeaderBorder)==null||p.dispose(),(C=this._columnHeaderGroup)==null||C.dispose(),(b=this._topLeftWidget)==null||b.dispose(),(w=this._topCenterWidget)==null||w.dispose(),(T=this._topRightWidget)==null||T.dispose(),(P=this._middleLeftWidget)==null||P.dispose(),(M=this._middleRightWidget)==null||M.dispose(),(O=this._bottomLeftWidget)==null||O.dispose(),(D=this._bottomCenterWidget)==null||D.dispose(),(N=this._bottomRightWidget)==null||N.dispose(),(k=this._controlExtension)==null||k.dispose(),super.dispose(),this._dispose$.next(this),this._dispose$.complete()}getCurrentCellInfo(){const e=this.model.currentCell;if(e){let t;if(e.isMerged){const i=e.mergeInfo;t={startRow:i.startRow,endRow:i.endRow,startColumn:i.startColumn,endColumn:i.endColumn,startX:i.startX,endX:i.endX,startY:i.startY,endY:i.endY}}else{const{actualRow:i,actualColumn:r,startX:s,endX:l,startY:c,endY:d}=e;t={startRow:i,endRow:i,startColumn:r,endColumn:r,startX:s,endX:l,startY:c,endY:d}}return t}}getValue(){return{...this._selectionRenderModel.getValue(),style:this._currentStyle}}getRange(){return this._selectionRenderModel.getValue().rangeWithCoord}enableHelperSelection(){this._isHelperSelection=!0}disableHelperSelection(){this._isHelperSelection=!1}_updateHeaderBackground(e){const{startX:t,startY:i,endX:r,endY:s,rangeType:l}=this._selectionRenderModel,c=this._currentStyle,d=this._getScale(),{stroke:u,rowHeaderFill:h=c.rowHeaderFill,rowHeaderStroke:g=c.rowHeaderStroke,columnHeaderFill:S=c.columnHeaderFill,columnHeaderStroke:f=c.columnHeaderStroke}=e;let{rowHeaderStrokeWidth:v=c.rowHeaderStrokeWidth,columnHeaderStrokeWidth:p=c.columnHeaderStrokeWidth}=e;v/=d,p/=d;const C=this._rowHeaderWidth,b=this._columnHeaderHeight;if(this._highlightHeader&&b>0){let w=S;l===a.RANGE_TYPE.COLUMN&&(w=new a.ColorKit(u).setAlpha(Vs).toString()),this._columnHeaderBackground.setProps({fill:w}),this._columnHeaderBackground.resize(r-t,b),this._columnHeaderBorder.setProps({fill:f}),this._columnHeaderBorder.transformByState({width:r-t,height:p,top:b-p+1/d}),this._columnHeaderGroup.show(),this._columnHeaderGroup.translate(t,0)}else this._columnHeaderGroup.hide();if(this._columnHeaderGroup.makeDirty(!0),this._highlightHeader&&C>0){let w=h;l===a.RANGE_TYPE.ROW&&(w=new a.ColorKit(u).setAlpha(Vs).toString()),this._rowHeaderBackground.setProps({fill:w}),this._rowHeaderBackground.resize(C,s-i),this._rowHeaderBorder.setProps({fill:g}),this._rowHeaderBorder.transformByState({width:v,height:s-i,left:C-v+1/d}),this._rowHeaderGroup.show(),this._rowHeaderGroup.translate(0,i)}else this._rowHeaderGroup.hide();this._rowHeaderGroup.makeDirty(!0)}_updateBackgroundControl(e){const{startX:t,startY:i,endX:r,endY:s}=this._selectionRenderModel,l=this._getScale(),{fill:c=e.fill}=e;let{strokeWidth:d}=e;d/=l;const u=this._selectionRenderModel.highlightToSelection();if(!u){this._backgroundControlTop.resize(r-t,s-i),this._backgroundControlTop.setProps({fill:c}),this._backgroundControlBottom.resize(0,0),this._backgroundControlMiddleLeft.resize(0,0),this._backgroundControlMiddleRight.resize(0,0);return}const{startX:h,startY:g,endX:S,endY:f}=u,v=d/2,p={left:-v,top:-v,width:r-t+v*2,height:g-i+v};p.height<0&&(p.width=0,p.height=0),this._backgroundControlTop.transformByState(p);const C={left:-v,top:g-i,width:h-t+v,height:f-g};C.width<0&&(C.width=0,C.height=0),this._backgroundControlMiddleLeft.transformByState(C);const b={left:S-t-v,top:g-i,width:r-S+v*2,height:f-g};b.width<0&&(b.width=0,b.height=0),this._backgroundControlMiddleRight.transformByState(b);const w={left:-v,top:f-i,width:r-t+v*2,height:s-f+v};w.height<0&&(w.width=0,w.height=0),this._backgroundControlBottom.transformByState(w),this._backgroundControlTop.setProps({fill:c}),this._backgroundControlMiddleLeft.setProps({fill:c}),this._backgroundControlMiddleRight.setProps({fill:c}),this._backgroundControlBottom.setProps({fill:c})}_updateWidgets(e){const{startX:t,startY:i,endX:r,endY:s}=this._selectionRenderModel,{stroke:l=e.stroke,widgets:c=e.widgets,widgetStroke:d=e.widgetStroke}=e,u=this._getScale();let{widgetSize:h,widgetStrokeWidth:g}=e;h/=u,g/=u;const S={left:-h/2+g/2,center:(r-t)/2-h/2+g/2,right:r-t-h/2+g/2,top:-h/2,middle:(s-i)/2-h/2,bottom:s-i-h/2+g/2},f=h-g;this._widgetRects.forEach(v=>{v.setProps({fill:l,stroke:d})}),c.tl===!0?(this._topLeftWidget.transformByState({height:f,width:f,left:S.left,top:S.top,strokeWidth:g}),this._topLeftWidget.show()):this._topLeftWidget.hide(),c.tc===!0?(this._topCenterWidget.transformByState({height:f,width:f,left:S.center,top:S.top,strokeWidth:g}),this._topCenterWidget.show()):this._topCenterWidget.hide(),c.tr===!0?(this._topRightWidget.transformByState({height:f,width:f,left:S.right,top:S.top,strokeWidth:g}),this._topRightWidget.show()):this._topRightWidget.hide(),c.ml===!0?(this._middleLeftWidget.transformByState({height:f,width:f,left:S.left,top:S.middle,strokeWidth:g}),this._middleLeftWidget.show()):this._middleLeftWidget.hide(),c.mr===!0?(this._middleRightWidget.transformByState({height:f,width:f,left:S.right,top:S.middle,strokeWidth:g}),this._middleRightWidget.show()):this._middleRightWidget.hide(),c.bl===!0?(this._bottomLeftWidget.transformByState({height:f,width:f,left:S.left,top:S.bottom,strokeWidth:g}),this._bottomLeftWidget.show()):this._bottomLeftWidget.hide(),c.bc===!0?(this._bottomCenterWidget.transformByState({height:f,width:f,left:S.center,top:S.bottom,strokeWidth:g}),this._bottomCenterWidget.show()):this._bottomCenterWidget.hide(),c.br===!0?(this._bottomRightWidget.transformByState({height:f,width:f,left:S.right,top:S.bottom,strokeWidth:g}),this._bottomRightWidget.show()):this._bottomRightWidget.hide()}_hasWidgets(e){if(e==null)return!1;const t=Object.keys(e);if(t.length===0)return!1;for(const i of t)if(e[i]===!0)return!0;return!1}_getScale(){const{scaleX:e,scaleY:t}=this._scene.getAncestorScale();return Math.max(e,t)}_stopAntLineAnimation(){this._antLineOffset=0,R.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=R.requestNewFrame(()=>{this._startAntLineAnimation()})}}class Sd extends R.Layer{render(o,e=!1){const t=a.Tools.now();return super.render(o,e),this._afterRender(t),this}_afterRender(o){this.scene.getEngine().renderFrameTimeMetric$.next(["selectionLayer",a.Tools.now()-o])}}const Ce=a.createIdentifier("univer.sheet.selection-render-service");class Qo extends a.Disposable{constructor(e,t,i,r,s){super();y(this,"_downObserver");y(this,"_scenePointerMoveSub");y(this,"_scenePointerUpSub");y(this,"_controlFillConfig$",new A.BehaviorSubject(null));y(this,"controlFillConfig$",this._controlFillConfig$.asObservable());y(this,"_selectionControls",[]);y(this,"_startRangeWhenPointerDown",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});y(this,"_activeControlIndex",-1);y(this,"_startViewportPosX",0);y(this,"_startViewportPosY",0);y(this,"_scrollTimer");y(this,"_cancelDownSubscription");y(this,"_cancelUpSubscription");y(this,"_skeleton");y(this,"_scene");y(this,"_highlightHeader",!0);y(this,"_rangeType",a.RANGE_TYPE.NORMAL);y(this,"_selectionStyle");y(this,"_remainLastEnabled",!1);y(this,"_skipLastEnabled",!1);y(this,"_singleSelectionEnabled",!1);y(this,"_selectionMoveEnd$",new A.BehaviorSubject([]));y(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());y(this,"_selectionMoving$",new A.Subject);y(this,"selectionMoving$",this._selectionMoving$.asObservable());y(this,"_selectionMoveStart$",new A.Subject);y(this,"selectionMoveStart$",this._selectionMoveStart$.asObservable());y(this,"_selectionMoving",!1);y(this,"_selectionTheme");y(this,"_activeViewport");y(this,"interceptor",new a.InterceptorManager({RANGE_MOVE_PERMISSION_CHECK:Zo,RANGE_FILL_PERMISSION_CHECK:Go}));y(this,"_escapeShortcutDisposable",null);this._injector=e,this._themeService=t,this._shortcutService=i,this._sheetSkeletonManagerService=r,this.contextService=s,this._initSelectionThemeFromThemeService(),this._initMoving()}get selectionMoving(){return this._selectionMoving}get _shouldDetectMergedCells(){return this._rangeType===a.RANGE_TYPE.NORMAL}_initMoving(){this.disposeWithMe(this._selectionMoving$.subscribe(()=>{this._selectionMoving=!0})),this.disposeWithMe(this._selectionMoveEnd$.subscribe(()=>{this._selectionMoving=!1}))}_setSelectionStyle(e){this._selectionStyle=e}getViewPort(){return this._activeViewport}setSingleSelectionEnabled(e=!1){this._singleSelectionEnabled=e}newSelectionControl(e,t,i){const r=this.getSelectionControls().length,{rowHeaderWidth:s,columnHeaderHeight:l}=t,c=new Jn(e,r,this._selectionTheme,{highlightHeader:this._highlightHeader,rowHeaderWidth:s,columnHeaderHeight:l});this._selectionControls.push(c);const d=Re(i,t);return c.updateRangeBySelectionWithCoord(d,t),c.setControlExtension({skeleton:t,scene:e,themeService:this._selectionTheme,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),c}resetSelectionsByModelData(e){const t=this.getSelectionControls(),i=this._skeleton;if(!(!t||!i)){for(let r=0,s=e.length;r<s;r++){const l=e[r],c=Re(l,this._skeleton),d=t[r];d?d.updateRangeBySelectionWithCoord(c,i):this.isSelectionEnabled()&&this.newSelectionControl(this._scene,i,l)}e.length<t.length&&t.splice(e.length).forEach(s=>s.dispose())}}refreshSelectionMoveStart(){this._selectionMoveStart$.next(this.getSelectionDataWithStyle())}refreshSelectionMoveEnd(){this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}_initSelectionThemeFromThemeService(){const e=this._themeService.getCurrentTheme();this._selectionTheme=new a.ThemeService,this._selectionTheme.setTheme(e)}setSelectionTheme(e){this._selectionTheme.setTheme(e)}_changeRuntime(e,t,i){this._skeleton=e,this._scene=t,this._activeViewport=i||(t==null?void 0:t.getViewports()[0]),t.findLayerByZIndex(Fi)||t.addLayer(new Sd(t,[],Fi))}getSkeleton(){return this._skeleton}getSelectionDataWithStyle(){const e=this._selectionControls;if(this._skeleton.worksheet){const[t,i]=this._skeleton.getLocation();return e.map(r=>{const s=r.getValue();return s.rangeWithCoord.sheetId=i,s.rangeWithCoord.unitId=t,s})}return[]}getSelectionControls(){return this._selectionControls}_addSelectionControlByModelData(e){var l;const t=this._skeleton,i=(l=e.style)!=null?l:qe(this._selectionTheme),r=this._scene;return e.style=i,this.newSelectionControl(r,t,e)}_clearAllSelectionControls(){const e=this._selectionControls;for(const t of e)t.dispose();this._selectionControls.length=0}_getFreeze(){var t;return(t=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:t.skeleton.getWorksheetConfig().freeze}_getViewportByCell(e,t){if(e===void 0||t===void 0)return null;const i=this._getFreeze();if(!i||i.startRow<=0&&i.startColumn<=0)return this._scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e>i.startRow&&t>i.startColumn)return this._scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e<=i.startRow&&t<=i.startColumn)return this._scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP);if(e<=i.startRow&&t>i.startColumn)return this._scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(e>i.startRow&&t<=i.startColumn)return this._scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)}getActiveRange(){const e=this.getSelectionControls(),t=e&&e[e.length-1].model;return t&&{startRow:t.startRow,startColumn:t.startColumn,endRow:t.endRow,endColumn:t.endColumn}}setActiveSelectionIndex(e){this._activeControlIndex=e}resetActiveSelectionIndex(){this._activeControlIndex=-1}getActiveSelectionControl(){const e=this.getSelectionControls();if(e)return this._activeControlIndex<0?e[e.length-1]:e[this._activeControlIndex]}endSelection(){var e;this._clearUpdatingListeners(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),(e=this._escapeShortcutDisposable)==null||e.dispose(),this._escapeShortcutDisposable=null}_reset(){var e;this._clearAllSelectionControls(),(e=this._downObserver)==null||e.unsubscribe(),this._downObserver=null}_setupPointerMoveListener(e,t,i,r=R.ScrollTimerType.ALL,s,l){var f,v;let c=0,d=0,u=s,h=l;this._scrollTimer=R.ScrollTimer.create(this._scene,r),this._scrollTimer.startScroll((f=e==null?void 0:e.left)!=null?f:0,(v=e==null?void 0:e.top)!=null?v:0,e);const g=this._scene,S=g.getActiveViewportByCoord(R.Vector2.FromArray([s,l]));this._scenePointerMoveSub=g.onPointerMove$.subscribeEvent(p=>{var V,W,L,B,U,F,z,X,j;const{offsetX:C,offsetY:b}=p,{x:w,y:T}=g.getCoordRelativeToViewport(R.Vector2.FromArray([C,b]));this._movingHandler(w,T,t,i);let P=w,M=T;const O=this.getActiveSelectionControl(),D=this._getFreeze(),N=O==null?void 0:O.model,k=(V=g.getActiveViewportByCoord(R.Vector2.FromArray([C,b])))!=null?V:this._getViewportByCell(N==null?void 0:N.endRow,N==null?void 0:N.endColumn);if((()=>{if(!S||!k||!e)return!1;const Q=[R.SHEET_VIEWPORT_KEY.VIEW_MAIN,R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,R.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT];return Q.includes(S.viewportKey)&&Q.includes(k.viewportKey)})()){if(!S||!k||!e)return!1;const Q=u<e.left&&w>e.left||u>e.left&&w<e.left,oe=h<e.top&&T>e.top||h>e.top&&T<e.top;Q&&(c+=1),oe&&(d+=1);const re=S.viewportKey,le=k.viewportKey;if(re===R.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP)b<e.top&&((W=N==null?void 0:N.endRow)!=null?W:0)<((L=D==null?void 0:D.startRow)!=null?L:0)?M=e.top:oe&&d