@univerjs/sheets-ui 0.1.0-beta.1 → 0.1.0-beta.3

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.
Files changed (71) hide show
  1. package/{LICENSE.txt → LICENSE} +0 -2
  2. package/lib/cjs/index.js +13 -10
  3. package/lib/es/index.js +7936 -6974
  4. package/lib/index.css +1 -1
  5. package/lib/types/commands/commands/__tests__/create-command-test-bed.d.ts +25 -0
  6. package/lib/types/{components/font-size/FontSize.d.ts → commands/commands/__tests__/hide-row-col-confirm.command.spec.d.ts} +1 -3
  7. package/lib/types/{components/font-family/FontFamily.d.ts → commands/commands/__tests__/remove-row-col-confirm.command.spec.d.ts} +1 -3
  8. package/lib/types/commands/commands/__tests__/selection-utils.spec.d.ts +16 -0
  9. package/lib/types/commands/commands/auto-fill.command.d.ts +1 -11
  10. package/lib/types/commands/commands/delete-range-move-left-confirm.command .d.ts +17 -0
  11. package/lib/types/commands/commands/{set-selection-frozen.command.d.ts → delete-range-move-up-confirm.command.d.ts} +1 -1
  12. package/lib/types/commands/commands/hide-row-col-confirm.command.d.ts +18 -0
  13. package/lib/types/commands/commands/insert-range-move-down-confirm.command.d.ts +17 -0
  14. package/lib/types/commands/commands/insert-range-move-right-confirm.command.d.ts +17 -0
  15. package/lib/types/commands/commands/remove-row-col-confirm.command.d.ts +18 -0
  16. package/lib/types/commands/commands/set-scroll.command.d.ts +1 -1
  17. package/lib/types/commands/commands/utils/selection-utils.d.ts +14 -0
  18. package/lib/types/commands/operations/activate-cell-edit.operation.d.ts +2 -2
  19. package/lib/types/common/keys.d.ts +1 -0
  20. package/lib/types/components/font-family/index.d.ts +2 -2
  21. package/lib/types/components/font-family/interface.d.ts +0 -7
  22. package/lib/types/components/font-size/index.d.ts +1 -1
  23. package/lib/types/components/font-size/interface.d.ts +0 -7
  24. package/lib/types/components/menu-item-input/interface.d.ts +2 -0
  25. package/lib/types/controllers/auto-fill.controller.d.ts +13 -9
  26. package/lib/types/controllers/clipboard/clipboard.controller.d.ts +5 -1
  27. package/lib/types/controllers/clipboard/utils.d.ts +16 -14
  28. package/lib/types/{components/font-family/FontFamilyItem.d.ts → controllers/editor/__tests__/create-test-bed.d.ts} +10 -3
  29. package/lib/types/controllers/editor/__tests__/end-edit.controller.spec.d.ts +16 -0
  30. package/lib/types/controllers/editor/end-edit.controller.d.ts +3 -0
  31. package/lib/types/controllers/editor/formula-editor.controller.d.ts +1 -0
  32. package/lib/types/controllers/editor-bridge.controller.d.ts +2 -5
  33. package/lib/types/controllers/format-painter/format-painter.controller.d.ts +3 -3
  34. package/lib/types/controllers/freeze.controller.d.ts +11 -3
  35. package/lib/types/controllers/header-menu.controller.d.ts +4 -2
  36. package/lib/types/controllers/header-move.controller.d.ts +1 -1
  37. package/lib/types/controllers/menu/menu.d.ts +2 -10
  38. package/lib/types/controllers/menu/sheet.menu.d.ts +3 -3
  39. package/lib/types/controllers/scroll.controller.d.ts +2 -2
  40. package/lib/types/controllers/selection.controller.d.ts +4 -1
  41. package/lib/types/controllers/shortcuts/utils.d.ts +24 -5
  42. package/lib/types/controllers/shortcuts/view.shortcut.d.ts +3 -0
  43. package/lib/types/controllers/status-bar.controller.d.ts +5 -3
  44. package/lib/types/index.d.ts +2 -2
  45. package/lib/types/locale/en-US.d.ts +7 -18
  46. package/lib/types/locale/zh-CN.d.ts +7 -18
  47. package/lib/types/services/auto-fill/auto-fill.service.d.ts +33 -29
  48. package/lib/types/services/auto-fill/rules.d.ts +1 -0
  49. package/lib/types/services/auto-fill/tools.d.ts +11 -3
  50. package/lib/types/services/auto-fill/type.d.ts +23 -9
  51. package/lib/types/services/clipboard/__tests__/clipboard-test-bed.d.ts +1 -0
  52. package/lib/types/services/clipboard/copy-content-cache.d.ts +2 -2
  53. package/lib/types/services/clipboard/type.d.ts +16 -14
  54. package/lib/types/services/editor/formula-editor-manager.service.d.ts +4 -0
  55. package/lib/types/services/editor-bridge.service.d.ts +52 -13
  56. package/lib/types/services/mark-selection/mark-selection.service.d.ts +14 -2
  57. package/lib/types/services/selection/__test__/create-service-test-bed.d.ts +25 -0
  58. package/lib/types/services/selection/__test__/selection-render.test.d.ts +16 -0
  59. package/lib/types/services/selection/selection-render.service.d.ts +19 -3
  60. package/lib/types/services/selection/selection-shape-extension.d.ts +7 -2
  61. package/lib/types/services/selection/selection-shape.d.ts +1 -2
  62. package/lib/types/services/shortcut-experience.service.d.ts +45 -0
  63. package/lib/types/services/status-bar.service.d.ts +7 -4
  64. package/lib/types/views/header-menu-shape.d.ts +2 -2
  65. package/lib/types/views/header-resize-shape.d.ts +2 -2
  66. package/lib/types/views/header-unhide-shape.d.ts +2 -2
  67. package/lib/types/views/sheet-bar/sheet-bar-tabs/utils/slide-tab-bar.d.ts +3 -1
  68. package/lib/types/views/status-bar/CopyableStatisticItem.d.ts +2 -1
  69. package/lib/umd/index.js +13 -10
  70. package/package.json +48 -45
  71. /package/lib/types/views/count-bar/{zoom-slider.d.ts → ZoomSlider.d.ts} +0 -0
package/lib/cjs/index.js CHANGED
@@ -1,9 +1,12 @@
1
- "use strict";var yr=Object.defineProperty;var Or=(i,e,t)=>e in i?yr(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var v=(i,e,t)=>(Or(i,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),f=require("@univerjs/sheets"),R=require("@univerjs/ui"),P=require("@wendellhu/redi"),k=require("rxjs"),w=require("@univerjs/engine-render"),L=require("react"),ie=require("@univerjs/design"),W=require("@wendellhu/redi/react-bindings"),K=require("@univerjs/docs"),po=require("rxjs/operators"),G=require("@univerjs/engine-formula"),Tt=require("clsx"),vo={InsertRow:!0,InsertColumn:!0,AddRowTop:!1,AddRowBottom:!1,AddColumnLeft:!1,AddColumnRight:!1,DeleteRow:!0,DeleteColumn:!0,HideRow:!1,ShowRow:!1,RowHeight:!1,HideColumn:!1,ShowColumn:!1,ColumnWidth:!1,DeleteCell:!0,ClearContent:!0,Matrix:!1},Co={undo:!0,redo:!0,paintFormat:!0,currencyFormat:!0,percentageFormat:!0,numberDecrease:!0,numberIncrease:!0,moreFormats:!0,font:!0,fontSize:!0,bold:!0,italic:!0,strikethrough:!0,underline:!0,textColor:!0,fillColor:!0,border:!0,horizontalAlignMode:!0,verticalAlignMode:!0,textWrapMode:!0,textRotateMode:!0,mergeCell:!0},Io={outerLeft:!1,outerRight:!1,header:!0,footer:!0,innerLeft:!1,innerRight:!1,frozenHeaderLT:!1,frozenHeaderRT:!1,frozenHeaderLM:!1,frozenContent:!1,infoBar:!0,toolbar:!0,formulaBar:!0,rightMenu:!0,countBar:!0,sheetBar:!0},xr={layout:{sheetContainerConfig:Io,rightMenuConfig:vo,toolbarConfig:Co}},Ro="SheetUI";function yn(i,e){if(i==null)return;const t=e.getRenderById(i);if(t==null)return;const{mainComponent:n,scene:o,engine:r}=t;return{document:n,scene:o,engine:r}}const Cn={type:a.CommandType.COMMAND,id:"sheet.command.auto-fill",handler:async(i,e)=>{var V,F;const t=i.get(a.ICommandService),n=i.get(a.IUniverInstanceService),o=i.get(a.IUndoRedoService),{applyRange:r,selectionRange:s,applyDatas:l,unitId:c=n.getCurrentUniverSheetInstance().getUnitId(),subUnitId:d=n.getCurrentUniverSheetInstance().getActiveSheet().getSheetId(),applyMergeRanges:u}=e||{};if(!r||!l||!s)return!1;const h=[],m=[];let S=!0;const g=[],_=(F=(V=n.getUniverSheetInstance(c))==null?void 0:V.getSheetBySheetId(d))==null?void 0:F.getMergeData();_&&_.forEach(j=>{a.Rectangle.intersects(j,r)&&g.push(j)});const I={unitId:c,subUnitId:d,ranges:g},C=f.RemoveMergeUndoMutationFactory(i,I);S=t.syncExecuteCommand(f.RemoveWorksheetMergeMutation.id,I),h.push({id:f.AddWorksheetMergeMutation.id,params:C}),m.push({id:f.RemoveWorksheetMergeMutation.id,params:I});const b=new a.ObjectMatrix,{startRow:M,startColumn:T,endRow:E,endColumn:y}=r;for(let j=0;j<=E-M;j++)for(let $=0;$<=y-T;$++)b.setValue(j+M,$+T,l[j][$]);const O={subUnitId:d,unitId:c,cellValue:b.getMatrix()},x=f.SetRangeValuesUndoMutationFactory(i,O),D=t.syncExecuteCommand(f.SetRangeValuesMutation.id,O);h.push({id:f.SetRangeValuesMutation.id,params:x}),m.push({id:f.SetRangeValuesMutation.id,params:O});const U=t.syncExecuteCommand(f.SetSelectionsOperation.id,{selections:[{primary:{...s,endColumn:s.startColumn,endRow:s.startRow},range:{...s,rangeType:a.RANGE_TYPE.NORMAL}}],unitId:c,subUnitId:d});h.push({id:f.SetRangeValuesMutation.id,params:x}),m.push({id:f.SetRangeValuesMutation.id,params:O});let N=!0;if(u!=null&&u.length){const j=f.getAddMergeMutationRangeByType(u),$={unitId:c,subUnitId:d,ranges:j},q=f.AddMergeUndoMutationFactory(i,$);N=t.syncExecuteCommand(f.AddWorksheetMergeMutation.id,$),h.push({id:f.RemoveWorksheetMergeMutation.id,params:q}),m.push({id:f.AddWorksheetMergeMutation.id,params:$})}const{undo:B,redo:A}=e==null?void 0:e.extendMutations,H=A.every(j=>t.syncExecuteCommand(j.id,j.params));return B.forEach(j=>{h.push(j)}),A.forEach(j=>{m.push(j)}),D&&S&&N&&U&&H&&o.pushUndoRedo({unitID:c,undoMutations:h,redoMutations:m}),!0}},zt={id:"sheet.command.auto-clear-content",type:a.CommandType.COMMAND,handler:async(i,e)=>{const t=i.get(a.IUniverInstanceService),n=i.get(a.ICommandService),o=i.get(a.IUndoRedoService),r=t.getCurrentUniverSheetInstance(),s=r.getUnitId(),c=r.getActiveSheet().getSheetId(),{clearRange:d,selectionRange:u}=e,h={subUnitId:c,unitId:s,cellValue:Ar([d])},m=f.SetRangeValuesUndoMutationFactory(i,h);return n.executeCommand(f.SetSelectionsOperation.id,{selections:[{primary:{...u},range:{...u}}],unitId:s,subUnitId:c}),n.syncExecuteCommand(f.SetRangeValuesMutation.id,h)?(o.pushUndoRedo({unitID:s,undoMutations:[{id:f.SetRangeValuesMutation.id,params:m}],redoMutations:[{id:f.SetRangeValuesMutation.id,params:h}],undo(){return n.syncExecuteCommand(f.SetRangeValuesMutation.id,m)},redo(){return n.syncExecuteCommand(f.SetRangeValuesMutation.id,h)}}),!0):!1}};function Ar(i){const e=new a.ObjectMatrix;return i.forEach(t=>{const{startRow:n,startColumn:o,endRow:r,endColumn:s}=t;for(let l=n;l<=r;l++)for(let c=o;c<=s;c++)e.setValue(l,c,{v:null,p:null,f:null,si:null})}),e.getData()}function Z(i){return i.getContextValue(a.FOCUSING_SHEET)&&!i.getContextValue(a.FOCUSING_EDITOR)}function bo(i){return i.getContextValue(a.FOCUSING_SHEET)&&i.getContextValue(a.FOCUSING_EDITOR)}function Hr(i){return i.getContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN)&&!i.getContextValue(a.FOCUSING_EDITOR)}function Dr(i){return i.getContextValue(a.FOCUSING_EDITOR)&&i.getContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN)}function Mo(i){return i.getContextValue(a.FOCUSING_FORMULA_EDITOR)}function Nr(i){return i.getContextValue(a.FOCUSING_SHEET)&&i.getContextValue(a.FOCUSING_EDITOR)&&i.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)}function In(i){return i.getContextValue(a.FOCUSING_SHEET)&&i.getContextValue(a.FOCUSING_EDITOR)&&!i.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)}class Pr{constructor(){v(this,"_startColumn",-1);v(this,"_startRow",-1);v(this,"_endColumn",-1);v(this,"_endRow",-1);v(this,"_startX",0);v(this,"_startY",0);v(this,"_endX",0);v(this,"_endY",0);v(this,"_currentCell");v(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._currentCell}get rangeType(){return this._rangeType}isEqual(e){const{startColumn:t,startRow:n,endColumn:o,endRow:r}=this,{startColumn:s,startRow:l,endColumn:c,endRow:d}=e;return t===s&&n===l&&o===c&&r===d}isInclude(e){const{startColumn:t,startRow:n,endColumn:o,endRow:r}=this,{startColumn:s,startRow:l,endColumn:c,endRow:d}=e;return!(c<t||s>o||l>r||d<n)}highlightToSelection(){return a.makeCellToSelection(this._currentCell)}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._currentCell}getRangeType(){return this._rangeType}getValue(){return{rangeWithCoord:{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},primaryWithCoord:this._currentCell}}setValue(e,t){const{startColumn:n,startRow:o,endColumn:r,endRow:s,startX:l,startY:c,endX:d,endY:u,rangeType:h}=e;this._startColumn=n,this._startRow=o,this._endColumn=r,this._endRow=s,this._startX=l,this._startY=c,this._endX=d,this._endY=u,h!=null&&(this._rangeType=h),this.setCurrentCell(t)}setCurrentCell(e){e&&(this._currentCell=e)}clearCurrentCell(){this._currentCell=null}}const Hi=.3;class Rn{constructor(e,t,n=!0,o){v(this,"_leftControl");v(this,"_rightControl");v(this,"_topControl");v(this,"_bottomControl");v(this,"_backgroundControlTop");v(this,"_backgroundControlBottom");v(this,"_backgroundControlMiddleLeft");v(this,"_backgroundControlMiddleRight");v(this,"_fillControl");v(this,"_selectionShape");v(this,"_rowHeaderBackground");v(this,"_rowHeaderBorder");v(this,"_rowHeaderGroup");v(this,"_rowHeaderHighlight");v(this,"_columnHeaderBackground");v(this,"_columnHeaderBorder");v(this,"_columnHeaderGroup");v(this,"_columnHeaderHighlight");v(this,"_topLeftWidget");v(this,"_topCenterWidget");v(this,"_topRightWidget");v(this,"_middleLeftWidget");v(this,"_middleRightWidget");v(this,"_bottomLeftWidget");v(this,"_bottomCenterWidget");v(this,"_bottomRightWidget");v(this,"_dashRect");v(this,"_selectionModel");v(this,"_selectionStyle");v(this,"_rowHeaderWidth",0);v(this,"_columnHeaderHeight",0);v(this,"_widgetRects",[]);v(this,"_dispose$",new k.BehaviorSubject(this));v(this,"dispose$",this._dispose$.asObservable());v(this,"selectionMoving$",new k.Subject);v(this,"selectionMoved$",new k.Subject);v(this,"selectionScaling$",new k.Subject);v(this,"selectionScaled$",new k.Subject);v(this,"selectionFilling$",new k.Subject);v(this,"_selectionFilled$",new k.Subject);v(this,"selectionFilled$",this._selectionFilled$.asObservable());v(this,"_defaultStyle");v(this,"_isHelperSelection",!0);this._scene=e,this._zIndex=t,this._isHeaderHighlight=n,this._themeService=o,this._initialize()}get zIndex(){return this._zIndex}get leftControl(){return this._leftControl}get rightControl(){return this._rightControl}get topControl(){return this._topControl}get bottomControl(){return this._bottomControl}get fillControl(){return this._fillControl}get backgroundControlTop(){return this._backgroundControlTop}get backgroundControlBottom(){return this._backgroundControlBottom}get backgroundControlMiddleLeft(){return this._backgroundControlMiddleLeft}get backgroundControlMiddleRight(){return this._backgroundControlMiddleRight}get selectionShape(){return this._selectionShape}get model(){return this._selectionModel}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 selectionStyle(){return this._selectionStyle}get dashRect(){return this._dashRect}get isHelperSelection(){return this._isHelperSelection}enableHeaderHighlight(){this._isHelperSelection=!0}disableHeaderHighlight(){this._isHeaderHighlight=!1}refreshSelectionFilled(e){this._selectionFilled$.next(e)}updateStyle(e){this._updateControl(e,this._rowHeaderWidth,this._columnHeaderHeight)}update(e,t=0,n=0,o,r){this._selectionModel.setValue(e,r),o==null&&(o=this._selectionStyle),this._updateControl(o,t,n)}clearHighlight(){this._selectionModel.clearCurrentCell(),this._updateControl(this._selectionStyle,this._rowHeaderWidth,this._columnHeaderHeight)}getScene(){return this._scene}dispose(){var e,t,n,o,r,s,l,c,d,u,h,m,S,g,_,I,C,b,M,T,E,y,O,x,D;(e=this._leftControl)==null||e.dispose(),(t=this._rightControl)==null||t.dispose(),(n=this._topControl)==null||n.dispose(),(o=this._bottomControl)==null||o.dispose(),(r=this._backgroundControlTop)==null||r.dispose(),(s=this._backgroundControlMiddleLeft)==null||s.dispose(),(l=this._backgroundControlMiddleRight)==null||l.dispose(),(c=this._backgroundControlBottom)==null||c.dispose(),(d=this._fillControl)==null||d.dispose(),(u=this._selectionShape)==null||u.dispose(),(h=this._rowHeaderBackground)==null||h.dispose(),(m=this._rowHeaderBorder)==null||m.dispose(),(S=this._rowHeaderGroup)==null||S.dispose(),(g=this._rowHeaderBackground)==null||g.dispose(),(_=this._columnHeaderBackground)==null||_.dispose(),(I=this._columnHeaderBorder)==null||I.dispose(),(C=this._columnHeaderGroup)==null||C.dispose(),(b=this._topLeftWidget)==null||b.dispose(),(M=this._topCenterWidget)==null||M.dispose(),(T=this._topRightWidget)==null||T.dispose(),(E=this._middleLeftWidget)==null||E.dispose(),(y=this._middleRightWidget)==null||y.dispose(),(O=this._bottomLeftWidget)==null||O.dispose(),(x=this._bottomCenterWidget)==null||x.dispose(),(D=this._bottomRightWidget)==null||D.dispose(),this._dispose$.next(this),this._dispose$.complete()}getCurrentCellInfo(){const e=this.model.currentCell;if(e){let t;if(e.isMerged){const n=e.mergeInfo;t={startRow:n.startRow,endRow:n.endRow,startColumn:n.startColumn,endColumn:n.endColumn,startX:n.startX,endX:n.endX,startY:n.startY,endY:n.endY}}else{const{actualRow:n,actualColumn:o,startX:r,endX:s,startY:l,endY:c}=e;t={startRow:n,endRow:n,startColumn:o,endColumn:o,startX:r,endX:s,startY:l,endY:c}}return t}}getValue(){return{...this._selectionModel.getValue(),style:this._selectionStyle}}getRange(){return this._selectionModel.getValue().rangeWithCoord}enableHelperSelection(){this._isHelperSelection=!0}disableHelperSelection(){this._isHelperSelection=!1}updateStyleId(e){this._selectionStyle!=null&&(this._selectionStyle.id=e)}_updateControl(e,t,n){let{startX:o,startY:r,endX:s,endY:l}=this._selectionModel;const c=this._defaultStyle;e==null&&(e=c);const{stroke:d=c.stroke,widgets:u=c.widgets,hasAutoFill:h=c.hasAutoFill,AutofillStroke:m=c.AutofillStroke,strokeDash:S}=e;let{strokeWidth:g=c.strokeWidth,AutofillSize:_=c.AutofillSize,AutofillStrokeWidth:I=c.AutofillStrokeWidth}=e;const C=this._getScale();o=w.fixLineWidthByScale(o,C),r=w.fixLineWidthByScale(r,C),s=w.fixLineWidthByScale(s,C),l=w.fixLineWidthByScale(l,C);const b=(g+f.SELECTION_CONTROL_BORDER_BUFFER_WIDTH)/2/C;g/=this._getPureScale(),_/=C,I/=C;const M=f.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/C,T=w.FIX_ONE_PIXEL_BLUR_OFFSET/C;this.leftControl.transformByState({height:l-r,left:-b+T,width:g,strokeWidth:M,top:-M/2+T}),this.leftControl.setProps({fill:d,stroke:f.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.rightControl.transformByState({height:l-r,left:s-o-b+T,width:g,strokeWidth:M,top:-M/2+T}),this.rightControl.setProps({fill:d,stroke:f.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.topControl.transformByState({width:s-o+g,top:-b+T,left:-b+T,height:g,strokeWidth:M}),this.topControl.setProps({fill:d,stroke:f.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.bottomControl.transformByState({width:s-o+g,top:l-r-b+T,height:g,left:-b+T,strokeWidth:M}),this.bottomControl.setProps({fill:d,stroke:f.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),S==null?this.dashRect.hide():(this.dashRect.transformByState({height:l-r-g/2,width:s-o-g/2,strokeWidth:g,left:g/2-1/C,top:g/2-1/C}),this.dashRect.setProps({strokeDashArray:[0,S]}),this.dashRect.show()),h===!0&&!this._hasWidgets(u)?(this.fillControl.setProps({fill:d,stroke:m}),this.fillControl.transformByState({width:_-I,height:_-I,left:s-o-_/2,top:l-r-_/2,strokeWidth:I}),this.fillControl.show()):this.fillControl.hide(),this._updateBackgroundControl(e),this._updateBackgroundTitle(e,w.fixLineWidthByScale(t,C),n),this._updateWidgets(e),this.selectionShape.show(),this.selectionShape.translate(o,r),this._selectionStyle=e,this._rowHeaderWidth=t||0,this._columnHeaderHeight=n||0,this.selectionShape.makeDirtyNoDebounce(!0)}_initialize(){this._defaultStyle=f.getNormalSelectionStyle(this._themeService),this._selectionModel=new Pr;const e=this._zIndex;this._leftControl=new w.Rect("__SpreadsheetSelectionShapeLeftControl__"+e,{zIndex:e}),this._rightControl=new w.Rect("__SpreadsheetSelectionShapeRightControl__"+e,{zIndex:e}),this._topControl=new w.Rect("__SpreadsheetSelectionTopControl__"+e,{zIndex:e}),this._bottomControl=new w.Rect("__SpreadsheetSelectionBottomControl__"+e,{zIndex:e}),this._backgroundControlTop=new w.Rect("__SpreadsheetSelectionBackgroundControlTop__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlBottom=new w.Rect("__SpreadsheetSelectionBackgroundControlBottom__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleLeft=new w.Rect("__SpreadsheetSelectionBackgroundControlMiddleLeft__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleRight=new w.Rect("__SpreadsheetSelectionBackgroundControlMiddleRight__"+e,{zIndex:e-1,evented:!1}),this._fillControl=new w.Rect("__SpreadsheetSelectionFillControl__"+e,{zIndex:e+1}),this._dashRect=new w.Rect("__SpreadsheetDragDashControl__"+e,{zIndex:e+2,evented:!1,stroke:"#fff"});const t=[this._fillControl,this._leftControl,this._rightControl,this._topControl,this._bottomControl,this._backgroundControlTop,this._backgroundControlMiddleLeft,this._backgroundControlMiddleRight,this._backgroundControlBottom,this._dashRect];this._widgetRects=this._initialWidget(),this._selectionShape=new w.Group("__SpreadsheetSelectionShape__"+e,...t,...this._widgetRects),this._selectionShape.hide(),this._selectionShape.evented=!1,this._selectionShape.zIndex=e,this.getScene().addObject(this._selectionShape),this._initialTitle()}_initialTitle(){const e=this._zIndex;this._rowHeaderBackground=new w.Rect("__SpreadSheetSelectionRowHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderBorder=new w.Rect("__SpreadSheetSelectionRowHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderGroup=new w.Group("__SpreadSheetSelectionRowHeaderGroup__"+e,this._rowHeaderBackground,this._rowHeaderBorder),this._rowHeaderGroup.hide(),this._rowHeaderGroup.evented=!1,this._rowHeaderGroup.zIndex=e,this._columnHeaderBackground=new w.Rect("__SpreadSheetSelectionColumnHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderBorder=new w.Rect("__SpreadSheetSelectionColumnHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderGroup=new w.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],w.DEFAULT_SELECTION_LAYER_INDEX)}_initialWidget(){const e=this._zIndex;return this._topLeftWidget=new w.Rect("__SpreadSheetSelectionTopLeftWidget__"+e,{zIndex:e+1}),this._topCenterWidget=new w.Rect("__SpreadSheetSelectionTopCenterWidget__"+e,{zIndex:e+1}),this._topRightWidget=new w.Rect("__SpreadSheetSelectionTopRightWidget__"+e,{zIndex:e+1}),this._middleLeftWidget=new w.Rect("__SpreadSheetSelectionMiddleLeftWidget__"+e,{zIndex:e+1}),this._middleRightWidget=new w.Rect("__SpreadSheetSelectionMiddleRightWidget__"+e,{zIndex:e+1}),this._bottomLeftWidget=new w.Rect("__SpreadSheetSelectionBottomLeftWidget__"+e,{zIndex:e+1}),this._bottomCenterWidget=new w.Rect("__SpreadSheetSelectionBottomCenterWidget__"+e,{zIndex:e+1}),this._bottomRightWidget=new w.Rect("__SpreadSheetSelectionBottomRightWidget__"+e,{zIndex:e+1}),[this._topLeftWidget,this._topCenterWidget,this._topRightWidget,this._middleLeftWidget,this._middleRightWidget,this._bottomLeftWidget,this._bottomCenterWidget,this._bottomRightWidget]}_updateBackgroundTitle(e,t,n){const{startX:o,startY:r,endX:s,endY:l,rangeType:c}=this._selectionModel,d=this._defaultStyle;e==null&&(e=d);const u=this._getScale(),{stroke:h,hasRowHeader:m,rowHeaderFill:S=d.rowHeaderFill,rowHeaderStroke:g=d.rowHeaderStroke,hasColumnHeader:_,columnHeaderFill:I=d.columnHeaderFill,columnHeaderStroke:C=d.columnHeaderStroke}=e;let{rowHeaderStrokeWidth:b=d.rowHeaderStrokeWidth,columnHeaderStrokeWidth:M=d.columnHeaderStrokeWidth}=e;if(b/=u,M/=u,_===!0){let T=I;this._isHeaderHighlight&&c===a.RANGE_TYPE.COLUMN&&(T=new a.ColorKit(h).setAlpha(Hi).toString()),this._columnHeaderBackground.setProps({fill:T}),this._columnHeaderBackground.resize(s-o,n),this._columnHeaderBorder.setProps({fill:C}),this._columnHeaderBorder.transformByState({width:s-o,height:M,top:n-M+1/u}),this._columnHeaderGroup.show(),this._columnHeaderGroup.translate(o,0)}else this._columnHeaderGroup.hide();if(this._columnHeaderGroup.makeDirty(!0),m===!0){let T=S;this._isHeaderHighlight&&c===a.RANGE_TYPE.ROW&&(T=new a.ColorKit(h).setAlpha(Hi).toString()),this._rowHeaderBackground.setProps({fill:T}),this._rowHeaderBackground.resize(t,l-r),this._rowHeaderBorder.setProps({fill:g}),this._rowHeaderBorder.transformByState({width:b,height:l-r,left:t-b+1/u}),this._rowHeaderGroup.show(),this._rowHeaderGroup.translate(0,r)}else this._rowHeaderGroup.hide();this._rowHeaderGroup.makeDirty(!0)}_updateBackgroundControl(e){let{startX:t,startY:n,endX:o,endY:r}=this._selectionModel;const s=this._defaultStyle;e==null&&(e=s);const l=this._getScale(),{fill:c=s.fill}=e;let{strokeWidth:d=s.strokeWidth}=e;d/=l;const u=this._selectionModel.highlightToSelection();if(t=w.fixLineWidthByScale(t,l),n=w.fixLineWidthByScale(n,l),o=w.fixLineWidthByScale(o,l),r=w.fixLineWidthByScale(r,l),!u){this._backgroundControlTop.resize(o-t,r-n),this._backgroundControlTop.setProps({fill:c}),this._backgroundControlBottom.resize(0,0),this._backgroundControlMiddleLeft.resize(0,0),this._backgroundControlMiddleRight.resize(0,0);return}let{startX:h,startY:m,endX:S,endY:g}=u;h=w.fixLineWidthByScale(h,l),m=w.fixLineWidthByScale(m,l),S=w.fixLineWidthByScale(S,l),g=w.fixLineWidthByScale(g,l);const _=w.fixLineWidthByScale(d/2,l),I={left:-_,top:-_,width:o-t+_*2,height:m-n+_};I.height<0&&(I.width=0,I.height=0),this._backgroundControlTop.transformByState(I);const C={left:-_,top:m-n,width:h-t+_,height:g-m};C.width<0&&(C.width=0,C.height=0),this._backgroundControlMiddleLeft.transformByState(C);const b={left:S-t-_,top:m-n,width:o-S+_*2,height:g-m};b.width<0&&(b.width=0,b.height=0),this._backgroundControlMiddleRight.transformByState(b);const M={left:-_,top:g-n,width:o-t+_*2,height:r-g+_};M.height<0&&(M.width=0,M.height=0),this._backgroundControlBottom.transformByState(M),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:n,endX:o,endY:r}=this._selectionModel,s=this._defaultStyle;e==null&&(e=s);const{stroke:l=s.stroke,widgets:c=s.widgets,widgetStroke:d=s.widgetStroke}=e,u=this._getScale();let{widgetSize:h=s.widgetSize,widgetStrokeWidth:m=s.widgetStrokeWidth}=e;h/=u,m/=u;const S={left:-h/2,center:(o-t)/2-h/2,right:o-t-h/2,top:-h/2,middle:(r-n)/2-h/2,bottom:r-n-h/2},g=h-m;this._widgetRects.forEach(_=>{_.setProps({fill:l,stroke:d})}),c.tl===!0?(this._topLeftWidget.transformByState({height:g,width:g,left:S.left,top:S.top,strokeWidth:m}),this._topLeftWidget.show()):this._topLeftWidget.hide(),c.tc===!0?(this._topCenterWidget.transformByState({height:g,width:g,left:S.center,top:S.top,strokeWidth:m}),this._topCenterWidget.show()):this._topCenterWidget.hide(),c.tr===!0?(this._topRightWidget.transformByState({height:g,width:g,left:S.right,top:S.top,strokeWidth:m}),this._topRightWidget.show()):this._topRightWidget.hide(),c.ml===!0?(this._middleLeftWidget.transformByState({height:g,width:g,left:S.left,top:S.middle,strokeWidth:m}),this._middleLeftWidget.show()):this._middleLeftWidget.hide(),c.mr===!0?(this._middleRightWidget.transformByState({height:g,width:g,left:S.right,top:S.middle,strokeWidth:m}),this._middleRightWidget.show()):this._middleRightWidget.hide(),c.bl===!0?(this._bottomLeftWidget.transformByState({height:g,width:g,left:S.left,top:S.bottom,strokeWidth:m}),this._bottomLeftWidget.show()):this._bottomLeftWidget.hide(),c.bc===!0?(this._bottomCenterWidget.transformByState({height:g,width:g,left:S.center,top:S.bottom,strokeWidth:m}),this._bottomCenterWidget.show()):this._bottomCenterWidget.hide(),c.br===!0?(this._bottomRightWidget.transformByState({height:g,width:g,left:S.right,top:S.bottom,strokeWidth:m}),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 n of t)if(e[n]===!0)return!0;return!0}_getScale(){const e=this._getPixelRatio(),{scaleX:t,scaleY:n}=this._scene.getAncestorScale();return Math.max(t*e,n*e)}_getPureScale(){const{scaleX:e,scaleY:t}=this._scene.getAncestorScale();return Math.max(e,t)}_getPixelRatio(){var e;return((e=this._scene.getEngine())==null?void 0:e.getPixelRatio())||1}}const Di="__SpreadsheetHelperSelectionTempRect",Lr=35;class Ni{constructor(e,t,n,o){v(this,"_startOffsetX",0);v(this,"_startOffsetY",0);v(this,"_relativeSelectionPositionRow",0);v(this,"_relativeSelectionPositionColumn",0);v(this,"_relativeSelectionRowLength",0);v(this,"_relativeSelectionColumnLength",0);v(this,"_moveObserver");v(this,"_upObserver");v(this,"_helperSelection");v(this,"_scrollTimer");v(this,"_targetSelection",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});v(this,"_isInMergeState",!1);v(this,"_fillControlColors",[]);this._control=e,this._skeleton=t,this._scene=n,this._themeService=o,this._initialControl(),this._initialWidget(),this._initialFill(),this._control.dispose$.subscribe(()=>{this.dispose()})}get isHelperSelection(){return this._control.isHelperSelection}dispose(){var e,t;(e=this._scrollTimer)==null||e.dispose(),this._fillControlColors=[],this._clearObserverEvent(),(t=this._helperSelection)==null||t.dispose()}_clearObserverEvent(){this._scene.onPointerMoveObserver.remove(this._moveObserver),this._scene.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_initialControl(){const{leftControl:e,rightControl:t,topControl:n,bottomControl:o}=this._control;[e,t,n,o].forEach(r=>{r.onPointerEnterObserver.add(()=>{r.setCursor(w.CURSOR_TYPE.MOVE)}),r.onPointerLeaveObserver.add(()=>{r.resetCursor()}),r.onPointerDownObserver.add(this._controlEvent.bind(this))})}_controlMoving(e,t){var y;const n=this._scene,o=n.getScrollXYByRelativeCoords(w.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:r,scaleY:s}=n.getAncestorScale(),l=this._skeleton.getCellPositionByOffset(e,t,r,s,o),{row:c,column:d}=l,u=this._skeleton.getRowCount()-1,h=this._skeleton.getColumnCount()-1;let m=c+this._relativeSelectionPositionRow;m<0&&(m=0);let S=m+this._relativeSelectionRowLength;S>u&&(S=u,S-m<this._relativeSelectionRowLength&&(m=S-this._relativeSelectionRowLength));let g=d+this._relativeSelectionPositionColumn;g<0&&(g=0);let _=g+this._relativeSelectionColumnLength;_>h&&(_=h,_-g<this._relativeSelectionColumnLength&&(g=_-this._relativeSelectionColumnLength));const I=this._skeleton.getNoMergeCellPositionByIndex(m,g,r,s),C=this._skeleton.getNoMergeCellPositionByIndex(S,_,r,s),b=(I==null?void 0:I.startY)||0,M=(C==null?void 0:C.endY)||0,T=(I==null?void 0:I.startX)||0,E=(C==null?void 0:C.endX)||0;(y=this._helperSelection)==null||y.transformByState({left:T,top:b,width:E-T,height:M-b}),this._targetSelection={startY:b,endY:M,startX:T,endX:E,startRow:m,endRow:S,startColumn:g,endColumn:_},this._control.selectionMoving$.next(this._targetSelection)}_controlEvent(e){const{offsetX:t,offsetY:n}=e,o=this._scene,r=o.getRelativeCoord(w.Vector2.FromArray([t,n])),{x:s,y:l}=r,c=o.getScrollXYByRelativeCoords(r),{scaleX:d,scaleY:u}=o.getAncestorScale(),h=this._skeleton.getCellPositionByOffset(s,l,d,u,c);this._startOffsetX=s,this._startOffsetY=l;const{row:m,column:S}=h,{startRow:g,startColumn:_,endRow:I,endColumn:C}=this._control.model;let b=0,M=0;m<g?b-=1:m>I&&(b+=1),S<_?M-=1:S>C&&(M+=1),this._relativeSelectionPositionRow=g-m+b,this._relativeSelectionPositionColumn=_-S+M,this._relativeSelectionRowLength=I-g,this._relativeSelectionColumnLength=C-_;const T=this._control.selectionStyle,E=this._getScale();this.isHelperSelection&&(this._helperSelection=new w.Rect(Di,{stroke:T.stroke,strokeWidth:T.strokeWidth/E}),o.addObject(this._helperSelection));const y=w.ScrollTimer.create(o);y.startScroll(s,l),this._scrollTimer=y,o.disableEvent(),this._moveObserver=o.onPointerMoveObserver.add(O=>{const{offsetX:x,offsetY:D}=O,{x:U,y:N}=o.getRelativeCoord(w.Vector2.FromArray([x,D]));this._controlMoving(U,N),o.setCursor(w.CURSOR_TYPE.MOVE),y.scrolling(U,N,()=>{this._controlMoving(U,N)})}),this._upObserver=o.onPointerUpObserver.add(()=>{var x,D;(x=this._helperSelection)==null||x.dispose();const O=this._scene;O.resetCursor(),this._clearObserverEvent(),O.enableEvent(),(D=this._scrollTimer)==null||D.dispose(),this._control.selectionMoved$.next(this._targetSelection)})}_initialWidget(){const{topLeftWidget:e,topCenterWidget:t,topRightWidget:n,middleLeftWidget:o,middleRightWidget:r,bottomLeftWidget:s,bottomCenterWidget:l,bottomRightWidget:c}=this._control,d=[w.CURSOR_TYPE.NORTH_WEST_RESIZE,w.CURSOR_TYPE.NORTH_RESIZE,w.CURSOR_TYPE.NORTH_EAST_RESIZE,w.CURSOR_TYPE.WEST_RESIZE,w.CURSOR_TYPE.EAST_RESIZE,w.CURSOR_TYPE.SOUTH_WEST_RESIZE,w.CURSOR_TYPE.SOUTH_RESIZE,w.CURSOR_TYPE.SOUTH_EAST_RESIZE];[e,t,n,o,r,s,l,c].forEach((u,h)=>{u.onPointerEnterObserver.add(()=>{u.setCursor(d[h])}),u.onPointerLeaveObserver.add(()=>{u.resetCursor()}),u.onPointerDownObserver.add(m=>{this._widgetEvent(m,d[h])})})}_widgetMoving(e,t,n){const o=this._scene,r=o.getScrollXYByRelativeCoords(w.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:s,scaleY:l}=o.getAncestorScale(),c=this._skeleton.getCellPositionByOffset(e,t,s,l,r),{row:d,column:u}=c,{rowHeaderWidth:h,columnHeaderHeight:m}=this._skeleton;let S=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,_=d,I=u;n===w.CURSOR_TYPE.NORTH_WEST_RESIZE?(S=d,g=u,_=this._relativeSelectionPositionRow,I=this._relativeSelectionPositionColumn):n===w.CURSOR_TYPE.NORTH_RESIZE?(S=d,g=this._relativeSelectionPositionColumn,_=this._relativeSelectionPositionRow,I=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength):n===w.CURSOR_TYPE.NORTH_EAST_RESIZE?(S=d,g=this._relativeSelectionPositionColumn,_=this._relativeSelectionPositionRow,I=u):n===w.CURSOR_TYPE.WEST_RESIZE?(S=this._relativeSelectionPositionRow,g=u,_=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,I=this._relativeSelectionPositionColumn):n===w.CURSOR_TYPE.EAST_RESIZE?_=this._relativeSelectionPositionRow+this._relativeSelectionRowLength:n===w.CURSOR_TYPE.SOUTH_WEST_RESIZE?(S=this._relativeSelectionPositionRow,g=u,_=d,I=this._relativeSelectionPositionColumn):n===w.CURSOR_TYPE.SOUTH_RESIZE&&(S=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,_=d,I=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength);const{startRow:C,startColumn:b,endRow:M,endColumn:T}=this._swapPositions(S,g,_,I),E=this._skeleton.getNoMergeCellPositionByIndex(C,b,s,l),y=this._skeleton.getNoMergeCellPositionByIndex(M,T,s,l),O=(E==null?void 0:E.startY)||0,x=(y==null?void 0:y.endY)||0,D=(E==null?void 0:E.startX)||0,U=(y==null?void 0:y.endX)||0;this._targetSelection={startY:O,endY:x,startX:D,endX:U,startRow:S,endRow:_,startColumn:g,endColumn:I},this._control.update(this._targetSelection,h,m,this._control.selectionStyle),this._control.clearHighlight(),this._control.selectionScaling$.next(this._targetSelection)}_widgetEvent(e,t){const{offsetX:n,offsetY:o}=e,r=this._scene,s=r.getRelativeCoord(w.Vector2.FromArray([n,o])),{x:l,y:c}=s;this._startOffsetX=n,this._startOffsetY=o;const{startRow:d,startColumn:u,endRow:h,endColumn:m}=this._control.model;this._relativeSelectionPositionRow=d,this._relativeSelectionPositionColumn=u,this._relativeSelectionRowLength=h-d,this._relativeSelectionColumnLength=m-u,t===w.CURSOR_TYPE.NORTH_WEST_RESIZE?(this._relativeSelectionPositionRow=h,this._relativeSelectionPositionColumn=m):t===w.CURSOR_TYPE.NORTH_RESIZE?this._relativeSelectionPositionRow=h:t===w.CURSOR_TYPE.NORTH_EAST_RESIZE?this._relativeSelectionPositionRow=h:t===w.CURSOR_TYPE.WEST_RESIZE?this._relativeSelectionPositionColumn=m:t===w.CURSOR_TYPE.SOUTH_WEST_RESIZE&&(this._relativeSelectionPositionColumn=m);const S=w.ScrollTimer.create(r);S.startScroll(l,c),this._scrollTimer=S,r.disableEvent(),this._moveObserver=r.onPointerMoveObserver.add(g=>{const{offsetX:_,offsetY:I}=g,{x:C,y:b}=r.getRelativeCoord(w.Vector2.FromArray([_,I]));this._widgetMoving(C,b,t),r.setCursor(t),S.scrolling(C,b,()=>{this._widgetMoving(C,b,t)})}),this._upObserver=r.onPointerUpObserver.add(()=>{var _;const g=this._scene;g.resetCursor(),this._clearObserverEvent(),g.enableEvent(),(_=this._scrollTimer)==null||_.dispose(),this._control.selectionScaled$.next(this._targetSelection)})}_initialFill(){const{fillControl:e}=this._control;e.onPointerEnterObserver.add(()=>{e.setCursor(w.CURSOR_TYPE.CROSSHAIR)}),e.onPointerLeaveObserver.add(()=>{e.resetCursor()}),e.onPointerDownObserver.add(this._fillEvent.bind(this))}_fillMoving(e,t){var U,N,B;const n=this._scene,o=n.getScrollXYByRelativeCoords(w.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:r,scaleY:s}=n.getAncestorScale(),l=this._skeleton.getCellPositionByOffset(e,t,r,s,o),{row:c,column:d}=l,u=n.getRelativeCoord(w.Vector2.FromArray([e,t])),h=this._skeleton.getRowCount()-1,m=this._skeleton.getColumnCount()-1;let S=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,_=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,I=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength,C=!1,b=!0;if((d<g||d>I)&&c>=S&&c<=_){const A=this._fillRuler(d,g,I,this._relativeSelectionColumnLength,m);g=A.startRowOrColumn,I=A.endRowOrColumn,C=A.isLighten,b=!1}else if((c<S||c>_)&&d>=g&&d<=I){const A=this._fillRuler(c,S,_,this._relativeSelectionRowLength,h);S=A.startRowOrColumn,_=A.endRowOrColumn,C=A.isLighten}else if(Math.abs(this._startOffsetX-u.x-o.x)/2>Math.abs(this._startOffsetY-u.y-o.y)){const A=this._fillRuler(d,g,I,this._relativeSelectionColumnLength,m);g=A.startRowOrColumn,I=A.endRowOrColumn,C=A.isLighten,b=!1}else{const A=this._fillRuler(c,S,_,this._relativeSelectionRowLength,h);S=A.startRowOrColumn,_=A.endRowOrColumn,C=A.isLighten}const M=this._skeleton.getNoMergeCellPositionByIndex(S,g,r,s),T=this._skeleton.getNoMergeCellPositionByIndex(_,I,r,s),E=(M==null?void 0:M.startY)||0,y=(T==null?void 0:T.endY)||0,O=(M==null?void 0:M.startX)||0,x=(T==null?void 0:T.endX)||0;C?this._controlHandler((A,H)=>{const V=new a.ColorKit(this._fillControlColors[H]).lighten(Lr).toRgbString();A.setProps({fill:V})}):this._controlHandler((A,H)=>{A.setProps({fill:this._fillControlColors[H]})});const D=f.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();S===_&&b===!0||g===I&&b===!1?(U=this._helperSelection)==null||U.hide():((N=this._helperSelection)==null||N.transformByState({left:O-D/2,top:E-D/2,width:x-O,height:y-E}),(B=this._helperSelection)==null||B.show()),this._targetSelection={startY:E,endY:y,startX:O,endX:x,startRow:S,endRow:_,startColumn:g,endColumn:I},this._control.selectionFilling$.next(this._targetSelection)}_fillEvent(e){const{offsetX:t,offsetY:n}=e,o=this._scene,r=o.getRelativeCoord(w.Vector2.FromArray([t,n])),{x:s,y:l}=r;this._startOffsetX=s,this._startOffsetY=l;const{startRow:c,startColumn:d,endRow:u,endColumn:h}=this._control.model;this._isInMergeState=this._hasMergeInRange(c,d,u,h),this._relativeSelectionPositionRow=c,this._relativeSelectionPositionColumn=d,this._relativeSelectionRowLength=u-c,this._relativeSelectionColumnLength=h-d;const m=this._control.selectionStyle;let S=m==null?void 0:m.stroke,g=m==null?void 0:m.strokeWidth;const _=f.getNormalSelectionStyle(this._themeService);S==null&&(S=_.stroke),g==null&&(g=_.strokeWidth);const I=this._getScale();g/=I;const C=f.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/I,b=new a.ColorKit(S).darken(2).toRgbString();this.isHelperSelection&&(this._helperSelection=new w.Rect(Di,{stroke:b,strokeWidth:g+C/2}),o.addObject(this._helperSelection));const M=w.ScrollTimer.create(o);M.startScroll(s,l),this._scrollTimer=M,o.disableEvent(),this._controlHandler(T=>{this._fillControlColors.push(T.fill)}),this._moveObserver=o.onPointerMoveObserver.add(T=>{const{offsetX:E,offsetY:y}=T,{x:O,y:x}=o.getRelativeCoord(w.Vector2.FromArray([E,y]));this._fillMoving(O,x),o.setCursor(w.CURSOR_TYPE.CROSSHAIR),M.scrolling(O,x,()=>{this._fillMoving(O,x)})}),this._upObserver=o.onPointerUpObserver.add(()=>{var E,y;(E=this._helperSelection)==null||E.dispose();const T=this._scene;T.resetCursor(),this._clearObserverEvent(),T.enableEvent(),(y=this._scrollTimer)==null||y.dispose(),this._control.refreshSelectionFilled(this._targetSelection),this._isInMergeState=!1,this._controlHandler((O,x)=>{O.setProps({fill:this._fillControlColors[x]})}),this._fillControlColors=[]})}_hasMergeInRange(e,t,n,o){const r=this._skeleton.mergeData;if(!r)return!1;for(const s of r){const{startRow:l,startColumn:c,endRow:d,endColumn:u}=s,h={left:t,top:e,right:o,bottom:n},m={left:c,top:l,right:u,bottom:d};if(w.isRectIntersect(h,m))return!0}return!1}_swapPositions(e,t,n,o){const r=Math.min(e,n),s=Math.min(t,o),l=Math.max(e,n),c=Math.max(t,o);return{startRow:r,startColumn:s,endRow:l,endColumn:c}}_controlHandler(e){const{leftControl:t,rightControl:n,topControl:o,bottomControl:r,backgroundControlTop:s,backgroundControlMiddleLeft:l,backgroundControlMiddleRight:c,backgroundControlBottom:d,fillControl:u}=this._control,h=[t,n,o,r,s,l,c,d,u];for(let m=0,S=h.length;m<S;m++){const g=h[m];e(g,m)}}_fillRuler(e,t,n,o,r){let s=!1;if(e<t)if(this._isInMergeState&&e<t){const l=t-e,c=o+1,d=Math.ceil(l/c);let u=t-d*c;u<0&&(u=t-(d-1)*c),t=u}else t=e;else if(e>=t&&e<=n)s=!0,n=e;else if(this._isInMergeState&&e>n){const l=e-n,c=o+1,d=Math.ceil(l/c);let u=n+d*c;u>r&&(u=n+(d-1)*c),n=u}else n=e;return{rowOrColumn:e,startRowOrColumn:t,endRowOrColumn:n,isLighten:s}}_getScale(){const{scaleX:e,scaleY:t}=this._scene.getAncestorScale();return Math.max(e,t)}}var Ur=Object.defineProperty,kr=Object.getOwnPropertyDescriptor,Br=(i,e,t,n)=>{for(var o=n>1?void 0:n?kr(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Ur(e,t,o),o},Pi=(i,e)=>(t,n)=>e(t,n,i);exports.SelectionRenderService=class{constructor(e,t){v(this,"hasSelection",!1);v(this,"_downObserver");v(this,"_moveObserver");v(this,"_upObserver");v(this,"_controlFillConfig$",new k.BehaviorSubject(null));v(this,"controlFillConfig$",this._controlFillConfig$.asObservable());v(this,"_selectionControls",[]);v(this,"_startSelectionRange",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});v(this,"_startOffsetX",0);v(this,"_startOffsetY",0);v(this,"_scrollTimer");v(this,"_cancelDownObserver");v(this,"_cancelUpObserver");v(this,"_skeleton");v(this,"_scene");v(this,"_isHeaderHighlight",!0);v(this,"_isDetectMergedCell",!0);v(this,"_selectionStyle");v(this,"_isSelectionEnabled",!0);v(this,"_isShowPreviousEnable",0);v(this,"_isRemainLastEnable",!0);v(this,"_isSkipRemainLastEnable",!1);v(this,"_selectionMoveEnd$",new k.BehaviorSubject([]));v(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());v(this,"_selectionMoving$",new k.Subject);v(this,"selectionMoving$",this._selectionMoving$.asObservable());v(this,"_selectionMoveStart$",new k.Subject);v(this,"selectionMoveStart$",this._selectionMoveStart$.asObservable());v(this,"_activeViewport");this._themeService=e,this._shortcutService=t,this._selectionStyle=f.getNormalSelectionStyle(this._themeService)}enableHeaderHighlight(){this._isHeaderHighlight=!0}disableHeaderHighlight(){this._isHeaderHighlight=!1}enableDetectMergedCell(){this._isDetectMergedCell=!0}disableDetectMergedCell(){this._isDetectMergedCell=!1}setStyle(e){this._selectionStyle=e}resetStyle(){this.setStyle(f.getNormalSelectionStyle(this._themeService))}enableSelection(){this._isSelectionEnabled=!0}disableSelection(){this._isSelectionEnabled=!1}enableShowPrevious(){this._isShowPreviousEnable=!0}disableShowPrevious(){this._isShowPreviousEnable=!1}enableRemainLast(){this._isRemainLastEnable=!0}disableRemainLast(){this._isRemainLastEnable=!1}enableSkipRemainLast(){this._isSkipRemainLastEnable=!0}disableSkipRemainLast(){this._isSkipRemainLastEnable=!1}getViewPort(){return this._activeViewport}addControlToCurrentByRangeData(e){const t=this.getCurrentControls();if(!t)return;const{rangeWithCoord:n,primaryWithCoord:o}=e,r=this._skeleton;let s=e.style;s==null&&(s=f.getNormalSelectionStyle(this._themeService));const l=this._scene;if(l==null||r==null)return;const c=new Rn(l,t.length,this._isHeaderHighlight,this._themeService);new Ni(c,r,l,this._themeService);const{rowHeaderWidth:d,columnHeaderHeight:u}=r;c.update(n,d,u,s,o),this._isHeaderHighlight?c.enableHeaderHighlight():c.disableHeaderHighlight(),t.push(c)}changeRuntime(e,t,n){this._skeleton=e,this._scene=t,this._activeViewport=n||t.getViewports()[0]}getSelectionDataWithStyle(){return this._selectionControls.map(t=>t.getValue())}getCurrentControls(){return this._selectionControls}_clearSelectionControls(){const e=this.getCurrentControls();if(e.length>0){for(const t of e)t.dispose();e.length=0}}getActiveSelections(){const e=this.getCurrentControls();if(e&&e.length>0)return e==null?void 0:e.map(n=>{const o=n.model,r=o.currentCell;let s=null;return r&&(s={actualRow:r.actualRow,actualColumn:r.actualColumn,isMerged:r.isMerged,isMergedMainCell:r.isMergedMainCell,startRow:r.mergeInfo.startRow,startColumn:r.mergeInfo.startColumn,endRow:r.mergeInfo.endRow,endColumn:r.mergeInfo.endColumn}),{range:{startRow:o.startRow,startColumn:o.startColumn,endRow:o.endRow,endColumn:o.endColumn},primary:s}})}getActiveRange(){const e=this.getCurrentControls(),t=e&&e[e.length-1].model;return t&&{startRow:t.startRow,startColumn:t.startColumn,endRow:t.endRow,endColumn:t.endColumn}}getActiveSelection(){const e=this.getCurrentControls();return e&&e[e.length-1]}endSelection(){this._endSelection()}reset(){this._clearSelectionControls(),this._moveObserver=null,this._upObserver=null,this._downObserver=null}resetAndEndSelection(){this.endSelection(),this.reset()}eventTrigger(e,t=0,n=a.RANGE_TYPE.NORMAL,o,r=w.ScrollTimerType.ALL){if(this._isSelectionEnabled===!1)return;const s=this._skeleton,{offsetX:l,offsetY:c}=e,d=this._scene;if(d==null||s==null)return;o!=null&&(this._activeViewport=o);const u=d.getRelativeCoord(w.Vector2.FromArray([l,c]));let{x:h,y:m}=u;this._startOffsetX=h,this._startOffsetY=m;const S=d.getScrollXYByRelativeCoords(u),{scaleX:g,scaleY:_}=d.getAncestorScale();n===a.RANGE_TYPE.ROW?h=0:n===a.RANGE_TYPE.COLUMN&&(m=0);const I=this._getSelectedRangeWithMerge(h,m,g,_,S);if(!I)return!1;const{rangeWithCoord:C,primaryWithCoord:b}=I,{startRow:M,startColumn:T,endColumn:E,endRow:y,startY:O,endY:x,startX:D,endX:U}=C,{rowHeaderWidth:N,columnHeaderHeight:B}=s,A={startColumn:T,startRow:M,endColumn:E,endRow:y,startY:O,endY:x,startX:D,endX:U,rangeType:n};this._startSelectionRange=A;let H=this.getActiveSelection();const V=this.getCurrentControls();if(!V)return!1;for(const $ of V){if(e.button===2&&$.model.isInclude(A)){H=$;return}if($.model.isEqual(A)){H=$;break}e.shiftKey||$.clearHighlight()}if(V.length>0&&!e.ctrlKey&&!e.shiftKey&&!this._isShowPreviousEnable&&!this._isRemainLastEnable){for(const $ of V)$.dispose();V.length=0}const F=H&&H.model.currentCell;if(H&&e.shiftKey&&F){const{actualRow:$,actualColumn:q,mergeInfo:z}=F,Q=Math.min($,A.startRow,z.startRow),J=Math.max($,A.endRow,z.endRow),we=Math.min(q,A.startColumn,z.startColumn),re=Math.max(q,A.endColumn,z.endColumn),Se=s.getMergeBounding(Q,we,J,re),qe=s.getNoMergeCellPositionByIndex(Se.startRow,Se.startColumn,g,_),Be=s.getNoMergeCellPositionByIndex(Se.endRow,Se.endColumn,g,_),Te={startColumn:Se.startColumn,startRow:Se.startRow,endColumn:Se.endColumn,endRow:Se.endRow,startY:qe.startY,endY:Be.endY,startX:qe.startX,endX:Be.endX,rangeType:n},de=s.getCellByIndex($,q,g,_);this._startSelectionRange={startColumn:de.mergeInfo.startColumn,startRow:de.mergeInfo.startRow,endColumn:de.mergeInfo.endColumn,endRow:de.mergeInfo.endRow,startY:de.mergeInfo.startY||0,endY:de.mergeInfo.endY||0,startX:de.mergeInfo.startX||0,endX:de.mergeInfo.endX||0,rangeType:n},H.update(Te,N,B,this._selectionStyle,F)}else this._isRemainLastEnable&&H&&!e.ctrlKey&&!e.shiftKey&&!this._isSkipRemainLastEnable?H.update(A,N,B,this._selectionStyle,b):(H=new Rn(d,V.length+t,this._isHeaderHighlight,this._themeService),new Ni(H,s,d,this._themeService),H.update(A,N,B,this._selectionStyle,b),V.push(H));this._selectionMoveStart$.next(this.getSelectionDataWithStyle()),this.hasSelection=!0,this._endSelection(),d.disableEvent();const j=w.ScrollTimer.create(this._scene,r);j.startScroll(h,m,o),this._scrollTimer=j,this._addCancelObserver(),(n===a.RANGE_TYPE.ROW||n===a.RANGE_TYPE.COLUMN)&&this._moving(h,m,H,n),this._moveObserver=d.onPointerMoveObserver.add($=>{const{offsetX:q,offsetY:z}=$,{x:Q,y:J}=d.getRelativeCoord(w.Vector2.FromArray([q,z]));this._moving(Q,J,H,n),j.scrolling(Q,J,()=>{this._moving(Q,J,H,n)})}),this._upObserver=d.onPointerUpObserver.add($=>{this._endSelection(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),this._shortcutService.setDisable(!1)}),this._shortcutService.setDisable(!0)}convertSelectionRangeToData(e){const{range:t,primary:n,style:o}=e;let r=this.convertRangeDataToSelection(t);return r==null&&(r={startRow:-1,startColumn:-1,endRow:-1,endColumn:-1,startY:0,endY:0,startX:0,endX:0,rangeType:a.RANGE_TYPE.NORMAL}),{rangeWithCoord:r,primaryWithCoord:this.convertCellRangeToInfo(n),style:o}}convertRangeDataToSelection(e){const{startRow:t,startColumn:n,endRow:o,endColumn:r,rangeType:s}=e,l=this._scene,c=this._skeleton;if(l==null||c==null)return;const{scaleX:d,scaleY:u}=l.getAncestorScale(),h=c.getNoMergeCellPositionByIndex(t,n,d,u),m=c.getNoMergeCellPositionByIndex(o,r,d,u);return{startRow:t,startColumn:n,endRow:o,endColumn:r,rangeType:s,startY:(h==null?void 0:h.startY)||0,endY:(m==null?void 0:m.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(m==null?void 0:m.endX)||0}}convertCellRangeToInfo(e){if(e==null)return;const t=this._scene,n=this._skeleton;if(t==null||n==null)return;const{actualRow:o,actualColumn:r,isMerged:s,isMergedMainCell:l,startRow:c,startColumn:d,endRow:u,endColumn:h}=e,{scaleX:m,scaleY:S}=t.getAncestorScale(),g=n.getNoMergeCellPositionByIndex(o,r,m,S),_=n.getNoMergeCellPositionByIndex(c,d,m,S),I=n.getNoMergeCellPositionByIndex(u,h,m,S);return{actualRow:o,actualColumn:r,isMerged:s,isMergedMainCell:l,startX:g.startX,startY:g.startY,endX:g.endX,endY:g.endY,mergeInfo:{startRow:c,startColumn:d,endRow:u,endColumn:h,startY:(_==null?void 0:_.startY)||0,endY:(I==null?void 0:I.endY)||0,startX:(_==null?void 0:_.startX)||0,endX:(I==null?void 0:I.endX)||0}}}_moving(e,t,n,o){const r=this._skeleton,s=this._scene;if(s==null||r==null)return!1;const{startRow:l,startColumn:c,endRow:d,endColumn:u}=this._startSelectionRange,h=s.getScrollXYByRelativeCoords(w.Vector2.FromArray([this._startOffsetX,this._startOffsetY]),this._activeViewport),{scaleX:m,scaleY:S}=s.getAncestorScale(),{rowHeaderWidth:g,columnHeaderHeight:_}=r;o===a.RANGE_TYPE.ROW?e=1/0:o===a.RANGE_TYPE.COLUMN&&(t=1/0);const I=this._getSelectedRangeWithMerge(e,t,m,S,h);if(!I)return!1;const{rangeWithCoord:C,primaryWithCoord:b}=I,{startRow:M,startColumn:T,endColumn:E,endRow:y}=C,O=Math.min(M,l),x=Math.min(T,c),D=Math.max(y,d),U=Math.max(E,u);let N={startRow:O,startColumn:x,endRow:D,endColumn:U};if(this._isDetectMergedCell&&(N=r.getSelectionBounding(O,x,D,U)),!N)return!1;const{startRow:B,startColumn:A,endRow:H,endColumn:V}=N,F=r.getNoMergeCellPositionByIndex(B,A,m,S),j=r.getNoMergeCellPositionByIndex(H,V,m,S),$={startColumn:A,startRow:B,endColumn:V,endRow:H,startY:(F==null?void 0:F.startY)||0,endY:(j==null?void 0:j.endY)||0,startX:(F==null?void 0:F.startX)||0,endX:(j==null?void 0:j.endX)||0},{startRow:q,endRow:z,startColumn:Q,endColumn:J}=(n==null?void 0:n.model)||{startRow:-1,endRow:-1,startColumn:-1,endColumn:-1};(Q!==A||q!==B||J!==V||z!==H)&&n!=null&&(n.update($,g,_),this._selectionMoving$.next(this.getSelectionDataWithStyle()))}_endSelection(){var n,o;const e=this._scene;if(e==null)return;e.onPointerMoveObserver.remove(this._moveObserver),e.onPointerUpObserver.remove(this._upObserver),e.enableEvent(),(n=this._scrollTimer)==null||n.dispose();const t=(o=e.getEngine())==null?void 0:o.activeScene;t==null||t.onPointerDownObserver.remove(this._cancelDownObserver),t==null||t.onPointerUpObserver.remove(this._cancelUpObserver)}_addCancelObserver(){var n;const e=this._scene;if(e==null)return;const t=(n=e.getEngine())==null?void 0:n.activeScene;t==null||t===e||(t.onPointerDownObserver.remove(this._cancelDownObserver),t.onPointerUpObserver.remove(this._cancelUpObserver),this._cancelDownObserver=t.onPointerDownObserver.add(o=>{this._endSelection()}),this._cancelUpObserver=t.onPointerUpObserver.add(o=>{this._endSelection()}))}_getSelectedRangeWithMerge(e,t,n,o,r){var C;if(this._isDetectMergedCell){const b=(C=this._skeleton)==null?void 0:C.calculateCellIndexByPosition(e,t,n,o,r),M=a.makeCellToSelection(b);return M==null?void 0:{primaryWithCoord:b,rangeWithCoord:M}}const s=this._skeleton;if(s==null)return;const l=s.getCellPositionByOffset(e,t,n,o,r),{row:c,column:d}=l,u=s.getNoMergeCellPositionByIndex(c,d,n,o),{startX:h,startY:m,endX:S,endY:g}=u,_={startY:m,endY:g,startX:h,endX:S,startRow:c,endRow:c,startColumn:d,endColumn:d};return{primaryWithCoord:{actualRow:c,actualColumn:d,isMerged:!1,isMergedMainCell:!1,startY:m,endY:g,startX:h,endX:S,mergeInfo:_},rangeWithCoord:_}}};exports.SelectionRenderService=Br([Pi(0,P.Inject(a.ThemeService)),Pi(1,R.IShortcutService)],exports.SelectionRenderService);const ce=P.createIdentifier("deprecated.univer.sheet.selection-render-service");var Vr=Object.defineProperty,Fr=Object.getOwnPropertyDescriptor,jr=(i,e,t,n)=>{for(var o=n>1?void 0:n?Fr(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Vr(e,t,o),o},Li=(i,e)=>(t,n)=>e(t,n,i);exports.SheetSkeletonManagerService=class{constructor(e,t){v(this,"_currentSkeleton",{unitId:"",sheetId:""});v(this,"_sheetSkeletonParam",[]);v(this,"_currentSkeleton$",new k.BehaviorSubject(null));v(this,"currentSkeleton$",this._currentSkeleton$.asObservable());v(this,"_currentSkeletonBefore$",new k.BehaviorSubject(null));v(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._currentUniverService=e,this._localeService=t}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._sheetSkeletonParam=[]}getCurrent(){return this._getCurrentBySearch(this._currentSkeleton)}setCurrent(e){const t=this._getCurrentBySearch(e);if(t!=null)this._reCalculate(t);else{const{unitId:o,sheetId:r}=e,s=this._currentUniverService.getUniverSheetInstance(e.unitId),l=s==null?void 0:s.getSheetBySheetId(e.sheetId);if(l==null||s==null)return;const c=this._buildSkeleton(l,s);this._sheetSkeletonParam.push({unitId:o,sheetId:r,skeleton:c,dirty:!1})}this._currentSkeleton=e;const n=this.getCurrent();return this._currentSkeletonBefore$.next(n),this._currentSkeleton$.next(n),this.getCurrent()}reCalculate(){const e=this.getCurrent();e!=null&&this._reCalculate(e)}_reCalculate(e){e.dirty&&(e.skeleton.makeDirty(!0),e.dirty=!1),e.skeleton.calculate()}makeDirtyCurrent(e=!0){this.makeDirty(this._currentSkeleton,e)}makeDirty(e,t=!0){const n=this._getCurrentBySearch(e);n!=null&&(n.dirty=t)}_getCurrentBySearch(e){const t=this._sheetSkeletonParam.find(n=>n.unitId===e.unitId&&n.sheetId===e.sheetId);return t!=null&&(t.commandId=e.commandId),t}_buildSkeleton(e,t){const n=e.getConfig();return w.SpreadsheetSkeleton.create(e,n,e.getCellMatrix(),t.getStyles(),this._localeService)}};exports.SheetSkeletonManagerService=jr([Li(0,a.IUniverInstanceService),Li(1,P.Inject(a.LocaleService))],exports.SheetSkeletonManagerService);var Wr=Object.defineProperty,$r=Object.getOwnPropertyDescriptor,zr=(i,e,t,n)=>{for(var o=n>1?void 0:n?$r(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Wr(e,t,o),o},Ve=(i,e)=>(t,n)=>e(t,n,i);const Xr=1e4,At=P.createIdentifier("univer.mark-selection-service");exports.MarkSelectionService=class extends a.Disposable{constructor(t,n,o,r,s,l,c){super();v(this,"_shapeMap",new Map);this._currentService=t,this._renderManagerService=n,this._selectionRenderService=o,this._commandService=r,this._sheetSkeletonManagerService=s,this._themeService=l,this._selectionManagerService=c}addShape(t,n=Xr){const o=this._currentService.getCurrentUniverSheetInstance(),r=o.getActiveSheet().getSheetId(),s=a.Tools.generateRandomId();return this._shapeMap.set(s,{selection:t,subUnitId:r,unitId:o.getUnitId(),zIndex:n,control:null}),this.refreshShapes(),s}refreshShapes(){const t=this._currentService.getCurrentUniverSheetInstance().getUnitId(),n=this._currentService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();this._shapeMap.forEach(o=>{var b;const{unitId:r,subUnitId:s,selection:l,control:c,zIndex:d}=o;if(r!==t||s!==n){c&&c.dispose();return}const{style:u}=l,{scene:h}=this._renderManagerService.getRenderById(r)||{},{rangeWithCoord:m,primaryWithCoord:S}=this._selectionRenderService.convertSelectionRangeToData(l),g=(b=this._sheetSkeletonManagerService.getCurrent())==null?void 0:b.skeleton;if(!h||!g)return;const{rowHeaderWidth:_,columnHeaderHeight:I}=g,C=new Rn(h,d,!1,this._themeService);C.update(m,_,I,u,S),o.control=C})}removeShape(t){const n=this._shapeMap.get(t);if(!n)return;const{control:o}=n;o&&o.dispose(),this._shapeMap.delete(t)}removeAllShapes(){for(const t of this._shapeMap.values()){const{control:n}=t;n&&n.dispose()}this._shapeMap.clear()}};exports.MarkSelectionService=zr([Ve(0,a.IUniverInstanceService),Ve(1,w.IRenderManagerService),Ve(2,ce),Ve(3,a.ICommandService),Ve(4,P.Inject(exports.SheetSkeletonManagerService)),Ve(5,P.Inject(a.ThemeService)),Ve(6,P.Inject(f.SelectionManagerService))],exports.MarkSelectionService);const Yr=10,Zr=6;function Gr(){return a.Tools.generateRandomId(Zr)}function Kr(i){const e=i.match(/data-copy-id="([^\s]+)"/);return e&&e[1]?e[1]:null}class qr{constructor(){v(this,"_cache",new a.LRUMap(Yr))}set(e,t){this._cache.set(e,t)}get(e){return this._cache.get(e)}del(e){this._cache.delete(e)}clear(){this._cache.clear()}}const Ln=new qr;function Jr(i){const e=new DOMParser,t=`<x-univer id="univer-root">${i}</x-univer>`;return e.parseFromString(t,"text/html").querySelector("#univer-root")}function Qr(i){const e=i.style,t={};for(let n=0;n<e.length;n++){const o=e[n],r=e.getPropertyValue(o);switch(o){case"margin-top":{const s=parseInt(r);t.spaceAbove=/pt/.test(r)?qn(s):s;break}case"margin-bottom":{const s=parseInt(r);t.spaceBelow=/pt/.test(r)?qn(s):s;break}}}return Object.getOwnPropertyNames(t).length?t:null}function qn(i){return i/.75}function Ui(i,e){const t=[];for(let n=0,o=i.length;n<o;n++)i[n]===a.DataStreamTreeTokenType.PARAGRAPH&&t.push({startIndex:n});if(e)for(const n of t)e.bullet&&(n.bullet=a.Tools.deepClone(e.bullet)),e.paragraphStyle&&(n.paragraphStyle=a.Tools.deepClone(e.paragraphStyle));return t}function ci(i){const e=i.style,t={},n=i.tagName.toLowerCase();switch(n){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=n==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}for(let o=0;o<e.length;o++){const r=e[o],s=e.getPropertyValue(r);switch(r){case"font-family":{t.ff=s;break}case"font-size":{const l=parseInt(s);Number.isNaN(l)||(t.fs=/pt$/.test(s)?qn(l):l);break}case"font-style":{s==="italic"&&(t.it=a.BooleanNumber.TRUE);break}case"font-weight":{Number(s)>400&&(t.bl=a.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(s)?t.ul={s:a.BooleanNumber.TRUE}:/overline/.test(s)?t.ol={s:a.BooleanNumber.TRUE}:/line-through/.test(s)&&(t.st={s:a.BooleanNumber.TRUE});break}case"color":{const l=new a.ColorKit(s);l.isValid&&(t.cl={rgb:l.toRgbString()});break}case"background-color":{const l=new a.ColorKit(s);l.isValid&&(t.bg={rgb:l.toRgbString()});break}}}return t}function ki(i,e){const t=i.tagName.toLowerCase();return typeof e=="string"?t===e:Array.isArray(e)?e.some(n=>n===t):e(i)}const En=class En{constructor(e){v(this,"styleCache",new Map);v(this,"styleRules",[]);v(this,"afterProcessRules",[]);v(this,"getCurrentSkeleton");this.getCurrentSkeleton=e.getCurrentSkeleton}static use(e){if(this.pluginList.includes(e))throw new Error(`Univer paste plugin ${e.name} already added`);this.pluginList.push(e)}convert(e){const t=En.pluginList.find(m=>m.checkPasteType(e));t&&(this.styleRules=[...t.stylesRules],this.afterProcessRules=[...t.afterProcessRules]);const n=new a.ObjectMatrix,o=Jr(e),r={dataStream:"",textRuns:[]},s=[],l=e.match(/<table.*?>([\s\S]*?)<\/table>/gi),c=[];this.process(null,o==null?void 0:o.childNodes,r,c);const{paragraphs:d,dataStream:u,textRuns:h}=r;if(d){const m=d.map(S=>S.startIndex+1);m.unshift(0);for(let S=0;S<m.length;S++){let g;S===m.length-1?g=`${u.substring(m[S])}\r
2
- `:g=`${u.substring(m[S],m[S+1]-1)}\r
3
- `;const _=[];h==null||h.forEach(C=>{C.st>=m[S]&&C.ed<=m[S+1]&&_.push({st:C.st-m[S],ed:C.ed-m[S],ts:C.ts})});const I=this._generateDocumentDataModelSnapshot({body:{dataStream:g,textRuns:_,paragraphs:Ui(g)}});n.setValue(n.getLength(),0,{v:g,p:I}),s.push({}),l&&c.forEach(C=>{const b=n.getLength();if(C.index===S){const M=l.shift(),{cellMatrix:T,colProperties:E,rowProperties:y}=this._parseTable(M);T&&T.forValue((O,x,D)=>{n.setValue(b+O,x,D)}),s.push(...y)}})}}else{if(u){const m=`${u}\r
4
- `,S={dataStream:m,textRuns:h,paragraphs:Ui(m)},g=this._generateDocumentDataModelSnapshot({body:S});n.setValue(0,0,{v:u,p:g}),s.push({})}l&&l.forEach(m=>{const S=n.getLength(),{cellMatrix:g}=this._parseTable(m);g&&g.forValue((_,I,C)=>{n.setValue(S+_,I,C)}),s.push(...s)})}return{rowProperties:[],colProperties:[],cellMatrix:n}}_parseTable(e){const t=new a.ObjectMatrix;ns(e);const{rowProperties:n,rowCount:o,cellMatrix:r}=es(e);return r&&r.forValue((s,l,c)=>{var u;const d=R.handleStringToStyle(void 0,(u=c.properties)==null?void 0:u.style);t.setValue(s,l,{v:c.content,s:d,rowSpan:c.rowSpan,colSpan:c.colSpan})}),{rowProperties:[],colProperties:[],cellMatrix:t}}_generateDocumentDataModelSnapshot(e){var l;const t=this.getCurrentSkeleton();if(t==null)return null;const{skeleton:n}=t,o=(l=n.getBlankCellDocumentModel())==null?void 0:l.documentModel,s={...o==null?void 0:o.getSnapshot(),...e};return o==null||o.reset(s),o==null?void 0:o.getSnapshot()}process(e,t,n,o){var r,s;for(const l of t)if(l.nodeName.toLowerCase()==="table")o.push({index:((r=n==null?void 0:n.paragraphs)==null?void 0:r.length)||0});else if(l.nodeType===Node.TEXT_NODE){const c=(s=l.nodeValue)==null?void 0:s.replace(/[\r\n]/g,"");let d;e&&this.styleCache.has(e)&&(d=this.styleCache.get(e));const u={dataStream:"",textRuns:[]};n.dataStream+=c,u.dataStream+=c,d&&Object.getOwnPropertyNames(d).length&&(n.textRuns.push({st:n.dataStream.length-c.length,ed:n.dataStream.length,ts:d}),u.textRuns.push({st:n.dataStream.length-c.length,ed:n.dataStream.length,ts:d}))}else if(l.nodeType===Node.ELEMENT_NODE){const c=e?this.styleCache.get(e):{},d=this.styleRules.find(({filter:S})=>ki(l,S)),u=d?d.getStyle(l):ci(l);this.styleCache.set(l,{...c,...u});const{childNodes:h}=l;this.process(l,h,n,o);const m=this.afterProcessRules.find(({filter:S})=>ki(l,S));m&&m.handler(n,l)}}};v(En,"pluginList",[]);let Et=En;function es(i){const e=/<tr([\s\S]*?)>([\s\S]*?)<\/tr>/gi,t=i.matchAll(e);if(!t)return{rowProperties:[],rowCount:0,colCount:0,cellMatrix:null};const n=Array.from(t),o=n.map(l=>di(l[1])),{colCount:r,cellMatrix:s}=ts(n.map(l=>l[2]));return{rowProperties:o,rowCount:o.length,colCount:r,cellMatrix:s}}function ts(i){const e=new a.ObjectMatrix,t=new Map,n=/<td([\s\S]*?)>([\s\S]*?)<\/td>/gi;let o=0,r=0,s=0;return i.forEach((l,c)=>{const d=c===0,u=l.matchAll(n);r=0,Array.from(u).forEach(h=>{const m=di(h[1]),S=h[2].replace(/&nbsp;/g," "),g=m.rowspan?+m.rowspan:1,_=m.colspan?+m.colspan:1;if(!d){for(let C=r;C<o;C++)if(!(t.get(C)>=s)){r=C;break}}const I={content:S,properties:m};_>1&&(I.colSpan=+_),g>1&&(I.rowSpan=+g),d&&(o+=_);for(let C=r;C<r+_;C++)t.set(C,s+g-1);e.setValue(s,r,I),r+=_}),s+=1}),{colCount:o,cellMatrix:e}}function di(i){if(!i)return{};const e=/([\w-]+)="([^"]*)"/gi,t=i.matchAll(e),n={};return Array.from(t).forEach(o=>{const[r,s,l]=o;n[s]=l}),n}function ns(i){const e=/<colgroup([\s\S]*?)>(.*?)<\/colgroup>/,t=i.match(e);if(!t||!t[2])return null;const n=/<col([\s\S]*?)>/g,o=t[2].matchAll(n);return o?Array.from(o).map(r=>di(r[1])):null}const is={name:"univer-doc-paste-plugin-lark",checkPasteType(i){return/lark-record-clipboard/i.test(i)},stylesRules:[{filter:["s"],getStyle(i){const e=ci(i);return{st:{s:a.BooleanNumber.TRUE},...e}}}],afterProcessRules:[{filter(i){return i.tagName==="DIV"&&/ace-line/i.test(i.className)},handler(i){i.paragraphs==null&&(i.paragraphs=[]),i.paragraphs.push({startIndex:i.dataStream.length}),i.dataStream+="\r"}}]},os=is,rs={name:"univer-doc-paste-plugin-word",checkPasteType(i){return/word|mso/i.test(i)},stylesRules:[{filter:["b"],getStyle(i){const e=ci(i);return{bl:a.BooleanNumber.TRUE,...e}}}],afterProcessRules:[{filter(i){return i.tagName==="P"&&/mso/i.test(i.className)},handler(i,e){i.paragraphs==null&&(i.paragraphs=[]);const t={startIndex:i.dataStream.length},n=Qr(e);n&&(t.paragraphStyle=n),i.paragraphs.push(t),i.dataStream+="\r"}}]},ss=rs;var Xe=(i=>(i.COPY="COPY",i.CUT="CUT",i))(Xe||{});function ls(i,e,t,n){const o=t.map(c=>{var d;return(d=c.onCopyRow)==null?void 0:d.call(c,i)}).filter(c=>!!c),r=ui(o),s=hi(r),l=e.map(c=>as(i,c,t,n)).filter(c=>!!c).join("");return`<tr${s}>${l}</tr>`}function as(i,e,t,n){const o=n.getValue(i,e),r=t.map(d=>{var u;return(u=d.onCopyCellStyle)==null?void 0:u.call(d,i,e,o==null?void 0:o.rowSpan,o==null?void 0:o.colSpan)}).filter(d=>!!d),s=ui(r),l=hi(s),c=t.reduce((d,u)=>{var h;return d||((h=u.onCopyCellContent)==null?void 0:h.call(u,i,e))||""},"");return`<td${l}>${c}</td>`}function cs(i,e){return`<colgroup>${i.map(n=>{const o=e.map(l=>{var c;return(c=l.onCopyColumn)==null?void 0:c.call(l,n)}).filter(l=>!!l),r=ui(o);return`<col ${hi(r)}>`}).join("")}</colgroup>`}function ui(i){return i.reduce((e,t)=>(Object.keys(t).forEach(o=>{e[o]?e[o]+=`;${t[o]}`:e[o]=t[o]}),e),{})}function hi(i){return Object.keys(i).reduce((e,t)=>(e+=` ${t}="${i[t]}"`,e),"")}function ds(i,e){const t=[];for(let n=i;n<=e;n++)t.push(n);return t}class us{convert(e,t,n){const{startColumn:o,endColumn:r}=t,s=cs(ds(o,r),n),l=[];return e.forRow((d,u)=>{l.push(ls(d,u,n,e))}),`<google-sheets-html-origin><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" border="1" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none">${s}
5
- <tbody>${l.join("")}</tbody></table>`}}var hs=Object.defineProperty,ms=Object.getOwnPropertyDescriptor,Ss=(i,e,t,n)=>{for(var o=n>1?void 0:n?ms(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&hs(e,t,o),o},He=(i,e)=>(t,n)=>e(t,n,i);const le={DEFAULT_COPY:"default-copy",DEFAULT_PASTE:"default-paste",SPECIAL_PASTE_VALUE:"special-paste-value",SPECIAL_PASTE_FORMAT:"special-paste-format",SPECIAL_PASTE_COL_WIDTH:"special-paste-col-width",SPECIAL_PASTE_BESIDES_BORDER:"special-paste-besides-border"};Et.use(ss);Et.use(os);const lt=P.createIdentifier("sheet.clipboard-service");exports.SheetClipboardService=class extends a.Disposable{constructor(t,n,o,r,s,l,c,d){super();v(this,"_clipboardHooks",[]);v(this,"_clipboardHooks$",new k.BehaviorSubject([]));v(this,"clipboardHooks$",this._clipboardHooks$.asObservable());v(this,"_htmlToUSM");v(this,"_usmToHtml");v(this,"_copyMarkId",null);v(this,"_pasteType",le.DEFAULT_PASTE);this._logService=t,this._currentUniverService=n,this._selectionManagerService=o,this._clipboardInterfaceService=r,this._undoRedoService=s,this._commandService=l,this._markSelectionService=c,this._sheetSkeletonManagerService=d,this._htmlToUSM=new Et({getCurrentSkeleton:()=>this._sheetSkeletonManagerService.getCurrent()}),this._usmToHtml=new us}async copy(t=Xe.COPY){const n=this._selectionManagerService.getLast();if(!n)return!1;const o=this._clipboardHooks;o.reduce((C,b)=>{var T;const M=(T=b.getFilteredOutRows)==null?void 0:T.call(b);return M==null||M.forEach(E=>C.add(E)),C},new Set);const{startColumn:r,startRow:s,endColumn:l,endRow:c}=n.range,d=this._currentUniverService.getCurrentUniverSheetInstance(),u=d.getActiveSheet(),h=u.getMatrixWithMergedCells(s,r,c,l),m=new a.ObjectMatrix;for(let C=s;C<=c;C++)for(let b=r;b<=l;b++){const M=h.getValue(C,b);M?m.setValue(C-s,b-r,{...Bi(),...a.Tools.deepClone(M)}):m.setValue(C-s,b-r,Bi())}o.forEach(C=>{var b;return(b=C.onBeforeCopy)==null?void 0:b.call(C,d.getUnitId(),u.getSheetId(),n.range)});let S=this._usmToHtml.convert(h,n.range,o);const g=_s(m),_=Gr();S=S.replace(/(<[a-z]+)/,(C,b)=>`${b} data-copy-id="${_}"`),Ln.set(_,{unitId:d.getUnitId(),subUnitId:u.getSheetId(),range:n.range,matrix:m,copyType:t}),await this._clipboardInterfaceService.write(g,S),this._markSelectionService.removeAllShapes();const I=this._selectionManagerService.createCopyPasteSelection();return this._copyMarkId=this._markSelectionService.addShape({...n,style:I}),o.forEach(C=>{var b;return(b=C.onAfterCopy)==null?void 0:b.call(C)}),!0}async cut(){return this.copy(Xe.CUT)}async paste(t,n=le.DEFAULT_PASTE){const o=t.types,r=o.indexOf(R.PLAIN_TEXT_CLIPBOARD_MIME_TYPE)!==-1?await t.getType(R.PLAIN_TEXT_CLIPBOARD_MIME_TYPE).then(l=>l&&l.text()):"",s=o.indexOf(R.HTML_CLIPBOARD_MIME_TYPE)!==-1?await t.getType(R.HTML_CLIPBOARD_MIME_TYPE).then(l=>l&&l.text()):"";return s?this._pasteHTML(s,n):r?this._pastePlainText(r):(this._logService.error("[SheetClipboardService]","No valid data on clipboard"),!1)}addClipboardHook(t){if(this._clipboardHooks.findIndex(o=>o.hookName===t.hookName)!==-1)return this._logService.error("[SheetClipboardService]","hook already exists",t.hookName),{dispose:()=>{}};const n=this._clipboardHooks.findIndex(o=>{const r=o.priority||0;return(t.priority||0)<r});return this._clipboardHooks.splice(n!==-1?n:this._clipboardHooks.length,0,t),this._notifyClipboardHook(),a.toDisposable(()=>{const o=this._clipboardHooks.indexOf(t);o>-1&&(this._clipboardHooks.splice(o,1),this._notifyClipboardHook())})}getClipboardHooks(){return this._clipboardHooks}_notifyClipboardHook(){this._clipboardHooks$.next(this._clipboardHooks)}async _pastePlainText(t){const n=this._getPastingTarget();if(!n.selection)return!1;const o=n.selection.range,r={[o.startRow]:{[o.endColumn]:{v:t}}},s={unitId:n.unitId,subUnitId:n.subUnitId,cellValue:r};return this._commandService.syncExecuteCommand(f.SetRangeValuesMutation.id,s)}async _pasteHTML(t,n){const o=Kr(t);return o?this._pasteInternal(o,n):this._pasteExternal(t,n)}async _pasteExternal(t,n){const o=this._getPastingTarget(),{selection:r,unitId:s,subUnitId:l}=o;if(!r)return!1;const{rowProperties:c,colProperties:d,cellMatrix:u}=this._htmlToUSM.convert(t),{startColumn:h,endColumn:m,startRow:S,endRow:g}=u.getDataRange(),_=g-S+1,I=m-h+1;if(!u)return!1;const C=this._transformPastedData(_,I,u,r.range);return C?this._pasteUSM({rowProperties:c,colProperties:d,cellMatrix:u},{unitId:s,subUnitId:l,pastedRange:C},n):!1}async _pasteInternal(t,n){var b;const o=this._getPastingTarget(),{selection:r,unitId:s,subUnitId:l}=o,c=a.Tools.deepClone(Ln.get(t)),{range:d,matrix:u}=c||{};if(!r||!u||!c||!d||!r||!u||!c)return!1;const h=(b=this._currentUniverService.getUniverSheetInstance(s))==null?void 0:b.getStyles();u.forValue((M,T,E)=>{if(typeof E.s=="string"){const y=a.Tools.deepClone(E);y.s=h==null?void 0:h.getStyleByCell(E),u.setValue(M,T,y)}});const{startColumn:m,endColumn:S,startRow:g,endRow:_}=d,I=this._transformPastedData(_-g+1,S-m+1,u,r.range);if(!I)return!1;const C=this._pasteUSM({cellMatrix:u},{unitId:s,subUnitId:l,pastedRange:I},n,{range:d,unitId:c.unitId,subUnitId:c.subUnitId,copyType:c.copyType,copyId:t});return c.copyType===Xe.CUT&&(Ln.del(t),this._copyMarkId&&this._markSelectionService.removeShape(this._copyMarkId),this._copyMarkId=null),C}_pasteUSM(t,n,o,r){const{rowProperties:s,colProperties:l,cellMatrix:c}=t,{unitId:d,subUnitId:u,pastedRange:h}=n,{startColumn:m,endColumn:S}=h,g=S-m+1,_=this._clipboardHooks,I=[];if(_.some(x=>{var D;return I.push(x)&&((D=x.onBeforePaste)==null?void 0:D.call(x,d,u,h))===!1}))return I.forEach(x=>{var D;return(D=x.onAfterPaste)==null?void 0:D.call(x,!1)}),!1;if(!c)return!1;const b=r?{copyRange:r.range,copyType:r.copyType,unitId:r.unitId,subUnitId:r.subUnitId}:{copyType:Xe.COPY},M=[],T=[];_.filter(x=>!x.specialPasteInfo&&x.hookName!==le.DEFAULT_PASTE||o===x.hookName).forEach(x=>{var N,B,A;if(s){const H=(N=x.onPasteRows)==null?void 0:N.call(x,h,s,o);H&&(M.push(...H.redos),T.push(...H.undos))}const D=(B=x.onPasteColumns)==null?void 0:B.call(x,h,l||new Array(g).map(()=>({})),o);D&&(M.push(...D.redos),T.push(...D.undos));const U=(A=x.onPasteCells)==null?void 0:A.call(x,h,c,o,b);U&&(M.push(...U.redos),T.push(...U.undos))});const y=this._getSetSelectionOperation(d,u,h,c);y&&M.push(y),this._logService.log("[SheetClipboardService]","pasting mutations",{undoMutationsInfo:T,redoMutationsInfo:M});const O=M.every(x=>this._commandService.executeCommand(x.id,x.params));return O&&this._undoRedoService.pushUndoRedo({unitID:d,undoMutations:T,redoMutations:M}),O}_getSetSelectionOperation(t,n,o,r){var _;const s=(_=this._currentUniverService.getUniverSheetInstance(t))==null?void 0:_.getSheetBySheetId(n);if(!s)return null;const{startRow:l,startColumn:c}=o,d={startRow:l,endRow:l,startColumn:c,endColumn:c},u=f.getPrimaryForRange(d,s),h=r.getValue(0,0),m=(h==null?void 0:h.rowSpan)||1,S=(h==null?void 0:h.colSpan)||1;if(m>1||S>1){const I={startRow:l,endRow:l+m-1,startColumn:c,endColumn:c+S-1};u.startRow=I.startRow,u.endRow=I.endRow,u.startColumn=I.startColumn,u.endColumn=I.endColumn,u.isMerged=!0,u.isMergedMainCell=!0}const g={unitId:t,subUnitId:n,pluginName:f.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:o,primary:u,style:null}]};return{id:f.SetSelectionsOperation.id,params:g}}_getPastingTarget(){const t=this._currentUniverService.getCurrentUniverSheetInstance(),n=t.getActiveSheet(),o=this._selectionManagerService.getLast();return{unitId:t.getUnitId(),subUnitId:n.getSheetId(),selection:o}}_transformPastedData(t,n,o,r){const{startRow:s,startColumn:l,endRow:c,endColumn:d}=r,u=c-s+1,h=d-l+1,_=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getMergeData().filter(E=>a.Rectangle.intersects({startRow:s,startColumn:l,endRow:c,endColumn:d},E)),I=_[0];let C=0,b=0,M=0,T=0;if(I&&(C=I.startRow,b=I.startColumn,M=I.endRow,T=I.endColumn),u%t===0&&h%n===0)if(_.length>0&&(u!==t||h!==n))if(C===s&&b===l&&M===c&&T===d)if(Cs(o))for(let y=0;y<u;y++)for(let O=0;O<h;O++){const x=o.getValue(y%t,O%n);x&&o.setValue(y,O,x)}else o.forValue((y,O,x)=>{x.s=null,delete x.colSpan,delete x.rowSpan});else for(let E=0;E<u;E++)for(let y=0;y<h;y++){const O=o.getValue(E%t,y%n);O&&o.setValue(E,y,O)}else for(let E=0;E<u;E++)for(let y=0;y<h;y++){const O=o.getValue(E%t,y%n);O&&o.setValue(E,y,O)}else if(_.length>0)if(this._topLeftCellsMatch(t,n,r))r.endRow=s+t-1,r.endColumn=l+n-1;else{if(c>I.endRow||d>I.endColumn)return alert("We can't do that to a merged cell "),null;o.forValue((y,O,x)=>{x.s=null,delete x.colSpan,delete x.rowSpan})}else r.endRow=s+t-1,r.endColumn=l+n-1;return r}_topLeftCellsMatch(t,n,o){const s=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet(),{startRow:l,startColumn:c,endRow:d,endColumn:u}=o,h=ps(l+t-1,c,c+t-1,s),m=vs(c+n-1,l,l+t-1,s);return!h&&!m}};exports.SheetClipboardService=Ss([He(0,a.ILogService),He(1,a.IUniverInstanceService),He(2,P.Inject(f.SelectionManagerService)),He(3,R.IClipboardInterfaceService),He(4,a.IUndoRedoService),He(5,a.ICommandService),He(6,At),He(7,P.Inject(exports.SheetSkeletonManagerService))],exports.SheetClipboardService);function _s(i){let e="";return i.forRow((t,n)=>{const o=[];n.forEach(r=>{const s=i.getValue(t,r);if(s){const l=gs(s);o.push(l)}}),e+=o.join(" "),t!==i.getLength()-1&&(e+=`
6
- `)}),e}function gs(i){const e=i.v;return fs((e==null?void 0:e.toString())||"")}const fs=i=>i.replace(/&/g,"&amp;").replace(/\ufeff/g,"").replace(/</g,"&lt;").replace(/>/g,"&gt;");function ps(i,e,t,n){return n.getMergeData().some(o=>o.startRow<=i&&i<o.endRow&&e<=o.startColumn&&o.startColumn<=t)}function vs(i,e,t,n){return n.getMergeData().some(o=>o.startColumn<=i&&i<o.endColumn&&e<=o.startRow&&o.startRow<=t)}function Cs(i){let e=0;return i.forValue((t,n,o)=>{if(o&&e++,e>1)return!1}),e>1}function Bi(){return{p:null,v:null,s:null,f:null,si:null,t:null}}const wo={id:R.CopyCommand.id,name:"sheet.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:1e3,preconditions:Z,handler:async i=>i.get(lt).copy()},Is={id:R.CutCommand.id,name:"sheet.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:1e3,preconditions:Z,handler:async i=>i.get(lt).cut()},at={id:R.PasteCommand.id,type:a.CommandType.COMMAND,multi:!0,name:"sheet.command.paste",priority:1e3,preconditions:Z,handler:async(i,e)=>{const t=i.get(a.ILogService);if(t.log("[SheetPasteCommand]","the focusing element is",document.activeElement),!document.execCommand("paste")){t.log("[SheetPasteCommand]","failed to execute paste command on the activeElement, trying to use clipboard API.");const r=await i.get(R.IClipboardInterfaceService).read(),s=i.get(lt);return r.length!==0?s.paste(r[0],e==null?void 0:e.value):!1}return!1}},To={id:"sheet.command.paste-value",type:a.CommandType.COMMAND,handler:async i=>i.get(a.ICommandService).executeCommand(at.id,{value:le.SPECIAL_PASTE_VALUE})},Eo={id:"sheet.command.paste-format",type:a.CommandType.COMMAND,handler:async i=>i.get(a.ICommandService).executeCommand(at.id,{value:le.SPECIAL_PASTE_FORMAT})},yo={id:"sheet.command.paste-col-width",type:a.CommandType.COMMAND,handler:async i=>i.get(a.ICommandService).executeCommand(at.id,{value:le.SPECIAL_PASTE_COL_WIDTH})},Oo={id:"sheet.command.paste-besides-border",type:a.CommandType.COMMAND,handler:async i=>i.get(a.ICommandService).executeCommand(at.id,{value:le.SPECIAL_PASTE_BESIDES_BORDER})};function Le(i,e,t,n,o=!0,r=1,s=!0){let l={...i};n==null&&(n={startRow:0,endRow:t.getRowCount()-1,startColumn:0,endColumn:t.getColumnCount()-1});let c;switch(e){case a.Direction.UP:for(c=i.startRow-r;c>-1&&!t.getRowVisible(c);)c-=1;c>=n.startRow?(l.startRow=c,l.endRow=c):s&&(l.startRow=n.endRow,l.endRow=n.endRow,o&&(l=Le(l,a.Direction.LEFT,t,n,!1)));break;case a.Direction.DOWN:for(c=i.endRow+r;c<t.getRowCount()&&!t.getRowVisible(c);)c+=1;c<=n.endRow?(l.startRow=c,l.endRow=c):s&&(l.startRow=n.startRow,l.endRow=n.startRow,o&&(l=Le(l,a.Direction.RIGHT,t,n,!1)));break;case a.Direction.LEFT:for(c=i.startColumn-r;c>-1&&!t.getColVisible(c);)c-=1;c>=n.startColumn?(l.startColumn=c,l.endColumn=c):s&&(l.startColumn=n.endColumn,l.endColumn=n.endColumn,o&&(l=Le(l,a.Direction.UP,t,n,!1)));break;case a.Direction.RIGHT:for(c=i.endColumn+r;c<t.getColumnCount()&&!t.getColVisible(c);)c+=1;c<=n.endColumn?(l.startColumn=c,l.endColumn=c):s&&(l.startColumn=n.startColumn,l.endColumn=n.startColumn,o&&(l=Le(l,a.Direction.DOWN,t,n,!1)));break}return l}function mi(i,e,t){const n={...i},{startRow:o,startColumn:r,endRow:s,endColumn:l}=yt(i,e,t);let c=St(t,o,r,s,l).hasValue,d=!0,u=!0;for(;u;){if(a.Direction.UP===e){let h=n.startRow-1;for(;h>-1&&!t.getRowVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:m,matrix:S}=St(t,h,n.startColumn,h,n.endColumn);if(c&&!m&&!d){u=!1;break}else{if(S.getLength()!==0){let g=h;S.forValue(_=>{g=Math.min(_,g)}),n.startRow=g}else n.startRow=h;if(n.endRow=n.startRow,!c&&m){u=!1;break}c=m,d=!1}}if(a.Direction.DOWN===e){let h=n.endRow+1;for(;h<t.getRowCount()&&!t.getRowVisible(h);)h+=1;if(h===t.getRowCount()){u=!1;break}const{hasValue:m,matrix:S}=St(t,h,n.startColumn,h,n.endColumn);if(c&&!m&&!d){u=!1;break}else{if(S.getLength()!==0){let g=h;S.forValue((_,I,C)=>{g=Math.max(_+(C.rowSpan||1)-1,g)}),n.endRow=g}else n.endRow=h;if(n.startRow=n.endRow,!c&&m){u=!1;break}c=m,d=!1}}if(a.Direction.LEFT===e){let h=n.startColumn-1;for(;h>-1&&!t.getColVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:m,matrix:S}=St(t,n.startRow,h,n.endRow,h);if(c&&!m&&!d){u=!1;break}else{if(S.getLength()!==0){let g=h;S.forValue((_,I)=>{g=Math.min(I,g)}),n.startColumn=g}else n.startColumn=h;if(n.endColumn=n.startColumn,!c&&m){u=!1;break}c=m,d=!1}}if(a.Direction.RIGHT===e){let h=n.endColumn+1;for(;h<t.getColumnCount()&&!t.getColVisible(h);)h+=1;if(h===t.getColumnCount()){u=!1;break}const{hasValue:m,matrix:S}=St(t,n.startRow,h,n.endRow,h);if(c&&!m&&!d){u=!1;break}else{if(S.getLength()!==0){let g=h;S.forValue((_,I,C)=>{g=Math.max(I+(C.colSpan||1)-1,g)}),n.endColumn=g}else n.endColumn=h;if(n.startColumn=n.endColumn,!c&&m){u=!1;break}c=m,d=!1}}}return f.alignToMergedCellsBorders(n,t,!0)}function xo(i,e,t){return Le(i,e,t,void 0,!1,1,!1)}function Rs(i,e,t){const n=mi(i,e,t);return f.alignToMergedCellsBorders(a.Rectangle.union(n,i),t,!0)}function bs(i,e,t){const n=xo(i,e,t),o={startRow:Math.min(i.startRow,n.startRow),startColumn:Math.min(i.startColumn,n.startColumn),endRow:Math.max(i.endRow,n.endRow),endColumn:Math.max(i.endColumn,n.endColumn)};return f.alignToMergedCellsBorders(a.Rectangle.union(i,o),t)}function Ms(i,e,t,n){const o=a.getReverseDirection(t),r=mi(yt(i,o,n),t,n);return t===a.Direction.UP&&r.startRow<=i.startRow?f.alignToMergedCellsBorders({...e,startColumn:i.startColumn,endColumn:i.endColumn},n,!0):t===a.Direction.DOWN&&r.endRow>=i.endRow?f.alignToMergedCellsBorders({...e,startColumn:i.startColumn,endColumn:i.endColumn},n,!0):t===a.Direction.LEFT&&r.startColumn<=i.startColumn?f.alignToMergedCellsBorders({...e,startRow:i.startRow,endRow:i.endRow},n,!0):t===a.Direction.RIGHT&&r.endColumn>=i.endColumn?f.alignToMergedCellsBorders({...e,startRow:i.startRow,endRow:i.endRow},n,!0):a.Rectangle.union(a.Rectangle.clone(e),r)}function ws(i,e,t){const n=a.getReverseDirection(e),o=yt(i,n,t),r=yt(i,e,t),s=xo(o,e,t);return f.alignToMergedCellsBorders(a.Rectangle.union(r,s),t,!1)}function Ts(i,e,t){const{left:n,right:o,up:r,down:s}=e,l=t.getMaxRows(),c=t.getMaxColumns();let d=!0;const u={...i};for(;d;){if(d=!1,r&&u.startRow!==0){const h=u.startRow-1;t.getMatrixWithMergedCells(h,u.startColumn,h,u.endColumn).forValue((S,g,_)=>{_.v&&(u.startRow=Math.min(S,u.startRow),u.startColumn=Math.min(g,u.startColumn),u.endColumn=Math.max(g,u.endColumn),d=!0)})}if(s&&u.endRow!==l-1){const h=u.endRow+1;t.getMatrixWithMergedCells(h,u.startColumn,h,u.endColumn).forValue((S,g,_)=>{_.v&&(u.endRow=Math.max(S+(_.rowSpan!==void 0?_.rowSpan-1:0),u.endRow),u.startColumn=Math.min(g,u.startColumn),u.endColumn=Math.max(g,u.endColumn),d=!0)})}if(n&&u.startColumn!==0){const h=u.startColumn-1;t.getMatrixWithMergedCells(u.startRow,h,u.endRow,h).forValue((S,g,_)=>{_.v&&(u.startColumn=Math.min(g,u.startColumn),u.startRow=Math.min(S,u.startRow),u.endRow=Math.max(S,u.endRow),d=!0)})}if(o&&u.endColumn!==c-1){const h=u.endColumn+1;t.getMatrixWithMergedCells(u.startRow,h,u.endRow,h).forValue((S,g,_)=>{_.v&&(u.endColumn=Math.max(g+(_.colSpan!==void 0?_.colSpan-1:0),u.endColumn),u.startRow=Math.min(S,u.startRow),u.endRow=Math.max(S,u.endRow),d=!0)})}}return u}function Vi(i){return{startRow:0,startColumn:0,endRow:i.getRowCount()-1,endColumn:i.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL}}function yt(i,e,t){let n;switch(e){case a.Direction.UP:n={startRow:i.startRow,startColumn:i.startColumn,endRow:i.startRow,endColumn:i.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.DOWN:n={startRow:i.endRow,startColumn:i.startColumn,endRow:i.endRow,endColumn:i.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.LEFT:n={startRow:i.startRow,startColumn:i.startColumn,endRow:i.endRow,endColumn:i.startColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.RIGHT:n={startRow:i.startRow,startColumn:i.endColumn,endRow:i.endRow,endColumn:i.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;default:throw new Error("Invalid direction")}return f.alignToMergedCellsBorders(n,t,!1)}function St(i,e,t,n,o){let r=!1;const s=i.getMatrixWithMergedCells(e,t,n,o).forValue((l,c,d)=>{if(d.v)return r=!0,!1});return{hasValue:r,matrix:s}}function Jn(i,e,t){const n=a.Rectangle.clone(i);if(e==null)return n;switch(t){case a.Direction.UP:case a.Direction.DOWN:n.startColumn=n.endColumn=e.actualColumn;break;case a.Direction.LEFT:case a.Direction.RIGHT:n.startRow=n.endRow=e.actualRow;break}return n}function Es(i,e,t){const{primary:n,range:o}=i,r=a.Rectangle.clone(o);switch(e){case a.Direction.UP:case a.Direction.DOWN:r.startRow=n.startRow,r.endRow=n.endRow;break;case a.Direction.LEFT:case a.Direction.RIGHT:r.startColumn=n.startColumn,r.endColumn=n.endColumn;break}const s=yt(r,e,t);switch(e){case a.Direction.DOWN:return o.startRow<s.startRow;case a.Direction.UP:return o.endRow>s.endRow;case a.Direction.LEFT:return s.endColumn<o.endColumn;case a.Direction.RIGHT:return s.startColumn>o.startColumn}}var be=(i=>(i[i.moveStopeOne=0]="moveStopeOne",i[i.moveGap=1]="moveGap",i[i.moveStepPage=2]="moveStepPage",i[i.moveStepEnd=3]="moveStepEnd",i))(be||{});const me={id:"sheet.command.move-selection",type:a.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const t=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance(),n=t.getActiveSheet(),o=i.get(f.SelectionManagerService).getLast();if(!o)return!1;const{direction:r,jumpOver:s}=e,{range:l,primary:c}=o,d=Jn(l,c,r),u=s===1?mi(d,r,n):Le(d,r,n),h=f.getCellAtRowCol(u.startRow,u.startColumn,n);return a.Rectangle.equals(h,d)?!1:(i.get(R.ShortcutExperienceService).remove({unitId:t.getUnitId(),sheetId:n.getSheetId(),keycode:R.KeyCode.TAB}),i.get(a.ICommandService).executeCommand(f.SetSelectionsOperation.id,{unitId:t.getUnitId(),sheetId:n.getSheetId(),pluginName:f.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:a.Rectangle.clone(h),primary:{startRow:h.startRow,startColumn:h.startColumn,endRow:h.endRow,endColumn:h.endColumn,actualRow:u.startRow,actualColumn:u.startColumn,isMerged:h.isMerged,isMergedMainCell:h.startRow===u.startRow&&h.startColumn===u.startColumn}}]}))}},Ke={id:"sheet.command.move-selection-enter-tab",type:a.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const t=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance(),n=t.getActiveSheet(),o=i.get(f.SelectionManagerService).getLast(),r=t.getUnitId(),s=n.getSheetId();if(!o)return!1;const{direction:l,keycode:c}=e,{range:d,primary:u}=o;let h=Jn(d,u,l);const m=i.get(R.ShortcutExperienceService),S=m.getCurrentBySearch({unitId:r,sheetId:s,keycode:R.KeyCode.TAB});let g;const{startRow:_,endRow:I,startColumn:C,endColumn:b}=d;if(a.Rectangle.equals(d,u)){if(c===R.KeyCode.TAB)S==null&&m.addOrUpdate({unitId:r,sheetId:s,keycode:R.KeyCode.TAB,selection:o});else{const E=S==null?void 0:S.selection;if(E!=null){const{range:y,primary:O}=E;h=Jn(y,O,l)}m.remove({unitId:r,sheetId:s,keycode:R.KeyCode.TAB})}const M=Le(h,l,n),T=f.getCellAtRowCol(M.startRow,M.startColumn,n);if(a.Rectangle.equals(T,h))return!1;g={range:a.Rectangle.clone(T),primary:{startRow:T.startRow,startColumn:T.startColumn,endRow:T.endRow,endColumn:T.endColumn,actualRow:M.startRow,actualColumn:M.startColumn,isMerged:T.isMerged,isMergedMainCell:T.startRow===M.startRow&&T.startColumn===M.startColumn}}}else{m.remove({unitId:r,sheetId:s,keycode:R.KeyCode.TAB});const M=a.Tools.deepClone(u),T=Le({startRow:M.startRow,startColumn:M.startColumn,endRow:M.endRow,endColumn:M.endColumn},l,n,{startRow:_,endRow:I,startColumn:C,endColumn:b}),E=f.getCellAtRowCol(T.startRow,T.startColumn,n);g={range:a.Rectangle.clone(d),primary:{startRow:E.startRow,startColumn:E.startColumn,endRow:E.endRow,endColumn:E.endColumn,actualRow:T.startRow,actualColumn:T.startColumn,isMerged:E.isMerged,isMergedMainCell:E.startRow===T.startRow&&E.startColumn===T.startColumn}}}return i.get(a.ICommandService).executeCommand(f.SetSelectionsOperation.id,{unitId:r,sheetId:s,pluginName:f.NORMAL_SELECTION_PLUGIN_NAME,selections:[g]})}},Me={id:"sheet.command.expand-selection",type:a.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const t=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance(),n=t.getActiveSheet(),o=i.get(f.SelectionManagerService).getLast();if(!o)return!1;const{range:r,primary:s}=o,{jumpOver:l,direction:c}=e,u=Es(o,c,n)?l===1?Ms(r,{...a.Rectangle.clone(s),rangeType:a.RANGE_TYPE.NORMAL},c,n):ws(r,c,n):l===1?Rs(r,c,n):bs(r,c,n);return a.Rectangle.equals(u,r)?!1:i.get(a.ICommandService).executeCommand(f.SetSelectionsOperation.id,{unitId:t.getUnitId(),sheetId:n.getSheetId(),pluginName:f.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:u,primary:s}]})}};let ve=[],Un="";const Ao={id:"sheet.command.select-all",type:a.CommandType.COMMAND,onDispose(){ve=[],Un=""},handler:async(i,e={expandToGapFirst:!0,loop:!1})=>{const t=i.get(f.SelectionManagerService).getLast(),n=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance(),o=n.getActiveSheet();if(!t||!o)return!1;const r=`${n.getUnitId()}|${o.getSheetId()}`;r!==Un&&(ve=[],Un=r);const s=o.getMaxRows(),l=o.getMaxColumns(),{expandToGapFirst:c,loop:d}=e,{range:u,primary:h}=t,m=u.endColumn===l-1&&u.endRow===s-1&&u.startRow===0&&u.startColumn===0;ve.some(g=>a.Rectangle.equals(g,u))||(ve=[],ve.push(u));let S;if(m)if(d){if(ve.findIndex(_=>a.Rectangle.equals(_,u))!==ve.length-1)return!1;S=ve[0]}else return!1;else c?(S=Ts(u,{left:!0,right:!0,up:!0,down:!0},o),a.Rectangle.equals(S,u)&&(S=Vi(o))):S=Vi(o);return ve.some(g=>a.Rectangle.equals(g,S))||ve.push(S),i.get(a.ICommandService).executeCommand(f.SetSelectionsOperation.id,{unitId:n.getUnitId(),sheetId:o.getSheetId(),pluginName:f.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:S,primary:h}]})}},ys=a.createInterceptorKey("BEFORE_CELL_EDIT"),Os=a.createInterceptorKey("AFTER_CELL_EDIT");class Ho extends a.Disposable{constructor(){super();v(this,"_state",null);v(this,"_isForceKeepVisible",!1);v(this,"_editorIsDirty",!1);v(this,"_visible",{visible:!1,eventType:w.DeviceInputEventType.Dblclick});v(this,"_state$",new k.BehaviorSubject(null));v(this,"state$",this._state$.asObservable());v(this,"_visible$",new k.BehaviorSubject(this._visible));v(this,"visible$",this._visible$.asObservable());v(this,"_afterVisible$",new k.BehaviorSubject(this._visible));v(this,"afterVisible$",this._afterVisible$.asObservable());v(this,"interceptor",new a.InterceptorManager({BEFORE_CELL_EDIT:ys,AFTER_CELL_EDIT:Os}));this.disposeWithMe(a.toDisposable(()=>{this._state$.complete(),this._state=null})),this.disposeWithMe(a.toDisposable(this.interceptor.intercept(this.interceptor.getInterceptPoints().AFTER_CELL_EDIT,{priority:-1,handler:t=>t}))),this.disposeWithMe(a.toDisposable(this.interceptor.intercept(this.interceptor.getInterceptPoints().BEFORE_CELL_EDIT,{priority:-1,handler:t=>t})))}setState(t){this._state=t,this._state$.next(t)}getState(){return this._state}getCurrentEditorId(){var t;return(t=this._state)==null?void 0:t.editorUnitId}changeVisible(t){this._visible=t,t.visible&&(this._editorIsDirty=!1),this._visible$.next(this._visible),this._afterVisible$.next(this._visible)}isVisible(){return this._visible}enableForceKeepVisible(){this._isForceKeepVisible=!0}disableForceKeepVisible(){this._isForceKeepVisible=!1}isForceKeepVisible(){return this._isForceKeepVisible}changeEditorDirty(t){this._editorIsDirty=t}getEditorDirty(){return this._editorIsDirty}}const pe=P.createIdentifier("univer.sheet-editor-bridge.service"),Re={id:"sheet.operation.set-cell-edit-visible",type:a.CommandType.OPERATION,handler:(i,e)=>{const t=i.get(pe);return e==null?!1:(t.changeVisible(e),!0)}},Ot={id:"sheet.operation.set-cell-edit-visible-arrow",type:a.CommandType.OPERATION,handler:()=>!0};class ke{constructor(){v(this,"_scrollInfo",new Map);v(this,"_currentScroll",null);v(this,"_scrollInfo$",new k.BehaviorSubject(null));v(this,"scrollInfo$",this._scrollInfo$.asObservable())}dispose(){this._scrollInfo$.complete()}setCurrentScroll(e){this._currentScroll=e,this._refresh(e)}getScrollByParam(e){return this._getCurrentScroll(e)}getCurrentScroll(){return this._getCurrentScroll(this._currentScroll)}addOrReplace(e){this._currentScroll!=null&&this._addByParam({...this._currentScroll,...e})}addOrReplaceNoRefresh(e){this._currentScroll!=null&&this._addByParam({...this._currentScroll,...e},!1)}addOrReplaceByParam(e){this._addByParam(e)}clear(){this._currentScroll!=null&&this._clearByParam(this._currentScroll)}_addByParam(e,t=!0){const{unitId:n,sheetId:o,sheetViewStartColumn:r,sheetViewStartRow:s,offsetX:l,offsetY:c}=e;this._scrollInfo.has(n)||this._scrollInfo.set(n,new Map),this._scrollInfo.get(n).set(o,{sheetViewStartRow:s,sheetViewStartColumn:r,offsetX:l,offsetY:c}),t===!0&&this._refresh({unitId:n,sheetId:o})}_clearByParam(e){this._addByParam({...e,sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0}),this._refresh(e)}_getCurrentScroll(e){var o;if(e==null)return;const{unitId:t,sheetId:n}=e;return(o=this._scrollInfo.get(t))==null?void 0:o.get(n)}_refresh(e){this._scrollInfo$.next(this._getCurrentScroll(e))}}const ct={id:"sheet.operation.set-scroll",type:a.CommandType.OPERATION,handler:(i,e)=>{if(!e)return!1;const t=i.get(ke),r=i.get(a.IUniverInstanceService).getUniverSheetInstance(e.unitId).getSheetBySheetId(e.sheetId),{xSplit:s,ySplit:l}=r.getConfig().freeze;return t.addOrReplaceByParam({...e,sheetViewStartRow:e.sheetViewStartRow-l,sheetViewStartColumn:e.sheetViewStartColumn-s}),!0}},On={id:"sheet.operation.set-editor-resize",type:a.CommandType.OPERATION,handler:(i,e)=>!0},xe={id:"sheet.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(i,e)=>{const t=i.get(a.IUniverInstanceService).getUniverSheetInstance(e.unitId);if(!t)return!1;const n=t.getSheetBySheetId(e.subUnitId);return n?(n.getConfig().zoomRatio=e.zoomRatio,!0):!1}};var oe=(i=>(i.MAIN="__SpreadsheetRender__",i.ROW="__SpreadsheetRowHeader__",i.COLUMN="__SpreadsheetColumnHeader__",i.LEFT_TOP="__SpreadsheetLeftTopPlaceholder__",i))(oe||{}),Y=(i=>(i.VIEW_MAIN="viewMain",i.VIEW_MAIN_LEFT_TOP="viewMainLeftTop",i.VIEW_MAIN_TOP="viewMainTop",i.VIEW_MAIN_LEFT="viewMainLeft",i.VIEW_ROW_TOP="viewRowTop",i.VIEW_ROW_BOTTOM="viewRowBottom",i.VIEW_COLUMN_LEFT="viewColumnLeft",i.VIEW_COLUMN_RIGHT="viewColumnRight",i.VIEW_LEFT_TOP="viewLeftTop",i))(Y||{});const Fi=0,Ue=2,Qn=[10,400],ji=1001;var Do={exports:{}},xn={};/**
1
+ "use strict";var Xr=Object.defineProperty;var Yr=(i,e,t)=>e in i?Xr(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var v=(i,e,t)=>(Yr(i,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),_=require("@univerjs/sheets"),I=require("@univerjs/ui"),D=require("@wendellhu/redi"),H=require("rxjs"),b=require("@univerjs/engine-render"),P=require("react"),Se=require("@univerjs/design"),K=require("@wendellhu/redi/react-bindings"),J=require("@univerjs/docs"),Ao=require("rxjs/operators"),te=require("@univerjs/engine-formula"),Bt=require("clsx"),Zr=require("@univerjs/engine-numfmt"),Do={InsertRow:!0,InsertColumn:!0,AddRowTop:!1,AddRowBottom:!1,AddColumnLeft:!1,AddColumnRight:!1,DeleteRow:!0,DeleteColumn:!0,HideRow:!1,ShowRow:!1,RowHeight:!1,HideColumn:!1,ShowColumn:!1,ColumnWidth:!1,DeleteCell:!0,ClearContent:!0,Matrix:!1},No={undo:!0,redo:!0,paintFormat:!0,currencyFormat:!0,percentageFormat:!0,numberDecrease:!0,numberIncrease:!0,moreFormats:!0,font:!0,fontSize:!0,bold:!0,italic:!0,strikethrough:!0,underline:!0,textColor:!0,fillColor:!0,border:!0,horizontalAlignMode:!0,verticalAlignMode:!0,textWrapMode:!0,textRotateMode:!0,mergeCell:!0},Po={outerLeft:!1,outerRight:!1,header:!0,footer:!0,innerLeft:!1,innerRight:!1,frozenHeaderLT:!1,frozenHeaderRT:!1,frozenHeaderLM:!1,frozenContent:!1,infoBar:!0,toolbar:!0,formulaBar:!0,rightMenu:!0,countBar:!0,sheetBar:!0},Gr={layout:{sheetContainerConfig:Po,rightMenuConfig:Do,toolbarConfig:No}},Ho="SheetUI";function Wn(i,e){if(i==null)return;const t=e.getRenderById(i);if(t==null)return;const{mainComponent:n,scene:o,engine:r}=t;return{document:n,scene:o,engine:r}}const mi={零:0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9},Hn=["零","一","二","三","四","五","六","七","八","九"],Xi=["","万","亿","万亿","亿亿"],Kr=["","十","百","千"],Lo={十:{value:10,secUnit:!1},百:{value:100,secUnit:!1},千:{value:1e3,secUnit:!1},万:{value:1e4,secUnit:!0},亿:{value:1e8,secUnit:!0}};function Fe(i){if(!i)return 0;let e=0,t=0,n=0,o=!1;const r=i.split("");for(let s=0;s<r.length;s++){const a=mi[r[s]];if(typeof a<"u")n=a,s===r.length-1&&(t+=n);else{const c=Lo[r[s]],d=c.value;o=c.secUnit,o?(t=(t+n)*d,e+=t,t=0):t+=n*d,n=0}}return e+t}function qr(i){let e="",t="",n=0,o=!0;for(;i>0;){const r=i%10;r===0?o||(o=!0,t=Hn[r]+t):(o=!1,e=Hn[r],e+=Kr[n],t=e+t),n++,i=Math.floor(i/10)}return t}function Jr(i){let e=0,t="",n="",o=!1;if(i===0)return Hn[0];for(;i>0;){const r=i%1e4;o&&(n=Hn[0]+n),t=qr(r),t+=r!==0?Xi[e]:Xi[0],n=t+n,o=r<1e3&&r>0,i=Math.floor(i/1e4),e++}return n}function Qr(i){if(!i)return!1;let e=!0;if(i)if(i.length===1)i==="日"||i in mi?e=!0:e=!1;else{const t=i.split("");for(let n=0;n<t.length;n++)if(!(t[n]in mi||t[n]in Lo)){e=!1;break}}return e}function Qt(i){if(!i)return{isExtendNumber:!1};const e=/0|([1-9]+[0-9]*)/g,t=e.test(i);if(t){const n=i.match(e);if(n&&n.length>0){const o=n[n.length-1],r=i.lastIndexOf(o),s=i.substr(0,r),a=i.substr(r+o.length);return{isExtendNumber:!0,matchTxt:Number(o),beforeTxt:s,afterTxt:a}}return{isExtendNumber:!1}}return{isExtendNumber:t}}function es(i){let e;return i.length===2&&(i==="周一"||i==="周二"||i==="周三"||i==="周四"||i==="周五"||i==="周六"||i==="周日")?e=!0:e=!1,e}function ts(i){let e;return i.length===3&&(i==="星期一"||i==="星期二"||i==="星期三"||i==="星期四"||i==="星期五"||i==="星期六"||i==="星期日")?e=!0:e=!1,e}function ns(i,e){let t=0;for(let n=0;n<i.length&&i[n]<e;n++)t++;return t}function zt(i){let e=!0;const t=i[1]-i[0];for(let n=1;n<i.length;n++)if(i[n]-i[n-1]!==t){e=!1;break}return e}function is(i,e,t){const n=[],o=Math.floor(e/i),r=e%i;let s=0;if(o>0){for(let a=0;a<o;a++)for(let c=0;c<t.length;c++)n[t[c]+a*i]=s,s++;for(let a=0;a<t.length&&t[a]<r;a++)n[t[a]+i*o]=s,s++}else for(let a=0;a<t.length&&t[a]<r;a++)n[t[a]]=s,s++;return n}function st(i,e){const t=[];for(let n=1;n<=e;n++){const o=(n-1)%i.length,r=l.Tools.deepClone(i[o]);t.push({v:null,s:null,p:null,f:null,si:null,t:null,...r})}return t}function os(i,e){var n;const t=[];for(let o=1;o<=e;o++){const r=(o-1)%i.length,s={s:(n=i[r])==null?void 0:n.s};t.push(s)}return t}function rs(i){let e=!0;const t=i[1]/i[0];for(let n=1;n<i.length;n++)if(i[n]/i[n-1]!==t){e=!1;break}return e}function ss(i){const e=[];for(let t=1;t<=i;t++)e.push(t);return e}function Yi(i,e,t){var r,s,a,c;const n=[],o=[];for(let d=0;d<i.length;d++)o.push(Number((r=i[d])==null?void 0:r.v));if(i.length>2&&rs(o))for(let d=1;d<=e;d++){const u=(d-1)%i.length,h=l.Tools.deepClone(i[u]),m=Number((s=i[i.length-1])==null?void 0:s.v)*(Number((a=i[1])==null?void 0:a.v)/Number((c=i[0])==null?void 0:c.v))**d;h&&(h.v=m,n.push(h))}else{const d=ss(i.length);for(let u=1;u<=e;u++){const h=(u-1)%i.length,m=l.Tools.deepClone(i[h]),g=t===(l.Direction.DOWN||t===l.Direction.RIGHT),S=as(i.length+u,o,d,g);m&&(m.v=S,n.push(m))}}return n}function as(i,e,t,n=!0){function o(h){let m=0;for(let g=0;g<h.length;g++)m+=h[g];return m/h.length}const r=o(t),s=o(e);let a=0,c=0;for(let h=0;h<t.length;h++)a+=(t[h]-r)*(e[h]-s),c+=(t[h]-r)*(t[h]-r);let d;c===0?d=n?1:-1:d=a/c;const u=s-d*r;return Math.round((u+d*i)*1e5)/1e5}function Zi(i,e,t){var r;const n=[],o=/0|([1-9]+[0-9]*)/g;for(let s=1;s<=e;s++){const a=(s-1)%i.length,c=l.Tools.deepClone(i[a]),d=`${(r=i[i.length-1])==null?void 0:r.v}`,u=d==null?void 0:d.match(o),h=u==null?void 0:u[u.length-1],m=Math.abs(Number(h)+t*s);if(!d||!h)continue;const g=d.lastIndexOf(h),S=d.substr(0,g)+m.toString()+d.substr(g+h.length);c&&(c.v=S,n.push(c))}return n}function Rt(i,e,t,n=0){var a,c;const o=[["日","一","二","三","四","五","六"],["周日","周一","周二","周三","周四","周五","周六"],["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]];if(n>=o.length)return[];const r=o[n],s=[];for(let d=1;d<=e;d++){const u=(d-1)%i.length,h=l.Tools.deepClone(i[u]);let m=0;if(((a=i[i.length-1])==null?void 0:a.v)===r[0])m=7+t*d;else{const S=`${(c=i[i.length-1])==null?void 0:c.v}`;if(S){const f=S.substr(S.length-1,1);m=Fe(f)+t*d}}m<0&&(m=Math.ceil(Math.abs(m)/7)*7+m);const g=m%7;h&&(h.v=r[g],s.push(h))}return s}function Gi(i,e,t){var o;const n=[];for(let r=1;r<=e;r++){const s=(r-1)%i.length,a=l.Tools.deepClone(i[s]),c=`${(o=i[i.length-1])==null?void 0:o.v}`,d=Fe(c)+t*r;let u;d<=0?u="零":u=Jr(d),a&&(a.v=u,n.push(a))}return n}const Vt={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 ls(i){let e=!1;return Object.keys(Vt).forEach(t=>{Vt[t].includes(i)&&(e=!0)}),e}function Qn(i){let e="";const t=[];return Object.keys(Vt).forEach(n=>{Vt[n].includes(i)&&(e=n,t.push(...Vt[n]))}),{name:e,series:t}}function Ki(i,e,t,n){var s;const o=n.length,r=[];for(let a=1;a<=e;a++){const c=(a-1)%i.length,d=l.Tools.deepClone(i[c]),u=`${(s=i[i.length-1])==null?void 0:s.v}`;let h=n.indexOf(u)+t*a;h<0&&(h+=Math.abs(t)*o);const m=h%o;d&&(d.v=n[m],r.push(d))}return r}function cs(i,e){const t=[];let n;if(e.startRow<i.startRow)n=l.Direction.UP;else if(e.endRow>i.endRow)n=l.Direction.DOWN;else if(e.startColumn<i.startColumn)n=l.Direction.LEFT;else if(e.endColumn>i.endColumn)n=l.Direction.RIGHT;else return[];if(n===l.Direction.DOWN||n===l.Direction.UP){const o=i.endRow-i.startRow+1,r=e.endRow-e.startRow+1,s=Math.floor(r/o),a=r%o,c={startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:i.endColumn-i.startColumn};if(n===l.Direction.DOWN){for(let d=0;d<s;d++)t.push({repeatStartCell:{row:i.startRow+(d+1)*o,col:i.startColumn},relativeRange:c});a>0&&t.push({repeatStartCell:{row:i.startRow+(s+1)*o,col:i.startColumn},relativeRange:{startRow:0,startColumn:0,endRow:a-1,endColumn:i.endColumn-i.startColumn}})}else{for(let d=0;d<s;d++)t.push({repeatStartCell:{row:i.startRow-(d+1)*o,col:i.startColumn},relativeRange:c});a>0&&t.push({repeatStartCell:{row:i.startRow-(s+1)*o,col:i.startColumn},relativeRange:{startRow:o-a,endRow:o-1,startColumn:0,endColumn:i.endColumn-i.startColumn}})}}if(n===l.Direction.RIGHT||n===l.Direction.LEFT){const o=i.endColumn-i.startColumn+1,r=e.endColumn-e.startColumn+1,s=Math.floor(r/o),a=r%o,c={startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:i.endColumn-i.startColumn};if(n===l.Direction.RIGHT){for(let d=0;d<s;d++)t.push({repeatStartCell:{row:i.startRow,col:i.startColumn+(d+1)*o},relativeRange:c});a>0&&t.push({repeatStartCell:{row:i.startRow,col:i.startColumn+(s+1)*o},relativeRange:{startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:a-1}})}else{for(let d=0;d<s;d++)t.push({repeatStartCell:{row:i.startRow,col:i.startColumn-(d+1)*o},relativeRange:c});a>0&&t.push({repeatStartCell:{row:i.startRow,col:i.startColumn-(s+1)*o},relativeRange:{startRow:0,startColumn:o-a,endRow:i.endRow-i.startRow,endColumn:o-1}})}}return t}function Uo(i){const e=new l.ObjectMatrix;return i.forEach(t=>{const{startRow:n,startColumn:o,endRow:r,endColumn:s}=t;for(let a=n;a<=r;a++)for(let c=o;c<=s;c++)e.setValue(a,c,{v:null,p:null,f:null,si:null})}),e.getData()}const ko={type:l.CommandType.COMMAND,id:"sheet.command.auto-fill",handler:async(i,e)=>!0},an={id:"sheet.command.auto-clear-content",type:l.CommandType.COMMAND,handler:async(i,e)=>{const t=i.get(l.IUniverInstanceService),n=i.get(l.ICommandService),o=i.get(l.IUndoRedoService),r=t.getCurrentUniverSheetInstance(),s=r.getUnitId(),c=r.getActiveSheet().getSheetId(),{clearRange:d,selectionRange:u}=e,h={subUnitId:c,unitId:s,cellValue:Uo([d])},m=_.SetRangeValuesUndoMutationFactory(i,h);return n.executeCommand(_.SetSelectionsOperation.id,{selections:[{primary:{...u},range:{...u}}],unitId:s,subUnitId:c}),n.syncExecuteCommand(_.SetRangeValuesMutation.id,h)?(o.pushUndoRedo({unitID:s,undoMutations:[{id:_.SetRangeValuesMutation.id,params:m}],redoMutations:[{id:_.SetRangeValuesMutation.id,params:h}],undo(){return n.syncExecuteCommand(_.SetRangeValuesMutation.id,m)},redo(){return n.syncExecuteCommand(_.SetRangeValuesMutation.id,h)}}),!0):!1}};function wi(i){return i.getContextValue(l.FOCUSING_SHEET)}function ne(i){return i.getContextValue(l.FOCUSING_SHEET)&&i.getContextValue(l.FOCUSING_UNIVER_EDITOR)&&!i.getContextValue(l.EDITOR_ACTIVATED)}function Vo(i){return i.getContextValue(l.FOCUSING_SHEET)&&i.getContextValue(l.FOCUSING_UNIVER_EDITOR)&&i.getContextValue(l.EDITOR_ACTIVATED)}function ds(i){return i.getContextValue(l.EDITOR_ACTIVATED)}function Bo(i){return i.getContextValue(l.FOCUSING_FORMULA_EDITOR)&&i.getContextValue(l.FOCUSING_UNIVER_EDITOR)}function us(i){return i.getContextValue(l.FOCUSING_SHEET)&&i.getContextValue(l.EDITOR_ACTIVATED)&&i.getContextValue(l.FOCUSING_EDITOR_INPUT_FORMULA)&&i.getContextValue(l.FOCUSING_UNIVER_EDITOR)}function Ln(i){return i.getContextValue(l.FOCUSING_SHEET)&&i.getContextValue(l.EDITOR_ACTIVATED)&&!i.getContextValue(l.FOCUSING_EDITOR_INPUT_FORMULA)}var fe=(i=>(i.MAIN="__SpreadsheetRender__",i.ROW="__SpreadsheetRowHeader__",i.COLUMN="__SpreadsheetColumnHeader__",i.LEFT_TOP="__SpreadsheetLeftTopPlaceholder__",i))(fe||{}),V=(i=>(i.VIEW_MAIN="viewMain",i.VIEW_MAIN_LEFT_TOP="viewMainLeftTop",i.VIEW_MAIN_TOP="viewMainTop",i.VIEW_MAIN_LEFT="viewMainLeft",i.VIEW_ROW_TOP="viewRowTop",i.VIEW_ROW_BOTTOM="viewRowBottom",i.VIEW_COLUMN_LEFT="viewColumnLeft",i.VIEW_COLUMN_RIGHT="viewColumnRight",i.VIEW_LEFT_TOP="viewLeftTop",i))(V||{});const qi=0,qe=2,hs=3,gi=[10,400],Ji=1001;var ms=Object.defineProperty,gs=Object.getOwnPropertyDescriptor,Ss=(i,e,t,n)=>{for(var o=n>1?void 0:n?gs(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&ms(e,t,o),o},Qi=(i,e)=>(t,n)=>e(t,n,i);exports.SheetSkeletonManagerService=class{constructor(e,t){v(this,"_currentSkeleton",{unitId:"",sheetId:""});v(this,"_sheetSkeletonParam",[]);v(this,"_currentSkeleton$",new H.BehaviorSubject(null));v(this,"currentSkeleton$",this._currentSkeleton$.asObservable());v(this,"_currentSkeletonBefore$",new H.BehaviorSubject(null));v(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._currentUniverService=e,this._localeService=t}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._sheetSkeletonParam=[]}getCurrent(){return this._getCurrentBySearch(this._currentSkeleton)}setCurrent(e){const t=this._getCurrentBySearch(e);if(t!=null)this._reCalculate(t);else{const{unitId:o,sheetId:r}=e,s=this._currentUniverService.getUniverSheetInstance(e.unitId),a=s==null?void 0:s.getSheetBySheetId(e.sheetId);if(a==null||s==null)return;const c=this._buildSkeleton(a,s);this._sheetSkeletonParam.push({unitId:o,sheetId:r,skeleton:c,dirty:!1})}this._currentSkeleton=e;const n=this.getCurrent();return this._currentSkeletonBefore$.next(n),this._currentSkeleton$.next(n),this.getCurrent()}reCalculate(){const e=this.getCurrent();e!=null&&this._reCalculate(e)}_reCalculate(e){e.dirty&&(e.skeleton.makeDirty(!0),e.dirty=!1),e.skeleton.calculate()}makeDirtyCurrent(e=!0){this.makeDirty(this._currentSkeleton,e)}makeDirty(e,t=!0){const n=this._getCurrentBySearch(e);n!=null&&(n.dirty=t)}_getCurrentBySearch(e){const t=this._sheetSkeletonParam.find(n=>n.unitId===e.unitId&&n.sheetId===e.sheetId);return t!=null&&(t.commandId=e.commandId),t}_buildSkeleton(e,t){const n=e.getConfig();return b.SpreadsheetSkeleton.create(e,n,e.getCellMatrix(),t.getStyles(),this._localeService)}};exports.SheetSkeletonManagerService=Ss([Qi(0,l.IUniverInstanceService),Qi(1,D.Inject(l.LocaleService))],exports.SheetSkeletonManagerService);class _s{constructor(){v(this,"_startColumn",-1);v(this,"_startRow",-1);v(this,"_endColumn",-1);v(this,"_endRow",-1);v(this,"_startX",0);v(this,"_startY",0);v(this,"_endX",0);v(this,"_endY",0);v(this,"_currentCell");v(this,"_rangeType",l.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._currentCell}get rangeType(){return this._rangeType}isEqual(e){const{startColumn:t,startRow:n,endColumn:o,endRow:r}=this,{startColumn:s,startRow:a,endColumn:c,endRow:d}=e;return t===s&&n===a&&o===c&&r===d}isInclude(e){const{startColumn:t,startRow:n,endColumn:o,endRow:r}=this,{startColumn:s,startRow:a,endColumn:c,endRow:d}=e;return!(c<t||s>o||a>r||d<n)}highlightToSelection(){return l.makeCellToSelection(this._currentCell)}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._currentCell}getRangeType(){return this._rangeType}getValue(){return{rangeWithCoord:{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},primaryWithCoord:this._currentCell}}setValue(e,t){const{startColumn:n,startRow:o,endColumn:r,endRow:s,startX:a,startY:c,endX:d,endY:u,rangeType:h}=e;this._startColumn=n,this._startRow=o,this._endColumn=r,this._endRow=s,this._startX=a,this._startY=c,this._endX=d,this._endY=u,h!=null&&(this._rangeType=h),this.setCurrentCell(t)}setCurrentCell(e){e&&(this._currentCell=e)}clearCurrentCell(){this._currentCell=null}}const eo=.3;class Un{constructor(e,t,n=!0,o){v(this,"_leftControl");v(this,"_rightControl");v(this,"_topControl");v(this,"_bottomControl");v(this,"_backgroundControlTop");v(this,"_backgroundControlBottom");v(this,"_backgroundControlMiddleLeft");v(this,"_backgroundControlMiddleRight");v(this,"_fillControl");v(this,"_selectionShape");v(this,"_rowHeaderBackground");v(this,"_rowHeaderBorder");v(this,"_rowHeaderGroup");v(this,"_rowHeaderHighlight");v(this,"_columnHeaderBackground");v(this,"_columnHeaderBorder");v(this,"_columnHeaderGroup");v(this,"_columnHeaderHighlight");v(this,"_topLeftWidget");v(this,"_topCenterWidget");v(this,"_topRightWidget");v(this,"_middleLeftWidget");v(this,"_middleRightWidget");v(this,"_bottomLeftWidget");v(this,"_bottomCenterWidget");v(this,"_bottomRightWidget");v(this,"_dashRect");v(this,"_selectionModel");v(this,"_selectionStyle");v(this,"_rowHeaderWidth",0);v(this,"_columnHeaderHeight",0);v(this,"_widgetRects",[]);v(this,"_dispose$",new H.BehaviorSubject(this));v(this,"dispose$",this._dispose$.asObservable());v(this,"selectionMoving$",new H.Subject);v(this,"selectionMoved$",new H.Subject);v(this,"selectionScaling$",new H.Subject);v(this,"selectionScaled$",new H.Subject);v(this,"selectionFilling$",new H.Subject);v(this,"_selectionFilled$",new H.Subject);v(this,"selectionFilled$",this._selectionFilled$.asObservable());v(this,"_defaultStyle");v(this,"_isHelperSelection",!0);this._scene=e,this._zIndex=t,this._isHeaderHighlight=n,this._themeService=o,this._initialize()}get zIndex(){return this._zIndex}get leftControl(){return this._leftControl}get rightControl(){return this._rightControl}get topControl(){return this._topControl}get bottomControl(){return this._bottomControl}get fillControl(){return this._fillControl}get backgroundControlTop(){return this._backgroundControlTop}get backgroundControlBottom(){return this._backgroundControlBottom}get backgroundControlMiddleLeft(){return this._backgroundControlMiddleLeft}get backgroundControlMiddleRight(){return this._backgroundControlMiddleRight}get selectionShape(){return this._selectionShape}get model(){return this._selectionModel}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 selectionStyle(){return this._selectionStyle}get dashRect(){return this._dashRect}get isHelperSelection(){return this._isHelperSelection}setEvent(e){this.leftControl.evented=e,this.rightControl.evented=e,this.topControl.evented=e,this.bottomControl.evented=e}enableHeaderHighlight(){this._isHelperSelection=!0}disableHeaderHighlight(){this._isHeaderHighlight=!1}refreshSelectionFilled(e){this._selectionFilled$.next(e)}updateStyle(e){this._updateControl(e,this._rowHeaderWidth,this._columnHeaderHeight)}update(e,t=0,n=0,o,r){this._selectionModel.setValue(e,r),o==null&&(o=this._selectionStyle),this._updateControl(o,t,n)}clearHighlight(){this._selectionModel.clearCurrentCell(),this._updateControl(this._selectionStyle,this._rowHeaderWidth,this._columnHeaderHeight)}getScene(){return this._scene}dispose(){var e,t,n,o,r,s,a,c,d,u,h,m,g,S,f,C,R,M,T,w,E,y,x,O,A;(e=this._leftControl)==null||e.dispose(),(t=this._rightControl)==null||t.dispose(),(n=this._topControl)==null||n.dispose(),(o=this._bottomControl)==null||o.dispose(),(r=this._backgroundControlTop)==null||r.dispose(),(s=this._backgroundControlMiddleLeft)==null||s.dispose(),(a=this._backgroundControlMiddleRight)==null||a.dispose(),(c=this._backgroundControlBottom)==null||c.dispose(),(d=this._fillControl)==null||d.dispose(),(u=this._selectionShape)==null||u.dispose(),(h=this._rowHeaderBackground)==null||h.dispose(),(m=this._rowHeaderBorder)==null||m.dispose(),(g=this._rowHeaderGroup)==null||g.dispose(),(S=this._rowHeaderBackground)==null||S.dispose(),(f=this._columnHeaderBackground)==null||f.dispose(),(C=this._columnHeaderBorder)==null||C.dispose(),(R=this._columnHeaderGroup)==null||R.dispose(),(M=this._topLeftWidget)==null||M.dispose(),(T=this._topCenterWidget)==null||T.dispose(),(w=this._topRightWidget)==null||w.dispose(),(E=this._middleLeftWidget)==null||E.dispose(),(y=this._middleRightWidget)==null||y.dispose(),(x=this._bottomLeftWidget)==null||x.dispose(),(O=this._bottomCenterWidget)==null||O.dispose(),(A=this._bottomRightWidget)==null||A.dispose(),this._dispose$.next(this),this._dispose$.complete()}getCurrentCellInfo(){const e=this.model.currentCell;if(e){let t;if(e.isMerged){const n=e.mergeInfo;t={startRow:n.startRow,endRow:n.endRow,startColumn:n.startColumn,endColumn:n.endColumn,startX:n.startX,endX:n.endX,startY:n.startY,endY:n.endY}}else{const{actualRow:n,actualColumn:o,startX:r,endX:s,startY:a,endY:c}=e;t={startRow:n,endRow:n,startColumn:o,endColumn:o,startX:r,endX:s,startY:a,endY:c}}return t}}getValue(){return{...this._selectionModel.getValue(),style:this._selectionStyle}}getRange(){return this._selectionModel.getValue().rangeWithCoord}enableHelperSelection(){this._isHelperSelection=!0}disableHelperSelection(){this._isHelperSelection=!1}updateStyleId(e){this._selectionStyle!=null&&(this._selectionStyle.id=e)}_updateControl(e,t,n){const{startX:o,startY:r,endX:s,endY:a}=this._selectionModel,c=this._defaultStyle;e==null&&(e=c);const{stroke:d=c.stroke,widgets:u=c.widgets,hasAutoFill:h=c.hasAutoFill,AutofillStroke:m=c.AutofillStroke,strokeDash:g}=e;let{strokeWidth:S=c.strokeWidth,AutofillSize:f=c.AutofillSize,AutofillStrokeWidth:C=c.AutofillStrokeWidth}=e;const R=this._getScale(),M=(S+_.SELECTION_CONTROL_BORDER_BUFFER_WIDTH)/2/R;S/=R,f/=R,C/=R<1?1:R;const T=_.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/R,w=b.FIX_ONE_PIXEL_BLUR_OFFSET/R;this.leftControl.transformByState({height:a-r,left:-M+w,width:S,strokeWidth:T,top:-T/2+w}),this.leftControl.setProps({fill:d,stroke:_.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.rightControl.transformByState({height:a-r,left:s-o-M+w,width:S,strokeWidth:T,top:-T/2+w}),this.rightControl.setProps({fill:d,stroke:_.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.topControl.transformByState({width:s-o+S,top:-M+w,left:-M+w,height:S,strokeWidth:T}),this.topControl.setProps({fill:d,stroke:_.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.bottomControl.transformByState({width:s-o+S,top:a-r-M+w,height:S,left:-M+w,strokeWidth:T}),this.bottomControl.setProps({fill:d,stroke:_.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),g==null?this.dashRect.hide():(this.dashRect.transformByState({height:a-r-S/2,width:s-o-S/2,strokeWidth:S,left:S/2-1/R,top:S/2-1/R}),this.dashRect.setProps({strokeDashArray:[0,g]}),this.dashRect.show()),h===!0&&!this._hasWidgets(u)?(this.fillControl.setProps({fill:d,stroke:m,strokeScaleEnabled:!1}),this.fillControl.transformByState({width:f-C,height:f-C,left:s-o-f/2+C/2,top:a-r-f/2+C/2,strokeWidth:C}),this.fillControl.show()):this.fillControl.hide(),this._updateBackgroundControl(e),this._updateBackgroundTitle(e,t,n),this._updateWidgets(e),this.selectionShape.show(),this.selectionShape.translate(o,r),this._selectionStyle=e,this._rowHeaderWidth=t||0,this._columnHeaderHeight=n||0,this.selectionShape.makeDirtyNoDebounce(!0)}_initialize(){this._defaultStyle=_.getNormalSelectionStyle(this._themeService),this._selectionModel=new _s;const e=this._zIndex;this._leftControl=new b.Rect("__SpreadsheetSelectionShapeLeftControl__"+e,{zIndex:e}),this._rightControl=new b.Rect("__SpreadsheetSelectionShapeRightControl__"+e,{zIndex:e}),this._topControl=new b.Rect("__SpreadsheetSelectionTopControl__"+e,{zIndex:e}),this._bottomControl=new b.Rect("__SpreadsheetSelectionBottomControl__"+e,{zIndex:e}),this._backgroundControlTop=new b.Rect("__SpreadsheetSelectionBackgroundControlTop__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlBottom=new b.Rect("__SpreadsheetSelectionBackgroundControlBottom__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleLeft=new b.Rect("__SpreadsheetSelectionBackgroundControlMiddleLeft__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleRight=new b.Rect("__SpreadsheetSelectionBackgroundControlMiddleRight__"+e,{zIndex:e-1,evented:!1}),this._fillControl=new b.Rect("__SpreadsheetSelectionFillControl__"+e,{zIndex:e+1}),this._dashRect=new b.Rect("__SpreadsheetDragDashControl__"+e,{zIndex:e+2,evented:!1,stroke:"#fff"});const t=[this._fillControl,this._leftControl,this._rightControl,this._topControl,this._bottomControl,this._backgroundControlTop,this._backgroundControlMiddleLeft,this._backgroundControlMiddleRight,this._backgroundControlBottom,this._dashRect];this._widgetRects=this._initialWidget(),this._selectionShape=new b.Group("__SpreadsheetSelectionShape__"+e,...t,...this._widgetRects),this._selectionShape.hide(),this._selectionShape.evented=!1,this._selectionShape.zIndex=e,this.getScene().addObject(this._selectionShape,hs),this._initialTitle()}_initialTitle(){const e=this._zIndex;this._rowHeaderBackground=new b.Rect("__SpreadSheetSelectionRowHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderBorder=new b.Rect("__SpreadSheetSelectionRowHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderGroup=new b.Group("__SpreadSheetSelectionRowHeaderGroup__"+e,this._rowHeaderBackground,this._rowHeaderBorder),this._rowHeaderGroup.hide(),this._rowHeaderGroup.evented=!1,this._rowHeaderGroup.zIndex=e,this._columnHeaderBackground=new b.Rect("__SpreadSheetSelectionColumnHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderBorder=new b.Rect("__SpreadSheetSelectionColumnHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderGroup=new b.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],b.DEFAULT_SELECTION_LAYER_INDEX)}_initialWidget(){const e=this._zIndex;return this._topLeftWidget=new b.Rect("__SpreadSheetSelectionTopLeftWidget__"+e,{zIndex:e+1}),this._topCenterWidget=new b.Rect("__SpreadSheetSelectionTopCenterWidget__"+e,{zIndex:e+1}),this._topRightWidget=new b.Rect("__SpreadSheetSelectionTopRightWidget__"+e,{zIndex:e+1}),this._middleLeftWidget=new b.Rect("__SpreadSheetSelectionMiddleLeftWidget__"+e,{zIndex:e+1}),this._middleRightWidget=new b.Rect("__SpreadSheetSelectionMiddleRightWidget__"+e,{zIndex:e+1}),this._bottomLeftWidget=new b.Rect("__SpreadSheetSelectionBottomLeftWidget__"+e,{zIndex:e+1}),this._bottomCenterWidget=new b.Rect("__SpreadSheetSelectionBottomCenterWidget__"+e,{zIndex:e+1}),this._bottomRightWidget=new b.Rect("__SpreadSheetSelectionBottomRightWidget__"+e,{zIndex:e+1}),[this._topLeftWidget,this._topCenterWidget,this._topRightWidget,this._middleLeftWidget,this._middleRightWidget,this._bottomLeftWidget,this._bottomCenterWidget,this._bottomRightWidget]}_updateBackgroundTitle(e,t,n){const{startX:o,startY:r,endX:s,endY:a,rangeType:c}=this._selectionModel,d=this._defaultStyle;e==null&&(e=d);const u=this._getScale(),{stroke:h,hasRowHeader:m,rowHeaderFill:g=d.rowHeaderFill,rowHeaderStroke:S=d.rowHeaderStroke,hasColumnHeader:f,columnHeaderFill:C=d.columnHeaderFill,columnHeaderStroke:R=d.columnHeaderStroke}=e;let{rowHeaderStrokeWidth:M=d.rowHeaderStrokeWidth,columnHeaderStrokeWidth:T=d.columnHeaderStrokeWidth}=e;if(M/=u,T/=u,f===!0){let w=C;this._isHeaderHighlight&&c===l.RANGE_TYPE.COLUMN&&(w=new l.ColorKit(h).setAlpha(eo).toString()),this._columnHeaderBackground.setProps({fill:w}),this._columnHeaderBackground.resize(s-o,n),this._columnHeaderBorder.setProps({fill:R}),this._columnHeaderBorder.transformByState({width:s-o,height:T,top:n-T+1/u}),this._columnHeaderGroup.show(),this._columnHeaderGroup.translate(o,0)}else this._columnHeaderGroup.hide();if(this._columnHeaderGroup.makeDirty(!0),m===!0){let w=g;this._isHeaderHighlight&&c===l.RANGE_TYPE.ROW&&(w=new l.ColorKit(h).setAlpha(eo).toString()),this._rowHeaderBackground.setProps({fill:w}),this._rowHeaderBackground.resize(t,a-r),this._rowHeaderBorder.setProps({fill:S}),this._rowHeaderBorder.transformByState({width:M,height:a-r,left:t-M+1/u}),this._rowHeaderGroup.show(),this._rowHeaderGroup.translate(0,r)}else this._rowHeaderGroup.hide();this._rowHeaderGroup.makeDirty(!0)}_updateBackgroundControl(e){const{startX:t,startY:n,endX:o,endY:r}=this._selectionModel,s=this._defaultStyle;e==null&&(e=s);const a=this._getScale(),{fill:c=s.fill}=e;let{strokeWidth:d=s.strokeWidth}=e;d/=a;const u=this._selectionModel.highlightToSelection();if(!u){this._backgroundControlTop.resize(o-t,r-n),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:m,endX:g,endY:S}=u,f=d/2,C={left:-f,top:-f,width:o-t+f*2,height:m-n+f};C.height<0&&(C.width=0,C.height=0),this._backgroundControlTop.transformByState(C);const R={left:-f,top:m-n,width:h-t+f,height:S-m};R.width<0&&(R.width=0,R.height=0),this._backgroundControlMiddleLeft.transformByState(R);const M={left:g-t-f,top:m-n,width:o-g+f*2,height:S-m};M.width<0&&(M.width=0,M.height=0),this._backgroundControlMiddleRight.transformByState(M);const T={left:-f,top:S-n,width:o-t+f*2,height:r-S+f};T.height<0&&(T.width=0,T.height=0),this._backgroundControlBottom.transformByState(T),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:n,endX:o,endY:r}=this._selectionModel,s=this._defaultStyle;e==null&&(e=s);const{stroke:a=s.stroke,widgets:c=s.widgets,widgetStroke:d=s.widgetStroke}=e,u=this._getScale();let{widgetSize:h=s.widgetSize,widgetStrokeWidth:m=s.widgetStrokeWidth}=e;h/=u,m/=u;const g={left:-h/2+m/2,center:(o-t)/2-h/2+m/2,right:o-t-h/2+m/2,top:-h/2,middle:(r-n)/2-h/2,bottom:r-n-h/2+m/2},S=h-m;this._widgetRects.forEach(f=>{f.setProps({fill:a,stroke:d})}),c.tl===!0?(this._topLeftWidget.transformByState({height:S,width:S,left:g.left,top:g.top,strokeWidth:m}),this._topLeftWidget.show()):this._topLeftWidget.hide(),c.tc===!0?(this._topCenterWidget.transformByState({height:S,width:S,left:g.center,top:g.top,strokeWidth:m}),this._topCenterWidget.show()):this._topCenterWidget.hide(),c.tr===!0?(this._topRightWidget.transformByState({height:S,width:S,left:g.right,top:g.top,strokeWidth:m}),this._topRightWidget.show()):this._topRightWidget.hide(),c.ml===!0?(this._middleLeftWidget.transformByState({height:S,width:S,left:g.left,top:g.middle,strokeWidth:m}),this._middleLeftWidget.show()):this._middleLeftWidget.hide(),c.mr===!0?(this._middleRightWidget.transformByState({height:S,width:S,left:g.right,top:g.middle,strokeWidth:m}),this._middleRightWidget.show()):this._middleRightWidget.hide(),c.bl===!0?(this._bottomLeftWidget.transformByState({height:S,width:S,left:g.left,top:g.bottom,strokeWidth:m}),this._bottomLeftWidget.show()):this._bottomLeftWidget.hide(),c.bc===!0?(this._bottomCenterWidget.transformByState({height:S,width:S,left:g.center,top:g.bottom,strokeWidth:m}),this._bottomCenterWidget.show()):this._bottomCenterWidget.hide(),c.br===!0?(this._bottomRightWidget.transformByState({height:S,width:S,left:g.right,top:g.bottom,strokeWidth:m}),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 n of t)if(e[n]===!0)return!0;return!0}_getScale(){const{scaleX:e,scaleY:t}=this._scene.getAncestorScale();return Math.max(e,t)}}const to="__SpreadsheetHelperSelectionTempRect",fs=35;class no{constructor(e,t,n,o,r){v(this,"_startOffsetX",0);v(this,"_startOffsetY",0);v(this,"_relativeSelectionPositionRow",0);v(this,"_relativeSelectionPositionColumn",0);v(this,"_relativeSelectionRowLength",0);v(this,"_relativeSelectionColumnLength",0);v(this,"_moveObserver");v(this,"_upObserver");v(this,"_helperSelection");v(this,"_scrollTimer");v(this,"_activeViewport");v(this,"_targetSelection",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});v(this,"_isInMergeState",!1);v(this,"_fillControlColors",[]);this._control=e,this._skeleton=t,this._scene=n,this._themeService=o,this._injector=r,this._initialControl(),this._initialWidget(),this._initialFill(),this._control.dispose$.subscribe(()=>{this.dispose()})}get isHelperSelection(){return this._control.isHelperSelection}dispose(){var e,t;(e=this._scrollTimer)==null||e.dispose(),this._fillControlColors=[],this._clearObserverEvent(),(t=this._helperSelection)==null||t.dispose()}_getFreeze(){var t;return(t=this._injector.get(exports.SheetSkeletonManagerService).getCurrent())==null?void 0:t.skeleton.getWorksheetConfig().freeze}_isSelectionInViewport(e,t){const n=this._getFreeze()||{startRow:-1,startColumn:-1,xSplit:0,ySplit:0};switch(t.viewPortKey){case V.VIEW_MAIN:return e.endRow>=n.startRow&&e.endColumn>=n.startColumn;case V.VIEW_MAIN_TOP:case V.VIEW_COLUMN_RIGHT:return e.endColumn>=n.startColumn&&e.startRow<n.startRow;case V.VIEW_MAIN_LEFT:case V.VIEW_ROW_BOTTOM:return e.endRow>=n.startRow&&e.startColumn<n.startColumn;case V.VIEW_MAIN_LEFT_TOP:case V.VIEW_COLUMN_LEFT:case V.VIEW_ROW_TOP:case V.VIEW_LEFT_TOP:return e.startRow<n.startRow&&e.startColumn<n.startColumn}}_clearObserverEvent(){this._scene.onPointerMoveObserver.remove(this._moveObserver),this._scene.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_initialControl(){const{leftControl:e,rightControl:t,topControl:n,bottomControl:o}=this._control;[e,t,n,o].forEach(r=>{r.onPointerEnterObserver.add(()=>{r.setCursor(b.CURSOR_TYPE.MOVE)}),r.onPointerLeaveObserver.add(()=>{r.resetCursor()}),r.onPointerDownObserver.add(this._controlEvent.bind(this))})}_controlMoving(e,t){var y;const n=this._scene,o=n.getScrollXYByRelativeCoords(b.Vector2.FromArray([e,t])),{scaleX:r,scaleY:s}=n.getAncestorScale(),a=this._skeleton.getCellPositionByOffset(e,t,r,s,o),{row:c,column:d}=a,u=this._skeleton.getRowCount()-1,h=this._skeleton.getColumnCount()-1;let m=c+this._relativeSelectionPositionRow;m<0&&(m=0);let g=m+this._relativeSelectionRowLength;g>u&&(g=u,g-m<this._relativeSelectionRowLength&&(m=g-this._relativeSelectionRowLength));let S=d+this._relativeSelectionPositionColumn;S<0&&(S=0);let f=S+this._relativeSelectionColumnLength;f>h&&(f=h,f-S<this._relativeSelectionColumnLength&&(S=f-this._relativeSelectionColumnLength));const C=this._skeleton.getNoMergeCellPositionByIndex(m,S),R=this._skeleton.getNoMergeCellPositionByIndex(g,f),M=(C==null?void 0:C.startY)||0,T=(R==null?void 0:R.endY)||0,w=(C==null?void 0:C.startX)||0,E=(R==null?void 0:R.endX)||0;(y=this._helperSelection)==null||y.transformByState({left:w,top:M,width:E-w,height:T-M}),this._targetSelection={startY:M,endY:T,startX:w,endX:E,startRow:m,endRow:g,startColumn:S,endColumn:f},this._control.selectionMoving$.next(this._targetSelection)}_controlEvent(e){const{offsetX:t,offsetY:n}=e,o=this._scene,r=o.getRelativeCoord(b.Vector2.FromArray([t,n])),{x:s,y:a}=r,c=o.getScrollXYByRelativeCoords(r),{scaleX:d,scaleY:u}=o.getAncestorScale(),h=this._skeleton.getCellPositionByOffset(s,a,d,u,c);this._startOffsetX=s,this._startOffsetY=a;const{row:m,column:g}=h,{startRow:S,startColumn:f,endRow:C,endColumn:R}=this._control.model;let M=0,T=0;m<S?M-=1:m>C&&(M+=1),g<f?T-=1:g>R&&(T+=1),this._relativeSelectionPositionRow=S-m+M,this._relativeSelectionPositionColumn=f-g+T,this._relativeSelectionRowLength=C-S,this._relativeSelectionColumnLength=R-f;const w=this._control.selectionStyle,E=this._getScale();this.isHelperSelection&&(this._helperSelection=new b.Rect(to,{stroke:w.stroke,strokeWidth:w.strokeWidth/E}),o.addObject(this._helperSelection));const y=o.getViewport(V.VIEW_MAIN),x=b.ScrollTimer.create(o);x.startScroll(s,a,y),this._scrollTimer=x,o.disableEvent(),this._moveObserver=o.onPointerMoveObserver.add(O=>{const{offsetX:A,offsetY:k}=O,{x:N,y:B}=o.getRelativeCoord(b.Vector2.FromArray([A,k]));this._controlMoving(N,B),o.setCursor(b.CURSOR_TYPE.MOVE),x.scrolling(N,B,()=>{this._controlMoving(N,B)})}),this._upObserver=o.onPointerUpObserver.add(()=>{var A,k;(A=this._helperSelection)==null||A.dispose();const O=this._scene;O.resetCursor(),this._clearObserverEvent(),O.enableEvent(),(k=this._scrollTimer)==null||k.dispose(),this._control.selectionMoved$.next(this._targetSelection)})}_initialWidget(){const{topLeftWidget:e,topCenterWidget:t,topRightWidget:n,middleLeftWidget:o,middleRightWidget:r,bottomLeftWidget:s,bottomCenterWidget:a,bottomRightWidget:c}=this._control,d=[b.CURSOR_TYPE.NORTH_WEST_RESIZE,b.CURSOR_TYPE.NORTH_RESIZE,b.CURSOR_TYPE.NORTH_EAST_RESIZE,b.CURSOR_TYPE.WEST_RESIZE,b.CURSOR_TYPE.EAST_RESIZE,b.CURSOR_TYPE.SOUTH_WEST_RESIZE,b.CURSOR_TYPE.SOUTH_RESIZE,b.CURSOR_TYPE.SOUTH_EAST_RESIZE];[e,t,n,o,r,s,a,c].forEach((u,h)=>{u.onPointerEnterObserver.add(()=>{u.setCursor(d[h])}),u.onPointerLeaveObserver.add(()=>{u.resetCursor()}),u.onPointerDownObserver.add(m=>{this._widgetEvent(m,d[h])})})}_widgetMoving(e,t,n){const o=this._scene,r=o.getScrollXYByRelativeCoords(b.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:s,scaleY:a}=o.getAncestorScale(),c=this._skeleton.getCellPositionByOffset(e,t,s,a,r),{row:d,column:u}=c,{rowHeaderWidth:h,columnHeaderHeight:m}=this._skeleton;let g=this._relativeSelectionPositionRow,S=this._relativeSelectionPositionColumn,f=d,C=u;n===b.CURSOR_TYPE.NORTH_WEST_RESIZE?(g=d,S=u,f=this._relativeSelectionPositionRow,C=this._relativeSelectionPositionColumn):n===b.CURSOR_TYPE.NORTH_RESIZE?(g=d,S=this._relativeSelectionPositionColumn,f=this._relativeSelectionPositionRow,C=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength):n===b.CURSOR_TYPE.NORTH_EAST_RESIZE?(g=d,S=this._relativeSelectionPositionColumn,f=this._relativeSelectionPositionRow,C=u):n===b.CURSOR_TYPE.WEST_RESIZE?(g=this._relativeSelectionPositionRow,S=u,f=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,C=this._relativeSelectionPositionColumn):n===b.CURSOR_TYPE.EAST_RESIZE?f=this._relativeSelectionPositionRow+this._relativeSelectionRowLength:n===b.CURSOR_TYPE.SOUTH_WEST_RESIZE?(g=this._relativeSelectionPositionRow,S=u,f=d,C=this._relativeSelectionPositionColumn):n===b.CURSOR_TYPE.SOUTH_RESIZE&&(g=this._relativeSelectionPositionRow,S=this._relativeSelectionPositionColumn,f=d,C=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength);const{startRow:R,startColumn:M,endRow:T,endColumn:w}=this._swapPositions(g,S,f,C),E=this._skeleton.getNoMergeCellPositionByIndex(R,M),y=this._skeleton.getNoMergeCellPositionByIndex(T,w),x=(E==null?void 0:E.startY)||0,O=(y==null?void 0:y.endY)||0,A=(E==null?void 0:E.startX)||0,k=(y==null?void 0:y.endX)||0;this._targetSelection={startY:x,endY:O,startX:A,endX:k,startRow:g,endRow:f,startColumn:S,endColumn:C},this._control.update(this._targetSelection,h,m,this._control.selectionStyle),this._control.clearHighlight(),this._control.selectionScaling$.next(this._targetSelection)}_widgetEvent(e,t){const{offsetX:n,offsetY:o}=e,r=this._scene,s=r.getRelativeCoord(b.Vector2.FromArray([n,o])),{x:a,y:c}=s;this._startOffsetX=n,this._startOffsetY=o;const{startRow:d,startColumn:u,endRow:h,endColumn:m}=this._control.model;this._relativeSelectionPositionRow=d,this._relativeSelectionPositionColumn=u,this._relativeSelectionRowLength=h-d,this._relativeSelectionColumnLength=m-u,t===b.CURSOR_TYPE.NORTH_WEST_RESIZE?(this._relativeSelectionPositionRow=h,this._relativeSelectionPositionColumn=m):t===b.CURSOR_TYPE.NORTH_RESIZE?this._relativeSelectionPositionRow=h:t===b.CURSOR_TYPE.NORTH_EAST_RESIZE?this._relativeSelectionPositionRow=h:t===b.CURSOR_TYPE.WEST_RESIZE?this._relativeSelectionPositionColumn=m:t===b.CURSOR_TYPE.SOUTH_WEST_RESIZE&&(this._relativeSelectionPositionColumn=m);const g=b.ScrollTimer.create(r);g.startScroll(a,c),this._scrollTimer=g,r.disableEvent(),this._moveObserver=r.onPointerMoveObserver.add(S=>{const{offsetX:f,offsetY:C}=S,{x:R,y:M}=r.getRelativeCoord(b.Vector2.FromArray([f,C]));this._widgetMoving(R,M,t),r.setCursor(t),g.scrolling(R,M,()=>{this._widgetMoving(R,M,t)})}),this._upObserver=r.onPointerUpObserver.add(()=>{var f;const S=this._scene;S.resetCursor(),this._clearObserverEvent(),S.enableEvent(),(f=this._scrollTimer)==null||f.dispose(),this._control.selectionScaled$.next(this._targetSelection)})}_initialFill(){const{fillControl:e}=this._control;e.onPointerEnterObserver.add(()=>{e.setCursor(b.CURSOR_TYPE.CROSSHAIR)}),e.onPointerLeaveObserver.add(()=>{e.resetCursor()}),e.onPointerDownObserver.add(this._fillEvent.bind(this))}_fillMoving(e,t){var k,N,B;const n=this._scene,o=n.getScrollXY(this._activeViewport),{scaleX:r,scaleY:s}=n.getAncestorScale(),a=this._skeleton.getCellPositionByOffset(e,t,r,s,o),{row:c,column:d}=a,u=n.getRelativeCoord(b.Vector2.FromArray([e,t])),h=this._skeleton.getRowCount()-1,m=this._skeleton.getColumnCount()-1;let g=this._relativeSelectionPositionRow,S=this._relativeSelectionPositionColumn,f=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,C=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength,R=!1,M=!0;if((d<S||d>C)&&c>=g&&c<=f){const F=this._fillRuler(d,S,C,this._relativeSelectionColumnLength,m);S=F.startRowOrColumn,C=F.endRowOrColumn,R=F.isLighten,M=!1}else if((c<g||c>f)&&d>=S&&d<=C){const F=this._fillRuler(c,g,f,this._relativeSelectionRowLength,h);g=F.startRowOrColumn,f=F.endRowOrColumn,R=F.isLighten}else if(Math.abs(this._startOffsetX-u.x-o.x)/2>Math.abs(this._startOffsetY-u.y-o.y)){const F=this._fillRuler(d,S,C,this._relativeSelectionColumnLength,m);S=F.startRowOrColumn,C=F.endRowOrColumn,R=F.isLighten,M=!1}else{const F=this._fillRuler(c,g,f,this._relativeSelectionRowLength,h);g=F.startRowOrColumn,f=F.endRowOrColumn,R=F.isLighten}const T=this._skeleton.getNoMergeCellPositionByIndex(g,S),w=this._skeleton.getNoMergeCellPositionByIndex(f,C),E=(T==null?void 0:T.startY)||0,y=(w==null?void 0:w.endY)||0,x=(T==null?void 0:T.startX)||0,O=(w==null?void 0:w.endX)||0;R?this._controlHandler((F,W)=>{const $=new l.ColorKit(this._fillControlColors[W]).lighten(fs).toRgbString();F.setProps({fill:$})}):this._controlHandler((F,W)=>{F.setProps({fill:this._fillControlColors[W]})});const A=_.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();g===f&&M===!0||S===C&&M===!1?(k=this._helperSelection)==null||k.hide():((N=this._helperSelection)==null||N.transformByState({left:x-A/2,top:E-A/2,width:O-x,height:y-E}),(B=this._helperSelection)==null||B.show()),this._targetSelection={startY:E,endY:y,startX:x,endX:O,startRow:g,endRow:f,startColumn:S,endColumn:C},this._control.selectionFilling$.next(this._targetSelection)}_fillEvent(e){const{offsetX:t,offsetY:n}=e,o=this._scene,r=o.getRelativeCoord(b.Vector2.FromArray([t,n])),{x:s,y:a}=r;this._startOffsetX=s,this._startOffsetY=a;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 m=this._control.selectionStyle;let g=m==null?void 0:m.stroke,S=m==null?void 0:m.strokeWidth;const f=_.getNormalSelectionStyle(this._themeService);g==null&&(g=f.stroke),S==null&&(S=f.strokeWidth);const C=this._getScale();S/=C;const R=_.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/C,M=new l.ColorKit(g).darken(2).toRgbString();this.isHelperSelection&&(this._helperSelection=new b.Rect(to,{stroke:M,strokeWidth:S+R/2}),o.addObject(this._helperSelection)),this._activeViewport=o.getActiveViewportByCoord(b.Vector2.FromArray([t,n]));const T=o.getViewport(V.VIEW_MAIN),w=b.ScrollTimer.create(o,this._activeViewport.viewPortKey===V.VIEW_MAIN?b.ScrollTimerType.ALL:b.ScrollTimerType.NONE);w.startScroll(s,a,T),this._scrollTimer=w,o.disableEvent(),this._controlHandler(E=>{this._fillControlColors.push(E.fill)}),this._moveObserver=o.onPointerMoveObserver.add(E=>{var B;const{offsetX:y,offsetY:x}=E,O=o.getActiveViewportByCoord(b.Vector2.FromArray([y,x])),{x:A,y:k}=o.getRelativeCoord(b.Vector2.FromArray([y,x]));this._fillMoving(A,k),o.setCursor(b.CURSOR_TYPE.CROSSHAIR);const N=this._targetSelection;if(T&&O&&((B=this._activeViewport)==null?void 0:B.viewPortKey)!==(O==null?void 0:O.viewPortKey)){let F;N.startRow!==c?(w.scrollTimerType=b.ScrollTimerType.Y,F={...N,endRow:N.startRow}):N.endRow!==u?(w.scrollTimerType=b.ScrollTimerType.Y,F={...N,startRow:N.endRow}):N.startColumn!==d?(w.scrollTimerType=b.ScrollTimerType.X,F={...N,endColumn:N.startColumn}):(w.scrollTimerType=b.ScrollTimerType.X,F={...N,startColumn:N.endColumn}),this._isSelectionInViewport(F,O)&&(T.scrollTo({x:w.scrollTimerType===b.ScrollTimerType.X?0:void 0,y:w.scrollTimerType===b.ScrollTimerType.Y?0:void 0}),this._activeViewport=O)}w.scrolling(A,k,()=>{this._fillMoving(A,k)})}),this._upObserver=o.onPointerUpObserver.add(()=>{var y,x;(y=this._helperSelection)==null||y.dispose();const E=this._scene;E.resetCursor(),this._clearObserverEvent(),E.enableEvent(),(x=this._scrollTimer)==null||x.dispose(),this._control.refreshSelectionFilled(this._targetSelection),this._isInMergeState=!1,this._controlHandler((O,A)=>{O.setProps({fill:this._fillControlColors[A]})}),this._fillControlColors=[]})}_hasMergeInRange(e,t,n,o){const r=this._skeleton.mergeData;if(!r)return!1;for(const s of r){const{startRow:a,startColumn:c,endRow:d,endColumn:u}=s,h={left:t,top:e,right:o,bottom:n},m={left:c,top:a,right:u,bottom:d};if(b.isRectIntersect(h,m))return!0}return!1}_swapPositions(e,t,n,o){const r=Math.min(e,n),s=Math.min(t,o),a=Math.max(e,n),c=Math.max(t,o);return{startRow:r,startColumn:s,endRow:a,endColumn:c}}_controlHandler(e){const{leftControl:t,rightControl:n,topControl:o,bottomControl:r,backgroundControlTop:s,backgroundControlMiddleLeft:a,backgroundControlMiddleRight:c,backgroundControlBottom:d,fillControl:u}=this._control,h=[t,n,o,r,s,a,c,d,u];for(let m=0,g=h.length;m<g;m++){const S=h[m];e(S,m)}}_fillRuler(e,t,n,o,r){let s=!1;if(e<t)if(this._isInMergeState&&e<t){const a=t-e,c=o+1,d=Math.ceil(a/c);let u=t-d*c;u<0&&(u=t-(d-1)*c),t=u}else t=e;else if(e>=t&&e<=n)s=!0,n=e;else if(this._isInMergeState&&e>n){const a=e-n,c=o+1,d=Math.ceil(a/c);let u=n+d*c;u>r&&(u=n+(d-1)*c),n=u}else n=e;return{rowOrColumn:e,startRowOrColumn:t,endRowOrColumn:n,isLighten:s}}_getScale(){const{scaleX:e,scaleY:t}=this._scene.getAncestorScale();return Math.max(e,t)}}var ps=Object.defineProperty,vs=Object.getOwnPropertyDescriptor,Cs=(i,e,t,n)=>{for(var o=n>1?void 0:n?vs(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&ps(e,t,o),o},en=(i,e)=>(t,n)=>e(t,n,i);exports.SelectionRenderService=class{constructor(e,t,n,o){v(this,"hasSelection",!1);v(this,"_downObserver");v(this,"_moveObserver");v(this,"_upObserver");v(this,"_controlFillConfig$",new H.BehaviorSubject(null));v(this,"controlFillConfig$",this._controlFillConfig$.asObservable());v(this,"_selectionControls",[]);v(this,"_startSelectionRange",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});v(this,"_startOffsetX",0);v(this,"_startOffsetY",0);v(this,"_scrollTimer");v(this,"_cancelDownObserver");v(this,"_cancelUpObserver");v(this,"_skeleton");v(this,"_scene");v(this,"_isHeaderHighlight",!0);v(this,"_isDetectMergedCell",!0);v(this,"_selectionStyle");v(this,"_isSelectionEnabled",!0);v(this,"_isShowPreviousEnable",0);v(this,"_isRemainLastEnable",!0);v(this,"_isSkipRemainLastEnable",!1);v(this,"_selectionMoveEnd$",new H.BehaviorSubject([]));v(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());v(this,"_selectionMoving$",new H.Subject);v(this,"selectionMoving$",this._selectionMoving$.asObservable());v(this,"_selectionMoveStart$",new H.Subject);v(this,"selectionMoveStart$",this._selectionMoveStart$.asObservable());v(this,"_activeViewport");this._themeService=e,this._shortcutService=t,this._sheetSkeletonManagerService=n,this._injector=o,this._selectionStyle=_.getNormalSelectionStyle(this._themeService)}enableHeaderHighlight(){this._isHeaderHighlight=!0}disableHeaderHighlight(){this._isHeaderHighlight=!1}enableDetectMergedCell(){this._isDetectMergedCell=!0}disableDetectMergedCell(){this._isDetectMergedCell=!1}setStyle(e){this._selectionStyle=e}resetStyle(){this.setStyle(_.getNormalSelectionStyle(this._themeService))}enableSelection(){this._isSelectionEnabled=!0}disableSelection(){this._isSelectionEnabled=!1}enableShowPrevious(){this._isShowPreviousEnable=!0}disableShowPrevious(){this._isShowPreviousEnable=!1}enableRemainLast(){this._isRemainLastEnable=!0}disableRemainLast(){this._isRemainLastEnable=!1}enableSkipRemainLast(){this._isSkipRemainLastEnable=!0}disableSkipRemainLast(){this._isSkipRemainLastEnable=!1}getViewPort(){return this._activeViewport}addControlToCurrentByRangeData(e){const t=this.getCurrentControls();if(!t)return;const{rangeWithCoord:n,primaryWithCoord:o}=e,r=this._skeleton;let s=e.style;s==null&&(s=_.getNormalSelectionStyle(this._themeService));const a=this._scene;if(a==null||r==null)return;const c=new Un(a,t.length,this._isHeaderHighlight,this._themeService);new no(c,r,a,this._themeService,this._injector);const{rowHeaderWidth:d,columnHeaderHeight:u}=r;c.update(n,d,u,s,o),this._isHeaderHighlight?c.enableHeaderHighlight():c.disableHeaderHighlight(),t.push(c)}updateControlForCurrentByRangeData(e){const t=this.getCurrentControls();if(!t)return;const n=this._skeleton;if(n==null)return;const{rowHeaderWidth:o,columnHeaderHeight:r}=n;for(let s=0,a=e.length;s<a;s++){const{rangeWithCoord:c,primaryWithCoord:d,style:u}=e[s];t[s].update(c,o,r,u,d)}}refreshSelectionMoveStart(){this._selectionMoveStart$.next(this.getSelectionDataWithStyle())}changeRuntime(e,t,n){this._skeleton=e,this._scene=t,this._activeViewport=n||t.getViewports()[0]}getSelectionDataWithStyle(){return this._selectionControls.map(t=>t.getValue())}getCurrentControls(){return this._selectionControls}_clearSelectionControls(){const e=this.getCurrentControls();if(e.length>0){for(const t of e)t.dispose();e.length=0}}_getFreeze(){var t;return(t=this._sheetSkeletonManagerService.getCurrent())==null?void 0:t.skeleton.getWorksheetConfig().freeze}_getViewportByCell(e,t){if(!this._scene||e===void 0||t===void 0)return null;const n=this._getFreeze();if(!n||n.startRow<=0&&n.startColumn<=0)return this._scene.getViewport(V.VIEW_MAIN);if(e>n.startRow&&t>n.startColumn)return this._scene.getViewport(V.VIEW_MAIN);if(e<=n.startRow&&t<=n.startColumn)return this._scene.getViewport(V.VIEW_MAIN_LEFT_TOP);if(e<=n.startRow&&t>n.startColumn)return this._scene.getViewport(V.VIEW_MAIN_TOP);if(e>n.startRow&&t<=n.startColumn)return this._scene.getViewport(V.VIEW_MAIN_LEFT)}getActiveSelections(){const e=this.getCurrentControls();if(e&&e.length>0)return e==null?void 0:e.map(n=>{const o=n.model,r=o.currentCell;let s=null;return r&&(s={actualRow:r.actualRow,actualColumn:r.actualColumn,isMerged:r.isMerged,isMergedMainCell:r.isMergedMainCell,startRow:r.mergeInfo.startRow,startColumn:r.mergeInfo.startColumn,endRow:r.mergeInfo.endRow,endColumn:r.mergeInfo.endColumn}),{range:{startRow:o.startRow,startColumn:o.startColumn,endRow:o.endRow,endColumn:o.endColumn},primary:s}})}getActiveRange(){const e=this.getCurrentControls(),t=e&&e[e.length-1].model;return t&&{startRow:t.startRow,startColumn:t.startColumn,endRow:t.endRow,endColumn:t.endColumn}}getActiveSelection(){const e=this.getCurrentControls();return e&&e[e.length-1]}endSelection(){this._endSelection(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),this._shortcutService.setDisable(!1)}reset(){this._clearSelectionControls(),this._moveObserver=null,this._upObserver=null,this._downObserver=null}resetAndEndSelection(){this.endSelection(),this.reset()}eventTrigger(e,t=0,n=l.RANGE_TYPE.NORMAL,o,r=b.ScrollTimerType.ALL){if(this._isSelectionEnabled===!1)return;const s=this._skeleton,{offsetX:a,offsetY:c}=e,d=this._scene;if(d==null||s==null)return;o!=null&&(this._activeViewport=o);const u=d.getViewport(V.VIEW_MAIN),h=d.getRelativeCoord(b.Vector2.FromArray([a,c]));let{x:m,y:g}=h;this._startOffsetX=m,this._startOffsetY=g;const S=d.getScrollXYByRelativeCoords(h),{scaleX:f,scaleY:C}=d.getAncestorScale();n===l.RANGE_TYPE.ROW?m=0:n===l.RANGE_TYPE.COLUMN&&(g=0);const R=this._getSelectedRangeWithMerge(m,g,f,C,S);if(!R)return!1;const{rangeWithCoord:M,primaryWithCoord:T}=R,{startRow:w,startColumn:E,endColumn:y,endRow:x,startY:O,endY:A,startX:k,endX:N}=M,{rowHeaderWidth:B,columnHeaderHeight:F}=s,W={startColumn:E,startRow:w,endColumn:y,endRow:x,startY:O,endY:A,startX:k,endX:N,rangeType:n};this._startSelectionRange=W;let $=this.getActiveSelection();const Z=this.getCurrentControls();if(!Z)return!1;for(const j of Z){if(e.button===2&&j.model.isInclude(W)){$=j;return}if(j.model.isEqual(W)){$=j;break}e.shiftKey||j.clearHighlight()}if(Z.length>0&&!e.ctrlKey&&!e.shiftKey&&!this._isShowPreviousEnable&&!this._isRemainLastEnable){for(const j of Z)j.dispose();Z.length=0}const z=$&&$.model.currentCell;if($&&e.shiftKey&&z){const{actualRow:j,actualColumn:oe,mergeInfo:G}=z,q=Math.min(j,W.startRow,G.startRow),ee=Math.max(j,W.endRow,G.endRow),ae=Math.min(oe,W.startColumn,G.startColumn),se=Math.max(oe,W.endColumn,G.endColumn),ce=s.getMergeBounding(q,ae,ee,se),he=s.getNoMergeCellPositionByIndex(ce.startRow,ce.startColumn),le=s.getNoMergeCellPositionByIndex(ce.endRow,ce.endColumn),$e={startColumn:ce.startColumn,startRow:ce.startRow,endColumn:ce.endColumn,endRow:ce.endRow,startY:he.startY,endY:le.endY,startX:he.startX,endX:le.endX,rangeType:n},ge=s.getCellByIndex(j,oe);this._startSelectionRange={startColumn:ge.mergeInfo.startColumn,startRow:ge.mergeInfo.startRow,endColumn:ge.mergeInfo.endColumn,endRow:ge.mergeInfo.endRow,startY:ge.mergeInfo.startY||0,endY:ge.mergeInfo.endY||0,startX:ge.mergeInfo.startX||0,endX:ge.mergeInfo.endX||0,rangeType:n},$.update($e,B,F,this._selectionStyle,z)}else this._isRemainLastEnable&&$&&!e.ctrlKey&&!e.shiftKey&&!this._isSkipRemainLastEnable?$.update(W,B,F,this._selectionStyle,T):($=new Un(d,Z.length+t,this._isHeaderHighlight,this._themeService),new no($,s,d,this._themeService,this._injector),$.update(W,B,F,this._selectionStyle,T),Z.push($));this._selectionMoveStart$.next(this.getSelectionDataWithStyle()),this.hasSelection=!0,this._endSelection(),d.disableEvent();const Q=d.getActiveViewportByCoord(b.Vector2.FromArray([m,g])),re=b.ScrollTimer.create(this._scene,r);re.startScroll((u==null?void 0:u.left)??0,(u==null?void 0:u.top)??0,u),this._scrollTimer=re,this._addCancelObserver(),(n===l.RANGE_TYPE.ROW||n===l.RANGE_TYPE.COLUMN)&&this._moving(m,g,$,n);let Y=0,L=0,U=m,X=g;this._moveObserver=d.onPointerMoveObserver.add(j=>{var ge;const{offsetX:oe,offsetY:G}=j,{x:q,y:ee}=d.getRelativeCoord(b.Vector2.FromArray([oe,G]));this._moving(q,ee,$,n);let ae=q,se=ee;const ce=this.getActiveSelection(),he=(ge=this._sheetSkeletonManagerService.getCurrent())==null?void 0:ge.skeleton.getWorksheetConfig().freeze,le=ce==null?void 0:ce.model,$e=d.getActiveViewportByCoord(b.Vector2.FromArray([oe,G]))??this._getViewportByCell(le==null?void 0:le.endRow,le==null?void 0:le.endColumn);if(Q&&$e&&u){const lt=U<u.left&&q>u.left||U>u.left&&q<u.left,ct=X<u.top&&ee>u.top||X>u.top&&ee<u.top;lt&&(Y+=1),ct&&(L+=1);const Ce=Q.viewPortKey,ze=$e.viewPortKey;if(Ce===V.VIEW_ROW_TOP)G<u.top&&((le==null?void 0:le.endRow)??0)<((he==null?void 0:he.startRow)??0)?se=u.top:ct&&L%2===1&&u.scrollTo({y:0});else if(Ce===V.VIEW_COLUMN_LEFT)oe<u.left&&((le==null?void 0:le.endColumn)??0)<((he==null?void 0:he.startColumn)??0)?ae=u.left:lt&&Y%2===1&&u.scrollTo({x:0});else if(Ce===ze){let Re=!1,xe=!1;Ce===V.VIEW_MAIN_LEFT_TOP?(Re=!0,xe=!0):Ce===V.VIEW_MAIN_TOP?xe=!0:Ce===V.VIEW_MAIN_LEFT&&(Re=!0),((le==null?void 0:le.endRow)??0)>((he==null?void 0:he.startRow)??0)&&(xe=!1),((le==null?void 0:le.endColumn)??0)>((he==null?void 0:he.startColumn)??0)&&(Re=!1),Re&&(ae=u.left),xe&&(se=u.top)}else{const Re={x:Q.scrollX,y:Q.scrollY},xe={x:$e.scrollX,y:$e.scrollY},qn=Re.x!==xe.x&&lt&&Y%2===1,Jn=Re.y!==xe.y&&ct&&L%2===1;(qn||Jn)&&(u.scrollTo({x:qn?Re.x:void 0,y:Jn?Re.y:void 0}),qn||(ae=u.left),Jn||(se=u.top)),(Ce===V.VIEW_MAIN_LEFT_TOP&&ze===V.VIEW_MAIN_LEFT||ze===V.VIEW_MAIN_LEFT_TOP&&Ce===V.VIEW_MAIN_LEFT)&&(ae=u.left),(Ce===V.VIEW_MAIN_LEFT_TOP&&ze===V.VIEW_MAIN_TOP||ze===V.VIEW_MAIN_LEFT_TOP&&Ce===V.VIEW_MAIN_TOP)&&(se=u.top)}U=q,X=ee}re.scrolling(ae,se,()=>{this._moving(q,ee,$,n)})}),this._upObserver=d.onPointerUpObserver.add(j=>{this._endSelection(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),this._shortcutService.setDisable(!1)}),this._shortcutService.setDisable(!0)}convertSelectionRangeToData(e){const{range:t,primary:n,style:o}=e;let r=this.convertRangeDataToSelection(t);return r==null&&(r={startRow:-1,startColumn:-1,endRow:-1,endColumn:-1,startY:0,endY:0,startX:0,endX:0,rangeType:l.RANGE_TYPE.NORMAL}),{rangeWithCoord:r,primaryWithCoord:this.convertCellRangeToInfo(n),style:o}}convertRangeDataToSelection(e){const{startRow:t,startColumn:n,endRow:o,endColumn:r,rangeType:s}=e,a=this._scene,c=this._skeleton;if(a==null||c==null)return;a.getAncestorScale();const d=c.getNoMergeCellPositionByIndex(t,n),u=c.getNoMergeCellPositionByIndex(o,r);return{startRow:t,startColumn:n,endRow:o,endColumn:r,rangeType:s,startY:(d==null?void 0:d.startY)||0,endY:(u==null?void 0:u.endY)||0,startX:(d==null?void 0:d.startX)||0,endX:(u==null?void 0:u.endX)||0}}convertCellRangeToInfo(e){if(e==null)return;const t=this._scene,n=this._skeleton;if(t==null||n==null)return;const{actualRow:o,actualColumn:r,isMerged:s,isMergedMainCell:a,startRow:c,startColumn:d,endRow:u,endColumn:h}=e,m=n.getNoMergeCellPositionByIndex(o,r),g=n.getNoMergeCellPositionByIndex(c,d),S=n.getNoMergeCellPositionByIndex(u,h);return{actualRow:o,actualColumn:r,isMerged:s,isMergedMainCell:a,startX:m.startX,startY:m.startY,endX:m.endX,endY:m.endY,mergeInfo:{startRow:c,startColumn:d,endRow:u,endColumn:h,startY:(g==null?void 0:g.startY)||0,endY:(S==null?void 0:S.endY)||0,startX:(g==null?void 0:g.startX)||0,endX:(S==null?void 0:S.endX)||0}}}_moving(e,t,n,o){const r=this._skeleton,s=this._scene;if(s==null||r==null)return!1;const{startRow:a,startColumn:c,endRow:d,endColumn:u}=this._startSelectionRange,{startRow:h,endRow:m,startColumn:g,endColumn:S}=(n==null?void 0:n.model)||{startRow:-1,endRow:-1,startColumn:-1,endColumn:-1},f=s.getViewport(V.VIEW_MAIN),C=this._getViewportByCell(m,S)??f,R=s.getScrollXYByRelativeCoords(b.Vector2.FromArray([this._startOffsetX,this._startOffsetY]),C),{scaleX:M,scaleY:T}=s.getAncestorScale(),{rowHeaderWidth:w,columnHeaderHeight:E}=r;o===l.RANGE_TYPE.ROW?e=Number.POSITIVE_INFINITY:o===l.RANGE_TYPE.COLUMN&&(t=Number.POSITIVE_INFINITY);const y=this._getSelectedRangeWithMerge(e,t,M,T,R);if(!y)return!1;const{rangeWithCoord:x,primaryWithCoord:O}=y,{startRow:A,startColumn:k,endColumn:N,endRow:B}=x,F=Math.min(A,a),W=Math.min(k,c),$=Math.max(B,d),Z=Math.max(N,u);let z={startRow:F,startColumn:W,endRow:$,endColumn:Z};if(this._isDetectMergedCell&&(z=r.getSelectionBounding(F,W,$,Z)),!z)return!1;const{startRow:Q,startColumn:re,endRow:Y,endColumn:L}=z,U=r.getNoMergeCellPositionByIndex(Q,re),X=r.getNoMergeCellPositionByIndex(Y,L),j={startColumn:re,startRow:Q,endColumn:L,endRow:Y,startY:(U==null?void 0:U.startY)||0,endY:(X==null?void 0:X.endY)||0,startX:(U==null?void 0:U.startX)||0,endX:(X==null?void 0:X.endX)||0};(g!==re||h!==Q||S!==L||m!==Y)&&n!=null&&(n.update(j,w,E),this._selectionMoving$.next(this.getSelectionDataWithStyle()))}_endSelection(){var n,o;const e=this._scene;if(e==null)return;e.onPointerMoveObserver.remove(this._moveObserver),e.onPointerUpObserver.remove(this._upObserver),e.enableEvent(),(n=this._scrollTimer)==null||n.dispose();const t=(o=e.getEngine())==null?void 0:o.activeScene;t==null||t.onPointerDownObserver.remove(this._cancelDownObserver),t==null||t.onPointerUpObserver.remove(this._cancelUpObserver)}_addCancelObserver(){var n;const e=this._scene;if(e==null)return;const t=(n=e.getEngine())==null?void 0:n.activeScene;t==null||t===e||(t.onPointerDownObserver.remove(this._cancelDownObserver),t.onPointerUpObserver.remove(this._cancelUpObserver),this._cancelDownObserver=t.onPointerDownObserver.add(o=>{this._endSelection()}),this._cancelUpObserver=t.onPointerUpObserver.add(o=>{this._endSelection()}))}_getSelectedRangeWithMerge(e,t,n,o,r){var R;if(this._isDetectMergedCell){const M=(R=this._skeleton)==null?void 0:R.calculateCellIndexByPosition(e,t,n,o,r),T=l.makeCellToSelection(M);return T==null?void 0:{primaryWithCoord:M,rangeWithCoord:T}}const s=this._skeleton;if(s==null)return;const a=s.getCellPositionByOffset(e,t,n,o,r),{row:c,column:d}=a,u=s.getNoMergeCellPositionByIndex(c,d),{startX:h,startY:m,endX:g,endY:S}=u,f={startY:m,endY:S,startX:h,endX:g,startRow:c,endRow:c,startColumn:d,endColumn:d};return{primaryWithCoord:{actualRow:c,actualColumn:d,isMerged:!1,isMergedMainCell:!1,startY:m,endY:S,startX:h,endX:g,mergeInfo:f},rangeWithCoord:f}}};exports.SelectionRenderService=Cs([en(0,D.Inject(l.ThemeService)),en(1,I.IShortcutService),en(2,D.Inject(exports.SheetSkeletonManagerService)),en(3,D.Inject(D.Injector))],exports.SelectionRenderService);const _e=D.createIdentifier("deprecated.univer.sheet.selection-render-service");var Is=Object.defineProperty,Rs=Object.getOwnPropertyDescriptor,Ms=(i,e,t,n)=>{for(var o=n>1?void 0:n?Rs(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Is(e,t,o),o},Qe=(i,e)=>(t,n)=>e(t,n,i);const bs=1e4,Xt=D.createIdentifier("univer.mark-selection-service");exports.MarkSelectionService=class extends l.Disposable{constructor(t,n,o,r,s,a,c){super();v(this,"_shapeMap",new Map);this._currentService=t,this._renderManagerService=n,this._selectionRenderService=o,this._commandService=r,this._sheetSkeletonManagerService=s,this._themeService=a,this._selectionManagerService=c}addShape(t,n=[],o=bs){const r=this._currentService.getCurrentUniverSheetInstance(),s=r.getActiveSheet().getSheetId(),a=l.Tools.generateRandomId();return this._shapeMap.set(a,{selection:t,subUnitId:s,unitId:r.getUnitId(),zIndex:o,control:null,exits:n}),this.refreshShapes(),a}refreshShapes(){const t=this._currentService.getCurrentUniverSheetInstance().getUnitId(),n=this._currentService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();this._shapeMap.forEach(o=>{var M;const{unitId:r,subUnitId:s,selection:a,control:c,zIndex:d}=o;if(c&&c.dispose(),r!==t||s!==n)return;const{style:u}=a,{scene:h}=this._renderManagerService.getRenderById(r)||{},{rangeWithCoord:m,primaryWithCoord:g}=this._selectionRenderService.convertSelectionRangeToData(a),S=(M=this._sheetSkeletonManagerService.getCurrent())==null?void 0:M.skeleton;if(!h||!S)return;const{rowHeaderWidth:f,columnHeaderHeight:C}=S,R=new Un(h,d,!1,this._themeService);R.update(m,f,C,u,g),o.control=R})}getShapeMap(){return this._shapeMap}removeShape(t){const n=this._shapeMap.get(t);if(!n)return;const{control:o}=n;o&&o.dispose(),this._shapeMap.delete(t)}removeAllShapes(){for(const t of this._shapeMap.values()){const{control:n}=t;n&&n.dispose()}this._shapeMap.clear()}};exports.MarkSelectionService=Ms([Qe(0,l.IUniverInstanceService),Qe(1,b.IRenderManagerService),Qe(2,_e),Qe(3,l.ICommandService),Qe(4,D.Inject(exports.SheetSkeletonManagerService)),Qe(5,D.Inject(l.ThemeService)),Qe(6,D.Inject(_.SelectionManagerService))],exports.MarkSelectionService);const ws=10,Ts=6;function Es(){return l.Tools.generateRandomId(Ts)}function ys(i){const e=i.match(/data-copy-id="([^\s]+)"/);return e&&e[1]?e[1]:null}class Os{constructor(){v(this,"_cache",new l.LRUMap(ws))}set(e,t){this._cache.set(e,t)}get(e){return this._cache.get(e)}del(e){this._cache.delete(e)}clear(){this._cache.clear()}}const tn=new Os;var ot=(i=>(i.COPY="COPY",i.CUT="CUT",i))(ot||{});function xs(i,e,t,n,o){const r=[],s=[];if(n.copyType===ot.CUT){const{undos:a,redos:c}=As(i,e,o);r.push(...c),s.push(...a)}else{const{undos:a,redos:c}=jo(e,t,o);r.push(...c),s.push(...a);const{undos:d,redos:u}=Fo(e,t,o);r.push(...u),s.push(...d);const{undos:h,redos:m}=Wo(e,t,o);r.push(...m),s.push(...h);const{undos:g,redos:S}=Si(e,t,o);r.push(...S),s.push(...g)}return{undos:s,redos:r}}function As(i,e,t){let n=[],o=[];const{range:r,subUnitId:s,unitId:a}=i,{range:c,subUnitId:d}=e;if(r&&c){const u=t.get(l.IUniverInstanceService),h=t.get(_.SheetInterceptorService),m=u.getUniverSheetInstance(a),g=m==null?void 0:m.getSheetBySheetId(s),S=m==null?void 0:m.getSheetBySheetId(d);if(g&&S){const f=new l.ObjectMatrix,C=new l.ObjectMatrix,R=(z,Q)=>({startRow:z,endRow:z,startColumn:Q,endColumn:Q}),M=g.getCellMatrix(),T=S.getCellMatrix();l.Range.foreach(r,(z,Q)=>{f.setValue(z,Q,M.getValue(z,Q)),C.setValue(z,Q,null)});const w=new l.ObjectMatrix;l.Range.foreach(c,(z,Q)=>{w.setValue(z,Q,T.getValue(z,Q))});const E=new l.ObjectMatrix;l.Range.foreach(r,(z,Q)=>{const re=R(z,Q),Y=l.Rectangle.getRelativeRange(re,r),L=l.Rectangle.getPositionRange(Y,c);E.setValue(L.startRow,L.startColumn,M.getValue(z,Q))});const y={from:{value:C.getMatrix(),subUnitId:s},to:{value:E.getMatrix(),subUnitId:d},unitId:a},x={from:{value:f.getMatrix(),subUnitId:s},to:{value:w.getMatrix(),subUnitId:d},unitId:a},O=h.onCommandExecute({id:_.MoveRangeCommand.id,params:{toRange:c,fromRange:r}}),A=g.getMergeData(),k=S.getMergeData(),N=A.filter(z=>l.Rectangle.intersects(z,r)),B=k.filter(z=>l.Rectangle.intersects(z,c)),F=N.map(z=>l.Rectangle.getRelativeRange(z,r)).map(z=>l.Rectangle.getPositionRange(z,c)),W=_.getAddMergeMutationRangeByType(F).filter(z=>!k.some(Q=>l.Rectangle.equals(z,Q))),$=[{id:_.RemoveWorksheetMergeMutation.id,params:{unitId:a,subUnitId:s,ranges:N}},{id:_.RemoveWorksheetMergeMutation.id,params:{unitId:a,subUnitId:s,ranges:B}},{id:_.AddWorksheetMergeMutation.id,params:{unitId:a,subUnitId:d,ranges:W}}],Z=[{id:_.RemoveWorksheetMergeMutation.id,params:{unitId:a,subUnitId:d,ranges:W}},{id:_.AddWorksheetMergeMutation.id,params:{unitId:a,subUnitId:d,ranges:B}},{id:_.AddWorksheetMergeMutation.id,params:{unitId:a,subUnitId:s,ranges:N}}];n=[{id:_.MoveRangeMutation.id,params:y},...O.redos,...$,{id:_.SetSelectionsOperation.id,params:{unitId:a,sheetId:d,pluginName:_.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:c}]}}],o=[{id:_.SetSelectionsOperation.id,params:{unitId:a,sheetId:s,pluginName:_.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:r}]}},...O.undos,...Z,{id:_.MoveRangeMutation.id,params:x}]}}return{undos:o,redos:n}}function Fo(i,e,t){const{unitId:n,subUnitId:o,range:r}=i,s=[],a=[],{startColumn:c,startRow:d}=r,u=new l.ObjectMatrix;e.forValue((g,S,f)=>{u.setValue(g+d,S+c,{v:f.v})});const h={unitId:n,subUnitId:o,cellValue:u.getData()};s.push({id:_.SetRangeValuesMutation.id,params:h});const m=_.SetRangeValuesUndoMutationFactory(t,h);return a.push({id:_.SetRangeValuesMutation.id,params:m}),{undos:a,redos:s}}function Wo(i,e,t){const n=[],o=[],{unitId:r,subUnitId:s,range:a}=i,{startColumn:c,startRow:d}=a,u=new l.ObjectMatrix;e.forValue((g,S,f)=>{var R;const C={s:f.s};(R=f.p)!=null&&R.body&&(C.p=f.p),u.setValue(g+d,S+c,C)});const h={unitId:r,subUnitId:s,cellValue:u.getData()};n.push({id:_.SetRangeValuesMutation.id,params:h});const m=_.SetRangeValuesUndoMutationFactory(t,h);return o.push({id:_.SetRangeValuesMutation.id,params:m}),{undos:o,redos:n}}function jo(i,e,t){const n=[],o=[],r=new l.ObjectMatrix,{unitId:s,subUnitId:a,range:c}=i,{startColumn:d,startRow:u}=c;if(e.forValue((h,m,g)=>{g.s&&r.setValue(h+u,m+d,{s:null})}),r.getLength()>0){const h={subUnitId:a,unitId:s,cellValue:r.getData()};n.push({id:_.SetRangeValuesMutation.id,params:h});const m=_.SetRangeValuesUndoMutationFactory(t,h);o.push({id:_.SetRangeValuesMutation.id,params:m})}return{undos:o,redos:n}}function Si(i,e,t){const n=[],o=[],{unitId:r,subUnitId:s,range:a}=i,{startColumn:c,startRow:d,endColumn:u,endRow:h}=a;let m=!1;const g=[];if(e.forValue((C,R,M)=>{if(M.rowSpan){const T=M.colSpan||1,w={startRow:d+C,endRow:d+C+M.rowSpan-1,startColumn:c+R,endColumn:c+R+T-1};g.push(w),m=!0}else if(M.colSpan){const T=M.rowSpan||1,w={startRow:d+C,endRow:d+C+T-1,startColumn:c+R,endColumn:c+R+M.colSpan-1};g.push(w),m=!0}}),m){const R=t.get(l.IUniverInstanceService).getUniverSheetInstance(r),M=R==null?void 0:R.getSheetBySheetId(s);if(R&&M){const w=M.getMergeData().filter(x=>l.Rectangle.intersects({startRow:d,startColumn:c,endRow:h,endColumn:u},x)),E={unitId:r,subUnitId:s,ranges:w};n.push({id:_.RemoveWorksheetMergeMutation.id,params:E});const y=_.RemoveMergeUndoMutationFactory(t,E);o.push({id:_.AddWorksheetMergeMutation.id,params:y})}}const S={unitId:r,subUnitId:s,ranges:g};n.push({id:_.AddWorksheetMergeMutation.id,params:S});const f=_.AddMergeUndoMutationFactory(t,S);return o.push({id:_.RemoveWorksheetMergeMutation.id,params:f}),{undos:o,redos:n}}function $o(i){let e=i.replace(/(\r\n|\n)/g,"\r");e.endsWith(`\r
2
+ `)||(e+=`\r
3
+ `);const t=[];for(let n=0;n<e.length;n++)e[n]==="\r"&&t.push({startIndex:n});return{dataStream:e,paragraphs:t,sectionBreaks:[{startIndex:e.indexOf(`
4
+ `)}]}}function Ds(i){const e=new DOMParser,t=`<x-univer id="univer-root">${i}</x-univer>`;return e.parseFromString(t,"text/html").querySelector("#univer-root")}function Ns(i){const e=i.style,t={};for(let n=0;n<e.length;n++){const o=e[n],r=e.getPropertyValue(o);switch(o){case"margin-top":{const s=parseInt(r);t.spaceAbove=/pt/.test(r)?_i(s):s;break}case"margin-bottom":{const s=parseInt(r);t.spaceBelow=/pt/.test(r)?_i(s):s;break}}}return Object.getOwnPropertyNames(t).length?t:null}function _i(i){return i/.75}function io(i,e){const t=[];for(let n=0,o=i.length;n<o;n++)i[n]===l.DataStreamTreeTokenType.PARAGRAPH&&t.push({startIndex:n});if(e)for(const n of t)e.bullet&&(n.bullet=l.Tools.deepClone(e.bullet)),e.paragraphStyle&&(n.paragraphStyle=l.Tools.deepClone(e.paragraphStyle));return t}function Ti(i){const e=i.style,t={},n=i.tagName.toLowerCase();switch(n){case"b":case"em":case"strong":{t.bl=l.BooleanNumber.TRUE;break}case"s":{t.st={s:l.BooleanNumber.TRUE};break}case"u":{t.ul={s:l.BooleanNumber.TRUE};break}case"i":{t.it=l.BooleanNumber.TRUE;break}case"sub":case"sup":{t.va=n==="sup"?l.BaselineOffset.SUPERSCRIPT:l.BaselineOffset.SUBSCRIPT;break}}for(let o=0;o<e.length;o++){const r=e[o],s=e.getPropertyValue(r);switch(r){case"font-family":{t.ff=s;break}case"font-size":{const a=parseInt(s);Number.isNaN(a)||(t.fs=/pt$/.test(s)?_i(a):a);break}case"font-style":{s==="italic"&&(t.it=l.BooleanNumber.TRUE);break}case"font-weight":{Number(s)>400&&(t.bl=l.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(s)?t.ul={s:l.BooleanNumber.TRUE}:/overline/.test(s)?t.ol={s:l.BooleanNumber.TRUE}:/line-through/.test(s)&&(t.st={s:l.BooleanNumber.TRUE});break}case"color":{const a=new l.ColorKit(s);a.isValid&&(t.cl={rgb:a.toRgbString()});break}case"background-color":{const a=new l.ColorKit(s);a.isValid&&(t.bg={rgb:a.toRgbString()});break}}}return t}function oo(i,e){const t=i.tagName.toLowerCase();return typeof e=="string"?t===e:Array.isArray(e)?e.some(n=>n===t):e(i)}const Fn=class Fn{constructor(e){v(this,"styleCache",new Map);v(this,"styleRules",[]);v(this,"afterProcessRules",[]);v(this,"getCurrentSkeleton");this.getCurrentSkeleton=e.getCurrentSkeleton}static use(e){if(this.pluginList.includes(e))throw new Error(`Univer paste plugin ${e.name} already added`);this.pluginList.push(e)}convert(e){const t=Fn.pluginList.find(m=>m.checkPasteType(e));t&&(this.styleRules=[...t.stylesRules],this.afterProcessRules=[...t.afterProcessRules]);const n=new l.ObjectMatrix,o=Ds(e),r={dataStream:"",textRuns:[]},s=[],a=e.match(/<table\b[^>]*>([\s\S]*?)<\/table>/gi),c=[];this.process(null,o==null?void 0:o.childNodes,r,c);const{paragraphs:d,dataStream:u,textRuns:h}=r;if(d){const m=d.map(g=>g.startIndex+1);m.unshift(0);for(let g=0;g<m.length;g++){let S;g===m.length-1?S=`${u.substring(m[g])}\r
5
+ `:S=`${u.substring(m[g],m[g+1]-1)}\r
6
+ `;const f=[];h==null||h.forEach(R=>{R.st>=m[g]&&R.ed<=m[g+1]&&f.push({st:R.st-m[g],ed:R.ed-m[g],ts:R.ts})});const C=this._generateDocumentDataModelSnapshot({body:{dataStream:S,textRuns:f,paragraphs:io(S)}});n.setValue(n.getLength(),0,{v:S,p:C}),s.push({}),a&&c.forEach(R=>{const M=n.getDataRange().endRow+1;if(R.index===g){const T=a.shift(),{cellMatrix:w,colProperties:E,rowProperties:y}=this._parseTable(T);w&&w.forValue((x,O,A)=>{n.setValue(M+x,O,A)}),s.push(...y)}})}}else{if(u){const m=`${u}\r
7
+ `,g={dataStream:m,textRuns:h,paragraphs:io(m)},S=this._generateDocumentDataModelSnapshot({body:g});n.setValue(0,0,{v:u,p:S}),s.push({})}a&&a.forEach(m=>{const g=n.getDataRange().endRow+1,{cellMatrix:S}=this._parseTable(m);S&&S.forValue((f,C,R)=>{const{rowSpan:M=1,colSpan:T=1}=R;for(let w=0;w<M;w++)for(let E=0;E<T;E++)n.setValue(g+f+w,C+E,{v:""});n.setValue(g+f,C,R)}),s.push(...s)})}return{rowProperties:[],colProperties:[],cellMatrix:n}}_parseTable(e){const t=new l.ObjectMatrix;Ls(e);const{rowProperties:n,rowCount:o,cellMatrix:r}=Ps(e);return r&&r.forValue((s,a,c)=>{var u;const d=I.handleStringToStyle(void 0,(u=c.properties)==null?void 0:u.style);if(/\r|\n/.test(c.content)){const h=$o(c.content),m=this._generateDocumentDataModelSnapshot({body:h});t.setValue(s,a,{v:c.content,p:m,s:d,rowSpan:c.rowSpan,colSpan:c.colSpan})}else t.setValue(s,a,{v:c.content,s:d,rowSpan:c.rowSpan,colSpan:c.colSpan})}),{rowProperties:[],colProperties:[],cellMatrix:t}}_generateDocumentDataModelSnapshot(e){var a;const t=this.getCurrentSkeleton();if(t==null)return null;const{skeleton:n}=t,o=(a=n.getBlankCellDocumentModel())==null?void 0:a.documentModel,s={...o==null?void 0:o.getSnapshot(),...e};return o==null||o.reset(s),o==null?void 0:o.getSnapshot()}process(e,t,n,o){var r,s;for(const a of t)if(a.nodeName.toLowerCase()==="table")o.push({index:((r=n==null?void 0:n.paragraphs)==null?void 0:r.length)||0});else if(a.nodeType===Node.TEXT_NODE){const c=(s=a.nodeValue)==null?void 0:s.replace(/[\r\n]/g,"");let d;e&&this.styleCache.has(e)&&(d=this.styleCache.get(e));const u={dataStream:"",textRuns:[]};n.dataStream+=c,u.dataStream+=c,d&&Object.getOwnPropertyNames(d).length&&(n.textRuns.push({st:n.dataStream.length-c.length,ed:n.dataStream.length,ts:d}),u.textRuns.push({st:n.dataStream.length-c.length,ed:n.dataStream.length,ts:d}))}else if(a.nodeType===Node.ELEMENT_NODE){const c=e?this.styleCache.get(e):{},d=this.styleRules.find(({filter:g})=>oo(a,g)),u=d?d.getStyle(a):Ti(a);this.styleCache.set(a,{...c,...u});const{childNodes:h}=a;this.process(a,h,n,o);const m=this.afterProcessRules.find(({filter:g})=>oo(a,g));m&&m.handler(n,a)}}};v(Fn,"pluginList",[]);let Ft=Fn;function Ps(i){const e=/<tr([\s\S]*?)>([\s\S]*?)<\/tr>/gi,t=i.matchAll(e);if(!t)return{rowProperties:[],rowCount:0,colCount:0,cellMatrix:null};const n=Array.from(t),o=n.map(a=>Ei(a[1])),{colCount:r,cellMatrix:s}=Hs(n.map(a=>a[2]));return{rowProperties:o,rowCount:o.length,colCount:r,cellMatrix:s}}function Hs(i){const e=new l.ObjectMatrix,t=new Map,n=/<td([\s\S]*?)>([\s\S]*?)<\/td>/gi;let o=0,r=0,s=0;return i.forEach((a,c)=>{const d=c===0,u=a.matchAll(n);r=0,Array.from(u).forEach(h=>{const m=Ei(h[1]),g=Us(h[2].replace("<br>","\r").replace(/<\/?[^>]*>/g,"")),S=m.rowspan?+m.rowspan:1,f=m.colspan?+m.colspan:1;if(!d){for(let R=r;R<o;R++)if(!(t.get(R)>=s)){r=R;break}}const C={content:g,properties:m};f>1&&(C.colSpan=+f),S>1&&(C.rowSpan=+S),d&&(o+=f);for(let R=r;R<r+f;R++)t.set(R,s+S-1);e.setValue(s,r,C),r+=f}),s+=1}),{colCount:o,cellMatrix:e}}function Ei(i){if(!i)return{};const e=/([\w-]+)="([^"]*)"/gi,t=i.matchAll(e),n={};return Array.from(t).forEach(o=>{const[r,s,a]=o;n[s]=a}),n}function Ls(i){const e=/<colgroup([\s\S]*?)>(.*?)<\/colgroup>/,t=i.match(e);if(!t||!t[2])return null;const n=/<col([\s\S]*?)>/g,o=t[2].matchAll(n);return o?Array.from(o).map(r=>Ei(r[1])):null}function Us(i){const e={"&lt;":"<","&gt;":">","&amp;":"&","&quot;":'"',"&#39;":"'","&nbsp;":" "};return i.replace(/&lt;|&gt;|&amp;|&quot;|&#39;|&nbsp;|<br>/g,t=>e[t])}const ks={name:"univer-doc-paste-plugin-lark",checkPasteType(i){return/lark-record-clipboard/i.test(i)},stylesRules:[{filter:["s"],getStyle(i){const e=Ti(i);return{st:{s:l.BooleanNumber.TRUE},...e}}}],afterProcessRules:[{filter(i){return i.tagName==="DIV"&&/ace-line/i.test(i.className)},handler(i){i.paragraphs==null&&(i.paragraphs=[]),i.paragraphs.push({startIndex:i.dataStream.length}),i.dataStream+="\r"}}]},Vs=ks,Bs={name:"univer-doc-paste-plugin-word",checkPasteType(i){return/word|mso/i.test(i)},stylesRules:[{filter:["b"],getStyle(i){const e=Ti(i);return{bl:l.BooleanNumber.TRUE,...e}}}],afterProcessRules:[{filter(i){return i.tagName==="P"&&/mso/i.test(i.className)},handler(i,e){i.paragraphs==null&&(i.paragraphs=[]);const t={startIndex:i.dataStream.length},n=Ns(e);n&&(t.paragraphStyle=n),i.paragraphs.push(t),i.dataStream+="\r"}}]},Fs=Bs;function Ws(i,e,t,n){const o=t.map(c=>{var d;return(d=c.onCopyRow)==null?void 0:d.call(c,i)}).filter(c=>!!c),r=yi(o),s=Oi(r),a=e.map(c=>js(i,c,t,n)).filter(c=>!!c).join("");return`<tr${s}>${a}</tr>`}function js(i,e,t,n){const o=n.getValue(i,e),r=t.map(d=>{var u;return(u=d.onCopyCellStyle)==null?void 0:u.call(d,i,e,o==null?void 0:o.rowSpan,o==null?void 0:o.colSpan)}).filter(d=>!!d),s=yi(r),a=Oi(s),c=t.reduce((d,u)=>{var h;return d||((h=u.onCopyCellContent)==null?void 0:h.call(u,i,e))||""},"");return`<td${a}>${c}</td>`}function $s(i,e){return`<colgroup>${i.map(n=>{const o=e.map(a=>{var c;return(c=a.onCopyColumn)==null?void 0:c.call(a,n)}).filter(a=>!!a),r=yi(o);return`<col ${Oi(r)}>`}).join("")}</colgroup>`}function yi(i){return i.reduce((e,t)=>(Object.keys(t).forEach(o=>{e[o]?e[o]+=`;${t[o]}`:e[o]=t[o]}),e),{})}function Oi(i){return Object.keys(i).reduce((e,t)=>(e+=` ${t}="${i[t]}"`,e),"")}function zs(i,e){const t=[];for(let n=i;n<=e;n++)t.push(n);return t}class Xs{convert(e,t,n){const{startColumn:o,endColumn:r}=t,s=$s(zs(o,r),n),a=[],{startRow:c,endRow:d,startColumn:u,endColumn:h}=e.getDataRange();for(let g=c;g<=d;g++){const S=Array.from({length:h-u+1},(f,C)=>u+C);a.push(Ws(g,S,n,e))}return`<google-sheets-html-origin><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" border="1" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none">${s}
8
+ <tbody>${a.join("")}</tbody></table>`}}var Ys=Object.defineProperty,Zs=Object.getOwnPropertyDescriptor,Gs=(i,e,t,n)=>{for(var o=n>1?void 0:n?Zs(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Ys(e,t,o),o},Xe=(i,e)=>(t,n)=>e(t,n,i);const pe={DEFAULT_COPY:"default-copy",DEFAULT_PASTE:"default-paste",SPECIAL_PASTE_VALUE:"special-paste-value",SPECIAL_PASTE_FORMAT:"special-paste-format",SPECIAL_PASTE_COL_WIDTH:"special-paste-col-width",SPECIAL_PASTE_BESIDES_BORDER:"special-paste-besides-border"};Ft.use(Fs);Ft.use(Vs);const bt=D.createIdentifier("sheet.clipboard-service");exports.SheetClipboardService=class extends l.Disposable{constructor(t,n,o,r,s,a,c,d){super();v(this,"_clipboardHooks",[]);v(this,"_clipboardHooks$",new H.BehaviorSubject([]));v(this,"clipboardHooks$",this._clipboardHooks$.asObservable());v(this,"_htmlToUSM");v(this,"_usmToHtml");v(this,"_copyMarkId",null);v(this,"_pasteType",pe.DEFAULT_PASTE);this._logService=t,this._currentUniverService=n,this._selectionManagerService=o,this._clipboardInterfaceService=r,this._undoRedoService=s,this._commandService=a,this._markSelectionService=c,this._sheetSkeletonManagerService=d,this._htmlToUSM=new Ft({getCurrentSkeleton:()=>this._sheetSkeletonManagerService.getCurrent()}),this._usmToHtml=new Xs}async copy(t=ot.COPY){const n=this._selectionManagerService.getLast();if(!n)return!1;const o=this._clipboardHooks;o.reduce((R,M)=>{var w;const T=(w=M.getFilteredOutRows)==null?void 0:w.call(M);return T==null||T.forEach(E=>R.add(E)),R},new Set);const{startColumn:r,startRow:s,endColumn:a,endRow:c}=n.range,d=this._currentUniverService.getCurrentUniverSheetInstance(),u=d.getActiveSheet(),h=u.getMatrixWithMergedCells(s,r,c,a),m=new l.ObjectMatrix;for(let R=s;R<=c;R++)for(let M=r;M<=a;M++){const T=h.getValue(R,M);T?m.setValue(R-s,M-r,{...ro(),...l.Tools.deepClone(T)}):m.setValue(R-s,M-r,ro())}o.forEach(R=>{var M;return(M=R.onBeforeCopy)==null?void 0:M.call(R,d.getUnitId(),u.getSheetId(),n.range)});let g=this._usmToHtml.convert(h,n.range,o);const S=Ks(m),f=Es();g=g.replace(/(<[a-z]+)/,(R,M)=>`${M} data-copy-id="${f}"`),tn.set(f,{unitId:d.getUnitId(),subUnitId:u.getSheetId(),range:n.range,matrix:m,copyType:t}),await this._clipboardInterfaceService.write(S,g),this._markSelectionService.removeAllShapes();const C=this._selectionManagerService.createCopyPasteSelection();return this._copyMarkId=this._markSelectionService.addShape({...n,style:C}),o.forEach(R=>{var M;return(M=R.onAfterCopy)==null?void 0:M.call(R)}),!0}async cut(){return this.copy(ot.CUT)}async paste(t,n=pe.DEFAULT_PASTE){const o=t.types,r=o.indexOf(I.PLAIN_TEXT_CLIPBOARD_MIME_TYPE)!==-1?await t.getType(I.PLAIN_TEXT_CLIPBOARD_MIME_TYPE).then(a=>a&&a.text()):"",s=o.indexOf(I.HTML_CLIPBOARD_MIME_TYPE)!==-1?await t.getType(I.HTML_CLIPBOARD_MIME_TYPE).then(a=>a&&a.text()):"";return s?this._pasteHTML(s,n):r?this._pastePlainText(r,n):(this._logService.error("[SheetClipboardService]","No valid data on clipboard"),!1)}addClipboardHook(t){if(this._clipboardHooks.findIndex(o=>o.id===t.id)!==-1)return this._logService.error("[SheetClipboardService]","hook already exists",t.id),{dispose:()=>{}};const n=this._clipboardHooks.findIndex(o=>{const r=o.priority||0;return(t.priority||0)<r});return this._clipboardHooks.splice(n!==-1?n:this._clipboardHooks.length,0,t),this._notifyClipboardHook(),l.toDisposable(()=>{const o=this._clipboardHooks.indexOf(t);o>-1&&(this._clipboardHooks.splice(o,1),this._notifyClipboardHook())})}getClipboardHooks(){return this._clipboardHooks}_notifyClipboardHook(){this._clipboardHooks$.next(this._clipboardHooks)}async _pastePlainText(t,n){const o=this._getPastingTarget();if(!o.selection)return!1;const r=o.selection.range,{unitId:s,subUnitId:a}=o,c=this._clipboardHooks,d=[];if(c.some(S=>{var f;return d.push(S)&&((f=S.onBeforePaste)==null?void 0:f.call(S,{unitId:s,subUnitId:a,range:r}))===!1}))return d.forEach(S=>{var f;return(f=S.onAfterPaste)==null?void 0:f.call(S,!1)}),!1;const h=[],m=[];d.forEach(S=>{var C;const f=(C=S.onPastePlainText)==null?void 0:C.call(S,{unitId:s,subUnitId:a,range:r},t,{pasteType:n});f&&(h.push(...f.redos),m.push(...f.undos))});const g=h.every(S=>this._commandService.executeCommand(S.id,S.params));return g&&this._undoRedoService.pushUndoRedo({unitID:this._currentUniverService.getCurrentUniverSheetInstance().getUnitId(),undoMutations:m,redoMutations:h}),g}async _pasteHTML(t,n){const o=ys(t);return o&&tn.get(o)?this._pasteInternal(o,n):this._pasteExternal(t,n)}async _pasteExternal(t,n){const o=this._getPastingTarget(),{selection:r,unitId:s,subUnitId:a}=o;if(!r)return!1;const{rowProperties:c,colProperties:d,cellMatrix:u}=this._htmlToUSM.convert(t),{startColumn:h,endColumn:m,startRow:g,endRow:S}=u.getDataRange(),f=S-g+1,C=m-h+1;if(!u||m<h||S<g)return!1;const R=this._transformPastedData(f,C,u,r.range);return R?this._pasteUSM({rowProperties:c,colProperties:d,cellMatrix:u},{unitId:s,subUnitId:a,pastedRange:R},n):!1}async _pasteInternal(t,n){var O,A;const o=this._getPastingTarget(),{selection:r,unitId:s,subUnitId:a}=o,c=l.Tools.deepClone(tn.get(t)),{range:d,matrix:u,unitId:h,subUnitId:m}=c||{};if(!r||!u||!c||!d||!h||!m||!r||!u||!c)return!1;const g=(O=this._currentUniverService.getUniverSheetInstance(h))==null?void 0:O.getStyles();u.forValue((k,N,B)=>{if(typeof B.s=="string"){const F=l.Tools.deepClone(B);F.s=g==null?void 0:g.getStyleByCell(B),u.setValue(k,N,F)}});const{startColumn:S,endColumn:f,startRow:C,endRow:R}=d,M=this._transformPastedData(R-C+1,f-S+1,u,r.range);if(!M)return!1;const T=(A=this._currentUniverService.getUniverSheetInstance(h))==null?void 0:A.getSheetBySheetId(m);if(!T)return!1;const w=T.getColumnManager(),E=T.getConfig().defaultColumnWidth,y=[];for(let k=S;k<=f;k++){const N=w.getColumnOrCreate(k);y.push({width:`${N.w||E}`})}const x=this._pasteUSM({cellMatrix:u,colProperties:y},{unitId:s,subUnitId:a,pastedRange:M},n,{range:d,unitId:c.unitId,subUnitId:c.subUnitId,copyType:c.copyType,copyId:t});return c.copyType===ot.CUT&&(tn.set(t,{...c,matrix:null}),this._copyMarkId&&this._markSelectionService.removeShape(this._copyMarkId),this._copyMarkId=null),x}_pasteUSM(t,n,o,r){const{rowProperties:s,colProperties:a,cellMatrix:c}=t,{unitId:d,subUnitId:u,pastedRange:h}=n,{startColumn:m,endColumn:g}=h,S=g-m+1,f=this._clipboardHooks,C=[];if(f.some(A=>{var k;return C.push(A)&&((k=A.onBeforePaste)==null?void 0:k.call(A,{unitId:d,subUnitId:u,range:h}))===!1}))return C.forEach(A=>{var k;return(k=A.onAfterPaste)==null?void 0:k.call(A,!1)}),!1;if(!c)return!1;const M=r?{unitId:r.unitId,subUnitId:r.subUnitId,range:r.range}:null,T={copyType:(r==null?void 0:r.copyType)||ot.COPY,copyId:r==null?void 0:r.copyId,pasteType:o},w=[],E=[];C.filter(A=>!A.specialPasteInfo&&A.id!==pe.DEFAULT_PASTE||o===A.id).forEach(A=>{var B,F,W;if(s){const $=(B=A.onPasteRows)==null?void 0:B.call(A,{range:h,unitId:d,subUnitId:u},s,{pasteType:o});$&&(w.push(...$.redos),E.push(...$.undos))}const k=(F=A.onPasteColumns)==null?void 0:F.call(A,{range:h,unitId:d,subUnitId:u},a||new Array(S).map(()=>({})),{pasteType:o});k&&(w.push(...k.redos),E.push(...k.undos));const N=(W=A.onPasteCells)==null?void 0:W.call(A,M,{range:h,unitId:d,subUnitId:u},c,T);N&&(w.push(...N.redos),E.push(...N.undos))});const x=this._getSetSelectionOperation(d,u,h,c);x&&w.push(x),this._logService.log("[SheetClipboardService]","pasting mutations",{undoMutationsInfo:E,redoMutationsInfo:w});const O=w.every(A=>this._commandService.executeCommand(A.id,A.params));return O&&this._undoRedoService.pushUndoRedo({unitID:d,undoMutations:E,redoMutations:w}),O}_getSetSelectionOperation(t,n,o,r){var f;const s=(f=this._currentUniverService.getUniverSheetInstance(t))==null?void 0:f.getSheetBySheetId(n);if(!s)return null;const{startRow:a,startColumn:c}=o,d={startRow:a,endRow:a,startColumn:c,endColumn:c},u=_.getPrimaryForRange(d,s),h=r.getValue(0,0),m=(h==null?void 0:h.rowSpan)||1,g=(h==null?void 0:h.colSpan)||1;if(m>1||g>1){const C={startRow:a,endRow:a+m-1,startColumn:c,endColumn:c+g-1};u.startRow=C.startRow,u.endRow=C.endRow,u.startColumn=C.startColumn,u.endColumn=C.endColumn,u.isMerged=!0,u.isMergedMainCell=!0}const S={unitId:t,subUnitId:n,pluginName:_.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:o,primary:u,style:null}]};return{id:_.SetSelectionsOperation.id,params:S}}_getPastingTarget(){const t=this._currentUniverService.getCurrentUniverSheetInstance(),n=t.getActiveSheet(),o=this._selectionManagerService.getLast();return{unitId:t.getUnitId(),subUnitId:n.getSheetId(),selection:o}}_transformPastedData(t,n,o,r){const{startRow:s,startColumn:a,endRow:c,endColumn:d}=r,u=c-s+1,h=d-a+1,f=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getMergeData().filter(E=>l.Rectangle.intersects({startRow:s,startColumn:a,endRow:c,endColumn:d},E)),C=f[0];let R=0,M=0,T=0,w=0;if(C&&(R=C.startRow,M=C.startColumn,T=C.endRow,w=C.endColumn),u%t===0&&h%n===0)if(f.length>0&&(u!==t||h!==n))if(R===s&&M===a&&T===c&&w===d)if(ta(o))for(let y=0;y<u;y++)for(let x=0;x<h;x++){const O=o.getValue(y%t,x%n);O&&o.setValue(y,x,O)}else o.forValue((y,x,O)=>{O.s=null,delete O.colSpan,delete O.rowSpan});else for(let E=0;E<u;E++)for(let y=0;y<h;y++){const x=o.getValue(E%t,y%n);x&&o.setValue(E,y,x)}else for(let E=0;E<u;E++)for(let y=0;y<h;y++){const x=o.getValue(E%t,y%n);x&&o.setValue(E,y,x)}else if(f.length>0)if(this._topLeftCellsMatch(t,n,r))r.endRow=s+t-1,r.endColumn=a+n-1;else{if(c>C.endRow||d>C.endColumn)return null;o.forValue((y,x,O)=>{O.s=null,delete O.colSpan,delete O.rowSpan})}else r.endRow=s+t-1,r.endColumn=a+n-1;return r}_topLeftCellsMatch(t,n,o){const s=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet(),{startRow:a,startColumn:c,endRow:d,endColumn:u}=o,h=Qs(a+t-1,c,c+t-1,s),m=ea(c+n-1,a,a+t-1,s);return!h&&!m}};exports.SheetClipboardService=Gs([Xe(0,l.ILogService),Xe(1,l.IUniverInstanceService),Xe(2,D.Inject(_.SelectionManagerService)),Xe(3,I.IClipboardInterfaceService),Xe(4,l.IUndoRedoService),Xe(5,l.ICommandService),Xe(6,Xt),Xe(7,D.Inject(exports.SheetSkeletonManagerService))],exports.SheetClipboardService);function Ks(i){let e="";return i.forRow((t,n)=>{const o=[];n.forEach(r=>{const s=i.getValue(t,r);if(s){const a=qs(s);o.push(a)}}),e+=o.join(" "),t!==i.getLength()-1&&(e+=`
9
+ `)}),e}function qs(i){const e=i.v;return Js((e==null?void 0:e.toString())||"")}const Js=i=>i.replace(/&/g,"&amp;").replace(/\uFEFF/g,"").replace(/</g,"&lt;").replace(/>/g,"&gt;");function Qs(i,e,t,n){return n.getMergeData().some(o=>o.startRow<=i&&i<o.endRow&&e<=o.startColumn&&o.startColumn<=t)}function ea(i,e,t,n){return n.getMergeData().some(o=>o.startColumn<=i&&i<o.endColumn&&e<=o.startRow&&o.startRow<=t)}function ta(i){let e=0;return i.forValue((t,n,o)=>{if(o&&e++,e>1)return!1}),e>1}function ro(){return{p:null,v:null,s:null,f:null,si:null,t:null}}const zo={id:I.CopyCommand.id,name:"sheet.command.copy",type:l.CommandType.COMMAND,multi:!0,priority:1e3,preconditions:wi,handler:async i=>i.get(bt).copy()},na={id:I.CutCommand.id,name:"sheet.command.cut",type:l.CommandType.COMMAND,multi:!0,priority:1e3,preconditions:wi,handler:async i=>i.get(bt).cut()},wt={id:I.PasteCommand.id,type:l.CommandType.COMMAND,multi:!0,name:"sheet.command.paste",priority:1e3,preconditions:wi,handler:async(i,e)=>{const t=i.get(l.ILogService);if(t.log("[SheetPasteCommand]","the focusing element is",document.activeElement),!document.execCommand("paste")){t.log("[SheetPasteCommand]","failed to execute paste command on the activeElement, trying to use clipboard API.");const r=await i.get(I.IClipboardInterfaceService).read(),s=i.get(bt);return r.length!==0?s.paste(r[0],e==null?void 0:e.value):!1}return!1}},Xo={id:"sheet.command.paste-value",type:l.CommandType.COMMAND,handler:async i=>i.get(l.ICommandService).executeCommand(wt.id,{value:pe.SPECIAL_PASTE_VALUE})},Yo={id:"sheet.command.paste-format",type:l.CommandType.COMMAND,handler:async i=>i.get(l.ICommandService).executeCommand(wt.id,{value:pe.SPECIAL_PASTE_FORMAT})},Zo={id:"sheet.command.paste-col-width",type:l.CommandType.COMMAND,handler:async i=>i.get(l.ICommandService).executeCommand(wt.id,{value:pe.SPECIAL_PASTE_COL_WIDTH})},Go={id:"sheet.command.paste-besides-border",type:l.CommandType.COMMAND,handler:async i=>i.get(l.ICommandService).executeCommand(wt.id,{value:pe.SPECIAL_PASTE_BESIDES_BORDER})};var ia=Object.defineProperty,oa=Object.getOwnPropertyDescriptor,ra=(i,e,t,n)=>{for(var o=n>1?void 0:n?oa(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&ia(e,t,o),o},so=(i,e)=>(t,n)=>e(t,n,i);let Wt=class{constructor(i,e){v(this,"_current",null);v(this,"_shortcutParam",[]);this._currentUniverService=i,this._localeService=e}dispose(){this._shortcutParam=[]}getCurrentBySearch(i){return this._getCurrentBySearch(i)}getCurrent(){return this._getCurrentBySearch(this._current)}addOrUpdate(i){const e=this._getCurrentBySearch({unitId:i.unitId,sheetId:i.sheetId,keycode:i.keycode});if(e!=null){const t=this._shortcutParam.indexOf(e);this._shortcutParam.splice(t,1)}return this._shortcutParam.push(i),e}remove(i){if(i==null)return;const e=this._getCurrentBySearch(i);if(e==null)return;const t=this._shortcutParam.indexOf(e);return this._shortcutParam.splice(t,1)[0]}_getCurrentBySearch(i){return i==null?void 0:this._shortcutParam.find(t=>t.unitId===i.unitId&&t.sheetId===i.sheetId&&t.keycode===i.keycode)}};Wt=ra([so(0,l.IUniverInstanceService),so(1,D.Inject(l.LocaleService))],Wt);function Ke(i,e,t,n,o=!0,r=1,s=!0){let a={...i};n==null&&(n={startRow:0,endRow:t.getRowCount()-1,startColumn:0,endColumn:t.getColumnCount()-1});let c;switch(e){case l.Direction.UP:for(c=i.startRow-r;c>-1&&!t.getRowVisible(c);)c-=1;c>=n.startRow?(a.startRow=c,a.endRow=c):s&&(a.startRow=n.endRow,a.endRow=n.endRow,o&&(a=Ke(a,l.Direction.LEFT,t,n,!1)));break;case l.Direction.DOWN:for(c=i.endRow+r;c<t.getRowCount()&&!t.getRowVisible(c);)c+=1;c<=n.endRow?(a.startRow=c,a.endRow=c):s&&(a.startRow=n.startRow,a.endRow=n.startRow,o&&(a=Ke(a,l.Direction.RIGHT,t,n,!1)));break;case l.Direction.LEFT:for(c=i.startColumn-r;c>-1&&!t.getColVisible(c);)c-=1;c>=n.startColumn?(a.startColumn=c,a.endColumn=c):s&&(a.startColumn=n.endColumn,a.endColumn=n.endColumn,o&&(a=Ke(a,l.Direction.UP,t,n,!1)));break;case l.Direction.RIGHT:for(c=i.endColumn+r;c<t.getColumnCount()&&!t.getColVisible(c);)c+=1;c<=n.endColumn?(a.startColumn=c,a.endColumn=c):s&&(a.startColumn=n.startColumn,a.endColumn=n.startColumn,o&&(a=Ke(a,l.Direction.DOWN,t,n,!1)));break}return a}function xi(i,e,t){const n={...i},{startRow:o,startColumn:r,endRow:s,endColumn:a}=jt(i,e,t);let c=At(t,o,r,s,a).hasValue,d=!0,u=!0;for(;u;){if(l.Direction.UP===e){let h=n.startRow-1;for(;h>-1&&!t.getRowVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:m,matrix:g}=At(t,h,n.startColumn,h,n.endColumn);if(c&&!m&&!d){u=!1;break}else{if(g.getLength()!==0){let S=h;g.forValue(f=>{S=Math.min(f,S)}),n.startRow=S}else n.startRow=h;if(n.endRow=n.startRow,!c&&m){u=!1;break}c=m,d=!1}}if(l.Direction.DOWN===e){let h=n.endRow+1;for(;h<t.getRowCount()&&!t.getRowVisible(h);)h+=1;if(h===t.getRowCount()){u=!1;break}const{hasValue:m,matrix:g}=At(t,h,n.startColumn,h,n.endColumn);if(c&&!m&&!d){u=!1;break}else{if(g.getLength()!==0){let S=h;g.forValue((f,C,R)=>{S=Math.max(f+(R.rowSpan||1)-1,S)}),n.endRow=S}else n.endRow=h;if(n.startRow=n.endRow,!c&&m){u=!1;break}c=m,d=!1}}if(l.Direction.LEFT===e){let h=n.startColumn-1;for(;h>-1&&!t.getColVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:m,matrix:g}=At(t,n.startRow,h,n.endRow,h);if(c&&!m&&!d){u=!1;break}else{if(g.getLength()!==0){let S=h;g.forValue((f,C)=>{S=Math.min(C,S)}),n.startColumn=S}else n.startColumn=h;if(n.endColumn=n.startColumn,!c&&m){u=!1;break}c=m,d=!1}}if(l.Direction.RIGHT===e){let h=n.endColumn+1;for(;h<t.getColumnCount()&&!t.getColVisible(h);)h+=1;if(h===t.getColumnCount()){u=!1;break}const{hasValue:m,matrix:g}=At(t,n.startRow,h,n.endRow,h);if(c&&!m&&!d){u=!1;break}else{if(g.getLength()!==0){let S=h;g.forValue((f,C,R)=>{S=Math.max(C+(R.colSpan||1)-1,S)}),n.endColumn=S}else n.endColumn=h;if(n.startColumn=n.endColumn,!c&&m){u=!1;break}c=m,d=!1}}}return _.alignToMergedCellsBorders(n,t,!0)}function Ko(i,e,t){return Ke(i,e,t,void 0,!1,1,!1)}function sa(i,e,t){const n=xi(i,e,t);return _.alignToMergedCellsBorders(l.Rectangle.union(n,i),t,!0)}function aa(i,e,t){const n=Ko(i,e,t),o={startRow:Math.min(i.startRow,n.startRow),startColumn:Math.min(i.startColumn,n.startColumn),endRow:Math.max(i.endRow,n.endRow),endColumn:Math.max(i.endColumn,n.endColumn)};return _.alignToMergedCellsBorders(l.Rectangle.union(i,o),t)}function la(i,e,t,n){const o=l.getReverseDirection(t),r=xi(jt(i,o,n),t,n);return t===l.Direction.UP&&r.startRow<=i.startRow?_.alignToMergedCellsBorders({...e,startColumn:i.startColumn,endColumn:i.endColumn},n,!0):t===l.Direction.DOWN&&r.endRow>=i.endRow?_.alignToMergedCellsBorders({...e,startColumn:i.startColumn,endColumn:i.endColumn},n,!0):t===l.Direction.LEFT&&r.startColumn<=i.startColumn?_.alignToMergedCellsBorders({...e,startRow:i.startRow,endRow:i.endRow},n,!0):t===l.Direction.RIGHT&&r.endColumn>=i.endColumn?_.alignToMergedCellsBorders({...e,startRow:i.startRow,endRow:i.endRow},n,!0):l.Rectangle.union(l.Rectangle.clone(e),r)}function ca(i,e,t){const n=l.getReverseDirection(e),o=jt(i,n,t),r=jt(i,e,t),s=Ko(o,e,t);return _.alignToMergedCellsBorders(l.Rectangle.union(r,s),t,!1)}function da(i,e,t){const{left:n,right:o,up:r,down:s}=e,a=t.getMaxRows(),c=t.getMaxColumns();let d=!0;const u={...i};for(;d;){if(d=!1,r&&u.startRow!==0){const h=u.startRow-1;t.getMatrixWithMergedCells(h,u.startColumn,h,u.endColumn).forValue((g,S,f)=>{f.v&&(u.startRow=Math.min(g,u.startRow),u.startColumn=Math.min(S,u.startColumn),u.endColumn=Math.max(S,u.endColumn),d=!0)})}if(s&&u.endRow!==a-1){const h=u.endRow+1;t.getMatrixWithMergedCells(h,u.startColumn,h,u.endColumn).forValue((g,S,f)=>{f.v&&(u.endRow=Math.max(g+(f.rowSpan!==void 0?f.rowSpan-1:0),u.endRow),u.startColumn=Math.min(S,u.startColumn),u.endColumn=Math.max(S,u.endColumn),d=!0)})}if(n&&u.startColumn!==0){const h=u.startColumn-1;t.getMatrixWithMergedCells(u.startRow,h,u.endRow,h).forValue((g,S,f)=>{f.v&&(u.startColumn=Math.min(S,u.startColumn),u.startRow=Math.min(g,u.startRow),u.endRow=Math.max(g,u.endRow),d=!0)})}if(o&&u.endColumn!==c-1){const h=u.endColumn+1;t.getMatrixWithMergedCells(u.startRow,h,u.endRow,h).forValue((g,S,f)=>{f.v&&(u.endColumn=Math.max(S+(f.colSpan!==void 0?f.colSpan-1:0),u.endColumn),u.startRow=Math.min(g,u.startRow),u.endRow=Math.max(g,u.endRow),d=!0)})}}return u}function ao(i){return{startRow:0,startColumn:0,endRow:i.getRowCount()-1,endColumn:i.getColumnCount()-1,rangeType:l.RANGE_TYPE.ALL}}function jt(i,e,t){let n;switch(e){case l.Direction.UP:n={startRow:i.startRow,startColumn:i.startColumn,endRow:i.startRow,endColumn:i.endColumn,rangeType:l.RANGE_TYPE.NORMAL};break;case l.Direction.DOWN:n={startRow:i.endRow,startColumn:i.startColumn,endRow:i.endRow,endColumn:i.endColumn,rangeType:l.RANGE_TYPE.NORMAL};break;case l.Direction.LEFT:n={startRow:i.startRow,startColumn:i.startColumn,endRow:i.endRow,endColumn:i.startColumn,rangeType:l.RANGE_TYPE.NORMAL};break;case l.Direction.RIGHT:n={startRow:i.startRow,startColumn:i.endColumn,endRow:i.endRow,endColumn:i.endColumn,rangeType:l.RANGE_TYPE.NORMAL};break;default:throw new Error("Invalid direction")}return _.alignToMergedCellsBorders(n,t,!1)}function At(i,e,t,n,o){let r=!1;const s=i.getMatrixWithMergedCells(e,t,n,o).forValue((a,c,d)=>{if(d.v)return r=!0,!1});return{hasValue:r,matrix:s}}function fi(i,e,t){const n=l.Rectangle.clone(i);if(e==null)return n;switch(t){case l.Direction.UP:case l.Direction.DOWN:n.startColumn=n.endColumn=e.actualColumn;break;case l.Direction.LEFT:case l.Direction.RIGHT:n.startRow=n.endRow=e.actualRow;break}return n}function ua(i,e,t){const{primary:n,range:o}=i,r=l.Rectangle.clone(o);switch(e){case l.Direction.UP:case l.Direction.DOWN:r.startRow=n.startRow,r.endRow=n.endRow;break;case l.Direction.LEFT:case l.Direction.RIGHT:r.startColumn=n.startColumn,r.endColumn=n.endColumn;break}const s=jt(r,e,t);switch(e){case l.Direction.DOWN:return o.startRow<s.startRow;case l.Direction.UP:return o.endRow>s.endRow;case l.Direction.LEFT:return s.endColumn<o.endColumn;case l.Direction.RIGHT:return s.startColumn>o.startColumn}}function qo(i,e){let t=i[0].startRow,n=i[0].endRow;i.forEach(r=>{const{startRow:s,endRow:a}=r;t=Math.min(t,s),n=Math.max(n,a)});const o=new Array(n-t+1).fill(!1);return e.forEach(r=>{const{startRow:s,endRow:a}=r;for(let c=Math.max(s,t);c<=Math.min(a,n);c++)o[c-t]=!0}),i.every(r=>{const{startRow:s,endRow:a}=r;for(let c=s;c<=a;c++)if(!o[c-t])return!1;return!0})}function Jo(i,e){let t=i[0].startColumn,n=i[0].endColumn;i.forEach(r=>{const{startColumn:s,endColumn:a}=r;t=Math.min(t,s),n=Math.max(n,a)});const o=new Array(n-t+1).fill(!1);return e.forEach(r=>{const{startColumn:s,endColumn:a}=r;for(let c=Math.max(s,t);c<=Math.min(a,n);c++)o[c-t]=!0}),i.every(r=>{const{startColumn:s,endColumn:a}=r;for(let c=s;c<=a;c++)if(!o[c-t])return!1;return!0})}var Le=(i=>(i[i.moveStopeOne=0]="moveStopeOne",i[i.moveGap=1]="moveGap",i[i.moveStepPage=2]="moveStepPage",i[i.moveStepEnd=3]="moveStepEnd",i))(Le||{});const Te={id:"sheet.command.move-selection",type:l.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const t=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance(),n=t.getActiveSheet(),o=i.get(_.SelectionManagerService).getLast();if(!o)return!1;const{direction:r,jumpOver:s}=e,{range:a,primary:c}=o,d=fi(a,c,r),u=s===1?xi(d,r,n):Ke(d,r,n),h=_.getCellAtRowCol(u.startRow,u.startColumn,n);return l.Rectangle.equals(h,d)?!1:(i.get(Wt).remove({unitId:t.getUnitId(),sheetId:n.getSheetId(),keycode:I.KeyCode.TAB}),i.get(l.ICommandService).executeCommand(_.SetSelectionsOperation.id,{unitId:t.getUnitId(),subUnitId:n.getSheetId(),pluginName:_.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:l.Rectangle.clone(h),primary:{startRow:h.startRow,startColumn:h.startColumn,endRow:h.endRow,endColumn:h.endColumn,actualRow:u.startRow,actualColumn:u.startColumn,isMerged:h.isMerged,isMergedMainCell:h.startRow===u.startRow&&h.startColumn===u.startColumn}}]}))}},at={id:"sheet.command.move-selection-enter-tab",type:l.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const t=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance(),n=t.getActiveSheet(),o=i.get(_.SelectionManagerService).getLast(),r=t.getUnitId(),s=n.getSheetId();if(!o)return!1;const{direction:a,keycode:c}=e,{range:d,primary:u}=o;let h=fi(d,u,a);const m=i.get(Wt),g=m.getCurrentBySearch({unitId:r,sheetId:s,keycode:I.KeyCode.TAB});let S;const{startRow:f,endRow:C,startColumn:R,endColumn:M}=d;if(l.Rectangle.equals(d,u)){if(c===I.KeyCode.TAB)g==null&&m.addOrUpdate({unitId:r,sheetId:s,keycode:I.KeyCode.TAB,selection:o});else{const E=g==null?void 0:g.selection;if(E!=null){const{range:y,primary:x}=E;h=fi(y,x,a)}m.remove({unitId:r,sheetId:s,keycode:I.KeyCode.TAB})}const T=Ke(h,a,n),w=_.getCellAtRowCol(T.startRow,T.startColumn,n);if(l.Rectangle.equals(w,h))return!1;S={range:l.Rectangle.clone(w),primary:{startRow:w.startRow,startColumn:w.startColumn,endRow:w.endRow,endColumn:w.endColumn,actualRow:T.startRow,actualColumn:T.startColumn,isMerged:w.isMerged,isMergedMainCell:w.startRow===T.startRow&&w.startColumn===T.startColumn}}}else{m.remove({unitId:r,sheetId:s,keycode:I.KeyCode.TAB});const T=l.Tools.deepClone(u),w=Ke({startRow:T.startRow,startColumn:T.startColumn,endRow:T.endRow,endColumn:T.endColumn},a,n,{startRow:f,endRow:C,startColumn:R,endColumn:M}),E=_.getCellAtRowCol(w.startRow,w.startColumn,n);S={range:l.Rectangle.clone(d),primary:{startRow:E.startRow,startColumn:E.startColumn,endRow:E.endRow,endColumn:E.endColumn,actualRow:w.startRow,actualColumn:w.startColumn,isMerged:E.isMerged,isMergedMainCell:E.startRow===w.startRow&&E.startColumn===w.startColumn}}}return i.get(l.ICommandService).executeCommand(_.SetSelectionsOperation.id,{unitId:r,subUnitId:s,pluginName:_.NORMAL_SELECTION_PLUGIN_NAME,selections:[S]})}},Ue={id:"sheet.command.expand-selection",type:l.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const t=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance(),n=t.getActiveSheet(),o=i.get(_.SelectionManagerService).getLast();if(!o)return!1;const{range:r,primary:s}=o,{jumpOver:a,direction:c}=e,u=ua(o,c,n)?a===1?la(r,{...l.Rectangle.clone(s),rangeType:l.RANGE_TYPE.NORMAL},c,n):ca(r,c,n):a===1?sa(r,c,n):aa(r,c,n);return l.Rectangle.equals(u,r)?!1:i.get(l.ICommandService).executeCommand(_.SetSelectionsOperation.id,{unitId:t.getUnitId(),subUnitId:n.getSheetId(),pluginName:_.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:u,primary:s}]})}};let Ae=[],ei="";const Qo={id:"sheet.command.select-all",type:l.CommandType.COMMAND,onDispose(){Ae=[],ei=""},handler:async(i,e={expandToGapFirst:!0,loop:!1})=>{const t=i.get(_.SelectionManagerService).getLast(),n=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance(),o=n.getActiveSheet();if(!t||!o)return!1;const r=`${n.getUnitId()}|${o.getSheetId()}`;r!==ei&&(Ae=[],ei=r);const s=o.getMaxRows(),a=o.getMaxColumns(),{expandToGapFirst:c,loop:d}=e,{range:u,primary:h}=t,m=u.endColumn===a-1&&u.endRow===s-1&&u.startRow===0&&u.startColumn===0;Ae.some(S=>l.Rectangle.equals(S,u))||(Ae=[],Ae.push(u));let g;if(m)if(d){if(Ae.findIndex(f=>l.Rectangle.equals(f,u))!==Ae.length-1)return!1;g=Ae[0]}else return!1;else c?(g=da(u,{left:!0,right:!0,up:!0,down:!0},o),l.Rectangle.equals(g,u)&&(g=ao(o))):g=ao(o);return Ae.some(S=>l.Rectangle.equals(S,g))||Ae.push(g),i.get(l.ICommandService).executeCommand(_.SetSelectionsOperation.id,{unitId:n.getUnitId(),subUnitId:o.getSheetId(),pluginName:_.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:g,primary:h}]})}};var ha=Object.defineProperty,ma=Object.getOwnPropertyDescriptor,ga=(i,e,t,n)=>{for(var o=n>1?void 0:n?ma(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&ha(e,t,o),o},nn=(i,e)=>(t,n)=>e(t,n,i);const Sa=l.createInterceptorKey("BEFORE_CELL_EDIT"),_a=l.createInterceptorKey("AFTER_CELL_EDIT");exports.EditorBridgeService=class extends l.Disposable{constructor(t,n,o,r){super();v(this,"_editorUnitId",l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);v(this,"_isForceKeepVisible",!1);v(this,"_editorIsDirty",!1);v(this,"_visible",{visible:!1,eventType:b.DeviceInputEventType.Dblclick});v(this,"_currentEditCell",null);v(this,"_currentEditCellState",null);v(this,"_currentEditCellState$",new H.BehaviorSubject(null));v(this,"currentEditCellState$",this._currentEditCellState$.asObservable());v(this,"_visible$",new H.BehaviorSubject(this._visible));v(this,"visible$",this._visible$.asObservable());v(this,"_afterVisible$",new H.BehaviorSubject(this._visible));v(this,"afterVisible$",this._afterVisible$.asObservable());v(this,"interceptor",new l.InterceptorManager({BEFORE_CELL_EDIT:Sa,AFTER_CELL_EDIT:_a}));this._sheetSkeletonManagerService=t,this._selectionRenderService=n,this._themeService=o,this._currentUniverService=r,this.disposeWithMe(l.toDisposable(()=>{this._currentEditCellState$.complete(),this._currentEditCell=null})),this.disposeWithMe(l.toDisposable(this.interceptor.intercept(this.interceptor.getInterceptPoints().AFTER_CELL_EDIT,{priority:-1,handler:s=>s}))),this.disposeWithMe(l.toDisposable(this.interceptor.intercept(this.interceptor.getInterceptPoints().BEFORE_CELL_EDIT,{priority:-1,handler:s=>s})))}refreshEditCellState(){const t=this.getLatestEditCellState();this._currentEditCellState=t,this._currentEditCellState$.next(t)}setEditCell(t){this._currentEditCell=t;const n=this.getLatestEditCellState();this._currentEditCellState=n,this._currentEditCellState$.next(n)}getEditCellState(){return this._currentEditCellState}getLatestEditCellState(){var F,W;const t=this._currentEditCell;if(t==null)return;const n=this._sheetSkeletonManagerService.getCurrent();if(n==null)return;const{skeleton:o}=n,{primary:r,unitId:s,sheetId:a,scene:c,engine:d}=t,{startRow:u,startColumn:h}=r,m=this._selectionRenderService.convertCellRangeToInfo(r);if(m==null)return;const g=l.makeCellToSelection(m);if(g==null)return;const S=b.getCanvasOffsetByEngine(d);let{startX:f,startY:C,endX:R,endY:M}=g;const{scaleX:T,scaleY:w}=c.getAncestorScale(),{scaleX:E,scaleY:y}=c.getPrecisionScale(),x=c.getScrollXY(this._selectionRenderService.getViewPort());f=b.fixLineWidthByScale(o.convertTransformToOffsetX(f,T,x),E),C=b.fixLineWidthByScale(o.convertTransformToOffsetY(C,w,x),y),R=b.fixLineWidthByScale(o.convertTransformToOffsetX(R,T,x),E),M=b.fixLineWidthByScale(o.convertTransformToOffsetY(M,w,x),y);const O=this._currentUniverService.getCurrentUniverSheetInstance(),A=O.getActiveSheet(),k={workbook:O,worksheet:A,unitId:O.getUnitId(),subUnitId:A.getSheetId(),row:u,col:h},N=this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().BEFORE_CELL_EDIT)(A.getCell(u,h),k);let B=N&&o.getCellDocumentModelWithFormula(N);if((!B||B.documentModel==null)&&(B=o.getBlankCellDocumentModel(N)),(F=B.documentModel)==null||F.setZoomRatio(Math.max(T,w)),(N==null?void 0:N.isInArrayFormulaRange)===!0){const $=(W=B.documentModel)==null?void 0:W.getBody();$&&($.textRuns=[{st:0,ed:$.dataStream.length-2,ts:{cl:{rgb:this._themeService.getCurrentTheme().textColorSecondary}}}])}return{position:{startX:f,startY:C,endX:R,endY:M},scaleX:T,scaleY:w,canvasOffset:S,row:u,column:h,unitId:s,sheetId:a,documentLayoutObject:B,editorUnitId:this._editorUnitId,isInArrayFormulaRange:N==null?void 0:N.isInArrayFormulaRange}}getCurrentEditorId(){return this._editorUnitId}changeVisible(t){this._visible=t,t.visible&&(this._editorIsDirty=!1),this._visible$.next(this._visible),this._afterVisible$.next(this._visible)}isVisible(){return this._visible}enableForceKeepVisible(){this._isForceKeepVisible=!0}disableForceKeepVisible(){this._isForceKeepVisible=!1}isForceKeepVisible(){return this._isForceKeepVisible}changeEditorDirty(t){this._editorIsDirty=t}getEditorDirty(){return this._editorIsDirty}};exports.EditorBridgeService=ga([nn(0,D.Inject(exports.SheetSkeletonManagerService)),nn(1,_e),nn(2,D.Inject(l.ThemeService)),nn(3,l.IUniverInstanceService)],exports.EditorBridgeService);const Ee=D.createIdentifier("univer.sheet-editor-bridge.service"),He={id:"sheet.operation.set-cell-edit-visible",type:l.CommandType.OPERATION,handler:(i,e)=>{const t=i.get(Ee);return e==null?!1:(t.changeVisible(e),!0)}},$t={id:"sheet.operation.set-cell-edit-visible-arrow",type:l.CommandType.OPERATION,handler:()=>!0};class Je{constructor(){v(this,"_scrollInfo",new Map);v(this,"_currentScroll",null);v(this,"_scrollInfo$",new H.BehaviorSubject(null));v(this,"scrollInfo$",this._scrollInfo$.asObservable())}dispose(){this._scrollInfo$.complete()}setCurrentScroll(e){this._currentScroll=e,this._refresh(e)}getScrollByParam(e){return this._getCurrentScroll(e)}getCurrentScroll(){return this._getCurrentScroll(this._currentScroll)}addOrReplace(e){this._currentScroll!=null&&this._addByParam({...this._currentScroll,...e})}addOrReplaceNoRefresh(e){this._currentScroll!=null&&this._addByParam({...this._currentScroll,...e},!1)}addOrReplaceByParam(e){this._addByParam(e)}clear(){this._currentScroll!=null&&this._clearByParam(this._currentScroll)}_addByParam(e,t=!0){const{unitId:n,sheetId:o,sheetViewStartColumn:r,sheetViewStartRow:s,offsetX:a,offsetY:c}=e;this._scrollInfo.has(n)||this._scrollInfo.set(n,new Map),this._scrollInfo.get(n).set(o,{sheetViewStartRow:s,sheetViewStartColumn:r,offsetX:a,offsetY:c}),t===!0&&this._refresh({unitId:n,sheetId:o})}_clearByParam(e){this._addByParam({...e,sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0}),this._refresh(e)}_getCurrentScroll(e){var o;if(e==null)return;const{unitId:t,sheetId:n}=e;return(o=this._scrollInfo.get(t))==null?void 0:o.get(n)}_refresh(e){this._scrollInfo$.next(this._getCurrentScroll(e))}}const Tt={id:"sheet.operation.set-scroll",type:l.CommandType.OPERATION,handler:(i,e)=>{if(e==null)return!1;const t=i.get(Je),r=i.get(l.IUniverInstanceService).getUniverSheetInstance(e.unitId).getSheetBySheetId(e.sheetId),{xSplit:s,ySplit:a}=r.getConfig().freeze;return t.addOrReplaceByParam({...e,sheetViewStartRow:e.sheetViewStartRow-a,sheetViewStartColumn:e.sheetViewStartColumn-s}),!0}},jn={id:"sheet.operation.set-editor-resize",type:l.CommandType.OPERATION,handler:(i,e)=>!0},We={id:"sheet.operation.set-zoom-ratio",type:l.CommandType.OPERATION,handler:(i,e)=>{const t=i.get(l.IUniverInstanceService).getUniverSheetInstance(e.unitId),n=t==null?void 0:t.getSheetBySheetId(e.subUnitId);return n==null?!1:(n.getConfig().zoomRatio=e.zoomRatio,!0)}};var er={exports:{}},$n={};/**
7
10
  * @license React
8
11
  * react-jsx-runtime.production.min.js
9
12
  *
@@ -11,7 +14,7 @@
11
14
  *
12
15
  * This source code is licensed under the MIT license found in the
13
16
  * LICENSE file in the root directory of this source tree.
14
- */var xs=L,As=Symbol.for("react.element"),Hs=Symbol.for("react.fragment"),Ds=Object.prototype.hasOwnProperty,Ns=xs.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Ps={key:!0,ref:!0,__self:!0,__source:!0};function No(i,e,t){var n,o={},r=null,s=null;t!==void 0&&(r=""+t),e.key!==void 0&&(r=""+e.key),e.ref!==void 0&&(s=e.ref);for(n in e)Ds.call(e,n)&&!Ps.hasOwnProperty(n)&&(o[n]=e[n]);if(i&&i.defaultProps)for(n in e=i.defaultProps,e)o[n]===void 0&&(o[n]=e[n]);return{$$typeof:As,type:i,key:r,ref:s,props:o,_owner:Ns.current}}xn.Fragment=Hs;xn.jsx=No;xn.jsxs=No;Do.exports=xn;var p=Do.exports,he=function(){return he=Object.assign||function(i){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(i[o]=e[o])}return i},he.apply(this,arguments)},Ls=function(i,e){var t={};for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&e.indexOf(n)<0&&(t[n]=i[n]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,n=Object.getOwnPropertySymbols(i);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(i,n[o])&&(t[n[o]]=i[n[o]]);return t},ue=L.forwardRef(function(i,e){var t=i.icon,n=i.id,o=i.className,r=i.extend,s=Ls(i,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(n," ").concat(o||"").trim(),c=L.useRef("_".concat(Bs()));return Po(t,"".concat(n),{defIds:t.defIds,idSuffix:c.current},he({ref:e,className:l},s),r)});function Po(i,e,t,n,o){return L.createElement(i.tag,he(he({key:e},Us(i,t,o)),n),(ks(i,t).children||[]).map(function(r,s){return Po(r,"".concat(e,"-").concat(i.tag,"-").concat(s),t,void 0,o)}))}function Us(i,e,t){var n=he({},i.attrs);t!=null&&t.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=t.colorChannel1);var o=e.defIds;return!o||o.length===0||(i.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+e.idSuffix),Object.entries(n).forEach(function(r){var s=r[0],l=r[1];typeof l=="string"&&(n[s]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),n}function ks(i,e){var t,n=e.defIds;return!n||n.length===0?i:i.tag==="defs"&&(!((t=i.children)===null||t===void 0)&&t.length)?he(he({},i),{children:i.children.map(function(o){return typeof o.attrs.id=="string"&&n&&n.indexOf(o.attrs.id)>-1?he(he({},o),{attrs:he(he({},o.attrs),{id:o.attrs.id+e.idSuffix})}):o})}):i}function Bs(){return Math.random().toString(36).substring(2,8)}ue.displayName="UniverIcon";var Vs={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M11.5261 12.834V14.634C11.5261 14.9654 11.7948 15.234 12.1261 15.234V15.234C12.4575 15.234 12.7261 14.9654 12.7261 14.634V12.834H14.5262C14.8576 12.834 15.1262 12.5654 15.1262 12.234V12.234C15.1262 11.9027 14.8576 11.634 14.5262 11.634H12.7261V9.83401C12.7261 9.50264 12.4575 9.23401 12.1261 9.23401V9.23401C11.7948 9.23401 11.5261 9.50264 11.5261 9.83401V11.634H9.72622C9.39485 11.634 9.12622 11.9027 9.12622 12.234V12.234C9.12622 12.5654 9.39485 12.834 9.72622 12.834H11.5261Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M3.05352 1.9613C2.39077 1.9613 1.85352 2.49856 1.85352 3.1613V6.7613C1.85352 7.42405 2.39077 7.9613 3.05352 7.9613H6.65352C7.31626 7.9613 7.85352 7.42405 7.85352 6.7613V3.1613C7.85352 2.49856 7.31626 1.9613 6.65352 1.9613H3.05352zM6.65352 3.1613H3.05352L3.05352 6.7613H6.65352V3.1613zM3.05352 9.23401C2.39077 9.23401 1.85352 9.77127 1.85352 10.434V14.034C1.85352 14.6968 2.39077 15.234 3.05352 15.234H6.65352C7.31626 15.234 7.85352 14.6968 7.85352 14.034V10.434C7.85352 9.77127 7.31626 9.23401 6.65352 9.23401H3.05352zM6.65352 10.434H3.05352L3.05352 14.034H6.65352V10.434zM10.3262 7.9613C9.66348 7.9613 9.12622 7.42405 9.12622 6.7613V3.1613C9.12622 2.49856 9.66348 1.9613 10.3262 1.9613H13.9262C14.589 1.9613 15.1262 2.49856 15.1262 3.1613V6.7613C15.1262 7.42405 14.589 7.9613 13.9262 7.9613H10.3262zM10.3262 6.7613V3.1613L13.9262 3.1613V6.7613H10.3262z",fillRule:"evenodd",clipRule:"evenodd"}}]},Lo=L.forwardRef(function(i,e){return L.createElement(ue,Object.assign({},i,{id:"autofill",ref:e,icon:Vs}))});Lo.displayName="Autofill";const Fs=Lo;var js={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.6152 4.52067C14.8732 4.77869 14.8732 5.19703 14.6152 5.45505L6.61862 13.4514C6.46241 13.6077 6.20915 13.6077 6.05294 13.4514L1.73512 9.13354C1.4771 8.87551 1.4771 8.45718 1.73513 8.19915C1.99315 7.94113 2.41149 7.94114 2.66951 8.19916L6.19436 11.7241C6.27247 11.8022 6.3991 11.8022 6.47721 11.7241L13.6808 4.52067C13.9388 4.26264 14.3571 4.26264 14.6152 4.52067Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Uo=L.forwardRef(function(i,e){return L.createElement(ue,Object.assign({},i,{id:"check-mark-single",ref:e,icon:js}))});Uo.displayName="CheckMarkSingle";const bn=Uo;var Ws={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.48712 4.59907C5.23328 4.34523 4.82172 4.34523 4.56788 4.59907C4.31404 4.85291 4.31404 5.26447 4.56788 5.51831L7.9973 8.94773L4.56773 12.3773C4.31389 12.6311 4.31389 13.0427 4.56773 13.2965C4.82157 13.5504 5.23313 13.5504 5.48697 13.2965L8.91654 9.86697L12.3461 13.2965C12.5999 13.5503 13.0114 13.5503 13.2653 13.2965C13.5191 13.0426 13.5191 12.6311 13.2653 12.3772L9.83577 8.94773L13.2651 5.51836C13.519 5.26452 13.519 4.85296 13.2651 4.59912C13.0113 4.34528 12.5997 4.34528 12.3459 4.59912L8.91654 8.02849L5.48712 4.59907Z"}}]},ko=L.forwardRef(function(i,e){return L.createElement(ue,Object.assign({},i,{id:"close-single",ref:e,icon:Ws}))});ko.displayName="CloseSingle";const $s=ko;var zs={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_1213",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#DCDCDC",d:"M0.54 0.32H16.54V16.32H0.54z"}}]},{tag:"g",attrs:{fill:"currentColor",mask:"url(#mask0_102_1213)"},children:[{tag:"path",attrs:{d:"M1.76539 1.27148C1.89532 1.2465 2.05784 1.23193 2.25712 1.23193H7.39957C7.59852 1.23193 7.76228 1.24644 7.89394 1.27682 8.02979 1.30817 8.13912 1.36697 8.22237 1.45577 8.30591 1.54488 8.35813 1.6636 8.38857 1.80057L8.38913 1.80311C8.41406 1.93772 8.42854 2.10966 8.42854 2.31825V7.47982C8.42854 7.67924 8.41396 7.84153 8.38908 7.97584 8.36281 8.11247 8.3041 8.22717 8.22073 8.31054 8.13704 8.39424 8.02807 8.4472 7.89934 8.4781 7.77208 8.50864 7.60803 8.52313 7.41869 8.52313H2.25712C2.06419 8.52313 1.90591 8.51354 1.77494 8.48836 1.64209 8.46281 1.53156 8.41527 1.4464 8.33054 1.3606 8.24999 1.30815 8.13434 1.27781 8.00286 1.2476 7.87192 1.22815 7.69892 1.22815 7.47982V2.27524C1.22815 2.07123 1.24271 1.90413 1.26761 1.76966 1.29388 1.63303 1.35259 1.51833 1.43596 1.43496 1.52104 1.34988 1.63137 1.30236 1.76275 1.27204L1.76539 1.27148zM2.56975 2.39137C2.49306 2.39568 2.45433 2.41469 2.43395 2.43562 2.41191 2.46884 2.39718 2.51452 2.39715 2.57614L2.40631 4.24285H4.26296V2.39137H2.56975zM5.44152 2.39615V4.24285H7.24998V2.51898C7.24998 2.47398 7.24652 2.44245 7.24141 2.42201 7.23917 2.41305 7.23709 2.40806 7.23591 2.40567 7.22586 2.40059 7.20631 2.39615 7.16061 2.39615H5.44152zM2.40708 5.39751L2.41626 7.22616C2.41626 7.26829 2.41965 7.29933 2.42492 7.32085 2.42882 7.33675 2.43309 7.34502 2.43572 7.34893 2.43572 7.34893 2.43928 7.35079 2.44202 7.35193 2.44831 7.35455 2.45718 7.35739 2.46908 7.35996 2.49304 7.36512 2.52583 7.36847 2.56777 7.36847H4.26774V5.39751H2.40708zM5.44152 5.39751V7.36847H7.09848C7.1739 7.36847 7.21416 7.35941 7.23151 7.35088 7.23281 7.34891 7.23591 7.34357 7.23933 7.33216 7.24553 7.3115 7.24998 7.27978 7.24998 7.23608V5.39751H5.44152zM9.19356 8.15082C9.3235 8.12583 9.48601 8.11127 9.6853 8.11127H14.8277C15.0267 8.11127 15.1905 8.12577 15.3221 8.15616 15.458 8.18751 15.5673 8.2463 15.6506 8.33511 15.7341 8.42421 15.7863 8.54294 15.8167 8.67991L15.8173 8.68245C15.8422 8.81705 15.8567 8.98899 15.8567 9.19759V14.3592C15.8567 14.5586 15.8421 14.7209 15.8173 14.8552 15.791 14.9918 15.7323 15.1065 15.6489 15.1899 15.5652 15.2736 15.4562 15.3265 15.3275 15.3574 15.2003 15.388 15.0362 15.4025 14.8469 15.4025H9.6853C9.49237 15.4025 9.33408 15.3929 9.20312 15.3677 9.07027 15.3421 8.95974 15.2946 8.87458 15.2099 8.78878 15.1293 8.73633 15.0137 8.70599 14.8822 8.67578 14.7513 8.65633 14.5783 8.65633 14.3592V9.15457C8.65633 8.95057 8.67088 8.78346 8.69579 8.649 8.72206 8.51237 8.78077 8.39767 8.86414 8.3143 8.94922 8.22922 9.05955 8.1817 9.19093 8.15138L9.19356 8.15082zM9.99793 9.27071C9.92124 9.27501 9.88251 9.29403 9.86212 9.31496 9.84009 9.34817 9.82536 9.39386 9.82533 9.45548L9.83448 11.1222H11.6911V9.27071H9.99793zM12.8697 9.27549V11.1222H14.6782V9.39831C14.6782 9.35332 14.6747 9.32178 14.6696 9.30135 14.6673 9.29238 14.6653 9.2874 14.6641 9.285 14.654 9.27992 14.6345 9.27549 14.5888 9.27549H12.8697zM9.83525 12.2768L9.84444 14.1055C9.84444 14.1476 9.84783 14.1787 9.8531 14.2002 9.85699 14.2161 9.86127 14.2244 9.86389 14.2283L9.86689 14.2298 9.87019 14.2313C9.87648 14.2339 9.88535 14.2367 9.89726 14.2393 9.92122 14.2445 9.95401 14.2478 9.99594 14.2478H11.6959V12.2768H9.83525zM12.8697 12.2768V14.2478H14.5267C14.6021 14.2478 14.6423 14.2387 14.6597 14.2302 14.661 14.2282 14.6641 14.2229 14.6675 14.2115 14.6737 14.1908 14.6782 14.1591 14.6782 14.1154V12.2768H12.8697z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{d:"M10.0049 2.46747C10.0049 2.06363 10.3323 1.73625 10.7361 1.73625H12.9298C14.1413 1.73625 15.1234 2.71838 15.1234 3.9299V6.12354C15.1234 6.52738 14.796 6.85476 14.3922 6.85476 13.9883 6.85476 13.661 6.52738 13.661 6.12354V3.9299C13.661 3.52606 13.3336 3.19868 12.9298 3.19868H10.7361C10.3323 3.19868 10.0049 2.87131 10.0049 2.46747zM3.42396 10.5108C3.42396 10.107 3.09658 9.77962 2.69274 9.77962 2.2889 9.77962 1.96152 10.107 1.96152 10.5108V12.7045C1.96152 13.916 2.94365 14.8981 4.15517 14.8981H6.34882C6.75266 14.8981 7.08003 14.5707 7.08003 14.1669 7.08003 13.7631 6.75266 13.4357 6.34882 13.4357H4.15517C3.75134 13.4357 3.42396 13.1083 3.42396 12.7045V10.5108z"}}]}]},Bo=L.forwardRef(function(i,e){return L.createElement(ue,Object.assign({},i,{id:"convert-single",ref:e,icon:zs}))});Bo.displayName="ConvertSingle";const Xs=Bo;var Ys={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_371_77",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#DCDCDC",d:"M0.87 0.63H16.87V16.63H0.87z"}}]},{tag:"g",attrs:{mask:"url(#mask0_371_77)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M9.72636 13.5549C9.25212 14.1041 8.48323 14.1041 8.00899 13.5549L1.22579 5.70056C0.46078 4.81474 1.00259 3.30013 2.08448 3.30013L15.6509 3.30013C16.7328 3.30013 17.2746 4.81474 16.5096 5.70056L9.72636 13.5549Z"}}]}]},Vo=L.forwardRef(function(i,e){return L.createElement(ue,Object.assign({},i,{id:"dropdown-single",ref:e,icon:Ys}))});Vo.displayName="DropdownSingle";const Wi=Vo;var Zs={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.90535 4.99197C2.23194 4.82196 2.63451 4.94889 2.80452 5.27548C2.96702 5.58764 3.22397 5.8971 3.57667 6.18615C4.57587 7.00507 6.2535 7.58331 8.21318 7.58331C10.1728 7.58331 11.8505 7.00508 12.8497 6.18616C13.2024 5.8971 13.4593 5.58763 13.6218 5.27549C13.7918 4.94889 14.1944 4.82196 14.521 4.99196C14.8476 5.16197 14.9745 5.56454 14.8045 5.89113C14.5439 6.39185 14.1596 6.83646 13.6948 7.2174C13.6514 7.25301 13.6071 7.28815 13.5621 7.3228L15.0214 8.78205C15.2817 9.0424 15.2817 9.46451 15.0214 9.72486C14.761 9.98521 14.3389 9.98521 14.0785 9.72486L12.3889 8.03522C11.8643 8.28584 11.2846 8.48827 10.6659 8.63563L11.2065 10.6532C11.3018 11.0088 11.0907 11.3744 10.7351 11.4697C10.3794 11.565 10.0139 11.3539 9.91857 10.9983L9.34529 8.85869C8.97555 8.89693 8.59724 8.91664 8.21318 8.91664C7.82639 8.91664 7.44544 8.89665 7.07321 8.85788L6.49971 10.9983C6.40441 11.354 6.03886 11.565 5.68321 11.4697C5.32757 11.3744 5.11651 11.0089 5.2118 10.6532L5.75288 8.63382C5.13793 8.48682 4.5615 8.28539 4.03968 8.03629L2.35121 9.72477C2.09086 9.98512 1.66875 9.98512 1.4084 9.72477C1.14805 9.46442 1.14805 9.04231 1.4084 8.78196L2.86611 7.32424C2.82044 7.28912 2.77557 7.2535 2.73152 7.2174C2.26668 6.83645 1.88248 6.39184 1.62183 5.89114C1.45182 5.56455 1.57876 5.16198 1.90535 4.99197Z"}}]},Fo=L.forwardRef(function(i,e){return L.createElement(ue,Object.assign({},i,{id:"eyelash-single",ref:e,icon:Zs}))});Fo.displayName="EyelashSingle";const Gs=Fo;var Ks={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_367_60",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0.06 0.78H16.06V16.78H0.06z"}}]},{tag:"g",attrs:{fill:"currentColor",mask:"url(#mask0_367_60)"},children:[{tag:"path",attrs:{d:"M5.54303 5.67809C5.41486 5.67809 5.31977 5.55923 5.34791 5.43419L5.43336 5.05446C5.53338 4.62534 5.71701 4.25903 5.99076 3.96308 6.28977 3.63984 6.73293 3.49761 7.27633 3.49761 7.47741 3.49761 7.69254 3.52131 7.92082 3.56601 7.93983 3.56973 7.95869 3.57361 7.9774 3.57766 8.18885 3.62335 8.41593 3.52833 8.49925 3.32869L8.72661 2.78395C8.81351 2.57574 8.71072 2.3376 8.49476 2.27229 8.46253 2.26255 8.42923 2.25268 8.39485 2.24269 8.10639 2.15986 7.76287 2.11572 7.35969 2.11572 6.29909 2.11572 5.50608 2.38292 4.95354 2.88796 4.38882 3.40424 3.98783 4.14273 3.76308 5.11976L2.31598 11.3345C2.2402 11.6722 2.14495 12.0353 2.02739 12.4247 1.90869 12.8169 1.76625 13.2031 1.60116 13.5809 1.43472 13.9595 1.24707 14.3197 1.0385 14.6607.972389 14.7687.904093 14.8718.833608 14.9698.744025 15.0945.813644 15.2766.965497 15.2989 1.6153 15.3945 2.29684 15.2198 2.66091 14.6732 2.80556 14.456 2.94673 14.2082 3.08403 13.9287 3.44529 13.1932 3.78416 12.1538 4.09761 10.801L4.94794 7.15889C4.96907 7.06839 5.04977 7.00436 5.14271 7.00436H7.10372C7.28864 7.00436 7.44946 6.87761 7.49265 6.6978L7.61908 6.17153C7.67951 5.91998 7.48886 5.67809 7.23015 5.67809H5.54303zM13.8 5.86392L11.9914 8.11319 10.8878 5.92109C10.8211 5.77368 10.6743 5.67896 10.5125 5.67896H9.79183C9.48739 5.67896 9.28816 5.99784 9.42165 6.27145L10.8878 9.19857 8.27677 12.2928C8.04481 12.5594 8.23414 12.9751 8.58749 12.9751H9.16501C9.28566 12.9751 9.43944 12.9258 9.5177 12.834L11.5897 10.4084 12.5966 12.7046C12.6575 12.8666 12.8119 12.9751 12.9851 12.9751H13.779C14.062 12.9751 14.2207 12.7611 14.1216 12.4959L12.6517 9.42983C12.6517 9.42983 14.8799 6.59898 15.0802 6.32247 15.2756 6.05285 15.0812 5.67896 14.7482 5.67896H14.145C14.0064 5.67896 13.9122 5.73242 13.8 5.86392z"}}]}]},jo=L.forwardRef(function(i,e){return L.createElement(ue,Object.assign({},i,{id:"fx-single",ref:e,icon:Ks}))});jo.displayName="FxSingle";const qs=jo;var Js={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_249",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0.37 0.77H16.37V16.77H0.37z"}}]},{tag:"g",attrs:{mask:"url(#mask0_102_249)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M9.12107 2.86418C9.12107 2.45648 8.78669 2.12598 8.37422 2.12598C7.96175 2.12598 7.62737 2.45648 7.62737 2.86418V8.03164H2.39931C1.98684 8.03164 1.65247 8.36214 1.65247 8.76984C1.65247 9.17754 1.98684 9.50805 2.39931 9.50805H7.62737V14.6754C7.62737 15.0831 7.96175 15.4136 8.37422 15.4136C8.78669 15.4136 9.12107 15.0831 9.12107 14.6754V9.50805H14.3489C14.7613 9.50805 15.0957 9.17754 15.0957 8.76984C15.0957 8.36214 14.7613 8.03164 14.3489 8.03164H9.12107V2.86418Z"}}]}]},Wo=L.forwardRef(function(i,e){return L.createElement(ue,Object.assign({},i,{id:"increase-single",ref:e,icon:Js}))});Wo.displayName="IncreaseSingle";const Qs=Wo;var el={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_556",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0.56 0.77H16.56V16.77H0.56z"}}]},{tag:"g",attrs:{mask:"url(#mask0_102_556)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.19318 4.76988C1.70089 4.26222 2.524 4.26226 3.03166 4.76997L8.13929 9.87808C8.3736 10.1124 8.75352 10.1124 8.98784 9.8781L14.0959 4.77C14.6036 4.26232 15.4267 4.26232 15.9344 4.77C16.4421 5.27768 16.4421 6.1008 15.9344 6.60848L9.97775 12.5651C9.19667 13.3462 7.93029 13.3462 7.14925 12.5651L1.1931 6.60836C0.685438 6.10065 0.685477 5.27753 1.19318 4.76988Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},$o=L.forwardRef(function(i,e){return L.createElement(ue,Object.assign({},i,{id:"more-down-single",ref:e,icon:el}))});$o.displayName="MoreDownSingle";const ei=$o;var tl={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.52628 3.57095C5.81918 3.26411 6.29405 3.26411 6.58695 3.57095L11.0869 8.28525C11.3798 8.59209 11.3798 9.08958 11.0869 9.39642L6.51623 14.04C6.22334 14.3468 5.74846 14.3468 5.45557 14.04C5.16268 13.7331 5.16268 13.2357 5.45557 12.9288L9.35939 8.979C9.43544 8.90205 9.43652 8.77857 9.36182 8.70031L5.52628 4.68212C5.23339 4.37528 5.23339 3.87779 5.52628 3.57095Z",fillRule:"evenodd",clipRule:"evenodd"}}]},zo=L.forwardRef(function(i,e){return L.createElement(ue,Object.assign({},i,{id:"more-single",ref:e,icon:tl}))});zo.displayName="MoreSingle";const $i=zo;var nl={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_1204",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#DCDCDC",d:"M0.25 0.41H16.25V16.41H0.25z"}}]},{tag:"g",attrs:{mask:"url(#mask0_102_1204)"},children:[{tag:"rect",attrs:{width:12.62,height:2.79,x:1.94,y:12.66,fill:"colorChannel1",rx:1.4}},{tag:"path",attrs:{fill:"currentColor",d:"M7.99664 2.57069C7.59302 2.05771 7.10966 1.68854 6.63466 1.50243C6.11882 1.30028 5.40184 1.25862 4.95066 1.83566C4.5486 2.34994 4.581 3.10899 4.82709 3.91045C4.93826 4.27259 5.11865 4.62903 5.37541 4.97266C5.38713 4.98834 5.39945 5.00329 5.41229 5.01752C5.4217 5.02789 5.4314 5.03788 5.44133 5.04746C5.45477 5.06043 5.46874 5.07267 5.48315 5.08419L3.75659 6.81071C3.51774 7.04955 3.51774 7.43683 3.75659 7.67569L7.48775 11.4068C7.72666 11.6457 8.11394 11.6457 8.35278 11.4068L13.0831 6.67651C13.3219 6.43766 13.3219 6.05039 13.0831 5.81155L9.35191 2.08037C9.11306 1.84153 8.72579 1.84153 8.48695 2.08037L7.99664 2.57069ZM7.71181 4.91288C7.72271 4.98224 7.73182 5.05302 7.73898 5.12518C7.77251 5.46131 8.07213 5.70663 8.40825 5.6731C8.74438 5.6396 8.98972 5.33994 8.9562 5.00382C8.90804 4.52113 8.79269 4.0731 8.6291 3.66819L8.91946 3.37784L11.7856 6.24403L10.8608 7.16886H5.12843L7.6582 4.63909C7.67903 4.72777 7.69702 4.81905 7.71181 4.91288ZM7.12302 3.44433C6.8246 3.02658 6.47279 2.75283 6.18833 2.64136C6.05252 2.58814 5.96546 2.58477 5.92656 2.58984C5.92268 2.59037 5.91947 2.59093 5.91678 2.59147L5.91208 2.59257C5.89185 2.62604 5.78612 2.86628 5.99645 3.5514C6.0626 3.76685 6.1728 3.99252 6.34325 4.2241L7.12302 3.44433Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M12.4434 11.9528C12.8956 11.9528 13.2622 11.5862 13.2622 11.134C13.2622 10.854 12.9483 10.3347 12.7092 9.9798C12.5801 9.78823 12.3066 9.78823 12.1776 9.97981C11.9385 10.3347 11.6246 10.854 11.6246 11.134C11.6246 11.5862 11.9912 11.9528 12.4434 11.9528Z"}}]}]},Xo=L.forwardRef(function(i,e){return L.createElement(ue,Object.assign({},i,{id:"paint-bucket",ref:e,icon:nl}))});Xo.displayName="PaintBucket";const il=Xo;var ol={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.80805 1.53809C2.10674 1.53809 1.53821 2.10661 1.53821 2.80793V13.6016C1.53821 14.3029 2.10674 14.8714 2.80805 14.8714H9.74456C10.2968 14.8714 10.7446 14.4237 10.7446 13.8714V13.6016V11.128C10.7446 10.9623 10.8789 10.828 11.0446 10.828H13.6017H13.8715C14.4238 10.828 14.8715 10.3803 14.8715 9.82802V2.80793C14.8715 2.10661 14.303 1.53809 13.6017 1.53809H2.80805ZM9.17472 13.6016C9.3404 13.6016 9.47472 13.4673 9.47472 13.3016V11.128C9.47472 10.9623 9.3404 10.828 9.17472 10.828H6.91757C6.75189 10.828 6.61757 10.9623 6.61757 11.128V13.3016C6.61757 13.4673 6.75189 13.6016 6.91757 13.6016H9.17472ZM13.6017 9.25817C13.6017 9.42386 13.4674 9.55818 13.3017 9.55818H11.0446C10.8789 9.55818 10.7446 9.42386 10.7446 9.25818V7.17177C10.7446 7.00608 10.8789 6.87177 11.0446 6.87177H13.3017C13.4674 6.87177 13.6017 7.00608 13.6017 7.17177V9.25817ZM9.17472 9.55818C9.3404 9.55818 9.47472 9.42386 9.47472 9.25818V7.17177C9.47472 7.00608 9.3404 6.87177 9.17472 6.87177H6.91757C6.75189 6.87177 6.61757 7.00608 6.61757 7.17177V9.25817C6.61757 9.42386 6.75189 9.55818 6.91757 9.55818H9.17472ZM13.6017 5.30193C13.6017 5.46761 13.4674 5.60193 13.3017 5.60193H11.0446C10.8789 5.60193 10.7446 5.46761 10.7446 5.30193V3.10793C10.7446 2.94224 10.8789 2.80793 11.0446 2.80793H13.3017C13.4674 2.80793 13.6017 2.94224 13.6017 3.10793V5.30193ZM9.17472 5.60193C9.3404 5.60193 9.47472 5.46761 9.47472 5.30193V3.10793C9.47472 2.94224 9.3404 2.80793 9.17472 2.80793H6.91757C6.75189 2.80793 6.61757 2.94224 6.61757 3.10793V5.30193C6.61757 5.46761 6.75189 5.60193 6.91757 5.60193H9.17472ZM5.34773 3.10793C5.34773 2.94224 5.21342 2.80793 5.04773 2.80793H3.10805C2.94236 2.80793 2.80805 2.94224 2.80805 3.10793V5.30193C2.80805 5.46761 2.94236 5.60193 3.10805 5.60193H5.04773C5.21342 5.60193 5.34773 5.46761 5.34773 5.30193V3.10793ZM5.34773 7.17177C5.34773 7.00608 5.21342 6.87177 5.04773 6.87177H3.10805C2.94236 6.87177 2.80805 7.00608 2.80805 7.17177V9.25817C2.80805 9.42386 2.94236 9.55818 3.10805 9.55818H5.04773C5.21342 9.55818 5.34773 9.42386 5.34773 9.25818V7.17177ZM5.34773 11.128C5.34773 10.9623 5.21342 10.828 5.04773 10.828H3.10805C2.94236 10.828 2.80805 10.9623 2.80805 11.128V13.3016C2.80805 13.4673 2.94236 13.6016 3.10805 13.6016H5.04773C5.21342 13.6016 5.34773 13.4673 5.34773 13.3016V11.128Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M12.3869 12.1183C12.361 11.9546 12.5342 11.8323 12.6798 11.9114L14.9901 13.1655C15.1577 13.2565 15.1137 13.5049 14.932 13.5378C14.9212 13.5398 14.9102 13.5417 14.8996 13.5446L13.8966 13.8224L13.1603 14.7467C13.0651 14.9084 12.8197 14.8618 12.7904 14.6764L12.3869 12.1183Z"}}]},Yo=L.forwardRef(function(i,e){return L.createElement(ue,Object.assign({},i,{id:"select-range-single",ref:e,icon:ol}))});Yo.displayName="SelectRangeSingle";const rl=Yo,sl="univer-range-selector",ll="univer-range-selector-editor",al="univer-range-selector-icon",cl="univer-range-selector-active",Fe={rangeSelector:sl,rangeSelectorEditor:ll,rangeSelectorIcon:al,rangeSelectorActive:cl};function dl(i){const{onChange:e,onActive:t}=i,[n,o]=L.useState(!1),r=L.useRef(null),s=W.useDependency(a.LocaleService),l=W.useDependency(f.SelectionManagerService);L.useEffect(()=>{var m;if(n){t(n);const S=l.selectionMoveEnd$.subscribe(g=>{const _=["A1","B2:C3","Sheet2!A1:B2","D10:E11,F1:G2,H3:I4"],I=Math.floor(Math.random()*_.length),C=_[I];r.current&&(r.current.innerHTML=C)});return document.addEventListener("click",c),()=>{document.removeEventListener("click",c),S.unsubscribe()}}e(((m=r.current)==null?void 0:m.innerHTML)||"")},[n]);function c(m){var I,C,b;if(((I=m.target)==null?void 0:I.closest('[data-range-selector="true"]'))||m.target===r.current)return;const g=(C=m.target)==null?void 0:C.closest(`.${Fe.rangeSelector}`);(g==null?void 0:g.querySelector(`.${Fe.rangeSelectorEditor}`))!==r.current&&(o(!1),(b=r.current)==null||b.blur())}function d(m){m.stopPropagation(),m.key==="Enter"&&(m.preventDefault(),m.currentTarget.blur(),o(!1))}function u(){o(!0)}function h(){var m;if(!n){(m=r.current)==null||m.focus();return}o(!n)}return p.jsxs("div",{className:n?`${Fe.rangeSelector} ${Fe.rangeSelectorActive}`:Fe.rangeSelector,children:[p.jsx("div",{ref:r,className:Fe.rangeSelectorEditor,contentEditable:!0,"data-placeholder":s.t("rangeSelector.placeholder"),onKeyDown:d,onFocus:u}),p.jsx(ie.Tooltip,{title:s.t("rangeSelector.tooltip"),placement:"bottom",children:p.jsx("button",{className:Fe.rangeSelectorIcon,onClick:h,children:p.jsx(rl,{})})})]})}const ti={零:0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9},Mn=["零","一","二","三","四","五","六","七","八","九"],zi=["","万","亿","万亿","亿亿"],ul=["","十","百","千"],Zo={十:{value:10,secUnit:!1},百:{value:100,secUnit:!1},千:{value:1e3,secUnit:!1},万:{value:1e4,secUnit:!0},亿:{value:1e8,secUnit:!0}};function Oe(i){if(!i)return 0;let e=0,t=0,n=0,o=!1;const r=i.split("");for(let s=0;s<r.length;s++){const l=ti[r[s]];if(typeof l<"u")n=l,s===r.length-1&&(t+=n);else{const c=Zo[r[s]],d=c.value;o=c.secUnit,o?(t=(t+n)*d,e+=t,t=0):t+=n*d,n=0}}return e+t}function hl(i){let e="",t="",n=0,o=!0;for(;i>0;){const r=i%10;r===0?o||(o=!0,t=Mn[r]+t):(o=!1,e=Mn[r],e+=ul[n],t=e+t),n++,i=Math.floor(i/10)}return t}function ml(i){let e=0,t="",n="",o=!1;if(i===0)return Mn[0];for(;i>0;){const r=i%1e4;o&&(n=Mn[0]+n),t=hl(r),t+=r!==0?zi[e]:zi[0],n=t+n,o=r<1e3&&r>0,i=Math.floor(i/1e4),e++}return n}function Sl(i){if(!i)return!1;let e=!0;if(i)if(i.length===1)i==="日"||i in ti?e=!0:e=!1;else{const t=i.split("");for(let n=0;n<t.length;n++)if(!(t[n]in ti||t[n]in Zo)){e=!1;break}}return e}function Ft(i){if(!i)return{isExtendNumber:!1};const e=/0|([1-9]+[0-9]*)/g,t=e.test(i);if(t){const n=i.match(e);if(n&&n.length>0){const o=n[n.length-1],r=i.lastIndexOf(o),s=i.substr(0,r),l=i.substr(r+o.length);return{isExtendNumber:!0,matchTxt:Number(o),beforeTxt:s,afterTxt:l}}return{isExtendNumber:!1}}return{isExtendNumber:t}}function _l(i){let e;return i.length===2&&(i==="周一"||i==="周二"||i==="周三"||i==="周四"||i==="周五"||i==="周六"||i==="周日")?e=!0:e=!1,e}function gl(i){let e;return i.length===3&&(i==="星期一"||i==="星期二"||i==="星期三"||i==="星期四"||i==="星期五"||i==="星期六"||i==="星期日")?e=!0:e=!1,e}function fl(i,e){let t=0;for(let n=0;n<i.length&&i[n]<e;n++)t++;return t}function Ht(i){let e=!0;const t=i[1]-i[0];for(let n=1;n<i.length;n++)if(i[n]-i[n-1]!==t){e=!1;break}return e}function pl(i,e,t){const n=[],o=Math.floor(e/i),r=e%i;let s=0;if(o>0){for(let l=0;l<o;l++)for(let c=0;c<t.length;c++)n[t[c]+l*i]=s,s++;for(let l=0;l<t.length&&t[l]<r;l++)n[t[l]+i*o]=s,s++}else for(let l=0;l<t.length&&t[l]<r;l++)n[t[l]]=s,s++;return n}function Ge(i,e){const t=[];for(let n=1;n<=e;n++){const o=(n-1)%i.length,r=a.Tools.deepClone(i[o]);t.push(r)}return t}function vl(i,e){var n;const t=[];for(let o=1;o<=e;o++){const r=(o-1)%i.length,s={s:(n=i[r])==null?void 0:n.s};t.push(s)}return t}function Cl(i){let e=!0;const t=i[1]/i[0];for(let n=1;n<i.length;n++)if(i[n]/i[n-1]!==t){e=!1;break}return e}function Il(i){const e=[];for(let t=1;t<=i;t++)e.push(t);return e}function Rl(i,e,t){var r,s,l,c,d,u,h;const n=[],o=[];for(let m=0;m<i.length;m++)o.push(Number((r=i[m])==null?void 0:r.v));if(i.length>2&&Cl(o))for(let m=1;m<=e;m++){const S=(m-1)%i.length,g=a.Tools.deepClone(i[S]);let _;t===a.Direction.DOWN||t===a.Direction.RIGHT?_=Number((s=i[i.length-1])==null?void 0:s.v)*(Number((l=i[1])==null?void 0:l.v)/Number((c=i[0])==null?void 0:c.v))**m:(t===a.Direction.UP||t===a.Direction.LEFT)&&(_=Number((d=i[0])==null?void 0:d.v)/(Number((u=i[1])==null?void 0:u.v)/Number((h=i[0])==null?void 0:h.v))**m),g&&(g.v=_,n.push(g))}else{const m=Il(i.length);for(let S=1;S<=e;S++){const g=(S-1)%i.length,_=a.Tools.deepClone(i[g]);let I;t===a.Direction.DOWN||t===a.Direction.RIGHT?I=Xi(i.length+S,o,m):I=Xi(1-S,o,m),_&&(_.v=I,n.push(_))}}return n}function Xi(i,e,t){function n(u){let h=0;for(let m=0;m<u.length;m++)h+=u[m];return h/u.length}const o=n(t),r=n(e);let s=0,l=0;for(let u=0;u<t.length;u++)s+=(t[u]-o)*(e[u]-r),l+=(t[u]-o)*(t[u]-o);let c;l===0?c=1:c=s/l;const d=r-c*o;return Math.round((d+c*i)*1e5)/1e5}function Yi(i,e,t){var r;const n=[],o=/0|([1-9]+[0-9]*)/g;for(let s=1;s<=e;s++){const l=(s-1)%i.length,c=a.Tools.deepClone(i[l]),d=`${(r=i[i.length-1])==null?void 0:r.v}`,u=d==null?void 0:d.match(o),h=u==null?void 0:u[u.length-1],m=Math.abs(Number(h)+t*s);if(!d||!h)continue;const S=d.lastIndexOf(h),g=d.substr(0,S)+m.toString()+d.substr(S+h.length);c&&(c.v=g,n.push(c))}return n}function rt(i,e,t,n=0){var l,c;const o=[["日","一","二","三","四","五","六"],["周日","周一","周二","周三","周四","周五","周六"],["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]];if(n>=o.length)return[];const r=o[n],s=[];for(let d=1;d<=e;d++){const u=(d-1)%i.length,h=a.Tools.deepClone(i[u]);let m=0;if(((l=i[i.length-1])==null?void 0:l.v)===r[0])m=7+t*d;else{const g=`${(c=i[i.length-1])==null?void 0:c.v}`;if(g){const _=g.substr(g.length-1,1);m=Oe(_)+t*d}}m<0&&(m=Math.ceil(Math.abs(m)/7)*7+m);const S=m%7;h&&(h.v=r[S],s.push(h))}return s}function Zi(i,e,t){var o;const n=[];for(let r=1;r<=e;r++){const s=(r-1)%i.length,l=a.Tools.deepClone(i[s]),c=`${(o=i[i.length-1])==null?void 0:o.v}`,d=Oe(c)+t*r;let u;d<=0?u="零":u=ml(d),l&&(l.v=u,n.push(l))}return n}const Mt={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 bl(i){let e=!1;return Object.keys(Mt).forEach(t=>{Mt[t].includes(i)&&(e=!0)}),e}function kn(i){let e="";const t=[];return Object.keys(Mt).forEach(n=>{Mt[n].includes(i)&&(e=n,t.push(...Mt[n]))}),{name:e,series:t}}function Gi(i,e,t,n){var s;const o=n.length,r=[];for(let l=1;l<=e;l++){const c=(l-1)%i.length,d=a.Tools.deepClone(i[c]),u=`${(s=i[i.length-1])==null?void 0:s.v}`,m=(n.indexOf(u)+t*l)%o;d&&(d.v=n[m],r.push(d))}return r}function Ml(i,e){const t=[];let n;if(e.startRow<i.startRow)n=a.Direction.UP;else if(e.endRow>i.endRow)n=a.Direction.DOWN;else if(e.startColumn<i.startColumn)n=a.Direction.LEFT;else if(e.endColumn>i.endColumn)n=a.Direction.RIGHT;else return[];if(n===a.Direction.DOWN||n===a.Direction.UP){const o=i.endRow-i.startRow+1,r=e.endRow-e.startRow+1,s=r/o,l=r%o,c={startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:i.endColumn-i.startColumn};if(n===a.Direction.DOWN){for(let d=0;d<s;d++)t.push({repeatStartCell:{row:i.startRow+(d+1)*o,col:i.startColumn},relativeRange:c});l>0&&t.push({repeatStartCell:{row:i.startRow+(s+1)*o,col:i.startColumn},relativeRange:{startRow:0,startColumn:0,endRow:l-1,endColumn:i.endColumn-i.startColumn}})}else{for(let d=0;d<s;d++)t.push({repeatStartCell:{row:i.startRow-(d+1)*o,col:i.startColumn},relativeRange:c});l>0&&t.push({repeatStartCell:{row:i.startRow-(s+1)*o,col:i.startColumn},relativeRange:{startRow:o-l,endRow:o-1,startColumn:0,endColumn:i.endColumn-i.startColumn}})}}if(n===a.Direction.RIGHT||n===a.Direction.LEFT){const o=i.endColumn-i.startColumn+1,r=e.endColumn-e.startColumn+1,s=r/o,l=r%o,c={startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:i.endColumn-i.startColumn};if(n===a.Direction.RIGHT){for(let d=0;d<s;d++)t.push({repeatStartCell:{row:i.startRow,col:i.startColumn+(d+1)*o},relativeRange:c});l>0&&t.push({repeatStartCell:{row:i.startRow,col:i.startColumn+(s+1)*o},relativeRange:{startRow:0,startColumn:0,endRow:i.endRow-i.startRow,endColumn:l-1}})}else{for(let d=0;d<s;d++)t.push({repeatStartCell:{row:i.startRow,col:i.startColumn-(d+1)*o},relativeRange:c});l>0&&t.push({repeatStartCell:{row:i.startRow,col:i.startColumn-(s+1)*o},relativeRange:{startRow:0,startColumn:o-l,endRow:i.endRow-i.startRow,endColumn:o-1}})}}return t}var te=(i=>(i.NUMBER="number",i.DATE="date",i.EXTEND_NUMBER="extendNumber",i.CHN_NUMBER="chnNumber",i.CHN_WEEK2="chnWeek2",i.CHN_WEEK3="chnWeek3",i.LOOP_SERIES="loopSeries",i.FORMULA="formula",i.OTHER="other",i))(te||{}),X=(i=>(i.COPY="0",i.SERIES="1",i.ONLY_FORMAT="2",i.NO_FORMAT="3",i))(X||{});const wl={type:te.NUMBER,priority:1e3,match:i=>typeof(i==null?void 0:i.v)=="number"||!isNaN(Number(i==null?void 0:i.v)),isContinue:(i,e)=>i.type===te.NUMBER,applyFunctions:{[X.SERIES]:(i,e,t)=>{const{data:n}=i;return(t===a.Direction.LEFT||t===a.Direction.UP)&&n.reverse(),Rl(n,e,t)}}},Go={type:te.OTHER,priority:0,match:()=>!0,isContinue:(i,e)=>i.type===te.OTHER},Tl={type:te.EXTEND_NUMBER,priority:900,match:i=>Ft(`${i==null?void 0:i.v}`||"").isExtendNumber,isContinue:(i,e)=>{var t;if(i.type===te.EXTEND_NUMBER){const{beforeTxt:n,afterTxt:o}=Ft(`${(t=i.cellData)==null?void 0:t.v}`||""),{beforeTxt:r,afterTxt:s}=Ft(`${e==null?void 0:e.v}`||"");if(n===r&&o===s)return!0}return!1},applyFunctions:{[X.SERIES]:(i,e,t)=>{var s;const{data:n}=i;let o;if(n.length===1)return o=t===a.Direction.DOWN||t===a.Direction.RIGHT?1:-1,Yi(n,e,o);const r=[];for(let l=0;l<n.length;l++){const c=`${(s=n[l])==null?void 0:s.v}`;c&&r.push(Number(Ft(c).matchTxt))}return(t===a.Direction.UP||t===a.Direction.LEFT)&&(n.reverse(),r.reverse()),Ht(r)?(o=r[1]-r[0],Yi(n,e,o)):Ge(n,e)}}},El={type:te.CHN_NUMBER,priority:830,match:i=>!!Sl(`${i==null?void 0:i.v}`||""),isContinue:(i,e)=>i.type===te.CHN_NUMBER,applyFunctions:{[X.SERIES]:(i,e,t)=>{var c,d,u;const{data:n}=i,o=t===a.Direction.LEFT||t===a.Direction.UP;if(n.length===1){const h=`${(c=n[0])==null?void 0:c.v}`;let m;return o?m=-1:m=1,h&&(h==="日"||Oe(h)<7)?rt(n,e,m):Zi(n,e,m)}let r=!1;for(let h=0;h<n.length;h++)if(((d=n[h])==null?void 0:d.v)==="日"){r=!0;break}const s=[];let l=0;for(let h=0;h<n.length;h++){const m=`${(u=n[h])==null?void 0:u.v}`;m==="日"?h===0?s.push(0):(l++,s.push(l*7)):r&&Oe(m)>0&&Oe(m)<7?s.push(Oe(m)+l*7):s.push(Oe(m))}if(o&&(n.reverse(),s.reverse()),Ht(s)){if(r||s[s.length-1]<6&&s[0]>0||s[0]<6&&s[s.length-1]>0){const m=s[1]-s[0];return rt(n,e,m)}const h=s[1]-s[0];return Zi(n,e,h)}return Ge(n,e)}}},yl={type:te.CHN_WEEK2,priority:820,match:i=>!!_l(`${i==null?void 0:i.v}`||""),isContinue:(i,e)=>i.type===te.CHN_WEEK2,applyFunctions:{[X.SERIES]:(i,e,t)=>{var l;const{data:n}=i,o=t===a.Direction.LEFT||t===a.Direction.UP;if(n.length===1){let c;return o?c=-1:c=1,rt(n,e,c,1)}const r=[];let s=0;for(let c=0;c<n.length;c++){const d=`${(l=n[c])==null?void 0:l.v}`,u=d==null?void 0:d.substr(d.length-1,1);d==="周日"?c===0?r.push(0):(s++,r.push(s*7)):r.push(Oe(u)+s*7)}if(o&&(n.reverse(),r.reverse()),Ht(r)){const c=r[1]-r[0];return rt(n,e,c,1)}return Ge(n,e)}}},Ol={type:te.CHN_WEEK3,priority:810,match:i=>gl(`${i==null?void 0:i.v}`||""),isContinue:(i,e)=>i.type===te.CHN_WEEK3,applyFunctions:{[X.SERIES]:(i,e,t)=>{var l;const{data:n}=i,o=t===a.Direction.LEFT||t===a.Direction.UP;if(n.length===1){let c;return o?c=-1:c=1,rt(n,e,c,2)}const r=[];let s=0;for(let c=0;c<n.length;c++){const d=`${(l=n[c])==null?void 0:l.v}`;if(d){const u=d.substr(d.length-1,1);d==="星期日"?c===0?r.push(0):(s++,r.push(s*7)):r.push(Oe(u)+s*7)}}if(o&&(n.reverse(),r.reverse()),Ht(r)){const c=r[1]-r[0];return rt(n,e,c,2)}return Ge(n,e)}}},xl={type:te.LOOP_SERIES,priority:800,match:i=>bl(`${i==null?void 0:i.v}`||""),isContinue:(i,e)=>{var t;return i.type===te.LOOP_SERIES?kn(`${(t=i.cellData)==null?void 0:t.v}`||"").name===kn(`${e==null?void 0:e.v}`||"").name:!1},applyFunctions:{[X.SERIES]:(i,e,t)=>{var c,d;const{data:n}=i,o=t===a.Direction.LEFT||t===a.Direction.UP,{series:r}=kn(`${(c=n[0])==null?void 0:c.v}`||"");if(n.length===1){let u;return o?u=-1:u=1,Gi(n,e,u,r)}const s=[];let l=0;for(let u=0;u<n.length;u++){const h=`${(d=n[u])==null?void 0:d.v}`;h&&(h===r[0]?u===0?s.push(0):(l++,s.push(l*r.length)):s.push(r.indexOf(h)+l*7))}if(o&&(n.reverse(),s.reverse()),Ht(s)){const u=s[1]-s[0];return Gi(n,e,u,r)}return Ge(n,e)}}};var Al=Object.defineProperty,Hl=Object.getOwnPropertyDescriptor,Dl=(i,e,t,n)=>{for(var o=n>1?void 0:n?Hl(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Al(e,t,o),o},Bn=(i,e)=>(t,n)=>e(t,n,i);exports.AutoFillService=class extends a.Disposable{constructor(t,n,o){super();v(this,"_rules",[]);v(this,"_hooks",[]);v(this,"_applyType$",new k.BehaviorSubject(X.SERIES));v(this,"_isFillingStyle",!0);v(this,"_sourceRange",null);v(this,"_destRange",null);v(this,"_applyRange",null);v(this,"applyType$",this._applyType$.asObservable());v(this,"_menu$",new k.BehaviorSubject([{label:"autoFill.copy",value:X.COPY,disable:!1},{label:"autoFill.series",value:X.SERIES,disable:!1},{label:"autoFill.formatOnly",value:X.ONLY_FORMAT,disable:!1},{label:"autoFill.noFormat",value:X.NO_FORMAT,disable:!1}]));v(this,"menu$",this._menu$.asObservable());this._sheetInterceptorService=t,this._univerInstanceService=n,this._selectionManagerService=o,this._init()}_init(){this._rules=[wl,Tl,El,yl,Ol,xl,Go].sort((t,n)=>n.priority-t.priority),this._isFillingStyle=!0}addHook(t){if(this._hooks.find(n=>n.hookName===t.hookName))throw new Error(`Add hook failed, hook name '${t.hookName}' already exist!`);return this._hooks.push(t),a.toDisposable(()=>{const n=this._hooks.findIndex(o=>o===t);n>-1&&this._hooks.splice(n,1)})}registerRule(t){if(this._rules.find(o=>o.type===t.type))throw new Error(`Registry rule failed, type '${t.type}' already exist!`);const n=this._rules.findIndex(o=>o.priority<t.priority);this._rules.splice(n===-1?this._rules.length:n,0,t)}getRules(){return this._rules}getHooks(){return this._hooks}getApplyType(){return this._applyType$.getValue()}setApplyType(t){this._applyType$.next(t)}isFillingStyle(){return this._isFillingStyle}setFillingStyle(t){this._isFillingStyle=t}setRanges(t,n,o){this._sourceRange=n,this._destRange=t,this._applyRange=o}getRanges(){return{sourceRange:this._sourceRange,destRange:this._destRange,applyRange:this._applyRange}}setDisableApplyType(t,n){this._menu$.next(this._menu$.getValue().map(o=>o.value===t?{...o,disable:n}:o))}};exports.AutoFillService=Dl([a.OnLifecycle(a.LifecycleStages.Rendered,exports.AutoFillService),Bn(0,P.Inject(f.SheetInterceptorService)),Bn(1,P.Inject(a.IUniverInstanceService)),Bn(2,P.Inject(f.SelectionManagerService))],exports.AutoFillService);const Dt=P.createIdentifier("univer.auto-fill-service");var Nl=Object.defineProperty,Pl=Object.getOwnPropertyDescriptor,Ll=(i,e,t,n)=>{for(var o=n>1?void 0:n?Pl(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Nl(e,t,o),o},Je=(i,e)=>(t,n)=>e(t,n,i);exports.AutoFillController=class extends a.Disposable{constructor(t,n,o,r,s,l){super();v(this,"_direction",null);v(this,"_beforeApplyData",[]);v(this,"_applyType",X.SERIES);v(this,"_hasFillingStyle",!0);v(this,"_copyData",[]);this._univerInstanceService=t,this._selectionRenderService=n,this._commandService=o,this._autoFillService=r,this._editorBridgeService=s,this._selectionManagerService=l,this._init()}_init(){this._onSelectionControlFillChanged(),this._onApplyTypeChanged(),[Cn,zt].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_handleDbClickFill(t){const n=this._detectFillRange(t);n.endRow<=t.endRow||this._handleFill(t,n)}_detectFillRange(t){var m,S,g,_,I,C;const{startRow:n,endRow:o,startColumn:r,endColumn:s}=t,l=(m=this._univerInstanceService.getCurrentUniverSheetInstance())==null?void 0:m.getActiveSheet();if(!l)return t;const c=l.getCellMatrix(),d=l.getMaxRows()-1,u=l.getMaxColumns()-1;let h=o;if(r>0&&((S=c.getValue(n,r-1))==null?void 0:S.v)!=null){let b=n;for(;((g=c.getValue(b,r-1))==null?void 0:g.v)!=null&&b<d;)b+=1;h=b}else if(s<u&&((_=c.getValue(o,s+1))==null?void 0:_.v)!=null){let b=n;for(;((I=c.getValue(b,s+1))==null?void 0:I.v)!=null&&b<d;)b++;h=b}for(let b=o+1;b<=h;b++)for(let M=r;M<=s;M++)if(((C=c.getValue(b,M))==null?void 0:C.v)!=null){h=b-1;break}return{startColumn:r,endColumn:s,startRow:n,endRow:h}}_handleFill(t,n){if(!(t.startColumn===n.startColumn&&t.startRow===n.startRow&&t.endColumn===n.endColumn&&t.endRow===n.endRow)){if(n.endColumn<t.endColumn&&n.endColumn>t.startColumn){this._commandService.executeCommand(zt.id,{clearRange:{startRow:n.startRow,endRow:n.endRow,startColumn:n.endColumn+1,endColumn:t.endColumn},selectionRange:n});return}if(n.endRow<t.endRow&&n.endRow>t.startRow){this._commandService.executeCommand(zt.id,{clearRange:{startRow:n.endRow+1,endRow:t.endRow,startColumn:n.startColumn,endColumn:n.endColumn},selectionRange:n});return}this._presetAndCacheData(t,n)}}_onSelectionControlFillChanged(){const t=new a.DisposableCollection;this.disposeWithMe(a.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(()=>{t.dispose();const n=this._selectionManagerService.getCurrent();if((n==null?void 0:n.pluginName)!==f.NORMAL_SELECTION_PLUGIN_NAME)return;this._selectionRenderService.getCurrentControls().forEach(r=>{t.add(a.toDisposable(r.selectionFilled$.subscribe(s=>{if(s==null)return;const l={startColumn:r.model.startColumn,endColumn:r.model.endColumn,startRow:r.model.startRow,endRow:r.model.endRow},c={startColumn:s.startColumn,endColumn:s.endColumn,startRow:s.startRow,endRow:s.endRow};this._handleFill(l,c)}))),t.add(a.toDisposable(r.fillControl.onDblclickObserver.add(()=>{const s={startColumn:r.model.startColumn,endColumn:r.model.endColumn,startRow:r.model.startRow,endRow:r.model.endRow};this._handleDbClickFill(s)}))),t.add(a.toDisposable(r.fillControl.onPointerDownObserver.add(()=>{this._editorBridgeService.isVisible().visible&&this._editorBridgeService.changeVisible({visible:!1,eventType:w.DeviceInputEventType.PointerDown})})))})})))}_onApplyTypeChanged(){this.disposeWithMe(a.toDisposable(this._autoFillService.applyType$.subscribe(t=>{t===X.NO_FORMAT?(this._applyType=X.SERIES,this._hasFillingStyle=!1):(this._applyType=t||X.SERIES,this._hasFillingStyle=!0),this._fillData()})))}_getApplyData(t,n,o,r,s,l=!0){const c=[],d=Math.floor(o/n),u=o%n,h=this._autoFillService.getRules();if(!l&&s===X.ONLY_FORMAT)return console.error("ERROR: only format can not be applied when hasStyle is false"),[];const m={};h.forEach(S=>{m[S.type]=[]}),h.forEach(S=>{const{type:g,applyFunctions:_={}}=S,I=t[g];I&&I.forEach(C=>{const b=fl(C.index,u),M=C.index.length*d+b,T=this._applyFunctions(C,M,r,s,_,t),E=pl(n,o,C.index);m[g].push({data:T,index:E})})});for(let S=0;S<o;S++)h.forEach(g=>{const{type:_}=g,I=m[_];for(let C=0;C<I.length;C++)S in I[C].index&&c.push(I[C].data[I[C].index[S]])});return c}_applyFunctions(t,n,o,r,s,l){const{data:c}=t,d=o===a.Direction.UP||o===a.Direction.LEFT;if(r===X.COPY){const u=s==null?void 0:s[X.COPY];return u?u(t,n,o,l):(d&&c.reverse(),Ge(c,n))}if(r===X.SERIES){const u=s==null?void 0:s[X.SERIES];return u?u(t,n,o,l):(d&&c.reverse(),s!=null&&s[X.COPY]?s[X.COPY](t,n,o,l):Ge(c,n))}if(r===X.ONLY_FORMAT){const u=s==null?void 0:s[X.ONLY_FORMAT];return u?u(t,n,o,l):vl(c,n)}}_getCopyData(t,n){const{startRow:o,startColumn:r,endRow:s,endColumn:l}=t,c=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getCellMatrix(),d=this._autoFillService.getRules(),u=[],h=n===a.Direction.DOWN||n===a.Direction.UP;let m,S,g,_;h?(m=r,S=l,g=o,_=s):(m=o,S=s,g=r,_=l);for(let I=m;I<=S;I++){const C=this._getEmptyCopyDataPiece(),b={type:void 0,cellData:void 0};for(let M=g;M<=_;M++){let T;h?T=c.getValue(M,I):T=c.getValue(I,M);const{type:E,isContinue:y}=d.find(O=>O.match(T))||Go;if(y(b,T)){const O=C[E],x=O[O.length-1];x.data.push(T),x.index.push(M-g)}else{const O=C[E];O?O.push({data:[T],index:[M-g]}):C[E]=[{data:[T],index:[M-g]}]}b.type=E,b.cellData=T}u.push(C)}return u}_getEmptyCopyDataPiece(){const t={};return this._autoFillService.getRules().forEach(n=>{t[n.type]=[]}),t}_getMergeApplyData(t,n,o,r){const s=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getMergeData(),l=[];for(let c=t.startRow;c<=t.endRow;c++)for(let d=t.startColumn;d<=t.endColumn;d++){const{isMergedMainCell:u,startRow:h,startColumn:m,endRow:S,endColumn:g}=w.getCellInfoInMergeData(c,d,s);if(u){if(o===a.Direction.DOWN){let _=h+r,I=S+r;for(;I<=n.endRow;)l.push({startRow:_,startColumn:m,endRow:I,endColumn:g}),_+=r,I+=r}else if(o===a.Direction.UP){let _=h-r,I=S-r;for(;_>=n.startRow;)l.push({startRow:_,startColumn:m,endRow:I,endColumn:g}),_-=r,I-=r}else if(o===a.Direction.RIGHT){let _=m+r,I=g+r;for(;I<=n.endColumn;)l.push({startRow:h,startColumn:_,endRow:S,endColumn:I}),_+=r,I+=r}else if(o===a.Direction.LEFT){const _=m-r,I=g-r;for(;_>=n.startColumn;)l.push({startRow:h,startColumn:_,endRow:S,endColumn:I})}}}return l}_presetAndCacheData(t,n){const o={startRow:n.startRow,endRow:n.endRow,startColumn:n.startColumn,endColumn:n.endColumn};let r=null;if(n.startRow<t.startRow)r=a.Direction.UP,o.endRow=t.startRow-1;else if(n.endRow>t.endRow)r=a.Direction.DOWN,o.startRow=t.endRow+1;else if(n.startColumn<t.startColumn)r=a.Direction.LEFT,o.endColumn=t.startColumn-1;else if(n.endColumn>t.endColumn)r=a.Direction.RIGHT,o.startColumn=t.endColumn+1;else return;this._direction=r;const s=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getCellMatrix(),l=[];for(let c=o.startRow;c<=o.endRow;c++){const d=[];for(let u=o.startColumn;u<=o.endColumn;u++)d.push(a.Tools.deepClone(s.getValue(c,u)));l.push(d)}this._beforeApplyData=l,this._autoFillService.setRanges(n,t,o),this._copyData=this._getCopyData(t,r),this._hasSeries(this._copyData)?(this._autoFillService.setDisableApplyType(X.SERIES,!1),this._autoFillService.setApplyType(X.SERIES)):(this._autoFillService.setDisableApplyType(X.SERIES,!0),this._autoFillService.setApplyType(X.COPY))}_fillData(){const{destRange:t,sourceRange:n,applyRange:o}=this._autoFillService.getRanges(),r=this._applyType,s=this._hasFillingStyle,l=this._direction;if(!t||!n||!o||l==null)return;const{startRow:c,startColumn:d,endRow:u,endColumn:h}=n,{startRow:m,startColumn:S,endRow:g,endColumn:_}=o,I=this._copyData;let C;l===a.Direction.DOWN||l===a.Direction.UP?C=u-c+1:C=h-d+1;const b=[];if(l===a.Direction.DOWN||l===a.Direction.UP){const D=g-m+1,U=[];for(let N=S;N<=_;N++){const B=I[N-S],A=this._getApplyData(B,C,D,l,r,s);U.push(A)}for(let N=0;N<U[0].length;N++){const B=[];for(let A=0;A<U.length;A++)B.push({v:null,s:null,...this._beforeApplyData[N][A],...U[A][N]});b.push(B)}}else{const D=_-S+1;for(let U=m;U<=g;U++){const N=I[U-m],B=this._getApplyData(N,C,D,l,r,s),A=[];for(let H=0;H<B.length;H++)A.push({v:null,s:null,...this._beforeApplyData[U-m][H],...B[H]});b.push(A)}}let M;const T=this._univerInstanceService.getCurrentUniverSheetInstance().getStyles();s?(M=this._getMergeApplyData(n,t,l,C),b.forEach(D=>{D.forEach(U=>{U&&T&&T&&(U.s=T.getStyleByCell(U))})})):b.forEach((D,U)=>{D.forEach((N,B)=>{N&&T&&(N.s=T.getStyleByCell(this._beforeApplyData[U][B])||null)})});const E=this._autoFillService.getHooks(),y=[],O=[],x=this._hasFillingStyle?r:X.NO_FORMAT;E.forEach(D=>{const{hook:U}=D,{redos:N,undos:B}=U==null?void 0:U[x](n,o);y.push(...N),O.push(...B)}),this._commandService.executeCommand(Cn.id,{selectionRange:t,applyRange:o,applyDatas:b,unitId:this._univerInstanceService.getCurrentUniverSheetInstance().getUnitId(),subUnitId:this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId(),extendMutations:{undo:O,redo:y},applyMergeRanges:M})}_hasSeries(t){return t.some(n=>Object.keys(n).some(r=>{var s;return!!((s=n[r])!=null&&s.length&&![te.OTHER,te.FORMULA].includes(r))}))}};exports.AutoFillController=Ll([a.OnLifecycle(a.LifecycleStages.Steady,exports.AutoFillController),Je(0,a.IUniverInstanceService),Je(1,ce),Je(2,a.ICommandService),Je(3,Dt),Je(4,pe),Je(5,P.Inject(f.SelectionManagerService))],exports.AutoFillController);const Si={type:a.CommandType.COMMAND,id:"sheet.command.set-range-bold",handler:async i=>{const e=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.FOCUSING_EDITOR)?e.executeCommand(K.SetInlineFormatBoldCommand.id):e.executeCommand(f.SetBoldCommand.id)}},_i={type:a.CommandType.COMMAND,id:"sheet.command.set-range-italic",handler:async i=>{const e=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.FOCUSING_EDITOR)?e.executeCommand(K.SetInlineFormatItalicCommand.id):e.executeCommand(f.SetItalicCommand.id)}},gi={type:a.CommandType.COMMAND,id:"sheet.command.set-range-underline",handler:async i=>{const e=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.FOCUSING_EDITOR)?e.executeCommand(K.SetInlineFormatUnderlineCommand.id):e.executeCommand(f.SetUnderlineCommand.id)}},fi={type:a.CommandType.COMMAND,id:"sheet.command.set-range-stroke",handler:async i=>{const e=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.FOCUSING_EDITOR)?e.executeCommand(K.SetInlineFormatStrikethroughCommand.id):e.executeCommand(f.SetStrikeThroughCommand.id)}},Ul={type:a.CommandType.COMMAND,id:"sheet.command.set-range-subscript",handler:async i=>{const e=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.FOCUSING_EDITOR)?e.executeCommand(K.SetInlineFormatSubscriptCommand.id):!1}},kl={type:a.CommandType.COMMAND,id:"sheet.command.set-range-superscript",handler:async i=>{const e=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.FOCUSING_EDITOR)?e.executeCommand(K.SetInlineFormatSuperscriptCommand.id):!1}},Ko={type:a.CommandType.COMMAND,id:"sheet.command.set-range-fontsize",handler:async(i,e)=>{const t=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.FOCUSING_EDITOR)?t.executeCommand(K.SetInlineFormatFontSizeCommand.id,e):t.executeCommand(f.SetFontSizeCommand.id,e)}},qo={type:a.CommandType.COMMAND,id:"sheet.command.set-range-font-family",handler:async(i,e)=>{const t=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.FOCUSING_EDITOR)?t.executeCommand(K.SetInlineFormatFontFamilyCommand.id,e):t.executeCommand(f.SetFontFamilyCommand.id,e)}},wn={type:a.CommandType.COMMAND,id:"sheet.command.set-range-text-color",handler:async(i,e)=>{const t=i.get(a.ICommandService);return i.get(a.IContextService).getContextValue(a.FOCUSING_EDITOR)?t.executeCommand(K.SetInlineFormatTextColorCommand.id,e):t.executeCommand(f.SetTextColorCommand.id,e)}};function Jo(i,e){return e.some(t=>Bl(i,t))}function Bl(i,e){const{startRow:t,startColumn:n,endColumn:o,endRow:r}=e,s=i.getMatrixWithMergedCells(t,n,r,o);let l=!1;return s.forValue((c,d,u)=>{if(u&&(c!==t||d!==n)&&i.cellHasValue(u))return l=!0,!1}),l}function Qo(i,e,t,n){const o=[],r=[],s=t.getSheetId();return n.forEach(l=>{const c=Vl(t,l),d={unitId:e,subUnitId:s,cellValue:c.getData()},u=f.SetRangeValuesUndoMutationFactory(i,d);o.push({id:f.SetRangeValuesMutation.id,params:u}),r.push({id:f.SetRangeValuesMutation.id,params:d})}),{undos:o,redos:r}}function Vl(i,e){const{startRow:t,startColumn:n,endColumn:o,endRow:r}=e,s=i.getMatrixWithMergedCells(t,n,r,o),l=new a.ObjectMatrix;return s.forValue((c,d,u)=>{u&&(c!==t||d!==n)&&l.setValue(c,d,null)}),l}var Fl=Object.defineProperty,jl=Object.getOwnPropertyDescriptor,Wl=(i,e,t,n)=>{for(var o=n>1?void 0:n?jl(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Fl(e,t,o),o},Vn=(i,e)=>(t,n)=>e(t,n,i),fe=(i=>(i[i.OFF=0]="OFF",i[i.ONCE=1]="ONCE",i[i.INFINITE=2]="INFINITE",i))(fe||{});const dt=P.createIdentifier("univer.format-painter-service");let ni=class extends a.Disposable{constructor(e,t,n){super();v(this,"status$");v(this,"_selectionFormat");v(this,"_markId",null);v(this,"_status$");this._selectionManagerService=e,this._univerInstanceService=t,this._markSelectionService=n,this._status$=new k.BehaviorSubject(0),this.status$=this._status$.asObservable(),this._selectionFormat={styles:new a.ObjectMatrix,merges:[]}}setStatus(e){e!==0&&this._getSelectionRangeFormat(),this._updateRangeMark(e),this._status$.next(e)}getStatus(){return this._status$.getValue()}_updateRangeMark(e){if(this._markSelectionService.removeAllShapes(),this._markId=null,e!==0){const t=this._selectionManagerService.getLast();if(t){const n=this._selectionManagerService.createCopyPasteSelection();this._markId=this._markSelectionService.addShape({...t,style:n})}}}_getSelectionRangeFormat(){const e=this._selectionManagerService.getLast(),t=e==null?void 0:e.range;if(!t)return;const{startRow:n,endRow:o,startColumn:r,endColumn:s}=t,l=this._univerInstanceService.getCurrentUniverSheetInstance(),d=(l==null?void 0:l.getActiveSheet()).getCellMatrix(),u=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getMergeData(),h=l.getStyles(),m=new a.ObjectMatrix;for(let S=n;S<=o;S++)for(let g=r;g<=s;g++){const _=d.getValue(S,g);m.setValue(S,g,h.getStyleByCell(_)||{});const{isMergedMainCell:I,...C}=w.getCellInfoInMergeData(S,g,u);I&&this._selectionFormat.merges.push({startRow:C.startRow,startColumn:C.startColumn,endRow:C.endRow,endColumn:C.endColumn})}this._selectionFormat.styles=m}getSelectionFormat(){return this._selectionFormat}};ni=Wl([Vn(0,P.Inject(f.SelectionManagerService)),Vn(1,a.IUniverInstanceService),Vn(2,At)],ni);const pi={id:"sheet.operation.set-format-painter",type:a.CommandType.OPERATION,handler:(i,e)=>e?(i.get(dt).setStatus(e.status),!0):!1},er={type:a.CommandType.COMMAND,id:"sheet.command.set-infinite-format-painter",handler:async i=>{const t=i.get(dt).getStatus();let n;return t!==fe.OFF?n=fe.OFF:n=fe.INFINITE,i.get(a.ICommandService).executeCommand(pi.id,{status:n})}},vi={type:a.CommandType.COMMAND,id:"sheet.command.set-once-format-painter",handler:async i=>{const t=i.get(dt).getStatus();let n;return t!==fe.OFF?n=fe.OFF:n=fe.ONCE,i.get(a.ICommandService).executeCommand(pi.id,{status:n})}},tr={type:a.CommandType.COMMAND,id:"sheet.command.apply-format-painter",handler:async(i,e)=>{const t=i.get(a.ICommandService),n=i.get(a.IUndoRedoService),o=i.get(a.IUniverInstanceService),r=i.get(f.SelectionManagerService),s=i.get(f.SheetInterceptorService),{styleValues:l,styleRange:c,mergeRanges:d,unitId:u=o.getCurrentUniverSheetInstance().getUnitId(),subUnitId:h=o.getCurrentUniverSheetInstance().getActiveSheet().getSheetId()}=e,m=c?[c]:r.getSelectionRanges();if(!m||!m.length)return!1;const S=new a.ObjectMatrix;let g;if(a.Tools.isArray(l))for(let H=0;H<m.length;H++){const{startRow:V,startColumn:F,endRow:j,endColumn:$}=m[H];for(let q=0;q<=j-V;q++)for(let z=0;z<=$-F;z++)S.setValue(q+V,z+F,l[q][z])}else if(a.isICellData(l))for(let H=0;H<m.length;H++){const{startRow:V,startColumn:F}=m[H];S.setValue(V,F,l)}else g=l;const _={subUnitId:h,unitId:u,cellValue:g??S.getMatrix()},I=f.SetRangeValuesUndoMutationFactory(i,_);if(!s.fetchThroughInterceptors(f.INTERCEPTOR_POINT.PERMISSION)(null,{id:f.SetRangeValuesCommand.id,params:_}))return!1;const C=t.syncExecuteCommand(f.SetRangeValuesMutation.id,_),{undos:b,redos:M}=s.onCommandExecute({id:f.SetRangeValuesCommand.id,params:{..._,range:m}}),T=f.getAddMergeMutationRangeByType(d),E=o.getUniverSheetInstance(u).getSheetBySheetId(h),y=[],O=[],x=Jo(E,T),D={unitId:u,subUnitId:h,ranges:T},U={unitId:u,subUnitId:h,ranges:T};y.push({id:f.RemoveWorksheetMergeMutation.id,params:D}),y.push({id:f.AddWorksheetMergeMutation.id,params:U});const N=f.RemoveMergeUndoMutationFactory(i,D),B=f.AddMergeUndoMutationFactory(i,U);if(O.push({id:f.RemoveWorksheetMergeMutation.id,params:B}),O.push({id:f.AddWorksheetMergeMutation.id,params:N}),x){const H=Qo(i,u,E,T);y.unshift(...H.redos),O.push(...H.undos)}const A=await a.sequenceExecute([...M,...y],t);return C&&A.result?(n.pushUndoRedo({unitID:u,undoMutations:[{id:f.SetRangeValuesMutation.id,params:I},...b,...O],redoMutations:[{id:f.SetRangeValuesMutation.id,params:_},...M,...y]}),!0):!1}},An={type:a.CommandType.COMMAND,id:"sheet.command.set-selection-frozen",handler:async(i,e)=>{const{type:t}=e||{},n=i.get(a.IUniverInstanceService),o=i.get(a.IUndoRedoService),r=n.getCurrentUniverSheetInstance().getUnitId(),s=n.getCurrentUniverSheetInstance().getActiveSheet().getSheetId(),l=i.get(a.ICommandService),d=i.get(f.SelectionManagerService).getSelections();if(!d)return!1;const u=d[(d==null?void 0:d.length)-1],{range:h}=u,m=i.get(ke),{sheetViewStartRow:S=0,sheetViewStartColumn:g=0}=m.getCurrentScroll()||{};let _,I,C,b;const{startRow:M,startColumn:T,rangeType:E}=h;if(E===a.RANGE_TYPE.ROW||t===1)_=M,C=M-S,I=-1,b=0;else if(E===a.RANGE_TYPE.COLUMN||t===2)_=-1,C=0,I=T,b=T-g;else if(E===a.RANGE_TYPE.NORMAL)_=M,C=M-S,I=T,b=T-g;else return!1;const y={unitId:r,subUnitId:s,startRow:_,startColumn:I,xSplit:b,ySplit:C},O=f.SetFrozenMutationFactory(i,y);return l.syncExecuteCommand(f.SetFrozenMutation.id,y)&&o.pushUndoRedo({unitID:r,undoMutations:[{id:f.SetFrozenMutation.id,params:O}],redoMutations:[{id:f.SetFrozenMutation.id,params:y}]}),!0}},nr={type:a.CommandType.COMMAND,id:"sheet.command.set-row-frozen",handler:async i=>(i.get(a.ICommandService).executeCommand(An.id,{type:1}),!0)},ir={type:a.CommandType.COMMAND,id:"sheet.command.set-col-frozen",handler:async i=>(i.get(a.ICommandService).executeCommand(An.id,{type:2}),!0)},or={type:a.CommandType.COMMAND,id:"sheet.command.cancel-frozen",handler:async i=>{const e=i.get(a.ICommandService),t=i.get(a.IUniverInstanceService),n=i.get(a.IUndoRedoService),o=t.getCurrentUniverSheetInstance().getUnitId(),r=t.getCurrentUniverSheetInstance().getActiveSheet().getSheetId(),s={unitId:o,subUnitId:r,startRow:-1,startColumn:-1,xSplit:0,ySplit:0},l=f.SetFrozenMutationFactory(i,s);return e.syncExecuteCommand(f.SetFrozenMutation.id,s)&&n.pushUndoRedo({unitID:o,undoMutations:[{id:f.SetFrozenMutation.id,params:l}],redoMutations:[{id:f.SetFrozenMutation.id,params:s}]}),!0}},ut="UI_PLUGIN_SHEETS",Hn=`${ut}_COLOR_PICKER_COMPONENT`,$l="univer-ui-plugin-sheets-font-family",zl="univer-ui-plugin-sheets-font-family-item",rr={uiPluginSheetsFontFamily:$l,uiPluginSheetsFontFamilyItem:zl},Xl=i=>{const{value:e}=i,t=W.useDependency(a.LocaleService);return p.jsx("div",{className:rr.uiPluginSheetsFontFamily,style:{fontFamily:e},children:t.t(`fontFamily.${(`${e}`??"").replace(/\s/g,"")}`)})},Yl=i=>{const{value:e}=i,t=W.useDependency(a.LocaleService);return p.jsx("span",{className:rr.uiPluginSheetsFontFamilyItem,style:{fontFamily:e},children:t.t(`fontFamily.${(`${e}`??"").replace(/\s/g,"")}`)})},sr=`${ut}_FONT_FAMILY_COMPONENT`,se=`${ut}_FONT_FAMILY_ITEM_COMPONENT`,Zl="univer-ui-plugin-sheets-font-size",Gl="univer-ui-plugin-sheets-font-size-input",Ki={uiPluginSheetsFontSize:Zl,uiPluginSheetsFontSizeInput:Gl},Kl=i=>{const{value:e,min:t,max:n,onChange:o}=i,[r,s]=L.useState(Number(e??0)),l=L.useMemo(()=>Number(e??r),[e]);function c(u){u!==null&&s(u)}function d(u){u.stopPropagation(),u.code==="Enter"&&o(r.toString())}return p.jsx("div",{className:Ki.uiPluginSheetsFontSize,children:p.jsx(ie.InputNumber,{className:Ki.uiPluginSheetsFontSizeInput,value:l,controls:!1,min:t,max:n,onKeyDown:d,onChange:c})})},lr=`${ut}_FONT_SIZE_COMPONENT`,Ci=`${ut}_MENU_ITEM_INPUT_COMPONENT`,ql="univer-sheets-ui-context-menu-input",Jl="univer-sheets-ui-context-menu-input-container",Ql="univer-sheets-ui-context-menu-input-number",Fn={sheetsUiContextMenuInput:ql,sheetsUiContextMenuInputContainer:Jl,sheetsUiContextMenuInputNumber:Ql},ea=i=>{const{prefix:e,suffix:t,value:n,onChange:o}=i,r=W.useDependency(a.LocaleService),[s,l]=L.useState(),c=u=>{l(u==null?void 0:u.toString()),o((u==null?void 0:u.toString())??"")};L.useEffect(()=>{l(n)},[n]);function d(u){u.key==="Backspace"&&u.stopPropagation()}return p.jsxs("div",{className:Fn.sheetsUiContextMenuInput,children:[r.t(e),p.jsx("span",{className:Fn.sheetsUiContextMenuInputContainer,onClick:u=>u.stopPropagation(),children:p.jsx(ie.InputNumber,{className:Fn.sheetsUiContextMenuInputNumber,value:Number(s),precision:0,onKeyDown:d,onChange:c})}),r.t(t)]})};var ee=(i=>(i.ROW_HEADER_CONTEXT_MENU="rowHeaderContextMenu",i.COL_HEADER_CONTEXT_MENU="colHeaderContextMenu",i.SHEET_BAR="sheetBar",i))(ee||{});function ta(i){const e=i.get(dt);return i.get(a.IUniverInstanceService),{id:vi.id,subId:er.id,group:R.MenuGroup.TOOLBAR_FORMAT,type:R.MenuItemType.BUTTON,icon:"BrushSingle",title:"Format Painter",tooltip:"toolbar.formatPainter",positions:[R.MenuPosition.TOOLBAR_START],activated$:new k.Observable(t=>{let n=!1;const o=e.status$.subscribe(r=>{n=r!==fe.OFF,t.next(n)});return t.next(n),()=>{o.unsubscribe()}}),hidden$:R.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}function na(i){const e=i.get(a.ICommandService),t=i.get(f.SheetPermissionService),n=i.get(a.IUniverInstanceService),o=i.get(f.SelectionManagerService),r=n.getCurrentUniverSheetInstance().getUnitId(),s=n.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();return{id:Si.id,group:R.MenuGroup.TOOLBAR_FORMAT,type:R.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",positions:[R.MenuPosition.TOOLBAR_START],disabled$:new k.Observable(l=>{var d;const c=(d=t.getEditable$(r,s))==null?void 0:d.subscribe(u=>{l.next(!u.value)});return()=>{c==null||c.unsubscribe()}}),activated$:new k.Observable(l=>{const c=e.onCommandExecuted(d=>{var g;const u=d.id;if(u!==f.SetRangeValuesMutation.id&&u!==f.SetSelectionsOperation.id)return;const h=(g=o.getLast())==null?void 0:g.primary,m=n.getCurrentUniverSheetInstance().getActiveSheet();let S=a.FontWeight.NORMAL;if(h!=null){const _=m.getRange(h.startRow,h.startColumn);S=_==null?void 0:_.getFontWeight()}l.next(S===a.FontWeight.BOLD)});return l.next(!1),c.dispose}),hidden$:R.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}function ia(i){const e=i.get(a.ICommandService),t=i.get(a.IUniverInstanceService),n=i.get(f.SelectionManagerService),o=i.get(f.SheetPermissionService),r=t.getCurrentUniverSheetInstance().getUnitId(),s=t.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();return{id:_i.id,group:R.MenuGroup.TOOLBAR_FORMAT,type:R.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",positions:[R.MenuPosition.TOOLBAR_START],disabled$:new k.Observable(l=>{var d;const c=(d=o.getEditable$(r,s))==null?void 0:d.subscribe(u=>{l.next(!u.value)});return()=>{c==null||c.unsubscribe()}}),activated$:new k.Observable(l=>{const c=e.onCommandExecuted(d=>{var g;const u=d.id;if(u!==f.SetRangeValuesMutation.id&&u!==f.SetSelectionsOperation.id)return;const h=(g=n.getLast())==null?void 0:g.primary,m=t.getCurrentUniverSheetInstance().getActiveSheet();let S=a.FontItalic.NORMAL;if(h!=null){const _=m.getRange(h.startRow,h.startColumn);S=_==null?void 0:_.getFontStyle()}l.next(S===a.FontItalic.ITALIC)});return l.next(!1),c.dispose}),hidden$:R.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}function oa(i){const e=i.get(a.ICommandService),t=i.get(a.IUniverInstanceService),n=i.get(f.SelectionManagerService),o=i.get(f.SheetPermissionService),r=t.getCurrentUniverSheetInstance().getUnitId(),s=t.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();return{id:gi.id,group:R.MenuGroup.TOOLBAR_FORMAT,type:R.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",positions:[R.MenuPosition.TOOLBAR_START],disabled$:new k.Observable(l=>{var d;const c=(d=o.getEditable$(r,s))==null?void 0:d.subscribe(u=>{l.next(!u.value)});return()=>{c==null||c.unsubscribe()}}),activated$:new k.Observable(l=>{const c=e.onCommandExecuted(d=>{var g;const u=d.id;if(u!==f.SetRangeValuesMutation.id&&u!==f.SetSelectionsOperation.id)return;const h=(g=n.getLast())==null?void 0:g.primary,m=t.getCurrentUniverSheetInstance().getActiveSheet();let S;if(h!=null){const _=m.getRange(h.startRow,h.startColumn);S=_==null?void 0:_.getUnderline()}l.next(!!(S&&S.s))});return l.next(!1),c.dispose}),hidden$:R.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}function ra(i){const e=i.get(a.ICommandService),t=i.get(a.IUniverInstanceService),n=i.get(f.SelectionManagerService),o=i.get(f.SheetPermissionService),r=t.getCurrentUniverSheetInstance().getUnitId(),s=t.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();return{id:fi.id,group:R.MenuGroup.TOOLBAR_FORMAT,type:R.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",positions:[R.MenuPosition.TOOLBAR_START],disabled$:new k.Observable(l=>{var d;const c=(d=o.getEditable$(r,s))==null?void 0:d.subscribe(u=>{l.next(!u.value)});return()=>{c==null||c.unsubscribe()}}),activated$:new k.Observable(l=>{const c=e.onCommandExecuted(d=>{var g;const u=d.id;if(u!==f.SetRangeValuesMutation.id&&u!==f.SetSelectionsOperation.id)return;const h=(g=n.getLast())==null?void 0:g.primary,m=t.getCurrentUniverSheetInstance().getActiveSheet();let S;if(h!=null){const _=m.getRange(h.startRow,h.startColumn);S=_==null?void 0:_.getStrikeThrough()}l.next(!!(S&&S.s))});return l.next(!1),c.dispose}),hidden$:R.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}const sa=[{label:"9",value:9},{label:"10",value:10},{label:"11",value:11},{label:"12",value:12},{label:"14",value:14},{label:"16",value:16},{label:"18",value:18},{label:"20",value:20},{label:"22",value:22},{label:"24",value:24},{label:"26",value:26},{label:"28",value:28},{label:"36",value:36},{label:"48",value:48},{label:"72",value:72}],qi=[{label:se,value:"Times New Roman"},{label:se,value:"Arial"},{label:se,value:"Tahoma"},{label:se,value:"Verdana"},{label:se,value:"Microsoft YaHei"},{label:se,value:"SimSun"},{label:se,value:"SimHei"},{label:se,value:"Kaiti"},{label:se,value:"FangSong"},{label:se,value:"NSimSun"},{label:se,value:"STXinwei"},{label:se,value:"STXingkai"},{label:se,value:"STLiti"}];function la(i){const e=i.get(a.ICommandService),t=i.get(a.IUniverInstanceService),n=i.get(f.SelectionManagerService),o=i.get(f.SheetPermissionService),r=t.getCurrentUniverSheetInstance().getUnitId(),s=t.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();return{id:qo.id,tooltip:"toolbar.font",group:R.MenuGroup.TOOLBAR_FORMAT,type:R.MenuItemType.SELECTOR,label:sr,positions:[R.MenuPosition.TOOLBAR_START],selections:qi,disabled$:new k.Observable(l=>{var d;const c=(d=o.getEditable$(r,s))==null?void 0:d.subscribe(u=>{l.next(!u.value)});return()=>{c==null||c.unsubscribe()}}),value$:new k.Observable(l=>{const c=qi[0].value,d=e.onCommandExecuted(u=>{var _;const h=u.id;if(h!==f.SetRangeValuesMutation.id&&h!==f.SetSelectionsOperation.id)return;const m=(_=n.getLast())==null?void 0:_.primary,S=t.getCurrentUniverSheetInstance().getActiveSheet();let g;if(m!=null){const I=S.getRange(m.startRow,m.startColumn);g=I==null?void 0:I.getFontFamily()}l.next(g??c)});return l.next(c),d.dispose}),hidden$:R.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}function aa(i){const e=i.get(a.ICommandService),t=i.get(a.IUniverInstanceService),n=i.get(f.SelectionManagerService),o=i.get(f.SheetPermissionService),r=t.getCurrentUniverSheetInstance().getUnitId(),s=t.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();return{id:Ko.id,group:R.MenuGroup.TOOLBAR_FORMAT,type:R.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:lr,props:{min:1,max:400}},positions:[R.MenuPosition.TOOLBAR_START],selections:sa,disabled$:new k.Observable(l=>{var d;const c=(d=o.getEditable$(r,s))==null?void 0:d.subscribe(u=>{l.next(!u.value)});return()=>{c==null||c.unsubscribe()}}),value$:new k.Observable(l=>{const d=e.onCommandExecuted(u=>{var _;const h=u.id;if(h!==f.SetRangeValuesMutation.id&&h!==f.SetSelectionsOperation.id)return;const m=(_=n.getLast())==null?void 0:_.primary,S=t.getCurrentUniverSheetInstance().getActiveSheet();let g;if(m!=null){const I=S.getRange(m.startRow,m.startColumn);g=I==null?void 0:I.getFontSize()}l.next(g??14)});return l.next(14),d.dispose}),hidden$:R.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}function ca(){return{id:f.ResetTextColorCommand.id,type:R.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:wn.id}}function da(i){const e=i.get(a.ICommandService),t=i.get(a.ThemeService);return i.get(a.IUniverInstanceService),{id:wn.id,icon:"FontColor",tooltip:"toolbar.textColor.main",group:R.MenuGroup.TOOLBAR_FORMAT,type:R.MenuItemType.BUTTON_SELECTOR,positions:[R.MenuPosition.TOOLBAR_START],selections:[{label:{name:Hn,hoverable:!1}}],value$:new k.Observable(n=>{const o=t.getCurrentTheme().textColor,r=e.onCommandExecuted(s=>{if(s.id===wn.id){const l=s.params.value;n.next(l??o)}});return n.next(o),r.dispose}),hidden$:R.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}function ua(){return{id:f.ResetBackgroundColorCommand.id,type:R.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:f.SetBackgroundColorCommand.id}}function ha(i){const e=i.get(a.ICommandService),t=i.get(a.ThemeService);return i.get(a.IUniverInstanceService),{id:f.SetBackgroundColorCommand.id,tooltip:"toolbar.fillColor.main",group:R.MenuGroup.TOOLBAR_FORMAT,type:R.MenuItemType.BUTTON_SELECTOR,positions:[R.MenuPosition.TOOLBAR_START],icon:"PaintBucket",selections:[{label:{name:Hn,hoverable:!1}}],value$:new k.Observable(n=>{const o=t.getCurrentTheme().primaryColor,r=e.onCommandExecuted(s=>{if(s.id===f.SetBackgroundColorCommand.id){const l=s.params.value;n.next(l??o)}});return n.next(o),r.dispose}),hidden$:R.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}const Ji=[{label:"align.left",icon:"LeftJustifyingSingle",value:a.HorizontalAlign.LEFT},{label:"align.center",icon:"HorizontallySingle",value:a.HorizontalAlign.CENTER},{label:"align.right",icon:"RightJustifyingSingle",value:a.HorizontalAlign.RIGHT}];function ma(i){const e=i.get(a.IUniverInstanceService),t=i.get(f.SelectionManagerService);return{id:f.SetHorizontalTextAlignCommand.id,icon:Ji[0].icon,positions:[R.MenuPosition.TOOLBAR_START],tooltip:"toolbar.horizontalAlignMode.main",group:R.MenuGroup.TOOLBAR_LAYOUT,type:R.MenuItemType.SELECTOR,selections:Ji,value$:new k.Observable(n=>{const o=i.get(a.ICommandService).onCommandExecuted(r=>{var u;const s=r.id;if(s!==f.SetHorizontalTextAlignCommand.id&&s!==f.SetSelectionsOperation.id)return;const l=(u=t.getLast())==null?void 0:u.primary,c=e.getCurrentUniverSheetInstance().getActiveSheet();let d;if(l!=null){const h=c.getRange(l.startRow,l.startColumn);d=h==null?void 0:h.getHorizontalAlignment()}n.next(d??a.HorizontalAlign.LEFT)});return n.next(a.HorizontalAlign.LEFT),o.dispose}),hidden$:R.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}const Qi=[{label:"align.top",icon:"AlignTopSingle",value:a.VerticalAlign.TOP},{label:"align.middle",icon:"VerticalCenterSingle",value:a.VerticalAlign.MIDDLE},{label:"align.bottom",icon:"AlignBottomSingle",value:a.VerticalAlign.BOTTOM}];function Sa(i){const e=i.get(a.IUniverInstanceService),t=i.get(f.SelectionManagerService);return{id:f.SetVerticalTextAlignCommand.id,icon:Qi[0].icon,tooltip:"toolbar.verticalAlignMode.main",group:R.MenuGroup.TOOLBAR_LAYOUT,type:R.MenuItemType.SELECTOR,positions:[R.MenuPosition.TOOLBAR_START],selections:Qi,value$:new k.Observable(n=>{const o=i.get(a.ICommandService).onCommandExecuted(r=>{var u;const s=r.id;if(s!==f.SetVerticalTextAlignCommand.id&&s!==f.SetSelectionsOperation.id)return;const l=(u=t.getLast())==null?void 0:u.primary,c=e.getCurrentUniverSheetInstance().getActiveSheet();let d;if(l!=null){const h=c.getRange(l.startRow,l.startColumn);d=h==null?void 0:h.getVerticalAlignment()}n.next(d??a.VerticalAlign.TOP)});return n.next(a.VerticalAlign.TOP),o.dispose}),hidden$:R.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}const eo=[{label:"textWrap.overflow",icon:"OverflowSingle",value:a.WrapStrategy.OVERFLOW},{label:"textWrap.wrap",icon:"AutowrapSingle",value:a.WrapStrategy.WRAP},{label:"textWrap.clip",icon:"TruncationSingle",value:a.WrapStrategy.CLIP}];function _a(i){const e=i.get(a.IUniverInstanceService),t=i.get(f.SelectionManagerService);return{id:f.SetTextWrapCommand.id,tooltip:"toolbar.textWrapMode.main",icon:eo[0].icon,group:R.MenuGroup.TOOLBAR_LAYOUT,type:R.MenuItemType.SELECTOR,positions:[R.MenuPosition.TOOLBAR_START],selections:eo,value$:new k.Observable(n=>{const o=i.get(a.ICommandService).onCommandExecuted(r=>{var u;const s=r.id;if(s!==f.SetTextWrapCommand.id&&s!==f.SetSelectionsOperation.id)return;const l=(u=t.getLast())==null?void 0:u.primary,c=e.getCurrentUniverSheetInstance().getActiveSheet();let d;if(l!=null){const h=c.getRange(l.startRow,l.startColumn);d=h==null?void 0:h.getWrapStrategy()}n.next(d??a.WrapStrategy.OVERFLOW)});return n.next(a.WrapStrategy.OVERFLOW),o.dispose}),hidden$:R.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}const to=[{label:"textRotate.none",icon:"NoRotationSingle",value:0},{label:"textRotate.angleUp",icon:"LeftRotationFortyFiveDegreesSingle",value:-45},{label:"textRotate.angleDown",icon:"RightRotationFortyFiveDegreesSingle",value:45},{label:"textRotate.vertical",icon:"VerticalTextSingle",value:"v"},{label:"textRotate.rotationUp",icon:"LeftRotationNinetyDegreesSingle",value:-90},{label:"textRotate.rotationDown",icon:"RightRotationNinetyDegreesSingle",value:90}];function ga(i){const e=i.get(a.IUniverInstanceService),t=i.get(f.SelectionManagerService);return{id:f.SetTextRotationCommand.id,tooltip:"toolbar.textRotateMode.main",icon:to[0].icon,group:R.MenuGroup.TOOLBAR_LAYOUT,type:R.MenuItemType.SELECTOR,selections:to,positions:[R.MenuPosition.TOOLBAR_START],value$:new k.Observable(n=>{const o=i.get(a.ICommandService).onCommandExecuted(r=>{var u;const s=r.id;if(s!==f.SetTextRotationCommand.id&&s!==f.SetSelectionsOperation.id)return;const l=(u=t.getLast())==null?void 0:u.primary,c=e.getCurrentUniverSheetInstance().getActiveSheet();let d;if(l!=null){const h=c.getRange(l.startRow,l.startColumn);d=h==null?void 0:h.getTextRotation()}(d==null?void 0:d.v)===a.BooleanNumber.TRUE?n.next("v"):n.next((d&&d.a)??0)});return n.next(0),o.dispose}),hidden$:R.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}function fa(){return{id:R.CopyCommand.id,group:R.MenuGroup.CONTEXT_MENU_FORMAT,type:R.MenuItemType.BUTTON,title:"rightClick.copy",icon:"Copy",positions:[R.MenuPosition.CONTEXT_MENU,"colHeaderContextMenu","rowHeaderContextMenu"]}}function pa(){return{id:R.PasteCommand.id,group:R.MenuGroup.CONTEXT_MENU_FORMAT,type:R.MenuItemType.BUTTON,title:"rightClick.paste",icon:"PasteSpecial",positions:[R.MenuPosition.CONTEXT_MENU,"colHeaderContextMenu","rowHeaderContextMenu"]}}const ht="sheet.menu.paste-special";function va(){return{id:ht,group:R.MenuGroup.CONTEXT_MENU_FORMAT,type:R.MenuItemType.SUBITEMS,icon:"PasteSpecial",title:"rightClick.pasteSpecial",positions:[R.MenuPosition.CONTEXT_MENU,"colHeaderContextMenu","rowHeaderContextMenu"]}}function Ca(){return{id:To.id,type:R.MenuItemType.BUTTON,title:"rightClick.pasteValue",positions:[ht]}}function Ia(){return{id:Eo.id,type:R.MenuItemType.BUTTON,title:"rightClick.pasteFormat",positions:[ht]}}function Ra(){return{id:yo.id,type:R.MenuItemType.BUTTON,title:"rightClick.pasteColWidth",positions:[ht]}}function ba(){return{id:Oo.id,type:R.MenuItemType.BUTTON,title:"rightClick.pasteBesidesBorder",positions:[ht]}}function Ma(){return{id:f.SetWorksheetRowIsAutoHeightCommand.id,group:R.MenuGroup.CONTEXT_MENU_LAYOUT,type:R.MenuItemType.BUTTON,positions:["rowHeaderContextMenu"],icon:"AutoHeight",title:"rightClick.fitContent"}}const Nt="sheet.menu.sheet-frozen";function wa(){return{id:Nt,group:R.MenuGroup.CONTEXT_MENU_LAYOUT,type:R.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",positions:[R.MenuPosition.CONTEXT_MENU]}}const Ii="sheet.header-menu.sheet-frozen";function Ta(){return{id:Ii,group:R.MenuGroup.CONTEXT_MENU_LAYOUT,type:R.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",positions:["rowHeaderContextMenu","colHeaderContextMenu"]}}function Ea(){return{id:An.id,type:R.MenuItemType.BUTTON,positions:[Nt,Ii],title:"rightClick.freeze",icon:"FreezeToSelectedSingle"}}function ya(){return{id:nr.id,type:R.MenuItemType.BUTTON,positions:[Nt],title:"rightClick.freezeRow",icon:"FreezeRowSingle"}}function Oa(){return{id:ir.id,type:R.MenuItemType.BUTTON,positions:[Nt],title:"rightClick.freezeCol",icon:"FreezeColumnSingle"}}function xa(){return{id:or.id,type:R.MenuItemType.BUTTON,positions:[Nt,Ii],title:"rightClick.cancelFreeze",icon:"CancelFreezeSingle"}}function Aa(){return{id:f.SetRowHiddenCommand.id,group:R.MenuGroup.CONTEXT_MENU_LAYOUT,type:R.MenuItemType.BUTTON,positions:["rowHeaderContextMenu"],icon:"Hide",title:"rightClick.hideSelectedRow"}}function Ha(){return{id:f.SetColHiddenCommand.id,group:R.MenuGroup.CONTEXT_MENU_LAYOUT,type:R.MenuItemType.BUTTON,positions:["colHeaderContextMenu"],icon:"Hide",title:"rightClick.hideSelectedColumn"}}function Da(i){const e=i.get(a.IUniverInstanceService),t=i.get(f.SelectionManagerService);function n(){var l;const r=e.getCurrentUniverSheetInstance().getActiveSheet(),s=(l=t.getSelections())==null?void 0:l.map(c=>c.range).filter(c=>c.rangeType===a.RANGE_TYPE.ROW);return!!(s!=null&&s.some(c=>{for(let d=c.startRow;d<=c.endRow;d++)if(!r.getRowVisible(d))return!0;return!1}))}const o=i.get(a.ICommandService);return{id:f.SetSelectedRowsVisibleCommand.id,group:R.MenuGroup.CONTEXT_MENU_LAYOUT,type:R.MenuItemType.BUTTON,positions:["rowHeaderContextMenu"],title:"rightClick.showHideRow",hidden$:new k.Observable(r=>{const s=o.onCommandExecuted(l=>{(l.id===f.SetSelectionsOperation.id||l.id===f.SetRowHiddenMutation.id||l.id===f.SetRowVisibleMutation.id)&&r.next(!n())});return r.next(!n()),()=>s.dispose()})}}function Na(i){const e=i.get(a.IUniverInstanceService),t=i.get(f.SelectionManagerService);function n(){var l;const r=e.getCurrentUniverSheetInstance().getActiveSheet(),s=(l=t.getSelections())==null?void 0:l.map(c=>c.range).filter(c=>c.rangeType===a.RANGE_TYPE.COLUMN);return!!(s!=null&&s.some(c=>{for(let d=c.startRow;d<=c.endRow;d++)if(!r.getColVisible(d))return!0;return!1}))}const o=i.get(a.ICommandService);return{id:f.SetSelectedColsVisibleCommand.id,group:R.MenuGroup.CONTEXT_MENU_LAYOUT,type:R.MenuItemType.BUTTON,positions:["colHeaderContextMenu"],title:"rightClick.showHideColumn",hidden$:new k.Observable(r=>{const s=o.onCommandExecuted(l=>{(l.id===f.SetSelectionsOperation.id||l.id===f.SetColHiddenMutation.id||l.id===f.SetColVisibleMutation.id)&&r.next(!n())});return r.next(!n()),()=>s.dispose()})}}function Pa(i){const e=i.get(a.ICommandService),t=i.get(a.IUniverInstanceService),n=i.get(f.SelectionManagerService);return{id:f.SetRowHeightCommand.id,group:R.MenuGroup.CONTEXT_MENU_LAYOUT,type:R.MenuItemType.BUTTON,icon:"AdjustHeight",positions:["rowHeaderContextMenu"],label:{name:Ci,props:{prefix:"rightClick.rowHeight",suffix:"px"}},value$:new k.Observable(o=>{function r(){var u;const l=(u=n.getLast())==null?void 0:u.primary,c=t.getCurrentUniverSheetInstance().getActiveSheet();let d;l!=null&&(d=c.getRowHeight(l.startRow)),o.next(d??0)}const s=e.onCommandExecuted(l=>{const c=l.id;if(c===f.SetRangeValuesMutation.id||c===f.SetSelectionsOperation.id)return r()});return r(),s.dispose})}}function La(i){const e=i.get(a.ICommandService),t=i.get(a.IUniverInstanceService),n=i.get(f.SelectionManagerService);return{id:f.SetColWidthCommand.id,group:R.MenuGroup.CONTEXT_MENU_LAYOUT,type:R.MenuItemType.BUTTON,icon:"AdjustWidth",positions:["colHeaderContextMenu"],label:{name:Ci,props:{prefix:"rightClick.columnWidth",suffix:"px"}},value$:new k.Observable(o=>{function r(){var u;const l=(u=n.getLast())==null?void 0:u.primary,c=t.getCurrentUniverSheetInstance().getActiveSheet();let d=0;l!=null&&(d=c.getColumnWidth(l.startColumn)),o.next(d)}const s=e.onCommandExecuted(l=>{const c=l.id;if(c===f.SetRangeValuesMutation.id||c===f.SetSelectionsOperation.id)return r()});return r(),s.dispose})}}function ae(i,e){const n=i.getCurrentUniverSheetInstance().getUnitId(),o=e.getRenderById(n);if(o==null)return;const{components:r,mainComponent:s,scene:l,engine:c}=o,d=s,u=r.get(oe.ROW),h=r.get(oe.COLUMN),m=r.get(oe.LEFT_TOP);return{spreadsheet:d,spreadsheetRowHeader:u,spreadsheetColumnHeader:h,spreadsheetLeftTopPlaceholder:m,scene:l,engine:c}}function ii(i,e,t,n){const{scaleX:o,scaleY:r}=t.getAncestorScale(),{startX:s,startY:l,endX:c,endY:d}=n.getCellByIndex(i,e,o,r);return{startX:s,startY:l,endX:c,endY:d}}function st(i,e,t,n,o){const r=t.getRelativeCoord(w.Vector2.FromArray([i,e])),{x:s,y:l}=r,c=t.getScrollXYByRelativeCoords(r,o),{scaleX:d,scaleY:u}=t.getAncestorScale(),h=n.getCellPositionByOffset(s,l,d,u,c),{row:m,column:S}=h,g=n.getNoMergeCellPositionByIndex(m,S,d,u),{startX:_,startY:I,endX:C,endY:b}=g;return{startX:_,startY:I,endX:C,endY:b,row:m,column:S}}function Xt(i,e,t,n){const o=t.getRelativeCoord(w.Vector2.FromArray([i,e])),r=t.getViewport(Y.VIEW_MAIN),s=t.getScrollXYByRelativeCoords(o,r),{scaleX:l,scaleY:c}=t.getAncestorScale(),{x:d,y:u}=s,h=i/l+d,m=e/c+u;return{x:h,y:m}}const Ua={spreadsheetLabel:"Spreadsheet",spreadsheetRightLabel:"more Sheets",toolbar:{undo:"Undo",redo:"Redo",formatPainter:"Paint format",currencyFormat:"Format as currency",percentageFormat:"Format as percent",numberDecrease:"Decrease decimal places",numberIncrease:"Increase decimal places",moreFormats:"More formats",font:"Font",fontSize:"Font size",bold:"Bold",italic:"Italic",strikethrough:"Strikethrough",subscript:"Subscript",superscript:"Superscript",underline:"Underline",textColor:{main:"Text color",right:"Choose color"},resetColor:"Reset",customColor:"CUSTOM",alternatingColors:"Alternating colors",confirmColor:"OK",cancelColor:"Cancel",collapse:"Collapse",fillColor:{main:"Fill color",right:"Choose color"},border:{main:"Border",right:"Border style"},mergeCell:{main:"Merge cells",right:"Choose merge type"},horizontalAlignMode:{main:"Horizontal align",right:"Alignment"},verticalAlignMode:{main:"Vertical align",right:"Alignment"},textWrapMode:{main:"Text wrap",right:"Text wrap mode"},textRotateMode:{main:"Text rotate",right:"Text rotate mode"},freezeTopRow:"Freeze top row",sortAndFilter:"Sort and filter",findAndReplace:"Find and replace",sum:"SUM",autoSum:"Auto SUM",moreFunction:"More functions",conditionalFormat:"Conditional format",comment:"Comment",pivotTable:"Pivot Table",chart:"Chart",screenshot:"Screenshot",splitColumn:"Split text",insertImage:"Insert image",insertLink:"Insert link",dataValidation:"Data validation",protection:"Protect the sheet",clearText:"Clear color",noColorSelectedText:"No color is selected",toolMore:"More",toolLess:"Less",toolClose:"Close",toolMoreTip:"More features",moreOptions:"More options",cellFormat:"Cell format config",print:"Print",borderMethod:{top:"Upper frame line",bottom:"Lower frame line",left:"Left frame line",right:"Right frame line"},more:"More"},defaultFmt:{Automatic:{text:"Automatic",value:"General",example:""},Number:{text:"Number",value:"##0.00",example:"1000.12"},Percent:{text:"Percent",value:"#0.00%",example:"12.21%"},PlainText:{text:"Plain text",value:"@",example:""},Scientific:{text:"Scientific",value:"0.00E+00",example:"1.01E+5"},Accounting:{text:"Accounting",value:"¥(0.00)",example:"¥(1200.09)"},Thousand:{text:"Ten Thousand",value:"w",example:"1亿2000万2500"},Currency:{text:"Currency",value:"¥0.00",example:"¥1200.09"},Digit:{text:"万元2位小数",value:"w0.00",example:"2万2500.55"},Date:{text:"Date",value:"yyyy-MM-dd",example:"2017-11-29"},Time:{text:"Time",value:"hh:mm AM/PM",example:"3:00 PM"},Time24H:{text:"Time 24H",value:"hh:mm",example:"15:00"},DateTime:{text:"Date time",value:"yyyy-MM-dd hh:mm AM/PM",example:"2017-11-29 3:00 PM"},DateTime24H:{text:"Date time 24H",value:"yyyy-MM-dd hh:mm",example:"2017-11-29 15:00"},CustomFormats:{text:"Custom Formats",value:"fmtOtherSelf",example:""}},format:{moreCurrency:"More currency formats",moreDateTime:"More date and time formats",moreNumber:"More number formats",titleCurrency:"Currency formats",decimalPlaces:"Decimal places",titleDateTime:"Date and time formats",titleNumber:"Number formats"},fontFamily:{TimesNewRoman:"Times New Roman",Arial:"Arial",Tahoma:"Tahoma",Verdana:"Verdana",MicrosoftYaHei:"Microsoft YaHei",SimSun:"SimSun",SimHei:"SimHei",Kaiti:"Kaiti",FangSong:"FangSong",NSimSun:"NSimSun",STXinwei:"STXinwei",STXingkai:"STXingkai",STLiti:"STLiti",HanaleiFill:"HanaleiFill",Anton:"Anton",Pacifico:"Pacifico"},print:{normalBtn:"Normal",layoutBtn:"Page Layout",pageBtn:"Page break preview",menuItemPrint:"Print (Ctrl+P)",menuItemAreas:"Print areas",menuItemRows:"Print title rows",menuItemColumns:"Print title columns"},align:{left:"left",center:"center",right:"right",top:"top",middle:"middle",bottom:"bottom"},dateFmtList:[{name:"1930-08-05",value:"yyyy-MM-dd"},{name:"1930/8/5",value:"yyyy/MM/dd"},{name:"08-05",value:"MM-dd"},{name:"8-5",value:"M-d"},{name:"13:30:30",value:"h:mm:ss"},{name:"13:30",value:"h:mm"},{name:"PM 01:30",value:"AM/PM hh:mm"},{name:"PM 1:30",value:"AM/PM h:mm"},{name:"PM 1:30:30",value:"AM/PM h:mm:ss"},{name:"08-05 PM 01:30",value:"MM-dd AM/PM hh:mm"}],numFmtList:[{name:"1235",value:"0"},{name:"1234.56",value:"0.00"},{name:"1,235",value:"#,##0"},{name:"1,234.56",value:"#,##0.00"},{name:"1,235",value:"#,##0_);(#,##0)"},{name:"1,235",value:"#,##0_);[Red](#,##0)"},{name:"1,234.56",value:"#,##0.00_);(#,##0.00)"},{name:"1,234.56",value:"#,##0.00_);[Red](#,##0.00)"},{name:"$1,235",value:"$#,##0_);($#,##0)"},{name:"$1,235",value:"$#,##0_);[Red]($#,##0)"},{name:"$1,234.56",value:"$#,##0.00_);($#,##0.00)"},{name:"$1,234.56",value:"$#,##0.00_);[Red]($#,##0.00)"},{name:"1234.56",value:"@"},{name:"123456%",value:"0%"},{name:"123456.00%",value:"0.00%"},{name:"1.23E+03",value:"0.00E+00"},{name:"1.2E+3",value:"##0.0E+0"},{name:"1234 5/9",value:"# ?/?"},{name:"1234 14/25",value:"# ??/??"},{name:"$ 1,235",value:'_($* #,##0_);_(...($* "-"_);_(@_)'},{name:"1,235",value:'_(* #,##0_);_(*..._(* "-"_);_(@_)'},{name:"$ 1,234.56",value:'_($* #,##0.00_);_(...($* "-"_);_(@_)'},{name:"1,234.56",value:'_(* #,##0.00_);...* "-"??_);_(@_)'}],button:{confirm:"OK",cancel:"Cancel",close:"Close",update:"Update",delete:"Delete",insert:"Insert",prevPage:"Previous",nextPage:"Next",total:"total:"},punctuation:{tab:"Tab",semicolon:"semicolond",comma:"comma",space:"space"},colorPicker:{collapse:"Collapse",customColor:"CUSTOM",change:"Change",confirmColor:"OK",cancelColor:"Cancel"},borderLine:{borderTop:"borderTop",borderBottom:"borderBottom",borderLeft:"borderLeft",borderRight:"borderRight",borderNone:"borderNone",borderAll:"borderAll",borderOutside:"borderOutside",borderInside:"borderInside",borderHorizontal:"borderHorizontal",borderVertical:"borderVertical",borderColor:"borderColor",borderSize:"borderSize",borderType:"borderType"},merge:{all:"Merge all",vertical:"Vertical merge",horizontal:"Horizontal merge",cancel:"Cancel merge",overlappingError:"Cannot merge overlapping areas",partiallyError:"Cannot perform this operation on partially merged cells",confirm:{title:"Continue merging would only keep the upper-left cell value, discard other values. Are you sure to continue?",cancel:"Cancel merging",confirm:"Continue merging"}},textWrap:{overflow:"Overflow",wrap:"Wrap",clip:"Clip"},textRotate:{none:"None",angleUp:"Tilt Up",angleDown:"Tilt Down",vertical:"Stack Vertically",rotationUp:"Rotate Up",rotationDown:"Rotate Down"},sheetConfig:{delete:"Delete",copy:"Copy",rename:"Rename",changeColor:"Change color",hide:"Hide",unhide:"Unhide",moveLeft:"Move left",moveRight:"Move right",resetColor:"Reset color",cancelText:"Cancel",chooseText:"Confirm color",tipNameRepeat:"The name of the tab page cannot be repeated! Please revise",noMoreSheet:"The workbook contains at least one visual worksheet. To delete the selected worksheet, please insert a new worksheet or show a hidden worksheet.",confirmDelete:"Are you sure to delete",redoDelete:"Can be undo by Ctrl+Z",noHide:"Can't hide, at least keep one sheet tag",chartEditNoOpt:"This operation is not allowed in chart editing mode!",sheetNameErrorTitle:"There was a problem",sheetNameSpecCharError:`The name cannot contain:[ ] : ? * / ' "`,sheetNameCannotIsEmptyError:"The sheet name cannot be empty.",sheetNameAlreadyExistsError:"The sheet name already exists. Please enter another name.",deleteSheet:"Delete worksheet",deleteSheetContent:"Confirm to delete this worksheet. It will not be retrieved after deletion. Are you sure you want to delete it?"},rightClick:{copy:"Copy",copyAs:"Copy as",cut:"Cut",paste:"Paste",pasteSpecial:"Paste Special",pasteValue:"Paste Value",pasteFormat:"Paste Format",pasteColWidth:"Paste Column Width",pasteBesidesBorder:"Paste Besides Border Styles",insert:"Insert",insertRow:"Insert Row",insertRowBefore:"Insert Row Before",insertColumn:"Insert Column",insertColumnBefore:"Insert Column Before",delete:"Delete",deleteCell:"Delete Cell",insertCell:"Insert Cell",deleteSelected:"Delete Selected ",hide:"Hide",hideSelected:"Hide Selected ",showHide:"Show Hidden",toTopAdd:"Towards Top Add",toBottomAdd:"Towards Bottom Add",toLeftAdd:"Towards Left Add",toRightAdd:"Towards Right Add",deleteSelectedRow:"Delete Selected row",deleteSelectedColumn:"Delete Selected column",hideSelectedRow:"Hide Selected Row",showHideRow:"Show Selected Row",rowHeight:"Row Height",hideSelectedColumn:"Hide Selected Column",showHideColumn:"Show Hide Column",columnWidth:"Column Width",to:"Towards",left:"Left",right:"Right",top:"Top",bottom:"Bottom",moveLeft:"Move Left",moveUp:"Move up",moveRight:"Move Right",moveDown:"Move Down",add:"Add",row:"Row",column:"Column",width:"Width",height:"Height",number:"Number",confirm:"Confirm",orderAZ:"A-Z order",orderZA:"Z-A order",clearSelection:"Clear",clearContent:"Clear Contents",clearFormat:"Clear Formats",clearAll:"Clear All",matrix:"Matrix operation",sortSelection:"Sort",filterSelection:"Filter",chartGeneration:"Create Chart",firstLineTitle:"First Line Title",untitled:"Untitled",array1:"One-dimensional array",array2:"Two-dimensional array",array3:"Multidimensional Arrays",diagonal:"Diagonal",antiDiagonal:"Anti-diagonal",diagonalOffset:"Diagonal offset",offset:"Offset",boolean:"Boolean",flip:"Flip",upAndDown:"Up and down",leftAndRight:"Left and right",clockwise:"Clockwise",counterclockwise:"Counterclockwise",transpose:"Transpose",matrixCalculation:"Matrix Calculation",plus:"Plus",minus:"Minus",multiply:"Multiply",divided:"Divided",power:"Power",root:"Root",log:"Log",delete0:"Delete 0 values at both ends",removeDuplicate:"Remove duplicate values",byRow:"By row",byCol:"By column",generateNewMatrix:"Generate new matrix",fitContent:"Fit for data",freeze:"Freeze",freezeCol:"Freeze to this column",freezeRow:"Freeze to this row",cancelFreeze:"Cancel freeze",zenEditor:"Full Screen Editor"},info:{tooltip:"Tooltip",notChangeMerge:"You cannot make partial changes to the merged cells",detailUpdate:"New opened",detailSave:"Local cache restored",row:"",column:"",loading:"Loading...",copy:"Copy",return:"Exit",rename:"Rename",tips:"Rename",noName:"Untitled spreadsheet",wait:"waiting for update",add:"Add",addLast:"more rows at bottom",backTop:"Back to the top",pageInfo:"Total ${total},${totalPage} page,current ${currentPage}",nextPage:"Next",tipInputNumber:"Please enter the number",tipInputNumberLimit:"The increase range is limited to 1-100",tipRowHeightLimit:"Row height must be between 0 ~ 545",tipColumnWidthLimit:"The column width must be between 0 ~ 2038",pageInfoFull:"Total ${total},${totalPage} page,All data displayed"},clipboard:{paste:{exceedMaxCells:"The number of cells pasted exceeds the maximum number of cells"}},statusbar:{sum:"Sum",average:"Average",min:"Min",max:"Max",count:"Numerical Count",countA:"Count",clickToCopy:"Click to Copy",copied:"Copied"},autoFill:{copy:"Copy Cell",series:"Fill Series",formatOnly:"Format Only",noFormat:"No Format"},rangeSelector:{placeholder:"Select range or input value",tooltip:"Select range"},shortcut:{sheet:{"zoom-in":"Zoom in","zoom-out":"Zoom out","reset-zoom":"Reset zoom level","select-below-cell":"Select the cell below","select-up-cell":"Select the cell above","select-left-cell":"Select the left cell","select-right-cell":"Select the right cell","select-next-cell":"Select the next cell","select-previous-cell":"Select the previous cell","select-up-value-cell":"Select the cell above that has value","select-below-value-cell":"Select the cell below that has value","select-left-value-cell":"Select the cell left that has value","select-right-value-cell":"Select the cell right that has value","expand-selection-down":"Expand selection down","expand-selection-up":"Expand selection up","expand-selection-left":"Expand selection left","expand-selection-right":"Expand selection right","expand-selection-to-left-gap":"Expand selection to the left gap","expand-selection-to-below-gap":"Expand selection to the below gap","expand-selection-to-right-gap":"Expand selection to the right gap","expand-selection-to-up-gap":"Expand selection to the up gap","select-all":"Select all","toggle-editing":"Toggle editing","delete-and-start-editing":"Clear and start editing","abort-editing":"Abort editing","break-line":"Break line","set-bold":"Toggle bold","set-italic":"Toggle italic","set-underline":"Toggle underline","set-strike-through":"Toggle strike through"}},"sheet-view":"Sheet View","sheet-edit":"Sheet Edit"},ar={spreadsheetLabel:"插件",spreadsheetRightLabel:"更多 Sheets",toolbar:{undo:"撤销",redo:"重做",formatPainter:"格式刷",currencyFormat:"货币格式",percentageFormat:"百分比格式",numberDecrease:"减少小数位数",numberIncrease:"增加小数位数",moreFormats:"更多格式",font:"字体",fontSize:"字号",bold:"粗体",italic:"斜体",strikethrough:"删除线",subscript:"下标",superscript:"上标",underline:"下划线",textColor:{main:"文本颜色",right:"颜色选择"},resetColor:"重置颜色",customColor:"自定义",alternatingColors:"交替颜色",confirmColor:"确定颜色",cancelColor:"取消",collapse:"收起",fillColor:{main:"单元格颜色",right:"颜色选择"},border:{main:"边框",right:"边框类型"},mergeCell:{main:"合并单元格",right:"选择合并类型"},horizontalAlignMode:{main:"水平对齐",right:"对齐方式"},verticalAlignMode:{main:"垂直对齐",right:"对齐方式"},textWrapMode:{main:"文本换行",right:"换行方式"},textRotateMode:{main:"文本旋转",right:"旋转方式"},freezeTopRow:"冻结首行",sortAndFilter:"排序和筛选",findAndReplace:"查找替换",sum:"求和",autoSum:"自动求和",moreFunction:"更多函数",conditionalalFormat:"条件格式",comment:"批注",pivotTable:"数据透视表",chart:"图表",screenshot:"截图",splitColumn:"分列",insertImage:"插入图片",insertLink:"插入链接",dataValidation:"数据验证",protection:"保护工作表内容",clearText:"清除颜色选择",noColorSelectedText:"没有颜色被选择",toolMore:"更多",toolLess:"少于",toolClose:"收起",toolMoreTip:"更多功能",moreOptions:"更多选项",cellFormat:"设置单元格格式",print:"打印",borderMethod:{top:"上框线",bottom:"下框线",left:"左框线",right:"右框线"},more:"更多"},defaultFmt:{Automatic:{text:"自动",value:"General",example:""},Number:{text:"数字",value:"##0.00",example:"1000.12"},Percent:{text:"百分比",value:"#0.00%",example:"12.21%"},PlainText:{text:"纯文本",value:"@",example:""},Scientific:{text:"科学计数",value:"0.00E+00",example:"1.01E+5"},Accounting:{text:"会计",value:"¥(0.00)",example:"¥(1200.09)"},Thousand:{text:"万元",value:"w",example:"1亿2000万2500"},Currency:{text:"货币",value:"¥0.00",example:"¥1200.09"},Digit:{text:"万元2位小数",value:"w0.00",example:"2万2500.55"},Date:{text:"日期",value:"yyyy-MM-dd",example:"2017-11-29"},Time:{text:"时间",value:"hh:mm AM/PM",example:"3:00 PM"},Time24H:{text:"时间24H",value:"hh:mm",example:"15:00"},DateTime:{text:"日期时间",value:"yyyy-MM-dd hh:mm AM/PM",example:"2017-11-29 3:00 PM"},DateTime24H:{text:"日期时间24H",value:"yyyy-MM-dd hh:mm",example:"2017-11-29 15:00"},CustomFormats:{text:"自定义格式",value:"fmtOtherSelf",example:""}},format:{moreCurrency:"更多货币格式",moreDateTime:"更多日期与时间格式",moreNumber:"更多数字格式",titleCurrency:"货币格式",decimalPlaces:"小数位数",titleDateTime:"日期与时间格式",titleNumber:"数字格式"},fontFamily:{TimesNewRoman:"Times New Roman",Arial:"Arial",Tahoma:"Tahoma",Verdana:"Verdana",MicrosoftYaHei:"微软雅黑",SimSun:"宋体",SimHei:"黑体",Kaiti:"楷体",FangSong:"仿宋",NSimSun:"新宋体",STXinwei:"华文新魏",STXingkai:"华文行楷",STLiti:"华文隶书",HanaleiFill:"HanaleiFill",Anton:"Anton",Pacifico:"Pacifico"},print:{normalBtn:"常规视图",layoutBtn:"页面布局",pageBtn:"分页预览",menuItemPrint:"打印(Ctrl+P)",menuItemAreas:"打印区域",menuItemRows:"打印标题行",menuItemColumns:"打印标题列"},align:{left:"左对齐",center:"中间对齐",right:"右对齐",top:"顶部对齐",middle:"居中对齐",bottom:"底部对齐"},button:{confirm:"确定",cancel:"取消",close:"关闭",update:"Update",delete:"Delete",insert:"新建",prevPage:"上一页",nextPage:"下一页",total:"总共:"},punctuation:{tab:"Tab 键",semicolon:"分号",comma:"逗号",space:"空格"},colorPicker:{collapse:"收起",customColor:"自定义",change:"切换",confirmColor:"确定",cancelColor:"取消"},borderLine:{borderTop:"上框线",borderBottom:"下框线",borderLeft:"左框线",borderRight:"右框线",borderNone:"无",borderAll:"所有",borderOutside:"外侧",borderInside:"内侧",borderHorizontal:"内侧横线",borderVertical:"内侧竖线",borderColor:"边框颜色",borderSize:"边框粗细",borderType:"边框线类型"},merge:{all:"全部合并",vertical:"垂直合并",horizontal:"水平合并",cancel:"取消合并",overlappingError:"不能合并重叠区域",partiallyError:"无法对部分合并单元格执行此操作",confirm:{title:"合并单元格仅保存左上角单元格的值,是否继续?",cancel:"取消合并",confirm:"继续合并"}},textWrap:{overflow:"溢出",wrap:"自动换行",clip:"截断"},textRotate:{none:"无旋转",angleUp:"向上倾斜",angleDown:"向下倾斜",vertical:"竖排文字",rotationUp:"向上90°",rotationDown:"向下90°"},sheetConfig:{delete:"删除",copy:"复制",rename:"重命名",changeColor:"更改颜色",hide:"隐藏",unhide:"取消隐藏",moveLeft:"向左移",moveRight:"向右移",resetColor:"重置颜色",cancelText:"取消",chooseText:"确定颜色",tipNameRepeat:"标签页的名称不能重复!请重新修改",noMoreSheet:"工作薄内至少含有一张可视工作表。若需删除选定的工作表,请先插入一张新工作表或显示一张隐藏的工作表。",confirmDelete:"是否删除",redoDelete:"可以通过Ctrl+Z撤销删除",noHide:"不能隐藏, 至少保留一个sheet标签",chartEditNoOpt:"图表编辑模式下不允许该操作!",sheetNameErrorTitle:"错误",sheetNameSpecCharError:`名称不能超过31个字符,首尾不能是' 且名称不能包含:\r
15
- [ ] : \\ ? * /`,sheetNameCannotIsEmptyError:"名称不能为空。",sheetNameAlreadyExistsError:"工作表已存在,请输入其它名称。",deleteSheet:"删除工作表",deleteSheetContent:"确认删除此工作表,删除后将不可找回,确定要删除吗?"},rightClick:{copy:"复制",copyAs:"复制为",cut:"剪切",paste:"粘贴",pasteSpecial:"选择性粘贴",pasteValue:"仅粘贴值",pasteFormat:"仅粘贴格式",pasteColWidth:"仅粘贴列宽",pasteBesidesBorder:"仅粘贴边框以外内容",insert:"插入",delete:"删除",insertRow:"插入行",insertRowBefore:"在上方插入行",insertColumn:"插入列",insertColumnBefore:"在左侧插入列",deleteCell:"删除单元格",insertCell:"插入单元格",deleteSelected:"删除选中",hide:"隐藏",hideSelected:"隐藏选中",showHide:"显示隐藏",toTopAdd:"向上增加",toBottomAdd:"向下增加",toLeftAdd:"向左增加",toRightAdd:"向右增加",deleteSelectedRow:"删除选中行",deleteSelectedColumn:"删除选中列",hideSelectedRow:"隐藏选中行",showHideRow:"显示隐藏行",rowHeight:"行高",hideSelectedColumn:"隐藏选中列",showHideColumn:"显示隐藏列",columnWidth:"列宽",to:"向",left:"左",right:"右",top:"上",bottom:"下",moveLeft:"左移",moveUp:"上移",moveRight:"右移",moveDown:"下移",add:"增加",row:"行",column:"列",width:"宽",height:"高",number:"数字",confirm:"确认",orderAZ:"A-Z顺序排列",orderZA:"Z-A降序排列",clearSelection:"清除",clearContent:"清除内容",clearFormat:"清除格式",clearAll:"清除全部",matrix:"矩阵操作选区",sortSelection:"排序选区",filterSelection:"筛选选区",chartGeneration:"图表生成",firstLineTitle:"首行为标题",untitled:"无标题",array1:"一维数组",array2:"二维数组",array3:"多维数组",diagonal:"对角线",antiDiagonal:"反对角线",diagonalOffset:"对角偏移",offset:"偏移量",boolean:"布尔值",flip:"翻转",upAndDown:"上下",leftAndRight:"左右",clockwise:"顺时针",counterclockwise:"逆时针",transpose:"转置",matrixCalculation:"矩阵计算",plus:"加",minus:"减",multiply:"乘",divided:"除",power:"次方",root:"次方根",log:"log",delete0:"删除两端0值",removeDuplicate:"删除重复值",byRow:"按行",byCol:"按列",generateNewMatrix:"生成新矩阵",fitContent:"适合数据",freeze:"冻结",freezeCol:"冻结列",freezeRow:"冻结行",cancelFreeze:"取消冻结",zenEditor:"禅模式编辑"},info:{tooltip:"提示",notChangeMerge:"不能对合并单元格做部分更改",detailUpdate:"新打开",detailSave:"已恢复本地缓存",row:"行",column:"列",loading:"渲染中···",copy:"副本",return:"返回",rename:"重命名",tips:"重命名",noName:"无标题的电子表格",wait:"待更新",add:"添加",addLast:"在底部添加",backTop:"回到顶部",pageInfo:"共${total}条,${totalPage}页,当前已显示${currentPage}页",nextPage:"下一页",tipInputNumber:"请输入数字",tipInputNumberLimit:"增加范围限制在1-100",tipRowHeightLimit:"行高必须在0 ~ 545之间",tipColumnWidthLimit:"列宽必须在0 ~ 2038之间",pageInfoFull:"共${total}条,${totalPage}页,已显示全部数据"},clipboard:{paste:{exceedMaxCells:"粘贴区域超出最大单元格数"}},statusbar:{sum:"求和",average:"平均值",min:"最小值",max:"最大值",count:"数值计数",countA:"计数",clickToCopy:"点击复制数值",copied:"已复制"},autoFill:{copy:"复制单元格",series:"填充序列",formatOnly:"仅填充格式",noFormat:"不带格式填充"},rangeSelector:{placeholder:"选择范围或输入值",tooltip:"选择范围"},shortcut:{sheet:{"zoom-in":"放大","zoom-out":"缩小","reset-zoom":"恢复缩放","select-below-cell":"选择下方单元格","select-up-cell":"选择上方单元格","select-left-cell":"选择左侧单元格","select-right-cell":"选择右侧单元格","select-next-cell":"选择后一个单元格","select-previous-cell":"选择前一个单元格","select-up-value-cell":"选择上方有值的单元格","select-below-value-cell":"选择下方有值的单元格","select-left-value-cell":"选择左侧有值的单元格","select-right-value-cell":"选择右侧有值的单元格","expand-selection-down":"向下扩展选区","expand-selection-up":"向上扩展选区","expand-selection-left":"向左扩展选区","expand-selection-right":"向右扩展选区","expand-selection-to-left-gap":"向左扩展选区到下一个边界","expand-selection-to-below-gap":"向下扩展选区到下一个边界","expand-selection-to-right-gap":"向右扩展选区到下一个边界","expand-selection-to-up-gap":"向上扩展选区到下一个边界","select-all":"全选","toggle-editing":"开始 / 结束编辑","delete-and-start-editing":"清空并开始编辑","abort-editing":"放弃编辑","break-line":"换行","set-bold":"切换粗体","set-italic":"切换斜体","set-underline":"切换下划线","set-strike-through":"切换删除线"}},"sheet-view":"浏览表格","sheet-edit":"编辑表格"},ka=(i,e,t=!1)=>{const n=h=>h.endRow-h.startRow+1,o=h=>h.endColumn-h.startColumn+1,r=n(e)%n(i),s=o(e)%o(i),l={startRow:0,endRow:n(i)-1,startColumn:0,endColumn:o(i)-1},c=Math.floor(n(e)/n(i)),d=Math.floor(o(e)/o(i)),u=[];if(!r&&!s)for(let h=1;h<=c;h++)for(let m=1;m<=d;m++){const S=n(i)*(h-1),g=o(i)*(m-1),_={startRow:S+e.startRow,endRow:S+e.startRow,startColumn:g+e.startColumn,endColumn:g+e.startColumn};u.push({repeatRelativeRange:l,startRange:_})}else if(!r&&s&&!t)for(let h=1;h<=c;h++){const m=n(i)*(h-1),S=0,g={startRow:m+e.startRow,endRow:m+e.startRow,startColumn:S+e.startColumn,endColumn:S+e.startColumn};u.push({repeatRelativeRange:l,startRange:g})}else if(r&&!s&&!t)for(let h=1;h<=d;h++){const S=o(i)*(h-1),g={startRow:0+e.startRow,endRow:0+e.startRow,startColumn:S+e.startColumn,endColumn:S+e.startColumn};u.push({repeatRelativeRange:l,startRange:g})}else{const h={startRow:e.startRow,endRow:e.startRow,startColumn:e.startColumn,endColumn:e.startColumn};u.push({startRange:h,repeatRelativeRange:l})}return u};class cr{constructor(){v(this,"_state",null);v(this,"_rect",null);v(this,"_focus",!1);v(this,"_state$",new k.BehaviorSubject(null));v(this,"state$",this._state$.asObservable());v(this,"_rect$",new k.BehaviorSubject(null));v(this,"rect$",this._rect$.asObservable());v(this,"_focus$",new k.BehaviorSubject(this._focus));v(this,"focus$",this._focus$.asObservable())}dispose(){this._state$.complete(),this._state=null,this._rect$.complete(),this._rect=null}setState(e){this._state=e,this._refresh(e)}getRect(){return this._rect}setRect(e){this._rect=e,this._rect$.next(e)}getState(){return this._state}setFocus(e=!1){this._focus=e,this._focus$.next(e)}_refresh(e){this._state$.next(e)}}const Pt=P.createIdentifier("univer.sheet-cell-editor-manager.service");class Ba{constructor(){v(this,"_position",null);v(this,"_position$",new k.BehaviorSubject(null));v(this,"position$",this._position$.asObservable());v(this,"_focus",!1);v(this,"_focus$",new k.BehaviorSubject(this._focus));v(this,"focus$",this._focus$.asObservable());v(this,"_fxBtnClick$",new k.BehaviorSubject(!1));v(this,"fxBtnClick$",this._fxBtnClick$.asObservable())}dispose(){this._position$.complete(),this._focus$.complete(),this._position=null,this._focus=!1}setPosition(e){this._position=e,this._refresh(e)}getPosition(){return this._position}setFocus(e=!1){this._focus=e,this._focus$.next(e)}handleFxBtnClick(e){this._fxBtnClick$.next(e)}_refresh(e){this._position$.next(e)}}const Dn=P.createIdentifier("univer.sheet-formula-editor-manager.service");var Va=Object.defineProperty,Fa=Object.getOwnPropertyDescriptor,ja=(i,e,t,n)=>{for(var o=n>1?void 0:n?Fa(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Va(e,t,o),o},no=(i,e)=>(t,n)=>e(t,n,i);let Yt=class extends a.Disposable{constructor(e,t){super();v(this,"_previousSheetIndex",-1);this._commandService=e,this._univerInstanceService=t,this.disposeWithMe(this._commandService.beforeCommandExecuted((n,o)=>{if(n.id===f.RemoveSheetMutation.id)return this._beforeAdjustActiveSheetOnRemoveSheet(n)})),this.disposeWithMe(this._commandService.onCommandExecuted((n,o)=>{if(n.id===f.RemoveSheetMutation.id)return this._adjustActiveSheetOnRemoveSheet(n);if(n.id===f.SetWorksheetHideMutation.id&&n.params.hidden)return this._adjustActiveSheetOnHideSheet(n);if(!(o!=null&&o.fromCollab)){if(n.id===f.InsertSheetMutation.id)return this._adjustActiveSheetOnInsertSheet(n);if(n.id===f.SetWorksheetHideMutation.id&&!n.params.hidden)return this._adjustActiveSheetOnShowSheet(n)}}))}_adjustActiveSheetOnHideSheet(e){const{unitId:t,subUnitId:n}=e.params,o=this._univerInstanceService.getUniverSheetInstance(t);if(!o||(o==null?void 0:o.getRawActiveSheet())!==n)return;const s=o.getActiveSheetIndex(),l=Wa(o,s);this._switchToNextSheet(t,l)}_beforeAdjustActiveSheetOnRemoveSheet(e){const{unitId:t,subUnitId:n}=e.params,o=this._univerInstanceService.getUniverSheetInstance(t);if(!o)return;const r=o.getSheetBySheetId(n);r&&(this._previousSheetIndex=o.getSheetIndex(r))}_adjustActiveSheetOnRemoveSheet(e){if(this._previousSheetIndex===-1)return;const{unitId:t}=e.params,n=this._univerInstanceService.getUniverSheetInstance(t);if(!n||n.getRawActiveSheet())return;const r=this._previousSheetIndex,s=r>=1?r-1:0,l=n.getSheetByIndex(s);if(!l)throw new Error("[ActiveWorksheetController]: cannot find the next sheet!");this._switchToNextSheet(t,l.getSheetId())}_adjustActiveSheetOnInsertSheet(e){const{unitId:t,sheet:n}=e.params;this._switchToNextSheet(t,n.id)}_adjustActiveSheetOnShowSheet(e){const{unitId:t,subUnitId:n}=e.params;this._switchToNextSheet(t,n)}_switchToNextSheet(e,t){this._commandService.executeCommand(f.SetWorksheetActiveOperation.id,{unitId:e,subUnitId:t})}};Yt=ja([a.OnLifecycle(a.LifecycleStages.Ready,Yt),no(0,a.ICommandService),no(1,a.IUniverInstanceService)],Yt);function Wa(i,e){const t=i.getSheetSize();for(let n=e;n>-1;n--){const o=i.getSheetByIndex(n);if(!o.getConfig().hidden)return o.getSheetId()}for(let n=e;n<t;n++){const o=i.getSheetByIndex(n);if(!o.getConfig().hidden)return o.getSheetId()}throw new Error("[ActiveWorksheetController]: could not find the next unhidden sheet! Collaboration error perhaps.")}var $a=Object.defineProperty,za=Object.getOwnPropertyDescriptor,Xa=(i,e,t,n)=>{for(var o=n>1?void 0:n?za(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&$a(e,t,o),o},_t=(i,e)=>(t,n)=>e(t,n,i);let Zt=class{constructor(i,e,t,n,o){this._injector=i,this._sheetInterceptorService=e,this._selectionManagerService=t,this._univerInstanceService=n,this._sheetSkeletonManagerService=o,this._initialize()}_getUndoRedoParamsOfAutoHeight(i){const{_univerInstanceService:e,_sheetSkeletonManagerService:t,_injector:n}=this,{skeleton:o}=t.getCurrent(),r=o.calculateAutoHeightInRange(i),s=e.getCurrentUniverSheetInstance(),l=s.getUnitId(),d={subUnitId:s.getActiveSheet().getSheetId(),unitId:l,rowsAutoHeightInfo:r},u=f.SetWorksheetRowAutoHeightMutationFactory(n,d);return{undos:[{id:f.SetWorksheetRowAutoHeightMutation.id,params:u}],redos:[{id:f.SetWorksheetRowAutoHeightMutation.id,params:d}]}}_initialize(){const{_sheetInterceptorService:i,_selectionManagerService:e}=this;i.interceptCommand({getMutations:t=>t.id!==f.SetRangeValuesCommand.id?{redos:[],undos:[]}:this._getUndoRedoParamsOfAutoHeight(t.params.range)}),i.interceptCommand({getMutations:t=>t.id!==f.SetWorksheetRowIsAutoHeightCommand.id?{redos:[],undos:[]}:this._getUndoRedoParamsOfAutoHeight(t.params.ranges)}),i.interceptCommand({getMutations:t=>{var r;if(t.id!==f.SetStyleCommand.id)return{redos:[],undos:[]};if(!["ff","fs","tr","tb"].includes((r=t.params)==null?void 0:r.style.type))return{redos:[],undos:[]};const o=e.getSelectionRanges();return o!=null&&o.length?this._getUndoRedoParamsOfAutoHeight(o):{redos:[],undos:[]}}})}};Zt=Xa([a.OnLifecycle(a.LifecycleStages.Ready,Zt),_t(0,P.Inject(P.Injector)),_t(1,P.Inject(f.SheetInterceptorService)),_t(2,P.Inject(f.SelectionManagerService)),_t(3,P.Inject(a.IUniverInstanceService)),_t(4,P.Inject(exports.SheetSkeletonManagerService))],Zt);function Ya(i,e,t,n,o,r){const s=[],l=[];if(o.copyType===Xe.CUT){const{undos:c,redos:d}=Za(i,t,n,o,r);s.push(...d),l.push(...c)}else{const{undos:c,redos:d}=hr(t,n,i,e,r);s.push(...d),l.push(...c);const{undos:u,redos:h}=dr(t,n,i,e,r);s.push(...h),l.push(...u);const{undos:m,redos:S}=ur(t,n,i,e,r);s.push(...S),l.push(...m);const{undos:g,redos:_}=oi(t,n,i,e,r);s.push(..._),l.push(...g)}return{undos:l,redos:s}}function Za(i,e,t,n,o){let r=[],s=[];const{copyRange:l}=n;if(l){const c=o.get(a.IUniverInstanceService),d=o.get(f.SheetInterceptorService),u=c.getUniverSheetInstance(e),h=u==null?void 0:u.getSheetBySheetId(t);if(h){const m=h.getRange(l).getValues(),S=m.reduce((T,E,y)=>(E.forEach((O,x)=>{T.setValue(l.startRow+y,l.startColumn+x,null)}),T),new a.ObjectMatrix),g=m.reduce((T,E,y)=>(E.forEach((O,x)=>{T.setValue(l.startRow+y,l.startColumn+x,O)}),T),new a.ObjectMatrix),_=m.reduce((T,E,y)=>(E.forEach((O,x)=>{T.setValue(i.startRow+y,i.startColumn+x,O)}),T),new a.ObjectMatrix),I=h.getRange(i).getValues().reduce((T,E,y)=>(E.forEach((O,x)=>{T.setValue(i.startRow+y,i.startColumn+x,O)}),T),new a.ObjectMatrix),C={from:S.getMatrix(),to:_.getMatrix(),unitId:e,subUnitId:t},b={from:g.getMatrix(),to:I.getMatrix(),unitId:e,subUnitId:t},M=d.onCommandExecute({id:f.MoveRangeCommand.id,params:{toRange:i,fromRange:l}});r=[{id:f.MoveRangeMutation.id,params:C},...M.redos,{id:f.SetSelectionsOperation.id,params:{unitId:e,sheetId:t,pluginName:f.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:i}]}}],s=[{id:f.SetSelectionsOperation.id,params:{unitId:e,sheetId:t,pluginName:f.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:l}]}},...M.undos,{id:f.MoveRangeMutation.id,params:b}]}}return{undos:s,redos:r}}function dr(i,e,t,n,o){const r=[],s=[],{startColumn:l,startRow:c}=t,d=new a.ObjectMatrix;n.forValue((m,S,g)=>{d.setValue(m+c,S+l,{v:g.v})});const u={unitId:i,subUnitId:e,cellValue:d.getData()};r.push({id:f.SetRangeValuesMutation.id,params:u});const h=f.SetRangeValuesUndoMutationFactory(o,u);return s.push({id:f.SetRangeValuesMutation.id,params:h}),{undos:s,redos:r}}function ur(i,e,t,n,o){const r=[],s=[],{startColumn:l,startRow:c}=t,d=new a.ObjectMatrix;n.forValue((m,S,g)=>{var _;d.setValue(m+c,S+l,{s:g.s}),(_=g.p)!=null&&_.body&&d.setValue(m+c,S+l,{p:g.p})});const u={unitId:i,subUnitId:e,cellValue:d.getData()};r.push({id:f.SetRangeValuesMutation.id,params:u});const h=f.SetRangeValuesUndoMutationFactory(o,u);return s.push({id:f.SetRangeValuesMutation.id,params:h}),{undos:s,redos:r}}function hr(i,e,t,n,o){const r=[],s=[],l=new a.ObjectMatrix,{startColumn:c,startRow:d}=t;if(n.forValue((u,h,m)=>{m.s&&l.setValue(u+d,h+c,{s:null})}),l.getLength()>0){const u={subUnitId:e,unitId:i,cellValue:l.getData()};r.push({id:f.SetRangeValuesMutation.id,params:u});const h=f.SetRangeValuesUndoMutationFactory(o,u);s.push({id:f.SetRangeValuesMutation.id,params:h})}return{undos:s,redos:r}}function oi(i,e,t,n,o){const r=[],s=[],{startColumn:l,startRow:c,endColumn:d,endRow:u}=t;let h=!1;const m=[];if(n.forValue((_,I,C)=>{if(C.rowSpan){const b=C.colSpan||1,M={startRow:c+_,endRow:c+_+C.rowSpan-1,startColumn:l+I,endColumn:l+I+b-1};m.push(M),h=!0}else if(C.colSpan){const b=C.rowSpan||1,M={startRow:c+_,endRow:c+_+b-1,startColumn:l+I,endColumn:l+I+C.colSpan-1};m.push(M),h=!0}}),h){const I=o.get(a.IUniverInstanceService).getUniverSheetInstance(i),C=I==null?void 0:I.getSheetBySheetId(e);if(I&&C){const M=C.getMergeData().filter(y=>a.Rectangle.intersects({startRow:c,startColumn:l,endRow:u,endColumn:d},y)),T={unitId:i,subUnitId:e,ranges:M};r.push({id:f.RemoveWorksheetMergeMutation.id,params:T});const E=f.RemoveMergeUndoMutationFactory(o,T);s.push({id:f.AddWorksheetMergeMutation.id,params:E})}}const S={unitId:i,subUnitId:e,ranges:m};r.push({id:f.AddWorksheetMergeMutation.id,params:S});const g=f.AddMergeUndoMutationFactory(o,S);return s.push({id:f.RemoveWorksheetMergeMutation.id,params:g}),{undos:s,redos:r}}var Ga=Object.defineProperty,Ka=Object.getOwnPropertyDescriptor,qa=(i,e,t,n)=>{for(var o=n>1?void 0:n?Ka(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Ga(e,t,o),o},je=(i,e)=>(t,n)=>e(t,n,i);let Gt=class extends a.Disposable{constructor(i,e,t,n,o,r,s){super(),this._currentUniverSheet=i,this._commandService=e,this._configService=t,this._sheetClipboardService=n,this._messageService=o,this._injector=r,this._localService=s,this._init()}_init(){[wo,Is,at].forEach(e=>this.disposeWithMe(this._commandService.registerAsMultipleCommand(e))),[To,Eo,yo,Oo].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e))),this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._initCopyingHooks())),this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._initPastingHook()));const i=this._initSpecialPasteHooks().map(e=>this._sheetClipboardService.addClipboardHook(e));this.disposeWithMe({dispose:()=>i.forEach(e=>e.dispose())})}_initCopyingHooks(){const i=this;let e=null;return{hookName:le.DEFAULT_COPY,isDefaultHook:!0,onBeforeCopy(t,n){e=i._getWorksheet(t,n)},onCopyCellContent(t,n){const o=e.getCell(t,n);return`${o==null?void 0:o.v}`||""},onCopyCellStyle:(t,n,o,r)=>{const s={};(o||r)&&(s.rowspan=`${o||1}`,s.colspan=`${r||1}`);const c=e.getRange(t,n).getTextStyle();let d="";return c&&(d=a.handleStyleToString(c)),d&&(s.style=d),s},onCopyColumn(t){return{width:`${e.getColumnWidth(t)}`}},onCopyRow(t){return{style:`height: ${e.getRowHeight(t)}px;`}},onAfterCopy(){e=null}}}_initPastingHook(){const i=this;let e=null,t=null,n=null;return{hookName:le.DEFAULT_PASTE,isDefaultHook:!0,onBeforePaste(o,r,s){n=i._getWorksheet(o,r),e=o,t=r;const l=i._configService.getConfig(f.MAX_CELL_PER_SHEET_KEY),{endRow:c,endColumn:d}=s;return l&&c*d>l?(i._messageService.show({type:ie.MessageType.Error,content:i._localService.t("clipboard.paste.exceedMaxCells")}),!1):!0},onPasteRows(o,r){const s=[],l=n.getMaxRows(),c=o.endRow-l,d=r.length-c;if(c>0){const m={};r.slice(d).forEach((g,_)=>{const I=g==null?void 0:g.style;if(!I)return;const C=I.split(";");let b=a.DEFAULT_WORKSHEET_ROW_HEIGHT;C.find(M=>{M=M.toLowerCase();const T=R.textTrim(M.substr(0,M.indexOf(":"))),E=R.textTrim(M.substr(M.indexOf(":")+1));return T==="height"?(b=parseFloat(E),!0):!1}),m[_]={h:b,hd:a.BooleanNumber.FALSE}});const S={unitId:e,subUnitId:t,range:{...o,startRow:l},rowInfo:m};s.push({id:f.InsertRowMutation.id,params:S})}const u={};r.slice(0,d).forEach((m,S)=>{const g=m.style;if(!g)return;const _=g.split(";");let I=a.DEFAULT_WORKSHEET_ROW_HEIGHT;_.find(C=>{C=C.toLowerCase();const b=R.textTrim(C.substr(0,C.indexOf(":"))),M=R.textTrim(C.substr(C.indexOf(":")+1));return b==="height"?(I=parseFloat(M),!0):!1}),u[S]=I});const h={unitId:e,subUnitId:t,ranges:[{...o,endRow:Math.min(o.endRow,l)}],rowHeight:u};return s.push({id:f.SetWorksheetRowHeightMutation.id,params:h}),{redos:s,undos:[]}},onPasteColumns(o,r,s){const l=[],c=n.getMaxColumns(),d=o.endColumn-c,u=r.length-d;if(d>0){const m={unitId:e,subUnitId:t,range:{...o,startColumn:c},colInfo:r.slice(u).map(S=>({w:S.width?+S.width:a.DEFAULT_WORKSHEET_COLUMN_WIDTH,hd:a.BooleanNumber.FALSE}))};l.push({id:f.InsertColMutation.id,params:m})}const h={unitId:e,subUnitId:t,ranges:[{...o,endRow:Math.min(o.endColumn,c)}],colWidth:r.slice(0,u).map(m=>m.width?+m.width:a.DEFAULT_WORKSHEET_COLUMN_WIDTH)};return l.push({id:f.SetWorksheetColWidthMutation.id,params:h}),{redos:l,undos:[]}},onPasteCells(o,r,s,l){return i._onPasteCells(o,r,e,t,s,l)},onAfterPaste(o){n=null}}}_onPasteCells(i,e,t,n,o,r){const s={get:this._injector.get.bind(this._injector)};return Ya(i,e,t,n,r,s)}_initSpecialPasteHooks(){const i={get:this._injector.get.bind(this._injector)},e=this,t={hookName:le.SPECIAL_PASTE_VALUE,specialPasteInfo:{label:"specialPaste.value"},onPasteCells:(s,l,c,d)=>{const u=e._currentUniverSheet.getCurrentUniverSheetInstance(),h=u.getUnitId(),m=u.getActiveSheet().getSheetId();return dr(h,m,s,l,i)}},n={hookName:le.SPECIAL_PASTE_FORMAT,specialPasteInfo:{label:"specialPaste.format"},onPasteCells(s,l,c,d){const u=e._currentUniverSheet.getCurrentUniverSheetInstance(),h=u.getUnitId(),m=u.getActiveSheet().getSheetId(),S=[],g=[],{undos:_,redos:I}=hr(h,m,s,l,i);S.push(...I),g.push(..._);const{undos:C,redos:b}=oi(h,m,s,l,i);S.push(...b),g.push(...C);const{undos:M,redos:T}=ur(h,m,s,l,i);return S.push(...T),g.push(...M),{undos:g,redos:S}}},o={hookName:le.SPECIAL_PASTE_COL_WIDTH,specialPasteInfo:{label:"specialPaste.colWidth"},onPasteCells(){return{undos:[],redos:[]}},onPasteColumns(s,l,c){const d=e._currentUniverSheet.getCurrentUniverSheetInstance(),u=d.getUnitId(),h=d.getActiveSheet().getSheetId(),m=[],g=e._getWorksheet(u,h).getMaxColumns(),_=s.endColumn-g,I=l.length-_,C={unitId:u,subUnitId:h,ranges:[{...s,endRow:Math.min(s.endColumn,g)}],colWidth:l.slice(0,I).map(b=>b.width?+b.width:a.DEFAULT_WORKSHEET_COLUMN_WIDTH)};return m.push({id:f.SetWorksheetColWidthMutation.id,params:C}),m.push({id:f.SetWorksheetColWidthMutation.id,params:C}),{redos:m,undos:[]}}},r={hookName:le.SPECIAL_PASTE_BESIDES_BORDER,specialPasteInfo:{label:"specialPaste.besidesBorder"},onPasteCells(s,l,c,d){const u=e._currentUniverSheet.getCurrentUniverSheetInstance(),h=u.getUnitId(),m=u.getActiveSheet().getSheetId(),S=[],g=[],{startColumn:_,startRow:I,endColumn:C,endRow:b}=s,M=new a.ObjectMatrix;l.forValue((x,D,U)=>{const N=U.s;typeof N=="object"&&M.setValue(x+I,D+_,{s:{...N,bd:void 0},v:U.v})});const T={unitId:h,subUnitId:m,cellValue:M.getData()};S.push({id:f.SetRangeValuesMutation.id,params:T});const E=f.SetRangeValuesUndoMutationFactory(i,T);g.push({id:f.SetRangeValuesMutation.id,params:E});const{undos:y,redos:O}=oi(h,m,s,l,i);return g.push(...y),S.push(...O),{redos:S,undos:g}}};return[t,n,o,r]}_getWorksheet(i,e){var n;const t=(n=this._currentUniverSheet.getUniverSheetInstance(i))==null?void 0:n.getSheetBySheetId(e);if(!t)throw new Error(`[SheetClipboardController]: cannot find a worksheet with unitId ${i} and subUnitId ${e}.`);return t}};Gt=qa([a.OnLifecycle(a.LifecycleStages.Rendered,Gt),je(0,a.IUniverInstanceService),je(1,a.ICommandService),je(2,a.IConfigService),je(3,lt),je(4,R.IMessageService),je(5,P.Inject(P.Injector)),je(6,P.Inject(a.LocaleService))],Gt);var Ja=Object.defineProperty,Qa=Object.getOwnPropertyDescriptor,ec=(i,e,t,n)=>{for(var o=n>1?void 0:n?Qa(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Ja(e,t,o),o},gt=(i,e)=>(t,n)=>e(t,n,i);let Kt=class extends a.Disposable{constructor(i,e,t,n,o){super(),this._currentUniverService=i,this._contextMenuService=e,this._renderManagerService=t,this._selectionManagerService=n,this._selectionRenderService=o,this._currentUniverService.currentSheet$.subscribe(r=>{if(r==null)throw new Error("workbook is null");this._addListeners()})}_addListeners(){const i=ae(this._currentUniverService,this._renderManagerService);if(!i)return;const e=i.spreadsheet.onPointerDownObserver,t=e.add(l=>{if(l.button===2){const c=this._selectionManagerService.getSelections(),d=c==null?void 0:c[0];if(!d)return;const u=d.range.rangeType,h=this._selectionRenderService.convertSelectionRangeToData(d).rangeWithCoord,m=()=>{if(!h)return!1;const g=l.offsetX,_=l.offsetY;switch(u){case a.RANGE_TYPE.ROW:return h.startY<=_&&h.endY>=_;case a.RANGE_TYPE.COLUMN:return h.startX<=g&&h.endX>=g;default:return h.startX<=g&&h.endX>=g&&h.startY<=_&&h.endY>=_}},S=g=>{this._contextMenuService.triggerContextMenu(l,g)};m()?u===a.RANGE_TYPE.COLUMN?S(ee.COL_HEADER_CONTEXT_MENU):u===a.RANGE_TYPE.ROW?S(ee.ROW_HEADER_CONTEXT_MENU):S(R.MenuPosition.CONTEXT_MENU):S(R.MenuPosition.CONTEXT_MENU)}});this.disposeWithMe(a.toDisposable(()=>e.remove(t)));const o=i.spreadsheetRowHeader.onPointerDownObserver.add(l=>{l.button===2&&this._contextMenuService.triggerContextMenu(l,ee.ROW_HEADER_CONTEXT_MENU)});this.disposeWithMe(a.toDisposable(()=>e.remove(o)));const s=i.spreadsheetColumnHeader.onPointerDownObserver.add(l=>{l.button===2&&this._contextMenuService.triggerContextMenu(l,ee.COL_HEADER_CONTEXT_MENU)});this.disposeWithMe(a.toDisposable(()=>e.remove(s)))}};Kt=ec([a.OnLifecycle(a.LifecycleStages.Rendered,Kt),gt(0,a.IUniverInstanceService),gt(1,R.IContextMenuService),gt(2,w.IRenderManagerService),gt(3,P.Inject(f.SelectionManagerService)),gt(4,ce)],Kt);var tc=Object.defineProperty,nc=Object.getOwnPropertyDescriptor,ic=(i,e,t,n)=>{for(var o=n>1?void 0:n?nc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&tc(e,t,o),o},jn=(i,e)=>(t,n)=>e(t,n,i);let qt=class extends a.RxDisposable{constructor(i,e,t){super(),this._currentUniverService=i,this._renderManagerService=e,this._undoRedoService=t,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialNormalInput(),this._listenEditorBlur()}_listenEditorBlur(){this._currentUniverService.currentDoc$.pipe(k.takeUntil(this.dispose$)).subscribe(i=>{if(i==null)return;i.getUnitId()!==a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._undoRedoService.clearUndoRedo(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})}_initialNormalInput(){const i={};this._currentUniverService.getCurrentUniverSheetInstance().getSheets().forEach(e=>{const t=e.getConfig();i[e.getSheetId()]={cellData:new a.ObjectMatrix(t.cellData),rowCount:t.rowCount,columnCount:t.columnCount}})}_commandExecutedListener(){}_getDocObject(){return K.getDocObject(this._currentUniverService,this._renderManagerService)}};qt=ic([a.OnLifecycle(a.LifecycleStages.Steady,qt),jn(0,a.IUniverInstanceService),jn(1,w.IRenderManagerService),jn(2,P.Inject(a.IUndoRedoService))],qt);const mr=[R.KeyCode.ARROW_DOWN,R.KeyCode.ARROW_UP,R.KeyCode.ARROW_LEFT,R.KeyCode.ARROW_RIGHT],oc=[R.KeyCode.ENTER,R.KeyCode.TAB,...mr];function rc(){const i=[];for(const e of mr)i.push({id:Ot.id,binding:e,preconditions:t=>In(t),staticParameters:{visible:!1,eventType:w.DeviceInputEventType.Keyboard,keycode:e,isShift:!1}}),i.push({id:Ot.id,binding:e|R.MetaKeys.SHIFT,preconditions:t=>In(t),staticParameters:{visible:!1,eventType:w.DeviceInputEventType.Keyboard,keycode:e,isShift:!0}});return i}const sc={id:Re.id,binding:R.KeyCode.ENTER,description:"shortcut.sheet.toggle-editing",group:"4_sheet-edit",preconditions:i=>In(i),staticParameters:{visible:!1,eventType:w.DeviceInputEventType.Keyboard,keycode:R.KeyCode.ENTER}},lc={id:Re.id,binding:R.KeyCode.TAB,preconditions:i=>In(i),staticParameters:{visible:!1,eventType:w.DeviceInputEventType.Keyboard,keycode:R.KeyCode.TAB}},ac={id:Re.id,binding:R.KeyCode.ESC,description:"shortcut.sheet.abort-editing",group:"4_sheet-edit",preconditions:i=>bo(i),staticParameters:{visible:!1,eventType:w.DeviceInputEventType.Keyboard,keycode:R.KeyCode.ESC}},cc={id:K.BreakLineCommand.id,description:"shortcut.sheet.break-line",group:"4_sheet-edit",preconditions:i=>bo(i),binding:R.KeyCode.ENTER|R.MetaKeys.ALT},dc={id:K.DeleteLeftCommand.id,preconditions:i=>Dr(i)||Mo(i),binding:R.KeyCode.BACKSPACE},uc={id:Re.id,description:"shortcut.sheet.delete-and-start-editing",group:"4_sheet-edit",preconditions:i=>Hr(i)&&!Mo(i),binding:R.KeyCode.BACKSPACE,staticParameters:{visible:!0,eventType:w.DeviceInputEventType.Keyboard,keycode:R.KeyCode.BACKSPACE}};var hc=Object.defineProperty,mc=Object.getOwnPropertyDescriptor,Sc=(i,e,t,n)=>{for(var o=n>1?void 0:n?mc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&hc(e,t,o),o},Ce=(i,e)=>(t,n)=>e(t,n,i);function _c(i){const{textRuns:e=[],paragraphs:t=[]}=i;return e.some(n=>n.ts&&!a.Tools.isEmptyObject(n.ts))||t.some(n=>n.bullet)}let Jt=class extends a.Disposable{constructor(e,t,n,o,r,s,l,c,d,u){super();v(this,"_onInputSubscription");v(this,"_cursorChangeObservers");v(this,"_editorVisiblePrevious",!1);v(this,"_isCursorChange",0);this._currentUniverService=e,this._renderManagerService=t,this._commandService=n,this._editorBridgeService=o,this._contextService=r,this._cellEditorManagerService=s,this._lexerTreeBuilder=l,this._undoRedoService=c,this._sheetInterceptorService=d,this._selectionManagerService=u,this._initialize(),this._commandExecutedListener()}dispose(){var n;(n=this._onInputSubscription)==null||n.unsubscribe();const e=this._getEditorObject();if(e==null)return;const{document:t}=e;t.onPointerDownObserver.remove(this._cursorChangeObservers)}_initialize(){this._initialExitInput(),this._cursorStateListener()}_initialExitInput(){this._onInputSubscription=this._editorBridgeService.visible$.subscribe(e=>{const{visible:t,keycode:n,eventType:o}=e;if(t===this._editorVisiblePrevious)return;if(this._editorVisiblePrevious=t,t===!0){this._isCursorChange=o===w.DeviceInputEventType.PointerDown?2:1;return}this._isCursorChange=0;const r=this._selectionManagerService.getSelections(),s=this._selectionManagerService.getCurrent();if(s==null)return;const{unitId:l,sheetId:c,pluginName:d}=s;if(this._exitInput(e),n===R.KeyCode.ESC){this._commandService.syncExecuteCommand(f.SetSelectionsOperation.id,{unitId:l,subUnitId:c,pluginName:d,selections:r});return}const u=this._editorBridgeService.getState();if(u==null)return;const{unitId:h,sheetId:m,row:S,column:g,documentLayoutObject:_}=u;if(_==null||(this._moveCursor(n),this._editorBridgeService.getEditorDirty()===!1))return;const C=this._currentUniverService.getUniverSheetInstance(h),b=C==null?void 0:C.getSheetBySheetId(m);if(b==null)return;const M=a.Tools.deepClone(b.getCellRaw(S,g)||{}),E=_.documentModel.getSnapshot(),y=E.body;if(y==null)return;const O=y.dataStream;let D=O.substring(O.length-2,O.length)===a.DEFAULT_EMPTY_DOCUMENT_VALUE?O.substring(0,O.length-2):O;if(a.isFormulaString(D)){if(M.f===D)return;const B=this._lexerTreeBuilder.checkIfAddBracket(D);for(let A=0;A<B;A++)D+=G.matchToken.CLOSE_BRACKET;M.f=D,M.v=null,M.p=null}else if(_c(y))y.dataStream===`\r
16
- `?(M.v="",M.f=null,M.p=null):(M.p=E,M.v=null,M.f=null);else{if(D==M.v||D==""&&M.v==null)return;M.v=D,M.f=null,M.p=null}const U={subUnitId:m,unitId:h,workbook:C,worksheet:b,row:S,col:g},N=this._editorBridgeService.interceptor.fetchThroughInterceptors(this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT)(M,U);this._commandService.executeCommand(f.SetRangeValuesCommand.id,{subUnitId:m,unitId:h,range:{startRow:S,startColumn:g,endRow:S,endColumn:g},value:N}),l===h&&m!==c&&this._commandService.executeCommand(f.SetWorksheetActivateCommand.id,{subUnitId:m,unitId:h})})}_exitInput(e){this._contextService.setContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA,!1),this._contextService.setContextValue(a.FOCUSING_EDITOR,!1),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!1),this._contextService.setContextValue(a.FOCUSING_FORMULA_EDITOR,!1),this._cellEditorManagerService.setState({show:e.visible});const t=this._editorBridgeService.getCurrentEditorId();t!=null&&(this._undoRedoService.clearUndoRedo(t),this._undoRedoService.clearUndoRedo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))}_moveCursor(e){if(e==null||!oc.includes(e))return;let t=a.Direction.LEFT;switch(e){case R.KeyCode.ENTER:t=a.Direction.DOWN;break;case R.KeyCode.TAB:t=a.Direction.RIGHT;break;case R.KeyCode.ARROW_DOWN:t=a.Direction.DOWN;break;case R.KeyCode.ARROW_UP:t=a.Direction.UP;break;case R.KeyCode.ARROW_LEFT:t=a.Direction.LEFT;break;case R.KeyCode.ARROW_RIGHT:t=a.Direction.RIGHT;break}e===R.KeyCode.ENTER||e===R.KeyCode.TAB?this._commandService.executeCommand(Ke.id,{keycode:e,direction:t}):this._commandService.executeCommand(me.id,{direction:t})}_cursorStateListener(){const e=this._getEditorObject();if(e==null)return;const{document:t}=e;this._cursorChangeObservers=t.onPointerDownObserver.add(()=>{this._isCursorChange===1&&(this._isCursorChange=2)})}_commandExecutedListener(){const e=[Ot.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=t.params,{keycode:o,isShift:r}=n;if(o!=null&&this._isCursorChange===2){this._moveInEditor(o,r);return}this._editorBridgeService.changeVisible(n)}}))}_moveInEditor(e,t){let n=a.Direction.LEFT;e===R.KeyCode.ARROW_DOWN?n=a.Direction.DOWN:e===R.KeyCode.ARROW_UP?n=a.Direction.UP:e===R.KeyCode.ARROW_RIGHT&&(n=a.Direction.RIGHT),t?this._commandService.executeCommand(K.MoveSelectionOperation.id,{direction:n}):this._commandService.executeCommand(K.MoveCursorOperation.id,{direction:n})}_getEditorObject(){return yn(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}};Jt=Sc([a.OnLifecycle(a.LifecycleStages.Steady,Jt),Ce(0,a.IUniverInstanceService),Ce(1,w.IRenderManagerService),Ce(2,a.ICommandService),Ce(3,pe),Ce(4,a.IContextService),Ce(5,Pt),Ce(6,P.Inject(G.LexerTreeBuilder)),Ce(7,a.IUndoRedoService),Ce(8,P.Inject(f.SheetInterceptorService)),Ce(9,P.Inject(f.SelectionManagerService))],Jt);var gc=Object.defineProperty,fc=Object.getOwnPropertyDescriptor,pc=(i,e,t,n)=>{for(var o=n>1?void 0:n?fc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&gc(e,t,o),o},Ie=(i,e)=>(t,n)=>e(t,n,i);let Qt=class extends a.RxDisposable{constructor(e,t,n,o,r,s,l,c,d,u){super();v(this,"_loadedMap",new Set);this._univerInstanceService=e,this._renderManagerService=t,this._editorBridgeService=n,this._docSkeletonManagerService=o,this._docViewModelManagerService=r,this._commandService=s,this._contextService=l,this._formulaEditorManagerService=c,this._undoRedoService=d,this._textSelectionManagerService=u,this._initialize()}_initialize(){this._syncFormulaEditorContent(),this._commandExecutedListener(),this._syncEditorSize(),this._listenFxBtnClick(),this._renderManagerService.currentRender$.pipe(k.takeUntil(this.dispose$)).subscribe(e=>{e===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(this._loadedMap.has(e)||(this._initialMain(e),this._loadedMap.add(e)))}),this._textSelectionManagerService.textSelection$.pipe(k.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const{unitId:t}=e;t!==a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(this._contextService.setContextValue(a.FOCUSING_FORMULA_EDITOR,!1),this._undoRedoService.clearUndoRedo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))})}_listenFxBtnClick(){this._formulaEditorManagerService.fxBtnClick$.pipe(k.takeUntil(this.dispose$)).subscribe(()=>{var t;if(this._contextService.getContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN)&&!this._contextService.getContextValue(a.FOCUSING_EDITOR)){this._univerInstanceService.setCurrentUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),this._contextService.setContextValue(a.FOCUSING_FORMULA_EDITOR,!0);const n=this._univerInstanceService.getUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);this._editorBridgeService.isVisible().visible===!1&&this._editorBridgeService.changeVisible({visible:!0,eventType:w.DeviceInputEventType.PointerDown});const r=(t=n==null?void 0:n.getBody())==null?void 0:t.dataStream;if(r==null)return;let s=r.startsWith("=")?r:`=${r}`;s=s.replace(/\r\n$/,"");const l=[{startOffset:s.length,endOffset:s.length}],c={unitId:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,body:{dataStream:s},segmentId:""};this._commandService.executeCommand(K.CoverContentCommand.id,c),this._textSelectionManagerService.replaceTextRanges(l)}})}_initialMain(e){const t=this._renderManagerService.getRenderById(e);if(t==null)return;const{mainComponent:n}=t;n!=null&&this.disposeWithMe(a.toDisposable(n.onPointerDownObserver.add(()=>{this._contextService.setContextValue(a.FOCUSING_FORMULA_EDITOR,!0),this._undoRedoService.clearUndoRedo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),this._editorBridgeService.isVisible().visible===!1&&this._editorBridgeService.changeVisible({visible:!0,eventType:w.DeviceInputEventType.PointerDown})})))}_syncEditorSize(){this._formulaEditorManagerService.position$.pipe(k.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const t=yn(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,this._renderManagerService),n=this._univerInstanceService.getUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);if(t==null||n==null)return;const{width:o,height:r}=e,{engine:s}=t;n.updateDocumentDataPageSize(o),this._autoScroll(),requestIdleCallback(()=>{s.resizeBySize(o,r)})})}_syncFormulaEditorContent(){this._editorBridgeService.state$.pipe(k.takeUntil(this.dispose$)).subscribe(e=>{e==null||this._editorBridgeService.isForceKeepVisible()||this._editorSyncHandler(e)}),this._editorBridgeService.visible$.pipe(k.takeUntil(this.dispose$)).subscribe(e=>{if(e==null||e.visible===!1||this._editorBridgeService.isForceKeepVisible())return;const t=this._editorBridgeService.getState();t!=null&&this._editorSyncHandler(t)})}_editorSyncHandler(e){var s;const t=(s=e.documentLayoutObject.documentModel)==null?void 0:s.getBody();let n=t==null?void 0:t.dataStream,o=t==null?void 0:t.paragraphs,r=[];n==null||o==null||(e.isInArrayFormulaRange===!0&&this._editorBridgeService.isVisible().eventType===w.DeviceInputEventType.Dblclick?(n=`\r
17
- `,o=[{startIndex:0}]):e.isInArrayFormulaRange===!0&&(r=(t==null?void 0:t.textRuns)||[]),this._syncContentAndRender(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,n,o,r),this._autoScroll())}_commandExecutedListener(){const e=[K.RichTextEditingMutation.id,On.id],t=[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{var o,r;if(e.includes(n.id)){const s=n.params,{unitId:l}=s;if(t.includes(l)){const c=this._univerInstanceService.getUniverDocInstance(l),d=(o=c==null?void 0:c.getBody())==null?void 0:o.dataStream,u=(r=c==null?void 0:c.getBody())==null?void 0:r.paragraphs,h=l===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY?a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY;if(d==null||u==null)return;this._syncContentAndRender(h,d,u),this._autoScroll()}}}))}_syncContentAndRender(e,t,n,o=[]){var h;const r=[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY],s=this._docSkeletonManagerService.getSkeletonByUnitId(e),l=this._univerInstanceService.getUniverDocInstance(e),c=this._docViewModelManagerService.getViewModel(e);if(l==null||c==null||s==null)return;l.getBody().dataStream=t,l.getBody().paragraphs=this._clearParagraph(n),e===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(l.getBody().textRuns=[]),o.length>0&&(l.getBody().textRuns=o),c.reset(l);const{skeleton:d}=s,u=this._renderManagerService.getRenderById(e);u!=null&&(d.calculate(),r.includes(e)&&((h=u.mainComponent)==null||h.makeDirty()))}_clearParagraph(e){const t=a.Tools.deepClone(e);for(const n of t)n.paragraphStyle&&(n.paragraphStyle.horizontalAlign=a.HorizontalAlign.UNSPECIFIED);return t}_autoScroll(){var g,_;const e=(g=this._docSkeletonManagerService.getSkeletonByUnitId(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:g.skeleton,t=this._formulaEditorManagerService.getPosition(),n=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),o=this._univerInstanceService.getUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);if(e==null||t==null||n==null||o==null)return;const{marginTop:r=0,marginBottom:s=0}=o.getSnapshot().documentStyle,{scene:l,mainComponent:c}=n;let{actualHeight:d}=e.getActualSize();d+=r+s;const{width:u,height:h}=t,m=l.getViewport(K.VIEWPORT_KEY.VIEW_MAIN);let S=m==null?void 0:m.getScrollBar();d>h?S==null?m&&new w.ScrollBar(m,{enableHorizontal:!1}):m==null||m.resetSizeAndScrollBar():(S=null,m==null||m.scrollTo({x:0,y:0}),(_=m==null?void 0:m.getScrollBar())==null||_.dispose()),l.transformByState({width:u,height:d}),c==null||c.resize(u,d)}};Qt=pc([a.OnLifecycle(a.LifecycleStages.Steady,Qt),Ie(0,a.IUniverInstanceService),Ie(1,w.IRenderManagerService),Ie(2,pe),Ie(3,P.Inject(K.DocSkeletonManagerService)),Ie(4,P.Inject(K.DocViewModelManagerService)),Ie(5,a.ICommandService),Ie(6,a.IContextService),Ie(7,Dn),Ie(8,a.IUndoRedoService),Ie(9,P.Inject(K.TextSelectionManagerService))],Qt);var vc=Object.defineProperty,Cc=Object.getOwnPropertyDescriptor,Ic=(i,e,t,n)=>{for(var o=n>1?void 0:n?Cc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&vc(e,t,o),o},Rc=(i,e)=>(t,n)=>e(t,n,i);let en=class extends a.Disposable{constructor(i){super(),this._currentUniverService=i,setTimeout(()=>{this._initialize()},0)}_initialize(){this._currentUniverService.createDoc({id:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:{dataStream:`${a.DEFAULT_EMPTY_DOCUMENT_VALUE}`,textRuns:[],paragraphs:[{startIndex:0}]},documentStyle:{}});const i={id:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,body:{dataStream:`${a.DEFAULT_EMPTY_DOCUMENT_VALUE}`,textRuns:[],paragraphs:[{startIndex:0}]},documentStyle:{pageSize:{width:1/0,height:1/0},marginTop:5,marginBottom:5,marginRight:0,marginLeft:0,paragraphLineGapDefault:0,renderConfig:{horizontalAlign:a.HorizontalAlign.UNSPECIFIED,verticalAlign:a.VerticalAlign.UNSPECIFIED,centerAngle:0,vertexAngle:0,wrapStrategy:a.WrapStrategy.WRAP}}};this._currentUniverService.createDoc(i)}};en=Ic([a.OnLifecycle(a.LifecycleStages.Rendered,en),Rc(0,a.IUniverInstanceService)],en);const bc="36",Mc="univer-sheet-container",Sr={sheetFooterBarHeight:bc,sheetContainer:Mc};var wc=Object.defineProperty,Tc=Object.getOwnPropertyDescriptor,Ec=(i,e,t,n)=>{for(var o=n>1?void 0:n?Tc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&wc(e,t,o),o},_e=(i,e)=>(t,n)=>e(t,n,i);const io=-1e3,oo=5,yc=2;let tn=class extends a.Disposable{constructor(e,t,n,o,r,s,l,c,d,u,h){super();v(this,"_onInputSubscription");v(this,"_onInputActivateSubscription");v(this,"_editorVisiblePrevious",!1);this._docSkeletonManagerService=e,this._docViewModelManagerService=t,this._contextService=n,this._currentUniverService=o,this._renderManagerService=r,this._editorBridgeService=s,this._cellEditorManagerService=l,this._textSelectionRenderManager=c,this._textSelectionManagerService=d,this._commandService=u,this._localService=h,this._initialize(),this._commandExecutedListener()}dispose(){var e,t;(e=this._onInputSubscription)==null||e.unsubscribe(),(t=this._onInputActivateSubscription)==null||t.unsubscribe()}_initialize(){this._initialEditFocusListener(),this._initialStartEdit(),this._initialKeyboardListener(),this._initialCursorSync(),this._listenEditorFocus()}_listenEditorFocus(){const e=this._getEditorObject();e!=null&&this.disposeWithMe(a.toDisposable(e.document.onPointerDownObserver.add(()=>{var t;if(this._editorBridgeService.isVisible()){const n=this._editorBridgeService.getState(),o=this._editorBridgeService.getCurrentEditorId();if(n==null||o==null)return;const r=(t=this._docSkeletonManagerService.getSkeletonByUnitId(o))==null?void 0:t.skeleton;if(r==null)return;const{position:s,documentLayoutObject:l,canvasOffset:c,scaleX:d,scaleY:u}=n;this._fitTextSize(s,c,r,l,d,u)}})))}_initialCursorSync(){this._cellEditorManagerService.focus$.subscribe(()=>{this._textSelectionRenderManager.sync()})}_initialEditFocusListener(){this._onInputSubscription=this._editorBridgeService.state$.subscribe(e=>{if(e==null||this._editorBridgeService.isForceKeepVisible())return;const{position:t,documentLayoutObject:n,scaleX:o,editorUnitId:r}=e;if(this._getEditorObject()==null)return;const{startX:l,endX:c}=t,{textRotation:d,wrapStrategy:u,documentModel:h}=n,{a:m}=d;h.updateDocumentId(r),u===a.WrapStrategy.WRAP&&m===0&&h.updateDocumentDataPageSize((c-l)/o),this._currentUniverService.changeDoc(r,h),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!0),this._textSelectionManagerService.replaceTextRanges([{startOffset:0,endOffset:0}]),this._textSelectionRenderManager.activate(io,io)})}_fitTextSize(e,t,n,o,r=1,s=1){const{startX:l,startY:c,endX:d,endY:u}=e,h=o.documentModel;if(h==null)return;const{actualWidth:m,actualHeight:S}=this._predictingSize(e,t,n,o,r,s),{verticalAlign:g,paddingData:_,fill:I}=o;let C=d-l,b=u-c;if(C<m&&(C=m),b<S)b=S,h.updateDocumentDataMargin(_);else{let M=_.t||0;g===a.VerticalAlign.MIDDLE?M=(b-S)/2:g===a.VerticalAlign.BOTTOM&&(M=b-S),M/=s,M=M<(_.t||0)?_.t||0:M,h.updateDocumentDataMargin({t:M})}n.calculate(),this._editAreaProcessing(C,b,e,t,I,r,s)}_predictingSize(e,t,n,o,r=1,s=1){const{startX:l,endX:c}=e,{textRotation:d,wrapStrategy:u}=o,h=o.documentModel,{a:m}=d,S=document.body.clientWidth;if(u===a.WrapStrategy.WRAP&&m===0){const{actualWidth:I,actualHeight:C}=n.getActualSize();return{actualWidth:I*r,actualHeight:C*s}}h==null||h.updateDocumentDataPageSize((S-l-t.left)/r),n.calculate();const g=n.getActualSize();let _=c-l;return _<g.actualWidth*r+oo*r&&(_=g.actualWidth*r+oo),h==null||h.updateDocumentDataPageSize(_/r),h==null||h.updateDocumentRenderConfig({horizontalAlign:a.HorizontalAlign.UNSPECIFIED}),{actualWidth:_,actualHeight:g.actualHeight*s}}_editAreaProcessing(e,t,n,o,r,s=1,l=1){var y;const c=this._getEditorObject();if(c==null)return;let{startX:d,startY:u}=n;const{document:h,scene:m,engine:S}=c,g=m.getViewport(K.VIEWPORT_KEY.VIEW_MAIN),_=document.body.clientHeight-u-parseFloat(Sr.sheetFooterBarHeight)-o.top-yc*2,I=document.body.clientWidth-d-o.left;let C=t,b=g==null?void 0:g.getScrollBar();C>_?(C=_,b==null?g&&new w.ScrollBar(g,{enableHorizontal:!1}):g==null||g.resetSizeAndScrollBar()):(b=null,(y=g==null?void 0:g.getScrollBar())==null||y.dispose()),e+=(b==null?void 0:b.barSize)||0,e>I&&(e=I);const M=S.getPixelRatio(),T=s*M,E=l*M;d=w.fixLineWidthByScale(d-w.FIX_ONE_PIXEL_BLUR_OFFSET,T),u=w.fixLineWidthByScale(u-w.FIX_ONE_PIXEL_BLUR_OFFSET,E),e=w.fixLineWidthByScale(e,T),t=w.fixLineWidthByScale(t,E),C=w.fixLineWidthByScale(t,E),this._addBackground(m,e/s,t/l,r),this._addBackground(m,e/s,t/l,r),m.transformByState({width:e,height:t}),h.resize(e,t),setTimeout(()=>{S.resizeBySize(e,C)},0),this._cellEditorManagerService.setState({startX:d,startY:u,endX:e+d,endY:C+u,show:!0})}_addBackground(e,t,n,o){const r="_backgroundRectHelperColor_",s=e.getObject(r);s==null&&o==null||(s==null?e.addObjects([new w.Rect(r,{width:t,height:n,fill:o,evented:!1})],K.DOCS_COMPONENT_MAIN_LAYER_INDEX):o==null?s.dispose():(s.setProps({fill:o}),s.transformByState({width:t,height:n})))}_initialStartEdit(){this._onInputActivateSubscription=this._editorBridgeService.visible$.subscribe(e=>{var T,E,y;const{visible:t,eventType:n,keycode:o}=e;if(t===this._editorVisiblePrevious||(this._editorVisiblePrevious=t,t===!1))return;const r=this._editorBridgeService.getState();if(r==null)return;const{position:s,documentLayoutObject:l,canvasOffset:c,scaleX:d,scaleY:u,editorUnitId:h,unitId:m,isInArrayFormulaRange:S=!1}=r,g=this._getEditorObject();if(g==null)return;const{document:_,scene:I}=g;this._contextService.setContextValue(a.FOCUSING_EDITOR,!0);const{documentModel:C}=l,b=this._docSkeletonManagerService.getSkeletonByUnitId(h);if(b==null||C==null)return;const{skeleton:M}=b;if(this._fitTextSize(s,c,M,l,d,u),n===w.DeviceInputEventType.Keyboard||n===w.DeviceInputEventType.Dblclick&&S){const O=a.Tools.deepClone(C.snapshot),x=(T=this._docViewModelManagerService.getCurrent())==null?void 0:T.docViewModel;this._resetBodyStyle(O.body),C.reset(O),x.reset(C),_.makeDirty(),(o===R.KeyCode.BACKSPACE||n===w.DeviceInputEventType.Dblclick)&&(M.calculate(),this._editorBridgeService.changeEditorDirty(!0)),this._textSelectionManagerService.replaceTextRanges([{startOffset:0,endOffset:0}])}else if(n===w.DeviceInputEventType.Dblclick){const O=C.getBody().dataStream.length-2||0;(E=I.getViewport(K.VIEWPORT_KEY.VIEW_MAIN))==null||E.scrollTo({y:1/0}),this._textSelectionManagerService.replaceTextRanges([{startOffset:O,endOffset:O}])}(y=this._renderManagerService.getRenderById(m))==null||y.scene.resetCursor()})}_resetBodyStyle(e){e.dataStream=a.DEFAULT_EMPTY_DOCUMENT_VALUE,e.textRuns!=null&&(e.textRuns.length===1?(e.textRuns[0].st=0,e.textRuns[0].ed=1):e.textRuns=void 0),e.paragraphs!=null&&(e.paragraphs.length===1?e.paragraphs[0].startIndex=0:e.paragraphs=[{startIndex:0}]),e.sectionBreaks!=null&&(e.sectionBreaks=void 0),e.tables!=null&&(e.tables=void 0),e.customRanges!=null&&(e.customRanges=void 0),e.customBlocks!=null&&(e.customBlocks=void 0)}_initialKeyboardListener(){this._textSelectionRenderManager.onInputBefore$.subscribe(e=>{const t=this._contextService.getContextValue(a.FOCUSING_FORMULA_EDITOR);this._contextService.getContextValue(a.FOCUSING_SHEET)&&!t&&this._showEditorByKeyboard(e)})}_showEditorByKeyboard(e){if(e==null)return;const t=e.event;this._commandService.executeCommand(Re.id,{visible:!0,eventType:w.DeviceInputEventType.Keyboard,keycode:t.which})}_commandExecutedListener(){const e=[K.RichTextEditingMutation.id,On.id],t=[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{var o;if(e.includes(n.id)){const r=n.params,{unitId:s}=r,l=this._editorBridgeService.getCurrentEditorId();if(l==null)return;this._editorBridgeService.changeEditorDirty(!0);const c=(o=this._docSkeletonManagerService.getSkeletonByUnitId(l))==null?void 0:o.skeleton;if(c==null||!t.includes(s))return;const d=this._editorBridgeService.getState();if(d==null)return;const{position:u,documentLayoutObject:h,canvasOffset:m,scaleX:S,scaleY:g}=d;this._fitTextSize(u,m,c,h,S,g)}}))}_getEditorObject(){return yn(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}};tn=Ec([a.OnLifecycle(a.LifecycleStages.Steady,tn),_e(0,P.Inject(K.DocSkeletonManagerService)),_e(1,P.Inject(K.DocViewModelManagerService)),_e(2,a.IContextService),_e(3,a.IUniverInstanceService),_e(4,w.IRenderManagerService),_e(5,pe),_e(6,Pt),_e(7,w.ITextSelectionRenderManager),_e(8,P.Inject(K.TextSelectionManagerService)),_e(9,a.ICommandService),_e(10,P.Inject(a.LocaleService))],tn);const _r={id:"sheet.operation.set-activate-cell-edit",type:a.CommandType.OPERATION,handler:(i,e)=>(i.get(pe).setState(e),!0)};var Oc=Object.defineProperty,xc=Object.getOwnPropertyDescriptor,Ac=(i,e,t,n)=>{for(var o=n>1?void 0:n?xc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Oc(e,t,o),o},De=(i,e)=>(t,n)=>e(t,n,i);let nn=class extends a.RxDisposable{constructor(i,e,t,n,o,r,s,l){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._editorBridgeService=o,this._selectionManagerService=r,this._selectionRenderService=s,this._themeService=l,this._initialize(),this._commandExecutedListener()}dispose(){}_initialize(){this._initSelectionChangeListener(),this._initialEventListener()}_initSelectionChangeListener(){k.merge(this._selectionManagerService.selectionMoveEnd$,this._selectionManagerService.selectionMoveStart$).pipe(k.takeUntil(this.dispose$)).subscribe(i=>this._handleSelectionListener(i))}_handleSelectionListener(i){var N,B;const e=this._selectionManagerService.getCurrent();if((e==null?void 0:e.pluginName)!==f.NORMAL_SELECTION_PLUGIN_NAME||this._editorBridgeService.isVisible().visible===!0)return;const t=this._sheetSkeletonManagerService.getCurrent(),n=this._getSheetObject();if(t==null||n==null)return;const{skeleton:o,unitId:r,sheetId:s}=t,{scene:l,engine:c}=n;if(i==null||i.length===0||o==null||i[i.length-1]==null)return;const{primary:d}=i[i.length-1];if(d==null)return;const{startRow:u,startColumn:h}=d,m=this._selectionRenderService.convertCellRangeToInfo(d);if(m==null)return;const S=a.makeCellToSelection(m);if(S==null)return;const g=w.getCanvasOffsetByEngine(c);let{startX:_,startY:I,endX:C,endY:b}=S;const{scaleX:M,scaleY:T}=l.getAncestorScale(),E=l.getScrollXY(this._selectionRenderService.getViewPort());_=o.convertTransformToOffsetX(_,M,E),I=o.convertTransformToOffsetY(I,T,E),C=o.convertTransformToOffsetX(C,M,E),b=o.convertTransformToOffsetY(b,T,E);const y=this._currentUniverService.getCurrentUniverSheetInstance(),O=y.getActiveSheet(),x={workbook:y,worksheet:O,unitId:y.getUnitId(),subUnitId:O.getSheetId(),row:u,col:h},D=this._editorBridgeService.interceptor.fetchThroughInterceptors(this._editorBridgeService.interceptor.getInterceptPoints().BEFORE_CELL_EDIT)(O.getCell(u,h),x);let U=D&&o.getCellDocumentModelWithFormula(D);if((!U||U.documentModel==null)&&(U=o.getBlankCellDocumentModel(D)),(N=U.documentModel)==null||N.setZoomRatio(Math.max(M,T)),(D==null?void 0:D.isInArrayFormulaRange)===!0){const A=(B=U.documentModel)==null?void 0:B.getBody();A&&(A.textRuns=[{st:0,ed:A.dataStream.length-2,ts:{cl:{rgb:this._themeService.getCurrentTheme().textColorSecondary}}}])}this._commandService.executeCommand(_r.id,{position:{startX:_,startY:I,endX:C,endY:b},scaleX:M,scaleY:T,canvasOffset:g,row:u,column:h,unitId:r,sheetId:s,documentLayoutObject:U,editorUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,isInArrayFormulaRange:D==null?void 0:D.isInArrayFormulaRange})}_initialEventListener(){const i=this._getSheetObject();if(i==null)return;const{spreadsheet:e,spreadsheetColumnHeader:t,spreadsheetLeftTopPlaceholder:n,spreadsheetRowHeader:o}=i;e.onDblclickObserver.add(r=>{r.button!==2&&this._commandService.executeCommand(Re.id,{visible:!0,eventType:w.DeviceInputEventType.Dblclick})}),e.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this)),t.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this)),n.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this)),o.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this))}_keepVisibleHideEditor(){this._editorBridgeService.isForceKeepVisible()||this._hideEditor()}_hideEditor(){this._editorBridgeService.isVisible().visible===!0&&(this._selectionManagerService.makeDirty(!1),this._commandService.executeCommand(Re.id,{visible:!1,eventType:w.DeviceInputEventType.PointerDown}),setTimeout(()=>{this._selectionManagerService.makeDirty(!0)},0))}_getSheetObject(){return ae(this._currentUniverService,this._renderManagerService)}_commandExecutedListener(){const i=f.COMMAND_LISTENER_SKELETON_CHANGE;this.disposeWithMe(this._commandService.onCommandExecuted((e,t)=>{t!=null&&t.fromCollab||(e.id===f.SetWorksheetActiveOperation.id?this._keepVisibleHideEditor():i.includes(e.id)&&this._hideEditor())}))}};nn=Ac([a.OnLifecycle(a.LifecycleStages.Rendered,nn),De(0,P.Inject(exports.SheetSkeletonManagerService)),De(1,a.IUniverInstanceService),De(2,a.ICommandService),De(3,w.IRenderManagerService),De(4,pe),De(5,P.Inject(f.SelectionManagerService)),De(6,ce),De(7,P.Inject(a.ThemeService))],nn);var Hc=Object.defineProperty,Dc=Object.getOwnPropertyDescriptor,Nc=(i,e,t,n)=>{for(var o=n>1?void 0:n?Dc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Hc(e,t,o),o},ft=(i,e)=>(t,n)=>e(t,n,i);let on=class extends a.Disposable{constructor(i,e,t,n,o){super(),this._commandService=i,this._formatPainterService=e,this._currentUniverService=t,this._renderManagerService=n,this._selectionManagerService=o,this._initialize()}_initialize(){this._commandExecutedListener(),this._bindFormatPainterStatus()}_bindFormatPainterStatus(){this._formatPainterService.status$.subscribe(i=>{const{scene:e}=this._getSheetObject()||{};e&&(i!==fe.OFF?e.setDefaultCursor(w.CURSOR_TYPE.CELL):e.setDefaultCursor(w.CURSOR_TYPE.DEFAULT))})}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===f.SetSelectionsOperation.id&&this._formatPainterService.getStatus()!==fe.OFF){const{selections:e}=i.params,{range:t}=e[e.length-1];this._applyFormatPainter(t),this._formatPainterService.getStatus()===fe.ONCE&&this._commandService.executeCommand(vi.id)}}))}async _applyFormatPainter(i){const{styles:e,merges:t}=this._formatPainterService.getSelectionFormat(),n=this._currentUniverService.getCurrentUniverSheetInstance().getUnitId(),o=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();if(!e)return;const{startRow:r,startColumn:s,endRow:l,endColumn:c}=e.getDataRange(),d=l-r+1,u=c-s+1,h=Array.from({length:i.endRow-i.startRow+1},()=>Array.from({length:i.endColumn-i.startColumn+1},()=>({}))),m=[];h.forEach((g,_)=>{g.forEach((I,C)=>{const b=_%d+r,M=C%u+s,T=e.getValue(b,M);T&&(h[_][C].s=T)})}),t.forEach(g=>{const _={startRow:g.startRow-r,startColumn:g.startColumn-s,endRow:g.endRow-r,endColumn:g.endColumn-s},I=Math.floor((i.endRow-i.startRow+1)/d),C=Math.floor((i.endColumn-i.startColumn+1)/u);for(let b=0;b<I;b++)for(let M=0;M<C;M++)m.push({startRow:_.startRow+b*d+i.startRow,startColumn:_.startColumn+M*u+i.startColumn,endRow:_.endRow+b*d+i.startRow,endColumn:_.endColumn+M*u+i.startColumn})});const S={subUnitId:o,unitId:n,styleRange:i,styleValues:h,mergeRanges:m};await this._commandService.executeCommand(tr.id,S)}_getSheetObject(){return ae(this._currentUniverService,this._renderManagerService)}};on=Nc([a.OnLifecycle(a.LifecycleStages.Rendered,on),ft(0,a.ICommandService),ft(1,dt),ft(2,a.IUniverInstanceService),ft(3,w.IRenderManagerService),ft(4,P.Inject(f.SelectionManagerService))],on);const rn={id:"sheet.command.set-scroll-relative",type:a.CommandType.COMMAND,handler:async(i,e={offsetX:0,offsetY:0})=>{const t=i.get(a.ICommandService),n=i.get(ke),r=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance(),s=r.getActiveSheet(),{xSplit:l,ySplit:c}=s.getConfig().freeze,d=n.getCurrentScroll(),{offsetX:u=0,offsetY:h=0}=e||{},{sheetViewStartRow:m=0,sheetViewStartColumn:S=0,offsetX:g=0,offsetY:_=0}=d||{};return t.executeCommand(ct.id,{unitId:r.getUnitId(),sheetId:s.getSheetId(),sheetViewStartRow:m+c,sheetViewStartColumn:S+l,offsetX:g+u,offsetY:_+h})}},Ye={id:"sheet.command.scroll-view",type:a.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const n=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance(),o=n.getActiveSheet(),s=i.get(ke).getCurrentScroll();if(!o)return!1;const l=i.get(a.ICommandService),{sheetViewStartRow:c,sheetViewStartColumn:d,offsetX:u,offsetY:h}=e,{sheetViewStartColumn:m,sheetViewStartRow:S,offsetX:g,offsetY:_}=s||{};return l.executeCommand(ct.id,{unitId:n.getUnitId(),sheetId:o.getSheetId(),sheetViewStartRow:c??m,sheetViewStartColumn:d??S,offsetX:u??g,offsetY:h??_})}};a.CommandType.COMMAND;var Pc=Object.defineProperty,Lc=Object.getOwnPropertyDescriptor,Uc=(i,e,t,n)=>{for(var o=n>1?void 0:n?Lc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Pc(e,t,o),o},Ne=(i,e)=>(t,n)=>e(t,n,i);const kc="__SpreadsheetFreezeRowMainName__",Bc="__SpreadsheetFreezeRowHeaderName__",Vc="__SpreadsheetFreezeColumnMainName__",Fc="__SpreadsheetFreezeColumnHeaderName__",Wn=4,jc=.01;let sn=class extends a.Disposable{constructor(e,t,n,o,r,s,l,c){super();v(this,"_rowFreezeHeaderRect");v(this,"_rowFreezeMainRect");v(this,"_columnFreezeHeaderRect");v(this,"_columnFreezeMainRect");v(this,"_freezeDownObservers",[]);v(this,"_freezeMoveObservers",[]);v(this,"_freezeLeaveObservers",[]);v(this,"_moveObserver");v(this,"_upObserver");v(this,"_viewportObservers",[]);v(this,"_changeToRow",-1);v(this,"_changeToColumn",-1);v(this,"_changeToOffsetX",0);v(this,"_changeToOffsetY",0);v(this,"_freezeNormalHeaderColor","");v(this,"_freezeNormalMainColor","");v(this,"_freezeActiveColor","");v(this,"_freezeHoverColor","");this._sheetSkeletonManagerService=e,this._currentUniverService=t,this._commandService=n,this._renderManagerService=o,this._selectionRenderService=r,this._selectionManagerService=s,this._scrollManagerService=l,this._themeService=c,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._themeChangeListener()}_createFreeze(e=0){var y;const t=this._getFreeze();if(t==null)return;const n=(y=this._sheetSkeletonManagerService.getCurrent())==null?void 0:y.skeleton;if(n==null)return;const{startRow:o,startColumn:r}=t,s=this._getPositionByIndex(o,r);if(s==null)return;const l=this._getSheetObject();if(l==null)return;const c=l.engine,d=(c==null?void 0:c.width)||0,u=(c==null?void 0:c.height)||0,h=l.scene,{startX:m,startY:S}=s,{rowTotalHeight:g,columnTotalWidth:_,rowHeaderWidthAndMarginLeft:I,columnHeaderHeightAndMarginTop:C}=n,b=d>_+I?d:_+C,M=u>g+C?u:g+C;this._changeToRow=o,this._changeToColumn=r,this._changeToOffsetX=m,this._changeToOffsetY=S;const T=Math.max(h.scaleX,h.scaleY),E=Wn/(T<1?1:T);if(e===0){this._rowFreezeHeaderRect=new w.Rect(Bc,{fill:this._freezeNormalHeaderColor,width:I,height:E,left:0,top:S-E,zIndex:3});let O=this._freezeNormalHeaderColor;(o===-1||o===0)&&(O=this._freezeNormalMainColor),this._rowFreezeMainRect=new w.Rect(kc,{fill:O,width:b*2,height:E,left:I,top:S-E,zIndex:3}),h.addObjects([this._rowFreezeHeaderRect,this._rowFreezeMainRect],Ue)}else{this._columnFreezeHeaderRect=new w.Rect(Fc,{fill:this._freezeNormalHeaderColor,width:E,height:C,left:m-E,top:0,zIndex:3});let O=this._freezeNormalHeaderColor;(r===-1||r===0)&&(O=this._freezeNormalMainColor),this._columnFreezeMainRect=new w.Rect(Vc,{fill:O,width:E,height:M*2,left:m-E,top:C,zIndex:3}),h.addObjects([this._columnFreezeHeaderRect,this._columnFreezeMainRect],Ue)}this._eventBinding(e)}_eventBinding(e=0){let t=this._rowFreezeHeaderRect,n=this._rowFreezeMainRect;e===1&&(t=this._columnFreezeHeaderRect,n=this._columnFreezeMainRect);const o=this._getSheetObject();if(o==null)return;const{scene:r}=o;this._freezeMoveObservers.push(t==null?void 0:t.onPointerEnterObserver.add(()=>{t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),r.setCursor(w.CURSOR_TYPE.GRAB)})),this._freezeMoveObservers.push(n==null?void 0:n.onPointerEnterObserver.add(()=>{t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),r.setCursor(w.CURSOR_TYPE.GRAB)})),this._freezeLeaveObservers.push(t==null?void 0:t.onPointerLeaveObserver.add(()=>{t==null||t.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),r.resetCursor()})),this._freezeLeaveObservers.push(n==null?void 0:n.onPointerLeaveObserver.add(()=>{t==null||t.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),r.resetCursor()})),this._freezeDownObservers.push(t==null?void 0:t.onPointerDownObserver.add(s=>{this._freezeDown(s,t,n,e)})),this._freezeDownObservers.push(n==null?void 0:n.onPointerDownObserver.add(s=>{this._freezeDown(s,t,n,e)}))}_getCurrentLastVisibleRow(){var u;const e=this._getSheetObject();if(e==null)return;const t=(u=this._sheetSkeletonManagerService.getCurrent())==null?void 0:u.skeleton;if(t==null)return;const n=e.scene,o=Math.max(n.scaleX,n.scaleY),r=this._scrollManagerService.getCurrentScroll(),s=(e.engine.height-t.columnHeaderHeight)/o,l=(r==null?void 0:r.sheetViewStartRow)??0,c=l===0?-((r==null?void 0:r.offsetY)??0):t.rowHeightAccumulation[l-1]-((r==null?void 0:r.offsetY)??0);let d=0;for(let h=l,m=t.rowHeightAccumulation.length;h<m;h++)if(t.rowHeightAccumulation[h]-c>s){d=h;break}return d}_freezeDown(e,t,n,o=0){var h;const r=(h=this._sheetSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(r==null)return;const s=this._getSheetObject();if(s==null)return;const{scene:l}=s;l.setCursor(w.CURSOR_TYPE.GRABBING),l.disableEvent();const c=this._getCurrentLastVisibleRow(),d=c===void 0?1/0:r.rowHeightAccumulation[c],u=l.getViewport(Y.VIEW_MAIN);this._moveObserver=l.onPointerMoveObserver.add(m=>{var b,M,T,E;const{startX:S,startY:g,row:_,column:I}=st(m.offsetX,m.offsetY,l,r,u);l.setCursor(w.CURSOR_TYPE.GRABBING);const C=Wn/Math.max(l.scaleX,l.scaleY);o===0?((b=t.transformByState({top:Math.min(g,d)-C/2}))==null||b.setProps({fill:this._freezeActiveColor}),(M=n.transformByState({top:Math.min(g,d)-C/2}))==null||M.setProps({fill:this._freezeNormalHeaderColor}),this._changeToRow=c===void 0?_:Math.min(_,c),this._changeToOffsetY=Math.min(g,d)):((T=t.transformByState({left:S-C/2}))==null||T.setProps({fill:this._freezeActiveColor}),(E=n.transformByState({left:S-C/2}))==null||E.setProps({fill:this._freezeNormalHeaderColor}),this._changeToColumn=I,this._changeToOffsetX=S)}),this._upObserver=l.onPointerUpObserver.add(()=>{var O;l.resetCursor(),l.enableEvent(),this._clearObserverEvent();const{rowHeaderWidthAndMarginLeft:m,columnHeaderHeightAndMarginTop:S}=r;o===0&&(this._changeToRow===0||this._changeToRow===-1)||o===1&&(this._changeToColumn===0||this._changeToColumn===-1)?(t.setProps({fill:this._freezeNormalHeaderColor}),n.setProps({fill:this._freezeNormalMainColor})):(t==null||t.setProps({fill:this._freezeNormalHeaderColor}),n==null||n.setProps({fill:this._freezeNormalHeaderColor}));const g=Wn/Math.max(l.scaleX,l.scaleY);o===0?(this._changeToRow===0||this._changeToRow===-1)&&(t.transformByState({top:S-g}),n.transformByState({top:S-g})):(this._changeToColumn===0||this._changeToColumn===-1)&&(t.transformByState({left:m-g}),n.transformByState({left:m-g}));const _=this._scrollManagerService.getCurrentScroll()||{sheetViewStartRow:0,sheetViewStartColumn:0},{sheetViewStartRow:I,sheetViewStartColumn:C}=_;if(C==null||I==null)return;const b=this._currentUniverService.getCurrentUniverSheetInstance(),M=b.getActiveSheet(),T=(O=M.getConfig())==null?void 0:O.freeze;let E=(T==null?void 0:T.xSplit)||0,y=(T==null?void 0:T.ySplit)||0;o===0&&(y=this._changeToRow-I,y=y<0?0:y),o===1&&(E=this._changeToColumn-C,E=E<0?0:E),this._commandService.executeCommand(f.SetFrozenCommand.id,{startRow:this._changeToRow,startColumn:this._changeToColumn,ySplit:y,xSplit:E,unitId:b.getUnitId(),subUnitId:M.getSheetId()})})}_updateViewport(e=-1,t=-1,n=0,o=0){var U;const r=this._getSheetObject();if(r==null)return;const{scene:s}=r,l=(U=this._sheetSkeletonManagerService.getCurrent())==null?void 0:U.skeleton;if(l==null)return;const{rowHeaderWidthAndMarginLeft:c,columnHeaderHeightAndMarginTop:d}=l,u=s.getViewport(Y.VIEW_COLUMN_LEFT),h=s.getViewport(Y.VIEW_COLUMN_RIGHT),m=s.getViewport(Y.VIEW_ROW_TOP),S=s.getViewport(Y.VIEW_ROW_BOTTOM),g=s.getViewport(Y.VIEW_LEFT_TOP),_=s.getViewport(Y.VIEW_MAIN),I=s.getViewport(Y.VIEW_MAIN_LEFT_TOP),C=s.getViewport(Y.VIEW_MAIN_LEFT),b=s.getViewport(Y.VIEW_MAIN_TOP);if(u==null||h==null||m==null||S==null||g==null||_==null||I==null||C==null||b==null)return;const{scaleX:M,scaleY:T}=s.getAncestorScale();this._viewportObservers.forEach(N=>{_.onScrollAfterObserver.remove(N)}),h.resize({left:c,top:0,height:d,right:0}),S.resize({left:0,top:d,bottom:0,width:c}),g.resize({left:0,top:0,width:c,height:d}),this._viewportObservers.push(_.onScrollAfterObserver.add(N=>{const{scrollX:B,scrollY:A,actualScrollX:H,actualScrollY:V}=N;h.updateScroll({scrollX:B,actualScrollX:H}).makeDirty(!0),S.updateScroll({scrollY:A,actualScrollY:V}).makeDirty(!0)}));let E=!0,y=!0;I.enable(),(e===-1||e===0)&&(E=!1),(t===-1||t===0)&&(y=!1);const O=l.getNoMergeCellPositionByIndexWithNoHeader(e-n,t-o,M,T),x=l.getNoMergeCellPositionByIndexWithNoHeader(e,t,M,T);I.disable(),b.disable(),C.disable(),m.disable(),u.disable(),I.resetPadding(),b.resetPadding(),C.resetPadding(),m.resetPadding(),u.resetPadding();const D=this._scrollManagerService.getCurrentScroll();if(E===!1&&y===!1)_.resize({left:c,top:d,bottom:0,right:0}),_.resetPadding(),this._commandService.executeCommand(Ye.id,D??{sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0});else if(E===!0&&y===!1){const N=x.startY-O.startY;_.resize({left:c,top:d+N,bottom:0,right:0}),_.setPadding({startY:O.startY,endY:x.startY,startX:0,endX:0}),this._commandService.executeCommand(Ye.id,D??{sheetViewStartRow:0,offsetY:0}),b.resize({left:c,top:d,height:N,right:0}),b.updateScroll({actualScrollY:O.startY,x:_.scrollX,actualScrollX:_.actualScrollX}).makeDirty(!0),m.resize({left:0,top:d,width:c,height:N}),m.updateScroll({actualScrollY:O.startY}).makeDirty(!0),S.resize({left:0,top:d+N,bottom:0,width:c}),this._viewportObservers.push(_.onScrollAfterObserver.add(B=>{const{scrollX:A,actualScrollX:H}=B;b.updateScroll({scrollX:A,actualScrollX:H}).makeDirty(!0)})),b.enable(),m.enable()}else if(E===!1&&y===!0){const N=x.startX-O.startX;_.resize({left:c+N,top:d,bottom:0,right:0}),_.setPadding({startX:O.startX,endX:x.startX,startY:0,endY:0}),this._commandService.executeCommand(Ye.id,D??{sheetViewStartColumn:0,offsetX:0}),C.resize({left:c,top:d,width:N,bottom:0,right:0}),C.updateScroll({actualScrollX:O.startX,y:_.scrollY,actualScrollY:_.actualScrollY}).makeDirty(!0),u.resize({left:c,top:0,width:N,height:d}),u.updateScroll({actualScrollX:O.startX}).makeDirty(!0),h.resize({left:c+N,top:0,height:d,right:0}),this._viewportObservers.push(_.onScrollAfterObserver.add(B=>{const{scrollY:A,actualScrollY:H}=B;C.updateScroll({scrollY:A,actualScrollY:H}).makeDirty(!0)})),C.enable(),u.enable()}else{const N=x.startX-O.startX,B=x.startY-O.startY;_.resize({left:c+N,top:d+B,bottom:0,right:0}),_.setPadding({startY:O.startY,endY:x.startY,startX:O.startX,endX:x.startX}),this._commandService.executeCommand(Ye.id,{sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0}),C.resize({left:c,top:d+B,width:N,bottom:0}),C.updateScroll({actualScrollX:O.startX,y:_.scrollY,actualScrollY:_.actualScrollY}).makeDirty(!0),b.resize({left:c+N,top:d,height:B,right:0}),b.updateScroll({actualScrollY:O.startY,x:_.scrollX,actualScrollX:_.actualScrollX}).makeDirty(!0),I.resize({left:c,top:d,width:N,height:B}),I.updateScroll({actualScrollX:O.startX,actualScrollY:O.startY}).makeDirty(!0),m.resize({left:0,top:d,width:c,height:B}),m.updateScroll({actualScrollY:O.startY}).makeDirty(!0),S.resize({left:0,top:d+B,bottom:0,width:c}),u.resize({left:c,top:0,width:N,height:d}),u.updateScroll({actualScrollX:O.startX}).makeDirty(!0),h.resize({left:c+N,top:0,height:d,right:0}),this._viewportObservers.forEach(A=>{_.onScrollAfterObserver.remove(A)}),this._viewportObservers.push(_.onScrollAfterObserver.add(A=>{const{scrollX:H,scrollY:V,actualScrollX:F,actualScrollY:j}=A;S.updateScroll({scrollY:V,actualScrollY:j}).makeDirty(!0),h.updateScroll({scrollX:H,actualScrollX:F}).makeDirty(!0),C.updateScroll({scrollY:V,actualScrollY:j}).makeDirty(!0),b.updateScroll({scrollX:H,actualScrollX:F}).makeDirty(!0)})),I.enable(),b.enable(),C.enable(),m.enable(),u.enable()}}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(e=>{[f.SetWorksheetActiveOperation.id].includes((e==null?void 0:e.commandId)||"")&&this._refreshCurrent()})))}_refreshCurrent(){const n=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getConfig().freeze,{startRow:o=-1,startColumn:r=-1,ySplit:s=0,xSplit:l=0}=n;this._refreshFreeze(o,r,s,l)}_themeChangeListener(){this._themeChange(this._themeService.getCurrentTheme()),this.disposeWithMe(a.toDisposable(this._themeService.currentTheme$.subscribe(e=>{this._clearFreeze(),this._themeChange(e),this._refreshCurrent()})))}_themeChange(e){this._freezeNormalHeaderColor=e.grey400,this._freezeNormalMainColor=new a.ColorKit(e.grey400).setAlpha(jc).toRgbString(),this._freezeActiveColor=e.primaryColor,this._freezeHoverColor=e.grey500}_commandExecutedListener(){const e=[f.SetFrozenMutation.id,xe.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=this._currentUniverService.getCurrentUniverSheetInstance(),o=n.getActiveSheet(),r=t.params,{unitId:s,subUnitId:l}=r;if(!(s===n.getUnitId()&&l===o.getSheetId())||o.getConfig().freeze==null)return;const{startRow:d=-1,startColumn:u=-1,ySplit:h=0,xSplit:m=0}=o.getConfig().freeze;this._refreshFreeze(d,u,h,m)}else if(t.id===f.DeltaRowHeightCommand.id){const n=this._getFreeze();t.params&&n&&t.params.anchorRow<n.startRow&&this._refreshCurrent()}else if(t.id===f.DeltaColumnWidthCommand.id){const n=this._getFreeze();t.params&&n&&t.params.anchorCol<n.startColumn&&this._refreshCurrent()}else if(t.id===f.SetWorksheetRowAutoHeightMutation.id){const n=t.params,o=this._getFreeze();if(o&&o.startRow>-1&&n.rowsAutoHeightInfo.some(r=>r.row<o.startRow)){const r=this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._refreshCurrent(),setTimeout(()=>{r.unsubscribe()})})}}}))}_clearObserverEvent(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;t.onPointerMoveObserver.remove(this._moveObserver),t.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_clearFreeze(){var n,o,r,s;(n=this._rowFreezeHeaderRect)==null||n.dispose(),(o=this._rowFreezeMainRect)==null||o.dispose(),(r=this._columnFreezeHeaderRect)==null||r.dispose(),(s=this._columnFreezeMainRect)==null||s.dispose();const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;[...this._freezeDownObservers,...this._freezeMoveObservers,...this._freezeLeaveObservers].forEach(l=>{t.onPointerDownObserver.remove(l),t.onPointerMoveObserver.remove(l),t.onPointerLeaveObserver.remove(l)}),t.onPointerEnterObserver.remove(this._moveObserver),t.onPointerMoveObserver.remove(this._upObserver)}_getPositionByIndex(e,t){var u;const n=this._getSheetObject();if(n==null)return;const{scaleX:o,scaleY:r}=n.scene.getAncestorScale(),s=(u=this._sheetSkeletonManagerService.getCurrent())==null?void 0:u.skeleton,l=s==null?void 0:s.getNoMergeCellPositionByIndex(e,t,o,r);if(s==null)return;if(l!=null&&(!isNaN(l.endX)||!isNaN(l.endY)))return l;const{rowHeaderWidthAndMarginLeft:c,columnHeaderHeightAndMarginTop:d}=s;return{startX:c,endX:c,startY:d,endY:d}}_getFreeze(){var t;const e=(t=this._sheetSkeletonManagerService.getCurrent())==null?void 0:t.skeleton.getWorksheetConfig();if(e!=null)return e.freeze}_getSheetObject(){return ae(this._currentUniverService,this._renderManagerService)}_refreshFreeze(e,t,n,o){var r;this._clearFreeze(),this._createFreeze(0),this._createFreeze(1),this._updateViewport(e,t,n,o),(r=this._getSheetObject())==null||r.spreadsheet.makeForceDirty()}};sn=Uc([a.OnLifecycle(a.LifecycleStages.Rendered,sn),Ne(0,P.Inject(exports.SheetSkeletonManagerService)),Ne(1,a.IUniverInstanceService),Ne(2,a.ICommandService),Ne(3,w.IRenderManagerService),Ne(4,ce),Ne(5,P.Inject(f.SelectionManagerService)),Ne(6,P.Inject(ke)),Ne(7,P.Inject(a.ThemeService))],sn);var ri=(i=>(i[i.NORMAL=0]="NORMAL",i[i.HIGHLIGHT=1]="HIGHLIGHT",i))(ri||{});const Wc="rgba(0, 0, 0, 0.15)",ye="rgb(0, 0, 0)",jt="rgb(255, 255, 255, 1)";class $c extends w.Shape{constructor(t,n){super(t,n);v(this,"_size",12);v(this,"_iconRatio",.4);v(this,"_mode",0);this.setShapeProps(n)}setShapeProps(t){t!=null&&t.size&&(this._size=t.size),t!=null&&t.mode&&(this._mode=t.mode),this.transformByState({width:this._size,height:this._size})}_draw(t){this._mode===1&&w.Rect.drawWith(t,{width:this._size,height:this._size,radius:this._size,fill:Wc});const n=this._size*.5*this._iconRatio,o=Math.PI/180*60,r=n*Math.sin(o),s=n*Math.cos(o);w.RegularPolygon.drawWith(t,{pointsGroup:[[{x:-r+this._size/2,y:-s+this._size/2},{x:r+this._size/2,y:-s+this._size/2},{x:this._size/2,y:n+this._size/2}]],fill:ye})}}var zc=Object.defineProperty,Xc=Object.getOwnPropertyDescriptor,Yc=(i,e,t,n)=>{for(var o=n>1?void 0:n?Xc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&zc(e,t,o),o},pt=(i,e)=>(t,n)=>e(t,n,i);const Zc="__SpreadsheetHeaderMenuSHAPEControllerShape__",Gc="__SpreadsheetHeaderMenuMAINControllerShape__",Kc="rgba(0, 0, 0, 0.1)";let ln=class extends a.Disposable{constructor(e,t,n,o,r){super();v(this,"_hoverRect");v(this,"_hoverMenu");v(this,"_currentColumn",1/0);v(this,"_observers",[]);this._sheetSkeletonManagerService=e,this._currentUniverService=t,this._renderManagerService=n,this._contextMenuService=o,this._selectionManagerService=r,this._initialize()}dispose(){var o,r;(o=this._hoverRect)==null||o.dispose(),(r=this._hoverMenu)==null||r.dispose();const e=this._getSheetObject();if(e==null)return;const{spreadsheetRowHeader:t,spreadsheetColumnHeader:n}=e;this._observers.forEach(s=>{t.onPointerEnterObserver.remove(s),t.onPointerMoveObserver.remove(s),t.onPointerLeaveObserver.remove(s),n.onPointerEnterObserver.remove(s),n.onPointerMoveObserver.remove(s),n.onPointerLeaveObserver.remove(s)})}_initialize(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;this._hoverRect=new w.Rect(Zc,{fill:Kc,evented:!1}),this._hoverMenu=new $c(Gc,{zIndex:100,visible:!1}),t.addObjects([this._hoverRect,this._hoverMenu],Ue),this._initialHover(0),this._initialHover(1),this._initialHoverMenu()}_initialHover(e=0){const t=this._getSheetObject();if(t==null)return;const{spreadsheetColumnHeader:n,spreadsheetRowHeader:o}=t,r=e===0?o:n;this._observers.push(r==null?void 0:r.onPointerEnterObserver.add(()=>{var s;(s=this._hoverRect)==null||s.show()})),this._observers.push(r==null?void 0:r.onPointerMoveObserver.add(s=>{var I,C,b;const l=(I=this._sheetSkeletonManagerService.getCurrent())==null?void 0:I.skeleton;if(l==null)return;const c=this._getSheetObject();if(c==null)return;const{rowHeaderWidth:d,columnHeaderHeight:u}=l,{startX:h,startY:m,endX:S,endY:g,column:_}=st(s.offsetX,s.offsetY,c.scene,l);if(e===0)(C=this._hoverRect)==null||C.transformByState({width:d,height:g-m,left:0,top:m});else{if(this._currentColumn=_,(b=this._hoverRect)==null||b.transformByState({width:S-h,height:u,left:h,top:0}),this._hoverMenu==null)return;if(S-h<u*2){this._hoverMenu.hide();return}const M=u*.8;this._hoverMenu.transformByState({left:S-u,top:u/2-M/2}),this._hoverMenu.setShapeProps({size:M}),this._hoverMenu.show()}})),this._observers.push(r==null?void 0:r.onPointerLeaveObserver.add(()=>{var s,l;(s=this._hoverRect)==null||s.hide(),(l=this._hoverMenu)==null||l.hide()}))}_initialHoverMenu(){this._hoverMenu!=null&&(this._hoverMenu.onPointerEnterObserver.add(()=>{if(this._hoverMenu==null)return;const e=this._getSheetObject();e!=null&&(this._hoverMenu.setProps({mode:ri.HIGHLIGHT,visible:!0}),e.scene.setCursor(w.CURSOR_TYPE.POINTER))}),this._hoverMenu.onPointerLeaveObserver.add(()=>{if(this._hoverMenu==null)return;const e=this._getSheetObject();e!=null&&(this._hoverMenu.setProps({mode:ri.NORMAL,visible:!1}),e.scene.resetCursor())}),this._hoverMenu.onPointerDownObserver.add(e=>{const t=this._getSheetObject();if(t==null)return;const n=this._currentColumn,o=this._selectionManagerService.getSelectionRanges();(o==null?void 0:o.find(s=>{const{startColumn:l,endColumn:c}=s;return n>=l&&l<=c}))==null?t.spreadsheetColumnHeader.onPointerDownObserver.notifyObservers(e):(e.stopPropagation(),e.preventDefault(),this._contextMenuService.triggerContextMenu(e,ee.COL_HEADER_CONTEXT_MENU))}))}_getSheetObject(){return ae(this._currentUniverService,this._renderManagerService)}};ln=Yc([a.OnLifecycle(a.LifecycleStages.Rendered,ln),pt(0,P.Inject(exports.SheetSkeletonManagerService)),pt(1,a.IUniverInstanceService),pt(2,w.IRenderManagerService),pt(3,R.IContextMenuService),pt(4,P.Inject(f.SelectionManagerService))],ln);var qc=Object.defineProperty,Jc=Object.getOwnPropertyDescriptor,Qc=(i,e,t,n)=>{for(var o=n>1?void 0:n?Jc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&qc(e,t,o),o},Qe=(i,e)=>(t,n)=>e(t,n,i);const ed="__SpreadsheetHeaderMoveControllerBackground__",td="__SpreadsheetHeaderMoveControllerShapeLine__",nd="rgba(0, 0, 0, 0.1)",id="rgb(119, 119, 119)",od=4;let an=class extends a.Disposable{constructor(e,t,n,o,r,s){super();v(this,"_startOffsetX",-1/0);v(this,"_startOffsetY",-1/0);v(this,"_moveHelperBackgroundShape");v(this,"_moveHelperLineShape");v(this,"_sheetObject");v(this,"_rowOrColumnDownObservers",[]);v(this,"_rowOrColumnMoveObservers",[]);v(this,"_rowOrColumnLeaveObservers",[]);v(this,"_moveObserver");v(this,"_upObserver");v(this,"_scrollTimer");v(this,"_changeFromColumn",-1);v(this,"_changeFromRow",-1);v(this,"_changeToColumn",-1);v(this,"_changeToRow",-1);this._sheetSkeletonManagerService=e,this._currentUniverService=t,this._renderManagerService=n,this._commandService=o,this._selectionRenderService=r,this._selectionManagerService=s,this._initialize()}dispose(){var r,s;(r=this._moveHelperBackgroundShape)==null||r.dispose(),(s=this._moveHelperLineShape)==null||s.dispose();const e=this._getSheetObject();if(e==null)return;const{spreadsheetRowHeader:t,spreadsheetColumnHeader:n,scene:o}=e;[...this._rowOrColumnDownObservers,...this._rowOrColumnMoveObservers,...this._rowOrColumnLeaveObservers].forEach(l=>{t.onPointerDownObserver.remove(l),n.onPointerDownObserver.remove(l)}),o.onPointerMoveObserver.remove(this._moveObserver),o.onPointerUpObserver.remove(this._upObserver),this._scrollTimer.dispose()}_initialize(){const e=this._getSheetObject();e!=null&&(this._sheetObject=e,this._initialRowOrColumn(0),this._initialRowOrColumn(1))}_initialRowOrColumn(e=0){const{spreadsheetColumnHeader:t,spreadsheetRowHeader:n,scene:o}=this._sheetObject,r=e===0?n:t;this._rowOrColumnMoveObservers.push(r==null?void 0:r.onPointerMoveObserver.add(s=>{var h;const l=(h=this._sheetSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(l==null)return;const{row:c,column:d}=st(s.offsetX,s.offsetY,o,l);if(this._checkInHeaderRange(e===0?c:d,e)===!1){o.resetCursor(),this._selectionRenderService.enableSelection();return}o.setCursor(w.CURSOR_TYPE.GRAB),this._selectionRenderService.disableSelection()})),this._rowOrColumnLeaveObservers.push(r==null?void 0:r.onPointerLeaveObserver.add(()=>{var s,l;(s=this._moveHelperBackgroundShape)==null||s.hide(),(l=this._moveHelperLineShape)==null||l.hide(),o.resetCursor(),this._selectionRenderService.enableSelection()})),this._rowOrColumnDownObservers.push(r==null?void 0:r.onPointerDownObserver.add(s=>{var b;const l=(b=this._sheetSkeletonManagerService.getCurrent())==null?void 0:b.skeleton;if(l==null)return;const{offsetX:c,offsetY:d}=s,u=o.getRelativeCoord(w.Vector2.FromArray([c,d])),{x:h,y:m}=u;this._startOffsetX=h,this._startOffsetY=m;const{row:S,column:g}=st(s.offsetX,s.offsetY,o,l);e===0?this._changeFromRow=S:this._changeFromColumn=g;const _=this._checkInHeaderRange(e===0?S:g,e);if(_===!1)return;this._newBackgroundAndLine(),o.setCursor(w.CURSOR_TYPE.GRABBING),o.disableEvent();const I=w.ScrollTimer.create(o),C=o.getViewport(Y.VIEW_MAIN);I.startScroll(h,m,C),this._scrollTimer=I,this._moveObserver=o.onPointerMoveObserver.add(M=>{const{offsetX:T,offsetY:E}=M,{x:y,y:O}=o.getRelativeCoord(w.Vector2.FromArray([T,E]));o.setCursor(w.CURSOR_TYPE.GRABBING),this._columnMoving(y,O,_,e),I.scrolling(y,O,()=>{this._columnMoving(y,O,_,e)})}),this._upObserver=o.onPointerUpObserver.add(()=>{var M;this._disposeBackgroundAndLine(),o.resetCursor(),o.enableEvent(),this._clearObserverEvent(),(M=this._scrollTimer)==null||M.dispose(),e===0?(this._changeFromRow!==this._changeToRow&&this._changeToRow!==-1&&this._commandService.executeCommand(f.MoveRowsCommand.id,{fromRow:this._changeFromRow,toRow:this._changeToRow}),this._changeToRow=this._changeFromRow=-1):(this._changeFromColumn!==this._changeToColumn&&this._changeToColumn!==-1&&this._commandService.executeCommand(f.MoveColsCommand.id,{fromCol:this._changeFromColumn,toCol:this._changeToColumn}),this._changeToColumn=this._changeFromColumn=-1)})}))}_columnMoving(e,t,n,o){var j,$,q,z,Q,J,we;const{scene:r}=this._sheetObject,s=(j=this._sheetSkeletonManagerService.getCurrent())==null?void 0:j.skeleton;if(s==null)return;const{rowHeaderWidth:l,columnHeaderHeight:c,rowTotalHeight:d,columnTotalWidth:u}=s,h=r.getScrollXYByRelativeCoords(w.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:m,scaleY:S}=r.getAncestorScale(),g=s.getCellPositionByOffset(e,t,m,S,h),{row:_,column:I}=g,C=s.getNoMergeCellPositionByIndex(_,I,m,S),{startX:b,startY:M,endX:T,endY:E}=C,y=this._selectionRenderService.convertRangeDataToSelection(n.range);if(y==null)return;const O=Math.max(m,m),{startX:x,endX:D,startY:U,endY:N,startRow:B,startColumn:A,endRow:H,endColumn:V}=y;o===0?($=this._moveHelperBackgroundShape)==null||$.transformByState({height:N-U,width:u+l,left:0,top:U+(t-this._startOffsetY)/O}):(q=this._moveHelperBackgroundShape)==null||q.transformByState({height:d+c,width:D-x,left:x+(e-this._startOffsetX)/O,top:0}),(z=this._moveHelperBackgroundShape)==null||z.show();const F=od/O;if(o===0){let re=0;if(_<=B)re=M-F/2,this._changeToRow=_;else if(_>H)re=E-F/2,this._changeToRow=_+1;else return;(Q=this._moveHelperLineShape)==null||Q.transformByState({height:F,width:u,left:l,top:re})}else{let re=0;if(I<=A)re=b-F/2,this._changeToColumn=I;else if(I>V)re=T-F/2,this._changeToColumn=I+1;else return;(J=this._moveHelperLineShape)==null||J.transformByState({height:d,width:F,left:re,top:c})}(we=this._moveHelperLineShape)==null||we.show()}_checkInHeaderRange(e,t=0){const n=this._selectionManagerService.getSelections(),o=n==null?void 0:n.find(s=>{const l=s.range,{startRow:c,endRow:d,startColumn:u,endColumn:h}=l;return t===1?e>=u&&e<=h:e>=c&&e<=d}),r=o==null?void 0:o.range;return o==null||r==null||r.rangeType===a.RANGE_TYPE.ALL||r.rangeType===a.RANGE_TYPE.NORMAL||r.rangeType===a.RANGE_TYPE.ROW&&t!==0||r.rangeType===a.RANGE_TYPE.COLUMN&&t!==1?!1:o}_clearObserverEvent(){const{scene:e}=this._sheetObject;e.onPointerMoveObserver.remove(this._moveObserver),e.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_newBackgroundAndLine(){const{scene:e}=this._sheetObject;this._moveHelperBackgroundShape=new w.Rect(ed,{fill:nd,evented:!1,zIndex:100}),this._moveHelperLineShape=new w.Rect(td,{fill:id,evented:!1,zIndex:100}),e.addObjects([this._moveHelperBackgroundShape,this._moveHelperLineShape],Ue)}_disposeBackgroundAndLine(){var e,t;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(t=this._moveHelperLineShape)==null||t.dispose()}_getSheetObject(){return ae(this._currentUniverService,this._renderManagerService)}};an=Qc([a.OnLifecycle(a.LifecycleStages.Rendered,an),Qe(0,P.Inject(exports.SheetSkeletonManagerService)),Qe(1,a.IUniverInstanceService),Qe(2,w.IRenderManagerService),Qe(3,a.ICommandService),Qe(4,ce),Qe(5,P.Inject(f.SelectionManagerService))],an);var si=(i=>(i[i.VERTICAL=0]="VERTICAL",i[i.HORIZONTAL=1]="HORIZONTAL",i))(si||{});const rd="rgba(120, 120, 120, 0.01)",$n="rgb(68, 71, 70)",Rt=12,li=4;class ro extends w.Shape{constructor(t,n){super(t,n);v(this,"_size",Rt);v(this,"_color",$n);v(this,"_mode",0);this.setShapeProps(n)}get size(){return this._size}get mode(){return this._mode}get color(){return this._color}_draw(t){let{width:n,height:o}=this,r=0,s=0;const l=this.getScene(),{scaleX:c,scaleY:d}=l.getAncestorScale(),u=Math.max(c,d),h=Rt/u,m=li/u;this.mode===0?(n=m,r=h-m):(o=m,s=h-m),w.Rect.drawWith(t,{width:this.width,height:this.height,left:0,top:0,fill:rd}),w.Rect.drawWith(t,{width:n,height:o,fill:$n,radius:m}),t.save(),t.transform(1,0,0,1,r,s),w.Rect.drawWith(t,{width:n,height:o,fill:$n,radius:m}),t.restore()}setShapeProps(t){return t!=null&&t.size&&(this._size=t.size),t!=null&&t.mode&&(this._mode=t.mode),t!=null&&t.color&&(this._color=t.color),this.mode===0?this.transformByState({width:Rt,height:this.size}):this.transformByState({width:this.size,height:Rt}),this}}var sd=Object.defineProperty,ld=Object.getOwnPropertyDescriptor,ad=(i,e,t,n)=>{for(var o=n>1?void 0:n?ld(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&sd(e,t,o),o},vt=(i,e)=>(t,n)=>e(t,n,i);const cd="__SpreadsheetHeaderResizeControllerShapeRow__",dd="__SpreadsheetHeaderResizeControllerShapeColumn__",so="__SpreadsheetHeaderResizeControllerShapeHelper__",lo="rgb(199, 199, 199)",ud=2;let cn=class extends a.Disposable{constructor(e,t,n,o,r){super();v(this,"_currentRow",0);v(this,"_currentColumn",0);v(this,"_rowResizeRect");v(this,"_columnResizeRect");v(this,"_observers",[]);v(this,"_moveObserver");v(this,"_upObserver");v(this,"_resizeHelperShape");v(this,"_startOffsetX",1/0);v(this,"_startOffsetY",1/0);this._sheetSkeletonManagerService=e,this._currentUniverService=t,this._commandService=n,this._renderManagerService=o,this._editorBridgeService=r,this._initialize()}dispose(){var o,r;(o=this._rowResizeRect)==null||o.dispose(),this._rowResizeRect=null,(r=this._columnResizeRect)==null||r.dispose(),this._columnResizeRect=null;const e=this._getSheetObject();if(e==null)throw new Error("sheetObject is null");const{spreadsheetRowHeader:t,spreadsheetColumnHeader:n}=e;this._observers.forEach(s=>{t.onPointerMoveObserver.remove(s),t.onPointerLeaveObserver.remove(s),n.onPointerMoveObserver.remove(s),n.onPointerLeaveObserver.remove(s)}),this._observers=[]}_initialize(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;this._rowResizeRect=new ro(cd,{visible:!1,mode:si.HORIZONTAL,zIndex:100}),this._columnResizeRect=new ro(dd,{visible:!1,mode:si.VERTICAL,zIndex:100}),t.addObjects([this._rowResizeRect,this._columnResizeRect],Ue),this._initialHover(0),this._initialHover(1),this._initialHoverResize(0),this._initialHoverResize(1)}_initialHover(e=0){const t=this._getSheetObject();if(t==null)return;const{spreadsheetRowHeader:n,spreadsheetColumnHeader:o,scene:r}=t,s=e===0?n:o;this._observers.push(s==null?void 0:s.onPointerMoveObserver.add((l,c)=>{var O;const d=(O=this._sheetSkeletonManagerService.getCurrent())==null?void 0:O.skeleton;if(d==null||this._rowResizeRect==null||this._columnResizeRect==null)return;const{rowHeaderWidth:u,columnHeaderHeight:h}=d,{startX:m,startY:S,endX:g,endY:_,row:I,column:C}=st(l.offsetX,l.offsetY,r,d),b=Xt(l.offsetX,l.offsetY,r),{scaleX:M,scaleY:T}=r.getAncestorScale(),E=Math.max(M,T),y=Rt/E;if(e===0){let x=S-y/2;if(b.y<=S+y/2&&b.y>=S)this._currentRow=I-1;else if(b.y>=_-y/2&&b.y<=_)this._currentRow=I,x=_-y/2;else{this._rowResizeRect.hide();return}if(this._currentRow===-1)return;const D=u/3;this._rowResizeRect.transformByState({left:u/2-D/2,top:x}),this._rowResizeRect.setShapeProps({size:D}),this._rowResizeRect.show()}else{let x=m-y/2;if(b.x<=m+y/2&&b.x>=m)this._currentColumn=C-1;else if(b.x>=g-y/2&&b.x<=g)this._currentColumn=C,x=g-y/2;else{this._columnResizeRect.hide();return}if(this._currentColumn===-1)return;const D=h*.7;this._columnResizeRect.transformByState({left:x,top:h/2-D/2}),this._columnResizeRect.setShapeProps({size:D}),this._columnResizeRect.show()}})),this._observers.push(s==null?void 0:s.onPointerLeaveObserver.add((l,c)=>{var d,u;(d=this._rowResizeRect)==null||d.hide(),(u=this._columnResizeRect)==null||u.hide()}))}_initialHoverResize(e=0){const t=this._getSheetObject();if(t==null)return;const{scene:n}=t,o=e===0?this._rowResizeRect:this._columnResizeRect;if(o==null)return;const r=n.getEngine(),s=(r==null?void 0:r.width)||0,l=(r==null?void 0:r.height)||0;this.disposeWithMe(a.toDisposable(o.onPointerEnterObserver.add(()=>{o!=null&&(o.show(),n.setCursor(e===0?w.CURSOR_TYPE.ROW_RESIZE:w.CURSOR_TYPE.COLUMN_RESIZE))}))),this.disposeWithMe(a.toDisposable(o.onPointerLeaveObserver.add(()=>{o!=null&&(o.hide(),n.resetCursor())}))),this.disposeWithMe(a.toDisposable(o.onPointerDownObserver.add((c,d)=>{var q,z,Q,J,we,re,Se;const u=(q=this._sheetSkeletonManagerService.getCurrent())==null?void 0:q.skeleton;if(u==null)return;const h=this._getSheetObject();if(h==null)return;const{scene:m}=h,S=m.getViewport(Y.VIEW_MAIN),g=(((Q=(z=S==null?void 0:S.getScrollBar())==null?void 0:z.horizonBarRect)==null?void 0:Q.height)||0)+10,_=(((we=(J=S==null?void 0:S.getScrollBar())==null?void 0:J.verticalBarRect)==null?void 0:we.width)||0)+10,I=Xt(c.offsetX,c.offsetY,m),{scaleX:C,scaleY:b}=m.getAncestorScale();this._startOffsetX=I.x,this._startOffsetY=I.y;const M=u.getOffsetByPositionX(this._currentColumn),T=u.getOffsetByPositionY(this._currentRow),E=u.getNoMergeCellPositionByIndex(this._currentRow,this._currentColumn,C,b);let y=!1,O=0,x=0;const{columnTotalWidth:D,rowHeaderWidth:U,rowTotalHeight:N,columnHeaderHeight:B}=u,A=s>D+U?s:D+U,H=l>N+B?l:N+B,V=Math.max(C,b),F=li/V;e===0?this._resizeHelperShape=new w.Rect(so,{width:A,height:F,fill:lo,left:0,top:T-F/2}):this._resizeHelperShape=new w.Rect(so,{width:F,height:H,fill:lo,left:M-F/2,top:0});const j=((re=this._columnResizeRect)==null?void 0:re.left)||0,$=((Se=this._rowResizeRect)==null?void 0:Se.top)||0;m.addObject(this._resizeHelperShape,Ue),m.disableEvent(),this._editorBridgeService.changeVisible({visible:!1,eventType:w.DeviceInputEventType.PointerDown}),this._moveObserver=m.onPointerMoveObserver.add(qe=>{var Ti,Ei,yi,Oi,xi,Ai;const Be=m.getRelativeCoord(w.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),Te=m.getScrollXYByRelativeCoords(Be,S),de=Xt(qe.offsetX,qe.offsetY,m),{x:kt,y:Bt}=de,{scaleX:wr,scaleY:Tr}=m.getAncestorScale(),Er=Math.max(wr,Tr),Vt=li/Er;O=kt-this._startOffsetX-Vt/2,x=Bt-this._startOffsetY-Vt/2,Math.abs(e===0?x:O)>=ud&&(y=!0),e===0?(x<-(E.endY-E.startY)+2&&(x=-(E.endY-E.startY)+2),x>l-g+Te.y-E.startY&&(x=l-g+Te.y-E.startY),y&&((Ti=this._resizeHelperShape)==null||Ti.transformByState({top:T+x}),(Ei=this._rowResizeRect)==null||Ei.transformByState({top:$+x+Vt/2}),(yi=this._rowResizeRect)==null||yi.show(),m.setCursor(w.CURSOR_TYPE.ROW_RESIZE))):(O<-(E.endX-E.startX)+2&&(O=-(E.endX-E.startX)+2),O>s-_+Te.x-E.startX&&(O=s-_+Te.x-E.startX),y&&((Oi=this._resizeHelperShape)==null||Oi.transformByState({left:M+O}),(xi=this._columnResizeRect)==null||xi.transformByState({left:j+O+Vt/2}),(Ai=this._columnResizeRect)==null||Ai.show(),m.setCursor(w.CURSOR_TYPE.COLUMN_RESIZE)))}),this._upObserver=m.onPointerUpObserver.add(qe=>{var de,kt,Bt;const Be=ae(this._currentUniverService,this._renderManagerService);if(Be==null)return;this._clearObserverEvent(),(de=this._resizeHelperShape)==null||de.dispose(),this._resizeHelperShape=null;const{scene:Te}=Be;Te.enableEvent(),y&&(Te.resetCursor(),(kt=this._rowResizeRect)==null||kt.hide(),(Bt=this._columnResizeRect)==null||Bt.hide(),e===0?this._commandService.executeCommand(f.DeltaRowHeightCommand.id,{deltaY:x,anchorRow:this._currentRow}):this._commandService.executeCommand(f.DeltaColumnWidthCommand.id,{deltaX:O,anchorCol:this._currentColumn}))})}))),this.disposeWithMe(a.toDisposable(o.onDblclickObserver.add(()=>{var c;if(e===0){const d=this._getSheetObject();if(d==null)return;const{scene:u}=d;u.resetCursor(),this._commandService.executeCommand(f.SetWorksheetRowIsAutoHeightCommand.id,{anchorRow:this._currentRow}),(c=this._rowResizeRect)==null||c.hide()}})))}_clearObserverEvent(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;t.onPointerMoveObserver.remove(this._moveObserver),t.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_getSheetObject(){return ae(this._currentUniverService,this._renderManagerService)}};cn=ad([a.OnLifecycle(a.LifecycleStages.Rendered,cn),vt(0,P.Inject(exports.SheetSkeletonManagerService)),vt(1,a.IUniverInstanceService),vt(2,a.ICommandService),vt(3,w.IRenderManagerService),vt(4,pe)],cn);var ai=(i=>(i[i.ROW=0]="ROW",i[i.COLUMN=1]="COLUMN",i))(ai||{});const bt=12,hd=.4;class ao extends w.Shape{constructor(t,n,o){super(t,n);v(this,"_size",bt);v(this,"_iconRatio",hd);v(this,"_hovered",!0);v(this,"_hasPrevious",!0);v(this,"_hasNext",!0);v(this,"_unhideType");n&&this.setShapeProps(n),this.onPointerEnterObserver.add(()=>this.setShapeProps({hovered:!0})),this.onPointerLeaveObserver.add(()=>this.setShapeProps({hovered:!1})),this.onPointerDownObserver.add(()=>o==null?void 0:o())}setShapeProps(t){t.type!==void 0&&(this._unhideType=t.type),t.hovered!==void 0&&(this._hovered=t.hovered),t.hasPrevious!==void 0&&(this._hasPrevious=t.hasPrevious),t.hasNext!==void 0&&(this._hasNext=t.hasNext),this.transformByState({width:this._size*(this._unhideType===1?2:1),height:this._size*(this._unhideType===0?2:1)})}_draw(t){this._unhideType===0?this._drawOnRow(t):this._drawOnCol(t)}_drawOnRow(t){this._hovered&&(!this._hasNext||!this._hasPrevious?w.Rect.drawWith(t,{width:this._size,height:this._size,stroke:ye,fill:jt}):w.Rect.drawWith(t,{width:this._size,height:2*this._size,stroke:ye,fill:jt}));const n=this._size*.5*this._iconRatio,o=Math.PI/3,r=n*Math.cos(o),s=n*Math.sin(o);if(this._hasPrevious&&w.RegularPolygon.drawWith(t,{pointsGroup:[[{x:this._size/2,y:this._size/2-s},{x:this._size/2-s,y:this._size/2+r},{x:this._size/2+s,y:this._size/2+r}]],fill:ye}),this._hasNext){const l=this._hasPrevious?3:1;w.RegularPolygon.drawWith(t,{pointsGroup:[[{x:this._size/2,y:this._size*l/2+s},{x:this._size/2-s,y:this._size*l/2-r},{x:this._size/2+s,y:this._size*l/2-r}]],fill:ye})}}_drawOnCol(t){this._hovered&&(!this._hasNext||!this._hasPrevious?w.Rect.drawWith(t,{width:this._size,height:this._size,stroke:ye,fill:jt}):w.Rect.drawWith(t,{width:2*this._size,height:this._size,stroke:ye,fill:jt}));const n=this._size*.5*this._iconRatio,o=Math.PI/3,r=n*Math.cos(o),s=n*Math.sin(o);if(this._hasPrevious&&w.RegularPolygon.drawWith(t,{pointsGroup:[[{x:-r+this._size/2,y:this._size/2},{x:this._size/2+s,y:this._size/2-s},{x:this._size/2+s,y:this._size/2+s}]],fill:ye}),this._hasNext){const l=this._hasPrevious?3:1;w.RegularPolygon.drawWith(t,{pointsGroup:[[{x:r+this._size*l/2,y:this._size/2},{x:-s+this._size*l/2,y:this._size/2-s},{x:-s+this._size*l/2,y:this._size/2+s}]],fill:ye})}}}var md=Object.defineProperty,Sd=Object.getOwnPropertyDescriptor,_d=(i,e,t,n)=>{for(var o=n>1?void 0:n?Sd(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&md(e,t,o),o},Wt=(i,e)=>(t,n)=>e(t,n,i);const co="__SpreadsheetHeaderUnhideSHAPEControllerShape__",gd=[f.SetRowHiddenMutation.id,f.SetRowVisibleMutation.id,f.SetColHiddenMutation.id,f.SetColVisibleMutation.id];let dn=class extends a.RxDisposable{constructor(e,t,n,o){super();v(this,"_shapes",new Map);this._sheetSkeletonManagerService=e,this._cmdSrv=t,this._univerInstanceService=n,this._rendererManagerService=o,this._init()}dispose(){super.dispose()}_init(){if(!this._getSheetObject())return;const t=this._univerInstanceService.getCurrentUniverSheetInstance(),n=t.getActiveSheet();n&&this._initForWorksheet(t,n),this._sheetSkeletonManagerService.currentSkeleton$.pipe(k.takeUntil(this.dispose$)).subscribe(o=>{if(o){const r=this._univerInstanceService.getUniverSheetInstance(o.unitId),s=r.getSheetBySheetId(o.sheetId);this._updateWorksheet(r,s)}}),this.disposeWithMe(this._cmdSrv.onCommandExecuted(o=>{if(!gd.includes(o.id)||!o.params||!o.params.unitId||!o.params.subUnitId)return;const r=this._univerInstanceService.getUniverSheetInstance(o.params.unitId),s=r==null?void 0:r.getSheetBySheetId(o.params.subUnitId);s&&this._updateWorksheet(r,s)}))}_initForWorksheet(e,t){var m;const n=(m=this._sheetSkeletonManagerService.getCurrent())==null?void 0:m.skeleton;if(!n)return;const o=t.getHiddenRows(),r=t.getHiddenCols(),s=this._getSheetObject();if(!s)return;const{scene:l}=s,c=t.getRowCount(),d=o.map(S=>{const{startRow:g,endRow:_}=S,I=ii(g,0,l,n),C=g!==0,b=_!==c-1;return new ao(co,{type:ai.ROW,hovered:!1,hasPrevious:C,hasNext:b,top:I.startY-(C?bt:0),left:I.startX-bt},()=>this._cmdSrv.executeCommand(f.SetSpecificRowsVisibleCommand.id,{unitId:e.getUnitId(),subUnitId:t.getSheetId(),ranges:[S]}))}),u=t.getColumnCount(),h=r.map(S=>{const{startColumn:g,endColumn:_}=S,I=ii(0,g,l,n),C=g!==0,b=_!==u-1;return new ao(co,{type:ai.COLUMN,hovered:!1,hasPrevious:C,hasNext:b,left:I.startX-(C?bt:0),top:20-bt},()=>this._cmdSrv.executeCommand(f.SetSpecificColsVisibleCommand.id,{unitId:e.getUnitId(),subUnitId:t.getSheetId(),ranges:[S]}))});l.addObjects(h,ji),l.addObjects(d,ji),this._shapes.set(a.getWorksheetUID(e,t),{cols:h,rows:d})}_updateWorksheet(e,t){const n=this._shapes.get(a.getWorksheetUID(e,t));n==null||n.cols.forEach(o=>o.dispose()),n==null||n.rows.forEach(o=>o.dispose()),this._initForWorksheet(e,t)}_getSheetObject(){return ae(this._univerInstanceService,this._rendererManagerService)}};dn=_d([a.OnLifecycle(a.LifecycleStages.Rendered,dn),Wt(0,P.Inject(exports.SheetSkeletonManagerService)),Wt(1,a.ICommandService),Wt(2,a.IUniverInstanceService),Wt(3,w.IRenderManagerService)],dn);var fd=Object.defineProperty,pd=Object.getOwnPropertyDescriptor,vd=(i,e,t,n)=>{for(var o=n>1?void 0:n?pd(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&fd(e,t,o),o},zn=(i,e)=>(t,n)=>e(t,n,i);let un=class extends a.Disposable{constructor(i,e,t){super(),this._markSelectionService=i,this._commandService=e,this._sheetSkeletonManagerService=t,this._initListeners()}_initListeners(){this._addRemoveListener(),this._addRefreshListener()}_addRemoveListener(){const i=[Re.id,f.SetRangeValuesMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{i.includes(e.id)&&this._markSelectionService.removeAllShapes()}))}_addRefreshListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{i&&this._markSelectionService.refreshShapes()})))}};un=vd([a.OnLifecycle(a.LifecycleStages.Steady,un),zn(0,P.Inject(At)),zn(1,a.ICommandService),zn(2,P.Inject(exports.SheetSkeletonManagerService))],un);var Cd=Object.defineProperty,Id=Object.getOwnPropertyDescriptor,Rd=(i,e,t,n)=>{for(var o=n>1?void 0:n?Id(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Cd(e,t,o),o},Xn=(i,e)=>(t,n)=>e(t,n,i);let hn=class extends a.Disposable{constructor(e,t,n){super();v(this,"_initialize",()=>{const e=new a.DisposableCollection;this.disposeWithMe(a.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(()=>{e.dispose();const t=this._selectionManagerService.getCurrent();if((t==null?void 0:t.pluginName)!==f.NORMAL_SELECTION_PLUGIN_NAME)return;this._selectionRenderService.getCurrentControls().forEach(o=>{e.add(a.toDisposable(o.selectionMoved$.subscribe(r=>{if(!r)return;const s=o.model.getRange(),l={startRow:s.startRow,startColumn:s.startColumn,endRow:s.endRow,endColumn:s.endColumn,rangeType:s.rangeType},c={startRow:r.startRow,startColumn:r.startColumn,endRow:r.endRow,endColumn:r.endColumn,rangeType:s.rangeType};if(l.startRow===c.startRow&&l.startColumn===c.startColumn||c.startRow<0||c.startColumn<0)return;const d={fromRange:l,toRange:c};this._commandService.executeCommand(f.MoveRangeCommand.id,d)})))})})))});this._selectionRenderService=e,this._selectionManagerService=t,this._commandService=n,this._initialize()}};hn=Rd([a.OnLifecycle(a.LifecycleStages.Steady,hn),Xn(0,P.Inject(ce)),Xn(1,P.Inject(f.SelectionManagerService)),Xn(2,P.Inject(a.ICommandService))],hn);var bd=Object.defineProperty,Md=Object.getOwnPropertyDescriptor,wd=(i,e,t,n)=>{for(var o=n>1?void 0:n?Md(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&bd(e,t,o),o},et=(i,e)=>(t,n)=>e(t,n,i);let wt=class extends a.Disposable{constructor(i,e,t,n,o,r){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._selectionManagerService=o,this._scrollManagerService=r,this._initialize()}dispose(){super.dispose()}_initialize(){this._scrollEventBinding(),this._scrollSubscribeBinding(),this._skeletonListener()}_scrollEventBinding(){var t;const i=(t=this._getSheetObject())==null?void 0:t.scene;if(i==null)return;const e=i.getViewport(Y.VIEW_MAIN);this.disposeWithMe(a.toDisposable(e==null?void 0:e.onScrollAfterObserver.add(n=>{var m;const o=(m=this._sheetSkeletonManagerService.getCurrent())==null?void 0:m.skeleton;if(o==null||n.isTrigger===!1)return;const r=this._getSheetObject();if(o==null||r==null)return;const{actualScrollX:s=0,actualScrollY:l=0}=n,{row:c,column:d,rowOffset:u,columnOffset:h}=o.getDecomposedOffset(s,l);this._scrollManagerService.addOrReplaceNoRefresh({sheetViewStartRow:c,sheetViewStartColumn:d,offsetX:h,offsetY:u})}))),this.disposeWithMe(a.toDisposable(e==null?void 0:e.onScrollByBarObserver.add(n=>{var m;const o=(m=this._sheetSkeletonManagerService.getCurrent())==null?void 0:m.skeleton;if(o==null||n.isTrigger===!1)return;const r=this._getSheetObject();if(o==null||r==null)return;const{actualScrollX:s=0,actualScrollY:l=0}=n,{row:c,column:d,rowOffset:u,columnOffset:h}=o.getDecomposedOffset(s,l);this._commandService.executeCommand(Ye.id,{sheetViewStartRow:c,sheetViewStartColumn:d,offsetX:h,offsetY:u})})))}scrollToVisible(i){var U,N,B;let e,t;const n=this._selectionManagerService.getLast();if(n==null)return;const{actualRow:o,actualColumn:r}=n.primary,{rowHeightAccumulation:s,columnWidthAccumulation:l}=((U=this._sheetSkeletonManagerService.getCurrent())==null?void 0:U.skeleton)??{};if(s==null||l==null)return;const c=(N=this._getSheetObject())==null?void 0:N.scene;if(c==null)return;const d=c.getViewport(Y.VIEW_MAIN);if(d==null||this._getSheetObject()==null)return;const h=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet(),{startColumn:m,startRow:S,ySplit:g,xSplit:_}=h.getFreeze(),I=d.getBounding(),C=(B=this._sheetSkeletonManagerService.getCurrent())==null?void 0:B.skeleton;if(C==null)return;const{startRow:b,startColumn:M,endRow:T,endColumn:E}=C.getRowColumnSegment(I);if(o>=S&&r>=m-_&&(o<=b&&(e=o),o>=T)){const A=s[o]-d.height;for(let H=b;H<=o;H++)if(s[H]>=A){e=H+1;break}}if(r>=m&&o>=S-g&&(r<=M&&(t=r),r>=E)){const A=l[r]-d.width;for(let H=M;H<=r;H++)if(l[H]>=A){t=H+1;break}}if(e===void 0&&t===void 0)return;const{sheetViewStartColumn:y,sheetViewStartRow:O,offsetX:x,offsetY:D}=this._scrollManagerService.getCurrentScroll()||{};this._commandService.executeCommand(Ye.id,{sheetViewStartRow:e??O,sheetViewStartColumn:t??y,offsetX:t===void 0?x:0,offsetY:e===void 0?D:0})}_scrollSubscribeBinding(){this.disposeWithMe(a.toDisposable(this._scrollManagerService.scrollInfo$.subscribe(i=>{var I;const e=(I=this._sheetSkeletonManagerService.getCurrent())==null?void 0:I.skeleton,t=this._getSheetObject();if(e==null||t==null)return;const n=t.scene,{scaleX:o,scaleY:r}=t.scene.getAncestorScale(),s=n.getViewport(Y.VIEW_MAIN);if(s==null)return;if(i==null){s.scrollTo({x:0,y:0});return}const{sheetViewStartRow:l,sheetViewStartColumn:c,offsetX:d,offsetY:u}=i,{startX:h,startY:m}=e.getCellByIndexWithNoHeader(l,c,o,r),S=h+d,g=m+u,_=s.getBarScroll(S,g);s.scrollTo(_)})))}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{unitId:e,sheetId:t}=i;this._renderManagerService.getRenderById(e)!=null&&(this._updateSceneSize(i),this._scrollManagerService.setCurrentScroll({unitId:e,sheetId:t}))})))}_updateSceneSize(i){var c;if(i==null)return;const{skeleton:e,unitId:t}=i,n=(c=this._renderManagerService.getRenderById(t))==null?void 0:c.scene;if(e==null||n==null)return;const{rowTotalHeight:o,columnTotalWidth:r,rowHeaderWidthAndMarginLeft:s,columnHeaderHeightAndMarginTop:l}=e;n==null||n.transformByState({width:s+r,height:l+o})}_getSheetObject(){return ae(this._currentUniverService,this._renderManagerService)}};wt=wd([a.OnLifecycle(a.LifecycleStages.Rendered,wt),et(0,P.Inject(exports.SheetSkeletonManagerService)),et(1,a.IUniverInstanceService),et(2,a.ICommandService),et(3,w.IRenderManagerService),et(4,P.Inject(f.SelectionManagerService)),et(5,P.Inject(ke))],wt);var Td=Object.defineProperty,Ed=Object.getOwnPropertyDescriptor,yd=(i,e,t,n)=>{for(var o=n>1?void 0:n?Ed(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Td(e,t,o),o},uo=(i,e)=>(t,n)=>e(t,n,i);const Od=[me.id,Ke.id];let mn=class extends a.Disposable{constructor(i,e){super(),this._commandService=i,this._scrollController=e,this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(Od.includes(t.id)){const n=t.params;this._scrollController.scrollToVisible(n.direction)}}))}};mn=yd([a.OnLifecycle(a.LifecycleStages.Rendered,mn),uo(0,a.ICommandService),uo(1,P.Inject(wt))],mn);var xd=Object.defineProperty,Ad=Object.getOwnPropertyDescriptor,Hd=(i,e,t,n)=>{for(var o=n>1?void 0:n?Ad(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&xd(e,t,o),o},We=(i,e)=>(t,n)=>e(t,n,i);let Sn=class extends a.Disposable{constructor(i,e,t,n,o,r,s){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._selectionRenderService=o,this._selectionManagerService=r,this._themeService=s,this._initialize()}_initialize(){const i=this._currentUniverService.getCurrentUniverSheetInstance(),e=i.getActiveSheet(),t=this._getSheetObject();if(t==null)return;this._initViewMainListener(t),this._initRowHeader(t),this._initColumnHeader(t),this._initLeftTop(t),this._initSelectionChangeListener(),this._initThemeChangeListener(),this._initSkeletonChangeListener(),this._initCommandListener(),this._initUserActionSyncListener();const n=i.getUnitId(),o=e.getSheetId();this._selectionManagerService.setCurrentSelection({pluginName:f.NORMAL_SELECTION_PLUGIN_NAME,unitId:n,sheetId:o})}_initViewMainListener(i){const{spreadsheet:e,scene:t}=i,n=t.getViewport(Y.VIEW_MAIN);this.disposeWithMe(a.toDisposable(e==null?void 0:e.onPointerDownObserver.add((o,r)=>{this._selectionRenderService.enableDetectMergedCell(),this._selectionRenderService.eventTrigger(o,e.zIndex+1,a.RANGE_TYPE.NORMAL,n),o.button!==2&&r.stopPropagation()})))}_initThemeChangeListener(){this.disposeWithMe(a.toDisposable(this._themeService.currentTheme$.subscribe(()=>{this._selectionRenderService.resetStyle();const i=this._selectionManagerService.getSelections(),e=this._selectionManagerService.getCurrent();i==null||(e==null?void 0:e.pluginName)!==f.NORMAL_SELECTION_PLUGIN_NAME||this._refreshSelection(i)})))}_refreshSelection(i){this._selectionRenderService.reset();for(const e of i){if(e==null)continue;const t=this._selectionRenderService.convertSelectionRangeToData(e);t.style=f.getNormalSelectionStyle(this._themeService),this._selectionRenderService.addControlToCurrentByRangeData(t)}}_initRowHeader(i){const{spreadsheetRowHeader:e,spreadsheet:t,scene:n}=i,o=n.getViewport(Y.VIEW_MAIN);this.disposeWithMe(a.toDisposable(e==null?void 0:e.onPointerDownObserver.add((r,s)=>{this._selectionRenderService.disableDetectMergedCell(),this._selectionRenderService.eventTrigger(r,((t==null?void 0:t.zIndex)||1)+1,a.RANGE_TYPE.ROW,o,w.ScrollTimerType.Y),r.button!==2&&s.stopPropagation()})))}_initColumnHeader(i){const{spreadsheetColumnHeader:e,spreadsheet:t,scene:n}=i,o=n.getViewport(Y.VIEW_MAIN);this.disposeWithMe(a.toDisposable(e==null?void 0:e.onPointerDownObserver.add((r,s)=>{this._selectionRenderService.disableDetectMergedCell(),this._selectionRenderService.eventTrigger(r,((t==null?void 0:t.zIndex)||1)+1,a.RANGE_TYPE.COLUMN,o,w.ScrollTimerType.X),r.button!==2&&s.stopPropagation()})))}_initLeftTop(i){const{spreadsheetLeftTopPlaceholder:e}=i;this.disposeWithMe(a.toDisposable(e==null?void 0:e.onPointerDownObserver.add((t,n)=>{var r;const o=(r=this._sheetSkeletonManagerService.getCurrent())==null?void 0:r.skeleton;o!=null&&(this._selectionManagerService.replace([this._getAllRange(o)]),t.button!==2&&n.stopPropagation())})))}_initSelectionChangeListener(){this.disposeWithMe(a.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(i=>{if(this._selectionRenderService.reset(),i!=null)for(const e of i){if(e==null)continue;const t=this._selectionRenderService.convertSelectionRangeToData(e);this._selectionRenderService.addControlToCurrentByRangeData(t)}})))}_initUserActionSyncListener(){this._selectionRenderService.selectionMoveStart$.subscribe(i=>{this._move(i,f.SelectionMoveType.MOVE_START)}),this._selectionRenderService.selectionMoving$.subscribe(i=>{this._move(i,f.SelectionMoveType.MOVING)}),this._selectionRenderService.selectionMoveEnd$.subscribe(i=>{this._move(i,f.SelectionMoveType.MOVE_END)})}_move(i,e){const t=this._currentUniverService.getCurrentUniverSheetInstance(),n=t.getUnitId(),o=t.getActiveSheet().getSheetId(),r=this._selectionManagerService.getCurrent();i==null||i.length===0||this._commandService.executeCommand(f.SetSelectionsOperation.id,{unitId:n,subUnitId:o,type:e,pluginName:(r==null?void 0:r.pluginName)||f.NORMAL_SELECTION_PLUGIN_NAME,selections:i.map(s=>f.convertSelectionDataToRange(s))})}_getSheetObject(){return ae(this._currentUniverService,this._renderManagerService)}_initCommandListener(){const i=[xe.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(i.includes(e.id)){const t=this._currentUniverService.getCurrentUniverSheetInstance(),n=t.getActiveSheet(),o=e.params,{unitId:r,subUnitId:s}=o;if(!(r===t.getUnitId()&&s===n.getSheetId()))return;this._selectionManagerService.refreshSelection()}}))}_initSkeletonChangeListener(){this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{unitId:e,sheetId:t,skeleton:n}=i,o=this._renderManagerService.getRenderById(e);if(o==null)return;const{scene:r}=o,s=r.getViewport(Y.VIEW_MAIN);this._selectionRenderService.changeRuntime(n,r,s);const l=this._selectionManagerService.getCurrent(),c=(l==null?void 0:l.pluginName)||f.NORMAL_SELECTION_PLUGIN_NAME;if((l==null?void 0:l.unitId)===e&&l.sheetId===t){const d=this._selectionManagerService.getSelections();d!=null&&this._refreshSelection(d)}else this._selectionManagerService.setCurrentSelection({pluginName:c,unitId:e,sheetId:t});c===f.NORMAL_SELECTION_PLUGIN_NAME&&this._selectionManagerService.getLast()==null&&this._selectionManagerService.add([this._getZeroRange(n)])})}_getAllRange(i){return{range:{startRow:0,startColumn:0,endRow:i.getRowCount()-1,endColumn:i.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL},primary:this._getZeroRange(i).primary,style:null}}_getZeroRange(i){const e=i.mergeData;return f.transformCellDataToSelectionData(0,0,e)||{range:{startRow:0,startColumn:0,endRow:0,endColumn:0},primary:{actualRow:0,actualColumn:0,startRow:0,startColumn:0,endRow:0,endColumn:0,isMerged:!1,isMergedMainCell:!1},style:null}}};Sn=Hd([a.OnLifecycle(a.LifecycleStages.Rendered,Sn),We(0,P.Inject(exports.SheetSkeletonManagerService)),We(1,a.IUniverInstanceService),We(2,a.ICommandService),We(3,w.IRenderManagerService),We(4,ce),We(5,P.Inject(f.SelectionManagerService)),We(6,P.Inject(a.ThemeService))],Sn);var Dd=Object.defineProperty,Nd=Object.getOwnPropertyDescriptor,Pd=(i,e,t,n)=>{for(var o=n>1?void 0:n?Nd(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Dd(e,t,o),o},tt=(i,e)=>(t,n)=>e(t,n,i);let _n=class extends a.Disposable{constructor(i,e,t,n,o,r){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._renderManagerService=t,this._commandService=n,this._selectionRenderService=o,this._selectionManagerService=r,this._initialize(),this._commandExecutedListener()}dispose(){super.dispose()}_initialize(){this._initialRenderRefresh()}_initialRenderRefresh(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{skeleton:e,unitId:t,sheetId:n}=i,o=this._currentUniverService.getUniverSheetInstance(t),r=o==null?void 0:o.getSheetBySheetId(n);if(o==null||r==null)return;const s=this._renderManagerService.getRenderById(t);if(s==null)return;const{mainComponent:l,components:c,scene:d}=s,u=l,h=c.get(oe.ROW),m=c.get(oe.COLUMN),S=c.get(oe.LEFT_TOP),{rowHeaderWidth:g,columnHeaderHeight:_}=e;u==null||u.updateSkeleton(e),h==null||h.updateSkeleton(e),m==null||m.updateSkeleton(e),S==null||S.transformByState({width:g,height:_})})))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((i,e)=>{var o,r;const t=this._currentUniverService.getCurrentUniverSheetInstance(),n=t.getUnitId();if(f.COMMAND_LISTENER_SKELETON_CHANGE.includes(i.id)){const s=t.getActiveSheet(),l=s.getSheetId(),c=i.params,{unitId:d,subUnitId:u}=c;if(!(d===t.getUnitId()&&u===s.getSheetId()))return;i.id!==f.SetWorksheetActiveOperation.id&&this._sheetSkeletonManagerService.makeDirty({unitId:d,sheetId:l,commandId:i.id},!0),this._sheetSkeletonManagerService.setCurrent({unitId:d,sheetId:l,commandId:i.id})}else f.COMMAND_LISTENER_VALUE_CHANGE.includes(i.id)&&this._sheetSkeletonManagerService.reCalculate();i.type===a.CommandType.MUTATION&&((r=(o=this._renderManagerService.getRenderById(n))==null?void 0:o.mainComponent)==null||r.makeDirty())}))}};_n=Pd([a.OnLifecycle(a.LifecycleStages.Ready,_n),tt(0,P.Inject(exports.SheetSkeletonManagerService)),tt(1,a.IUniverInstanceService),tt(2,w.IRenderManagerService),tt(3,a.ICommandService),tt(4,ce),tt(5,P.Inject(f.SelectionManagerService))],_n);const Ae={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge",handler:async(i,e)=>{const t=i.get(a.ICommandService),n=i.get(a.IUndoRedoService),o=i.get(a.IUniverInstanceService),r=i.get(R.IConfirmService),s=i.get(a.LocaleService),l=e.unitId,c=e.subUnitId,d=e.selections,u=f.getAddMergeMutationRangeByType(d,e.value),h=o.getUniverSheetInstance(l).getSheetBySheetId(c),m=[],S=[],g=Jo(h,u);if(g&&!await r.confirm({id:"merge.confirm.add-worksheet-merge",title:{title:"merge.confirm.title"},cancelText:s.t("merge.confirm.cancel"),confirmText:s.t("merge.confirm.confirm")}))return!1;const _={unitId:l,subUnitId:c,ranges:u},I={unitId:l,subUnitId:c,ranges:u};m.push({id:f.RemoveWorksheetMergeMutation.id,params:_}),m.push({id:f.AddWorksheetMergeMutation.id,params:I});const C=f.RemoveMergeUndoMutationFactory(i,_),b=f.AddMergeUndoMutationFactory(i,I);if(S.push({id:f.RemoveWorksheetMergeMutation.id,params:b}),S.push({id:f.AddWorksheetMergeMutation.id,params:C}),g){const T=Qo(i,l,h,u);m.unshift(...T.redos),S.push(...T.undos)}return a.sequenceExecute(m,t).result?(n.pushUndoRedo({unitID:l,undoMutations:S,redoMutations:m}),!0):!1}},gr={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-all",handler:async i=>{const e=i.get(a.ICommandService),n=i.get(f.SelectionManagerService).getSelectionRanges();if(!(n!=null&&n.length))return!1;const r=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance();if(!r)return!1;const s=r.getActiveSheet();if(!s)return!1;const l=r.getUnitId(),c=s.getSheetId();return e.executeCommand(Ae.id,{selections:n,unitId:l,subUnitId:c})}},fr={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-vertical",handler:async i=>{const e=i.get(a.ICommandService),n=i.get(f.SelectionManagerService).getSelectionRanges();if(!(n!=null&&n.length))return!1;const r=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance();if(!r)return!1;const s=r.getActiveSheet();if(!s)return!1;const l=r.getUnitId(),c=s.getSheetId();return e.executeCommand(Ae.id,{value:a.Dimension.COLUMNS,selections:n,unitId:l,subUnitId:c})}},pr={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-horizontal",handler:async i=>{const e=i.get(a.ICommandService),n=i.get(f.SelectionManagerService).getSelectionRanges();if(!(n!=null&&n.length))return!1;const r=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance();if(!r)return!1;const s=r.getActiveSheet();if(!s)return!1;const l=r.getUnitId(),c=s.getSheetId();return e.executeCommand(Ae.id,{value:a.Dimension.ROWS,selections:n,unitId:l,subUnitId:c})}},vr={id:"sheet.command.refill",type:a.CommandType.COMMAND,handler:async(i,e)=>(i.get(Dt).setApplyType(e.type),!0)},Cr={id:"sheet.command.remove-sheet-confirm",type:a.CommandType.COMMAND,handler:async(i,e)=>{const{subUnitId:t}=e,n=i.get(R.IConfirmService),o=i.get(a.ICommandService),r=i.get(a.LocaleService);return await n.confirm({id:"merge.confirm.add-worksheet-merge",title:{title:r.t("sheetConfig.deleteSheet")},children:{title:r.t("sheetConfig.deleteSheetContent")},cancelText:r.t("button.cancel"),confirmText:r.t("button.confirm")})?(await o.executeCommand(f.RemoveSheetCommand.id,{subUnitId:t}),!0):!1}},Nn={id:"sheet.command.change-zoom-ratio",type:a.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const{delta:t,reset:n}=e,o=i.get(a.IUniverInstanceService).getCurrentUniverSheetInstance(),r=o.getActiveSheet(),s=o.getUnitId(),l=r.getSheetId();let c=n?100:Math.round((r.getConfig().zoomRatio+t)*100);c=Math.max(Qn[0],c),c=Math.min(Qn[1],c);const d=c/100;return i.get(a.ICommandService).executeCommand(xe.id,{unitId:s,subUnitId:l,zoomRatio:d})}},Ri={id:"sheet.command.set-zoom-ratio",type:a.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const{unitId:t,subUnitId:n,zoomRatio:o}=e;return i.get(a.ICommandService).executeCommand(xe.id,{unitId:t,subUnitId:n,zoomRatio:o})}},mt=P.createIdentifier("univer.sheetbar-service");class Ld extends a.Disposable{constructor(){super();v(this,"renameId$");v(this,"removeId$");v(this,"scroll$");v(this,"scrollX$");v(this,"addSheet$");v(this,"_renameId$");v(this,"_removeId$");v(this,"_scroll$");v(this,"_scrollX$");v(this,"_addSheet$");v(this,"_currentHandler",null);this._renameId$=new k.Subject,this.renameId$=this._renameId$.asObservable(),this._removeId$=new k.Subject,this.removeId$=this._removeId$.asObservable(),this._scroll$=new k.Subject,this.scroll$=this._scroll$.asObservable(),this._scrollX$=new k.Subject,this.scrollX$=this._scrollX$.asObservable(),this._addSheet$=new k.Subject,this.addSheet$=this._addSheet$.asObservable()}setRenameId(t){this._renameId$.next(t)}setRemoveId(t){this._removeId$.next(t)}setScroll(t){this._scroll$.next(t)}setScrollX(t){this._scrollX$.next(t)}setAddSheet(t){this._addSheet$.next(t)}triggerSheetBarMenu(){var t;(t=this._currentHandler)==null||t.handleSheetBarMenu()}registerSheetBarMenuHandler(t){if(this._currentHandler)throw new Error("There is already a context menu handler!");return this._currentHandler=t,a.toDisposable(()=>{this._currentHandler=null})}}const Ir={id:"ui-sheet.command.show-menu-list",type:a.CommandType.OPERATION,handler:async i=>(i.get(mt).triggerSheetBarMenu(),!0)},Rr={id:"sheet.operation.rename-sheet",type:a.CommandType.OPERATION,handler:async(i,e)=>{const t=i.get(mt);return e&&t.setRenameId(e.subUnitId),!0}},Ud=()=>p.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M0.98999 1.08218H-0.0100098V0.0821838H0.98999V1.08218Z",fill:"black"}),p.jsx("path",{d:"M5.78992 1.08218H2.78992V0.0821838H5.78992V1.08218Z",fill:"black"}),p.jsx("path",{d:"M7.58984 1.08218H8.58984V0.0821838H7.58984V1.08218Z",fill:"black"}),p.jsx("path",{d:"M14.9152 1.08218H13.9152V0.0821838H14.9152V1.08218Z",fill:"black"}),p.jsx("path",{d:"M16.7151 1.08218H19.7151V0.0821838H16.7151V1.08218Z",fill:"black"}),p.jsx("path",{d:"M22.515 1.08218H21.515V0.0821838H22.515V1.08218Z",fill:"black"}),p.jsx("path",{d:"M27.8405 1.08218H28.8405V0.0821838H27.8405V1.08218Z",fill:"black"}),p.jsx("path",{d:"M33.6404 1.08218H30.6404V0.0821838H33.6404V1.08218Z",fill:"black"}),p.jsx("path",{d:"M35.4403 1.08218H36.4403V0.0821838H35.4403V1.08218Z",fill:"black"}),p.jsx("path",{d:"M42.7657 1.08218H41.7657V0.0821838H42.7657V1.08218Z",fill:"black"}),p.jsx("path",{d:"M44.5657 1.08218H47.5657V0.0821838H44.5657V1.08218Z",fill:"black"}),p.jsx("path",{d:"M50.3656 1.08218H49.3656V0.0821838H50.3656V1.08218Z",fill:"black"}),p.jsx("path",{d:"M55.691 1.08218H56.691V0.0821838H55.691V1.08218Z",fill:"black"}),p.jsx("path",{d:"M61.491 1.08218H58.491V0.0821838H61.491V1.08218Z",fill:"black"}),p.jsx("path",{d:"M63.2909 1.08218H64.2909V0.0821838H63.2909V1.08218Z",fill:"black"}),p.jsx("path",{d:"M70.6163 1.08218H69.6163V0.0821838H70.6163V1.08218Z",fill:"black"}),p.jsx("path",{d:"M72.4163 1.08218H75.4163V0.0821838H72.4163V1.08218Z",fill:"black"}),p.jsx("path",{d:"M78.2162 1.08218H77.2162V0.0821838H78.2162V1.08218Z",fill:"black"}),p.jsx("path",{d:"M83.5416 1.08218H84.5416V0.0821838H83.5416V1.08218Z",fill:"black"}),p.jsx("path",{d:"M89.3416 1.08218H86.3416V0.0821838H89.3416V1.08218Z",fill:"black"}),p.jsx("path",{d:"M91.1415 1.08218H92.1415V0.0821838H91.1415V1.08218Z",fill:"black"}),p.jsx("path",{d:"M98.4669 1.08218H97.4669V0.0821838H98.4669V1.08218Z",fill:"black"}),p.jsx("path",{d:"M100.267 1.08218H103.267V0.0821838H100.267V1.08218Z",fill:"black"}),p.jsx("path",{d:"M106.067 1.08218H105.067V0.0821838H106.067V1.08218Z",fill:"black"}),p.jsx("path",{d:"M111.392 1.08218H112.392V0.0821838H111.392V1.08218Z",fill:"black"}),p.jsx("path",{d:"M117.192 1.08218H114.192V0.0821838H117.192V1.08218Z",fill:"black"}),p.jsx("path",{d:"M118.992 1.08218H119.992V0.0821838H118.992V1.08218Z",fill:"black"})]}),kd=()=>p.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.0100098 1.15771H0.98999V0.157715H-0.0100098V1.15771Z",fill:"black"}),p.jsx("path",{d:"M2.78992 1.15771H5.78992V0.157715H2.78992V1.15771Z",fill:"black"}),p.jsx("path",{d:"M8.58984 1.15771H7.58984V0.157715H8.58984V1.15771Z",fill:"black"}),p.jsx("path",{d:"M10.3899 1.15771H11.3899V0.157715H10.3899V1.15771Z",fill:"black"}),p.jsx("path",{d:"M19.0903 1.15771H18.0903V0.157715H19.0903V1.15771Z",fill:"black"}),p.jsx("path",{d:"M20.8903 1.15771H23.8903V0.157715H20.8903V1.15771Z",fill:"black"}),p.jsx("path",{d:"M26.6902 1.15771H25.6902V0.157715H26.6902V1.15771Z",fill:"black"}),p.jsx("path",{d:"M28.4902 1.15771H29.4902V0.157715H28.4902V1.15771Z",fill:"black"}),p.jsx("path",{d:"M37.1907 1.15771H36.1907V0.157715H37.1907V1.15771Z",fill:"black"}),p.jsx("path",{d:"M38.9906 1.15771H41.9906V0.157715H38.9906V1.15771Z",fill:"black"}),p.jsx("path",{d:"M44.7905 1.15771H43.7905V0.157715H44.7905V1.15771Z",fill:"black"}),p.jsx("path",{d:"M46.5906 1.15771H47.5906V0.157715H46.5906V1.15771Z",fill:"black"}),p.jsx("path",{d:"M55.291 1.15771H54.291V0.157715H55.291V1.15771Z",fill:"black"}),p.jsx("path",{d:"M57.0909 1.15771H60.0909V0.157715H57.0909V1.15771Z",fill:"black"}),p.jsx("path",{d:"M62.8909 1.15771H61.8909V0.157715H62.8909V1.15771Z",fill:"black"}),p.jsx("path",{d:"M64.6909 1.15771H65.6909V0.157715H64.6909V1.15771Z",fill:"black"}),p.jsx("path",{d:"M73.3914 1.15771H72.3914V0.157715H73.3914V1.15771Z",fill:"black"}),p.jsx("path",{d:"M75.1913 1.15771H78.1913V0.157715H75.1913V1.15771Z",fill:"black"}),p.jsx("path",{d:"M80.9912 1.15771H79.9912V0.157715H80.9912V1.15771Z",fill:"black"}),p.jsx("path",{d:"M82.7913 1.15771H83.7913V0.157715H82.7913V1.15771Z",fill:"black"}),p.jsx("path",{d:"M91.4917 1.15771H90.4917V0.157715H91.4917V1.15771Z",fill:"black"}),p.jsx("path",{d:"M93.2916 1.15771H96.2916V0.157715H93.2916V1.15771Z",fill:"black"}),p.jsx("path",{d:"M99.0916 1.15771H98.0916V0.157715H99.0916V1.15771Z",fill:"black"}),p.jsx("path",{d:"M100.892 1.15771H101.892V0.157715H100.892V1.15771Z",fill:"black"}),p.jsx("path",{d:"M109.592 1.15771H108.592V0.157715H109.592V1.15771Z",fill:"black"}),p.jsx("path",{d:"M111.392 1.15771H114.392V0.157715H111.392V1.15771Z",fill:"black"}),p.jsx("path",{d:"M117.192 1.15771H116.192V0.157715H117.192V1.15771Z",fill:"black"}),p.jsx("path",{d:"M118.992 1.15771H119.992V0.157715H118.992V1.15771Z",fill:"black"})]}),Bd=()=>p.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.00842285 1.22449H2.99158V0.224487H-0.00842285V1.22449Z",fill:"black"}),p.jsx("path",{d:"M6.14941 1.22449H9.14941V0.224487H6.14941V1.22449Z",fill:"black"}),p.jsx("path",{d:"M15.3073 1.22449H12.3073V0.224487H15.3073V1.22449Z",fill:"black"}),p.jsx("path",{d:"M18.4651 1.22449H21.4651V0.224487H18.4651V1.22449Z",fill:"black"}),p.jsx("path",{d:"M27.6229 1.22449H24.6229V0.224487H27.6229V1.22449Z",fill:"black"}),p.jsx("path",{d:"M30.7808 1.22449H33.7808V0.224487H30.7808V1.22449Z",fill:"black"}),p.jsx("path",{d:"M39.9386 1.22449H36.9386V0.224487H39.9386V1.22449Z",fill:"black"}),p.jsx("path",{d:"M43.0964 1.22449H46.0964V0.224487H43.0964V1.22449Z",fill:"black"}),p.jsx("path",{d:"M52.2543 1.22449H49.2543V0.224487H52.2543V1.22449Z",fill:"black"}),p.jsx("path",{d:"M55.4121 1.22449H58.4121V0.224487H55.4121V1.22449Z",fill:"black"}),p.jsx("path",{d:"M64.5699 1.22449H61.5699V0.224487H64.5699V1.22449Z",fill:"black"}),p.jsx("path",{d:"M67.7278 1.22449H70.7278V0.224487H67.7278V1.22449Z",fill:"black"}),p.jsx("path",{d:"M76.8856 1.22449H73.8856V0.224487H76.8856V1.22449Z",fill:"black"}),p.jsx("path",{d:"M80.0435 1.22449H83.0435V0.224487H80.0435V1.22449Z",fill:"black"}),p.jsx("path",{d:"M89.2013 1.22449H86.2013V0.224487H89.2013V1.22449Z",fill:"black"}),p.jsx("path",{d:"M92.3591 1.22449H95.3591V0.224487H92.3591V1.22449Z",fill:"black"}),p.jsx("path",{d:"M101.517 1.22449H98.517V0.224487H101.517V1.22449Z",fill:"black"}),p.jsx("path",{d:"M104.675 1.22449H107.675V0.224487H104.675V1.22449Z",fill:"black"}),p.jsx("path",{d:"M113.833 1.22449H110.833V0.224487H113.833V1.22449Z",fill:"black"}),p.jsx("path",{d:"M116.99 1.22449H119.99V0.224487H116.99V1.22449Z",fill:"black"})]}),Vd=()=>p.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.00976562 1.65707H0.990234V0.657074H-0.00976562V1.65707Z",fill:"black"}),p.jsx("path",{d:"M2.32361 1.65707H3.32361V0.657074H2.32361V1.65707Z",fill:"black"}),p.jsx("path",{d:"M5.65698 1.65707H4.65698V0.657074H5.65698V1.65707Z",fill:"black"}),p.jsx("path",{d:"M6.99036 1.65707H7.99036V0.657074H6.99036V1.65707Z",fill:"black"}),p.jsx("path",{d:"M10.3237 1.65707H9.32373V0.657074H10.3237V1.65707Z",fill:"black"}),p.jsx("path",{d:"M11.6571 1.65707H12.6571V0.657074H11.6571V1.65707Z",fill:"black"}),p.jsx("path",{d:"M14.9905 1.65707H13.9905V0.657074H14.9905V1.65707Z",fill:"black"}),p.jsx("path",{d:"M16.3239 1.65707H17.3239V0.657074H16.3239V1.65707Z",fill:"black"}),p.jsx("path",{d:"M19.6572 1.65707H18.6572V0.657074H19.6572V1.65707Z",fill:"black"}),p.jsx("path",{d:"M20.9906 1.65707H21.9906V0.657074H20.9906V1.65707Z",fill:"black"}),p.jsx("path",{d:"M24.324 1.65707H23.324V0.657074H24.324V1.65707Z",fill:"black"}),p.jsx("path",{d:"M25.6573 1.65707H26.6573V0.657074H25.6573V1.65707Z",fill:"black"}),p.jsx("path",{d:"M28.9907 1.65707H27.9907V0.657074H28.9907V1.65707Z",fill:"black"}),p.jsx("path",{d:"M30.3241 1.65707H31.3241V0.657074H30.3241V1.65707Z",fill:"black"}),p.jsx("path",{d:"M33.6575 1.65707H32.6575V0.657074H33.6575V1.65707Z",fill:"black"}),p.jsx("path",{d:"M34.9908 1.65707H35.9908V0.657074H34.9908V1.65707Z",fill:"black"}),p.jsx("path",{d:"M38.3242 1.65707H37.3242V0.657074H38.3242V1.65707Z",fill:"black"}),p.jsx("path",{d:"M39.6576 1.65707H40.6576V0.657074H39.6576V1.65707Z",fill:"black"}),p.jsx("path",{d:"M42.991 1.65707H41.991V0.657074H42.991V1.65707Z",fill:"black"}),p.jsx("path",{d:"M44.3243 1.65707H45.3243V0.657074H44.3243V1.65707Z",fill:"black"}),p.jsx("path",{d:"M47.6577 1.65707H46.6577V0.657074H47.6577V1.65707Z",fill:"black"}),p.jsx("path",{d:"M48.9911 1.65707H49.9911V0.657074H48.9911V1.65707Z",fill:"black"}),p.jsx("path",{d:"M52.3245 1.65707H51.3245V0.657074H52.3245V1.65707Z",fill:"black"}),p.jsx("path",{d:"M53.6578 1.65707H54.6578V0.657074H53.6578V1.65707Z",fill:"black"}),p.jsx("path",{d:"M56.9912 1.65707H55.9912V0.657074H56.9912V1.65707Z",fill:"black"}),p.jsx("path",{d:"M58.3246 1.65707H59.3246V0.657074H58.3246V1.65707Z",fill:"black"}),p.jsx("path",{d:"M61.658 1.65707H60.658V0.657074H61.658V1.65707Z",fill:"black"}),p.jsx("path",{d:"M62.9913 1.65707H63.9913V0.657074H62.9913V1.65707Z",fill:"black"}),p.jsx("path",{d:"M66.3247 1.65707H65.3247V0.657074H66.3247V1.65707Z",fill:"black"}),p.jsx("path",{d:"M67.6581 1.65707H68.6581V0.657074H67.6581V1.65707Z",fill:"black"}),p.jsx("path",{d:"M70.9915 1.65707H69.9915V0.657074H70.9915V1.65707Z",fill:"black"}),p.jsx("path",{d:"M72.3248 1.65707H73.3248V0.657074H72.3248V1.65707Z",fill:"black"}),p.jsx("path",{d:"M75.6582 1.65707H74.6582V0.657074H75.6582V1.65707Z",fill:"black"}),p.jsx("path",{d:"M76.9916 1.65707H77.9916V0.657074H76.9916V1.65707Z",fill:"black"}),p.jsx("path",{d:"M80.325 1.65707H79.325V0.657074H80.325V1.65707Z",fill:"black"}),p.jsx("path",{d:"M81.6583 1.65707H82.6583V0.657074H81.6583V1.65707Z",fill:"black"}),p.jsx("path",{d:"M84.9917 1.65707H83.9917V0.657074H84.9917V1.65707Z",fill:"black"}),p.jsx("path",{d:"M86.3251 1.65707H87.3251V0.657074H86.3251V1.65707Z",fill:"black"}),p.jsx("path",{d:"M89.6584 1.65707H88.6584V0.657074H89.6584V1.65707Z",fill:"black"}),p.jsx("path",{d:"M90.9918 1.65707H91.9918V0.657074H90.9918V1.65707Z",fill:"black"}),p.jsx("path",{d:"M94.3252 1.65707H93.3252V0.657074H94.3252V1.65707Z",fill:"black"}),p.jsx("path",{d:"M95.6586 1.65707H96.6586V0.657074H95.6586V1.65707Z",fill:"black"}),p.jsx("path",{d:"M98.9919 1.65707H97.9919V0.657074H98.9919V1.65707Z",fill:"black"}),p.jsx("path",{d:"M100.325 1.65707H101.325V0.657074H100.325V1.65707Z",fill:"black"}),p.jsx("path",{d:"M103.659 1.65707H102.659V0.657074H103.659V1.65707Z",fill:"black"}),p.jsx("path",{d:"M104.992 1.65707H105.992V0.657074H104.992V1.65707Z",fill:"black"}),p.jsx("path",{d:"M108.325 1.65707H107.325V0.657074H108.325V1.65707Z",fill:"black"}),p.jsx("path",{d:"M109.659 1.65707H110.659V0.657074H109.659V1.65707Z",fill:"black"}),p.jsx("path",{d:"M112.992 1.65707H111.992V0.657074H112.992V1.65707Z",fill:"black"}),p.jsx("path",{d:"M114.325 1.65707H115.325V0.657074H114.325V1.65707Z",fill:"black"}),p.jsx("path",{d:"M117.659 1.65707H116.659V0.657074H117.659V1.65707Z",fill:"black"}),p.jsx("path",{d:"M118.992 1.65707H119.992V0.657074H118.992V1.65707Z",fill:"black"})]}),Fd=()=>p.jsx("svg",{width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:p.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 2.42035H-0.0090332V0.420349H119.991V2.42035Z",fill:"black"})}),jd=()=>p.jsxs("svg",{width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.0100098 2.47614H1.98999V0.476135H-0.0100098V2.47614Z",fill:"black"}),p.jsx("path",{d:"M3.99014 2.47614H9.99014V0.476135H3.99014V2.47614Z",fill:"black"}),p.jsx("path",{d:"M13.9901 2.47614H11.9901V0.476135H13.9901V2.47614Z",fill:"black"}),p.jsx("path",{d:"M21.1904 2.47614H23.1904V0.476135H21.1904V2.47614Z",fill:"black"}),p.jsx("path",{d:"M31.1906 2.47614H25.1906V0.476135H31.1906V2.47614Z",fill:"black"}),p.jsx("path",{d:"M33.1906 2.47614H35.1906V0.476135H33.1906V2.47614Z",fill:"black"}),p.jsx("path",{d:"M44.3909 2.47614H42.3909V0.476135H44.3909V2.47614Z",fill:"black"}),p.jsx("path",{d:"M46.391 2.47614H52.391V0.476135H46.391V2.47614Z",fill:"black"}),p.jsx("path",{d:"M56.391 2.47614H54.391V0.476135H56.391V2.47614Z",fill:"black"}),p.jsx("path",{d:"M63.5913 2.47614H65.5913V0.476135H63.5913V2.47614Z",fill:"black"}),p.jsx("path",{d:"M73.5915 2.47614H67.5915V0.476135H73.5915V2.47614Z",fill:"black"}),p.jsx("path",{d:"M75.5915 2.47614H77.5915V0.476135H75.5915V2.47614Z",fill:"black"}),p.jsx("path",{d:"M86.7917 2.47614H84.7917V0.476135H86.7917V2.47614Z",fill:"black"}),p.jsx("path",{d:"M88.7919 2.47614H94.7919V0.476135H88.7919V2.47614Z",fill:"black"}),p.jsx("path",{d:"M98.7919 2.47614H96.7919V0.476135H98.7919V2.47614Z",fill:"black"}),p.jsx("path",{d:"M105.992 2.47614H107.992V0.476135H105.992V2.47614Z",fill:"black"}),p.jsx("path",{d:"M115.992 2.47614H109.992V0.476135H115.992V2.47614Z",fill:"black"}),p.jsx("path",{d:"M117.992 2.47614H119.992V0.476135H117.992V2.47614Z",fill:"black"})]}),Wd=()=>p.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.0100098 2.00415H1.98999V0.00415039H-0.0100098V2.00415Z",fill:"black"}),p.jsx("path",{d:"M3.99014 2.00415H9.99014V0.00415039H3.99014V2.00415Z",fill:"black"}),p.jsx("path",{d:"M13.9901 2.00415H11.9901V0.00415039H13.9901V2.00415Z",fill:"black"}),p.jsx("path",{d:"M15.9901 2.00415H17.9901V0.00415039H15.9901V2.00415Z",fill:"black"}),p.jsx("path",{d:"M27.4905 2.00415H25.4905V0.00415039H27.4905V2.00415Z",fill:"black"}),p.jsx("path",{d:"M29.4906 2.00415H35.4906V0.00415039H29.4906V2.00415Z",fill:"black"}),p.jsx("path",{d:"M39.4906 2.00415H37.4906V0.00415039H39.4906V2.00415Z",fill:"black"}),p.jsx("path",{d:"M41.4906 2.00415H43.4906V0.00415039H41.4906V2.00415Z",fill:"black"}),p.jsx("path",{d:"M52.991 2.00415H50.991V0.00415039H52.991V2.00415Z",fill:"black"}),p.jsx("path",{d:"M54.9911 2.00415H60.9911V0.00415039H54.9911V2.00415Z",fill:"black"}),p.jsx("path",{d:"M64.9911 2.00415H62.9911V0.00415039H64.9911V2.00415Z",fill:"black"}),p.jsx("path",{d:"M66.9911 2.00415H68.9911V0.00415039H66.9911V2.00415Z",fill:"black"}),p.jsx("path",{d:"M78.4915 2.00415H76.4915V0.00415039H78.4915V2.00415Z",fill:"black"}),p.jsx("path",{d:"M80.4916 2.00415H86.4916V0.00415039H80.4916V2.00415Z",fill:"black"}),p.jsx("path",{d:"M90.4916 2.00415H88.4916V0.00415039H90.4916V2.00415Z",fill:"black"}),p.jsx("path",{d:"M92.4916 2.00415H94.4916V0.00415039H92.4916V2.00415Z",fill:"black"}),p.jsx("path",{d:"M103.992 2.00415H101.992V0.00415039H103.992V2.00415Z",fill:"black"}),p.jsx("path",{d:"M105.992 2.00415H111.992V0.00415039H105.992V2.00415Z",fill:"black"}),p.jsx("path",{d:"M115.992 2.00415H113.992V0.00415039H115.992V2.00415Z",fill:"black"}),p.jsx("path",{d:"M117.992 2.00415H119.992V0.00415039H117.992V2.00415Z",fill:"black"})]}),$d=()=>p.jsxs("svg",{width:"118",height:"3",viewBox:"0 0 118 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.00854492 2.94815H1.99146V0.948151H-0.00854492V2.94815Z",fill:"black"}),p.jsx("path",{d:"M6.09668 2.94815H8.09668V0.948151H6.09668V2.94815Z",fill:"black"}),p.jsx("path",{d:"M14.2019 2.94815H12.2019V0.948151H14.2019V2.94815Z",fill:"black"}),p.jsx("path",{d:"M18.3071 2.94815H20.3071V0.948151H18.3071V2.94815Z",fill:"black"}),p.jsx("path",{d:"M26.4124 2.94815H24.4124V0.948151H26.4124V2.94815Z",fill:"black"}),p.jsx("path",{d:"M30.5176 2.94815H32.5176V0.948151H30.5176V2.94815Z",fill:"black"}),p.jsx("path",{d:"M38.6228 2.94815H36.6228V0.948151H38.6228V2.94815Z",fill:"black"}),p.jsx("path",{d:"M42.728 2.94815H44.728V0.948151H42.728V2.94815Z",fill:"black"}),p.jsx("path",{d:"M50.8333 2.94815H48.8333V0.948151H50.8333V2.94815Z",fill:"black"}),p.jsx("path",{d:"M54.9385 2.94815H56.9385V0.948151H54.9385V2.94815Z",fill:"black"}),p.jsx("path",{d:"M63.0437 2.94815H61.0437V0.948151H63.0437V2.94815Z",fill:"black"}),p.jsx("path",{d:"M67.1489 2.94815H69.1489V0.948151H67.1489V2.94815Z",fill:"black"}),p.jsx("path",{d:"M75.2542 2.94815H73.2542V0.948151H75.2542V2.94815Z",fill:"black"}),p.jsx("path",{d:"M79.3594 2.94815H81.3594V0.948151H79.3594V2.94815Z",fill:"black"}),p.jsx("path",{d:"M87.4645 2.94815H85.4645V0.948151H87.4645V2.94815Z",fill:"black"}),p.jsx("path",{d:"M91.5697 2.94815H93.5697V0.948151H91.5697V2.94815Z",fill:"black"}),p.jsx("path",{d:"M99.6749 2.94815H97.6749V0.948151H99.6749V2.94815Z",fill:"black"}),p.jsx("path",{d:"M103.78 2.94815H105.78V0.948151H103.78V2.94815Z",fill:"black"}),p.jsx("path",{d:"M111.885 2.94815H109.885V0.948151H111.885V2.94815Z",fill:"black"}),p.jsx("path",{d:"M115.991 2.94815H117.991V0.948151H115.991V2.94815Z",fill:"black"})]}),zd=()=>p.jsx("svg",{width:"120",height:"4",viewBox:"0 0 120 4",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:p.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 3.86215H-0.0090332V0.862152H119.991V3.86215Z",fill:"black"})}),ho=()=>p.jsx("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:p.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 1.15668H-0.0090332V0.156677H119.991V1.15668Z",fill:"black"})});function mo(i){const{type:e=a.BorderStyleTypes.THIN}=i;switch(e){case a.BorderStyleTypes.DASH_DOT:return p.jsx(Ud,{});case a.BorderStyleTypes.DASH_DOT_DOT:return p.jsx(kd,{});case a.BorderStyleTypes.DASHED:return p.jsx(Bd,{});case a.BorderStyleTypes.HAIR:return p.jsx(Vd,{});case a.BorderStyleTypes.MEDIUM:return p.jsx(Fd,{});case a.BorderStyleTypes.MEDIUM_DASH_DOT:return p.jsx(jd,{});case a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT:return p.jsx(Wd,{});case a.BorderStyleTypes.MEDIUM_DASHED:return p.jsx($d,{});case a.BorderStyleTypes.THICK:return p.jsx(zd,{});case a.BorderStyleTypes.THIN:return p.jsx(ho,{});default:return p.jsx(ho,{})}}const Xd="univer-ui-plugin-sheets-border-panel",Yd="univer-ui-plugin-sheets-border-panel-position",Zd="univer-ui-plugin-sheets-border-panel-position-item",Gd="univer-ui-plugin-sheets-border-panel-styles",Kd="univer-ui-plugin-sheets-border-panel-board",qd="univer-ui-plugin-sheets-border-panel-button",Jd="univer-ui-plugin-sheets-border-panel-more-icon",Ee={uiPluginSheetsBorderPanel:Xd,uiPluginSheetsBorderPanelPosition:Yd,uiPluginSheetsBorderPanelPositionItem:Zd,uiPluginSheetsBorderPanelStyles:Gd,uiPluginSheetsBorderPanelBoard:Kd,uiPluginSheetsBorderPanelButton:qd,uiPluginSheetsBorderPanelMoreIcon:Jd},br=`${ut}_BORDER_PANEL_COMPONENT`,Mr=[{label:"borderLine.borderTop",icon:"UpBorder",value:"top"},{label:"borderLine.borderBottom",icon:"DownBorder",value:"bottom"},{label:"borderLine.borderLeft",icon:"LeftBorder",value:"left"},{label:"borderLine.borderRight",icon:"RightBorder",value:"right"},{label:"borderLine.borderNone",icon:"NoBorderSingle",value:"none"},{label:"borderLine.borderAll",icon:"AllBorderSingle",value:"all"},{label:"borderLine.borderOutside",icon:"OuterBorder",value:"outside"},{label:"borderLine.borderInside",icon:"InnerBorder",value:"inside"},{label:"borderLine.borderHorizontal",icon:"InnerBorder",value:"horizontal"},{label:"borderLine.borderVertical",icon:"InnerBorder",value:"vertical"},{label:"borderLine.borderTlbr",icon:"BackSlashSingle",value:"tlbr"},{label:"borderLine.borderTlbcTlmr",icon:"LeftDoubleDiagonalSingle",value:"tlbc_tlmr"},{label:"borderLine.borderTlbrTlbcTlmr",icon:"LeftTridiagonalSingle",value:"tlbr_tlbc_tlmr"},{label:"borderLine.borderBlTr",icon:"SlashSingle",value:"bltr"},{label:"borderLine.borderMltrBctr",icon:"RightDoubleDiagonalSingle",value:"mltr_bctr"}],Qd=[{label:a.BorderStyleTypes.THIN,value:a.BorderStyleTypes.THIN},{label:a.BorderStyleTypes.HAIR,value:a.BorderStyleTypes.HAIR},{label:a.BorderStyleTypes.DOTTED,value:a.BorderStyleTypes.DOTTED},{label:a.BorderStyleTypes.DASHED,value:a.BorderStyleTypes.DASHED},{label:a.BorderStyleTypes.DASH_DOT,value:a.BorderStyleTypes.DASH_DOT},{label:a.BorderStyleTypes.DASH_DOT_DOT,value:a.BorderStyleTypes.DASH_DOT_DOT},{label:a.BorderStyleTypes.MEDIUM,value:a.BorderStyleTypes.MEDIUM},{label:a.BorderStyleTypes.MEDIUM_DASHED,value:a.BorderStyleTypes.MEDIUM_DASHED},{label:a.BorderStyleTypes.MEDIUM_DASH_DOT,value:a.BorderStyleTypes.MEDIUM_DASH_DOT},{label:a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT,value:a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT},{label:a.BorderStyleTypes.THICK,value:a.BorderStyleTypes.THICK}];function eu(i){const e=W.useDependency(R.ComponentManager),{onChange:t,value:n}=i;function o(l,c){t==null||t({...n,[c]:l})}function r(l){const c=e.get(l);return c&&p.jsx(c,{extend:{colorChannel1:"rgb(var(--primary-color))"}})}function s(l){l.stopPropagation()}return p.jsxs("section",{className:Ee.uiPluginSheetsBorderPanel,children:[p.jsx("div",{className:Ee.uiPluginSheetsBorderPanelPosition,children:Mr.map(l=>p.jsx("div",{className:Ee.uiPluginSheetsBorderPanelPositionItem,onClick:()=>o(l.value,"type"),children:r(l.icon)},l.value))}),p.jsxs("div",{className:Ee.uiPluginSheetsBorderPanelStyles,children:[p.jsx("div",{children:p.jsx(ie.Dropdown,{align:{offset:[0,18]},overlay:p.jsx("section",{className:Ee.uiPluginSheetsBorderPanelBoard,onClick:s,children:p.jsx(ie.ColorPicker,{onChange:l=>o(l,"color")})}),children:p.jsxs("a",{className:Ee.uiPluginSheetsBorderPanelButton,onClick:s,children:[p.jsx(il,{extend:{colorChannel1:n.color??"rgb(var(--primary-color))"}}),p.jsx("span",{className:Ee.uiPluginSheetsBorderPanelMoreIcon,children:p.jsx(ei,{})})]})})}),p.jsx("div",{children:p.jsx(ie.Dropdown,{align:{offset:[0,18]},overlay:p.jsx("section",{onClick:s,children:p.jsx(ie.Menu,{children:Qd.map(l=>p.jsx(ie.MenuItem,{eventKey:l.value.toString(),onClick:()=>o(l.value,"style"),children:p.jsx(mo,{type:l.value})},l.value))})}),children:p.jsxs("a",{className:Ee.uiPluginSheetsBorderPanelButton,onClick:s,children:[p.jsx(mo,{type:a.BorderStyleTypes.THIN}),p.jsx("span",{className:Ee.uiPluginSheetsBorderPanelMoreIcon,children:p.jsx(ei,{})})]})})})]})]})}const tu="univer-count-bar",nu={countBar:tu},iu=[50,80,100,130,150,170,200,400];function ou(){const i=W.useDependency(a.ICommandService),e=W.useDependency(a.IUniverInstanceService),t=r(),[n,o]=L.useState(t);L.useEffect(()=>i.onCommandExecuted(c=>{if(c.id===xe.id||c.id===f.SetWorksheetActivateCommand.id){const d=r();o(d)}}).dispose,[i]);function r(){const l=e.getCurrentUniverSheetInstance().getActiveSheet().getZoomRatio()*100||100;return Math.round(l)}function s(l){o(l);const c=e.getCurrentUniverSheetInstance();if(!c)return;const d=c.getActiveSheet();if(!d)return;const u=l/100;i.executeCommand(Ri.id,{unitId:c.getUnitId(),subUnitId:d.getSheetId(),zoomRatio:u})}return p.jsx(ie.Slider,{min:Qn[0],value:n,shortcuts:iu,onChange:s})}function ru(i){return p.jsx("section",{className:nu.countBar,children:p.jsx(ou,{})})}const su="univer-editor-container",lu="univer-editor-input",So={editorContainer:su,editorInput:lu},Tn=-1e3,_o={width:0,height:0,top:Tn,left:Tn},au=()=>{const[i,e]=L.useState({..._o}),t=L.useRef(null),n=W.useDependency(w.IRenderManagerService),o=W.useDependency(Pt);return L.useEffect(()=>{const r=t.current;if(!r)return;const s=n.currentRender$.pipe(po.switchMap(()=>{var c;const l=(c=n.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:c.engine;return l==null||l.setContainer(r),o.state$})).subscribe(l=>{if(l==null)return;const{startX:c=Tn,startY:d=Tn,endX:u=0,endY:h=0,show:m=!1}=l;if(!m)e({..._o});else{e({width:u-c,height:h-d,left:c,top:d});const S=t.current;if(!S)return;const{left:g,top:_,width:I,height:C}=S.getBoundingClientRect();o.setRect({left:g,top:_,width:I,height:C})}});return()=>{s.unsubscribe()}},[]),L.useEffect(()=>{o.setFocus(!0)},[i]),p.jsx("div",{className:So.editorContainer,style:{left:i.left,top:i.top,width:i.width,height:i.height},children:p.jsx("div",{className:So.editorInput,ref:t})})},cu="univer-formula-box",du="univer-name-ranges",uu="univer-name-ranges-input",hu="univer-formula-bar",mu="univer-formula-icon",Su="univer-formula-icon-wrapper",_u="univer-icon-container",gu="univer-icon-container-success",fu="univer-formula-active",pu="univer-icon-container-error",vu="univer-formula-input",Cu="univer-formula-content",Iu="univer-arrow-container",ne={formulaBox:cu,nameRanges:du,nameRangesInput:uu,formulaBar:hu,formulaIcon:mu,formulaIconWrapper:Su,iconContainer:_u,iconContainerSuccess:gu,formulaActive:fu,iconContainerError:pu,formulaInput:vu,formulaContent:Cu,arrowContainer:Iu};function Ru(){const[i,e]=L.useState(ne.formulaGrey),[t,n]=L.useState(0),o=L.useRef(null),r=W.useDependency(w.IRenderManagerService),s=W.useDependency(Dn),l=W.useDependency(pe);L.useEffect(()=>{const m=o.current;if(!m)return;const S=r.currentRender$.subscribe(_=>{var C;if(_!==a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;const I=(C=r.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:C.engine;I==null||I.setContainer(m)}),g=new ResizeObserver(()=>{const _=m.getBoundingClientRect();s.setPosition(_)});return g.observe(m),l.visible$.subscribe(_=>{e(_.visible?ne.formulaActive:ne.formulaGrey)}),()=>{g.unobserve(m),S.unsubscribe()}},[]);function c(){n(t===0?1:0)}function d(){l.isVisible().visible&&l.changeVisible({visible:!1,eventType:w.DeviceInputEventType.Keyboard,keycode:R.KeyCode.ESC})}function u(){l.isVisible().visible&&l.changeVisible({visible:!1,eventType:w.DeviceInputEventType.PointerDown})}function h(){s.handleFxBtnClick(!0)}return p.jsxs("div",{className:ne.formulaBox,style:{height:t===0?"28px":"82px"},children:[p.jsx("div",{className:ne.nameRanges,children:p.jsx("div",{className:ne.nameRangesInput})}),p.jsxs("div",{className:ne.formulaBar,children:[p.jsx("div",{className:ne.formulaIcon,children:p.jsxs("div",{className:ne.formulaIconWrapper,children:[p.jsx("span",{className:Tt(ne.iconContainer,ne.iconContainerError,i),onClick:d,children:p.jsx($s,{})}),p.jsx("span",{className:Tt(ne.iconContainer,ne.iconContainerSuccess,i),onClick:u,children:p.jsx(bn,{})}),p.jsx("span",{className:ne.iconContainer,onClick:h,children:p.jsx(qs,{})})]})}),p.jsxs("div",{className:ne.formulaInput,children:[p.jsx("div",{onContextMenu:m=>m.preventDefault(),className:ne.formulaContent,ref:o}),p.jsx("div",{className:ne.arrowContainer,onClick:c,children:t===0?p.jsx(Wi,{}):p.jsx(Wi,{style:{transform:"rotateZ(180deg)"}})})]})]})]})}const bu="univer-operate-container",Mu="univer-auto-fill-popup-menu",wu="univer-auto-fill-popup-menu-item",Tu="univer-auto-fill-popup-menu-item-icon",Eu="univer-auto-fill-popup-menu-item-title",yu="univer-auto-fill-popup-menu-item-hide",Ou="univer-btn-container",xu="univer-btn-container-expand",ze={operateContainer:bu,autoFillPopupMenu:Mu,autoFillPopupMenuItem:wu,autoFillPopupMenuItemIcon:Tu,autoFillPopupMenuItemTitle:Eu,autoFillPopupMenuItemHide:yu,btnContainer:Ou,btnContainerExpand:xu},Au=()=>{const[,i]=L.useState({});return L.useCallback(()=>i({}),[])},Hu=()=>{var q;const i=W.useDependency(a.ICommandService),e=W.useDependency(exports.SheetSkeletonManagerService),t=W.useDependency(a.IUniverInstanceService),n=W.useDependency(w.IRenderManagerService),o=W.useDependency(ce),r=W.useDependency(Dt),s=W.useDependency(a.LocaleService),[l,c]=L.useState([]),[d,u]=L.useState(!1),[h,m]=L.useState({row:-1,col:-1}),[S,g]=L.useState(X.SERIES),[_,I]=L.useState(!1),C=()=>{I(!0)},b=()=>{I(!1)},M=Au(),T=ae(t,n);if(T==null)return null;const{scene:E}=T;if(L.useEffect(()=>{const z=[Re.id,zt.id,xe.id,f.SetRangeValuesMutation.id];return i.onCommandExecuted(J=>{if(J.id===Cn.id){const{endColumn:we,endRow:re}=(J==null?void 0:J.params).selectionRange;m({row:re,col:we})}J.id===ct.id&&M(),z.includes(J.id)&&m({row:-1,col:-1})}).dispose},[M,i]),L.useEffect(()=>a.toDisposable(r.menu$.subscribe(Q=>{c(Q.map(J=>({...J,index:Q.indexOf(J)})))})).dispose,[r]),L.useEffect(()=>a.toDisposable(r.applyType$.subscribe(Q=>{g(Q)})).dispose,[r]),L.useEffect(()=>{function z(){u(!1)}return document.addEventListener("wheel",z),()=>{document.removeEventListener("wheel",z)}},[d]),h.col<0||h.row<0)return null;const y=(q=e.getCurrent())==null?void 0:q.skeleton,O=o.getViewPort(),x=E==null?void 0:E.scaleX,D=E==null?void 0:E.scaleY,U=E==null?void 0:E.getScrollXY(O);if(!x||!E||!x||!D||!U)return null;const N=(y==null?void 0:y.getNoMergeCellPositionByIndex(h.row,h.col,x,D).endX)||0,B=(y==null?void 0:y.getNoMergeCellPositionByIndex(h.row,h.col,x,D).endY)||0,A=y==null?void 0:y.convertTransformToOffsetX(N,x,U),H=y==null?void 0:y.convertTransformToOffsetY(B,D,U);if(A==null||H==null)return null;const V=z=>{u(z)},F=z=>{i.executeCommand(vr.id,{type:z.value})},j=d||_,$=l.filter(z=>!z.disable);return p.jsx("div",{onMouseEnter:C,onMouseLeave:b,style:{left:`${A+2}px`,top:`${H+2}px`,position:"absolute"},children:p.jsx(ie.Dropdown,{placement:"bottomLeft",trigger:["click"],overlay:p.jsx("ul",{className:ze.autoFillPopupMenu,children:$.map(z=>p.jsxs("li",{onClick:()=>F(z),className:ze.autoFillPopupMenuItem,children:[p.jsx("span",{className:ze.autoFillPopupMenuItemIcon,children:z.value===S&&p.jsx(bn,{style:{color:"rgb(var(--green-700, #409f11))"}})}),p.jsx("span",{className:ze.autoFillPopupMenuItemTitle,children:s.t(z.label)})]},z.index))}),visible:d,onVisibleChange:V,children:p.jsxs("div",{className:Tt(ze.btnContainer,{[ze.btnContainerExpand]:d}),children:[p.jsx(Fs,{style:{color:"#35322B"},extend:{colorChannel1:"rgb(var(--green-700, #409f11))"}}),j&&p.jsx(ei,{style:{color:"#CCCCCC",fontSize:"8px",marginLeft:"8px"}})]})})})},Du=()=>p.jsx("div",{className:ze.operateContainer,children:p.jsx(Hu,{})}),Nu="univer-sheet-bar",Pu="univer-sheet-bar-options",Lu="univer-sheet-bar-options-divider",$t={sheetBar:Nu,sheetBarOptions:Pu,sheetBarOptionsDivider:Lu},Uu="univer-sheet-bar-btn",ku={sheetBarBtn:Uu};function gn(i){const{children:e,className:t,style:n,disabled:o=!1,onClick:r,...s}=i,l=c=>{if(o){c.preventDefault();return}r&&r(c)};return p.jsx("button",{className:ku.sheetBarBtn,style:n,disabled:o,onClick:l,...s,children:e})}const Bu="univer-sheet-bar-menu",Vu="univer-sheet-bar-menu-item",Fu="univer-sheet-bar-menu-item-icon",ju="univer-sheet-bar-menu-item-hide",Wu="univer-sheet-bar-menu-item-select",$u="univer-sheet-bar-menu-item-label",Pe={sheetBarMenu:Bu,sheetBarMenuItem:Vu,sheetBarMenuItemIcon:Fu,sheetBarMenuItemHide:ju,sheetBarMenuItemSelect:Wu,sheetBarMenuItemLabel:$u};function zu(i){const{style:e}=i,[t,n]=L.useState([]),[o,r]=L.useState(!1),s=W.useDependency(a.IUniverInstanceService),l=W.useDependency(a.ICommandService),c=W.useDependency(mt),d=s.getCurrentUniverSheetInstance(),u=_=>{const{sheetId:I}=_;I&&(_.hidden?l.executeCommand(f.SetWorksheetShowCommand.id,{value:I}):_.selected||l.executeCommand(f.SetWorksheetActivateCommand.id,{unitId:d.getUnitId(),subUnitId:I}),r(!1))};L.useEffect(()=>{m();const _=new a.DisposableCollection;return _.add(h()),_.add(c.registerSheetBarMenuHandler({handleSheetBarMenu:S})),()=>{_.dispose()}},[]);const h=()=>l.onCommandExecuted(_=>{switch(_.id){case f.SetWorksheetHideMutation.id:case f.RemoveSheetMutation.id:case f.SetWorksheetNameMutation.id:case f.InsertSheetMutation.id:case f.SetWorksheetOrderMutation.id:case f.SetWorksheetActiveOperation.id:m();break}}),m=()=>{const I=d.getSheets().map((C,b)=>({label:C.getName(),index:`${b}`,sheetId:C.getSheetId(),hidden:C.isSheetHidden()===a.BooleanNumber.TRUE,selected:C.getStatus()===a.BooleanNumber.TRUE}));n(I)};function S(){r(!0)}const g=_=>{r(_)};return p.jsx(ie.Dropdown,{placement:"topLeft",trigger:["click"],overlay:p.jsx("ul",{className:Pe.sheetBarMenu,style:{...e},children:t.map(_=>p.jsxs("li",{onClick:()=>u(_),className:_.selected?`${Pe.sheetBarMenuItem} ${Pe.sheetBarMenuItemSelect}`:_.hidden?`${Pe.sheetBarMenuItem} ${Pe.sheetBarMenuItemHide}`:Pe.sheetBarMenuItem,children:[p.jsx("span",{className:Pe.sheetBarMenuItemIcon,children:_.selected?p.jsx(bn,{}):_.hidden?p.jsx(Gs,{}):p.jsx(bn,{})}),p.jsx("span",{className:Pe.sheetBarMenuItemLabel,children:_.label})]},_.index))}),visible:o,onVisibleChange:g,children:p.jsx(gn,{children:p.jsx(Xs,{})})})}const Xu="univer-slide-tab-bar-container",Yu="univer-slide-tab-bar",Zu="univer-slide-tab-item",Gu="univer-slide-tab-active",Ku="univer-slide-tab-span",qu="univer-slide-tab-span-edit",ge={slideTabBarContainer:Xu,slideTabBar:Yu,slideTabItem:Zu,slideTabActive:Gu,slideTabSpan:Ku,slideTabSpanEdit:qu};function Ju(i){const{sheetId:e,label:t,color:n,selected:o}=i,[r,s]=L.useState(!1),[l,c]=L.useState(o),d=W.useDependency(a.ICommandService),u=W.useDependency(a.ThemeService);L.useEffect(()=>{c(o)},[o]);const h=S=>{s(S)},m=S=>{const g=u.getCurrentTheme(),_=g.textColor,I=g.colorWhite;return new a.ColorKit(S).isDark()?I:_};return p.jsx(ie.Dropdown,{visible:r,trigger:["contextMenu"],overlay:p.jsx(R.Menu,{menuType:ee.SHEET_BAR,onOptionSelect:S=>{const{label:g,value:_}=S;d.executeCommand(g,{value:_,subUnitId:e}),s(!1)}}),onVisibleChange:h,children:p.jsx("div",{"data-id":e,className:l?`${ge.slideTabActive} ${ge.slideTabItem}`:ge.slideTabItem,style:{backgroundColor:!l&&n?n:"",color:!l&&n?m(n):"",boxShadow:l&&n?`0px 0px 12px rgba(0, 0, 0, 0.2), inset 0px -2px 0px 0px ${n}`:""},children:p.jsx("span",{className:ge.slideTabSpan,children:t})},e)})}const Qu={easeOutStrong(i,e,t,n){return-t*((i=i/n-1)*i*i*i-1)+e},backOut(i,e,t,n,o){return typeof o>"u"&&(o=.7),t*((i=i/n-1)*i*((o+1)*i+o)+1)+e}},eh={loop:!1,begin:0,end:0,duration:300,delay:0,type:"easeOutStrong",receive(i){},success(i){},cancel(i){},complete(i){}};class th{constructor(e){v(this,"_config");v(this,"_status",0);v(this,"_start",0);v(this,"_handle",0);v(this,"_delayHandle",null);this._config={...eh,...e},this._config.loop&&(this._config.complete=()=>{},this._config.success=()=>{this.request()})}static success(...e){let t=0;return new Promise(n=>{for(let o=0;o<e.length;o++){const r=e[o],s=r._config,l=s.success;s.loop||(s.success=d=>{t++,l&&l.call(r,d),t===e.length&&n()})}})}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 e=Date.now()-this._start;e=e>=this._config.duration?this._config.duration:e;const n=Qu[this._config.type](e,this._config.begin,this._config.end-this._config.begin,this._config.duration,.7).toFixed(2);if(this._config.receive(n),this._status===1){this._config.cancel(n),this._config.complete(n);return}if(e===this._config.duration){this._config.success(n),this._config.complete(n);return}this._handle=requestAnimationFrame(()=>{this._fakeHandle()})}}class Ze{constructor(e,t){v(this,"_slideTabItem");v(this,"_animate");v(this,"_midline",0);v(this,"_translateX");v(this,"_scrollbar");v(this,"_slideTabBar");v(this,"_editMode");v(this,"_placeholder");this._slideTabItem=e,this._animate=null,this._translateX=0,this._editMode=!1,this._slideTabBar=t,this._placeholder=null,this._scrollbar=t.getScrollbar(),this.update()}static midline(e){return e.getBoundingRect().x+e.getBoundingRect().width/2}static leftLine(e){return e.getBoundingRect().x}static rightLine(e){return e.getBoundingRect().x+e.getBoundingRect().width}static make(e,t){const n=[];return e.forEach(o=>n.push(new Ze(o,t))),n}getSlideTabItem(){return this._slideTabItem}getEditor(){return this._slideTabItem.querySelector("span")}isEditMode(){return this._editMode}classList(){return this._slideTabItem.classList}translateX(e){return this._translateX=e,this._slideTabItem.style.transform=`translateX(${e}px)`,this.getTranslateXDirection()}setEditor(e){let t=!0;if(this._editMode===!1){const n=this._slideTabItem.querySelector("span"),o=d=>{if(!this.nameCheck()){if(this._editMode=!1,n&&(n.removeAttribute("contentEditable"),n.removeEventListener("blur",o),n.removeEventListener("compositionstart",s),n.removeEventListener("compositionend",l),n.removeEventListener("input",c),n.removeEventListener("keydown",r),n.classList.remove(this._slideTabBar.getConfig().slideTabBarSpanEditClassName)),this._slideTabBar.removeListener(),this._slideTabBar.updateItems(),this._slideTabBar.getConfig().onChangeName){const u=(n==null?void 0:n.innerText)||"",h=this.getId();this._slideTabBar.getConfig().onChangeName(h,u)}e&&e(d)}};let r=d=>{n&&(d.stopPropagation(),d.key==="Enter"&&n.blur())};const s=d=>{t=!1},l=d=>{t=!0},c=d=>{if(!n)return;const u=50;setTimeout(()=>{if(t){const h=n.innerText;h.length>u&&(n.innerText=h.substring(0,u),xt.keepLastIndex(n))}},0)};n&&(n.setAttribute("contentEditable","true"),n.addEventListener("blur",o),n.addEventListener("compositionstart",s),n.addEventListener("compositionend",l),n.addEventListener("input",c),n.addEventListener("keydown",r),n.classList.add(this._slideTabBar.getConfig().slideTabBarSpanEditClassName),this._editMode=!0,xt.keepSelectAll(n))}}nameCheck(){const e=this._slideTabItem.querySelector("span");if(!e)return!1;const t=e.innerText;return this._slideTabBar.getConfig().onNameCheckAlert(t)}animate(){return{translateX:e=>{this._translateX!==e&&(this._animate&&(this._animate.cancel(),this._animate=null),this._animate=new th({begin:this._translateX,end:e,receive:t=>{this._slideTabItem.style.transform=`translateX(${t}px)`}}),this._translateX=e,this._animate.request())},cancel:()=>{this._animate&&(this._animate.cancel(),this._animate=null)}}}after(e){this._slideTabItem.after(e._slideTabItem||e)}update(){this._midline=Ze.midline(this)}disableFixed(){if(this._placeholder){const e=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),e.removeChild(this._placeholder),this._placeholder=null}}enableFixed(){const e=document.createElement("div"),t=this.getBoundingRect(),n=getComputedStyle(this._slideTabItem),o=this._slideTabItem.querySelector("span");if(this._placeholder=e,this._placeholder.style.width=`${t.width}px`,this._placeholder.style.height=`${t.height}px`,this._placeholder.style.flexShrink="0",this._placeholder.style.margin=n.margin,this._slideTabItem.style.background=n.background,o){const r=getComputedStyle(o).padding;this._slideTabItem.style.padding=r}this._slideTabItem.style.boxSizing=n.boxSizing,this._slideTabItem.style.fontSize=n.fontSize,this._slideTabItem.style.fontFamily=n.fontFamily,this._slideTabItem.style.fontWeight=n.fontWeight,this._slideTabItem.style.color=n.color,this._slideTabItem.style.borderRadius=n.borderRadius,this._slideTabItem.style.left=`${t.x-this.getScrollbar().getScrollX()}px`,this._slideTabItem.style.top=`${t.y}px`,this._slideTabItem.style.width=`${t.width}px`,this._slideTabItem.style.height=`${t.height}px`,this._slideTabItem.style.position="fixed",this._slideTabItem.after(e),document.body.appendChild(this._slideTabItem)}addEventListener(e,t,n){this._slideTabItem.addEventListener(e,t,n)}removeEventListener(e,t,n){this._slideTabItem.removeEventListener(e,t,n)}getScrollbar(){return this._scrollbar}getMidLine(){return this._midline}getBoundingRect(){const e=this._slideTabItem.getBoundingClientRect();return e.x+=this._scrollbar.getScrollX(),e}getWidth(){return this.getBoundingRect().width}getTranslateXDirection(){const e=Ze.midline(this);return e>this._midline?1:e<this._midline?-1:0}equals(e){return e&&e._slideTabItem===this._slideTabItem}getId(){return this._slideTabItem.dataset.id||""}}class nh{constructor(e){v(this,"_slideTabBar");v(this,"_scrollX");const t=e.primeval();this._scrollX=t.scrollLeft,this._slideTabBar=e}scrollX(e){const t=this._slideTabBar.primeval();t.scrollLeft=e,this._scrollX=t.scrollLeft}scrollRight(){const e=this._slideTabBar.primeval();e.scrollLeft=e.scrollWidth,this._scrollX=e.scrollLeft}getScrollX(){return this._scrollX}}const ot=class ot{constructor(e){v(this,"_activeTabItemIndex",0);v(this,"_slideTabBar");v(this,"_slideTabItems",[]);v(this,"_config");v(this,"_downActionX",0);v(this,"_moveActionX",0);v(this,"_compareIndex",0);v(this,"_activeTabItem",null);v(this,"_moveAction");v(this,"_upAction");v(this,"_downAction");v(this,"_wheelAction");v(this,"_scrollIncremental",0);v(this,"_compareDirection",0);v(this,"_autoScrollTime",null);v(this,"_slideScrollbar");v(this,"_longPressTimer",null);v(this,"_leftBoundingLine",0);v(this,"_rightBoundingLine",0);v(this,"_leftMoveX",0);v(this,"_rightMoveX",0);if(e.slideTabBarContainer==null)throw new Error("not found slide-tab-bar root element");const t=e.slideTabBarContainer.querySelector(`.${e.slideTabBarClassName??"slide-tab-bar"}`);if(t==null)throw new Error("not found slide-tab-bar");this._slideTabBar=t,this._slideScrollbar=new nh(this),this._config=e,this._initConfig();let n=0,o=0,r=0;this._downAction=s=>{var E,y,O,x,D,U;if((E=this._activeTabItem)!=null&&E.isEditMode())return;const l=(O=(y=s.target)==null?void 0:y.closest(`.${e.slideTabBarItemClassName}`))==null?void 0:O.getAttribute("data-id"),c=this._slideTabItems.findIndex(N=>N.getId()===l);if(l==null||c===-1)return;if(this._activeTabItemIndex!==c){(x=this._activeTabItem)==null||x.removeEventListener("pointermove",this._moveAction),(D=this._activeTabItem)==null||D.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),(U=this._activeTabItem)==null||U.addEventListener("pointerup",this._upAction);const{x:u,width:h}=this._activeTabItem.getBoundingRect(),{x:m,width:S}=this.getBoundingRect(),g=this._slideScrollbar.getScrollX();if(this._leftBoundingLine=this._downActionX-(u-g),this._rightBoundingLine=u-g+h-this._downActionX,this._leftMoveX=u-m-g,this._rightMoveX=m+S-(u+h)+g,s.button===2||this._hasEditItem())return;const{pageX:_,pageY:I}=s,C=Date.now(),b=C-r<=ot.DoubleClickDelay,M=Math.abs(_-n)<10,T=Math.abs(I-o)<10;b&&M&&T&&this._activeTabItem.setEditor(),n=_,o=I,r=C,this._longPressTimer=setTimeout(()=>{var N,B;(N=this._activeTabItem)==null||N.enableFixed(),this._startAutoScroll(),d&&(d.setPointerCapture(s.pointerId),d.style.cursor="move",(B=this._activeTabItem)==null||B.addEventListener("pointermove",this._moveAction))},ot.LongPressDelay)},this._upAction=s=>{var c,d,u;if(this._longPressTimer&&(clearTimeout(this._longPressTimer),this._longPressTimer=null),!this._activeTabItem)return;this._closeAutoScroll(),this._activeTabItem.disableFixed(),this.updateItems();const l=(c=this._activeTabItem)==null?void 0:c.getSlideTabItem();l&&(l.style.cursor="",l.releasePointerCapture(s.pointerId),(d=this._activeTabItem)==null||d.removeEventListener("pointermove",this._moveAction),(u=this._activeTabItem)==null||u.removeEventListener("pointerup",this._upAction),this._config.onSlideEnd&&this._activeTabItemIndex!==this._compareIndex&&(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(e){let t=e.target;for(;t!=null&&t!==document.body;){if(t.getAttribute("data-slide-skip"))return!0;t=t.parentElement}return!1}static keepLastIndex(e){setTimeout(()=>{const t=window.getSelection();t&&(t.selectAllChildren(e),t.collapseToEnd())})}static keepSelectAll(e){setTimeout(()=>{const t=window.getSelection();if(!t)return;const n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)})}update(e){this._config.currentIndex=e,this._initConfig(),this.removeListener(),this.addListener()}primeval(){return this._slideTabBar}updateItems(){for(let e=0;e<this._slideTabItems.length;e++)this._slideTabItems[e].animate().cancel(),this._slideTabItems[e].translateX(0),this._slideTabItems[e].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 e=this._slideTabBar.parentElement;return e?this._slideTabBar.scrollWidth-e.clientWidth===this._slideTabBar.scrollLeft:!1}addListener(){this._slideTabBar.addEventListener("wheel",this._wheelAction),this._slideTabItems.forEach(e=>{e.addEventListener("pointerdown",this._downAction)})}removeListener(){this._slideTabBar.removeEventListener("wheel",this._wheelAction),this._slideTabItems.forEach(e=>{e.removeEventListener("pointerdown",this._downAction)})}setScroll(e){if(this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e),e>0){const t=this.calculateLeftScrollX();this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+t)}else if(e<0){const t=this.calculateRightScrollX();this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+t)}this._config.onScroll({leftEnd:this.isLeftEnd(),rightEnd:this.isRightEnd()})}flipPage(e){if(e>0){const t=this.calculateLeftScrollX(!0);this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+t)}else if(e<0){const t=this.calculateRightScrollX(!0);this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+t)}this._config.onScroll({leftEnd:this.isLeftEnd(),rightEnd:this.isRightEnd()})}calculateLeftScrollX(e){let t=0;const n=4;return this._slideTabItems.some(o=>{const r=this._slideTabBar.getBoundingClientRect(),s=r.left+r.width,l=o.getSlideTabItem().getBoundingClientRect(),c=l.left,d=l.width;return c<s&&c+d+n*2>s?(t=e?c-r.left-n:c+d-s+n,!0):!1}),t}calculateRightScrollX(e){let t=0;const n=4;return this._slideTabItems.some(o=>{const r=this._slideTabBar.getBoundingClientRect(),s=r.left,l=o.getSlideTabItem().getBoundingClientRect(),c=l.left,d=l.width;return c-n*2<s&&c+d>s?(t=e?c+d-r.left-r.width+n:c-s-n,!0):!1}),t}destroy(){this._downActionX=0,this._moveActionX=0,this._compareDirection=0,this._compareIndex=0,this._slideTabItems=[],this._activeTabItem=null,this.removeListener()}_hasEditItem(){for(let e=0;e<this._slideTabItems.length;e++)if(this._slideTabItems[e].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(e){const t=this.getBoundingRect(),n=e.pageX-t.x;n<this._leftBoundingLine&&(this._scrollIncremental=-Math.min(Math.abs(n-this._leftBoundingLine)*.1,50))}_scrollRight(e){const t=this.getBoundingRect(),n=e.pageX-t.x;n>t.width-this._rightBoundingLine&&(this._scrollIncremental=Math.min(Math.abs(n-(t.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 e=0;e<this._slideTabItems.length;e++){const t=this._slideTabItems[e],n=this._slideTabItems[e+1];n&&t.after(n)}}_compareLeft(){if(this._activeTabItem&&this._activeTabItemIndex){const e=this._slideTabItems.findIndex(r=>r.equals(this._activeTabItem)),t=this._slideTabItems.length,n=[];for(let r=0;r<e&&!(r>=e);r++)n.push(this._slideTabItems[r]);for(let r=e+1;r<t;r++)this._slideTabItems[r].animate().translateX(0);let o=!0;for(let r=n.length-1;r>=0;r--){const s=n[r];Ze.leftLine(this._activeTabItem)<s.getMidLine()?(s.animate().translateX(this._activeTabItem.getWidth()),this._compareIndex=r,o=!1):(s.animate().translateX(0),o&&(this._compareIndex=this._activeTabItemIndex))}}}_compareRight(){if(this._activeTabItem){const e=this._slideTabItems.findIndex(r=>r.equals(this._activeTabItem)),t=this._slideTabItems.length,n=[];for(let r=e+1;r<t;r++)n.push(this._slideTabItems[r]);for(let r=0;r<e;r++)this._slideTabItems[r].animate().translateX(0);let o=!0;for(let r=0;r<n.length;r++){const s=n[r];Ze.rightLine(this._activeTabItem)>s.getMidLine()?(s.animate().translateX(-this._activeTabItem.getWidth()),this._compareIndex=e+r+1,o=!1):(s.animate().translateX(0),o&&(this._compareIndex=this._activeTabItemIndex))}}}_initConfig(){const e=this._slideTabBar.querySelectorAll(`.${this._config.slideTabBarItemClassName??"slide-tab-item"}`);this._downActionX=0,this._moveActionX=0,this._compareDirection=0,this._compareIndex=0,this._slideTabItems=Ze.make(e,this),this._activeTabItemIndex=this._config.currentIndex,this._activeTabItem=this._slideTabItems[this._activeTabItemIndex]}};v(ot,"LongPressDelay",500),v(ot,"DoubleClickDelay",300);let xt=ot;function ih(){const[i,e]=L.useState([]),[t,n]=L.useState(""),[o,r]=L.useState(""),s=L.useRef({slideTabBar:null}),l=L.useRef(null),c=W.useDependency(a.IUniverInstanceService),d=W.useDependency(a.ICommandService),u=W.useDependency(mt),h=W.useDependency(a.LocaleService),m=W.useDependency(R.IConfirmService),S=c.getCurrentUniverSheetInstance();L.useEffect(()=>{E();const A=g(),H=T(),V=[y(),O(),x(),D()];return()=>{H.dispose(),A.destroy(),V.forEach(F=>F.unsubscribe())}},[]),L.useEffect(()=>{i.length>0&&M()},[i]);const g=()=>{const A=new xt({slideTabBarClassName:ge.slideTabBar,slideTabBarItemActiveClassName:ge.slideTabActive,slideTabBarItemClassName:ge.slideTabItem,slideTabBarSpanEditClassName:ge.slideTabSpanEdit,slideTabBarItemAutoSort:!0,slideTabBarContainer:l.current,currentIndex:0,onChangeName:(H,V)=>{d.executeCommand(f.SetWorksheetNameCommand.id,{subUnitId:H,name:V})},onSlideEnd:(H,V)=>{d.executeCommand(f.SetWorksheetOrderCommand.id,{order:V})},onChangeTab:(H,V)=>{d.executeCommand(f.SetWorksheetActivateCommand.id,{subUnitId:V,unitId:S.getUnitId()})},onScroll:H=>{u.setScroll(H)},onNameCheckAlert:H=>_(H)||I(H)});return s.current.slideTabBar=A,B(A),A},_=A=>{if(A.trim()===""){const H="sheetNameEmptyAlert";return m.open({id:H,title:{title:h.t("sheetConfig.sheetNameErrorTitle")},children:{title:h.t("sheetConfig.sheetNameCannotIsEmptyError")},cancelText:h.t("button.cancel"),confirmText:h.t("button.confirm"),onClose(){m.close(H),C()},onConfirm(){m.close(H),C()}}),!0}return!1},I=A=>{const H=c.getCurrentUniverSheetInstance();if(H.getActiveSheet().getName()===A)return!1;const j=H.checkSheetName(A);if(j){const $="sheetNameRepeatAlert";m.open({id:$,title:{title:h.t("sheetConfig.sheetNameErrorTitle")},children:{title:h.t("sheetConfig.sheetNameAlreadyExistsError")},cancelText:h.t("button.cancel"),confirmText:h.t("button.confirm"),onClose(){m.close($),b()},onConfirm(){m.close($),b()}})}return j},C=()=>{var H,V;const A=(V=(H=s.current.slideTabBar)==null?void 0:H.getActiveItem())==null?void 0:V.getEditor();A&&A.focus()},b=()=>{var A,H;(H=(A=s.current.slideTabBar)==null?void 0:A.getActiveItem())==null||H.setEditor()},M=()=>{var H;const A=i.findIndex(V=>V.selected);(H=s.current.slideTabBar)==null||H.update(A)},T=()=>d.onCommandExecuted(A=>{switch(A.id){case f.SetTabColorMutation.id:case f.SetWorksheetHideMutation.id:case f.RemoveSheetMutation.id:case f.SetWorksheetNameMutation.id:case f.InsertSheetMutation.id:case f.SetWorksheetOrderMutation.id:case f.SetWorksheetActiveOperation.id:E();break}}),E=()=>{const A=S.getActiveSheet().getSheetId();n(A);const V=S.getSheets().filter(F=>!F.isSheetHidden()).map((F,j)=>({sheetId:F.getSheetId(),label:F.getName(),index:j,selected:F.getStatus()===a.BooleanNumber.TRUE,color:F.getTabColor()??void 0}));e(V)},y=()=>u.scroll$.subscribe(A=>{U(A)}),O=()=>u.scrollX$.subscribe(A=>{var H;(H=s.current.slideTabBar)==null||H.flipPage(A)}),x=()=>u.renameId$.subscribe(()=>{b()}),D=()=>u.addSheet$.subscribe(()=>{var A;(A=s.current.slideTabBar)==null||A.getScrollbar().scrollRight()}),U=A=>{const{leftEnd:H,rightEnd:V}=A;let F="";H&&V?F="":H&&!V?F="inset -10px 0px 10px -10px rgba(0, 0, 0, 0.2)":!H&&V?F="inset 10px 0px 10px -10px rgba(0, 0, 0, 0.2)":!H&&!V&&(F="inset 10px 0px 10px -10px rgba(0, 0, 0, 0.2), inset -10px 0px 10px -10px rgba(0, 0, 0, 0.2)"),r(F)},N=A=>{u.setScroll({leftEnd:A.isLeftEnd(),rightEnd:A.isRightEnd()})},B=A=>{var F;const H=(F=l.current)==null?void 0:F.querySelector(`.${ge.slideTabBar}`);if(!H)return;new ResizeObserver(()=>{N(A)}).observe(H)};return p.jsx("div",{className:ge.slideTabBarContainer,ref:l,children:p.jsx("div",{className:ge.slideTabBar,style:{boxShadow:o},children:i.map(A=>L.createElement(Ju,{...A,key:A.sheetId,selected:t===A.sheetId}))})})}const go=100,oh=()=>{const[i,e]=L.useState(!0),[t,n]=L.useState(!0),o=W.useDependency(a.ICommandService),r=W.useDependency(mt);L.useEffect(()=>{const u=r.scroll$.subscribe(h=>{s(h)});return()=>{u.unsubscribe()}},[]);const s=u=>{const{leftEnd:h,rightEnd:m}=u;e(h),n(m)},l=()=>{o.executeCommand(f.InsertSheetCommand.id),setTimeout(()=>{r.setAddSheet(0)},0)},c=()=>{r.setScrollX(-go)},d=()=>{r.setScrollX(go)};return p.jsxs("div",{className:$t.sheetBar,children:[p.jsxs("div",{className:$t.sheetBarOptions,children:[p.jsx(gn,{onClick:l,children:p.jsx(Qs,{})}),p.jsx(zu,{})]}),p.jsx(ih,{}),(!i||!t)&&p.jsxs("div",{className:`${$t.sheetBarOptions} ${$t.sheetBarOptionsDivider}`,children:[p.jsx(gn,{disabled:i,onClick:c,children:p.jsx($i,{style:{transform:"rotateZ(180deg)"}})}),p.jsx(gn,{disabled:t,onClick:d,children:p.jsx($i,{})})]})]})};class rh{constructor(){v(this,"_functions",[{func:G.FUNCTION_NAMES_STATISTICAL.MAX,filter:e=>{var t,n;return(((t=e.find(o=>o.func===G.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:t.value)??0)>1&&(((n=e.find(o=>o.func===G.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:n.value)??0)>0}},{func:G.FUNCTION_NAMES_STATISTICAL.MIN,filter:e=>{var t,n;return(((t=e.find(o=>o.func===G.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:t.value)??0)>1&&(((n=e.find(o=>o.func===G.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:n.value)??0)>0}},{func:G.FUNCTION_NAMES_MATH.SUM,filter:e=>{var t,n;return(((t=e.find(o=>o.func===G.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:t.value)??0)>1&&(((n=e.find(o=>o.func===G.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:n.value)??0)>0}},{func:G.FUNCTION_NAMES_STATISTICAL.COUNTA,filter:e=>{var t;return(((t=e.find(n=>n.func===G.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:t.value)??0)>1}},{func:G.FUNCTION_NAMES_STATISTICAL.COUNT,filter:e=>{var t,n;return(((t=e.find(o=>o.func===G.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:t.value)??0)>1&&(((n=e.find(o=>o.func===G.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:n.value)??0)>0}},{func:G.FUNCTION_NAMES_STATISTICAL.AVERAGE,filter:e=>{var t,n;return(((t=e.find(o=>o.func===G.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:t.value)??0)>1&&(((n=e.find(o=>o.func===G.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:n.value)??0)>0}}]);v(this,"_state$",new k.BehaviorSubject(null));v(this,"state$",this._state$.asObservable())}dispose(){this._state$.complete()}setState(e){const t=[];e==null||e.forEach(n=>{const o=this._functions.find(r=>r.func===n.func);o&&(o.filter===void 0||o.filter(e))&&t.push(n)}),this._state$.next(t)}getState(){return this._state$.getValue()}getFunctions(){return this._functions}addFunctions(e){this._functions.push(...e)}}const bi=P.createIdentifier("univer.sheet-status-bar.service"),sh="univer-status-bar",lh="univer-single-mode",ah="univer-status-bar-div",ch="univer-statistic-list",dh="univer-statistic-list-column",uh="univer-statistic-item",hh="univer-statistic-picker",mh="univer-statistic-picker-item",Sh="univer-statistic-more",it={statusBar:sh,singleMode:lh,statusBarDiv:ah,statisticList:ch,statisticListColumn:dh,statisticItem:uh,statisticPicker:hh,statisticPickerItem:mh,statisticMore:Sh},Yn={[G.FUNCTION_NAMES_MATH.SUM]:"statusbar.sum",[G.FUNCTION_NAMES_STATISTICAL.AVERAGE]:"statusbar.average",[G.FUNCTION_NAMES_STATISTICAL.MIN]:"statusbar.min",[G.FUNCTION_NAMES_STATISTICAL.MAX]:"statusbar.max",[G.FUNCTION_NAMES_STATISTICAL.COUNT]:"statusbar.count",[G.FUNCTION_NAMES_STATISTICAL.COUNTA]:"statusbar.countA",[G.FUNCTION_NAMES_COMPATIBILITY.CONCATENATE]:"concatenate"},Zn=i=>{const e=W.useDependency(a.LocaleService),t=W.useDependency(R.IMessageService),n=W.useDependency(R.IClipboardInterfaceService),o=_h(i.value),r=async()=>{await n.writeText(i.value.toString()),t.show({type:ie.MessageType.Success,content:e.t("statusbar.copied")})};return p.jsx(ie.Tooltip,{title:e.t("statusbar.clickToCopy"),placement:"top",children:p.jsx("div",{className:it.statisticItem,onClick:r,children:p.jsx("span",{children:`${e.t((Yn==null?void 0:Yn[i.name])||i.name)}: ${o}`})},i.name)})};function _h(i){return typeof i!="number"?"Invalid input":i>=1e8?i.toExponential(2):i.toLocaleString()}const fo=800,gh=3,fh=()=>{const[i,e]=L.useState(window.innerWidth<fo),[t,n]=L.useState(!0),o=W.useDependency(bi),r=o.getFunctions().map((m,S)=>({name:m.func,value:0,show:!0,disable:!1})),[s,l]=L.useState(r),c=s.find(m=>m.show&&!m.disable),d=i&&c?[c]:s.filter(m=>m.show&&!m.disable);L.useEffect(()=>{const m=o.state$.subscribe(S=>{if(!S||S.length===0)n(!1);else{n(!0);const g=s.map(_=>{const I=S.find(C=>C.func===_.name);return I?(_.value=I.value,_.disable=!1):_.disable=!0,_});l(g)}});return()=>{m.unsubscribe()}},[o]);const u=ph(()=>{const m=window.innerWidth<fo;i!==m&&e(m)},100);L.useEffect(()=>(window.addEventListener("resize",u),()=>{window.removeEventListener("resize",u)}),[i]);let h=null;if(d.length>gh){const m=[];d.forEach((S,g)=>{g%2===0&&m.push(d.slice(g,g+2))}),h=p.jsxs(p.Fragment,{children:[" ",m.map((S,g)=>p.jsxs("div",{className:it.statisticListColumn,children:[(S==null?void 0:S[0])&&p.jsx(Zn,{...S==null?void 0:S[0]},S==null?void 0:S[0].name),(S==null?void 0:S[1])&&p.jsx(Zn,{...S==null?void 0:S[1]},S==null?void 0:S[1].name)]},`stat-col-${g}`))," "]})}else h=p.jsx(p.Fragment,{children:d.map(m=>p.jsx(Zn,{...m},m.name))});return t&&p.jsxs("div",{className:Tt(it.statusBar,{[it.singleMode]:i}),children:[p.jsx("div",{className:Tt(it.statisticList),children:h}),p.jsx("div",{className:it.statusBarDiv})]})};function ph(i,e){let t;return function(...n){const o=this,r=function(){t=null,i.apply(o,n)};clearTimeout(t),t=setTimeout(r,e)}}function vh(){return p.jsxs("section",{className:Sr.sheetContainer,"data-range-selector":!0,children:[p.jsx(oh,{}),p.jsx(fh,{}),p.jsx(ru,{})]})}function Ch(){return p.jsx(p.Fragment,{children:p.jsx(Ru,{})})}function Ih(){return p.jsxs(p.Fragment,{children:[p.jsx(au,{}),p.jsx(Du,{})]})}function Rh(i){const e=i.get(f.BorderStyleManagerService);return{id:f.SetBorderBasicCommand.id,icon:new k.Observable(t=>{const n="AllBorderSingle",o=i.get(f.BorderStyleManagerService),r=i.get(a.ICommandService).onCommandExecuted(s=>{if(s.id!==f.SetBorderBasicCommand.id)return;const{type:c}=o.getBorderInfo(),d=Mr.find(h=>h.value===c),u=(d==null?void 0:d.icon)??n;t.next(u)});return t.next(n),r.dispose}),group:R.MenuGroup.TOOLBAR_FORMAT,tooltip:"toolbar.border.main",positions:[R.MenuPosition.TOOLBAR_START],type:R.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:br,hoverable:!1},value$:e.borderInfo$}],value$:e.borderInfo$,hidden$:R.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}const Pn="sheet.menu.clear-selection";function bh(){return{id:Pn,group:R.MenuGroup.CONTEXT_MENU_FORMAT,type:R.MenuItemType.SUBITEMS,icon:"ClearFormat",title:"rightClick.clearSelection",positions:[R.MenuPosition.CONTEXT_MENU,ee.COL_HEADER_CONTEXT_MENU,ee.ROW_HEADER_CONTEXT_MENU]}}function Mh(){return{id:f.ClearSelectionContentCommand.id,type:R.MenuItemType.BUTTON,title:"rightClick.clearContent",positions:[Pn]}}function wh(){return{id:f.ClearSelectionFormatCommand.id,type:R.MenuItemType.BUTTON,title:"rightClick.clearFormat",positions:[Pn]}}function Th(){return{id:f.ClearSelectionAllCommand.id,type:R.MenuItemType.BUTTON,title:"rightClick.clearAll",positions:[Pn]}}const Lt="sheet.menu.delete";function Eh(){return{id:Lt,group:R.MenuGroup.CONTEXT_MENU_LAYOUT,type:R.MenuItemType.SUBITEMS,title:"rightClick.delete",icon:"Reduce",positions:[R.MenuPosition.CONTEXT_MENU]}}function yh(){return{id:f.RemoveColCommand.id,group:R.MenuGroup.CONTEXT_MENU_LAYOUT,type:R.MenuItemType.BUTTON,icon:"DeleteColumn",positions:[Lt,ee.COL_HEADER_CONTEXT_MENU],title:"rightClick.deleteSelectedColumn"}}function Oh(){return{id:f.RemoveRowCommand.id,group:R.MenuGroup.CONTEXT_MENU_LAYOUT,type:R.MenuItemType.BUTTON,icon:"DeleteRow",positions:[Lt,ee.ROW_HEADER_CONTEXT_MENU],title:"rightClick.deleteSelectedRow"}}function xh(){return{id:f.DeleteRangeMoveLeftCommand.id,group:R.MenuGroup.CONTEXT_MENU_LAYOUT,type:R.MenuItemType.BUTTON,title:"rightClick.moveLeft",icon:"DeleteCellShiftLeft",positions:[Lt]}}function Ah(){return{id:f.DeleteRangeMoveUpCommand.id,group:R.MenuGroup.CONTEXT_MENU_LAYOUT,type:R.MenuItemType.BUTTON,title:"rightClick.moveUp",icon:"DeleteCellShiftUp",positions:[Lt]}}const Mi="sheet.menu.col-insert";function Hh(){return{id:Mi,group:R.MenuGroup.CONTEXT_MENU_LAYOUT,type:R.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"Insert",positions:[ee.COL_HEADER_CONTEXT_MENU]}}const wi="sheet.menu.row-insert";function Dh(){return{id:wi,group:R.MenuGroup.CONTEXT_MENU_LAYOUT,type:R.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"Insert",positions:[ee.ROW_HEADER_CONTEXT_MENU]}}const Ut="sheet.menu.cell-insert";function Nh(){return{id:Ut,group:R.MenuGroup.CONTEXT_MENU_LAYOUT,type:R.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"Insert",positions:[R.MenuPosition.CONTEXT_MENU]}}function Ph(i){const e=i.get(f.SelectionManagerService);return{id:f.InsertRowBeforeCommand.id,type:R.MenuItemType.BUTTON,title:"rightClick.insertRowBefore",icon:"InsertRowAbove",positions:[wi,Ut],hidden$:new k.Observable(t=>{const n=e.getSelections();t.next((n==null?void 0:n.length)!==1)})}}function Lh(i){const e=i.get(f.SelectionManagerService);return{id:f.InsertRowAfterCommand.id,type:R.MenuItemType.BUTTON,positions:[wi],title:"rightClick.insertRow",icon:"InsertRowBelow",hidden$:new k.Observable(t=>{const n=e.getSelections();t.next((n==null?void 0:n.length)!==1)})}}function Uh(i){const e=i.get(f.SelectionManagerService);return{id:f.InsertColBeforeCommand.id,type:R.MenuItemType.BUTTON,positions:[Mi,Ut],title:"rightClick.insertColumnBefore",icon:"LeftInsertColumn",hidden$:new k.Observable(t=>{const n=e.getSelections();t.next((n==null?void 0:n.length)!==1)})}}function kh(i){const e=i.get(f.SelectionManagerService);return{id:f.InsertColAfterCommand.id,type:R.MenuItemType.BUTTON,positions:[Mi],title:"rightClick.insertColumn",icon:"RightInsertColumn",hidden$:new k.Observable(t=>{const n=e.getSelections();t.next((n==null?void 0:n.length)!==1)})}}function Bh(){return{id:f.InsertRangeMoveRightCommand.id,type:R.MenuItemType.BUTTON,title:"rightClick.moveRight",icon:"InsertCellShiftRight",positions:[Ut]}}function Vh(){return{id:f.InsertRangeMoveDownCommand.id,type:R.MenuItemType.BUTTON,title:"rightClick.moveDown",icon:"InsertCellDown",positions:[Ut]}}function Fh(i){return{id:Ae.id,icon:"MergeAllSingle",tooltip:"toolbar.mergeCell.main",positions:[R.MenuPosition.TOOLBAR_START],group:R.MenuGroup.TOOLBAR_LAYOUT,type:R.MenuItemType.SUBITEMS,hidden$:R.getMenuHiddenObservable(i,a.UniverInstanceType.SHEET)}}function jh(i){return{id:gr.id,type:R.MenuItemType.BUTTON,title:"merge.all",icon:"MergeAllSingle",positions:[Ae.id]}}function Wh(i){return{id:fr.id,type:R.MenuItemType.BUTTON,title:"merge.vertical",icon:"VerticalIntegrationSingle",positions:[Ae.id]}}function $h(i){return{id:pr.id,type:R.MenuItemType.BUTTON,title:"merge.horizontal",icon:"HorizontalMergeSingle",positions:[Ae.id]}}function zh(i){return{id:f.RemoveWorksheetMergeCommand.id,type:R.MenuItemType.BUTTON,title:"merge.cancel",icon:"CancelMergeSingle",positions:[Ae.id]}}function Xh(){return{id:Cr.id,type:R.MenuItemType.BUTTON,positions:[ee.SHEET_BAR],title:"sheetConfig.delete"}}function Yh(){return{id:f.CopySheetCommand.id,type:R.MenuItemType.BUTTON,positions:[ee.SHEET_BAR],title:"sheetConfig.copy"}}function Zh(){return{id:Rr.id,type:R.MenuItemType.BUTTON,positions:[ee.SHEET_BAR],title:"sheetConfig.rename"}}function Gh(){return{id:f.SetTabColorCommand.id,title:"sheetConfig.changeColor",positions:[ee.SHEET_BAR],type:R.MenuItemType.SELECTOR,selections:[{label:{name:Hn,hoverable:!1}}]}}function Kh(){return{id:f.SetWorksheetHideCommand.id,type:R.MenuItemType.BUTTON,positions:[ee.SHEET_BAR],title:"sheetConfig.hide"}}function qh(){return{id:Ir.id,type:R.MenuItemType.BUTTON,positions:[ee.SHEET_BAR],title:"sheetConfig.unhide"}}const Jh={id:f.SetRowHiddenCommand.id,preconditions:i=>Z(i),binding:R.KeyCode.Digit9|R.MetaKeys.CTRL_COMMAND},Qh={id:f.SetColHiddenCommand.id,preconditions:i=>Z(i),binding:R.KeyCode.Digit0|R.MetaKeys.CTRL_COMMAND|R.MetaKeys.SHIFT},em={id:me.id,description:"shortcut.sheet.select-below-cell",group:"3_sheet-view",binding:R.KeyCode.ARROW_DOWN,priority:100,preconditions:Z,staticParameters:{direction:a.Direction.DOWN}},tm={id:me.id,description:"shortcut.sheet.select-up-cell",group:"3_sheet-view",binding:R.KeyCode.ARROW_UP,priority:100,preconditions:Z,staticParameters:{direction:a.Direction.UP}},nm={id:me.id,description:"shortcut.sheet.select-left-cell",group:"3_sheet-view",binding:R.KeyCode.ARROW_LEFT,priority:100,preconditions:Z,staticParameters:{direction:a.Direction.LEFT}},im={id:me.id,description:"shortcut.sheet.select-right-cell",group:"3_sheet-view",binding:R.KeyCode.ARROW_RIGHT,priority:100,preconditions:Z,staticParameters:{direction:a.Direction.RIGHT}},om={id:Ke.id,description:"shortcut.sheet.select-next-cell",group:"3_sheet-view",binding:R.KeyCode.TAB,priority:100,preconditions:Z,staticParameters:{direction:a.Direction.RIGHT,keycode:R.KeyCode.TAB}},rm={id:Ke.id,description:"shortcut.sheet.select-previous-cell",group:"3_sheet-view",binding:R.KeyCode.TAB|R.MetaKeys.SHIFT,priority:100,preconditions:Z,staticParameters:{direction:a.Direction.LEFT,keycode:R.KeyCode.TAB}},sm={id:Ke.id,description:"shortcut.sheet.select-below-cell",group:"3_sheet-view",binding:R.KeyCode.ENTER,priority:100,preconditions:Z,staticParameters:{direction:a.Direction.DOWN,keycode:R.KeyCode.ENTER}},lm={id:Ke.id,description:"shortcut.sheet.select-up-cell",group:"3_sheet-view",binding:R.KeyCode.ENTER|R.MetaKeys.SHIFT,priority:100,preconditions:Z,staticParameters:{direction:a.Direction.UP,keycode:R.KeyCode.ENTER}},am={id:me.id,description:"shortcut.sheet.select-below-value-cell",group:"3_sheet-view",binding:R.KeyCode.ARROW_DOWN|R.MetaKeys.CTRL_COMMAND,preconditions:Z,staticParameters:{direction:a.Direction.DOWN,jumpOver:be.moveGap}},cm={id:me.id,description:"shortcut.sheet.select-up-value-cell",group:"3_sheet-view",binding:R.KeyCode.ARROW_UP|R.MetaKeys.CTRL_COMMAND,preconditions:Z,staticParameters:{direction:a.Direction.UP,jumpOver:be.moveGap}},dm={id:me.id,description:"shortcut.sheet.select-left-value-cell",group:"3_sheet-view",binding:R.KeyCode.ARROW_LEFT|R.MetaKeys.CTRL_COMMAND,preconditions:Z,staticParameters:{direction:a.Direction.LEFT,jumpOver:be.moveGap}},um={id:me.id,description:"shortcut.sheet.select-right-value-cell",group:"3_sheet-view",binding:R.KeyCode.ARROW_RIGHT|R.MetaKeys.CTRL_COMMAND,preconditions:Z,staticParameters:{direction:a.Direction.RIGHT,jumpOver:be.moveGap}},hm={id:Me.id,description:"shortcut.sheet.expand-selection-down",group:"3_sheet-view",binding:R.KeyCode.ARROW_DOWN|R.MetaKeys.SHIFT,preconditions:Z,staticParameters:{direction:a.Direction.DOWN}},mm={id:Me.id,description:"shortcut.sheet.expand-selection-up",group:"3_sheet-view",binding:R.KeyCode.ARROW_UP|R.MetaKeys.SHIFT,preconditions:Z,staticParameters:{direction:a.Direction.UP}},Sm={id:Me.id,description:"shortcut.sheet.expand-selection-left",group:"3_sheet-view",binding:R.KeyCode.ARROW_LEFT|R.MetaKeys.SHIFT,preconditions:Z,staticParameters:{direction:a.Direction.LEFT}},_m={id:Me.id,description:"shortcut.sheet.expand-selection-right",group:"3_sheet-view",binding:R.KeyCode.ARROW_RIGHT|R.MetaKeys.SHIFT,preconditions:Z,staticParameters:{direction:a.Direction.RIGHT}},gm={id:Me.id,description:"shortcut.sheet.expand-selection-to-below-gap",group:"3_sheet-view",binding:R.KeyCode.ARROW_DOWN|R.MetaKeys.SHIFT|R.MetaKeys.CTRL_COMMAND,preconditions:Z,staticParameters:{direction:a.Direction.DOWN,jumpOver:be.moveGap}},fm={id:Me.id,description:"shortcut.sheet.expand-selection-to-up-gap",group:"3_sheet-view",binding:R.KeyCode.ARROW_UP|R.MetaKeys.SHIFT|R.MetaKeys.CTRL_COMMAND,preconditions:Z,staticParameters:{direction:a.Direction.UP,jumpOver:be.moveGap}},pm={id:Me.id,description:"shortcut.sheet.expand-selection-to-left-gap",group:"3_sheet-view",binding:R.KeyCode.ARROW_LEFT|R.MetaKeys.SHIFT|R.MetaKeys.CTRL_COMMAND,preconditions:Z,staticParameters:{direction:a.Direction.LEFT,jumpOver:be.moveGap}},vm={id:Me.id,description:"shortcut.sheet.expand-selection-to-right-gap",group:"3_sheet-view",binding:R.KeyCode.ARROW_RIGHT|R.MetaKeys.SHIFT|R.MetaKeys.CTRL_COMMAND,preconditions:Z,staticParameters:{direction:a.Direction.RIGHT,jumpOver:be.moveGap}},Cm={id:Ao.id,description:"shortcut.sheet.select-all",group:"3_sheet-view",binding:R.KeyCode.A|R.MetaKeys.CTRL_COMMAND,preconditions:Z,staticParameters:{expandToGapFirst:!0,loop:!0}},Im={id:Si.id,description:"shortcut.sheet.set-bold",group:"4_sheet-edit",preconditions:i=>Z(i),binding:R.KeyCode.B|R.MetaKeys.CTRL_COMMAND},Rm={id:_i.id,description:"shortcut.sheet.set-italic",group:"4_sheet-edit",preconditions:i=>Z(i),binding:R.KeyCode.I|R.MetaKeys.CTRL_COMMAND},bm={id:gi.id,description:"shortcut.sheet.set-underline",group:"4_sheet-edit",preconditions:i=>Z(i),binding:R.KeyCode.U|R.MetaKeys.CTRL_COMMAND},Mm={id:fi.id,description:"shortcut.sheet.set-strike-through",group:"4_sheet-edit",preconditions:i=>Z(i),binding:R.KeyCode.X|R.MetaKeys.SHIFT|R.MetaKeys.CTRL_COMMAND},wm={id:f.ClearSelectionContentCommand.id,preconditions:i=>Z(i),binding:R.KeyCode.DELETE,mac:R.KeyCode.BACKSPACE},Tm={id:Nn.id,description:"shortcut.sheet.zoom-in",binding:R.KeyCode.EQUAL|R.MetaKeys.CTRL_COMMAND,group:"3_sheet-view",staticParameters:{delta:.2}},Em={id:Nn.id,description:"shortcut.sheet.zoom-out",binding:R.KeyCode.MINUS|R.MetaKeys.CTRL_COMMAND,group:"3_sheet-view",staticParameters:{delta:-.2}},ym={id:Nn.id,description:"shortcut.sheet.reset-zoom",binding:R.KeyCode.Digit0|R.MetaKeys.CTRL_COMMAND,group:"3_sheet-view",staticParameters:{reset:!0}};var Om=Object.defineProperty,xm=Object.getOwnPropertyDescriptor,Am=(i,e,t,n)=>{for(var o=n>1?void 0:n?xm(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Om(e,t,o),o},nt=(i,e)=>(t,n)=>e(t,n,i);let fn=class extends a.Disposable{constructor(i,e,t,n,o,r){super(),this._injector=i,this._componentManager=e,this._commandService=t,this._shortcutService=n,this._menuService=o,this._uiController=r,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Ci,ea)),this.disposeWithMe(i.register(br,eu)),this.disposeWithMe(i.register(Hn,ie.ColorPicker)),this.disposeWithMe(i.register(sr,Xl)),this.disposeWithMe(i.register(se,Yl)),this.disposeWithMe(i.register(lr,Kl))}_initCommands(){[gr,Ae,pr,fr,Nn,Me,me,Ke,Rr,Cr,Ye,Ao,_r,On,f.SetBoldCommand,Ot,Re,Si,_i,gi,fi,Ul,kl,Ko,qo,wn,f.SetItalicCommand,f.SetStrikeThroughCommand,f.SetFontFamilyCommand,f.SetFontSizeCommand,pi,er,vi,tr,ct,rn,An,nr,ir,or,f.SetUnderlineCommand,Ri,xe,Ir,vr].forEach(i=>{this.disposeWithMe(this._commandService.registerCommand(i))})}_initMenus(){[fa,pa,va,Ca,Ia,Ra,ba,Mh,wh,Th,bh,Hh,Dh,Nh,Ph,Lh,Uh,kh,Oh,Aa,Da,Ha,Na,yh,Pa,Ma,La,Eh,xh,Ah,Bh,Vh,Ea,ya,Oa,xa,wa,Ta,ta,na,ia,oa,ra,la,aa,ca,da,ua,ha,Rh,Fh,jh,Wh,$h,zh,ma,Sa,_a,ga,Xh,Yh,Zh,Gh,Kh,qh].forEach(i=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(i)))})}_initShortcuts(){[em,tm,nm,im,om,rm,sm,lm,am,cm,dm,um,hm,mm,Sm,_m,gm,fm,pm,vm,Cm,Tm,Em,ym,Im,Rm,bm,Mm,wm,...rc(),sc,lc,cc,dc,uc,ac,Jh,Qh].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_initWorkbenchParts(){this.disposeWithMe(this._uiController.registerHeaderComponent(()=>W.connectInjector(Ch,this._injector))),this.disposeWithMe(this._uiController.registerFooterComponent(()=>W.connectInjector(vh,this._injector))),this.disposeWithMe(this._uiController.registerContentComponent(()=>W.connectInjector(Ih,this._injector)))}_init(){this._initCustomComponents(),this._initCommands(),this._initMenus(),this._initShortcuts(),this._initWorkbenchParts()}};fn=Am([a.OnLifecycle(a.LifecycleStages.Ready,fn),nt(0,P.Inject(P.Injector)),nt(1,P.Inject(R.ComponentManager)),nt(2,a.ICommandService),nt(3,R.IShortcutService),nt(4,R.IMenuService),nt(5,R.IUIController)],fn);var Hm=Object.defineProperty,Dm=Object.getOwnPropertyDescriptor,Nm=(i,e,t,n)=>{for(var o=n>1?void 0:n?Dm(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Hm(e,t,o),o},Ct=(i,e)=>(t,n)=>e(t,n,i);let pn=class extends a.Disposable{constructor(e,t,n,o,r){super();v(this,"_calculateTimeout",-1);this._univerInstanceService=e,this._selectionManagerService=t,this._functionService=n,this._statusBarService=o,this._formulaDataModel=r,this._init()}_init(){this._registerSelectionListener()}_registerSelectionListener(){this.disposeWithMe(a.toDisposable(this._selectionManagerService.selectionMoving$.subscribe(e=>{e&&(clearTimeout(this._calculateTimeout),this._calculateTimeout=setTimeout(()=>{this._calculateSelection(e.map(t=>t.range))},100))}))),this.disposeWithMe(a.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(e=>{e&&this._calculateSelection(e.map(t=>t.range))})))}_calculateSelection(e){const t=this._univerInstanceService.getCurrentUniverSheetInstance(),n=t.getUnitId(),o=t.getActiveSheet().getSheetId(),r={},s=this._formulaDataModel.getArrayFormulaCellData();if(this._univerInstanceService.getCurrentUniverSheetInstance().getSheets().forEach(l=>{const c=l.getConfig();r[l.getSheetId()]={cellData:new a.ObjectMatrix(c.cellData),rowCount:c.rowCount,columnCount:c.columnCount}}),e!=null&&e.length){const l=e.map(h=>new G.RangeReferenceObject(h,o,n));l.forEach(h=>{h.setUnitData({[n]:r}),s&&h.setArrayFormulaCellData(G.convertUnitDataToRuntime(s))});const d=this._statusBarService.getFunctions().map(h=>{const m=this._functionService.getExecutor(h.func);if(!m)return;const S=l.map(_=>_.toArrayValueObject());if((m==null?void 0:m.calculate(...S)).getValue)return{func:h.func,value:(m==null?void 0:m.calculate(...S)).getValue()}});if(d.every(h=>h===void 0))return;const u=d.filter(h=>h!==void 0);this._statusBarService.setState(u)}else this._statusBarService.setState(null)}_isSingleCell(e){return e.startRow===e.endRow&&e.startColumn===e.endColumn}};pn=Nm([a.OnLifecycle(a.LifecycleStages.Ready,pn),Ct(0,a.IUniverInstanceService),Ct(1,P.Inject(f.SelectionManagerService)),Ct(2,G.IFunctionService),Ct(3,bi),Ct(4,P.Inject(G.FormulaDataModel))],pn);var Pm=Object.defineProperty,Lm=Object.getOwnPropertyDescriptor,Um=(i,e,t,n)=>{for(var o=n>1?void 0:n?Lm(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Pm(e,t,o),o},$e=(i,e)=>(t,n)=>e(t,n,i);let vn=class extends a.Disposable{constructor(i,e,t,n,o,r,s){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._selectionRenderService=o,this._selectionManagerService=r,this._scrollManagerService=s,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._zoomEventBinding()}_zoomEventBinding(){var e;const i=(e=this._getSheetObject())==null?void 0:e.scene;i!=null&&(i.getViewport(Y.VIEW_MAIN),this.disposeWithMe(a.toDisposable(i.onMouseWheelObserver.add((t,n)=>{if(!t.ctrlKey)return;const o=Math.abs(t.deltaX);let r=o<40?.2:o<80?.4:.2;r*=t.deltaY>0?-1:1,i.scaleX<1&&(r/=2);const s=this._currentUniverService.getCurrentUniverSheetInstance(),l=s.getActiveSheet(),c=l.getZoomRatio();let d=+parseFloat(`${c+r}`).toFixed(1);d=d>=4?4:d<=.1?.1:d,this._commandService.executeCommand(Ri.id,{zoomRatio:Math.round(d*10)/10,unitId:s.getUnitId(),subUnitId:l.getSheetId()}),t.preventDefault()}))))}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeletonBefore$.subscribe(i=>{if(i==null)return;const n=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getZoomRatio()||1;this._updateViewZoom(n)})))}_commandExecutedListener(){const i=[xe.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(i.includes(e.id)){const t=this._currentUniverService.getCurrentUniverSheetInstance(),n=t.getActiveSheet(),o=e.params,{unitId:r,subUnitId:s}=o;if(!(r===t.getUnitId()&&s===n.getSheetId()))return;const l=n.getConfig().zoomRatio||1;this._updateViewZoom(l)}}))}_updateViewZoom(i){const e=this._getSheetObject();e==null||e.scene.scale(i,i),e==null||e.spreadsheet.makeForceDirty()}_getSheetObject(){return ae(this._currentUniverService,this._renderManagerService)}};vn=Um([a.OnLifecycle(a.LifecycleStages.Rendered,vn),$e(0,P.Inject(exports.SheetSkeletonManagerService)),$e(1,a.IUniverInstanceService),$e(2,a.ICommandService),$e(3,w.IRenderManagerService),$e(4,ce),$e(5,P.Inject(f.SelectionManagerService)),$e(6,P.Inject(ke))],vn);var km=Object.defineProperty,Bm=Object.getOwnPropertyDescriptor,Vm=(i,e,t,n)=>{for(var o=n>1?void 0:n?Bm(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&km(e,t,o),o},It=(i,e)=>(t,n)=>e(t,n,i);exports.SheetCanvasView=class extends a.RxDisposable{constructor(t,n,o,r,s){super();v(this,"_scene");v(this,"_currentWorkbook");v(this,"_loadedMap",new Set);v(this,"_isLoadedEditor",!1);v(this,"_fps$",new k.BehaviorSubject(""));v(this,"fps$",this._fps$.asObservable());this._currentUniverService=t,this._commandService=n,this._renderManagerService=o,this._selectionRenderService=r,this._sheetSkeletonManagerService=s,this._currentUniverService.currentSheet$.subscribe(l=>{if(l==null)return;const c=l.getUnitId();this._loadedMap.has(c)||(this._currentWorkbook=l,this._addNewRender(),this._loadedMap.add(c))})}dispose(){this._fps$.complete()}_addNewRender(){const t=this._currentWorkbook,n=t.getUnitId(),o=t.getContainer(),r=t.getParentRenderUnitId();if(o!=null&&r!=null)throw new Error("container or parentRenderUnitId can only exist one");const s=o==null&&r!=null;s?this._renderManagerService.createRenderWithParent(n,r):this._renderManagerService.createRender(n);const l=this._renderManagerService.getRenderById(n);if(l==null)return;const{scene:c,engine:d}=l;c.openTransformer(),this._scene=c,c.addLayer(new w.Layer(c,[],0),new w.Layer(c,[],2)),l!=null&&this._addComponent(l),t.getShouldRenderLoopImmediately()&&!s&&d.runRenderLoop(()=>{c.render(),this._fps$.next(Math.round(d.getFps()).toString())}),this._renderManagerService.setCurrent(n)}_addComponent(t){const n=this._scene,o=this._currentWorkbook,r=o.getActiveSheet(),s=o.getUnitId(),l=r.getSheetId();this._addViewport(r);const c=new w.Spreadsheet(oe.MAIN),d=new w.SpreadsheetRowHeader(oe.ROW),u=new w.SpreadsheetColumnHeader(oe.COLUMN),h=new w.Rect(oe.LEFT_TOP,{zIndex:2,left:-1,top:-1,fill:"rgb(248, 249, 250)",stroke:"rgb(217, 217, 217)",strokeWidth:1});t.mainComponent=c,t.components.set(oe.MAIN,c),t.components.set(oe.ROW,d),t.components.set(oe.COLUMN,u),t.components.set(oe.LEFT_TOP,h),n.addObjects([c],Fi),n.addObjects([d,u,h],Ue),n.enableLayerCache(Fi,Ue),this._sheetSkeletonManagerService.setCurrent({sheetId:l,unitId:s})}_addViewport(t){const n=this._scene;if(n==null)return;const{rowHeader:o,columnHeader:r}=t.getConfig(),s=new w.Viewport(Y.VIEW_MAIN,n,{left:o.width,top:r.height,bottom:0,right:0,isWheelPreventDefaultX:!0}),l=new w.Viewport(Y.VIEW_ROW_TOP,n,{active:!1,isWheelPreventDefaultX:!0}),c=new w.Viewport(Y.VIEW_ROW_BOTTOM,n,{left:0,top:r.height,bottom:0,width:o.width,isWheelPreventDefaultX:!0}),d=new w.Viewport(Y.VIEW_COLUMN_LEFT,n,{active:!1,isWheelPreventDefaultX:!0}),u=new w.Viewport(Y.VIEW_COLUMN_RIGHT,n,{left:o.width,top:0,height:r.height,right:0,isWheelPreventDefaultX:!0}),h=new w.Viewport(Y.VIEW_LEFT_TOP,n,{left:0,top:0,width:o.width,height:r.height,isWheelPreventDefaultX:!0}),m=new w.Viewport(Y.VIEW_MAIN_LEFT_TOP,n,{isWheelPreventDefaultX:!0,active:!1}),S=new w.Viewport(Y.VIEW_MAIN_LEFT,n,{isWheelPreventDefaultX:!0,active:!1}),g=new w.Viewport(Y.VIEW_MAIN_TOP,n,{isWheelPreventDefaultX:!0,active:!1});return n.onMouseWheelObserver.add((_,I)=>{if(_.ctrlKey)return;let C=0,b=0;const M=s.limitedScroll();if(_.inputIndex===w.PointerInput.MouseWheelX){const E=Math.abs(_.deltaX);_.deltaX>0?C=E:C=-E,this._commandService.executeCommand(rn.id,{offsetX:C}),n.getParent().classType===w.RENDER_CLASS_TYPE.SCENE_VIEWER?M!=null&&M.isLimitedX||I.stopPropagation():s.isWheelPreventDefaultX?_.preventDefault():M!=null&&M.isLimitedX||_.preventDefault()}if(_.inputIndex===w.PointerInput.MouseWheelY){let E=Math.abs(_.deltaY);_.shiftKey?(E*=3,_.deltaY>0?C=E:C=-E,this._commandService.executeCommand(rn.id,{offsetX:C}),n.getParent().classType===w.RENDER_CLASS_TYPE.SCENE_VIEWER?M!=null&&M.isLimitedX||I.stopPropagation():s.isWheelPreventDefaultX?_.preventDefault():M!=null&&M.isLimitedX||_.preventDefault()):(_.deltaY>0?b=E:b=-E,this._commandService.executeCommand(rn.id,{offsetY:b}),n.getParent().classType===w.RENDER_CLASS_TYPE.SCENE_VIEWER?M!=null&&M.isLimitedY||I.stopPropagation():s.isWheelPreventDefaultY?_.preventDefault():M!=null&&M.isLimitedY||_.preventDefault())}_.inputIndex,w.PointerInput.MouseWheelZ,this._scene.makeDirty(!0)}),new w.ScrollBar(s),n.addViewport(s,d,u,l,c,h,m,S,g).attachControl(),s}};exports.SheetCanvasView=Vm([a.OnLifecycle(a.LifecycleStages.Ready,exports.SheetCanvasView),It(0,a.IUniverInstanceService),It(1,a.ICommandService),It(2,w.IRenderManagerService),It(3,ce),It(4,P.Inject(exports.SheetSkeletonManagerService))],exports.SheetCanvasView);var Fm=Object.defineProperty,jm=Object.getOwnPropertyDescriptor,Wm=(i,e,t,n)=>{for(var o=n>1?void 0:n?jm(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Fm(e,t,o),o},Gn=(i,e)=>(t,n)=>e(t,n,i),Kn;exports.UniverSheetsUIPlugin=(Kn=class extends a.Plugin{constructor(e,t,n,o){super(Ro),this._injector=t,this._localeService=n,this._currentUniverService=o,this._localeService.load({zhCN:ar})}onStarting(e){[[exports.SheetCanvasView],[pe,{useClass:Ho}],[lt,{useClass:exports.SheetClipboardService}],[mt,{useClass:Ld}],[dt,{useClass:ni}],[Pt,{useClass:cr}],[Dn,{useClass:Ba}],[Dt,{useClass:exports.AutoFillService}],[ke],[exports.SheetSkeletonManagerService],[ce,{useClass:exports.SelectionRenderService}],[bi,{useClass:rh}],[At,{useClass:exports.MarkSelectionService}],[Yt],[Zt],[nn],[Jt],[Qt],[on],[sn],[ln],[an],[cn],[dn],[en],[hn],[wt],[Sn],[Gt],[Kt],[mn],[_n],[fn],[tn],[vn],[exports.AutoFillController],[pn],[qt],[un]].forEach(t=>e.add(t))}onReady(){this._markSheetAsFocused()}_markSheetAsFocused(){const e=this._currentUniverService;e.currentSheet$.pipe(po.filter(t=>!!t)).subscribe(t=>{e.focusUniverInstance(t.getUnitId())})}},v(Kn,"type",a.PluginType.Sheet),Kn);exports.UniverSheetsUIPlugin=Wm([Gn(1,P.Inject(P.Injector)),Gn(2,P.Inject(a.LocaleService)),Gn(3,a.IUniverInstanceService)],exports.UniverSheetsUIPlugin);exports.APPLY_TYPE=X;exports.AutoFillCommand=Cn;exports.COPY_TYPE=Xe;exports.CellEditorManagerService=cr;exports.DATA_TYPE=te;exports.DefaultRightMenuConfig=vo;exports.DefaultSheetContainerConfig=Io;exports.DefaultSheetUIConfig=xr;exports.DefaultToolbarConfig=Co;exports.EditorBridgeService=Ho;exports.ExpandSelectionCommand=Me;exports.IAutoFillService=Dt;exports.ICellEditorManagerService=Pt;exports.IEditorBridgeService=pe;exports.IFormulaEditorManagerService=Dn;exports.IMarkSelectionService=At;exports.ISelectionRenderService=ce;exports.ISheetClipboardService=lt;exports.JumpOver=be;exports.MoveSelectionCommand=me;exports.PASTE_SPECIAL_MENU_ID=ht;exports.PREDEFINED_HOOK_NAME=le;exports.RangeSelector=dl;exports.SHEET_UI_PLUGIN_NAME=Ro;exports.SelectionShape=Rn;exports.SetCellEditVisibleArrowOperation=Ot;exports.SetEditorResizeOperation=On;exports.SetScrollOperation=ct;exports.SetZoomRatioOperation=xe;exports.SheetCopyCommand=wo;exports.SheetPasteCommand=at;exports.VIEWPORT_KEY=Y;exports.enUS=Ua;exports.getAutoFillRepeatRange=Ml;exports.getCoordByCell=ii;exports.getCoordByOffset=st;exports.getEditorObject=yn;exports.getRepeatRange=ka;exports.getSheetObject=ae;exports.getTransformCoord=Xt;exports.whenEditorInputFormulaActivated=Nr;exports.zhCN=ar;
17
+ */var fa=P,pa=Symbol.for("react.element"),va=Symbol.for("react.fragment"),Ca=Object.prototype.hasOwnProperty,Ia=fa.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Ra={key:!0,ref:!0,__self:!0,__source:!0};function tr(i,e,t){var n,o={},r=null,s=null;t!==void 0&&(r=""+t),e.key!==void 0&&(r=""+e.key),e.ref!==void 0&&(s=e.ref);for(n in e)Ca.call(e,n)&&!Ra.hasOwnProperty(n)&&(o[n]=e[n]);if(i&&i.defaultProps)for(n in e=i.defaultProps,e)o[n]===void 0&&(o[n]=e[n]);return{$$typeof:pa,type:i,key:r,ref:s,props:o,_owner:Ia.current}}$n.Fragment=va;$n.jsx=tr;$n.jsxs=tr;er.exports=$n;var p=er.exports,be=function(){return be=Object.assign||function(i){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(i[o]=e[o])}return i},be.apply(this,arguments)},Ma=function(i,e){var t={};for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&e.indexOf(n)<0&&(t[n]=i[n]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,n=Object.getOwnPropertySymbols(i);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(i,n[o])&&(t[n[o]]=i[n[o]]);return t},Ie=P.forwardRef(function(i,e){var t=i.icon,n=i.id,o=i.className,r=i.extend,s=Ma(i,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(n," ").concat(o||"").trim(),c=P.useRef("_".concat(Ta()));return nr(t,"".concat(n),{defIds:t.defIds,idSuffix:c.current},be({ref:e,className:a},s),r)});function nr(i,e,t,n,o){return P.createElement(i.tag,be(be({key:e},ba(i,t,o)),n),(wa(i,t).children||[]).map(function(r,s){return nr(r,"".concat(e,"-").concat(i.tag,"-").concat(s),t,void 0,o)}))}function ba(i,e,t){var n=be({},i.attrs);t!=null&&t.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=t.colorChannel1);var o=e.defIds;return!o||o.length===0||(i.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+e.idSuffix),Object.entries(n).forEach(function(r){var s=r[0],a=r[1];typeof a=="string"&&(n[s]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),n}function wa(i,e){var t,n=e.defIds;return!n||n.length===0?i:i.tag==="defs"&&(!((t=i.children)===null||t===void 0)&&t.length)?be(be({},i),{children:i.children.map(function(o){return typeof o.attrs.id=="string"&&n&&n.indexOf(o.attrs.id)>-1?be(be({},o),{attrs:be(be({},o.attrs),{id:o.attrs.id+e.idSuffix})}):o})}):i}function Ta(){return Math.random().toString(36).substring(2,8)}Ie.displayName="UniverIcon";var Ea={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M11.53 12.83v1.8c0 .34.26.6.6.6a.6.6 0 00.6-.6v-1.8h1.8a.6.6 0 000-1.2h-1.8v-1.8a.6.6 0 00-1.2 0v1.8h-1.8a.6.6 0 100 1.2h1.8z"}},{tag:"path",attrs:{fill:"currentColor",d:"M3.05 1.96c-.66 0-1.2.54-1.2 1.2v3.6c0 .66.54 1.2 1.2 1.2h3.6c.67 0 1.2-.54 1.2-1.2v-3.6c0-.66-.53-1.2-1.2-1.2h-3.6zm3.6 1.2h-3.6v3.6h3.6v-3.6zM3.05 9.23c-.66 0-1.2.54-1.2 1.2v3.6c0 .67.54 1.2 1.2 1.2h3.6c.67 0 1.2-.53 1.2-1.2v-3.6c0-.66-.53-1.2-1.2-1.2h-3.6zm3.6 1.2h-3.6v3.6h3.6v-3.6zM10.33 7.96a1.2 1.2 0 01-1.2-1.2v-3.6c0-.66.53-1.2 1.2-1.2h3.6c.66 0 1.2.54 1.2 1.2v3.6c0 .66-.54 1.2-1.2 1.2h-3.6zm0-1.2v-3.6h3.6v3.6h-3.6z",fillRule:"evenodd",clipRule:"evenodd"}}]},ir=P.forwardRef(function(i,e){return P.createElement(Ie,Object.assign({},i,{id:"autofill",ref:e,icon:Ea}))});ir.displayName="Autofill";const ya=ir;var Oa={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.62 4.52c.25.26.25.68 0 .94l-8 8a.4.4 0 01-.57 0L1.74 9.12a.66.66 0 01.93-.93l3.52 3.52c.08.08.2.08.29 0l7.2-7.2a.66.66 0 01.94 0z",fillRule:"evenodd",clipRule:"evenodd"}}]},or=P.forwardRef(function(i,e){return P.createElement(Ie,Object.assign({},i,{id:"check-mark-single",ref:e,icon:Oa}))});or.displayName="CheckMarkSingle";const kn=or;var xa={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.49 4.6a.65.65 0 00-.92.92L8 8.95l-3.43 3.43a.65.65 0 10.92.92l3.43-3.43 3.43 3.43a.65.65 0 00.92-.92L9.84 8.95l3.43-3.43a.65.65 0 10-.92-.92L8.92 8.03 5.49 4.6z"}}]},rr=P.forwardRef(function(i,e){return P.createElement(Ie,Object.assign({},i,{id:"close-single",ref:e,icon:xa}))});rr.displayName="CloseSingle";const Aa=rr;var Da={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_1213",style:{"mask-type":"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#DCDCDC",d:"M.54.32h16v16h-16z"}}]},{tag:"g",attrs:{fill:"currentColor",mask:"url(#mask0_102_1213)"},children:[{tag:"path",attrs:{d:"M1.77 1.27c.13-.02.29-.04.49-.04H7.4c.2 0 .36.02.5.05.13.03.24.09.32.18.09.08.14.2.17.34.02.14.04.31.04.52v5.16c0 .2-.02.36-.04.5a.64.64 0 01-.17.33.66.66 0 01-.32.17c-.13.03-.3.04-.48.04H2.26c-.2 0-.35 0-.49-.03a.61.61 0 01-.32-.16.64.64 0 01-.17-.33c-.03-.13-.05-.3-.05-.52v-5.2c0-.2.01-.38.04-.51a.64.64 0 01.17-.34c.08-.08.2-.13.32-.16zm.8 1.12c-.08 0-.12.02-.14.05a.25.25 0 00-.03.14v1.66h1.86V2.4H2.57zm2.87 0v1.85h1.81V2.52a.42.42 0 00-.01-.11.18.18 0 00-.08-.01H5.44zm-3.03 3v1.84l.01.1.02.02.03.01h1.8V5.4H2.4zm3.03 0v1.98H7.1c.07 0 .11-.01.13-.02v-.02c.02-.02.02-.05.02-.1V5.4h-1.8zM9.2 8.15c.12-.02.29-.04.49-.04h5.14c.2 0 .36.02.5.05.13.03.24.09.32.18.08.08.14.2.17.34.02.14.04.3.04.52v5.16c0 .2-.02.36-.04.5a.64.64 0 01-.17.33.66.66 0 01-.32.17c-.13.03-.3.04-.48.04H9.69c-.2 0-.36 0-.49-.03a.61.61 0 01-.33-.16.64.64 0 01-.16-.33c-.03-.13-.05-.3-.05-.52v-5.2c0-.2.01-.38.04-.51a.64.64 0 01.16-.34c.09-.08.2-.13.33-.16zm.8 1.12c-.08 0-.12.02-.14.04a.25.25 0 00-.03.15v1.66h1.86V9.27H10zm2.87 0v1.85h1.8V9.4a.42.42 0 000-.12.18.18 0 00-.08 0h-1.72zm-3.03 3v1.84l.01.09.01.03h.04l.1.02h1.7v-1.97H9.84zm3.03 0v1.98h1.66c.07 0 .11-.01.13-.02v-.02l.02-.1v-1.83h-1.81z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{d:"M10 2.47c0-.4.33-.73.74-.73h2.19c1.21 0 2.2.98 2.2 2.19v2.2a.73.73 0 01-1.47 0v-2.2c0-.4-.33-.73-.73-.73h-2.2a.73.73 0 01-.73-.73zM3.42 10.51a.73.73 0 00-1.46 0v2.2c0 1.2.98 2.19 2.2 2.19h2.19a.73.73 0 000-1.46h-2.2a.73.73 0 01-.73-.74v-2.19z"}}]}]},sr=P.forwardRef(function(i,e){return P.createElement(Ie,Object.assign({},i,{id:"convert-single",ref:e,icon:Da}))});sr.displayName="ConvertSingle";const Na=sr;var Pa={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_371_77",style:{"mask-type":"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#DCDCDC",d:"M.87.63h16v16h-16z"}}]},{tag:"g",attrs:{mask:"url(#mask0_371_77)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M9.73 13.55a1.1 1.1 0 01-1.72 0L1.23 5.7c-.77-.89-.23-2.4.85-2.4h13.57c1.08 0 1.62 1.51.86 2.4l-6.78 7.85z"}}]}]},ar=P.forwardRef(function(i,e){return P.createElement(Ie,Object.assign({},i,{id:"dropdown-single",ref:e,icon:Pa}))});ar.displayName="DropdownSingle";const lo=ar;var Ha={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.9 5a.67.67 0 01.9.28c.17.3.42.62.78.9 1 .83 2.67 1.4 4.63 1.4s3.64-.57 4.64-1.4c.35-.28.6-.6.77-.9a.67.67 0 011.18.61 4.31 4.31 0 01-1.24 1.43l1.46 1.46a.67.67 0 01-.94.94l-1.7-1.68c-.52.25-1.1.45-1.71.6l.54 2.01a.67.67 0 01-1.3.35l-.56-2.14a11.01 11.01 0 01-2.28 0L6.5 11a.67.67 0 11-1.29-.35l.54-2.02a8.66 8.66 0 01-1.71-.6l-1.69 1.7a.67.67 0 11-.94-.95l1.46-1.46-.14-.1a4.31 4.31 0 01-1.1-1.33.67.67 0 01.28-.9z"}}]},lr=P.forwardRef(function(i,e){return P.createElement(Ie,Object.assign({},i,{id:"eyelash-single",ref:e,icon:Ha}))});lr.displayName="EyelashSingle";const La=lr;var Ua={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_367_60",style:{"mask-type":"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M.06.78h16v16h-16z"}}]},{tag:"g",attrs:{fill:"currentColor",mask:"url(#mask0_367_60)"},children:[{tag:"path",attrs:{d:"M5.54 5.68a.2.2 0 01-.2-.25l.1-.38c.1-.42.28-.8.55-1.09.3-.32.74-.46 1.29-.46a3.37 3.37 0 01.7.08c.2.04.44-.05.52-.25l.23-.55a.38.38 0 00-.24-.5 3.77 3.77 0 00-1.14-.16c-1.05 0-1.84.26-2.4.77a4.2 4.2 0 00-1.19 2.23l-1.44 6.21a15.59 15.59 0 01-.72 2.25 9.04 9.04 0 01-.77 1.39c-.09.12-.02.3.14.33.65.1 1.33-.08 1.7-.63.14-.21.28-.46.41-.74.37-.74.7-1.78 1.02-3.13l.85-3.64a.2.2 0 01.2-.16H7.1a.4.4 0 00.4-.3l.12-.53a.4.4 0 00-.39-.5H5.54zM13.8 5.86L12 8.11l-1.11-2.19a.41.41 0 00-.38-.24H9.8c-.3 0-.5.32-.37.6L10.9 9.2l-2.61 3.1a.41.41 0 00.3.68h.59c.12 0 .27-.05.35-.15l2.07-2.42 1 2.3c.07.16.22.27.4.27h.79c.28 0 .44-.22.34-.48l-1.47-3.07 2.43-3.1a.4.4 0 00-.33-.65h-.6c-.14 0-.24.05-.35.18z"}}]}]},cr=P.forwardRef(function(i,e){return P.createElement(Ie,Object.assign({},i,{id:"fx-single",ref:e,icon:Ua}))});cr.displayName="FxSingle";const ka=cr;var Va={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_249",style:{"mask-type":"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M.37.77h16v16h-16z"}}]},{tag:"g",attrs:{mask:"url(#mask0_102_249)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M9.12 2.86c0-.4-.33-.73-.75-.73a.74.74 0 00-.74.73v5.17H2.4a.74.74 0 00-.75.74c0 .4.34.74.75.74h5.23v5.17c0 .4.33.73.74.73.42 0 .75-.33.75-.73V9.5h5.23c.41 0 .75-.33.75-.74 0-.4-.34-.74-.75-.74H9.12V2.86z"}}]}]},dr=P.forwardRef(function(i,e){return P.createElement(Ie,Object.assign({},i,{id:"increase-single",ref:e,icon:Va}))});dr.displayName="IncreaseSingle";const Ba=dr;var Fa={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_556",style:{"mask-type":"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M.56.77h16v16h-16z"}}]},{tag:"g",attrs:{mask:"url(#mask0_102_556)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.2 4.77c.5-.5 1.32-.5 1.83 0l5.1 5.1a.6.6 0 00.86 0l5.1-5.1a1.3 1.3 0 011.84 1.84l-5.95 5.96a2 2 0 01-2.83 0L1.19 6.6a1.3 1.3 0 010-1.84z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},ur=P.forwardRef(function(i,e){return P.createElement(Ie,Object.assign({},i,{id:"more-down-single",ref:e,icon:Fa}))});ur.displayName="MoreDownSingle";const pi=ur;var Wa={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.53 3.57c.29-.3.76-.3 1.06 0l4.5 4.72c.29.3.29.8 0 1.1l-4.57 4.65c-.3.3-.77.3-1.06 0-.3-.3-.3-.8 0-1.11l3.9-3.95a.2.2 0 000-.28L5.53 4.68c-.3-.3-.3-.8 0-1.1z",fillRule:"evenodd",clipRule:"evenodd"}}]},hr=P.forwardRef(function(i,e){return P.createElement(Ie,Object.assign({},i,{id:"more-single",ref:e,icon:Wa}))});hr.displayName="MoreSingle";const co=hr;var ja={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_1204",style:{"mask-type":"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#DCDCDC",d:"M.25.41h16v16h-16z"}}]},{tag:"g",attrs:{mask:"url(#mask0_102_1204)"},children:[{tag:"rect",attrs:{width:12.62,height:2.79,x:1.94,y:12.66,fill:"colorChannel1",rx:1.4}},{tag:"path",attrs:{fill:"currentColor",d:"M8 2.57c-.4-.51-.89-.88-1.37-1.07-.51-.2-1.23-.24-1.68.34-.4.51-.37 1.27-.12 2.07a3.48 3.48 0 00.65 1.17L3.76 6.81a.61.61 0 000 .87l3.73 3.73c.24.24.62.24.86 0l4.73-4.73a.61.61 0 000-.87L9.35 2.08a.61.61 0 00-.86 0l-.5.5zM7.7 4.91l.03.22A.61.61 0 108.96 5a4.85 4.85 0 00-.33-1.33l.29-.3 2.87 2.87-.93.93H5.13l2.53-2.53.05.27zm-.59-1.47c-.3-.41-.65-.69-.93-.8a.57.57 0 00-.27-.05c-.03.04-.13.28.08.96.06.22.17.44.34.67l.78-.78z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M12.44 11.95c.46 0 .82-.36.82-.82 0-.28-.31-.8-.55-1.15a.32.32 0 00-.53 0c-.24.35-.56.87-.56 1.15 0 .46.37.82.82.82z"}}]}]},mr=P.forwardRef(function(i,e){return P.createElement(Ie,Object.assign({},i,{id:"paint-bucket",ref:e,icon:ja}))});mr.displayName="PaintBucket";const $a=mr;var za={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.8 1.54c-.7 0-1.26.57-1.26 1.27v10.8c0 .7.57 1.26 1.27 1.26h6.93a1 1 0 001-1v-2.74c0-.17.14-.3.3-.3h2.83a1 1 0 001-1V2.8c0-.7-.57-1.27-1.27-1.27H2.8zM9.18 13.6a.3.3 0 00.3-.3v-2.17a.3.3 0 00-.3-.3H6.92a.3.3 0 00-.3.3v2.17c0 .17.13.3.3.3h2.25zm4.43-4.34a.3.3 0 01-.3.3h-2.26a.3.3 0 01-.3-.3V7.17c0-.16.14-.3.3-.3h2.26c.17 0 .3.14.3.3v2.09zm-4.43.3a.3.3 0 00.3-.3V7.17a.3.3 0 00-.3-.3H6.92a.3.3 0 00-.3.3v2.09c0 .16.13.3.3.3h2.25zM13.6 5.3a.3.3 0 01-.3.3h-2.26a.3.3 0 01-.3-.3V3.1c0-.16.14-.3.3-.3h2.26c.17 0 .3.14.3.3v2.2zm-4.43.3a.3.3 0 00.3-.3V3.1a.3.3 0 00-.3-.3H6.92a.3.3 0 00-.3.3v2.2c0 .17.13.3.3.3h2.25zM5.35 3.1a.3.3 0 00-.3-.3H3.1a.3.3 0 00-.3.3v2.2c0 .17.13.3.3.3h1.94a.3.3 0 00.3-.3V3.1zm0 4.07a.3.3 0 00-.3-.3H3.1a.3.3 0 00-.3.3v2.09c0 .16.13.3.3.3h1.94a.3.3 0 00.3-.3V7.17zm0 3.96a.3.3 0 00-.3-.3H3.1a.3.3 0 00-.3.3v2.17c0 .17.13.3.3.3h1.94a.3.3 0 00.3-.3v-2.17z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M12.39 12.12a.2.2 0 01.29-.2l2.31 1.25a.2.2 0 01-.06.37h-.03l-1 .28-.74.93a.2.2 0 01-.37-.07l-.4-2.56z"}}]},gr=P.forwardRef(function(i,e){return P.createElement(Ie,Object.assign({},i,{id:"select-range-single",ref:e,icon:za}))});gr.displayName="SelectRangeSingle";const Xa=gr,Ya="univer-range-selector",Za="univer-range-selector-editor",Ga="univer-range-selector-icon",Ka="univer-range-selector-active",et={rangeSelector:Ya,rangeSelectorEditor:Za,rangeSelectorIcon:Ga,rangeSelectorActive:Ka};function qa(i){const{onChange:e,onActive:t}=i,[n,o]=P.useState(!1),r=P.useRef(null),s=K.useDependency(l.LocaleService),a=K.useDependency(_.SelectionManagerService);P.useEffect(()=>{var m;if(n){t(n);const g=a.selectionMoveEnd$.subscribe(S=>{const f=["A1","B2:C3","Sheet2!A1:B2","D10:E11,F1:G2,H3:I4"],C=Math.floor(Math.random()*f.length),R=f[C];r.current&&(r.current.innerHTML=R)});return document.addEventListener("click",c),()=>{document.removeEventListener("click",c),g.unsubscribe()}}e(((m=r.current)==null?void 0:m.innerHTML)||"")},[n]);function c(m){var C,R,M;if(((C=m.target)==null?void 0:C.closest('[data-range-selector="true"]'))||m.target===r.current)return;const S=(R=m.target)==null?void 0:R.closest(`.${et.rangeSelector}`);(S==null?void 0:S.querySelector(`.${et.rangeSelectorEditor}`))!==r.current&&(o(!1),(M=r.current)==null||M.blur())}function d(m){m.stopPropagation(),m.key==="Enter"&&(m.preventDefault(),m.currentTarget.blur(),o(!1))}function u(){o(!0)}function h(){var m;if(!n){(m=r.current)==null||m.focus();return}o(!n)}return p.jsxs("div",{className:n?`${et.rangeSelector} ${et.rangeSelectorActive}`:et.rangeSelector,children:[p.jsx("div",{ref:r,className:et.rangeSelectorEditor,contentEditable:!0,"data-placeholder":s.t("rangeSelector.placeholder"),onKeyDown:d,onFocus:u}),p.jsx(Se.Tooltip,{title:s.t("rangeSelector.tooltip"),placement:"bottom",children:p.jsx("button",{className:et.rangeSelectorIcon,onClick:h,children:p.jsx(Xa,{})})})]})}var ft=(i=>(i.Append="APPEND",i.Default="DEFAULT",i.Only="ONLY",i))(ft||{}),ue=(i=>(i.NUMBER="number",i.DATE="date",i.EXTEND_NUMBER="extendNumber",i.CHN_NUMBER="chnNumber",i.CHN_WEEK2="chnWeek2",i.CHN_WEEK3="chnWeek3",i.LOOP_SERIES="loopSeries",i.FORMULA="formula",i.OTHER="other",i))(ue||{}),ie=(i=>(i.COPY="0",i.SERIES="1",i.ONLY_FORMAT="2",i.NO_FORMAT="3",i))(ie||{});const Ja={type:ue.NUMBER,priority:1e3,match:i=>typeof(i==null?void 0:i.v)=="number"||(i==null?void 0:i.t)===l.CellValueType.NUMBER,isContinue:(i,e)=>i.type===ue.NUMBER,applyFunctions:{[ie.SERIES]:(i,e,t)=>{const{data:n}=i;return t===l.Direction.LEFT||t===l.Direction.UP?(n.reverse(),Yi(n,e,t).reverse()):Yi(n,e,t)}}},Sr={type:ue.OTHER,priority:0,match:()=>!0,isContinue:(i,e)=>i.type===ue.OTHER},Qa={type:ue.EXTEND_NUMBER,priority:900,match:i=>Qt(`${i==null?void 0:i.v}`||"").isExtendNumber,isContinue:(i,e)=>{var t;if(i.type===ue.EXTEND_NUMBER){const{beforeTxt:n,afterTxt:o}=Qt(`${(t=i.cellData)==null?void 0:t.v}`||""),{beforeTxt:r,afterTxt:s}=Qt(`${e==null?void 0:e.v}`||"");if(n===r&&o===s)return!0}return!1},applyFunctions:{[ie.SERIES]:(i,e,t)=>{var a;const{data:n}=i,o=t===l.Direction.UP||t===l.Direction.LEFT;let r;if(n.length===1)return r=o?-1:1,we(Zi(n,e,r),o);const s=[];for(let c=0;c<n.length;c++){const d=`${(a=n[c])==null?void 0:a.v}`;d&&s.push(Number(Qt(d).matchTxt))}return o&&(n.reverse(),s.reverse()),zt(s)?(r=s[1]-s[0],we(Zi(n,e,r),o)):st(n,e)}}},el={type:ue.CHN_NUMBER,priority:830,match:i=>!!Qr(`${i==null?void 0:i.v}`||""),isContinue:(i,e)=>i.type===ue.CHN_NUMBER,applyFunctions:{[ie.SERIES]:(i,e,t)=>{var c,d,u;const{data:n}=i,o=t===l.Direction.LEFT||t===l.Direction.UP;if(n.length===1){const h=`${(c=n[0])==null?void 0:c.v}`;let m;return o?m=-1:m=1,h&&(h==="日"||Fe(h)<7)?we(Rt(n,e,m),o):we(Gi(n,e,m),o)}let r=!1;for(let h=0;h<n.length;h++)if(((d=n[h])==null?void 0:d.v)==="日"){r=!0;break}const s=[];let a=0;for(let h=0;h<n.length;h++){const m=`${(u=n[h])==null?void 0:u.v}`;m==="日"?h===0?s.push(0):(a++,s.push(a*7)):r&&Fe(m)>0&&Fe(m)<7?s.push(Fe(m)+a*7):s.push(Fe(m))}if(o&&(n.reverse(),s.reverse()),zt(s)){if(r||s[s.length-1]<6&&s[0]>0||s[0]<6&&s[s.length-1]>0){const m=s[1]-s[0];return we(Rt(n,e,m),o)}const h=s[1]-s[0];return we(Gi(n,e,h),o)}return st(n,e)}}},tl={type:ue.CHN_WEEK2,priority:820,match:i=>!!es(`${i==null?void 0:i.v}`||""),isContinue:(i,e)=>i.type===ue.CHN_WEEK2,applyFunctions:{[ie.SERIES]:(i,e,t)=>{var a;const{data:n}=i,o=t===l.Direction.LEFT||t===l.Direction.UP;if(n.length===1){let c;return o?c=-1:c=1,we(Rt(n,e,c,1),o)}const r=[];let s=0;for(let c=0;c<n.length;c++){const d=`${(a=n[c])==null?void 0:a.v}`,u=d==null?void 0:d.substr(d.length-1,1);d==="周日"?c===0?r.push(0):(s++,r.push(s*7)):r.push(Fe(u)+s*7)}if(o&&(n.reverse(),r.reverse()),zt(r)){const c=r[1]-r[0];return we(Rt(n,e,c,1),o)}return st(n,e)}}},nl={type:ue.CHN_WEEK3,priority:810,match:i=>ts(`${i==null?void 0:i.v}`||""),isContinue:(i,e)=>i.type===ue.CHN_WEEK3,applyFunctions:{[ie.SERIES]:(i,e,t)=>{var a;const{data:n}=i,o=t===l.Direction.LEFT||t===l.Direction.UP;if(n.length===1){let c;return o?c=-1:c=1,we(Rt(n,e,c,2),o)}const r=[];let s=0;for(let c=0;c<n.length;c++){const d=`${(a=n[c])==null?void 0:a.v}`;if(d){const u=d.substr(d.length-1,1);d==="星期日"?c===0?r.push(0):(s++,r.push(s*7)):r.push(Fe(u)+s*7)}}if(o&&(n.reverse(),r.reverse()),zt(r)){const c=r[1]-r[0];return we(Rt(n,e,c,2),o)}return st(n,e)}}},il={type:ue.LOOP_SERIES,priority:800,match:i=>ls(`${i==null?void 0:i.v}`||""),isContinue:(i,e)=>{var t;return i.type===ue.LOOP_SERIES?Qn(`${(t=i.cellData)==null?void 0:t.v}`||"").name===Qn(`${e==null?void 0:e.v}`||"").name:!1},applyFunctions:{[ie.SERIES]:(i,e,t)=>{var c,d;const{data:n}=i,o=t===l.Direction.LEFT||t===l.Direction.UP,{series:r}=Qn(`${(c=n[0])==null?void 0:c.v}`||"");if(n.length===1){let u;return o?u=-1:u=1,we(Ki(n,e,u,r),o)}const s=[];let a=0;for(let u=0;u<n.length;u++){const h=`${(d=n[u])==null?void 0:d.v}`;h&&(h===r[0]?u===0?s.push(0):(a++,s.push(a*r.length)):s.push(r.indexOf(h)+a*7))}if(o&&(n.reverse(),s.reverse()),zt(s)){const u=s[1]-s[0];return we(Ki(n,e,u,r),o)}return st(n,e)}}};function we(i,e){return e?i.reverse():i}var ol=Object.defineProperty,rl=Object.getOwnPropertyDescriptor,sl=(i,e,t,n)=>{for(var o=n>1?void 0:n?rl(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&ol(e,t,o),o},ti=(i,e)=>(t,n)=>e(t,n,i);exports.AutoFillService=class extends l.Disposable{constructor(t,n,o){super();v(this,"_rules",[]);v(this,"_hooks",[]);v(this,"_applyType$",new H.BehaviorSubject(ie.SERIES));v(this,"_isFillingStyle",!0);v(this,"_autoFillLocation$",new H.BehaviorSubject(null));v(this,"autoFillLocation$",this._autoFillLocation$.asObservable());v(this,"_showMenu$",new H.BehaviorSubject(!1));v(this,"showMenu$",this._showMenu$.asObservable());v(this,"_direction",l.Direction.DOWN);v(this,"applyType$",this._applyType$.asObservable());v(this,"_menu$",new H.BehaviorSubject([{label:"autoFill.copy",value:ie.COPY,disable:!1},{label:"autoFill.series",value:ie.SERIES,disable:!1},{label:"autoFill.formatOnly",value:ie.ONLY_FORMAT,disable:!1},{label:"autoFill.noFormat",value:ie.NO_FORMAT,disable:!1}]));v(this,"menu$",this._menu$.asObservable());this._sheetInterceptorService=t,this._univerInstanceService=n,this._selectionManagerService=o,this._init()}_init(){this._rules=[Ja,Qa,el,tl,nl,il,Sr].sort((t,n)=>n.priority-t.priority),this._isFillingStyle=!0}getOneByPriority(t){return t.length<=0?[]:[t.reduce((o,r)=>(r.priority||0)>(o.priority||0)?r:o,t[0])]}addHook(t){if(this._hooks.find(n=>n.id===t.id))throw new Error(`Add hook failed, hook id '${t.id}' already exist!`);return t.priority===void 0&&(t.priority=0),t.type===void 0&&(t.type=ft.Append),this._hooks.push(t),l.toDisposable(()=>{const n=this._hooks.findIndex(o=>o===t);n>-1&&this._hooks.splice(n,1)})}registerRule(t){if(this._rules.find(o=>o.type===t.type))throw new Error(`Registry rule failed, type '${t.type}' already exist!`);const n=this._rules.findIndex(o=>o.priority<t.priority);this._rules.splice(n===-1?this._rules.length:n,0,t)}getRules(){return this._rules}getAllHooks(){return this._hooks}getActiveHooks(){const{source:t,target:n,unitId:o,subUnitId:r}=this.autoFillLocation||{};if(!t||!n||!o||!r)return[];const s=this._hooks.filter(u=>{var h;return!((h=u.disable)!=null&&h.call(u,{source:t,target:n,unitId:o,subUnitId:r},this._direction,this.applyType))}),a=s.filter(u=>u.type===ft.Only);if(a.length>0)return this.getOneByPriority(a);const c=this.getOneByPriority(s.filter(u=>u.type===ft.Default)),d=s.filter(u=>u.type===ft.Append)||[];return[...c,...d]}get applyType(){return this._applyType$.getValue()}set applyType(t){this._applyType$.next(t)}get menu(){return this._menu$.getValue()}get direction(){return this._direction}set direction(t){this._direction=t}isFillingStyle(){return this._isFillingStyle}setFillingStyle(t){this._isFillingStyle=t}get autoFillLocation(){return this._autoFillLocation$.getValue()}set autoFillLocation(t){this._autoFillLocation$.next(t)}setDisableApplyType(t,n){this._menu$.next(this._menu$.getValue().map(o=>o.value===t?{...o,disable:n}:o))}setShowMenu(t){this._showMenu$.next(t)}};exports.AutoFillService=sl([l.OnLifecycle(l.LifecycleStages.Rendered,exports.AutoFillService),ti(0,D.Inject(_.SheetInterceptorService)),ti(1,D.Inject(l.IUniverInstanceService)),ti(2,D.Inject(_.SelectionManagerService))],exports.AutoFillService);const Yt=D.createIdentifier("univer.auto-fill-service");var al=Object.defineProperty,ll=Object.getOwnPropertyDescriptor,cl=(i,e,t,n)=>{for(var o=n>1?void 0:n?ll(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&al(e,t,o),o},ke=(i,e)=>(t,n)=>e(t,n,i);exports.AutoFillController=class extends l.Disposable{constructor(t,n,o,r,s,a,c,d,u){super();v(this,"_beforeApplyData",[]);v(this,"_copyData",[]);v(this,"_defaultHook");this._univerInstanceService=t,this._selectionRenderService=n,this._commandService=o,this._undoRedoService=r,this._autoFillService=s,this._editorBridgeService=a,this._sheetInterceptorService=c,this._selectionManagerService=d,this._injector=u,this._defaultHook={id:"default",type:ft.Default,priority:0,onBeforeFillData:(h,m)=>{this._presetAndCacheData(h,m)},onFillData:(h,m,g)=>this._fillData(h,m,g)},this._init()}_init(){this._initDefaultHook(),this._onSelectionControlFillChanged(),this._onApplyTypeChanged(),[ko,an].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initDefaultHook(){this._autoFillService.addHook(this._defaultHook)}_onSelectionControlFillChanged(){const t=new l.DisposableCollection;this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id!==_.SetSelectionsOperation.id)return;const o=this._selectionManagerService.getCurrent();if((o==null?void 0:o.pluginName)!==_.NORMAL_SELECTION_PLUGIN_NAME)return;t.dispose(),this._selectionRenderService.getCurrentControls().forEach(s=>{t.add(l.toDisposable(s.selectionFilled$.subscribe(a=>{if(a==null||a.startColumn===-1||a.startRow===-1||a.endColumn===-1||a.endRow===-1)return;const c={startColumn:s.model.startColumn,endColumn:s.model.endColumn,startRow:s.model.startRow,endRow:s.model.endRow},d={startColumn:a.startColumn,endColumn:a.endColumn,startRow:a.startRow,endRow:a.endRow};this._triggerAutoFill(c,d)}))),t.add(l.toDisposable(s.fillControl.onDblclickObserver.add(()=>{const a={startColumn:s.model.startColumn,endColumn:s.model.endColumn,startRow:s.model.startRow,endRow:s.model.endRow};this._handleDbClickFill(a)}))),t.add(l.toDisposable(s.fillControl.onPointerDownObserver.add(()=>{this._editorBridgeService.isVisible().visible&&this._editorBridgeService.changeVisible({visible:!1,eventType:b.DeviceInputEventType.PointerDown})})))})}))}_onApplyTypeChanged(){this.disposeWithMe(l.toDisposable(this._autoFillService.applyType$.subscribe(()=>{this._handleFillData()})))}_triggerAutoFill(t,n){var d;if(t.startColumn===n.startColumn&&t.startRow===n.startRow&&t.endColumn===n.endColumn&&t.endRow===n.endRow)return;if(n.endColumn<t.endColumn&&n.endColumn>t.startColumn){this._commandService.executeCommand(an.id,{clearRange:{startRow:n.startRow,endRow:n.endRow,startColumn:n.endColumn+1,endColumn:t.endColumn},selectionRange:n});return}if(n.endRow<t.endRow&&n.endRow>t.startRow){this._commandService.executeCommand(an.id,{clearRange:{startRow:n.endRow+1,endRow:t.endRow,startColumn:n.startColumn,endColumn:n.endColumn},selectionRange:n});return}const o={startRow:n.startRow,endRow:n.endRow,startColumn:n.startColumn,endColumn:n.endColumn};let r=null;if(n.startRow<t.startRow)r=l.Direction.UP,o.endRow=t.startRow-1;else if(n.endRow>t.endRow)r=l.Direction.DOWN,o.startRow=t.endRow+1;else if(n.startColumn<t.startColumn)r=l.Direction.LEFT,o.endColumn=t.startColumn-1;else if(n.endColumn>t.endColumn)r=l.Direction.RIGHT,o.startColumn=t.endColumn+1;else return;const s=this._univerInstanceService.getCurrentUniverSheetInstance().getUnitId(),a=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();this._autoFillService.direction=r,this._autoFillService.autoFillLocation={source:t,target:o,unitId:s,subUnitId:a},this._autoFillService.getActiveHooks().forEach(u=>{var h;(h=u==null?void 0:u.onBeforeFillData)==null||h.call(u,{source:t,target:o,unitId:s,subUnitId:a},r)}),(d=this._autoFillService.menu.find(u=>u.value===ie.SERIES))!=null&&d.disable?this._autoFillService.applyType=ie.COPY:this._autoFillService.applyType=ie.SERIES}_handleDbClickFill(t){const n=this._detectFillRange(t);n.endRow<=t.endRow||this._triggerAutoFill(t,n)}_detectFillRange(t){var m,g,S,f,C,R;const{startRow:n,endRow:o,startColumn:r,endColumn:s}=t,a=(m=this._univerInstanceService.getCurrentUniverSheetInstance())==null?void 0:m.getActiveSheet();if(!a)return t;const c=a.getCellMatrix(),d=a.getMaxRows()-1,u=a.getMaxColumns()-1;let h=o;if(r>0&&((g=c.getValue(n,r-1))==null?void 0:g.v)!=null){let M=n;for(;((S=c.getValue(M,r-1))==null?void 0:S.v)!=null&&M<d;)M+=1;h=M-1}else if(s<u&&((f=c.getValue(o,s+1))==null?void 0:f.v)!=null){let M=n;for(;((C=c.getValue(M,s+1))==null?void 0:C.v)!=null&&M<d;)M+=1;h=M-1}for(let M=o+1;M<=h;M++)for(let T=r;T<=s;T++)if(((R=c.getValue(M,T))==null?void 0:R.v)!=null){h=M-1;break}return{startColumn:r,endColumn:s,startRow:n,endRow:h}}_handleFillData(){const{source:t,target:n,unitId:o=this._univerInstanceService.getCurrentUniverSheetInstance().getUnitId(),subUnitId:r=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId()}=this._autoFillService.autoFillLocation||{},s=this._autoFillService.direction;if(!t||!n)return;const a=l.Rectangle.union(t,n),c=this._autoFillService.applyType,d=this._autoFillService.getActiveHooks();this._commandService.syncExecuteCommand(_.SetSelectionsOperation.id,{selections:[{primary:{...a,actualRow:a.startRow,actualColumn:a.startColumn,endColumn:a.startColumn,endRow:a.startRow},range:{...a,rangeType:l.RANGE_TYPE.NORMAL}}],unitId:o,subUnitId:r});const u=[],h=[];d.forEach(g=>{var C;const{undos:S,redos:f}=((C=g.onFillData)==null?void 0:C.call(g,{source:t,target:n,unitId:o,subUnitId:r},s,c))||{};S&&u.push(...S),f&&h.push(...f)}),h.every(g=>this._commandService.syncExecuteCommand(g.id,g.params))&&this._undoRedoService.pushUndoRedo({unitID:o,undoMutations:u,redoMutations:h}),d.forEach(g=>{var S;(S=g.onAfterFillData)==null||S.call(g,{source:t,target:n,unitId:o,subUnitId:r},s,c)}),this._autoFillService.setShowMenu(!0)}_getApplyData(t,n,o,r,s,a=!0){const c=[],d=Math.floor(o/n),u=o%n,h=this._autoFillService.getRules();if(!a&&s===ie.ONLY_FORMAT)return console.error("ERROR: only format can not be applied when hasStyle is false"),[];const m={};h.forEach(g=>{m[g.type]=[]}),h.forEach(g=>{const{type:S,applyFunctions:f={}}=g,C=t[S];C&&C.forEach(R=>{const M=ns(R.index,u),T=R.index.length*d+M,w=this._applyFunctions(R,T,r,s,f,t),E=is(n,o,R.index);m[S].push({data:w,index:E})})});for(let g=0;g<o;g++)h.forEach(S=>{const{type:f}=S,C=m[f];for(let R=0;R<C.length;R++)g in C[R].index&&c.push(C[R].data[C[R].index[g]])});return c}_applyFunctions(t,n,o,r,s,a){const{data:c}=t,d=o===l.Direction.UP||o===l.Direction.LEFT;if(r===ie.COPY){const u=s==null?void 0:s[ie.COPY];return u?u(t,n,o,a):(d&&c.reverse(),st(c,n))}if(r===ie.SERIES){const u=s==null?void 0:s[ie.SERIES];return u?u(t,n,o,a):(d&&c.reverse(),s!=null&&s[ie.COPY]?s[ie.COPY](t,n,o,a):st(c,n))}if(r===ie.ONLY_FORMAT){const u=s==null?void 0:s[ie.ONLY_FORMAT];return u?u(t,n,o,a):os(c,n)}}_getCopyData(t,n){const{startRow:o,startColumn:r,endRow:s,endColumn:a}=t,c=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getCellMatrix(),d=this._autoFillService.getRules(),u=[],h=n===l.Direction.DOWN||n===l.Direction.UP;let m,g,S,f;h?(m=r,g=a,S=o,f=s):(m=o,g=s,S=r,f=a);for(let C=m;C<=g;C++){const R=this._getEmptyCopyDataPiece(),M={type:void 0,cellData:void 0};for(let T=S;T<=f;T++){let w;h?w=c.getValue(T,C):w=c.getValue(C,T);const{type:E,isContinue:y}=d.find(x=>x.match(w))||Sr;if(y(M,w)){const x=R[E],O=x[x.length-1];O.data.push(w),O.index.push(T-S)}else{const x=R[E];x?x.push({data:[w],index:[T-S]}):R[E]=[{data:[w],index:[T-S]}]}M.type=E,M.cellData=w}u.push(R)}return u}_getEmptyCopyDataPiece(){const t={};return this._autoFillService.getRules().forEach(n=>{t[n.type]=[]}),t}_getMergeApplyData(t,n,o,r){const s=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getMergeData(),a=[];for(let c=t.startRow;c<=t.endRow;c++)for(let d=t.startColumn;d<=t.endColumn;d++){const{isMergedMainCell:u,startRow:h,startColumn:m,endRow:g,endColumn:S}=b.getCellInfoInMergeData(c,d,s);if(u){if(o===l.Direction.DOWN){let f=h+r,C=g+r;for(;C<=n.endRow;)a.push({startRow:f,startColumn:m,endRow:C,endColumn:S}),f+=r,C+=r}else if(o===l.Direction.UP){let f=h-r,C=g-r;for(;f>=n.startRow;)a.push({startRow:f,startColumn:m,endRow:C,endColumn:S}),f-=r,C-=r}else if(o===l.Direction.RIGHT){let f=m+r,C=S+r;for(;C<=n.endColumn;)a.push({startRow:h,startColumn:f,endRow:g,endColumn:C}),f+=r,C+=r}else if(o===l.Direction.LEFT){let f=m-r,C=S-r;for(;f>=n.startColumn;)a.push({startRow:h,startColumn:f,endRow:g,endColumn:C}),f-=r,C-=r}}}return a}_presetAndCacheData(t,n){const{source:o,target:r}=t,s=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getCellMatrix(),a=[];for(let c=r.startRow;c<=r.endRow;c++){const d=[];for(let u=r.startColumn;u<=r.endColumn;u++)d.push(l.Tools.deepClone(s.getValue(c,u)));a.push(d)}this._beforeApplyData=a,this._copyData=this._getCopyData(o,n),this._hasSeries(this._copyData)?this._autoFillService.setDisableApplyType(ie.SERIES,!1):this._autoFillService.setDisableApplyType(ie.SERIES,!0)}_fillData(t,n,o){var j,oe;const r=[],s=[];let a=!0;o===ie.NO_FORMAT&&(a=!1,o=ie.SERIES);const{source:c,target:d,unitId:u,subUnitId:h}=t;if(!c||!d||n==null)return{undos:r,redos:s};const{startRow:m,startColumn:g,endRow:S,endColumn:f}=c,{startRow:C,startColumn:R,endRow:M,endColumn:T}=d,w=this._copyData;let E;n===l.Direction.DOWN||n===l.Direction.UP?E=S-m+1:E=f-g+1;const y=[];if(n===l.Direction.DOWN||n===l.Direction.UP){const G=M-C+1,q=[];for(let ee=R;ee<=T;ee++){const ae=w[ee-R],se=this._getApplyData(ae,E,G,n,o,a);q.push(se)}for(let ee=0;ee<q[0].length;ee++){const ae=[];for(let se=0;se<q.length;se++)ae.push({s:null,...q[se][ee]});y.push(ae)}}else{const G=T-R+1;for(let q=C;q<=M;q++){const ee=w[q-C],ae=this._getApplyData(ee,E,G,n,o,a),se=[];for(let ce=0;ce<ae.length;ce++)se.push({s:null,...ae[ce]});y.push(se)}}let x=[];const O=this._univerInstanceService.getCurrentUniverSheetInstance().getStyles();a?(x=this._getMergeApplyData(c,d,n,E),y.forEach(G=>{G.forEach(q=>{q&&O&&O&&(q.s=O.getStyleByCell(q))})})):y.forEach((G,q)=>{G.forEach((ee,ae)=>{ee&&O&&(ee.s=O.getStyleByCell(this._beforeApplyData[q][ae])||null)})}),o===ie.ONLY_FORMAT&&y.forEach((G,q)=>{G.forEach((ee,ae)=>{if(ee){const se=this._beforeApplyData[q][ae]||{};ee.f=se.f,ee.si=se.si,ee.t=se.t,ee.v=se.v}})});const A={get:this._injector.get.bind(this._injector)},k=[],N=(oe=(j=this._univerInstanceService.getUniverSheetInstance(u))==null?void 0:j.getSheetBySheetId(h))==null?void 0:oe.getMergeData();N&&N.forEach(G=>{l.Rectangle.intersects(G,d)&&k.push(G)});const B={unitId:u,subUnitId:h,ranges:k},F=_.RemoveMergeUndoMutationFactory(A,B);s.push({id:_.RemoveWorksheetMergeMutation.id,params:B}),r.push({id:_.AddWorksheetMergeMutation.id,params:F});const W={subUnitId:h,unitId:u,cellValue:Uo([d])},$=_.SetRangeValuesUndoMutationFactory(A,W),Z=this._sheetInterceptorService.onCommandExecute({id:_.ClearSelectionContentCommand.id});s.push({id:_.SetRangeValuesMutation.id,params:W},...Z.redos),r.push(...Z.undos,{id:_.SetRangeValuesMutation.id,params:$});const z=new l.ObjectMatrix,{startRow:Q,startColumn:re,endRow:Y,endColumn:L}=d;for(let G=0;G<=Y-Q;G++)for(let q=0;q<=L-re;q++)y[G][q]&&z.setValue(G+Q,q+re,y[G][q]);const U={subUnitId:h,unitId:u,cellValue:z.getMatrix()},X=_.SetRangeValuesUndoMutationFactory(A,U);if(r.push({id:_.SetRangeValuesMutation.id,params:X}),s.push({id:_.SetRangeValuesMutation.id,params:U}),x!=null&&x.length){const G=_.getAddMergeMutationRangeByType(x),q={unitId:u,subUnitId:h,ranges:G},ee=_.AddMergeUndoMutationFactory(A,q);r.push({id:_.RemoveWorksheetMergeMutation.id,params:ee}),s.push({id:_.AddWorksheetMergeMutation.id,params:q})}return{undos:r,redos:s}}_hasSeries(t){return t.some(n=>Object.keys(n).some(r=>{var s;return!!((s=n[r])!=null&&s.length&&![ue.OTHER,ue.FORMULA].includes(r))}))}};exports.AutoFillController=cl([l.OnLifecycle(l.LifecycleStages.Steady,exports.AutoFillController),ke(0,l.IUniverInstanceService),ke(1,_e),ke(2,l.ICommandService),ke(3,l.IUndoRedoService),ke(4,Yt),ke(5,Ee),ke(6,D.Inject(_.SheetInterceptorService)),ke(7,D.Inject(_.SelectionManagerService)),ke(8,D.Inject(D.Injector))],exports.AutoFillController);const _r={id:"sheet.command.hide-row-confirm",type:l.CommandType.COMMAND,handler:async i=>{var c;const t=(c=i.get(_.SelectionManagerService).getSelections())==null?void 0:c.map(d=>d.range);if(!(t!=null&&t.length))return!1;const n=i.get(l.ICommandService),a=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet().getVisibleRows();if(qo(a,t)){const d=i.get(I.IConfirmService),u=i.get(l.LocaleService);return await d.confirm({id:"sheet.confirm.hide-row",title:{title:u.t("info.problem")},children:{title:u.t("rightClick.hideAllRowsAlert")},cancelText:u.t("button.cancel"),confirmText:u.t("button.confirm")}),!1}return await n.executeCommand(_.SetRowHiddenCommand.id),!0}},fr={id:"sheet.command.hide-col-confirm",type:l.CommandType.COMMAND,handler:async i=>{var c;const t=(c=i.get(_.SelectionManagerService).getSelections())==null?void 0:c.map(d=>d.range);if(!(t!=null&&t.length))return!1;const n=i.get(l.ICommandService),a=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet().getVisibleCols();if(Jo(a,t)){const d=i.get(I.IConfirmService),u=i.get(l.LocaleService);return await d.confirm({id:"sheet.confirm.hide-col",title:{title:u.t("info.problem")},children:{title:u.t("rightClick.hideAllColumnsAlert")},cancelText:u.t("button.cancel"),confirmText:u.t("button.confirm")}),!1}return await n.executeCommand(_.SetColHiddenCommand.id),!0}},Ai={type:l.CommandType.COMMAND,id:"sheet.command.set-range-bold",handler:async i=>{const e=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?e.executeCommand(J.SetInlineFormatBoldCommand.id):e.executeCommand(_.SetBoldCommand.id)}},Di={type:l.CommandType.COMMAND,id:"sheet.command.set-range-italic",handler:async i=>{const e=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?e.executeCommand(J.SetInlineFormatItalicCommand.id):e.executeCommand(_.SetItalicCommand.id)}},Ni={type:l.CommandType.COMMAND,id:"sheet.command.set-range-underline",handler:async i=>{const e=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?e.executeCommand(J.SetInlineFormatUnderlineCommand.id):e.executeCommand(_.SetUnderlineCommand.id)}},Pi={type:l.CommandType.COMMAND,id:"sheet.command.set-range-stroke",handler:async i=>{const e=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?e.executeCommand(J.SetInlineFormatStrikethroughCommand.id):e.executeCommand(_.SetStrikeThroughCommand.id)}},dl={type:l.CommandType.COMMAND,id:"sheet.command.set-range-subscript",handler:async i=>{const e=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?e.executeCommand(J.SetInlineFormatSubscriptCommand.id):!1}},ul={type:l.CommandType.COMMAND,id:"sheet.command.set-range-superscript",handler:async i=>{const e=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?e.executeCommand(J.SetInlineFormatSuperscriptCommand.id):!1}},pr={type:l.CommandType.COMMAND,id:"sheet.command.set-range-fontsize",handler:async(i,e)=>{const t=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?t.executeCommand(J.SetInlineFormatFontSizeCommand.id,e):t.executeCommand(_.SetFontSizeCommand.id,e)}},vr={type:l.CommandType.COMMAND,id:"sheet.command.set-range-font-family",handler:async(i,e)=>{const t=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?t.executeCommand(J.SetInlineFormatFontFamilyCommand.id,e):t.executeCommand(_.SetFontFamilyCommand.id,e)}},Vn={type:l.CommandType.COMMAND,id:"sheet.command.set-range-text-color",handler:async(i,e)=>{const t=i.get(l.ICommandService);return i.get(l.IContextService).getContextValue(l.EDITOR_ACTIVATED)?t.executeCommand(J.SetInlineFormatTextColorCommand.id,e):t.executeCommand(_.SetTextColorCommand.id,e)}};function Cr(i,e){return e.some(t=>hl(i,t))}function hl(i,e){const{startRow:t,startColumn:n,endColumn:o,endRow:r}=e,s=i.getMatrixWithMergedCells(t,n,r,o);let a=!1;return s.forValue((c,d,u)=>{if(u&&(c!==t||d!==n)&&i.cellHasValue(u))return a=!0,!1}),a}function Ir(i,e,t,n){const o=[],r=[],s=t.getSheetId();return n.forEach(a=>{const c=ml(t,a),d={unitId:e,subUnitId:s,cellValue:c.getData()},u=_.SetRangeValuesUndoMutationFactory(i,d);o.push({id:_.SetRangeValuesMutation.id,params:u}),r.push({id:_.SetRangeValuesMutation.id,params:d})}),{undos:o,redos:r}}function ml(i,e){const{startRow:t,startColumn:n,endColumn:o,endRow:r}=e,s=i.getMatrixWithMergedCells(t,n,r,o),a=new l.ObjectMatrix;return s.forValue((c,d,u)=>{u&&(c!==t||d!==n)&&a.setValue(c,d,null)}),a}var gl=Object.defineProperty,Sl=Object.getOwnPropertyDescriptor,_l=(i,e,t,n)=>{for(var o=n>1?void 0:n?Sl(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&gl(e,t,o),o},ni=(i,e)=>(t,n)=>e(t,n,i),Oe=(i=>(i[i.OFF=0]="OFF",i[i.ONCE=1]="ONCE",i[i.INFINITE=2]="INFINITE",i))(Oe||{});const Et=D.createIdentifier("univer.format-painter-service");let vi=class extends l.Disposable{constructor(e,t,n){super();v(this,"status$");v(this,"_selectionFormat");v(this,"_markId",null);v(this,"_status$");this._selectionManagerService=e,this._univerInstanceService=t,this._markSelectionService=n,this._status$=new H.BehaviorSubject(0),this.status$=this._status$.asObservable(),this._selectionFormat={styles:new l.ObjectMatrix,merges:[]}}setStatus(e){e!==0&&this._getSelectionRangeFormat(),this._updateRangeMark(e),this._status$.next(e)}getStatus(){return this._status$.getValue()}_updateRangeMark(e){if(this._markSelectionService.removeAllShapes(),this._markId=null,e!==0){const t=this._selectionManagerService.getLast();if(t){const n=this._selectionManagerService.createCopyPasteSelection();e===2?this._markId=this._markSelectionService.addShape({...t,style:n}):this._markId=this._markSelectionService.addShape({...t,style:n},[_.SetRangeValuesMutation.id])}}}_getSelectionRangeFormat(){const e=this._selectionManagerService.getLast(),t=e==null?void 0:e.range;if(!t)return;const{startRow:n,endRow:o,startColumn:r,endColumn:s}=t,a=this._univerInstanceService.getCurrentUniverSheetInstance(),d=(a==null?void 0:a.getActiveSheet()).getCellMatrix(),u=this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getMergeData(),h=a.getStyles(),m=new l.ObjectMatrix;for(let g=n;g<=o;g++)for(let S=r;S<=s;S++){const f=d.getValue(g,S);m.setValue(g,S,h.getStyleByCell(f)||{});const{isMergedMainCell:C,...R}=b.getCellInfoInMergeData(g,S,u);C&&this._selectionFormat.merges.push({startRow:R.startRow,startColumn:R.startColumn,endRow:R.endRow,endColumn:R.endColumn})}this._selectionFormat.styles=m}getSelectionFormat(){return this._selectionFormat}};vi=_l([ni(0,D.Inject(_.SelectionManagerService)),ni(1,l.IUniverInstanceService),ni(2,Xt)],vi);const Hi={id:"sheet.operation.set-format-painter",type:l.CommandType.OPERATION,handler:(i,e)=>e?(i.get(Et).setStatus(e.status),!0):!1},Rr={type:l.CommandType.COMMAND,id:"sheet.command.set-infinite-format-painter",handler:async i=>{const t=i.get(Et).getStatus();let n;return t!==Oe.OFF?n=Oe.OFF:n=Oe.INFINITE,i.get(l.ICommandService).executeCommand(Hi.id,{status:n})}},Li={type:l.CommandType.COMMAND,id:"sheet.command.set-once-format-painter",handler:async i=>{const t=i.get(Et).getStatus();let n;return t!==Oe.OFF?n=Oe.OFF:n=Oe.ONCE,i.get(l.ICommandService).executeCommand(Hi.id,{status:n})}},Mr={type:l.CommandType.COMMAND,id:"sheet.command.apply-format-painter",handler:async(i,e)=>{const t=i.get(l.ICommandService),n=i.get(l.IUndoRedoService),o=i.get(l.IUniverInstanceService),r=i.get(_.SelectionManagerService),s=i.get(_.SheetInterceptorService),{styleValues:a,styleRange:c,mergeRanges:d,unitId:u=o.getCurrentUniverSheetInstance().getUnitId(),subUnitId:h=o.getCurrentUniverSheetInstance().getActiveSheet().getSheetId()}=e,m=c?[c]:r.getSelectionRanges();if(!m||!m.length)return!1;const g=new l.ObjectMatrix;let S;if(l.Tools.isArray(a))for(let W=0;W<m.length;W++){const{startRow:$,startColumn:Z,endRow:z,endColumn:Q}=m[W];for(let re=0;re<=z-$;re++)for(let Y=0;Y<=Q-Z;Y++)g.setValue(re+$,Y+Z,a[re][Y])}else if(l.isICellData(a))for(let W=0;W<m.length;W++){const{startRow:$,startColumn:Z}=m[W];g.setValue($,Z,a)}else S=a;const f={subUnitId:h,unitId:u,cellValue:S??g.getMatrix()},C=_.SetRangeValuesUndoMutationFactory(i,f);if(!s.fetchThroughInterceptors(_.INTERCEPTOR_POINT.PERMISSION)(null,{id:_.SetRangeValuesCommand.id,params:f}))return!1;const R=t.syncExecuteCommand(_.SetRangeValuesMutation.id,f),{undos:M,redos:T}=s.onCommandExecute({id:_.SetRangeValuesCommand.id,params:{...f,range:m}}),w=_.getAddMergeMutationRangeByType(d),E=o.getUniverSheetInstance(u).getSheetBySheetId(h),y=[],x=[],O=Cr(E,w),A={unitId:u,subUnitId:h,ranges:w},k={unitId:u,subUnitId:h,ranges:w};y.push({id:_.RemoveWorksheetMergeMutation.id,params:A}),y.push({id:_.AddWorksheetMergeMutation.id,params:k});const N=_.RemoveMergeUndoMutationFactory(i,A),B=_.AddMergeUndoMutationFactory(i,k);if(x.push({id:_.RemoveWorksheetMergeMutation.id,params:B}),x.push({id:_.AddWorksheetMergeMutation.id,params:N}),O){const W=Ir(i,u,E,w);y.unshift(...W.redos),x.push(...W.undos)}const F=await l.sequenceExecute([...T,...y],t);return R&&F.result?(n.pushUndoRedo({unitID:u,undoMutations:[{id:_.SetRangeValuesMutation.id,params:C},...M,...x],redoMutations:[{id:_.SetRangeValuesMutation.id,params:f},...T,...y]}),!0):!1}},zn={type:l.CommandType.COMMAND,id:"sheet.command.set-selection-frozen",handler:async(i,e)=>{const{type:t}=e||{},n=i.get(l.IUniverInstanceService),o=i.get(l.IUndoRedoService),r=n.getCurrentUniverSheetInstance().getUnitId(),s=n.getCurrentUniverSheetInstance().getActiveSheet().getSheetId(),a=i.get(l.ICommandService),d=i.get(_.SelectionManagerService).getSelections();if(!d)return!1;const u=d[(d==null?void 0:d.length)-1],{range:h}=u,m=i.get(Je),{sheetViewStartRow:g=0,sheetViewStartColumn:S=0}=m.getCurrentScroll()||{};let f,C,R,M;const{startRow:T,startColumn:w,rangeType:E}=h;if(E===l.RANGE_TYPE.ROW||t===1)f=T,R=T-g,C=-1,M=0;else if(E===l.RANGE_TYPE.COLUMN||t===2)f=-1,R=0,C=w,M=w-S;else if(E===l.RANGE_TYPE.NORMAL)f=T,R=T-g,C=w,M=w-S;else return!1;const y={unitId:r,subUnitId:s,startRow:f,startColumn:C,xSplit:C>0?Math.max(1,M):M,ySplit:f>0?Math.max(1,R):R},x=_.SetFrozenMutationFactory(i,y);return a.syncExecuteCommand(_.SetFrozenMutation.id,y)&&o.pushUndoRedo({unitID:r,undoMutations:[{id:_.SetFrozenMutation.id,params:x}],redoMutations:[{id:_.SetFrozenMutation.id,params:y}]}),!0}},br={type:l.CommandType.COMMAND,id:"sheet.command.set-row-frozen",handler:async i=>(i.get(l.ICommandService).executeCommand(zn.id,{type:1}),!0)},wr={type:l.CommandType.COMMAND,id:"sheet.command.set-col-frozen",handler:async i=>(i.get(l.ICommandService).executeCommand(zn.id,{type:2}),!0)},Tr={type:l.CommandType.COMMAND,id:"sheet.command.cancel-frozen",handler:async i=>{const e=i.get(l.ICommandService),t=i.get(l.IUniverInstanceService),n=i.get(l.IUndoRedoService),o=t.getCurrentUniverSheetInstance().getUnitId(),r=t.getCurrentUniverSheetInstance().getActiveSheet().getSheetId(),s={unitId:o,subUnitId:r,startRow:-1,startColumn:-1,xSplit:0,ySplit:0},a=_.SetFrozenMutationFactory(i,s);return e.syncExecuteCommand(_.SetFrozenMutation.id,s)&&n.pushUndoRedo({unitID:o,undoMutations:[{id:_.SetFrozenMutation.id,params:a}],redoMutations:[{id:_.SetFrozenMutation.id,params:s}]}),!0}},yt="UI_PLUGIN_SHEETS",Xn=`${yt}_COLOR_PICKER_COMPONENT`,Er=`${yt}_FONT_FAMILY_COMPONENT`,yr=`${yt}_FONT_FAMILY_ITEM_COMPONENT`,Or=`${yt}_FONT_SIZE_COMPONENT`,Ui=`${yt}_MENU_ITEM_INPUT_COMPONENT`,fl="univer-sheets-ui-context-menu-input",pl="univer-sheets-ui-context-menu-input-container",vl="univer-sheets-ui-context-menu-input-number",ii={sheetsUiContextMenuInput:fl,sheetsUiContextMenuInputContainer:pl,sheetsUiContextMenuInputNumber:vl},Cl=i=>{const{prefix:e,suffix:t,value:n,onChange:o,min:r=Number.MIN_SAFE_INTEGER,max:s=Number.MAX_SAFE_INTEGER}=i,a=K.useDependency(l.LocaleService),[c,d]=P.useState(),u=m=>{d(m==null?void 0:m.toString()),o((m==null?void 0:m.toString())??"")};P.useEffect(()=>{d(n)},[n]);function h(m){m.key==="Backspace"&&m.stopPropagation()}return p.jsxs("div",{className:ii.sheetsUiContextMenuInput,children:[a.t(e),p.jsx("span",{className:ii.sheetsUiContextMenuInputContainer,onClick:m=>m.stopPropagation(),children:p.jsx(Se.InputNumber,{className:ii.sheetsUiContextMenuInputNumber,value:Number(c),precision:0,onKeyDown:h,onChange:u,min:r,max:s})}),a.t(t)]})};var de=(i=>(i.ROW_HEADER_CONTEXT_MENU="rowHeaderContextMenu",i.COL_HEADER_CONTEXT_MENU="colHeaderContextMenu",i.SHEET_BAR="sheetBar",i))(de||{});function Il(i){const e=i.get(Et);return{id:Li.id,subId:Rr.id,group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON,icon:"BrushSingle",title:"Format Painter",tooltip:"toolbar.formatPainter",positions:[I.MenuPosition.TOOLBAR_START],activated$:new H.Observable(t=>{let n=!1;const o=e.status$.subscribe(r=>{n=r!==Oe.OFF,t.next(n)});return t.next(n),()=>{o.unsubscribe()}}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:_.getCurrentSheetDisabled$(i)}}function Rl(i){const e=i.get(l.ICommandService),t=i.get(l.IUniverInstanceService),n=i.get(l.IContextService),o=i.get(_.SelectionManagerService);return{id:Ai.id,group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",positions:[I.MenuPosition.TOOLBAR_START],disabled$:_.getCurrentSheetDisabled$(i),activated$:new H.Observable(r=>{const s=e.onCommandExecuted(a=>{var d,u;const c=a.id;if(c===_.SetRangeValuesMutation.id||c===_.SetSelectionsOperation.id){const h=(d=o.getLast())==null?void 0:d.primary,m=t.getCurrentUniverSheetInstance().getActiveSheet();let g=l.FontWeight.NORMAL;if(h!=null){const S=m.getRange(h.startRow,h.startColumn);g=S==null?void 0:S.getFontWeight()}r.next(g===l.FontWeight.BOLD)}if((c===J.SetTextSelectionsOperation.id||c===J.SetInlineFormatCommand.id)&&n.getContextValue(l.EDITOR_ACTIVATED)&&n.getContextValue(l.FOCUSING_SHEET)){const h=Gt(i);if(h==null)return;const m=(u=h.ts)==null?void 0:u.bl;r.next(m===l.BooleanNumber.TRUE)}});return r.next(!1),s.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET)}}function Ml(i){const e=i.get(l.ICommandService),t=i.get(l.IUniverInstanceService),n=i.get(_.SelectionManagerService),o=i.get(l.IContextService);return{id:Di.id,group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",positions:[I.MenuPosition.TOOLBAR_START],disabled$:_.getCurrentSheetDisabled$(i),activated$:new H.Observable(r=>{const s=e.onCommandExecuted(a=>{var d,u;const c=a.id;if(c===_.SetRangeValuesMutation.id||c===_.SetSelectionsOperation.id){const h=(d=n.getLast())==null?void 0:d.primary,m=t.getCurrentUniverSheetInstance().getActiveSheet();let g=l.FontItalic.NORMAL;if(h!=null){const S=m.getRange(h.startRow,h.startColumn);g=S==null?void 0:S.getFontStyle()}r.next(g===l.FontItalic.ITALIC)}if((c===J.SetTextSelectionsOperation.id||c===J.SetInlineFormatCommand.id)&&o.getContextValue(l.EDITOR_ACTIVATED)&&o.getContextValue(l.FOCUSING_SHEET)){const h=Gt(i);if(h==null)return;const m=(u=h.ts)==null?void 0:u.it;r.next(m===l.BooleanNumber.TRUE)}});return r.next(!1),s.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET)}}function bl(i){const e=i.get(l.ICommandService),t=i.get(l.IUniverInstanceService),n=i.get(_.SelectionManagerService),o=i.get(l.IContextService);return{id:Ni.id,group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",positions:[I.MenuPosition.TOOLBAR_START],disabled$:_.getCurrentSheetDisabled$(i),activated$:new H.Observable(r=>{const s=e.onCommandExecuted(a=>{var d,u;const c=a.id;if(c===_.SetRangeValuesMutation.id||c===_.SetSelectionsOperation.id){const h=(d=n.getLast())==null?void 0:d.primary,m=t.getCurrentUniverSheetInstance().getActiveSheet();let g;if(h!=null){const S=m.getRange(h.startRow,h.startColumn);g=S==null?void 0:S.getUnderline()}r.next(!!(g&&g.s))}if((c===J.SetTextSelectionsOperation.id||c===J.SetInlineFormatCommand.id)&&o.getContextValue(l.EDITOR_ACTIVATED)&&o.getContextValue(l.FOCUSING_SHEET)){const h=Gt(i);if(h==null)return;const m=(u=h.ts)==null?void 0:u.ul;r.next((m==null?void 0:m.s)===l.BooleanNumber.TRUE)}});return r.next(!1),s.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET)}}function wl(i){const e=i.get(l.ICommandService),t=i.get(l.IUniverInstanceService),n=i.get(_.SelectionManagerService),o=i.get(l.IContextService);return{id:Pi.id,group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",positions:[I.MenuPosition.TOOLBAR_START],disabled$:_.getCurrentSheetDisabled$(i),activated$:new H.Observable(r=>{const s=e.onCommandExecuted(a=>{var d,u;const c=a.id;if(c===_.SetRangeValuesMutation.id||c===_.SetSelectionsOperation.id){const h=(d=n.getLast())==null?void 0:d.primary,m=t.getCurrentUniverSheetInstance().getActiveSheet();let g;if(h!=null){const S=m.getRange(h.startRow,h.startColumn);g=S==null?void 0:S.getStrikeThrough()}r.next(!!(g&&g.s))}if((c===J.SetTextSelectionsOperation.id||c===J.SetInlineFormatCommand.id)&&o.getContextValue(l.EDITOR_ACTIVATED)&&o.getContextValue(l.FOCUSING_SHEET)){const h=Gt(i);if(h==null)return;const m=(u=h.ts)==null?void 0:u.st;r.next((m==null?void 0:m.s)===l.BooleanNumber.TRUE)}});return r.next(!1),s.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET)}}function Tl(i){const e=i.get(l.ICommandService),t=i.get(l.IUniverInstanceService),n=i.get(_.SelectionManagerService);return{id:vr.id,tooltip:"toolbar.font",group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.SELECTOR,label:Er,positions:[I.MenuPosition.TOOLBAR_START],selections:I.FONT_FAMILY_LIST.map(o=>({label:{name:yr,hoverable:!0},value:o.value})),disabled$:_.getCurrentSheetDisabled$(i),value$:new H.Observable(o=>{const r=I.FONT_FAMILY_LIST[0].value,s=e.onCommandExecuted(a=>{var m;const c=a.id;if(c!==_.SetRangeValuesMutation.id&&c!==_.SetSelectionsOperation.id)return;const d=(m=n.getLast())==null?void 0:m.primary,u=t.getCurrentUniverSheetInstance().getActiveSheet();let h;if(d!=null){const g=u.getRange(d.startRow,d.startColumn);h=g==null?void 0:g.getFontFamily()}o.next(h??r)});return o.next(r),s.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET)}}function El(i){const e=i.get(l.ICommandService),t=i.get(l.IUniverInstanceService),n=i.get(_.SelectionManagerService),o=i.get(l.IContextService),r=_.getCurrentSheetDisabled$(i);return{id:pr.id,group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Or,props:{min:1,max:400,disabled$:r}},positions:[I.MenuPosition.TOOLBAR_START],selections:I.FONT_SIZE_LIST,disabled$:r,value$:new H.Observable(s=>{const c=e.onCommandExecuted(d=>{var h,m;const u=d.id;if(u===_.SetRangeValuesMutation.id||u===_.SetSelectionsOperation.id){const g=(h=n.getLast())==null?void 0:h.primary,S=t.getCurrentUniverSheetInstance().getActiveSheet();let f;if(g!=null){const C=S.getRange(g.startRow,g.startColumn);f=C==null?void 0:C.getFontSize()}s.next(f??14)}if((u===J.SetTextSelectionsOperation.id||u===J.SetInlineFormatCommand.id)&&o.getContextValue(l.EDITOR_ACTIVATED)&&o.getContextValue(l.FOCUSING_SHEET)){const g=Gt(i);if(g==null)return;const S=(m=g.ts)==null?void 0:m.fs;s.next(S??14)}});return s.next(14),c.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET)}}function yl(i){return{id:_.ResetTextColorCommand.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:Vn.id,disabled$:_.getCurrentSheetDisabled$(i)}}function Ol(i){const e=i.get(l.ICommandService),t=i.get(l.ThemeService);return{id:Vn.id,icon:"FontColor",tooltip:"toolbar.textColor.main",group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON_SELECTOR,positions:[I.MenuPosition.TOOLBAR_START],selections:[{label:{name:Xn,hoverable:!1}}],value$:new H.Observable(n=>{const o=t.getCurrentTheme().textColor,r=e.onCommandExecuted(s=>{if(s.id===Vn.id){const a=s.params.value;n.next(a??o)}});return n.next(o),r.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:_.getCurrentSheetDisabled$(i)}}function xl(i){return{id:_.ResetBackgroundColorCommand.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:_.SetBackgroundColorCommand.id,disabled$:_.getCurrentSheetDisabled$(i)}}function Al(i){const e=i.get(l.ICommandService),t=i.get(l.ThemeService);return{id:_.SetBackgroundColorCommand.id,tooltip:"toolbar.fillColor.main",group:I.MenuGroup.TOOLBAR_FORMAT,type:I.MenuItemType.BUTTON_SELECTOR,positions:[I.MenuPosition.TOOLBAR_START],icon:"PaintBucket",selections:[{label:{name:Xn,hoverable:!1}}],value$:new H.Observable(n=>{const o=t.getCurrentTheme().primaryColor,r=e.onCommandExecuted(s=>{if(s.id===_.SetBackgroundColorCommand.id){const a=s.params.value;n.next(a??o)}});return n.next(o),r.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:_.getCurrentSheetDisabled$(i)}}const uo=[{label:"align.left",icon:"LeftJustifyingSingle",value:l.HorizontalAlign.LEFT},{label:"align.center",icon:"HorizontallySingle",value:l.HorizontalAlign.CENTER},{label:"align.right",icon:"RightJustifyingSingle",value:l.HorizontalAlign.RIGHT}];function Dl(i){const e=i.get(l.IUniverInstanceService),t=i.get(_.SelectionManagerService);return{id:_.SetHorizontalTextAlignCommand.id,icon:uo[0].icon,positions:[I.MenuPosition.TOOLBAR_START],tooltip:"toolbar.horizontalAlignMode.main",group:I.MenuGroup.TOOLBAR_LAYOUT,type:I.MenuItemType.SELECTOR,selections:uo,value$:new H.Observable(n=>{const o=i.get(l.ICommandService).onCommandExecuted(r=>{var u;const s=r.id;if(s!==_.SetHorizontalTextAlignCommand.id&&s!==_.SetSelectionsOperation.id)return;const a=(u=t.getLast())==null?void 0:u.primary,c=e.getCurrentUniverSheetInstance().getActiveSheet();let d;if(a!=null){const h=c.getRange(a.startRow,a.startColumn);d=h==null?void 0:h.getHorizontalAlignment()}n.next(d??l.HorizontalAlign.LEFT)});return n.next(l.HorizontalAlign.LEFT),o.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:_.getCurrentSheetDisabled$(i)}}const ho=[{label:"align.top",icon:"AlignTopSingle",value:l.VerticalAlign.TOP},{label:"align.middle",icon:"VerticalCenterSingle",value:l.VerticalAlign.MIDDLE},{label:"align.bottom",icon:"AlignBottomSingle",value:l.VerticalAlign.BOTTOM}];function Nl(i){const e=i.get(l.IUniverInstanceService),t=i.get(_.SelectionManagerService);return{id:_.SetVerticalTextAlignCommand.id,icon:ho[0].icon,tooltip:"toolbar.verticalAlignMode.main",group:I.MenuGroup.TOOLBAR_LAYOUT,type:I.MenuItemType.SELECTOR,positions:[I.MenuPosition.TOOLBAR_START],selections:ho,value$:new H.Observable(n=>{const o=i.get(l.ICommandService).onCommandExecuted(r=>{var u;const s=r.id;if(s!==_.SetVerticalTextAlignCommand.id&&s!==_.SetSelectionsOperation.id)return;const a=(u=t.getLast())==null?void 0:u.primary,c=e.getCurrentUniverSheetInstance().getActiveSheet();let d;if(a!=null){const h=c.getRange(a.startRow,a.startColumn);d=h==null?void 0:h.getVerticalAlignment()}n.next(d??l.VerticalAlign.TOP)});return n.next(l.VerticalAlign.TOP),o.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:_.getCurrentSheetDisabled$(i)}}const mo=[{label:"textWrap.overflow",icon:"OverflowSingle",value:l.WrapStrategy.OVERFLOW},{label:"textWrap.wrap",icon:"AutowrapSingle",value:l.WrapStrategy.WRAP},{label:"textWrap.clip",icon:"TruncationSingle",value:l.WrapStrategy.CLIP}];function Pl(i){const e=i.get(_.SelectionManagerService),t=i.get(l.IUniverInstanceService);return{id:_.SetTextWrapCommand.id,tooltip:"toolbar.textWrapMode.main",icon:mo[0].icon,group:I.MenuGroup.TOOLBAR_LAYOUT,type:I.MenuItemType.SELECTOR,positions:[I.MenuPosition.TOOLBAR_START],selections:mo,value$:new H.Observable(n=>{const o=i.get(l.ICommandService).onCommandExecuted(r=>{var u;const s=r.id;if(s!==_.SetTextWrapCommand.id&&s!==_.SetSelectionsOperation.id)return;const a=(u=e.getLast())==null?void 0:u.primary,c=t.getCurrentUniverSheetInstance().getActiveSheet();let d;if(a!=null){const h=c.getRange(a.startRow,a.startColumn);d=h==null?void 0:h.getWrapStrategy()}n.next(d??l.WrapStrategy.OVERFLOW)});return n.next(l.WrapStrategy.OVERFLOW),o.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:_.getCurrentSheetDisabled$(i)}}const go=[{label:"textRotate.none",icon:"NoRotationSingle",value:0},{label:"textRotate.angleUp",icon:"LeftRotationFortyFiveDegreesSingle",value:-45},{label:"textRotate.angleDown",icon:"RightRotationFortyFiveDegreesSingle",value:45},{label:"textRotate.vertical",icon:"VerticalTextSingle",value:"v"},{label:"textRotate.rotationUp",icon:"LeftRotationNinetyDegreesSingle",value:-90},{label:"textRotate.rotationDown",icon:"RightRotationNinetyDegreesSingle",value:90}];function Hl(i){const e=i.get(_.SelectionManagerService),t=i.get(l.IUniverInstanceService);return{id:_.SetTextRotationCommand.id,tooltip:"toolbar.textRotateMode.main",icon:go[0].icon,group:I.MenuGroup.TOOLBAR_LAYOUT,type:I.MenuItemType.SELECTOR,selections:go,positions:[I.MenuPosition.TOOLBAR_START],value$:new H.Observable(n=>{const o=i.get(l.ICommandService).onCommandExecuted(r=>{var u;const s=r.id;if(s!==_.SetTextRotationCommand.id&&s!==_.SetSelectionsOperation.id)return;const a=(u=e.getLast())==null?void 0:u.primary,c=t.getCurrentUniverSheetInstance().getActiveSheet();let d;if(a!=null){const h=c.getRange(a.startRow,a.startColumn);d=h==null?void 0:h.getTextRotation()}(d==null?void 0:d.v)===l.BooleanNumber.TRUE?n.next("v"):n.next((d&&d.a)??0)});return n.next(0),o.dispose}),hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:_.getCurrentSheetDisabled$(i)}}function Ll(){return{id:I.CopyCommand.id,group:I.MenuGroup.CONTEXT_MENU_FORMAT,type:I.MenuItemType.BUTTON,title:"rightClick.copy",icon:"Copy",positions:[I.MenuPosition.CONTEXT_MENU,"colHeaderContextMenu","rowHeaderContextMenu"]}}function Ul(){return{id:I.PasteCommand.id,group:I.MenuGroup.CONTEXT_MENU_FORMAT,type:I.MenuItemType.BUTTON,title:"rightClick.paste",icon:"PasteSpecial",positions:[I.MenuPosition.CONTEXT_MENU,"colHeaderContextMenu","rowHeaderContextMenu"]}}const Ot="sheet.menu.paste-special";function kl(){return{id:Ot,group:I.MenuGroup.CONTEXT_MENU_FORMAT,type:I.MenuItemType.SUBITEMS,icon:"PasteSpecial",title:"rightClick.pasteSpecial",positions:[I.MenuPosition.CONTEXT_MENU,"colHeaderContextMenu","rowHeaderContextMenu"]}}function Vl(){return{id:Xo.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteValue",positions:[Ot]}}function Bl(){return{id:Yo.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteFormat",positions:[Ot]}}function Fl(){return{id:Zo.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteColWidth",positions:[Ot]}}function Wl(){return{id:Go.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteBesidesBorder",positions:[Ot]}}function jl(){return{id:_.SetWorksheetRowIsAutoHeightCommand.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,positions:["rowHeaderContextMenu"],icon:"AutoHeight",title:"rightClick.fitContent"}}const Zt="sheet.menu.sheet-frozen";function $l(){return{id:Zt,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",positions:[I.MenuPosition.CONTEXT_MENU]}}const ki="sheet.header-menu.sheet-frozen";function zl(){return{id:ki,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",positions:["rowHeaderContextMenu","colHeaderContextMenu"]}}function Xl(){return{id:zn.id,type:I.MenuItemType.BUTTON,positions:[Zt,ki],title:"rightClick.freeze",icon:"FreezeToSelectedSingle"}}function Yl(){return{id:br.id,type:I.MenuItemType.BUTTON,positions:[Zt],title:"rightClick.freezeRow",icon:"FreezeRowSingle"}}function Zl(){return{id:wr.id,type:I.MenuItemType.BUTTON,positions:[Zt],title:"rightClick.freezeCol",icon:"FreezeColumnSingle"}}function Gl(){return{id:Tr.id,type:I.MenuItemType.BUTTON,positions:[Zt,ki],title:"rightClick.cancelFreeze",icon:"CancelFreezeSingle"}}function Kl(){return{id:_r.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,positions:["rowHeaderContextMenu"],icon:"Hide",title:"rightClick.hideSelectedRow"}}function ql(){return{id:fr.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,positions:["colHeaderContextMenu"],icon:"Hide",title:"rightClick.hideSelectedColumn"}}function Jl(i){const e=i.get(l.IUniverInstanceService),t=i.get(_.SelectionManagerService);function n(){var a;const r=e.getCurrentUniverSheetInstance().getActiveSheet(),s=(a=t.getSelections())==null?void 0:a.map(c=>c.range).filter(c=>c.rangeType===l.RANGE_TYPE.ROW);return!!(s!=null&&s.some(c=>{for(let d=c.startRow;d<=c.endRow;d++)if(!r.getRowVisible(d))return!0;return!1}))}const o=i.get(l.ICommandService);return{id:_.SetSelectedRowsVisibleCommand.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,positions:["rowHeaderContextMenu"],title:"rightClick.showHideRow",hidden$:new H.Observable(r=>{const s=o.onCommandExecuted(a=>{(a.id===_.SetSelectionsOperation.id||a.id===_.SetRowHiddenMutation.id||a.id===_.SetRowVisibleMutation.id)&&r.next(!n())});return r.next(!n()),()=>s.dispose()})}}function Ql(i){const e=i.get(l.IUniverInstanceService),t=i.get(_.SelectionManagerService);function n(){var a;const r=e.getCurrentUniverSheetInstance().getActiveSheet(),s=(a=t.getSelections())==null?void 0:a.map(c=>c.range).filter(c=>c.rangeType===l.RANGE_TYPE.COLUMN);return!s||s.length===0?!1:!!s.some(c=>{for(let d=c.startColumn;d<=c.endColumn;d++)if(!r.getColVisible(d))return!0;return!1})}const o=i.get(l.ICommandService);return{id:_.SetSelectedColsVisibleCommand.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,positions:["colHeaderContextMenu"],title:"rightClick.showHideColumn",hidden$:new H.Observable(r=>{const s=o.onCommandExecuted(a=>{(a.id===_.SetSelectionsOperation.id||a.id===_.SetColHiddenMutation.id||a.id===_.SetColVisibleMutation.id)&&r.next(!n())});return r.next(!n()),()=>s.dispose()})}}function ec(i){const e=i.get(l.ICommandService),t=i.get(l.IUniverInstanceService),n=i.get(_.SelectionManagerService);return{id:_.SetRowHeightCommand.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,icon:"AdjustHeight",positions:["rowHeaderContextMenu"],label:{name:Ui,props:{prefix:"rightClick.rowHeight",suffix:"px",min:2,max:1e3}},value$:new H.Observable(o=>{function r(){var u;const a=(u=n.getLast())==null?void 0:u.primary,c=t.getCurrentUniverSheetInstance().getActiveSheet();let d;a!=null&&(d=c.getRowHeight(a.startRow)),o.next(d??0)}const s=e.onCommandExecuted(a=>{const c=a.id;if(c===_.SetRangeValuesMutation.id||c===_.SetSelectionsOperation.id)return r()});return r(),s.dispose})}}function tc(i){const e=i.get(l.ICommandService),t=i.get(l.IUniverInstanceService),n=i.get(_.SelectionManagerService);return{id:_.SetColWidthCommand.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,icon:"AdjustWidth",positions:["colHeaderContextMenu"],label:{name:Ui,props:{prefix:"rightClick.columnWidth",suffix:"px",min:2,max:1e3}},value$:new H.Observable(o=>{function r(){var u;const a=(u=n.getLast())==null?void 0:u.primary,c=t.getCurrentUniverSheetInstance().getActiveSheet();let d=0;a!=null&&(d=c.getColumnWidth(a.startColumn)),o.next(d)}const s=e.onCommandExecuted(a=>{const c=a.id;if(c===_.SetRangeValuesMutation.id||c===_.SetSelectionsOperation.id)return r()});return r(),s.dispose})}}function Gt(i){var c;const e=i.get(l.IUniverInstanceService),t=i.get(J.TextSelectionManagerService),n=e.getUniverDocInstance(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),o=t.getActiveRange();if(n==null||o==null)return;const r=(c=n.getBody())==null?void 0:c.textRuns;if(r==null)return;const{startOffset:s}=o;return r.find(({st:d,ed:u})=>s>=d&&s<u)}function ve(i,e){const n=i.getCurrentUniverSheetInstance().getUnitId(),o=e.getRenderById(n);if(o==null)return;const{components:r,mainComponent:s,scene:a,engine:c}=o,d=s,u=r.get(fe.ROW),h=r.get(fe.COLUMN),m=r.get(fe.LEFT_TOP);return{spreadsheet:d,spreadsheetRowHeader:u,spreadsheetColumnHeader:h,spreadsheetLeftTopPlaceholder:m,scene:a,engine:c}}function Ci(i,e,t,n){const{startX:o,startY:r,endX:s,endY:a}=n.getCellByIndex(i,e);return{startX:o,startY:r,endX:s,endY:a}}function Mt(i,e,t,n,o){const r=t.getRelativeCoord(b.Vector2.FromArray([i,e])),{x:s,y:a}=r,c=t.getScrollXYByRelativeCoords(r,o),{scaleX:d,scaleY:u}=t.getAncestorScale(),h=n.getCellPositionByOffset(s,a,d,u,c),{row:m,column:g}=h,S=n.getNoMergeCellPositionByIndex(m,g),{startX:f,startY:C,endX:R,endY:M}=S;return{startX:f,startY:C,endX:R,endY:M,row:m,column:g}}function ln(i,e,t,n){const o=t.getRelativeCoord(b.Vector2.FromArray([i,e])),r=t.getViewport(V.VIEW_MAIN),s=t.getScrollXYByRelativeCoords(o,r),{scaleX:a,scaleY:c}=t.getAncestorScale(),{x:d,y:u}=s,h=i/a+d,m=e/c+u;return{x:h,y:m}}const nc={spreadsheetLabel:"Spreadsheet",spreadsheetRightLabel:"more Sheets",toolbar:{undo:"Undo",redo:"Redo",formatPainter:"Paint format",currencyFormat:"Format as currency",percentageFormat:"Format as percent",numberDecrease:"Decrease decimal places",numberIncrease:"Increase decimal places",moreFormats:"More formats",font:"Font",fontSize:"Font size",bold:"Bold",italic:"Italic",strikethrough:"Strikethrough",subscript:"Subscript",superscript:"Superscript",underline:"Underline",textColor:{main:"Text color",right:"Choose color"},resetColor:"Reset",customColor:"CUSTOM",alternatingColors:"Alternating colors",confirmColor:"OK",cancelColor:"Cancel",collapse:"Collapse",fillColor:{main:"Fill color",right:"Choose color"},border:{main:"Border",right:"Border style"},mergeCell:{main:"Merge cells",right:"Choose merge type"},horizontalAlignMode:{main:"Horizontal align",right:"Alignment"},verticalAlignMode:{main:"Vertical align",right:"Alignment"},textWrapMode:{main:"Text wrap",right:"Text wrap mode"},textRotateMode:{main:"Text rotate",right:"Text rotate mode"},freezeTopRow:"Freeze top row",sortAndFilter:"Sort and filter",findAndReplace:"Find and replace",sum:"SUM",autoSum:"Auto SUM",moreFunction:"More functions",conditionalFormat:"Conditional format",comment:"Comment",pivotTable:"Pivot Table",chart:"Chart",screenshot:"Screenshot",splitColumn:"Split text",insertImage:"Insert image",insertLink:"Insert link",dataValidation:"Data validation",protection:"Protect the sheet",clearText:"Clear color",noColorSelectedText:"No color is selected",toolMore:"More",toolLess:"Less",toolClose:"Close",toolMoreTip:"More features",moreOptions:"More options",cellFormat:"Cell format config",print:"Print",borderMethod:{top:"Upper frame line",bottom:"Lower frame line",left:"Left frame line",right:"Right frame line"},more:"More"},defaultFmt:{Automatic:{text:"Automatic",value:"General",example:""},Number:{text:"Number",value:"##0.00",example:"1000.12"},Percent:{text:"Percent",value:"#0.00%",example:"12.21%"},PlainText:{text:"Plain text",value:"@",example:""},Scientific:{text:"Scientific",value:"0.00E+00",example:"1.01E+5"},Accounting:{text:"Accounting",value:"¥(0.00)",example:"¥(1200.09)"},Thousand:{text:"Ten Thousand",value:"w",example:"1亿2000万2500"},Currency:{text:"Currency",value:"¥0.00",example:"¥1200.09"},Digit:{text:"万元2位小数",value:"w0.00",example:"2万2500.55"},Date:{text:"Date",value:"yyyy-MM-dd",example:"2017-11-29"},Time:{text:"Time",value:"hh:mm AM/PM",example:"3:00 PM"},Time24H:{text:"Time 24H",value:"hh:mm",example:"15:00"},DateTime:{text:"Date time",value:"yyyy-MM-dd hh:mm AM/PM",example:"2017-11-29 3:00 PM"},DateTime24H:{text:"Date time 24H",value:"yyyy-MM-dd hh:mm",example:"2017-11-29 15:00"},CustomFormats:{text:"Custom Formats",value:"fmtOtherSelf",example:""}},format:{moreCurrency:"More currency formats",moreDateTime:"More date and time formats",moreNumber:"More number formats",titleCurrency:"Currency formats",decimalPlaces:"Decimal places",titleDateTime:"Date and time formats",titleNumber:"Number formats"},print:{normalBtn:"Normal",layoutBtn:"Page Layout",pageBtn:"Page break preview",menuItemPrint:"Print (Ctrl+P)",menuItemAreas:"Print areas",menuItemRows:"Print title rows",menuItemColumns:"Print title columns"},align:{left:"left",center:"center",right:"right",top:"top",middle:"middle",bottom:"bottom"},dateFmtList:[{name:"1930-08-05",value:"yyyy-MM-dd"},{name:"1930/8/5",value:"yyyy/MM/dd"},{name:"08-05",value:"MM-dd"},{name:"8-5",value:"M-d"},{name:"13:30:30",value:"h:mm:ss"},{name:"13:30",value:"h:mm"},{name:"PM 01:30",value:"AM/PM hh:mm"},{name:"PM 1:30",value:"AM/PM h:mm"},{name:"PM 1:30:30",value:"AM/PM h:mm:ss"},{name:"08-05 PM 01:30",value:"MM-dd AM/PM hh:mm"}],numFmtList:[{name:"1235",value:"0"},{name:"1234.56",value:"0.00"},{name:"1,235",value:"#,##0"},{name:"1,234.56",value:"#,##0.00"},{name:"1,235",value:"#,##0_);(#,##0)"},{name:"1,235",value:"#,##0_);[Red](#,##0)"},{name:"1,234.56",value:"#,##0.00_);(#,##0.00)"},{name:"1,234.56",value:"#,##0.00_);[Red](#,##0.00)"},{name:"$1,235",value:"$#,##0_);($#,##0)"},{name:"$1,235",value:"$#,##0_);[Red]($#,##0)"},{name:"$1,234.56",value:"$#,##0.00_);($#,##0.00)"},{name:"$1,234.56",value:"$#,##0.00_);[Red]($#,##0.00)"},{name:"1234.56",value:"@"},{name:"123456%",value:"0%"},{name:"123456.00%",value:"0.00%"},{name:"1.23E+03",value:"0.00E+00"},{name:"1.2E+3",value:"##0.0E+0"},{name:"1234 5/9",value:"# ?/?"},{name:"1234 14/25",value:"# ??/??"},{name:"$ 1,235",value:'_($* #,##0_);_(...($* "-"_);_(@_)'},{name:"1,235",value:'_(* #,##0_);_(*..._(* "-"_);_(@_)'},{name:"$ 1,234.56",value:'_($* #,##0.00_);_(...($* "-"_);_(@_)'},{name:"1,234.56",value:'_(* #,##0.00_);...* "-"??_);_(@_)'}],button:{confirm:"OK",cancel:"Cancel",close:"Close",update:"Update",delete:"Delete",insert:"Insert",prevPage:"Previous",nextPage:"Next",total:"total:"},punctuation:{tab:"Tab",semicolon:"semicolond",comma:"comma",space:"space"},colorPicker:{collapse:"Collapse",customColor:"CUSTOM",change:"Change",confirmColor:"OK",cancelColor:"Cancel"},borderLine:{borderTop:"borderTop",borderBottom:"borderBottom",borderLeft:"borderLeft",borderRight:"borderRight",borderNone:"borderNone",borderAll:"borderAll",borderOutside:"borderOutside",borderInside:"borderInside",borderHorizontal:"borderHorizontal",borderVertical:"borderVertical",borderColor:"borderColor",borderSize:"borderSize",borderType:"borderType"},merge:{all:"Merge all",vertical:"Vertical merge",horizontal:"Horizontal merge",cancel:"Cancel merge",overlappingError:"Cannot merge overlapping areas",partiallyError:"Cannot perform this operation on partially merged cells",confirm:{title:"Continue merging would only keep the upper-left cell value, discard other values. Are you sure to continue?",cancel:"Cancel merging",confirm:"Continue merging",waring:"Waring",dismantleMergeCellWaring:"This will cause some merged cells to be split. Do you want to continue?"}},textWrap:{overflow:"Overflow",wrap:"Wrap",clip:"Clip"},textRotate:{none:"None",angleUp:"Tilt Up",angleDown:"Tilt Down",vertical:"Stack Vertically",rotationUp:"Rotate Up",rotationDown:"Rotate Down"},sheetConfig:{delete:"Delete",copy:"Copy",rename:"Rename",changeColor:"Change color",hide:"Hide",unhide:"Unhide",moveLeft:"Move left",moveRight:"Move right",resetColor:"Reset color",cancelText:"Cancel",chooseText:"Confirm color",tipNameRepeat:"The name of the tab page cannot be repeated! Please revise",noMoreSheet:"The workbook contains at least one visual worksheet. To delete the selected worksheet, please insert a new worksheet or show a hidden worksheet.",confirmDelete:"Are you sure to delete",redoDelete:"Can be undo by Ctrl+Z",noHide:"Can't hide, at least keep one sheet tag",chartEditNoOpt:"This operation is not allowed in chart editing mode!",sheetNameErrorTitle:"There was a problem",sheetNameSpecCharError:`The name cannot contain:[ ] : ? * / ' "`,sheetNameCannotIsEmptyError:"The sheet name cannot be empty.",sheetNameAlreadyExistsError:"The sheet name already exists. Please enter another name.",deleteSheet:"Delete worksheet",deleteSheetContent:"Confirm to delete this worksheet. It will not be retrieved after deletion. Are you sure you want to delete it?"},rightClick:{copy:"Copy",copyAs:"Copy as",cut:"Cut",paste:"Paste",pasteSpecial:"Paste Special",pasteValue:"Paste Value",pasteFormat:"Paste Format",pasteColWidth:"Paste Column Width",pasteBesidesBorder:"Paste Besides Border Styles",insert:"Insert",insertRow:"Insert Row",insertRowBefore:"Insert Row Before",insertColumn:"Insert Column",insertColumnBefore:"Insert Column Before",delete:"Delete",deleteCell:"Delete Cell",insertCell:"Insert Cell",deleteSelected:"Delete Selected ",hide:"Hide",hideSelected:"Hide Selected ",showHide:"Show Hidden",toTopAdd:"Towards Top Add",toBottomAdd:"Towards Bottom Add",toLeftAdd:"Towards Left Add",toRightAdd:"Towards Right Add",deleteSelectedRow:"Delete Selected row",deleteSelectedColumn:"Delete Selected column",hideSelectedRow:"Hide Selected Row",showHideRow:"Show Selected Row",rowHeight:"Row Height",hideSelectedColumn:"Hide Selected Column",showHideColumn:"Show Hide Column",columnWidth:"Column Width",to:"Towards",left:"Left",right:"Right",top:"Top",bottom:"Bottom",moveLeft:"Move Left",moveUp:"Move up",moveRight:"Move Right",moveDown:"Move Down",add:"Add",row:"Row",column:"Column",width:"Width",height:"Height",number:"Number",confirm:"Confirm",orderAZ:"A-Z order",orderZA:"Z-A order",clearSelection:"Clear",clearContent:"Clear Contents",clearFormat:"Clear Formats",clearAll:"Clear All",matrix:"Matrix operation",sortSelection:"Sort",filterSelection:"Filter",chartGeneration:"Create Chart",firstLineTitle:"First Line Title",untitled:"Untitled",array1:"One-dimensional array",array2:"Two-dimensional array",array3:"Multidimensional Arrays",diagonal:"Diagonal",antiDiagonal:"Anti-diagonal",diagonalOffset:"Diagonal offset",offset:"Offset",boolean:"Boolean",flip:"Flip",upAndDown:"Up and down",leftAndRight:"Left and right",clockwise:"Clockwise",counterclockwise:"Counterclockwise",transpose:"Transpose",matrixCalculation:"Matrix Calculation",plus:"Plus",minus:"Minus",multiply:"Multiply",divided:"Divided",power:"Power",root:"Root",log:"Log",delete0:"Delete 0 values at both ends",removeDuplicate:"Remove duplicate values",byRow:"By row",byCol:"By column",generateNewMatrix:"Generate new matrix",fitContent:"Fit for data",freeze:"Freeze",freezeCol:"Freeze to this column",freezeRow:"Freeze to this row",cancelFreeze:"Cancel freeze",zenEditor:"Full Screen Editor",deleteAllRowsAlert:"You can't delete all the rows on the sheet",deleteAllColumnsAlert:"You can't delete all the columns on the sheet",hideAllRowsAlert:"You can't hide all the rows on the sheet",hideAllColumnsAlert:"You can't hide all the columns on the sheet"},info:{tooltip:"Tooltip",notChangeMerge:"You cannot make partial changes to the merged cells",detailUpdate:"New opened",detailSave:"Local cache restored",row:"",column:"",loading:"Loading...",copy:"Copy",return:"Exit",rename:"Rename",tips:"Rename",noName:"Untitled spreadsheet",wait:"waiting for update",add:"Add",addLast:"more rows at bottom",backTop:"Back to the top",pageInfo:"Total ${total},${totalPage} page,current ${currentPage}",nextPage:"Next",tipInputNumber:"Please enter the number",tipInputNumberLimit:"The increase range is limited to 1-100",tipRowHeightLimit:"Row height must be between 0 ~ 545",tipColumnWidthLimit:"The column width must be between 0 ~ 2038",pageInfoFull:"Total ${total},${totalPage} page,All data displayed",problem:"There was a problem"},clipboard:{paste:{exceedMaxCells:"The number of cells pasted exceeds the maximum number of cells"}},statusbar:{sum:"Sum",average:"Average",min:"Min",max:"Max",count:"Numerical Count",countA:"Count",clickToCopy:"Click to Copy",copied:"Copied"},autoFill:{copy:"Copy Cell",series:"Fill Series",formatOnly:"Format Only",noFormat:"No Format"},rangeSelector:{placeholder:"Select range or input value",tooltip:"Select range"},shortcut:{sheet:{"zoom-in":"Zoom in","zoom-out":"Zoom out","reset-zoom":"Reset zoom level","select-below-cell":"Select the cell below","select-up-cell":"Select the cell above","select-left-cell":"Select the left cell","select-right-cell":"Select the right cell","select-next-cell":"Select the next cell","select-previous-cell":"Select the previous cell","select-up-value-cell":"Select the cell above that has value","select-below-value-cell":"Select the cell below that has value","select-left-value-cell":"Select the cell left that has value","select-right-value-cell":"Select the cell right that has value","expand-selection-down":"Expand selection down","expand-selection-up":"Expand selection up","expand-selection-left":"Expand selection left","expand-selection-right":"Expand selection right","expand-selection-to-left-gap":"Expand selection to the left gap","expand-selection-to-below-gap":"Expand selection to the below gap","expand-selection-to-right-gap":"Expand selection to the right gap","expand-selection-to-up-gap":"Expand selection to the up gap","select-all":"Select all","toggle-editing":"Toggle editing","delete-and-start-editing":"Clear and start editing","abort-editing":"Abort editing","break-line":"Break line","set-bold":"Toggle bold","set-italic":"Toggle italic","set-underline":"Toggle underline","set-strike-through":"Toggle strike through"}},"sheet-view":"Sheet View","sheet-edit":"Sheet Edit"},xr={spreadsheetLabel:"插件",spreadsheetRightLabel:"更多 Sheets",toolbar:{undo:"撤销",redo:"重做",formatPainter:"格式刷",currencyFormat:"货币格式",percentageFormat:"百分比格式",numberDecrease:"减少小数位数",numberIncrease:"增加小数位数",moreFormats:"更多格式",font:"字体",fontSize:"字号",bold:"粗体",italic:"斜体",strikethrough:"删除线",subscript:"下标",superscript:"上标",underline:"下划线",textColor:{main:"文本颜色",right:"颜色选择"},resetColor:"重置颜色",customColor:"自定义",alternatingColors:"交替颜色",confirmColor:"确定颜色",cancelColor:"取消",collapse:"收起",fillColor:{main:"单元格颜色",right:"颜色选择"},border:{main:"边框",right:"边框类型"},mergeCell:{main:"合并单元格",right:"选择合并类型"},horizontalAlignMode:{main:"水平对齐",right:"对齐方式"},verticalAlignMode:{main:"垂直对齐",right:"对齐方式"},textWrapMode:{main:"文本换行",right:"换行方式"},textRotateMode:{main:"文本旋转",right:"旋转方式"},freezeTopRow:"冻结首行",sortAndFilter:"排序和筛选",findAndReplace:"查找替换",sum:"求和",autoSum:"自动求和",moreFunction:"更多函数",conditionalalFormat:"条件格式",comment:"批注",pivotTable:"数据透视表",chart:"图表",screenshot:"截图",splitColumn:"分列",insertImage:"插入图片",insertLink:"插入链接",dataValidation:"数据验证",protection:"保护工作表内容",clearText:"清除颜色选择",noColorSelectedText:"没有颜色被选择",toolMore:"更多",toolLess:"少于",toolClose:"收起",toolMoreTip:"更多功能",moreOptions:"更多选项",cellFormat:"设置单元格格式",print:"打印",borderMethod:{top:"上框线",bottom:"下框线",left:"左框线",right:"右框线"},more:"更多"},defaultFmt:{Automatic:{text:"自动",value:"General",example:""},Number:{text:"数字",value:"##0.00",example:"1000.12"},Percent:{text:"百分比",value:"#0.00%",example:"12.21%"},PlainText:{text:"纯文本",value:"@",example:""},Scientific:{text:"科学计数",value:"0.00E+00",example:"1.01E+5"},Accounting:{text:"会计",value:"¥(0.00)",example:"¥(1200.09)"},Thousand:{text:"万元",value:"w",example:"1亿2000万2500"},Currency:{text:"货币",value:"¥0.00",example:"¥1200.09"},Digit:{text:"万元2位小数",value:"w0.00",example:"2万2500.55"},Date:{text:"日期",value:"yyyy-MM-dd",example:"2017-11-29"},Time:{text:"时间",value:"hh:mm AM/PM",example:"3:00 PM"},Time24H:{text:"时间24H",value:"hh:mm",example:"15:00"},DateTime:{text:"日期时间",value:"yyyy-MM-dd hh:mm AM/PM",example:"2017-11-29 3:00 PM"},DateTime24H:{text:"日期时间24H",value:"yyyy-MM-dd hh:mm",example:"2017-11-29 15:00"},CustomFormats:{text:"自定义格式",value:"fmtOtherSelf",example:""}},format:{moreCurrency:"更多货币格式",moreDateTime:"更多日期与时间格式",moreNumber:"更多数字格式",titleCurrency:"货币格式",decimalPlaces:"小数位数",titleDateTime:"日期与时间格式",titleNumber:"数字格式"},print:{normalBtn:"常规视图",layoutBtn:"页面布局",pageBtn:"分页预览",menuItemPrint:"打印(Ctrl+P)",menuItemAreas:"打印区域",menuItemRows:"打印标题行",menuItemColumns:"打印标题列"},align:{left:"左对齐",center:"中间对齐",right:"右对齐",top:"顶部对齐",middle:"居中对齐",bottom:"底部对齐"},button:{confirm:"确定",cancel:"取消",close:"关闭",update:"Update",delete:"Delete",insert:"新建",prevPage:"上一页",nextPage:"下一页",total:"总共:"},punctuation:{tab:"Tab 键",semicolon:"分号",comma:"逗号",space:"空格"},colorPicker:{collapse:"收起",customColor:"自定义",change:"切换",confirmColor:"确定",cancelColor:"取消"},borderLine:{borderTop:"上框线",borderBottom:"下框线",borderLeft:"左框线",borderRight:"右框线",borderNone:"无",borderAll:"所有",borderOutside:"外侧",borderInside:"内侧",borderHorizontal:"内侧横线",borderVertical:"内侧竖线",borderColor:"边框颜色",borderSize:"边框粗细",borderType:"边框线类型"},merge:{all:"全部合并",vertical:"垂直合并",horizontal:"水平合并",cancel:"取消合并",overlappingError:"不能合并重叠区域",partiallyError:"无法对部分合并单元格执行此操作",confirm:{title:"合并单元格仅保存左上角单元格的值,是否继续?",cancel:"取消合并",confirm:"继续合并",waring:"警告",dismantleMergeCellWaring:"此操作会导致一些合并单元格被拆散,是否继续?"}},textWrap:{overflow:"溢出",wrap:"自动换行",clip:"截断"},textRotate:{none:"无旋转",angleUp:"向上倾斜",angleDown:"向下倾斜",vertical:"竖排文字",rotationUp:"向上90°",rotationDown:"向下90°"},sheetConfig:{delete:"删除",copy:"复制",rename:"重命名",changeColor:"更改颜色",hide:"隐藏",unhide:"取消隐藏",moveLeft:"向左移",moveRight:"向右移",resetColor:"重置颜色",cancelText:"取消",chooseText:"确定颜色",tipNameRepeat:"标签页的名称不能重复!请重新修改",noMoreSheet:"工作薄内至少含有一张可视工作表。若需删除选定的工作表,请先插入一张新工作表或显示一张隐藏的工作表。",confirmDelete:"是否删除",redoDelete:"可以通过Ctrl+Z撤销删除",noHide:"不能隐藏, 至少保留一个sheet标签",chartEditNoOpt:"图表编辑模式下不允许该操作!",sheetNameErrorTitle:"错误",sheetNameSpecCharError:`名称不能超过31个字符,首尾不能是' 且名称不能包含:\r
18
+ [ ] : \\ ? * /`,sheetNameCannotIsEmptyError:"名称不能为空。",sheetNameAlreadyExistsError:"工作表已存在,请输入其它名称。",deleteSheet:"删除工作表",deleteSheetContent:"确认删除此工作表,删除后将不可找回,确定要删除吗?"},rightClick:{copy:"复制",copyAs:"复制为",cut:"剪切",paste:"粘贴",pasteSpecial:"选择性粘贴",pasteValue:"仅粘贴值",pasteFormat:"仅粘贴格式",pasteColWidth:"仅粘贴列宽",pasteBesidesBorder:"仅粘贴边框以外内容",insert:"插入",delete:"删除",insertRow:"插入行",insertRowBefore:"在上方插入行",insertColumn:"插入列",insertColumnBefore:"在左侧插入列",deleteCell:"删除单元格",insertCell:"插入单元格",deleteSelected:"删除选中",hide:"隐藏",hideSelected:"隐藏选中",showHide:"显示隐藏",toTopAdd:"向上增加",toBottomAdd:"向下增加",toLeftAdd:"向左增加",toRightAdd:"向右增加",deleteSelectedRow:"删除选中行",deleteSelectedColumn:"删除选中列",hideSelectedRow:"隐藏选中行",showHideRow:"显示隐藏行",rowHeight:"行高",hideSelectedColumn:"隐藏选中列",showHideColumn:"显示隐藏列",columnWidth:"列宽",to:"向",left:"左",right:"右",top:"上",bottom:"下",moveLeft:"左移",moveUp:"上移",moveRight:"右移",moveDown:"下移",add:"增加",row:"行",column:"列",width:"宽",height:"高",number:"数字",confirm:"确认",orderAZ:"A-Z顺序排列",orderZA:"Z-A降序排列",clearSelection:"清除",clearContent:"清除内容",clearFormat:"清除格式",clearAll:"清除全部",matrix:"矩阵操作选区",sortSelection:"排序选区",filterSelection:"筛选选区",chartGeneration:"图表生成",firstLineTitle:"首行为标题",untitled:"无标题",array1:"一维数组",array2:"二维数组",array3:"多维数组",diagonal:"对角线",antiDiagonal:"反对角线",diagonalOffset:"对角偏移",offset:"偏移量",boolean:"布尔值",flip:"翻转",upAndDown:"上下",leftAndRight:"左右",clockwise:"顺时针",counterclockwise:"逆时针",transpose:"转置",matrixCalculation:"矩阵计算",plus:"加",minus:"减",multiply:"乘",divided:"除",power:"次方",root:"次方根",log:"log",delete0:"删除两端0值",removeDuplicate:"删除重复值",byRow:"按行",byCol:"按列",generateNewMatrix:"生成新矩阵",fitContent:"适合数据",freeze:"冻结",freezeCol:"冻结列",freezeRow:"冻结行",cancelFreeze:"取消冻结",zenEditor:"禅模式编辑",deleteAllRowsAlert:"您无法删除工作表上的所有行",deleteAllColumnsAlert:"您无法删除工作表上的所有列",hideAllRowsAlert:"您无法隐藏工作表上的所有行",hideAllColumnsAlert:"您无法隐藏工作表上的所有列"},info:{tooltip:"提示",notChangeMerge:"不能对合并单元格做部分更改",detailUpdate:"新打开",detailSave:"已恢复本地缓存",row:"行",column:"列",loading:"渲染中···",copy:"副本",return:"返回",rename:"重命名",tips:"重命名",noName:"无标题的电子表格",wait:"待更新",add:"添加",addLast:"在底部添加",backTop:"回到顶部",pageInfo:"共${total}条,${totalPage}页,当前已显示${currentPage}页",nextPage:"下一页",tipInputNumber:"请输入数字",tipInputNumberLimit:"增加范围限制在1-100",tipRowHeightLimit:"行高必须在0 ~ 545之间",tipColumnWidthLimit:"列宽必须在0 ~ 2038之间",pageInfoFull:"共${total}条,${totalPage}页,已显示全部数据",problem:"出现了一个问题"},clipboard:{paste:{exceedMaxCells:"粘贴区域超出最大单元格数"}},statusbar:{sum:"求和",average:"平均值",min:"最小值",max:"最大值",count:"数值计数",countA:"计数",clickToCopy:"点击复制数值",copied:"已复制"},autoFill:{copy:"复制单元格",series:"填充序列",formatOnly:"仅填充格式",noFormat:"不带格式填充"},rangeSelector:{placeholder:"选择范围或输入值",tooltip:"选择范围"},shortcut:{sheet:{"zoom-in":"放大","zoom-out":"缩小","reset-zoom":"恢复缩放","select-below-cell":"选择下方单元格","select-up-cell":"选择上方单元格","select-left-cell":"选择左侧单元格","select-right-cell":"选择右侧单元格","select-next-cell":"选择后一个单元格","select-previous-cell":"选择前一个单元格","select-up-value-cell":"选择上方有值的单元格","select-below-value-cell":"选择下方有值的单元格","select-left-value-cell":"选择左侧有值的单元格","select-right-value-cell":"选择右侧有值的单元格","expand-selection-down":"向下扩展选区","expand-selection-up":"向上扩展选区","expand-selection-left":"向左扩展选区","expand-selection-right":"向右扩展选区","expand-selection-to-left-gap":"向左扩展选区到下一个边界","expand-selection-to-below-gap":"向下扩展选区到下一个边界","expand-selection-to-right-gap":"向右扩展选区到下一个边界","expand-selection-to-up-gap":"向上扩展选区到下一个边界","select-all":"全选","toggle-editing":"开始 / 结束编辑","delete-and-start-editing":"清空并开始编辑","abort-editing":"放弃编辑","break-line":"换行","set-bold":"切换粗体","set-italic":"切换斜体","set-underline":"切换下划线","set-strike-through":"切换删除线"}},"sheet-view":"浏览表格","sheet-edit":"编辑表格"},ic=(i,e,t=!1)=>{const n=h=>h.endRow-h.startRow+1,o=h=>h.endColumn-h.startColumn+1,r=n(e)%n(i),s=o(e)%o(i),a={startRow:0,endRow:n(i)-1,startColumn:0,endColumn:o(i)-1},c=Math.floor(n(e)/n(i)),d=Math.floor(o(e)/o(i)),u=[];if(!r&&!s)for(let h=1;h<=c;h++)for(let m=1;m<=d;m++){const g=n(i)*(h-1),S=o(i)*(m-1),f={startRow:g+e.startRow,endRow:g+e.startRow,startColumn:S+e.startColumn,endColumn:S+e.startColumn};u.push({repeatRelativeRange:a,startRange:f})}else if(!r&&s&&!t)for(let h=1;h<=c;h++){const m=n(i)*(h-1),g=0,S={startRow:m+e.startRow,endRow:m+e.startRow,startColumn:g+e.startColumn,endColumn:g+e.startColumn};u.push({repeatRelativeRange:a,startRange:S})}else if(r&&!s&&!t)for(let h=1;h<=d;h++){const g=o(i)*(h-1),S={startRow:0+e.startRow,endRow:0+e.startRow,startColumn:g+e.startColumn,endColumn:g+e.startColumn};u.push({repeatRelativeRange:a,startRange:S})}else{const h={startRow:e.startRow,endRow:e.startRow,startColumn:e.startColumn,endColumn:e.startColumn};u.push({startRange:h,repeatRelativeRange:a})}return u};class Ar{constructor(){v(this,"_state",null);v(this,"_rect",null);v(this,"_focus",!1);v(this,"_state$",new H.BehaviorSubject(null));v(this,"state$",this._state$.asObservable());v(this,"_rect$",new H.BehaviorSubject(null));v(this,"rect$",this._rect$.asObservable());v(this,"_focus$",new H.BehaviorSubject(this._focus));v(this,"focus$",this._focus$.asObservable())}dispose(){this._state$.complete(),this._state=null,this._rect$.complete(),this._rect=null}setState(e){this._state=e,this._refresh(e)}getRect(){return this._rect}setRect(e){this._rect=e,this._rect$.next(e)}getState(){return this._state}setFocus(e=!1){this._focus=e,this._focus$.next(e)}_refresh(e){this._state$.next(e)}}const Kt=D.createIdentifier("univer.sheet-cell-editor-manager.service");class oc{constructor(){v(this,"_position",null);v(this,"_position$",new H.BehaviorSubject(null));v(this,"position$",this._position$.asObservable());v(this,"_focus",!1);v(this,"_focus$",new H.BehaviorSubject(this._focus));v(this,"focus$",this._focus$.asObservable());v(this,"_fxBtnClick$",new H.BehaviorSubject(!1));v(this,"fxBtnClick$",this._fxBtnClick$.asObservable());v(this,"_foldBtnStatus$",new H.BehaviorSubject(!1));v(this,"foldBtnStatus$",this._foldBtnStatus$.asObservable())}dispose(){this._position$.complete(),this._focus$.complete(),this._position=null,this._focus=!1}setPosition(e){this._position=e,this._refresh(e)}getPosition(){return this._position}setFocus(e=!1){this._focus=e,this._focus$.next(e)}handleFxBtnClick(e){this._fxBtnClick$.next(e)}handleFoldBtnClick(e){this._foldBtnStatus$.next(e)}_refresh(e){this._position$.next(e)}}const Yn=D.createIdentifier("univer.sheet-formula-editor-manager.service");var rc=Object.defineProperty,sc=Object.getOwnPropertyDescriptor,ac=(i,e,t,n)=>{for(var o=n>1?void 0:n?sc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&rc(e,t,o),o},So=(i,e)=>(t,n)=>e(t,n,i);let cn=class extends l.Disposable{constructor(e,t){super();v(this,"_previousSheetIndex",-1);this._commandService=e,this._univerInstanceService=t,this.disposeWithMe(this._commandService.beforeCommandExecuted((n,o)=>{if(n.id===_.RemoveSheetMutation.id)return this._beforeAdjustActiveSheetOnRemoveSheet(n)})),this.disposeWithMe(this._commandService.onCommandExecuted((n,o)=>{if(n.id===_.RemoveSheetMutation.id)return this._adjustActiveSheetOnRemoveSheet(n);if(n.id===_.SetWorksheetHideMutation.id&&n.params.hidden)return this._adjustActiveSheetOnHideSheet(n);if(!(o!=null&&o.fromCollab)){if(n.id===_.InsertSheetMutation.id)return this._adjustActiveSheetOnInsertSheet(n);if(n.id===_.SetWorksheetHideMutation.id&&!n.params.hidden)return this._adjustActiveSheetOnShowSheet(n)}}))}_adjustActiveSheetOnHideSheet(e){const{unitId:t,subUnitId:n}=e.params,o=this._univerInstanceService.getUniverSheetInstance(t);if(!o||(o==null?void 0:o.getRawActiveSheet())!==n)return;const s=o.getActiveSheetIndex(),a=_o(o,s);this._switchToNextSheet(t,a)}_beforeAdjustActiveSheetOnRemoveSheet(e){const{unitId:t,subUnitId:n}=e.params,o=this._univerInstanceService.getUniverSheetInstance(t);if(!o)return;const r=o.getSheetBySheetId(n);r&&(this._previousSheetIndex=o.getSheetIndex(r))}_adjustActiveSheetOnRemoveSheet(e){if(this._previousSheetIndex===-1)return;const{unitId:t}=e.params,n=this._univerInstanceService.getUniverSheetInstance(t);if(!n||n.getRawActiveSheet())return;const r=this._previousSheetIndex,s=r>=1?r-1:0,a=_o(n,s);this._switchToNextSheet(t,a)}_adjustActiveSheetOnInsertSheet(e){const{unitId:t,sheet:n}=e.params;this._switchToNextSheet(t,n.id)}_adjustActiveSheetOnShowSheet(e){const{unitId:t,subUnitId:n}=e.params;this._switchToNextSheet(t,n)}_switchToNextSheet(e,t){this._commandService.executeCommand(_.SetWorksheetActiveOperation.id,{unitId:e,subUnitId:t})}};cn=ac([l.OnLifecycle(l.LifecycleStages.Ready,cn),So(0,l.ICommandService),So(1,l.IUniverInstanceService)],cn);function _o(i,e){const t=i.getSheetSize();for(let n=e;n>-1;n--){const o=i.getSheetByIndex(n);if(!o.getConfig().hidden)return o.getSheetId()}for(let n=e;n<t;n++){const o=i.getSheetByIndex(n);if(!o.getConfig().hidden)return o.getSheetId()}throw new Error("[ActiveWorksheetController]: could not find the next unhidden sheet! Collaboration error perhaps.")}var lc=Object.defineProperty,cc=Object.getOwnPropertyDescriptor,dc=(i,e,t,n)=>{for(var o=n>1?void 0:n?cc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&lc(e,t,o),o},Dt=(i,e)=>(t,n)=>e(t,n,i);let dn=class{constructor(i,e,t,n,o){this._injector=i,this._sheetInterceptorService=e,this._selectionManagerService=t,this._univerInstanceService=n,this._sheetSkeletonManagerService=o,this._initialize()}_getUndoRedoParamsOfAutoHeight(i){const{_univerInstanceService:e,_sheetSkeletonManagerService:t,_injector:n}=this,{skeleton:o}=t.getCurrent(),r=o.calculateAutoHeightInRange(i),s=e.getCurrentUniverSheetInstance(),a=s.getUnitId(),d={subUnitId:s.getActiveSheet().getSheetId(),unitId:a,rowsAutoHeightInfo:r},u=_.SetWorksheetRowAutoHeightMutationFactory(n,d);return{undos:[{id:_.SetWorksheetRowAutoHeightMutation.id,params:u}],redos:[{id:_.SetWorksheetRowAutoHeightMutation.id,params:d}]}}_initialize(){const{_sheetInterceptorService:i,_selectionManagerService:e}=this;i.interceptCommand({getMutations:t=>t.id!==_.SetRangeValuesCommand.id?{redos:[],undos:[]}:this._getUndoRedoParamsOfAutoHeight(t.params.range)}),i.interceptCommand({getMutations:t=>t.id!==_.SetWorksheetRowIsAutoHeightCommand.id?{redos:[],undos:[]}:this._getUndoRedoParamsOfAutoHeight(t.params.ranges)}),i.interceptCommand({getMutations:t=>{var r;if(t.id!==_.SetStyleCommand.id)return{redos:[],undos:[]};if(!["ff","fs","tr","tb"].includes((r=t.params)==null?void 0:r.style.type))return{redos:[],undos:[]};const o=e.getSelectionRanges();return o!=null&&o.length?this._getUndoRedoParamsOfAutoHeight(o):{redos:[],undos:[]}}})}};dn=dc([l.OnLifecycle(l.LifecycleStages.Ready,dn),Dt(0,D.Inject(D.Injector)),Dt(1,D.Inject(_.SheetInterceptorService)),Dt(2,D.Inject(_.SelectionManagerService)),Dt(3,D.Inject(l.IUniverInstanceService)),Dt(4,D.Inject(exports.SheetSkeletonManagerService))],dn);var uc=Object.defineProperty,hc=Object.getOwnPropertyDescriptor,mc=(i,e,t,n)=>{for(var o=n>1?void 0:n?hc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&uc(e,t,o),o},Ye=(i,e)=>(t,n)=>e(t,n,i);let un=class extends l.Disposable{constructor(i,e,t,n,o,r,s,a){super(),this._currentUniverSheet=i,this._commandService=e,this._configService=t,this._sheetClipboardService=n,this._messageService=o,this._sheetSkeletonManagerService=r,this._injector=s,this._localService=a,this._init()}_init(){[zo,na,wt].forEach(e=>this.disposeWithMe(this._commandService.registerMultipleCommand(e))),[Xo,Yo,Zo,Go].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e))),this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._initCopyingHooks())),this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._initPastingHook()));const i=this._initSpecialPasteHooks().map(e=>this._sheetClipboardService.addClipboardHook(e));this.disposeWithMe({dispose:()=>i.forEach(e=>e.dispose())})}_initCopyingHooks(){const i=this;let e=null;return{id:pe.DEFAULT_COPY,isDefaultHook:!0,onBeforeCopy(t,n){e=i._getWorksheet(t,n)},onCopyCellContent(t,n){const o=e.getCell(t,n);return`${(o==null?void 0:o.v)||""}`},onCopyCellStyle:(t,n,o,r)=>{const s={};(o||r)&&(s.rowspan=`${o||1}`,s.colspan=`${r||1}`);const c=e.getRange(t,n).getTextStyle();let d="";return c&&(d=l.handleStyleToString(c)),d&&(s.style=d),s},onCopyColumn(t){return{width:`${e.getColumnWidth(t)}`}},onCopyRow(t){return{style:`height: ${e.getRowHeight(t)}px;`}},onAfterCopy(){e=null}}}_initPastingHook(){const i=this;let e=null,t=null,n=null;return{id:pe.DEFAULT_PASTE,isDefaultHook:!0,onBeforePaste({unitId:o,subUnitId:r,range:s}){n=i._getWorksheet(o,r),e=o,t=r;const a=i._configService.getConfig(_.MAX_CELL_PER_SHEET_KEY),{endRow:c,endColumn:d}=s;return a&&c*d>a?(i._messageService.show({type:Se.MessageType.Error,content:i._localService.t("clipboard.paste.exceedMaxCells")}),!1):!0},onPasteRows(o,r){const{range:s}=o,a=[],c=n.getMaxRows(),d=s.endRow-c,u=r.length-d;if(d>0){const g={};r.slice(u).forEach((f,C)=>{const R=f==null?void 0:f.style;if(!R)return;const M=R.split(";");let T=l.DEFAULT_WORKSHEET_ROW_HEIGHT;M.find(w=>{w=w.toLowerCase();const E=I.textTrim(w.substr(0,w.indexOf(":"))),y=I.textTrim(w.substr(w.indexOf(":")+1));return E==="height"?(T=Number.parseFloat(y),!0):!1}),g[C]={h:T,hd:l.BooleanNumber.FALSE}});const S={unitId:e,subUnitId:t,range:{...s,startRow:c},rowInfo:g};a.push({id:_.InsertRowMutation.id,params:S})}const h={};r.slice(0,u).forEach((g,S)=>{const f=g.style;if(!f)return;const C=f.split(";");let R=l.DEFAULT_WORKSHEET_ROW_HEIGHT;C.find(M=>{M=M.toLowerCase();const T=I.textTrim(M.substr(0,M.indexOf(":"))),w=I.textTrim(M.substr(M.indexOf(":")+1));return T==="height"?(R=Number.parseFloat(w),!0):!1}),h[S]=R});const m={unitId:e,subUnitId:t,ranges:[{...s,endRow:Math.min(s.endRow,c)}],rowHeight:h};return a.push({id:_.SetWorksheetRowHeightMutation.id,params:m}),{redos:a,undos:[]}},onPasteColumns(o,r,s){const{range:a}=o,c=[],d=n.getMaxColumns(),u=a.endColumn-d,h=r.length-u;if(u>0){const g={unitId:e,subUnitId:t,range:{...a,startColumn:d},colInfo:r.slice(h).map(S=>({w:S.width?+S.width:l.DEFAULT_WORKSHEET_COLUMN_WIDTH,hd:l.BooleanNumber.FALSE}))};c.push({id:_.InsertColMutation.id,params:g})}const m={unitId:e,subUnitId:t,ranges:[{...a,endRow:Math.min(a.endColumn,d)}],colWidth:r.slice(0,h).map(g=>g.width?+g.width:l.DEFAULT_WORKSHEET_COLUMN_WIDTH)};return c.push({id:_.SetWorksheetColWidthMutation.id,params:m}),{redos:c,undos:[]}},onPastePlainText(o,r,s){return i._onPastePlainText(o,r,s)},onPasteCells(o,r,s,a){return i._onPasteCells(o,r,s,a)},onAfterPaste(o){n=null}}}_generateDocumentDataModelSnapshot(i){var s;const e=this._sheetSkeletonManagerService.getCurrent();if(e==null)return null;const{skeleton:t}=e,n=(s=t.getBlankCellDocumentModel())==null?void 0:s.documentModel,r={...n==null?void 0:n.getSnapshot(),...i};return n==null||n.reset(r),n==null?void 0:n.getSnapshot()}_onPastePlainText(i,e,t){const{range:n,unitId:o,subUnitId:r}=i;let s;if(/\r|\n/.test(e)){const c=$o(e),d=this._generateDocumentDataModelSnapshot({body:c});s={[n.startRow]:{[n.startColumn]:{p:d}}}}else s={[n.startRow]:{[n.startColumn]:{v:e}}};const a={unitId:o,subUnitId:r,cellValue:s};return{redos:[{id:_.SetRangeValuesMutation.id,params:a}],undos:[{id:_.SetRangeValuesMutation.id,params:_.SetRangeValuesUndoMutationFactory(this._injector,a)}]}}_onPasteCells(i,e,t,n){const o={get:this._injector.get.bind(this._injector)};return xs(i,e,t,n,o)}_initSpecialPasteHooks(){const i={get:this._injector.get.bind(this._injector)},e=this,t={id:pe.SPECIAL_PASTE_VALUE,specialPasteInfo:{label:"specialPaste.value"},onPasteCells:(s,a,c,d)=>{const u=e._currentUniverSheet.getCurrentUniverSheetInstance();return u.getUnitId(),u.getActiveSheet().getSheetId(),Fo(a,c,i)}},n={id:pe.SPECIAL_PASTE_FORMAT,specialPasteInfo:{label:"specialPaste.format"},onPasteCells(s,a,c,d){const u=e._currentUniverSheet.getCurrentUniverSheetInstance();u.getUnitId(),u.getActiveSheet().getSheetId();const h=[],m=[],{undos:g,redos:S}=jo(a,c,i);h.push(...S),m.push(...g);const{undos:f,redos:C}=Si(a,c,i);h.push(...C),m.push(...f);const{undos:R,redos:M}=Wo(a,c,i);return h.push(...M),m.push(...R),{undos:m,redos:h}}},o={id:pe.SPECIAL_PASTE_COL_WIDTH,specialPasteInfo:{label:"specialPaste.colWidth"},onPasteCells(){return{undos:[],redos:[]}},onPasteColumns(s,a,c){const d=e._currentUniverSheet.getCurrentUniverSheetInstance(),u=d.getUnitId(),h=d.getActiveSheet().getSheetId(),m=[],g=e._getWorksheet(u,h),{range:S}=s,f=g.getMaxColumns(),C=S.endColumn-f,R=a.length-C,M={unitId:u,subUnitId:h,ranges:[{...S,endRow:Math.min(S.endColumn,f)}],colWidth:a.slice(0,R).map(T=>T.width?+T.width:l.DEFAULT_WORKSHEET_COLUMN_WIDTH)};return m.push({id:_.SetWorksheetColWidthMutation.id,params:M}),m.push({id:_.SetWorksheetColWidthMutation.id,params:M}),{redos:m,undos:[]}}},r={id:pe.SPECIAL_PASTE_BESIDES_BORDER,specialPasteInfo:{label:"specialPaste.besidesBorder"},onPasteCells(s,a,c,d){e._currentUniverSheet.getCurrentUniverSheetInstance();const u=[],h=[],{range:m,unitId:g,subUnitId:S}=a,{startColumn:f,startRow:C,endColumn:R,endRow:M}=m,T=new l.ObjectMatrix;c.forValue((O,A,k)=>{const N=k.s;typeof N=="object"&&T.setValue(O+C,A+f,{s:{...N,bd:void 0},v:k.v})});const w={unitId:g,subUnitId:S,cellValue:T.getData()};u.push({id:_.SetRangeValuesMutation.id,params:w});const E=_.SetRangeValuesUndoMutationFactory(i,w);h.push({id:_.SetRangeValuesMutation.id,params:E});const{undos:y,redos:x}=Si(a,c,i);return h.push(...y),u.push(...x),{redos:u,undos:h}}};return[t,n,o,r]}_getWorksheet(i,e){var n;const t=(n=this._currentUniverSheet.getUniverSheetInstance(i))==null?void 0:n.getSheetBySheetId(e);if(!t)throw new Error(`[SheetClipboardController]: cannot find a worksheet with unitId ${i} and subUnitId ${e}.`);return t}};un=mc([l.OnLifecycle(l.LifecycleStages.Ready,un),Ye(0,l.IUniverInstanceService),Ye(1,l.ICommandService),Ye(2,l.IConfigService),Ye(3,bt),Ye(4,I.IMessageService),Ye(5,D.Inject(exports.SheetSkeletonManagerService)),Ye(6,D.Inject(D.Injector)),Ye(7,D.Inject(l.LocaleService))],un);var gc=Object.defineProperty,Sc=Object.getOwnPropertyDescriptor,_c=(i,e,t,n)=>{for(var o=n>1?void 0:n?Sc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&gc(e,t,o),o},Nt=(i,e)=>(t,n)=>e(t,n,i);let hn=class extends l.Disposable{constructor(i,e,t,n,o){super(),this._currentUniverService=i,this._contextMenuService=e,this._renderManagerService=t,this._selectionManagerService=n,this._selectionRenderService=o,this._currentUniverService.currentSheet$.subscribe(r=>{if(r==null)throw new Error("workbook is null");this._addListeners()})}_addListeners(){const i=ve(this._currentUniverService,this._renderManagerService);if(!i)return;const e=i.spreadsheet.onPointerDownObserver,t=e.add(a=>{if(a.button===2){const c=this._selectionManagerService.getSelections(),d=c==null?void 0:c[0];if(!d)return;const u=d.range.rangeType,h=this._selectionRenderService.convertSelectionRangeToData(d).rangeWithCoord,m=()=>{if(!h)return!1;const S=a.offsetX,f=a.offsetY;switch(u){case l.RANGE_TYPE.ROW:return h.startY<=f&&h.endY>=f;case l.RANGE_TYPE.COLUMN:return h.startX<=S&&h.endX>=S;default:return h.startX<=S&&h.endX>=S&&h.startY<=f&&h.endY>=f}},g=S=>{this._contextMenuService.triggerContextMenu(a,S)};m()?u===l.RANGE_TYPE.COLUMN?g(de.COL_HEADER_CONTEXT_MENU):u===l.RANGE_TYPE.ROW?g(de.ROW_HEADER_CONTEXT_MENU):g(I.MenuPosition.CONTEXT_MENU):g(I.MenuPosition.CONTEXT_MENU)}});this.disposeWithMe(l.toDisposable(()=>e.remove(t)));const o=i.spreadsheetRowHeader.onPointerDownObserver.add(a=>{a.button===2&&this._contextMenuService.triggerContextMenu(a,de.ROW_HEADER_CONTEXT_MENU)});this.disposeWithMe(l.toDisposable(()=>e.remove(o)));const s=i.spreadsheetColumnHeader.onPointerDownObserver.add(a=>{a.button===2&&this._contextMenuService.triggerContextMenu(a,de.COL_HEADER_CONTEXT_MENU)});this.disposeWithMe(l.toDisposable(()=>e.remove(s)))}};hn=_c([l.OnLifecycle(l.LifecycleStages.Rendered,hn),Nt(0,l.IUniverInstanceService),Nt(1,I.IContextMenuService),Nt(2,b.IRenderManagerService),Nt(3,D.Inject(_.SelectionManagerService)),Nt(4,_e)],hn);var fc=Object.defineProperty,pc=Object.getOwnPropertyDescriptor,vc=(i,e,t,n)=>{for(var o=n>1?void 0:n?pc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&fc(e,t,o),o},oi=(i,e)=>(t,n)=>e(t,n,i);let mn=class extends l.RxDisposable{constructor(i,e,t){super(),this._currentUniverService=i,this._renderManagerService=e,this._undoRedoService=t,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialNormalInput(),this._listenEditorBlur()}_listenEditorBlur(){this._currentUniverService.currentDoc$.pipe(H.takeUntil(this.dispose$)).subscribe(i=>{if(i==null)return;i.getUnitId()!==l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._undoRedoService.clearUndoRedo(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})}_initialNormalInput(){const i={};this._currentUniverService.getCurrentUniverSheetInstance().getSheets().forEach(e=>{const t=e.getConfig();i[e.getSheetId()]={cellData:new l.ObjectMatrix(t.cellData),rowCount:t.rowCount,columnCount:t.columnCount}})}_commandExecutedListener(){}_getDocObject(){return J.getDocObject(this._currentUniverService,this._renderManagerService)}};mn=vc([l.OnLifecycle(l.LifecycleStages.Steady,mn),oi(0,l.IUniverInstanceService),oi(1,b.IRenderManagerService),oi(2,D.Inject(l.IUndoRedoService))],mn);const Dr=[I.KeyCode.ARROW_DOWN,I.KeyCode.ARROW_UP,I.KeyCode.ARROW_LEFT,I.KeyCode.ARROW_RIGHT],Cc=[I.KeyCode.ENTER,I.KeyCode.TAB,...Dr];function Ic(){const i=[];for(const e of Dr)i.push({id:$t.id,binding:e,preconditions:t=>Ln(t),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:e,isShift:!1}}),i.push({id:$t.id,binding:e|I.MetaKeys.SHIFT,preconditions:t=>Ln(t),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:e,isShift:!0}});return i}const Rc={id:He.id,binding:I.KeyCode.ENTER,description:"shortcut.sheet.toggle-editing",group:"4_sheet-edit",preconditions:i=>Ln(i),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ENTER}},Mc={id:He.id,binding:I.KeyCode.TAB,preconditions:i=>Ln(i),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:I.KeyCode.TAB}},bc={id:He.id,binding:I.KeyCode.ESC,description:"shortcut.sheet.abort-editing",group:"4_sheet-edit",preconditions:i=>Vo(i),staticParameters:{visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ESC}},wc={id:J.BreakLineCommand.id,description:"shortcut.sheet.break-line",group:"4_sheet-edit",preconditions:i=>Vo(i),binding:I.KeyCode.ENTER|I.MetaKeys.ALT},Tc={id:J.DeleteLeftCommand.id,preconditions:i=>ds(i)||Bo(i),binding:I.KeyCode.BACKSPACE},Ec={id:He.id,description:"shortcut.sheet.delete-and-start-editing",group:"4_sheet-edit",preconditions:i=>ne(i)&&!Bo(i),binding:I.KeyCode.BACKSPACE,staticParameters:{visible:!0,eventType:b.DeviceInputEventType.Keyboard,keycode:I.KeyCode.BACKSPACE}};var yc=Object.defineProperty,Oc=Object.getOwnPropertyDescriptor,xc=(i,e,t,n)=>{for(var o=n>1?void 0:n?Oc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&yc(e,t,o),o},De=(i,e)=>(t,n)=>e(t,n,i);function Ac(i){const{textRuns:e=[],paragraphs:t=[]}=i;return e.some(n=>n.ts&&!l.Tools.isEmptyObject(n.ts))||t.some(n=>n.bullet)||t.length>=2}let gn=class extends l.Disposable{constructor(e,t,n,o,r,s,a,c,d,u){super();v(this,"_onInputSubscription");v(this,"_cursorChangeObservers");v(this,"_editorVisiblePrevious",!1);v(this,"_isCursorChange",0);this._currentUniverService=e,this._renderManagerService=t,this._commandService=n,this._editorBridgeService=o,this._contextService=r,this._cellEditorManagerService=s,this._lexerTreeBuilder=a,this._undoRedoService=c,this._sheetInterceptorService=d,this._selectionManagerService=u,this._initialize(),this._commandExecutedListener()}dispose(){var n;(n=this._onInputSubscription)==null||n.unsubscribe();const e=this._getEditorObject();if(e==null)return;const{document:t}=e;t.onPointerDownObserver.remove(this._cursorChangeObservers)}_initialize(){this._initialExitInput(),this._cursorStateListener()}_initialExitInput(){this._onInputSubscription=this._editorBridgeService.visible$.subscribe(e=>{const{visible:t,keycode:n,eventType:o}=e;if(t===this._editorVisiblePrevious)return;if(this._editorVisiblePrevious=t,t===!0){this._isCursorChange=o===b.DeviceInputEventType.PointerDown?2:1;return}this._isCursorChange=0;const r=this._selectionManagerService.getSelections(),s=this._selectionManagerService.getCurrent();if(s==null)return;const{unitId:a,sheetId:c,pluginName:d}=s;if(this._exitInput(e),n===I.KeyCode.ESC){this._commandService.syncExecuteCommand(_.SetSelectionsOperation.id,{unitId:a,subUnitId:c,pluginName:d,selections:r});return}const u=this._editorBridgeService.getEditCellState();if(u==null)return;const{unitId:h,sheetId:m,row:g,column:S,documentLayoutObject:f}=u;if(this._editorBridgeService.getEditorDirty()===!1){this._moveCursor(n);return}const R=this._currentUniverService.getUniverSheetInstance(h),M=R==null?void 0:R.getSheetBySheetId(m);if(M==null)return;const T=Dc(M.getCellRaw(g,S)||{},f,this._lexerTreeBuilder);if(T==null){this._moveCursor(n);return}const w={subUnitId:m,unitId:h,workbook:R,worksheet:M,row:g,col:S},E=this._editorBridgeService.interceptor.fetchThroughInterceptors(this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT)(T,w);this._commandService.executeCommand(_.SetRangeValuesCommand.id,{subUnitId:m,unitId:h,range:{startRow:g,startColumn:S,endRow:g,endColumn:S},value:E}),this._moveCursor(n),a===h&&m!==c&&this._editorBridgeService.isForceKeepVisible()&&this._commandService.executeCommand(_.SetWorksheetActivateCommand.id,{subUnitId:m,unitId:h}),this._selectionManagerService.refreshSelection()})}_exitInput(e){this._contextService.setContextValue(l.FOCUSING_EDITOR_INPUT_FORMULA,!1),this._contextService.setContextValue(l.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(l.FOCUSING_EDITOR_BUT_HIDDEN,!1),this._contextService.setContextValue(l.FOCUSING_FORMULA_EDITOR,!1),this._cellEditorManagerService.setState({show:e.visible});const t=this._editorBridgeService.getCurrentEditorId();t!=null&&(this._undoRedoService.clearUndoRedo(t),this._undoRedoService.clearUndoRedo(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))}_moveCursor(e){if(e==null||!Cc.includes(e))return;let t=l.Direction.LEFT;switch(e){case I.KeyCode.ENTER:t=l.Direction.DOWN;break;case I.KeyCode.TAB:t=l.Direction.RIGHT;break;case I.KeyCode.ARROW_DOWN:t=l.Direction.DOWN;break;case I.KeyCode.ARROW_UP:t=l.Direction.UP;break;case I.KeyCode.ARROW_LEFT:t=l.Direction.LEFT;break;case I.KeyCode.ARROW_RIGHT:t=l.Direction.RIGHT;break}e===I.KeyCode.ENTER||e===I.KeyCode.TAB?this._commandService.executeCommand(at.id,{keycode:e,direction:t}):this._commandService.executeCommand(Te.id,{direction:t})}_cursorStateListener(){const e=this._getEditorObject();if(e==null)return;const{document:t}=e;this._cursorChangeObservers=t.onPointerDownObserver.add(()=>{this._isCursorChange===1&&(this._isCursorChange=2)})}_commandExecutedListener(){const e=[$t.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=t.params,{keycode:o,isShift:r}=n;if(o!=null&&this._isCursorChange===2){this._moveInEditor(o,r);return}this._editorBridgeService.changeVisible(n)}}))}_moveInEditor(e,t){let n=l.Direction.LEFT;e===I.KeyCode.ARROW_DOWN?n=l.Direction.DOWN:e===I.KeyCode.ARROW_UP?n=l.Direction.UP:e===I.KeyCode.ARROW_RIGHT&&(n=l.Direction.RIGHT),t?this._commandService.executeCommand(J.MoveSelectionOperation.id,{direction:n}):this._commandService.executeCommand(J.MoveCursorOperation.id,{direction:n})}_getEditorObject(){return Wn(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}};gn=xc([l.OnLifecycle(l.LifecycleStages.Steady,gn),De(0,l.IUniverInstanceService),De(1,b.IRenderManagerService),De(2,l.ICommandService),De(3,Ee),De(4,l.IContextService),De(5,Kt),De(6,D.Inject(te.LexerTreeBuilder)),De(7,l.IUndoRedoService),De(8,D.Inject(_.SheetInterceptorService)),De(9,D.Inject(_.SelectionManagerService))],gn);function Dc(i,e,t){i=l.Tools.deepClone(i);const{documentModel:n}=e;if(n==null)return null;const o=n.getSnapshot(),{body:r}=o;if(r==null)return null;const s=r.dataStream;let c=s.substring(s.length-2,s.length)===l.DEFAULT_EMPTY_DOCUMENT_VALUE?s.substring(0,s.length-2):s;if(l.isFormulaString(c)){if(i.f===c)return null;const d=t.checkIfAddBracket(c);for(let u=0;u<d;u++)c+=te.matchToken.CLOSE_BRACKET;i.f=c,i.v=null,i.p=null}else if(Ac(r))r.dataStream===`\r
19
+ `?(i.v="",i.f=null,i.si=null,i.p=null):(i.p=o,i.v=null,i.f=null,i.si=null);else{if((c===i.v||c===""&&i.v==null)&&i.p==null)return null;i.v=c,i.f=null,i.si=null,i.p=null}return i}var Nc=Object.defineProperty,Pc=Object.getOwnPropertyDescriptor,Hc=(i,e,t,n)=>{for(var o=n>1?void 0:n?Pc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Nc(e,t,o),o},Ne=(i,e)=>(t,n)=>e(t,n,i);let Sn=class extends l.RxDisposable{constructor(e,t,n,o,r,s,a,c,d,u){super();v(this,"_loadedMap",new Set);this._univerInstanceService=e,this._renderManagerService=t,this._editorBridgeService=n,this._docSkeletonManagerService=o,this._docViewModelManagerService=r,this._commandService=s,this._contextService=a,this._formulaEditorManagerService=c,this._undoRedoService=d,this._textSelectionManagerService=u,this._initialize()}_initialize(){this._syncFormulaEditorContent(),this._commandExecutedListener(),this._syncEditorSize(),this._listenFxBtnClick(),this._listenFoldBtnClick(),this._renderManagerService.currentRender$.pipe(H.takeUntil(this.dispose$)).subscribe(e=>{e===l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(this._loadedMap.has(e)||(this._initialMain(e),this._loadedMap.add(e)))}),this._textSelectionManagerService.textSelection$.pipe(H.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const{unitId:t}=e;t!==l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(this._contextService.setContextValue(l.FOCUSING_FORMULA_EDITOR,!1),this._undoRedoService.clearUndoRedo(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))})}_listenFxBtnClick(){this._formulaEditorManagerService.fxBtnClick$.pipe(H.takeUntil(this.dispose$)).subscribe(()=>{var t;if(this._contextService.getContextValue(l.FOCUSING_EDITOR_BUT_HIDDEN)&&!this._contextService.getContextValue(l.EDITOR_ACTIVATED)){this._univerInstanceService.setCurrentUniverDocInstance(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),this._contextService.setContextValue(l.FOCUSING_FORMULA_EDITOR,!0);const n=this._univerInstanceService.getUniverDocInstance(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);this._editorBridgeService.isVisible().visible===!1&&this._editorBridgeService.changeVisible({visible:!0,eventType:b.DeviceInputEventType.PointerDown});const r=(t=n==null?void 0:n.getBody())==null?void 0:t.dataStream;if(r==null)return;let s=r.startsWith("=")?r:`=${r}`;s=s.replace(/\r\n$/,"");const a=[{startOffset:s.length,endOffset:s.length}],c={unitId:l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,body:{dataStream:s},segmentId:""};this._commandService.executeCommand(J.CoverContentCommand.id,c),this._textSelectionManagerService.replaceTextRanges(a)}})}_listenFoldBtnClick(){this._formulaEditorManagerService.foldBtnStatus$.pipe(H.takeUntil(this.dispose$)).subscribe(()=>{this._textSelectionManagerService.refreshSelection()})}_initialMain(e){const t=this._renderManagerService.getRenderById(e);if(t==null)return;const{mainComponent:n}=t;n!=null&&this.disposeWithMe(l.toDisposable(n.onPointerDownObserver.add(()=>{this._contextService.setContextValue(l.FOCUSING_FORMULA_EDITOR,!0),this._undoRedoService.clearUndoRedo(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),this._editorBridgeService.isVisible().visible===!1&&this._editorBridgeService.changeVisible({visible:!0,eventType:b.DeviceInputEventType.PointerDown})})))}_syncEditorSize(){this._formulaEditorManagerService.position$.pipe(H.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const t=Wn(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,this._renderManagerService),n=this._univerInstanceService.getUniverDocInstance(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);if(t==null||n==null)return;const{width:o,height:r}=e,{engine:s}=t;n.updateDocumentDataPageSize(o),this._autoScroll(),requestIdleCallback(()=>{s.resizeBySize(o,r)})})}_syncFormulaEditorContent(){this._editorBridgeService.currentEditCellState$.pipe(H.takeUntil(this.dispose$)).subscribe(e=>{e==null||this._editorBridgeService.isForceKeepVisible()||this._editorSyncHandler(e)}),this._editorBridgeService.visible$.pipe(H.takeUntil(this.dispose$)).subscribe(e=>{if(e==null||e.visible===!1||this._editorBridgeService.isForceKeepVisible())return;const t=this._editorBridgeService.getLatestEditCellState();t!=null&&this._editorSyncHandler(t)})}_editorSyncHandler(e){var s;const t=(s=e.documentLayoutObject.documentModel)==null?void 0:s.getBody();let n=t==null?void 0:t.dataStream,o=t==null?void 0:t.paragraphs,r=[];n==null||o==null||(e.isInArrayFormulaRange===!0&&this._editorBridgeService.isVisible().eventType===b.DeviceInputEventType.Dblclick?(n=`\r
20
+ `,o=[{startIndex:0}]):e.isInArrayFormulaRange===!0&&(r=(t==null?void 0:t.textRuns)||[]),this._syncContentAndRender(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,n,o,r),this._autoScroll())}_commandExecutedListener(){const e=[J.RichTextEditingMutation.id,jn.id],t=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(o=>{var r,s;if(e.includes(o.id)){const a=o.params,{unitId:c}=a;if(t.includes(c)){const d=this._univerInstanceService.getUniverDocInstance(c),u=(r=d==null?void 0:d.getBody())==null?void 0:r.dataStream,h=(s=d==null?void 0:d.getBody())==null?void 0:s.paragraphs,m=c===l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY?l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY:l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY;if(u==null||h==null)return;this._syncContentAndRender(m,u,h),this._autoScroll()}}}));const n=[_.SetRangeValuesMutation.id,_.MoveRangeMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(o=>{var r,s,a,c,d;if(n.includes(o.id)){const u=this._editorBridgeService.getLatestEditCellState();if(u==null)return;let h=!1;const{row:m,column:g}=u;if(o.id===_.SetRangeValuesMutation.id&&o.params?(s=(r=o.params.cellValue)==null?void 0:r[m])!=null&&s[g]&&(h=!0):o.id===_.MoveRangeMutation.id&&o.params&&(c=(a=o.params.to.value)==null?void 0:a[m])!=null&&c[g]&&(h=!0),h){const S=(d=u.documentLayoutObject.documentModel)==null?void 0:d.getBody();if(S==null)return;const{dataStream:f,paragraphs:C=[]}=S;this._syncContentAndRender(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,f,C),this._autoScroll()}}}))}_syncContentAndRender(e,t,n,o=[]){var h;const r=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY],s=this._docSkeletonManagerService.getSkeletonByUnitId(e),a=this._univerInstanceService.getUniverDocInstance(e),c=this._docViewModelManagerService.getViewModel(e);if(a==null||c==null||s==null)return;a.getBody().dataStream=t,a.getBody().paragraphs=this._clearParagraph(n),e===l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(a.getBody().textRuns=[]),o.length>0&&(a.getBody().textRuns=o),c.reset(a);const{skeleton:d}=s,u=this._renderManagerService.getRenderById(e);u!=null&&(d.calculate(),r.includes(e)&&((h=u.mainComponent)==null||h.makeDirty()))}_clearParagraph(e){const t=l.Tools.deepClone(e);for(const n of t)n.paragraphStyle&&(n.paragraphStyle.horizontalAlign=l.HorizontalAlign.UNSPECIFIED);return t}_autoScroll(){var S,f;const e=(S=this._docSkeletonManagerService.getSkeletonByUnitId(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:S.skeleton,t=this._formulaEditorManagerService.getPosition(),n=this._renderManagerService.getRenderById(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),o=this._univerInstanceService.getUniverDocInstance(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);if(e==null||t==null||n==null||o==null)return;const{marginTop:r=0,marginBottom:s=0}=o.getSnapshot().documentStyle,{scene:a,mainComponent:c}=n;let{actualHeight:d}=e.getActualSize();d+=r+s;const{width:u,height:h}=t,m=a.getViewport(J.VIEWPORT_KEY.VIEW_MAIN);let g=m==null?void 0:m.getScrollBar();a.transformByState({width:u,height:d}),c==null||c.resize(u,d),d>h?g==null?m&&new b.ScrollBar(m,{enableHorizontal:!1,barSize:8}):m==null||m.resetSizeAndScrollBar():(g=null,m==null||m.scrollTo({x:0,y:0}),(f=m==null?void 0:m.getScrollBar())==null||f.dispose())}};Sn=Hc([l.OnLifecycle(l.LifecycleStages.Steady,Sn),Ne(0,l.IUniverInstanceService),Ne(1,b.IRenderManagerService),Ne(2,Ee),Ne(3,D.Inject(J.DocSkeletonManagerService)),Ne(4,D.Inject(J.DocViewModelManagerService)),Ne(5,l.ICommandService),Ne(6,l.IContextService),Ne(7,Yn),Ne(8,l.IUndoRedoService),Ne(9,D.Inject(J.TextSelectionManagerService))],Sn);var Lc=Object.defineProperty,Uc=Object.getOwnPropertyDescriptor,kc=(i,e,t,n)=>{for(var o=n>1?void 0:n?Uc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Lc(e,t,o),o},Vc=(i,e)=>(t,n)=>e(t,n,i);let _n=class extends l.Disposable{constructor(i){super(),this._currentUniverService=i,setTimeout(()=>{this._initialize()},0)}_initialize(){this._currentUniverService.createDoc({id:l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:{dataStream:`${l.DEFAULT_EMPTY_DOCUMENT_VALUE}`,textRuns:[],paragraphs:[{startIndex:0}]},documentStyle:{}});const i={id:l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,body:{dataStream:`${l.DEFAULT_EMPTY_DOCUMENT_VALUE}`,textRuns:[],paragraphs:[{startIndex:0}]},documentStyle:{pageSize:{width:1/0,height:1/0},marginTop:5,marginBottom:5,marginRight:0,marginLeft:0,paragraphLineGapDefault:0,renderConfig:{horizontalAlign:l.HorizontalAlign.UNSPECIFIED,verticalAlign:l.VerticalAlign.UNSPECIFIED,centerAngle:0,vertexAngle:0,wrapStrategy:l.WrapStrategy.WRAP}}};this._currentUniverService.createDoc(i)}};_n=kc([l.OnLifecycle(l.LifecycleStages.Rendered,_n),Vc(0,l.IUniverInstanceService)],_n);const Bc="36",Fc="univer-sheet-container",Nr={sheetFooterBarHeight:Bc,sheetContainer:Fc};var Wc=Object.defineProperty,jc=Object.getOwnPropertyDescriptor,$c=(i,e,t,n)=>{for(var o=n>1?void 0:n?jc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Wc(e,t,o),o},ye=(i,e)=>(t,n)=>e(t,n,i);const fo=-1e3,po=5,zc=2;let fn=class extends l.Disposable{constructor(e,t,n,o,r,s,a,c,d,u,h){super();v(this,"_onInputSubscription");v(this,"_onInputActivateSubscription");v(this,"_editorVisiblePrevious",!1);this._docSkeletonManagerService=e,this._docViewModelManagerService=t,this._contextService=n,this._currentUniverService=o,this._renderManagerService=r,this._editorBridgeService=s,this._cellEditorManagerService=a,this._textSelectionRenderManager=c,this._textSelectionManagerService=d,this._commandService=u,this._localService=h,this._initialize(),this._commandExecutedListener()}dispose(){var e,t;(e=this._onInputSubscription)==null||e.unsubscribe(),(t=this._onInputActivateSubscription)==null||t.unsubscribe()}_initialize(){this._initialEditFocusListener(),this._initialStartEdit(),this._initialKeyboardListener(),this._initialCursorSync(),this._listenEditorFocus()}_listenEditorFocus(){const e=this._getEditorObject();e!=null&&this.disposeWithMe(l.toDisposable(e.document.onPointerDownObserver.add(()=>{var t;if(this._editorBridgeService.isVisible()){const n=this._editorBridgeService.getEditCellState(),o=this._editorBridgeService.getCurrentEditorId();if(n==null||o==null)return;const r=(t=this._docSkeletonManagerService.getSkeletonByUnitId(o))==null?void 0:t.skeleton;if(r==null)return;const{position:s,documentLayoutObject:a,canvasOffset:c,scaleX:d,scaleY:u}=n;this._fitTextSize(s,c,r,a,d,u)}})))}_initialCursorSync(){this._cellEditorManagerService.focus$.subscribe(()=>{this._textSelectionRenderManager.sync()})}_initialEditFocusListener(){this._onInputSubscription=this._editorBridgeService.currentEditCellState$.subscribe(e=>{if(e==null||this._editorBridgeService.isForceKeepVisible())return;const{position:t,documentLayoutObject:n,scaleX:o,editorUnitId:r}=e;if(this._getEditorObject()==null)return;const{startX:a,endX:c}=t,{textRotation:d,wrapStrategy:u,documentModel:h}=n,{a:m}=d;h.updateDocumentId(r),u===l.WrapStrategy.WRAP&&m===0&&h.updateDocumentDataPageSize((c-a)/o),this._currentUniverService.changeDoc(r,h),this._contextService.setContextValue(l.FOCUSING_EDITOR_BUT_HIDDEN,!0),this._textSelectionManagerService.replaceTextRanges([{startOffset:0,endOffset:0}]),this._textSelectionRenderManager.activate(fo,fo)})}_fitTextSize(e,t,n,o,r=1,s=1){const{startX:a,startY:c,endX:d,endY:u}=e,h=o.documentModel;if(h==null)return;const{actualWidth:m,actualHeight:g}=this._predictingSize(e,t,n,o,r,s),{verticalAlign:S,paddingData:f,fill:C}=o;let R=d-a,M=u-c;if(R<m&&(R=m),M<g)M=g,h.updateDocumentDataMargin(f);else{let T=f.t||0;S===l.VerticalAlign.MIDDLE?T=(M-g)/2:S===l.VerticalAlign.BOTTOM&&(T=M-g),T/=s,T=T<(f.t||0)?f.t||0:T,h.updateDocumentDataMargin({t:T})}n.calculate(),this._editAreaProcessing(R,M,e,t,C,r,s)}_predictingSize(e,t,n,o,r=1,s=1){const{startX:a,endX:c}=e,{textRotation:d,wrapStrategy:u}=o,h=o.documentModel,{a:m}=d,g=document.body.clientWidth;if(u===l.WrapStrategy.WRAP&&m===0){const{actualWidth:C,actualHeight:R}=n.getActualSize();return{actualWidth:C*r,actualHeight:R*s}}h==null||h.updateDocumentDataPageSize((g-a-t.left)/r),n.calculate();const S=n.getActualSize();let f=c-a;return f<S.actualWidth*r+po*r&&(f=S.actualWidth*r+po*r),h==null||h.updateDocumentDataPageSize(f/r),h==null||h.updateDocumentRenderConfig({horizontalAlign:l.HorizontalAlign.UNSPECIFIED}),{actualWidth:f,actualHeight:S.actualHeight*s}}_editAreaProcessing(e,t,n,o,r,s=1,a=1){var E;const c=this._getEditorObject();if(c==null)return;let{startX:d,startY:u}=n;const{document:h,scene:m,engine:g}=c,S=m.getViewport(J.VIEWPORT_KEY.VIEW_MAIN),f=document.body.clientHeight-u-parseFloat(Nr.sheetFooterBarHeight)-o.top-zc*2,C=document.body.clientWidth-d-o.left;let R=t,M=S==null?void 0:S.getScrollBar();R>f?(R=f,M==null?S&&new b.ScrollBar(S,{enableHorizontal:!1,barSize:8}):S==null||S.resetSizeAndScrollBar()):(M=null,(E=S==null?void 0:S.getScrollBar())==null||E.dispose()),e+=(M==null?void 0:M.barSize)||0,e>C&&(e=C),d-=b.FIX_ONE_PIXEL_BLUR_OFFSET,u-=b.FIX_ONE_PIXEL_BLUR_OFFSET,this._addBackground(m,e/s,t/a,r);const{scaleX:T,scaleY:w}=m.getPrecisionScale();m.transformByState({width:e/s,height:t/a,scaleX:s,scaleY:a}),h.resize(e/s,t/a),requestIdleCallback(()=>{g.resizeBySize(b.fixLineWidthByScale(e,T),b.fixLineWidthByScale(R,w))}),this._cellEditorManagerService.setState({startX:d,startY:u,endX:e+d,endY:R+u,show:!0})}_addBackground(e,t,n,o){const r="_backgroundRectHelperColor_",s=e.getObject(r);s==null&&o==null||(s==null?e.addObjects([new b.Rect(r,{width:t,height:n,fill:o,evented:!1})],J.DOCS_COMPONENT_MAIN_LAYER_INDEX):o==null?s.dispose():(s.setProps({fill:o}),s.transformByState({width:t,height:n})))}_initialStartEdit(){this._onInputActivateSubscription=this._editorBridgeService.visible$.subscribe(e=>{var w,E,y;const{visible:t,eventType:n,keycode:o}=e;if(t===this._editorVisiblePrevious||(this._editorVisiblePrevious=t,t===!1))return;const r=this._editorBridgeService.getEditCellState();if(r==null)return;const{position:s,documentLayoutObject:a,canvasOffset:c,scaleX:d,scaleY:u,editorUnitId:h,unitId:m,isInArrayFormulaRange:g=!1}=r,S=this._getEditorObject();if(S==null)return;const{document:f,scene:C}=S;this._contextService.setContextValue(l.EDITOR_ACTIVATED,!0);const{documentModel:R}=a,M=this._docSkeletonManagerService.getSkeletonByUnitId(h);if(M==null||R==null)return;const{skeleton:T}=M;if(this._fitTextSize(s,c,T,a,d,u),n===b.DeviceInputEventType.Keyboard||n===b.DeviceInputEventType.Dblclick&&g){const x=l.Tools.deepClone(R.snapshot),O=(w=this._docViewModelManagerService.getCurrent())==null?void 0:w.docViewModel;this._resetBodyStyle(x.body),R.reset(x),O.reset(R),f.makeDirty(),(o===I.KeyCode.BACKSPACE||n===b.DeviceInputEventType.Dblclick)&&(T.calculate(),this._editorBridgeService.changeEditorDirty(!0)),this._textSelectionManagerService.replaceTextRanges([{startOffset:0,endOffset:0}])}else if(n===b.DeviceInputEventType.Dblclick){const x=R.getBody().dataStream.length-2||0;(E=C.getViewport(J.VIEWPORT_KEY.VIEW_MAIN))==null||E.scrollTo({y:1/0}),this._textSelectionManagerService.replaceTextRanges([{startOffset:x,endOffset:x}])}(y=this._renderManagerService.getRenderById(m))==null||y.scene.resetCursor()})}_resetBodyStyle(e){e.dataStream=l.DEFAULT_EMPTY_DOCUMENT_VALUE,e.textRuns!=null&&(e.textRuns.length===1?(e.textRuns[0].st=0,e.textRuns[0].ed=1):e.textRuns=void 0),e.paragraphs!=null&&(e.paragraphs.length===1?e.paragraphs[0].startIndex=0:e.paragraphs=[{startIndex:0}]),e.sectionBreaks!=null&&(e.sectionBreaks=void 0),e.tables!=null&&(e.tables=void 0),e.customRanges!=null&&(e.customRanges=void 0),e.customBlocks!=null&&(e.customBlocks=void 0)}_initialKeyboardListener(){this._textSelectionRenderManager.onInputBefore$.subscribe(e=>{const t=this._contextService.getContextValue(l.FOCUSING_FORMULA_EDITOR);this._contextService.getContextValue(l.FOCUSING_SHEET)&&!t&&this._showEditorByKeyboard(e)})}_showEditorByKeyboard(e){if(e==null)return;const t=e.event;this._commandService.executeCommand(He.id,{visible:!0,eventType:b.DeviceInputEventType.Keyboard,keycode:t.which})}_commandExecutedListener(){const e=[J.RichTextEditingMutation.id,jn.id],t=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{var o;if(e.includes(n.id)){const r=n.params,{unitId:s}=r,a=this._editorBridgeService.getCurrentEditorId();if(a==null)return;this._editorBridgeService.changeEditorDirty(!0);const c=(o=this._docSkeletonManagerService.getSkeletonByUnitId(a))==null?void 0:o.skeleton;if(c==null||!t.includes(s))return;const d=this._editorBridgeService.getEditCellState();if(d==null)return;const{position:u,documentLayoutObject:h,canvasOffset:m,scaleX:g,scaleY:S}=d;this._fitTextSize(u,m,c,h,g,S)}}))}_getEditorObject(){return Wn(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}};fn=$c([l.OnLifecycle(l.LifecycleStages.Steady,fn),ye(0,D.Inject(J.DocSkeletonManagerService)),ye(1,D.Inject(J.DocViewModelManagerService)),ye(2,l.IContextService),ye(3,l.IUniverInstanceService),ye(4,b.IRenderManagerService),ye(5,Ee),ye(6,Kt),ye(7,b.ITextSelectionRenderManager),ye(8,D.Inject(J.TextSelectionManagerService)),ye(9,l.ICommandService),ye(10,D.Inject(l.LocaleService))],fn);const Zn={id:"sheet.command.change-zoom-ratio",type:l.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const{delta:t,reset:n}=e,o=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance(),r=o.getActiveSheet(),s=o.getUnitId(),a=r.getSheetId();let c=n?100:Math.round((r.getConfig().zoomRatio+t)*100);c=Math.max(gi[0],c),c=Math.min(gi[1],c);const d=c/100;return i.get(l.ICommandService).executeCommand(We.id,{unitId:s,subUnitId:a,zoomRatio:d})}},Gn={id:"sheet.command.set-zoom-ratio",type:l.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const{unitId:t,subUnitId:n,zoomRatio:o}=e;return i.get(l.ICommandService).executeCommand(We.id,{unitId:t,subUnitId:n,zoomRatio:o})}},Pr={id:"sheet.operation.set-activate-cell-edit",type:l.CommandType.OPERATION,handler:(i,e)=>(i.get(Ee).setEditCell(e),!0)};var Xc=Object.defineProperty,Yc=Object.getOwnPropertyDescriptor,Zc=(i,e,t,n)=>{for(var o=n>1?void 0:n?Yc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Xc(e,t,o),o},dt=(i,e)=>(t,n)=>e(t,n,i);let pn=class extends l.RxDisposable{constructor(i,e,t,n,o,r){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._editorBridgeService=o,this._selectionManagerService=r,this._initialize(),this._commandExecutedListener()}dispose(){}_initialize(){this._initSelectionChangeListener(),this._initialEventListener()}_initSelectionChangeListener(){H.merge(this._selectionManagerService.selectionMoveEnd$,this._selectionManagerService.selectionMoveStart$).pipe(H.takeUntil(this.dispose$)).subscribe(i=>this._handleSelectionListener(i))}_handleSelectionListener(i){const e=this._selectionManagerService.getCurrent();if((e==null?void 0:e.pluginName)!==_.NORMAL_SELECTION_PLUGIN_NAME||this._editorBridgeService.isVisible().visible===!0)return;const t=this._sheetSkeletonManagerService.getCurrent();if(t==null||i==null||i.length===0||i[i.length-1]==null)return;const{primary:n}=i[i.length-1];if(n==null)return;const o=this._getSheetObject();if(o==null)return;const{unitId:r,sheetId:s}=t,{scene:a,engine:c}=o;this._commandService.executeCommand(Pr.id,{scene:a,engine:c,primary:n,unitId:r,sheetId:s})}_initialEventListener(){const i=this._getSheetObject();if(i==null)return;const{spreadsheet:e,spreadsheetColumnHeader:t,spreadsheetLeftTopPlaceholder:n,spreadsheetRowHeader:o}=i;e.onDblclickObserver.add(r=>{r.button!==2&&this._commandService.executeCommand(He.id,{visible:!0,eventType:b.DeviceInputEventType.Dblclick})}),e.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this)),t.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this)),n.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this)),o.onPointerDownObserver.add(this._keepVisibleHideEditor.bind(this))}_keepVisibleHideEditor(){this._editorBridgeService.isForceKeepVisible()||this._hideEditor()}_hideEditor(){this._editorBridgeService.isVisible().visible===!0&&(this._selectionManagerService.makeDirty(!1),this._commandService.executeCommand(He.id,{visible:!1,eventType:b.DeviceInputEventType.PointerDown}),setTimeout(()=>{this._selectionManagerService.makeDirty(!0)},0))}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}_commandExecutedListener(){const i=_.COMMAND_LISTENER_SKELETON_CHANGE;this.disposeWithMe(this._commandService.onCommandExecuted((e,t)=>{t!=null&&t.fromCollab||(e.id===_.SetWorksheetActiveOperation.id?this._keepVisibleHideEditor():i.includes(e.id)&&this._hideEditor())})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{e.id===Gn.id&&this._editorBridgeService.refreshEditCellState()}))}};pn=Zc([l.OnLifecycle(l.LifecycleStages.Rendered,pn),dt(0,D.Inject(exports.SheetSkeletonManagerService)),dt(1,l.IUniverInstanceService),dt(2,l.ICommandService),dt(3,b.IRenderManagerService),dt(4,Ee),dt(5,D.Inject(_.SelectionManagerService))],pn);var Gc=Object.defineProperty,Kc=Object.getOwnPropertyDescriptor,qc=(i,e,t,n)=>{for(var o=n>1?void 0:n?Kc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Gc(e,t,o),o},Pt=(i,e)=>(t,n)=>e(t,n,i);let vn=class extends l.Disposable{constructor(i,e,t,n,o){super(),this._commandService=i,this._formatPainterService=e,this._currentUniverService=t,this._renderManagerService=n,this._selectionRenderService=o,this._initialize()}_initialize(){this._commandExecutedListener(),this._bindFormatPainterStatus()}_bindFormatPainterStatus(){this._formatPainterService.status$.subscribe(i=>{const{scene:e}=this._getSheetObject()||{};e&&(i!==Oe.OFF?e.setDefaultCursor(b.CURSOR_TYPE.CELL):e.setDefaultCursor(b.CURSOR_TYPE.DEFAULT))})}_commandExecutedListener(){this.disposeWithMe(l.toDisposable(this._selectionRenderService.selectionMoveEnd$.subscribe(i=>{if(this._formatPainterService.getStatus()!==Oe.OFF){const{rangeWithCoord:e}=i[i.length-1];this._applyFormatPainter({startRow:e.startRow,startColumn:e.startColumn,endRow:e.endRow,endColumn:e.endColumn}),this._formatPainterService.getStatus()===Oe.ONCE&&this._commandService.executeCommand(Li.id)}})))}async _applyFormatPainter(i){const{styles:e,merges:t}=this._formatPainterService.getSelectionFormat(),n=this._currentUniverService.getCurrentUniverSheetInstance().getUnitId(),o=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();if(!e)return;const{startRow:r,startColumn:s,endRow:a,endColumn:c}=e.getDataRange(),d=a-r+1,u=c-s+1,h=Array.from({length:i.endRow-i.startRow+1},()=>Array.from({length:i.endColumn-i.startColumn+1},()=>({}))),m=[];h.forEach((S,f)=>{S.forEach((C,R)=>{const M=f%d+r,T=R%u+s,w=e.getValue(M,T);w&&(h[f][R].s=w)})}),t.forEach(S=>{const f={startRow:S.startRow-r,startColumn:S.startColumn-s,endRow:S.endRow-r,endColumn:S.endColumn-s},C=Math.max(1,Math.floor((i.endRow-i.startRow+1)/d)),R=Math.max(1,Math.floor((i.endColumn-i.startColumn+1)/u));for(let M=0;M<C;M++)for(let T=0;T<R;T++)m.push({startRow:f.startRow+M*d+i.startRow,startColumn:f.startColumn+T*u+i.startColumn,endRow:f.endRow+M*d+i.startRow,endColumn:f.endColumn+T*u+i.startColumn})});const g={subUnitId:o,unitId:n,styleRange:i,styleValues:h,mergeRanges:m};await this._commandService.executeCommand(Mr.id,g)}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}};vn=qc([l.OnLifecycle(l.LifecycleStages.Rendered,vn),Pt(0,l.ICommandService),Pt(1,Et),Pt(2,l.IUniverInstanceService),Pt(3,b.IRenderManagerService),Pt(4,_e)],vn);const Cn={id:"sheet.command.set-scroll-relative",type:l.CommandType.COMMAND,handler:async(i,e={offsetX:0,offsetY:0})=>{const t=i.get(l.ICommandService),n=i.get(Je),r=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance(),s=r.getActiveSheet(),{xSplit:a,ySplit:c}=s.getConfig().freeze,d=n.getCurrentScroll(),{offsetX:u=0,offsetY:h=0}=e||{},{sheetViewStartRow:m=0,sheetViewStartColumn:g=0,offsetX:S=0,offsetY:f=0}=d||{};return t.executeCommand(Tt.id,{unitId:r.getUnitId(),sheetId:s.getSheetId(),sheetViewStartRow:m+c,sheetViewStartColumn:g+a,offsetX:S+u,offsetY:f+h})}},vt={id:"sheet.command.scroll-view",type:l.CommandType.COMMAND,handler:async(i,e)=>{if(!e)return!1;const n=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance(),o=n.getActiveSheet(),s=i.get(Je).getCurrentScroll();if(!o)return!1;const a=i.get(l.ICommandService),{sheetViewStartRow:c,sheetViewStartColumn:d,offsetX:u,offsetY:h}=e,{sheetViewStartColumn:m,sheetViewStartRow:g,offsetX:S,offsetY:f}=s||{},{xSplit:C,ySplit:R}=o.getConfig().freeze;return a.executeCommand(Tt.id,{unitId:n.getUnitId(),sheetId:o.getSheetId(),sheetViewStartRow:c??(g??0)+R,sheetViewStartColumn:d??(m??0)+C,offsetX:u??S,offsetY:h??f})}};l.CommandType.COMMAND;var Jc=Object.defineProperty,Qc=Object.getOwnPropertyDescriptor,ed=(i,e,t,n)=>{for(var o=n>1?void 0:n?Qc(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Jc(e,t,o),o},Pe=(i,e)=>(t,n)=>e(t,n,i);const td="__SpreadsheetFreezeRowMainName__",nd="__SpreadsheetFreezeRowHeaderName__",id="__SpreadsheetFreezeColumnMainName__",od="__SpreadsheetFreezeColumnHeaderName__",ri=4,rd=.01;let In=class extends l.Disposable{constructor(e,t,n,o,r,s,a,c,d,u){super();v(this,"_rowFreezeHeaderRect");v(this,"_rowFreezeMainRect");v(this,"_columnFreezeHeaderRect");v(this,"_columnFreezeMainRect");v(this,"_freezeDownObservers",[]);v(this,"_freezeMoveObservers",[]);v(this,"_freezeLeaveObservers",[]);v(this,"_moveObserver");v(this,"_upObserver");v(this,"_changeToRow",-1);v(this,"_changeToColumn",-1);v(this,"_changeToOffsetX",0);v(this,"_changeToOffsetY",0);v(this,"_activeViewport",null);v(this,"_freezeNormalHeaderColor","");v(this,"_freezeNormalMainColor","");v(this,"_freezeActiveColor","");v(this,"_freezeHoverColor","");v(this,"_lastFreeze");this._sheetSkeletonManagerService=e,this._currentUniverService=t,this._commandService=n,this._renderManagerService=o,this._selectionRenderService=r,this._selectionManagerService=s,this._scrollManagerService=a,this._themeService=c,this._sheetInterceptorService=d,this._injector=u,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._themeChangeListener(),this._interceptorCommands(),this._bindViewportScroll()}_createFreeze(e=0,t){var x;const n=t??this._getFreeze();if(n==null)return;const o=(x=this._sheetSkeletonManagerService.getCurrent())==null?void 0:x.skeleton;if(o==null)return;const{startRow:r,startColumn:s}=n,a=this._getPositionByIndex(r,s);if(a==null)return;const c=this._getSheetObject();if(c==null)return;const d=c.engine,u=(d==null?void 0:d.width)||0,h=(d==null?void 0:d.height)||0,m=c.scene,{startX:g,startY:S}=a,{rowTotalHeight:f,columnTotalWidth:C,rowHeaderWidthAndMarginLeft:R,columnHeaderHeightAndMarginTop:M}=o,T=u>C+R?u:C+M,w=h>f+M?h:f+M;this._changeToRow=r,this._changeToColumn=s,this._changeToOffsetX=g,this._changeToOffsetY=S;const E=Math.max(m.scaleX,m.scaleY),y=ri/(E<1?1:E);if(e===0){const O=y;this._rowFreezeHeaderRect=new b.Rect(nd,{fill:this._freezeNormalHeaderColor,width:R,height:y,left:0,top:S-O,zIndex:3});let A=this._freezeNormalHeaderColor;(r===-1||r===0)&&(A=this._freezeNormalMainColor),this._rowFreezeMainRect=new b.Rect(td,{fill:A,width:T*2,height:y,left:R,top:S-O,zIndex:3}),m.addObjects([this._rowFreezeHeaderRect,this._rowFreezeMainRect],qe)}else{const O=y;this._columnFreezeHeaderRect=new b.Rect(od,{fill:this._freezeNormalHeaderColor,width:y,height:M,left:g-O,top:0,zIndex:3});let A=this._freezeNormalHeaderColor;(s===-1||s===0)&&(A=this._freezeNormalMainColor),this._columnFreezeMainRect=new b.Rect(id,{fill:A,width:y,height:w*2,left:g-O,top:M,zIndex:3}),m.addObjects([this._columnFreezeHeaderRect,this._columnFreezeMainRect],qe)}this._eventBinding(e)}_eventBinding(e=0){let t=this._rowFreezeHeaderRect,n=this._rowFreezeMainRect;e===1&&(t=this._columnFreezeHeaderRect,n=this._columnFreezeMainRect);const o=this._getSheetObject();if(o==null)return;const{scene:r}=o;this._freezeMoveObservers.push(t==null?void 0:t.onPointerEnterObserver.add(()=>{t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),r.setCursor(b.CURSOR_TYPE.GRAB)})),this._freezeMoveObservers.push(n==null?void 0:n.onPointerEnterObserver.add(()=>{t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),r.setCursor(b.CURSOR_TYPE.GRAB)})),this._freezeLeaveObservers.push(t==null?void 0:t.onPointerLeaveObserver.add(()=>{t==null||t.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),r.resetCursor()})),this._freezeLeaveObservers.push(n==null?void 0:n.onPointerLeaveObserver.add(()=>{t==null||t.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),r.resetCursor()})),this._freezeDownObservers.push(t==null?void 0:t.onPointerDownObserver.add(s=>{this._freezeDown(s,t,n,e)})),this._freezeDownObservers.push(n==null?void 0:n.onPointerDownObserver.add(s=>{this._freezeDown(s,t,n,e)}))}_getCurrentLastVisibleRow(){var h;const e=this._getSheetObject();if(e==null)return;const t=(h=this._sheetSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(t==null)return;const n=e.scene,o=Math.max(n.scaleX,n.scaleY),r=this._scrollManagerService.getCurrentScroll(),s=(e.engine.height-t.columnHeaderHeight)/o,a=(r==null?void 0:r.sheetViewStartRow)??0,c=a===0?-((r==null?void 0:r.offsetY)??0):t.rowHeightAccumulation[a-1]-((r==null?void 0:r.offsetY)??0);let d=0,u=!1;for(let m=a,g=t.rowHeightAccumulation.length;m<g;m++)if(t.rowHeightAccumulation[m]-c>s){d=m,u=!0;break}return u||(d=t.rowHeightAccumulation.length-1),d}_getActiveViewport(e){var n;const t=(n=this._getSheetObject())==null?void 0:n.scene.getViewports();return t&&t.find(o=>o.isHit(new b.Vector2(e.offsetX,e.offsetY)))||null}_freezeDown(e,t,n,o=0){var h;const r=(h=this._sheetSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(r==null)return;const s=this._getSheetObject();if(s==null)return;const{scene:a}=s;a.setCursor(b.CURSOR_TYPE.GRABBING),a.disableEvent();const c=this._getCurrentLastVisibleRow(),d=c===void 0?Number.POSITIVE_INFINITY:r.rowHeightAccumulation[c];this._activeViewport=null;const u=this._getFreeze();u&&(this._changeToColumn=u.startColumn,this._changeToRow=u.startRow),this._moveObserver=a.onPointerMoveObserver.add(m=>{var T,w,E,y;const g=this._getActiveViewport(m),{startX:S,startY:f,row:C,column:R}=Mt(m.offsetX,m.offsetY,a,r,g||void 0);a.setCursor(b.CURSOR_TYPE.GRABBING);const M=ri/Math.max(a.scaleX,a.scaleY);o===0?((T=t.transformByState({top:Math.min(f,d)-M/2}))==null||T.setProps({fill:this._freezeActiveColor}),(w=n.transformByState({top:Math.min(f,d)-M/2}))==null||w.setProps({fill:this._freezeNormalHeaderColor}),this._changeToRow=c===void 0?C:Math.min(C,c),this._changeToOffsetY=Math.min(f,d),this._activeViewport=g):((E=t.transformByState({left:S-M/2}))==null||E.setProps({fill:this._freezeActiveColor}),(y=n.transformByState({left:S-M/2}))==null||y.setProps({fill:this._freezeNormalHeaderColor}),this._changeToColumn=R,this._changeToOffsetX=S,this._activeViewport=g)}),this._upObserver=a.onPointerUpObserver.add(()=>{var O,A;a.resetCursor(),a.enableEvent(),this._clearObserverEvent();const{rowHeaderWidthAndMarginLeft:m,columnHeaderHeightAndMarginTop:g}=r;o===0&&(this._changeToRow===0||this._changeToRow===-1)||o===1&&(this._changeToColumn===0||this._changeToColumn===-1)?(t.setProps({fill:this._freezeNormalHeaderColor}),n.setProps({fill:this._freezeNormalMainColor})):(t==null||t.setProps({fill:this._freezeNormalHeaderColor}),n==null||n.setProps({fill:this._freezeNormalHeaderColor}));const S=ri/Math.max(a.scaleX,a.scaleY);o===0?(this._changeToRow===0||this._changeToRow===-1)&&(t.transformByState({top:g-S}),n.transformByState({top:g-S})):(this._changeToColumn===0||this._changeToColumn===-1)&&(t.transformByState({left:m-S}),n.transformByState({left:m-S}));const f=this._scrollManagerService.getCurrentScroll()||{sheetViewStartRow:0,sheetViewStartColumn:0},{sheetViewStartRow:C,sheetViewStartColumn:R}=f;if(R==null||C==null)return;const M=this._currentUniverService.getCurrentUniverSheetInstance(),T=M.getActiveSheet(),w=(O=T.getConfig())==null?void 0:O.freeze;let E=(w==null?void 0:w.xSplit)||0,y=(w==null?void 0:w.ySplit)||0;const x=(A=this._activeViewport)==null?void 0:A.viewPortKey;o===0&&(!x||x===V.VIEW_LEFT_TOP||x===V.VIEW_MAIN_LEFT_TOP||x===V.VIEW_MAIN_TOP||x===V.VIEW_ROW_TOP?y=this._changeToRow-(w.startRow-w.ySplit):y=this._changeToRow-C,y=y<0?0:y),o===1&&(!x||x===V.VIEW_LEFT_TOP||x===V.VIEW_MAIN_LEFT_TOP||x===V.VIEW_MAIN_LEFT||x===V.VIEW_COLUMN_LEFT?E=this._changeToColumn-(w.startColumn-w.xSplit):E=this._changeToColumn-R,E=E<0?0:E),this._commandService.executeCommand(_.SetFrozenCommand.id,{startRow:y===0?-1:this._changeToRow,startColumn:E===0?-1:this._changeToColumn,ySplit:y,xSplit:E,unitId:M.getUnitId(),subUnitId:T.getSheetId()})})}_getViewports(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e,n=t.getViewport(V.VIEW_COLUMN_LEFT),o=t.getViewport(V.VIEW_COLUMN_RIGHT),r=t.getViewport(V.VIEW_ROW_TOP),s=t.getViewport(V.VIEW_ROW_BOTTOM),a=t.getViewport(V.VIEW_LEFT_TOP),c=t.getViewport(V.VIEW_MAIN),d=t.getViewport(V.VIEW_MAIN_LEFT_TOP),u=t.getViewport(V.VIEW_MAIN_LEFT),h=t.getViewport(V.VIEW_MAIN_TOP);if(!(n==null||o==null||r==null||s==null||a==null||c==null||d==null||u==null||h==null))return{viewMain:c,viewMainLeftTop:d,viewMainLeft:u,viewMainTop:h,viewColumnLeft:n,viewColumnRight:o,viewRowTop:r,viewRowBottom:s,viewLeftTop:a}}_bindViewportScroll(){const e=this._getViewports();if(!e)return;const{viewMain:t,viewRowBottom:n,viewColumnRight:o,viewMainLeft:r,viewMainTop:s}=e;this.disposeWithMe(t.onScrollAfterObserver.add(a=>{const{scrollX:c,scrollY:d,actualScrollX:u,actualScrollY:h}=a;n.isActive&&n.updateScroll({scrollY:d,actualScrollY:h}).makeDirty(!0),o.isActive&&o.updateScroll({scrollX:c,actualScrollX:u}).makeDirty(!0),r.isActive&&r.updateScroll({scrollY:d,actualScrollY:h}).makeDirty(!0),s.isActive&&s.updateScroll({scrollX:c,actualScrollX:u}).makeDirty(!0)}))}_updateViewport(e=-1,t=-1,n=0,o=0,r=3){var x;const s=(x=this._sheetSkeletonManagerService.getCurrent())==null?void 0:x.skeleton;if(s==null)return;const{rowHeaderWidthAndMarginLeft:a,columnHeaderHeightAndMarginTop:c}=s,d=this._getViewports();if(!d)return;const{viewMain:u,viewMainLeftTop:h,viewMainLeft:m,viewMainTop:g,viewColumnLeft:S,viewColumnRight:f,viewRowTop:C,viewRowBottom:R,viewLeftTop:M}=d;f.resize({left:a,top:0,height:c,right:0}),R.resize({left:0,top:c,bottom:0,width:a}),M.resize({left:0,top:0,width:a,height:c});let T=!0,w=!0;h.enable(),(e===-1||e===0)&&(T=!1),(t===-1||t===0)&&(w=!1);const E=s.getNoMergeCellPositionByIndexWithNoHeader(e-n,t-o),y=s.getNoMergeCellPositionByIndexWithNoHeader(e,t);if(h.disable(),g.disable(),m.disable(),C.disable(),S.disable(),h.resetPadding(),g.resetPadding(),m.resetPadding(),C.resetPadding(),S.resetPadding(),T===!1&&w===!1)u.resize({left:a,top:c,bottom:0,right:0}),u.resetPadding();else if(T===!0&&w===!1){const O=y.startY-E.startY;u.resize({left:a,top:c+O,bottom:0,right:0}),u.setPadding({startY:E.startY,endY:y.startY,startX:0,endX:0}),r&2&&this._commandService.executeCommand(vt.id,{sheetViewStartRow:0,offsetY:0}),g.resize({left:a,top:c,height:O,right:0}),g.updateScroll({actualScrollY:E.startY,x:u.scrollX,actualScrollX:u.actualScrollX}).makeDirty(!0),C.resize({left:0,top:c,width:a,height:O}),C.updateScroll({actualScrollY:E.startY}).makeDirty(!0),R.resize({left:0,top:c+O,bottom:0,width:a}),g.enable(),C.enable()}else if(T===!1&&w===!0){const O=y.startX-E.startX;u.resize({left:a+O,top:c,bottom:0,right:0}),u.setPadding({startX:E.startX,endX:y.startX,startY:0,endY:0}),r&1&&this._commandService.executeCommand(vt.id,{sheetViewStartColumn:0,offsetX:0}),m.resize({left:a,top:c,width:O,bottom:0,right:0}),m.updateScroll({actualScrollX:E.startX,y:u.scrollY,actualScrollY:u.actualScrollY}).makeDirty(!0),S.resize({left:a,top:0,width:O,height:c}),S.updateScroll({actualScrollX:E.startX}).makeDirty(!0),f.resize({left:a+O,top:0,height:c,right:0}),m.enable(),S.enable()}else{const O=y.startX-E.startX,A=y.startY-E.startY;u.resize({left:a+O,top:c+A,bottom:0,right:0}),u.setPadding({startY:E.startY,endY:y.startY,startX:E.startX,endX:y.startX}),r&&this._commandService.executeCommand(vt.id,{...r&1?{sheetViewStartColumn:0,offsetX:0}:null,...r&2?{sheetViewStartRow:0,offsetY:0}:null}),m.resize({left:a,top:c+A,width:O,bottom:0}),m.updateScroll({actualScrollX:E.startX,y:u.scrollY,actualScrollY:u.actualScrollY}).makeDirty(!0),g.resize({left:a+O,top:c,height:A,right:0}),g.updateScroll({actualScrollY:E.startY,x:u.scrollX,actualScrollX:u.actualScrollX}).makeDirty(!0),h.resize({left:a,top:c,width:O,height:A}),h.updateScroll({actualScrollX:E.startX,actualScrollY:E.startY}).makeDirty(!0),C.resize({left:0,top:c,width:a,height:A}),C.updateScroll({actualScrollY:E.startY}).makeDirty(!0),R.resize({left:0,top:c+A,bottom:0,width:a}),S.resize({left:a,top:0,width:O,height:c}),S.updateScroll({actualScrollX:E.startX}).makeDirty(!0),f.resize({left:a+O,top:0,height:c,right:0}),h.enable(),g.enable(),m.enable(),C.enable(),S.enable()}}_skeletonListener(){this.disposeWithMe(l.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(e=>{[_.SetWorksheetActiveOperation.id,_.InsertRangeMoveDownCommand.id,_.InsertRangeMoveRightCommand.id].includes((e==null?void 0:e.commandId)||"")&&this._refreshCurrent()})))}_refreshCurrent(){const n=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getConfig().freeze,{startRow:o=-1,startColumn:r=-1,ySplit:s=0,xSplit:a=0}=n;this._refreshFreeze(o,r,s,a,0)}_themeChangeListener(){this._themeChange(this._themeService.getCurrentTheme()),this.disposeWithMe(l.toDisposable(this._themeService.currentTheme$.subscribe(e=>{this._clearFreeze(),this._themeChange(e),this._refreshCurrent()})))}_themeChange(e){this._freezeNormalHeaderColor=e.grey400,this._freezeNormalMainColor=new l.ColorKit(e.grey400).setAlpha(rd).toRgbString(),this._freezeActiveColor=e.primaryColor,this._freezeHoverColor=e.grey500}_interceptorCommands(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{const t={redos:[],undos:[]},n=this._getFreeze();if(!n)return t;const o=r=>{const s=this._currentUniverService.getCurrentUniverSheetInstance(),a=s.getUnitId(),d=s.getActiveSheet().getSheetId();this._refreshFreeze(r.startRow,r.startColumn,r.ySplit,r.xSplit,0);const u={...r,unitId:a,subUnitId:d,resetScroll:!1},h=_.SetFrozenMutationFactory(this._injector,u);return{undos:[{id:_.SetFrozenMutation.id,params:h}],redos:[{id:_.SetFrozenMutation.id,params:u}]}};if(e.id===_.MoveColsCommand.id){const r=this._selectionManagerService.getSelections(),{fromRange:{startColumn:s},toRange:{startColumn:a}}=e.params,c=r==null?void 0:r.filter(C=>C.range.rangeType===l.RANGE_TYPE.COLUMN&&C.range.startColumn<=s&&s<=C.range.endColumn);if(!(c!=null&&c.length))return t;const d=c[0].range,u={...d,startColumn:a,endColumn:a+d.endColumn-d.startColumn};if(!n||n.startColumn<=0||d.startColumn>=n.startColumn&&u.startColumn>=n.startColumn||d.startColumn===u.startColumn||d.endColumn<n.startColumn&&u.startColumn<n.startColumn)return t;const h=d.endColumn-d.startColumn+1,m=Math.max(Math.min(n.startColumn,d.endColumn+1)-d.startColumn,0);let g,S;u.startColumn>=n.startColumn?(g=Math.max(n.startColumn-m,1),S=Math.max(n.xSplit-m,1)):(g=n.startColumn+h-m,S=n.xSplit+h-m);const f={...n,startColumn:g,xSplit:S};return o(f)}if(e.id===_.MoveRowsCommand.id){const r=this._selectionManagerService.getSelections(),{fromRange:{startRow:s},toRange:{startRow:a}}=e.params,c=r==null?void 0:r.filter(C=>C.range.rangeType===l.RANGE_TYPE.ROW&&C.range.startRow<=s&&s<=C.range.endRow);if(!(c!=null&&c.length))return t;const d=c[0].range,u={...d,startRow:a,endRow:a+d.endRow-d.startRow};if(!n||n.startRow<=0||d.startRow>=n.startRow&&u.startRow>=n.startRow||d.startRow===u.startRow||d.endRow<n.startRow&&u.startRow<n.startRow)return t;const h=d.endRow-d.startRow+1,m=Math.max(Math.min(n.startRow,d.endRow+1)-d.startRow,0);let g,S;u.startRow>=n.startRow?(g=Math.max(n.startRow-m,1),S=Math.max(n.ySplit-m,1)):(g=n.startRow+h-m,S=n.ySplit+h-m);const f={...n,startRow:g,ySplit:S};return o(f)}if(e.id===_.RemoveColCommand.id||e.id===_.RemoveRowCommand.id){const r=e.params,s=r.range;if(s.rangeType===l.RANGE_TYPE.COLUMN&&s.startColumn<n.startColumn){const a=Math.min(n.startColumn,s.endColumn+1)-s.startColumn,c={...n,startColumn:Math.max(1,n.startColumn-a),xSplit:Math.max(1,n.xSplit-a)};return o(c)}if(r.range.rangeType===l.RANGE_TYPE.ROW&&s.startRow<n.startRow){const a=Math.min(n.startRow,s.endRow+1)-s.startRow,c={...n,startRow:Math.max(1,n.startRow-a),ySplit:Math.max(1,n.ySplit-a)};return o(c)}}return t}}))}_commandExecutedListener(){const e=[_.SetFrozenMutation.id,We.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=this._lastFreeze,o=this._currentUniverService.getCurrentUniverSheetInstance(),r=o.getActiveSheet(),s=t.params,{unitId:a,subUnitId:c}=s;if(!(a===o.getUnitId()&&c===r.getSheetId()))return;const d=r.getConfig().freeze;if(this._lastFreeze=d,d==null)return;let u=0;const{startRow:h=-1,startColumn:m=-1,ySplit:g=0,xSplit:S=0}=d;(!n||n.startRow!==h||n.ySplit!==g)&&(u|=2),(!n||n.startColumn!==m||n.xSplit!==S)&&(u|=1),s.resetScroll===!1&&(u=0),this._refreshFreeze(h,m,g,S,u)}else if(t.id===_.SetWorksheetRowHeightMutation.id){const n=this._getFreeze();t.params&&n&&t.params.ranges.some(o=>o.startRow<n.startRow)&&this._refreshCurrent()}else if(t.id===_.SetWorksheetColWidthMutation.id){const n=this._getFreeze();t.params&&n&&t.params.ranges.some(o=>o.startColumn<n.startColumn)&&this._refreshCurrent()}else if(t.id===_.SetWorksheetRowAutoHeightMutation.id){const n=t.params,o=this._getFreeze();if(o&&o.startRow>-1&&n.rowsAutoHeightInfo.some(r=>r.row<o.startRow)){const r=this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._refreshCurrent(),setTimeout(()=>{r.unsubscribe()})})}}else if(t.id===_.SetColHiddenMutation.id||t.id===_.SetColVisibleMutation.id){const n=t.params,o=this._getFreeze(),r=n.ranges;o&&o.startColumn>-1&&r.some(s=>s.startColumn<o.startColumn)&&this._refreshCurrent()}else if(t.id===_.SetRowHiddenMutation.id||t.id===_.SetRowVisibleMutation.id){const n=t.params,o=this._getFreeze(),r=n.ranges;o&&o.startRow>-1&&r.some(s=>s.startRow<o.startRow)&&this._refreshCurrent()}}))}_clearObserverEvent(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;t.onPointerMoveObserver.remove(this._moveObserver),t.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_clearFreeze(){var n,o,r,s;(n=this._rowFreezeHeaderRect)==null||n.dispose(),(o=this._rowFreezeMainRect)==null||o.dispose(),(r=this._columnFreezeHeaderRect)==null||r.dispose(),(s=this._columnFreezeMainRect)==null||s.dispose();const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;[...this._freezeDownObservers,...this._freezeMoveObservers,...this._freezeLeaveObservers].forEach(a=>{t.onPointerDownObserver.remove(a),t.onPointerMoveObserver.remove(a),t.onPointerLeaveObserver.remove(a)}),t.onPointerEnterObserver.remove(this._moveObserver),t.onPointerMoveObserver.remove(this._upObserver)}_getPositionByIndex(e,t){var c;if(this._getSheetObject()==null)return;const o=(c=this._sheetSkeletonManagerService.getCurrent())==null?void 0:c.skeleton,r=o==null?void 0:o.getNoMergeCellPositionByIndex(e,t);if(o==null)return;if(r!=null&&(!isNaN(r.endX)||!isNaN(r.endY)))return r;const{rowHeaderWidthAndMarginLeft:s,columnHeaderHeightAndMarginTop:a}=o;return{startX:s,endX:s,startY:a,endY:a}}_getFreeze(){var t;const e=(t=this._sheetSkeletonManagerService.getCurrent())==null?void 0:t.skeleton.getWorksheetConfig();if(e!=null)return e.freeze}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}_refreshFreeze(e,t,n,o,r){var a;const s={startRow:e,startColumn:t,ySplit:n,xSplit:o};this._clearFreeze(),this._createFreeze(0,s),this._createFreeze(1,s),this._updateViewport(e,t,n,o,r),(a=this._getSheetObject())==null||a.spreadsheet.makeForceDirty()}};In=ed([l.OnLifecycle(l.LifecycleStages.Rendered,In),Pe(0,D.Inject(exports.SheetSkeletonManagerService)),Pe(1,l.IUniverInstanceService),Pe(2,l.ICommandService),Pe(3,b.IRenderManagerService),Pe(4,_e),Pe(5,D.Inject(_.SelectionManagerService)),Pe(6,D.Inject(Je)),Pe(7,D.Inject(l.ThemeService)),Pe(8,D.Inject(_.SheetInterceptorService)),Pe(9,D.Inject(D.Injector))],In);var Ii=(i=>(i[i.NORMAL=0]="NORMAL",i[i.HIGHLIGHT=1]="HIGHLIGHT",i))(Ii||{});const sd="rgba(0, 0, 0, 0.15)",Be="rgb(0, 0, 0)",on="rgb(255, 255, 255, 1)";class ad extends b.Shape{constructor(t,n){super(t,n);v(this,"_size",12);v(this,"_iconRatio",.4);v(this,"_mode",0);this.setShapeProps(n)}setShapeProps(t){t!=null&&t.size&&(this._size=t.size),t!=null&&t.mode&&(this._mode=t.mode),this.transformByState({width:this._size,height:this._size})}_draw(t){this._mode===1&&b.Rect.drawWith(t,{width:this._size,height:this._size,radius:this._size,fill:sd});const n=this._size*.5*this._iconRatio,o=Math.PI/180*60,r=n*Math.sin(o),s=n*Math.cos(o);b.RegularPolygon.drawWith(t,{pointsGroup:[[{x:-r+this._size/2,y:-s+this._size/2},{x:r+this._size/2,y:-s+this._size/2},{x:this._size/2,y:n+this._size/2}]],fill:Be})}}var ld=Object.defineProperty,cd=Object.getOwnPropertyDescriptor,dd=(i,e,t,n)=>{for(var o=n>1?void 0:n?cd(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&ld(e,t,o),o},ut=(i,e)=>(t,n)=>e(t,n,i);const ud="__SpreadsheetHeaderMenuSHAPEControllerShape__",hd="__SpreadsheetHeaderMenuMAINControllerShape__",md="rgba(0, 0, 0, 0.1)";let Rn=class extends l.Disposable{constructor(e,t,n,o,r,s){super();v(this,"_hoverRect");v(this,"_hoverMenu");v(this,"_currentColumn",1/0);v(this,"_observers",[]);this._sheetSkeletonManagerService=e,this._currentUniverService=t,this._renderManagerService=n,this._contextMenuService=o,this._commandService=r,this._selectionManagerService=s,this._initialize()}dispose(){var o,r;(o=this._hoverRect)==null||o.dispose(),(r=this._hoverMenu)==null||r.dispose();const e=this._getSheetObject();if(e==null)return;const{spreadsheetRowHeader:t,spreadsheetColumnHeader:n}=e;this._observers.forEach(s=>{t.onPointerEnterObserver.remove(s),t.onPointerMoveObserver.remove(s),t.onPointerLeaveObserver.remove(s),n.onPointerEnterObserver.remove(s),n.onPointerMoveObserver.remove(s),n.onPointerLeaveObserver.remove(s)})}_initialize(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;this._hoverRect=new b.Rect(ud,{fill:md,evented:!1}),this._hoverMenu=new ad(hd,{zIndex:100,visible:!1}),t.addObjects([this._hoverRect,this._hoverMenu],qe),this._initialHover(0),this._initialHover(1),this._initialHoverMenu()}_initialHover(e=0){const t=this._getSheetObject();if(t==null)return;const{spreadsheetColumnHeader:n,spreadsheetRowHeader:o}=t,r=e===0?o:n;this._observers.push(r==null?void 0:r.onPointerEnterObserver.add(()=>{var s;(s=this._hoverRect)==null||s.show()})),this._observers.push(r==null?void 0:r.onPointerMoveObserver.add(s=>{var C,R,M;const a=(C=this._sheetSkeletonManagerService.getCurrent())==null?void 0:C.skeleton;if(a==null)return;const c=this._getSheetObject();if(c==null)return;const{rowHeaderWidth:d,columnHeaderHeight:u}=a,{startX:h,startY:m,endX:g,endY:S,column:f}=Mt(s.offsetX,s.offsetY,c.scene,a);if(e===0)(R=this._hoverRect)==null||R.transformByState({width:d,height:S-m,left:0,top:m});else{if(this._currentColumn=f,(M=this._hoverRect)==null||M.transformByState({width:g-h,height:u,left:h,top:0}),this._hoverMenu==null)return;if(g-h<u*2){this._hoverMenu.hide();return}const T=u*.8;this._hoverMenu.transformByState({left:g-u,top:u/2-T/2}),this._hoverMenu.setShapeProps({size:T}),this._hoverMenu.show()}})),this._observers.push(r==null?void 0:r.onPointerLeaveObserver.add(()=>{var s,a;(s=this._hoverRect)==null||s.hide(),(a=this._hoverMenu)==null||a.hide()}))}_initialHoverMenu(){this._hoverMenu!=null&&(this._hoverMenu.onPointerEnterObserver.add(()=>{if(this._hoverMenu==null)return;const e=this._getSheetObject();e!=null&&(this._hoverMenu.setProps({mode:Ii.HIGHLIGHT,visible:!0}),e.scene.setCursor(b.CURSOR_TYPE.POINTER))}),this._hoverMenu.onPointerLeaveObserver.add(()=>{if(this._hoverMenu==null)return;const e=this._getSheetObject();e!=null&&(this._hoverMenu.setProps({mode:Ii.NORMAL,visible:!1}),e.scene.resetCursor())}),this._hoverMenu.onPointerDownObserver.add(e=>{if(!this._getSheetObject())return;const n=this._currentColumn,o=this._selectionManagerService.getSelectionRanges();if(!!!(o!=null&&o.filter(s=>s.rangeType===l.RANGE_TYPE.COLUMN).find(s=>{const{startColumn:a,endColumn:c}=s;return n>=a&&n<=c}))){const s=this._getSelectionOnColumn(n);this._commandService.syncExecuteCommand(_.SetSelectionsOperation.id,s)}e.stopPropagation(),e.preventDefault(),this._contextMenuService.triggerContextMenu(e,de.COL_HEADER_CONTEXT_MENU)}))}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}_getSelectionOnColumn(e){const t=this._currentUniverService.getCurrentUniverSheetInstance(),n=t.getActiveSheet();return{unitId:t.getUnitId(),subUnitId:n.getSheetId(),pluginName:_.NORMAL_SELECTION_PLUGIN_NAME,selections:[{range:{startRow:0,startColumn:e,endRow:n.getRowCount()-1,endColumn:e,rangeType:l.RANGE_TYPE.COLUMN},primary:{startRow:0,startColumn:e,endRow:0,endColumn:e,actualRow:0,actualColumn:e,isMerged:!1,isMergedMainCell:!1},style:null}]}}};Rn=dd([l.OnLifecycle(l.LifecycleStages.Rendered,Rn),ut(0,D.Inject(exports.SheetSkeletonManagerService)),ut(1,l.IUniverInstanceService),ut(2,b.IRenderManagerService),ut(3,I.IContextMenuService),ut(4,l.ICommandService),ut(5,D.Inject(_.SelectionManagerService))],Rn);var gd=Object.defineProperty,Sd=Object.getOwnPropertyDescriptor,_d=(i,e,t,n)=>{for(var o=n>1?void 0:n?Sd(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&gd(e,t,o),o},ht=(i,e)=>(t,n)=>e(t,n,i);const fd="__SpreadsheetHeaderMoveControllerBackground__",pd="__SpreadsheetHeaderMoveControllerShapeLine__",vd="rgba(0, 0, 0, 0.1)",Cd="rgb(119, 119, 119)",Id=4;let Mn=class extends l.Disposable{constructor(e,t,n,o,r,s){super();v(this,"_startOffsetX",-1/0);v(this,"_startOffsetY",-1/0);v(this,"_moveHelperBackgroundShape");v(this,"_moveHelperLineShape");v(this,"_sheetObject");v(this,"_rowOrColumnDownObservers",[]);v(this,"_rowOrColumnMoveObservers",[]);v(this,"_rowOrColumnLeaveObservers",[]);v(this,"_moveObserver");v(this,"_upObserver");v(this,"_scrollTimer");v(this,"_changeFromColumn",-1);v(this,"_changeFromRow",-1);v(this,"_changeToColumn",-1);v(this,"_changeToRow",-1);this._sheetSkeletonManagerService=e,this._currentUniverService=t,this._renderManagerService=n,this._commandService=o,this._selectionRenderService=r,this._selectionManagerService=s,this._initialize()}dispose(){var r,s;(r=this._moveHelperBackgroundShape)==null||r.dispose(),(s=this._moveHelperLineShape)==null||s.dispose();const e=this._getSheetObject();if(e==null)return;const{spreadsheetRowHeader:t,spreadsheetColumnHeader:n,scene:o}=e;[...this._rowOrColumnDownObservers,...this._rowOrColumnMoveObservers,...this._rowOrColumnLeaveObservers].forEach(a=>{t.onPointerDownObserver.remove(a),n.onPointerDownObserver.remove(a)}),o.onPointerMoveObserver.remove(this._moveObserver),o.onPointerUpObserver.remove(this._upObserver),this._scrollTimer.dispose()}_initialize(){const e=this._getSheetObject();e!=null&&(this._sheetObject=e,this._initialRowOrColumn(0),this._initialRowOrColumn(1))}_initialRowOrColumn(e=0){const{spreadsheetColumnHeader:t,spreadsheetRowHeader:n,scene:o}=this._sheetObject,r=e===0?n:t;this._rowOrColumnMoveObservers.push(r==null?void 0:r.onPointerMoveObserver.add(s=>{var h;const a=(h=this._sheetSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(a==null)return;const{row:c,column:d}=Mt(s.offsetX,s.offsetY,o,a);if(this._checkInHeaderRange(e===0?c:d,e)===!1){o.resetCursor(),this._selectionRenderService.enableSelection();return}o.setCursor(b.CURSOR_TYPE.GRAB),this._selectionRenderService.disableSelection()})),this._rowOrColumnLeaveObservers.push(r==null?void 0:r.onPointerLeaveObserver.add(()=>{var s,a;(s=this._moveHelperBackgroundShape)==null||s.hide(),(a=this._moveHelperLineShape)==null||a.hide(),o.resetCursor(),this._selectionRenderService.enableSelection()})),this._rowOrColumnDownObservers.push(r==null?void 0:r.onPointerDownObserver.add(s=>{var E;const a=(E=this._sheetSkeletonManagerService.getCurrent())==null?void 0:E.skeleton;if(a==null)return;const{offsetX:c,offsetY:d}=s,u=o.getRelativeCoord(b.Vector2.FromArray([c,d])),{x:h,y:m}=u;this._startOffsetX=h,this._startOffsetY=m;const{row:g,column:S}=Mt(s.offsetX,s.offsetY,o,a);let f;e===0?(this._changeFromRow=g,f=b.ScrollTimerType.Y):(this._changeFromColumn=S,f=b.ScrollTimerType.X);const C=this._checkInHeaderRange(e===0?g:S,e);if(C===!1)return;const R=o.getScrollXYByRelativeCoords(b.Vector2.FromArray([this._startOffsetX,this._startOffsetY]));this._newBackgroundAndLine(),o.setCursor(b.CURSOR_TYPE.GRABBING),o.disableEvent();let M=!1,T;const w=()=>{if(M)return;T=b.ScrollTimer.create(o,f);const y=o.getViewport(V.VIEW_MAIN);T.startScroll(h,m,y),this._scrollTimer=T,M=!0};this._moveObserver=o.onPointerMoveObserver.add(y=>{w();const{offsetX:x,offsetY:O}=y,{x:A,y:k}=o.getRelativeCoord(b.Vector2.FromArray([x,O]));o.setCursor(b.CURSOR_TYPE.GRABBING),this._rowColumnMoving(A,k,C,R,e),T.scrolling(A,k,()=>{this._rowColumnMoving(A,k,C,R,e)})}),this._upObserver=o.onPointerUpObserver.add(()=>{var x,O,A;this._disposeBackgroundAndLine(),o.resetCursor(),o.enableEvent(),this._clearObserverEvent(),(x=this._scrollTimer)==null||x.dispose();const y=this._selectionManagerService.getSelections();if(e===0){if(this._changeFromRow!==this._changeToRow&&this._changeToRow!==-1){const N=(O=((y==null?void 0:y.filter(B=>B.range.rangeType===l.RANGE_TYPE.ROW&&B.range.startRow<=this._changeFromRow&&this._changeFromRow<=B.range.endRow))||[])[0])==null?void 0:O.range;N&&this._commandService.executeCommand(_.MoveRowsCommand.id,{fromRange:N,toRange:{...N,startRow:this._changeToRow,endRow:this._changeToRow+N.endRow-N.startRow}})}this._changeToRow=this._changeFromRow=-1}else{if(this._changeFromColumn!==this._changeToColumn&&this._changeToColumn!==-1){const N=(A=((y==null?void 0:y.filter(B=>B.range.rangeType===l.RANGE_TYPE.COLUMN&&B.range.startColumn<=this._changeFromColumn&&this._changeFromColumn<=B.range.endColumn))||[])[0])==null?void 0:A.range;N&&this._commandService.executeCommand(_.MoveColsCommand.id,{fromRange:N,toRange:{...N,startColumn:this._changeToColumn,endColumn:this._changeToColumn+N.endColumn-N.startColumn}})}this._changeToColumn=this._changeFromColumn=-1}})}))}_rowColumnMoving(e,t,n,o,r){var Q,re,Y,L,U,X,j;const{scene:s}=this._sheetObject,a=(Q=this._sheetSkeletonManagerService.getCurrent())==null?void 0:Q.skeleton;if(a==null)return;const{rowHeaderWidth:c,columnHeaderHeight:d,rowTotalHeight:u,columnTotalWidth:h}=a,m=s.getScrollXY(s.getViewport(V.VIEW_MAIN)),{scaleX:g,scaleY:S}=s.getAncestorScale(),f=a.getCellPositionByOffset(e,t,g,S,m),{row:C,column:R}=f,M=a.getNoMergeCellPositionByIndex(C,R),{startX:T,startY:w,endX:E,endY:y}=M,x=this._selectionRenderService.convertRangeDataToSelection(n.range);if(x==null)return;const O=Math.max(g,g),{startX:A,endX:k,startY:N,endY:B,startRow:F,startColumn:W,endRow:$,endColumn:Z}=x;r===0?(re=this._moveHelperBackgroundShape)==null||re.transformByState({height:B-N,width:h+c,left:0,top:N+(t-this._startOffsetY)/O+m.y-o.y}):(Y=this._moveHelperBackgroundShape)==null||Y.transformByState({height:u+d,width:k-A,left:A+(e-this._startOffsetX)/O+m.x-o.x,top:0}),(L=this._moveHelperBackgroundShape)==null||L.show();const z=Id/O;if(r===0){let oe=0;if(C<=F)oe=w-z/2,this._changeToRow=C;else if(C>$)oe=y-z/2,this._changeToRow=C+1;else return;(U=this._moveHelperLineShape)==null||U.transformByState({height:z,width:h,left:c,top:oe})}else{let oe=0;if(R<=W)oe=T-z/2,this._changeToColumn=R;else if(R>Z)oe=E-z/2,this._changeToColumn=R+1;else return;(X=this._moveHelperLineShape)==null||X.transformByState({height:u,width:z,left:oe,top:d})}(j=this._moveHelperLineShape)==null||j.show()}_checkInHeaderRange(e,t=0){var a;const n=this._selectionManagerService.getSelections();if(((a=this._selectionManagerService.getCurrent())==null?void 0:a.pluginName)!==_.NORMAL_SELECTION_PLUGIN_NAME)return!1;const r=n==null?void 0:n.find(c=>{const d=c.range,{startRow:u,endRow:h,startColumn:m,endColumn:g,rangeType:S}=d;return t===1?e>=m&&e<=g&&l.RANGE_TYPE.COLUMN===S:e>=u&&e<=h&&l.RANGE_TYPE.ROW===S}),s=r==null?void 0:r.range;return r==null||s==null||s.rangeType===l.RANGE_TYPE.ALL||s.rangeType===l.RANGE_TYPE.NORMAL||s.rangeType===l.RANGE_TYPE.ROW&&t!==0||s.rangeType===l.RANGE_TYPE.COLUMN&&t!==1?!1:r}_clearObserverEvent(){const{scene:e}=this._sheetObject;e.onPointerMoveObserver.remove(this._moveObserver),e.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_newBackgroundAndLine(){const{scene:e}=this._sheetObject;this._moveHelperBackgroundShape=new b.Rect(fd,{fill:vd,evented:!1,zIndex:100}),this._moveHelperLineShape=new b.Rect(pd,{fill:Cd,evented:!1,zIndex:100}),e.addObjects([this._moveHelperBackgroundShape,this._moveHelperLineShape],qe)}_disposeBackgroundAndLine(){var e,t;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(t=this._moveHelperLineShape)==null||t.dispose()}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}};Mn=_d([l.OnLifecycle(l.LifecycleStages.Rendered,Mn),ht(0,D.Inject(exports.SheetSkeletonManagerService)),ht(1,l.IUniverInstanceService),ht(2,b.IRenderManagerService),ht(3,l.ICommandService),ht(4,_e),ht(5,D.Inject(_.SelectionManagerService))],Mn);var Ri=(i=>(i[i.VERTICAL=0]="VERTICAL",i[i.HORIZONTAL=1]="HORIZONTAL",i))(Ri||{});const Rd="rgba(120, 120, 120, 0.01)",si="rgb(68, 71, 70)",Ut=12,Mi=4;class vo extends b.Shape{constructor(t,n){super(t,n);v(this,"_size",Ut);v(this,"_color",si);v(this,"_mode",0);this.setShapeProps(n)}get size(){return this._size}get mode(){return this._mode}get color(){return this._color}_draw(t){let{width:n,height:o}=this,r=0,s=0;const a=this.getScene(),{scaleX:c,scaleY:d}=a.getAncestorScale(),u=Math.max(c,d),h=Ut/u,m=Mi/u;this.mode===0?(n=m,r=h-m):(o=m,s=h-m),b.Rect.drawWith(t,{width:this.width,height:this.height,left:0,top:0,fill:Rd}),b.Rect.drawWith(t,{width:n,height:o,fill:si,radius:m}),t.save(),t.transform(1,0,0,1,r,s),b.Rect.drawWith(t,{width:n,height:o,fill:si,radius:m}),t.restore()}setShapeProps(t){return t!=null&&t.size&&(this._size=t.size),t!=null&&t.mode&&(this._mode=t.mode),t!=null&&t.color&&(this._color=t.color),this.mode===0?this.transformByState({width:Ut,height:this.size}):this.transformByState({width:this.size,height:Ut}),this}}var Md=Object.defineProperty,bd=Object.getOwnPropertyDescriptor,wd=(i,e,t,n)=>{for(var o=n>1?void 0:n?bd(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Md(e,t,o),o},Ht=(i,e)=>(t,n)=>e(t,n,i);const Td="__SpreadsheetHeaderResizeControllerShapeRow__",Ed="__SpreadsheetHeaderResizeControllerShapeColumn__",Co="__SpreadsheetHeaderResizeControllerShapeHelper__",Io="rgb(199, 199, 199)",yd=2;let bn=class extends l.Disposable{constructor(e,t,n,o,r){super();v(this,"_currentRow",0);v(this,"_currentColumn",0);v(this,"_rowResizeRect");v(this,"_columnResizeRect");v(this,"_observers",[]);v(this,"_moveObserver");v(this,"_upObserver");v(this,"_resizeHelperShape");v(this,"_startOffsetX",1/0);v(this,"_startOffsetY",1/0);this._sheetSkeletonManagerService=e,this._currentUniverService=t,this._commandService=n,this._renderManagerService=o,this._editorBridgeService=r,this._initialize()}dispose(){var o,r;(o=this._rowResizeRect)==null||o.dispose(),this._rowResizeRect=null,(r=this._columnResizeRect)==null||r.dispose(),this._columnResizeRect=null;const e=this._getSheetObject();if(e==null)return;const{spreadsheetRowHeader:t,spreadsheetColumnHeader:n}=e;this._observers.forEach(s=>{t.onPointerMoveObserver.remove(s),t.onPointerLeaveObserver.remove(s),n.onPointerMoveObserver.remove(s),n.onPointerLeaveObserver.remove(s)}),this._observers=[]}_initialize(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;this._rowResizeRect=new vo(Td,{visible:!1,mode:Ri.HORIZONTAL,zIndex:100}),this._columnResizeRect=new vo(Ed,{visible:!1,mode:Ri.VERTICAL,zIndex:100}),t.addObjects([this._rowResizeRect,this._columnResizeRect],qe),this._initialHover(0),this._initialHover(1),this._initialHoverResize(0),this._initialHoverResize(1)}_initialHover(e=0){const t=this._getSheetObject();if(t==null)return;const{spreadsheetRowHeader:n,spreadsheetColumnHeader:o,scene:r}=t,s=e===0?n:o;this._observers.push(s==null?void 0:s.onPointerMoveObserver.add((a,c)=>{var x;const d=(x=this._sheetSkeletonManagerService.getCurrent())==null?void 0:x.skeleton;if(d==null||this._rowResizeRect==null||this._columnResizeRect==null)return;const{rowHeaderWidth:u,columnHeaderHeight:h}=d,{startX:m,startY:g,endX:S,endY:f,row:C,column:R}=Mt(a.offsetX,a.offsetY,r,d),M=ln(a.offsetX,a.offsetY,r),{scaleX:T,scaleY:w}=r.getAncestorScale(),E=Math.max(T,w),y=Ut/E;if(e===0){let O=g-y/2;if(M.y<=g+y/2&&M.y>=g)this._currentRow=C-1;else if(M.y>=f-y/2&&M.y<=f)this._currentRow=C,O=f-y/2;else{this._rowResizeRect.hide();return}if(this._currentRow===-1)return;const A=u/3;this._rowResizeRect.transformByState({left:u/2-A/2,top:O}),this._rowResizeRect.setShapeProps({size:A}),this._rowResizeRect.show()}else{let O=m-y/2;if(M.x<=m+y/2&&M.x>=m)this._currentColumn=R-1;else if(M.x>=S-y/2&&M.x<=S)this._currentColumn=R,O=S-y/2;else{this._columnResizeRect.hide();return}if(this._currentColumn===-1)return;const A=h*.7;this._columnResizeRect.transformByState({left:O,top:h/2-A/2}),this._columnResizeRect.setShapeProps({size:A}),this._columnResizeRect.show()}})),this._observers.push(s==null?void 0:s.onPointerLeaveObserver.add((a,c)=>{var d,u;(d=this._rowResizeRect)==null||d.hide(),(u=this._columnResizeRect)==null||u.hide()}))}_initialHoverResize(e=0){const t=this._getSheetObject();if(t==null)return;const{scene:n}=t,o=e===0?this._rowResizeRect:this._columnResizeRect;if(o==null)return;const r=n.getEngine(),s=(r==null?void 0:r.width)||0,a=(r==null?void 0:r.height)||0;this.disposeWithMe(l.toDisposable(o.onPointerEnterObserver.add(()=>{o!=null&&(o.show(),n.setCursor(e===0?b.CURSOR_TYPE.ROW_RESIZE:b.CURSOR_TYPE.COLUMN_RESIZE))}))),this.disposeWithMe(l.toDisposable(o.onPointerLeaveObserver.add(()=>{o!=null&&(o.hide(),n.resetCursor())}))),this.disposeWithMe(l.toDisposable(o.onPointerDownObserver.add((c,d)=>{var re,Y,L,U,X,j,oe;const u=(re=this._sheetSkeletonManagerService.getCurrent())==null?void 0:re.skeleton;if(u==null)return;const h=this._getSheetObject();if(h==null)return;const{scene:m}=h,g=m.getViewport(V.VIEW_MAIN),S=(((L=(Y=g==null?void 0:g.getScrollBar())==null?void 0:Y.horizonBarRect)==null?void 0:L.height)||0)+10,f=(((X=(U=g==null?void 0:g.getScrollBar())==null?void 0:U.verticalBarRect)==null?void 0:X.width)||0)+10,C=ln(c.offsetX,c.offsetY,m),{scaleX:R,scaleY:M}=m.getAncestorScale();this._startOffsetX=C.x,this._startOffsetY=C.y;const T=u.getOffsetByPositionX(this._currentColumn),w=u.getOffsetByPositionY(this._currentRow),E=u.getNoMergeCellPositionByIndex(this._currentRow,this._currentColumn);let y=!1,x=0,O=0;const{columnTotalWidth:A,rowHeaderWidth:k,rowTotalHeight:N,columnHeaderHeight:B}=u,F=s>A+k?s:A+k,W=a>N+B?a:N+B,$=Math.max(R,M),Z=Mi/$;e===0?this._resizeHelperShape=new b.Rect(Co,{width:F,height:Z,fill:Io,left:0,top:w-Z/2}):this._resizeHelperShape=new b.Rect(Co,{width:Z,height:W,fill:Io,left:T-Z/2,top:0});const z=((j=this._columnResizeRect)==null?void 0:j.left)||0,Q=((oe=this._rowResizeRect)==null?void 0:oe.top)||0;m.addObject(this._resizeHelperShape,qe),m.disableEvent(),this._editorBridgeService.changeVisible({visible:!1,eventType:b.DeviceInputEventType.PointerDown}),this._moveObserver=m.onPointerMoveObserver.add(G=>{var lt,ct,Ce,ze,Re,xe;const q=m.getRelativeCoord(b.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),ee=m.getScrollXYByRelativeCoords(q,g),ae=ln(G.offsetX,G.offsetY,m),{x:se,y:ce}=ae,{scaleX:he,scaleY:le}=m.getAncestorScale(),$e=Math.max(he,le),ge=Mi/$e;x=se-this._startOffsetX-ge/2,O=ce-this._startOffsetY-ge/2,Math.abs(e===0?O:x)>=yd&&(y=!0),e===0?(O>a-S+ee.y-E.startY&&(O=a-S+ee.y-E.startY),O<-(E.endY-E.startY)+2&&(O=-(E.endY-E.startY)+2),y&&((lt=this._resizeHelperShape)==null||lt.transformByState({top:w+O}),(ct=this._rowResizeRect)==null||ct.transformByState({top:Q+O+ge/2}),(Ce=this._rowResizeRect)==null||Ce.show(),m.setCursor(b.CURSOR_TYPE.ROW_RESIZE))):(x>s-f+ee.x-E.startX&&(x=s-f+ee.x-E.startX),x<-(E.endX-E.startX)+2&&(x=-(E.endX-E.startX)+2),y&&((ze=this._resizeHelperShape)==null||ze.transformByState({left:T+x}),(Re=this._columnResizeRect)==null||Re.transformByState({left:z+x+ge/2}),(xe=this._columnResizeRect)==null||xe.show(),m.setCursor(b.CURSOR_TYPE.COLUMN_RESIZE)))}),this._upObserver=m.onPointerUpObserver.add(G=>{var ae,se,ce;const q=ve(this._currentUniverService,this._renderManagerService);if(q==null)return;this._clearObserverEvent(),(ae=this._resizeHelperShape)==null||ae.dispose(),this._resizeHelperShape=null;const{scene:ee}=q;ee.enableEvent(),y&&(ee.resetCursor(),(se=this._rowResizeRect)==null||se.hide(),(ce=this._columnResizeRect)==null||ce.hide(),e===0?this._commandService.executeCommand(_.DeltaRowHeightCommand.id,{deltaY:O,anchorRow:this._currentRow}):this._commandService.executeCommand(_.DeltaColumnWidthCommand.id,{deltaX:x,anchorCol:this._currentColumn}))})}))),this.disposeWithMe(l.toDisposable(o.onDblclickObserver.add(()=>{var c;if(e===0){const d=this._getSheetObject();if(d==null)return;const{scene:u}=d;u.resetCursor(),this._commandService.executeCommand(_.SetWorksheetRowIsAutoHeightCommand.id,{anchorRow:this._currentRow}),(c=this._rowResizeRect)==null||c.hide()}})))}_clearObserverEvent(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;t.onPointerMoveObserver.remove(this._moveObserver),t.onPointerUpObserver.remove(this._upObserver),this._moveObserver=null,this._upObserver=null}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}};bn=wd([l.OnLifecycle(l.LifecycleStages.Rendered,bn),Ht(0,D.Inject(exports.SheetSkeletonManagerService)),Ht(1,l.IUniverInstanceService),Ht(2,l.ICommandService),Ht(3,b.IRenderManagerService),Ht(4,Ee)],bn);var bi=(i=>(i[i.ROW=0]="ROW",i[i.COLUMN=1]="COLUMN",i))(bi||{});const kt=12,Od=.4;class Ro extends b.Shape{constructor(t,n,o){super(t,n);v(this,"_size",kt);v(this,"_iconRatio",Od);v(this,"_hovered",!0);v(this,"_hasPrevious",!0);v(this,"_hasNext",!0);v(this,"_unhideType");n&&this.setShapeProps(n),this.onPointerEnterObserver.add(()=>this.setShapeProps({hovered:!0})),this.onPointerLeaveObserver.add(()=>this.setShapeProps({hovered:!1})),this.onPointerDownObserver.add(()=>o==null?void 0:o())}setShapeProps(t){t.type!==void 0&&(this._unhideType=t.type),t.hovered!==void 0&&(this._hovered=t.hovered),t.hasPrevious!==void 0&&(this._hasPrevious=t.hasPrevious),t.hasNext!==void 0&&(this._hasNext=t.hasNext),this.transformByState({width:this._size*(this._unhideType===1?2:1),height:this._size*(this._unhideType===0?2:1)})}_draw(t){this._unhideType===0?this._drawOnRow(t):this._drawOnCol(t)}_drawOnRow(t){this._hovered&&(!this._hasNext||!this._hasPrevious?b.Rect.drawWith(t,{width:this._size,height:this._size,stroke:Be,fill:on}):b.Rect.drawWith(t,{width:this._size,height:2*this._size,stroke:Be,fill:on}));const n=this._size*.5*this._iconRatio,o=Math.PI/3,r=n*Math.cos(o),s=n*Math.sin(o);if(this._hasPrevious&&b.RegularPolygon.drawWith(t,{pointsGroup:[[{x:this._size/2,y:this._size/2-s},{x:this._size/2-s,y:this._size/2+r},{x:this._size/2+s,y:this._size/2+r}]],fill:Be}),this._hasNext){const a=this._hasPrevious?3:1;b.RegularPolygon.drawWith(t,{pointsGroup:[[{x:this._size/2,y:this._size*a/2+s},{x:this._size/2-s,y:this._size*a/2-r},{x:this._size/2+s,y:this._size*a/2-r}]],fill:Be})}}_drawOnCol(t){this._hovered&&(!this._hasNext||!this._hasPrevious?b.Rect.drawWith(t,{width:this._size,height:this._size,stroke:Be,fill:on}):b.Rect.drawWith(t,{width:2*this._size,height:this._size,stroke:Be,fill:on}));const n=this._size*.5*this._iconRatio,o=Math.PI/3,r=n*Math.cos(o),s=n*Math.sin(o);if(this._hasPrevious&&b.RegularPolygon.drawWith(t,{pointsGroup:[[{x:-r+this._size/2,y:this._size/2},{x:this._size/2+s,y:this._size/2-s},{x:this._size/2+s,y:this._size/2+s}]],fill:Be}),this._hasNext){const a=this._hasPrevious?3:1;b.RegularPolygon.drawWith(t,{pointsGroup:[[{x:r+this._size*a/2,y:this._size/2},{x:-s+this._size*a/2,y:this._size/2-s},{x:-s+this._size*a/2,y:this._size/2+s}]],fill:Be})}}}var xd=Object.defineProperty,Ad=Object.getOwnPropertyDescriptor,Dd=(i,e,t,n)=>{for(var o=n>1?void 0:n?Ad(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&xd(e,t,o),o},rn=(i,e)=>(t,n)=>e(t,n,i);const Mo="__SpreadsheetHeaderUnhideSHAPEControllerShape__",Nd=[_.SetRowHiddenMutation.id,_.SetRowVisibleMutation.id,_.SetColHiddenMutation.id,_.SetColVisibleMutation.id];let wn=class extends l.RxDisposable{constructor(e,t,n,o){super();v(this,"_shapes",new Map);this._sheetSkeletonManagerService=e,this._cmdSrv=t,this._univerInstanceService=n,this._rendererManagerService=o,this._init()}dispose(){super.dispose()}_init(){if(!this._getSheetObject())return;const t=this._univerInstanceService.getCurrentUniverSheetInstance(),n=t.getActiveSheet();n&&this._initForWorksheet(t,n),this._sheetSkeletonManagerService.currentSkeleton$.pipe(H.takeUntil(this.dispose$),H.startWith(void 0),H.pairwise()).subscribe(([o,r])=>{if(r){const s=this._univerInstanceService.getUniverSheetInstance(r.unitId),a=s.getSheetBySheetId(r.sheetId);this._updateWorksheet(s,a,o==null?void 0:o.sheetId)}}),this.disposeWithMe(this._cmdSrv.onCommandExecuted(o=>{if(!Nd.includes(o.id)||!o.params||!o.params.unitId||!o.params.subUnitId)return;const r=this._univerInstanceService.getUniverSheetInstance(o.params.unitId),s=r==null?void 0:r.getSheetBySheetId(o.params.subUnitId);s&&this._updateWorksheet(r,s,s.getSheetId())}))}_initForWorksheet(e,t){var m;const n=(m=this._sheetSkeletonManagerService.getCurrent())==null?void 0:m.skeleton;if(!n)return;const o=t.getHiddenRows(),r=t.getHiddenCols(),s=this._getSheetObject();if(!s)return;const{scene:a}=s,c=t.getRowCount(),d=o.map(g=>{const{startRow:S,endRow:f}=g,C=Ci(S,0,a,n),R=S!==0,M=f!==c-1;return new Ro(Mo,{type:bi.ROW,hovered:!1,hasPrevious:R,hasNext:M,top:C.startY-(R?kt:0),left:C.startX-kt},()=>this._cmdSrv.executeCommand(_.SetSpecificRowsVisibleCommand.id,{unitId:e.getUnitId(),subUnitId:t.getSheetId(),ranges:[g]}))}),u=t.getColumnCount(),h=r.map(g=>{const{startColumn:S,endColumn:f}=g,C=Ci(0,S,a,n),R=S!==0,M=f!==u-1;return new Ro(Mo,{type:bi.COLUMN,hovered:!1,hasPrevious:R,hasNext:M,left:C.startX-(R?kt:0),top:20-kt},()=>this._cmdSrv.executeCommand(_.SetSpecificColsVisibleCommand.id,{unitId:e.getUnitId(),subUnitId:t.getSheetId(),ranges:[g]}))});a.addObjects(h,Ji),a.addObjects(d,Ji),this._shapes.set(l.getWorksheetUID(e,t),{cols:h,rows:d})}_updateWorksheet(e,t,n){if(n){const o=this._shapes.get(`${e.getUnitId()}|${n}`);o==null||o.cols.forEach(r=>r.dispose()),o==null||o.rows.forEach(r=>r.dispose())}this._initForWorksheet(e,t)}_getSheetObject(){return ve(this._univerInstanceService,this._rendererManagerService)}};wn=Dd([l.OnLifecycle(l.LifecycleStages.Rendered,wn),rn(0,D.Inject(exports.SheetSkeletonManagerService)),rn(1,l.ICommandService),rn(2,l.IUniverInstanceService),rn(3,b.IRenderManagerService)],wn);var Pd=Object.defineProperty,Hd=Object.getOwnPropertyDescriptor,Ld=(i,e,t,n)=>{for(var o=n>1?void 0:n?Hd(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Pd(e,t,o),o},ai=(i,e)=>(t,n)=>e(t,n,i);let Tn=class extends l.Disposable{constructor(i,e,t){super(),this._markSelectionService=i,this._commandService=e,this._sheetSkeletonManagerService=t,this._initListeners()}_initListeners(){this._addRemoveListener(),this._addRefreshListener()}_addRemoveListener(){const i=[He.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{i.includes(e.id)?this._markSelectionService.removeAllShapes():this._markSelectionService.getShapeMap().forEach((n,o)=>{n.exits.includes(e.id)&&this._markSelectionService.removeShape(o)})}))}_addRefreshListener(){this.disposeWithMe(l.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{i&&this._markSelectionService.refreshShapes()})))}};Tn=Ld([l.OnLifecycle(l.LifecycleStages.Steady,Tn),ai(0,D.Inject(Xt)),ai(1,l.ICommandService),ai(2,D.Inject(exports.SheetSkeletonManagerService))],Tn);var Ud=Object.defineProperty,kd=Object.getOwnPropertyDescriptor,Vd=(i,e,t,n)=>{for(var o=n>1?void 0:n?kd(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Ud(e,t,o),o},li=(i,e)=>(t,n)=>e(t,n,i);let En=class extends l.Disposable{constructor(e,t,n){super();v(this,"_initialize",()=>{const e=new l.DisposableCollection;this.disposeWithMe(l.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(()=>{e.dispose();const t=this._selectionManagerService.getCurrent();if((t==null?void 0:t.pluginName)!==_.NORMAL_SELECTION_PLUGIN_NAME)return;this._selectionRenderService.getCurrentControls().forEach(o=>{e.add(l.toDisposable(o.selectionMoved$.subscribe(r=>{if(!r)return;const s=o.model.getRange(),a={startRow:s.startRow,startColumn:s.startColumn,endRow:s.endRow,endColumn:s.endColumn,rangeType:s.rangeType},c={startRow:r.startRow,startColumn:r.startColumn,endRow:r.endRow,endColumn:r.endColumn,rangeType:s.rangeType};if(a.startRow===c.startRow&&a.startColumn===c.startColumn||c.startRow<0||c.startColumn<0)return;const d={fromRange:a,toRange:c};this._commandService.executeCommand(_.MoveRangeCommand.id,d)})))})})))});this._selectionRenderService=e,this._selectionManagerService=t,this._commandService=n,this._initialize()}};En=Vd([l.OnLifecycle(l.LifecycleStages.Steady,En),li(0,D.Inject(_e)),li(1,D.Inject(_.SelectionManagerService)),li(2,D.Inject(l.ICommandService))],En);var Bd=Object.defineProperty,Fd=Object.getOwnPropertyDescriptor,Wd=(i,e,t,n)=>{for(var o=n>1?void 0:n?Fd(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Bd(e,t,o),o},mt=(i,e)=>(t,n)=>e(t,n,i);let Ct=class extends l.Disposable{constructor(i,e,t,n,o,r){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._selectionManagerService=o,this._scrollManagerService=r,this._initialize()}scrollToVisible(i=!0){var B,F,W;let e,t;const n=this._selectionManagerService.getLast();if(n==null)return;const{startRow:o,startColumn:r,actualRow:s,actualColumn:a}=n.primary,c=i?s:o,d=i?a:r,{rowHeightAccumulation:u,columnWidthAccumulation:h}=((B=this._sheetSkeletonManagerService.getCurrent())==null?void 0:B.skeleton)??{};if(u==null||h==null)return;const m=(F=this._getSheetObject())==null?void 0:F.scene;if(m==null)return;const g=m.getViewport(V.VIEW_MAIN);if(g==null||this._getSheetObject()==null)return;const f=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet(),{startColumn:C,startRow:R,ySplit:M,xSplit:T}=f.getFreeze(),w=g.getBounding(),E=(W=this._sheetSkeletonManagerService.getCurrent())==null?void 0:W.skeleton;if(E==null)return;const{startRow:y,startColumn:x,endRow:O,endColumn:A}=E.getRowColumnSegment(w);if(c>=R&&d>=C-T&&(c<=y&&(e=c),c>=O)){const $=u[c]-g.height;for(let Z=y;Z<=c;Z++)if(u[Z]>=$){e=Z+1;break}}if(d>=C&&c>=R-M&&(d<=x&&(t=d),d>=A)){const $=h[d]-g.width;for(let Z=x;Z<=d;Z++)if(h[Z]>=$){t=Z+1;break}}if(e===void 0&&t===void 0)return;const{offsetX:k,offsetY:N}=this._scrollManagerService.getCurrentScroll()||{};this._commandService.executeCommand(vt.id,{sheetViewStartRow:e,sheetViewStartColumn:t,offsetX:t===void 0?k:0,offsetY:e===void 0?N:0})}dispose(){super.dispose()}_initialize(){this._scrollEventBinding(),this._scrollSubscribeBinding(),this._skeletonListener()}_getFreeze(){var e;const i=(e=this._sheetSkeletonManagerService.getCurrent())==null?void 0:e.skeleton.getWorksheetConfig();if(i!=null)return i.freeze}_scrollEventBinding(){var t;const i=(t=this._getSheetObject())==null?void 0:t.scene;if(i==null)return;const e=i.getViewport(V.VIEW_MAIN);this.disposeWithMe(l.toDisposable(e==null?void 0:e.onScrollAfterObserver.add(n=>{var m;const o=(m=this._sheetSkeletonManagerService.getCurrent())==null?void 0:m.skeleton;if(o==null||n.isTrigger===!1)return;const r=this._getSheetObject();if(o==null||r==null)return;const{actualScrollX:s=0,actualScrollY:a=0}=n,{row:c,column:d,rowOffset:u,columnOffset:h}=o.getDecomposedOffset(s,a);this._scrollManagerService.addOrReplaceNoRefresh({sheetViewStartRow:c,sheetViewStartColumn:d,offsetX:h,offsetY:u})}))),this.disposeWithMe(l.toDisposable(e==null?void 0:e.onScrollByBarObserver.add(n=>{var g;const o=(g=this._sheetSkeletonManagerService.getCurrent())==null?void 0:g.skeleton;if(o==null||n.isTrigger===!1)return;const r=this._getSheetObject();if(o==null||r==null)return;const{actualScrollX:s=0,actualScrollY:a=0}=n,c=this._getFreeze(),{row:d,column:u,rowOffset:h,columnOffset:m}=o.getDecomposedOffset(s,a);this._commandService.executeCommand(vt.id,{sheetViewStartRow:d+((c==null?void 0:c.ySplit)||0),sheetViewStartColumn:u+((c==null?void 0:c.xSplit)||0),offsetX:m,offsetY:h})})))}_scrollSubscribeBinding(){this.disposeWithMe(l.toDisposable(this._scrollManagerService.scrollInfo$.subscribe(i=>{var S;const e=(S=this._sheetSkeletonManagerService.getCurrent())==null?void 0:S.skeleton,t=this._getSheetObject();if(e==null||t==null)return;const n=t.scene;t.scene.getAncestorScale();const o=n.getViewport(V.VIEW_MAIN);if(o==null)return;if(i==null){o.scrollTo({x:0,y:0});return}const{sheetViewStartRow:r,sheetViewStartColumn:s,offsetX:a,offsetY:c}=i,{startX:d,startY:u}=e.getCellByIndexWithNoHeader(r,s),h=d+a,m=u+c,g=o.getBarScroll(h,m);o.scrollTo(g)})))}_skeletonListener(){this.disposeWithMe(l.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{unitId:e,sheetId:t}=i;this._renderManagerService.getRenderById(e)!=null&&(this._updateSceneSize(i),this._scrollManagerService.setCurrentScroll({unitId:e,sheetId:t}))})))}_updateSceneSize(i){var c;if(i==null)return;const{skeleton:e,unitId:t}=i,n=(c=this._renderManagerService.getRenderById(t))==null?void 0:c.scene;if(e==null||n==null)return;const{rowTotalHeight:o,columnTotalWidth:r,rowHeaderWidthAndMarginLeft:s,columnHeaderHeightAndMarginTop:a}=e;n==null||n.transformByState({width:s+r,height:a+o})}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}};Ct=Wd([l.OnLifecycle(l.LifecycleStages.Rendered,Ct),mt(0,D.Inject(exports.SheetSkeletonManagerService)),mt(1,l.IUniverInstanceService),mt(2,l.ICommandService),mt(3,b.IRenderManagerService),mt(4,D.Inject(_.SelectionManagerService)),mt(5,D.Inject(Je))],Ct);var jd=Object.defineProperty,$d=Object.getOwnPropertyDescriptor,zd=(i,e,t,n)=>{for(var o=n>1?void 0:n?$d(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&jd(e,t,o),o},bo=(i,e)=>(t,n)=>e(t,n,i);const Xd=[Te.id,at.id];let yn=class extends l.Disposable{constructor(i,e){super(),this._commandService=i,this._scrollController=e,this.disposeWithMe(this._commandService.onCommandExecuted(t=>{Xd.includes(t.id)&&this._scrollController.scrollToVisible()}))}};yn=zd([l.OnLifecycle(l.LifecycleStages.Rendered,yn),bo(0,l.ICommandService),bo(1,D.Inject(Ct))],yn);var Yd=Object.defineProperty,Zd=Object.getOwnPropertyDescriptor,Gd=(i,e,t,n)=>{for(var o=n>1?void 0:n?Zd(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Yd(e,t,o),o},Ze=(i,e)=>(t,n)=>e(t,n,i);let On=class extends l.Disposable{constructor(i,e,t,n,o,r,s,a){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._selectionRenderService=o,this._selectionManagerService=r,this._themeService=s,this._scrollController=a,this._initialize()}_initialize(){const i=this._currentUniverService.getCurrentUniverSheetInstance(),e=i.getActiveSheet(),t=this._getSheetObject();if(t==null)return;this._initViewMainListener(t),this._initRowHeader(t),this._initColumnHeader(t),this._initLeftTop(t),this._initSelectionChangeListener(),this._initThemeChangeListener(),this._initSkeletonChangeListener(),this._initCommandListener(),this._initUserActionSyncListener();const n=i.getUnitId(),o=e.getSheetId();this._selectionManagerService.setCurrentSelection({pluginName:_.NORMAL_SELECTION_PLUGIN_NAME,unitId:n,sheetId:o})}_getActiveViewport(i){const e=this._getSheetObject();return e==null?void 0:e.scene.getActiveViewportByCoord(b.Vector2.FromArray([i.offsetX,i.offsetY]))}_initViewMainListener(i){const{spreadsheet:e}=i;this.disposeWithMe(l.toDisposable(e==null?void 0:e.onPointerDownObserver.add((t,n)=>{this._selectionRenderService.enableDetectMergedCell(),this._selectionRenderService.eventTrigger(t,e.zIndex+1,l.RANGE_TYPE.NORMAL,this._getActiveViewport(t)),t.button!==2&&n.stopPropagation()})))}_initThemeChangeListener(){this.disposeWithMe(l.toDisposable(this._themeService.currentTheme$.subscribe(()=>{this._selectionRenderService.resetStyle();const i=this._selectionManagerService.getSelections(),e=this._selectionManagerService.getCurrent();i==null||(e==null?void 0:e.pluginName)!==_.NORMAL_SELECTION_PLUGIN_NAME||this._refreshSelection(i)})))}_refreshSelection(i){const e=i.map(t=>{const n=this._selectionRenderService.convertSelectionRangeToData(t);return n.style=_.getNormalSelectionStyle(this._themeService),n});this._selectionRenderService.updateControlForCurrentByRangeData(e)}_initRowHeader(i){const{spreadsheetRowHeader:e,spreadsheet:t}=i;this.disposeWithMe(l.toDisposable(e==null?void 0:e.onPointerDownObserver.add((n,o)=>{this._selectionRenderService.disableDetectMergedCell(),this._selectionRenderService.eventTrigger(n,((t==null?void 0:t.zIndex)||1)+1,l.RANGE_TYPE.ROW,this._getActiveViewport(n),b.ScrollTimerType.Y),n.button!==2&&o.stopPropagation()})))}_initColumnHeader(i){const{spreadsheetColumnHeader:e,spreadsheet:t}=i;this.disposeWithMe(l.toDisposable(e==null?void 0:e.onPointerDownObserver.add((n,o)=>{this._selectionRenderService.disableDetectMergedCell(),this._selectionRenderService.eventTrigger(n,((t==null?void 0:t.zIndex)||1)+1,l.RANGE_TYPE.COLUMN,this._getActiveViewport(n),b.ScrollTimerType.X),n.button!==2&&o.stopPropagation()})))}_initLeftTop(i){const{spreadsheetLeftTopPlaceholder:e}=i;this.disposeWithMe(l.toDisposable(e==null?void 0:e.onPointerDownObserver.add((t,n)=>{var a;const o=(a=this._sheetSkeletonManagerService.getCurrent())==null?void 0:a.skeleton;if(o==null)return;this._selectionRenderService.reset();const r=this._getAllRange(o),s=this._selectionRenderService.convertSelectionRangeToData(r);this._selectionRenderService.addControlToCurrentByRangeData(s),this._selectionRenderService.refreshSelectionMoveStart(),t.button!==2&&n.stopPropagation()})))}_initSelectionChangeListener(){this.disposeWithMe(l.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(i=>{if(this._selectionRenderService.reset(),i!=null)for(const e of i){if(e==null)continue;const t=this._selectionRenderService.convertSelectionRangeToData(e);this._selectionRenderService.addControlToCurrentByRangeData(t)}})))}_initUserActionSyncListener(){this._selectionRenderService.selectionMoveStart$.subscribe(i=>{this._move(i,_.SelectionMoveType.MOVE_START)}),this._selectionRenderService.selectionMoving$.subscribe(i=>{this._move(i,_.SelectionMoveType.MOVING)}),this._selectionRenderService.selectionMoveEnd$.subscribe(i=>{this._move(i,_.SelectionMoveType.MOVE_END)})}_move(i,e){const t=this._currentUniverService.getCurrentUniverSheetInstance(),n=t.getUnitId(),o=t.getActiveSheet().getSheetId(),r=this._selectionManagerService.getCurrent();i==null||i.length===0||this._commandService.executeCommand(_.SetSelectionsOperation.id,{unitId:n,subUnitId:o,type:e,pluginName:(r==null?void 0:r.pluginName)||_.NORMAL_SELECTION_PLUGIN_NAME,selections:i.map(s=>_.convertSelectionDataToRange(s))})}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}_initCommandListener(){const i=[We.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(i.includes(e.id)){const t=this._currentUniverService.getCurrentUniverSheetInstance(),n=t.getActiveSheet(),o=e.params,{unitId:r,subUnitId:s}=o;if(!(r===t.getUnitId()&&s===n.getSheetId()))return;this._selectionManagerService.refreshSelection()}}))}_initSkeletonChangeListener(){this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{unitId:e,sheetId:t,skeleton:n}=i,o=this._renderManagerService.getRenderById(e);if(o==null)return;const{scene:r}=o,s=r.getViewport(V.VIEW_MAIN);this._selectionRenderService.changeRuntime(n,r,s);const a=this._selectionManagerService.getCurrent(),c=(a==null?void 0:a.pluginName)||_.NORMAL_SELECTION_PLUGIN_NAME;if((a==null?void 0:a.unitId)===e&&a.sheetId===t){const d=this._selectionManagerService.getSelections();d!=null&&this._refreshSelection(d)}else this._selectionManagerService.setCurrentSelection({pluginName:c,unitId:e,sheetId:t});c===_.NORMAL_SELECTION_PLUGIN_NAME&&this._selectionManagerService.getLast()==null&&this._selectionManagerService.add([this._getZeroRange(n)])})}_getAllRange(i){return{range:{startRow:0,startColumn:0,endRow:i.getRowCount()-1,endColumn:i.getColumnCount()-1,rangeType:l.RANGE_TYPE.ALL},primary:this._getZeroRange(i).primary,style:null}}_getZeroRange(i){const e=i.mergeData;return _.transformCellDataToSelectionData(0,0,e)||{range:{startRow:0,startColumn:0,endRow:0,endColumn:0},primary:{actualRow:0,actualColumn:0,startRow:0,startColumn:0,endRow:0,endColumn:0,isMerged:!1,isMergedMainCell:!1},style:null}}};On=Gd([l.OnLifecycle(l.LifecycleStages.Rendered,On),Ze(0,D.Inject(exports.SheetSkeletonManagerService)),Ze(1,l.IUniverInstanceService),Ze(2,l.ICommandService),Ze(3,b.IRenderManagerService),Ze(4,_e),Ze(5,D.Inject(_.SelectionManagerService)),Ze(6,D.Inject(l.ThemeService)),Ze(7,D.Inject(Ct))],On);var Kd=Object.defineProperty,qd=Object.getOwnPropertyDescriptor,Jd=(i,e,t,n)=>{for(var o=n>1?void 0:n?qd(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Kd(e,t,o),o},gt=(i,e)=>(t,n)=>e(t,n,i);let xn=class extends l.Disposable{constructor(i,e,t,n,o,r){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._renderManagerService=t,this._commandService=n,this._selectionRenderService=o,this._selectionManagerService=r,this._initialize(),this._commandExecutedListener()}dispose(){super.dispose()}_initialize(){this._initialRenderRefresh()}_initialRenderRefresh(){this.disposeWithMe(l.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{skeleton:e,unitId:t,sheetId:n}=i,o=this._currentUniverService.getUniverSheetInstance(t),r=o==null?void 0:o.getSheetBySheetId(n);if(o==null||r==null)return;const s=this._renderManagerService.getRenderById(t);if(s==null)return;const{mainComponent:a,components:c,scene:d}=s,u=a,h=c.get(fe.ROW),m=c.get(fe.COLUMN),g=c.get(fe.LEFT_TOP),{rowHeaderWidth:S,columnHeaderHeight:f}=e;u==null||u.updateSkeleton(e),h==null||h.updateSkeleton(e),m==null||m.updateSkeleton(e),g==null||g.transformByState({width:S,height:f})})))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((i,e)=>{var o,r;const t=this._currentUniverService.getCurrentUniverSheetInstance(),n=t.getUnitId();if(_.COMMAND_LISTENER_SKELETON_CHANGE.includes(i.id)){const s=t.getActiveSheet(),a=s.getSheetId(),c=i.params,{unitId:d,subUnitId:u}=c;if(!(d===t.getUnitId()&&u===s.getSheetId()))return;i.id!==_.SetWorksheetActiveOperation.id&&this._sheetSkeletonManagerService.makeDirty({unitId:d,sheetId:a,commandId:i.id},!0),this._sheetSkeletonManagerService.setCurrent({unitId:d,sheetId:a,commandId:i.id})}else _.COMMAND_LISTENER_VALUE_CHANGE.includes(i.id)&&this._sheetSkeletonManagerService.reCalculate();i.type===l.CommandType.MUTATION&&((r=(o=this._renderManagerService.getRenderById(n))==null?void 0:o.mainComponent)==null||r.makeDirty())}))}};xn=Jd([l.OnLifecycle(l.LifecycleStages.Ready,xn),gt(0,D.Inject(exports.SheetSkeletonManagerService)),gt(1,l.IUniverInstanceService),gt(2,b.IRenderManagerService),gt(3,l.ICommandService),gt(4,_e),gt(5,D.Inject(_.SelectionManagerService))],xn);const je={type:l.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge",handler:async(i,e)=>{const t=i.get(l.ICommandService),n=i.get(l.IUndoRedoService),o=i.get(l.IUniverInstanceService),r=i.get(I.IConfirmService),s=i.get(l.LocaleService),a=e.unitId,c=e.subUnitId,d=e.selections,u=_.getAddMergeMutationRangeByType(d,e.value),h=o.getUniverSheetInstance(a).getSheetBySheetId(c),m=[],g=[],S=Cr(h,u);if(S&&!await r.confirm({id:"merge.confirm.add-worksheet-merge",title:{title:"merge.confirm.title"},cancelText:s.t("merge.confirm.cancel"),confirmText:s.t("merge.confirm.confirm")}))return!1;const f={unitId:a,subUnitId:c,ranges:u},C={unitId:a,subUnitId:c,ranges:u};m.push({id:_.RemoveWorksheetMergeMutation.id,params:f}),m.push({id:_.AddWorksheetMergeMutation.id,params:C});const R=_.RemoveMergeUndoMutationFactory(i,f),M=_.AddMergeUndoMutationFactory(i,C);if(g.push({id:_.RemoveWorksheetMergeMutation.id,params:M}),g.push({id:_.AddWorksheetMergeMutation.id,params:R}),S){const w=Ir(i,a,h,u);m.unshift(...w.redos),g.push(...w.undos)}return l.sequenceExecute(m,t).result?(n.pushUndoRedo({unitID:a,undoMutations:g,redoMutations:m}),!0):!1}},Hr={type:l.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-all",handler:async i=>{const e=i.get(l.ICommandService),n=i.get(_.SelectionManagerService).getSelectionRanges();if(!(n!=null&&n.length))return!1;const r=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance();if(!r)return!1;const s=r.getActiveSheet();if(!s)return!1;const a=r.getUnitId(),c=s.getSheetId();return e.executeCommand(je.id,{selections:n,unitId:a,subUnitId:c})}},Lr={type:l.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-vertical",handler:async i=>{const e=i.get(l.ICommandService),n=i.get(_.SelectionManagerService).getSelectionRanges();if(!(n!=null&&n.length))return!1;const r=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance();if(!r)return!1;const s=r.getActiveSheet();if(!s)return!1;const a=r.getUnitId(),c=s.getSheetId();return e.executeCommand(je.id,{value:l.Dimension.COLUMNS,selections:n,unitId:a,subUnitId:c})}},Ur={type:l.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-horizontal",handler:async i=>{const e=i.get(l.ICommandService),n=i.get(_.SelectionManagerService).getSelectionRanges();if(!(n!=null&&n.length))return!1;const r=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance();if(!r)return!1;const s=r.getActiveSheet();if(!s)return!1;const a=r.getUnitId(),c=s.getSheetId();return e.executeCommand(je.id,{value:l.Dimension.ROWS,selections:n,unitId:a,subUnitId:c})}},Vi={type:l.CommandType.COMMAND,id:"sheet.command.delete-range-move-left-confirm",handler:async i=>{const e=i.get(I.IConfirmService),t=i.get(l.ICommandService),n=i.get(l.LocaleService),o=i.get(_.SelectionManagerService),r=i.get(l.IUniverInstanceService),s=o.getSelections();if(!s)return!1;const c=r.getCurrentUniverSheetInstance().getActiveSheet();let d=s[0].range;if(!d)return!1;d={...d,endColumn:c.getColumnCount()-1};const u=g=>g.endRow-g.startRow;return!c.getMergeData().find(g=>{const S=l.Rectangle.getIntersects(g,d);return S?u(g)>u(S):!1})||await e.confirm({id:Vi.id,title:{title:n.t("merge.confirm.waring")},children:{title:n.t("merge.confirm.dismantleMergeCellWaring")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")})?t.executeCommand(_.DeleteRangeMoveLeftCommand.id):!0}},Bi={type:l.CommandType.COMMAND,id:"sheet.command.delete-range-move-up-confirm",handler:async i=>{const e=i.get(I.IConfirmService),t=i.get(l.ICommandService),n=i.get(l.LocaleService),o=i.get(_.SelectionManagerService),r=i.get(l.IUniverInstanceService),s=o.getSelections();if(!s)return!1;const c=r.getCurrentUniverSheetInstance().getActiveSheet();let d=s[0].range;if(!d)return!1;d={...d,endRow:c.getColumnCount()-1};const u=g=>g.endColumn-g.startColumn;return!c.getMergeData().find(g=>{const S=l.Rectangle.getIntersects(g,d);return S?u(g)>u(S):!1})||await e.confirm({id:Bi.id,title:{title:n.t("merge.confirm.waring")},children:{title:n.t("merge.confirm.dismantleMergeCellWaring")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")})?t.executeCommand(_.DeleteRangeMoveUpCommand.id):!0}},Fi={type:l.CommandType.COMMAND,id:"sheet.command.insert-range-move-down-confirm",handler:async i=>{const e=i.get(I.IConfirmService),t=i.get(l.ICommandService),n=i.get(l.LocaleService),o=i.get(_.SelectionManagerService),r=i.get(l.IUniverInstanceService),s=o.getSelections();if(!s)return!1;const c=r.getCurrentUniverSheetInstance().getActiveSheet();let d=s[0].range;if(!d)return!1;d={...d,endRow:c.getColumnCount()-1};const u=g=>g.endColumn-g.startColumn;return!c.getMergeData().find(g=>{const S=l.Rectangle.getIntersects(g,d);return S?u(g)>u(S):!1})||await e.confirm({id:Fi.id,title:{title:n.t("merge.confirm.waring")},children:{title:n.t("merge.confirm.dismantleMergeCellWaring")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")})?t.executeCommand(_.InsertRangeMoveDownCommand.id):!0}},Wi={type:l.CommandType.COMMAND,id:"sheet.command.insert-range-move-right-confirm",handler:async i=>{const e=i.get(I.IConfirmService),t=i.get(l.ICommandService),n=i.get(l.LocaleService),o=i.get(_.SelectionManagerService),r=i.get(l.IUniverInstanceService),s=o.getSelections();if(!s)return!1;const c=r.getCurrentUniverSheetInstance().getActiveSheet();let d=s[0].range;if(!d)return!1;d={...d,endColumn:c.getColumnCount()-1};const u=g=>g.endRow-g.startRow;return!c.getMergeData().find(g=>{const S=l.Rectangle.getIntersects(g,d);return S?u(g)>u(S):!1})||await e.confirm({id:Wi.id,title:{title:n.t("merge.confirm.waring")},children:{title:n.t("merge.confirm.dismantleMergeCellWaring")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")})?t.executeCommand(_.InsertRangeMoveRightCommand.id):!0}},kr={id:"sheet.command.refill",type:l.CommandType.COMMAND,handler:async(i,e)=>{const t=i.get(Yt);return t.applyType=e.type,!0}},Vr={id:"sheet.command.remove-row-confirm",type:l.CommandType.COMMAND,handler:async(i,e)=>{var d;const t=i.get(_.SelectionManagerService);let n=e==null?void 0:e.range;if(n||(n=(d=t.getLast())==null?void 0:d.range),!n)return!1;const o=i.get(l.ICommandService),c=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet().getVisibleRows();if(qo(c,[n])){const u=i.get(I.IConfirmService),h=i.get(l.LocaleService);return await u.confirm({id:"sheet.confirm.remove-row",title:{title:h.t("info.problem")},children:{title:h.t("rightClick.deleteAllRowsAlert")},cancelText:h.t("button.cancel"),confirmText:h.t("button.confirm")}),!1}return await o.executeCommand(_.RemoveRowCommand.id,{range:n}),!0}},Br={id:"sheet.command.remove-col-confirm",type:l.CommandType.COMMAND,handler:async(i,e)=>{var d;const t=i.get(_.SelectionManagerService);let n=e==null?void 0:e.range;if(n||(n=(d=t.getLast())==null?void 0:d.range),!n)return!1;const o=i.get(l.ICommandService),c=i.get(l.IUniverInstanceService).getCurrentUniverSheetInstance().getActiveSheet().getVisibleCols();if(Jo(c,[n])){const u=i.get(I.IConfirmService),h=i.get(l.LocaleService);return await u.confirm({id:"sheet.confirm.remove-col",title:{title:h.t("info.problem")},children:{title:h.t("rightClick.deleteAllColumnsAlert")},cancelText:h.t("button.cancel"),confirmText:h.t("button.confirm")}),!1}return await o.executeCommand(_.RemoveColCommand.id,{range:n}),!0}},Fr={id:"sheet.command.remove-sheet-confirm",type:l.CommandType.COMMAND,handler:async(i,e)=>{const{subUnitId:t}=e,n=i.get(I.IConfirmService),o=i.get(l.ICommandService),r=i.get(l.LocaleService);return await n.confirm({id:"merge.confirm.add-worksheet-merge",title:{title:r.t("sheetConfig.deleteSheet")},children:{title:r.t("sheetConfig.deleteSheetContent")},cancelText:r.t("button.cancel"),confirmText:r.t("button.confirm")})?(await o.executeCommand(_.RemoveSheetCommand.id,{subUnitId:t}),!0):!1}},xt=D.createIdentifier("univer.sheetbar-service");class Qd extends l.Disposable{constructor(){super();v(this,"renameId$");v(this,"removeId$");v(this,"scroll$");v(this,"scrollX$");v(this,"addSheet$");v(this,"_renameId$");v(this,"_removeId$");v(this,"_scroll$");v(this,"_scrollX$");v(this,"_addSheet$");v(this,"_currentHandler",null);this._renameId$=new H.Subject,this.renameId$=this._renameId$.asObservable(),this._removeId$=new H.Subject,this.removeId$=this._removeId$.asObservable(),this._scroll$=new H.Subject,this.scroll$=this._scroll$.asObservable(),this._scrollX$=new H.Subject,this.scrollX$=this._scrollX$.asObservable(),this._addSheet$=new H.Subject,this.addSheet$=this._addSheet$.asObservable()}setRenameId(t){this._renameId$.next(t)}setRemoveId(t){this._removeId$.next(t)}setScroll(t){this._scroll$.next(t)}setScrollX(t){this._scrollX$.next(t)}setAddSheet(t){this._addSheet$.next(t)}triggerSheetBarMenu(){var t;(t=this._currentHandler)==null||t.handleSheetBarMenu()}registerSheetBarMenuHandler(t){if(this._currentHandler)throw new Error("There is already a context menu handler!");return this._currentHandler=t,l.toDisposable(()=>{this._currentHandler=null})}}const Wr={id:"ui-sheet.command.show-menu-list",type:l.CommandType.OPERATION,handler:async i=>(i.get(xt).triggerSheetBarMenu(),!0)},jr={id:"sheet.operation.rename-sheet",type:l.CommandType.OPERATION,handler:async(i,e)=>{const t=i.get(xt);return e&&t.setRenameId(e.subUnitId),!0}},eu=()=>p.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M0.98999 1.08218H-0.0100098V0.0821838H0.98999V1.08218Z",fill:"black"}),p.jsx("path",{d:"M5.78992 1.08218H2.78992V0.0821838H5.78992V1.08218Z",fill:"black"}),p.jsx("path",{d:"M7.58984 1.08218H8.58984V0.0821838H7.58984V1.08218Z",fill:"black"}),p.jsx("path",{d:"M14.9152 1.08218H13.9152V0.0821838H14.9152V1.08218Z",fill:"black"}),p.jsx("path",{d:"M16.7151 1.08218H19.7151V0.0821838H16.7151V1.08218Z",fill:"black"}),p.jsx("path",{d:"M22.515 1.08218H21.515V0.0821838H22.515V1.08218Z",fill:"black"}),p.jsx("path",{d:"M27.8405 1.08218H28.8405V0.0821838H27.8405V1.08218Z",fill:"black"}),p.jsx("path",{d:"M33.6404 1.08218H30.6404V0.0821838H33.6404V1.08218Z",fill:"black"}),p.jsx("path",{d:"M35.4403 1.08218H36.4403V0.0821838H35.4403V1.08218Z",fill:"black"}),p.jsx("path",{d:"M42.7657 1.08218H41.7657V0.0821838H42.7657V1.08218Z",fill:"black"}),p.jsx("path",{d:"M44.5657 1.08218H47.5657V0.0821838H44.5657V1.08218Z",fill:"black"}),p.jsx("path",{d:"M50.3656 1.08218H49.3656V0.0821838H50.3656V1.08218Z",fill:"black"}),p.jsx("path",{d:"M55.691 1.08218H56.691V0.0821838H55.691V1.08218Z",fill:"black"}),p.jsx("path",{d:"M61.491 1.08218H58.491V0.0821838H61.491V1.08218Z",fill:"black"}),p.jsx("path",{d:"M63.2909 1.08218H64.2909V0.0821838H63.2909V1.08218Z",fill:"black"}),p.jsx("path",{d:"M70.6163 1.08218H69.6163V0.0821838H70.6163V1.08218Z",fill:"black"}),p.jsx("path",{d:"M72.4163 1.08218H75.4163V0.0821838H72.4163V1.08218Z",fill:"black"}),p.jsx("path",{d:"M78.2162 1.08218H77.2162V0.0821838H78.2162V1.08218Z",fill:"black"}),p.jsx("path",{d:"M83.5416 1.08218H84.5416V0.0821838H83.5416V1.08218Z",fill:"black"}),p.jsx("path",{d:"M89.3416 1.08218H86.3416V0.0821838H89.3416V1.08218Z",fill:"black"}),p.jsx("path",{d:"M91.1415 1.08218H92.1415V0.0821838H91.1415V1.08218Z",fill:"black"}),p.jsx("path",{d:"M98.4669 1.08218H97.4669V0.0821838H98.4669V1.08218Z",fill:"black"}),p.jsx("path",{d:"M100.267 1.08218H103.267V0.0821838H100.267V1.08218Z",fill:"black"}),p.jsx("path",{d:"M106.067 1.08218H105.067V0.0821838H106.067V1.08218Z",fill:"black"}),p.jsx("path",{d:"M111.392 1.08218H112.392V0.0821838H111.392V1.08218Z",fill:"black"}),p.jsx("path",{d:"M117.192 1.08218H114.192V0.0821838H117.192V1.08218Z",fill:"black"}),p.jsx("path",{d:"M118.992 1.08218H119.992V0.0821838H118.992V1.08218Z",fill:"black"})]}),tu=()=>p.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.0100098 1.15771H0.98999V0.157715H-0.0100098V1.15771Z",fill:"black"}),p.jsx("path",{d:"M2.78992 1.15771H5.78992V0.157715H2.78992V1.15771Z",fill:"black"}),p.jsx("path",{d:"M8.58984 1.15771H7.58984V0.157715H8.58984V1.15771Z",fill:"black"}),p.jsx("path",{d:"M10.3899 1.15771H11.3899V0.157715H10.3899V1.15771Z",fill:"black"}),p.jsx("path",{d:"M19.0903 1.15771H18.0903V0.157715H19.0903V1.15771Z",fill:"black"}),p.jsx("path",{d:"M20.8903 1.15771H23.8903V0.157715H20.8903V1.15771Z",fill:"black"}),p.jsx("path",{d:"M26.6902 1.15771H25.6902V0.157715H26.6902V1.15771Z",fill:"black"}),p.jsx("path",{d:"M28.4902 1.15771H29.4902V0.157715H28.4902V1.15771Z",fill:"black"}),p.jsx("path",{d:"M37.1907 1.15771H36.1907V0.157715H37.1907V1.15771Z",fill:"black"}),p.jsx("path",{d:"M38.9906 1.15771H41.9906V0.157715H38.9906V1.15771Z",fill:"black"}),p.jsx("path",{d:"M44.7905 1.15771H43.7905V0.157715H44.7905V1.15771Z",fill:"black"}),p.jsx("path",{d:"M46.5906 1.15771H47.5906V0.157715H46.5906V1.15771Z",fill:"black"}),p.jsx("path",{d:"M55.291 1.15771H54.291V0.157715H55.291V1.15771Z",fill:"black"}),p.jsx("path",{d:"M57.0909 1.15771H60.0909V0.157715H57.0909V1.15771Z",fill:"black"}),p.jsx("path",{d:"M62.8909 1.15771H61.8909V0.157715H62.8909V1.15771Z",fill:"black"}),p.jsx("path",{d:"M64.6909 1.15771H65.6909V0.157715H64.6909V1.15771Z",fill:"black"}),p.jsx("path",{d:"M73.3914 1.15771H72.3914V0.157715H73.3914V1.15771Z",fill:"black"}),p.jsx("path",{d:"M75.1913 1.15771H78.1913V0.157715H75.1913V1.15771Z",fill:"black"}),p.jsx("path",{d:"M80.9912 1.15771H79.9912V0.157715H80.9912V1.15771Z",fill:"black"}),p.jsx("path",{d:"M82.7913 1.15771H83.7913V0.157715H82.7913V1.15771Z",fill:"black"}),p.jsx("path",{d:"M91.4917 1.15771H90.4917V0.157715H91.4917V1.15771Z",fill:"black"}),p.jsx("path",{d:"M93.2916 1.15771H96.2916V0.157715H93.2916V1.15771Z",fill:"black"}),p.jsx("path",{d:"M99.0916 1.15771H98.0916V0.157715H99.0916V1.15771Z",fill:"black"}),p.jsx("path",{d:"M100.892 1.15771H101.892V0.157715H100.892V1.15771Z",fill:"black"}),p.jsx("path",{d:"M109.592 1.15771H108.592V0.157715H109.592V1.15771Z",fill:"black"}),p.jsx("path",{d:"M111.392 1.15771H114.392V0.157715H111.392V1.15771Z",fill:"black"}),p.jsx("path",{d:"M117.192 1.15771H116.192V0.157715H117.192V1.15771Z",fill:"black"}),p.jsx("path",{d:"M118.992 1.15771H119.992V0.157715H118.992V1.15771Z",fill:"black"})]}),nu=()=>p.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.00842285 1.22449H2.99158V0.224487H-0.00842285V1.22449Z",fill:"black"}),p.jsx("path",{d:"M6.14941 1.22449H9.14941V0.224487H6.14941V1.22449Z",fill:"black"}),p.jsx("path",{d:"M15.3073 1.22449H12.3073V0.224487H15.3073V1.22449Z",fill:"black"}),p.jsx("path",{d:"M18.4651 1.22449H21.4651V0.224487H18.4651V1.22449Z",fill:"black"}),p.jsx("path",{d:"M27.6229 1.22449H24.6229V0.224487H27.6229V1.22449Z",fill:"black"}),p.jsx("path",{d:"M30.7808 1.22449H33.7808V0.224487H30.7808V1.22449Z",fill:"black"}),p.jsx("path",{d:"M39.9386 1.22449H36.9386V0.224487H39.9386V1.22449Z",fill:"black"}),p.jsx("path",{d:"M43.0964 1.22449H46.0964V0.224487H43.0964V1.22449Z",fill:"black"}),p.jsx("path",{d:"M52.2543 1.22449H49.2543V0.224487H52.2543V1.22449Z",fill:"black"}),p.jsx("path",{d:"M55.4121 1.22449H58.4121V0.224487H55.4121V1.22449Z",fill:"black"}),p.jsx("path",{d:"M64.5699 1.22449H61.5699V0.224487H64.5699V1.22449Z",fill:"black"}),p.jsx("path",{d:"M67.7278 1.22449H70.7278V0.224487H67.7278V1.22449Z",fill:"black"}),p.jsx("path",{d:"M76.8856 1.22449H73.8856V0.224487H76.8856V1.22449Z",fill:"black"}),p.jsx("path",{d:"M80.0435 1.22449H83.0435V0.224487H80.0435V1.22449Z",fill:"black"}),p.jsx("path",{d:"M89.2013 1.22449H86.2013V0.224487H89.2013V1.22449Z",fill:"black"}),p.jsx("path",{d:"M92.3591 1.22449H95.3591V0.224487H92.3591V1.22449Z",fill:"black"}),p.jsx("path",{d:"M101.517 1.22449H98.517V0.224487H101.517V1.22449Z",fill:"black"}),p.jsx("path",{d:"M104.675 1.22449H107.675V0.224487H104.675V1.22449Z",fill:"black"}),p.jsx("path",{d:"M113.833 1.22449H110.833V0.224487H113.833V1.22449Z",fill:"black"}),p.jsx("path",{d:"M116.99 1.22449H119.99V0.224487H116.99V1.22449Z",fill:"black"})]}),iu=()=>p.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.00976562 1.65707H0.990234V0.657074H-0.00976562V1.65707Z",fill:"black"}),p.jsx("path",{d:"M2.32361 1.65707H3.32361V0.657074H2.32361V1.65707Z",fill:"black"}),p.jsx("path",{d:"M5.65698 1.65707H4.65698V0.657074H5.65698V1.65707Z",fill:"black"}),p.jsx("path",{d:"M6.99036 1.65707H7.99036V0.657074H6.99036V1.65707Z",fill:"black"}),p.jsx("path",{d:"M10.3237 1.65707H9.32373V0.657074H10.3237V1.65707Z",fill:"black"}),p.jsx("path",{d:"M11.6571 1.65707H12.6571V0.657074H11.6571V1.65707Z",fill:"black"}),p.jsx("path",{d:"M14.9905 1.65707H13.9905V0.657074H14.9905V1.65707Z",fill:"black"}),p.jsx("path",{d:"M16.3239 1.65707H17.3239V0.657074H16.3239V1.65707Z",fill:"black"}),p.jsx("path",{d:"M19.6572 1.65707H18.6572V0.657074H19.6572V1.65707Z",fill:"black"}),p.jsx("path",{d:"M20.9906 1.65707H21.9906V0.657074H20.9906V1.65707Z",fill:"black"}),p.jsx("path",{d:"M24.324 1.65707H23.324V0.657074H24.324V1.65707Z",fill:"black"}),p.jsx("path",{d:"M25.6573 1.65707H26.6573V0.657074H25.6573V1.65707Z",fill:"black"}),p.jsx("path",{d:"M28.9907 1.65707H27.9907V0.657074H28.9907V1.65707Z",fill:"black"}),p.jsx("path",{d:"M30.3241 1.65707H31.3241V0.657074H30.3241V1.65707Z",fill:"black"}),p.jsx("path",{d:"M33.6575 1.65707H32.6575V0.657074H33.6575V1.65707Z",fill:"black"}),p.jsx("path",{d:"M34.9908 1.65707H35.9908V0.657074H34.9908V1.65707Z",fill:"black"}),p.jsx("path",{d:"M38.3242 1.65707H37.3242V0.657074H38.3242V1.65707Z",fill:"black"}),p.jsx("path",{d:"M39.6576 1.65707H40.6576V0.657074H39.6576V1.65707Z",fill:"black"}),p.jsx("path",{d:"M42.991 1.65707H41.991V0.657074H42.991V1.65707Z",fill:"black"}),p.jsx("path",{d:"M44.3243 1.65707H45.3243V0.657074H44.3243V1.65707Z",fill:"black"}),p.jsx("path",{d:"M47.6577 1.65707H46.6577V0.657074H47.6577V1.65707Z",fill:"black"}),p.jsx("path",{d:"M48.9911 1.65707H49.9911V0.657074H48.9911V1.65707Z",fill:"black"}),p.jsx("path",{d:"M52.3245 1.65707H51.3245V0.657074H52.3245V1.65707Z",fill:"black"}),p.jsx("path",{d:"M53.6578 1.65707H54.6578V0.657074H53.6578V1.65707Z",fill:"black"}),p.jsx("path",{d:"M56.9912 1.65707H55.9912V0.657074H56.9912V1.65707Z",fill:"black"}),p.jsx("path",{d:"M58.3246 1.65707H59.3246V0.657074H58.3246V1.65707Z",fill:"black"}),p.jsx("path",{d:"M61.658 1.65707H60.658V0.657074H61.658V1.65707Z",fill:"black"}),p.jsx("path",{d:"M62.9913 1.65707H63.9913V0.657074H62.9913V1.65707Z",fill:"black"}),p.jsx("path",{d:"M66.3247 1.65707H65.3247V0.657074H66.3247V1.65707Z",fill:"black"}),p.jsx("path",{d:"M67.6581 1.65707H68.6581V0.657074H67.6581V1.65707Z",fill:"black"}),p.jsx("path",{d:"M70.9915 1.65707H69.9915V0.657074H70.9915V1.65707Z",fill:"black"}),p.jsx("path",{d:"M72.3248 1.65707H73.3248V0.657074H72.3248V1.65707Z",fill:"black"}),p.jsx("path",{d:"M75.6582 1.65707H74.6582V0.657074H75.6582V1.65707Z",fill:"black"}),p.jsx("path",{d:"M76.9916 1.65707H77.9916V0.657074H76.9916V1.65707Z",fill:"black"}),p.jsx("path",{d:"M80.325 1.65707H79.325V0.657074H80.325V1.65707Z",fill:"black"}),p.jsx("path",{d:"M81.6583 1.65707H82.6583V0.657074H81.6583V1.65707Z",fill:"black"}),p.jsx("path",{d:"M84.9917 1.65707H83.9917V0.657074H84.9917V1.65707Z",fill:"black"}),p.jsx("path",{d:"M86.3251 1.65707H87.3251V0.657074H86.3251V1.65707Z",fill:"black"}),p.jsx("path",{d:"M89.6584 1.65707H88.6584V0.657074H89.6584V1.65707Z",fill:"black"}),p.jsx("path",{d:"M90.9918 1.65707H91.9918V0.657074H90.9918V1.65707Z",fill:"black"}),p.jsx("path",{d:"M94.3252 1.65707H93.3252V0.657074H94.3252V1.65707Z",fill:"black"}),p.jsx("path",{d:"M95.6586 1.65707H96.6586V0.657074H95.6586V1.65707Z",fill:"black"}),p.jsx("path",{d:"M98.9919 1.65707H97.9919V0.657074H98.9919V1.65707Z",fill:"black"}),p.jsx("path",{d:"M100.325 1.65707H101.325V0.657074H100.325V1.65707Z",fill:"black"}),p.jsx("path",{d:"M103.659 1.65707H102.659V0.657074H103.659V1.65707Z",fill:"black"}),p.jsx("path",{d:"M104.992 1.65707H105.992V0.657074H104.992V1.65707Z",fill:"black"}),p.jsx("path",{d:"M108.325 1.65707H107.325V0.657074H108.325V1.65707Z",fill:"black"}),p.jsx("path",{d:"M109.659 1.65707H110.659V0.657074H109.659V1.65707Z",fill:"black"}),p.jsx("path",{d:"M112.992 1.65707H111.992V0.657074H112.992V1.65707Z",fill:"black"}),p.jsx("path",{d:"M114.325 1.65707H115.325V0.657074H114.325V1.65707Z",fill:"black"}),p.jsx("path",{d:"M117.659 1.65707H116.659V0.657074H117.659V1.65707Z",fill:"black"}),p.jsx("path",{d:"M118.992 1.65707H119.992V0.657074H118.992V1.65707Z",fill:"black"})]}),ou=()=>p.jsx("svg",{width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:p.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 2.42035H-0.0090332V0.420349H119.991V2.42035Z",fill:"black"})}),ru=()=>p.jsxs("svg",{width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.0100098 2.47614H1.98999V0.476135H-0.0100098V2.47614Z",fill:"black"}),p.jsx("path",{d:"M3.99014 2.47614H9.99014V0.476135H3.99014V2.47614Z",fill:"black"}),p.jsx("path",{d:"M13.9901 2.47614H11.9901V0.476135H13.9901V2.47614Z",fill:"black"}),p.jsx("path",{d:"M21.1904 2.47614H23.1904V0.476135H21.1904V2.47614Z",fill:"black"}),p.jsx("path",{d:"M31.1906 2.47614H25.1906V0.476135H31.1906V2.47614Z",fill:"black"}),p.jsx("path",{d:"M33.1906 2.47614H35.1906V0.476135H33.1906V2.47614Z",fill:"black"}),p.jsx("path",{d:"M44.3909 2.47614H42.3909V0.476135H44.3909V2.47614Z",fill:"black"}),p.jsx("path",{d:"M46.391 2.47614H52.391V0.476135H46.391V2.47614Z",fill:"black"}),p.jsx("path",{d:"M56.391 2.47614H54.391V0.476135H56.391V2.47614Z",fill:"black"}),p.jsx("path",{d:"M63.5913 2.47614H65.5913V0.476135H63.5913V2.47614Z",fill:"black"}),p.jsx("path",{d:"M73.5915 2.47614H67.5915V0.476135H73.5915V2.47614Z",fill:"black"}),p.jsx("path",{d:"M75.5915 2.47614H77.5915V0.476135H75.5915V2.47614Z",fill:"black"}),p.jsx("path",{d:"M86.7917 2.47614H84.7917V0.476135H86.7917V2.47614Z",fill:"black"}),p.jsx("path",{d:"M88.7919 2.47614H94.7919V0.476135H88.7919V2.47614Z",fill:"black"}),p.jsx("path",{d:"M98.7919 2.47614H96.7919V0.476135H98.7919V2.47614Z",fill:"black"}),p.jsx("path",{d:"M105.992 2.47614H107.992V0.476135H105.992V2.47614Z",fill:"black"}),p.jsx("path",{d:"M115.992 2.47614H109.992V0.476135H115.992V2.47614Z",fill:"black"}),p.jsx("path",{d:"M117.992 2.47614H119.992V0.476135H117.992V2.47614Z",fill:"black"})]}),su=()=>p.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.0100098 2.00415H1.98999V0.00415039H-0.0100098V2.00415Z",fill:"black"}),p.jsx("path",{d:"M3.99014 2.00415H9.99014V0.00415039H3.99014V2.00415Z",fill:"black"}),p.jsx("path",{d:"M13.9901 2.00415H11.9901V0.00415039H13.9901V2.00415Z",fill:"black"}),p.jsx("path",{d:"M15.9901 2.00415H17.9901V0.00415039H15.9901V2.00415Z",fill:"black"}),p.jsx("path",{d:"M27.4905 2.00415H25.4905V0.00415039H27.4905V2.00415Z",fill:"black"}),p.jsx("path",{d:"M29.4906 2.00415H35.4906V0.00415039H29.4906V2.00415Z",fill:"black"}),p.jsx("path",{d:"M39.4906 2.00415H37.4906V0.00415039H39.4906V2.00415Z",fill:"black"}),p.jsx("path",{d:"M41.4906 2.00415H43.4906V0.00415039H41.4906V2.00415Z",fill:"black"}),p.jsx("path",{d:"M52.991 2.00415H50.991V0.00415039H52.991V2.00415Z",fill:"black"}),p.jsx("path",{d:"M54.9911 2.00415H60.9911V0.00415039H54.9911V2.00415Z",fill:"black"}),p.jsx("path",{d:"M64.9911 2.00415H62.9911V0.00415039H64.9911V2.00415Z",fill:"black"}),p.jsx("path",{d:"M66.9911 2.00415H68.9911V0.00415039H66.9911V2.00415Z",fill:"black"}),p.jsx("path",{d:"M78.4915 2.00415H76.4915V0.00415039H78.4915V2.00415Z",fill:"black"}),p.jsx("path",{d:"M80.4916 2.00415H86.4916V0.00415039H80.4916V2.00415Z",fill:"black"}),p.jsx("path",{d:"M90.4916 2.00415H88.4916V0.00415039H90.4916V2.00415Z",fill:"black"}),p.jsx("path",{d:"M92.4916 2.00415H94.4916V0.00415039H92.4916V2.00415Z",fill:"black"}),p.jsx("path",{d:"M103.992 2.00415H101.992V0.00415039H103.992V2.00415Z",fill:"black"}),p.jsx("path",{d:"M105.992 2.00415H111.992V0.00415039H105.992V2.00415Z",fill:"black"}),p.jsx("path",{d:"M115.992 2.00415H113.992V0.00415039H115.992V2.00415Z",fill:"black"}),p.jsx("path",{d:"M117.992 2.00415H119.992V0.00415039H117.992V2.00415Z",fill:"black"})]}),au=()=>p.jsxs("svg",{width:"118",height:"3",viewBox:"0 0 118 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M-0.00854492 2.94815H1.99146V0.948151H-0.00854492V2.94815Z",fill:"black"}),p.jsx("path",{d:"M6.09668 2.94815H8.09668V0.948151H6.09668V2.94815Z",fill:"black"}),p.jsx("path",{d:"M14.2019 2.94815H12.2019V0.948151H14.2019V2.94815Z",fill:"black"}),p.jsx("path",{d:"M18.3071 2.94815H20.3071V0.948151H18.3071V2.94815Z",fill:"black"}),p.jsx("path",{d:"M26.4124 2.94815H24.4124V0.948151H26.4124V2.94815Z",fill:"black"}),p.jsx("path",{d:"M30.5176 2.94815H32.5176V0.948151H30.5176V2.94815Z",fill:"black"}),p.jsx("path",{d:"M38.6228 2.94815H36.6228V0.948151H38.6228V2.94815Z",fill:"black"}),p.jsx("path",{d:"M42.728 2.94815H44.728V0.948151H42.728V2.94815Z",fill:"black"}),p.jsx("path",{d:"M50.8333 2.94815H48.8333V0.948151H50.8333V2.94815Z",fill:"black"}),p.jsx("path",{d:"M54.9385 2.94815H56.9385V0.948151H54.9385V2.94815Z",fill:"black"}),p.jsx("path",{d:"M63.0437 2.94815H61.0437V0.948151H63.0437V2.94815Z",fill:"black"}),p.jsx("path",{d:"M67.1489 2.94815H69.1489V0.948151H67.1489V2.94815Z",fill:"black"}),p.jsx("path",{d:"M75.2542 2.94815H73.2542V0.948151H75.2542V2.94815Z",fill:"black"}),p.jsx("path",{d:"M79.3594 2.94815H81.3594V0.948151H79.3594V2.94815Z",fill:"black"}),p.jsx("path",{d:"M87.4645 2.94815H85.4645V0.948151H87.4645V2.94815Z",fill:"black"}),p.jsx("path",{d:"M91.5697 2.94815H93.5697V0.948151H91.5697V2.94815Z",fill:"black"}),p.jsx("path",{d:"M99.6749 2.94815H97.6749V0.948151H99.6749V2.94815Z",fill:"black"}),p.jsx("path",{d:"M103.78 2.94815H105.78V0.948151H103.78V2.94815Z",fill:"black"}),p.jsx("path",{d:"M111.885 2.94815H109.885V0.948151H111.885V2.94815Z",fill:"black"}),p.jsx("path",{d:"M115.991 2.94815H117.991V0.948151H115.991V2.94815Z",fill:"black"})]}),lu=()=>p.jsx("svg",{width:"120",height:"4",viewBox:"0 0 120 4",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:p.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 3.86215H-0.0090332V0.862152H119.991V3.86215Z",fill:"black"})}),wo=()=>p.jsx("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:p.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 1.15668H-0.0090332V0.156677H119.991V1.15668Z",fill:"black"})});function To(i){const{type:e=l.BorderStyleTypes.THIN}=i;switch(e){case l.BorderStyleTypes.DASH_DOT:return p.jsx(eu,{});case l.BorderStyleTypes.DASH_DOT_DOT:return p.jsx(tu,{});case l.BorderStyleTypes.DASHED:return p.jsx(nu,{});case l.BorderStyleTypes.HAIR:return p.jsx(iu,{});case l.BorderStyleTypes.MEDIUM:return p.jsx(ou,{});case l.BorderStyleTypes.MEDIUM_DASH_DOT:return p.jsx(ru,{});case l.BorderStyleTypes.MEDIUM_DASH_DOT_DOT:return p.jsx(su,{});case l.BorderStyleTypes.MEDIUM_DASHED:return p.jsx(au,{});case l.BorderStyleTypes.THICK:return p.jsx(lu,{});case l.BorderStyleTypes.THIN:return p.jsx(wo,{});default:return p.jsx(wo,{})}}const cu="univer-ui-plugin-sheets-border-panel",du="univer-ui-plugin-sheets-border-panel-position",uu="univer-ui-plugin-sheets-border-panel-position-item",hu="univer-ui-plugin-sheets-border-panel-styles",mu="univer-ui-plugin-sheets-border-panel-board",gu="univer-ui-plugin-sheets-border-panel-button",Su="univer-ui-plugin-sheets-border-panel-more-icon",Ve={uiPluginSheetsBorderPanel:cu,uiPluginSheetsBorderPanelPosition:du,uiPluginSheetsBorderPanelPositionItem:uu,uiPluginSheetsBorderPanelStyles:hu,uiPluginSheetsBorderPanelBoard:mu,uiPluginSheetsBorderPanelButton:gu,uiPluginSheetsBorderPanelMoreIcon:Su},$r=`${yt}_BORDER_PANEL_COMPONENT`,zr=[{label:"borderLine.borderTop",icon:"UpBorder",value:"top"},{label:"borderLine.borderBottom",icon:"DownBorder",value:"bottom"},{label:"borderLine.borderLeft",icon:"LeftBorder",value:"left"},{label:"borderLine.borderRight",icon:"RightBorder",value:"right"},{label:"borderLine.borderNone",icon:"NoBorderSingle",value:"none"},{label:"borderLine.borderAll",icon:"AllBorderSingle",value:"all"},{label:"borderLine.borderOutside",icon:"OuterBorder",value:"outside"},{label:"borderLine.borderInside",icon:"InnerBorder",value:"inside"},{label:"borderLine.borderHorizontal",icon:"InnerBorder",value:"horizontal"},{label:"borderLine.borderVertical",icon:"InnerBorder",value:"vertical"},{label:"borderLine.borderTlbr",icon:"BackSlashSingle",value:"tlbr"},{label:"borderLine.borderTlbcTlmr",icon:"LeftDoubleDiagonalSingle",value:"tlbc_tlmr"},{label:"borderLine.borderTlbrTlbcTlmr",icon:"LeftTridiagonalSingle",value:"tlbr_tlbc_tlmr"},{label:"borderLine.borderBlTr",icon:"SlashSingle",value:"bltr"},{label:"borderLine.borderMltrBctr",icon:"RightDoubleDiagonalSingle",value:"mltr_bctr"}],_u=[{label:l.BorderStyleTypes.THIN,value:l.BorderStyleTypes.THIN},{label:l.BorderStyleTypes.HAIR,value:l.BorderStyleTypes.HAIR},{label:l.BorderStyleTypes.DOTTED,value:l.BorderStyleTypes.DOTTED},{label:l.BorderStyleTypes.DASHED,value:l.BorderStyleTypes.DASHED},{label:l.BorderStyleTypes.DASH_DOT,value:l.BorderStyleTypes.DASH_DOT},{label:l.BorderStyleTypes.DASH_DOT_DOT,value:l.BorderStyleTypes.DASH_DOT_DOT},{label:l.BorderStyleTypes.MEDIUM,value:l.BorderStyleTypes.MEDIUM},{label:l.BorderStyleTypes.MEDIUM_DASHED,value:l.BorderStyleTypes.MEDIUM_DASHED},{label:l.BorderStyleTypes.MEDIUM_DASH_DOT,value:l.BorderStyleTypes.MEDIUM_DASH_DOT},{label:l.BorderStyleTypes.MEDIUM_DASH_DOT_DOT,value:l.BorderStyleTypes.MEDIUM_DASH_DOT_DOT},{label:l.BorderStyleTypes.THICK,value:l.BorderStyleTypes.THICK}];function fu(i){const e=K.useDependency(I.ComponentManager),{onChange:t,value:n}=i;function o(a,c){t==null||t({...n,[c]:a})}function r(a){const c=e.get(a);return c&&p.jsx(c,{extend:{colorChannel1:"rgb(var(--primary-color))"}})}function s(a){a.stopPropagation()}return p.jsxs("section",{className:Ve.uiPluginSheetsBorderPanel,children:[p.jsx("div",{className:Ve.uiPluginSheetsBorderPanelPosition,children:zr.map(a=>p.jsx("div",{className:Ve.uiPluginSheetsBorderPanelPositionItem,onClick:()=>o(a.value,"type"),children:r(a.icon)},a.value))}),p.jsxs("div",{className:Ve.uiPluginSheetsBorderPanelStyles,children:[p.jsx("div",{children:p.jsx(Se.Dropdown,{align:{offset:[0,18]},overlay:p.jsx("section",{className:Ve.uiPluginSheetsBorderPanelBoard,onClick:s,children:p.jsx(Se.ColorPicker,{onChange:a=>o(a,"color")})}),children:p.jsxs("a",{className:Ve.uiPluginSheetsBorderPanelButton,onClick:s,children:[p.jsx($a,{extend:{colorChannel1:n.color??"rgb(var(--primary-color))"}}),p.jsx("span",{className:Ve.uiPluginSheetsBorderPanelMoreIcon,children:p.jsx(pi,{})})]})})}),p.jsx("div",{children:p.jsx(Se.Dropdown,{align:{offset:[0,18]},overlay:p.jsx("section",{onClick:s,children:p.jsx(Se.Menu,{children:_u.map(a=>p.jsx(Se.MenuItem,{eventKey:a.value.toString(),onClick:()=>o(a.value,"style"),children:p.jsx(To,{type:a.value})},a.value))})}),children:p.jsxs("a",{className:Ve.uiPluginSheetsBorderPanelButton,onClick:s,children:[p.jsx(To,{type:l.BorderStyleTypes.THIN}),p.jsx("span",{className:Ve.uiPluginSheetsBorderPanelMoreIcon,children:p.jsx(pi,{})})]})})})]})]})}const pu="univer-count-bar",vu={countBar:pu},Cu=[50,80,100,130,150,170,200,400],Iu=100;function Ru(){const i=K.useDependency(l.ICommandService),e=K.useDependency(l.IUniverInstanceService),t=K.useDependency(l.IContextService),n=c(),[o,r]=P.useState(n),a=!Se.useObservable(()=>H.combineLatest(t.subscribeContextValue$(l.FOCUSING_UNIVER_EDITOR),t.subscribeContextValue$(l.EDITOR_ACTIVATED)).pipe(H.map(([u,h])=>u&&!h),H.debounceTime(Iu)),!1,!0,[l.FOCUSING_UNIVER_EDITOR]);P.useEffect(()=>i.onCommandExecuted(h=>{if(h.id===We.id||h.id===_.SetWorksheetActivateCommand.id){const m=c();r(m)}}).dispose,[i]);function c(){const u=e.getCurrentUniverSheetInstance().getActiveSheet().getZoomRatio()*100||100;return Math.round(u)}function d(u){r(u);const h=e.getCurrentUniverSheetInstance(),m=h==null?void 0:h.getActiveSheet();if(m==null)return;const g=u/100;i.executeCommand(Gn.id,{unitId:h.getUnitId(),subUnitId:m.getSheetId(),zoomRatio:g})}return p.jsx(Se.Slider,{disabled:a,min:gi[0],value:o,shortcuts:Cu,onChange:d})}function Mu(i){return p.jsx("section",{className:vu.countBar,children:p.jsx(Ru,{})})}const bu="univer-editor-container",wu="univer-editor-input",Eo={editorContainer:bu,editorInput:wu},Bn=-1e3,yo={width:0,height:0,top:Bn,left:Bn},Tu=()=>{const[i,e]=P.useState({...yo}),t=P.useRef(null),n=K.useDependency(b.IRenderManagerService),o=K.useDependency(Kt);return P.useEffect(()=>{const r=t.current;if(!r)return;const s=n.currentRender$.pipe(Ao.switchMap(()=>{var c;const a=(c=n.getRenderById(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:c.engine;return a==null||a.setContainer(r),o.state$})).subscribe(a=>{if(a==null)return;const{startX:c=Bn,startY:d=Bn,endX:u=0,endY:h=0,show:m=!1}=a;if(!m)e({...yo});else{e({width:u-c,height:h-d,left:c,top:d});const g=t.current;if(!g)return;const{left:S,top:f,width:C,height:R}=g.getBoundingClientRect();o.setRect({left:S,top:f,width:C,height:R})}});return()=>{s.unsubscribe()}},[]),P.useEffect(()=>{o.setFocus(!0)},[i]),p.jsx("div",{className:Eo.editorContainer,style:{left:i.left,top:i.top,width:i.width,height:i.height},children:p.jsx("div",{className:Eo.editorInput,ref:t})})},Eu="univer-formula-box",yu="univer-name-ranges",Ou="univer-name-ranges-input",xu="univer-formula-bar",Au="univer-formula-icon",Du="univer-formula-icon-wrapper",Nu="univer-icon-container",Pu="univer-icon-container-success",Hu="univer-formula-active",Lu="univer-icon-container-error",Uu="univer-formula-input",ku="univer-formula-content",Vu="univer-arrow-container",me={formulaBox:Eu,nameRanges:yu,nameRangesInput:Ou,formulaBar:xu,formulaIcon:Au,formulaIconWrapper:Du,iconContainer:Nu,iconContainerSuccess:Pu,formulaActive:Hu,iconContainerError:Lu,formulaInput:Uu,formulaContent:ku,arrowContainer:Vu};function Bu(){const[i,e]=P.useState(me.formulaGrey),[t,n]=P.useState(0),o=P.useRef(null),r=K.useDependency(b.IRenderManagerService),s=K.useDependency(Yn),a=K.useDependency(Ee);P.useEffect(()=>{const m=o.current;if(!m)return;const g=r.currentRender$.subscribe(f=>{var R;if(f!==l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;const C=(R=r.getRenderById(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:R.engine;C==null||C.setContainer(m)}),S=new ResizeObserver(()=>{const f=m.getBoundingClientRect();s.setPosition(f)});return S.observe(m),a.visible$.subscribe(f=>{e(f.visible?me.formulaActive:me.formulaGrey)}),()=>{S.unobserve(m),g.unsubscribe()}},[]);function c(){n(t===0?1:0),setTimeout(()=>{s.handleFoldBtnClick(t===1)},150)}function d(){a.isVisible().visible&&a.changeVisible({visible:!1,eventType:b.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ESC})}function u(){a.isVisible().visible&&a.changeVisible({visible:!1,eventType:b.DeviceInputEventType.PointerDown})}function h(){s.handleFxBtnClick(!0)}return p.jsxs("div",{className:me.formulaBox,style:{height:t===0?"28px":"82px"},children:[p.jsx("div",{className:me.nameRanges,children:p.jsx("div",{className:me.nameRangesInput})}),p.jsxs("div",{className:me.formulaBar,children:[p.jsx("div",{className:me.formulaIcon,children:p.jsxs("div",{className:me.formulaIconWrapper,children:[p.jsx("span",{className:Bt(me.iconContainer,me.iconContainerError,i),onClick:d,children:p.jsx(Aa,{})}),p.jsx("span",{className:Bt(me.iconContainer,me.iconContainerSuccess,i),onClick:u,children:p.jsx(kn,{})}),p.jsx("span",{className:me.iconContainer,onClick:h,children:p.jsx(ka,{})})]})}),p.jsxs("div",{className:me.formulaInput,children:[p.jsx("div",{onContextMenu:m=>m.preventDefault(),className:me.formulaContent,ref:o}),p.jsx("div",{className:me.arrowContainer,onClick:c,children:t===0?p.jsx(lo,{}):p.jsx(lo,{style:{transform:"rotateZ(180deg)"}})})]})]})]})}const Fu="univer-operate-container",Wu="univer-auto-fill-popup-menu",ju="univer-auto-fill-popup-menu-item",$u="univer-auto-fill-popup-menu-item-icon",zu="univer-auto-fill-popup-menu-item-title",Xu="univer-auto-fill-popup-menu-item-hide",Yu="univer-btn-container",Zu="univer-btn-container-expand",it={operateContainer:Fu,autoFillPopupMenu:Wu,autoFillPopupMenuItem:ju,autoFillPopupMenuItemIcon:$u,autoFillPopupMenuItemTitle:zu,autoFillPopupMenuItemHide:Xu,btnContainer:Yu,btnContainerExpand:Zu},Gu=()=>{const[,i]=P.useState({});return P.useCallback(()=>i(e=>!e),[])},Ku=()=>{var re;const i=K.useDependency(l.ICommandService),e=K.useDependency(exports.SheetSkeletonManagerService),t=K.useDependency(l.IUniverInstanceService),n=K.useDependency(b.IRenderManagerService),o=K.useDependency(_e),r=K.useDependency(Yt),s=K.useDependency(l.LocaleService),[a,c]=P.useState([]),[d,u]=P.useState(!1),[h,m]=P.useState({row:-1,col:-1}),[g,S]=P.useState(ie.SERIES),[f,C]=P.useState(!1),R=()=>{C(!0)},M=()=>{C(!1)},T=Gu(),w=ve(t,n);if(w==null)return null;const{scene:E}=w;if(P.useEffect(()=>{const Y=[He.id,an.id,We.id,_.SetWorksheetActiveOperation.id,_.MoveRangeMutation.id];return i.onCommandExecuted(U=>{U.id===Tt.id&&T(),Y.includes(U.id)&&m({row:-1,col:-1})}).dispose},[T,i]),P.useEffect(()=>l.toDisposable(r.menu$.subscribe(L=>{c(L.map(U=>({...U,index:L.indexOf(U)})))})).dispose,[r]),P.useEffect(()=>l.toDisposable(r.showMenu$.subscribe(L=>{const{source:U,target:X}=r.autoFillLocation||{source:null,target:null};if(L&&U&&X){const j=l.Rectangle.union(U,X);m({row:j.endRow,col:j.endColumn})}})).dispose,[r]),P.useEffect(()=>l.toDisposable(r.applyType$.subscribe(L=>{S(L)})).dispose,[r]),P.useEffect(()=>{function Y(){u(!1)}return document.addEventListener("wheel",Y),()=>{document.removeEventListener("wheel",Y)}},[d]),h.col<0||h.row<0)return null;const y=(re=e.getCurrent())==null?void 0:re.skeleton,x=o.getViewPort(),O=E==null?void 0:E.scaleX,A=E==null?void 0:E.scaleY,k=E==null?void 0:E.getScrollXY(x);if(!O||!E||!O||!A||!k)return null;const N=(y==null?void 0:y.getNoMergeCellPositionByIndex(h.row,h.col).endX)||0,B=(y==null?void 0:y.getNoMergeCellPositionByIndex(h.row,h.col).endY)||0,F=y==null?void 0:y.convertTransformToOffsetX(N,O,k),W=y==null?void 0:y.convertTransformToOffsetY(B,A,k);if(F==null||W==null)return null;const $=Y=>{u(Y)},Z=Y=>{i.executeCommand(kr.id,{type:Y.value})},z=d||f,Q=a.filter(Y=>!Y.disable);return p.jsx("div",{onMouseEnter:R,onMouseLeave:M,style:{left:`${F+2}px`,top:`${W+2}px`,position:"absolute"},children:p.jsx(Se.Dropdown,{placement:"bottomLeft",trigger:["click"],overlay:p.jsx("ul",{className:it.autoFillPopupMenu,children:Q.map(Y=>p.jsxs("li",{onClick:()=>Z(Y),className:it.autoFillPopupMenuItem,children:[p.jsx("span",{className:it.autoFillPopupMenuItemIcon,children:Y.value===g&&p.jsx(kn,{style:{color:"rgb(var(--green-700, #409f11))"}})}),p.jsx("span",{className:it.autoFillPopupMenuItemTitle,children:s.t(Y.label)})]},Y.index))}),visible:d,onVisibleChange:$,children:p.jsxs("div",{className:Bt(it.btnContainer,{[it.btnContainerExpand]:d}),children:[p.jsx(ya,{style:{color:"#35322B"},extend:{colorChannel1:"rgb(var(--green-700, #409f11))"}}),z&&p.jsx(pi,{style:{color:"#CCCCCC",fontSize:"8px",marginLeft:"8px"}})]})})})},qu=()=>p.jsx("div",{className:it.operateContainer,children:p.jsx(Ku,{})}),Ju="univer-sheet-bar",Qu="univer-sheet-bar-options",eh="univer-sheet-bar-options-divider",sn={sheetBar:Ju,sheetBarOptions:Qu,sheetBarOptionsDivider:eh},th="univer-sheet-bar-btn",nh={sheetBarBtn:th};function An(i){const{children:e,className:t,style:n,disabled:o=!1,onClick:r,...s}=i,a=c=>{if(o){c.preventDefault();return}r&&r(c)};return p.jsx("button",{className:nh.sheetBarBtn,style:n,disabled:o,onClick:a,...s,children:e})}const ih="univer-sheet-bar-menu",oh="univer-sheet-bar-menu-item",rh="univer-sheet-bar-menu-item-icon",sh="univer-sheet-bar-menu-item-hide",ah="univer-sheet-bar-menu-item-select",lh="univer-sheet-bar-menu-item-label",Ge={sheetBarMenu:ih,sheetBarMenuItem:oh,sheetBarMenuItemIcon:rh,sheetBarMenuItemHide:sh,sheetBarMenuItemSelect:ah,sheetBarMenuItemLabel:lh};function ch(i){const{style:e}=i,[t,n]=P.useState([]),[o,r]=P.useState(!1),s=K.useDependency(l.IUniverInstanceService),a=K.useDependency(l.ICommandService),c=K.useDependency(xt),d=s.getCurrentUniverSheetInstance(),u=f=>{const{sheetId:C}=f;C&&(f.hidden?a.executeCommand(_.SetWorksheetShowCommand.id,{value:C}):f.selected||a.executeCommand(_.SetWorksheetActivateCommand.id,{unitId:d.getUnitId(),subUnitId:C}),r(!1))};P.useEffect(()=>{m();const f=new l.DisposableCollection;return f.add(h()),f.add(c.registerSheetBarMenuHandler({handleSheetBarMenu:g})),()=>{f.dispose()}},[]);const h=()=>a.onCommandExecuted(f=>{switch(f.id){case _.SetWorksheetHideMutation.id:case _.RemoveSheetMutation.id:case _.SetWorksheetNameMutation.id:case _.InsertSheetMutation.id:case _.SetWorksheetOrderMutation.id:case _.SetWorksheetActiveOperation.id:m();break}}),m=()=>{const C=d.getSheets().map((R,M)=>({label:R.getName(),index:`${M}`,sheetId:R.getSheetId(),hidden:R.isSheetHidden()===l.BooleanNumber.TRUE,selected:R.getStatus()===l.BooleanNumber.TRUE}));n(C)};function g(){r(!0)}const S=f=>{r(f)};return p.jsx(Se.Dropdown,{placement:"topLeft",trigger:["click"],overlay:p.jsx("ul",{className:Ge.sheetBarMenu,style:{...e},children:t.map(f=>p.jsxs("li",{onClick:()=>u(f),className:f.selected?`${Ge.sheetBarMenuItem} ${Ge.sheetBarMenuItemSelect}`:f.hidden?`${Ge.sheetBarMenuItem} ${Ge.sheetBarMenuItemHide}`:Ge.sheetBarMenuItem,children:[p.jsx("span",{className:Ge.sheetBarMenuItemIcon,children:f.selected?p.jsx(kn,{}):f.hidden?p.jsx(La,{}):p.jsx(kn,{})}),p.jsx("span",{className:Ge.sheetBarMenuItemLabel,children:f.label})]},f.index))}),visible:o,onVisibleChange:S,children:p.jsx(An,{children:p.jsx(Na,{})})})}const dh="univer-slide-tab-bar-container",uh="univer-slide-tab-bar",hh="univer-slide-tab-item",mh="univer-slide-tab-active",gh="univer-slide-tab-span",Sh="univer-slide-tab-span-edit",_h="univer-slide-tab-item-dropdown",Me={slideTabBarContainer:dh,slideTabBar:uh,slideTabItem:hh,slideTabActive:mh,slideTabSpan:gh,slideTabSpanEdit:Sh,slideTabItemDropdown:_h};function fh(i){const{sheetId:e,label:t,color:n,selected:o}=i,[r,s]=P.useState(o),a=K.useDependency(l.ThemeService);P.useEffect(()=>{s(o)},[o]);const c=d=>{const u=a.getCurrentTheme(),h=u.textColor,m=u.colorWhite;return new l.ColorKit(d).isDark()?m:h};return p.jsx("div",{"data-id":e,className:r?`${Me.slideTabActive} ${Me.slideTabItem}`:Me.slideTabItem,style:{backgroundColor:!r&&n?n:"",color:!r&&n?c(n):"",boxShadow:r&&n?`0px 0px 8px rgba(0, 0, 0, 0.08), inset 0px -2px 0px 0px ${n}`:""},children:p.jsx("span",{className:Me.slideTabSpan,children:t})},e)}const ph={easeOutStrong(i,e,t,n){return-t*((i=i/n-1)*i*i*i-1)+e},backOut(i,e,t,n,o){return typeof o>"u"&&(o=.7),t*((i=i/n-1)*i*((o+1)*i+o)+1)+e}},vh={loop:!1,begin:0,end:0,duration:300,delay:0,type:"easeOutStrong",receive(i){},success(i){},cancel(i){},complete(i){}};class Ch{constructor(e){v(this,"_config");v(this,"_status",0);v(this,"_start",0);v(this,"_handle",0);v(this,"_delayHandle",null);this._config={...vh,...e},this._config.loop&&(this._config.complete=()=>{},this._config.success=()=>{this.request()})}static success(...e){let t=0;return new Promise(n=>{for(let o=0;o<e.length;o++){const r=e[o],s=r._config,a=s.success;s.loop||(s.success=d=>{t++,a&&a.call(r,d),t===e.length&&n()})}})}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 e=Date.now()-this._start;e=e>=this._config.duration?this._config.duration:e;const n=ph[this._config.type](e,this._config.begin,this._config.end-this._config.begin,this._config.duration,.7).toFixed(2);if(this._config.receive(n),this._status===1){this._config.cancel(n),this._config.complete(n);return}if(e===this._config.duration){this._config.success(n),this._config.complete(n);return}this._handle=requestAnimationFrame(()=>{this._fakeHandle()})}}class rt{constructor(e,t){v(this,"_slideTabItem");v(this,"_animate");v(this,"_midline",0);v(this,"_translateX");v(this,"_scrollbar");v(this,"_slideTabBar");v(this,"_editMode");v(this,"_placeholder");this._slideTabItem=e,this._animate=null,this._translateX=0,this._editMode=!1,this._slideTabBar=t,this._placeholder=null,this._scrollbar=t.getScrollbar(),this.update()}static midline(e){return e.getBoundingRect().x+e.getBoundingRect().width/2}static leftLine(e){return e.getBoundingRect().x}static rightLine(e){return e.getBoundingRect().x+e.getBoundingRect().width}static make(e,t){const n=[];return e.forEach(o=>n.push(new rt(o,t))),n}getSlideTabItem(){return this._slideTabItem}getEditor(){return this._slideTabItem.querySelector("span")}focus(){var e;(e=this.getEditor())==null||e.focus()}selectAll(){const e=this.getEditor();e&&It.keepSelectAll(e)}isEditMode(){return this._editMode}classList(){return this._slideTabItem.classList}translateX(e){return this._translateX=e,this._slideTabItem.style.transform=`translateX(${e}px)`,this.getTranslateXDirection()}setEditor(e){let t=!0;if(this._editMode===!1){const n=this._slideTabItem.querySelector("span"),o=d=>{if(!this.nameCheck()){if(this._editMode=!1,n&&(n.removeAttribute("contentEditable"),n.removeEventListener("blur",o),n.removeEventListener("compositionstart",s),n.removeEventListener("compositionend",a),n.removeEventListener("input",c),n.removeEventListener("keydown",r),n.classList.remove(this._slideTabBar.getConfig().slideTabBarSpanEditClassName)),this._slideTabBar.removeListener(),this._slideTabBar.updateItems(),this._slideTabBar.getConfig().onChangeName){const u=(n==null?void 0:n.innerText)||"",h=this.getId();this._slideTabBar.getConfig().onChangeName(h,u)}e&&e(d)}};let r=d=>{n&&(d.stopPropagation(),d.key==="Enter"&&n.blur())};const s=d=>{t=!1},a=d=>{t=!0},c=d=>{if(!n)return;const u=50;setTimeout(()=>{if(t){const h=n.innerText;h.length>u&&(n.innerText=h.substring(0,u),It.keepLastIndex(n))}},0)};n&&(n.setAttribute("contentEditable","true"),n.addEventListener("blur",o),n.addEventListener("compositionstart",s),n.addEventListener("compositionend",a),n.addEventListener("input",c),n.addEventListener("keydown",r),n.classList.add(this._slideTabBar.getConfig().slideTabBarSpanEditClassName),this._editMode=!0,It.keepSelectAll(n))}}nameCheck(){const e=this._slideTabItem.querySelector("span");if(!e)return!1;const t=e.innerText;return this._slideTabBar.getConfig().onNameCheckAlert(t)}animate(){return{translateX:e=>{this._translateX!==e&&(this._animate&&(this._animate.cancel(),this._animate=null),this._animate=new Ch({begin:this._translateX,end:e,receive:t=>{this._slideTabItem.style.transform=`translateX(${t}px)`}}),this._translateX=e,this._animate.request())},cancel:()=>{this._animate&&(this._animate.cancel(),this._animate=null)}}}after(e){this._slideTabItem.after(e._slideTabItem||e)}update(){this._midline=rt.midline(this)}disableFixed(){if(this._placeholder){const e=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),e.removeChild(this._placeholder),this._placeholder=null}}enableFixed(){const e=document.createElement("div"),t=this.getBoundingRect(),n=getComputedStyle(this._slideTabItem),o=this._slideTabItem.querySelector("span");if(this._placeholder=e,this._placeholder.style.width=`${t.width}px`,this._placeholder.style.height=`${t.height}px`,this._placeholder.style.flexShrink="0",this._placeholder.style.margin=n.margin,this._slideTabItem.style.background=n.background,o){const r=getComputedStyle(o).padding;this._slideTabItem.style.padding=r}this._slideTabItem.style.boxSizing=n.boxSizing,this._slideTabItem.style.fontSize=n.fontSize,this._slideTabItem.style.fontFamily=n.fontFamily,this._slideTabItem.style.fontWeight=n.fontWeight,this._slideTabItem.style.color=n.color,this._slideTabItem.style.borderRadius=n.borderRadius,this._slideTabItem.style.left=`${t.x-this.getScrollbar().getScrollX()}px`,this._slideTabItem.style.top=`${t.y}px`,this._slideTabItem.style.width=`${t.width}px`,this._slideTabItem.style.height=`${t.height}px`,this._slideTabItem.style.position="fixed",this._slideTabItem.after(e),document.body.appendChild(this._slideTabItem)}addEventListener(e,t,n){this._slideTabItem.addEventListener(e,t,n)}removeEventListener(e,t,n){this._slideTabItem.removeEventListener(e,t,n)}getScrollbar(){return this._scrollbar}getMidLine(){return this._midline}getBoundingRect(){const e=this._slideTabItem.getBoundingClientRect();return e.x+=this._scrollbar.getScrollX(),e}getWidth(){return this.getBoundingRect().width}getTranslateXDirection(){const e=rt.midline(this);return e>this._midline?1:e<this._midline?-1:0}equals(e){return e&&e._slideTabItem===this._slideTabItem}getId(){return this._slideTabItem.dataset.id||""}}class Ih{constructor(e){v(this,"_slideTabBar");v(this,"_scrollX");const t=e.primeval();this._scrollX=t.scrollLeft,this._slideTabBar=e}scrollX(e){const t=this._slideTabBar.primeval();t.scrollLeft=e,this._scrollX=t.scrollLeft}scrollRight(){const e=this._slideTabBar.primeval();e.scrollLeft=e.scrollWidth,this._scrollX=e.scrollLeft}getScrollX(){return this._scrollX}}const pt=class pt{constructor(e){v(this,"_activeTabItemIndex",0);v(this,"_slideTabBar");v(this,"_slideTabItems",[]);v(this,"_config");v(this,"_downActionX",0);v(this,"_moveActionX",0);v(this,"_compareIndex",0);v(this,"_activeTabItem",null);v(this,"_moveAction");v(this,"_upAction");v(this,"_downAction");v(this,"_wheelAction");v(this,"_scrollIncremental",0);v(this,"_compareDirection",0);v(this,"_autoScrollTime",null);v(this,"_slideScrollbar");v(this,"_longPressTimer",null);v(this,"_leftBoundingLine",0);v(this,"_rightBoundingLine",0);v(this,"_leftMoveX",0);v(this,"_rightMoveX",0);if(e.slideTabBarContainer==null)throw new Error("not found slide-tab-bar root element");const t=e.slideTabBarContainer.querySelector(`.${e.slideTabBarClassName??"slide-tab-bar"}`);if(t==null)throw new Error("not found slide-tab-bar");this._slideTabBar=t,this._slideScrollbar=new Ih(this),this._config=e,this._initConfig();let n=0,o=0,r=0;this._downAction=s=>{var E,y,x,O,A,k;if((E=this._activeTabItem)!=null&&E.isEditMode())return;const a=(x=(y=s.target)==null?void 0:y.closest(`.${e.slideTabBarItemClassName}`))==null?void 0:x.getAttribute("data-id"),c=this._slideTabItems.findIndex(N=>N.getId()===a);if(a==null||c===-1)return;if(this._activeTabItemIndex!==c){(O=this._activeTabItem)==null||O.removeEventListener("pointermove",this._moveAction),(A=this._activeTabItem)==null||A.removeEventListener("pointerup",this._upAction),this.removeListener(),this._config.onChangeTab(s,a);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),(k=this._activeTabItem)==null||k.addEventListener("pointerup",this._upAction);const{x:u,width:h}=this._activeTabItem.getBoundingRect(),{x:m,width:g}=this.getBoundingRect(),S=this._slideScrollbar.getScrollX();if(this._leftBoundingLine=this._downActionX-(u-S),this._rightBoundingLine=u-S+h-this._downActionX,this._leftMoveX=u-m-S,this._rightMoveX=m+g-(u+h)+S,s.button===2||this._hasEditItem())return;const{pageX:f,pageY:C}=s,R=Date.now(),M=R-r<=pt.DoubleClickDelay,T=Math.abs(f-n)<10,w=Math.abs(C-o)<10;M&&T&&w&&this._activeTabItem.setEditor(),n=f,o=C,r=R,this._longPressTimer=setTimeout(()=>{var N,B;(N=this._activeTabItem)==null||N.enableFixed(),this._startAutoScroll(),d&&(d.setPointerCapture(s.pointerId),d.style.cursor="move",(B=this._activeTabItem)==null||B.addEventListener("pointermove",this._moveAction))},pt.LongPressDelay)},this._upAction=s=>{var c,d,u;if(this._longPressTimer&&(clearTimeout(this._longPressTimer),this._longPressTimer=null),!this._activeTabItem)return;this._closeAutoScroll(),this._activeTabItem.disableFixed(),this.updateItems();const a=(c=this._activeTabItem)==null?void 0:c.getSlideTabItem();a&&(a.style.cursor="",a.releasePointerCapture(s.pointerId),(d=this._activeTabItem)==null||d.removeEventListener("pointermove",this._moveAction),(u=this._activeTabItem)==null||u.removeEventListener("pointerup",this._upAction),this._config.onSlideEnd&&this._activeTabItemIndex!==this._compareIndex&&(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(e){let t=e.target;for(;t!=null&&t!==document.body;){if(t.getAttribute("data-slide-skip"))return!0;t=t.parentElement}return!1}static keepLastIndex(e){setTimeout(()=>{const t=window.getSelection();t&&(t.selectAllChildren(e),t.collapseToEnd())})}static keepSelectAll(e){setTimeout(()=>{const t=window.getSelection();if(!t)return;const n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)})}update(e){this._config.currentIndex=e,this._initConfig(),this.removeListener(),this.addListener()}primeval(){return this._slideTabBar}updateItems(){for(let e=0;e<this._slideTabItems.length;e++)this._slideTabItems[e].animate().cancel(),this._slideTabItems[e].translateX(0),this._slideTabItems[e].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 e=this._slideTabBar.parentElement;return e?this._slideTabBar.scrollWidth-e.clientWidth===this._slideTabBar.scrollLeft:!1}addListener(){this._slideTabBar.addEventListener("wheel",this._wheelAction),this._slideTabItems.forEach(e=>{e.addEventListener("pointerdown",this._downAction)})}removeListener(){this._slideTabBar.removeEventListener("wheel",this._wheelAction),this._slideTabItems.forEach(e=>{e.removeEventListener("pointerdown",this._downAction)})}setScroll(e){if(this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e),e>0){const t=this.calculateLeftScrollX();this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+t)}else if(e<0){const t=this.calculateRightScrollX();this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+t)}this._config.onScroll({leftEnd:this.isLeftEnd(),rightEnd:this.isRightEnd()})}flipPage(e){if(e>0){const t=this.calculateLeftScrollX(!0);this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+t)}else if(e<0){const t=this.calculateRightScrollX(!0);this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+t)}this._config.onScroll({leftEnd:this.isLeftEnd(),rightEnd:this.isRightEnd()})}calculateLeftScrollX(e){let t=0;const n=4;return this._slideTabItems.some(o=>{const r=this._slideTabBar.getBoundingClientRect(),s=r.left+r.width,a=o.getSlideTabItem().getBoundingClientRect(),c=a.left,d=a.width;return c<s&&c+d+n*2>s?(t=e?c-r.left-n:c+d-s+n,!0):!1}),t}calculateRightScrollX(e){let t=0;const n=4;return this._slideTabItems.some(o=>{const r=this._slideTabBar.getBoundingClientRect(),s=r.left,a=o.getSlideTabItem().getBoundingClientRect(),c=a.left,d=a.width;return c-n*2<s&&c+d>s?(t=e?c+d-r.left-r.width+n:c-s-n,!0):!1}),t}destroy(){this._downActionX=0,this._moveActionX=0,this._compareDirection=0,this._compareIndex=0,this._slideTabItems=[],this._activeTabItem=null,this.removeListener()}_hasEditItem(){for(let e=0;e<this._slideTabItems.length;e++)if(this._slideTabItems[e].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(e){const t=this.getBoundingRect(),n=e.pageX-t.x;n<this._leftBoundingLine&&(this._scrollIncremental=-Math.min(Math.abs(n-this._leftBoundingLine)*.1,50))}_scrollRight(e){const t=this.getBoundingRect(),n=e.pageX-t.x;n>t.width-this._rightBoundingLine&&(this._scrollIncremental=Math.min(Math.abs(n-(t.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 e=0;e<this._slideTabItems.length;e++){const t=this._slideTabItems[e],n=this._slideTabItems[e+1];n&&t.after(n)}}_compareLeft(){if(this._activeTabItem&&this._activeTabItemIndex){const e=this._slideTabItems.findIndex(r=>r.equals(this._activeTabItem)),t=this._slideTabItems.length,n=[];for(let r=0;r<e&&!(r>=e);r++)n.push(this._slideTabItems[r]);for(let r=e+1;r<t;r++)this._slideTabItems[r].animate().translateX(0);let o=!0;for(let r=n.length-1;r>=0;r--){const s=n[r];rt.leftLine(this._activeTabItem)<s.getMidLine()?(s.animate().translateX(this._activeTabItem.getWidth()),this._compareIndex=r,o=!1):(s.animate().translateX(0),o&&(this._compareIndex=this._activeTabItemIndex))}}}_compareRight(){if(this._activeTabItem){const e=this._slideTabItems.findIndex(r=>r.equals(this._activeTabItem)),t=this._slideTabItems.length,n=[];for(let r=e+1;r<t;r++)n.push(this._slideTabItems[r]);for(let r=0;r<e;r++)this._slideTabItems[r].animate().translateX(0);let o=!0;for(let r=0;r<n.length;r++){const s=n[r];rt.rightLine(this._activeTabItem)>s.getMidLine()?(s.animate().translateX(-this._activeTabItem.getWidth()),this._compareIndex=e+r+1,o=!1):(s.animate().translateX(0),o&&(this._compareIndex=this._activeTabItemIndex))}}}_initConfig(){const e=this._slideTabBar.querySelectorAll(`.${this._config.slideTabBarItemClassName??"slide-tab-item"}`);this._downActionX=0,this._moveActionX=0,this._compareDirection=0,this._compareIndex=0,this._slideTabItems=rt.make(e,this),this._activeTabItemIndex=this._config.currentIndex,this._activeTabItem=this._slideTabItems[this._activeTabItemIndex]}};v(pt,"LongPressDelay",500),v(pt,"DoubleClickDelay",300);let It=pt;function Rh(){const[i,e]=P.useState([]),[t,n]=P.useState(""),[o,r]=P.useState(""),[s,a]=P.useState(!1),[c,d]=P.useState([0,0]),u=P.useRef({slideTabBar:null}),h=P.useRef(null),m=K.useDependency(l.IUniverInstanceService),g=K.useDependency(l.ICommandService),S=K.useDependency(xt),f=K.useDependency(l.LocaleService),C=K.useDependency(I.IConfirmService),R=K.useDependency(_e),M=K.useDependency(Ee),T=K.useInjector(),w=m.getCurrentUniverSheetInstance();P.useEffect(()=>{B();const L=E(),U=N(),X=[F(),W(),$(),Z()];return()=>{U.dispose(),L.destroy(),X.forEach(j=>j.unsubscribe())}},[]),P.useEffect(()=>{i.length>0&&k()},[i]);const E=()=>{const L=new It({slideTabBarClassName:Me.slideTabBar,slideTabBarItemActiveClassName:Me.slideTabActive,slideTabBarItemClassName:Me.slideTabItem,slideTabBarSpanEditClassName:Me.slideTabSpanEdit,slideTabBarItemAutoSort:!0,slideTabBarContainer:h.current,currentIndex:0,onChangeName:(U,X)=>{g.executeCommand(_.SetWorksheetNameCommand.id,{subUnitId:U,name:X})},onSlideEnd:(U,X)=>{g.executeCommand(_.SetWorksheetOrderCommand.id,{order:X})},onChangeTab:(U,X)=>{g.executeCommand(_.SetWorksheetActivateCommand.id,{subUnitId:X,unitId:w.getUnitId()}).then(()=>{U.button===2&&Y(!0)}),setTimeout(()=>{T.get(b.ITextSelectionRenderManager).focus()},0)},onScroll:U=>{S.setScroll(U)},onNameCheckAlert:U=>y(U)||x(U)});return u.current.slideTabBar=L,re(L),L},y=L=>{if(L.trim()===""){const U="sheetNameEmptyAlert";return C.open({id:U,title:{title:f.t("sheetConfig.sheetNameErrorTitle")},children:{title:f.t("sheetConfig.sheetNameCannotIsEmptyError")},cancelText:f.t("button.cancel"),confirmText:f.t("button.confirm"),onClose(){O(),C.close(U)},onConfirm(){O(),C.close(U)}}),!0}return!1},x=L=>{const U=m.getCurrentUniverSheetInstance();if(U.getActiveSheet().getName()===L)return!1;const oe=U.checkSheetName(L);if(oe){const G="sheetNameRepeatAlert";C.open({id:G,title:{title:f.t("sheetConfig.sheetNameErrorTitle")},children:{title:f.t("sheetConfig.sheetNameAlreadyExistsError")},cancelText:f.t("button.cancel"),confirmText:f.t("button.confirm"),onClose(){C.close(G),O()},onConfirm(){C.close(G),O()}})}return oe},O=()=>{R.endSelection(),setTimeout(()=>{var U;const L=(U=u.current.slideTabBar)==null?void 0:U.getActiveItem();L&&(L.focus(),L.selectAll())},0)},A=()=>{var L,U;(U=(L=u.current.slideTabBar)==null?void 0:L.getActiveItem())==null||U.setEditor()},k=()=>{var U;const L=i.findIndex(X=>X.selected);(U=u.current.slideTabBar)==null||U.update(L)},N=()=>g.onCommandExecuted(L=>{switch(L.id){case _.SetTabColorMutation.id:case _.SetWorksheetHideMutation.id:case _.RemoveSheetMutation.id:case _.SetWorksheetNameMutation.id:case _.InsertSheetMutation.id:case _.SetWorksheetOrderMutation.id:case _.SetWorksheetActiveOperation.id:B();break}}),B=()=>{const L=w.getActiveSheet().getSheetId();n(L);const X=w.getSheets().filter(j=>!j.isSheetHidden()).map((j,oe)=>({sheetId:j.getSheetId(),label:j.getName(),index:oe,selected:j.getStatus()===l.BooleanNumber.TRUE,color:j.getTabColor()??void 0}));e(X)},F=()=>S.scroll$.subscribe(L=>{z(L)}),W=()=>S.scrollX$.subscribe(L=>{var U;(U=u.current.slideTabBar)==null||U.flipPage(L)}),$=()=>S.renameId$.subscribe(()=>{A()}),Z=()=>S.addSheet$.subscribe(()=>{var L;(L=u.current.slideTabBar)==null||L.getScrollbar().scrollRight()}),z=L=>{const{leftEnd:U,rightEnd:X}=L;let j="";U&&X?j="":U&&!X?j="inset -10px 0px 10px -10px rgba(0, 0, 0, 0.2)":!U&&X?j="inset 10px 0px 10px -10px rgba(0, 0, 0, 0.2)":!U&&!X&&(j="inset 10px 0px 10px -10px rgba(0, 0, 0, 0.2), inset -10px 0px 10px -10px rgba(0, 0, 0, 0.2)"),r(j)},Q=L=>{S.setScroll({leftEnd:L.isLeftEnd(),rightEnd:L.isRightEnd()})},re=L=>{var j;const U=(j=h.current)==null?void 0:j.querySelector(`.${Me.slideTabBar}`);if(!U)return;new ResizeObserver(()=>{Q(L)}).observe(U)},Y=L=>{var U,X,j;if(!M.isForceKeepVisible()){if(L){const{left:oe}=((U=h.current)==null?void 0:U.getBoundingClientRect())??{},{left:G}=((j=(X=u.current.slideTabBar)==null?void 0:X.getActiveItem())==null?void 0:j.getSlideTabItem().getBoundingClientRect())??{};oe!==void 0&&G!==void 0&&d([G-oe,0])}a(L)}};return p.jsx(Se.Dropdown,{className:Me.slideTabItemDropdown,visible:s,align:{offset:c},trigger:["contextMenu"],overlay:p.jsx(I.Menu,{menuType:de.SHEET_BAR,onOptionSelect:L=>{const{label:U,value:X}=L;g.executeCommand(U,{value:X,subUnitId:t}),a(!1)}}),onVisibleChange:Y,children:p.jsx("div",{className:Me.slideTabBarContainer,ref:h,children:p.jsx("div",{className:Me.slideTabBar,style:{boxShadow:o},children:i.map(L=>P.createElement(fh,{...L,key:L.sheetId,selected:t===L.sheetId}))})})})}const Oo=100,Mh=()=>{const[i,e]=P.useState(!0),[t,n]=P.useState(!0),o=K.useDependency(l.ICommandService),r=K.useDependency(xt);P.useEffect(()=>{const u=r.scroll$.subscribe(h=>{s(h)});return()=>{u.unsubscribe()}},[]);const s=u=>{const{leftEnd:h,rightEnd:m}=u;e(h),n(m)},a=()=>{o.executeCommand(_.InsertSheetCommand.id),setTimeout(()=>{r.setAddSheet(0)},0)},c=()=>{r.setScrollX(-Oo)},d=()=>{r.setScrollX(Oo)};return p.jsxs("div",{className:sn.sheetBar,children:[p.jsxs("div",{className:sn.sheetBarOptions,children:[p.jsx(An,{onClick:a,children:p.jsx(Ba,{})}),p.jsx(ch,{})]}),p.jsx(Rh,{}),(!i||!t)&&p.jsxs("div",{className:`${sn.sheetBarOptions} ${sn.sheetBarOptionsDivider}`,children:[p.jsx(An,{disabled:i,onClick:c,children:p.jsx(co,{style:{transform:"rotateZ(180deg)"}})}),p.jsx(An,{disabled:t,onClick:d,children:p.jsx(co,{})})]})]})};class bh{constructor(){v(this,"_functions",[{func:te.FUNCTION_NAMES_STATISTICAL.MAX,filter:e=>{var t,n;return(((t=e.values.find(o=>o.func===te.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:t.value)??0)>1&&(((n=e.values.find(o=>o.func===te.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:n.value)??0)>0}},{func:te.FUNCTION_NAMES_STATISTICAL.MIN,filter:e=>{var t,n;return(((t=e.values.find(o=>o.func===te.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:t.value)??0)>1&&(((n=e.values.find(o=>o.func===te.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:n.value)??0)>0}},{func:te.FUNCTION_NAMES_MATH.SUM,filter:e=>{var t,n;return(((t=e.values.find(o=>o.func===te.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:t.value)??0)>1&&(((n=e.values.find(o=>o.func===te.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:n.value)??0)>0}},{func:te.FUNCTION_NAMES_STATISTICAL.COUNTA,filter:e=>{var t;return(((t=e.values.find(n=>n.func===te.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:t.value)??0)>1}},{func:te.FUNCTION_NAMES_STATISTICAL.COUNT,filter:e=>{var t,n;return(((t=e.values.find(o=>o.func===te.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:t.value)??0)>1&&(((n=e.values.find(o=>o.func===te.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:n.value)??0)>0}},{func:te.FUNCTION_NAMES_STATISTICAL.AVERAGE,filter:e=>{var t,n;return(((t=e.values.find(o=>o.func===te.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:t.value)??0)>1&&(((n=e.values.find(o=>o.func===te.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:n.value)??0)>0}}]);v(this,"_state$",new H.BehaviorSubject(null));v(this,"state$",this._state$.asObservable())}dispose(){this._state$.complete()}setState(e){const t={values:[],pattern:null};e==null||e.values.forEach(n=>{const o=this._functions.find(r=>r.func===n.func);o&&(o.filter===void 0||o.filter(e))&&t.values.push(n)}),t.pattern=(e==null?void 0:e.pattern)??null,this._state$.next(t)}getState(){return this._state$.getValue()}getFunctions(){return this._functions}addFunctions(e){this._functions.push(...e)}}const ji=D.createIdentifier("univer.sheet-status-bar.service"),wh="univer-status-bar",Th="univer-single-mode",Eh="univer-status-bar-div",yh="univer-statistic-list",Oh="univer-statistic-list-column",xh="univer-statistic-item",Ah="univer-statistic-picker",Dh="univer-statistic-picker-item",Nh="univer-statistic-more",_t={statusBar:wh,singleMode:Th,statusBarDiv:Eh,statisticList:yh,statisticListColumn:Oh,statisticItem:xh,statisticPicker:Ah,statisticPickerItem:Dh,statisticMore:Nh},Ph=[te.FUNCTION_NAMES_MATH.SUM,te.FUNCTION_NAMES_STATISTICAL.AVERAGE,te.FUNCTION_NAMES_STATISTICAL.MIN,te.FUNCTION_NAMES_STATISTICAL.MAX],ci={[te.FUNCTION_NAMES_MATH.SUM]:"statusbar.sum",[te.FUNCTION_NAMES_STATISTICAL.AVERAGE]:"statusbar.average",[te.FUNCTION_NAMES_STATISTICAL.MIN]:"statusbar.min",[te.FUNCTION_NAMES_STATISTICAL.MAX]:"statusbar.max",[te.FUNCTION_NAMES_STATISTICAL.COUNT]:"statusbar.count",[te.FUNCTION_NAMES_STATISTICAL.COUNTA]:"statusbar.countA",[te.FUNCTION_NAMES_TEXT.CONCATENATE]:"concatenate"},di=i=>{const e=K.useDependency(l.LocaleService),t=K.useDependency(I.IMessageService),n=K.useDependency(I.IClipboardInterfaceService),o=Hh(i),r=async()=>{await n.writeText(i.value.toString()),t.show({type:Se.MessageType.Success,content:e.t("statusbar.copied")})};return p.jsx(Se.Tooltip,{title:e.t("statusbar.clickToCopy"),placement:"top",children:p.jsx("div",{className:_t.statisticItem,onClick:r,children:p.jsx("span",{children:`${e.t((ci==null?void 0:ci[i.name])||i.name)}: ${o}`})},i.name)})};function Hh(i){const{pattern:e,value:t}=i;return typeof t!="number"?"Invalid input":t>=1e8?t.toExponential(2):e&&Ph.includes(i.name)?Zr.format(e,t):t.toLocaleString()}const xo=800,Lh=3,Uh=()=>{const[i,e]=P.useState(window.innerWidth<xo),[t,n]=P.useState(!0),o=K.useDependency(ji),r=o.getFunctions().map((m,g)=>({name:m.func,value:0,show:!0,disable:!1,pattern:null})),[s,a]=P.useState(r),c=s.find(m=>m.show&&!m.disable),d=i&&c?[c]:s.filter(m=>m.show&&!m.disable);P.useEffect(()=>{const m=o.state$.subscribe(g=>{const S=g==null?void 0:g.values;if(!S||S.length===0)n(!1);else{n(!0);const f=s.map(C=>{const R=S.find(M=>M.func===C.name);return R?(C.value=R.value,C.disable=!1):C.disable=!0,C.pattern=(g==null?void 0:g.pattern)??null,C});a(f)}});return()=>{m.unsubscribe()}},[o]);const u=kh(()=>{const m=window.innerWidth<xo;i!==m&&e(m)},100);P.useEffect(()=>(window.addEventListener("resize",u),()=>{window.removeEventListener("resize",u)}),[i]);let h=null;if(d.length>Lh){const m=[];d.forEach((g,S)=>{S%2===0&&m.push(d.slice(S,S+2))}),h=p.jsxs(p.Fragment,{children:[" ",m.map((g,S)=>p.jsxs("div",{className:_t.statisticListColumn,children:[(g==null?void 0:g[0])&&p.jsx(di,{...g==null?void 0:g[0]},g==null?void 0:g[0].name),(g==null?void 0:g[1])&&p.jsx(di,{...g==null?void 0:g[1]},g==null?void 0:g[1].name)]},`stat-col-${S}`))," "]})}else h=p.jsx(p.Fragment,{children:d.map(m=>p.jsx(di,{...m},m.name))});return t&&p.jsxs("div",{className:Bt(_t.statusBar,{[_t.singleMode]:i}),children:[p.jsx("div",{className:Bt(_t.statisticList),children:h}),p.jsx("div",{className:_t.statusBarDiv})]})};function kh(i,e){let t;return function(...n){const o=this,r=function(){t=null,i.apply(o,n)};clearTimeout(t),t=setTimeout(r,e)}}function Vh(){return p.jsxs("section",{className:Nr.sheetContainer,"data-range-selector":!0,children:[p.jsx(Mh,{}),p.jsx(Uh,{}),p.jsx(Mu,{})]})}function Bh(){return p.jsx(p.Fragment,{children:p.jsx(Bu,{})})}function Fh(){return p.jsxs(p.Fragment,{children:[p.jsx(Tu,{}),p.jsx(qu,{})]})}function Wh(i){const e=i.get(_.BorderStyleManagerService),t=_.getCurrentSheetDisabled$(i);return{id:_.SetBorderBasicCommand.id,icon:new H.Observable(n=>{const o="AllBorderSingle",r=i.get(_.BorderStyleManagerService),s=i.get(l.ICommandService).onCommandExecuted(a=>{if(a.id!==_.SetBorderBasicCommand.id)return;const{type:d}=r.getBorderInfo(),u=zr.find(m=>m.value===d),h=(u==null?void 0:u.icon)??o;n.next(h)});return n.next(o),s.dispose}),group:I.MenuGroup.TOOLBAR_FORMAT,tooltip:"toolbar.border.main",positions:[I.MenuPosition.TOOLBAR_START],type:I.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:$r,hoverable:!1},value$:e.borderInfo$}],value$:e.borderInfo$,hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:t}}const Kn="sheet.menu.clear-selection";function jh(){return{id:Kn,group:I.MenuGroup.CONTEXT_MENU_FORMAT,type:I.MenuItemType.SUBITEMS,icon:"ClearFormat",title:"rightClick.clearSelection",positions:[I.MenuPosition.CONTEXT_MENU,de.COL_HEADER_CONTEXT_MENU,de.ROW_HEADER_CONTEXT_MENU]}}function $h(){return{id:_.ClearSelectionContentCommand.id,type:I.MenuItemType.BUTTON,title:"rightClick.clearContent",positions:[Kn]}}function zh(){return{id:_.ClearSelectionFormatCommand.id,type:I.MenuItemType.BUTTON,title:"rightClick.clearFormat",positions:[Kn]}}function Xh(){return{id:_.ClearSelectionAllCommand.id,type:I.MenuItemType.BUTTON,title:"rightClick.clearAll",positions:[Kn]}}const qt="sheet.menu.delete";function Yh(){return{id:qt,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.delete",icon:"Reduce",positions:[I.MenuPosition.CONTEXT_MENU]}}function Zh(){return{id:Br.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,icon:"DeleteColumn",positions:[qt,de.COL_HEADER_CONTEXT_MENU],title:"rightClick.deleteSelectedColumn"}}function Gh(){return{id:Vr.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,icon:"DeleteRow",positions:[qt,de.ROW_HEADER_CONTEXT_MENU],title:"rightClick.deleteSelectedRow"}}function Kh(){return{id:Vi.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,title:"rightClick.moveLeft",icon:"DeleteCellShiftLeft",positions:[qt]}}function qh(){return{id:Bi.id,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.BUTTON,title:"rightClick.moveUp",icon:"DeleteCellShiftUp",positions:[qt]}}const $i="sheet.menu.col-insert";function Jh(){return{id:$i,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"Insert",positions:[de.COL_HEADER_CONTEXT_MENU]}}const zi="sheet.menu.row-insert";function Qh(){return{id:zi,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"Insert",positions:[de.ROW_HEADER_CONTEXT_MENU]}}const Jt="sheet.menu.cell-insert";function em(){return{id:Jt,group:I.MenuGroup.CONTEXT_MENU_LAYOUT,type:I.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"Insert",positions:[I.MenuPosition.CONTEXT_MENU]}}function tm(i){const e=i.get(_.SelectionManagerService);return{id:_.InsertRowBeforeCommand.id,type:I.MenuItemType.BUTTON,title:"rightClick.insertRowBefore",icon:"InsertRowAbove",positions:[zi,Jt],hidden$:new H.Observable(t=>{const n=e.getSelections();t.next((n==null?void 0:n.length)!==1)})}}function nm(i){const e=i.get(_.SelectionManagerService);return{id:_.InsertRowAfterCommand.id,type:I.MenuItemType.BUTTON,positions:[zi],title:"rightClick.insertRow",icon:"InsertRowBelow",hidden$:new H.Observable(t=>{const n=e.getSelections();t.next((n==null?void 0:n.length)!==1)})}}function im(i){const e=i.get(_.SelectionManagerService);return{id:_.InsertColBeforeCommand.id,type:I.MenuItemType.BUTTON,positions:[$i,Jt],title:"rightClick.insertColumnBefore",icon:"LeftInsertColumn",hidden$:new H.Observable(t=>{const n=e.getSelections();t.next((n==null?void 0:n.length)!==1)})}}function om(i){const e=i.get(_.SelectionManagerService);return{id:_.InsertColAfterCommand.id,type:I.MenuItemType.BUTTON,positions:[$i],title:"rightClick.insertColumn",icon:"RightInsertColumn",hidden$:new H.Observable(t=>{const n=e.getSelections();t.next((n==null?void 0:n.length)!==1)})}}function rm(){return{id:Wi.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveRight",icon:"InsertCellShiftRight",positions:[Jt]}}function sm(){return{id:Fi.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveDown",icon:"InsertCellDown",positions:[Jt]}}function am(i){const e=_.getCurrentSheetDisabled$(i);return{id:je.id,icon:"MergeAllSingle",tooltip:"toolbar.mergeCell.main",positions:[I.MenuPosition.TOOLBAR_START],group:I.MenuGroup.TOOLBAR_LAYOUT,type:I.MenuItemType.SUBITEMS,hidden$:I.getMenuHiddenObservable(i,l.UniverInstanceType.SHEET),disabled$:e}}function lm(i){return{id:Hr.id,type:I.MenuItemType.BUTTON,title:"merge.all",icon:"MergeAllSingle",positions:[je.id]}}function cm(i){return{id:Lr.id,type:I.MenuItemType.BUTTON,title:"merge.vertical",icon:"VerticalIntegrationSingle",positions:[je.id]}}function dm(i){return{id:Ur.id,type:I.MenuItemType.BUTTON,title:"merge.horizontal",icon:"HorizontalMergeSingle",positions:[je.id]}}function um(i){return{id:_.RemoveWorksheetMergeCommand.id,type:I.MenuItemType.BUTTON,title:"merge.cancel",icon:"CancelMergeSingle",positions:[je.id]}}function hm(i){const e=i.get(l.IUniverInstanceService),t=i.get(l.ICommandService);return{id:Fr.id,type:I.MenuItemType.BUTTON,positions:[de.SHEET_BAR],title:"sheetConfig.delete",disabled$:new H.Observable(n=>{const o=t.onCommandExecuted(r=>{const s=r.id;if(s===_.RemoveSheetMutation.id||s===_.InsertSheetMutation.id||s===_.SetWorksheetHideMutation.id){const a=e.getCurrentUniverSheetInstance().getWorksheets(),c=Array.from(a.values()).filter(d=>d.getConfig().hidden===l.BooleanNumber.FALSE);n.next(c.length===1)}});return n.next(!1),o.dispose})}}function mm(){return{id:_.CopySheetCommand.id,type:I.MenuItemType.BUTTON,positions:[de.SHEET_BAR],title:"sheetConfig.copy"}}function gm(){return{id:jr.id,type:I.MenuItemType.BUTTON,positions:[de.SHEET_BAR],title:"sheetConfig.rename"}}function Sm(){return{id:_.SetTabColorCommand.id,title:"sheetConfig.changeColor",positions:[de.SHEET_BAR],type:I.MenuItemType.SELECTOR,selections:[{label:{name:Xn,hoverable:!1}}]}}function _m(i){const e=i.get(l.IUniverInstanceService),t=i.get(l.ICommandService);return{id:_.SetWorksheetHideCommand.id,type:I.MenuItemType.BUTTON,positions:[de.SHEET_BAR],title:"sheetConfig.hide",disabled$:new H.Observable(n=>{const o=t.onCommandExecuted(r=>{const s=r.id;if(s===_.RemoveSheetMutation.id||s===_.InsertSheetMutation.id||s===_.SetWorksheetHideMutation.id){const a=e.getCurrentUniverSheetInstance().getWorksheets(),c=Array.from(a.values()).filter(d=>d.getConfig().hidden===l.BooleanNumber.FALSE);n.next(c.length===1)}});return n.next(!1),o.dispose})}}function fm(i){const e=i.get(l.IUniverInstanceService),t=i.get(l.ICommandService);return{id:Wr.id,type:I.MenuItemType.BUTTON,positions:[de.SHEET_BAR],title:"sheetConfig.unhide",disabled$:new H.Observable(n=>{const o=t.onCommandExecuted(r=>{const s=r.id;if(s===_.RemoveSheetMutation.id||s===_.InsertSheetMutation.id||s===_.SetWorksheetHideMutation.id){const a=e.getCurrentUniverSheetInstance().getWorksheets(),c=Array.from(a.values());n.next(c.length===1)}});return n.next(!1),o.dispose})}}const pm={id:_.SetRowHiddenCommand.id,preconditions:i=>ne(i),binding:I.KeyCode.Digit9|I.MetaKeys.CTRL_COMMAND},vm={id:_.SetColHiddenCommand.id,preconditions:i=>ne(i),binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT},Cm={id:Te.id,description:"shortcut.sheet.select-below-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN,priority:100,preconditions:ne,staticParameters:{direction:l.Direction.DOWN}},Im={id:Te.id,description:"shortcut.sheet.select-up-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP,priority:100,preconditions:ne,staticParameters:{direction:l.Direction.UP}},Rm={id:Te.id,description:"shortcut.sheet.select-left-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT,priority:100,preconditions:ne,staticParameters:{direction:l.Direction.LEFT}},Mm={id:Te.id,description:"shortcut.sheet.select-right-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT,priority:100,preconditions:ne,staticParameters:{direction:l.Direction.RIGHT}},bm={id:at.id,description:"shortcut.sheet.select-next-cell",group:"3_sheet-view",binding:I.KeyCode.TAB,priority:100,preconditions:ne,staticParameters:{direction:l.Direction.RIGHT,keycode:I.KeyCode.TAB}},wm={id:at.id,description:"shortcut.sheet.select-previous-cell",group:"3_sheet-view",binding:I.KeyCode.TAB|I.MetaKeys.SHIFT,priority:100,preconditions:ne,staticParameters:{direction:l.Direction.LEFT,keycode:I.KeyCode.TAB}},Tm={id:at.id,description:"shortcut.sheet.select-below-cell",group:"3_sheet-view",binding:I.KeyCode.ENTER,priority:100,preconditions:ne,staticParameters:{direction:l.Direction.DOWN,keycode:I.KeyCode.ENTER}},Em={id:at.id,description:"shortcut.sheet.select-up-cell",group:"3_sheet-view",binding:I.KeyCode.ENTER|I.MetaKeys.SHIFT,priority:100,preconditions:ne,staticParameters:{direction:l.Direction.UP,keycode:I.KeyCode.ENTER}},ym={id:Te.id,description:"shortcut.sheet.select-below-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN|I.MetaKeys.CTRL_COMMAND,preconditions:ne,staticParameters:{direction:l.Direction.DOWN,jumpOver:Le.moveGap}},Om={id:Te.id,description:"shortcut.sheet.select-up-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP|I.MetaKeys.CTRL_COMMAND,preconditions:ne,staticParameters:{direction:l.Direction.UP,jumpOver:Le.moveGap}},xm={id:Te.id,description:"shortcut.sheet.select-left-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT|I.MetaKeys.CTRL_COMMAND,preconditions:ne,staticParameters:{direction:l.Direction.LEFT,jumpOver:Le.moveGap}},Am={id:Te.id,description:"shortcut.sheet.select-right-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT|I.MetaKeys.CTRL_COMMAND,preconditions:ne,staticParameters:{direction:l.Direction.RIGHT,jumpOver:Le.moveGap}},Dm={id:Ue.id,description:"shortcut.sheet.expand-selection-down",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN|I.MetaKeys.SHIFT,preconditions:ne,staticParameters:{direction:l.Direction.DOWN}},Nm={id:Ue.id,description:"shortcut.sheet.expand-selection-up",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP|I.MetaKeys.SHIFT,preconditions:ne,staticParameters:{direction:l.Direction.UP}},Pm={id:Ue.id,description:"shortcut.sheet.expand-selection-left",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT|I.MetaKeys.SHIFT,preconditions:ne,staticParameters:{direction:l.Direction.LEFT}},Hm={id:Ue.id,description:"shortcut.sheet.expand-selection-right",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT|I.MetaKeys.SHIFT,preconditions:ne,staticParameters:{direction:l.Direction.RIGHT}},Lm={id:Ue.id,description:"shortcut.sheet.expand-selection-to-below-gap",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ne,staticParameters:{direction:l.Direction.DOWN,jumpOver:Le.moveGap}},Um={id:Ue.id,description:"shortcut.sheet.expand-selection-to-up-gap",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ne,staticParameters:{direction:l.Direction.UP,jumpOver:Le.moveGap}},km={id:Ue.id,description:"shortcut.sheet.expand-selection-to-left-gap",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ne,staticParameters:{direction:l.Direction.LEFT,jumpOver:Le.moveGap}},Vm={id:Ue.id,description:"shortcut.sheet.expand-selection-to-right-gap",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ne,staticParameters:{direction:l.Direction.RIGHT,jumpOver:Le.moveGap}},Bm={id:Qo.id,description:"shortcut.sheet.select-all",group:"3_sheet-view",binding:I.KeyCode.A|I.MetaKeys.CTRL_COMMAND,preconditions:ne,staticParameters:{expandToGapFirst:!0,loop:!0}},Fm={id:Ai.id,description:"shortcut.sheet.set-bold",group:"4_sheet-edit",preconditions:i=>ne(i),binding:I.KeyCode.B|I.MetaKeys.CTRL_COMMAND},Wm={id:Di.id,description:"shortcut.sheet.set-italic",group:"4_sheet-edit",preconditions:i=>ne(i),binding:I.KeyCode.I|I.MetaKeys.CTRL_COMMAND},jm={id:Ni.id,description:"shortcut.sheet.set-underline",group:"4_sheet-edit",preconditions:i=>ne(i),binding:I.KeyCode.U|I.MetaKeys.CTRL_COMMAND},$m={id:Pi.id,description:"shortcut.sheet.set-strike-through",group:"4_sheet-edit",preconditions:i=>ne(i),binding:I.KeyCode.X|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND},zm={id:_.ClearSelectionContentCommand.id,preconditions:i=>ne(i),binding:I.KeyCode.DELETE,mac:I.KeyCode.BACKSPACE},Xm={id:Zn.id,description:"shortcut.sheet.zoom-in",binding:I.KeyCode.EQUAL|I.MetaKeys.CTRL_COMMAND,group:"3_sheet-view",preconditions:ne,priority:1,staticParameters:{delta:.2}},Ym={id:l.NilCommand.id,binding:I.KeyCode.EQUAL|I.MetaKeys.CTRL_COMMAND},Zm={id:Zn.id,description:"shortcut.sheet.zoom-out",binding:I.KeyCode.MINUS|I.MetaKeys.CTRL_COMMAND,group:"3_sheet-view",preconditions:ne,priority:1,staticParameters:{delta:-.2}},Gm={id:l.NilCommand.id,binding:I.KeyCode.MINUS|I.MetaKeys.CTRL_COMMAND},Km={id:Zn.id,description:"shortcut.sheet.reset-zoom",binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND,preconditions:ne,group:"3_sheet-view",priority:1,staticParameters:{reset:!0}},qm={id:l.NilCommand.id,binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND};var Jm=Object.defineProperty,Qm=Object.getOwnPropertyDescriptor,eg=(i,e,t,n)=>{for(var o=n>1?void 0:n?Qm(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&Jm(e,t,o),o},St=(i,e)=>(t,n)=>e(t,n,i);let Dn=class extends l.Disposable{constructor(i,e,t,n,o,r){super(),this._injector=i,this._componentManager=e,this._commandService=t,this._shortcutService=n,this._menuService=o,this._uiController=r,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Ui,Cl)),this.disposeWithMe(i.register($r,fu)),this.disposeWithMe(i.register(Xn,Se.ColorPicker)),this.disposeWithMe(i.register(Er,I.FontFamily)),this.disposeWithMe(i.register(yr,I.FontFamilyItem)),this.disposeWithMe(i.register(Or,I.FontSize))}_initCommands(){[Hr,je,Ur,Lr,Zn,Ue,Te,at,jr,Fr,Vr,Br,_r,fr,vt,Qo,Pr,jn,_.SetBoldCommand,$t,He,Ai,Di,Ni,Pi,dl,ul,pr,vr,Vn,_.SetItalicCommand,_.SetStrikeThroughCommand,_.SetFontFamilyCommand,_.SetFontSizeCommand,Hi,Rr,Li,Mr,Tt,Cn,zn,br,wr,Tr,_.SetUnderlineCommand,Gn,We,Wr,kr,Fi,Bi,Wi,Vi].forEach(i=>{this.disposeWithMe(this._commandService.registerCommand(i))})}_initMenus(){[Ll,Ul,kl,Vl,Bl,Fl,Wl,$h,zh,Xh,jh,Jh,Qh,em,tm,nm,im,om,Gh,Kl,Jl,ql,Ql,Zh,ec,jl,tc,Yh,Kh,qh,rm,sm,Xl,Yl,Zl,Gl,$l,zl,Il,Rl,Ml,bl,wl,Tl,El,yl,Ol,xl,Al,Wh,am,lm,cm,dm,um,Dl,Nl,Pl,Hl,hm,mm,gm,Sm,_m,fm].forEach(i=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(i)))})}_initShortcuts(){[Cm,Im,Rm,Mm,bm,wm,Tm,Em,ym,Om,xm,Am,Dm,Nm,Pm,Hm,Lm,Um,km,Vm,Bm,Xm,Zm,Km,qm,Ym,Gm,Fm,Wm,jm,$m,zm,...Ic(),Rc,Mc,wc,Tc,Ec,bc,pm,vm].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_initWorkbenchParts(){this.disposeWithMe(this._uiController.registerHeaderComponent(()=>K.connectInjector(Bh,this._injector))),this.disposeWithMe(this._uiController.registerFooterComponent(()=>K.connectInjector(Vh,this._injector))),this.disposeWithMe(this._uiController.registerContentComponent(()=>K.connectInjector(Fh,this._injector)))}_init(){this._initCustomComponents(),this._initCommands(),this._initMenus(),this._initShortcuts(),this._initWorkbenchParts()}};Dn=eg([l.OnLifecycle(l.LifecycleStages.Ready,Dn),St(0,D.Inject(D.Injector)),St(1,D.Inject(I.ComponentManager)),St(2,l.ICommandService),St(3,I.IShortcutService),St(4,I.IMenuService),St(5,I.IUIController)],Dn);var tg=Object.defineProperty,ng=Object.getOwnPropertyDescriptor,ig=(i,e,t,n)=>{for(var o=n>1?void 0:n?ng(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&tg(e,t,o),o},tt=(i,e)=>(t,n)=>e(t,n,i);let Nn=class extends l.Disposable{constructor(e,t,n,o,r,s,a){super();v(this,"_calculateTimeout",-1);this._univerInstanceService=e,this._selectionManagerService=t,this._functionService=n,this._statusBarService=o,this._commandService=r,this._formulaDataModel=s,this._numfmtService=a,this._init()}_init(){this._registerSelectionListener()}_registerSelectionListener(){this.disposeWithMe(l.toDisposable(this._selectionManagerService.selectionMoving$.subscribe(e=>{var t;((t=this._selectionManagerService.getCurrent())==null?void 0:t.pluginName)===_.NORMAL_SELECTION_PLUGIN_NAME&&e&&(clearTimeout(this._calculateTimeout),this._calculateTimeout=setTimeout(()=>{const n=e[e.length-1].primary;this._calculateSelection(e.map(o=>o.range),n)},100))}))),this.disposeWithMe(l.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(e=>{var t;if(((t=this._selectionManagerService.getCurrent())==null?void 0:t.pluginName)===_.NORMAL_SELECTION_PLUGIN_NAME&&e){const n=e[e.length-1].primary;this._calculateSelection(e.map(o=>o.range),n)}}))),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===_.SetRangeValuesMutation.id){const t=this._selectionManagerService.getSelections();t&&(clearTimeout(this._calculateTimeout),this._calculateTimeout=setTimeout(()=>{this._calculateSelection(t.map(n=>n.range))},100))}}))}_calculateSelection(e,t){var c;const n=this._univerInstanceService.getCurrentUniverSheetInstance(),o=n.getUnitId(),r=n.getActiveSheet().getSheetId(),s={},a=this._formulaDataModel.getArrayFormulaCellData();if(this._univerInstanceService.getCurrentUniverSheetInstance().getSheets().forEach(d=>{const u=d.getConfig();s[d.getSheetId()]={cellData:new l.ObjectMatrix(u.cellData),rowCount:u.rowCount,columnCount:u.columnCount}}),e!=null&&e.length){const d=e.map(f=>new te.RangeReferenceObject(f,r,o));d.forEach(f=>{f.setUnitData({[o]:s}),a&&f.setArrayFormulaCellData(te.convertUnitDataToRuntime(a))});const h=this._statusBarService.getFunctions().map(f=>{const C=this._functionService.getExecutor(f.func);if(!C)return;const R=d.map(T=>T.toArrayValueObject(!1));if((C==null?void 0:C.calculate(...R)).getValue)return{func:f.func,value:(C==null?void 0:C.calculate(...R)).getValue()}});if(h.every(f=>f===void 0))return;let m=null;if(t){const{actualRow:f,actualColumn:C}=t;m=(c=this._numfmtService.getValue(o,r,f,C))==null?void 0:c.pattern}const S={values:h.filter(f=>f!==void 0),pattern:m};this._statusBarService.setState(S)}else this._statusBarService.setState(null)}_isSingleCell(e){return e.startRow===e.endRow&&e.startColumn===e.endColumn}};Nn=ig([l.OnLifecycle(l.LifecycleStages.Ready,Nn),tt(0,l.IUniverInstanceService),tt(1,D.Inject(_.SelectionManagerService)),tt(2,te.IFunctionService),tt(3,ji),tt(4,l.ICommandService),tt(5,D.Inject(te.FormulaDataModel)),tt(6,D.Inject(_.INumfmtService))],Nn);var og=Object.defineProperty,rg=Object.getOwnPropertyDescriptor,sg=(i,e,t,n)=>{for(var o=n>1?void 0:n?rg(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&og(e,t,o),o},nt=(i,e)=>(t,n)=>e(t,n,i);let Pn=class extends l.Disposable{constructor(i,e,t,n,o,r,s){super(),this._sheetSkeletonManagerService=i,this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._selectionRenderService=o,this._selectionManagerService=r,this._scrollManagerService=s,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._zoomEventBinding()}_zoomEventBinding(){var e;const i=(e=this._getSheetObject())==null?void 0:e.scene;i!=null&&(i.getViewport(V.VIEW_MAIN),this.disposeWithMe(l.toDisposable(i.onMouseWheelObserver.add((t,n)=>{if(!t.ctrlKey)return;const o=Math.abs(t.deltaX);let r=o<40?.2:o<80?.4:.2;r*=t.deltaY>0?-1:1,i.scaleX<1&&(r/=2);const s=this._currentUniverService.getCurrentUniverSheetInstance(),a=s.getActiveSheet(),c=a.getZoomRatio();let d=+parseFloat(`${c+r}`).toFixed(1);d=d>=4?4:d<=.1?.1:d,this._commandService.executeCommand(Gn.id,{zoomRatio:Math.round(d*10)/10,unitId:s.getUnitId(),subUnitId:a.getSheetId()}),t.preventDefault()}))))}_skeletonListener(){this.disposeWithMe(l.toDisposable(this._sheetSkeletonManagerService.currentSkeletonBefore$.subscribe(i=>{if(i==null)return;const n=this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getZoomRatio()||1;this._updateViewZoom(n)})))}_commandExecutedListener(){const i=[We.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(i.includes(e.id)){const t=this._currentUniverService.getCurrentUniverSheetInstance(),n=t.getActiveSheet(),o=e.params,{unitId:r,subUnitId:s}=o;if(!(r===t.getUnitId()&&s===n.getSheetId()))return;const a=n.getConfig().zoomRatio||1;this._updateViewZoom(a)}}))}_updateViewZoom(i){const e=this._getSheetObject();e==null||e.scene.scale(i,i),e==null||e.spreadsheet.makeForceDirty()}_getSheetObject(){return ve(this._currentUniverService,this._renderManagerService)}};Pn=sg([l.OnLifecycle(l.LifecycleStages.Rendered,Pn),nt(0,D.Inject(exports.SheetSkeletonManagerService)),nt(1,l.IUniverInstanceService),nt(2,l.ICommandService),nt(3,b.IRenderManagerService),nt(4,_e),nt(5,D.Inject(_.SelectionManagerService)),nt(6,D.Inject(Je))],Pn);var ag=Object.defineProperty,lg=Object.getOwnPropertyDescriptor,cg=(i,e,t,n)=>{for(var o=n>1?void 0:n?lg(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&ag(e,t,o),o},Lt=(i,e)=>(t,n)=>e(t,n,i);exports.SheetCanvasView=class extends l.RxDisposable{constructor(t,n,o,r,s){super();v(this,"_scene");v(this,"_currentWorkbook");v(this,"_loadedMap",new Set);v(this,"_isLoadedEditor",!1);v(this,"_fps$",new H.BehaviorSubject(""));v(this,"fps$",this._fps$.asObservable());this._currentUniverService=t,this._commandService=n,this._renderManagerService=o,this._selectionRenderService=r,this._sheetSkeletonManagerService=s,this._currentUniverService.currentSheet$.subscribe(a=>{if(a==null)return;const c=a.getUnitId();this._loadedMap.has(c)||(this._currentWorkbook=a,this._addNewRender(),this._loadedMap.add(c))})}dispose(){this._fps$.complete()}_addNewRender(){const t=this._currentWorkbook,n=t.getUnitId(),o=t.getContainer(),r=t.getParentRenderUnitId();if(o!=null&&r!=null)throw new Error("container or parentRenderUnitId can only exist one");const s=o==null&&r!=null;s?this._renderManagerService.createRenderWithParent(n,r):this._renderManagerService.createRender(n);const a=this._renderManagerService.getRenderById(n);if(a==null)return;const{scene:c,engine:d}=a;c.openTransformer(),this._scene=c,c.addLayer(new b.Layer(c,[],0),new b.Layer(c,[],2)),a!=null&&this._addComponent(a),t.getShouldRenderLoopImmediately()&&!s&&d.runRenderLoop(()=>{c.render(),this._fps$.next(Math.round(d.getFps()).toString())}),this._renderManagerService.setCurrent(n)}_addComponent(t){const n=this._scene,o=this._currentWorkbook,r=o.getActiveSheet(),s=o.getUnitId(),a=r.getSheetId();this._addViewport(r);const c=new b.Spreadsheet(fe.MAIN),d=new b.SpreadsheetRowHeader(fe.ROW),u=new b.SpreadsheetColumnHeader(fe.COLUMN),h=new b.Rect(fe.LEFT_TOP,{zIndex:2,left:-1,top:-1,fill:"rgb(248, 249, 250)",stroke:"rgb(217, 217, 217)",strokeWidth:1});t.mainComponent=c,t.components.set(fe.MAIN,c),t.components.set(fe.ROW,d),t.components.set(fe.COLUMN,u),t.components.set(fe.LEFT_TOP,h),n.addObjects([c],qi),n.addObjects([d,u,h],qe),n.enableLayerCache(qi,qe),this._sheetSkeletonManagerService.setCurrent({sheetId:a,unitId:s})}_addViewport(t){const n=this._scene;if(n==null)return;const{rowHeader:o,columnHeader:r}=t.getConfig(),s=new b.Viewport(V.VIEW_MAIN,n,{left:o.width,top:r.height,bottom:0,right:0,isWheelPreventDefaultX:!0});return new b.Viewport(V.VIEW_ROW_TOP,n,{active:!1,isWheelPreventDefaultX:!0}),new b.Viewport(V.VIEW_ROW_BOTTOM,n,{left:0,top:r.height,bottom:0,width:o.width,isWheelPreventDefaultX:!0}),new b.Viewport(V.VIEW_COLUMN_LEFT,n,{active:!1,isWheelPreventDefaultX:!0}),new b.Viewport(V.VIEW_COLUMN_RIGHT,n,{left:o.width,top:0,height:r.height,right:0,isWheelPreventDefaultX:!0}),new b.Viewport(V.VIEW_LEFT_TOP,n,{left:0,top:0,width:o.width,height:r.height,isWheelPreventDefaultX:!0}),new b.Viewport(V.VIEW_MAIN_LEFT_TOP,n,{isWheelPreventDefaultX:!0,active:!1}),new b.Viewport(V.VIEW_MAIN_LEFT,n,{isWheelPreventDefaultX:!0,active:!1}),new b.Viewport(V.VIEW_MAIN_TOP,n,{isWheelPreventDefaultX:!0,active:!1}),n.onMouseWheelObserver.add((a,c)=>{if(a.ctrlKey)return;let d=0,u=0;const h=s.limitedScroll();if(a.inputIndex===b.PointerInput.MouseWheelX){const g=Math.abs(a.deltaX);a.deltaX>0?d=g:d=-g,this._commandService.executeCommand(Cn.id,{offsetX:d}),n.getParent().classType===b.RENDER_CLASS_TYPE.SCENE_VIEWER?h!=null&&h.isLimitedX||c.stopPropagation():s.isWheelPreventDefaultX?a.preventDefault():h!=null&&h.isLimitedX||a.preventDefault()}if(a.inputIndex===b.PointerInput.MouseWheelY){let g=Math.abs(a.deltaY);a.shiftKey?(g*=3,a.deltaY>0?d=g:d=-g,this._commandService.executeCommand(Cn.id,{offsetX:d}),n.getParent().classType===b.RENDER_CLASS_TYPE.SCENE_VIEWER?h!=null&&h.isLimitedX||c.stopPropagation():s.isWheelPreventDefaultX?a.preventDefault():h!=null&&h.isLimitedX||a.preventDefault()):(a.deltaY>0?u=g:u=-g,this._commandService.executeCommand(Cn.id,{offsetY:u}),n.getParent().classType===b.RENDER_CLASS_TYPE.SCENE_VIEWER?h!=null&&h.isLimitedY||c.stopPropagation():s.isWheelPreventDefaultY?a.preventDefault():h!=null&&h.isLimitedY||a.preventDefault())}a.inputIndex,b.PointerInput.MouseWheelZ,this._scene.makeDirty(!0)}),new b.ScrollBar(s),n.attachControl(),s}};exports.SheetCanvasView=cg([l.OnLifecycle(l.LifecycleStages.Ready,exports.SheetCanvasView),Lt(0,l.IUniverInstanceService),Lt(1,l.ICommandService),Lt(2,b.IRenderManagerService),Lt(3,_e),Lt(4,D.Inject(exports.SheetSkeletonManagerService))],exports.SheetCanvasView);var dg=Object.defineProperty,ug=Object.getOwnPropertyDescriptor,hg=(i,e,t,n)=>{for(var o=n>1?void 0:n?ug(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&dg(e,t,o),o},ui=(i,e)=>(t,n)=>e(t,n,i),hi;exports.UniverSheetsUIPlugin=(hi=class extends l.Plugin{constructor(e,t,n,o){super(Ho),this._injector=t,this._localeService=n,this._currentUniverService=o,this._localeService.load({zhCN:xr})}onStarting(e){[[exports.SheetCanvasView],[Wt],[Ee,{useClass:exports.EditorBridgeService}],[bt,{useClass:exports.SheetClipboardService}],[xt,{useClass:Qd}],[Et,{useClass:vi}],[Kt,{useClass:Ar}],[Yn,{useClass:oc}],[Yt,{useClass:exports.AutoFillService}],[Je],[exports.SheetSkeletonManagerService],[_e,{useClass:exports.SelectionRenderService}],[ji,{useClass:bh}],[Xt,{useClass:exports.MarkSelectionService}],[cn],[dn],[pn],[gn],[Sn],[vn],[In],[Rn],[Mn],[bn],[wn],[_n],[En],[Ct],[On],[un],[hn],[yn],[xn],[Dn],[fn],[Pn],[exports.AutoFillController],[Nn],[mn],[Tn]].forEach(t=>e.add(t))}onReady(){this._markSheetAsFocused()}_markSheetAsFocused(){const e=this._currentUniverService;e.currentSheet$.pipe(Ao.filter(t=>!!t)).subscribe(t=>{e.focusUniverInstance(t.getUnitId())})}},v(hi,"type",l.PluginType.Sheet),hi);exports.UniverSheetsUIPlugin=hg([ui(1,D.Inject(D.Injector)),ui(2,D.Inject(l.LocaleService)),ui(3,l.IUniverInstanceService)],exports.UniverSheetsUIPlugin);exports.APPLY_TYPE=ie;exports.AutoFillCommand=ko;exports.COPY_TYPE=ot;exports.CellEditorManagerService=Ar;exports.DATA_TYPE=ue;exports.DefaultRightMenuConfig=Do;exports.DefaultSheetContainerConfig=Po;exports.DefaultSheetUIConfig=Gr;exports.DefaultToolbarConfig=No;exports.ExpandSelectionCommand=Ue;exports.IAutoFillService=Yt;exports.ICellEditorManagerService=Kt;exports.IEditorBridgeService=Ee;exports.IFormulaEditorManagerService=Yn;exports.IMarkSelectionService=Xt;exports.ISelectionRenderService=_e;exports.ISheetClipboardService=bt;exports.JumpOver=Le;exports.MoveSelectionCommand=Te;exports.PASTE_SPECIAL_MENU_ID=Ot;exports.PREDEFINED_HOOK_NAME=pe;exports.RangeSelector=qa;exports.SHEET_UI_PLUGIN_NAME=Ho;exports.SelectionShape=Un;exports.SetCellEditVisibleArrowOperation=$t;exports.SetEditorResizeOperation=jn;exports.SetScrollOperation=Tt;exports.SetZoomRatioOperation=We;exports.SheetCopyCommand=zo;exports.SheetPasteCommand=wt;exports.VIEWPORT_KEY=V;exports.enUS=nc;exports.getAutoFillRepeatRange=cs;exports.getCoordByCell=Ci;exports.getCoordByOffset=Mt;exports.getEditorObject=Wn;exports.getRepeatRange=ic;exports.getSheetObject=ve;exports.getTransformCoord=ln;exports.whenFormulaEditorActivated=us;exports.zhCN=xr;