@univerjs/sheets-ui 0.6.3-nightly.202503041606 → 0.6.3-nightly.202503061606

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -44,7 +44,7 @@
44
44
  univer-box-border univer-flex univer-items-center univer-justify-between univer-bg-white univer-px-5
45
45
  univer-text-gray-900
46
46
  dark:univer-bg-gray-900 dark:univer-text-gray-200
47
- `,style:{height:hl},"data-range-selector":!0,children:[I.jsx(ul,{}),I.jsx(lm,{}),e.length&&I.jsx("div",{className:"univer-mr-2 univer-flex univer-gap-2",children:e.map(t=>{var r;return(r=t.children)==null?void 0:r.map(o=>(o==null?void 0:o.item)&&I.jsx(_.ToolbarItem,{...o.item},o.key))})}),I.jsx(qu,{})]})}function gl(){return fl()?I.jsx(cl,{}):null}function Sl(){return fl()?I.jsxs(I.Fragment,{children:[I.jsx($u,{}),I.jsx(Xu,{})]}):null}function fl(){const n=_.useDependency(a.IUniverInstanceService),e=!!_.useObservable(()=>n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),null,!1,[]);return V.useMemo(()=>n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).length>0,[n,e])}var cm=Object.getOwnPropertyDescriptor,dm=(n,i,e,t)=>{for(var r=t>1?void 0:t?cm(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=s(r)||r);return r},sn=(n,i)=>(e,t)=>i(e,t,n);const ra=5,ia=2;exports.SheetCellEditorResizeService=class extends a.Disposable{constructor(i,e,t,r,o,s,l){super(),this._context=i,this._layoutService=e,this._cellEditorManagerService=t,this._editorBridgeService=r,this._renderManagerService=o,this._sheetSkeletonManagerService=s,this._univerInstanceService=l}fitTextSize(i){var A,k,N,H;const e=this._editorBridgeService.getEditCellState();if(!e)return;const{position:t,documentLayoutObject:r,canvasOffset:o,scaleX:s,scaleY:l}=e,{startX:c,startY:d,endX:u,endY:h}=t,g=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);if(g==null)return;const S=this._getEditorSkeleton();if(!S)return;const f=this._predictingSize(t,o,S,r,s,l);if(!f)return;let{actualWidth:p,actualHeight:v}=f;const{verticalAlign:C,horizontalAlign:b,paddingData:R,fill:w}=r;p=p+((A=R.l)!=null?A:0)+((k=R.r)!=null?k:0),v=v+((N=R.t)!=null?N:0)+((H=R.b)!=null?H:0);let M=u-c,y=h-d;M<p&&(M=Math.ceil(p)),y<v&&(y=Math.ceil(v));let P=0;C===a.VerticalAlign.MIDDLE?P=(y-v)/2/l:C===a.VerticalAlign.TOP?P=R.t||0:P=(y-v)/l;let x=0;b===a.HorizontalAlign.CENTER?x=(M-p)/2/s:b===a.HorizontalAlign.RIGHT?x=(M-p)/s:x=R.l||0,P=P<(R.t||0)?R.t||0:P,x=x<(R.l||0)?R.l||0:x,g.updateDocumentDataMargin({t:P,l:x}),S.calculate(),this._editAreaProcessing(M,y,t,o,w,s,l,b,i)}_predictingSize(i,e,t,r,o=1,s=1){const{startX:l,endX:c}=i,{textRotation:d,wrapStrategy:u,paddingData:h}=r,g=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC),{vertexAngle:S}=T.convertTextRotation(d);if(u===a.WrapStrategy.WRAP&&S===0){g==null||g.updateDocumentDataPageSize(c-l),g==null||g.updateDocumentDataMargin({l:h.l,t:h.t}),t.calculate();const{actualWidth:C,actualHeight:b}=t.getActualSize();return{actualWidth:C*o,actualHeight:b*s}}const f=this._getEditorMaxSize(i,e,r.horizontalAlign);if(!f)return;g==null||g.updateDocumentDataPageSize(f.width/o),t.calculate();const p=t.getActualSize();let v=c-l;return v<p.actualWidth*o+ra*o&&(v=p.actualWidth*o+ra*o),g==null||g.updateDocumentDataPageSize(v/o),g==null||g.updateDocumentRenderConfig({horizontalAlign:a.HorizontalAlign.UNSPECIFIED,cellValueType:void 0}),{actualWidth:p.actualWidth*o,actualHeight:p.actualHeight*s}}_getEditorMaxSize(i,e,t){if(this._getEditorObject()==null)return;function o(b){return Number.parseInt(b.replace("px",""))}const l=this._context.engine.getCanvasElement(),c=l.getBoundingClientRect(),d=o(l.style.width),{width:u}=c,h=u/d,{startX:g,startY:S,endX:f}=i,p=this._context.engine.width,v=document.body.clientHeight-S-hl-e.top-ia*2;let C=u-g;if(t===a.HorizontalAlign.CENTER){const b=p-f,R=g;C=f-g+Math.min(R,b)*2}else t===a.HorizontalAlign.RIGHT&&(C=f);return{height:v,width:C-ia,scaleAdjust:h}}_editAreaProcessing(i,e,t,r,o,s=1,l=1,c,d){var D;const u=this._getEditorObject();if(u==null)return;const g=this._context.engine.getCanvasElement();let{startX:S,startY:f}=t;const{document:p,scene:v,engine:C}=u,b=v.getViewport($.VIEWPORT_KEY.VIEW_MAIN),R=this._getEditorMaxSize(t,r,c),{height:w,width:M,scaleAdjust:y}=R;let P=e,x=b==null?void 0:b.getScrollBar();P>w?(x==null?b&&new T.ScrollBar(b,{enableHorizontal:!1,barSize:8}):b==null||b.resetCanvasSizeAndUpdateScroll(),b==null||b.scrollToViewportPos({viewportScrollY:P-w}),P=w):(x=null,(D=b==null?void 0:b.getScrollBar())==null||D.dispose()),i+=(x==null?void 0:x.barSize)||0,i>M&&(i=M),this._addBackground(v,i/s,e/l,o);const{scaleX:A,scaleY:k}=v.getPrecisionScale();v.transformByState({width:i*y/s,height:e*y/l,scaleX:s*y,scaleY:l*y}),p.resize(i*y/s,e*y/l),setTimeout(()=>{C.resizeBySize(T.fixLineWidthByScale(i,A),T.fixLineWidthByScale(P,k)),d==null||d()},0);const N=this._layoutService.getContentElement().getBoundingClientRect(),H=g.getBoundingClientRect();S=S*y+(H.left-N.left),f=f*y+(H.top-N.top);const W=t.endX-t.startX;c===a.HorizontalAlign.RIGHT?S+=(W-i)*y:c===a.HorizontalAlign.CENTER&&(S+=(W-i*y)/2),this._cellEditorManagerService.setState({startX:S,startY:f,endX:i*y+S,endY:P*y+f,show:!0})}_addBackground(i,e,t,r){const o="_backgroundRectHelperColor_",s=i.getObject(o);s==null&&r==null||(s==null?i.addObjects([new T.Rect(o,{width:e,height:t,fill:r,evented:!1})],$.DOCS_COMPONENT_MAIN_LAYER_INDEX):r==null?s.dispose():(s.setProps({fill:r}),s.transformByState({width:e,height:t})))}resizeCellEditor(i){var y;const e=this._cellEditorManagerService.getState();if(!e||!this._editorBridgeService.isVisible().visible)return;this._editorBridgeService.refreshEditCellPosition(!0);const t=this._editorBridgeService.getEditCellState();if(!t)return;const r=(y=this._sheetSkeletonManagerService.getSkeletonParam(t.sheetId))==null?void 0:y.skeleton;if(!r)return;const{row:o,column:s,scaleX:l,scaleY:c,position:d,canvasOffset:u,documentLayoutObject:h}=t,{horizontalAlign:g}=h,S=this._getEditorMaxSize(d,u,g);if(!S)return;const{height:f,width:p,scaleAdjust:v}=S,C=r.getCellWithCoordByIndex(o,s),b=Math.min((C.mergeInfo.endY-C.mergeInfo.startY)*c,f)*v,R=Math.min((C.mergeInfo.endX-C.mergeInfo.startX)*l,p)*v,w=e.endY-e.startY,M=e.endX-e.startX;if(w!==b||M!==R){if(this._editorBridgeService.refreshEditCellPosition(!0),!this._getEditorSkeleton())return;this.fitTextSize(i)}}_getEditorObject(){return Mi(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}_getEditorSkeleton(){var i;return(i=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:i.with(Re.DocSkeletonManagerService).getSkeleton()}};exports.SheetCellEditorResizeService=dm([sn(1,_.ILayoutService),sn(2,mr),sn(3,Se),sn(4,T.IRenderManagerService),sn(5,a.Inject(exports.SheetSkeletonManagerService)),sn(6,a.IUniverInstanceService)],exports.SheetCellEditorResizeService);function Es(n){return n.getContextValue(a.FOCUSING_SHEET)}function ae(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function pl(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function um(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function hm(n){return n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function vl(n){return n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function mm(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.EDITOR_ACTIVATED)&&n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function rr(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&!n.getContextValue(a.FOCUSING_EDITOR_STANDALONE)}const Cl=[_.KeyCode.ARROW_DOWN,_.KeyCode.ARROW_UP,_.KeyCode.ARROW_LEFT,_.KeyCode.ARROW_RIGHT],gm=[_.KeyCode.ENTER,_.KeyCode.TAB,...Cl];function _l(){const n=[];for(const i of Cl)n.push({id:zt.id,binding:i,preconditions:e=>rr(e),staticParameters:{visible:!1,eventType:T.DeviceInputEventType.Keyboard,keycode:i,isShift:!1}}),n.push({id:zt.id,binding:i|_.MetaKeys.SHIFT,preconditions:e=>rr(e),staticParameters:{visible:!1,eventType:T.DeviceInputEventType.Keyboard,keycode:i,isShift:!0}});return n}const Il={id:hr.id,binding:_.KeyCode.F2,description:"shortcut.sheet.start-editing",group:"4_sheet-edit",preconditions:ae,staticParameters:{visible:!0,eventType:T.DeviceInputEventType.Keyboard,keycode:_.KeyCode.F2}},bl={id:Ce.id,binding:_.KeyCode.ENTER,description:"shortcut.sheet.toggle-editing",group:"4_sheet-edit",preconditions:n=>rr(n),staticParameters:{visible:!1,eventType:T.DeviceInputEventType.Keyboard,keycode:_.KeyCode.ENTER}},Rl={id:Ce.id,binding:_.KeyCode.TAB,preconditions:n=>rr(n),staticParameters:{visible:!1,eventType:T.DeviceInputEventType.Keyboard,keycode:_.KeyCode.TAB}},El={id:Ce.id,binding:_.KeyCode.ESC,description:"shortcut.sheet.abort-editing",group:"4_sheet-edit",preconditions:n=>rr(n),staticParameters:{visible:!1,eventType:T.DeviceInputEventType.Keyboard,keycode:_.KeyCode.ESC}},wl={id:$.BreakLineCommand.id,description:"shortcut.sheet.break-line",group:"4_sheet-edit",preconditions:n=>um(n),binding:_.KeyCode.ENTER|_.MetaKeys.ALT},Tl={id:$.DeleteLeftCommand.id,preconditions:n=>hm(n)||vl(n),binding:_.KeyCode.BACKSPACE},yl={id:Ce.id,description:"shortcut.sheet.delete-and-start-editing",group:"4_sheet-edit",preconditions:n=>ae(n)&&!vl(n),binding:_.KeyCode.BACKSPACE,staticParameters:{visible:!0,eventType:T.DeviceInputEventType.Keyboard,keycode:_.KeyCode.BACKSPACE}};function Sm(n){return n.startsWith("'")}function fm(n){return n.slice(1)}const pm={"0":"0","1":"1","2":"2","3":"3","4":"4","5":"5","6":"6","7":"7","8":"8","9":"9",A:"A",B:"B",C:"C",D:"D",E:"E",F:"F",G:"G",H:"H",I:"I",J:"J",K:"K",L:"L",M:"M",N:"N",O:"O",P:"P",Q:"Q",R:"R",S:"S",T:"T",U:"U",V:"V",W:"W",X:"X",Y:"Y",Z:"Z",a:"a",b:"b",c:"c",d:"d",e:"e",f:"f",g:"g",h:"h",i:"i",j:"j",k:"k",l:"l",m:"m",n:"n",o:"o",p:"p",q:"q",r:"r",s:"s",t:"t",u:"u",v:"v",w:"w",x:"x",y:"y",z:"z","%":"%","-":"-",".":".",":":":","/":"/","+":"+","@":"@","&":"&","*":"*","#":"#","=":"=",">":">","<":"<","$":"$",""":'"',"'":"'","(":"(",")":")"," ":" ",",":",","!":"!","?":"?",";":";","[":"[","]":"]","{":"{","}":"}"},jo={true:"TRUE",false:"FALSE"};function vm(n){return[a.LocaleType.ZH_CN,a.LocaleType.ZH_TW].includes(n)}function Cm(n,i,e,t){let r=n;if(vm(e)){if(n.startsWith("'")||n.startsWith("'"))return`'${n.slice(1)}`;r=_m(r)}if(r.startsWith("="))return Im(n,r,i,t);const o=r.toLowerCase();return jo[o]?jo[o]:a.numfmt.parseValue(r)==null?n:r}function _m(n){const i=/['"].*?['"]/g,e=[],t=n.split(i);n.replace(i,o=>(e.push(o),""));let r=t.join("").split("").map(Em).join("");return e.forEach((o,s)=>{r=r.slice(0,s*2)+o+r.slice((s+1)*2)}),r}function Im(n,i,e,t){const r=e.sequenceNodesBuilder(i);if(!r)return n;let o=i,s=0;return r.forEach((l,c)=>{if(typeof l=="object"){const d=l.token;if(jo[d.toLowerCase()]){const u=l.startIndex+s+1,h=l.endIndex+s+2;o=an(d.toLocaleUpperCase(),o,u,h)}else if(l.nodeType===Z.sequenceNodeType.FUNCTION&&bm(d,t,r,c)||l.nodeType===Z.sequenceNodeType.REFERENCE){const u=d.indexOf("!");if(u>-1){const h=d.substring(u+1),g=l.startIndex+s+(u+1)+1,S=l.endIndex+s+2;o=an(h.toLocaleUpperCase(),o,g,S)}else{const h=l.startIndex+s+1,g=l.endIndex+s+2;o=an(d.toLocaleUpperCase(),o,h,g)}}else if(d.startsWith('"')&&d.endsWith('"')||d.startsWith("'")&&d.endsWith("'")){const u=l.startIndex+s+2,h=l.endIndex+s+1;o=an(n.slice(u,h),o,u,h)}else if(l.nodeType!==Z.sequenceNodeType.ARRAY){const u=a.numfmt.parseValue(d);if(u==null){const h=l.startIndex+s+1,g=l.endIndex+s+2;o=an(n.slice(h,g),o,h,g)}else if(typeof u.v=="number"&&(u.z===void 0||!a.numfmt.isDate(u.z))){const h=`${u.v}`,g=l.startIndex+s+1,S=l.endIndex+s+2,{processedString:f,offset:p}=wm(d,h);o=an(f,o,g,S),s+=p}}}}),o}function bm(n,i,e,t){const r=i.getDescriptions();return e[t+1]!==Z.matchToken.OPEN_BRACKET?!1:r.get(Rm(n).toLocaleUpperCase())!==void 0}function Rm(n){const i=/^@+/;return n.replace(i,"")}function Em(n){return pm[n]||n}function an(n,i,e,t){return i.substring(0,e)+n+i.substring(t)}function wm(n,i){var s,l;const e=((s=n.match(/^\s*/))==null?void 0:s[0])||"",t=((l=n.match(/\s*$/))==null?void 0:l[0])||"",r=e+i+t,o=r.length-n.length;return{processedString:r,offset:o}}const Ml="range_selector",Pl=n=>n.includes(Ml);var Tm=Object.getOwnPropertyDescriptor,ym=(n,i,e,t)=>{for(var r=t>1?void 0:t?Tm(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=s(r)||r);return r},ye=(n,i)=>(e,t)=>i(e,t,n);const oa=-1e3;exports.EditingRenderController=class extends a.Disposable{constructor(e,t,r,o,s,l,c,d,u,h,g,S,f,p,v,C){super();E(this,"_cursorChange",0);E(this,"_isUnitEditing",!1);E(this,"_workbookSelections");E(this,"_d");E(this,"_cursorTimeout");this._context=e,this._undoRedoService=r,this._contextService=o,this._renderManagerService=s,this._editorBridgeService=l,this._cellEditorManagerService=c,this._lexerTreeBuilder=d,this._functionService=u,this._textSelectionManagerService=h,this._commandService=g,this._localService=S,this._editorService=f,this._sheetCellEditorResizeService=p,this._univerInstanceService=v,this._sheetInterceptorService=C,this._workbookSelections=t.getWorkbookSelections(this._context.unitId),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(b=>{(b==null?void 0:b.getUnitId())===this._context.unitId?this._d=this._init():(this._disposeCurrent(),this._isUnitEditing&&(this._handleEditorInvisible({visible:!1,eventType:T.DeviceInputEventType.Keyboard,keycode:_.KeyCode.ESC,unitId:this._context.unitId}),this._isUnitEditing=!1))})),this._initEditorVisibilityListener()}dispose(){super.dispose(),this._disposeCurrent()}_disposeCurrent(){var e;(e=this._d)==null||e.dispose(),this._d=null}_init(){const e=new a.DisposableCollection;return this._subscribeToCurrentCell(e),this._initialCursorSync(e),this._listenEditorFocus(e),this._commandExecutedListener(e),this._initSkeletonListener(e),e.add(()=>{clearTimeout(this._cursorTimeout)}),this._cursorTimeout=setTimeout(()=>{this._cursorStateListener(e)},1e3),e}_initEditorVisibilityListener(){this.disposeWithMe(this._editorBridgeService.visible$.pipe(O.distinctUntilChanged((e,t)=>e.visible===t.visible)).subscribe(e=>{(e.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY||e.unitId===this._context.unitId)&&e.visible?(this._isUnitEditing=!0,this._handleEditorVisible(e)):this._isUnitEditing&&(this._handleEditorInvisible(e),this._isUnitEditing=!1)}))}_listenEditorFocus(e){const t=this._getEditorObject();t&&e.add(t.document.onPointerDown$.subscribeEvent(()=>{if(this._isUnitEditing&&this._editorBridgeService.isVisible()){const r=this._editorBridgeService.getEditCellState(),o=this._editorBridgeService.getCurrentEditorId();if(!r||!o)return;this._sheetCellEditorResizeService.fitTextSize()}}))}_initialCursorSync(e){e.add(this._cellEditorManagerService.focus$.pipe(O.filter(t=>!!t)).subscribe(()=>{var o;const t=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(!t)return;const r=(o=this._renderManagerService.getRenderById(t==null?void 0:t.getUnitId()))==null?void 0:o.with($.DocSelectionRenderService);r&&r.sync()}))}_initSkeletonListener(e){const t=new Set(m.COMMAND_LISTENER_SKELETON_CHANGE);t.delete(m.SetWorksheetActiveOperation.id),e.add(this._commandService.onCommandExecuted(r=>{if(t.has(r.id)){switch(r.id){case m.MoveRowsMutation.id:case m.MoveColsMutation.id:case m.RemoveColMutation.id:case m.RemoveRowMutation.id:case m.InsertColMutation.id:case m.InsertRowMutation.id:{const o=this._editorBridgeService.getEditLocation();if(!o)break;const s={startRow:o.row,startColumn:o.column,endRow:o.row,endColumn:o.column},l=m.adjustRangeOnMutation(s,r);if(!l)break;const c=l.startRow,d=l.startColumn;this._editorBridgeService.updateEditLocation(c,d);break}}this._sheetCellEditorResizeService.resizeCellEditor(()=>{this._textSelectionManagerService.refreshSelection({unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})})}}))}_subscribeToCurrentCell(e){e.add(this._editorBridgeService.currentEditCellState$.subscribe(t=>{var b,R;if(t==null||this._editorBridgeService.isForceKeepVisible())return;const r=this._editorBridgeService.getEditCellState();if(r==null)return;const{position:o,documentLayoutObject:s,scaleX:l,editorUnitId:c}=r;if(this._contextService.getContextValue(a.FOCUSING_EDITOR_STANDALONE))return;const d=this._getDocumentDataModel();if(d==null)return;const{startX:u,endX:h}=o,{textRotation:g,wrapStrategy:S,documentModel:f}=s,{vertexAngle:p}=T.convertTextRotation(g);S===a.WrapStrategy.WRAP&&p===0&&d.updateDocumentDataPageSize((h-u)/l),this._commandService.syncExecuteCommand($.ReplaceSnapshotCommand.id,{unitId:c,snapshot:f.getSnapshot()}),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!0),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});const v=(b=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:b.with($.DocSelectionRenderService),C=(R=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:R.with($.DocSelectionRenderService);(v!=null&&v.canFocusing||C!=null&&C.canFocusing)&&(this._univerInstanceService.setCurrentUnitForType(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),v==null||v.activate(oa,oa,!0))}))}_commandExecutedListener(e){e.add(this._commandService.onCommandExecuted(r=>{if(r.id===Re.RichTextEditingMutation.id){const o=r.params,{unitId:s}=o;if(!this._isCurrentSheetFocused()||Pl(s)||(this._editorBridgeService.changeEditorDirty(!0),!this._editorBridgeService.isVisible().visible))return;s===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._sheetCellEditorResizeService.fitTextSize()}}));const t=[zt.id];e.add(this._commandService.onCommandExecuted(r=>{if(t.includes(r.id)){const o=r.params,{keycode:s,isShift:l}=o;if(s!=null&&(this._cursorChange===2||this._contextService.getContextValue(a.FOCUSING_FX_BAR_EDITOR))){this._moveInEditor(s,l);return}this._commandService.syncExecuteCommand(Ce.id,o)}r.id===hr.id&&(this._cursorChange=2)}))}_handleEditorVisible(e){var S,f,p;const{eventType:t,keycode:r}=e;this._cursorChange=t===T.DeviceInputEventType.PointerDown||t===T.DeviceInputEventType.Dblclick?2:1;const o=this._editorBridgeService.getEditLocation();if(o==null)return;this._commandService.syncExecuteCommand(vs.id,{range:{startRow:o.row,startColumn:o.column,endRow:o.row,endColumn:o.column}}),this._editorBridgeService.refreshEditCellPosition(!1);const{unitId:s,isInArrayFormulaRange:l=!1}=o,c=this._getEditorObject();if(c==null)return;const{document:d,scene:u}=c;this._contextService.setContextValue(a.EDITOR_ACTIVATED,!0);const h=this._getDocumentDataModel(),g=this._getEditorSkeleton(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(!(!g||!h)){if(this._sheetCellEditorResizeService.fitTextSize(()=>{const v=u.getViewport($.VIEWPORT_KEY.VIEW_MAIN);v==null||v.scrollToViewportPos({viewportScrollX:Number.POSITIVE_INFINITY,viewportScrollY:Number.POSITIVE_INFINITY})}),t===T.DeviceInputEventType.Keyboard&&r===_.KeyCode.F2){d.makeDirty(),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}]);const v=((f=(S=h.getBody())==null?void 0:S.dataStream.length)!=null?f:2)-2;this._textSelectionManagerService.replaceDocRanges([{startOffset:v,endOffset:v}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})}else if(t===T.DeviceInputEventType.Keyboard||t===T.DeviceInputEventType.Dblclick&&l)this._emptyDocumentDataModel(h.getSnapshot().documentStyle,!!l),d.makeDirty(),(r===_.KeyCode.BACKSPACE||t===T.DeviceInputEventType.Dblclick)&&(g.calculate(),this._editorBridgeService.changeEditorDirty(!0)),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});else if(t===T.DeviceInputEventType.Dblclick){if(this._contextService.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA))return;const v=h.getBody().dataStream.length-2||0;this._textSelectionManagerService.replaceDocRanges([{startOffset:v,endOffset:v}])}(p=this._renderManagerService.getRenderById(s))==null||p.scene.resetCursor()}}async _handleEditorInvisible(e){const t=this._editorBridgeService.getEditCellState(),r=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),o=a.Tools.deepClone(r==null?void 0:r.getSnapshot());let{keycode:s}=e;if(this._cursorChange=0,this._exitInput(e),t==null)return;this._editorBridgeService.getEditorDirty()===!1&&(s=_.KeyCode.ESC);const d=this._context.unit.getActiveSheet(),u=this._context.unitId,h=d.getSheetId(),{unitId:g,sheetId:S}=t;if(u===g&&S!==h&&await this._commandService.executeCommand(m.SetWorksheetActivateCommand.id,{subUnitId:S,unitId:g}),s===_.KeyCode.ESC){this._editorBridgeService.isForceKeepVisible()&&this._editorBridgeService.disableForceKeepVisible();const f=this._workbookSelections.getCurrentSelections();f&&(this._contextService.setContextValue(m.REF_SELECTIONS_ENABLED,!1),this._commandService.syncExecuteCommand(m.SetSelectionsOperation.id,{unitId:this._context.unit.getUnitId(),subUnitId:S,selections:f}));return}o&&await this._submitCellData(o),this._moveCursor(s)}_getEditorObject(){return Mi(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}submitCellData(e){return this._submitCellData(e.getSnapshot())}async _submitCellData(e){const t=this._editorBridgeService.getEditCellState();if(t==null)return;const{unitId:r,sheetId:o,row:s,column:l}=t,c=this._context.unit;let d=c.getActiveSheet();if(!c.getSheetBySheetId(o))return;d=c.getActiveSheet();const h=Mm({...d.getCellRaw(s,l)||{}},e,this._lexerTreeBuilder,this._localService,this._functionService,c.getStyles());if(!h)return;const g=await this._sheetInterceptorService.onWriteCell(c,d,s,l,h);g!==d.getCellRaw(s,l)&&this._commandService.executeCommand(m.SetRangeValuesCommand.id,{subUnitId:o,unitId:r,range:{startRow:s,startColumn:l,endRow:s,endColumn:l},value:g})}_exitInput(e){var o;this._contextService.setContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA,!1),this._contextService.setContextValue(a.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!1),this._contextService.setContextValue(a.FOCUSING_FX_BAR_EDITOR,!1),this._cellEditorManagerService.setState({show:e.visible});const t=this._getEditorObject();(o=t==null?void 0:t.scene.getViewport($.VIEWPORT_KEY.VIEW_MAIN))==null||o.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});const r=this._editorBridgeService.getCurrentEditorId();r==null||!this._editorService.isSheetEditor(r)||(this._undoRedoService.clearUndoRedo(r),this._undoRedoService.clearUndoRedo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))}_moveCursor(e){if(e==null||!gm.includes(e))return;let t=a.Direction.LEFT;switch(e){case _.KeyCode.ENTER:t=a.Direction.DOWN;break;case _.KeyCode.TAB:t=a.Direction.RIGHT;break;case _.KeyCode.ARROW_DOWN:t=a.Direction.DOWN;break;case _.KeyCode.ARROW_UP:t=a.Direction.UP;break;case _.KeyCode.ARROW_LEFT:t=a.Direction.LEFT;break;case _.KeyCode.ARROW_RIGHT:t=a.Direction.RIGHT;break}e===_.KeyCode.ENTER||e===_.KeyCode.TAB?this._commandService.executeCommand($e.id,{keycode:e,direction:t}):this._commandService.executeCommand(xe.id,{direction:t})}_cursorStateListener(e){const t=this._getEditorObject();if(!(t!=null&&t.document))return;const{document:r}=t;e.add(a.toDisposable(r.onPointerDown$.subscribeEvent(()=>{this._cursorChange===1&&(this._cursorChange=2)})))}_moveInEditor(e,t){let r=a.Direction.LEFT;e===_.KeyCode.ARROW_DOWN?r=a.Direction.DOWN:e===_.KeyCode.ARROW_UP?r=a.Direction.UP:e===_.KeyCode.ARROW_RIGHT&&(r=a.Direction.RIGHT),t?this._commandService.executeCommand($.MoveSelectionOperation.id,{direction:r}):this._commandService.executeCommand($.MoveCursorOperation.id,{direction:r})}_getDocumentDataModel(){return this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC)}_isCurrentSheetFocused(){var e;return((e=this._univerInstanceService.getFocusedUnit())==null?void 0:e.getUnitId())===this._context.unitId}_getEditorSkeleton(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(Re.DocSkeletonManagerService).getSkeleton()}_getEditorViewModel(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(Re.DocSkeletonManagerService).getViewModel()}_emptyDocumentDataModel(e,t){const r=(l,c)=>{const d=a.Tools.deepClone(l.getSnapshot()),u=this._getEditorViewModel(l.getUnitId());u!=null&&(Pm(d.body,t),c&&(d.documentStyle=e),d.drawings={},d.drawingsOrder=[],l.reset(d),u.reset(l))},o=this._getDocumentDataModel();o&&r(o,!0);const s=this._univerInstanceService.getUnit(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);s&&r(s)}};exports.EditingRenderController=ym([ye(1,a.Inject(m.SheetsSelectionsService)),ye(2,a.IUndoRedoService),ye(3,a.IContextService),ye(4,T.IRenderManagerService),ye(5,Se),ye(6,mr),ye(7,a.Inject(Z.LexerTreeBuilder)),ye(8,Z.IFunctionService),ye(9,a.Inject(Re.DocSelectionManagerService)),ye(10,a.ICommandService),ye(11,a.Inject(a.LocaleService)),ye(12,$.IEditorService),ye(13,a.Inject(exports.SheetCellEditorResizeService)),ye(14,a.IUniverInstanceService),ye(15,a.Inject(m.SheetInterceptorService))],exports.EditingRenderController);function Mm(n,i,e,t,r,o){var h,g,S;if((i==null?void 0:i.body)==null)return null;const{body:s}=i;n.t=void 0;const l=s.dataStream;let d=l.substring(l.length-2,l.length)===a.DEFAULT_EMPTY_DOCUMENT_VALUE?l.substring(0,l.length-2):l;const u=t.getCurrentLocale();if(d=Cm(d,e,u,r),(h=i.drawingsOrder)!=null&&h.length)n.v="",n.f=null,n.si=null,n.p=i,n.t=a.CellValueType.STRING;else if(n.s&&hd.isTextFormat((S=(g=o==null?void 0:o.get(n.s))==null?void 0:g.n)==null?void 0:S.pattern)){n.v=d,n.f=null,n.si=null,n.p=null,n.t=a.CellValueType.STRING,zo(s)&&s.dataStream!==`\r
47
+ `,style:{height:hl},"data-range-selector":!0,children:[I.jsx(ul,{}),I.jsx(lm,{}),e.length&&I.jsx("div",{className:"univer-mr-2 univer-flex univer-gap-2",children:e.map(t=>{var r;return(r=t.children)==null?void 0:r.map(o=>(o==null?void 0:o.item)&&I.jsx(_.ToolbarItem,{...o.item},o.key))})}),I.jsx(qu,{})]})}function gl(){return fl()?I.jsx(cl,{}):null}function Sl(){return fl()?I.jsxs(I.Fragment,{children:[I.jsx($u,{}),I.jsx(Xu,{})]}):null}function fl(){const n=_.useDependency(a.IUniverInstanceService),e=!!_.useObservable(()=>n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),null,!1,[]);return V.useMemo(()=>n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).length>0,[n,e])}var cm=Object.getOwnPropertyDescriptor,dm=(n,i,e,t)=>{for(var r=t>1?void 0:t?cm(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=s(r)||r);return r},sn=(n,i)=>(e,t)=>i(e,t,n);const ra=5,ia=2;exports.SheetCellEditorResizeService=class extends a.Disposable{constructor(i,e,t,r,o,s,l){super(),this._context=i,this._layoutService=e,this._cellEditorManagerService=t,this._editorBridgeService=r,this._renderManagerService=o,this._sheetSkeletonManagerService=s,this._univerInstanceService=l}fitTextSize(i){var A,k,N,H;const e=this._editorBridgeService.getEditCellState();if(!e)return;const{position:t,documentLayoutObject:r,canvasOffset:o,scaleX:s,scaleY:l}=e,{startX:c,startY:d,endX:u,endY:h}=t,g=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);if(g==null)return;const S=this._getEditorSkeleton();if(!S)return;const f=this._predictingSize(t,o,S,r,s,l);if(!f)return;let{actualWidth:p,actualHeight:v}=f;const{verticalAlign:C,horizontalAlign:b,paddingData:R,fill:w}=r;p=p+((A=R.l)!=null?A:0)+((k=R.r)!=null?k:0),v=v+((N=R.t)!=null?N:0)+((H=R.b)!=null?H:0);let M=u-c,y=h-d;M<p&&(M=Math.ceil(p)),y<v&&(y=Math.ceil(v));let P=0;C===a.VerticalAlign.MIDDLE?P=(y-v)/2/l:C===a.VerticalAlign.TOP?P=R.t||0:P=(y-v)/l;let x=0;b===a.HorizontalAlign.CENTER?x=(M-p)/2/s:b===a.HorizontalAlign.RIGHT?x=(M-p)/s:x=R.l||0,P=P<(R.t||0)?R.t||0:P,x=x<(R.l||0)?R.l||0:x,g.updateDocumentDataMargin({t:P,l:x}),S.calculate(),this._editAreaProcessing(M,y,t,o,w,s,l,b,i)}_predictingSize(i,e,t,r,o=1,s=1){const{startX:l,endX:c}=i,{textRotation:d,wrapStrategy:u,paddingData:h}=r,g=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC),{vertexAngle:S}=T.convertTextRotation(d);if(u===a.WrapStrategy.WRAP&&S===0){g==null||g.updateDocumentDataPageSize(c-l),g==null||g.updateDocumentDataMargin({l:h.l,t:h.t}),t.calculate();const{actualWidth:C,actualHeight:b}=t.getActualSize();return{actualWidth:C*o,actualHeight:b*s}}const f=this._getEditorMaxSize(i,e,r.horizontalAlign);if(!f)return;g==null||g.updateDocumentDataPageSize(f.width/o),t.calculate();const p=t.getActualSize();let v=c-l;return v<p.actualWidth*o+ra*o&&(v=p.actualWidth*o+ra*o),g==null||g.updateDocumentDataPageSize(v/o),g==null||g.updateDocumentRenderConfig({horizontalAlign:a.HorizontalAlign.UNSPECIFIED,cellValueType:void 0}),{actualWidth:p.actualWidth*o,actualHeight:p.actualHeight*s}}_getEditorMaxSize(i,e,t){if(this._getEditorObject()==null)return;function o(b){return Number.parseInt(b.replace("px",""))}const l=this._context.engine.getCanvasElement(),c=l.getBoundingClientRect(),d=o(l.style.width),{width:u}=c,h=u/d,{startX:g,startY:S,endX:f}=i,p=this._context.engine.width,v=document.body.clientHeight-S-hl-e.top-ia*2;let C=u-g;if(t===a.HorizontalAlign.CENTER){const b=p-f,R=g;C=f-g+Math.min(R,b)*2}else t===a.HorizontalAlign.RIGHT&&(C=f);return{height:v,width:C-ia,scaleAdjust:h}}_editAreaProcessing(i,e,t,r,o,s=1,l=1,c,d){var D;const u=this._getEditorObject();if(u==null)return;const g=this._context.engine.getCanvasElement();let{startX:S,startY:f}=t;const{document:p,scene:v,engine:C}=u,b=v.getViewport($.VIEWPORT_KEY.VIEW_MAIN),R=this._getEditorMaxSize(t,r,c),{height:w,width:M,scaleAdjust:y}=R;let P=e,x=b==null?void 0:b.getScrollBar();P>w?(x==null?b&&new T.ScrollBar(b,{enableHorizontal:!1,barSize:8}):b==null||b.resetCanvasSizeAndUpdateScroll(),b==null||b.scrollToViewportPos({viewportScrollY:P-w}),P=w):(x=null,(D=b==null?void 0:b.getScrollBar())==null||D.dispose()),i+=(x==null?void 0:x.barSize)||0,i>M&&(i=M),this._addBackground(v,i/s,e/l,o);const{scaleX:A,scaleY:k}=v.getPrecisionScale();v.transformByState({width:i*y/s,height:e*y/l,scaleX:s*y,scaleY:l*y}),p.resize(i*y/s,e*y/l),setTimeout(()=>{C.resizeBySize(T.fixLineWidthByScale(i,A),T.fixLineWidthByScale(P,k)),d==null||d()},0);const N=this._layoutService.getContentElement().getBoundingClientRect(),H=g.getBoundingClientRect();S=S*y+(H.left-N.left),f=f*y+(H.top-N.top);const W=t.endX-t.startX;c===a.HorizontalAlign.RIGHT?S+=(W-i)*y:c===a.HorizontalAlign.CENTER&&(S+=(W-i*y)/2),this._cellEditorManagerService.setState({startX:S,startY:f,endX:i*y+S,endY:P*y+f,show:!0})}_addBackground(i,e,t,r){const o="_backgroundRectHelperColor_",s=i.getObject(o);s==null&&r==null||(s==null?i.addObjects([new T.Rect(o,{width:e,height:t,fill:r,evented:!1})],$.DOCS_COMPONENT_MAIN_LAYER_INDEX):r==null?s.dispose():(s.setProps({fill:r}),s.transformByState({width:e,height:t})))}resizeCellEditor(i){var y;const e=this._cellEditorManagerService.getState();if(!e||!this._editorBridgeService.isVisible().visible)return;this._editorBridgeService.refreshEditCellPosition(!0);const t=this._editorBridgeService.getEditCellState();if(!t)return;const r=(y=this._sheetSkeletonManagerService.getSkeletonParam(t.sheetId))==null?void 0:y.skeleton;if(!r)return;const{row:o,column:s,scaleX:l,scaleY:c,position:d,canvasOffset:u,documentLayoutObject:h}=t,{horizontalAlign:g}=h,S=this._getEditorMaxSize(d,u,g);if(!S)return;const{height:f,width:p,scaleAdjust:v}=S,C=r.getCellWithCoordByIndex(o,s),b=Math.min((C.mergeInfo.endY-C.mergeInfo.startY)*c,f)*v,R=Math.min((C.mergeInfo.endX-C.mergeInfo.startX)*l,p)*v,w=e.endY-e.startY,M=e.endX-e.startX;if(w!==b||M!==R){if(this._editorBridgeService.refreshEditCellPosition(!0),!this._getEditorSkeleton())return;this.fitTextSize(i)}}_getEditorObject(){return Mi(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}_getEditorSkeleton(){var i;return(i=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:i.with(Re.DocSkeletonManagerService).getSkeleton()}};exports.SheetCellEditorResizeService=dm([sn(1,_.ILayoutService),sn(2,mr),sn(3,Se),sn(4,T.IRenderManagerService),sn(5,a.Inject(exports.SheetSkeletonManagerService)),sn(6,a.IUniverInstanceService)],exports.SheetCellEditorResizeService);function Es(n){return n.getContextValue(a.FOCUSING_SHEET)}function ae(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function pl(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function um(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function hm(n){return n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function vl(n){return n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function mm(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.EDITOR_ACTIVATED)&&n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function rr(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&!n.getContextValue(a.FOCUSING_EDITOR_STANDALONE)}const Cl=[_.KeyCode.ARROW_DOWN,_.KeyCode.ARROW_UP,_.KeyCode.ARROW_LEFT,_.KeyCode.ARROW_RIGHT],gm=[_.KeyCode.ENTER,_.KeyCode.TAB,...Cl];function _l(){const n=[];for(const i of Cl)n.push({id:zt.id,binding:i,preconditions:e=>rr(e),staticParameters:{visible:!1,eventType:T.DeviceInputEventType.Keyboard,keycode:i,isShift:!1}}),n.push({id:zt.id,binding:i|_.MetaKeys.SHIFT,preconditions:e=>rr(e),staticParameters:{visible:!1,eventType:T.DeviceInputEventType.Keyboard,keycode:i,isShift:!0}});return n}const Il={id:hr.id,binding:_.KeyCode.F2,description:"shortcut.sheet.start-editing",group:"4_sheet-edit",preconditions:ae,staticParameters:{visible:!0,eventType:T.DeviceInputEventType.Keyboard,keycode:_.KeyCode.F2}},bl={id:Ce.id,binding:_.KeyCode.ENTER,description:"shortcut.sheet.toggle-editing",group:"4_sheet-edit",preconditions:n=>rr(n),staticParameters:{visible:!1,eventType:T.DeviceInputEventType.Keyboard,keycode:_.KeyCode.ENTER}},Rl={id:Ce.id,binding:_.KeyCode.TAB,preconditions:n=>rr(n),staticParameters:{visible:!1,eventType:T.DeviceInputEventType.Keyboard,keycode:_.KeyCode.TAB}},El={id:Ce.id,binding:_.KeyCode.ESC,description:"shortcut.sheet.abort-editing",group:"4_sheet-edit",preconditions:n=>rr(n),staticParameters:{visible:!1,eventType:T.DeviceInputEventType.Keyboard,keycode:_.KeyCode.ESC}},wl={id:$.BreakLineCommand.id,description:"shortcut.sheet.break-line",group:"4_sheet-edit",preconditions:n=>um(n),binding:_.KeyCode.ENTER|_.MetaKeys.ALT},Tl={id:$.DeleteLeftCommand.id,preconditions:n=>hm(n)||vl(n),binding:_.KeyCode.BACKSPACE},yl={id:Ce.id,description:"shortcut.sheet.delete-and-start-editing",group:"4_sheet-edit",preconditions:n=>ae(n)&&!vl(n),binding:_.KeyCode.BACKSPACE,staticParameters:{visible:!0,eventType:T.DeviceInputEventType.Keyboard,keycode:_.KeyCode.BACKSPACE}};function Sm(n){return n.startsWith("'")}function fm(n){return n.slice(1)}const pm={"0":"0","1":"1","2":"2","3":"3","4":"4","5":"5","6":"6","7":"7","8":"8","9":"9",A:"A",B:"B",C:"C",D:"D",E:"E",F:"F",G:"G",H:"H",I:"I",J:"J",K:"K",L:"L",M:"M",N:"N",O:"O",P:"P",Q:"Q",R:"R",S:"S",T:"T",U:"U",V:"V",W:"W",X:"X",Y:"Y",Z:"Z",a:"a",b:"b",c:"c",d:"d",e:"e",f:"f",g:"g",h:"h",i:"i",j:"j",k:"k",l:"l",m:"m",n:"n",o:"o",p:"p",q:"q",r:"r",s:"s",t:"t",u:"u",v:"v",w:"w",x:"x",y:"y",z:"z","%":"%","-":"-",".":".",":":":","/":"/","+":"+","@":"@","&":"&","*":"*","#":"#","=":"=",">":">","<":"<","$":"$",""":'"',"'":"'","(":"(",")":")"," ":" ",",":",","!":"!","?":"?",";":";","[":"[","]":"]","{":"{","}":"}"},jo={true:"TRUE",false:"FALSE"};function vm(n){return[a.LocaleType.ZH_CN,a.LocaleType.ZH_TW].includes(n)}function Cm(n,i,e,t){let r=n;if(vm(e)){if(n.startsWith("'")||n.startsWith("'"))return`'${n.slice(1)}`;r=_m(r)}if(r.startsWith("="))return Im(n,r,i,t);const o=r.toLowerCase();return jo[o]?jo[o]:a.numfmt.parseValue(r)==null?n:r}function _m(n){const i=/['"].*?['"]/g,e=[],t=n.split(i);n.replace(i,o=>(e.push(o),""));let r=t.join("").split("").map(Em).join("");return e.forEach((o,s)=>{r=r.slice(0,s*2)+o+r.slice((s+1)*2)}),r}function Im(n,i,e,t){const r=e.sequenceNodesBuilder(i);if(!r)return n;let o=i,s=0;return r.forEach((l,c)=>{if(typeof l=="object"){const d=l.token;if(jo[d.toLowerCase()]){const u=l.startIndex+s+1,h=l.endIndex+s+2;o=an(d.toLocaleUpperCase(),o,u,h)}else if(l.nodeType===Z.sequenceNodeType.FUNCTION&&bm(d,t,r,c)||l.nodeType===Z.sequenceNodeType.REFERENCE){const u=d.indexOf("!");if(u>-1){const h=d.substring(u+1),g=l.startIndex+s+(u+1)+1,S=l.endIndex+s+2;o=an(h.toLocaleUpperCase(),o,g,S)}else{const h=l.startIndex+s+1,g=l.endIndex+s+2;o=an(d.toLocaleUpperCase(),o,h,g)}}else if(d.startsWith('"')&&d.endsWith('"')||d.startsWith("'")&&d.endsWith("'")){const u=l.startIndex+s+2,h=l.endIndex+s+1;o=an(n.slice(u,h),o,u,h)}else if(l.nodeType!==Z.sequenceNodeType.ARRAY){const u=a.numfmt.parseValue(d);if(u==null){const h=l.startIndex+s+1,g=l.endIndex+s+2;o=an(n.slice(h,g),o,h,g)}else if(typeof u.v=="number"&&(u.z===void 0||!a.numfmt.isDate(u.z))){const h=`${u.v}`,g=l.startIndex+s+1,S=l.endIndex+s+2,{processedString:f,offset:p}=wm(d,h);o=an(f,o,g,S),s+=p}}}}),o}function bm(n,i,e,t){const r=i.getDescriptions();return e[t+1]!==Z.matchToken.OPEN_BRACKET?!1:r.get(Rm(n).toLocaleUpperCase())!==void 0}function Rm(n){const i=/^@+/;return n.replace(i,"")}function Em(n){return pm[n]||n}function an(n,i,e,t){return i.substring(0,e)+n+i.substring(t)}function wm(n,i){var s,l;const e=((s=n.match(/^\s*/))==null?void 0:s[0])||"",t=((l=n.match(/\s*$/))==null?void 0:l[0])||"",r=e+i+t,o=r.length-n.length;return{processedString:r,offset:o}}const Ml="range_selector",Pl=n=>n.includes(Ml);var Tm=Object.getOwnPropertyDescriptor,ym=(n,i,e,t)=>{for(var r=t>1?void 0:t?Tm(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=s(r)||r);return r},ye=(n,i)=>(e,t)=>i(e,t,n);const oa=-1e3;exports.EditingRenderController=class extends a.Disposable{constructor(e,t,r,o,s,l,c,d,u,h,g,S,f,p,v,C){super();E(this,"_cursorChange",0);E(this,"_isUnitEditing",!1);E(this,"_workbookSelections");E(this,"_d");E(this,"_cursorTimeout");this._context=e,this._undoRedoService=r,this._contextService=o,this._renderManagerService=s,this._editorBridgeService=l,this._cellEditorManagerService=c,this._lexerTreeBuilder=d,this._functionService=u,this._textSelectionManagerService=h,this._commandService=g,this._localService=S,this._editorService=f,this._sheetCellEditorResizeService=p,this._univerInstanceService=v,this._sheetInterceptorService=C,this._workbookSelections=t.getWorkbookSelections(this._context.unitId),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(b=>{(b==null?void 0:b.getUnitId())===this._context.unitId?this._d=this._init():(this._disposeCurrent(),this._isUnitEditing&&(this._handleEditorInvisible({visible:!1,eventType:T.DeviceInputEventType.Keyboard,keycode:_.KeyCode.ESC,unitId:this._context.unitId}),this._isUnitEditing=!1))})),this._initEditorVisibilityListener()}dispose(){super.dispose(),this._disposeCurrent()}_disposeCurrent(){var e;(e=this._d)==null||e.dispose(),this._d=null}_init(){const e=new a.DisposableCollection;return this._subscribeToCurrentCell(e),this._initialCursorSync(e),this._listenEditorFocus(e),this._commandExecutedListener(e),this._initSkeletonListener(e),e.add(()=>{clearTimeout(this._cursorTimeout)}),this._cursorTimeout=setTimeout(()=>{this._cursorStateListener(e)},1e3),e}_initEditorVisibilityListener(){this.disposeWithMe(this._editorBridgeService.visible$.pipe(O.distinctUntilChanged((e,t)=>e.visible===t.visible)).subscribe(e=>{(e.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY||e.unitId===this._context.unitId)&&e.visible?(this._isUnitEditing=!0,this._handleEditorVisible(e)):this._isUnitEditing&&(this._handleEditorInvisible(e),this._isUnitEditing=!1)}))}_listenEditorFocus(e){const t=this._getEditorObject();t&&e.add(t.document.onPointerDown$.subscribeEvent(()=>{if(this._isUnitEditing&&this._editorBridgeService.isVisible()){const r=this._editorBridgeService.getEditCellState(),o=this._editorBridgeService.getCurrentEditorId();if(!r||!o)return;this._sheetCellEditorResizeService.fitTextSize()}}))}_initialCursorSync(e){e.add(this._cellEditorManagerService.focus$.pipe(O.filter(t=>!!t)).subscribe(()=>{var o;const t=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(!t)return;const r=(o=this._renderManagerService.getRenderById(t==null?void 0:t.getUnitId()))==null?void 0:o.with($.DocSelectionRenderService);r&&r.sync()}))}_initSkeletonListener(e){const t=new Set(m.COMMAND_LISTENER_SKELETON_CHANGE);t.delete(m.SetWorksheetActiveOperation.id),e.add(this._commandService.onCommandExecuted(r=>{if(t.has(r.id)){switch(r.id){case m.MoveRowsMutation.id:case m.MoveColsMutation.id:case m.RemoveColMutation.id:case m.RemoveRowMutation.id:case m.InsertColMutation.id:case m.InsertRowMutation.id:{const o=this._editorBridgeService.getEditLocation();if(!o)break;const s={startRow:o.row,startColumn:o.column,endRow:o.row,endColumn:o.column},l=m.adjustRangeOnMutation(s,r);if(!l)break;const c=l.startRow,d=l.startColumn;this._editorBridgeService.updateEditLocation(c,d);break}}this._sheetCellEditorResizeService.resizeCellEditor(()=>{this._textSelectionManagerService.refreshSelection({unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})})}}))}_subscribeToCurrentCell(e){e.add(this._editorBridgeService.currentEditCellState$.subscribe(t=>{var b,R;if(t==null||this._editorBridgeService.isForceKeepVisible())return;const r=this._editorBridgeService.getEditCellState();if(r==null)return;const{position:o,documentLayoutObject:s,scaleX:l,editorUnitId:c}=r;if(this._contextService.getContextValue(a.FOCUSING_EDITOR_STANDALONE))return;const d=this._getDocumentDataModel();if(d==null)return;const{startX:u,endX:h}=o,{textRotation:g,wrapStrategy:S,documentModel:f}=s,{vertexAngle:p}=T.convertTextRotation(g);S===a.WrapStrategy.WRAP&&p===0&&d.updateDocumentDataPageSize((h-u)/l),this._commandService.syncExecuteCommand($.ReplaceSnapshotCommand.id,{unitId:c,snapshot:f.getSnapshot()}),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!0),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});const v=(b=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:b.with($.DocSelectionRenderService),C=(R=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:R.with($.DocSelectionRenderService);(v!=null&&v.canFocusing||C!=null&&C.canFocusing)&&(this._univerInstanceService.setCurrentUnitForType(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),v==null||v.activate(oa,oa,!0))}))}_commandExecutedListener(e){e.add(this._commandService.onCommandExecuted(r=>{if(r.id===Re.RichTextEditingMutation.id){const o=r.params,{unitId:s}=o;if(!this._isCurrentSheetFocused()||Pl(s)||(this._editorBridgeService.changeEditorDirty(!0),!this._editorBridgeService.isVisible().visible))return;s===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._sheetCellEditorResizeService.fitTextSize()}}));const t=[zt.id];e.add(this._commandService.onCommandExecuted(r=>{if(t.includes(r.id)){const o=r.params,{keycode:s,isShift:l}=o;if(s!=null&&(this._cursorChange===2||this._contextService.getContextValue(a.FOCUSING_FX_BAR_EDITOR))){this._moveInEditor(s,l);return}this._commandService.syncExecuteCommand(Ce.id,o)}r.id===hr.id&&(this._cursorChange=2)}))}_handleEditorVisible(e){var S,f,p;const{eventType:t,keycode:r}=e;this._cursorChange=t===T.DeviceInputEventType.PointerDown||t===T.DeviceInputEventType.Dblclick?2:1;const o=this._editorBridgeService.getEditLocation();if(o==null)return;this._commandService.syncExecuteCommand(vs.id,{range:{startRow:o.row,startColumn:o.column,endRow:o.row,endColumn:o.column}}),this._editorBridgeService.refreshEditCellPosition(!1);const{unitId:s,isInArrayFormulaRange:l=!1}=o,c=this._getEditorObject();if(c==null)return;const{document:d,scene:u}=c;this._contextService.setContextValue(a.EDITOR_ACTIVATED,!0);const h=this._getDocumentDataModel(),g=this._getEditorSkeleton(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(!(!g||!h)){if(this._sheetCellEditorResizeService.fitTextSize(()=>{const v=u.getViewport($.VIEWPORT_KEY.VIEW_MAIN);v==null||v.scrollToViewportPos({viewportScrollX:Number.POSITIVE_INFINITY,viewportScrollY:Number.POSITIVE_INFINITY})}),t===T.DeviceInputEventType.Keyboard&&r===_.KeyCode.F2){d.makeDirty(),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}]);const v=((f=(S=h.getBody())==null?void 0:S.dataStream.length)!=null?f:2)-2;this._textSelectionManagerService.replaceDocRanges([{startOffset:v,endOffset:v}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})}else if(t===T.DeviceInputEventType.Keyboard||t===T.DeviceInputEventType.Dblclick&&l)this._emptyDocumentDataModel(h.getSnapshot().documentStyle,!!l),d.makeDirty(),(r===_.KeyCode.BACKSPACE||t===T.DeviceInputEventType.Dblclick)&&(g.calculate(),this._editorBridgeService.changeEditorDirty(!0)),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});else if(t===T.DeviceInputEventType.Dblclick){if(this._contextService.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA))return;const v=h.getBody().dataStream.length-2||0;this._textSelectionManagerService.replaceDocRanges([{startOffset:v,endOffset:v}])}(p=this._renderManagerService.getRenderById(s))==null||p.scene.resetCursor()}}async _handleEditorInvisible(e){const t=this._editorBridgeService.getEditCellState(),r=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),o=a.Tools.deepClone(r==null?void 0:r.getSnapshot());let{keycode:s}=e;if(this._cursorChange=0,this._exitInput(e),t==null)return;this._editorBridgeService.getEditorDirty()===!1&&(s=_.KeyCode.ESC);const d=this._context.unit.getActiveSheet(),u=this._context.unitId,h=d.getSheetId(),{unitId:g,sheetId:S}=t;if(u===g&&S!==h&&await this._commandService.executeCommand(m.SetWorksheetActivateCommand.id,{subUnitId:S,unitId:g}),s===_.KeyCode.ESC){this._editorBridgeService.isForceKeepVisible()&&this._editorBridgeService.disableForceKeepVisible();const f=this._workbookSelections.getCurrentSelections();f&&(this._contextService.setContextValue(m.REF_SELECTIONS_ENABLED,!1),this._commandService.syncExecuteCommand(m.SetSelectionsOperation.id,{unitId:this._context.unit.getUnitId(),subUnitId:S,selections:f}));return}o&&await this._submitCellData(o)===!1||this._moveSelection(s)}_getEditorObject(){return Mi(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}submitCellData(e){return this._submitCellData(e.getSnapshot())}async _submitCellData(e){const t=this._editorBridgeService.getEditCellState();if(t==null)return!0;const{unitId:r,sheetId:o,row:s,column:l}=t,c=this._context.unit;let d=c.getActiveSheet();if(!c.getSheetBySheetId(o))return!0;d=c.getActiveSheet();const h=Mm({...d.getCellRaw(s,l)||{}},e,this._lexerTreeBuilder,this._localService,this._functionService,c.getStyles());if(!h||this._sheetInterceptorService.onWriteCell(c,d,s,l,h)===d.getCellRaw(s,l))return!0;const S=a.generateRandomId(6);return this._commandService.syncExecuteCommand(m.SetRangeValuesCommand.id,{subUnitId:o,unitId:r,range:{startRow:s,startColumn:l,endRow:s,endColumn:l},value:h,redoUndoId:S})&&await this._sheetInterceptorService.onValidateCell(c,d,s,l)===!1?(this._undoRedoService.rollback(S,r),!1):!0}_exitInput(e){var o;this._contextService.setContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA,!1),this._contextService.setContextValue(a.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!1),this._contextService.setContextValue(a.FOCUSING_FX_BAR_EDITOR,!1),this._cellEditorManagerService.setState({show:e.visible});const t=this._getEditorObject();(o=t==null?void 0:t.scene.getViewport($.VIEWPORT_KEY.VIEW_MAIN))==null||o.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});const r=this._editorBridgeService.getCurrentEditorId();r==null||!this._editorService.isSheetEditor(r)||(this._undoRedoService.clearUndoRedo(r),this._undoRedoService.clearUndoRedo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))}_moveSelection(e){if(e==null||!gm.includes(e))return;let t=a.Direction.LEFT;switch(e){case _.KeyCode.ENTER:t=a.Direction.DOWN;break;case _.KeyCode.TAB:t=a.Direction.RIGHT;break;case _.KeyCode.ARROW_DOWN:t=a.Direction.DOWN;break;case _.KeyCode.ARROW_UP:t=a.Direction.UP;break;case _.KeyCode.ARROW_LEFT:t=a.Direction.LEFT;break;case _.KeyCode.ARROW_RIGHT:t=a.Direction.RIGHT;break}e===_.KeyCode.ENTER||e===_.KeyCode.TAB?this._commandService.executeCommand($e.id,{keycode:e,direction:t}):this._commandService.executeCommand(xe.id,{direction:t})}_cursorStateListener(e){const t=this._getEditorObject();if(!(t!=null&&t.document))return;const{document:r}=t;e.add(a.toDisposable(r.onPointerDown$.subscribeEvent(()=>{this._cursorChange===1&&(this._cursorChange=2)})))}_moveInEditor(e,t){let r=a.Direction.LEFT;e===_.KeyCode.ARROW_DOWN?r=a.Direction.DOWN:e===_.KeyCode.ARROW_UP?r=a.Direction.UP:e===_.KeyCode.ARROW_RIGHT&&(r=a.Direction.RIGHT),t?this._commandService.executeCommand($.MoveSelectionOperation.id,{direction:r}):this._commandService.executeCommand($.MoveCursorOperation.id,{direction:r})}_getDocumentDataModel(){return this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC)}_isCurrentSheetFocused(){var e;return((e=this._univerInstanceService.getFocusedUnit())==null?void 0:e.getUnitId())===this._context.unitId}_getEditorSkeleton(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(Re.DocSkeletonManagerService).getSkeleton()}_getEditorViewModel(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(Re.DocSkeletonManagerService).getViewModel()}_emptyDocumentDataModel(e,t){const r=(l,c)=>{const d=a.Tools.deepClone(l.getSnapshot()),u=this._getEditorViewModel(l.getUnitId());u!=null&&(Pm(d.body,t),c&&(d.documentStyle=e),d.drawings={},d.drawingsOrder=[],l.reset(d),u.reset(l))},o=this._getDocumentDataModel();o&&r(o,!0);const s=this._univerInstanceService.getUnit(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);s&&r(s)}};exports.EditingRenderController=ym([ye(1,a.Inject(m.SheetsSelectionsService)),ye(2,a.IUndoRedoService),ye(3,a.IContextService),ye(4,T.IRenderManagerService),ye(5,Se),ye(6,mr),ye(7,a.Inject(Z.LexerTreeBuilder)),ye(8,Z.IFunctionService),ye(9,a.Inject(Re.DocSelectionManagerService)),ye(10,a.ICommandService),ye(11,a.Inject(a.LocaleService)),ye(12,$.IEditorService),ye(13,a.Inject(exports.SheetCellEditorResizeService)),ye(14,a.IUniverInstanceService),ye(15,a.Inject(m.SheetInterceptorService))],exports.EditingRenderController);function Mm(n,i,e,t,r,o){var h,g,S;if((i==null?void 0:i.body)==null)return null;const{body:s}=i;n.t=void 0;const l=s.dataStream;let d=l.substring(l.length-2,l.length)===a.DEFAULT_EMPTY_DOCUMENT_VALUE?l.substring(0,l.length-2):l;const u=t.getCurrentLocale();if(d=Cm(d,e,u,r),(h=i.drawingsOrder)!=null&&h.length)n.v="",n.f=null,n.si=null,n.p=i,n.t=a.CellValueType.STRING;else if(n.s&&hd.isTextFormat((S=(g=o==null?void 0:o.get(n.s))==null?void 0:g.n)==null?void 0:S.pattern)){n.v=d,n.f=null,n.si=null,n.p=null,n.t=a.CellValueType.STRING,zo(s)&&s.dataStream!==`\r
48
48
  `&&(n.p=i);const f=sa(i);f&&(n.s=f)}else if(a.isFormulaString(d)){if(n.f===d)return null;const f=e.checkIfAddBracket(d);for(let p=0;p<f;p++)d+=Z.matchToken.CLOSE_BRACKET;n.f=d,n.si=null,n.v=null,n.p=null}else if(Sm(d)){const f=fm(d);n.v=f,n.f=null,n.si=null,n.p=null,n.t=a.CellValueType.FORCE_STRING}else if(zo(s))s.dataStream===`\r
49
49
  `?(n.v="",n.f=null,n.si=null,n.p=null):(n.p=i,n.v=null,n.f=null,n.si=null);else{if(d===""&&n.v==null&&n.p==null)return null;n.v=d,n.f=null,n.si=null,n.p=null;const f=sa(i);f&&(n.s=f)}return n}function zo(n){const{textRuns:i=[],paragraphs:e=[],customRanges:t,customBlocks:r=[]}=n,o=n.dataStream.replace(/(\r\n)+$/,""),s=["va"];return i.filter(l=>l.st<o.length).some(l=>{var d;return!!(l.ts&&Object.keys(l.ts).some(u=>s.includes(u)))||Object.keys((d=l.ts)!=null?d:{}).length&&l.ed-l.st<o.length})||e.some(l=>l.bullet)||e.length>=2||!!(t!=null&&t.length)||r.length>0}function sa(n){const{body:i}=n;if(!i)return null;const{textRuns:e=[]}=i;let t={};const r=i.dataStream.replace(`\r
50
50
  `,"");return e.forEach(o=>{const{st:s,ed:l,ts:c}=o;l-s>=r.length&&(t={...t,...c})}),Object.keys(t).length?t:null}function Pm(n,i=!1){n.dataStream=a.DEFAULT_EMPTY_DOCUMENT_VALUE,n.textRuns!=null&&(n.textRuns.length===1&&!i?(n.textRuns[0].st=0,n.textRuns[0].ed=1):n.textRuns=void 0),n.paragraphs!=null&&(n.paragraphs=[{startIndex:0}]),n.sectionBreaks!=null&&(n.sectionBreaks=void 0),n.tables!=null&&(n.tables=void 0),n.customRanges!=null&&(n.customRanges=void 0),n.customBlocks!=null&&(n.customBlocks=void 0)}var Om=Object.getOwnPropertyDescriptor,xm=(n,i,e,t)=>{for(var r=t>1?void 0:t?Om(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=s(r)||r);return r},Yi=(n,i)=>(e,t)=>i(e,t,n);const aa=cs.MARK_SELECTION,qt=a.createIdentifier("univer.mark-selection-service");exports.MarkSelectionService=class extends a.Disposable{constructor(e,t,r){super();E(this,"_shapeMap",new Map);this._currentService=e,this._renderManagerService=t,this._themeService=r}addShape(e,t=[],r=aa){var d;const o=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=(d=o.getActiveSheet())==null?void 0:d.getSheetId();if(!s)return null;const l=a.Tools.generateRandomId(),c={selection:e,subUnitId:s,unitId:o.getUnitId(),zIndex:r,control:null,exits:t};return this._shapeMap.set(l,c),this.refreshShapes(),l}addShapeWithNoFresh(e,t=[],r=aa){var c;const o=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=(c=o.getActiveSheet())==null?void 0:c.getSheetId();if(!s)return null;const l=a.Tools.generateRandomId();return this._shapeMap.set(l,{selection:e,subUnitId:s,unitId:o.getUnitId(),zIndex:r,control:null,exits:t}),l}refreshShapes(){var o;const e=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!e)return;const t=e.getUnitId(),r=(o=e.getActiveSheet())==null?void 0:o.getSheetId();this._shapeMap.forEach(s=>{const{unitId:l,subUnitId:c,selection:d,control:u,zIndex:h}=s;if(u==null||u.dispose(),l!==t||c!==r)return;const g=this._renderManagerService.getRenderById(l);if(!g)return;const S=g.with(exports.SheetSkeletonManagerService).getCurrentSkeleton();if(!S)return;const{scene:f}=g,{rowHeaderWidth:p,columnHeaderHeight:v}=S,C=new cr(f,h,this._themeService,{enableAutoFill:!1,highlightHeader:!1,rowHeaderWidth:p,columnHeaderHeight:v}),b=Pe(d,S);C.updateRangeBySelectionWithCoord(b),s.control=C})}getShapeMap(){return this._shapeMap}removeShape(e){const t=this._shapeMap.get(e);if(!t)return;const{control:r}=t;r==null||r.dispose(),this._shapeMap.delete(e)}removeAllShapes(){for(const e of this._shapeMap.values()){const{control:t}=e;t==null||t.dispose()}this._shapeMap.clear()}};exports.MarkSelectionService=xm([Yi(0,a.IUniverInstanceService),Yi(1,T.IRenderManagerService),Yi(2,a.Inject(a.ThemeService))],exports.MarkSelectionService);function Ol(n){return{strokeWidth:1.5,stroke:n.getCurrentTheme().primaryColor,fill:"rgba(178, 178, 178, 0.10)",widgets:{},strokeDash:8}}const Am=10,km=6;function Nm(){return a.Tools.generateRandomId(km)}function Dm(n){const i=n.match(/data-copy-id="([^\s]+)"/);return i&&i[1]?i[1]:null}class Hm{constructor(){E(this,"_cache",new a.LRUMap(Am))}set(i,e){this._cache.set(i,e)}get(i){return this._cache.get(i)}del(i){this._cache.delete(i)}clear(){this._cache.clear()}clearWithUnitId(i){this._cache.forEach((e,t)=>{e.unitId===i&&this._cache.delete(t)})}}function ii(n,i){const e=i!=null?i:n.style,t={},r=n.tagName.toLowerCase();switch(r){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=r==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}return Vm(e,t),t}function Vm(n,i){if(n instanceof CSSStyleDeclaration)for(let e=0;e<n.length;e++){const t=n[e],r=n.getPropertyValue(t);la(t,r,i)}else for(const e in n){const t=n[e];la(e,t,i)}}function la(n,i,e){switch(n){case"font-family":e.ff=i;break;case"font-size":{const t=Number.parseInt(i);Number.isNaN(t)||(i.endsWith("pt")?e.fs=t:i.endsWith("px")&&(e.fs=t*.75));break}case"font-style":i==="italic"&&(e.it=a.BooleanNumber.TRUE);break;case"font-weight":{(Number(i)>400||i==="bold")&&(e.bl=a.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(i)?e.ul={s:a.BooleanNumber.TRUE}:/overline/.test(i)?e.ol={s:a.BooleanNumber.TRUE}:/line-through/.test(i)&&(e.st={s:a.BooleanNumber.TRUE});break}case"color":{try{const t=new a.ColorKit(i);t.isValid&&(e.cl={rgb:t.toRgbString()})}catch{}break}case"background-color":{const t=new a.ColorKit(i),r=t.isValid?t.toRgbString():"";r!==_.DEFAULT_BACKGROUND_COLOR_RGB&&r!==_.DEFAULT_BACKGROUND_COLOR_RGBA&&(e.bg={rgb:r});break}}}function Wm(n){const i=document.createElement("body");return i.innerHTML=n,i}function xl(n){const i=n.style,e={};for(let t=0;t<i.length;t++){const r=i[t],o=i.getPropertyValue(r);switch(r){case"margin-top":{const s=Number.parseInt(o);e.spaceAbove={v:/pt/.test(o)?T.ptToPixel(s):s};break}case"margin-bottom":{const s=Number.parseInt(o);e.spaceBelow={v:/pt/.test(o)?T.ptToPixel(s):s};break}case"line-height":{const s=Number.parseFloat(o);e.lineSpacing=s;break}}}return Object.getOwnPropertyNames(e).length?e:null}function Gi(n,i){const e=[];for(let t=0,r=n.length;t<r;t++)n[t]===a.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});return e}function ca(n,i,e){var s,l,c;const t=i.length,o=((s=e==null?void 0:e.length)!=null?s:0)===1&&e[0].st===0&&e[0].ed===t;return n.p?o&&((c=(l=n.p.body)==null?void 0:l.textRuns)!=null&&c.length)?(n.p.body.textRuns=[],{...n,s:e[0].ts}):n:o?{...n,s:e[0].ts}:n}const da=["color","background","font-size","text-align","vertical-align","font-weight","font-style","font-family","text-decoration","white-space","word-wrap","border-left","border-right","border-top","border-bottom","--data-rotate"];function ua(n,i){const e=n.tagName.toLowerCase();return typeof i=="string"?e===i:Array.isArray(i)?i.some(t=>t===e):i(n)}const yi=class yi{constructor(i){E(this,"_styleMap",new Map);E(this,"_styleCache",new Map);E(this,"_styleRules",[]);E(this,"_afterProcessRules",[]);E(this,"_dom",null);E(this,"_getCurrentSkeleton");this._getCurrentSkeleton=i.getCurrentSkeleton}static use(i){if(this._pluginList.includes(i))throw new Error(`Univer paste plugin ${i.name} already added`);this._pluginList.push(i)}convert(i){const e=yi._pluginList.find(p=>p.checkPasteType(i));e&&(this._styleRules=[...e.stylesRules],this._afterProcessRules=[...e.afterProcessRules]);const t=new a.ObjectMatrix;this._dom=Wm(i);const r=this._dom.querySelector("style");if(r){const p=document.createElement("div"),v=p.attachShadow({mode:"open"});document.body.appendChild(p),v.appendChild(r);for(const C of r.sheet.cssRules){const b=C,R=b.selectorText,w=b.style;this._styleMap.set(R,w)}r.remove(),p.remove()}const o={dataStream:"",textRuns:[]},s=[],l=[],c=i.match(/<table\b[^>]*>([\s\S]*?)<\/table>/gi),d=[];this.process(null,this._dom.childNodes,o,d);const{paragraphs:u,dataStream:h,textRuns:g,payloads:S,customRanges:f}=o;if(u){const p=u.map(v=>v.startIndex+1);p.unshift(0);for(let v=0;v<p.length;v++){let C;if(v===p.length-1){if(C=`${h.substring(p[v])}\r
@@ -55,7 +55,7 @@
55
55
  `,g={...u,body:{dataStream:h,textRuns:c.textRuns,paragraphs:Gi(h)}};d==null||d.reset(g),o=d==null?void 0:d.getSnapshot(),r=c.dataStream}else r=Bm(i.innerHTML.replace(/[\r\n]/g,""));return{cellText:r,cellRichStyle:o}}_generateDocumentDataModelSnapshot(i){var l;const e=this._getCurrentSkeleton();if(e==null)return null;const{skeleton:t}=e,r=(l=t.getBlankCellDocumentModel())==null?void 0:l.documentModel,s={...r==null?void 0:r.getSnapshot(),...i};return r==null||r.reset(s),r==null?void 0:r.getSnapshot()}process(i,e,t,r){var o,s,l;for(const c of e)if(c.nodeName.toLowerCase()==="table")r.push({index:((o=t==null?void 0:t.paragraphs)==null?void 0:o.length)||0});else if(c.nodeType===Node.TEXT_NODE){if(((s=c.nodeValue)==null?void 0:s.trim())==="")continue;const d=(l=c.nodeValue)==null?void 0:l.replace(/[\r\n]/g,"");let u;i&&this._styleCache.has(i)&&(u=this._styleCache.get(i));const h={dataStream:"",textRuns:[]};t.dataStream+=d,h.dataStream+=d,u&&Object.getOwnPropertyNames(u).length&&(t.textRuns.push({st:t.dataStream.length-d.length,ed:t.dataStream.length,ts:u}),h.textRuns.push({st:t.dataStream.length-d.length,ed:t.dataStream.length,ts:u}))}else{if(a.skipParseTagNames.includes(c.nodeName.toLowerCase()))continue;if(c.nodeName.toLowerCase()==="br")t.paragraphs||(t.paragraphs=[]),t.paragraphs.push({startIndex:t.dataStream.length}),t.dataStream+="\r";else if(c.nodeType===Node.ELEMENT_NODE){if(c.nodeName==="STYLE")continue;const d=c,u=this._processBeforeLink(d,{body:t}),h=i?this._styleCache.get(i):{},g=this._styleRules.find(({filter:v})=>ua(c,v)),S=g?g.getStyle(c):ii(c);this._styleCache.set(c,{...h,...S});const{childNodes:f}=c;this.process(c,f,t,r);const p=this._afterProcessRules.find(({filter:v})=>ua(c,v));p&&p.handler(t,c),this._processAfterLink(d,{body:t},u)}}}_processBeforeLink(i,e){return e.body.dataStream.length}_processAfterLink(i,e,t){var s,l;const r=e.body,o=i;o.tagName.toUpperCase()==="A"&&(r.customRanges=(s=r.customRanges)!=null?s:[],r.customRanges.push({startIndex:t,endIndex:r.dataStream.length-1,rangeId:(l=o.dataset.rangeid)!=null?l:a.generateRandomId(),rangeType:a.CustomRangeType.HYPERLINK,properties:{url:o.href}}))}dispose(){this._dom=null,this._styleCache.clear(),this._styleMap.clear()}};E(yi,"_pluginList",[]);let wn=yi;function Um(n){const i=/<tr([\s\S]*?)>([\s\S]*?)<\/tr>/gi,e=n.matchAll(i);if(!e)return{rowProperties:[],rowCount:0};const r=Array.from(e).map(o=>Al(o[1])).map(o=>{if(!o.height){const s=o.style,l=s&&s.match(/height\s*:\s*(\d+(\.\d+)?)px/);o.height=`${l?Number.parseInt(l[1],10):a.DEFAULT_WORKSHEET_ROW_HEIGHT}`}return o});return{rowProperties:r,rowCount:r.length}}function ha(n){const i={};return n.split(";").forEach(t=>{const[r,o]=t.split(":");i[r]=o}),i}function Al(n){if(!n)return{};const i={},e=/([\w-]+)\s*=\s*(?:(['"])([^'"]*)\2|(\S+))/g;let t;for(;(t=e.exec(n))!==null;){const[,r,,o,s]=t,l=o!==void 0?o:s;i[r]=l}return i}function Lm(n){const i=/<colgroup([\s\S]*?)>(.*?)<\/colgroup>/,e=n.match(i),t=/<col([\s\S]*?)>/g;let r;if(e!=null&&e[2]?r=e[2].matchAll(t):r=n.matchAll(t),!r)return null;const o=Array.from(r).map(l=>Al(l[1])),s=[];return o.forEach(l=>{const c=Number(l.span);if(c)for(let d=0;d<c;d++){const u={...l};delete u.span,s.push(u)}else s.push(l)}),s}function Bm(n){const i={"&lt;":"<","&gt;":">","&amp;":"&","&quot;":'"',"&#39;":"'","&nbsp;":" "};return n.replace(/&lt;|&gt;|&amp;|&quot;|&#39;|&nbsp;|<br>/g,e=>i[e])}function ma(n,i){if(!n||!i)return null;const e=new RegExp(`(${i}\\s*:\\s*[^;]+);`,"i"),t=n.match(e);return t?t[1]:null}function Fm(n,i,e,t){const{rowSpan:r,colSpan:o,rowIndex:s,colSetValueIndex:l}=t;for(let c=s;c<s+r;c++)for(let d=l;d<l+o;d++)c===s&&d===l?n.setValue(c,d,{...e,style:i}):n.setValue(c,d,{style:i})}const jm={name:"univer-doc-paste-plugin-lark",checkPasteType(n){return/lark-record-clipboard/i.test(n)},stylesRules:[{filter:["s"],getStyle(n){const i=ii(n);return{st:{s:a.BooleanNumber.TRUE},...i}}}],afterProcessRules:[{filter(n){return n.tagName==="DIV"&&/ace-line/i.test(n.className)},handler(n){n.paragraphs==null&&(n.paragraphs=[]),n.paragraphs.push({startIndex:n.dataStream.length}),n.dataStream+="\r"}}]},zm={name:"univer-doc-paste-plugin-univer",checkPasteType(n){return/UniverNormal/i.test(n)},stylesRules:[],afterProcessRules:[{filter(n){return n.tagName==="P"&&/UniverNormal/i.test(n.className)},handler(n,i){n.paragraphs==null&&(n.paragraphs=[]);const e={startIndex:n.dataStream.length},t=xl(i);t&&(e.paragraphStyle=t),n.paragraphs.push(e),n.dataStream+="\r"}}]},Xm={name:"univer-doc-paste-plugin-word",checkPasteType(n){return/word|mso/i.test(n)},stylesRules:[{filter:["b"],getStyle(n){const i=ii(n);return{bl:a.BooleanNumber.TRUE,...i}}}],afterProcessRules:[{filter(n){return n.tagName==="P"&&/mso/i.test(n.className)},handler(n,i){n.paragraphs==null&&(n.paragraphs=[]);const e={startIndex:n.dataStream.length},t=xl(i);t&&(e.paragraphStyle=t),n.paragraphs.push(e),n.dataStream+="\r"}}]};var ct=(n=>(n.COPY="COPY",n.CUT="CUT",n))(ct||{});function Ym(n,i,e,t,r){const o=e.map(d=>{var u;return(u=d.onCopyRow)==null?void 0:u.call(d,n)}).filter(d=>!!d),s=ws(o),l=Ts(s),c=i.map(d=>{if(!r.has(`${n}-${d}`)){const u=t.getValue(n,d);if(u!=null&&u.rowSpan&&(u!=null&&u.colSpan))for(let h=n;h<n+u.rowSpan;h++)for(let g=d;g<d+u.colSpan;g++)r.add(`${h}-${g}`);return Gm(n,d,e,t)}return null}).filter(d=>!!d).join("");return`<tr${l}>${c}</tr>`}function Gm(n,i,e,t){const r=t.getValue(n,i),o=e.map(d=>{var u;return(u=d.onCopyCellStyle)==null?void 0:u.call(d,n,i,r==null?void 0:r.rowSpan,r==null?void 0:r.colSpan)}).filter(d=>!!d),s=ws(o),l=Ts(s),c=e.reduce((d,u)=>{var h;return d||((h=u.onCopyCellContent)==null?void 0:h.call(u,n,i))||""},"");return`<td${l}>${c}</td>`}function Zm(n,i){return`<colgroup>${n.map(t=>{const r=i.map(l=>{var c;return(c=l.onCopyColumn)==null?void 0:c.call(l,t)}).filter(l=>!!l),o=ws(r);return`<col ${Ts(o)}>`}).join("")}</colgroup>`}function ws(n){return n.reduce((i,e)=>(Object.keys(e).forEach(r=>{i[r]?i[r]+=`;${e[r]}`:i[r]=e[r]}),i),{})}function Ts(n){return Object.keys(n).reduce((i,e)=>(i+=` ${e}="${n[e]}"`,i),"")}class Km{convert(i,e,t){const{cols:r,rows:o}=e;if(!r.length)return"";const s=Zm(r,t),l=[],c=new Set;return o.forEach(u=>{l.push(Ym(u,r,t,i,c))}),`<google-sheets-html-origin><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none">${s}
56
56
  <tbody>${l.join("")}</tbody></table>`}}const qm=(n,i,e=!1)=>{const t=h=>h.endRow-h.startRow+1,r=h=>h.endColumn-h.startColumn+1,o=t(i)%t(n),s=r(i)%r(n),l={startRow:0,endRow:t(n)-1,startColumn:0,endColumn:r(n)-1},c=Math.floor(t(i)/t(n)),d=Math.floor(r(i)/r(n)),u=[];if(!o&&!s)for(let h=1;h<=c;h++)for(let g=1;g<=d;g++){const S=t(n)*(h-1),f=r(n)*(g-1),p={startRow:S+i.startRow,endRow:S+i.startRow,startColumn:f+i.startColumn,endColumn:f+i.startColumn};u.push({repeatRelativeRange:l,startRange:p})}else if(!o&&s&&!e)for(let h=1;h<=c;h++){const g=t(n)*(h-1),S=0,f={startRow:g+i.startRow,endRow:g+i.startRow,startColumn:S+i.startColumn,endColumn:S+i.startColumn};u.push({repeatRelativeRange:l,startRange:f})}else if(o&&!s&&!e)for(let h=1;h<=d;h++){const S=r(n)*(h-1),f={startRow:0+i.startRow,endRow:0+i.startRow,startColumn:S+i.startColumn,endColumn:S+i.startColumn};u.push({repeatRelativeRange:l,startRange:f})}else{const h={startRow:i.startRow,endRow:i.startRow,startColumn:i.startColumn,endColumn:i.startColumn};u.push({startRange:h,repeatRelativeRange:l})}return u};function ga(n){return n?[/<td[^>]*class=".*?xl.*?"[^>]*>/i,/xmlns:x="urn:schemas-microsoft-com:office:excel"/i,/ProgId="Excel.Sheet"/i,/xmlns:o="urn:schemas-microsoft-com:office:office"/i,/@mso-|mso-excel/i,/<x:ExcelWorkbook>/i].some(e=>e.test(n)):!1}function Qm(n){if(!n)return!1;const i=/<img[^>]*src\s*=\s*["']data:image\/[^;]+;base64,[^"']*["'][^>]*>/i;return(n.match(i)||[]).length>0}function Jm(...n){if(n.length===1)return n[0];const i=new a.ObjectMatrix;return n.forEach(e=>{e&&new a.ObjectMatrix(e).forValue((r,o,s)=>{i.setValue(r,o,{...i.getValue(r,o),...s})})}),i.getMatrix()}function $m(n,i){return n.id===i.id&&n.params.unitId===i.params.unitId&&n.params.subUnitId===i.params.subUnitId}function Xo(n){const i=[];for(let e=0;e<n.length;){let t=1;if(n[e].id===m.SetRangeValuesMutation.id){const r=n[e],o=[r];for(;e+t<n.length&&$m(r,n[e+t]);)o.push(n[e+t]),t+=1;const s=Jm(...o.map(l=>l.params.cellValue||{}));i.push({...r,params:{...r.params,cellValue:s}})}else i.push(n[e]);e+=t}return i}function Zi(n,i){const{startRow:e,endRow:t,startColumn:r,endColumn:o}=n;for(let s=e;s<=t;s++)for(let l=r;l<=o;l++)if(i.rows.includes(s)&&i.cols.includes(l))return!0}function Sa(n,i){const{startRow:e,endRow:t,startColumn:r,endColumn:o}=i;for(let s=e;s<=t;s++)if(!n.rows.includes(s))return!1;for(let s=r;s<=o;s++)if(!n.cols.includes(s))return!1;return!0}function eg(n){const i=n.trim().split(`
57
57
  `);let e="<table>";return i.forEach(t=>{const r=t.split(" ");e+="<tr>",r.forEach(o=>{e+=`<td>${o}</td>`}),e+="</tr>"}),e+="</table>",e}var tg=Object.getOwnPropertyDescriptor,ng=(n,i,e,t)=>{for(var r=t>1?void 0:t?tg(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=s(r)||r);return r},Oe=(n,i)=>(e,t)=>i(e,t,n);const ge={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",SPECIAL_PASTE_FORMULA:"special-paste-formula"},rg={[_.FILE_PNG_CLIPBOARD_MIME_TYPE]:"png",[_.FILE__JPEG_CLIPBOARD_MIME_TYPE]:"jpg",[_.FILE__WEBP_CLIPBOARD_MIME_TYPE]:"webp",[_.FILE__BMP_CLIPBOARD_MIME_TYPE]:"bmp"};wn.use(Xm);wn.use(jm);wn.use(zm);const Be=a.createIdentifier("sheet.clipboard-service");exports.SheetClipboardService=class extends a.Disposable{constructor(e,t,r,o,s,l,c,d,u,h,g,S,f,p){super();E(this,"_clipboardHooks",[]);E(this,"_clipboardHooks$",new O.BehaviorSubject([]));E(this,"clipboardHooks$",this._clipboardHooks$.asObservable());E(this,"_htmlToUSM");E(this,"_usmToHtml");E(this,"_copyContentCache");E(this,"_copyMarkId",null);E(this,"_pasteOptionsCache$",new O.BehaviorSubject(null));E(this,"pasteOptionsCache$",this._pasteOptionsCache$.asObservable());E(this,"_showMenu$",new O.BehaviorSubject(!1));E(this,"showMenu$",this._showMenu$.asObservable());this._logService=e,this._univerInstanceService=t,this._selectionManagerService=r,this._clipboardInterfaceService=o,this._undoRedoService=s,this._commandService=l,this._markSelectionService=c,this._notificationService=d,this._platformService=u,this._renderManagerService=h,this._themeService=g,this._localeService=S,this._errorService=f,this._injector=p,this._htmlToUSM=new wn({getCurrentSkeleton:()=>{var v;return(v=T.withCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET,exports.SheetSkeletonManagerService,this._univerInstanceService,this._renderManagerService))==null?void 0:v.getCurrentParam()}}),this._usmToHtml=new Km,this._copyContentCache=new Hm,this.disposeWithMe(this._htmlToUSM),this._initUnitDisposed()}setShowMenu(e){this._showMenu$.next(e)}getPasteMenuVisible(){return this._showMenu$.getValue()}getPasteOptionsCache(){return this._pasteOptionsCache$.getValue()}copyContentCache(){return this._copyContentCache}generateCopyContent(e,t,r,o=ct.COPY){const s=this._clipboardHooks;s.forEach(c=>{var d;return(d=c.onBeforeCopy)==null?void 0:d.call(c,e,t,r,o)});const l=this._generateCopyContent(e,t,r,this._clipboardHooks);return s.forEach(c=>{var d;return(d=c.onAfterCopy)==null?void 0:d.call(c)}),l}async copy(e=ct.COPY){const t=this._selectionManagerService.getCurrentLastSelection();if(!t)return!1;const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),o=r.getActiveSheet();if(!o)return!1;const s=r.getUnitId(),l=o.getSheetId(),c=this.generateCopyContent(s,l,t.range);if(!c)return!1;const{html:d,plain:u,matrixFragment:h,copyId:g,discreteRange:S}=c;this._copyContentCache.set(g,{unitId:r.getUnitId(),subUnitId:o.getSheetId(),range:S,matrix:h,copyType:e}),await this._clipboardInterfaceService.write(u,d),this._markSelectionService.removeAllShapes();const f=Ol(this._themeService);return this._copyMarkId=this._markSelectionService.addShape({...t,style:f}),!0}async cut(){return this.copy(ct.CUT)}async paste(e,t=ge.DEFAULT_PASTE){const r=e.types,o=r.indexOf(_.PLAIN_TEXT_CLIPBOARD_MIME_TYPE)!==-1?await e.getType(_.PLAIN_TEXT_CLIPBOARD_MIME_TYPE).then(d=>d&&d.text()):"",s=r.indexOf(_.HTML_CLIPBOARD_MIME_TYPE)!==-1?await e.getType(_.HTML_CLIPBOARD_MIME_TYPE).then(d=>d&&d.text()):"",l=r.findIndex(d=>_.imageMimeTypeSet.has(d)),c=l===-1||!Qm(s);if(s&&c)return this._platformService.isWindows&&ga(s)&&this._notificationService.show({type:"warning",title:this._localeService.t("clipboard.shortCutNotify.title"),content:this._localeService.t("clipboard.shortCutNotify.useShortCutInstead")}),this._pasteHTML(s,t);if(l!==-1){const d=r[l],u=await e.getType(d);if(u){const h=rg[d],g=new File([u],`clipboard-image.${h}`,{type:d});return this._pasteFiles([g],t)}}return o?this._pastePlainText(o,t):(this._logService.error("[SheetClipboardService]","No valid data on clipboard"),!1)}async legacyPaste(e,t,r){const o=ga(e!=null?e:"");return r&&!o?this._pasteFiles(r,ge.DEFAULT_PASTE):e?this._pasteHTML(e,ge.DEFAULT_PASTE):t?/[\n\t]/.test(t)?this._pasteHTML(eg(t),ge.DEFAULT_PASTE):this._pastePlainText(t,ge.DEFAULT_PASTE):this._pasteUnrecognized()}rePasteWithPasteType(e){const t=this._pasteOptionsCache$.getValue();if(!t)return!1;const r=this._injector.get(a.IUndoRedoService),o=r.pitchTopUndoElement();o&&a.sequenceExecute(o.undoMutations,this._commandService)&&r.popUndoToRedo();const{cellMatrix:s,rowProperties:l=[],colProperties:c=[],source:d,target:u}=t;return this._pasteUSM({cellMatrix:s,colProperties:c,rowProperties:l},u,ge[e],d),!0}updatePasteOptionsCache(e){this._pasteOptionsCache$.next(e)}addClipboardHook(e){if(this._clipboardHooks.findIndex(r=>r.id===e.id)!==-1)return this._logService.error("[SheetClipboardService]","hook already exists",e.id),{dispose:()=>{}};const t=this._clipboardHooks.findIndex(r=>{const o=r.priority||0;return(e.priority||0)<o});return this._clipboardHooks.splice(t!==-1?t:this._clipboardHooks.length,0,e),this._notifyClipboardHook(),a.toDisposable(()=>{const r=this._clipboardHooks.indexOf(e);r>-1&&(this._clipboardHooks.splice(r,1),this._notifyClipboardHook())})}getClipboardHooks(){return this._clipboardHooks}_generateCopyContent(e,t,r,o){const s=this._univerInstanceService.getUniverSheetInstance(e),l=s==null?void 0:s.getSheetBySheetId(t);if(!s||!l)return null;const c=o.reduce((M,y)=>{var x;const P=(x=y.getFilteredOutRows)==null?void 0:x.call(y,r);return P==null||P.forEach(A=>M.add(A)),M},new Set),{startColumn:d,startRow:u,endColumn:h,endRow:g}=r,S=l.getMatrixWithMergedCells(u,d,g,h,a.CellModeEnum.Both),f=new a.ObjectMatrix;let p=u;const v=new a.ObjectMatrix,C={rows:[],cols:[]};for(let M=u;M<=g;M++)if(!c.has(M)){C.rows.push(M);for(let y=d;y<=h;y++){const P=S.getValue(M,y);if(P){const x=a.Tools.deepClone(P);v.setValue(p-u,y-d,{...Bn(),...x}),delete x.displayV,f.setValue(p-u,y-d,{...Bn(),...x})}else v.setValue(p-u,y-d,Bn()),f.setValue(p-u,y-d,Bn()),S.setValue(M,y,Bn())}p+=1}for(let M=d;M<=h;M++)C.cols.push(M);let b=this._usmToHtml.convert(S,C,o);const R=kl(v),w=Nm();return b=b.replace(/(<[a-z]+)/,(M,y)=>`${y} data-copy-id="${w}"`),{copyId:w,plain:R,html:b,matrixFragment:f,discreteRange:C}}_notifyClipboardHook(){this._clipboardHooks$.next(this._clipboardHooks)}async _executePaste(e){const t=this._getPastingTarget();if(!t.subUnitId||!t.selection)return!1;const r=this._injector.invoke(S=>m.rangeToDiscreteRange(t.selection.range,S,t.unitId,t.subUnitId));if(!r)return!1;const{unitId:o,subUnitId:s}=t,l=this._clipboardHooks,c=[];if(l.some(S=>{var f;return c.push(S)&&((f=S.onBeforePaste)==null?void 0:f.call(S,{unitId:o,subUnitId:s,range:r}))===!1}))return c.forEach(S=>{var f;return(f=S.onAfterPaste)==null?void 0:f.call(S,!1)}),!1;const u=[],h=[];c.forEach(S=>{const f=e(S,{unitId:o,subUnitId:s,range:r});f&&(u.push(...f.redos),h.push(...f.undos))});const g=u.every(S=>this._commandService.executeCommand(S.id,S.params));return g&&this._undoRedoService.pushUndoRedo({unitID:this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId(),undoMutations:h,redoMutations:u}),g}async _pasteFiles(e,t){return this._executePaste((r,o)=>{var s;return(s=r.onPasteFiles)==null?void 0:s.call(r,o,e,{pasteType:t})})}async _pastePlainText(e,t){return this._executePaste((r,o)=>{var s;return(s=r.onPastePlainText)==null?void 0:s.call(r,o,e,{pasteType:t})})}_pasteUnrecognized(){return this._executePaste((e,t)=>{var r;return(r=e.onPasteUnrecognized)==null?void 0:r.call(e,t)})}async _pasteHTML(e,t){const r=Dm(e);return r&&this._copyContentCache.get(r)?this._pasteInternal(r,t):this._pasteExternal(e,t)}async _pasteExternal(e,t){var h;const{rowProperties:r,colProperties:o,cellMatrix:s}=this._htmlToUSM.convert(e);if(!s)return!1;const l=this._getPastedRange(s);if(!l)return!1;const c=(h=this._univerInstanceService.getUniverSheetInstance(l.unitId))==null?void 0:h.getSheetBySheetId(l.subUnitId);if(!c)return!1;const d=c==null?void 0:c.getMergeData();return d.length&&d.some(S=>Zi(S,l.pastedRange)&&!Sa(l.pastedRange,S))?(this._errorService.emit(this._localeService.t("clipboard.paste.overlappingMergedCells")),!1):this._pasteUSM({rowProperties:r,colProperties:o,cellMatrix:s},l,t)}async _pasteInternal(e,t){var y,P;const r=a.Tools.deepClone(this._copyContentCache.get(e)),{range:o,matrix:s,unitId:l,subUnitId:c}=r||{};if(!s||!r||!o||!l||!c||!s||!r)return!1;const d=(y=this._univerInstanceService.getUniverSheetInstance(l))==null?void 0:y.getStyles();s.forValue((x,A,k)=>{if(typeof k.s=="string"){const N=a.Tools.deepClone(k);N.s=d==null?void 0:d.getStyleByCell(k),s.setValue(x,A,N)}if(k.colSpan||k.rowSpan)for(let N=0;N<k.rowSpan;N++)for(let H=0;H<k.colSpan;H++){if(N===0&&H===0)continue;const W=x+N,D=A+H;s.setValue(W,D,{s:d==null?void 0:d.getStyleByCell(k)})}});const u=this._getPastedRange(s);if(!u)return!1;const h=(P=this._univerInstanceService.getUniverSheetInstance(u.unitId))==null?void 0:P.getSheetBySheetId(u.subUnitId);if(!h)return!1;const g=h==null?void 0:h.getMergeData();if(g&&g.some(A=>Zi(A,u.pastedRange)&&!Sa(u.pastedRange,A)))return this._errorService.emit(this._localeService.t("clipboard.paste.overlappingMergedCells")),!1;const S=this._univerInstanceService.getUnit(l);if(!S)return!1;const f=S.getSheetBySheetId(c);if(!f)return!1;const p=f.getColumnManager(),v=f.getRowManager(),C=f.getConfig().defaultColumnWidth,b=f.getConfig().defaultRowHeight,R=[],w=[];if(o.cols.forEach(x=>{const A=p.getColumnOrCreate(x);R.push({width:`${A.w||C}`})}),o.rows.forEach(x=>{const A=v.getRowOrCreate(x),{ah:k=b,h:N=b}=A,H=Math.max(k,N);w.push({height:`${H}`})}),r.copyType===ct.CUT){const x=u.pastedRange.rows[0],A=o.rows[o.rows.length-1]-o.rows[0]+x;u.pastedRange.rows=Array.from(new Array(A+1).keys()).slice(x)}const M=this._pasteUSM({cellMatrix:s,colProperties:R,rowProperties:w},u,t,{range:o,unitId:r.unitId,subUnitId:r.subUnitId,copyType:r.copyType,copyId:e});return r.copyType===ct.CUT&&(this._copyContentCache.set(e,{...r,matrix:null}),this._copyMarkId&&this._markSelectionService.removeShape(this._copyMarkId),this._copyMarkId=null),M}_pasteUSM(e,t,r,o){const{rowProperties:s,colProperties:l,cellMatrix:c}=e,{unitId:d,subUnitId:u,pastedRange:h}=t,g=h.cols.length,S=this._clipboardHooks,f=[];if(S.some(P=>{var x;return f.push(P)&&((x=P.onBeforePaste)==null?void 0:x.call(P,{unitId:d,subUnitId:u,range:h}))===!1}))return f.forEach(P=>{var x;return(x=P.onAfterPaste)==null?void 0:x.call(P,!1)}),!1;if(!c)return!1;const v=o?{unitId:o.unitId,subUnitId:o.subUnitId,range:o.range}:null,C={copyType:(o==null?void 0:o.copyType)||ct.COPY,copyId:o==null?void 0:o.copyId,pasteType:r};let b=[],R=[];const w=f.filter(P=>!P.specialPasteInfo&&P.id!==ge.DEFAULT_PASTE||r===P.id);w.forEach(P=>{var k,N,H;if(s){const W=(k=P.onPasteRows)==null?void 0:k.call(P,{range:h,unitId:d,subUnitId:u},s,{pasteType:r});W&&(b.push(...W.redos),R.push(...W.undos))}const x=(N=P.onPasteColumns)==null?void 0:N.call(P,{range:h,unitId:d,subUnitId:u},l||new Array(g).map(()=>({})),{pasteType:r});x&&(b.push(...x.redos),R.push(...x.undos));const A=(H=P.onPasteCells)==null?void 0:H.call(P,v,{range:h,unitId:d,subUnitId:u},c,C);A&&(b.push(...A.redos),R.push(...A.undos))});const M=this._getSetSelectionOperation(d,u,h,c,r);M&&b.push(M),b=Xo(b),R=Xo(R),R.push({id:m.SetWorksheetActiveOperation.id,params:{unitId:t.unitId,subUnitId:t.subUnitId}}),this._logService.log("[SheetClipboardService]","pasting mutations",{undoMutationsInfo:R,redoMutationsInfo:b});const y=b.every(P=>this._commandService.syncExecuteCommand(P.id,P.params));return y&&(this._undoRedoService.pushUndoRedo({unitID:d,undoMutations:R,redoMutations:b}),this.updatePasteOptionsCache({target:{pastedRange:h,unitId:d,subUnitId:u},cellMatrix:c,rowProperties:s,colProperties:l,pasteType:r,source:o}),this.setShowMenu(!0)),w.forEach(P=>{var x;return(x=P.onAfterPaste)==null?void 0:x.call(P,y)}),y}_getSetSelectionOperation(e,t,r,o,s){var M;const l=(M=this._univerInstanceService.getUniverSheetInstance(e))==null?void 0:M.getSheetBySheetId(t);if(!l)return null;const{rows:c,cols:d}=r,u=c[0],h=d[0],g=c[c.length-1],S=d[d.length-1],f={startRow:u,endRow:u,startColumn:h,endColumn:h},p=m.getPrimaryForRange(f,l),v=o.getValue(0,0),C=(v==null?void 0:v.rowSpan)||1,b=(v==null?void 0:v.colSpan)||1;if((s===ge.DEFAULT_PASTE||s===ge.SPECIAL_PASTE_BESIDES_BORDER||s===ge.SPECIAL_PASTE_FORMAT)&&(C>1||b>1)){const y={startRow:u,endRow:u+C-1,startColumn:h,endColumn:h+b-1};p.startRow=y.startRow,p.endRow=y.endRow,p.startColumn=y.startColumn,p.endColumn=y.endColumn,p.isMerged=!0,p.isMergedMainCell=!0}const w={unitId:e,subUnitId:t,selections:[{range:{startRow:u,endRow:g,startColumn:h,endColumn:S},primary:p,style:null}]};return{id:m.SetSelectionsOperation.id,params:w}}_getPastingTarget(){const e=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),t=e.getActiveSheet(),r=this._selectionManagerService.getCurrentLastSelection();return{unitId:e.getUnitId(),subUnitId:t==null?void 0:t.getSheetId(),selection:r}}_transformPastedData(e,t,r){const o=this._getPastingTarget(),{selection:s,unitId:l,subUnitId:c}=o;if(!c||!s)return null;const d=this._injector.invoke(N=>m.rangeToDiscreteRange(s.range,N,l,c));if(!d)return null;const{ranges:[u],mapFunc:h}=Gt([d]),{startRow:g,startColumn:S,endRow:f,endColumn:p}=u,v=f-g+1,C=p-S+1,b=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),R=b==null?void 0:b.getActiveSheet();if(!R)return null;const M=R.getMergeData().filter(N=>d.rows.includes(N.startRow)&&d.cols.includes(N.startColumn)),y=M[0];let P=0,x=0,A=0,k=0;if(y&&(P=y.startRow,x=y.startColumn,A=y.endRow,k=y.endColumn),v%e===0&&C%t===0)if(M.length>0&&(v!==e||C!==t))if(P===d.rows[0]&&x===d.cols[0]&&A===d.rows[v-1]&&k===d.cols[C-1])if(ag(r))for(let H=0;H<v;H++)for(let W=0;W<C;W++){const D=r.getValue(H%e,W%t);D&&r.setValue(H,W,D)}else r.forValue((H,W,D)=>{D.s=null,delete D.colSpan,delete D.rowSpan});else for(let N=0;N<v;N++)for(let H=0;H<C;H++){const W=r.getValue(N%e,H%t);W&&r.setValue(N,H,W)}else for(let N=0;N<v;N++)for(let H=0;H<C;H++){const W=r.getValue(N%e,H%t);W&&r.setValue(N,H,W)}else if(M.length>0){const{row:N,col:H}=h(g,S);if(this._topLeftCellsMatch(e,t,{topRow:N,leftCol:H})){const D=this._expandOrShrinkRowsCols(l,c,d,t,e);d.rows=D.rows,d.cols=D.cols}else{if(f>y.endRow||p>y.endColumn)return null;r.forValue((D,U,L)=>{L.s=null,delete L.colSpan,delete L.rowSpan})}}else{const N=this._expandOrShrinkRowsCols(l,c,d,t,e);d.rows=N.rows,d.cols=N.cols}return{pastedRange:d,unitId:l,subUnitId:c}}_getPastedRange(e){var R;const t=this._getPastingTarget(),{selection:r,unitId:o,subUnitId:s}=t;if(!s||!r)return null;const l=this._injector.invoke(w=>m.rangeToDiscreteRange(r.range,w,o,s));if(!l)return null;const{startColumn:c,endColumn:d,startRow:u,endRow:h}=e.getDataRange(),g=h-u+1,S=d-c+1;if(g<=0||S<=0)return null;const f=l.rows.length,p=l.cols.length,v=(R=this._univerInstanceService.getUniverSheetInstance(o))==null?void 0:R.getSheetBySheetId(s);if(!v)return null;const C=v==null?void 0:v.getMergeData();if(f%g===0&&p%S===0&&!(C==null?void 0:C.some(M=>Zi(M,l)))){for(let M=0;M<f;M++)for(let y=0;y<p;y++){const P=e.getValue(M%g,y%S);P&&e.setValue(M,y,P)}return{pastedRange:l,unitId:o,subUnitId:s}}const b=this._expandOrShrinkRowsCols(o,s,l,S,g);return l.rows=b.rows,l.cols=b.cols,{pastedRange:l,unitId:o,subUnitId:s}}_expandOrShrinkRowsCols(e,t,r,o,s){const{rows:l,cols:c}=r,d=this._univerInstanceService.getUniverSheetInstance(e),u=d==null?void 0:d.getSheetBySheetId(t);let h,g;if(l.length>=s)h=l.slice(0,s);else{h=l.slice(0);let S=l[l.length-1]+1;for(;h.length<s;)u.getRowFiltered(S)||h.push(S),S++}if(c.length>=o)g=c.slice(0,o);else{g=c.slice(0);let S=c[c.length-1]+1;for(;g.length<o;)g.push(S),S++}return{rows:h,cols:g}}_topLeftCellsMatch(e,t,r){const o=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=o==null?void 0:o.getActiveSheet();if(!s)return!1;const{topRow:l,leftCol:c}=r,d=og(l+e-1,c,c+t-1,s),u=sg(c+t-1,l,l+e-1,s);return!d&&!u}removeMarkSelection(){this._copyMarkId&&(this._markSelectionService.removeShape(this._copyMarkId),this._copyMarkId=null)}_initUnitDisposed(){this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).subscribe(e=>{e&&this.copyContentCache().clearWithUnitId(e.getUnitId())}))}disposePasteOptionsCache(){this.setShowMenu(!1),this.updatePasteOptionsCache(null)}};exports.SheetClipboardService=ng([Oe(0,a.ILogService),Oe(1,a.IUniverInstanceService),Oe(2,a.Inject(m.SheetsSelectionsService)),Oe(3,_.IClipboardInterfaceService),Oe(4,a.IUndoRedoService),Oe(5,a.ICommandService),Oe(6,qt),Oe(7,_.INotificationService),Oe(8,_.IPlatformService),Oe(9,T.IRenderManagerService),Oe(10,a.Inject(a.ThemeService)),Oe(11,a.Inject(a.LocaleService)),Oe(12,a.Inject(a.ErrorService)),Oe(13,a.Inject(a.Injector))],exports.SheetClipboardService);function kl(n){let i="";const e=n.getLength();return n.forRow((t,r)=>{const o=[];r.forEach(s=>{const l=n.getValue(t,s);if(l){const c=ig(l);o.push(c)}}),i+=o.join(" "),t!==e-1&&(i+=`
58
- `)}),i}function ig(n){return a.isNotNullOrUndefined(n.displayV)?n.displayV:a.extractPureTextFromCell(n)}function og(n,i,e,t){return t.getMergeData().some(r=>r.startRow<=n&&n<r.endRow&&i<=r.startColumn&&r.startColumn<=e)}function sg(n,i,e,t){return t.getMergeData().some(r=>r.startColumn<=n&&n<r.endColumn&&i<=r.startRow&&r.startRow<=e)}function ag(n){let i=0;return n.forValue((e,t,r)=>{if(r&&i++,i>1)return!1}),i>1}function Bn(){return{p:null,v:null,s:null,f:null,si:null,t:null}}const ys=998,Xe={id:_.CopyCommand.id,name:"sheet.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:ys,preconditions:Es,handler:async n=>n.get(Be).copy()},Ms={id:_.CutCommand.id,name:"sheet.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:ys,preconditions:Es,handler:async n=>n.get(Be).cut()},Ye={id:_.PasteCommand.id,type:a.CommandType.COMMAND,multi:!0,name:"sheet.command.paste",priority:ys,preconditions:Es,handler:async(n,i)=>{const t=await n.get(_.IClipboardInterfaceService).read(),r=n.get(Be);return t.length!==0?r.paste(t[0],i==null?void 0:i.value):!1}},oi={id:_.SheetPasteShortKeyCommandName,type:a.CommandType.COMMAND,handler:async(n,i)=>{const e=n.get(Be),{htmlContent:t,textContent:r,files:o}=i;return e.legacyPaste(t,r,o),!0}},gn={id:"sheet.command.paste-value",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Ye.id,{value:ge.SPECIAL_PASTE_VALUE})},Sn={id:"sheet.command.paste-format",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Ye.id,{value:ge.SPECIAL_PASTE_FORMAT})},Vt={id:"sheet.command.paste-col-width",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Ye.id,{value:ge.SPECIAL_PASTE_COL_WIDTH})},fn={id:"sheet.command.paste-besides-border",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Ye.id,{value:ge.SPECIAL_PASTE_BESIDES_BORDER})},Nl={id:"sheet.command.optional-paste",type:a.CommandType.COMMAND,handler:async(n,{type:i})=>n.get(Be).rePasteWithPasteType(i)},fr={id:"sheet.command.hide-row-confirm",type:a.CommandType.COMMAND,handler:async n=>{var c;const e=(c=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:c.map(d=>d.range);if(!(e!=null&&e.length))return!1;const t=n.get(a.ICommandService),r=n.get(a.IUniverInstanceService),o=m.getSheetCommandTarget(r);if(!o)return!1;const{worksheet:s}=o,l=s.getVisibleRows();if(Ka(l,e)){const d=n.get(_.IConfirmService),u=n.get(a.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 t.executeCommand(m.SetRowHiddenCommand.id),!0}},pr={id:"sheet.command.hide-col-confirm",type:a.CommandType.COMMAND,handler:async n=>{var c;const e=(c=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:c.map(d=>d.range);if(!(e!=null&&e.length))return!1;const t=n.get(a.ICommandService),r=n.get(a.IUniverInstanceService),o=m.getSheetCommandTarget(r);if(!o)return!1;const{worksheet:s}=o,l=s.getVisibleCols();if(qa(l,e)){const d=n.get(_.IConfirmService),u=n.get(a.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 t.executeCommand(m.SetColHiddenCommand.id),!0}},Qt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-bold",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand($.SetInlineFormatBoldCommand.id):i.executeCommand(m.SetBoldCommand.id)}},Jt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-italic",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand($.SetInlineFormatItalicCommand.id):i.executeCommand(m.SetItalicCommand.id)}},$t={type:a.CommandType.COMMAND,id:"sheet.command.set-range-underline",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand($.SetInlineFormatUnderlineCommand.id):i.executeCommand(m.SetUnderlineCommand.id)}},en={type:a.CommandType.COMMAND,id:"sheet.command.set-range-stroke",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand($.SetInlineFormatStrikethroughCommand.id):i.executeCommand(m.SetStrikeThroughCommand.id)}},Ps={type:a.CommandType.COMMAND,id:"sheet.command.set-range-subscript",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand($.SetInlineFormatSubscriptCommand.id):!1}},Os={type:a.CommandType.COMMAND,id:"sheet.command.set-range-superscript",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand($.SetInlineFormatSuperscriptCommand.id):!1}},vr={type:a.CommandType.COMMAND,id:"sheet.command.set-range-fontsize",handler:async(n,i)=>{const e=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand($.SetInlineFormatFontSizeCommand.id,i):e.executeCommand(m.SetFontSizeCommand.id,i)}},Cr={type:a.CommandType.COMMAND,id:"sheet.command.set-range-font-family",handler:async(n,i)=>{const e=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand($.SetInlineFormatFontFamilyCommand.id,i):e.executeCommand(m.SetFontFamilyCommand.id,i)}},Tn={type:a.CommandType.COMMAND,id:"sheet.command.set-range-text-color",handler:async(n,i)=>{const e=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand($.SetInlineFormatTextColorCommand.id,i):e.executeCommand(m.SetTextColorCommand.id,i)}},xs={type:a.CommandType.COMMAND,id:"sheet.command.reset-range-text-color",handler:async n=>{const i=n.get(a.ICommandService),t=n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED),r=n.get(a.ThemeService);return t?i.executeCommand($.SetInlineFormatTextColorCommand.id,{value:null}):i.executeCommand(m.SetTextColorCommand.id,{value:r.getCurrentTheme().textColor})}};var lg=Object.getOwnPropertyDescriptor,cg=(n,i,e,t)=>{for(var r=t>1?void 0:t?lg(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=s(r)||r);return r},ln=(n,i)=>(e,t)=>i(e,t,n),Ne=(n=>(n[n.OFF=0]="OFF",n[n.ONCE=1]="ONCE",n[n.INFINITE=2]="INFINITE",n))(Ne||{});const et=a.createIdentifier("univer.format-painter-service");let si=class extends a.Disposable{constructor(i,e,t,r,o,s){super();E(this,"status$");E(this,"_selectionFormat");E(this,"_markId",null);E(this,"_status$");E(this,"_defaultHook",null);E(this,"_extendHooks",[]);this._selectionManagerService=i,this._themeService=e,this._markSelectionService=t,this._logService=r,this._commandService=o,this._undoRedoService=s,this._status$=new O.BehaviorSubject(0),this.status$=this._status$.asObservable(),this._selectionFormat={styles:new a.ObjectMatrix,merges:[]}}addHook(i){var e,t,r;i.isDefaultHook&&((e=i.priority)!=null?e:0)>((r=(t=this._defaultHook)==null?void 0:t.priority)!=null?r:-1)?this._defaultHook=i:(this._extendHooks.push(i),this._extendHooks.sort((o,s)=>(o.priority||0)-(s.priority||0)))}getHooks(){return this._defaultHook?[this._defaultHook,...this._extendHooks]:this._extendHooks}setStatus(i){this._updateRangeMark(i),this._status$.next(i),this.getHooks().forEach(t=>{t.onStatusChange!==void 0&&t.onStatusChange(i)})}getStatus(){return this._status$.getValue()}setSelectionFormat(i){this._selectionFormat=i}getSelectionFormat(){return this._selectionFormat}applyFormatPainter(i,e,t){const r=this.getHooks(),o=[],s=[];r.forEach(c=>{if(c.onApply!==void 0){const d=c.onApply(i,e,t,this._selectionFormat);d&&(o.push(...d.redos),s.push(...d.undos))}});for(const c of r)if(c.onBeforeApply!==void 0&&!c.onBeforeApply({unitId:i,subUnitId:e,range:t,redoMutationsInfo:o,format:this._selectionFormat,undoMutationsInfo:s}))return!1;this._logService.log("[FormatPainterService]","apply mutations",{undoMutationsInfo:s,redoMutationsInfo:o});const l=o.every(c=>this._commandService.executeCommand(c.id,c.params));return l&&this._undoRedoService.pushUndoRedo({unitID:i,undoMutations:s,redoMutations:o}),l}_updateRangeMark(i){if(this._markSelectionService.removeAllShapes(),i!==0){const e=this._selectionManagerService.getCurrentLastSelection();if(e){const t=Ol(this._themeService);i===2?this._markId=this._markSelectionService.addShape({...e,style:t}):this._markId=this._markSelectionService.addShape({...e,style:t},[m.SetRangeValuesMutation.id])}}}};si=cg([ln(0,a.Inject(m.SheetsSelectionsService)),ln(1,a.Inject(a.ThemeService)),ln(2,qt),ln(3,a.ILogService),ln(4,a.ICommandService),ln(5,a.IUndoRedoService)],si);const _r={id:"sheet.operation.set-format-painter",type:a.CommandType.OPERATION,handler:(n,i)=>i?(n.get(et).setStatus(i.status),!0):!1},Vi={type:a.CommandType.COMMAND,id:"sheet.command.set-infinite-format-painter",handler:async n=>{const e=n.get(et).getStatus();let t;return e!==Ne.OFF?t=Ne.OFF:t=Ne.INFINITE,n.get(a.ICommandService).executeCommand(_r.id,{status:t})}},kn={type:a.CommandType.COMMAND,id:"sheet.command.set-once-format-painter",handler:async n=>{const e=n.get(et).getStatus();let t;return e!==Ne.OFF?t=Ne.OFF:t=Ne.ONCE,n.get(a.ICommandService).executeCommand(_r.id,{status:t})}},Ir={type:a.CommandType.COMMAND,id:"sheet.command.apply-format-painter",handler:async(n,i)=>n.get(et).applyFormatPainter(i.unitId,i.subUnitId,i.range)},ht={type:a.CommandType.COMMAND,id:"sheet.command.set-selection-frozen",handler:async(n,i)=>{const{type:e}=i||{},t=n.get(a.IUniverInstanceService),r=n.get(a.IUndoRedoService),o=m.getSheetCommandTarget(t);if(!o)return!1;const{unitId:s,subUnitId:l}=o,c=n.get(a.ICommandService),u=n.get(m.SheetsSelectionsService).getCurrentSelections();if(!u)return!1;const h=u[(u==null?void 0:u.length)-1],{range:g}=h,f=n.get(T.IRenderManagerService).getRenderById(s).with(exports.SheetScrollManagerService),{sheetViewStartRow:p=0,sheetViewStartColumn:v=0}=f.getCurrentScrollState()||{};let C,b,R,w;const{startRow:M,startColumn:y,rangeType:P}=g;if(P===a.RANGE_TYPE.ROW||e===1)C=M,R=M-p,b=-1,w=0;else if(P===a.RANGE_TYPE.COLUMN||e===2)C=-1,R=0,b=y,w=y-v;else if(P===a.RANGE_TYPE.NORMAL)C=M,R=M-p,b=y,w=y-v;else return!1;const x={unitId:s,subUnitId:l,startRow:C,startColumn:b,xSplit:b>0?Math.max(1,w):w,ySplit:C>0?Math.max(1,R):R},A=m.SetFrozenMutationFactory(n,x);return c.syncExecuteCommand(m.SetFrozenMutation.id,x)&&r.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetFrozenMutation.id,params:A}],redoMutations:[{id:m.SetFrozenMutation.id,params:x}]}),!0}},br={type:a.CommandType.COMMAND,id:"sheet.command.set-row-frozen",handler:async n=>(n.get(a.ICommandService).executeCommand(ht.id,{type:1}),!0)},Rr={type:a.CommandType.COMMAND,id:"sheet.command.set-col-frozen",handler:async n=>(n.get(a.ICommandService).executeCommand(ht.id,{type:2}),!0)};var dg=Object.getOwnPropertyDescriptor,ug=(n,i,e,t)=>{for(var r=t>1?void 0:t?dg(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=s(r)||r);return r},fa=(n,i)=>(e,t)=>i(e,t,n);const hg=(n,i)=>{const{unitId:e,subUnitId:t,ranges:r}=n,o={},s=i.getColumnManager();for(let l=0;l<r.length;l++){const c=r[l];for(let d=c.startColumn;d<c.endColumn+1;d++){const u=s.getColumnOrCreate(d);o[d]=u.w}}return{unitId:e,subUnitId:t,ranges:r,colWidth:o}};exports.AutoWidthController=class extends a.Disposable{constructor(i,e){super(),this._renderManagerService=i,this._univerInstanceService=e}getUndoRedoParamsOfColWidth(i){const e={redos:[],undos:[]},{_univerInstanceService:t}=this,r=m.getSheetCommandTarget(t);if(!r)return e;const{unitId:o,subUnitId:s,worksheet:l}=r,c=this._renderManagerService.getRenderById(o).with(exports.SheetSkeletonManagerService);if(!c.getCurrentParam())return e;const{skeleton:d}=c.getCurrentParam(),u=d.calculateAutoWidthInRange(i.ranges),h={};for(const{col:f,width:p}of u)h[f]=p;const g={subUnitId:s,unitId:o,ranges:i.ranges,colWidth:h},S=hg(g,l);return{undos:[{id:m.SetWorksheetColWidthMutation.id,params:S}],redos:[{id:m.SetWorksheetColWidthMutation.id,params:g}]}}};exports.AutoWidthController=ug([fa(0,T.IRenderManagerService),fa(1,a.Inject(a.IUniverInstanceService))],exports.AutoWidthController);const Er={type:a.CommandType.COMMAND,id:"sheet.command.set-col-auto-width",handler:(n,i)=>{const e=n.get(a.ICommandService),t=n.get(a.IUndoRedoService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(o,i);if(!s)return!1;const{unitId:l,subUnitId:c}=s;let d=[];if(i!=null&&i.ranges)d=[...i.ranges];else{const f=r.getCurrentSelections();for(let p=0;p<f.length;p++)d.push(f[p].range)}if(!(d!=null&&d.length))return!1;const u={unitId:l,subUnitId:c,ranges:d},{redos:h,undos:g}=n.get(exports.AutoWidthController).getUndoRedoParamsOfColWidth(u);return a.sequenceExecute([...h],e).result?(t.pushUndoRedo({unitID:l,undoMutations:[...g],redoMutations:[...h]}),!0):!1}},Nn="UI_PLUGIN_SHEETS",wr=`${Nn}_COLOR_PICKER_COMPONENT`,Wi=`${Nn}_FONT_FAMILY_COMPONENT`,Ui=`${Nn}_FONT_FAMILY_ITEM_COMPONENT`,Li=`${Nn}_FONT_SIZE_COMPONENT`,tt=`${Nn}_MENU_ITEM_INPUT_COMPONENT`,mg="univer-sheets-ui-context-menu-input",gg="univer-sheets-ui-context-menu-input-container",Sg="univer-sheets-ui-context-menu-input-number",Ki={sheetsUiContextMenuInput:mg,sheetsUiContextMenuInputContainer:gg,sheetsUiContextMenuInputNumber:Sg},Dl=n=>{const{prefix:i,suffix:e,value:t,onChange:r,min:o=Number.MIN_SAFE_INTEGER,max:s=Number.MAX_SAFE_INTEGER}=n,l=_.useDependency(a.LocaleService),c=_.useDependency(_.IContextMenuService),[d,u]=V.useState(),h=S=>{var f;u(S==null?void 0:S.toString()),r((f=S==null?void 0:S.toString())!=null?f:"")};V.useEffect(()=>{c.visible||u(t)},[c.visible]),V.useEffect(()=>{u(t)},[t]);function g(S){S.key==="Backspace"&&S.stopPropagation()}return I.jsxs("div",{className:Ki.sheetsUiContextMenuInput,children:[l.t(i),I.jsx("span",{className:Ki.sheetsUiContextMenuInputContainer,onClick:S=>S.stopPropagation(),children:I.jsx(Y.InputNumber,{className:Ki.sheetsUiContextMenuInputNumber,value:Number(d),precision:0,onKeyDown:g,onChange:h,min:o,max:s})}),l.t(e)]})};function fg(n){return n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(me.switchMap(i=>i?i.activeSheet$.pipe(me.map(e=>e?{workbook:i,worksheet:e}:null)):O.of(null)))}function be(n,i,e){return fg(n).pipe(me.switchMap(t=>t?e(t):O.of(i)))}function Hl(n,i){const e=n.get(a.IUniverInstanceService),t=n.get(m.IExclusiveRangeService),r=n.get(m.SheetsSelectionsService);return e.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(me.switchMap(s=>s?O.combineLatest([r.selectionMoveEnd$,s.activeSheet$]).pipe(me.switchMap(([l,c])=>{if(!c||l.length===0)return O.of(!1);const d=t.getInterestGroupId(l);if(i){const u=d.filter(h=>i.has(h));return O.of(u.length>0)}else return O.of(d.length>0)})):O.of(!1)))}function tn(n,i,e){return O.combineLatest([i,Hl(n,e)]).pipe(me.map(([t,r])=>t||r))}function te(n,i={},e=!1){var g;const r=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),o=n.get(a.UserManagerService),s=n.has(Se)?n.get(Se):null,l=n.get(a.IContextService),c=new O.BehaviorSubject(!1),d=(g=s==null?void 0:s.visible$)!=null?g:O.of(null),u=l.subscribeContextValue$(a.FOCUSING_FX_BAR_EDITOR).subscribe(S=>{c.next(S)});return O.combineLatest([o.currentUser$,r,d,c]).pipe(me.finalize(()=>{u.unsubscribe(),c.complete()}),me.switchMap(([S,f,p,v])=>!f||p!=null&&p.visible&&p.unitId===f.getUnitId()&&!e||v&&!e?O.of(!0):f.activeSheet$.pipe(me.switchMap(C=>{if(!C)return O.of(!0);const b=n.get(m.SheetsSelectionsService),R=n.get(m.RangeProtectionRuleModel),w=n.get(m.WorksheetProtectionRuleModel),y=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_COMMON_DRAWINGS).pipe(me.startWith(!1));return O.combineLatest([b.selectionMoveEnd$,y]).pipe(me.switchMap(([P,x])=>{if(x)return O.of(!0);const A=f.getUnitId(),k=C.getSheetId(),N=n.get(a.IPermissionService),{workbookTypes:H=[m.WorkbookEditablePermission],worksheetTypes:W,rangeTypes:D}=i,U=[];if(H==null||H.forEach(j=>{U.push(new j(A).id)}),W==null||W.forEach(j=>{U.push(new j(A,k).id)}),w.getRule(A,k))return N.composePermission$(U).pipe(me.map(j=>j.some(z=>z.value===!1)));const F=P==null?void 0:P.map(j=>j.range),B=R.getSubunitRuleList(A,k).filter(j=>F==null?void 0:F.some(z=>j.ranges.some(K=>a.Rectangle.intersects(z,K))));return D==null||D.forEach(j=>{B.forEach(z=>{U.push(new j(A,k,z.permissionId).id)})}),N.composePermission$(U).pipe(me.map(j=>j.some(z=>z.value===!1)))}))}))))}function Dn(n){const i=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(m.RangeProtectionRuleModel),r=n.get(a.IPermissionService);return O.merge(e.selectionMoveEnd$,r.permissionPointUpdate$.pipe(me.debounceTime(100))).pipe(me.map(()=>{var h;const o=(h=e.getCurrentLastSelection())==null?void 0:h.range;if(!o)return!0;const s=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),l=s==null?void 0:s.getActiveSheet();if(!s||!l)return!0;const c=s.getUnitId(),d=l.getSheetId(),u=[new m.WorkbookEditablePermission(c).id,new m.WorksheetEditPermission(c,d).id];return t.getSubunitRuleList(c,d).filter(g=>g.ranges.some(S=>a.Rectangle.intersects(o,S))).forEach(g=>{u.push(new m.RangeProtectionPermissionEditPoint(c,d,g.permissionId).id)}),r.composePermission(u).some(g=>g.value===!1)}))}function Vl(n,i){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.RangeProtectionRuleModel),o=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,o.permissionPointUpdate$.pipe(me.debounceTime(100))).pipe(me.map(()=>{var g;const s=(g=t.getCurrentLastSelection())==null?void 0:g.range;if(!s)return!0;const l=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),c=l==null?void 0:l.getActiveSheet();if(!l||!c)return!0;const d=l.getUnitId(),u=c.getSheetId(),h=[new m.WorkbookEditablePermission(d).id,new m.WorksheetEditPermission(d,u).id];return r.getSubunitRuleList(d,u).filter(S=>i==="row"?S.ranges.some(f=>s.startRow>f.startRow&&s.startRow<=f.endRow):S.ranges.some(f=>s.startColumn>f.startColumn&&s.startColumn<=f.endColumn)).forEach(S=>{h.push(new m.RangeProtectionPermissionEditPoint(d,u,S.permissionId).id)}),o.composePermission(h).some(S=>S.value===!1)}))}function Wl(n,i){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.RangeProtectionRuleModel),o=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,o.permissionPointUpdate$.pipe(me.debounceTime(100))).pipe(me.map(()=>{var S;const s=(S=t.getCurrentLastSelection())==null?void 0:S.range;if(!s)return!0;const l=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),c=l==null?void 0:l.getActiveSheet();if(!l||!c)return!0;const d=l.getUnitId(),u=c.getSheetId(),h=[new m.WorkbookEditablePermission(d).id,new m.WorksheetEditPermission(d,u).id],g=a.Tools.deepClone(s);return i==="row"?(g.startColumn=0,g.endColumn=c.getColumnCount()-1):(g.startRow=0,g.endRow=c.getRowCount()-1),r.getSubunitRuleList(d,u).filter(f=>f.ranges.some(p=>a.Rectangle.intersects(g,p))).forEach(f=>{h.push(new m.RangeProtectionPermissionEditPoint(d,u,f.permissionId).id)}),o.composePermission(h).some(f=>f.value===!1)}))}function Bi(n,i){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.RangeProtectionRuleModel),o=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,o.permissionPointUpdate$.pipe(me.debounceTime(100))).pipe(me.map(()=>{var S;const s=(S=t.getCurrentLastSelection())==null?void 0:S.range;if(!s)return!0;const l=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),c=l==null?void 0:l.getActiveSheet();if(!l||!c)return!0;const d=l.getUnitId(),u=c.getSheetId(),h=[new m.WorkbookEditablePermission(d).id,new m.WorksheetEditPermission(d,u).id],g=a.Tools.deepClone(s);return i==="row"?g.endRow=c.getRowCount()-1:g.endColumn=c.getColumnCount()-1,r.getSubunitRuleList(d,u).filter(f=>f.ranges.some(p=>a.Rectangle.intersects(g,p))).forEach(f=>{h.push(new m.RangeProtectionPermissionEditPoint(d,u,f.permissionId).id)}),o.composePermission(h).some(f=>f.value===!1)}))}function Hn(n,i){const t=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(m.WorksheetProtectionRuleModel),o=n.get(m.RangeProtectionRuleModel),s=n.get(a.IPermissionService),l=n.get(a.UserManagerService);return O.combineLatest([l.currentUser$,t]).pipe(me.switchMap(([c,d])=>d?d.activeSheet$.pipe(me.switchMap(u=>{if(!u)return O.of(!0);const h=d.getUnitId(),g=[];return i.forEach(f=>g.push(new f(h).id)),s.composePermission$(g).pipe(me.map(f=>f.every(p=>p.value===!0))).pipe(me.map(f=>{if(!f)return!0;const p=u.getSheetId(),v=r.getRule(h,p),C=o.getSubunitRuleList(h,p);return!!(v||C.length)}))})):O.of(!0)))}var Ul=(n=>(n.ROW_HEADER_CONTEXT_MENU="ROW_HEADER_CONTEXT_MENU",n.COL_HEADER_CONTEXT_MENU="COL_HEADER_CONTEXT_MENU",n.SHEET_BAR="SHEET_BAR",n.SHEET_FOOTER="SHEET_FOOTER",n))(Ul||{});function pg(n){const i=n.get(et);return{id:kn.id,subId:Vi.id,type:_.MenuItemType.BUTTON,icon:"BrushSingle",title:"Format Painter",tooltip:"toolbar.formatPainter",activated$:new O.Observable(e=>{let t=!1;const r=i.status$.subscribe(o=>{t=o!==Ne.OFF,e.next(t)});return e.next(t),()=>{r.unsubscribe()}}),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetCopyPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0)}}function vg(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(a.IContextService),r=n.get(m.SheetsSelectionsService);return{id:Qt.id,type:_.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:be(e,!1,({worksheet:o})=>new O.Observable(s=>{var u;const l=i.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const p=(S=r.getCurrentLastSelection())==null?void 0:S.primary;let v=a.FontWeight.NORMAL;if(p!=null){const C=o.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getFontWeight()}s.next(v===a.FontWeight.BOLD)}if((g===Re.SetTextSelectionsOperation.id||g===$.SetInlineFormatCommand.id)&&t.getContextValue(a.EDITOR_ACTIVATED)&&t.getContextValue(a.FOCUSING_SHEET)){const p=yr(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.bl;s.next(v===a.BooleanNumber.TRUE)}}),c=(u=r.getCurrentLastSelection())==null?void 0:u.primary;if(!o){s.next(!1);return}let d=a.FontWeight.NORMAL;if(c!=null){const h=o.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getFontWeight()}return s.next(d===a.FontWeight.BOLD),l.dispose})),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Cg(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService);return{id:Jt.id,type:_.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:be(e,!1,({worksheet:o})=>new O.Observable(s=>{var u;const l=i.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const p=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let v=a.FontItalic.NORMAL;if(p!=null){const C=o.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getFontStyle()}s.next(v===a.FontItalic.ITALIC)}if((g===Re.SetTextSelectionsOperation.id||g===$.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const p=yr(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.it;s.next(v===a.BooleanNumber.TRUE)}}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d=a.FontItalic.NORMAL;if(c!=null){const h=o.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getFontStyle()}return s.next(d===a.FontItalic.ITALIC),l.dispose})),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function _g(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService);return{id:$t.id,type:_.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",activated$:be(e,!1,({worksheet:o})=>new O.Observable(s=>{var u;const l=i.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const p=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let v;if(p!=null){const C=o.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getUnderline()}s.next(!!(v&&v.s))}if((g===Re.SetTextSelectionsOperation.id||g===$.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const p=yr(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.ul;s.next((v==null?void 0:v.s)===a.BooleanNumber.TRUE)}}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d;if(c!=null){const h=o.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getUnderline()}return s.next(!!(d&&d.s)),l.dispose})),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Ig(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService);return{id:en.id,type:_.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:be(e,!1,({worksheet:o})=>new O.Observable(s=>{var u;const l=i.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const p=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let v;if(p!=null){const C=o.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getStrikeThrough()}s.next(!!(v&&v.s))}if((g===Re.SetTextSelectionsOperation.id||g===$.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const p=yr(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.st;s.next((v==null?void 0:v.s)===a.BooleanNumber.TRUE)}}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d;if(c!=null){const h=o.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getStrikeThrough()}return s.next(!!(d&&d.s)),l.dispose})),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function bg(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=a.DEFAULT_STYLES.ff;return{id:Cr.id,tooltip:"toolbar.font",type:_.MenuItemType.SELECTOR,label:Wi,selections:_.FONT_FAMILY_LIST.map(o=>({label:{name:Ui},value:o.value})),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),value$:be(e,r,({worksheet:o})=>new O.Observable(s=>{var u;const l=i.onCommandExecuted(h=>{var p;const g=h.id;if(g!==m.SetRangeValuesMutation.id&&g!==m.SetSelectionsOperation.id&&g!==m.SetWorksheetActiveOperation.id)return;const S=(p=t.getCurrentLastSelection())==null?void 0:p.primary;let f;if(S!=null){const v=o.getRange(S.startRow,S.startColumn);f=v==null?void 0:v.getFontFamily()}s.next(f!=null?f:r)}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d;if(c!=null){const h=o.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getFontFamily()}return s.next(d!=null?d:r),l.dispose})),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Rg(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService),o=a.DEFAULT_STYLES.fs,s=te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0);return{id:vr.id,type:_.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Li,props:{min:1,max:400,disabled$:s}},selections:_.FONT_SIZE_LIST,disabled$:s,value$:be(e,o,({worksheet:l})=>new O.Observable(c=>{var g;const d=i.onCommandExecuted(S=>{var p,v;const f=S.id;if(f===m.SetRangeValuesMutation.id||f===m.SetSelectionsOperation.id||f===m.SetWorksheetActiveOperation.id){const C=(p=t.getCurrentLastSelection())==null?void 0:p.primary;let b;if(C!=null){const R=l.getRange(C.startRow,C.startColumn);b=R==null?void 0:R.getFontSize()}c.next(b!=null?b:o)}if((f===Re.SetTextSelectionsOperation.id||f===$.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const C=yr(n);if(C==null)return;const b=(v=C.ts)==null?void 0:v.fs;c.next(b!=null?b:o)}}),u=(g=t.getCurrentLastSelection())==null?void 0:g.primary;let h;if(u!=null){const S=l.getRange(u.startRow,u.startColumn);h=S==null?void 0:S.getFontSize()}return c.next(h!=null?h:o),d.dispose})),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Eg(n){return{id:xs.id,type:_.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function wg(n){const i=n.get(a.ICommandService),e=n.get(a.ThemeService);return{id:Tn.id,icon:"FontColor",tooltip:"toolbar.textColor.main",type:_.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:wr,hoverable:!1,selectable:!1}}],value$:new O.Observable(t=>{const r=e.getCurrentTheme().textColor,o=i.onCommandExecuted(s=>{if(s.id===Tn.id){const l=s.params.value;t.next(l!=null?l:r)}});return t.next(r),o.dispose}),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0)}}function Tg(n){return{id:m.ResetBackgroundColorCommand.id,type:_.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function yg(n){const i=n.get(a.ICommandService),e=n.get(a.ThemeService);return{id:m.SetBackgroundColorCommand.id,tooltip:"toolbar.fillColor.main",type:_.MenuItemType.BUTTON_SELECTOR,icon:"PaintBucket",selections:[{label:{name:wr,hoverable:!1,selectable:!1}}],value$:new O.Observable(t=>{const r=e.getCurrentTheme().primaryColor,o=i.onCommandExecuted(s=>{if(s.id===m.SetBackgroundColorCommand.id){const l=s.params.value;t.next(l!=null?l:r)}});return t.next(r),o.dispose}),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const pa=[{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 Mg(n){const i=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=a.HorizontalAlign.LEFT;return{id:m.SetHorizontalTextAlignCommand.id,icon:pa[0].icon,tooltip:"toolbar.horizontalAlignMode.main",type:_.MenuItemType.SELECTOR,selections:pa,value$:be(i,t,({worksheet:r})=>new O.Observable(o=>{var d;const s=n.get(a.ICommandService).onCommandExecuted(u=>{var f;const h=u.id;if(h!==m.SetHorizontalTextAlignCommand.id&&h!==m.SetSelectionsOperation.id&&h!==m.SetWorksheetActiveOperation.id)return;const g=(f=e.getCurrentLastSelection())==null?void 0:f.primary;let S;if(g!=null){const p=r.getRange(g.startRow,g.startColumn);S=p==null?void 0:p.getHorizontalAlignment()}o.next(S!=null?S:t)}),l=(d=e.getCurrentLastSelection())==null?void 0:d.primary;let c;if(l!=null){const u=r.getRange(l.startRow,l.startColumn);c=u==null?void 0:u.getHorizontalAlignment()}return o.next(c!=null?c:t),s.dispose})),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const va=[{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 Pg(n){const i=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=a.VerticalAlign.BOTTOM;return{id:m.SetVerticalTextAlignCommand.id,icon:va[2].icon,tooltip:"toolbar.verticalAlignMode.main",type:_.MenuItemType.SELECTOR,selections:va,value$:be(i,t,({worksheet:r})=>new O.Observable(o=>{var d;const s=n.get(a.ICommandService).onCommandExecuted(u=>{var f;const h=u.id;if(h!==m.SetVerticalTextAlignCommand.id&&h!==m.SetSelectionsOperation.id&&h!==m.SetWorksheetActiveOperation.id)return;const g=(f=e.getCurrentLastSelection())==null?void 0:f.primary;let S;if(g!=null){const p=r.getRange(g.startRow,g.startColumn);S=p==null?void 0:p.getVerticalAlignment()}o.next(S!=null?S:t)}),l=(d=e.getCurrentLastSelection())==null?void 0:d.primary;let c;if(l!=null){const u=r.getRange(l.startRow,l.startColumn);c=u==null?void 0:u.getVerticalAlignment()}return o.next(c!=null?c:t),s.dispose})),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const Ca=[{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 Og(n){const i=n.get(m.SheetsSelectionsService),e=n.get(a.IUniverInstanceService),t=a.WrapStrategy.OVERFLOW;return{id:m.SetTextWrapCommand.id,tooltip:"toolbar.textWrapMode.main",icon:Ca[0].icon,type:_.MenuItemType.SELECTOR,selections:Ca,value$:be(e,t,({worksheet:r})=>new O.Observable(o=>{var d;const s=n.get(a.ICommandService).onCommandExecuted(u=>{var f;const h=u.id;if(h!==m.SetTextWrapCommand.id&&h!==m.SetSelectionsOperation.id&&h!==m.SetWorksheetActiveOperation.id)return;const g=(f=i.getCurrentLastSelection())==null?void 0:f.primary;let S;if(g!=null){const p=r.getRange(g.startRow,g.startColumn);S=p==null?void 0:p.getWrapStrategy()}o.next(S!=null?S:t)}),l=(d=i.getCurrentLastSelection())==null?void 0:d.primary;let c;if(l!=null){const u=r.getRange(l.startRow,l.startColumn);c=u==null?void 0:u.getWrapStrategy()}return o.next(c!=null?c:t),s.dispose})),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const _a=[{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 xg(n){const i=n.get(m.SheetsSelectionsService),e=n.get(a.IUniverInstanceService),t=0;return{id:m.SetTextRotationCommand.id,tooltip:"toolbar.textRotateMode.main",icon:_a[0].icon,type:_.MenuItemType.SELECTOR,selections:_a,value$:be(e,t,({worksheet:r})=>new O.Observable(o=>{var d,u;const s=n.get(a.ICommandService).onCommandExecuted(h=>{var p,v;const g=h.id;if(g!==m.SetTextRotationCommand.id&&g!==m.SetSelectionsOperation.id&&g!==m.SetWorksheetActiveOperation.id)return;const S=(p=i.getCurrentLastSelection())==null?void 0:p.primary;let f;if(S!=null){const C=r.getRange(S.startRow,S.startColumn);f=C==null?void 0:C.getTextRotation()}(f==null?void 0:f.v)===a.BooleanNumber.TRUE?o.next("v"):o.next((v=f&&f.a)!=null?v:t)}),l=(d=i.getCurrentLastSelection())==null?void 0:d.primary;let c;if(l!=null){const h=r.getRange(l.startRow,l.startColumn);c=h==null?void 0:h.getTextRotation()}return(c==null?void 0:c.v)===a.BooleanNumber.TRUE?o.next("v"):o.next((u=c&&c.a)!=null?u:t),s.dispose})),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Tr(n){return new O.Observable(e=>e.next(!n.get(_.IClipboardInterfaceService).supportClipboard))}function pn(n){return{id:Xe.name,commandId:Xe.id,type:_.MenuItemType.BUTTON,title:"rightClick.copy",icon:"Copy",disabled$:te(n,{workbookTypes:[m.WorkbookCopyPermission],worksheetTypes:[m.WorksheetCopyPermission],rangeTypes:[m.RangeProtectionPermissionViewPoint]}),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function qi(n){return{id:Ye.name,commandId:Ye.id,type:_.MenuItemType.BUTTON,title:"rightClick.paste",icon:"PasteSpecial",disabled$:Tr(n).pipe(O.combineLatestWith(te(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission,m.WorksheetSetCellValuePermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([i,e])=>i||e)),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Jn="sheet.menu.paste-special";function Qi(n){return{id:Jn,type:_.MenuItemType.SUBITEMS,icon:"PasteSpecial",title:"rightClick.pasteSpecial",hidden$:tn(n,_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET))}}function Ji(n){return{id:gn.id,type:_.MenuItemType.BUTTON,title:"rightClick.pasteValue",disabled$:Tr(n).pipe(O.combineLatestWith(te(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellValuePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([i,e])=>i||e)),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function $i(n){return{id:Sn.id,type:_.MenuItemType.BUTTON,title:"rightClick.pasteFormat",disabled$:Tr(n).pipe(O.combineLatestWith(te(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellStylePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([i,e])=>i||e)),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function eo(n){return{id:Vt.id,type:_.MenuItemType.BUTTON,title:"rightClick.pasteColWidth",disabled$:Tr(n).pipe(O.combineLatestWith(te(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetColumnStylePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([i,e])=>i||e))}}function to(n){return{id:fn.id,type:_.MenuItemType.BUTTON,title:"rightClick.pasteBesidesBorder",disabled$:Tr(n).pipe(O.combineLatestWith(te(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission,m.WorksheetSetCellValuePermission,m.WorksheetSetRowStylePermission,m.WorksheetSetColumnStylePermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([i,e])=>i||e)),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Ag(n){return{id:m.SetWorksheetRowIsAutoHeightCommand.id,type:_.MenuItemType.BUTTON,icon:"AutoHeight",title:"rightClick.fitContent",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function kg(n){return{id:Er.id,type:_.MenuItemType.BUTTON,icon:"AutoWidth",title:"rightClick.fitContent",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Ll="sheet.menu.sheet-frozen";function Ng(n){return{id:Ll,type:_.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Yo="sheet.header-menu.sheet-frozen";function Ia(n){return{id:Yo,type:_.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function no(n){return{id:ht.id,type:_.MenuItemType.BUTTON,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Dg(n){return{id:br.id,type:_.MenuItemType.BUTTON,title:"rightClick.freezeRow",icon:"FreezeRowSingle",hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Hg(n){return{id:Rr.id,type:_.MenuItemType.BUTTON,title:"rightClick.freezeCol",icon:"FreezeColumnSingle",hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function ro(n){return{id:m.CancelFrozenCommand.id,type:_.MenuItemType.BUTTON,title:"rightClick.cancelFreeze",icon:"CancelFreezeSingle",hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Vg(n){return{id:fr.id,type:_.MenuItemType.BUTTON,icon:"Hide",title:"rightClick.hideSelectedRow",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Wg(n){return{id:pr.id,type:_.MenuItemType.BUTTON,icon:"Hide",title:"rightClick.hideSelectedColumn",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Ug(n){const i=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=[m.SetSelectionsOperation,m.SetRowHiddenMutation,m.SetRowVisibleMutation].map(o=>o.id);return{id:m.SetSelectedRowsVisibleCommand.id,type:_.MenuItemType.BUTTON,title:"rightClick.showHideRow",hidden$:be(i,!0,({worksheet:o})=>new O.Observable(s=>{function l(){var u;const d=(u=e.getCurrentSelections())==null?void 0:u.map(h=>h.range).filter(h=>h.rangeType===a.RANGE_TYPE.ROW);return!!(d!=null&&d.some(h=>{for(let g=h.startRow;g<=h.endRow;g++)if(!o.getRowRawVisible(g))return!0;return!1}))}const c=t.onCommandExecuted(d=>{r.findIndex(u=>u===d.id)!==-1&&s.next(!l())});return s.next(!l()),()=>c.dispose()})),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetRowStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Lg(n){const i=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=[m.SetSelectionsOperation,m.SetColHiddenMutation,m.SetColVisibleMutation].map(o=>o.id);return{id:m.SetSelectedColsVisibleCommand.id,type:_.MenuItemType.BUTTON,title:"rightClick.showHideColumn",hidden$:be(i,!0,({worksheet:o})=>new O.Observable(s=>{function l(){var u;const d=(u=e.getCurrentSelections())==null?void 0:u.map(h=>h.range).filter(h=>h.rangeType===a.RANGE_TYPE.COLUMN);return!d||d.length===0?!1:!!d.some(h=>{for(let g=h.startColumn;g<=h.endColumn;g++)if(!o.getColVisible(g))return!0;return!1})}const c=t.onCommandExecuted(d=>{r.findIndex(u=>u===d.id)!==-1&&s.next(!l())});return s.next(!l()),()=>c.dispose()})),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetColumnStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Bg(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=0;return{id:m.SetRowHeightCommand.id,type:_.MenuItemType.BUTTON,icon:"AdjustHeight",label:{name:tt,props:{prefix:"rightClick.rowHeight",suffix:"px",min:2,max:1e3}},value$:be(e,r,({worksheet:o})=>new O.Observable(s=>{function l(){var h;const d=(h=t.getCurrentLastSelection())==null?void 0:h.primary,u=d?o.getRowHeight(d.startRow):r;s.next(u)}const c=i.onCommandExecuted(d=>{const u=d.id;if(u===m.SetRangeValuesMutation.id||u===m.SetSelectionsOperation.id||u===m.SetWorksheetRowIsAutoHeightMutation.id)return l()});return l(),c.dispose})),hidden$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetRowStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Fg(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=0;return{id:m.SetColWidthCommand.id,type:_.MenuItemType.BUTTON,icon:"AdjustWidth",label:{name:tt,props:{prefix:"rightClick.columnWidth",suffix:"px",min:2,max:1e3}},value$:be(e,r,({worksheet:o})=>new O.Observable(s=>{function l(){var h;const d=(h=t.getCurrentLastSelection())==null?void 0:h.primary;let u=r;d!=null&&(u=o.getColumnWidth(d.startColumn)),s.next(u)}const c=i.onCommandExecuted(d=>{const u=d.id;if(u===m.SetRangeValuesMutation.id||u===m.SetSelectionsOperation.id||u===m.SetWorksheetColWidthMutation.id)return l()});return l(),c.dispose})),hidden$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function yr(n){var c;const i=n.get(a.IUniverInstanceService),e=n.get(Re.DocSelectionManagerService),t=i.getUniverDocInstance(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),r=e.getActiveTextRange();if(t==null||r==null)return null;const o=(c=t.getBody())==null?void 0:c.textRuns;if(o==null)return;const{startOffset:s}=r;return o.find(({st:d,ed:u})=>s>=d&&s<=u)}var jg=Object.getOwnPropertyDescriptor,zg=(n,i,e,t)=>{for(var r=t>1?void 0:t?jg(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=s(r)||r);return r},xt=(n,i)=>(e,t)=>i(e,t,n);const Xg="__SpreadsheetFreezeRowMainName__",Yg="__SpreadsheetFreezeRowHeaderName__",Gg="__SpreadsheetFreezeColumnMainName__",Zg="__SpreadsheetFreezeColumnHeaderName__",io=2,Kg=.01,Fn=a.createInterceptorKey("freezePermissionCheck");exports.HeaderFreezeRenderController=class extends a.Disposable{constructor(e,t,r,o,s,l,c,d){super();E(this,"_rowFreezeHeaderRect");E(this,"_rowFreezeMainRect");E(this,"_columnFreezeHeaderRect");E(this,"_columnFreezeMainRect");E(this,"_freezeDownSubs");E(this,"_freezePointerEnterSubs");E(this,"_freezePointerLeaveSubs");E(this,"_scenePointerMoveSub");E(this,"_scenePointerUpSub");E(this,"_changeToRow",-1);E(this,"_changeToColumn",-1);E(this,"_changeToOffsetX",0);E(this,"_changeToOffsetY",0);E(this,"_activeViewport",null);E(this,"_freezeNormalHeaderColor","");E(this,"_freezeNormalMainColor","");E(this,"_freezeActiveColor","");E(this,"_freezeHoverColor","");E(this,"_lastFreeze");E(this,"interceptor",new a.InterceptorManager({FREEZE_PERMISSION_CHECK:Fn}));this._context=e,this._sheetSkeletonManagerService=t,this._commandService=r,this._selectionManagerService=o,this._scrollManagerService=s,this._themeService=l,this._sheetInterceptorService=c,this._injector=d,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._themeChangeListener(),this._interceptorCommands(),this._bindViewportScroll(),this._zoomRefresh()}_createFreeze(e=0,t){var x;const r=t!=null?t:this._getFreeze();if(r==null)return null;const o=(x=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:x.skeleton,{startRow:s,startColumn:l}=r,c=this._getPositionByIndex(s,l);if(c==null||o==null)return null;const d=this._getSheetObject(),u=d.engine,h=(u==null?void 0:u.width)||0,g=(u==null?void 0:u.height)||0,S=d.scene,{startX:f,startY:p}=c,{rowTotalHeight:v,columnTotalWidth:C,rowHeaderWidthAndMarginLeft:b,columnHeaderHeightAndMarginTop:R}=o,w=h>C+b?h:C+R,M=g>v+R?g:v+R;this._changeToRow=s,this._changeToColumn=l,this._changeToOffsetX=f,this._changeToOffsetY=p;const y=Math.max(S.scaleX,S.scaleY);let P=io/(y<1?1:y);if(e===0){(s===-1||s===0)&&(P=P*2);const A=P;this._rowFreezeHeaderRect=new T.Rect(Yg,{fill:this._freezeNormalHeaderColor,width:b,height:P,left:0,top:p-A,zIndex:3});let k=this._freezeNormalHeaderColor;(s===-1||s===0)&&(k=this._freezeNormalMainColor),this._rowFreezeMainRect=new T.Rect(Xg,{fill:k,width:w*2/y,height:P,left:b,top:p-A,zIndex:3}),S.addObjects([this._rowFreezeHeaderRect,this._rowFreezeMainRect],bt)}else{(l===-1||l===0)&&(P=P*2);const A=P;this._columnFreezeHeaderRect=new T.Rect(Zg,{fill:this._freezeNormalHeaderColor,width:P,height:R,left:f-A,top:0,zIndex:3});let k=this._freezeNormalHeaderColor;(l===-1||l===0)&&(k=this._freezeNormalMainColor),this._columnFreezeMainRect=new T.Rect(Gg,{fill:k,width:P,height:M*2/y,left:f-A,top:R,zIndex:3}),S.addObjects([this._columnFreezeHeaderRect,this._columnFreezeMainRect],bt)}this._eventBinding(e)}_eventBinding(e=0){let t=this._rowFreezeHeaderRect,r=this._rowFreezeMainRect;e===1&&(t=this._columnFreezeHeaderRect,r=this._columnFreezeMainRect);const o=this._getSheetObject();if(o==null)return;const{scene:s}=o;if(this._freezePointerEnterSubs=new O.Subscription,this._freezePointerLeaveSubs=new O.Subscription,this._freezeDownSubs=new O.Subscription,r){const d=r.onPointerEnter$.subscribeEvent(()=>{if(!this.interceptor.fetchThroughInterceptors(Fn)(!0,null))return!1;t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),s.setCursor(T.CURSOR_TYPE.GRAB)});this._freezePointerEnterSubs.add(d);const u=r.onPointerLeave$.subscribeEvent(()=>{t==null||t.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),s.resetCursor()});this._freezePointerLeaveSubs.add(u)}if(t){const d=t.onPointerEnter$.subscribeEvent(()=>{if(!this.interceptor.fetchThroughInterceptors(Fn)(!0,null))return!1;t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),s.setCursor(T.CURSOR_TYPE.GRAB)});this._freezePointerEnterSubs.add(d);const u=t.onPointerLeave$.subscribeEvent(()=>{t==null||t.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),s.resetCursor()});this._freezePointerLeaveSubs.add(u)}const l=t==null?void 0:t.onPointerDown$.subscribeEvent(d=>{this._freezeDown(d,t,r,e)});l&&this._freezeDownSubs.add(l);const c=r==null?void 0:r.onPointerDown$.subscribeEvent(d=>{this._freezeDown(d,t,r,e)});c&&this._freezeDownSubs.add(c)}_getCurrentLastVisible(){var C,b,R,w,M,y,P;const e=this._getSheetObject();if(e==null)return;const t=(C=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:C.skeleton;if(t==null)return;const r=e.scene,o=Math.max(r.scaleX,r.scaleY),s=this._scrollManagerService.getCurrentScrollState(),l=(e.engine.height-t.columnHeaderHeight)/o,c=(e.engine.width-t.rowHeaderWidth)/o,d=(b=s==null?void 0:s.sheetViewStartRow)!=null?b:0,u=d===0?-((R=s==null?void 0:s.offsetY)!=null?R:0):t.rowHeightAccumulation[d-1]-((w=s==null?void 0:s.offsetY)!=null?w:0);let h=0,g=!1;for(let x=d,A=t.rowHeightAccumulation.length;x<A;x++)if(t.rowHeightAccumulation[x]-u>l){h=x,g=!0;break}g||(h=t.rowHeightAccumulation.length-1);const S=(M=s==null?void 0:s.sheetViewStartColumn)!=null?M:0,f=S===0?-((y=s==null?void 0:s.offsetX)!=null?y:0):t.columnWidthAccumulation[S-1]-((P=s==null?void 0:s.offsetX)!=null?P:0);let p=0,v=!1;for(let x=S,A=t.columnWidthAccumulation.length;x<A;x++)if(t.columnWidthAccumulation[x]-f>c){p=x,v=!0;break}return v||(p=t.columnWidthAccumulation.length-1),{lastRow:h,lastColumn:p}}_getActiveViewport(e){var r;const t=(r=this._getSheetObject())==null?void 0:r.scene.getViewports();return t&&t.find(o=>o.isHit(new T.Vector2(e.offsetX,e.offsetY)))||null}_freezeDown(e,t,r,o=0){var f;const s=(f=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:f.skeleton;if(s==null)return;const l=this._getSheetObject();if(l==null)return;if(!this.interceptor.fetchThroughInterceptors(Fn)(!0,null))return!1;const{scene:d}=l;d.setCursor(T.CURSOR_TYPE.GRABBING),d.disableObjectsEvent();const u=this._getCurrentLastVisible(),h=u===void 0?Number.POSITIVE_INFINITY:s.rowHeightAccumulation[u.lastRow],g=u===void 0?Number.POSITIVE_INFINITY:s.columnWidthAccumulation[u.lastColumn-1]+s.rowHeaderWidth;this._activeViewport=null;const S=this._getFreeze();S&&(this._changeToColumn=S.startColumn,this._changeToRow=S.startRow),this._scenePointerMoveSub=d.onPointerMove$.subscribeEvent(p=>{var P,x,A,k;const v=this._getActiveViewport(p),{startX:C,startY:b,row:R,column:w}=qe(p.offsetX,p.offsetY,d,s,v||void 0,!0);if(!this.interceptor.fetchThroughInterceptors(Fn)(!0,null))return!1;d.setCursor(T.CURSOR_TYPE.GRABBING);const y=io/Math.max(d.scaleX,d.scaleY);o===0?((P=t.transformByState({top:Math.min(b,h)-y/2}))==null||P.setProps({fill:this._freezeActiveColor}),(x=r.transformByState({top:Math.min(b,h)-y/2}))==null||x.setProps({fill:this._freezeNormalHeaderColor}),this._changeToRow=u===void 0?R:Math.min(R,u.lastRow),this._changeToOffsetY=Math.min(b,h),this._activeViewport=v):((A=t.transformByState({left:Math.min(C,g)-y/2}))==null||A.setProps({fill:this._freezeActiveColor}),(k=r.transformByState({left:Math.min(C,g)-y/2}))==null||k.setProps({fill:this._freezeNormalHeaderColor}),this._changeToColumn=u===void 0?w:Math.min(w,u.lastColumn),this._changeToOffsetX=C,this._activeViewport=v)}),this._scenePointerUpSub=d.onPointerUp$.subscribeEvent(()=>{var N,H;d.resetCursor(),d.enableObjectsEvent(),this._clearObserverEvent();const{rowHeaderWidthAndMarginLeft:p,columnHeaderHeightAndMarginTop:v}=s;o===0&&(this._changeToRow===0||this._changeToRow===-1)||o===1&&(this._changeToColumn===0||this._changeToColumn===-1)?(t.setProps({fill:this._freezeNormalHeaderColor}),r.setProps({fill:this._freezeNormalMainColor})):(t==null||t.setProps({fill:this._freezeNormalHeaderColor}),r==null||r.setProps({fill:this._freezeNormalHeaderColor}));const C=io/Math.max(d.scaleX,d.scaleY);o===0?(this._changeToRow===0||this._changeToRow===-1)&&(t.transformByState({top:v-C}),r.transformByState({top:v-C})):(this._changeToColumn===0||this._changeToColumn===-1)&&(t.transformByState({left:p-C}),r.transformByState({left:p-C}));const b=this._scrollManagerService.getCurrentScrollState()||{sheetViewStartRow:0,sheetViewStartColumn:0},{sheetViewStartRow:R,sheetViewStartColumn:w}=b;if(w==null||R==null)return;const M=this._context.unit,y=M.getActiveSheet();if(!y)return;const P=(N=y.getConfig())==null?void 0:N.freeze;let x=(P==null?void 0:P.xSplit)||0,A=(P==null?void 0:P.ySplit)||0;const k=(H=this._activeViewport)==null?void 0:H.viewportKey;o===0&&(!k||k===T.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP||k===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP||k===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||k===T.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP?A=this._changeToRow-(P.startRow-P.ySplit):A=this._changeToRow-R,A=A<0?0:A),o===1&&(!k||k===T.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP||k===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP||k===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||k===T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT?x=this._changeToColumn-(P.startColumn-P.xSplit):x=this._changeToColumn-w,x=x<0?0:x),this._commandService.executeCommand(m.SetFrozenCommand.id,{startRow:A===0?-1:this._changeToRow,startColumn:x===0?-1:this._changeToColumn,ySplit:A,xSplit:x,unitId:M.getUnitId(),subUnitId:y.getSheetId()})})}_getViewports(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e,r=t.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT),o=t.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT),s=t.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP),l=t.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM),c=t.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP),d=t.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN),u=t.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP),h=t.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT),g=t.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(!(r==null||o==null||s==null||l==null||c==null||d==null||u==null||h==null||g==null))return{viewMain:d,viewMainLeftTop:u,viewMainLeft:h,viewMainTop:g,viewColumnLeft:r,viewColumnRight:o,viewRowTop:s,viewRowBottom:l,viewLeftTop:c}}_bindViewportScroll(){const e=this._getViewports();if(!e)return;const{viewRowBottom:t,viewColumnRight:r,viewMainLeft:o,viewMainTop:s}=e;this.disposeWithMe(this._scrollManagerService.validViewportScrollInfo$.subscribe(l=>{if(!l)return;const{scrollX:c,scrollY:d,viewportScrollX:u,viewportScrollY:h}=l;t.isActive&&t.updateScrollVal({scrollY:d,viewportScrollY:h}),r.isActive&&r.updateScrollVal({scrollX:c,viewportScrollX:u}),o.isActive&&o.updateScrollVal({scrollY:d,viewportScrollY:h}),s.isActive&&s.updateScrollVal({scrollX:c,viewportScrollX:u})}))}_updateViewport(e=-1,t=-1,r=0,o=0,s=3){var x;const l=(x=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:x.skeleton;if(l==null)return;const{rowHeaderWidthAndMarginLeft:c,columnHeaderHeightAndMarginTop:d}=l,u=this._getViewports();if(!u)return;const{viewMain:h,viewMainLeftTop:g,viewMainLeft:S,viewMainTop:f,viewColumnLeft:p,viewColumnRight:v,viewRowTop:C,viewRowBottom:b,viewLeftTop:R}=u;v.resizeWhenFreezeChange({left:c,top:0,height:d,right:0}),b.resizeWhenFreezeChange({left:0,top:d,bottom:0,width:c}),R.resizeWhenFreezeChange({left:0,top:0,width:c,height:d});let w=!0,M=!0;g.enable(),(e===-1||e===0)&&(w=!1),(t===-1||t===0)&&(M=!1);const y=l.getNoMergeCellWithCoordByIndex(e-r,t-o,!1),P=l.getNoMergeCellWithCoordByIndex(e,t,!1);if(g.disable(),f.disable(),S.disable(),C.disable(),p.disable(),g.resetPadding(),f.resetPadding(),S.resetPadding(),C.resetPadding(),p.resetPadding(),w===!1&&M===!1)h.resizeWhenFreezeChange({left:c,top:d,bottom:0,right:0}),h.resetPadding(),S.resizeWhenFreezeChange({left:c,top:d,bottom:0,width:0}),f.resizeWhenFreezeChange({left:c,top:d,height:0,right:0}),g.resizeWhenFreezeChange({left:c,top:d,width:0,height:0}),C.resizeWhenFreezeChange({left:0,top:d,width:c,height:0}),p.resizeWhenFreezeChange({left:0,top:0,height:d,width:0});else if(w===!0&&M===!1){const A=P.startY-y.startY;h.resizeWhenFreezeChange({left:c,top:d+A,bottom:0,right:0}),h.setPadding({startY:y.startY,endY:P.startY,startX:0,endX:0}),s&2&&this._commandService.executeCommand(ze.id,{sheetViewStartRow:0,offsetY:0}),f.resizeWhenFreezeChange({left:c,top:d,height:A,right:0}),f.updateScrollVal({viewportScrollY:y.startY,rawScrollX:h.scrollX,viewportScrollX:h.viewportScrollX}),C.resizeWhenFreezeChange({left:0,top:d,width:c,height:A}),C.updateScrollVal({viewportScrollY:y.startY}),b.resizeWhenFreezeChange({left:0,top:d+A,bottom:0,width:c}),f.enable(),C.enable()}else if(w===!1&&M===!0){const A=P.startX-y.startX;h.resizeWhenFreezeChange({left:c+A,top:d,bottom:0,right:0}),h.setPadding({startX:y.startX,endX:P.startX,startY:0,endY:0}),s&1&&this._commandService.executeCommand(ze.id,{sheetViewStartColumn:0,offsetX:0}),S.resizeWhenFreezeChange({left:c,top:d,width:A,bottom:0,right:0}),S.updateScrollVal({viewportScrollX:y.startX,rawScrollY:h.scrollY,viewportScrollY:h.viewportScrollY}),p.resizeWhenFreezeChange({left:c,top:0,width:A,height:d}),p.updateScrollVal({viewportScrollX:y.startX}),v.resizeWhenFreezeChange({left:c+A,top:0,height:d,right:0}),S.enable(),p.enable()}else{const A=P.startX-y.startX,k=P.startY-y.startY;h.resizeWhenFreezeChange({left:c+A,top:d+k,bottom:0,right:0}),h.setPadding({startY:y.startY,endY:P.startY,startX:y.startX,endX:P.startX}),s&&this._commandService.executeCommand(ze.id,{...s&1?{sheetViewStartColumn:0,offsetX:0}:null,...s&2?{sheetViewStartRow:0,offsetY:0}:null}),S.resizeWhenFreezeChange({left:c,top:d+k,width:A,bottom:0}),S.updateScrollVal({viewportScrollX:y.startX,rawScrollY:h.scrollY,viewportScrollY:h.viewportScrollY}),f.resizeWhenFreezeChange({left:c+A,top:d,height:k,right:0}),f.updateScrollVal({viewportScrollY:y.startY,rawScrollX:h.scrollX,viewportScrollX:h.viewportScrollX}),g.resizeWhenFreezeChange({left:c,top:d,width:A,height:k}),g.updateScrollVal({viewportScrollX:y.startX,viewportScrollY:y.startY}),C.resizeWhenFreezeChange({left:0,top:d,width:c,height:k}),C.updateScrollVal({viewportScrollY:y.startY}),b.resizeWhenFreezeChange({left:0,top:d+k,bottom:0,width:c}),p.resizeWhenFreezeChange({left:c,top:0,width:A,height:d}),p.updateScrollVal({viewportScrollX:y.startX}),v.resizeWhenFreezeChange({left:c+A,top:0,height:d,right:0}),g.enable(),f.enable(),S.enable(),C.enable(),p.enable()}}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(e=>{[m.SetWorksheetActiveOperation.id,m.InsertRangeMoveDownCommand.id,m.InsertRangeMoveRightCommand.id].includes((e==null?void 0:e.commandId)||"")&&this._refreshCurrent()})))}_refreshCurrent(){const t=this._context.unit.getActiveSheet();if(!t)return;const r=t.getConfig().freeze,{startRow:o=-1,startColumn:s=-1,ySplit:l=0,xSplit:c=0}=r;this._refreshFreeze(o,s,l,c,0)}_themeChangeListener(){this._themeChange(this._themeService.getCurrentTheme()),this.disposeWithMe(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(Kg).toRgbString(),this._freezeActiveColor=e.primaryColor,this._freezeHoverColor=e.grey500}_interceptorCommands(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{const t={redos:[],undos:[]},r=this._getFreeze();if(!r)return t;const o=s=>{const l=this._context.unit,c=l.getUnitId(),d=l.getActiveSheet();if(!d)return t;const u=d.getSheetId();this._refreshFreeze(s.startRow,s.startColumn,s.ySplit,s.xSplit,0);const h={...s,unitId:c,subUnitId:u,resetScroll:!1},g=m.SetFrozenMutationFactory(this._injector,h);return{undos:[{id:m.SetFrozenMutation.id,params:g}],redos:[{id:m.SetFrozenMutation.id,params:h}]}};if(e.id===m.InsertRowCommand.id){const s=e.params,{range:l,direction:c}=s,d=l.endRow-l.startRow+1;if(l.startRow+1<r.startRow||l.startRow+1===r.startRow&&c===a.Direction.UP){const u={...r,startRow:Math.max(1,r.startRow+d),ySplit:Math.max(1,r.ySplit+d)};return o(u)}}if(e.id===m.InsertColCommand.id){const s=e.params,{range:l,direction:c}=s,d=l.endColumn-l.startColumn+1;if(l.startColumn+1<r.startColumn||l.startColumn+1===r.startColumn&&c===a.Direction.LEFT){const u={...r,startColumn:Math.max(1,r.startColumn+d),xSplit:Math.max(1,r.xSplit+d)};return o(u)}}if(e.id===m.MoveColsCommand.id){const s=this._selectionManagerService.getCurrentSelections(),{fromRange:{startColumn:l},toRange:{startColumn:c}}=e.params,d=s==null?void 0:s.filter(C=>C.range.rangeType===a.RANGE_TYPE.COLUMN&&C.range.startColumn<=l&&l<=C.range.endColumn);if(!(d!=null&&d.length))return t;const u=d[0].range,h={...u,startColumn:c,endColumn:c+u.endColumn-u.startColumn};if(!r||r.startColumn<=0||u.startColumn>=r.startColumn&&h.startColumn>=r.startColumn||u.startColumn===h.startColumn||u.endColumn<r.startColumn&&h.startColumn<r.startColumn)return t;const g=u.endColumn-u.startColumn+1,S=Math.max(Math.min(r.startColumn,u.endColumn+1)-u.startColumn,0);let f,p;h.startColumn>=r.startColumn?(f=Math.max(r.startColumn-S,1),p=Math.max(r.xSplit-S,1)):(f=r.startColumn+g-S,p=r.xSplit+g-S);const v={...r,startColumn:f,xSplit:p};return o(v)}if(e.id===m.MoveRowsCommand.id){const s=this._selectionManagerService.getCurrentSelections(),{fromRange:{startRow:l},toRange:{startRow:c}}=e.params,d=s==null?void 0:s.filter(C=>C.range.rangeType===a.RANGE_TYPE.ROW&&C.range.startRow<=l&&l<=C.range.endRow);if(!(d!=null&&d.length))return t;const u=d[0].range,h={...u,startRow:c,endRow:c+u.endRow-u.startRow};if(!r||r.startRow<=0||u.startRow>=r.startRow&&h.startRow>=r.startRow||u.startRow===h.startRow||u.endRow<r.startRow&&h.startRow<r.startRow)return t;const g=u.endRow-u.startRow+1,S=Math.max(Math.min(r.startRow,u.endRow+1)-u.startRow,0);let f,p;h.startRow>=r.startRow?(f=Math.max(r.startRow-S,1),p=Math.max(r.ySplit-S,1)):(f=r.startRow+g-S,p=r.ySplit+g-S);const v={...r,startRow:f,ySplit:p};return o(v)}if(e.id===m.RemoveColCommand.id||e.id===m.RemoveRowCommand.id){const s=e.params,l=s.range;if(l.rangeType===a.RANGE_TYPE.COLUMN&&l.startColumn<r.startColumn){const c=Math.min(r.startColumn,l.endColumn+1)-l.startColumn,d={...r,startColumn:Math.max(1,r.startColumn-c),xSplit:Math.max(1,r.xSplit-c)};return o(d)}if(s.range.rangeType===a.RANGE_TYPE.ROW&&l.startRow<r.startRow){const c=Math.min(r.startRow,l.endRow+1)-l.startRow,d={...r,startRow:Math.max(1,r.startRow-c),ySplit:Math.max(1,r.ySplit-c)};return o(d)}}return t}}))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{switch(e.id){case m.SetFrozenMutation.id:case Le.id:{const t=this._lastFreeze,r=this._context.unit,o=r.getActiveSheet(),s=e.params,{unitId:l,subUnitId:c}=s;if(!(l===r.getUnitId()&&c===(o==null?void 0:o.getSheetId())))return;const d=o.getConfig().freeze;if(this._lastFreeze=d,d==null)return;let u=0;const{startRow:h=-1,startColumn:g=-1,ySplit:S=0,xSplit:f=0}=d;(!t||t.startRow!==h||t.ySplit!==S)&&(u|=2),(!t||t.startColumn!==g||t.xSplit!==f)&&(u|=1),s.resetScroll===!1&&(u=0),this._refreshFreeze(h,g,S,f,u)}break;case m.SetWorksheetRowHeightMutation.id:{const t=this._getFreeze(),r=t&&e.params.ranges.some(o=>o.startRow<t.startRow);e.params&&r&&this._refreshCurrent()}break;case m.SetWorksheetColWidthMutation.id:{const t=this._getFreeze();e.params&&t&&e.params.ranges.some(r=>r.startColumn<t.startColumn)&&this._refreshCurrent()}break;case m.SetWorksheetRowAutoHeightMutation.id:{const t=e.params,r=this._getFreeze();if(r&&r.startRow>-1&&t.rowsAutoHeightInfo.some(o=>o.row<r.startRow)){const o=this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._refreshCurrent(),setTimeout(()=>{o.unsubscribe()})})}}break;case m.SetColHiddenMutation.id:case m.SetColVisibleMutation.id:{const t=e.params,r=this._getFreeze(),o=t.ranges;r&&r.startColumn>-1&&o.some(s=>s.startColumn<r.startColumn)&&this._refreshCurrent()}break;case m.SetRowHiddenMutation.id:case m.SetRowVisibleMutation.id:{const t=e.params,r=this._getFreeze(),o=t.ranges;r&&r.startRow>-1&&o.some(s=>s.startRow<r.startRow)&&this._refreshCurrent()}break;case Oi.id:case xi.id:this._refreshCurrent()}}))}_zoomRefresh(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;this.disposeWithMe(t.onTransformChange$.subscribeEvent(r=>{[T.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale,T.TRANSFORM_CHANGE_OBSERVABLE_TYPE.all].includes(r.type)&&this._refreshCurrent()}))}_clearObserverEvent(){var t,r;this._getSheetObject()!=null&&((t=this._scenePointerMoveSub)==null||t.unsubscribe(),(r=this._scenePointerUpSub)==null||r.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null)}_clearFreeze(){var t,r,o,s,l,c;(t=this._rowFreezeHeaderRect)==null||t.dispose(),(r=this._rowFreezeMainRect)==null||r.dispose(),(o=this._columnFreezeHeaderRect)==null||o.dispose(),(s=this._columnFreezeMainRect)==null||s.dispose(),this._getSheetObject()!=null&&([this._freezeDownSubs,this._freezePointerEnterSubs,this._freezePointerLeaveSubs].forEach(d=>{d==null||d.unsubscribe()}),this._freezeDownSubs=null,this._freezePointerEnterSubs=null,this._freezePointerLeaveSubs=null,(l=this._scenePointerMoveSub)==null||l.unsubscribe(),(c=this._scenePointerUpSub)==null||c.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null)}_getPositionByIndex(e,t){var d;if(this._getSheetObject()==null)return;const o=(d=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:d.skeleton,s=o==null?void 0:o.getNoMergeCellWithCoordByIndex(e,t);if(o==null)return;if(s!=null&&(!isNaN(s.endX)||!isNaN(s.endY)))return s;const{rowHeaderWidthAndMarginLeft:l,columnHeaderHeightAndMarginTop:c}=o;return{startX:l,endX:l,startY:c,endY:c}}_getFreeze(){var t;const e=(t=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:t.skeleton.getWorksheetConfig();if(e!=null)return e.freeze}_getSheetObject(){return Ge(this._context.unit,this._context)}_refreshFreeze(e,t,r,o,s){var c;const l={startRow:e,startColumn:t,ySplit:r,xSplit:o};this._clearFreeze(),this._createFreeze(0,l),this._createFreeze(1,l),this._updateViewport(e,t,r,o,s),(c=this._getSheetObject())==null||c.spreadsheet.makeForceDirty()}};exports.HeaderFreezeRenderController=zg([xt(1,a.Inject(exports.SheetSkeletonManagerService)),xt(2,a.ICommandService),xt(3,a.Inject(m.SheetsSelectionsService)),xt(4,a.Inject(exports.SheetScrollManagerService)),xt(5,a.Inject(a.ThemeService)),xt(6,a.Inject(m.SheetInterceptorService)),xt(7,a.Inject(a.Injector))],exports.HeaderFreezeRenderController);function qg(n){const i=n.get(m.SheetsSelectionsService),e=n.get(m.RangeProtectionRuleModel),t=n.get(a.IUniverInstanceService),r=n.get(m.MergeCellController),o=t.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET);return O.combineLatest([i.selectionMoveEnd$,o.pipe(O.map(s=>{var l;return(l=s==null?void 0:s.getUnitId())!=null?l:""})),o.pipe(O.switchMap(s=>{var l;return(l=s==null?void 0:s.activeSheet$)!=null?l:O.of(null)}))]).pipe(O.map(([s,l,c])=>{if(!c||!s||s.length===0)return!1;const d=c.getSheetId(),u=s.map(S=>S.range);if(r.interceptor.fetchThroughInterceptors(m.MERGE_CELL_INTERCEPTOR_CHECK)(!1,u))return!0;const g=e.getSubunitRuleList(l,d).map(S=>S.ranges).flat();if(s.length<2){const S=s[0].range;return g.some(p=>a.Rectangle.intersects(p,S)&&!a.Rectangle.contains(p,S))}for(let S=0;S<s.length;S++)for(let f=S+1;f<s.length;f++)if(a.Rectangle.intersects(s[S].range,s[f].range))return!0;return!1}))}function Bl(n,i){return!!ir(n,i,a.RANGE_TYPE.ROW)}function Fl(n,i){return!!ir(n,i,a.RANGE_TYPE.COLUMN)}function ir(n,i,e){return n.find(r=>{const o=r.range,{startRow:s,endRow:l,startColumn:c,endColumn:d,rangeType:u}=o;return u===a.RANGE_TYPE.ALL||u===a.RANGE_TYPE.NORMAL?!1:u===e&&(e===a.RANGE_TYPE.COLUMN&&c<=i&&i<=d||e===a.RANGE_TYPE.ROW&&s<=i&&i<=l)})}var Qg=Object.getOwnPropertyDescriptor,Jg=(n,i,e,t)=>{for(var r=t>1?void 0:t?Qg(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=s(r)||r);return r},oo=(n,i)=>(e,t)=>i(e,t,n);const $g="__SpreadsheetHeaderMoveControllerBackground__",eS="__SpreadsheetHeaderMoveControllerShapeLine__",tS="rgba(0, 0, 0, 0.1)",nS="rgb(119, 119, 119)",rS=4,so=a.createInterceptorKey("headerMovePermissionCheck");exports.HeaderMoveRenderController=class extends a.Disposable{constructor(e,t,r,o){super();E(this,"_startOffsetX",Number.NEGATIVE_INFINITY);E(this,"_startOffsetY",Number.NEGATIVE_INFINITY);E(this,"_moveHelperBackgroundShape");E(this,"_moveHelperLineShape");E(this,"_headerPointerDownSubs");E(this,"_headerPointerMoveSubs");E(this,"_headerPointerLeaveSubs");E(this,"_dragHeaderMoveSub");E(this,"_scenePointerUpSub");E(this,"_scrollTimer");E(this,"_changeFromColumn",-1);E(this,"_changeFromRow",-1);E(this,"_changeToColumn",-1);E(this,"_changeToRow",-1);E(this,"interceptor",new a.InterceptorManager({HEADER_MOVE_PERMISSION_CHECK:so}));E(this,"_workbookSelections");this._context=e,this._sheetSkeletonManagerService=r,this._commandService=o,this._workbookSelections=t.getWorkbookSelections(this._context.unitId),this._init()}dispose(){var e,t,r,o,s,l,c,d;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(t=this._moveHelperLineShape)==null||t.dispose(),(r=this._headerPointerMoveSubs)==null||r.unsubscribe(),(o=this._headerPointerLeaveSubs)==null||o.unsubscribe(),(s=this._headerPointerDownSubs)==null||s.unsubscribe(),this._headerPointerMoveSubs=null,this._headerPointerLeaveSubs=null,this._headerPointerDownSubs=null,(l=this._dragHeaderMoveSub)==null||l.unsubscribe(),(c=this._scenePointerUpSub)==null||c.unsubscribe(),this._dragHeaderMoveSub=null,this._scenePointerUpSub=null,(d=this._scrollTimer)==null||d.dispose()}_init(){this._initialRowOrColumn(a.RANGE_TYPE.ROW),this._initialRowOrColumn(a.RANGE_TYPE.COLUMN)}_initialRowOrColumn(e=a.RANGE_TYPE.ROW){const t=this._context.components.get(he.COLUMN),r=this._context.components.get(he.ROW),o=this._context.scene,s=e===a.RANGE_TYPE.ROW?r:t,l=u=>{var b,R;const h=(b=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:b.skeleton;if(h==null)return;const g=(R=this._workbookSelections.getCurrentLastSelection())==null?void 0:R.range;if(!g||!this.interceptor.fetchThroughInterceptors(so)(!1,g))return;const f=this._workbookSelections.getCurrentSelections(),{row:p,column:v}=qe(u.offsetX,u.offsetY,o,h);if(!ir(f,e===a.RANGE_TYPE.ROW?p:v,e)){o.resetCursor();return}o.setCursor(T.CURSOR_TYPE.GRAB)},c=()=>{var u,h;(u=this._moveHelperBackgroundShape)==null||u.hide(),(h=this._moveHelperLineShape)==null||h.hide(),o.resetCursor()},d=(u,h)=>{var W,D;if(h.isStopPropagation)return;const g=(W=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:W.skeleton;if(g==null)return;const S=(D=this._workbookSelections.getCurrentLastSelection())==null?void 0:D.range;if(!S||!this.interceptor.fetchThroughInterceptors(so)(!1,S))return;const{offsetX:p,offsetY:v}=u,C=o.getCoordRelativeToViewport(T.Vector2.FromArray([p,v])),{x:b,y:R}=C;this._startOffsetX=b,this._startOffsetY=R;const{row:w,column:M}=qe(u.offsetX,u.offsetY,o,g);let y;e===a.RANGE_TYPE.ROW?(this._changeFromRow=w,y=T.ScrollTimerType.Y):(this._changeFromColumn=M,y=T.ScrollTimerType.X);const P=this._workbookSelections.getCurrentSelections(),x=ir(P,e===a.RANGE_TYPE.ROW?w:M,e);if(!x)return;const A=o.getScrollXYInfoByViewport(T.Vector2.FromArray([this._startOffsetX,this._startOffsetY]));this._newBackgroundAndLine(),o.setCursor(T.CURSOR_TYPE.GRABBING),o.disableObjectsEvent();let k=!1,N;const H=()=>{if(k)return;N=T.ScrollTimer.create(o,y),this._scrollTimer=N;const U=o.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN);N.startScroll(b,R,U),k=!0};this._dragHeaderMoveSub=o.onPointerMove$.subscribeEvent(U=>{H();const{offsetX:L,offsetY:F}=U,{x:B,y:j}=o.getCoordRelativeToViewport(T.Vector2.FromArray([L,F]));this._rowColumnMoving(B,j,x,A,e),N.scrolling(B,j,()=>{this._rowColumnMoving(B,j,x,A,e)})}),this._scenePointerUpSub=o.onPointerUp$.subscribeEvent(()=>{var L,F,B;this._disposeBackgroundAndLine(),o.resetCursor(),o.enableObjectsEvent(),this._clearObserverEvent(),(L=this._scrollTimer)==null||L.dispose();const U=this._workbookSelections.getCurrentSelections();if(e===a.RANGE_TYPE.ROW){if(this._changeFromRow!==this._changeToRow&&this._changeToRow!==-1){const z=(F=((U==null?void 0:U.filter(K=>K.range.rangeType===a.RANGE_TYPE.ROW&&K.range.startRow<=this._changeFromRow&&this._changeFromRow<=K.range.endRow))||[])[0])==null?void 0:F.range;z&&this._commandService.executeCommand(m.MoveRowsCommand.id,{fromRange:z,toRange:{...z,startRow:this._changeToRow,endRow:this._changeToRow+z.endRow-z.startRow}})}this._changeToRow=this._changeFromRow=-1}else{if(this._changeFromColumn!==this._changeToColumn&&this._changeToColumn!==-1){const z=(B=((U==null?void 0:U.filter(K=>K.range.rangeType===a.RANGE_TYPE.COLUMN&&K.range.startColumn<=this._changeFromColumn&&this._changeFromColumn<=K.range.endColumn))||[])[0])==null?void 0:B.range;z&&this._commandService.executeCommand(m.MoveColsCommand.id,{fromRange:z,toRange:{...z,startColumn:this._changeToColumn,endColumn:this._changeToColumn+z.endColumn-z.startColumn}})}this._changeToColumn=this._changeFromColumn=-1}})};this._headerPointerMoveSubs=new O.Subscription,this._headerPointerMoveSubs.add(s.onPointerMove$.subscribeEvent(l)),this._headerPointerLeaveSubs=new O.Subscription,this._headerPointerLeaveSubs.add(s==null?void 0:s.onPointerLeave$.subscribeEvent(c)),this._headerPointerDownSubs=new O.Subscription,this._headerPointerDownSubs.add(s==null?void 0:s.onPointerDown$.subscribeEvent(d))}_rowColumnMoving(e,t,r,o,s){var j,z,K,ne,Q,se,ce;const l=this._context.scene,c=(j=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:j.skeleton;if(c==null)return;const{rowHeaderWidth:d,columnHeaderHeight:u,rowTotalHeight:h,columnTotalWidth:g}=c,S=l.getViewportScrollXY(l.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:f,scaleY:p}=l.getAncestorScale(),v=c.getCellIndexByOffset(e,t,f,p,S),{row:C,column:b}=v,R=c.getNoMergeCellWithCoordByIndex(C,b),{startX:w,startY:M,endX:y,endY:P}=R,x=this._sheetSkeletonManagerService.attachRangeWithCoord(r.range);if(x==null)return;const A=Math.max(f,f),{startX:k,endX:N,startY:H,endY:W,startRow:D,startColumn:U,endRow:L,endColumn:F}=x;s===a.RANGE_TYPE.ROW?(z=this._moveHelperBackgroundShape)==null||z.transformByState({height:W-H,width:g+d,left:0,top:H+(t-this._startOffsetY)/A+S.y-o.y}):(K=this._moveHelperBackgroundShape)==null||K.transformByState({height:h+u,width:N-k,left:k+(e-this._startOffsetX)/A+S.x-o.x,top:0}),(ne=this._moveHelperBackgroundShape)==null||ne.show();const B=rS/A;if(s===a.RANGE_TYPE.ROW){let X=0;if(C<=D)X=M-B/2,this._changeToRow=C;else if(C>L)X=P-B/2,this._changeToRow=C+1;else return;(Q=this._moveHelperLineShape)==null||Q.transformByState({height:B,width:g,left:d,top:X})}else{let X=0;if(b<=U)X=w-B/2,this._changeToColumn=b;else if(b>F)X=y-B/2,this._changeToColumn=b+1;else return;(se=this._moveHelperLineShape)==null||se.transformByState({height:h,width:B,left:X,top:u})}(ce=this._moveHelperLineShape)==null||ce.show()}_clearObserverEvent(){var e,t;(e=this._dragHeaderMoveSub)==null||e.unsubscribe(),(t=this._scenePointerUpSub)==null||t.unsubscribe(),this._dragHeaderMoveSub=null,this._scenePointerUpSub=null}_newBackgroundAndLine(){const e=this._context.scene;this._moveHelperBackgroundShape=new T.Rect($g,{fill:tS,evented:!1,zIndex:100}),this._moveHelperLineShape=new T.Rect(eS,{fill:nS,evented:!1,zIndex:100}),e.addObjects([this._moveHelperBackgroundShape,this._moveHelperLineShape],bt)}_disposeBackgroundAndLine(){var e,t;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(t=this._moveHelperLineShape)==null||t.dispose()}};exports.HeaderMoveRenderController=Jg([oo(1,a.Inject(m.SheetsSelectionsService)),oo(2,a.Inject(exports.SheetSkeletonManagerService)),oo(3,a.ICommandService)],exports.HeaderMoveRenderController);var Go=(n=>(n[n.VERTICAL=0]="VERTICAL",n[n.HORIZONTAL=1]="HORIZONTAL",n))(Go||{});const iS="rgba(120, 120, 120, 0.01)",ao="rgb(68, 71, 70)",Zn=12,oS=44,Zo=4;class ba extends T.Shape{constructor(e,t){super(e,t);E(this,"_size",Zn);E(this,"_color",ao);E(this,"_mode",0);this.setShapeProps(t)}get size(){return this._size}get mode(){return this._mode}get color(){return this._color}_draw(e){const t=this.getScene();if(!t)return;const{scaleX:r,scaleY:o}=t.getAncestorScale(),s=Math.max(r,o),l=Zn/s,c=Zo/s;let{width:d,height:u}=this,h=0,g=0;this.mode===0?(d=c,h=l-c):(u=c,g=l-c),T.Rect.drawWith(e,{width:this.width,height:this.height,left:0,top:0,fill:iS}),T.Rect.drawWith(e,{width:d,height:u,fill:ao,radius:c}),e.save(),e.transform(1,0,0,1,h,g),T.Rect.drawWith(e,{width:d,height:u,fill:ao,radius:c}),e.restore()}setShapeProps(e){return e!=null&&e.size&&(this._size=e.size),e!=null&&e.mode&&(this._mode=e.mode),e!=null&&e.color&&(this._color=e.color),this.mode===0?this.transformByState({width:Zn,height:this.size}):this.transformByState({width:this.size,height:Zn}),this}}var sS=Object.getOwnPropertyDescriptor,aS=(n,i,e,t)=>{for(var r=t>1?void 0:t?sS(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=s(r)||r);return r},lo=(n,i)=>(e,t)=>i(e,t,n);const lS="__SpreadsheetHeaderResizeControllerShapeRow__",cS="__SpreadsheetHeaderResizeControllerShapeColumn__",Ra="__SpreadsheetHeaderResizeControllerShapeHelper__",Ea="rgb(199, 199, 199)",dS=2,co=a.createInterceptorKey("headerResizePermissionCheck");exports.HeaderResizeRenderController=class extends a.Disposable{constructor(e,t,r,o){super();E(this,"_currentRow",0);E(this,"_currentColumn",0);E(this,"_rowResizeRect");E(this,"_columnResizeRect");E(this,"_headerPointerSubs");E(this,"_scenePointerMoveSub");E(this,"_scenePointerUpSub");E(this,"_resizeHelperShape");E(this,"_startOffsetX",Number.POSITIVE_INFINITY);E(this,"_startOffsetY",Number.POSITIVE_INFINITY);E(this,"interceptor",new a.InterceptorManager({HEADER_RESIZE_PERMISSION_CHECK:co}));this._context=e,this._sheetSkeletonManagerService=t,this._selectionManagerService=r,this._commandService=o,this._init()}dispose(){var e,t,r;(e=this._rowResizeRect)==null||e.dispose(),this._rowResizeRect=null,(t=this._columnResizeRect)==null||t.dispose(),this._columnResizeRect=null,(r=this._headerPointerSubs)==null||r.unsubscribe(),this._headerPointerSubs=null}_init(){const e=this._context.scene;this._rowResizeRect=new ba(lS,{visible:!1,mode:Go.HORIZONTAL,zIndex:100}),this._columnResizeRect=new ba(cS,{visible:!1,mode:Go.VERTICAL,zIndex:100}),e.addObjects([this._rowResizeRect,this._columnResizeRect],bt),this._initialHover(0),this._initialHover(1),this._initialHoverResize(0),this._initialHoverResize(1)}_initialHover(e=0){const t=this._context.components.get(he.COLUMN),r=this._context.components.get(he.ROW),o=this._context.scene,s=e===0?r:t,l=(d,u)=>{var h,g;(h=this._rowResizeRect)==null||h.hide(),(g=this._columnResizeRect)==null||g.hide()},c=(d,u)=>{var A;const h=(A=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:A.skeleton;if(h==null||this._rowResizeRect==null||this._columnResizeRect==null)return;const{rowHeaderWidth:g,columnHeaderHeight:S}=h,{startX:f,startY:p,endX:v,endY:C,row:b,column:R}=qe(d.offsetX,d.offsetY,o,h),w=Qn(d.offsetX,d.offsetY,o),{scaleX:M,scaleY:y}=o.getAncestorScale(),P=Math.max(M,y),x=Zn/P;if(e===0){let k=p-x/2;if(w.y<=p+x/2&&w.y>=p)this._currentRow=b-1;else if(w.y>=C-x/2&&w.y<=C)this._currentRow=b,k=C-x/2;else{this._rowResizeRect.hide();return}if(this._currentRow===-1)return;if(!this.interceptor.fetchThroughInterceptors(co)(null,{row:this._currentRow}))return!1;const H=Math.min(oS,g/3);this._rowResizeRect.transformByState({left:g/2-H/2,top:k}),this._rowResizeRect.setShapeProps({size:H}),this._rowResizeRect.show()}else{let k=f-x/2;if(w.x<=f+x/2&&w.x>=f)this._currentColumn=R-1;else if(w.x>=v-x/2&&w.x<=v)this._currentColumn=R,k=v-x/2;else{this._columnResizeRect.hide();return}if(this._currentColumn===-1)return;if(!this.interceptor.fetchThroughInterceptors(co)(null,{col:this._currentColumn}))return!1;const H=S*.7;this._columnResizeRect.transformByState({left:k,top:S/2-H/2}),this._columnResizeRect.setShapeProps({size:H}),this._columnResizeRect.show()}};this._headerPointerSubs=new O.Subscription,this._headerPointerSubs.add(s==null?void 0:s.onPointerMove$.subscribeEvent(c)),this._headerPointerSubs.add(s==null?void 0:s.onPointerLeave$.subscribeEvent(l))}_initialHoverResize(e=0){const t=this._context.scene,r=e===0?this._rowResizeRect:this._columnResizeRect;r!=null&&(this.disposeWithMe(r.onPointerEnter$.subscribeEvent(()=>{r!=null&&(r.show(),t.setCursor(e===0?T.CURSOR_TYPE.ROW_RESIZE:T.CURSOR_TYPE.COLUMN_RESIZE))})),this.disposeWithMe(r.onPointerLeave$.subscribeEvent(()=>{r!=null&&(r.hide(),t.resetCursor())})),this.disposeWithMe(r.onPointerDown$.subscribeEvent(o=>{var F,B,j,z,K,ne,Q;const s=(F=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:F.skeleton;if(s==null)return;const l=this._context.scene,c=l.getEngine(),d=(c==null?void 0:c.height)||0,u=(c==null?void 0:c.width)||0,h=l.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=(((j=(B=h==null?void 0:h.getScrollBar())==null?void 0:B.horizonScrollTrack)==null?void 0:j.height)||0)+10,S=(((K=(z=h==null?void 0:h.getScrollBar())==null?void 0:z.verticalScrollTrack)==null?void 0:K.width)||0)+10,f=Qn(o.offsetX,o.offsetY,l),{scaleX:p,scaleY:v}=l.getAncestorScale();this._startOffsetX=f.x,this._startOffsetY=f.y;const C=s.getOffsetByColumn(this._currentColumn),b=s.getOffsetByRow(this._currentRow),R=s.getNoMergeCellWithCoordByIndex(this._currentRow,this._currentColumn);let w=!1,M=0,y=0;const{columnTotalWidth:P,rowHeaderWidth:x,rowTotalHeight:A,columnHeaderHeight:k}=s,N=u>P+x?u:P+x,H=d>A+k?d:A+k,W=Math.max(p,v),D=Zo/W;e===0?this._resizeHelperShape=new T.Rect(Ra,{width:N,height:D,fill:Ea,left:0,top:b-D/2}):this._resizeHelperShape=new T.Rect(Ra,{width:D,height:H,fill:Ea,left:C-D/2,top:0});const U=((ne=this._columnResizeRect)==null?void 0:ne.left)||0,L=((Q=this._rowResizeRect)==null?void 0:Q.top)||0;l.addObject(this._resizeHelperShape,bt),l.disableObjectsEvent(),this._scenePointerMoveSub=l.onPointerMove$.subscribeEvent(se=>{var fe,Te,we,Fe,St,Mt;const ce=l.getCoordRelativeToViewport(T.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),X=l.getScrollXYInfoByViewport(ce,h),G=Qn(se.offsetX,se.offsetY,l),{x:q,y:ie}=G,{scaleX:oe,scaleY:J}=l.getAncestorScale(),ee=Math.max(oe,J),de=Zo/ee;M=q-this._startOffsetX-de/2,y=ie-this._startOffsetY-de/2,Math.abs(e===0?y:M)>=dS&&(w=!0),e===0?(y>d-g+X.y-R.startY&&(y=d-g+X.y-R.startY),y<-(R.endY-R.startY)+2&&(y=-(R.endY-R.startY)+2),w&&((fe=this._resizeHelperShape)==null||fe.transformByState({top:b+y}),(Te=this._rowResizeRect)==null||Te.transformByState({top:L+y+de/2}),(we=this._rowResizeRect)==null||we.show(),l.setCursor(T.CURSOR_TYPE.ROW_RESIZE))):(M>u-S+X.x-R.startX&&(M=u-S+X.x-R.startX),M<-(R.endX-R.startX)+2&&(M=-(R.endX-R.startX)+2),w&&((Fe=this._resizeHelperShape)==null||Fe.transformByState({left:C+M}),(St=this._columnResizeRect)==null||St.transformByState({left:U+M+de/2}),(Mt=this._columnResizeRect)==null||Mt.show(),l.setCursor(T.CURSOR_TYPE.COLUMN_RESIZE)))}),this._scenePointerUpSub=l.onPointerUp$.subscribeEvent(se=>{var X,G,q;const ce=this._context.scene;this._clearObserverEvent(),(X=this._resizeHelperShape)==null||X.dispose(),this._resizeHelperShape=null,ce.enableObjectsEvent(),w&&(ce.resetCursor(),(G=this._rowResizeRect)==null||G.hide(),(q=this._columnResizeRect)==null||q.hide(),e===0?this._commandService.executeCommand(m.DeltaRowHeightCommand.id,{deltaY:y,anchorRow:this._currentRow}):this._commandService.executeCommand(m.DeltaColumnWidthCommand.id,{deltaX:M,anchorCol:this._currentColumn}))})})),this.disposeWithMe(r.onDblclick$.subscribeEvent(()=>{var h,g,S;this._context.scene.resetCursor();const s=(h=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:h.skeleton;if(!s)return;const l=0,c=0,d=s.worksheet.getRowCount()-1||0,u=s.worksheet.getColumnCount()-1||0;switch(e){case 1:{const f=this._selectionManagerService.getCurrentSelections(),p=[];for(let v=0;v<f.length;v++){const C=f[v];C.range.rangeType===a.RANGE_TYPE.COLUMN&&this._currentColumn<=C.range.endColumn&&this._currentColumn>=C.range.startColumn&&p.push({startColumn:C.range.startColumn,endColumn:C.range.endColumn,startRow:l,endRow:d})}p.length===0&&p.push({startColumn:this._currentColumn,endColumn:this._currentColumn,startRow:l,endRow:d}),this._commandService.executeCommand(Er.id,{ranges:p}),(g=this._columnResizeRect)==null||g.hide();break}case 0:this._commandService.executeCommand(m.SetWorksheetRowIsAutoHeightCommand.id,{ranges:[{startRow:this._currentRow,endRow:this._currentRow,startColumn:c,endColumn:u}]}),(S=this._rowResizeRect)==null||S.hide();break}})))}_clearObserverEvent(){var e,t;(e=this._scenePointerMoveSub)==null||e.unsubscribe(),(t=this._scenePointerUpSub)==null||t.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null}};exports.HeaderResizeRenderController=aS([lo(1,a.Inject(exports.SheetSkeletonManagerService)),lo(2,a.Inject(m.SheetsSelectionsService)),lo(3,a.ICommandService)],exports.HeaderResizeRenderController);var uS=Object.getOwnPropertyDescriptor,hS=(n,i,e,t)=>{for(var r=t>1?void 0:t?uS(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=s(r)||r);return r},Lr=(n,i)=>(e,t)=>i(e,t,n);const mS=60;exports.SheetRenderController=class extends a.RxDisposable{constructor(e,t,r,o,s){super();E(this,"_renderFrameTimeMetric",null);E(this,"_renderFrameTags",{});E(this,"_afterRenderMetric$",new O.Subject);this._context=e,this._sheetSkeletonManagerService=t,this._sheetRenderService=r,this._commandService=o,this._telemetryService=s,this._addNewRender(),this._initRenderMetricSubscriber()}_addNewRender(){const{scene:e,engine:t,unit:r}=this._context;this._addComponent(r),this._initRerenderScheduler(),this._initCommandListener();const o=this._context.unit.getActiveSheet();if(!o)throw new Error("No active sheet found");const s=o.getSheetId();this._sheetSkeletonManagerService.setCurrent({sheetId:s});const l=()=>e.render();this.disposeWithMe(this._context.activated$.subscribe(c=>{c?t.runRenderLoop(l):t.stopRenderLoop(l)}))}_initRenderMetricSubscriber(){if(!this._telemetryService)return;const{engine:e}=this._context;e.beginFrame$.subscribe(()=>{this._renderFrameTimeMetric=null,this._renderFrameTags={}}),e.endFrame$.subscribe(()=>{this._renderFrameTimeMetric&&Object.keys(this._renderFrameTimeMetric).filter(o=>o.startsWith(T.SHEET_EXTENSION_PREFIX)).length>0&&this._afterRenderMetric$.next({frameTimeMetric:this._renderFrameTimeMetric,tags:this._renderFrameTags})}),e.renderFrameTimeMetric$.subscribe(([r,o])=>{this._renderFrameTimeMetric||(this._renderFrameTimeMetric={}),this._renderFrameTimeMetric[r]||(this._renderFrameTimeMetric[r]=[]),this._renderFrameTimeMetric[r].push(Math.round(o*100)/100)}),e.renderFrameTags$.subscribe(([r,o])=>{this._renderFrameTags[r]=o});const t=[];this._afterRenderMetric$.pipe(O.withLatestFrom(e.endFrame$)).subscribe(([r,o])=>{t.push({FPS:o.FPS,elapsedTime:o.elapsedTime,frameTime:Math.round(o.frameTime*100)/100,...r.frameTimeMetric,...r.tags}),t.length>mS&&(this._renderMetricCapture(t),t.length=0)})}_renderMetricCapture(e){const t=e;if(t.length===0)return;const r=g=>{let S=0;const p=Object.entries(g).filter(([C,b])=>Array.isArray(b)).map(([C])=>C).reduce((C,b)=>{const R=g[b].reduce((w,M)=>w+M,0);return C[b]=R,C},{});return Object.keys(g).filter(C=>C.startsWith(T.SHEET_EXTENSION_PREFIX)).forEach(C=>{S+=p[C]}),{...p,extensionTotal:S}},o=e.map(g=>({...g,...r(g)})),l=(g=>Object.entries(g[0]).filter(([p,v])=>!["elapsedTime"].includes(p)).filter(([p,v])=>typeof v=="number").map(([p])=>p).reduce((p,v)=>{const C=g.map(M=>M[v]),b=Math.max(...C),R=Math.min(...C),w=C.reduce((M,y)=>M+y,0)/C.length;return p[v]={max:Math.round(b*100)/100,min:Math.round(R*100)/100,avg:Math.round(w*100)/100},p},{}))(o),c=t[t.length-1].elapsedTime,d=this._context.unit.getActiveSheet().getSheetId(),u=this._context.unit.getUnitId(),h={sheetId:d,unitId:u,elapsedTimeToStart:c,...l};this._telemetryService.capture("sheet_render_cost",h)}_addComponent(e){const{scene:t,components:r}=this._context,o=e.getActiveSheet(),s=new T.Spreadsheet(he.MAIN);this._addViewport(o);const l=new T.SpreadsheetRowHeader(he.ROW),c=new T.SpreadsheetColumnHeader(he.COLUMN),d=new T.Rect(he.LEFT_TOP,{zIndex:2,left:-1,top:-1,fill:"rgb(248, 249, 250)",stroke:"rgb(217, 217, 217)",strokeWidth:1});this._context.mainComponent=s,r.set(he.MAIN,s),r.set(he.ROW,l),r.set(he.COLUMN,c),r.set(he.LEFT_TOP,d),t.addObjects([s],Bs),t.addObjects([l,c,d],bt),t.enableLayerCache(Bs,bt)}_initViewports(e,t,r){const l=new T.Viewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN,e,{left:t.width,top:r.height,bottom:0,right:0,isWheelPreventDefaultX:!0,allowCache:!0,bufferEdgeX:100,bufferEdgeY:100}),c=new T.Viewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:0,bufferEdgeY:0}),d=new T.Viewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:0,bufferEdgeY:100}),u=new T.Viewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:100,bufferEdgeY:0}),h=new T.Viewport(T.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP,e,{active:!1,isWheelPreventDefaultX:!0}),g=new T.Viewport(T.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM,e,{left:0,top:r.height,bottom:0,width:t.width,isWheelPreventDefaultX:!0}),S=new T.Viewport(T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT,e,{active:!1,isWheelPreventDefaultX:!0}),f=new T.Viewport(T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT,e,{left:t.width,top:0,height:r.height,right:0,isWheelPreventDefaultX:!0}),p=new T.Viewport(T.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP,e,{left:0,top:0,width:t.width,height:r.height,isWheelPreventDefaultX:!0});return{viewMain:l,viewLeftTop:p,viewMainLeftTop:c,viewMainLeft:d,viewMainTop:u,viewColumnLeft:S,viewRowTop:h,viewRowBottom:g,viewColumnRight:f}}_addViewport(e){const t=this._context.scene,{rowHeader:r,columnHeader:o}=e.getConfig(),{viewMain:s}=this._initViewports(t,r,o);return new T.ScrollBar(s),t.attachControl(),s}_initRerenderScheduler(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(!e)return null;const{skeleton:t,sheetId:r}=e,o=this._context.unit,s=o==null?void 0:o.getSheetBySheetId(r);if(o==null||s==null)return;const{mainComponent:l,components:c}=this._context,d=l,u=c.get(he.ROW),h=c.get(he.COLUMN),g=c.get(he.LEFT_TOP),{rowHeaderWidth:S,columnHeaderHeight:f}=t;d==null||d.updateSkeleton(t),u==null||u.updateSkeleton(t),h==null||h.updateSkeleton(t),g==null||g.transformByState({width:S,height:f})}))}_initCommandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{const{unit:t}=this._context,{id:r}=e;if(m.COMMAND_LISTENER_SKELETON_CHANGE.includes(r)||this._sheetRenderService.checkMutationShouldTriggerRerender(r)){const o=e.params,{unitId:s,subUnitId:l}=o,c=t.getActiveSheet();if(!c)return;const d=this._context.unitId,u=c.getSheetId();if(s!==d||l!==u)return;this._sheetSkeletonManagerService.makeDirty({sheetId:u,commandId:r},!0),this._sheetSkeletonManagerService.setCurrent({sheetId:u,commandId:r})}else m.COMMAND_LISTENER_VALUE_CHANGE.includes(r)&&this._sheetSkeletonManagerService.reCalculate();e.type===a.CommandType.MUTATION&&this._markUnitDirty(e)}))}_markUnitDirty(e){const{mainComponent:t,scene:r}=this._context;if(e.id===Z.SetFormulaCalculationNotificationMutation.id&&e.params.stageInfo!=null||(t&&t.makeDirty(),r.makeDirty(),!e.params))return;const o=e.params,s=this._spreadsheetViewports(r);if(e.id===m.SetRangeValuesMutation.id&&o.cellValue){const l=this._cellValueToRange(o.cellValue),c=this._rangeToBounds([l]);this._markViewportDirty(s,c),t.setDirtyArea(c)}if(e.id===m.MoveRangeMutation.id&&o.from&&o.to){const l=o.fromRange||this._cellValueToRange(o.from.value),c=o.toRange||this._cellValueToRange(o.to.value),d=this._rangeToBounds([l,c]);this._markViewportDirty(s,d),t.setDirtyArea(d)}}_cellValueToRange(e){let t=0,r=0,o=0,s=0;for(const[h,g]of Object.entries(e)){for(const S in g)t>Number(S)&&(t=Number(S)),r<Number(S)&&(r=Number(S));o>Number(h)&&(o=Number(h)),s<Number(h)&&(s=Number(h))}return{startRow:o,endRow:s,startColumn:t,endColumn:r}}_rangeToBounds(e){const t=this._sheetSkeletonManagerService.getCurrentParam().skeleton,{rowHeightAccumulation:r,columnWidthAccumulation:o,rowHeaderWidth:s,columnHeaderHeight:l}=t,c=[];for(const d of e){const{startRow:u,endRow:h,startColumn:g,endColumn:S}=d,f=u===0?0:r[u-1]+l,p=r[h]+l,v=g===0?0:o[g-1]+s,C=o[S]+s;c.push({top:f,left:v,bottom:p,right:C,width:C-v,height:p-f})}return c}_markViewportDirty(e,t){const r=e.filter(o=>o.isActive&&o.cacheBound);for(const o of r)for(const s of t)a.Rectangle.hasIntersectionBetweenTwoRect(o.cacheBound,s)&&o.markDirty(!0)}_spreadsheetViewports(e){return e.getViewports().filter(t=>["viewMain","viewMainLeftTop","viewMainTop","viewMainLeft"].includes(t.viewportKey))}};exports.SheetRenderController=hS([Lr(1,a.Inject(exports.SheetSkeletonManagerService)),Lr(2,a.Inject(exports.SheetsRenderService)),Lr(3,a.ICommandService),Lr(4,a.Optional(md.ITelemetryService))],exports.SheetRenderController);function gS(n,i){if(n.length!==i.length)return!1;const e=n.sort((r,o)=>r.id.localeCompare(o.id)),t=i.sort((r,o)=>r.id.localeCompare(o.id));return e.every((r,o)=>{var s,l;return((s=r.subject)==null?void 0:s.userID)===((l=t[o].subject)==null?void 0:l.userID)&&r.role===t[o].role})}function jl(n,i){return i.some(e=>SS(n,e))}function SS(n,i){const{startRow:e,startColumn:t,endColumn:r,endRow:o}=i,s=n.getMatrixWithMergedCells(e,t,o,r);let l=!1;return s.forValue((c,d,u)=>{if(u&&(c!==e||d!==t)&&n.cellHasValue(u))return l=!0,!1}),l}function zl(n,i,e,t){const r=[],o=[],s=e.getSheetId();return t.forEach(l=>{const c=fS(e,l),d={unitId:i,subUnitId:s,cellValue:c.getData()},u=m.SetRangeValuesUndoMutationFactory(n,d);r.push({id:m.SetRangeValuesMutation.id,params:u}),o.push({id:m.SetRangeValuesMutation.id,params:d})}),{undos:r,redos:o}}function fS(n,i){const{startRow:e,startColumn:t,endColumn:r,endRow:o}=i,s=n.getMatrixWithMergedCells(e,t,o,r,a.CellModeEnum.Intercepted),l=new a.ObjectMatrix;let c=null;return s.forValue((d,u,h)=>{var g,S,f,p;h&&d>=e&&u>=t&&(!c&&n.cellHasValue(h)&&(h.v!==""||((p=(f=(S=(g=h.p)==null?void 0:g.body)==null?void 0:S.dataStream)==null?void 0:f.length)!=null?p:0)>2)&&(c=h),l.setValue(d,u,null))}),l.setValue(e,t,c),l}function pS(n,i,e,t){const r=e.getActiveViewportByCoord(T.Vector2.FromArray([n,i]));if(!r)return;const{scaleX:o,scaleY:s}=e.getAncestorScale(),l={x:r.viewportScrollX,y:r.viewportScrollY},c=t.getCellIndexByOffset(n,i,o,s,l),d=t.worksheet.getMergedCell(c.row,c.column);return{actualRow:d?d.startRow:c.row,actualCol:d?d.startColumn:c.column,mergeCell:d,row:c.row,col:c.column}}function wa(n,i,e,t){const r=t.getFreeze();if(!r||r.startRow<=0&&r.startColumn<=0||n>=r.startRow&&i>=r.startColumn)return e.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(n<r.startRow&&i<r.startColumn)return e.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP);if(n<r.startRow&&i>=r.startColumn)return e.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(n>=r.startRow&&i<r.startColumn)return e.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)}function vS(n,i,e,t){const r=Ta(n.left,n.top,i,e,t),o=Ta(n.right,n.bottom,i,e,t);return{left:r.x,top:r.y,right:o.x,bottom:o.y}}function Ta(n,i,e,t,r){const{scaleX:o,scaleY:s}=e.getAncestorScale(),l=e.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!l)return{x:n,y:i};const c=r.getFreeze(),{startColumn:d,startRow:u,xSplit:h,ySplit:g}=c,S=t.getNoMergeCellWithCoordByIndex(u-g,d-h,!1),f=t.getNoMergeCellWithCoordByIndex(u,d,!1),{rowHeaderWidth:p,columnHeaderHeight:v}=t,C=f.startX-S.startX,b=f.startY-S.startY,{top:R,left:w,viewportScrollX:M,viewportScrollY:y}=l;let P;n>w?P=(n-M)*o:P=(C+p-(w-n))*o;let x;return i>R?x=(i-y)*s:x=(b+v-(R-i))*o,{x:P,y:x}}function Xl(n,i,e,t,r){let o=t,s=r;e.overflowCache.forValue((d,u,h)=>{h.startRow<=o&&h.endRow>=o&&h.startColumn<=s&&h.endColumn>=s&&(s=u,o=d)});const l=e.getCellWithCoordByIndex(o,s);return{unitId:n.getUnitId(),subUnitId:i.getSheetId(),workbook:n,worksheet:i,row:l.actualRow,col:l.actualColumn}}function Yl(n,i,e,t,r,o){const{scene:s}=n,l=i.getUnitId(),{skeleton:c,sheetId:d}=t,u=pS(r,o,s,c);if(!u)return null;let{actualCol:h,actualRow:g}=u;const S={unitId:l,subUnitId:d,workbook:i,worksheet:e,row:g,col:h};c.overflowCache.forValue((y,P,x)=>{x.startRow<=g&&x.endRow>=g&&x.startColumn<=h&&x.endColumn>=h&&(h=P,g=y)});const f=c.getCellWithCoordByIndex(g,h),p=Xl(i,e,c,g,h);let v;f.mergeInfo?v=f.mergeInfo:v={startRow:p.row,endRow:p.row,startColumn:p.col,endColumn:p.col};const C=s.getActiveViewportByCoord(T.Vector2.FromArray([r,o]));if(!C)return;const{scaleX:b,scaleY:R}=s.getAncestorScale(),w={x:C.viewportScrollX,y:C.viewportScrollY};return{position:{startX:(c.getOffsetByColumn(v.startColumn-1)-w.x)*b,endX:(c.getOffsetByColumn(v.endColumn)-w.x)*b,startY:(c.getOffsetByRow(v.startRow-1)-w.y)*R,endY:(c.getOffsetByRow(v.endRow)-w.y)*R},location:S,overflowLocation:p}}const Tt={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge",handler:async(n,i)=>{const e=n.get(a.ICommandService),t=n.get(a.IUndoRedoService),r=n.get(a.IUniverInstanceService),o=n.get(_.IConfirmService),s=n.get(a.LocaleService),l=i.unitId,c=i.subUnitId,d=i.selections,u=m.getAddMergeMutationRangeByType(d,i.value),h=r.getUniverSheetInstance(l).getSheetBySheetId(c),g=[],S=[],f=jl(h,u);if(f&&!i.defaultMerge&&!await o.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 p={unitId:l,subUnitId:c,ranges:a.Tools.deepClone(u)},v={unitId:l,subUnitId:c,ranges:a.Tools.deepClone(u)},C=m.RemoveMergeUndoMutationFactory(n,p),b=m.AddMergeUndoMutationFactory(n,v);if(C.ranges.length>0&&g.push({id:m.RemoveWorksheetMergeMutation.id,params:C}),g.push({id:m.AddWorksheetMergeMutation.id,params:v}),S.push({id:m.RemoveWorksheetMergeMutation.id,params:b}),C.ranges.length>0&&S.push({id:m.AddWorksheetMergeMutation.id,params:C}),f){const x=zl(n,l,h,u);g.unshift(...x.redos),S.push(...x.undos)}const R=m.AddMergeRedoSelectionsOperationFactory(n,i,u);R&&g.push(R);const w=m.AddMergeUndoSelectionsOperationFactory(n,i);w&&S.push(w);const y=n.get(m.SheetInterceptorService).onCommandExecute({id:Tt.id,params:{unitId:l,subUnitId:c,ranges:u}});return g.push(...y.redos),S.push(...y.undos),a.sequenceExecute(g,e).result?(t.pushUndoRedo({unitID:l,undoMutations:S,redoMutations:g}),!0):!1}},As={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-all",handler:async n=>{var u;const i=n.get(a.ICommandService),t=(u=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:u.map(h=>h.range),r=fs(ki.MergeAll,t);if(!(r!=null&&r.length))return!1;const s=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;const l=s.getActiveSheet();if(!l)return!1;const c=s.getUnitId(),d=l.getSheetId();return i.executeCommand(Tt.id,{selections:r,unitId:c,subUnitId:d})}},ks={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-vertical",handler:async n=>{var u;const i=n.get(a.ICommandService),t=(u=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:u.map(h=>h.range),r=fs(ki.MergeVertical,t);if(!(r!=null&&r.length))return!1;const s=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;const l=s.getActiveSheet();if(!l)return!1;const c=s.getUnitId(),d=l.getSheetId();return i.executeCommand(Tt.id,{value:a.Dimension.COLUMNS,selections:r,unitId:c,subUnitId:d})}},Ns={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-horizontal",handler:async n=>{var u;const i=n.get(a.ICommandService),t=(u=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:u.map(h=>h.range),r=fs(ki.MergeHorizontal,t);if(!(r!=null&&r.length))return!1;const s=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;const l=s.getActiveSheet();if(!l)return!1;const c=s.getUnitId(),d=l.getSheetId();return i.executeCommand(Tt.id,{value:a.Dimension.ROWS,selections:r,unitId:c,subUnitId:d})}},Vn={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-move-left-confirm",handler:async n=>{const i=n.get(_.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=r.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(o);if(!l)return!1;const{worksheet:c}=l;let d=s[0].range;if(!d)return!1;d={...d,endColumn:c.getColumnCount()-1};const u=S=>S.endRow-S.startRow;return!c.getMergeData().find(S=>{const f=a.Rectangle.getIntersects(S,d);return f?u(S)>u(f):!1})||await i.confirm({id:Vn.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.DeleteRangeMoveLeftCommand.id):!0}},Xt={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-move-up-confirm",handler:async n=>{const i=n.get(_.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=r.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(o);if(!l)return!1;const{worksheet:c}=l;let d=s[0].range;if(!d)return!1;d={...d,endRow:c.getRowCount()-1};for(let S=d.startRow;S<=d.endRow;S++)if(c.getRowFiltered(S)&&await i.confirm({id:Xt.id,title:{title:t.t("filter.confirm.error")},children:{title:t.t("filter.confirm.notAllowedToInsertRange")},confirmText:t.t("button.confirm")}))return!1;const u=S=>S.endColumn-S.startColumn;return!c.getMergeData().find(S=>{const f=a.Rectangle.getIntersects(S,d);return f?u(S)>u(f):!1})||await i.confirm({id:Xt.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.DeleteRangeMoveUpCommand.id):!0}},Yt={type:a.CommandType.COMMAND,id:"sheet.command.insert-range-move-down-confirm",handler:async n=>{const i=n.get(_.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=r.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(o);if(!l)return!1;const{worksheet:c}=l;let d=s[0].range;if(!d)return!1;d={...d,endRow:c.getRowCount()-1};for(let S=d.startRow;S<=d.endRow;S++)if(c.getRowFiltered(S)&&await i.confirm({id:Yt.id,title:{title:t.t("filter.confirm.error")},children:{title:t.t("filter.confirm.notAllowedToInsertRange")},confirmText:t.t("button.confirm")}))return!1;const u=S=>S.endColumn-S.startColumn;return!c.getMergeData().find(S=>{const f=a.Rectangle.getIntersects(S,d);return f?u(S)>u(f):!1})||await i.confirm({id:Yt.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.InsertRangeMoveDownCommand.id):!0}},Wn={type:a.CommandType.COMMAND,id:"sheet.command.insert-range-move-right-confirm",handler:async n=>{const i=n.get(_.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=r.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(o);if(!l)return!1;const{worksheet:c}=l;let d=s[0].range;if(!d)return!1;d={...d,endColumn:c.getColumnCount()-1};const u=S=>S.endRow-S.startRow;return!c.getMergeData().find(S=>{const f=a.Rectangle.getIntersects(S,d);return f?u(S)>u(f):!1})||await i.confirm({id:Wn.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.InsertRangeMoveRightCommand.id):!0}};var Gl=(n=>(n[n.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",n[n.UNIVER_DOC=1]="UNIVER_DOC",n[n.UNIVER_SHEET=2]="UNIVER_SHEET",n[n.UNIVER_SLIDE=3]="UNIVER_SLIDE",n[n.UNIVER_PROJECT=4]="UNIVER_PROJECT",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(Gl||{}),re=(n=>(n[n.View=0]="View",n[n.Edit=1]="Edit",n[n.ManageCollaborator=2]="ManageCollaborator",n[n.Print=3]="Print",n[n.Duplicate=4]="Duplicate",n[n.Comment=5]="Comment",n[n.Copy=6]="Copy",n[n.Share=7]="Share",n[n.Export=8]="Export",n[n.MoveWorksheet=9]="MoveWorksheet",n[n.DeleteWorksheet=10]="DeleteWorksheet",n[n.HideWorksheet=11]="HideWorksheet",n[n.RenameWorksheet=12]="RenameWorksheet",n[n.CreateWorksheet=13]="CreateWorksheet",n[n.SetWorksheetStyle=14]="SetWorksheetStyle",n[n.EditWorksheetCell=15]="EditWorksheetCell",n[n.InsertHyperlink=16]="InsertHyperlink",n[n.Sort=17]="Sort",n[n.Filter=18]="Filter",n[n.PivotTable=19]="PivotTable",n[n.FloatImg=20]="FloatImg",n[n.History=21]="History",n[n.RwHgtClWdt=22]="RwHgtClWdt",n[n.ViemRwHgtClWdt=23]="ViemRwHgtClWdt",n[n.ViewFilter=24]="ViewFilter",n[n.MoveSheet=25]="MoveSheet",n[n.DeleteSheet=26]="DeleteSheet",n[n.HideSheet=27]="HideSheet",n[n.CopySheet=28]="CopySheet",n[n.RenameSheet=29]="RenameSheet",n[n.CreateSheet=30]="CreateSheet",n[n.SelectProtectedCells=31]="SelectProtectedCells",n[n.SelectUnProtectedCells=32]="SelectUnProtectedCells",n[n.SetCellStyle=33]="SetCellStyle",n[n.SetCellValue=34]="SetCellValue",n[n.SetRowStyle=35]="SetRowStyle",n[n.SetColumnStyle=36]="SetColumnStyle",n[n.InsertRow=37]="InsertRow",n[n.InsertColumn=38]="InsertColumn",n[n.DeleteRow=39]="DeleteRow",n[n.DeleteColumn=40]="DeleteColumn",n[n.EditExtraObject=41]="EditExtraObject",n[n.Delete=42]="Delete",n[n.RecoverHistory=43]="RecoverHistory",n[n.ViewHistory=44]="ViewHistory",n[n.CreatePermissionObject=45]="CreatePermissionObject",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(re||{}),ke=(n=>(n[n.Reader=0]="Reader",n[n.Editor=1]="Editor",n[n.Owner=2]="Owner",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(ke||{}),dt=(n=>(n[n.Unkonwn=0]="Unkonwn",n[n.Workbook=1]="Workbook",n[n.Worksheet=2]="Worksheet",n[n.SelectRange=3]="SelectRange",n[n.Document=4]="Document",n[n.Slide=5]="Slide",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(dt||{}),Ke=(n=>(n[n.SomeCollaborator=0]="SomeCollaborator",n[n.AllCollaborator=1]="AllCollaborator",n[n.OneSelf=2]="OneSelf",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(Ke||{});const or="UNIVER_SHEET_PERMISSION_PANEL",ai="UNIVER_SHEET_PERMISSION_USER_PART",Ds="UNIVER_SHEET_PERMISSION_BACKGROUND",Zl="UNIVER_SHEET_PERMISSION_USER_DIALOG",Kl="UNIVER_SHEET_PERMISSION_DIALOG",li="UNIVER_SHEET_PERMISSION_USER_DIALOG_ID",ci="UNIVER_SHEET_PERMISSION_DIALOG_ID",Br={[re.Copy]:"Copy",[re.SetCellStyle]:"SetCellStyle",[re.SetCellValue]:"SetCellValue",[re.SetRowStyle]:"SetRowStyle",[re.SetColumnStyle]:"SetColumnStyle",[re.InsertRow]:"InsertRow",[re.InsertColumn]:"InsertColumn",[re.InsertHyperlink]:"InsertHyperlink",[re.DeleteRow]:"DeleteRow",[re.DeleteColumn]:"DeleteColumn",[re.Sort]:"Sort",[re.Filter]:"Filter",[re.PivotTable]:"PivotTable",[re.EditExtraObject]:"EditExtraObject"},CS=[re.Copy,re.SetCellStyle,re.SetCellValue,re.SetRowStyle,re.SetColumnStyle,re.InsertRow,re.InsertColumn,re.InsertHyperlink,re.DeleteRow,re.DeleteColumn,re.Sort,re.Filter,re.PivotTable,re.EditExtraObject,re.View],ql="sheet-permission-menu-icon",_S="sheet-permission-delete-icon",IS="sheet-permission-edit-icon",bS="sheet-permission-check-icon",Ql="sheet-permission-lock-icon",RS={unitId:"",subUnitId:"",permissionId:"",unitType:m.UnitObject.SelectRange,id:"",ranges:[],viewState:m.ViewStateEnum.OthersCanView,editState:m.EditStateEnum.OnlyMe};class yn{constructor(){E(this,"_rule",RS);E(this,"_visible",!1)}setVisible(i){this._visible=i}getVisible(){return this._visible}reset(){this.setVisible(!1)}}class yt{constructor(){E(this,"_userList",[]);E(this,"_userList$",new O.BehaviorSubject(this._userList));E(this,"userList$",this._userList$.asObservable());E(this,"_oldCollaboratorList",[]);E(this,"_selectUserList",[]);E(this,"_selectUserList$",new O.BehaviorSubject(this._selectUserList));E(this,"selectUserList$",this._selectUserList$.asObservable())}get userList(){return this._userList}setCanEditUserList(i){this._userList=i,this._userList$.next(i)}reset(){this._userList=[],this._oldCollaboratorList=[],this._selectUserList=[],this._selectUserList$.next([])}get oldCollaboratorList(){return this._oldCollaboratorList}setOldCollaboratorList(i){this._oldCollaboratorList=i}get selectUserList(){return this._selectUserList}setSelectUserList(i){this._selectUserList=i,this._selectUserList$.next(i)}}const Qe={type:a.CommandType.OPERATION,id:"sheet-permission.operation.openPanel",async handler(n,i={}){const e=n.get(_.ISidebarService),t=n.get(yn),r=n.get(yt),{showDetail:o=!0,fromSheetBar:s=!1,rule:l,oldRule:c}=i,d={header:{title:"permission.panel.title"},children:{label:or,showDetail:o,fromSheetBar:s,rule:l,oldRule:c},width:330,onClose:()=>{t.reset(),r.reset()}};return t.setVisible(!0),e.open(d),!0}},Mr={type:a.CommandType.COMMAND,id:"sheet.command.add-range-protection-from-toolbar",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{showDetail:!0}),!0}},Wt={type:a.CommandType.COMMAND,id:"sheet.command.add-range-protection-from-context-menu",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{showDetail:!0}),!0}},Ut={type:a.CommandType.COMMAND,id:"sheet.command.view-sheet-permission-from-context-menu",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{showDetail:!1}),!0}},Pr={type:a.CommandType.COMMAND,id:"sheet.command.add-range-protection-from-sheet-bar",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{fromSheetBar:!0,showDetail:!0}),!0}},Or={type:a.CommandType.COMMAND,id:"sheet.command.view-sheet-permission-from-sheet-bar",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{showDetail:!1}),!0}},Lt={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-protection-from-context-menu",async handler(n){var h;const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(a.IUndoRedoService),r=n.get(m.SheetsSelectionsService),o=n.get(m.WorksheetProtectionRuleModel),s=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),l=s.getActiveSheet(),c=s.getUnitId(),d=l.getSheetId(),u=o.getRule(c,d);if(u!=null&&u.permissionId)return i.executeCommand(m.DeleteWorksheetProtectionCommand.id,{unitId:c,subUnitId:d,rule:u});{const g=(h=r.getCurrentLastSelection())==null?void 0:h.range;if(!g)return!1;const p=n.get(m.RangeProtectionRuleModel).getSubunitRuleList(c,d).find(v=>v.ranges.some(C=>a.Rectangle.intersects(C,g)));if(p){const v={unitId:c,subUnitId:d,ruleIds:[p.id]};return await i.executeCommand(m.DeleteRangeProtectionMutation.id,v)&&t.pushUndoRedo({unitID:c,redoMutations:[{id:m.DeleteRangeProtectionMutation.id,params:v}],undoMutations:[{id:m.AddRangeProtectionMutation.id,params:{unitId:c,subUnitId:d,rules:[p]}}]}),!0}else return!1}}},Bt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-protection-from-context-menu",async handler(n){var u;const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.WorksheetProtectionRuleModel),o=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=o.getActiveSheet(),l=o.getUnitId(),c=s.getSheetId(),d=r.getRule(l,c);if(d!=null&&d.permissionId){const h={...d,unitId:l,subUnitId:c,ranges:[]};return await i.executeCommand(Qe.id,{showDetail:!0,rule:a.Tools.deepClone(h),oldRule:a.Tools.deepClone(h)}),!0}else{const h=(u=t.getCurrentLastSelection())==null?void 0:u.range;if(!h)return!1;const f=n.get(m.RangeProtectionRuleModel).getSubunitRuleList(l,c).find(p=>{var v;return(v=p==null?void 0:p.ranges)==null?void 0:v.some(C=>a.Rectangle.intersects(C,h))});if(f){const p={...f,unitId:l,subUnitId:c};return await i.executeCommand(Qe.id,{showDetail:!0,rule:a.Tools.deepClone(p),oldRule:a.Tools.deepClone(p)}),!0}else return!1}}},Mn={id:"sheet.command.remove-row-confirm",type:a.CommandType.COMMAND,handler:async(n,i)=>{var d;const e=n.get(m.SheetsSelectionsService);let t=i==null?void 0:i.range;if(t||(t=(d=e.getCurrentLastSelection())==null?void 0:d.range),!t)return!1;const r=n.get(a.ICommandService),o=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(o);if(!s)return!1;const{worksheet:l}=s,c=l.getVisibleRows();if(Ka(c,[t])){const u=n.get(_.IConfirmService),h=n.get(a.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 r.executeCommand(m.RemoveRowCommand.id,{range:t}),!0}},Pn={id:"sheet.command.remove-col-confirm",type:a.CommandType.COMMAND,handler:async(n,i)=>{var d;const e=n.get(m.SheetsSelectionsService);let t=i==null?void 0:i.range;if(t||(t=(d=e.getCurrentLastSelection())==null?void 0:d.range),!t)return!1;const r=n.get(a.ICommandService),o=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(o);if(!s)return!1;const{worksheet:l}=s,c=l.getVisibleCols();if(qa(c,[t])){const u=n.get(_.IConfirmService),h=n.get(a.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 r.executeCommand(m.RemoveColCommand.id,{range:t}),!0}},xr={id:"sheet.command.remove-sheet-confirm",type:a.CommandType.COMMAND,handler:async(n,i)=>{const{subUnitId:e}=i,t=n.get(_.IConfirmService),r=n.get(a.ICommandService),o=n.get(a.LocaleService);return await t.confirm({id:"sheet.confirm.remove-sheet",title:{title:o.t("sheetConfig.deleteSheet")},children:{title:o.t("sheetConfig.deleteSheetContent")},cancelText:o.t("button.cancel"),confirmText:o.t("button.confirm")})?(await r.executeCommand(m.RemoveSheetCommand.id,{subUnitId:e}),!0):!1}},Ar={id:"ui-sheet.command.show-menu-list",type:a.CommandType.OPERATION,handler:async n=>(n.get(Kt).triggerSheetBarMenu(),!0)},kr={type:a.CommandType.COMMAND,id:"sheet.command.delete-worksheet-protection-from-sheet-bar",async handler(n,i){if(!i)return!1;const e=n.get(a.ICommandService),t=n.get(a.IUndoRedoService),r=n.get(m.WorksheetProtectionRuleModel),s=n.get(a.IUniverInstanceService).getCurrentUnitForType(Gl.UNIVER_SHEET),l=s==null?void 0:s.getActiveSheet(),c=s.getUnitId();if(!l)return!1;const d=l.getSheetId(),u=r.getRule(c,d);if(await e.executeCommand(m.DeleteWorksheetProtectionCommand.id,{unitId:c,subUnitId:d})){const g=[{id:m.DeleteWorksheetProtectionCommand.id,params:{unitId:c,subUnitId:d}}],S=[{id:m.AddWorksheetProtectionCommand.id,params:{unitId:c,rule:u}}];t.pushUndoRedo({unitID:c,redoMutations:g,undoMutations:S})}return!0}},Nr={type:a.CommandType.COMMAND,id:"sheet.command.change-sheet-protection-from-sheet-bar",async handler(n){return await n.get(a.ICommandService).executeCommand("sheet-permission.operation.openDialog"),!0}},Fi={id:"sheet.operation.set-activate-cell-edit",type:a.CommandType.OPERATION,handler:(n,i)=>(n.get(Se).setEditCell(i),!0)},Dr={id:"sheet.operation.rename-sheet",type:a.CommandType.OPERATION,handler:async(n,i)=>{const e=n.get(Kt);return i&&e.setRenameId(i.subUnitId),!0}},Hs={type:a.CommandType.OPERATION,id:"sheet-permission.operation.openDialog",async handler(n,i){const e=n.get(_.IDialogService);return e.close("DESKTOP_FIND_REPLACE_DIALOG"),e.open({id:ci,title:{title:"permission.dialog.allowedPermissionType"},children:{label:Kl},width:393,destroyOnClose:!0,onClose:()=>e.close(ci)}),!0}},ES=()=>I.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[I.jsx("path",{d:"M0.98999 1.08218H-0.0100098V0.0821838H0.98999V1.08218Z",fill:"black"}),I.jsx("path",{d:"M5.78992 1.08218H2.78992V0.0821838H5.78992V1.08218Z",fill:"black"}),I.jsx("path",{d:"M7.58984 1.08218H8.58984V0.0821838H7.58984V1.08218Z",fill:"black"}),I.jsx("path",{d:"M14.9152 1.08218H13.9152V0.0821838H14.9152V1.08218Z",fill:"black"}),I.jsx("path",{d:"M16.7151 1.08218H19.7151V0.0821838H16.7151V1.08218Z",fill:"black"}),I.jsx("path",{d:"M22.515 1.08218H21.515V0.0821838H22.515V1.08218Z",fill:"black"}),I.jsx("path",{d:"M27.8405 1.08218H28.8405V0.0821838H27.8405V1.08218Z",fill:"black"}),I.jsx("path",{d:"M33.6404 1.08218H30.6404V0.0821838H33.6404V1.08218Z",fill:"black"}),I.jsx("path",{d:"M35.4403 1.08218H36.4403V0.0821838H35.4403V1.08218Z",fill:"black"}),I.jsx("path",{d:"M42.7657 1.08218H41.7657V0.0821838H42.7657V1.08218Z",fill:"black"}),I.jsx("path",{d:"M44.5657 1.08218H47.5657V0.0821838H44.5657V1.08218Z",fill:"black"}),I.jsx("path",{d:"M50.3656 1.08218H49.3656V0.0821838H50.3656V1.08218Z",fill:"black"}),I.jsx("path",{d:"M55.691 1.08218H56.691V0.0821838H55.691V1.08218Z",fill:"black"}),I.jsx("path",{d:"M61.491 1.08218H58.491V0.0821838H61.491V1.08218Z",fill:"black"}),I.jsx("path",{d:"M63.2909 1.08218H64.2909V0.0821838H63.2909V1.08218Z",fill:"black"}),I.jsx("path",{d:"M70.6163 1.08218H69.6163V0.0821838H70.6163V1.08218Z",fill:"black"}),I.jsx("path",{d:"M72.4163 1.08218H75.4163V0.0821838H72.4163V1.08218Z",fill:"black"}),I.jsx("path",{d:"M78.2162 1.08218H77.2162V0.0821838H78.2162V1.08218Z",fill:"black"}),I.jsx("path",{d:"M83.5416 1.08218H84.5416V0.0821838H83.5416V1.08218Z",fill:"black"}),I.jsx("path",{d:"M89.3416 1.08218H86.3416V0.0821838H89.3416V1.08218Z",fill:"black"}),I.jsx("path",{d:"M91.1415 1.08218H92.1415V0.0821838H91.1415V1.08218Z",fill:"black"}),I.jsx("path",{d:"M98.4669 1.08218H97.4669V0.0821838H98.4669V1.08218Z",fill:"black"}),I.jsx("path",{d:"M100.267 1.08218H103.267V0.0821838H100.267V1.08218Z",fill:"black"}),I.jsx("path",{d:"M106.067 1.08218H105.067V0.0821838H106.067V1.08218Z",fill:"black"}),I.jsx("path",{d:"M111.392 1.08218H112.392V0.0821838H111.392V1.08218Z",fill:"black"}),I.jsx("path",{d:"M117.192 1.08218H114.192V0.0821838H117.192V1.08218Z",fill:"black"}),I.jsx("path",{d:"M118.992 1.08218H119.992V0.0821838H118.992V1.08218Z",fill:"black"})]}),wS=()=>I.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[I.jsx("path",{d:"M-0.0100098 1.15771H0.98999V0.157715H-0.0100098V1.15771Z",fill:"black"}),I.jsx("path",{d:"M2.78992 1.15771H5.78992V0.157715H2.78992V1.15771Z",fill:"black"}),I.jsx("path",{d:"M8.58984 1.15771H7.58984V0.157715H8.58984V1.15771Z",fill:"black"}),I.jsx("path",{d:"M10.3899 1.15771H11.3899V0.157715H10.3899V1.15771Z",fill:"black"}),I.jsx("path",{d:"M19.0903 1.15771H18.0903V0.157715H19.0903V1.15771Z",fill:"black"}),I.jsx("path",{d:"M20.8903 1.15771H23.8903V0.157715H20.8903V1.15771Z",fill:"black"}),I.jsx("path",{d:"M26.6902 1.15771H25.6902V0.157715H26.6902V1.15771Z",fill:"black"}),I.jsx("path",{d:"M28.4902 1.15771H29.4902V0.157715H28.4902V1.15771Z",fill:"black"}),I.jsx("path",{d:"M37.1907 1.15771H36.1907V0.157715H37.1907V1.15771Z",fill:"black"}),I.jsx("path",{d:"M38.9906 1.15771H41.9906V0.157715H38.9906V1.15771Z",fill:"black"}),I.jsx("path",{d:"M44.7905 1.15771H43.7905V0.157715H44.7905V1.15771Z",fill:"black"}),I.jsx("path",{d:"M46.5906 1.15771H47.5906V0.157715H46.5906V1.15771Z",fill:"black"}),I.jsx("path",{d:"M55.291 1.15771H54.291V0.157715H55.291V1.15771Z",fill:"black"}),I.jsx("path",{d:"M57.0909 1.15771H60.0909V0.157715H57.0909V1.15771Z",fill:"black"}),I.jsx("path",{d:"M62.8909 1.15771H61.8909V0.157715H62.8909V1.15771Z",fill:"black"}),I.jsx("path",{d:"M64.6909 1.15771H65.6909V0.157715H64.6909V1.15771Z",fill:"black"}),I.jsx("path",{d:"M73.3914 1.15771H72.3914V0.157715H73.3914V1.15771Z",fill:"black"}),I.jsx("path",{d:"M75.1913 1.15771H78.1913V0.157715H75.1913V1.15771Z",fill:"black"}),I.jsx("path",{d:"M80.9912 1.15771H79.9912V0.157715H80.9912V1.15771Z",fill:"black"}),I.jsx("path",{d:"M82.7913 1.15771H83.7913V0.157715H82.7913V1.15771Z",fill:"black"}),I.jsx("path",{d:"M91.4917 1.15771H90.4917V0.157715H91.4917V1.15771Z",fill:"black"}),I.jsx("path",{d:"M93.2916 1.15771H96.2916V0.157715H93.2916V1.15771Z",fill:"black"}),I.jsx("path",{d:"M99.0916 1.15771H98.0916V0.157715H99.0916V1.15771Z",fill:"black"}),I.jsx("path",{d:"M100.892 1.15771H101.892V0.157715H100.892V1.15771Z",fill:"black"}),I.jsx("path",{d:"M109.592 1.15771H108.592V0.157715H109.592V1.15771Z",fill:"black"}),I.jsx("path",{d:"M111.392 1.15771H114.392V0.157715H111.392V1.15771Z",fill:"black"}),I.jsx("path",{d:"M117.192 1.15771H116.192V0.157715H117.192V1.15771Z",fill:"black"}),I.jsx("path",{d:"M118.992 1.15771H119.992V0.157715H118.992V1.15771Z",fill:"black"})]}),TS=()=>I.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[I.jsx("path",{d:"M-0.00842285 1.22449H2.99158V0.224487H-0.00842285V1.22449Z",fill:"black"}),I.jsx("path",{d:"M6.14941 1.22449H9.14941V0.224487H6.14941V1.22449Z",fill:"black"}),I.jsx("path",{d:"M15.3073 1.22449H12.3073V0.224487H15.3073V1.22449Z",fill:"black"}),I.jsx("path",{d:"M18.4651 1.22449H21.4651V0.224487H18.4651V1.22449Z",fill:"black"}),I.jsx("path",{d:"M27.6229 1.22449H24.6229V0.224487H27.6229V1.22449Z",fill:"black"}),I.jsx("path",{d:"M30.7808 1.22449H33.7808V0.224487H30.7808V1.22449Z",fill:"black"}),I.jsx("path",{d:"M39.9386 1.22449H36.9386V0.224487H39.9386V1.22449Z",fill:"black"}),I.jsx("path",{d:"M43.0964 1.22449H46.0964V0.224487H43.0964V1.22449Z",fill:"black"}),I.jsx("path",{d:"M52.2543 1.22449H49.2543V0.224487H52.2543V1.22449Z",fill:"black"}),I.jsx("path",{d:"M55.4121 1.22449H58.4121V0.224487H55.4121V1.22449Z",fill:"black"}),I.jsx("path",{d:"M64.5699 1.22449H61.5699V0.224487H64.5699V1.22449Z",fill:"black"}),I.jsx("path",{d:"M67.7278 1.22449H70.7278V0.224487H67.7278V1.22449Z",fill:"black"}),I.jsx("path",{d:"M76.8856 1.22449H73.8856V0.224487H76.8856V1.22449Z",fill:"black"}),I.jsx("path",{d:"M80.0435 1.22449H83.0435V0.224487H80.0435V1.22449Z",fill:"black"}),I.jsx("path",{d:"M89.2013 1.22449H86.2013V0.224487H89.2013V1.22449Z",fill:"black"}),I.jsx("path",{d:"M92.3591 1.22449H95.3591V0.224487H92.3591V1.22449Z",fill:"black"}),I.jsx("path",{d:"M101.517 1.22449H98.517V0.224487H101.517V1.22449Z",fill:"black"}),I.jsx("path",{d:"M104.675 1.22449H107.675V0.224487H104.675V1.22449Z",fill:"black"}),I.jsx("path",{d:"M113.833 1.22449H110.833V0.224487H113.833V1.22449Z",fill:"black"}),I.jsx("path",{d:"M116.99 1.22449H119.99V0.224487H116.99V1.22449Z",fill:"black"})]}),yS=()=>I.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[I.jsx("path",{d:"M-0.00976562 1.65707H0.990234V0.657074H-0.00976562V1.65707Z",fill:"black"}),I.jsx("path",{d:"M2.32361 1.65707H3.32361V0.657074H2.32361V1.65707Z",fill:"black"}),I.jsx("path",{d:"M5.65698 1.65707H4.65698V0.657074H5.65698V1.65707Z",fill:"black"}),I.jsx("path",{d:"M6.99036 1.65707H7.99036V0.657074H6.99036V1.65707Z",fill:"black"}),I.jsx("path",{d:"M10.3237 1.65707H9.32373V0.657074H10.3237V1.65707Z",fill:"black"}),I.jsx("path",{d:"M11.6571 1.65707H12.6571V0.657074H11.6571V1.65707Z",fill:"black"}),I.jsx("path",{d:"M14.9905 1.65707H13.9905V0.657074H14.9905V1.65707Z",fill:"black"}),I.jsx("path",{d:"M16.3239 1.65707H17.3239V0.657074H16.3239V1.65707Z",fill:"black"}),I.jsx("path",{d:"M19.6572 1.65707H18.6572V0.657074H19.6572V1.65707Z",fill:"black"}),I.jsx("path",{d:"M20.9906 1.65707H21.9906V0.657074H20.9906V1.65707Z",fill:"black"}),I.jsx("path",{d:"M24.324 1.65707H23.324V0.657074H24.324V1.65707Z",fill:"black"}),I.jsx("path",{d:"M25.6573 1.65707H26.6573V0.657074H25.6573V1.65707Z",fill:"black"}),I.jsx("path",{d:"M28.9907 1.65707H27.9907V0.657074H28.9907V1.65707Z",fill:"black"}),I.jsx("path",{d:"M30.3241 1.65707H31.3241V0.657074H30.3241V1.65707Z",fill:"black"}),I.jsx("path",{d:"M33.6575 1.65707H32.6575V0.657074H33.6575V1.65707Z",fill:"black"}),I.jsx("path",{d:"M34.9908 1.65707H35.9908V0.657074H34.9908V1.65707Z",fill:"black"}),I.jsx("path",{d:"M38.3242 1.65707H37.3242V0.657074H38.3242V1.65707Z",fill:"black"}),I.jsx("path",{d:"M39.6576 1.65707H40.6576V0.657074H39.6576V1.65707Z",fill:"black"}),I.jsx("path",{d:"M42.991 1.65707H41.991V0.657074H42.991V1.65707Z",fill:"black"}),I.jsx("path",{d:"M44.3243 1.65707H45.3243V0.657074H44.3243V1.65707Z",fill:"black"}),I.jsx("path",{d:"M47.6577 1.65707H46.6577V0.657074H47.6577V1.65707Z",fill:"black"}),I.jsx("path",{d:"M48.9911 1.65707H49.9911V0.657074H48.9911V1.65707Z",fill:"black"}),I.jsx("path",{d:"M52.3245 1.65707H51.3245V0.657074H52.3245V1.65707Z",fill:"black"}),I.jsx("path",{d:"M53.6578 1.65707H54.6578V0.657074H53.6578V1.65707Z",fill:"black"}),I.jsx("path",{d:"M56.9912 1.65707H55.9912V0.657074H56.9912V1.65707Z",fill:"black"}),I.jsx("path",{d:"M58.3246 1.65707H59.3246V0.657074H58.3246V1.65707Z",fill:"black"}),I.jsx("path",{d:"M61.658 1.65707H60.658V0.657074H61.658V1.65707Z",fill:"black"}),I.jsx("path",{d:"M62.9913 1.65707H63.9913V0.657074H62.9913V1.65707Z",fill:"black"}),I.jsx("path",{d:"M66.3247 1.65707H65.3247V0.657074H66.3247V1.65707Z",fill:"black"}),I.jsx("path",{d:"M67.6581 1.65707H68.6581V0.657074H67.6581V1.65707Z",fill:"black"}),I.jsx("path",{d:"M70.9915 1.65707H69.9915V0.657074H70.9915V1.65707Z",fill:"black"}),I.jsx("path",{d:"M72.3248 1.65707H73.3248V0.657074H72.3248V1.65707Z",fill:"black"}),I.jsx("path",{d:"M75.6582 1.65707H74.6582V0.657074H75.6582V1.65707Z",fill:"black"}),I.jsx("path",{d:"M76.9916 1.65707H77.9916V0.657074H76.9916V1.65707Z",fill:"black"}),I.jsx("path",{d:"M80.325 1.65707H79.325V0.657074H80.325V1.65707Z",fill:"black"}),I.jsx("path",{d:"M81.6583 1.65707H82.6583V0.657074H81.6583V1.65707Z",fill:"black"}),I.jsx("path",{d:"M84.9917 1.65707H83.9917V0.657074H84.9917V1.65707Z",fill:"black"}),I.jsx("path",{d:"M86.3251 1.65707H87.3251V0.657074H86.3251V1.65707Z",fill:"black"}),I.jsx("path",{d:"M89.6584 1.65707H88.6584V0.657074H89.6584V1.65707Z",fill:"black"}),I.jsx("path",{d:"M90.9918 1.65707H91.9918V0.657074H90.9918V1.65707Z",fill:"black"}),I.jsx("path",{d:"M94.3252 1.65707H93.3252V0.657074H94.3252V1.65707Z",fill:"black"}),I.jsx("path",{d:"M95.6586 1.65707H96.6586V0.657074H95.6586V1.65707Z",fill:"black"}),I.jsx("path",{d:"M98.9919 1.65707H97.9919V0.657074H98.9919V1.65707Z",fill:"black"}),I.jsx("path",{d:"M100.325 1.65707H101.325V0.657074H100.325V1.65707Z",fill:"black"}),I.jsx("path",{d:"M103.659 1.65707H102.659V0.657074H103.659V1.65707Z",fill:"black"}),I.jsx("path",{d:"M104.992 1.65707H105.992V0.657074H104.992V1.65707Z",fill:"black"}),I.jsx("path",{d:"M108.325 1.65707H107.325V0.657074H108.325V1.65707Z",fill:"black"}),I.jsx("path",{d:"M109.659 1.65707H110.659V0.657074H109.659V1.65707Z",fill:"black"}),I.jsx("path",{d:"M112.992 1.65707H111.992V0.657074H112.992V1.65707Z",fill:"black"}),I.jsx("path",{d:"M114.325 1.65707H115.325V0.657074H114.325V1.65707Z",fill:"black"}),I.jsx("path",{d:"M117.659 1.65707H116.659V0.657074H117.659V1.65707Z",fill:"black"}),I.jsx("path",{d:"M118.992 1.65707H119.992V0.657074H118.992V1.65707Z",fill:"black"})]}),MS=()=>I.jsx("svg",{width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:I.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 2.42035H-0.0090332V0.420349H119.991V2.42035Z",fill:"black"})}),PS=()=>I.jsxs("svg",{width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[I.jsx("path",{d:"M-0.0100098 2.47614H1.98999V0.476135H-0.0100098V2.47614Z",fill:"black"}),I.jsx("path",{d:"M3.99014 2.47614H9.99014V0.476135H3.99014V2.47614Z",fill:"black"}),I.jsx("path",{d:"M13.9901 2.47614H11.9901V0.476135H13.9901V2.47614Z",fill:"black"}),I.jsx("path",{d:"M21.1904 2.47614H23.1904V0.476135H21.1904V2.47614Z",fill:"black"}),I.jsx("path",{d:"M31.1906 2.47614H25.1906V0.476135H31.1906V2.47614Z",fill:"black"}),I.jsx("path",{d:"M33.1906 2.47614H35.1906V0.476135H33.1906V2.47614Z",fill:"black"}),I.jsx("path",{d:"M44.3909 2.47614H42.3909V0.476135H44.3909V2.47614Z",fill:"black"}),I.jsx("path",{d:"M46.391 2.47614H52.391V0.476135H46.391V2.47614Z",fill:"black"}),I.jsx("path",{d:"M56.391 2.47614H54.391V0.476135H56.391V2.47614Z",fill:"black"}),I.jsx("path",{d:"M63.5913 2.47614H65.5913V0.476135H63.5913V2.47614Z",fill:"black"}),I.jsx("path",{d:"M73.5915 2.47614H67.5915V0.476135H73.5915V2.47614Z",fill:"black"}),I.jsx("path",{d:"M75.5915 2.47614H77.5915V0.476135H75.5915V2.47614Z",fill:"black"}),I.jsx("path",{d:"M86.7917 2.47614H84.7917V0.476135H86.7917V2.47614Z",fill:"black"}),I.jsx("path",{d:"M88.7919 2.47614H94.7919V0.476135H88.7919V2.47614Z",fill:"black"}),I.jsx("path",{d:"M98.7919 2.47614H96.7919V0.476135H98.7919V2.47614Z",fill:"black"}),I.jsx("path",{d:"M105.992 2.47614H107.992V0.476135H105.992V2.47614Z",fill:"black"}),I.jsx("path",{d:"M115.992 2.47614H109.992V0.476135H115.992V2.47614Z",fill:"black"}),I.jsx("path",{d:"M117.992 2.47614H119.992V0.476135H117.992V2.47614Z",fill:"black"})]}),OS=()=>I.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[I.jsx("path",{d:"M-0.0100098 2.00415H1.98999V0.00415039H-0.0100098V2.00415Z",fill:"black"}),I.jsx("path",{d:"M3.99014 2.00415H9.99014V0.00415039H3.99014V2.00415Z",fill:"black"}),I.jsx("path",{d:"M13.9901 2.00415H11.9901V0.00415039H13.9901V2.00415Z",fill:"black"}),I.jsx("path",{d:"M15.9901 2.00415H17.9901V0.00415039H15.9901V2.00415Z",fill:"black"}),I.jsx("path",{d:"M27.4905 2.00415H25.4905V0.00415039H27.4905V2.00415Z",fill:"black"}),I.jsx("path",{d:"M29.4906 2.00415H35.4906V0.00415039H29.4906V2.00415Z",fill:"black"}),I.jsx("path",{d:"M39.4906 2.00415H37.4906V0.00415039H39.4906V2.00415Z",fill:"black"}),I.jsx("path",{d:"M41.4906 2.00415H43.4906V0.00415039H41.4906V2.00415Z",fill:"black"}),I.jsx("path",{d:"M52.991 2.00415H50.991V0.00415039H52.991V2.00415Z",fill:"black"}),I.jsx("path",{d:"M54.9911 2.00415H60.9911V0.00415039H54.9911V2.00415Z",fill:"black"}),I.jsx("path",{d:"M64.9911 2.00415H62.9911V0.00415039H64.9911V2.00415Z",fill:"black"}),I.jsx("path",{d:"M66.9911 2.00415H68.9911V0.00415039H66.9911V2.00415Z",fill:"black"}),I.jsx("path",{d:"M78.4915 2.00415H76.4915V0.00415039H78.4915V2.00415Z",fill:"black"}),I.jsx("path",{d:"M80.4916 2.00415H86.4916V0.00415039H80.4916V2.00415Z",fill:"black"}),I.jsx("path",{d:"M90.4916 2.00415H88.4916V0.00415039H90.4916V2.00415Z",fill:"black"}),I.jsx("path",{d:"M92.4916 2.00415H94.4916V0.00415039H92.4916V2.00415Z",fill:"black"}),I.jsx("path",{d:"M103.992 2.00415H101.992V0.00415039H103.992V2.00415Z",fill:"black"}),I.jsx("path",{d:"M105.992 2.00415H111.992V0.00415039H105.992V2.00415Z",fill:"black"}),I.jsx("path",{d:"M115.992 2.00415H113.992V0.00415039H115.992V2.00415Z",fill:"black"}),I.jsx("path",{d:"M117.992 2.00415H119.992V0.00415039H117.992V2.00415Z",fill:"black"})]}),xS=()=>I.jsxs("svg",{width:"118",height:"3",viewBox:"0 0 118 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[I.jsx("path",{d:"M-0.00854492 2.94815H1.99146V0.948151H-0.00854492V2.94815Z",fill:"black"}),I.jsx("path",{d:"M6.09668 2.94815H8.09668V0.948151H6.09668V2.94815Z",fill:"black"}),I.jsx("path",{d:"M14.2019 2.94815H12.2019V0.948151H14.2019V2.94815Z",fill:"black"}),I.jsx("path",{d:"M18.3071 2.94815H20.3071V0.948151H18.3071V2.94815Z",fill:"black"}),I.jsx("path",{d:"M26.4124 2.94815H24.4124V0.948151H26.4124V2.94815Z",fill:"black"}),I.jsx("path",{d:"M30.5176 2.94815H32.5176V0.948151H30.5176V2.94815Z",fill:"black"}),I.jsx("path",{d:"M38.6228 2.94815H36.6228V0.948151H38.6228V2.94815Z",fill:"black"}),I.jsx("path",{d:"M42.728 2.94815H44.728V0.948151H42.728V2.94815Z",fill:"black"}),I.jsx("path",{d:"M50.8333 2.94815H48.8333V0.948151H50.8333V2.94815Z",fill:"black"}),I.jsx("path",{d:"M54.9385 2.94815H56.9385V0.948151H54.9385V2.94815Z",fill:"black"}),I.jsx("path",{d:"M63.0437 2.94815H61.0437V0.948151H63.0437V2.94815Z",fill:"black"}),I.jsx("path",{d:"M67.1489 2.94815H69.1489V0.948151H67.1489V2.94815Z",fill:"black"}),I.jsx("path",{d:"M75.2542 2.94815H73.2542V0.948151H75.2542V2.94815Z",fill:"black"}),I.jsx("path",{d:"M79.3594 2.94815H81.3594V0.948151H79.3594V2.94815Z",fill:"black"}),I.jsx("path",{d:"M87.4645 2.94815H85.4645V0.948151H87.4645V2.94815Z",fill:"black"}),I.jsx("path",{d:"M91.5697 2.94815H93.5697V0.948151H91.5697V2.94815Z",fill:"black"}),I.jsx("path",{d:"M99.6749 2.94815H97.6749V0.948151H99.6749V2.94815Z",fill:"black"}),I.jsx("path",{d:"M103.78 2.94815H105.78V0.948151H103.78V2.94815Z",fill:"black"}),I.jsx("path",{d:"M111.885 2.94815H109.885V0.948151H111.885V2.94815Z",fill:"black"}),I.jsx("path",{d:"M115.991 2.94815H117.991V0.948151H115.991V2.94815Z",fill:"black"})]}),AS=()=>I.jsx("svg",{width:"120",height:"4",viewBox:"0 0 120 4",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:I.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 3.86215H-0.0090332V0.862152H119.991V3.86215Z",fill:"black"})}),ya=()=>I.jsx("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:I.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 1.15668H-0.0090332V0.156677H119.991V1.15668Z",fill:"black"})});function Ma(n){const{type:i=a.BorderStyleTypes.THIN}=n;switch(i){case a.BorderStyleTypes.DASH_DOT:return I.jsx(ES,{});case a.BorderStyleTypes.DASH_DOT_DOT:return I.jsx(wS,{});case a.BorderStyleTypes.DASHED:return I.jsx(TS,{});case a.BorderStyleTypes.HAIR:return I.jsx(yS,{});case a.BorderStyleTypes.MEDIUM:return I.jsx(MS,{});case a.BorderStyleTypes.MEDIUM_DASH_DOT:return I.jsx(PS,{});case a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT:return I.jsx(OS,{});case a.BorderStyleTypes.MEDIUM_DASHED:return I.jsx(xS,{});case a.BorderStyleTypes.THICK:return I.jsx(AS,{});case a.BorderStyleTypes.THIN:return I.jsx(ya,{});default:return I.jsx(ya,{})}}const Vs=`${Nn}_BORDER_PANEL_COMPONENT`,Jl=[{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:"HorizontalBorder",value:"horizontal"},{label:"borderLine.borderVertical",icon:"VerticalBorder",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"}],kS=[{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 $l(n){var l;const i=_.useDependency(_.ComponentManager),e=_.useDependency(m.BorderStyleManagerService),{onChange:t,value:r}=n;function o(c,d){t==null||t({...r,[d]:c})}function s(c){const d=i.get(c);return d&&I.jsx(d,{extend:{colorChannel1:"#2c53f1"}})}return I.jsxs("section",{className:"univer-box-border univer-grid univer-gap-2 univer-p-1.5",children:[I.jsx("div",{className:"univer-box-border univer-grid univer-grid-cols-5 univer-gap-2",children:Jl.map(c=>I.jsx("a",{className:Y.clsx(`
58
+ `)}),i}function ig(n){return a.isNotNullOrUndefined(n.displayV)?n.displayV:a.extractPureTextFromCell(n)}function og(n,i,e,t){return t.getMergeData().some(r=>r.startRow<=n&&n<r.endRow&&i<=r.startColumn&&r.startColumn<=e)}function sg(n,i,e,t){return t.getMergeData().some(r=>r.startColumn<=n&&n<r.endColumn&&i<=r.startRow&&r.startRow<=e)}function ag(n){let i=0;return n.forValue((e,t,r)=>{if(r&&i++,i>1)return!1}),i>1}function Bn(){return{p:null,v:null,s:null,f:null,si:null,t:null}}const ys=998,Xe={id:_.CopyCommand.id,name:"sheet.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:ys,preconditions:Es,handler:async n=>n.get(Be).copy()},Ms={id:_.CutCommand.id,name:"sheet.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:ys,preconditions:Es,handler:async n=>n.get(Be).cut()},Ye={id:_.PasteCommand.id,type:a.CommandType.COMMAND,multi:!0,name:"sheet.command.paste",priority:ys,preconditions:Es,handler:async(n,i)=>{const t=await n.get(_.IClipboardInterfaceService).read(),r=n.get(Be);return t.length!==0?r.paste(t[0],i==null?void 0:i.value):!1}},oi={id:_.SheetPasteShortKeyCommandName,type:a.CommandType.COMMAND,handler:async(n,i)=>{const e=n.get(Be),{htmlContent:t,textContent:r,files:o}=i;return e.legacyPaste(t,r,o),!0}},gn={id:"sheet.command.paste-value",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Ye.id,{value:ge.SPECIAL_PASTE_VALUE})},Sn={id:"sheet.command.paste-format",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Ye.id,{value:ge.SPECIAL_PASTE_FORMAT})},Vt={id:"sheet.command.paste-col-width",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Ye.id,{value:ge.SPECIAL_PASTE_COL_WIDTH})},fn={id:"sheet.command.paste-besides-border",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Ye.id,{value:ge.SPECIAL_PASTE_BESIDES_BORDER})},Nl={id:"sheet.command.optional-paste",type:a.CommandType.COMMAND,handler:async(n,{type:i})=>n.get(Be).rePasteWithPasteType(i)},fr={id:"sheet.command.hide-row-confirm",type:a.CommandType.COMMAND,handler:async n=>{var c;const e=(c=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:c.map(d=>d.range);if(!(e!=null&&e.length))return!1;const t=n.get(a.ICommandService),r=n.get(a.IUniverInstanceService),o=m.getSheetCommandTarget(r);if(!o)return!1;const{worksheet:s}=o,l=s.getVisibleRows();if(Ka(l,e)){const d=n.get(_.IConfirmService),u=n.get(a.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 t.executeCommand(m.SetRowHiddenCommand.id),!0}},pr={id:"sheet.command.hide-col-confirm",type:a.CommandType.COMMAND,handler:async n=>{var c;const e=(c=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:c.map(d=>d.range);if(!(e!=null&&e.length))return!1;const t=n.get(a.ICommandService),r=n.get(a.IUniverInstanceService),o=m.getSheetCommandTarget(r);if(!o)return!1;const{worksheet:s}=o,l=s.getVisibleCols();if(qa(l,e)){const d=n.get(_.IConfirmService),u=n.get(a.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 t.executeCommand(m.SetColHiddenCommand.id),!0}},Qt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-bold",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand($.SetInlineFormatBoldCommand.id):i.executeCommand(m.SetBoldCommand.id)}},Jt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-italic",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand($.SetInlineFormatItalicCommand.id):i.executeCommand(m.SetItalicCommand.id)}},$t={type:a.CommandType.COMMAND,id:"sheet.command.set-range-underline",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand($.SetInlineFormatUnderlineCommand.id):i.executeCommand(m.SetUnderlineCommand.id)}},en={type:a.CommandType.COMMAND,id:"sheet.command.set-range-stroke",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand($.SetInlineFormatStrikethroughCommand.id):i.executeCommand(m.SetStrikeThroughCommand.id)}},Ps={type:a.CommandType.COMMAND,id:"sheet.command.set-range-subscript",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand($.SetInlineFormatSubscriptCommand.id):!1}},Os={type:a.CommandType.COMMAND,id:"sheet.command.set-range-superscript",handler:async n=>{const i=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?i.executeCommand($.SetInlineFormatSuperscriptCommand.id):!1}},vr={type:a.CommandType.COMMAND,id:"sheet.command.set-range-fontsize",handler:async(n,i)=>{const e=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand($.SetInlineFormatFontSizeCommand.id,i):e.executeCommand(m.SetFontSizeCommand.id,i)}},Cr={type:a.CommandType.COMMAND,id:"sheet.command.set-range-font-family",handler:async(n,i)=>{const e=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand($.SetInlineFormatFontFamilyCommand.id,i):e.executeCommand(m.SetFontFamilyCommand.id,i)}},Tn={type:a.CommandType.COMMAND,id:"sheet.command.set-range-text-color",handler:async(n,i)=>{const e=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand($.SetInlineFormatTextColorCommand.id,i):e.executeCommand(m.SetTextColorCommand.id,i)}},xs={type:a.CommandType.COMMAND,id:"sheet.command.reset-range-text-color",handler:async n=>{const i=n.get(a.ICommandService),t=n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED),r=n.get(a.ThemeService);return t?i.executeCommand($.SetInlineFormatTextColorCommand.id,{value:null}):i.executeCommand(m.SetTextColorCommand.id,{value:r.getCurrentTheme().textColor})}};var lg=Object.getOwnPropertyDescriptor,cg=(n,i,e,t)=>{for(var r=t>1?void 0:t?lg(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=s(r)||r);return r},ln=(n,i)=>(e,t)=>i(e,t,n),Ne=(n=>(n[n.OFF=0]="OFF",n[n.ONCE=1]="ONCE",n[n.INFINITE=2]="INFINITE",n))(Ne||{});const et=a.createIdentifier("univer.format-painter-service");let si=class extends a.Disposable{constructor(i,e,t,r,o,s){super();E(this,"status$");E(this,"_selectionFormat");E(this,"_markId",null);E(this,"_status$");E(this,"_defaultHook",null);E(this,"_extendHooks",[]);this._selectionManagerService=i,this._themeService=e,this._markSelectionService=t,this._logService=r,this._commandService=o,this._undoRedoService=s,this._status$=new O.BehaviorSubject(0),this.status$=this._status$.asObservable(),this._selectionFormat={styles:new a.ObjectMatrix,merges:[]}}addHook(i){var e,t,r;i.isDefaultHook&&((e=i.priority)!=null?e:0)>((r=(t=this._defaultHook)==null?void 0:t.priority)!=null?r:-1)?this._defaultHook=i:(this._extendHooks.push(i),this._extendHooks.sort((o,s)=>(o.priority||0)-(s.priority||0)))}getHooks(){return this._defaultHook?[this._defaultHook,...this._extendHooks]:this._extendHooks}setStatus(i){this._updateRangeMark(i),this._status$.next(i),this.getHooks().forEach(t=>{t.onStatusChange!==void 0&&t.onStatusChange(i)})}getStatus(){return this._status$.getValue()}setSelectionFormat(i){this._selectionFormat=i}getSelectionFormat(){return this._selectionFormat}applyFormatPainter(i,e,t){const r=this.getHooks(),o=[],s=[];r.forEach(c=>{if(c.onApply!==void 0){const d=c.onApply(i,e,t,this._selectionFormat);d&&(o.push(...d.redos),s.push(...d.undos))}});for(const c of r)if(c.onBeforeApply!==void 0&&!c.onBeforeApply({unitId:i,subUnitId:e,range:t,redoMutationsInfo:o,format:this._selectionFormat,undoMutationsInfo:s}))return!1;this._logService.log("[FormatPainterService]","apply mutations",{undoMutationsInfo:s,redoMutationsInfo:o});const l=o.every(c=>this._commandService.executeCommand(c.id,c.params));return l&&this._undoRedoService.pushUndoRedo({unitID:i,undoMutations:s,redoMutations:o}),l}_updateRangeMark(i){if(this._markSelectionService.removeAllShapes(),i!==0){const e=this._selectionManagerService.getCurrentLastSelection();if(e){const t=Ol(this._themeService);i===2?this._markId=this._markSelectionService.addShape({...e,style:t}):this._markId=this._markSelectionService.addShape({...e,style:t},[m.SetRangeValuesMutation.id])}}}};si=cg([ln(0,a.Inject(m.SheetsSelectionsService)),ln(1,a.Inject(a.ThemeService)),ln(2,qt),ln(3,a.ILogService),ln(4,a.ICommandService),ln(5,a.IUndoRedoService)],si);const _r={id:"sheet.operation.set-format-painter",type:a.CommandType.OPERATION,handler:(n,i)=>i?(n.get(et).setStatus(i.status),!0):!1},Vi={type:a.CommandType.COMMAND,id:"sheet.command.set-infinite-format-painter",handler:async n=>{const e=n.get(et).getStatus();let t;return e!==Ne.OFF?t=Ne.OFF:t=Ne.INFINITE,n.get(a.ICommandService).executeCommand(_r.id,{status:t})}},kn={type:a.CommandType.COMMAND,id:"sheet.command.set-once-format-painter",handler:async n=>{const e=n.get(et).getStatus();let t;return e!==Ne.OFF?t=Ne.OFF:t=Ne.ONCE,n.get(a.ICommandService).executeCommand(_r.id,{status:t})}},Ir={type:a.CommandType.COMMAND,id:"sheet.command.apply-format-painter",handler:async(n,i)=>n.get(et).applyFormatPainter(i.unitId,i.subUnitId,i.range)},ht={type:a.CommandType.COMMAND,id:"sheet.command.set-selection-frozen",handler:async(n,i)=>{const{type:e}=i||{},t=n.get(a.IUniverInstanceService),r=n.get(a.IUndoRedoService),o=m.getSheetCommandTarget(t);if(!o)return!1;const{unitId:s,subUnitId:l}=o,c=n.get(a.ICommandService),u=n.get(m.SheetsSelectionsService).getCurrentSelections();if(!u)return!1;const h=u[(u==null?void 0:u.length)-1],{range:g}=h,f=n.get(T.IRenderManagerService).getRenderById(s).with(exports.SheetScrollManagerService),{sheetViewStartRow:p=0,sheetViewStartColumn:v=0}=f.getCurrentScrollState()||{};let C,b,R,w;const{startRow:M,startColumn:y,rangeType:P}=g;if(P===a.RANGE_TYPE.ROW||e===1)C=M,R=M-p,b=-1,w=0;else if(P===a.RANGE_TYPE.COLUMN||e===2)C=-1,R=0,b=y,w=y-v;else if(P===a.RANGE_TYPE.NORMAL)C=M,R=M-p,b=y,w=y-v;else return!1;const x={unitId:s,subUnitId:l,startRow:C,startColumn:b,xSplit:b>0?Math.max(1,w):w,ySplit:C>0?Math.max(1,R):R},A=m.SetFrozenMutationFactory(n,x);return c.syncExecuteCommand(m.SetFrozenMutation.id,x)&&r.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetFrozenMutation.id,params:A}],redoMutations:[{id:m.SetFrozenMutation.id,params:x}]}),!0}},br={type:a.CommandType.COMMAND,id:"sheet.command.set-row-frozen",handler:async n=>(n.get(a.ICommandService).executeCommand(ht.id,{type:1}),!0)},Rr={type:a.CommandType.COMMAND,id:"sheet.command.set-col-frozen",handler:async n=>(n.get(a.ICommandService).executeCommand(ht.id,{type:2}),!0)};var dg=Object.getOwnPropertyDescriptor,ug=(n,i,e,t)=>{for(var r=t>1?void 0:t?dg(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=s(r)||r);return r},fa=(n,i)=>(e,t)=>i(e,t,n);const hg=(n,i)=>{const{unitId:e,subUnitId:t,ranges:r}=n,o={},s=i.getColumnManager();for(let l=0;l<r.length;l++){const c=r[l];for(let d=c.startColumn;d<c.endColumn+1;d++){const u=s.getColumnOrCreate(d);o[d]=u.w}}return{unitId:e,subUnitId:t,ranges:r,colWidth:o}};exports.AutoWidthController=class extends a.Disposable{constructor(i,e){super(),this._renderManagerService=i,this._univerInstanceService=e}getUndoRedoParamsOfColWidth(i){const e={redos:[],undos:[]},{_univerInstanceService:t}=this,r=m.getSheetCommandTarget(t);if(!r)return e;const{unitId:o,subUnitId:s,worksheet:l}=r,c=this._renderManagerService.getRenderById(o).with(exports.SheetSkeletonManagerService);if(!c.getCurrentParam())return e;const{skeleton:d}=c.getCurrentParam(),u=d.calculateAutoWidthInRange(i.ranges),h={};for(const{col:f,width:p}of u)h[f]=p;const g={subUnitId:s,unitId:o,ranges:i.ranges,colWidth:h},S=hg(g,l);return{undos:[{id:m.SetWorksheetColWidthMutation.id,params:S}],redos:[{id:m.SetWorksheetColWidthMutation.id,params:g}]}}};exports.AutoWidthController=ug([fa(0,T.IRenderManagerService),fa(1,a.Inject(a.IUniverInstanceService))],exports.AutoWidthController);const Er={type:a.CommandType.COMMAND,id:"sheet.command.set-col-auto-width",handler:(n,i)=>{const e=n.get(a.ICommandService),t=n.get(a.IUndoRedoService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(o,i);if(!s)return!1;const{unitId:l,subUnitId:c}=s;let d=[];if(i!=null&&i.ranges)d=[...i.ranges];else{const f=r.getCurrentSelections();for(let p=0;p<f.length;p++)d.push(f[p].range)}if(!(d!=null&&d.length))return!1;const u={unitId:l,subUnitId:c,ranges:d},{redos:h,undos:g}=n.get(exports.AutoWidthController).getUndoRedoParamsOfColWidth(u);return a.sequenceExecute([...h],e).result?(t.pushUndoRedo({unitID:l,undoMutations:[...g],redoMutations:[...h]}),!0):!1}},Nn="UI_PLUGIN_SHEETS",wr=`${Nn}_COLOR_PICKER_COMPONENT`,Wi=`${Nn}_FONT_FAMILY_COMPONENT`,Ui=`${Nn}_FONT_FAMILY_ITEM_COMPONENT`,Li=`${Nn}_FONT_SIZE_COMPONENT`,tt=`${Nn}_MENU_ITEM_INPUT_COMPONENT`,mg="univer-sheets-ui-context-menu-input",gg="univer-sheets-ui-context-menu-input-container",Sg="univer-sheets-ui-context-menu-input-number",Ki={sheetsUiContextMenuInput:mg,sheetsUiContextMenuInputContainer:gg,sheetsUiContextMenuInputNumber:Sg},Dl=n=>{const{prefix:i,suffix:e,value:t,onChange:r,min:o=Number.MIN_SAFE_INTEGER,max:s=Number.MAX_SAFE_INTEGER}=n,l=_.useDependency(a.LocaleService),c=_.useDependency(_.IContextMenuService),[d,u]=V.useState(),h=S=>{var f;u(S==null?void 0:S.toString()),r((f=S==null?void 0:S.toString())!=null?f:"")};V.useEffect(()=>{c.visible||u(t)},[c.visible]),V.useEffect(()=>{u(t)},[t]);function g(S){S.key==="Backspace"&&S.stopPropagation()}return I.jsxs("div",{className:Ki.sheetsUiContextMenuInput,children:[l.t(i),I.jsx("span",{className:Ki.sheetsUiContextMenuInputContainer,onClick:S=>S.stopPropagation(),children:I.jsx(Y.InputNumber,{className:Ki.sheetsUiContextMenuInputNumber,value:Number(d),precision:0,onKeyDown:g,onChange:h,min:o,max:s})}),l.t(e)]})};function fg(n){return n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(me.switchMap(i=>i?i.activeSheet$.pipe(me.map(e=>e?{workbook:i,worksheet:e}:null)):O.of(null)))}function be(n,i,e){return fg(n).pipe(me.switchMap(t=>t?e(t):O.of(i)))}function Hl(n,i){const e=n.get(a.IUniverInstanceService),t=n.get(m.IExclusiveRangeService),r=n.get(m.SheetsSelectionsService);return e.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(me.switchMap(s=>s?O.combineLatest([r.selectionMoveEnd$,s.activeSheet$]).pipe(me.switchMap(([l,c])=>{if(!c||l.length===0)return O.of(!1);const d=t.getInterestGroupId(l);if(i){const u=d.filter(h=>i.has(h));return O.of(u.length>0)}else return O.of(d.length>0)})):O.of(!1)))}function tn(n,i,e){return O.combineLatest([i,Hl(n,e)]).pipe(me.map(([t,r])=>t||r))}function te(n,i={},e=!1){var g;const r=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),o=n.get(a.UserManagerService),s=n.has(Se)?n.get(Se):null,l=n.get(a.IContextService),c=new O.BehaviorSubject(!1),d=(g=s==null?void 0:s.visible$)!=null?g:O.of(null),u=l.subscribeContextValue$(a.FOCUSING_FX_BAR_EDITOR).subscribe(S=>{c.next(S)});return O.combineLatest([o.currentUser$,r,d,c]).pipe(me.finalize(()=>{u.unsubscribe(),c.complete()}),me.switchMap(([S,f,p,v])=>!f||p!=null&&p.visible&&p.unitId===f.getUnitId()&&!e||v&&!e?O.of(!0):f.activeSheet$.pipe(me.switchMap(C=>{if(!C)return O.of(!0);const b=n.get(m.SheetsSelectionsService),R=n.get(m.RangeProtectionRuleModel),w=n.get(m.WorksheetProtectionRuleModel),y=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_COMMON_DRAWINGS).pipe(me.startWith(!1));return O.combineLatest([b.selectionMoveEnd$,y]).pipe(me.switchMap(([P,x])=>{if(x)return O.of(!0);const A=f.getUnitId(),k=C.getSheetId(),N=n.get(a.IPermissionService),{workbookTypes:H=[m.WorkbookEditablePermission],worksheetTypes:W,rangeTypes:D}=i,U=[];if(H==null||H.forEach(j=>{U.push(new j(A).id)}),W==null||W.forEach(j=>{U.push(new j(A,k).id)}),w.getRule(A,k))return N.composePermission$(U).pipe(me.map(j=>j.some(z=>z.value===!1)));const F=P==null?void 0:P.map(j=>j.range),B=R.getSubunitRuleList(A,k).filter(j=>F==null?void 0:F.some(z=>j.ranges.some(K=>a.Rectangle.intersects(z,K))));return D==null||D.forEach(j=>{B.forEach(z=>{U.push(new j(A,k,z.permissionId).id)})}),N.composePermission$(U).pipe(me.map(j=>j.some(z=>z.value===!1)))}))}))))}function Dn(n){const i=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(m.RangeProtectionRuleModel),r=n.get(a.IPermissionService);return O.merge(e.selectionMoveEnd$,r.permissionPointUpdate$.pipe(me.debounceTime(100))).pipe(me.map(()=>{var h;const o=(h=e.getCurrentLastSelection())==null?void 0:h.range;if(!o)return!0;const s=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),l=s==null?void 0:s.getActiveSheet();if(!s||!l)return!0;const c=s.getUnitId(),d=l.getSheetId(),u=[new m.WorkbookEditablePermission(c).id,new m.WorksheetEditPermission(c,d).id];return t.getSubunitRuleList(c,d).filter(g=>g.ranges.some(S=>a.Rectangle.intersects(o,S))).forEach(g=>{u.push(new m.RangeProtectionPermissionEditPoint(c,d,g.permissionId).id)}),r.composePermission(u).some(g=>g.value===!1)}))}function Vl(n,i){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.RangeProtectionRuleModel),o=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,o.permissionPointUpdate$.pipe(me.debounceTime(100))).pipe(me.map(()=>{var g;const s=(g=t.getCurrentLastSelection())==null?void 0:g.range;if(!s)return!0;const l=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),c=l==null?void 0:l.getActiveSheet();if(!l||!c)return!0;const d=l.getUnitId(),u=c.getSheetId(),h=[new m.WorkbookEditablePermission(d).id,new m.WorksheetEditPermission(d,u).id];return r.getSubunitRuleList(d,u).filter(S=>i==="row"?S.ranges.some(f=>s.startRow>f.startRow&&s.startRow<=f.endRow):S.ranges.some(f=>s.startColumn>f.startColumn&&s.startColumn<=f.endColumn)).forEach(S=>{h.push(new m.RangeProtectionPermissionEditPoint(d,u,S.permissionId).id)}),o.composePermission(h).some(S=>S.value===!1)}))}function Wl(n,i){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.RangeProtectionRuleModel),o=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,o.permissionPointUpdate$.pipe(me.debounceTime(100))).pipe(me.map(()=>{var S;const s=(S=t.getCurrentLastSelection())==null?void 0:S.range;if(!s)return!0;const l=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),c=l==null?void 0:l.getActiveSheet();if(!l||!c)return!0;const d=l.getUnitId(),u=c.getSheetId(),h=[new m.WorkbookEditablePermission(d).id,new m.WorksheetEditPermission(d,u).id],g=a.Tools.deepClone(s);return i==="row"?(g.startColumn=0,g.endColumn=c.getColumnCount()-1):(g.startRow=0,g.endRow=c.getRowCount()-1),r.getSubunitRuleList(d,u).filter(f=>f.ranges.some(p=>a.Rectangle.intersects(g,p))).forEach(f=>{h.push(new m.RangeProtectionPermissionEditPoint(d,u,f.permissionId).id)}),o.composePermission(h).some(f=>f.value===!1)}))}function Bi(n,i){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.RangeProtectionRuleModel),o=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,o.permissionPointUpdate$.pipe(me.debounceTime(100))).pipe(me.map(()=>{var S;const s=(S=t.getCurrentLastSelection())==null?void 0:S.range;if(!s)return!0;const l=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),c=l==null?void 0:l.getActiveSheet();if(!l||!c)return!0;const d=l.getUnitId(),u=c.getSheetId(),h=[new m.WorkbookEditablePermission(d).id,new m.WorksheetEditPermission(d,u).id],g=a.Tools.deepClone(s);return i==="row"?g.endRow=c.getRowCount()-1:g.endColumn=c.getColumnCount()-1,r.getSubunitRuleList(d,u).filter(f=>f.ranges.some(p=>a.Rectangle.intersects(g,p))).forEach(f=>{h.push(new m.RangeProtectionPermissionEditPoint(d,u,f.permissionId).id)}),o.composePermission(h).some(f=>f.value===!1)}))}function Hn(n,i){const t=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(m.WorksheetProtectionRuleModel),o=n.get(m.RangeProtectionRuleModel),s=n.get(a.IPermissionService),l=n.get(a.UserManagerService);return O.combineLatest([l.currentUser$,t]).pipe(me.switchMap(([c,d])=>d?d.activeSheet$.pipe(me.switchMap(u=>{if(!u)return O.of(!0);const h=d.getUnitId(),g=[];return i.forEach(f=>g.push(new f(h).id)),s.composePermission$(g).pipe(me.map(f=>f.every(p=>p.value===!0))).pipe(me.map(f=>{if(!f)return!0;const p=u.getSheetId(),v=r.getRule(h,p),C=o.getSubunitRuleList(h,p);return!!(v||C.length)}))})):O.of(!0)))}var Ul=(n=>(n.ROW_HEADER_CONTEXT_MENU="ROW_HEADER_CONTEXT_MENU",n.COL_HEADER_CONTEXT_MENU="COL_HEADER_CONTEXT_MENU",n.SHEET_BAR="SHEET_BAR",n.SHEET_FOOTER="SHEET_FOOTER",n))(Ul||{});function pg(n){const i=n.get(et);return{id:kn.id,subId:Vi.id,type:_.MenuItemType.BUTTON,icon:"BrushSingle",title:"Format Painter",tooltip:"toolbar.formatPainter",activated$:new O.Observable(e=>{let t=!1;const r=i.status$.subscribe(o=>{t=o!==Ne.OFF,e.next(t)});return e.next(t),()=>{r.unsubscribe()}}),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetCopyPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0)}}function vg(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(a.IContextService),r=n.get(m.SheetsSelectionsService);return{id:Qt.id,type:_.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:be(e,!1,({worksheet:o})=>new O.Observable(s=>{var u;const l=i.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const p=(S=r.getCurrentLastSelection())==null?void 0:S.primary;let v=a.FontWeight.NORMAL;if(p!=null){const C=o.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getFontWeight()}s.next(v===a.FontWeight.BOLD)}if((g===Re.SetTextSelectionsOperation.id||g===$.SetInlineFormatCommand.id)&&t.getContextValue(a.EDITOR_ACTIVATED)&&t.getContextValue(a.FOCUSING_SHEET)){const p=yr(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.bl;s.next(v===a.BooleanNumber.TRUE)}}),c=(u=r.getCurrentLastSelection())==null?void 0:u.primary;if(!o){s.next(!1);return}let d=a.FontWeight.NORMAL;if(c!=null){const h=o.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getFontWeight()}return s.next(d===a.FontWeight.BOLD),l.dispose})),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Cg(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService);return{id:Jt.id,type:_.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:be(e,!1,({worksheet:o})=>new O.Observable(s=>{var u;const l=i.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const p=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let v=a.FontItalic.NORMAL;if(p!=null){const C=o.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getFontStyle()}s.next(v===a.FontItalic.ITALIC)}if((g===Re.SetTextSelectionsOperation.id||g===$.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const p=yr(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.it;s.next(v===a.BooleanNumber.TRUE)}}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d=a.FontItalic.NORMAL;if(c!=null){const h=o.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getFontStyle()}return s.next(d===a.FontItalic.ITALIC),l.dispose})),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function _g(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService);return{id:$t.id,type:_.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",activated$:be(e,!1,({worksheet:o})=>new O.Observable(s=>{var u;const l=i.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const p=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let v;if(p!=null){const C=o.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getUnderline()}s.next(!!(v&&v.s))}if((g===Re.SetTextSelectionsOperation.id||g===$.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const p=yr(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.ul;s.next((v==null?void 0:v.s)===a.BooleanNumber.TRUE)}}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d;if(c!=null){const h=o.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getUnderline()}return s.next(!!(d&&d.s)),l.dispose})),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Ig(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService);return{id:en.id,type:_.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:be(e,!1,({worksheet:o})=>new O.Observable(s=>{var u;const l=i.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const p=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let v;if(p!=null){const C=o.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getStrikeThrough()}s.next(!!(v&&v.s))}if((g===Re.SetTextSelectionsOperation.id||g===$.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const p=yr(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.st;s.next((v==null?void 0:v.s)===a.BooleanNumber.TRUE)}}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d;if(c!=null){const h=o.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getStrikeThrough()}return s.next(!!(d&&d.s)),l.dispose})),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function bg(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=a.DEFAULT_STYLES.ff;return{id:Cr.id,tooltip:"toolbar.font",type:_.MenuItemType.SELECTOR,label:Wi,selections:_.FONT_FAMILY_LIST.map(o=>({label:{name:Ui},value:o.value})),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),value$:be(e,r,({worksheet:o})=>new O.Observable(s=>{var u;const l=i.onCommandExecuted(h=>{var p;const g=h.id;if(g!==m.SetRangeValuesMutation.id&&g!==m.SetSelectionsOperation.id&&g!==m.SetWorksheetActiveOperation.id)return;const S=(p=t.getCurrentLastSelection())==null?void 0:p.primary;let f;if(S!=null){const v=o.getRange(S.startRow,S.startColumn);f=v==null?void 0:v.getFontFamily()}s.next(f!=null?f:r)}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d;if(c!=null){const h=o.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getFontFamily()}return s.next(d!=null?d:r),l.dispose})),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Rg(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService),o=a.DEFAULT_STYLES.fs,s=te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0);return{id:vr.id,type:_.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Li,props:{min:1,max:400,disabled$:s}},selections:_.FONT_SIZE_LIST,disabled$:s,value$:be(e,o,({worksheet:l})=>new O.Observable(c=>{var g;const d=i.onCommandExecuted(S=>{var p,v;const f=S.id;if(f===m.SetRangeValuesMutation.id||f===m.SetSelectionsOperation.id||f===m.SetWorksheetActiveOperation.id){const C=(p=t.getCurrentLastSelection())==null?void 0:p.primary;let b;if(C!=null){const R=l.getRange(C.startRow,C.startColumn);b=R==null?void 0:R.getFontSize()}c.next(b!=null?b:o)}if((f===Re.SetTextSelectionsOperation.id||f===$.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const C=yr(n);if(C==null)return;const b=(v=C.ts)==null?void 0:v.fs;c.next(b!=null?b:o)}}),u=(g=t.getCurrentLastSelection())==null?void 0:g.primary;let h;if(u!=null){const S=l.getRange(u.startRow,u.startColumn);h=S==null?void 0:S.getFontSize()}return c.next(h!=null?h:o),d.dispose})),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Eg(n){return{id:xs.id,type:_.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function wg(n){const i=n.get(a.ICommandService),e=n.get(a.ThemeService);return{id:Tn.id,icon:"FontColor",tooltip:"toolbar.textColor.main",type:_.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:wr,hoverable:!1,selectable:!1}}],value$:new O.Observable(t=>{const r=e.getCurrentTheme().textColor,o=i.onCommandExecuted(s=>{if(s.id===Tn.id){const l=s.params.value;t.next(l!=null?l:r)}});return t.next(r),o.dispose}),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0)}}function Tg(n){return{id:m.ResetBackgroundColorCommand.id,type:_.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function yg(n){const i=n.get(a.ICommandService),e=n.get(a.ThemeService);return{id:m.SetBackgroundColorCommand.id,tooltip:"toolbar.fillColor.main",type:_.MenuItemType.BUTTON_SELECTOR,icon:"PaintBucket",selections:[{label:{name:wr,hoverable:!1,selectable:!1}}],value$:new O.Observable(t=>{const r=e.getCurrentTheme().primaryColor,o=i.onCommandExecuted(s=>{if(s.id===m.SetBackgroundColorCommand.id){const l=s.params.value;t.next(l!=null?l:r)}});return t.next(r),o.dispose}),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const pa=[{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 Mg(n){const i=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=a.HorizontalAlign.LEFT;return{id:m.SetHorizontalTextAlignCommand.id,icon:pa[0].icon,tooltip:"toolbar.horizontalAlignMode.main",type:_.MenuItemType.SELECTOR,selections:pa,value$:be(i,t,({worksheet:r})=>new O.Observable(o=>{var d;const s=n.get(a.ICommandService).onCommandExecuted(u=>{var f;const h=u.id;if(h!==m.SetHorizontalTextAlignCommand.id&&h!==m.SetSelectionsOperation.id&&h!==m.SetWorksheetActiveOperation.id)return;const g=(f=e.getCurrentLastSelection())==null?void 0:f.primary;let S;if(g!=null){const p=r.getRange(g.startRow,g.startColumn);S=p==null?void 0:p.getHorizontalAlignment()}o.next(S!=null?S:t)}),l=(d=e.getCurrentLastSelection())==null?void 0:d.primary;let c;if(l!=null){const u=r.getRange(l.startRow,l.startColumn);c=u==null?void 0:u.getHorizontalAlignment()}return o.next(c!=null?c:t),s.dispose})),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const va=[{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 Pg(n){const i=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=a.VerticalAlign.BOTTOM;return{id:m.SetVerticalTextAlignCommand.id,icon:va[2].icon,tooltip:"toolbar.verticalAlignMode.main",type:_.MenuItemType.SELECTOR,selections:va,value$:be(i,t,({worksheet:r})=>new O.Observable(o=>{var d;const s=n.get(a.ICommandService).onCommandExecuted(u=>{var f;const h=u.id;if(h!==m.SetVerticalTextAlignCommand.id&&h!==m.SetSelectionsOperation.id&&h!==m.SetWorksheetActiveOperation.id)return;const g=(f=e.getCurrentLastSelection())==null?void 0:f.primary;let S;if(g!=null){const p=r.getRange(g.startRow,g.startColumn);S=p==null?void 0:p.getVerticalAlignment()}o.next(S!=null?S:t)}),l=(d=e.getCurrentLastSelection())==null?void 0:d.primary;let c;if(l!=null){const u=r.getRange(l.startRow,l.startColumn);c=u==null?void 0:u.getVerticalAlignment()}return o.next(c!=null?c:t),s.dispose})),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const Ca=[{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 Og(n){const i=n.get(m.SheetsSelectionsService),e=n.get(a.IUniverInstanceService),t=a.WrapStrategy.OVERFLOW;return{id:m.SetTextWrapCommand.id,tooltip:"toolbar.textWrapMode.main",icon:Ca[0].icon,type:_.MenuItemType.SELECTOR,selections:Ca,value$:be(e,t,({worksheet:r})=>new O.Observable(o=>{var d;const s=n.get(a.ICommandService).onCommandExecuted(u=>{var f;const h=u.id;if(h!==m.SetTextWrapCommand.id&&h!==m.SetSelectionsOperation.id&&h!==m.SetWorksheetActiveOperation.id)return;const g=(f=i.getCurrentLastSelection())==null?void 0:f.primary;let S;if(g!=null){const p=r.getRange(g.startRow,g.startColumn);S=p==null?void 0:p.getWrapStrategy()}o.next(S!=null?S:t)}),l=(d=i.getCurrentLastSelection())==null?void 0:d.primary;let c;if(l!=null){const u=r.getRange(l.startRow,l.startColumn);c=u==null?void 0:u.getWrapStrategy()}return o.next(c!=null?c:t),s.dispose})),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const _a=[{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 xg(n){const i=n.get(m.SheetsSelectionsService),e=n.get(a.IUniverInstanceService),t=0;return{id:m.SetTextRotationCommand.id,tooltip:"toolbar.textRotateMode.main",icon:_a[0].icon,type:_.MenuItemType.SELECTOR,selections:_a,value$:be(e,t,({worksheet:r})=>new O.Observable(o=>{var d,u;const s=n.get(a.ICommandService).onCommandExecuted(h=>{var p,v;const g=h.id;if(g!==m.SetTextRotationCommand.id&&g!==m.SetSelectionsOperation.id&&g!==m.SetWorksheetActiveOperation.id)return;const S=(p=i.getCurrentLastSelection())==null?void 0:p.primary;let f;if(S!=null){const C=r.getRange(S.startRow,S.startColumn);f=C==null?void 0:C.getTextRotation()}(f==null?void 0:f.v)===a.BooleanNumber.TRUE?o.next("v"):o.next((v=f&&f.a)!=null?v:t)}),l=(d=i.getCurrentLastSelection())==null?void 0:d.primary;let c;if(l!=null){const h=r.getRange(l.startRow,l.startColumn);c=h==null?void 0:h.getTextRotation()}return(c==null?void 0:c.v)===a.BooleanNumber.TRUE?o.next("v"):o.next((u=c&&c.a)!=null?u:t),s.dispose})),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Tr(n){return new O.Observable(e=>e.next(!n.get(_.IClipboardInterfaceService).supportClipboard))}function pn(n){return{id:Xe.name,commandId:Xe.id,type:_.MenuItemType.BUTTON,title:"rightClick.copy",icon:"Copy",disabled$:te(n,{workbookTypes:[m.WorkbookCopyPermission],worksheetTypes:[m.WorksheetCopyPermission],rangeTypes:[m.RangeProtectionPermissionViewPoint]}),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function qi(n){return{id:Ye.name,commandId:Ye.id,type:_.MenuItemType.BUTTON,title:"rightClick.paste",icon:"PasteSpecial",disabled$:Tr(n).pipe(O.combineLatestWith(te(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission,m.WorksheetSetCellValuePermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([i,e])=>i||e)),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Jn="sheet.menu.paste-special";function Qi(n){return{id:Jn,type:_.MenuItemType.SUBITEMS,icon:"PasteSpecial",title:"rightClick.pasteSpecial",hidden$:tn(n,_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET))}}function Ji(n){return{id:gn.id,type:_.MenuItemType.BUTTON,title:"rightClick.pasteValue",disabled$:Tr(n).pipe(O.combineLatestWith(te(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellValuePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([i,e])=>i||e)),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function $i(n){return{id:Sn.id,type:_.MenuItemType.BUTTON,title:"rightClick.pasteFormat",disabled$:Tr(n).pipe(O.combineLatestWith(te(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellStylePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([i,e])=>i||e)),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function eo(n){return{id:Vt.id,type:_.MenuItemType.BUTTON,title:"rightClick.pasteColWidth",disabled$:Tr(n).pipe(O.combineLatestWith(te(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetColumnStylePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([i,e])=>i||e))}}function to(n){return{id:fn.id,type:_.MenuItemType.BUTTON,title:"rightClick.pasteBesidesBorder",disabled$:Tr(n).pipe(O.combineLatestWith(te(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission,m.WorksheetSetCellValuePermission,m.WorksheetSetRowStylePermission,m.WorksheetSetColumnStylePermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([i,e])=>i||e)),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Ag(n){return{id:m.SetWorksheetRowIsAutoHeightCommand.id,type:_.MenuItemType.BUTTON,icon:"AutoHeight",title:"rightClick.fitContent",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function kg(n){return{id:Er.id,type:_.MenuItemType.BUTTON,icon:"AutoWidth",title:"rightClick.fitContent",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Ll="sheet.menu.sheet-frozen";function Ng(n){return{id:Ll,type:_.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Yo="sheet.header-menu.sheet-frozen";function Ia(n){return{id:Yo,type:_.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function no(n){return{id:ht.id,type:_.MenuItemType.BUTTON,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Dg(n){return{id:br.id,type:_.MenuItemType.BUTTON,title:"rightClick.freezeRow",icon:"FreezeRowSingle",hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Hg(n){return{id:Rr.id,type:_.MenuItemType.BUTTON,title:"rightClick.freezeCol",icon:"FreezeColumnSingle",hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function ro(n){return{id:m.CancelFrozenCommand.id,type:_.MenuItemType.BUTTON,title:"rightClick.cancelFreeze",icon:"CancelFreezeSingle",hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Vg(n){return{id:fr.id,type:_.MenuItemType.BUTTON,icon:"Hide",title:"rightClick.hideSelectedRow",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Wg(n){return{id:pr.id,type:_.MenuItemType.BUTTON,icon:"Hide",title:"rightClick.hideSelectedColumn",disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Ug(n){const i=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=[m.SetSelectionsOperation,m.SetRowHiddenMutation,m.SetRowVisibleMutation].map(o=>o.id);return{id:m.SetSelectedRowsVisibleCommand.id,type:_.MenuItemType.BUTTON,title:"rightClick.showHideRow",hidden$:be(i,!0,({worksheet:o})=>new O.Observable(s=>{function l(){var u;const d=(u=e.getCurrentSelections())==null?void 0:u.map(h=>h.range).filter(h=>h.rangeType===a.RANGE_TYPE.ROW);return!!(d!=null&&d.some(h=>{for(let g=h.startRow;g<=h.endRow;g++)if(!o.getRowRawVisible(g))return!0;return!1}))}const c=t.onCommandExecuted(d=>{r.findIndex(u=>u===d.id)!==-1&&s.next(!l())});return s.next(!l()),()=>c.dispose()})),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetRowStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Lg(n){const i=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=[m.SetSelectionsOperation,m.SetColHiddenMutation,m.SetColVisibleMutation].map(o=>o.id);return{id:m.SetSelectedColsVisibleCommand.id,type:_.MenuItemType.BUTTON,title:"rightClick.showHideColumn",hidden$:be(i,!0,({worksheet:o})=>new O.Observable(s=>{function l(){var u;const d=(u=e.getCurrentSelections())==null?void 0:u.map(h=>h.range).filter(h=>h.rangeType===a.RANGE_TYPE.COLUMN);return!d||d.length===0?!1:!!d.some(h=>{for(let g=h.startColumn;g<=h.endColumn;g++)if(!o.getColVisible(g))return!0;return!1})}const c=t.onCommandExecuted(d=>{r.findIndex(u=>u===d.id)!==-1&&s.next(!l())});return s.next(!l()),()=>c.dispose()})),disabled$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetColumnStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Bg(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=0;return{id:m.SetRowHeightCommand.id,type:_.MenuItemType.BUTTON,icon:"AdjustHeight",label:{name:tt,props:{prefix:"rightClick.rowHeight",suffix:"px",min:2,max:1e3}},value$:be(e,r,({worksheet:o})=>new O.Observable(s=>{function l(){var h;const d=(h=t.getCurrentLastSelection())==null?void 0:h.primary,u=d?o.getRowHeight(d.startRow):r;s.next(u)}const c=i.onCommandExecuted(d=>{const u=d.id;if(u===m.SetRangeValuesMutation.id||u===m.SetSelectionsOperation.id||u===m.SetWorksheetRowIsAutoHeightMutation.id)return l()});return l(),c.dispose})),hidden$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetRowStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Fg(n){const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=0;return{id:m.SetColWidthCommand.id,type:_.MenuItemType.BUTTON,icon:"AdjustWidth",label:{name:tt,props:{prefix:"rightClick.columnWidth",suffix:"px",min:2,max:1e3}},value$:be(e,r,({worksheet:o})=>new O.Observable(s=>{function l(){var h;const d=(h=t.getCurrentLastSelection())==null?void 0:h.primary;let u=r;d!=null&&(u=o.getColumnWidth(d.startColumn)),s.next(u)}const c=i.onCommandExecuted(d=>{const u=d.id;if(u===m.SetRangeValuesMutation.id||u===m.SetSelectionsOperation.id||u===m.SetWorksheetColWidthMutation.id)return l()});return l(),c.dispose})),hidden$:te(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function yr(n){var c;const i=n.get(a.IUniverInstanceService),e=n.get(Re.DocSelectionManagerService),t=i.getUniverDocInstance(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),r=e.getActiveTextRange();if(t==null||r==null)return null;const o=(c=t.getBody())==null?void 0:c.textRuns;if(o==null)return;const{startOffset:s}=r;return o.find(({st:d,ed:u})=>s>=d&&s<=u)}var jg=Object.getOwnPropertyDescriptor,zg=(n,i,e,t)=>{for(var r=t>1?void 0:t?jg(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=s(r)||r);return r},xt=(n,i)=>(e,t)=>i(e,t,n);const Xg="__SpreadsheetFreezeRowMainName__",Yg="__SpreadsheetFreezeRowHeaderName__",Gg="__SpreadsheetFreezeColumnMainName__",Zg="__SpreadsheetFreezeColumnHeaderName__",io=2,Kg=.01,Fn=a.createInterceptorKey("freezePermissionCheck");exports.HeaderFreezeRenderController=class extends a.Disposable{constructor(e,t,r,o,s,l,c,d){super();E(this,"_rowFreezeHeaderRect");E(this,"_rowFreezeMainRect");E(this,"_columnFreezeHeaderRect");E(this,"_columnFreezeMainRect");E(this,"_freezeDownSubs");E(this,"_freezePointerEnterSubs");E(this,"_freezePointerLeaveSubs");E(this,"_scenePointerMoveSub");E(this,"_scenePointerUpSub");E(this,"_changeToRow",-1);E(this,"_changeToColumn",-1);E(this,"_changeToOffsetX",0);E(this,"_changeToOffsetY",0);E(this,"_activeViewport",null);E(this,"_freezeNormalHeaderColor","");E(this,"_freezeNormalMainColor","");E(this,"_freezeActiveColor","");E(this,"_freezeHoverColor","");E(this,"_lastFreeze");E(this,"interceptor",new a.InterceptorManager({FREEZE_PERMISSION_CHECK:Fn}));this._context=e,this._sheetSkeletonManagerService=t,this._commandService=r,this._selectionManagerService=o,this._scrollManagerService=s,this._themeService=l,this._sheetInterceptorService=c,this._injector=d,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._themeChangeListener(),this._interceptorCommands(),this._bindViewportScroll(),this._zoomRefresh()}_createFreeze(e=0,t){var x;const r=t!=null?t:this._getFreeze();if(r==null)return null;const o=(x=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:x.skeleton,{startRow:s,startColumn:l}=r,c=this._getPositionByIndex(s,l);if(c==null||o==null)return null;const d=this._getSheetObject(),u=d.engine,h=(u==null?void 0:u.width)||0,g=(u==null?void 0:u.height)||0,S=d.scene,{startX:f,startY:p}=c,{rowTotalHeight:v,columnTotalWidth:C,rowHeaderWidthAndMarginLeft:b,columnHeaderHeightAndMarginTop:R}=o,w=h>C+b?h:C+R,M=g>v+R?g:v+R;this._changeToRow=s,this._changeToColumn=l,this._changeToOffsetX=f,this._changeToOffsetY=p;const y=Math.max(S.scaleX,S.scaleY);let P=io/(y<1?1:y);if(e===0){(s===-1||s===0)&&(P=P*2);const A=P;this._rowFreezeHeaderRect=new T.Rect(Yg,{fill:this._freezeNormalHeaderColor,width:b,height:P,left:0,top:p-A,zIndex:3});let k=this._freezeNormalHeaderColor;(s===-1||s===0)&&(k=this._freezeNormalMainColor),this._rowFreezeMainRect=new T.Rect(Xg,{fill:k,width:w*2/y,height:P,left:b,top:p-A,zIndex:3}),S.addObjects([this._rowFreezeHeaderRect,this._rowFreezeMainRect],bt)}else{(l===-1||l===0)&&(P=P*2);const A=P;this._columnFreezeHeaderRect=new T.Rect(Zg,{fill:this._freezeNormalHeaderColor,width:P,height:R,left:f-A,top:0,zIndex:3});let k=this._freezeNormalHeaderColor;(l===-1||l===0)&&(k=this._freezeNormalMainColor),this._columnFreezeMainRect=new T.Rect(Gg,{fill:k,width:P,height:M*2/y,left:f-A,top:R,zIndex:3}),S.addObjects([this._columnFreezeHeaderRect,this._columnFreezeMainRect],bt)}this._eventBinding(e)}_eventBinding(e=0){let t=this._rowFreezeHeaderRect,r=this._rowFreezeMainRect;e===1&&(t=this._columnFreezeHeaderRect,r=this._columnFreezeMainRect);const o=this._getSheetObject();if(o==null)return;const{scene:s}=o;if(this._freezePointerEnterSubs=new O.Subscription,this._freezePointerLeaveSubs=new O.Subscription,this._freezeDownSubs=new O.Subscription,r){const d=r.onPointerEnter$.subscribeEvent(()=>{if(!this.interceptor.fetchThroughInterceptors(Fn)(!0,null))return!1;t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),s.setCursor(T.CURSOR_TYPE.GRAB)});this._freezePointerEnterSubs.add(d);const u=r.onPointerLeave$.subscribeEvent(()=>{t==null||t.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),s.resetCursor()});this._freezePointerLeaveSubs.add(u)}if(t){const d=t.onPointerEnter$.subscribeEvent(()=>{if(!this.interceptor.fetchThroughInterceptors(Fn)(!0,null))return!1;t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),s.setCursor(T.CURSOR_TYPE.GRAB)});this._freezePointerEnterSubs.add(d);const u=t.onPointerLeave$.subscribeEvent(()=>{t==null||t.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),s.resetCursor()});this._freezePointerLeaveSubs.add(u)}const l=t==null?void 0:t.onPointerDown$.subscribeEvent(d=>{this._freezeDown(d,t,r,e)});l&&this._freezeDownSubs.add(l);const c=r==null?void 0:r.onPointerDown$.subscribeEvent(d=>{this._freezeDown(d,t,r,e)});c&&this._freezeDownSubs.add(c)}_getCurrentLastVisible(){var C,b,R,w,M,y,P;const e=this._getSheetObject();if(e==null)return;const t=(C=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:C.skeleton;if(t==null)return;const r=e.scene,o=Math.max(r.scaleX,r.scaleY),s=this._scrollManagerService.getCurrentScrollState(),l=(e.engine.height-t.columnHeaderHeight)/o,c=(e.engine.width-t.rowHeaderWidth)/o,d=(b=s==null?void 0:s.sheetViewStartRow)!=null?b:0,u=d===0?-((R=s==null?void 0:s.offsetY)!=null?R:0):t.rowHeightAccumulation[d-1]-((w=s==null?void 0:s.offsetY)!=null?w:0);let h=0,g=!1;for(let x=d,A=t.rowHeightAccumulation.length;x<A;x++)if(t.rowHeightAccumulation[x]-u>l){h=x,g=!0;break}g||(h=t.rowHeightAccumulation.length-1);const S=(M=s==null?void 0:s.sheetViewStartColumn)!=null?M:0,f=S===0?-((y=s==null?void 0:s.offsetX)!=null?y:0):t.columnWidthAccumulation[S-1]-((P=s==null?void 0:s.offsetX)!=null?P:0);let p=0,v=!1;for(let x=S,A=t.columnWidthAccumulation.length;x<A;x++)if(t.columnWidthAccumulation[x]-f>c){p=x,v=!0;break}return v||(p=t.columnWidthAccumulation.length-1),{lastRow:h,lastColumn:p}}_getActiveViewport(e){var r;const t=(r=this._getSheetObject())==null?void 0:r.scene.getViewports();return t&&t.find(o=>o.isHit(new T.Vector2(e.offsetX,e.offsetY)))||null}_freezeDown(e,t,r,o=0){var f;const s=(f=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:f.skeleton;if(s==null)return;const l=this._getSheetObject();if(l==null)return;if(!this.interceptor.fetchThroughInterceptors(Fn)(!0,null))return!1;const{scene:d}=l;d.setCursor(T.CURSOR_TYPE.GRABBING),d.disableObjectsEvent();const u=this._getCurrentLastVisible(),h=u===void 0?Number.POSITIVE_INFINITY:s.rowHeightAccumulation[u.lastRow],g=u===void 0?Number.POSITIVE_INFINITY:s.columnWidthAccumulation[u.lastColumn-1]+s.rowHeaderWidth;this._activeViewport=null;const S=this._getFreeze();S&&(this._changeToColumn=S.startColumn,this._changeToRow=S.startRow),this._scenePointerMoveSub=d.onPointerMove$.subscribeEvent(p=>{var P,x,A,k;const v=this._getActiveViewport(p),{startX:C,startY:b,row:R,column:w}=qe(p.offsetX,p.offsetY,d,s,v||void 0,!0);if(!this.interceptor.fetchThroughInterceptors(Fn)(!0,null))return!1;d.setCursor(T.CURSOR_TYPE.GRABBING);const y=io/Math.max(d.scaleX,d.scaleY);o===0?((P=t.transformByState({top:Math.min(b,h)-y/2}))==null||P.setProps({fill:this._freezeActiveColor}),(x=r.transformByState({top:Math.min(b,h)-y/2}))==null||x.setProps({fill:this._freezeNormalHeaderColor}),this._changeToRow=u===void 0?R:Math.min(R,u.lastRow),this._changeToOffsetY=Math.min(b,h),this._activeViewport=v):((A=t.transformByState({left:Math.min(C,g)-y/2}))==null||A.setProps({fill:this._freezeActiveColor}),(k=r.transformByState({left:Math.min(C,g)-y/2}))==null||k.setProps({fill:this._freezeNormalHeaderColor}),this._changeToColumn=u===void 0?w:Math.min(w,u.lastColumn),this._changeToOffsetX=C,this._activeViewport=v)}),this._scenePointerUpSub=d.onPointerUp$.subscribeEvent(()=>{var N,H;d.resetCursor(),d.enableObjectsEvent(),this._clearObserverEvent();const{rowHeaderWidthAndMarginLeft:p,columnHeaderHeightAndMarginTop:v}=s;o===0&&(this._changeToRow===0||this._changeToRow===-1)||o===1&&(this._changeToColumn===0||this._changeToColumn===-1)?(t.setProps({fill:this._freezeNormalHeaderColor}),r.setProps({fill:this._freezeNormalMainColor})):(t==null||t.setProps({fill:this._freezeNormalHeaderColor}),r==null||r.setProps({fill:this._freezeNormalHeaderColor}));const C=io/Math.max(d.scaleX,d.scaleY);o===0?(this._changeToRow===0||this._changeToRow===-1)&&(t.transformByState({top:v-C}),r.transformByState({top:v-C})):(this._changeToColumn===0||this._changeToColumn===-1)&&(t.transformByState({left:p-C}),r.transformByState({left:p-C}));const b=this._scrollManagerService.getCurrentScrollState()||{sheetViewStartRow:0,sheetViewStartColumn:0},{sheetViewStartRow:R,sheetViewStartColumn:w}=b;if(w==null||R==null)return;const M=this._context.unit,y=M.getActiveSheet();if(!y)return;const P=(N=y.getConfig())==null?void 0:N.freeze;let x=(P==null?void 0:P.xSplit)||0,A=(P==null?void 0:P.ySplit)||0;const k=(H=this._activeViewport)==null?void 0:H.viewportKey;o===0&&(!k||k===T.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP||k===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP||k===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||k===T.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP?A=this._changeToRow-(P.startRow-P.ySplit):A=this._changeToRow-R,A=A<0?0:A),o===1&&(!k||k===T.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP||k===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP||k===T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||k===T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT?x=this._changeToColumn-(P.startColumn-P.xSplit):x=this._changeToColumn-w,x=x<0?0:x),this._commandService.executeCommand(m.SetFrozenCommand.id,{startRow:A===0?-1:this._changeToRow,startColumn:x===0?-1:this._changeToColumn,ySplit:A,xSplit:x,unitId:M.getUnitId(),subUnitId:y.getSheetId()})})}_getViewports(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e,r=t.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT),o=t.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT),s=t.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP),l=t.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM),c=t.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP),d=t.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN),u=t.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP),h=t.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT),g=t.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(!(r==null||o==null||s==null||l==null||c==null||d==null||u==null||h==null||g==null))return{viewMain:d,viewMainLeftTop:u,viewMainLeft:h,viewMainTop:g,viewColumnLeft:r,viewColumnRight:o,viewRowTop:s,viewRowBottom:l,viewLeftTop:c}}_bindViewportScroll(){const e=this._getViewports();if(!e)return;const{viewRowBottom:t,viewColumnRight:r,viewMainLeft:o,viewMainTop:s}=e;this.disposeWithMe(this._scrollManagerService.validViewportScrollInfo$.subscribe(l=>{if(!l)return;const{scrollX:c,scrollY:d,viewportScrollX:u,viewportScrollY:h}=l;t.isActive&&t.updateScrollVal({scrollY:d,viewportScrollY:h}),r.isActive&&r.updateScrollVal({scrollX:c,viewportScrollX:u}),o.isActive&&o.updateScrollVal({scrollY:d,viewportScrollY:h}),s.isActive&&s.updateScrollVal({scrollX:c,viewportScrollX:u})}))}_updateViewport(e=-1,t=-1,r=0,o=0,s=3){var x;const l=(x=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:x.skeleton;if(l==null)return;const{rowHeaderWidthAndMarginLeft:c,columnHeaderHeightAndMarginTop:d}=l,u=this._getViewports();if(!u)return;const{viewMain:h,viewMainLeftTop:g,viewMainLeft:S,viewMainTop:f,viewColumnLeft:p,viewColumnRight:v,viewRowTop:C,viewRowBottom:b,viewLeftTop:R}=u;v.resizeWhenFreezeChange({left:c,top:0,height:d,right:0}),b.resizeWhenFreezeChange({left:0,top:d,bottom:0,width:c}),R.resizeWhenFreezeChange({left:0,top:0,width:c,height:d});let w=!0,M=!0;g.enable(),(e===-1||e===0)&&(w=!1),(t===-1||t===0)&&(M=!1);const y=l.getNoMergeCellWithCoordByIndex(e-r,t-o,!1),P=l.getNoMergeCellWithCoordByIndex(e,t,!1);if(g.disable(),f.disable(),S.disable(),C.disable(),p.disable(),g.resetPadding(),f.resetPadding(),S.resetPadding(),C.resetPadding(),p.resetPadding(),w===!1&&M===!1)h.resizeWhenFreezeChange({left:c,top:d,bottom:0,right:0}),h.resetPadding(),S.resizeWhenFreezeChange({left:c,top:d,bottom:0,width:0}),f.resizeWhenFreezeChange({left:c,top:d,height:0,right:0}),g.resizeWhenFreezeChange({left:c,top:d,width:0,height:0}),C.resizeWhenFreezeChange({left:0,top:d,width:c,height:0}),p.resizeWhenFreezeChange({left:0,top:0,height:d,width:0});else if(w===!0&&M===!1){const A=P.startY-y.startY;h.resizeWhenFreezeChange({left:c,top:d+A,bottom:0,right:0}),h.setPadding({startY:y.startY,endY:P.startY,startX:0,endX:0}),s&2&&this._commandService.executeCommand(ze.id,{sheetViewStartRow:0,offsetY:0}),f.resizeWhenFreezeChange({left:c,top:d,height:A,right:0}),f.updateScrollVal({viewportScrollY:y.startY,rawScrollX:h.scrollX,viewportScrollX:h.viewportScrollX}),C.resizeWhenFreezeChange({left:0,top:d,width:c,height:A}),C.updateScrollVal({viewportScrollY:y.startY}),b.resizeWhenFreezeChange({left:0,top:d+A,bottom:0,width:c}),f.enable(),C.enable()}else if(w===!1&&M===!0){const A=P.startX-y.startX;h.resizeWhenFreezeChange({left:c+A,top:d,bottom:0,right:0}),h.setPadding({startX:y.startX,endX:P.startX,startY:0,endY:0}),s&1&&this._commandService.executeCommand(ze.id,{sheetViewStartColumn:0,offsetX:0}),S.resizeWhenFreezeChange({left:c,top:d,width:A,bottom:0,right:0}),S.updateScrollVal({viewportScrollX:y.startX,rawScrollY:h.scrollY,viewportScrollY:h.viewportScrollY}),p.resizeWhenFreezeChange({left:c,top:0,width:A,height:d}),p.updateScrollVal({viewportScrollX:y.startX}),v.resizeWhenFreezeChange({left:c+A,top:0,height:d,right:0}),S.enable(),p.enable()}else{const A=P.startX-y.startX,k=P.startY-y.startY;h.resizeWhenFreezeChange({left:c+A,top:d+k,bottom:0,right:0}),h.setPadding({startY:y.startY,endY:P.startY,startX:y.startX,endX:P.startX}),s&&this._commandService.executeCommand(ze.id,{...s&1?{sheetViewStartColumn:0,offsetX:0}:null,...s&2?{sheetViewStartRow:0,offsetY:0}:null}),S.resizeWhenFreezeChange({left:c,top:d+k,width:A,bottom:0}),S.updateScrollVal({viewportScrollX:y.startX,rawScrollY:h.scrollY,viewportScrollY:h.viewportScrollY}),f.resizeWhenFreezeChange({left:c+A,top:d,height:k,right:0}),f.updateScrollVal({viewportScrollY:y.startY,rawScrollX:h.scrollX,viewportScrollX:h.viewportScrollX}),g.resizeWhenFreezeChange({left:c,top:d,width:A,height:k}),g.updateScrollVal({viewportScrollX:y.startX,viewportScrollY:y.startY}),C.resizeWhenFreezeChange({left:0,top:d,width:c,height:k}),C.updateScrollVal({viewportScrollY:y.startY}),b.resizeWhenFreezeChange({left:0,top:d+k,bottom:0,width:c}),p.resizeWhenFreezeChange({left:c,top:0,width:A,height:d}),p.updateScrollVal({viewportScrollX:y.startX}),v.resizeWhenFreezeChange({left:c+A,top:0,height:d,right:0}),g.enable(),f.enable(),S.enable(),C.enable(),p.enable()}}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(e=>{[m.SetWorksheetActiveOperation.id,m.InsertRangeMoveDownCommand.id,m.InsertRangeMoveRightCommand.id].includes((e==null?void 0:e.commandId)||"")&&this._refreshCurrent()})))}_refreshCurrent(){const t=this._context.unit.getActiveSheet();if(!t)return;const r=t.getConfig().freeze,{startRow:o=-1,startColumn:s=-1,ySplit:l=0,xSplit:c=0}=r;this._refreshFreeze(o,s,l,c,0)}_themeChangeListener(){this._themeChange(this._themeService.getCurrentTheme()),this.disposeWithMe(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(Kg).toRgbString(),this._freezeActiveColor=e.primaryColor,this._freezeHoverColor=e.grey500}_interceptorCommands(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{const t={redos:[],undos:[]},r=this._getFreeze();if(!r)return t;const o=s=>{const l=this._context.unit,c=l.getUnitId(),d=l.getActiveSheet();if(!d)return t;const u=d.getSheetId();this._refreshFreeze(s.startRow,s.startColumn,s.ySplit,s.xSplit,0);const h={...s,unitId:c,subUnitId:u,resetScroll:!1},g=m.SetFrozenMutationFactory(this._injector,h);return{undos:[{id:m.SetFrozenMutation.id,params:g}],redos:[{id:m.SetFrozenMutation.id,params:h}]}};if(e.id===m.InsertRowCommand.id){const s=e.params,{range:l,direction:c}=s,d=l.endRow-l.startRow+1;if(l.startRow+1<r.startRow||l.startRow+1===r.startRow&&c===a.Direction.UP){const u={...r,startRow:Math.max(1,r.startRow+d),ySplit:Math.max(1,r.ySplit+d)};return o(u)}}if(e.id===m.InsertColCommand.id){const s=e.params,{range:l,direction:c}=s,d=l.endColumn-l.startColumn+1;if(l.startColumn+1<r.startColumn||l.startColumn+1===r.startColumn&&c===a.Direction.LEFT){const u={...r,startColumn:Math.max(1,r.startColumn+d),xSplit:Math.max(1,r.xSplit+d)};return o(u)}}if(e.id===m.MoveColsCommand.id){const s=this._selectionManagerService.getCurrentSelections(),{fromRange:{startColumn:l},toRange:{startColumn:c}}=e.params,d=s==null?void 0:s.filter(C=>C.range.rangeType===a.RANGE_TYPE.COLUMN&&C.range.startColumn<=l&&l<=C.range.endColumn);if(!(d!=null&&d.length))return t;const u=d[0].range,h={...u,startColumn:c,endColumn:c+u.endColumn-u.startColumn};if(!r||r.startColumn<=0||u.startColumn>=r.startColumn&&h.startColumn>=r.startColumn||u.startColumn===h.startColumn||u.endColumn<r.startColumn&&h.startColumn<r.startColumn)return t;const g=u.endColumn-u.startColumn+1,S=Math.max(Math.min(r.startColumn,u.endColumn+1)-u.startColumn,0);let f,p;h.startColumn>=r.startColumn?(f=Math.max(r.startColumn-S,1),p=Math.max(r.xSplit-S,1)):(f=r.startColumn+g-S,p=r.xSplit+g-S);const v={...r,startColumn:f,xSplit:p};return o(v)}if(e.id===m.MoveRowsCommand.id){const s=this._selectionManagerService.getCurrentSelections(),{fromRange:{startRow:l},toRange:{startRow:c}}=e.params,d=s==null?void 0:s.filter(C=>C.range.rangeType===a.RANGE_TYPE.ROW&&C.range.startRow<=l&&l<=C.range.endRow);if(!(d!=null&&d.length))return t;const u=d[0].range,h={...u,startRow:c,endRow:c+u.endRow-u.startRow};if(!r||r.startRow<=0||u.startRow>=r.startRow&&h.startRow>=r.startRow||u.startRow===h.startRow||u.endRow<r.startRow&&h.startRow<r.startRow)return t;const g=u.endRow-u.startRow+1,S=Math.max(Math.min(r.startRow,u.endRow+1)-u.startRow,0);let f,p;h.startRow>=r.startRow?(f=Math.max(r.startRow-S,1),p=Math.max(r.ySplit-S,1)):(f=r.startRow+g-S,p=r.ySplit+g-S);const v={...r,startRow:f,ySplit:p};return o(v)}if(e.id===m.RemoveColCommand.id||e.id===m.RemoveRowCommand.id){const s=e.params,l=s.range;if(l.rangeType===a.RANGE_TYPE.COLUMN&&l.startColumn<r.startColumn){const c=Math.min(r.startColumn,l.endColumn+1)-l.startColumn,d={...r,startColumn:Math.max(1,r.startColumn-c),xSplit:Math.max(1,r.xSplit-c)};return o(d)}if(s.range.rangeType===a.RANGE_TYPE.ROW&&l.startRow<r.startRow){const c=Math.min(r.startRow,l.endRow+1)-l.startRow,d={...r,startRow:Math.max(1,r.startRow-c),ySplit:Math.max(1,r.ySplit-c)};return o(d)}}return t}}))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{switch(e.id){case m.SetFrozenMutation.id:case Le.id:{const t=this._lastFreeze,r=this._context.unit,o=r.getActiveSheet(),s=e.params,{unitId:l,subUnitId:c}=s;if(!(l===r.getUnitId()&&c===(o==null?void 0:o.getSheetId())))return;const d=o.getConfig().freeze;if(this._lastFreeze=d,d==null)return;let u=0;const{startRow:h=-1,startColumn:g=-1,ySplit:S=0,xSplit:f=0}=d;(!t||t.startRow!==h||t.ySplit!==S)&&(u|=2),(!t||t.startColumn!==g||t.xSplit!==f)&&(u|=1),s.resetScroll===!1&&(u=0),this._refreshFreeze(h,g,S,f,u)}break;case m.SetWorksheetRowHeightMutation.id:{const t=this._getFreeze(),r=t&&e.params.ranges.some(o=>o.startRow<t.startRow);e.params&&r&&this._refreshCurrent()}break;case m.SetWorksheetColWidthMutation.id:{const t=this._getFreeze();e.params&&t&&e.params.ranges.some(r=>r.startColumn<t.startColumn)&&this._refreshCurrent()}break;case m.SetWorksheetRowAutoHeightMutation.id:{const t=e.params,r=this._getFreeze();if(r&&r.startRow>-1&&t.rowsAutoHeightInfo.some(o=>o.row<r.startRow)){const o=this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._refreshCurrent(),setTimeout(()=>{o.unsubscribe()})})}}break;case m.SetColHiddenMutation.id:case m.SetColVisibleMutation.id:{const t=e.params,r=this._getFreeze(),o=t.ranges;r&&r.startColumn>-1&&o.some(s=>s.startColumn<r.startColumn)&&this._refreshCurrent()}break;case m.SetRowHiddenMutation.id:case m.SetRowVisibleMutation.id:{const t=e.params,r=this._getFreeze(),o=t.ranges;r&&r.startRow>-1&&o.some(s=>s.startRow<r.startRow)&&this._refreshCurrent()}break;case Oi.id:case xi.id:this._refreshCurrent()}}))}_zoomRefresh(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;this.disposeWithMe(t.onTransformChange$.subscribeEvent(r=>{[T.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale,T.TRANSFORM_CHANGE_OBSERVABLE_TYPE.all].includes(r.type)&&this._refreshCurrent()}))}_clearObserverEvent(){var t,r;this._getSheetObject()!=null&&((t=this._scenePointerMoveSub)==null||t.unsubscribe(),(r=this._scenePointerUpSub)==null||r.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null)}_clearFreeze(){var t,r,o,s,l,c;(t=this._rowFreezeHeaderRect)==null||t.dispose(),(r=this._rowFreezeMainRect)==null||r.dispose(),(o=this._columnFreezeHeaderRect)==null||o.dispose(),(s=this._columnFreezeMainRect)==null||s.dispose(),this._getSheetObject()!=null&&([this._freezeDownSubs,this._freezePointerEnterSubs,this._freezePointerLeaveSubs].forEach(d=>{d==null||d.unsubscribe()}),this._freezeDownSubs=null,this._freezePointerEnterSubs=null,this._freezePointerLeaveSubs=null,(l=this._scenePointerMoveSub)==null||l.unsubscribe(),(c=this._scenePointerUpSub)==null||c.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null)}_getPositionByIndex(e,t){var d;if(this._getSheetObject()==null)return;const o=(d=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:d.skeleton,s=o==null?void 0:o.getNoMergeCellWithCoordByIndex(e,t);if(o==null)return;if(s!=null&&(!isNaN(s.endX)||!isNaN(s.endY)))return s;const{rowHeaderWidthAndMarginLeft:l,columnHeaderHeightAndMarginTop:c}=o;return{startX:l,endX:l,startY:c,endY:c}}_getFreeze(){var t;const e=(t=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:t.skeleton.getWorksheetConfig();if(e!=null)return e.freeze}_getSheetObject(){return Ge(this._context.unit,this._context)}_refreshFreeze(e,t,r,o,s){var c;const l={startRow:e,startColumn:t,ySplit:r,xSplit:o};this._clearFreeze(),this._createFreeze(0,l),this._createFreeze(1,l),this._updateViewport(e,t,r,o,s),(c=this._getSheetObject())==null||c.spreadsheet.makeForceDirty()}};exports.HeaderFreezeRenderController=zg([xt(1,a.Inject(exports.SheetSkeletonManagerService)),xt(2,a.ICommandService),xt(3,a.Inject(m.SheetsSelectionsService)),xt(4,a.Inject(exports.SheetScrollManagerService)),xt(5,a.Inject(a.ThemeService)),xt(6,a.Inject(m.SheetInterceptorService)),xt(7,a.Inject(a.Injector))],exports.HeaderFreezeRenderController);function qg(n){const i=n.get(m.SheetsSelectionsService),e=n.get(m.RangeProtectionRuleModel),t=n.get(a.IUniverInstanceService),r=n.get(m.MergeCellController),o=t.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET);return O.combineLatest([i.selectionMoveEnd$,o.pipe(O.map(s=>{var l;return(l=s==null?void 0:s.getUnitId())!=null?l:""})),o.pipe(O.switchMap(s=>{var l;return(l=s==null?void 0:s.activeSheet$)!=null?l:O.of(null)}))]).pipe(O.map(([s,l,c])=>{if(!c||!s||s.length===0)return!1;const d=c.getSheetId(),u=s.map(S=>S.range);if(r.interceptor.fetchThroughInterceptors(m.MERGE_CELL_INTERCEPTOR_CHECK)(!1,u))return!0;const g=e.getSubunitRuleList(l,d).map(S=>S.ranges).flat();if(s.length<2){const S=s[0].range;return g.some(p=>a.Rectangle.intersects(p,S)&&!a.Rectangle.contains(p,S))}for(let S=0;S<s.length;S++)for(let f=S+1;f<s.length;f++)if(a.Rectangle.intersects(s[S].range,s[f].range))return!0;return!1}))}function Bl(n,i){return!!ir(n,i,a.RANGE_TYPE.ROW)}function Fl(n,i){return!!ir(n,i,a.RANGE_TYPE.COLUMN)}function ir(n,i,e){return n.find(r=>{const o=r.range,{startRow:s,endRow:l,startColumn:c,endColumn:d,rangeType:u}=o;return u===a.RANGE_TYPE.ALL||u===a.RANGE_TYPE.NORMAL?!1:u===e&&(e===a.RANGE_TYPE.COLUMN&&c<=i&&i<=d||e===a.RANGE_TYPE.ROW&&s<=i&&i<=l)})}var Qg=Object.getOwnPropertyDescriptor,Jg=(n,i,e,t)=>{for(var r=t>1?void 0:t?Qg(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=s(r)||r);return r},oo=(n,i)=>(e,t)=>i(e,t,n);const $g="__SpreadsheetHeaderMoveControllerBackground__",eS="__SpreadsheetHeaderMoveControllerShapeLine__",tS="rgba(0, 0, 0, 0.1)",nS="rgb(119, 119, 119)",rS=4,so=a.createInterceptorKey("headerMovePermissionCheck");exports.HeaderMoveRenderController=class extends a.Disposable{constructor(e,t,r,o){super();E(this,"_startOffsetX",Number.NEGATIVE_INFINITY);E(this,"_startOffsetY",Number.NEGATIVE_INFINITY);E(this,"_moveHelperBackgroundShape");E(this,"_moveHelperLineShape");E(this,"_headerPointerDownSubs");E(this,"_headerPointerMoveSubs");E(this,"_headerPointerLeaveSubs");E(this,"_dragHeaderMoveSub");E(this,"_scenePointerUpSub");E(this,"_scrollTimer");E(this,"_changeFromColumn",-1);E(this,"_changeFromRow",-1);E(this,"_changeToColumn",-1);E(this,"_changeToRow",-1);E(this,"interceptor",new a.InterceptorManager({HEADER_MOVE_PERMISSION_CHECK:so}));E(this,"_workbookSelections");this._context=e,this._sheetSkeletonManagerService=r,this._commandService=o,this._workbookSelections=t.getWorkbookSelections(this._context.unitId),this._init()}dispose(){var e,t,r,o,s,l,c,d;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(t=this._moveHelperLineShape)==null||t.dispose(),(r=this._headerPointerMoveSubs)==null||r.unsubscribe(),(o=this._headerPointerLeaveSubs)==null||o.unsubscribe(),(s=this._headerPointerDownSubs)==null||s.unsubscribe(),this._headerPointerMoveSubs=null,this._headerPointerLeaveSubs=null,this._headerPointerDownSubs=null,(l=this._dragHeaderMoveSub)==null||l.unsubscribe(),(c=this._scenePointerUpSub)==null||c.unsubscribe(),this._dragHeaderMoveSub=null,this._scenePointerUpSub=null,(d=this._scrollTimer)==null||d.dispose()}_init(){this._initialRowOrColumn(a.RANGE_TYPE.ROW),this._initialRowOrColumn(a.RANGE_TYPE.COLUMN)}_initialRowOrColumn(e=a.RANGE_TYPE.ROW){const t=this._context.components.get(he.COLUMN),r=this._context.components.get(he.ROW),o=this._context.scene,s=e===a.RANGE_TYPE.ROW?r:t,l=u=>{var b,R;const h=(b=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:b.skeleton;if(h==null)return;const g=(R=this._workbookSelections.getCurrentLastSelection())==null?void 0:R.range;if(!g||!this.interceptor.fetchThroughInterceptors(so)(!1,g))return;const f=this._workbookSelections.getCurrentSelections(),{row:p,column:v}=qe(u.offsetX,u.offsetY,o,h);if(!ir(f,e===a.RANGE_TYPE.ROW?p:v,e)){o.resetCursor();return}o.setCursor(T.CURSOR_TYPE.GRAB)},c=()=>{var u,h;(u=this._moveHelperBackgroundShape)==null||u.hide(),(h=this._moveHelperLineShape)==null||h.hide(),o.resetCursor()},d=(u,h)=>{var W,D;if(h.isStopPropagation)return;const g=(W=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:W.skeleton;if(g==null)return;const S=(D=this._workbookSelections.getCurrentLastSelection())==null?void 0:D.range;if(!S||!this.interceptor.fetchThroughInterceptors(so)(!1,S))return;const{offsetX:p,offsetY:v}=u,C=o.getCoordRelativeToViewport(T.Vector2.FromArray([p,v])),{x:b,y:R}=C;this._startOffsetX=b,this._startOffsetY=R;const{row:w,column:M}=qe(u.offsetX,u.offsetY,o,g);let y;e===a.RANGE_TYPE.ROW?(this._changeFromRow=w,y=T.ScrollTimerType.Y):(this._changeFromColumn=M,y=T.ScrollTimerType.X);const P=this._workbookSelections.getCurrentSelections(),x=ir(P,e===a.RANGE_TYPE.ROW?w:M,e);if(!x)return;const A=o.getScrollXYInfoByViewport(T.Vector2.FromArray([this._startOffsetX,this._startOffsetY]));this._newBackgroundAndLine(),o.setCursor(T.CURSOR_TYPE.GRABBING),o.disableObjectsEvent();let k=!1,N;const H=()=>{if(k)return;N=T.ScrollTimer.create(o,y),this._scrollTimer=N;const U=o.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN);N.startScroll(b,R,U),k=!0};this._dragHeaderMoveSub=o.onPointerMove$.subscribeEvent(U=>{H();const{offsetX:L,offsetY:F}=U,{x:B,y:j}=o.getCoordRelativeToViewport(T.Vector2.FromArray([L,F]));this._rowColumnMoving(B,j,x,A,e),N.scrolling(B,j,()=>{this._rowColumnMoving(B,j,x,A,e)})}),this._scenePointerUpSub=o.onPointerUp$.subscribeEvent(()=>{var L,F,B;this._disposeBackgroundAndLine(),o.resetCursor(),o.enableObjectsEvent(),this._clearObserverEvent(),(L=this._scrollTimer)==null||L.dispose();const U=this._workbookSelections.getCurrentSelections();if(e===a.RANGE_TYPE.ROW){if(this._changeFromRow!==this._changeToRow&&this._changeToRow!==-1){const z=(F=((U==null?void 0:U.filter(K=>K.range.rangeType===a.RANGE_TYPE.ROW&&K.range.startRow<=this._changeFromRow&&this._changeFromRow<=K.range.endRow))||[])[0])==null?void 0:F.range;z&&this._commandService.executeCommand(m.MoveRowsCommand.id,{fromRange:z,toRange:{...z,startRow:this._changeToRow,endRow:this._changeToRow+z.endRow-z.startRow}})}this._changeToRow=this._changeFromRow=-1}else{if(this._changeFromColumn!==this._changeToColumn&&this._changeToColumn!==-1){const z=(B=((U==null?void 0:U.filter(K=>K.range.rangeType===a.RANGE_TYPE.COLUMN&&K.range.startColumn<=this._changeFromColumn&&this._changeFromColumn<=K.range.endColumn))||[])[0])==null?void 0:B.range;z&&this._commandService.executeCommand(m.MoveColsCommand.id,{fromRange:z,toRange:{...z,startColumn:this._changeToColumn,endColumn:this._changeToColumn+z.endColumn-z.startColumn}})}this._changeToColumn=this._changeFromColumn=-1}})};this._headerPointerMoveSubs=new O.Subscription,this._headerPointerMoveSubs.add(s.onPointerMove$.subscribeEvent(l)),this._headerPointerLeaveSubs=new O.Subscription,this._headerPointerLeaveSubs.add(s==null?void 0:s.onPointerLeave$.subscribeEvent(c)),this._headerPointerDownSubs=new O.Subscription,this._headerPointerDownSubs.add(s==null?void 0:s.onPointerDown$.subscribeEvent(d))}_rowColumnMoving(e,t,r,o,s){var j,z,K,ne,Q,se,ce;const l=this._context.scene,c=(j=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:j.skeleton;if(c==null)return;const{rowHeaderWidth:d,columnHeaderHeight:u,rowTotalHeight:h,columnTotalWidth:g}=c,S=l.getViewportScrollXY(l.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:f,scaleY:p}=l.getAncestorScale(),v=c.getCellIndexByOffset(e,t,f,p,S),{row:C,column:b}=v,R=c.getNoMergeCellWithCoordByIndex(C,b),{startX:w,startY:M,endX:y,endY:P}=R,x=this._sheetSkeletonManagerService.attachRangeWithCoord(r.range);if(x==null)return;const A=Math.max(f,f),{startX:k,endX:N,startY:H,endY:W,startRow:D,startColumn:U,endRow:L,endColumn:F}=x;s===a.RANGE_TYPE.ROW?(z=this._moveHelperBackgroundShape)==null||z.transformByState({height:W-H,width:g+d,left:0,top:H+(t-this._startOffsetY)/A+S.y-o.y}):(K=this._moveHelperBackgroundShape)==null||K.transformByState({height:h+u,width:N-k,left:k+(e-this._startOffsetX)/A+S.x-o.x,top:0}),(ne=this._moveHelperBackgroundShape)==null||ne.show();const B=rS/A;if(s===a.RANGE_TYPE.ROW){let X=0;if(C<=D)X=M-B/2,this._changeToRow=C;else if(C>L)X=P-B/2,this._changeToRow=C+1;else return;(Q=this._moveHelperLineShape)==null||Q.transformByState({height:B,width:g,left:d,top:X})}else{let X=0;if(b<=U)X=w-B/2,this._changeToColumn=b;else if(b>F)X=y-B/2,this._changeToColumn=b+1;else return;(se=this._moveHelperLineShape)==null||se.transformByState({height:h,width:B,left:X,top:u})}(ce=this._moveHelperLineShape)==null||ce.show()}_clearObserverEvent(){var e,t;(e=this._dragHeaderMoveSub)==null||e.unsubscribe(),(t=this._scenePointerUpSub)==null||t.unsubscribe(),this._dragHeaderMoveSub=null,this._scenePointerUpSub=null}_newBackgroundAndLine(){const e=this._context.scene;this._moveHelperBackgroundShape=new T.Rect($g,{fill:tS,evented:!1,zIndex:100}),this._moveHelperLineShape=new T.Rect(eS,{fill:nS,evented:!1,zIndex:100}),e.addObjects([this._moveHelperBackgroundShape,this._moveHelperLineShape],bt)}_disposeBackgroundAndLine(){var e,t;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(t=this._moveHelperLineShape)==null||t.dispose()}};exports.HeaderMoveRenderController=Jg([oo(1,a.Inject(m.SheetsSelectionsService)),oo(2,a.Inject(exports.SheetSkeletonManagerService)),oo(3,a.ICommandService)],exports.HeaderMoveRenderController);var Go=(n=>(n[n.VERTICAL=0]="VERTICAL",n[n.HORIZONTAL=1]="HORIZONTAL",n))(Go||{});const iS="rgba(120, 120, 120, 0.01)",ao="rgb(68, 71, 70)",Zn=12,oS=44,Zo=4;class ba extends T.Shape{constructor(e,t){super(e,t);E(this,"_size",Zn);E(this,"_color",ao);E(this,"_mode",0);this.setShapeProps(t)}get size(){return this._size}get mode(){return this._mode}get color(){return this._color}_draw(e){const t=this.getScene();if(!t)return;const{scaleX:r,scaleY:o}=t.getAncestorScale(),s=Math.max(r,o),l=Zn/s,c=Zo/s;let{width:d,height:u}=this,h=0,g=0;this.mode===0?(d=c,h=l-c):(u=c,g=l-c),T.Rect.drawWith(e,{width:this.width,height:this.height,left:0,top:0,fill:iS}),T.Rect.drawWith(e,{width:d,height:u,fill:ao,radius:c}),e.save(),e.transform(1,0,0,1,h,g),T.Rect.drawWith(e,{width:d,height:u,fill:ao,radius:c}),e.restore()}setShapeProps(e){return e!=null&&e.size&&(this._size=e.size),e!=null&&e.mode&&(this._mode=e.mode),e!=null&&e.color&&(this._color=e.color),this.mode===0?this.transformByState({width:Zn,height:this.size}):this.transformByState({width:this.size,height:Zn}),this}}var sS=Object.getOwnPropertyDescriptor,aS=(n,i,e,t)=>{for(var r=t>1?void 0:t?sS(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=s(r)||r);return r},lo=(n,i)=>(e,t)=>i(e,t,n);const lS="__SpreadsheetHeaderResizeControllerShapeRow__",cS="__SpreadsheetHeaderResizeControllerShapeColumn__",Ra="__SpreadsheetHeaderResizeControllerShapeHelper__",Ea="rgb(199, 199, 199)",dS=2,co=a.createInterceptorKey("headerResizePermissionCheck");exports.HeaderResizeRenderController=class extends a.Disposable{constructor(e,t,r,o){super();E(this,"_currentRow",0);E(this,"_currentColumn",0);E(this,"_rowResizeRect");E(this,"_columnResizeRect");E(this,"_headerPointerSubs");E(this,"_scenePointerMoveSub");E(this,"_scenePointerUpSub");E(this,"_resizeHelperShape");E(this,"_startOffsetX",Number.POSITIVE_INFINITY);E(this,"_startOffsetY",Number.POSITIVE_INFINITY);E(this,"interceptor",new a.InterceptorManager({HEADER_RESIZE_PERMISSION_CHECK:co}));this._context=e,this._sheetSkeletonManagerService=t,this._selectionManagerService=r,this._commandService=o,this._init()}dispose(){var e,t,r;(e=this._rowResizeRect)==null||e.dispose(),this._rowResizeRect=null,(t=this._columnResizeRect)==null||t.dispose(),this._columnResizeRect=null,(r=this._headerPointerSubs)==null||r.unsubscribe(),this._headerPointerSubs=null}_init(){const e=this._context.scene;this._rowResizeRect=new ba(lS,{visible:!1,mode:Go.HORIZONTAL,zIndex:100}),this._columnResizeRect=new ba(cS,{visible:!1,mode:Go.VERTICAL,zIndex:100}),e.addObjects([this._rowResizeRect,this._columnResizeRect],bt),this._initialHover(0),this._initialHover(1),this._initialHoverResize(0),this._initialHoverResize(1)}_initialHover(e=0){const t=this._context.components.get(he.COLUMN),r=this._context.components.get(he.ROW),o=this._context.scene,s=e===0?r:t,l=(d,u)=>{var h,g;(h=this._rowResizeRect)==null||h.hide(),(g=this._columnResizeRect)==null||g.hide()},c=(d,u)=>{var A;const h=(A=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:A.skeleton;if(h==null||this._rowResizeRect==null||this._columnResizeRect==null)return;const{rowHeaderWidth:g,columnHeaderHeight:S}=h,{startX:f,startY:p,endX:v,endY:C,row:b,column:R}=qe(d.offsetX,d.offsetY,o,h),w=Qn(d.offsetX,d.offsetY,o),{scaleX:M,scaleY:y}=o.getAncestorScale(),P=Math.max(M,y),x=Zn/P;if(e===0){let k=p-x/2;if(w.y<=p+x/2&&w.y>=p)this._currentRow=b-1;else if(w.y>=C-x/2&&w.y<=C)this._currentRow=b,k=C-x/2;else{this._rowResizeRect.hide();return}if(this._currentRow===-1)return;if(!this.interceptor.fetchThroughInterceptors(co)(null,{row:this._currentRow}))return!1;const H=Math.min(oS,g/3);this._rowResizeRect.transformByState({left:g/2-H/2,top:k}),this._rowResizeRect.setShapeProps({size:H}),this._rowResizeRect.show()}else{let k=f-x/2;if(w.x<=f+x/2&&w.x>=f)this._currentColumn=R-1;else if(w.x>=v-x/2&&w.x<=v)this._currentColumn=R,k=v-x/2;else{this._columnResizeRect.hide();return}if(this._currentColumn===-1)return;if(!this.interceptor.fetchThroughInterceptors(co)(null,{col:this._currentColumn}))return!1;const H=S*.7;this._columnResizeRect.transformByState({left:k,top:S/2-H/2}),this._columnResizeRect.setShapeProps({size:H}),this._columnResizeRect.show()}};this._headerPointerSubs=new O.Subscription,this._headerPointerSubs.add(s==null?void 0:s.onPointerMove$.subscribeEvent(c)),this._headerPointerSubs.add(s==null?void 0:s.onPointerLeave$.subscribeEvent(l))}_initialHoverResize(e=0){const t=this._context.scene,r=e===0?this._rowResizeRect:this._columnResizeRect;r!=null&&(this.disposeWithMe(r.onPointerEnter$.subscribeEvent(()=>{r!=null&&(r.show(),t.setCursor(e===0?T.CURSOR_TYPE.ROW_RESIZE:T.CURSOR_TYPE.COLUMN_RESIZE))})),this.disposeWithMe(r.onPointerLeave$.subscribeEvent(()=>{r!=null&&(r.hide(),t.resetCursor())})),this.disposeWithMe(r.onPointerDown$.subscribeEvent(o=>{var F,B,j,z,K,ne,Q;const s=(F=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:F.skeleton;if(s==null)return;const l=this._context.scene,c=l.getEngine(),d=(c==null?void 0:c.height)||0,u=(c==null?void 0:c.width)||0,h=l.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=(((j=(B=h==null?void 0:h.getScrollBar())==null?void 0:B.horizonScrollTrack)==null?void 0:j.height)||0)+10,S=(((K=(z=h==null?void 0:h.getScrollBar())==null?void 0:z.verticalScrollTrack)==null?void 0:K.width)||0)+10,f=Qn(o.offsetX,o.offsetY,l),{scaleX:p,scaleY:v}=l.getAncestorScale();this._startOffsetX=f.x,this._startOffsetY=f.y;const C=s.getOffsetByColumn(this._currentColumn),b=s.getOffsetByRow(this._currentRow),R=s.getNoMergeCellWithCoordByIndex(this._currentRow,this._currentColumn);let w=!1,M=0,y=0;const{columnTotalWidth:P,rowHeaderWidth:x,rowTotalHeight:A,columnHeaderHeight:k}=s,N=u>P+x?u:P+x,H=d>A+k?d:A+k,W=Math.max(p,v),D=Zo/W;e===0?this._resizeHelperShape=new T.Rect(Ra,{width:N,height:D,fill:Ea,left:0,top:b-D/2}):this._resizeHelperShape=new T.Rect(Ra,{width:D,height:H,fill:Ea,left:C-D/2,top:0});const U=((ne=this._columnResizeRect)==null?void 0:ne.left)||0,L=((Q=this._rowResizeRect)==null?void 0:Q.top)||0;l.addObject(this._resizeHelperShape,bt),l.disableObjectsEvent(),this._scenePointerMoveSub=l.onPointerMove$.subscribeEvent(se=>{var fe,Te,we,Fe,St,Mt;const ce=l.getCoordRelativeToViewport(T.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),X=l.getScrollXYInfoByViewport(ce,h),G=Qn(se.offsetX,se.offsetY,l),{x:q,y:ie}=G,{scaleX:oe,scaleY:J}=l.getAncestorScale(),ee=Math.max(oe,J),de=Zo/ee;M=q-this._startOffsetX-de/2,y=ie-this._startOffsetY-de/2,Math.abs(e===0?y:M)>=dS&&(w=!0),e===0?(y>d-g+X.y-R.startY&&(y=d-g+X.y-R.startY),y<-(R.endY-R.startY)+2&&(y=-(R.endY-R.startY)+2),w&&((fe=this._resizeHelperShape)==null||fe.transformByState({top:b+y}),(Te=this._rowResizeRect)==null||Te.transformByState({top:L+y+de/2}),(we=this._rowResizeRect)==null||we.show(),l.setCursor(T.CURSOR_TYPE.ROW_RESIZE))):(M>u-S+X.x-R.startX&&(M=u-S+X.x-R.startX),M<-(R.endX-R.startX)+2&&(M=-(R.endX-R.startX)+2),w&&((Fe=this._resizeHelperShape)==null||Fe.transformByState({left:C+M}),(St=this._columnResizeRect)==null||St.transformByState({left:U+M+de/2}),(Mt=this._columnResizeRect)==null||Mt.show(),l.setCursor(T.CURSOR_TYPE.COLUMN_RESIZE)))}),this._scenePointerUpSub=l.onPointerUp$.subscribeEvent(se=>{var X,G,q;const ce=this._context.scene;this._clearObserverEvent(),(X=this._resizeHelperShape)==null||X.dispose(),this._resizeHelperShape=null,ce.enableObjectsEvent(),w&&(ce.resetCursor(),(G=this._rowResizeRect)==null||G.hide(),(q=this._columnResizeRect)==null||q.hide(),e===0?this._commandService.executeCommand(m.DeltaRowHeightCommand.id,{deltaY:y,anchorRow:this._currentRow}):this._commandService.executeCommand(m.DeltaColumnWidthCommand.id,{deltaX:M,anchorCol:this._currentColumn}))})})),this.disposeWithMe(r.onDblclick$.subscribeEvent(()=>{var h,g,S;this._context.scene.resetCursor();const s=(h=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:h.skeleton;if(!s)return;const l=0,c=0,d=s.worksheet.getRowCount()-1||0,u=s.worksheet.getColumnCount()-1||0;switch(e){case 1:{const f=this._selectionManagerService.getCurrentSelections(),p=[];for(let v=0;v<f.length;v++){const C=f[v];C.range.rangeType===a.RANGE_TYPE.COLUMN&&this._currentColumn<=C.range.endColumn&&this._currentColumn>=C.range.startColumn&&p.push({startColumn:C.range.startColumn,endColumn:C.range.endColumn,startRow:l,endRow:d})}p.length===0&&p.push({startColumn:this._currentColumn,endColumn:this._currentColumn,startRow:l,endRow:d}),this._commandService.executeCommand(Er.id,{ranges:p}),(g=this._columnResizeRect)==null||g.hide();break}case 0:this._commandService.executeCommand(m.SetWorksheetRowIsAutoHeightCommand.id,{ranges:[{startRow:this._currentRow,endRow:this._currentRow,startColumn:c,endColumn:u}]}),(S=this._rowResizeRect)==null||S.hide();break}})))}_clearObserverEvent(){var e,t;(e=this._scenePointerMoveSub)==null||e.unsubscribe(),(t=this._scenePointerUpSub)==null||t.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null}};exports.HeaderResizeRenderController=aS([lo(1,a.Inject(exports.SheetSkeletonManagerService)),lo(2,a.Inject(m.SheetsSelectionsService)),lo(3,a.ICommandService)],exports.HeaderResizeRenderController);var uS=Object.getOwnPropertyDescriptor,hS=(n,i,e,t)=>{for(var r=t>1?void 0:t?uS(i,e):i,o=n.length-1,s;o>=0;o--)(s=n[o])&&(r=s(r)||r);return r},Lr=(n,i)=>(e,t)=>i(e,t,n);const mS=60;exports.SheetRenderController=class extends a.RxDisposable{constructor(e,t,r,o,s){super();E(this,"_renderFrameTimeMetric",null);E(this,"_renderFrameTags",{});E(this,"_afterRenderMetric$",new O.Subject);this._context=e,this._sheetSkeletonManagerService=t,this._sheetRenderService=r,this._commandService=o,this._telemetryService=s,this._addNewRender(),this._initRenderMetricSubscriber()}_addNewRender(){const{scene:e,engine:t,unit:r}=this._context;this._addComponent(r),this._initRerenderScheduler(),this._initCommandListener();const o=this._context.unit.getActiveSheet();if(!o)throw new Error("No active sheet found");const s=o.getSheetId();this._sheetSkeletonManagerService.setCurrent({sheetId:s});const l=()=>e.render();this.disposeWithMe(this._context.activated$.subscribe(c=>{c?t.runRenderLoop(l):t.stopRenderLoop(l)}))}_initRenderMetricSubscriber(){if(!this._telemetryService)return;const{engine:e}=this._context;e.beginFrame$.subscribe(()=>{this._renderFrameTimeMetric=null,this._renderFrameTags={}}),e.endFrame$.subscribe(()=>{this._renderFrameTimeMetric&&Object.keys(this._renderFrameTimeMetric).filter(o=>o.startsWith(T.SHEET_EXTENSION_PREFIX)).length>0&&this._afterRenderMetric$.next({frameTimeMetric:this._renderFrameTimeMetric,tags:this._renderFrameTags})}),e.renderFrameTimeMetric$.subscribe(([r,o])=>{this._renderFrameTimeMetric||(this._renderFrameTimeMetric={}),this._renderFrameTimeMetric[r]||(this._renderFrameTimeMetric[r]=[]),this._renderFrameTimeMetric[r].push(Math.round(o*100)/100)}),e.renderFrameTags$.subscribe(([r,o])=>{this._renderFrameTags[r]=o});const t=[];this._afterRenderMetric$.pipe(O.withLatestFrom(e.endFrame$)).subscribe(([r,o])=>{t.push({FPS:o.FPS,elapsedTime:o.elapsedTime,frameTime:Math.round(o.frameTime*100)/100,...r.frameTimeMetric,...r.tags}),t.length>mS&&(this._renderMetricCapture(t),t.length=0)})}_renderMetricCapture(e){if(!this._telemetryService)return;const t=e;if(t.length===0)return;const r=g=>{let S=0;const p=Object.entries(g).filter(([C,b])=>Array.isArray(b)).map(([C])=>C).reduce((C,b)=>{const R=g[b].reduce((w,M)=>w+M,0);return C[b]=R,C},{});return Object.keys(g).filter(C=>C.startsWith(T.SHEET_EXTENSION_PREFIX)).forEach(C=>{S+=p[C]}),{...p,extensionTotal:S}},o=e.map(g=>({...g,...r(g)})),l=(g=>Object.entries(g[0]).filter(([p,v])=>!["elapsedTime"].includes(p)).filter(([p,v])=>typeof v=="number").map(([p])=>p).reduce((p,v)=>{const C=g.map(M=>M[v]),b=Math.max(...C),R=Math.min(...C),w=C.reduce((M,y)=>M+y,0)/C.length;return p[v]={max:Math.round(b*100)/100,min:Math.round(R*100)/100,avg:Math.round(w*100)/100},p},{}))(o),c=t[t.length-1].elapsedTime,d=this._context.unit.getActiveSheet().getSheetId(),u=this._context.unit.getUnitId(),h={sheetId:d,unitId:u,elapsedTimeToStart:c,...l};this._telemetryService.capture("sheet_render_cost",h)}_addComponent(e){const{scene:t,components:r}=this._context,o=e.getActiveSheet(),s=new T.Spreadsheet(he.MAIN);this._addViewport(o);const l=new T.SpreadsheetRowHeader(he.ROW),c=new T.SpreadsheetColumnHeader(he.COLUMN),d=new T.Rect(he.LEFT_TOP,{zIndex:2,left:-1,top:-1,fill:"rgb(248, 249, 250)",stroke:"rgb(217, 217, 217)",strokeWidth:1});this._context.mainComponent=s,r.set(he.MAIN,s),r.set(he.ROW,l),r.set(he.COLUMN,c),r.set(he.LEFT_TOP,d),t.addObjects([s],Bs),t.addObjects([l,c,d],bt),t.enableLayerCache(Bs,bt)}_initViewports(e,t,r){const l=new T.Viewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN,e,{left:t.width,top:r.height,bottom:0,right:0,isWheelPreventDefaultX:!0,allowCache:!0,bufferEdgeX:100,bufferEdgeY:100}),c=new T.Viewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:0,bufferEdgeY:0}),d=new T.Viewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:0,bufferEdgeY:100}),u=new T.Viewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:100,bufferEdgeY:0}),h=new T.Viewport(T.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP,e,{active:!1,isWheelPreventDefaultX:!0}),g=new T.Viewport(T.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM,e,{left:0,top:r.height,bottom:0,width:t.width,isWheelPreventDefaultX:!0}),S=new T.Viewport(T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT,e,{active:!1,isWheelPreventDefaultX:!0}),f=new T.Viewport(T.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT,e,{left:t.width,top:0,height:r.height,right:0,isWheelPreventDefaultX:!0}),p=new T.Viewport(T.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP,e,{left:0,top:0,width:t.width,height:r.height,isWheelPreventDefaultX:!0});return{viewMain:l,viewLeftTop:p,viewMainLeftTop:c,viewMainLeft:d,viewMainTop:u,viewColumnLeft:S,viewRowTop:h,viewRowBottom:g,viewColumnRight:f}}_addViewport(e){const t=this._context.scene,{rowHeader:r,columnHeader:o}=e.getConfig(),{viewMain:s}=this._initViewports(t,r,o);return new T.ScrollBar(s),t.attachControl(),s}_initRerenderScheduler(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(!e)return null;const{skeleton:t,sheetId:r}=e,o=this._context.unit,s=o==null?void 0:o.getSheetBySheetId(r);if(o==null||s==null)return;const{mainComponent:l,components:c}=this._context,d=l,u=c.get(he.ROW),h=c.get(he.COLUMN),g=c.get(he.LEFT_TOP),{rowHeaderWidth:S,columnHeaderHeight:f}=t;d==null||d.updateSkeleton(t),u==null||u.updateSkeleton(t),h==null||h.updateSkeleton(t),g==null||g.transformByState({width:S,height:f})}))}_initCommandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{const{unit:t}=this._context,{id:r}=e;if(m.COMMAND_LISTENER_SKELETON_CHANGE.includes(r)||this._sheetRenderService.checkMutationShouldTriggerRerender(r)){const o=e.params,{unitId:s,subUnitId:l}=o,c=t.getActiveSheet();if(!c)return;const d=this._context.unitId,u=c.getSheetId();if(s!==d||l!==u)return;this._sheetSkeletonManagerService.makeDirty({sheetId:u,commandId:r},!0),this._sheetSkeletonManagerService.setCurrent({sheetId:u,commandId:r})}else m.COMMAND_LISTENER_VALUE_CHANGE.includes(r)&&this._sheetSkeletonManagerService.reCalculate();e.type===a.CommandType.MUTATION&&this._markUnitDirty(e)}))}_markUnitDirty(e){const{mainComponent:t,scene:r}=this._context;if(e.id===Z.SetFormulaCalculationNotificationMutation.id&&e.params.stageInfo!=null||(t&&t.makeDirty(),r.makeDirty(),!e.params))return;const o=e.params,s=this._spreadsheetViewports(r);if(e.id===m.SetRangeValuesMutation.id&&o.cellValue){const l=this._cellValueToRange(o.cellValue),c=this._rangeToBounds([l]);this._markViewportDirty(s,c),t.setDirtyArea(c)}if(e.id===m.MoveRangeMutation.id&&o.from&&o.to){const l=o.fromRange||this._cellValueToRange(o.from.value),c=o.toRange||this._cellValueToRange(o.to.value),d=this._rangeToBounds([l,c]);this._markViewportDirty(s,d),t.setDirtyArea(d)}}_cellValueToRange(e){let t=0,r=0,o=0,s=0;for(const[h,g]of Object.entries(e)){for(const S in g)t>Number(S)&&(t=Number(S)),r<Number(S)&&(r=Number(S));o>Number(h)&&(o=Number(h)),s<Number(h)&&(s=Number(h))}return{startRow:o,endRow:s,startColumn:t,endColumn:r}}_rangeToBounds(e){const t=this._sheetSkeletonManagerService.getCurrentParam().skeleton,{rowHeightAccumulation:r,columnWidthAccumulation:o,rowHeaderWidth:s,columnHeaderHeight:l}=t,c=[];for(const d of e){const{startRow:u,endRow:h,startColumn:g,endColumn:S}=d,f=u===0?0:r[u-1]+l,p=r[h]+l,v=g===0?0:o[g-1]+s,C=o[S]+s;c.push({top:f,left:v,bottom:p,right:C,width:C-v,height:p-f})}return c}_markViewportDirty(e,t){const r=e.filter(o=>o.isActive&&o.cacheBound);for(const o of r)for(const s of t)a.Rectangle.hasIntersectionBetweenTwoRect(o.cacheBound,s)&&o.markDirty(!0)}_spreadsheetViewports(e){return e.getViewports().filter(t=>["viewMain","viewMainLeftTop","viewMainTop","viewMainLeft"].includes(t.viewportKey))}};exports.SheetRenderController=hS([Lr(1,a.Inject(exports.SheetSkeletonManagerService)),Lr(2,a.Inject(exports.SheetsRenderService)),Lr(3,a.ICommandService),Lr(4,a.Optional(md.ITelemetryService))],exports.SheetRenderController);function gS(n,i){if(n.length!==i.length)return!1;const e=n.sort((r,o)=>r.id.localeCompare(o.id)),t=i.sort((r,o)=>r.id.localeCompare(o.id));return e.every((r,o)=>{var s,l;return((s=r.subject)==null?void 0:s.userID)===((l=t[o].subject)==null?void 0:l.userID)&&r.role===t[o].role})}function jl(n,i){return i.some(e=>SS(n,e))}function SS(n,i){const{startRow:e,startColumn:t,endColumn:r,endRow:o}=i,s=n.getMatrixWithMergedCells(e,t,o,r);let l=!1;return s.forValue((c,d,u)=>{if(u&&(c!==e||d!==t)&&n.cellHasValue(u))return l=!0,!1}),l}function zl(n,i,e,t){const r=[],o=[],s=e.getSheetId();return t.forEach(l=>{const c=fS(e,l),d={unitId:i,subUnitId:s,cellValue:c.getData()},u=m.SetRangeValuesUndoMutationFactory(n,d);r.push({id:m.SetRangeValuesMutation.id,params:u}),o.push({id:m.SetRangeValuesMutation.id,params:d})}),{undos:r,redos:o}}function fS(n,i){const{startRow:e,startColumn:t,endColumn:r,endRow:o}=i,s=n.getMatrixWithMergedCells(e,t,o,r,a.CellModeEnum.Intercepted),l=new a.ObjectMatrix;let c=null;return s.forValue((d,u,h)=>{var g,S,f,p;h&&d>=e&&u>=t&&(!c&&n.cellHasValue(h)&&(h.v!==""||((p=(f=(S=(g=h.p)==null?void 0:g.body)==null?void 0:S.dataStream)==null?void 0:f.length)!=null?p:0)>2)&&(c=h),l.setValue(d,u,null))}),l.setValue(e,t,c),l}function pS(n,i,e,t){const r=e.getActiveViewportByCoord(T.Vector2.FromArray([n,i]));if(!r)return;const{scaleX:o,scaleY:s}=e.getAncestorScale(),l={x:r.viewportScrollX,y:r.viewportScrollY},c=t.getCellIndexByOffset(n,i,o,s,l),d=t.worksheet.getMergedCell(c.row,c.column);return{actualRow:d?d.startRow:c.row,actualCol:d?d.startColumn:c.column,mergeCell:d,row:c.row,col:c.column}}function wa(n,i,e,t){const r=t.getFreeze();if(!r||r.startRow<=0&&r.startColumn<=0||n>=r.startRow&&i>=r.startColumn)return e.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(n<r.startRow&&i<r.startColumn)return e.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP);if(n<r.startRow&&i>=r.startColumn)return e.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(n>=r.startRow&&i<r.startColumn)return e.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)}function vS(n,i,e,t){const r=Ta(n.left,n.top,i,e,t),o=Ta(n.right,n.bottom,i,e,t);return{left:r.x,top:r.y,right:o.x,bottom:o.y}}function Ta(n,i,e,t,r){const{scaleX:o,scaleY:s}=e.getAncestorScale(),l=e.getViewport(T.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!l)return{x:n,y:i};const c=r.getFreeze(),{startColumn:d,startRow:u,xSplit:h,ySplit:g}=c,S=t.getNoMergeCellWithCoordByIndex(u-g,d-h,!1),f=t.getNoMergeCellWithCoordByIndex(u,d,!1),{rowHeaderWidth:p,columnHeaderHeight:v}=t,C=f.startX-S.startX,b=f.startY-S.startY,{top:R,left:w,viewportScrollX:M,viewportScrollY:y}=l;let P;n>w?P=(n-M)*o:P=(C+p-(w-n))*o;let x;return i>R?x=(i-y)*s:x=(b+v-(R-i))*o,{x:P,y:x}}function Xl(n,i,e,t,r){let o=t,s=r;e.overflowCache.forValue((d,u,h)=>{h.startRow<=o&&h.endRow>=o&&h.startColumn<=s&&h.endColumn>=s&&(s=u,o=d)});const l=e.getCellWithCoordByIndex(o,s);return{unitId:n.getUnitId(),subUnitId:i.getSheetId(),workbook:n,worksheet:i,row:l.actualRow,col:l.actualColumn}}function Yl(n,i,e,t,r,o){const{scene:s}=n,l=i.getUnitId(),{skeleton:c,sheetId:d}=t,u=pS(r,o,s,c);if(!u)return null;let{actualCol:h,actualRow:g}=u;const S={unitId:l,subUnitId:d,workbook:i,worksheet:e,row:g,col:h};c.overflowCache.forValue((y,P,x)=>{x.startRow<=g&&x.endRow>=g&&x.startColumn<=h&&x.endColumn>=h&&(h=P,g=y)});const f=c.getCellWithCoordByIndex(g,h),p=Xl(i,e,c,g,h);let v;f.mergeInfo?v=f.mergeInfo:v={startRow:p.row,endRow:p.row,startColumn:p.col,endColumn:p.col};const C=s.getActiveViewportByCoord(T.Vector2.FromArray([r,o]));if(!C)return;const{scaleX:b,scaleY:R}=s.getAncestorScale(),w={x:C.viewportScrollX,y:C.viewportScrollY};return{position:{startX:(c.getOffsetByColumn(v.startColumn-1)-w.x)*b,endX:(c.getOffsetByColumn(v.endColumn)-w.x)*b,startY:(c.getOffsetByRow(v.startRow-1)-w.y)*R,endY:(c.getOffsetByRow(v.endRow)-w.y)*R},location:S,overflowLocation:p}}const Tt={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge",handler:async(n,i)=>{const e=n.get(a.ICommandService),t=n.get(a.IUndoRedoService),r=n.get(a.IUniverInstanceService),o=n.get(_.IConfirmService),s=n.get(a.LocaleService),l=i.unitId,c=i.subUnitId,d=i.selections,u=m.getAddMergeMutationRangeByType(d,i.value),h=r.getUniverSheetInstance(l).getSheetBySheetId(c),g=[],S=[],f=jl(h,u);if(f&&!i.defaultMerge&&!await o.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 p={unitId:l,subUnitId:c,ranges:a.Tools.deepClone(u)},v={unitId:l,subUnitId:c,ranges:a.Tools.deepClone(u)},C=m.RemoveMergeUndoMutationFactory(n,p),b=m.AddMergeUndoMutationFactory(n,v);if(C.ranges.length>0&&g.push({id:m.RemoveWorksheetMergeMutation.id,params:C}),g.push({id:m.AddWorksheetMergeMutation.id,params:v}),S.push({id:m.RemoveWorksheetMergeMutation.id,params:b}),C.ranges.length>0&&S.push({id:m.AddWorksheetMergeMutation.id,params:C}),f){const x=zl(n,l,h,u);g.unshift(...x.redos),S.push(...x.undos)}const R=m.AddMergeRedoSelectionsOperationFactory(n,i,u);R&&g.push(R);const w=m.AddMergeUndoSelectionsOperationFactory(n,i);w&&S.push(w);const y=n.get(m.SheetInterceptorService).onCommandExecute({id:Tt.id,params:{unitId:l,subUnitId:c,ranges:u}});return g.push(...y.redos),S.push(...y.undos),a.sequenceExecute(g,e).result?(t.pushUndoRedo({unitID:l,undoMutations:S,redoMutations:g}),!0):!1}},As={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-all",handler:async n=>{var u;const i=n.get(a.ICommandService),t=(u=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:u.map(h=>h.range),r=fs(ki.MergeAll,t);if(!(r!=null&&r.length))return!1;const s=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;const l=s.getActiveSheet();if(!l)return!1;const c=s.getUnitId(),d=l.getSheetId();return i.executeCommand(Tt.id,{selections:r,unitId:c,subUnitId:d})}},ks={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-vertical",handler:async n=>{var u;const i=n.get(a.ICommandService),t=(u=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:u.map(h=>h.range),r=fs(ki.MergeVertical,t);if(!(r!=null&&r.length))return!1;const s=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;const l=s.getActiveSheet();if(!l)return!1;const c=s.getUnitId(),d=l.getSheetId();return i.executeCommand(Tt.id,{value:a.Dimension.COLUMNS,selections:r,unitId:c,subUnitId:d})}},Ns={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-horizontal",handler:async n=>{var u;const i=n.get(a.ICommandService),t=(u=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:u.map(h=>h.range),r=fs(ki.MergeHorizontal,t);if(!(r!=null&&r.length))return!1;const s=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;const l=s.getActiveSheet();if(!l)return!1;const c=s.getUnitId(),d=l.getSheetId();return i.executeCommand(Tt.id,{value:a.Dimension.ROWS,selections:r,unitId:c,subUnitId:d})}},Vn={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-move-left-confirm",handler:async n=>{const i=n.get(_.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=r.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(o);if(!l)return!1;const{worksheet:c}=l;let d=s[0].range;if(!d)return!1;d={...d,endColumn:c.getColumnCount()-1};const u=S=>S.endRow-S.startRow;return!c.getMergeData().find(S=>{const f=a.Rectangle.getIntersects(S,d);return f?u(S)>u(f):!1})||await i.confirm({id:Vn.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.DeleteRangeMoveLeftCommand.id):!0}},Xt={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-move-up-confirm",handler:async n=>{const i=n.get(_.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=r.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(o);if(!l)return!1;const{worksheet:c}=l;let d=s[0].range;if(!d)return!1;d={...d,endRow:c.getRowCount()-1};for(let S=d.startRow;S<=d.endRow;S++)if(c.getRowFiltered(S)&&await i.confirm({id:Xt.id,title:{title:t.t("filter.confirm.error")},children:{title:t.t("filter.confirm.notAllowedToInsertRange")},confirmText:t.t("button.confirm")}))return!1;const u=S=>S.endColumn-S.startColumn;return!c.getMergeData().find(S=>{const f=a.Rectangle.getIntersects(S,d);return f?u(S)>u(f):!1})||await i.confirm({id:Xt.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.DeleteRangeMoveUpCommand.id):!0}},Yt={type:a.CommandType.COMMAND,id:"sheet.command.insert-range-move-down-confirm",handler:async n=>{const i=n.get(_.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=r.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(o);if(!l)return!1;const{worksheet:c}=l;let d=s[0].range;if(!d)return!1;d={...d,endRow:c.getRowCount()-1};for(let S=d.startRow;S<=d.endRow;S++)if(c.getRowFiltered(S)&&await i.confirm({id:Yt.id,title:{title:t.t("filter.confirm.error")},children:{title:t.t("filter.confirm.notAllowedToInsertRange")},confirmText:t.t("button.confirm")}))return!1;const u=S=>S.endColumn-S.startColumn;return!c.getMergeData().find(S=>{const f=a.Rectangle.getIntersects(S,d);return f?u(S)>u(f):!1})||await i.confirm({id:Yt.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.InsertRangeMoveDownCommand.id):!0}},Wn={type:a.CommandType.COMMAND,id:"sheet.command.insert-range-move-right-confirm",handler:async n=>{const i=n.get(_.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),r=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=r.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(o);if(!l)return!1;const{worksheet:c}=l;let d=s[0].range;if(!d)return!1;d={...d,endColumn:c.getColumnCount()-1};const u=S=>S.endRow-S.startRow;return!c.getMergeData().find(S=>{const f=a.Rectangle.getIntersects(S,d);return f?u(S)>u(f):!1})||await i.confirm({id:Wn.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.InsertRangeMoveRightCommand.id):!0}};var Gl=(n=>(n[n.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",n[n.UNIVER_DOC=1]="UNIVER_DOC",n[n.UNIVER_SHEET=2]="UNIVER_SHEET",n[n.UNIVER_SLIDE=3]="UNIVER_SLIDE",n[n.UNIVER_PROJECT=4]="UNIVER_PROJECT",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(Gl||{}),re=(n=>(n[n.View=0]="View",n[n.Edit=1]="Edit",n[n.ManageCollaborator=2]="ManageCollaborator",n[n.Print=3]="Print",n[n.Duplicate=4]="Duplicate",n[n.Comment=5]="Comment",n[n.Copy=6]="Copy",n[n.Share=7]="Share",n[n.Export=8]="Export",n[n.MoveWorksheet=9]="MoveWorksheet",n[n.DeleteWorksheet=10]="DeleteWorksheet",n[n.HideWorksheet=11]="HideWorksheet",n[n.RenameWorksheet=12]="RenameWorksheet",n[n.CreateWorksheet=13]="CreateWorksheet",n[n.SetWorksheetStyle=14]="SetWorksheetStyle",n[n.EditWorksheetCell=15]="EditWorksheetCell",n[n.InsertHyperlink=16]="InsertHyperlink",n[n.Sort=17]="Sort",n[n.Filter=18]="Filter",n[n.PivotTable=19]="PivotTable",n[n.FloatImg=20]="FloatImg",n[n.History=21]="History",n[n.RwHgtClWdt=22]="RwHgtClWdt",n[n.ViemRwHgtClWdt=23]="ViemRwHgtClWdt",n[n.ViewFilter=24]="ViewFilter",n[n.MoveSheet=25]="MoveSheet",n[n.DeleteSheet=26]="DeleteSheet",n[n.HideSheet=27]="HideSheet",n[n.CopySheet=28]="CopySheet",n[n.RenameSheet=29]="RenameSheet",n[n.CreateSheet=30]="CreateSheet",n[n.SelectProtectedCells=31]="SelectProtectedCells",n[n.SelectUnProtectedCells=32]="SelectUnProtectedCells",n[n.SetCellStyle=33]="SetCellStyle",n[n.SetCellValue=34]="SetCellValue",n[n.SetRowStyle=35]="SetRowStyle",n[n.SetColumnStyle=36]="SetColumnStyle",n[n.InsertRow=37]="InsertRow",n[n.InsertColumn=38]="InsertColumn",n[n.DeleteRow=39]="DeleteRow",n[n.DeleteColumn=40]="DeleteColumn",n[n.EditExtraObject=41]="EditExtraObject",n[n.Delete=42]="Delete",n[n.RecoverHistory=43]="RecoverHistory",n[n.ViewHistory=44]="ViewHistory",n[n.CreatePermissionObject=45]="CreatePermissionObject",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(re||{}),ke=(n=>(n[n.Reader=0]="Reader",n[n.Editor=1]="Editor",n[n.Owner=2]="Owner",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(ke||{}),dt=(n=>(n[n.Unkonwn=0]="Unkonwn",n[n.Workbook=1]="Workbook",n[n.Worksheet=2]="Worksheet",n[n.SelectRange=3]="SelectRange",n[n.Document=4]="Document",n[n.Slide=5]="Slide",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(dt||{}),Ke=(n=>(n[n.SomeCollaborator=0]="SomeCollaborator",n[n.AllCollaborator=1]="AllCollaborator",n[n.OneSelf=2]="OneSelf",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(Ke||{});const or="UNIVER_SHEET_PERMISSION_PANEL",ai="UNIVER_SHEET_PERMISSION_USER_PART",Ds="UNIVER_SHEET_PERMISSION_BACKGROUND",Zl="UNIVER_SHEET_PERMISSION_USER_DIALOG",Kl="UNIVER_SHEET_PERMISSION_DIALOG",li="UNIVER_SHEET_PERMISSION_USER_DIALOG_ID",ci="UNIVER_SHEET_PERMISSION_DIALOG_ID",Br={[re.Copy]:"Copy",[re.SetCellStyle]:"SetCellStyle",[re.SetCellValue]:"SetCellValue",[re.SetRowStyle]:"SetRowStyle",[re.SetColumnStyle]:"SetColumnStyle",[re.InsertRow]:"InsertRow",[re.InsertColumn]:"InsertColumn",[re.InsertHyperlink]:"InsertHyperlink",[re.DeleteRow]:"DeleteRow",[re.DeleteColumn]:"DeleteColumn",[re.Sort]:"Sort",[re.Filter]:"Filter",[re.PivotTable]:"PivotTable",[re.EditExtraObject]:"EditExtraObject"},CS=[re.Copy,re.SetCellStyle,re.SetCellValue,re.SetRowStyle,re.SetColumnStyle,re.InsertRow,re.InsertColumn,re.InsertHyperlink,re.DeleteRow,re.DeleteColumn,re.Sort,re.Filter,re.PivotTable,re.EditExtraObject,re.View],ql="sheet-permission-menu-icon",_S="sheet-permission-delete-icon",IS="sheet-permission-edit-icon",bS="sheet-permission-check-icon",Ql="sheet-permission-lock-icon",RS={unitId:"",subUnitId:"",permissionId:"",unitType:m.UnitObject.SelectRange,id:"",ranges:[],viewState:m.ViewStateEnum.OthersCanView,editState:m.EditStateEnum.OnlyMe};class yn{constructor(){E(this,"_rule",RS);E(this,"_visible",!1)}setVisible(i){this._visible=i}getVisible(){return this._visible}reset(){this.setVisible(!1)}}class yt{constructor(){E(this,"_userList",[]);E(this,"_userList$",new O.BehaviorSubject(this._userList));E(this,"userList$",this._userList$.asObservable());E(this,"_oldCollaboratorList",[]);E(this,"_selectUserList",[]);E(this,"_selectUserList$",new O.BehaviorSubject(this._selectUserList));E(this,"selectUserList$",this._selectUserList$.asObservable())}get userList(){return this._userList}setCanEditUserList(i){this._userList=i,this._userList$.next(i)}reset(){this._userList=[],this._oldCollaboratorList=[],this._selectUserList=[],this._selectUserList$.next([])}get oldCollaboratorList(){return this._oldCollaboratorList}setOldCollaboratorList(i){this._oldCollaboratorList=i}get selectUserList(){return this._selectUserList}setSelectUserList(i){this._selectUserList=i,this._selectUserList$.next(i)}}const Qe={type:a.CommandType.OPERATION,id:"sheet-permission.operation.openPanel",async handler(n,i={}){const e=n.get(_.ISidebarService),t=n.get(yn),r=n.get(yt),{showDetail:o=!0,fromSheetBar:s=!1,rule:l,oldRule:c}=i,d={header:{title:"permission.panel.title"},children:{label:or,showDetail:o,fromSheetBar:s,rule:l,oldRule:c},width:330,onClose:()=>{t.reset(),r.reset()}};return t.setVisible(!0),e.open(d),!0}},Mr={type:a.CommandType.COMMAND,id:"sheet.command.add-range-protection-from-toolbar",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{showDetail:!0}),!0}},Wt={type:a.CommandType.COMMAND,id:"sheet.command.add-range-protection-from-context-menu",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{showDetail:!0}),!0}},Ut={type:a.CommandType.COMMAND,id:"sheet.command.view-sheet-permission-from-context-menu",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{showDetail:!1}),!0}},Pr={type:a.CommandType.COMMAND,id:"sheet.command.add-range-protection-from-sheet-bar",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{fromSheetBar:!0,showDetail:!0}),!0}},Or={type:a.CommandType.COMMAND,id:"sheet.command.view-sheet-permission-from-sheet-bar",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{showDetail:!1}),!0}},Lt={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-protection-from-context-menu",async handler(n){var h;const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(a.IUndoRedoService),r=n.get(m.SheetsSelectionsService),o=n.get(m.WorksheetProtectionRuleModel),s=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),l=s.getActiveSheet(),c=s.getUnitId(),d=l.getSheetId(),u=o.getRule(c,d);if(u!=null&&u.permissionId)return i.executeCommand(m.DeleteWorksheetProtectionCommand.id,{unitId:c,subUnitId:d,rule:u});{const g=(h=r.getCurrentLastSelection())==null?void 0:h.range;if(!g)return!1;const p=n.get(m.RangeProtectionRuleModel).getSubunitRuleList(c,d).find(v=>v.ranges.some(C=>a.Rectangle.intersects(C,g)));if(p){const v={unitId:c,subUnitId:d,ruleIds:[p.id]};return await i.executeCommand(m.DeleteRangeProtectionMutation.id,v)&&t.pushUndoRedo({unitID:c,redoMutations:[{id:m.DeleteRangeProtectionMutation.id,params:v}],undoMutations:[{id:m.AddRangeProtectionMutation.id,params:{unitId:c,subUnitId:d,rules:[p]}}]}),!0}else return!1}}},Bt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-protection-from-context-menu",async handler(n){var u;const i=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.WorksheetProtectionRuleModel),o=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=o.getActiveSheet(),l=o.getUnitId(),c=s.getSheetId(),d=r.getRule(l,c);if(d!=null&&d.permissionId){const h={...d,unitId:l,subUnitId:c,ranges:[]};return await i.executeCommand(Qe.id,{showDetail:!0,rule:a.Tools.deepClone(h),oldRule:a.Tools.deepClone(h)}),!0}else{const h=(u=t.getCurrentLastSelection())==null?void 0:u.range;if(!h)return!1;const f=n.get(m.RangeProtectionRuleModel).getSubunitRuleList(l,c).find(p=>{var v;return(v=p==null?void 0:p.ranges)==null?void 0:v.some(C=>a.Rectangle.intersects(C,h))});if(f){const p={...f,unitId:l,subUnitId:c};return await i.executeCommand(Qe.id,{showDetail:!0,rule:a.Tools.deepClone(p),oldRule:a.Tools.deepClone(p)}),!0}else return!1}}},Mn={id:"sheet.command.remove-row-confirm",type:a.CommandType.COMMAND,handler:async(n,i)=>{var d;const e=n.get(m.SheetsSelectionsService);let t=i==null?void 0:i.range;if(t||(t=(d=e.getCurrentLastSelection())==null?void 0:d.range),!t)return!1;const r=n.get(a.ICommandService),o=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(o);if(!s)return!1;const{worksheet:l}=s,c=l.getVisibleRows();if(Ka(c,[t])){const u=n.get(_.IConfirmService),h=n.get(a.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 r.executeCommand(m.RemoveRowCommand.id,{range:t}),!0}},Pn={id:"sheet.command.remove-col-confirm",type:a.CommandType.COMMAND,handler:async(n,i)=>{var d;const e=n.get(m.SheetsSelectionsService);let t=i==null?void 0:i.range;if(t||(t=(d=e.getCurrentLastSelection())==null?void 0:d.range),!t)return!1;const r=n.get(a.ICommandService),o=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(o);if(!s)return!1;const{worksheet:l}=s,c=l.getVisibleCols();if(qa(c,[t])){const u=n.get(_.IConfirmService),h=n.get(a.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 r.executeCommand(m.RemoveColCommand.id,{range:t}),!0}},xr={id:"sheet.command.remove-sheet-confirm",type:a.CommandType.COMMAND,handler:async(n,i)=>{const{subUnitId:e}=i,t=n.get(_.IConfirmService),r=n.get(a.ICommandService),o=n.get(a.LocaleService);return await t.confirm({id:"sheet.confirm.remove-sheet",title:{title:o.t("sheetConfig.deleteSheet")},children:{title:o.t("sheetConfig.deleteSheetContent")},cancelText:o.t("button.cancel"),confirmText:o.t("button.confirm")})?(await r.executeCommand(m.RemoveSheetCommand.id,{subUnitId:e}),!0):!1}},Ar={id:"ui-sheet.command.show-menu-list",type:a.CommandType.OPERATION,handler:async n=>(n.get(Kt).triggerSheetBarMenu(),!0)},kr={type:a.CommandType.COMMAND,id:"sheet.command.delete-worksheet-protection-from-sheet-bar",async handler(n,i){if(!i)return!1;const e=n.get(a.ICommandService),t=n.get(a.IUndoRedoService),r=n.get(m.WorksheetProtectionRuleModel),s=n.get(a.IUniverInstanceService).getCurrentUnitForType(Gl.UNIVER_SHEET),l=s==null?void 0:s.getActiveSheet(),c=s.getUnitId();if(!l)return!1;const d=l.getSheetId(),u=r.getRule(c,d);if(await e.executeCommand(m.DeleteWorksheetProtectionCommand.id,{unitId:c,subUnitId:d})){const g=[{id:m.DeleteWorksheetProtectionCommand.id,params:{unitId:c,subUnitId:d}}],S=[{id:m.AddWorksheetProtectionCommand.id,params:{unitId:c,rule:u}}];t.pushUndoRedo({unitID:c,redoMutations:g,undoMutations:S})}return!0}},Nr={type:a.CommandType.COMMAND,id:"sheet.command.change-sheet-protection-from-sheet-bar",async handler(n){return await n.get(a.ICommandService).executeCommand("sheet-permission.operation.openDialog"),!0}},Fi={id:"sheet.operation.set-activate-cell-edit",type:a.CommandType.OPERATION,handler:(n,i)=>(n.get(Se).setEditCell(i),!0)},Dr={id:"sheet.operation.rename-sheet",type:a.CommandType.OPERATION,handler:async(n,i)=>{const e=n.get(Kt);return i&&e.setRenameId(i.subUnitId),!0}},Hs={type:a.CommandType.OPERATION,id:"sheet-permission.operation.openDialog",async handler(n,i){const e=n.get(_.IDialogService);return e.close("DESKTOP_FIND_REPLACE_DIALOG"),e.open({id:ci,title:{title:"permission.dialog.allowedPermissionType"},children:{label:Kl},width:393,destroyOnClose:!0,onClose:()=>e.close(ci)}),!0}},ES=()=>I.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[I.jsx("path",{d:"M0.98999 1.08218H-0.0100098V0.0821838H0.98999V1.08218Z",fill:"black"}),I.jsx("path",{d:"M5.78992 1.08218H2.78992V0.0821838H5.78992V1.08218Z",fill:"black"}),I.jsx("path",{d:"M7.58984 1.08218H8.58984V0.0821838H7.58984V1.08218Z",fill:"black"}),I.jsx("path",{d:"M14.9152 1.08218H13.9152V0.0821838H14.9152V1.08218Z",fill:"black"}),I.jsx("path",{d:"M16.7151 1.08218H19.7151V0.0821838H16.7151V1.08218Z",fill:"black"}),I.jsx("path",{d:"M22.515 1.08218H21.515V0.0821838H22.515V1.08218Z",fill:"black"}),I.jsx("path",{d:"M27.8405 1.08218H28.8405V0.0821838H27.8405V1.08218Z",fill:"black"}),I.jsx("path",{d:"M33.6404 1.08218H30.6404V0.0821838H33.6404V1.08218Z",fill:"black"}),I.jsx("path",{d:"M35.4403 1.08218H36.4403V0.0821838H35.4403V1.08218Z",fill:"black"}),I.jsx("path",{d:"M42.7657 1.08218H41.7657V0.0821838H42.7657V1.08218Z",fill:"black"}),I.jsx("path",{d:"M44.5657 1.08218H47.5657V0.0821838H44.5657V1.08218Z",fill:"black"}),I.jsx("path",{d:"M50.3656 1.08218H49.3656V0.0821838H50.3656V1.08218Z",fill:"black"}),I.jsx("path",{d:"M55.691 1.08218H56.691V0.0821838H55.691V1.08218Z",fill:"black"}),I.jsx("path",{d:"M61.491 1.08218H58.491V0.0821838H61.491V1.08218Z",fill:"black"}),I.jsx("path",{d:"M63.2909 1.08218H64.2909V0.0821838H63.2909V1.08218Z",fill:"black"}),I.jsx("path",{d:"M70.6163 1.08218H69.6163V0.0821838H70.6163V1.08218Z",fill:"black"}),I.jsx("path",{d:"M72.4163 1.08218H75.4163V0.0821838H72.4163V1.08218Z",fill:"black"}),I.jsx("path",{d:"M78.2162 1.08218H77.2162V0.0821838H78.2162V1.08218Z",fill:"black"}),I.jsx("path",{d:"M83.5416 1.08218H84.5416V0.0821838H83.5416V1.08218Z",fill:"black"}),I.jsx("path",{d:"M89.3416 1.08218H86.3416V0.0821838H89.3416V1.08218Z",fill:"black"}),I.jsx("path",{d:"M91.1415 1.08218H92.1415V0.0821838H91.1415V1.08218Z",fill:"black"}),I.jsx("path",{d:"M98.4669 1.08218H97.4669V0.0821838H98.4669V1.08218Z",fill:"black"}),I.jsx("path",{d:"M100.267 1.08218H103.267V0.0821838H100.267V1.08218Z",fill:"black"}),I.jsx("path",{d:"M106.067 1.08218H105.067V0.0821838H106.067V1.08218Z",fill:"black"}),I.jsx("path",{d:"M111.392 1.08218H112.392V0.0821838H111.392V1.08218Z",fill:"black"}),I.jsx("path",{d:"M117.192 1.08218H114.192V0.0821838H117.192V1.08218Z",fill:"black"}),I.jsx("path",{d:"M118.992 1.08218H119.992V0.0821838H118.992V1.08218Z",fill:"black"})]}),wS=()=>I.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[I.jsx("path",{d:"M-0.0100098 1.15771H0.98999V0.157715H-0.0100098V1.15771Z",fill:"black"}),I.jsx("path",{d:"M2.78992 1.15771H5.78992V0.157715H2.78992V1.15771Z",fill:"black"}),I.jsx("path",{d:"M8.58984 1.15771H7.58984V0.157715H8.58984V1.15771Z",fill:"black"}),I.jsx("path",{d:"M10.3899 1.15771H11.3899V0.157715H10.3899V1.15771Z",fill:"black"}),I.jsx("path",{d:"M19.0903 1.15771H18.0903V0.157715H19.0903V1.15771Z",fill:"black"}),I.jsx("path",{d:"M20.8903 1.15771H23.8903V0.157715H20.8903V1.15771Z",fill:"black"}),I.jsx("path",{d:"M26.6902 1.15771H25.6902V0.157715H26.6902V1.15771Z",fill:"black"}),I.jsx("path",{d:"M28.4902 1.15771H29.4902V0.157715H28.4902V1.15771Z",fill:"black"}),I.jsx("path",{d:"M37.1907 1.15771H36.1907V0.157715H37.1907V1.15771Z",fill:"black"}),I.jsx("path",{d:"M38.9906 1.15771H41.9906V0.157715H38.9906V1.15771Z",fill:"black"}),I.jsx("path",{d:"M44.7905 1.15771H43.7905V0.157715H44.7905V1.15771Z",fill:"black"}),I.jsx("path",{d:"M46.5906 1.15771H47.5906V0.157715H46.5906V1.15771Z",fill:"black"}),I.jsx("path",{d:"M55.291 1.15771H54.291V0.157715H55.291V1.15771Z",fill:"black"}),I.jsx("path",{d:"M57.0909 1.15771H60.0909V0.157715H57.0909V1.15771Z",fill:"black"}),I.jsx("path",{d:"M62.8909 1.15771H61.8909V0.157715H62.8909V1.15771Z",fill:"black"}),I.jsx("path",{d:"M64.6909 1.15771H65.6909V0.157715H64.6909V1.15771Z",fill:"black"}),I.jsx("path",{d:"M73.3914 1.15771H72.3914V0.157715H73.3914V1.15771Z",fill:"black"}),I.jsx("path",{d:"M75.1913 1.15771H78.1913V0.157715H75.1913V1.15771Z",fill:"black"}),I.jsx("path",{d:"M80.9912 1.15771H79.9912V0.157715H80.9912V1.15771Z",fill:"black"}),I.jsx("path",{d:"M82.7913 1.15771H83.7913V0.157715H82.7913V1.15771Z",fill:"black"}),I.jsx("path",{d:"M91.4917 1.15771H90.4917V0.157715H91.4917V1.15771Z",fill:"black"}),I.jsx("path",{d:"M93.2916 1.15771H96.2916V0.157715H93.2916V1.15771Z",fill:"black"}),I.jsx("path",{d:"M99.0916 1.15771H98.0916V0.157715H99.0916V1.15771Z",fill:"black"}),I.jsx("path",{d:"M100.892 1.15771H101.892V0.157715H100.892V1.15771Z",fill:"black"}),I.jsx("path",{d:"M109.592 1.15771H108.592V0.157715H109.592V1.15771Z",fill:"black"}),I.jsx("path",{d:"M111.392 1.15771H114.392V0.157715H111.392V1.15771Z",fill:"black"}),I.jsx("path",{d:"M117.192 1.15771H116.192V0.157715H117.192V1.15771Z",fill:"black"}),I.jsx("path",{d:"M118.992 1.15771H119.992V0.157715H118.992V1.15771Z",fill:"black"})]}),TS=()=>I.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[I.jsx("path",{d:"M-0.00842285 1.22449H2.99158V0.224487H-0.00842285V1.22449Z",fill:"black"}),I.jsx("path",{d:"M6.14941 1.22449H9.14941V0.224487H6.14941V1.22449Z",fill:"black"}),I.jsx("path",{d:"M15.3073 1.22449H12.3073V0.224487H15.3073V1.22449Z",fill:"black"}),I.jsx("path",{d:"M18.4651 1.22449H21.4651V0.224487H18.4651V1.22449Z",fill:"black"}),I.jsx("path",{d:"M27.6229 1.22449H24.6229V0.224487H27.6229V1.22449Z",fill:"black"}),I.jsx("path",{d:"M30.7808 1.22449H33.7808V0.224487H30.7808V1.22449Z",fill:"black"}),I.jsx("path",{d:"M39.9386 1.22449H36.9386V0.224487H39.9386V1.22449Z",fill:"black"}),I.jsx("path",{d:"M43.0964 1.22449H46.0964V0.224487H43.0964V1.22449Z",fill:"black"}),I.jsx("path",{d:"M52.2543 1.22449H49.2543V0.224487H52.2543V1.22449Z",fill:"black"}),I.jsx("path",{d:"M55.4121 1.22449H58.4121V0.224487H55.4121V1.22449Z",fill:"black"}),I.jsx("path",{d:"M64.5699 1.22449H61.5699V0.224487H64.5699V1.22449Z",fill:"black"}),I.jsx("path",{d:"M67.7278 1.22449H70.7278V0.224487H67.7278V1.22449Z",fill:"black"}),I.jsx("path",{d:"M76.8856 1.22449H73.8856V0.224487H76.8856V1.22449Z",fill:"black"}),I.jsx("path",{d:"M80.0435 1.22449H83.0435V0.224487H80.0435V1.22449Z",fill:"black"}),I.jsx("path",{d:"M89.2013 1.22449H86.2013V0.224487H89.2013V1.22449Z",fill:"black"}),I.jsx("path",{d:"M92.3591 1.22449H95.3591V0.224487H92.3591V1.22449Z",fill:"black"}),I.jsx("path",{d:"M101.517 1.22449H98.517V0.224487H101.517V1.22449Z",fill:"black"}),I.jsx("path",{d:"M104.675 1.22449H107.675V0.224487H104.675V1.22449Z",fill:"black"}),I.jsx("path",{d:"M113.833 1.22449H110.833V0.224487H113.833V1.22449Z",fill:"black"}),I.jsx("path",{d:"M116.99 1.22449H119.99V0.224487H116.99V1.22449Z",fill:"black"})]}),yS=()=>I.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[I.jsx("path",{d:"M-0.00976562 1.65707H0.990234V0.657074H-0.00976562V1.65707Z",fill:"black"}),I.jsx("path",{d:"M2.32361 1.65707H3.32361V0.657074H2.32361V1.65707Z",fill:"black"}),I.jsx("path",{d:"M5.65698 1.65707H4.65698V0.657074H5.65698V1.65707Z",fill:"black"}),I.jsx("path",{d:"M6.99036 1.65707H7.99036V0.657074H6.99036V1.65707Z",fill:"black"}),I.jsx("path",{d:"M10.3237 1.65707H9.32373V0.657074H10.3237V1.65707Z",fill:"black"}),I.jsx("path",{d:"M11.6571 1.65707H12.6571V0.657074H11.6571V1.65707Z",fill:"black"}),I.jsx("path",{d:"M14.9905 1.65707H13.9905V0.657074H14.9905V1.65707Z",fill:"black"}),I.jsx("path",{d:"M16.3239 1.65707H17.3239V0.657074H16.3239V1.65707Z",fill:"black"}),I.jsx("path",{d:"M19.6572 1.65707H18.6572V0.657074H19.6572V1.65707Z",fill:"black"}),I.jsx("path",{d:"M20.9906 1.65707H21.9906V0.657074H20.9906V1.65707Z",fill:"black"}),I.jsx("path",{d:"M24.324 1.65707H23.324V0.657074H24.324V1.65707Z",fill:"black"}),I.jsx("path",{d:"M25.6573 1.65707H26.6573V0.657074H25.6573V1.65707Z",fill:"black"}),I.jsx("path",{d:"M28.9907 1.65707H27.9907V0.657074H28.9907V1.65707Z",fill:"black"}),I.jsx("path",{d:"M30.3241 1.65707H31.3241V0.657074H30.3241V1.65707Z",fill:"black"}),I.jsx("path",{d:"M33.6575 1.65707H32.6575V0.657074H33.6575V1.65707Z",fill:"black"}),I.jsx("path",{d:"M34.9908 1.65707H35.9908V0.657074H34.9908V1.65707Z",fill:"black"}),I.jsx("path",{d:"M38.3242 1.65707H37.3242V0.657074H38.3242V1.65707Z",fill:"black"}),I.jsx("path",{d:"M39.6576 1.65707H40.6576V0.657074H39.6576V1.65707Z",fill:"black"}),I.jsx("path",{d:"M42.991 1.65707H41.991V0.657074H42.991V1.65707Z",fill:"black"}),I.jsx("path",{d:"M44.3243 1.65707H45.3243V0.657074H44.3243V1.65707Z",fill:"black"}),I.jsx("path",{d:"M47.6577 1.65707H46.6577V0.657074H47.6577V1.65707Z",fill:"black"}),I.jsx("path",{d:"M48.9911 1.65707H49.9911V0.657074H48.9911V1.65707Z",fill:"black"}),I.jsx("path",{d:"M52.3245 1.65707H51.3245V0.657074H52.3245V1.65707Z",fill:"black"}),I.jsx("path",{d:"M53.6578 1.65707H54.6578V0.657074H53.6578V1.65707Z",fill:"black"}),I.jsx("path",{d:"M56.9912 1.65707H55.9912V0.657074H56.9912V1.65707Z",fill:"black"}),I.jsx("path",{d:"M58.3246 1.65707H59.3246V0.657074H58.3246V1.65707Z",fill:"black"}),I.jsx("path",{d:"M61.658 1.65707H60.658V0.657074H61.658V1.65707Z",fill:"black"}),I.jsx("path",{d:"M62.9913 1.65707H63.9913V0.657074H62.9913V1.65707Z",fill:"black"}),I.jsx("path",{d:"M66.3247 1.65707H65.3247V0.657074H66.3247V1.65707Z",fill:"black"}),I.jsx("path",{d:"M67.6581 1.65707H68.6581V0.657074H67.6581V1.65707Z",fill:"black"}),I.jsx("path",{d:"M70.9915 1.65707H69.9915V0.657074H70.9915V1.65707Z",fill:"black"}),I.jsx("path",{d:"M72.3248 1.65707H73.3248V0.657074H72.3248V1.65707Z",fill:"black"}),I.jsx("path",{d:"M75.6582 1.65707H74.6582V0.657074H75.6582V1.65707Z",fill:"black"}),I.jsx("path",{d:"M76.9916 1.65707H77.9916V0.657074H76.9916V1.65707Z",fill:"black"}),I.jsx("path",{d:"M80.325 1.65707H79.325V0.657074H80.325V1.65707Z",fill:"black"}),I.jsx("path",{d:"M81.6583 1.65707H82.6583V0.657074H81.6583V1.65707Z",fill:"black"}),I.jsx("path",{d:"M84.9917 1.65707H83.9917V0.657074H84.9917V1.65707Z",fill:"black"}),I.jsx("path",{d:"M86.3251 1.65707H87.3251V0.657074H86.3251V1.65707Z",fill:"black"}),I.jsx("path",{d:"M89.6584 1.65707H88.6584V0.657074H89.6584V1.65707Z",fill:"black"}),I.jsx("path",{d:"M90.9918 1.65707H91.9918V0.657074H90.9918V1.65707Z",fill:"black"}),I.jsx("path",{d:"M94.3252 1.65707H93.3252V0.657074H94.3252V1.65707Z",fill:"black"}),I.jsx("path",{d:"M95.6586 1.65707H96.6586V0.657074H95.6586V1.65707Z",fill:"black"}),I.jsx("path",{d:"M98.9919 1.65707H97.9919V0.657074H98.9919V1.65707Z",fill:"black"}),I.jsx("path",{d:"M100.325 1.65707H101.325V0.657074H100.325V1.65707Z",fill:"black"}),I.jsx("path",{d:"M103.659 1.65707H102.659V0.657074H103.659V1.65707Z",fill:"black"}),I.jsx("path",{d:"M104.992 1.65707H105.992V0.657074H104.992V1.65707Z",fill:"black"}),I.jsx("path",{d:"M108.325 1.65707H107.325V0.657074H108.325V1.65707Z",fill:"black"}),I.jsx("path",{d:"M109.659 1.65707H110.659V0.657074H109.659V1.65707Z",fill:"black"}),I.jsx("path",{d:"M112.992 1.65707H111.992V0.657074H112.992V1.65707Z",fill:"black"}),I.jsx("path",{d:"M114.325 1.65707H115.325V0.657074H114.325V1.65707Z",fill:"black"}),I.jsx("path",{d:"M117.659 1.65707H116.659V0.657074H117.659V1.65707Z",fill:"black"}),I.jsx("path",{d:"M118.992 1.65707H119.992V0.657074H118.992V1.65707Z",fill:"black"})]}),MS=()=>I.jsx("svg",{width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:I.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 2.42035H-0.0090332V0.420349H119.991V2.42035Z",fill:"black"})}),PS=()=>I.jsxs("svg",{width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[I.jsx("path",{d:"M-0.0100098 2.47614H1.98999V0.476135H-0.0100098V2.47614Z",fill:"black"}),I.jsx("path",{d:"M3.99014 2.47614H9.99014V0.476135H3.99014V2.47614Z",fill:"black"}),I.jsx("path",{d:"M13.9901 2.47614H11.9901V0.476135H13.9901V2.47614Z",fill:"black"}),I.jsx("path",{d:"M21.1904 2.47614H23.1904V0.476135H21.1904V2.47614Z",fill:"black"}),I.jsx("path",{d:"M31.1906 2.47614H25.1906V0.476135H31.1906V2.47614Z",fill:"black"}),I.jsx("path",{d:"M33.1906 2.47614H35.1906V0.476135H33.1906V2.47614Z",fill:"black"}),I.jsx("path",{d:"M44.3909 2.47614H42.3909V0.476135H44.3909V2.47614Z",fill:"black"}),I.jsx("path",{d:"M46.391 2.47614H52.391V0.476135H46.391V2.47614Z",fill:"black"}),I.jsx("path",{d:"M56.391 2.47614H54.391V0.476135H56.391V2.47614Z",fill:"black"}),I.jsx("path",{d:"M63.5913 2.47614H65.5913V0.476135H63.5913V2.47614Z",fill:"black"}),I.jsx("path",{d:"M73.5915 2.47614H67.5915V0.476135H73.5915V2.47614Z",fill:"black"}),I.jsx("path",{d:"M75.5915 2.47614H77.5915V0.476135H75.5915V2.47614Z",fill:"black"}),I.jsx("path",{d:"M86.7917 2.47614H84.7917V0.476135H86.7917V2.47614Z",fill:"black"}),I.jsx("path",{d:"M88.7919 2.47614H94.7919V0.476135H88.7919V2.47614Z",fill:"black"}),I.jsx("path",{d:"M98.7919 2.47614H96.7919V0.476135H98.7919V2.47614Z",fill:"black"}),I.jsx("path",{d:"M105.992 2.47614H107.992V0.476135H105.992V2.47614Z",fill:"black"}),I.jsx("path",{d:"M115.992 2.47614H109.992V0.476135H115.992V2.47614Z",fill:"black"}),I.jsx("path",{d:"M117.992 2.47614H119.992V0.476135H117.992V2.47614Z",fill:"black"})]}),OS=()=>I.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[I.jsx("path",{d:"M-0.0100098 2.00415H1.98999V0.00415039H-0.0100098V2.00415Z",fill:"black"}),I.jsx("path",{d:"M3.99014 2.00415H9.99014V0.00415039H3.99014V2.00415Z",fill:"black"}),I.jsx("path",{d:"M13.9901 2.00415H11.9901V0.00415039H13.9901V2.00415Z",fill:"black"}),I.jsx("path",{d:"M15.9901 2.00415H17.9901V0.00415039H15.9901V2.00415Z",fill:"black"}),I.jsx("path",{d:"M27.4905 2.00415H25.4905V0.00415039H27.4905V2.00415Z",fill:"black"}),I.jsx("path",{d:"M29.4906 2.00415H35.4906V0.00415039H29.4906V2.00415Z",fill:"black"}),I.jsx("path",{d:"M39.4906 2.00415H37.4906V0.00415039H39.4906V2.00415Z",fill:"black"}),I.jsx("path",{d:"M41.4906 2.00415H43.4906V0.00415039H41.4906V2.00415Z",fill:"black"}),I.jsx("path",{d:"M52.991 2.00415H50.991V0.00415039H52.991V2.00415Z",fill:"black"}),I.jsx("path",{d:"M54.9911 2.00415H60.9911V0.00415039H54.9911V2.00415Z",fill:"black"}),I.jsx("path",{d:"M64.9911 2.00415H62.9911V0.00415039H64.9911V2.00415Z",fill:"black"}),I.jsx("path",{d:"M66.9911 2.00415H68.9911V0.00415039H66.9911V2.00415Z",fill:"black"}),I.jsx("path",{d:"M78.4915 2.00415H76.4915V0.00415039H78.4915V2.00415Z",fill:"black"}),I.jsx("path",{d:"M80.4916 2.00415H86.4916V0.00415039H80.4916V2.00415Z",fill:"black"}),I.jsx("path",{d:"M90.4916 2.00415H88.4916V0.00415039H90.4916V2.00415Z",fill:"black"}),I.jsx("path",{d:"M92.4916 2.00415H94.4916V0.00415039H92.4916V2.00415Z",fill:"black"}),I.jsx("path",{d:"M103.992 2.00415H101.992V0.00415039H103.992V2.00415Z",fill:"black"}),I.jsx("path",{d:"M105.992 2.00415H111.992V0.00415039H105.992V2.00415Z",fill:"black"}),I.jsx("path",{d:"M115.992 2.00415H113.992V0.00415039H115.992V2.00415Z",fill:"black"}),I.jsx("path",{d:"M117.992 2.00415H119.992V0.00415039H117.992V2.00415Z",fill:"black"})]}),xS=()=>I.jsxs("svg",{width:"118",height:"3",viewBox:"0 0 118 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[I.jsx("path",{d:"M-0.00854492 2.94815H1.99146V0.948151H-0.00854492V2.94815Z",fill:"black"}),I.jsx("path",{d:"M6.09668 2.94815H8.09668V0.948151H6.09668V2.94815Z",fill:"black"}),I.jsx("path",{d:"M14.2019 2.94815H12.2019V0.948151H14.2019V2.94815Z",fill:"black"}),I.jsx("path",{d:"M18.3071 2.94815H20.3071V0.948151H18.3071V2.94815Z",fill:"black"}),I.jsx("path",{d:"M26.4124 2.94815H24.4124V0.948151H26.4124V2.94815Z",fill:"black"}),I.jsx("path",{d:"M30.5176 2.94815H32.5176V0.948151H30.5176V2.94815Z",fill:"black"}),I.jsx("path",{d:"M38.6228 2.94815H36.6228V0.948151H38.6228V2.94815Z",fill:"black"}),I.jsx("path",{d:"M42.728 2.94815H44.728V0.948151H42.728V2.94815Z",fill:"black"}),I.jsx("path",{d:"M50.8333 2.94815H48.8333V0.948151H50.8333V2.94815Z",fill:"black"}),I.jsx("path",{d:"M54.9385 2.94815H56.9385V0.948151H54.9385V2.94815Z",fill:"black"}),I.jsx("path",{d:"M63.0437 2.94815H61.0437V0.948151H63.0437V2.94815Z",fill:"black"}),I.jsx("path",{d:"M67.1489 2.94815H69.1489V0.948151H67.1489V2.94815Z",fill:"black"}),I.jsx("path",{d:"M75.2542 2.94815H73.2542V0.948151H75.2542V2.94815Z",fill:"black"}),I.jsx("path",{d:"M79.3594 2.94815H81.3594V0.948151H79.3594V2.94815Z",fill:"black"}),I.jsx("path",{d:"M87.4645 2.94815H85.4645V0.948151H87.4645V2.94815Z",fill:"black"}),I.jsx("path",{d:"M91.5697 2.94815H93.5697V0.948151H91.5697V2.94815Z",fill:"black"}),I.jsx("path",{d:"M99.6749 2.94815H97.6749V0.948151H99.6749V2.94815Z",fill:"black"}),I.jsx("path",{d:"M103.78 2.94815H105.78V0.948151H103.78V2.94815Z",fill:"black"}),I.jsx("path",{d:"M111.885 2.94815H109.885V0.948151H111.885V2.94815Z",fill:"black"}),I.jsx("path",{d:"M115.991 2.94815H117.991V0.948151H115.991V2.94815Z",fill:"black"})]}),AS=()=>I.jsx("svg",{width:"120",height:"4",viewBox:"0 0 120 4",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:I.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 3.86215H-0.0090332V0.862152H119.991V3.86215Z",fill:"black"})}),ya=()=>I.jsx("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:I.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 1.15668H-0.0090332V0.156677H119.991V1.15668Z",fill:"black"})});function Ma(n){const{type:i=a.BorderStyleTypes.THIN}=n;switch(i){case a.BorderStyleTypes.DASH_DOT:return I.jsx(ES,{});case a.BorderStyleTypes.DASH_DOT_DOT:return I.jsx(wS,{});case a.BorderStyleTypes.DASHED:return I.jsx(TS,{});case a.BorderStyleTypes.HAIR:return I.jsx(yS,{});case a.BorderStyleTypes.MEDIUM:return I.jsx(MS,{});case a.BorderStyleTypes.MEDIUM_DASH_DOT:return I.jsx(PS,{});case a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT:return I.jsx(OS,{});case a.BorderStyleTypes.MEDIUM_DASHED:return I.jsx(xS,{});case a.BorderStyleTypes.THICK:return I.jsx(AS,{});case a.BorderStyleTypes.THIN:return I.jsx(ya,{});default:return I.jsx(ya,{})}}const Vs=`${Nn}_BORDER_PANEL_COMPONENT`,Jl=[{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:"HorizontalBorder",value:"horizontal"},{label:"borderLine.borderVertical",icon:"VerticalBorder",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"}],kS=[{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 $l(n){var l;const i=_.useDependency(_.ComponentManager),e=_.useDependency(m.BorderStyleManagerService),{onChange:t,value:r}=n;function o(c,d){t==null||t({...r,[d]:c})}function s(c){const d=i.get(c);return d&&I.jsx(d,{extend:{colorChannel1:"#2c53f1"}})}return I.jsxs("section",{className:"univer-box-border univer-grid univer-gap-2 univer-p-1.5",children:[I.jsx("div",{className:"univer-box-border univer-grid univer-grid-cols-5 univer-gap-2",children:Jl.map(c=>I.jsx("a",{className:Y.clsx(`
59
59
  univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center
60
60
  univer-justify-self-center univer-rounded
61
61
  hover:univer-bg-gray-100