@univerjs/sheets-ui 0.8.2-nightly.202506251607 → 0.8.2-nightly.202506261607
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +6 -10
- package/lib/index.js +6 -10
- package/lib/umd/index.js +1 -1
- package/package.json +13 -13
package/lib/umd/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(y,q){typeof exports=="object"&&typeof module<"u"?q(exports,require("@univerjs/docs-ui"),require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("react"),require("rxjs"),require("@univerjs/sheets"),require("@univerjs/docs"),require("@univerjs/engine-formula"),require("@univerjs/engine-numfmt"),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/engine-render","@univerjs/ui","react","rxjs","@univerjs/sheets","@univerjs/docs","@univerjs/engine-formula","@univerjs/engine-numfmt","react/jsx-runtime","@univerjs/design","rxjs/operators","@univerjs/telemetry"],q):(y=typeof globalThis<"u"?globalThis:y||self,q(y.UniverSheetsUi={},y.UniverDocsUi,y.UniverCore,y.UniverEngineRender,y.UniverUi,y.React,y.rxjs,y.UniverSheets,y.UniverDocs,y.UniverEngineFormula,y.UniverEngineNumfmt,y.React,y.UniverDesign,y.rxjs.operators,y.UniverTelemetry))})(this,function(y,q,a,R,_,W,D,m,_e,K,Oi,I,X,de,Jc){"use strict";var lp=Object.defineProperty;var cp=(y,q,a)=>q in y?lp(y,q,{enumerable:!0,configurable:!0,writable:!0,value:a}):y[q]=a;var T=(y,q,a)=>cp(y,typeof q!="symbol"?q+"":q,a);function Ai(n,r){if(n==null)return;const e=r.getRenderById(n);if(e==null)return;const{mainComponent:t,scene:i,engine:o,components:s}=e,l=t,c=s.get(q.DOCS_VIEW_KEY.BACKGROUND);return{document:l,docBackground:c,scene:i,engine:o}}const Hr=[10,400],Vr="RANGE_SELECTOR_COMPONENT_KEY",Di="EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY";var he=(n=>(n.MAIN="__SpreadsheetRender__",n.ROW="__SpreadsheetRowHeader__",n.COLUMN="__SpreadsheetColumnHeader__",n.LEFT_TOP="__SpreadsheetLeftTopPlaceholder__",n))(he||{});const ys=0,ki=1,st=10,$c=11,Rs=12,Ni={id:"sheet.command.set-row-header-width",type:a.CommandType.COMMAND,handler:async(n,r)=>{if(!r)return!1;const e=n.get(R.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:i,size:o}=r,s=e.getRenderById(t);if(s){e.getRenderById(t).with(y.SheetSkeletonManagerService).setRowHeaderSize(s,i,o);const{components:c}=s,d=c.get(he.ROW);d&&d.setCustomHeader({headerStyle:{size:o}})}return!0}},Hi={id:"sheet.command.set-col-header-height",type:a.CommandType.COMMAND,handler:async(n,r)=>{if(!r)return!1;const e=n.get(R.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:i,size:o}=r,s=e.getRenderById(t);if(s){e.getRenderById(t).with(y.SheetSkeletonManagerService).setColumnHeaderSize(s,i,o);const{components:c}=s,d=c.get(he.COLUMN);d&&d.setCustomHeader({headerStyle:{size:o}})}return!0}},Wr=a.createInterceptorKey("rangeMovePermissionCheck"),xr=a.createInterceptorKey("rangeFillPermissionCheck");var Lr=(n=>(n[n.FORMULA_EDITOR_SHOW=100]="FORMULA_EDITOR_SHOW",n[n.MARK_SELECTION=1e4]="MARK_SELECTION",n))(Lr||{});function at(n){const r=n.getColorFromTheme("primary.600"),e=n.getColorFromTheme("white"),t=new a.ColorKit(r).setAlpha(.07).toRgbString();return{strokeWidth:1,stroke:r,fill:t,widgets:{},widgetSize:6,widgetStrokeWidth:1,widgetStroke:e,autofillSize:6,autofillStrokeWidth:1,autofillStroke:e,rowHeaderFill:t,rowHeaderStroke:r,rowHeaderStrokeWidth:1,columnHeaderFill:t,columnHeaderStroke:r,columnHeaderStrokeWidth:1,expandCornerSize:40}}class ed{constructor(){T(this,"_startColumn",-1);T(this,"_startRow",-1);T(this,"_endColumn",-1);T(this,"_endRow",-1);T(this,"_startX",0);T(this,"_startY",0);T(this,"_endX",0);T(this,"_endY",0);T(this,"_primary");T(this,"_rangeType",a.RANGE_TYPE.NORMAL)}get startColumn(){return this._startColumn}get startRow(){return this._startRow}get endColumn(){return this._endColumn}get endRow(){return this._endRow}get startX(){return this._startX}get startY(){return this._startY}get endX(){return this._endX}get endY(){return this._endY}get currentCell(){return this._primary}get rangeType(){return this._rangeType}isEqual(r){const{startColumn:e,startRow:t,endColumn:i,endRow:o}=this,{startColumn:s,startRow:l,endColumn:c,endRow:d}=r;return e===s&&t===l&&i===c&&o===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(r){this._rangeType=r}getValue(){return{rangeWithCoord:this.getRange(),primaryWithCoord:this._primary}}setValue(r,e){const{startColumn:t,startRow:i,endColumn:o,endRow:s,startX:l,startY:c,endX:d,endY:u,rangeType:h}=r;this._startColumn=t,this._startRow=i,this._endColumn=o,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(r){this._primary=r}clearCurrentCell(){this._primary=null}}function Gt(n,r){const{startRow:e,startColumn:t,endRow:i,endColumn:o,rangeType:s}=r,l=i<e?i:e,c=i<e?e:i,d=o<t?o:t,u=o<t?t:o,h=n.getNoMergeCellWithCoordByIndex(l,d),g=n.getNoMergeCellWithCoordByIndex(c,u);return{startRow:e,startColumn:t,endRow:i,endColumn:o,rangeType:s,startY:(h==null?void 0:h.startY)||0,endY:(g==null?void 0:g.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(g==null?void 0:g.endX)||0}}function Te(n,r){const{range:e,primary:t,style:i}=n,o=Gt(r,e),s=t&&Dn(r,t);return{rangeWithCoord:o,primaryWithCoord:s,style:i}}function Dn(n,r){const{actualRow:e,actualColumn:t,isMerged:i,isMergedMainCell:o,startRow:s,startColumn:l,endRow:c,endColumn:d}=r,u=n.getNoMergeCellWithCoordByIndex(e,t),h=n.getNoMergeCellWithCoordByIndex(s,l),g=n.getNoMergeCellWithCoordByIndex(c,d);return{actualRow:e,actualColumn:t,isMerged:i,isMergedMainCell:o,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 Ms="__SpreadsheetHelperSelectionTempRect",td=35;class Ps{constructor(r,e){T(this,"_startOffsetX",0);T(this,"_startOffsetY",0);T(this,"_relativeSelectionPositionRow",0);T(this,"_relativeSelectionPositionColumn",0);T(this,"_relativeSelectionRowLength",0);T(this,"_relativeSelectionColumnLength",0);T(this,"_scenePointerMoveSub");T(this,"_scenePointerUpSub");T(this,"_disabled",!1);T(this,"_helperSelection");T(this,"_scrollTimer");T(this,"_activeViewport");T(this,"_targetSelection",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});T(this,"_isInMergeState",!1);T(this,"_fillControlColors",[]);T(this,"_skeleton");T(this,"_scene");T(this,"_themeService");T(this,"_injector");T(this,"_selectionHooks");this._control=r,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 r,e;(r=this._scrollTimer)==null||r.dispose(),this._fillControlColors=[],this._clearObserverEvent(),(e=this._helperSelection)==null||e.dispose()}setDisabled(r){this._disabled=r}_getFreeze(){var e,t;return(t=(e=R.withCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET,y.SheetSkeletonManagerService,this._injector.get(a.IUniverInstanceService),this._injector.get(R.IRenderManagerService)))==null?void 0:e.getCurrentParam())==null?void 0:t.skeleton.getWorksheetConfig().freeze}_isSelectionInViewport(r,e){const t=this._getFreeze()||{startRow:-1,startColumn:-1};switch(e.viewportKey){case R.SHEET_VIEWPORT_KEY.VIEW_MAIN:return r.endRow>=t.startRow&&r.endColumn>=t.startColumn;case R.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP:case R.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT:return r.endColumn>=t.startColumn&&r.startRow<t.startRow;case R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT:case R.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM:return r.endRow>=t.startRow&&r.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 r.startRow<t.startRow&&r.startColumn<t.startColumn}}_clearObserverEvent(){var r,e;(r=this._scenePointerMoveSub)==null||r.unsubscribe(),(e=this._scenePointerUpSub)==null||e.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null}_initialControl(){const{leftControl:r,rightControl:e,topControl:t,bottomControl:i}=this._control;[r,e,t,i].forEach(o=>{o.onPointerEnter$.subscribeEvent(()=>{var l;((l=this._injector.get(ve,a.Quantity.OPTIONAL))==null?void 0:l.interceptor.fetchThroughInterceptors(Wr)(!1,null))!==!1&&o.setCursor(R.CURSOR_TYPE.MOVE)}),o.onPointerLeave$.subscribeEvent(()=>{o.resetCursor()}),o.onPointerDown$.subscribeEvent(this._controlPointerDownHandler.bind(this))})}_controlMoving(r,e){var k;const t=this._scene,i=t.getScrollXYInfoByViewport(R.Vector2.FromArray([r,e])),{scaleX:o,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(r,e,o,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=Te({range:{startRow:g,endRow:S,startColumn:f,endColumn:v},primary:p,style:null},this._skeleton),E=this._skeleton.getNoMergeCellWithCoordByIndex(g,f),w=this._skeleton.getNoMergeCellWithCoordByIndex(S,v),O=(E==null?void 0:E.startY)||0,M=(w==null?void 0:w.endY)||0,P=(E==null?void 0:E.startX)||0,A=(w==null?void 0:w.endX)||0;(k=this._helperSelection)==null||k.transformByState({left:P,top:O,width:A-P,height:M-O}),this._targetSelection={...b.rangeWithCoord},this._control.selectionMoving$.next(b.rangeWithCoord)}_controlPointerDownHandler(r){const{offsetX:e,offsetY:t}=r,i=this._scene,o=i.getCoordRelativeToViewport(R.Vector2.FromArray([e,t])),{x:s,y:l}=o,c=i.getScrollXYInfoByViewport(o),{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,E=0;g<f?b-=1:g>p&&(b+=1),S<v?E-=1:S>C&&(E+=1),this._relativeSelectionPositionRow=f-g+b,this._relativeSelectionPositionColumn=v-S+E,this._relativeSelectionRowLength=p-f,this._relativeSelectionColumnLength=C-v;const w=this._control.currentStyle,O=this._getScale();this.isHelperSelection&&(this._helperSelection=new R.Rect(Ms,{stroke:w.stroke,strokeWidth:w.strokeWidth/O}),i.addObject(this._helperSelection));const M=i.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN),P=R.ScrollTimer.create(i);this._scrollTimer=P,P.startScroll(s,l,M),i.disableObjectsEvent(),this._scenePointerMoveSub=i.onPointerMove$.subscribeEvent(A=>{var V;if(this._disabled)return;const{offsetX:k,offsetY:N}=A;if(((V=this._injector.get(ve,a.Quantity.OPTIONAL))==null?void 0:V.interceptor.fetchThroughInterceptors(Wr)(!1,null))===!1)return;const{x,y:L}=i.getCoordRelativeToViewport(R.Vector2.FromArray([k,N]));this._controlMoving(x,L),i.setCursor(R.CURSOR_TYPE.MOVE),P.scrolling(x,L,()=>{this._controlMoving(x,L)})}),this._scenePointerUpSub=i.onPointerUp$.subscribeEvent(()=>{var k,N,H,x;(k=this._helperSelection)==null||k.dispose();const A=this._scene;A.resetCursor(),this._clearObserverEvent(),A.enableObjectsEvent(),(N=this._scrollTimer)==null||N.dispose(),this._control.selectionMoveEnd$.next(this._targetSelection),(x=(H=this._selectionHooks).selectionMoveEnd)==null||x.call(H)})}_initialWidget(){const{topLeftWidget:r,topCenterWidget:e,topRightWidget:t,middleLeftWidget:i,middleRightWidget:o,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];[r,e,t,i,o,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(r,e){const t=this._scene,{offsetX:i,offsetY:o}=r,s=t.getCoordRelativeToViewport(R.Vector2.FromArray([i,o])),{x:l,y:c}=s;this._startOffsetX=i,this._startOffsetY=o;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(E=>{const{offsetX:w,offsetY:O}=E,{x:M,y:P}=t.getCoordRelativeToViewport(R.Vector2.FromArray([w,O]));this._widgetMoving(M,P,e),t.setCursor(e),C.scrolling(M,P,()=>{this._widgetMoving(M,P,e)})}),this._scenePointerUpSub=t.onPointerUp$.subscribeEvent(()=>{var w,O,M;const E=this._scene;E.resetCursor(),this._clearObserverEvent(),E.enableObjectsEvent(),(w=this._scrollTimer)==null||w.dispose(),this._control.selectionScaled$.next(this._targetSelection),(M=(O=this._selectionHooks).selectionMoveEnd)==null||M.call(O)})}_widgetMoving(r,e,t){const i=this._scene,o=i.getScrollXYInfoByViewport(R.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:s,scaleY:l}=i.getAncestorScale(),c=this._skeleton.getCellIndexByOffset(r,e,s,l,o),{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=Te({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:r}=this._control;r.onPointerEnter$.subscribeEvent(e=>{this._injector.get(ve).interceptor.fetchThroughInterceptors(xr)(!1,{x:e.offsetX,y:e.offsetY,skeleton:this._skeleton,scene:this._scene})&&r.setCursor(R.CURSOR_TYPE.CROSSHAIR)}),r.onPointerLeave$.subscribeEvent(()=>{r.resetCursor()}),r.onPointerDown$.subscribeEvent(this._autoFillForPointerdown.bind(this))}_autoFillMoving(r,e){var N,H,x;const t=this._scene,i=t.getViewportScrollXY(this._activeViewport),{scaleX:o,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(r,e,o,s,i),{row:c,column:d}=l,u=t.getCoordRelativeToViewport(R.Vector2.FromArray([r,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 L=this._fillRuler(d,f,p,this._relativeSelectionColumnLength,g);f=L.startRowOrColumn,p=L.endRowOrColumn,C=L.isLighten,b=!1}else if((c<S||c>v)&&d>=f&&d<=p){const L=this._fillRuler(c,S,v,this._relativeSelectionRowLength,h);S=L.startRowOrColumn,v=L.endRowOrColumn,C=L.isLighten}else if(Math.abs(this._startOffsetX-u.x-i.x)/2>Math.abs(this._startOffsetY-u.y-i.y)){const L=this._fillRuler(d,f,p,this._relativeSelectionColumnLength,g);f=L.startRowOrColumn,p=L.endRowOrColumn,C=L.isLighten,b=!1}else{const L=this._fillRuler(c,S,v,this._relativeSelectionRowLength,h);S=L.startRowOrColumn,v=L.endRowOrColumn,C=L.isLighten}const E=this._skeleton.getNoMergeCellWithCoordByIndex(S,f),w=this._skeleton.getNoMergeCellWithCoordByIndex(v,p),O=(E==null?void 0:E.startY)||0,M=(w==null?void 0:w.endY)||0,P=(E==null?void 0:E.startX)||0,A=(w==null?void 0:w.endX)||0;C?this._controlHandler((L,V)=>{const U=new a.ColorKit(this._fillControlColors[V]).lighten(td).toRgbString();L.setProps({fill:U})}):this._controlHandler((L,V)=>{L.setProps({fill:this._fillControlColors[V]})});const k=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();S===v&&b===!0||f===p&&b===!1?(N=this._helperSelection)==null||N.hide():((H=this._helperSelection)==null||H.transformByState({left:P-k/2,top:O-k/2,width:A-P,height:M-O}),(x=this._helperSelection)==null||x.show()),this._targetSelection={startY:O,endY:M,startX:P,endX:A,startRow:S,endRow:v,startColumn:f,endColumn:p},this._control.selectionFilling$.next(this._targetSelection)}_autoFillForPointerdown(r){const{offsetX:e,offsetY:t}=r,i=this._scene,o=i.getCoordRelativeToViewport(R.Vector2.FromArray([e,t])),{x:s,y:l}=o;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=at(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(Ms,{stroke:b,strokeWidth:f+C/2}),i.addObject(this._helperSelection)),this._activeViewport=i.getActiveViewportByCoord(R.Vector2.FromArray([e,t]));const E=i.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN),w=R.ScrollTimer.create(i,this._activeViewport.viewportKey===R.SHEET_VIEWPORT_KEY.VIEW_MAIN?R.ScrollTimerType.ALL:R.ScrollTimerType.NONE);w.startScroll(s,l,E),this._scrollTimer=w,i.disableObjectsEvent(),this._controlHandler(O=>{this._fillControlColors.push(O.fill)}),this._scenePointerMoveSub=i.onPointerMove$.subscribeEvent(O=>{var L;const{offsetX:M,offsetY:P}=O,A=i.getActiveViewportByCoord(R.Vector2.FromArray([M,P]));if(!this._injector.get(ve).interceptor.fetchThroughInterceptors(xr)(!1,{x:r.offsetX,y:r.offsetY,skeleton:this._skeleton,scene:this._scene}))return;const{x:N,y:H}=i.getCoordRelativeToViewport(R.Vector2.FromArray([M,P]));this._autoFillMoving(N,H),i.setCursor(R.CURSOR_TYPE.CROSSHAIR);const x=this._targetSelection;if(E&&A&&((L=this._activeViewport)==null?void 0:L.viewportKey)!==(A==null?void 0:A.viewportKey)){let V;x.startRow!==c?(w.scrollTimerType=R.ScrollTimerType.Y,V={...x,endRow:x.startRow}):x.endRow!==u?(w.scrollTimerType=R.ScrollTimerType.Y,V={...x,startRow:x.endRow}):x.startColumn!==d?(w.scrollTimerType=R.ScrollTimerType.X,V={...x,endColumn:x.startColumn}):(w.scrollTimerType=R.ScrollTimerType.X,V={...x,startColumn:x.endColumn}),this._isSelectionInViewport(V,A)&&(this._viewportMainScrollBarNeedResetPosition(w.scrollTimerType,this._activeViewport.viewportKey,A.viewportKey)&&E.scrollToBarPos({x:w.scrollTimerType===R.ScrollTimerType.X?0:void 0,y:w.scrollTimerType===R.ScrollTimerType.Y?0:void 0}),this._activeViewport=A)}w.scrolling(N,H,()=>{this._autoFillMoving(N,H)})}),this._scenePointerUpSub=i.onPointerUp$.subscribeEvent(()=>{var M,P;(M=this._helperSelection)==null||M.dispose();const O=this._scene;O.resetCursor(),this._clearObserverEvent(),O.enableObjectsEvent(),(P=this._scrollTimer)==null||P.dispose(),this._control.refreshSelectionFilled(this._targetSelection),this._isInMergeState=!1,this._controlHandler((A,k)=>{A.setProps({fill:this._fillControlColors[k]})}),this._fillControlColors=[]})}_viewportMainScrollBarNeedResetPosition(r,e,t){return r===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)||r===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(r,e,t,i){return this._skeleton.worksheet.getMergedCellRange(r,e,t,i).length>0}_swapPositions(r,e,t,i){const o=Math.min(r,t),s=Math.min(e,i),l=Math.max(r,t),c=Math.max(e,i);return{startRow:o,startColumn:s,endRow:l,endColumn:c}}_controlHandler(r){const{leftControl:e,rightControl:t,topControl:i,bottomControl:o,backgroundControlTop:s,backgroundControlMiddleLeft:l,backgroundControlMiddleRight:c,backgroundControlBottom:d,fillControl:u}=this._control,h=[e,t,i,o,s,l,c,d,u];for(let g=0,S=h.length;g<S;g++){const f=h[g];r(f,g)}}_fillRuler(r,e,t,i,o){let s=!1;if(r<e)if(this._isInMergeState&&r<e){const l=e-r,c=i+1,d=Math.ceil(l/c);let u=e-d*c;u<0&&(u=e-(d-1)*c),e=u}else e=r;else if(r>=e&&r<=t)s=!0,this._isInMergeState||(t=r);else if(this._isInMergeState&&r>t){const l=r-t,c=i+1,d=Math.ceil(l/c);let u=t+d*c;u>o&&(u=t+(d-1)*c),t=u}else t=r;return{rowOrColumn:r,startRowOrColumn:e,endRowOrColumn:t,isLighten:s}}_getScale(){const{scaleX:r,scaleY:e}=this._scene.getAncestorScale();return Math.max(r,e)}}var Ur=(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))(Ur||{});const Os=.3;class kn extends a.Disposable{constructor(e,t,i,o){var s,l,c,d;super();T(this,"_isHelperSelection",!0);T(this,"_enableAutoFill",!0);T(this,"_showAutoFill",!1);T(this,"_highlightHeader",!0);T(this,"_selectionRenderModel");T(this,"_leftBorder");T(this,"_rightBorder");T(this,"_topBorder");T(this,"_bottomBorder");T(this,"_backgroundControlTop");T(this,"_backgroundControlBottom");T(this,"_backgroundControlMiddleLeft");T(this,"_backgroundControlMiddleRight");T(this,"_autoFillControl");T(this,"_selectionShapeGroup");T(this,"_rowHeaderBackground");T(this,"_rowHeaderBorder");T(this,"_rowHeaderGroup");T(this,"_columnHeaderBackground");T(this,"_columnHeaderBorder");T(this,"_columnHeaderGroup");T(this,"_dashedRect");T(this,"_topLeftWidget");T(this,"_topCenterWidget");T(this,"_topRightWidget");T(this,"_middleLeftWidget");T(this,"_middleRightWidget");T(this,"_bottomLeftWidget");T(this,"_bottomCenterWidget");T(this,"_bottomRightWidget");T(this,"_defaultStyle");T(this,"_currentStyle");T(this,"_rowHeaderWidth",0);T(this,"_columnHeaderHeight",0);T(this,"_widgetRects",[]);T(this,"_controlExtension");T(this,"_dispose$",new D.BehaviorSubject(this));T(this,"dispose$",this._dispose$.asObservable());T(this,"selectionMoving$",new D.Subject);T(this,"selectionMoveEnd$",new D.Subject);T(this,"selectionScaling$",new D.Subject);T(this,"selectionScaled$",new D.Subject);T(this,"selectionFilling$",new D.Subject);T(this,"_selectionFilled$",new D.Subject);T(this,"selectionFilled$",this._selectionFilled$.asObservable());T(this,"_antLineOffset",0);T(this,"_antRequestNewFrame",-1);this._scene=e,this._zIndex=t,this._themeService=i,this._enableAutoFill=(s=o==null?void 0:o.enableAutoFill)!=null?s:!0,this._highlightHeader=(l=o==null?void 0:o.highlightHeader)!=null?l:!0,this._rowHeaderWidth=(c=o==null?void 0:o.rowHeaderWidth)!=null?c:0,this._columnHeaderHeight=(d=o==null?void 0:o.columnHeaderHeight)!=null?d:0,this._initializeSheetBody(),this._initialHeader()}_initializeSheetBody(){this._defaultStyle=at(this._themeService),this._currentStyle=at(this._themeService),this._selectionRenderModel=new ed;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,ki),this.disposeWithMe(a.toDisposable(i.onTransformChange$.subscribeEvent(o=>{o.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],$c)}_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 Ps(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:o,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:E}=this._selectionRenderModel;if(this.leftControl.transformByState({height:E-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:E-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:E-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 w=t.strokeWidth*2/g;this.dashedRect.transformByState({height:E-C,width:b-p,strokeWidth:w,left:-w/2+v,top:-w/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(o)){const w={fill:i,stroke:s,strokeScaleEnabled:!1},O={width:d-h,height:d-h,left:b-p-d/2+h/2-v,top:E-C-d/2+h/2-v,strokeWidth:h};this._autoFillControl.setProps(w),this._autoFillControl.transformByState(O),this._autoFillControl.show()}else this._autoFillControl.hide();this._updateBackgroundControl(t),this._updateHeaderBackground(t),this._updateWidgets(t)}_updateControlCoord(){const{startX:e,startY:t}=this._selectionRenderModel;this.selectionShapeGroup.show(),this.selectionShapeGroup.translate(e,t),this.selectionShapeGroup.makeDirtyNoDebounce(!0)}updateStyle(e){this._updateLayoutOfSelectionControl(e),this._updateControlCoord()}updateRange(e,t){this._selectionRenderModel.setValue(e,t),this._showAutoFill=t!==null,this._updateLayoutOfSelectionControl(),this._updateControlCoord()}updateRangeBySelectionWithCoord(e,t){t&&(this._rowHeaderWidth=t.rowHeaderWidth,this._columnHeaderHeight=t.columnHeaderHeight),this._selectionRenderModel.setValue(e.rangeWithCoord,e.primaryWithCoord),this._showAutoFill=e.primaryWithCoord!==null,this._updateLayoutOfSelectionControl(e.style),this._updateControlCoord()}update(e,t=0,i=0,o,s){this._rowHeaderWidth=t,this._columnHeaderHeight=i,this.updateRangeBySelectionWithCoord({rangeWithCoord:e,primaryWithCoord:s,style:o}),o&&this.updateStyle(o)}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,o,s,l,c,d,u,h,g,S,f,v,p,C,b,E,w,O,M,P,A,k,N;(e=this._leftBorder)==null||e.dispose(),(t=this._rightBorder)==null||t.dispose(),(i=this._topBorder)==null||i.dispose(),(o=this._bottomBorder)==null||o.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(),(E=this._topCenterWidget)==null||E.dispose(),(w=this._topRightWidget)==null||w.dispose(),(O=this._middleLeftWidget)==null||O.dispose(),(M=this._middleRightWidget)==null||M.dispose(),(P=this._bottomLeftWidget)==null||P.dispose(),(A=this._bottomCenterWidget)==null||A.dispose(),(k=this._bottomRightWidget)==null||k.dispose(),(N=this._controlExtension)==null||N.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:o,startX:s,endX:l,startY:c,endY:d}=e;t={startRow:i,endRow:i,startColumn:o,endColumn:o,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:o,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 E=S;l===a.RANGE_TYPE.COLUMN&&(E=new a.ColorKit(u).setAlpha(Os).toString()),this._columnHeaderBackground.setProps({fill:E}),this._columnHeaderBackground.resize(o-t,b),this._columnHeaderBorder.setProps({fill:f}),this._columnHeaderBorder.transformByState({width:o-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 E=h;l===a.RANGE_TYPE.ROW&&(E=new a.ColorKit(u).setAlpha(Os).toString()),this._rowHeaderBackground.setProps({fill:E}),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:o,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(o-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:o-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:o-S+v*2,height:f-g};b.width<0&&(b.width=0,b.height=0),this._backgroundControlMiddleRight.transformByState(b);const E={left:-v,top:f-i,width:o-t+v*2,height:s-f+v};E.height<0&&(E.width=0,E.height=0),this._backgroundControlBottom.transformByState(E),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:o,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:(o-t)/2-h/2+g/2,right:o-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 nd extends R.Layer{render(r,e=!1){const t=a.Tools.now();return super.render(r,e),this._afterRender(t),this}_afterRender(r){this.scene.getEngine().renderFrameTimeMetric$.next(["selectionLayer",a.Tools.now()-r])}}const ve=a.createIdentifier("univer.sheet.selection-render-service");class Br extends a.Disposable{constructor(e,t,i,o,s){super();T(this,"_downObserver");T(this,"_scenePointerMoveSub");T(this,"_scenePointerUpSub");T(this,"_controlFillConfig$",new D.BehaviorSubject(null));T(this,"controlFillConfig$",this._controlFillConfig$.asObservable());T(this,"_selectionControls",[]);T(this,"_startRangeWhenPointerDown",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});T(this,"_activeControlIndex",-1);T(this,"_startViewportPosX",0);T(this,"_startViewportPosY",0);T(this,"_scrollTimer");T(this,"_cancelDownSubscription");T(this,"_cancelUpSubscription");T(this,"_skeleton");T(this,"_scene");T(this,"_highlightHeader",!0);T(this,"_rangeType",a.RANGE_TYPE.NORMAL);T(this,"_selectionStyle");T(this,"_remainLastEnabled",!1);T(this,"_skipLastEnabled",!1);T(this,"_singleSelectionEnabled",!1);T(this,"_selectionMoveEnd$",new D.BehaviorSubject([]));T(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());T(this,"_selectionMoving$",new D.Subject);T(this,"selectionMoving$",this._selectionMoving$.asObservable());T(this,"_selectionMoveStart$",new D.Subject);T(this,"selectionMoveStart$",this._selectionMoveStart$.asObservable());T(this,"_selectionMoving",!1);T(this,"_selectionTheme");T(this,"_activeViewport");T(this,"interceptor",new a.InterceptorManager({RANGE_MOVE_PERMISSION_CHECK:Wr,RANGE_FILL_PERMISSION_CHECK:xr}));T(this,"_escapeShortcutDisposable",null);this._injector=e,this._themeService=t,this._shortcutService=i,this._sheetSkeletonManagerService=o,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 o=this.getSelectionControls().length,{rowHeaderWidth:s,columnHeaderHeight:l}=t,c=new kn(e,o,this._selectionTheme,{highlightHeader:this._highlightHeader,rowHeaderWidth:s,columnHeaderHeight:l});this._selectionControls.push(c);const d=Te(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 o=0,s=e.length;o<s;o++){const l=e[o],c=Te(l,this._skeleton),d=t[o];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(ki)||t.addLayer(new nd(t,[],ki))}getSkeleton(){return this._skeleton}getSelectionDataWithStyle(){const e=this._selectionControls,[t,i]=this._skeleton.getLocation();return e.map(o=>{const s=o.getValue();return s.rangeWithCoord.sheetId=i,s.rangeWithCoord.unitId=t,s})}getSelectionControls(){return this._selectionControls}_addSelectionControlByModelData(e){var l;const t=this._skeleton,i=(l=e.style)!=null?l:at(this._selectionTheme),o=this._scene;return e.style=i,this.newSelectionControl(o,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,o=R.ScrollTimerType.ALL,s,l){var f,v;let c=0,d=0,u=s,h=l;this._scrollTimer=R.ScrollTimer.create(this._scene,o),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 x,L,V,U,B,Y,F,z,j;const{offsetX:C,offsetY:b}=p,{x:E,y:w}=g.getCoordRelativeToViewport(R.Vector2.FromArray([C,b]));this._movingHandler(E,w,t,i);let O=E,M=w;const P=this.getActiveSelectionControl(),A=this._getFreeze(),k=P==null?void 0:P.model,N=(x=g.getActiveViewportByCoord(R.Vector2.FromArray([C,b])))!=null?x:this._getViewportByCell(k==null?void 0:k.endRow,k==null?void 0:k.endColumn);if((()=>{if(!S||!N||!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(N.viewportKey)})()){if(!S||!N||!e)return!1;const Q=u<e.left&&E>e.left||u>e.left&&E<e.left,ie=h<e.top&&w>e.top||h>e.top&&w<e.top;Q&&(c+=1),ie&&(d+=1);const $=S.viewportKey,se=N.viewportKey;if($===R.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP)b<e.top&&((L=k==null?void 0:k.endRow)!=null?L:0)<((V=A==null?void 0:A.startRow)!=null?V:0)?M=e.top:ie&&d%2===1&&e.scrollToViewportPos({viewportScrollY:0});else if($===R.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT)C<e.left&&((U=k==null?void 0:k.endColumn)!=null?U:0)<((B=A==null?void 0:A.startColumn)!=null?B:0)?O=e.left:Q&&c%2===1&&e.scrollToViewportPos({viewportScrollX:0});else if($===se){let Z=!1,G=!1;$===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP?(Z=!0,G=!0):$===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP?G=!0:$===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT&&(Z=!0),((Y=k==null?void 0:k.endRow)!=null?Y:0)>((F=A==null?void 0:A.startRow)!=null?F:0)&&(G=!1),((z=k==null?void 0:k.endColumn)!=null?z:0)>((j=A==null?void 0:A.startColumn)!=null?j:0)&&(Z=!1),Z&&(O=e.left),G&&(M=e.top)}else{const Z={x:S.scrollX,y:S.scrollY},G={x:N.scrollX,y:N.scrollY},J=Z.x!==G.x&&Q&&c%2===1,re=Z.y!==G.y&&ie&&d%2===1;(J||re)&&(e.scrollToBarPos({x:J?Z.x:void 0,y:re?Z.y:void 0}),J||(O=e.left),re||(M=e.top)),($===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&se===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||se===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&$===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)&&(O=e.left),($===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&se===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||se===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&$===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP)&&(M=e.top)}u=E,h=w}this._scrollTimer.scrolling(O,M,()=>{this._movingHandler(E,w,t,i)})})}attachSelectionWithCoord(e){return Te(e,this._skeleton)}attachPrimaryWithCoord(e){return Dn(this._skeleton,e)}getSelectionCellByPosition(e,t){return this.getCellWithCoordByOffset(e,t)}getCellWithCoordByOffset(e,t,i){const o=this._scene,s=i!=null?i:this._skeleton,l=o.getViewportScrollXY(o.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:c,scaleY:d}=o.getAncestorScale();return s.getCellWithCoordByOffset(e,t,c,d,l)}_movingHandler(e,t,i,o){var O,M,P,A,k;const s=this._skeleton,l=this._scene,[c,d]=s.getLocation(),u={startRow:(O=i==null?void 0:i.model.startRow)!=null?O:-1,endRow:(M=i==null?void 0:i.model.endRow)!=null?M:-1,startColumn:(P=i==null?void 0:i.model.startColumn)!=null?P:-1,endColumn:(A=i==null?void 0:i.model.endColumn)!=null?A:-1},h=l.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=(k=this._getViewportByCell(u.endRow,u.endColumn))!=null?k:h,S=l.getScrollXYInfoByViewport(R.Vector2.FromArray([this._startViewportPosX,this._startViewportPosY]),g),{scaleX:f,scaleY:v}=l.getAncestorScale();o===a.RANGE_TYPE.ROW?e=Number.POSITIVE_INFINITY:o===a.RANGE_TYPE.COLUMN&&(t=Number.POSITIVE_INFINITY);const p=this._skeleton.getCellByOffset(e,t,f,v,S);if(!p)return;let C={startRow:Math.min(p.startRow,this._startRangeWhenPointerDown.startRow),startColumn:Math.min(p.startColumn,this._startRangeWhenPointerDown.startColumn),endRow:Math.max(p.endRow,this._startRangeWhenPointerDown.endRow),endColumn:Math.max(p.endColumn,this._startRangeWhenPointerDown.endColumn)};this._shouldDetectMergedCells&&(C=s.expandRangeByMerge(C));const E=Te({range:C,primary:void 0,style:null},s);E.rangeWithCoord.unitId=c,E.rangeWithCoord.sheetId=d,E.rangeWithCoord.rangeType=o;const w=u.startRow!==C.startRow||u.startColumn!==C.startColumn||u.endRow!==C.endRow||u.endColumn!==C.endColumn;i!=null&&w&&(i.updateRangeBySelectionWithCoord(E),this._selectionMoving$.next(this.getSelectionDataWithStyle()))}_clearUpdatingListeners(){var t,i,o,s,l;this._scene.enableObjectsEvent(),(t=this._scenePointerMoveSub)==null||t.unsubscribe(),this._scenePointerMoveSub=null,(i=this._scenePointerUpSub)==null||i.unsubscribe(),this._scenePointerUpSub=null,(o=this._cancelDownSubscription)==null||o.unsubscribe(),this._cancelDownSubscription=null,(s=this._cancelUpSubscription)==null||s.unsubscribe(),this._cancelUpSubscription=null,(l=this._scrollTimer)==null||l.dispose()}_addEndingListeners(){var i,o,s;const e=this._scene,t=(i=e.getEngine())==null?void 0:i.activeScene;!t||t===e||((o=this._cancelDownSubscription)==null||o.unsubscribe(),this._cancelDownSubscription=null,(s=this._cancelUpSubscription)==null||s.unsubscribe(),this._cancelUpSubscription=null,this._cancelDownSubscription=t.onPointerDown$.subscribeEvent(()=>this._clearUpdatingListeners()),this._cancelUpSubscription=t.onPointerUp$.subscribeEvent(()=>this._clearUpdatingListeners()))}_getSelectionWithCoordByOffset(e,t,i,o,s){const l=this._skeleton;if(l==null)return null;if(this._shouldDetectMergedCells){const C=l==null?void 0:l.getCellWithCoordByOffset(e,t,i,o,s,{firstMatch:!0});if(!C)return;const b=a.convertCellToRange(C);return{primaryWithCoord:C,rangeWithCoord:b}}const{row:c,column:d}=l.getCellIndexByOffset(e,t,i,o,s),u=l.getNoMergeCellWithCoordByIndex(c,d),{startX:h,startY:g,endX:S,endY:f}=u,v={startY:g,endY:f,startX:h,endX:S,startRow:c,endRow:c,startColumn:d,endColumn:d};return{primaryWithCoord:{mergeInfo:v,actualRow:c,actualColumn:d,isMerged:!1,isMergedMainCell:!1,startY:g,endY:f,startX:h,endX:S},rangeWithCoord:v}}_checkClearPreviousControls(e){this.getSelectionControls().length!==0&&(!e.ctrlKey&&!e.shiftKey&&!this._remainLastEnabled||this._singleSelectionEnabled&&!e.shiftKey)&&this._clearAllSelectionControls()}_makeSelectionByTwoCells(e,t,i,o,s){const{actualRow:l,actualColumn:c,mergeInfo:d}=e;this._startRangeWhenPointerDown={...e.mergeInfo};const u=Math.min(l,t.startRow,d.startRow),h=Math.max(l,t.endRow,d.endRow),g=Math.min(c,t.startColumn,d.startColumn),S=Math.max(c,t.endColumn,d.endColumn),v={range:i.expandRangeByMerge({startRow:u,startColumn:g,endRow:h,endColumn:S}),primary:null,style:null},p=Te(v,i);s.updateRangeBySelectionWithCoord(p)}isSelectionEnabled(){return this.contextService.getContextValue(m.SELECTIONS_ENABLED)}isSelectionDisabled(){return this.contextService.getContextValue(m.SELECTIONS_ENABLED)===!1}inRefSelectionMode(){return this.contextService.getContextValue(m.REF_SELECTIONS_ENABLED)}}function Fr(n){return{range:{startRow:0,startColumn:0,endRow:n.getRowCount()-1,endColumn:n.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL},primary:Vi(n).primary,style:null}}function Vi(n){return As(n,{startRow:0,startColumn:0,endRow:0,endColumn:0})}function As(n,r){const e=n.worksheet.getCellInfoInMergeData(r.startRow,r.startColumn),t=n.worksheet.getCellInfoInMergeData(r.endRow,r.endColumn);return{range:{startRow:e.startRow,startColumn:e.startColumn,endRow:t.endRow,endColumn:t.endColumn,rangeType:a.RANGE_TYPE.NORMAL},primary:{actualRow:e.startRow,actualColumn:e.startColumn,startRow:e.startRow,startColumn:e.startColumn,endRow:e.endRow,endColumn:e.endColumn,isMerged:e.isMerged,isMergedMainCell:e.isMergedMainCell},style:null}}var id=Object.getOwnPropertyDescriptor,rd=(n,r,e,t)=>{for(var i=t>1?void 0:t?id(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},Ds=(n,r)=>(e,t)=>r(e,t,n);y.SheetSkeletonManagerService=class extends a.Disposable{constructor(e,t,i){super();T(this,"_sheetId","");T(this,"_sheetSkeletonParamStore",new Map);T(this,"_currentSkeleton$",new D.BehaviorSubject(null));T(this,"currentSkeleton$",this._currentSkeleton$.asObservable());T(this,"_currentSkeletonBefore$",new D.BehaviorSubject(null));T(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._context=e,this._injector=t,this._sheetSkService=i,this.disposeWithMe(()=>{this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._sheetSkeletonParamStore.forEach(o=>this.disposeSkeleton(o.sheetId)),this._sheetSkeletonParamStore.clear()}),this._initRemoveSheet()}_initRemoveSheet(){this.disposeWithMe(this._context.unit.sheetDisposed$.subscribe(e=>{this.disposeSkeleton(e.getSheetId())}))}getCurrentSkeleton(){var e;return(e=this.getCurrentParam())==null?void 0:e.skeleton}getCurrent(){return this.getCurrentParam()}getCurrentParam(){return this._getSkeletonParam(this._sheetId)}getSkeleton(e){return this._getSkeleton(e)}getSkeletonParam(e){return this._getSkeletonParam(e)}getWorksheetSkeleton(e){return this.getSkeletonParam(e)}getUnitSkeleton(e,t){const i=this._getSkeletonParam(t);return i!=null&&(i.unitId=e),i}setCurrent(e){this._setCurrent(e.sheetId)}setSkeletonParam(e,t){this._sheetSkService.setSkeleton(t.unitId,e,t.skeleton),this._sheetSkeletonParamStore.set(e,t)}_setCurrent(e){this._sheetId=e;const t=this._getSkeletonParam(e),i=this._context.unitId;if(t!=null)this.reCalculate(t);else{const l=this._context.unit.getSheetBySheetId(e);if(l==null)return;const c=this._context.scene,d=this._buildSkeleton(l,c);this.setSkeletonParam(e,{unitId:i,sheetId:e,skeleton:d,dirty:!1})}const o=this._getSkeletonParam(e);this._currentSkeletonBefore$.next(o),this._currentSkeleton$.next(o)}reCalculate(e){e||(e=this.getCurrentParam()),e!=null&&(e.dirty&&(e.skeleton.makeDirty(!0),e.dirty=!1),e.skeleton.calculate())}makeDirty(e,t=!0){const i=this._getSkeletonParam(e.sheetId);i!=null&&(i.dirty=t)}getOrCreateSkeleton(e){return this.ensureSkeleton(e.sheetId)}ensureSkeleton(e){const t=this._getSkeletonParam(e);if(t)return t.skeleton;const o=this._context.unit.getSheetBySheetId(e);if(!o)return;const s=this._buildSkeleton(o);return this.setSkeletonParam(e,{unitId:this._context.unitId,sheetId:e,skeleton:s,dirty:!1}),s}disposeSkeleton(e){const t=this.getSkeletonParam(e);t&&(t.skeleton.dispose(),this._sheetSkeletonParamStore.delete(e),this._sheetSkService.deleteSkeleton(t.unitId,e))}attachRangeWithCoord(e){const t=this.getCurrentSkeleton();return t?Gt(t,e):null}_getSkeletonParam(e){return this._sheetSkeletonParamStore.get(e)}_getSkeleton(e){const t=this._getSkeletonParam(e);return t?t.skeleton:null}_buildSkeleton(e,t){return this._injector.createInstance(R.SpreadsheetSkeleton,e,this._context.unit.getStyles())}setColumnHeaderSize(e,t,i){var u;if(!e)return;const o=(u=this.getWorksheetSkeleton(t))==null?void 0:u.skeleton;if(!o)return;o.columnHeaderHeight=i,e.scene.getViewports()[0].top=i,e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({height:i}),e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({height:i}),e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({top:i}),e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({top:i}),e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({height:i});const s=e==null?void 0:e.with(m.SheetsSelectionsService),l=e==null?void 0:e.with(ve),c=s.getCurrentSelections();l.resetSelectionsByModelData(c);const d=this.getUnitSkeleton(e.unitId,t);d&&(d.commandId=Hi.id,this._currentSkeleton$.next(d))}setRowHeaderSize(e,t,i){var f;const o=(f=this.getWorksheetSkeleton(t))==null?void 0:f.skeleton;if(!e||!o)return;o.rowHeaderWidth=i;const s=e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).width||46,l=i-s,c=e.scene.getViewports()[0].left;e.scene.getViewports()[0].left=c+l,e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({width:i}),e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({width:i}),e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({left:i});const d=e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).left||0;e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({left:d+l}),e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({width:i});const u=e==null?void 0:e.with(m.SheetsSelectionsService),h=e==null?void 0:e.with(ve),g=u.getCurrentSelections();h.resetSelectionsByModelData(g);const S=this.getCurrent();S&&(S.commandId=Ni.id,this._currentSkeleton$.next(S))}},y.SheetSkeletonManagerService=rd([Ds(1,a.Inject(a.Injector)),Ds(2,a.Inject(m.SheetSkeletonService))],y.SheetSkeletonManagerService);function lt(){const n=_.useDependency(a.IUniverInstanceService),r=_.useObservable(()=>n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]);return r!=null?r:null}function od(n){return _.useObservable(()=>{var e;return(e=n==null?void 0:n.activeSheet$)!=null?e:D.of(null)},void 0,void 0,[n])}function sd(){const n=_.useDependency(a.IUniverInstanceService);return _.useObservable(()=>D.merge([n.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET),n.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET)]).pipe(D.map(()=>n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET)),D.startWith(n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET))),[],void 0,[n])}const ad="SheetUI";var zr=(n=>(n.FILTER_PANEL_EMBED_POINT="filter-panel-embed-point",n.SHEETS_FOOTER="sheets-footer",n.FORMULA_AUX="formula-aux",n))(zr||{}),ld=Object.getOwnPropertyDescriptor,cd=(n,r,e,t)=>{for(var i=t>1?void 0:t?ld(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},Nn=(n,r)=>(e,t)=>r(e,t,n);const ks=["ff","fs","tr","tb"];y.AutoHeightController=class extends a.Disposable{constructor(r,e,t,i,o){super(),this._renderManagerService=r,this._sheetInterceptorService=e,this._selectionManagerService=t,this._univerInstanceService=i,this._configService=o,this._initialize()}_processLazyAutoHeight(r,e,t,i){if(i!=null&&i.length){const o={id:m.MarkDirtyRowAutoHeightMutation.id,params:{unitId:e,subUnitId:t,ranges:i,id:a.generateRandomId()},options:{onlyLocal:!0}},s={id:m.CancelMarkDirtyRowAutoHeightMutation.id,params:{unitId:e,subUnitId:t,id:o.params.id},options:{onlyLocal:!0}};return{redos:[...r.redos,o],undos:[...r.undos,s]}}return r}getUndoRedoParamsOfAutoHeight(r,e,t){const{_univerInstanceService:i}=this,o=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=o.getUnitId();let l=o.getActiveSheet(),c=l.getSheetId();if(e){const v=m.getSheetCommandTarget(i,{unitId:s,subUnitId:e});v&&(l=v.worksheet,c=l.getSheetId())}const u=this._renderManagerService.getRenderById(s).with(y.SheetSkeletonManagerService).ensureSkeleton(c);if(!u)return{redos:[],undos:[]};const g=u.calculateAutoHeightInRange(r,t).filter(v=>{const{row:p,autoHeight:C}=v;return!(!C||l.getRowHeight(p)===C)});if(g.length===0)return{redos:[],undos:[]};const S={subUnitId:c,unitId:s,rowsAutoHeightInfo:g},f=m.SetWorksheetRowAutoHeightMutationFactory(S,l);return{undos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:f}],redos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:S}]}}_initialize(){this.disposeWithMe(this._sheetInterceptorService.interceptAutoHeight({getMutations:r=>{const{unitId:e,subUnitId:t,ranges:i,autoHeightRanges:o,lazyAutoHeightRanges:s,cellHeights:l}=r,c=this.getUndoRedoParamsOfAutoHeight(o!=null?o:i,t,l);return this._processLazyAutoHeight(c,e,t,s)}}))}},y.AutoHeightController=cd([Nn(0,R.IRenderManagerService),Nn(1,a.Inject(m.SheetInterceptorService)),Nn(2,a.Inject(m.SheetsSelectionsService)),Nn(3,a.Inject(a.IUniverInstanceService)),Nn(4,a.IConfigService)],y.AutoHeightController);function ct(n){const{rows:r,cols:e}=n;return{startRow:r[0],endRow:r[r.length-1],startColumn:e[0],endColumn:e[e.length-1]}}function dt(n){let r=[],e=[];const t=[];return n.forEach(i=>{r=r.concat(i.rows),e=e.concat(i.cols)}),r=Array.from(new Set(r)).sort((i,o)=>i-o),e=Array.from(new Set(e)).sort((i,o)=>i-o),n.forEach(i=>{t.push({startRow:r.findIndex(o=>o===i.rows[0]),endRow:r.findIndex(o=>o===i.rows[i.rows.length-1]),startColumn:e.findIndex(o=>o===i.cols[0]),endColumn:e.findIndex(o=>o===i.cols[i.cols.length-1])})}),{ranges:t,mapFunc:(i,o)=>({row:r[i],col:e[o]})}}function dd(n){const r=new a.ObjectMatrix;return n.forEach(e=>{const{rows:t,cols:i}=e;t.forEach(o=>{i.forEach(s=>{r.setValue(o,s,{v:null,p:null,f:null,si:null,custom:null})})})}),r.getData()}const Xr={零:0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9},Wi=["零","一","二","三","四","五","六","七","八","九"],Ns=["","万","亿","万亿","亿亿"],ud=["","十","百","千"],Hs={十:{value:10,secUnit:!1},百:{value:100,secUnit:!1},千:{value:1e3,secUnit:!1},万:{value:1e4,secUnit:!0},亿:{value:1e8,secUnit:!0}};function Qe(n){if(!n)return 0;let r=0,e=0,t=0,i=!1;const o=n.split("");for(let s=0;s<o.length;s++){const l=Xr[o[s]];if(typeof l<"u")t=l,s===o.length-1&&(e+=t);else{const c=Hs[o[s]],d=c.value;i=c.secUnit,i?(e=(e+t)*d,r+=e,e=0):e+=t*d,t=0}}return r+e}function hd(n){let r="",e="",t=0,i=!0;for(;n>0;){const o=n%10;o===0?i||(i=!0,e=Wi[o]+e):(i=!1,r=Wi[o],r+=ud[t],e=r+e),t++,n=Math.floor(n/10)}return e}function md(n){let r=0,e="",t="",i=!1;if(n===0)return Wi[0];for(;n>0;){const o=n%1e4;i&&(t=Wi[0]+t),e=hd(o),e+=o!==0?Ns[r]:Ns[0],t=e+t,i=o<1e3&&o>0,n=Math.floor(n/1e4),r++}return t}function gd(n){if(!n)return!1;let r=!0;if(n)if(n.length===1)n==="日"||n in Xr?r=!0:r=!1;else{const e=n.split("");for(let t=0;t<e.length;t++)if(!(e[t]in Xr||e[t]in Hs)){r=!1;break}}return r}function xi(n){if(!n)return{isExtendNumber:!1};const r=/0|([1-9]+[0-9]*)/g,e=r.test(n);if(e){const t=n.match(r);if(t&&t.length>0){const i=t[t.length-1],o=n.lastIndexOf(i),s=n.substr(0,o),l=n.substr(o+i.length);return{isExtendNumber:!0,matchTxt:Number(i),beforeTxt:s,afterTxt:l}}return{isExtendNumber:!1}}return{isExtendNumber:e}}function Sd(n){let r;return n.length===2&&(n==="周一"||n==="周二"||n==="周三"||n==="周四"||n==="周五"||n==="周六"||n==="周日")?r=!0:r=!1,r}function fd(n){let r;return n.length===3&&(n==="星期一"||n==="星期二"||n==="星期三"||n==="星期四"||n==="星期五"||n==="星期六"||n==="星期日")?r=!0:r=!1,r}function vd(n,r){let e=0;for(let t=0;t<n.length&&n[t]<r;t++)e++;return e}function Hn(n){let r=!0;const e=n[1]-n[0];for(let t=1;t<n.length;t++)if(n[t]-n[t-1]!==e){r=!1;break}return r}function pd(n,r,e){const t=[],i=Math.floor(r/n),o=r%n;let s=0;if(i>0){for(let l=0;l<i;l++)for(let c=0;c<e.length;c++)t[e[c]+l*n]=s,s++;for(let l=0;l<e.length&&e[l]<o;l++)t[e[l]+n*i]=s,s++}else for(let l=0;l<e.length&&e[l]<o;l++)t[e[l]]=s,s++;return t}function It(n,r){const e=[];for(let t=1;t<=r;t++){const i=(t-1)%n.length,o=a.Tools.deepClone(n[i]);bt(o),e.push({v:null,s:null,p:null,f:null,si:null,t:null,...o})}return e}function Cd(n,r){var t;const e=[];for(let i=1;i<=r;i++){const o=(i-1)%n.length,s={s:(t=n[o])==null?void 0:t.s};e.push(s)}return e}function _d(n){let r=!0;const e=n[1]/n[0];for(let t=1;t<n.length;t++)if(n[t]/n[t-1]!==e){r=!1;break}return r}function Id(n){const r=[];for(let e=1;e<=n;e++)r.push(e);return r}function Li(n,r,e){var o,s,l,c;const t=[],i=[];for(let d=0;d<n.length;d++)i.push(Number((o=n[d])==null?void 0:o.v));if(n.length>2&&_d(i))for(let d=1;d<=r;d++){const u=(d-1)%n.length,h=a.Tools.deepClone(n[u]);bt(h);const g=Number((s=n[n.length-1])==null?void 0:s.v)*(Number((l=n[1])==null?void 0:l.v)/Number((c=n[0])==null?void 0:c.v))**d;h&&(Ls(h)&&(h.v=g),t.push(h))}else{const d=Id(n.length);for(let u=1;u<=r;u++){const h=(u-1)%n.length,g=a.Tools.deepClone(n[h]);bt(g);const S=e===a.Direction.DOWN||e===a.Direction.RIGHT,f=bd(n.length+u,i,d,S);g&&(Ls(g)&&(g.v=f),t.push(g))}}return t}function bd(n,r,e,t=!0){function i(h){let g=0;for(let S=0;S<h.length;S++)g+=h[S];return g/h.length}const o=i(e),s=i(r);let l=0,c=0;for(let h=0;h<e.length;h++)l+=(e[h]-o)*(r[h]-s),c+=(e[h]-o)*(e[h]-o);let d;c===0?d=t?1:-1:d=l/c;const u=s-d*o;return Math.round((u+d*n)*1e5)/1e5}function Vs(n,r,e){var o;const t=[],i=/0|([1-9]+[0-9]*)/g;for(let s=1;s<=r;s++){const l=(s-1)%n.length,c=a.Tools.deepClone(n[l]);bt(c);const d=`${(o=n[n.length-1])==null?void 0:o.v}`;if(!d)continue;const u=d==null?void 0:d.match(i),h=u==null?void 0:u[u.length-1];if(!h)continue;const g=Math.abs(Number(h)+e*s),S=d.lastIndexOf(h),f=d.substr(0,S)+g.toString()+d.substr(S+h.length);c&&(c.v=f,t.push(c))}return t}function Zt(n,r,e,t=0){var l,c;const i=[["日","一","二","三","四","五","六"],["周日","周一","周二","周三","周四","周五","周六"],["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]];if(t>=i.length)return[];const o=i[t],s=[];for(let d=1;d<=r;d++){const u=(d-1)%n.length,h=a.Tools.deepClone(n[u]);bt(h);let g=0;if(((l=n[n.length-1])==null?void 0:l.v)===o[0])g=7+e*d;else{const f=`${(c=n[n.length-1])==null?void 0:c.v}`;if(f){const v=f.substr(f.length-1,1);g=Qe(v)+e*d}}g<0&&(g=Math.ceil(Math.abs(g)/7)*7+g);const S=g%7;h&&(h.v=o[S],s.push(h))}return s}function Ws(n,r,e){var i;const t=[];for(let o=1;o<=r;o++){const s=(o-1)%n.length,l=a.Tools.deepClone(n[s]);bt(l);const c=`${(i=n[n.length-1])==null?void 0:i.v}`,d=Qe(c)+e*o;let u;d<=0?u="零":u=md(d),l&&(l.v=u,t.push(l))}return t}const Vn={enWeek1:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],enWeek2:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],enMonth1:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],enMonth2:["January","February","March","April","May","June","July","August","September","October","November","December"],chnMonth1:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],chnMonth2:["正月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","腊月"],chHour1:["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"],chHour2:["子时","丑时","寅时","卯时","辰时","巳时","午时","未时","申时","酉时","戌时","亥时"],chYear1:["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"],chSeason1:["春","夏","秋","冬"],chSeason2:["春季","夏季","秋季","冬季"]};function wd(n){let r=!1;return Object.keys(Vn).forEach(e=>{Vn[e].includes(n)&&(r=!0)}),r}function Yr(n){let r="";const e=[];return Object.keys(Vn).forEach(t=>{Vn[t].includes(n)&&(r=t,e.push(...Vn[t]))}),{name:r,series:e}}function xs(n,r,e,t){var s;const i=t.length,o=[];for(let l=1;l<=r;l++){const c=(l-1)%n.length,d=a.Tools.deepClone(n[c]);bt(d);const u=`${(s=n[n.length-1])==null?void 0:s.v}`;let h=t.indexOf(u)+e*l;h<0&&(h+=Math.abs(e)*i);const g=h%i;d&&(d.v=t[g],o.push(d))}return o}function Ed(n,r){const e=[];let t;if(r.startRow<n.startRow)t=a.Direction.UP;else if(r.endRow>n.endRow)t=a.Direction.DOWN;else if(r.startColumn<n.startColumn)t=a.Direction.LEFT;else if(r.endColumn>n.endColumn)t=a.Direction.RIGHT;else return[];if(t===a.Direction.DOWN||t===a.Direction.UP){const i=n.endRow-n.startRow+1,o=r.endRow-r.startRow+1,s=Math.floor(o/i),l=o%i,c={startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:n.endColumn-n.startColumn};if(t===a.Direction.DOWN){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow+(d+1)*i,col:n.startColumn},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow+(s+1)*i,col:n.startColumn},relativeRange:{startRow:0,startColumn:0,endRow:l-1,endColumn:n.endColumn-n.startColumn}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow-(d+1)*i,col:n.startColumn},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow-(s+1)*i,col:n.startColumn},relativeRange:{startRow:i-l,endRow:i-1,startColumn:0,endColumn:n.endColumn-n.startColumn}})}}if(t===a.Direction.RIGHT||t===a.Direction.LEFT){const i=n.endColumn-n.startColumn+1,o=r.endColumn-r.startColumn+1,s=Math.floor(o/i),l=o%i,c={startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:n.endColumn-n.startColumn};if(t===a.Direction.RIGHT){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow,col:n.startColumn+(d+1)*i},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow,col:n.startColumn+(s+1)*i},relativeRange:{startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:l-1}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow,col:n.startColumn-(d+1)*i},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow,col:n.startColumn-(s+1)*i},relativeRange:{startRow:0,startColumn:i-l,endRow:n.endRow-n.startRow,endColumn:i-1}})}}return e}function Ls(n){return!(a.isFormulaString(n.f)||a.isFormulaId(n.si)||n.t===a.CellValueType.BOOLEAN)}function bt(n){n&&"custom"in n&&delete n.custom}var Kt=(n=>(n.Append="APPEND",n.Default="DEFAULT",n.Only="ONLY",n))(Kt||{}),Ie=(n=>(n.NUMBER="number",n.DATE="date",n.EXTEND_NUMBER="extendNumber",n.CHN_NUMBER="chnNumber",n.CHN_WEEK2="chnWeek2",n.CHN_WEEK3="chnWeek3",n.LOOP_SERIES="loopSeries",n.FORMULA="formula",n.OTHER="other",n))(Ie||{}),ce=(n=>(n.COPY="COPY",n.SERIES="SERIES",n.ONLY_FORMAT="ONLY_FORMAT",n.NO_FORMAT="NO_FORMAT",n))(ce||{});const Td={type:Ie.DATE,priority:1100,match:(n,r)=>{var e;if(n!=null&&n.f||n!=null&&n.si)return!1;if((typeof(n==null?void 0:n.v)=="number"||(n==null?void 0:n.t)===a.CellValueType.NUMBER)&&n.s){if(typeof n.s=="string"){const i=r.get(a.IUniverInstanceService).getFocusedUnit().getStyles().get(n.s),o=(e=i==null?void 0:i.n)==null?void 0:e.pattern;if(o)return a.numfmt.getFormatInfo(o).isDate}else if(n.s.n&&a.numfmt.getFormatInfo(n.s.n.pattern).isDate)return!0}return!1},isContinue:(n,r)=>n.type===Ie.DATE,applyFunctions:{[ce.SERIES]:(n,r,e)=>{const{data:t}=n;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),Li(t,r,e).reverse()):Li(t,r,e)}}},yd={type:Ie.NUMBER,priority:1e3,match:n=>typeof(n==null?void 0:n.v)=="number"||(n==null?void 0:n.t)===a.CellValueType.NUMBER,isContinue:(n,r)=>n.type===Ie.NUMBER,applyFunctions:{[ce.SERIES]:(n,r,e)=>{const{data:t}=n;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),Li(t,r,e).reverse()):Li(t,r,e)}}},Us={type:Ie.OTHER,priority:0,match:()=>!0,isContinue:(n,r)=>n.type===Ie.OTHER},Rd={type:Ie.EXTEND_NUMBER,priority:900,match:n=>xi(`${n==null?void 0:n.v}`||"").isExtendNumber,isContinue:(n,r)=>{var e;if(n.type===Ie.EXTEND_NUMBER){const{beforeTxt:t,afterTxt:i}=xi(`${(e=n.cellData)==null?void 0:e.v}`||""),{beforeTxt:o,afterTxt:s}=xi(`${r==null?void 0:r.v}`||"");if(t===o&&i===s)return!0}return!1},applyFunctions:{[ce.SERIES]:(n,r,e)=>{var l;const{data:t}=n,i=e===a.Direction.UP||e===a.Direction.LEFT;let o;if(t.length===1)return o=i?-1:1,ke(Vs(t,r,o),i);const s=[];for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`;d&&s.push(Number(xi(d).matchTxt))}return i&&(t.reverse(),s.reverse()),Hn(s)?(o=s[1]-s[0],ke(Vs(t,r,o),i)):It(t,r)}}},Md={type:Ie.CHN_NUMBER,priority:830,match:n=>!!gd(`${n==null?void 0:n.v}`||""),isContinue:(n,r)=>n.type===Ie.CHN_NUMBER,applyFunctions:{[ce.SERIES]:(n,r,e)=>{var c,d,u;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){const h=`${(c=t[0])==null?void 0:c.v}`;let g;return i?g=-1:g=1,h&&(h==="日"||Qe(h)<7)?ke(Zt(t,r,g),i):ke(Ws(t,r,g),i)}let o=!1;for(let h=0;h<t.length;h++)if(((d=t[h])==null?void 0:d.v)==="日"){o=!0;break}const s=[];let l=0;for(let h=0;h<t.length;h++){const g=`${(u=t[h])==null?void 0:u.v}`;g==="日"?h===0?s.push(0):(l++,s.push(l*7)):o&&Qe(g)>0&&Qe(g)<7?s.push(Qe(g)+l*7):s.push(Qe(g))}if(i&&(t.reverse(),s.reverse()),Hn(s)){if(o||s[s.length-1]<6&&s[0]>0||s[0]<6&&s[s.length-1]>0){const g=s[1]-s[0];return ke(Zt(t,r,g),i)}const h=s[1]-s[0];return ke(Ws(t,r,h),i)}return It(t,r)}}},Pd={type:Ie.CHN_WEEK2,priority:820,match:n=>!!Sd(`${n==null?void 0:n.v}`||""),isContinue:(n,r)=>n.type===Ie.CHN_WEEK2,applyFunctions:{[ce.SERIES]:(n,r,e)=>{var l;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let c;return i?c=-1:c=1,ke(Zt(t,r,c,1),i)}const o=[];let s=0;for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`,u=d==null?void 0:d.substr(d.length-1,1);d==="周日"?c===0?o.push(0):(s++,o.push(s*7)):o.push(Qe(u)+s*7)}if(i&&(t.reverse(),o.reverse()),Hn(o)){const c=o[1]-o[0];return ke(Zt(t,r,c,1),i)}return It(t,r)}}},Od={type:Ie.CHN_WEEK3,priority:810,match:n=>fd(`${n==null?void 0:n.v}`||""),isContinue:(n,r)=>n.type===Ie.CHN_WEEK3,applyFunctions:{[ce.SERIES]:(n,r,e)=>{var l;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let c;return i?c=-1:c=1,ke(Zt(t,r,c,2),i)}const o=[];let s=0;for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`;if(d){const u=d.substr(d.length-1,1);d==="星期日"?c===0?o.push(0):(s++,o.push(s*7)):o.push(Qe(u)+s*7)}}if(i&&(t.reverse(),o.reverse()),Hn(o)){const c=o[1]-o[0];return ke(Zt(t,r,c,2),i)}return It(t,r)}}},Ad={type:Ie.LOOP_SERIES,priority:800,match:n=>wd(`${n==null?void 0:n.v}`||""),isContinue:(n,r)=>{var e;return n.type===Ie.LOOP_SERIES?Yr(`${(e=n.cellData)==null?void 0:e.v}`||"").name===Yr(`${r==null?void 0:r.v}`||"").name:!1},applyFunctions:{[ce.SERIES]:(n,r,e)=>{var c,d;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP,{series:o}=Yr(`${(c=t[0])==null?void 0:c.v}`||"");if(t.length===1){let u;return i?u=-1:u=1,ke(xs(t,r,u,o),i)}const s=[];let l=0;for(let u=0;u<t.length;u++){const h=`${(d=t[u])==null?void 0:d.v}`;h&&(h===o[0]?u===0?s.push(0):(l++,s.push(l*o.length)):s.push(o.indexOf(h)+l*7))}if(i&&(t.reverse(),s.reverse()),Hn(s)){const u=s[1]-s[0];return ke(xs(t,r,u,o),i)}return It(t,r)}}};function ke(n,r){return r?n.reverse():n}var Dd=Object.getOwnPropertyDescriptor,kd=(n,r,e,t)=>{for(var i=t>1?void 0:t?Dd(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},qt=(n,r)=>(e,t)=>r(e,t,n);y.AutoFillService=class extends a.Disposable{constructor(e,t,i,o,s,l){super();T(this,"_rules",[]);T(this,"_hooks",[]);T(this,"_applyType$",new D.BehaviorSubject(ce.SERIES));T(this,"_isFillingStyle",!0);T(this,"_prevUndos",[]);T(this,"_autoFillLocation$",new D.BehaviorSubject(null));T(this,"autoFillLocation$",this._autoFillLocation$.asObservable());T(this,"_showMenu$",new D.BehaviorSubject(!1));T(this,"showMenu$",this._showMenu$.asObservable());T(this,"_direction",a.Direction.DOWN);T(this,"applyType$",this._applyType$.asObservable());T(this,"_menu$",new D.BehaviorSubject([{label:"autoFill.copy",value:ce.COPY,disable:!1},{label:"autoFill.series",value:ce.SERIES,disable:!1},{label:"autoFill.formatOnly",value:ce.ONLY_FORMAT,disable:!1},{label:"autoFill.noFormat",value:ce.NO_FORMAT,disable:!1}]));T(this,"menu$",this._menu$.asObservable());this._commandService=e,this._undoRedoService=t,this._renderManagerService=i,this._univerInstanceService=o,this._selectionManagerService=s,this._injector=l,this._init()}_init(){this._rules=[Td,yd,Rd,Md,Pd,Od,Ad,Us].sort((e,t)=>t.priority-e.priority),this._isFillingStyle=!0}_getOneByPriority(e){return e.length<=0?[]:[e.reduce((i,o)=>(o.priority||0)>(i.priority||0)?o:i,e[0])]}_initPrevUndo(){this._prevUndos=[]}async triggerAutoFill(e,t,i,o){var S;if(i.startColumn===o.startColumn&&i.startRow===o.startRow&&i.endColumn===o.endColumn&&i.endRow===o.endRow)return!1;if(o.endColumn<i.endColumn&&o.endColumn>i.startColumn)return this._commandService.executeCommand(Qt.id,{clearRange:{startRow:o.startRow,endRow:o.endRow,startColumn:o.endColumn+1,endColumn:i.endColumn},selectionRange:o});if(o.endRow<i.endRow&&o.endRow>i.startRow)return this._commandService.executeCommand(Qt.id,{clearRange:{startRow:o.endRow+1,endRow:i.endRow,startColumn:o.startColumn,endColumn:o.endColumn},selectionRange:o});const s={startRow:o.startRow,endRow:o.endRow,startColumn:o.startColumn,endColumn:o.endColumn};let l=null;if(o.startRow<i.startRow)l=a.Direction.UP,s.endRow=i.startRow-1;else if(o.endRow>i.endRow)l=a.Direction.DOWN,s.startRow=i.endRow+1;else if(o.startColumn<i.startColumn)l=a.Direction.LEFT,s.endColumn=i.startColumn-1;else if(o.endColumn>i.endColumn)l=a.Direction.RIGHT,s.startColumn=i.endColumn+1;else return!1;this.direction=l;const c=this._injector.invoke(f=>m.rangeToDiscreteRange(i,f)),d=this._injector.invoke(f=>m.rangeToDiscreteRange(s,f));if(!c||!d)return!1;this.autoFillLocation={source:c,target:d,unitId:e,subUnitId:t};const u=[];this.getActiveHooks().forEach(f=>{var p;const v=(p=f==null?void 0:f.onBeforeFillData)==null?void 0:p.call(f,{source:c,target:d,unitId:e,subUnitId:t},l);v&&u.unshift(v)}),this._initPrevUndo();for(let f=0;f<u.length;f++){const v=this.menu.find(p=>p.value===u[f]);if(v&&!v.disable)return this.fillData(u[f])}const g=(S=this.menu.find(f=>f.disable===!1))==null?void 0:S.value;return g?this.fillData(g):!1}addHook(e){if(this._hooks.find(t=>t.id===e.id))throw new Error(`Add hook failed, hook id '${e.id}' already exist!`);return e.priority===void 0&&(e.priority=0),e.type===void 0&&(e.type=Kt.Append),this._hooks.push(e),a.toDisposable(()=>{const t=this._hooks.findIndex(i=>i===e);t>-1&&this._hooks.splice(t,1)})}registerRule(e){if(this._rules.find(i=>i.type===e.type))throw new Error(`Registry rule failed, type '${e.type}' already exist!`);const t=this._rules.findIndex(i=>i.priority<e.priority);this._rules.splice(t===-1?this._rules.length:t,0,e)}getRules(){return this._rules}getAllHooks(){return this._hooks}getActiveHooks(){const{source:e,target:t,unitId:i,subUnitId:o}=this.autoFillLocation||{};if(!e||!t||!i||!o)return[];const s=this._hooks.filter(u=>{var h;return!((h=u.disable)!=null&&h.call(u,{source:e,target:t,unitId:i,subUnitId:o},this._direction,this.applyType))}),l=s.filter(u=>u.type===Kt.Only);if(l.length>0)return this._getOneByPriority(l);const c=this._getOneByPriority(s.filter(u=>u.type===Kt.Default)),d=s.filter(u=>u.type===Kt.Append)||[];return[...c,...d]}get applyType(){return this._applyType$.getValue()}set applyType(e){this._applyType$.next(e)}get menu(){return this._menu$.getValue()}get direction(){return this._direction}set direction(e){this._direction=e}isFillingStyle(){return this._isFillingStyle}setFillingStyle(e){this._isFillingStyle=e}get autoFillLocation(){return this._autoFillLocation$.getValue()}set autoFillLocation(e){this._autoFillLocation$.next(e)}setDisableApplyType(e,t){this._menu$.next(this._menu$.getValue().map(i=>i.value===e?{...i,disable:t}:i))}setShowMenu(e){this._showMenu$.next(e)}fillData(e){var C,b,E;this.applyType=e;const{source:t,target:i,unitId:o=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId(),subUnitId:s=(C=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:C.getSheetId()}=this.autoFillLocation||{};if(!t||!i||!o||!s)return!1;const l=this.direction;this._prevUndos.length>0&&this._prevUndos.forEach(w=>{this._commandService.syncExecuteCommand(w.id,w.params)}),this._prevUndos=[];const c=a.Rectangle.union(ct(t),ct(i)),d=this.getActiveHooks(),u=this._univerInstanceService.getUnit(o,a.UniverInstanceType.UNIVER_SHEET);this._commandService.syncExecuteCommand(m.SetSelectionsOperation.id,{selections:[{primary:{...(E=(b=this._selectionManagerService.getCurrentLastSelection())==null?void 0:b.primary)!=null?E:c},range:{...c,rangeType:a.RANGE_TYPE.NORMAL}}],unitId:o,subUnitId:s});const h=[],g=[];d.forEach(w=>{var P;const{undos:O,redos:M}=((P=w.onFillData)==null?void 0:P.call(w,{source:t,target:i,unitId:o,subUnitId:s},l,e))||{};O&&h.push(...O),M&&g.push(...M)});const S=g.every(w=>this._commandService.syncExecuteCommand(w.id,w.params)),f=[];e!==ce.NO_FORMAT&&g.forEach(w=>{if(w.id===m.SetRangeValuesMutation.id){const{cellValue:O}=w.params;new a.ObjectMatrix(O).forValue((P,A,k)=>{const N=Object.keys(u.getStyles().get(k==null?void 0:k.s)||{});(k!=null&&k.p||N.length&&ks.some(H=>N.includes(H)))&&f.push({startRow:P,endRow:P,startColumn:A,endColumn:A})})}});const v=this._getAutoHeightUndoRedos(o,s,f);return v.redos.every(w=>this._commandService.syncExecuteCommand(w.id,w.params))&&(h.push(...v.undos),g.push(...v.redos)),S&&(this._prevUndos=h,this._undoRedoService.pushUndoRedo({unitID:o,undoMutations:h,redoMutations:g})),d.forEach(w=>{var O;(O=w.onAfterFillData)==null||O.call(w,{source:t,target:i,unitId:o,subUnitId:s},l,e)}),this.setShowMenu(!0),!0}_getAutoHeightUndoRedos(e,t,i){var h,g;const o=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(y.SheetSkeletonManagerService),s=(g=o==null?void 0:o.getCurrentParam())==null?void 0:g.skeleton;if(!s)return{redos:[],undos:[]};const l=s.calculateAutoHeightInRange(i),c={subUnitId:t,unitId:e,rowsAutoHeightInfo:l},d=s.worksheet,u=m.SetWorksheetRowAutoHeightMutationFactory(c,d);return{undos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:u}],redos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:c}]}}},y.AutoFillService=kd([qt(0,a.ICommandService),qt(1,a.IUndoRedoService),qt(2,R.IRenderManagerService),qt(3,a.Inject(a.IUniverInstanceService)),qt(4,a.Inject(m.SheetsSelectionsService)),qt(5,a.Inject(a.Injector))],y.AutoFillService);const ut=a.createIdentifier("univer.auto-fill-service"),ht={type:a.CommandType.COMMAND,id:"sheet.command.auto-fill",handler:async(n,r)=>{const e=n.get(ut),t=n.get(a.IUniverInstanceService),{sourceRange:i,targetRange:o}=r,s=m.getSheetCommandTarget(t);if(!s)return!1;const{subUnitId:l,unitId:c}=s;return e.triggerAutoFill(c,l,i,o)}},Qt={id:"sheet.command.auto-clear-content",type:a.CommandType.COMMAND,handler:async(n,r)=>{const e=n.get(a.IUniverInstanceService),t=n.get(a.ICommandService),i=n.get(a.IUndoRedoService),o=n.get(m.SheetInterceptorService),s=m.getSheetCommandTarget(e);if(!s)return!1;const{unitId:l,subUnitId:c}=s,{clearRange:d,selectionRange:u}=r,h={subUnitId:c,unitId:l,cellValue:m.generateNullCellValue([d])},g=m.SetRangeValuesUndoMutationFactory(n,h),{startColumn:S,startRow:f}=u,v={selections:[{primary:{startColumn:S,startRow:f,endColumn:S,endRow:f,actualRow:f,actualColumn:S,isMerged:!1,isMergedMainCell:!1},range:{...u}}],unitId:l,subUnitId:c};if(t.executeCommand(m.SetSelectionsOperation.id,v),t.syncExecuteCommand(m.SetRangeValuesMutation.id,h)){const C=o.afterCommandExecute({id:m.SetRangeValuesMutation.id,params:h});return a.sequenceExecute(C.redos,t),i.pushUndoRedo({unitID:l,undoMutations:[{id:m.SetRangeValuesMutation.id,params:g},...C.undos],redoMutations:[{id:m.SetRangeValuesMutation.id,params:h},...C.redos]}),!0}return!1}},Wn={id:"sheet.command.refill",type:a.CommandType.COMMAND,handler:async(n,r)=>n.get(ut).fillData(r.type)};var Nd=Object.getOwnPropertyDescriptor,Hd=(n,r,e,t)=>{for(var i=t>1?void 0:t?Nd(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},Jt=(n,r)=>(e,t)=>r(e,t,n);y.EditorBridgeService=class extends a.Disposable{constructor(e,t,i,o,s,l){super();T(this,"_editorUnitId",a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);T(this,"_editorIsDirty",!1);T(this,"_visibleParams",{visible:!1,eventType:R.DeviceInputEventType.Dblclick,unitId:""});T(this,"_currentEditCell",null);T(this,"_currentEditCellState",null);T(this,"_currentEditCellLayout",null);T(this,"helpFunctionVisible$",new D.BehaviorSubject(!0));T(this,"_currentEditCellState$",new D.BehaviorSubject(null));T(this,"currentEditCellState$",this._currentEditCellState$.asObservable());T(this,"_currentEditCellLayout$",new D.BehaviorSubject(null));T(this,"currentEditCellLayout$",this._currentEditCellLayout$.asObservable());T(this,"currentEditCell$",this._currentEditCellState$.pipe(D.switchMap(e=>this._currentEditCellLayout$.pipe(D.map(t=>e&&t?{...e,...t}:null)))));T(this,"_visibleParams$",new D.BehaviorSubject(this._visibleParams));T(this,"visible$",this._visibleParams$.asObservable());T(this,"_afterVisibleParams$",new D.BehaviorSubject(this._visibleParams));T(this,"afterVisible$",this._afterVisibleParams$.asObservable());T(this,"_forceKeepVisible$",new D.BehaviorSubject(!1));T(this,"forceKeepVisible$",this._forceKeepVisible$.asObservable());this._sheetInterceptorService=e,this._renderManagerService=t,this._themeService=i,this._univerInstanceService=o,this._editorService=s,this._contextService=l,this.disposeWithMe(a.toDisposable(()=>{this._currentEditCellState$.complete(),this._currentEditCell=null})),this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).subscribe(c=>{var d;c.getUnitId()===((d=this._currentEditCellState)==null?void 0:d.unitId)&&this._clearCurrentEditCellState()})}refreshEditCellState(){const e=this.getLatestEditCellState();if(!e){this._currentEditCellState=null,this._currentEditCellLayout=null,this._currentEditCellState$.next(null),this._currentEditCellLayout$.next(null);return}const{position:t,scaleX:i,scaleY:o,canvasOffset:s,...l}=e;this._currentEditCellState=l,this._currentEditCellLayout={position:t,scaleX:i,scaleY:o,canvasOffset:s},this._currentEditCellState$.next(this._currentEditCellState),this._currentEditCellLayout$.next(this._currentEditCellLayout)}refreshEditCellPosition(e){var O;const t=this._currentEditCell;if(t==null)return;const i=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!i)return;const o=this._renderManagerService.getRenderUnitById(i.getUnitId());if(!o)return;const s=(O=o.with(y.SheetSkeletonManagerService).getSkeletonParam(t.sheetId))==null?void 0:O.skeleton,l=o.with(ve);if(!s||!this._currentEditCellState)return;const{primary:c,scene:d,engine:u}=t,h=Dn(s,c);if(h==null)return;const g=a.convertCellToRange(h),S=q.getCanvasOffsetByEngine(u);let{startX:f,startY:v,endX:p,endY:C}=g;const{scaleX:b,scaleY:E}=d.getAncestorScale(),w=d.getViewportScrollXY(l.getViewPort());f=R.convertTransformToOffsetX(f,b,w),v=R.convertTransformToOffsetY(v,E,w),p=R.convertTransformToOffsetX(p,b,w),C=R.convertTransformToOffsetY(C,E,w),e&&this._currentEditCellLayout&&(p=p-f+this._currentEditCellLayout.position.startX,C=C-v+this._currentEditCellLayout.position.startY,f=this._currentEditCellLayout.position.startX,v=this._currentEditCellLayout.position.startY),this._currentEditCellLayout={position:{startX:f,startY:v,endX:p,endY:C},canvasOffset:S,scaleX:b,scaleY:E},this._currentEditCellLayout$.next(this._currentEditCellLayout)}setEditCell(e){this._currentEditCell=e,this._editorService.getFocusEditor()||(this._editorService.focus(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._contextService.setContextValue(a.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(a.FOCUSING_EDITOR_STANDALONE,!1));const t=this.getLatestEditCellState();if(!t){this._currentEditCellState=t,this._currentEditCellLayout=t,this._currentEditCellState$.next(t),this._currentEditCellLayout$.next(t);return}const{position:i,canvasOffset:o,scaleX:s,scaleY:l,...c}=t;this._currentEditCellState=c,this._currentEditCellLayout={position:i,canvasOffset:o,scaleX:s,scaleY:l},this._currentEditCellState$.next(this._currentEditCellState),this._currentEditCellLayout$.next(this._currentEditCellLayout)}_clearCurrentEditCellState(){this._currentEditCellState=null,this._currentEditCellState$.next(null),this._currentEditCellLayout=null,this._currentEditCellLayout$.next(null)}getEditCellState(){return this._currentEditCellState==null||this._currentEditCellLayout==null?null:{...this._currentEditCellState,...this._currentEditCellLayout}}getEditCellLayout(){return this._currentEditCellLayout}getEditLocation(){return this._currentEditCellState}updateEditLocation(e,t){this._currentEditCellState&&(this._currentEditCellState={...this._currentEditCellState,row:e,column:t})}getLatestEditCellState(){var L,V,U;const e=this._currentEditCell;if(e==null)return;const t=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!t)return;const i=this._renderManagerService.getRenderUnitById(t.getUnitId());if(!i)return;const o=i.with(y.SheetSkeletonManagerService).getCurrentSkeleton(),s=i.with(ve);if(!o)return;const{primary:l,unitId:c,sheetId:d,scene:u,engine:h}=e,{startRow:g,startColumn:S}=l,f=Dn(o,l);if(f==null)return;const v=a.convertCellToRange(f),p=q.getCanvasOffsetByEngine(h);let{startX:C,startY:b,endX:E,endY:w}=v;const{scaleX:O,scaleY:M}=u.getAncestorScale(),P=u.getViewportScrollXY(s.getViewPort());C=R.convertTransformToOffsetX(C,O,P),b=R.convertTransformToOffsetY(b,M,P),E=R.convertTransformToOffsetX(E,O,P),w=R.convertTransformToOffsetY(w,M,P);const A=t.getActiveSheet();if(!A)return;const k={workbook:t,worksheet:A,unitId:t.getUnitId(),subUnitId:A.getSheetId(),row:g,col:S,origin:A.getCellRaw(g,S)};let N;const H=this._sheetInterceptorService.writeCellInterceptor.fetchThroughInterceptors(m.BEFORE_CELL_EDIT)(A.getCell(g,S),k);N=H&&A.getCellDocumentModelWithFormula(H,k.row,k.col);const x=(L=N==null?void 0:N.documentModel)==null?void 0:L.documentStyle.renderConfig;if(x!=null&&(x.cellValueType=a.CellValueType.STRING),!N||N.documentModel==null){const B=A.getBlankCellDocumentModel(H,k.row,k.col);if(N!=null){const{verticalAlign:Y,horizontalAlign:F,wrapStrategy:z,textRotation:j,fill:Q}=N,{centerAngle:ie,vertexAngle:$}=R.convertTextRotation(j);B.documentModel.documentStyle.renderConfig={...x,verticalAlign:Y,horizontalAlign:F,wrapStrategy:z,background:{rgb:Q},centerAngle:ie,vertexAngle:$}}N=B}if(N.fill=N.fill||"#fff",(V=N.documentModel)==null||V.setZoomRatio(Math.max(O,M)),(H==null?void 0:H.isInArrayFormulaRange)===!0){const B=(U=N.documentModel)==null?void 0:U.getBody();B&&(B.textRuns=[{st:0,ed:B.dataStream.length-2,ts:{cl:{rgb:this._themeService.getColorFromTheme("gray.600")}}}])}return{position:{startX:C,startY:b,endX:E,endY:w},scaleX:O,scaleY:M,canvasOffset:p,row:g,column:S,unitId:c,sheetId:d,documentLayoutObject:N,editorUnitId:this._editorUnitId,isInArrayFormulaRange:H==null?void 0:H.isInArrayFormulaRange}}getCurrentEditorId(){return this._editorUnitId}changeVisible(e){this._visibleParams=e,e.visible&&(this._editorIsDirty=!1),this._visibleParams$.next(this._visibleParams),this._afterVisibleParams$.next(this._visibleParams)}isVisible(){return this._visibleParams}enableForceKeepVisible(){this._forceKeepVisible$.next(!0)}disableForceKeepVisible(){this._forceKeepVisible$.next(!1)}isForceKeepVisible(){return this._forceKeepVisible$.getValue()}changeEditorDirty(e){this._editorIsDirty=e}getEditorDirty(){return this._editorIsDirty}},y.EditorBridgeService=Hd([Jt(0,a.Inject(m.SheetInterceptorService)),Jt(1,R.IRenderManagerService),Jt(2,a.Inject(a.ThemeService)),Jt(3,a.IUniverInstanceService),Jt(4,q.IEditorService),Jt(5,a.IContextService)],y.EditorBridgeService);const me=a.createIdentifier("univer.sheet-editor-bridge.service"),ge={id:"sheet.operation.set-cell-edit-visible",type:a.CommandType.OPERATION,handler:(n,r)=>{if(!r)return!1;const{unitId:e}=r,i=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);return i?(n.get(me).changeVisible({...r,unitId:e!=null?e:i.getUnitId()}),!0):!1}},xn={id:"sheet.operation.set-cell-edit-visible-f2",type:a.CommandType.OPERATION,handler:(n,r)=>{const e=n.get(a.ICommandService),i=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);return i?e.syncExecuteCommand(ge.id,{...r,unitId:i.getUnitId()}):!1}},wt={id:"sheet.operation.set-cell-edit-visible-arrow",type:a.CommandType.OPERATION,handler:()=>!0},$t={id:"sheet.command.change-zoom-ratio",type:a.CommandType.COMMAND,handler:(n,r)=>{if(!r)return!1;const e=n.get(a.IUniverInstanceService),t=m.getSheetCommandTarget(e);if(!t)return!1;const{worksheet:i,subUnitId:o,unitId:s}=t,{delta:l,reset:c}=r;let d=c?100:Math.round((i.getConfig().zoomRatio+l)*100);d=Math.max(Hr[0],d),d=Math.min(Hr[1],d);const u=d/100,g=n.get(me).isVisible();return(g.unitId===s||g.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&g.visible?!1:n.get(a.ICommandService).executeCommand(He.id,{unitId:s,subUnitId:o,zoomRatio:u})}},en={id:"sheet.command.set-zoom-ratio",type:a.CommandType.COMMAND,handler:(n,r)=>{if(!r)return!1;const{unitId:e,subUnitId:t,zoomRatio:i}=r,s=n.get(me).isVisible();return(s.unitId===e||s.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&s.visible?!1:n.get(a.ICommandService).executeCommand(He.id,{unitId:e,subUnitId:t,zoomRatio:i})}};function Vd(n){return typeof n.isMainScene>"u"}function Ne(n,r){const e=n instanceof a.Workbook?n:n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!e)return null;const t=e.getUnitId();let i,o,s,l;if(Vd(r)){const g=r.getRenderById(t);if(g==null)return null;i=g.components,i=g.components,o=g.mainComponent,s=g.scene,l=g.engine}else i=r.components,o=r.mainComponent,s=r.scene,l=r.engine;if(!i||!o)return null;const c=o,d=i.get(he.ROW),u=i.get(he.COLUMN),h=i.get(he.LEFT_TOP);return{spreadsheet:c,spreadsheetRowHeader:d,spreadsheetColumnHeader:u,spreadsheetLeftTopPlaceholder:h,scene:s,engine:l}}function jr(n,r,e,t){const{startX:i,startY:o,endX:s,endY:l}=t.getCellWithCoordByIndex(n,r);return{startX:i,startY:o,endX:s,endY:l}}function ze(n,r,e,t,i,o){const s=e.getCoordRelativeToViewport(R.Vector2.FromArray([n,r])),{x:l,y:c}=s,d=e.getScrollXYInfoByViewport(s,i),{scaleX:u,scaleY:h}=e.getAncestorScale(),g=t.getCellIndexByOffset(l,c,u,h,d,{closeFirst:o}),{row:S,column:f}=g,v=t.getNoMergeCellWithCoordByIndex(S,f),{startX:p,startY:C,endX:b,endY:E}=v;return{startX:p,startY:C,endX:b,endY:E,row:S,column:f}}function Ln(n,r,e,t){const i=e.getCoordRelativeToViewport(R.Vector2.FromArray([n,r])),o=e.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN),s=e.getScrollXYInfoByViewport(i,o),{scaleX:l,scaleY:c}=e.getAncestorScale(),{x:d,y:u}=s,h=n/l+d,g=r/c+u;return{x:h,y:g}}var Wd=Object.getOwnPropertyDescriptor,xd=(n,r,e,t)=>{for(var i=t>1?void 0:t?Wd(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},Ui=(n,r)=>(e,t)=>r(e,t,n);let Un=class extends a.Disposable{constructor(r,e,t,i,o){super();T(this,"_zoom");this._context=r,this._sheetSkeletonManagerService=e,this._commandService=t,this._contextService=i,this._editorBridgeService=o,this._initSkeletonListener(),this._initZoomEventListener()}updateZoom(r,e){const t=this._context.unit.getSheetBySheetId(r);return t?(t.getConfig().zoomRatio=e,t===this._context.unit.getActiveSheet()&&this._updateViewZoom(e),!0):!1}_initZoomEventListener(){const r=Ne(this._context.unit,this._context).scene;this.disposeWithMe(r.onMouseWheel$.subscribeEvent(e=>{if(!e.ctrlKey||!this._contextService.getContextValue(a.FOCUSING_SHEET))return;if(this._editorBridgeService){const d=this._editorBridgeService.isVisible();if((d.unitId===this._context.unitId||d.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&d.visible)return}const t=Math.abs(e.deltaX);let i=t<40?.2:t<80?.4:.2;i*=e.deltaY>0?-1:1,r.scaleX<1&&(i/=2);const o=this._context.unit,s=o.getActiveSheet();if(!s)return;const l=s.getZoomRatio();let c=+Number.parseFloat(`${l+i}`).toFixed(1);c=c>=4?4:c<=.1?.1:c,this._commandService.executeCommand(en.id,{zoomRatio:Math.round(c*10)/10,unitId:o.getUnitId(),subUnitId:s.getSheetId()}),e.preventDefault()}))}_initSkeletonListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(r=>{if(r==null)return;const t=this._context.unit.getActiveSheet();if(!t)return;const i=t.getZoomRatio()||1;this._zoom!==i&&this._updateViewZoom(i)}))}_updateViewZoom(r){this._zoom=r;const e=Ne(this._context.unit,this._context);e==null||e.scene.scale(r,r),e==null||e.spreadsheet.makeForceDirty()}};Un=xd([Ui(1,a.Inject(y.SheetSkeletonManagerService)),Ui(2,a.ICommandService),Ui(3,a.IContextService),Ui(4,a.Optional(me))],Un);const He={id:"sheet.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(n,r)=>{const t=n.get(R.IRenderManagerService).getRenderById(r.unitId);return t?t.with(Un).updateZoom(r.subUnitId,r.zoomRatio):!1}};var Ld=Object.getOwnPropertyDescriptor,Ud=(n,r,e,t)=>{for(var i=t>1?void 0:t?Ld(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},Bi=(n,r)=>(e,t)=>r(e,t,n);const Bs="univer-sheet-main-canvas";y.SheetsRenderService=class extends a.RxDisposable{constructor(e,t,i,o){super();T(this,"_skeletonChangeMutations",new Set);this._contextService=e,this._instanceSrv=t,this._renderManagerService=i,this._themeService=o,Promise.resolve().then(()=>this._init())}registerSkeletonChangingMutations(e){return this._skeletonChangeMutations.has(e)?a.toDisposable(()=>{}):(this._skeletonChangeMutations.add(e),a.toDisposable(()=>this._skeletonChangeMutations.delete(e)))}checkMutationShouldTriggerRerender(e){return this._skeletonChangeMutations.has(e)}_init(){this._initWorkbookListener(),this._initContextListener()}_initWorkbookListener(){this._instanceSrv.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET).pipe(D.takeUntil(this.dispose$)).subscribe(e=>this._createRenderer(e)),this._instanceSrv.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(e=>this._createRenderer(e)),this._instanceSrv.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).pipe(D.takeUntil(this.dispose$)).subscribe(e=>this._disposeRenderer(e))}_createRenderer(e){const t=e.getUnitId();this._renderManagerService.created$.subscribe(i=>{i.unitId===t&&(i.engine.getCanvas().setId(`${Bs}_${t}`),i.engine.getCanvas().getContext().setId(`${Bs}_${t}`))}),this._renderManagerService.createRender(t)}_disposeRenderer(e){const t=e.getUnitId();this._renderManagerService.removeRender(t)}_initContextListener(){this.disposeWithMe(this._contextService.subscribeContextValue$(R.RENDER_RAW_FORMULA_KEY).pipe(D.distinctUntilChanged()).subscribe(()=>{this._renderManagerService.getRenderAll().forEach(e=>{e.mainComponent instanceof R.Spreadsheet&&e.mainComponent.makeForceDirty(!0)})}))}},y.SheetsRenderService=Ud([Bi(0,a.IContextService),Bi(1,a.IUniverInstanceService),Bi(2,R.IRenderManagerService),Bi(3,a.Inject(a.ThemeService))],y.SheetsRenderService);var Bd=Object.getOwnPropertyDescriptor,Fd=(n,r,e,t)=>{for(var i=t>1?void 0:t?Bd(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},Et=(n,r)=>(e,t)=>r(e,t,n);y.AutoFillController=class extends a.Disposable{constructor(e,t,i,o,s,l,c){super();T(this,"_beforeApplyData",[]);T(this,"_currentLocation",null);T(this,"_copyData",[]);T(this,"_defaultHook");this._univerInstanceService=e,this._commandService=t,this._autoFillService=i,this._editorBridgeService=o,this._renderManagerService=s,this._injector=l,this._sheetsRenderService=c,this._defaultHook={id:"default",type:Kt.Default,priority:0,onBeforeFillData:(d,u)=>this._presetAndCacheData(d,u),onFillData:(d,u,h)=>this._fillData(d,u,h)},this._init()}_init(){this._initDefaultHook(),this._initSelectionControlFillChanged(),this._initQuitListener(),this._initSkeletonChange()}_initSkeletonChange(){this.disposeWithMe(this._sheetsRenderService.registerSkeletonChangingMutations(ht.id))}_initDefaultHook(){this.disposeWithMe(this._autoFillService.addHook(this._defaultHook))}_initQuitListener(){const e=[ge.id,Qt.id,m.SetRangeValuesCommand.id,He.id,m.SetWorksheetActiveOperation.id,m.MoveRangeMutation.id,m.RemoveRowMutation.id,m.RemoveColMutation.id,m.InsertRowMutation.id,m.InsertColMutation.id,m.MoveRowsMutation.id,m.MoveColsMutation.id,m.SetWorksheetColWidthMutation.id,m.SetWorksheetRowHeightMutation.id,m.SetRangeValuesMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted((t,i)=>{var c,d;const o=i==null?void 0:i.fromCollab,s=i==null?void 0:i.fromSync,l=i==null?void 0:i.fromFormula;e.includes(t.id)&&!o&&!s&&!l&&t.params.trigger!==ht.id&&t.params.trigger!==Wn.id&&this._quit(),t.id===m.RemoveSheetMutation.id&&t.params.unitId===((c=this._currentLocation)==null?void 0:c.unitId)&&t.params.subUnitId===((d=this._currentLocation)==null?void 0:d.subUnitId)&&this._quit()})),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{var i;t.getUnitId()===((i=this._currentLocation)==null?void 0:i.unitId)&&this._quit()}))}_quit(){this._currentLocation=null,this._beforeApplyData=[],this._copyData=[],this._autoFillService.setShowMenu(!1)}_initSelectionControlFillChanged(){const e=new a.DisposableCollection,t=()=>{e.dispose();const i=R.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService);if(!i)return;i.with(ve).getSelectionControls().forEach(l=>{e.add(l.selectionFilled$.subscribe(c=>{if(c==null||c.startColumn===-1||c.startRow===-1||c.endColumn===-1||c.endRow===-1)return;const d={startColumn:l.model.startColumn,endColumn:l.model.endColumn,startRow:l.model.startRow,endRow:l.model.endRow},u={startColumn:c.startColumn,endColumn:c.endColumn,startRow:c.startRow,endRow:c.endRow};this._commandService.executeCommand(ht.id,{sourceRange:d,targetRange:u})})),e.add(l.fillControl.onDblclick$.subscribeEvent(()=>{const c={startColumn:l.model.startColumn,endColumn:l.model.endColumn,startRow:l.model.startRow,endRow:l.model.endRow};this._handleDbClickFill(c)})),e.add(l.fillControl.onPointerDown$.subscribeEvent(()=>{this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(ge.id,{visible:!1,eventType:R.DeviceInputEventType.PointerDown,unitId:i.unitId})}))})};t(),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===m.SetSelectionsOperation.id&&t()})),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(()=>t()))}_handleDbClickFill(e){const t=this._detectFillRange(e);t.endRow<=e.endRow||this._commandService.executeCommand(ht.id,{sourceRange:e,targetRange:t})}_detectFillRange(e){var g,S,f,v,p,C;const{startRow:t,endRow:i,startColumn:o,endColumn:s}=e,l=(g=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET))==null?void 0:g.getActiveSheet();if(!l)return e;const c=l.getCellMatrix(),d=l.getMaxRows()-1,u=l.getMaxColumns()-1;let h=i;if(o>0&&((S=c.getValue(t,o-1))==null?void 0:S.v)!=null){let b=t;for(;((f=c.getValue(b,o-1))==null?void 0:f.v)!=null&&b<d;)b+=1;h=b-1}else if(s<u&&((v=c.getValue(i,s+1))==null?void 0:v.v)!=null){let b=t;for(;((p=c.getValue(b,s+1))==null?void 0:p.v)!=null&&b<d;)b+=1;h=b-1}for(let b=i+1;b<=h;b++)for(let E=o;E<=s;E++)if(((C=c.getValue(b,E))==null?void 0:C.v)!=null){h=b-1;break}return{startColumn:o,endColumn:s,startRow:t,endRow:h}}_getApplyData(e,t,i,o,s,l=!0,c){const d=[],u=Math.floor(i/t),h=i%t,g=this._autoFillService.getRules();if(!l&&s===ce.ONLY_FORMAT)return console.error("ERROR: only format can not be applied when hasStyle is false"),[];const S={};g.forEach(f=>{S[f.type]=[]}),g.forEach(f=>{const{type:v,applyFunctions:p={}}=f,C=e[v];C&&C.forEach(b=>{const E=vd(b.index,h),w=b.index.length*u+E,O=this._applyFunctions(b,w,o,s,p,e,c),M=pd(t,i,b.index);S[v].push({data:O,index:M})})});for(let f=0;f<i;f++)g.forEach(v=>{const{type:p}=v,C=S[p];for(let b=0;b<C.length;b++)f in C[b].index&&d.push(C[b].data[C[b].index[f]])});return d}_applyFunctions(e,t,i,o,s,l,c){const{data:d}=e,u=i===a.Direction.UP||i===a.Direction.LEFT;if(o===ce.COPY){const h=s==null?void 0:s[ce.COPY];return h?h(e,t,i,l,c):(u&&d.reverse(),It(d,t))}if(o===ce.SERIES){const h=s==null?void 0:s[ce.SERIES];return h?h(e,t,i,l):(u&&d.reverse(),s!=null&&s[ce.COPY]?s[ce.COPY](e,t,i,l,c):It(d,t))}if(o===ce.ONLY_FORMAT){const h=s==null?void 0:s[ce.ONLY_FORMAT];return h?h(e,t,i,l):Cd(d,t)}}_getCopyData(e,t){const i=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!i)throw new Error("No active sheet found");const o=i.getCellMatrix(),s=this._autoFillService.getRules(),l=[],c=t===a.Direction.DOWN||t===a.Direction.UP;let d,u;return c?(d=e.cols,u=e.rows):(d=e.rows,u=e.cols),d.forEach(h=>{const g=this._getEmptyCopyDataPiece(),S={type:void 0,cellData:void 0};u.forEach(f=>{let v;c?v=o.getValue(f,h):v=o.getValue(h,f);const{type:p,isContinue:C}=s.find(b=>b.match(v,this._injector))||Us;if(C(S,v)){const b=g[p],E=b[b.length-1];E.data.push(v),E.index.push(f-u[0])}else{const b=g[p];b?b.push({data:[v],index:[f-u[0]]}):g[p]=[{data:[v],index:[f-u[0]]}]}S.type=p,S.cellData=v}),l.push(g)}),l}_getEmptyCopyDataPiece(){const e={};return this._autoFillService.getRules().forEach(t=>{e[t.type]=[]}),e}_getMergeApplyData(e,t,i,o){const s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!s)throw new Error("No active sheet found");const l=[];for(let c=e.startRow;c<=e.endRow;c++)for(let d=e.startColumn;d<=e.endColumn;d++){const{isMergedMainCell:u,startRow:h,startColumn:g,endRow:S,endColumn:f}=s.getCellInfoInMergeData(c,d);if(u){if(i===a.Direction.DOWN){let v=h+o,p=S+o;for(;p<=t.endRow;)l.push({startRow:v,startColumn:g,endRow:p,endColumn:f}),v+=o,p+=o}else if(i===a.Direction.UP){let v=h-o,p=S-o;for(;v>=t.startRow;)l.push({startRow:v,startColumn:g,endRow:p,endColumn:f}),v-=o,p-=o}else if(i===a.Direction.RIGHT){let v=g+o,p=f+o;for(;p<=t.endColumn;)l.push({startRow:h,startColumn:v,endRow:S,endColumn:p}),v+=o,p+=o}else if(i===a.Direction.LEFT){let v=g-o,p=f-o;for(;v>=t.startColumn;)l.push({startRow:h,startColumn:v,endRow:S,endColumn:p}),v-=o,p-=o}}}return l}_presetAndCacheData(e,t){const{source:i,target:o}=e,s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!s)throw new Error("No active sheet found");const l=s.getCellMatrix(),c=[];return o.rows.forEach(d=>{const u=[];o.cols.forEach(h=>{u.push(a.Tools.deepClone(l.getValue(d,h)))}),c.push(u)}),this._beforeApplyData=c,this._copyData=this._getCopyData(i,t),this._currentLocation=e,this._shouldDisableSeries(this._copyData)?(this._autoFillService.setDisableApplyType(ce.SERIES,!0),ce.COPY):(this._autoFillService.setDisableApplyType(ce.SERIES,!1),this._getPreferredApplyType(this._copyData))}_fillData(e,t,i){var L,V;const o=[],s=[];let l=!0;i===ce.NO_FORMAT&&(l=!1,i=ce.SERIES);const{source:c,target:d,unitId:u,subUnitId:h}=e;if(!c||!d||t==null)return{undos:o,redos:s};const g=ct(c),S=ct(d),{cols:f,rows:v}=d,{cols:p,rows:C}=c,b=this._copyData;let E;t===a.Direction.DOWN||t===a.Direction.UP?E=C.length:E=p.length;const w=[];if(t===a.Direction.DOWN||t===a.Direction.UP){const U=v.length,B=[];f.forEach((Y,F)=>{const z=b[F],j=this._getApplyData(z,E,U,t,i,l,e);B.push(j)});for(let Y=0;Y<B[0].length;Y++){const F=[];for(let z=0;z<B.length;z++)F.push({s:null,...B[z][Y]});w.push(F)}}else{const U=f.length;v.forEach((B,Y)=>{const F=b[Y],z=this._getApplyData(F,E,U,t,i,l,e),j=[];for(let Q=0;Q<z.length;Q++)j.push({s:null,...z[Q]});w.push(j)})}let O=[];const M=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getStyles();if(l?(O=this._getMergeApplyData(g,S,t,E),w.forEach(U=>{U.forEach(B=>{B&&M&&M&&(B.s=M.getStyleByCell(B))})})):w.forEach((U,B)=>{U.forEach((Y,F)=>{Y&&M&&(Y.s=M.getStyleByCell(this._beforeApplyData[B][F])||null)})}),i===ce.ONLY_FORMAT&&w.forEach((U,B)=>{U.forEach((Y,F)=>{if(Y){const z=this._beforeApplyData[B][F]||{};Y.f=z.f,Y.si=z.si,Y.t=z.t,Y.v=z.v}})}),l){const U=[],B=(V=(L=this._univerInstanceService.getUniverSheetInstance(u))==null?void 0:L.getSheetBySheetId(h))==null?void 0:V.getMergeData();B&&B.forEach(z=>{a.Rectangle.intersects(z,S)&&U.push(z)});const Y={unitId:u,subUnitId:h,ranges:U},F=this._injector.invoke(m.RemoveMergeUndoMutationFactory,Y);U.length&&(s.push({id:m.RemoveWorksheetMergeMutation.id,params:Y}),o.unshift({id:m.AddWorksheetMergeMutation.id,params:F}))}const P={subUnitId:h,unitId:u,cellValue:dd([d])},A=this._injector.invoke(m.SetRangeValuesUndoMutationFactory,P);s.push({id:m.SetRangeValuesMutation.id,params:P}),o.unshift({id:m.SetRangeValuesMutation.id,params:A});const k=new a.ObjectMatrix;v.forEach((U,B)=>{f.forEach((Y,F)=>{w[B][F]&&k.setValue(U,Y,w[B][F])})});const N=k.getMatrix(),H={subUnitId:h,unitId:u,cellValue:N},x=this._injector.invoke(m.SetRangeValuesUndoMutationFactory,H);if(this._autoFillService.getActiveHooks().forEach(U=>{var B;(B=U.onBeforeSubmit)==null||B.call(U,e,t,i,N)}),o.unshift({id:m.SetRangeValuesMutation.id,params:x}),s.push({id:m.SetRangeValuesMutation.id,params:H}),O!=null&&O.length){const U=m.getAddMergeMutationRangeByType(O),B={unitId:u,subUnitId:h,ranges:U},Y=this._injector.invoke(m.AddMergeUndoMutationFactory,B);o.unshift({id:m.RemoveWorksheetMergeMutation.id,params:Y}),s.push({id:m.AddWorksheetMergeMutation.id,params:B})}return{undos:o,redos:s}}_shouldDisableSeries(e){return e.every(t=>Object.keys(t).every(i=>{var o;return((o=t[i])==null?void 0:o.length)===0||[Ie.OTHER,Ie.FORMULA].includes(i)}))}_getPreferredApplyType(e){return e.every(i=>Object.keys(i).every(o=>{var s,l;return((s=i[o])==null?void 0:s.length)===0||((l=i[o])==null?void 0:l.length)===1&&i[o][0].data.length===1&&Ie.NUMBER===o}))?ce.COPY:ce.SERIES}},y.AutoFillController=Fd([Et(0,a.IUniverInstanceService),Et(1,a.ICommandService),Et(2,ut),Et(3,me),Et(4,R.IRenderManagerService),Et(5,a.Inject(a.Injector)),Et(6,a.Inject(y.SheetsRenderService))],y.AutoFillController);var zd=Object.getOwnPropertyDescriptor,Xd=(n,r,e,t)=>{for(var i=t>1?void 0:t?zd(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},Gr=(n,r)=>(e,t)=>r(e,t,n);y.CellCustomRenderController=class extends a.Disposable{constructor(e,t,i,o){super();T(this,"_enterActiveRender");this._context=e,this._sheetSkeletonManagerService=t,this._renderManagerService=i,this._permissionService=o,this._initEventBinding()}_initEventBinding(){const e=new a.DisposableCollection,t=this._context.unit,i=o=>{if(e.dispose(),!o)return;const s=this._context.unitId,{skeleton:l}=o,c=this._renderManagerService.getRenderById(s);if(c&&c.mainComponent){const d=c.mainComponent,u=S=>{const{offsetX:f,offsetY:v}=S,p=c.scene,C=t.getActiveSheet();if(!C)return;const b=p.getActiveViewportByCoord(R.Vector2.FromArray([f,v]));if(!b)return;const{scaleX:E,scaleY:w}=p.getAncestorScale(),O={x:b.viewportScrollX,y:b.viewportScrollY},M=l.getCellIndexByOffset(f,v,E,w,O),P=l.worksheet.getMergedCell(M.row,M.column),A={actualRow:P?P.startRow:M.row,actualCol:P?P.startColumn:M.column,row:M.row,col:M.column};if(!A||!l)return;const k=C.getCell(A.actualRow,A.actualCol);if(!k)return;const N=k.customRender;if(!(N!=null&&N.length))return;const H=A.actualRow,x=A.actualCol,L=N.sort(a.sortRules),V=C.getSheetId(),U={data:k,style:l.getStyles().getStyleByCell(k),primaryWithCoord:l.getCellWithCoordByIndex(A.actualRow,A.actualCol),unitId:s,subUnitId:V,row:H,col:x,workbook:t,worksheet:C},B={x:O.x+f/E,y:O.y+v/w},Y=L.find(F=>{var z;return(z=F.isHit)==null?void 0:z.call(F,B,U)});if(Y)return[Y,U]},h=d.onPointerDown$.subscribeEvent(S=>{var v,p,C,b;const f=u(S);if(f){const[E,w]=f,{row:O,col:M,worksheet:P,unitId:A,subUnitId:k}=w;if(!((v=this._permissionService.composePermission([new m.WorkbookEditablePermission(A).id,new m.WorksheetEditPermission(A,k).id]))==null?void 0:v.every(x=>x.value)))return!1;const H=(C=(p=P.getCell(O,M))==null?void 0:p.selectionProtection)==null?void 0:C[0];if((H==null?void 0:H[m.UnitAction.Edit])===!1)return!1;(b=E.onPointerDown)==null||b.call(E,w,S)}}),g=a.fromEventSubject(d.onPointerMove$).pipe(D.throttleTime(30)).subscribe(S=>{var v,p,C,b,E,w;const f=u(S);if(f){const[O,M]=f;this._enterActiveRender?this._enterActiveRender.render!==O&&((p=(v=this._enterActiveRender.render).onPointerLeave)==null||p.call(v,this._enterActiveRender.cellContext,S),this._enterActiveRender={render:O,cellContext:M},(C=O.onPointerEnter)==null||C.call(O,M,S)):(this._enterActiveRender={render:O,cellContext:M},(b=O.onPointerEnter)==null||b.call(O,M,S))}else this._enterActiveRender&&((w=(E=this._enterActiveRender.render).onPointerLeave)==null||w.call(E,this._enterActiveRender.cellContext,S),this._enterActiveRender=null)});h&&e.add(h),g&&e.add(g)}};this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i)),i(this._sheetSkeletonManagerService.getCurrentParam()),this.disposeWithMe(e)}},y.CellCustomRenderController=Xd([Gr(1,a.Inject(y.SheetSkeletonManagerService)),Gr(2,R.IRenderManagerService),Gr(3,a.IPermissionService)],y.CellCustomRenderController);class Zr extends a.Disposable{constructor(){super(...arguments);T(this,"rangesStack",[]);T(this,"selectedRangeWorksheet","")}}var Yd=Object.getOwnPropertyDescriptor,jd=(n,r,e,t)=>{for(var i=t>1?void 0:t?Yd(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},Fs=(n,r)=>(e,t)=>r(e,t,n);let tn=class{constructor(n,r){T(this,"_current",null);T(this,"_shortcutParam",[]);this._univerInstanceService=n,this._localeService=r}dispose(){this._shortcutParam=[]}getCurrentBySearch(n){return this._getCurrentBySearch(n)}getCurrent(){return this._getCurrentBySearch(this._current)}addOrUpdate(n){const r=this._getCurrentBySearch({unitId:n.unitId,sheetId:n.sheetId,keycode:n.keycode});if(r!=null){const e=this._shortcutParam.indexOf(r);this._shortcutParam.splice(e,1)}return this._shortcutParam.push(n),r}remove(n){if(n==null)return;const r=this._getCurrentBySearch(n);if(r==null)return;const e=this._shortcutParam.indexOf(r);return this._shortcutParam.splice(e,1)[0]}_getCurrentBySearch(n){return n==null?void 0:this._shortcutParam.find(e=>e.unitId===n.unitId&&e.sheetId===n.sheetId&&e.keycode===n.keycode)}};tn=jd([Fs(0,a.IUniverInstanceService),Fs(1,a.Inject(a.LocaleService))],tn);var Fi=(n=>(n.MergeAll="mergeAll",n.MergeVertical="mergeVertical",n.MergeHorizontal="mergeHorizontal",n))(Fi||{});function mt(n,r,e,t,i=!0,o=1,s=!0){let l={...n};t==null&&(t={startRow:0,endRow:e.getRowCount()-1,startColumn:0,endColumn:e.getColumnCount()-1});let c;switch(r){case a.Direction.UP:for(c=n.startRow-o;c>-1&&!e.getRowVisible(c);)c-=1;c>=t.startRow?(l.startRow=c,l.endRow=c):s&&(l.startRow=t.endRow,l.endRow=t.endRow,i&&(l=mt(l,a.Direction.LEFT,e,t,!1)));break;case a.Direction.DOWN:for(c=n.endRow+o;c<e.getRowCount()&&!e.getRowVisible(c);)c+=1;c<=t.endRow?(l.startRow=c,l.endRow=c):s&&(l.startRow=t.startRow,l.endRow=t.startRow,i&&(l=mt(l,a.Direction.RIGHT,e,t,!1)));break;case a.Direction.LEFT:for(c=n.startColumn-o;c>-1&&!e.getColVisible(c);)c-=1;c>=t.startColumn?(l.startColumn=c,l.endColumn=c):s&&(l.startColumn=t.endColumn,l.endColumn=t.endColumn,i&&(l=mt(l,a.Direction.UP,e,t,!1)));break;case a.Direction.RIGHT:for(c=n.endColumn+o;c<e.getColumnCount()&&!e.getColVisible(c);)c+=1;c<=t.endColumn?(l.startColumn=c,l.endColumn=c):s&&(l.startColumn=t.startColumn,l.endColumn=t.startColumn,i&&(l=mt(l,a.Direction.DOWN,e,t,!1)));break}return l}function Kr(n,r,e){const t={...n},{startRow:i,startColumn:o,endRow:s,endColumn:l}=Bn(n,r,e);let c=Fn(e,i,o,s,l).hasValue,d=!0,u=!0;for(;u;){if(a.Direction.UP===r){let h=t.startRow-1;for(;h>-1&&!e.getRowVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:g,matrix:S}=Fn(e,h,t.startColumn,h,t.endColumn);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue(v=>{f=Math.min(v,f)}),t.startRow=f}else t.startRow=h;if(t.endRow=t.startRow,!c&&g){u=!1;break}c=g,d=!1}}if(a.Direction.DOWN===r){let h=t.endRow+1;for(;h<e.getRowCount()&&!e.getRowVisible(h);)h+=1;if(h===e.getRowCount()){u=!1;break}const{hasValue:g,matrix:S}=Fn(e,h,t.startColumn,h,t.endColumn);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((v,p,C)=>{f=Math.max(v+(C.rowSpan||1)-1,f)}),t.endRow=f}else t.endRow=h;if(t.startRow=t.endRow,!c&&g){u=!1;break}c=g,d=!1}}if(a.Direction.LEFT===r){let h=t.startColumn-1;for(;h>-1&&!e.getColVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:g,matrix:S}=Fn(e,t.startRow,h,t.endRow,h);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((v,p)=>{f=Math.min(p,f)}),t.startColumn=f}else t.startColumn=h;if(t.endColumn=t.startColumn,!c&&g){u=!1;break}c=g,d=!1}}if(a.Direction.RIGHT===r){let h=t.endColumn+1;for(;h<e.getColumnCount()&&!e.getColVisible(h);)h+=1;if(h===e.getColumnCount()){u=!1;break}const{hasValue:g,matrix:S}=Fn(e,t.startRow,h,t.endRow,h);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((v,p,C)=>{f=Math.max(p+(C.colSpan||1)-1,f)}),t.endColumn=f}else t.endColumn=h;if(t.startColumn=t.endColumn,!c&&g){u=!1;break}c=g,d=!1}}}return m.alignToMergedCellsBorders(t,e,!0)}function zs(n,r,e){return mt(n,r,e,void 0,!1,1,!1)}function Gd(n,r,e){const t=Kr(n,r,e);return m.alignToMergedCellsBorders(a.Rectangle.union(t,n),e,!0)}function Zd(n,r,e){const t=zs(n,r,e),i={startRow:Math.min(n.startRow,t.startRow),startColumn:Math.min(n.startColumn,t.startColumn),endRow:Math.max(n.endRow,t.endRow),endColumn:Math.max(n.endColumn,t.endColumn)};return m.alignToMergedCellsBorders(a.Rectangle.union(n,i),e)}function Kd(n,r,e,t){const i=a.getReverseDirection(e),o=Kr(Bn(n,i,t),e,t);return e===a.Direction.UP&&o.startRow<=n.startRow?m.alignToMergedCellsBorders({...r,startColumn:n.startColumn,endColumn:n.endColumn},t,!0):e===a.Direction.DOWN&&o.endRow>=n.endRow?m.alignToMergedCellsBorders({...r,startColumn:n.startColumn,endColumn:n.endColumn},t,!0):e===a.Direction.LEFT&&o.startColumn<=n.startColumn?m.alignToMergedCellsBorders({...r,startRow:n.startRow,endRow:n.endRow},t,!0):e===a.Direction.RIGHT&&o.endColumn>=n.endColumn?m.alignToMergedCellsBorders({...r,startRow:n.startRow,endRow:n.endRow},t,!0):a.Rectangle.union(a.Rectangle.clone(r),o)}function qd(n,r,e){const t=a.getReverseDirection(r),i=Bn(n,t,e),o=Bn(n,r,e),s=zs(i,r,e);return m.alignToMergedCellsBorders(a.Rectangle.union(o,s),e,!1)}function Xs(n){return{startRow:0,startColumn:0,endRow:n.getRowCount()-1,endColumn:n.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL}}function Bn(n,r,e){let t;switch(r){case a.Direction.UP:t={startRow:n.startRow,startColumn:n.startColumn,endRow:n.startRow,endColumn:n.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.DOWN:t={startRow:n.endRow,startColumn:n.startColumn,endRow:n.endRow,endColumn:n.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.LEFT:t={startRow:n.startRow,startColumn:n.startColumn,endRow:n.endRow,endColumn:n.startColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.RIGHT:t={startRow:n.startRow,startColumn:n.endColumn,endRow:n.endRow,endColumn:n.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;default:throw new Error("Invalid direction")}return m.alignToMergedCellsBorders(t,e,!1)}function Fn(n,r,e,t,i){let o=!1;const s=n.getMatrixWithMergedCells(r,e,t,i).forValue((l,c,d)=>{if(Jd(d))return o=!0,!1});return{hasValue:o,matrix:s}}function qr(n,r,e){const t=a.Rectangle.clone(n);if(r==null)return t;switch(e){case a.Direction.UP:case a.Direction.DOWN:t.startColumn=t.endColumn=r.actualColumn;break;case a.Direction.LEFT:case a.Direction.RIGHT:t.startRow=t.endRow=r.actualRow;break}return t}function Qd(n,r,e){var l,c,d,u;const{primary:t,range:i}=n,o=a.Rectangle.clone(i);switch(r){case a.Direction.UP:case a.Direction.DOWN:o.startRow=(l=t==null?void 0:t.startRow)!=null?l:i.startRow,o.endRow=(c=t==null?void 0:t.endRow)!=null?c:i.startRow;break;case a.Direction.LEFT:case a.Direction.RIGHT:o.startColumn=(d=t==null?void 0:t.startColumn)!=null?d:i.startColumn,o.endColumn=(u=t==null?void 0:t.endColumn)!=null?u:i.startColumn;break}const s=Bn(o,r,e);switch(r){case a.Direction.DOWN:return i.startRow<s.startRow;case a.Direction.UP:return i.endRow>s.endRow;case a.Direction.LEFT:return s.endColumn<i.endColumn;case a.Direction.RIGHT:return s.startColumn>i.startColumn}}function Ys(n,r){let e=n[0].startRow,t=n[0].endRow;n.forEach(o=>{const{startRow:s,endRow:l}=o;e=Math.min(e,s),t=Math.max(t,l)});const i=new Array(t-e+1).fill(!1);return r.forEach(o=>{const{startRow:s,endRow:l}=o;for(let c=Math.max(s,e);c<=Math.min(l,t);c++)i[c-e]=!0}),n.every(o=>{const{startRow:s,endRow:l}=o;for(let c=s;c<=l;c++)if(!i[c-e])return!1;return!0})}function js(n,r){let e=n[0].startColumn,t=n[0].endColumn;n.forEach(o=>{const{startColumn:s,endColumn:l}=o;e=Math.min(e,s),t=Math.max(t,l)});const i=new Array(t-e+1).fill(!1);return r.forEach(o=>{const{startColumn:s,endColumn:l}=o;for(let c=Math.max(s,e);c<=Math.min(l,t);c++)i[c-e]=!0}),n.every(o=>{const{startColumn:s,endColumn:l}=o;for(let c=s;c<=l;c++)if(!i[c-e])return!1;return!0})}function Qr(n,r){return r?n==="mergeAll"?r.filter(e=>!(e.startRow===e.endRow&&e.startColumn===e.endColumn)):n==="mergeVertical"?r.filter(e=>e.startRow!==e.endRow):n==="mergeHorizontal"?r.filter(e=>e.startColumn!==e.endColumn):r:null}function Jd(n){return n.v!==void 0&&n.v!==null&&n.v!==""||n.p!==void 0}var Xe=(n=>(n[n.moveStopeOne=0]="moveStopeOne",n[n.moveGap=1]="moveGap",n[n.moveStepPage=2]="moveStepPage",n[n.moveStepEnd=3]="moveStepEnd",n))(Xe||{});const Re={id:"sheet.command.move-selection",type:a.CommandType.COMMAND,handler:(n,r)=>{if(!r)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{workbook:t,worksheet:i}=e,o=m.getSelectionsService(n,r.fromCurrentSelection).getCurrentLastSelection();if(!o)return!1;const{direction:s,jumpOver:l,extra:c}=r,{range:d,primary:u}=o,h=qr(d,u,s),g=l===1?Kr(h,s,i):mt(h,s,i),S=m.getCellAtRowCol(g.startRow,g.startColumn,i);if(a.Rectangle.equals(S,h))return!1;const f=t.getUnitId();n.get(tn).remove({unitId:f,sheetId:i.getSheetId(),keycode:_.KeyCode.TAB});const v=[{range:a.Rectangle.clone(S),primary:{startRow:S.startRow,startColumn:S.startColumn,endRow:S.endRow,endColumn:S.endColumn,actualRow:g.startRow,actualColumn:g.startColumn,isMerged:S.isMerged,isMergedMainCell:S.startRow===g.startRow&&S.startColumn===g.startColumn}}];return n.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:t.getUnitId(),subUnitId:i.getSheetId(),selections:v,type:m.SelectionMoveType.MOVE_END,extra:c,reveal:!0})}},Ye={id:"sheet.command.move-selection-enter-tab",type:a.CommandType.COMMAND,handler:(n,r)=>{var U;if(!r)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{workbook:t,worksheet:i}=e,o=m.getSelectionsService(n),{direction:s,keycode:l}=r,c=s===a.Direction.LEFT||s===a.Direction.UP,d=o.getCurrentSelections().concat(),u=d.findIndex(B=>B.primary),h=d[u];if(!h)return!1;const g=c?-1:1,S=u+g!==d.length?d[u+g]:d[0],f=d.findIndex(B=>B===S),v=t.getUnitId(),p=i.getSheetId();if(!h)return!1;const{range:C}=h,b=h.primary;let E=qr(C,b,s);const w=n.get(tn),O=w.getCurrentBySearch({unitId:v,sheetId:p,keycode:_.KeyCode.TAB});let M;const{startRow:P,endRow:A,startColumn:k,endColumn:N}=C,H=c?b.startRow===P&&b.startColumn===k:b.endRow===A&&b.endColumn===N;if(a.Rectangle.equals(C,b)){if(l===_.KeyCode.TAB)O==null&&w.addOrUpdate({unitId:v,sheetId:p,keycode:_.KeyCode.TAB,selection:h});else{const F=O==null?void 0:O.selection;if(F!=null){const{range:z,primary:j}=F;E=qr(z,j,s)}w.remove({unitId:v,sheetId:p,keycode:_.KeyCode.TAB})}const B=mt(E,s,i),Y=m.getCellAtRowCol(B.startRow,B.startColumn,i);if(a.Rectangle.equals(Y,E))return!1;M={range:a.Rectangle.clone(Y),primary:{startRow:Y.startRow,startColumn:Y.startColumn,endRow:Y.endRow,endColumn:Y.endColumn,actualRow:B.startRow,actualColumn:B.startColumn,isMerged:Y.isMerged,isMergedMainCell:Y.startRow===B.startRow&&Y.startColumn===B.startColumn}}}else{w.remove({unitId:v,sheetId:p,keycode:_.KeyCode.TAB});const B=a.Tools.deepClone(b),Y=H?S.range:mt({startRow:B.startRow,startColumn:B.startColumn,endRow:B.endRow,endColumn:B.endColumn},s,i,{startRow:P,endRow:A,startColumn:k,endColumn:N}),F=H&&c,z=F?m.getCellAtRowCol(Y.endRow,Y.endColumn,i):m.getCellAtRowCol(Y.startRow,Y.startColumn,i);M={range:H?S.range:a.Rectangle.clone(C),primary:{startRow:z.startRow,startColumn:z.startColumn,endRow:z.endRow,endColumn:z.endColumn,actualRow:F?z.startRow:Y.startRow,actualColumn:F?z.startColumn:Y.startColumn,isMerged:z.isMerged,isMergedMainCell:z.startRow===Y.startRow&&z.startColumn===Y.startColumn},style:H?S.style:h.style}}H?(d[u].primary=null,d[f]=M,o.setSelections(v,p,[],m.SelectionMoveType.MOVE_END)):d[u]=M;const x=n.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:v,subUnitId:p,type:m.SelectionMoveType.MOVE_END,selections:d,reveal:!0,extra:r.extra}),V=(U=n.get(R.IRenderManagerService).getRenderById(v))==null?void 0:U.with(ve);return V==null||V.refreshSelectionMoveEnd(),x}},Pe={id:"sheet.command.expand-selection",type:a.CommandType.COMMAND,handler:(n,r)=>{if(!r)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{worksheet:t,unitId:i,subUnitId:o}=e,s=m.getSelectionsService(n).getCurrentLastSelection();if(!s)return!1;const{range:l,primary:c}=s,{jumpOver:d,direction:u,extra:h}=r,S=Qd(s,u,t)?d===1?Kd(l,{...a.Rectangle.clone(c),rangeType:a.RANGE_TYPE.NORMAL},u,t):qd(l,u,t):d===1?Gd(l,u,t):Zd(l,u,t);return S.rangeType=s.range.rangeType,a.Rectangle.equals(S,l)?!1:n.get(a.ICommandService).syncExecuteCommand(m.SetSelectionsOperation.id,{unitId:i,subUnitId:o,type:m.SelectionMoveType.MOVE_END,selections:[{range:S,primary:c}],extra:h,reveal:!0})}},zn={id:"sheet.command.select-all",type:a.CommandType.COMMAND,handler:async(n,r={expandToGapFirst:!0,loop:!1})=>{const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const t=m.getSelectionsService(n).getCurrentLastSelection();if(!t)return!1;const i=n.get(Zr),{worksheet:o,unitId:s,subUnitId:l}=e,c=`${s}|${l}`;c!==i.selectedRangeWorksheet&&(i.rangesStack=[],i.selectedRangeWorksheet=c);const d=o.getMaxRows(),u=o.getMaxColumns(),{expandToGapFirst:h,loop:g}=r,{range:S,primary:f}=t,v=S.endColumn===u-1&&S.endRow===d-1&&S.startRow===0&&S.startColumn===0;i.rangesStack.some(O=>a.Rectangle.equals(O,S))||(i.rangesStack=[],i.rangesStack.push(S));let p;if(v)if(g){if(i.rangesStack.findIndex(M=>a.Rectangle.equals(M,S))!==i.rangesStack.length-1)return!1;p=i.rangesStack[0]}else return!1;else h?(p=m.expandToContinuousRange(S,{left:!0,right:!0,up:!0,down:!0},o),a.Rectangle.equals(p,S)&&(p=Xs(o))):p=Xs(o);i.rangesStack.some(O=>a.Rectangle.equals(O,p))||i.rangesStack.push(p);const C=[];C.push({id:m.SetSelectionsOperation.id,params:{unitId:s,subUnitId:l,reveal:!0,selections:[{range:p,primary:f}]}});const E=n.get(m.SheetInterceptorService).onCommandExecute({id:zn.id,params:{range:S}});E.redos.length&&C.push(...E.redos);const w=n.get(a.ICommandService);return a.sequenceExecute(C,w),!0}};var $d=Object.getOwnPropertyDescriptor,eu=(n,r,e,t)=>{for(var i=t>1?void 0:t?$d(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},tu=(n,r)=>(e,t)=>r(e,t,n);y.SheetScrollManagerService=class{constructor(r,e){T(this,"_scrollStateMap",new Map);T(this,"_rawScrollInfo$",new D.BehaviorSubject(null));T(this,"rawScrollInfo$",this._rawScrollInfo$.asObservable());T(this,"validViewportScrollInfo$",new D.BehaviorSubject(null));T(this,"_searchParamForScroll",null);this._context=r,this._sheetSkeletonManagerService=e}dispose(){this._rawScrollInfo$.complete()}calcViewportScrollFromRowColOffset(r){if(!r)return{viewportScrollX:0,viewportScrollY:0};let{sheetViewStartColumn:e,sheetViewStartRow:t,offsetX:i,offsetY:o}=r;t=t||0,o=o||0;const s=this._sheetSkeletonManagerService.getCurrentSkeleton(),l=(s==null?void 0:s.rowHeightAccumulation[t-1])||0,d=((s==null?void 0:s.columnWidthAccumulation[e-1])||0)+i,u=l+o;return{viewportScrollX:d,viewportScrollY:u}}setSearchParam(r){this._searchParamForScroll=r}getScrollStateByParam(r){return this._getCurrentScroll(r)}getCurrentScrollState(){return this._getCurrentScroll(this._searchParamForScroll)}setValidScrollState(r){this._setScrollState(r)}emitRawScrollParam(r){this._emitRawScroll(r)}setValidScrollStateToCurrSheet(r){if(this._searchParamForScroll==null)return;this._setScrollState({...this._searchParamForScroll,...r});const e=this._searchParamForScroll.sheetId,t=this._sheetSkeletonManagerService.getSkeleton(e);t&&t.setScroll(r.viewportScrollX,r.viewportScrollY)}clear(){this._searchParamForScroll!=null&&this._clearByParamAndNotify(this._searchParamForScroll)}_setScrollState(r){const{unitId:e,sheetId:t,sheetViewStartColumn:i,sheetViewStartRow:o,offsetX:s,offsetY:l}=r;this._scrollStateMap.has(e)||this._scrollStateMap.set(e,new Map);const c=this._scrollStateMap.get(e),d={sheetViewStartRow:o,sheetViewStartColumn:i,offsetX:s,offsetY:l};c.set(t,d)}_clearByParamAndNotify(r){this._setScrollState({...r,sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0}),this._emitRawScroll({sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0})}_getCurrentScroll(r){var s;const e={sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0};if(r==null)return e;const{unitId:t,sheetId:i}=r;return((s=this._scrollStateMap.get(t))==null?void 0:s.get(i))||e}_emitRawScroll(r){this._rawScrollInfo$.next(r)}},y.SheetScrollManagerService=eu([tu(1,a.Inject(y.SheetSkeletonManagerService))],y.SheetScrollManagerService);const Le={id:"sheet.operation.set-scroll",type:a.CommandType.OPERATION,handler:(n,r)=>{if(!r)return!1;const{unitId:e,sheetId:t,offsetX:i,offsetY:o,sheetViewStartColumn:s,sheetViewStartRow:l}=r;return n.get(R.IRenderManagerService).getRenderById(e).with(y.SheetScrollManagerService).emitRawScrollParam({unitId:e,sheetId:t,offsetX:i,offsetY:o,sheetViewStartRow:l,sheetViewStartColumn:s}),!0}},nn={id:"sheet.command.set-scroll-relative",type:a.CommandType.COMMAND,handler:async(n,r)=>{const e=n.get(a.ICommandService),t=n.get(a.IUniverInstanceService),i=n.get(R.IRenderManagerService),o=m.getSheetCommandTarget(t);if(!o)return!1;const{unitId:s,subUnitId:l}=o,d=i.getRenderById(s).with(y.SheetScrollManagerService).getCurrentScrollState(),{offsetX:u=0,offsetY:h=0}=r||{},{sheetViewStartRow:g=0,sheetViewStartColumn:S=0,offsetX:f=0,offsetY:v=0}=d||{};return e.executeCommand(Le.id,{unitId:s,sheetId:l,sheetViewStartRow:g,sheetViewStartColumn:S,offsetX:f+u,offsetY:v+h})}},Ue={id:"sheet.command.scroll-view",type:a.CommandType.COMMAND,handler:(n,r)=>{if(!r)return!1;const e=n.get(a.IUniverInstanceService),t=n.get(R.IRenderManagerService),i=m.getSheetCommandTarget(e);if(!i)return!1;const{workbook:o,worksheet:s,unitId:l}=i,d=t.getRenderById(l).with(y.SheetScrollManagerService).getCurrentScrollState();if(!s)return!1;const{sheetViewStartRow:u,sheetViewStartColumn:h,offsetX:g,offsetY:S}=r,{sheetViewStartColumn:f,sheetViewStartRow:v,offsetX:p,offsetY:C}=d||{},{xSplit:b,ySplit:E}=i.worksheet.getConfig().freeze;return n.get(a.ICommandService).syncExecuteCommand(Le.id,{unitId:o.getUnitId(),sheetId:s.getSheetId(),sheetViewStartRow:u!=null?u:v!=null?v:0+E,sheetViewStartColumn:h!=null?h:f!=null?f:0+b,offsetX:g!=null?g:p,offsetY:S!=null?S:C})}},Jr={id:"sheet.command.scroll-to-cell",type:a.CommandType.COMMAND,handler:(n,r)=>{const e=n.get(a.IUniverInstanceService);return n.get(R.IRenderManagerService).getRenderById(e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(y.SheetsScrollRenderController).scrollToRange(r.range,r.forceTop,r.forceLeft)}},nu={id:"sheet.command.scroll-view-reset",type:a.CommandType.COMMAND,handler:async n=>{const r=n.get(a.IUniverInstanceService),e=m.getSheetCommandTarget(r);if(!e)return!1;const{subUnitId:t,unitId:i}=e;return n.get(a.ICommandService).executeCommand(Le.id,{unitId:i,sheetId:t,sheetViewStartRow:0,sheetViewStartColumn:0})}};var iu=Object.getOwnPropertyDescriptor,ru=(n,r,e,t)=>{for(var i=t>1?void 0:t?iu(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},rn=(n,r)=>(e,t)=>r(e,t,n);Re.id,Ye.id;const ou=3;y.SheetsScrollRenderController=class extends a.Disposable{constructor(r,e,t,i,o,s,l){super(),this._context=r,this._injector=e,this._sheetSkeletonManagerService=t,this._contextService=i,this._commandService=o,this._renderManagerService=s,this._scrollManagerService=l,this._initCommandListener(),this._wheelEventListener(),this._scrollBarEventListener(),this._initSkeletonListener()}_wheelEventListener(){const{scene:r}=this._context;if(!r)return;const e=r.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN);e&&this.disposeWithMe(r.onMouseWheel$.subscribeEvent((t,i)=>{if(t.ctrlKey||!this._contextService.getContextValue(a.FOCUSING_SHEET))return;let o=0,s=0;o=t.deltaX,t.shiftKey?o=(t.deltaY||t.deltaX)*ou:s=t.deltaY,this._commandService.executeCommand(nn.id,{offsetX:o,offsetY:s}),this._context.scene.makeDirty(!0);const l=e.limitedScroll(e.scrollX+o,e.scrollY+s);l&&!l.isLimitedX&&!l.isLimitedY&&(t.preventDefault(),r.getParent().classType===R.RENDER_CLASS_TYPE.SCENE_VIEWER&&i.stopPropagation()),e.isWheelPreventDefaultX&&e.isWheelPreventDefaultY&&t.preventDefault()}))}_scrollBarEventListener(){const{scene:r}=this._context;if(r==null)return;const e=r.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN);e&&(this.disposeWithMe(a.toDisposable(this._scrollManagerService.rawScrollInfo$.subscribe(t=>{var S;const i=(S=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:S.skeleton;if(!i)return;if(t==null){e.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});return}const{sheetViewStartRow:o,sheetViewStartColumn:s,offsetX:l,offsetY:c}=t,{startX:d,startY:u}=i.getCellWithCoordByIndex(o,s,!1),h=d+l,g=u+c;e.scrollToViewportPos({viewportScrollX:h,viewportScrollY:g})}))),this.disposeWithMe(e.onScrollAfter$.subscribeEvent(t=>{var v;const i=(v=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:v.skeleton;if(i==null||t.isTrigger===!1)return;const o=this._getSheetObject();if(i==null||o==null)return;const{viewportScrollX:s,viewportScrollY:l,scrollX:c,scrollY:d}=t,{row:u,column:h,rowOffset:g,columnOffset:S}=i.getOffsetRelativeToRowCol(s,l),f={sheetViewStartRow:u,sheetViewStartColumn:h,offsetX:S,offsetY:g,viewportScrollX:s,viewportScrollY:l,scrollX:c,scrollY:d};this._scrollManagerService.setValidScrollStateToCurrSheet(f),this._scrollManagerService.validViewportScrollInfo$.next({...f,viewportScrollX:s,viewportScrollY:l,scrollX:c,scrollY:d})})),this.disposeWithMe(e.onScrollByBar$.subscribeEvent(t=>{var g;const i=(g=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:g.skeleton;if(i==null||t.isTrigger===!1)return;const o=this._getSheetObject();if(i==null||o==null)return;const{viewportScrollX:s=0,viewportScrollY:l=0}=t;this._getFreeze();const{row:c,column:d,rowOffset:u,columnOffset:h}=i.getOffsetRelativeToRowCol(s,l);this._commandService.executeCommand(Ue.id,{sheetViewStartRow:c,sheetViewStartColumn:d,offsetX:h,offsetY:u})})))}_initSkeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeletonBefore$.subscribe(r=>{if(r==null)return;const e={unitId:r.unitId,sheetId:r.sheetId};if(this._scrollManagerService.setSearchParam(e),!this._getSheetObject())return;const i=this._scrollManagerService.getScrollStateByParam(e),{viewportScrollX:o,viewportScrollY:s}=this._scrollManagerService.calcViewportScrollFromRowColOffset(i);i&&this._updateViewportScroll(o,s)})))}_updateViewportScroll(r=0,e=0){const t=this._getSheetObject();if(!t)return;const i=t.scene,o=i.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN),s=i.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT),l=i.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM),c=i.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT),d=i.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);o&&(o.viewportScrollX=r,o.viewportScrollY=e),l&&(l.viewportScrollY=e),s&&(s.viewportScrollX=r),c&&(c.viewportScrollY=e),d&&(d.viewportScrollX=r)}scrollToRange(r,e,t){let{endRow:i,endColumn:o,startColumn:s,startRow:l}=r;const c=this._getViewportBounding();if(r.rangeType===a.RANGE_TYPE.ROW?(s=0,o=0):r.rangeType===a.RANGE_TYPE.COLUMN&&(l=0,i=0),c&&!e&&!t){const d=c.startRow>i?l:i,u=c.startColumn>o?s:o;return this._scrollToCell(d,u)}else return this._scrollToCell(l,s,e,t)}scrollToCell(r,e){const t=this._context.unit.getActiveSheet(),{ySplit:i,xSplit:o}=t.getFreeze();return this._commandService.syncExecuteCommand(Ue.id,{sheetViewStartRow:r-i,sheetViewStartColumn:e-o,offsetX:0,offsetY:0})}_initCommandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{switch(r.id){case m.SetSelectionsOperation.id:{const e=r.params;e.unitId===this._context.unitId&&e.reveal&&this._scrollToSelection()}break;case m.ScrollToCellOperation.id:{const e=r.params;if(e.unitId===this._context.unitId){const t=e.range;this.scrollToRange(t)}}break;case Pe.id:{const e=r.params;this._scrollToSelectionForExpand(e)}break}}))}_scrollToSelectionForExpand(r){setTimeout(()=>{const e=this._getSelectionsService().getCurrentLastSelection();if(e==null)return;const{startRow:t,startColumn:i,endRow:o,endColumn:s}=e.range,l=this._getViewportBounding();if(l==null)return;const{startRow:c,startColumn:d,endRow:u,endColumn:h}=l;let g=0,S=0;t>c?g=o:o<u?g=t:g=c,i>d?S=s:s<h?S=i:S=d,r.direction===a.Direction.DOWN?g=o:r.direction===a.Direction.UP?g=t:r.direction===a.Direction.RIGHT?S=s:r.direction===a.Direction.LEFT&&(S=i),this._scrollToCell(g,S)},0)}_getFreeze(){var e;const r=(e=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:e.skeleton.getWorksheetConfig();if(r!=null)return r.freeze}_updateSceneSize(r){var h;if(r==null)return;const{unitId:e}=this._context,{skeleton:t}=r,i=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.scene;if(t==null||i==null)return;const{rowTotalHeight:o,columnTotalWidth:s,rowHeaderWidthAndMarginLeft:l,columnHeaderHeightAndMarginTop:c}=t;this._context.unit.getActiveSheet()&&(i==null||i.transformByState({width:l+s,height:c+o}))}_getSheetObject(){return Ne(this._context.unit,this._context)}_scrollToSelectionByDirection(r){const e=this._getViewportBounding();if(e==null)return!1;const{startRow:t,startColumn:i,endRow:o,endColumn:s}=e;let l=0,c=0;const{startRow:d,startColumn:u,endRow:h,endColumn:g}=r;d>=t&&(l=h),h<=o&&(l=d),u>=i&&(c=g),g<=s&&(c=u),this._scrollToCell(l,c)}_scrollToSelection(r=!0){var d;const e=this._getSelectionsService().getCurrentLastSelection();if(!e)return;const{startRow:t,startColumn:i,actualRow:o,actualColumn:s}=(d=e.primary)!=null?d:e.range,l=r&&o!=null?o:t,c=r&&s!=null?s:i;this._scrollToCell(l,c)}_getSelectionsService(){return m.getSelectionsService(this._injector)}_getViewportBounding(){var o,s;const r=(o=this._getSheetObject())==null?void 0:o.scene;if(r==null)return;const e=r.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e==null)return;const t=(s=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:s.skeleton;if(t==null)return;const i=e.calcViewportInfo();return t.getRangeByViewBound(i.viewBound)}_scrollToCell(r,e,t=!1,i=!1){var N,H,x;const{rowHeightAccumulation:o,columnWidthAccumulation:s}=(N=this._sheetSkeletonManagerService.getCurrentSkeleton())!=null?N:{};if(o==null||s==null)return!1;const l=(H=this._getSheetObject())==null?void 0:H.scene;if(l==null)return!1;const c=l.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(c==null)return!1;const d=(x=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:x.skeleton;if(d==null)return!1;const u=this._context.unit.getActiveSheet();if(!u)return!1;r=a.Tools.clamp(r,0,o.length-1),e=a.Tools.clamp(e,0,s.length-1);const{startColumn:h,startRow:g,ySplit:S,xSplit:f}=u.getFreeze(),v=this._getViewportBounding();if(v==null)return!1;const{startRow:p,startColumn:C,endRow:b,endColumn:E}=v;let w,O;if(r>=g&&e>=h-S&&(r<=p&&(w=r,t=!0),r>=b)){const L=o[r]-c.height;for(let V=p;V<=r&&(w=V+1,!(o[V]>=L));V++);}if(e>=h&&r>=g-S&&(e<=C&&(O=e,i=!0),e>=E)){const L=s[e]-c.width;for(let V=C;V<=e&&(O=V+1,!(s[V]>=L));V++);}if(w===void 0&&O===void 0)return!1;let{offsetX:M,offsetY:P,sheetViewStartRow:A,sheetViewStartColumn:k}=this._scrollManagerService.getCurrentScrollState()||{};if(w=w?Math.min(w,r):A+S,O=O?Math.min(O,e):k+f,i){M=0,O=e;const L=d.getHiddenColumnsInRange({startColumn:O-f,endColumn:O});O=O-L.length}if(t){P=0,w=r;const L=d.getHiddenRowsInRange({startRow:w-S,endRow:w});w=w-L.length}return this._commandService.syncExecuteCommand(Ue.id,{sheetViewStartRow:Math.max(0,w-S),sheetViewStartColumn:Math.max(0,O-f),offsetX:M,offsetY:P})}},y.SheetsScrollRenderController=ru([rn(1,a.Inject(a.Injector)),rn(2,a.Inject(y.SheetSkeletonManagerService)),rn(3,a.IContextService),rn(4,a.ICommandService),rn(5,R.IRenderManagerService),rn(6,a.Inject(y.SheetScrollManagerService))],y.SheetsScrollRenderController);const $r={id:"sheet.operation.scroll-to-range",type:a.CommandType.OPERATION,handler:(n,r)=>{if(!r)return!1;const e=n.get(a.IUniverInstanceService);return n.get(R.IRenderManagerService).getRenderById(e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(y.SheetsScrollRenderController).scrollToRange(r.range,r.forceTop,r.forceLeft)}};class Gs{constructor(){T(this,"_state",null);T(this,"_rect",null);T(this,"_state$",new D.BehaviorSubject(null));T(this,"state$",this._state$.asObservable());T(this,"_rect$",new D.BehaviorSubject(null));T(this,"rect$",this._rect$.asObservable());T(this,"_focus",!1);T(this,"_focus$",new D.BehaviorSubject(this._focus));T(this,"focus$",this._focus$.asObservable())}dispose(){this._state$.complete(),this._state=null,this._rect$.complete(),this._rect=null}setState(r){this._state=r,this._refresh(r)}getRect(){return this._rect}setRect(r){this._rect=r,this._rect$.next(r)}getState(){return this._state}setFocus(r=!1){this._focus=r,this._focus$.next(r)}_refresh(r){this._state$.next(r)}}const Xn=a.createIdentifier("univer.sheet-cell-editor-manager.service"),Oe="sheets-ui.config",eo={formulaBar:!0,statusBarStatistic:!0,maxAutoHeightCount:1e3};var Ve=function(){return Ve=Object.assign||function(n){for(var r,e=1,t=arguments.length;e<t;e++){r=arguments[e];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(n[i]=r[i])}return n},Ve.apply(this,arguments)},su=function(n,r){var e={};for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&r.indexOf(t)<0&&(e[t]=n[t]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,t=Object.getOwnPropertySymbols(n);i<t.length;i++)r.indexOf(t[i])<0&&Object.prototype.propertyIsEnumerable.call(n,t[i])&&(e[t[i]]=n[t[i]]);return e},Ce=W.forwardRef(function(n,r){var e=n.icon,t=n.id,i=n.className,o=n.extend,s=su(n,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(t," ").concat(i||"").trim(),c=W.useRef("_".concat(cu()));return Zs(e,"".concat(t),{defIds:e.defIds,idSuffix:c.current},Ve({ref:r,className:l},s),o)});function Zs(n,r,e,t,i){return W.createElement(n.tag,Ve(Ve({key:r},au(n,e,i)),t),(lu(n,e).children||[]).map(function(o,s){return Zs(o,"".concat(r,"-").concat(n.tag,"-").concat(s),e,void 0,i)}))}function au(n,r,e){var t=Ve({},n.attrs);e!=null&&e.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=e.colorChannel1),n.tag==="mask"&&t.id&&(t.id=t.id+r.idSuffix),Object.entries(t).forEach(function(o){var s=o[0],l=o[1];s==="mask"&&typeof l=="string"&&(t[s]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))});var i=r.defIds;return!i||i.length===0||(n.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+r.idSuffix),Object.entries(t).forEach(function(o){var s=o[0],l=o[1];typeof l=="string"&&(t[s]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),t}function lu(n,r){var e,t=r.defIds;return!t||t.length===0?n:n.tag==="defs"&&(!((e=n.children)===null||e===void 0)&&e.length)?Ve(Ve({},n),{children:n.children.map(function(i){return typeof i.attrs.id=="string"&&t&&t.includes(i.attrs.id)?Ve(Ve({},i),{attrs:Ve(Ve({},i.attrs),{id:i.attrs.id+r.idSuffix})}):i})}):n}function cu(){return Math.random().toString(36).substring(2,8)}Ce.displayName="UniverIcon";var du={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M11.0363 12.2367V14.0367C11.0363 14.3681 11.3049 14.6367 11.6363 14.6367C11.9676 14.6367 12.2363 14.3681 12.2363 14.0367V12.2367H14.0364C14.3677 12.2367 14.6364 11.9681 14.6364 11.6367C14.6364 11.3054 14.3677 11.0367 14.0364 11.0367H12.2363V9.23672C12.2363 8.90535 11.9676 8.63672 11.6363 8.63672C11.3049 8.63672 11.0363 8.90535 11.0363 9.23672V11.0367H9.23635C8.90498 11.0367 8.63635 11.3054 8.63635 11.6367C8.63635 11.9681 8.90498 12.2367 9.23635 12.2367H11.0363Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M2.56365 1.36377C1.90091 1.36377 1.36365 1.90103 1.36365 2.56377V6.16377C1.36365 6.82651 1.90091 7.36377 2.56365 7.36377H6.16365C6.82639 7.36377 7.36365 6.82651 7.36365 6.16377V2.56377C7.36365 1.90103 6.82639 1.36377 6.16365 1.36377H2.56365ZM6.16365 2.56377H2.56365L2.56365 6.16377H6.16365V2.56377Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M2.56365 8.63647C1.90091 8.63647 1.36365 9.17373 1.36365 9.83647V13.4365C1.36365 14.0992 1.90091 14.6365 2.56365 14.6365H6.16365C6.82639 14.6365 7.36365 14.0992 7.36365 13.4365V9.83647C7.36365 9.17373 6.82639 8.63647 6.16365 8.63647H2.56365ZM6.16365 9.83647H2.56365L2.56365 13.4365H6.16365V9.83647Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M9.83635 7.36377C9.17361 7.36377 8.63635 6.82651 8.63635 6.16377V2.56377C8.63635 1.90103 9.17361 1.36377 9.83635 1.36377H13.4364C14.0991 1.36377 14.6364 1.90103 14.6364 2.56377V6.16377C14.6364 6.82651 14.0991 7.36377 13.4364 7.36377H9.83635ZM9.83635 6.16377V2.56377L13.4364 2.56377V6.16377H9.83635Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ks=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"autofill-double-icon",ref:r,icon:du}))});Ks.displayName="AutofillDoubleIcon";var uu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},on=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"check-mark-icon",ref:r,icon:uu}))});on.displayName="CheckMarkIcon";var hu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.71274 2.86421C3.47843 2.6299 3.09853 2.6299 2.86421 2.86421C2.6299 3.09853 2.6299 3.47843 2.86421 3.71274L7.15154 8.00007L2.86421 12.2874C2.6299 12.5217 2.6299 12.9016 2.86421 13.1359C3.09853 13.3702 3.47843 13.3702 3.71274 13.1359L8.00007 8.84859L12.2874 13.1359C12.5217 13.3702 12.9016 13.3702 13.1359 13.1359C13.3702 12.9016 13.3702 12.5217 13.1359 12.2874L8.84859 8.00007L13.1359 3.71274C13.3702 3.47843 13.3702 3.09853 13.1359 2.86421C12.9016 2.6299 12.5217 2.6299 12.2874 2.86421L8.00007 7.15154L3.71274 2.86421Z"}}]},qs=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"close-icon",ref:r,icon:hu}))});qs.displayName="CloseIcon";var mu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"g",attrs:{fill:"currentColor",clipPath:"url(#convert-icon_clip0_911_593)"},children:[{tag:"path",attrs:{d:"M2.44766 0.848145C1.564 0.848145 0.847656 1.56449 0.847656 2.44814V6.44814C0.847656 7.3318 1.564 8.04814 2.44766 8.04814H6.44766C7.33131 8.04814 8.04766 7.3318 8.04766 6.44814V2.44814C8.04766 1.56449 7.33131 0.848145 6.44766 0.848145H2.44766ZM2.04766 6.44814V5.04824H3.84775V6.84814H2.44766C2.22674 6.84814 2.04766 6.66906 2.04766 6.44814ZM2.04766 3.84824H3.84775V2.04814H2.44766C2.22674 2.04814 2.04766 2.22723 2.04766 2.44814V3.84824ZM5.04775 6.84814V5.04824H6.84766V6.44814C6.84766 6.66906 6.66857 6.84814 6.44766 6.84814H5.04775ZM5.04775 3.84824H6.84766V2.44814C6.84766 2.22723 6.66857 2.04814 6.44766 2.04814H5.04775V3.84824Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{d:"M9.55215 7.95166C8.66849 7.95166 7.95215 8.668 7.95215 9.55166V13.5517C7.95215 14.4353 8.66849 15.1517 9.55215 15.1517L11.5522 15.1517L13.5521 15.1517C14.4358 15.1517 15.1521 14.4353 15.1521 13.5517L15.1521 11.5518L15.1521 9.55166C15.1521 8.668 14.4358 7.95166 13.5521 7.95166H9.55215ZM13.9521 10.9518V9.55166C13.9521 9.33075 13.7731 9.15166 13.5521 9.15166H12.1522V10.9518H13.9521ZM10.9522 10.9518V9.15166H9.55215C9.33123 9.15166 9.15215 9.33075 9.15215 9.55166V10.9518H10.9522ZM9.15215 12.1518H10.9522V13.9517H9.55215C9.33123 13.9517 9.15215 13.7726 9.15215 13.5517V12.1518ZM12.1522 12.1518H13.9521V13.5517C13.9521 13.7726 13.7731 13.9517 13.5521 13.9517H12.1522V12.1518Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{d:"M9.62158 2.44912C9.62158 2.11775 9.89021 1.84912 10.2216 1.84912H12.7516C13.6352 1.84912 14.3516 2.56547 14.3516 3.44912V5.9791C14.3516 6.31047 14.0829 6.5791 13.7516 6.5791C13.4202 6.5791 13.1516 6.31047 13.1516 5.9791V3.44912C13.1516 3.22821 12.9725 3.04912 12.7516 3.04912H10.2216C9.89021 3.04912 9.62158 2.78049 9.62158 2.44912Z"}},{tag:"path",attrs:{d:"M5.77871 14.1507C6.11008 14.1507 6.37871 13.8821 6.37871 13.5507C6.37871 13.2193 6.11008 12.9507 5.77871 12.9507L3.24873 12.9507C3.02782 12.9507 2.84873 12.7716 2.84873 12.5507L2.84873 10.0207C2.84873 9.68933 2.5801 9.4207 2.24873 9.4207C1.91736 9.4207 1.64873 9.68933 1.64873 10.0207L1.64873 12.5507C1.64873 13.4343 2.36507 14.1507 3.24873 14.1507H5.77871Z"}}]},{tag:"defs",attrs:{},children:[{tag:"clipPath",attrs:{id:"convert-icon_clip0_911_593"},children:[{tag:"path",attrs:{fill:"white",d:"M0 0H16V16H0z"}}]}]}],defIds:["convert-icon_clip0_911_593"]},Qs=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"convert-icon",ref:r,icon:mu}))});Qs.displayName="ConvertIcon";var gu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.3313 1.4667C5.3313 1.13533 5.59993 0.866699 5.9313 0.866699H10.069C10.4004 0.866699 10.669 1.13533 10.669 1.4667C10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443C14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928L9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171C10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778L9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539C9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263L6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539C5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778L6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},zi=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"delete-icon",ref:r,icon:gu}))});zi.displayName="DeleteIcon";var Su={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.85869 12.9216C8.38445 13.4708 7.61555 13.4708 7.14131 12.9216L0.358114 5.06726C-0.406895 4.18144 0.134916 2.66683 1.2168 2.66683L14.7832 2.66683C15.8651 2.66683 16.4069 4.18144 15.6419 5.06726L8.85869 12.9216Z"}}]},Js=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"dropdown-icon",ref:r,icon:Su}))});Js.displayName="DropdownIcon";var fu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M15 8C15 11.866 11.866 15 8 15C4.13401 15 1 11.866 1 8C1 4.13401 4.13401 1 8 1C11.866 1 15 4.13401 15 8ZM10.3097 5.69014C10.544 5.92445 10.544 6.30435 10.3097 6.53867L8.84843 7.9999L10.3099 9.46137C10.5442 9.69569 10.5442 10.0756 10.3099 10.3099C10.0756 10.5442 9.69569 10.5442 9.46137 10.3099L7.9999 8.84843L6.53842 10.3099C6.30411 10.5442 5.92421 10.5442 5.6899 10.3099C5.45558 10.0756 5.45558 9.69569 5.6899 9.46137L7.15137 7.9999L5.69014 6.53867C5.45583 6.30435 5.45583 5.92445 5.69014 5.69014C5.92445 5.45583 6.30435 5.45583 6.53867 5.69014L7.9999 7.15137L9.46113 5.69014C9.69544 5.45583 10.0753 5.45583 10.3097 5.69014Z",fillRule:"evenodd",clipRule:"evenodd"}}]},to=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"error-icon",ref:r,icon:fu}))});to.displayName="ErrorIcon";var vu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.28096 4.6541C1.57489 4.50109 1.93721 4.61533 2.09022 4.90926C2.27315 5.26067 2.55999 5.60455 2.94829 5.92278C4.04628 6.82266 5.87505 7.44865 7.99828 7.44865C10.1215 7.44865 11.9503 6.82267 13.0482 5.92279C13.4366 5.60455 13.7234 5.26067 13.9063 4.90927C14.0594 4.61533 14.4217 4.50109 14.7156 4.65409C15.0095 4.8071 15.1238 5.16941 14.9708 5.46334C14.6995 5.98445 14.2981 6.44997 13.8089 6.8509C13.7298 6.91575 13.6481 6.97914 13.564 7.041L15.2245 8.70153C15.4588 8.93585 15.4588 9.31575 15.2245 9.55006C14.9902 9.78438 14.6103 9.78438 14.376 9.55006L12.5041 7.67822C11.8977 7.97568 11.2181 8.21208 10.4884 8.37706L11.0996 10.6581C11.1853 10.9782 10.9954 11.3072 10.6753 11.393C10.3552 11.4787 10.0262 11.2888 9.94045 10.9687L9.29949 8.57652C8.8758 8.62404 8.44081 8.64865 7.99828 8.64865C7.55276 8.64865 7.11487 8.62371 6.68846 8.57555L6.04723 10.9687C5.96147 11.2888 5.63247 11.4788 5.31239 11.393C4.99231 11.3073 4.80236 10.9783 4.88812 10.6582L5.49983 8.37516C4.7743 8.2105 4.09843 7.9752 3.49498 7.67947L1.62436 9.55009C1.39005 9.78441 1.01015 9.78441 0.775835 9.5501C0.54152 9.31578 0.541518 8.93588 0.775832 8.70157L2.43478 7.04261C2.34987 6.98024 2.26746 6.91632 2.18764 6.8509C1.69842 6.44997 1.29706 5.98445 1.0258 5.46335C0.872791 5.16942 0.987031 4.80711 1.28096 4.6541Z"}}]},$s=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"eyelash-icon",ref:r,icon:vu}))});$s.displayName="EyelashIcon";var pu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M6.06409 5.53454C5.93592 5.53454 5.84083 5.41567 5.86897 5.29063L5.95442 4.9109C6.05444 4.48178 6.23806 4.11547 6.51182 3.81952C6.81082 3.49628 7.25398 3.35405 7.79738 3.35405C7.99847 3.35405 8.21359 3.37775 8.44188 3.42245C8.46089 3.42617 8.47974 3.43006 8.49846 3.4341C8.7099 3.4798 8.93698 3.38478 9.02031 3.18514L9.24767 2.6404C9.33457 2.43219 9.23178 2.19404 9.01582 2.12874C8.98358 2.11899 8.95028 2.10912 8.91591 2.09914C8.62745 2.01631 8.28392 1.97217 7.88074 1.97217C6.82015 1.97217 6.02714 2.23936 5.4746 2.7444C4.90987 3.26069 4.50889 3.99917 4.28413 4.9762L2.83703 11.1909C2.76126 11.5286 2.666 11.8917 2.54844 12.2812C2.42975 12.6734 2.2873 13.0595 2.12221 13.4373C1.95577 13.8159 1.76813 14.1762 1.55955 14.5171C1.49345 14.6251 1.42515 14.7282 1.35467 14.8263C1.26508 14.9509 1.3347 15.133 1.48655 15.1554C2.13635 15.2509 2.8179 15.0763 3.18197 14.5296C3.32661 14.3124 3.46779 14.0646 3.60509 13.7851C3.96635 13.0497 4.30522 12.0103 4.61867 10.6574L5.469 7.01534C5.49013 6.92483 5.57082 6.86081 5.66376 6.86081H7.62478C7.8097 6.86081 7.97051 6.73405 8.01371 6.55425L8.14014 6.02798C8.20057 5.77642 8.00992 5.53454 7.75121 5.53454H6.06409Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M14.3211 5.72037L12.5124 7.96963L11.4089 5.77754C11.3422 5.63012 11.1954 5.5354 11.0336 5.5354H10.3129C10.0085 5.5354 9.80921 5.85428 9.9427 6.1279L11.4089 9.05502L8.79783 12.1493C8.56587 12.4158 8.75519 12.8315 9.10855 12.8315H9.68607C9.80672 12.8315 9.9605 12.7822 10.0388 12.6904L12.1108 10.2648L13.1176 12.561C13.1786 12.7231 13.333 12.8315 13.5061 12.8315H14.3C14.5831 12.8315 14.7417 12.6175 14.6426 12.3524L13.1728 9.28628C13.1728 9.28628 15.4009 6.45542 15.6013 6.17892C15.7966 5.90929 15.6023 5.5354 15.2693 5.5354H14.6661C14.5275 5.5354 14.4333 5.58887 14.3211 5.72037Z"}}]},ea=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"fx-icon",ref:r,icon:pu}))});ea.displayName="FxIcon";var Cu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M6.4833 1.65005C6.4833 1.31868 6.21467 1.05005 5.8833 1.05005C5.55193 1.05005 5.2833 1.31868 5.2833 1.65005V5.28345H1.65029C1.31892 5.28345 1.05029 5.55208 1.05029 5.88345C1.05029 6.21482 1.31892 6.48345 1.65029 6.48345H5.2833V9.51684H1.65029C1.31892 9.51684 1.05029 9.78547 1.05029 10.1168C1.05029 10.4482 1.31892 10.7168 1.65029 10.7168H5.2833V14.35C5.2833 14.6814 5.55193 14.95 5.8833 14.95C6.21467 14.95 6.4833 14.6814 6.4833 14.35V10.7168H9.5167V14.35C9.5167 14.6814 9.78533 14.95 10.1167 14.95C10.4481 14.95 10.7167 14.6814 10.7167 14.35V10.7168H14.3503C14.6817 10.7168 14.9503 10.4482 14.9503 10.1168C14.9503 9.78547 14.6817 9.51685 14.3503 9.51685H10.7167V6.48345H14.3503C14.6817 6.48345 14.9503 6.21482 14.9503 5.88345C14.9503 5.55208 14.6817 5.28345 14.3503 5.28345H10.7167V1.65005C10.7167 1.31868 10.4481 1.05005 10.1167 1.05005C9.78533 1.05005 9.5167 1.31868 9.5167 1.65005V5.28345L6.4833 5.28345V1.65005ZM6.4833 6.48345V9.51684L9.5167 9.51685V6.48345L6.4833 6.48345Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.0498 3.65005C1.0498 2.21411 2.21386 1.05005 3.6498 1.05005H12.3498C13.7857 1.05005 14.9498 2.21411 14.9498 3.65005V12.3501C14.9498 13.786 13.7857 14.95 12.3498 14.95H3.6498C2.21386 14.95 1.0498 13.786 1.0498 12.35V3.65005ZM3.6498 2.25005C2.87661 2.25005 2.2498 2.87685 2.2498 3.65005V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V3.65005C13.7498 2.87685 13.123 2.25005 12.3498 2.25005H3.6498Z",fillRule:"evenodd",clipRule:"evenodd"}}]},ta=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"hide-gridlines-double-icon",ref:r,icon:Cu}))});ta.displayName="HideGridlinesDoubleIcon";var _u={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},no=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"increase-icon",ref:r,icon:_u}))});no.displayName="IncreaseIcon";var Iu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.00016 1.33203C6.68162 1.33203 5.39269 1.72302 4.29636 2.45557C3.20004 3.18811 2.34555 4.2293 1.84097 5.44747C1.33638 6.66565 1.20436 8.00609 1.4616 9.2993C1.71883 10.5925 2.35377 11.7804 3.28612 12.7127C4.21847 13.6451 5.40636 14.28 6.69956 14.5373C7.99277 14.7945 9.33321 14.6625 10.5514 14.1579C11.7696 13.6533 12.8108 12.7988 13.5433 11.7025C14.2758 10.6062 14.6668 9.31724 14.6668 7.9987C14.6649 6.23118 13.9619 4.53662 12.7121 3.2868C11.4622 2.03697 9.76768 1.33397 8.00016 1.33203ZM7.66683 3.9987C7.86461 3.9987 8.05795 4.05735 8.2224 4.16723C8.38685 4.27711 8.51502 4.43329 8.59071 4.61601C8.6664 4.79874 8.6862 4.99981 8.64762 5.19379C8.60903 5.38777 8.51379 5.56595 8.37394 5.7058C8.23409 5.84566 8.0559 5.9409 7.86192 5.97948C7.66794 6.01807 7.46687 5.99826 7.28415 5.92258C7.10142 5.84689 6.94524 5.71872 6.83536 5.55427C6.72548 5.38982 6.66683 5.19648 6.66683 4.9987C6.66683 4.73348 6.77219 4.47913 6.95972 4.29159C7.14726 4.10405 7.40162 3.9987 7.66683 3.9987ZM9.3335 11.332H6.66683C6.49002 11.332 6.32045 11.2618 6.19543 11.1368C6.0704 11.0117 6.00016 10.8422 6.00016 10.6654C6.00016 10.4886 6.0704 10.319 6.19543 10.194C6.32045 10.0689 6.49002 9.9987 6.66683 9.9987H7.3335V7.9987H6.66683C6.49002 7.9987 6.32045 7.92846 6.19543 7.80343C6.0704 7.67841 6.00016 7.50884 6.00016 7.33203C6.00016 7.15522 6.0704 6.98565 6.19543 6.86063C6.32045 6.7356 6.49002 6.66536 6.66683 6.66536H8.00016C8.17698 6.66536 8.34655 6.7356 8.47157 6.86063C8.59659 6.98565 8.66683 7.15522 8.66683 7.33203V9.9987H9.3335C9.51031 9.9987 9.67988 10.0689 9.8049 10.194C9.92993 10.319 10.0002 10.4886 10.0002 10.6654C10.0002 10.8422 9.92993 11.0117 9.8049 11.1368C9.67988 11.2618 9.51031 11.332 9.3335 11.332Z"}}]},na=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"info-icon",ref:r,icon:Iu}))});na.displayName="InfoIcon";var bu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.62402 7.72905C2.58427 7.72905 2.55205 7.76127 2.55205 7.80102V13.6782C2.55205 13.7179 2.58427 13.7502 2.62402 13.7502H13.3755C13.4152 13.7502 13.4474 13.7179 13.4474 13.6782V7.80102C13.4474 7.76127 13.4152 7.72905 13.3755 7.72905H2.62402ZM1.35205 7.80102C1.35205 7.09853 1.92153 6.52905 2.62402 6.52905H13.3755C14.0779 6.52905 14.6474 7.09853 14.6474 7.80102V13.6782C14.6474 14.3807 14.0779 14.9502 13.3755 14.9502H2.62402C1.92153 14.9502 1.35205 14.3807 1.35205 13.6782V7.80102Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M8 2.25005C6.69847 2.25003 5.64336 3.30513 5.64336 4.60666V7.12895C5.64336 7.46032 5.37473 7.72895 5.04336 7.72895C4.71199 7.72895 4.44336 7.46032 4.44336 7.12895V4.60666C4.44336 2.64239 6.04451 1.05565 8.00879 1.05566M8 2.25005L8.00879 1.05566L8 2.25005ZM8.00879 1.05566L8 2.25005C9.30154 2.25003 10.3567 3.30513 10.3567 4.60666V7.12895C10.3567 7.46032 10.6253 7.72895 10.9567 7.72895C11.288 7.72895 11.5567 7.46032 11.5567 7.12895V4.60666C11.5567 2.64239 9.97306 1.05565 8.00879 1.05566Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M8.00039 9.4668C8.33176 9.4668 8.60039 9.73543 8.60039 10.0668V12.0827C8.60039 12.4141 8.33176 12.6827 8.00039 12.6827C7.66902 12.6827 7.40039 12.4141 7.40039 12.0827V10.0668C7.40039 9.73543 7.66902 9.4668 8.00039 9.4668Z",fillRule:"evenodd",clipRule:"evenodd"}}]},io=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"lock-icon",ref:r,icon:bu}))});io.displayName="LockIcon";var wu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M11.3536 6.14645C11.5488 6.34171 11.5488 6.65829 11.3536 6.85355L8.35355 9.85355C8.15829 10.0488 7.84171 10.0488 7.64645 9.85355L4.64645 6.85355C4.45118 6.65829 4.45118 6.34171 4.64645 6.14645C4.84171 5.95118 5.15829 5.95118 5.35355 6.14645L8 8.79289L10.6464 6.14645C10.8417 5.95118 11.1583 5.95118 11.3536 6.14645Z",fillRule:"evenodd",clipRule:"evenodd"}}]},sn=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"more-down-icon",ref:r,icon:wu}))});sn.displayName="MoreDownIcon";var Eu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.90913 3.57564C6.14345 3.34132 6.52335 3.34132 6.75766 3.57564L10.7577 7.57564C10.992 7.80995 10.992 8.18985 10.7577 8.42417L6.75766 12.4242C6.52335 12.6585 6.14345 12.6585 5.90913 12.4242C5.67482 12.1899 5.67482 11.81 5.90913 11.5756L9.48487 7.9999L5.90913 4.42417C5.67482 4.18985 5.67482 3.80995 5.90913 3.57564Z",fillRule:"evenodd",clipRule:"evenodd"}}]},ro=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"more-icon",ref:r,icon:Eu}))});ro.displayName="MoreIcon";var Tu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.01281 1.36643C8.79386 0.585377 10.0602 0.585378 10.8412 1.36643L12.9223 3.44752C13.7034 4.22857 13.7034 5.4949 12.9223 6.27595L9.36445 9.83383C8.5834 10.6149 7.31707 10.6149 6.53602 9.83383L4.45493 7.75273C3.67388 6.97168 3.67388 5.70535 4.45493 4.9243L8.01281 1.36643ZM9.9927 2.21495C9.68028 1.90253 9.17375 1.90253 8.86133 2.21495L5.30346 5.77283L5.29671 5.77966L10.839 6.66224L12.0738 5.42742C12.3862 5.115 12.3862 4.60847 12.0738 4.29605L9.9927 2.21495Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M14.5179 9.48875C14.5179 9.99175 14.1101 10.3995 13.607 10.3995C13.1041 10.3995 12.6963 9.99175 12.6963 9.48875C12.6963 9.1773 13.0455 8.59966 13.3114 8.20487C13.4549 7.99177 13.7591 7.99177 13.9027 8.20486C14.1687 8.59965 14.5179 9.1773 14.5179 9.48875Z"}},{tag:"path",attrs:{fill:"colorChannel1",d:"M1.98682 13.4992C1.98682 12.5603 2.74793 11.7992 3.68682 11.7992H14.2868C15.2257 11.7992 15.9868 12.5603 15.9868 13.4992V13.4992C15.9868 14.4381 15.2257 15.1992 14.2868 15.1992H3.68682C2.74793 15.1992 1.98682 14.4381 1.98682 13.4992V13.4992Z"}}]},ia=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"paint-bucket-double-icon",ref:r,icon:Tu}))});ia.displayName="PaintBucketDoubleIcon";var yu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_1138",width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#DCDCDC",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{mask:"url(#mask0_102_1138)"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M7.74692 9.12463C7.74692 9.46018 8.01893 9.73219 8.35448 9.73219H11.4933C11.8288 9.73219 12.1009 9.46018 12.1009 9.12463C12.1009 8.78909 11.8288 8.51707 11.4933 8.51707H8.35448C8.01893 8.51707 7.74692 8.78909 7.74692 9.12463Z"}},{tag:"path",attrs:{fill:"colorChannel1",d:"M10.8636 10.8523C10.8636 11.1879 10.5915 11.4599 10.256 11.4599H8.35448C8.01893 11.4599 7.74692 11.1879 7.74692 10.8523C7.74692 10.5168 8.01893 10.2447 8.35448 10.2447H10.256C10.5915 10.2447 10.8636 10.5168 10.8636 10.8523Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M5.4791 1.98268C5.47913 1.71529 5.87912 1.49854 6.37252 1.49854C6.86593 1.49854 7.26592 1.71529 7.26595 1.98268H7.62187C8.22277 1.98268 8.72459 2.39534 8.84412 2.9452H9.39563C10.0856 2.9452 10.6449 3.48923 10.6449 4.16032V6.00569H12.1261C13.161 6.00569 14 6.82174 14 7.82838V11.334C14 11.8174 13.8025 12.281 13.4511 12.6228L12.0693 13.9647C11.7179 14.3065 11.2412 14.4985 10.7442 14.4985H7.91116C7.05024 14.4985 6.32492 14.0431 6.10535 13.2737H3.34925C2.6593 13.2737 2.09998 12.7297 2.09998 12.0586V4.16032C2.09998 3.48923 2.6593 2.9452 3.34925 2.9452H3.90107C4.0206 2.39534 4.52241 1.98268 5.12332 1.98268H5.4791ZM3.97249 4.16032H3.24925L3.24925 12.0586H6.03725V7.82838C6.03725 6.82174 6.87623 6.00569 7.91116 6.00569H9.49563V4.16032H8.7727C8.58289 4.59611 8.13909 4.90183 7.62187 4.90183H5.12332C4.6061 4.90183 4.1623 4.59611 3.97249 4.16032ZM5.12332 2.89403H7.62187C7.79436 2.89403 7.93419 3.03003 7.93419 3.19781V3.68671C7.93419 3.85448 7.79436 3.99049 7.62187 3.99049H5.12332C4.95083 3.99049 4.811 3.85448 4.811 3.68671V3.19781C4.811 3.03003 4.95083 2.89403 5.12332 2.89403ZM7.91116 7.11157C7.56618 7.11157 7.28652 7.38359 7.28652 7.71913V12.7851C7.28652 13.1206 7.56618 13.3927 7.91116 13.3927H10.7442C10.8401 13.3927 10.9337 13.3712 11.0182 13.3311C11.1373 13.2746 11.1859 13.1423 11.1859 13.0134V12.0066C11.1859 11.8724 11.2978 11.7636 11.4358 11.7636H12.4709C12.6034 11.7636 12.7394 11.7163 12.7975 11.6004C12.8388 11.5182 12.8608 11.4272 12.8608 11.334V7.71913C12.8608 7.38359 12.5811 7.11157 12.2362 7.11157H7.91116Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},ra=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"paste-special-double-icon",ref:r,icon:yu}))});ra.displayName="PasteSpecialDoubleIcon";var Ru={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.666 2.70571C11.7769 1.76476 10.3295 1.76476 9.4404 2.70571L3.37843 9.12427C3.31779 9.18848 3.27756 9.26409 3.24979 9.3439C3.24809 9.3493 3.24299 9.3529 3.24129 9.3583L2.02912 13.2097C1.96112 13.4251 2.01439 13.6633 2.16626 13.8236C2.27393 13.9382 2.41901 14 2.56692 14C2.62699 14 2.68762 13.9898 2.74599 13.9688L6.3825 12.6846C6.3876 12.6828 6.391 12.678 6.39553 12.6762C6.47147 12.6474 6.54287 12.6042 6.60351 12.54L12.666 6.12202C13.5558 5.18048 13.5558 3.64725 12.666 2.70571ZM8.62832 5.26209L9.04031 5.69836C9.03918 5.69956 9.03748 5.70016 9.03634 5.70136L4.99182 9.9836L4.58096 9.54853L8.62832 5.26209ZM3.46287 12.4512L4.02673 10.6593L5.15446 11.8535L3.46287 12.4512ZM6.20342 11.2672L5.79256 10.8321L9.83709 6.54988C9.83822 6.54868 9.83879 6.54688 9.83992 6.54568L10.2513 6.98135L6.20342 11.2672ZM11.8647 5.27349L11.0532 6.13282L9.42963 4.41356L10.2411 3.55423C10.6888 3.08016 11.417 3.08076 11.8642 3.55423C12.3124 4.0283 12.3124 4.79942 11.8647 5.27349Z"}}]},oa=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"pen-icon",ref:r,icon:Ru}))});oa.displayName="PenIcon";var Mu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.785 6.77762C5.78908 6.7777 5.79316 6.77774 5.79725 6.77774C5.80134 6.77774 5.80543 6.7777 5.8095 6.77762H10.0184C10.0225 6.7777 10.0266 6.77774 10.0307 6.77774C10.0347 6.77774 10.0388 6.7777 10.0429 6.77762H13.6638V7.63727C13.6638 7.96864 13.9324 8.23727 14.2638 8.23727C14.5951 8.23727 14.8638 7.96864 14.8638 7.63727V3.9999C14.8638 2.56395 13.6997 1.39989 12.2637 1.3999L3.56389 1.39999C2.12797 1.40001 0.96393 2.56405 0.96392 3.99998L0.963867 11.6666C0.963857 13.1025 2.12792 14.2666 3.56387 14.2666H8.0542C8.38557 14.2666 8.6542 13.9979 8.6542 13.6666C8.6542 13.3352 8.38557 13.0666 8.0542 13.0666H3.56387C2.79067 13.0666 2.16386 12.4398 2.16387 11.6666L2.1639 6.77762H5.785ZM6.39725 2.59996L9.43065 2.59993V5.57762H6.39725V2.59996ZM5.19725 5.57762V2.59998L3.56391 2.59999C2.79072 2.6 2.16393 3.22679 2.16392 3.99998L2.16391 5.57762H5.19725ZM13.6638 5.57762V3.9999C13.6638 3.2267 13.037 2.59989 12.2638 2.5999L10.6307 2.59992V5.57762H13.6638Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M14.1223 10.2333V10.7496C14.7087 10.9869 15.1223 11.5618 15.1223 12.2333V12.8999C15.1223 13.7836 14.406 14.4999 13.5223 14.4999H11.5223C10.6387 14.4999 9.92235 13.7836 9.92235 12.8999V12.2333C9.92235 11.5618 10.336 10.9869 10.9223 10.7496V10.2333C10.9223 9.34961 11.6387 8.63328 12.5223 8.63328C13.406 8.63328 14.1223 9.34961 14.1223 10.2333ZM11.1223 12.2333C11.1223 12.0124 11.3014 11.8333 11.5223 11.8333H13.5223C13.7433 11.8333 13.9223 12.0124 13.9223 12.2333V12.8999C13.9223 13.1209 13.7433 13.2999 13.5223 13.2999H11.5223C11.3014 13.2999 11.1223 13.1209 11.1223 12.8999V12.2333ZM12.9223 10.2333V10.6333H12.1223V10.2333C12.1223 10.0124 12.3014 9.83328 12.5223 9.83328C12.7433 9.83328 12.9223 10.0124 12.9223 10.2333Z",fillRule:"evenodd",clipRule:"evenodd"}}]},sa=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"protect-icon",ref:r,icon:Mu}))});sa.displayName="ProtectIcon";var Pu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M15 8C15 11.866 11.866 15 8 15C4.13401 15 1 11.866 1 8C1 4.13401 4.13401 1 8 1C11.866 1 15 4.13401 15 8ZM8.00008 12.3671C8.46031 12.3671 8.83342 11.994 8.83342 11.5338C8.83342 11.0735 8.46031 10.7004 8.00008 10.7004C7.53985 10.7004 7.16675 11.0735 7.16675 11.5338C7.16675 11.994 7.53985 12.3671 8.00008 12.3671ZM8.5999 4.4335C8.5999 4.10213 8.33127 3.8335 7.9999 3.8335C7.66853 3.8335 7.3999 4.10213 7.3999 4.4335V9.36683C7.3999 9.6982 7.66853 9.96683 7.9999 9.96683C8.33127 9.96683 8.5999 9.6982 8.5999 9.36683V4.4335Z",fillRule:"evenodd",clipRule:"evenodd"}}]},aa=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"warning-icon",ref:r,icon:Pu}))});aa.displayName="WarningIcon";var Ou={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.6551 1.98906C11.7476 1.08113 10.2757 1.08149 9.3686 1.98987L4.82542 6.53955C4.75087 6.61421 4.69336 6.70411 4.65682 6.80309L3.2461 10.625C3.16506 10.8446 3.21909 11.0912 3.3845 11.2568C3.54991 11.4224 3.79651 11.4767 4.01616 11.3959L7.85031 9.98517C7.94979 9.94856 8.04014 9.89077 8.11508 9.81579L12.6552 5.27327C13.5618 4.36621 13.5618 2.89607 12.6551 1.98906ZM10.2177 2.83779C10.6562 2.39869 11.3677 2.39851 11.8064 2.8374C12.2447 3.27584 12.2447 3.9865 11.8065 4.42497L7.3392 8.89457L4.82213 9.82068L5.74706 7.31487L10.2177 2.83779Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.79238 13.2999C1.46101 13.2999 1.19238 13.5685 1.19238 13.8999C1.19238 14.2313 1.46101 14.4999 1.79238 14.4999H14.4924C14.8238 14.4999 15.0924 14.2313 15.0924 13.8999C15.0924 13.5685 14.8238 13.2999 14.4924 13.2999H1.79238Z"}}]},oo=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"write-icon",ref:r,icon:Ou}))});oo.displayName="WriteIcon";const Au=()=>{const[,n]=W.useState({});return W.useCallback(()=>n(r=>!r),[])};function Du(){const n=_.useDependency(a.ICommandService),r=_.useDependency(a.IUniverInstanceService),e=_.useDependency(R.IRenderManagerService),t=_.useDependency(ut),i=_.useDependency(a.LocaleService),[o,s]=W.useState([]),[l,c]=W.useState(!1),[d,u]=W.useState({row:-1,col:-1}),[h,g]=W.useState(ce.SERIES),[S,f]=W.useState(!1),v=lt(),{sheetSkeletonManagerService:p,selectionRenderService:C}=W.useMemo(()=>{if(v){const j=e.getRenderById(v.getUnitId());return{sheetSkeletonManagerService:j==null?void 0:j.with(y.SheetSkeletonManagerService),selectionRenderService:j==null?void 0:j.with(ve)}}return{sheetSkeletonManagerService:null,selectionRenderService:null}},[v,e]),b=()=>{f(!0)},E=()=>{f(!1)},w=Au();if(W.useEffect(()=>n.onCommandExecuted((Q,ie)=>{Q.id===Le.id&&w()}).dispose,[w,n]),W.useEffect(()=>{const j=p&&a.toDisposable(p.currentSkeleton$.subscribe(Q=>{Q&&w()}));return j==null?void 0:j.dispose},[p,w]),W.useEffect(()=>a.toDisposable(t.menu$.subscribe(Q=>{s(Q.map(ie=>({...ie,index:Q.indexOf(ie)})))})).dispose,[t]),W.useEffect(()=>a.toDisposable(t.showMenu$.subscribe(Q=>{const{source:ie,target:$}=t.autoFillLocation||{source:null,target:null};if(Q&&ie&&$){const se=Math.max(ie.rows[ie.rows.length-1],$.rows[$.rows.length-1]),Z=Math.max(ie.cols[ie.cols.length-1],$.cols[$.cols.length-1]);u({row:se,col:Z})}else u({row:-1,col:-1})})).dispose,[t]),W.useEffect(()=>a.toDisposable(t.applyType$.subscribe(Q=>{g(Q)})).dispose,[t]),W.useEffect(()=>{function j(){c(!1)}return document.addEventListener("wheel",j),()=>{document.removeEventListener("wheel",j)}},[l]),d.col<0||d.row<0)return null;const O=Ne(r,e);if(!O||!C)return null;const{scene:M}=O,P=p==null?void 0:p.getCurrentSkeleton(),A=C.getViewPort(),k=M==null?void 0:M.scaleX,N=M==null?void 0:M.scaleY,H=M==null?void 0:M.getViewportScrollXY(A);if(!k||!M||!k||!N||!H)return null;const x=(P==null?void 0:P.getNoMergeCellWithCoordByIndex(d.row,d.col).endX)||0,L=(P==null?void 0:P.getNoMergeCellWithCoordByIndex(d.row,d.col).endY)||0,V=R.convertTransformToOffsetX(x,k,H),U=R.convertTransformToOffsetY(L,N,H);if(V==null||U==null)return null;const B=j=>{c(j)},Y=j=>{n.executeCommand(Wn.id,{type:j.value}),c(!1)},F=l||S,z=o.filter(j=>!j.disable);return I.jsx("div",{className:"univer-absolute univer-inset-0 univer-z-10 univer-size-0",children:I.jsx("div",{className:"univer-absolute",style:{left:`${V+2}px`,top:`${U+2}px`},onMouseEnter:b,onMouseLeave:E,children:I.jsx(X.DropdownMenu,{align:"start",items:z.map(j=>({type:"radio",value:h,options:[{label:i.t(j.label),value:j.value}],onSelect:()=>Y(j)})),open:l,onOpenChange:B,children:I.jsxs("div",{className:X.clsx("univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-800",X.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-800":l,"univer-bg-white dark:!univer-bg-gray-900":!l}),children:[I.jsx(Ks,{className:"univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-white"}),F&&I.jsx(sn,{className:"dark:!univer-text-white"})]})})})})}function so(n,r){const e=_.useDependency(me),t=_.useDependency(a.ICommandService);return W.useMemo(()=>({keyCodes:[{keyCode:_.KeyCode.ENTER},{keyCode:_.KeyCode.ESC},{keyCode:_.KeyCode.TAB}],handler:o=>{(o===_.KeyCode.ENTER||o===_.KeyCode.ESC||o===_.KeyCode.TAB)&&(e.disableForceKeepVisible(),t.executeCommand(ge.id,{visible:!1,eventType:R.DeviceInputEventType.Keyboard,keycode:o,unitId:r}))}}),[t,e,r])}const Xi=-1e3,la={width:0,height:0,top:Xi,left:Xi},ku=()=>{const[n,r]=W.useState({...la}),e=_.useDependency(Xn),t=_.useDependency(q.IEditorService),i=_.useDependency(a.IContextService),o=_.useDependency(_.ComponentManager),s=_.useDependency(me),l=_.useObservable(s.visible$),c=_.useDependency(a.ICommandService),d=W.useRef(0),u=_.useObservable(()=>i.subscribeContextValue$(_.DISABLE_AUTO_FOCUS_KEY),!1,void 0,[i,_.DISABLE_AUTO_FOCUS_KEY]),h=o.get(Di),g=s.getEditLocation();W.useEffect(()=>{const p=e.state$.subscribe(C=>{if(C==null)return;const{startX:b=Xi,startY:E=Xi,endX:w=0,endY:O=0,show:M=!1}=C;if(!M)r({...la});else{r({width:w-b,height:O-E,left:b,top:E});const P=t.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(P==null)return;const{left:A,top:k,width:N,height:H}=P.getBoundingClientRect();e.setRect({left:A,top:k,width:N,height:H})}});return()=>{p.unsubscribe()}},[]),W.useEffect(()=>{u||e.setFocus(!0)},[u,n]);const S=_.useEvent(()=>{s.isVisible().visible&&c.executeCommand(ge.id,{visible:!1,eventType:R.DeviceInputEventType.PointerUp,unitId:g==null?void 0:g.unitId})});_.useSidebarClick(S);const f=so(d,g==null?void 0:g.unitId),v=_.useEvent((p,C)=>{c.executeCommand(wt.id,{keycode:p,visible:!1,eventType:R.DeviceInputEventType.Keyboard,isShift:C===_.MetaKeys.SHIFT||C===(_.MetaKeys.CTRL_COMMAND|_.MetaKeys.SHIFT),unitId:g==null?void 0:g.unitId})});return I.jsx("div",{className:"univer-absolute univer-z-10 univer-flex",style:{left:n.left,top:n.top,width:n.width,height:n.height},children:h&&I.jsx(h,{editorId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,className:"univer-relative univer-flex univer-h-full univer-w-full [&_canvas]:univer-absolute",initValue:"",onChange:()=>{},isFocus:l==null?void 0:l.visible,unitId:g==null?void 0:g.unitId,subUnitId:g==null?void 0:g.sheetId,keyboardEventConfig:f,onMoveInEditor:v,isSupportAcrossSheet:!0,resetSelectionOnBlur:!1,isSingle:!1,autoScrollbar:!1,onFormulaSelectingChange:(p,C)=>{d.current=p,C&&(p?s.enableForceKeepVisible():s.disableForceKeepVisible())},disableSelectionOnClick:!0,disableContextMenu:!1})})};class Nu{constructor(){T(this,"_position",null);T(this,"_position$",new D.BehaviorSubject(null));T(this,"position$",this._position$.asObservable());T(this,"_focus",!1);T(this,"_focus$",new D.BehaviorSubject(this._focus));T(this,"focus$",this._focus$.asObservable());T(this,"_fxBtnClick$",new D.Subject);T(this,"fxBtnClick$",this._fxBtnClick$.asObservable());T(this,"_foldBtnStatus$",new D.Subject);T(this,"foldBtnStatus$",this._foldBtnStatus$.asObservable())}dispose(){this._position$.complete(),this._focus$.complete(),this._position=null,this._focus=!1}setPosition(r){this._position=r,this._refresh(r)}getPosition(){return this._position}setFocus(r=!1){this._focus=r,this._focus$.next(r)}handleFxBtnClick(r){this._fxBtnClick$.next(r)}handleFoldBtnClick(r){this._foldBtnStatus$.next(r)}_refresh(r){this._position$.next(r)}}const Yn=a.createIdentifier("univer.sheet-formula-editor-manager.service"),jn="DefinedNameContainer",Yi={id:"sidebar.operation.defined-name",type:a.CommandType.COMMAND,handler:async(n,r)=>{const e=n.get(_.ISidebarService);n.get(q.IEditorService);const t=n.get(a.LocaleService),i=n.get(a.IUniverInstanceService),o=m.getSheetCommandTarget(i);if(!o)return!1;const{unitId:s}=o;switch(r.value){case"open":e.open({id:jn,header:{title:t.t("definedName.featureTitle")},children:{label:jn},onClose:()=>{},width:333});break;case"close":default:e.close();break}return!0}};function Hu(){const n=_.useDependency(a.ICommandService),r=_.useDependency(a.LocaleService),e=_.useDependency(K.IDefinedNamesService),t=_.useDependency(a.IUniverInstanceService),i=_.useDependency(_.ISidebarService),s=t.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId(),l=()=>{const g=e.getDefinedNameMap(s);return g?Array.from(Object.values(g)):[]},[c,d]=W.useState(l());W.useEffect(()=>{const g=e.update$.subscribe(()=>{d(l())});return()=>{g.unsubscribe()}},[]),W.useEffect(()=>{const g=i.sidebarOptions$.subscribe(S=>{S.id===jn&&(S.visible||setTimeout(()=>{i.sidebarOptions$.next({visible:!1})}))});return()=>{g.unsubscribe()}},[]);const u=()=>{n.executeCommand(Yi.id,{value:"open"})},h=async g=>{const{formulaOrRefString:S,id:f}=g,v=e.getWorksheetByRef(s,S);if(!v)return;v.isSheetHidden()&&await n.executeCommand(m.SetWorksheetShowCommand.id,{unitId:s,subUnitId:v.getSheetId()}),e.focusRange(s,f)};return I.jsxs("div",{className:"univer-w-[300px]",children:[I.jsx("ul",{className:X.clsx("univer-m-0 univer-max-h-[360px] univer-list-none univer-overflow-y-auto univer-p-0",X.scrollbarClassName),children:c.map((g,S)=>I.jsx("li",{className:"univer-cursor-pointer univer-px-2 univer-transition-colors univer-duration-200 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-600",onClick:()=>{h(g)},children:I.jsxs("div",{className:X.clsx("univer-flex univer-items-center univer-justify-between univer-gap-2 univer-py-1",X.borderBottomClassName),children:[I.jsx("div",{className:"univer-w-[50%] univer-flex-shrink-0 univer-overflow-hidden univer-text-ellipsis univer-whitespace-nowrap univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",title:g.name,children:g.name}),I.jsx("div",{className:"univer-w-[50%] univer-flex-shrink-0 univer-overflow-hidden univer-text-ellipsis univer-whitespace-nowrap univer-text-xs univer-text-gray-400",title:g.formulaOrRefString,children:g.formulaOrRefString})]})},S))}),I.jsxs("div",{className:"univer-cursor-pointer univer-p-2 univer-transition-colors univer-duration-200 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-600",onClick:u,children:[I.jsx("div",{className:"univer-mb-2 univer-text-sm univer-font-semibold univer-text-gray-600 dark:!univer-text-gray-200",children:r.t("definedName.managerTitle")}),I.jsx("div",{className:"univer-text-xs univer-text-gray-400",children:r.t("definedName.managerDescription")})]})]})}function Vu({disable:n}){const[r,e]=W.useState(""),t=_.useDependency(K.IDefinedNamesService);W.useEffect(()=>{const o=t.currentRange$.subscribe(()=>{e(t.getCurrentRangeForString())});return()=>{o.unsubscribe()}},[]);function i(){}return I.jsxs("div",{"data-u-comp":"defined-name",className:"univer-relative univer-box-border univer-flex univer-h-full univer-w-24 univer-border-r-gray-200 univer-py-1.5 univer-transition-all",children:[I.jsx("input",{className:X.clsx("univer-box-border univer-h-full univer-w-full univer-appearance-none univer-px-1.5 univer-text-gray-900 focus:univer-outline-none dark:!univer-border-r-gray-700 dark:!univer-bg-gray-900 dark:!univer-text-white",X.borderRightClassName,{"univer-cursor-not-allowed":n}),type:"text",value:r,onChange:i}),I.jsx(X.Dropdown,{overlay:I.jsx("div",{className:"univer-z-[1001]",children:I.jsx(Hu,{})}),disabled:n,children:I.jsx("a",{className:X.clsx("univer-absolute univer-right-0 univer-top-0 univer-flex univer-h-full univer-cursor-pointer univer-items-center univer-justify-center univer-px-1 univer-transition-colors univer-duration-200 hover:univer-bg-gray-100 dark:!univer-text-white dark:hover:!univer-bg-gray-800",{"univer-cursor-not-allowed univer-text-gray-300 hover:univer-bg-transparent dark:!univer-text-gray-700":n}),children:I.jsx(sn,{})})})]})}function ca(n){var J,re,ue,oe;const{className:r,disableDefinedName:e}=n,[t,i]=W.useState(!1),[o,s]=W.useState(0),l=_.useDependency(Yn),c=_.useDependency(me),d=_.useDependency(m.WorksheetProtectionRuleModel),u=_.useDependency(m.RangeProtectionRuleModel),h=_.useDependency(a.IUniverInstanceService),g=_.useDependency(m.SheetsSelectionsService),S=_.useDependency(a.IPermissionService),f=_.useDependency(m.RangeProtectionCache),v=_.useDependency(a.ICommandService),[p,C]=W.useState({editDisable:!1,viewDisable:!1}),[b,E]=W.useState(!1),w=_.useDependency(_.ComponentManager),O=_.useObservable(()=>h.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),M=W.useRef(0),P=_.useObservable(c.currentEditCellState$),A=so(M,(J=P==null?void 0:P.unitId)!=null?J:""),k=w.get(Di),N=_.useComponentsOfPart(zr.FORMULA_AUX),H=_.useDependency(a.IContextService);_.useObservable(W.useMemo(()=>H.subscribeContextValue$(a.FOCUSING_FX_BAR_EDITOR),[H]));const x=H.getContextValue(a.FOCUSING_FX_BAR_EDITOR),L=W.useRef(null),V=_.useDependency(q.IEditorService);W.useLayoutEffect(()=>{const ae=O.activeSheet$.pipe(D.switchMap(te=>te?D.merge(d.ruleChange$,u.ruleChange$,g.selectionMoveEnd$,g.selectionSet$).pipe(D.switchMap(()=>{var Ct,_t;const fe=O.getUnitId(),pe=te.getSheetId();if(!((Ct=g.getCurrentLastSelection())==null?void 0:Ct.range))return D.EMPTY;const Ee=(_t=g.getCurrentLastSelection())==null?void 0:_t.primary;return Ee?D.of({unitId:fe,subUnitId:pe,primary:Ee}):D.of(null)})):D.EMPTY)).subscribe(te=>{var fe,pe,we,Ee,Ct,_t;if(te){const{unitId:jt,subUnitId:Nr,primary:ip}=te;if(d.getRule(jt,Nr)){const sp=!((pe=(fe=S.getPermissionPoint(new m.WorksheetEditPermission(jt,Nr).id))==null?void 0:fe.value)==null||pe),ap=!((Ee=(we=S.getPermissionPoint(new m.WorksheetViewPermission(jt,Nr).id))==null?void 0:we.value)==null||Ee);C({viewDisable:ap,editDisable:sp});return}const{actualRow:rp,actualColumn:op}=ip,An=f.getCellInfo(jt,Nr,rp,op);C({editDisable:!((Ct=An==null?void 0:An[m.UnitAction.Edit])==null||Ct),viewDisable:!((_t=An==null?void 0:An[m.UnitAction.View])==null||_t)})}else C({viewDisable:!1,editDisable:!1})});return()=>{ae.unsubscribe()}},[O]),W.useEffect(()=>{const ae=c.visible$.subscribe(te=>{i(te.visible)});return()=>ae.unsubscribe()},[c.visible$]),W.useEffect(()=>{const ae=c.currentEditCellState$.subscribe(te=>{var fe,pe,we;(we=(pe=(fe=te==null?void 0:te.documentLayoutObject.documentModel)==null?void 0:fe.getBody())==null?void 0:pe.customBlocks)!=null&&we.length?E(!0):E(!1)});return()=>ae.unsubscribe()},[c.currentEditCellState$]),W.useEffect(()=>{const ae=()=>{if(!L.current)return;const te=L.current.getBoundingClientRect();l.setPosition(te)};if(L.current){ae();const te=new ResizeObserver(ae);return te.observe(L.current),()=>te.disconnect()}},[l]);function U(){s(o===0?1:0),setTimeout(()=>{l.handleFoldBtnClick(o===1)},150)}function B(){c.isVisible().visible&&v.executeCommand(ge.id,{visible:!1,eventType:R.DeviceInputEventType.Keyboard,keycode:_.KeyCode.ESC,unitId:P.unitId})}function Y(){c.isVisible().visible&&v.executeCommand(ge.id,{visible:!1,eventType:R.DeviceInputEventType.PointerDown,unitId:P.unitId})}function F(){l.handleFxBtnClick(!0)}const{viewDisable:z,editDisable:j}=p,Q=j||b,ie=W.useRef(!1),$=()=>{try{c.isVisible().visible===!1&&v.syncExecuteCommand(ge.id,{visible:!0,eventType:R.DeviceInputEventType.PointerDown,unitId:P.unitId}),H.setContextValue(a.FOCUSING_FX_BAR_EDITOR,!0)}catch(ae){throw ie.current=!0,ae}},se=()=>{ie.current&&setTimeout(()=>{V.blur(!0)},30),ie.current=!1},G=((oe=(ue=(re=P==null?void 0:P.documentLayoutObject.documentModel)==null?void 0:re.getDrawingsOrder())==null?void 0:ue.length)!=null?oe:0)>0||z;return I.jsxs("div",{"data-u-comp":"formula-bar",className:X.clsx("univer-box-border univer-flex univer-bg-white univer-transition-[height] univer-ease-linear dark:!univer-bg-gray-900",X.borderBottomClassName,r,{"univer-h-7":o===0,"univer-h-20":o===1,"univer-pointer-events-none":j}),children:[I.jsx("div",{className:"univer-relative univer-box-border univer-h-full univer-w-[100px]",children:I.jsx(Vu,{disable:e!=null?e:j})}),I.jsxs("div",{className:"univer-flex univer-h-full univer-w-full",children:[I.jsx("div",{className:X.clsx("univer-py-1.5",{"univer-cursor-not-allowed univer-text-gray-200":Q}),children:I.jsxs("div",{className:X.clsx("univer-relative univer-box-border univer-flex univer-h-full univer-w-20 univer-items-center univer-justify-center univer-text-xs",X.borderRightClassName),children:[I.jsx("span",{className:X.clsx("univer-flex univer-items-center univer-justify-center univer-rounded univer-p-1 univer-text-base dark:!univer-text-white",{"univer-cursor-pointer univer-text-green-600 hover:univer-bg-gray-100 dark:!univer-text-green-400 dark:hover:!univer-bg-gray-700":t}),onClick:B,children:I.jsx(qs,{})}),I.jsx("span",{className:X.clsx("univer-flex univer-items-center univer-justify-center univer-rounded univer-p-1 univer-text-base dark:!univer-text-white",{"univer-cursor-pointer univer-text-red-600 hover:univer-bg-gray-100 dark:!univer-text-red-400 dark:hover:!univer-bg-gray-700":t}),onClick:Y,children:I.jsx(on,{})}),I.jsx("span",{className:"univer-flex univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-p-1 univer-text-base hover:univer-bg-gray-100 dark:!univer-text-white dark:hover:!univer-bg-gray-700",onClick:F,children:I.jsx(ea,{})})]})}),I.jsxs("div",{className:"univer-flex univer-w-full univer-flex-1 univer-overflow-hidden univer-pl-3",children:[I.jsxs("div",{ref:L,className:"univer-relative univer-flex-1",onPointerDown:$,onPointerUp:se,style:{pointerEvents:G?"none":"auto"},children:[k&&I.jsx(k,{className:"univer-relative univer-h-full univer-w-full univer-break-words univer-outline-none [&>div]:univer-ring-transparent",disableSelectionOnClick:!0,editorId:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,initValue:"",onChange:()=>{},isFocus:x,unitId:P==null?void 0:P.unitId,subUnitId:P==null?void 0:P.sheetId,isSupportAcrossSheet:!0,resetSelectionOnBlur:!1,isSingle:!1,keyboardEventConfig:A,onFormulaSelectingChange:(ae,te)=>{M.current=ae,te&&(ae?c.enableForceKeepVisible():c.disableForceKeepVisible())},autoScrollbar:!1,disableContextMenu:!1}),G&&I.jsx("div",{className:"univer-pointer-events-none univer-relative univer-left-0 univer-top-0 univer-z-[100] univer-h-full univer-w-full univer-cursor-not-allowed univer-bg-white"})]}),I.jsx("div",{className:X.clsx("univer-flex univer-h-full univer-w-5 univer-cursor-pointer univer-items-center univer-justify-center univer-text-xs univer-text-gray-700 dark:!univer-text-gray-200",{"univer-cursor-not-allowed univer-text-gray-200 dark:!univer-text-gray-700":j}),onClick:U,children:I.jsx(Js,{className:X.clsx({"univer-rotate-180":o===1})})})]})]}),I.jsx(_.ComponentContainer,{components:N},"formula-aux")]})}const Tt=a.createIdentifier("univer.sheetbar-service");class da extends a.Disposable{constructor(){super();T(this,"renameId$");T(this,"removeId$");T(this,"scroll$");T(this,"scrollX$");T(this,"addSheet$");T(this,"_renameId$");T(this,"_removeId$");T(this,"_scroll$");T(this,"_scrollX$");T(this,"_addSheet$");T(this,"_currentHandler",null);this._renameId$=new D.Subject,this.renameId$=this._renameId$.asObservable(),this._removeId$=new D.Subject,this.removeId$=this._removeId$.asObservable(),this._scroll$=new D.Subject,this.scroll$=this._scroll$.asObservable(),this._scrollX$=new D.Subject,this.scrollX$=this._scrollX$.asObservable(),this._addSheet$=new D.Subject,this.addSheet$=this._addSheet$.asObservable()}setRenameId(e){this._renameId$.next(e)}setRemoveId(e){this._removeId$.next(e)}setScroll(e){this._scroll$.next(e)}setScrollX(e){this._scrollX$.next(e)}setAddSheet(e){this._addSheet$.next(e)}triggerSheetBarMenu(){var e;(e=this._currentHandler)==null||e.handleSheetBarMenu()}registerSheetBarMenuHandler(e){if(this._currentHandler)throw new Error("There is already a context menu handler!");return this._currentHandler=e,a.toDisposable(()=>{this._currentHandler=null})}}function ji(n){const{children:r,className:e,style:t,disabled:i=!1,onClick:o,...s}=n,l=c=>{if(i){c.preventDefault();return}o&&o(c)};return I.jsx(X.Button,{"data-u-comp":"sheet-bar-append-button",className:e,size:"small",disabled:i,style:t,variant:"text",onClick:l,...s,children:r})}function Wu(){const[n,r]=W.useState([]),[e,t]=W.useState(!1),i=_.useDependency(a.IUniverInstanceService),o=_.useDependency(a.ICommandService),s=_.useDependency(Tt),l=_.useDependency(m.WorksheetProtectionRuleModel),c=_.useObservable(()=>i.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),null,!1,[]),d=v=>{const{sheetId:p}=v;!p||!c||(v.hidden?o.executeCommand(m.SetWorksheetShowCommand.id,{unitId:c.getUnitId(),subUnitId:p,value:p}):v.selected||o.executeCommand(m.SetWorksheetActivateCommand.id,{unitId:c.getUnitId(),subUnitId:p}),t(!1))},u=W.useCallback(()=>{if(!c)return;const v=c.getSheets(),p=c.getActiveSheet(),C=v.map((b,E)=>({label:b.getName(),index:`${E}`,sheetId:b.getSheetId(),hidden:b.isSheetHidden()===a.BooleanNumber.TRUE,selected:p===b}));r(C)},[c,l]),h=W.useCallback(()=>o.onCommandExecuted(v=>{switch(v.id){case m.SetWorksheetHideMutation.id:case m.RemoveSheetMutation.id:case m.SetWorksheetNameMutation.id:case m.InsertSheetMutation.id:case m.SetWorksheetOrderMutation.id:case m.SetWorksheetActiveOperation.id:u();break}}),[o,u]);function g(){t(!0)}const S=v=>{t(v)};W.useEffect(()=>{u();const v=new a.DisposableCollection;return v.add(h()),v.add(s.registerSheetBarMenuHandler({handleSheetBarMenu:g})),()=>v.dispose()},[h,s,u,c]);const f=W.useMemo(()=>n.map(v=>({type:"item",children:I.jsxs("div",{className:"univer-relative univer-box-border univer-pl-6",children:[(v.selected||v.hidden)&&I.jsxs("span",{className:"univer-absolute univer-left-1 univer-top-0.5",children:[v.selected&&I.jsx(on,{className:"univer-size-4 univer-text-primary-600"}),v.hidden&&I.jsx($s,{className:"univer-size-4 univer-text-gray-400"})]}),I.jsx("span",{className:X.clsx({"univer-text-primary-600":v.selected}),children:v.label})]}),onSelect:()=>{d(v)}})),[n]);return I.jsx(X.DropdownMenu,{align:"start",items:f,open:e,onOpenChange:S,children:I.jsx("div",{children:I.jsx(ji,{children:I.jsx(Qs,{})})})})}function xu(n){const{sheetId:r,label:e,color:t,selected:i,menuOverlay:o}=n,[s,l]=W.useState(i),c=_.useDependency(a.ThemeService);W.useEffect(()=>{l(i)},[i]);const d=u=>{const h=c.getColorFromTheme("gray.900"),g=c.getColorFromTheme("white");return new a.ColorKit(u).isDark()?g:h};return I.jsx("div",{"data-u-comp":"slide-tab-item","data-id":r,className:X.clsx("univer-mx-1 univer-box-border univer-flex univer-flex-grow univer-cursor-pointer univer-select-none univer-flex-row univer-items-center univer-rounded univer-text-xs univer-transition-[colors,box-shadow]",{"dark:!univer-text-white":!t||t&&!d(t),"univer-justify-center univer-bg-white univer-font-bold univer-text-primary-700 univer-shadow":s,"dark:!univer-bg-gray-900":s&&!t,"univer-font-medium univer-text-gray-900 hover:univer-bg-gray-100":!s,"dark:hover:!univer-bg-gray-700":!s&&!t}),style:{backgroundColor:!s&&t?t:"",color:!s&&t?d(t):"",boxShadow:s&&t?`0px 0px 8px rgba(0, 0, 0, 0.08), inset 0px -2px 0px 0px ${t}`:""},children:I.jsx("div",{className:"univer-box-border univer-flex univer-items-center univer-gap-1 univer-whitespace-nowrap univer-rounded univer-border-2 univer-border-solid univer-border-transparent univer-px-1.5 univer-py-1",children:e})},r)}const Lu={easeOutStrong(n,r,e,t){return-e*((n=n/t-1)*n*n*n-1)+r},backOut(n,r,e,t,i){return typeof i>"u"&&(i=.7),e*((n=n/t-1)*n*((i+1)*n+i)+1)+r}},Uu={loop:!1,begin:0,end:0,duration:300,delay:0,type:"easeOutStrong",receive(n){},success(n){},cancel(n){},complete(n){}};class Bu{constructor(r){T(this,"_config");T(this,"_status",0);T(this,"_start",0);T(this,"_handle",0);T(this,"_delayHandle",null);this._config={...Uu,...r},this._config.loop&&(this._config.complete=()=>{},this._config.success=()=>{this.request()})}static success(...r){let e=0;return new Promise(t=>{for(let i=0;i<r.length;i++){const o=r[i],s=o._config,l=s.success;s.loop||(s.success=d=>{e++,l&&l.call(o,d),e===r.length&&t()})}})}request(){this._config.delay===0?(this._status=0,this._start=Date.now(),this._fakeHandle()):(this._delayHandle&&clearTimeout(this._delayHandle),this._delayHandle=setTimeout(()=>{this._status=0,this._start=Date.now(),this._fakeHandle()},this._config.delay))}cancel(){this._status=1,this._delayHandle&&clearTimeout(this._delayHandle),cancelAnimationFrame(this._handle)}_fakeHandle(){let r=Date.now()-this._start;r=r>=this._config.duration?this._config.duration:r;const t=Lu[this._config.type](r,this._config.begin,this._config.end-this._config.begin,this._config.duration,.7).toFixed(2);if(this._config.receive(t),this._status===1){this._config.cancel(t),this._config.complete(t);return}if(r===this._config.duration){this._config.success(t),this._config.complete(t);return}this._handle=requestAnimationFrame(()=>{this._fakeHandle()})}}class yt{constructor(r,e){T(this,"_slideTabItem");T(this,"_animate");T(this,"_midline",0);T(this,"_translateX");T(this,"_scrollbar");T(this,"_slideTabBar");T(this,"_editMode");T(this,"_placeholder");this._slideTabItem=r,this._animate=null,this._translateX=0,this._editMode=!1,this._slideTabBar=e,this._placeholder=null,this._scrollbar=e.getScrollbar(),this.update()}static midline(r){return r.getBoundingRect().x+r.getBoundingRect().width/2}static leftLine(r){return r.getBoundingRect().x}static rightLine(r){return r.getBoundingRect().x+r.getBoundingRect().width}static make(r,e){const t=[];return r.forEach(i=>t.push(new yt(i,e))),t}getSlideTabItem(){return this._slideTabItem}getEditor(){return this._slideTabItem.querySelector("span")}focus(){var r;(r=this.getEditor())==null||r.focus()}selectAll(){const r=this.getEditor();r&&an.keepSelectAll(r)}isEditMode(){return this._editMode}classList(){return this._slideTabItem.classList}translateX(r){return this._translateX=r,this._slideTabItem.style.transform=`translateX(${r}px)`,this.getTranslateXDirection()}setEditor(r){if(!this._slideTabBar.getConfig().onNameChangeCheck())return;let e=!0;if(this._editMode===!1){const t=this._slideTabItem.querySelector("span"),i=d=>{if(!this.nameCheck()){if(this._editMode=!1,t&&(t.removeAttribute("contentEditable"),t.removeEventListener("focusout",i),t.removeEventListener("compositionstart",s),t.removeEventListener("compositionend",l),t.removeEventListener("input",c),t.removeEventListener("keydown",o)),this._slideTabBar.removeListener(),this._slideTabBar.updateItems(),this._slideTabBar.getConfig().onChangeName){const u=(t==null?void 0:t.innerText)||"",h=this.getId();this._slideTabBar.getConfig().onChangeName(h,u)}r&&r(d)}};let o=d=>{t&&(d.stopPropagation(),d.key==="Enter"&&t.blur())};const s=d=>{e=!1},l=d=>{e=!0},c=d=>{if(!t)return;const u=31;setTimeout(()=>{if(e){const h=t.innerText;h.length>u&&(t.innerText=h.substring(0,u),an.keepLastIndex(t))}},0)};t&&(t.setAttribute("contentEditable","true"),t.addEventListener("focusout",i),t.addEventListener("compositionstart",s),t.addEventListener("compositionend",l),t.addEventListener("input",c),t.addEventListener("keydown",o),this._editMode=!0,an.keepSelectAll(t))}}nameCheck(){const r=this._slideTabItem.querySelector("span");if(!r)return!1;const e=r.innerText;return this._slideTabBar.getConfig().onNameCheckAlert(e)}animate(){return{translateX:r=>{this._translateX!==r&&(this._animate&&(this._animate.cancel(),this._animate=null),this._animate=new Bu({begin:this._translateX,end:r,receive:e=>{this._slideTabItem.style.transform=`translateX(${e}px)`}}),this._translateX=r,this._animate.request())},cancel:()=>{this._animate&&(this._animate.cancel(),this._animate=null)}}}after(r){this._slideTabItem.after(r._slideTabItem||r)}update(){this._midline=yt.midline(this)}disableFixed(){if(this._placeholder){const r=this._slideTabBar.primeval();this._slideTabItem.style.removeProperty("position"),this._slideTabItem.style.removeProperty("left"),this._slideTabItem.style.removeProperty("top"),this._slideTabItem.style.removeProperty("width"),this._slideTabItem.style.removeProperty("height"),this._slideTabItem.style.removeProperty("background"),this._slideTabItem.style.removeProperty("padding"),this._slideTabItem.style.removeProperty("box-sizing"),this._slideTabItem.style.removeProperty("font-size"),this._slideTabItem.style.removeProperty("font-family"),this._slideTabItem.style.removeProperty("font-weight"),this._slideTabItem.style.removeProperty("color"),this._slideTabItem.style.removeProperty("border-radius"),this._placeholder.after(this._slideTabItem),r.removeChild(this._placeholder),this._placeholder=null}}enableFixed(){const r=document.createElement("div"),e=this.getBoundingRect(),t=getComputedStyle(this._slideTabItem),i=this._slideTabItem.querySelector("span");if(this._placeholder=r,this._placeholder.style.width=`${e.width}px`,this._placeholder.style.height=`${e.height}px`,this._placeholder.style.flexShrink="0",this._placeholder.style.margin=t.margin,this._slideTabItem.style.background=t.background,i){const o=getComputedStyle(i).padding;this._slideTabItem.style.padding=o}this._slideTabItem.style.boxSizing=t.boxSizing,this._slideTabItem.style.fontSize=t.fontSize,this._slideTabItem.style.fontFamily=t.fontFamily,this._slideTabItem.style.fontWeight=t.fontWeight,this._slideTabItem.style.color=t.color,this._slideTabItem.style.borderRadius=t.borderRadius,this._slideTabItem.style.left=`${e.x-this.getScrollbar().getScrollX()}px`,this._slideTabItem.style.top=`${e.y}px`,this._slideTabItem.style.width=`${e.width}px`,this._slideTabItem.style.height=`${e.height}px`,this._slideTabItem.style.position="fixed",this._slideTabItem.after(r),document.body.appendChild(this._slideTabItem)}addEventListener(r,e,t){this._slideTabItem.addEventListener(r,e,t)}removeEventListener(r,e,t){this._slideTabItem.removeEventListener(r,e,t)}getScrollbar(){return this._scrollbar}getMidLine(){return this._midline}getBoundingRect(){const r=this._slideTabItem.getBoundingClientRect();return r.x+=this._scrollbar.getScrollX(),r}getWidth(){return this.getBoundingRect().width}getTranslateXDirection(){const r=yt.midline(this);return r>this._midline?1:r<this._midline?-1:0}equals(r){return r&&r._slideTabItem===this._slideTabItem}getId(){return this._slideTabItem.dataset.id||""}}class Fu{constructor(r){T(this,"_slideTabBar");T(this,"_scrollX");const e=r.primeval();this._scrollX=e.scrollLeft,this._slideTabBar=r}scrollX(r){const e=this._slideTabBar.primeval();e.scrollLeft=r,this._scrollX=e.scrollLeft}scrollRight(){const r=this._slideTabBar.primeval();r.scrollLeft=r.scrollWidth,this._scrollX=r.scrollLeft}getScrollX(){return this._scrollX}}const On=class On{constructor(r){T(this,"_activeTabItemIndex",0);T(this,"_slideTabBar");T(this,"_slideTabItems",[]);T(this,"_config");T(this,"_downActionX",0);T(this,"_moveActionX",0);T(this,"_compareIndex",0);T(this,"_activeTabItem",null);T(this,"_moveAction");T(this,"_upAction");T(this,"_downAction");T(this,"_wheelAction");T(this,"_scrollIncremental",0);T(this,"_compareDirection",0);T(this,"_autoScrollTime",null);T(this,"_slideScrollbar");T(this,"_longPressTimer",null);T(this,"_leftBoundingLine",0);T(this,"_rightBoundingLine",0);T(this,"_leftMoveX",0);T(this,"_rightMoveX",0);if(r.slideTabBarContainer==null)throw new Error("not found slide-tab-bar root element");const e=r.slideTabBarContainer.querySelector(`${r.slideTabBarSelector}`);if(e==null)throw new Error("not found slide-tab-bar");this._slideTabBar=e,this._slideScrollbar=new Fu(this),this._config=r,this._initConfig();let t=0,i=0,o=0;this._downAction=s=>{var O,M,P,A,k,N;if((O=this._activeTabItem)!=null&&O.isEditMode())return;this._longPressTimer&&(clearTimeout(this._longPressTimer),this._longPressTimer=null);const l=(P=(M=s.target)==null?void 0:M.closest(`${r.slideTabBarItemSelector}`))==null?void 0:P.getAttribute("data-id"),c=this._slideTabItems.findIndex(H=>H.getId()===l);if(l==null||c===-1)return;if(this._activeTabItemIndex!==c){(A=this._activeTabItem)==null||A.removeEventListener("pointermove",this._moveAction),(k=this._activeTabItem)==null||k.removeEventListener("pointerup",this._upAction),this.removeListener(),this._config.onChangeTab(s,l);return}if(this._compareIndex=c,this._downActionX=s.pageX,this._moveActionX=0,this._scrollIncremental=0,this._activeTabItem=this._slideTabItems[c],!this._activeTabItem){console.error("Not found active slide-tab-item in sheet bar");return}const d=this._activeTabItem.getSlideTabItem();d==null||d.setPointerCapture(s.pointerId),(N=this._activeTabItem)==null||N.addEventListener("pointerup",this._upAction);const{x:u,width:h}=this._activeTabItem.getBoundingRect(),{x:g,width:S}=this.getBoundingRect(),f=this._slideScrollbar.getScrollX();if(this._leftBoundingLine=this._downActionX-(u-f),this._rightBoundingLine=u-f+h-this._downActionX,this._leftMoveX=u-g-f,this._rightMoveX=g+S-(u+h)+f,s.button===2||this._hasEditItem())return;const{pageX:v,pageY:p}=s,C=Date.now(),b=C-o<=On.DoubleClickDelay,E=Math.abs(v-t)<10,w=Math.abs(p-i)<10;b&&E&&w&&this._activeTabItem.setEditor(),t=v,i=p,o=C,this._longPressTimer=setTimeout(()=>{var H,x,L;!d||(H=this._activeTabItem)!=null&&H.isEditMode()||((x=this._activeTabItem)==null||x.enableFixed(),this._startAutoScroll(),d.setPointerCapture(s.pointerId),d.style.cursor="move",(L=this._activeTabItem)==null||L.addEventListener("pointermove",this._moveAction))},On.LongPressDelay)},this._upAction=s=>{var d,u,h,g;if((d=this._activeTabItem)!=null&&d.isEditMode()||(this._longPressTimer&&(clearTimeout(this._longPressTimer),this._longPressTimer=null),!this._activeTabItem))return;const l=this._autoScrollTime!==null;this._closeAutoScroll(),this._activeTabItem.disableFixed(),this.updateItems();const c=(u=this._activeTabItem)==null?void 0:u.getSlideTabItem();c&&(c.style.cursor="",c.releasePointerCapture(s.pointerId),(h=this._activeTabItem)==null||h.removeEventListener("pointermove",this._moveAction),(g=this._activeTabItem)==null||g.removeEventListener("pointerup",this._upAction),this._config.onSlideEnd&&this._activeTabItemIndex!==this._compareIndex&&l&&(this.removeListener(),this._config.onSlideEnd(s,this._compareIndex||0)),this._scrollIncremental=0,this._downActionX=0,this._moveActionX=0,this._compareIndex=0)},this._moveAction=s=>{this._activeTabItem&&(this._moveActionX=s.pageX-this._downActionX,this._moveActionX<=-this._leftMoveX?this._moveActionX=-this._leftMoveX:this._moveActionX>=this._rightMoveX&&(this._moveActionX=this._rightMoveX),this._scrollIncremental=0,this._scrollLeft(s),this._scrollRight(s))},this._wheelAction=s=>{this.setScroll(s.deltaY)},this.addListener()}static checkedSkipSlide(r){let e=r.target;for(;e!=null&&e!==document.body;){if(e.getAttribute("data-slide-skip"))return!0;e=e.parentElement}return!1}static keepLastIndex(r){setTimeout(()=>{const e=window.getSelection();e&&(e.selectAllChildren(r),e.collapseToEnd())})}static keepSelectAll(r){setTimeout(()=>{const e=window.getSelection();if(!e)return;const t=document.createRange();t.selectNodeContents(r),e.removeAllRanges(),e.addRange(t)})}update(r){this._config.currentIndex=r,this._initConfig(),this.removeListener(),this.addListener(),this.scrollToItem(r)}primeval(){return this._slideTabBar}updateItems(){for(let r=0;r<this._slideTabItems.length;r++)this._slideTabItems[r].animate().cancel(),this._slideTabItems[r].translateX(0),this._slideTabItems[r].update()}getScrollbar(){return this._slideScrollbar}getConfig(){return this._config}getBoundingRect(){return this._slideTabBar.getBoundingClientRect()}getSlideTabItems(){return this._slideTabItems}getActiveItem(){return this._activeTabItem}isLeftEnd(){return this._slideTabBar.scrollLeft===0}isRightEnd(){const r=this._slideTabBar.parentElement;return r?this._slideTabBar.scrollWidth-r.clientWidth===this._slideTabBar.scrollLeft:!1}addListener(){this._slideTabBar.addEventListener("wheel",this._wheelAction),this._slideTabItems.forEach(r=>{r.addEventListener("pointerdown",this._downAction)})}removeListener(){this._slideTabBar.removeEventListener("wheel",this._wheelAction),this._slideTabItems.forEach(r=>{r.removeEventListener("pointerdown",this._downAction)})}setScroll(r){if(this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+r),r>0){const e=this.calculateLeftScrollX();this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e)}else if(r<0){const e=this.calculateRightScrollX();this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e)}this._config.onScroll({leftEnd:this.isLeftEnd(),rightEnd:this.isRightEnd()})}flipPage(r){if(r>0){const e=this.calculateLeftScrollX(!0);this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e)}else if(r<0){const e=this.calculateRightScrollX(!0);this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e)}this._config.onScroll({leftEnd:this.isLeftEnd(),rightEnd:this.isRightEnd()})}scrollToItem(r){if(r=r!=null?r:this._config.currentIndex,r<0||r>=this._slideTabItems.length){console.error("Index out of bounds");return}const e=this.calculateTabItemScrollX(r);this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e),this._config.onScroll({leftEnd:this.isLeftEnd(),rightEnd:this.isRightEnd()})}calculateLeftScrollX(r){let e=0;const t=4;return this._slideTabItems.some(i=>{const o=this._slideTabBar.getBoundingClientRect(),s=o.left+o.width,l=i.getSlideTabItem().getBoundingClientRect(),c=l.left,d=l.width;return c<s&&c+d+t*2>s?(e=r?c-o.left-t:c+d-s+t,!0):!1}),e}calculateRightScrollX(r){let e=0;const t=4;return this._slideTabItems.some(i=>{const o=this._slideTabBar.getBoundingClientRect(),s=o.left,l=i.getSlideTabItem().getBoundingClientRect(),c=l.left,d=l.width;return c-t*2<s&&c+d>s?(e=r?c+d-o.left-o.width+t:c-s-t,!0):!1}),e}calculateTabItemScrollX(r){let e=0;const t=4,i=this._slideTabBar.getBoundingClientRect(),o=i.left,s=i.left+i.width,l=this._slideTabItems[r].getSlideTabItem().getBoundingClientRect(),c=l.left,d=l.width;return c-t*2<o&&(e=c-o-t),c+d+t*2>s&&(e=c+d-s+t),e}calculateActiveTabItemScrollX(){var d;let r=0;const e=4,t=this._slideTabBar.getBoundingClientRect(),i=t.left,o=t.left+t.width,s=(d=this._activeTabItem)==null?void 0:d.getSlideTabItem().getBoundingClientRect();if(!s)return 0;const l=s.left,c=s.width;return l-e*2<i&&l+c>i&&(r=l-i-e),l<o&&l+c+e*2>o&&(r=l+c-o+e),r}destroy(){this.removeListener(),this._downActionX=0,this._moveActionX=0,this._compareDirection=0,this._compareIndex=0,this._slideTabItems=[],this._activeTabItem=null}_hasEditItem(){for(let r=0;r<this._slideTabItems.length;r++)if(this._slideTabItems[r].isEditMode())return!0;return!1}_autoScrollFrame(){if(this._activeTabItem)switch(this._compareDirection=this._activeTabItem.translateX(this._moveActionX),this._compareDirection){case 1:{this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+this._scrollIncremental),this._compareRight();break}case 0:{this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+this._scrollIncremental),this._compareIndex=this._activeTabItemIndex;break}case-1:{this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+this._scrollIncremental),this._compareLeft();break}}this._autoScrollTime=requestAnimationFrame(()=>{this._autoScrollFrame()})}_startAutoScroll(){this._autoScrollTime==null&&this._autoScrollFrame()}_closeAutoScroll(){this._autoScrollTime&&cancelAnimationFrame(this._autoScrollTime),this._autoScrollTime=null}_scrollLeft(r){const e=this.getBoundingRect(),t=r.pageX-e.x;t<this._leftBoundingLine&&(this._scrollIncremental=-Math.min(Math.abs(t-this._leftBoundingLine)*.1,50))}_scrollRight(r){const e=this.getBoundingRect(),t=r.pageX-e.x;t>e.width-this._rightBoundingLine&&(this._scrollIncremental=Math.min(Math.abs(t-(e.width-this._rightBoundingLine))*.1,50))}_sortedItems(){if(this._activeTabItem!=null&&this._activeTabItemIndex!=null&&this._compareIndex!=null&&(this._slideTabItems.splice(this._activeTabItemIndex,1),this._slideTabItems.splice(this._compareIndex,0,this._activeTabItem),this._config.slideTabBarItemAutoSort))for(let r=0;r<this._slideTabItems.length;r++){const e=this._slideTabItems[r],t=this._slideTabItems[r+1];t&&e.after(t)}}_compareLeft(){if(this._activeTabItem&&this._activeTabItemIndex){const r=this._slideTabItems.findIndex(o=>o.equals(this._activeTabItem)),e=this._slideTabItems.length,t=[];for(let o=0;o<r&&!(o>=r);o++)t.push(this._slideTabItems[o]);for(let o=r+1;o<e;o++)this._slideTabItems[o].animate().translateX(0);let i=!0;for(let o=t.length-1;o>=0;o--){const s=t[o];yt.leftLine(this._activeTabItem)<s.getMidLine()?(s.animate().translateX(this._activeTabItem.getWidth()),this._compareIndex=o,i=!1):(s.animate().translateX(0),i&&(this._compareIndex=this._activeTabItemIndex))}}}_compareRight(){if(this._activeTabItem){const r=this._slideTabItems.findIndex(o=>o.equals(this._activeTabItem)),e=this._slideTabItems.length,t=[];for(let o=r+1;o<e;o++)t.push(this._slideTabItems[o]);for(let o=0;o<r;o++)this._slideTabItems[o].animate().translateX(0);let i=!0;for(let o=0;o<t.length;o++){const s=t[o];yt.rightLine(this._activeTabItem)>s.getMidLine()?(s.animate().translateX(-this._activeTabItem.getWidth()),this._compareIndex=r+o+1,i=!1):(s.animate().translateX(0),i&&(this._compareIndex=this._activeTabItemIndex))}}}_initConfig(){const r=this._slideTabBar.querySelectorAll(`${this._config.slideTabBarItemSelector}`);this._downActionX=0,this._moveActionX=0,this._compareDirection=0,this._compareIndex=0,this._slideTabItems=yt.make(r,this),this._activeTabItemIndex=this._config.currentIndex,this._activeTabItem=this._slideTabItems[this._activeTabItemIndex]}};T(On,"LongPressDelay",500),T(On,"DoubleClickDelay",300);let an=On;function zu(){var se;const[n,r]=W.useState([]),[e,t]=W.useState(""),[i,o]=W.useState(""),[s,l]=W.useState(!1),[c,d]=W.useState([0,0]),u=W.useRef({slideTabBar:null}),h=W.useRef(null),g=_.useDependency(a.ICommandService),S=_.useDependency(Tt),f=_.useDependency(a.LocaleService),v=_.useDependency(_.IConfirmService),p=_.useDependency(me,a.Quantity.OPTIONAL),C=_.useDependency(m.WorksheetProtectionRuleModel),b=_.useDependency(m.RangeProtectionRuleModel),E=_.useObservable(C.resetOrder$),w=lt(),O=_.useDependency(a.IPermissionService),M=W.useCallback(()=>{var ue;const Z=((ue=w.getActiveSheet())==null?void 0:ue.getSheetId())||"";t(Z);const G=w.getSheets(),J=w.getActiveSheet(),re=G.filter(oe=>!oe.isSheetHidden()).map((oe,ae)=>{var Ee;const te=C.getRule(w.getUnitId(),oe.getSheetId()),fe=b.getSubunitRuleList(w.getUnitId(),oe.getSheetId()).length>0,we=(te==null?void 0:te.permissionId)||fe?I.jsxs(I.Fragment,{children:[I.jsx(io,{}),I.jsx("span",{className:"univer-outline-none",children:oe.getName()})]}):I.jsx("span",{className:"univer-outline-none",children:oe.getName()});return{sheetId:oe.getSheetId(),label:we,index:ae,selected:J===oe,color:(Ee=oe.getTabColor())!=null?Ee:void 0}});r(re),t(Z)},[b,w,C]);W.useEffect(()=>{M();const{slideTabBar:Z,disconnectResizeObserver:G}=P(),J=B(),re=[Y(),F(),z()];return()=>{J.dispose(),Z.destroy(),re.forEach(ue=>ue.unsubscribe()),G&&G()}},[E,w]),W.useEffect(()=>{n.length>0&&U()},[n]),W.useEffect(()=>{const Z=D.merge(C.ruleChange$,b.ruleChange$).subscribe(()=>{M()});return()=>{Z.unsubscribe()}},[C,M]);const P=()=>{const Z=new an({slideTabBarSelector:"[data-u-comp=slide-tab-bar]",slideTabBarItemSelector:"[data-u-comp=slide-tab-item]",slideTabBarItemAutoSort:!0,slideTabBarContainer:h.current,currentIndex:0,onChangeName:(J,re)=>{g.executeCommand(m.SetWorksheetNameCommand.id,{subUnitId:J,name:re})},onSlideEnd:async(J,re)=>{await g.executeCommand(m.SetWorksheetOrderCommand.id,{order:re})},onChangeTab:(J,re)=>{g.executeCommand(m.SetWorksheetActiveOperation.id,{subUnitId:re,unitId:w.getUnitId()}).then(()=>{J.button===2&&$(!0)})},onScroll:J=>{S.setScroll(J)},onNameCheckAlert:J=>N(J)||H(J)||x(J),onNameChangeCheck:()=>{var te,fe,pe,we;const J=w.getUnitId(),re=w==null?void 0:w.getActiveSheet();if(!re)throw new Error("No active sheet found");const ue=re.getSheetId(),oe=C.getRule(J,ue),ae=b.getSubunitRuleList(J,ue).length>0;return oe||ae?(fe=(te=O.getPermissionPoint(new m.WorkbookManageCollaboratorPermission(J).id))==null?void 0:te.value)!=null?fe:!1:(we=(pe=O.getPermissionPoint(new m.WorkbookRenameSheetPermission(J).id))==null?void 0:pe.value)!=null?we:!1}});u.current.slideTabBar=Z;const G=ie(Z);return{slideTabBar:Z,disconnectResizeObserver:G}},A=_.useConfigValue(_.UI_PLUGIN_CONFIG_KEY),k=(se=A==null?void 0:A.contextMenu)!=null?se:!0,N=Z=>{if(Z.trim()===""){const G="sheetNameEmptyAlert";return v.open({id:G,title:{title:f.t("sheetConfig.sheetNameErrorTitle")},children:{title:f.t("sheetConfig.sheetNameCannotIsEmptyError")},cancelText:f.t("button.cancel"),confirmText:f.t("button.confirm"),onClose(){L(),v.close(G)},onConfirm(){L(),v.close(G)}}),!0}return!1},H=Z=>{if(!a.nameCharacterCheck(Z)){const G="sheetNameSpecCharAlert";return v.open({id:G,title:{title:f.t("sheetConfig.sheetNameErrorTitle")},children:{title:f.t("sheetConfig.sheetNameSpecCharError")},cancelText:f.t("button.cancel"),confirmText:f.t("button.confirm"),onClose(){L(),v.close(G)},onConfirm(){L(),v.close(G)}}),!0}return!1},x=Z=>{const G=w.getActiveSheet();if((G==null?void 0:G.getName())===Z)return!1;const re=w.checkSheetName(Z);if(re){const ue="sheetNameRepeatAlert";v.open({id:ue,title:{title:f.t("sheetConfig.sheetNameErrorTitle")},children:{title:f.t("sheetConfig.sheetNameAlreadyExistsError")},cancelText:f.t("button.cancel"),confirmText:f.t("button.confirm"),onClose(){v.close(ue),L()},onConfirm(){v.close(ue),L()}})}return re},L=()=>{setTimeout(()=>{var G;const Z=(G=u.current.slideTabBar)==null?void 0:G.getActiveItem();Z&&(Z.focus(),Z.selectAll())},0)},V=()=>{var Z,G;(G=(Z=u.current.slideTabBar)==null?void 0:Z.getActiveItem())==null||G.setEditor()},U=()=>{var G;const Z=n.findIndex(J=>J.selected);(G=u.current.slideTabBar)==null||G.update(Z)},B=()=>g.onCommandExecuted(Z=>{switch(Z.id){case m.SetTabColorMutation.id:case m.SetWorksheetHideMutation.id:case m.RemoveSheetMutation.id:case m.SetWorksheetNameMutation.id:case m.InsertSheetMutation.id:case m.SetWorksheetOrderMutation.id:case m.SetWorksheetActiveOperation.id:M();break}}),Y=()=>S.scroll$.subscribe(Z=>{j(Z)}),F=()=>S.scrollX$.subscribe(Z=>{var G;(G=u.current.slideTabBar)==null||G.flipPage(Z)}),z=()=>S.renameId$.subscribe(()=>{V()}),j=Z=>{const{leftEnd:G,rightEnd:J}=Z;let re="";G&&J?re="":G&&!J?re="inset -10px 0px 10px -10px rgba(0, 0, 0, 0.2)":!G&&J?re="inset 10px 0px 10px -10px rgba(0, 0, 0, 0.2)":!G&&!J&&(re="inset 10px 0px 10px -10px rgba(0, 0, 0, 0.2), inset -10px 0px 10px -10px rgba(0, 0, 0, 0.2)"),o(re)},Q=Z=>{const G=Z.calculateActiveTabItemScrollX();if(G){const J=Z.getScrollbar();J.scrollX(J.getScrollX()+G)}S.setScroll({leftEnd:Z.isLeftEnd(),rightEnd:Z.isRightEnd()})},ie=Z=>{var re;const G=(re=h.current)==null?void 0:re.querySelector("[data-u-comp=slide-tab-bar]");if(!G)return;const J=new ResizeObserver(()=>{Q(Z)});return J.observe(G),()=>J.disconnect()},$=Z=>{var G,J,re,ue,oe;if(k&&!(p!=null&&p.isForceKeepVisible())){if(Z){const{left:ae}=(J=(G=h.current)==null?void 0:G.getBoundingClientRect())!=null?J:{},{left:te}=(oe=(ue=(re=u.current.slideTabBar)==null?void 0:re.getActiveItem())==null?void 0:ue.getSlideTabItem().getBoundingClientRect())!=null?oe:{};ae!==void 0&&te!==void 0&&d([te-ae,0])}l(Z)}};return I.jsx(X.DropdownLegacy,{className:"univer-select-none",visible:s,align:{offset:c},trigger:["contextMenu"],overlay:I.jsx(_.UIMenu,{menuType:_.ContextMenuPosition.FOOTER_TABS,onOptionSelect:Z=>{const{label:G,value:J,commandId:re}=Z;g.executeCommand(re!=null?re:G,{value:J,subUnitId:e}),l(!1)}}),onVisibleChange:$,children:I.jsx("div",{className:"univer-max-w-[calc(100%-112px)] univer-overflow-hidden",ref:h,onDragStart:Z=>Z.preventDefault(),onContextMenu:Z=>Z.preventDefault(),children:I.jsx("div",{"data-u-comp":"slide-tab-bar",className:"univer-flex univer-select-none univer-flex-row univer-items-center univer-overflow-hidden univer-px-1.5 univer-py-1",style:{boxShadow:i},children:n.map(Z=>W.createElement(xu,{...Z,key:Z.sheetId,selected:e===Z.sheetId}))})})})}const Xu=100,ua=()=>{var v,p;const[n,r]=W.useState(!0),[e,t]=W.useState(!0),i=_.useDependency(a.ICommandService),o=_.useDependency(Tt),s=_.useDependency(a.IPermissionService),c=lt().getUnitId(),d=_.useObservable(s.getPermissionPoint$((v=new m.WorkbookEditablePermission(c))==null?void 0:v.id)),u=_.useObservable(s.getPermissionPoint$((p=new m.WorkbookCreateSheetPermission(c))==null?void 0:p.id)),h=C=>{const{leftEnd:b,rightEnd:E}=C;r(b),t(E)};W.useEffect(()=>{const C=o.scroll$.subscribe(a.throttle(b=>{h(b)},100));return()=>{C.unsubscribe()}},[]);const g=()=>{i.executeCommand(m.InsertSheetCommand.id),setTimeout(()=>{o.setAddSheet(0)},0)},S=()=>{o.setScrollX(-100)},f=()=>{o.setScrollX(Xu)};return I.jsxs("div",{className:"univer-relative univer-flex univer-h-full univer-min-w-0 univer-flex-1",children:[I.jsxs("div",{className:"univer-flex univer-items-center",children:[I.jsx(ji,{className:"univer-mr-2",onClick:g,disabled:!(u!=null&&u.value&&(d!=null&&d.value)),children:I.jsx(no,{})}),I.jsx(Wu,{})]}),I.jsx(zu,{}),(!n||!e)&&I.jsxs("div",{className:'univer-relative univer-flex univer-items-center univer-px-2 after:univer-absolute after:univer-right-0 after:univer-top-1/2 after:univer-h-4 after:univer-w-px after:-univer-translate-y-1/2 after:univer-bg-gray-200 after:univer-content-[""]',children:[I.jsx(ji,{disabled:n,onClick:S,children:I.jsx(ro,{className:"univer-rotate-180"})}),I.jsx(ji,{disabled:e,onClick:f,children:I.jsx(ro,{})})]})]})},Yu=[50,75,100,125,150,175,200,400];function ju(){const n=_.useDependency(a.ICommandService),r=_.useDependency(a.IUniverInstanceService),e=lt(),t=_.useDependency(me),i=_.useObservable(t.visible$),o=W.useCallback(()=>{if(!e)return 100;const u=e.getActiveSheet(),h=u&&u.getZoomRatio()*100||100;return Math.round(h)},[e]),[s,l]=W.useState(()=>o());W.useEffect(()=>(l(o()),n.onCommandExecuted(h=>{if(h.id===He.id||h.id===m.SetWorksheetActiveOperation.id){const g=o();l(g)}}).dispose),[n,o]);function c(u){l(u);const h=r.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),g=h==null?void 0:h.getActiveSheet();if(g==null)return;const S=u/100;n.executeCommand(en.id,{unitId:h.getUnitId(),subUnitId:g.getSheetId(),zoomRatio:S})}const d=(i==null?void 0:i.visible)&&(i.unitId===(e==null?void 0:e.getUnitId())||i.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);return I.jsx(_.Slider,{disabled:d,min:Hr[0],value:s,shortcuts:Yu,onChange:c})}function Gu(){return I.jsx("section",{className:"univer-flex univer-flex-shrink-0 univer-justify-end",children:I.jsx(ju,{})})}class ao{constructor(){T(this,"_functions",[{func:K.FUNCTION_NAMES_STATISTICAL.MAX,filter:r=>{var e,t,i,o;return((t=(e=r.values.find(s=>s.func===K.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1&&((o=(i=r.values.find(s=>s.func===K.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:i.value)!=null?o:0)>0}},{func:K.FUNCTION_NAMES_STATISTICAL.MIN,filter:r=>{var e,t,i,o;return((t=(e=r.values.find(s=>s.func===K.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1&&((o=(i=r.values.find(s=>s.func===K.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:i.value)!=null?o:0)>0}},{func:K.FUNCTION_NAMES_MATH.SUM,filter:r=>{var e,t,i,o;return((t=(e=r.values.find(s=>s.func===K.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1&&((o=(i=r.values.find(s=>s.func===K.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:i.value)!=null?o:0)>0}},{func:K.FUNCTION_NAMES_STATISTICAL.COUNTA,filter:r=>{var e,t;return((t=(e=r.values.find(i=>i.func===K.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1}},{func:K.FUNCTION_NAMES_STATISTICAL.COUNT,filter:r=>{var e,t,i,o;return((t=(e=r.values.find(s=>s.func===K.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1&&((o=(i=r.values.find(s=>s.func===K.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:i.value)!=null?o:0)>0}},{func:K.FUNCTION_NAMES_STATISTICAL.AVERAGE,filter:r=>{var e,t,i,o;return((t=(e=r.values.find(s=>s.func===K.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1&&((o=(i=r.values.find(s=>s.func===K.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:i.value)!=null?o:0)>0}}]);T(this,"_state$",new D.BehaviorSubject(null));T(this,"state$",this._state$.asObservable())}dispose(){this._state$.complete()}setState(r){var t;const e={values:[],pattern:null};r==null||r.values.forEach(i=>{const o=this._functions.find(s=>s.func===i.func);o&&(o.filter===void 0||o.filter(r))&&e.values.push(i)}),e.pattern=(t=r==null?void 0:r.pattern)!=null?t:null,this._state$.next(e)}getState(){return this._state$.getValue()}getFunctions(){return this._functions}addFunctions(r){this._functions.push(...r)}}const Gn=a.createIdentifier("univer.sheet-status-bar.service"),Zu=[K.FUNCTION_NAMES_MATH.SUM,K.FUNCTION_NAMES_STATISTICAL.AVERAGE,K.FUNCTION_NAMES_STATISTICAL.MIN,K.FUNCTION_NAMES_STATISTICAL.MAX],Gi={[K.FUNCTION_NAMES_MATH.SUM]:"statusbar.sum",[K.FUNCTION_NAMES_STATISTICAL.AVERAGE]:"statusbar.average",[K.FUNCTION_NAMES_STATISTICAL.MIN]:"statusbar.min",[K.FUNCTION_NAMES_STATISTICAL.MAX]:"statusbar.max",[K.FUNCTION_NAMES_STATISTICAL.COUNT]:"statusbar.count",[K.FUNCTION_NAMES_STATISTICAL.COUNTA]:"statusbar.countA",[K.FUNCTION_NAMES_TEXT.CONCATENATE]:"concatenate"},Ku=n=>{const r=_.useDependency(a.LocaleService),e=_.useDependency(_.IMessageService),t=_.useDependency(_.IClipboardInterfaceService),i=qu(n),o=async()=>{await t.writeText(n.value.toString()),e.show({type:X.MessageType.Success,content:r.t("statusbar.copied")})};return I.jsx(X.Tooltip,{title:r.t("statusbar.clickToCopy"),placement:"top",children:I.jsx("div",{className:"univer-flex univer-max-w-24 univer-cursor-default univer-truncate univer-text-center univer-text-xs univer-text-gray-400",onClick:o,children:I.jsx("span",{children:`${r.t((Gi==null?void 0:Gi[n.name])||n.name)}: ${i}`})},n.name)})};function qu(n){const{pattern:r,value:e}=n;return typeof e!="number"?0:e>=1e8?e.toExponential(2):r&&Zu.includes(n.name)?a.numfmt.format(r,e,{throws:!1}):e.toLocaleString()}const ha=800,Qu=3,Ju=()=>{var h,g;const n=(g=(h=_.useConfigValue(Oe))==null?void 0:h.statusBarStatistic)!=null?g:!0,[r,e]=W.useState(window.innerWidth<ha),t=_.useDependency(Gn),i=t.getFunctions().map((S,f)=>({name:S.func,value:0,show:!0,disable:!1,pattern:null})),o=(S,f,v,p)=>{const[C,b]=W.useState(S),[E,w]=W.useState(!0),O=W.useMemo(()=>C.filter(k=>k.show&&!k.disable),[C]),M=W.useMemo(()=>O.find(k=>k.show&&!k.disable),[O]),P=W.useMemo(()=>v&&M?[M]:O,[v,M,O]),A=W.useCallback(k=>{const N=k==null?void 0:k.values;if(!(N!=null&&N.length)){w(!1);return}w(!0),b(H=>H.map(x=>{var L,V,U;return{...x,value:(V=(L=N.find(B=>B.func===x.name))==null?void 0:L.value)!=null?V:x.value,disable:!N.some(B=>B.func===x.name),pattern:(U=k==null?void 0:k.pattern)!=null?U:null}}))},[]);return W.useEffect(()=>{if(!p)return;const k=f.state$.subscribe(A);return()=>k.unsubscribe()},[p,f,A]),{statistics:C,showList:P,show:E}},{showList:s,show:l}=o(i,t,r,n),c=a.debounce(()=>{const S=window.innerWidth<ha;r!==S&&e(S)},100);W.useEffect(()=>(window.addEventListener("resize",c),()=>{window.removeEventListener("resize",c)}),[r]);const u=((S,f,v)=>n?W.useMemo(()=>{if(S.length>f){const C=S.reduce((b,E,w)=>(w%2===0&&b.push(S.slice(w,w+2)),b),[]);return I.jsx(I.Fragment,{children:C.map((b,E)=>I.jsxs("div",{children:[b[0]&&I.jsx(v,{...b[0]},b[0].name),b[1]&&I.jsx(v,{...b[1]},b[1].name)]},`stat-col-${E}`))})}return I.jsx(I.Fragment,{children:S.map(C=>I.jsx(v,{...C},C.name))})},[S,f,v]):null)(s,Qu,Ku);return l&&I.jsx("div",{className:X.clsx('univer-relative univer-box-border univer-flex univer-items-center univer-px-2 after:univer-absolute after:univer-right-0 after:univer-top-1/2 after:univer-block after:univer-h-4 after:univer-w-px after:-univer-translate-y-1/2 after:univer-bg-gray-200 after:univer-content-[""]',{"univer-max-w-32":r,"univer-max-w-80":!r}),children:I.jsx("div",{className:"univer-flex univer-gap-x-2",children:u})})},ma=36;function ga(){var d;const n=_.useConfigValue(Oe),r=_.useDependency(_.IMenuManagerService),e=(d=n==null?void 0:n.footer)!=null?d:!0;if(!lt()||!e)return null;const i=r.getMenuByPositionKey(_.ContextMenuPosition.FOOTER_MENU),{sheetBar:o=!0,statisticBar:s=!0,menus:l=!0,zoomSlider:c=!0}=(n==null?void 0:n.footer)||{};return!o&&!s&&!l&&!c?null:I.jsxs("section",{className:"univer-box-border univer-grid univer-w-full univer-grid-flow-col univer-grid-cols-[1fr,auto,auto,auto] univer-items-center univer-justify-between univer-bg-white univer-px-5 univer-text-gray-900 dark:!univer-bg-gray-900 dark:!univer-text-gray-200",style:{height:ma},"data-range-selector":!0,children:[o&&I.jsx(ua,{}),s&&I.jsx(Ju,{}),l&&i.length>0&&I.jsx("div",{className:"univer-box-border univer-flex univer-gap-2 univer-px-2",children:i.map(u=>{var h;return(h=u.children)==null?void 0:h.map(g=>(g==null?void 0:g.item)&&I.jsx(_.ToolbarItem,{...g.item},g.key))})}),c&&I.jsx(Gu,{})]})}function Sa(){const n=_.useConfigValue(Oe);return va()&&(n==null?void 0:n.formulaBar)!==!1?I.jsx(ca,{}):null}function fa(){return va()?I.jsxs(I.Fragment,{children:[I.jsx(ku,{}),I.jsx(Du,{})]}):null}function va(){const n=_.useDependency(a.IUniverInstanceService),e=!!_.useObservable(()=>n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),null,!1,[]);return W.useMemo(()=>n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).length>0,[n,e])}var $u=Object.getOwnPropertyDescriptor,eh=(n,r,e,t)=>{for(var i=t>1?void 0:t?$u(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},ln=(n,r)=>(e,t)=>r(e,t,n);const pa=5,Ca=2;y.SheetCellEditorResizeService=class extends a.Disposable{constructor(r,e,t,i,o,s){super(),this._layoutService=r,this._cellEditorManagerService=e,this._editorBridgeService=t,this._renderManagerService=i,this._univerInstanceService=o,this._configService=s}get _currentRenderer(){return R.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService)}get _editingUnitId(){var r,e;return(e=(r=this._editorBridgeService.getEditCellState())==null?void 0:r.unitId)!=null?e:""}get _editingRenderer(){return this._renderManagerService.getRenderById(this._editingUnitId)}get _renderer(){var e;const r=(e=this._univerInstanceService.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET))==null?void 0:e.getUnitId();return this._editingUnitId===r?this._editingRenderer:this._currentRenderer}get _sheetSkeletonManagerService(){var r;return(r=this._renderer)==null?void 0:r.with(y.SheetSkeletonManagerService)}get engine(){var r;return(r=this._renderer)==null?void 0:r.engine}fitTextSize(r){var k,N,H,x;const e=this._editorBridgeService.getEditCellState();if(!e)return;const{position:t,documentLayoutObject:i,canvasOffset:o,scaleX:s,scaleY:l}=e,{startX:c,startY:d,endX:u,endY:h}=t,g=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);if(g==null)return;const S=this._getEditorSkeleton();if(!S)return;const f=this._predictingSize(t,o,S,i,s,l);if(!f||f.actualWidth<=0)return;let{actualWidth:v,actualHeight:p}=f;const{verticalAlign:C,horizontalAlign:b,paddingData:E,fill:w}=i;v=v+((k=E.l)!=null?k:0)+((N=E.r)!=null?N:0),p=p+((H=E.t)!=null?H:0)+((x=E.b)!=null?x:0);let O=u-c,M=h-d;O<v&&(O=Math.ceil(v)),M<p&&(M=Math.ceil(p));let P=0;C===a.VerticalAlign.MIDDLE?P=(M-p)/2/l:C===a.VerticalAlign.TOP?P=E.t||0:P=(M-p)/l;let A=0;b===a.HorizontalAlign.CENTER?A=(O-v)/2/s:b===a.HorizontalAlign.RIGHT?A=(O-v)/s:A=E.l||0,P=P<(E.t||0)?E.t||0:P,A=A<(E.l||0)?E.l||0:A,g.updateDocumentDataMargin({t:P,l:A}),S.calculate(),this._editAreaProcessing(O,M,t,o,w,s,l,b,r)}_predictingSize(r,e,t,i,o=1,s=1){const{startX:l,endX:c}=r,{textRotation:d,wrapStrategy:u,paddingData:h}=i,g=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC),{vertexAngle:S}=R.convertTextRotation(d);if(u===a.WrapStrategy.WRAP&&S===0){g==null||g.updateDocumentDataPageSize(c-l),g==null||g.updateDocumentDataMargin({l:h.l,t:h.t}),t.calculate();const{actualWidth:C,actualHeight:b}=t.getActualSize();return{actualWidth:C*o,actualHeight:b*s}}const f=this._getEditorMaxSize(r,e,i.horizontalAlign);if(!f)return;g==null||g.updateDocumentDataPageSize(f.width/o),t.calculate();const v=t.getActualSize();let p=c-l;return p<v.actualWidth*o+pa*o&&(p=v.actualWidth*o+pa*o),g==null||g.updateDocumentDataPageSize(p/o),g==null||g.updateDocumentRenderConfig({horizontalAlign:a.HorizontalAlign.UNSPECIFIED,cellValueType:void 0}),{actualWidth:v.actualWidth*o,actualHeight:v.actualHeight*s}}_getEditorMaxSize(r,e,t){var E,w,O,M;if(this._getEditorObject()==null)return;function o(P){return Number.parseInt(P.replace("px",""))}const s=this.engine;if(!s)return;const l=s.getCanvasElement(),c=l.getBoundingClientRect(),d=o(l.style.width),{width:u}=c,h=u/d,{startX:g,startY:S,endX:f}=r,v=s.width,p=((w=(E=this._configService.getConfig(_.UI_PLUGIN_CONFIG_KEY))==null?void 0:E.footer)==null||w)&&((M=(O=this._configService.getConfig(Oe))==null?void 0:O.footer)==null||M)?ma:0,C=document.body.clientHeight-S-p-e.top-Ca*2;let b=u-g;if(t===a.HorizontalAlign.CENTER){const P=v-f,A=g;b=f-g+Math.min(A,P)*2}else t===a.HorizontalAlign.RIGHT&&(b=f);return{height:C,width:b-Ca,scaleAdjust:h}}_editAreaProcessing(r,e,t,i,o,s=1,l=1,c,d){var V;const u=this._getEditorObject();if(u==null)return;const h=this.engine;if(!h)return;const g=h.getCanvasElement();let{startX:S,startY:f}=t;const{document:v,scene:p,engine:C}=u,b=p.getViewport(q.VIEWPORT_KEY.VIEW_MAIN),E=this._getEditorMaxSize(t,i,c),{height:w,width:O,scaleAdjust:M}=E;let P=e,A=b==null?void 0:b.getScrollBar();P>w?(A==null?b&&new R.ScrollBar(b,{enableHorizontal:!1,barSize:8}):b==null||b.resetCanvasSizeAndUpdateScroll(),b==null||b.scrollToViewportPos({viewportScrollY:P-w}),P=w):(A=null,(V=b==null?void 0:b.getScrollBar())==null||V.dispose()),r+=(A==null?void 0:A.barSize)||0,r>O&&(r=O),this._addBackground(p,r/s,e/l,o);const{scaleX:k,scaleY:N}=p.getPrecisionScale();p.transformByState({width:r*M/s,height:e*M/l,scaleX:s*M,scaleY:l*M}),v.resize(r*M/s,e*M/l),setTimeout(()=>{C.resizeBySize(R.fixLineWidthByScale(r,k),R.fixLineWidthByScale(P,N)),d==null||d()},0);const H=this._layoutService.getContentElement().getBoundingClientRect(),x=g.getBoundingClientRect();S=S*M+(x.left-H.left),f=f*M+(x.top-H.top);const L=t.endX-t.startX;c===a.HorizontalAlign.RIGHT?S+=(L-r)*M:c===a.HorizontalAlign.CENTER&&(S+=(L-r*M)/2),this._cellEditorManagerService.setState({startX:S,startY:f,endX:r*M+S,endY:P*M+f,show:!0})}_addBackground(r,e,t,i){const o="_backgroundRectHelperColor_",s=r.getObject(o);s==null&&i==null||(s==null?r.addObjects([new R.Rect(o,{width:e,height:t,fill:i,evented:!1})],q.DOCS_COMPONENT_MAIN_LAYER_INDEX):i==null?s.dispose():(s.setProps({fill:i}),s.transformByState({width:e,height:t})))}resizeCellEditor(r){var M,P;const e=this._cellEditorManagerService.getState();if(!e||!this._editorBridgeService.isVisible().visible)return;this._editorBridgeService.refreshEditCellPosition(!0);const t=this._editorBridgeService.getEditCellState();if(!t)return;const i=(P=(M=this._sheetSkeletonManagerService)==null?void 0:M.getSkeletonParam(t.sheetId))==null?void 0:P.skeleton;if(!i)return;const{row:o,column:s,scaleX:l,scaleY:c,position:d,canvasOffset:u,documentLayoutObject:h}=t,{horizontalAlign:g}=h,S=this._getEditorMaxSize(d,u,g);if(!S)return;const{height:f,width:v,scaleAdjust:p}=S,C=i.getCellWithCoordByIndex(o,s),b=Math.min((C.mergeInfo.endY-C.mergeInfo.startY)*c,f)*p,E=Math.min((C.mergeInfo.endX-C.mergeInfo.startX)*l,v)*p,w=e.endY-e.startY,O=e.endX-e.startX;if(w!==b||O!==E){if(this._editorBridgeService.refreshEditCellPosition(!0),!this._getEditorSkeleton())return;this.fitTextSize(r)}}_getEditorObject(){return Ai(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}_getEditorSkeleton(){var r;return(r=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:r.with(_e.DocSkeletonManagerService).getSkeleton()}},y.SheetCellEditorResizeService=eh([ln(0,_.ILayoutService),ln(1,Xn),ln(2,me),ln(3,R.IRenderManagerService),ln(4,a.IUniverInstanceService),ln(5,a.IConfigService)],y.SheetCellEditorResizeService);const Zi={id:"sheet.operation.set-activate-cell-edit",type:a.CommandType.OPERATION,handler:(n,r)=>(n.get(me).setEditCell(r),!0)};var th=Object.getOwnPropertyDescriptor,nh=(n,r,e,t)=>{for(var i=t>1?void 0:t?th(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},Rt=(n,r)=>(e,t)=>r(e,t,n);let Ki=class extends a.RxDisposable{constructor(r,e,t,i,o,s,l,c){super();T(this,"_d");this._context=r,this._instanceSrv=e,this._commandService=t,this._editorBridgeService=i,this._selectionManagerService=o,this._contextService=s,this._renderManagerService=l,this._sheetSkeletonManagerService=c,this.disposeWithMe(this._instanceSrv.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(d=>{d&&d.getUnitId()===this._context.unitId?this._d=this._init():this._disposeCurrent()}))}_init(){const r=new a.DisposableCollection;return this._initSelectionChangeListener(r),this._initEventListener(r),this._commandExecutedListener(r),this._initialKeyboardListener(r),r}_disposeCurrent(){var r;(r=this._d)==null||r.dispose(),this._d=null}_initSelectionChangeListener(r){r.add(D.merge(this._selectionManagerService.selectionMoveEnd$,this._selectionManagerService.selectionSet$,this._selectionManagerService.selectionMoveStart$).subscribe(e=>this._updateEditorPosition(e)))}_updateEditorPosition(r){var t,i,o;if(this._editorBridgeService.isVisible().visible)return;const e=(t=r==null?void 0:r[r.length-1])==null?void 0:t.primary;if(e){const s=this._getSheetObject(),{scene:l,engine:c}=s,d=this._context.unitId,u=(i=this._context.unit.getActiveSheet())==null?void 0:i.getSheetId();if(!u)return;const h=(o=this._sheetSkeletonManagerService.getSkeletonParam(u))==null?void 0:o.skeleton.getCellWithCoordByIndex(e.actualRow,e.actualColumn),g=h?{actualRow:h.actualRow,actualColumn:h.actualColumn,isMerged:h.isMerged,startRow:h.mergeInfo.startRow,startColumn:h.mergeInfo.startColumn,endRow:h.mergeInfo.endRow,endColumn:h.mergeInfo.endColumn,isMergedMainCell:h.isMergedMainCell}:e;this._commandService.executeCommand(Zi.id,{scene:l,engine:c,primary:g,unitId:d,sheetId:u})}}refreshEditorPosition(){const r=this._selectionManagerService.getWorkbookSelections(this._context.unitId);if(r){const e=r.getCurrentSelections();e&&this._updateEditorPosition([...e])}}_initEventListener(r){const e=this._getSheetObject(),{spreadsheet:t,spreadsheetColumnHeader:i,spreadsheetLeftTopPlaceholder:o,spreadsheetRowHeader:s}=e;r.add(t.onDblclick$.subscribeEvent(l=>{l.button!==2&&this._commandService.executeCommand(ge.id,{visible:!0,eventType:R.DeviceInputEventType.Dblclick,unitId:this._context.unitId})})),r.add(t.onPointerDown$.subscribeEvent({next:this._tryHideEditor.bind(this),priority:-1})),r.add(i.onPointerDown$.subscribeEvent({next:this._tryHideEditor.bind(this),priority:-1})),r.add(o.onPointerDown$.subscribeEvent({next:this._tryHideEditor.bind(this),priority:-1})),r.add(s.onPointerDown$.subscribeEvent({next:this._tryHideEditor.bind(this),priority:-1}))}_initialKeyboardListener(r){let e=null;const t=o=>{const s=o.with(q.DocSelectionRenderService);s&&(e=a.toDisposable(s.onInputBefore$.subscribe(l=>{if(!this._isCurrentSheetFocused())return;const c=this._contextService.getContextValue(a.FOCUSING_FX_BAR_EDITOR),d=this._contextService.getContextValue(a.FOCUSING_SHEET),u=o.unitId;this._editorBridgeService.isVisible().visible||u&&d&&!c&&this._showEditorByKeyboard(l)})),r.add(e))},i=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);i?t(i):this.disposeWithMe(this._renderManagerService.created$.pipe(D.filter(o=>o.unitId===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)).subscribe(o=>{e==null||e.dispose(),t(o)}))}_commandExecutedListener(r){const e=new Set([m.ClearSelectionFormatCommand.id,en.id]);r.add(this._commandService.onCommandExecuted(t=>{if(e.has(t.id)){if(this._editorBridgeService.isVisible().visible)return;this._editorBridgeService.refreshEditCellState()}if(t.id===m.SetRangeValuesMutation.id){const i=t.params,{cellValue:o,unitId:s,subUnitId:l}=i;if(!o)return;const c=this._editorBridgeService.getEditLocation();if(c){const{unitId:d,sheetId:u,row:h,column:g}=c;s===d&&l===u&&o&&o[h]&&Object.prototype.hasOwnProperty.call(o[h],g)&&this._editorBridgeService.refreshEditCellState()}}})),r.add(this._commandService.beforeCommandExecuted((t,i)=>{i!=null&&i.fromCollab||t.id===m.SetWorksheetActiveOperation.id&&this._tryHideEditor()}))}_showEditorByKeyboard(r){const e=r==null?void 0:r.event;r==null||!e.data&&e.inputType!=="InsertParagraph"||this._commandService.syncExecuteCommand(ge.id,{visible:!0,eventType:R.DeviceInputEventType.Keyboard,keycode:e.which,unitId:this._context.unitId})}_tryHideEditor(){this._editorBridgeService.isForceKeepVisible()||this._hideEditor()}_hideEditor(){this._editorBridgeService.isVisible().visible===!0&&this._commandService.syncExecuteCommand(ge.id,{visible:!1,eventType:R.DeviceInputEventType.PointerDown,unitId:this._context.unitId})}_getSheetObject(){return Ne(this._context.unit,this._context)}_isCurrentSheetFocused(){var r;return((r=this._instanceSrv.getFocusedUnit())==null?void 0:r.getUnitId())===this._context.unitId}};Ki=nh([Rt(1,a.IUniverInstanceService),Rt(2,a.ICommandService),Rt(3,me),Rt(4,a.Inject(m.SheetsSelectionsService)),Rt(5,a.IContextService),Rt(6,R.IRenderManagerService),Rt(7,a.Inject(y.SheetSkeletonManagerService))],Ki);function lo(n){return n.getContextValue(a.FOCUSING_SHEET)}function le(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function _a(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function ih(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function co(n){return n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function qi(n){return n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function rh(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.EDITOR_ACTIVATED)&&n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function cn(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&!n.getContextValue(a.FOCUSING_EDITOR_STANDALONE)}const Ia=[_.KeyCode.ARROW_DOWN,_.KeyCode.ARROW_UP,_.KeyCode.ARROW_LEFT,_.KeyCode.ARROW_RIGHT],oh=[_.KeyCode.ENTER,_.KeyCode.TAB,...Ia];function ba(){const n=[];for(const r of Ia)n.push({id:wt.id,binding:r,preconditions:e=>cn(e),staticParameters:{visible:!1,eventType:R.DeviceInputEventType.Keyboard,keycode:r,isShift:!1}}),n.push({id:wt.id,binding:r|_.MetaKeys.SHIFT,preconditions:e=>cn(e),staticParameters:{visible:!1,eventType:R.DeviceInputEventType.Keyboard,keycode:r,isShift:!0}});return n}const wa={id:xn.id,binding:_.KeyCode.F2,description:"shortcut.sheet.start-editing",group:"4_sheet-edit",preconditions:le,staticParameters:{visible:!0,eventType:R.DeviceInputEventType.Keyboard,keycode:_.KeyCode.F2}},Ea={id:ge.id,binding:_.KeyCode.ENTER,description:"shortcut.sheet.toggle-editing",group:"4_sheet-edit",preconditions:n=>cn(n),staticParameters:{visible:!1,eventType:R.DeviceInputEventType.Keyboard,keycode:_.KeyCode.ENTER}},Ta={id:ge.id,binding:_.KeyCode.TAB,preconditions:n=>cn(n),staticParameters:{visible:!1,eventType:R.DeviceInputEventType.Keyboard,keycode:_.KeyCode.TAB}},ya={id:ge.id,binding:_.KeyCode.ESC,description:"shortcut.sheet.abort-editing",group:"4_sheet-edit",preconditions:n=>cn(n),staticParameters:{visible:!1,eventType:R.DeviceInputEventType.Keyboard,keycode:_.KeyCode.ESC}},sh={id:ge.id,binding:_.KeyCode.ENTER|_.MetaKeys.CTRL_COMMAND,mac:_.KeyCode.ENTER|_.MetaKeys.MAC_CTRL,preconditions:n=>cn(n),staticParameters:{visible:!1,eventType:R.DeviceInputEventType.Keyboard,keycode:_.KeyCode.ENTER|_.MetaKeys.CTRL_COMMAND}},Ra={id:q.BreakLineCommand.id,description:"shortcut.sheet.break-line",group:"4_sheet-edit",preconditions:n=>ih(n),binding:_.KeyCode.ENTER|_.MetaKeys.ALT},Ma={id:q.DeleteLeftCommand.id,preconditions:n=>co(n)||qi(n),binding:_.KeyCode.BACKSPACE},ah={id:q.DeleteRightCommand.id,preconditions:n=>co(n)||qi(n),binding:_.KeyCode.DELETE},lh={id:q.DeleteLeftCommand.id,preconditions:n=>co(n)||qi(n),binding:_.KeyCode.BACKSPACE|_.MetaKeys.SHIFT},Pa={id:ge.id,description:"shortcut.sheet.delete-and-start-editing",group:"4_sheet-edit",preconditions:n=>le(n)&&!qi(n),binding:_.KeyCode.BACKSPACE,staticParameters:{visible:!0,eventType:R.DeviceInputEventType.Keyboard,keycode:_.KeyCode.BACKSPACE}};function ch(n){return n.startsWith("'")}function dh(n){return n.slice(1)}const uh={"0":"0","1":"1","2":"2","3":"3","4":"4","5":"5","6":"6","7":"7","8":"8","9":"9",A:"A",B:"B",C:"C",D:"D",E:"E",F:"F",G:"G",H:"H",I:"I",J:"J",K:"K",L:"L",M:"M",N:"N",O:"O",P:"P",Q:"Q",R:"R",S:"S",T:"T",U:"U",V:"V",W:"W",X:"X",Y:"Y",Z:"Z",a:"a",b:"b",c:"c",d:"d",e:"e",f:"f",g:"g",h:"h",i:"i",j:"j",k:"k",l:"l",m:"m",n:"n",o:"o",p:"p",q:"q",r:"r",s:"s",t:"t",u:"u",v:"v",w:"w",x:"x",y:"y",z:"z","%":"%","-":"-",".":".",":":":","/":"/","+":"+","@":"@","&":"&","*":"*","#":"#","=":"=",">":">","<":"<","$":"$",""":'"',"'":"'","(":"(",")":")"," ":" ",",":",","!":"!","?":"?",";":";","[":"[","]":"]","{":"{","}":"}"},uo={true:"TRUE",false:"FALSE"};function hh(n){return[a.LocaleType.ZH_CN,a.LocaleType.ZH_TW].includes(n)}function mh(n,r,e,t){let i=n;if(hh(e)){if(n.startsWith("'")||n.startsWith("'"))return`'${n.slice(1)}`;i=gh(i)}if(i.startsWith("="))return Sh(n,i,r,t);const o=i.toLowerCase();return uo[o]?uo[o]:a.numfmt.parseValue(i)==null?n:i}function gh(n){const r=/['"].*?['"]/g,e=[],t=n.split(r);n.replace(r,o=>(e.push(o),""));let i=t.join("").split("").map(ph).join("");return e.forEach((o,s)=>{i=i.slice(0,s*2)+o+i.slice((s+1)*2)}),i}function Sh(n,r,e,t){const i=e.sequenceNodesBuilder(r);if(!i)return n;let o=r,s=0;return i.forEach((l,c)=>{if(typeof l=="object"){const d=l.token;if(uo[d.toLowerCase()]){const u=l.startIndex+s+1,h=l.endIndex+s+2;o=dn(d.toLocaleUpperCase(),o,u,h)}else if(l.nodeType===K.sequenceNodeType.FUNCTION&&fh(d,t,i,c)||l.nodeType===K.sequenceNodeType.REFERENCE){const u=d.indexOf("!");if(u>-1){const h=d.substring(u+1),g=l.startIndex+s+(u+1)+1,S=l.endIndex+s+2;o=dn(h.toLocaleUpperCase(),o,g,S)}else{const h=l.startIndex+s+1,g=l.endIndex+s+2;o=dn(d.toLocaleUpperCase(),o,h,g)}}else if(d.startsWith('"')&&d.endsWith('"')||d.startsWith("'")&&d.endsWith("'")){const u=l.startIndex+s+2,h=l.endIndex+s+1;o=dn(n.slice(u,h),o,u,h)}else if(l.nodeType!==K.sequenceNodeType.ARRAY){const u=a.numfmt.parseValue(d);if(u==null){const h=l.startIndex+s+1,g=l.endIndex+s+2;o=dn(n.slice(h,g),o,h,g)}else if(typeof u.v=="number"&&(u.z===void 0||!a.numfmt.getFormatInfo(u.z).isDate)){const h=`${u.v}`,g=l.startIndex+s+1,S=l.endIndex+s+2,{processedString:f,offset:v}=Ch(d,h);o=dn(f,o,g,S),s+=v}}}}),o}function fh(n,r,e,t){const i=r.getDescriptions();return e[t+1]!==K.matchToken.OPEN_BRACKET?!1:i.get(vh(n).toLocaleUpperCase())!==void 0}function vh(n){const r=/^@+/;return n.replace(r,"")}function ph(n){return uh[n]||n}function dn(n,r,e,t){return r.substring(0,e)+n+r.substring(t)}function Ch(n,r){var s,l;const e=((s=n.match(/^\s*/))==null?void 0:s[0])||"",t=((l=n.match(/\s*$/))==null?void 0:l[0])||"",i=e+r+t,o=i.length-n.length;return{processedString:i,offset:o}}const Oa="range_selector",Aa=n=>n.includes(Oa);var _h=Object.getOwnPropertyDescriptor,Ih=(n,r,e,t)=>{for(var i=t>1?void 0:t?_h(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},ye=(n,r)=>(e,t)=>r(e,t,n);const Da=-1e3;y.EditingRenderController=class extends a.Disposable{constructor(e,t,i,o,s,l,c,d,u,h,g,S,f,v,p){super();T(this,"_cursorChange",0);T(this,"_editingUnit","");T(this,"_cursorTimeout");this._undoRedoService=e,this._contextService=t,this._renderManagerService=i,this._editorBridgeService=o,this._cellEditorManagerService=s,this._lexerTreeBuilder=l,this._functionService=c,this._textSelectionManagerService=d,this._commandService=u,this._localService=h,this._editorService=g,this._univerInstanceService=S,this._sheetInterceptorService=f,this._sheetCellEditorResizeService=v,this._selectionManagerService=p,this.disposeWithMe(this._init()),this._initEditorVisibilityListener()}dispose(){super.dispose()}get _workbookSelections(){return this._selectionManagerService.getWorkbookSelections(this._editingUnit)}_init(){const e=new a.DisposableCollection;return this._subscribeToCurrentCell(e),this._initialCursorSync(e),this._listenEditorFocus(e),this._commandExecutedListener(e),this._initSkeletonListener(e),e.add(()=>{clearTimeout(this._cursorTimeout)}),this._cursorTimeout=setTimeout(()=>{this._cursorStateListener(e)},1e3),e}_initEditorVisibilityListener(){this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(async e=>{var t;if(this._editingUnit&&(e==null?void 0:e.getUnitId())!==this._editingUnit&&!this._editorBridgeService.isForceKeepVisible()){this._commandService.syncExecuteCommand(ge.id,{visible:!1,eventType:R.DeviceInputEventType.Keyboard,keycode:_.KeyCode.ESC,unitId:this._editingUnit});const i=(t=this._renderManagerService.getRenderById(e.getUnitId()))==null?void 0:t.with(Ki);i&&i.refreshEditorPosition()}})),this.disposeWithMe(this._editorBridgeService.visible$.pipe(D.distinctUntilChanged((e,t)=>e.visible===t.visible)).subscribe(async e=>{e.visible?(this._editingUnit=e.unitId,this._handleEditorVisible(e)):this._editingUnit&&(await this._handleEditorInvisible(e),this._editingUnit="")}))}_listenEditorFocus(e){const t=this._getEditorObject();t&&e.add(t.document.onPointerDown$.subscribeEvent(()=>{var i;if(this._editingUnit&&this._editorBridgeService.isVisible()){const o=this._editorBridgeService.getEditCellState(),s=this._editorBridgeService.getCurrentEditorId();if(!o||!s)return;(i=this._sheetCellEditorResizeService)==null||i.fitTextSize()}}))}_initialCursorSync(e){e.add(this._cellEditorManagerService.focus$.pipe(D.filter(t=>!!t)).subscribe(()=>{var o;const t=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(!t)return;const i=(o=this._renderManagerService.getRenderById(t==null?void 0:t.getUnitId()))==null?void 0:o.with(q.DocSelectionRenderService);i&&i.sync()}))}_initSkeletonListener(e){const t=new Set(m.COMMAND_LISTENER_SKELETON_CHANGE);t.delete(m.SetWorksheetActiveOperation.id),e.add(this._commandService.onCommandExecuted(i=>{var o;if(t.has(i.id)){switch(i.id){case m.MoveRowsMutation.id:case m.MoveColsMutation.id:case m.RemoveColMutation.id:case m.RemoveRowMutation.id:case m.InsertColMutation.id:case m.InsertRowMutation.id:{const s=this._editorBridgeService.getEditLocation();if(!s)break;const l={startRow:s.row,startColumn:s.column,endRow:s.row,endColumn:s.column},c=m.adjustRangeOnMutation(l,i);if(!c)break;const d=c.startRow,u=c.startColumn;this._editorBridgeService.updateEditLocation(d,u);break}}(o=this._sheetCellEditorResizeService)==null||o.resizeCellEditor(()=>{this._textSelectionManagerService.refreshSelection({unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})})}}))}_subscribeToCurrentCell(e){e.add(this._editorBridgeService.currentEditCellState$.subscribe(t=>{var b,E;if(t==null||this._editorBridgeService.isForceKeepVisible())return;const i=this._editorBridgeService.getEditCellState();if(i==null)return;const{position:o,documentLayoutObject:s,scaleX:l,editorUnitId:c}=i;if(this._contextService.getContextValue(a.FOCUSING_EDITOR_STANDALONE))return;const d=this._getDocumentDataModel();if(d==null)return;const{startX:u,endX:h}=o,{textRotation:g,wrapStrategy:S,documentModel:f}=s,{vertexAngle:v}=R.convertTextRotation(g);S===a.WrapStrategy.WRAP&&v===0&&d.updateDocumentDataPageSize((h-u)/l),this._commandService.syncExecuteCommand(q.ReplaceSnapshotCommand.id,{unitId:c,snapshot:f.getSnapshot()}),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!0),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});const p=(b=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:b.with(q.DocSelectionRenderService),C=(E=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:E.with(q.DocSelectionRenderService);(p!=null&&p.canFocusing||C!=null&&C.canFocusing)&&(this._univerInstanceService.setCurrentUnitForType(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),p==null||p.activate(Da,Da,!0))}))}_commandExecutedListener(e){e.add(this._commandService.onCommandExecuted(i=>{var o;if(i.id===_e.RichTextEditingMutation.id){const s=i.params,{unitId:l}=s;if(Aa(l)||(this._editorBridgeService.changeEditorDirty(!0),!this._editorBridgeService.isVisible().visible))return;l===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&((o=this._sheetCellEditorResizeService)==null||o.fitTextSize())}}));const t=[wt.id];e.add(this._commandService.onCommandExecuted(i=>{if(t.includes(i.id)){const o=i.params,{keycode:s,isShift:l}=o;if(s!=null&&(this._cursorChange===2||this._contextService.getContextValue(a.FOCUSING_FX_BAR_EDITOR))){this._moveInEditor(s,l);return}this._commandService.syncExecuteCommand(ge.id,o)}i.id===xn.id&&(this._cursorChange=2)}))}_handleEditorVisible(e){var f,v,p,C;const{eventType:t,keycode:i}=e;this._cursorChange=t===R.DeviceInputEventType.PointerDown||t===R.DeviceInputEventType.Dblclick?2:1;const o=this._editorBridgeService.getEditLocation();if(o==null)return;this._commandService.syncExecuteCommand($r.id,{range:{startRow:o.row,startColumn:o.column,endRow:o.row,endColumn:o.column}}),this._editorBridgeService.refreshEditCellPosition(!1);const{unitId:s,isInArrayFormulaRange:l=!1}=o,c=this._getEditorObject();if(c==null)return;const{document:d,scene:u}=c;this._contextService.setContextValue(a.EDITOR_ACTIVATED,!0);const h=this._getDocumentDataModel(),g=this._getEditorSkeleton(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(!g||!h)return;(f=this._sheetCellEditorResizeService)==null||f.fitTextSize(()=>{const b=u.getViewport(q.VIEWPORT_KEY.VIEW_MAIN);b==null||b.scrollToViewportPos({viewportScrollX:Number.POSITIVE_INFINITY,viewportScrollY:Number.POSITIVE_INFINITY})});const S=()=>{this._emptyDocumentDataModel(h.getSnapshot().documentStyle,!!l),d.makeDirty(),(i===_.KeyCode.BACKSPACE||t===R.DeviceInputEventType.Dblclick)&&(g.calculate(),this._editorBridgeService.changeEditorDirty(!0)),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})};if(this._isCellImageData(h.getSnapshot()))S();else if(t===R.DeviceInputEventType.Keyboard&&i===_.KeyCode.F2){d.makeDirty(),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}]);const b=((p=(v=h.getBody())==null?void 0:v.dataStream.length)!=null?p:2)-2;this._textSelectionManagerService.replaceDocRanges([{startOffset:b,endOffset:b}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})}else if(t===R.DeviceInputEventType.Keyboard||t===R.DeviceInputEventType.Dblclick&&l)S();else if(t===R.DeviceInputEventType.Dblclick){if(this._contextService.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA))return;const b=h.getBody().dataStream.length-2||0;this._textSelectionManagerService.replaceDocRanges([{startOffset:b,endOffset:b}])}(C=this._renderManagerService.getRenderById(s))==null||C.scene.resetCursor()}_refreshCurrentSelections(e){const t=this._workbookSelections.getSelectionsOfWorksheet(e);t&&(this._contextService.setContextValue(m.REF_SELECTIONS_ENABLED,!1),this._commandService.syncExecuteCommand(m.SetSelectionsOperation.id,{unitId:this._editingUnit,subUnitId:e,selections:t}))}async _handleEditorInvisible(e){var C,b;const t=this._editorBridgeService.getEditCellState(),i=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),o=a.Tools.deepClone(i==null?void 0:i.getSnapshot()),{keycode:s}=e;this._cursorChange=0;const l=(C=t==null?void 0:t.unitId)!=null?C:"";if(this._exitInput(e),t==null)return;const c=this._univerInstanceService.getUnit(l,a.UniverInstanceType.UNIVER_SHEET);if(!c)return;const d=c.getActiveSheet(),u=c.getUnitId(),h=d.getSheetId(),{unitId:g,sheetId:S}=t;if(u===g&&S!==h&&await this._commandService.executeCommand(m.SetWorksheetActivateCommand.id,{subUnitId:S,unitId:g}),this._editorBridgeService.getEditorDirty()===!1){this._editorBridgeService.isForceKeepVisible()&&this._editorBridgeService.disableForceKeepVisible(),this._moveSelection(s,l,h);return}if(s===_.KeyCode.ESC){this._editorBridgeService.isForceKeepVisible()&&this._editorBridgeService.disableForceKeepVisible(),this._refreshCurrentSelections(S);return}const v=((b=o==null?void 0:o.body)==null?void 0:b.dataStream.length)===2,p=t.documentLayoutObject.documentModel?this._isCellImageData(t.documentLayoutObject.documentModel.getSnapshot()):!1;o&&!(v&&p)&&await this._submitEdit(o,s===(_.MetaKeys.CTRL_COMMAND|_.KeyCode.ENTER)||s===(_.MetaKeys.MAC_CTRL|_.KeyCode.ENTER))===!1||this._moveSelection(s,l,h)}_getEditorObject(){return Ai(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}_isCellImageData(e){var i,o;return((o=(i=e.drawingsOrder)==null?void 0:i.length)!=null?o:0)>0}submitCellData(e){return this._submitEdit(e.getSnapshot())}async _submitEdit(e,t=!1){var C;const i=this._editorBridgeService.getEditCellState();if(i==null)return!0;const{unitId:o,sheetId:s,row:l,column:c}=i,d=this._univerInstanceService.getUnit(o,a.UniverInstanceType.UNIVER_SHEET);if(!d)return!0;let u=d.getActiveSheet();if(!d.getSheetBySheetId(s))return!0;u=d.getActiveSheet();const g=bh({...u.getCellRaw(l,c)||{}},e,this._lexerTreeBuilder,this._localService,this._functionService,d.getStyles());if(!g)return!0;const S=this._sheetInterceptorService.onWriteCell(d,u,l,c,g);if(S===u.getCellRaw(l,c))return!0;const f=t?(C=this._workbookSelections.getCurrentLastSelection())==null?void 0:C.range:{startRow:l,startColumn:c,endRow:l,endColumn:c},v=a.generateRandomId(6);return this._commandService.syncExecuteCommand(m.SetRangeValuesCommand.id,{subUnitId:s,unitId:o,range:f,value:S,redoUndoId:v})&&await this._sheetInterceptorService.onValidateCell(d,u,l,c)===!1?(this._undoRedoService.rollback(v,o),!1):!0}_exitInput(e){var o;this._contextService.setContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA,!1),this._contextService.setContextValue(a.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!1),this._contextService.setContextValue(a.FOCUSING_FX_BAR_EDITOR,!1),this._cellEditorManagerService.setState({show:e.visible});const t=this._getEditorObject();(o=t==null?void 0:t.scene.getViewport(q.VIEWPORT_KEY.VIEW_MAIN))==null||o.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});const i=this._editorBridgeService.getCurrentEditorId();i==null||!this._editorService.isSheetEditor(i)||(this._undoRedoService.clearUndoRedo(i),this._undoRedoService.clearUndoRedo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))}_moveSelection(e,t,i){if(e==null||!oh.includes(e)){this._refreshCurrentSelections(i);return}let o=a.Direction.LEFT;switch(e){case _.KeyCode.ENTER:o=a.Direction.DOWN;break;case _.KeyCode.TAB:o=a.Direction.RIGHT;break;case _.KeyCode.ARROW_DOWN:o=a.Direction.DOWN;break;case _.KeyCode.ARROW_UP:o=a.Direction.UP;break;case _.KeyCode.ARROW_LEFT:o=a.Direction.LEFT;break;case _.KeyCode.ARROW_RIGHT:o=a.Direction.RIGHT;break}const s=this._univerInstanceService.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET);t&&(s==null?void 0:s.getUnitId())!==t&&this._univerInstanceService.setCurrentUnitForType(t),e===_.KeyCode.ENTER||e===_.KeyCode.TAB?this._commandService.executeCommand(Ye.id,{keycode:e,direction:o}):this._commandService.executeCommand(Re.id,{direction:o})}_cursorStateListener(e){const t=this._getEditorObject();if(!(t!=null&&t.document))return;const{document:i}=t;e.add(a.toDisposable(i.onPointerDown$.subscribeEvent(()=>{this._cursorChange===1&&(this._cursorChange=2)})))}_moveInEditor(e,t){let i=a.Direction.LEFT;e===_.KeyCode.ARROW_DOWN?i=a.Direction.DOWN:e===_.KeyCode.ARROW_UP?i=a.Direction.UP:e===_.KeyCode.ARROW_RIGHT&&(i=a.Direction.RIGHT),t?this._commandService.executeCommand(q.MoveSelectionOperation.id,{direction:i}):this._commandService.executeCommand(q.MoveCursorOperation.id,{direction:i})}_getDocumentDataModel(){return this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC)}_getEditorSkeleton(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(_e.DocSkeletonManagerService).getSkeleton()}_getEditorViewModel(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(_e.DocSkeletonManagerService).getViewModel()}_getEditingUnit(){return this._editingUnit?this._univerInstanceService.getUnit(this._editingUnit,a.UniverInstanceType.UNIVER_SHEET):null}_emptyDocumentDataModel(e,t){const i=(l,c)=>{const d=a.Tools.deepClone(l.getSnapshot()),u=this._getEditorViewModel(l.getUnitId());u!=null&&(wh(d.body,t),c&&(d.documentStyle=e),d.drawings={},d.drawingsOrder=[],l.reset(d),u.reset(l))},o=this._getDocumentDataModel();o&&i(o,!0);const s=this._univerInstanceService.getUnit(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);s&&i(s)}},y.EditingRenderController=Ih([ye(0,a.IUndoRedoService),ye(1,a.IContextService),ye(2,R.IRenderManagerService),ye(3,me),ye(4,Xn),ye(5,a.Inject(K.LexerTreeBuilder)),ye(6,K.IFunctionService),ye(7,a.Inject(_e.DocSelectionManagerService)),ye(8,a.ICommandService),ye(9,a.Inject(a.LocaleService)),ye(10,q.IEditorService),ye(11,a.IUniverInstanceService),ye(12,a.Inject(m.SheetInterceptorService)),ye(13,a.Inject(y.SheetCellEditorResizeService)),ye(14,a.Inject(m.SheetsSelectionsService))],y.EditingRenderController);function bh(n,r,e,t,i,o){var h,g,S;if((r==null?void 0:r.body)==null)return null;const{body:s}=r;n.t=void 0;const l=s.dataStream;let d=l.substring(l.length-2,l.length)===a.DEFAULT_EMPTY_DOCUMENT_VALUE?l.substring(0,l.length-2):l;const u=t.getCurrentLocale();if(d=mh(d,e,u,i),(h=r.drawingsOrder)!=null&&h.length)n.v="",n.f=null,n.si=null,n.p=r,n.t=a.CellValueType.STRING;else if(n.s&&Oi.isTextFormat((S=(g=o==null?void 0:o.get(n.s))==null?void 0:g.n)==null?void 0:S.pattern)){n.v=d,n.f=null,n.si=null,n.p=null,n.t=a.CellValueType.STRING,ho(s)&&s.dataStream!==`\r
|
|
1
|
+
(function(y,q){typeof exports=="object"&&typeof module<"u"?q(exports,require("@univerjs/docs-ui"),require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("react"),require("rxjs"),require("@univerjs/sheets"),require("@univerjs/docs"),require("@univerjs/engine-formula"),require("@univerjs/engine-numfmt"),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/engine-render","@univerjs/ui","react","rxjs","@univerjs/sheets","@univerjs/docs","@univerjs/engine-formula","@univerjs/engine-numfmt","react/jsx-runtime","@univerjs/design","rxjs/operators","@univerjs/telemetry"],q):(y=typeof globalThis<"u"?globalThis:y||self,q(y.UniverSheetsUi={},y.UniverDocsUi,y.UniverCore,y.UniverEngineRender,y.UniverUi,y.React,y.rxjs,y.UniverSheets,y.UniverDocs,y.UniverEngineFormula,y.UniverEngineNumfmt,y.React,y.UniverDesign,y.rxjs.operators,y.UniverTelemetry))})(this,function(y,q,a,R,_,W,D,m,_e,K,Oi,I,X,de,Jc){"use strict";var lp=Object.defineProperty;var cp=(y,q,a)=>q in y?lp(y,q,{enumerable:!0,configurable:!0,writable:!0,value:a}):y[q]=a;var T=(y,q,a)=>cp(y,typeof q!="symbol"?q+"":q,a);function Ai(n,r){if(n==null)return;const e=r.getRenderById(n);if(e==null)return;const{mainComponent:t,scene:i,engine:o,components:s}=e,l=t,c=s.get(q.DOCS_VIEW_KEY.BACKGROUND);return{document:l,docBackground:c,scene:i,engine:o}}const Hr=[10,400],Vr="RANGE_SELECTOR_COMPONENT_KEY",Di="EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY";var he=(n=>(n.MAIN="__SpreadsheetRender__",n.ROW="__SpreadsheetRowHeader__",n.COLUMN="__SpreadsheetColumnHeader__",n.LEFT_TOP="__SpreadsheetLeftTopPlaceholder__",n))(he||{});const ys=0,ki=1,st=10,$c=11,Rs=12,Ni={id:"sheet.command.set-row-header-width",type:a.CommandType.COMMAND,handler:async(n,r)=>{if(!r)return!1;const e=n.get(R.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:i,size:o}=r,s=e.getRenderById(t);if(s){e.getRenderById(t).with(y.SheetSkeletonManagerService).setRowHeaderSize(s,i,o);const{components:c}=s,d=c.get(he.ROW);d&&d.setCustomHeader({headerStyle:{size:o}})}return!0}},Hi={id:"sheet.command.set-col-header-height",type:a.CommandType.COMMAND,handler:async(n,r)=>{if(!r)return!1;const e=n.get(R.IRenderManagerService);if(!e)return!1;const{unitId:t,subUnitId:i,size:o}=r,s=e.getRenderById(t);if(s){e.getRenderById(t).with(y.SheetSkeletonManagerService).setColumnHeaderSize(s,i,o);const{components:c}=s,d=c.get(he.COLUMN);d&&d.setCustomHeader({headerStyle:{size:o}})}return!0}},Wr=a.createInterceptorKey("rangeMovePermissionCheck"),xr=a.createInterceptorKey("rangeFillPermissionCheck");var Lr=(n=>(n[n.FORMULA_EDITOR_SHOW=100]="FORMULA_EDITOR_SHOW",n[n.MARK_SELECTION=1e4]="MARK_SELECTION",n))(Lr||{});function at(n){const r=n.getColorFromTheme("primary.600"),e=n.getColorFromTheme("white"),t=new a.ColorKit(r).setAlpha(.07).toRgbString();return{strokeWidth:1,stroke:r,fill:t,widgets:{},widgetSize:6,widgetStrokeWidth:1,widgetStroke:e,autofillSize:6,autofillStrokeWidth:1,autofillStroke:e,rowHeaderFill:t,rowHeaderStroke:r,rowHeaderStrokeWidth:1,columnHeaderFill:t,columnHeaderStroke:r,columnHeaderStrokeWidth:1,expandCornerSize:40}}class ed{constructor(){T(this,"_startColumn",-1);T(this,"_startRow",-1);T(this,"_endColumn",-1);T(this,"_endRow",-1);T(this,"_startX",0);T(this,"_startY",0);T(this,"_endX",0);T(this,"_endY",0);T(this,"_primary");T(this,"_rangeType",a.RANGE_TYPE.NORMAL)}get startColumn(){return this._startColumn}get startRow(){return this._startRow}get endColumn(){return this._endColumn}get endRow(){return this._endRow}get startX(){return this._startX}get startY(){return this._startY}get endX(){return this._endX}get endY(){return this._endY}get currentCell(){return this._primary}get rangeType(){return this._rangeType}isEqual(r){const{startColumn:e,startRow:t,endColumn:i,endRow:o}=this,{startColumn:s,startRow:l,endColumn:c,endRow:d}=r;return e===s&&t===l&&i===c&&o===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(r){this._rangeType=r}getValue(){return{rangeWithCoord:this.getRange(),primaryWithCoord:this._primary}}setValue(r,e){const{startColumn:t,startRow:i,endColumn:o,endRow:s,startX:l,startY:c,endX:d,endY:u,rangeType:h}=r;this._startColumn=t,this._startRow=i,this._endColumn=o,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(r){this._primary=r}clearCurrentCell(){this._primary=null}}function Gt(n,r){const{startRow:e,startColumn:t,endRow:i,endColumn:o,rangeType:s}=r,l=i<e?i:e,c=i<e?e:i,d=o<t?o:t,u=o<t?t:o,h=n.getNoMergeCellWithCoordByIndex(l,d),g=n.getNoMergeCellWithCoordByIndex(c,u);return{startRow:e,startColumn:t,endRow:i,endColumn:o,rangeType:s,startY:(h==null?void 0:h.startY)||0,endY:(g==null?void 0:g.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(g==null?void 0:g.endX)||0}}function Te(n,r){const{range:e,primary:t,style:i}=n,o=Gt(r,e),s=t&&Dn(r,t);return{rangeWithCoord:o,primaryWithCoord:s,style:i}}function Dn(n,r){const{actualRow:e,actualColumn:t,isMerged:i,isMergedMainCell:o,startRow:s,startColumn:l,endRow:c,endColumn:d}=r,u=n.getNoMergeCellWithCoordByIndex(e,t),h=n.getNoMergeCellWithCoordByIndex(s,l),g=n.getNoMergeCellWithCoordByIndex(c,d);return{actualRow:e,actualColumn:t,isMerged:i,isMergedMainCell:o,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 Ms="__SpreadsheetHelperSelectionTempRect",td=35;class Ps{constructor(r,e){T(this,"_startOffsetX",0);T(this,"_startOffsetY",0);T(this,"_relativeSelectionPositionRow",0);T(this,"_relativeSelectionPositionColumn",0);T(this,"_relativeSelectionRowLength",0);T(this,"_relativeSelectionColumnLength",0);T(this,"_scenePointerMoveSub");T(this,"_scenePointerUpSub");T(this,"_disabled",!1);T(this,"_helperSelection");T(this,"_scrollTimer");T(this,"_activeViewport");T(this,"_targetSelection",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});T(this,"_isInMergeState",!1);T(this,"_fillControlColors",[]);T(this,"_skeleton");T(this,"_scene");T(this,"_themeService");T(this,"_injector");T(this,"_selectionHooks");this._control=r,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 r,e;(r=this._scrollTimer)==null||r.dispose(),this._fillControlColors=[],this._clearObserverEvent(),(e=this._helperSelection)==null||e.dispose()}setDisabled(r){this._disabled=r}_getFreeze(){var e,t;return(t=(e=R.withCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET,y.SheetSkeletonManagerService,this._injector.get(a.IUniverInstanceService),this._injector.get(R.IRenderManagerService)))==null?void 0:e.getCurrentParam())==null?void 0:t.skeleton.getWorksheetConfig().freeze}_isSelectionInViewport(r,e){const t=this._getFreeze()||{startRow:-1,startColumn:-1};switch(e.viewportKey){case R.SHEET_VIEWPORT_KEY.VIEW_MAIN:return r.endRow>=t.startRow&&r.endColumn>=t.startColumn;case R.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP:case R.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT:return r.endColumn>=t.startColumn&&r.startRow<t.startRow;case R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT:case R.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM:return r.endRow>=t.startRow&&r.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 r.startRow<t.startRow&&r.startColumn<t.startColumn}}_clearObserverEvent(){var r,e;(r=this._scenePointerMoveSub)==null||r.unsubscribe(),(e=this._scenePointerUpSub)==null||e.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null}_initialControl(){const{leftControl:r,rightControl:e,topControl:t,bottomControl:i}=this._control;[r,e,t,i].forEach(o=>{o.onPointerEnter$.subscribeEvent(()=>{var l;((l=this._injector.get(ve,a.Quantity.OPTIONAL))==null?void 0:l.interceptor.fetchThroughInterceptors(Wr)(!1,null))!==!1&&o.setCursor(R.CURSOR_TYPE.MOVE)}),o.onPointerLeave$.subscribeEvent(()=>{o.resetCursor()}),o.onPointerDown$.subscribeEvent(this._controlPointerDownHandler.bind(this))})}_controlMoving(r,e){var k;const t=this._scene,i=t.getScrollXYInfoByViewport(R.Vector2.FromArray([r,e])),{scaleX:o,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(r,e,o,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=Te({range:{startRow:g,endRow:S,startColumn:f,endColumn:v},primary:p,style:null},this._skeleton),E=this._skeleton.getNoMergeCellWithCoordByIndex(g,f),w=this._skeleton.getNoMergeCellWithCoordByIndex(S,v),O=(E==null?void 0:E.startY)||0,M=(w==null?void 0:w.endY)||0,P=(E==null?void 0:E.startX)||0,A=(w==null?void 0:w.endX)||0;(k=this._helperSelection)==null||k.transformByState({left:P,top:O,width:A-P,height:M-O}),this._targetSelection={...b.rangeWithCoord},this._control.selectionMoving$.next(b.rangeWithCoord)}_controlPointerDownHandler(r){const{offsetX:e,offsetY:t}=r,i=this._scene,o=i.getCoordRelativeToViewport(R.Vector2.FromArray([e,t])),{x:s,y:l}=o,c=i.getScrollXYInfoByViewport(o),{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,E=0;g<f?b-=1:g>p&&(b+=1),S<v?E-=1:S>C&&(E+=1),this._relativeSelectionPositionRow=f-g+b,this._relativeSelectionPositionColumn=v-S+E,this._relativeSelectionRowLength=p-f,this._relativeSelectionColumnLength=C-v;const w=this._control.currentStyle,O=this._getScale();this.isHelperSelection&&(this._helperSelection=new R.Rect(Ms,{stroke:w.stroke,strokeWidth:w.strokeWidth/O}),i.addObject(this._helperSelection));const M=i.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN),P=R.ScrollTimer.create(i);this._scrollTimer=P,P.startScroll(s,l,M),i.disableObjectsEvent(),this._scenePointerMoveSub=i.onPointerMove$.subscribeEvent(A=>{var V;if(this._disabled)return;const{offsetX:k,offsetY:N}=A;if(((V=this._injector.get(ve,a.Quantity.OPTIONAL))==null?void 0:V.interceptor.fetchThroughInterceptors(Wr)(!1,null))===!1)return;const{x,y:L}=i.getCoordRelativeToViewport(R.Vector2.FromArray([k,N]));this._controlMoving(x,L),i.setCursor(R.CURSOR_TYPE.MOVE),P.scrolling(x,L,()=>{this._controlMoving(x,L)})}),this._scenePointerUpSub=i.onPointerUp$.subscribeEvent(()=>{var k,N,H,x;(k=this._helperSelection)==null||k.dispose();const A=this._scene;A.resetCursor(),this._clearObserverEvent(),A.enableObjectsEvent(),(N=this._scrollTimer)==null||N.dispose(),this._control.selectionMoveEnd$.next(this._targetSelection),(x=(H=this._selectionHooks).selectionMoveEnd)==null||x.call(H)})}_initialWidget(){const{topLeftWidget:r,topCenterWidget:e,topRightWidget:t,middleLeftWidget:i,middleRightWidget:o,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];[r,e,t,i,o,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(r,e){const t=this._scene,{offsetX:i,offsetY:o}=r,s=t.getCoordRelativeToViewport(R.Vector2.FromArray([i,o])),{x:l,y:c}=s;this._startOffsetX=i,this._startOffsetY=o;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(E=>{const{offsetX:w,offsetY:O}=E,{x:M,y:P}=t.getCoordRelativeToViewport(R.Vector2.FromArray([w,O]));this._widgetMoving(M,P,e),t.setCursor(e),C.scrolling(M,P,()=>{this._widgetMoving(M,P,e)})}),this._scenePointerUpSub=t.onPointerUp$.subscribeEvent(()=>{var w,O,M;const E=this._scene;E.resetCursor(),this._clearObserverEvent(),E.enableObjectsEvent(),(w=this._scrollTimer)==null||w.dispose(),this._control.selectionScaled$.next(this._targetSelection),(M=(O=this._selectionHooks).selectionMoveEnd)==null||M.call(O)})}_widgetMoving(r,e,t){const i=this._scene,o=i.getScrollXYInfoByViewport(R.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:s,scaleY:l}=i.getAncestorScale(),c=this._skeleton.getCellIndexByOffset(r,e,s,l,o),{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=Te({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:r}=this._control;r.onPointerEnter$.subscribeEvent(e=>{this._injector.get(ve).interceptor.fetchThroughInterceptors(xr)(!1,{x:e.offsetX,y:e.offsetY,skeleton:this._skeleton,scene:this._scene})&&r.setCursor(R.CURSOR_TYPE.CROSSHAIR)}),r.onPointerLeave$.subscribeEvent(()=>{r.resetCursor()}),r.onPointerDown$.subscribeEvent(this._autoFillForPointerdown.bind(this))}_autoFillMoving(r,e){var N,H,x;const t=this._scene,i=t.getViewportScrollXY(this._activeViewport),{scaleX:o,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(r,e,o,s,i),{row:c,column:d}=l,u=t.getCoordRelativeToViewport(R.Vector2.FromArray([r,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 L=this._fillRuler(d,f,p,this._relativeSelectionColumnLength,g);f=L.startRowOrColumn,p=L.endRowOrColumn,C=L.isLighten,b=!1}else if((c<S||c>v)&&d>=f&&d<=p){const L=this._fillRuler(c,S,v,this._relativeSelectionRowLength,h);S=L.startRowOrColumn,v=L.endRowOrColumn,C=L.isLighten}else if(Math.abs(this._startOffsetX-u.x-i.x)/2>Math.abs(this._startOffsetY-u.y-i.y)){const L=this._fillRuler(d,f,p,this._relativeSelectionColumnLength,g);f=L.startRowOrColumn,p=L.endRowOrColumn,C=L.isLighten,b=!1}else{const L=this._fillRuler(c,S,v,this._relativeSelectionRowLength,h);S=L.startRowOrColumn,v=L.endRowOrColumn,C=L.isLighten}const E=this._skeleton.getNoMergeCellWithCoordByIndex(S,f),w=this._skeleton.getNoMergeCellWithCoordByIndex(v,p),O=(E==null?void 0:E.startY)||0,M=(w==null?void 0:w.endY)||0,P=(E==null?void 0:E.startX)||0,A=(w==null?void 0:w.endX)||0;C?this._controlHandler((L,V)=>{const U=new a.ColorKit(this._fillControlColors[V]).lighten(td).toRgbString();L.setProps({fill:U})}):this._controlHandler((L,V)=>{L.setProps({fill:this._fillControlColors[V]})});const k=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();S===v&&b===!0||f===p&&b===!1?(N=this._helperSelection)==null||N.hide():((H=this._helperSelection)==null||H.transformByState({left:P-k/2,top:O-k/2,width:A-P,height:M-O}),(x=this._helperSelection)==null||x.show()),this._targetSelection={startY:O,endY:M,startX:P,endX:A,startRow:S,endRow:v,startColumn:f,endColumn:p},this._control.selectionFilling$.next(this._targetSelection)}_autoFillForPointerdown(r){const{offsetX:e,offsetY:t}=r,i=this._scene,o=i.getCoordRelativeToViewport(R.Vector2.FromArray([e,t])),{x:s,y:l}=o;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=at(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(Ms,{stroke:b,strokeWidth:f+C/2}),i.addObject(this._helperSelection)),this._activeViewport=i.getActiveViewportByCoord(R.Vector2.FromArray([e,t]));const E=i.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN),w=R.ScrollTimer.create(i,this._activeViewport.viewportKey===R.SHEET_VIEWPORT_KEY.VIEW_MAIN?R.ScrollTimerType.ALL:R.ScrollTimerType.NONE);w.startScroll(s,l,E),this._scrollTimer=w,i.disableObjectsEvent(),this._controlHandler(O=>{this._fillControlColors.push(O.fill)}),this._scenePointerMoveSub=i.onPointerMove$.subscribeEvent(O=>{var L;const{offsetX:M,offsetY:P}=O,A=i.getActiveViewportByCoord(R.Vector2.FromArray([M,P]));if(!this._injector.get(ve).interceptor.fetchThroughInterceptors(xr)(!1,{x:r.offsetX,y:r.offsetY,skeleton:this._skeleton,scene:this._scene}))return;const{x:N,y:H}=i.getCoordRelativeToViewport(R.Vector2.FromArray([M,P]));this._autoFillMoving(N,H),i.setCursor(R.CURSOR_TYPE.CROSSHAIR);const x=this._targetSelection;if(E&&A&&((L=this._activeViewport)==null?void 0:L.viewportKey)!==(A==null?void 0:A.viewportKey)){let V;x.startRow!==c?(w.scrollTimerType=R.ScrollTimerType.Y,V={...x,endRow:x.startRow}):x.endRow!==u?(w.scrollTimerType=R.ScrollTimerType.Y,V={...x,startRow:x.endRow}):x.startColumn!==d?(w.scrollTimerType=R.ScrollTimerType.X,V={...x,endColumn:x.startColumn}):(w.scrollTimerType=R.ScrollTimerType.X,V={...x,startColumn:x.endColumn}),this._isSelectionInViewport(V,A)&&(this._viewportMainScrollBarNeedResetPosition(w.scrollTimerType,this._activeViewport.viewportKey,A.viewportKey)&&E.scrollToBarPos({x:w.scrollTimerType===R.ScrollTimerType.X?0:void 0,y:w.scrollTimerType===R.ScrollTimerType.Y?0:void 0}),this._activeViewport=A)}w.scrolling(N,H,()=>{this._autoFillMoving(N,H)})}),this._scenePointerUpSub=i.onPointerUp$.subscribeEvent(()=>{var M,P;(M=this._helperSelection)==null||M.dispose();const O=this._scene;O.resetCursor(),this._clearObserverEvent(),O.enableObjectsEvent(),(P=this._scrollTimer)==null||P.dispose(),this._control.refreshSelectionFilled(this._targetSelection),this._isInMergeState=!1,this._controlHandler((A,k)=>{A.setProps({fill:this._fillControlColors[k]})}),this._fillControlColors=[]})}_viewportMainScrollBarNeedResetPosition(r,e,t){return r===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)||r===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(r,e,t,i){return this._skeleton.worksheet.getMergedCellRange(r,e,t,i).length>0}_swapPositions(r,e,t,i){const o=Math.min(r,t),s=Math.min(e,i),l=Math.max(r,t),c=Math.max(e,i);return{startRow:o,startColumn:s,endRow:l,endColumn:c}}_controlHandler(r){const{leftControl:e,rightControl:t,topControl:i,bottomControl:o,backgroundControlTop:s,backgroundControlMiddleLeft:l,backgroundControlMiddleRight:c,backgroundControlBottom:d,fillControl:u}=this._control,h=[e,t,i,o,s,l,c,d,u];for(let g=0,S=h.length;g<S;g++){const f=h[g];r(f,g)}}_fillRuler(r,e,t,i,o){let s=!1;if(r<e)if(this._isInMergeState&&r<e){const l=e-r,c=i+1,d=Math.ceil(l/c);let u=e-d*c;u<0&&(u=e-(d-1)*c),e=u}else e=r;else if(r>=e&&r<=t)s=!0,this._isInMergeState||(t=r);else if(this._isInMergeState&&r>t){const l=r-t,c=i+1,d=Math.ceil(l/c);let u=t+d*c;u>o&&(u=t+(d-1)*c),t=u}else t=r;return{rowOrColumn:r,startRowOrColumn:e,endRowOrColumn:t,isLighten:s}}_getScale(){const{scaleX:r,scaleY:e}=this._scene.getAncestorScale();return Math.max(r,e)}}var Ur=(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))(Ur||{});const Os=.3;class kn extends a.Disposable{constructor(e,t,i,o){var s,l,c,d;super();T(this,"_isHelperSelection",!0);T(this,"_enableAutoFill",!0);T(this,"_showAutoFill",!1);T(this,"_highlightHeader",!0);T(this,"_selectionRenderModel");T(this,"_leftBorder");T(this,"_rightBorder");T(this,"_topBorder");T(this,"_bottomBorder");T(this,"_backgroundControlTop");T(this,"_backgroundControlBottom");T(this,"_backgroundControlMiddleLeft");T(this,"_backgroundControlMiddleRight");T(this,"_autoFillControl");T(this,"_selectionShapeGroup");T(this,"_rowHeaderBackground");T(this,"_rowHeaderBorder");T(this,"_rowHeaderGroup");T(this,"_columnHeaderBackground");T(this,"_columnHeaderBorder");T(this,"_columnHeaderGroup");T(this,"_dashedRect");T(this,"_topLeftWidget");T(this,"_topCenterWidget");T(this,"_topRightWidget");T(this,"_middleLeftWidget");T(this,"_middleRightWidget");T(this,"_bottomLeftWidget");T(this,"_bottomCenterWidget");T(this,"_bottomRightWidget");T(this,"_defaultStyle");T(this,"_currentStyle");T(this,"_rowHeaderWidth",0);T(this,"_columnHeaderHeight",0);T(this,"_widgetRects",[]);T(this,"_controlExtension");T(this,"_dispose$",new D.BehaviorSubject(this));T(this,"dispose$",this._dispose$.asObservable());T(this,"selectionMoving$",new D.Subject);T(this,"selectionMoveEnd$",new D.Subject);T(this,"selectionScaling$",new D.Subject);T(this,"selectionScaled$",new D.Subject);T(this,"selectionFilling$",new D.Subject);T(this,"_selectionFilled$",new D.Subject);T(this,"selectionFilled$",this._selectionFilled$.asObservable());T(this,"_antLineOffset",0);T(this,"_antRequestNewFrame",-1);this._scene=e,this._zIndex=t,this._themeService=i,this._enableAutoFill=(s=o==null?void 0:o.enableAutoFill)!=null?s:!0,this._highlightHeader=(l=o==null?void 0:o.highlightHeader)!=null?l:!0,this._rowHeaderWidth=(c=o==null?void 0:o.rowHeaderWidth)!=null?c:0,this._columnHeaderHeight=(d=o==null?void 0:o.columnHeaderHeight)!=null?d:0,this._initializeSheetBody(),this._initialHeader()}_initializeSheetBody(){this._defaultStyle=at(this._themeService),this._currentStyle=at(this._themeService),this._selectionRenderModel=new ed;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,ki),this.disposeWithMe(a.toDisposable(i.onTransformChange$.subscribeEvent(o=>{o.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],$c)}_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 Ps(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:o,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:E}=this._selectionRenderModel;if(this.leftControl.transformByState({height:E-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:E-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:E-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 w=t.strokeWidth*2/g;this.dashedRect.transformByState({height:E-C,width:b-p,strokeWidth:w,left:-w/2+v,top:-w/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(o)){const w={fill:i,stroke:s,strokeScaleEnabled:!1},O={width:d-h,height:d-h,left:b-p-d/2+h/2-v,top:E-C-d/2+h/2-v,strokeWidth:h};this._autoFillControl.setProps(w),this._autoFillControl.transformByState(O),this._autoFillControl.show()}else this._autoFillControl.hide();this._updateBackgroundControl(t),this._updateHeaderBackground(t),this._updateWidgets(t)}_updateControlCoord(){const{startX:e,startY:t}=this._selectionRenderModel;this.selectionShapeGroup.show(),this.selectionShapeGroup.translate(e,t),this.selectionShapeGroup.makeDirtyNoDebounce(!0)}updateStyle(e){this._updateLayoutOfSelectionControl(e),this._updateControlCoord()}updateRange(e,t){this._selectionRenderModel.setValue(e,t),this._showAutoFill=t!==null,this._updateLayoutOfSelectionControl(),this._updateControlCoord()}updateRangeBySelectionWithCoord(e,t){t&&(this._rowHeaderWidth=t.rowHeaderWidth,this._columnHeaderHeight=t.columnHeaderHeight),this._selectionRenderModel.setValue(e.rangeWithCoord,e.primaryWithCoord),this._showAutoFill=e.primaryWithCoord!==null,this._updateLayoutOfSelectionControl(e.style),this._updateControlCoord()}update(e,t=0,i=0,o,s){this._rowHeaderWidth=t,this._columnHeaderHeight=i,this.updateRangeBySelectionWithCoord({rangeWithCoord:e,primaryWithCoord:s,style:o}),o&&this.updateStyle(o)}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,o,s,l,c,d,u,h,g,S,f,v,p,C,b,E,w,O,M,P,A,k,N;(e=this._leftBorder)==null||e.dispose(),(t=this._rightBorder)==null||t.dispose(),(i=this._topBorder)==null||i.dispose(),(o=this._bottomBorder)==null||o.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(),(E=this._topCenterWidget)==null||E.dispose(),(w=this._topRightWidget)==null||w.dispose(),(O=this._middleLeftWidget)==null||O.dispose(),(M=this._middleRightWidget)==null||M.dispose(),(P=this._bottomLeftWidget)==null||P.dispose(),(A=this._bottomCenterWidget)==null||A.dispose(),(k=this._bottomRightWidget)==null||k.dispose(),(N=this._controlExtension)==null||N.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:o,startX:s,endX:l,startY:c,endY:d}=e;t={startRow:i,endRow:i,startColumn:o,endColumn:o,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:o,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 E=S;l===a.RANGE_TYPE.COLUMN&&(E=new a.ColorKit(u).setAlpha(Os).toString()),this._columnHeaderBackground.setProps({fill:E}),this._columnHeaderBackground.resize(o-t,b),this._columnHeaderBorder.setProps({fill:f}),this._columnHeaderBorder.transformByState({width:o-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 E=h;l===a.RANGE_TYPE.ROW&&(E=new a.ColorKit(u).setAlpha(Os).toString()),this._rowHeaderBackground.setProps({fill:E}),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:o,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(o-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:o-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:o-S+v*2,height:f-g};b.width<0&&(b.width=0,b.height=0),this._backgroundControlMiddleRight.transformByState(b);const E={left:-v,top:f-i,width:o-t+v*2,height:s-f+v};E.height<0&&(E.width=0,E.height=0),this._backgroundControlBottom.transformByState(E),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:o,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:(o-t)/2-h/2+g/2,right:o-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 nd extends R.Layer{render(r,e=!1){const t=a.Tools.now();return super.render(r,e),this._afterRender(t),this}_afterRender(r){this.scene.getEngine().renderFrameTimeMetric$.next(["selectionLayer",a.Tools.now()-r])}}const ve=a.createIdentifier("univer.sheet.selection-render-service");class Br extends a.Disposable{constructor(e,t,i,o,s){super();T(this,"_downObserver");T(this,"_scenePointerMoveSub");T(this,"_scenePointerUpSub");T(this,"_controlFillConfig$",new D.BehaviorSubject(null));T(this,"controlFillConfig$",this._controlFillConfig$.asObservable());T(this,"_selectionControls",[]);T(this,"_startRangeWhenPointerDown",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});T(this,"_activeControlIndex",-1);T(this,"_startViewportPosX",0);T(this,"_startViewportPosY",0);T(this,"_scrollTimer");T(this,"_cancelDownSubscription");T(this,"_cancelUpSubscription");T(this,"_skeleton");T(this,"_scene");T(this,"_highlightHeader",!0);T(this,"_rangeType",a.RANGE_TYPE.NORMAL);T(this,"_selectionStyle");T(this,"_remainLastEnabled",!1);T(this,"_skipLastEnabled",!1);T(this,"_singleSelectionEnabled",!1);T(this,"_selectionMoveEnd$",new D.BehaviorSubject([]));T(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());T(this,"_selectionMoving$",new D.Subject);T(this,"selectionMoving$",this._selectionMoving$.asObservable());T(this,"_selectionMoveStart$",new D.Subject);T(this,"selectionMoveStart$",this._selectionMoveStart$.asObservable());T(this,"_selectionMoving",!1);T(this,"_selectionTheme");T(this,"_activeViewport");T(this,"interceptor",new a.InterceptorManager({RANGE_MOVE_PERMISSION_CHECK:Wr,RANGE_FILL_PERMISSION_CHECK:xr}));T(this,"_escapeShortcutDisposable",null);this._injector=e,this._themeService=t,this._shortcutService=i,this._sheetSkeletonManagerService=o,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 o=this.getSelectionControls().length,{rowHeaderWidth:s,columnHeaderHeight:l}=t,c=new kn(e,o,this._selectionTheme,{highlightHeader:this._highlightHeader,rowHeaderWidth:s,columnHeaderHeight:l});this._selectionControls.push(c);const d=Te(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 o=0,s=e.length;o<s;o++){const l=e[o],c=Te(l,this._skeleton),d=t[o];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(ki)||t.addLayer(new nd(t,[],ki))}getSkeleton(){return this._skeleton}getSelectionDataWithStyle(){const e=this._selectionControls,[t,i]=this._skeleton.getLocation();return e.map(o=>{const s=o.getValue();return s.rangeWithCoord.sheetId=i,s.rangeWithCoord.unitId=t,s})}getSelectionControls(){return this._selectionControls}_addSelectionControlByModelData(e){var l;const t=this._skeleton,i=(l=e.style)!=null?l:at(this._selectionTheme),o=this._scene;return e.style=i,this.newSelectionControl(o,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,o=R.ScrollTimerType.ALL,s,l){var f,v;let c=0,d=0,u=s,h=l;this._scrollTimer=R.ScrollTimer.create(this._scene,o),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 x,L,V,U,B,Y,F,z,j;const{offsetX:C,offsetY:b}=p,{x:E,y:w}=g.getCoordRelativeToViewport(R.Vector2.FromArray([C,b]));this._movingHandler(E,w,t,i);let O=E,M=w;const P=this.getActiveSelectionControl(),A=this._getFreeze(),k=P==null?void 0:P.model,N=(x=g.getActiveViewportByCoord(R.Vector2.FromArray([C,b])))!=null?x:this._getViewportByCell(k==null?void 0:k.endRow,k==null?void 0:k.endColumn);if((()=>{if(!S||!N||!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(N.viewportKey)})()){if(!S||!N||!e)return!1;const Q=u<e.left&&E>e.left||u>e.left&&E<e.left,ie=h<e.top&&w>e.top||h>e.top&&w<e.top;Q&&(c+=1),ie&&(d+=1);const $=S.viewportKey,se=N.viewportKey;if($===R.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP)b<e.top&&((L=k==null?void 0:k.endRow)!=null?L:0)<((V=A==null?void 0:A.startRow)!=null?V:0)?M=e.top:ie&&d%2===1&&e.scrollToViewportPos({viewportScrollY:0});else if($===R.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT)C<e.left&&((U=k==null?void 0:k.endColumn)!=null?U:0)<((B=A==null?void 0:A.startColumn)!=null?B:0)?O=e.left:Q&&c%2===1&&e.scrollToViewportPos({viewportScrollX:0});else if($===se){let Z=!1,G=!1;$===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP?(Z=!0,G=!0):$===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP?G=!0:$===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT&&(Z=!0),((Y=k==null?void 0:k.endRow)!=null?Y:0)>((F=A==null?void 0:A.startRow)!=null?F:0)&&(G=!1),((z=k==null?void 0:k.endColumn)!=null?z:0)>((j=A==null?void 0:A.startColumn)!=null?j:0)&&(Z=!1),Z&&(O=e.left),G&&(M=e.top)}else{const Z={x:S.scrollX,y:S.scrollY},G={x:N.scrollX,y:N.scrollY},J=Z.x!==G.x&&Q&&c%2===1,re=Z.y!==G.y&&ie&&d%2===1;(J||re)&&(e.scrollToBarPos({x:J?Z.x:void 0,y:re?Z.y:void 0}),J||(O=e.left),re||(M=e.top)),($===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&se===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||se===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&$===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)&&(O=e.left),($===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&se===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||se===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&$===R.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP)&&(M=e.top)}u=E,h=w}this._scrollTimer.scrolling(O,M,()=>{this._movingHandler(E,w,t,i)})})}attachSelectionWithCoord(e){return Te(e,this._skeleton)}attachPrimaryWithCoord(e){return Dn(this._skeleton,e)}getSelectionCellByPosition(e,t){return this.getCellWithCoordByOffset(e,t)}getCellWithCoordByOffset(e,t,i){const o=this._scene,s=i!=null?i:this._skeleton,l=o.getViewportScrollXY(o.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:c,scaleY:d}=o.getAncestorScale();return s.getCellWithCoordByOffset(e,t,c,d,l)}_movingHandler(e,t,i,o){var O,M,P,A,k;const s=this._skeleton,l=this._scene,[c,d]=s.getLocation(),u={startRow:(O=i==null?void 0:i.model.startRow)!=null?O:-1,endRow:(M=i==null?void 0:i.model.endRow)!=null?M:-1,startColumn:(P=i==null?void 0:i.model.startColumn)!=null?P:-1,endColumn:(A=i==null?void 0:i.model.endColumn)!=null?A:-1},h=l.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=(k=this._getViewportByCell(u.endRow,u.endColumn))!=null?k:h,S=l.getScrollXYInfoByViewport(R.Vector2.FromArray([this._startViewportPosX,this._startViewportPosY]),g),{scaleX:f,scaleY:v}=l.getAncestorScale();o===a.RANGE_TYPE.ROW?e=Number.POSITIVE_INFINITY:o===a.RANGE_TYPE.COLUMN&&(t=Number.POSITIVE_INFINITY);const p=this._skeleton.getCellByOffset(e,t,f,v,S);if(!p)return;let C={startRow:Math.min(p.startRow,this._startRangeWhenPointerDown.startRow),startColumn:Math.min(p.startColumn,this._startRangeWhenPointerDown.startColumn),endRow:Math.max(p.endRow,this._startRangeWhenPointerDown.endRow),endColumn:Math.max(p.endColumn,this._startRangeWhenPointerDown.endColumn)};this._shouldDetectMergedCells&&(C=s.expandRangeByMerge(C));const E=Te({range:C,primary:void 0,style:null},s);E.rangeWithCoord.unitId=c,E.rangeWithCoord.sheetId=d,E.rangeWithCoord.rangeType=o;const w=u.startRow!==C.startRow||u.startColumn!==C.startColumn||u.endRow!==C.endRow||u.endColumn!==C.endColumn;i!=null&&w&&(i.updateRangeBySelectionWithCoord(E),this._selectionMoving$.next(this.getSelectionDataWithStyle()))}_clearUpdatingListeners(){var t,i,o,s,l;this._scene.enableObjectsEvent(),(t=this._scenePointerMoveSub)==null||t.unsubscribe(),this._scenePointerMoveSub=null,(i=this._scenePointerUpSub)==null||i.unsubscribe(),this._scenePointerUpSub=null,(o=this._cancelDownSubscription)==null||o.unsubscribe(),this._cancelDownSubscription=null,(s=this._cancelUpSubscription)==null||s.unsubscribe(),this._cancelUpSubscription=null,(l=this._scrollTimer)==null||l.dispose()}_addEndingListeners(){var i,o,s;const e=this._scene,t=(i=e.getEngine())==null?void 0:i.activeScene;!t||t===e||((o=this._cancelDownSubscription)==null||o.unsubscribe(),this._cancelDownSubscription=null,(s=this._cancelUpSubscription)==null||s.unsubscribe(),this._cancelUpSubscription=null,this._cancelDownSubscription=t.onPointerDown$.subscribeEvent(()=>this._clearUpdatingListeners()),this._cancelUpSubscription=t.onPointerUp$.subscribeEvent(()=>this._clearUpdatingListeners()))}_getSelectionWithCoordByOffset(e,t,i,o,s){const l=this._skeleton;if(l==null)return null;if(this._shouldDetectMergedCells){const C=l==null?void 0:l.getCellWithCoordByOffset(e,t,i,o,s,{firstMatch:!0});if(!C)return;const b=a.convertCellToRange(C);return{primaryWithCoord:C,rangeWithCoord:b}}const{row:c,column:d}=l.getCellIndexByOffset(e,t,i,o,s),u=l.getNoMergeCellWithCoordByIndex(c,d),{startX:h,startY:g,endX:S,endY:f}=u,v={startY:g,endY:f,startX:h,endX:S,startRow:c,endRow:c,startColumn:d,endColumn:d};return{primaryWithCoord:{mergeInfo:v,actualRow:c,actualColumn:d,isMerged:!1,isMergedMainCell:!1,startY:g,endY:f,startX:h,endX:S},rangeWithCoord:v}}_checkClearPreviousControls(e){this.getSelectionControls().length!==0&&(!e.ctrlKey&&!e.shiftKey&&!this._remainLastEnabled||this._singleSelectionEnabled&&!e.shiftKey)&&this._clearAllSelectionControls()}_makeSelectionByTwoCells(e,t,i,o,s){const{actualRow:l,actualColumn:c,mergeInfo:d}=e;this._startRangeWhenPointerDown={...e.mergeInfo};const u=Math.min(l,t.startRow,d.startRow),h=Math.max(l,t.endRow,d.endRow),g=Math.min(c,t.startColumn,d.startColumn),S=Math.max(c,t.endColumn,d.endColumn),v={range:i.expandRangeByMerge({startRow:u,startColumn:g,endRow:h,endColumn:S}),primary:null,style:null},p=Te(v,i);s.updateRangeBySelectionWithCoord(p)}isSelectionEnabled(){return this.contextService.getContextValue(m.SELECTIONS_ENABLED)}isSelectionDisabled(){return this.contextService.getContextValue(m.SELECTIONS_ENABLED)===!1}inRefSelectionMode(){return this.contextService.getContextValue(m.REF_SELECTIONS_ENABLED)}}function Fr(n){return{range:{startRow:0,startColumn:0,endRow:n.getRowCount()-1,endColumn:n.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL},primary:Vi(n).primary,style:null}}function Vi(n){return As(n,{startRow:0,startColumn:0,endRow:0,endColumn:0})}function As(n,r){const e=n.worksheet.getCellInfoInMergeData(r.startRow,r.startColumn),t=n.worksheet.getCellInfoInMergeData(r.endRow,r.endColumn);return{range:{startRow:e.startRow,startColumn:e.startColumn,endRow:t.endRow,endColumn:t.endColumn,rangeType:a.RANGE_TYPE.NORMAL},primary:{actualRow:e.startRow,actualColumn:e.startColumn,startRow:e.startRow,startColumn:e.startColumn,endRow:e.endRow,endColumn:e.endColumn,isMerged:e.isMerged,isMergedMainCell:e.isMergedMainCell},style:null}}var id=Object.getOwnPropertyDescriptor,rd=(n,r,e,t)=>{for(var i=t>1?void 0:t?id(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},Ds=(n,r)=>(e,t)=>r(e,t,n);y.SheetSkeletonManagerService=class extends a.Disposable{constructor(e,t,i){super();T(this,"_sheetId","");T(this,"_sheetSkeletonParamStore",new Map);T(this,"_currentSkeleton$",new D.BehaviorSubject(null));T(this,"currentSkeleton$",this._currentSkeleton$.asObservable());T(this,"_currentSkeletonBefore$",new D.BehaviorSubject(null));T(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._context=e,this._injector=t,this._sheetSkService=i,this.disposeWithMe(()=>{this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._sheetSkeletonParamStore.forEach(o=>this.disposeSkeleton(o.sheetId)),this._sheetSkeletonParamStore.clear()}),this._initRemoveSheet()}_initRemoveSheet(){this.disposeWithMe(this._context.unit.sheetDisposed$.subscribe(e=>{this.disposeSkeleton(e.getSheetId())}))}getCurrentSkeleton(){var e;return(e=this.getCurrentParam())==null?void 0:e.skeleton}getCurrent(){return this.getCurrentParam()}getCurrentParam(){return this._getSkeletonParam(this._sheetId)}getSkeleton(e){return this._getSkeleton(e)}getSkeletonParam(e){return this._getSkeletonParam(e)}getWorksheetSkeleton(e){return this.getSkeletonParam(e)}getUnitSkeleton(e,t){const i=this._getSkeletonParam(t);return i!=null&&(i.unitId=e),i}setCurrent(e){this._setCurrent(e.sheetId)}setSkeletonParam(e,t){this._sheetSkService.setSkeleton(t.unitId,e,t.skeleton),this._sheetSkeletonParamStore.set(e,t)}_setCurrent(e){this._sheetId=e;const t=this._getSkeletonParam(e),i=this._context.unitId;if(t!=null)this.reCalculate(t);else{const l=this._context.unit.getSheetBySheetId(e);if(l==null)return;const c=this._context.scene,d=this._buildSkeleton(l,c);this.setSkeletonParam(e,{unitId:i,sheetId:e,skeleton:d,dirty:!1})}const o=this._getSkeletonParam(e);this._currentSkeletonBefore$.next(o),this._currentSkeleton$.next(o)}reCalculate(e){e||(e=this.getCurrentParam()),e!=null&&(e.dirty&&(e.skeleton.makeDirty(!0),e.dirty=!1),e.skeleton.calculate())}makeDirty(e,t=!0){const i=this._getSkeletonParam(e.sheetId);i!=null&&(i.dirty=t)}getOrCreateSkeleton(e){return this.ensureSkeleton(e.sheetId)}ensureSkeleton(e){const t=this._getSkeletonParam(e);if(t)return t.skeleton;const o=this._context.unit.getSheetBySheetId(e);if(!o)return;const s=this._buildSkeleton(o);return this.setSkeletonParam(e,{unitId:this._context.unitId,sheetId:e,skeleton:s,dirty:!1}),s}disposeSkeleton(e){const t=this.getSkeletonParam(e);t&&(t.skeleton.dispose(),this._sheetSkeletonParamStore.delete(e),this._sheetSkService.deleteSkeleton(t.unitId,e))}attachRangeWithCoord(e){const t=this.getCurrentSkeleton();return t?Gt(t,e):null}_getSkeletonParam(e){return this._sheetSkeletonParamStore.get(e)}_getSkeleton(e){const t=this._getSkeletonParam(e);return t?t.skeleton:null}_buildSkeleton(e,t){return this._injector.createInstance(R.SpreadsheetSkeleton,e,this._context.unit.getStyles())}setColumnHeaderSize(e,t,i){var u;if(!e)return;const o=(u=this.getWorksheetSkeleton(t))==null?void 0:u.skeleton;if(!o)return;o.columnHeaderHeight=i,e.scene.getViewports()[0].top=i,e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({height:i}),e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({height:i}),e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({top:i}),e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({top:i}),e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({height:i});const s=e==null?void 0:e.with(m.SheetsSelectionsService),l=e==null?void 0:e.with(ve),c=s.getCurrentSelections();l.resetSelectionsByModelData(c);const d=this.getUnitSkeleton(e.unitId,t);d&&(d.commandId=Hi.id,this._currentSkeleton$.next(d))}setRowHeaderSize(e,t,i){var f;const o=(f=this.getWorksheetSkeleton(t))==null?void 0:f.skeleton;if(!e||!o)return;o.rowHeaderWidth=i;const s=e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).width||46,l=i-s,c=e.scene.getViewports()[0].left;e.scene.getViewports()[0].left=c+l,e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({width:i}),e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({width:i}),e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT).setViewportSize({left:i});const d=e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).left||0;e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({left:d+l}),e.scene.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({width:i});const u=e==null?void 0:e.with(m.SheetsSelectionsService),h=e==null?void 0:e.with(ve),g=u.getCurrentSelections();h.resetSelectionsByModelData(g);const S=this.getCurrent();S&&(S.commandId=Ni.id,this._currentSkeleton$.next(S))}},y.SheetSkeletonManagerService=rd([Ds(1,a.Inject(a.Injector)),Ds(2,a.Inject(m.SheetSkeletonService))],y.SheetSkeletonManagerService);function lt(){const n=_.useDependency(a.IUniverInstanceService),r=_.useObservable(()=>n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]);return r!=null?r:null}function od(n){return _.useObservable(()=>{var e;return(e=n==null?void 0:n.activeSheet$)!=null?e:D.of(null)},void 0,void 0,[n])}function sd(){const n=_.useDependency(a.IUniverInstanceService);return _.useObservable(()=>D.merge([n.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET),n.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET)]).pipe(D.map(()=>n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET)),D.startWith(n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET))),[],void 0,[n])}const ad="SheetUI";var zr=(n=>(n.FILTER_PANEL_EMBED_POINT="filter-panel-embed-point",n.SHEETS_FOOTER="sheets-footer",n.FORMULA_AUX="formula-aux",n))(zr||{}),ld=Object.getOwnPropertyDescriptor,cd=(n,r,e,t)=>{for(var i=t>1?void 0:t?ld(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},Nn=(n,r)=>(e,t)=>r(e,t,n);const ks=["ff","fs","tr","tb"];y.AutoHeightController=class extends a.Disposable{constructor(r,e,t,i,o){super(),this._renderManagerService=r,this._sheetInterceptorService=e,this._selectionManagerService=t,this._univerInstanceService=i,this._configService=o,this._initialize()}_processLazyAutoHeight(r,e,t,i){if(i!=null&&i.length){const o={id:m.MarkDirtyRowAutoHeightMutation.id,params:{unitId:e,subUnitId:t,ranges:i,id:a.generateRandomId()},options:{onlyLocal:!0}},s={id:m.CancelMarkDirtyRowAutoHeightMutation.id,params:{unitId:e,subUnitId:t,id:o.params.id},options:{onlyLocal:!0}};return{redos:[...r.redos,o],undos:[...r.undos,s]}}return r}getUndoRedoParamsOfAutoHeight(r,e,t){const{_univerInstanceService:i}=this,o=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=o.getUnitId();let l=o.getActiveSheet(),c=l.getSheetId();if(e){const v=m.getSheetCommandTarget(i,{unitId:s,subUnitId:e});v&&(l=v.worksheet,c=l.getSheetId())}const u=this._renderManagerService.getRenderById(s).with(y.SheetSkeletonManagerService).ensureSkeleton(c);if(!u)return{redos:[],undos:[]};const g=u.calculateAutoHeightInRange(r,t).filter(v=>{const{row:p,autoHeight:C}=v;return!(!C||l.getRowHeight(p)===C)});if(g.length===0)return{redos:[],undos:[]};const S={subUnitId:c,unitId:s,rowsAutoHeightInfo:g},f=m.SetWorksheetRowAutoHeightMutationFactory(S,l);return{undos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:f}],redos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:S}]}}_initialize(){this.disposeWithMe(this._sheetInterceptorService.interceptAutoHeight({getMutations:r=>{const{unitId:e,subUnitId:t,ranges:i,autoHeightRanges:o,lazyAutoHeightRanges:s,cellHeights:l}=r,c=this.getUndoRedoParamsOfAutoHeight(o!=null?o:i,t,l);return this._processLazyAutoHeight(c,e,t,s)}}))}},y.AutoHeightController=cd([Nn(0,R.IRenderManagerService),Nn(1,a.Inject(m.SheetInterceptorService)),Nn(2,a.Inject(m.SheetsSelectionsService)),Nn(3,a.Inject(a.IUniverInstanceService)),Nn(4,a.IConfigService)],y.AutoHeightController);function ct(n){const{rows:r,cols:e}=n;return{startRow:r[0],endRow:r[r.length-1],startColumn:e[0],endColumn:e[e.length-1]}}function dt(n){let r=[],e=[];const t=[];return n.forEach(i=>{r=r.concat(i.rows),e=e.concat(i.cols)}),r=Array.from(new Set(r)).sort((i,o)=>i-o),e=Array.from(new Set(e)).sort((i,o)=>i-o),n.forEach(i=>{t.push({startRow:r.findIndex(o=>o===i.rows[0]),endRow:r.findIndex(o=>o===i.rows[i.rows.length-1]),startColumn:e.findIndex(o=>o===i.cols[0]),endColumn:e.findIndex(o=>o===i.cols[i.cols.length-1])})}),{ranges:t,mapFunc:(i,o)=>({row:r[i],col:e[o]})}}function dd(n){const r=new a.ObjectMatrix;return n.forEach(e=>{const{rows:t,cols:i}=e;t.forEach(o=>{i.forEach(s=>{r.setValue(o,s,{v:null,p:null,f:null,si:null,custom:null})})})}),r.getData()}const Xr={零:0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9},Wi=["零","一","二","三","四","五","六","七","八","九"],Ns=["","万","亿","万亿","亿亿"],ud=["","十","百","千"],Hs={十:{value:10,secUnit:!1},百:{value:100,secUnit:!1},千:{value:1e3,secUnit:!1},万:{value:1e4,secUnit:!0},亿:{value:1e8,secUnit:!0}};function Qe(n){if(!n)return 0;let r=0,e=0,t=0,i=!1;const o=n.split("");for(let s=0;s<o.length;s++){const l=Xr[o[s]];if(typeof l<"u")t=l,s===o.length-1&&(e+=t);else{const c=Hs[o[s]],d=c.value;i=c.secUnit,i?(e=(e+t)*d,r+=e,e=0):e+=t*d,t=0}}return r+e}function hd(n){let r="",e="",t=0,i=!0;for(;n>0;){const o=n%10;o===0?i||(i=!0,e=Wi[o]+e):(i=!1,r=Wi[o],r+=ud[t],e=r+e),t++,n=Math.floor(n/10)}return e}function md(n){let r=0,e="",t="",i=!1;if(n===0)return Wi[0];for(;n>0;){const o=n%1e4;i&&(t=Wi[0]+t),e=hd(o),e+=o!==0?Ns[r]:Ns[0],t=e+t,i=o<1e3&&o>0,n=Math.floor(n/1e4),r++}return t}function gd(n){if(!n)return!1;let r=!0;if(n)if(n.length===1)n==="日"||n in Xr?r=!0:r=!1;else{const e=n.split("");for(let t=0;t<e.length;t++)if(!(e[t]in Xr||e[t]in Hs)){r=!1;break}}return r}function xi(n){if(!n)return{isExtendNumber:!1};const r=/0|([1-9]+[0-9]*)/g,e=r.test(n);if(e){const t=n.match(r);if(t&&t.length>0){const i=t[t.length-1],o=n.lastIndexOf(i),s=n.substr(0,o),l=n.substr(o+i.length);return{isExtendNumber:!0,matchTxt:Number(i),beforeTxt:s,afterTxt:l}}return{isExtendNumber:!1}}return{isExtendNumber:e}}function Sd(n){let r;return n.length===2&&(n==="周一"||n==="周二"||n==="周三"||n==="周四"||n==="周五"||n==="周六"||n==="周日")?r=!0:r=!1,r}function fd(n){let r;return n.length===3&&(n==="星期一"||n==="星期二"||n==="星期三"||n==="星期四"||n==="星期五"||n==="星期六"||n==="星期日")?r=!0:r=!1,r}function vd(n,r){let e=0;for(let t=0;t<n.length&&n[t]<r;t++)e++;return e}function Hn(n){let r=!0;const e=n[1]-n[0];for(let t=1;t<n.length;t++)if(n[t]-n[t-1]!==e){r=!1;break}return r}function pd(n,r,e){const t=[],i=Math.floor(r/n),o=r%n;let s=0;if(i>0){for(let l=0;l<i;l++)for(let c=0;c<e.length;c++)t[e[c]+l*n]=s,s++;for(let l=0;l<e.length&&e[l]<o;l++)t[e[l]+n*i]=s,s++}else for(let l=0;l<e.length&&e[l]<o;l++)t[e[l]]=s,s++;return t}function It(n,r){const e=[];for(let t=1;t<=r;t++){const i=(t-1)%n.length,o=a.Tools.deepClone(n[i]);bt(o),e.push({v:null,s:null,p:null,f:null,si:null,t:null,...o})}return e}function Cd(n,r){var t;const e=[];for(let i=1;i<=r;i++){const o=(i-1)%n.length,s={s:(t=n[o])==null?void 0:t.s};e.push(s)}return e}function _d(n){let r=!0;const e=n[1]/n[0];for(let t=1;t<n.length;t++)if(n[t]/n[t-1]!==e){r=!1;break}return r}function Id(n){const r=[];for(let e=1;e<=n;e++)r.push(e);return r}function Li(n,r,e){var o,s,l,c;const t=[],i=[];for(let d=0;d<n.length;d++)i.push(Number((o=n[d])==null?void 0:o.v));if(n.length>2&&_d(i))for(let d=1;d<=r;d++){const u=(d-1)%n.length,h=a.Tools.deepClone(n[u]);bt(h);const g=Number((s=n[n.length-1])==null?void 0:s.v)*(Number((l=n[1])==null?void 0:l.v)/Number((c=n[0])==null?void 0:c.v))**d;h&&(Ls(h)&&(h.v=g),t.push(h))}else{const d=Id(n.length);for(let u=1;u<=r;u++){const h=(u-1)%n.length,g=a.Tools.deepClone(n[h]);bt(g);const S=e===a.Direction.DOWN||e===a.Direction.RIGHT,f=bd(n.length+u,i,d,S);g&&(Ls(g)&&(g.v=f),t.push(g))}}return t}function bd(n,r,e,t=!0){function i(h){let g=0;for(let S=0;S<h.length;S++)g+=h[S];return g/h.length}const o=i(e),s=i(r);let l=0,c=0;for(let h=0;h<e.length;h++)l+=(e[h]-o)*(r[h]-s),c+=(e[h]-o)*(e[h]-o);let d;c===0?d=t?1:-1:d=l/c;const u=s-d*o;return Math.round((u+d*n)*1e5)/1e5}function Vs(n,r,e){var o;const t=[],i=/0|([1-9]+[0-9]*)/g;for(let s=1;s<=r;s++){const l=(s-1)%n.length,c=a.Tools.deepClone(n[l]);bt(c);const d=`${(o=n[n.length-1])==null?void 0:o.v}`;if(!d)continue;const u=d==null?void 0:d.match(i),h=u==null?void 0:u[u.length-1];if(!h)continue;const g=Math.abs(Number(h)+e*s),S=d.lastIndexOf(h),f=d.substr(0,S)+g.toString()+d.substr(S+h.length);c&&(c.v=f,t.push(c))}return t}function Zt(n,r,e,t=0){var l,c;const i=[["日","一","二","三","四","五","六"],["周日","周一","周二","周三","周四","周五","周六"],["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]];if(t>=i.length)return[];const o=i[t],s=[];for(let d=1;d<=r;d++){const u=(d-1)%n.length,h=a.Tools.deepClone(n[u]);bt(h);let g=0;if(((l=n[n.length-1])==null?void 0:l.v)===o[0])g=7+e*d;else{const f=`${(c=n[n.length-1])==null?void 0:c.v}`;if(f){const v=f.substr(f.length-1,1);g=Qe(v)+e*d}}g<0&&(g=Math.ceil(Math.abs(g)/7)*7+g);const S=g%7;h&&(h.v=o[S],s.push(h))}return s}function Ws(n,r,e){var i;const t=[];for(let o=1;o<=r;o++){const s=(o-1)%n.length,l=a.Tools.deepClone(n[s]);bt(l);const c=`${(i=n[n.length-1])==null?void 0:i.v}`,d=Qe(c)+e*o;let u;d<=0?u="零":u=md(d),l&&(l.v=u,t.push(l))}return t}const Vn={enWeek1:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],enWeek2:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],enMonth1:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],enMonth2:["January","February","March","April","May","June","July","August","September","October","November","December"],chnMonth1:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],chnMonth2:["正月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","腊月"],chHour1:["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"],chHour2:["子时","丑时","寅时","卯时","辰时","巳时","午时","未时","申时","酉时","戌时","亥时"],chYear1:["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"],chSeason1:["春","夏","秋","冬"],chSeason2:["春季","夏季","秋季","冬季"]};function wd(n){let r=!1;return Object.keys(Vn).forEach(e=>{Vn[e].includes(n)&&(r=!0)}),r}function Yr(n){let r="";const e=[];return Object.keys(Vn).forEach(t=>{Vn[t].includes(n)&&(r=t,e.push(...Vn[t]))}),{name:r,series:e}}function xs(n,r,e,t){var s;const i=t.length,o=[];for(let l=1;l<=r;l++){const c=(l-1)%n.length,d=a.Tools.deepClone(n[c]);bt(d);const u=`${(s=n[n.length-1])==null?void 0:s.v}`;let h=t.indexOf(u)+e*l;h<0&&(h+=Math.abs(e)*i);const g=h%i;d&&(d.v=t[g],o.push(d))}return o}function Ed(n,r){const e=[];let t;if(r.startRow<n.startRow)t=a.Direction.UP;else if(r.endRow>n.endRow)t=a.Direction.DOWN;else if(r.startColumn<n.startColumn)t=a.Direction.LEFT;else if(r.endColumn>n.endColumn)t=a.Direction.RIGHT;else return[];if(t===a.Direction.DOWN||t===a.Direction.UP){const i=n.endRow-n.startRow+1,o=r.endRow-r.startRow+1,s=Math.floor(o/i),l=o%i,c={startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:n.endColumn-n.startColumn};if(t===a.Direction.DOWN){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow+(d+1)*i,col:n.startColumn},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow+(s+1)*i,col:n.startColumn},relativeRange:{startRow:0,startColumn:0,endRow:l-1,endColumn:n.endColumn-n.startColumn}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow-(d+1)*i,col:n.startColumn},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow-(s+1)*i,col:n.startColumn},relativeRange:{startRow:i-l,endRow:i-1,startColumn:0,endColumn:n.endColumn-n.startColumn}})}}if(t===a.Direction.RIGHT||t===a.Direction.LEFT){const i=n.endColumn-n.startColumn+1,o=r.endColumn-r.startColumn+1,s=Math.floor(o/i),l=o%i,c={startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:n.endColumn-n.startColumn};if(t===a.Direction.RIGHT){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow,col:n.startColumn+(d+1)*i},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow,col:n.startColumn+(s+1)*i},relativeRange:{startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:l-1}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow,col:n.startColumn-(d+1)*i},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow,col:n.startColumn-(s+1)*i},relativeRange:{startRow:0,startColumn:i-l,endRow:n.endRow-n.startRow,endColumn:i-1}})}}return e}function Ls(n){return!(a.isFormulaString(n.f)||a.isFormulaId(n.si)||n.t===a.CellValueType.BOOLEAN)}function bt(n){n&&"custom"in n&&delete n.custom}var Kt=(n=>(n.Append="APPEND",n.Default="DEFAULT",n.Only="ONLY",n))(Kt||{}),Ie=(n=>(n.NUMBER="number",n.DATE="date",n.EXTEND_NUMBER="extendNumber",n.CHN_NUMBER="chnNumber",n.CHN_WEEK2="chnWeek2",n.CHN_WEEK3="chnWeek3",n.LOOP_SERIES="loopSeries",n.FORMULA="formula",n.OTHER="other",n))(Ie||{}),ce=(n=>(n.COPY="COPY",n.SERIES="SERIES",n.ONLY_FORMAT="ONLY_FORMAT",n.NO_FORMAT="NO_FORMAT",n))(ce||{});const Td={type:Ie.DATE,priority:1100,match:(n,r)=>{var e;if(n!=null&&n.f||n!=null&&n.si)return!1;if((typeof(n==null?void 0:n.v)=="number"||(n==null?void 0:n.t)===a.CellValueType.NUMBER)&&n.s){if(typeof n.s=="string"){const i=r.get(a.IUniverInstanceService).getFocusedUnit().getStyles().get(n.s),o=(e=i==null?void 0:i.n)==null?void 0:e.pattern;if(o)return a.numfmt.getFormatInfo(o).isDate}else if(n.s.n&&a.numfmt.getFormatInfo(n.s.n.pattern).isDate)return!0}return!1},isContinue:(n,r)=>n.type===Ie.DATE,applyFunctions:{[ce.SERIES]:(n,r,e)=>{const{data:t}=n;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),Li(t,r,e).reverse()):Li(t,r,e)}}},yd={type:Ie.NUMBER,priority:1e3,match:n=>typeof(n==null?void 0:n.v)=="number"||(n==null?void 0:n.t)===a.CellValueType.NUMBER,isContinue:(n,r)=>n.type===Ie.NUMBER,applyFunctions:{[ce.SERIES]:(n,r,e)=>{const{data:t}=n;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),Li(t,r,e).reverse()):Li(t,r,e)}}},Us={type:Ie.OTHER,priority:0,match:()=>!0,isContinue:(n,r)=>n.type===Ie.OTHER},Rd={type:Ie.EXTEND_NUMBER,priority:900,match:n=>xi(`${n==null?void 0:n.v}`||"").isExtendNumber,isContinue:(n,r)=>{var e;if(n.type===Ie.EXTEND_NUMBER){const{beforeTxt:t,afterTxt:i}=xi(`${(e=n.cellData)==null?void 0:e.v}`||""),{beforeTxt:o,afterTxt:s}=xi(`${r==null?void 0:r.v}`||"");if(t===o&&i===s)return!0}return!1},applyFunctions:{[ce.SERIES]:(n,r,e)=>{var l;const{data:t}=n,i=e===a.Direction.UP||e===a.Direction.LEFT;let o;if(t.length===1)return o=i?-1:1,ke(Vs(t,r,o),i);const s=[];for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`;d&&s.push(Number(xi(d).matchTxt))}return i&&(t.reverse(),s.reverse()),Hn(s)?(o=s[1]-s[0],ke(Vs(t,r,o),i)):It(t,r)}}},Md={type:Ie.CHN_NUMBER,priority:830,match:n=>!!gd(`${n==null?void 0:n.v}`||""),isContinue:(n,r)=>n.type===Ie.CHN_NUMBER,applyFunctions:{[ce.SERIES]:(n,r,e)=>{var c,d,u;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){const h=`${(c=t[0])==null?void 0:c.v}`;let g;return i?g=-1:g=1,h&&(h==="日"||Qe(h)<7)?ke(Zt(t,r,g),i):ke(Ws(t,r,g),i)}let o=!1;for(let h=0;h<t.length;h++)if(((d=t[h])==null?void 0:d.v)==="日"){o=!0;break}const s=[];let l=0;for(let h=0;h<t.length;h++){const g=`${(u=t[h])==null?void 0:u.v}`;g==="日"?h===0?s.push(0):(l++,s.push(l*7)):o&&Qe(g)>0&&Qe(g)<7?s.push(Qe(g)+l*7):s.push(Qe(g))}if(i&&(t.reverse(),s.reverse()),Hn(s)){if(o||s[s.length-1]<6&&s[0]>0||s[0]<6&&s[s.length-1]>0){const g=s[1]-s[0];return ke(Zt(t,r,g),i)}const h=s[1]-s[0];return ke(Ws(t,r,h),i)}return It(t,r)}}},Pd={type:Ie.CHN_WEEK2,priority:820,match:n=>!!Sd(`${n==null?void 0:n.v}`||""),isContinue:(n,r)=>n.type===Ie.CHN_WEEK2,applyFunctions:{[ce.SERIES]:(n,r,e)=>{var l;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let c;return i?c=-1:c=1,ke(Zt(t,r,c,1),i)}const o=[];let s=0;for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`,u=d==null?void 0:d.substr(d.length-1,1);d==="周日"?c===0?o.push(0):(s++,o.push(s*7)):o.push(Qe(u)+s*7)}if(i&&(t.reverse(),o.reverse()),Hn(o)){const c=o[1]-o[0];return ke(Zt(t,r,c,1),i)}return It(t,r)}}},Od={type:Ie.CHN_WEEK3,priority:810,match:n=>fd(`${n==null?void 0:n.v}`||""),isContinue:(n,r)=>n.type===Ie.CHN_WEEK3,applyFunctions:{[ce.SERIES]:(n,r,e)=>{var l;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let c;return i?c=-1:c=1,ke(Zt(t,r,c,2),i)}const o=[];let s=0;for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`;if(d){const u=d.substr(d.length-1,1);d==="星期日"?c===0?o.push(0):(s++,o.push(s*7)):o.push(Qe(u)+s*7)}}if(i&&(t.reverse(),o.reverse()),Hn(o)){const c=o[1]-o[0];return ke(Zt(t,r,c,2),i)}return It(t,r)}}},Ad={type:Ie.LOOP_SERIES,priority:800,match:n=>wd(`${n==null?void 0:n.v}`||""),isContinue:(n,r)=>{var e;return n.type===Ie.LOOP_SERIES?Yr(`${(e=n.cellData)==null?void 0:e.v}`||"").name===Yr(`${r==null?void 0:r.v}`||"").name:!1},applyFunctions:{[ce.SERIES]:(n,r,e)=>{var c,d;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP,{series:o}=Yr(`${(c=t[0])==null?void 0:c.v}`||"");if(t.length===1){let u;return i?u=-1:u=1,ke(xs(t,r,u,o),i)}const s=[];let l=0;for(let u=0;u<t.length;u++){const h=`${(d=t[u])==null?void 0:d.v}`;h&&(h===o[0]?u===0?s.push(0):(l++,s.push(l*o.length)):s.push(o.indexOf(h)+l*7))}if(i&&(t.reverse(),s.reverse()),Hn(s)){const u=s[1]-s[0];return ke(xs(t,r,u,o),i)}return It(t,r)}}};function ke(n,r){return r?n.reverse():n}var Dd=Object.getOwnPropertyDescriptor,kd=(n,r,e,t)=>{for(var i=t>1?void 0:t?Dd(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},qt=(n,r)=>(e,t)=>r(e,t,n);y.AutoFillService=class extends a.Disposable{constructor(e,t,i,o,s,l){super();T(this,"_rules",[]);T(this,"_hooks",[]);T(this,"_applyType$",new D.BehaviorSubject(ce.SERIES));T(this,"_isFillingStyle",!0);T(this,"_prevUndos",[]);T(this,"_autoFillLocation$",new D.BehaviorSubject(null));T(this,"autoFillLocation$",this._autoFillLocation$.asObservable());T(this,"_showMenu$",new D.BehaviorSubject(!1));T(this,"showMenu$",this._showMenu$.asObservable());T(this,"_direction",a.Direction.DOWN);T(this,"applyType$",this._applyType$.asObservable());T(this,"_menu$",new D.BehaviorSubject([{label:"autoFill.copy",value:ce.COPY,disable:!1},{label:"autoFill.series",value:ce.SERIES,disable:!1},{label:"autoFill.formatOnly",value:ce.ONLY_FORMAT,disable:!1},{label:"autoFill.noFormat",value:ce.NO_FORMAT,disable:!1}]));T(this,"menu$",this._menu$.asObservable());this._commandService=e,this._undoRedoService=t,this._renderManagerService=i,this._univerInstanceService=o,this._selectionManagerService=s,this._injector=l,this._init()}_init(){this._rules=[Td,yd,Rd,Md,Pd,Od,Ad,Us].sort((e,t)=>t.priority-e.priority),this._isFillingStyle=!0}_getOneByPriority(e){return e.length<=0?[]:[e.reduce((i,o)=>(o.priority||0)>(i.priority||0)?o:i,e[0])]}_initPrevUndo(){this._prevUndos=[]}async triggerAutoFill(e,t,i,o){var S;if(i.startColumn===o.startColumn&&i.startRow===o.startRow&&i.endColumn===o.endColumn&&i.endRow===o.endRow)return!1;if(o.endColumn<i.endColumn&&o.endColumn>i.startColumn)return this._commandService.executeCommand(Qt.id,{clearRange:{startRow:o.startRow,endRow:o.endRow,startColumn:o.endColumn+1,endColumn:i.endColumn},selectionRange:o});if(o.endRow<i.endRow&&o.endRow>i.startRow)return this._commandService.executeCommand(Qt.id,{clearRange:{startRow:o.endRow+1,endRow:i.endRow,startColumn:o.startColumn,endColumn:o.endColumn},selectionRange:o});const s={startRow:o.startRow,endRow:o.endRow,startColumn:o.startColumn,endColumn:o.endColumn};let l=null;if(o.startRow<i.startRow)l=a.Direction.UP,s.endRow=i.startRow-1;else if(o.endRow>i.endRow)l=a.Direction.DOWN,s.startRow=i.endRow+1;else if(o.startColumn<i.startColumn)l=a.Direction.LEFT,s.endColumn=i.startColumn-1;else if(o.endColumn>i.endColumn)l=a.Direction.RIGHT,s.startColumn=i.endColumn+1;else return!1;this.direction=l;const c=this._injector.invoke(f=>m.rangeToDiscreteRange(i,f)),d=this._injector.invoke(f=>m.rangeToDiscreteRange(s,f));if(!c||!d)return!1;this.autoFillLocation={source:c,target:d,unitId:e,subUnitId:t};const u=[];this.getActiveHooks().forEach(f=>{var p;const v=(p=f==null?void 0:f.onBeforeFillData)==null?void 0:p.call(f,{source:c,target:d,unitId:e,subUnitId:t},l);v&&u.unshift(v)}),this._initPrevUndo();for(let f=0;f<u.length;f++){const v=this.menu.find(p=>p.value===u[f]);if(v&&!v.disable)return this.fillData(u[f])}const g=(S=this.menu.find(f=>f.disable===!1))==null?void 0:S.value;return g?this.fillData(g):!1}addHook(e){if(this._hooks.find(t=>t.id===e.id))throw new Error(`Add hook failed, hook id '${e.id}' already exist!`);return e.priority===void 0&&(e.priority=0),e.type===void 0&&(e.type=Kt.Append),this._hooks.push(e),a.toDisposable(()=>{const t=this._hooks.findIndex(i=>i===e);t>-1&&this._hooks.splice(t,1)})}registerRule(e){if(this._rules.find(i=>i.type===e.type))throw new Error(`Registry rule failed, type '${e.type}' already exist!`);const t=this._rules.findIndex(i=>i.priority<e.priority);this._rules.splice(t===-1?this._rules.length:t,0,e)}getRules(){return this._rules}getAllHooks(){return this._hooks}getActiveHooks(){const{source:e,target:t,unitId:i,subUnitId:o}=this.autoFillLocation||{};if(!e||!t||!i||!o)return[];const s=this._hooks.filter(u=>{var h;return!((h=u.disable)!=null&&h.call(u,{source:e,target:t,unitId:i,subUnitId:o},this._direction,this.applyType))}),l=s.filter(u=>u.type===Kt.Only);if(l.length>0)return this._getOneByPriority(l);const c=this._getOneByPriority(s.filter(u=>u.type===Kt.Default)),d=s.filter(u=>u.type===Kt.Append)||[];return[...c,...d]}get applyType(){return this._applyType$.getValue()}set applyType(e){this._applyType$.next(e)}get menu(){return this._menu$.getValue()}get direction(){return this._direction}set direction(e){this._direction=e}isFillingStyle(){return this._isFillingStyle}setFillingStyle(e){this._isFillingStyle=e}get autoFillLocation(){return this._autoFillLocation$.getValue()}set autoFillLocation(e){this._autoFillLocation$.next(e)}setDisableApplyType(e,t){this._menu$.next(this._menu$.getValue().map(i=>i.value===e?{...i,disable:t}:i))}setShowMenu(e){this._showMenu$.next(e)}fillData(e){var C,b,E;this.applyType=e;const{source:t,target:i,unitId:o=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId(),subUnitId:s=(C=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:C.getSheetId()}=this.autoFillLocation||{};if(!t||!i||!o||!s)return!1;const l=this.direction;this._prevUndos.length>0&&this._prevUndos.forEach(w=>{this._commandService.syncExecuteCommand(w.id,w.params)}),this._prevUndos=[];const c=a.Rectangle.union(ct(t),ct(i)),d=this.getActiveHooks(),u=this._univerInstanceService.getUnit(o,a.UniverInstanceType.UNIVER_SHEET);this._commandService.syncExecuteCommand(m.SetSelectionsOperation.id,{selections:[{primary:{...(E=(b=this._selectionManagerService.getCurrentLastSelection())==null?void 0:b.primary)!=null?E:c},range:{...c,rangeType:a.RANGE_TYPE.NORMAL}}],unitId:o,subUnitId:s});const h=[],g=[];d.forEach(w=>{var P;const{undos:O,redos:M}=((P=w.onFillData)==null?void 0:P.call(w,{source:t,target:i,unitId:o,subUnitId:s},l,e))||{};O&&h.push(...O),M&&g.push(...M)});const S=g.every(w=>this._commandService.syncExecuteCommand(w.id,w.params)),f=[];e!==ce.NO_FORMAT&&g.forEach(w=>{if(w.id===m.SetRangeValuesMutation.id){const{cellValue:O}=w.params;new a.ObjectMatrix(O).forValue((P,A,k)=>{const N=Object.keys(u.getStyles().get(k==null?void 0:k.s)||{});(k!=null&&k.p||N.length&&ks.some(H=>N.includes(H)))&&f.push({startRow:P,endRow:P,startColumn:A,endColumn:A})})}});const v=this._getAutoHeightUndoRedos(o,s,f);return v.redos.every(w=>this._commandService.syncExecuteCommand(w.id,w.params))&&(h.push(...v.undos),g.push(...v.redos)),S&&(this._prevUndos=h,this._undoRedoService.pushUndoRedo({unitID:o,undoMutations:h,redoMutations:g})),d.forEach(w=>{var O;(O=w.onAfterFillData)==null||O.call(w,{source:t,target:i,unitId:o,subUnitId:s},l,e)}),this.setShowMenu(!0),!0}_getAutoHeightUndoRedos(e,t,i){var h,g;const o=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(y.SheetSkeletonManagerService),s=(g=o==null?void 0:o.getCurrentParam())==null?void 0:g.skeleton;if(!s)return{redos:[],undos:[]};const l=s.calculateAutoHeightInRange(i),c={subUnitId:t,unitId:e,rowsAutoHeightInfo:l},d=s.worksheet,u=m.SetWorksheetRowAutoHeightMutationFactory(c,d);return{undos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:u}],redos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:c}]}}},y.AutoFillService=kd([qt(0,a.ICommandService),qt(1,a.IUndoRedoService),qt(2,R.IRenderManagerService),qt(3,a.Inject(a.IUniverInstanceService)),qt(4,a.Inject(m.SheetsSelectionsService)),qt(5,a.Inject(a.Injector))],y.AutoFillService);const ut=a.createIdentifier("univer.auto-fill-service"),ht={type:a.CommandType.COMMAND,id:"sheet.command.auto-fill",handler:async(n,r)=>{const e=n.get(ut),t=n.get(a.IUniverInstanceService),{sourceRange:i,targetRange:o}=r,s=m.getSheetCommandTarget(t);if(!s)return!1;const{subUnitId:l,unitId:c}=s;return e.triggerAutoFill(c,l,i,o)}},Qt={id:"sheet.command.auto-clear-content",type:a.CommandType.COMMAND,handler:async(n,r)=>{const e=n.get(a.IUniverInstanceService),t=n.get(a.ICommandService),i=n.get(a.IUndoRedoService),o=n.get(m.SheetInterceptorService),s=m.getSheetCommandTarget(e);if(!s)return!1;const{unitId:l,subUnitId:c}=s,{clearRange:d,selectionRange:u}=r,h={subUnitId:c,unitId:l,cellValue:m.generateNullCellValue([d])},g=m.SetRangeValuesUndoMutationFactory(n,h),{startColumn:S,startRow:f}=u,v={selections:[{primary:{startColumn:S,startRow:f,endColumn:S,endRow:f,actualRow:f,actualColumn:S,isMerged:!1,isMergedMainCell:!1},range:{...u}}],unitId:l,subUnitId:c};if(t.executeCommand(m.SetSelectionsOperation.id,v),t.syncExecuteCommand(m.SetRangeValuesMutation.id,h)){const C=o.afterCommandExecute({id:m.SetRangeValuesMutation.id,params:h});return a.sequenceExecute(C.redos,t),i.pushUndoRedo({unitID:l,undoMutations:[{id:m.SetRangeValuesMutation.id,params:g},...C.undos],redoMutations:[{id:m.SetRangeValuesMutation.id,params:h},...C.redos]}),!0}return!1}},Wn={id:"sheet.command.refill",type:a.CommandType.COMMAND,handler:async(n,r)=>n.get(ut).fillData(r.type)};var Nd=Object.getOwnPropertyDescriptor,Hd=(n,r,e,t)=>{for(var i=t>1?void 0:t?Nd(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},Jt=(n,r)=>(e,t)=>r(e,t,n);y.EditorBridgeService=class extends a.Disposable{constructor(e,t,i,o,s,l){super();T(this,"_editorUnitId",a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);T(this,"_editorIsDirty",!1);T(this,"_visibleParams",{visible:!1,eventType:R.DeviceInputEventType.Dblclick,unitId:""});T(this,"_currentEditCell",null);T(this,"_currentEditCellState",null);T(this,"_currentEditCellLayout",null);T(this,"helpFunctionVisible$",new D.BehaviorSubject(!0));T(this,"_currentEditCellState$",new D.BehaviorSubject(null));T(this,"currentEditCellState$",this._currentEditCellState$.asObservable());T(this,"_currentEditCellLayout$",new D.BehaviorSubject(null));T(this,"currentEditCellLayout$",this._currentEditCellLayout$.asObservable());T(this,"currentEditCell$",this._currentEditCellState$.pipe(D.switchMap(e=>this._currentEditCellLayout$.pipe(D.map(t=>e&&t?{...e,...t}:null)))));T(this,"_visibleParams$",new D.BehaviorSubject(this._visibleParams));T(this,"visible$",this._visibleParams$.asObservable());T(this,"_afterVisibleParams$",new D.BehaviorSubject(this._visibleParams));T(this,"afterVisible$",this._afterVisibleParams$.asObservable());T(this,"_forceKeepVisible$",new D.BehaviorSubject(!1));T(this,"forceKeepVisible$",this._forceKeepVisible$.asObservable());this._sheetInterceptorService=e,this._renderManagerService=t,this._themeService=i,this._univerInstanceService=o,this._editorService=s,this._contextService=l,this.disposeWithMe(a.toDisposable(()=>{this._currentEditCellState$.complete(),this._currentEditCell=null})),this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).subscribe(c=>{var d;c.getUnitId()===((d=this._currentEditCellState)==null?void 0:d.unitId)&&this._clearCurrentEditCellState()})}refreshEditCellState(){const e=this.getLatestEditCellState();if(!e){this._currentEditCellState=null,this._currentEditCellLayout=null,this._currentEditCellState$.next(null),this._currentEditCellLayout$.next(null);return}const{position:t,scaleX:i,scaleY:o,canvasOffset:s,...l}=e;this._currentEditCellState=l,this._currentEditCellLayout={position:t,scaleX:i,scaleY:o,canvasOffset:s},this._currentEditCellState$.next(this._currentEditCellState),this._currentEditCellLayout$.next(this._currentEditCellLayout)}refreshEditCellPosition(e){var O;const t=this._currentEditCell;if(t==null)return;const i=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!i)return;const o=this._renderManagerService.getRenderUnitById(i.getUnitId());if(!o)return;const s=(O=o.with(y.SheetSkeletonManagerService).getSkeletonParam(t.sheetId))==null?void 0:O.skeleton,l=o.with(ve);if(!s||!this._currentEditCellState)return;const{primary:c,scene:d,engine:u}=t,h=Dn(s,c);if(h==null)return;const g=a.convertCellToRange(h),S=q.getCanvasOffsetByEngine(u);let{startX:f,startY:v,endX:p,endY:C}=g;const{scaleX:b,scaleY:E}=d.getAncestorScale(),w=d.getViewportScrollXY(l.getViewPort());f=R.convertTransformToOffsetX(f,b,w),v=R.convertTransformToOffsetY(v,E,w),p=R.convertTransformToOffsetX(p,b,w),C=R.convertTransformToOffsetY(C,E,w),e&&this._currentEditCellLayout&&(p=p-f+this._currentEditCellLayout.position.startX,C=C-v+this._currentEditCellLayout.position.startY,f=this._currentEditCellLayout.position.startX,v=this._currentEditCellLayout.position.startY),this._currentEditCellLayout={position:{startX:f,startY:v,endX:p,endY:C},canvasOffset:S,scaleX:b,scaleY:E},this._currentEditCellLayout$.next(this._currentEditCellLayout)}setEditCell(e){this._currentEditCell=e,this._editorService.getFocusEditor()||(this._editorService.focus(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._contextService.setContextValue(a.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(a.FOCUSING_EDITOR_STANDALONE,!1));const t=this.getLatestEditCellState();if(!t){this._currentEditCellState=t,this._currentEditCellLayout=t,this._currentEditCellState$.next(t),this._currentEditCellLayout$.next(t);return}const{position:i,canvasOffset:o,scaleX:s,scaleY:l,...c}=t;this._currentEditCellState=c,this._currentEditCellLayout={position:i,canvasOffset:o,scaleX:s,scaleY:l},this._currentEditCellState$.next(this._currentEditCellState),this._currentEditCellLayout$.next(this._currentEditCellLayout)}_clearCurrentEditCellState(){this._currentEditCellState=null,this._currentEditCellState$.next(null),this._currentEditCellLayout=null,this._currentEditCellLayout$.next(null)}getEditCellState(){return this._currentEditCellState==null||this._currentEditCellLayout==null?null:{...this._currentEditCellState,...this._currentEditCellLayout}}getEditCellLayout(){return this._currentEditCellLayout}getEditLocation(){return this._currentEditCellState}updateEditLocation(e,t){this._currentEditCellState&&(this._currentEditCellState={...this._currentEditCellState,row:e,column:t})}getLatestEditCellState(){var L,V,U;const e=this._currentEditCell;if(e==null)return;const t=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!t)return;const i=this._renderManagerService.getRenderUnitById(t.getUnitId());if(!i)return;const o=i.with(y.SheetSkeletonManagerService).getCurrentSkeleton(),s=i.with(ve);if(!o)return;const{primary:l,unitId:c,sheetId:d,scene:u,engine:h}=e,{startRow:g,startColumn:S}=l,f=Dn(o,l);if(f==null)return;const v=a.convertCellToRange(f),p=q.getCanvasOffsetByEngine(h);let{startX:C,startY:b,endX:E,endY:w}=v;const{scaleX:O,scaleY:M}=u.getAncestorScale(),P=u.getViewportScrollXY(s.getViewPort());C=R.convertTransformToOffsetX(C,O,P),b=R.convertTransformToOffsetY(b,M,P),E=R.convertTransformToOffsetX(E,O,P),w=R.convertTransformToOffsetY(w,M,P);const A=t.getActiveSheet();if(!A)return;const k={workbook:t,worksheet:A,unitId:t.getUnitId(),subUnitId:A.getSheetId(),row:g,col:S,origin:A.getCellRaw(g,S)};let N;const H=this._sheetInterceptorService.writeCellInterceptor.fetchThroughInterceptors(m.BEFORE_CELL_EDIT)(A.getCell(g,S),k);N=H&&A.getCellDocumentModelWithFormula(H,k.row,k.col);const x=(L=N==null?void 0:N.documentModel)==null?void 0:L.documentStyle.renderConfig;if(x!=null&&(x.cellValueType=a.CellValueType.STRING),!N||N.documentModel==null){const B=A.getBlankCellDocumentModel(H,k.row,k.col);if(N!=null){const{verticalAlign:Y,horizontalAlign:F,wrapStrategy:z,textRotation:j,fill:Q}=N,{centerAngle:ie,vertexAngle:$}=R.convertTextRotation(j);B.documentModel.documentStyle.renderConfig={...x,verticalAlign:Y,horizontalAlign:F,wrapStrategy:z,background:{rgb:Q},centerAngle:ie,vertexAngle:$}}N=B}if(N.fill=N.fill||"#fff",(V=N.documentModel)==null||V.setZoomRatio(Math.max(O,M)),(H==null?void 0:H.isInArrayFormulaRange)===!0){const B=(U=N.documentModel)==null?void 0:U.getBody();B&&(B.textRuns=[{st:0,ed:B.dataStream.length-2,ts:{cl:{rgb:this._themeService.getColorFromTheme("gray.600")}}}])}return{position:{startX:C,startY:b,endX:E,endY:w},scaleX:O,scaleY:M,canvasOffset:p,row:g,column:S,unitId:c,sheetId:d,documentLayoutObject:N,editorUnitId:this._editorUnitId,isInArrayFormulaRange:H==null?void 0:H.isInArrayFormulaRange}}getCurrentEditorId(){return this._editorUnitId}changeVisible(e){this._visibleParams=e,e.visible&&(this._editorIsDirty=!1),this._visibleParams$.next(this._visibleParams),this._afterVisibleParams$.next(this._visibleParams)}isVisible(){return this._visibleParams}enableForceKeepVisible(){this._forceKeepVisible$.next(!0)}disableForceKeepVisible(){this._forceKeepVisible$.next(!1)}isForceKeepVisible(){return this._forceKeepVisible$.getValue()}changeEditorDirty(e){this._editorIsDirty=e}getEditorDirty(){return this._editorIsDirty}},y.EditorBridgeService=Hd([Jt(0,a.Inject(m.SheetInterceptorService)),Jt(1,R.IRenderManagerService),Jt(2,a.Inject(a.ThemeService)),Jt(3,a.IUniverInstanceService),Jt(4,q.IEditorService),Jt(5,a.IContextService)],y.EditorBridgeService);const me=a.createIdentifier("univer.sheet-editor-bridge.service"),ge={id:"sheet.operation.set-cell-edit-visible",type:a.CommandType.OPERATION,handler:(n,r)=>{if(!r)return!1;const{unitId:e}=r,i=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);return i?(n.get(me).changeVisible({...r,unitId:e!=null?e:i.getUnitId()}),!0):!1}},xn={id:"sheet.operation.set-cell-edit-visible-f2",type:a.CommandType.OPERATION,handler:(n,r)=>{const e=n.get(a.ICommandService),i=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);return i?e.syncExecuteCommand(ge.id,{...r,unitId:i.getUnitId()}):!1}},wt={id:"sheet.operation.set-cell-edit-visible-arrow",type:a.CommandType.OPERATION,handler:()=>!0},$t={id:"sheet.command.change-zoom-ratio",type:a.CommandType.COMMAND,handler:(n,r)=>{if(!r)return!1;const e=n.get(a.IUniverInstanceService),t=m.getSheetCommandTarget(e);if(!t)return!1;const{worksheet:i,subUnitId:o,unitId:s}=t,{delta:l,reset:c}=r;let d=c?100:Math.round((i.getConfig().zoomRatio+l)*100);d=Math.max(Hr[0],d),d=Math.min(Hr[1],d);const u=d/100,g=n.get(me).isVisible();return(g.unitId===s||g.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&g.visible?!1:n.get(a.ICommandService).executeCommand(He.id,{unitId:s,subUnitId:o,zoomRatio:u})}},en={id:"sheet.command.set-zoom-ratio",type:a.CommandType.COMMAND,handler:(n,r)=>{if(!r)return!1;const{unitId:e,subUnitId:t,zoomRatio:i}=r,s=n.get(me).isVisible();return(s.unitId===e||s.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&s.visible?!1:n.get(a.ICommandService).executeCommand(He.id,{unitId:e,subUnitId:t,zoomRatio:i})}};function Vd(n){return typeof n.isMainScene>"u"}function Ne(n,r){const e=n instanceof a.Workbook?n:n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!e)return null;const t=e.getUnitId();let i,o,s,l;if(Vd(r)){const g=r.getRenderById(t);if(g==null)return null;i=g.components,i=g.components,o=g.mainComponent,s=g.scene,l=g.engine}else i=r.components,o=r.mainComponent,s=r.scene,l=r.engine;if(!i||!o)return null;const c=o,d=i.get(he.ROW),u=i.get(he.COLUMN),h=i.get(he.LEFT_TOP);return{spreadsheet:c,spreadsheetRowHeader:d,spreadsheetColumnHeader:u,spreadsheetLeftTopPlaceholder:h,scene:s,engine:l}}function jr(n,r,e,t){const{startX:i,startY:o,endX:s,endY:l}=t.getCellWithCoordByIndex(n,r);return{startX:i,startY:o,endX:s,endY:l}}function ze(n,r,e,t,i,o){const s=e.getCoordRelativeToViewport(R.Vector2.FromArray([n,r])),{x:l,y:c}=s,d=e.getScrollXYInfoByViewport(s,i),{scaleX:u,scaleY:h}=e.getAncestorScale(),g=t.getCellIndexByOffset(l,c,u,h,d,{closeFirst:o}),{row:S,column:f}=g,v=t.getNoMergeCellWithCoordByIndex(S,f),{startX:p,startY:C,endX:b,endY:E}=v;return{startX:p,startY:C,endX:b,endY:E,row:S,column:f}}function Ln(n,r,e,t){const i=e.getCoordRelativeToViewport(R.Vector2.FromArray([n,r])),o=e.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN),s=e.getScrollXYInfoByViewport(i,o),{scaleX:l,scaleY:c}=e.getAncestorScale(),{x:d,y:u}=s,h=n/l+d,g=r/c+u;return{x:h,y:g}}var Wd=Object.getOwnPropertyDescriptor,xd=(n,r,e,t)=>{for(var i=t>1?void 0:t?Wd(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},Ui=(n,r)=>(e,t)=>r(e,t,n);let Un=class extends a.Disposable{constructor(r,e,t,i,o){super();T(this,"_zoom");this._context=r,this._sheetSkeletonManagerService=e,this._commandService=t,this._contextService=i,this._editorBridgeService=o,this._initSkeletonListener(),this._initZoomEventListener()}updateZoom(r,e){const t=this._context.unit.getSheetBySheetId(r);return t?(t.getConfig().zoomRatio=e,t===this._context.unit.getActiveSheet()&&this._updateViewZoom(e),!0):!1}_initZoomEventListener(){const r=Ne(this._context.unit,this._context).scene;this.disposeWithMe(r.onMouseWheel$.subscribeEvent(e=>{if(!e.ctrlKey||!this._contextService.getContextValue(a.FOCUSING_SHEET))return;if(this._editorBridgeService){const d=this._editorBridgeService.isVisible();if((d.unitId===this._context.unitId||d.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&d.visible)return}const t=Math.abs(e.deltaX);let i=t<40?.2:t<80?.4:.2;i*=e.deltaY>0?-1:1,r.scaleX<1&&(i/=2);const o=this._context.unit,s=o.getActiveSheet();if(!s)return;const l=s.getZoomRatio();let c=+Number.parseFloat(`${l+i}`).toFixed(1);c=c>=4?4:c<=.1?.1:c,this._commandService.executeCommand(en.id,{zoomRatio:Math.round(c*10)/10,unitId:o.getUnitId(),subUnitId:s.getSheetId()}),e.preventDefault()}))}_initSkeletonListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(r=>{if(r==null)return;const t=this._context.unit.getActiveSheet();if(!t)return;const i=t.getZoomRatio()||1;this._zoom!==i&&this._updateViewZoom(i)}))}_updateViewZoom(r){this._zoom=r;const e=Ne(this._context.unit,this._context);e==null||e.scene.scale(r,r),e==null||e.spreadsheet.makeForceDirty()}};Un=xd([Ui(1,a.Inject(y.SheetSkeletonManagerService)),Ui(2,a.ICommandService),Ui(3,a.IContextService),Ui(4,a.Optional(me))],Un);const He={id:"sheet.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(n,r)=>{const t=n.get(R.IRenderManagerService).getRenderById(r.unitId);return t?t.with(Un).updateZoom(r.subUnitId,r.zoomRatio):!1}};var Ld=Object.getOwnPropertyDescriptor,Ud=(n,r,e,t)=>{for(var i=t>1?void 0:t?Ld(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},Bi=(n,r)=>(e,t)=>r(e,t,n);const Bs="univer-sheet-main-canvas";y.SheetsRenderService=class extends a.RxDisposable{constructor(e,t,i,o){super();T(this,"_skeletonChangeMutations",new Set);this._contextService=e,this._instanceSrv=t,this._renderManagerService=i,this._themeService=o,Promise.resolve().then(()=>this._init())}registerSkeletonChangingMutations(e){return this._skeletonChangeMutations.has(e)?a.toDisposable(()=>{}):(this._skeletonChangeMutations.add(e),a.toDisposable(()=>this._skeletonChangeMutations.delete(e)))}checkMutationShouldTriggerRerender(e){return this._skeletonChangeMutations.has(e)}_init(){this._initWorkbookListener(),this._initContextListener()}_initWorkbookListener(){this._instanceSrv.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET).pipe(D.takeUntil(this.dispose$)).subscribe(e=>this._createRenderer(e)),this._instanceSrv.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(e=>this._createRenderer(e)),this._instanceSrv.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).pipe(D.takeUntil(this.dispose$)).subscribe(e=>this._disposeRenderer(e))}_createRenderer(e){const t=e.getUnitId();this._renderManagerService.created$.subscribe(i=>{i.unitId===t&&(i.engine.getCanvas().setId(`${Bs}_${t}`),i.engine.getCanvas().getContext().setId(`${Bs}_${t}`))}),this._renderManagerService.createRender(t)}_disposeRenderer(e){const t=e.getUnitId();this._renderManagerService.removeRender(t)}_initContextListener(){this.disposeWithMe(this._contextService.subscribeContextValue$(R.RENDER_RAW_FORMULA_KEY).pipe(D.distinctUntilChanged()).subscribe(()=>{this._renderManagerService.getRenderAll().forEach(e=>{e.mainComponent instanceof R.Spreadsheet&&e.mainComponent.makeForceDirty(!0)})}))}},y.SheetsRenderService=Ud([Bi(0,a.IContextService),Bi(1,a.IUniverInstanceService),Bi(2,R.IRenderManagerService),Bi(3,a.Inject(a.ThemeService))],y.SheetsRenderService);var Bd=Object.getOwnPropertyDescriptor,Fd=(n,r,e,t)=>{for(var i=t>1?void 0:t?Bd(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},Et=(n,r)=>(e,t)=>r(e,t,n);y.AutoFillController=class extends a.Disposable{constructor(e,t,i,o,s,l,c){super();T(this,"_beforeApplyData",[]);T(this,"_currentLocation",null);T(this,"_copyData",[]);T(this,"_defaultHook");this._univerInstanceService=e,this._commandService=t,this._autoFillService=i,this._editorBridgeService=o,this._renderManagerService=s,this._injector=l,this._sheetsRenderService=c,this._defaultHook={id:"default",type:Kt.Default,priority:0,onBeforeFillData:(d,u)=>this._presetAndCacheData(d,u),onFillData:(d,u,h)=>this._fillData(d,u,h)},this._init()}_init(){this._initDefaultHook(),this._initSelectionControlFillChanged(),this._initQuitListener(),this._initSkeletonChange()}_initSkeletonChange(){this.disposeWithMe(this._sheetsRenderService.registerSkeletonChangingMutations(ht.id))}_initDefaultHook(){this.disposeWithMe(this._autoFillService.addHook(this._defaultHook))}_initQuitListener(){const e=[ge.id,Qt.id,m.SetRangeValuesCommand.id,He.id,m.SetWorksheetActiveOperation.id,m.MoveRangeMutation.id,m.RemoveRowMutation.id,m.RemoveColMutation.id,m.InsertRowMutation.id,m.InsertColMutation.id,m.MoveRowsMutation.id,m.MoveColsMutation.id,m.SetWorksheetColWidthMutation.id,m.SetWorksheetRowHeightMutation.id,m.SetRangeValuesMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted((t,i)=>{var c,d;const o=i==null?void 0:i.fromCollab,s=i==null?void 0:i.fromSync,l=i==null?void 0:i.fromFormula;e.includes(t.id)&&!o&&!s&&!l&&t.params.trigger!==ht.id&&t.params.trigger!==Wn.id&&this._quit(),t.id===m.RemoveSheetMutation.id&&t.params.unitId===((c=this._currentLocation)==null?void 0:c.unitId)&&t.params.subUnitId===((d=this._currentLocation)==null?void 0:d.subUnitId)&&this._quit()})),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{var i;t.getUnitId()===((i=this._currentLocation)==null?void 0:i.unitId)&&this._quit()}))}_quit(){this._currentLocation=null,this._beforeApplyData=[],this._copyData=[],this._autoFillService.setShowMenu(!1)}_initSelectionControlFillChanged(){const e=new a.DisposableCollection,t=()=>{e.dispose();const i=R.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService);if(!i)return;i.with(ve).getSelectionControls().forEach(l=>{e.add(l.selectionFilled$.subscribe(c=>{if(c==null||c.startColumn===-1||c.startRow===-1||c.endColumn===-1||c.endRow===-1)return;const d={startColumn:l.model.startColumn,endColumn:l.model.endColumn,startRow:l.model.startRow,endRow:l.model.endRow},u={startColumn:c.startColumn,endColumn:c.endColumn,startRow:c.startRow,endRow:c.endRow};this._commandService.executeCommand(ht.id,{sourceRange:d,targetRange:u})})),e.add(l.fillControl.onDblclick$.subscribeEvent(()=>{const c={startColumn:l.model.startColumn,endColumn:l.model.endColumn,startRow:l.model.startRow,endRow:l.model.endRow};this._handleDbClickFill(c)})),e.add(l.fillControl.onPointerDown$.subscribeEvent(()=>{this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(ge.id,{visible:!1,eventType:R.DeviceInputEventType.PointerDown,unitId:i.unitId})}))})};t(),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===m.SetSelectionsOperation.id&&t()})),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(()=>t()))}_handleDbClickFill(e){const t=this._detectFillRange(e);t.endRow<=e.endRow||this._commandService.executeCommand(ht.id,{sourceRange:e,targetRange:t})}_detectFillRange(e){var g,S,f,v,p,C;const{startRow:t,endRow:i,startColumn:o,endColumn:s}=e,l=(g=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET))==null?void 0:g.getActiveSheet();if(!l)return e;const c=l.getCellMatrix(),d=l.getMaxRows()-1,u=l.getMaxColumns()-1;let h=i;if(o>0&&((S=c.getValue(t,o-1))==null?void 0:S.v)!=null){let b=t;for(;((f=c.getValue(b,o-1))==null?void 0:f.v)!=null&&b<d;)b+=1;h=b-1}else if(s<u&&((v=c.getValue(i,s+1))==null?void 0:v.v)!=null){let b=t;for(;((p=c.getValue(b,s+1))==null?void 0:p.v)!=null&&b<d;)b+=1;h=b-1}for(let b=i+1;b<=h;b++)for(let E=o;E<=s;E++)if(((C=c.getValue(b,E))==null?void 0:C.v)!=null){h=b-1;break}return{startColumn:o,endColumn:s,startRow:t,endRow:h}}_getApplyData(e,t,i,o,s,l=!0,c){const d=[],u=Math.floor(i/t),h=i%t,g=this._autoFillService.getRules();if(!l&&s===ce.ONLY_FORMAT)return console.error("ERROR: only format can not be applied when hasStyle is false"),[];const S={};g.forEach(f=>{S[f.type]=[]}),g.forEach(f=>{const{type:v,applyFunctions:p={}}=f,C=e[v];C&&C.forEach(b=>{const E=vd(b.index,h),w=b.index.length*u+E,O=this._applyFunctions(b,w,o,s,p,e,c),M=pd(t,i,b.index);S[v].push({data:O,index:M})})});for(let f=0;f<i;f++)g.forEach(v=>{const{type:p}=v,C=S[p];for(let b=0;b<C.length;b++)f in C[b].index&&d.push(C[b].data[C[b].index[f]])});return d}_applyFunctions(e,t,i,o,s,l,c){const{data:d}=e,u=i===a.Direction.UP||i===a.Direction.LEFT;if(o===ce.COPY){const h=s==null?void 0:s[ce.COPY];return h?h(e,t,i,l,c):(u&&d.reverse(),It(d,t))}if(o===ce.SERIES){const h=s==null?void 0:s[ce.SERIES];return h?h(e,t,i,l):(u&&d.reverse(),s!=null&&s[ce.COPY]?s[ce.COPY](e,t,i,l,c):It(d,t))}if(o===ce.ONLY_FORMAT){const h=s==null?void 0:s[ce.ONLY_FORMAT];return h?h(e,t,i,l):Cd(d,t)}}_getCopyData(e,t){const i=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!i)throw new Error("No active sheet found");const o=i.getCellMatrix(),s=this._autoFillService.getRules(),l=[],c=t===a.Direction.DOWN||t===a.Direction.UP;let d,u;return c?(d=e.cols,u=e.rows):(d=e.rows,u=e.cols),d.forEach(h=>{const g=this._getEmptyCopyDataPiece(),S={type:void 0,cellData:void 0};u.forEach(f=>{let v;c?v=o.getValue(f,h):v=o.getValue(h,f);const{type:p,isContinue:C}=s.find(b=>b.match(v,this._injector))||Us;if(C(S,v)){const b=g[p],E=b[b.length-1];E.data.push(v),E.index.push(f-u[0])}else{const b=g[p];b?b.push({data:[v],index:[f-u[0]]}):g[p]=[{data:[v],index:[f-u[0]]}]}S.type=p,S.cellData=v}),l.push(g)}),l}_getEmptyCopyDataPiece(){const e={};return this._autoFillService.getRules().forEach(t=>{e[t.type]=[]}),e}_getMergeApplyData(e,t,i,o){const s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!s)throw new Error("No active sheet found");const l=[];for(let c=e.startRow;c<=e.endRow;c++)for(let d=e.startColumn;d<=e.endColumn;d++){const{isMergedMainCell:u,startRow:h,startColumn:g,endRow:S,endColumn:f}=s.getCellInfoInMergeData(c,d);if(u){if(i===a.Direction.DOWN){let v=h+o,p=S+o;for(;p<=t.endRow;)l.push({startRow:v,startColumn:g,endRow:p,endColumn:f}),v+=o,p+=o}else if(i===a.Direction.UP){let v=h-o,p=S-o;for(;v>=t.startRow;)l.push({startRow:v,startColumn:g,endRow:p,endColumn:f}),v-=o,p-=o}else if(i===a.Direction.RIGHT){let v=g+o,p=f+o;for(;p<=t.endColumn;)l.push({startRow:h,startColumn:v,endRow:S,endColumn:p}),v+=o,p+=o}else if(i===a.Direction.LEFT){let v=g-o,p=f-o;for(;v>=t.startColumn;)l.push({startRow:h,startColumn:v,endRow:S,endColumn:p}),v-=o,p-=o}}}return l}_presetAndCacheData(e,t){const{source:i,target:o}=e,s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!s)throw new Error("No active sheet found");const l=s.getCellMatrix(),c=[];return o.rows.forEach(d=>{const u=[];o.cols.forEach(h=>{u.push(a.Tools.deepClone(l.getValue(d,h)))}),c.push(u)}),this._beforeApplyData=c,this._copyData=this._getCopyData(i,t),this._currentLocation=e,this._shouldDisableSeries(this._copyData)?(this._autoFillService.setDisableApplyType(ce.SERIES,!0),ce.COPY):(this._autoFillService.setDisableApplyType(ce.SERIES,!1),this._getPreferredApplyType(this._copyData))}_fillData(e,t,i){var L,V;const o=[],s=[];let l=!0;i===ce.NO_FORMAT&&(l=!1,i=ce.SERIES);const{source:c,target:d,unitId:u,subUnitId:h}=e;if(!c||!d||t==null)return{undos:o,redos:s};const g=ct(c),S=ct(d),{cols:f,rows:v}=d,{cols:p,rows:C}=c,b=this._copyData;let E;t===a.Direction.DOWN||t===a.Direction.UP?E=C.length:E=p.length;const w=[];if(t===a.Direction.DOWN||t===a.Direction.UP){const U=v.length,B=[];f.forEach((Y,F)=>{const z=b[F],j=this._getApplyData(z,E,U,t,i,l,e);B.push(j)});for(let Y=0;Y<B[0].length;Y++){const F=[];for(let z=0;z<B.length;z++)F.push({s:null,...B[z][Y]});w.push(F)}}else{const U=f.length;v.forEach((B,Y)=>{const F=b[Y],z=this._getApplyData(F,E,U,t,i,l,e),j=[];for(let Q=0;Q<z.length;Q++)j.push({s:null,...z[Q]});w.push(j)})}let O=[];const M=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getStyles();if(l?(O=this._getMergeApplyData(g,S,t,E),w.forEach(U=>{U.forEach(B=>{B&&M&&M&&(B.s=M.getStyleByCell(B))})})):w.forEach((U,B)=>{U.forEach((Y,F)=>{Y&&M&&(Y.s=M.getStyleByCell(this._beforeApplyData[B][F])||null)})}),i===ce.ONLY_FORMAT&&w.forEach((U,B)=>{U.forEach((Y,F)=>{if(Y){const z=this._beforeApplyData[B][F]||{};Y.f=z.f,Y.si=z.si,Y.t=z.t,Y.v=z.v}})}),l){const U=[],B=(V=(L=this._univerInstanceService.getUniverSheetInstance(u))==null?void 0:L.getSheetBySheetId(h))==null?void 0:V.getMergeData();B&&B.forEach(z=>{a.Rectangle.intersects(z,S)&&U.push(z)});const Y={unitId:u,subUnitId:h,ranges:U},F=this._injector.invoke(m.RemoveMergeUndoMutationFactory,Y);U.length&&(s.push({id:m.RemoveWorksheetMergeMutation.id,params:Y}),o.unshift({id:m.AddWorksheetMergeMutation.id,params:F}))}const P={subUnitId:h,unitId:u,cellValue:dd([d])},A=this._injector.invoke(m.SetRangeValuesUndoMutationFactory,P);s.push({id:m.SetRangeValuesMutation.id,params:P}),o.unshift({id:m.SetRangeValuesMutation.id,params:A});const k=new a.ObjectMatrix;v.forEach((U,B)=>{f.forEach((Y,F)=>{w[B][F]&&k.setValue(U,Y,w[B][F])})});const N=k.getMatrix(),H={subUnitId:h,unitId:u,cellValue:N},x=this._injector.invoke(m.SetRangeValuesUndoMutationFactory,H);if(this._autoFillService.getActiveHooks().forEach(U=>{var B;(B=U.onBeforeSubmit)==null||B.call(U,e,t,i,N)}),o.unshift({id:m.SetRangeValuesMutation.id,params:x}),s.push({id:m.SetRangeValuesMutation.id,params:H}),O!=null&&O.length){const U=m.getAddMergeMutationRangeByType(O),B={unitId:u,subUnitId:h,ranges:U},Y=this._injector.invoke(m.AddMergeUndoMutationFactory,B);o.unshift({id:m.RemoveWorksheetMergeMutation.id,params:Y}),s.push({id:m.AddWorksheetMergeMutation.id,params:B})}return{undos:o,redos:s}}_shouldDisableSeries(e){return e.every(t=>Object.keys(t).every(i=>{var o;return((o=t[i])==null?void 0:o.length)===0||[Ie.OTHER,Ie.FORMULA].includes(i)}))}_getPreferredApplyType(e){return e.every(i=>Object.keys(i).every(o=>{var s,l;return((s=i[o])==null?void 0:s.length)===0||((l=i[o])==null?void 0:l.length)===1&&i[o][0].data.length===1&&Ie.NUMBER===o}))?ce.COPY:ce.SERIES}},y.AutoFillController=Fd([Et(0,a.IUniverInstanceService),Et(1,a.ICommandService),Et(2,ut),Et(3,me),Et(4,R.IRenderManagerService),Et(5,a.Inject(a.Injector)),Et(6,a.Inject(y.SheetsRenderService))],y.AutoFillController);var zd=Object.getOwnPropertyDescriptor,Xd=(n,r,e,t)=>{for(var i=t>1?void 0:t?zd(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},Gr=(n,r)=>(e,t)=>r(e,t,n);y.CellCustomRenderController=class extends a.Disposable{constructor(e,t,i,o){super();T(this,"_enterActiveRender");this._context=e,this._sheetSkeletonManagerService=t,this._renderManagerService=i,this._permissionService=o,this._initEventBinding()}_initEventBinding(){const e=new a.DisposableCollection,t=this._context.unit,i=o=>{if(e.dispose(),!o)return;const s=this._context.unitId,{skeleton:l}=o,c=this._renderManagerService.getRenderById(s);if(c&&c.mainComponent){const d=c.mainComponent,u=S=>{const{offsetX:f,offsetY:v}=S,p=c.scene,C=t.getActiveSheet();if(!C)return;const b=p.getActiveViewportByCoord(R.Vector2.FromArray([f,v]));if(!b)return;const{scaleX:E,scaleY:w}=p.getAncestorScale(),O={x:b.viewportScrollX,y:b.viewportScrollY},M=l.getCellIndexByOffset(f,v,E,w,O),P=l.worksheet.getMergedCell(M.row,M.column),A={actualRow:P?P.startRow:M.row,actualCol:P?P.startColumn:M.column,row:M.row,col:M.column};if(!A||!l)return;const k=C.getCell(A.actualRow,A.actualCol);if(!k)return;const N=k.customRender;if(!(N!=null&&N.length))return;const H=A.actualRow,x=A.actualCol,L=N.sort(a.sortRules),V=C.getSheetId(),U={data:k,style:l.getStyles().getStyleByCell(k),primaryWithCoord:l.getCellWithCoordByIndex(A.actualRow,A.actualCol),unitId:s,subUnitId:V,row:H,col:x,workbook:t,worksheet:C},B={x:O.x+f/E,y:O.y+v/w},Y=L.find(F=>{var z;return(z=F.isHit)==null?void 0:z.call(F,B,U)});if(Y)return[Y,U]},h=d.onPointerDown$.subscribeEvent(S=>{var v,p,C,b;const f=u(S);if(f){const[E,w]=f,{row:O,col:M,worksheet:P,unitId:A,subUnitId:k}=w;if(!((v=this._permissionService.composePermission([new m.WorkbookEditablePermission(A).id,new m.WorksheetEditPermission(A,k).id]))==null?void 0:v.every(x=>x.value)))return!1;const H=(C=(p=P.getCell(O,M))==null?void 0:p.selectionProtection)==null?void 0:C[0];if((H==null?void 0:H[m.UnitAction.Edit])===!1)return!1;(b=E.onPointerDown)==null||b.call(E,w,S)}}),g=a.fromEventSubject(d.onPointerMove$).pipe(D.throttleTime(30)).subscribe(S=>{var v,p,C,b,E,w;const f=u(S);if(f){const[O,M]=f;this._enterActiveRender?this._enterActiveRender.render!==O&&((p=(v=this._enterActiveRender.render).onPointerLeave)==null||p.call(v,this._enterActiveRender.cellContext,S),this._enterActiveRender={render:O,cellContext:M},(C=O.onPointerEnter)==null||C.call(O,M,S)):(this._enterActiveRender={render:O,cellContext:M},(b=O.onPointerEnter)==null||b.call(O,M,S))}else this._enterActiveRender&&((w=(E=this._enterActiveRender.render).onPointerLeave)==null||w.call(E,this._enterActiveRender.cellContext,S),this._enterActiveRender=null)});h&&e.add(h),g&&e.add(g)}};this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i)),i(this._sheetSkeletonManagerService.getCurrentParam()),this.disposeWithMe(e)}},y.CellCustomRenderController=Xd([Gr(1,a.Inject(y.SheetSkeletonManagerService)),Gr(2,R.IRenderManagerService),Gr(3,a.IPermissionService)],y.CellCustomRenderController);class Zr extends a.Disposable{constructor(){super(...arguments);T(this,"rangesStack",[]);T(this,"selectedRangeWorksheet","")}}var Yd=Object.getOwnPropertyDescriptor,jd=(n,r,e,t)=>{for(var i=t>1?void 0:t?Yd(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},Fs=(n,r)=>(e,t)=>r(e,t,n);let tn=class{constructor(n,r){T(this,"_current",null);T(this,"_shortcutParam",[]);this._univerInstanceService=n,this._localeService=r}dispose(){this._shortcutParam=[]}getCurrentBySearch(n){return this._getCurrentBySearch(n)}getCurrent(){return this._getCurrentBySearch(this._current)}addOrUpdate(n){const r=this._getCurrentBySearch({unitId:n.unitId,sheetId:n.sheetId,keycode:n.keycode});if(r!=null){const e=this._shortcutParam.indexOf(r);this._shortcutParam.splice(e,1)}return this._shortcutParam.push(n),r}remove(n){if(n==null)return;const r=this._getCurrentBySearch(n);if(r==null)return;const e=this._shortcutParam.indexOf(r);return this._shortcutParam.splice(e,1)[0]}_getCurrentBySearch(n){return n==null?void 0:this._shortcutParam.find(e=>e.unitId===n.unitId&&e.sheetId===n.sheetId&&e.keycode===n.keycode)}};tn=jd([Fs(0,a.IUniverInstanceService),Fs(1,a.Inject(a.LocaleService))],tn);var Fi=(n=>(n.MergeAll="mergeAll",n.MergeVertical="mergeVertical",n.MergeHorizontal="mergeHorizontal",n))(Fi||{});function mt(n,r,e,t,i=!0,o=1,s=!0){let l={...n};t==null&&(t={startRow:0,endRow:e.getRowCount()-1,startColumn:0,endColumn:e.getColumnCount()-1});let c;switch(r){case a.Direction.UP:for(c=n.startRow-o;c>-1&&!e.getRowVisible(c);)c-=1;c>=t.startRow?(l.startRow=c,l.endRow=c):s&&(l.startRow=t.endRow,l.endRow=t.endRow,i&&(l=mt(l,a.Direction.LEFT,e,t,!1)));break;case a.Direction.DOWN:for(c=n.endRow+o;c<e.getRowCount()&&!e.getRowVisible(c);)c+=1;c<=t.endRow?(l.startRow=c,l.endRow=c):s&&(l.startRow=t.startRow,l.endRow=t.startRow,i&&(l=mt(l,a.Direction.RIGHT,e,t,!1)));break;case a.Direction.LEFT:for(c=n.startColumn-o;c>-1&&!e.getColVisible(c);)c-=1;c>=t.startColumn?(l.startColumn=c,l.endColumn=c):s&&(l.startColumn=t.endColumn,l.endColumn=t.endColumn,i&&(l=mt(l,a.Direction.UP,e,t,!1)));break;case a.Direction.RIGHT:for(c=n.endColumn+o;c<e.getColumnCount()&&!e.getColVisible(c);)c+=1;c<=t.endColumn?(l.startColumn=c,l.endColumn=c):s&&(l.startColumn=t.startColumn,l.endColumn=t.startColumn,i&&(l=mt(l,a.Direction.DOWN,e,t,!1)));break}return l}function Kr(n,r,e){const t={...n},{startRow:i,startColumn:o,endRow:s,endColumn:l}=Bn(n,r,e);let c=Fn(e,i,o,s,l).hasValue,d=!0,u=!0;for(;u;){if(a.Direction.UP===r){let h=t.startRow-1;for(;h>-1&&!e.getRowVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:g,matrix:S}=Fn(e,h,t.startColumn,h,t.endColumn);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue(v=>{f=Math.min(v,f)}),t.startRow=f}else t.startRow=h;if(t.endRow=t.startRow,!c&&g){u=!1;break}c=g,d=!1}}if(a.Direction.DOWN===r){let h=t.endRow+1;for(;h<e.getRowCount()&&!e.getRowVisible(h);)h+=1;if(h===e.getRowCount()){u=!1;break}const{hasValue:g,matrix:S}=Fn(e,h,t.startColumn,h,t.endColumn);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((v,p,C)=>{f=Math.max(v+(C.rowSpan||1)-1,f)}),t.endRow=f}else t.endRow=h;if(t.startRow=t.endRow,!c&&g){u=!1;break}c=g,d=!1}}if(a.Direction.LEFT===r){let h=t.startColumn-1;for(;h>-1&&!e.getColVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:g,matrix:S}=Fn(e,t.startRow,h,t.endRow,h);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((v,p)=>{f=Math.min(p,f)}),t.startColumn=f}else t.startColumn=h;if(t.endColumn=t.startColumn,!c&&g){u=!1;break}c=g,d=!1}}if(a.Direction.RIGHT===r){let h=t.endColumn+1;for(;h<e.getColumnCount()&&!e.getColVisible(h);)h+=1;if(h===e.getColumnCount()){u=!1;break}const{hasValue:g,matrix:S}=Fn(e,t.startRow,h,t.endRow,h);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((v,p,C)=>{f=Math.max(p+(C.colSpan||1)-1,f)}),t.endColumn=f}else t.endColumn=h;if(t.startColumn=t.endColumn,!c&&g){u=!1;break}c=g,d=!1}}}return m.alignToMergedCellsBorders(t,e,!0)}function zs(n,r,e){return mt(n,r,e,void 0,!1,1,!1)}function Gd(n,r,e){const t=Kr(n,r,e);return m.alignToMergedCellsBorders(a.Rectangle.union(t,n),e,!0)}function Zd(n,r,e){const t=zs(n,r,e),i={startRow:Math.min(n.startRow,t.startRow),startColumn:Math.min(n.startColumn,t.startColumn),endRow:Math.max(n.endRow,t.endRow),endColumn:Math.max(n.endColumn,t.endColumn)};return m.alignToMergedCellsBorders(a.Rectangle.union(n,i),e)}function Kd(n,r,e,t){const i=a.getReverseDirection(e),o=Kr(Bn(n,i,t),e,t);return e===a.Direction.UP&&o.startRow<=n.startRow?m.alignToMergedCellsBorders({...r,startColumn:n.startColumn,endColumn:n.endColumn},t,!0):e===a.Direction.DOWN&&o.endRow>=n.endRow?m.alignToMergedCellsBorders({...r,startColumn:n.startColumn,endColumn:n.endColumn},t,!0):e===a.Direction.LEFT&&o.startColumn<=n.startColumn?m.alignToMergedCellsBorders({...r,startRow:n.startRow,endRow:n.endRow},t,!0):e===a.Direction.RIGHT&&o.endColumn>=n.endColumn?m.alignToMergedCellsBorders({...r,startRow:n.startRow,endRow:n.endRow},t,!0):a.Rectangle.union(a.Rectangle.clone(r),o)}function qd(n,r,e){const t=a.getReverseDirection(r),i=Bn(n,t,e),o=Bn(n,r,e),s=zs(i,r,e);return m.alignToMergedCellsBorders(a.Rectangle.union(o,s),e,!1)}function Xs(n){return{startRow:0,startColumn:0,endRow:n.getRowCount()-1,endColumn:n.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL}}function Bn(n,r,e){let t;switch(r){case a.Direction.UP:t={startRow:n.startRow,startColumn:n.startColumn,endRow:n.startRow,endColumn:n.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.DOWN:t={startRow:n.endRow,startColumn:n.startColumn,endRow:n.endRow,endColumn:n.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.LEFT:t={startRow:n.startRow,startColumn:n.startColumn,endRow:n.endRow,endColumn:n.startColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.RIGHT:t={startRow:n.startRow,startColumn:n.endColumn,endRow:n.endRow,endColumn:n.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;default:throw new Error("Invalid direction")}return m.alignToMergedCellsBorders(t,e,!1)}function Fn(n,r,e,t,i){let o=!1;const s=n.getMatrixWithMergedCells(r,e,t,i).forValue((l,c,d)=>{if(Jd(d))return o=!0,!1});return{hasValue:o,matrix:s}}function qr(n,r,e){const t=a.Rectangle.clone(n);if(r==null)return t;switch(e){case a.Direction.UP:case a.Direction.DOWN:t.startColumn=t.endColumn=r.actualColumn;break;case a.Direction.LEFT:case a.Direction.RIGHT:t.startRow=t.endRow=r.actualRow;break}return t}function Qd(n,r,e){var l,c,d,u;const{primary:t,range:i}=n,o=a.Rectangle.clone(i);switch(r){case a.Direction.UP:case a.Direction.DOWN:o.startRow=(l=t==null?void 0:t.startRow)!=null?l:i.startRow,o.endRow=(c=t==null?void 0:t.endRow)!=null?c:i.startRow;break;case a.Direction.LEFT:case a.Direction.RIGHT:o.startColumn=(d=t==null?void 0:t.startColumn)!=null?d:i.startColumn,o.endColumn=(u=t==null?void 0:t.endColumn)!=null?u:i.startColumn;break}const s=Bn(o,r,e);switch(r){case a.Direction.DOWN:return i.startRow<s.startRow;case a.Direction.UP:return i.endRow>s.endRow;case a.Direction.LEFT:return s.endColumn<i.endColumn;case a.Direction.RIGHT:return s.startColumn>i.startColumn}}function Ys(n,r){let e=n[0].startRow,t=n[0].endRow;n.forEach(o=>{const{startRow:s,endRow:l}=o;e=Math.min(e,s),t=Math.max(t,l)});const i=new Array(t-e+1).fill(!1);return r.forEach(o=>{const{startRow:s,endRow:l}=o;for(let c=Math.max(s,e);c<=Math.min(l,t);c++)i[c-e]=!0}),n.every(o=>{const{startRow:s,endRow:l}=o;for(let c=s;c<=l;c++)if(!i[c-e])return!1;return!0})}function js(n,r){let e=n[0].startColumn,t=n[0].endColumn;n.forEach(o=>{const{startColumn:s,endColumn:l}=o;e=Math.min(e,s),t=Math.max(t,l)});const i=new Array(t-e+1).fill(!1);return r.forEach(o=>{const{startColumn:s,endColumn:l}=o;for(let c=Math.max(s,e);c<=Math.min(l,t);c++)i[c-e]=!0}),n.every(o=>{const{startColumn:s,endColumn:l}=o;for(let c=s;c<=l;c++)if(!i[c-e])return!1;return!0})}function Qr(n,r){return r?n==="mergeAll"?r.filter(e=>!(e.startRow===e.endRow&&e.startColumn===e.endColumn)):n==="mergeVertical"?r.filter(e=>e.startRow!==e.endRow):n==="mergeHorizontal"?r.filter(e=>e.startColumn!==e.endColumn):r:null}function Jd(n){return n.v!==void 0&&n.v!==null&&n.v!==""||n.p!==void 0}var Xe=(n=>(n[n.moveStopeOne=0]="moveStopeOne",n[n.moveGap=1]="moveGap",n[n.moveStepPage=2]="moveStepPage",n[n.moveStepEnd=3]="moveStepEnd",n))(Xe||{});const Re={id:"sheet.command.move-selection",type:a.CommandType.COMMAND,handler:(n,r)=>{if(!r)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{workbook:t,worksheet:i}=e,o=m.getSelectionsService(n,r.fromCurrentSelection).getCurrentLastSelection();if(!o)return!1;const{direction:s,jumpOver:l,extra:c}=r,{range:d,primary:u}=o,h=qr(d,u,s),g=l===1?Kr(h,s,i):mt(h,s,i),S=m.getCellAtRowCol(g.startRow,g.startColumn,i);if(a.Rectangle.equals(S,h))return!1;const f=t.getUnitId();n.get(tn).remove({unitId:f,sheetId:i.getSheetId(),keycode:_.KeyCode.TAB});const v=[{range:a.Rectangle.clone(S),primary:{startRow:S.startRow,startColumn:S.startColumn,endRow:S.endRow,endColumn:S.endColumn,actualRow:g.startRow,actualColumn:g.startColumn,isMerged:S.isMerged,isMergedMainCell:S.startRow===g.startRow&&S.startColumn===g.startColumn}}];return n.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:t.getUnitId(),subUnitId:i.getSheetId(),selections:v,type:m.SelectionMoveType.MOVE_END,extra:c,reveal:!0})}},Ye={id:"sheet.command.move-selection-enter-tab",type:a.CommandType.COMMAND,handler:(n,r)=>{var U;if(!r)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{workbook:t,worksheet:i}=e,o=m.getSelectionsService(n),{direction:s,keycode:l}=r,c=s===a.Direction.LEFT||s===a.Direction.UP,d=o.getCurrentSelections().concat(),u=d.findIndex(B=>B.primary),h=d[u];if(!h)return!1;const g=c?-1:1,S=u+g!==d.length?d[u+g]:d[0],f=d.findIndex(B=>B===S),v=t.getUnitId(),p=i.getSheetId();if(!h)return!1;const{range:C}=h,b=h.primary;let E=qr(C,b,s);const w=n.get(tn),O=w.getCurrentBySearch({unitId:v,sheetId:p,keycode:_.KeyCode.TAB});let M;const{startRow:P,endRow:A,startColumn:k,endColumn:N}=C,H=c?b.startRow===P&&b.startColumn===k:b.endRow===A&&b.endColumn===N;if(a.Rectangle.equals(C,b)){if(l===_.KeyCode.TAB)O==null&&w.addOrUpdate({unitId:v,sheetId:p,keycode:_.KeyCode.TAB,selection:h});else{const F=O==null?void 0:O.selection;if(F!=null){const{range:z,primary:j}=F;E=qr(z,j,s)}w.remove({unitId:v,sheetId:p,keycode:_.KeyCode.TAB})}const B=mt(E,s,i),Y=m.getCellAtRowCol(B.startRow,B.startColumn,i);if(a.Rectangle.equals(Y,E))return!1;M={range:a.Rectangle.clone(Y),primary:{startRow:Y.startRow,startColumn:Y.startColumn,endRow:Y.endRow,endColumn:Y.endColumn,actualRow:B.startRow,actualColumn:B.startColumn,isMerged:Y.isMerged,isMergedMainCell:Y.startRow===B.startRow&&Y.startColumn===B.startColumn}}}else{w.remove({unitId:v,sheetId:p,keycode:_.KeyCode.TAB});const B=a.Tools.deepClone(b),Y=H?S.range:mt({startRow:B.startRow,startColumn:B.startColumn,endRow:B.endRow,endColumn:B.endColumn},s,i,{startRow:P,endRow:A,startColumn:k,endColumn:N}),F=H&&c,z=F?m.getCellAtRowCol(Y.endRow,Y.endColumn,i):m.getCellAtRowCol(Y.startRow,Y.startColumn,i);M={range:H?S.range:a.Rectangle.clone(C),primary:{startRow:z.startRow,startColumn:z.startColumn,endRow:z.endRow,endColumn:z.endColumn,actualRow:F?z.startRow:Y.startRow,actualColumn:F?z.startColumn:Y.startColumn,isMerged:z.isMerged,isMergedMainCell:z.startRow===Y.startRow&&z.startColumn===Y.startColumn},style:H?S.style:h.style}}H?(d[u].primary=null,d[f]=M,o.setSelections(v,p,[],m.SelectionMoveType.MOVE_END)):d[u]=M;const x=n.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:v,subUnitId:p,type:m.SelectionMoveType.MOVE_END,selections:d,reveal:!0,extra:r.extra}),V=(U=n.get(R.IRenderManagerService).getRenderById(v))==null?void 0:U.with(ve);return V==null||V.refreshSelectionMoveEnd(),x}},Pe={id:"sheet.command.expand-selection",type:a.CommandType.COMMAND,handler:(n,r)=>{if(!r)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{worksheet:t,unitId:i,subUnitId:o}=e,s=m.getSelectionsService(n).getCurrentLastSelection();if(!s)return!1;const{range:l,primary:c}=s,{jumpOver:d,direction:u,extra:h}=r,S=Qd(s,u,t)?d===1?Kd(l,{...a.Rectangle.clone(c),rangeType:a.RANGE_TYPE.NORMAL},u,t):qd(l,u,t):d===1?Gd(l,u,t):Zd(l,u,t);return S.rangeType=s.range.rangeType,a.Rectangle.equals(S,l)?!1:n.get(a.ICommandService).syncExecuteCommand(m.SetSelectionsOperation.id,{unitId:i,subUnitId:o,type:m.SelectionMoveType.MOVE_END,selections:[{range:S,primary:c}],extra:h,reveal:!0})}},zn={id:"sheet.command.select-all",type:a.CommandType.COMMAND,handler:async(n,r={expandToGapFirst:!0,loop:!1})=>{const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const t=m.getSelectionsService(n).getCurrentLastSelection();if(!t)return!1;const i=n.get(Zr),{worksheet:o,unitId:s,subUnitId:l}=e,c=`${s}|${l}`;c!==i.selectedRangeWorksheet&&(i.rangesStack=[],i.selectedRangeWorksheet=c);const d=o.getMaxRows(),u=o.getMaxColumns(),{expandToGapFirst:h,loop:g}=r,{range:S,primary:f}=t,v=S.endColumn===u-1&&S.endRow===d-1&&S.startRow===0&&S.startColumn===0;i.rangesStack.some(O=>a.Rectangle.equals(O,S))||(i.rangesStack=[],i.rangesStack.push(S));let p;if(v)if(g){if(i.rangesStack.findIndex(M=>a.Rectangle.equals(M,S))!==i.rangesStack.length-1)return!1;p=i.rangesStack[0]}else return!1;else h?(p=m.expandToContinuousRange(S,{left:!0,right:!0,up:!0,down:!0},o),a.Rectangle.equals(p,S)&&(p=Xs(o))):p=Xs(o);i.rangesStack.some(O=>a.Rectangle.equals(O,p))||i.rangesStack.push(p);const C=[];C.push({id:m.SetSelectionsOperation.id,params:{unitId:s,subUnitId:l,reveal:!0,selections:[{range:p,primary:f}]}});const E=n.get(m.SheetInterceptorService).onCommandExecute({id:zn.id,params:{range:S}});E.redos.length&&C.push(...E.redos);const w=n.get(a.ICommandService);return a.sequenceExecute(C,w),!0}};var $d=Object.getOwnPropertyDescriptor,eu=(n,r,e,t)=>{for(var i=t>1?void 0:t?$d(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},tu=(n,r)=>(e,t)=>r(e,t,n);y.SheetScrollManagerService=class{constructor(r,e){T(this,"_scrollStateMap",new Map);T(this,"_rawScrollInfo$",new D.BehaviorSubject(null));T(this,"rawScrollInfo$",this._rawScrollInfo$.asObservable());T(this,"validViewportScrollInfo$",new D.BehaviorSubject(null));T(this,"_searchParamForScroll",null);this._context=r,this._sheetSkeletonManagerService=e}dispose(){this._rawScrollInfo$.complete()}calcViewportScrollFromRowColOffset(r){if(!r)return{viewportScrollX:0,viewportScrollY:0};let{sheetViewStartColumn:e,sheetViewStartRow:t,offsetX:i,offsetY:o}=r;t=t||0,o=o||0;const s=this._sheetSkeletonManagerService.getCurrentSkeleton(),l=(s==null?void 0:s.rowHeightAccumulation[t-1])||0,d=((s==null?void 0:s.columnWidthAccumulation[e-1])||0)+i,u=l+o;return{viewportScrollX:d,viewportScrollY:u}}setSearchParam(r){this._searchParamForScroll=r}getScrollStateByParam(r){return this._getCurrentScroll(r)}getCurrentScrollState(){return this._getCurrentScroll(this._searchParamForScroll)}setValidScrollState(r){this._setScrollState(r)}emitRawScrollParam(r){this._emitRawScroll(r)}setValidScrollStateToCurrSheet(r){if(this._searchParamForScroll==null)return;this._setScrollState({...this._searchParamForScroll,...r});const e=this._searchParamForScroll.sheetId,t=this._sheetSkeletonManagerService.getSkeleton(e);t&&t.setScroll(r.viewportScrollX,r.viewportScrollY)}clear(){this._searchParamForScroll!=null&&this._clearByParamAndNotify(this._searchParamForScroll)}_setScrollState(r){const{unitId:e,sheetId:t,sheetViewStartColumn:i,sheetViewStartRow:o,offsetX:s,offsetY:l}=r;this._scrollStateMap.has(e)||this._scrollStateMap.set(e,new Map);const c=this._scrollStateMap.get(e),d={sheetViewStartRow:o,sheetViewStartColumn:i,offsetX:s,offsetY:l};c.set(t,d)}_clearByParamAndNotify(r){this._setScrollState({...r,sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0}),this._emitRawScroll({sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0})}_getCurrentScroll(r){var s;const e={sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0};if(r==null)return e;const{unitId:t,sheetId:i}=r;return((s=this._scrollStateMap.get(t))==null?void 0:s.get(i))||e}_emitRawScroll(r){this._rawScrollInfo$.next(r)}},y.SheetScrollManagerService=eu([tu(1,a.Inject(y.SheetSkeletonManagerService))],y.SheetScrollManagerService);const Le={id:"sheet.operation.set-scroll",type:a.CommandType.OPERATION,handler:(n,r)=>{if(!r)return!1;const{unitId:e,sheetId:t,offsetX:i,offsetY:o,sheetViewStartColumn:s,sheetViewStartRow:l}=r;return n.get(R.IRenderManagerService).getRenderById(e).with(y.SheetScrollManagerService).emitRawScrollParam({unitId:e,sheetId:t,offsetX:i,offsetY:o,sheetViewStartRow:l,sheetViewStartColumn:s}),!0}},nn={id:"sheet.command.set-scroll-relative",type:a.CommandType.COMMAND,handler:async(n,r)=>{const e=n.get(a.ICommandService),t=n.get(a.IUniverInstanceService),i=n.get(R.IRenderManagerService),o=m.getSheetCommandTarget(t);if(!o)return!1;const{unitId:s,subUnitId:l}=o,d=i.getRenderById(s).with(y.SheetScrollManagerService).getCurrentScrollState(),{offsetX:u=0,offsetY:h=0}=r||{},{sheetViewStartRow:g=0,sheetViewStartColumn:S=0,offsetX:f=0,offsetY:v=0}=d||{};return e.executeCommand(Le.id,{unitId:s,sheetId:l,sheetViewStartRow:g,sheetViewStartColumn:S,offsetX:f+u,offsetY:v+h})}},Ue={id:"sheet.command.scroll-view",type:a.CommandType.COMMAND,handler:(n,r)=>{if(!r)return!1;const e=n.get(a.IUniverInstanceService),t=n.get(R.IRenderManagerService),i=m.getSheetCommandTarget(e);if(!i)return!1;const{workbook:o,worksheet:s,unitId:l}=i,d=t.getRenderById(l).with(y.SheetScrollManagerService).getCurrentScrollState();if(!s)return!1;const{sheetViewStartRow:u,sheetViewStartColumn:h,offsetX:g,offsetY:S}=r,{sheetViewStartColumn:f,sheetViewStartRow:v,offsetX:p,offsetY:C}=d||{},{xSplit:b,ySplit:E}=i.worksheet.getConfig().freeze;return n.get(a.ICommandService).syncExecuteCommand(Le.id,{unitId:o.getUnitId(),sheetId:s.getSheetId(),sheetViewStartRow:u!=null?u:v!=null?v:0+E,sheetViewStartColumn:h!=null?h:f!=null?f:0+b,offsetX:g!=null?g:p,offsetY:S!=null?S:C})}},Jr={id:"sheet.command.scroll-to-cell",type:a.CommandType.COMMAND,handler:(n,r)=>{const e=n.get(a.IUniverInstanceService);return n.get(R.IRenderManagerService).getRenderById(e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(y.SheetsScrollRenderController).scrollToRange(r.range,r.forceTop,r.forceLeft)}},nu={id:"sheet.command.scroll-view-reset",type:a.CommandType.COMMAND,handler:async n=>{const r=n.get(a.IUniverInstanceService),e=m.getSheetCommandTarget(r);if(!e)return!1;const{subUnitId:t,unitId:i}=e;return n.get(a.ICommandService).executeCommand(Le.id,{unitId:i,sheetId:t,sheetViewStartRow:0,sheetViewStartColumn:0})}};var iu=Object.getOwnPropertyDescriptor,ru=(n,r,e,t)=>{for(var i=t>1?void 0:t?iu(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},rn=(n,r)=>(e,t)=>r(e,t,n);Re.id,Ye.id;const ou=3;y.SheetsScrollRenderController=class extends a.Disposable{constructor(r,e,t,i,o,s,l){super(),this._context=r,this._injector=e,this._sheetSkeletonManagerService=t,this._contextService=i,this._commandService=o,this._renderManagerService=s,this._scrollManagerService=l,this._initCommandListener(),this._wheelEventListener(),this._scrollBarEventListener(),this._initSkeletonListener()}_wheelEventListener(){const{scene:r}=this._context;if(!r)return;const e=r.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN);e&&this.disposeWithMe(r.onMouseWheel$.subscribeEvent((t,i)=>{if(t.ctrlKey||!this._contextService.getContextValue(a.FOCUSING_SHEET))return;let o=0,s=0;o=t.deltaX,t.shiftKey?o=(t.deltaY||t.deltaX)*ou:s=t.deltaY,this._commandService.executeCommand(nn.id,{offsetX:o,offsetY:s}),this._context.scene.makeDirty(!0);const l=e.limitedScroll(e.scrollX+o,e.scrollY+s);l&&!l.isLimitedX&&!l.isLimitedY&&(t.preventDefault(),r.getParent().classType===R.RENDER_CLASS_TYPE.SCENE_VIEWER&&i.stopPropagation()),e.isWheelPreventDefaultX&&e.isWheelPreventDefaultY&&t.preventDefault()}))}_scrollBarEventListener(){const{scene:r}=this._context;if(r==null)return;const e=r.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN);e&&(this.disposeWithMe(a.toDisposable(this._scrollManagerService.rawScrollInfo$.subscribe(t=>{var S;const i=(S=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:S.skeleton;if(!i)return;if(t==null){e.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});return}const{sheetViewStartRow:o,sheetViewStartColumn:s,offsetX:l,offsetY:c}=t,{startX:d,startY:u}=i.getCellWithCoordByIndex(o,s,!1),h=d+l,g=u+c;e.scrollToViewportPos({viewportScrollX:h,viewportScrollY:g})}))),this.disposeWithMe(e.onScrollAfter$.subscribeEvent(t=>{var v;const i=(v=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:v.skeleton;if(i==null||t.isTrigger===!1)return;const o=this._getSheetObject();if(i==null||o==null)return;const{viewportScrollX:s,viewportScrollY:l,scrollX:c,scrollY:d}=t,{row:u,column:h,rowOffset:g,columnOffset:S}=i.getOffsetRelativeToRowCol(s,l),f={sheetViewStartRow:u,sheetViewStartColumn:h,offsetX:S,offsetY:g,viewportScrollX:s,viewportScrollY:l,scrollX:c,scrollY:d};this._scrollManagerService.setValidScrollStateToCurrSheet(f),this._scrollManagerService.validViewportScrollInfo$.next({...f,viewportScrollX:s,viewportScrollY:l,scrollX:c,scrollY:d})})),this.disposeWithMe(e.onScrollByBar$.subscribeEvent(t=>{var g;const i=(g=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:g.skeleton;if(i==null||t.isTrigger===!1)return;const o=this._getSheetObject();if(i==null||o==null)return;const{viewportScrollX:s=0,viewportScrollY:l=0}=t;this._getFreeze();const{row:c,column:d,rowOffset:u,columnOffset:h}=i.getOffsetRelativeToRowCol(s,l);this._commandService.executeCommand(Ue.id,{sheetViewStartRow:c,sheetViewStartColumn:d,offsetX:h,offsetY:u})})))}_initSkeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeletonBefore$.subscribe(r=>{if(r==null)return;const e={unitId:r.unitId,sheetId:r.sheetId};if(this._scrollManagerService.setSearchParam(e),!this._getSheetObject())return;const i=this._scrollManagerService.getScrollStateByParam(e),{viewportScrollX:o,viewportScrollY:s}=this._scrollManagerService.calcViewportScrollFromRowColOffset(i);i&&this._updateViewportScroll(o,s)})))}_updateViewportScroll(r=0,e=0){const t=this._getSheetObject();if(!t)return;const i=t.scene,o=i.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN),s=i.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT),l=i.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM),c=i.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT),d=i.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);o&&(o.viewportScrollX=r,o.viewportScrollY=e),l&&(l.viewportScrollY=e),s&&(s.viewportScrollX=r),c&&(c.viewportScrollY=e),d&&(d.viewportScrollX=r)}scrollToRange(r,e,t){let{endRow:i,endColumn:o,startColumn:s,startRow:l}=r;const c=this._getViewportBounding();if(r.rangeType===a.RANGE_TYPE.ROW?(s=0,o=0):r.rangeType===a.RANGE_TYPE.COLUMN&&(l=0,i=0),c&&!e&&!t){const d=c.startRow>i?l:i,u=c.startColumn>o?s:o;return this._scrollToCell(d,u)}else return this._scrollToCell(l,s,e,t)}scrollToCell(r,e){const t=this._context.unit.getActiveSheet(),{ySplit:i,xSplit:o}=t.getFreeze();return this._commandService.syncExecuteCommand(Ue.id,{sheetViewStartRow:r-i,sheetViewStartColumn:e-o,offsetX:0,offsetY:0})}_initCommandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{switch(r.id){case m.SetSelectionsOperation.id:{const e=r.params;e.unitId===this._context.unitId&&e.reveal&&this._scrollToSelection()}break;case m.ScrollToCellOperation.id:{const e=r.params;if(e.unitId===this._context.unitId){const t=e.range;this.scrollToRange(t)}}break;case Pe.id:{const e=r.params;this._scrollToSelectionForExpand(e)}break}}))}_scrollToSelectionForExpand(r){setTimeout(()=>{const e=this._getSelectionsService().getCurrentLastSelection();if(e==null)return;const{startRow:t,startColumn:i,endRow:o,endColumn:s}=e.range,l=this._getViewportBounding();if(l==null)return;const{startRow:c,startColumn:d,endRow:u,endColumn:h}=l;let g=0,S=0;t>c?g=o:o<u?g=t:g=c,i>d?S=s:s<h?S=i:S=d,r.direction===a.Direction.DOWN?g=o:r.direction===a.Direction.UP?g=t:r.direction===a.Direction.RIGHT?S=s:r.direction===a.Direction.LEFT&&(S=i),this._scrollToCell(g,S)},0)}_getFreeze(){var e;const r=(e=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:e.skeleton.getWorksheetConfig();if(r!=null)return r.freeze}_updateSceneSize(r){var h;if(r==null)return;const{unitId:e}=this._context,{skeleton:t}=r,i=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.scene;if(t==null||i==null)return;const{rowTotalHeight:o,columnTotalWidth:s,rowHeaderWidthAndMarginLeft:l,columnHeaderHeightAndMarginTop:c}=t;this._context.unit.getActiveSheet()&&(i==null||i.transformByState({width:l+s,height:c+o}))}_getSheetObject(){return Ne(this._context.unit,this._context)}_scrollToSelectionByDirection(r){const e=this._getViewportBounding();if(e==null)return!1;const{startRow:t,startColumn:i,endRow:o,endColumn:s}=e;let l=0,c=0;const{startRow:d,startColumn:u,endRow:h,endColumn:g}=r;d>=t&&(l=h),h<=o&&(l=d),u>=i&&(c=g),g<=s&&(c=u),this._scrollToCell(l,c)}_scrollToSelection(r=!0){var d;const e=this._getSelectionsService().getCurrentLastSelection();if(!e)return;const{startRow:t,startColumn:i,actualRow:o,actualColumn:s}=(d=e.primary)!=null?d:e.range,l=r&&o!=null?o:t,c=r&&s!=null?s:i;this._scrollToCell(l,c)}_getSelectionsService(){return m.getSelectionsService(this._injector)}_getViewportBounding(){var o,s;const r=(o=this._getSheetObject())==null?void 0:o.scene;if(r==null)return;const e=r.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e==null)return;const t=(s=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:s.skeleton;if(t==null)return;const i=e.calcViewportInfo();return t.getRangeByViewBound(i.viewBound)}_scrollToCell(r,e,t=!1,i=!1){var N,H,x;const{rowHeightAccumulation:o,columnWidthAccumulation:s}=(N=this._sheetSkeletonManagerService.getCurrentSkeleton())!=null?N:{};if(o==null||s==null)return!1;const l=(H=this._getSheetObject())==null?void 0:H.scene;if(l==null)return!1;const c=l.getViewport(R.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(c==null)return!1;const d=(x=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:x.skeleton;if(d==null)return!1;const u=this._context.unit.getActiveSheet();if(!u)return!1;r=a.Tools.clamp(r,0,o.length-1),e=a.Tools.clamp(e,0,s.length-1);const{startColumn:h,startRow:g,ySplit:S,xSplit:f}=u.getFreeze(),v=this._getViewportBounding();if(v==null)return!1;const{startRow:p,startColumn:C,endRow:b,endColumn:E}=v;let w,O;if(r>=g&&e>=h-S&&(r<=p&&(w=r,t=!0),r>=b)){const L=o[r]-c.height;for(let V=p;V<=r&&(w=V+1,!(o[V]>=L));V++);}if(e>=h&&r>=g-S&&(e<=C&&(O=e,i=!0),e>=E)){const L=s[e]-c.width;for(let V=C;V<=e&&(O=V+1,!(s[V]>=L));V++);}if(w===void 0&&O===void 0)return!1;let{offsetX:M,offsetY:P,sheetViewStartRow:A,sheetViewStartColumn:k}=this._scrollManagerService.getCurrentScrollState()||{};if(w=w?Math.min(w,r):A+S,O=O?Math.min(O,e):k+f,i){M=0,O=e;const L=d.getHiddenColumnsInRange({startColumn:O-f,endColumn:O});O=O-L.length}if(t){P=0,w=r;const L=d.getHiddenRowsInRange({startRow:w-S,endRow:w});w=w-L.length}return this._commandService.syncExecuteCommand(Ue.id,{sheetViewStartRow:Math.max(0,w-S),sheetViewStartColumn:Math.max(0,O-f),offsetX:M,offsetY:P})}},y.SheetsScrollRenderController=ru([rn(1,a.Inject(a.Injector)),rn(2,a.Inject(y.SheetSkeletonManagerService)),rn(3,a.IContextService),rn(4,a.ICommandService),rn(5,R.IRenderManagerService),rn(6,a.Inject(y.SheetScrollManagerService))],y.SheetsScrollRenderController);const $r={id:"sheet.operation.scroll-to-range",type:a.CommandType.OPERATION,handler:(n,r)=>{if(!r)return!1;const e=n.get(a.IUniverInstanceService);return n.get(R.IRenderManagerService).getRenderById(e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(y.SheetsScrollRenderController).scrollToRange(r.range,r.forceTop,r.forceLeft)}};class Gs{constructor(){T(this,"_state",null);T(this,"_rect",null);T(this,"_state$",new D.BehaviorSubject(null));T(this,"state$",this._state$.asObservable());T(this,"_rect$",new D.BehaviorSubject(null));T(this,"rect$",this._rect$.asObservable());T(this,"_focus",!1);T(this,"_focus$",new D.BehaviorSubject(this._focus));T(this,"focus$",this._focus$.asObservable())}dispose(){this._state$.complete(),this._state=null,this._rect$.complete(),this._rect=null}setState(r){this._state=r,this._refresh(r)}getRect(){return this._rect}setRect(r){this._rect=r,this._rect$.next(r)}getState(){return this._state}setFocus(r=!1){this._focus=r,this._focus$.next(r)}_refresh(r){this._state$.next(r)}}const Xn=a.createIdentifier("univer.sheet-cell-editor-manager.service"),Oe="sheets-ui.config",eo={formulaBar:!0,statusBarStatistic:!0,maxAutoHeightCount:1e3};var Ve=function(){return Ve=Object.assign||function(n){for(var r,e=1,t=arguments.length;e<t;e++){r=arguments[e];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(n[i]=r[i])}return n},Ve.apply(this,arguments)},su=function(n,r){var e={};for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&r.indexOf(t)<0&&(e[t]=n[t]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,t=Object.getOwnPropertySymbols(n);i<t.length;i++)r.indexOf(t[i])<0&&Object.prototype.propertyIsEnumerable.call(n,t[i])&&(e[t[i]]=n[t[i]]);return e},Ce=W.forwardRef(function(n,r){var e=n.icon,t=n.id,i=n.className,o=n.extend,s=su(n,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(t," ").concat(i||"").trim(),c=W.useRef("_".concat(cu()));return Zs(e,"".concat(t),{defIds:e.defIds,idSuffix:c.current},Ve({ref:r,className:l},s),o)});function Zs(n,r,e,t,i){return W.createElement(n.tag,Ve(Ve({key:r},au(n,e,i)),t),(lu(n,e).children||[]).map(function(o,s){return Zs(o,"".concat(r,"-").concat(n.tag,"-").concat(s),e,void 0,i)}))}function au(n,r,e){var t=Ve({},n.attrs);e!=null&&e.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=e.colorChannel1),n.tag==="mask"&&t.id&&(t.id=t.id+r.idSuffix),Object.entries(t).forEach(function(o){var s=o[0],l=o[1];s==="mask"&&typeof l=="string"&&(t[s]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))});var i=r.defIds;return!i||i.length===0||(n.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+r.idSuffix),Object.entries(t).forEach(function(o){var s=o[0],l=o[1];typeof l=="string"&&(t[s]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),t}function lu(n,r){var e,t=r.defIds;return!t||t.length===0?n:n.tag==="defs"&&(!((e=n.children)===null||e===void 0)&&e.length)?Ve(Ve({},n),{children:n.children.map(function(i){return typeof i.attrs.id=="string"&&t&&t.includes(i.attrs.id)?Ve(Ve({},i),{attrs:Ve(Ve({},i.attrs),{id:i.attrs.id+r.idSuffix})}):i})}):n}function cu(){return Math.random().toString(36).substring(2,8)}Ce.displayName="UniverIcon";var du={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M11.0363 12.2367V14.0367C11.0363 14.3681 11.3049 14.6367 11.6363 14.6367C11.9676 14.6367 12.2363 14.3681 12.2363 14.0367V12.2367H14.0364C14.3677 12.2367 14.6364 11.9681 14.6364 11.6367C14.6364 11.3054 14.3677 11.0367 14.0364 11.0367H12.2363V9.23672C12.2363 8.90535 11.9676 8.63672 11.6363 8.63672C11.3049 8.63672 11.0363 8.90535 11.0363 9.23672V11.0367H9.23635C8.90498 11.0367 8.63635 11.3054 8.63635 11.6367C8.63635 11.9681 8.90498 12.2367 9.23635 12.2367H11.0363Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M2.56365 1.36377C1.90091 1.36377 1.36365 1.90103 1.36365 2.56377V6.16377C1.36365 6.82651 1.90091 7.36377 2.56365 7.36377H6.16365C6.82639 7.36377 7.36365 6.82651 7.36365 6.16377V2.56377C7.36365 1.90103 6.82639 1.36377 6.16365 1.36377H2.56365ZM6.16365 2.56377H2.56365L2.56365 6.16377H6.16365V2.56377Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M2.56365 8.63647C1.90091 8.63647 1.36365 9.17373 1.36365 9.83647V13.4365C1.36365 14.0992 1.90091 14.6365 2.56365 14.6365H6.16365C6.82639 14.6365 7.36365 14.0992 7.36365 13.4365V9.83647C7.36365 9.17373 6.82639 8.63647 6.16365 8.63647H2.56365ZM6.16365 9.83647H2.56365L2.56365 13.4365H6.16365V9.83647Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M9.83635 7.36377C9.17361 7.36377 8.63635 6.82651 8.63635 6.16377V2.56377C8.63635 1.90103 9.17361 1.36377 9.83635 1.36377H13.4364C14.0991 1.36377 14.6364 1.90103 14.6364 2.56377V6.16377C14.6364 6.82651 14.0991 7.36377 13.4364 7.36377H9.83635ZM9.83635 6.16377V2.56377L13.4364 2.56377V6.16377H9.83635Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ks=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"autofill-double-icon",ref:r,icon:du}))});Ks.displayName="AutofillDoubleIcon";var uu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},on=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"check-mark-icon",ref:r,icon:uu}))});on.displayName="CheckMarkIcon";var hu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.71274 2.86421C3.47843 2.6299 3.09853 2.6299 2.86421 2.86421C2.6299 3.09853 2.6299 3.47843 2.86421 3.71274L7.15154 8.00007L2.86421 12.2874C2.6299 12.5217 2.6299 12.9016 2.86421 13.1359C3.09853 13.3702 3.47843 13.3702 3.71274 13.1359L8.00007 8.84859L12.2874 13.1359C12.5217 13.3702 12.9016 13.3702 13.1359 13.1359C13.3702 12.9016 13.3702 12.5217 13.1359 12.2874L8.84859 8.00007L13.1359 3.71274C13.3702 3.47843 13.3702 3.09853 13.1359 2.86421C12.9016 2.6299 12.5217 2.6299 12.2874 2.86421L8.00007 7.15154L3.71274 2.86421Z"}}]},qs=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"close-icon",ref:r,icon:hu}))});qs.displayName="CloseIcon";var mu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"g",attrs:{fill:"currentColor",clipPath:"url(#convert-icon_clip0_911_593)"},children:[{tag:"path",attrs:{d:"M2.44766 0.848145C1.564 0.848145 0.847656 1.56449 0.847656 2.44814V6.44814C0.847656 7.3318 1.564 8.04814 2.44766 8.04814H6.44766C7.33131 8.04814 8.04766 7.3318 8.04766 6.44814V2.44814C8.04766 1.56449 7.33131 0.848145 6.44766 0.848145H2.44766ZM2.04766 6.44814V5.04824H3.84775V6.84814H2.44766C2.22674 6.84814 2.04766 6.66906 2.04766 6.44814ZM2.04766 3.84824H3.84775V2.04814H2.44766C2.22674 2.04814 2.04766 2.22723 2.04766 2.44814V3.84824ZM5.04775 6.84814V5.04824H6.84766V6.44814C6.84766 6.66906 6.66857 6.84814 6.44766 6.84814H5.04775ZM5.04775 3.84824H6.84766V2.44814C6.84766 2.22723 6.66857 2.04814 6.44766 2.04814H5.04775V3.84824Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{d:"M9.55215 7.95166C8.66849 7.95166 7.95215 8.668 7.95215 9.55166V13.5517C7.95215 14.4353 8.66849 15.1517 9.55215 15.1517L11.5522 15.1517L13.5521 15.1517C14.4358 15.1517 15.1521 14.4353 15.1521 13.5517L15.1521 11.5518L15.1521 9.55166C15.1521 8.668 14.4358 7.95166 13.5521 7.95166H9.55215ZM13.9521 10.9518V9.55166C13.9521 9.33075 13.7731 9.15166 13.5521 9.15166H12.1522V10.9518H13.9521ZM10.9522 10.9518V9.15166H9.55215C9.33123 9.15166 9.15215 9.33075 9.15215 9.55166V10.9518H10.9522ZM9.15215 12.1518H10.9522V13.9517H9.55215C9.33123 13.9517 9.15215 13.7726 9.15215 13.5517V12.1518ZM12.1522 12.1518H13.9521V13.5517C13.9521 13.7726 13.7731 13.9517 13.5521 13.9517H12.1522V12.1518Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{d:"M9.62158 2.44912C9.62158 2.11775 9.89021 1.84912 10.2216 1.84912H12.7516C13.6352 1.84912 14.3516 2.56547 14.3516 3.44912V5.9791C14.3516 6.31047 14.0829 6.5791 13.7516 6.5791C13.4202 6.5791 13.1516 6.31047 13.1516 5.9791V3.44912C13.1516 3.22821 12.9725 3.04912 12.7516 3.04912H10.2216C9.89021 3.04912 9.62158 2.78049 9.62158 2.44912Z"}},{tag:"path",attrs:{d:"M5.77871 14.1507C6.11008 14.1507 6.37871 13.8821 6.37871 13.5507C6.37871 13.2193 6.11008 12.9507 5.77871 12.9507L3.24873 12.9507C3.02782 12.9507 2.84873 12.7716 2.84873 12.5507L2.84873 10.0207C2.84873 9.68933 2.5801 9.4207 2.24873 9.4207C1.91736 9.4207 1.64873 9.68933 1.64873 10.0207L1.64873 12.5507C1.64873 13.4343 2.36507 14.1507 3.24873 14.1507H5.77871Z"}}]},{tag:"defs",attrs:{},children:[{tag:"clipPath",attrs:{id:"convert-icon_clip0_911_593"},children:[{tag:"path",attrs:{fill:"white",d:"M0 0H16V16H0z"}}]}]}],defIds:["convert-icon_clip0_911_593"]},Qs=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"convert-icon",ref:r,icon:mu}))});Qs.displayName="ConvertIcon";var gu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.3313 1.4667C5.3313 1.13533 5.59993 0.866699 5.9313 0.866699H10.069C10.4004 0.866699 10.669 1.13533 10.669 1.4667C10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443C14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928L9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171C10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778L9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539C9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263L6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539C5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778L6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},zi=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"delete-icon",ref:r,icon:gu}))});zi.displayName="DeleteIcon";var Su={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.85869 12.9216C8.38445 13.4708 7.61555 13.4708 7.14131 12.9216L0.358114 5.06726C-0.406895 4.18144 0.134916 2.66683 1.2168 2.66683L14.7832 2.66683C15.8651 2.66683 16.4069 4.18144 15.6419 5.06726L8.85869 12.9216Z"}}]},Js=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"dropdown-icon",ref:r,icon:Su}))});Js.displayName="DropdownIcon";var fu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M15 8C15 11.866 11.866 15 8 15C4.13401 15 1 11.866 1 8C1 4.13401 4.13401 1 8 1C11.866 1 15 4.13401 15 8ZM10.3097 5.69014C10.544 5.92445 10.544 6.30435 10.3097 6.53867L8.84843 7.9999L10.3099 9.46137C10.5442 9.69569 10.5442 10.0756 10.3099 10.3099C10.0756 10.5442 9.69569 10.5442 9.46137 10.3099L7.9999 8.84843L6.53842 10.3099C6.30411 10.5442 5.92421 10.5442 5.6899 10.3099C5.45558 10.0756 5.45558 9.69569 5.6899 9.46137L7.15137 7.9999L5.69014 6.53867C5.45583 6.30435 5.45583 5.92445 5.69014 5.69014C5.92445 5.45583 6.30435 5.45583 6.53867 5.69014L7.9999 7.15137L9.46113 5.69014C9.69544 5.45583 10.0753 5.45583 10.3097 5.69014Z",fillRule:"evenodd",clipRule:"evenodd"}}]},to=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"error-icon",ref:r,icon:fu}))});to.displayName="ErrorIcon";var vu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.28096 4.6541C1.57489 4.50109 1.93721 4.61533 2.09022 4.90926C2.27315 5.26067 2.55999 5.60455 2.94829 5.92278C4.04628 6.82266 5.87505 7.44865 7.99828 7.44865C10.1215 7.44865 11.9503 6.82267 13.0482 5.92279C13.4366 5.60455 13.7234 5.26067 13.9063 4.90927C14.0594 4.61533 14.4217 4.50109 14.7156 4.65409C15.0095 4.8071 15.1238 5.16941 14.9708 5.46334C14.6995 5.98445 14.2981 6.44997 13.8089 6.8509C13.7298 6.91575 13.6481 6.97914 13.564 7.041L15.2245 8.70153C15.4588 8.93585 15.4588 9.31575 15.2245 9.55006C14.9902 9.78438 14.6103 9.78438 14.376 9.55006L12.5041 7.67822C11.8977 7.97568 11.2181 8.21208 10.4884 8.37706L11.0996 10.6581C11.1853 10.9782 10.9954 11.3072 10.6753 11.393C10.3552 11.4787 10.0262 11.2888 9.94045 10.9687L9.29949 8.57652C8.8758 8.62404 8.44081 8.64865 7.99828 8.64865C7.55276 8.64865 7.11487 8.62371 6.68846 8.57555L6.04723 10.9687C5.96147 11.2888 5.63247 11.4788 5.31239 11.393C4.99231 11.3073 4.80236 10.9783 4.88812 10.6582L5.49983 8.37516C4.7743 8.2105 4.09843 7.9752 3.49498 7.67947L1.62436 9.55009C1.39005 9.78441 1.01015 9.78441 0.775835 9.5501C0.54152 9.31578 0.541518 8.93588 0.775832 8.70157L2.43478 7.04261C2.34987 6.98024 2.26746 6.91632 2.18764 6.8509C1.69842 6.44997 1.29706 5.98445 1.0258 5.46335C0.872791 5.16942 0.987031 4.80711 1.28096 4.6541Z"}}]},$s=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"eyelash-icon",ref:r,icon:vu}))});$s.displayName="EyelashIcon";var pu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M6.06409 5.53454C5.93592 5.53454 5.84083 5.41567 5.86897 5.29063L5.95442 4.9109C6.05444 4.48178 6.23806 4.11547 6.51182 3.81952C6.81082 3.49628 7.25398 3.35405 7.79738 3.35405C7.99847 3.35405 8.21359 3.37775 8.44188 3.42245C8.46089 3.42617 8.47974 3.43006 8.49846 3.4341C8.7099 3.4798 8.93698 3.38478 9.02031 3.18514L9.24767 2.6404C9.33457 2.43219 9.23178 2.19404 9.01582 2.12874C8.98358 2.11899 8.95028 2.10912 8.91591 2.09914C8.62745 2.01631 8.28392 1.97217 7.88074 1.97217C6.82015 1.97217 6.02714 2.23936 5.4746 2.7444C4.90987 3.26069 4.50889 3.99917 4.28413 4.9762L2.83703 11.1909C2.76126 11.5286 2.666 11.8917 2.54844 12.2812C2.42975 12.6734 2.2873 13.0595 2.12221 13.4373C1.95577 13.8159 1.76813 14.1762 1.55955 14.5171C1.49345 14.6251 1.42515 14.7282 1.35467 14.8263C1.26508 14.9509 1.3347 15.133 1.48655 15.1554C2.13635 15.2509 2.8179 15.0763 3.18197 14.5296C3.32661 14.3124 3.46779 14.0646 3.60509 13.7851C3.96635 13.0497 4.30522 12.0103 4.61867 10.6574L5.469 7.01534C5.49013 6.92483 5.57082 6.86081 5.66376 6.86081H7.62478C7.8097 6.86081 7.97051 6.73405 8.01371 6.55425L8.14014 6.02798C8.20057 5.77642 8.00992 5.53454 7.75121 5.53454H6.06409Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M14.3211 5.72037L12.5124 7.96963L11.4089 5.77754C11.3422 5.63012 11.1954 5.5354 11.0336 5.5354H10.3129C10.0085 5.5354 9.80921 5.85428 9.9427 6.1279L11.4089 9.05502L8.79783 12.1493C8.56587 12.4158 8.75519 12.8315 9.10855 12.8315H9.68607C9.80672 12.8315 9.9605 12.7822 10.0388 12.6904L12.1108 10.2648L13.1176 12.561C13.1786 12.7231 13.333 12.8315 13.5061 12.8315H14.3C14.5831 12.8315 14.7417 12.6175 14.6426 12.3524L13.1728 9.28628C13.1728 9.28628 15.4009 6.45542 15.6013 6.17892C15.7966 5.90929 15.6023 5.5354 15.2693 5.5354H14.6661C14.5275 5.5354 14.4333 5.58887 14.3211 5.72037Z"}}]},ea=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"fx-icon",ref:r,icon:pu}))});ea.displayName="FxIcon";var Cu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M6.4833 1.65005C6.4833 1.31868 6.21467 1.05005 5.8833 1.05005C5.55193 1.05005 5.2833 1.31868 5.2833 1.65005V5.28345H1.65029C1.31892 5.28345 1.05029 5.55208 1.05029 5.88345C1.05029 6.21482 1.31892 6.48345 1.65029 6.48345H5.2833V9.51684H1.65029C1.31892 9.51684 1.05029 9.78547 1.05029 10.1168C1.05029 10.4482 1.31892 10.7168 1.65029 10.7168H5.2833V14.35C5.2833 14.6814 5.55193 14.95 5.8833 14.95C6.21467 14.95 6.4833 14.6814 6.4833 14.35V10.7168H9.5167V14.35C9.5167 14.6814 9.78533 14.95 10.1167 14.95C10.4481 14.95 10.7167 14.6814 10.7167 14.35V10.7168H14.3503C14.6817 10.7168 14.9503 10.4482 14.9503 10.1168C14.9503 9.78547 14.6817 9.51685 14.3503 9.51685H10.7167V6.48345H14.3503C14.6817 6.48345 14.9503 6.21482 14.9503 5.88345C14.9503 5.55208 14.6817 5.28345 14.3503 5.28345H10.7167V1.65005C10.7167 1.31868 10.4481 1.05005 10.1167 1.05005C9.78533 1.05005 9.5167 1.31868 9.5167 1.65005V5.28345L6.4833 5.28345V1.65005ZM6.4833 6.48345V9.51684L9.5167 9.51685V6.48345L6.4833 6.48345Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.0498 3.65005C1.0498 2.21411 2.21386 1.05005 3.6498 1.05005H12.3498C13.7857 1.05005 14.9498 2.21411 14.9498 3.65005V12.3501C14.9498 13.786 13.7857 14.95 12.3498 14.95H3.6498C2.21386 14.95 1.0498 13.786 1.0498 12.35V3.65005ZM3.6498 2.25005C2.87661 2.25005 2.2498 2.87685 2.2498 3.65005V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V3.65005C13.7498 2.87685 13.123 2.25005 12.3498 2.25005H3.6498Z",fillRule:"evenodd",clipRule:"evenodd"}}]},ta=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"hide-gridlines-double-icon",ref:r,icon:Cu}))});ta.displayName="HideGridlinesDoubleIcon";var _u={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},no=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"increase-icon",ref:r,icon:_u}))});no.displayName="IncreaseIcon";var Iu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.00016 1.33203C6.68162 1.33203 5.39269 1.72302 4.29636 2.45557C3.20004 3.18811 2.34555 4.2293 1.84097 5.44747C1.33638 6.66565 1.20436 8.00609 1.4616 9.2993C1.71883 10.5925 2.35377 11.7804 3.28612 12.7127C4.21847 13.6451 5.40636 14.28 6.69956 14.5373C7.99277 14.7945 9.33321 14.6625 10.5514 14.1579C11.7696 13.6533 12.8108 12.7988 13.5433 11.7025C14.2758 10.6062 14.6668 9.31724 14.6668 7.9987C14.6649 6.23118 13.9619 4.53662 12.7121 3.2868C11.4622 2.03697 9.76768 1.33397 8.00016 1.33203ZM7.66683 3.9987C7.86461 3.9987 8.05795 4.05735 8.2224 4.16723C8.38685 4.27711 8.51502 4.43329 8.59071 4.61601C8.6664 4.79874 8.6862 4.99981 8.64762 5.19379C8.60903 5.38777 8.51379 5.56595 8.37394 5.7058C8.23409 5.84566 8.0559 5.9409 7.86192 5.97948C7.66794 6.01807 7.46687 5.99826 7.28415 5.92258C7.10142 5.84689 6.94524 5.71872 6.83536 5.55427C6.72548 5.38982 6.66683 5.19648 6.66683 4.9987C6.66683 4.73348 6.77219 4.47913 6.95972 4.29159C7.14726 4.10405 7.40162 3.9987 7.66683 3.9987ZM9.3335 11.332H6.66683C6.49002 11.332 6.32045 11.2618 6.19543 11.1368C6.0704 11.0117 6.00016 10.8422 6.00016 10.6654C6.00016 10.4886 6.0704 10.319 6.19543 10.194C6.32045 10.0689 6.49002 9.9987 6.66683 9.9987H7.3335V7.9987H6.66683C6.49002 7.9987 6.32045 7.92846 6.19543 7.80343C6.0704 7.67841 6.00016 7.50884 6.00016 7.33203C6.00016 7.15522 6.0704 6.98565 6.19543 6.86063C6.32045 6.7356 6.49002 6.66536 6.66683 6.66536H8.00016C8.17698 6.66536 8.34655 6.7356 8.47157 6.86063C8.59659 6.98565 8.66683 7.15522 8.66683 7.33203V9.9987H9.3335C9.51031 9.9987 9.67988 10.0689 9.8049 10.194C9.92993 10.319 10.0002 10.4886 10.0002 10.6654C10.0002 10.8422 9.92993 11.0117 9.8049 11.1368C9.67988 11.2618 9.51031 11.332 9.3335 11.332Z"}}]},na=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"info-icon",ref:r,icon:Iu}))});na.displayName="InfoIcon";var bu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.62402 7.72905C2.58427 7.72905 2.55205 7.76127 2.55205 7.80102V13.6782C2.55205 13.7179 2.58427 13.7502 2.62402 13.7502H13.3755C13.4152 13.7502 13.4474 13.7179 13.4474 13.6782V7.80102C13.4474 7.76127 13.4152 7.72905 13.3755 7.72905H2.62402ZM1.35205 7.80102C1.35205 7.09853 1.92153 6.52905 2.62402 6.52905H13.3755C14.0779 6.52905 14.6474 7.09853 14.6474 7.80102V13.6782C14.6474 14.3807 14.0779 14.9502 13.3755 14.9502H2.62402C1.92153 14.9502 1.35205 14.3807 1.35205 13.6782V7.80102Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M8 2.25005C6.69847 2.25003 5.64336 3.30513 5.64336 4.60666V7.12895C5.64336 7.46032 5.37473 7.72895 5.04336 7.72895C4.71199 7.72895 4.44336 7.46032 4.44336 7.12895V4.60666C4.44336 2.64239 6.04451 1.05565 8.00879 1.05566M8 2.25005L8.00879 1.05566L8 2.25005ZM8.00879 1.05566L8 2.25005C9.30154 2.25003 10.3567 3.30513 10.3567 4.60666V7.12895C10.3567 7.46032 10.6253 7.72895 10.9567 7.72895C11.288 7.72895 11.5567 7.46032 11.5567 7.12895V4.60666C11.5567 2.64239 9.97306 1.05565 8.00879 1.05566Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M8.00039 9.4668C8.33176 9.4668 8.60039 9.73543 8.60039 10.0668V12.0827C8.60039 12.4141 8.33176 12.6827 8.00039 12.6827C7.66902 12.6827 7.40039 12.4141 7.40039 12.0827V10.0668C7.40039 9.73543 7.66902 9.4668 8.00039 9.4668Z",fillRule:"evenodd",clipRule:"evenodd"}}]},io=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"lock-icon",ref:r,icon:bu}))});io.displayName="LockIcon";var wu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M11.3536 6.14645C11.5488 6.34171 11.5488 6.65829 11.3536 6.85355L8.35355 9.85355C8.15829 10.0488 7.84171 10.0488 7.64645 9.85355L4.64645 6.85355C4.45118 6.65829 4.45118 6.34171 4.64645 6.14645C4.84171 5.95118 5.15829 5.95118 5.35355 6.14645L8 8.79289L10.6464 6.14645C10.8417 5.95118 11.1583 5.95118 11.3536 6.14645Z",fillRule:"evenodd",clipRule:"evenodd"}}]},sn=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"more-down-icon",ref:r,icon:wu}))});sn.displayName="MoreDownIcon";var Eu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.90913 3.57564C6.14345 3.34132 6.52335 3.34132 6.75766 3.57564L10.7577 7.57564C10.992 7.80995 10.992 8.18985 10.7577 8.42417L6.75766 12.4242C6.52335 12.6585 6.14345 12.6585 5.90913 12.4242C5.67482 12.1899 5.67482 11.81 5.90913 11.5756L9.48487 7.9999L5.90913 4.42417C5.67482 4.18985 5.67482 3.80995 5.90913 3.57564Z",fillRule:"evenodd",clipRule:"evenodd"}}]},ro=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"more-icon",ref:r,icon:Eu}))});ro.displayName="MoreIcon";var Tu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.01281 1.36643C8.79386 0.585377 10.0602 0.585378 10.8412 1.36643L12.9223 3.44752C13.7034 4.22857 13.7034 5.4949 12.9223 6.27595L9.36445 9.83383C8.5834 10.6149 7.31707 10.6149 6.53602 9.83383L4.45493 7.75273C3.67388 6.97168 3.67388 5.70535 4.45493 4.9243L8.01281 1.36643ZM9.9927 2.21495C9.68028 1.90253 9.17375 1.90253 8.86133 2.21495L5.30346 5.77283L5.29671 5.77966L10.839 6.66224L12.0738 5.42742C12.3862 5.115 12.3862 4.60847 12.0738 4.29605L9.9927 2.21495Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M14.5179 9.48875C14.5179 9.99175 14.1101 10.3995 13.607 10.3995C13.1041 10.3995 12.6963 9.99175 12.6963 9.48875C12.6963 9.1773 13.0455 8.59966 13.3114 8.20487C13.4549 7.99177 13.7591 7.99177 13.9027 8.20486C14.1687 8.59965 14.5179 9.1773 14.5179 9.48875Z"}},{tag:"path",attrs:{fill:"colorChannel1",d:"M1.98682 13.4992C1.98682 12.5603 2.74793 11.7992 3.68682 11.7992H14.2868C15.2257 11.7992 15.9868 12.5603 15.9868 13.4992V13.4992C15.9868 14.4381 15.2257 15.1992 14.2868 15.1992H3.68682C2.74793 15.1992 1.98682 14.4381 1.98682 13.4992V13.4992Z"}}]},ia=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"paint-bucket-double-icon",ref:r,icon:Tu}))});ia.displayName="PaintBucketDoubleIcon";var yu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_1138",width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#DCDCDC",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{mask:"url(#mask0_102_1138)"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M7.74692 9.12463C7.74692 9.46018 8.01893 9.73219 8.35448 9.73219H11.4933C11.8288 9.73219 12.1009 9.46018 12.1009 9.12463C12.1009 8.78909 11.8288 8.51707 11.4933 8.51707H8.35448C8.01893 8.51707 7.74692 8.78909 7.74692 9.12463Z"}},{tag:"path",attrs:{fill:"colorChannel1",d:"M10.8636 10.8523C10.8636 11.1879 10.5915 11.4599 10.256 11.4599H8.35448C8.01893 11.4599 7.74692 11.1879 7.74692 10.8523C7.74692 10.5168 8.01893 10.2447 8.35448 10.2447H10.256C10.5915 10.2447 10.8636 10.5168 10.8636 10.8523Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M5.4791 1.98268C5.47913 1.71529 5.87912 1.49854 6.37252 1.49854C6.86593 1.49854 7.26592 1.71529 7.26595 1.98268H7.62187C8.22277 1.98268 8.72459 2.39534 8.84412 2.9452H9.39563C10.0856 2.9452 10.6449 3.48923 10.6449 4.16032V6.00569H12.1261C13.161 6.00569 14 6.82174 14 7.82838V11.334C14 11.8174 13.8025 12.281 13.4511 12.6228L12.0693 13.9647C11.7179 14.3065 11.2412 14.4985 10.7442 14.4985H7.91116C7.05024 14.4985 6.32492 14.0431 6.10535 13.2737H3.34925C2.6593 13.2737 2.09998 12.7297 2.09998 12.0586V4.16032C2.09998 3.48923 2.6593 2.9452 3.34925 2.9452H3.90107C4.0206 2.39534 4.52241 1.98268 5.12332 1.98268H5.4791ZM3.97249 4.16032H3.24925L3.24925 12.0586H6.03725V7.82838C6.03725 6.82174 6.87623 6.00569 7.91116 6.00569H9.49563V4.16032H8.7727C8.58289 4.59611 8.13909 4.90183 7.62187 4.90183H5.12332C4.6061 4.90183 4.1623 4.59611 3.97249 4.16032ZM5.12332 2.89403H7.62187C7.79436 2.89403 7.93419 3.03003 7.93419 3.19781V3.68671C7.93419 3.85448 7.79436 3.99049 7.62187 3.99049H5.12332C4.95083 3.99049 4.811 3.85448 4.811 3.68671V3.19781C4.811 3.03003 4.95083 2.89403 5.12332 2.89403ZM7.91116 7.11157C7.56618 7.11157 7.28652 7.38359 7.28652 7.71913V12.7851C7.28652 13.1206 7.56618 13.3927 7.91116 13.3927H10.7442C10.8401 13.3927 10.9337 13.3712 11.0182 13.3311C11.1373 13.2746 11.1859 13.1423 11.1859 13.0134V12.0066C11.1859 11.8724 11.2978 11.7636 11.4358 11.7636H12.4709C12.6034 11.7636 12.7394 11.7163 12.7975 11.6004C12.8388 11.5182 12.8608 11.4272 12.8608 11.334V7.71913C12.8608 7.38359 12.5811 7.11157 12.2362 7.11157H7.91116Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},ra=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"paste-special-double-icon",ref:r,icon:yu}))});ra.displayName="PasteSpecialDoubleIcon";var Ru={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.666 2.70571C11.7769 1.76476 10.3295 1.76476 9.4404 2.70571L3.37843 9.12427C3.31779 9.18848 3.27756 9.26409 3.24979 9.3439C3.24809 9.3493 3.24299 9.3529 3.24129 9.3583L2.02912 13.2097C1.96112 13.4251 2.01439 13.6633 2.16626 13.8236C2.27393 13.9382 2.41901 14 2.56692 14C2.62699 14 2.68762 13.9898 2.74599 13.9688L6.3825 12.6846C6.3876 12.6828 6.391 12.678 6.39553 12.6762C6.47147 12.6474 6.54287 12.6042 6.60351 12.54L12.666 6.12202C13.5558 5.18048 13.5558 3.64725 12.666 2.70571ZM8.62832 5.26209L9.04031 5.69836C9.03918 5.69956 9.03748 5.70016 9.03634 5.70136L4.99182 9.9836L4.58096 9.54853L8.62832 5.26209ZM3.46287 12.4512L4.02673 10.6593L5.15446 11.8535L3.46287 12.4512ZM6.20342 11.2672L5.79256 10.8321L9.83709 6.54988C9.83822 6.54868 9.83879 6.54688 9.83992 6.54568L10.2513 6.98135L6.20342 11.2672ZM11.8647 5.27349L11.0532 6.13282L9.42963 4.41356L10.2411 3.55423C10.6888 3.08016 11.417 3.08076 11.8642 3.55423C12.3124 4.0283 12.3124 4.79942 11.8647 5.27349Z"}}]},oa=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"pen-icon",ref:r,icon:Ru}))});oa.displayName="PenIcon";var Mu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.785 6.77762C5.78908 6.7777 5.79316 6.77774 5.79725 6.77774C5.80134 6.77774 5.80543 6.7777 5.8095 6.77762H10.0184C10.0225 6.7777 10.0266 6.77774 10.0307 6.77774C10.0347 6.77774 10.0388 6.7777 10.0429 6.77762H13.6638V7.63727C13.6638 7.96864 13.9324 8.23727 14.2638 8.23727C14.5951 8.23727 14.8638 7.96864 14.8638 7.63727V3.9999C14.8638 2.56395 13.6997 1.39989 12.2637 1.3999L3.56389 1.39999C2.12797 1.40001 0.96393 2.56405 0.96392 3.99998L0.963867 11.6666C0.963857 13.1025 2.12792 14.2666 3.56387 14.2666H8.0542C8.38557 14.2666 8.6542 13.9979 8.6542 13.6666C8.6542 13.3352 8.38557 13.0666 8.0542 13.0666H3.56387C2.79067 13.0666 2.16386 12.4398 2.16387 11.6666L2.1639 6.77762H5.785ZM6.39725 2.59996L9.43065 2.59993V5.57762H6.39725V2.59996ZM5.19725 5.57762V2.59998L3.56391 2.59999C2.79072 2.6 2.16393 3.22679 2.16392 3.99998L2.16391 5.57762H5.19725ZM13.6638 5.57762V3.9999C13.6638 3.2267 13.037 2.59989 12.2638 2.5999L10.6307 2.59992V5.57762H13.6638Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M14.1223 10.2333V10.7496C14.7087 10.9869 15.1223 11.5618 15.1223 12.2333V12.8999C15.1223 13.7836 14.406 14.4999 13.5223 14.4999H11.5223C10.6387 14.4999 9.92235 13.7836 9.92235 12.8999V12.2333C9.92235 11.5618 10.336 10.9869 10.9223 10.7496V10.2333C10.9223 9.34961 11.6387 8.63328 12.5223 8.63328C13.406 8.63328 14.1223 9.34961 14.1223 10.2333ZM11.1223 12.2333C11.1223 12.0124 11.3014 11.8333 11.5223 11.8333H13.5223C13.7433 11.8333 13.9223 12.0124 13.9223 12.2333V12.8999C13.9223 13.1209 13.7433 13.2999 13.5223 13.2999H11.5223C11.3014 13.2999 11.1223 13.1209 11.1223 12.8999V12.2333ZM12.9223 10.2333V10.6333H12.1223V10.2333C12.1223 10.0124 12.3014 9.83328 12.5223 9.83328C12.7433 9.83328 12.9223 10.0124 12.9223 10.2333Z",fillRule:"evenodd",clipRule:"evenodd"}}]},sa=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"protect-icon",ref:r,icon:Mu}))});sa.displayName="ProtectIcon";var Pu={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M15 8C15 11.866 11.866 15 8 15C4.13401 15 1 11.866 1 8C1 4.13401 4.13401 1 8 1C11.866 1 15 4.13401 15 8ZM8.00008 12.3671C8.46031 12.3671 8.83342 11.994 8.83342 11.5338C8.83342 11.0735 8.46031 10.7004 8.00008 10.7004C7.53985 10.7004 7.16675 11.0735 7.16675 11.5338C7.16675 11.994 7.53985 12.3671 8.00008 12.3671ZM8.5999 4.4335C8.5999 4.10213 8.33127 3.8335 7.9999 3.8335C7.66853 3.8335 7.3999 4.10213 7.3999 4.4335V9.36683C7.3999 9.6982 7.66853 9.96683 7.9999 9.96683C8.33127 9.96683 8.5999 9.6982 8.5999 9.36683V4.4335Z",fillRule:"evenodd",clipRule:"evenodd"}}]},aa=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"warning-icon",ref:r,icon:Pu}))});aa.displayName="WarningIcon";var Ou={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.6551 1.98906C11.7476 1.08113 10.2757 1.08149 9.3686 1.98987L4.82542 6.53955C4.75087 6.61421 4.69336 6.70411 4.65682 6.80309L3.2461 10.625C3.16506 10.8446 3.21909 11.0912 3.3845 11.2568C3.54991 11.4224 3.79651 11.4767 4.01616 11.3959L7.85031 9.98517C7.94979 9.94856 8.04014 9.89077 8.11508 9.81579L12.6552 5.27327C13.5618 4.36621 13.5618 2.89607 12.6551 1.98906ZM10.2177 2.83779C10.6562 2.39869 11.3677 2.39851 11.8064 2.8374C12.2447 3.27584 12.2447 3.9865 11.8065 4.42497L7.3392 8.89457L4.82213 9.82068L5.74706 7.31487L10.2177 2.83779Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.79238 13.2999C1.46101 13.2999 1.19238 13.5685 1.19238 13.8999C1.19238 14.2313 1.46101 14.4999 1.79238 14.4999H14.4924C14.8238 14.4999 15.0924 14.2313 15.0924 13.8999C15.0924 13.5685 14.8238 13.2999 14.4924 13.2999H1.79238Z"}}]},oo=W.forwardRef(function(n,r){return W.createElement(Ce,Object.assign({},n,{id:"write-icon",ref:r,icon:Ou}))});oo.displayName="WriteIcon";const Au=()=>{const[,n]=W.useState({});return W.useCallback(()=>n(r=>!r),[])};function Du(){const n=_.useDependency(a.ICommandService),r=_.useDependency(a.IUniverInstanceService),e=_.useDependency(R.IRenderManagerService),t=_.useDependency(ut),i=_.useDependency(a.LocaleService),[o,s]=W.useState([]),[l,c]=W.useState(!1),[d,u]=W.useState({row:-1,col:-1}),[h,g]=W.useState(ce.SERIES),[S,f]=W.useState(!1),v=lt(),{sheetSkeletonManagerService:p,selectionRenderService:C}=W.useMemo(()=>{if(v){const j=e.getRenderById(v.getUnitId());return{sheetSkeletonManagerService:j==null?void 0:j.with(y.SheetSkeletonManagerService),selectionRenderService:j==null?void 0:j.with(ve)}}return{sheetSkeletonManagerService:null,selectionRenderService:null}},[v,e]),b=()=>{f(!0)},E=()=>{f(!1)},w=Au();if(W.useEffect(()=>n.onCommandExecuted((Q,ie)=>{Q.id===Le.id&&w()}).dispose,[w,n]),W.useEffect(()=>{const j=p&&a.toDisposable(p.currentSkeleton$.subscribe(Q=>{Q&&w()}));return j==null?void 0:j.dispose},[p,w]),W.useEffect(()=>a.toDisposable(t.menu$.subscribe(Q=>{s(Q.map(ie=>({...ie,index:Q.indexOf(ie)})))})).dispose,[t]),W.useEffect(()=>a.toDisposable(t.showMenu$.subscribe(Q=>{const{source:ie,target:$}=t.autoFillLocation||{source:null,target:null};if(Q&&ie&&$){const se=Math.max(ie.rows[ie.rows.length-1],$.rows[$.rows.length-1]),Z=Math.max(ie.cols[ie.cols.length-1],$.cols[$.cols.length-1]);u({row:se,col:Z})}else u({row:-1,col:-1})})).dispose,[t]),W.useEffect(()=>a.toDisposable(t.applyType$.subscribe(Q=>{g(Q)})).dispose,[t]),W.useEffect(()=>{function j(){c(!1)}return document.addEventListener("wheel",j),()=>{document.removeEventListener("wheel",j)}},[l]),d.col<0||d.row<0)return null;const O=Ne(r,e);if(!O||!C)return null;const{scene:M}=O,P=p==null?void 0:p.getCurrentSkeleton(),A=C.getViewPort(),k=M==null?void 0:M.scaleX,N=M==null?void 0:M.scaleY,H=M==null?void 0:M.getViewportScrollXY(A);if(!k||!M||!k||!N||!H)return null;const x=(P==null?void 0:P.getNoMergeCellWithCoordByIndex(d.row,d.col).endX)||0,L=(P==null?void 0:P.getNoMergeCellWithCoordByIndex(d.row,d.col).endY)||0,V=R.convertTransformToOffsetX(x,k,H),U=R.convertTransformToOffsetY(L,N,H);if(V==null||U==null)return null;const B=j=>{c(j)},Y=j=>{n.executeCommand(Wn.id,{type:j.value}),c(!1)},F=l||S,z=o.filter(j=>!j.disable);return I.jsx("div",{className:"univer-absolute univer-inset-0 univer-z-10 univer-size-0",children:I.jsx("div",{className:"univer-absolute",style:{left:`${V+2}px`,top:`${U+2}px`},onMouseEnter:b,onMouseLeave:E,children:I.jsx(X.DropdownMenu,{align:"start",items:z.map(j=>({type:"radio",value:h,options:[{label:i.t(j.label),value:j.value}],onSelect:()=>Y(j)})),open:l,onOpenChange:B,children:I.jsxs("div",{className:X.clsx("univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-800",X.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-800":l,"univer-bg-white dark:!univer-bg-gray-900":!l}),children:[I.jsx(Ks,{className:"univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-white"}),F&&I.jsx(sn,{className:"dark:!univer-text-white"})]})})})})}function so(n,r){const e=_.useDependency(me),t=_.useDependency(a.ICommandService);return W.useMemo(()=>({keyCodes:[{keyCode:_.KeyCode.ENTER},{keyCode:_.KeyCode.ESC},{keyCode:_.KeyCode.TAB}],handler:o=>{(o===_.KeyCode.ENTER||o===_.KeyCode.ESC||o===_.KeyCode.TAB)&&(e.disableForceKeepVisible(),t.syncExecuteCommand(ge.id,{visible:!1,eventType:R.DeviceInputEventType.Keyboard,keycode:o,unitId:r}))}}),[t,e,r])}const Xi=-1e3,la={width:0,height:0,top:Xi,left:Xi},ku=()=>{const[n,r]=W.useState({...la}),e=_.useDependency(Xn),t=_.useDependency(q.IEditorService),i=_.useDependency(a.IContextService),o=_.useDependency(_.ComponentManager),s=_.useDependency(me),l=_.useObservable(s.visible$),c=_.useDependency(a.ICommandService),d=W.useRef(0),u=_.useObservable(()=>i.subscribeContextValue$(_.DISABLE_AUTO_FOCUS_KEY),!1,void 0,[i,_.DISABLE_AUTO_FOCUS_KEY]),h=o.get(Di),g=s.getEditLocation();W.useEffect(()=>{const p=e.state$.subscribe(C=>{if(C==null)return;const{startX:b=Xi,startY:E=Xi,endX:w=0,endY:O=0,show:M=!1}=C;if(!M)r({...la});else{r({width:w-b,height:O-E,left:b,top:E});const P=t.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(P==null)return;const{left:A,top:k,width:N,height:H}=P.getBoundingClientRect();e.setRect({left:A,top:k,width:N,height:H})}});return()=>{p.unsubscribe()}},[]),W.useEffect(()=>{u||e.setFocus(!0)},[u,n]);const S=_.useEvent(()=>{s.isVisible().visible&&c.executeCommand(ge.id,{visible:!1,eventType:R.DeviceInputEventType.PointerUp,unitId:g==null?void 0:g.unitId})});_.useSidebarClick(S);const f=so(d,g==null?void 0:g.unitId),v=_.useEvent((p,C)=>{c.executeCommand(wt.id,{keycode:p,visible:!1,eventType:R.DeviceInputEventType.Keyboard,isShift:C===_.MetaKeys.SHIFT||C===(_.MetaKeys.CTRL_COMMAND|_.MetaKeys.SHIFT),unitId:g==null?void 0:g.unitId})});return I.jsx("div",{className:"univer-absolute univer-z-10 univer-flex",style:{left:n.left,top:n.top,width:n.width,height:n.height},children:h&&I.jsx(h,{editorId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,className:"univer-relative univer-flex univer-h-full univer-w-full [&_canvas]:univer-absolute",initValue:"",onChange:()=>{},isFocus:l==null?void 0:l.visible,unitId:g==null?void 0:g.unitId,subUnitId:g==null?void 0:g.sheetId,keyboardEventConfig:f,onMoveInEditor:v,isSupportAcrossSheet:!0,resetSelectionOnBlur:!1,isSingle:!1,autoScrollbar:!1,onFormulaSelectingChange:(p,C)=>{d.current=p,C&&(p?s.enableForceKeepVisible():s.disableForceKeepVisible())},disableSelectionOnClick:!0,disableContextMenu:!1})})};class Nu{constructor(){T(this,"_position",null);T(this,"_position$",new D.BehaviorSubject(null));T(this,"position$",this._position$.asObservable());T(this,"_focus",!1);T(this,"_focus$",new D.BehaviorSubject(this._focus));T(this,"focus$",this._focus$.asObservable());T(this,"_fxBtnClick$",new D.Subject);T(this,"fxBtnClick$",this._fxBtnClick$.asObservable());T(this,"_foldBtnStatus$",new D.Subject);T(this,"foldBtnStatus$",this._foldBtnStatus$.asObservable())}dispose(){this._position$.complete(),this._focus$.complete(),this._position=null,this._focus=!1}setPosition(r){this._position=r,this._refresh(r)}getPosition(){return this._position}setFocus(r=!1){this._focus=r,this._focus$.next(r)}handleFxBtnClick(r){this._fxBtnClick$.next(r)}handleFoldBtnClick(r){this._foldBtnStatus$.next(r)}_refresh(r){this._position$.next(r)}}const Yn=a.createIdentifier("univer.sheet-formula-editor-manager.service"),jn="DefinedNameContainer",Yi={id:"sidebar.operation.defined-name",type:a.CommandType.COMMAND,handler:async(n,r)=>{const e=n.get(_.ISidebarService);n.get(q.IEditorService);const t=n.get(a.LocaleService),i=n.get(a.IUniverInstanceService),o=m.getSheetCommandTarget(i);if(!o)return!1;const{unitId:s}=o;switch(r.value){case"open":e.open({id:jn,header:{title:t.t("definedName.featureTitle")},children:{label:jn},onClose:()=>{},width:333});break;case"close":default:e.close();break}return!0}};function Hu(){const n=_.useDependency(a.ICommandService),r=_.useDependency(a.LocaleService),e=_.useDependency(K.IDefinedNamesService),t=_.useDependency(a.IUniverInstanceService),i=_.useDependency(_.ISidebarService),s=t.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId(),l=()=>{const g=e.getDefinedNameMap(s);return g?Array.from(Object.values(g)):[]},[c,d]=W.useState(l());W.useEffect(()=>{const g=e.update$.subscribe(()=>{d(l())});return()=>{g.unsubscribe()}},[]),W.useEffect(()=>{const g=i.sidebarOptions$.subscribe(S=>{S.id===jn&&(S.visible||setTimeout(()=>{i.sidebarOptions$.next({visible:!1})}))});return()=>{g.unsubscribe()}},[]);const u=()=>{n.executeCommand(Yi.id,{value:"open"})},h=async g=>{const{formulaOrRefString:S,id:f}=g,v=e.getWorksheetByRef(s,S);if(!v)return;v.isSheetHidden()&&await n.executeCommand(m.SetWorksheetShowCommand.id,{unitId:s,subUnitId:v.getSheetId()}),e.focusRange(s,f)};return I.jsxs("div",{className:"univer-w-[300px]",children:[I.jsx("ul",{className:X.clsx("univer-m-0 univer-max-h-[360px] univer-list-none univer-overflow-y-auto univer-p-0",X.scrollbarClassName),children:c.map((g,S)=>I.jsx("li",{className:"univer-cursor-pointer univer-px-2 univer-transition-colors univer-duration-200 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-600",onClick:()=>{h(g)},children:I.jsxs("div",{className:X.clsx("univer-flex univer-items-center univer-justify-between univer-gap-2 univer-py-1",X.borderBottomClassName),children:[I.jsx("div",{className:"univer-w-[50%] univer-flex-shrink-0 univer-overflow-hidden univer-text-ellipsis univer-whitespace-nowrap univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",title:g.name,children:g.name}),I.jsx("div",{className:"univer-w-[50%] univer-flex-shrink-0 univer-overflow-hidden univer-text-ellipsis univer-whitespace-nowrap univer-text-xs univer-text-gray-400",title:g.formulaOrRefString,children:g.formulaOrRefString})]})},S))}),I.jsxs("div",{className:"univer-cursor-pointer univer-p-2 univer-transition-colors univer-duration-200 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-600",onClick:u,children:[I.jsx("div",{className:"univer-mb-2 univer-text-sm univer-font-semibold univer-text-gray-600 dark:!univer-text-gray-200",children:r.t("definedName.managerTitle")}),I.jsx("div",{className:"univer-text-xs univer-text-gray-400",children:r.t("definedName.managerDescription")})]})]})}function Vu({disable:n}){const[r,e]=W.useState(""),t=_.useDependency(K.IDefinedNamesService);W.useEffect(()=>{const o=t.currentRange$.subscribe(()=>{e(t.getCurrentRangeForString())});return()=>{o.unsubscribe()}},[]);function i(){}return I.jsxs("div",{"data-u-comp":"defined-name",className:"univer-relative univer-box-border univer-flex univer-h-full univer-w-24 univer-border-r-gray-200 univer-py-1.5 univer-transition-all",children:[I.jsx("input",{className:X.clsx("univer-box-border univer-h-full univer-w-full univer-appearance-none univer-px-1.5 univer-text-gray-900 focus:univer-outline-none dark:!univer-border-r-gray-700 dark:!univer-bg-gray-900 dark:!univer-text-white",X.borderRightClassName,{"univer-cursor-not-allowed":n}),type:"text",value:r,onChange:i}),I.jsx(X.Dropdown,{overlay:I.jsx("div",{className:"univer-z-[1001]",children:I.jsx(Hu,{})}),disabled:n,children:I.jsx("a",{className:X.clsx("univer-absolute univer-right-0 univer-top-0 univer-flex univer-h-full univer-cursor-pointer univer-items-center univer-justify-center univer-px-1 univer-transition-colors univer-duration-200 hover:univer-bg-gray-100 dark:!univer-text-white dark:hover:!univer-bg-gray-800",{"univer-cursor-not-allowed univer-text-gray-300 hover:univer-bg-transparent dark:!univer-text-gray-700":n}),children:I.jsx(sn,{})})})]})}function ca(n){var J,re,ue,oe;const{className:r,disableDefinedName:e}=n,[t,i]=W.useState(!1),[o,s]=W.useState(0),l=_.useDependency(Yn),c=_.useDependency(me),d=_.useDependency(m.WorksheetProtectionRuleModel),u=_.useDependency(m.RangeProtectionRuleModel),h=_.useDependency(a.IUniverInstanceService),g=_.useDependency(m.SheetsSelectionsService),S=_.useDependency(a.IPermissionService),f=_.useDependency(m.RangeProtectionCache),v=_.useDependency(a.ICommandService),[p,C]=W.useState({editDisable:!1,viewDisable:!1}),[b,E]=W.useState(!1),w=_.useDependency(_.ComponentManager),O=_.useObservable(()=>h.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),M=W.useRef(0),P=_.useObservable(c.currentEditCellState$),A=so(M,(J=P==null?void 0:P.unitId)!=null?J:""),k=w.get(Di),N=_.useComponentsOfPart(zr.FORMULA_AUX),H=_.useDependency(a.IContextService);_.useObservable(W.useMemo(()=>H.subscribeContextValue$(a.FOCUSING_FX_BAR_EDITOR),[H]));const x=H.getContextValue(a.FOCUSING_FX_BAR_EDITOR),L=W.useRef(null),V=_.useDependency(q.IEditorService);W.useLayoutEffect(()=>{const ae=O.activeSheet$.pipe(D.switchMap(te=>te?D.merge(d.ruleChange$,u.ruleChange$,g.selectionMoveEnd$,g.selectionSet$).pipe(D.switchMap(()=>{var Ct,_t;const fe=O.getUnitId(),pe=te.getSheetId();if(!((Ct=g.getCurrentLastSelection())==null?void 0:Ct.range))return D.EMPTY;const Ee=(_t=g.getCurrentLastSelection())==null?void 0:_t.primary;return Ee?D.of({unitId:fe,subUnitId:pe,primary:Ee}):D.of(null)})):D.EMPTY)).subscribe(te=>{var fe,pe,we,Ee,Ct,_t;if(te){const{unitId:jt,subUnitId:Nr,primary:ip}=te;if(d.getRule(jt,Nr)){const sp=!((pe=(fe=S.getPermissionPoint(new m.WorksheetEditPermission(jt,Nr).id))==null?void 0:fe.value)==null||pe),ap=!((Ee=(we=S.getPermissionPoint(new m.WorksheetViewPermission(jt,Nr).id))==null?void 0:we.value)==null||Ee);C({viewDisable:ap,editDisable:sp});return}const{actualRow:rp,actualColumn:op}=ip,An=f.getCellInfo(jt,Nr,rp,op);C({editDisable:!((Ct=An==null?void 0:An[m.UnitAction.Edit])==null||Ct),viewDisable:!((_t=An==null?void 0:An[m.UnitAction.View])==null||_t)})}else C({viewDisable:!1,editDisable:!1})});return()=>{ae.unsubscribe()}},[O]),W.useEffect(()=>{const ae=c.visible$.subscribe(te=>{i(te.visible)});return()=>ae.unsubscribe()},[c.visible$]),W.useEffect(()=>{const ae=c.currentEditCellState$.subscribe(te=>{var fe,pe,we;(we=(pe=(fe=te==null?void 0:te.documentLayoutObject.documentModel)==null?void 0:fe.getBody())==null?void 0:pe.customBlocks)!=null&&we.length?E(!0):E(!1)});return()=>ae.unsubscribe()},[c.currentEditCellState$]),W.useEffect(()=>{const ae=()=>{if(!L.current)return;const te=L.current.getBoundingClientRect();l.setPosition(te)};if(L.current){ae();const te=new ResizeObserver(ae);return te.observe(L.current),()=>te.disconnect()}},[l]);function U(){s(o===0?1:0),setTimeout(()=>{l.handleFoldBtnClick(o===1)},150)}function B(){c.isVisible().visible&&v.executeCommand(ge.id,{visible:!1,eventType:R.DeviceInputEventType.Keyboard,keycode:_.KeyCode.ESC,unitId:P.unitId})}function Y(){c.isVisible().visible&&v.executeCommand(ge.id,{visible:!1,eventType:R.DeviceInputEventType.PointerDown,unitId:P.unitId})}function F(){l.handleFxBtnClick(!0)}const{viewDisable:z,editDisable:j}=p,Q=j||b,ie=W.useRef(!1),$=()=>{try{c.isVisible().visible===!1&&v.syncExecuteCommand(ge.id,{visible:!0,eventType:R.DeviceInputEventType.PointerDown,unitId:P.unitId}),H.setContextValue(a.FOCUSING_FX_BAR_EDITOR,!0)}catch(ae){throw ie.current=!0,ae}},se=()=>{ie.current&&setTimeout(()=>{V.blur(!0)},30),ie.current=!1},G=((oe=(ue=(re=P==null?void 0:P.documentLayoutObject.documentModel)==null?void 0:re.getDrawingsOrder())==null?void 0:ue.length)!=null?oe:0)>0||z;return I.jsxs("div",{"data-u-comp":"formula-bar",className:X.clsx("univer-box-border univer-flex univer-bg-white univer-transition-[height] univer-ease-linear dark:!univer-bg-gray-900",X.borderBottomClassName,r,{"univer-h-7":o===0,"univer-h-20":o===1,"univer-pointer-events-none":j}),children:[I.jsx("div",{className:"univer-relative univer-box-border univer-h-full univer-w-[100px]",children:I.jsx(Vu,{disable:e!=null?e:j})}),I.jsxs("div",{className:"univer-flex univer-h-full univer-w-full",children:[I.jsx("div",{className:X.clsx("univer-py-1.5",{"univer-cursor-not-allowed univer-text-gray-200":Q}),children:I.jsxs("div",{className:X.clsx("univer-relative univer-box-border univer-flex univer-h-full univer-w-20 univer-items-center univer-justify-center univer-text-xs",X.borderRightClassName),children:[I.jsx("span",{className:X.clsx("univer-flex univer-items-center univer-justify-center univer-rounded univer-p-1 univer-text-base dark:!univer-text-white",{"univer-cursor-pointer univer-text-green-600 hover:univer-bg-gray-100 dark:!univer-text-green-400 dark:hover:!univer-bg-gray-700":t}),onClick:B,children:I.jsx(qs,{})}),I.jsx("span",{className:X.clsx("univer-flex univer-items-center univer-justify-center univer-rounded univer-p-1 univer-text-base dark:!univer-text-white",{"univer-cursor-pointer univer-text-red-600 hover:univer-bg-gray-100 dark:!univer-text-red-400 dark:hover:!univer-bg-gray-700":t}),onClick:Y,children:I.jsx(on,{})}),I.jsx("span",{className:"univer-flex univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-p-1 univer-text-base hover:univer-bg-gray-100 dark:!univer-text-white dark:hover:!univer-bg-gray-700",onClick:F,children:I.jsx(ea,{})})]})}),I.jsxs("div",{className:"univer-flex univer-w-full univer-flex-1 univer-overflow-hidden univer-pl-3",children:[I.jsxs("div",{ref:L,className:"univer-relative univer-flex-1",onPointerDown:$,onPointerUp:se,style:{pointerEvents:G?"none":"auto"},children:[k&&I.jsx(k,{className:"univer-relative univer-h-full univer-w-full univer-break-words univer-outline-none [&>div]:univer-ring-transparent",disableSelectionOnClick:!0,editorId:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,initValue:"",onChange:()=>{},isFocus:x,unitId:P==null?void 0:P.unitId,subUnitId:P==null?void 0:P.sheetId,isSupportAcrossSheet:!0,resetSelectionOnBlur:!1,isSingle:!1,keyboardEventConfig:A,onFormulaSelectingChange:(ae,te)=>{M.current=ae,te&&(ae?c.enableForceKeepVisible():c.disableForceKeepVisible())},autoScrollbar:!1,disableContextMenu:!1}),G&&I.jsx("div",{className:"univer-pointer-events-none univer-relative univer-left-0 univer-top-0 univer-z-[100] univer-h-full univer-w-full univer-cursor-not-allowed univer-bg-white"})]}),I.jsx("div",{className:X.clsx("univer-flex univer-h-full univer-w-5 univer-cursor-pointer univer-items-center univer-justify-center univer-text-xs univer-text-gray-700 dark:!univer-text-gray-200",{"univer-cursor-not-allowed univer-text-gray-200 dark:!univer-text-gray-700":j}),onClick:U,children:I.jsx(Js,{className:X.clsx({"univer-rotate-180":o===1})})})]})]}),I.jsx(_.ComponentContainer,{components:N},"formula-aux")]})}const Tt=a.createIdentifier("univer.sheetbar-service");class da extends a.Disposable{constructor(){super();T(this,"renameId$");T(this,"removeId$");T(this,"scroll$");T(this,"scrollX$");T(this,"addSheet$");T(this,"_renameId$");T(this,"_removeId$");T(this,"_scroll$");T(this,"_scrollX$");T(this,"_addSheet$");T(this,"_currentHandler",null);this._renameId$=new D.Subject,this.renameId$=this._renameId$.asObservable(),this._removeId$=new D.Subject,this.removeId$=this._removeId$.asObservable(),this._scroll$=new D.Subject,this.scroll$=this._scroll$.asObservable(),this._scrollX$=new D.Subject,this.scrollX$=this._scrollX$.asObservable(),this._addSheet$=new D.Subject,this.addSheet$=this._addSheet$.asObservable()}setRenameId(e){this._renameId$.next(e)}setRemoveId(e){this._removeId$.next(e)}setScroll(e){this._scroll$.next(e)}setScrollX(e){this._scrollX$.next(e)}setAddSheet(e){this._addSheet$.next(e)}triggerSheetBarMenu(){var e;(e=this._currentHandler)==null||e.handleSheetBarMenu()}registerSheetBarMenuHandler(e){if(this._currentHandler)throw new Error("There is already a context menu handler!");return this._currentHandler=e,a.toDisposable(()=>{this._currentHandler=null})}}function ji(n){const{children:r,className:e,style:t,disabled:i=!1,onClick:o,...s}=n,l=c=>{if(i){c.preventDefault();return}o&&o(c)};return I.jsx(X.Button,{"data-u-comp":"sheet-bar-append-button",className:e,size:"small",disabled:i,style:t,variant:"text",onClick:l,...s,children:r})}function Wu(){const[n,r]=W.useState([]),[e,t]=W.useState(!1),i=_.useDependency(a.IUniverInstanceService),o=_.useDependency(a.ICommandService),s=_.useDependency(Tt),l=_.useDependency(m.WorksheetProtectionRuleModel),c=_.useObservable(()=>i.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),null,!1,[]),d=v=>{const{sheetId:p}=v;!p||!c||(v.hidden?o.executeCommand(m.SetWorksheetShowCommand.id,{unitId:c.getUnitId(),subUnitId:p,value:p}):v.selected||o.executeCommand(m.SetWorksheetActivateCommand.id,{unitId:c.getUnitId(),subUnitId:p}),t(!1))},u=W.useCallback(()=>{if(!c)return;const v=c.getSheets(),p=c.getActiveSheet(),C=v.map((b,E)=>({label:b.getName(),index:`${E}`,sheetId:b.getSheetId(),hidden:b.isSheetHidden()===a.BooleanNumber.TRUE,selected:p===b}));r(C)},[c,l]),h=W.useCallback(()=>o.onCommandExecuted(v=>{switch(v.id){case m.SetWorksheetHideMutation.id:case m.RemoveSheetMutation.id:case m.SetWorksheetNameMutation.id:case m.InsertSheetMutation.id:case m.SetWorksheetOrderMutation.id:case m.SetWorksheetActiveOperation.id:u();break}}),[o,u]);function g(){t(!0)}const S=v=>{t(v)};W.useEffect(()=>{u();const v=new a.DisposableCollection;return v.add(h()),v.add(s.registerSheetBarMenuHandler({handleSheetBarMenu:g})),()=>v.dispose()},[h,s,u,c]);const f=W.useMemo(()=>n.map(v=>({type:"item",children:I.jsxs("div",{className:"univer-relative univer-box-border univer-pl-6",children:[(v.selected||v.hidden)&&I.jsxs("span",{className:"univer-absolute univer-left-1 univer-top-0.5",children:[v.selected&&I.jsx(on,{className:"univer-size-4 univer-text-primary-600"}),v.hidden&&I.jsx($s,{className:"univer-size-4 univer-text-gray-400"})]}),I.jsx("span",{className:X.clsx({"univer-text-primary-600":v.selected}),children:v.label})]}),onSelect:()=>{d(v)}})),[n]);return I.jsx(X.DropdownMenu,{align:"start",items:f,open:e,onOpenChange:S,children:I.jsx("div",{children:I.jsx(ji,{children:I.jsx(Qs,{})})})})}function xu(n){const{sheetId:r,label:e,color:t,selected:i,menuOverlay:o}=n,[s,l]=W.useState(i),c=_.useDependency(a.ThemeService);W.useEffect(()=>{l(i)},[i]);const d=u=>{const h=c.getColorFromTheme("gray.900"),g=c.getColorFromTheme("white");return new a.ColorKit(u).isDark()?g:h};return I.jsx("div",{"data-u-comp":"slide-tab-item","data-id":r,className:X.clsx("univer-mx-1 univer-box-border univer-flex univer-flex-grow univer-cursor-pointer univer-select-none univer-flex-row univer-items-center univer-rounded univer-text-xs univer-transition-[colors,box-shadow]",{"dark:!univer-text-white":!t||t&&!d(t),"univer-justify-center univer-bg-white univer-font-bold univer-text-primary-700 univer-shadow":s,"dark:!univer-bg-gray-900":s&&!t,"univer-font-medium univer-text-gray-900 hover:univer-bg-gray-100":!s,"dark:hover:!univer-bg-gray-700":!s&&!t}),style:{backgroundColor:!s&&t?t:"",color:!s&&t?d(t):"",boxShadow:s&&t?`0px 0px 8px rgba(0, 0, 0, 0.08), inset 0px -2px 0px 0px ${t}`:""},children:I.jsx("div",{className:"univer-box-border univer-flex univer-items-center univer-gap-1 univer-whitespace-nowrap univer-rounded univer-border-2 univer-border-solid univer-border-transparent univer-px-1.5 univer-py-1",children:e})},r)}const Lu={easeOutStrong(n,r,e,t){return-e*((n=n/t-1)*n*n*n-1)+r},backOut(n,r,e,t,i){return typeof i>"u"&&(i=.7),e*((n=n/t-1)*n*((i+1)*n+i)+1)+r}},Uu={loop:!1,begin:0,end:0,duration:300,delay:0,type:"easeOutStrong",receive(n){},success(n){},cancel(n){},complete(n){}};class Bu{constructor(r){T(this,"_config");T(this,"_status",0);T(this,"_start",0);T(this,"_handle",0);T(this,"_delayHandle",null);this._config={...Uu,...r},this._config.loop&&(this._config.complete=()=>{},this._config.success=()=>{this.request()})}static success(...r){let e=0;return new Promise(t=>{for(let i=0;i<r.length;i++){const o=r[i],s=o._config,l=s.success;s.loop||(s.success=d=>{e++,l&&l.call(o,d),e===r.length&&t()})}})}request(){this._config.delay===0?(this._status=0,this._start=Date.now(),this._fakeHandle()):(this._delayHandle&&clearTimeout(this._delayHandle),this._delayHandle=setTimeout(()=>{this._status=0,this._start=Date.now(),this._fakeHandle()},this._config.delay))}cancel(){this._status=1,this._delayHandle&&clearTimeout(this._delayHandle),cancelAnimationFrame(this._handle)}_fakeHandle(){let r=Date.now()-this._start;r=r>=this._config.duration?this._config.duration:r;const t=Lu[this._config.type](r,this._config.begin,this._config.end-this._config.begin,this._config.duration,.7).toFixed(2);if(this._config.receive(t),this._status===1){this._config.cancel(t),this._config.complete(t);return}if(r===this._config.duration){this._config.success(t),this._config.complete(t);return}this._handle=requestAnimationFrame(()=>{this._fakeHandle()})}}class yt{constructor(r,e){T(this,"_slideTabItem");T(this,"_animate");T(this,"_midline",0);T(this,"_translateX");T(this,"_scrollbar");T(this,"_slideTabBar");T(this,"_editMode");T(this,"_placeholder");this._slideTabItem=r,this._animate=null,this._translateX=0,this._editMode=!1,this._slideTabBar=e,this._placeholder=null,this._scrollbar=e.getScrollbar(),this.update()}static midline(r){return r.getBoundingRect().x+r.getBoundingRect().width/2}static leftLine(r){return r.getBoundingRect().x}static rightLine(r){return r.getBoundingRect().x+r.getBoundingRect().width}static make(r,e){const t=[];return r.forEach(i=>t.push(new yt(i,e))),t}getSlideTabItem(){return this._slideTabItem}getEditor(){return this._slideTabItem.querySelector("span")}focus(){var r;(r=this.getEditor())==null||r.focus()}selectAll(){const r=this.getEditor();r&&an.keepSelectAll(r)}isEditMode(){return this._editMode}classList(){return this._slideTabItem.classList}translateX(r){return this._translateX=r,this._slideTabItem.style.transform=`translateX(${r}px)`,this.getTranslateXDirection()}setEditor(r){if(!this._slideTabBar.getConfig().onNameChangeCheck())return;let e=!0;if(this._editMode===!1){const t=this._slideTabItem.querySelector("span"),i=d=>{if(!this.nameCheck()){if(this._editMode=!1,t&&(t.removeAttribute("contentEditable"),t.removeEventListener("focusout",i),t.removeEventListener("compositionstart",s),t.removeEventListener("compositionend",l),t.removeEventListener("input",c),t.removeEventListener("keydown",o)),this._slideTabBar.removeListener(),this._slideTabBar.updateItems(),this._slideTabBar.getConfig().onChangeName){const u=(t==null?void 0:t.innerText)||"",h=this.getId();this._slideTabBar.getConfig().onChangeName(h,u)}r&&r(d)}};let o=d=>{t&&(d.stopPropagation(),d.key==="Enter"&&t.blur())};const s=d=>{e=!1},l=d=>{e=!0},c=d=>{if(!t)return;const u=31;setTimeout(()=>{if(e){const h=t.innerText;h.length>u&&(t.innerText=h.substring(0,u),an.keepLastIndex(t))}},0)};t&&(t.setAttribute("contentEditable","true"),t.addEventListener("focusout",i),t.addEventListener("compositionstart",s),t.addEventListener("compositionend",l),t.addEventListener("input",c),t.addEventListener("keydown",o),this._editMode=!0,an.keepSelectAll(t))}}nameCheck(){const r=this._slideTabItem.querySelector("span");if(!r)return!1;const e=r.innerText;return this._slideTabBar.getConfig().onNameCheckAlert(e)}animate(){return{translateX:r=>{this._translateX!==r&&(this._animate&&(this._animate.cancel(),this._animate=null),this._animate=new Bu({begin:this._translateX,end:r,receive:e=>{this._slideTabItem.style.transform=`translateX(${e}px)`}}),this._translateX=r,this._animate.request())},cancel:()=>{this._animate&&(this._animate.cancel(),this._animate=null)}}}after(r){this._slideTabItem.after(r._slideTabItem||r)}update(){this._midline=yt.midline(this)}disableFixed(){if(this._placeholder){const r=this._slideTabBar.primeval();this._slideTabItem.style.removeProperty("position"),this._slideTabItem.style.removeProperty("left"),this._slideTabItem.style.removeProperty("top"),this._slideTabItem.style.removeProperty("width"),this._slideTabItem.style.removeProperty("height"),this._slideTabItem.style.removeProperty("background"),this._slideTabItem.style.removeProperty("padding"),this._slideTabItem.style.removeProperty("box-sizing"),this._slideTabItem.style.removeProperty("font-size"),this._slideTabItem.style.removeProperty("font-family"),this._slideTabItem.style.removeProperty("font-weight"),this._slideTabItem.style.removeProperty("color"),this._slideTabItem.style.removeProperty("border-radius"),this._placeholder.after(this._slideTabItem),r.removeChild(this._placeholder),this._placeholder=null}}enableFixed(){const r=document.createElement("div"),e=this.getBoundingRect(),t=getComputedStyle(this._slideTabItem),i=this._slideTabItem.querySelector("span");if(this._placeholder=r,this._placeholder.style.width=`${e.width}px`,this._placeholder.style.height=`${e.height}px`,this._placeholder.style.flexShrink="0",this._placeholder.style.margin=t.margin,this._slideTabItem.style.background=t.background,i){const o=getComputedStyle(i).padding;this._slideTabItem.style.padding=o}this._slideTabItem.style.boxSizing=t.boxSizing,this._slideTabItem.style.fontSize=t.fontSize,this._slideTabItem.style.fontFamily=t.fontFamily,this._slideTabItem.style.fontWeight=t.fontWeight,this._slideTabItem.style.color=t.color,this._slideTabItem.style.borderRadius=t.borderRadius,this._slideTabItem.style.left=`${e.x-this.getScrollbar().getScrollX()}px`,this._slideTabItem.style.top=`${e.y}px`,this._slideTabItem.style.width=`${e.width}px`,this._slideTabItem.style.height=`${e.height}px`,this._slideTabItem.style.position="fixed",this._slideTabItem.after(r),document.body.appendChild(this._slideTabItem)}addEventListener(r,e,t){this._slideTabItem.addEventListener(r,e,t)}removeEventListener(r,e,t){this._slideTabItem.removeEventListener(r,e,t)}getScrollbar(){return this._scrollbar}getMidLine(){return this._midline}getBoundingRect(){const r=this._slideTabItem.getBoundingClientRect();return r.x+=this._scrollbar.getScrollX(),r}getWidth(){return this.getBoundingRect().width}getTranslateXDirection(){const r=yt.midline(this);return r>this._midline?1:r<this._midline?-1:0}equals(r){return r&&r._slideTabItem===this._slideTabItem}getId(){return this._slideTabItem.dataset.id||""}}class Fu{constructor(r){T(this,"_slideTabBar");T(this,"_scrollX");const e=r.primeval();this._scrollX=e.scrollLeft,this._slideTabBar=r}scrollX(r){const e=this._slideTabBar.primeval();e.scrollLeft=r,this._scrollX=e.scrollLeft}scrollRight(){const r=this._slideTabBar.primeval();r.scrollLeft=r.scrollWidth,this._scrollX=r.scrollLeft}getScrollX(){return this._scrollX}}const On=class On{constructor(r){T(this,"_activeTabItemIndex",0);T(this,"_slideTabBar");T(this,"_slideTabItems",[]);T(this,"_config");T(this,"_downActionX",0);T(this,"_moveActionX",0);T(this,"_compareIndex",0);T(this,"_activeTabItem",null);T(this,"_moveAction");T(this,"_upAction");T(this,"_downAction");T(this,"_wheelAction");T(this,"_scrollIncremental",0);T(this,"_compareDirection",0);T(this,"_autoScrollTime",null);T(this,"_slideScrollbar");T(this,"_longPressTimer",null);T(this,"_leftBoundingLine",0);T(this,"_rightBoundingLine",0);T(this,"_leftMoveX",0);T(this,"_rightMoveX",0);if(r.slideTabBarContainer==null)throw new Error("not found slide-tab-bar root element");const e=r.slideTabBarContainer.querySelector(`${r.slideTabBarSelector}`);if(e==null)throw new Error("not found slide-tab-bar");this._slideTabBar=e,this._slideScrollbar=new Fu(this),this._config=r,this._initConfig();let t=0,i=0,o=0;this._downAction=s=>{var O,M,P,A,k,N;if((O=this._activeTabItem)!=null&&O.isEditMode())return;this._longPressTimer&&(clearTimeout(this._longPressTimer),this._longPressTimer=null);const l=(P=(M=s.target)==null?void 0:M.closest(`${r.slideTabBarItemSelector}`))==null?void 0:P.getAttribute("data-id"),c=this._slideTabItems.findIndex(H=>H.getId()===l);if(l==null||c===-1)return;if(this._activeTabItemIndex!==c){(A=this._activeTabItem)==null||A.removeEventListener("pointermove",this._moveAction),(k=this._activeTabItem)==null||k.removeEventListener("pointerup",this._upAction),this.removeListener(),this._config.onChangeTab(s,l);return}if(this._compareIndex=c,this._downActionX=s.pageX,this._moveActionX=0,this._scrollIncremental=0,this._activeTabItem=this._slideTabItems[c],!this._activeTabItem){console.error("Not found active slide-tab-item in sheet bar");return}const d=this._activeTabItem.getSlideTabItem();d==null||d.setPointerCapture(s.pointerId),(N=this._activeTabItem)==null||N.addEventListener("pointerup",this._upAction);const{x:u,width:h}=this._activeTabItem.getBoundingRect(),{x:g,width:S}=this.getBoundingRect(),f=this._slideScrollbar.getScrollX();if(this._leftBoundingLine=this._downActionX-(u-f),this._rightBoundingLine=u-f+h-this._downActionX,this._leftMoveX=u-g-f,this._rightMoveX=g+S-(u+h)+f,s.button===2||this._hasEditItem())return;const{pageX:v,pageY:p}=s,C=Date.now(),b=C-o<=On.DoubleClickDelay,E=Math.abs(v-t)<10,w=Math.abs(p-i)<10;b&&E&&w&&this._activeTabItem.setEditor(),t=v,i=p,o=C,this._longPressTimer=setTimeout(()=>{var H,x,L;!d||(H=this._activeTabItem)!=null&&H.isEditMode()||((x=this._activeTabItem)==null||x.enableFixed(),this._startAutoScroll(),d.setPointerCapture(s.pointerId),d.style.cursor="move",(L=this._activeTabItem)==null||L.addEventListener("pointermove",this._moveAction))},On.LongPressDelay)},this._upAction=s=>{var d,u,h,g;if((d=this._activeTabItem)!=null&&d.isEditMode()||(this._longPressTimer&&(clearTimeout(this._longPressTimer),this._longPressTimer=null),!this._activeTabItem))return;const l=this._autoScrollTime!==null;this._closeAutoScroll(),this._activeTabItem.disableFixed(),this.updateItems();const c=(u=this._activeTabItem)==null?void 0:u.getSlideTabItem();c&&(c.style.cursor="",c.releasePointerCapture(s.pointerId),(h=this._activeTabItem)==null||h.removeEventListener("pointermove",this._moveAction),(g=this._activeTabItem)==null||g.removeEventListener("pointerup",this._upAction),this._config.onSlideEnd&&this._activeTabItemIndex!==this._compareIndex&&l&&(this.removeListener(),this._config.onSlideEnd(s,this._compareIndex||0)),this._scrollIncremental=0,this._downActionX=0,this._moveActionX=0,this._compareIndex=0)},this._moveAction=s=>{this._activeTabItem&&(this._moveActionX=s.pageX-this._downActionX,this._moveActionX<=-this._leftMoveX?this._moveActionX=-this._leftMoveX:this._moveActionX>=this._rightMoveX&&(this._moveActionX=this._rightMoveX),this._scrollIncremental=0,this._scrollLeft(s),this._scrollRight(s))},this._wheelAction=s=>{this.setScroll(s.deltaY)},this.addListener()}static checkedSkipSlide(r){let e=r.target;for(;e!=null&&e!==document.body;){if(e.getAttribute("data-slide-skip"))return!0;e=e.parentElement}return!1}static keepLastIndex(r){setTimeout(()=>{const e=window.getSelection();e&&(e.selectAllChildren(r),e.collapseToEnd())})}static keepSelectAll(r){setTimeout(()=>{const e=window.getSelection();if(!e)return;const t=document.createRange();t.selectNodeContents(r),e.removeAllRanges(),e.addRange(t)})}update(r){this._config.currentIndex=r,this._initConfig(),this.removeListener(),this.addListener(),this.scrollToItem(r)}primeval(){return this._slideTabBar}updateItems(){for(let r=0;r<this._slideTabItems.length;r++)this._slideTabItems[r].animate().cancel(),this._slideTabItems[r].translateX(0),this._slideTabItems[r].update()}getScrollbar(){return this._slideScrollbar}getConfig(){return this._config}getBoundingRect(){return this._slideTabBar.getBoundingClientRect()}getSlideTabItems(){return this._slideTabItems}getActiveItem(){return this._activeTabItem}isLeftEnd(){return this._slideTabBar.scrollLeft===0}isRightEnd(){const r=this._slideTabBar.parentElement;return r?this._slideTabBar.scrollWidth-r.clientWidth===this._slideTabBar.scrollLeft:!1}addListener(){this._slideTabBar.addEventListener("wheel",this._wheelAction),this._slideTabItems.forEach(r=>{r.addEventListener("pointerdown",this._downAction)})}removeListener(){this._slideTabBar.removeEventListener("wheel",this._wheelAction),this._slideTabItems.forEach(r=>{r.removeEventListener("pointerdown",this._downAction)})}setScroll(r){if(this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+r),r>0){const e=this.calculateLeftScrollX();this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e)}else if(r<0){const e=this.calculateRightScrollX();this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e)}this._config.onScroll({leftEnd:this.isLeftEnd(),rightEnd:this.isRightEnd()})}flipPage(r){if(r>0){const e=this.calculateLeftScrollX(!0);this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e)}else if(r<0){const e=this.calculateRightScrollX(!0);this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e)}this._config.onScroll({leftEnd:this.isLeftEnd(),rightEnd:this.isRightEnd()})}scrollToItem(r){if(r=r!=null?r:this._config.currentIndex,r<0||r>=this._slideTabItems.length){console.error("Index out of bounds");return}const e=this.calculateTabItemScrollX(r);this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e),this._config.onScroll({leftEnd:this.isLeftEnd(),rightEnd:this.isRightEnd()})}calculateLeftScrollX(r){let e=0;const t=4;return this._slideTabItems.some(i=>{const o=this._slideTabBar.getBoundingClientRect(),s=o.left+o.width,l=i.getSlideTabItem().getBoundingClientRect(),c=l.left,d=l.width;return c<s&&c+d+t*2>s?(e=r?c-o.left-t:c+d-s+t,!0):!1}),e}calculateRightScrollX(r){let e=0;const t=4;return this._slideTabItems.some(i=>{const o=this._slideTabBar.getBoundingClientRect(),s=o.left,l=i.getSlideTabItem().getBoundingClientRect(),c=l.left,d=l.width;return c-t*2<s&&c+d>s?(e=r?c+d-o.left-o.width+t:c-s-t,!0):!1}),e}calculateTabItemScrollX(r){let e=0;const t=4,i=this._slideTabBar.getBoundingClientRect(),o=i.left,s=i.left+i.width,l=this._slideTabItems[r].getSlideTabItem().getBoundingClientRect(),c=l.left,d=l.width;return c-t*2<o&&(e=c-o-t),c+d+t*2>s&&(e=c+d-s+t),e}calculateActiveTabItemScrollX(){var d;let r=0;const e=4,t=this._slideTabBar.getBoundingClientRect(),i=t.left,o=t.left+t.width,s=(d=this._activeTabItem)==null?void 0:d.getSlideTabItem().getBoundingClientRect();if(!s)return 0;const l=s.left,c=s.width;return l-e*2<i&&l+c>i&&(r=l-i-e),l<o&&l+c+e*2>o&&(r=l+c-o+e),r}destroy(){this.removeListener(),this._downActionX=0,this._moveActionX=0,this._compareDirection=0,this._compareIndex=0,this._slideTabItems=[],this._activeTabItem=null}_hasEditItem(){for(let r=0;r<this._slideTabItems.length;r++)if(this._slideTabItems[r].isEditMode())return!0;return!1}_autoScrollFrame(){if(this._activeTabItem)switch(this._compareDirection=this._activeTabItem.translateX(this._moveActionX),this._compareDirection){case 1:{this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+this._scrollIncremental),this._compareRight();break}case 0:{this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+this._scrollIncremental),this._compareIndex=this._activeTabItemIndex;break}case-1:{this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+this._scrollIncremental),this._compareLeft();break}}this._autoScrollTime=requestAnimationFrame(()=>{this._autoScrollFrame()})}_startAutoScroll(){this._autoScrollTime==null&&this._autoScrollFrame()}_closeAutoScroll(){this._autoScrollTime&&cancelAnimationFrame(this._autoScrollTime),this._autoScrollTime=null}_scrollLeft(r){const e=this.getBoundingRect(),t=r.pageX-e.x;t<this._leftBoundingLine&&(this._scrollIncremental=-Math.min(Math.abs(t-this._leftBoundingLine)*.1,50))}_scrollRight(r){const e=this.getBoundingRect(),t=r.pageX-e.x;t>e.width-this._rightBoundingLine&&(this._scrollIncremental=Math.min(Math.abs(t-(e.width-this._rightBoundingLine))*.1,50))}_sortedItems(){if(this._activeTabItem!=null&&this._activeTabItemIndex!=null&&this._compareIndex!=null&&(this._slideTabItems.splice(this._activeTabItemIndex,1),this._slideTabItems.splice(this._compareIndex,0,this._activeTabItem),this._config.slideTabBarItemAutoSort))for(let r=0;r<this._slideTabItems.length;r++){const e=this._slideTabItems[r],t=this._slideTabItems[r+1];t&&e.after(t)}}_compareLeft(){if(this._activeTabItem&&this._activeTabItemIndex){const r=this._slideTabItems.findIndex(o=>o.equals(this._activeTabItem)),e=this._slideTabItems.length,t=[];for(let o=0;o<r&&!(o>=r);o++)t.push(this._slideTabItems[o]);for(let o=r+1;o<e;o++)this._slideTabItems[o].animate().translateX(0);let i=!0;for(let o=t.length-1;o>=0;o--){const s=t[o];yt.leftLine(this._activeTabItem)<s.getMidLine()?(s.animate().translateX(this._activeTabItem.getWidth()),this._compareIndex=o,i=!1):(s.animate().translateX(0),i&&(this._compareIndex=this._activeTabItemIndex))}}}_compareRight(){if(this._activeTabItem){const r=this._slideTabItems.findIndex(o=>o.equals(this._activeTabItem)),e=this._slideTabItems.length,t=[];for(let o=r+1;o<e;o++)t.push(this._slideTabItems[o]);for(let o=0;o<r;o++)this._slideTabItems[o].animate().translateX(0);let i=!0;for(let o=0;o<t.length;o++){const s=t[o];yt.rightLine(this._activeTabItem)>s.getMidLine()?(s.animate().translateX(-this._activeTabItem.getWidth()),this._compareIndex=r+o+1,i=!1):(s.animate().translateX(0),i&&(this._compareIndex=this._activeTabItemIndex))}}}_initConfig(){const r=this._slideTabBar.querySelectorAll(`${this._config.slideTabBarItemSelector}`);this._downActionX=0,this._moveActionX=0,this._compareDirection=0,this._compareIndex=0,this._slideTabItems=yt.make(r,this),this._activeTabItemIndex=this._config.currentIndex,this._activeTabItem=this._slideTabItems[this._activeTabItemIndex]}};T(On,"LongPressDelay",500),T(On,"DoubleClickDelay",300);let an=On;function zu(){var se;const[n,r]=W.useState([]),[e,t]=W.useState(""),[i,o]=W.useState(""),[s,l]=W.useState(!1),[c,d]=W.useState([0,0]),u=W.useRef({slideTabBar:null}),h=W.useRef(null),g=_.useDependency(a.ICommandService),S=_.useDependency(Tt),f=_.useDependency(a.LocaleService),v=_.useDependency(_.IConfirmService),p=_.useDependency(me,a.Quantity.OPTIONAL),C=_.useDependency(m.WorksheetProtectionRuleModel),b=_.useDependency(m.RangeProtectionRuleModel),E=_.useObservable(C.resetOrder$),w=lt(),O=_.useDependency(a.IPermissionService),M=W.useCallback(()=>{var ue;const Z=((ue=w.getActiveSheet())==null?void 0:ue.getSheetId())||"";t(Z);const G=w.getSheets(),J=w.getActiveSheet(),re=G.filter(oe=>!oe.isSheetHidden()).map((oe,ae)=>{var Ee;const te=C.getRule(w.getUnitId(),oe.getSheetId()),fe=b.getSubunitRuleList(w.getUnitId(),oe.getSheetId()).length>0,we=(te==null?void 0:te.permissionId)||fe?I.jsxs(I.Fragment,{children:[I.jsx(io,{}),I.jsx("span",{className:"univer-outline-none",children:oe.getName()})]}):I.jsx("span",{className:"univer-outline-none",children:oe.getName()});return{sheetId:oe.getSheetId(),label:we,index:ae,selected:J===oe,color:(Ee=oe.getTabColor())!=null?Ee:void 0}});r(re),t(Z)},[b,w,C]);W.useEffect(()=>{M();const{slideTabBar:Z,disconnectResizeObserver:G}=P(),J=B(),re=[Y(),F(),z()];return()=>{J.dispose(),Z.destroy(),re.forEach(ue=>ue.unsubscribe()),G&&G()}},[E,w]),W.useEffect(()=>{n.length>0&&U()},[n]),W.useEffect(()=>{const Z=D.merge(C.ruleChange$,b.ruleChange$).subscribe(()=>{M()});return()=>{Z.unsubscribe()}},[C,M]);const P=()=>{const Z=new an({slideTabBarSelector:"[data-u-comp=slide-tab-bar]",slideTabBarItemSelector:"[data-u-comp=slide-tab-item]",slideTabBarItemAutoSort:!0,slideTabBarContainer:h.current,currentIndex:0,onChangeName:(J,re)=>{g.executeCommand(m.SetWorksheetNameCommand.id,{subUnitId:J,name:re})},onSlideEnd:async(J,re)=>{await g.executeCommand(m.SetWorksheetOrderCommand.id,{order:re})},onChangeTab:(J,re)=>{g.executeCommand(m.SetWorksheetActiveOperation.id,{subUnitId:re,unitId:w.getUnitId()}).then(()=>{J.button===2&&$(!0)})},onScroll:J=>{S.setScroll(J)},onNameCheckAlert:J=>N(J)||H(J)||x(J),onNameChangeCheck:()=>{var te,fe,pe,we;const J=w.getUnitId(),re=w==null?void 0:w.getActiveSheet();if(!re)throw new Error("No active sheet found");const ue=re.getSheetId(),oe=C.getRule(J,ue),ae=b.getSubunitRuleList(J,ue).length>0;return oe||ae?(fe=(te=O.getPermissionPoint(new m.WorkbookManageCollaboratorPermission(J).id))==null?void 0:te.value)!=null?fe:!1:(we=(pe=O.getPermissionPoint(new m.WorkbookRenameSheetPermission(J).id))==null?void 0:pe.value)!=null?we:!1}});u.current.slideTabBar=Z;const G=ie(Z);return{slideTabBar:Z,disconnectResizeObserver:G}},A=_.useConfigValue(_.UI_PLUGIN_CONFIG_KEY),k=(se=A==null?void 0:A.contextMenu)!=null?se:!0,N=Z=>{if(Z.trim()===""){const G="sheetNameEmptyAlert";return v.open({id:G,title:{title:f.t("sheetConfig.sheetNameErrorTitle")},children:{title:f.t("sheetConfig.sheetNameCannotIsEmptyError")},cancelText:f.t("button.cancel"),confirmText:f.t("button.confirm"),onClose(){L(),v.close(G)},onConfirm(){L(),v.close(G)}}),!0}return!1},H=Z=>{if(!a.nameCharacterCheck(Z)){const G="sheetNameSpecCharAlert";return v.open({id:G,title:{title:f.t("sheetConfig.sheetNameErrorTitle")},children:{title:f.t("sheetConfig.sheetNameSpecCharError")},cancelText:f.t("button.cancel"),confirmText:f.t("button.confirm"),onClose(){L(),v.close(G)},onConfirm(){L(),v.close(G)}}),!0}return!1},x=Z=>{const G=w.getActiveSheet();if((G==null?void 0:G.getName())===Z)return!1;const re=w.checkSheetName(Z);if(re){const ue="sheetNameRepeatAlert";v.open({id:ue,title:{title:f.t("sheetConfig.sheetNameErrorTitle")},children:{title:f.t("sheetConfig.sheetNameAlreadyExistsError")},cancelText:f.t("button.cancel"),confirmText:f.t("button.confirm"),onClose(){v.close(ue),L()},onConfirm(){v.close(ue),L()}})}return re},L=()=>{setTimeout(()=>{var G;const Z=(G=u.current.slideTabBar)==null?void 0:G.getActiveItem();Z&&(Z.focus(),Z.selectAll())},0)},V=()=>{var Z,G;(G=(Z=u.current.slideTabBar)==null?void 0:Z.getActiveItem())==null||G.setEditor()},U=()=>{var G;const Z=n.findIndex(J=>J.selected);(G=u.current.slideTabBar)==null||G.update(Z)},B=()=>g.onCommandExecuted(Z=>{switch(Z.id){case m.SetTabColorMutation.id:case m.SetWorksheetHideMutation.id:case m.RemoveSheetMutation.id:case m.SetWorksheetNameMutation.id:case m.InsertSheetMutation.id:case m.SetWorksheetOrderMutation.id:case m.SetWorksheetActiveOperation.id:M();break}}),Y=()=>S.scroll$.subscribe(Z=>{j(Z)}),F=()=>S.scrollX$.subscribe(Z=>{var G;(G=u.current.slideTabBar)==null||G.flipPage(Z)}),z=()=>S.renameId$.subscribe(()=>{V()}),j=Z=>{const{leftEnd:G,rightEnd:J}=Z;let re="";G&&J?re="":G&&!J?re="inset -10px 0px 10px -10px rgba(0, 0, 0, 0.2)":!G&&J?re="inset 10px 0px 10px -10px rgba(0, 0, 0, 0.2)":!G&&!J&&(re="inset 10px 0px 10px -10px rgba(0, 0, 0, 0.2), inset -10px 0px 10px -10px rgba(0, 0, 0, 0.2)"),o(re)},Q=Z=>{const G=Z.calculateActiveTabItemScrollX();if(G){const J=Z.getScrollbar();J.scrollX(J.getScrollX()+G)}S.setScroll({leftEnd:Z.isLeftEnd(),rightEnd:Z.isRightEnd()})},ie=Z=>{var re;const G=(re=h.current)==null?void 0:re.querySelector("[data-u-comp=slide-tab-bar]");if(!G)return;const J=new ResizeObserver(()=>{Q(Z)});return J.observe(G),()=>J.disconnect()},$=Z=>{var G,J,re,ue,oe;if(k&&!(p!=null&&p.isForceKeepVisible())){if(Z){const{left:ae}=(J=(G=h.current)==null?void 0:G.getBoundingClientRect())!=null?J:{},{left:te}=(oe=(ue=(re=u.current.slideTabBar)==null?void 0:re.getActiveItem())==null?void 0:ue.getSlideTabItem().getBoundingClientRect())!=null?oe:{};ae!==void 0&&te!==void 0&&d([te-ae,0])}l(Z)}};return I.jsx(X.DropdownLegacy,{className:"univer-select-none",visible:s,align:{offset:c},trigger:["contextMenu"],overlay:I.jsx(_.UIMenu,{menuType:_.ContextMenuPosition.FOOTER_TABS,onOptionSelect:Z=>{const{label:G,value:J,commandId:re}=Z;g.executeCommand(re!=null?re:G,{value:J,subUnitId:e}),l(!1)}}),onVisibleChange:$,children:I.jsx("div",{className:"univer-max-w-[calc(100%-112px)] univer-overflow-hidden",ref:h,onDragStart:Z=>Z.preventDefault(),onContextMenu:Z=>Z.preventDefault(),children:I.jsx("div",{"data-u-comp":"slide-tab-bar",className:"univer-flex univer-select-none univer-flex-row univer-items-center univer-overflow-hidden univer-px-1.5 univer-py-1",style:{boxShadow:i},children:n.map(Z=>W.createElement(xu,{...Z,key:Z.sheetId,selected:e===Z.sheetId}))})})})}const Xu=100,ua=()=>{var v,p;const[n,r]=W.useState(!0),[e,t]=W.useState(!0),i=_.useDependency(a.ICommandService),o=_.useDependency(Tt),s=_.useDependency(a.IPermissionService),c=lt().getUnitId(),d=_.useObservable(s.getPermissionPoint$((v=new m.WorkbookEditablePermission(c))==null?void 0:v.id)),u=_.useObservable(s.getPermissionPoint$((p=new m.WorkbookCreateSheetPermission(c))==null?void 0:p.id)),h=C=>{const{leftEnd:b,rightEnd:E}=C;r(b),t(E)};W.useEffect(()=>{const C=o.scroll$.subscribe(a.throttle(b=>{h(b)},100));return()=>{C.unsubscribe()}},[]);const g=()=>{i.executeCommand(m.InsertSheetCommand.id),setTimeout(()=>{o.setAddSheet(0)},0)},S=()=>{o.setScrollX(-100)},f=()=>{o.setScrollX(Xu)};return I.jsxs("div",{className:"univer-relative univer-flex univer-h-full univer-min-w-0 univer-flex-1",children:[I.jsxs("div",{className:"univer-flex univer-items-center",children:[I.jsx(ji,{className:"univer-mr-2",onClick:g,disabled:!(u!=null&&u.value&&(d!=null&&d.value)),children:I.jsx(no,{})}),I.jsx(Wu,{})]}),I.jsx(zu,{}),(!n||!e)&&I.jsxs("div",{className:'univer-relative univer-flex univer-items-center univer-px-2 after:univer-absolute after:univer-right-0 after:univer-top-1/2 after:univer-h-4 after:univer-w-px after:-univer-translate-y-1/2 after:univer-bg-gray-200 after:univer-content-[""]',children:[I.jsx(ji,{disabled:n,onClick:S,children:I.jsx(ro,{className:"univer-rotate-180"})}),I.jsx(ji,{disabled:e,onClick:f,children:I.jsx(ro,{})})]})]})},Yu=[50,75,100,125,150,175,200,400];function ju(){const n=_.useDependency(a.ICommandService),r=_.useDependency(a.IUniverInstanceService),e=lt(),t=_.useDependency(me),i=_.useObservable(t.visible$),o=W.useCallback(()=>{if(!e)return 100;const u=e.getActiveSheet(),h=u&&u.getZoomRatio()*100||100;return Math.round(h)},[e]),[s,l]=W.useState(()=>o());W.useEffect(()=>(l(o()),n.onCommandExecuted(h=>{if(h.id===He.id||h.id===m.SetWorksheetActiveOperation.id){const g=o();l(g)}}).dispose),[n,o]);function c(u){l(u);const h=r.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),g=h==null?void 0:h.getActiveSheet();if(g==null)return;const S=u/100;n.executeCommand(en.id,{unitId:h.getUnitId(),subUnitId:g.getSheetId(),zoomRatio:S})}const d=(i==null?void 0:i.visible)&&(i.unitId===(e==null?void 0:e.getUnitId())||i.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);return I.jsx(_.Slider,{disabled:d,min:Hr[0],value:s,shortcuts:Yu,onChange:c})}function Gu(){return I.jsx("section",{className:"univer-flex univer-flex-shrink-0 univer-justify-end",children:I.jsx(ju,{})})}class ao{constructor(){T(this,"_functions",[{func:K.FUNCTION_NAMES_STATISTICAL.MAX,filter:r=>{var e,t,i,o;return((t=(e=r.values.find(s=>s.func===K.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1&&((o=(i=r.values.find(s=>s.func===K.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:i.value)!=null?o:0)>0}},{func:K.FUNCTION_NAMES_STATISTICAL.MIN,filter:r=>{var e,t,i,o;return((t=(e=r.values.find(s=>s.func===K.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1&&((o=(i=r.values.find(s=>s.func===K.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:i.value)!=null?o:0)>0}},{func:K.FUNCTION_NAMES_MATH.SUM,filter:r=>{var e,t,i,o;return((t=(e=r.values.find(s=>s.func===K.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1&&((o=(i=r.values.find(s=>s.func===K.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:i.value)!=null?o:0)>0}},{func:K.FUNCTION_NAMES_STATISTICAL.COUNTA,filter:r=>{var e,t;return((t=(e=r.values.find(i=>i.func===K.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1}},{func:K.FUNCTION_NAMES_STATISTICAL.COUNT,filter:r=>{var e,t,i,o;return((t=(e=r.values.find(s=>s.func===K.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1&&((o=(i=r.values.find(s=>s.func===K.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:i.value)!=null?o:0)>0}},{func:K.FUNCTION_NAMES_STATISTICAL.AVERAGE,filter:r=>{var e,t,i,o;return((t=(e=r.values.find(s=>s.func===K.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1&&((o=(i=r.values.find(s=>s.func===K.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:i.value)!=null?o:0)>0}}]);T(this,"_state$",new D.BehaviorSubject(null));T(this,"state$",this._state$.asObservable())}dispose(){this._state$.complete()}setState(r){var t;const e={values:[],pattern:null};r==null||r.values.forEach(i=>{const o=this._functions.find(s=>s.func===i.func);o&&(o.filter===void 0||o.filter(r))&&e.values.push(i)}),e.pattern=(t=r==null?void 0:r.pattern)!=null?t:null,this._state$.next(e)}getState(){return this._state$.getValue()}getFunctions(){return this._functions}addFunctions(r){this._functions.push(...r)}}const Gn=a.createIdentifier("univer.sheet-status-bar.service"),Zu=[K.FUNCTION_NAMES_MATH.SUM,K.FUNCTION_NAMES_STATISTICAL.AVERAGE,K.FUNCTION_NAMES_STATISTICAL.MIN,K.FUNCTION_NAMES_STATISTICAL.MAX],Gi={[K.FUNCTION_NAMES_MATH.SUM]:"statusbar.sum",[K.FUNCTION_NAMES_STATISTICAL.AVERAGE]:"statusbar.average",[K.FUNCTION_NAMES_STATISTICAL.MIN]:"statusbar.min",[K.FUNCTION_NAMES_STATISTICAL.MAX]:"statusbar.max",[K.FUNCTION_NAMES_STATISTICAL.COUNT]:"statusbar.count",[K.FUNCTION_NAMES_STATISTICAL.COUNTA]:"statusbar.countA",[K.FUNCTION_NAMES_TEXT.CONCATENATE]:"concatenate"},Ku=n=>{const r=_.useDependency(a.LocaleService),e=_.useDependency(_.IMessageService),t=_.useDependency(_.IClipboardInterfaceService),i=qu(n),o=async()=>{await t.writeText(n.value.toString()),e.show({type:X.MessageType.Success,content:r.t("statusbar.copied")})};return I.jsx(X.Tooltip,{title:r.t("statusbar.clickToCopy"),placement:"top",children:I.jsx("div",{className:"univer-flex univer-max-w-24 univer-cursor-default univer-truncate univer-text-center univer-text-xs univer-text-gray-400",onClick:o,children:I.jsx("span",{children:`${r.t((Gi==null?void 0:Gi[n.name])||n.name)}: ${i}`})},n.name)})};function qu(n){const{pattern:r,value:e}=n;return typeof e!="number"?0:e>=1e8?e.toExponential(2):r&&Zu.includes(n.name)?a.numfmt.format(r,e,{throws:!1}):e.toLocaleString()}const ha=800,Qu=3,Ju=()=>{var h,g;const n=(g=(h=_.useConfigValue(Oe))==null?void 0:h.statusBarStatistic)!=null?g:!0,[r,e]=W.useState(window.innerWidth<ha),t=_.useDependency(Gn),i=t.getFunctions().map((S,f)=>({name:S.func,value:0,show:!0,disable:!1,pattern:null})),o=(S,f,v,p)=>{const[C,b]=W.useState(S),[E,w]=W.useState(!0),O=W.useMemo(()=>C.filter(k=>k.show&&!k.disable),[C]),M=W.useMemo(()=>O.find(k=>k.show&&!k.disable),[O]),P=W.useMemo(()=>v&&M?[M]:O,[v,M,O]),A=W.useCallback(k=>{const N=k==null?void 0:k.values;if(!(N!=null&&N.length)){w(!1);return}w(!0),b(H=>H.map(x=>{var L,V,U;return{...x,value:(V=(L=N.find(B=>B.func===x.name))==null?void 0:L.value)!=null?V:x.value,disable:!N.some(B=>B.func===x.name),pattern:(U=k==null?void 0:k.pattern)!=null?U:null}}))},[]);return W.useEffect(()=>{if(!p)return;const k=f.state$.subscribe(A);return()=>k.unsubscribe()},[p,f,A]),{statistics:C,showList:P,show:E}},{showList:s,show:l}=o(i,t,r,n),c=a.debounce(()=>{const S=window.innerWidth<ha;r!==S&&e(S)},100);W.useEffect(()=>(window.addEventListener("resize",c),()=>{window.removeEventListener("resize",c)}),[r]);const u=((S,f,v)=>n?W.useMemo(()=>{if(S.length>f){const C=S.reduce((b,E,w)=>(w%2===0&&b.push(S.slice(w,w+2)),b),[]);return I.jsx(I.Fragment,{children:C.map((b,E)=>I.jsxs("div",{children:[b[0]&&I.jsx(v,{...b[0]},b[0].name),b[1]&&I.jsx(v,{...b[1]},b[1].name)]},`stat-col-${E}`))})}return I.jsx(I.Fragment,{children:S.map(C=>I.jsx(v,{...C},C.name))})},[S,f,v]):null)(s,Qu,Ku);return l&&I.jsx("div",{className:X.clsx('univer-relative univer-box-border univer-flex univer-items-center univer-px-2 after:univer-absolute after:univer-right-0 after:univer-top-1/2 after:univer-block after:univer-h-4 after:univer-w-px after:-univer-translate-y-1/2 after:univer-bg-gray-200 after:univer-content-[""]',{"univer-max-w-32":r,"univer-max-w-80":!r}),children:I.jsx("div",{className:"univer-flex univer-gap-x-2",children:u})})},ma=36;function ga(){var d;const n=_.useConfigValue(Oe),r=_.useDependency(_.IMenuManagerService),e=(d=n==null?void 0:n.footer)!=null?d:!0;if(!lt()||!e)return null;const i=r.getMenuByPositionKey(_.ContextMenuPosition.FOOTER_MENU),{sheetBar:o=!0,statisticBar:s=!0,menus:l=!0,zoomSlider:c=!0}=(n==null?void 0:n.footer)||{};return!o&&!s&&!l&&!c?null:I.jsxs("section",{className:"univer-box-border univer-grid univer-w-full univer-grid-flow-col univer-grid-cols-[1fr,auto,auto,auto] univer-items-center univer-justify-between univer-bg-white univer-px-5 univer-text-gray-900 dark:!univer-bg-gray-900 dark:!univer-text-gray-200",style:{height:ma},"data-range-selector":!0,children:[o&&I.jsx(ua,{}),s&&I.jsx(Ju,{}),l&&i.length>0&&I.jsx("div",{className:"univer-box-border univer-flex univer-gap-2 univer-px-2",children:i.map(u=>{var h;return(h=u.children)==null?void 0:h.map(g=>(g==null?void 0:g.item)&&I.jsx(_.ToolbarItem,{...g.item},g.key))})}),c&&I.jsx(Gu,{})]})}function Sa(){const n=_.useConfigValue(Oe);return va()&&(n==null?void 0:n.formulaBar)!==!1?I.jsx(ca,{}):null}function fa(){return va()?I.jsxs(I.Fragment,{children:[I.jsx(ku,{}),I.jsx(Du,{})]}):null}function va(){const n=_.useDependency(a.IUniverInstanceService),e=!!_.useObservable(()=>n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),null,!1,[]);return W.useMemo(()=>n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).length>0,[n,e])}var $u=Object.getOwnPropertyDescriptor,eh=(n,r,e,t)=>{for(var i=t>1?void 0:t?$u(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},ln=(n,r)=>(e,t)=>r(e,t,n);const pa=5,Ca=2;y.SheetCellEditorResizeService=class extends a.Disposable{constructor(r,e,t,i,o,s){super(),this._layoutService=r,this._cellEditorManagerService=e,this._editorBridgeService=t,this._renderManagerService=i,this._univerInstanceService=o,this._configService=s}get _currentRenderer(){return R.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService)}get _editingUnitId(){var r,e;return(e=(r=this._editorBridgeService.getEditCellState())==null?void 0:r.unitId)!=null?e:""}get _editingRenderer(){return this._renderManagerService.getRenderById(this._editingUnitId)}get _renderer(){var e;const r=(e=this._univerInstanceService.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET))==null?void 0:e.getUnitId();return this._editingUnitId===r?this._editingRenderer:this._currentRenderer}get _sheetSkeletonManagerService(){var r;return(r=this._renderer)==null?void 0:r.with(y.SheetSkeletonManagerService)}get engine(){var r;return(r=this._renderer)==null?void 0:r.engine}fitTextSize(r){var k,N,H,x;const e=this._editorBridgeService.getEditCellState();if(!e)return;const{position:t,documentLayoutObject:i,canvasOffset:o,scaleX:s,scaleY:l}=e,{startX:c,startY:d,endX:u,endY:h}=t,g=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);if(g==null)return;const S=this._getEditorSkeleton();if(!S)return;const f=this._predictingSize(t,o,S,i,s,l);if(!f||f.actualWidth<=0)return;let{actualWidth:v,actualHeight:p}=f;const{verticalAlign:C,horizontalAlign:b,paddingData:E,fill:w}=i;v=v+((k=E.l)!=null?k:0)+((N=E.r)!=null?N:0),p=p+((H=E.t)!=null?H:0)+((x=E.b)!=null?x:0);let O=u-c,M=h-d;O<v&&(O=Math.ceil(v)),M<p&&(M=Math.ceil(p));let P=0;C===a.VerticalAlign.MIDDLE?P=(M-p)/2/l:C===a.VerticalAlign.TOP?P=E.t||0:P=(M-p)/l;let A=0;b===a.HorizontalAlign.CENTER?A=(O-v)/2/s:b===a.HorizontalAlign.RIGHT?A=(O-v)/s:A=E.l||0,P=P<(E.t||0)?E.t||0:P,A=A<(E.l||0)?E.l||0:A,g.updateDocumentDataMargin({t:P,l:A}),S.calculate(),this._editAreaProcessing(O,M,t,o,w,s,l,b,r)}_predictingSize(r,e,t,i,o=1,s=1){const{startX:l,endX:c}=r,{textRotation:d,wrapStrategy:u,paddingData:h}=i,g=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC),{vertexAngle:S}=R.convertTextRotation(d);if(u===a.WrapStrategy.WRAP&&S===0){g==null||g.updateDocumentDataPageSize(c-l),g==null||g.updateDocumentDataMargin({l:h.l,t:h.t}),t.calculate();const{actualWidth:C,actualHeight:b}=t.getActualSize();return{actualWidth:C*o,actualHeight:b*s}}const f=this._getEditorMaxSize(r,e,i.horizontalAlign);if(!f)return;g==null||g.updateDocumentDataPageSize(f.width/o),t.calculate();const v=t.getActualSize();let p=c-l;return p<v.actualWidth*o+pa*o&&(p=v.actualWidth*o+pa*o),g==null||g.updateDocumentDataPageSize(p/o),g==null||g.updateDocumentRenderConfig({horizontalAlign:a.HorizontalAlign.UNSPECIFIED,cellValueType:void 0}),{actualWidth:v.actualWidth*o,actualHeight:v.actualHeight*s}}_getEditorMaxSize(r,e,t){var E,w,O,M;if(this._getEditorObject()==null)return;function o(P){return Number.parseInt(P.replace("px",""))}const s=this.engine;if(!s)return;const l=s.getCanvasElement(),c=l.getBoundingClientRect(),d=o(l.style.width),{width:u}=c,h=u/d,{startX:g,startY:S,endX:f}=r,v=s.width,p=((w=(E=this._configService.getConfig(_.UI_PLUGIN_CONFIG_KEY))==null?void 0:E.footer)==null||w)&&((M=(O=this._configService.getConfig(Oe))==null?void 0:O.footer)==null||M)?ma:0,C=document.body.clientHeight-S-p-e.top-Ca*2;let b=u-g;if(t===a.HorizontalAlign.CENTER){const P=v-f,A=g;b=f-g+Math.min(A,P)*2}else t===a.HorizontalAlign.RIGHT&&(b=f);return{height:C,width:b-Ca,scaleAdjust:h}}_editAreaProcessing(r,e,t,i,o,s=1,l=1,c,d){var V;const u=this._getEditorObject();if(u==null)return;const h=this.engine;if(!h)return;const g=h.getCanvasElement();let{startX:S,startY:f}=t;const{document:v,scene:p,engine:C}=u,b=p.getViewport(q.VIEWPORT_KEY.VIEW_MAIN),E=this._getEditorMaxSize(t,i,c),{height:w,width:O,scaleAdjust:M}=E;let P=e,A=b==null?void 0:b.getScrollBar();P>w?(A==null?b&&new R.ScrollBar(b,{enableHorizontal:!1,barSize:8}):b==null||b.resetCanvasSizeAndUpdateScroll(),b==null||b.scrollToViewportPos({viewportScrollY:P-w}),P=w):(A=null,(V=b==null?void 0:b.getScrollBar())==null||V.dispose()),r+=(A==null?void 0:A.barSize)||0,r>O&&(r=O),this._addBackground(p,r/s,e/l,o);const{scaleX:k,scaleY:N}=p.getPrecisionScale();p.transformByState({width:r*M/s,height:e*M/l,scaleX:s*M,scaleY:l*M}),v.resize(r*M/s,e*M/l),setTimeout(()=>{C.resizeBySize(R.fixLineWidthByScale(r,k),R.fixLineWidthByScale(P,N)),d==null||d()},0);const H=this._layoutService.getContentElement().getBoundingClientRect(),x=g.getBoundingClientRect();S=S*M+(x.left-H.left),f=f*M+(x.top-H.top);const L=t.endX-t.startX;c===a.HorizontalAlign.RIGHT?S+=(L-r)*M:c===a.HorizontalAlign.CENTER&&(S+=(L-r*M)/2),this._cellEditorManagerService.setState({startX:S,startY:f,endX:r*M+S,endY:P*M+f,show:!0})}_addBackground(r,e,t,i){const o="_backgroundRectHelperColor_",s=r.getObject(o);s==null&&i==null||(s==null?r.addObjects([new R.Rect(o,{width:e,height:t,fill:i,evented:!1})],q.DOCS_COMPONENT_MAIN_LAYER_INDEX):i==null?s.dispose():(s.setProps({fill:i}),s.transformByState({width:e,height:t})))}resizeCellEditor(r){var M,P;const e=this._cellEditorManagerService.getState();if(!e||!this._editorBridgeService.isVisible().visible)return;this._editorBridgeService.refreshEditCellPosition(!0);const t=this._editorBridgeService.getEditCellState();if(!t)return;const i=(P=(M=this._sheetSkeletonManagerService)==null?void 0:M.getSkeletonParam(t.sheetId))==null?void 0:P.skeleton;if(!i)return;const{row:o,column:s,scaleX:l,scaleY:c,position:d,canvasOffset:u,documentLayoutObject:h}=t,{horizontalAlign:g}=h,S=this._getEditorMaxSize(d,u,g);if(!S)return;const{height:f,width:v,scaleAdjust:p}=S,C=i.getCellWithCoordByIndex(o,s),b=Math.min((C.mergeInfo.endY-C.mergeInfo.startY)*c,f)*p,E=Math.min((C.mergeInfo.endX-C.mergeInfo.startX)*l,v)*p,w=e.endY-e.startY,O=e.endX-e.startX;if(w!==b||O!==E){if(this._editorBridgeService.refreshEditCellPosition(!0),!this._getEditorSkeleton())return;this.fitTextSize(r)}}_getEditorObject(){return Ai(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}_getEditorSkeleton(){var r;return(r=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:r.with(_e.DocSkeletonManagerService).getSkeleton()}},y.SheetCellEditorResizeService=eh([ln(0,_.ILayoutService),ln(1,Xn),ln(2,me),ln(3,R.IRenderManagerService),ln(4,a.IUniverInstanceService),ln(5,a.IConfigService)],y.SheetCellEditorResizeService);const Zi={id:"sheet.operation.set-activate-cell-edit",type:a.CommandType.OPERATION,handler:(n,r)=>(n.get(me).setEditCell(r),!0)};var th=Object.getOwnPropertyDescriptor,nh=(n,r,e,t)=>{for(var i=t>1?void 0:t?th(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},Rt=(n,r)=>(e,t)=>r(e,t,n);let Ki=class extends a.RxDisposable{constructor(r,e,t,i,o,s,l,c){super();T(this,"_d");this._context=r,this._instanceSrv=e,this._commandService=t,this._editorBridgeService=i,this._selectionManagerService=o,this._contextService=s,this._renderManagerService=l,this._sheetSkeletonManagerService=c,this.disposeWithMe(this._instanceSrv.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(d=>{d&&d.getUnitId()===this._context.unitId?this._d=this._init():this._disposeCurrent()}))}_init(){const r=new a.DisposableCollection;return this._initSelectionChangeListener(r),this._initEventListener(r),this._commandExecutedListener(r),this._initialKeyboardListener(r),r}_disposeCurrent(){var r;(r=this._d)==null||r.dispose(),this._d=null}_initSelectionChangeListener(r){r.add(D.merge(this._selectionManagerService.selectionMoveEnd$,this._selectionManagerService.selectionSet$,this._selectionManagerService.selectionMoveStart$).subscribe(e=>this._updateEditorPosition(e)))}_updateEditorPosition(r){var t,i,o;if(this._editorBridgeService.isVisible().visible)return;const e=(t=r==null?void 0:r[r.length-1])==null?void 0:t.primary;if(e){const s=this._getSheetObject(),{scene:l,engine:c}=s,d=this._context.unitId,u=(i=this._context.unit.getActiveSheet())==null?void 0:i.getSheetId();if(!u)return;const h=(o=this._sheetSkeletonManagerService.getSkeletonParam(u))==null?void 0:o.skeleton.getCellWithCoordByIndex(e.actualRow,e.actualColumn),g=h?{actualRow:h.actualRow,actualColumn:h.actualColumn,isMerged:h.isMerged,startRow:h.mergeInfo.startRow,startColumn:h.mergeInfo.startColumn,endRow:h.mergeInfo.endRow,endColumn:h.mergeInfo.endColumn,isMergedMainCell:h.isMergedMainCell}:e;this._commandService.executeCommand(Zi.id,{scene:l,engine:c,primary:g,unitId:d,sheetId:u})}}refreshEditorPosition(){const r=this._selectionManagerService.getWorkbookSelections(this._context.unitId);if(r){const e=r.getCurrentSelections();e&&this._updateEditorPosition([...e])}}_initEventListener(r){const e=this._getSheetObject(),{spreadsheet:t,spreadsheetColumnHeader:i,spreadsheetLeftTopPlaceholder:o,spreadsheetRowHeader:s}=e;r.add(t.onDblclick$.subscribeEvent(l=>{l.button!==2&&this._commandService.executeCommand(ge.id,{visible:!0,eventType:R.DeviceInputEventType.Dblclick,unitId:this._context.unitId})})),r.add(t.onPointerDown$.subscribeEvent({next:this._tryHideEditor.bind(this),priority:-1})),r.add(i.onPointerDown$.subscribeEvent({next:this._tryHideEditor.bind(this),priority:-1})),r.add(o.onPointerDown$.subscribeEvent({next:this._tryHideEditor.bind(this),priority:-1})),r.add(s.onPointerDown$.subscribeEvent({next:this._tryHideEditor.bind(this),priority:-1}))}_initialKeyboardListener(r){let e=null;const t=o=>{const s=o.with(q.DocSelectionRenderService);s&&(e=a.toDisposable(s.onInputBefore$.subscribe(l=>{if(!this._isCurrentSheetFocused())return;const c=this._contextService.getContextValue(a.FOCUSING_FX_BAR_EDITOR),d=this._contextService.getContextValue(a.FOCUSING_SHEET),u=o.unitId;this._editorBridgeService.isVisible().visible||u&&d&&!c&&this._showEditorByKeyboard(l)})),r.add(e))},i=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);i?t(i):this.disposeWithMe(this._renderManagerService.created$.pipe(D.filter(o=>o.unitId===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)).subscribe(o=>{e==null||e.dispose(),t(o)}))}_commandExecutedListener(r){const e=new Set([m.ClearSelectionFormatCommand.id,en.id]);r.add(this._commandService.onCommandExecuted(t=>{if(e.has(t.id)){if(this._editorBridgeService.isVisible().visible)return;this._editorBridgeService.refreshEditCellState()}if(t.id===m.SetRangeValuesMutation.id){const i=t.params,{cellValue:o,unitId:s,subUnitId:l}=i;if(!o)return;const c=this._editorBridgeService.getEditLocation();if(c){const{unitId:d,sheetId:u,row:h,column:g}=c;s===d&&l===u&&o&&o[h]&&Object.prototype.hasOwnProperty.call(o[h],g)&&this._editorBridgeService.refreshEditCellState()}}})),r.add(this._commandService.beforeCommandExecuted((t,i)=>{i!=null&&i.fromCollab||t.id===m.SetWorksheetActiveOperation.id&&this._tryHideEditor()}))}_showEditorByKeyboard(r){const e=r==null?void 0:r.event;r==null||!e.data&&e.inputType!=="InsertParagraph"||this._commandService.syncExecuteCommand(ge.id,{visible:!0,eventType:R.DeviceInputEventType.Keyboard,keycode:e.which,unitId:this._context.unitId})}_tryHideEditor(){this._editorBridgeService.isForceKeepVisible()||this._hideEditor()}_hideEditor(){this._editorBridgeService.isVisible().visible===!0&&this._commandService.syncExecuteCommand(ge.id,{visible:!1,eventType:R.DeviceInputEventType.PointerDown,unitId:this._context.unitId})}_getSheetObject(){return Ne(this._context.unit,this._context)}_isCurrentSheetFocused(){var r;return((r=this._instanceSrv.getFocusedUnit())==null?void 0:r.getUnitId())===this._context.unitId}};Ki=nh([Rt(1,a.IUniverInstanceService),Rt(2,a.ICommandService),Rt(3,me),Rt(4,a.Inject(m.SheetsSelectionsService)),Rt(5,a.IContextService),Rt(6,R.IRenderManagerService),Rt(7,a.Inject(y.SheetSkeletonManagerService))],Ki);function lo(n){return n.getContextValue(a.FOCUSING_SHEET)}function le(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function _a(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function ih(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function co(n){return n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function qi(n){return n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function rh(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.EDITOR_ACTIVATED)&&n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function cn(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&!n.getContextValue(a.FOCUSING_EDITOR_STANDALONE)}const Ia=[_.KeyCode.ARROW_DOWN,_.KeyCode.ARROW_UP,_.KeyCode.ARROW_LEFT,_.KeyCode.ARROW_RIGHT],oh=[_.KeyCode.ENTER,_.KeyCode.TAB,...Ia];function ba(){const n=[];for(const r of Ia)n.push({id:wt.id,binding:r,preconditions:e=>cn(e),staticParameters:{visible:!1,eventType:R.DeviceInputEventType.Keyboard,keycode:r,isShift:!1}}),n.push({id:wt.id,binding:r|_.MetaKeys.SHIFT,preconditions:e=>cn(e),staticParameters:{visible:!1,eventType:R.DeviceInputEventType.Keyboard,keycode:r,isShift:!0}});return n}const wa={id:xn.id,binding:_.KeyCode.F2,description:"shortcut.sheet.start-editing",group:"4_sheet-edit",preconditions:le,staticParameters:{visible:!0,eventType:R.DeviceInputEventType.Keyboard,keycode:_.KeyCode.F2}},Ea={id:ge.id,binding:_.KeyCode.ENTER,description:"shortcut.sheet.toggle-editing",group:"4_sheet-edit",preconditions:n=>cn(n),staticParameters:{visible:!1,eventType:R.DeviceInputEventType.Keyboard,keycode:_.KeyCode.ENTER}},Ta={id:ge.id,binding:_.KeyCode.TAB,preconditions:n=>cn(n),staticParameters:{visible:!1,eventType:R.DeviceInputEventType.Keyboard,keycode:_.KeyCode.TAB}},ya={id:ge.id,binding:_.KeyCode.ESC,description:"shortcut.sheet.abort-editing",group:"4_sheet-edit",preconditions:n=>cn(n),staticParameters:{visible:!1,eventType:R.DeviceInputEventType.Keyboard,keycode:_.KeyCode.ESC}},sh={id:ge.id,binding:_.KeyCode.ENTER|_.MetaKeys.CTRL_COMMAND,mac:_.KeyCode.ENTER|_.MetaKeys.MAC_CTRL,preconditions:n=>cn(n),staticParameters:{visible:!1,eventType:R.DeviceInputEventType.Keyboard,keycode:_.KeyCode.ENTER|_.MetaKeys.CTRL_COMMAND}},Ra={id:q.BreakLineCommand.id,description:"shortcut.sheet.break-line",group:"4_sheet-edit",preconditions:n=>ih(n),binding:_.KeyCode.ENTER|_.MetaKeys.ALT},Ma={id:q.DeleteLeftCommand.id,preconditions:n=>co(n)||qi(n),binding:_.KeyCode.BACKSPACE},ah={id:q.DeleteRightCommand.id,preconditions:n=>co(n)||qi(n),binding:_.KeyCode.DELETE},lh={id:q.DeleteLeftCommand.id,preconditions:n=>co(n)||qi(n),binding:_.KeyCode.BACKSPACE|_.MetaKeys.SHIFT},Pa={id:ge.id,description:"shortcut.sheet.delete-and-start-editing",group:"4_sheet-edit",preconditions:n=>le(n)&&!qi(n),binding:_.KeyCode.BACKSPACE,staticParameters:{visible:!0,eventType:R.DeviceInputEventType.Keyboard,keycode:_.KeyCode.BACKSPACE}};function ch(n){return n.startsWith("'")}function dh(n){return n.slice(1)}const uh={"0":"0","1":"1","2":"2","3":"3","4":"4","5":"5","6":"6","7":"7","8":"8","9":"9",A:"A",B:"B",C:"C",D:"D",E:"E",F:"F",G:"G",H:"H",I:"I",J:"J",K:"K",L:"L",M:"M",N:"N",O:"O",P:"P",Q:"Q",R:"R",S:"S",T:"T",U:"U",V:"V",W:"W",X:"X",Y:"Y",Z:"Z",a:"a",b:"b",c:"c",d:"d",e:"e",f:"f",g:"g",h:"h",i:"i",j:"j",k:"k",l:"l",m:"m",n:"n",o:"o",p:"p",q:"q",r:"r",s:"s",t:"t",u:"u",v:"v",w:"w",x:"x",y:"y",z:"z","%":"%","-":"-",".":".",":":":","/":"/","+":"+","@":"@","&":"&","*":"*","#":"#","=":"=",">":">","<":"<","$":"$",""":'"',"'":"'","(":"(",")":")"," ":" ",",":",","!":"!","?":"?",";":";","[":"[","]":"]","{":"{","}":"}"},uo={true:"TRUE",false:"FALSE"};function hh(n){return[a.LocaleType.ZH_CN,a.LocaleType.ZH_TW].includes(n)}function mh(n,r,e,t){let i=n;if(hh(e)){if(n.startsWith("'")||n.startsWith("'"))return`'${n.slice(1)}`;i=gh(i)}if(i.startsWith("="))return Sh(n,i,r,t);const o=i.toLowerCase();return uo[o]?uo[o]:a.numfmt.parseValue(i)==null?n:i}function gh(n){const r=/['"].*?['"]/g,e=[],t=n.split(r);n.replace(r,o=>(e.push(o),""));let i=t.join("").split("").map(ph).join("");return e.forEach((o,s)=>{i=i.slice(0,s*2)+o+i.slice((s+1)*2)}),i}function Sh(n,r,e,t){const i=e.sequenceNodesBuilder(r);if(!i)return n;let o=r,s=0;return i.forEach((l,c)=>{if(typeof l=="object"){const d=l.token;if(uo[d.toLowerCase()]){const u=l.startIndex+s+1,h=l.endIndex+s+2;o=dn(d.toLocaleUpperCase(),o,u,h)}else if(l.nodeType===K.sequenceNodeType.FUNCTION&&fh(d,t,i,c)||l.nodeType===K.sequenceNodeType.REFERENCE){const u=d.indexOf("!");if(u>-1){const h=d.substring(u+1),g=l.startIndex+s+(u+1)+1,S=l.endIndex+s+2;o=dn(h.toLocaleUpperCase(),o,g,S)}else{const h=l.startIndex+s+1,g=l.endIndex+s+2;o=dn(d.toLocaleUpperCase(),o,h,g)}}else if(d.startsWith('"')&&d.endsWith('"')||d.startsWith("'")&&d.endsWith("'")){const u=l.startIndex+s+2,h=l.endIndex+s+1;o=dn(n.slice(u,h),o,u,h)}else if(l.nodeType!==K.sequenceNodeType.ARRAY){const u=a.numfmt.parseValue(d);if(u==null){const h=l.startIndex+s+1,g=l.endIndex+s+2;o=dn(n.slice(h,g),o,h,g)}else if(typeof u.v=="number"&&(u.z===void 0||!a.numfmt.getFormatInfo(u.z).isDate)){const h=`${u.v}`,g=l.startIndex+s+1,S=l.endIndex+s+2,{processedString:f,offset:v}=Ch(d,h);o=dn(f,o,g,S),s+=v}}}}),o}function fh(n,r,e,t){const i=r.getDescriptions();return e[t+1]!==K.matchToken.OPEN_BRACKET?!1:i.get(vh(n).toLocaleUpperCase())!==void 0}function vh(n){const r=/^@+/;return n.replace(r,"")}function ph(n){return uh[n]||n}function dn(n,r,e,t){return r.substring(0,e)+n+r.substring(t)}function Ch(n,r){var s,l;const e=((s=n.match(/^\s*/))==null?void 0:s[0])||"",t=((l=n.match(/\s*$/))==null?void 0:l[0])||"",i=e+r+t,o=i.length-n.length;return{processedString:i,offset:o}}const Oa="range_selector",Aa=n=>n.includes(Oa);var _h=Object.getOwnPropertyDescriptor,Ih=(n,r,e,t)=>{for(var i=t>1?void 0:t?_h(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},ye=(n,r)=>(e,t)=>r(e,t,n);const Da=-1e3;y.EditingRenderController=class extends a.Disposable{constructor(e,t,i,o,s,l,c,d,u,h,g,S,f,v,p){super();T(this,"_cursorChange",0);T(this,"_editingUnit","");T(this,"_cursorTimeout");this._undoRedoService=e,this._contextService=t,this._renderManagerService=i,this._editorBridgeService=o,this._cellEditorManagerService=s,this._lexerTreeBuilder=l,this._functionService=c,this._textSelectionManagerService=d,this._commandService=u,this._localService=h,this._editorService=g,this._univerInstanceService=S,this._sheetInterceptorService=f,this._sheetCellEditorResizeService=v,this._selectionManagerService=p,this.disposeWithMe(this._init()),this._initEditorVisibilityListener()}dispose(){super.dispose()}get _workbookSelections(){return this._selectionManagerService.getWorkbookSelections(this._editingUnit)}_init(){const e=new a.DisposableCollection;return this._subscribeToCurrentCell(e),this._initialCursorSync(e),this._listenEditorFocus(e),this._commandExecutedListener(e),this._initSkeletonListener(e),e.add(()=>{clearTimeout(this._cursorTimeout)}),this._cursorTimeout=setTimeout(()=>{this._cursorStateListener(e)},1e3),e}_initEditorVisibilityListener(){this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(async e=>{var t;if(this._editingUnit&&(e==null?void 0:e.getUnitId())!==this._editingUnit&&!this._editorBridgeService.isForceKeepVisible()){this._commandService.syncExecuteCommand(ge.id,{visible:!1,eventType:R.DeviceInputEventType.Keyboard,keycode:_.KeyCode.ESC,unitId:this._editingUnit});const i=(t=this._renderManagerService.getRenderById(e.getUnitId()))==null?void 0:t.with(Ki);i&&i.refreshEditorPosition()}})),this.disposeWithMe(this._editorBridgeService.visible$.pipe(D.distinctUntilChanged((e,t)=>e.visible===t.visible)).subscribe(async e=>{e.visible?(this._editingUnit=e.unitId,this._handleEditorVisible(e)):this._editingUnit&&(await this._handleEditorInvisible(e),this._editingUnit="")}))}_listenEditorFocus(e){const t=this._getEditorObject();t&&e.add(t.document.onPointerDown$.subscribeEvent(()=>{var i;if(this._editingUnit&&this._editorBridgeService.isVisible()){const o=this._editorBridgeService.getEditCellState(),s=this._editorBridgeService.getCurrentEditorId();if(!o||!s)return;(i=this._sheetCellEditorResizeService)==null||i.fitTextSize()}}))}_initialCursorSync(e){e.add(this._cellEditorManagerService.focus$.pipe(D.filter(t=>!!t)).subscribe(()=>{var o;const t=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(!t)return;const i=(o=this._renderManagerService.getRenderById(t==null?void 0:t.getUnitId()))==null?void 0:o.with(q.DocSelectionRenderService);i&&i.sync()}))}_initSkeletonListener(e){const t=new Set(m.COMMAND_LISTENER_SKELETON_CHANGE);t.delete(m.SetWorksheetActiveOperation.id),e.add(this._commandService.onCommandExecuted(i=>{var o;if(t.has(i.id)){switch(i.id){case m.MoveRowsMutation.id:case m.MoveColsMutation.id:case m.RemoveColMutation.id:case m.RemoveRowMutation.id:case m.InsertColMutation.id:case m.InsertRowMutation.id:{const s=this._editorBridgeService.getEditLocation();if(!s)break;const l={startRow:s.row,startColumn:s.column,endRow:s.row,endColumn:s.column},c=m.adjustRangeOnMutation(l,i);if(!c)break;const d=c.startRow,u=c.startColumn;this._editorBridgeService.updateEditLocation(d,u);break}}(o=this._sheetCellEditorResizeService)==null||o.resizeCellEditor(()=>{this._textSelectionManagerService.refreshSelection({unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})})}}))}_subscribeToCurrentCell(e){e.add(this._editorBridgeService.currentEditCellState$.subscribe(t=>{var b,E;if(t==null||this._editorBridgeService.isForceKeepVisible())return;const i=this._editorBridgeService.getEditCellState();if(i==null)return;const{position:o,documentLayoutObject:s,scaleX:l,editorUnitId:c}=i;if(this._contextService.getContextValue(a.FOCUSING_EDITOR_STANDALONE))return;const d=this._getDocumentDataModel();if(d==null)return;const{startX:u,endX:h}=o,{textRotation:g,wrapStrategy:S,documentModel:f}=s,{vertexAngle:v}=R.convertTextRotation(g);S===a.WrapStrategy.WRAP&&v===0&&d.updateDocumentDataPageSize((h-u)/l),this._commandService.syncExecuteCommand(q.ReplaceSnapshotCommand.id,{unitId:c,snapshot:f.getSnapshot()}),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!0),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});const p=(b=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:b.with(q.DocSelectionRenderService),C=(E=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:E.with(q.DocSelectionRenderService);(p!=null&&p.canFocusing||C!=null&&C.canFocusing)&&(this._univerInstanceService.setCurrentUnitForType(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),p==null||p.activate(Da,Da,!0))}))}_commandExecutedListener(e){e.add(this._commandService.onCommandExecuted(i=>{var o;if(i.id===_e.RichTextEditingMutation.id){const s=i.params,{unitId:l}=s;if(Aa(l)||(this._editorBridgeService.changeEditorDirty(!0),!this._editorBridgeService.isVisible().visible))return;l===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&((o=this._sheetCellEditorResizeService)==null||o.fitTextSize())}}));const t=[wt.id];e.add(this._commandService.onCommandExecuted(i=>{if(t.includes(i.id)){const o=i.params,{keycode:s,isShift:l}=o;if(s!=null&&(this._cursorChange===2||this._contextService.getContextValue(a.FOCUSING_FX_BAR_EDITOR))){this._moveInEditor(s,l);return}this._commandService.syncExecuteCommand(ge.id,o)}i.id===xn.id&&(this._cursorChange=2)}))}_handleEditorVisible(e){var f,v,p,C;const{eventType:t,keycode:i}=e;this._cursorChange=t===R.DeviceInputEventType.PointerDown||t===R.DeviceInputEventType.Dblclick?2:1;const o=this._editorBridgeService.getEditLocation();if(o==null)return;this._commandService.syncExecuteCommand($r.id,{range:{startRow:o.row,startColumn:o.column,endRow:o.row,endColumn:o.column}}),this._editorBridgeService.refreshEditCellPosition(!1);const{unitId:s,isInArrayFormulaRange:l=!1}=o,c=this._getEditorObject();if(c==null)return;const{document:d,scene:u}=c;this._contextService.setContextValue(a.EDITOR_ACTIVATED,!0);const h=this._getDocumentDataModel(),g=this._getEditorSkeleton(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(!g||!h)return;(f=this._sheetCellEditorResizeService)==null||f.fitTextSize(()=>{const b=u.getViewport(q.VIEWPORT_KEY.VIEW_MAIN);b==null||b.scrollToViewportPos({viewportScrollX:Number.POSITIVE_INFINITY,viewportScrollY:Number.POSITIVE_INFINITY})});const S=()=>{this._emptyDocumentDataModel(h.getSnapshot().documentStyle,!!l),d.makeDirty(),(i===_.KeyCode.BACKSPACE||t===R.DeviceInputEventType.Dblclick)&&(g.calculate(),this._editorBridgeService.changeEditorDirty(!0)),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})};if(this._isCellImageData(h.getSnapshot()))S();else if(t===R.DeviceInputEventType.Keyboard&&i===_.KeyCode.F2){d.makeDirty(),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}]);const b=((p=(v=h.getBody())==null?void 0:v.dataStream.length)!=null?p:2)-2;this._textSelectionManagerService.replaceDocRanges([{startOffset:b,endOffset:b}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})}else if(t===R.DeviceInputEventType.Keyboard||t===R.DeviceInputEventType.Dblclick&&l)S();else if(t===R.DeviceInputEventType.Dblclick){if(this._contextService.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA))return;const b=h.getBody().dataStream.length-2||0;this._textSelectionManagerService.replaceDocRanges([{startOffset:b,endOffset:b}])}(C=this._renderManagerService.getRenderById(s))==null||C.scene.resetCursor()}_refreshCurrentSelections(e){const t=this._workbookSelections.getSelectionsOfWorksheet(e);t&&(this._contextService.setContextValue(m.REF_SELECTIONS_ENABLED,!1),this._commandService.syncExecuteCommand(m.SetSelectionsOperation.id,{unitId:this._editingUnit,subUnitId:e,selections:t}))}async _handleEditorInvisible(e){var p,C;const t=this._editorBridgeService.getEditCellState(),i=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),o=a.Tools.deepClone(i==null?void 0:i.getSnapshot()),{keycode:s}=e;this._cursorChange=0;const l=(p=t==null?void 0:t.unitId)!=null?p:"";if(this._exitInput(e),t==null)return;const c=this._univerInstanceService.getUnit(l,a.UniverInstanceType.UNIVER_SHEET);if(!c)return;const d=c.getActiveSheet(),u=c.getUnitId(),h=d.getSheetId(),{unitId:g,sheetId:S}=t;if(u===g&&S!==h&&await this._commandService.executeCommand(m.SetWorksheetActivateCommand.id,{subUnitId:S,unitId:g}),s===_.KeyCode.ESC){this._editorBridgeService.isForceKeepVisible()&&this._editorBridgeService.disableForceKeepVisible(),this._refreshCurrentSelections(S);return}const f=((C=o==null?void 0:o.body)==null?void 0:C.dataStream.length)===2,v=t.documentLayoutObject.documentModel?this._isCellImageData(t.documentLayoutObject.documentModel.getSnapshot()):!1;o&&!(f&&v)&&await this._submitEdit(o,s===(_.MetaKeys.CTRL_COMMAND|_.KeyCode.ENTER)||s===(_.MetaKeys.MAC_CTRL|_.KeyCode.ENTER))===!1||this._moveSelection(s,l,h)}_getEditorObject(){return Ai(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}_isCellImageData(e){var i,o;return((o=(i=e.drawingsOrder)==null?void 0:i.length)!=null?o:0)>0}submitCellData(e){return this._submitEdit(e.getSnapshot())}async _submitEdit(e,t=!1){var C;const i=this._editorBridgeService.getEditCellState();if(i==null)return!0;const{unitId:o,sheetId:s,row:l,column:c}=i,d=this._univerInstanceService.getUnit(o,a.UniverInstanceType.UNIVER_SHEET);if(!d)return!0;let u=d.getActiveSheet();if(!d.getSheetBySheetId(s))return!0;u=d.getActiveSheet();const g=bh({...u.getCellRaw(l,c)||{}},e,this._lexerTreeBuilder,this._localService,this._functionService,d.getStyles());if(!g)return!0;const S=this._sheetInterceptorService.onWriteCell(d,u,l,c,g);if(S===u.getCellRaw(l,c))return!0;const f=t?(C=this._workbookSelections.getCurrentLastSelection())==null?void 0:C.range:{startRow:l,startColumn:c,endRow:l,endColumn:c},v=a.generateRandomId(6);return this._commandService.syncExecuteCommand(m.SetRangeValuesCommand.id,{subUnitId:s,unitId:o,range:f,value:S,redoUndoId:v})&&await this._sheetInterceptorService.onValidateCell(d,u,l,c)===!1?(this._undoRedoService.rollback(v,o),!1):!0}_exitInput(e){var o;this._contextService.setContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA,!1),this._contextService.setContextValue(a.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!1),this._contextService.setContextValue(a.FOCUSING_FX_BAR_EDITOR,!1),this._cellEditorManagerService.setState({show:e.visible});const t=this._getEditorObject();(o=t==null?void 0:t.scene.getViewport(q.VIEWPORT_KEY.VIEW_MAIN))==null||o.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});const i=this._editorBridgeService.getCurrentEditorId();i==null||!this._editorService.isSheetEditor(i)||(this._undoRedoService.clearUndoRedo(i),this._undoRedoService.clearUndoRedo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))}_moveSelection(e,t,i){if(e==null||!oh.includes(e)){this._refreshCurrentSelections(i);return}let o=a.Direction.LEFT;switch(e){case _.KeyCode.ENTER:o=a.Direction.DOWN;break;case _.KeyCode.TAB:o=a.Direction.RIGHT;break;case _.KeyCode.ARROW_DOWN:o=a.Direction.DOWN;break;case _.KeyCode.ARROW_UP:o=a.Direction.UP;break;case _.KeyCode.ARROW_LEFT:o=a.Direction.LEFT;break;case _.KeyCode.ARROW_RIGHT:o=a.Direction.RIGHT;break}const s=this._univerInstanceService.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET);t&&(s==null?void 0:s.getUnitId())!==t&&this._univerInstanceService.setCurrentUnitForType(t),e===_.KeyCode.ENTER||e===_.KeyCode.TAB?this._commandService.executeCommand(Ye.id,{keycode:e,direction:o}):this._commandService.executeCommand(Re.id,{direction:o})}_cursorStateListener(e){const t=this._getEditorObject();if(!(t!=null&&t.document))return;const{document:i}=t;e.add(a.toDisposable(i.onPointerDown$.subscribeEvent(()=>{this._cursorChange===1&&(this._cursorChange=2)})))}_moveInEditor(e,t){let i=a.Direction.LEFT;e===_.KeyCode.ARROW_DOWN?i=a.Direction.DOWN:e===_.KeyCode.ARROW_UP?i=a.Direction.UP:e===_.KeyCode.ARROW_RIGHT&&(i=a.Direction.RIGHT),t?this._commandService.executeCommand(q.MoveSelectionOperation.id,{direction:i}):this._commandService.executeCommand(q.MoveCursorOperation.id,{direction:i})}_getDocumentDataModel(){return this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC)}_getEditorSkeleton(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(_e.DocSkeletonManagerService).getSkeleton()}_getEditorViewModel(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(_e.DocSkeletonManagerService).getViewModel()}_getEditingUnit(){return this._editingUnit?this._univerInstanceService.getUnit(this._editingUnit,a.UniverInstanceType.UNIVER_SHEET):null}_emptyDocumentDataModel(e,t){const i=(l,c)=>{const d=a.Tools.deepClone(l.getSnapshot()),u=this._getEditorViewModel(l.getUnitId());u!=null&&(wh(d.body,t),c&&(d.documentStyle=e),d.drawings={},d.drawingsOrder=[],l.reset(d),u.reset(l))},o=this._getDocumentDataModel();o&&i(o,!0);const s=this._univerInstanceService.getUnit(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);s&&i(s)}},y.EditingRenderController=Ih([ye(0,a.IUndoRedoService),ye(1,a.IContextService),ye(2,R.IRenderManagerService),ye(3,me),ye(4,Xn),ye(5,a.Inject(K.LexerTreeBuilder)),ye(6,K.IFunctionService),ye(7,a.Inject(_e.DocSelectionManagerService)),ye(8,a.ICommandService),ye(9,a.Inject(a.LocaleService)),ye(10,q.IEditorService),ye(11,a.IUniverInstanceService),ye(12,a.Inject(m.SheetInterceptorService)),ye(13,a.Inject(y.SheetCellEditorResizeService)),ye(14,a.Inject(m.SheetsSelectionsService))],y.EditingRenderController);function bh(n,r,e,t,i,o){var h,g,S;if((r==null?void 0:r.body)==null)return null;const{body:s}=r;n.t=void 0;const l=s.dataStream;let d=l.substring(l.length-2,l.length)===a.DEFAULT_EMPTY_DOCUMENT_VALUE?l.substring(0,l.length-2):l;const u=t.getCurrentLocale();if(d=mh(d,e,u,i),(h=r.drawingsOrder)!=null&&h.length)n.v="",n.f=null,n.si=null,n.p=r,n.t=a.CellValueType.STRING;else if(n.s&&Oi.isTextFormat((S=(g=o==null?void 0:o.get(n.s))==null?void 0:g.n)==null?void 0:S.pattern)){n.v=d,n.f=null,n.si=null,n.p=null,n.t=a.CellValueType.STRING,ho(s)&&s.dataStream!==`\r
|
|
2
2
|
`&&(n.p=r);const f=ka(r);f&&(n.s=f)}else if(a.isFormulaString(d)){if(n.f===d)return null;const f=e.checkIfAddBracket(d);for(let v=0;v<f;v++)d+=K.matchToken.CLOSE_BRACKET;n.f=d,n.si=null,n.v=null,n.p=null}else if(ch(d)){const f=dh(d);n.v=f,n.f=null,n.si=null,n.p=null,n.t=a.CellValueType.FORCE_STRING}else if(ho(s))s.dataStream===`\r
|
|
3
3
|
`?(n.v="",n.f=null,n.si=null,n.p=null):(n.p=r,n.v=null,n.f=null,n.si=null);else{if(d===""&&n.v==null&&n.p==null)return null;n.v=d,n.f=null,n.si=null,n.p=null;const f=ka(r);f&&(n.s=f)}return n}function ho(n){const{textRuns:r=[],paragraphs:e=[],customRanges:t,customBlocks:i=[]}=n,o=n.dataStream.replace(/(\r\n)+$/,""),s=["va"];return r.filter(l=>l.st<o.length).some(l=>{var d;return!!(l.ts&&Object.keys(l.ts).some(u=>s.includes(u)))||Object.keys((d=l.ts)!=null?d:{}).length&&l.ed-l.st<o.length})||e.some(l=>l.bullet)||e.length>=2||!!(t!=null&&t.length)||i.length>0}function ka(n){const{body:r}=n;if(!r)return null;const{textRuns:e=[]}=r;let t={};const i=r.dataStream.replace(`\r
|
|
4
4
|
`,"");return e.forEach(o=>{const{st:s,ed:l,ts:c}=o;l-s>=i.length&&(t={...t,...c})}),Object.keys(t).length?t:null}function wh(n,r=!1){n.dataStream=a.DEFAULT_EMPTY_DOCUMENT_VALUE,n.textRuns!=null&&(n.textRuns.length===1&&!r?(n.textRuns[0].st=0,n.textRuns[0].ed=1):n.textRuns=void 0),n.paragraphs!=null&&(n.paragraphs=[{startIndex:0}]),n.sectionBreaks!=null&&(n.sectionBreaks=void 0),n.tables!=null&&(n.tables=void 0),n.customRanges!=null&&(n.customRanges=void 0),n.customBlocks!=null&&(n.customBlocks=void 0)}var Eh=Object.getOwnPropertyDescriptor,Th=(n,r,e,t)=>{for(var i=t>1?void 0:t?Eh(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=s(i)||i);return i},mo=(n,r)=>(e,t)=>r(e,t,n);const Na=Lr.MARK_SELECTION,Mt=a.createIdentifier("univer.mark-selection-service");y.MarkSelectionService=class extends a.Disposable{constructor(e,t,i){super();T(this,"_shapeMap",new Map);this._currentService=e,this._renderManagerService=t,this._themeService=i}addShape(e,t=[],i=Na){var d;const o=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=(d=o.getActiveSheet())==null?void 0:d.getSheetId();if(!s)return null;const l=a.Tools.generateRandomId(),c={selection:e,subUnitId:s,unitId:o.getUnitId(),zIndex:i,control:null,exits:t};return this._shapeMap.set(l,c),this.refreshShapes(),l}addShapeWithNoFresh(e,t=[],i=Na){var c;const o=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=(c=o.getActiveSheet())==null?void 0:c.getSheetId();if(!s)return null;const l=a.Tools.generateRandomId();return this._shapeMap.set(l,{selection:e,subUnitId:s,unitId:o.getUnitId(),zIndex:i,control:null,exits:t}),l}refreshShapes(){var o;const e=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!e)return;const t=e.getUnitId(),i=(o=e.getActiveSheet())==null?void 0:o.getSheetId();this._shapeMap.forEach(s=>{const{unitId:l,subUnitId:c,selection:d,control:u,zIndex:h}=s;if(u==null||u.dispose(),l!==t||c!==i)return;const g=this._renderManagerService.getRenderById(l);if(!g)return;const S=g.with(y.SheetSkeletonManagerService).getCurrentSkeleton();if(!S)return;const{scene:f}=g,{rowHeaderWidth:v,columnHeaderHeight:p}=S,C=new kn(f,h,this._themeService,{enableAutoFill:!1,highlightHeader:!1,rowHeaderWidth:v,columnHeaderHeight:p}),b=Te(d,S);C.updateRangeBySelectionWithCoord(b),s.control=C})}getShapeMap(){return this._shapeMap}removeShape(e){const t=this._shapeMap.get(e);if(!t)return;const{control:i}=t;i==null||i.dispose(),this._shapeMap.delete(e)}removeAllShapes(){for(const e of this._shapeMap.values()){const{control:t}=e;t==null||t.dispose()}this._shapeMap.clear()}},y.MarkSelectionService=Th([mo(0,a.IUniverInstanceService),mo(1,R.IRenderManagerService),mo(2,a.Inject(a.ThemeService))],y.MarkSelectionService);function Ha(n){return{strokeWidth:1.5,stroke:n.getColorFromTheme("primary.600"),fill:"rgba(178, 178, 178, 0.10)",widgets:{},strokeDash:8}}const yh=10,Rh=6;function Mh(){return a.Tools.generateRandomId(Rh)}function Ph(n){const r=n.match(/data-copy-id="([^\s]+)"/);return r&&r[1]?r[1]:null}class Oh{constructor(){T(this,"_cache",new a.LRUMap(yh))}set(r,e){this._cache.set(r,e)}get(r){return this._cache.get(r)}del(r){this._cache.delete(r)}clear(){this._cache.clear()}clearWithUnitId(r){this._cache.forEach((e,t)=>{e.unitId===r&&this._cache.delete(t)})}}function Qi(n,r){const e=r!=null?r:n.style,t={},i=n.tagName.toLowerCase();switch(i){case"b":case"em":case"strong":{t.bl=a.BooleanNumber.TRUE;break}case"s":{t.st={s:a.BooleanNumber.TRUE};break}case"u":{t.ul={s:a.BooleanNumber.TRUE};break}case"i":{t.it=a.BooleanNumber.TRUE;break}case"sub":case"sup":{t.va=i==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}return Ah(e,t),t}function Ah(n,r){if(n instanceof CSSStyleDeclaration)for(let e=0;e<n.length;e++){const t=n[e],i=n.getPropertyValue(t);Va(t,i,r)}else for(const e in n){const t=n[e];Va(e,t,r)}}function Va(n,r,e){switch(n){case"font-family":e.ff=r;break;case"font-size":{const t=Number.parseInt(r);Number.isNaN(t)||(r.endsWith("pt")?e.fs=t:r.endsWith("px")&&(e.fs=t*.75));break}case"font-style":r==="italic"&&(e.it=a.BooleanNumber.TRUE);break;case"font-weight":{(Number(r)>400||r==="bold")&&(e.bl=a.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(r)?e.ul={s:a.BooleanNumber.TRUE}:/overline/.test(r)?e.ol={s:a.BooleanNumber.TRUE}:/line-through/.test(r)&&(e.st={s:a.BooleanNumber.TRUE});break}case"color":{try{const t=new a.ColorKit(r);t.isValid&&(e.cl={rgb:t.toRgbString()})}catch{}break}case"background-color":{const t=new a.ColorKit(r),i=t.isValid?t.toRgbString():"";i!==_.DEFAULT_BACKGROUND_COLOR_RGB&&i!==_.DEFAULT_BACKGROUND_COLOR_RGBA&&(e.bg={rgb:i});break}}}function Dh(n){const r=document.createElement("body");return r.innerHTML=n,r}function Wa(n){const r=n.style,e={};for(let t=0;t<r.length;t++){const i=r[t],o=r.getPropertyValue(i);switch(i){case"margin-top":{const s=Number.parseInt(o);e.spaceAbove={v:/pt/.test(o)?R.ptToPixel(s):s};break}case"margin-bottom":{const s=Number.parseInt(o);e.spaceBelow={v:/pt/.test(o)?R.ptToPixel(s):s};break}case"line-height":{const s=Number.parseFloat(o);e.lineSpacing=s;break}}}return Object.getOwnPropertyNames(e).length?e:null}function go(n,r){const e=[];for(let t=0,i=n.length;t<i;t++)n[t]===a.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});return e}function xa(n,r,e){var s,l,c;const t=r.length,o=((s=e==null?void 0:e.length)!=null?s:0)===1&&e[0].st===0&&e[0].ed===t;return n.p?o&&((c=(l=n.p.body)==null?void 0:l.textRuns)!=null&&c.length)?(n.p.body.textRuns=[],{...n,s:e[0].ts}):n:o?{...n,s:e[0].ts}:n}const La=["color","background","font-size","text-align","vertical-align","font-weight","font-style","font-family","text-decoration","white-space","word-wrap","border-left","border-right","border-top","border-bottom","--data-rotate"];function Ua(n,r){const e=n.tagName.toLowerCase();return typeof r=="string"?e===r:Array.isArray(r)?r.some(t=>t===e):r(n)}const kr=class kr{constructor(r){T(this,"_styleMap",new Map);T(this,"_styleCache",new Map);T(this,"_styleRules",[]);T(this,"_afterProcessRules",[]);T(this,"_dom",null);T(this,"_getCurrentSkeleton");this._getCurrentSkeleton=r.getCurrentSkeleton}static use(r){if(this._pluginList.includes(r))throw new Error(`Univer paste plugin ${r.name} already added`);this._pluginList.push(r)}convert(r){const e=kr._pluginList.find(v=>v.checkPasteType(r));e&&(this._styleRules=[...e.stylesRules],this._afterProcessRules=[...e.afterProcessRules]);const t=new a.ObjectMatrix;this._dom=Dh(r);const i=this._dom.querySelector("style");if(i){const v=document.createElement("div"),p=v.attachShadow({mode:"open"});document.body.appendChild(v),p.appendChild(i);for(const C of i.sheet.cssRules){const b=C,E=b.selectorText,w=b.style;this._styleMap.set(E,w)}i.remove(),v.remove()}const o={dataStream:"",textRuns:[]},s=[],l=[],c=r.match(/<table\b[^>]*>([\s\S]*?)<\/table>/gi),d=[];this.process(null,this._dom.childNodes,o,d);const{paragraphs:u,dataStream:h,textRuns:g,payloads:S,customRanges:f}=o;if(u){const v=u.map(p=>p.startIndex+1);v.unshift(0);for(let p=0;p<v.length;p++){let C;if(p===v.length-1){if(C=`${h.substring(v[p])}\r
|