UNPKG

@univerjs/sheets-ui

Version:

Spreadsheet UI layer for Univer Sheets.

1 lines • 956 kB
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/docs-ui"),require("@univerjs/core"),require("@univerjs/ui"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/docs"),require("@univerjs/protocol"),require("react"),require("@univerjs/design"),require("react/jsx-runtime"),require("@univerjs/engine-formula"),require("@univerjs/telemetry"),require("rxjs/operators")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/docs-ui`,`@univerjs/core`,`@univerjs/ui`,`@univerjs/engine-render`,`@univerjs/sheets`,`rxjs`,`@univerjs/docs`,`@univerjs/protocol`,`react`,`@univerjs/design`,`react/jsx-runtime`,`@univerjs/engine-formula`,`@univerjs/telemetry`,`rxjs/operators`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsUi={},e.UniverDocsUi,e.UniverCore,e.UniverUi,e.UniverEngineRender,e.UniverSheets,e.rxjs,e.UniverDocs,e.UniverProtocol,e.React,e.UniverDesign,e.React,e.UniverEngineFormula,e.UniverTelemetry,e.rxjs.operators))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var h=Object.create,g=Object.defineProperty,_=Object.getOwnPropertyDescriptor,v=Object.getOwnPropertyNames,y=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty,x=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=v(t),a=0,o=i.length,s;a<o;a++)s=i[a],!b.call(e,s)&&s!==n&&g(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=_(t,s))||r.enumerable});return e};l=((e,t,n)=>(n=e==null?{}:h(y(e)),x(t||!e||!e.__esModule?g(n,`default`,{value:e,enumerable:!0}):n,e)))(l,1);function S(e,n){if(e==null)return;let r=n.getRenderById(e);if(r==null)return;let{mainComponent:i,scene:a,engine:o,components:s}=r;return{document:i,docBackground:s.get(t.DOCS_VIEW_KEY.BACKGROUND),scene:a,engine:o}}function C(e){return e.getContextValue(n.FOCUSING_SHEET)}function w(e){return e.getContextValue(n.FOCUSING_SHEET)&&e.getContextValue(n.FOCUSING_UNIVER_EDITOR)&&!e.getContextValue(n.EDITOR_ACTIVATED)&&!e.getContextValue(n.FOCUSING_COMMON_DRAWINGS)}function T(e){return e.getContextValue(n.FOCUSING_SHEET)&&e.getContextValue(n.FOCUSING_UNIVER_EDITOR)&&!e.getContextValue(n.FOCUSING_COMMON_DRAWINGS)}function E(e){return e.getContextValue(n.FOCUSING_SHEET)&&e.getContextValue(n.FOCUSING_UNIVER_EDITOR)&&!e.getContextValue(n.EDITOR_ACTIVATED)&&!e.getContextValue(n.FOCUSING_FX_BAR_EDITOR)&&!e.getContextValue(n.FOCUSING_COMMON_DRAWINGS)}function D(e){return e.getContextValue(n.FOCUSING_SHEET)&&e.getContextValue(n.FOCUSING_UNIVER_EDITOR)&&e.getContextValue(n.EDITOR_ACTIVATED)}function O(e){return e.getContextValue(n.FOCUSING_UNIVER_EDITOR)&&e.getContextValue(n.EDITOR_ACTIVATED)}function k(e){return e.getContextValue(n.FOCUSING_FX_BAR_EDITOR)&&e.getContextValue(n.FOCUSING_UNIVER_EDITOR)}function A(e){return e.getContextValue(n.FOCUSING_SHEET)&&e.getContextValue(n.EDITOR_ACTIVATED)&&e.getContextValue(n.FOCUSING_EDITOR_INPUT_FORMULA)&&e.getContextValue(n.FOCUSING_UNIVER_EDITOR)}function j(e){return e.getContextValue(n.FOCUSING_SHEET)&&e.getContextValue(n.FOCUSING_UNIVER_EDITOR)&&e.getContextValue(n.EDITOR_ACTIVATED)&&!e.getContextValue(n.FOCUSING_EDITOR_INPUT_FORMULA)&&!e.getContextValue(n.FOCUSING_EDITOR_STANDALONE)}function M(e){let t=[],n=[],r=[];return e.forEach(e=>{t=t.concat(e.rows),n=n.concat(e.cols)}),t=Array.from(new Set(t)).sort((e,t)=>e-t),n=Array.from(new Set(n)).sort((e,t)=>e-t),e.forEach(e=>{r.push({startRow:t.findIndex(t=>t===e.rows[0]),endRow:t.findIndex(t=>t===e.rows[e.rows.length-1]),startColumn:n.findIndex(t=>t===e.cols[0]),endColumn:n.findIndex(t=>t===e.cols[e.cols.length-1])})}),{ranges:r,mapFunc:(e,r)=>({row:t[e],col:n[r]})}}let N=(0,n.createInterceptorKey)(`rangeMovePermissionCheck`),P=(0,n.createInterceptorKey)(`rangeFillPermissionCheck`),F=function(e){return e[e.FORMULA_EDITOR_SHOW=100]=`FORMULA_EDITOR_SHOW`,e[e.MARK_SELECTION=1e4]=`MARK_SELECTION`,e}({});function I(e){let t=e.getColorFromTheme(`primary.600`),r=e.getColorFromTheme(`white`),i=new n.ColorKit(t).setAlpha(.07).toRgbString();return{strokeWidth:1,stroke:t,fill:i,widgets:{},widgetSize:6,widgetStrokeWidth:1,widgetStroke:r,autofillSize:6,autofillStrokeWidth:1,autofillStroke:r,rowHeaderFill:i,rowHeaderStroke:t,rowHeaderStrokeWidth:1,columnHeaderFill:i,columnHeaderStroke:t,columnHeaderStrokeWidth:1,expandCornerSize:40}}let L=[10,400],R=`RANGE_SELECTOR_COMPONENT_KEY`,z=`EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY`,B=function(e){return e.MAIN=`__SpreadsheetRender__`,e.ROW=`__SpreadsheetRowHeader__`,e.COLUMN=`__SpreadsheetColumnHeader__`,e.LEFT_TOP=`__SpreadsheetLeftTopPlaceholder__`,e}({});function ee(e){"@babel/helpers - typeof";return ee=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},ee(e)}function te(e,t){if(ee(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(ee(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function V(e){var t=te(e,`string`);return ee(t)==`symbol`?t:t+``}function H(e,t,n){return(t=V(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var ne=class{constructor(){H(this,`_startColumn`,-1),H(this,`_startRow`,-1),H(this,`_endColumn`,-1),H(this,`_endRow`,-1),H(this,`_startX`,0),H(this,`_startY`,0),H(this,`_endX`,0),H(this,`_endY`,0),H(this,`_primary`,void 0),H(this,`_rangeType`,n.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(e){let{startColumn:t,startRow:n,endColumn:r,endRow:i}=this,{startColumn:a,startRow:o,endColumn:s,endRow:c}=e;return t===a&&n===o&&r===s&&i===c}highlightToSelection(){if(this._primary)return(0,n.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(e){this._rangeType=e}getValue(){return{rangeWithCoord:this.getRange(),primaryWithCoord:this._primary}}setValue(e,t){let{startColumn:n,startRow:r,endColumn:i,endRow:a,startX:o,startY:s,endX:c,endY:l,rangeType:u}=e;this._startColumn=n,this._startRow=r,this._endColumn=i,this._endRow=a,this._startX=o,this._startY=s,this._endX=c,this._endY=l,u!==void 0&&(this._rangeType=u),t!==void 0&&this.setCurrentCell(t)}setCurrentCell(e){this._primary=e}clearCurrentCell(){this._primary=null}};let re={id:`sheet.command.set-row-header-width`,type:n.CommandType.COMMAND,handler:async(e,t)=>{if(!t)return!1;let n=e.get(i.IRenderManagerService);if(!n)return!1;let{unitId:r,subUnitId:a,size:o}=t,s=n.getRenderById(r);if(s){n.getRenderById(r).with(K).setRowHeaderSize(s,a,o);let{components:e}=s,t=e.get(`__SpreadsheetRowHeader__`);t&&t.setCustomHeader({headerStyle:{size:o}},a)}return!0}},ie={id:`sheet.command.set-col-header-height`,type:n.CommandType.COMMAND,handler:async(e,t)=>{if(!t)return!1;let n=e.get(i.IRenderManagerService);if(!n)return!1;let{unitId:r,subUnitId:a,size:o}=t,s=n.getRenderById(r);if(s){n.getRenderById(r).with(K).setColumnHeaderSize(s,a,o);let{components:e}=s,t=e.get(`__SpreadsheetColumnHeader__`);t&&t.setCustomHeader({headerStyle:{size:o}},a)}return!0}};var ae=class extends i.Layer{render(e,t=!1){let r=n.Tools.now();return super.render(e,t),this._afterRender(r),this}_afterRender(e){this.scene.getEngine().renderFrameTimeMetric$.next([`selectionLayer`,n.Tools.now()-e])}};let U=(0,n.createIdentifier)(`univer.sheet.selection-render-service`);var oe=class extends n.Disposable{get selectionMoving(){return this._selectionMoving}constructor(e,t,r,i,a){super(),this._injector=e,this._themeService=t,this._shortcutService=r,this._sheetSkeletonManagerService=i,this.contextService=a,H(this,`_downObserver`,void 0),H(this,`_scenePointerMoveSub`,void 0),H(this,`_scenePointerUpSub`,void 0),H(this,`_controlFillConfig$`,new o.BehaviorSubject(null)),H(this,`controlFillConfig$`,this._controlFillConfig$.asObservable()),H(this,`_selectionControls`,[]),H(this,`_startRangeWhenPointerDown`,{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1}),H(this,`_activeControlIndex`,-1),H(this,`_startViewportPosX`,0),H(this,`_startViewportPosY`,0),H(this,`_scrollTimer`,void 0),H(this,`_cancelDownSubscription`,void 0),H(this,`_cancelUpSubscription`,void 0),H(this,`_skeleton`,void 0),H(this,`_scene`,void 0),H(this,`_highlightHeader`,!0),H(this,`_rangeType`,n.RANGE_TYPE.NORMAL),H(this,`_selectionStyle`,void 0),H(this,`_remainLastEnabled`,!1),H(this,`_skipLastEnabled`,!1),H(this,`_singleSelectionEnabled`,!1),H(this,`_selectionMoveEnd$`,new o.BehaviorSubject([])),H(this,`selectionMoveEnd$`,this._selectionMoveEnd$.asObservable()),H(this,`_selectionMoving$`,new o.Subject),H(this,`selectionMoving$`,this._selectionMoving$.asObservable()),H(this,`_selectionMoveStart$`,new o.Subject),H(this,`selectionMoveStart$`,this._selectionMoveStart$.asObservable()),H(this,`_selectionMoving`,!1),H(this,`_selectionTheme`,void 0),H(this,`_activeViewport`,void 0),H(this,`interceptor`,new n.InterceptorManager({RANGE_MOVE_PERMISSION_CHECK:N,RANGE_FILL_PERMISSION_CHECK:P})),H(this,`_escapeShortcutDisposable`,null),this._initSelectionThemeFromThemeService(),this._initMoving()}get _shouldDetectMergedCells(){return this._rangeType===n.RANGE_TYPE.NORMAL}_initMoving(){this.disposeWithMe(this._selectionMoving$.subscribe(()=>{this._selectionMoving=!0})),this.disposeWithMe(this._selectionMoveEnd$.subscribe(()=>{this._selectionMoving=!1}))}_setSelectionStyle(e){this._selectionStyle=e}getViewPort(){return this._activeViewport}setSingleSelectionEnabled(e=!1){this._singleSelectionEnabled=e}newSelectionControl(e,t,n){let r=this.getSelectionControls().length,{rowHeaderWidth:i,rowHeaderWidthAndMarginLeft:o,columnHeaderHeight:s,columnHeaderHeightAndMarginTop:c}=t,l=new pe(e,r,this._selectionTheme,{highlightHeader:this._highlightHeader,rowHeaderWidth:i,columnHeaderHeight:s,rowHeaderOffsetX:Math.max(0,o-i),columnHeaderOffsetY:Math.max(0,c-s)});this._selectionControls.push(l);let u=(0,a.attachSelectionWithCoord)(n,t);return l.updateRangeBySelectionWithCoord(u,t),l.setControlExtension({skeleton:t,scene:e,themeService:this._selectionTheme,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),l}resetSelectionsByModelData(e){let t=this.getSelectionControls(),n=this._skeleton;if(!(!t||!n)){for(let r=0,i=e.length;r<i;r++){let i=e[r],o=(0,a.attachSelectionWithCoord)(i,this._skeleton),s=t[r];s?s.updateRangeBySelectionWithCoord(o,n):this.isSelectionEnabled()&&this.newSelectionControl(this._scene,n,i)}e.length<t.length&&t.splice(e.length).forEach(e=>e.dispose())}}refreshSelectionMoveStart(){this._selectionMoveStart$.next(this.getSelectionDataWithStyle())}refreshSelectionMoveEnd(){this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}_initSelectionThemeFromThemeService(){let e=this._themeService.getCurrentTheme();this._selectionTheme=new n.ThemeService,this._selectionTheme.setTheme(e)}setSelectionTheme(e){this._selectionTheme.setTheme(e)}_changeRuntime(e,t,n){this._skeleton=e,this._scene=t,this._activeViewport=n||(t==null?void 0:t.getViewports()[0]),t.findLayerByZIndex(1)||t.addLayer(new ae(t,[],1))}getSkeleton(){return this._skeleton}getSelectionDataWithStyle(){let e=this._selectionControls;if(this._skeleton.worksheet){let[t,n]=this._skeleton.getLocation();return e.map(e=>{let r=e.getValue();return r.rangeWithCoord.sheetId=n,r.rangeWithCoord.unitId=t,r})}return[]}getSelectionControls(){return this._selectionControls}_addSelectionControlByModelData(e){var t;let n=this._skeleton,r=(t=e.style)==null?I(this._selectionTheme):t,i=this._scene;return e.style=r,this.newSelectionControl(i,n,e)}_clearAllSelectionControls(){let e=this._selectionControls;for(let t of e)t.dispose();this._selectionControls.length=0}_getFreeze(){var e;return(e=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:e.skeleton.getWorksheetConfig().freeze}_getViewportByCell(e,t){if(e===void 0||t===void 0)return null;let n=this._getFreeze();if(!n||n.startRow<=0&&n.startColumn<=0||e>n.startRow&&t>n.startColumn)return this._scene.getViewport(i.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e<=n.startRow&&t<=n.startColumn)return this._scene.getViewport(i.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP);if(e<=n.startRow&&t>n.startColumn)return this._scene.getViewport(i.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(e>n.startRow&&t<=n.startColumn)return this._scene.getViewport(i.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)}getActiveRange(){let 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(){let e=this.getSelectionControls();if(e)return this._activeControlIndex<0?e[e.length-1]:e[this._activeControlIndex]}endSelection(){var e;this._clearUpdatingListeners(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),(e=this._escapeShortcutDisposable)==null||e.dispose(),this._escapeShortcutDisposable=null}_reset(){var e;this._clearAllSelectionControls(),(e=this._downObserver)==null||e.unsubscribe(),this._downObserver=null}_setupPointerMoveListener(e,t,n,r=i.ScrollTimerType.ALL,a,o){var s,c;let l=0,u=0,d=a,f=o;this._scrollTimer=i.ScrollTimer.create(this._scene,r),this._scrollTimer.startScroll((s=e==null?void 0:e.left)==null?0:s,(c=e==null?void 0:e.top)==null?0:c,e);let p=this._scene,m=p.getActiveViewportByCoord(i.Vector2.FromArray([a,o]));this._scenePointerMoveSub=p.onPointerMove$.subscribeEvent(r=>{var a;let{offsetX:o,offsetY:s}=r,{x:c,y:h}=p.getCoordRelativeToViewport(i.Vector2.FromArray([o,s]));this._movingHandler(c,h,t,n);let g=c,_=h,v=this.getActiveSelectionControl(),y=this._getFreeze(),b=v==null?void 0:v.model,x=(a=p.getActiveViewportByCoord(i.Vector2.FromArray([o,s])))==null?this._getViewportByCell(b==null?void 0:b.endRow,b==null?void 0:b.endColumn):a;if((()=>{if(!m||!x||!e)return!1;let t=[i.SHEET_VIEWPORT_KEY.VIEW_MAIN,i.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,i.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,i.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT];return t.includes(m.viewportKey)&&t.includes(x.viewportKey)})()){if(!m||!x||!e)return!1;let t=d<e.left&&c>e.left||d>e.left&&c<e.left,n=f<e.top&&h>e.top||f>e.top&&h<e.top;t&&(l+=1),n&&(u+=1);let r=m.viewportKey,a=x.viewportKey;if(r===i.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP){var S,C;s<e.top&&((S=b==null?void 0:b.endRow)==null?0:S)<((C=y==null?void 0:y.startRow)==null?0:C)?_=e.top:n&&u%2==1&&e.scrollToViewportPos({viewportScrollY:0})}else if(r===i.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT){var w,T;o<e.left&&((w=b==null?void 0:b.endColumn)==null?0:w)<((T=y==null?void 0:y.startColumn)==null?0:T)?g=e.left:t&&l%2==1&&e.scrollToViewportPos({viewportScrollX:0})}else if(r===a){var E,D,O,k;let t=!1,n=!1;r===i.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP?(t=!0,n=!0):r===i.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP?n=!0:r===i.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT&&(t=!0),((E=b==null?void 0:b.endRow)==null?0:E)>((D=y==null?void 0:y.startRow)==null?0:D)&&(n=!1),((O=b==null?void 0:b.endColumn)==null?0:O)>((k=y==null?void 0:y.startColumn)==null?0:k)&&(t=!1),t&&(g=e.left),n&&(_=e.top)}else{let o={x:m.scrollX,y:m.scrollY},s={x:x.scrollX,y:x.scrollY},c=o.x!==s.x&&t&&l%2==1,d=o.y!==s.y&&n&&u%2==1;(c||d)&&(e.scrollToBarPos({x:c?o.x:void 0,y:d?o.y:void 0}),c||(g=e.left),d||(_=e.top)),(r===i.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&a===i.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||a===i.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&r===i.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)&&(g=e.left),(r===i.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&a===i.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||a===i.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&r===i.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP)&&(_=e.top)}d=c,f=h}this._scrollTimer.scrolling(g,_,()=>{this._movingHandler(c,h,t,n)})})}getSelectionCellByPosition(e,t){return this.getCellWithCoordByOffset(e,t)}getCellWithCoordByOffset(e,t,n){let r=this._scene,a=n==null?this._skeleton:n,o=r.getViewportScrollXY(r.getViewport(i.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:s,scaleY:c}=r.getAncestorScale();return a.getCellWithCoordByOffset(e-o.x,t-o.y,s,c,o)}_movingHandler(e,t,r,o){var s,c,l,u,d;let f=this._skeleton,p=this._scene,[m,h]=f.getLocation(),g={startRow:(s=r==null?void 0:r.model.startRow)==null?-1:s,endRow:(c=r==null?void 0:r.model.endRow)==null?-1:c,startColumn:(l=r==null?void 0:r.model.startColumn)==null?-1:l,endColumn:(u=r==null?void 0:r.model.endColumn)==null?-1:u,unitId:m,sheetId:h},_=p.getViewport(i.SHEET_VIEWPORT_KEY.VIEW_MAIN),v=(d=this._getViewportByCell(g.endRow,g.endColumn))==null?_:d,y=p.getScrollXYInfoByViewport(i.Vector2.FromArray([this._startViewportPosX,this._startViewportPosY]),v),{scaleX:b,scaleY:x}=p.getAncestorScale();o===n.RANGE_TYPE.ROW?e=1/0:o===n.RANGE_TYPE.COLUMN&&(t=1/0);let S=this._skeleton.getCellByOffset(e,t,b,x,y);if(!S)return;let C={startRow:Math.min(S.startRow,this._startRangeWhenPointerDown.startRow),startColumn:Math.min(S.startColumn,this._startRangeWhenPointerDown.startColumn),endRow:Math.max(S.endRow,this._startRangeWhenPointerDown.endRow),endColumn:Math.max(S.endColumn,this._startRangeWhenPointerDown.endColumn)};this._shouldDetectMergedCells&&(C=f.expandRangeByMerge(C,this.inRefSelectionMode()));let w=(0,a.attachSelectionWithCoord)({range:C,primary:void 0,style:null},f);w.rangeWithCoord.unitId=m,w.rangeWithCoord.sheetId=h,w.rangeWithCoord.rangeType=o;let T=g.startRow!==C.startRow||g.startColumn!==C.startColumn||g.endRow!==C.endRow||g.endColumn!==C.endColumn;r!=null&&T&&(r.updateRangeBySelectionWithCoord(w),this._selectionMoving$.next(this.getSelectionDataWithStyle()))}_clearUpdatingListeners(){var e,t,n,r,i;this._scene.enableObjectsEvent(),(e=this._scenePointerMoveSub)==null||e.unsubscribe(),this._scenePointerMoveSub=null,(t=this._scenePointerUpSub)==null||t.unsubscribe(),this._scenePointerUpSub=null,(n=this._cancelDownSubscription)==null||n.unsubscribe(),this._cancelDownSubscription=null,(r=this._cancelUpSubscription)==null||r.unsubscribe(),this._cancelUpSubscription=null,(i=this._scrollTimer)==null||i.dispose()}_addEndingListeners(){var e,t,n;let r=this._scene,i=(e=r.getEngine())==null?void 0:e.activeScene;!i||i===r||((t=this._cancelDownSubscription)==null||t.unsubscribe(),this._cancelDownSubscription=null,(n=this._cancelUpSubscription)==null||n.unsubscribe(),this._cancelUpSubscription=null,this._cancelDownSubscription=i.onPointerDown$.subscribeEvent(()=>this._clearUpdatingListeners()),this._cancelUpSubscription=i.onPointerUp$.subscribeEvent(()=>this._clearUpdatingListeners()))}_getSelectionWithCoordByOffset(e,t,r,i,a){let o=this._skeleton;if(o==null)return null;if(this._shouldDetectMergedCells){let s=o==null?void 0:o.getCellWithCoordByOffset(e,t,r,i,a,{firstMatch:!0});return s?{primaryWithCoord:s,rangeWithCoord:(0,n.convertCellToRange)(s)}:void 0}let{row:s,column:c}=o.getCellIndexByOffset(e,t,r,i,a),{startX:l,startY:u,endX:d,endY:f}=o.getNoMergeCellWithCoordByIndex(s,c),p={startY:u,endY:f,startX:l,endX:d,startRow:s,endRow:s,startColumn:c,endColumn:c};return{primaryWithCoord:{mergeInfo:p,actualRow:s,actualColumn:c,isMerged:!1,isMergedMainCell:!1,startY:u,endY:f,startX:l,endX:d},rangeWithCoord:p}}_checkClearPreviousControls(e){this.getSelectionControls().length!==0&&(!e.ctrlKey&&!e.shiftKey&&!this._remainLastEnabled||this._singleSelectionEnabled&&!e.shiftKey)&&this._clearAllSelectionControls()}_makeSelectionByTwoCells(e,t,n,r,i){let{actualRow:o,actualColumn:s,mergeInfo:c}=e;this._startRangeWhenPointerDown={...e.mergeInfo};let l=Math.min(o,t.startRow,c.startRow),u=Math.max(o,t.endRow,c.endRow),d=Math.min(s,t.startColumn,c.startColumn),f=Math.max(s,t.endColumn,c.endColumn),p=(0,a.attachSelectionWithCoord)({range:n.expandRangeByMerge({startRow:l,startColumn:d,endRow:u,endColumn:f}),primary:(0,a.convertPrimaryWithCoordToPrimary)(e),style:null},n);i.updateRangeBySelectionWithCoord(p)}isSelectionEnabled(){return this.contextService.getContextValue(a.SELECTIONS_ENABLED)}isSelectionDisabled(){return this.contextService.getContextValue(a.SELECTIONS_ENABLED)===!1}inRefSelectionMode(){return this.contextService.getContextValue(a.REF_SELECTIONS_ENABLED)}};function se(e){return{range:{startRow:0,startColumn:0,endRow:e.getRowCount()-1,endColumn:e.getColumnCount()-1,rangeType:n.RANGE_TYPE.ALL},primary:ce(e).primary,style:null}}function ce(e){return le(e,{startRow:0,startColumn:0,endRow:0,endColumn:0})}function le(e,t){let r=e.worksheet.getCellInfoInMergeData(t.startRow,t.startColumn),i=e.worksheet.getCellInfoInMergeData(t.endRow,t.endColumn);return{range:{startRow:r.startRow,startColumn:r.startColumn,endRow:i.endRow,endColumn:i.endColumn,rangeType:n.RANGE_TYPE.NORMAL},primary:{actualRow:r.startRow,actualColumn:r.startColumn,startRow:r.startRow,startColumn:r.startColumn,endRow:r.endRow,endColumn:r.endColumn,isMerged:r.isMerged,isMergedMainCell:r.isMergedMainCell},style:null}}function W(e,t){return function(n,r){t(n,r,e)}}function G(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let K=class extends n.Disposable{constructor(e,t){super(),this._context=e,this._sheetSkeletonService=t,H(this,`_sheetId`,``),H(this,`_currentSkeleton$`,new o.BehaviorSubject(null)),H(this,`currentSkeleton$`,this._currentSkeleton$.asObservable()),H(this,`_currentSkeletonBefore$`,new o.BehaviorSubject(null)),H(this,`currentSkeletonBefore$`,this._currentSkeletonBefore$.asObservable());let{unitId:n,scene:r}=this._context;this._sheetSkeletonService.setScene(n,r),this._initSkeletonsRegisterGetCellHeight(n)}_initSkeletonsRegisterGetCellHeight(e){this._sheetSkeletonService.getSkeletonsByUnitId(e).forEach(e=>e.registerGetCellHeight()),this.disposeWithMe(this._sheetSkeletonService.buildSkeleton$.subscribe(e=>e.registerGetCellHeight()))}dispose(){super.dispose(),this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete()}getCurrentSkeleton(){var e;return(e=this.getCurrentParam())==null?void 0:e.skeleton}getCurrentParam(){return this._getSkeletonParam(this._sheetId)}getSkeleton(e){return this._getSkeleton(e)}getSkeletonParam(e){return this._getSkeletonParam(e)}setCurrent(e){this._setCurrent(e.sheetId)}_setCurrent(e){this._sheetId=e;let t=this._getSkeletonParam(e);if(t)this.reCalculate(t);else{let n=this._context.unit,r=n.getSheetBySheetId(e),i=this._context.unitId;if(!r)return;t=this._sheetSkeletonService.newSkeletonParam(i,e,r,n.getStyles())}this._currentSkeletonBefore$.next(t),this._currentSkeleton$.next(t)}reCalculate(e){let t=e||this.getCurrentParam();t&&(t.dirty&&(t.skeleton.makeDirty(!0),t.dirty=!1),t.skeleton.calculate())}makeDirty(e,t=!0){let n=this._getSkeletonParam(e.sheetId);n!=null&&(n.dirty=t)}ensureSkeleton(e){return this._sheetSkeletonService.ensureSkeleton(this._context.unitId,e)}_getSkeletonParam(e){return this._sheetSkeletonService.getSkeletonParam(this._context.unitId,e)}_getSkeleton(e){return this._sheetSkeletonService.getSkeleton(this._context.unitId,e)}setColumnHeaderSize(e,t,n){if(!e)return;let r=this.getSkeleton(t);if(!r)return;r.columnHeaderHeight=n,e.scene.getViewports()[0].top=n,e.scene.getViewport(i.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({height:n}),e.scene.getViewport(i.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({height:n}),e.scene.getViewport(i.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({top:n}),e.scene.getViewport(i.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({top:n}),e.scene.getViewport(i.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({height:n});let o=e==null?void 0:e.with(a.SheetsSelectionsService),s=e==null?void 0:e.with(U),c=o.getCurrentSelections();s.resetSelectionsByModelData(c);let l=this._sheetSkeletonService.getSkeletonParam(e.unitId,t);l&&(l.commandId=ie.id,this._currentSkeleton$.next(l))}setRowHeaderSize(e,t,n){if(!e)return;let r=this.getSkeleton(t);if(!r)return;r.rowHeaderWidth=n;let o=n-(e.scene.getViewport(i.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).width||46),s=e.scene.getViewports()[0].left;e.scene.getViewports()[0].left=s+o,e.scene.getViewport(i.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({width:n}),e.scene.getViewport(i.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({width:n}),e.scene.getViewport(i.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({left:n});let c=e.scene.getViewport(i.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).left||0;e.scene.getViewport(i.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({left:c+o}),e.scene.getViewport(i.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({width:n});let l=e==null?void 0:e.with(a.SheetsSelectionsService),u=e==null?void 0:e.with(U),d=l.getCurrentSelections();u.resetSelectionsByModelData(d);let f=this._sheetSkeletonService.getSkeletonParam(e.unitId,t);f&&(f.commandId=re.id,this._currentSkeleton$.next(f))}};K=G([W(1,(0,n.Inject)(a.SheetSkeletonService))],K);let ue=`__SpreadsheetHelperSelectionTempRect`;var de=class{constructor(e,t){this._control=e,H(this,`_startOffsetX`,0),H(this,`_startOffsetY`,0),H(this,`_relativeSelectionPositionRow`,0),H(this,`_relativeSelectionPositionColumn`,0),H(this,`_relativeSelectionRowLength`,0),H(this,`_relativeSelectionColumnLength`,0),H(this,`_scenePointerMoveSub`,void 0),H(this,`_scenePointerUpSub`,void 0),H(this,`_disabled`,!1),H(this,`_helperSelection`,void 0),H(this,`_scrollTimer`,void 0),H(this,`_activeViewport`,void 0),H(this,`_targetSelection`,{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1}),H(this,`_isInMergeState`,!1),H(this,`_fillControlColors`,[]),H(this,`_skeleton`,void 0),H(this,`_scene`,void 0),H(this,`_themeService`,void 0),H(this,`_injector`,void 0),H(this,`_selectionHooks`,void 0),this._skeleton=t.skeleton,this._scene=t.scene,this._themeService=t.themeService,this._injector=t.injector,this._selectionHooks=t.selectionHooks,this._initialControl(),this._initialWidget(),this._initialAutoFill(),this._control.dispose$.subscribe(()=>{this.dispose()})}get isHelperSelection(){return this._control.isHelperSelection}dispose(){var e,t;(e=this._scrollTimer)==null||e.dispose(),this._fillControlColors=[],this._clearObserverEvent(),(t=this._helperSelection)==null||t.dispose()}setDisabled(e){this._disabled=e}_getFreeze(){var e;return(e=(0,i.withCurrentTypeOfRenderer)(n.UniverInstanceType.UNIVER_SHEET,K,this._injector.get(n.IUniverInstanceService),this._injector.get(i.IRenderManagerService)))==null||(e=e.getCurrentParam())==null?void 0:e.skeleton.getWorksheetConfig().freeze}_isSelectionInViewport(e,t){let n=this._getFreeze()||{startRow:-1,startColumn:-1,xSplit:0,ySplit:0};switch(t.viewportKey){case i.SHEET_VIEWPORT_KEY.VIEW_MAIN:return e.endRow>=n.startRow&&e.endColumn>=n.startColumn;case i.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP:case i.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT:return e.endColumn>=n.startColumn&&e.startRow<n.startRow;case i.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT:case i.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM:return e.endRow>=n.startRow&&e.startColumn<n.startColumn;case i.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP:case i.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT:case i.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP:case i.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP:return e.startRow<n.startRow&&e.startColumn<n.startColumn;default:break}}_clearObserverEvent(){var e,t;(e=this._scenePointerMoveSub)==null||e.unsubscribe(),(t=this._scenePointerUpSub)==null||t.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null}_initialControl(){let{leftControl:e,rightControl:t,topControl:r,bottomControl:a}=this._control;[e,t,r,a].forEach(e=>{e.onPointerEnter$.subscribeEvent(()=>{var t;((t=this._injector.get(U,n.Quantity.OPTIONAL))==null?void 0:t.interceptor.fetchThroughInterceptors(N)(!1,null))!==!1&&e.setCursor(i.CURSOR_TYPE.MOVE)}),e.onPointerLeave$.subscribeEvent(()=>{e.resetCursor()}),e.onPointerDown$.subscribeEvent(this._controlPointerDownHandler.bind(this))})}_controlMoving(e,t){var n;let r=this._scene,o=r.getScrollXYInfoByViewport(i.Vector2.FromArray([e,t])),{scaleX:s,scaleY:c}=r.getAncestorScale(),{row:l,column:u}=this._skeleton.getCellIndexByOffset(e,t,s,c,o),d=this._skeleton.getRowCount()-1,f=this._skeleton.getColumnCount()-1,p=Math.max(0,l+this._relativeSelectionPositionRow),m=p+this._relativeSelectionRowLength;m>d&&(m=d,m-p<this._relativeSelectionRowLength&&(p=m-this._relativeSelectionRowLength));let h=Math.max(0,u+this._relativeSelectionPositionColumn),g=h+this._relativeSelectionColumnLength;g>f&&(g=f,g-h<this._relativeSelectionColumnLength&&(h=g-this._relativeSelectionColumnLength));let _=this._skeleton.worksheet.getCellInfoInMergeData(p,h),v=(0,a.attachSelectionWithCoord)({range:{startRow:p,endRow:m,startColumn:h,endColumn:g},primary:_,style:null},this._skeleton),y=this._skeleton.getNoMergeCellWithCoordByIndex(p,h),b=this._skeleton.getNoMergeCellWithCoordByIndex(m,g),x=(y==null?void 0:y.startY)||0,S=(b==null?void 0:b.endY)||0,C=(y==null?void 0:y.startX)||0,w=(b==null?void 0:b.endX)||0;(n=this._helperSelection)==null||n.transformByState({left:C,top:x,width:w-C,height:S-x}),this._targetSelection={...v.rangeWithCoord},this._control.selectionMoving$.next(v.rangeWithCoord)}_controlPointerDownHandler(e){let{offsetX:t,offsetY:r}=e,a=this._scene,o=a.getCoordRelativeToViewport(i.Vector2.FromArray([t,r])),{x:s,y:c}=o,l=a.getScrollXYInfoByViewport(o),{scaleX:u,scaleY:d}=a.getAncestorScale(),f=this._skeleton.getCellIndexByOffset(s,c,u,d,l);this._startOffsetX=s,this._startOffsetY=c;let{row:p,column:m}=f,{startRow:h,startColumn:g,endRow:_,endColumn:v}=this._control.model,y=0,b=0;p<h?--y:p>_&&(y+=1),m<g?--b:m>v&&(b+=1),this._relativeSelectionPositionRow=h-p+y,this._relativeSelectionPositionColumn=g-m+b,this._relativeSelectionRowLength=_-h,this._relativeSelectionColumnLength=v-g;let x=this._control.currentStyle,S=this._getScale();this.isHelperSelection&&(this._helperSelection=new i.Rect(ue,{stroke:x.stroke,strokeWidth:x.strokeWidth/S}),a.addObject(this._helperSelection));let C=a.getViewport(i.SHEET_VIEWPORT_KEY.VIEW_MAIN),w=i.ScrollTimer.create(a);this._scrollTimer=w,w.startScroll(s,c,C),a.disableObjectsEvent(),this._scenePointerMoveSub=a.onPointerMove$.subscribeEvent(e=>{var t;if(this._disabled)return;let{offsetX:r,offsetY:o}=e;if(((t=this._injector.get(U,n.Quantity.OPTIONAL))==null?void 0:t.interceptor.fetchThroughInterceptors(N)(!1,null))===!1)return;let{x:s,y:c}=a.getCoordRelativeToViewport(i.Vector2.FromArray([r,o]));this._controlMoving(s,c),a.setCursor(i.CURSOR_TYPE.MOVE),w.scrolling(s,c,()=>{this._controlMoving(s,c)})}),this._scenePointerUpSub=a.onPointerUp$.subscribeEvent(()=>{var e,t,n,r;(e=this._helperSelection)==null||e.dispose();let i=this._scene;i.resetCursor(),this._clearObserverEvent(),i.enableObjectsEvent(),(t=this._scrollTimer)==null||t.dispose(),this._control.selectionMoveEnd$.next(this._targetSelection),(n=(r=this._selectionHooks).selectionMoveEnd)==null||n.call(r)})}_initialWidget(){let{topLeftWidget:e,topCenterWidget:t,topRightWidget:n,middleLeftWidget:r,middleRightWidget:a,bottomLeftWidget:o,bottomCenterWidget:s,bottomRightWidget:c}=this._control,l=[i.CURSOR_TYPE.NORTH_WEST_RESIZE,i.CURSOR_TYPE.NORTH_RESIZE,i.CURSOR_TYPE.NORTH_EAST_RESIZE,i.CURSOR_TYPE.WEST_RESIZE,i.CURSOR_TYPE.EAST_RESIZE,i.CURSOR_TYPE.SOUTH_WEST_RESIZE,i.CURSOR_TYPE.SOUTH_RESIZE,i.CURSOR_TYPE.SOUTH_EAST_RESIZE];[e,t,n,r,a,o,s,c].forEach((e,t)=>{e.onPointerEnter$.subscribeEvent(()=>{e.setCursor(l[t])}),e.onPointerLeave$.subscribeEvent(()=>{e.resetCursor()}),e.onPointerDown$.subscribeEvent(e=>{this._widgetPointerDownEvent(e,l[t])})})}_widgetPointerDownEvent(e,t){let n=this._scene,{offsetX:r,offsetY:a}=e,{x:o,y:s}=n.getCoordRelativeToViewport(i.Vector2.FromArray([r,a]));this._startOffsetX=r,this._startOffsetY=a;let{startRow:c,startColumn:l,endRow:u,endColumn:d}=this._control.model,f=Math.min(c,u),p=Math.min(l,d),m=Math.max(c,u),h=Math.max(l,d);this._relativeSelectionPositionRow=f,this._relativeSelectionPositionColumn=p,this._relativeSelectionRowLength=m-f,this._relativeSelectionColumnLength=h-p,t===i.CURSOR_TYPE.NORTH_WEST_RESIZE?(this._relativeSelectionPositionRow=m,this._relativeSelectionPositionColumn=h):t===i.CURSOR_TYPE.NORTH_RESIZE||t===i.CURSOR_TYPE.NORTH_EAST_RESIZE?this._relativeSelectionPositionRow=m:t===i.CURSOR_TYPE.WEST_RESIZE||t===i.CURSOR_TYPE.SOUTH_WEST_RESIZE?this._relativeSelectionPositionColumn=h:t===i.CURSOR_TYPE.SOUTH_RESIZE&&(this._relativeSelectionPositionRow=f);let g=i.ScrollTimer.create(n),_=n.getViewport(i.SHEET_VIEWPORT_KEY.VIEW_MAIN);g.startScroll(o,s,_),this._scrollTimer=g,n.disableObjectsEvent(),this._scenePointerMoveSub=n.onPointerMove$.subscribeEvent(e=>{let{offsetX:r,offsetY:a}=e,{x:o,y:s}=n.getCoordRelativeToViewport(i.Vector2.FromArray([r,a]));this._widgetMoving(o,s,t),n.setCursor(t),g.scrolling(o,s,()=>{this._widgetMoving(o,s,t)})}),this._scenePointerUpSub=n.onPointerUp$.subscribeEvent(()=>{var e,t,n;let r=this._scene;r.resetCursor(),this._clearObserverEvent(),r.enableObjectsEvent(),(e=this._scrollTimer)==null||e.dispose(),this._control.selectionScaled$.next(this._targetSelection),(t=(n=this._selectionHooks).selectionMoveEnd)==null||t.call(n)})}_widgetMoving(e,t,n){let r=this._scene,o=r.getScrollXYInfoByViewport(i.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:s,scaleY:c}=r.getAncestorScale(),{row:l,column:u}=this._skeleton.getCellIndexByOffset(e,t,s,c,o),d=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn,p=l,m=u;n===i.CURSOR_TYPE.NORTH_WEST_RESIZE?(d=l,f=u,p=this._relativeSelectionPositionRow,m=this._relativeSelectionPositionColumn):n===i.CURSOR_TYPE.NORTH_RESIZE?(d=l,f=this._relativeSelectionPositionColumn,p=this._relativeSelectionPositionRow,m=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength):n===i.CURSOR_TYPE.NORTH_EAST_RESIZE?(d=l,f=this._relativeSelectionPositionColumn,p=this._relativeSelectionPositionRow,m=u):n===i.CURSOR_TYPE.WEST_RESIZE?(d=this._relativeSelectionPositionRow,f=u,p=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,m=this._relativeSelectionPositionColumn):n===i.CURSOR_TYPE.EAST_RESIZE?p=this._relativeSelectionPositionRow+this._relativeSelectionRowLength:n===i.CURSOR_TYPE.SOUTH_WEST_RESIZE?(d=this._relativeSelectionPositionRow,f=u,p=l,m=this._relativeSelectionPositionColumn):n===i.CURSOR_TYPE.SOUTH_RESIZE&&(d=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn,p=l,m=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength);let h=(0,a.attachSelectionWithCoord)({range:this._swapPositions(d,f,p,m),primary:this._skeleton.getCellWithMergeInfoByIndex(d,f),style:null},this._skeleton);this._targetSelection={...h.rangeWithCoord},this._control.updateRangeBySelectionWithCoord(h),this._control.selectionScaling$.next(this._targetSelection)}_initialAutoFill(){let{fillControl:e}=this._control;e.onPointerEnter$.subscribeEvent(t=>{this._injector.get(U).interceptor.fetchThroughInterceptors(P)(!1,{x:t.offsetX,y:t.offsetY,skeleton:this._skeleton,scene:this._scene})&&e.setCursor(i.CURSOR_TYPE.CROSSHAIR)}),e.onPointerLeave$.subscribeEvent(()=>{e.resetCursor()}),e.onPointerDown$.subscribeEvent(this._autoFillForPointerdown.bind(this))}_autoFillMoving(e,t){let r=this._scene,o=r.getViewportScrollXY(this._activeViewport),{scaleX:s,scaleY:c}=r.getAncestorScale(),{row:l,column:u}=this._skeleton.getCellIndexByOffset(e,t,s,c,o),d=r.getCoordRelativeToViewport(i.Vector2.FromArray([e,t])),f=this._skeleton.getRowCount()-1,p=this._skeleton.getColumnCount()-1,m=this._relativeSelectionPositionRow,h=this._relativeSelectionPositionColumn,g=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,_=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength,v=!1,y=!0;if((u<h||u>_)&&l>=m&&l<=g){let e=this._fillRuler(u,h,_,this._relativeSelectionColumnLength,p);h=e.startRowOrColumn,_=e.endRowOrColumn,v=e.isLighten,y=!1}else if((l<m||l>g)&&u>=h&&u<=_){let e=this._fillRuler(l,m,g,this._relativeSelectionRowLength,f);m=e.startRowOrColumn,g=e.endRowOrColumn,v=e.isLighten}else if(Math.abs(this._startOffsetX-d.x-o.x)/2>Math.abs(this._startOffsetY-d.y-o.y)){let e=this._fillRuler(u,h,_,this._relativeSelectionColumnLength,p);h=e.startRowOrColumn,_=e.endRowOrColumn,v=e.isLighten,y=!1}else{let e=this._fillRuler(l,m,g,this._relativeSelectionRowLength,f);m=e.startRowOrColumn,g=e.endRowOrColumn,v=e.isLighten}let b=this._skeleton.getNoMergeCellWithCoordByIndex(m,h),x=this._skeleton.getNoMergeCellWithCoordByIndex(g,_),S=(b==null?void 0:b.startY)||0,C=(x==null?void 0:x.endY)||0,w=(b==null?void 0:b.startX)||0,T=(x==null?void 0:x.endX)||0;v?this._controlHandler((e,t)=>{let r=new n.ColorKit(this._fillControlColors[t]).lighten(35).toRgbString();e.setProps({fill:r})}):this._controlHandler((e,t)=>{e.setProps({fill:this._fillControlColors[t]})});let E=a.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();if(m===g&&y===!0||h===_&&y===!1){var D;(D=this._helperSelection)==null||D.hide()}else{var O,k;(O=this._helperSelection)==null||O.transformByState({left:w-E/2,top:S-E/2,width:T-w,height:C-S}),(k=this._helperSelection)==null||k.show()}this._targetSelection={startY:S,endY:C,startX:w,endX:T,startRow:m,endRow:g,startColumn:h,endColumn:_},this._control.selectionFilling$.next(this._targetSelection)}_autoFillForPointerdown(e){let{offsetX:t,offsetY:r}=e,o=this._scene,{x:s,y:c}=o.getCoordRelativeToViewport(i.Vector2.FromArray([t,r]));this._startOffsetX=s,this._startOffsetY=c;let{startRow:l,startColumn:u,endRow:d,endColumn:f}=this._control.model;this._isInMergeState=this._hasMergeInRange(l,u,d,f),this._relativeSelectionPositionRow=l,this._relativeSelectionPositionColumn=u,this._relativeSelectionRowLength=d-l,this._relativeSelectionColumnLength=f-u;let p=this._control.currentStyle,m=p==null?void 0:p.stroke,h=p==null?void 0:p.strokeWidth,g=I(this._themeService);m==null&&(m=g.stroke),h==null&&(h=g.strokeWidth);let _=this._getScale();h/=_;let v=a.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/_,y=new n.ColorKit(m).darken(2).toRgbString();this.isHelperSelection&&(this._helperSelection=new i.Rect(ue,{stroke:y,strokeWidth:h+v/2}),o.addObject(this._helperSelection)),this._activeViewport=o.getActiveViewportByCoord(i.Vector2.FromArray([t,r]));let b=o.getViewport(i.SHEET_VIEWPORT_KEY.VIEW_MAIN),x=i.ScrollTimer.create(o,this._activeViewport.viewportKey===i.SHEET_VIEWPORT_KEY.VIEW_MAIN?i.ScrollTimerType.ALL:i.ScrollTimerType.NONE);x.startScroll(s,c,b),this._scrollTimer=x,o.disableObjectsEvent(),this._controlHandler(e=>{this._fillControlColors.push(e.fill)}),this._scenePointerMoveSub=o.onPointerMove$.subscribeEvent(t=>{var n;let{offsetX:r,offsetY:a}=t,s=o.getActiveViewportByCoord(i.Vector2.FromArray([r,a]));if(!this._injector.get(U).interceptor.fetchThroughInterceptors(P)(!1,{x:e.offsetX,y:e.offsetY,skeleton:this._skeleton,scene:this._scene}))return;let{x:c,y:f}=o.getCoordRelativeToViewport(i.Vector2.FromArray([r,a]));this._autoFillMoving(c,f),o.setCursor(i.CURSOR_TYPE.CROSSHAIR);let p=this._targetSelection;if(b&&s&&((n=this._activeViewport)==null?void 0:n.viewportKey)!==(s==null?void 0:s.viewportKey)){let e;p.startRow===l?p.endRow===d?p.startColumn===u?(x.scrollTimerType=i.ScrollTimerType.X,e={...p,startColumn:p.endColumn}):(x.scrollTimerType=i.ScrollTimerType.X,e={...p,endColumn:p.startColumn}):(x.scrollTimerType=i.ScrollTimerType.Y,e={...p,startRow:p.endRow}):(x.scrollTimerType=i.ScrollTimerType.Y,e={...p,endRow:p.startRow}),this._isSelectionInViewport(e,s)&&(this._viewportMainScrollBarNeedResetPosition(x.scrollTimerType,this._activeViewport.viewportKey,s.viewportKey)&&b.scrollToBarPos({x:x.scrollTimerType===i.ScrollTimerType.X?0:void 0,y:x.scrollTimerType===i.ScrollTimerType.Y?0:void 0}),this._activeViewport=s)}x.scrolling(c,f,()=>{this._autoFillMoving(c,f)})}),this._scenePointerUpSub=o.onPointerUp$.subscribeEvent(()=>{var e,t;(e=this._helperSelection)==null||e.dispose();let n=this._scene;n.resetCursor(),this._clearObserverEvent(),n.enableObjectsEvent(),(t=this._scrollTimer)==null||t.dispose(),this._control.refreshSelectionFilled(this._targetSelection),this._isInMergeState=!1,this._controlHandler((e,t)=>{e.setProps({fill:this._fillControlColors[t]})}),this._fillControlColors=[]})}_viewportMainScrollBarNeedResetPosition(e,t,n){return e===i.ScrollTimerType.X&&(t===i.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||t===i.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP)&&(n===i.SHEET_VIEWPORT_KEY.VIEW_MAIN||n===i.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP)||e===i.ScrollTimerType.Y&&(t===i.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||t===i.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP)&&(n===i.SHEET_VIEWPORT_KEY.VIEW_MAIN||n===i.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)}_hasMergeInRange(e,t,n,r){return this._skeleton.worksheet.getMergedCellRange(e,t,n,r).length>0}_swapPositions(e,t,n,r){return{startRow:Math.min(e,n),startColumn:Math.min(t,r),endRow:Math.max(e,n),endColumn:Math.max(t,r)}}_controlHandler(e){let{leftControl:t,rightControl:n,topControl:r,bottomControl:i,backgroundControlTop:a,backgroundControlMiddleLeft:o,backgroundControlMiddleRight:s,backgroundControlBottom:c,fillControl:l}=this._control,u=[t,n,r,i,a,o,s,c,l];for(let t=0,n=u.length;t<n;t++){let n=u[t];e(n,t)}}_fillRuler(e,t,n,r,i){let a=!1;if(e<t)if(this._isInMergeState&&e<t){let n=t-e,i=r+1,a=Math.ceil(n/i),o=t-a*i;o<0&&(o=t-(a-1)*i),t=o}else t=e;else if(e>=t&&e<=n)a=!0,this._isInMergeState||(n=e);else if(this._isInMergeState&&e>n){let t=e-n,a=r+1,o=Math.ceil(t/a),s=n+o*a;s>i&&(s=n+(o-1)*a),n=s}else n=e;return{rowOrColumn:e,startRowOrColumn:t,endRowOrColumn:n,isLighten:a}}_getScale(){let{scaleX:e,scaleY:t}=this._scene.getAncestorScale();return Math.max(e,t)}};let fe=.3;var pe=class extends n.Disposable{constructor(e,t,n,r){var i,a,s,c,l,u;super(),this._scene=e,this._zIndex=t,this._themeService=n,H(this,`_isHelperSelection`,!0),H(this,`_enableAutoFill`,!0),H(this,`_showAutoFill`,!1),H(this,`_highlightHeader`,!0),H(this,`_selectionRenderModel`,void 0),H(this,`_leftBorder`,void 0),H(this,`_rightBorder`,void 0),H(this,`_topBorder`,void 0),H(this,`_bottomBorder`,void 0),H(this,`_backgroundControlTop`,void 0),H(this,`_backgroundControlBottom`,void 0),H(this,`_backgroundControlMiddleLeft`,void 0),H(this,`_backgroundControlMiddleRight`,void 0),H(this,`_autoFillControl`,void 0),H(this,`_selectionShapeGroup`,void 0),H(this,`_rowHeaderBackground`,void 0),H(this,`_rowHeaderBorder`,void 0),H(this,`_rowHeaderGroup`,void 0),H(this,`_columnHeaderBackground`,void 0),H(this,`_columnHeaderBorder`,void 0),H(this,`_columnHeaderGroup`,void 0),H(this,`_dashedRect`,void 0),H(this,`_topLeftWidget`,void 0),H(this,`_topCenterWidget`,void 0),H(this,`_topRightWidget`,void 0),H(this,`_middleLeftWidget`,void 0),H(this,`_middleRightWidget`,void 0),H(this,`_bottomLeftWidget`,void 0),H(this,`_bottomCenterWidget`,void 0),H(this,`_bottomRightWidget`,void 0),H(this,`_defaultStyle`,void 0),H(this,`_currentStyle`,void 0),H(this,`_rowHeaderWidth`,0),H(this,`_columnHeaderHeight`,0),H(this,`_rowHeaderOffsetX`,0),H(this,`_columnHeaderOffsetY`,0),H(this,`_widgetRects`,[]),H(this,`_controlExtension`,void 0),H(this,`_dispose$`,new o.BehaviorSubject(this)),H(this,`dispose$`,this._dispose$.asObservable()),H(this,`selectionMoving$`,new o.Subject),H(this,`selectionMoveEnd$`,new o.Subject),H(this,`selectionScaling$`,new o.Subject),H(this,`selectionScaled$`,new o.Subject),H(this,`selectionFilling$`,new o.Subject),H(this,`_selectionFilled$`,new o.Subject),H(this,`selectionFilled$`,this._selectionFilled$.asObservable()),H(this,`_antLineOffset`,0),H(this,`_antRequestNewFrame`,-1),this._enableAutoFill=(i=r==null?void 0:r.enableAutoFill)==null?!0:i,this._highlightHeader=(a=r==null?void 0:r.highlightHeader)==null?!0:a,this._rowHeaderWidth=(s=r==null?void 0:r.rowHeaderWidth)==null?0:s,this._columnHeaderHeight=(c=r==null?void 0:r.columnHeaderHeight)==null?0:c,this._rowHeaderOffsetX=(l=r==null?void 0:r.rowHeaderOffsetX)==null?0:l,this._columnHeaderOffsetY=(u=r==null?void 0:r.columnHeaderOffsetY)==null?0:u,this._initializeSheetBody(),this._initialHeader()}_initializeSheetBody(){this._defaultStyle=I(this._themeService),this._currentStyle=I(this._themeService),this._selectionRenderModel=new ne;let e=this._zIndex;this._leftBorder=new i.Rect(`__SpreadsheetSelectionShapeLeftControl__`+e,{zIndex:e}),this._rightBorder=new i.Rect(`__SpreadsheetSelectionShapeRightControl__`+e,{zIndex:e}),this._topBorder=new i.Rect(`__SpreadsheetSelectionTopControl__`+e,{zIndex:e}),this._bottomBorder=new i.Rect(`__SpreadsheetSelectionBottomControl__`+e,{zIndex:e}),this._backgroundControlTop=new i.Rect(`__SpreadsheetSelectionBackgroundControlTop__`+e,{zIndex:e-1,evented:!1}),this._backgroundControlBottom=new i.Rect(`__SpreadsheetSelectionBackgroundControlBottom__`+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleLeft=new i.Rect(`__SpreadsheetSelectionBackgroundControlMiddleLeft__`+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleRight=new i.Rect(`__SpreadsheetSelectionBackgroundControlMiddleRight__`+e,{zIndex:e-1,evented:!1}),this._autoFillControl=new i.Rect(`__SpreadsheetSelectionFillControl__`+e,{zIndex:e+1}),this._autoFillControl.hide(),this._dashedRect=new i.DashedRect(`__SpreadsheetDragDashControl__`+e,{zIndex:e+2,evented:!1,stroke:`#fff`});let 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 i.Group(`__SpreadsheetSelectionShape__`+e,...t,...this._widgetRects),this._selectionShapeGroup.hide(),this._selectionShapeGroup.evented=!1,this._selectionShapeGroup.zIndex=e;let r=this.getScene();r.addObject(this._selectionShapeGroup,1),this.disposeWithMe((0,n.toDisposable)(r.onTransformChange$.subscribeEvent(e=>{e.type===i.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&(this._updateLayoutOfSelectionControl(this._currentStyle),this._updateControlCoord())})))}_initialHeader(){let e=this._zIndex;this._rowHeaderBackground=new i.Rect(`__SpreadSheetSelectionRowHeaderBackground__`+e,{zIndex:e-1,evented:!1}),this._rowHeaderBorder=new i.Rect(`__SpreadSheetSelectionRowHeaderBorder__`+e,{zIndex:e-1,evented:!1}),this._rowHeaderGroup=new i.Group(`__SpreadSheetSelectionRowHeaderGroup__`+e,this._rowHeaderBackground,this._rowHeaderBorder),this._rowHeaderGroup.hide(),this._rowHeaderGroup.evented=!1,this._rowHeaderGroup.zIndex=e,this._columnHeaderBackground=new i.Rect(`__SpreadSheetSelectionColumnHeaderBackground__`+e,{zIndex:e-1,evented:!1}),this._columnHeaderBorder=new i.Rect(`__SpreadSheetSelectionColumnHeaderBorder__`+e,{zIndex:e-1,evented:!1}),this._columnHeaderGroup=new i.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],11)}_initialWidget(){let e=this._zIndex;return this._topLeftWidget=new i.Rect(`__SpreadSheetSelectionTopLeftWidget__`+e,{zIndex:e+1}),this._topCenterWidget=new i.Rect(`__SpreadSheetSelectionTopCenterWidget__`+e,{zIndex:e+1}),this._topRightWidget=new i.Rect(`__SpreadSheetSelectionTopRightWidget__`+e,{zIndex:e+1}),this._middleLeftWidget=new i.Rect(`__SpreadSheetSelectionMiddleLeftWidget__`+e,{zIndex:e+1}),this._middleRightWidget=new i.Rect(`__SpreadSheetSelectionMiddleRightWidget__`+e,{zIndex:e+1}),this._bottomLeftWidget=new i.Rect(`__SpreadSheetSelectionBottomLeftWidget__`+e,{zIndex:e+1}),this._bottomCenterWidget=new i.Rect(`__SpreadSheetSelectionBottomCenterWidget__`+e,{zIndex:e+1}),this._bottomRightWidget=new i.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