@univerjs/sheets-ui 0.12.3-experimental.20251205-71d07c3 → 0.12.3-nightly.202512060617

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/umd/index.js CHANGED
@@ -9,7 +9,7 @@
9
9
  `)}),o}function _u(n){return a.isNotNullOrUndefined(n.displayV)?n.displayV:a.extractPureTextFromCell(n)}function bu(n,o,e,t){return t.getMergeData().some(i=>i.startRow<=n&&n<i.endRow&&o<=i.startColumn&&i.startColumn<=e)}function wu(n,o,e,t){return t.getMergeData().some(i=>i.startColumn<=n&&n<i.endColumn&&o<=i.startRow&&i.startRow<=e)}function Eu(n){let o=0;return n.forValue((e,t,i)=>{if(i&&o++,o>1)return!1}),o>1}function Qn(){return{p:null,v:null,s:null,f:null,si:null,t:null}}const ar=998,He={id:I.CopyCommand.id,name:"sheet.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:ar,preconditions:$o,handler:async n=>n.get(Ne).copy()},ji={id:I.CutCommand.id,name:"sheet.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:ar,preconditions:$o,handler:async n=>n.get(Ne).cut()},We={id:I.PasteCommand.id,type:a.CommandType.COMMAND,multi:!0,name:"sheet.command.paste",priority:ar,preconditions:$o,handler:async(n,o)=>{const t=await n.get(I.IClipboardInterfaceService).read(),i=n.get(Ne);return t.length!==0?i.paste(t[0],o==null?void 0:o.value):!1}},Zi={id:I.SheetPasteShortKeyCommandName,type:a.CommandType.COMMAND,handler:async(n,o)=>{const e=n.get(Ne),{htmlContent:t,textContent:i,files:r}=o;return e.legacyPaste(t,i,r),!0}},on={id:"sheet.command.paste-value",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(We.id,{value:ge.SPECIAL_PASTE_VALUE})},rn={id:"sheet.command.paste-format",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(We.id,{value:ge.SPECIAL_PASTE_FORMAT})},Et={id:"sheet.command.paste-col-width",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(We.id,{value:ge.SPECIAL_PASTE_COL_WIDTH})},sn={id:"sheet.command.paste-besides-border",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(We.id,{value:ge.SPECIAL_PASTE_BESIDES_BORDER})},ca={id:"sheet.command.optional-paste",type:a.CommandType.COMMAND,handler:async(n,{type:o})=>n.get(Ne).rePasteWithPasteType(o)},an={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-move-left-confirm",handler:async n=>{const o=n.get(I.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),i=n.get(m.SheetsSelectionsService),r=n.get(a.IUniverInstanceService),s=i.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(r);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 o.confirm({id:an.id,title:{title:t.t("merge.confirm.warning")},children:{title:t.t("merge.confirm.dismantleMergeCellWarning")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.DeleteRangeMoveLeftCommand.id):!0}},Tt={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-move-up-confirm",handler:async n=>{const o=n.get(I.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),i=n.get(m.SheetsSelectionsService),r=n.get(a.IUniverInstanceService),s=i.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(r);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 o.confirm({id:Tt.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 o.confirm({id:Tt.id,title:{title:t.t("merge.confirm.warning")},children:{title:t.t("merge.confirm.dismantleMergeCellWarning")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.DeleteRangeMoveUpCommand.id):!0}};var Gi=(n=>(n.MergeAll="mergeAll",n.MergeVertical="mergeVertical",n.MergeHorizontal="mergeHorizontal",n))(Gi||{});function ut(n,o,e,t,i=!0,r=1,s=!0){let l={...n};t==null&&(t={startRow:0,endRow:e.getRowCount()-1,startColumn:0,endColumn:e.getColumnCount()-1});let c;switch(o){case a.Direction.UP:for(c=n.startRow-r;c>-1&&!e.getRowVisible(c);)c-=1;c>=t.startRow?(l.startRow=c,l.endRow=c):s&&(l.startRow=t.endRow,l.endRow=t.endRow,i&&(l=ut(l,a.Direction.LEFT,e,t,!1)));break;case a.Direction.DOWN:for(c=n.endRow+r;c<e.getRowCount()&&!e.getRowVisible(c);)c+=1;c<=t.endRow?(l.startRow=c,l.endRow=c):s&&(l.startRow=t.startRow,l.endRow=t.startRow,i&&(l=ut(l,a.Direction.RIGHT,e,t,!1)));break;case a.Direction.LEFT:for(c=n.startColumn-r;c>-1&&!e.getColVisible(c);)c-=1;c>=t.startColumn?(l.startColumn=c,l.endColumn=c):s&&(l.startColumn=t.endColumn,l.endColumn=t.endColumn,i&&(l=ut(l,a.Direction.UP,e,t,!1)));break;case a.Direction.RIGHT:for(c=n.endColumn+r;c<e.getColumnCount()&&!e.getColVisible(c);)c+=1;c<=t.endColumn?(l.startColumn=c,l.endColumn=c):s&&(l.startColumn=t.startColumn,l.endColumn=t.startColumn,i&&(l=ut(l,a.Direction.DOWN,e,t,!1)));break}return l}function lr(n,o,e){const t={...n},{startRow:i,startColumn:r,endRow:s,endColumn:l}=Jn(n,o,e);let c=$n(e,i,r,s,l).hasValue,d=!0,u=!0;for(;u;){if(a.Direction.UP===o){let h=t.startRow-1;for(;h>-1&&!e.getRowVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:g,matrix:S}=$n(e,h,t.startColumn,h,t.endColumn);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue(v=>{f=Math.min(v,f)}),t.startRow=f}else t.startRow=h;if(t.endRow=t.startRow,!c&&g){u=!1;break}c=g,d=!1}}if(a.Direction.DOWN===o){let h=t.endRow+1;for(;h<e.getRowCount()&&!e.getRowVisible(h);)h+=1;if(h===e.getRowCount()){u=!1;break}const{hasValue:g,matrix:S}=$n(e,h,t.startColumn,h,t.endColumn);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((v,p,C)=>{f=Math.max(v+(C.rowSpan||1)-1,f)}),t.endRow=f}else t.endRow=h;if(t.startRow=t.endRow,!c&&g){u=!1;break}c=g,d=!1}}if(a.Direction.LEFT===o){let h=t.startColumn-1;for(;h>-1&&!e.getColVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:g,matrix:S}=$n(e,t.startRow,h,t.endRow,h);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((v,p)=>{f=Math.min(p,f)}),t.startColumn=f}else t.startColumn=h;if(t.endColumn=t.startColumn,!c&&g){u=!1;break}c=g,d=!1}}if(a.Direction.RIGHT===o){let h=t.endColumn+1;for(;h<e.getColumnCount()&&!e.getColVisible(h);)h+=1;if(h===e.getColumnCount()){u=!1;break}const{hasValue:g,matrix:S}=$n(e,t.startRow,h,t.endRow,h);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((v,p,C)=>{f=Math.max(p+(C.colSpan||1)-1,f)}),t.endColumn=f}else t.endColumn=h;if(t.startColumn=t.endColumn,!c&&g){u=!1;break}c=g,d=!1}}}return m.alignToMergedCellsBorders(t,e,!0)}function da(n,o,e){return ut(n,o,e,void 0,!1,1,!1)}function Tu(n,o,e){const t=lr(n,o,e);return m.alignToMergedCellsBorders(a.Rectangle.union(t,n),e,!0)}function yu(n,o,e){const t=da(n,o,e),i={startRow:Math.min(n.startRow,t.startRow),startColumn:Math.min(n.startColumn,t.startColumn),endRow:Math.max(n.endRow,t.endRow),endColumn:Math.max(n.endColumn,t.endColumn)};return m.alignToMergedCellsBorders(a.Rectangle.union(n,i),e)}function Ru(n,o,e,t){const i=a.getReverseDirection(e),r=lr(Jn(n,i,t),e,t);return e===a.Direction.UP&&r.startRow<=n.startRow?m.alignToMergedCellsBorders({...o,startColumn:n.startColumn,endColumn:n.endColumn},t,!0):e===a.Direction.DOWN&&r.endRow>=n.endRow?m.alignToMergedCellsBorders({...o,startColumn:n.startColumn,endColumn:n.endColumn},t,!0):e===a.Direction.LEFT&&r.startColumn<=n.startColumn?m.alignToMergedCellsBorders({...o,startRow:n.startRow,endRow:n.endRow},t,!0):e===a.Direction.RIGHT&&r.endColumn>=n.endColumn?m.alignToMergedCellsBorders({...o,startRow:n.startRow,endRow:n.endRow},t,!0):a.Rectangle.union(a.Rectangle.clone(o),r)}function Mu(n,o,e){const t=a.getReverseDirection(o),i=Jn(n,t,e),r=Jn(n,o,e),s=da(i,o,e);return m.alignToMergedCellsBorders(a.Rectangle.union(r,s),e,!1)}function ua(n){return{startRow:0,startColumn:0,endRow:n.getRowCount()-1,endColumn:n.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL}}function Jn(n,o,e){let t;switch(o){case a.Direction.UP:t={startRow:n.startRow,startColumn:n.startColumn,endRow:n.startRow,endColumn:n.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.DOWN:t={startRow:n.endRow,startColumn:n.startColumn,endRow:n.endRow,endColumn:n.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.LEFT:t={startRow:n.startRow,startColumn:n.startColumn,endRow:n.endRow,endColumn:n.startColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.RIGHT:t={startRow:n.startRow,startColumn:n.endColumn,endRow:n.endRow,endColumn:n.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;default:throw new Error("Invalid direction")}return m.alignToMergedCellsBorders(t,e,!1)}function $n(n,o,e,t,i){let r=!1;const s=n.getMatrixWithMergedCells(o,e,t,i).forValue((l,c,d)=>{if(Ou(d))return r=!0,!1});return{hasValue:r,matrix:s}}function cr(n,o,e){const t=a.Rectangle.clone(n);if(o==null)return t;switch(e){case a.Direction.UP:case a.Direction.DOWN:t.startColumn=t.endColumn=o.actualColumn;break;case a.Direction.LEFT:case a.Direction.RIGHT:t.startRow=t.endRow=o.actualRow;break}return t}function Pu(n,o,e){var l,c,d,u;const{primary:t,range:i}=n,r=a.Rectangle.clone(i);switch(o){case a.Direction.UP:case a.Direction.DOWN:r.startRow=(l=t==null?void 0:t.startRow)!=null?l:i.startRow,r.endRow=(c=t==null?void 0:t.endRow)!=null?c:i.startRow;break;case a.Direction.LEFT:case a.Direction.RIGHT:r.startColumn=(d=t==null?void 0:t.startColumn)!=null?d:i.startColumn,r.endColumn=(u=t==null?void 0:t.endColumn)!=null?u:i.startColumn;break}const s=Jn(r,o,e);switch(o){case a.Direction.DOWN:return i.startRow<s.startRow;case a.Direction.UP:return i.endRow>s.endRow;case a.Direction.LEFT:return s.endColumn<i.endColumn;case a.Direction.RIGHT:return s.startColumn>i.startColumn}}function ha(n,o){let e=n[0].startRow,t=n[0].endRow;n.forEach(r=>{const{startRow:s,endRow:l}=r;e=Math.min(e,s),t=Math.max(t,l)});const i=new Array(t-e+1).fill(!1);return o.forEach(r=>{const{startRow:s,endRow:l}=r;for(let c=Math.max(s,e);c<=Math.min(l,t);c++)i[c-e]=!0}),n.every(r=>{const{startRow:s,endRow:l}=r;for(let c=s;c<=l;c++)if(!i[c-e])return!1;return!0})}function ma(n,o){let e=n[0].startColumn,t=n[0].endColumn;n.forEach(r=>{const{startColumn:s,endColumn:l}=r;e=Math.min(e,s),t=Math.max(t,l)});const i=new Array(t-e+1).fill(!1);return o.forEach(r=>{const{startColumn:s,endColumn:l}=r;for(let c=Math.max(s,e);c<=Math.min(l,t);c++)i[c-e]=!0}),n.every(r=>{const{startColumn:s,endColumn:l}=r;for(let c=s;c<=l;c++)if(!i[c-e])return!1;return!0})}function dr(n,o){return o?n==="mergeAll"?o.filter(e=>!(e.startRow===e.endRow&&e.startColumn===e.endColumn)):n==="mergeVertical"?o.filter(e=>e.startRow!==e.endRow):n==="mergeHorizontal"?o.filter(e=>e.startColumn!==e.endColumn):o:null}function Ou(n){return n.v!==void 0&&n.v!==null&&n.v!==""||n.p!==void 0}const ei={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),i=n.get(a.IUniverInstanceService),r=m.getSheetCommandTarget(i);if(!r)return!1;const{worksheet:s}=r,l=s.getVisibleRows();if(ha(l,e)){const d=n.get(I.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}},ti={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),i=n.get(a.IUniverInstanceService),r=m.getSheetCommandTarget(i);if(!r)return!1;const{worksheet:s}=r,l=s.getVisibleCols();if(ma(l,e)){const d=n.get(I.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}};function yt(n){var c;const o=n.get(a.IUniverInstanceService),e=n.get(Ce.DocSelectionManagerService),t=o.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),i=e.getActiveTextRange();if(t==null||i==null)return null;const r=(c=t.getBody())==null?void 0:c.textRuns;if(r==null)return;const{startOffset:s}=i;return r.find(({st:d,ed:u})=>s>=d&&s<=u)}const Rt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-bold",handler:async n=>{const o=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?o.executeCommand(K.SetInlineFormatBoldCommand.id):o.executeCommand(m.SetBoldCommand.id)}},Mt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-italic",handler:async n=>{const o=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?o.executeCommand(K.SetInlineFormatItalicCommand.id):o.executeCommand(m.SetItalicCommand.id)}},Pt={type:a.CommandType.COMMAND,id:"sheet.command.set-range-underline",handler:async n=>{const o=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?o.executeCommand(K.SetInlineFormatUnderlineCommand.id):o.executeCommand(m.SetUnderlineCommand.id)}},Ot={type:a.CommandType.COMMAND,id:"sheet.command.set-range-stroke",handler:async n=>{const o=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?o.executeCommand(K.SetInlineFormatStrikethroughCommand.id):o.executeCommand(m.SetStrikeThroughCommand.id)}},ur={type:a.CommandType.COMMAND,id:"sheet.command.set-range-subscript",handler:async n=>{const o=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?o.executeCommand(K.SetInlineFormatSubscriptCommand.id):!1}},hr={type:a.CommandType.COMMAND,id:"sheet.command.set-range-superscript",handler:async n=>{const o=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?o.executeCommand(K.SetInlineFormatSuperscriptCommand.id):!1}},ni={type:a.CommandType.COMMAND,id:"sheet.command.set-range-fontsize",handler:async(n,o)=>{const e=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(K.SetInlineFormatFontSizeCommand.id,o):e.executeCommand(m.SetFontSizeCommand.id,o)}},Ki={type:a.CommandType.COMMAND,id:"sheet.command.set-range-font-increase",handler:async n=>{var h,g,S,f;const o=n.get(a.IUniverInstanceService),e=n.get(a.ICommandService),i=n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED),r=n.get(m.SheetsSelectionsService),s=a.DEFAULT_STYLES.fs,c=o.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet(),d=(h=r.getCurrentLastSelection())==null?void 0:h.primary,u={value:s};if(i){const v=yt(n);if(v!=null){const p=(S=(g=v.ts)==null?void 0:g.fs)!=null?S:s;u.value=p>=400?400:p+1}return e.executeCommand(K.SetInlineFormatFontSizeCommand.id,u)}if(d!=null){const p=(f=c.getComposedCellStyle(d.startRow,d.startColumn).fs)!=null?f:s;return u.value=p>=400?400:p+1,e.executeCommand(m.SetFontSizeCommand.id,u)}return!1}},qi={type:a.CommandType.COMMAND,id:"sheet.command.set-range-font-decrease",handler:async n=>{var h,g,S,f;const o=n.get(a.IUniverInstanceService),e=n.get(a.ICommandService),i=n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED),r=n.get(m.SheetsSelectionsService),s=a.DEFAULT_STYLES.fs,c=o.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet(),d=(h=r.getCurrentLastSelection())==null?void 0:h.primary,u={value:s};if(i){const v=yt(n);if(v!=null){const p=(S=(g=v.ts)==null?void 0:g.fs)!=null?S:s;u.value=p<=6?6:p-1}return e.executeCommand(K.SetInlineFormatFontSizeCommand.id,u)}if(d!=null){const p=(f=c.getComposedCellStyle(d.startRow,d.startColumn).fs)!=null?f:s;return u.value=p<=6?6:p-1,e.executeCommand(m.SetFontSizeCommand.id,u)}return!1}},ln={type:a.CommandType.COMMAND,id:"sheet.command.set-range-font-family",handler:async(n,o)=>{const e=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(K.SetInlineFormatFontFamilyCommand.id,o):e.executeCommand(m.SetFontFamilyCommand.id,o)}},cn={type:a.CommandType.COMMAND,id:"sheet.command.set-range-text-color",handler:async(n,o)=>{const e=n.get(a.ICommandService);return n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED)?e.executeCommand(K.SetInlineFormatTextColorCommand.id,o):e.executeCommand(m.SetTextColorCommand.id,o)}},Qi={type:a.CommandType.COMMAND,id:"sheet.command.reset-range-text-color",handler:async n=>{const o=n.get(a.ICommandService),t=n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED),i=n.get(a.ThemeService);return t?o.executeCommand(K.SetInlineFormatTextColorCommand.id,{value:null}):o.executeCommand(m.SetTextColorCommand.id,{value:i.getColorFromTheme("gray.900")})}},At={type:a.CommandType.COMMAND,id:"sheet.command.insert-range-move-down-confirm",handler:async n=>{const o=n.get(I.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),i=n.get(m.SheetsSelectionsService),r=n.get(a.IUniverInstanceService),s=i.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(r);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 o.confirm({id:At.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 o.confirm({id:At.id,title:{title:t.t("merge.confirm.warning")},children:{title:t.t("merge.confirm.dismantleMergeCellWarning")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.InsertRangeMoveDownCommand.id):!0}},dn={type:a.CommandType.COMMAND,id:"sheet.command.insert-range-move-right-confirm",handler:async n=>{const o=n.get(I.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),i=n.get(m.SheetsSelectionsService),r=n.get(a.IUniverInstanceService),s=i.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(r);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 o.confirm({id:dn.id,title:{title:t.t("merge.confirm.warning")},children:{title:t.t("merge.confirm.dismantleMergeCellWarning")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.InsertRangeMoveRightCommand.id):!0}};var ga=(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))(ga||{}),$=(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))($||{}),Oe=(n=>(n[n.Reader=0]="Reader",n[n.Editor=1]="Editor",n[n.Owner=2]="Owner",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(Oe||{}),Qe=(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))(Qe||{}),xe=(n=>(n[n.SomeCollaborator=0]="SomeCollaborator",n[n.AllCollaborator=1]="AllCollaborator",n[n.OneSelf=2]="OneSelf",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(xe||{});const ii="UNIVER_SHEET_PERMISSION_PANEL",oi="UNIVER_SHEET_PERMISSION_USER_PART",Sa="UNIVER_SHEET_PERMISSION_USER_DIALOG",fa="UNIVER_SHEET_PERMISSION_DIALOG",Ji="UNIVER_SHEET_PERMISSION_USER_DIALOG_ID",$i="UNIVER_SHEET_PERMISSION_DIALOG_ID",eo={[$.Copy]:"Copy",[$.SetCellStyle]:"SetCellStyle",[$.SetCellValue]:"SetCellValue",[$.SetRowStyle]:"SetRowStyle",[$.SetColumnStyle]:"SetColumnStyle",[$.InsertRow]:"InsertRow",[$.InsertColumn]:"InsertColumn",[$.InsertHyperlink]:"InsertHyperlink",[$.DeleteRow]:"DeleteRow",[$.DeleteColumn]:"DeleteColumn",[$.Sort]:"Sort",[$.Filter]:"Filter",[$.PivotTable]:"PivotTable",[$.EditExtraObject]:"EditExtraObject"},Au=[$.Copy,$.SetCellStyle,$.SetCellValue,$.SetRowStyle,$.SetColumnStyle,$.InsertRow,$.InsertColumn,$.InsertHyperlink,$.DeleteRow,$.DeleteColumn,$.Sort,$.Filter,$.PivotTable,$.EditExtraObject,$.View],va="sheet-permission-menu-icon",Du="sheet-permission-delete-icon",ku="sheet-permission-edit-icon",Nu="sheet-permission-check-icon",pa="sheet-permission-lock-icon",Vu={unitId:"",subUnitId:"",permissionId:"",unitType:m.UnitObject.SelectRange,id:"",ranges:[],viewState:m.ViewStateEnum.OthersCanView,editState:m.EditStateEnum.OnlyMe};class Dt{constructor(){y(this,"_rule",Vu);y(this,"_visible",!1)}setVisible(o){this._visible=o}getVisible(){return this._visible}reset(){this.setVisible(!1)}}class ht{constructor(){y(this,"_userList",[]);y(this,"_userList$",new D.BehaviorSubject(this._userList));y(this,"userList$",this._userList$.asObservable());y(this,"_oldCollaboratorList",[]);y(this,"_selectUserList",[]);y(this,"_selectUserList$",new D.BehaviorSubject(this._selectUserList));y(this,"selectUserList$",this._selectUserList$.asObservable())}get userList(){return this._userList}setCanEditUserList(o){this._userList=o,this._userList$.next(o)}reset(){this._userList=[],this._oldCollaboratorList=[],this._selectUserList=[],this._selectUserList$.next([])}get oldCollaboratorList(){return this._oldCollaboratorList}setOldCollaboratorList(o){this._oldCollaboratorList=o}get selectUserList(){return this._selectUserList}setSelectUserList(o){this._selectUserList=o,this._selectUserList$.next(o)}}const Ue={type:a.CommandType.OPERATION,id:"sheet-permission.operation.openPanel",async handler(n,o={}){const e=n.get(I.ISidebarService),t=n.get(Dt),i=n.get(ht),{showDetail:r=!0,fromSheetBar:s=!1,rule:l,oldRule:c}=o,d={header:{title:"permission.panel.title"},children:{label:ii,showDetail:r,fromSheetBar:s,rule:l,oldRule:c},width:330,onClose:()=>{t.reset(),i.reset()}};return t.setVisible(!0),e.open(d),!0}},ri={type:a.CommandType.COMMAND,id:"sheet.command.add-range-protection-from-toolbar",async handler(n){return await n.get(a.ICommandService).executeCommand(Ue.id,{showDetail:!0}),!0}},kt={type:a.CommandType.COMMAND,id:"sheet.command.add-range-protection-from-context-menu",async handler(n){return await n.get(a.ICommandService).executeCommand(Ue.id,{showDetail:!0}),!0}},Nt={type:a.CommandType.COMMAND,id:"sheet.command.view-sheet-permission-from-context-menu",async handler(n){return await n.get(a.ICommandService).executeCommand(Ue.id,{showDetail:!1}),!0}},si={type:a.CommandType.COMMAND,id:"sheet.command.add-range-protection-from-sheet-bar",async handler(n){return await n.get(a.ICommandService).executeCommand(Ue.id,{fromSheetBar:!0,showDetail:!0}),!0}},ai={type:a.CommandType.COMMAND,id:"sheet.command.view-sheet-permission-from-sheet-bar",async handler(n){return await n.get(a.ICommandService).executeCommand(Ue.id,{showDetail:!1}),!0}},Vt={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-protection-from-context-menu",async handler(n){var h;const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(a.IUndoRedoService),i=n.get(m.SheetsSelectionsService),r=n.get(m.WorksheetProtectionRuleModel),s=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),l=s.getActiveSheet(),c=s.getUnitId(),d=l.getSheetId(),u=r.getRule(c,d);if(u!=null&&u.permissionId)return o.executeCommand(m.DeleteWorksheetProtectionCommand.id,{unitId:c,subUnitId:d,rule:u});{const g=(h=i.getCurrentLastSelection())==null?void 0:h.range;if(!g)return!1;const v=n.get(m.RangeProtectionRuleModel).getSubunitRuleList(c,d).find(p=>p.ranges.some(C=>a.Rectangle.intersects(C,g)));if(v){const p={unitId:c,subUnitId:d,ruleIds:[v.id]};return await o.executeCommand(m.DeleteRangeProtectionMutation.id,p)&&t.pushUndoRedo({unitID:c,redoMutations:[{id:m.DeleteRangeProtectionMutation.id,params:p}],undoMutations:[{id:m.AddRangeProtectionMutation.id,params:{unitId:c,subUnitId:d,rules:[v]}}]}),!0}else return!1}}},Ht={type:a.CommandType.COMMAND,id:"sheet.command.set-range-protection-from-context-menu",async handler(n){var u;const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(m.WorksheetProtectionRuleModel),r=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=r.getActiveSheet(),l=r.getUnitId(),c=s.getSheetId(),d=i.getRule(l,c);if(d!=null&&d.permissionId){const h={...d,unitId:l,subUnitId:c,ranges:[]};return await o.executeCommand(Ue.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(v=>{var p;return(p=v==null?void 0:v.ranges)==null?void 0:p.some(C=>a.Rectangle.intersects(C,h))});if(f){const v={...f,unitId:l,subUnitId:c};return await o.executeCommand(Ue.id,{showDetail:!0,rule:a.Tools.deepClone(v),oldRule:a.Tools.deepClone(v)}),!0}else return!1}}},li={id:"sheet.command.refill",type:a.CommandType.COMMAND,handler:async(n,o)=>n.get(ct).fillData(o.type)},un={id:"sheet.command.remove-row-confirm",type:a.CommandType.COMMAND,handler:async(n,o)=>{var d;const e=n.get(m.SheetsSelectionsService);let t=o==null?void 0:o.range;if(t||(t=(d=e.getCurrentLastSelection())==null?void 0:d.range),!t)return!1;const i=n.get(a.ICommandService),r=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(r);if(!s)return!1;const{worksheet:l}=s,c=l.getVisibleRows();if(ha(c,[t])){const u=n.get(I.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 i.executeCommand(m.RemoveRowCommand.id,{range:t}),!0}},hn={id:"sheet.command.remove-col-confirm",type:a.CommandType.COMMAND,handler:async(n,o)=>{var d;const e=n.get(m.SheetsSelectionsService);let t=o==null?void 0:o.range;if(t||(t=(d=e.getCurrentLastSelection())==null?void 0:d.range),!t)return!1;const i=n.get(a.ICommandService),r=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(r);if(!s)return!1;const{worksheet:l}=s,c=l.getVisibleCols();if(ma(c,[t])){const u=n.get(I.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 i.executeCommand(m.RemoveColCommand.id,{range:t}),!0}},ci={id:"sheet.command.remove-sheet-confirm",type:a.CommandType.COMMAND,handler:async(n,o)=>{const{subUnitId:e}=o,t=n.get(I.IConfirmService),i=n.get(a.ICommandService),r=n.get(a.LocaleService),s=n.get(a.IConfigService),l=n.get(a.IUniverInstanceService),c=m.getSheetCommandTarget(l,{subUnitId:e});if(!c)return!1;const{worksheet:d}=c,u=s.getConfig(m.SHEETS_PLUGIN_CONFIG_KEY),h={...m.defaultLargeSheetOperationConfig,...u==null?void 0:u.largeSheetOperation},S=m.countCells(d.getCellMatrix())>=h.largeSheetCellCountThreshold;return await t.confirm({id:"sheet.confirm.remove-sheet",title:{title:r.t("sheetConfig.deleteSheet")},children:{title:S?r.t("sheetConfig.deleteLargeSheetContent"):r.t("sheetConfig.deleteSheetContent")},cancelText:r.t("button.cancel"),confirmText:r.t("button.confirm")})?(await i.executeCommand(m.RemoveSheetCommand.id,{subUnitId:e}),!0):!1}};var Hu=Object.getOwnPropertyDescriptor,Wu=(n,o,e,t)=>{for(var i=t>1?void 0:t?Hu(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},mn=(n,o)=>(e,t)=>o(e,t,n),Ae=(n=>(n[n.OFF=0]="OFF",n[n.ONCE=1]="ONCE",n[n.INFINITE=2]="INFINITE",n))(Ae||{});const Be=a.createIdentifier("univer.format-painter-service");let to=class extends a.Disposable{constructor(o,e,t,i,r,s){super();y(this,"status$");y(this,"_selectionFormat");y(this,"_markId",null);y(this,"_status$");y(this,"_defaultHook",null);y(this,"_extendHooks",[]);this._selectionManagerService=o,this._themeService=e,this._markSelectionService=t,this._logService=i,this._commandService=r,this._undoRedoService=s,this._status$=new D.BehaviorSubject(0),this.status$=this._status$.asObservable(),this._selectionFormat={styles:new a.ObjectMatrix,merges:[]}}addHook(o){var e,t,i;o.isDefaultHook&&((e=o.priority)!=null?e:0)>((i=(t=this._defaultHook)==null?void 0:t.priority)!=null?i:-1)?this._defaultHook=o:(this._extendHooks.push(o),this._extendHooks.sort((r,s)=>(r.priority||0)-(s.priority||0)))}getHooks(){return this._defaultHook?[this._defaultHook,...this._extendHooks]:this._extendHooks}setStatus(o){this._updateRangeMark(o),this._status$.next(o),this.getHooks().forEach(t=>{t.onStatusChange!==void 0&&t.onStatusChange(o)})}getStatus(){return this._status$.getValue()}setSelectionFormat(o){this._selectionFormat=o}getSelectionFormat(){return this._selectionFormat}applyFormatPainter(o,e,t){const i=this.getHooks(),r=[],s=[];i.forEach(c=>{if(c.onApply!==void 0){const d=c.onApply(o,e,t,this._selectionFormat);d&&(r.push(...d.redos),s.push(...d.undos))}});for(const c of i)if(c.onBeforeApply!==void 0&&!c.onBeforeApply({unitId:o,subUnitId:e,range:t,redoMutationsInfo:r,format:this._selectionFormat,undoMutationsInfo:s}))return!1;this._logService.log("[FormatPainterService]","apply mutations",{undoMutationsInfo:s,redoMutationsInfo:r});const l=r.every(c=>this._commandService.executeCommand(c.id,c.params));return l&&this._undoRedoService.pushUndoRedo({unitID:o,undoMutations:s,redoMutations:r}),l}_updateRangeMark(o){if(this._markSelectionService.removeAllShapes(),o!==0){const e=this._selectionManagerService.getCurrentLastSelection();if(e){const t=qs(this._themeService);o===2?this._markId=this._markSelectionService.addShape({...e,style:t}):this._markId=this._markSelectionService.addShape({...e,style:t},[m.SetRangeValuesMutation.id])}}}};to=Wu([mn(0,a.Inject(m.SheetsSelectionsService)),mn(1,a.Inject(a.ThemeService)),mn(2,wt),mn(3,a.ILogService),mn(4,a.ICommandService),mn(5,a.IUndoRedoService)],to);const di={id:"sheet.operation.set-format-painter",type:a.CommandType.OPERATION,handler:(n,o)=>o?(n.get(Be).setStatus(o.status),!0):!1},no={type:a.CommandType.COMMAND,id:"sheet.command.set-infinite-format-painter",handler:async n=>{const e=n.get(Be).getStatus();let t;return e!==Ae.OFF?t=Ae.OFF:t=Ae.INFINITE,n.get(a.ICommandService).executeCommand(di.id,{status:t})}},gn={type:a.CommandType.COMMAND,id:"sheet.command.set-once-format-painter",handler:async n=>{const e=n.get(Be).getStatus();let t;return e!==Ae.OFF?t=Ae.OFF:t=Ae.ONCE,n.get(a.ICommandService).executeCommand(di.id,{status:t})}},ui={type:a.CommandType.COMMAND,id:"sheet.command.apply-format-painter",handler:async(n,o)=>n.get(Be).applyFormatPainter(o.unitId,o.subUnitId,o.range)};var Lu=Object.getOwnPropertyDescriptor,xu=(n,o,e,t)=>{for(var i=t>1?void 0:t?Lu(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},Uu=(n,o)=>(e,t)=>o(e,t,n);T.SheetScrollManagerService=class{constructor(o,e){y(this,"_scrollStateMap",new Map);y(this,"_rawScrollInfo$",new D.BehaviorSubject(null));y(this,"rawScrollInfo$",this._rawScrollInfo$.asObservable());y(this,"validViewportScrollInfo$",new D.BehaviorSubject(null));y(this,"_searchParamForScroll",null);this._context=o,this._sheetSkeletonManagerService=e}dispose(){this._rawScrollInfo$.complete()}calcViewportScrollFromRowColOffset(o){if(!o)return{viewportScrollX:0,viewportScrollY:0};let{sheetViewStartColumn:e,sheetViewStartRow:t,offsetX:i,offsetY:r}=o;t=t||0,r=r||0;const s=this._sheetSkeletonManagerService.getCurrentSkeleton(),l=(s==null?void 0:s.rowHeightAccumulation[t-1])||0,d=((s==null?void 0:s.columnWidthAccumulation[e-1])||0)+i,u=l+r;return{viewportScrollX:d,viewportScrollY:u}}setSearchParam(o){this._searchParamForScroll=o}getScrollStateByParam(o){return this._getCurrentScroll(o)}getCurrentScrollState(){return this._getCurrentScroll(this._searchParamForScroll)}setValidScrollState(o){this._setScrollState(o)}emitRawScrollParam(o){this._emitRawScroll(o)}setValidScrollStateToCurrSheet(o){if(this._searchParamForScroll==null)return;this._setScrollState({...this._searchParamForScroll,...o});const e=this._searchParamForScroll.sheetId,t=this._sheetSkeletonManagerService.getSkeleton(e);t&&t.setScroll(o.viewportScrollX,o.viewportScrollY)}clear(){this._searchParamForScroll!=null&&this._clearByParamAndNotify(this._searchParamForScroll)}_setScrollState(o){const{unitId:e,sheetId:t,sheetViewStartColumn:i,sheetViewStartRow:r,offsetX:s,offsetY:l}=o;this._scrollStateMap.has(e)||this._scrollStateMap.set(e,new Map);const c=this._scrollStateMap.get(e),d={sheetViewStartRow:r,sheetViewStartColumn:i,offsetX:s,offsetY:l};c.set(t,d)}_clearByParamAndNotify(o){this._setScrollState({...o,sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0}),this._emitRawScroll({sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0})}_getCurrentScroll(o){var s;const e={sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0};if(o==null)return e;const{unitId:t,sheetId:i}=o;return((s=this._scrollStateMap.get(t))==null?void 0:s.get(i))||e}_emitRawScroll(o){this._rawScrollInfo$.next(o)}},T.SheetScrollManagerService=xu([Uu(1,a.Inject(T.SheetSkeletonManagerService))],T.SheetScrollManagerService);const Je={type:a.CommandType.COMMAND,id:"sheet.command.set-selection-frozen",handler:async(n,o)=>{const{type:e}=o||{},t=n.get(a.IUniverInstanceService),i=n.get(a.IUndoRedoService),r=m.getSheetCommandTarget(t);if(!r)return!1;const{unitId:s,subUnitId:l}=r,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(M.IRenderManagerService).getRenderById(s).with(T.SheetScrollManagerService),{sheetViewStartRow:v=0,sheetViewStartColumn:p=0}=f.getCurrentScrollState()||{};let C,_,w,E;const{startRow:O,startColumn:R,rangeType:P}=g;if(P===a.RANGE_TYPE.ROW||e===1)C=O,w=O-v,_=-1,E=0;else if(P===a.RANGE_TYPE.COLUMN||e===2)C=-1,w=0,_=R,E=R-p;else if(P===a.RANGE_TYPE.NORMAL)C=O,w=O-v,_=R,E=R-p;else return!1;const A={unitId:s,subUnitId:l,startRow:C,startColumn:_,xSplit:_>0?Math.max(1,E):E,ySplit:C>0?Math.max(1,w):w},k=m.SetFrozenMutationFactory(n,A);return c.syncExecuteCommand(m.SetFrozenMutation.id,A)&&i.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetFrozenMutation.id,params:k}],redoMutations:[{id:m.SetFrozenMutation.id,params:A}]}),!0}},hi={type:a.CommandType.COMMAND,id:"sheet.command.set-row-frozen",handler:async n=>(n.get(a.ICommandService).executeCommand(Je.id,{type:1}),!0)},mi={type:a.CommandType.COMMAND,id:"sheet.command.set-col-frozen",handler:async n=>(n.get(a.ICommandService).executeCommand(Je.id,{type:2}),!0)};class mr extends a.Disposable{constructor(){super(...arguments);y(this,"rangesStack",[]);y(this,"selectedRangeWorksheet","")}}var Bu=Object.getOwnPropertyDescriptor,Fu=(n,o,e,t)=>{for(var i=t>1?void 0:t?Bu(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},Ca=(n,o)=>(e,t)=>o(e,t,n);let Sn=class{constructor(n,o){y(this,"_current",null);y(this,"_shortcutParam",[]);this._univerInstanceService=n,this._localeService=o}dispose(){this._shortcutParam=[]}getCurrentBySearch(n){return this._getCurrentBySearch(n)}getCurrent(){return this._getCurrentBySearch(this._current)}addOrUpdate(n){const o=this._getCurrentBySearch({unitId:n.unitId,sheetId:n.sheetId,keycode:n.keycode});if(o!=null){const e=this._shortcutParam.indexOf(o);this._shortcutParam.splice(e,1)}return this._shortcutParam.push(n),o}remove(n){if(n==null)return;const o=this._getCurrentBySearch(n);if(o==null)return;const e=this._shortcutParam.indexOf(o);return this._shortcutParam.splice(e,1)[0]}_getCurrentBySearch(n){return n==null?void 0:this._shortcutParam.find(e=>e.unitId===n.unitId&&e.sheetId===n.sheetId&&e.keycode===n.keycode)}};Sn=Fu([Ca(0,a.IUniverInstanceService),Ca(1,a.Inject(a.LocaleService))],Sn);var Fe=(n=>(n[n.moveStopeOne=0]="moveStopeOne",n[n.moveGap=1]="moveGap",n[n.moveStepPage=2]="moveStepPage",n[n.moveStepEnd=3]="moveStepEnd",n))(Fe||{});const Pe={id:"sheet.command.move-selection",type:a.CommandType.COMMAND,handler:(n,o)=>{if(!o)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{workbook:t,worksheet:i}=e,r=m.getSelectionsService(n,o.fromCurrentSelection).getCurrentLastSelection();if(!r)return!1;const{direction:s,jumpOver:l,extra:c}=o,{range:d,primary:u}=r,h=cr(d,u,s),g=l===1?lr(h,s,i):ut(h,s,i),S=m.getCellAtRowCol(g.startRow,g.startColumn,i);if(a.Rectangle.equals(S,h))return!1;const f=t.getUnitId();n.get(Sn).remove({unitId:f,sheetId:i.getSheetId(),keycode:I.KeyCode.TAB});const v=[{range:a.Rectangle.clone(S),primary:{startRow:S.startRow,startColumn:S.startColumn,endRow:S.endRow,endColumn:S.endColumn,actualRow:g.startRow,actualColumn:g.startColumn,isMerged:S.isMerged,isMergedMainCell:S.startRow===g.startRow&&S.startColumn===g.startColumn}}];return n.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:t.getUnitId(),subUnitId:i.getSheetId(),selections:v,type:m.SelectionMoveType.MOVE_END,extra:c,reveal:!0})}},ze={id:"sheet.command.move-selection-enter-tab",type:a.CommandType.COMMAND,handler:(n,o)=>{var B;if(!o)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{workbook:t,worksheet:i}=e,r=m.getSelectionsService(n),{direction:s,keycode:l}=o,c=s===a.Direction.LEFT||s===a.Direction.UP,d=r.getCurrentSelections().concat(),u=d.findIndex(U=>U.primary),h=d[u];if(!h)return!1;const g=c?-1:1,S=u+g!==d.length?d[u+g]:d[0],f=d.findIndex(U=>U===S),v=t.getUnitId(),p=i.getSheetId();if(!h)return!1;const{range:C}=h,_=h.primary;let w=cr(C,_,s);const E=n.get(Sn),O=E.getCurrentBySearch({unitId:v,sheetId:p,keycode:I.KeyCode.TAB});let R;const{startRow:P,endRow:A,startColumn:k,endColumn:N}=C,V=c?_.startRow===P&&_.startColumn===k:_.endRow===A&&_.endColumn===N;if(a.Rectangle.equals(C,_)){if(l===I.KeyCode.TAB)O==null&&E.addOrUpdate({unitId:v,sheetId:p,keycode:I.KeyCode.TAB,selection:h});else{const F=O==null?void 0:O.selection;if(F!=null){const{range:Y,primary:j}=F;w=cr(Y,j,s)}E.remove({unitId:v,sheetId:p,keycode:I.KeyCode.TAB})}const U=ut(w,s,i),X=m.getCellAtRowCol(U.startRow,U.startColumn,i);if(a.Rectangle.equals(X,w))return!1;R={range:a.Rectangle.clone(X),primary:{startRow:X.startRow,startColumn:X.startColumn,endRow:X.endRow,endColumn:X.endColumn,actualRow:U.startRow,actualColumn:U.startColumn,isMerged:X.isMerged,isMergedMainCell:X.startRow===U.startRow&&X.startColumn===U.startColumn}}}else{E.remove({unitId:v,sheetId:p,keycode:I.KeyCode.TAB});const U=a.Tools.deepClone(_),X=V?S.range:ut({startRow:U.startRow,startColumn:U.startColumn,endRow:U.endRow,endColumn:U.endColumn},s,i,{startRow:P,endRow:A,startColumn:k,endColumn:N}),F=V&&c,Y=F?m.getCellAtRowCol(X.endRow,X.endColumn,i):m.getCellAtRowCol(X.startRow,X.startColumn,i);R={range:V?S.range:a.Rectangle.clone(C),primary:{startRow:Y.startRow,startColumn:Y.startColumn,endRow:Y.endRow,endColumn:Y.endColumn,actualRow:F?Y.startRow:X.startRow,actualColumn:F?Y.startColumn:X.startColumn,isMerged:Y.isMerged,isMergedMainCell:Y.startRow===X.startRow&&Y.startColumn===X.startColumn},style:V?S.style:h.style}}V?(d[u].primary=null,d[f]=R,r.setSelections(v,p,[],m.SelectionMoveType.MOVE_END)):d[u]=R;const L=n.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:v,subUnitId:p,type:m.SelectionMoveType.MOVE_END,selections:d,reveal:!0,extra:o.extra}),W=(B=n.get(M.IRenderManagerService).getRenderById(v))==null?void 0:B.with(Ie);return W==null||W.refreshSelectionMoveEnd(),L}},De={id:"sheet.command.expand-selection",type:a.CommandType.COMMAND,handler:(n,o)=>{if(!o)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{worksheet:t,unitId:i,subUnitId:r}=e,s=m.getSelectionsService(n).getCurrentLastSelection();if(!s)return!1;const{range:l,primary:c}=s,{jumpOver:d,direction:u,extra:h}=o,S=Pu(s,u,t)?d===1?Ru(l,{...a.Rectangle.clone(c),rangeType:a.RANGE_TYPE.NORMAL},u,t):Mu(l,u,t):d===1?Tu(l,u,t):yu(l,u,t);return S.rangeType=s.range.rangeType,a.Rectangle.equals(S,l)?!1:n.get(a.ICommandService).syncExecuteCommand(m.SetSelectionsOperation.id,{unitId:i,subUnitId:r,type:m.SelectionMoveType.MOVE_END,selections:[{range:S,primary:c}],extra:h,reveal:!0})}},gi={id:"sheet.command.select-all",type:a.CommandType.COMMAND,handler:async(n,o={expandToGapFirst:!0,loop:!1})=>{const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const t=m.getSelectionsService(n).getCurrentLastSelection();if(!t)return!1;const i=n.get(mr),{worksheet:r,unitId:s,subUnitId:l}=e,c=`${s}|${l}`;c!==i.selectedRangeWorksheet&&(i.rangesStack=[],i.selectedRangeWorksheet=c);const d=r.getMaxRows(),u=r.getMaxColumns(),{expandToGapFirst:h,loop:g}=o,{range:S,primary:f}=t,v=S.endColumn===u-1&&S.endRow===d-1&&S.startRow===0&&S.startColumn===0;i.rangesStack.some(O=>a.Rectangle.equals(O,S))||(i.rangesStack=[],i.rangesStack.push(S));let p;if(v)if(g){if(i.rangesStack.findIndex(R=>a.Rectangle.equals(R,S))!==i.rangesStack.length-1)return!1;p=i.rangesStack[0]}else return!1;else h?(p=m.expandToContinuousRange(S,{left:!0,right:!0,up:!0,down:!0},r),a.Rectangle.equals(p,S)&&(p=ua(r))):p=ua(r);i.rangesStack.some(O=>a.Rectangle.equals(O,p))||i.rangesStack.push(p);const C=[];C.push({id:m.SetSelectionsOperation.id,params:{unitId:s,subUnitId:l,reveal:!0,selections:[{range:p,primary:f}]}});const w=n.get(m.SheetInterceptorService).onCommandExecute({id:gi.id,params:{range:S}});w.redos.length&&C.push(...w.redos);const E=n.get(a.ICommandService);return a.sequenceExecute(C,E),!0}};function zu(n){return typeof n.isMainScene>"u"}function Ve(n,o){const e=n instanceof a.Workbook?n:n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!e)return null;const t=e.getUnitId();let i,r,s,l;if(zu(o)){const g=o.getRenderById(t);if(g==null)return null;i=g.components,i=g.components,r=g.mainComponent,s=g.scene,l=g.engine}else i=o.components,r=o.mainComponent,s=o.scene,l=o.engine;if(!i||!r)return null;const c=r,d=i.get(he.ROW),u=i.get(he.COLUMN),h=i.get(he.LEFT_TOP);return{spreadsheet:c,spreadsheetRowHeader:d,spreadsheetColumnHeader:u,spreadsheetLeftTopPlaceholder:h,scene:s,engine:l}}function gr(n,o,e,t){const{startX:i,startY:r,endX:s,endY:l}=t.getCellWithCoordByIndex(n,o);return{startX:i,startY:r,endX:s,endY:l}}function Xe(n,o,e,t,i,r){const s=e.getCoordRelativeToViewport(M.Vector2.FromArray([n,o])),{x:l,y:c}=s,d=e.getScrollXYInfoByViewport(s,i),{scaleX:u,scaleY:h}=e.getAncestorScale(),g=t.getCellIndexByOffset(l,c,u,h,d,{closeFirst:r}),{row:S,column:f}=g,v=t.getNoMergeCellWithCoordByIndex(S,f),{startX:p,startY:C,endX:_,endY:w}=v;return{startX:p,startY:C,endX:_,endY:w,row:S,column:f}}function Si(n,o,e,t){const i=e.getCoordRelativeToViewport(M.Vector2.FromArray([n,o])),r=e.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN),s=e.getScrollXYInfoByViewport(i,r),{scaleX:l,scaleY:c}=e.getAncestorScale(),{x:d,y:u}=s,h=n/l+d,g=o/c+u;return{x:h,y:g}}var Xu=Object.getOwnPropertyDescriptor,Yu=(n,o,e,t)=>{for(var i=t>1?void 0:t?Xu(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},fn=(n,o)=>(e,t)=>o(e,t,n);Pe.id,ze.id;const ju=3;T.SheetsScrollRenderController=class extends a.Disposable{constructor(o,e,t,i,r,s,l){super(),this._context=o,this._injector=e,this._sheetSkeletonManagerService=t,this._contextService=i,this._commandService=r,this._renderManagerService=s,this._scrollManagerService=l,this._initCommandListener(),this._wheelEventListener(),this._scrollBarEventListener(),this._initSkeletonListener()}_wheelEventListener(){const{scene:o}=this._context;if(!o)return;const e=o.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN);e&&this.disposeWithMe(o.onMouseWheel$.subscribeEvent((t,i)=>{if(t.ctrlKey||!this._contextService.getContextValue(a.FOCUSING_SHEET))return;let r=0,s=0;r=t.deltaX,t.shiftKey?r=(t.deltaY||t.deltaX)*ju:s=t.deltaY,this._commandService.executeCommand(vn.id,{offsetX:r,offsetY:s}),this._context.scene.makeDirty(!0);const l=e.limitedScroll(e.scrollX+r,e.scrollY+s);l&&!l.isLimitedX&&!l.isLimitedY&&(t.preventDefault(),o.getParent().classType===M.RENDER_CLASS_TYPE.SCENE_VIEWER&&i.stopPropagation()),e.isWheelPreventDefaultX&&e.isWheelPreventDefaultY&&t.preventDefault()}))}_scrollBarEventListener(){const{scene:o}=this._context;if(o==null)return;const e=o.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN);e&&(this.disposeWithMe(a.toDisposable(this._scrollManagerService.rawScrollInfo$.subscribe(t=>{var f;const i=(f=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:f.skeleton;if(!i)return;if(t==null){e.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});return}const{sheetViewStartRow:r,sheetViewStartColumn:s,offsetX:l,offsetY:c,duration:d}=t,{startX:u,startY:h}=i.getCellWithCoordByIndex(r,s,!1),g=u+l,S=h+c;e.scrollAnimationFrameId!==null&&cancelAnimationFrame(e.scrollAnimationFrameId),d?this._smoothScrollToViewportPos({viewportMain:e,viewportScrollX:g,viewportScrollY:S,duration:d}):e.scrollToViewportPos({viewportScrollX:g,viewportScrollY:S})}))),this.disposeWithMe(e.onScrollAfter$.subscribeEvent(t=>{var v;const i=(v=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:v.skeleton;if(i==null||t.isTrigger===!1)return;const r=this._getSheetObject();if(i==null||r==null)return;const{viewportScrollX:s,viewportScrollY:l,scrollX:c,scrollY:d}=t,{row:u,column:h,rowOffset:g,columnOffset:S}=i.getOffsetRelativeToRowCol(s,l),f={sheetViewStartRow:u,sheetViewStartColumn:h,offsetX:S,offsetY:g,viewportScrollX:s,viewportScrollY:l,scrollX:c,scrollY:d};this._scrollManagerService.setValidScrollStateToCurrSheet(f),this._scrollManagerService.validViewportScrollInfo$.next({...f,viewportScrollX:s,viewportScrollY:l,scrollX:c,scrollY:d})})),this.disposeWithMe(e.onScrollByBar$.subscribeEvent(t=>{var g;const i=(g=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:g.skeleton;if(i==null||t.isTrigger===!1)return;const r=this._getSheetObject();if(i==null||r==null)return;const{viewportScrollX:s=0,viewportScrollY:l=0}=t;this._getFreeze();const{row:c,column:d,rowOffset:u,columnOffset:h}=i.getOffsetRelativeToRowCol(s,l);this._commandService.executeCommand(Le.id,{sheetViewStartRow:c,sheetViewStartColumn:d,offsetX:h,offsetY:u})})))}_initSkeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeletonBefore$.subscribe(o=>{if(o==null)return;const e={unitId:o.unitId,sheetId:o.sheetId};if(this._scrollManagerService.setSearchParam(e),!this._getSheetObject())return;const i=this._scrollManagerService.getScrollStateByParam(e),{viewportScrollX:r,viewportScrollY:s}=this._scrollManagerService.calcViewportScrollFromRowColOffset(i);i&&this._updateViewportScroll(r,s)})))}_smoothScrollToViewportPos(o){const{viewportMain:e,viewportScrollX:t,viewportScrollY:i,duration:r}=o,s=performance.now(),l=e.viewportScrollX,c=e.viewportScrollY,d=t-l,u=i-c;function h(g){const S=g-s,f=Math.min(S/r,1),v=1-(1-f)**3,p=l+d*v,C=c+u*v;e.scrollToViewportPos({viewportScrollX:p,viewportScrollY:C}),f<1?e.scrollAnimationFrameId=requestAnimationFrame(h):e.scrollAnimationFrameId=null}e.scrollAnimationFrameId=requestAnimationFrame(h)}_updateViewportScroll(o=0,e=0){const t=this._getSheetObject();if(!t)return;const i=t.scene,r=i.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN),s=i.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT),l=i.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM),c=i.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT),d=i.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);r&&(r.viewportScrollX=o,r.viewportScrollY=e),l&&(l.viewportScrollY=e),s&&(s.viewportScrollX=o),c&&(c.viewportScrollY=e),d&&(d.viewportScrollX=o)}scrollToRange(o,e,t){let{endRow:i,endColumn:r,startColumn:s,startRow:l}=o;const c=this._getViewportBounding();if(o.rangeType===a.RANGE_TYPE.ROW?(s=0,r=0):o.rangeType===a.RANGE_TYPE.COLUMN&&(l=0,i=0),c&&!e&&!t){const d=c.startRow>i?l:i,u=c.startColumn>r?s:r;return this._scrollToCell(d,u)}else return this._scrollToCell(l,s,e,t)}scrollToCell(o,e,t){const i=this._context.unit.getActiveSheet(),{ySplit:r,xSplit:s}=i.getFreeze();return this._commandService.syncExecuteCommand(Le.id,{sheetViewStartRow:o-r,sheetViewStartColumn:e-s,offsetX:0,offsetY:0,duration:t})}_initCommandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(o=>{switch(o.id){case m.SetSelectionsOperation.id:{const e=o.params;e.unitId===this._context.unitId&&e.reveal&&this._scrollToSelection()}break;case m.ScrollToCellOperation.id:{const e=o.params;if(e.unitId===this._context.unitId){const t=e.range;this.scrollToRange(t)}}break;case De.id:{const e=o.params;this._scrollToSelectionForExpand(e)}break}}))}_scrollToSelectionForExpand(o){setTimeout(()=>{const e=this._getSelectionsService().getCurrentLastSelection();if(e==null)return;const{startRow:t,startColumn:i,endRow:r,endColumn:s}=e.range,l=this._getViewportBounding();if(l==null)return;const{startRow:c,startColumn:d,endRow:u,endColumn:h}=l;let g=0,S=0;t>c?g=r:r<u?g=t:g=c,i>d?S=s:s<h?S=i:S=d,o.direction===a.Direction.DOWN?g=r:o.direction===a.Direction.UP?g=t:o.direction===a.Direction.RIGHT?S=s:o.direction===a.Direction.LEFT&&(S=i),this._scrollToCell(g,S)},0)}_getFreeze(){var e;const o=(e=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:e.skeleton.getWorksheetConfig();if(o!=null)return o.freeze}_updateSceneSize(o){var h;if(o==null)return;const{unitId:e}=this._context,{skeleton:t}=o,i=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.scene;if(t==null||i==null)return;const{rowTotalHeight:r,columnTotalWidth:s,rowHeaderWidthAndMarginLeft:l,columnHeaderHeightAndMarginTop:c}=t;this._context.unit.getActiveSheet()&&(i==null||i.transformByState({width:l+s,height:c+r}))}_getSheetObject(){return Ve(this._context.unit,this._context)}_scrollToSelectionByDirection(o){const e=this._getViewportBounding();if(e==null)return!1;const{startRow:t,startColumn:i,endRow:r,endColumn:s}=e;let l=0,c=0;const{startRow:d,startColumn:u,endRow:h,endColumn:g}=o;d>=t&&(l=h),h<=r&&(l=d),u>=i&&(c=g),g<=s&&(c=u),this._scrollToCell(l,c)}_scrollToSelection(o=!0){var d;const e=this._getSelectionsService().getCurrentLastSelection();if(!e)return;const{startRow:t,startColumn:i,actualRow:r,actualColumn:s}=(d=e.primary)!=null?d:e.range,l=o&&r!=null?r:t,c=o&&s!=null?s:i;this._scrollToCell(l,c)}_getSelectionsService(){return m.getSelectionsService(this._injector)}_getViewportBounding(){var r,s;const o=(r=this._getSheetObject())==null?void 0:r.scene;if(o==null)return;const e=o.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e==null)return;const t=(s=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:s.skeleton;if(t==null)return;const i=e.calcViewportInfo();return t.getRangeByViewBound(i.viewBound)}_scrollToCell(o,e,t=!1,i=!1){var N,V,L;const{rowHeightAccumulation:r,columnWidthAccumulation:s}=(N=this._sheetSkeletonManagerService.getCurrentSkeleton())!=null?N:{};if(r==null||s==null)return!1;const l=(V=this._getSheetObject())==null?void 0:V.scene;if(l==null)return!1;const c=l.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(c==null)return!1;const d=(L=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:L.skeleton;if(d==null)return!1;const u=this._context.unit.getActiveSheet();if(!u)return!1;o=a.Tools.clamp(o,0,r.length-1),e=a.Tools.clamp(e,0,s.length-1);const{startColumn:h,startRow:g,ySplit:S,xSplit:f}=u.getFreeze(),v=this._getViewportBounding();if(v==null)return!1;const{startRow:p,startColumn:C,endRow:_,endColumn:w}=v;let E,O;if(o>=g&&e>=h-S&&(o<=p&&(E=o,t=!0),o>=_)){const H=r[o]-c.height;for(let W=p;W<=o&&(E=W+1,!(r[W]>=H));W++);}if(e>=h&&o>=g-S&&(e<=C&&(O=e,i=!0),e>=w)){const H=s[e]-c.width;for(let W=C;W<=e&&(O=W+1,!(s[W]>=H));W++);}if(E===void 0&&O===void 0)return!1;let{offsetX:R,offsetY:P,sheetViewStartRow:A,sheetViewStartColumn:k}=this._scrollManagerService.getCurrentScrollState()||{};if(E=E?Math.min(E,o):A+S,O=O?Math.min(O,e):k+f,i){R=0,O=e;const H=d.getHiddenColumnsInRange({startColumn:O-f,endColumn:O});O=O-H.length}if(t){P=0,E=o;const H=d.getHiddenRowsInRange({startRow:E-S,endRow:E});E=E-H.length}return this._commandService.syncExecuteCommand(Le.id,{sheetViewStartRow:Math.max(0,E-S),sheetViewStartColumn:Math.max(0,O-f),offsetX:R,offsetY:P})}},T.SheetsScrollRenderController=Yu([fn(1,a.Inject(a.Injector)),fn(2,a.Inject(T.SheetSkeletonManagerService)),fn(3,a.IContextService),fn(4,a.ICommandService),fn(5,M.IRenderManagerService),fn(6,a.Inject(T.SheetScrollManagerService))],T.SheetsScrollRenderController);const $e={id:"sheet.operation.set-scroll",type:a.CommandType.OPERATION,handler:(n,o)=>{if(!o)return!1;const{unitId:e,sheetId:t,offsetX:i=0,offsetY:r=0,sheetViewStartColumn:s,sheetViewStartRow:l,duration:c,screenRatioX:d,screenRatioY:u}=o,h=n.get(M.IRenderManagerService),g=h.getRenderById(e).with(T.SheetScrollManagerService),S=h.getRenderById(e);if(!S)return!1;const f=S.engine,v=f.width,p=f.height,C=d!==void 0?v*d+i:i,_=u!==void 0?p*u+r:r;return g.emitRawScrollParam({unitId:e,sheetId:t,offsetX:C,offsetY:_,sheetViewStartRow:l,sheetViewStartColumn:s,duration:c}),!0}},vn={id:"sheet.command.set-scroll-relative",type:a.CommandType.COMMAND,handler:async(n,o)=>{const e=n.get(a.ICommandService),t=n.get(a.IUniverInstanceService),i=n.get(M.IRenderManagerService),r=m.getSheetCommandTarget(t);if(!r)return!1;const{unitId:s,subUnitId:l}=r,d=i.getRenderById(s).with(T.SheetScrollManagerService).getCurrentScrollState(),{offsetX:u=0,offsetY:h=0}=o||{},{sheetViewStartRow:g=0,sheetViewStartColumn:S=0,offsetX:f=0,offsetY:v=0}=d||{};return e.executeCommand($e.id,{unitId:s,sheetId:l,sheetViewStartRow:g,sheetViewStartColumn:S,offsetX:f+u,offsetY:v+h})}},Le={id:"sheet.command.scroll-view",type:a.CommandType.COMMAND,handler:(n,o)=>{if(!o)return!1;const e=n.get(a.IUniverInstanceService),t=n.get(M.IRenderManagerService),i=m.getSheetCommandTarget(e);if(!i)return!1;const{workbook:r,worksheet:s,unitId:l}=i,d=t.getRenderById(l).with(T.SheetScrollManagerService).getCurrentScrollState();if(!s)return!1;const{sheetViewStartRow:u,sheetViewStartColumn:h,offsetX:g,offsetY:S,duration:f}=o,{sheetViewStartColumn:v,sheetViewStartRow:p,offsetX:C,offsetY:_}=d||{},{xSplit:w,ySplit:E}=i.worksheet.getConfig().freeze;return n.get(a.ICommandService).syncExecuteCommand($e.id,{unitId:r.getUnitId(),sheetId:s.getSheetId(),sheetViewStartRow:u!=null?u:p!=null?p:0+E,sheetViewStartColumn:h!=null?h:v!=null?v:0+w,offsetX:g!=null?g:C,offsetY:S!=null?S:_,duration:f})}},Sr={id:"sheet.command.scroll-to-cell",type:a.CommandType.COMMAND,handler:(n,o)=>{const e=n.get(a.IUniverInstanceService);return n.get(M.IRenderManagerService).getRenderById(e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(T.SheetsScrollRenderController).scrollToRange(o.range,o.forceTop,o.forceLeft)}},Zu={id:"sheet.command.scroll-view-reset",type:a.CommandType.COMMAND,handler:async n=>{const o=n.get(a.IUniverInstanceService),e=m.getSheetCommandTarget(o);if(!e)return!1;const{subUnitId:t,unitId:i}=e;return n.get(a.ICommandService).executeCommand($e.id,{unitId:i,sheetId:t,sheetViewStartRow:0,sheetViewStartColumn:0})}};var Gu=Object.getOwnPropertyDescriptor,Ku=(n,o,e,t)=>{for(var i=t>1?void 0:t?Gu(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},Ia=(n,o)=>(e,t)=>o(e,t,n);const qu=(n,o)=>{const{unitId:e,subUnitId:t,ranges:i}=n,r={},s=o.getColumnManager();for(let l=0;l<i.length;l++){const c=i[l];for(let d=c.startColumn;d<c.endColumn+1;d++)r[d]=s.getColumnWidth(d)}return{unitId:e,subUnitId:t,ranges:i,colWidth:r}};T.AutoWidthController=class extends a.Disposable{constructor(o,e){super(),this._renderManagerService=o,this._univerInstanceService=e}getUndoRedoParamsOfColWidth(o){const e={redos:[],undos:[]},{_univerInstanceService:t}=this,i=m.getSheetCommandTarget(t);if(!i)return e;const{unitId:r,subUnitId:s,worksheet:l}=i,c=this._renderManagerService.getRenderById(r).with(T.SheetSkeletonManagerService);if(!c.getCurrentParam())return e;const{skeleton:d}=c.getCurrentParam(),u=d.calculateAutoWidthInRange(o.ranges),h={};for(const{col:f,width:v}of u)h[f]=v;const g={subUnitId:s,unitId:r,ranges:o.ranges,colWidth:h},S=qu(g,l);return{undos:[{id:m.SetWorksheetColWidthMutation.id,params:S}],redos:[{id:m.SetWorksheetColWidthMutation.id,params:g}]}}},T.AutoWidthController=Ku([Ia(0,M.IRenderManagerService),Ia(1,a.Inject(a.IUniverInstanceService))],T.AutoWidthController);const pn={type:a.CommandType.COMMAND,id:"sheet.command.set-col-auto-width",handler:(n,o)=>{const e=n.get(a.ICommandService),t=n.get(a.IUndoRedoService),i=n.get(m.SheetsSelectionsService),r=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(r,o);if(!s)return!1;const{unitId:l,subUnitId:c}=s;let d=[];if(o!=null&&o.ranges)d=[...o.ranges];else{const f=i.getCurrentSelections();for(let v=0;v<f.length;v++)d.push(f[v].range)}if(!(d!=null&&d.length))return!1;const u={unitId:l,subUnitId:c,ranges:d},{redos:h,undos:g}=n.get(T.AutoWidthController).getUndoRedoParamsOfColWidth(u);return a.sequenceExecute([...h],e).result?(t.pushUndoRedo({unitID:l,undoMutations:[...g],redoMutations:[...h]}),!0):!1}};var Qu=Object.getOwnPropertyDescriptor,Ju=(n,o,e,t)=>{for(var i=t>1?void 0:t?Qu(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},Cn=(n,o)=>(e,t)=>o(e,t,n);T.EditorBridgeService=class extends a.Disposable{constructor(e,t,i,r,s,l){super();y(this,"_editorUnitId",a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);y(this,"_editorIsDirty",!1);y(this,"_visibleParams",{visible:!1,eventType:M.DeviceInputEventType.Dblclick,unitId:""});y(this,"_currentEditCell",null);y(this,"_currentEditCellState",null);y(this,"_currentEditCellLayout",null);y(this,"helpFunctionVisible$",new D.BehaviorSubject(!0));y(this,"_currentEditCellState$",new D.BehaviorSubject(null));y(this,"currentEditCellState$",this._currentEditCellState$.asObservable());y(this,"_currentEditCellLayout$",new D.BehaviorSubject(null));y(this,"currentEditCellLayout$",this._currentEditCellLayout$.asObservable());y(this,"currentEditCell$",this._currentEditCellState$.pipe(D.switchMap(e=>this._currentEditCellLayout$.pipe(D.map(t=>e&&t?{...e,...t}:null)))));y(this,"_visibleParams$",new D.BehaviorSubject(this._visibleParams));y(this,"visible$",this._visibleParams$.asObservable());y(this,"_afterVisibleParams$",new D.BehaviorSubject(this._visibleParams));y(this,"afterVisible$",this._afterVisibleParams$.asObservable());y(this,"_forceKeepVisible$",new D.BehaviorSubject(!1));y(this,"forceKeepVisible$",this._forceKeepVisible$.asObservable());this._sheetInterceptorService=e,this._renderManagerService=t,this._themeService=i,this._univerInstanceService=r,this._editorService=s,this._contextService=l,this.disposeWithMe(a.toDisposable(()=>{this._currentEditCellState$.complete(),this._currentEditCell=null})),this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).subscribe(c=>{var d;c.getUnitId()===((d=this._currentEditCellState)==null?void 0:d.unitId)&&this._clearCurrentEditCellState()})}refreshEditCellState(){const e=this.getLatestEditCellState();if(!e){this._currentEditCellState=null,this._currentEditCellLayout=null,this._currentEditCellState$.next(null),this._currentEditCellLayout$.next(null);return}const{position:t,scaleX:i,scaleY:r,canvasOffset:s,...l}=e;this._currentEditCellState=l,this._currentEditCellLayout={position:t,scaleX:i,scaleY:r,canvasOffset:s},this._currentEditCellState$.next(this._currentEditCellState),this._currentEditCellLayout$.next(this._currentEditCellLayout)}refreshEditCellPosition(e){var O;const t=this._currentEditCell;if(t==null)return;const i=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!i)return;const r=this._renderManagerService.getRenderUnitById(i.getUnitId());if(!r)return;const s=(O=r.with(T.SheetSkeletonManagerService).getSkeletonParam(t.sheetId))==null?void 0:O.skeleton,l=r.with(Ie);if(!s||!this._currentEditCellState)return;const{primary:c,scene:d,engine:u}=t,h=jn(s,c);if(h==null)return;const g=a.convertCellToRange(h),S=K.getCanvasOffsetByEngine(u);let{startX:f,startY:v,endX:p,endY:C}=g;const{scaleX:_,scaleY:w}=d.getAncestorScale(),E=d.getViewportScrollXY(l.getViewPort());f=M.convertTransformToOffsetX(f,_,E),v=M.convertTransformToOffsetY(v,w,E),p=M.convertTransformToOffsetX(p,_,E),C=M.convertTransformToOffsetY(C,w,E),e&&this._currentEditCellLayout&&(p=p-f+this._currentEditCellLayout.position.startX,C=C-v+this._currentEditCellLayout.position.startY,f=this._currentEditCellLayout.position.startX,v=this._currentEditCellLayout.position.startY),this._currentEditCellLayout={position:{startX:f,startY:v,endX:p,endY:C},canvasOffset:S,scaleX:_,scaleY:w},this._currentEditCellLayout$.next(this._currentEditCellLayout)}setEditCell(e){this._currentEditCell=e,this._editorService.getFocusEditor()||(this._editorService.focus(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._contextService.setContextValue(a.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(a.FOCUSING_EDITOR_STANDALONE,!1));const t=this.getLatestEditCellState();if(!t){this._currentEditCellState=t,this._currentEditCellLayout=t,this._currentEditCellState$.next(t),this._currentEditCellLayout$.next(t);return}const{position:i,canvasOffset:r,scaleX:s,scaleY:l,...c}=t;this._currentEditCellState=c,this._currentEditCellLayout={position:i,canvasOffset:r,scaleX:s,scaleY:l},this._currentEditCellState$.next(this._currentEditCellState),this._currentEditCellLayout$.next(this._currentEditCellLayout)}_clearCurrentEditCellState(){this._currentEditCellState=null,this._currentEditCellState$.next(null),this._currentEditCellLayout=null,this._currentEditCellLayout$.next(null)}getEditCellState(){return this._currentEditCellState==null||this._currentEditCellLayout==null?null:{...this._currentEditCellState,...this._currentEditCellLayout}}getEditCellLayout(){return this._currentEditCellLayout}getEditLocation(){return this._currentEditCellState}updateEditLocation(e,t){this._currentEditCellState&&(this._currentEditCellState={...this._currentEditCellState,row:e,column:t})}getLatestEditCellState(){var H,W,B;const e=this._currentEditCell;if(e==null)return;const t=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!t)return;const i=this._renderManagerService.getRenderUnitById(t.getUnitId());if(!i)return;const r=i.with(T.SheetSkeletonManagerService).getCurrentSkeleton(),s=i.with(Ie);if(!r)return;const{primary:l,unitId:c,sheetId:d,scene:u,engine:h}=e,{startRow:g,startColumn:S}=l,f=jn(r,l);if(f==null)return;const v=a.convertCellToRange(f),p=K.getCanvasOffsetByEngine(h);let{startX:C,startY:_,endX:w,endY:E}=v;const{scaleX:O,scaleY:R}=u.getAncestorScale(),P=u.getViewportScrollXY(s.getViewPort());C=M.convertTransformToOffsetX(C,O,P),_=M.convertTransformToOffsetY(_,R,P),w=M.convertTransformToOffsetX(w,O,P),E=M.convertTransformToOffsetY(E,R,P);const A=t.getActiveSheet();if(!A)return;const k={workbook:t,worksheet:A,unitId:t.getUnitId(),subUnitId:A.getSheetId(),row:g,col:S,origin:A.getCellRaw(g,S)};let N;const V=this._sheetInterceptorService.writeCellInterceptor.fetchThroughInterceptors(m.BEFORE_CELL_EDIT)(A.getCell(g,S),k);N=V&&A.getCellDocumentModelWithFormula(V,k.row,k.col);const L=(H=N==null?void 0:N.documentModel)==null?void 0:H.documentStyle.renderConfig;if(L!=null&&(L.cellValueType=a.CellValueType.STRING),!N||N.documentModel==null){const U=A.getBlankCellDocumentModel(V,k.row,k.col);if(N!=null){const{verticalAlign:X,horizontalAlign:F,wrapStrategy:Y,textRotation:j,fill:Q}=N,{centerAngle:oe,vertexAngle:re}=M.convertTextRotation(j);U.documentModel.documentStyle.renderConfig={...L,verticalAlign:X,horizontalAlign:F,wrapStrategy:Y,background:{rgb:Q},centerAngle:oe,vertexAngle:re}}N=U}if(N.fill=N.fill||"#fff",(W=N.documentModel)==null||W.setZoomRatio(Math.max(O,R)),(V==null?void 0:V.isInArrayFormulaRange)===!0){const U=(B=N.documentModel)==null?void 0:B.getBody();U&&(U.textRuns=[{st:0,ed:U.dataStream.length-2,ts:{cl:{rgb:this._themeService.getColorFromTheme("gray.300")}}}])}return{position:{startX:C,startY:_,endX:w,endY:E},scaleX:O,scaleY:R,canvasOffset:p,row:g,column:S,unitId:c,sheetId:d,documentLayoutObject:N,editorUnitId:this._editorUnitId,isInArrayFormulaRange:V==null?void 0:V.isInArrayFormulaRange}}getCurrentEditorId(){return this._editorUnitId}changeVisible(e){this._visibleParams=e,e.visible&&(this._editorIsDirty=!1),this._visibleParams$.next(this._visibleParams),this._afterVisibleParams$.next(this._visibleParams)}isVisible(){return this._visibleParams}enableForceKeepVisible(){this._forceKeepVisible$.next(!0)}disableForceKeepVisible(){this._forceKeepVisible$.next(!1)}isForceKeepVisible(){return this._forceKeepVisible$.getValue()}changeEditorDirty(e){this._editorIsDirty=e}getEditorDirty(){return this._editorIsDirty}},T.EditorBridgeService=Ju([Cn(0,a.Inject(m.SheetInterceptorService)),Cn(1,M.IRenderManagerService),Cn(2,a.Inject(a.ThemeService)),Cn(3,a.IUniverInstanceService),Cn(4,K.IEditorService),Cn(5,a.IContextService)],T.EditorBridgeService);const me=a.createIdentifier("univer.sheet-editor-bridge.service");var $u=Object.getOwnPropertyDescriptor,eh=(n,o,e,t)=>{for(var i=t>1?void 0:t?$u(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},io=(n,o)=>(e,t)=>o(e,t,n);let fi=class extends a.Disposable{constructor(o,e,t,i,r){super();y(this,"_zoom");this._context=o,this._sheetSkeletonManagerService=e,this._commandService=t,this._contextService=i,this._editorBridgeService=r,this._initSkeletonListener(),this._initZoomEventListener()}updateZoom(o,e){const t=this._context.unit.getSheetBySheetId(o);return t?(t.getConfig().zoomRatio=e,t===this._context.unit.getActiveSheet()&&this._updateViewZoom(e),!0):!1}_initZoomEventListener(){const o=Ve(this._context.unit,this._context).scene;this.disposeWithMe(o.onMouseWheel$.subscribeEvent(e=>{if(!e.ctrlKey||!this._contextService.getContextValue(a.FOCUSING_SHEET))return;if(this._editorBridgeService){const d=this._editorBridgeService.isVisible();if((d.unitId===this._context.unitId||d.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&d.visible)return}const t=Math.abs(e.deltaX);let i=t<40?.2:t<80?.4:.2;i*=e.deltaY>0?-1:1,o.scaleX<1&&(i/=2);const r=this._context.unit,s=r.getActiveSheet();if(!s)return;const l=s.getZoomRatio();let c=+Number.parseFloat(`${l+i}`).toFixed(1);c=c>=4?4:c<=.1?.1:c,this._commandService.executeCommand(_n.id,{zoomRatio:Math.round(c*10)/10,unitId:r.getUnitId(),subUnitId:s.getSheetId()}),e.preventDefault()}))}_initSkeletonListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(o=>{if(o==null)return;const t=this._context.unit.getActiveSheet();if(!t)return;const i=t.getZoomRatio()||1;this._zoom!==i&&this._updateViewZoom(i)}))}_updateViewZoom(o){this._zoom=o;const e=Ve(this._context.unit,this._context);e==null||e.scene.scale(o,o),e==null||e.spreadsheet.makeForceDirty()}};fi=eh([io(1,a.Inject(T.SheetSkeletonManagerService)),io(2,a.ICommandService),io(3,a.IContextService),io(4,a.Optional(me))],fi);const Ye={id:"sheet.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(n,o)=>{const t=n.get(M.IRenderManagerService).getRenderById(o.unitId);return t?t.with(fi).updateZoom(o.subUnitId,o.zoomRatio):!1}},In={id:"sheet.command.change-zoom-ratio",type:a.CommandType.COMMAND,handler:(n,o)=>{if(!o)return!1;const e=n.get(a.IUniverInstanceService),t=m.getSheetCommandTarget(e);if(!t)return!1;const{worksheet:i,subUnitId:r,unitId:s}=t,{delta:l,reset:c}=o;let d=c?100:Math.round((i.getConfig().zoomRatio+l)*100);d=Math.max(zo[0],d),d=Math.min(zo[1],d);const u=d/100,g=n.get(me).isVisible();return(g.unitId===s||g.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&g.visible?!1:n.get(a.ICommandService).executeCommand(Ye.id,{unitId:s,subUnitId:r,zoomRatio:u})}},_n={id:"sheet.command.set-zoom-ratio",type:a.CommandType.COMMAND,handler:(n,o)=>{if(!o)return!1;const{unitId:e,subUnitId:t,zoomRatio:i}=o,s=n.get(me).isVisible();return(s.unitId===e||s.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&s.visible?!1:n.get(a.ICommandService).executeCommand(Ye.id,{unitId:e,subUnitId:t,zoomRatio:i})}},Wt=a.createIdentifier("univer.sheetbar-service");class _a extends a.Disposable{constructor(){super();y(this,"renameId$");y(this,"removeId$");y(this,"scroll$");y(this,"scrollX$");y(this,"addSheet$");y(this,"_renameId$");y(this,"_removeId$");y(this,"_scroll$");y(this,"_scrollX$");y(this,"_addSheet$");y(this,"_currentHandler",null);this._renameId$=new D.Subject,this.renameId$=this._renameId$.asObservable(),this._removeId$=new D.Subject,this.removeId$=this._removeId$.asObservable(),this._scroll$=new D.Subject,this.scroll$=this._scroll$.asObservable(),this._scrollX$=new D.Subject,this.scrollX$=this._scrollX$.asObservable(),this._addSheet$=new D.Subject,this.addSheet$=this._addSheet$.asObservable()}setRenameId(e){this._renameId$.next(e)}setRemoveId(e){this._removeId$.next(e)}setScroll(e){this._scroll$.next(e)}setScrollX(e){this._scrollX$.next(e)}setAddSheet(e){this._addSheet$.next(e)}triggerSheetBarMenu(){var e;(e=this._currentHandler)==null||e.handleSheetBarMenu()}registerSheetBarMenuHandler(e){if(this._currentHandler)throw new Error("There is already a context menu handler!");return this._currentHandler=e,a.toDisposable(()=>{this._currentHandler=null})}}const vi={id:"ui-sheet.command.show-menu-list",type:a.CommandType.OPERATION,handler:async n=>(n.get(Wt).triggerSheetBarMenu(),!0)},pi={type:a.CommandType.COMMAND,id:"sheet.command.delete-worksheet-protection-from-sheet-bar",async handler(n,o){if(!o)return!1;const e=n.get(a.ICommandService),t=n.get(a.IUndoRedoService),i=n.get(m.WorksheetProtectionRuleModel),s=n.get(a.IUniverInstanceService).getCurrentUnitForType(ga.UNIVER_SHEET),l=s==null?void 0:s.getActiveSheet(),c=s.getUnitId();if(!l)return!1;const d=l.getSheetId(),u=i.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}},Ci={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}},oo={id:"sheet.operation.set-activate-cell-edit",type:a.CommandType.OPERATION,handler:(n,o)=>(n.get(me).setEditCell(o),!0)},Se={id:"sheet.operation.set-cell-edit-visible",type:a.CommandType.OPERATION,handler:(n,o)=>{if(!o)return!1;const{unitId:e}=o,i=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);return i?(n.get(me).changeVisible({...o,unitId:e!=null?e:i.getUnitId()}),!0):!1}},Ii={id:"sheet.operation.set-cell-edit-visible-f2",type:a.CommandType.OPERATION,handler:(n,o)=>{const e=n.get(a.ICommandService),i=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);return i?e.syncExecuteCommand(Se.id,{...o,unitId:i.getUnitId()}):!1}},Lt={id:"sheet.operation.set-cell-edit-visible-arrow",type:a.CommandType.OPERATION,handler:()=>!0},_i={id:"sheet.operation.rename-sheet",type:a.CommandType.OPERATION,handler:async(n,o)=>{const e=n.get(Wt);return o&&e.setRenameId(o.subUnitId),!0}},ro={id:"sheet.operation.scroll-to-range",type:a.CommandType.OPERATION,handler:(n,o)=>{if(!o)return!1;const e=n.get(a.IUniverInstanceService);return n.get(M.IRenderManagerService).getRenderById(e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(T.SheetsScrollRenderController).scrollToRange(o.range,o.forceTop,o.forceLeft)}},fr={type:a.CommandType.OPERATION,id:"sheet-permission.operation.openDialog",async handler(n,o){const e=n.get(I.IDialogService);return e.close("DESKTOP_FIND_REPLACE_DIALOG"),e.open({id:$i,title:{title:"permission.dialog.allowedPermissionType"},children:{label:fa},width:393,destroyOnClose:!0,onClose:()=>e.close($i)}),!0}},bi="DefinedNameContainer",so={id:"sidebar.operation.defined-name",type:a.CommandType.COMMAND,handler:async(n,o)=>{const e=n.get(I.ISidebarService);n.get(K.IEditorService);const t=n.get(a.LocaleService),i=n.get(a.IUniverInstanceService),r=m.getSheetCommandTarget(i);if(!r)return!1;const{unitId:s}=r;switch(o.value){case"open":e.open({id:bi,header:{title:t.t("definedName.featureTitle")},children:{label:bi},onClose:()=>{},width:333});break;case"close":default:e.close();break}return!0}};function th(n,o){if(n.length!==o.length)return!1;const e=n.sort((i,r)=>i.id.localeCompare(r.id)),t=o.sort((i,r)=>i.id.localeCompare(r.id));return e.every((i,r)=>{var s,l;return((s=i.subject)==null?void 0:s.userID)===((l=t[r].subject)==null?void 0:l.userID)&&i.role===t[r].role})}function ba(n,o){return o.some(e=>nh(n,e))}function nh(n,o){const{startRow:e,startColumn:t,endColumn:i,endRow:r}=o,s=n.getMatrixWithMergedCells(e,t,r,i);let l=!1;return s.forValue((c,d,u)=>{if(u&&(c!==e||d!==t)&&n.cellHasValue(u))return l=!0,!1}),l}function wa(n,o,e,t){const i=[],r=[],s=e.getSheetId();return t.forEach(l=>{const c=ih(e,l),d={unitId:o,subUnitId:s,cellValue:c.getData()},u=m.SetRangeValuesUndoMutationFactory(n,d);i.push({id:m.SetRangeValuesMutation.id,params:u}),r.push({id:m.SetRangeValuesMutation.id,params:d})}),{undos:i,redos:r}}function ih(n,o){const{startRow:e,startColumn:t,endColumn:i,endRow:r}=o,s=n.getMatrixWithMergedCells(e,t,r,i,a.CellModeEnum.Raw),l=new a.ObjectMatrix;let c=null;return s.forValue((d,u,h)=>{var g,S,f,v;h&&d>=e&&u>=t&&(!c&&n.cellHasValue(h)&&(h.v!==""||((v=(f=(S=(g=h.p)==null?void 0:g.body)==null?void 0:S.dataStream)==null?void 0:f.length)!=null?v:0)>2)&&(c=h),l.setValue(d,u,null))}),l.setValue(e,t,c),l}function oh(n,o,e,t){const i=e.getActiveViewportByCoord(M.Vector2.FromArray([n,o]));if(!i)return;const{scaleX:r,scaleY:s}=e.getAncestorScale(),l={x:i.viewportScrollX,y:i.viewportScrollY},c=t.getCellIndexByOffset(n,o,r,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 Ea(n,o,e,t){const i=t.getFreeze();if(!i||i.startRow<=0&&i.startColumn<=0||n>=i.startRow&&o>=i.startColumn)return e.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(n<i.startRow&&o<i.startColumn)return e.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP);if(n<i.startRow&&o>=i.startColumn)return e.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(n>=i.startRow&&o<i.startColumn)return e.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)}function rh(n,o,e,t){const i=Ta(n.left,n.top,o,e,t),r=Ta(n.right,n.bottom,o,e,t);return{left:i.x,top:i.y,right:r.x,bottom:r.y}}function Ta(n,o,e,t,i){const{scaleX:r,scaleY:s}=e.getAncestorScale(),l=e.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!l)return{x:n,y:o};const c=i.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:v,columnHeaderHeight:p}=t,C=f.startX-S.startX,_=f.startY-S.startY,{top:w,left:E,viewportScrollX:O,viewportScrollY:R}=l;let P;n>E?P=(n-O)*r:P=(C+v-(E-n))*r;let A;return o>w?A=(o-R)*s:A=(_+p-(w-o))*r,{x:P,y:A}}function ya(n,o,e,t,i){let r=t,s=i;e.overflowCache.forValue((d,u,h)=>{h.startRow<=r&&h.endRow>=r&&h.startColumn<=s&&h.endColumn>=s&&(s=u,r=d)});const l=e.getCellWithCoordByIndex(r,s);return{unitId:n.getUnitId(),subUnitId:o.getSheetId(),workbook:n,worksheet:o,row:l.actualRow,col:l.actualColumn}}function Ra(n,o,e,t,i,r){const{scene:s}=n,l=o.getUnitId(),{skeleton:c,sheetId:d}=t,u=oh(i,r,s,c);if(!u)return null;let{actualCol:h,actualRow:g}=u;const S={unitId:l,subUnitId:d,workbook:o,worksheet:e,row:g,col:h};c.overflowCache.forValue((R,P,A)=>{A.startRow<=g&&A.endRow>=g&&A.startColumn<=h&&A.endColumn>=h&&(h=P,g=R)});const f=c.getCellWithCoordByIndex(g,h),v=ya(o,e,c,g,h);let p;f.mergeInfo?p=f.mergeInfo:p={startRow:v.row,endRow:v.row,startColumn:v.col,endColumn:v.col};const C=s.getActiveViewportByCoord(M.Vector2.FromArray([i,r]));if(!C)return;const{scaleX:_,scaleY:w}=s.getAncestorScale(),E={x:C.viewportScrollX,y:C.viewportScrollY};return{position:{startX:(c.getOffsetByColumn(p.startColumn-1)-E.x)*_,endX:(c.getOffsetByColumn(p.endColumn)-E.x)*_,startY:(c.getOffsetByRow(p.startRow-1)-E.y)*w,endY:(c.getOffsetByRow(p.endRow)-E.y)*w},location:S,overflowLocation:v}}function mt(){const n=I.useDependency(a.IUniverInstanceService),o=I.useObservable(()=>n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]);return o!=null?o:null}function sh(n){return I.useObservable(()=>{var e;return(e=n==null?void 0:n.activeSheet$)!=null?e:D.of(null)},void 0,void 0,[n])}function ah(){const n=I.useDependency(a.IUniverInstanceService);return I.useObservable(()=>D.merge([n.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET),n.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET)]).pipe(D.map(()=>n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET)),D.startWith(n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET))),[],void 0,[n])}const lh="SheetUI";var vr=(n=>(n.FILTER_PANEL_EMBED_POINT="filter-panel-embed-point",n.SHEETS_FOOTER="sheets-footer",n.FORMULA_AUX="formula-aux",n))(vr||{}),ch=Object.getOwnPropertyDescriptor,dh=(n,o,e,t)=>{for(var i=t>1?void 0:t?ch(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},ao=(n,o)=>(e,t)=>o(e,t,n);const Ma="univer-sheet-main-canvas";T.SheetsRenderService=class extends a.RxDisposable{constructor(e,t,i,r){super();y(this,"_skeletonChangeMutations",new Set);this._contextService=e,this._instanceSrv=t,this._renderManagerService=i,this._themeService=r,Promise.resolve().then(()=>this._init())}registerSkeletonChangingMutations(e){return this._skeletonChangeMutations.has(e)?a.toDisposable(()=>{}):(this._skeletonChangeMutations.add(e),a.toDisposable(()=>this._skeletonChangeMutations.delete(e)))}checkMutationShouldTriggerRerender(e){return this._skeletonChangeMutations.has(e)}_init(){this._initWorkbookListener(),this._initContextListener()}_initWorkbookListener(){this._instanceSrv.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET).pipe(D.takeUntil(this.dispose$)).subscribe(e=>this._createRenderer(e)),this._instanceSrv.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(e=>this._createRenderer(e)),this._instanceSrv.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).pipe(D.takeUntil(this.dispose$)).subscribe(e=>this._disposeRenderer(e))}_createRenderer(e){const t=e.getUnitId();this._renderManagerService.created$.subscribe(i=>{i.unitId===t&&(i.engine.getCanvas().setId(`${Ma}_${t}`),i.engine.getCanvas().getContext().setId(`${Ma}_${t}`))}),this._renderManagerService.createRender(t)}_disposeRenderer(e){const t=e.getUnitId();this._renderManagerService.removeRender(t)}_initContextListener(){this.disposeWithMe(this._contextService.subscribeContextValue$(M.RENDER_RAW_FORMULA_KEY).pipe(D.distinctUntilChanged()).subscribe(()=>{this._renderManagerService.getRenderAll().forEach(e=>{e.mainComponent instanceof M.Spreadsheet&&e.mainComponent.makeForceDirty(!0)})}))}},T.SheetsRenderService=dh([ao(0,a.IContextService),ao(1,a.IUniverInstanceService),ao(2,M.IRenderManagerService),ao(3,a.Inject(a.ThemeService))],T.SheetsRenderService);var uh=Object.getOwnPropertyDescriptor,hh=(n,o,e,t)=>{for(var i=t>1?void 0:t?uh(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},xt=(n,o)=>(e,t)=>o(e,t,n);T.AutoFillController=class extends a.Disposable{constructor(e,t,i,r,s,l,c){super();y(this,"_beforeApplyData",[]);y(this,"_currentLocation",null);y(this,"_copyData",[]);y(this,"_defaultHook");this._univerInstanceService=e,this._commandService=t,this._autoFillService=i,this._editorBridgeService=r,this._renderManagerService=s,this._injector=l,this._sheetsRenderService=c,this._defaultHook={id:"default",type:Jt.Default,priority:0,onBeforeFillData:(d,u)=>this._presetAndCacheData(d,u),onFillData:(d,u,h)=>this._fillData(d,u,h)},this._init()}_init(){this._initDefaultHook(),this._initSelectionControlFillChanged(),this._initQuitListener(),this._initSkeletonChange()}_initSkeletonChange(){this.disposeWithMe(this._sheetsRenderService.registerSkeletonChangingMutations(dt.id))}_initDefaultHook(){this.disposeWithMe(this._autoFillService.addHook(this._defaultHook))}_initQuitListener(){const e=[Se.id,en.id,m.SetRangeValuesCommand.id,Ye.id,m.SetWorksheetActiveOperation.id,m.MoveRangeMutation.id,m.RemoveRowMutation.id,m.RemoveColMutation.id,m.InsertRowMutation.id,m.InsertColMutation.id,m.MoveRowsMutation.id,m.MoveColsMutation.id,m.SetWorksheetColWidthMutation.id,m.SetWorksheetRowHeightMutation.id,m.SetRangeValuesMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted((t,i)=>{var c,d;const r=i==null?void 0:i.fromCollab,s=i==null?void 0:i.fromSync,l=i==null?void 0:i.fromFormula;e.includes(t.id)&&!r&&!s&&!l&&t.params.trigger!==dt.id&&t.params.trigger!==li.id&&this._quit(),t.id===m.RemoveSheetMutation.id&&t.params.unitId===((c=this._currentLocation)==null?void 0:c.unitId)&&t.params.subUnitId===((d=this._currentLocation)==null?void 0:d.subUnitId)&&this._quit()})),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{var i;t.getUnitId()===((i=this._currentLocation)==null?void 0:i.unitId)&&this._quit()}))}_quit(){this._currentLocation=null,this._beforeApplyData=[],this._copyData=[],this._autoFillService.setShowMenu(!1)}_initSelectionControlFillChanged(){const e=new a.DisposableCollection,t=()=>{e.dispose();const i=M.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService);if(!i)return;i.with(Ie).getSelectionControls().forEach(l=>{e.add(l.selectionFilled$.subscribe(c=>{if(c==null||c.startColumn===-1||c.startRow===-1||c.endColumn===-1||c.endRow===-1)return;const d={startColumn:l.model.startColumn,endColumn:l.model.endColumn,startRow:l.model.startRow,endRow:l.model.endRow},u={startColumn:c.startColumn,endColumn:c.endColumn,startRow:c.startRow,endRow:c.endRow};this._commandService.executeCommand(dt.id,{sourceRange:d,targetRange:u})})),e.add(l.fillControl.onDblclick$.subscribeEvent(()=>{const c={startColumn:l.model.startColumn,endColumn:l.model.endColumn,startRow:l.model.startRow,endRow:l.model.endRow};this._handleDbClickFill(c)})),e.add(l.fillControl.onPointerDown$.subscribeEvent(()=>{this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(Se.id,{visible:!1,eventType:M.DeviceInputEventType.PointerDown,unitId:i.unitId})}))})};t(),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===m.SetSelectionsOperation.id&&t()})),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(()=>t()))}_handleDbClickFill(e){const t=this._detectFillRange(e);t.endRow<=e.endRow||this._commandService.executeCommand(dt.id,{sourceRange:e,targetRange:t})}_detectFillRange(e){var g,S,f,v,p,C;const{startRow:t,endRow:i,startColumn:r,endColumn:s}=e,l=(g=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET))==null?void 0:g.getActiveSheet();if(!l)return e;const c=l.getCellMatrix(),d=l.getMaxRows()-1,u=l.getMaxColumns()-1;let h=i;if(r>0&&((S=c.getValue(t,r-1))==null?void 0:S.v)!=null){let _=t;for(;((f=c.getValue(_,r-1))==null?void 0:f.v)!=null&&_<d;)_+=1;h=_-1}else if(s<u&&((v=c.getValue(i,s+1))==null?void 0:v.v)!=null){let _=t;for(;((p=c.getValue(_,s+1))==null?void 0:p.v)!=null&&_<d;)_+=1;h=_-1}for(let _=i+1;_<=h;_++)for(let w=r;w<=s;w++)if(((C=c.getValue(_,w))==null?void 0:C.v)!=null){h=_-1;break}return{startColumn:r,endColumn:s,startRow:t,endRow:h}}_getApplyData(e,t,i,r,s,l=!0,c){const d=[],u=Math.floor(i/t),h=i%t,g=this._autoFillService.getRules();if(!l&&s===le.ONLY_FORMAT)return console.error("ERROR: only format can not be applied when hasStyle is false"),[];const S={};g.forEach(f=>{S[f.type]=[]}),g.forEach(f=>{const{type:v,applyFunctions:p={}}=f,C=e[v];C&&C.forEach(_=>{const w=Rd(_.index,h),E=_.index.length*u+w,O=this._applyFunctions(_,E,r,s,p,e,c),R=Md(t,i,_.index);S[v].push({data:O,index:R})})});for(let f=0;f<i;f++)g.forEach(v=>{const{type:p}=v,C=S[p];for(let _=0;_<C.length;_++)f in C[_].index&&d.push(C[_].data[C[_].index[f]])});return d}_applyFunctions(e,t,i,r,s,l,c){const{data:d}=e,u=i===a.Direction.UP||i===a.Direction.LEFT;if(r===le.COPY){const h=s==null?void 0:s[le.COPY];return h?h(e,t,i,l,c):(u&&d.reverse(),_t(d,t))}if(r===le.SERIES){const h=s==null?void 0:s[le.SERIES];return h?h(e,t,i,l):(u&&d.reverse(),s!=null&&s[le.COPY]?s[le.COPY](e,t,i,l,c):_t(d,t))}if(r===le.ONLY_FORMAT){const h=s==null?void 0:s[le.ONLY_FORMAT];return h?h(e,t,i,l):Pd(d,t)}}_getCopyData(e,t){var f;const{unitId:i,subUnitId:r,source:s}=e,l=(f=this._univerInstanceService.getUnit(i))==null?void 0:f.getSheetBySheetId(r);if(!l)throw new Error("No worksheet found");const c=l.getCellMatrix(),d=this._autoFillService.getRules(),u=[],h=t===a.Direction.DOWN||t===a.Direction.UP;let g,S;return h?(g=s.cols,S=s.rows):(g=s.rows,S=s.cols),g.forEach(v=>{const p=this._getEmptyCopyDataPiece(),C={type:void 0,cellData:void 0};S.forEach(_=>{let w;h?w=c.getValue(_,v):w=c.getValue(v,_);const{type:E,isContinue:O}=d.find(R=>R.match(w,this._injector))||Zs;if(O(C,w)){const R=p[E],P=R[R.length-1];P.data.push(w),P.index.push(_-S[0])}else{const R=p[E];R?R.push({data:[w],index:[_-S[0]]}):p[E]=[{data:[w],index:[_-S[0]]}]}C.type=E,C.cellData=w}),u.push(p)}),u}_getEmptyCopyDataPiece(){const e={};return this._autoFillService.getRules().forEach(t=>{e[t.type]=[]}),e}_getMergeApplyData(e,t,i,r,s){var h;const{unitId:l,subUnitId:c}=s,d=(h=this._univerInstanceService.getUnit(l))==null?void 0:h.getSheetBySheetId(c);if(!d)throw new Error("No active sheet found");const u=[];for(let g=e.startRow;g<=e.endRow;g++)for(let S=e.startColumn;S<=e.endColumn;S++){const{isMergedMainCell:f,startRow:v,startColumn:p,endRow:C,endColumn:_}=d.getCellInfoInMergeData(g,S);if(f){if(i===a.Direction.DOWN){let w=v+r,E=C+r;for(;E<=t.endRow;)u.push({startRow:w,startColumn:p,endRow:E,endColumn:_}),w+=r,E+=r}else if(i===a.Direction.UP){let w=v-r,E=C-r;for(;w>=t.startRow;)u.push({startRow:w,startColumn:p,endRow:E,endColumn:_}),w-=r,E-=r}else if(i===a.Direction.RIGHT){let w=p+r,E=_+r;for(;E<=t.endColumn;)u.push({startRow:v,startColumn:w,endRow:C,endColumn:E}),w+=r,E+=r}else if(i===a.Direction.LEFT){let w=p-r,E=_-r;for(;w>=t.startColumn;)u.push({startRow:v,startColumn:w,endRow:C,endColumn:E}),w-=r,E-=r}}}return u}_presetAndCacheData(e,t){var u;const{unitId:i,subUnitId:r,target:s}=e,l=(u=this._univerInstanceService.getUnit(i))==null?void 0:u.getSheetBySheetId(r);if(!l)throw new Error("No active sheet found");const c=l.getCellMatrix(),d=[];return s.rows.forEach(h=>{const g=[];s.cols.forEach(S=>{g.push(a.Tools.deepClone(c.getValue(h,S)))}),d.push(g)}),this._beforeApplyData=d,this._copyData=this._getCopyData(e,t),this._currentLocation=e,this._shouldDisableSeries(this._copyData)?(this._autoFillService.setDisableApplyType(le.SERIES,!0),le.COPY):(this._autoFillService.setDisableApplyType(le.SERIES,!1),this._getPreferredApplyType(this._copyData))}_fillData(e,t,i){var H,W,B;const r=[],s=[];let l=!0;i===le.NO_FORMAT&&(l=!1,i=le.SERIES);const{source:c,target:d,unitId:u,subUnitId:h}=e;if(!c||!d||t==null)return{undos:r,redos:s};const g=at(c),S=at(d),{cols:f,rows:v}=d,{cols:p,rows:C}=c,_=this._copyData;let w;t===a.Direction.DOWN||t===a.Direction.UP?w=C.length:w=p.length;const E=[];if(t===a.Direction.DOWN||t===a.Direction.UP){const U=v.length,X=[];f.forEach((F,Y)=>{const j=_[Y],Q=this._getApplyData(j,w,U,t,i,l,e);X.push(Q)});for(let F=0;F<X[0].length;F++){const Y=[];for(let j=0;j<X.length;j++)Y.push({s:null,...X[j][F]});E.push(Y)}}else{const U=f.length;v.forEach((X,F)=>{const Y=_[F],j=this._getApplyData(Y,w,U,t,i,l,e),Q=[];for(let oe=0;oe<j.length;oe++)Q.push({s:null,...j[oe]});E.push(Q)})}let O=[];const R=(H=this._univerInstanceService.getUnit(u))==null?void 0:H.getStyles();if(l?(O=this._getMergeApplyData(g,S,t,w,e),E.forEach(U=>{U.forEach(X=>{X&&R&&R&&(X.s=R.getStyleByCell(X))})})):E.forEach((U,X)=>{U.forEach((F,Y)=>{F&&R&&(F.s=R.getStyleByCell(this._beforeApplyData[X][Y])||null)})}),i===le.ONLY_FORMAT&&E.forEach((U,X)=>{U.forEach((F,Y)=>{if(F){const j=this._beforeApplyData[X][Y]||{};F.f=j.f,F.si=j.si,F.t=j.t,F.v=j.v}})}),l){const U=[],X=(B=(W=this._univerInstanceService.getUniverSheetInstance(u))==null?void 0:W.getSheetBySheetId(h))==null?void 0:B.getMergeData();X&&X.forEach(j=>{a.Rectangle.intersects(j,S)&&U.push(j)});const F={unitId:u,subUnitId:h,ranges:U},Y=this._injector.invoke(m.RemoveMergeUndoMutationFactory,F);U.length&&(s.push({id:m.RemoveWorksheetMergeMutation.id,params:F}),r.unshift({id:m.AddWorksheetMergeMutation.id,params:Y}))}const P={subUnitId:h,unitId:u,cellValue:Id([d])},A=this._injector.invoke(m.SetRangeValuesUndoMutationFactory,P);s.push({id:m.SetRangeValuesMutation.id,params:P}),r.unshift({id:m.SetRangeValuesMutation.id,params:A});const k=new a.ObjectMatrix;v.forEach((U,X)=>{f.forEach((F,Y)=>{E[X][Y]&&k.setValue(U,F,E[X][Y])})});const N=k.getMatrix(),V={subUnitId:h,unitId:u,cellValue:N},L=this._injector.invoke(m.SetRangeValuesUndoMutationFactory,V);if(this._autoFillService.getActiveHooks().forEach(U=>{var X;(X=U.onBeforeSubmit)==null||X.call(U,e,t,i,N)}),r.unshift({id:m.SetRangeValuesMutation.id,params:L}),s.push({id:m.SetRangeValuesMutation.id,params:V}),O!=null&&O.length){const U=m.getAddMergeMutationRangeByType(O),X={unitId:u,subUnitId:h,ranges:U},F=this._injector.invoke(m.AddMergeUndoMutationFactory,X);r.unshift({id:m.RemoveWorksheetMergeMutation.id,params:F}),s.push({id:m.AddWorksheetMergeMutation.id,params:X})}return{undos:r,redos:s}}_shouldDisableSeries(e){return e.every(t=>Object.keys(t).every(i=>{var r;return((r=t[i])==null?void 0:r.length)===0||[_e.OTHER,_e.FORMULA].includes(i)}))}_getPreferredApplyType(e){return e.every(i=>Object.keys(i).every(r=>{var s,l;return((s=i[r])==null?void 0:s.length)===0||((l=i[r])==null?void 0:l.length)===1&&i[r][0].data.length===1&&_e.NUMBER===r}))?le.COPY:le.SERIES}},T.AutoFillController=hh([xt(0,a.IUniverInstanceService),xt(1,a.ICommandService),xt(2,ct),xt(3,me),xt(4,M.IRenderManagerService),xt(5,a.Inject(a.Injector)),xt(6,a.Inject(T.SheetsRenderService))],T.AutoFillController);var mh=Object.getOwnPropertyDescriptor,gh=(n,o,e,t)=>{for(var i=t>1?void 0:t?mh(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},pr=(n,o)=>(e,t)=>o(e,t,n);T.CellCustomRenderController=class extends a.Disposable{constructor(e,t,i,r){super();y(this,"_enterActiveRender");this._context=e,this._sheetSkeletonManagerService=t,this._renderManagerService=i,this._permissionService=r,this._initEventBinding()}_initEventBinding(){const e=new a.DisposableCollection,t=this._context.unit,i=r=>{if(e.dispose(),!r)return;const s=this._context.unitId,{skeleton:l}=r,c=this._renderManagerService.getRenderById(s);if(c&&c.mainComponent){const d=c.mainComponent,u=S=>{const{offsetX:f,offsetY:v}=S,p=c.scene,C=t.getActiveSheet();if(!C)return;const _=p.getActiveViewportByCoord(M.Vector2.FromArray([f,v]));if(!_)return;const{scaleX:w,scaleY:E}=p.getAncestorScale(),O={x:_.viewportScrollX,y:_.viewportScrollY},R=l.getCellIndexByOffset(f,v,w,E,O),P=l.worksheet.getMergedCell(R.row,R.column),A={actualRow:P?P.startRow:R.row,actualCol:P?P.startColumn:R.column,row:R.row,col:R.column};if(!A||!l)return;const k=C.getCell(A.actualRow,A.actualCol);if(!k)return;const N=k.customRender;if(!(N!=null&&N.length))return;const V=A.actualRow,L=A.actualCol,H=N.sort(a.sortRules),W=C.getSheetId(),B={data:k,style:l.getStyles().getStyleByCell(k),primaryWithCoord:l.getCellWithCoordByIndex(A.actualRow,A.actualCol),unitId:s,subUnitId:W,row:V,col:L,workbook:t,worksheet:C},U={x:O.x+f/w,y:O.y+v/E},X=H.find(F=>{var Y;return(Y=F.isHit)==null?void 0:Y.call(F,U,B)});if(X)return[X,B]},h=d.onPointerDown$.subscribeEvent(S=>{var v,p,C,_;const f=u(S);if(f){const[w,E]=f,{row:O,col:R,worksheet:P,unitId:A,subUnitId:k}=E;if(!((v=this._permissionService.composePermission([new m.WorkbookEditablePermission(A).id,new m.WorksheetEditPermission(A,k).id]))==null?void 0:v.every(L=>L.value)))return!1;const V=(C=(p=P.getCell(O,R))==null?void 0:p.selectionProtection)==null?void 0:C[0];if((V==null?void 0:V[m.UnitAction.Edit])===!1)return!1;(_=w.onPointerDown)==null||_.call(w,E,S)}}),g=a.fromEventSubject(d.onPointerMove$).pipe(D.throttleTime(30)).subscribe(S=>{var v,p,C,_,w,E;const f=u(S);if(f){const[O,R]=f;this._enterActiveRender?this._enterActiveRender.render!==O&&((p=(v=this._enterActiveRender.render).onPointerLeave)==null||p.call(v,this._enterActiveRender.cellContext,S),this._enterActiveRender={render:O,cellContext:R},(C=O.onPointerEnter)==null||C.call(O,R,S)):(this._enterActiveRender={render:O,cellContext:R},(_=O.onPointerEnter)==null||_.call(O,R,S))}else this._enterActiveRender&&((E=(w=this._enterActiveRender.render).onPointerLeave)==null||E.call(w,this._enterActiveRender.cellContext,S),this._enterActiveRender=null)});h&&e.add(h),g&&e.add(g)}};this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i)),i(this._sheetSkeletonManagerService.getCurrentParam()),this.disposeWithMe(e)}},T.CellCustomRenderController=gh([pr(1,a.Inject(T.SheetSkeletonManagerService)),pr(2,M.IRenderManagerService),pr(3,a.IPermissionService)],T.CellCustomRenderController);var Sh=Object.getOwnPropertyDescriptor,fh=(n,o,e,t)=>{for(var i=t>1?void 0:t?Sh(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},Pa=(n,o)=>(e,t)=>o(e,t,n);T.DragManagerService=class extends a.Disposable{constructor(e,t){super();y(this,"_currentCell$",new D.Subject);y(this,"currentCell$",this._currentCell$.asObservable().pipe(D.distinctUntilChanged((e,t)=>{var i,r,s,l,c,d,u,h;return((i=e==null?void 0:e.location)==null?void 0:i.unitId)===((r=t==null?void 0:t.location)==null?void 0:r.unitId)&&((s=e==null?void 0:e.location)==null?void 0:s.subUnitId)===((l=t==null?void 0:t.location)==null?void 0:l.subUnitId)&&((c=e==null?void 0:e.location)==null?void 0:c.row)===((d=t==null?void 0:t.location)==null?void 0:d.row)&&((u=e==null?void 0:e.location)==null?void 0:u.col)===((h=t==null?void 0:t.location)==null?void 0:h.col)})));y(this,"_endCell$",new D.Subject);y(this,"endCell$",this._endCell$.asObservable());this._univerInstanceService=e,this._renderManagerService=t,this._initCellDisposableListener()}dispose(){super.dispose(),this._currentCell$.complete(),this._endCell$.complete()}_initCellDisposableListener(){this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(e=>{e||(this._currentCell$.next(null),this._endCell$.next(null))}))}_calcActiveCell(e,t){const i=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!i)return null;const r=i.getActiveSheet();if(!r)return;const s=this._renderManagerService.getRenderById(i.getUnitId());if(!s)return;const l=s.with(T.SheetSkeletonManagerService).getCurrentParam(),d=s.with(T.SheetScrollManagerService).getCurrentScrollState();if(!(!l||!d||!s))return Ra(s,i,r,l,e,t)}onDragOver(e){const{offsetX:t,offsetY:i,dataTransfer:r}=e,s=this._calcActiveCell(t,i);if(!s){this._currentCell$.next(null);return}const{location:l,position:c}=s;this._currentCell$.next({location:l,position:c,dataTransfer:r})}onDrop(e){const{offsetX:t,offsetY:i,dataTransfer:r}=e,s=this._calcActiveCell(t,i);if(!s){this._endCell$.next(null);return}const{location:l,position:c}=s;this._endCell$.next({location:l,position:c,dataTransfer:r})}},T.DragManagerService=fh([Pa(0,a.IUniverInstanceService),Pa(1,M.IRenderManagerService)],T.DragManagerService);var vh=Object.getOwnPropertyDescriptor,ph=(n,o,e,t)=>{for(var i=t>1?void 0:t?vh(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},Cr=(n,o)=>(e,t)=>o(e,t,n);T.DragRenderController=class extends a.Disposable{constructor(o,e,t,i){super(),this._context=o,this._renderManagerService=e,this._dragManagerService=t,this._sheetSkeletonManagerService=i,this._initDragEvent()}_initDragEvent(){const o=new a.DisposableCollection,e=t=>{if(o.dispose(),!t)return;const{scene:i}=this._context,r=i.onDragOver$.subscribeEvent(l=>{this._dragManagerService.onDragOver(l)}),s=i.onDrop$.subscribeEvent(l=>{this._dragManagerService.onDrop(l)});o.add({dispose(){r.unsubscribe(),s.unsubscribe()}})};e(this._sheetSkeletonManagerService.getCurrentParam()),this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(t=>{e(t)}))}},T.DragRenderController=ph([Cr(1,M.IRenderManagerService),Cr(2,a.Inject(T.DragManagerService)),Cr(3,a.Inject(T.SheetSkeletonManagerService))],T.DragRenderController);class Ir{constructor(){y(this,"_state",null);y(this,"_rect",null);y(this,"_state$",new D.BehaviorSubject(null));y(this,"state$",this._state$.asObservable());y(this,"_rect$",new D.BehaviorSubject(null));y(this,"rect$",this._rect$.asObservable());y(this,"_focus",!1);y(this,"_focus$",new D.BehaviorSubject(this._focus));y(this,"focus$",this._focus$.asObservable())}dispose(){this._state$.complete(),this._state=null,this._rect$.complete(),this._rect=null}setState(o){this._state=o,this._refresh(o)}getRect(){return this._rect}setRect(o){this._rect=o,this._rect$.next(o)}getState(){return this._state}setFocus(o=!1){this._focus=o,this._focus$.next(o)}_refresh(o){this._state$.next(o)}}const bn=a.createIdentifier("univer.sheet-cell-editor-manager.service"),Te="sheets-ui.config",lo={formulaBar:!0,statusBarStatistic:!0,protectedRangeShadow:!0,maxAutoHeightCount:1e3};function _r(n){return n===!0?"always":n===!1?"none":n||"always"}function pe({ref:n,...o}){const{icon:e,id:t,className:i,extend:r,...s}=o,l=`univerjs-icon univerjs-icon-${t} ${i||""}`.trim(),c=x.useRef(`_${_h()}`);return Oa(e,`${t}`,{defIds:e.defIds,idSuffix:c.current},{ref:n,className:l,...s},r)}function Oa(n,o,e,t,i){return x.createElement(n.tag,{key:o,...Ch(n,e,i),...t},(Ih(n,e).children||[]).map((r,s)=>Oa(r,`${o}-${n.tag}-${s}`,e,void 0,i)))}function Ch(n,o,e){const t={...n.attrs};e!=null&&e.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=e.colorChannel1),n.tag==="mask"&&t.id&&(t.id=t.id+o.idSuffix),Object.entries(t).forEach(([r,s])=>{r==="mask"&&typeof s=="string"&&(t[r]=s.replace(/url\(#(.*)\)/,`url(#$1${o.idSuffix})`))});const{defIds:i}=o;return!i||i.length===0||(n.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+o.idSuffix),Object.entries(t).forEach(([r,s])=>{typeof s=="string"&&(t[r]=s.replace(/url\(#(.*)\)/,`url(#$1${o.idSuffix})`))})),t}function Ih(n,o){var t;const{defIds:e}=o;return!e||e.length===0?n:n.tag==="defs"&&((t=n.children)!=null&&t.length)?{...n,children:n.children.map(i=>typeof i.attrs.id=="string"&&e&&e.includes(i.attrs.id)?{...i,attrs:{...i.attrs,id:i.attrs.id+o.idSuffix}}:i)}:n}function _h(){return Math.random().toString(36).substring(2,8)}pe.displayName="UniverIcon";const bh={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ut=x.forwardRef(function(o,e){return x.createElement(pe,Object.assign({},o,{id:"check-mark-icon",ref:e,icon:bh}))});Ut.displayName="CheckMarkIcon";const wh={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.71274 2.86421C3.47843 2.6299 3.09853 2.6299 2.86421 2.86421C2.6299 3.09853 2.6299 3.47843 2.86421 3.71274L7.15154 8.00007L2.86421 12.2874C2.6299 12.5217 2.6299 12.9016 2.86421 13.1359C3.09853 13.3702 3.47843 13.3702 3.71274 13.1359L8.00007 8.84859L12.2874 13.1359C12.5217 13.3702 12.9016 13.3702 13.1359 13.1359C13.3702 12.9016 13.3702 12.5217 13.1359 12.2874L8.84859 8.00007L13.1359 3.71274C13.3702 3.47843 13.3702 3.09853 13.1359 2.86421C12.9016 2.6299 12.5217 2.6299 12.2874 2.86421L8.00007 7.15154L3.71274 2.86421Z"}}]},Aa=x.forwardRef(function(o,e){return x.createElement(pe,Object.assign({},o,{id:"close-icon",ref:e,icon:wh}))});Aa.displayName="CloseIcon";const Eh={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"g",attrs:{fill:"currentColor",clipPath:"url(#convert-icon_clip0_911_593)"},children:[{tag:"path",attrs:{d:"M2.44766 0.848145C1.564 0.848145 0.847656 1.56449 0.847656 2.44814V6.44814C0.847656 7.3318 1.564 8.04814 2.44766 8.04814H6.44766C7.33131 8.04814 8.04766 7.3318 8.04766 6.44814V2.44814C8.04766 1.56449 7.33131 0.848145 6.44766 0.848145H2.44766ZM2.04766 6.44814V5.04824H3.84775V6.84814H2.44766C2.22674 6.84814 2.04766 6.66906 2.04766 6.44814ZM2.04766 3.84824H3.84775V2.04814H2.44766C2.22674 2.04814 2.04766 2.22723 2.04766 2.44814V3.84824ZM5.04775 6.84814V5.04824H6.84766V6.44814C6.84766 6.66906 6.66857 6.84814 6.44766 6.84814H5.04775ZM5.04775 3.84824H6.84766V2.44814C6.84766 2.22723 6.66857 2.04814 6.44766 2.04814H5.04775V3.84824Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{d:"M9.55215 7.95166C8.66849 7.95166 7.95215 8.668 7.95215 9.55166V13.5517C7.95215 14.4353 8.66849 15.1517 9.55215 15.1517L11.5522 15.1517L13.5521 15.1517C14.4358 15.1517 15.1521 14.4353 15.1521 13.5517L15.1521 11.5518L15.1521 9.55166C15.1521 8.668 14.4358 7.95166 13.5521 7.95166H9.55215ZM13.9521 10.9518V9.55166C13.9521 9.33075 13.7731 9.15166 13.5521 9.15166H12.1522V10.9518H13.9521ZM10.9522 10.9518V9.15166H9.55215C9.33123 9.15166 9.15215 9.33075 9.15215 9.55166V10.9518H10.9522ZM9.15215 12.1518H10.9522V13.9517H9.55215C9.33123 13.9517 9.15215 13.7726 9.15215 13.5517V12.1518ZM12.1522 12.1518H13.9521V13.5517C13.9521 13.7726 13.7731 13.9517 13.5521 13.9517H12.1522V12.1518Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{d:"M9.62158 2.44912C9.62158 2.11775 9.89021 1.84912 10.2216 1.84912H12.7516C13.6352 1.84912 14.3516 2.56547 14.3516 3.44912V5.9791C14.3516 6.31047 14.0829 6.5791 13.7516 6.5791C13.4202 6.5791 13.1516 6.31047 13.1516 5.9791V3.44912C13.1516 3.22821 12.9725 3.04912 12.7516 3.04912H10.2216C9.89021 3.04912 9.62158 2.78049 9.62158 2.44912Z"}},{tag:"path",attrs:{d:"M5.77871 14.1507C6.11008 14.1507 6.37871 13.8821 6.37871 13.5507C6.37871 13.2193 6.11008 12.9507 5.77871 12.9507L3.24873 12.9507C3.02782 12.9507 2.84873 12.7716 2.84873 12.5507L2.84873 10.0207C2.84873 9.68933 2.5801 9.4207 2.24873 9.4207C1.91736 9.4207 1.64873 9.68933 1.64873 10.0207L1.64873 12.5507C1.64873 13.4343 2.36507 14.1507 3.24873 14.1507H5.77871Z"}}]},{tag:"defs",attrs:{},children:[{tag:"clipPath",attrs:{id:"convert-icon_clip0_911_593"},children:[{tag:"path",attrs:{fill:"white",d:"M0 0H16V16H0z"}}]}]}],defIds:["convert-icon_clip0_911_593"]},Da=x.forwardRef(function(o,e){return x.createElement(pe,Object.assign({},o,{id:"convert-icon",ref:e,icon:Eh}))});Da.displayName="ConvertIcon";const Th={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.3313 1.4667C5.3313 1.13533 5.59993 0.866699 5.9313 0.866699H10.069C10.4004 0.866699 10.669 1.13533 10.669 1.4667C10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443C14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928L9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171C10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778L9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539C9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263L6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539C5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778L6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},co=x.forwardRef(function(o,e){return x.createElement(pe,Object.assign({},o,{id:"delete-icon",ref:e,icon:Th}))});co.displayName="DeleteIcon";const yh={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.85869 12.9216C8.38445 13.4708 7.61555 13.4708 7.14131 12.9216L0.358114 5.06726C-0.406895 4.18144 0.134916 2.66683 1.2168 2.66683L14.7832 2.66683C15.8651 2.66683 16.4069 4.18144 15.6419 5.06726L8.85869 12.9216Z"}}]},ka=x.forwardRef(function(o,e){return x.createElement(pe,Object.assign({},o,{id:"dropdown-icon",ref:e,icon:yh}))});ka.displayName="DropdownIcon";const Rh={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M15 8C15 11.866 11.866 15 8 15C4.13401 15 1 11.866 1 8C1 4.13401 4.13401 1 8 1C11.866 1 15 4.13401 15 8ZM10.3097 5.69014C10.544 5.92445 10.544 6.30435 10.3097 6.53867L8.84843 7.9999L10.3099 9.46137C10.5442 9.69569 10.5442 10.0756 10.3099 10.3099C10.0756 10.5442 9.69569 10.5442 9.46137 10.3099L7.9999 8.84843L6.53842 10.3099C6.30411 10.5442 5.92421 10.5442 5.6899 10.3099C5.45558 10.0756 5.45558 9.69569 5.6899 9.46137L7.15137 7.9999L5.69014 6.53867C5.45583 6.30435 5.45583 5.92445 5.69014 5.69014C5.92445 5.45583 6.30435 5.45583 6.53867 5.69014L7.9999 7.15137L9.46113 5.69014C9.69544 5.45583 10.0753 5.45583 10.3097 5.69014Z",fillRule:"evenodd",clipRule:"evenodd"}}]},br=x.forwardRef(function(o,e){return x.createElement(pe,Object.assign({},o,{id:"error-icon",ref:e,icon:Rh}))});br.displayName="ErrorIcon";const Mh={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.28096 4.6541C1.57489 4.50109 1.93721 4.61533 2.09022 4.90926C2.27315 5.26067 2.55999 5.60455 2.94829 5.92278C4.04628 6.82266 5.87505 7.44865 7.99828 7.44865C10.1215 7.44865 11.9503 6.82267 13.0482 5.92279C13.4366 5.60455 13.7234 5.26067 13.9063 4.90927C14.0594 4.61533 14.4217 4.50109 14.7156 4.65409C15.0095 4.8071 15.1238 5.16941 14.9708 5.46334C14.6995 5.98445 14.2981 6.44997 13.8089 6.8509C13.7298 6.91575 13.6481 6.97914 13.564 7.041L15.2245 8.70153C15.4588 8.93585 15.4588 9.31575 15.2245 9.55006C14.9902 9.78438 14.6103 9.78438 14.376 9.55006L12.5041 7.67822C11.8977 7.97568 11.2181 8.21208 10.4884 8.37706L11.0996 10.6581C11.1853 10.9782 10.9954 11.3072 10.6753 11.393C10.3552 11.4787 10.0262 11.2888 9.94045 10.9687L9.29949 8.57652C8.8758 8.62404 8.44081 8.64865 7.99828 8.64865C7.55276 8.64865 7.11487 8.62371 6.68846 8.57555L6.04723 10.9687C5.96147 11.2888 5.63247 11.4788 5.31239 11.393C4.99231 11.3073 4.80236 10.9783 4.88812 10.6582L5.49983 8.37516C4.7743 8.2105 4.09843 7.9752 3.49498 7.67947L1.62436 9.55009C1.39005 9.78441 1.01015 9.78441 0.775835 9.5501C0.54152 9.31578 0.541518 8.93588 0.775832 8.70157L2.43478 7.04261C2.34987 6.98024 2.26746 6.91632 2.18764 6.8509C1.69842 6.44997 1.29706 5.98445 1.0258 5.46335C0.872791 5.16942 0.987031 4.80711 1.28096 4.6541Z"}}]},Na=x.forwardRef(function(o,e){return x.createElement(pe,Object.assign({},o,{id:"eyelash-icon",ref:e,icon:Mh}))});Na.displayName="EyelashIcon";const Ph={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M6.06409 5.53454C5.93592 5.53454 5.84083 5.41567 5.86897 5.29063L5.95442 4.9109C6.05444 4.48178 6.23806 4.11547 6.51182 3.81952C6.81082 3.49628 7.25398 3.35405 7.79738 3.35405C7.99847 3.35405 8.21359 3.37775 8.44188 3.42245C8.46089 3.42617 8.47974 3.43006 8.49846 3.4341C8.7099 3.4798 8.93698 3.38478 9.02031 3.18514L9.24767 2.6404C9.33457 2.43219 9.23178 2.19404 9.01582 2.12874C8.98358 2.11899 8.95028 2.10912 8.91591 2.09914C8.62745 2.01631 8.28392 1.97217 7.88074 1.97217C6.82015 1.97217 6.02714 2.23936 5.4746 2.7444C4.90987 3.26069 4.50889 3.99917 4.28413 4.9762L2.83703 11.1909C2.76126 11.5286 2.666 11.8917 2.54844 12.2812C2.42975 12.6734 2.2873 13.0595 2.12221 13.4373C1.95577 13.8159 1.76813 14.1762 1.55955 14.5171C1.49345 14.6251 1.42515 14.7282 1.35467 14.8263C1.26508 14.9509 1.3347 15.133 1.48655 15.1554C2.13635 15.2509 2.8179 15.0763 3.18197 14.5296C3.32661 14.3124 3.46779 14.0646 3.60509 13.7851C3.96635 13.0497 4.30522 12.0103 4.61867 10.6574L5.469 7.01534C5.49013 6.92483 5.57082 6.86081 5.66376 6.86081H7.62478C7.8097 6.86081 7.97051 6.73405 8.01371 6.55425L8.14014 6.02798C8.20057 5.77642 8.00992 5.53454 7.75121 5.53454H6.06409Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M14.3211 5.72037L12.5124 7.96963L11.4089 5.77754C11.3422 5.63012 11.1954 5.5354 11.0336 5.5354H10.3129C10.0085 5.5354 9.80921 5.85428 9.9427 6.1279L11.4089 9.05502L8.79783 12.1493C8.56587 12.4158 8.75519 12.8315 9.10855 12.8315H9.68607C9.80672 12.8315 9.9605 12.7822 10.0388 12.6904L12.1108 10.2648L13.1176 12.561C13.1786 12.7231 13.333 12.8315 13.5061 12.8315H14.3C14.5831 12.8315 14.7417 12.6175 14.6426 12.3524L13.1728 9.28628C13.1728 9.28628 15.4009 6.45542 15.6013 6.17892C15.7966 5.90929 15.6023 5.5354 15.2693 5.5354H14.6661C14.5275 5.5354 14.4333 5.58887 14.3211 5.72037Z"}}]},Va=x.forwardRef(function(o,e){return x.createElement(pe,Object.assign({},o,{id:"fx-icon",ref:e,icon:Ph}))});Va.displayName="FxIcon";const Oh={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},wr=x.forwardRef(function(o,e){return x.createElement(pe,Object.assign({},o,{id:"increase-icon",ref:e,icon:Oh}))});wr.displayName="IncreaseIcon";const Ah={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.00016 1.33203C6.68162 1.33203 5.39269 1.72302 4.29636 2.45557C3.20004 3.18811 2.34555 4.2293 1.84097 5.44747C1.33638 6.66565 1.20436 8.00609 1.4616 9.2993C1.71883 10.5925 2.35377 11.7804 3.28612 12.7127C4.21847 13.6451 5.40636 14.28 6.69956 14.5373C7.99277 14.7945 9.33321 14.6625 10.5514 14.1579C11.7696 13.6533 12.8108 12.7988 13.5433 11.7025C14.2758 10.6062 14.6668 9.31724 14.6668 7.9987C14.6649 6.23118 13.9619 4.53662 12.7121 3.2868C11.4622 2.03697 9.76768 1.33397 8.00016 1.33203ZM7.66683 3.9987C7.86461 3.9987 8.05795 4.05735 8.2224 4.16723C8.38685 4.27711 8.51502 4.43329 8.59071 4.61601C8.6664 4.79874 8.6862 4.99981 8.64762 5.19379C8.60903 5.38777 8.51379 5.56595 8.37394 5.7058C8.23409 5.84566 8.0559 5.9409 7.86192 5.97948C7.66794 6.01807 7.46687 5.99826 7.28415 5.92258C7.10142 5.84689 6.94524 5.71872 6.83536 5.55427C6.72548 5.38982 6.66683 5.19648 6.66683 4.9987C6.66683 4.73348 6.77219 4.47913 6.95972 4.29159C7.14726 4.10405 7.40162 3.9987 7.66683 3.9987ZM9.3335 11.332H6.66683C6.49002 11.332 6.32045 11.2618 6.19543 11.1368C6.0704 11.0117 6.00016 10.8422 6.00016 10.6654C6.00016 10.4886 6.0704 10.319 6.19543 10.194C6.32045 10.0689 6.49002 9.9987 6.66683 9.9987H7.3335V7.9987H6.66683C6.49002 7.9987 6.32045 7.92846 6.19543 7.80343C6.0704 7.67841 6.00016 7.50884 6.00016 7.33203C6.00016 7.15522 6.0704 6.98565 6.19543 6.86063C6.32045 6.7356 6.49002 6.66536 6.66683 6.66536H8.00016C8.17698 6.66536 8.34655 6.7356 8.47157 6.86063C8.59659 6.98565 8.66683 7.15522 8.66683 7.33203V9.9987H9.3335C9.51031 9.9987 9.67988 10.0689 9.8049 10.194C9.92993 10.319 10.0002 10.4886 10.0002 10.6654C10.0002 10.8422 9.92993 11.0117 9.8049 11.1368C9.67988 11.2618 9.51031 11.332 9.3335 11.332Z"}}]},Ha=x.forwardRef(function(o,e){return x.createElement(pe,Object.assign({},o,{id:"info-icon",ref:e,icon:Ah}))});Ha.displayName="InfoIcon";const Dh={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.62402 7.72905C2.58427 7.72905 2.55205 7.76127 2.55205 7.80102V13.6782C2.55205 13.7179 2.58427 13.7502 2.62402 13.7502H13.3755C13.4152 13.7502 13.4474 13.7179 13.4474 13.6782V7.80102C13.4474 7.76127 13.4152 7.72905 13.3755 7.72905H2.62402ZM1.35205 7.80102C1.35205 7.09853 1.92153 6.52905 2.62402 6.52905H13.3755C14.0779 6.52905 14.6474 7.09853 14.6474 7.80102V13.6782C14.6474 14.3807 14.0779 14.9502 13.3755 14.9502H2.62402C1.92153 14.9502 1.35205 14.3807 1.35205 13.6782V7.80102Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M8 2.25005C6.69847 2.25003 5.64336 3.30513 5.64336 4.60666V7.12895C5.64336 7.46032 5.37473 7.72895 5.04336 7.72895C4.71199 7.72895 4.44336 7.46032 4.44336 7.12895V4.60666C4.44336 2.64239 6.04451 1.05565 8.00879 1.05566M8 2.25005L8.00879 1.05566L8 2.25005ZM8.00879 1.05566L8 2.25005C9.30154 2.25003 10.3567 3.30513 10.3567 4.60666V7.12895C10.3567 7.46032 10.6253 7.72895 10.9567 7.72895C11.288 7.72895 11.5567 7.46032 11.5567 7.12895V4.60666C11.5567 2.64239 9.97306 1.05565 8.00879 1.05566Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M8.00039 9.4668C8.33176 9.4668 8.60039 9.73543 8.60039 10.0668V12.0827C8.60039 12.4141 8.33176 12.6827 8.00039 12.6827C7.66902 12.6827 7.40039 12.4141 7.40039 12.0827V10.0668C7.40039 9.73543 7.66902 9.4668 8.00039 9.4668Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Er=x.forwardRef(function(o,e){return x.createElement(pe,Object.assign({},o,{id:"lock-icon",ref:e,icon:Dh}))});Er.displayName="LockIcon";const kh={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M11.3536 6.14645C11.5488 6.34171 11.5488 6.65829 11.3536 6.85355L8.35355 9.85355C8.15829 10.0488 7.84171 10.0488 7.64645 9.85355L4.64645 6.85355C4.45118 6.65829 4.45118 6.34171 4.64645 6.14645C4.84171 5.95118 5.15829 5.95118 5.35355 6.14645L8 8.79289L10.6464 6.14645C10.8417 5.95118 11.1583 5.95118 11.3536 6.14645Z",fillRule:"evenodd",clipRule:"evenodd"}}]},wn=x.forwardRef(function(o,e){return x.createElement(pe,Object.assign({},o,{id:"more-down-icon",ref:e,icon:kh}))});wn.displayName="MoreDownIcon";const Nh={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.90913 3.57564C6.14345 3.34132 6.52335 3.34132 6.75766 3.57564L10.7577 7.57564C10.992 7.80995 10.992 8.18985 10.7577 8.42417L6.75766 12.4242C6.52335 12.6585 6.14345 12.6585 5.90913 12.4242C5.67482 12.1899 5.67482 11.81 5.90913 11.5756L9.48487 7.9999L5.90913 4.42417C5.67482 4.18985 5.67482 3.80995 5.90913 3.57564Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Tr=x.forwardRef(function(o,e){return x.createElement(pe,Object.assign({},o,{id:"more-icon",ref:e,icon:Nh}))});Tr.displayName="MoreIcon";const Vh={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.666 2.70571C11.7769 1.76476 10.3295 1.76476 9.4404 2.70571L3.37843 9.12427C3.31779 9.18848 3.27756 9.26409 3.24979 9.3439C3.24809 9.3493 3.24299 9.3529 3.24129 9.3583L2.02912 13.2097C1.96112 13.4251 2.01439 13.6633 2.16626 13.8236C2.27393 13.9382 2.41901 14 2.56692 14C2.62699 14 2.68762 13.9898 2.74599 13.9688L6.3825 12.6846C6.3876 12.6828 6.391 12.678 6.39553 12.6762C6.47147 12.6474 6.54287 12.6042 6.60351 12.54L12.666 6.12202C13.5558 5.18048 13.5558 3.64725 12.666 2.70571ZM8.62832 5.26209L9.04031 5.69836C9.03918 5.69956 9.03748 5.70016 9.03634 5.70136L4.99182 9.9836L4.58096 9.54853L8.62832 5.26209ZM3.46287 12.4512L4.02673 10.6593L5.15446 11.8535L3.46287 12.4512ZM6.20342 11.2672L5.79256 10.8321L9.83709 6.54988C9.83822 6.54868 9.83879 6.54688 9.83992 6.54568L10.2513 6.98135L6.20342 11.2672ZM11.8647 5.27349L11.0532 6.13282L9.42963 4.41356L10.2411 3.55423C10.6888 3.08016 11.417 3.08076 11.8642 3.55423C12.3124 4.0283 12.3124 4.79942 11.8647 5.27349Z"}}]},Wa=x.forwardRef(function(o,e){return x.createElement(pe,Object.assign({},o,{id:"pen-icon",ref:e,icon:Vh}))});Wa.displayName="PenIcon";const Hh={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.785 6.77762C5.78908 6.7777 5.79316 6.77774 5.79725 6.77774C5.80134 6.77774 5.80543 6.7777 5.8095 6.77762H10.0184C10.0225 6.7777 10.0266 6.77774 10.0307 6.77774C10.0347 6.77774 10.0388 6.7777 10.0429 6.77762H13.6638V7.63727C13.6638 7.96864 13.9324 8.23727 14.2638 8.23727C14.5951 8.23727 14.8638 7.96864 14.8638 7.63727V3.9999C14.8638 2.56395 13.6997 1.39989 12.2637 1.3999L3.56389 1.39999C2.12797 1.40001 0.96393 2.56405 0.96392 3.99998L0.963867 11.6666C0.963857 13.1025 2.12792 14.2666 3.56387 14.2666H8.0542C8.38557 14.2666 8.6542 13.9979 8.6542 13.6666C8.6542 13.3352 8.38557 13.0666 8.0542 13.0666H3.56387C2.79067 13.0666 2.16386 12.4398 2.16387 11.6666L2.1639 6.77762H5.785ZM6.39725 2.59996L9.43065 2.59993V5.57762H6.39725V2.59996ZM5.19725 5.57762V2.59998L3.56391 2.59999C2.79072 2.6 2.16393 3.22679 2.16392 3.99998L2.16391 5.57762H5.19725ZM13.6638 5.57762V3.9999C13.6638 3.2267 13.037 2.59989 12.2638 2.5999L10.6307 2.59992V5.57762H13.6638Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M14.1223 10.2333V10.7496C14.7087 10.9869 15.1223 11.5618 15.1223 12.2333V12.8999C15.1223 13.7836 14.406 14.4999 13.5223 14.4999H11.5223C10.6387 14.4999 9.92235 13.7836 9.92235 12.8999V12.2333C9.92235 11.5618 10.336 10.9869 10.9223 10.7496V10.2333C10.9223 9.34961 11.6387 8.63328 12.5223 8.63328C13.406 8.63328 14.1223 9.34961 14.1223 10.2333ZM11.1223 12.2333C11.1223 12.0124 11.3014 11.8333 11.5223 11.8333H13.5223C13.7433 11.8333 13.9223 12.0124 13.9223 12.2333V12.8999C13.9223 13.1209 13.7433 13.2999 13.5223 13.2999H11.5223C11.3014 13.2999 11.1223 13.1209 11.1223 12.8999V12.2333ZM12.9223 10.2333V10.6333H12.1223V10.2333C12.1223 10.0124 12.3014 9.83328 12.5223 9.83328C12.7433 9.83328 12.9223 10.0124 12.9223 10.2333Z",fillRule:"evenodd",clipRule:"evenodd"}}]},La=x.forwardRef(function(o,e){return x.createElement(pe,Object.assign({},o,{id:"protect-icon",ref:e,icon:Hh}))});La.displayName="ProtectIcon";const Wh={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M15 8C15 11.866 11.866 15 8 15C4.13401 15 1 11.866 1 8C1 4.13401 4.13401 1 8 1C11.866 1 15 4.13401 15 8ZM8.00008 12.3671C8.46031 12.3671 8.83342 11.994 8.83342 11.5338C8.83342 11.0735 8.46031 10.7004 8.00008 10.7004C7.53985 10.7004 7.16675 11.0735 7.16675 11.5338C7.16675 11.994 7.53985 12.3671 8.00008 12.3671ZM8.5999 4.4335C8.5999 4.10213 8.33127 3.8335 7.9999 3.8335C7.66853 3.8335 7.3999 4.10213 7.3999 4.4335V9.36683C7.3999 9.6982 7.66853 9.96683 7.9999 9.96683C8.33127 9.96683 8.5999 9.6982 8.5999 9.36683V4.4335Z",fillRule:"evenodd",clipRule:"evenodd"}}]},xa=x.forwardRef(function(o,e){return x.createElement(pe,Object.assign({},o,{id:"warning-icon",ref:e,icon:Wh}))});xa.displayName="WarningIcon";const Lh={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.6551 1.98906C11.7476 1.08113 10.2757 1.08149 9.3686 1.98987L4.82542 6.53955C4.75087 6.61421 4.69336 6.70411 4.65682 6.80309L3.2461 10.625C3.16506 10.8446 3.21909 11.0912 3.3845 11.2568C3.54991 11.4224 3.79651 11.4767 4.01616 11.3959L7.85031 9.98517C7.94979 9.94856 8.04014 9.89077 8.11508 9.81579L12.6552 5.27327C13.5618 4.36621 13.5618 2.89607 12.6551 1.98906ZM10.2177 2.83779C10.6562 2.39869 11.3677 2.39851 11.8064 2.8374C12.2447 3.27584 12.2447 3.9865 11.8065 4.42497L7.3392 8.89457L4.82213 9.82068L5.74706 7.31487L10.2177 2.83779Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.79238 13.2999C1.46101 13.2999 1.19238 13.5685 1.19238 13.8999C1.19238 14.2313 1.46101 14.4999 1.79238 14.4999H14.4924C14.8238 14.4999 15.0924 14.2313 15.0924 13.8999C15.0924 13.5685 14.8238 13.2999 14.4924 13.2999H1.79238Z"}}]},yr=x.forwardRef(function(o,e){return x.createElement(pe,Object.assign({},o,{id:"write-icon",ref:e,icon:Lh}))});yr.displayName="WriteIcon";const xh={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M11.0363 12.2367V14.0367C11.0363 14.3681 11.3049 14.6367 11.6363 14.6367C11.9676 14.6367 12.2363 14.3681 12.2363 14.0367V12.2367H14.0364C14.3677 12.2367 14.6364 11.9681 14.6364 11.6367C14.6364 11.3054 14.3677 11.0367 14.0364 11.0367H12.2363V9.23672C12.2363 8.90535 11.9676 8.63672 11.6363 8.63672C11.3049 8.63672 11.0363 8.90535 11.0363 9.23672V11.0367H9.23635C8.90498 11.0367 8.63635 11.3054 8.63635 11.6367C8.63635 11.9681 8.90498 12.2367 9.23635 12.2367H11.0363Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M2.56365 1.36377C1.90091 1.36377 1.36365 1.90103 1.36365 2.56377V6.16377C1.36365 6.82651 1.90091 7.36377 2.56365 7.36377H6.16365C6.82639 7.36377 7.36365 6.82651 7.36365 6.16377V2.56377C7.36365 1.90103 6.82639 1.36377 6.16365 1.36377H2.56365ZM6.16365 2.56377H2.56365L2.56365 6.16377H6.16365V2.56377Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M2.56365 8.63647C1.90091 8.63647 1.36365 9.17373 1.36365 9.83647V13.4365C1.36365 14.0992 1.90091 14.6365 2.56365 14.6365H6.16365C6.82639 14.6365 7.36365 14.0992 7.36365 13.4365V9.83647C7.36365 9.17373 6.82639 8.63647 6.16365 8.63647H2.56365ZM6.16365 9.83647H2.56365L2.56365 13.4365H6.16365V9.83647Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M9.83635 7.36377C9.17361 7.36377 8.63635 6.82651 8.63635 6.16377V2.56377C8.63635 1.90103 9.17361 1.36377 9.83635 1.36377H13.4364C14.0991 1.36377 14.6364 1.90103 14.6364 2.56377V6.16377C14.6364 6.82651 14.0991 7.36377 13.4364 7.36377H9.83635ZM9.83635 6.16377V2.56377L13.4364 2.56377V6.16377H9.83635Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ua=x.forwardRef(function(o,e){return x.createElement(pe,Object.assign({},o,{id:"autofill-double-icon",ref:e,icon:xh}))});Ua.displayName="AutofillDoubleIcon";const Uh={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M6.4833 1.65005C6.4833 1.31868 6.21467 1.05005 5.8833 1.05005C5.55193 1.05005 5.2833 1.31868 5.2833 1.65005V5.28345H1.65029C1.31892 5.28345 1.05029 5.55208 1.05029 5.88345C1.05029 6.21482 1.31892 6.48345 1.65029 6.48345H5.2833V9.51684H1.65029C1.31892 9.51684 1.05029 9.78547 1.05029 10.1168C1.05029 10.4482 1.31892 10.7168 1.65029 10.7168H5.2833V14.35C5.2833 14.6814 5.55193 14.95 5.8833 14.95C6.21467 14.95 6.4833 14.6814 6.4833 14.35V10.7168H9.5167V14.35C9.5167 14.6814 9.78533 14.95 10.1167 14.95C10.4481 14.95 10.7167 14.6814 10.7167 14.35V10.7168H14.3503C14.6817 10.7168 14.9503 10.4482 14.9503 10.1168C14.9503 9.78547 14.6817 9.51685 14.3503 9.51685H10.7167V6.48345H14.3503C14.6817 6.48345 14.9503 6.21482 14.9503 5.88345C14.9503 5.55208 14.6817 5.28345 14.3503 5.28345H10.7167V1.65005C10.7167 1.31868 10.4481 1.05005 10.1167 1.05005C9.78533 1.05005 9.5167 1.31868 9.5167 1.65005V5.28345L6.4833 5.28345V1.65005ZM6.4833 6.48345V9.51684L9.5167 9.51685V6.48345L6.4833 6.48345Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.0498 3.65005C1.0498 2.21411 2.21386 1.05005 3.6498 1.05005H12.3498C13.7857 1.05005 14.9498 2.21411 14.9498 3.65005V12.3501C14.9498 13.786 13.7857 14.95 12.3498 14.95H3.6498C2.21386 14.95 1.0498 13.786 1.0498 12.35V3.65005ZM3.6498 2.25005C2.87661 2.25005 2.2498 2.87685 2.2498 3.65005V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V3.65005C13.7498 2.87685 13.123 2.25005 12.3498 2.25005H3.6498Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Rr=x.forwardRef(function(o,e){return x.createElement(pe,Object.assign({},o,{id:"hide-gridlines-double-icon",ref:e,icon:Uh}))});Rr.displayName="HideGridlinesDoubleIcon";const Bh={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.01281 1.36643C8.79386 0.585377 10.0602 0.585378 10.8412 1.36643L12.9223 3.44752C13.7034 4.22857 13.7034 5.4949 12.9223 6.27595L9.36445 9.83383C8.5834 10.6149 7.31707 10.6149 6.53602 9.83383L4.45493 7.75273C3.67388 6.97168 3.67388 5.70535 4.45493 4.9243L8.01281 1.36643ZM9.9927 2.21495C9.68028 1.90253 9.17375 1.90253 8.86133 2.21495L5.30346 5.77283L5.29671 5.77966L10.839 6.66224L12.0738 5.42742C12.3862 5.115 12.3862 4.60847 12.0738 4.29605L9.9927 2.21495Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M14.5179 9.48875C14.5179 9.99175 14.1101 10.3995 13.607 10.3995C13.1041 10.3995 12.6963 9.99175 12.6963 9.48875C12.6963 9.1773 13.0455 8.59966 13.3114 8.20487C13.4549 7.99177 13.7591 7.99177 13.9027 8.20486C14.1687 8.59965 14.5179 9.1773 14.5179 9.48875Z"}},{tag:"path",attrs:{fill:"colorChannel1",d:"M1.98682 13.4992C1.98682 12.5603 2.74793 11.7992 3.68682 11.7992H14.2868C15.2257 11.7992 15.9868 12.5603 15.9868 13.4992V13.4992C15.9868 14.4381 15.2257 15.1992 14.2868 15.1992H3.68682C2.74793 15.1992 1.98682 14.4381 1.98682 13.4992V13.4992Z"}}]},Ba=x.forwardRef(function(o,e){return x.createElement(pe,Object.assign({},o,{id:"paint-bucket-double-icon",ref:e,icon:Bh}))});Ba.displayName="PaintBucketDoubleIcon";const Fh={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M7.74692 9.12463C7.74692 9.46018 8.01893 9.73219 8.35448 9.73219H11.4933C11.8288 9.73219 12.1009 9.46018 12.1009 9.12463C12.1009 8.78909 11.8288 8.51707 11.4933 8.51707H8.35448C8.01893 8.51707 7.74692 8.78909 7.74692 9.12463Z"}},{tag:"path",attrs:{fill:"colorChannel1",d:"M10.8636 10.8523C10.8636 11.1879 10.5915 11.4599 10.256 11.4599H8.35448C8.01893 11.4599 7.74692 11.1879 7.74692 10.8523C7.74692 10.5168 8.01893 10.2447 8.35448 10.2447H10.256C10.5915 10.2447 10.8636 10.5168 10.8636 10.8523Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M5.4791 1.98268C5.47913 1.71529 5.87912 1.49854 6.37252 1.49854C6.86593 1.49854 7.26592 1.71529 7.26595 1.98268H7.62187C8.22277 1.98268 8.72459 2.39534 8.84412 2.9452H9.39563C10.0856 2.9452 10.6449 3.48923 10.6449 4.16032V6.00569H12.1261C13.161 6.00569 14 6.82174 14 7.82838V11.334C14 11.8174 13.8025 12.281 13.4511 12.6228L12.0693 13.9647C11.7179 14.3065 11.2412 14.4985 10.7442 14.4985H7.91116C7.05024 14.4985 6.32492 14.0431 6.10535 13.2737H3.34925C2.6593 13.2737 2.09998 12.7297 2.09998 12.0586V4.16032C2.09998 3.48923 2.6593 2.9452 3.34925 2.9452H3.90107C4.0206 2.39534 4.52241 1.98268 5.12332 1.98268H5.4791ZM3.97249 4.16032H3.24925L3.24925 12.0586H6.03725V7.82838C6.03725 6.82174 6.87623 6.00569 7.91116 6.00569H9.49563V4.16032H8.7727C8.58289 4.59611 8.13909 4.90183 7.62187 4.90183H5.12332C4.6061 4.90183 4.1623 4.59611 3.97249 4.16032ZM5.12332 2.89403H7.62187C7.79436 2.89403 7.93419 3.03003 7.93419 3.19781V3.68671C7.93419 3.85448 7.79436 3.99049 7.62187 3.99049H5.12332C4.95083 3.99049 4.811 3.85448 4.811 3.68671V3.19781C4.811 3.03003 4.95083 2.89403 5.12332 2.89403ZM7.91116 7.11157C7.56618 7.11157 7.28652 7.38359 7.28652 7.71913V12.7851C7.28652 13.1206 7.56618 13.3927 7.91116 13.3927H10.7442C10.8401 13.3927 10.9337 13.3712 11.0182 13.3311C11.1373 13.2746 11.1859 13.1423 11.1859 13.0134V12.0066C11.1859 11.8724 11.2978 11.7636 11.4358 11.7636H12.4709C12.6034 11.7636 12.7394 11.7163 12.7975 11.6004C12.8388 11.5182 12.8608 11.4272 12.8608 11.334V7.71913C12.8608 7.38359 12.5811 7.11157 12.2362 7.11157H7.91116Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Fa=x.forwardRef(function(o,e){return x.createElement(pe,Object.assign({},o,{id:"paste-special-double-icon",ref:e,icon:Fh}))});Fa.displayName="PasteSpecialDoubleIcon";const zh=()=>{const[,n]=x.useState({});return x.useCallback(()=>n(o=>!o),[])};function Xh(){const n=I.useDependency(a.ICommandService),o=I.useDependency(a.IUniverInstanceService),e=I.useDependency(M.IRenderManagerService),t=I.useDependency(ct),i=I.useDependency(a.LocaleService),[r,s]=x.useState([]),[l,c]=x.useState(!1),[d,u]=x.useState({row:-1,col:-1}),[h,g]=x.useState(le.SERIES),[S,f]=x.useState(!1),v=mt(),{sheetSkeletonManagerService:p,selectionRenderService:C}=x.useMemo(()=>{if(v){const j=e.getRenderById(v.getUnitId());return{sheetSkeletonManagerService:j==null?void 0:j.with(T.SheetSkeletonManagerService),selectionRenderService:j==null?void 0:j.with(Ie)}}return{sheetSkeletonManagerService:null,selectionRenderService:null}},[v,e]),_=()=>{f(!0)},w=()=>{f(!1)},E=zh();if(x.useEffect(()=>n.onCommandExecuted((Q,oe)=>{Q.id===$e.id&&E()}).dispose,[E,n]),x.useEffect(()=>{const j=p&&a.toDisposable(p.currentSkeleton$.subscribe(Q=>{Q&&E()}));return j==null?void 0:j.dispose},[p,E]),x.useEffect(()=>a.toDisposable(t.menu$.subscribe(Q=>{s(Q.map(oe=>({...oe,index:Q.indexOf(oe)})))})).dispose,[t]),x.useEffect(()=>a.toDisposable(t.showMenu$.subscribe(Q=>{const{source:oe,target:re}=t.autoFillLocation||{source:null,target:null};if(Q&&oe&&re){const ce=Math.max(oe.rows[oe.rows.length-1],re.rows[re.rows.length-1]),G=Math.max(oe.cols[oe.cols.length-1],re.cols[re.cols.length-1]);u({row:ce,col:G})}else u({row:-1,col:-1})})).dispose,[t]),x.useEffect(()=>a.toDisposable(t.applyType$.subscribe(Q=>{g(Q)})).dispose,[t]),x.useEffect(()=>{function j(){c(!1)}return document.addEventListener("wheel",j),()=>{document.removeEventListener("wheel",j)}},[l]),d.col<0||d.row<0)return null;const O=Ve(o,e);if(!O||!C)return null;const{scene:R}=O,P=p==null?void 0:p.getCurrentSkeleton(),A=C.getViewPort(),k=R==null?void 0:R.scaleX,N=R==null?void 0:R.scaleY,V=R==null?void 0:R.getViewportScrollXY(A);if(!k||!R||!k||!N||!V)return null;const L=(P==null?void 0:P.getNoMergeCellWithCoordByIndex(d.row,d.col).endX)||0,H=(P==null?void 0:P.getNoMergeCellWithCoordByIndex(d.row,d.col).endY)||0,W=M.convertTransformToOffsetX(L,k,V),B=M.convertTransformToOffsetY(H,N,V);if(W==null||B==null)return null;const U=j=>{c(j)},X=j=>{n.executeCommand(li.id,{type:j.value}),c(!1)},F=l||S,Y=r.filter(j=>!j.disable);return b.jsx("div",{className:"univer-absolute univer-inset-0 univer-z-10 univer-size-0",children:b.jsx("div",{className:"univer-absolute",style:{left:`${W+2}px`,top:`${B+2}px`},onMouseEnter:_,onMouseLeave:w,children:b.jsx(z.DropdownMenu,{align:"start",items:Y.map(j=>({type:"radio",value:h,options:[{label:i.t(j.label),value:j.value}],onSelect:()=>X(j)})),open:l,onOpenChange:U,children:b.jsxs("div",{className:z.clsx("univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-800",z.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-800":l,"univer-bg-white dark:!univer-bg-gray-900":!l}),children:[b.jsx(Ua,{className:"univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-white"}),F&&b.jsx(wn,{className:"dark:!univer-text-white"})]})})})})}function Mr(n,o){const e=I.useDependency(me),t=I.useDependency(a.ICommandService);return x.useMemo(()=>({keyCodes:[{keyCode:I.KeyCode.ENTER},{keyCode:I.KeyCode.ESC},{keyCode:I.KeyCode.TAB}],handler:r=>{(r===I.KeyCode.ENTER||r===I.KeyCode.ESC||r===I.KeyCode.TAB)&&(e.disableForceKeepVisible(),t.syncExecuteCommand(Se.id,{visible:!1,eventType:M.DeviceInputEventType.Keyboard,keycode:r,unitId:o}))}}),[t,e,o])}const uo=-1e3,za={width:0,height:0,top:uo,left:uo},Yh=()=>{const[n,o]=x.useState({...za}),e=I.useDependency(bn),t=I.useDependency(K.IEditorService),i=I.useDependency(a.IContextService),r=I.useDependency(I.ComponentManager),s=I.useDependency(me),l=I.useObservable(s.visible$),c=I.useDependency(a.ICommandService),d=x.useRef(0),u=I.useObservable(()=>i.subscribeContextValue$(I.DISABLE_AUTO_FOCUS_KEY),!1,void 0,[i,I.DISABLE_AUTO_FOCUS_KEY]),h=r.get(Li),g=s.getEditLocation();x.useEffect(()=>{const p=e.state$.subscribe(C=>{if(C==null)return;const{startX:_=uo,startY:w=uo,endX:E=0,endY:O=0,show:R=!1}=C;if(!R)o({...za});else{o({width:E-_,height:O-w,left:_,top:w});const P=t.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(P==null)return;const{left:A,top:k,width:N,height:V}=P.getBoundingClientRect();e.setRect({left:A,top:k,width:N,height:V})}});return()=>{p.unsubscribe()}},[]),x.useEffect(()=>{u||e.setFocus(!0)},[u,n]);const S=I.useEvent(()=>{s.isVisible().visible&&c.executeCommand(Se.id,{visible:!1,eventType:M.DeviceInputEventType.PointerUp,unitId:g==null?void 0:g.unitId})});I.useSidebarClick(S);const f=Mr(d,g==null?void 0:g.unitId),v=I.useEvent((p,C)=>{c.executeCommand(Lt.id,{keycode:p,visible:!1,eventType:M.DeviceInputEventType.Keyboard,isShift:C===I.MetaKeys.SHIFT||C===(I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT),unitId:g==null?void 0:g.unitId})});return b.jsx("div",{className:"univer-absolute univer-z-10 univer-flex",style:{left:n.left,top:n.top,width:n.width,height:n.height},children:h&&b.jsx(h,{editorId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,className:"univer-relative univer-flex univer-h-full univer-w-full [&_canvas]:univer-absolute",initValue:"",onChange:()=>{},isFocus:l==null?void 0:l.visible,unitId:g==null?void 0:g.unitId,subUnitId:g==null?void 0:g.sheetId,keyboardEventConfig:f,onMoveInEditor:v,isSupportAcrossSheet:!0,resetSelectionOnBlur:!1,isSingle:!1,autoScrollbar:!1,onFormulaSelectingChange:(p,C)=>{d.current=p,C&&(p?s.enableForceKeepVisible():s.disableForceKeepVisible())},disableSelectionOnClick:!0,disableContextMenu:!1})})};class Xa{constructor(){y(this,"_position",null);y(this,"_position$",new D.BehaviorSubject(null));y(this,"position$",this._position$.asObservable());y(this,"_focus",!1);y(this,"_focus$",new D.BehaviorSubject(this._focus));y(this,"focus$",this._focus$.asObservable());y(this,"_fxBtnClick$",new D.Subject);y(this,"fxBtnClick$",this._fxBtnClick$.asObservable());y(this,"_foldBtnStatus$",new D.Subject);y(this,"foldBtnStatus$",this._foldBtnStatus$.asObservable())}dispose(){this._position$.complete(),this._focus$.complete(),this._position=null,this._focus=!1}setPosition(o){this._position=o,this._refresh(o)}getPosition(){return this._position}setFocus(o=!1){this._focus=o,this._focus$.next(o)}handleFxBtnClick(o){this._fxBtnClick$.next(o)}handleFoldBtnClick(o){this._foldBtnStatus$.next(o)}_refresh(o){this._position$.next(o)}}const En=a.createIdentifier("univer.sheet-formula-editor-manager.service");function jh(){const n=I.useDependency(a.ICommandService),o=I.useDependency(a.LocaleService),e=I.useDependency(q.IDefinedNamesService),t=I.useDependency(a.IUniverInstanceService),i=I.useDependency(I.ISidebarService),s=t.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId(),l=()=>{const g=e.getDefinedNameMap(s);return g?Array.from(Object.values(g)):[]},[c,d]=x.useState(l());x.useEffect(()=>{const g=e.update$.subscribe(()=>{d(l())});return()=>{g.unsubscribe()}},[]),x.useEffect(()=>{const g=i.sidebarOptions$.subscribe(S=>{S.id===bi&&(S.visible||setTimeout(()=>{i.sidebarOptions$.next({visible:!1})}))});return()=>{g.unsubscribe()}},[]);const u=()=>{n.executeCommand(so.id,{value:"open"})},h=async g=>{const{formulaOrRefString:S,id:f}=g,v=e.getWorksheetByRef(s,S);if(!v)return;v.isSheetHidden()&&await n.executeCommand(m.SetWorksheetShowCommand.id,{unitId:s,subUnitId:v.getSheetId()}),e.focusRange(s,f)};return b.jsxs("div",{className:"univer-w-[300px]",children:[b.jsx("ul",{className:z.clsx("univer-m-0 univer-max-h-[360px] univer-list-none univer-overflow-y-auto univer-p-0",z.scrollbarClassName),children:c.map((g,S)=>b.jsx("li",{className:"univer-cursor-pointer univer-px-2 univer-transition-colors univer-duration-200 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-600",onClick:()=>{h(g)},children:b.jsxs("div",{className:z.clsx("univer-flex univer-items-center univer-justify-between univer-gap-2 univer-py-1",z.borderBottomClassName),children:[b.jsx("div",{className:"univer-w-[50%] univer-flex-shrink-0 univer-truncate univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",title:g.name,children:g.name}),b.jsx("div",{className:"univer-w-[50%] univer-flex-shrink-0 univer-truncate univer-text-xs univer-text-gray-400",title:g.formulaOrRefString,children:g.formulaOrRefString})]})},S))}),b.jsxs("div",{className:"univer-cursor-pointer univer-p-2 univer-transition-colors univer-duration-200 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-600",onClick:u,children:[b.jsx("div",{className:"univer-mb-2 univer-text-sm univer-font-semibold univer-text-gray-600 dark:!univer-text-gray-200",children:o.t("definedName.managerTitle")}),b.jsx("div",{className:"univer-text-xs univer-text-gray-400",children:o.t("definedName.managerDescription")})]})]})}function Zh({disable:n}){const[o,e]=x.useState(""),t=I.useDependency(q.IDefinedNamesService);x.useEffect(()=>{const r=t.currentRange$.subscribe(()=>{e(t.getCurrentRangeForString())});return()=>{r.unsubscribe()}},[]);function i(){}return b.jsxs("div",{"data-u-comp":"defined-name",className:"univer-relative univer-box-border univer-flex univer-h-full univer-w-24 univer-border-r-gray-200 univer-py-1.5 univer-transition-all",children:[b.jsx("input",{className:z.clsx("univer-box-border univer-h-full univer-w-full univer-appearance-none univer-px-1.5 univer-text-gray-900 focus:univer-outline-none dark:!univer-border-r-gray-700 dark:!univer-bg-gray-900 dark:!univer-text-white",z.borderRightClassName,{"univer-cursor-not-allowed":n}),type:"text",value:o,onChange:i}),b.jsx(z.Dropdown,{overlay:b.jsx("div",{className:"univer-z-[1001]",children:b.jsx(jh,{})}),disabled:n,children:b.jsx("a",{className:z.clsx("univer-absolute univer-right-0 univer-top-0 univer-flex univer-h-full univer-cursor-pointer univer-items-center univer-justify-center univer-px-1 univer-transition-colors univer-duration-200 hover:univer-bg-gray-100 dark:!univer-text-white dark:hover:!univer-bg-gray-800",{"univer-cursor-not-allowed univer-text-gray-300 hover:univer-bg-transparent dark:!univer-text-gray-700":n}),children:b.jsx(wn,{})})})]})}function Ya(n){var J,ne,ue,ie;const{className:o,disableDefinedName:e}=n,[t,i]=x.useState(!1),[r,s]=x.useState(0),l=I.useDependency(En),c=I.useDependency(me),d=I.useDependency(m.WorksheetProtectionRuleModel),u=I.useDependency(m.RangeProtectionRuleModel),h=I.useDependency(a.IUniverInstanceService),g=I.useDependency(m.SheetsSelectionsService),S=I.useDependency(a.IPermissionService),f=I.useDependency(m.RangeProtectionCache),v=I.useDependency(a.ICommandService),[p,C]=x.useState({editDisable:!1,viewDisable:!1}),[_,w]=x.useState(!1),E=I.useDependency(I.ComponentManager),O=I.useObservable(()=>h.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),R=x.useRef(0),P=I.useObservable(c.currentEditCellState$),A=Mr(R,(J=P==null?void 0:P.unitId)!=null?J:""),k=E.get(Li),N=I.useComponentsOfPart(vr.FORMULA_AUX),V=I.useDependency(a.IContextService);I.useObservable(x.useMemo(()=>V.subscribeContextValue$(a.FOCUSING_FX_BAR_EDITOR),[V]));const L=V.getContextValue(a.FOCUSING_FX_BAR_EDITOR),H=x.useRef(null),W=I.useDependency(K.IEditorService);x.useLayoutEffect(()=>{const se=O.activeSheet$.pipe(D.switchMap(te=>te?D.merge(d.ruleChange$,u.ruleChange$,g.selectionMoveEnd$,g.selectionSet$).pipe(D.switchMap(()=>{var Ct,It;const fe=O.getUnitId(),ve=te.getSheetId();if(!((Ct=g.getCurrentLastSelection())==null?void 0:Ct.range))return D.EMPTY;const Ee=(It=g.getCurrentLastSelection())==null?void 0:It.primary;return Ee?D.of({unitId:fe,subUnitId:ve,primary:Ee}):D.of(null)})):D.EMPTY)).subscribe(te=>{var fe,ve,we,Ee,Ct,It;if(te){const{unitId:Kt,subUnitId:Fo,primary:vp}=te;if(d.getRule(Kt,Fo)){const Ip=!((ve=(fe=S.getPermissionPoint(new m.WorksheetEditPermission(Kt,Fo).id))==null?void 0:fe.value)==null||ve),_p=!((Ee=(we=S.getPermissionPoint(new m.WorksheetViewPermission(Kt,Fo).id))==null?void 0:we.value)==null||Ee);C({viewDisable:_p,editDisable:Ip});return}const{actualRow:pp,actualColumn:Cp}=vp,zn=f.getCellInfo(Kt,Fo,pp,Cp);C({editDisable:!((Ct=zn==null?void 0:zn[m.UnitAction.Edit])==null||Ct),viewDisable:!((It=zn==null?void 0:zn[m.UnitAction.View])==null||It)})}else C({viewDisable:!1,editDisable:!1})});return()=>{se.unsubscribe()}},[O]),x.useEffect(()=>{const se=c.visible$.subscribe(te=>{i(te.visible)});return()=>se.unsubscribe()},[c.visible$]),x.useEffect(()=>{const se=c.currentEditCellState$.subscribe(te=>{var fe,ve,we;(we=(ve=(fe=te==null?void 0:te.documentLayoutObject.documentModel)==null?void 0:fe.getBody())==null?void 0:ve.customBlocks)!=null&&we.length?w(!0):w(!1)});return()=>se.unsubscribe()},[c.currentEditCellState$]),x.useEffect(()=>{const se=()=>{if(!H.current)return;const te=H.current.getBoundingClientRect();l.setPosition(te)};if(H.current){se();const te=new ResizeObserver(se);return te.observe(H.current),()=>te.disconnect()}},[l]);function B(){s(r===0?1:0),setTimeout(()=>{l.handleFoldBtnClick(r===1)},150)}function U(){c.isVisible().visible&&v.executeCommand(Se.id,{visible:!1,eventType:M.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ESC,unitId:P.unitId})}function X(){c.isVisible().visible&&v.executeCommand(Se.id,{visible:!1,eventType:M.DeviceInputEventType.PointerDown,unitId:P.unitId})}function F(){l.handleFxBtnClick(!0)}const{viewDisable:Y,editDisable:j}=p,Q=j||_,oe=x.useRef(!1),re=()=>{try{if(c.isVisible().visible===!1&&!v.syncExecuteCommand(Se.id,{visible:!0,eventType:M.DeviceInputEventType.PointerDown,unitId:P.unitId})){oe.current=!0;return}V.setContextValue(a.FOCUSING_FX_BAR_EDITOR,!0)}catch(se){throw oe.current=!0,se}},ce=()=>{oe.current&&setTimeout(()=>{W.blur(!0)},30),oe.current=!1},Z=((ie=(ue=(ne=P==null?void 0:P.documentLayoutObject.documentModel)==null?void 0:ne.getDrawingsOrder())==null?void 0:ue.length)!=null?ie:0)>0||Y;return b.jsxs("div",{"data-u-comp":"formula-bar",className:z.clsx("univer-box-border univer-flex univer-bg-white univer-transition-[height] univer-ease-linear dark:!univer-bg-gray-900",z.borderBottomClassName,o,{"univer-h-7":r===0,"univer-h-20":r===1,"univer-pointer-events-none":j}),children:[b.jsx("div",{className:"univer-relative univer-box-border univer-h-full univer-w-[100px]",children:b.jsx(Zh,{disable:e!=null?e:j})}),b.jsxs("div",{className:"univer-flex univer-h-full univer-w-full",children:[b.jsx("div",{className:z.clsx("univer-py-1.5",{"univer-cursor-not-allowed univer-text-gray-200":Q}),children:b.jsxs("div",{className:z.clsx("univer-relative univer-box-border univer-flex univer-h-full univer-w-20 univer-items-center univer-justify-center univer-text-xs",z.borderRightClassName),children:[b.jsx("span",{className:z.clsx("univer-flex univer-items-center univer-justify-center univer-rounded univer-p-1 univer-text-base dark:!univer-text-white",{"univer-cursor-pointer univer-text-red-600 hover:univer-bg-gray-100 dark:!univer-text-green-400 dark:hover:!univer-bg-gray-700":t}),onClick:U,children:b.jsx(Aa,{})}),b.jsx("span",{className:z.clsx("univer-flex univer-items-center univer-justify-center univer-rounded univer-p-1 univer-text-base dark:!univer-text-white",{"univer-cursor-pointer univer-text-green-600 hover:univer-bg-gray-100 dark:!univer-text-red-400 dark:hover:!univer-bg-gray-700":t}),onClick:X,children:b.jsx(Ut,{})}),b.jsx("span",{className:"univer-flex univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-p-1 univer-text-base hover:univer-bg-gray-100 dark:!univer-text-white dark:hover:!univer-bg-gray-700",onClick:F,children:b.jsx(Va,{})})]})}),b.jsxs("div",{className:"univer-flex univer-w-full univer-flex-1 univer-overflow-hidden univer-pl-3",children:[b.jsxs("div",{ref:H,className:"univer-relative univer-flex-1",onPointerDown:re,onPointerUp:ce,style:{pointerEvents:Z?"none":"auto"},children:[k&&b.jsx(k,{className:"univer-relative univer-h-full univer-w-full univer-break-words univer-outline-none [&>div]:univer-ring-transparent",disableSelectionOnClick:!0,editorId:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,initValue:"",onChange:()=>{},isFocus:L,unitId:P==null?void 0:P.unitId,subUnitId:P==null?void 0:P.sheetId,isSupportAcrossSheet:!0,resetSelectionOnBlur:!1,isSingle:!1,keyboardEventConfig:A,onFormulaSelectingChange:(se,te)=>{R.current=se,te&&(se?c.enableForceKeepVisible():c.disableForceKeepVisible())},autoScrollbar:!1,disableContextMenu:!1}),Z&&b.jsx("div",{className:"univer-pointer-events-none univer-relative univer-left-0 univer-top-0 univer-z-[100] univer-h-full univer-w-full univer-cursor-not-allowed univer-bg-white"})]}),b.jsx("div",{className:z.clsx("univer-flex univer-h-full univer-w-5 univer-cursor-pointer univer-items-center univer-justify-center univer-text-xs univer-text-gray-700 dark:!univer-text-gray-200",{"univer-cursor-not-allowed univer-text-gray-200 dark:!univer-text-gray-700":j}),onClick:B,children:b.jsx(ka,{className:z.clsx({"univer-rotate-180":r===1})})})]})]}),b.jsx(I.ComponentContainer,{components:N},"formula-aux")]})}function ho(n){const{children:o,className:e,style:t,disabled:i=!1,onClick:r,...s}=n,l=c=>{if(i){c.preventDefault();return}r&&r(c)};return b.jsx(z.Button,{"data-u-comp":"sheet-bar-append-button",className:e,size:"small",disabled:i,style:t,variant:"text",onClick:l,...s,children:o})}function Gh(){const[n,o]=x.useState([]),[e,t]=x.useState(!1),i=I.useDependency(a.IUniverInstanceService),r=I.useDependency(a.ICommandService),s=I.useDependency(Wt),l=I.useDependency(m.WorksheetProtectionRuleModel),c=I.useObservable(()=>i.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),null,!1,[]),d=v=>{const{sheetId:p}=v;!p||!c||(v.hidden?r.executeCommand(m.SetWorksheetShowCommand.id,{unitId:c.getUnitId(),subUnitId:p,value:p}):v.selected||r.executeCommand(m.SetWorksheetActivateCommand.id,{unitId:c.getUnitId(),subUnitId:p}),t(!1))},u=x.useCallback(()=>{if(!c)return;const v=c.getSheets(),p=c.getActiveSheet(),C=v.map((_,w)=>({label:_.getName(),index:`${w}`,sheetId:_.getSheetId(),hidden:_.isSheetHidden()===a.BooleanNumber.TRUE,selected:p===_}));o(C)},[c,l]),h=x.useCallback(()=>r.onCommandExecuted(v=>{switch(v.id){case m.SetWorksheetHideMutation.id:case m.RemoveSheetMutation.id:case m.SetWorksheetNameMutation.id:case m.InsertSheetMutation.id:case m.SetWorksheetOrderMutation.id:case m.SetWorksheetActiveOperation.id:u();break}}),[r,u]);function g(){t(!0)}const S=v=>{t(v)};x.useEffect(()=>{u();const v=new a.DisposableCollection;return v.add(h()),v.add(s.registerSheetBarMenuHandler({handleSheetBarMenu:g})),()=>v.dispose()},[h,s,u,c]);const f=x.useMemo(()=>n.map(v=>({type:"item",children:b.jsxs("div",{className:"univer-relative univer-box-border univer-pl-6",children:[(v.selected||v.hidden)&&b.jsxs("span",{className:"univer-absolute univer-left-1 univer-top-0.5",children:[v.selected&&b.jsx(Ut,{className:"univer-size-4 univer-text-primary-600"}),v.hidden&&b.jsx(Na,{className:"univer-size-4 univer-text-gray-400"})]}),b.jsx("span",{className:z.clsx({"univer-text-primary-600":v.selected}),children:v.label})]}),onSelect:()=>{d(v)}})),[n]);return b.jsx(z.DropdownMenu,{align:"start",items:f,open:e,onOpenChange:S,children:b.jsx("div",{children:b.jsx(ho,{children:b.jsx(Da,{})})})})}function Kh(n){const{sheetId:o,label:e,color:t,selected:i,menuOverlay:r}=n,[s,l]=x.useState(i),c=I.useDependency(a.ThemeService);x.useEffect(()=>{l(i)},[i]);const d=u=>{const h=c.getColorFromTheme("gray.900"),g=c.getColorFromTheme("white");return new a.ColorKit(u).isDark()?g:h};return b.jsx("div",{"data-u-comp":"slide-tab-item","data-id":o,className:z.clsx("univer-mx-1 univer-box-border univer-flex univer-flex-grow univer-cursor-pointer univer-select-none univer-flex-row univer-items-center univer-rounded univer-text-xs univer-transition-[colors,box-shadow]",{"dark:!univer-text-white":!t||t&&!d(t),"univer-justify-center univer-bg-white univer-font-bold univer-text-primary-700 univer-shadow":s,"dark:!univer-bg-gray-900":s&&!t,"univer-font-medium univer-text-gray-900 hover:univer-bg-gray-100":!s,"dark:hover:!univer-bg-gray-700":!s&&!t}),style:{backgroundColor:!s&&t?t:"",color:!s&&t?d(t):"",boxShadow:s&&t?`0px 0px 8px rgba(0, 0, 0, 0.08), inset 0px -2px 0px 0px ${t}`:""},children:b.jsx("div",{className:"univer-box-border univer-flex univer-items-center univer-gap-1 univer-whitespace-nowrap univer-rounded univer-border-2 univer-border-solid univer-border-transparent univer-px-1.5 univer-py-1",children:e})},o)}const qh={easeOutStrong(n,o,e,t){return-e*((n=n/t-1)*n*n*n-1)+o},backOut(n,o,e,t,i){return typeof i>"u"&&(i=.7),e*((n=n/t-1)*n*((i+1)*n+i)+1)+o}},Qh={loop:!1,begin:0,end:0,duration:300,delay:0,type:"easeOutStrong",receive(n){},success(n){},cancel(n){},complete(n){}};class Jh{constructor(o){y(this,"_config");y(this,"_status",0);y(this,"_start",0);y(this,"_handle",0);y(this,"_delayHandle",null);this._config={...Qh,...o},this._config.loop&&(this._config.complete=()=>{},this._config.success=()=>{this.request()})}static success(...o){let e=0;return new Promise(t=>{for(let i=0;i<o.length;i++){const r=o[i],s=r._config,l=s.success;s.loop||(s.success=d=>{e++,l&&l.call(r,d),e===o.length&&t()})}})}request(){this._config.delay===0?(this._status=0,this._start=Date.now(),this._fakeHandle()):(this._delayHandle&&clearTimeout(this._delayHandle),this._delayHandle=setTimeout(()=>{this._status=0,this._start=Date.now(),this._fakeHandle()},this._config.delay))}cancel(){this._status=1,this._delayHandle&&clearTimeout(this._delayHandle),cancelAnimationFrame(this._handle)}_fakeHandle(){let o=Date.now()-this._start;o=o>=this._config.duration?this._config.duration:o;const t=qh[this._config.type](o,this._config.begin,this._config.end-this._config.begin,this._config.duration,.7).toFixed(2);if(this._config.receive(t),this._status===1){this._config.cancel(t),this._config.complete(t);return}if(o===this._config.duration){this._config.success(t),this._config.complete(t);return}this._handle=requestAnimationFrame(()=>{this._fakeHandle()})}}class Bt{constructor(o,e){y(this,"_slideTabItem");y(this,"_animate");y(this,"_midline",0);y(this,"_translateX");y(this,"_scrollbar");y(this,"_slideTabBar");y(this,"_editMode");y(this,"_placeholder");this._slideTabItem=o,this._animate=null,this._translateX=0,this._editMode=!1,this._slideTabBar=e,this._placeholder=null,this._scrollbar=e.getScrollbar(),this.update()}static midline(o){return o.getBoundingRect().x+o.getBoundingRect().width/2}static leftLine(o){return o.getBoundingRect().x}static rightLine(o){return o.getBoundingRect().x+o.getBoundingRect().width}static make(o,e){const t=[];return o.forEach(i=>t.push(new Bt(i,e))),t}getSlideTabItem(){return this._slideTabItem}getEditor(){return this._slideTabItem.querySelector("span")}focus(){var o;(o=this.getEditor())==null||o.focus()}selectAll(){const o=this.getEditor();o&&Tn.keepSelectAll(o)}isEditMode(){return this._editMode}classList(){return this._slideTabItem.classList}translateX(o){return this._translateX=o,this._slideTabItem.style.transform=`translateX(${o}px)`,this.getTranslateXDirection()}setEditor(o){if(!this._slideTabBar.getConfig().onNameChangeCheck())return;let e=!0;if(this._editMode===!1){const t=this._slideTabItem.querySelector("span"),i=d=>{if(!this.nameCheck()){if(this._editMode=!1,t&&(t.removeAttribute("contentEditable"),t.removeEventListener("focusout",i),t.removeEventListener("compositionstart",s),t.removeEventListener("compositionend",l),t.removeEventListener("input",c),t.removeEventListener("keydown",r)),this._slideTabBar.removeListener(),this._slideTabBar.updateItems(),this._slideTabBar.getConfig().onChangeName){const u=(t==null?void 0:t.innerText)||"",h=this.getId();this._slideTabBar.getConfig().onChangeName(h,u)}o&&o(d)}};let r=d=>{t&&(d.stopPropagation(),d.key==="Enter"&&t.blur())};const s=d=>{e=!1},l=d=>{e=!0},c=d=>{if(!t)return;const u=31;setTimeout(()=>{if(e){const h=t.innerText;h.length>u&&(t.innerText=h.substring(0,u),Tn.keepLastIndex(t))}},0)};t&&(t.setAttribute("contentEditable","true"),t.addEventListener("focusout",i),t.addEventListener("compositionstart",s),t.addEventListener("compositionend",l),t.addEventListener("input",c),t.addEventListener("keydown",r),this._editMode=!0,Tn.keepSelectAll(t))}}nameCheck(){const o=this._slideTabItem.querySelector("span");if(!o)return!1;const e=o.innerText;return this._slideTabBar.getConfig().onNameCheckAlert(e)}animate(){return{translateX:o=>{this._translateX!==o&&(this._animate&&(this._animate.cancel(),this._animate=null),this._animate=new Jh({begin:this._translateX,end:o,receive:e=>{this._slideTabItem.style.transform=`translateX(${e}px)`}}),this._translateX=o,this._animate.request())},cancel:()=>{this._animate&&(this._animate.cancel(),this._animate=null)}}}after(o){this._slideTabItem.after(o._slideTabItem||o)}update(){this._midline=Bt.midline(this)}disableFixed(){if(this._placeholder){const o=this._slideTabBar.primeval();this._slideTabItem.style.removeProperty("position"),this._slideTabItem.style.removeProperty("left"),this._slideTabItem.style.removeProperty("top"),this._slideTabItem.style.removeProperty("width"),this._slideTabItem.style.removeProperty("height"),this._slideTabItem.style.removeProperty("background"),this._slideTabItem.style.removeProperty("padding"),this._slideTabItem.style.removeProperty("box-sizing"),this._slideTabItem.style.removeProperty("font-size"),this._slideTabItem.style.removeProperty("font-family"),this._slideTabItem.style.removeProperty("font-weight"),this._slideTabItem.style.removeProperty("color"),this._slideTabItem.style.removeProperty("border-radius"),this._placeholder.after(this._slideTabItem),o.removeChild(this._placeholder),this._placeholder=null}}enableFixed(){const o=document.createElement("div"),e=this.getBoundingRect(),t=getComputedStyle(this._slideTabItem),i=this._slideTabItem.querySelector("span");if(this._placeholder=o,this._placeholder.style.width=`${e.width}px`,this._placeholder.style.height=`${e.height}px`,this._placeholder.style.flexShrink="0",this._placeholder.style.margin=t.margin,this._slideTabItem.style.background=t.background,i){const r=getComputedStyle(i).padding;this._slideTabItem.style.padding=r}this._slideTabItem.style.boxSizing=t.boxSizing,this._slideTabItem.style.fontSize=t.fontSize,this._slideTabItem.style.fontFamily=t.fontFamily,this._slideTabItem.style.fontWeight=t.fontWeight,this._slideTabItem.style.color=t.color,this._slideTabItem.style.borderRadius=t.borderRadius,this._slideTabItem.style.left=`${e.x-this.getScrollbar().getScrollX()}px`,this._slideTabItem.style.top=`${e.y}px`,this._slideTabItem.style.width=`${e.width}px`,this._slideTabItem.style.height=`${e.height}px`,this._slideTabItem.style.position="fixed",this._slideTabItem.after(o),document.body.appendChild(this._slideTabItem)}addEventListener(o,e,t){this._slideTabItem.addEventListener(o,e,t)}removeEventListener(o,e,t){this._slideTabItem.removeEventListener(o,e,t)}getScrollbar(){return this._scrollbar}getMidLine(){return this._midline}getBoundingRect(){const o=this._slideTabItem.getBoundingClientRect();return o.x+=this._scrollbar.getScrollX(),o}getWidth(){return this.getBoundingRect().width}getTranslateXDirection(){const o=Bt.midline(this);return o>this._midline?1:o<this._midline?-1:0}equals(o){return o&&o._slideTabItem===this._slideTabItem}getId(){return this._slideTabItem.dataset.id||""}}class $h{constructor(o){y(this,"_slideTabBar");y(this,"_scrollX");const e=o.primeval();this._scrollX=e.scrollLeft,this._slideTabBar=o}scrollX(o){const e=this._slideTabBar.primeval();e.scrollLeft=o,this._scrollX=e.scrollLeft}scrollRight(){const o=this._slideTabBar.primeval();o.scrollLeft=o.scrollWidth,this._scrollX=o.scrollLeft}getScrollX(){return this._scrollX}}const Fn=class Fn{constructor(o){y(this,"_activeTabItemIndex",0);y(this,"_slideTabBar");y(this,"_slideTabItems",[]);y(this,"_config");y(this,"_downActionX",0);y(this,"_moveActionX",0);y(this,"_compareIndex",0);y(this,"_activeTabItem",null);y(this,"_moveAction");y(this,"_upAction");y(this,"_downAction");y(this,"_wheelAction");y(this,"_scrollIncremental",0);y(this,"_compareDirection",0);y(this,"_autoScrollTime",null);y(this,"_slideScrollbar");y(this,"_longPressTimer",null);y(this,"_leftBoundingLine",0);y(this,"_rightBoundingLine",0);y(this,"_leftMoveX",0);y(this,"_rightMoveX",0);if(o.slideTabBarContainer==null)throw new Error("not found slide-tab-bar root element");const e=o.slideTabBarContainer.querySelector(`${o.slideTabBarSelector}`);if(e==null)throw new Error("not found slide-tab-bar");this._slideTabBar=e,this._slideScrollbar=new $h(this),this._config=o,this._initConfig();let t=0,i=0,r=0;this._downAction=s=>{var O,R,P,A,k,N;if((O=this._activeTabItem)!=null&&O.isEditMode())return;this._longPressTimer&&(clearTimeout(this._longPressTimer),this._longPressTimer=null);const l=(P=(R=s.target)==null?void 0:R.closest(`${o.slideTabBarItemSelector}`))==null?void 0:P.getAttribute("data-id"),c=this._slideTabItems.findIndex(V=>V.getId()===l);if(l==null||c===-1)return;if(this._activeTabItemIndex!==c){(A=this._activeTabItem)==null||A.removeEventListener("pointermove",this._moveAction),(k=this._activeTabItem)==null||k.removeEventListener("pointerup",this._upAction),this.removeListener(),this._config.onChangeTab(s,l);return}if(this._compareIndex=c,this._downActionX=s.pageX,this._moveActionX=0,this._scrollIncremental=0,this._activeTabItem=this._slideTabItems[c],!this._activeTabItem){console.error("Not found active slide-tab-item in sheet bar");return}const d=this._activeTabItem.getSlideTabItem();d==null||d.setPointerCapture(s.pointerId),(N=this._activeTabItem)==null||N.addEventListener("pointerup",this._upAction);const{x:u,width:h}=this._activeTabItem.getBoundingRect(),{x:g,width:S}=this.getBoundingRect(),f=this._slideScrollbar.getScrollX();if(this._leftBoundingLine=this._downActionX-(u-f),this._rightBoundingLine=u-f+h-this._downActionX,this._leftMoveX=u-g-f,this._rightMoveX=g+S-(u+h)+f,s.button===2||this._hasEditItem())return;const{pageX:v,pageY:p}=s,C=Date.now(),_=C-r<=Fn.DoubleClickDelay,w=Math.abs(v-t)<10,E=Math.abs(p-i)<10;_&&w&&E&&this._activeTabItem.setEditor(),t=v,i=p,r=C,this._longPressTimer=setTimeout(()=>{var V,L,H;!d||(V=this._activeTabItem)!=null&&V.isEditMode()||((L=this._activeTabItem)==null||L.enableFixed(),this._startAutoScroll(),d.setPointerCapture(s.pointerId),d.style.cursor="move",(H=this._activeTabItem)==null||H.addEventListener("pointermove",this._moveAction))},Fn.LongPressDelay)},this._upAction=s=>{var d,u,h,g;if((d=this._activeTabItem)!=null&&d.isEditMode()||(this._longPressTimer&&(clearTimeout(this._longPressTimer),this._longPressTimer=null),!this._activeTabItem))return;const l=this._autoScrollTime!==null;this._closeAutoScroll(),this._activeTabItem.disableFixed(),this.updateItems();const c=(u=this._activeTabItem)==null?void 0:u.getSlideTabItem();c&&(c.style.cursor="",c.releasePointerCapture(s.pointerId),(h=this._activeTabItem)==null||h.removeEventListener("pointermove",this._moveAction),(g=this._activeTabItem)==null||g.removeEventListener("pointerup",this._upAction),this._config.onSlideEnd&&this._activeTabItemIndex!==this._compareIndex&&l&&(this.removeListener(),this._config.onSlideEnd(s,this._compareIndex||0)),this._scrollIncremental=0,this._downActionX=0,this._moveActionX=0,this._compareIndex=0)},this._moveAction=s=>{this._activeTabItem&&(this._moveActionX=s.pageX-this._downActionX,this._moveActionX<=-this._leftMoveX?this._moveActionX=-this._leftMoveX:this._moveActionX>=this._rightMoveX&&(this._moveActionX=this._rightMoveX),this._scrollIncremental=0,this._scrollLeft(s),this._scrollRight(s))},this._wheelAction=s=>{this.setScroll(s.deltaY)},this.addListener()}static checkedSkipSlide(o){let e=o.target;for(;e!=null&&e!==document.body;){if(e.getAttribute("data-slide-skip"))return!0;e=e.parentElement}return!1}static keepLastIndex(o){setTimeout(()=>{const e=window.getSelection();e&&(e.selectAllChildren(o),e.collapseToEnd())})}static keepSelectAll(o){setTimeout(()=>{const e=window.getSelection();if(!e)return;const t=document.createRange();t.selectNodeContents(o),e.removeAllRanges(),e.addRange(t)})}update(o){this._config.currentIndex=o,this._initConfig(),this.removeListener(),this.addListener(),this.scrollToItem(o)}primeval(){return this._slideTabBar}updateItems(){for(let o=0;o<this._slideTabItems.length;o++)this._slideTabItems[o].animate().cancel(),this._slideTabItems[o].translateX(0),this._slideTabItems[o].update()}getScrollbar(){return this._slideScrollbar}getConfig(){return this._config}getBoundingRect(){return this._slideTabBar.getBoundingClientRect()}getSlideTabItems(){return this._slideTabItems}getActiveItem(){return this._activeTabItem}isLeftEnd(){return this._slideTabBar.scrollLeft===0}isRightEnd(){const o=this._slideTabBar.parentElement;return o?this._slideTabBar.scrollWidth-o.clientWidth===this._slideTabBar.scrollLeft:!1}addListener(){this._slideTabBar.addEventListener("wheel",this._wheelAction),this._slideTabItems.forEach(o=>{o.addEventListener("pointerdown",this._downAction)})}removeListener(){this._slideTabBar.removeEventListener("wheel",this._wheelAction),this._slideTabItems.forEach(o=>{o.removeEventListener("pointerdown",this._downAction)})}setScroll(o){if(this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+o),o>0){const e=this.calculateLeftScrollX();this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e)}else if(o<0){const e=this.calculateRightScrollX();this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e)}this._config.onScroll({leftEnd:this.isLeftEnd(),rightEnd:this.isRightEnd()})}flipPage(o){if(o>0){const e=this.calculateLeftScrollX(!0);this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e)}else if(o<0){const e=this.calculateRightScrollX(!0);this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e)}this._config.onScroll({leftEnd:this.isLeftEnd(),rightEnd:this.isRightEnd()})}scrollToItem(o){if(o=o!=null?o:this._config.currentIndex,o<0||o>=this._slideTabItems.length){console.error("Index out of bounds");return}const e=this.calculateTabItemScrollX(o);this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+e),this._config.onScroll({leftEnd:this.isLeftEnd(),rightEnd:this.isRightEnd()})}calculateLeftScrollX(o){let e=0;const t=4;return this._slideTabItems.some(i=>{const r=this._slideTabBar.getBoundingClientRect(),s=r.left+r.width,l=i.getSlideTabItem().getBoundingClientRect(),c=l.left,d=l.width;return c<s&&c+d+t*2>s?(e=o?c-r.left-t:c+d-s+t,!0):!1}),e}calculateRightScrollX(o){let e=0;const t=4;return this._slideTabItems.some(i=>{const r=this._slideTabBar.getBoundingClientRect(),s=r.left,l=i.getSlideTabItem().getBoundingClientRect(),c=l.left,d=l.width;return c-t*2<s&&c+d>s?(e=o?c+d-r.left-r.width+t:c-s-t,!0):!1}),e}calculateTabItemScrollX(o){let e=0;const t=4,i=this._slideTabBar.getBoundingClientRect(),r=i.left,s=i.left+i.width,l=this._slideTabItems[o].getSlideTabItem().getBoundingClientRect(),c=l.left,d=l.width;return c-t*2<r&&(e=c-r-t),c+d+t*2>s&&(e=c+d-s+t),e}calculateActiveTabItemScrollX(){var d;let o=0;const e=4,t=this._slideTabBar.getBoundingClientRect(),i=t.left,r=t.left+t.width,s=(d=this._activeTabItem)==null?void 0:d.getSlideTabItem().getBoundingClientRect();if(!s)return 0;const l=s.left,c=s.width;return l-e*2<i&&l+c>i&&(o=l-i-e),l<r&&l+c+e*2>r&&(o=l+c-r+e),o}destroy(){this.removeListener(),this._downActionX=0,this._moveActionX=0,this._compareDirection=0,this._compareIndex=0,this._slideTabItems=[],this._activeTabItem=null}_hasEditItem(){for(let o=0;o<this._slideTabItems.length;o++)if(this._slideTabItems[o].isEditMode())return!0;return!1}_autoScrollFrame(){if(this._activeTabItem)switch(this._compareDirection=this._activeTabItem.translateX(this._moveActionX),this._compareDirection){case 1:{this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+this._scrollIncremental),this._compareRight();break}case 0:{this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+this._scrollIncremental),this._compareIndex=this._activeTabItemIndex;break}case-1:{this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX()+this._scrollIncremental),this._compareLeft();break}}this._autoScrollTime=requestAnimationFrame(()=>{this._autoScrollFrame()})}_startAutoScroll(){this._autoScrollTime==null&&this._autoScrollFrame()}_closeAutoScroll(){this._autoScrollTime&&cancelAnimationFrame(this._autoScrollTime),this._autoScrollTime=null}_scrollLeft(o){const e=this.getBoundingRect(),t=o.pageX-e.x;t<this._leftBoundingLine&&(this._scrollIncremental=-Math.min(Math.abs(t-this._leftBoundingLine)*.1,50))}_scrollRight(o){const e=this.getBoundingRect(),t=o.pageX-e.x;t>e.width-this._rightBoundingLine&&(this._scrollIncremental=Math.min(Math.abs(t-(e.width-this._rightBoundingLine))*.1,50))}_sortedItems(){if(this._activeTabItem!=null&&this._activeTabItemIndex!=null&&this._compareIndex!=null&&(this._slideTabItems.splice(this._activeTabItemIndex,1),this._slideTabItems.splice(this._compareIndex,0,this._activeTabItem),this._config.slideTabBarItemAutoSort))for(let o=0;o<this._slideTabItems.length;o++){const e=this._slideTabItems[o],t=this._slideTabItems[o+1];t&&e.after(t)}}_compareLeft(){if(this._activeTabItem&&this._activeTabItemIndex){const o=this._slideTabItems.findIndex(r=>r.equals(this._activeTabItem)),e=this._slideTabItems.length,t=[];for(let r=0;r<o&&!(r>=o);r++)t.push(this._slideTabItems[r]);for(let r=o+1;r<e;r++)this._slideTabItems[r].animate().translateX(0);let i=!0;for(let r=t.length-1;r>=0;r--){const s=t[r];Bt.leftLine(this._activeTabItem)<s.getMidLine()?(s.animate().translateX(this._activeTabItem.getWidth()),this._compareIndex=r,i=!1):(s.animate().translateX(0),i&&(this._compareIndex=this._activeTabItemIndex))}}}_compareRight(){if(this._activeTabItem){const o=this._slideTabItems.findIndex(r=>r.equals(this._activeTabItem)),e=this._slideTabItems.length,t=[];for(let r=o+1;r<e;r++)t.push(this._slideTabItems[r]);for(let r=0;r<o;r++)this._slideTabItems[r].animate().translateX(0);let i=!0;for(let r=0;r<t.length;r++){const s=t[r];Bt.rightLine(this._activeTabItem)>s.getMidLine()?(s.animate().translateX(-this._activeTabItem.getWidth()),this._compareIndex=o+r+1,i=!1):(s.animate().translateX(0),i&&(this._compareIndex=this._activeTabItemIndex))}}}_initConfig(){const o=this._slideTabBar.querySelectorAll(`${this._config.slideTabBarItemSelector}`);this._downActionX=0,this._moveActionX=0,this._compareDirection=0,this._compareIndex=0,this._slideTabItems=Bt.make(o,this),this._activeTabItemIndex=this._config.currentIndex,this._activeTabItem=this._slideTabItems[this._activeTabItemIndex]}};y(Fn,"LongPressDelay",500),y(Fn,"DoubleClickDelay",300);let Tn=Fn;function em(){var ce;const[n,o]=x.useState([]),[e,t]=x.useState(""),[i,r]=x.useState(""),[s,l]=x.useState(!1),[c,d]=x.useState([0,0]),u=x.useRef({slideTabBar:null}),h=x.useRef(null),g=I.useDependency(a.ICommandService),S=I.useDependency(Wt),f=I.useDependency(a.LocaleService),v=I.useDependency(I.IConfirmService),p=I.useDependency(me,a.Quantity.OPTIONAL),C=I.useDependency(m.WorksheetProtectionRuleModel),_=I.useDependency(m.RangeProtectionRuleModel),w=I.useObservable(C.resetOrder$),E=mt(),O=I.useDependency(a.IPermissionService),R=x.useCallback(()=>{var ue;const G=((ue=E.getActiveSheet())==null?void 0:ue.getSheetId())||"";t(G);const Z=E.getSheets(),J=E.getActiveSheet(),ne=Z.filter(ie=>!ie.isSheetHidden()).map((ie,se)=>{var Ee;const te=C.getRule(E.getUnitId(),ie.getSheetId()),fe=_.getSubunitRuleList(E.getUnitId(),ie.getSheetId()).length>0,we=(te==null?void 0:te.permissionId)||fe?b.jsxs(b.Fragment,{children:[b.jsx(Er,{}),b.jsx("span",{className:"univer-outline-none",children:ie.getName()})]}):b.jsx("span",{className:"univer-outline-none",children:ie.getName()});return{sheetId:ie.getSheetId(),label:we,index:se,selected:J===ie,color:(Ee=ie.getTabColor())!=null?Ee:void 0}});o(ne),t(G)},[_,E,C]);x.useEffect(()=>{R();const{slideTabBar:G,disconnectResizeObserver:Z}=P(),J=U(),ne=[X(),F(),Y()];return()=>{J.dispose(),G.destroy(),ne.forEach(ue=>ue.unsubscribe()),Z&&Z()}},[w,E]),x.useEffect(()=>{n.length>0&&B()},[n]),x.useEffect(()=>{const G=D.merge(C.ruleChange$,_.ruleChange$).subscribe(()=>{R()});return()=>{G.unsubscribe()}},[C,R]);const P=()=>{const G=new Tn({slideTabBarSelector:"[data-u-comp=slide-tab-bar]",slideTabBarItemSelector:"[data-u-comp=slide-tab-item]",slideTabBarItemAutoSort:!0,slideTabBarContainer:h.current,currentIndex:0,onChangeName:(J,ne)=>{g.executeCommand(m.SetWorksheetNameCommand.id,{subUnitId:J,name:ne})},onSlideEnd:async(J,ne)=>{await g.executeCommand(m.SetWorksheetOrderCommand.id,{order:ne})},onChangeTab:(J,ne)=>{g.executeCommand(m.SetWorksheetActiveOperation.id,{subUnitId:ne,unitId:E.getUnitId()}).then(()=>{J.button===2&&re(!0)})},onScroll:J=>{S.setScroll(J)},onNameCheckAlert:J=>N(J)||V(J)||L(J),onNameChangeCheck:()=>{var te,fe,ve,we;const J=E.getUnitId(),ne=E==null?void 0:E.getActiveSheet();if(!ne)throw new Error("No active sheet found");const ue=ne.getSheetId(),ie=C.getRule(J,ue),se=_.getSubunitRuleList(J,ue).length>0;return ie||se?(fe=(te=O.getPermissionPoint(new m.WorkbookManageCollaboratorPermission(J).id))==null?void 0:te.value)!=null?fe:!1:(we=(ve=O.getPermissionPoint(new m.WorkbookRenameSheetPermission(J).id))==null?void 0:ve.value)!=null?we:!1}});u.current.slideTabBar=G;const Z=oe(G);return{slideTabBar:G,disconnectResizeObserver:Z}},A=I.useConfigValue(I.UI_PLUGIN_CONFIG_KEY),k=(ce=A==null?void 0:A.contextMenu)!=null?ce:!0,N=G=>{if(G.trim()===""){const Z="sheetNameEmptyAlert";return v.open({id:Z,title:{title:f.t("sheetConfig.sheetNameErrorTitle")},children:{title:f.t("sheetConfig.sheetNameCannotIsEmptyError")},cancelText:f.t("button.cancel"),confirmText:f.t("button.confirm"),onClose(){H(),v.close(Z)},onConfirm(){H(),v.close(Z)}}),!0}return!1},V=G=>{if(!a.nameCharacterCheck(G)){const Z="sheetNameSpecCharAlert";return v.open({id:Z,title:{title:f.t("sheetConfig.sheetNameErrorTitle")},children:{title:f.t("sheetConfig.sheetNameSpecCharError")},cancelText:f.t("button.cancel"),confirmText:f.t("button.confirm"),onClose(){H(),v.close(Z)},onConfirm(){H(),v.close(Z)}}),!0}return!1},L=G=>{const Z=E.getActiveSheet();if((Z==null?void 0:Z.getName())===G)return!1;const ne=E.checkSheetName(G);if(ne){const ue="sheetNameRepeatAlert";v.open({id:ue,title:{title:f.t("sheetConfig.sheetNameErrorTitle")},children:{title:f.t("sheetConfig.sheetNameAlreadyExistsError")},cancelText:f.t("button.cancel"),confirmText:f.t("button.confirm"),onClose(){v.close(ue),H()},onConfirm(){v.close(ue),H()}})}return ne},H=()=>{setTimeout(()=>{var Z;const G=(Z=u.current.slideTabBar)==null?void 0:Z.getActiveItem();G&&(G.focus(),G.selectAll())},0)},W=()=>{var G,Z;(Z=(G=u.current.slideTabBar)==null?void 0:G.getActiveItem())==null||Z.setEditor()},B=()=>{var Z;const G=n.findIndex(J=>J.selected);(Z=u.current.slideTabBar)==null||Z.update(G)},U=()=>g.onCommandExecuted(G=>{switch(G.id){case m.SetTabColorMutation.id:case m.SetWorksheetHideMutation.id:case m.RemoveSheetMutation.id:case m.SetWorksheetNameMutation.id:case m.InsertSheetMutation.id:case m.SetWorksheetOrderMutation.id:case m.SetWorksheetActiveOperation.id:R();break}}),X=()=>S.scroll$.subscribe(G=>{j(G)}),F=()=>S.scrollX$.subscribe(G=>{var Z;(Z=u.current.slideTabBar)==null||Z.flipPage(G)}),Y=()=>S.renameId$.subscribe(()=>{W()}),j=G=>{const{leftEnd:Z,rightEnd:J}=G;let ne="";Z&&J?ne="":Z&&!J?ne="inset -10px 0px 10px -10px rgba(0, 0, 0, 0.2)":!Z&&J?ne="inset 10px 0px 10px -10px rgba(0, 0, 0, 0.2)":!Z&&!J&&(ne="inset 10px 0px 10px -10px rgba(0, 0, 0, 0.2), inset -10px 0px 10px -10px rgba(0, 0, 0, 0.2)"),r(ne)},Q=G=>{const Z=G.calculateActiveTabItemScrollX();if(Z){const J=G.getScrollbar();J.scrollX(J.getScrollX()+Z)}S.setScroll({leftEnd:G.isLeftEnd(),rightEnd:G.isRightEnd()})},oe=G=>{var ne;const Z=(ne=h.current)==null?void 0:ne.querySelector("[data-u-comp=slide-tab-bar]");if(!Z)return;const J=new ResizeObserver(()=>{Q(G)});return J.observe(Z),()=>J.disconnect()},re=G=>{var Z,J,ne,ue,ie;if(k&&!(p!=null&&p.isForceKeepVisible())){if(G){const{left:se}=(J=(Z=h.current)==null?void 0:Z.getBoundingClientRect())!=null?J:{},{left:te}=(ie=(ue=(ne=u.current.slideTabBar)==null?void 0:ne.getActiveItem())==null?void 0:ue.getSlideTabItem().getBoundingClientRect())!=null?ie:{};se!==void 0&&te!==void 0&&d([te-se,0])}l(G)}};return b.jsx(z.DropdownLegacy,{className:"univer-select-none",visible:s,align:{offset:c},trigger:["contextMenu"],overlay:b.jsx(I.UIMenu,{menuType:I.ContextMenuPosition.FOOTER_TABS,onOptionSelect:G=>{const{label:Z,value:J,commandId:ne}=G;g.executeCommand(ne!=null?ne:Z,{value:J,subUnitId:e}),l(!1)}}),onVisibleChange:re,children:b.jsx("div",{className:"univer-max-w-[calc(100%-112px)] univer-overflow-hidden",ref:h,onDragStart:G=>G.preventDefault(),onContextMenu:G=>G.preventDefault(),children:b.jsx("div",{"data-u-comp":"slide-tab-bar",className:"univer-flex univer-select-none univer-flex-row univer-items-center univer-overflow-hidden univer-px-1.5 univer-py-1",style:{boxShadow:i},children:n.map(G=>x.createElement(Kh,{...G,key:G.sheetId,selected:e===G.sheetId}))})})})}const ja=100,Za=()=>{var v,p;const[n,o]=x.useState(!0),[e,t]=x.useState(!0),i=I.useDependency(a.ICommandService),r=I.useDependency(Wt),s=I.useDependency(a.IPermissionService),c=mt().getUnitId(),d=I.useObservable(s.getPermissionPoint$((v=new m.WorkbookEditablePermission(c))==null?void 0:v.id)),u=I.useObservable(s.getPermissionPoint$((p=new m.WorkbookCreateSheetPermission(c))==null?void 0:p.id)),h=C=>{const{leftEnd:_,rightEnd:w}=C;o(_),t(w)};x.useEffect(()=>{const C=r.scroll$.subscribe(a.throttle(_=>{h(_)},100));return()=>{C.unsubscribe()}},[]);const g=()=>{i.executeCommand(m.InsertSheetCommand.id),setTimeout(()=>{r.setAddSheet(0)},0)},S=()=>{r.setScrollX(-ja)},f=()=>{r.setScrollX(ja)};return b.jsxs("div",{className:"univer-relative univer-flex univer-h-full univer-min-w-0 univer-flex-1",children:[b.jsxs("div",{className:"univer-flex univer-items-center",children:[b.jsx(ho,{className:"univer-mr-2",onClick:g,disabled:!(u!=null&&u.value&&(d!=null&&d.value)),children:b.jsx(wr,{})}),b.jsx(Gh,{})]}),b.jsx(em,{}),(!n||!e)&&b.jsxs("div",{className:'univer-relative univer-flex univer-items-center univer-px-2 after:univer-absolute after:univer-right-0 after:univer-top-1/2 after:univer-h-4 after:univer-w-px after:-univer-translate-y-1/2 after:univer-bg-gray-200 after:univer-content-[""]',children:[b.jsx(ho,{disabled:n,onClick:S,children:b.jsx(Tr,{className:"univer-rotate-180"})}),b.jsx(ho,{disabled:e,onClick:f,children:b.jsx(Tr,{})})]})]})},tm=[50,75,100,125,150,175,200,400];function nm(){const n=I.useDependency(a.ICommandService),o=I.useDependency(a.IUniverInstanceService),e=mt(),t=I.useDependency(me),i=I.useObservable(t.visible$),r=x.useCallback(()=>{if(!e)return 100;const u=e.getActiveSheet(),h=u&&u.getZoomRatio()*100||100;return Math.round(h)},[e]),[s,l]=x.useState(()=>r());x.useEffect(()=>(l(r()),n.onCommandExecuted(h=>{if(h.id===Ye.id||h.id===m.SetWorksheetActiveOperation.id){const g=r();l(g)}}).dispose),[n,r]);function c(u){l(u);const h=o.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),g=h==null?void 0:h.getActiveSheet();if(g==null)return;const S=u/100;n.executeCommand(_n.id,{unitId:h.getUnitId(),subUnitId:g.getSheetId(),zoomRatio:S})}const d=(i==null?void 0:i.visible)&&(i.unitId===(e==null?void 0:e.getUnitId())||i.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);return b.jsx(I.Slider,{disabled:d,min:zo[0],value:s,shortcuts:tm,onChange:c})}function im(){return b.jsx("section",{className:"univer-flex univer-flex-shrink-0 univer-justify-end",children:b.jsx(nm,{})})}class Pr{constructor(){y(this,"_functions",[{func:q.FUNCTION_NAMES_STATISTICAL.MAX,filter:o=>{var e,t,i,r;return((t=(e=o.values.find(s=>s.func===q.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1&&((r=(i=o.values.find(s=>s.func===q.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:i.value)!=null?r:0)>0}},{func:q.FUNCTION_NAMES_STATISTICAL.MIN,filter:o=>{var e,t,i,r;return((t=(e=o.values.find(s=>s.func===q.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1&&((r=(i=o.values.find(s=>s.func===q.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:i.value)!=null?r:0)>0}},{func:q.FUNCTION_NAMES_MATH.SUM,filter:o=>{var e,t,i,r;return((t=(e=o.values.find(s=>s.func===q.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1&&((r=(i=o.values.find(s=>s.func===q.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:i.value)!=null?r:0)>0}},{func:q.FUNCTION_NAMES_STATISTICAL.COUNTA,filter:o=>{var e,t;return((t=(e=o.values.find(i=>i.func===q.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1}},{func:q.FUNCTION_NAMES_STATISTICAL.COUNT,filter:o=>{var e,t,i,r;return((t=(e=o.values.find(s=>s.func===q.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1&&((r=(i=o.values.find(s=>s.func===q.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:i.value)!=null?r:0)>0}},{func:q.FUNCTION_NAMES_STATISTICAL.AVERAGE,filter:o=>{var e,t,i,r;return((t=(e=o.values.find(s=>s.func===q.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1&&((r=(i=o.values.find(s=>s.func===q.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:i.value)!=null?r:0)>0}}]);y(this,"_state$",new D.BehaviorSubject(null));y(this,"state$",this._state$.asObservable())}dispose(){this._state$.complete()}setState(o){var t;const e={values:[],pattern:null};o==null||o.values.forEach(i=>{const r=this._functions.find(s=>s.func===i.func);r&&(r.filter===void 0||r.filter(o))&&e.values.push(i)}),e.pattern=(t=o==null?void 0:o.pattern)!=null?t:null,this._state$.next(e)}getState(){return this._state$.getValue()}getFunctions(){return this._functions}addFunctions(o){this._functions.push(...o)}}const wi=a.createIdentifier("univer.sheet-status-bar.service"),om=[q.FUNCTION_NAMES_MATH.SUM,q.FUNCTION_NAMES_STATISTICAL.AVERAGE,q.FUNCTION_NAMES_STATISTICAL.MIN,q.FUNCTION_NAMES_STATISTICAL.MAX],mo={[q.FUNCTION_NAMES_MATH.SUM]:"statusbar.sum",[q.FUNCTION_NAMES_STATISTICAL.AVERAGE]:"statusbar.average",[q.FUNCTION_NAMES_STATISTICAL.MIN]:"statusbar.min",[q.FUNCTION_NAMES_STATISTICAL.MAX]:"statusbar.max",[q.FUNCTION_NAMES_STATISTICAL.COUNT]:"statusbar.count",[q.FUNCTION_NAMES_STATISTICAL.COUNTA]:"statusbar.countA",[q.FUNCTION_NAMES_TEXT.CONCATENATE]:"concatenate"},rm=n=>{const o=I.useDependency(a.LocaleService),e=I.useDependency(I.IMessageService),t=I.useDependency(I.IClipboardInterfaceService),i=sm(n),r=async()=>{await t.writeText(n.value.toString()),e.show({type:z.MessageType.Success,content:o.t("statusbar.copied")})};return b.jsx(z.Tooltip,{title:o.t("statusbar.clickToCopy"),placement:"top",children:b.jsx("div",{className:"univer-flex univer-cursor-pointer univer-truncate univer-text-center univer-text-xs univer-text-gray-400",onClick:r,children:b.jsx("span",{children:`${o.t((mo==null?void 0:mo[n.name])||n.name)}: ${i}`})},n.name)})};function sm(n){const{pattern:o,value:e}=n;return typeof e!="number"?0:e>=1e8?e.toExponential(2):o&&om.includes(n.name)?a.numfmt.format(o,e,{throws:!1}):e.toLocaleString()}const Ga=800,am=3,lm=()=>{var h,g;const n=(g=(h=I.useConfigValue(Te))==null?void 0:h.statusBarStatistic)!=null?g:!0,[o,e]=x.useState(window.innerWidth<Ga),t=I.useDependency(wi),i=t.getFunctions().map((S,f)=>({name:S.func,value:0,show:!0,disable:!1,pattern:null})),r=(S,f,v,p)=>{const[C,_]=x.useState(S),[w,E]=x.useState(!0),O=x.useMemo(()=>C.filter(k=>k.show&&!k.disable),[C]),R=x.useMemo(()=>O.find(k=>k.show&&!k.disable),[O]),P=x.useMemo(()=>v&&R?[R]:O,[v,R,O]),A=x.useCallback(k=>{const N=k==null?void 0:k.values;if(!(N!=null&&N.length)){E(!1);return}E(!0),_(V=>V.map(L=>{var H,W,B;return{...L,value:(W=(H=N.find(U=>U.func===L.name))==null?void 0:H.value)!=null?W:L.value,disable:!N.some(U=>U.func===L.name),pattern:(B=k==null?void 0:k.pattern)!=null?B:null}}))},[]);return x.useEffect(()=>{if(!p)return;const k=f.state$.subscribe(A);return()=>k.unsubscribe()},[p,f,A]),{statistics:C,showList:P,show:w}},{showList:s,show:l}=r(i,t,o,n),c=a.debounce(()=>{const S=window.innerWidth<Ga;o!==S&&e(S)},100);x.useEffect(()=>(window.addEventListener("resize",c),()=>{window.removeEventListener("resize",c)}),[o]);const u=((S,f,v)=>n?x.useMemo(()=>S.length>f?S.reduce((_,w,E)=>(E%2===0&&_.push(S.slice(E,E+2)),_),[]).map((_,w)=>b.jsxs("div",{className:"univer-grid univer-h-full univer-items-center",children:[_[0]&&b.jsx(v,{..._[0]},_[0].name),_[1]&&b.jsx(v,{..._[1]},_[1].name)]},`stat-col-${w}`)):S.map(C=>b.jsx("div",{className:"univer-grid univer-h-full univer-items-center",children:b.jsx(v,{...C})},C.name)),[S,f,v]):null)(s,am,rm);return l&&b.jsx("div",{className:z.clsx('univer-relative univer-box-border univer-flex univer-h-full univer-items-center univer-overflow-hidden univer-px-2 after:univer-absolute after:univer-right-0 after:univer-top-1/2 after:univer-block after:univer-h-4 after:univer-w-px after:-univer-translate-y-1/2 after:univer-bg-gray-200 after:univer-content-[""]',{"univer-max-w-32":o,"univer-max-w-fit":!o}),children:b.jsx("div",{className:"univer-flex univer-h-full univer-gap-x-2",children:u})})},Ka=36;function qa(){var d;const n=I.useConfigValue(Te),o=I.useDependency(I.IMenuManagerService),e=(d=n==null?void 0:n.footer)!=null?d:!0;if(!mt()||!e)return null;const i=o.getMenuByPositionKey(I.ContextMenuPosition.FOOTER_MENU),{sheetBar:r=!0,statisticBar:s=!0,menus:l=!0,zoomSlider:c=!0}=(n==null?void 0:n.footer)||{};return!r&&!s&&!l&&!c?null:b.jsxs("section",{className:"univer-box-border univer-grid univer-w-full univer-grid-flow-col univer-grid-cols-[1fr,auto,auto,auto] univer-items-center univer-justify-between univer-bg-white univer-px-5 univer-text-gray-900 dark:!univer-bg-gray-900 dark:!univer-text-gray-200",style:{height:Ka},"data-range-selector":!0,children:[r&&b.jsx(Za,{}),s&&b.jsx(lm,{}),l&&i.length>0&&b.jsx("div",{className:"univer-box-border univer-flex univer-gap-2 univer-px-2",children:i.map(u=>{var h;return(h=u.children)==null?void 0:h.map(g=>(g==null?void 0:g.item)&&b.jsx(I.ToolbarItem,{...g.item},g.key))})}),c&&b.jsx(im,{})]})}function Qa(){const n=I.useConfigValue(Te);return Ja()&&(n==null?void 0:n.formulaBar)!==!1?b.jsx(Ya,{}):null}function Or(){return Ja()?b.jsxs(b.Fragment,{children:[b.jsx(Yh,{}),b.jsx(Xh,{})]}):null}function Ja(){const n=I.useDependency(a.IUniverInstanceService),e=!!I.useObservable(()=>n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),null,!1,[]);return x.useMemo(()=>n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).length>0,[n,e])}var cm=Object.getOwnPropertyDescriptor,dm=(n,o,e,t)=>{for(var i=t>1?void 0:t?cm(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},yn=(n,o)=>(e,t)=>o(e,t,n);const $a=5,el=2;T.SheetCellEditorResizeService=class extends a.Disposable{constructor(o,e,t,i,r,s){super(),this._layoutService=o,this._cellEditorManagerService=e,this._editorBridgeService=t,this._renderManagerService=i,this._univerInstanceService=r,this._configService=s}get _currentRenderer(){return M.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService)}get _editingUnitId(){var o,e;return(e=(o=this._editorBridgeService.getEditCellState())==null?void 0:o.unitId)!=null?e:""}get _editingRenderer(){return this._renderManagerService.getRenderById(this._editingUnitId)}get _renderer(){var e;const o=(e=this._univerInstanceService.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET))==null?void 0:e.getUnitId();return this._editingUnitId===o?this._editingRenderer:this._currentRenderer}get _sheetSkeletonManagerService(){var o;return(o=this._renderer)==null?void 0:o.with(T.SheetSkeletonManagerService)}get engine(){var o;return(o=this._renderer)==null?void 0:o.engine}fitTextSize(o){var k,N,V,L;const e=this._editorBridgeService.getEditCellState();if(!e)return;const{position:t,documentLayoutObject:i,canvasOffset:r,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,r,S,i,s,l);if(!f||f.actualWidth<=0)return;let{actualWidth:v,actualHeight:p}=f;const{verticalAlign:C,horizontalAlign:_,paddingData:w,fill:E}=i;v=v+((k=w.l)!=null?k:0)+((N=w.r)!=null?N:0),p=p+((V=w.t)!=null?V:0)+((L=w.b)!=null?L:0);let O=u-c,R=h-d;O<v&&(O=Math.ceil(v)),R<p&&(R=Math.ceil(p));let P=0;C===a.VerticalAlign.MIDDLE?P=(R-p)/2/l:C===a.VerticalAlign.TOP?P=w.t||0:P=(R-p)/l;let A=0;_===a.HorizontalAlign.CENTER||(_===a.HorizontalAlign.RIGHT?A=(O-v)/s:A=w.l||0),P=P<(w.t||0)?w.t||0:P,A=A<(w.l||0)?w.l||0:A,g.updateDocumentDataMargin({t:P,l:A}),S.calculate(),this._editAreaProcessing(O,R,t,r,E,s,l,_,o)}_predictingSize(o,e,t,i,r=1,s=1){const{startX:l,endX:c}=o,{textRotation:d,wrapStrategy:u,paddingData:h}=i,g=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC),{vertexAngle:S}=M.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:_}=t.getActualSize();return{actualWidth:C*r,actualHeight:_*s}}const f=this._getEditorMaxSize(o,e,i.horizontalAlign);if(!f)return;g==null||g.updateDocumentDataPageSize(f.width/r),t.calculate();const v=t.getActualSize();let p=c-l;return p<v.actualWidth*r+$a*r&&(p=v.actualWidth*r+$a*r),g==null||g.updateDocumentDataPageSize(p/r),g==null||g.updateDocumentRenderConfig({horizontalAlign:a.HorizontalAlign.UNSPECIFIED,cellValueType:void 0}),{actualWidth:v.actualWidth*r,actualHeight:v.actualHeight*s}}_getEditorMaxSize(o,e,t){var w,E,O,R;if(this._getEditorObject()==null)return;function r(P){return Number.parseInt(P.replace("px",""))}const s=this.engine;if(!s)return;const l=s.getCanvasElement(),c=l.getBoundingClientRect(),d=r(l.style.width),{width:u}=c,h=u/d,{startX:g,startY:S,endX:f}=o,v=s.width,p=((E=(w=this._configService.getConfig(I.UI_PLUGIN_CONFIG_KEY))==null?void 0:w.footer)==null||E)&&((R=(O=this._configService.getConfig(Te))==null?void 0:O.footer)==null||R)?Ka:0,C=document.body.clientHeight-S-p-e.top-el*2;let _=u-g;if(t===a.HorizontalAlign.CENTER){const P=v-f,A=g;_=f-g+Math.min(A,P)*2}else t===a.HorizontalAlign.RIGHT&&(_=f);return{height:C,width:_-el,scaleAdjust:h}}_editAreaProcessing(o,e,t,i,r,s=1,l=1,c,d){var W;const u=this._getEditorObject();if(u==null)return;const h=this.engine;if(!h)return;const g=h.getCanvasElement();let{startX:S,startY:f}=t;const{document:v,scene:p,engine:C}=u,_=p.getViewport(K.VIEWPORT_KEY.VIEW_MAIN),w=this._getEditorMaxSize(t,i,c),{height:E,width:O,scaleAdjust:R}=w;let P=e,A=_==null?void 0:_.getScrollBar();P>E?(A==null?_&&new M.ScrollBar(_,{enableHorizontal:!1,barSize:8}):_==null||_.resetCanvasSizeAndUpdateScroll(),_==null||_.scrollToViewportPos({viewportScrollY:P-E}),P=E):(A=null,(W=_==null?void 0:_.getScrollBar())==null||W.dispose()),o+=(A==null?void 0:A.barSize)||0,o>O&&(o=O),this._addBackground(p,o/s,e/l,r);const{scaleX:k,scaleY:N}=p.getPrecisionScale();p.transformByState({width:o*R/s,height:e*R/l,scaleX:s*R,scaleY:l*R}),v.resize(o*R/s,e*R/l),setTimeout(()=>{C.resizeBySize(M.fixLineWidthByScale(o,k),M.fixLineWidthByScale(P,N)),d==null||d()},0);const V=this._layoutService.getContentElement().getBoundingClientRect(),L=g.getBoundingClientRect();S=S*R+(L.left-V.left),f=f*R+(L.top-V.top);const H=t.endX-t.startX;c===a.HorizontalAlign.RIGHT?S+=(H-o)*R:c===a.HorizontalAlign.CENTER&&(S+=(H-o*R)/2),this._cellEditorManagerService.setState({startX:S,startY:f,endX:o*R+S,endY:P*R+f,show:!0})}_addBackground(o,e,t,i){const r="_backgroundRectHelperColor_",s=o.getObject(r);s==null&&i==null||(s==null?o.addObjects([new M.Rect(r,{width:e,height:t,fill:i,evented:!1})],K.DOCS_COMPONENT_MAIN_LAYER_INDEX):i==null?s.dispose():(s.setProps({fill:i}),s.transformByState({width:e,height:t})))}resizeCellEditor(o){var R,P;const e=this._cellEditorManagerService.getState();if(!e||!this._editorBridgeService.isVisible().visible)return;this._editorBridgeService.refreshEditCellPosition(!0);const t=this._editorBridgeService.getEditCellState();if(!t)return;const i=(P=(R=this._sheetSkeletonManagerService)==null?void 0:R.getSkeletonParam(t.sheetId))==null?void 0:P.skeleton;if(!i)return;const{row:r,column:s,scaleX:l,scaleY:c,position:d,canvasOffset:u,documentLayoutObject:h}=t,{horizontalAlign:g}=h,S=this._getEditorMaxSize(d,u,g);if(!S)return;const{height:f,width:v,scaleAdjust:p}=S,C=i.getCellWithCoordByIndex(r,s),_=Math.min((C.mergeInfo.endY-C.mergeInfo.startY)*c,f)*p,w=Math.min((C.mergeInfo.endX-C.mergeInfo.startX)*l,v)*p,E=e.endY-e.startY,O=e.endX-e.startX;if(E!==_||O!==w){if(this._editorBridgeService.refreshEditCellPosition(!0),!this._getEditorSkeleton())return;this.fitTextSize(o)}}_getEditorObject(){return Wi(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}_getEditorSkeleton(){var o;return(o=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:o.with(Ce.DocSkeletonManagerService).getSkeleton()}},T.SheetCellEditorResizeService=dm([yn(0,I.ILayoutService),yn(1,bn),yn(2,me),yn(3,M.IRenderManagerService),yn(4,a.IUniverInstanceService),yn(5,a.IConfigService)],T.SheetCellEditorResizeService);var um=Object.getOwnPropertyDescriptor,hm=(n,o,e,t)=>{for(var i=t>1?void 0:t?um(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},Ft=(n,o)=>(e,t)=>o(e,t,n);let Ei=class extends a.RxDisposable{constructor(o,e,t,i,r,s,l,c){super();y(this,"_d");this._context=o,this._instanceSrv=e,this._commandService=t,this._editorBridgeService=i,this._selectionManagerService=r,this._contextService=s,this._renderManagerService=l,this._sheetSkeletonManagerService=c,this.disposeWithMe(this._instanceSrv.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(d=>{d&&d.getUnitId()===this._context.unitId?this._d=this._init():this._disposeCurrent()}))}_init(){const o=new a.DisposableCollection;return this._initSelectionChangeListener(o),this._initEventListener(o),this._commandExecutedListener(o),this._initialKeyboardListener(o),o}_disposeCurrent(){var o;(o=this._d)==null||o.dispose(),this._d=null}_initSelectionChangeListener(o){o.add(D.merge(this._selectionManagerService.selectionMoveEnd$,this._selectionManagerService.selectionSet$,this._selectionManagerService.selectionMoveStart$).subscribe(e=>this._updateEditorPosition(e)))}_updateEditorPosition(o){var t,i,r;if(this._editorBridgeService.isVisible().visible)return;const e=(t=o==null?void 0:o[o.length-1])==null?void 0:t.primary;if(e){const s=this._getSheetObject(),{scene:l,engine:c}=s,d=this._context.unitId,u=(i=this._context.unit.getActiveSheet())==null?void 0:i.getSheetId();if(!u)return;const h=(r=this._sheetSkeletonManagerService.getSkeletonParam(u))==null?void 0:r.skeleton.getCellWithCoordByIndex(e.actualRow,e.actualColumn),g=h?{actualRow:h.actualRow,actualColumn:h.actualColumn,isMerged:h.isMerged,startRow:h.mergeInfo.startRow,startColumn:h.mergeInfo.startColumn,endRow:h.mergeInfo.endRow,endColumn:h.mergeInfo.endColumn,isMergedMainCell:h.isMergedMainCell}:e;this._commandService.executeCommand(oo.id,{scene:l,engine:c,primary:g,unitId:d,sheetId:u})}}refreshEditorPosition(){const o=this._selectionManagerService.getWorkbookSelections(this._context.unitId);if(o){const e=o.getCurrentSelections();e&&this._updateEditorPosition([...e])}}_initEventListener(o){const e=this._getSheetObject(),{spreadsheet:t,spreadsheetColumnHeader:i,spreadsheetLeftTopPlaceholder:r,spreadsheetRowHeader:s}=e;o.add(t.onDblclick$.subscribeEvent(l=>{l.button!==2&&this._commandService.executeCommand(Se.id,{visible:!0,eventType:M.DeviceInputEventType.Dblclick,unitId:this._context.unitId})})),o.add(t.onPointerDown$.subscribeEvent({next:this._tryHideEditor.bind(this),priority:-1})),o.add(i.onPointerDown$.subscribeEvent({next:this._tryHideEditor.bind(this),priority:-1})),o.add(r.onPointerDown$.subscribeEvent({next:this._tryHideEditor.bind(this),priority:-1})),o.add(s.onPointerDown$.subscribeEvent({next:this._tryHideEditor.bind(this),priority:-1}))}_initialKeyboardListener(o){let e=null;const t=r=>{const s=r.with(K.DocSelectionRenderService);s&&(e=a.toDisposable(s.onInputBefore$.subscribe(l=>{if(!this._isCurrentSheetFocused())return;const c=this._contextService.getContextValue(a.FOCUSING_FX_BAR_EDITOR),d=this._contextService.getContextValue(a.FOCUSING_SHEET),u=r.unitId;this._editorBridgeService.isVisible().visible||u&&d&&!c&&this._showEditorByKeyboard(l)})),o.add(e))},i=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);i?t(i):this.disposeWithMe(this._renderManagerService.created$.pipe(D.filter(r=>r.unitId===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)).subscribe(r=>{e==null||e.dispose(),t(r)}))}_commandExecutedListener(o){const e=new Set([m.ClearSelectionFormatCommand.id,_n.id]);o.add(this._commandService.onCommandExecuted(t=>{if(e.has(t.id)){if(this._editorBridgeService.isVisible().visible)return;this._editorBridgeService.refreshEditCellState()}if(t.id===m.SetRangeValuesMutation.id){const i=t.params,{cellValue:r,unitId:s,subUnitId:l}=i;if(!r)return;const c=this._editorBridgeService.getEditLocation();if(c){const{unitId:d,sheetId:u,row:h,column:g}=c;s===d&&l===u&&r&&r[h]&&Object.prototype.hasOwnProperty.call(r[h],g)&&this._editorBridgeService.refreshEditCellState()}}})),o.add(this._commandService.beforeCommandExecuted((t,i)=>{i!=null&&i.fromCollab||t.id===m.SetWorksheetActiveOperation.id&&this._tryHideEditor()}))}_showEditorByKeyboard(o){const e=o==null?void 0:o.event;o==null||!e.data&&e.inputType!=="InsertParagraph"||this._commandService.syncExecuteCommand(Se.id,{visible:!0,eventType:M.DeviceInputEventType.Keyboard,keycode:e.which,unitId:this._context.unitId})}_tryHideEditor(){this._editorBridgeService.isForceKeepVisible()||this._hideEditor()}_hideEditor(){this._editorBridgeService.isVisible().visible===!0&&this._commandService.syncExecuteCommand(Se.id,{visible:!1,eventType:M.DeviceInputEventType.PointerDown,unitId:this._context.unitId})}_getSheetObject(){return Ve(this._context.unit,this._context)}_isCurrentSheetFocused(){var o;return((o=this._instanceSrv.getFocusedUnit())==null?void 0:o.getUnitId())===this._context.unitId}};Ei=hm([Ft(1,a.IUniverInstanceService),Ft(2,a.ICommandService),Ft(3,me),Ft(4,a.Inject(m.SheetsSelectionsService)),Ft(5,a.IContextService),Ft(6,M.IRenderManagerService),Ft(7,a.Inject(T.SheetSkeletonManagerService))],Ei);const tl=[I.KeyCode.ARROW_DOWN,I.KeyCode.ARROW_UP,I.KeyCode.ARROW_LEFT,I.KeyCode.ARROW_RIGHT],mm=[I.KeyCode.ENTER,I.KeyCode.TAB,...tl];function nl(){const n=[];for(const o of tl)n.push({id:Lt.id,binding:o,preconditions:e=>tn(e),staticParameters:{visible:!1,eventType:M.DeviceInputEventType.Keyboard,keycode:o,isShift:!1}}),n.push({id:Lt.id,binding:o|I.MetaKeys.SHIFT,preconditions:e=>tn(e),staticParameters:{visible:!1,eventType:M.DeviceInputEventType.Keyboard,keycode:o,isShift:!0}});return n}const il={id:Ii.id,binding:I.KeyCode.F2,description:"shortcut.sheet.start-editing",group:"4_sheet-edit",preconditions:ae,staticParameters:{visible:!0,eventType:M.DeviceInputEventType.Keyboard,keycode:I.KeyCode.F2}},ol={id:Se.id,binding:I.KeyCode.ENTER,description:"shortcut.sheet.toggle-editing",group:"4_sheet-edit",preconditions:n=>tn(n),staticParameters:{visible:!1,eventType:M.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ENTER}},rl={id:Se.id,binding:I.KeyCode.TAB,preconditions:n=>tn(n),staticParameters:{visible:!1,eventType:M.DeviceInputEventType.Keyboard,keycode:I.KeyCode.TAB}},sl={id:Se.id,binding:I.KeyCode.ESC,description:"shortcut.sheet.abort-editing",group:"4_sheet-edit",preconditions:n=>tn(n),staticParameters:{visible:!1,eventType:M.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ESC}},al={id:Se.id,binding:I.KeyCode.ENTER|I.MetaKeys.CTRL_COMMAND,mac:I.KeyCode.ENTER|I.MetaKeys.MAC_CTRL,preconditions:n=>tn(n),staticParameters:{visible:!1,eventType:M.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ENTER|I.MetaKeys.CTRL_COMMAND}},ll={id:K.BreakLineCommand.id,description:"shortcut.sheet.break-line",group:"4_sheet-edit",preconditions:n=>Xd(n),binding:I.KeyCode.ENTER|I.MetaKeys.ALT},cl={id:K.DeleteLeftCommand.id,preconditions:n=>er(n)||Xi(n),binding:I.KeyCode.BACKSPACE},dl={id:K.DeleteRightCommand.id,preconditions:n=>er(n)||Xi(n),binding:I.KeyCode.DELETE},ul={id:K.DeleteLeftCommand.id,preconditions:n=>er(n)||Xi(n),binding:I.KeyCode.BACKSPACE|I.MetaKeys.SHIFT},hl={id:Se.id,description:"shortcut.sheet.delete-and-start-editing",group:"4_sheet-edit",preconditions:n=>ae(n)&&!Xi(n),binding:I.KeyCode.BACKSPACE,staticParameters:{visible:!0,eventType:M.DeviceInputEventType.Keyboard,keycode:I.KeyCode.BACKSPACE}};function gm(n){return n.startsWith("'")}function Sm(n){return n.slice(1)}const fm={"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","%":"%","-":"-",".":".",":":":","/":"/","+":"+","@":"@","&":"&","*":"*","#":"#","=":"=",">":">","<":"<","$":"$",""":'"',"'":"'","(":"(",")":")"," ":" ",",":",","!":"!","?":"?",";":";","[":"[","]":"]","{":"{","}":"}"},Ar={true:"TRUE",false:"FALSE"};function vm(n){return[a.LocaleType.ZH_CN,a.LocaleType.ZH_TW].includes(n)}function pm(n,o,e,t){let i=n;if(vm(e)){if(n.startsWith("'")||n.startsWith("'"))return`'${n.slice(1)}`;i=Cm(i)}if(i.startsWith("="))return Im(n,i,o,t);const r=i.toLowerCase();return Ar[r]?Ar[r]:a.numfmt.parseValue(i)==null?n:i}function Cm(n){const o=/['"].*?['"]/g,e=[],t=n.split(o);n.replace(o,r=>(e.push(r),""));let i=t.join("").split("").map(wm).join("");return e.forEach((r,s)=>{i=i.slice(0,s*2)+r+i.slice((s+1)*2)}),i}function Im(n,o,e,t){const i=e.sequenceNodesBuilder(o);if(!i)return n;let r=o,s=0;return i.forEach((l,c)=>{if(typeof l=="object"){const d=l.token;if(Ar[d.toLowerCase()]){const u=l.startIndex+s+1,h=l.endIndex+s+2;r=Rn(d.toLocaleUpperCase(),r,u,h)}else if(l.nodeType===q.sequenceNodeType.FUNCTION&&_m(d,t,i,c)||l.nodeType===q.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;r=Rn(h.toLocaleUpperCase(),r,g,S)}else{const h=l.startIndex+s+1,g=l.endIndex+s+2;r=Rn(d.toLocaleUpperCase(),r,h,g)}}else if(d.startsWith('"')&&d.endsWith('"')||d.startsWith("'")&&d.endsWith("'")){const u=l.startIndex+s+2,h=l.endIndex+s+1;r=Rn(n.slice(u,h),r,u,h)}else if(l.nodeType!==q.sequenceNodeType.ARRAY){const u=a.numfmt.parseValue(d);if(u==null){const h=l.startIndex+s+1,g=l.endIndex+s+2;r=Rn(n.slice(h,g),r,h,g)}else if(typeof u.v=="number"&&(u.z===void 0||!a.numfmt.getFormatInfo(u.z).isDate)){const h=`${u.v}`,g=l.startIndex+s+1,S=l.endIndex+s+2,{processedString:f,offset:v}=Em(d,h);r=Rn(f,r,g,S),s+=v}}}}),r}function _m(n,o,e,t){const i=o.getDescriptions();return e[t+1]!==q.matchToken.OPEN_BRACKET?!1:i.get(bm(n).toLocaleUpperCase())!==void 0}function bm(n){const o=/^@+/;return n.replace(o,"")}function wm(n){return fm[n]||n}function Rn(n,o,e,t){return o.substring(0,e)+n+o.substring(t)}function Em(n,o){var s,l;const e=((s=n.match(/^\s*/))==null?void 0:s[0])||"",t=((l=n.match(/\s*$/))==null?void 0:l[0])||"",i=e+o+t,r=i.length-n.length;return{processedString:i,offset:r}}const ml="range_selector",gl=n=>n.includes(ml);var Tm=Object.getOwnPropertyDescriptor,ym=(n,o,e,t)=>{for(var i=t>1?void 0:t?Tm(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},ye=(n,o)=>(e,t)=>o(e,t,n);const Sl=-1e3;T.EditingRenderController=class extends a.Disposable{constructor(e,t,i,r,s,l,c,d,u,h,g,S,f,v,p){super();y(this,"_cursorChange",0);y(this,"_editingUnit","");y(this,"_cursorTimeout");this._undoRedoService=e,this._contextService=t,this._renderManagerService=i,this._editorBridgeService=r,this._cellEditorManagerService=s,this._lexerTreeBuilder=l,this._functionService=c,this._textSelectionManagerService=d,this._commandService=u,this._localService=h,this._editorService=g,this._univerInstanceService=S,this._sheetInterceptorService=f,this._sheetCellEditorResizeService=v,this._selectionManagerService=p,this.disposeWithMe(this._init()),this._initEditorVisibilityListener()}dispose(){super.dispose()}get _workbookSelections(){return this._selectionManagerService.getWorkbookSelections(this._editingUnit)}_init(){const e=new a.DisposableCollection;return this._subscribeToCurrentCell(e),this._initialCursorSync(e),this._listenEditorFocus(e),this._commandExecutedListener(e),this._initSkeletonListener(e),e.add(()=>{clearTimeout(this._cursorTimeout)}),this._cursorTimeout=setTimeout(()=>{this._cursorStateListener(e)},1e3),e}_initEditorVisibilityListener(){this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(async e=>{var t;if(this._editingUnit&&(e==null?void 0:e.getUnitId())!==this._editingUnit&&!this._editorBridgeService.isForceKeepVisible()){this._commandService.syncExecuteCommand(Se.id,{visible:!1,eventType:M.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ESC,unitId:this._editingUnit});const i=(t=this._renderManagerService.getRenderById(e.getUnitId()))==null?void 0:t.with(Ei);i&&i.refreshEditorPosition()}})),this.disposeWithMe(this._editorBridgeService.visible$.pipe(D.distinctUntilChanged((e,t)=>e.visible===t.visible)).subscribe(async e=>{e.visible?(this._editingUnit=e.unitId,this._handleEditorVisible(e)):this._editingUnit&&(await this._handleEditorInvisible(e),this._editingUnit="")}))}_listenEditorFocus(e){const t=this._getEditorObject();t&&e.add(t.document.onPointerDown$.subscribeEvent(()=>{var i;if(this._editingUnit&&this._editorBridgeService.isVisible()){const r=this._editorBridgeService.getEditCellState(),s=this._editorBridgeService.getCurrentEditorId();if(!r||!s)return;(i=this._sheetCellEditorResizeService)==null||i.fitTextSize()}}))}_initialCursorSync(e){e.add(this._cellEditorManagerService.focus$.pipe(D.filter(t=>!!t)).subscribe(()=>{var r;const t=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(!t)return;const i=(r=this._renderManagerService.getRenderById(t==null?void 0:t.getUnitId()))==null?void 0:r.with(K.DocSelectionRenderService);i&&i.sync()}))}_initSkeletonListener(e){const t=new Set(m.COMMAND_LISTENER_SKELETON_CHANGE);t.delete(m.SetWorksheetActiveOperation.id),e.add(this._commandService.onCommandExecuted(i=>{var r;if(t.has(i.id)){switch(i.id){case m.MoveRowsMutation.id:case m.MoveColsMutation.id:case m.RemoveColMutation.id:case m.RemoveRowMutation.id:case m.InsertColMutation.id:case m.InsertRowMutation.id:{const s=this._editorBridgeService.getEditLocation();if(!s)break;const l={startRow:s.row,startColumn:s.column,endRow:s.row,endColumn:s.column},c=m.adjustRangeOnMutation(l,i);if(!c)break;const d=c.startRow,u=c.startColumn;this._editorBridgeService.updateEditLocation(d,u);break}}(r=this._sheetCellEditorResizeService)==null||r.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 _,w;if(t==null||this._editorBridgeService.isForceKeepVisible())return;const i=this._editorBridgeService.getEditCellState();if(i==null)return;const{position:r,documentLayoutObject:s,scaleX:l,editorUnitId:c}=i;if(this._contextService.getContextValue(a.FOCUSING_EDITOR_STANDALONE))return;const d=this._getDocumentDataModel();if(d==null)return;const{startX:u,endX:h}=r,{textRotation:g,wrapStrategy:S,documentModel:f}=s,{vertexAngle:v}=M.convertTextRotation(g);S===a.WrapStrategy.WRAP&&v===0&&d.updateDocumentDataPageSize((h-u)/l),this._commandService.syncExecuteCommand(K.ReplaceSnapshotCommand.id,{unitId:c,snapshot:f.getSnapshot()}),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!0),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});const p=(_=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:_.with(K.DocSelectionRenderService),C=(w=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:w.with(K.DocSelectionRenderService);(p!=null&&p.canFocusing||C!=null&&C.canFocusing)&&(this._univerInstanceService.setCurrentUnitForType(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),p==null||p.activate(Sl,Sl,!0))}))}_commandExecutedListener(e){e.add(this._commandService.onCommandExecuted(i=>{var r;if(i.id===Ce.RichTextEditingMutation.id){const s=i.params,{unitId:l}=s;if(gl(l)||(this._editorBridgeService.changeEditorDirty(!0),!this._editorBridgeService.isVisible().visible))return;l===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&((r=this._sheetCellEditorResizeService)==null||r.fitTextSize())}}));const t=[Lt.id];e.add(this._commandService.onCommandExecuted(i=>{if(t.includes(i.id)){const r=i.params,{keycode:s,isShift:l}=r;if(s!=null&&(this._cursorChange===2||this._contextService.getContextValue(a.FOCUSING_FX_BAR_EDITOR))){this._moveInEditor(s,l);return}this._commandService.syncExecuteCommand(Se.id,r)}i.id===Ii.id&&(this._cursorChange=2)}))}_handleEditorVisible(e){var f,v,p,C;const{eventType:t,keycode:i}=e;this._cursorChange=t===M.DeviceInputEventType.PointerDown||t===M.DeviceInputEventType.Dblclick?2:1;const r=this._editorBridgeService.getEditLocation();if(r==null)return;this._commandService.syncExecuteCommand(ro.id,{range:{startRow:r.row,startColumn:r.column,endRow:r.row,endColumn:r.column}}),this._editorBridgeService.refreshEditCellPosition(!1);const{unitId:s,isInArrayFormulaRange:l=!1}=r,c=this._getEditorObject();if(c==null)return;const{document:d,scene:u}=c;this._contextService.setContextValue(a.EDITOR_ACTIVATED,!0);const h=this._getDocumentDataModel(),g=this._getEditorSkeleton(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(!g||!h)return;(f=this._sheetCellEditorResizeService)==null||f.fitTextSize(()=>{const _=u.getViewport(K.VIEWPORT_KEY.VIEW_MAIN);_==null||_.scrollToViewportPos({viewportScrollX:Number.POSITIVE_INFINITY,viewportScrollY:Number.POSITIVE_INFINITY})});const S=()=>{this._emptyDocumentDataModel(h.getSnapshot().documentStyle,!!l),d.makeDirty(),(i===I.KeyCode.BACKSPACE||t===M.DeviceInputEventType.Dblclick)&&(g.calculate(),this._editorBridgeService.changeEditorDirty(!0)),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})};if(this._isCellImageData(h.getSnapshot()))S();else if(t===M.DeviceInputEventType.Keyboard&&i===I.KeyCode.F2){d.makeDirty(),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}]);const _=((p=(v=h.getBody())==null?void 0:v.dataStream.length)!=null?p:2)-2;this._textSelectionManagerService.replaceDocRanges([{startOffset:_,endOffset:_}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})}else if(t===M.DeviceInputEventType.Keyboard||t===M.DeviceInputEventType.Dblclick&&l)S();else if(t===M.DeviceInputEventType.Dblclick){if(this._contextService.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA))return;const _=h.getBody().dataStream.length-2||0;this._textSelectionManagerService.replaceDocRanges([{startOffset:_,endOffset:_}])}(C=this._renderManagerService.getRenderById(s))==null||C.scene.resetCursor()}_refreshCurrentSelections(e){const t=this._workbookSelections.getSelectionsOfWorksheet(e);t&&(this._contextService.setContextValue(m.REF_SELECTIONS_ENABLED,!1),this._commandService.syncExecuteCommand(m.SetSelectionsOperation.id,{unitId:this._editingUnit,subUnitId:e,selections:t}))}async _handleEditorInvisible(e){var p,C;const t=this._editorBridgeService.getEditCellState(),i=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),r=a.Tools.deepClone(i==null?void 0:i.getSnapshot()),{keycode:s}=e;this._cursorChange=0;const l=(p=t==null?void 0:t.unitId)!=null?p:"";if(this._exitInput(e),t==null)return;const c=this._univerInstanceService.getUnit(l,a.UniverInstanceType.UNIVER_SHEET);if(!c)return;const d=c.getActiveSheet(),u=c.getUnitId(),h=d.getSheetId(),{unitId:g,sheetId:S}=t;if(u===g&&S!==h&&await this._commandService.executeCommand(m.SetWorksheetActivateCommand.id,{subUnitId:S,unitId:g}),s===I.KeyCode.ESC){this._editorBridgeService.isForceKeepVisible()&&this._editorBridgeService.disableForceKeepVisible(),this._refreshCurrentSelections(S);return}const f=((C=r==null?void 0:r.body)==null?void 0:C.dataStream.length)===2,v=t.documentLayoutObject.documentModel?this._isCellImageData(t.documentLayoutObject.documentModel.getSnapshot()):!1;r&&!(f&&v)&&await this._submitEdit(r,s===(I.MetaKeys.CTRL_COMMAND|I.KeyCode.ENTER)||s===(I.MetaKeys.MAC_CTRL|I.KeyCode.ENTER))===!1||s!==void 0&&this._moveSelection(s,l,h)}_getEditorObject(){return Wi(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}_isCellImageData(e){var i,r;return((r=(i=e.drawingsOrder)==null?void 0:i.length)!=null?r:0)>0}submitCellData(e){return this._submitEdit(e.getSnapshot())}async _submitEdit(e,t=!1){var C;const i=this._editorBridgeService.getEditCellState();if(i==null)return!0;const{unitId:r,sheetId:s,row:l,column:c}=i,d=this._univerInstanceService.getUnit(r,a.UniverInstanceType.UNIVER_SHEET);if(!d)return!0;let u=d.getActiveSheet();if(!d.getSheetBySheetId(s))return!0;u=d.getActiveSheet();const g=Rm({...u.getCellRaw(l,c)||{}},e,this._lexerTreeBuilder,this._localService,this._functionService,d.getStyles());if(!g)return!0;this._removeComposedCellStyleInCellData(g,u.getComposedCellStyle(l,c));const S=this._sheetInterceptorService.onWriteCell(d,u,l,c,g);if(a.Tools.diffValue(vl(S),vl(u.getCellRaw(l,c))))return!0;const f=t?(C=this._workbookSelections.getCurrentLastSelection())==null?void 0:C.range:{startRow:l,startColumn:c,endRow:l,endColumn:c},v=a.generateRandomId(6);return this._commandService.syncExecuteCommand(m.SetRangeValuesCommand.id,{subUnitId:s,unitId:r,range:f,value:S,redoUndoId:v})&&await this._sheetInterceptorService.onValidateCell(d,u,l,c)===!1?(this._undoRedoService.rollback(v,r),!1):!0}_removeComposedCellStyleInCellData(e,t){if(!e.s||typeof e.s=="string")return;const i=Object.keys(e.s);for(const r of i)t[r]!==void 0&&a.Tools.diffValue(e.s[r],t[r])&&delete e.s[r]}_exitInput(e){var r,s;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();(r=t==null?void 0:t.scene.getViewport(K.VIEWPORT_KEY.VIEW_MAIN))==null||r.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});const i=this._editorBridgeService.getCurrentEditorId();i==null||!this._editorService.isSheetEditor(i)||(i===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&((s=this._getEditorSkeleton(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null||s.resetInitialWidth()),this._undoRedoService.clearUndoRedo(i),this._undoRedoService.clearUndoRedo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))}_moveSelection(e,t,i){if(e==null||!mm.includes(e)){this._refreshCurrentSelections(i);return}let r=a.Direction.LEFT;switch(e){case I.KeyCode.ENTER:r=a.Direction.DOWN;break;case I.KeyCode.TAB:r=a.Direction.RIGHT;break;case I.KeyCode.ARROW_DOWN:r=a.Direction.DOWN;break;case I.KeyCode.ARROW_UP:r=a.Direction.UP;break;case I.KeyCode.ARROW_LEFT:r=a.Direction.LEFT;break;case I.KeyCode.ARROW_RIGHT:r=a.Direction.RIGHT;break}const s=this._univerInstanceService.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET);t&&(s==null?void 0:s.getUnitId())!==t&&this._univerInstanceService.setCurrentUnitForType(t),e===I.KeyCode.ENTER||e===I.KeyCode.TAB?this._commandService.executeCommand(ze.id,{keycode:e,direction:r}):this._commandService.executeCommand(Pe.id,{direction:r})}_cursorStateListener(e){const t=this._getEditorObject();if(!(t!=null&&t.document))return;const{document:i}=t;e.add(a.toDisposable(i.onPointerDown$.subscribeEvent(()=>{this._cursorChange===1&&(this._cursorChange=2)})))}_moveInEditor(e,t){let i=a.Direction.LEFT;e===I.KeyCode.ARROW_DOWN?i=a.Direction.DOWN:e===I.KeyCode.ARROW_UP?i=a.Direction.UP:e===I.KeyCode.ARROW_RIGHT&&(i=a.Direction.RIGHT),t?this._commandService.executeCommand(K.MoveSelectionOperation.id,{direction:i}):this._commandService.executeCommand(K.MoveCursorOperation.id,{direction:i})}_getDocumentDataModel(){return this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC)}_getEditorSkeleton(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(Ce.DocSkeletonManagerService).getSkeleton()}_getEditorViewModel(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(Ce.DocSkeletonManagerService).getViewModel()}_getEditingUnit(){return this._editingUnit?this._univerInstanceService.getUnit(this._editingUnit,a.UniverInstanceType.UNIVER_SHEET):null}_emptyDocumentDataModel(e,t){const i=(l,c)=>{const d=a.Tools.deepClone(l.getSnapshot()),u=this._getEditorViewModel(l.getUnitId());u!=null&&(Mm(d.body,t),c&&(d.documentStyle=e),d.drawings={},d.drawingsOrder=[],l.reset(d),u.reset(l))},r=this._getDocumentDataModel();r&&i(r,!0);const s=this._univerInstanceService.getUnit(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);s&&i(s)}},T.EditingRenderController=ym([ye(0,a.IUndoRedoService),ye(1,a.IContextService),ye(2,M.IRenderManagerService),ye(3,me),ye(4,bn),ye(5,a.Inject(q.LexerTreeBuilder)),ye(6,q.IFunctionService),ye(7,a.Inject(Ce.DocSelectionManagerService)),ye(8,a.ICommandService),ye(9,a.Inject(a.LocaleService)),ye(10,K.IEditorService),ye(11,a.IUniverInstanceService),ye(12,a.Inject(m.SheetInterceptorService)),ye(13,a.Inject(T.SheetCellEditorResizeService)),ye(14,a.Inject(m.SheetsSelectionsService))],T.EditingRenderController);function Rm(n,o,e,t,i,r){var h,g,S;if((o==null?void 0:o.body)==null)return null;const{body:s}=o;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=pm(d,e,u,i),(h=o.drawingsOrder)!=null&&h.length)n.v="",n.f=null,n.si=null,n.p=o,n.t=a.CellValueType.STRING;else if(n.s&&a.isTextFormat((S=(g=r==null?void 0:r.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,Dr(s)&&s.dataStream!==`\r
10
10
  `&&(n.p=o);const f=fl(o);f&&(n.s=f)}else if(a.isFormulaString(d)){if(n.f===d)return null;const f=e.checkIfAddBracket(d);for(let v=0;v<f;v++)d+=q.matchToken.CLOSE_BRACKET;n.f=d,n.si=null,n.v=null,n.p=null}else if(gm(d)){const f=Sm(d);n.v=f,n.f=null,n.si=null,n.p=null,n.t=a.CellValueType.FORCE_STRING}else if(Dr(s))s.dataStream===`\r
11
11
  `?(n.v="",n.f=null,n.si=null,n.p=null):(n.p=o,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=fl(o);f&&(n.s=f)}return n}function Dr(n){const{textRuns:o=[],paragraphs:e=[],customRanges:t,customBlocks:i=[]}=n,r=n.dataStream.replace(/(\r\n)+$/,""),s=["va"];return o.filter(l=>l.st<r.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<r.length})||e.some(l=>l.bullet)||e.length>=2||!!(t!=null&&t.length)||i.length>0}function fl(n){const{body:o}=n;if(!o)return null;const{textRuns:e=[]}=o;let t={};const i=o.dataStream.replace(`\r
12
- `,"");return e.forEach(r=>{const{st:s,ed:l,ts:c}=r;l-s>=i.length&&(t={...t,...c})}),Object.keys(t).length?t:null}function Mm(n,o=!1){n.dataStream=a.DEFAULT_EMPTY_DOCUMENT_VALUE,n.textRuns!=null&&(n.textRuns.length===1&&!o?(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)}function vl(n){return n&&Object.fromEntries(Object.entries(n).filter(([o,e])=>!(e==null||Array.isArray(e)&&e.length===0||typeof e=="object"&&Object.keys(e).length===0)))}var Pm=Object.getOwnPropertyDescriptor,Om=(n,o,e,t)=>{for(var i=t>1?void 0:t?Pm(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},et=(n,o)=>(e,t)=>o(e,t,n);T.FormulaEditorController=class extends a.RxDisposable{constructor(e,t,i,r,s,l,c,d,u){super();y(this,"_loadedMap",new WeakSet);y(this,"_scheduledCallback",-1);this._univerInstanceService=e,this._renderManagerService=t,this._editorBridgeService=i,this._commandService=r,this._contextService=s,this._formulaEditorManagerService=l,this._undoRedoService=c,this._textSelectionManagerService=d,this._editorService=u,this._initialize()}_initialize(){this._syncEditorSize(),this._listenFxBtnClick(),this._handleContentChange(),this._univerInstanceService.focused$.pipe(D.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)}),this._create(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),this.disposeWithMe(this._editorService.focus$.subscribe(()=>{var t;((t=this._editorService.getFocusEditor())==null?void 0:t.getEditorId())!==a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY?this._contextService.setContextValue(a.FOCUSING_FX_BAR_EDITOR,!1):this._contextService.setContextValue(a.FOCUSING_FX_BAR_EDITOR,!0)}))}_handleContentChange(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===Ce.RichTextEditingMutation.id){const t=e.params,{unitId:i}=t;i===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&this.autoScroll()}}))}_create(e){if(e!==a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;const t=this._renderManagerService.getRenderById(e);if(t==null)return;const{mainComponent:i}=t;i!=null&&(this._loadedMap.has(i)||this._loadedMap.add(i))}_listenFxBtnClick(){this._formulaEditorManagerService.fxBtnClick$.pipe(D.takeUntil(this.dispose$)).subscribe(()=>{var t;if(this._contextService.getContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN)&&!this._contextService.getContextValue(a.EDITOR_ACTIVATED)){this._univerInstanceService.setCurrentUnitForType(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);const i=this._univerInstanceService.getUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);this._editorBridgeService.isVisible().visible===!1&&this._commandService.syncExecuteCommand(Se.id,{visible:!0,eventType:M.DeviceInputEventType.PointerDown,unitId:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY});const s=(t=i==null?void 0:i.getBody())==null?void 0:t.dataStream;if(s==null)return;let l=s.startsWith("=")?s:`=${s}`;l=l.replace(/\r\n$/,"");const c=[{startOffset:l.length,endOffset:l.length}],d={unitId:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,body:{dataStream:l},segmentId:"",textRanges:c};this._commandService.syncExecuteCommand(K.CoverContentCommand.id,d),requestAnimationFrame(()=>{this._textSelectionManagerService.replaceDocRanges([],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY}),this._textSelectionManagerService.replaceDocRanges(c,{unitId:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY}),this._contextService.setContextValue(a.FOCUSING_FX_BAR_EDITOR,!0)})}})}_syncEditorSize(){const e=this._univerInstanceService.unitAdded$.pipe(D.filter(t=>t.getUnitId()===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY));this.disposeWithMe(D.combineLatest([this._formulaEditorManagerService.position$,e]).subscribe(([t])=>{if(!t)return this._clearScheduledCallback();const i=Wi(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,this._renderManagerService),r=this._univerInstanceService.getUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);if(i==null||r==null)return this._clearScheduledCallback();const{width:s,height:l}=t;if(s===0||l===0)return this._clearScheduledCallback();const{engine:c}=i;r.updateDocumentDataPageSize(s),this.autoScroll(),this._scheduledCallback=requestIdleCallback(()=>c.resizeBySize(s,l))}))}_clearScheduledCallback(){this._scheduledCallback!==-1&&cancelIdleCallback(this._scheduledCallback),this._scheduledCallback=-1}autoScroll(){var v,p;const e=this._formulaEditorManagerService.getPosition(),t=(v=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:v.with(Ce.DocSkeletonManagerService).getSkeleton(),i=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),r=this._univerInstanceService.getUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);if(t==null||e==null||i==null||r==null)return;const{marginTop:s=0,marginBottom:l=0}=r.getSnapshot().documentStyle,{scene:c,mainComponent:d}=i;let{actualHeight:u}=t.getActualSize();u+=s+l;const{width:h,height:g}=e,S=c.getViewport(K.VIEWPORT_KEY.VIEW_MAIN);let f=S==null?void 0:S.getScrollBar();c.transformByState({width:h,height:u}),d==null||d.resize(h,u),u>g?f==null?S&&new M.ScrollBar(S,{enableHorizontal:!1,barSize:8}):S==null||S.resetCanvasSizeAndUpdateScroll():(f=null,S==null||S.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0}),(p=S==null?void 0:S.getScrollBar())==null||p.dispose())}},T.FormulaEditorController=Om([et(0,a.IUniverInstanceService),et(1,M.IRenderManagerService),et(2,me),et(3,a.ICommandService),et(4,a.IContextService),et(5,En),et(6,a.IUndoRedoService),et(7,a.Inject(Ce.DocSelectionManagerService)),et(8,K.IEditorService)],T.FormulaEditorController);const pl="embedding_formula_editor",Am=n=>n.includes(pl),kr=(n,o)=>{var h,g,S,f,v;const t=o.findNodePositionByCharIndex(n.startOffset,!0,n.segmentId,-1),i=o.getSkeletonData();let r=n.endOffset;if(n.segmentId){const p=(v=Array.from((g=(h=i==null?void 0:i.skeFooters.get(n.segmentId))==null?void 0:h.values())!=null?g:[])[0])!=null?v:Array.from((f=(S=i==null?void 0:i.skeHeaders.get(n.segmentId))==null?void 0:S.values())!=null?f:[])[0];p&&(r=Math.min(p.ed,r))}const s=o.findNodePositionByCharIndex(r,!0,n.segmentId,-1);if(!s||!t)return;const l={docsLeft:0,docsTop:0,pageMarginLeft:0,pageMarginTop:0},c=new K.NodePositionConvertToCursor(l,o),{borderBoxPointGroup:d}=c.getRangePointData(t,s);return K.getLineBounding(d).map(p=>({top:p.top,bottom:p.bottom,left:p.left,right:p.right}))},Dm=(n,o,e=-1)=>{const t=o.findPositionByGlyph(n,e);if(!t)return;const i={...t,isBack:!0},r={docsLeft:0,docsTop:0,pageMarginLeft:0,pageMarginTop:0},s=new K.NodePositionConvertToCursor(r,o),{borderBoxPointGroup:l}=s.getRangePointData(i,i),d=K.getLineBounding(l)[0];return{top:d.top,bottom:d.bottom,left:d.left,right:d.right}},km=(n,o,e=0,t=0)=>{const i=kr({startOffset:o.startIndex,endOffset:o.endIndex+1},n);if(i)return{rects:i.map(r=>({top:r.top+t,bottom:r.bottom+t,left:r.left+e,right:r.right+e})),range:o}},Nm=(n,o,e=0,t=0)=>{var h,g,S;const i=n.findNodeByCharIndex(o.startIndex),r=i==null?void 0:i.parent,s=r==null?void 0:r.parent,l=s==null?void 0:s.parent,c=l==null?void 0:l.lines.find(f=>f.paragraphStart&&f.paragraphIndex===o.startIndex),d=(S=(g=(h=c==null?void 0:c.divides)==null?void 0:h[0])==null?void 0:g.glyphGroup)==null?void 0:S[0];if(!d||!d)return;const u=Dm(d,n);if(u)return{rect:{top:u.top+t,bottom:u.bottom+t,left:u.left+e,right:u.right+e},segmentId:void 0,segmentPageIndex:-1,paragraph:o}},Cl=(n,o=0,e=0)=>{var l,c,d,u,h,g,S;const t=n.getViewModel().getDataModel(),i=(d=(c=(l=t.getBody())==null?void 0:l.customRanges)==null?void 0:c.filter(f=>f.rangeType===a.CustomRangeType.HYPERLINK))!=null?d:[],r=(g=(h=(u=t.getBody())==null?void 0:u.paragraphs)==null?void 0:h.filter(f=>{var v;return((v=f.bullet)==null?void 0:v.listType.indexOf(a.PresetListType.CHECK_LIST))===0}))!=null?g:[],s=(S=n.getSkeletonData())==null?void 0:S.pages[0].skeDrawings;return{links:i.map(f=>km(n,f,o,e)).filter(Boolean),checkLists:r.map(f=>Nm(n,f,o,e)).filter(Boolean),drawings:s?Array.from(s.keys()).map(f=>({drawingId:f,rect:{top:s.get(f).aTop,bottom:s.get(f).aTop+s.get(f).width,left:s.get(f).aLeft,right:s.get(f).aLeft+s.get(f).height},drawing:s.get(f)})):[]}};function Il(n,o,e){var d,u,h,g,S,f;const t=(h=(u=(d=o.documentSkeleton)==null?void 0:d.getSkeletonData())==null?void 0:u.pages[0].height)!=null?h:0,i=(f=(S=(g=o.documentSkeleton)==null?void 0:g.getSkeletonData())==null?void 0:S.pages[0].width)!=null?f:0,r=o.verticalAlign,s=o.horizontalAlign;let l=0;switch(r){case a.VerticalAlign.UNSPECIFIED:case a.VerticalAlign.BOTTOM:l=n.mergeInfo.endY-n.mergeInfo.startY-t;break;case a.VerticalAlign.MIDDLE:l=(n.mergeInfo.endY-n.mergeInfo.startY-t)/2;break}let c=0;switch(s){case a.HorizontalAlign.RIGHT:c=n.mergeInfo.endX-n.mergeInfo.startX-i;break;case a.HorizontalAlign.CENTER:c=(n.mergeInfo.endX-n.mergeInfo.startX-i)/2;break;case a.HorizontalAlign.UNSPECIFIED:{e&&(c=n.mergeInfo.endX-n.mergeInfo.startX-i);break}}return{paddingLeft:c,paddingTop:l}}const Vm=(n,o,e,t,i,r)=>{var V,L,H;const s=n.get(a.IUniverInstanceService),l=n.get(M.IRenderManagerService),c=s.getUnit(o,a.UniverInstanceType.UNIVER_SHEET);if(!c)return null;const d=c.getSheetBySheetId(e);if(!d)return null;const u=l.getRenderById(c.getUnitId()),h=u==null?void 0:u.with(T.SheetSkeletonManagerService).getSkeletonParam(d.getSheetId()),g=h==null?void 0:h.skeleton;if(!g||!u)return;const S=g.getFont(t,i),f=S==null?void 0:S.documentSkeleton;if(!f)return null;const v=(L=(V=f.getViewModel().getBody())==null?void 0:V.customRanges)==null?void 0:L.find(W=>W.rangeId===r);if(!v)return null;const p=K.DOC_VERTICAL_PADDING,C=g.getCellWithCoordByIndex(t,i);let{actualColumn:_,actualRow:w}=C;g.overflowCache.forValue((W,B,U)=>{U.startRow<=w&&U.endRow>=w&&U.startColumn<=_&&U.endColumn>=_&&(_=B,w=W)});const E=g.getCellWithCoordByIndex(w,_),O=d.getCell(E.actualRow,E.actualColumn),{topOffset:R=0,leftOffset:P=0}=(H=O==null?void 0:O.fontRenderExtension)!=null?H:{},{paddingLeft:A,paddingTop:k}=Il(E,S,!1),N=kr({startOffset:v.startIndex,endOffset:v.endIndex},f);return{rects:N==null?void 0:N.map(W=>({top:W.top+E.mergeInfo.startY+k+R+p,bottom:W.bottom+E.mergeInfo.startY+k+R+p,left:W.left+E.mergeInfo.startX+A+P,right:W.right+E.mergeInfo.startX+A+P})),customRange:v,label:f.getViewModel().getBody().dataStream.slice(v.startIndex,v.endIndex+1)}},Hm=(n,o,e,t,i,r)=>{var P,A,k;const s=n.get(me),l=s.getEditCellState();if(!l||!s.isVisible().visible)return null;const{editorUnitId:d,unitId:u,sheetId:h,row:g,column:S}=l;if(o!==u||e!==h||g!==t||S!==i)return null;const f=n.get(M.IRenderManagerService),v=f.getRenderById(d),p=f.getRenderById(o);if(!v||!p)return null;const C=v.with(Ce.DocSkeletonManagerService).getSkeleton(),_=(P=p.with(T.SheetSkeletonManagerService).getSkeletonParam(h))==null?void 0:P.skeleton;if(!C||!_)return null;const w=(k=(A=C.getViewModel().getBody())==null?void 0:A.customRanges)==null?void 0:k.find(N=>N.rangeId===r);if(!w)return null;const E=4,O=kr({startOffset:w.startIndex,endOffset:w.endIndex},C),R=v.engine.getCanvasElement().getBoundingClientRect();return{rects:O==null?void 0:O.map(N=>({top:N.top+R.top-E,bottom:N.bottom+R.top+E,left:N.left+R.left,right:N.right+R.left})),customRange:w,label:C.getViewModel().getBody().dataStream.slice(w.startIndex,w.endIndex+1)}};var Wm=Object.getOwnPropertyDescriptor,Lm=(n,o,e,t)=>{for(var i=t>1?void 0:t?Wm(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},_l=(n,o)=>(e,t)=>o(e,t,n);function zt(n){const{workbook:o,worksheet:e,...t}=n;return t}T.HoverManagerService=class extends a.Disposable{constructor(e,t){super();y(this,"_currentCell$",new D.BehaviorSubject(null));y(this,"_currentRichText$",new D.BehaviorSubject(null));y(this,"_currentClickedCell$",new D.Subject);y(this,"_currentDbClickedCell$",new D.Subject);y(this,"_currentCellWithEvent$",new D.Subject);y(this,"_currentPointerDownCell$",new D.Subject);y(this,"_currentPointerUpCell$",new D.Subject);y(this,"_currentHoveredRowHeader$",new D.BehaviorSubject(null));y(this,"_currentHoveredColHeader$",new D.BehaviorSubject(null));y(this,"_currentRowHeaderClick$",new D.Subject);y(this,"_currentColHeaderClick$",new D.Subject);y(this,"_currentRowHeaderDbClick$",new D.Subject);y(this,"_currentColHeaderDbClick$",new D.Subject);y(this,"_currentRowHeaderPointerDown$",new D.Subject);y(this,"_currentColHeaderPointerDown$",new D.Subject);y(this,"_currentRowHeaderPointerUp$",new D.Subject);y(this,"_currentColHeaderPointerUp$",new D.Subject);y(this,"currentCell$",this._currentCell$.asObservable().pipe(D.distinctUntilChanged((e,t)=>{var i,r,s,l,c,d,u,h;return((i=e==null?void 0:e.location)==null?void 0:i.unitId)===((r=t==null?void 0:t.location)==null?void 0:r.unitId)&&((s=e==null?void 0:e.location)==null?void 0:s.subUnitId)===((l=t==null?void 0:t.location)==null?void 0:l.subUnitId)&&((c=e==null?void 0:e.location)==null?void 0:c.row)===((d=t==null?void 0:t.location)==null?void 0:d.row)&&((u=e==null?void 0:e.location)==null?void 0:u.col)===((h=t==null?void 0:t.location)==null?void 0:h.col)})));y(this,"currentRichTextNoDistinct$",this._currentRichText$.pipe(D.map(e=>e&&{unitId:e.location.unitId,subUnitId:e.location.subUnitId,row:e.location.row,col:e.location.col,customRange:e.customRange,bullet:e.bullet,rect:e.rect,drawing:e.drawing})));y(this,"currentRichText$",this._currentRichText$.pipe(D.distinctUntilChanged((e,t)=>{var i,r,s,l,c,d,u,h,g,S,f,v,p,C,_,w,E,O;return((i=e==null?void 0:e.location)==null?void 0:i.unitId)===((r=t==null?void 0:t.location)==null?void 0:r.unitId)&&((s=e==null?void 0:e.location)==null?void 0:s.subUnitId)===((l=t==null?void 0:t.location)==null?void 0:l.subUnitId)&&((c=e==null?void 0:e.location)==null?void 0:c.row)===((d=t==null?void 0:t.location)==null?void 0:d.row)&&((u=e==null?void 0:e.location)==null?void 0:u.col)===((h=t==null?void 0:t.location)==null?void 0:h.col)&&((g=e==null?void 0:e.customRange)==null?void 0:g.rangeId)===((S=t==null?void 0:t.customRange)==null?void 0:S.rangeId)&&((f=e==null?void 0:e.bullet)==null?void 0:f.startIndex)===((v=t==null?void 0:t.bullet)==null?void 0:v.startIndex)&&((p=e==null?void 0:e.customRange)==null?void 0:p.startIndex)===((C=t==null?void 0:t.customRange)==null?void 0:C.startIndex)&&((_=e==null?void 0:e.customRange)==null?void 0:_.endIndex)===((w=t==null?void 0:t.customRange)==null?void 0:w.endIndex)&&((E=e==null?void 0:e.drawing)==null?void 0:E.drawingId)===((O=t==null?void 0:t.drawing)==null?void 0:O.drawingId)}),D.map(e=>e&&{unitId:e.location.unitId,subUnitId:e.location.subUnitId,row:e.location.row,col:e.location.col,customRange:e.customRange,bullet:e.bullet,rect:e.rect,drawing:e.drawing})));y(this,"currentCellPosWithEvent$",this._currentCellWithEvent$.pipe(D.distinctUntilChanged((e,t)=>{var i,r,s,l,c,d,u,h;return((i=e==null?void 0:e.location)==null?void 0:i.unitId)===((r=t==null?void 0:t.location)==null?void 0:r.unitId)&&((s=e==null?void 0:e.location)==null?void 0:s.subUnitId)===((l=t==null?void 0:t.location)==null?void 0:l.subUnitId)&&((c=e==null?void 0:e.location)==null?void 0:c.row)===((d=t==null?void 0:t.location)==null?void 0:d.row)&&((u=e==null?void 0:e.location)==null?void 0:u.col)===((h=t==null?void 0:t.location)==null?void 0:h.col)}),D.map(e=>e&&{unitId:e.location.unitId,subUnitId:e.location.subUnitId,row:e.location.row,col:e.location.col,event:e.event})));y(this,"currentPosition$",this._currentCell$.asObservable());y(this,"currentClickedCell$",this._currentClickedCell$.asObservable());y(this,"currentDbClickedCell$",this._currentDbClickedCell$.asObservable());y(this,"currentPointerDownCell$",this._currentPointerDownCell$.asObservable());y(this,"currentPointerUpCell$",this._currentPointerUpCell$.asObservable());y(this,"currentHoveredRowHeader$",this._currentHoveredRowHeader$.asObservable());y(this,"currentHoveredColHeader$",this._currentHoveredColHeader$.asObservable());y(this,"currentRowHeaderClick$",this._currentRowHeaderClick$.asObservable());y(this,"currentColHeaderClick$",this._currentColHeaderClick$.asObservable());y(this,"currentRowHeaderDbClick$",this._currentRowHeaderDbClick$.asObservable());y(this,"currentColHeaderDbClick$",this._currentColHeaderDbClick$.asObservable());y(this,"currentRowHeaderPointerDown$",this._currentRowHeaderPointerDown$.asObservable());y(this,"currentColHeaderPointerDown$",this._currentColHeaderPointerDown$.asObservable());y(this,"currentRowHeaderPointerUp$",this._currentRowHeaderPointerUp$.asObservable());y(this,"currentColHeaderPointerUp$",this._currentColHeaderPointerUp$.asObservable());this._univerInstanceService=e,this._renderManagerService=t,this._initCellDisposableListener()}dispose(){super.dispose(),this._currentCell$.complete(),this._currentClickedCell$.complete(),this._currentPointerDownCell$.complete(),this._currentPointerUpCell$.complete(),this._currentCellWithEvent$.complete(),this._currentRichText$.complete(),this._currentDbClickedCell$.complete(),this._currentHoveredRowHeader$.complete(),this._currentHoveredColHeader$.complete(),this._currentRowHeaderClick$.complete(),this._currentColHeaderClick$.complete(),this._currentRowHeaderDbClick$.complete(),this._currentColHeaderDbClick$.complete(),this._currentRowHeaderPointerDown$.complete(),this._currentColHeaderPointerDown$.complete(),this._currentRowHeaderPointerUp$.complete(),this._currentColHeaderPointerUp$.complete(),this.currentCellPosWithEvent$=D.of(null),this.currentRichText$=D.of(null)}_initCellDisposableListener(){this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(e=>{e||this._currentCell$.next(null)})),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(e=>{var t,i;((t=this._currentCell$.getValue())==null?void 0:t.location.unitId)===e.getUnitId()&&this._currentCell$.next(null),((i=this._currentRichText$.getValue())==null?void 0:i.location.unitId)===e.getUnitId()&&this._currentRichText$.next(null)}))}_getCalcDeps(e){const t=this._univerInstanceService.getUnit(e,a.UniverInstanceType.UNIVER_SHEET);if(!t)return null;const i=t.getActiveSheet();if(!i)return null;const r=this._renderManagerService.getRenderById(t.getUnitId());if(!r)return null;const s=r.with(T.SheetSkeletonManagerService).getSkeletonParam(i.getSheetId());if(!s)return null;const l=r.with(T.SheetScrollManagerService);if(!(!(l!=null&&l.getCurrentScrollState())||!r))return{currentRender:r,workbook:t,worksheet:i,skeletonParam:s}}_calcActiveCell(e,t,i,r,s,l){var P,A,k;const c=Ra(e,t,i,r,s,l),d=r.skeleton;if(!c)return null;const{position:u,overflowLocation:h,location:g}=c,S=d.getFont(h.row,h.col);let f=null,v=null,p=null;const C=d.getCellWithCoordByIndex(h.row,h.col),_=i.getCell(h.row,h.col),{topOffset:w=0,leftOffset:E=0}=(P=_==null?void 0:_.fontRenderExtension)!=null?P:{};if(S!=null&&S.documentSkeleton){const{paddingLeft:N,paddingTop:V}=Il(C,S,(_==null?void 0:_.v)!==null&&(_==null?void 0:_.v)!==void 0?!Number.isNaN(+_.v):!1),L=Cl(S.documentSkeleton,N,V),H=s-u.startX-E,W=l-u.startY-w;f=L.links.find(B=>B.rects.some(U=>U.left<=H&&H<=U.right&&U.top<=W&&W<=U.bottom)),v=L.checkLists.find(B=>B.rect.left<=H&&H<=B.rect.right&&B.rect.top<=W&&W<=B.rect.bottom),p=L.drawings.find(B=>B.rect.left<=H&&H<=B.rect.right&&B.rect.top<=W&&W<=B.rect.bottom)}const O=(k=(A=f==null?void 0:f.rects.pop())!=null?A:v==null?void 0:v.rect)!=null?k:p==null?void 0:p.rect,R=O&&(()=>{const N=O.top+C.mergeInfo.startY+w,V=O.bottom+C.mergeInfo.startY+w,L=O.left+C.mergeInfo.startX+E,H=O.right+C.mergeInfo.startX+E,W=C.mergeInfo.startY+w,B=C.mergeInfo.endY+w,U=C.mergeInfo.startX+E,X=C.mergeInfo.endX+E,F=Math.min(Math.max(N,W),W),Y=Math.min(V,B),j=Math.min(Math.max(L,U),U),Q=Math.min(H,X);return{top:F,bottom:Y,left:j,right:Q}})();return{location:g,position:u,overflowLocation:h,customRange:f==null?void 0:f.range,bullet:v==null?void 0:v.paragraph,drawing:p,rect:R}}_calcActiveRowHeader(e,t,i){const r=this._getCalcDeps(e);if(!r)return;const{currentRender:s,worksheet:l,skeletonParam:c}=r,{scaleY:d}=s.scene.getAncestorScale(),u=s.scene.getViewports().find(S=>S.isHit(new M.Vector2(t,i)));if(!u||u.viewportKey!==M.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP&&u.viewportKey!==M.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM)return;const h={x:u.viewportScrollX,y:u.viewportScrollY},g=c.skeleton.getRowIndexByOffsetY(i,d,h);return{unitId:e,index:g,subUnitId:l.getSheetId()}}_calcActiveColHeader(e,t,i){const r=this._getCalcDeps(e);if(!r)return;const{currentRender:s,worksheet:l,skeletonParam:c}=r,{scaleX:d}=s.scene.getAncestorScale(),u=s.scene.getViewports().find(S=>S.isHit(new M.Vector2(t,i)));if(!u||u.viewportKey!==M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT&&u.viewportKey!==M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT)return;const h={x:u.viewportScrollX,y:u.viewportScrollY},g=c.skeleton.getColumnIndexByOffsetX(t,d,h);return{unitId:e,index:g,subUnitId:l.getSheetId()}}triggerPointerDown(e,t){const i=this._getCalcDeps(e);if(!i)return;const{currentRender:r,workbook:s,worksheet:l,skeletonParam:c}=i,d=this._calcActiveCell(r,s,l,c,t.offsetX,t.offsetY);if(d&&d.location){const{unitId:u,subUnitId:h,row:g,col:S}=zt(d.location);this._currentPointerDownCell$.next({unitId:u,subUnitId:h,row:g,col:S,event:t})}}triggerPointerUp(e,t){const i=this._getCalcDeps(e);if(!i)return;const{currentRender:r,workbook:s,worksheet:l,skeletonParam:c}=i,d=this._calcActiveCell(r,s,l,c,t.offsetX,t.offsetY);if(d){const u=zt(d.location);this._currentPointerUpCell$.next({...u,event:t})}}triggerMouseMove(e,t){const i=this._getCalcDeps(e);if(!i)return;const{currentRender:r,workbook:s,worksheet:l,skeletonParam:c}=i,d=this._calcActiveCell(r,s,l,c,t.offsetX,t.offsetY);this._currentCell$.next(d&&{location:zt(d.location),position:d.position}),this._currentRichText$.next(d&&{...d,location:zt(d.overflowLocation)}),this._currentCellWithEvent$.next(d&&{...d,location:zt(d.location),event:t})}triggerClick(e,t,i){const r=this._getCalcDeps(e);if(!r)return;const{currentRender:s,workbook:l,worksheet:c,skeletonParam:d}=r,u=this._calcActiveCell(s,l,c,d,t,i);u&&this._currentClickedCell$.next({...u,location:zt(u.location)})}triggerDbClick(e,t,i){const r=this._getCalcDeps(e);if(!r)return;const{currentRender:s,workbook:l,worksheet:c,skeletonParam:d}=r,u=this._calcActiveCell(s,l,c,d,t,i);u&&this._currentDbClickedCell$.next({...u,location:zt(u.location)})}triggerScroll(){this._currentCell$.next(null)}triggerRowHeaderClick(e,t,i){const r=this._calcActiveRowHeader(e,t,i);r&&this._currentRowHeaderClick$.next(r)}triggerColHeaderClick(e,t,i){const r=this._calcActiveColHeader(e,t,i);r&&this._currentColHeaderClick$.next(r)}triggerRowHeaderDbClick(e,t,i){const r=this._calcActiveRowHeader(e,t,i);r&&this._currentRowHeaderDbClick$.next(r)}triggerColHeaderDbClick(e,t,i){const r=this._calcActiveColHeader(e,t,i);r&&this._currentColHeaderDbClick$.next(r)}triggerRowHeaderMouseMove(e,t,i){this._currentHoveredRowHeader$.next(this._calcActiveRowHeader(e,t,i))}triggerColHeaderMouseMove(e,t,i){this._currentHoveredColHeader$.next(this._calcActiveColHeader(e,t,i))}triggerRowHeaderPoniterDown(e,t,i){const r=this._calcActiveRowHeader(e,t,i);r&&this._currentRowHeaderPointerDown$.next(r)}triggerColHeaderPoniterDown(e,t,i){const r=this._calcActiveColHeader(e,t,i);r&&this._currentColHeaderPointerDown$.next(r)}triggerRowHeaderPoniterUp(e,t,i){const r=this._calcActiveRowHeader(e,t,i);r&&this._currentRowHeaderPointerUp$.next(r)}triggerColHeaderPoniterUp(e,t,i){const r=this._calcActiveColHeader(e,t,i);r&&this._currentColHeaderPointerUp$.next(r)}},T.HoverManagerService=Lm([_l(0,a.IUniverInstanceService),_l(1,M.IRenderManagerService)],T.HoverManagerService);var xm=Object.getOwnPropertyDescriptor,Um=(n,o,e,t)=>{for(var i=t>1?void 0:t?xm(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},Nr=(n,o)=>(e,t)=>o(e,t,n);T.HoverRenderController=class extends a.Disposable{constructor(e,t,i,r){super();y(this,"_active",!1);this._context=e,this._hoverManagerService=t,this._sheetSkeletonManagerService=i,this._scrollManagerService=r,this._initPointerEvent(),this._initScrollEvent()}get active(){return this._active}_initPointerEvent(){const e=new a.DisposableCollection,t=i=>{if(e.dispose(),!i)return;const{mainComponent:r,unitId:s,components:l}=this._context;if(!r)return;e.add(r.onPointerEnter$.subscribeEvent(u=>{this._active=!0})),e.add(a.fromEventSubject(r.onPointerMove$).subscribe(u=>{this._active=!0,this._hoverManagerService.triggerMouseMove(s,u)})),e.add(r.onPointerDown$.subscribeEvent(u=>{this._hoverManagerService.triggerPointerDown(s,u)})),e.add(r.onPointerUp$.subscribeEvent(u=>{this._hoverManagerService.triggerPointerUp(s,u)})),e.add(r.onClick$.subscribeEvent(u=>{this._hoverManagerService.triggerClick(s,u.offsetX,u.offsetY)})),e.add(r.onDblclick$.subscribeEvent(u=>{this._hoverManagerService.triggerDbClick(s,u.offsetX,u.offsetY)})),e.add(r.onPointerLeave$.subscribeEvent(()=>{this._active=!1}));const c=l.get(he.ROW),d=l.get(he.COLUMN);c&&(e.add(c.onPointerMove$.subscribeEvent(u=>{this._hoverManagerService.triggerRowHeaderMouseMove(s,u.offsetX,u.offsetY)})),e.add(c.onPointerDown$.subscribeEvent(u=>{this._hoverManagerService.triggerRowHeaderPoniterDown(s,u.offsetX,u.offsetY)})),e.add(c.onPointerUp$.subscribeEvent(u=>{this._hoverManagerService.triggerRowHeaderPoniterUp(s,u.offsetX,u.offsetY),this._hoverManagerService.triggerRowHeaderClick(s,u.offsetX,u.offsetY)})),e.add(c.onDblclick$.subscribeEvent(u=>{this._hoverManagerService.triggerRowHeaderDbClick(s,u.offsetX,u.offsetY)}))),d&&(e.add(d.onPointerMove$.subscribeEvent(u=>{this._hoverManagerService.triggerColHeaderMouseMove(s,u.offsetX,u.offsetY)})),e.add(d.onPointerDown$.subscribeEvent(u=>{this._hoverManagerService.triggerColHeaderPoniterDown(s,u.offsetX,u.offsetY)})),e.add(d.onPointerUp$.subscribeEvent(u=>{this._hoverManagerService.triggerColHeaderPoniterUp(s,u.offsetX,u.offsetY),this._hoverManagerService.triggerColHeaderClick(s,u.offsetX,u.offsetY)})),e.add(d.onDblclick$.subscribeEvent(u=>{this._hoverManagerService.triggerColHeaderDbClick(s,u.offsetX,u.offsetY)})))};t(this._sheetSkeletonManagerService.getCurrentParam()),this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{t(i)}))}_initScrollEvent(){this.disposeWithMe(this._scrollManagerService.validViewportScrollInfo$.subscribe(()=>this._hoverManagerService.triggerScroll()))}},T.HoverRenderController=Um([Nr(1,a.Inject(T.HoverManagerService)),Nr(2,a.Inject(T.SheetSkeletonManagerService)),Nr(3,a.Inject(T.SheetScrollManagerService))],T.HoverRenderController);const bl="UI_PLUGIN_SHEETS",Vr=`${bl}_BORDER_PANEL_COMPONENT`,wl=[{label:"borderLine.borderTop",icon:"UpBorderDoubleIcon",value:"top"},{label:"borderLine.borderBottom",icon:"DownBorderDoubleIcon",value:"bottom"},{label:"borderLine.borderLeft",icon:"LeftBorderDoubleIcon",value:"left"},{label:"borderLine.borderRight",icon:"RightBorderDoubleIcon",value:"right"},{label:"borderLine.borderNone",icon:"NoBorderIcon",value:"none"},{label:"borderLine.borderAll",icon:"AllBorderIcon",value:"all"},{label:"borderLine.borderOutside",icon:"OuterBorderDoubleIcon",value:"outside"},{label:"borderLine.borderInside",icon:"InnerBorderDoubleIcon",value:"inside"},{label:"borderLine.borderHorizontal",icon:"HorizontalBorderDoubleIcon",value:"horizontal"},{label:"borderLine.borderVertical",icon:"VerticalBorderDoubleIcon",value:"vertical"},{label:"borderLine.borderTlbr",icon:"BackSlashDoubleIcon",value:"tlbr"},{label:"borderLine.borderTlbcTlmr",icon:"LeftDoubleDiagonalDoubleIcon",value:"tlbc_tlmr"},{label:"borderLine.borderTlbrTlbcTlmr",icon:"LeftTridiagonalDoubleIcon",value:"tlbr_tlbc_tlmr"},{label:"borderLine.borderBlTr",icon:"SlashDoubleIcon",value:"bltr"},{label:"borderLine.borderMltrBctr",icon:"RightDoubleDiagonalDoubleIcon",value:"mltr_bctr"}];function Bm(n){return n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(de.switchMap(o=>o?o.activeSheet$.pipe(de.map(e=>e?{workbook:o,worksheet:e}:null)):D.of(null)))}function be(n,o,e){return Bm(n).pipe(de.switchMap(t=>t?e(t):D.of(o)))}function El(n,o){const e=n.get(a.IUniverInstanceService),t=n.get(m.IExclusiveRangeService),i=n.get(m.SheetsSelectionsService);return e.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(de.switchMap(s=>s?D.combineLatest([i.selectionMoveEnd$,s.activeSheet$]).pipe(de.switchMap(([l,c])=>{if(!c||l.length===0)return D.of(!1);const d=t.getInterestGroupId(l);if(o){const u=d.filter(h=>o.has(h));return D.of(u.length>0)}else return D.of(d.length>0)})):D.of(!1)))}function Xt(n,o,e){return D.combineLatest([o,El(n,e)]).pipe(de.map(([t,i])=>t||i))}function ee(n,o={},e=!1){var g;const i=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(a.UserManagerService),s=n.has(me)?n.get(me):null,l=n.get(a.IContextService),d=((g=s==null?void 0:s.visible$)!=null?g:D.of(null)).pipe(de.startWith(null),de.shareReplay(1)),u=l.subscribeContextValue$(a.FOCUSING_FX_BAR_EDITOR).pipe(de.startWith(!1),de.shareReplay(1));return D.combineLatest([r.currentUser$,i,d,u]).pipe(de.switchMap(([S,f,v,p])=>!f||v!=null&&v.visible&&v.unitId===f.getUnitId()&&!e||p&&!e?D.of(!0):f.activeSheet$.pipe(de.switchMap(C=>{if(!C)return D.of(!0);const _=n.get(m.SheetsSelectionsService),w=n.get(m.RangeProtectionRuleModel),E=n.get(m.WorksheetProtectionRuleModel),R=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_COMMON_DRAWINGS).pipe(de.startWith(!1));return D.combineLatest([_.selectionMoveEnd$,R]).pipe(de.switchMap(([P,A])=>{if(A)return D.of(!0);const k=f.getUnitId(),N=C.getSheetId(),V=n.get(a.IPermissionService),{workbookTypes:L=[m.WorkbookEditablePermission],worksheetTypes:H,rangeTypes:W}=o,B=[];if(L==null||L.forEach(Y=>{B.push(new Y(k).id)}),H==null||H.forEach(Y=>{B.push(new Y(k,N).id)}),E.getRule(k,N))return V.composePermission$(B).pipe(de.map(Y=>Y.some(j=>j.value===!1)));const X=P==null?void 0:P.map(Y=>Y.range),F=w.getSubunitRuleList(k,N).filter(Y=>X==null?void 0:X.some(j=>Y.ranges.some(Q=>a.Rectangle.intersects(j,Q))));return W==null||W.forEach(Y=>{F.forEach(j=>{B.push(new Y(k,N,j.permissionId).id)})}),V.composePermission$(B).pipe(de.map(Y=>Y.some(j=>j.value===!1)))}))}))))}function Mn(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(m.RangeProtectionRuleModel),i=n.get(a.IPermissionService);return D.merge(e.selectionMoveEnd$,i.permissionPointUpdate$.pipe(de.debounceTime(100))).pipe(de.map(()=>{var h;const r=(h=e.getCurrentLastSelection())==null?void 0:h.range;if(!r)return!0;const s=o.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(r,S))).forEach(g=>{u.push(new m.RangeProtectionPermissionEditPoint(c,d,g.permissionId).id)}),i.composePermission(u).some(g=>g.value===!1)}))}function Tl(n,o){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(m.RangeProtectionRuleModel),r=n.get(a.IPermissionService);return D.merge(t.selectionMoveEnd$,r.permissionPointUpdate$.pipe(de.debounceTime(100))).pipe(de.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 i.getSubunitRuleList(d,u).filter(S=>o==="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)}),r.composePermission(h).some(S=>S.value===!1)}))}function yl(n,o){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(m.RangeProtectionRuleModel),r=n.get(a.IPermissionService);return D.merge(t.selectionMoveEnd$,r.permissionPointUpdate$.pipe(de.debounceTime(100))).pipe(de.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 o==="row"?(g.startColumn=0,g.endColumn=c.getColumnCount()-1):(g.startRow=0,g.endRow=c.getRowCount()-1),i.getSubunitRuleList(d,u).filter(f=>f.ranges.some(v=>a.Rectangle.intersects(g,v))).forEach(f=>{h.push(new m.RangeProtectionPermissionEditPoint(d,u,f.permissionId).id)}),r.composePermission(h).some(f=>f.value===!1)}))}function go(n,o){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(m.RangeProtectionRuleModel),r=n.get(a.IPermissionService);return D.merge(t.selectionMoveEnd$,r.permissionPointUpdate$.pipe(de.debounceTime(100))).pipe(de.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 o==="row"?g.endRow=c.getRowCount()-1:g.endColumn=c.getColumnCount()-1,i.getSubunitRuleList(d,u).filter(f=>f.ranges.some(v=>a.Rectangle.intersects(g,v))).forEach(f=>{h.push(new m.RangeProtectionPermissionEditPoint(d,u,f.permissionId).id)}),r.composePermission(h).some(f=>f.value===!1)}))}function Pn(n,o){const t=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),i=n.get(m.WorksheetProtectionRuleModel),r=n.get(m.RangeProtectionRuleModel),s=n.get(a.IPermissionService),l=n.get(a.UserManagerService);return D.combineLatest([l.currentUser$,t]).pipe(de.switchMap(([c,d])=>d?d.activeSheet$.pipe(de.switchMap(u=>{if(!u)return D.of(!0);const h=d.getUnitId(),g=[];return o.forEach(f=>g.push(new f(h).id)),s.composePermission$(g).pipe(de.map(f=>f.every(v=>v.value===!0))).pipe(de.map(f=>{if(!f)return!0;const v=u.getSheetId(),p=i.getRule(h,v),C=r.getSubunitRuleList(h,v);return!!(p||C.length)}))})):D.of(!0)))}function Fm(n){const o=n.get(m.BorderStyleManagerService),e=ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]});return{id:m.SetBorderBasicCommand.id,icon:new D.Observable(t=>{const i="AllBorderIcon",r=n.get(m.BorderStyleManagerService),s=n.get(a.ICommandService).onCommandExecuted(l=>{var g;if(l.id!==m.SetBorderBasicCommand.id)return;const{type:d}=r.getBorderInfo(),u=wl.find(S=>S.value===d),h=(g=u==null?void 0:u.icon)!=null?g:i;t.next(h)});return t.next(i),s.dispose}),tooltip:"toolbar.border.main",type:I.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:Vr,hoverable:!1,selectable:!1},value$:o.borderInfo$}],value$:o.borderInfo$,hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:e}}const So="sheet.menu.clear-selection";function Hr(n){return{id:So,type:I.MenuItemType.SUBITEMS,icon:"ClearFormatDoubleIcon",title:"rightClick.clearSelection",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Wr(n){return{id:m.ClearSelectionContentCommand.id,type:I.MenuItemType.BUTTON,icon:"ClearFormatDoubleIcon",title:"rightClick.clearContent",disabled$:Xt(n,ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellValuePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Lr(n){return{id:m.ClearSelectionFormatCommand.id,type:I.MenuItemType.BUTTON,icon:"ClearFormatDoubleIcon",title:"rightClick.clearFormat",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function fo(n){return{id:m.ClearSelectionAllCommand.id,type:I.MenuItemType.BUTTON,icon:"ClearFormatDoubleIcon",title:"rightClick.clearAll",tooltip:"rightClick.clearAll",disabled$:Xt(n,ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellValuePermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Rl="sheet.menu.delete";function zm(n){return{id:Rl,type:I.MenuItemType.SUBITEMS,title:"rightClick.delete",icon:"ReduceDoubleIcon",hidden$:Xt(n,Mn(n)),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission]})}}function Ml(n){return{id:hn.id,type:I.MenuItemType.BUTTON,icon:"DeleteColumnDoubleIcon",title:"rightClick.deleteSelectedColumn",hidden$:yl(n,"col"),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookDeleteColumnPermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetDeleteColumnPermission]})}}function Pl(n){return{id:un.id,type:I.MenuItemType.BUTTON,icon:"DeleteRowDoubleIcon",title:"rightClick.deleteSelectedRow",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookDeleteRowPermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetDeleteRowPermission]}),hidden$:yl(n,"row")}}function Xm(n){return{id:an.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveLeft",icon:"DeleteCellShiftLeftDoubleIcon",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:go(n,"col")}}function Ym(n){return{id:Tt.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveUp",icon:"DeleteCellShiftUpDoubleIcon",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:go(n,"row")}}function jm(n,o){const e=n.get(m.SheetsSelectionsService),t=n.get(a.IUniverInstanceService),i=n.get(a.ICommandService),r=n.get(a.IContextService);return be(t,o,({worksheet:s})=>new D.Observable(l=>{const c=()=>{var S;let h=o;const g=(S=e.getCurrentLastSelection())==null?void 0:S.primary;if(g!=null){const f=s.getComposedCellStyle(g.startRow,g.startColumn);f.fs&&(h=f.fs)}l.next(h)},d=()=>{var g,S;const h=yt(n);if(h!=null){const f=(S=(g=h.ts)==null?void 0:g.fs)!=null?S:o;l.next(f)}},u=i.onCommandExecuted(h=>{const g=h.id;(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id)&&c(),(g===Ce.SetTextSelectionsOperation.id||g===K.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)&&d()});return c(),u.dispose}))}function Zm(n){const o=a.DEFAULT_STYLES.fs,e=ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0);return{id:ni.id,type:I.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:I.FONT_SIZE_COMPONENT,props:{min:6,max:400,disabled$:e}},selections:I.FONT_SIZE_LIST,disabled$:e,value$:jm(n,o),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Gm(n){const o=ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0);return{id:Ki.id,type:I.MenuItemType.BUTTON,icon:"FontSizeIncreaseIcon",tooltip:"toolbar.fontSizeIncrease",disabled$:o,hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Km(n){const o=ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0);return{id:qi.id,type:I.MenuItemType.BUTTON,icon:"FontSizeReduceIcon",tooltip:"toolbar.fontSizeDecrease",disabled$:o,hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function qm(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService);return{id:m.ToggleGridlinesCommand.id,type:I.MenuItemType.BUTTON,tooltip:"toolbar.toggleGridlines",icon:"HideGridlinesDoubleIcon",activated$:new D.Observable(t=>{const i=()=>{const s=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);return s?s.getActiveSheet().getConfig().showGridlines===a.BooleanNumber.TRUE:!1},r=new a.DisposableCollection;return r.add(o.onCommandExecuted(s=>{(s.id===m.ToggleGridlinesMutation.id||s.id===m.SetWorksheetActiveOperation.id)&&t.next(i())})),r.add(e.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(()=>{t.next(i())})),t.next(i()),()=>r.dispose()}),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission]})}}const je=`${bl}_MENU_ITEM_INPUT_COMPONENT`,Ol=n=>{const{prefix:o,suffix:e,value:t,min:i=Number.MIN_SAFE_INTEGER,max:r=Number.MAX_SAFE_INTEGER,disabled$:s,onChange:l}=n,c=I.useDependency(a.LocaleService),d=I.useDependency(I.IContextMenuService),[u,h]=x.useState(!1),[g,S]=x.useState(),f=p=>{if(!p){S(i.toString());return}const C=p.toString();S(C),l(C)};x.useEffect(()=>{if(!s)return;const p=s.subscribe(C=>{h(C)});return()=>{p.unsubscribe()}},[]),x.useEffect(()=>{d.visible||S(t)},[d.visible]),x.useEffect(()=>{+t<i?S(i.toString()):+t>r?S(r.toString()):S(t)},[t]);function v(){g&&l(g)}return b.jsxs("div",{className:"univer-inline-flex univer-items-center univer-gap-1",children:[c.t(o),b.jsx("div",{className:"univer-w-16",onClick:p=>p.stopPropagation(),children:b.jsx(z.InputNumber,{value:Number(g),size:"mini",precision:0,min:i,max:r,disabled:u,onPressEnter:v,onChange:f})}),c.t(e)]})},Al="sheet.menu.cell-insert";function Qm(n){return{id:Al,type:I.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"InsertDoubleIcon",hidden$:Xt(n,Mn(n)),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookInsertColumnPermission,m.WorkbookInsertRowPermission],worksheetTypes:[m.WorksheetInsertColumnPermission,m.WorksheetInsertRowPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Jm(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),i=1,r=ee(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookInsertRowPermission],worksheetTypes:[m.WorksheetInsertRowPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]});return{id:m.InsertRowBeforeCommand.id,type:I.MenuItemType.BUTTON,icon:"InsertRowAboveDoubleIcon",label:{name:je,props:{prefix:"rightClick.insertRowsAbove",min:1,max:1e3,suffix:"rightClick.insertRowsAboveSuffix",disabled$:r}},value$:be(o,i,()=>new D.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=i;d&&(u=(d==null?void 0:d.endRow)-(d==null?void 0:d.startRow)+1),s.next(u)}const c=t.onCommandExecuted(d=>{if(d.id===m.SetSelectionsOperation.id)return l()});return l(),c.dispose})),disabled$:r,hidden$:Tl(n,"row")}}function $m(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),i=1,r=ee(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookInsertColumnPermission],worksheetTypes:[m.WorksheetInsertColumnPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]});return{id:m.InsertColBeforeCommand.id,type:I.MenuItemType.BUTTON,icon:"LeftInsertColumnDoubleIcon",label:{name:je,props:{prefix:"rightClick.insertColsLeft",min:1,max:1e3,suffix:"rightClick.insertColsLeftSuffix",disabled$:r}},value$:be(o,i,()=>new D.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=i;d&&(u=(d==null?void 0:d.endColumn)-(d==null?void 0:d.startColumn)+1),s.next(u)}const c=t.onCommandExecuted(d=>{if(d.id===m.SetSelectionsOperation.id)return l()});return l(),c.dispose})),disabled$:r,hidden$:Tl(n,"col")}}function eg(n){return{id:dn.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveRight",icon:"InsertCellShiftRightDoubleIcon",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:go(n,"col")}}function tg(n){return{id:At.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveDown",icon:"InsertCellDownDoubleIcon",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:go(n,"row")}}function ng(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),i=1,r=ee(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookInsertRowPermission],worksheetTypes:[m.WorksheetInsertRowPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]});return{id:m.InsertMultiRowsAfterCommand.id,type:I.MenuItemType.BUTTON,icon:"InsertRowBelowDoubleIcon",label:{name:je,props:{prefix:"rightClick.insertRowsAfter",min:1,max:1e3,suffix:"rightClick.insertRowsAfterSuffix",disabled$:r}},value$:be(o,i,()=>new D.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=i;d&&(u=(d==null?void 0:d.endRow)-(d==null?void 0:d.startRow)+1),s.next(u)}const c=t.onCommandExecuted(d=>{if(d.id===m.SetSelectionsOperation.id)return l()});return l(),c.dispose})),disabled$:r,hidden$:Mn(n)}}function ig(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),i=1,r=ee(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookInsertRowPermission],worksheetTypes:[m.WorksheetInsertRowPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]});return{id:m.InsertMultiRowsAboveCommand.id,type:I.MenuItemType.BUTTON,icon:"InsertRowAboveDoubleIcon",label:{name:je,props:{prefix:"rightClick.insertRowsAbove",min:1,max:1e3,suffix:"rightClick.insertRowsAboveSuffix",disabled$:r}},value$:be(o,i,()=>new D.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=i;d&&(u=(d==null?void 0:d.endRow)-(d==null?void 0:d.startRow)+1),s.next(u)}const c=t.onCommandExecuted(d=>{if(d.id===m.SetSelectionsOperation.id)return l()});return l(),c.dispose})),disabled$:r,hidden$:Mn(n)}}function og(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),i=1,r=ee(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookInsertColumnPermission],worksheetTypes:[m.WorksheetInsertColumnPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]});return{id:m.InsertMultiColsLeftCommand.id,type:I.MenuItemType.BUTTON,icon:"LeftInsertColumnDoubleIcon",label:{name:je,props:{prefix:"rightClick.insertColsLeft",min:1,max:1e3,suffix:"rightClick.insertColsLeftSuffix",disabled$:r}},value$:be(o,i,()=>new D.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=i;d&&(u=(d==null?void 0:d.endColumn)-(d==null?void 0:d.startColumn)+1),s.next(u)}const c=t.onCommandExecuted(d=>{if(d.id===m.SetSelectionsOperation.id)return l()});return l(),c.dispose})),disabled$:r,hidden$:Mn(n)}}function rg(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),i=1,r=ee(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookInsertColumnPermission],worksheetTypes:[m.WorksheetInsertColumnPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]});return{id:m.InsertMultiColsRightCommand.id,type:I.MenuItemType.BUTTON,icon:"RightInsertColumnDoubleIcon",label:{name:je,props:{prefix:"rightClick.insertColsRight",min:1,max:1e3,suffix:"rightClick.insertColsRightSuffix",disabled$:r}},value$:be(o,i,()=>new D.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=i;d&&(u=(d==null?void 0:d.endColumn)-(d==null?void 0:d.startColumn)+1),s.next(u)}const c=t.onCommandExecuted(d=>{if(d.id===m.SetSelectionsOperation.id)return l()});return l(),c.dispose})),disabled$:r,hidden$:Mn(n)}}var Dl=(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))(Dl||{});function sg(n){const o=n.get(Be);return{id:gn.id,subId:no.id,type:I.MenuItemType.BUTTON,icon:"BrushIcon",title:"Format Painter",tooltip:"toolbar.formatPainter",activated$:new D.Observable(e=>{let t=!1;const i=o.status$.subscribe(r=>{t=r!==Ae.OFF,e.next(t)});return e.next(t),()=>{i.unsubscribe()}}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetCopyPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0)}}function ag(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(a.IContextService),i=n.get(m.SheetsSelectionsService);return{id:Rt.id,type:I.MenuItemType.BUTTON,icon:"BoldIcon",title:"Set bold",tooltip:"toolbar.bold",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:be(e,!1,({worksheet:r})=>new D.Observable(s=>{var u;const l=o.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const v=(S=i.getCurrentLastSelection())==null?void 0:S.primary;let p=a.FontWeight.NORMAL;if(v!=null){const C=r.getRange(v.startRow,v.startColumn);p=C==null?void 0:C.getFontWeight()}s.next(p===a.FontWeight.BOLD)}if((g===Ce.SetTextSelectionsOperation.id||g===K.SetInlineFormatCommand.id)&&t.getContextValue(a.EDITOR_ACTIVATED)&&t.getContextValue(a.FOCUSING_SHEET)){const v=yt(n);if(v==null)return;const p=(f=v.ts)==null?void 0:f.bl;s.next(p===a.BooleanNumber.TRUE)}}),c=(u=i.getCurrentLastSelection())==null?void 0:u.primary;if(!r){s.next(!1);return}let d=a.FontWeight.NORMAL;if(c!=null){const h=r.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getFontWeight()}return s.next(d===a.FontWeight.BOLD),l.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function lg(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(a.IContextService);return{id:Mt.id,type:I.MenuItemType.BUTTON,icon:"ItalicIcon",title:"Set italic",tooltip:"toolbar.italic",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:be(e,!1,({worksheet:r})=>new D.Observable(s=>{var u;const l=o.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const v=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let p=a.FontItalic.NORMAL;if(v!=null){const C=r.getRange(v.startRow,v.startColumn);p=C==null?void 0:C.getFontStyle()}s.next(p===a.FontItalic.ITALIC)}if((g===Ce.SetTextSelectionsOperation.id||g===K.SetInlineFormatCommand.id)&&i.getContextValue(a.EDITOR_ACTIVATED)&&i.getContextValue(a.FOCUSING_SHEET)){const v=yt(n);if(v==null)return;const p=(f=v.ts)==null?void 0:f.it;s.next(p===a.BooleanNumber.TRUE)}}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d=a.FontItalic.NORMAL;if(c!=null){const h=r.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getFontStyle()}return s.next(d===a.FontItalic.ITALIC),l.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function cg(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(a.IContextService);return{id:Pt.id,type:I.MenuItemType.BUTTON,icon:"UnderlineIcon",title:"Set underline",tooltip:"toolbar.underline",activated$:be(e,!1,({worksheet:r})=>new D.Observable(s=>{var u;const l=o.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const v=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let p;if(v!=null){const C=r.getRange(v.startRow,v.startColumn);p=C==null?void 0:C.getUnderline()}s.next(!!(p&&p.s))}if((g===Ce.SetTextSelectionsOperation.id||g===K.SetInlineFormatCommand.id)&&i.getContextValue(a.EDITOR_ACTIVATED)&&i.getContextValue(a.FOCUSING_SHEET)){const v=yt(n);if(v==null)return;const p=(f=v.ts)==null?void 0:f.ul;s.next((p==null?void 0:p.s)===a.BooleanNumber.TRUE)}}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d;if(c!=null){const h=r.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getUnderline()}return s.next(!!(d&&d.s)),l.dispose})),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function dg(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(a.IContextService);return{id:Ot.id,type:I.MenuItemType.BUTTON,icon:"StrikethroughIcon",title:"Set strike through",tooltip:"toolbar.strikethrough",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:be(e,!1,({worksheet:r})=>new D.Observable(s=>{var u;const l=o.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const v=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let p;if(v!=null){const C=r.getRange(v.startRow,v.startColumn);p=C==null?void 0:C.getStrikeThrough()}s.next(!!(p&&p.s))}if((g===Ce.SetTextSelectionsOperation.id||g===K.SetInlineFormatCommand.id)&&i.getContextValue(a.EDITOR_ACTIVATED)&&i.getContextValue(a.FOCUSING_SHEET)){const v=yt(n);if(v==null)return;const p=(f=v.ts)==null?void 0:f.st;s.next((p==null?void 0:p.s)===a.BooleanNumber.TRUE)}}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d;if(c!=null){const h=r.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getStrikeThrough()}return s.next(!!(d&&d.s)),l.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function ug(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=a.DEFAULT_STYLES.ff;return{id:ln.id,tooltip:"toolbar.font",type:I.MenuItemType.SELECTOR,label:I.FONT_FAMILY_COMPONENT,selections:[{label:{name:I.FONT_FAMILY_ITEM_COMPONENT,hoverable:!1,selectable:!1,props:{id:ln.id}}}],disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),value$:be(e,i,({worksheet:r})=>new D.Observable(s=>{const l=()=>{var h;let d=i;const u=(h=t.getCurrentLastSelection())==null?void 0:h.primary;if(u!=null){const g=r.getCellStyle(u.startRow,u.startColumn),S=r.getDefaultCellStyleInternal(),f=r.getRowStyle(u.startRow),v=r.getColumnStyle(u.startColumn),p=a.composeStyles(S,f,v,g);p.ff&&(d=p.ff)}s.next(d)},c=o.onCommandExecuted(d=>{const u=d.id;(u===m.SetRangeValuesMutation.id||u===m.SetSelectionsOperation.id||u===m.SetWorksheetActiveOperation.id)&&l()});return l(),c.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function hg(n){return{id:Qi.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColorDoubleIcon",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function mg(n){const o=n.get(a.ICommandService),e=n.get(a.ThemeService),t=n.get(m.SheetsSelectionsService);return{id:cn.id,icon:"FontColorDoubleIcon",tooltip:"toolbar.textColor.main",type:I.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:I.COLOR_PICKER_COMPONENT,hoverable:!1,selectable:!1},value$:new D.Observable(i=>{var c;const r=a.DEFAULT_STYLES.cl.rgb,{isAllValuesSame:s,value:l}=t.getCellStylesProperty("cl");s?i.next((c=l==null?void 0:l.rgb)!=null?c:r):i.next(r)})}],value$:new D.Observable(i=>{const r=e.getColorFromTheme("gray.900"),s=o.onCommandExecuted(l=>{if(l.id===cn.id){const c=l.params.value;i.next(c!=null?c:r)}});return i.next(r),s.dispose}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0)}}function gg(n){return{id:m.ResetBackgroundColorCommand.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColorDoubleIcon",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Sg(n){const o=n.get(a.ICommandService),e=n.get(a.ThemeService),t=n.get(m.SheetsSelectionsService);return{id:m.SetBackgroundColorCommand.id,tooltip:"toolbar.fillColor.main",type:I.MenuItemType.BUTTON_SELECTOR,icon:"PaintBucketDoubleIcon",selections:[{label:{name:I.COLOR_PICKER_COMPONENT,hoverable:!1,selectable:!1},value$:new D.Observable(i=>{var c;const r=a.DEFAULT_STYLES.bg.rgb,{isAllValuesSame:s,value:l}=t.getCellStylesProperty("bg");s?i.next((c=l==null?void 0:l.rgb)!=null?c:r):i.next(r)})}],value$:new D.Observable(i=>{const r=e.getColorFromTheme("primary.600"),s=o.onCommandExecuted(l=>{if(l.id===m.SetBackgroundColorCommand.id){const c=l.params.value;i.next(c!=null?c:r)}});return i.next(r),s.dispose}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const kl=[{label:"align.left",icon:"LeftJustifyingIcon",value:a.HorizontalAlign.LEFT},{label:"align.center",icon:"HorizontallyIcon",value:a.HorizontalAlign.CENTER},{label:"align.right",icon:"RightJustifyingIcon",value:a.HorizontalAlign.RIGHT}];function fg(n){var s,l;const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=o.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET),i=t==null?void 0:t.getActiveSheet().getDefaultCellStyleInternal(),r=(s=i==null?void 0:i.ht)!=null?s:a.HorizontalAlign.LEFT;return{id:m.SetHorizontalTextAlignCommand.id,icon:(l=kl.find(c=>c.value===r))==null?void 0:l.icon,tooltip:"toolbar.horizontalAlignMode.main",type:I.MenuItemType.SELECTOR,selections:kl,value$:be(o,r,({worksheet:c})=>new D.Observable(d=>{var S,f;const u=n.get(a.ICommandService).onCommandExecuted(v=>{var w,E;const p=v.id;if(p!==m.SetHorizontalTextAlignCommand.id&&p!==m.SetSelectionsOperation.id&&p!==m.SetWorksheetActiveOperation.id)return;const C=(w=e.getCurrentLastSelection())==null?void 0:w.primary;let _;if(C!=null){const O=c.getRange(C.startRow,C.startColumn),R=t==null?void 0:t.getActiveSheet().getComposedCellStyle(C.startRow,C.startColumn);_=(E=R==null?void 0:R.ht)!=null?E:O==null?void 0:O.getHorizontalAlignment()}d.next(_!=null?_:r)}),h=(S=e.getCurrentLastSelection())==null?void 0:S.primary;let g;if(h!=null){const v=c.getRange(h.startRow,h.startColumn),p=t==null?void 0:t.getActiveSheet().getComposedCellStyle(h.startRow,h.startColumn);g=(f=p==null?void 0:p.ht)!=null?f:v==null?void 0:v.getHorizontalAlignment()}return d.next(g!=null?g:r),u.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const Nl=[{label:"align.top",icon:"AlignTopIcon",value:a.VerticalAlign.TOP},{label:"align.middle",icon:"VerticalCenterIcon",value:a.VerticalAlign.MIDDLE},{label:"align.bottom",icon:"AlignBottomIcon",value:a.VerticalAlign.BOTTOM}];function vg(n){var s,l;const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=o.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET),i=t==null?void 0:t.getActiveSheet().getDefaultCellStyleInternal(),r=(s=i==null?void 0:i.vt)!=null?s:a.VerticalAlign.BOTTOM;return{id:m.SetVerticalTextAlignCommand.id,icon:(l=Nl.find(c=>c.value===r))==null?void 0:l.icon,tooltip:"toolbar.verticalAlignMode.main",type:I.MenuItemType.SELECTOR,selections:Nl,value$:be(o,r,({worksheet:c})=>new D.Observable(d=>{var S,f;const u=n.get(a.ICommandService).onCommandExecuted(v=>{var w,E;const p=v.id;if(p!==m.SetVerticalTextAlignCommand.id&&p!==m.SetSelectionsOperation.id&&p!==m.SetWorksheetActiveOperation.id)return;const C=(w=e.getCurrentLastSelection())==null?void 0:w.primary;let _;if(C!=null){const O=c.getRange(C.startRow,C.startColumn),R=t==null?void 0:t.getActiveSheet().getComposedCellStyle(C.startRow,C.startColumn);_=(E=R==null?void 0:R.vt)!=null?E:O==null?void 0:O.getVerticalAlignment()}d.next(_!=null?_:r)}),h=(S=e.getCurrentLastSelection())==null?void 0:S.primary;let g;if(h!=null){const v=c.getRange(h.startRow,h.startColumn),p=t==null?void 0:t.getActiveSheet().getComposedCellStyle(h.startRow,h.startColumn);g=(f=p==null?void 0:p.vt)!=null?f:v==null?void 0:v.getVerticalAlignment()}return d.next(g!=null?g:r),u.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const Vl=[{label:"textWrap.overflow",icon:"OverflowIcon",value:a.WrapStrategy.OVERFLOW},{label:"textWrap.wrap",icon:"AutowrapIcon",value:a.WrapStrategy.WRAP},{label:"textWrap.clip",icon:"TruncationIcon",value:a.WrapStrategy.CLIP}];function pg(n){var s,l;const o=n.get(m.SheetsSelectionsService),e=n.get(a.IUniverInstanceService),t=e.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET),i=t==null?void 0:t.getActiveSheet().getDefaultCellStyleInternal(),r=(s=i==null?void 0:i.tb)!=null?s:a.WrapStrategy.OVERFLOW;return{id:m.SetTextWrapCommand.id,tooltip:"toolbar.textWrapMode.main",icon:(l=Vl.find(c=>c.value===r))==null?void 0:l.icon,type:I.MenuItemType.SELECTOR,selections:Vl,value$:be(e,r,({worksheet:c})=>new D.Observable(d=>{var S,f;const u=n.get(a.ICommandService).onCommandExecuted(v=>{var w,E;const p=v.id;if(p!==m.SetTextWrapCommand.id&&p!==m.SetSelectionsOperation.id&&p!==m.SetWorksheetActiveOperation.id)return;const C=(w=o.getCurrentLastSelection())==null?void 0:w.primary;let _;if(C!=null){const O=c.getRange(C.startRow,C.startColumn),R=t==null?void 0:t.getActiveSheet().getComposedCellStyle(C.startRow,C.startColumn);_=(E=R==null?void 0:R.tb)!=null?E:O==null?void 0:O.getWrapStrategy()}d.next(_!=null?_:r)}),h=(S=o.getCurrentLastSelection())==null?void 0:S.primary;let g;if(h!=null){const v=c.getRange(h.startRow,h.startColumn),p=t==null?void 0:t.getActiveSheet().getComposedCellStyle(h.startRow,h.startColumn);g=(f=p==null?void 0:p.tb)!=null?f:v==null?void 0:v.getWrapStrategy()}return d.next(g!=null?g:r),u.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const Hl=[{label:"textRotate.none",icon:"NoRotationIcon",value:0},{label:"textRotate.angleUp",icon:"LeftRotationFortyFiveDegreesIcon",value:-45},{label:"textRotate.angleDown",icon:"RightRotationFortyFiveDegreesIcon",value:45},{label:"textRotate.vertical",icon:"VerticalTextIcon",value:"v"},{label:"textRotate.rotationUp",icon:"LeftRotationNinetyDegreesIcon",value:-90},{label:"textRotate.rotationDown",icon:"RightRotationNinetyDegreesIcon",value:90}];function Cg(n){const o=n.get(m.SheetsSelectionsService),e=n.get(a.IUniverInstanceService),t=0;return{id:m.SetTextRotationCommand.id,tooltip:"toolbar.textRotateMode.main",icon:Hl[0].icon,type:I.MenuItemType.SELECTOR,selections:Hl,value$:be(e,t,({worksheet:i})=>new D.Observable(r=>{var d,u;const s=n.get(a.ICommandService).onCommandExecuted(h=>{var v,p;const g=h.id;if(g!==m.SetTextRotationCommand.id&&g!==m.SetSelectionsOperation.id&&g!==m.SetWorksheetActiveOperation.id)return;const S=(v=o.getCurrentLastSelection())==null?void 0:v.primary;let f;if(S!=null){const C=i.getRange(S.startRow,S.startColumn);f=C==null?void 0:C.getTextRotation()}(f==null?void 0:f.v)===a.BooleanNumber.TRUE?r.next("v"):r.next((p=f&&f.a)!=null?p:t)}),l=(d=o.getCurrentLastSelection())==null?void 0:d.primary;let c;if(l!=null){const h=i.getRange(l.startRow,l.startColumn);c=h==null?void 0:h.getTextRotation()}return(c==null?void 0:c.v)===a.BooleanNumber.TRUE?r.next("v"):r.next((u=c&&c.a)!=null?u:t),s.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Ti(n){return new D.Observable(e=>e.next(!n.get(I.IClipboardInterfaceService).supportClipboard))}function On(n){return{id:He.name,commandId:He.id,type:I.MenuItemType.BUTTON,title:"rightClick.copy",icon:"CopyDoubleIcon",disabled$:ee(n,{workbookTypes:[m.WorkbookCopyPermission],worksheetTypes:[m.WorksheetCopyPermission],rangeTypes:[m.RangeProtectionPermissionViewPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function xr(n){return{id:We.name,commandId:We.id,type:I.MenuItemType.BUTTON,title:"rightClick.paste",icon:"PasteSpecialDoubleIcon",disabled$:Ti(n).pipe(D.combineLatestWith(ee(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission,m.WorksheetSetCellValuePermission],workbookTypes:[m.WorkbookEditablePermission]})),D.map(([o,e])=>o||e)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const yi="sheet.menu.paste-special";function Ur(n){return{id:yi,type:I.MenuItemType.SUBITEMS,icon:"PasteSpecialDoubleIcon",title:"rightClick.pasteSpecial",hidden$:Xt(n,I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET))}}function Br(n){return{id:on.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteValue",disabled$:Ti(n).pipe(D.combineLatestWith(ee(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellValuePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),D.map(([o,e])=>o||e)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Fr(n){return{id:rn.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteFormat",disabled$:Ti(n).pipe(D.combineLatestWith(ee(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellStylePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),D.map(([o,e])=>o||e)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function zr(n){return{id:Et.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteColWidth",disabled$:Ti(n).pipe(D.combineLatestWith(ee(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetColumnStylePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),D.map(([o,e])=>o||e))}}function Xr(n){return{id:sn.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteBesidesBorder",disabled$:Ti(n).pipe(D.combineLatestWith(ee(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission,m.WorksheetSetCellValuePermission,m.WorksheetSetRowStylePermission,m.WorksheetSetColumnStylePermission],workbookTypes:[m.WorkbookEditablePermission]})),D.map(([o,e])=>o||e)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Ig(n){return{id:m.SetWorksheetRowIsAutoHeightCommand.id,type:I.MenuItemType.BUTTON,icon:"AutoHeightDoubleIcon",title:"rightClick.fitContent",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function _g(n){return{id:pn.id,type:I.MenuItemType.BUTTON,icon:"AutoWidthDoubleIcon",title:"rightClick.fitContent",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Wl="sheet.menu.sheet-frozen";function bg(n){return{id:Wl,type:I.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Yr="sheet.header-menu.sheet-frozen";function Ll(n){return{id:Yr,type:I.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function jr(n){return{id:Je.id,type:I.MenuItemType.BUTTON,title:"rightClick.freeze",icon:"FreezeToSelectedIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function wg(n){return{id:hi.id,type:I.MenuItemType.BUTTON,title:"rightClick.freezeRow",icon:"FreezeRowIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Eg(n){return{id:mi.id,type:I.MenuItemType.BUTTON,title:"rightClick.freezeCol",icon:"FreezeColumnIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Zr(n){return{id:m.CancelFrozenCommand.id,type:I.MenuItemType.BUTTON,title:"rightClick.cancelFreeze",icon:"CancelFreezeIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Tg(n){return{id:ei.id,type:I.MenuItemType.BUTTON,icon:"HideDoubleIcon",title:"rightClick.hideSelectedRow",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function yg(n){return{id:ti.id,type:I.MenuItemType.BUTTON,icon:"HideDoubleIcon",title:"rightClick.hideSelectedColumn",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Rg(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),i=[m.SetSelectionsOperation,m.SetRowHiddenMutation,m.SetRowVisibleMutation].map(r=>r.id);return{id:m.SetSelectedRowsVisibleCommand.id,type:I.MenuItemType.BUTTON,icon:"EyeOutlineIcon",title:"rightClick.showHideRow",hidden$:be(o,!0,({worksheet:r})=>new D.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(!r.getRowRawVisible(g))return!0;return!1}))}const c=t.onCommandExecuted(d=>{i.findIndex(u=>u===d.id)!==-1&&s.next(!l())});return s.next(!l()),()=>c.dispose()})),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetRowStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Mg(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),i=[m.SetSelectionsOperation,m.SetColHiddenMutation,m.SetColVisibleMutation].map(r=>r.id);return{id:m.SetSelectedColsVisibleCommand.id,type:I.MenuItemType.BUTTON,icon:"EyeOutlineIcon",title:"rightClick.showHideColumn",hidden$:be(o,!0,({worksheet:r})=>new D.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(!r.getColVisible(g))return!0;return!1})}const c=t.onCommandExecuted(d=>{i.findIndex(u=>u===d.id)!==-1&&s.next(!l())});return s.next(!l()),()=>c.dispose()})),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetColumnStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Pg(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=2;return{id:m.SetRowHeightCommand.id,type:I.MenuItemType.BUTTON,icon:"AdjustHeightDoubleIcon",label:{name:je,props:{prefix:"rightClick.rowHeight",suffix:"px",min:i,max:1e3}},value$:be(e,i,({worksheet:r})=>new D.Observable(s=>{function l(){var h;const d=(h=t.getCurrentLastSelection())==null?void 0:h.primary,u=d?r.getRowHeight(d.startRow):r.getConfig().defaultRowHeight;s.next(u)}const c=o.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$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetRowStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Og(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=2;return{id:m.SetColWidthCommand.id,type:I.MenuItemType.BUTTON,icon:"AdjustWidthDoubleIcon",label:{name:je,props:{prefix:"rightClick.columnWidth",suffix:"px",min:i,max:1e3}},value$:be(e,i,({worksheet:r})=>new D.Observable(s=>{function l(){var h;const d=(h=t.getCurrentLastSelection())==null?void 0:h.primary,u=d?r.getColumnWidth(d.startColumn):r.getConfig().defaultColumnWidth;s.next(u)}const c=o.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$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const gt={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge",handler:async(n,o)=>{const e=n.get(a.ICommandService),t=n.get(a.IUndoRedoService),i=n.get(a.IUniverInstanceService),r=n.get(I.IConfirmService),s=n.get(a.LocaleService),l=o.unitId,c=o.subUnitId,d=o.selections,u=m.getAddMergeMutationRangeByType(d,o.value),h=i.getUniverSheetInstance(l).getSheetBySheetId(c),g=[],S=[],f=ba(h,u);if(f&&!o.defaultMerge&&!await r.confirm({id:"merge.confirm.add-worksheet-merge",title:{title:"merge.confirm.warning"},children:{title:"merge.confirm.title"},cancelText:s.t("merge.confirm.cancel"),confirmText:s.t("merge.confirm.confirm")}))return!1;const v={unitId:l,subUnitId:c,ranges:a.Tools.deepClone(u)},p={unitId:l,subUnitId:c,ranges:a.Tools.deepClone(u)},C=m.RemoveMergeUndoMutationFactory(n,v),_=m.AddMergeUndoMutationFactory(n,p);if(C.ranges.length>0&&g.push({id:m.RemoveWorksheetMergeMutation.id,params:C}),g.push({id:m.AddWorksheetMergeMutation.id,params:p}),S.push({id:m.RemoveWorksheetMergeMutation.id,params:_}),C.ranges.length>0&&S.push({id:m.AddWorksheetMergeMutation.id,params:C}),f){const A=wa(n,l,h,u);g.unshift(...A.redos),S.push(...A.undos)}const w=m.AddMergeRedoSelectionsOperationFactory(n,o,u);w&&g.push(w);const E=m.AddMergeUndoSelectionsOperationFactory(n,o);E&&S.push(E);const R=n.get(m.SheetInterceptorService).onCommandExecute({id:gt.id,params:{unitId:l,subUnitId:c,ranges:u}});return g.push(...R.redos),S.push(...R.undos),a.sequenceExecute(g,e).result?(t.pushUndoRedo({unitID:l,undoMutations:S,redoMutations:g}),!0):!1}},Gr={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-all",handler:async n=>{var u;const o=n.get(a.ICommandService),t=(u=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:u.map(h=>h.range),i=dr(Gi.MergeAll,t);if(!(i!=null&&i.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 o.executeCommand(gt.id,{selections:i,unitId:c,subUnitId:d})}},Kr={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-vertical",handler:async n=>{var u;const o=n.get(a.ICommandService),t=(u=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:u.map(h=>h.range),i=dr(Gi.MergeVertical,t);if(!(i!=null&&i.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 o.executeCommand(gt.id,{value:a.Dimension.COLUMNS,selections:i,unitId:c,subUnitId:d})}},qr={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-horizontal",handler:async n=>{var u;const o=n.get(a.ICommandService),t=(u=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:u.map(h=>h.range),i=dr(Gi.MergeHorizontal,t);if(!(i!=null&&i.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 o.executeCommand(gt.id,{value:a.Dimension.ROWS,selections:i,unitId:c,subUnitId:d})}};function Ag(n){const o=n.get(m.SheetsSelectionsService),e=n.get(m.RangeProtectionRuleModel),t=n.get(a.IUniverInstanceService),i=n.get(m.MergeCellController),r=t.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET);return D.combineLatest([o.selectionMoveEnd$,r.pipe(D.map(s=>{var l;return(l=s==null?void 0:s.getUnitId())!=null?l:""})),r.pipe(D.switchMap(s=>{var l;return(l=s==null?void 0:s.activeSheet$)!=null?l:D.of(null)}))]).pipe(D.map(([s,l,c])=>{if(!c||!s||s.length===0)return!1;const d=c.getSheetId(),u=s.map(S=>S.range);if(i.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(v=>a.Rectangle.intersects(v,S)&&!a.Rectangle.contains(v,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 xl(n,o){return!!Ri(n,o,a.RANGE_TYPE.ROW)}function Ul(n,o){return!!Ri(n,o,a.RANGE_TYPE.COLUMN)}function Ri(n,o,e){return n.find(i=>{const r=i.range,{startRow:s,endRow:l,startColumn:c,endColumn:d,rangeType:u}=r;return u===a.RANGE_TYPE.ALL||u===a.RANGE_TYPE.NORMAL?!1:u===e&&(e===a.RANGE_TYPE.COLUMN&&c<=o&&o<=d||e===a.RANGE_TYPE.ROW&&s<=o&&o<=l)})}function Dg(n){const o=Xt(n,ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellValuePermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})),e=Ag(n);return{id:gt.id,icon:"MergeAllIcon",tooltip:"toolbar.mergeCell.main",type:I.MenuItemType.SUBITEMS,hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:o.pipe(D.combineLatestWith(e),D.map(([t,i])=>t||i))}}function kg(n){return{id:Gr.id,type:I.MenuItemType.BUTTON,title:"merge.all",icon:"MergeAllIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Ng(n){return{id:Kr.id,type:I.MenuItemType.BUTTON,title:"merge.vertical",icon:"VerticalIntegrationIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Vg(n){return{id:qr.id,type:I.MenuItemType.BUTTON,title:"merge.horizontal",icon:"HorizontalMergeIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Hg(n){return{id:m.RemoveWorksheetMergeCommand.id,type:I.MenuItemType.BUTTON,title:"merge.cancel",icon:"CancelMergeIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Wg(n){const e=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),t=n.get(a.UserManagerService);return D.combineLatest([e,t.currentUser$]).pipe(D.switchMap(([i,r])=>i?i.activeSheet$.pipe(D.switchMap(s=>{if(!s)return D.of(!0);const l=n.get(m.RangeProtectionRuleModel),c=n.get(m.WorksheetProtectionRuleModel),d=n.get(m.SheetsSelectionsService);return D.merge(d.selectionMoveEnd$,l.ruleChange$,c.ruleChange$).pipe(D.map(()=>{const u=i.getUnitId(),h=s.getSheetId(),g=l.getSubunitRuleList(u,h),S=d.getCurrentSelections(),f=S==null?void 0:S.map(C=>C.range),v=g.map(C=>C.ranges).flat();if(!f)return!1;const p=c.getRule(u,h);return p!=null&&p.permissionId?!0:f==null?void 0:f.some(C=>v.some(_=>a.Rectangle.intersects(C,_)))}))})):D.of(!0)))}function Lg(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.RangeProtectionRuleModel),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),i=n.get(a.UserManagerService);return D.combineLatest([t,i.currentUser$]).pipe(D.switchMap(([r,s])=>r?r.activeSheet$.pipe(D.switchMap(l=>{if(!l)return D.of(!0);const c=n.get(m.RangeProtectionRuleModel),d=n.get(m.WorksheetProtectionRuleModel),u=n.get(a.IPermissionService),h=n.get(m.SheetsSelectionsService);return D.merge(h.selectionMoveEnd$,c.ruleChange$,d.ruleChange$).pipe(D.map(()=>{var A,k;const g=r.getUnitId(),S=l.getSheetId(),f=e.getSubunitRuleList(g,S),v=(A=h.getCurrentSelections())==null?void 0:A.map(N=>N.range);if(f.map(N=>N.ranges).flat(),!(v!=null&&v.length)||v.length>1)return!0;const p=v[0];if((p==null?void 0:p.rangeType)===a.RANGE_TYPE.ALL||(p==null?void 0:p.rangeType)===a.RANGE_TYPE.COLUMN||(p==null?void 0:p.rangeType)===a.RANGE_TYPE.ROW)return!0;const C=d.getRule(g,S);if(C!=null&&C.permissionId)return((k=u.getPermissionPoint(new m.WorksheetManageCollaboratorPermission(g,S).id))==null?void 0:k.value)===!1;if(f.filter(N=>N.ranges.some(V=>a.Rectangle.intersects(V,p))).length!==1)return!0;const{startRow:w,endRow:E,startColumn:O,endColumn:R}=p,P=n.get(m.RangeProtectionCache);for(let N=w;N<=E;N++)for(let V=O;V<=R;V++){const L=P.getCellInfo(g,S,N,V);if(L)return L[m.UnitAction.ManageCollaborator]===!1}return!1}))})):D.of(!0)))}function xg(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),i=n.get(a.UserManagerService);return D.combineLatest([t,i.currentUser$]).pipe(D.switchMap(([r,s])=>r?r.activeSheet$.pipe(D.switchMap(l=>{var f;if(!l)return D.of(!0);const c=r.getUnitId(),d=n.get(m.SheetsSelectionsService),u=n.get(m.RangeProtectionRuleModel),h=n.get(m.WorksheetProtectionRuleModel),g=(f=e.composePermission$([new m.WorkbookEditablePermission(c).id]).pipe(D.map(v=>v.every(p=>p.value))))!=null?f:D.of(!1),S=D.merge(u.ruleChange$,h.ruleChange$).pipe(D.startWith(null));return D.combineLatest([g,S,d.selectionMoveEnd$]).pipe(D.map(([v,p,C])=>{if(!v)return!0;const _=d.getCurrentSelections(),w=_==null?void 0:_.map(E=>E.range);return w!=null&&w.length?w.length>1:!1}))})):D.of(!0)))}function Bl(n){var d;const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),i=n.get(a.UserManagerService),r=n.has(me)?n.get(me):null,l=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_FX_BAR_EDITOR).pipe(D.startWith(!1),D.shareReplay(1)),c=(d=r==null?void 0:r.visible$.pipe(D.startWith(null),D.shareReplay(1)))!=null?d:D.of(null);return D.combineLatest([t,i.currentUser$,c,l]).pipe(D.switchMap(([u,h,g,S])=>!u||g!=null&&g.visible&&g.unitId===u.getUnitId()||S?D.of(!0):u.activeSheet$.pipe(D.switchMap(f=>{var A;if(!f)return D.of(!0);const p=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_COMMON_DRAWINGS).pipe(D.startWith(!1)),C=u.getUnitId(),_=f.getSheetId(),w=n.get(m.RangeProtectionRuleModel),E=n.get(m.WorksheetProtectionRuleModel),O=n.get(m.SheetsSelectionsService),R=(A=e.composePermission$([new m.WorkbookCreateProtectPermission(C).id]).pipe(D.map(k=>k.every(N=>N.value))))!=null?A:D.of(!1),P=D.merge(w.ruleChange$,E.ruleChange$).pipe(D.startWith(null));return D.combineLatest([R,P,O.selectionMoveEnd$,p]).pipe(D.map(([k,N,V,L])=>{if(!k||L)return!0;const H=O.getCurrentSelections(),W=H==null?void 0:H.map(F=>F.range);if(!(W!=null&&W.length))return!0;const B=E.getRule(C,_);if(B!=null&&B.permissionId)return!0;const U=w.getSubunitRuleList(C,_);return W==null?void 0:W.some(F=>U.some(Y=>Y.ranges.some(j=>a.Rectangle.intersects(F,j))))}))}))))}function Ug(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),i=n.get(a.UserManagerService);return D.combineLatest([t,i.currentUser$]).pipe(D.switchMap(([r,s])=>r?r.activeSheet$.pipe(D.switchMap(l=>{var f;if(!l)return D.of(!0);const c=r.getUnitId(),d=l.getSheetId(),u=n.get(m.RangeProtectionRuleModel),h=n.get(m.WorksheetProtectionRuleModel),g=(f=e.composePermission$([new m.WorkbookCreateProtectPermission(c).id]).pipe(D.map(v=>v.every(p=>p.value))))!=null?f:D.of(!1),S=D.merge(u.ruleChange$,h.ruleChange$).pipe(D.startWith(null));return D.combineLatest([g,S]).pipe(D.map(([v,p])=>{var w;if(!v)return!0;const C=h.getRule(c,d);return C!=null&&C.permissionId?!0:((w=u.getSubunitRuleList(c,d))==null?void 0:w.filter(E=>E==null?void 0:E.permissionId)).length>0}))})):D.of(!0)))}function Bg(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),i=n.get(a.UserManagerService);return D.combineLatest([t,i.currentUser$]).pipe(D.switchMap(([r,s])=>r?r.activeSheet$.pipe(D.switchMap(l=>{if(!l)return D.of(!0);const c=r.getUnitId(),d=l.getSheetId(),u=n.get(m.WorksheetProtectionRuleModel);return u.ruleChange$.pipe(D.startWith(null)).pipe(D.map(()=>{var g;return u.getRule(c,d)?((g=e.getPermissionPoint(new m.WorksheetDeleteProtectionPermission(c,d).id))==null?void 0:g.value)===!1:!0}))})):D.of(!0)))}function Fg(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),i=n.get(a.UserManagerService);return D.combineLatest([t,i.currentUser$]).pipe(D.switchMap(([r,s])=>r?r.activeSheet$.pipe(D.switchMap(l=>{var f;if(!l)return D.of(!0);const c=r.getUnitId(),d=n.get(m.RangeProtectionRuleModel),u=n.get(m.WorksheetProtectionRuleModel),h=(f=e.composePermission$([new m.WorkbookCreateProtectPermission(c).id,new m.WorkbookManageCollaboratorPermission(c).id]).pipe(D.map(v=>v.every(p=>p.value))))!=null?f:D.of(!1),g=u.ruleChange$.pipe(D.startWith(null)),S=d.ruleChange$.pipe(D.startWith(null));return D.combineLatest([h,g,S]).pipe(D.map(([v,p,C])=>{if(!v)return!0;const _=l.getSheetId(),w=u.getRule(c,_),E=d.getSubunitRuleList(c,_);return!(w||E.length)}))})):D.of(!0)))}function zg(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),i=n.get(a.UserManagerService);return D.combineLatest([t,i.currentUser$]).pipe(D.switchMap(([r,s])=>r?r.activeSheet$.pipe(D.switchMap(l=>{if(!l)return D.of(!0);const c=r.getUnitId(),d=l.getSheetId(),u=n.get(m.SheetsSelectionsService),h=n.get(m.RangeProtectionRuleModel),g=n.get(m.WorksheetProtectionRuleModel),S=D.merge(h.ruleChange$,g.ruleChange$,u.selectionMoveEnd$).pipe(D.startWith(null));return D.combineLatest([S]).pipe(D.map(([f])=>{var k;const v=n.get(m.SheetsSelectionsService).getCurrentSelections(),p=v==null?void 0:v.map(N=>N.range);if(!(p!=null&&p.length)||p.length>1)return!0;const C=p[0];if((C==null?void 0:C.rangeType)===a.RANGE_TYPE.ALL||(C==null?void 0:C.rangeType)===a.RANGE_TYPE.COLUMN||(C==null?void 0:C.rangeType)===a.RANGE_TYPE.ROW)return!0;const _=g.getRule(c,d);if(_!=null&&_.permissionId)return((k=e.getPermissionPoint(new m.WorksheetDeleteProtectionPermission(c,d).id))==null?void 0:k.value)===!1;if(h.getSubunitRuleList(c,d).filter(N=>N.ranges.some(V=>a.Rectangle.intersects(V,C))).length!==1)return!0;const{startRow:E,endRow:O,startColumn:R,endColumn:P}=C,A=n.get(m.RangeProtectionCache);for(let N=E;N<=O;N++)for(let V=R;V<=P;V++){const L=A.getCellInfo(c,d,N,V);if(L)return L[m.UnitAction.Delete]===!1}return!1}))})):D.of(!0)))}function Fl(n){var d;const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),i=n.get(a.UserManagerService),r=n.has(me)?n.get(me):null,l=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_FX_BAR_EDITOR),c=(d=r==null?void 0:r.visible$)!=null?d:D.of(null);return D.combineLatest([t,i.currentUser$,c,l]).pipe(D.switchMap(([u,h,g,S])=>!u||g!=null&&g.visible&&g.unitId===u.getUnitId()||S?D.of(!0):u.activeSheet$.pipe(D.switchMap(f=>{var C,_;if(!f)return D.of(!0);const v=u.getUnitId();return((_=(C=e.getPermissionPoint$(new m.WorkbookEditablePermission(v).id))==null?void 0:C.pipe(D.map(w=>!!w.value)))!=null?_:D.of(!1)).pipe(D.map(w=>!w))}))))}const vo="sheet.contextMenu.permission";function Xg(n){return{id:ri.id,type:I.MenuItemType.BUTTON,icon:va,tooltip:"permission.toolbarMenu",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:Bl(n)}}function Qr(n){return{id:vo,type:I.MenuItemType.SUBITEMS,title:"rightClick.protectRange",icon:pa,hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Jr(n){return{id:kt.id,type:I.MenuItemType.BUTTON,title:"rightClick.turnOnProtectRange",hidden$:Wg(n),disabled$:Bl(n)}}function $r(n){return{id:Ht.id,type:I.MenuItemType.BUTTON,title:"rightClick.editProtectRange",disabled$:xg(n),hidden$:Lg(n)}}function es(n){return{id:Vt.id,type:I.MenuItemType.BUTTON,title:"rightClick.removeProtectRange",disabled$:zg(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function ts(n){return{id:Nt.id,type:I.MenuItemType.BUTTON,title:"rightClick.viewAllProtectArea",disabled$:Fl(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Yg(n){return{id:si.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.addProtectSheet",disabled$:Ug(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function jg(n){return{id:pi.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.removeProtectSheet",disabled$:Bg(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Zg(n){return{id:Ci.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.changeSheetPermission",disabled$:Fg(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Gg(n){return{id:ai.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.viewAllProtectArea",disabled$:Fl(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Kg(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.ICommandService),t=new D.Observable(r=>{const s=e.onCommandExecuted(l=>{const c=l.id;(c===m.RemoveSheetMutation.id||c===m.InsertSheetMutation.id||c===m.SetWorksheetHideMutation.id)&&po(o,r)});return po(o,r),s.dispose}),i=Pn(n,[m.WorkbookEditablePermission,m.WorkbookDeleteSheetPermission]);return{id:ci.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.delete",disabled$:D.combineLatest([t,i]).pipe(D.map(([r,s])=>r||s)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function qg(n){return{id:m.CopySheetCommand.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.copy",disabled$:Pn(n,[m.WorkbookEditablePermission,m.WorkbookCreateSheetPermission]),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Qg(n){return{id:_i.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.rename",disabled$:Pn(n,[m.WorkbookEditablePermission,m.WorkbookRenameSheetPermission]),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Jg(n){return{id:m.SetTabColorCommand.id,title:"sheetConfig.changeColor",type:I.MenuItemType.SELECTOR,selections:[{label:{name:I.COLOR_PICKER_COMPONENT,hoverable:!1}}],hidden$:Pn(n,[m.WorkbookEditablePermission])}}function $g(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.ICommandService);return{id:m.SetWorksheetHideCommand.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.hide",disabled$:new D.Observable(t=>{const i=e.onCommandExecuted(r=>{const s=r.id;(s===m.RemoveSheetMutation.id||s===m.InsertSheetMutation.id||s===m.SetWorksheetHideMutation.id)&&po(o,t)});return po(o,t),i.dispose}).pipe(D.combineLatestWith(Pn(n,[m.WorkbookEditablePermission,m.WorkbookHideSheetPermission])),D.map(([t,i])=>t||i)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function eS(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.ICommandService);return{id:vi.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.unhide",disabled$:new D.Observable(t=>{function i(){const s=o.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getWorksheets(),l=Array.from(s.values());t.next(l.length===1)}const r=e.onCommandExecuted(s=>{const l=s.id;(l===m.RemoveSheetMutation.id||l===m.InsertSheetMutation.id||l===m.SetWorksheetHideMutation.id)&&i()});return i(),r.dispose}).pipe(D.combineLatestWith(Pn(n,[m.WorkbookEditablePermission,m.WorkbookHideSheetPermission])),D.map(([t,i])=>t||i)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function po(n,o){const e=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getWorksheets(),t=Array.from(e.values()).filter(i=>i.getConfig().hidden===a.BooleanNumber.FALSE);o.next(t.length===1)}const zl={[I.RibbonPosition.START]:{[I.RibbonStartGroup.HISTORY]:{[gn.id]:{order:2,menuItemFactory:sg},[m.ClearSelectionAllCommand.id]:{order:3,menuItemFactory:fo}},[I.RibbonStartGroup.FORMAT]:{[ln.id]:{order:1,menuItemFactory:ug},[ni.id]:{order:2,menuItemFactory:Zm},[Ki.id]:{order:2.1,menuItemFactory:Gm},[qi.id]:{order:2.2,menuItemFactory:Km},[Rt.id]:{order:5,menuItemFactory:ag},[Mt.id]:{order:6,menuItemFactory:lg},[Pt.id]:{order:7,menuItemFactory:cg},[Ot.id]:{order:8,menuItemFactory:dg},[cn.id]:{order:9,menuItemFactory:mg,[m.ResetTextColorCommand.id]:{order:0,menuItemFactory:hg}},[m.SetBackgroundColorCommand.id]:{order:10,menuItemFactory:Sg,[m.ResetBackgroundColorCommand.id]:{order:0,menuItemFactory:gg}},[m.SetBorderBasicCommand.id]:{order:11,menuItemFactory:Fm}},[I.RibbonStartGroup.LAYOUT]:{[m.SetHorizontalTextAlignCommand.id]:{order:0,menuItemFactory:fg},[m.SetVerticalTextAlignCommand.id]:{order:3,menuItemFactory:vg},[m.SetTextWrapCommand.id]:{order:6,menuItemFactory:pg},[m.SetTextRotationCommand.id]:{order:7,menuItemFactory:Cg},[m.AddWorksheetMergeCommand.id]:{order:8,menuItemFactory:Dg,[m.AddWorksheetMergeAllCommand.id]:{order:0,menuItemFactory:kg},[m.AddWorksheetMergeVerticalCommand.id]:{order:1,menuItemFactory:Ng},[m.AddWorksheetMergeHorizontalCommand.id]:{order:2,menuItemFactory:Vg},[m.RemoveWorksheetMergeCommand.id]:{order:3,menuItemFactory:Hg}}},[I.RibbonStartGroup.OTHERS]:{[ri.id]:{order:0,menuItemFactory:Xg}}},[I.ContextMenuPosition.MAIN_AREA]:{[I.ContextMenuGroup.FORMAT]:{[He.name]:{order:0,menuItemFactory:On},[We.name]:{order:2,menuItemFactory:xr},[yi]:{order:3,menuItemFactory:Ur,[on.id]:{order:0,menuItemFactory:Br},[rn.id]:{order:1,menuItemFactory:Fr},[Et.id]:{order:2,menuItemFactory:zr},[sn.id]:{order:3,menuItemFactory:Xr}},[So]:{order:4,menuItemFactory:Hr,[m.ClearSelectionContentCommand.id]:{order:0,menuItemFactory:Wr},[m.ClearSelectionFormatCommand.id]:{order:1,menuItemFactory:Lr},[m.ClearSelectionAllCommand.id]:{order:2,menuItemFactory:fo}}},[I.ContextMenuGroup.LAYOUT]:{order:1,[Al]:{order:0,menuItemFactory:Qm,[m.InsertRowBeforeCommand.id]:{order:0,menuItemFactory:Jm},[m.InsertColBeforeCommand.id]:{order:1,menuItemFactory:$m},[dn.id]:{order:2,menuItemFactory:eg},[At.id]:{order:3,menuItemFactory:tg}},[Rl]:{order:0,menuItemFactory:zm,[hn.id]:{order:0,menuItemFactory:Ml},[un.id]:{order:1,menuItemFactory:Pl},[an.id]:{order:2,menuItemFactory:Xm},[Tt.id]:{order:3,menuItemFactory:Ym}},[Wl]:{order:2,menuItemFactory:bg,[Je.id]:{order:0,menuItemFactory:jr},[hi.id]:{order:1,menuItemFactory:wg},[mi.id]:{order:2,menuItemFactory:Eg},[m.CancelFrozenCommand.id]:{order:3,menuItemFactory:Zr}},[vo]:{order:3,menuItemFactory:Qr,[kt.id]:{order:0,menuItemFactory:Jr},[Ht.id]:{order:1,menuItemFactory:$r},[Vt.id]:{order:2,menuItemFactory:es},[Nt.id]:{order:3,menuItemFactory:ts}}},[I.ContextMenuGroup.DATA]:{order:2},[I.ContextMenuGroup.OTHERS]:{order:3}},[I.ContextMenuPosition.COL_HEADER]:{[I.ContextMenuGroup.FORMAT]:{[He.name]:{order:0,menuItemFactory:On},[We.name]:{order:2,menuItemFactory:xr},[yi]:{order:3,menuItemFactory:Ur,[on.id]:{order:0,menuItemFactory:Br},[rn.id]:{order:1,menuItemFactory:Fr},[Et.id]:{order:2,menuItemFactory:zr},[sn.id]:{order:3,menuItemFactory:Xr}},[So]:{order:4,menuItemFactory:Hr,[m.ClearSelectionContentCommand.id]:{order:0,menuItemFactory:Wr},[m.ClearSelectionFormatCommand.id]:{order:1,menuItemFactory:Lr},[m.ClearSelectionAllCommand.id]:{order:2,menuItemFactory:fo}}},[I.ContextMenuGroup.LAYOUT]:{order:1,[m.InsertMultiColsLeftCommand.id]:{order:0,menuItemFactory:og},[m.InsertMultiColsRightCommand.id]:{order:0,menuItemFactory:rg},[ti.id]:{order:1,menuItemFactory:yg},[m.SetSelectedColsVisibleCommand.id]:{order:2,menuItemFactory:Mg},[hn.id]:{order:2,menuItemFactory:Ml},[m.SetColWidthCommand.id]:{order:3,menuItemFactory:Og},[pn.id]:{order:4,menuItemFactory:_g},[Yr]:{order:5,menuItemFactory:Ll,[Je.id]:{order:0,menuItemFactory:jr},[m.CancelFrozenCommand.id]:{order:3,menuItemFactory:Zr}},[vo]:{order:6,menuItemFactory:Qr,[kt.id]:{order:0,menuItemFactory:Jr},[Ht.id]:{order:1,menuItemFactory:$r},[Vt.id]:{order:2,menuItemFactory:es},[Nt.id]:{order:3,menuItemFactory:ts}}},[I.ContextMenuGroup.DATA]:{order:2},[I.ContextMenuGroup.OTHERS]:{order:3}},[I.ContextMenuPosition.ROW_HEADER]:{[I.ContextMenuGroup.FORMAT]:{[He.name]:{order:0,menuItemFactory:On},[We.name]:{order:2,menuItemFactory:xr},[yi]:{order:3,menuItemFactory:Ur,[on.id]:{order:0,menuItemFactory:Br},[rn.id]:{order:1,menuItemFactory:Fr},[Et.id]:{order:2,menuItemFactory:zr},[sn.id]:{order:3,menuItemFactory:Xr}},[So]:{order:4,menuItemFactory:Hr,[m.ClearSelectionContentCommand.id]:{order:0,menuItemFactory:Wr},[m.ClearSelectionFormatCommand.id]:{order:1,menuItemFactory:Lr},[m.ClearSelectionAllCommand.id]:{order:2,menuItemFactory:fo}}},[I.ContextMenuGroup.LAYOUT]:{order:1,[m.InsertMultiRowsAboveCommand.id]:{order:0,menuItemFactory:ig},[m.InsertMultiRowsAfterCommand.id]:{order:1,menuItemFactory:ng},[un.id]:{order:1,menuItemFactory:Pl},[ei.id]:{order:2,menuItemFactory:Tg},[m.SetSelectedRowsVisibleCommand.id]:{order:2,menuItemFactory:Rg},[m.SetRowHeightCommand.id]:{order:3,menuItemFactory:Pg},[m.SetWorksheetRowIsAutoHeightCommand.id]:{order:4,menuItemFactory:Ig},[Yr]:{order:5,menuItemFactory:Ll,[Je.id]:{order:0,menuItemFactory:jr},[m.CancelFrozenCommand.id]:{order:3,menuItemFactory:Zr}},[vo]:{order:6,menuItemFactory:Qr,[kt.id]:{order:0,menuItemFactory:Jr},[Ht.id]:{order:1,menuItemFactory:$r},[Vt.id]:{order:2,menuItemFactory:es},[Nt.id]:{order:3,menuItemFactory:ts}}},[I.ContextMenuGroup.DATA]:{order:2},[I.ContextMenuGroup.OTHERS]:{order:3}},[I.ContextMenuPosition.FOOTER_TABS]:{[I.ContextMenuGroup.OTHERS]:{order:0,[ci.id]:{order:0,menuItemFactory:Kg},[m.CopySheetCommand.id]:{order:1,menuItemFactory:qg},[_i.id]:{order:2,menuItemFactory:Qg},[m.SetTabColorCommand.id]:{order:3,menuItemFactory:Jg},[m.SetWorksheetHideCommand.id]:{order:4,menuItemFactory:$g},[vi.id]:{order:6,menuItemFactory:eS},[si.id]:{order:7,menuItemFactory:Yg},[pi.id]:{order:8,menuItemFactory:jg},[Ci.id]:{order:9,menuItemFactory:Zg},[ai.id]:{order:10,menuItemFactory:Gg}}},[I.ContextMenuPosition.FOOTER_MENU]:{[I.ContextMenuGroup.OTHERS]:{[m.ToggleGridlinesCommand.id]:{order:1,menuItemFactory:qm}}}},ns="UNIVER_SHEET_PERMISSION_ALERT_DIALOG_ID",Xl="UNIVER_SHEET_PERMISSION_ALERT_DIALOG";var tS=Object.getOwnPropertyDescriptor,nS=(n,o,e,t)=>{for(var i=t>1?void 0:t?tS(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},tt=(n,o)=>(e,t)=>o(e,t,n);T.SheetPermissionCheckUIController=class extends a.Disposable{constructor(e,t,i,r,s,l,c,d,u){super();y(this,"disposableCollection",new a.DisposableCollection);this._commandService=e,this._univerInstanceService=t,this._permissionService=i,this._dialogService=r,this._rangeProtectionRuleModel=s,this._autoFillService=l,this._localeService=c,this._contextService=d,this._sheetPermissionCheckController=u,this._initialize(),this._initUIEvent()}_initUIEvent(){this.disposeWithMe(this._sheetPermissionCheckController.triggerPermissionUIEvent$.subscribe(e=>{this._haveNotPermissionHandle(e)}))}_haveNotPermissionHandle(e){const t={id:ns,title:{title:"permission.dialog.alert"},children:{label:Xl,errorMsg:e},width:320,destroyOnClose:!0,showOk:!0,onClose:()=>{this._dialogService.close(ns)},onOk:()=>{this._dialogService.close(ns)},className:"sheet-permission-user-dialog"};this._permissionService.getShowComponents()&&this._dialogService.open(t)}_getPermissionCheck(e,t){var s,l;let i=!0,r="";switch(e){case K.InsertCommand.id:case K.IMEInputCommand.id:if(this._contextService.getContextValue(a.FOCUSING_EDITOR_STANDALONE)===!0)break;i=this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellValuePermission,m.WorksheetEditPermission]}),r=this._localeService.t("permission.dialog.editErr");break;case Se.id:if(t.visible===!1)break;i=this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellValuePermission,m.WorksheetEditPermission]}),r=this._localeService.t("permission.dialog.editErr");break;case Et.id:i=this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission]}),r=this._localeService.t("permission.dialog.pasteErr");break;case Zi.id:i=this._permissionCheckByPaste(t),r=this._localeService.t("permission.dialog.pasteErr");break;case ui.id:i=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellValuePermission,m.WorksheetSetCellStylePermission]}),r=this._localeService.t("permission.dialog.commonErr");break;case m.SetBackgroundColorCommand.id:case Rt.id:case Mt.id:case Pt.id:case Ot.id:i=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellStylePermission,m.WorksheetEditPermission]}),r=this._localeService.t("permission.dialog.setStyleErr");break;case He.id:i=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookCopyPermission],rangeTypes:[m.RangeProtectionPermissionViewPoint],worksheetTypes:[m.WorksheetCopyPermission]}),r=this._localeService.t("permission.dialog.copyErr"),(s=this._permissionService.getPermissionPoint(new m.WorkbookCopyPermission(this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).id))!=null&&s.value||(r=this._localeService.t("permission.dialog.workbookCopyErr"));break;case ji.id:i=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookCopyPermission,m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionViewPoint,m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetCopyPermission,m.WorksheetEditPermission]}),r=this._localeService.t("permission.dialog.copyErr"),(l=this._permissionService.getPermissionPoint(new m.WorkbookCopyPermission(this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).id))!=null&&l.value||(r=this._localeService.t("permission.dialog.workbookCopyErr"));break;case dt.id:i=this._permissionCheckByAutoFillCommand(t),r=this._localeService.t("permission.dialog.autoFillErr");break}i||this._sheetPermissionCheckController.blockExecuteWithoutPermission(r)}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{this._getPermissionCheck(e.id,e==null?void 0:e.params)}))}_permissionCheckByPaste(e){return e.value===ge.SPECIAL_PASTE_VALUE||e.value===ge.SPECIAL_PASTE_FORMULA?this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellStylePermission,m.WorksheetEditPermission]}):e.value===ge.SPECIAL_PASTE_FORMAT?this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellStylePermission,m.WorksheetEditPermission]}):this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellValuePermission,m.WorksheetSetCellStylePermission,m.WorksheetEditPermission]})}_permissionCheckByAutoFillCommand(e){if(!e)return!1;const{targetRange:t}=e,i=m.getSheetCommandTarget(this._univerInstanceService);if(!i)return!1;const{worksheet:r,unitId:s,subUnitId:l}=i;return!this._rangeProtectionRuleModel.getSubunitRuleList(s,l).reduce((u,h)=>[...u,...h.ranges],[]).filter(u=>a.Rectangle.intersects(u,t)).some(u=>{var h,g;for(let S=u.startRow;S<=u.endRow;S++)for(let f=u.startColumn;f<=u.endColumn;f++){const v=(g=(h=r.getCell(S,f))==null?void 0:h.selectionProtection)==null?void 0:g[0];if((v==null?void 0:v[$.Edit])===!1)return!0}return!1})}},T.SheetPermissionCheckUIController=nS([tt(0,a.ICommandService),tt(1,a.IUniverInstanceService),tt(2,a.IPermissionService),tt(3,I.IDialogService),tt(4,a.Inject(m.RangeProtectionRuleModel)),tt(5,ct),tt(6,a.Inject(a.LocaleService)),tt(7,a.IContextService),tt(8,a.Inject(m.SheetPermissionCheckController))],T.SheetPermissionCheckUIController);var iS=Object.getOwnPropertyDescriptor,oS=(n,o,e,t)=>{for(var i=t>1?void 0:t?iS(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},Yt=(n,o)=>(e,t)=>o(e,t,n);const rS="__SpreadsheetFreezeRowMainName__",sS="__SpreadsheetFreezeRowHeaderName__",aS="__SpreadsheetFreezeColumnMainName__",lS="__SpreadsheetFreezeColumnHeaderName__",is=2,cS=.01,Mi=a.createInterceptorKey("freezePermissionCheck");T.HeaderFreezeRenderController=class extends a.Disposable{constructor(e,t,i,r,s,l,c,d){super();y(this,"_rowFreezeHeaderRect");y(this,"_rowFreezeMainRect");y(this,"_columnFreezeHeaderRect");y(this,"_columnFreezeMainRect");y(this,"_freezeDownSubs");y(this,"_freezePointerEnterSubs");y(this,"_freezePointerLeaveSubs");y(this,"_scenePointerMoveSub");y(this,"_scenePointerUpSub");y(this,"_changeToRow",-1);y(this,"_changeToColumn",-1);y(this,"_changeToOffsetX",0);y(this,"_changeToOffsetY",0);y(this,"_activeViewport",null);y(this,"_freezeNormalHeaderColor","");y(this,"_freezeNormalMainColor","");y(this,"_freezeActiveColor","");y(this,"_freezeHoverColor","");y(this,"_lastFreeze");y(this,"interceptor",new a.InterceptorManager({FREEZE_PERMISSION_CHECK:Mi}));this._context=e,this._sheetSkeletonManagerService=t,this._commandService=i,this._selectionManagerService=r,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 A;const i=t!=null?t:this._getFreeze();if(i==null)return null;const r=(A=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:A.skeleton,{startRow:s,startColumn:l}=i,c=this._getPositionByIndex(s,l);if(c==null||r==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:v}=c,{rowTotalHeight:p,columnTotalWidth:C,rowHeaderWidthAndMarginLeft:_,columnHeaderHeightAndMarginTop:w}=r,E=h>C+_?h:C+w,O=g>p+w?g:p+w;this._changeToRow=s,this._changeToColumn=l,this._changeToOffsetX=f,this._changeToOffsetY=v;const R=Math.max(S.scaleX,S.scaleY);let P=is/Math.max(1,R);if(e===0){(s===-1||s===0)&&(P=P*2);const k=P;this._rowFreezeHeaderRect=new M.Rect(sS,{fill:this._freezeNormalHeaderColor,width:_,height:P,left:0,top:v-k,zIndex:3});let N=this._freezeNormalHeaderColor;(s===-1||s===0)&&(N=this._freezeNormalMainColor),this._rowFreezeMainRect=new M.Rect(rS,{fill:N,width:E*2/R,height:P,left:_,top:v-k,zIndex:3}),S.addObjects([this._rowFreezeHeaderRect,this._rowFreezeMainRect],rt)}else{(l===-1||l===0)&&(P=P*2);const k=P;this._columnFreezeHeaderRect=new M.Rect(lS,{fill:this._freezeNormalHeaderColor,width:P,height:w,left:f-k,top:0,zIndex:3});let N=this._freezeNormalHeaderColor;(l===-1||l===0)&&(N=this._freezeNormalMainColor),this._columnFreezeMainRect=new M.Rect(aS,{fill:N,width:P,height:O*2/R,left:f-k,top:w,zIndex:3}),S.addObjects([this._columnFreezeHeaderRect,this._columnFreezeMainRect],rt)}this._eventBinding(e)}_eventBinding(e=0){let t=this._rowFreezeHeaderRect,i=this._rowFreezeMainRect;e===1&&(t=this._columnFreezeHeaderRect,i=this._columnFreezeMainRect);const r=this._getSheetObject();if(r==null)return;const{scene:s}=r;if(this._freezePointerEnterSubs=new D.Subscription,this._freezePointerLeaveSubs=new D.Subscription,this._freezeDownSubs=new D.Subscription,i){const d=i.onPointerEnter$.subscribeEvent(()=>{if(!this.interceptor.fetchThroughInterceptors(Mi)(!0,null))return!1;t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),s.setCursor(M.CURSOR_TYPE.GRAB)});this._freezePointerEnterSubs.add(d);const u=i.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(Mi)(!0,null))return!1;t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),s.setCursor(M.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,i,e)});l&&this._freezeDownSubs.add(l);const c=i==null?void 0:i.onPointerDown$.subscribeEvent(d=>{this._freezeDown(d,t,i,e)});c&&this._freezeDownSubs.add(c)}_getCurrentLastVisible(){var C,_,w,E,O,R,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 i=e.scene,r=Math.max(i.scaleX,i.scaleY),s=this._scrollManagerService.getCurrentScrollState(),l=(e.engine.height-t.columnHeaderHeight)/r,c=(e.engine.width-t.rowHeaderWidth)/r,d=(_=s==null?void 0:s.sheetViewStartRow)!=null?_:0,u=d===0?-((w=s==null?void 0:s.offsetY)!=null?w:0):t.rowHeightAccumulation[d-1]-((E=s==null?void 0:s.offsetY)!=null?E:0);let h=0,g=!1;for(let A=d,k=t.rowHeightAccumulation.length;A<k;A++)if(t.rowHeightAccumulation[A]-u>l){h=A,g=!0;break}g||(h=t.rowHeightAccumulation.length-1);const S=(O=s==null?void 0:s.sheetViewStartColumn)!=null?O:0,f=S===0?-((R=s==null?void 0:s.offsetX)!=null?R:0):t.columnWidthAccumulation[S-1]-((P=s==null?void 0:s.offsetX)!=null?P:0);let v=0,p=!1;for(let A=S,k=t.columnWidthAccumulation.length;A<k;A++)if(t.columnWidthAccumulation[A]-f>c){v=A,p=!0;break}return p||(v=t.columnWidthAccumulation.length-1),{lastRow:h,lastColumn:v}}_getActiveViewport(e){var i;const t=(i=this._getSheetObject())==null?void 0:i.scene.getViewports();return t&&t.find(r=>r.isHit(new M.Vector2(e.offsetX,e.offsetY)))||null}_freezeDown(e,t,i,r=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(Mi)(!0,null))return!1;const{scene:d}=l;d.setCursor(M.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(v=>{var P,A,k,N;const p=this._getActiveViewport(v),{startX:C,startY:_,row:w,column:E}=Xe(v.offsetX,v.offsetY,d,s,p||void 0,!0);if(!this.interceptor.fetchThroughInterceptors(Mi)(!0,null))return!1;d.setCursor(M.CURSOR_TYPE.GRABBING);const R=is/Math.max(d.scaleX,d.scaleY);r===0?((P=t.transformByState({top:Math.min(_,h)-R/2}))==null||P.setProps({fill:this._freezeActiveColor}),(A=i.transformByState({top:Math.min(_,h)-R/2}))==null||A.setProps({fill:this._freezeNormalHeaderColor}),this._changeToRow=u===void 0?w:Math.min(w,u.lastRow),this._changeToOffsetY=Math.min(_,h),this._activeViewport=p):((k=t.transformByState({left:Math.min(C,g)-R/2}))==null||k.setProps({fill:this._freezeActiveColor}),(N=i.transformByState({left:Math.min(C,g)-R/2}))==null||N.setProps({fill:this._freezeNormalHeaderColor}),this._changeToColumn=u===void 0?E:Math.min(E,u.lastColumn),this._changeToOffsetX=C,this._activeViewport=p)}),this._scenePointerUpSub=d.onPointerUp$.subscribeEvent(()=>{var V,L;d.resetCursor(),d.enableObjectsEvent(),this._clearObserverEvent();const{rowHeaderWidthAndMarginLeft:v,columnHeaderHeightAndMarginTop:p}=s;r===0&&(this._changeToRow===0||this._changeToRow===-1)||r===1&&(this._changeToColumn===0||this._changeToColumn===-1)?(t.setProps({fill:this._freezeNormalHeaderColor}),i.setProps({fill:this._freezeNormalMainColor})):(t==null||t.setProps({fill:this._freezeNormalHeaderColor}),i==null||i.setProps({fill:this._freezeNormalHeaderColor}));const C=is/Math.max(d.scaleX,d.scaleY);r===0?(this._changeToRow===0||this._changeToRow===-1)&&(t.transformByState({top:p-C}),i.transformByState({top:p-C})):(this._changeToColumn===0||this._changeToColumn===-1)&&(t.transformByState({left:v-C}),i.transformByState({left:v-C}));const _=this._scrollManagerService.getCurrentScrollState()||{sheetViewStartRow:0,sheetViewStartColumn:0},{sheetViewStartRow:w,sheetViewStartColumn:E}=_;if(E==null||w==null)return;const O=this._context.unit,R=O.getActiveSheet();if(!R)return;const P=(V=R.getConfig())==null?void 0:V.freeze;let A=(P==null?void 0:P.xSplit)||0,k=(P==null?void 0:P.ySplit)||0;const N=(L=this._activeViewport)==null?void 0:L.viewportKey;r===0&&(!N||N===M.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP||N===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP||N===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||N===M.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP?k=this._changeToRow-(P.startRow-P.ySplit):k=this._changeToRow-w,k=k<0?0:k),r===1&&(!N||N===M.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP||N===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP||N===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||N===M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT?A=this._changeToColumn-(P.startColumn-P.xSplit):A=this._changeToColumn-E,A=A<0?0:A),this._commandService.executeCommand(m.SetFrozenCommand.id,{startRow:k===0?-1:this._changeToRow,startColumn:A===0?-1:this._changeToColumn,ySplit:k,xSplit:A,unitId:O.getUnitId(),subUnitId:R.getSheetId()})})}_getViewports(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e,i=t.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT),r=t.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT),s=t.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP),l=t.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM),c=t.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP),d=t.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN),u=t.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP),h=t.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT),g=t.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(!(i==null||r==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:i,viewColumnRight:r,viewRowTop:s,viewRowBottom:l,viewLeftTop:c}}_bindViewportScroll(){const e=this._getViewports();if(!e)return;const{viewRowBottom:t,viewColumnRight:i,viewMainLeft:r,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}),i.isActive&&i.updateScrollVal({scrollX:c,viewportScrollX:u}),r.isActive&&r.updateScrollVal({scrollY:d,viewportScrollY:h}),s.isActive&&s.updateScrollVal({scrollX:c,viewportScrollX:u})}))}_updateViewport(e=-1,t=-1,i=0,r=0,s=3){var A;const l=(A=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:A.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:v,viewColumnRight:p,viewRowTop:C,viewRowBottom:_,viewLeftTop:w}=u;p.resizeWhenFreezeChange({left:c,top:0,height:d+1,right:0}),_.resizeWhenFreezeChange({left:0,top:d,bottom:0,width:c+1}),w.resizeWhenFreezeChange({left:0,top:0,width:c+1,height:d});let E=!0,O=!0;g.enable(),(e===-1||e===0)&&(E=!1),(t===-1||t===0)&&(O=!1);const R=l.getNoMergeCellWithCoordByIndex(e-i,t-r,!1),P=l.getNoMergeCellWithCoordByIndex(e,t,!1);if(g.disable(),f.disable(),S.disable(),C.disable(),v.disable(),g.resetPadding(),f.resetPadding(),S.resetPadding(),C.resetPadding(),v.resetPadding(),E===!1&&O===!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+1,height:0}),v.resizeWhenFreezeChange({left:0,top:0,height:d+1,width:0});else if(E===!0&&O===!1){const k=P.startY-R.startY;h.resizeWhenFreezeChange({left:c,top:d+k,bottom:0,right:0}),h.setPadding({startY:R.startY,endY:P.startY,startX:0,endX:0}),s&2&&this._commandService.executeCommand(Le.id,{sheetViewStartRow:0,offsetY:0}),f.resizeWhenFreezeChange({left:c,top:d,height:k,right:0}),f.updateScrollVal({viewportScrollY:R.startY,rawScrollX:h.scrollX,viewportScrollX:h.viewportScrollX}),C.resizeWhenFreezeChange({left:0,top:d,width:c+1,height:k}),C.updateScrollVal({viewportScrollY:R.startY}),_.resizeWhenFreezeChange({left:0,top:d+k,bottom:0,width:c+1}),f.enable(),C.enable()}else if(E===!1&&O===!0){const k=P.startX-R.startX;h.resizeWhenFreezeChange({left:c+k,top:d,bottom:0,right:0}),h.setPadding({startX:R.startX,endX:P.startX,startY:0,endY:0}),s&1&&this._commandService.executeCommand(Le.id,{sheetViewStartColumn:0,offsetX:0}),S.resizeWhenFreezeChange({left:c,top:d,width:k,bottom:0,right:0}),S.updateScrollVal({viewportScrollX:R.startX,rawScrollY:h.scrollY,viewportScrollY:h.viewportScrollY}),v.resizeWhenFreezeChange({left:c,top:0,width:k,height:d+1}),v.updateScrollVal({viewportScrollX:R.startX}),p.resizeWhenFreezeChange({left:c+k,top:0,height:d+1,right:0}),S.enable(),v.enable()}else{const k=P.startX-R.startX,N=P.startY-R.startY;h.resizeWhenFreezeChange({left:c+k,top:d+N,bottom:0,right:0}),h.setPadding({startY:R.startY,endY:P.startY,startX:R.startX,endX:P.startX}),s&&this._commandService.executeCommand(Le.id,{...s&1?{sheetViewStartColumn:0,offsetX:0}:null,...s&2?{sheetViewStartRow:0,offsetY:0}:null}),S.resizeWhenFreezeChange({left:c,top:d+N,width:k,bottom:0}),S.updateScrollVal({viewportScrollX:R.startX,rawScrollY:h.scrollY,viewportScrollY:h.viewportScrollY}),f.resizeWhenFreezeChange({left:c+k,top:d,height:N,right:0}),f.updateScrollVal({viewportScrollY:R.startY,rawScrollX:h.scrollX,viewportScrollX:h.viewportScrollX}),g.resizeWhenFreezeChange({left:c,top:d,width:k,height:N}),g.updateScrollVal({viewportScrollX:R.startX,viewportScrollY:R.startY}),C.resizeWhenFreezeChange({left:0,top:d,width:c+1,height:N}),C.updateScrollVal({viewportScrollY:R.startY}),_.resizeWhenFreezeChange({left:0,top:d+N,bottom:0,width:c+1}),v.resizeWhenFreezeChange({left:c,top:0,width:k,height:d+1}),v.updateScrollVal({viewportScrollX:R.startX}),p.resizeWhenFreezeChange({left:c+k,top:0,height:d+1,right:0}),g.enable(),f.enable(),S.enable(),C.enable(),v.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 i=t.getConfig().freeze,{startRow:r=-1,startColumn:s=-1,ySplit:l=0,xSplit:c=0}=i;this._refreshFreeze(r,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=a.get(e,"gray.300"),this._freezeNormalMainColor=new a.ColorKit(this._freezeNormalHeaderColor).setAlpha(cS).toRgbString(),this._freezeActiveColor=a.get(e,"primary.600"),this._freezeHoverColor=a.get(e,"gray.500")}_interceptorCommands(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{const t={redos:[],undos:[]},i=this._getFreeze();if(!i)return t;const r=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<i.startRow||l.startRow+1===i.startRow&&c===a.Direction.UP){const u={...i,startRow:Math.max(1,i.startRow+d),ySplit:Math.max(1,i.ySplit+d)};return r(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<i.startColumn||l.startColumn+1===i.startColumn&&c===a.Direction.LEFT){const u={...i,startColumn:Math.max(1,i.startColumn+d),xSplit:Math.max(1,i.xSplit+d)};return r(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(!i||i.startColumn<=0||u.startColumn>=i.startColumn&&h.startColumn>=i.startColumn||u.startColumn===h.startColumn||u.endColumn<i.startColumn&&h.startColumn<i.startColumn)return t;const g=u.endColumn-u.startColumn+1,S=Math.max(Math.min(i.startColumn,u.endColumn+1)-u.startColumn,0);let f,v;h.startColumn>=i.startColumn?(f=Math.max(i.startColumn-S,1),v=Math.max(i.xSplit-S,1)):(f=i.startColumn+g-S,v=i.xSplit+g-S);const p={...i,startColumn:f,xSplit:v};return r(p)}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(!i||i.startRow<=0||u.startRow>=i.startRow&&h.startRow>=i.startRow||u.startRow===h.startRow||u.endRow<i.startRow&&h.startRow<i.startRow)return t;const g=u.endRow-u.startRow+1,S=Math.max(Math.min(i.startRow,u.endRow+1)-u.startRow,0);let f,v;h.startRow>=i.startRow?(f=Math.max(i.startRow-S,1),v=Math.max(i.ySplit-S,1)):(f=i.startRow+g-S,v=i.ySplit+g-S);const p={...i,startRow:f,ySplit:v};return r(p)}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<i.startColumn){const c=Math.min(i.startColumn,l.endColumn+1)-l.startColumn,d={...i,startColumn:Math.max(1,i.startColumn-c),xSplit:Math.max(1,i.xSplit-c)};return r(d)}if(s.range.rangeType===a.RANGE_TYPE.ROW&&l.startRow<i.startRow){const c=Math.min(i.startRow,l.endRow+1)-l.startRow,d={...i,startRow:Math.max(1,i.startRow-c),ySplit:Math.max(1,i.ySplit-c)};return r(d)}}return t}}))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{switch(e.id){case m.SetFrozenMutation.id:case Ye.id:{const t=this._lastFreeze,i=this._context.unit,r=i.getActiveSheet(),s=e.params,{unitId:l,subUnitId:c}=s;if(!(l===i.getUnitId()&&c===(r==null?void 0:r.getSheetId())))return;const d=r.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(),i=t&&e.params.ranges.some(r=>r.startRow<t.startRow);e.params&&i&&this._refreshCurrent()}break;case m.SetWorksheetColWidthMutation.id:{const t=this._getFreeze();e.params&&t&&e.params.ranges.some(i=>i.startColumn<t.startColumn)&&this._refreshCurrent()}break;case m.SetWorksheetRowAutoHeightMutation.id:{const t=e.params,i=this._getFreeze();if(i&&i.startRow>-1&&t.rowsAutoHeightInfo.some(r=>r.row<i.startRow)){const r=this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._refreshCurrent(),setTimeout(()=>{r.unsubscribe()})})}}break;case m.SetColHiddenMutation.id:case m.SetColVisibleMutation.id:{const t=e.params,i=this._getFreeze(),r=t.ranges;i&&i.startColumn>-1&&r.some(s=>s.startColumn<i.startColumn)&&this._refreshCurrent()}break;case m.SetRowHiddenMutation.id:case m.SetRowVisibleMutation.id:{const t=e.params,i=this._getFreeze(),r=t.ranges;i&&i.startRow>-1&&r.some(s=>s.startRow<i.startRow)&&this._refreshCurrent()}break;case Xn.id:case Yn.id:this._refreshCurrent()}}))}_zoomRefresh(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;this.disposeWithMe(t.onTransformChange$.subscribeEvent(i=>{[M.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale,M.TRANSFORM_CHANGE_OBSERVABLE_TYPE.all].includes(i.type)&&this._refreshCurrent()}))}_clearObserverEvent(){var t,i;this._getSheetObject()!=null&&((t=this._scenePointerMoveSub)==null||t.unsubscribe(),(i=this._scenePointerUpSub)==null||i.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null)}_clearFreeze(){var t,i,r,s,l,c;(t=this._rowFreezeHeaderRect)==null||t.dispose(),(i=this._rowFreezeMainRect)==null||i.dispose(),(r=this._columnFreezeHeaderRect)==null||r.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 r=(d=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:d.skeleton,s=r==null?void 0:r.getNoMergeCellWithCoordByIndex(e,t);if(r==null)return;if(s!=null&&(!isNaN(s.endX)||!isNaN(s.endY)))return s;const{rowHeaderWidthAndMarginLeft:l,columnHeaderHeightAndMarginTop:c}=r;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 Ve(this._context.unit,this._context)}_refreshFreeze(e,t,i,r,s){var c;const l={startRow:e,startColumn:t,ySplit:i,xSplit:r};this._clearFreeze(),this._createFreeze(0,l),this._createFreeze(1,l),this._updateViewport(e,t,i,r,s),(c=this._getSheetObject())==null||c.spreadsheet.makeForceDirty()}},T.HeaderFreezeRenderController=oS([Yt(1,a.Inject(T.SheetSkeletonManagerService)),Yt(2,a.ICommandService),Yt(3,a.Inject(m.SheetsSelectionsService)),Yt(4,a.Inject(T.SheetScrollManagerService)),Yt(5,a.Inject(a.ThemeService)),Yt(6,a.Inject(m.SheetInterceptorService)),Yt(7,a.Inject(a.Injector))],T.HeaderFreezeRenderController);var dS=Object.getOwnPropertyDescriptor,uS=(n,o,e,t)=>{for(var i=t>1?void 0:t?dS(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},os=(n,o)=>(e,t)=>o(e,t,n);const hS="__SpreadsheetHeaderMoveControllerBackground__",mS="__SpreadsheetHeaderMoveControllerShapeLine__",gS="rgba(0, 0, 0, 0.1)",SS="rgb(119, 119, 119)",fS=4,rs=a.createInterceptorKey("headerMovePermissionCheck");T.HeaderMoveRenderController=class extends a.Disposable{constructor(e,t,i,r){super();y(this,"_startOffsetX",Number.NEGATIVE_INFINITY);y(this,"_startOffsetY",Number.NEGATIVE_INFINITY);y(this,"_moveHelperBackgroundShape");y(this,"_moveHelperLineShape");y(this,"_headerPointerDownSubs");y(this,"_headerPointerMoveSubs");y(this,"_headerPointerLeaveSubs");y(this,"_dragHeaderMoveSub");y(this,"_scenePointerUpSub");y(this,"_scrollTimer");y(this,"_changeFromColumn",-1);y(this,"_changeFromRow",-1);y(this,"_changeToColumn",-1);y(this,"_changeToRow",-1);y(this,"interceptor",new a.InterceptorManager({HEADER_MOVE_PERMISSION_CHECK:rs}));y(this,"_workbookSelections");this._context=e,this._sheetSkeletonManagerService=i,this._commandService=r,this._workbookSelections=t.getWorkbookSelections(this._context.unitId),this._init()}dispose(){var e,t,i,r,s,l,c,d;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(t=this._moveHelperLineShape)==null||t.dispose(),(i=this._headerPointerMoveSubs)==null||i.unsubscribe(),(r=this._headerPointerLeaveSubs)==null||r.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),i=this._context.components.get(he.ROW),r=this._context.scene,s=e===a.RANGE_TYPE.ROW?i:t,l=u=>{var _,w;const h=(_=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:_.skeleton;if(h==null)return;const g=(w=this._workbookSelections.getCurrentLastSelection())==null?void 0:w.range;if(!g||!this.interceptor.fetchThroughInterceptors(rs)(!1,g))return;const f=this._workbookSelections.getCurrentSelections(),{row:v,column:p}=Xe(u.offsetX,u.offsetY,r,h);if(!Ri(f,e===a.RANGE_TYPE.ROW?v:p,e)){r.resetCursor();return}r.setCursor(M.CURSOR_TYPE.GRAB)},c=()=>{var u,h;(u=this._moveHelperBackgroundShape)==null||u.hide(),(h=this._moveHelperLineShape)==null||h.hide(),r.resetCursor()},d=(u,h)=>{var H,W;if(h.isStopPropagation)return;const g=(H=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:H.skeleton;if(g==null)return;const S=(W=this._workbookSelections.getCurrentLastSelection())==null?void 0:W.range;if(!S||!this.interceptor.fetchThroughInterceptors(rs)(!1,S))return;const{offsetX:v,offsetY:p}=u,C=r.getCoordRelativeToViewport(M.Vector2.FromArray([v,p])),{x:_,y:w}=C;this._startOffsetX=_,this._startOffsetY=w;const{row:E,column:O}=Xe(u.offsetX,u.offsetY,r,g);let R;e===a.RANGE_TYPE.ROW?(this._changeFromRow=E,R=M.ScrollTimerType.Y):(this._changeFromColumn=O,R=M.ScrollTimerType.X);const P=this._workbookSelections.getCurrentSelections(),A=Ri(P,e===a.RANGE_TYPE.ROW?E:O,e);if(!A)return;const k=r.getScrollXYInfoByViewport(M.Vector2.FromArray([this._startOffsetX,this._startOffsetY]));this._newBackgroundAndLine(),r.setCursor(M.CURSOR_TYPE.GRABBING),r.disableObjectsEvent();let N=!1,V;const L=()=>{if(N)return;V=M.ScrollTimer.create(r,R),this._scrollTimer=V;const B=r.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN);V.startScroll(_,w,B),N=!0};this._dragHeaderMoveSub=r.onPointerMove$.subscribeEvent(B=>{L();const{offsetX:U,offsetY:X}=B,{x:F,y:Y}=r.getCoordRelativeToViewport(M.Vector2.FromArray([U,X]));this._rowColumnMoving(F,Y,A,k,e),V.scrolling(F,Y,()=>{this._rowColumnMoving(F,Y,A,k,e)})}),this._scenePointerUpSub=r.onPointerUp$.subscribeEvent(()=>{var U,X,F;this._disposeBackgroundAndLine(),r.resetCursor(),r.enableObjectsEvent(),this._clearObserverEvent(),(U=this._scrollTimer)==null||U.dispose();const B=this._workbookSelections.getCurrentSelections();if(e===a.RANGE_TYPE.ROW){if(this._changeFromRow!==this._changeToRow&&this._changeToRow!==-1){const j=(X=((B==null?void 0:B.filter(Q=>Q.range.rangeType===a.RANGE_TYPE.ROW&&Q.range.startRow<=this._changeFromRow&&this._changeFromRow<=Q.range.endRow))||[])[0])==null?void 0:X.range;j&&this._commandService.executeCommand(m.MoveRowsCommand.id,{fromRange:j,toRange:{...j,startRow:this._changeToRow,endRow:this._changeToRow+j.endRow-j.startRow}})}this._changeToRow=this._changeFromRow=-1}else{if(this._changeFromColumn!==this._changeToColumn&&this._changeToColumn!==-1){const j=(F=((B==null?void 0:B.filter(Q=>Q.range.rangeType===a.RANGE_TYPE.COLUMN&&Q.range.startColumn<=this._changeFromColumn&&this._changeFromColumn<=Q.range.endColumn))||[])[0])==null?void 0:F.range;j&&this._commandService.executeCommand(m.MoveColsCommand.id,{fromRange:j,toRange:{...j,startColumn:this._changeToColumn,endColumn:this._changeToColumn+j.endColumn-j.startColumn}})}this._changeToColumn=this._changeFromColumn=-1}})};this._headerPointerMoveSubs=new D.Subscription,this._headerPointerMoveSubs.add(s.onPointerMove$.subscribeEvent(l)),this._headerPointerLeaveSubs=new D.Subscription,this._headerPointerLeaveSubs.add(s==null?void 0:s.onPointerLeave$.subscribeEvent(c)),this._headerPointerDownSubs=new D.Subscription,this._headerPointerDownSubs.add(s==null?void 0:s.onPointerDown$.subscribeEvent(d))}_rowColumnMoving(e,t,i,r,s){var Y,j,Q,oe,re,ce,G;const l=this._context.scene,c=(Y=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:Y.skeleton;if(c==null)return;const{rowHeaderWidth:d,columnHeaderHeight:u,rowTotalHeight:h,columnTotalWidth:g}=c,S=l.getViewportScrollXY(l.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:f,scaleY:v}=l.getAncestorScale(),p=c.getCellIndexByOffset(e,t,f,v,S),{row:C,column:_}=p,w=c.getNoMergeCellWithCoordByIndex(C,_),{startX:E,startY:O,endX:R,endY:P}=w,A=this._sheetSkeletonManagerService.attachRangeWithCoord(i.range);if(A==null)return;const k=Math.max(f,f),{startX:N,endX:V,startY:L,endY:H,startRow:W,startColumn:B,endRow:U,endColumn:X}=A;s===a.RANGE_TYPE.ROW?(j=this._moveHelperBackgroundShape)==null||j.transformByState({height:H-L,width:g+d,left:0,top:L+(t-this._startOffsetY)/k+S.y-r.y}):(Q=this._moveHelperBackgroundShape)==null||Q.transformByState({height:h+u,width:V-N,left:N+(e-this._startOffsetX)/k+S.x-r.x,top:0}),(oe=this._moveHelperBackgroundShape)==null||oe.show();const F=fS/k;if(s===a.RANGE_TYPE.ROW){let Z=0;if(C<=W)Z=O-F/2,this._changeToRow=C;else if(C>U)Z=P-F/2,this._changeToRow=C+1;else return;(re=this._moveHelperLineShape)==null||re.transformByState({height:F,width:g,left:d,top:Z})}else{let Z=0;if(_<=B)Z=E-F/2,this._changeToColumn=_;else if(_>X)Z=R-F/2,this._changeToColumn=_+1;else return;(ce=this._moveHelperLineShape)==null||ce.transformByState({height:h,width:F,left:Z,top:u})}(G=this._moveHelperLineShape)==null||G.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 M.Rect(hS,{fill:gS,evented:!1,zIndex:100}),this._moveHelperLineShape=new M.Rect(mS,{fill:SS,evented:!1,zIndex:100}),e.addObjects([this._moveHelperBackgroundShape,this._moveHelperLineShape],rt)}_disposeBackgroundAndLine(){var e,t;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(t=this._moveHelperLineShape)==null||t.dispose()}},T.HeaderMoveRenderController=uS([os(1,a.Inject(m.SheetsSelectionsService)),os(2,a.Inject(T.SheetSkeletonManagerService)),os(3,a.ICommandService)],T.HeaderMoveRenderController);var ss=(n=>(n[n.VERTICAL=0]="VERTICAL",n[n.HORIZONTAL=1]="HORIZONTAL",n))(ss||{});const vS="rgba(120, 120, 120, 0.01)",as="rgb(68, 71, 70)",Pi=12,pS=44,ls=4;class Yl extends M.Shape{constructor(e,t){super(e,t);y(this,"_size",Pi);y(this,"_color",as);y(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:i,scaleY:r}=t.getAncestorScale(),s=Math.max(i,r),l=Pi/s,c=ls/s;let{width:d,height:u}=this,h=0,g=0;this.mode===0?(d=c,h=l-c):(u=c,g=l-c),M.Rect.drawWith(e,{width:this.width,height:this.height,left:0,top:0,fill:vS}),M.Rect.drawWith(e,{width:d,height:u,fill:as,radius:c}),e.save(),e.transform(1,0,0,1,h,g),M.Rect.drawWith(e,{width:d,height:u,fill:as,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:Pi,height:this.size}):this.transformByState({width:this.size,height:Pi}),this}}var CS=Object.getOwnPropertyDescriptor,IS=(n,o,e,t)=>{for(var i=t>1?void 0:t?CS(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},cs=(n,o)=>(e,t)=>o(e,t,n);const _S="__SpreadsheetHeaderResizeControllerShapeRow__",bS="__SpreadsheetHeaderResizeControllerShapeColumn__",jl="__SpreadsheetHeaderResizeControllerShapeHelper__",Zl="rgb(199, 199, 199)",wS=2,ds=a.createInterceptorKey("headerResizePermissionCheck");T.HeaderResizeRenderController=class extends a.Disposable{constructor(e,t,i,r){super();y(this,"_currentRow",0);y(this,"_currentColumn",0);y(this,"_rowResizeRect");y(this,"_columnResizeRect");y(this,"_headerPointerSubs");y(this,"_scenePointerMoveSub");y(this,"_scenePointerUpSub");y(this,"_resizeHelperShape");y(this,"_startOffsetX",Number.POSITIVE_INFINITY);y(this,"_startOffsetY",Number.POSITIVE_INFINITY);y(this,"interceptor",new a.InterceptorManager({HEADER_RESIZE_PERMISSION_CHECK:ds}));this._context=e,this._sheetSkeletonManagerService=t,this._selectionManagerService=i,this._commandService=r,this._init()}dispose(){var e,t,i;(e=this._rowResizeRect)==null||e.dispose(),this._rowResizeRect=null,(t=this._columnResizeRect)==null||t.dispose(),this._columnResizeRect=null,(i=this._headerPointerSubs)==null||i.unsubscribe(),this._headerPointerSubs=null}_init(){const e=this._context.scene;this._rowResizeRect=new Yl(_S,{visible:!1,mode:ss.HORIZONTAL,zIndex:100}),this._columnResizeRect=new Yl(bS,{visible:!1,mode:ss.VERTICAL,zIndex:100}),e.addObjects([this._rowResizeRect,this._columnResizeRect],rt),this._initialHover(0),this._initialHover(1),this._initialHoverResize(0),this._initialHoverResize(1)}_initialHover(e=0){const t=this._context.components.get(he.COLUMN),i=this._context.components.get(he.ROW),r=this._context.scene,s=e===0?i:t,l=(d,u)=>{var h,g;(h=this._rowResizeRect)==null||h.hide(),(g=this._columnResizeRect)==null||g.hide()},c=(d,u)=>{var k;const h=(k=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:k.skeleton;if(h==null||this._rowResizeRect==null||this._columnResizeRect==null)return;const{rowHeaderWidth:g,columnHeaderHeight:S}=h,{startX:f,startY:v,endX:p,endY:C,row:_,column:w}=Xe(d.offsetX,d.offsetY,r,h),E=Si(d.offsetX,d.offsetY,r),{scaleX:O,scaleY:R}=r.getAncestorScale(),P=Math.max(O,R),A=Pi/P;if(e===0){let N=v-A/2;if(E.y<=v+A/2&&E.y>=v)this._currentRow=_-1;else if(E.y>=C-A/2&&E.y<=C)this._currentRow=_,N=C-A/2;else{this._rowResizeRect.hide();return}if(this._currentRow===-1)return;if(!this.interceptor.fetchThroughInterceptors(ds)(null,{row:this._currentRow}))return!1;const L=Math.min(pS,g/3);this._rowResizeRect.transformByState({left:g/2-L/2,top:N}),this._rowResizeRect.setShapeProps({size:L}),this._rowResizeRect.show()}else{let N=f-A/2;if(E.x<=f+A/2&&E.x>=f)this._currentColumn=w-1;else if(E.x>=p-A/2&&E.x<=p)this._currentColumn=w,N=p-A/2;else{this._columnResizeRect.hide();return}if(this._currentColumn===-1)return;if(!this.interceptor.fetchThroughInterceptors(ds)(null,{col:this._currentColumn}))return!1;const L=S*.7;this._columnResizeRect.transformByState({left:N,top:S/2-L/2}),this._columnResizeRect.setShapeProps({size:L}),this._columnResizeRect.show()}};this._headerPointerSubs=new D.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,i=e===0?this._rowResizeRect:this._columnResizeRect;i!=null&&(this.disposeWithMe(i.onPointerEnter$.subscribeEvent(()=>{i!=null&&(i.show(),t.setCursor(e===0?M.CURSOR_TYPE.ROW_RESIZE:M.CURSOR_TYPE.COLUMN_RESIZE))})),this.disposeWithMe(i.onPointerLeave$.subscribeEvent(()=>{i!=null&&(i.hide(),t.resetCursor())})),this.disposeWithMe(i.onPointerDown$.subscribeEvent(r=>{var X,F,Y,j,Q,oe,re;const s=(X=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:X.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(M.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=(((Y=(F=h==null?void 0:h.getScrollBar())==null?void 0:F.horizonScrollTrack)==null?void 0:Y.height)||0)+10,S=(((Q=(j=h==null?void 0:h.getScrollBar())==null?void 0:j.verticalScrollTrack)==null?void 0:Q.width)||0)+10,f=Si(r.offsetX,r.offsetY,l),{scaleX:v,scaleY:p}=l.getAncestorScale();this._startOffsetX=f.x,this._startOffsetY=f.y;const C=s.getOffsetByColumn(this._currentColumn),_=s.getOffsetByRow(this._currentRow),w=s.getNoMergeCellWithCoordByIndex(this._currentRow,this._currentColumn);let E=!1,O=0,R=0;const{columnTotalWidth:P,rowHeaderWidth:A,rowTotalHeight:k,columnHeaderHeight:N}=s,V=u>P+A?u:P+A,L=d>k+N?d:k+N,H=Math.max(v,p),W=ls/H;e===0?this._resizeHelperShape=new M.Rect(jl,{width:V,height:W,fill:Zl,left:0,top:_-W/2}):this._resizeHelperShape=new M.Rect(jl,{width:W,height:L,fill:Zl,left:C-W/2,top:0});const B=((oe=this._columnResizeRect)==null?void 0:oe.left)||0,U=((re=this._rowResizeRect)==null?void 0:re.top)||0;l.addObject(this._resizeHelperShape,rt),l.disableObjectsEvent(),this._scenePointerMoveSub=l.onPointerMove$.subscribeEvent(ce=>{var ve,we,Ee,Ct,It,Kt;const G=l.getCoordRelativeToViewport(M.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),Z=l.getScrollXYInfoByViewport(G,h),J=Si(ce.offsetX,ce.offsetY,l),{x:ne,y:ue}=J,{scaleX:ie,scaleY:se}=l.getAncestorScale(),te=Math.max(ie,se),fe=ls/te;O=ne-this._startOffsetX-fe/2,R=ue-this._startOffsetY-fe/2,Math.abs(e===0?R:O)>=wS&&(E=!0),e===0?(R>d-g+Z.y-w.startY&&(R=d-g+Z.y-w.startY),R<-(w.endY-w.startY)+2&&(R=-(w.endY-w.startY)+2),E&&((ve=this._resizeHelperShape)==null||ve.transformByState({top:_+R}),(we=this._rowResizeRect)==null||we.transformByState({top:U+R+fe/2}),(Ee=this._rowResizeRect)==null||Ee.show(),l.setCursor(M.CURSOR_TYPE.ROW_RESIZE))):(O>u-S+Z.x-w.startX&&(O=u-S+Z.x-w.startX),O<-(w.endX-w.startX)+2&&(O=-(w.endX-w.startX)+2),E&&((Ct=this._resizeHelperShape)==null||Ct.transformByState({left:C+O}),(It=this._columnResizeRect)==null||It.transformByState({left:B+O+fe/2}),(Kt=this._columnResizeRect)==null||Kt.show(),l.setCursor(M.CURSOR_TYPE.COLUMN_RESIZE)))}),this._scenePointerUpSub=l.onPointerUp$.subscribeEvent(ce=>{var Z,J,ne;const G=this._context.scene;this._clearObserverEvent(),(Z=this._resizeHelperShape)==null||Z.dispose(),this._resizeHelperShape=null,G.enableObjectsEvent(),E&&(G.resetCursor(),(J=this._rowResizeRect)==null||J.hide(),(ne=this._columnResizeRect)==null||ne.hide(),e===0?this._commandService.executeCommand(m.DeltaRowHeightCommand.id,{deltaY:R,anchorRow:this._currentRow}):this._commandService.executeCommand(m.DeltaColumnWidthCommand.id,{deltaX:O,anchorCol:this._currentColumn}))})})),this.disposeWithMe(i.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(),v=[];for(let p=0;p<f.length;p++){const C=f[p];C.range.rangeType===a.RANGE_TYPE.COLUMN&&this._currentColumn<=C.range.endColumn&&this._currentColumn>=C.range.startColumn&&v.push({startColumn:C.range.startColumn,endColumn:C.range.endColumn,startRow:l,endRow:d})}v.length===0&&v.push({startColumn:this._currentColumn,endColumn:this._currentColumn,startRow:l,endRow:d}),this._commandService.executeCommand(pn.id,{ranges:v}),(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}},T.HeaderResizeRenderController=IS([cs(1,a.Inject(T.SheetSkeletonManagerService)),cs(2,a.Inject(m.SheetsSelectionsService)),cs(3,a.ICommandService)],T.HeaderResizeRenderController);var ES=Object.getOwnPropertyDescriptor,TS=(n,o,e,t)=>{for(var i=t>1?void 0:t?ES(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},Oi=(n,o)=>(e,t)=>o(e,t,n);const yS=60;T.SheetRenderController=class extends a.RxDisposable{constructor(e,t,i,r,s,l){super();y(this,"_renderMetric$",new D.Subject);y(this,"renderMetric$",this._renderMetric$.asObservable());y(this,"_renderFrameTimeMetric",null);y(this,"_renderFrameTags",{});y(this,"_afterRenderMetric$",new D.Subject);this._context=e,this._configService=t,this._sheetSkeletonManagerService=i,this._sheetRenderService=r,this._commandService=s,this._telemetryService=l,this._addNewRender(),this._initRenderMetricSubscriber()}_addNewRender(){const{scene:e,engine:t,unit:i}=this._context;this._addComponent(i),this._initRerenderScheduler(),this._initCommandListener();const r=this._context.unit.getActiveSheet();if(!r)throw new Error("No active sheet found");const s=r.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(){const{engine:e}=this._context;e.beginFrame$.subscribe(()=>{this._renderFrameTimeMetric=null,this._renderFrameTags={}}),e.endFrame$.subscribe(()=>{this._renderFrameTimeMetric&&Object.keys(this._renderFrameTimeMetric).filter(r=>r.startsWith(M.SHEET_EXTENSION_PREFIX)).length>0&&this._afterRenderMetric$.next({frameTimeMetric:this._renderFrameTimeMetric,tags:this._renderFrameTags})}),e.renderFrameTimeMetric$.subscribe(([i,r])=>{this._renderFrameTimeMetric||(this._renderFrameTimeMetric={}),this._renderFrameTimeMetric[i]||(this._renderFrameTimeMetric[i]=[]),this._renderFrameTimeMetric[i].push(Math.round(r*100)/100)}),e.renderFrameTags$.subscribe(([i,r])=>{this._renderFrameTags[i]=r});const t=[];this._afterRenderMetric$.pipe(D.withLatestFrom(e.endFrame$)).subscribe(([i,r])=>{t.push({FPS:r.FPS,elapsedTime:r.elapsedTime,frameTime:Math.round(r.frameTime*100)/100,...i.frameTimeMetric,...i.tags}),t.length>yS&&(this._captureRenderMetric(t),t.length=0)})}_captureRenderMetric(e){var g;const t=e;if(t.length===0)return;const i=S=>{let f=0;const p=Object.entries(S).filter(([_,w])=>Array.isArray(w)).map(([_])=>_).reduce((_,w)=>{const E=S[w].reduce((O,R)=>O+R,0);return _[w]=E,_},{});return Object.keys(S).filter(_=>_.startsWith(M.SHEET_EXTENSION_PREFIX)).forEach(_=>{f+=p[_]}),{...p,extensionTotal:f}},r=e.map(S=>({...S,...i(S)})),l=(S=>Object.entries(S[0]).filter(([p,C])=>!["elapsedTime"].includes(p)).filter(([p,C])=>typeof C=="number").map(([p])=>p).reduce((p,C)=>{const _=S.map(R=>R[C]),w=Math.max(..._),E=Math.min(..._),O=_.reduce((R,P)=>R+P,0)/_.length;return p[C]={max:Math.round(w*100)/100,min:Math.round(E*100)/100,avg:Math.round(O*100)/100},p},{}))(r),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._renderMetric$.next(h),(g=this._telemetryService)==null||g.capture("sheet_render_cost",h)}_addComponent(e){const{scene:t,components:i}=this._context,r=e.getActiveSheet(),s=new M.Spreadsheet(he.MAIN);this._addViewport(r);const l=new M.SpreadsheetRowHeader(he.ROW),c=new M.SpreadsheetColumnHeader(he.COLUMN),d=new M.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,i.set(he.MAIN,s),i.set(he.ROW,l),i.set(he.COLUMN,c),i.set(he.LEFT_TOP,d),t.addObjects([s],ks),t.addObjects([l,c,d],rt),t.enableLayerCache(ks,rt)}_initViewports(e,t,i){const l=new M.Viewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN,e,{left:t.width,top:i.height,bottom:0,right:0,isWheelPreventDefaultX:!0,allowCache:!0,bufferEdgeX:100,bufferEdgeY:100}),c=new M.Viewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:0,bufferEdgeY:0}),d=new M.Viewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:0,bufferEdgeY:100}),u=new M.Viewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:100,bufferEdgeY:0}),h=new M.Viewport(M.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP,e,{active:!1,isWheelPreventDefaultX:!0}),g=new M.Viewport(M.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM,e,{left:0,top:i.height,bottom:0,width:t.width+1,isWheelPreventDefaultX:!0}),S=new M.Viewport(M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT,e,{active:!1,isWheelPreventDefaultX:!0}),f=new M.Viewport(M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT,e,{left:t.width,top:0,height:i.height+1,right:0,isWheelPreventDefaultX:!0}),v=new M.Viewport(M.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP,e,{left:0,top:0,width:t.width,height:i.height,isWheelPreventDefaultX:!0});return{viewMain:l,viewLeftTop:v,viewMainLeftTop:c,viewMainLeft:d,viewMainTop:u,viewColumnLeft:S,viewRowTop:h,viewRowBottom:g,viewColumnRight:f}}_addViewport(e){const t=this._context.scene,{rowHeader:i,columnHeader:r}=e.getConfig(),{viewMain:s}=this._initViewports(t,i,r),l=this._configService.getConfig(Te),c=l==null?void 0:l.scrollConfig;return new M.ScrollBar(s,c),t.attachControl(),s}_initRerenderScheduler(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(!e)return null;const{skeleton:t,sheetId:i}=e,r=this._context.unit,s=r==null?void 0:r.getSheetBySheetId(i);if(r==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:i}=e;if(m.COMMAND_LISTENER_SKELETON_CHANGE.includes(i)||this._sheetRenderService.checkMutationShouldTriggerRerender(i)){const r=e.params,{unitId:s,subUnitId:l}=r,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:i},!0),this._sheetSkeletonManagerService.setCurrent({sheetId:u,commandId:i})}else m.COMMAND_LISTENER_VALUE_CHANGE.includes(i)&&this._sheetSkeletonManagerService.reCalculate();e.type===a.CommandType.MUTATION&&this._markUnitDirty(e)}))}_markUnitDirty(e){if(e.id.substring(0,3)==="doc")return;const{mainComponent:t,scene:i}=this._context;if(e.id===q.SetFormulaCalculationNotificationMutation.id&&e.params.stageInfo!=null||(t&&t.makeDirty(),i.makeDirty(),!e.params))return;const r=e.params,s=this._spreadsheetViewports(i);if(e.id===m.SetRangeValuesMutation.id&&r.cellValue){const l=this._cellValueToRange(r.cellValue),c=this._rangeToBounds([l]);this._markViewportDirty(s,c),t.setDirtyArea(c)}if(e.id===m.MoveRangeMutation.id&&r.from&&r.to){const l=r.fromRange||this._cellValueToRange(r.from.value),c=r.toRange||this._cellValueToRange(r.to.value),d=this._rangeToBounds([l,c]);this._markViewportDirty(s,d),t.setDirtyArea(d)}}_cellValueToRange(e){let t=0,i=0,r=0,s=0;for(const[h,g]of Object.entries(e)){for(const S in g)t>Number(S)&&(t=Number(S)),i<Number(S)&&(i=Number(S));r>Number(h)&&(r=Number(h)),s<Number(h)&&(s=Number(h))}return{startRow:r,endRow:s,startColumn:t,endColumn:i}}_rangeToBounds(e){const t=this._sheetSkeletonManagerService.getCurrentParam().skeleton,{rowHeightAccumulation:i,columnWidthAccumulation:r,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:i[u-1]+l,v=i[h]+l,p=g===0?0:r[g-1]+s,C=r[S]+s;c.push({top:f,left:p,bottom:v,right:C,width:C-p,height:v-f})}return c}_markViewportDirty(e,t){const i=e.filter(r=>r.isActive&&r.cacheBound);for(const r of i)for(const s of t)a.Rectangle.hasIntersectionBetweenTwoRect(r.cacheBound,s)&&r.markDirty(!0)}_spreadsheetViewports(e){return e.getViewports().filter(t=>["viewMain","viewMainLeftTop","viewMainTop","viewMainLeft"].includes(t.viewportKey))}},T.SheetRenderController=TS([Oi(1,a.Inject(a.IConfigService)),Oi(2,a.Inject(T.SheetSkeletonManagerService)),Oi(3,a.Inject(T.SheetsRenderService)),Oi(4,a.ICommandService),Oi(5,a.Optional(ud.ITelemetryService))],T.SheetRenderController);const RS=({className:n})=>b.jsxs("svg",{className:n,width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[b.jsx("path",{d:"M0.98999 1.08218H-0.0100098V0.0821838H0.98999V1.08218Z"}),b.jsx("path",{d:"M5.78992 1.08218H2.78992V0.0821838H5.78992V1.08218Z"}),b.jsx("path",{d:"M7.58984 1.08218H8.58984V0.0821838H7.58984V1.08218Z"}),b.jsx("path",{d:"M14.9152 1.08218H13.9152V0.0821838H14.9152V1.08218Z"}),b.jsx("path",{d:"M16.7151 1.08218H19.7151V0.0821838H16.7151V1.08218Z"}),b.jsx("path",{d:"M22.515 1.08218H21.515V0.0821838H22.515V1.08218Z"}),b.jsx("path",{d:"M27.8405 1.08218H28.8405V0.0821838H27.8405V1.08218Z"}),b.jsx("path",{d:"M33.6404 1.08218H30.6404V0.0821838H33.6404V1.08218Z"}),b.jsx("path",{d:"M35.4403 1.08218H36.4403V0.0821838H35.4403V1.08218Z"}),b.jsx("path",{d:"M42.7657 1.08218H41.7657V0.0821838H42.7657V1.08218Z"}),b.jsx("path",{d:"M44.5657 1.08218H47.5657V0.0821838H44.5657V1.08218Z"}),b.jsx("path",{d:"M50.3656 1.08218H49.3656V0.0821838H50.3656V1.08218Z"}),b.jsx("path",{d:"M55.691 1.08218H56.691V0.0821838H55.691V1.08218Z"}),b.jsx("path",{d:"M61.491 1.08218H58.491V0.0821838H61.491V1.08218Z"}),b.jsx("path",{d:"M63.2909 1.08218H64.2909V0.0821838H63.2909V1.08218Z"}),b.jsx("path",{d:"M70.6163 1.08218H69.6163V0.0821838H70.6163V1.08218Z"}),b.jsx("path",{d:"M72.4163 1.08218H75.4163V0.0821838H72.4163V1.08218Z"}),b.jsx("path",{d:"M78.2162 1.08218H77.2162V0.0821838H78.2162V1.08218Z"}),b.jsx("path",{d:"M83.5416 1.08218H84.5416V0.0821838H83.5416V1.08218Z"}),b.jsx("path",{d:"M89.3416 1.08218H86.3416V0.0821838H89.3416V1.08218Z"}),b.jsx("path",{d:"M91.1415 1.08218H92.1415V0.0821838H91.1415V1.08218Z"}),b.jsx("path",{d:"M98.4669 1.08218H97.4669V0.0821838H98.4669V1.08218Z"}),b.jsx("path",{d:"M100.267 1.08218H103.267V0.0821838H100.267V1.08218Z"}),b.jsx("path",{d:"M106.067 1.08218H105.067V0.0821838H106.067V1.08218Z"}),b.jsx("path",{d:"M111.392 1.08218H112.392V0.0821838H111.392V1.08218Z"}),b.jsx("path",{d:"M117.192 1.08218H114.192V0.0821838H117.192V1.08218Z"}),b.jsx("path",{d:"M118.992 1.08218H119.992V0.0821838H118.992V1.08218Z"})]}),MS=({className:n})=>b.jsxs("svg",{className:n,width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[b.jsx("path",{d:"M-0.0100098 1.15771H0.98999V0.157715H-0.0100098V1.15771Z"}),b.jsx("path",{d:"M2.78992 1.15771H5.78992V0.157715H2.78992V1.15771Z"}),b.jsx("path",{d:"M8.58984 1.15771H7.58984V0.157715H8.58984V1.15771Z"}),b.jsx("path",{d:"M10.3899 1.15771H11.3899V0.157715H10.3899V1.15771Z"}),b.jsx("path",{d:"M19.0903 1.15771H18.0903V0.157715H19.0903V1.15771Z"}),b.jsx("path",{d:"M20.8903 1.15771H23.8903V0.157715H20.8903V1.15771Z"}),b.jsx("path",{d:"M26.6902 1.15771H25.6902V0.157715H26.6902V1.15771Z"}),b.jsx("path",{d:"M28.4902 1.15771H29.4902V0.157715H28.4902V1.15771Z"}),b.jsx("path",{d:"M37.1907 1.15771H36.1907V0.157715H37.1907V1.15771Z"}),b.jsx("path",{d:"M38.9906 1.15771H41.9906V0.157715H38.9906V1.15771Z"}),b.jsx("path",{d:"M44.7905 1.15771H43.7905V0.157715H44.7905V1.15771Z"}),b.jsx("path",{d:"M46.5906 1.15771H47.5906V0.157715H46.5906V1.15771Z"}),b.jsx("path",{d:"M55.291 1.15771H54.291V0.157715H55.291V1.15771Z"}),b.jsx("path",{d:"M57.0909 1.15771H60.0909V0.157715H57.0909V1.15771Z"}),b.jsx("path",{d:"M62.8909 1.15771H61.8909V0.157715H62.8909V1.15771Z"}),b.jsx("path",{d:"M64.6909 1.15771H65.6909V0.157715H64.6909V1.15771Z"}),b.jsx("path",{d:"M73.3914 1.15771H72.3914V0.157715H73.3914V1.15771Z"}),b.jsx("path",{d:"M75.1913 1.15771H78.1913V0.157715H75.1913V1.15771Z"}),b.jsx("path",{d:"M80.9912 1.15771H79.9912V0.157715H80.9912V1.15771Z"}),b.jsx("path",{d:"M82.7913 1.15771H83.7913V0.157715H82.7913V1.15771Z"}),b.jsx("path",{d:"M91.4917 1.15771H90.4917V0.157715H91.4917V1.15771Z"}),b.jsx("path",{d:"M93.2916 1.15771H96.2916V0.157715H93.2916V1.15771Z"}),b.jsx("path",{d:"M99.0916 1.15771H98.0916V0.157715H99.0916V1.15771Z"}),b.jsx("path",{d:"M100.892 1.15771H101.892V0.157715H100.892V1.15771Z"}),b.jsx("path",{d:"M109.592 1.15771H108.592V0.157715H109.592V1.15771Z"}),b.jsx("path",{d:"M111.392 1.15771H114.392V0.157715H111.392V1.15771Z"}),b.jsx("path",{d:"M117.192 1.15771H116.192V0.157715H117.192V1.15771Z"}),b.jsx("path",{d:"M118.992 1.15771H119.992V0.157715H118.992V1.15771Z"})]}),PS=({className:n})=>b.jsxs("svg",{className:n,width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[b.jsx("path",{d:"M-0.00842285 1.22449H2.99158V0.224487H-0.00842285V1.22449Z"}),b.jsx("path",{d:"M6.14941 1.22449H9.14941V0.224487H6.14941V1.22449Z"}),b.jsx("path",{d:"M15.3073 1.22449H12.3073V0.224487H15.3073V1.22449Z"}),b.jsx("path",{d:"M18.4651 1.22449H21.4651V0.224487H18.4651V1.22449Z"}),b.jsx("path",{d:"M27.6229 1.22449H24.6229V0.224487H27.6229V1.22449Z"}),b.jsx("path",{d:"M30.7808 1.22449H33.7808V0.224487H30.7808V1.22449Z"}),b.jsx("path",{d:"M39.9386 1.22449H36.9386V0.224487H39.9386V1.22449Z"}),b.jsx("path",{d:"M43.0964 1.22449H46.0964V0.224487H43.0964V1.22449Z"}),b.jsx("path",{d:"M52.2543 1.22449H49.2543V0.224487H52.2543V1.22449Z"}),b.jsx("path",{d:"M55.4121 1.22449H58.4121V0.224487H55.4121V1.22449Z"}),b.jsx("path",{d:"M64.5699 1.22449H61.5699V0.224487H64.5699V1.22449Z"}),b.jsx("path",{d:"M67.7278 1.22449H70.7278V0.224487H67.7278V1.22449Z"}),b.jsx("path",{d:"M76.8856 1.22449H73.8856V0.224487H76.8856V1.22449Z"}),b.jsx("path",{d:"M80.0435 1.22449H83.0435V0.224487H80.0435V1.22449Z"}),b.jsx("path",{d:"M89.2013 1.22449H86.2013V0.224487H89.2013V1.22449Z"}),b.jsx("path",{d:"M92.3591 1.22449H95.3591V0.224487H92.3591V1.22449Z"}),b.jsx("path",{d:"M101.517 1.22449H98.517V0.224487H101.517V1.22449Z"}),b.jsx("path",{d:"M104.675 1.22449H107.675V0.224487H104.675V1.22449Z"}),b.jsx("path",{d:"M113.833 1.22449H110.833V0.224487H113.833V1.22449Z"}),b.jsx("path",{d:"M116.99 1.22449H119.99V0.224487H116.99V1.22449Z"})]}),OS=({className:n})=>b.jsxs("svg",{className:n,width:"120",height:"8",viewBox:"0 0 120 8",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[b.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 2.06215H-0.0090332V0.862152H119.991V1.86215Z"}),b.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 6.66215H-0.0090332V5.86215H119.991V6.86215Z"})]}),AS=({className:n})=>b.jsxs("svg",{className:n,width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[b.jsx("path",{d:"M-0.00976562 1.65707H0.990234V0.657074H-0.00976562V1.65707Z"}),b.jsx("path",{d:"M2.32361 1.65707H3.32361V0.657074H2.32361V1.65707Z"}),b.jsx("path",{d:"M5.65698 1.65707H4.65698V0.657074H5.65698V1.65707Z"}),b.jsx("path",{d:"M6.99036 1.65707H7.99036V0.657074H6.99036V1.65707Z"}),b.jsx("path",{d:"M10.3237 1.65707H9.32373V0.657074H10.3237V1.65707Z"}),b.jsx("path",{d:"M11.6571 1.65707H12.6571V0.657074H11.6571V1.65707Z"}),b.jsx("path",{d:"M14.9905 1.65707H13.9905V0.657074H14.9905V1.65707Z"}),b.jsx("path",{d:"M16.3239 1.65707H17.3239V0.657074H16.3239V1.65707Z"}),b.jsx("path",{d:"M19.6572 1.65707H18.6572V0.657074H19.6572V1.65707Z"}),b.jsx("path",{d:"M20.9906 1.65707H21.9906V0.657074H20.9906V1.65707Z"}),b.jsx("path",{d:"M24.324 1.65707H23.324V0.657074H24.324V1.65707Z"}),b.jsx("path",{d:"M25.6573 1.65707H26.6573V0.657074H25.6573V1.65707Z"}),b.jsx("path",{d:"M28.9907 1.65707H27.9907V0.657074H28.9907V1.65707Z"}),b.jsx("path",{d:"M30.3241 1.65707H31.3241V0.657074H30.3241V1.65707Z"}),b.jsx("path",{d:"M33.6575 1.65707H32.6575V0.657074H33.6575V1.65707Z"}),b.jsx("path",{d:"M34.9908 1.65707H35.9908V0.657074H34.9908V1.65707Z"}),b.jsx("path",{d:"M38.3242 1.65707H37.3242V0.657074H38.3242V1.65707Z"}),b.jsx("path",{d:"M39.6576 1.65707H40.6576V0.657074H39.6576V1.65707Z"}),b.jsx("path",{d:"M42.991 1.65707H41.991V0.657074H42.991V1.65707Z"}),b.jsx("path",{d:"M44.3243 1.65707H45.3243V0.657074H44.3243V1.65707Z"}),b.jsx("path",{d:"M47.6577 1.65707H46.6577V0.657074H47.6577V1.65707Z"}),b.jsx("path",{d:"M48.9911 1.65707H49.9911V0.657074H48.9911V1.65707Z"}),b.jsx("path",{d:"M52.3245 1.65707H51.3245V0.657074H52.3245V1.65707Z"}),b.jsx("path",{d:"M53.6578 1.65707H54.6578V0.657074H53.6578V1.65707Z"}),b.jsx("path",{d:"M56.9912 1.65707H55.9912V0.657074H56.9912V1.65707Z"}),b.jsx("path",{d:"M58.3246 1.65707H59.3246V0.657074H58.3246V1.65707Z"}),b.jsx("path",{d:"M61.658 1.65707H60.658V0.657074H61.658V1.65707Z"}),b.jsx("path",{d:"M62.9913 1.65707H63.9913V0.657074H62.9913V1.65707Z"}),b.jsx("path",{d:"M66.3247 1.65707H65.3247V0.657074H66.3247V1.65707Z"}),b.jsx("path",{d:"M67.6581 1.65707H68.6581V0.657074H67.6581V1.65707Z"}),b.jsx("path",{d:"M70.9915 1.65707H69.9915V0.657074H70.9915V1.65707Z"}),b.jsx("path",{d:"M72.3248 1.65707H73.3248V0.657074H72.3248V1.65707Z"}),b.jsx("path",{d:"M75.6582 1.65707H74.6582V0.657074H75.6582V1.65707Z"}),b.jsx("path",{d:"M76.9916 1.65707H77.9916V0.657074H76.9916V1.65707Z"}),b.jsx("path",{d:"M80.325 1.65707H79.325V0.657074H80.325V1.65707Z"}),b.jsx("path",{d:"M81.6583 1.65707H82.6583V0.657074H81.6583V1.65707Z"}),b.jsx("path",{d:"M84.9917 1.65707H83.9917V0.657074H84.9917V1.65707Z"}),b.jsx("path",{d:"M86.3251 1.65707H87.3251V0.657074H86.3251V1.65707Z"}),b.jsx("path",{d:"M89.6584 1.65707H88.6584V0.657074H89.6584V1.65707Z"}),b.jsx("path",{d:"M90.9918 1.65707H91.9918V0.657074H90.9918V1.65707Z"}),b.jsx("path",{d:"M94.3252 1.65707H93.3252V0.657074H94.3252V1.65707Z"}),b.jsx("path",{d:"M95.6586 1.65707H96.6586V0.657074H95.6586V1.65707Z"}),b.jsx("path",{d:"M98.9919 1.65707H97.9919V0.657074H98.9919V1.65707Z"}),b.jsx("path",{d:"M100.325 1.65707H101.325V0.657074H100.325V1.65707Z"}),b.jsx("path",{d:"M103.659 1.65707H102.659V0.657074H103.659V1.65707Z"}),b.jsx("path",{d:"M104.992 1.65707H105.992V0.657074H104.992V1.65707Z"}),b.jsx("path",{d:"M108.325 1.65707H107.325V0.657074H108.325V1.65707Z"}),b.jsx("path",{d:"M109.659 1.65707H110.659V0.657074H109.659V1.65707Z"}),b.jsx("path",{d:"M112.992 1.65707H111.992V0.657074H112.992V1.65707Z"}),b.jsx("path",{d:"M114.325 1.65707H115.325V0.657074H114.325V1.65707Z"}),b.jsx("path",{d:"M117.659 1.65707H116.659V0.657074H117.659V1.65707Z"}),b.jsx("path",{d:"M118.992 1.65707H119.992V0.657074H118.992V1.65707Z"})]}),DS=({className:n})=>b.jsx("svg",{className:n,width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:b.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 2.42035H-0.0090332V0.420349H119.991V2.42035Z"})}),kS=({className:n})=>b.jsxs("svg",{className:n,width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[b.jsx("path",{d:"M-0.0100098 2.47614H1.98999V0.476135H-0.0100098V2.47614Z"}),b.jsx("path",{d:"M3.99014 2.47614H9.99014V0.476135H3.99014V2.47614Z"}),b.jsx("path",{d:"M13.9901 2.47614H11.9901V0.476135H13.9901V2.47614Z"}),b.jsx("path",{d:"M21.1904 2.47614H23.1904V0.476135H21.1904V2.47614Z"}),b.jsx("path",{d:"M31.1906 2.47614H25.1906V0.476135H31.1906V2.47614Z"}),b.jsx("path",{d:"M33.1906 2.47614H35.1906V0.476135H33.1906V2.47614Z"}),b.jsx("path",{d:"M44.3909 2.47614H42.3909V0.476135H44.3909V2.47614Z"}),b.jsx("path",{d:"M46.391 2.47614H52.391V0.476135H46.391V2.47614Z"}),b.jsx("path",{d:"M56.391 2.47614H54.391V0.476135H56.391V2.47614Z"}),b.jsx("path",{d:"M63.5913 2.47614H65.5913V0.476135H63.5913V2.47614Z"}),b.jsx("path",{d:"M73.5915 2.47614H67.5915V0.476135H73.5915V2.47614Z"}),b.jsx("path",{d:"M75.5915 2.47614H77.5915V0.476135H75.5915V2.47614Z"}),b.jsx("path",{d:"M86.7917 2.47614H84.7917V0.476135H86.7917V2.47614Z"}),b.jsx("path",{d:"M88.7919 2.47614H94.7919V0.476135H88.7919V2.47614Z"}),b.jsx("path",{d:"M98.7919 2.47614H96.7919V0.476135H98.7919V2.47614Z"}),b.jsx("path",{d:"M105.992 2.47614H107.992V0.476135H105.992V2.47614Z"}),b.jsx("path",{d:"M115.992 2.47614H109.992V0.476135H115.992V2.47614Z"}),b.jsx("path",{d:"M117.992 2.47614H119.992V0.476135H117.992V2.47614Z"})]}),NS=({className:n})=>b.jsxs("svg",{className:n,width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[b.jsx("path",{d:"M-0.0100098 2.00415H1.98999V0.00415039H-0.0100098V2.00415Z"}),b.jsx("path",{d:"M3.99014 2.00415H9.99014V0.00415039H3.99014V2.00415Z"}),b.jsx("path",{d:"M13.9901 2.00415H11.9901V0.00415039H13.9901V2.00415Z"}),b.jsx("path",{d:"M15.9901 2.00415H17.9901V0.00415039H15.9901V2.00415Z"}),b.jsx("path",{d:"M27.4905 2.00415H25.4905V0.00415039H27.4905V2.00415Z"}),b.jsx("path",{d:"M29.4906 2.00415H35.4906V0.00415039H29.4906V2.00415Z"}),b.jsx("path",{d:"M39.4906 2.00415H37.4906V0.00415039H39.4906V2.00415Z"}),b.jsx("path",{d:"M41.4906 2.00415H43.4906V0.00415039H41.4906V2.00415Z"}),b.jsx("path",{d:"M52.991 2.00415H50.991V0.00415039H52.991V2.00415Z"}),b.jsx("path",{d:"M54.9911 2.00415H60.9911V0.00415039H54.9911V2.00415Z"}),b.jsx("path",{d:"M64.9911 2.00415H62.9911V0.00415039H64.9911V2.00415Z"}),b.jsx("path",{d:"M66.9911 2.00415H68.9911V0.00415039H66.9911V2.00415Z"}),b.jsx("path",{d:"M78.4915 2.00415H76.4915V0.00415039H78.4915V2.00415Z"}),b.jsx("path",{d:"M80.4916 2.00415H86.4916V0.00415039H80.4916V2.00415Z"}),b.jsx("path",{d:"M90.4916 2.00415H88.4916V0.00415039H90.4916V2.00415Z"}),b.jsx("path",{d:"M92.4916 2.00415H94.4916V0.00415039H92.4916V2.00415Z"}),b.jsx("path",{d:"M103.992 2.00415H101.992V0.00415039H103.992V2.00415Z"}),b.jsx("path",{d:"M105.992 2.00415H111.992V0.00415039H105.992V2.00415Z"}),b.jsx("path",{d:"M115.992 2.00415H113.992V0.00415039H115.992V2.00415Z"}),b.jsx("path",{d:"M117.992 2.00415H119.992V0.00415039H117.992V2.00415Z"})]}),VS=({className:n})=>b.jsxs("svg",{className:n,width:"118",height:"3",viewBox:"0 0 118 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[b.jsx("path",{d:"M-0.00854492 2.94815H1.99146V0.948151H-0.00854492V2.94815Z"}),b.jsx("path",{d:"M6.09668 2.94815H8.09668V0.948151H6.09668V2.94815Z"}),b.jsx("path",{d:"M14.2019 2.94815H12.2019V0.948151H14.2019V2.94815Z"}),b.jsx("path",{d:"M18.3071 2.94815H20.3071V0.948151H18.3071V2.94815Z"}),b.jsx("path",{d:"M26.4124 2.94815H24.4124V0.948151H26.4124V2.94815Z"}),b.jsx("path",{d:"M30.5176 2.94815H32.5176V0.948151H30.5176V2.94815Z"}),b.jsx("path",{d:"M38.6228 2.94815H36.6228V0.948151H38.6228V2.94815Z"}),b.jsx("path",{d:"M42.728 2.94815H44.728V0.948151H42.728V2.94815Z"}),b.jsx("path",{d:"M50.8333 2.94815H48.8333V0.948151H50.8333V2.94815Z"}),b.jsx("path",{d:"M54.9385 2.94815H56.9385V0.948151H54.9385V2.94815Z"}),b.jsx("path",{d:"M63.0437 2.94815H61.0437V0.948151H63.0437V2.94815Z"}),b.jsx("path",{d:"M67.1489 2.94815H69.1489V0.948151H67.1489V2.94815Z"}),b.jsx("path",{d:"M75.2542 2.94815H73.2542V0.948151H75.2542V2.94815Z"}),b.jsx("path",{d:"M79.3594 2.94815H81.3594V0.948151H79.3594V2.94815Z"}),b.jsx("path",{d:"M87.4645 2.94815H85.4645V0.948151H87.4645V2.94815Z"}),b.jsx("path",{d:"M91.5697 2.94815H93.5697V0.948151H91.5697V2.94815Z"}),b.jsx("path",{d:"M99.6749 2.94815H97.6749V0.948151H99.6749V2.94815Z"}),b.jsx("path",{d:"M103.78 2.94815H105.78V0.948151H103.78V2.94815Z"}),b.jsx("path",{d:"M111.885 2.94815H109.885V0.948151H111.885V2.94815Z"}),b.jsx("path",{d:"M115.991 2.94815H117.991V0.948151H115.991V2.94815Z"})]}),HS=({className:n})=>b.jsx("svg",{className:n,width:"120",height:"4",viewBox:"0 0 120 4",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:b.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 3.86215H-0.0090332V0.862152H119.991V3.86215Z"})}),WS=({className:n})=>b.jsx("svg",{className:n,width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:b.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 1.15668H-0.0090332V0.156677H119.991V1.15668Z"})});function Gl(n){const{type:o=a.BorderStyleTypes.THIN,className:e}=n;switch(o){case a.BorderStyleTypes.DASH_DOT:return b.jsx(RS,{className:e});case a.BorderStyleTypes.DASH_DOT_DOT:return b.jsx(MS,{className:e});case a.BorderStyleTypes.DASHED:return b.jsx(PS,{className:e});case a.BorderStyleTypes.HAIR:return b.jsx(AS,{className:e});case a.BorderStyleTypes.MEDIUM:return b.jsx(DS,{className:e});case a.BorderStyleTypes.MEDIUM_DASH_DOT:return b.jsx(kS,{className:e});case a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT:return b.jsx(NS,{className:e});case a.BorderStyleTypes.MEDIUM_DASHED:return b.jsx(VS,{className:e});case a.BorderStyleTypes.THICK:return b.jsx(HS,{className:e});case a.BorderStyleTypes.DOUBLE:return b.jsx(OS,{className:e});case a.BorderStyleTypes.THIN:default:return b.jsx(WS,{className:e})}}const LS=[{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},{label:a.BorderStyleTypes.DOUBLE,value:a.BorderStyleTypes.DOUBLE}];function xS(n){var o;if(n)for(const e in n){const t=n[e];if((o=t==null?void 0:t.cl)!=null&&o.rgb)return t.cl.rgb}}function US(n){var o;if(n)for(const e in n){const t=n[e];if((o=t==null?void 0:t.cl)!=null&&o.rgb)return t.s}}function Kl(n){var g;const o=I.useDependency(I.ComponentManager),e=I.useDependency(m.BorderStyleManagerService),t=I.useDependency(m.SheetsSelectionsService),{isAllValuesSame:i,value:r}=t.getCellStylesProperty("bd"),s=i?xS(r):void 0,l=i?US(r):void 0,{onChange:c,value:d}=n;function u(S,f){c==null||c({...d,[f]:S})}function h(S){const f=o.get(S);return f&&b.jsx(f,{className:"univer-fill-primary-600"})}return b.jsxs("section",{className:"univer-box-border univer-grid univer-gap-2 univer-p-1.5",children:[b.jsx("div",{className:"univer-box-border univer-grid univer-grid-cols-5 univer-gap-2 univer-text-gray-600 dark:!univer-text-gray-200",children:wl.map(S=>b.jsx("a",{className:z.clsx("univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-justify-self-center univer-rounded hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",{"univer-bg-gray-200 dark:!univer-bg-gray-600":e.getBorderInfo().type===S.value}),onClick:f=>{f.stopPropagation(),u(S.value,"type")},children:h(S.icon)},S.value))}),b.jsx(z.Separator,{}),b.jsxs("div",{className:"univer-flex univer-items-center univer-gap-2",children:[b.jsx("div",{children:b.jsx(z.Dropdown,{overlay:b.jsx("div",{className:"univer-rounded-lg univer-p-4",children:b.jsx(z.ColorPicker,{value:s,onChange:S=>u(S,"color")})}),children:b.jsxs("button",{className:"univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-rounded univer-border-none univer-bg-transparent univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",type:"button",children:[b.jsx(Ba,{className:"univer-fill-primary-600 dark:!univer-text-white",extend:{colorChannel1:(g=d==null?void 0:d.color)!=null?g:""}}),b.jsx(wn,{className:"dark:!univer-text-white"})]})})}),b.jsx("div",{children:b.jsx(z.Dropdown,{overlay:b.jsx("section",{className:"univer-rounded-lg univer-p-1.5",children:b.jsx("ul",{className:"univer-m-0 univer-grid univer-list-none univer-gap-1 univer-p-0",children:LS.map(S=>b.jsxs("li",{className:"univer-flex univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-px-1 univer-py-3 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",onClick:()=>u(S.value,"style"),children:[S.value===l&&b.jsx(Ut,{className:"univer-absolute univer-left-3 univer-text-primary-600"}),b.jsx(Gl,{className:"univer-ml-6 univer-fill-gray-900 dark:!univer-fill-white",type:S.value})]},S.value))})}),children:b.jsxs("button",{className:"univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-rounded univer-border-none univer-bg-transparent univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",type:"button",children:[b.jsx(Gl,{className:"univer-fill-gray-900 dark:!univer-fill-white",type:l!=null?l:a.BorderStyleTypes.THIN}),b.jsx(wn,{className:"dark:!univer-text-white"})]})})})]})]})}const us="sheets.component.cell-popup";var BS=Object.getOwnPropertyDescriptor,FS=(n,o,e,t)=>{for(var i=t>1?void 0:t?BS(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},jt=(n,o)=>(e,t)=>o(e,t,n);T.SheetCanvasPopManagerService=class extends a.Disposable{constructor(e,t,i,r,s,l,c){super();y(this,"_popupMenuFeatureMap",new Map);y(this,"_isSelectionMoving",!1);this._globalPopupManagerService=e,this._renderManagerService=t,this._univerInstanceService=i,this._refRangeService=r,this._commandService=s,this._refSelectionsService=l,this._selectionManagerService=c,this._initMoving()}_initMoving(){this.disposeWithMe(this._refSelectionsService.selectionMoving$.subscribe(()=>{this._isSelectionMoving=!0})),this.disposeWithMe(this._refSelectionsService.selectionMoveEnd$.subscribe(()=>{this._isSelectionMoving=!1})),this.disposeWithMe(this._selectionManagerService.selectionMoving$.subscribe(()=>{this._isSelectionMoving=!0})),this.disposeWithMe(this._selectionManagerService.selectionMoveEnd$.subscribe(()=>{this._isSelectionMoving=!1}))}registerFeatureMenu(e,t){this._popupMenuFeatureMap.set(e,t)}getFeatureMenu(e,t,i,r){const s=this._popupMenuFeatureMap.get(r);if(s)return s(e,t,i,r)}dispose(){super.dispose(),this._popupMenuFeatureMap.clear()}_createHiddenRectObserver(e){const{row:t,column:i,worksheet:r,skeleton:s,currentRender:l}=e,c=()=>{var Y,j;const g=r.getFreeze(),{startRow:S,startColumn:f,xSplit:v,ySplit:p}=g,C=S-p,_=f-v,{rowHeightAccumulation:w,columnWidthAccumulation:E,rowHeaderWidth:O,columnHeaderHeight:R}=s,P=O+(_===-1?0:E[_+v-1]-((Y=E[_-1])!=null?Y:0)),A=R+(C===-1?0:w[C+p-1]-((j=w[C])!=null?j:0)),k=l.engine.getCanvasElement(),N=k.getBoundingClientRect(),V=hs(k.style.width),L=N.width/V,H=l.scene.getAncestorScale().scaleX,W=P*L*H,B=A*L*H,U={left:-1/0,top:-1/0,right:N.left+W,bottom:N.top+B},X={left:N.left+W,top:-1/0,right:1/0,bottom:N.top+B},F={left:-1/0,top:N.top+B,right:N.left+W,bottom:1/0};return t<S&&i<f?[]:t<S?[U]:i<f?[U]:[U,X,F]},d=c(),u=new D.BehaviorSubject(d),h=new a.DisposableCollection;return h.add(this._commandService.onCommandExecuted(g=>{g.id===m.SetFrozenMutation.id&&u.next(c())})),h.add(a.fromEventSubject(l.engine.onTransformChange$).pipe(D.throttleTime(16)).subscribe(()=>{u.next(c())})),{rects$:u,disposable:h}}_createPositionObserver(e,t,i,r){const s=()=>{const{scene:u}=t,h=rh(e,u,i,r),g=t.engine.getCanvasElement(),S=g.getBoundingClientRect(),f=hs(g.style.width),v=S.width/f;return{left:h.left*v+S.left,right:h.right*v+S.left,top:h.top*v+S.top,bottom:h.bottom*v+S.top}},l=s(),c=new D.BehaviorSubject(l),d=new a.DisposableCollection;return d.add(this._commandService.onCommandExecuted(u=>{ms(u.id)&&c.next(s())})),{position:l,position$:c,disposable:d}}attachPopupToObject(e,t){var w;const i=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),r=i.getActiveSheet();if(!r||this._isSelectionMoving&&!t.showOnSelectionMoving)return{dispose:()=>{},canDispose:()=>!0};const s=i.getUnitId(),l=r.getSheetId(),c=(w=this._renderManagerService.getRenderById(s))==null?void 0:w.with(T.SheetSkeletonManagerService).ensureSkeleton(l),d=this._renderManagerService.getRenderById(s);if(!d||!c)return{dispose:()=>{},canDispose:()=>!0};const{left:u,top:h,width:g,height:S}=e,f={left:u,right:u+g,top:h,bottom:h+S},{position:v,position$:p,disposable:C}=this._createPositionObserver(f,d,c,r),_=this._globalPopupManagerService.addPopup({...t,unitId:s,subUnitId:l,anchorRect:v,anchorRect$:p,canvasElement:d.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(_),p.complete(),C.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==_}}attachPopupByPosition(e,t,i){var C;let r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=r.getActiveSheet();if(!s)return null;const l=r.getUnitId(),c=s.getSheetId();if(l!==i.unitId||i.subUnitId!==c)return null;if(this._isSelectionMoving&&!t.showOnSelectionMoving)return;const d=(C=this._renderManagerService.getRenderById(l))==null?void 0:C.with(T.SheetSkeletonManagerService).getOrCreateSkeleton({sheetId:c}),u=this._renderManagerService.getRenderById(l);if(!u||!d)return null;const{position:h,position$:g,disposable:S}=this._createPositionObserver(e,u,d,s),{rects$:f,disposable:v}=this._createHiddenRectObserver({row:i.row,column:i.col,worksheet:s,skeleton:d,currentRender:u}),p=this._globalPopupManagerService.addPopup({...t,unitId:l,subUnitId:c,anchorRect:h,anchorRect$:g,hiddenRects$:f,canvasElement:u.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(p),g.complete(),S.dispose(),v.dispose(),r=null,s=null},canDispose:()=>this._globalPopupManagerService.activePopupId!==p}}attachPopupToAbsolutePosition(e,t,i,r){var f;const s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),l=s.getActiveSheet();if(!l)return null;const c=s.getUnitId(),d=l.getSheetId();if(i&&c!==i||r&&r!==d)return null;const u=(f=this._renderManagerService.getRenderById(c))==null?void 0:f.with(T.SheetSkeletonManagerService).ensureSkeleton(d),h=this._renderManagerService.getRenderById(c);if(!h||!u)return null;if(this._isSelectionMoving&&!t.showOnSelectionMoving)return;const g=new D.BehaviorSubject(e),S=this._globalPopupManagerService.addPopup({...t,unitId:c,subUnitId:d,anchorRect:e,anchorRect$:g.asObservable(),canvasElement:h.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(S),g.complete()},canDispose:()=>this._globalPopupManagerService.activePopupId!==S}}attachPopupToCell(e,t,i,r,s,l){let c=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d=c.getActiveSheet();if(!d)return null;const u=c.getUnitId(),h=d.getSheetId();if(r&&u!==r||s&&h!==s)return null;const g=this._renderManagerService.getRenderById(u),S=g==null?void 0:g.with(T.SheetSkeletonManagerService).ensureSkeleton(h),f=g==null?void 0:g.with(Ie);if(!g||!S||!f)return null;if(this._isSelectionMoving&&!i.showOnSelectionMoving)return;const v=l!=null?l:Ea(e,t,g.scene,d);if(!v)return null;const{position:p,position$:C,disposable:_,updateRowCol:w}=this._createCellPositionObserver(e,t,g,S,v),{rects$:E,disposable:O}=this._createHiddenRectObserver({row:e,column:t,worksheet:d,skeleton:S,currentRender:g}),R=this._globalPopupManagerService.addPopup({...i,unitId:u,subUnitId:h,anchorRect:p,anchorRect$:C,canvasElement:g.engine.getCanvasElement(),hiddenRects$:E}),P=new a.DisposableCollection;P.add(_),P.add(a.toDisposable(()=>{this._globalPopupManagerService.removePopup(R),C.complete()})),P.add(O);const A={startRow:e,endRow:e,startColumn:t,endColumn:t};return P.add(this._refRangeService.watchRange(u,h,A,(k,N)=>{N?w(N.startRow,N.startColumn):P.dispose()})),{dispose(){P.dispose(),d=null,c=null},canDispose:()=>this._globalPopupManagerService.activePopupId!==R}}attachRangePopup(e,t,i,r,s,l=!1){const c=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d=c.getActiveSheet();if(!d)return null;const u=c.getUnitId(),h=d.getSheetId();if(i&&u!==i||r&&h!==r)return null;const g=this._renderManagerService.getRenderById(u),S=g==null?void 0:g.with(T.SheetSkeletonManagerService).getOrCreateSkeleton({sheetId:h}),f=g==null?void 0:g.with(Ie);if(!g||!S||!f)return null;if(f.selectionMoving&&!l)return;const v=s!=null?s:Ea(e.startRow,e.startColumn,g.scene,d);if(!v)return null;const{position:p,position$:C,disposable:_,updateRange:w,topLeftPos$:E,rightBottomPos$:O}=this._createRangePositionObserver(e,g,S,v),{rects$:R,disposable:P}=this._createHiddenRectObserver({row:e.startRow,column:e.startColumn,worksheet:d,skeleton:S,currentRender:g}),A=this._globalPopupManagerService.addPopup({...t,unitId:u,subUnitId:h,anchorRect:p,anchorRect$:C,canvasElement:g.engine.getCanvasElement(),hiddenRects$:R}),k=new a.DisposableCollection;k.add(_),k.add(a.toDisposable(()=>{this._globalPopupManagerService.removePopup(A),E.complete(),O.complete()})),k.add(P);const N={...e};return k.add(this._refRangeService.watchRange(u,h,N,(V,L)=>{L?w(L):k.dispose()})),{dispose(){k.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==A}}_createCellPositionObserver(e,t,i,r,s){let l=e,c=t;const d=this._calcCellPositionByCell(l,c,i,r,s),u=new D.BehaviorSubject(d),h=()=>u.next(this._calcCellPositionByCell(l,c,i,r,s)),g=new a.DisposableCollection;return g.add(i.engine.clientRect$.subscribe(()=>h())),g.add(a.fromEventSubject(i.engine.onTransformChange$).pipe(D.throttleTime(16)).subscribe(()=>h())),g.add(this._commandService.onCommandExecuted(f=>{if(f.id===m.SetWorksheetRowAutoHeightMutation.id&&f.params.rowsAutoHeightInfo.findIndex(p=>p.row===l)>-1){h();return}ms(f.id)&&h()})),{position$:u,disposable:g,position:d,updateRowCol:(f,v)=>{l=f,c=v,h()}}}_calcCellPositionByCell(e,t,i,r,s){const{scene:l,engine:c}=i;if(r._disposed||l._disposed)return{left:0,right:0,top:0,bottom:0};const d=r.getCellWithCoordByIndex(e,t),u=d.isMergedMainCell?d.mergeInfo:d,{scaleX:h,scaleY:g}=l.getAncestorScale(),S={x:s.viewportScrollX,y:s.viewportScrollY},f=c.getCanvasElement();if(!f)return{left:0,right:0,top:0,bottom:0};const v=f.getBoundingClientRect(),p=hs(f.style.width),{top:C,left:_,width:w}=v,E=w/p;return{left:(u.startX-S.x)*E*h+_,right:(u.endX-S.x)*E*h+_,top:(u.startY-S.y)*E*g+C,bottom:(u.endY-S.y)*E*g+C}}_createRangePositionObserver(e,t,i,r){let{startRow:s,startColumn:l,endRow:c,endColumn:d}=e;const u=this._calcCellPositionByCell(s,l,t,i,r),h=new D.BehaviorSubject(u),g=this._calcCellPositionByCell(c,d,t,i,r),S=new D.BehaviorSubject(g),f=()=>{const w=this._calcCellPositionByCell(s,l,t,i,r),E=this._calcCellPositionByCell(c,d,t,i,r);h.next(w),S.next(E)},v=new a.DisposableCollection;v.add(t.engine.clientRect$.subscribe(()=>f())),v.add(this._commandService.onCommandExecuted(w=>{if(w.id===m.SetWorksheetRowAutoHeightMutation.id&&w.params.rowsAutoHeightInfo.findIndex(O=>O.row===s)>-1){f();return}ms(w.id)&&f()}));const p=w=>{s=w.startRow,l=w.startColumn,c=w.endRow,d=w.endColumn,f()},C=h.pipe(D.map(w=>{const E=this._calcCellPositionByCell(c,d,t,i,r);return{top:w.top,left:w.left,right:E.right,bottom:E.bottom}})),_={top:u.top,left:u.left,right:g.right,bottom:g.bottom};return{position$:C,position:_,updateRange:p,topLeftPos$:h,rightBottomPos$:S,disposable:v}}},T.SheetCanvasPopManagerService=FS([jt(0,a.Inject(I.ICanvasPopupService)),jt(1,M.IRenderManagerService),jt(2,a.IUniverInstanceService),jt(3,a.Inject(m.RefRangeService)),jt(4,a.ICommandService),jt(5,m.IRefSelectionsService),jt(6,a.Inject(m.SheetsSelectionsService))],T.SheetCanvasPopManagerService);function hs(n){return Number.parseInt(n.replace("px",""))}const zS=new Set([$e.id,Ye.id,m.SetSelectionsOperation.id]);function ms(n){return zS.has(n)||m.COMMAND_LISTENER_SKELETON_CHANGE.includes(n)}var XS=Object.getOwnPropertyDescriptor,YS=(n,o,e,t)=>{for(var i=t>1?void 0:t?XS(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},jS=(n,o)=>(e,t)=>o(e,t,n);T.CellPopupManagerService=class extends a.Disposable{constructor(e){super();y(this,"_cellPopupMap",new Map);y(this,"_change$",new D.Subject);y(this,"change$",this._change$.asObservable());this._sheetCanvasPopManagerService=e}_ensureCellPopupMap(e,t){let i=this._cellPopupMap.get(e);i||(i=new Map,this._cellPopupMap.set(e,i));let r=i.get(t);return r||(r=new a.ObjectMatrix,i.set(t,r)),r}showPopup(e,t){var g,S;const{direction:i="horizontal"}=t,{unitId:r,subUnitId:s,row:l,col:c}=e,d=this._ensureCellPopupMap(r,s),u=(g=d.getValue(l,c))==null?void 0:g[i];t.id=(S=t.id)!=null?S:a.generateRandomId();const h=()=>{var C;const f=d.getValue(l,c);if(!f)return;const v=f[i];if(!v)return;const p=v==null?void 0:v.popups.findIndex(_=>_.id===t.id&&_.componentKey===t.componentKey);v==null||v.popups.splice(p,1),v.popups.length===0&&((C=v.disposable)==null||C.dispose(),f[i]=void 0),this._change$.next({...e,direction:i})};if(u)u.popups.push(t),u.popups.sort((f,v)=>f.priority-v.priority);else{const f=this._sheetCanvasPopManagerService.attachPopupToCell(l,c,{...t,direction:i,componentKey:us,extraProps:{...e,direction:i},noPushMinimumGap:!0,autoRelayout:!1,zIndex:90},r,s);d.setValue(l,c,{...d.getValue(l,c),[i]:{disposable:f,popups:[t]}})}return this._change$.next({...e,direction:i}),a.toDisposable(h)}getPopups(e,t,i,r,s){var c,d;return((d=(c=this._ensureCellPopupMap(e,t).getValue(i,r))==null?void 0:c[s])==null?void 0:d.popups)||[]}hidePopup(e,t,i,r){var c,d;const s=this._ensureCellPopupMap(e,t),l=s.getValue(i,r);l&&(l.horizontal&&((c=l.horizontal.disposable)==null||c.dispose(),l.horizontal=void 0,this._change$.next({unitId:e,subUnitId:t,row:i,col:r,direction:"horizontal"})),l.vertical&&((d=l.vertical.disposable)==null||d.dispose(),l.vertical=void 0,this._change$.next({unitId:e,subUnitId:t,row:i,col:r,direction:"vertical"})),!l.horizontal&&!l.vertical&&s.realDeleteValue(i,r))}},T.CellPopupManagerService=YS([jS(0,a.Inject(T.SheetCanvasPopManagerService))],T.CellPopupManagerService);const ql=n=>{const{popup:o}=n,e=o.extraProps,{row:t,col:i,direction:r,unitId:s,subUnitId:l}=e,c=I.useDependency(T.CellPopupManagerService);I.useObservable(x.useMemo(()=>c.change$.pipe(D.filter(h=>h.row===t&&h.col===i&&h.direction===r)),[c,t,i,r]));const d=c.getPopups(s,l,t,i,r),u=I.useDependency(I.ComponentManager);return b.jsx("div",{"data-u-comp":"cell-popup",className:"univer-ml-px univer-flex univer-flex-col",children:d.map(h=>{var S;const g=u.get(h.componentKey);return g?b.jsx(g,{popup:h},(S=h.id)!=null?S:h.componentKey):null})})},Ql=n=>{const{inputId:o,state:e=!1,type:t="range",confirm:i,cancel:r,name:s,formulaOrRefString:l,comment:c="",localSheetId:d=m.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,hidden:u=!1,id:h}=n,S=I.useDependency(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),f=I.useDependency(a.LocaleService),v=I.useDependency(q.IDefinedNamesService),p=I.useDependency(q.IFunctionService),C=I.useDependency(q.LexerTreeBuilder),_=I.useDependency(I.ComponentManager),w=x.useMemo(()=>_.get(Xo),[]),E=x.useMemo(()=>_.get(Li),[]);if(S==null)return;const O=x.useMemo(()=>S.getUnitId(),[]),R=x.useMemo(()=>S.getActiveSheet().getSheetId(),[]),[P,A]=x.useState(s),[k,N]=x.useState(l),[V,L]=x.useState(c),[H,W]=x.useState(d),[B,U]=x.useState(""),[X,F]=x.useState(t),[Y,j]=x.useState(!0),Q=[{label:f.t("definedName.scopeWorkbook"),value:m.SCOPE_WORKBOOK_VALUE_DEFINED_NAME}],oe=ie=>!q.isReferenceStrings(ie);x.useEffect(()=>{j(!0),A(s),L(c),W(d);let ie=l;l.substring(0,1)===q.operatorToken.EQUALS?F("formula"):oe(l)?(F("formula"),ie=q.operatorToken.EQUALS+l):F("range"),N(ie),U("")},[e]),S.getSheetOrders().forEach(ie=>{const se=S.getSheetBySheetId(ie);Q.push({label:(se==null?void 0:se.getName())||"",value:ie})});const re=ie=>{N(ie)},ce=ie=>{N(ie||"")},G=()=>{if(P.length===0){U(f.t("definedName.nameEmpty"));return}if(v.getValueByName(O,P)!=null&&(h==null||h.length===0)){U(f.t("definedName.nameDuplicate"));return}if(!a.Tools.isValidParameter(P)||q.isReferenceStringWithEffectiveColumn(P)||!a.Tools.isStartValidPosition(P)&&!M.hasCJKText(P.substring(0,1))){U(f.t("definedName.nameInvalid"));return}if(S.getSheetOrders().map(te=>{var fe;return((fe=S.getSheetBySheetId(te))==null?void 0:fe.getName())||""}).includes(P)){U(f.t("definedName.nameSheetConflict"));return}if(k.length===0){U(f.t("definedName.formulaOrRefStringEmpty"));return}if(!Y){U(f.t("definedName.formulaOrRefStringInvalid"));return}if(p.hasExecutor(P.toUpperCase())){U(f.t("definedName.nameConflict"));return}const se=S.getActiveSheet().getName();i&&i({id:h||"",name:P,formulaOrRefString:C.convertRefersToAbsolute(k,a.AbsoluteRefType.ALL,a.AbsoluteRefType.ALL,se),comment:V,localSheetId:H})},Z=ie=>{const se=ie;se==="formula"?l[0]===q.operatorToken.EQUALS?N(l):N(`${q.operatorToken.EQUALS}`):l[0]===q.operatorToken.EQUALS?N(""):N(l),F(se)},J=x.useRef(null),[ne,ue]=x.useState(!1);return I.useSidebarClick(ie=>{var te;((te=J.current)==null?void 0:te.isClickOutSide(ie))&&ue(!1)}),b.jsxs("div",{className:z.clsx("univer-grid univer-space-y-2 univer-pb-1",z.borderBottomClassName,{"univer-hidden":!e}),children:[b.jsx("div",{children:b.jsx(z.Input,{className:"univer-w-full",placeholder:f.t("definedName.inputNamePlaceholder"),value:P,allowClear:!0,onChange:A})}),b.jsx("div",{children:b.jsxs(z.RadioGroup,{value:X,onChange:Z,children:[b.jsx(z.Radio,{value:"range",children:f.t("definedName.ratioRange")}),b.jsx(z.Radio,{value:"formula",children:f.t("definedName.ratioFormula")})]})}),X==="range"?w&&b.jsx(w,{unitId:O,subUnitId:R,initialValue:k,onChange:(ie,se)=>re(se),supportAcrossSheet:!0}):E&&b.jsx("div",{className:"univer-relative univer-mt-4 univer-h-full",children:b.jsx("div",{className:"univer-relative univer-h-8 univer-select-none",children:b.jsx(E,{ref:J,className:z.clsx("univer-box-border univer-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-rounded-lg univer-bg-white univer-pt-2 univer-transition-colors hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white [&>div:first-child]:univer-px-2.5 [&>div]:univer-h-5 [&>div]:univer-ring-transparent",z.borderClassName),initValue:k,unitId:O,subUnitId:R,isFocus:ne,isSupportAcrossSheet:!0,onChange:(ie="")=>{ce(ie||"")},onVerify:ie=>{j(ie)},onFocus:()=>ue(!0)})})}),b.jsx("div",{children:b.jsx(z.Select,{className:"univer-w-full",value:H,options:Q,onChange:W})}),b.jsx("div",{children:b.jsx(z.Input,{className:"univer-w-full",placeholder:f.t("definedName.inputCommentPlaceholder"),value:V,onChange:L,allowClear:!0})}),b.jsxs("div",{className:z.clsx("univer-items-center univer-gap-1 univer-text-sm univer-text-red-500",{"univer-hidden":B.length===0,"univer-flex":B.length!==0}),children:[b.jsx("span",{children:B}),b.jsx(br,{})]}),b.jsxs("div",{className:"univer-flex univer-gap-2",children:[b.jsx(z.Button,{onClick:()=>{r==null||r()},children:f.t("definedName.cancel")}),b.jsx(z.Button,{variant:"primary",onClick:G,children:f.t("definedName.confirm")})]})]})},Jl=()=>{const n=I.useDependency(a.ICommandService),e=I.useDependency(a.IUniverInstanceService).getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET),t=I.useDependency(a.LocaleService),i=I.useDependency(q.IDefinedNamesService),r=I.useDependency(m.SheetsSelectionsService);if(e==null)return;const s=e.getUnitId(),l=()=>{const V=i.getDefinedNameMap(s);return V?Array.from(Object.values(V)):[]},[c,d]=x.useState(!1),[u,h]=x.useState(l()),[g,S]=x.useState(null),[f,v]=x.useState();x.useEffect(()=>{const V=i.update$.subscribe(()=>{h(l())});return()=>{V.unsubscribe()}},[]);const p=V=>{const{name:L,formulaOrRefString:H,comment:W,localSheetId:B,hidden:U}=V;let X=V.id;if(X==null||X.length===0)X=a.generateRandomId(10),n.executeCommand(m.InsertDefinedNameCommand.id,{id:X,unitId:s,name:L,formulaOrRefString:H,comment:W,localSheetId:B,hidden:U});else{const F={id:X,unitId:s,name:L,formulaOrRefString:H,comment:W,localSheetId:B,hidden:U};n.executeCommand(m.SetDefinedNameCommand.id,F)}d(!1),S(null)},C=V=>{v(V)};function _(){v(null)}function w(V){const L=i.getValueById(s,V);n.executeCommand(m.RemoveDefinedNameCommand.id,{...L,unitId:s}),v(null)}const E=async V=>{const{formulaOrRefString:L,id:H}=V,W=i.getWorksheetByRef(s,L);if(!W)return;W.isSheetHidden()&&await n.executeCommand(m.SetWorksheetShowCommand.id,{unitId:s,subUnitId:W.getSheetId()}),i.focusRange(s,H)},O=()=>{const V=u.length+1,L=t.t("definedName.defaultName")+V;if(i.getValueByName(s,L)==null)return L;let H=V+1;for(;;){const W=t.t("definedName.defaultName")+H;if(i.getValueByName(s,W)==null)return W;H++}},R=()=>{var W;const V=(W=e.getActiveSheet())==null?void 0:W.getName();if(!V)return"";const L=r.getCurrentSelections();return L==null?"":L.map(B=>q.serializeRangeWithSheet(V,B.range)).join(",")},P=()=>{d(!1),S(null)},A=()=>{d(!0),S(null)},k=V=>{d(!1),S(V)},N=V=>{const L=e.getSheetBySheetId(V);return L==null?"":L.getName()};return b.jsx("div",{"data-u-comp":"defined-name-container",className:"univer-relative univer-box-border univer-w-full",children:b.jsxs("div",{className:z.clsx("univer-w-full univer-overflow-hidden univer-overflow-y-auto",z.scrollbarClassName),children:[b.jsxs("div",{className:"univer-mb-4",children:[b.jsxs(z.Button,{className:z.clsx("univer-w-full",{"univer-hidden":c}),onClick:A,children:[b.jsx(wr,{}),b.jsx("span",{className:"univer-ml-1",children:t.t("definedName.addButton")})]}),c&&b.jsx(Ql,{confirm:p,cancel:P,state:c,inputId:"insertDefinedName",name:O(),formulaOrRefString:R()})]},"insertDefinedName"),u.map((V,L)=>b.jsxs("div",{className:"univer-relative univer-w-full univer-divide-x-0 univer-divide-y univer-divide-solid univer-divide-gray-200 dark:!univer-divide-gray-600",children:[b.jsxs("div",{className:z.clsx("univer-group univer-relative univer-flex univer-w-full univer-cursor-default univer-select-none univer-items-center univer-justify-between univer-rounded-md univer-p-2 hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-700",{"univer-hidden":V.id===g}),onClick:()=>{E(V)},children:[b.jsxs("div",{title:V.comment,children:[b.jsxs("div",{className:"univer-my-1 univer-max-h-[100px] univer-max-w-[190px] univer-truncate univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white",children:[V.name,b.jsx("span",{className:"univer-text-xxs univer-ml-1 univer-text-gray-400",children:V.localSheetId===m.SCOPE_WORKBOOK_VALUE_DEFINED_NAME||V.localSheetId==null?"":N(V.localSheetId)})]}),b.jsx("div",{className:"univer-my-1 univer-max-h-[100px] univer-w-full univer-max-w-[190px] univer-truncate univer-text-xs univer-text-gray-500",title:V.formulaOrRefString,children:V.formulaOrRefString})]}),b.jsxs("div",{className:"univer-absolute univer-right-5 univer-top-1/2 univer-hidden -univer-translate-y-1/2 univer-cursor-pointer univer-items-center univer-justify-end univer-gap-7 univer-text-xs univer-text-primary-600 group-hover:univer-flex dark:hover:!univer-bg-gray-600",children:[b.jsx(z.Tooltip,{title:t.t("definedName.updateButton"),placement:"top",children:b.jsx("a",{className:"univer-rounded univer-p-1 hover:univer-bg-gray-100",onClick:H=>{H.stopPropagation(),k(V.id)},children:b.jsx(Wa,{})})}),b.jsx(z.Tooltip,{title:t.t("definedName.deleteButton"),placement:"top",children:b.jsx("a",{className:"univer-rounded univer-p-1 univer-text-red-600 hover:univer-bg-gray-100",onClick:H=>{H.stopPropagation(),C(V.id)},children:b.jsx(co,{})})})]})]}),b.jsx(z.Confirm,{visible:f===V.id,onClose:_,onConfirm:()=>{w(V.id)},children:t.t("definedName.deleteConfirmText")}),V.id===g&&b.jsx(Ql,{confirm:p,cancel:P,state:V.id===g,id:V.id,inputId:V.id+L,name:V.name,formulaOrRefString:V.formulaOrRefString,comment:V.comment,localSheetId:V.localSheetId})]},L))]})})},$l={id:m.SetRowHiddenCommand.id,preconditions:n=>ae(n),binding:I.KeyCode.Digit9|I.MetaKeys.CTRL_COMMAND},ec={id:m.SetColHiddenCommand.id,preconditions:n=>ae(n),binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT},tc={id:Pe.id,description:"shortcut.sheet.select-below-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN,priority:100,preconditions:ae,staticParameters:{direction:a.Direction.DOWN}},nc={id:Pe.id,description:"shortcut.sheet.select-up-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP,priority:100,preconditions:ae,staticParameters:{direction:a.Direction.UP}},ic={id:Pe.id,description:"shortcut.sheet.select-left-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT,priority:100,preconditions:Gs,staticParameters:{direction:a.Direction.LEFT}},oc={id:Pe.id,description:"shortcut.sheet.select-right-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT,priority:100,preconditions:Gs,staticParameters:{direction:a.Direction.RIGHT}},rc={id:ze.id,description:"shortcut.sheet.select-next-cell",group:"3_sheet-view",binding:I.KeyCode.TAB,priority:100,preconditions:ae,staticParameters:{direction:a.Direction.RIGHT,keycode:I.KeyCode.TAB}},sc={id:ze.id,description:"shortcut.sheet.select-previous-cell",group:"3_sheet-view",binding:I.KeyCode.TAB|I.MetaKeys.SHIFT,priority:100,preconditions:ae,staticParameters:{direction:a.Direction.LEFT,keycode:I.KeyCode.TAB}},ac={id:ze.id,description:"shortcut.sheet.select-below-cell",group:"3_sheet-view",binding:I.KeyCode.ENTER,priority:100,preconditions:ae,staticParameters:{direction:a.Direction.DOWN,keycode:I.KeyCode.ENTER}},lc={id:ze.id,description:"shortcut.sheet.select-up-cell",group:"3_sheet-view",binding:I.KeyCode.ENTER|I.MetaKeys.SHIFT,priority:100,preconditions:ae,staticParameters:{direction:a.Direction.UP,keycode:I.KeyCode.ENTER}},cc={id:Pe.id,description:"shortcut.sheet.select-below-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN|I.MetaKeys.CTRL_COMMAND,preconditions:ae,staticParameters:{direction:a.Direction.DOWN,jumpOver:Fe.moveGap}},dc={id:Pe.id,description:"shortcut.sheet.select-up-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP|I.MetaKeys.CTRL_COMMAND,preconditions:ae,staticParameters:{direction:a.Direction.UP,jumpOver:Fe.moveGap}},uc={id:Pe.id,description:"shortcut.sheet.select-left-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT|I.MetaKeys.CTRL_COMMAND,preconditions:ae,staticParameters:{direction:a.Direction.LEFT,jumpOver:Fe.moveGap}},hc={id:Pe.id,description:"shortcut.sheet.select-right-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT|I.MetaKeys.CTRL_COMMAND,preconditions:ae,staticParameters:{direction:a.Direction.RIGHT,jumpOver:Fe.moveGap}},mc={id:De.id,description:"shortcut.sheet.expand-selection-down",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN|I.MetaKeys.SHIFT,preconditions:ae,staticParameters:{direction:a.Direction.DOWN}},gc={id:De.id,description:"shortcut.sheet.expand-selection-up",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP|I.MetaKeys.SHIFT,preconditions:ae,staticParameters:{direction:a.Direction.UP}},Sc={id:De.id,description:"shortcut.sheet.expand-selection-left",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT|I.MetaKeys.SHIFT,preconditions:ae,staticParameters:{direction:a.Direction.LEFT}},fc={id:De.id,description:"shortcut.sheet.expand-selection-right",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT|I.MetaKeys.SHIFT,preconditions:ae,staticParameters:{direction:a.Direction.RIGHT}},vc={id:De.id,description:"shortcut.sheet.expand-selection-to-below-gap",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ae,staticParameters:{direction:a.Direction.DOWN,jumpOver:Fe.moveGap}},pc={id:De.id,description:"shortcut.sheet.expand-selection-to-up-gap",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ae,staticParameters:{direction:a.Direction.UP,jumpOver:Fe.moveGap}},Cc={id:De.id,description:"shortcut.sheet.expand-selection-to-left-gap",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ae,staticParameters:{direction:a.Direction.LEFT,jumpOver:Fe.moveGap}},Ic={id:De.id,description:"shortcut.sheet.expand-selection-to-right-gap",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ae,staticParameters:{direction:a.Direction.RIGHT,jumpOver:Fe.moveGap}},_c={id:gi.id,description:"shortcut.sheet.select-all",group:"3_sheet-view",binding:I.KeyCode.A|I.MetaKeys.CTRL_COMMAND,preconditions:ae,staticParameters:{expandToGapFirst:!0,loop:!0}},bc={id:Rt.id,description:"shortcut.sheet.set-bold",group:"4_sheet-edit",preconditions:n=>ae(n),binding:I.KeyCode.B|I.MetaKeys.CTRL_COMMAND},wc={id:Mt.id,description:"shortcut.sheet.set-italic",group:"4_sheet-edit",preconditions:n=>ae(n),binding:I.KeyCode.I|I.MetaKeys.CTRL_COMMAND},Ec={id:Pt.id,description:"shortcut.sheet.set-underline",group:"4_sheet-edit",preconditions:n=>ae(n),binding:I.KeyCode.U|I.MetaKeys.CTRL_COMMAND},Tc={id:Ot.id,description:"shortcut.sheet.set-strike-through",group:"4_sheet-edit",preconditions:n=>ae(n),binding:I.KeyCode.X|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND},yc={id:m.ClearSelectionContentCommand.id,preconditions:n=>ae(n),binding:I.KeyCode.DELETE,mac:I.KeyCode.BACKSPACE},Rc={id:m.ClearSelectionContentCommand.id,preconditions:n=>ae(n),mac:I.KeyCode.DELETE},Mc={id:m.ClearSelectionContentCommand.id,preconditions:n=>ae(n),binding:I.MetaKeys.SHIFT+I.KeyCode.BACKSPACE},Pc={id:ji.id,preconditions:n=>ae(n),binding:I.MetaKeys.SHIFT+I.KeyCode.DELETE},Oc={id:In.id,description:"shortcut.sheet.zoom-in",binding:I.KeyCode.EQUAL|I.MetaKeys.CTRL_COMMAND,group:"3_sheet-view",preconditions:ae,priority:1,staticParameters:{delta:.2}},Ac={id:a.NilCommand.id,binding:I.KeyCode.EQUAL|I.MetaKeys.CTRL_COMMAND},Dc={id:In.id,description:"shortcut.sheet.zoom-out",binding:I.KeyCode.MINUS|I.MetaKeys.CTRL_COMMAND,group:"3_sheet-view",preconditions:ae,priority:1,staticParameters:{delta:-.2}},kc={id:a.NilCommand.id,binding:I.KeyCode.MINUS|I.MetaKeys.CTRL_COMMAND},Nc={id:In.id,description:"shortcut.sheet.reset-zoom",binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND,preconditions:ae,group:"3_sheet-view",priority:1,staticParameters:{reset:!0}},Vc={id:a.NilCommand.id,binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND};var ZS=Object.getOwnPropertyDescriptor,GS=(n,o,e,t)=>{for(var i=t>1?void 0:t?ZS(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},St=(n,o)=>(e,t)=>o(e,t,n);T.SheetUIController=class extends a.Disposable{constructor(o,e,t,i,r,s,l,c){super(),this._injector=o,this._componentManager=e,this._layoutService=t,this._commandService=i,this._shortcutService=r,this._menuManagerService=s,this._uiPartsService=l,this._configService=c,this._init()}_init(){this._initComponents(),this._initCommands(),this._initMenus(),this._initShortcuts(),this._initWorkbenchParts(),this._initFocusHandler()}_initComponents(){const o=this._componentManager;this.disposeWithMe(o.register(je,Ol)),this.disposeWithMe(o.register(Vr,Kl)),this.disposeWithMe(o.register(bi,Jl)),this.disposeWithMe(o.register(us,ql)),this.disposeWithMe(o.register("HideGridlinesDoubleIcon",Rr))}_initCommands(){[Gr,gt,qr,Kr,In,De,Pe,ze,_i,ci,un,hn,ei,ti,Le,Sr,gi,oo,m.SetBoldCommand,Lt,Se,Ii,Rt,Mt,Pt,Ot,ur,hr,ni,Ki,qi,ln,cn,Qi,m.SetItalicCommand,m.SetStrikeThroughCommand,m.SetFontFamilyCommand,m.SetFontSizeCommand,di,no,gn,ui,$e,vn,Je,hi,mi,ro,m.SetUnderlineCommand,_n,Ye,vi,li,At,Tt,dn,an,so,dt,en,Ue,fr,ri,kt,Nt,si,ai,Ci,Vt,Ht,pi,pn,Xn,Yn].forEach(o=>{this.disposeWithMe(this._commandService.registerCommand(o))})}_initMenus(){this._menuManagerService.mergeMenu(zl)}_initShortcuts(){[tc,nc,ic,oc,rc,sc,ac,lc,cc,dc,uc,hc,mc,gc,Sc,fc,vc,pc,Cc,Ic,_c,Oc,Dc,Nc,Vc,Ac,kc,bc,wc,Ec,Tc,yc,Rc,Mc,Pc,...nl(),ol,il,rl,ll,cl,dl,hl,sl,al,ul,$l,ec].forEach(o=>{this.disposeWithMe(this._shortcutService.registerShortcut(o))})}_initWorkbenchParts(){const o=this._uiPartsService,e=this._injector;this.disposeWithMe(o.registerComponent(I.BuiltInUIPart.HEADER,()=>I.connectInjector(Qa,e))),this.disposeWithMe(o.registerComponent(I.BuiltInUIPart.FOOTER,()=>I.connectInjector(qa,e))),this.disposeWithMe(o.registerComponent(I.BuiltInUIPart.CONTENT,()=>I.connectInjector(Or,e)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(a.UniverInstanceType.UNIVER_SHEET,o=>{const e=this._injector.get(M.IRenderManagerService),t=this._injector.get(a.IUniverInstanceService),i=M.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_DOC,t,e),r=i==null?void 0:i.with(K.DocSelectionRenderService);r==null||r.focus()}))}},T.SheetUIController=GS([St(0,a.Inject(a.Injector)),St(1,a.Inject(I.ComponentManager)),St(2,I.ILayoutService),St(3,a.ICommandService),St(4,I.IShortcutService),St(5,I.IMenuManagerService),St(6,I.IUIPartsService),St(7,a.IConfigService)],T.SheetUIController);var KS=Object.getOwnPropertyDescriptor,qS=(n,o,e,t)=>{for(var i=t>1?void 0:t?KS(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},An=(n,o)=>(e,t)=>o(e,t,n);const QS=a.createInterceptorKey("statusBarPermissionCorrect");class JS{constructor(){y(this,"_sum",0);y(this,"_count",0);y(this,"_countNumber",0);y(this,"_min",Number.POSITIVE_INFINITY);y(this,"_max",Number.NEGATIVE_INFINITY)}add(o,e,t){if(!a.Tools.isDefine(o==null?void 0:o.v))return;const i=o==null?void 0:o.t;let{v:r}=o;const s=c=>{this._sum+=c,this._countNumber++,this._min=Math.min(this._min,c),this._max=Math.max(this._max,c)},l=(c,d,u)=>{var S;if(!((S=c==null?void 0:c.n)!=null&&S.pattern))return;const{pattern:h}=c.n;u[h]||(u[h]=a.numfmt.getFormatInfo(h)),u[h].isDate&&s(d)};if(typeof r=="string"&&i===a.CellValueType.NUMBER){const c=Number(r);Number.isNaN(c)||(r=c)}if(typeof r=="number"&&i!==a.CellValueType.STRING)s(r);else if(i===a.CellValueType.NUMBER&&o.s){const c=e.get(o.s);l(c,r,t)}this._count++}getResults(){return{sum:this._sum,count:this._countNumber,countA:this._count,min:this._min,max:this._max}}}function $S(n){const{sum:o,count:e,countA:t,min:i,max:r}=n.getResults();return[{func:q.FUNCTION_NAMES_STATISTICAL.MAX,value:r},{func:q.FUNCTION_NAMES_STATISTICAL.MIN,value:i},{func:q.FUNCTION_NAMES_MATH.SUM,value:o},{func:q.FUNCTION_NAMES_STATISTICAL.COUNTA,value:t},{func:q.FUNCTION_NAMES_STATISTICAL.COUNT,value:e},{func:q.FUNCTION_NAMES_STATISTICAL.AVERAGE,value:o/e}]}T.StatusBarController=class extends a.Disposable{constructor(e,t,i,r,s,l){super();y(this,"interceptor",new a.InterceptorManager({STATUS_BAR_PERMISSION_CORRECT:QS}));this._univerInstanceService=e,this._selectionManagerService=t,this._statusBarService=i,this._commandService=r,this._numfmtService=s,this._formulaDataModel=l,this._init()}_init(){this._registerSelectionListener()}_registerSelectionListener(){const e=a.debounce(i=>{var s;const r=(s=i[i.length-1])==null?void 0:s.primary;this._calculateSelection(i.map(l=>l.range),r)},100),t=a.debounce(i=>{var s;const r=(s=i[i.length-1])==null?void 0:s.primary;this._calculateSelection(i.map(l=>l.range),r)},500);this.disposeWithMe(a.toDisposable(this._selectionManagerService.selectionMoving$.subscribe(i=>{i&&t(i)}))),this.disposeWithMe(a.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(i=>{i&&e(i)}))),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===m.SetRangeValuesMutation.id){const r=this._selectionManagerService.getCurrentSelections();r&&e(r)}}))}_clearResult(){this._statusBarService.setState(null)}getRangeStartEndInfo(e,t){return e.rangeType===a.RANGE_TYPE.ALL?{startRow:0,startColumn:0,endRow:t.getRowCount()-1,endColumn:t.getColumnCount()-1}:e.rangeType===a.RANGE_TYPE.COLUMN?{startRow:0,startColumn:e.startColumn,endRow:t.getRowCount()-1,endColumn:e.endColumn}:e.rangeType===a.RANGE_TYPE.ROW?{startRow:e.startRow,startColumn:0,endRow:e.endRow,endColumn:t.getColumnCount()-1}:{startRow:e.startRow,startColumn:e.startColumn,endRow:e.endRow,endColumn:e.endColumn}}_getCellValue(e,t,i,r){var c,d,u,h;const s=i.getCellRaw(e,t),l=(c=r==null?void 0:r[e])==null?void 0:c[t];return l?{t:(d=l.t)!=null?d:s==null?void 0:s.t,v:(u=l.v)!=null?u:s==null?void 0:s.v,s:(h=l.s)!=null?h:s==null?void 0:s.s}:s}_calculateSelection(e,t){var d,u;const i=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!i)return this._clearResult();const r=i.getUnitId(),s=i.getActiveSheet(),l=s==null?void 0:s.getSheetId();if(!l)return this._clearResult();const c={};if(this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getSheets().forEach(h=>{const g=h.getConfig();c[h.getSheetId()]={cellData:new a.ObjectMatrix(g.cellData),rowCount:g.rowCount,columnCount:g.columnCount,rowData:g.rowData,columnData:g.columnData}}),e!=null&&e.length){const h=[];e.forEach(R=>{const{startRow:P,endRow:A}=R;let k=null;for(let N=P;N<=A;N++)s.getRowVisible(N)?k===null&&(k=N):k!==null&&(h.push({...R,startRow:k,endRow:N-1}),k=null);k!==null&&h.push({...R,startRow:k,endRow:A})});const g=a.splitIntoGrid(h),S=new JS,f=i.getStyles(),v={},p=this._formulaDataModel.getArrayFormulaCellData(),C=(d=p==null?void 0:p[r])==null?void 0:d[l];for(const R of g){const{startRow:P,startColumn:A,endColumn:k,endRow:N}=this.getRangeStartEndInfo(R,s);for(let V=P;V<=N;V++)for(let L=A;L<=k;L++){const H=this._getCellValue(V,L,s,C);S.add(H,f,v)}}const _=$S(S);if(_.every(R=>R===void 0))return;let w=null;if(t){const{actualRow:R,actualColumn:P}=t;w=(u=this._numfmtService.getValue(r,l,R,P))==null?void 0:u.pattern}const O={values:_.filter(R=>R!==void 0),pattern:w};this._statusBarService.setState(O)}else this._clearResult()}},T.StatusBarController=qS([An(0,a.IUniverInstanceService),An(1,a.Inject(m.SheetsSelectionsService)),An(2,wi),An(3,a.ICommandService),An(4,a.Inject(m.INumfmtService)),An(5,a.Inject(q.FormulaDataModel))],T.StatusBarController);const Hc=(n=[])=>{const o=I.useDependency(wt);x.useEffect(()=>{const e=n.map(t=>o.addShape({range:t,style:{fill:"rgba(73, 184, 17, 0.05)",strokeWidth:1,stroke:"#49B811",widgets:{}},primary:{startColumn:t.startColumn,endColumn:t.endColumn,startRow:t.startRow,endRow:t.endRow,actualRow:t.startRow,actualColumn:t.startColumn,isMerged:!1,isMergedMainCell:!1}}));return()=>{e.forEach(t=>{t&&o.removeShape(t)})}},[n])};var ef=Object.getOwnPropertyDescriptor,tf=(n,o,e,t)=>{for(var i=t>1?void 0:t?ef(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},Wc=(n,o)=>(e,t)=>o(e,t,n);let Dn=class extends a.Disposable{constructor(o,e){super();y(this,"_previousSheetIndex",-1);this._commandService=o,this._univerInstanceService=e,this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{if(t.id===m.RemoveSheetMutation.id)return this._beforeAdjustActiveSheetOnRemoveSheet(t)})),this.disposeWithMe(this._commandService.onCommandExecuted((t,i)=>{if(t.id===m.RemoveSheetMutation.id)return this._adjustActiveSheetOnRemoveSheet(t);if(t.id===m.SetWorksheetHideMutation.id&&t.params.hidden)return this._adjustActiveSheetOnHideSheet(t);if(i!=null&&i.fromCollab)return!1;if(t.id===m.InsertSheetMutation.id)return this._adjustActiveSheetOnInsertSheet(t);if(t.id===m.SetWorksheetHideMutation.id&&!t.params.hidden)return this._adjustActiveSheetOnShowSheet(t);if(t.id===m.SetSelectionsOperation.id)return this._adjustActiveSheetOnSelection(t)}))}_adjustActiveSheetOnHideSheet(o){var c;const{unitId:e,subUnitId:t}=o.params,i=this._univerInstanceService.getUniverSheetInstance(e);if(!i||((c=i.getActiveSheet())==null?void 0:c.getSheetId())!==t)return;const s=i.getActiveSheetIndex(),l=Lc(i,s);this._switchToNextSheet(e,l)}_beforeAdjustActiveSheetOnRemoveSheet(o){const{unitId:e,subUnitId:t}=o.params,i=this._univerInstanceService.getUniverSheetInstance(e);if(!i)return;const r=i.getSheetBySheetId(t);r&&(this._previousSheetIndex=i.getSheetIndex(r))}_adjustActiveSheetOnRemoveSheet(o){if(this._previousSheetIndex===-1)return;const{unitId:e}=o.params,t=this._univerInstanceService.getUniverSheetInstance(e);if(!t)return;if(t.getActiveSheet().getSheetId()===o.params.subUnitId){const r=this._previousSheetIndex,s=r>=1?r-1:0,l=Lc(t,s);this._switchToNextSheet(e,l)}}_adjustActiveSheetOnInsertSheet(o){const{unitId:e,sheet:t}=o.params;this._switchToNextSheet(e,t.id)}_adjustActiveSheetOnShowSheet(o){const{unitId:e,subUnitId:t}=o.params;this._switchToNextSheet(e,t)}_adjustActiveSheetOnSelection(o){var i;const{unitId:e,subUnitId:t}=o.params;t!==((i=this._univerInstanceService.getUnit(e))==null?void 0:i.getActiveSheet().getSheetId())&&this._switchToNextSheet(e,t)}_switchToNextSheet(o,e){this._commandService.executeCommand(m.SetWorksheetActiveOperation.id,{unitId:o,subUnitId:e})}};Dn=tf([Wc(0,a.ICommandService),Wc(1,a.IUniverInstanceService)],Dn);function Lc(n,o){const e=n.getSheetSize();for(let t=o;t>-1;t--){const i=n.getSheetByIndex(t);if(!i.getConfig().hidden)return i.getSheetId()}for(let t=o;t<e;t++){const i=n.getSheetByIndex(t);if(!i.getConfig().hidden)return i.getSheetId()}throw new Error("[ActiveWorksheetController]: could not find the next unhidden sheet! Collaboration error perhaps.")}var nf=Object.getOwnPropertyDescriptor,of=(n,o,e,t)=>{for(var i=t>1?void 0:t?nf(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},xc=(n,o)=>(e,t)=>o(e,t,n),kn=(n=>(n[n.INFO=0]="INFO",n[n.WARNING=1]="WARNING",n[n.ERROR=2]="ERROR",n))(kn||{});T.CellAlertManagerService=class extends a.Disposable{constructor(e,t){super();y(this,"_currentAlert$",new D.Subject);y(this,"_currentAlert",new Map);y(this,"currentAlert$",this._currentAlert$.asObservable());this._renderManagerService=e,this._cellPopupManagerService=t,this.disposeWithMe(()=>{this._currentAlert$.complete()})}get currentAlert(){return this._currentAlert}showAlert(e){var h;let t=this._currentAlert.get(e.key);t&&t.dispose.dispose(),t?t.dispose.dispose():(t={alert:e,dispose:{dispose(){}}},this._currentAlert.set(e.key,t));const{location:i}=e,{row:r,col:s,unitId:l,subUnitId:c}=i;if(!this._renderManagerService.getRenderById(l))return;const u=this._cellPopupManagerService.showPopup({unitId:l,subUnitId:c,row:r,col:s},{componentKey:Uc,direction:"horizontal",extraProps:{alert:e},priority:1});u&&(t&&((h=t.dispose)==null||h.dispose()),t.dispose=u),this._currentAlert$.next(Array.from(this._currentAlert.entries()))}removeAlert(e){const t=this._currentAlert.get(e);t&&(this._currentAlert.delete(e),t==null||t.dispose.dispose(),this._currentAlert$.next(Array.from(this._currentAlert.entries())))}clearAlert(){this._currentAlert.forEach(e=>{e.dispose.dispose()}),this._currentAlert.clear(),this._currentAlert$.next(Array.from(this._currentAlert.entries()))}},T.CellAlertManagerService=of([xc(0,M.IRenderManagerService),xc(1,a.Inject(T.CellPopupManagerService))],T.CellAlertManagerService);function rf({popup:n}){var s;const o=(s=n.extraProps)==null?void 0:s.alert;if(!o)return null;const{type:e,title:t,message:i}=o,r={[kn.ERROR]:b.jsx(br,{className:"univer-mr-1.5 univer-text-red-500"}),[kn.INFO]:b.jsx(Ha,{className:"univer-mr-1.5 univer-text-blue-500"}),[kn.WARNING]:b.jsx(xa,{className:"univer-mr-1.5 univer-text-yellow-500"})};return b.jsxs("div",{className:"univer-z-[100] univer-box-border univer-w-[156px] univer-rounded-lg univer-bg-white univer-px-2 univer-py-1 univer-text-gray-900 univer-shadow dark:!univer-bg-black dark:!univer-text-white",children:[b.jsxs("div",{className:"univer-mb-1.5 univer-flex univer-h-5 univer-flex-row univer-items-center univer-text-sm univer-font-medium",children:[e?r[e]:null,t]}),b.jsx("div",{className:"univer-text-sm",children:i})]})}const Uc="univer.sheet.cell-alert";var sf=Object.getOwnPropertyDescriptor,af=(n,o,e,t)=>{for(var i=t>1?void 0:t?sf(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},lf=(n,o)=>(e,t)=>o(e,t,n);let Co=class extends a.Disposable{constructor(n,o){super(),this._context=n,this._componentManager=o,this._initComponent()}_initComponent(){this.disposeWithMe(this._componentManager.register(Uc,rf))}};Co=af([lf(1,a.Inject(I.ComponentManager))],Co);var cf=Object.getOwnPropertyDescriptor,df=(n,o,e,t)=>{for(var i=t>1?void 0:t?cf(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},Bc=(n,o)=>(e,t)=>o(e,t,n);let Io=class extends a.Disposable{constructor(n,o,e){super(),this._context=n,this._editorBridgeService=o,this._cellPopupManagerService=e,this._initEditorVisibleListener()}_initEditorVisibleListener(){this.disposeWithMe(this._editorBridgeService.visible$.pipe(D.filter(n=>n.visible)).subscribe(()=>{const n=this._editorBridgeService.getEditLocation();n&&this._cellPopupManagerService.hidePopup(n.unitId,n.sheetId,n.row,n.column)}))}};Io=df([Bc(1,me),Bc(2,a.Inject(T.CellPopupManagerService))],Io);var uf=Object.getOwnPropertyDescriptor,hf=(n,o,e,t)=>{for(var i=t>1?void 0:t?uf(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},_o=(n,o)=>(e,t)=>o(e,t,n);let Nn=class extends a.Disposable{constructor(o,e,t,i){super();y(this,"_isPointer",!1);this._hoverManagerService=o,this._instanceService=e,this._commandService=t,this._renderManagerService=i,this._initPointerEvent(),this._initHover()}get _mainComponent(){var o;return(o=M.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET,this._instanceService,this._renderManagerService))==null?void 0:o.mainComponent}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichText$.subscribe(o=>{var e,t;o!=null&&o.bullet?(this._isPointer||(e=this._mainComponent)==null||e.setCursor(M.CURSOR_TYPE.POINTER),this._isPointer=!0):(this._isPointer&&((t=this._mainComponent)==null||t.setCursor(M.CURSOR_TYPE.AUTO)),this._isPointer=!1)}))}_initPointerEvent(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(o=>{const{location:e,bullet:t}=o;t&&this._commandService.executeCommand(m.ToggleCellCheckboxCommand.id,{unitId:e.unitId,subUnitId:e.subUnitId,row:e.row,col:e.col,paragraphIndex:t.startIndex})}))}};Nn=hf([_o(0,a.Inject(T.HoverManagerService)),_o(1,a.IUniverInstanceService),_o(2,a.ICommandService),_o(3,M.IRenderManagerService)],Nn);const Fc=2,mf=[{value:"DEFAULT_PASTE",label:"rightClick.paste"},{value:"SPECIAL_PASTE_VALUE",label:"rightClick.pasteValue"},{value:"SPECIAL_PASTE_FORMAT",label:"rightClick.pasteFormat"},{value:"SPECIAL_PASTE_COL_WIDTH",label:"rightClick.pasteColWidth"},{value:"SPECIAL_PASTE_BESIDES_BORDER",label:"rightClick.pasteBesidesBorder"},{value:"SPECIAL_PASTE_FORMULA",label:"formula.operation.pasteFormula"}],gf=n=>{var V,L,H,W,B;const o=I.useDependency(a.IUniverInstanceService),e=I.useDependency(M.IRenderManagerService),t=mt();if(!n||!t)return null;const i={startRow:n.rows[0],startCol:n.cols[0],endRow:n.rows[n.rows.length-1],endCol:n.cols[n.cols.length-1]};if(i.endRow<0||i.endCol<0)return null;const r=e.getRenderById(t.getUnitId()),s=r==null?void 0:r.with(T.SheetSkeletonManagerService),l=r==null?void 0:r.with(Ie),c=Ve(o,e);if(!c||!l)return null;const{scene:d}=c,u=s==null?void 0:s.getCurrentSkeleton(),h=l.getViewPort(),g=d==null?void 0:d.scaleX,S=d==null?void 0:d.scaleY,f=d==null?void 0:d.getViewportScrollXY(h),v=(V=d.getEngine())==null?void 0:V.getCanvas();if(!g||!d||!g||!S||!f)return null;const p=u==null?void 0:u.getNoMergeCellPositionByIndex(i.endRow,i.endCol),C=(L=p==null?void 0:p.endX)!=null?L:0,_=(H=p==null?void 0:p.endY)!=null?H:0,w=(W=M.convertTransformToOffsetX(C,g,f))!=null?W:-9999,E=(B=M.convertTransformToOffsetY(_,S,f))!=null?B:-9999,O=v==null?void 0:v.getWidth(),R=v==null?void 0:v.getHeight();if(!O||!R)return null;const P=w+50<=O,A=E+50<=R;let k=w,N=E;return P||(k=O-100),A||(N=R-100),{positionX:k,positionY:N}},Sf=()=>{const n=I.useDependency(Ne),o=I.useObservable(n.showMenu$,!1),e=I.useObservable(n.pasteOptionsCache$,null),t=I.useDependency(a.LocaleService),i=I.useDependency(a.ICommandService),[r,s]=x.useState(!1),[l,c]=x.useState(!1),d=e==null?void 0:e.target.pastedRange,u=gf(d);if(!u||!o||u.positionX<50||u.positionY<30)return null;const h=r||l,g=S=>{c(!1),i.executeCommand(ca.id,{type:S})};return b.jsx("div",{className:"univer-absolute univer-inset-0 univer-z-10 univer-size-0",children:b.jsx("div",{className:"univer-absolute",style:{left:u.positionX+Fc,top:u.positionY+Fc},onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),children:b.jsx(z.DropdownMenu,{align:"start",items:mf.map(S=>({type:"checkbox",value:S.value,label:t.t(S.label),checked:(e==null?void 0:e.pasteType)===ge[S.value],onSelect:()=>g(S.value)})),open:l,onOpenChange:c,children:b.jsxs("div",{className:z.clsx("univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-800",z.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-800":l,"univer-bg-white dark:!univer-bg-gray-900":!l}),children:[b.jsx(Fa,{className:"univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-white"}),h&&b.jsx(wn,{className:"dark:!univer-text-white"})]})})})})},ff=[Se.id,m.SetRangeValuesCommand.id,Ye.id,m.MoveRangeMutation.id,m.RemoveRowMutation.id,m.RemoveColMutation.id,m.InsertRowMutation.id,m.InsertColMutation.id,m.MoveRowsMutation.id,m.MoveColsMutation.id,m.SetWorksheetColWidthMutation.id,m.SetWorksheetRowHeightMutation.id,m.SetSelectionsOperation.id,a.UndoCommandId];function vf(n,o,e,t,i){const r=[],s=[];if(t.copyType===qe.CUT){const{undos:l,redos:c}=pf(n,o,i);r.push(...c),s.push(...l)}else{const{undos:l,redos:c}=Yc(o,e,i);r.push(...c),s.push(...l);const{undos:d,redos:u}=Cf(o,e,i);r.push(...u),s.push(...d);const{undos:h,redos:g}=zc(o,n,e,i);r.push(...g),s.push(...h);const{undos:S,redos:f}=Xc(o,n,e,i,!0);r.push(...f),s.push(...S);const{undos:v,redos:p}=gs(o,e,i);r.push(...p),s.push(...v)}return{undos:s,redos:r}}function pf(n,o,e){let t=[],i=[];const{range:r,subUnitId:s,unitId:l}=n,{range:c,subUnitId:d}=o,u=c?at(c):null,h=r?at(r):null;if(h&&u){const g=e.get(a.IUniverInstanceService),S=e.get(m.SheetInterceptorService),f=g.getUniverSheetInstance(l),v=f==null?void 0:f.getSheetBySheetId(s),p=f==null?void 0:f.getSheetBySheetId(d);if(v&&p){const C=new a.ObjectMatrix,_=new a.ObjectMatrix,w=v.getCellMatrix(),E=p.getCellMatrix();a.Range.foreach(h,(F,Y)=>{C.setValue(F,Y,a.cloneCellData(w.getValue(F,Y))),_.setValue(F,Y,null)});const O=new a.ObjectMatrix;a.Range.foreach(u,(F,Y)=>{O.setValue(F,Y,a.cloneCellData(E.getValue(F,Y)))});const R=new a.ObjectMatrix;a.Range.foreach(h,(F,Y)=>{const j=a.cellToRange(F,Y),Q=a.Rectangle.getRelativeRange(j,h),oe=a.Rectangle.getPositionRange(Q,u);R.setValue(oe.startRow,oe.startColumn,w.getValue(F,Y))});const P={fromRange:h,toRange:u,from:{value:_.getMatrix(),subUnitId:s},to:{value:R.getMatrix(),subUnitId:d},unitId:l},A={fromRange:u,toRange:h,from:{value:C.getMatrix(),subUnitId:s},to:{value:O.getMatrix(),subUnitId:d},unitId:l},k=S.onCommandExecute({id:m.MoveRangeCommand.id,params:{toRange:u,fromRange:h}}),N=v.getMergeData(),V=p.getMergeData(),L=N.filter(F=>a.Rectangle.intersects(F,h)),H=V.filter(F=>a.Rectangle.intersects(F,u)),W=L.map(F=>a.Rectangle.getRelativeRange(F,h)).map(F=>a.Rectangle.getPositionRange(F,u)),B=m.getAddMergeMutationRangeByType(W),U=[{id:m.RemoveWorksheetMergeMutation.id,params:{unitId:l,subUnitId:s,ranges:L}},{id:m.RemoveWorksheetMergeMutation.id,params:{unitId:l,subUnitId:s,ranges:H}},{id:m.AddWorksheetMergeMutation.id,params:{unitId:l,subUnitId:d,ranges:B}}],X=[{id:m.RemoveWorksheetMergeMutation.id,params:{unitId:l,subUnitId:d,ranges:B}},{id:m.AddWorksheetMergeMutation.id,params:{unitId:l,subUnitId:d,ranges:H}},{id:m.AddWorksheetMergeMutation.id,params:{unitId:l,subUnitId:s,ranges:L}}];t=[{id:m.MoveRangeMutation.id,params:P},...k.redos,...U,{id:m.SetSelectionsOperation.id,params:{unitId:l,subUnitId:d,selections:[{range:u}],type:m.SelectionMoveType.MOVE_END}}],i=[{id:m.MoveRangeMutation.id,params:A},...k.undos,...X,{id:m.SetSelectionsOperation.id,params:{unitId:l,subUnitId:s,type:m.SelectionMoveType.MOVE_END,selections:[{range:h}]}}]}}return{undos:i,redos:t}}function zc(n,o,e,t){var f;const{unitId:i,subUnitId:r,range:s}=n,l=(f=t.get(a.IUniverInstanceService).getUniverSheetInstance(i))==null?void 0:f.getSheetBySheetId(r),c=[],d=[],{mapFunc:u}=lt([s]),h=new a.ObjectMatrix;e.forValue((v,p,C)=>{var O,R;const{row:_,col:w}=u(v,p),E={v:C.v,t:C.t};if(!C.p&&C.v&&!o){const P=l==null?void 0:l.getCellStyle(_,w);if(a.isTextFormat((O=P==null?void 0:P.n)==null?void 0:O.pattern))E.t=a.CellValueType.STRING;else{const A=String(C.v),k=a.numfmt.parseValue(A);(k==null?void 0:k.v)!==void 0&&typeof k.v=="number"&&(!k.z&&a.willLoseNumericPrecision(A)?E.t=a.CellValueType.FORCE_STRING:E.v=k.v)}}if((R=C.p)!=null&&R.body&&Dr(C.p.body)){const P={p:a.cloneValue(C.p),v:C.v};h.setValue(_,w,P)}else h.setValue(_,w,E&&a.cloneCellData(E))});const g={unitId:i,subUnitId:r,cellValue:a.cloneCellDataMatrix(h.getMatrix())};c.push({id:m.SetRangeValuesMutation.id,params:g});const S=m.SetRangeValuesUndoMutationFactory(t,g);return d.push({id:m.SetRangeValuesMutation.id,params:S}),{undos:d,redos:c}}function Xc(n,o,e,t,i=!1){var v;const r=[],s=[],{unitId:l,subUnitId:c,range:d}=n,u=(v=t.get(a.IUniverInstanceService).getUniverSheetInstance(l))==null?void 0:v.getSheetBySheetId(c),h=new a.ObjectMatrix,{mapFunc:g}=lt([d]);e.forValue((p,C,_)=>{var A,k;const w={s:Object.assign({},{...a.DEFAULT_STYLES,pd:M.DEFAULT_PADDING_DATA,bg:null,cl:null},_.s)},E=w.s.bd;E&&(Object.keys(E).length>0||(w.s.bd={b:null,l:null,r:null,t:null}));const{row:O,col:R}=g(p,C),P=u==null?void 0:u.getCellStyle(O,R);if(_.v&&!o&&a.isTextFormat((A=P==null?void 0:P.n)==null?void 0:A.pattern))w.s||(w.s={}),w.s.n=P==null?void 0:P.n;else{const N=String(_.v),V=a.numfmt.parseValue(N);V!=null&&V.z&&(w.s||(w.s={}),typeof w.s=="object"&&((k=w.s)!=null&&k.n?w.s.n.pattern=V.z:w.s.n={pattern:V.z}))}h.setValue(O,R,w)});const S={unitId:l,subUnitId:c,cellValue:a.cloneCellDataMatrix(h.getMatrix())};r.push({id:m.SetRangeValuesMutation.id,params:S});const f=m.SetRangeValuesUndoMutationFactory(t,S);return s.push({id:m.SetRangeValuesMutation.id,params:f}),{undos:s,redos:r}}function Yc(n,o,e){const t=[],i=[],r=new a.ObjectMatrix,{unitId:s,subUnitId:l,range:c}=n,{mapFunc:d}=lt([c]);if(o.forEach((u,h)=>{Object.keys(h).forEach(g=>{const S=Number(g),{row:f,col:v}=d(u,S);r.setValue(f,v,{s:null})})}),r.getLength()>0){const u={subUnitId:l,unitId:s,cellValue:a.cloneCellDataMatrix(r.getMatrix())};t.push({id:m.SetRangeValuesMutation.id,params:u});const h=m.SetRangeValuesUndoMutationFactory(e,u);i.push({id:m.SetRangeValuesMutation.id,params:h})}return{undos:i,redos:t}}function Cf(n,o,e){const t=[],i=[],r=new a.ObjectMatrix,{unitId:s,subUnitId:l,range:c}=n,{mapFunc:d}=lt([c]);if(o.forValue((u,h,g)=>{const{row:S,col:f}=d(u,h);r.setValue(S,f,{v:null,p:null})}),r.getLength()>0){const u={subUnitId:l,unitId:s,cellValue:a.cloneCellDataMatrix(r.getMatrix())};t.push({id:m.SetRangeValuesMutation.id,params:u});const h=m.SetRangeValuesUndoMutationFactory(e,u);i.push({id:m.SetRangeValuesMutation.id,params:h})}return{undos:i,redos:t}}function gs(n,o,e){const t=[],i=[],{unitId:r,subUnitId:s,range:l}=n,{startColumn:c,startRow:d,endColumn:u,endRow:h}=at(l),g=[];o.forValue((_,w,E)=>{if(E.rowSpan&&E.rowSpan>1){const O=E.colSpan||1,R={startRow:d+_,endRow:d+_+E.rowSpan-1,startColumn:c+w,endColumn:c+w+O-1};g.push(R)}else if(E.colSpan&&E.colSpan>1){const O=E.rowSpan||1,R={startRow:d+_,endRow:d+_+O-1,startColumn:c+w,endColumn:c+w+E.colSpan-1};g.push(R)}});const f=e.get(a.IUniverInstanceService).getUniverSheetInstance(r),v=f==null?void 0:f.getSheetBySheetId(s);if(f&&v){const w=v.getMergeData().filter(R=>a.Rectangle.intersects({startRow:d,startColumn:c,endRow:h,endColumn:u},R)),E={unitId:r,subUnitId:s,ranges:w};t.push({id:m.RemoveWorksheetMergeMutation.id,params:E});const O=m.RemoveMergeUndoMutationFactory(e,E);i.push({id:m.AddWorksheetMergeMutation.id,params:O})}const p={unitId:r,subUnitId:s,ranges:g};g.length>0&&t.push({id:m.AddWorksheetMergeMutation.id,params:p});const C=m.AddMergeUndoMutationFactory(e,p);return g.length>0&&i.push({id:m.RemoveWorksheetMergeMutation.id,params:C}),{undos:i,redos:t}}function If(n){if(!n.includes("\r")&&a.Tools.isLegalUrl(n)){const t=a.generateRandomId(),i=`${n}`,r={startIndex:0,endIndex:i.length-1,rangeId:t,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:n}};return{dataStream:`${i}\r
12
+ `,"");return e.forEach(r=>{const{st:s,ed:l,ts:c}=r;l-s>=i.length&&(t={...t,...c})}),Object.keys(t).length?t:null}function Mm(n,o=!1){n.dataStream=a.DEFAULT_EMPTY_DOCUMENT_VALUE,n.textRuns!=null&&(n.textRuns.length===1&&!o?(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)}function vl(n){return n&&Object.fromEntries(Object.entries(n).filter(([o,e])=>!(e==null||Array.isArray(e)&&e.length===0||typeof e=="object"&&Object.keys(e).length===0)))}var Pm=Object.getOwnPropertyDescriptor,Om=(n,o,e,t)=>{for(var i=t>1?void 0:t?Pm(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},et=(n,o)=>(e,t)=>o(e,t,n);T.FormulaEditorController=class extends a.RxDisposable{constructor(e,t,i,r,s,l,c,d,u){super();y(this,"_loadedMap",new WeakSet);y(this,"_scheduledCallback",-1);this._univerInstanceService=e,this._renderManagerService=t,this._editorBridgeService=i,this._commandService=r,this._contextService=s,this._formulaEditorManagerService=l,this._undoRedoService=c,this._textSelectionManagerService=d,this._editorService=u,this._initialize()}_initialize(){this._syncEditorSize(),this._listenFxBtnClick(),this._handleContentChange(),this._univerInstanceService.focused$.pipe(D.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)}),this._create(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),this.disposeWithMe(this._editorService.focus$.subscribe(()=>{var t;((t=this._editorService.getFocusEditor())==null?void 0:t.getEditorId())!==a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY?this._contextService.setContextValue(a.FOCUSING_FX_BAR_EDITOR,!1):this._contextService.setContextValue(a.FOCUSING_FX_BAR_EDITOR,!0)}))}_handleContentChange(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===Ce.RichTextEditingMutation.id){const t=e.params,{unitId:i}=t;i===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&this.autoScroll()}}))}_create(e){if(e!==a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;const t=this._renderManagerService.getRenderById(e);if(t==null)return;const{mainComponent:i}=t;i!=null&&(this._loadedMap.has(i)||this._loadedMap.add(i))}_listenFxBtnClick(){this._formulaEditorManagerService.fxBtnClick$.pipe(D.takeUntil(this.dispose$)).subscribe(()=>{var t;if(this._contextService.getContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN)&&!this._contextService.getContextValue(a.EDITOR_ACTIVATED)){this._univerInstanceService.setCurrentUnitForType(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);const i=this._univerInstanceService.getUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);this._editorBridgeService.isVisible().visible===!1&&this._commandService.syncExecuteCommand(Se.id,{visible:!0,eventType:M.DeviceInputEventType.PointerDown,unitId:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY});const s=(t=i==null?void 0:i.getBody())==null?void 0:t.dataStream;if(s==null)return;let l=s.startsWith("=")?s:`=${s}`;l=l.replace(/\r\n$/,"");const c=[{startOffset:l.length,endOffset:l.length}],d={unitId:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,body:{dataStream:l},segmentId:"",textRanges:c};this._commandService.syncExecuteCommand(K.CoverContentCommand.id,d),requestAnimationFrame(()=>{this._textSelectionManagerService.replaceDocRanges([],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY}),this._textSelectionManagerService.replaceDocRanges(c,{unitId:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY}),this._contextService.setContextValue(a.FOCUSING_FX_BAR_EDITOR,!0)})}})}_syncEditorSize(){const e=this._univerInstanceService.unitAdded$.pipe(D.filter(t=>t.getUnitId()===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY));this.disposeWithMe(D.combineLatest([this._formulaEditorManagerService.position$,e]).subscribe(([t])=>{if(!t)return this._clearScheduledCallback();const i=Wi(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,this._renderManagerService),r=this._univerInstanceService.getUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);if(i==null||r==null)return this._clearScheduledCallback();const{width:s,height:l}=t;if(s===0||l===0)return this._clearScheduledCallback();const{engine:c}=i;r.updateDocumentDataPageSize(s),this.autoScroll(),this._scheduledCallback=requestIdleCallback(()=>c.resizeBySize(s,l))}))}_clearScheduledCallback(){this._scheduledCallback!==-1&&cancelIdleCallback(this._scheduledCallback),this._scheduledCallback=-1}autoScroll(){var v,p;const e=this._formulaEditorManagerService.getPosition(),t=(v=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:v.with(Ce.DocSkeletonManagerService).getSkeleton(),i=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),r=this._univerInstanceService.getUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);if(t==null||e==null||i==null||r==null)return;const{marginTop:s=0,marginBottom:l=0}=r.getSnapshot().documentStyle,{scene:c,mainComponent:d}=i;let{actualHeight:u}=t.getActualSize();u+=s+l;const{width:h,height:g}=e,S=c.getViewport(K.VIEWPORT_KEY.VIEW_MAIN);let f=S==null?void 0:S.getScrollBar();c.transformByState({width:h,height:u}),d==null||d.resize(h,u),u>g?f==null?S&&new M.ScrollBar(S,{enableHorizontal:!1,barSize:8}):S==null||S.resetCanvasSizeAndUpdateScroll():(f=null,S==null||S.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0}),(p=S==null?void 0:S.getScrollBar())==null||p.dispose())}},T.FormulaEditorController=Om([et(0,a.IUniverInstanceService),et(1,M.IRenderManagerService),et(2,me),et(3,a.ICommandService),et(4,a.IContextService),et(5,En),et(6,a.IUndoRedoService),et(7,a.Inject(Ce.DocSelectionManagerService)),et(8,K.IEditorService)],T.FormulaEditorController);const pl="embedding_formula_editor",Am=n=>n.includes(pl),kr=(n,o)=>{var h,g,S,f,v;const t=o.findNodePositionByCharIndex(n.startOffset,!0,n.segmentId,-1),i=o.getSkeletonData();let r=n.endOffset;if(n.segmentId){const p=(v=Array.from((g=(h=i==null?void 0:i.skeFooters.get(n.segmentId))==null?void 0:h.values())!=null?g:[])[0])!=null?v:Array.from((f=(S=i==null?void 0:i.skeHeaders.get(n.segmentId))==null?void 0:S.values())!=null?f:[])[0];p&&(r=Math.min(p.ed,r))}const s=o.findNodePositionByCharIndex(r,!0,n.segmentId,-1);if(!s||!t)return;const l={docsLeft:0,docsTop:0,pageMarginLeft:0,pageMarginTop:0},c=new K.NodePositionConvertToCursor(l,o),{borderBoxPointGroup:d}=c.getRangePointData(t,s);return K.getLineBounding(d).map(p=>({top:p.top,bottom:p.bottom,left:p.left,right:p.right}))},Dm=(n,o,e=-1)=>{const t=o.findPositionByGlyph(n,e);if(!t)return;const i={...t,isBack:!0},r={docsLeft:0,docsTop:0,pageMarginLeft:0,pageMarginTop:0},s=new K.NodePositionConvertToCursor(r,o),{borderBoxPointGroup:l}=s.getRangePointData(i,i),d=K.getLineBounding(l)[0];return{top:d.top,bottom:d.bottom,left:d.left,right:d.right}},km=(n,o,e=0,t=0)=>{const i=kr({startOffset:o.startIndex,endOffset:o.endIndex+1},n);if(i)return{rects:i.map(r=>({top:r.top+t,bottom:r.bottom+t,left:r.left+e,right:r.right+e})),range:o}},Nm=(n,o,e=0,t=0)=>{var h,g,S;const i=n.findNodeByCharIndex(o.startIndex),r=i==null?void 0:i.parent,s=r==null?void 0:r.parent,l=s==null?void 0:s.parent,c=l==null?void 0:l.lines.find(f=>f.paragraphStart&&f.paragraphIndex===o.startIndex),d=(S=(g=(h=c==null?void 0:c.divides)==null?void 0:h[0])==null?void 0:g.glyphGroup)==null?void 0:S[0];if(!d||!d)return;const u=Dm(d,n);if(u)return{rect:{top:u.top+t,bottom:u.bottom+t,left:u.left+e,right:u.right+e},segmentId:void 0,segmentPageIndex:-1,paragraph:o}},Cl=(n,o=0,e=0)=>{var l,c,d,u,h,g,S;const t=n.getViewModel().getDataModel(),i=(d=(c=(l=t.getBody())==null?void 0:l.customRanges)==null?void 0:c.filter(f=>f.rangeType===a.CustomRangeType.HYPERLINK))!=null?d:[],r=(g=(h=(u=t.getBody())==null?void 0:u.paragraphs)==null?void 0:h.filter(f=>{var v;return((v=f.bullet)==null?void 0:v.listType.indexOf(a.PresetListType.CHECK_LIST))===0}))!=null?g:[],s=(S=n.getSkeletonData())==null?void 0:S.pages[0].skeDrawings;return{links:i.map(f=>km(n,f,o,e)).filter(Boolean),checkLists:r.map(f=>Nm(n,f,o,e)).filter(Boolean),drawings:s?Array.from(s.keys()).map(f=>({drawingId:f,rect:{top:s.get(f).aTop,bottom:s.get(f).aTop+s.get(f).width,left:s.get(f).aLeft,right:s.get(f).aLeft+s.get(f).height},drawing:s.get(f)})):[]}};function Il(n,o,e){var d,u,h,g,S,f;const t=(h=(u=(d=o.documentSkeleton)==null?void 0:d.getSkeletonData())==null?void 0:u.pages[0].height)!=null?h:0,i=(f=(S=(g=o.documentSkeleton)==null?void 0:g.getSkeletonData())==null?void 0:S.pages[0].width)!=null?f:0,r=o.verticalAlign,s=o.horizontalAlign;let l=0;switch(r){case a.VerticalAlign.UNSPECIFIED:case a.VerticalAlign.BOTTOM:l=n.mergeInfo.endY-n.mergeInfo.startY-t;break;case a.VerticalAlign.MIDDLE:l=(n.mergeInfo.endY-n.mergeInfo.startY-t)/2;break}let c=0;switch(s){case a.HorizontalAlign.RIGHT:c=n.mergeInfo.endX-n.mergeInfo.startX-i;break;case a.HorizontalAlign.CENTER:c=(n.mergeInfo.endX-n.mergeInfo.startX-i)/2;break;case a.HorizontalAlign.UNSPECIFIED:{e&&(c=n.mergeInfo.endX-n.mergeInfo.startX-i);break}}return{paddingLeft:c,paddingTop:l}}const Vm=(n,o,e,t,i,r)=>{var V,L,H;const s=n.get(a.IUniverInstanceService),l=n.get(M.IRenderManagerService),c=s.getUnit(o,a.UniverInstanceType.UNIVER_SHEET);if(!c)return null;const d=c.getSheetBySheetId(e);if(!d)return null;const u=l.getRenderById(c.getUnitId()),h=u==null?void 0:u.with(T.SheetSkeletonManagerService).getSkeletonParam(d.getSheetId()),g=h==null?void 0:h.skeleton;if(!g||!u)return;const S=g.getFont(t,i),f=S==null?void 0:S.documentSkeleton;if(!f)return null;const v=(L=(V=f.getViewModel().getBody())==null?void 0:V.customRanges)==null?void 0:L.find(W=>W.rangeId===r);if(!v)return null;const p=K.DOC_VERTICAL_PADDING,C=g.getCellWithCoordByIndex(t,i);let{actualColumn:_,actualRow:w}=C;g.overflowCache.forValue((W,B,U)=>{U.startRow<=w&&U.endRow>=w&&U.startColumn<=_&&U.endColumn>=_&&(_=B,w=W)});const E=g.getCellWithCoordByIndex(w,_),O=d.getCell(E.actualRow,E.actualColumn),{topOffset:R=0,leftOffset:P=0}=(H=O==null?void 0:O.fontRenderExtension)!=null?H:{},{paddingLeft:A,paddingTop:k}=Il(E,S,!1),N=kr({startOffset:v.startIndex,endOffset:v.endIndex},f);return{rects:N==null?void 0:N.map(W=>({top:W.top+E.mergeInfo.startY+k+R+p,bottom:W.bottom+E.mergeInfo.startY+k+R+p,left:W.left+E.mergeInfo.startX+A+P,right:W.right+E.mergeInfo.startX+A+P})),customRange:v,label:f.getViewModel().getBody().dataStream.slice(v.startIndex,v.endIndex+1)}},Hm=(n,o,e,t,i,r)=>{var P,A,k;const s=n.get(me),l=s.getEditCellState();if(!l||!s.isVisible().visible)return null;const{editorUnitId:d,unitId:u,sheetId:h,row:g,column:S}=l;if(o!==u||e!==h||g!==t||S!==i)return null;const f=n.get(M.IRenderManagerService),v=f.getRenderById(d),p=f.getRenderById(o);if(!v||!p)return null;const C=v.with(Ce.DocSkeletonManagerService).getSkeleton(),_=(P=p.with(T.SheetSkeletonManagerService).getSkeletonParam(h))==null?void 0:P.skeleton;if(!C||!_)return null;const w=(k=(A=C.getViewModel().getBody())==null?void 0:A.customRanges)==null?void 0:k.find(N=>N.rangeId===r);if(!w)return null;const E=4,O=kr({startOffset:w.startIndex,endOffset:w.endIndex},C),R=v.engine.getCanvasElement().getBoundingClientRect();return{rects:O==null?void 0:O.map(N=>({top:N.top+R.top-E,bottom:N.bottom+R.top+E,left:N.left+R.left,right:N.right+R.left})),customRange:w,label:C.getViewModel().getBody().dataStream.slice(w.startIndex,w.endIndex+1)}};var Wm=Object.getOwnPropertyDescriptor,Lm=(n,o,e,t)=>{for(var i=t>1?void 0:t?Wm(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},_l=(n,o)=>(e,t)=>o(e,t,n);function zt(n){const{workbook:o,worksheet:e,...t}=n;return t}T.HoverManagerService=class extends a.Disposable{constructor(e,t){super();y(this,"_currentCell$",new D.BehaviorSubject(null));y(this,"_currentRichText$",new D.BehaviorSubject(null));y(this,"_currentClickedCell$",new D.Subject);y(this,"_currentDbClickedCell$",new D.Subject);y(this,"_currentCellWithEvent$",new D.Subject);y(this,"_currentPointerDownCell$",new D.Subject);y(this,"_currentPointerUpCell$",new D.Subject);y(this,"_currentHoveredRowHeader$",new D.BehaviorSubject(null));y(this,"_currentHoveredColHeader$",new D.BehaviorSubject(null));y(this,"_currentRowHeaderClick$",new D.Subject);y(this,"_currentColHeaderClick$",new D.Subject);y(this,"_currentRowHeaderDbClick$",new D.Subject);y(this,"_currentColHeaderDbClick$",new D.Subject);y(this,"_currentRowHeaderPointerDown$",new D.Subject);y(this,"_currentColHeaderPointerDown$",new D.Subject);y(this,"_currentRowHeaderPointerUp$",new D.Subject);y(this,"_currentColHeaderPointerUp$",new D.Subject);y(this,"currentCell$",this._currentCell$.asObservable().pipe(D.distinctUntilChanged((e,t)=>{var i,r,s,l,c,d,u,h;return((i=e==null?void 0:e.location)==null?void 0:i.unitId)===((r=t==null?void 0:t.location)==null?void 0:r.unitId)&&((s=e==null?void 0:e.location)==null?void 0:s.subUnitId)===((l=t==null?void 0:t.location)==null?void 0:l.subUnitId)&&((c=e==null?void 0:e.location)==null?void 0:c.row)===((d=t==null?void 0:t.location)==null?void 0:d.row)&&((u=e==null?void 0:e.location)==null?void 0:u.col)===((h=t==null?void 0:t.location)==null?void 0:h.col)})));y(this,"currentRichTextNoDistinct$",this._currentRichText$.pipe(D.map(e=>e&&{unitId:e.location.unitId,subUnitId:e.location.subUnitId,row:e.location.row,col:e.location.col,customRange:e.customRange,bullet:e.bullet,rect:e.rect,drawing:e.drawing})));y(this,"currentRichText$",this._currentRichText$.pipe(D.distinctUntilChanged((e,t)=>{var i,r,s,l,c,d,u,h,g,S,f,v,p,C,_,w,E,O;return((i=e==null?void 0:e.location)==null?void 0:i.unitId)===((r=t==null?void 0:t.location)==null?void 0:r.unitId)&&((s=e==null?void 0:e.location)==null?void 0:s.subUnitId)===((l=t==null?void 0:t.location)==null?void 0:l.subUnitId)&&((c=e==null?void 0:e.location)==null?void 0:c.row)===((d=t==null?void 0:t.location)==null?void 0:d.row)&&((u=e==null?void 0:e.location)==null?void 0:u.col)===((h=t==null?void 0:t.location)==null?void 0:h.col)&&((g=e==null?void 0:e.customRange)==null?void 0:g.rangeId)===((S=t==null?void 0:t.customRange)==null?void 0:S.rangeId)&&((f=e==null?void 0:e.bullet)==null?void 0:f.startIndex)===((v=t==null?void 0:t.bullet)==null?void 0:v.startIndex)&&((p=e==null?void 0:e.customRange)==null?void 0:p.startIndex)===((C=t==null?void 0:t.customRange)==null?void 0:C.startIndex)&&((_=e==null?void 0:e.customRange)==null?void 0:_.endIndex)===((w=t==null?void 0:t.customRange)==null?void 0:w.endIndex)&&((E=e==null?void 0:e.drawing)==null?void 0:E.drawingId)===((O=t==null?void 0:t.drawing)==null?void 0:O.drawingId)}),D.map(e=>e&&{unitId:e.location.unitId,subUnitId:e.location.subUnitId,row:e.location.row,col:e.location.col,customRange:e.customRange,bullet:e.bullet,rect:e.rect,drawing:e.drawing})));y(this,"currentCellPosWithEvent$",this._currentCellWithEvent$.pipe(D.distinctUntilChanged((e,t)=>{var i,r,s,l,c,d,u,h;return((i=e==null?void 0:e.location)==null?void 0:i.unitId)===((r=t==null?void 0:t.location)==null?void 0:r.unitId)&&((s=e==null?void 0:e.location)==null?void 0:s.subUnitId)===((l=t==null?void 0:t.location)==null?void 0:l.subUnitId)&&((c=e==null?void 0:e.location)==null?void 0:c.row)===((d=t==null?void 0:t.location)==null?void 0:d.row)&&((u=e==null?void 0:e.location)==null?void 0:u.col)===((h=t==null?void 0:t.location)==null?void 0:h.col)}),D.map(e=>e&&{unitId:e.location.unitId,subUnitId:e.location.subUnitId,row:e.location.row,col:e.location.col,event:e.event})));y(this,"currentPosition$",this._currentCell$.asObservable());y(this,"currentClickedCell$",this._currentClickedCell$.asObservable());y(this,"currentDbClickedCell$",this._currentDbClickedCell$.asObservable());y(this,"currentPointerDownCell$",this._currentPointerDownCell$.asObservable());y(this,"currentPointerUpCell$",this._currentPointerUpCell$.asObservable());y(this,"currentHoveredRowHeader$",this._currentHoveredRowHeader$.asObservable());y(this,"currentHoveredColHeader$",this._currentHoveredColHeader$.asObservable());y(this,"currentRowHeaderClick$",this._currentRowHeaderClick$.asObservable());y(this,"currentColHeaderClick$",this._currentColHeaderClick$.asObservable());y(this,"currentRowHeaderDbClick$",this._currentRowHeaderDbClick$.asObservable());y(this,"currentColHeaderDbClick$",this._currentColHeaderDbClick$.asObservable());y(this,"currentRowHeaderPointerDown$",this._currentRowHeaderPointerDown$.asObservable());y(this,"currentColHeaderPointerDown$",this._currentColHeaderPointerDown$.asObservable());y(this,"currentRowHeaderPointerUp$",this._currentRowHeaderPointerUp$.asObservable());y(this,"currentColHeaderPointerUp$",this._currentColHeaderPointerUp$.asObservable());this._univerInstanceService=e,this._renderManagerService=t,this._initCellDisposableListener()}dispose(){super.dispose(),this._currentCell$.complete(),this._currentClickedCell$.complete(),this._currentPointerDownCell$.complete(),this._currentPointerUpCell$.complete(),this._currentCellWithEvent$.complete(),this._currentRichText$.complete(),this._currentDbClickedCell$.complete(),this._currentHoveredRowHeader$.complete(),this._currentHoveredColHeader$.complete(),this._currentRowHeaderClick$.complete(),this._currentColHeaderClick$.complete(),this._currentRowHeaderDbClick$.complete(),this._currentColHeaderDbClick$.complete(),this._currentRowHeaderPointerDown$.complete(),this._currentColHeaderPointerDown$.complete(),this._currentRowHeaderPointerUp$.complete(),this._currentColHeaderPointerUp$.complete(),this.currentCellPosWithEvent$=D.of(null),this.currentRichText$=D.of(null)}_initCellDisposableListener(){this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(e=>{e||this._currentCell$.next(null)})),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(e=>{var t,i;((t=this._currentCell$.getValue())==null?void 0:t.location.unitId)===e.getUnitId()&&this._currentCell$.next(null),((i=this._currentRichText$.getValue())==null?void 0:i.location.unitId)===e.getUnitId()&&this._currentRichText$.next(null)}))}_getCalcDeps(e){const t=this._univerInstanceService.getUnit(e,a.UniverInstanceType.UNIVER_SHEET);if(!t)return null;const i=t.getActiveSheet();if(!i)return null;const r=this._renderManagerService.getRenderById(t.getUnitId());if(!r)return null;const s=r.with(T.SheetSkeletonManagerService).getSkeletonParam(i.getSheetId());if(!s)return null;const l=r.with(T.SheetScrollManagerService);if(!(!(l!=null&&l.getCurrentScrollState())||!r))return{currentRender:r,workbook:t,worksheet:i,skeletonParam:s}}_calcActiveCell(e,t,i,r,s,l){var P,A,k;const c=Ra(e,t,i,r,s,l),d=r.skeleton;if(!c)return null;const{position:u,overflowLocation:h,location:g}=c,S=d.getFont(h.row,h.col);let f=null,v=null,p=null;const C=d.getCellWithCoordByIndex(h.row,h.col),_=i.getCell(h.row,h.col),{topOffset:w=0,leftOffset:E=0}=(P=_==null?void 0:_.fontRenderExtension)!=null?P:{};if(S!=null&&S.documentSkeleton){const{paddingLeft:N,paddingTop:V}=Il(C,S,(_==null?void 0:_.v)!==null&&(_==null?void 0:_.v)!==void 0?!Number.isNaN(+_.v):!1),L=Cl(S.documentSkeleton,N,V),H=s-u.startX-E,W=l-u.startY-w;f=L.links.find(B=>B.rects.some(U=>U.left<=H&&H<=U.right&&U.top<=W&&W<=U.bottom)),v=L.checkLists.find(B=>B.rect.left<=H&&H<=B.rect.right&&B.rect.top<=W&&W<=B.rect.bottom),p=L.drawings.find(B=>B.rect.left<=H&&H<=B.rect.right&&B.rect.top<=W&&W<=B.rect.bottom)}const O=(k=(A=f==null?void 0:f.rects.pop())!=null?A:v==null?void 0:v.rect)!=null?k:p==null?void 0:p.rect,R=O&&(()=>{const N=O.top+C.mergeInfo.startY+w,V=O.bottom+C.mergeInfo.startY+w,L=O.left+C.mergeInfo.startX+E,H=O.right+C.mergeInfo.startX+E,W=C.mergeInfo.startY+w,B=C.mergeInfo.endY+w,U=C.mergeInfo.startX+E,X=C.mergeInfo.endX+E,F=Math.min(Math.max(N,W),W),Y=Math.min(V,B),j=Math.min(Math.max(L,U),U),Q=Math.min(H,X);return{top:F,bottom:Y,left:j,right:Q}})();return{location:g,position:u,overflowLocation:h,customRange:f==null?void 0:f.range,bullet:v==null?void 0:v.paragraph,drawing:p,rect:R}}_calcActiveRowHeader(e,t,i){const r=this._getCalcDeps(e);if(!r)return;const{currentRender:s,worksheet:l,skeletonParam:c}=r,{scaleY:d}=s.scene.getAncestorScale(),u=s.scene.getViewports().find(S=>S.isHit(new M.Vector2(t,i)));if(!u||u.viewportKey!==M.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP&&u.viewportKey!==M.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM)return;const h={x:u.viewportScrollX,y:u.viewportScrollY},g=c.skeleton.getRowIndexByOffsetY(i,d,h);return{unitId:e,index:g,subUnitId:l.getSheetId()}}_calcActiveColHeader(e,t,i){const r=this._getCalcDeps(e);if(!r)return;const{currentRender:s,worksheet:l,skeletonParam:c}=r,{scaleX:d}=s.scene.getAncestorScale(),u=s.scene.getViewports().find(S=>S.isHit(new M.Vector2(t,i)));if(!u||u.viewportKey!==M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT&&u.viewportKey!==M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT)return;const h={x:u.viewportScrollX,y:u.viewportScrollY},g=c.skeleton.getColumnIndexByOffsetX(t,d,h);return{unitId:e,index:g,subUnitId:l.getSheetId()}}triggerPointerDown(e,t){const i=this._getCalcDeps(e);if(!i)return;const{currentRender:r,workbook:s,worksheet:l,skeletonParam:c}=i,d=this._calcActiveCell(r,s,l,c,t.offsetX,t.offsetY);if(d&&d.location){const{unitId:u,subUnitId:h,row:g,col:S}=zt(d.location);this._currentPointerDownCell$.next({unitId:u,subUnitId:h,row:g,col:S,event:t})}}triggerPointerUp(e,t){const i=this._getCalcDeps(e);if(!i)return;const{currentRender:r,workbook:s,worksheet:l,skeletonParam:c}=i,d=this._calcActiveCell(r,s,l,c,t.offsetX,t.offsetY);if(d){const u=zt(d.location);this._currentPointerUpCell$.next({...u,event:t})}}triggerMouseMove(e,t){const i=this._getCalcDeps(e);if(!i)return;const{currentRender:r,workbook:s,worksheet:l,skeletonParam:c}=i,d=this._calcActiveCell(r,s,l,c,t.offsetX,t.offsetY);this._currentCell$.next(d&&{location:zt(d.location),position:d.position}),this._currentRichText$.next(d&&{...d,location:zt(d.overflowLocation)}),this._currentCellWithEvent$.next(d&&{...d,location:zt(d.location),event:t})}triggerClick(e,t,i){const r=this._getCalcDeps(e);if(!r)return;const{currentRender:s,workbook:l,worksheet:c,skeletonParam:d}=r,u=this._calcActiveCell(s,l,c,d,t,i);u&&this._currentClickedCell$.next({...u,location:zt(u.location)})}triggerDbClick(e,t,i){const r=this._getCalcDeps(e);if(!r)return;const{currentRender:s,workbook:l,worksheet:c,skeletonParam:d}=r,u=this._calcActiveCell(s,l,c,d,t,i);u&&this._currentDbClickedCell$.next({...u,location:zt(u.location)})}triggerScroll(){this._currentCell$.next(null)}triggerRowHeaderClick(e,t,i){const r=this._calcActiveRowHeader(e,t,i);r&&this._currentRowHeaderClick$.next(r)}triggerColHeaderClick(e,t,i){const r=this._calcActiveColHeader(e,t,i);r&&this._currentColHeaderClick$.next(r)}triggerRowHeaderDbClick(e,t,i){const r=this._calcActiveRowHeader(e,t,i);r&&this._currentRowHeaderDbClick$.next(r)}triggerColHeaderDbClick(e,t,i){const r=this._calcActiveColHeader(e,t,i);r&&this._currentColHeaderDbClick$.next(r)}triggerRowHeaderMouseMove(e,t,i){this._currentHoveredRowHeader$.next(this._calcActiveRowHeader(e,t,i))}triggerColHeaderMouseMove(e,t,i){this._currentHoveredColHeader$.next(this._calcActiveColHeader(e,t,i))}triggerRowHeaderPoniterDown(e,t,i){const r=this._calcActiveRowHeader(e,t,i);r&&this._currentRowHeaderPointerDown$.next(r)}triggerColHeaderPoniterDown(e,t,i){const r=this._calcActiveColHeader(e,t,i);r&&this._currentColHeaderPointerDown$.next(r)}triggerRowHeaderPoniterUp(e,t,i){const r=this._calcActiveRowHeader(e,t,i);r&&this._currentRowHeaderPointerUp$.next(r)}triggerColHeaderPoniterUp(e,t,i){const r=this._calcActiveColHeader(e,t,i);r&&this._currentColHeaderPointerUp$.next(r)}},T.HoverManagerService=Lm([_l(0,a.IUniverInstanceService),_l(1,M.IRenderManagerService)],T.HoverManagerService);var xm=Object.getOwnPropertyDescriptor,Um=(n,o,e,t)=>{for(var i=t>1?void 0:t?xm(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},Nr=(n,o)=>(e,t)=>o(e,t,n);T.HoverRenderController=class extends a.Disposable{constructor(e,t,i,r){super();y(this,"_active",!1);this._context=e,this._hoverManagerService=t,this._sheetSkeletonManagerService=i,this._scrollManagerService=r,this._initPointerEvent(),this._initScrollEvent()}get active(){return this._active}_initPointerEvent(){const e=new a.DisposableCollection,t=i=>{if(e.dispose(),!i)return;const{mainComponent:r,unitId:s,components:l}=this._context;if(!r)return;e.add(r.onPointerEnter$.subscribeEvent(u=>{this._active=!0})),e.add(a.fromEventSubject(r.onPointerMove$).subscribe(u=>{this._active=!0,this._hoverManagerService.triggerMouseMove(s,u)})),e.add(r.onPointerDown$.subscribeEvent(u=>{this._hoverManagerService.triggerPointerDown(s,u)})),e.add(r.onPointerUp$.subscribeEvent(u=>{this._hoverManagerService.triggerPointerUp(s,u)})),e.add(r.onClick$.subscribeEvent(u=>{this._hoverManagerService.triggerClick(s,u.offsetX,u.offsetY)})),e.add(r.onDblclick$.subscribeEvent(u=>{this._hoverManagerService.triggerDbClick(s,u.offsetX,u.offsetY)})),e.add(r.onPointerLeave$.subscribeEvent(()=>{this._active=!1}));const c=l.get(he.ROW),d=l.get(he.COLUMN);c&&(e.add(c.onPointerMove$.subscribeEvent(u=>{this._hoverManagerService.triggerRowHeaderMouseMove(s,u.offsetX,u.offsetY)})),e.add(c.onPointerDown$.subscribeEvent(u=>{this._hoverManagerService.triggerRowHeaderPoniterDown(s,u.offsetX,u.offsetY)})),e.add(c.onPointerUp$.subscribeEvent(u=>{this._hoverManagerService.triggerRowHeaderPoniterUp(s,u.offsetX,u.offsetY),this._hoverManagerService.triggerRowHeaderClick(s,u.offsetX,u.offsetY)})),e.add(c.onDblclick$.subscribeEvent(u=>{this._hoverManagerService.triggerRowHeaderDbClick(s,u.offsetX,u.offsetY)}))),d&&(e.add(d.onPointerMove$.subscribeEvent(u=>{this._hoverManagerService.triggerColHeaderMouseMove(s,u.offsetX,u.offsetY)})),e.add(d.onPointerDown$.subscribeEvent(u=>{this._hoverManagerService.triggerColHeaderPoniterDown(s,u.offsetX,u.offsetY)})),e.add(d.onPointerUp$.subscribeEvent(u=>{this._hoverManagerService.triggerColHeaderPoniterUp(s,u.offsetX,u.offsetY),this._hoverManagerService.triggerColHeaderClick(s,u.offsetX,u.offsetY)})),e.add(d.onDblclick$.subscribeEvent(u=>{this._hoverManagerService.triggerColHeaderDbClick(s,u.offsetX,u.offsetY)})))};t(this._sheetSkeletonManagerService.getCurrentParam()),this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i=>{t(i)}))}_initScrollEvent(){this.disposeWithMe(this._scrollManagerService.validViewportScrollInfo$.subscribe(()=>this._hoverManagerService.triggerScroll()))}},T.HoverRenderController=Um([Nr(1,a.Inject(T.HoverManagerService)),Nr(2,a.Inject(T.SheetSkeletonManagerService)),Nr(3,a.Inject(T.SheetScrollManagerService))],T.HoverRenderController);const bl="UI_PLUGIN_SHEETS",Vr=`${bl}_BORDER_PANEL_COMPONENT`,wl=[{label:"borderLine.borderTop",icon:"UpBorderDoubleIcon",value:"top"},{label:"borderLine.borderBottom",icon:"DownBorderDoubleIcon",value:"bottom"},{label:"borderLine.borderLeft",icon:"LeftBorderDoubleIcon",value:"left"},{label:"borderLine.borderRight",icon:"RightBorderDoubleIcon",value:"right"},{label:"borderLine.borderNone",icon:"NoBorderIcon",value:"none"},{label:"borderLine.borderAll",icon:"AllBorderIcon",value:"all"},{label:"borderLine.borderOutside",icon:"OuterBorderDoubleIcon",value:"outside"},{label:"borderLine.borderInside",icon:"InnerBorderDoubleIcon",value:"inside"},{label:"borderLine.borderHorizontal",icon:"HorizontalBorderDoubleIcon",value:"horizontal"},{label:"borderLine.borderVertical",icon:"VerticalBorderDoubleIcon",value:"vertical"},{label:"borderLine.borderTlbr",icon:"BackSlashDoubleIcon",value:"tlbr"},{label:"borderLine.borderTlbcTlmr",icon:"LeftDoubleDiagonalDoubleIcon",value:"tlbc_tlmr"},{label:"borderLine.borderTlbrTlbcTlmr",icon:"LeftTridiagonalDoubleIcon",value:"tlbr_tlbc_tlmr"},{label:"borderLine.borderBlTr",icon:"SlashDoubleIcon",value:"bltr"},{label:"borderLine.borderMltrBctr",icon:"RightDoubleDiagonalDoubleIcon",value:"mltr_bctr"}];function Bm(n){return n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(de.switchMap(o=>o?o.activeSheet$.pipe(de.map(e=>e?{workbook:o,worksheet:e}:null)):D.of(null)))}function be(n,o,e){return Bm(n).pipe(de.switchMap(t=>t?e(t):D.of(o)))}function El(n,o){const e=n.get(a.IUniverInstanceService),t=n.get(m.IExclusiveRangeService),i=n.get(m.SheetsSelectionsService);return e.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(de.switchMap(s=>s?D.combineLatest([i.selectionMoveEnd$,s.activeSheet$]).pipe(de.switchMap(([l,c])=>{if(!c||l.length===0)return D.of(!1);const d=t.getInterestGroupId(l);if(o){const u=d.filter(h=>o.has(h));return D.of(u.length>0)}else return D.of(d.length>0)})):D.of(!1)))}function Xt(n,o,e){return D.combineLatest([o,El(n,e)]).pipe(de.map(([t,i])=>t||i))}function ee(n,o={},e=!1){var g;const i=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(a.UserManagerService),s=n.has(me)?n.get(me):null,l=n.get(a.IContextService),d=((g=s==null?void 0:s.visible$)!=null?g:D.of(null)).pipe(de.startWith(null),de.shareReplay(1)),u=l.subscribeContextValue$(a.FOCUSING_FX_BAR_EDITOR).pipe(de.startWith(!1),de.shareReplay(1));return D.combineLatest([r.currentUser$,i,d,u]).pipe(de.switchMap(([S,f,v,p])=>!f||v!=null&&v.visible&&v.unitId===f.getUnitId()&&!e||p&&!e?D.of(!0):f.activeSheet$.pipe(de.switchMap(C=>{if(!C)return D.of(!0);const _=n.get(m.SheetsSelectionsService),w=n.get(m.RangeProtectionRuleModel),E=n.get(m.WorksheetProtectionRuleModel),R=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_COMMON_DRAWINGS).pipe(de.startWith(!1));return D.combineLatest([_.selectionMoveEnd$,R]).pipe(de.switchMap(([P,A])=>{if(A)return D.of(!0);const k=f.getUnitId(),N=C.getSheetId(),V=n.get(a.IPermissionService),{workbookTypes:L=[m.WorkbookEditablePermission],worksheetTypes:H,rangeTypes:W}=o,B=[];if(L==null||L.forEach(Y=>{B.push(new Y(k).id)}),H==null||H.forEach(Y=>{B.push(new Y(k,N).id)}),E.getRule(k,N))return V.composePermission$(B).pipe(de.map(Y=>Y.some(j=>j.value===!1)));const X=P==null?void 0:P.map(Y=>Y.range),F=w.getSubunitRuleList(k,N).filter(Y=>X==null?void 0:X.some(j=>Y.ranges.some(Q=>a.Rectangle.intersects(j,Q))));return W==null||W.forEach(Y=>{F.forEach(j=>{B.push(new Y(k,N,j.permissionId).id)})}),V.composePermission$(B).pipe(de.map(Y=>Y.some(j=>j.value===!1)))}))}))))}function Mn(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(m.RangeProtectionRuleModel),i=n.get(a.IPermissionService);return D.merge(e.selectionMoveEnd$,i.permissionPointUpdate$.pipe(de.debounceTime(100))).pipe(de.map(()=>{var h;const r=(h=e.getCurrentLastSelection())==null?void 0:h.range;if(!r)return!0;const s=o.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(r,S))).forEach(g=>{u.push(new m.RangeProtectionPermissionEditPoint(c,d,g.permissionId).id)}),i.composePermission(u).some(g=>g.value===!1)}))}function Tl(n,o){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(m.RangeProtectionRuleModel),r=n.get(a.IPermissionService);return D.merge(t.selectionMoveEnd$,r.permissionPointUpdate$.pipe(de.debounceTime(100))).pipe(de.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 i.getSubunitRuleList(d,u).filter(S=>o==="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)}),r.composePermission(h).some(S=>S.value===!1)}))}function yl(n,o){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(m.RangeProtectionRuleModel),r=n.get(a.IPermissionService);return D.merge(t.selectionMoveEnd$,r.permissionPointUpdate$.pipe(de.debounceTime(100))).pipe(de.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 o==="row"?(g.startColumn=0,g.endColumn=c.getColumnCount()-1):(g.startRow=0,g.endRow=c.getRowCount()-1),i.getSubunitRuleList(d,u).filter(f=>f.ranges.some(v=>a.Rectangle.intersects(g,v))).forEach(f=>{h.push(new m.RangeProtectionPermissionEditPoint(d,u,f.permissionId).id)}),r.composePermission(h).some(f=>f.value===!1)}))}function go(n,o){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(m.RangeProtectionRuleModel),r=n.get(a.IPermissionService);return D.merge(t.selectionMoveEnd$,r.permissionPointUpdate$.pipe(de.debounceTime(100))).pipe(de.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 o==="row"?g.endRow=c.getRowCount()-1:g.endColumn=c.getColumnCount()-1,i.getSubunitRuleList(d,u).filter(f=>f.ranges.some(v=>a.Rectangle.intersects(g,v))).forEach(f=>{h.push(new m.RangeProtectionPermissionEditPoint(d,u,f.permissionId).id)}),r.composePermission(h).some(f=>f.value===!1)}))}function Pn(n,o){const t=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),i=n.get(m.WorksheetProtectionRuleModel),r=n.get(m.RangeProtectionRuleModel),s=n.get(a.IPermissionService),l=n.get(a.UserManagerService);return D.combineLatest([l.currentUser$,t]).pipe(de.switchMap(([c,d])=>d?d.activeSheet$.pipe(de.switchMap(u=>{if(!u)return D.of(!0);const h=d.getUnitId(),g=[];return o.forEach(f=>g.push(new f(h).id)),s.composePermission$(g).pipe(de.map(f=>f.every(v=>v.value===!0))).pipe(de.map(f=>{if(!f)return!0;const v=u.getSheetId(),p=i.getRule(h,v),C=r.getSubunitRuleList(h,v);return!!(p||C.length)}))})):D.of(!0)))}function Fm(n){const o=n.get(m.BorderStyleManagerService),e=ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]});return{id:m.SetBorderBasicCommand.id,icon:new D.Observable(t=>{const i="AllBorderIcon",r=n.get(m.BorderStyleManagerService),s=n.get(a.ICommandService).onCommandExecuted(l=>{var g;if(l.id!==m.SetBorderBasicCommand.id)return;const{type:d}=r.getBorderInfo(),u=wl.find(S=>S.value===d),h=(g=u==null?void 0:u.icon)!=null?g:i;t.next(h)});return t.next(i),s.dispose}),tooltip:"toolbar.border.main",type:I.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:Vr,hoverable:!1,selectable:!1},value$:o.borderInfo$}],value$:o.borderInfo$,hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:e}}const So="sheet.menu.clear-selection";function Hr(n){return{id:So,type:I.MenuItemType.SUBITEMS,icon:"ClearFormatDoubleIcon",title:"rightClick.clearSelection",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Wr(n){return{id:m.ClearSelectionContentCommand.id,type:I.MenuItemType.BUTTON,icon:"ClearFormatDoubleIcon",title:"rightClick.clearContent",disabled$:Xt(n,ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellValuePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Lr(n){return{id:m.ClearSelectionFormatCommand.id,type:I.MenuItemType.BUTTON,icon:"ClearFormatDoubleIcon",title:"rightClick.clearFormat",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function fo(n){return{id:m.ClearSelectionAllCommand.id,type:I.MenuItemType.BUTTON,icon:"ClearFormatDoubleIcon",title:"rightClick.clearAll",tooltip:"rightClick.clearAll",disabled$:Xt(n,ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellValuePermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Rl="sheet.menu.delete";function zm(n){return{id:Rl,type:I.MenuItemType.SUBITEMS,title:"rightClick.delete",icon:"ReduceDoubleIcon",hidden$:Xt(n,Mn(n)),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission]})}}function Ml(n){return{id:hn.id,type:I.MenuItemType.BUTTON,icon:"DeleteColumnDoubleIcon",title:"rightClick.deleteSelectedColumn",hidden$:yl(n,"col"),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookDeleteColumnPermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetDeleteColumnPermission]})}}function Pl(n){return{id:un.id,type:I.MenuItemType.BUTTON,icon:"DeleteRowDoubleIcon",title:"rightClick.deleteSelectedRow",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookDeleteRowPermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetDeleteRowPermission]}),hidden$:yl(n,"row")}}function Xm(n){return{id:an.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveLeft",icon:"DeleteCellShiftLeftDoubleIcon",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:go(n,"col")}}function Ym(n){return{id:Tt.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveUp",icon:"DeleteCellShiftUpDoubleIcon",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:go(n,"row")}}function jm(n,o){const e=n.get(m.SheetsSelectionsService),t=n.get(a.IUniverInstanceService),i=n.get(a.ICommandService),r=n.get(a.IContextService);return be(t,o,({worksheet:s})=>new D.Observable(l=>{const c=()=>{var S;let h=o;const g=(S=e.getCurrentLastSelection())==null?void 0:S.primary;if(g!=null){const f=s.getComposedCellStyle(g.startRow,g.startColumn);f.fs&&(h=f.fs)}l.next(h)},d=()=>{var g,S;const h=yt(n);if(h!=null){const f=(S=(g=h.ts)==null?void 0:g.fs)!=null?S:o;l.next(f)}},u=i.onCommandExecuted(h=>{const g=h.id;(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id)&&c(),(g===Ce.SetTextSelectionsOperation.id||g===K.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)&&d()});return c(),u.dispose}))}function Zm(n){const o=a.DEFAULT_STYLES.fs,e=ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0);return{id:ni.id,type:I.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:I.FONT_SIZE_COMPONENT,props:{min:6,max:400,disabled$:e}},selections:I.FONT_SIZE_LIST,disabled$:e,value$:jm(n,o),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Gm(n){const o=ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0);return{id:Ki.id,type:I.MenuItemType.BUTTON,icon:"FontSizeIncreaseIcon",tooltip:"toolbar.fontSizeIncrease",disabled$:o,hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Km(n){const o=ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0);return{id:qi.id,type:I.MenuItemType.BUTTON,icon:"FontSizeReduceIcon",tooltip:"toolbar.fontSizeDecrease",disabled$:o,hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function qm(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService);return{id:m.ToggleGridlinesCommand.id,type:I.MenuItemType.BUTTON,tooltip:"toolbar.toggleGridlines",icon:"HideGridlinesDoubleIcon",activated$:new D.Observable(t=>{const i=()=>{const s=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);return s?s.getActiveSheet().getConfig().showGridlines===a.BooleanNumber.TRUE:!1},r=new a.DisposableCollection;return r.add(o.onCommandExecuted(s=>{(s.id===m.ToggleGridlinesMutation.id||s.id===m.SetWorksheetActiveOperation.id)&&t.next(i())})),r.add(e.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(()=>{t.next(i())})),t.next(i()),()=>r.dispose()}),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission]})}}const je=`${bl}_MENU_ITEM_INPUT_COMPONENT`,Ol=n=>{const{prefix:o,suffix:e,value:t,min:i=Number.MIN_SAFE_INTEGER,max:r=Number.MAX_SAFE_INTEGER,disabled$:s,onChange:l}=n,c=I.useDependency(a.LocaleService),d=I.useDependency(I.IContextMenuService),[u,h]=x.useState(!1),[g,S]=x.useState(),f=p=>{if(!p){S(i.toString());return}const C=p.toString();S(C),l(C)};x.useEffect(()=>{if(!s)return;const p=s.subscribe(C=>{h(C)});return()=>{p.unsubscribe()}},[]),x.useEffect(()=>{d.visible||S(t)},[d.visible]),x.useEffect(()=>{+t<i?S(i.toString()):+t>r?S(r.toString()):S(t)},[t]);function v(){g&&l(g)}return b.jsxs("div",{className:"univer-inline-flex univer-items-center univer-gap-1",children:[c.t(o),b.jsx("div",{className:"univer-w-16",onClick:p=>p.stopPropagation(),children:b.jsx(z.InputNumber,{value:Number(g),size:"mini",precision:0,min:i,max:r,disabled:u,onPressEnter:v,onChange:f})}),c.t(e)]})},Al="sheet.menu.cell-insert";function Qm(n){return{id:Al,type:I.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"InsertDoubleIcon",hidden$:Xt(n,Mn(n)),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookInsertColumnPermission,m.WorkbookInsertRowPermission],worksheetTypes:[m.WorksheetInsertColumnPermission,m.WorksheetInsertRowPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Jm(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),i=1,r=ee(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookInsertRowPermission],worksheetTypes:[m.WorksheetInsertRowPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]});return{id:m.InsertRowBeforeCommand.id,type:I.MenuItemType.BUTTON,icon:"InsertRowAboveDoubleIcon",label:{name:je,props:{prefix:"rightClick.insertRowsAbove",min:1,max:1e3,suffix:"rightClick.insertRowsAboveSuffix",disabled$:r}},value$:be(o,i,()=>new D.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=i;d&&(u=(d==null?void 0:d.endRow)-(d==null?void 0:d.startRow)+1),s.next(u)}const c=t.onCommandExecuted(d=>{if(d.id===m.SetSelectionsOperation.id)return l()});return l(),c.dispose})),disabled$:r,hidden$:Tl(n,"row")}}function $m(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),i=1,r=ee(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookInsertColumnPermission],worksheetTypes:[m.WorksheetInsertColumnPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]});return{id:m.InsertColBeforeCommand.id,type:I.MenuItemType.BUTTON,icon:"LeftInsertColumnDoubleIcon",label:{name:je,props:{prefix:"rightClick.insertColsLeft",min:1,max:1e3,suffix:"rightClick.insertColsLeftSuffix",disabled$:r}},value$:be(o,i,()=>new D.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=i;d&&(u=(d==null?void 0:d.endColumn)-(d==null?void 0:d.startColumn)+1),s.next(u)}const c=t.onCommandExecuted(d=>{if(d.id===m.SetSelectionsOperation.id)return l()});return l(),c.dispose})),disabled$:r,hidden$:Tl(n,"col")}}function eg(n){return{id:dn.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveRight",icon:"InsertCellShiftRightDoubleIcon",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:go(n,"col")}}function tg(n){return{id:At.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveDown",icon:"InsertCellDownDoubleIcon",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:go(n,"row")}}function ng(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),i=1,r=ee(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookInsertRowPermission],worksheetTypes:[m.WorksheetInsertRowPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]});return{id:m.InsertMultiRowsAfterCommand.id,type:I.MenuItemType.BUTTON,icon:"InsertRowBelowDoubleIcon",label:{name:je,props:{prefix:"rightClick.insertRowsAfter",min:1,max:1e3,suffix:"rightClick.insertRowsAfterSuffix",disabled$:r}},value$:be(o,i,()=>new D.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=i;d&&(u=(d==null?void 0:d.endRow)-(d==null?void 0:d.startRow)+1),s.next(u)}const c=t.onCommandExecuted(d=>{if(d.id===m.SetSelectionsOperation.id)return l()});return l(),c.dispose})),disabled$:r,hidden$:Mn(n)}}function ig(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),i=1,r=ee(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookInsertRowPermission],worksheetTypes:[m.WorksheetInsertRowPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]});return{id:m.InsertMultiRowsAboveCommand.id,type:I.MenuItemType.BUTTON,icon:"InsertRowAboveDoubleIcon",label:{name:je,props:{prefix:"rightClick.insertRowsAbove",min:1,max:1e3,suffix:"rightClick.insertRowsAboveSuffix",disabled$:r}},value$:be(o,i,()=>new D.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=i;d&&(u=(d==null?void 0:d.endRow)-(d==null?void 0:d.startRow)+1),s.next(u)}const c=t.onCommandExecuted(d=>{if(d.id===m.SetSelectionsOperation.id)return l()});return l(),c.dispose})),disabled$:r,hidden$:Mn(n)}}function og(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),i=1,r=ee(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookInsertColumnPermission],worksheetTypes:[m.WorksheetInsertColumnPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]});return{id:m.InsertMultiColsLeftCommand.id,type:I.MenuItemType.BUTTON,icon:"LeftInsertColumnDoubleIcon",label:{name:je,props:{prefix:"rightClick.insertColsLeft",min:1,max:1e3,suffix:"rightClick.insertColsLeftSuffix",disabled$:r}},value$:be(o,i,()=>new D.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=i;d&&(u=(d==null?void 0:d.endColumn)-(d==null?void 0:d.startColumn)+1),s.next(u)}const c=t.onCommandExecuted(d=>{if(d.id===m.SetSelectionsOperation.id)return l()});return l(),c.dispose})),disabled$:r,hidden$:Mn(n)}}function rg(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),i=1,r=ee(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookInsertColumnPermission],worksheetTypes:[m.WorksheetInsertColumnPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]});return{id:m.InsertMultiColsRightCommand.id,type:I.MenuItemType.BUTTON,icon:"RightInsertColumnDoubleIcon",label:{name:je,props:{prefix:"rightClick.insertColsRight",min:1,max:1e3,suffix:"rightClick.insertColsRightSuffix",disabled$:r}},value$:be(o,i,()=>new D.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=i;d&&(u=(d==null?void 0:d.endColumn)-(d==null?void 0:d.startColumn)+1),s.next(u)}const c=t.onCommandExecuted(d=>{if(d.id===m.SetSelectionsOperation.id)return l()});return l(),c.dispose})),disabled$:r,hidden$:Mn(n)}}var Dl=(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))(Dl||{});function sg(n){const o=n.get(Be);return{id:gn.id,subId:no.id,type:I.MenuItemType.BUTTON,icon:"BrushIcon",title:"Format Painter",tooltip:"toolbar.formatPainter",activated$:new D.Observable(e=>{let t=!1;const i=o.status$.subscribe(r=>{t=r!==Ae.OFF,e.next(t)});return e.next(t),()=>{i.unsubscribe()}}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetCopyPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0)}}function ag(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(a.IContextService),i=n.get(m.SheetsSelectionsService);return{id:Rt.id,type:I.MenuItemType.BUTTON,icon:"BoldIcon",title:"Set bold",tooltip:"toolbar.bold",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:be(e,!1,({worksheet:r})=>new D.Observable(s=>{var u;const l=o.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const v=(S=i.getCurrentLastSelection())==null?void 0:S.primary;let p=a.FontWeight.NORMAL;if(v!=null){const C=r.getRange(v.startRow,v.startColumn);p=C==null?void 0:C.getFontWeight()}s.next(p===a.FontWeight.BOLD)}if((g===Ce.SetTextSelectionsOperation.id||g===K.SetInlineFormatCommand.id)&&t.getContextValue(a.EDITOR_ACTIVATED)&&t.getContextValue(a.FOCUSING_SHEET)){const v=yt(n);if(v==null)return;const p=(f=v.ts)==null?void 0:f.bl;s.next(p===a.BooleanNumber.TRUE)}}),c=(u=i.getCurrentLastSelection())==null?void 0:u.primary;if(!r){s.next(!1);return}let d=a.FontWeight.NORMAL;if(c!=null){const h=r.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getFontWeight()}return s.next(d===a.FontWeight.BOLD),l.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function lg(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(a.IContextService);return{id:Mt.id,type:I.MenuItemType.BUTTON,icon:"ItalicIcon",title:"Set italic",tooltip:"toolbar.italic",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:be(e,!1,({worksheet:r})=>new D.Observable(s=>{var u;const l=o.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const v=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let p=a.FontItalic.NORMAL;if(v!=null){const C=r.getRange(v.startRow,v.startColumn);p=C==null?void 0:C.getFontStyle()}s.next(p===a.FontItalic.ITALIC)}if((g===Ce.SetTextSelectionsOperation.id||g===K.SetInlineFormatCommand.id)&&i.getContextValue(a.EDITOR_ACTIVATED)&&i.getContextValue(a.FOCUSING_SHEET)){const v=yt(n);if(v==null)return;const p=(f=v.ts)==null?void 0:f.it;s.next(p===a.BooleanNumber.TRUE)}}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d=a.FontItalic.NORMAL;if(c!=null){const h=r.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getFontStyle()}return s.next(d===a.FontItalic.ITALIC),l.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function cg(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(a.IContextService);return{id:Pt.id,type:I.MenuItemType.BUTTON,icon:"UnderlineIcon",title:"Set underline",tooltip:"toolbar.underline",activated$:be(e,!1,({worksheet:r})=>new D.Observable(s=>{var u;const l=o.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const v=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let p;if(v!=null){const C=r.getRange(v.startRow,v.startColumn);p=C==null?void 0:C.getUnderline()}s.next(!!(p&&p.s))}if((g===Ce.SetTextSelectionsOperation.id||g===K.SetInlineFormatCommand.id)&&i.getContextValue(a.EDITOR_ACTIVATED)&&i.getContextValue(a.FOCUSING_SHEET)){const v=yt(n);if(v==null)return;const p=(f=v.ts)==null?void 0:f.ul;s.next((p==null?void 0:p.s)===a.BooleanNumber.TRUE)}}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d;if(c!=null){const h=r.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getUnderline()}return s.next(!!(d&&d.s)),l.dispose})),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function dg(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(a.IContextService);return{id:Ot.id,type:I.MenuItemType.BUTTON,icon:"StrikethroughIcon",title:"Set strike through",tooltip:"toolbar.strikethrough",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:be(e,!1,({worksheet:r})=>new D.Observable(s=>{var u;const l=o.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const v=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let p;if(v!=null){const C=r.getRange(v.startRow,v.startColumn);p=C==null?void 0:C.getStrikeThrough()}s.next(!!(p&&p.s))}if((g===Ce.SetTextSelectionsOperation.id||g===K.SetInlineFormatCommand.id)&&i.getContextValue(a.EDITOR_ACTIVATED)&&i.getContextValue(a.FOCUSING_SHEET)){const v=yt(n);if(v==null)return;const p=(f=v.ts)==null?void 0:f.st;s.next((p==null?void 0:p.s)===a.BooleanNumber.TRUE)}}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d;if(c!=null){const h=r.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getStrikeThrough()}return s.next(!!(d&&d.s)),l.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function ug(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=a.DEFAULT_STYLES.ff;return{id:ln.id,tooltip:"toolbar.font",type:I.MenuItemType.SELECTOR,label:I.FONT_FAMILY_COMPONENT,selections:[{label:{name:I.FONT_FAMILY_ITEM_COMPONENT,hoverable:!1,selectable:!1,props:{id:ln.id}}}],disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),value$:be(e,i,({worksheet:r})=>new D.Observable(s=>{const l=()=>{var h;let d=i;const u=(h=t.getCurrentLastSelection())==null?void 0:h.primary;if(u!=null){const g=r.getCellStyle(u.startRow,u.startColumn),S=r.getDefaultCellStyleInternal(),f=r.getRowStyle(u.startRow),v=r.getColumnStyle(u.startColumn),p=a.composeStyles(S,f,v,g);p.ff&&(d=p.ff)}s.next(d)},c=o.onCommandExecuted(d=>{const u=d.id;(u===m.SetRangeValuesMutation.id||u===m.SetSelectionsOperation.id||u===m.SetWorksheetActiveOperation.id)&&l()});return l(),c.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function hg(n){return{id:Qi.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColorDoubleIcon",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function mg(n){const o=n.get(a.ICommandService),e=n.get(a.ThemeService),t=n.get(m.SheetsSelectionsService);return{id:cn.id,icon:"FontColorDoubleIcon",tooltip:"toolbar.textColor.main",type:I.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:I.COLOR_PICKER_COMPONENT,hoverable:!1,selectable:!1},value$:new D.Observable(i=>{var c;const r=a.DEFAULT_STYLES.cl.rgb,{isAllValuesSame:s,value:l}=t.getCellStylesProperty("cl");s?i.next((c=l==null?void 0:l.rgb)!=null?c:r):i.next(r)})}],value$:new D.Observable(i=>{const r=e.getColorFromTheme("gray.900"),s=o.onCommandExecuted(l=>{if(l.id===cn.id){const c=l.params.value;i.next(c!=null?c:r)}});return i.next(r),s.dispose}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0)}}function gg(n){return{id:m.ResetBackgroundColorCommand.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColorDoubleIcon",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Sg(n){const o=n.get(a.ICommandService),e=n.get(a.ThemeService),t=n.get(m.SheetsSelectionsService);return{id:m.SetBackgroundColorCommand.id,tooltip:"toolbar.fillColor.main",type:I.MenuItemType.BUTTON_SELECTOR,icon:"PaintBucketDoubleIcon",selections:[{label:{name:I.COLOR_PICKER_COMPONENT,hoverable:!1,selectable:!1},value$:new D.Observable(i=>{var c;const r=a.DEFAULT_STYLES.bg.rgb,{isAllValuesSame:s,value:l}=t.getCellStylesProperty("bg");s?i.next((c=l==null?void 0:l.rgb)!=null?c:r):i.next(r)})}],value$:new D.Observable(i=>{const r=e.getColorFromTheme("primary.600"),s=o.onCommandExecuted(l=>{if(l.id===m.SetBackgroundColorCommand.id){const c=l.params.value;i.next(c!=null?c:r)}});return i.next(r),s.dispose}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const kl=[{label:"align.left",icon:"LeftJustifyingIcon",value:a.HorizontalAlign.LEFT},{label:"align.center",icon:"HorizontallyIcon",value:a.HorizontalAlign.CENTER},{label:"align.right",icon:"RightJustifyingIcon",value:a.HorizontalAlign.RIGHT}];function fg(n){var s,l;const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=o.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET),i=t==null?void 0:t.getActiveSheet().getDefaultCellStyleInternal(),r=(s=i==null?void 0:i.ht)!=null?s:a.HorizontalAlign.LEFT;return{id:m.SetHorizontalTextAlignCommand.id,icon:(l=kl.find(c=>c.value===r))==null?void 0:l.icon,tooltip:"toolbar.horizontalAlignMode.main",type:I.MenuItemType.SELECTOR,selections:kl,value$:be(o,r,({worksheet:c})=>new D.Observable(d=>{var S,f;const u=n.get(a.ICommandService).onCommandExecuted(v=>{var w,E;const p=v.id;if(p!==m.SetHorizontalTextAlignCommand.id&&p!==m.SetSelectionsOperation.id&&p!==m.SetWorksheetActiveOperation.id)return;const C=(w=e.getCurrentLastSelection())==null?void 0:w.primary;let _;if(C!=null){const O=c.getRange(C.startRow,C.startColumn),R=t==null?void 0:t.getActiveSheet().getComposedCellStyle(C.startRow,C.startColumn);_=(E=R==null?void 0:R.ht)!=null?E:O==null?void 0:O.getHorizontalAlignment()}d.next(_!=null?_:r)}),h=(S=e.getCurrentLastSelection())==null?void 0:S.primary;let g;if(h!=null){const v=c.getRange(h.startRow,h.startColumn),p=t==null?void 0:t.getActiveSheet().getComposedCellStyle(h.startRow,h.startColumn);g=(f=p==null?void 0:p.ht)!=null?f:v==null?void 0:v.getHorizontalAlignment()}return d.next(g!=null?g:r),u.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const Nl=[{label:"align.top",icon:"AlignTopIcon",value:a.VerticalAlign.TOP},{label:"align.middle",icon:"VerticalCenterIcon",value:a.VerticalAlign.MIDDLE},{label:"align.bottom",icon:"AlignBottomIcon",value:a.VerticalAlign.BOTTOM}];function vg(n){var s,l;const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=o.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET),i=t==null?void 0:t.getActiveSheet().getDefaultCellStyleInternal(),r=(s=i==null?void 0:i.vt)!=null?s:a.VerticalAlign.BOTTOM;return{id:m.SetVerticalTextAlignCommand.id,icon:(l=Nl.find(c=>c.value===r))==null?void 0:l.icon,tooltip:"toolbar.verticalAlignMode.main",type:I.MenuItemType.SELECTOR,selections:Nl,value$:be(o,r,({worksheet:c})=>new D.Observable(d=>{var S,f;const u=n.get(a.ICommandService).onCommandExecuted(v=>{var w,E;const p=v.id;if(p!==m.SetVerticalTextAlignCommand.id&&p!==m.SetSelectionsOperation.id&&p!==m.SetWorksheetActiveOperation.id)return;const C=(w=e.getCurrentLastSelection())==null?void 0:w.primary;let _;if(C!=null){const O=c.getRange(C.startRow,C.startColumn),R=t==null?void 0:t.getActiveSheet().getComposedCellStyle(C.startRow,C.startColumn);_=(E=R==null?void 0:R.vt)!=null?E:O==null?void 0:O.getVerticalAlignment()}d.next(_!=null?_:r)}),h=(S=e.getCurrentLastSelection())==null?void 0:S.primary;let g;if(h!=null){const v=c.getRange(h.startRow,h.startColumn),p=t==null?void 0:t.getActiveSheet().getComposedCellStyle(h.startRow,h.startColumn);g=(f=p==null?void 0:p.vt)!=null?f:v==null?void 0:v.getVerticalAlignment()}return d.next(g!=null?g:r),u.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const Vl=[{label:"textWrap.overflow",icon:"OverflowIcon",value:a.WrapStrategy.OVERFLOW},{label:"textWrap.wrap",icon:"AutowrapIcon",value:a.WrapStrategy.WRAP},{label:"textWrap.clip",icon:"TruncationIcon",value:a.WrapStrategy.CLIP}];function pg(n){var s,l;const o=n.get(m.SheetsSelectionsService),e=n.get(a.IUniverInstanceService),t=e.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET),i=t==null?void 0:t.getActiveSheet().getDefaultCellStyleInternal(),r=(s=i==null?void 0:i.tb)!=null?s:a.WrapStrategy.OVERFLOW;return{id:m.SetTextWrapCommand.id,tooltip:"toolbar.textWrapMode.main",icon:(l=Vl.find(c=>c.value===r))==null?void 0:l.icon,type:I.MenuItemType.SELECTOR,selections:Vl,value$:be(e,r,({worksheet:c})=>new D.Observable(d=>{var S,f;const u=n.get(a.ICommandService).onCommandExecuted(v=>{var w,E;const p=v.id;if(p!==m.SetTextWrapCommand.id&&p!==m.SetSelectionsOperation.id&&p!==m.SetWorksheetActiveOperation.id)return;const C=(w=o.getCurrentLastSelection())==null?void 0:w.primary;let _;if(C!=null){const O=c.getRange(C.startRow,C.startColumn),R=t==null?void 0:t.getActiveSheet().getComposedCellStyle(C.startRow,C.startColumn);_=(E=R==null?void 0:R.tb)!=null?E:O==null?void 0:O.getWrapStrategy()}d.next(_!=null?_:r)}),h=(S=o.getCurrentLastSelection())==null?void 0:S.primary;let g;if(h!=null){const v=c.getRange(h.startRow,h.startColumn),p=t==null?void 0:t.getActiveSheet().getComposedCellStyle(h.startRow,h.startColumn);g=(f=p==null?void 0:p.tb)!=null?f:v==null?void 0:v.getWrapStrategy()}return d.next(g!=null?g:r),u.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const Hl=[{label:"textRotate.none",icon:"NoRotationIcon",value:0},{label:"textRotate.angleUp",icon:"LeftRotationFortyFiveDegreesIcon",value:-45},{label:"textRotate.angleDown",icon:"RightRotationFortyFiveDegreesIcon",value:45},{label:"textRotate.vertical",icon:"VerticalTextIcon",value:"v"},{label:"textRotate.rotationUp",icon:"LeftRotationNinetyDegreesIcon",value:-90},{label:"textRotate.rotationDown",icon:"RightRotationNinetyDegreesIcon",value:90}];function Cg(n){const o=n.get(m.SheetsSelectionsService),e=n.get(a.IUniverInstanceService),t=0;return{id:m.SetTextRotationCommand.id,tooltip:"toolbar.textRotateMode.main",icon:Hl[0].icon,type:I.MenuItemType.SELECTOR,selections:Hl,value$:be(e,t,({worksheet:i})=>new D.Observable(r=>{var d,u;const s=n.get(a.ICommandService).onCommandExecuted(h=>{var v,p;const g=h.id;if(g!==m.SetTextRotationCommand.id&&g!==m.SetSelectionsOperation.id&&g!==m.SetWorksheetActiveOperation.id)return;const S=(v=o.getCurrentLastSelection())==null?void 0:v.primary;let f;if(S!=null){const C=i.getRange(S.startRow,S.startColumn);f=C==null?void 0:C.getTextRotation()}(f==null?void 0:f.v)===a.BooleanNumber.TRUE?r.next("v"):r.next((p=f&&f.a)!=null?p:t)}),l=(d=o.getCurrentLastSelection())==null?void 0:d.primary;let c;if(l!=null){const h=i.getRange(l.startRow,l.startColumn);c=h==null?void 0:h.getTextRotation()}return(c==null?void 0:c.v)===a.BooleanNumber.TRUE?r.next("v"):r.next((u=c&&c.a)!=null?u:t),s.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Ti(n){return new D.Observable(e=>e.next(!n.get(I.IClipboardInterfaceService).supportClipboard))}function On(n){return{id:He.name,commandId:He.id,type:I.MenuItemType.BUTTON,title:"rightClick.copy",icon:"CopyDoubleIcon",disabled$:ee(n,{workbookTypes:[m.WorkbookCopyPermission],worksheetTypes:[m.WorksheetCopyPermission],rangeTypes:[m.RangeProtectionPermissionViewPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function xr(n){return{id:We.name,commandId:We.id,type:I.MenuItemType.BUTTON,title:"rightClick.paste",icon:"PasteSpecialDoubleIcon",disabled$:Ti(n).pipe(D.combineLatestWith(ee(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission,m.WorksheetSetCellValuePermission],workbookTypes:[m.WorkbookEditablePermission]})),D.map(([o,e])=>o||e)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const yi="sheet.menu.paste-special";function Ur(n){return{id:yi,type:I.MenuItemType.SUBITEMS,icon:"PasteSpecialDoubleIcon",title:"rightClick.pasteSpecial",hidden$:Xt(n,I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET))}}function Br(n){return{id:on.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteValue",disabled$:Ti(n).pipe(D.combineLatestWith(ee(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellValuePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),D.map(([o,e])=>o||e)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Fr(n){return{id:rn.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteFormat",disabled$:Ti(n).pipe(D.combineLatestWith(ee(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellStylePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),D.map(([o,e])=>o||e)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function zr(n){return{id:Et.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteColWidth",disabled$:Ti(n).pipe(D.combineLatestWith(ee(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetColumnStylePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),D.map(([o,e])=>o||e))}}function Xr(n){return{id:sn.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteBesidesBorder",disabled$:Ti(n).pipe(D.combineLatestWith(ee(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission,m.WorksheetSetCellValuePermission,m.WorksheetSetRowStylePermission,m.WorksheetSetColumnStylePermission],workbookTypes:[m.WorkbookEditablePermission]})),D.map(([o,e])=>o||e)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Ig(n){return{id:m.SetWorksheetRowIsAutoHeightCommand.id,type:I.MenuItemType.BUTTON,icon:"AutoHeightDoubleIcon",title:"rightClick.fitContent",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function _g(n){return{id:pn.id,type:I.MenuItemType.BUTTON,icon:"AutoWidthDoubleIcon",title:"rightClick.fitContent",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Wl="sheet.menu.sheet-frozen";function bg(n){return{id:Wl,type:I.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Yr="sheet.header-menu.sheet-frozen";function Ll(n){return{id:Yr,type:I.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function jr(n){return{id:Je.id,type:I.MenuItemType.BUTTON,title:"rightClick.freeze",icon:"FreezeToSelectedIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function wg(n){return{id:hi.id,type:I.MenuItemType.BUTTON,title:"rightClick.freezeRow",icon:"FreezeRowIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Eg(n){return{id:mi.id,type:I.MenuItemType.BUTTON,title:"rightClick.freezeCol",icon:"FreezeColumnIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Zr(n){return{id:m.CancelFrozenCommand.id,type:I.MenuItemType.BUTTON,title:"rightClick.cancelFreeze",icon:"CancelFreezeIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Tg(n){return{id:ei.id,type:I.MenuItemType.BUTTON,icon:"HideDoubleIcon",title:"rightClick.hideSelectedRow",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function yg(n){return{id:ti.id,type:I.MenuItemType.BUTTON,icon:"HideDoubleIcon",title:"rightClick.hideSelectedColumn",disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Rg(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),i=[m.SetSelectionsOperation,m.SetRowHiddenMutation,m.SetRowVisibleMutation].map(r=>r.id);return{id:m.SetSelectedRowsVisibleCommand.id,type:I.MenuItemType.BUTTON,icon:"EyeOutlineIcon",title:"rightClick.showHideRow",hidden$:be(o,!0,({worksheet:r})=>new D.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(!r.getRowRawVisible(g))return!0;return!1}))}const c=t.onCommandExecuted(d=>{i.findIndex(u=>u===d.id)!==-1&&s.next(!l())});return s.next(!l()),()=>c.dispose()})),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetRowStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Mg(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),i=[m.SetSelectionsOperation,m.SetColHiddenMutation,m.SetColVisibleMutation].map(r=>r.id);return{id:m.SetSelectedColsVisibleCommand.id,type:I.MenuItemType.BUTTON,icon:"EyeOutlineIcon",title:"rightClick.showHideColumn",hidden$:be(o,!0,({worksheet:r})=>new D.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(!r.getColVisible(g))return!0;return!1})}const c=t.onCommandExecuted(d=>{i.findIndex(u=>u===d.id)!==-1&&s.next(!l())});return s.next(!l()),()=>c.dispose()})),disabled$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetColumnStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Pg(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=2;return{id:m.SetRowHeightCommand.id,type:I.MenuItemType.BUTTON,icon:"AdjustHeightDoubleIcon",label:{name:je,props:{prefix:"rightClick.rowHeight",suffix:"px",min:i,max:1e3}},value$:be(e,i,({worksheet:r})=>new D.Observable(s=>{function l(){var h;const d=(h=t.getCurrentLastSelection())==null?void 0:h.primary,u=d?r.getRowHeight(d.startRow):r.getConfig().defaultRowHeight;s.next(u)}const c=o.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$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetRowStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Og(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=2;return{id:m.SetColWidthCommand.id,type:I.MenuItemType.BUTTON,icon:"AdjustWidthDoubleIcon",label:{name:je,props:{prefix:"rightClick.columnWidth",suffix:"px",min:i,max:1e3}},value$:be(e,i,({worksheet:r})=>new D.Observable(s=>{function l(){var h;const d=(h=t.getCurrentLastSelection())==null?void 0:h.primary,u=d?r.getColumnWidth(d.startColumn):r.getConfig().defaultColumnWidth;s.next(u)}const c=o.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$:ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const gt={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge",handler:async(n,o)=>{const e=n.get(a.ICommandService),t=n.get(a.IUndoRedoService),i=n.get(a.IUniverInstanceService),r=n.get(I.IConfirmService),s=n.get(a.LocaleService),l=o.unitId,c=o.subUnitId,d=o.selections,u=m.getAddMergeMutationRangeByType(d,o.value),h=i.getUniverSheetInstance(l).getSheetBySheetId(c),g=[],S=[],f=ba(h,u);if(f&&!o.defaultMerge&&!await r.confirm({id:"merge.confirm.add-worksheet-merge",title:{title:"merge.confirm.warning"},children:{title:"merge.confirm.title"},cancelText:s.t("merge.confirm.cancel"),confirmText:s.t("merge.confirm.confirm")}))return!1;const v={unitId:l,subUnitId:c,ranges:a.Tools.deepClone(u)},p={unitId:l,subUnitId:c,ranges:a.Tools.deepClone(u)},C=m.RemoveMergeUndoMutationFactory(n,v),_=m.AddMergeUndoMutationFactory(n,p);if(C.ranges.length>0&&g.push({id:m.RemoveWorksheetMergeMutation.id,params:C}),g.push({id:m.AddWorksheetMergeMutation.id,params:p}),S.push({id:m.RemoveWorksheetMergeMutation.id,params:_}),C.ranges.length>0&&S.push({id:m.AddWorksheetMergeMutation.id,params:C}),f){const A=wa(n,l,h,u);g.unshift(...A.redos),S.push(...A.undos)}const w=m.AddMergeRedoSelectionsOperationFactory(n,o,u);w&&g.push(w);const E=m.AddMergeUndoSelectionsOperationFactory(n,o);E&&S.push(E);const R=n.get(m.SheetInterceptorService).onCommandExecute({id:gt.id,params:{unitId:l,subUnitId:c,ranges:u}});return g.push(...R.redos),S.push(...R.undos),a.sequenceExecute(g,e).result?(t.pushUndoRedo({unitID:l,undoMutations:S,redoMutations:g}),!0):!1}},Gr={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-all",handler:async n=>{var u;const o=n.get(a.ICommandService),t=(u=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:u.map(h=>h.range),i=dr(Gi.MergeAll,t);if(!(i!=null&&i.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 o.executeCommand(gt.id,{selections:i,unitId:c,subUnitId:d})}},Kr={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-vertical",handler:async n=>{var u;const o=n.get(a.ICommandService),t=(u=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:u.map(h=>h.range),i=dr(Gi.MergeVertical,t);if(!(i!=null&&i.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 o.executeCommand(gt.id,{value:a.Dimension.COLUMNS,selections:i,unitId:c,subUnitId:d})}},qr={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-horizontal",handler:async n=>{var u;const o=n.get(a.ICommandService),t=(u=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:u.map(h=>h.range),i=dr(Gi.MergeHorizontal,t);if(!(i!=null&&i.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 o.executeCommand(gt.id,{value:a.Dimension.ROWS,selections:i,unitId:c,subUnitId:d})}};function Ag(n){const o=n.get(m.SheetsSelectionsService),e=n.get(m.RangeProtectionRuleModel),t=n.get(a.IUniverInstanceService),i=n.get(m.MergeCellController),r=t.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET);return D.combineLatest([o.selectionMoveEnd$,r.pipe(D.map(s=>{var l;return(l=s==null?void 0:s.getUnitId())!=null?l:""})),r.pipe(D.switchMap(s=>{var l;return(l=s==null?void 0:s.activeSheet$)!=null?l:D.of(null)}))]).pipe(D.map(([s,l,c])=>{if(!c||!s||s.length===0)return!1;const d=c.getSheetId(),u=s.map(S=>S.range);if(i.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(v=>a.Rectangle.intersects(v,S)&&!a.Rectangle.contains(v,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 xl(n,o){return!!Ri(n,o,a.RANGE_TYPE.ROW)}function Ul(n,o){return!!Ri(n,o,a.RANGE_TYPE.COLUMN)}function Ri(n,o,e){return n.find(i=>{const r=i.range,{startRow:s,endRow:l,startColumn:c,endColumn:d,rangeType:u}=r;return u===a.RANGE_TYPE.ALL||u===a.RANGE_TYPE.NORMAL?!1:u===e&&(e===a.RANGE_TYPE.COLUMN&&c<=o&&o<=d||e===a.RANGE_TYPE.ROW&&s<=o&&o<=l)})}function Dg(n){const o=Xt(n,ee(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellValuePermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})),e=Ag(n);return{id:gt.id,icon:"MergeAllIcon",tooltip:"toolbar.mergeCell.main",type:I.MenuItemType.SUBITEMS,hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:o.pipe(D.combineLatestWith(e),D.map(([t,i])=>t||i))}}function kg(n){return{id:Gr.id,type:I.MenuItemType.BUTTON,title:"merge.all",icon:"MergeAllIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Ng(n){return{id:Kr.id,type:I.MenuItemType.BUTTON,title:"merge.vertical",icon:"VerticalIntegrationIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Vg(n){return{id:qr.id,type:I.MenuItemType.BUTTON,title:"merge.horizontal",icon:"HorizontalMergeIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Hg(n){return{id:m.RemoveWorksheetMergeCommand.id,type:I.MenuItemType.BUTTON,title:"merge.cancel",icon:"CancelMergeIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Wg(n){const e=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),t=n.get(a.UserManagerService);return D.combineLatest([e,t.currentUser$]).pipe(D.switchMap(([i,r])=>i?i.activeSheet$.pipe(D.switchMap(s=>{if(!s)return D.of(!0);const l=n.get(m.RangeProtectionRuleModel),c=n.get(m.WorksheetProtectionRuleModel),d=n.get(m.SheetsSelectionsService);return D.merge(d.selectionMoveEnd$,l.ruleChange$,c.ruleChange$).pipe(D.map(()=>{const u=i.getUnitId(),h=s.getSheetId(),g=l.getSubunitRuleList(u,h),S=d.getCurrentSelections(),f=S==null?void 0:S.map(C=>C.range),v=g.map(C=>C.ranges).flat();if(!f)return!1;const p=c.getRule(u,h);return p!=null&&p.permissionId?!0:f==null?void 0:f.some(C=>v.some(_=>a.Rectangle.intersects(C,_)))}))})):D.of(!0)))}function Lg(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.RangeProtectionRuleModel),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),i=n.get(a.UserManagerService);return D.combineLatest([t,i.currentUser$]).pipe(D.switchMap(([r,s])=>r?r.activeSheet$.pipe(D.switchMap(l=>{if(!l)return D.of(!0);const c=n.get(m.RangeProtectionRuleModel),d=n.get(m.WorksheetProtectionRuleModel),u=n.get(a.IPermissionService),h=n.get(m.SheetsSelectionsService);return D.merge(h.selectionMoveEnd$,c.ruleChange$,d.ruleChange$).pipe(D.map(()=>{var A,k;const g=r.getUnitId(),S=l.getSheetId(),f=e.getSubunitRuleList(g,S),v=(A=h.getCurrentSelections())==null?void 0:A.map(N=>N.range);if(f.map(N=>N.ranges).flat(),!(v!=null&&v.length)||v.length>1)return!0;const p=v[0];if((p==null?void 0:p.rangeType)===a.RANGE_TYPE.ALL||(p==null?void 0:p.rangeType)===a.RANGE_TYPE.COLUMN||(p==null?void 0:p.rangeType)===a.RANGE_TYPE.ROW)return!0;const C=d.getRule(g,S);if(C!=null&&C.permissionId)return((k=u.getPermissionPoint(new m.WorksheetManageCollaboratorPermission(g,S).id))==null?void 0:k.value)===!1;if(f.filter(N=>N.ranges.some(V=>a.Rectangle.intersects(V,p))).length!==1)return!0;const{startRow:w,endRow:E,startColumn:O,endColumn:R}=p,P=n.get(m.RangeProtectionCache);for(let N=w;N<=E;N++)for(let V=O;V<=R;V++){const L=P.getCellInfo(g,S,N,V);if(L)return L[m.UnitAction.ManageCollaborator]===!1}return!1}))})):D.of(!0)))}function xg(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),i=n.get(a.UserManagerService);return D.combineLatest([t,i.currentUser$]).pipe(D.switchMap(([r,s])=>r?r.activeSheet$.pipe(D.switchMap(l=>{var f;if(!l)return D.of(!0);const c=r.getUnitId(),d=n.get(m.SheetsSelectionsService),u=n.get(m.RangeProtectionRuleModel),h=n.get(m.WorksheetProtectionRuleModel),g=(f=e.composePermission$([new m.WorkbookEditablePermission(c).id]).pipe(D.map(v=>v.every(p=>p.value))))!=null?f:D.of(!1),S=D.merge(u.ruleChange$,h.ruleChange$).pipe(D.startWith(null));return D.combineLatest([g,S,d.selectionMoveEnd$]).pipe(D.map(([v,p,C])=>{if(!v)return!0;const _=d.getCurrentSelections(),w=_==null?void 0:_.map(E=>E.range);return w!=null&&w.length?w.length>1:!1}))})):D.of(!0)))}function Bl(n){var d;const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),i=n.get(a.UserManagerService),r=n.has(me)?n.get(me):null,l=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_FX_BAR_EDITOR).pipe(D.startWith(!1),D.shareReplay(1)),c=(d=r==null?void 0:r.visible$.pipe(D.startWith(null),D.shareReplay(1)))!=null?d:D.of(null);return D.combineLatest([t,i.currentUser$,c,l]).pipe(D.switchMap(([u,h,g,S])=>!u||g!=null&&g.visible&&g.unitId===u.getUnitId()||S?D.of(!0):u.activeSheet$.pipe(D.switchMap(f=>{var A;if(!f)return D.of(!0);const p=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_COMMON_DRAWINGS).pipe(D.startWith(!1)),C=u.getUnitId(),_=f.getSheetId(),w=n.get(m.RangeProtectionRuleModel),E=n.get(m.WorksheetProtectionRuleModel),O=n.get(m.SheetsSelectionsService),R=(A=e.composePermission$([new m.WorkbookCreateProtectPermission(C).id]).pipe(D.map(k=>k.every(N=>N.value))))!=null?A:D.of(!1),P=D.merge(w.ruleChange$,E.ruleChange$).pipe(D.startWith(null));return D.combineLatest([R,P,O.selectionMoveEnd$,p]).pipe(D.map(([k,N,V,L])=>{if(!k||L)return!0;const H=O.getCurrentSelections(),W=H==null?void 0:H.map(F=>F.range);if(!(W!=null&&W.length))return!0;const B=E.getRule(C,_);if(B!=null&&B.permissionId)return!0;const U=w.getSubunitRuleList(C,_);return W==null?void 0:W.some(F=>U.some(Y=>Y.ranges.some(j=>a.Rectangle.intersects(F,j))))}))}))))}function Ug(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),i=n.get(a.UserManagerService);return D.combineLatest([t,i.currentUser$]).pipe(D.switchMap(([r,s])=>r?r.activeSheet$.pipe(D.switchMap(l=>{var f;if(!l)return D.of(!0);const c=r.getUnitId(),d=l.getSheetId(),u=n.get(m.RangeProtectionRuleModel),h=n.get(m.WorksheetProtectionRuleModel),g=(f=e.composePermission$([new m.WorkbookCreateProtectPermission(c).id]).pipe(D.map(v=>v.every(p=>p.value))))!=null?f:D.of(!1),S=D.merge(u.ruleChange$,h.ruleChange$).pipe(D.startWith(null));return D.combineLatest([g,S]).pipe(D.map(([v,p])=>{var w;if(!v)return!0;const C=h.getRule(c,d);return C!=null&&C.permissionId?!0:((w=u.getSubunitRuleList(c,d))==null?void 0:w.filter(E=>E==null?void 0:E.permissionId)).length>0}))})):D.of(!0)))}function Bg(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),i=n.get(a.UserManagerService);return D.combineLatest([t,i.currentUser$]).pipe(D.switchMap(([r,s])=>r?r.activeSheet$.pipe(D.switchMap(l=>{if(!l)return D.of(!0);const c=r.getUnitId(),d=l.getSheetId(),u=n.get(m.WorksheetProtectionRuleModel);return u.ruleChange$.pipe(D.startWith(null)).pipe(D.map(()=>{var g;return u.getRule(c,d)?((g=e.getPermissionPoint(new m.WorksheetDeleteProtectionPermission(c,d).id))==null?void 0:g.value)===!1:!0}))})):D.of(!0)))}function Fg(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),i=n.get(a.UserManagerService);return D.combineLatest([t,i.currentUser$]).pipe(D.switchMap(([r,s])=>r?r.activeSheet$.pipe(D.switchMap(l=>{var f;if(!l)return D.of(!0);const c=r.getUnitId(),d=n.get(m.RangeProtectionRuleModel),u=n.get(m.WorksheetProtectionRuleModel),h=(f=e.composePermission$([new m.WorkbookCreateProtectPermission(c).id,new m.WorkbookManageCollaboratorPermission(c).id]).pipe(D.map(v=>v.every(p=>p.value))))!=null?f:D.of(!1),g=u.ruleChange$.pipe(D.startWith(null)),S=d.ruleChange$.pipe(D.startWith(null));return D.combineLatest([h,g,S]).pipe(D.map(([v,p,C])=>{if(!v)return!0;const _=l.getSheetId(),w=u.getRule(c,_),E=d.getSubunitRuleList(c,_);return!(w||E.length)}))})):D.of(!0)))}function zg(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),i=n.get(a.UserManagerService);return D.combineLatest([t,i.currentUser$]).pipe(D.switchMap(([r,s])=>r?r.activeSheet$.pipe(D.switchMap(l=>{if(!l)return D.of(!0);const c=r.getUnitId(),d=l.getSheetId(),u=n.get(m.SheetsSelectionsService),h=n.get(m.RangeProtectionRuleModel),g=n.get(m.WorksheetProtectionRuleModel),S=D.merge(h.ruleChange$,g.ruleChange$,u.selectionMoveEnd$).pipe(D.startWith(null));return D.combineLatest([S]).pipe(D.map(([f])=>{var k;const v=n.get(m.SheetsSelectionsService).getCurrentSelections(),p=v==null?void 0:v.map(N=>N.range);if(!(p!=null&&p.length)||p.length>1)return!0;const C=p[0];if((C==null?void 0:C.rangeType)===a.RANGE_TYPE.ALL||(C==null?void 0:C.rangeType)===a.RANGE_TYPE.COLUMN||(C==null?void 0:C.rangeType)===a.RANGE_TYPE.ROW)return!0;const _=g.getRule(c,d);if(_!=null&&_.permissionId)return((k=e.getPermissionPoint(new m.WorksheetDeleteProtectionPermission(c,d).id))==null?void 0:k.value)===!1;if(h.getSubunitRuleList(c,d).filter(N=>N.ranges.some(V=>a.Rectangle.intersects(V,C))).length!==1)return!0;const{startRow:E,endRow:O,startColumn:R,endColumn:P}=C,A=n.get(m.RangeProtectionCache);for(let N=E;N<=O;N++)for(let V=R;V<=P;V++){const L=A.getCellInfo(c,d,N,V);if(L)return L[m.UnitAction.Delete]===!1}return!1}))})):D.of(!0)))}function Fl(n){var d;const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),i=n.get(a.UserManagerService),r=n.has(me)?n.get(me):null,l=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_FX_BAR_EDITOR),c=(d=r==null?void 0:r.visible$)!=null?d:D.of(null);return D.combineLatest([t,i.currentUser$,c,l]).pipe(D.switchMap(([u,h,g,S])=>!u||g!=null&&g.visible&&g.unitId===u.getUnitId()||S?D.of(!0):u.activeSheet$.pipe(D.switchMap(f=>{var C,_;if(!f)return D.of(!0);const v=u.getUnitId();return((_=(C=e.getPermissionPoint$(new m.WorkbookEditablePermission(v).id))==null?void 0:C.pipe(D.map(w=>!!w.value)))!=null?_:D.of(!1)).pipe(D.map(w=>!w))}))))}const vo="sheet.contextMenu.permission";function Xg(n){return{id:ri.id,type:I.MenuItemType.BUTTON,icon:va,tooltip:"permission.toolbarMenu",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:Bl(n)}}function Qr(n){return{id:vo,type:I.MenuItemType.SUBITEMS,title:"rightClick.protectRange",icon:pa,hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Jr(n){return{id:kt.id,type:I.MenuItemType.BUTTON,title:"rightClick.turnOnProtectRange",hidden$:Wg(n),disabled$:Bl(n)}}function $r(n){return{id:Ht.id,type:I.MenuItemType.BUTTON,title:"rightClick.editProtectRange",disabled$:xg(n),hidden$:Lg(n)}}function es(n){return{id:Vt.id,type:I.MenuItemType.BUTTON,title:"rightClick.removeProtectRange",disabled$:zg(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function ts(n){return{id:Nt.id,type:I.MenuItemType.BUTTON,title:"rightClick.viewAllProtectArea",disabled$:Fl(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Yg(n){return{id:si.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.addProtectSheet",disabled$:Ug(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function jg(n){return{id:pi.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.removeProtectSheet",disabled$:Bg(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Zg(n){return{id:Ci.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.changeSheetPermission",disabled$:Fg(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Gg(n){return{id:ai.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.viewAllProtectArea",disabled$:Fl(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Kg(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.ICommandService),t=new D.Observable(r=>{const s=e.onCommandExecuted(l=>{const c=l.id;(c===m.RemoveSheetMutation.id||c===m.InsertSheetMutation.id||c===m.SetWorksheetHideMutation.id)&&po(o,r)});return po(o,r),s.dispose}),i=Pn(n,[m.WorkbookEditablePermission,m.WorkbookDeleteSheetPermission]);return{id:ci.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.delete",disabled$:D.combineLatest([t,i]).pipe(D.map(([r,s])=>r||s)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function qg(n){return{id:m.CopySheetCommand.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.copy",disabled$:Pn(n,[m.WorkbookEditablePermission,m.WorkbookCreateSheetPermission]),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Qg(n){return{id:_i.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.rename",disabled$:Pn(n,[m.WorkbookEditablePermission,m.WorkbookRenameSheetPermission]),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Jg(n){return{id:m.SetTabColorCommand.id,title:"sheetConfig.changeColor",type:I.MenuItemType.SELECTOR,selections:[{label:{name:I.COLOR_PICKER_COMPONENT,hoverable:!1}}],hidden$:Pn(n,[m.WorkbookEditablePermission])}}function $g(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.ICommandService);return{id:m.SetWorksheetHideCommand.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.hide",disabled$:new D.Observable(t=>{const i=e.onCommandExecuted(r=>{const s=r.id;(s===m.RemoveSheetMutation.id||s===m.InsertSheetMutation.id||s===m.SetWorksheetHideMutation.id)&&po(o,t)});return po(o,t),i.dispose}).pipe(D.combineLatestWith(Pn(n,[m.WorkbookEditablePermission,m.WorkbookHideSheetPermission])),D.map(([t,i])=>t||i)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function eS(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.ICommandService);return{id:vi.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.unhide",disabled$:new D.Observable(t=>{function i(){const s=o.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getWorksheets(),l=Array.from(s.values());t.next(l.length===1)}const r=e.onCommandExecuted(s=>{const l=s.id;(l===m.RemoveSheetMutation.id||l===m.InsertSheetMutation.id||l===m.SetWorksheetHideMutation.id)&&i()});return i(),r.dispose}).pipe(D.combineLatestWith(Pn(n,[m.WorkbookEditablePermission,m.WorkbookHideSheetPermission])),D.map(([t,i])=>t||i)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function po(n,o){const e=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getWorksheets(),t=Array.from(e.values()).filter(i=>i.getConfig().hidden===a.BooleanNumber.FALSE);o.next(t.length===1)}const zl={[I.RibbonPosition.START]:{[I.RibbonStartGroup.HISTORY]:{[gn.id]:{order:2,menuItemFactory:sg},[m.ClearSelectionAllCommand.id]:{order:3,menuItemFactory:fo}},[I.RibbonStartGroup.FORMAT]:{[ln.id]:{order:1,menuItemFactory:ug},[ni.id]:{order:2,menuItemFactory:Zm},[Ki.id]:{order:2.1,menuItemFactory:Gm},[qi.id]:{order:2.2,menuItemFactory:Km},[Rt.id]:{order:5,menuItemFactory:ag},[Mt.id]:{order:6,menuItemFactory:lg},[Pt.id]:{order:7,menuItemFactory:cg},[Ot.id]:{order:8,menuItemFactory:dg},[cn.id]:{order:9,menuItemFactory:mg,[m.ResetTextColorCommand.id]:{order:0,menuItemFactory:hg}},[m.SetBackgroundColorCommand.id]:{order:10,menuItemFactory:Sg,[m.ResetBackgroundColorCommand.id]:{order:0,menuItemFactory:gg}},[m.SetBorderBasicCommand.id]:{order:11,menuItemFactory:Fm}},[I.RibbonStartGroup.LAYOUT]:{[m.SetHorizontalTextAlignCommand.id]:{order:0,menuItemFactory:fg},[m.SetVerticalTextAlignCommand.id]:{order:3,menuItemFactory:vg},[m.SetTextWrapCommand.id]:{order:6,menuItemFactory:pg},[m.SetTextRotationCommand.id]:{order:7,menuItemFactory:Cg},[m.AddWorksheetMergeCommand.id]:{order:8,menuItemFactory:Dg,[m.AddWorksheetMergeAllCommand.id]:{order:0,menuItemFactory:kg},[m.AddWorksheetMergeVerticalCommand.id]:{order:1,menuItemFactory:Ng},[m.AddWorksheetMergeHorizontalCommand.id]:{order:2,menuItemFactory:Vg},[m.RemoveWorksheetMergeCommand.id]:{order:3,menuItemFactory:Hg}}},[I.RibbonStartGroup.OTHERS]:{[ri.id]:{order:0,menuItemFactory:Xg}}},[I.ContextMenuPosition.MAIN_AREA]:{[I.ContextMenuGroup.FORMAT]:{[He.name]:{order:0,menuItemFactory:On},[We.name]:{order:2,menuItemFactory:xr},[yi]:{order:3,menuItemFactory:Ur,[on.id]:{order:0,menuItemFactory:Br},[rn.id]:{order:1,menuItemFactory:Fr},[Et.id]:{order:2,menuItemFactory:zr},[sn.id]:{order:3,menuItemFactory:Xr}},[So]:{order:4,menuItemFactory:Hr,[m.ClearSelectionContentCommand.id]:{order:0,menuItemFactory:Wr},[m.ClearSelectionFormatCommand.id]:{order:1,menuItemFactory:Lr},[m.ClearSelectionAllCommand.id]:{order:2,menuItemFactory:fo}}},[I.ContextMenuGroup.LAYOUT]:{order:1,[Al]:{order:0,menuItemFactory:Qm,[m.InsertRowBeforeCommand.id]:{order:0,menuItemFactory:Jm},[m.InsertColBeforeCommand.id]:{order:1,menuItemFactory:$m},[dn.id]:{order:2,menuItemFactory:eg},[At.id]:{order:3,menuItemFactory:tg}},[Rl]:{order:0,menuItemFactory:zm,[hn.id]:{order:0,menuItemFactory:Ml},[un.id]:{order:1,menuItemFactory:Pl},[an.id]:{order:2,menuItemFactory:Xm},[Tt.id]:{order:3,menuItemFactory:Ym}},[Wl]:{order:2,menuItemFactory:bg,[Je.id]:{order:0,menuItemFactory:jr},[hi.id]:{order:1,menuItemFactory:wg},[mi.id]:{order:2,menuItemFactory:Eg},[m.CancelFrozenCommand.id]:{order:3,menuItemFactory:Zr}},[vo]:{order:3,menuItemFactory:Qr,[kt.id]:{order:0,menuItemFactory:Jr},[Ht.id]:{order:1,menuItemFactory:$r},[Vt.id]:{order:2,menuItemFactory:es},[Nt.id]:{order:3,menuItemFactory:ts}}},[I.ContextMenuGroup.DATA]:{order:2},[I.ContextMenuGroup.OTHERS]:{order:3}},[I.ContextMenuPosition.COL_HEADER]:{[I.ContextMenuGroup.FORMAT]:{[He.name]:{order:0,menuItemFactory:On},[We.name]:{order:2,menuItemFactory:xr},[yi]:{order:3,menuItemFactory:Ur,[on.id]:{order:0,menuItemFactory:Br},[rn.id]:{order:1,menuItemFactory:Fr},[Et.id]:{order:2,menuItemFactory:zr},[sn.id]:{order:3,menuItemFactory:Xr}},[So]:{order:4,menuItemFactory:Hr,[m.ClearSelectionContentCommand.id]:{order:0,menuItemFactory:Wr},[m.ClearSelectionFormatCommand.id]:{order:1,menuItemFactory:Lr},[m.ClearSelectionAllCommand.id]:{order:2,menuItemFactory:fo}}},[I.ContextMenuGroup.LAYOUT]:{order:1,[m.InsertMultiColsLeftCommand.id]:{order:0,menuItemFactory:og},[m.InsertMultiColsRightCommand.id]:{order:0,menuItemFactory:rg},[ti.id]:{order:1,menuItemFactory:yg},[m.SetSelectedColsVisibleCommand.id]:{order:2,menuItemFactory:Mg},[hn.id]:{order:2,menuItemFactory:Ml},[m.SetColWidthCommand.id]:{order:3,menuItemFactory:Og},[pn.id]:{order:4,menuItemFactory:_g},[Yr]:{order:5,menuItemFactory:Ll,[Je.id]:{order:0,menuItemFactory:jr},[m.CancelFrozenCommand.id]:{order:3,menuItemFactory:Zr}},[vo]:{order:6,menuItemFactory:Qr,[kt.id]:{order:0,menuItemFactory:Jr},[Ht.id]:{order:1,menuItemFactory:$r},[Vt.id]:{order:2,menuItemFactory:es},[Nt.id]:{order:3,menuItemFactory:ts}}},[I.ContextMenuGroup.DATA]:{order:2},[I.ContextMenuGroup.OTHERS]:{order:3}},[I.ContextMenuPosition.ROW_HEADER]:{[I.ContextMenuGroup.FORMAT]:{[He.name]:{order:0,menuItemFactory:On},[We.name]:{order:2,menuItemFactory:xr},[yi]:{order:3,menuItemFactory:Ur,[on.id]:{order:0,menuItemFactory:Br},[rn.id]:{order:1,menuItemFactory:Fr},[Et.id]:{order:2,menuItemFactory:zr},[sn.id]:{order:3,menuItemFactory:Xr}},[So]:{order:4,menuItemFactory:Hr,[m.ClearSelectionContentCommand.id]:{order:0,menuItemFactory:Wr},[m.ClearSelectionFormatCommand.id]:{order:1,menuItemFactory:Lr},[m.ClearSelectionAllCommand.id]:{order:2,menuItemFactory:fo}}},[I.ContextMenuGroup.LAYOUT]:{order:1,[m.InsertMultiRowsAboveCommand.id]:{order:0,menuItemFactory:ig},[m.InsertMultiRowsAfterCommand.id]:{order:1,menuItemFactory:ng},[un.id]:{order:1,menuItemFactory:Pl},[ei.id]:{order:2,menuItemFactory:Tg},[m.SetSelectedRowsVisibleCommand.id]:{order:2,menuItemFactory:Rg},[m.SetRowHeightCommand.id]:{order:3,menuItemFactory:Pg},[m.SetWorksheetRowIsAutoHeightCommand.id]:{order:4,menuItemFactory:Ig},[Yr]:{order:5,menuItemFactory:Ll,[Je.id]:{order:0,menuItemFactory:jr},[m.CancelFrozenCommand.id]:{order:3,menuItemFactory:Zr}},[vo]:{order:6,menuItemFactory:Qr,[kt.id]:{order:0,menuItemFactory:Jr},[Ht.id]:{order:1,menuItemFactory:$r},[Vt.id]:{order:2,menuItemFactory:es},[Nt.id]:{order:3,menuItemFactory:ts}}},[I.ContextMenuGroup.DATA]:{order:2},[I.ContextMenuGroup.OTHERS]:{order:3}},[I.ContextMenuPosition.FOOTER_TABS]:{[I.ContextMenuGroup.OTHERS]:{order:0,[ci.id]:{order:0,menuItemFactory:Kg},[m.CopySheetCommand.id]:{order:1,menuItemFactory:qg},[_i.id]:{order:2,menuItemFactory:Qg},[m.SetTabColorCommand.id]:{order:3,menuItemFactory:Jg},[m.SetWorksheetHideCommand.id]:{order:4,menuItemFactory:$g},[vi.id]:{order:6,menuItemFactory:eS},[si.id]:{order:7,menuItemFactory:Yg},[pi.id]:{order:8,menuItemFactory:jg},[Ci.id]:{order:9,menuItemFactory:Zg},[ai.id]:{order:10,menuItemFactory:Gg}}},[I.ContextMenuPosition.FOOTER_MENU]:{[I.ContextMenuGroup.OTHERS]:{[m.ToggleGridlinesCommand.id]:{order:1,menuItemFactory:qm}}}},ns="UNIVER_SHEET_PERMISSION_ALERT_DIALOG_ID",Xl="UNIVER_SHEET_PERMISSION_ALERT_DIALOG";var tS=Object.getOwnPropertyDescriptor,nS=(n,o,e,t)=>{for(var i=t>1?void 0:t?tS(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},tt=(n,o)=>(e,t)=>o(e,t,n);T.SheetPermissionCheckUIController=class extends a.Disposable{constructor(e,t,i,r,s,l,c,d,u){super();y(this,"disposableCollection",new a.DisposableCollection);this._commandService=e,this._univerInstanceService=t,this._permissionService=i,this._dialogService=r,this._rangeProtectionRuleModel=s,this._autoFillService=l,this._localeService=c,this._contextService=d,this._sheetPermissionCheckController=u,this._initialize(),this._initUIEvent()}_initUIEvent(){this.disposeWithMe(this._sheetPermissionCheckController.triggerPermissionUIEvent$.subscribe(e=>{this._haveNotPermissionHandle(e)}))}_haveNotPermissionHandle(e){const t={id:ns,title:{title:"permission.dialog.alert"},children:{label:Xl,errorMsg:e},width:320,destroyOnClose:!0,showOk:!0,onClose:()=>{this._dialogService.close(ns)},onOk:()=>{this._dialogService.close(ns)},className:"sheet-permission-user-dialog"};this._permissionService.getShowComponents()&&this._dialogService.open(t)}_getPermissionCheck(e,t){var s,l;let i=!0,r="";switch(e){case K.InsertCommand.id:case K.IMEInputCommand.id:if(this._contextService.getContextValue(a.FOCUSING_EDITOR_STANDALONE)===!0)break;i=this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellValuePermission,m.WorksheetEditPermission]}),r=this._localeService.t("permission.dialog.editErr");break;case Se.id:if(t.visible===!1)break;i=this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellValuePermission,m.WorksheetEditPermission]}),r=this._localeService.t("permission.dialog.editErr");break;case Et.id:i=this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission]}),r=this._localeService.t("permission.dialog.pasteErr");break;case Zi.id:i=this._permissionCheckByPaste(t),r=this._localeService.t("permission.dialog.pasteErr");break;case ui.id:i=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellValuePermission,m.WorksheetSetCellStylePermission]}),r=this._localeService.t("permission.dialog.commonErr");break;case m.SetBackgroundColorCommand.id:case Rt.id:case Mt.id:case Pt.id:case Ot.id:i=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellStylePermission,m.WorksheetEditPermission]}),r=this._localeService.t("permission.dialog.setStyleErr");break;case He.id:i=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookCopyPermission],rangeTypes:[m.RangeProtectionPermissionViewPoint],worksheetTypes:[m.WorksheetCopyPermission]}),r=this._localeService.t("permission.dialog.copyErr"),(s=this._permissionService.getPermissionPoint(new m.WorkbookCopyPermission(this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).id))!=null&&s.value||(r=this._localeService.t("permission.dialog.workbookCopyErr"));break;case ji.id:i=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookCopyPermission,m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionViewPoint,m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetCopyPermission,m.WorksheetEditPermission]}),r=this._localeService.t("permission.dialog.copyErr"),(l=this._permissionService.getPermissionPoint(new m.WorkbookCopyPermission(this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).id))!=null&&l.value||(r=this._localeService.t("permission.dialog.workbookCopyErr"));break;case dt.id:i=this._permissionCheckByAutoFillCommand(t),r=this._localeService.t("permission.dialog.autoFillErr");break}i||this._sheetPermissionCheckController.blockExecuteWithoutPermission(r)}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{this._getPermissionCheck(e.id,e==null?void 0:e.params)}))}_permissionCheckByPaste(e){return e.value===ge.SPECIAL_PASTE_VALUE||e.value===ge.SPECIAL_PASTE_FORMULA?this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellStylePermission,m.WorksheetEditPermission]}):e.value===ge.SPECIAL_PASTE_FORMAT?this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellStylePermission,m.WorksheetEditPermission]}):this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellValuePermission,m.WorksheetSetCellStylePermission,m.WorksheetEditPermission]})}_permissionCheckByAutoFillCommand(e){if(!e)return!1;const{targetRange:t}=e,i=m.getSheetCommandTarget(this._univerInstanceService);if(!i)return!1;const{worksheet:r,unitId:s,subUnitId:l}=i;return!this._rangeProtectionRuleModel.getSubunitRuleList(s,l).reduce((u,h)=>[...u,...h.ranges],[]).filter(u=>a.Rectangle.intersects(u,t)).some(u=>{var h,g;for(let S=u.startRow;S<=u.endRow;S++)for(let f=u.startColumn;f<=u.endColumn;f++){const v=(g=(h=r.getCell(S,f))==null?void 0:h.selectionProtection)==null?void 0:g[0];if((v==null?void 0:v[$.Edit])===!1)return!0}return!1})}},T.SheetPermissionCheckUIController=nS([tt(0,a.ICommandService),tt(1,a.IUniverInstanceService),tt(2,a.IPermissionService),tt(3,I.IDialogService),tt(4,a.Inject(m.RangeProtectionRuleModel)),tt(5,ct),tt(6,a.Inject(a.LocaleService)),tt(7,a.IContextService),tt(8,a.Inject(m.SheetPermissionCheckController))],T.SheetPermissionCheckUIController);var iS=Object.getOwnPropertyDescriptor,oS=(n,o,e,t)=>{for(var i=t>1?void 0:t?iS(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},Yt=(n,o)=>(e,t)=>o(e,t,n);const rS="__SpreadsheetFreezeRowMainName__",sS="__SpreadsheetFreezeRowHeaderName__",aS="__SpreadsheetFreezeColumnMainName__",lS="__SpreadsheetFreezeColumnHeaderName__",is=2,cS=.01,Mi=a.createInterceptorKey("freezePermissionCheck");T.HeaderFreezeRenderController=class extends a.Disposable{constructor(e,t,i,r,s,l,c,d){super();y(this,"_rowFreezeHeaderRect");y(this,"_rowFreezeMainRect");y(this,"_columnFreezeHeaderRect");y(this,"_columnFreezeMainRect");y(this,"_freezeDownSubs");y(this,"_freezePointerEnterSubs");y(this,"_freezePointerLeaveSubs");y(this,"_scenePointerMoveSub");y(this,"_scenePointerUpSub");y(this,"_changeToRow",-1);y(this,"_changeToColumn",-1);y(this,"_changeToOffsetX",0);y(this,"_changeToOffsetY",0);y(this,"_activeViewport",null);y(this,"_freezeNormalHeaderColor","");y(this,"_freezeNormalMainColor","");y(this,"_freezeActiveColor","");y(this,"_freezeHoverColor","");y(this,"_lastFreeze");y(this,"interceptor",new a.InterceptorManager({FREEZE_PERMISSION_CHECK:Mi}));this._context=e,this._sheetSkeletonManagerService=t,this._commandService=i,this._selectionManagerService=r,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 A;const i=t!=null?t:this._getFreeze();if(i==null)return null;const r=(A=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:A.skeleton,{startRow:s,startColumn:l}=i,c=this._getPositionByIndex(s,l);if(c==null||r==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:v}=c,{rowTotalHeight:p,columnTotalWidth:C,rowHeaderWidthAndMarginLeft:_,columnHeaderHeightAndMarginTop:w}=r,E=h>C+_?h:C+w,O=g>p+w?g:p+w;this._changeToRow=s,this._changeToColumn=l,this._changeToOffsetX=f,this._changeToOffsetY=v;const R=Math.max(S.scaleX,S.scaleY);let P=is/Math.max(1,R);if(e===0){(s===-1||s===0)&&(P=P*2);const k=P;this._rowFreezeHeaderRect=new M.Rect(sS,{fill:this._freezeNormalHeaderColor,width:_,height:P,left:0,top:v-k,zIndex:3});let N=this._freezeNormalHeaderColor;(s===-1||s===0)&&(N=this._freezeNormalMainColor),this._rowFreezeMainRect=new M.Rect(rS,{fill:N,width:E*2/R,height:P,left:_,top:v-k,zIndex:3}),S.addObjects([this._rowFreezeHeaderRect,this._rowFreezeMainRect],rt)}else{(l===-1||l===0)&&(P=P*2);const k=P;this._columnFreezeHeaderRect=new M.Rect(lS,{fill:this._freezeNormalHeaderColor,width:P,height:w,left:f-k,top:0,zIndex:3});let N=this._freezeNormalHeaderColor;(l===-1||l===0)&&(N=this._freezeNormalMainColor),this._columnFreezeMainRect=new M.Rect(aS,{fill:N,width:P,height:O*2/R,left:f-k,top:w,zIndex:3}),S.addObjects([this._columnFreezeHeaderRect,this._columnFreezeMainRect],rt)}this._eventBinding(e)}_eventBinding(e=0){let t=this._rowFreezeHeaderRect,i=this._rowFreezeMainRect;e===1&&(t=this._columnFreezeHeaderRect,i=this._columnFreezeMainRect);const r=this._getSheetObject();if(r==null)return;const{scene:s}=r;if(this._freezePointerEnterSubs=new D.Subscription,this._freezePointerLeaveSubs=new D.Subscription,this._freezeDownSubs=new D.Subscription,i){const d=i.onPointerEnter$.subscribeEvent(()=>{if(!this.interceptor.fetchThroughInterceptors(Mi)(!0,null))return!1;t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),s.setCursor(M.CURSOR_TYPE.GRAB)});this._freezePointerEnterSubs.add(d);const u=i.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(Mi)(!0,null))return!1;t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),s.setCursor(M.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,i,e)});l&&this._freezeDownSubs.add(l);const c=i==null?void 0:i.onPointerDown$.subscribeEvent(d=>{this._freezeDown(d,t,i,e)});c&&this._freezeDownSubs.add(c)}_getCurrentLastVisible(){var C,_,w,E,O,R,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 i=e.scene,r=Math.max(i.scaleX,i.scaleY),s=this._scrollManagerService.getCurrentScrollState(),l=(e.engine.height-t.columnHeaderHeight)/r,c=(e.engine.width-t.rowHeaderWidth)/r,d=(_=s==null?void 0:s.sheetViewStartRow)!=null?_:0,u=d===0?-((w=s==null?void 0:s.offsetY)!=null?w:0):t.rowHeightAccumulation[d-1]-((E=s==null?void 0:s.offsetY)!=null?E:0);let h=0,g=!1;for(let A=d,k=t.rowHeightAccumulation.length;A<k;A++)if(t.rowHeightAccumulation[A]-u>l){h=A,g=!0;break}g||(h=t.rowHeightAccumulation.length-1);const S=(O=s==null?void 0:s.sheetViewStartColumn)!=null?O:0,f=S===0?-((R=s==null?void 0:s.offsetX)!=null?R:0):t.columnWidthAccumulation[S-1]-((P=s==null?void 0:s.offsetX)!=null?P:0);let v=0,p=!1;for(let A=S,k=t.columnWidthAccumulation.length;A<k;A++)if(t.columnWidthAccumulation[A]-f>c){v=A,p=!0;break}return p||(v=t.columnWidthAccumulation.length-1),{lastRow:h,lastColumn:v}}_getActiveViewport(e){var i;const t=(i=this._getSheetObject())==null?void 0:i.scene.getViewports();return t&&t.find(r=>r.isHit(new M.Vector2(e.offsetX,e.offsetY)))||null}_freezeDown(e,t,i,r=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(Mi)(!0,null))return!1;const{scene:d}=l;d.setCursor(M.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(v=>{var P,A,k,N;const p=this._getActiveViewport(v),{startX:C,startY:_,row:w,column:E}=Xe(v.offsetX,v.offsetY,d,s,p||void 0,!0);if(!this.interceptor.fetchThroughInterceptors(Mi)(!0,null))return!1;d.setCursor(M.CURSOR_TYPE.GRABBING);const R=is/Math.max(d.scaleX,d.scaleY);r===0?((P=t.transformByState({top:Math.min(_,h)-R/2}))==null||P.setProps({fill:this._freezeActiveColor}),(A=i.transformByState({top:Math.min(_,h)-R/2}))==null||A.setProps({fill:this._freezeNormalHeaderColor}),this._changeToRow=u===void 0?w:Math.min(w,u.lastRow),this._changeToOffsetY=Math.min(_,h),this._activeViewport=p):((k=t.transformByState({left:Math.min(C,g)-R/2}))==null||k.setProps({fill:this._freezeActiveColor}),(N=i.transformByState({left:Math.min(C,g)-R/2}))==null||N.setProps({fill:this._freezeNormalHeaderColor}),this._changeToColumn=u===void 0?E:Math.min(E,u.lastColumn),this._changeToOffsetX=C,this._activeViewport=p)}),this._scenePointerUpSub=d.onPointerUp$.subscribeEvent(()=>{var V,L;d.resetCursor(),d.enableObjectsEvent(),this._clearObserverEvent();const{rowHeaderWidthAndMarginLeft:v,columnHeaderHeightAndMarginTop:p}=s;r===0&&(this._changeToRow===0||this._changeToRow===-1)||r===1&&(this._changeToColumn===0||this._changeToColumn===-1)?(t.setProps({fill:this._freezeNormalHeaderColor}),i.setProps({fill:this._freezeNormalMainColor})):(t==null||t.setProps({fill:this._freezeNormalHeaderColor}),i==null||i.setProps({fill:this._freezeNormalHeaderColor}));const C=is/Math.max(d.scaleX,d.scaleY);r===0?(this._changeToRow===0||this._changeToRow===-1)&&(t.transformByState({top:p-C}),i.transformByState({top:p-C})):(this._changeToColumn===0||this._changeToColumn===-1)&&(t.transformByState({left:v-C}),i.transformByState({left:v-C}));const _=this._scrollManagerService.getCurrentScrollState()||{sheetViewStartRow:0,sheetViewStartColumn:0},{sheetViewStartRow:w,sheetViewStartColumn:E}=_;if(E==null||w==null)return;const O=this._context.unit,R=O.getActiveSheet();if(!R)return;const P=(V=R.getConfig())==null?void 0:V.freeze;let A=(P==null?void 0:P.xSplit)||0,k=(P==null?void 0:P.ySplit)||0;const N=(L=this._activeViewport)==null?void 0:L.viewportKey;r===0&&(!N||N===M.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP||N===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP||N===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||N===M.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP?k=this._changeToRow-(P.startRow-P.ySplit):k=this._changeToRow-w,k=k<0?0:k),r===1&&(!N||N===M.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP||N===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP||N===M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||N===M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT?A=this._changeToColumn-(P.startColumn-P.xSplit):A=this._changeToColumn-E,A=A<0?0:A),this._commandService.executeCommand(m.SetFrozenCommand.id,{startRow:k===0?-1:this._changeToRow,startColumn:A===0?-1:this._changeToColumn,ySplit:k,xSplit:A,unitId:O.getUnitId(),subUnitId:R.getSheetId()})})}_getViewports(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e,i=t.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT),r=t.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT),s=t.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP),l=t.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM),c=t.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP),d=t.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN),u=t.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP),h=t.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT),g=t.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(!(i==null||r==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:i,viewColumnRight:r,viewRowTop:s,viewRowBottom:l,viewLeftTop:c}}_bindViewportScroll(){const e=this._getViewports();if(!e)return;const{viewRowBottom:t,viewColumnRight:i,viewMainLeft:r,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}),i.isActive&&i.updateScrollVal({scrollX:c,viewportScrollX:u}),r.isActive&&r.updateScrollVal({scrollY:d,viewportScrollY:h}),s.isActive&&s.updateScrollVal({scrollX:c,viewportScrollX:u})}))}_updateViewport(e=-1,t=-1,i=0,r=0,s=3){var A;const l=(A=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:A.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:v,viewColumnRight:p,viewRowTop:C,viewRowBottom:_,viewLeftTop:w}=u;p.resizeWhenFreezeChange({left:c,top:0,height:d+1,right:0}),_.resizeWhenFreezeChange({left:0,top:d,bottom:0,width:c+1}),w.resizeWhenFreezeChange({left:0,top:0,width:c+1,height:d});let E=!0,O=!0;g.enable(),(e===-1||e===0)&&(E=!1),(t===-1||t===0)&&(O=!1);const R=l.getNoMergeCellWithCoordByIndex(e-i,t-r,!1),P=l.getNoMergeCellWithCoordByIndex(e,t,!1);if(g.disable(),f.disable(),S.disable(),C.disable(),v.disable(),g.resetPadding(),f.resetPadding(),S.resetPadding(),C.resetPadding(),v.resetPadding(),E===!1&&O===!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+1,height:0}),v.resizeWhenFreezeChange({left:0,top:0,height:d+1,width:0});else if(E===!0&&O===!1){const k=P.startY-R.startY;h.resizeWhenFreezeChange({left:c,top:d+k,bottom:0,right:0}),h.setPadding({startY:R.startY,endY:P.startY,startX:0,endX:0}),s&2&&this._commandService.executeCommand(Le.id,{sheetViewStartRow:0,offsetY:0}),f.resizeWhenFreezeChange({left:c,top:d,height:k,right:0}),f.updateScrollVal({viewportScrollY:R.startY,rawScrollX:h.scrollX,viewportScrollX:h.viewportScrollX}),C.resizeWhenFreezeChange({left:0,top:d,width:c+1,height:k}),C.updateScrollVal({viewportScrollY:R.startY}),_.resizeWhenFreezeChange({left:0,top:d+k,bottom:0,width:c+1}),f.enable(),C.enable()}else if(E===!1&&O===!0){const k=P.startX-R.startX;h.resizeWhenFreezeChange({left:c+k,top:d,bottom:0,right:0}),h.setPadding({startX:R.startX,endX:P.startX,startY:0,endY:0}),s&1&&this._commandService.executeCommand(Le.id,{sheetViewStartColumn:0,offsetX:0}),S.resizeWhenFreezeChange({left:c,top:d,width:k,bottom:0,right:0}),S.updateScrollVal({viewportScrollX:R.startX,rawScrollY:h.scrollY,viewportScrollY:h.viewportScrollY}),v.resizeWhenFreezeChange({left:c,top:0,width:k,height:d+1}),v.updateScrollVal({viewportScrollX:R.startX}),p.resizeWhenFreezeChange({left:c+k,top:0,height:d+1,right:0}),S.enable(),v.enable()}else{const k=P.startX-R.startX,N=P.startY-R.startY;h.resizeWhenFreezeChange({left:c+k,top:d+N,bottom:0,right:0}),h.setPadding({startY:R.startY,endY:P.startY,startX:R.startX,endX:P.startX}),s&&this._commandService.executeCommand(Le.id,{...s&1?{sheetViewStartColumn:0,offsetX:0}:null,...s&2?{sheetViewStartRow:0,offsetY:0}:null}),S.resizeWhenFreezeChange({left:c,top:d+N,width:k,bottom:0}),S.updateScrollVal({viewportScrollX:R.startX,rawScrollY:h.scrollY,viewportScrollY:h.viewportScrollY}),f.resizeWhenFreezeChange({left:c+k,top:d,height:N,right:0}),f.updateScrollVal({viewportScrollY:R.startY,rawScrollX:h.scrollX,viewportScrollX:h.viewportScrollX}),g.resizeWhenFreezeChange({left:c,top:d,width:k,height:N}),g.updateScrollVal({viewportScrollX:R.startX,viewportScrollY:R.startY}),C.resizeWhenFreezeChange({left:0,top:d,width:c+1,height:N}),C.updateScrollVal({viewportScrollY:R.startY}),_.resizeWhenFreezeChange({left:0,top:d+N,bottom:0,width:c+1}),v.resizeWhenFreezeChange({left:c,top:0,width:k,height:d+1}),v.updateScrollVal({viewportScrollX:R.startX}),p.resizeWhenFreezeChange({left:c+k,top:0,height:d+1,right:0}),g.enable(),f.enable(),S.enable(),C.enable(),v.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 i=t.getConfig().freeze,{startRow:r=-1,startColumn:s=-1,ySplit:l=0,xSplit:c=0}=i;this._refreshFreeze(r,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=a.get(e,"gray.300"),this._freezeNormalMainColor=new a.ColorKit(this._freezeNormalHeaderColor).setAlpha(cS).toRgbString(),this._freezeActiveColor=a.get(e,"primary.600"),this._freezeHoverColor=a.get(e,"gray.500")}_interceptorCommands(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{const t={redos:[],undos:[]},i=this._getFreeze();if(!i)return t;const r=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<i.startRow||l.startRow+1===i.startRow&&c===a.Direction.UP){const u={...i,startRow:Math.max(1,i.startRow+d),ySplit:Math.max(1,i.ySplit+d)};return r(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<i.startColumn||l.startColumn+1===i.startColumn&&c===a.Direction.LEFT){const u={...i,startColumn:Math.max(1,i.startColumn+d),xSplit:Math.max(1,i.xSplit+d)};return r(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(!i||i.startColumn<=0||u.startColumn>=i.startColumn&&h.startColumn>=i.startColumn||u.startColumn===h.startColumn||u.endColumn<i.startColumn&&h.startColumn<i.startColumn)return t;const g=u.endColumn-u.startColumn+1,S=Math.max(Math.min(i.startColumn,u.endColumn+1)-u.startColumn,0);let f,v;h.startColumn>=i.startColumn?(f=Math.max(i.startColumn-S,1),v=Math.max(i.xSplit-S,1)):(f=i.startColumn+g-S,v=i.xSplit+g-S);const p={...i,startColumn:f,xSplit:v};return r(p)}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(!i||i.startRow<=0||u.startRow>=i.startRow&&h.startRow>=i.startRow||u.startRow===h.startRow||u.endRow<i.startRow&&h.startRow<i.startRow)return t;const g=u.endRow-u.startRow+1,S=Math.max(Math.min(i.startRow,u.endRow+1)-u.startRow,0);let f,v;h.startRow>=i.startRow?(f=Math.max(i.startRow-S,1),v=Math.max(i.ySplit-S,1)):(f=i.startRow+g-S,v=i.ySplit+g-S);const p={...i,startRow:f,ySplit:v};return r(p)}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<i.startColumn){const c=Math.min(i.startColumn,l.endColumn+1)-l.startColumn,d={...i,startColumn:Math.max(1,i.startColumn-c),xSplit:Math.max(1,i.xSplit-c)};return r(d)}if(s.range.rangeType===a.RANGE_TYPE.ROW&&l.startRow<i.startRow){const c=Math.min(i.startRow,l.endRow+1)-l.startRow,d={...i,startRow:Math.max(1,i.startRow-c),ySplit:Math.max(1,i.ySplit-c)};return r(d)}}return t}}))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{switch(e.id){case m.SetFrozenMutation.id:case Ye.id:{const t=this._lastFreeze,i=this._context.unit,r=i.getActiveSheet(),s=e.params,{unitId:l,subUnitId:c}=s;if(!(l===i.getUnitId()&&c===(r==null?void 0:r.getSheetId())))return;const d=r.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(),i=t&&e.params.ranges.some(r=>r.startRow<t.startRow);e.params&&i&&this._refreshCurrent()}break;case m.SetWorksheetColWidthMutation.id:{const t=this._getFreeze();e.params&&t&&e.params.ranges.some(i=>i.startColumn<t.startColumn)&&this._refreshCurrent()}break;case m.SetWorksheetRowAutoHeightMutation.id:{const t=e.params,i=this._getFreeze();if(i&&i.startRow>-1&&t.rowsAutoHeightInfo.some(r=>r.row<i.startRow)){const r=this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._refreshCurrent(),setTimeout(()=>{r.unsubscribe()})})}}break;case m.SetColHiddenMutation.id:case m.SetColVisibleMutation.id:{const t=e.params,i=this._getFreeze(),r=t.ranges;i&&i.startColumn>-1&&r.some(s=>s.startColumn<i.startColumn)&&this._refreshCurrent()}break;case m.SetRowHiddenMutation.id:case m.SetRowVisibleMutation.id:{const t=e.params,i=this._getFreeze(),r=t.ranges;i&&i.startRow>-1&&r.some(s=>s.startRow<i.startRow)&&this._refreshCurrent()}break;case Xn.id:case Yn.id:this._refreshCurrent()}}))}_zoomRefresh(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;this.disposeWithMe(t.onTransformChange$.subscribeEvent(i=>{[M.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale,M.TRANSFORM_CHANGE_OBSERVABLE_TYPE.all].includes(i.type)&&this._refreshCurrent()}))}_clearObserverEvent(){var t,i;this._getSheetObject()!=null&&((t=this._scenePointerMoveSub)==null||t.unsubscribe(),(i=this._scenePointerUpSub)==null||i.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null)}_clearFreeze(){var t,i,r,s,l,c;(t=this._rowFreezeHeaderRect)==null||t.dispose(),(i=this._rowFreezeMainRect)==null||i.dispose(),(r=this._columnFreezeHeaderRect)==null||r.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 r=(d=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:d.skeleton,s=r==null?void 0:r.getNoMergeCellWithCoordByIndex(e,t);if(r==null)return;if(s!=null&&(!isNaN(s.endX)||!isNaN(s.endY)))return s;const{rowHeaderWidthAndMarginLeft:l,columnHeaderHeightAndMarginTop:c}=r;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 Ve(this._context.unit,this._context)}_refreshFreeze(e,t,i,r,s){var c;const l={startRow:e,startColumn:t,ySplit:i,xSplit:r};this._clearFreeze(),this._createFreeze(0,l),this._createFreeze(1,l),this._updateViewport(e,t,i,r,s),(c=this._getSheetObject())==null||c.spreadsheet.makeForceDirty()}},T.HeaderFreezeRenderController=oS([Yt(1,a.Inject(T.SheetSkeletonManagerService)),Yt(2,a.ICommandService),Yt(3,a.Inject(m.SheetsSelectionsService)),Yt(4,a.Inject(T.SheetScrollManagerService)),Yt(5,a.Inject(a.ThemeService)),Yt(6,a.Inject(m.SheetInterceptorService)),Yt(7,a.Inject(a.Injector))],T.HeaderFreezeRenderController);var dS=Object.getOwnPropertyDescriptor,uS=(n,o,e,t)=>{for(var i=t>1?void 0:t?dS(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},os=(n,o)=>(e,t)=>o(e,t,n);const hS="__SpreadsheetHeaderMoveControllerBackground__",mS="__SpreadsheetHeaderMoveControllerShapeLine__",gS="rgba(0, 0, 0, 0.1)",SS="rgb(119, 119, 119)",fS=4,rs=a.createInterceptorKey("headerMovePermissionCheck");T.HeaderMoveRenderController=class extends a.Disposable{constructor(e,t,i,r){super();y(this,"_startOffsetX",Number.NEGATIVE_INFINITY);y(this,"_startOffsetY",Number.NEGATIVE_INFINITY);y(this,"_moveHelperBackgroundShape");y(this,"_moveHelperLineShape");y(this,"_headerPointerDownSubs");y(this,"_headerPointerMoveSubs");y(this,"_headerPointerLeaveSubs");y(this,"_dragHeaderMoveSub");y(this,"_scenePointerUpSub");y(this,"_scrollTimer");y(this,"_changeFromColumn",-1);y(this,"_changeFromRow",-1);y(this,"_changeToColumn",-1);y(this,"_changeToRow",-1);y(this,"interceptor",new a.InterceptorManager({HEADER_MOVE_PERMISSION_CHECK:rs}));y(this,"_workbookSelections");this._context=e,this._sheetSkeletonManagerService=i,this._commandService=r,this._workbookSelections=t.getWorkbookSelections(this._context.unitId),this._init()}dispose(){var e,t,i,r,s,l,c,d;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(t=this._moveHelperLineShape)==null||t.dispose(),(i=this._headerPointerMoveSubs)==null||i.unsubscribe(),(r=this._headerPointerLeaveSubs)==null||r.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),i=this._context.components.get(he.ROW),r=this._context.scene,s=e===a.RANGE_TYPE.ROW?i:t,l=u=>{var _,w;const h=(_=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:_.skeleton;if(h==null)return;const g=(w=this._workbookSelections.getCurrentLastSelection())==null?void 0:w.range;if(!g||!this.interceptor.fetchThroughInterceptors(rs)(!1,g))return;const f=this._workbookSelections.getCurrentSelections(),{row:v,column:p}=Xe(u.offsetX,u.offsetY,r,h);if(!Ri(f,e===a.RANGE_TYPE.ROW?v:p,e)){r.resetCursor();return}r.setCursor(M.CURSOR_TYPE.GRAB)},c=()=>{var u,h;(u=this._moveHelperBackgroundShape)==null||u.hide(),(h=this._moveHelperLineShape)==null||h.hide(),r.resetCursor()},d=(u,h)=>{var H,W;if(h.isStopPropagation)return;const g=(H=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:H.skeleton;if(g==null)return;const S=(W=this._workbookSelections.getCurrentLastSelection())==null?void 0:W.range;if(!S||!this.interceptor.fetchThroughInterceptors(rs)(!1,S))return;const{offsetX:v,offsetY:p}=u,C=r.getCoordRelativeToViewport(M.Vector2.FromArray([v,p])),{x:_,y:w}=C;this._startOffsetX=_,this._startOffsetY=w;const{row:E,column:O}=Xe(u.offsetX,u.offsetY,r,g);let R;e===a.RANGE_TYPE.ROW?(this._changeFromRow=E,R=M.ScrollTimerType.Y):(this._changeFromColumn=O,R=M.ScrollTimerType.X);const P=this._workbookSelections.getCurrentSelections(),A=Ri(P,e===a.RANGE_TYPE.ROW?E:O,e);if(!A)return;const k=r.getScrollXYInfoByViewport(M.Vector2.FromArray([this._startOffsetX,this._startOffsetY]));this._newBackgroundAndLine(),r.setCursor(M.CURSOR_TYPE.GRABBING),r.disableObjectsEvent();let N=!1,V;const L=()=>{if(N)return;V=M.ScrollTimer.create(r,R),this._scrollTimer=V;const B=r.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN);V.startScroll(_,w,B),N=!0};this._dragHeaderMoveSub=r.onPointerMove$.subscribeEvent(B=>{L();const{offsetX:U,offsetY:X}=B,{x:F,y:Y}=r.getCoordRelativeToViewport(M.Vector2.FromArray([U,X]));this._rowColumnMoving(F,Y,A,k,e),V.scrolling(F,Y,()=>{this._rowColumnMoving(F,Y,A,k,e)})}),this._scenePointerUpSub=r.onPointerUp$.subscribeEvent(()=>{var U,X,F;this._disposeBackgroundAndLine(),r.resetCursor(),r.enableObjectsEvent(),this._clearObserverEvent(),(U=this._scrollTimer)==null||U.dispose();const B=this._workbookSelections.getCurrentSelections();if(e===a.RANGE_TYPE.ROW){if(this._changeFromRow!==this._changeToRow&&this._changeToRow!==-1){const j=(X=((B==null?void 0:B.filter(Q=>Q.range.rangeType===a.RANGE_TYPE.ROW&&Q.range.startRow<=this._changeFromRow&&this._changeFromRow<=Q.range.endRow))||[])[0])==null?void 0:X.range;j&&this._commandService.executeCommand(m.MoveRowsCommand.id,{fromRange:j,toRange:{...j,startRow:this._changeToRow,endRow:this._changeToRow+j.endRow-j.startRow}})}this._changeToRow=this._changeFromRow=-1}else{if(this._changeFromColumn!==this._changeToColumn&&this._changeToColumn!==-1){const j=(F=((B==null?void 0:B.filter(Q=>Q.range.rangeType===a.RANGE_TYPE.COLUMN&&Q.range.startColumn<=this._changeFromColumn&&this._changeFromColumn<=Q.range.endColumn))||[])[0])==null?void 0:F.range;j&&this._commandService.executeCommand(m.MoveColsCommand.id,{fromRange:j,toRange:{...j,startColumn:this._changeToColumn,endColumn:this._changeToColumn+j.endColumn-j.startColumn}})}this._changeToColumn=this._changeFromColumn=-1}})};this._headerPointerMoveSubs=new D.Subscription,this._headerPointerMoveSubs.add(s.onPointerMove$.subscribeEvent(l)),this._headerPointerLeaveSubs=new D.Subscription,this._headerPointerLeaveSubs.add(s==null?void 0:s.onPointerLeave$.subscribeEvent(c)),this._headerPointerDownSubs=new D.Subscription,this._headerPointerDownSubs.add(s==null?void 0:s.onPointerDown$.subscribeEvent(d))}_rowColumnMoving(e,t,i,r,s){var Y,j,Q,oe,re,ce,G;const l=this._context.scene,c=(Y=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:Y.skeleton;if(c==null)return;const{rowHeaderWidth:d,columnHeaderHeight:u,rowTotalHeight:h,columnTotalWidth:g}=c,S=l.getViewportScrollXY(l.getViewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:f,scaleY:v}=l.getAncestorScale(),p=c.getCellIndexByOffset(e,t,f,v,S),{row:C,column:_}=p,w=c.getNoMergeCellWithCoordByIndex(C,_),{startX:E,startY:O,endX:R,endY:P}=w,A=this._sheetSkeletonManagerService.attachRangeWithCoord(i.range);if(A==null)return;const k=Math.max(f,f),{startX:N,endX:V,startY:L,endY:H,startRow:W,startColumn:B,endRow:U,endColumn:X}=A;s===a.RANGE_TYPE.ROW?(j=this._moveHelperBackgroundShape)==null||j.transformByState({height:H-L,width:g+d,left:0,top:L+(t-this._startOffsetY)/k+S.y-r.y}):(Q=this._moveHelperBackgroundShape)==null||Q.transformByState({height:h+u,width:V-N,left:N+(e-this._startOffsetX)/k+S.x-r.x,top:0}),(oe=this._moveHelperBackgroundShape)==null||oe.show();const F=fS/k;if(s===a.RANGE_TYPE.ROW){let Z=0;if(C<=W)Z=O-F/2,this._changeToRow=C;else if(C>U)Z=P-F/2,this._changeToRow=C+1;else return;(re=this._moveHelperLineShape)==null||re.transformByState({height:F,width:g,left:d,top:Z})}else{let Z=0;if(_<=B)Z=E-F/2,this._changeToColumn=_;else if(_>X)Z=R-F/2,this._changeToColumn=_+1;else return;(ce=this._moveHelperLineShape)==null||ce.transformByState({height:h,width:F,left:Z,top:u})}(G=this._moveHelperLineShape)==null||G.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 M.Rect(hS,{fill:gS,evented:!1,zIndex:100}),this._moveHelperLineShape=new M.Rect(mS,{fill:SS,evented:!1,zIndex:100}),e.addObjects([this._moveHelperBackgroundShape,this._moveHelperLineShape],rt)}_disposeBackgroundAndLine(){var e,t;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(t=this._moveHelperLineShape)==null||t.dispose()}},T.HeaderMoveRenderController=uS([os(1,a.Inject(m.SheetsSelectionsService)),os(2,a.Inject(T.SheetSkeletonManagerService)),os(3,a.ICommandService)],T.HeaderMoveRenderController);var ss=(n=>(n[n.VERTICAL=0]="VERTICAL",n[n.HORIZONTAL=1]="HORIZONTAL",n))(ss||{});const vS="rgba(120, 120, 120, 0.01)",as="rgb(68, 71, 70)",Pi=12,pS=44,ls=4;class Yl extends M.Shape{constructor(e,t){super(e,t);y(this,"_size",Pi);y(this,"_color",as);y(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:i,scaleY:r}=t.getAncestorScale(),s=Math.max(i,r),l=Pi/s,c=ls/s;let{width:d,height:u}=this,h=0,g=0;this.mode===0?(d=c,h=l-c):(u=c,g=l-c),M.Rect.drawWith(e,{width:this.width,height:this.height,left:0,top:0,fill:vS}),M.Rect.drawWith(e,{width:d,height:u,fill:as,radius:c}),e.save(),e.transform(1,0,0,1,h,g),M.Rect.drawWith(e,{width:d,height:u,fill:as,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:Pi,height:this.size}):this.transformByState({width:this.size,height:Pi}),this}}var CS=Object.getOwnPropertyDescriptor,IS=(n,o,e,t)=>{for(var i=t>1?void 0:t?CS(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},cs=(n,o)=>(e,t)=>o(e,t,n);const _S="__SpreadsheetHeaderResizeControllerShapeRow__",bS="__SpreadsheetHeaderResizeControllerShapeColumn__",jl="__SpreadsheetHeaderResizeControllerShapeHelper__",Zl="rgb(199, 199, 199)",wS=2,ds=a.createInterceptorKey("headerResizePermissionCheck");T.HeaderResizeRenderController=class extends a.Disposable{constructor(e,t,i,r){super();y(this,"_currentRow",0);y(this,"_currentColumn",0);y(this,"_rowResizeRect");y(this,"_columnResizeRect");y(this,"_headerPointerSubs");y(this,"_scenePointerMoveSub");y(this,"_scenePointerUpSub");y(this,"_resizeHelperShape");y(this,"_startOffsetX",Number.POSITIVE_INFINITY);y(this,"_startOffsetY",Number.POSITIVE_INFINITY);y(this,"interceptor",new a.InterceptorManager({HEADER_RESIZE_PERMISSION_CHECK:ds}));this._context=e,this._sheetSkeletonManagerService=t,this._selectionManagerService=i,this._commandService=r,this._init()}dispose(){var e,t,i;(e=this._rowResizeRect)==null||e.dispose(),this._rowResizeRect=null,(t=this._columnResizeRect)==null||t.dispose(),this._columnResizeRect=null,(i=this._headerPointerSubs)==null||i.unsubscribe(),this._headerPointerSubs=null}_init(){const e=this._context.scene;this._rowResizeRect=new Yl(_S,{visible:!1,mode:ss.HORIZONTAL,zIndex:100}),this._columnResizeRect=new Yl(bS,{visible:!1,mode:ss.VERTICAL,zIndex:100}),e.addObjects([this._rowResizeRect,this._columnResizeRect],rt),this._initialHover(0),this._initialHover(1),this._initialHoverResize(0),this._initialHoverResize(1)}_initialHover(e=0){const t=this._context.components.get(he.COLUMN),i=this._context.components.get(he.ROW),r=this._context.scene,s=e===0?i:t,l=(d,u)=>{var h,g;(h=this._rowResizeRect)==null||h.hide(),(g=this._columnResizeRect)==null||g.hide()},c=(d,u)=>{var k;const h=(k=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:k.skeleton;if(h==null||this._rowResizeRect==null||this._columnResizeRect==null)return;const{rowHeaderWidth:g,columnHeaderHeight:S}=h,{startX:f,startY:v,endX:p,endY:C,row:_,column:w}=Xe(d.offsetX,d.offsetY,r,h),E=Si(d.offsetX,d.offsetY,r),{scaleX:O,scaleY:R}=r.getAncestorScale(),P=Math.max(O,R),A=Pi/P;if(e===0){let N=v-A/2;if(E.y<=v+A/2&&E.y>=v)this._currentRow=_-1;else if(E.y>=C-A/2&&E.y<=C)this._currentRow=_,N=C-A/2;else{this._rowResizeRect.hide();return}if(this._currentRow===-1)return;if(!this.interceptor.fetchThroughInterceptors(ds)(null,{row:this._currentRow}))return!1;const L=Math.min(pS,g/3);this._rowResizeRect.transformByState({left:g/2-L/2,top:N}),this._rowResizeRect.setShapeProps({size:L}),this._rowResizeRect.show()}else{let N=f-A/2;if(E.x<=f+A/2&&E.x>=f)this._currentColumn=w-1;else if(E.x>=p-A/2&&E.x<=p)this._currentColumn=w,N=p-A/2;else{this._columnResizeRect.hide();return}if(this._currentColumn===-1)return;if(!this.interceptor.fetchThroughInterceptors(ds)(null,{col:this._currentColumn}))return!1;const L=S*.7;this._columnResizeRect.transformByState({left:N,top:S/2-L/2}),this._columnResizeRect.setShapeProps({size:L}),this._columnResizeRect.show()}};this._headerPointerSubs=new D.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,i=e===0?this._rowResizeRect:this._columnResizeRect;i!=null&&(this.disposeWithMe(i.onPointerEnter$.subscribeEvent(()=>{i!=null&&(i.show(),t.setCursor(e===0?M.CURSOR_TYPE.ROW_RESIZE:M.CURSOR_TYPE.COLUMN_RESIZE))})),this.disposeWithMe(i.onPointerLeave$.subscribeEvent(()=>{i!=null&&(i.hide(),t.resetCursor())})),this.disposeWithMe(i.onPointerDown$.subscribeEvent(r=>{var X,F,Y,j,Q,oe,re;const s=(X=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:X.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(M.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=(((Y=(F=h==null?void 0:h.getScrollBar())==null?void 0:F.horizonScrollTrack)==null?void 0:Y.height)||0)+10,S=(((Q=(j=h==null?void 0:h.getScrollBar())==null?void 0:j.verticalScrollTrack)==null?void 0:Q.width)||0)+10,f=Si(r.offsetX,r.offsetY,l),{scaleX:v,scaleY:p}=l.getAncestorScale();this._startOffsetX=f.x,this._startOffsetY=f.y;const C=s.getOffsetByColumn(this._currentColumn),_=s.getOffsetByRow(this._currentRow),w=s.getNoMergeCellWithCoordByIndex(this._currentRow,this._currentColumn);let E=!1,O=0,R=0;const{columnTotalWidth:P,rowHeaderWidth:A,rowTotalHeight:k,columnHeaderHeight:N}=s,V=u>P+A?u:P+A,L=d>k+N?d:k+N,H=Math.max(v,p),W=ls/H;e===0?this._resizeHelperShape=new M.Rect(jl,{width:V,height:W,fill:Zl,left:0,top:_-W/2}):this._resizeHelperShape=new M.Rect(jl,{width:W,height:L,fill:Zl,left:C-W/2,top:0});const B=((oe=this._columnResizeRect)==null?void 0:oe.left)||0,U=((re=this._rowResizeRect)==null?void 0:re.top)||0;l.addObject(this._resizeHelperShape,rt),l.disableObjectsEvent(),this._scenePointerMoveSub=l.onPointerMove$.subscribeEvent(ce=>{var ve,we,Ee,Ct,It,Kt;const G=l.getCoordRelativeToViewport(M.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),Z=l.getScrollXYInfoByViewport(G,h),J=Si(ce.offsetX,ce.offsetY,l),{x:ne,y:ue}=J,{scaleX:ie,scaleY:se}=l.getAncestorScale(),te=Math.max(ie,se),fe=ls/te;O=ne-this._startOffsetX-fe/2,R=ue-this._startOffsetY-fe/2,Math.abs(e===0?R:O)>=wS&&(E=!0),e===0?(R>d-g+Z.y-w.startY&&(R=d-g+Z.y-w.startY),R<-(w.endY-w.startY)+2&&(R=-(w.endY-w.startY)+2),E&&((ve=this._resizeHelperShape)==null||ve.transformByState({top:_+R}),(we=this._rowResizeRect)==null||we.transformByState({top:U+R+fe/2}),(Ee=this._rowResizeRect)==null||Ee.show(),l.setCursor(M.CURSOR_TYPE.ROW_RESIZE))):(O>u-S+Z.x-w.startX&&(O=u-S+Z.x-w.startX),O<-(w.endX-w.startX)+2&&(O=-(w.endX-w.startX)+2),E&&((Ct=this._resizeHelperShape)==null||Ct.transformByState({left:C+O}),(It=this._columnResizeRect)==null||It.transformByState({left:B+O+fe/2}),(Kt=this._columnResizeRect)==null||Kt.show(),l.setCursor(M.CURSOR_TYPE.COLUMN_RESIZE)))}),this._scenePointerUpSub=l.onPointerUp$.subscribeEvent(ce=>{var Z,J,ne;const G=this._context.scene;this._clearObserverEvent(),(Z=this._resizeHelperShape)==null||Z.dispose(),this._resizeHelperShape=null,G.enableObjectsEvent(),E&&(G.resetCursor(),(J=this._rowResizeRect)==null||J.hide(),(ne=this._columnResizeRect)==null||ne.hide(),e===0?this._commandService.executeCommand(m.DeltaRowHeightCommand.id,{deltaY:R,anchorRow:this._currentRow}):this._commandService.executeCommand(m.DeltaColumnWidthCommand.id,{deltaX:O,anchorCol:this._currentColumn}))})})),this.disposeWithMe(i.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(),v=[];for(let p=0;p<f.length;p++){const C=f[p];C.range.rangeType===a.RANGE_TYPE.COLUMN&&this._currentColumn<=C.range.endColumn&&this._currentColumn>=C.range.startColumn&&v.push({startColumn:C.range.startColumn,endColumn:C.range.endColumn,startRow:l,endRow:d})}v.length===0&&v.push({startColumn:this._currentColumn,endColumn:this._currentColumn,startRow:l,endRow:d}),this._commandService.executeCommand(pn.id,{ranges:v}),(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}},T.HeaderResizeRenderController=IS([cs(1,a.Inject(T.SheetSkeletonManagerService)),cs(2,a.Inject(m.SheetsSelectionsService)),cs(3,a.ICommandService)],T.HeaderResizeRenderController);var ES=Object.getOwnPropertyDescriptor,TS=(n,o,e,t)=>{for(var i=t>1?void 0:t?ES(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},Oi=(n,o)=>(e,t)=>o(e,t,n);const yS=60;T.SheetRenderController=class extends a.RxDisposable{constructor(e,t,i,r,s,l){super();y(this,"_renderMetric$",new D.Subject);y(this,"renderMetric$",this._renderMetric$.asObservable());y(this,"_renderFrameTimeMetric",null);y(this,"_renderFrameTags",{});y(this,"_afterRenderMetric$",new D.Subject);this._context=e,this._configService=t,this._sheetSkeletonManagerService=i,this._sheetRenderService=r,this._commandService=s,this._telemetryService=l,this._addNewRender(),this._initRenderMetricSubscriber()}_addNewRender(){const{scene:e,engine:t,unit:i}=this._context;this._addComponent(i),this._initRerenderScheduler(),this._initCommandListener();const r=this._context.unit.getActiveSheet();if(!r)throw new Error("No active sheet found");const s=r.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(){const{engine:e}=this._context;e.beginFrame$.subscribe(()=>{this._renderFrameTimeMetric=null,this._renderFrameTags={}}),e.endFrame$.subscribe(()=>{this._renderFrameTimeMetric&&Object.keys(this._renderFrameTimeMetric).filter(r=>r.startsWith(M.SHEET_EXTENSION_PREFIX)).length>0&&this._afterRenderMetric$.next({frameTimeMetric:this._renderFrameTimeMetric,tags:this._renderFrameTags})}),e.renderFrameTimeMetric$.subscribe(([i,r])=>{this._renderFrameTimeMetric||(this._renderFrameTimeMetric={}),this._renderFrameTimeMetric[i]||(this._renderFrameTimeMetric[i]=[]),this._renderFrameTimeMetric[i].push(Math.round(r*100)/100)}),e.renderFrameTags$.subscribe(([i,r])=>{this._renderFrameTags[i]=r});const t=[];this._afterRenderMetric$.pipe(D.withLatestFrom(e.endFrame$)).subscribe(([i,r])=>{t.push({FPS:r.FPS,elapsedTime:r.elapsedTime,frameTime:Math.round(r.frameTime*100)/100,...i.frameTimeMetric,...i.tags}),t.length>yS&&(this._captureRenderMetric(t),t.length=0)})}_captureRenderMetric(e){var g;const t=e;if(t.length===0)return;const i=S=>{let f=0;const p=Object.entries(S).filter(([_,w])=>Array.isArray(w)).map(([_])=>_).reduce((_,w)=>{const E=S[w].reduce((O,R)=>O+R,0);return _[w]=E,_},{});return Object.keys(S).filter(_=>_.startsWith(M.SHEET_EXTENSION_PREFIX)).forEach(_=>{f+=p[_]}),{...p,extensionTotal:f}},r=e.map(S=>({...S,...i(S)})),l=(S=>Object.entries(S[0]).filter(([p,C])=>!["elapsedTime"].includes(p)).filter(([p,C])=>typeof C=="number").map(([p])=>p).reduce((p,C)=>{const _=S.map(R=>R[C]),w=Math.max(..._),E=Math.min(..._),O=_.reduce((R,P)=>R+P,0)/_.length;return p[C]={max:Math.round(w*100)/100,min:Math.round(E*100)/100,avg:Math.round(O*100)/100},p},{}))(r),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._renderMetric$.next(h),(g=this._telemetryService)==null||g.capture("sheet_render_cost",h)}_addComponent(e){const{scene:t,components:i}=this._context,r=e.getActiveSheet(),s=new M.Spreadsheet(he.MAIN);this._addViewport(r);const l=new M.SpreadsheetRowHeader(he.ROW),c=new M.SpreadsheetColumnHeader(he.COLUMN),d=new M.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,i.set(he.MAIN,s),i.set(he.ROW,l),i.set(he.COLUMN,c),i.set(he.LEFT_TOP,d),t.addObjects([s],ks),t.addObjects([l,c,d],rt),t.enableLayerCache(ks,rt)}_initViewports(e,t,i){const l=new M.Viewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN,e,{left:t.width,top:i.height,bottom:0,right:0,isWheelPreventDefaultX:!0,allowCache:!0,bufferEdgeX:100,bufferEdgeY:100}),c=new M.Viewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:0,bufferEdgeY:0}),d=new M.Viewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:0,bufferEdgeY:100}),u=new M.Viewport(M.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:100,bufferEdgeY:0}),h=new M.Viewport(M.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP,e,{active:!1,isWheelPreventDefaultX:!0}),g=new M.Viewport(M.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM,e,{left:0,top:i.height,bottom:0,width:t.width+1,isWheelPreventDefaultX:!0}),S=new M.Viewport(M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT,e,{active:!1,isWheelPreventDefaultX:!0}),f=new M.Viewport(M.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT,e,{left:t.width,top:0,height:i.height+1,right:0,isWheelPreventDefaultX:!0}),v=new M.Viewport(M.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP,e,{left:0,top:0,width:t.width,height:i.height,isWheelPreventDefaultX:!0});return{viewMain:l,viewLeftTop:v,viewMainLeftTop:c,viewMainLeft:d,viewMainTop:u,viewColumnLeft:S,viewRowTop:h,viewRowBottom:g,viewColumnRight:f}}_addViewport(e){const t=this._context.scene,{rowHeader:i,columnHeader:r}=e.getConfig(),{viewMain:s}=this._initViewports(t,i,r),l=this._configService.getConfig(Te),c=l==null?void 0:l.scrollConfig;return new M.ScrollBar(s,c),t.attachControl(),s}_initRerenderScheduler(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(!e)return null;const{skeleton:t,sheetId:i}=e,r=this._context.unit,s=r==null?void 0:r.getSheetBySheetId(i);if(r==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:i}=e;if(m.COMMAND_LISTENER_SKELETON_CHANGE.includes(i)||this._sheetRenderService.checkMutationShouldTriggerRerender(i)){const r=e.params,{unitId:s,subUnitId:l}=r,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:i},!0),this._sheetSkeletonManagerService.setCurrent({sheetId:u,commandId:i})}else m.COMMAND_LISTENER_VALUE_CHANGE.includes(i)&&this._sheetSkeletonManagerService.reCalculate();e.type===a.CommandType.MUTATION&&this._markUnitDirty(e)}))}_markUnitDirty(e){if(e.id.substring(0,3)==="doc")return;const{mainComponent:t,scene:i}=this._context;if(e.id===q.SetFormulaCalculationNotificationMutation.id&&e.params.stageInfo!=null||(t&&t.makeDirty(),i.makeDirty(),!e.params))return;const r=e.params,s=this._spreadsheetViewports(i);if(e.id===m.SetRangeValuesMutation.id&&r.cellValue){const l=this._cellValueToRange(r.cellValue),c=this._rangeToBounds([l]);this._markViewportDirty(s,c),t.setDirtyArea(c)}if(e.id===m.MoveRangeMutation.id&&r.from&&r.to){const l=r.fromRange||this._cellValueToRange(r.from.value),c=r.toRange||this._cellValueToRange(r.to.value),d=this._rangeToBounds([l,c]);this._markViewportDirty(s,d),t.setDirtyArea(d)}}_cellValueToRange(e){let t=0,i=0,r=0,s=0;for(const[h,g]of Object.entries(e)){for(const S in g)t>Number(S)&&(t=Number(S)),i<Number(S)&&(i=Number(S));r>Number(h)&&(r=Number(h)),s<Number(h)&&(s=Number(h))}return{startRow:r,endRow:s,startColumn:t,endColumn:i}}_rangeToBounds(e){const t=this._sheetSkeletonManagerService.getCurrentParam().skeleton,{rowHeightAccumulation:i,columnWidthAccumulation:r,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:i[u-1]+l,v=i[h]+l,p=g===0?0:r[g-1]+s,C=r[S]+s;c.push({top:f,left:p,bottom:v,right:C,width:C-p,height:v-f})}return c}_markViewportDirty(e,t){const i=e.filter(r=>r.isActive&&r.cacheBound);for(const r of i)for(const s of t)a.Rectangle.hasIntersectionBetweenTwoRect(r.cacheBound,s)&&r.markDirty(!0)}_spreadsheetViewports(e){return e.getViewports().filter(t=>["viewMain","viewMainLeftTop","viewMainTop","viewMainLeft"].includes(t.viewportKey))}},T.SheetRenderController=TS([Oi(1,a.Inject(a.IConfigService)),Oi(2,a.Inject(T.SheetSkeletonManagerService)),Oi(3,a.Inject(T.SheetsRenderService)),Oi(4,a.ICommandService),Oi(5,a.Optional(ud.ITelemetryService))],T.SheetRenderController);const RS=({className:n})=>b.jsxs("svg",{className:n,width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[b.jsx("path",{d:"M0.98999 1.08218H-0.0100098V0.0821838H0.98999V1.08218Z"}),b.jsx("path",{d:"M5.78992 1.08218H2.78992V0.0821838H5.78992V1.08218Z"}),b.jsx("path",{d:"M7.58984 1.08218H8.58984V0.0821838H7.58984V1.08218Z"}),b.jsx("path",{d:"M14.9152 1.08218H13.9152V0.0821838H14.9152V1.08218Z"}),b.jsx("path",{d:"M16.7151 1.08218H19.7151V0.0821838H16.7151V1.08218Z"}),b.jsx("path",{d:"M22.515 1.08218H21.515V0.0821838H22.515V1.08218Z"}),b.jsx("path",{d:"M27.8405 1.08218H28.8405V0.0821838H27.8405V1.08218Z"}),b.jsx("path",{d:"M33.6404 1.08218H30.6404V0.0821838H33.6404V1.08218Z"}),b.jsx("path",{d:"M35.4403 1.08218H36.4403V0.0821838H35.4403V1.08218Z"}),b.jsx("path",{d:"M42.7657 1.08218H41.7657V0.0821838H42.7657V1.08218Z"}),b.jsx("path",{d:"M44.5657 1.08218H47.5657V0.0821838H44.5657V1.08218Z"}),b.jsx("path",{d:"M50.3656 1.08218H49.3656V0.0821838H50.3656V1.08218Z"}),b.jsx("path",{d:"M55.691 1.08218H56.691V0.0821838H55.691V1.08218Z"}),b.jsx("path",{d:"M61.491 1.08218H58.491V0.0821838H61.491V1.08218Z"}),b.jsx("path",{d:"M63.2909 1.08218H64.2909V0.0821838H63.2909V1.08218Z"}),b.jsx("path",{d:"M70.6163 1.08218H69.6163V0.0821838H70.6163V1.08218Z"}),b.jsx("path",{d:"M72.4163 1.08218H75.4163V0.0821838H72.4163V1.08218Z"}),b.jsx("path",{d:"M78.2162 1.08218H77.2162V0.0821838H78.2162V1.08218Z"}),b.jsx("path",{d:"M83.5416 1.08218H84.5416V0.0821838H83.5416V1.08218Z"}),b.jsx("path",{d:"M89.3416 1.08218H86.3416V0.0821838H89.3416V1.08218Z"}),b.jsx("path",{d:"M91.1415 1.08218H92.1415V0.0821838H91.1415V1.08218Z"}),b.jsx("path",{d:"M98.4669 1.08218H97.4669V0.0821838H98.4669V1.08218Z"}),b.jsx("path",{d:"M100.267 1.08218H103.267V0.0821838H100.267V1.08218Z"}),b.jsx("path",{d:"M106.067 1.08218H105.067V0.0821838H106.067V1.08218Z"}),b.jsx("path",{d:"M111.392 1.08218H112.392V0.0821838H111.392V1.08218Z"}),b.jsx("path",{d:"M117.192 1.08218H114.192V0.0821838H117.192V1.08218Z"}),b.jsx("path",{d:"M118.992 1.08218H119.992V0.0821838H118.992V1.08218Z"})]}),MS=({className:n})=>b.jsxs("svg",{className:n,width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[b.jsx("path",{d:"M-0.0100098 1.15771H0.98999V0.157715H-0.0100098V1.15771Z"}),b.jsx("path",{d:"M2.78992 1.15771H5.78992V0.157715H2.78992V1.15771Z"}),b.jsx("path",{d:"M8.58984 1.15771H7.58984V0.157715H8.58984V1.15771Z"}),b.jsx("path",{d:"M10.3899 1.15771H11.3899V0.157715H10.3899V1.15771Z"}),b.jsx("path",{d:"M19.0903 1.15771H18.0903V0.157715H19.0903V1.15771Z"}),b.jsx("path",{d:"M20.8903 1.15771H23.8903V0.157715H20.8903V1.15771Z"}),b.jsx("path",{d:"M26.6902 1.15771H25.6902V0.157715H26.6902V1.15771Z"}),b.jsx("path",{d:"M28.4902 1.15771H29.4902V0.157715H28.4902V1.15771Z"}),b.jsx("path",{d:"M37.1907 1.15771H36.1907V0.157715H37.1907V1.15771Z"}),b.jsx("path",{d:"M38.9906 1.15771H41.9906V0.157715H38.9906V1.15771Z"}),b.jsx("path",{d:"M44.7905 1.15771H43.7905V0.157715H44.7905V1.15771Z"}),b.jsx("path",{d:"M46.5906 1.15771H47.5906V0.157715H46.5906V1.15771Z"}),b.jsx("path",{d:"M55.291 1.15771H54.291V0.157715H55.291V1.15771Z"}),b.jsx("path",{d:"M57.0909 1.15771H60.0909V0.157715H57.0909V1.15771Z"}),b.jsx("path",{d:"M62.8909 1.15771H61.8909V0.157715H62.8909V1.15771Z"}),b.jsx("path",{d:"M64.6909 1.15771H65.6909V0.157715H64.6909V1.15771Z"}),b.jsx("path",{d:"M73.3914 1.15771H72.3914V0.157715H73.3914V1.15771Z"}),b.jsx("path",{d:"M75.1913 1.15771H78.1913V0.157715H75.1913V1.15771Z"}),b.jsx("path",{d:"M80.9912 1.15771H79.9912V0.157715H80.9912V1.15771Z"}),b.jsx("path",{d:"M82.7913 1.15771H83.7913V0.157715H82.7913V1.15771Z"}),b.jsx("path",{d:"M91.4917 1.15771H90.4917V0.157715H91.4917V1.15771Z"}),b.jsx("path",{d:"M93.2916 1.15771H96.2916V0.157715H93.2916V1.15771Z"}),b.jsx("path",{d:"M99.0916 1.15771H98.0916V0.157715H99.0916V1.15771Z"}),b.jsx("path",{d:"M100.892 1.15771H101.892V0.157715H100.892V1.15771Z"}),b.jsx("path",{d:"M109.592 1.15771H108.592V0.157715H109.592V1.15771Z"}),b.jsx("path",{d:"M111.392 1.15771H114.392V0.157715H111.392V1.15771Z"}),b.jsx("path",{d:"M117.192 1.15771H116.192V0.157715H117.192V1.15771Z"}),b.jsx("path",{d:"M118.992 1.15771H119.992V0.157715H118.992V1.15771Z"})]}),PS=({className:n})=>b.jsxs("svg",{className:n,width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[b.jsx("path",{d:"M-0.00842285 1.22449H2.99158V0.224487H-0.00842285V1.22449Z"}),b.jsx("path",{d:"M6.14941 1.22449H9.14941V0.224487H6.14941V1.22449Z"}),b.jsx("path",{d:"M15.3073 1.22449H12.3073V0.224487H15.3073V1.22449Z"}),b.jsx("path",{d:"M18.4651 1.22449H21.4651V0.224487H18.4651V1.22449Z"}),b.jsx("path",{d:"M27.6229 1.22449H24.6229V0.224487H27.6229V1.22449Z"}),b.jsx("path",{d:"M30.7808 1.22449H33.7808V0.224487H30.7808V1.22449Z"}),b.jsx("path",{d:"M39.9386 1.22449H36.9386V0.224487H39.9386V1.22449Z"}),b.jsx("path",{d:"M43.0964 1.22449H46.0964V0.224487H43.0964V1.22449Z"}),b.jsx("path",{d:"M52.2543 1.22449H49.2543V0.224487H52.2543V1.22449Z"}),b.jsx("path",{d:"M55.4121 1.22449H58.4121V0.224487H55.4121V1.22449Z"}),b.jsx("path",{d:"M64.5699 1.22449H61.5699V0.224487H64.5699V1.22449Z"}),b.jsx("path",{d:"M67.7278 1.22449H70.7278V0.224487H67.7278V1.22449Z"}),b.jsx("path",{d:"M76.8856 1.22449H73.8856V0.224487H76.8856V1.22449Z"}),b.jsx("path",{d:"M80.0435 1.22449H83.0435V0.224487H80.0435V1.22449Z"}),b.jsx("path",{d:"M89.2013 1.22449H86.2013V0.224487H89.2013V1.22449Z"}),b.jsx("path",{d:"M92.3591 1.22449H95.3591V0.224487H92.3591V1.22449Z"}),b.jsx("path",{d:"M101.517 1.22449H98.517V0.224487H101.517V1.22449Z"}),b.jsx("path",{d:"M104.675 1.22449H107.675V0.224487H104.675V1.22449Z"}),b.jsx("path",{d:"M113.833 1.22449H110.833V0.224487H113.833V1.22449Z"}),b.jsx("path",{d:"M116.99 1.22449H119.99V0.224487H116.99V1.22449Z"})]}),OS=({className:n})=>b.jsxs("svg",{className:n,width:"120",height:"8",viewBox:"0 0 120 8",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[b.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 2.06215H-0.0090332V0.862152H119.991V1.86215Z"}),b.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 6.66215H-0.0090332V5.86215H119.991V6.86215Z"})]}),AS=({className:n})=>b.jsxs("svg",{className:n,width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[b.jsx("path",{d:"M-0.00976562 1.65707H0.990234V0.657074H-0.00976562V1.65707Z"}),b.jsx("path",{d:"M2.32361 1.65707H3.32361V0.657074H2.32361V1.65707Z"}),b.jsx("path",{d:"M5.65698 1.65707H4.65698V0.657074H5.65698V1.65707Z"}),b.jsx("path",{d:"M6.99036 1.65707H7.99036V0.657074H6.99036V1.65707Z"}),b.jsx("path",{d:"M10.3237 1.65707H9.32373V0.657074H10.3237V1.65707Z"}),b.jsx("path",{d:"M11.6571 1.65707H12.6571V0.657074H11.6571V1.65707Z"}),b.jsx("path",{d:"M14.9905 1.65707H13.9905V0.657074H14.9905V1.65707Z"}),b.jsx("path",{d:"M16.3239 1.65707H17.3239V0.657074H16.3239V1.65707Z"}),b.jsx("path",{d:"M19.6572 1.65707H18.6572V0.657074H19.6572V1.65707Z"}),b.jsx("path",{d:"M20.9906 1.65707H21.9906V0.657074H20.9906V1.65707Z"}),b.jsx("path",{d:"M24.324 1.65707H23.324V0.657074H24.324V1.65707Z"}),b.jsx("path",{d:"M25.6573 1.65707H26.6573V0.657074H25.6573V1.65707Z"}),b.jsx("path",{d:"M28.9907 1.65707H27.9907V0.657074H28.9907V1.65707Z"}),b.jsx("path",{d:"M30.3241 1.65707H31.3241V0.657074H30.3241V1.65707Z"}),b.jsx("path",{d:"M33.6575 1.65707H32.6575V0.657074H33.6575V1.65707Z"}),b.jsx("path",{d:"M34.9908 1.65707H35.9908V0.657074H34.9908V1.65707Z"}),b.jsx("path",{d:"M38.3242 1.65707H37.3242V0.657074H38.3242V1.65707Z"}),b.jsx("path",{d:"M39.6576 1.65707H40.6576V0.657074H39.6576V1.65707Z"}),b.jsx("path",{d:"M42.991 1.65707H41.991V0.657074H42.991V1.65707Z"}),b.jsx("path",{d:"M44.3243 1.65707H45.3243V0.657074H44.3243V1.65707Z"}),b.jsx("path",{d:"M47.6577 1.65707H46.6577V0.657074H47.6577V1.65707Z"}),b.jsx("path",{d:"M48.9911 1.65707H49.9911V0.657074H48.9911V1.65707Z"}),b.jsx("path",{d:"M52.3245 1.65707H51.3245V0.657074H52.3245V1.65707Z"}),b.jsx("path",{d:"M53.6578 1.65707H54.6578V0.657074H53.6578V1.65707Z"}),b.jsx("path",{d:"M56.9912 1.65707H55.9912V0.657074H56.9912V1.65707Z"}),b.jsx("path",{d:"M58.3246 1.65707H59.3246V0.657074H58.3246V1.65707Z"}),b.jsx("path",{d:"M61.658 1.65707H60.658V0.657074H61.658V1.65707Z"}),b.jsx("path",{d:"M62.9913 1.65707H63.9913V0.657074H62.9913V1.65707Z"}),b.jsx("path",{d:"M66.3247 1.65707H65.3247V0.657074H66.3247V1.65707Z"}),b.jsx("path",{d:"M67.6581 1.65707H68.6581V0.657074H67.6581V1.65707Z"}),b.jsx("path",{d:"M70.9915 1.65707H69.9915V0.657074H70.9915V1.65707Z"}),b.jsx("path",{d:"M72.3248 1.65707H73.3248V0.657074H72.3248V1.65707Z"}),b.jsx("path",{d:"M75.6582 1.65707H74.6582V0.657074H75.6582V1.65707Z"}),b.jsx("path",{d:"M76.9916 1.65707H77.9916V0.657074H76.9916V1.65707Z"}),b.jsx("path",{d:"M80.325 1.65707H79.325V0.657074H80.325V1.65707Z"}),b.jsx("path",{d:"M81.6583 1.65707H82.6583V0.657074H81.6583V1.65707Z"}),b.jsx("path",{d:"M84.9917 1.65707H83.9917V0.657074H84.9917V1.65707Z"}),b.jsx("path",{d:"M86.3251 1.65707H87.3251V0.657074H86.3251V1.65707Z"}),b.jsx("path",{d:"M89.6584 1.65707H88.6584V0.657074H89.6584V1.65707Z"}),b.jsx("path",{d:"M90.9918 1.65707H91.9918V0.657074H90.9918V1.65707Z"}),b.jsx("path",{d:"M94.3252 1.65707H93.3252V0.657074H94.3252V1.65707Z"}),b.jsx("path",{d:"M95.6586 1.65707H96.6586V0.657074H95.6586V1.65707Z"}),b.jsx("path",{d:"M98.9919 1.65707H97.9919V0.657074H98.9919V1.65707Z"}),b.jsx("path",{d:"M100.325 1.65707H101.325V0.657074H100.325V1.65707Z"}),b.jsx("path",{d:"M103.659 1.65707H102.659V0.657074H103.659V1.65707Z"}),b.jsx("path",{d:"M104.992 1.65707H105.992V0.657074H104.992V1.65707Z"}),b.jsx("path",{d:"M108.325 1.65707H107.325V0.657074H108.325V1.65707Z"}),b.jsx("path",{d:"M109.659 1.65707H110.659V0.657074H109.659V1.65707Z"}),b.jsx("path",{d:"M112.992 1.65707H111.992V0.657074H112.992V1.65707Z"}),b.jsx("path",{d:"M114.325 1.65707H115.325V0.657074H114.325V1.65707Z"}),b.jsx("path",{d:"M117.659 1.65707H116.659V0.657074H117.659V1.65707Z"}),b.jsx("path",{d:"M118.992 1.65707H119.992V0.657074H118.992V1.65707Z"})]}),DS=({className:n})=>b.jsx("svg",{className:n,width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:b.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 2.42035H-0.0090332V0.420349H119.991V2.42035Z"})}),kS=({className:n})=>b.jsxs("svg",{className:n,width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[b.jsx("path",{d:"M-0.0100098 2.47614H1.98999V0.476135H-0.0100098V2.47614Z"}),b.jsx("path",{d:"M3.99014 2.47614H9.99014V0.476135H3.99014V2.47614Z"}),b.jsx("path",{d:"M13.9901 2.47614H11.9901V0.476135H13.9901V2.47614Z"}),b.jsx("path",{d:"M21.1904 2.47614H23.1904V0.476135H21.1904V2.47614Z"}),b.jsx("path",{d:"M31.1906 2.47614H25.1906V0.476135H31.1906V2.47614Z"}),b.jsx("path",{d:"M33.1906 2.47614H35.1906V0.476135H33.1906V2.47614Z"}),b.jsx("path",{d:"M44.3909 2.47614H42.3909V0.476135H44.3909V2.47614Z"}),b.jsx("path",{d:"M46.391 2.47614H52.391V0.476135H46.391V2.47614Z"}),b.jsx("path",{d:"M56.391 2.47614H54.391V0.476135H56.391V2.47614Z"}),b.jsx("path",{d:"M63.5913 2.47614H65.5913V0.476135H63.5913V2.47614Z"}),b.jsx("path",{d:"M73.5915 2.47614H67.5915V0.476135H73.5915V2.47614Z"}),b.jsx("path",{d:"M75.5915 2.47614H77.5915V0.476135H75.5915V2.47614Z"}),b.jsx("path",{d:"M86.7917 2.47614H84.7917V0.476135H86.7917V2.47614Z"}),b.jsx("path",{d:"M88.7919 2.47614H94.7919V0.476135H88.7919V2.47614Z"}),b.jsx("path",{d:"M98.7919 2.47614H96.7919V0.476135H98.7919V2.47614Z"}),b.jsx("path",{d:"M105.992 2.47614H107.992V0.476135H105.992V2.47614Z"}),b.jsx("path",{d:"M115.992 2.47614H109.992V0.476135H115.992V2.47614Z"}),b.jsx("path",{d:"M117.992 2.47614H119.992V0.476135H117.992V2.47614Z"})]}),NS=({className:n})=>b.jsxs("svg",{className:n,width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[b.jsx("path",{d:"M-0.0100098 2.00415H1.98999V0.00415039H-0.0100098V2.00415Z"}),b.jsx("path",{d:"M3.99014 2.00415H9.99014V0.00415039H3.99014V2.00415Z"}),b.jsx("path",{d:"M13.9901 2.00415H11.9901V0.00415039H13.9901V2.00415Z"}),b.jsx("path",{d:"M15.9901 2.00415H17.9901V0.00415039H15.9901V2.00415Z"}),b.jsx("path",{d:"M27.4905 2.00415H25.4905V0.00415039H27.4905V2.00415Z"}),b.jsx("path",{d:"M29.4906 2.00415H35.4906V0.00415039H29.4906V2.00415Z"}),b.jsx("path",{d:"M39.4906 2.00415H37.4906V0.00415039H39.4906V2.00415Z"}),b.jsx("path",{d:"M41.4906 2.00415H43.4906V0.00415039H41.4906V2.00415Z"}),b.jsx("path",{d:"M52.991 2.00415H50.991V0.00415039H52.991V2.00415Z"}),b.jsx("path",{d:"M54.9911 2.00415H60.9911V0.00415039H54.9911V2.00415Z"}),b.jsx("path",{d:"M64.9911 2.00415H62.9911V0.00415039H64.9911V2.00415Z"}),b.jsx("path",{d:"M66.9911 2.00415H68.9911V0.00415039H66.9911V2.00415Z"}),b.jsx("path",{d:"M78.4915 2.00415H76.4915V0.00415039H78.4915V2.00415Z"}),b.jsx("path",{d:"M80.4916 2.00415H86.4916V0.00415039H80.4916V2.00415Z"}),b.jsx("path",{d:"M90.4916 2.00415H88.4916V0.00415039H90.4916V2.00415Z"}),b.jsx("path",{d:"M92.4916 2.00415H94.4916V0.00415039H92.4916V2.00415Z"}),b.jsx("path",{d:"M103.992 2.00415H101.992V0.00415039H103.992V2.00415Z"}),b.jsx("path",{d:"M105.992 2.00415H111.992V0.00415039H105.992V2.00415Z"}),b.jsx("path",{d:"M115.992 2.00415H113.992V0.00415039H115.992V2.00415Z"}),b.jsx("path",{d:"M117.992 2.00415H119.992V0.00415039H117.992V2.00415Z"})]}),VS=({className:n})=>b.jsxs("svg",{className:n,width:"118",height:"3",viewBox:"0 0 118 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[b.jsx("path",{d:"M-0.00854492 2.94815H1.99146V0.948151H-0.00854492V2.94815Z"}),b.jsx("path",{d:"M6.09668 2.94815H8.09668V0.948151H6.09668V2.94815Z"}),b.jsx("path",{d:"M14.2019 2.94815H12.2019V0.948151H14.2019V2.94815Z"}),b.jsx("path",{d:"M18.3071 2.94815H20.3071V0.948151H18.3071V2.94815Z"}),b.jsx("path",{d:"M26.4124 2.94815H24.4124V0.948151H26.4124V2.94815Z"}),b.jsx("path",{d:"M30.5176 2.94815H32.5176V0.948151H30.5176V2.94815Z"}),b.jsx("path",{d:"M38.6228 2.94815H36.6228V0.948151H38.6228V2.94815Z"}),b.jsx("path",{d:"M42.728 2.94815H44.728V0.948151H42.728V2.94815Z"}),b.jsx("path",{d:"M50.8333 2.94815H48.8333V0.948151H50.8333V2.94815Z"}),b.jsx("path",{d:"M54.9385 2.94815H56.9385V0.948151H54.9385V2.94815Z"}),b.jsx("path",{d:"M63.0437 2.94815H61.0437V0.948151H63.0437V2.94815Z"}),b.jsx("path",{d:"M67.1489 2.94815H69.1489V0.948151H67.1489V2.94815Z"}),b.jsx("path",{d:"M75.2542 2.94815H73.2542V0.948151H75.2542V2.94815Z"}),b.jsx("path",{d:"M79.3594 2.94815H81.3594V0.948151H79.3594V2.94815Z"}),b.jsx("path",{d:"M87.4645 2.94815H85.4645V0.948151H87.4645V2.94815Z"}),b.jsx("path",{d:"M91.5697 2.94815H93.5697V0.948151H91.5697V2.94815Z"}),b.jsx("path",{d:"M99.6749 2.94815H97.6749V0.948151H99.6749V2.94815Z"}),b.jsx("path",{d:"M103.78 2.94815H105.78V0.948151H103.78V2.94815Z"}),b.jsx("path",{d:"M111.885 2.94815H109.885V0.948151H111.885V2.94815Z"}),b.jsx("path",{d:"M115.991 2.94815H117.991V0.948151H115.991V2.94815Z"})]}),HS=({className:n})=>b.jsx("svg",{className:n,width:"120",height:"4",viewBox:"0 0 120 4",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:b.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 3.86215H-0.0090332V0.862152H119.991V3.86215Z"})}),WS=({className:n})=>b.jsx("svg",{className:n,width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:b.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 1.15668H-0.0090332V0.156677H119.991V1.15668Z"})});function Gl(n){const{type:o=a.BorderStyleTypes.THIN,className:e}=n;switch(o){case a.BorderStyleTypes.DASH_DOT:return b.jsx(RS,{className:e});case a.BorderStyleTypes.DASH_DOT_DOT:return b.jsx(MS,{className:e});case a.BorderStyleTypes.DASHED:return b.jsx(PS,{className:e});case a.BorderStyleTypes.HAIR:return b.jsx(AS,{className:e});case a.BorderStyleTypes.MEDIUM:return b.jsx(DS,{className:e});case a.BorderStyleTypes.MEDIUM_DASH_DOT:return b.jsx(kS,{className:e});case a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT:return b.jsx(NS,{className:e});case a.BorderStyleTypes.MEDIUM_DASHED:return b.jsx(VS,{className:e});case a.BorderStyleTypes.THICK:return b.jsx(HS,{className:e});case a.BorderStyleTypes.DOUBLE:return b.jsx(OS,{className:e});case a.BorderStyleTypes.THIN:default:return b.jsx(WS,{className:e})}}const LS=[{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},{label:a.BorderStyleTypes.DOUBLE,value:a.BorderStyleTypes.DOUBLE}];function xS(n){var o;if(n)for(const e in n){const t=n[e];if((o=t==null?void 0:t.cl)!=null&&o.rgb)return t.cl.rgb}}function US(n){var o;if(n)for(const e in n){const t=n[e];if((o=t==null?void 0:t.cl)!=null&&o.rgb)return t.s}}function Kl(n){var g;const o=I.useDependency(I.ComponentManager),e=I.useDependency(m.BorderStyleManagerService),t=I.useDependency(m.SheetsSelectionsService),{isAllValuesSame:i,value:r}=t.getCellStylesProperty("bd"),s=i?xS(r):void 0,l=i?US(r):void 0,{onChange:c,value:d}=n;function u(S,f){c==null||c({...d,[f]:S})}function h(S){const f=o.get(S);return f&&b.jsx(f,{className:"univer-fill-primary-600"})}return b.jsxs("section",{className:"univer-box-border univer-grid univer-gap-2 univer-p-1.5",children:[b.jsx("div",{className:"univer-box-border univer-grid univer-grid-cols-5 univer-gap-2 univer-text-gray-600 dark:!univer-text-gray-200",children:wl.map(S=>b.jsx("a",{className:z.clsx("univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-justify-self-center univer-rounded hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",{"univer-bg-gray-200 dark:!univer-bg-gray-600":e.getBorderInfo().type===S.value}),onClick:f=>{f.stopPropagation(),u(S.value,"type")},children:h(S.icon)},S.value))}),b.jsx(z.Separator,{}),b.jsxs("div",{className:"univer-flex univer-items-center univer-gap-2",children:[b.jsx("div",{children:b.jsx(z.Dropdown,{overlay:b.jsx("div",{className:"univer-rounded-lg univer-p-4",children:b.jsx(z.ColorPicker,{value:s,onChange:S=>u(S,"color")})}),children:b.jsxs("button",{className:"univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-rounded univer-border-none univer-bg-transparent univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",type:"button",children:[b.jsx(Ba,{className:"univer-fill-primary-600 dark:!univer-text-white",extend:{colorChannel1:(g=d==null?void 0:d.color)!=null?g:""}}),b.jsx(wn,{className:"dark:!univer-text-white"})]})})}),b.jsx("div",{children:b.jsx(z.Dropdown,{overlay:b.jsx("section",{className:"univer-rounded-lg univer-p-1.5",children:b.jsx("ul",{className:"univer-m-0 univer-grid univer-list-none univer-gap-1 univer-p-0",children:LS.map(S=>b.jsxs("li",{className:"univer-flex univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-px-1 univer-py-3 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",onClick:()=>u(S.value,"style"),children:[S.value===l&&b.jsx(Ut,{className:"univer-absolute univer-left-3 univer-text-primary-600"}),b.jsx(Gl,{className:"univer-ml-6 univer-fill-gray-900 dark:!univer-fill-white",type:S.value})]},S.value))})}),children:b.jsxs("button",{className:"univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-rounded univer-border-none univer-bg-transparent univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",type:"button",children:[b.jsx(Gl,{className:"univer-fill-gray-900 dark:!univer-fill-white",type:l!=null?l:a.BorderStyleTypes.THIN}),b.jsx(wn,{className:"dark:!univer-text-white"})]})})})]})]})}const us="sheets.component.cell-popup";var BS=Object.getOwnPropertyDescriptor,FS=(n,o,e,t)=>{for(var i=t>1?void 0:t?BS(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},jt=(n,o)=>(e,t)=>o(e,t,n);T.SheetCanvasPopManagerService=class extends a.Disposable{constructor(e,t,i,r,s,l,c){super();y(this,"_popupMenuFeatureMap",new Map);y(this,"_isSelectionMoving",!1);this._globalPopupManagerService=e,this._renderManagerService=t,this._univerInstanceService=i,this._refRangeService=r,this._commandService=s,this._refSelectionsService=l,this._selectionManagerService=c,this._initMoving()}_initMoving(){this.disposeWithMe(this._refSelectionsService.selectionMoving$.subscribe(()=>{this._isSelectionMoving=!0})),this.disposeWithMe(this._refSelectionsService.selectionMoveEnd$.subscribe(()=>{this._isSelectionMoving=!1})),this.disposeWithMe(this._selectionManagerService.selectionMoving$.subscribe(()=>{this._isSelectionMoving=!0})),this.disposeWithMe(this._selectionManagerService.selectionMoveEnd$.subscribe(()=>{this._isSelectionMoving=!1}))}registerFeatureMenu(e,t){this._popupMenuFeatureMap.set(e,t)}getFeatureMenu(e,t,i,r){const s=this._popupMenuFeatureMap.get(r);if(s)return s(e,t,i,r)}dispose(){super.dispose(),this._popupMenuFeatureMap.clear()}_createHiddenRectObserver(e){const{row:t,column:i,worksheet:r,skeleton:s,currentRender:l}=e,c=()=>{var Y,j;const g=r.getFreeze(),{startRow:S,startColumn:f,xSplit:v,ySplit:p}=g,C=S-p,_=f-v,{rowHeightAccumulation:w,columnWidthAccumulation:E,rowHeaderWidth:O,columnHeaderHeight:R}=s,P=O+(_===-1?0:E[_+v-1]-((Y=E[_-1])!=null?Y:0)),A=R+(C===-1?0:w[C+p-1]-((j=w[C])!=null?j:0)),k=l.engine.getCanvasElement(),N=k.getBoundingClientRect(),V=hs(k.style.width),L=N.width/V,H=l.scene.getAncestorScale().scaleX,W=P*L*H,B=A*L*H,U={left:-1/0,top:-1/0,right:N.left+W,bottom:N.top+B},X={left:N.left+W,top:-1/0,right:1/0,bottom:N.top+B},F={left:-1/0,top:N.top+B,right:N.left+W,bottom:1/0};return t<S&&i<f?[]:t<S?[U]:i<f?[U]:[U,X,F]},d=c(),u=new D.BehaviorSubject(d),h=new a.DisposableCollection;return h.add(this._commandService.onCommandExecuted(g=>{g.id===m.SetFrozenMutation.id&&u.next(c())})),h.add(a.fromEventSubject(l.engine.onTransformChange$).pipe(D.throttleTime(16)).subscribe(()=>{u.next(c())})),{rects$:u,disposable:h}}_createPositionObserver(e,t,i,r){const s=()=>{const{scene:u}=t,h=rh(e,u,i,r),g=t.engine.getCanvasElement(),S=g.getBoundingClientRect(),f=hs(g.style.width),v=S.width/f;return{left:h.left*v+S.left,right:h.right*v+S.left,top:h.top*v+S.top,bottom:h.bottom*v+S.top}},l=s(),c=new D.BehaviorSubject(l),d=new a.DisposableCollection;return d.add(this._commandService.onCommandExecuted(u=>{ms(u.id)&&c.next(s())})),{position:l,position$:c,disposable:d}}attachPopupToObject(e,t){var w;const i=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),r=i.getActiveSheet();if(!r||this._isSelectionMoving&&!t.showOnSelectionMoving)return{dispose:()=>{},canDispose:()=>!0};const s=i.getUnitId(),l=r.getSheetId(),c=(w=this._renderManagerService.getRenderById(s))==null?void 0:w.with(T.SheetSkeletonManagerService).ensureSkeleton(l),d=this._renderManagerService.getRenderById(s);if(!d||!c)return{dispose:()=>{},canDispose:()=>!0};const{left:u,top:h,width:g,height:S}=e,f={left:u,right:u+g,top:h,bottom:h+S},{position:v,position$:p,disposable:C}=this._createPositionObserver(f,d,c,r),_=this._globalPopupManagerService.addPopup({...t,unitId:s,subUnitId:l,anchorRect:v,anchorRect$:p,canvasElement:d.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(_),p.complete(),C.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==_}}attachPopupByPosition(e,t,i){var C;let r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=r.getActiveSheet();if(!s)return null;const l=r.getUnitId(),c=s.getSheetId();if(l!==i.unitId||i.subUnitId!==c)return null;if(this._isSelectionMoving&&!t.showOnSelectionMoving)return;const d=(C=this._renderManagerService.getRenderById(l))==null?void 0:C.with(T.SheetSkeletonManagerService).getOrCreateSkeleton({sheetId:c}),u=this._renderManagerService.getRenderById(l);if(!u||!d)return null;const{position:h,position$:g,disposable:S}=this._createPositionObserver(e,u,d,s),{rects$:f,disposable:v}=this._createHiddenRectObserver({row:i.row,column:i.col,worksheet:s,skeleton:d,currentRender:u}),p=this._globalPopupManagerService.addPopup({...t,unitId:l,subUnitId:c,anchorRect:h,anchorRect$:g,hiddenRects$:f,canvasElement:u.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(p),g.complete(),S.dispose(),v.dispose(),r=null,s=null},canDispose:()=>this._globalPopupManagerService.activePopupId!==p}}attachPopupToAbsolutePosition(e,t,i,r){var f;const s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),l=s.getActiveSheet();if(!l)return null;const c=s.getUnitId(),d=l.getSheetId();if(i&&c!==i||r&&r!==d)return null;const u=(f=this._renderManagerService.getRenderById(c))==null?void 0:f.with(T.SheetSkeletonManagerService).ensureSkeleton(d),h=this._renderManagerService.getRenderById(c);if(!h||!u)return null;if(this._isSelectionMoving&&!t.showOnSelectionMoving)return;const g=new D.BehaviorSubject(e),S=this._globalPopupManagerService.addPopup({...t,unitId:c,subUnitId:d,anchorRect:e,anchorRect$:g.asObservable(),canvasElement:h.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(S),g.complete()},canDispose:()=>this._globalPopupManagerService.activePopupId!==S}}attachPopupToCell(e,t,i,r,s,l){let c=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d=c.getActiveSheet();if(!d)return null;const u=c.getUnitId(),h=d.getSheetId();if(r&&u!==r||s&&h!==s)return null;const g=this._renderManagerService.getRenderById(u),S=g==null?void 0:g.with(T.SheetSkeletonManagerService).ensureSkeleton(h),f=g==null?void 0:g.with(Ie);if(!g||!S||!f)return null;if(this._isSelectionMoving&&!i.showOnSelectionMoving)return;const v=l!=null?l:Ea(e,t,g.scene,d);if(!v)return null;const{position:p,position$:C,disposable:_,updateRowCol:w}=this._createCellPositionObserver(e,t,g,S,v),{rects$:E,disposable:O}=this._createHiddenRectObserver({row:e,column:t,worksheet:d,skeleton:S,currentRender:g}),R=this._globalPopupManagerService.addPopup({...i,unitId:u,subUnitId:h,anchorRect:p,anchorRect$:C,canvasElement:g.engine.getCanvasElement(),hiddenRects$:E}),P=new a.DisposableCollection;P.add(_),P.add(a.toDisposable(()=>{this._globalPopupManagerService.removePopup(R),C.complete()})),P.add(O);const A={startRow:e,endRow:e,startColumn:t,endColumn:t};return P.add(this._refRangeService.watchRange(u,h,A,(k,N)=>{N?w(N.startRow,N.startColumn):P.dispose()})),{dispose(){P.dispose(),d=null,c=null},canDispose:()=>this._globalPopupManagerService.activePopupId!==R}}attachRangePopup(e,t,i,r,s,l=!1){const c=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d=c.getActiveSheet();if(!d)return null;const u=c.getUnitId(),h=d.getSheetId();if(i&&u!==i||r&&h!==r)return null;const g=this._renderManagerService.getRenderById(u),S=g==null?void 0:g.with(T.SheetSkeletonManagerService).getOrCreateSkeleton({sheetId:h}),f=g==null?void 0:g.with(Ie);if(!g||!S||!f)return null;if(f.selectionMoving&&!l)return;const v=s!=null?s:Ea(e.startRow,e.startColumn,g.scene,d);if(!v)return null;const{position:p,position$:C,disposable:_,updateRange:w,topLeftPos$:E,rightBottomPos$:O}=this._createRangePositionObserver(e,g,S,v),{rects$:R,disposable:P}=this._createHiddenRectObserver({row:e.startRow,column:e.startColumn,worksheet:d,skeleton:S,currentRender:g}),A=this._globalPopupManagerService.addPopup({...t,unitId:u,subUnitId:h,anchorRect:p,anchorRect$:C,canvasElement:g.engine.getCanvasElement(),hiddenRects$:R}),k=new a.DisposableCollection;k.add(_),k.add(a.toDisposable(()=>{this._globalPopupManagerService.removePopup(A),E.complete(),O.complete()})),k.add(P);const N={...e};return k.add(this._refRangeService.watchRange(u,h,N,(V,L)=>{L?w(L):k.dispose()})),{dispose(){k.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==A}}_createCellPositionObserver(e,t,i,r,s){let l=e,c=t;const d=this._calcCellPositionByCell(l,c,i,r,s),u=new D.BehaviorSubject(d),h=()=>u.next(this._calcCellPositionByCell(l,c,i,r,s)),g=new a.DisposableCollection;return g.add(i.engine.clientRect$.subscribe(()=>h())),g.add(a.fromEventSubject(i.engine.onTransformChange$).pipe(D.throttleTime(16)).subscribe(()=>h())),g.add(this._commandService.onCommandExecuted(f=>{if(f.id===m.SetWorksheetRowAutoHeightMutation.id&&f.params.rowsAutoHeightInfo.findIndex(p=>p.row===l)>-1){h();return}ms(f.id)&&h()})),{position$:u,disposable:g,position:d,updateRowCol:(f,v)=>{l=f,c=v,h()}}}_calcCellPositionByCell(e,t,i,r,s){const{scene:l,engine:c}=i;if(r._disposed||l._disposed)return{left:0,right:0,top:0,bottom:0};const d=r.getCellWithCoordByIndex(e,t),u=d.isMergedMainCell?d.mergeInfo:d,{scaleX:h,scaleY:g}=l.getAncestorScale(),S={x:s.viewportScrollX,y:s.viewportScrollY},f=c.getCanvasElement();if(!f)return{left:0,right:0,top:0,bottom:0};const v=f.getBoundingClientRect(),p=hs(f.style.width),{top:C,left:_,width:w}=v,E=w/p;return{left:(u.startX-S.x)*E*h+_,right:(u.endX-S.x)*E*h+_,top:(u.startY-S.y)*E*g+C,bottom:(u.endY-S.y)*E*g+C}}_createRangePositionObserver(e,t,i,r){let{startRow:s,startColumn:l,endRow:c,endColumn:d}=e;const u=this._calcCellPositionByCell(s,l,t,i,r),h=new D.BehaviorSubject(u),g=this._calcCellPositionByCell(c,d,t,i,r),S=new D.BehaviorSubject(g),f=()=>{const w=this._calcCellPositionByCell(s,l,t,i,r),E=this._calcCellPositionByCell(c,d,t,i,r);h.next(w),S.next(E)},v=new a.DisposableCollection;v.add(t.engine.clientRect$.subscribe(()=>f())),v.add(this._commandService.onCommandExecuted(w=>{if(w.id===m.SetWorksheetRowAutoHeightMutation.id&&w.params.rowsAutoHeightInfo.findIndex(O=>O.row===s)>-1){f();return}ms(w.id)&&f()}));const p=w=>{s=w.startRow,l=w.startColumn,c=w.endRow,d=w.endColumn,f()},C=h.pipe(D.map(w=>{const E=this._calcCellPositionByCell(c,d,t,i,r);return{top:w.top,left:w.left,right:E.right,bottom:E.bottom}})),_={top:u.top,left:u.left,right:g.right,bottom:g.bottom};return{position$:C,position:_,updateRange:p,topLeftPos$:h,rightBottomPos$:S,disposable:v}}},T.SheetCanvasPopManagerService=FS([jt(0,a.Inject(I.ICanvasPopupService)),jt(1,M.IRenderManagerService),jt(2,a.IUniverInstanceService),jt(3,a.Inject(m.RefRangeService)),jt(4,a.ICommandService),jt(5,m.IRefSelectionsService),jt(6,a.Inject(m.SheetsSelectionsService))],T.SheetCanvasPopManagerService);function hs(n){return Number.parseInt(n.replace("px",""))}const zS=new Set([$e.id,Ye.id,m.SetSelectionsOperation.id]);function ms(n){return zS.has(n)||m.COMMAND_LISTENER_SKELETON_CHANGE.includes(n)}var XS=Object.getOwnPropertyDescriptor,YS=(n,o,e,t)=>{for(var i=t>1?void 0:t?XS(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},jS=(n,o)=>(e,t)=>o(e,t,n);T.CellPopupManagerService=class extends a.Disposable{constructor(e){super();y(this,"_cellPopupMap",new Map);y(this,"_change$",new D.Subject);y(this,"change$",this._change$.asObservable());this._sheetCanvasPopManagerService=e}_ensureCellPopupMap(e,t){let i=this._cellPopupMap.get(e);i||(i=new Map,this._cellPopupMap.set(e,i));let r=i.get(t);return r||(r=new a.ObjectMatrix,i.set(t,r)),r}showPopup(e,t){var g,S;const{direction:i="horizontal"}=t,{unitId:r,subUnitId:s,row:l,col:c}=e,d=this._ensureCellPopupMap(r,s),u=(g=d.getValue(l,c))==null?void 0:g[i];t.id=(S=t.id)!=null?S:a.generateRandomId();const h=()=>{var C;const f=d.getValue(l,c);if(!f)return;const v=f[i];if(!v)return;const p=v==null?void 0:v.popups.findIndex(_=>_.id===t.id&&_.componentKey===t.componentKey);v==null||v.popups.splice(p,1),v.popups.length===0&&((C=v.disposable)==null||C.dispose(),f[i]=void 0),this._change$.next({...e,direction:i})};if(u)u.popups.push(t),u.popups.sort((f,v)=>f.priority-v.priority);else{const f=this._sheetCanvasPopManagerService.attachPopupToCell(l,c,{...t,direction:i,componentKey:us,extraProps:{...e,direction:i},noPushMinimumGap:!0,autoRelayout:!1,zIndex:90},r,s);d.setValue(l,c,{...d.getValue(l,c),[i]:{disposable:f,popups:[t]}})}return this._change$.next({...e,direction:i}),a.toDisposable(h)}getPopups(e,t,i,r,s){var c,d;return((d=(c=this._ensureCellPopupMap(e,t).getValue(i,r))==null?void 0:c[s])==null?void 0:d.popups)||[]}hidePopup(e,t,i,r){var c,d;const s=this._ensureCellPopupMap(e,t),l=s.getValue(i,r);l&&(l.horizontal&&((c=l.horizontal.disposable)==null||c.dispose(),l.horizontal=void 0,this._change$.next({unitId:e,subUnitId:t,row:i,col:r,direction:"horizontal"})),l.vertical&&((d=l.vertical.disposable)==null||d.dispose(),l.vertical=void 0,this._change$.next({unitId:e,subUnitId:t,row:i,col:r,direction:"vertical"})),!l.horizontal&&!l.vertical&&s.realDeleteValue(i,r))}},T.CellPopupManagerService=YS([jS(0,a.Inject(T.SheetCanvasPopManagerService))],T.CellPopupManagerService);const ql=n=>{const{popup:o}=n,e=o.extraProps,{row:t,col:i,direction:r,unitId:s,subUnitId:l}=e,c=I.useDependency(T.CellPopupManagerService);I.useObservable(x.useMemo(()=>c.change$.pipe(D.filter(h=>h.row===t&&h.col===i&&h.direction===r)),[c,t,i,r]));const d=c.getPopups(s,l,t,i,r),u=I.useDependency(I.ComponentManager);return b.jsx("div",{"data-u-comp":"cell-popup",className:"univer-ml-px univer-flex univer-flex-col",children:d.map(h=>{var S;const g=u.get(h.componentKey);return g?b.jsx(g,{popup:h},(S=h.id)!=null?S:h.componentKey):null})})},Ql=n=>{const{inputId:o,state:e=!1,type:t="range",confirm:i,cancel:r,name:s,formulaOrRefString:l,comment:c="",localSheetId:d=m.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,hidden:u=!1,id:h}=n,S=I.useDependency(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),f=I.useDependency(a.LocaleService),v=I.useDependency(q.IDefinedNamesService),p=I.useDependency(q.IFunctionService),C=I.useDependency(q.LexerTreeBuilder),_=I.useDependency(I.ComponentManager),w=x.useMemo(()=>_.get(Xo),[]),E=x.useMemo(()=>_.get(Li),[]);if(S==null)return;const O=x.useMemo(()=>S.getUnitId(),[]),R=x.useMemo(()=>S.getActiveSheet().getSheetId(),[]),[P,A]=x.useState(s),[k,N]=x.useState(l),[V,L]=x.useState(c),[H,W]=x.useState(d),[B,U]=x.useState(""),[X,F]=x.useState(t),[Y,j]=x.useState(!0),Q=[{label:f.t("definedName.scopeWorkbook"),value:m.SCOPE_WORKBOOK_VALUE_DEFINED_NAME}],oe=ie=>!q.isReferenceStrings(ie);x.useEffect(()=>{j(!0),A(s),L(c),W(d);let ie=l;l.substring(0,1)===q.operatorToken.EQUALS?F("formula"):oe(l)?(F("formula"),ie=q.operatorToken.EQUALS+l):F("range"),N(ie),U("")},[e]),S.getSheetOrders().forEach(ie=>{const se=S.getSheetBySheetId(ie);Q.push({label:(se==null?void 0:se.getName())||"",value:ie})});const re=ie=>{N(ie)},ce=ie=>{N(ie||"")},G=()=>{if(P.length===0){U(f.t("definedName.nameEmpty"));return}if(v.getValueByName(O,P)!=null&&(h==null||h.length===0)){U(f.t("definedName.nameDuplicate"));return}if(!a.Tools.isValidParameter(P)||q.isReferenceStringWithEffectiveColumn(P)||!a.Tools.isStartValidPosition(P)&&!M.hasCJKText(P.substring(0,1))){U(f.t("definedName.nameInvalid"));return}if(S.getSheetOrders().map(te=>{var fe;return((fe=S.getSheetBySheetId(te))==null?void 0:fe.getName())||""}).includes(P)){U(f.t("definedName.nameSheetConflict"));return}if(k.length===0){U(f.t("definedName.formulaOrRefStringEmpty"));return}if(!Y){U(f.t("definedName.formulaOrRefStringInvalid"));return}if(p.hasExecutor(P.toUpperCase())){U(f.t("definedName.nameConflict"));return}const se=S.getActiveSheet().getName();i&&i({id:h||"",name:P,formulaOrRefString:C.convertRefersToAbsolute(k,a.AbsoluteRefType.ALL,a.AbsoluteRefType.ALL,se),comment:V,localSheetId:H})},Z=ie=>{const se=ie;se==="formula"?l[0]===q.operatorToken.EQUALS?N(l):N(`${q.operatorToken.EQUALS}`):l[0]===q.operatorToken.EQUALS?N(""):N(l),F(se)},J=x.useRef(null),[ne,ue]=x.useState(!1);return I.useSidebarClick(ie=>{var te;((te=J.current)==null?void 0:te.isClickOutSide(ie))&&ue(!1)}),b.jsxs("div",{className:z.clsx("univer-grid univer-space-y-2 univer-pb-1",z.borderBottomClassName,{"univer-hidden":!e}),children:[b.jsx("div",{children:b.jsx(z.Input,{className:"univer-w-full",placeholder:f.t("definedName.inputNamePlaceholder"),value:P,allowClear:!0,onChange:A})}),b.jsx("div",{children:b.jsxs(z.RadioGroup,{value:X,onChange:Z,children:[b.jsx(z.Radio,{value:"range",children:f.t("definedName.ratioRange")}),b.jsx(z.Radio,{value:"formula",children:f.t("definedName.ratioFormula")})]})}),X==="range"?w&&b.jsx(w,{unitId:O,subUnitId:R,initialValue:k,onChange:(ie,se)=>re(se),supportAcrossSheet:!0}):E&&b.jsx("div",{className:"univer-relative univer-mt-4 univer-h-full",children:b.jsx("div",{className:"univer-relative univer-h-8 univer-select-none",children:b.jsx(E,{ref:J,className:z.clsx("univer-box-border univer-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-rounded-lg univer-bg-white univer-pt-2 univer-transition-colors hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white [&>div:first-child]:univer-px-2.5 [&>div]:univer-h-5 [&>div]:univer-ring-transparent",z.borderClassName),initValue:k,unitId:O,subUnitId:R,isFocus:ne,isSupportAcrossSheet:!0,onChange:(ie="")=>{ce(ie||"")},onVerify:ie=>{j(ie)},onFocus:()=>ue(!0)})})}),b.jsx("div",{children:b.jsx(z.Select,{className:"univer-w-full",value:H,options:Q,onChange:W})}),b.jsx("div",{children:b.jsx(z.Input,{className:"univer-w-full",placeholder:f.t("definedName.inputCommentPlaceholder"),value:V,onChange:L,allowClear:!0})}),b.jsxs("div",{className:z.clsx("univer-items-center univer-gap-1 univer-text-sm univer-text-red-500",{"univer-hidden":B.length===0,"univer-flex":B.length!==0}),children:[b.jsx("span",{children:B}),b.jsx(br,{})]}),b.jsxs("div",{className:"univer-flex univer-gap-2",children:[b.jsx(z.Button,{onClick:()=>{r==null||r()},children:f.t("definedName.cancel")}),b.jsx(z.Button,{variant:"primary",onClick:G,children:f.t("definedName.confirm")})]})]})},Jl=()=>{const n=I.useDependency(a.ICommandService),e=I.useDependency(a.IUniverInstanceService).getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET),t=I.useDependency(a.LocaleService),i=I.useDependency(q.IDefinedNamesService),r=I.useDependency(m.SheetsSelectionsService);if(e==null)return;const s=e.getUnitId(),l=()=>{const V=i.getDefinedNameMap(s);return V?Array.from(Object.values(V)):[]},[c,d]=x.useState(!1),[u,h]=x.useState(l()),[g,S]=x.useState(null),[f,v]=x.useState();x.useEffect(()=>{const V=i.update$.subscribe(()=>{h(l())});return()=>{V.unsubscribe()}},[]);const p=V=>{const{name:L,formulaOrRefString:H,comment:W,localSheetId:B,hidden:U}=V;let X=V.id;if(X==null||X.length===0)X=a.generateRandomId(10),n.executeCommand(m.InsertDefinedNameCommand.id,{id:X,unitId:s,name:L,formulaOrRefString:H,comment:W,localSheetId:B,hidden:U});else{const F={id:X,unitId:s,name:L,formulaOrRefString:H,comment:W,localSheetId:B,hidden:U};n.executeCommand(m.SetDefinedNameCommand.id,F)}d(!1),S(null)},C=V=>{v(V)};function _(){v(null)}function w(V){const L=i.getValueById(s,V);n.executeCommand(m.RemoveDefinedNameCommand.id,{...L,unitId:s}),v(null)}const E=async V=>{const{formulaOrRefString:L,id:H}=V,W=i.getWorksheetByRef(s,L);if(!W)return;W.isSheetHidden()&&await n.executeCommand(m.SetWorksheetShowCommand.id,{unitId:s,subUnitId:W.getSheetId()}),i.focusRange(s,H)},O=()=>{const V=u.length+1,L=t.t("definedName.defaultName")+V;if(i.getValueByName(s,L)==null)return L;let H=V+1;for(;;){const W=t.t("definedName.defaultName")+H;if(i.getValueByName(s,W)==null)return W;H++}},R=()=>{var W;const V=(W=e.getActiveSheet())==null?void 0:W.getName();if(!V)return"";const L=r.getCurrentSelections();return L==null?"":L.map(B=>q.serializeRangeWithSheet(V,B.range)).join(",")},P=()=>{d(!1),S(null)},A=()=>{d(!0),S(null)},k=V=>{d(!1),S(V)},N=V=>{const L=e.getSheetBySheetId(V);return L==null?"":L.getName()};return b.jsx("div",{"data-u-comp":"defined-name-container",className:"univer-relative univer-box-border univer-w-full",children:b.jsxs("div",{className:z.clsx("univer-w-full univer-overflow-hidden univer-overflow-y-auto",z.scrollbarClassName),children:[b.jsxs("div",{className:"univer-mb-4",children:[b.jsxs(z.Button,{className:z.clsx("univer-w-full",{"univer-hidden":c}),onClick:A,children:[b.jsx(wr,{}),b.jsx("span",{className:"univer-ml-1",children:t.t("definedName.addButton")})]}),c&&b.jsx(Ql,{confirm:p,cancel:P,state:c,inputId:"insertDefinedName",name:O(),formulaOrRefString:R()})]},"insertDefinedName"),u.map((V,L)=>b.jsxs("div",{className:"univer-relative univer-w-full univer-divide-x-0 univer-divide-y univer-divide-solid univer-divide-gray-200 dark:!univer-divide-gray-600",children:[b.jsxs("div",{className:z.clsx("univer-group univer-relative univer-flex univer-w-full univer-cursor-default univer-select-none univer-items-center univer-justify-between univer-rounded-md univer-p-2 hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-700",{"univer-hidden":V.id===g}),onClick:()=>{E(V)},children:[b.jsxs("div",{title:V.comment,children:[b.jsxs("div",{className:"univer-my-1 univer-max-h-[100px] univer-max-w-[190px] univer-truncate univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white",children:[V.name,b.jsx("span",{className:"univer-text-xxs univer-ml-1 univer-text-gray-400",children:V.localSheetId===m.SCOPE_WORKBOOK_VALUE_DEFINED_NAME||V.localSheetId==null?"":N(V.localSheetId)})]}),b.jsx("div",{className:"univer-my-1 univer-max-h-[100px] univer-w-full univer-max-w-[190px] univer-truncate univer-text-xs univer-text-gray-500",title:V.formulaOrRefString,children:V.formulaOrRefString})]}),b.jsxs("div",{className:"univer-absolute univer-right-5 univer-top-1/2 univer-hidden -univer-translate-y-1/2 univer-cursor-pointer univer-items-center univer-justify-end univer-gap-7 univer-text-xs univer-text-primary-600 group-hover:univer-flex dark:hover:!univer-bg-gray-600",children:[b.jsx(z.Tooltip,{title:t.t("definedName.updateButton"),placement:"top",children:b.jsx("a",{className:"univer-rounded univer-p-1 hover:univer-bg-gray-100",onClick:H=>{H.stopPropagation(),k(V.id)},children:b.jsx(Wa,{})})}),b.jsx(z.Tooltip,{title:t.t("definedName.deleteButton"),placement:"top",children:b.jsx("a",{className:"univer-rounded univer-p-1 univer-text-red-600 hover:univer-bg-gray-100",onClick:H=>{H.stopPropagation(),C(V.id)},children:b.jsx(co,{})})})]})]}),b.jsx(z.Confirm,{visible:f===V.id,onClose:_,onConfirm:()=>{w(V.id)},children:t.t("definedName.deleteConfirmText")}),V.id===g&&b.jsx(Ql,{confirm:p,cancel:P,state:V.id===g,id:V.id,inputId:V.id+L,name:V.name,formulaOrRefString:V.formulaOrRefString,comment:V.comment,localSheetId:V.localSheetId})]},L))]})})},$l={id:m.SetRowHiddenCommand.id,preconditions:n=>ae(n),binding:I.KeyCode.Digit9|I.MetaKeys.CTRL_COMMAND},ec={id:m.SetColHiddenCommand.id,preconditions:n=>ae(n),binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT},tc={id:Pe.id,description:"shortcut.sheet.select-below-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN,priority:100,preconditions:ae,staticParameters:{direction:a.Direction.DOWN}},nc={id:Pe.id,description:"shortcut.sheet.select-up-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP,priority:100,preconditions:ae,staticParameters:{direction:a.Direction.UP}},ic={id:Pe.id,description:"shortcut.sheet.select-left-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT,priority:100,preconditions:Gs,staticParameters:{direction:a.Direction.LEFT}},oc={id:Pe.id,description:"shortcut.sheet.select-right-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT,priority:100,preconditions:Gs,staticParameters:{direction:a.Direction.RIGHT}},rc={id:ze.id,description:"shortcut.sheet.select-next-cell",group:"3_sheet-view",binding:I.KeyCode.TAB,priority:100,preconditions:ae,staticParameters:{direction:a.Direction.RIGHT,keycode:I.KeyCode.TAB}},sc={id:ze.id,description:"shortcut.sheet.select-previous-cell",group:"3_sheet-view",binding:I.KeyCode.TAB|I.MetaKeys.SHIFT,priority:100,preconditions:ae,staticParameters:{direction:a.Direction.LEFT,keycode:I.KeyCode.TAB}},ac={id:ze.id,description:"shortcut.sheet.select-below-cell",group:"3_sheet-view",binding:I.KeyCode.ENTER,priority:100,preconditions:ae,staticParameters:{direction:a.Direction.DOWN,keycode:I.KeyCode.ENTER}},lc={id:ze.id,description:"shortcut.sheet.select-up-cell",group:"3_sheet-view",binding:I.KeyCode.ENTER|I.MetaKeys.SHIFT,priority:100,preconditions:ae,staticParameters:{direction:a.Direction.UP,keycode:I.KeyCode.ENTER}},cc={id:Pe.id,description:"shortcut.sheet.select-below-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN|I.MetaKeys.CTRL_COMMAND,preconditions:ae,staticParameters:{direction:a.Direction.DOWN,jumpOver:Fe.moveGap}},dc={id:Pe.id,description:"shortcut.sheet.select-up-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP|I.MetaKeys.CTRL_COMMAND,preconditions:ae,staticParameters:{direction:a.Direction.UP,jumpOver:Fe.moveGap}},uc={id:Pe.id,description:"shortcut.sheet.select-left-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT|I.MetaKeys.CTRL_COMMAND,preconditions:ae,staticParameters:{direction:a.Direction.LEFT,jumpOver:Fe.moveGap}},hc={id:Pe.id,description:"shortcut.sheet.select-right-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT|I.MetaKeys.CTRL_COMMAND,preconditions:ae,staticParameters:{direction:a.Direction.RIGHT,jumpOver:Fe.moveGap}},mc={id:De.id,description:"shortcut.sheet.expand-selection-down",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN|I.MetaKeys.SHIFT,preconditions:ae,staticParameters:{direction:a.Direction.DOWN}},gc={id:De.id,description:"shortcut.sheet.expand-selection-up",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP|I.MetaKeys.SHIFT,preconditions:ae,staticParameters:{direction:a.Direction.UP}},Sc={id:De.id,description:"shortcut.sheet.expand-selection-left",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT|I.MetaKeys.SHIFT,preconditions:ae,staticParameters:{direction:a.Direction.LEFT}},fc={id:De.id,description:"shortcut.sheet.expand-selection-right",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT|I.MetaKeys.SHIFT,preconditions:ae,staticParameters:{direction:a.Direction.RIGHT}},vc={id:De.id,description:"shortcut.sheet.expand-selection-to-below-gap",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ae,staticParameters:{direction:a.Direction.DOWN,jumpOver:Fe.moveGap}},pc={id:De.id,description:"shortcut.sheet.expand-selection-to-up-gap",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ae,staticParameters:{direction:a.Direction.UP,jumpOver:Fe.moveGap}},Cc={id:De.id,description:"shortcut.sheet.expand-selection-to-left-gap",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ae,staticParameters:{direction:a.Direction.LEFT,jumpOver:Fe.moveGap}},Ic={id:De.id,description:"shortcut.sheet.expand-selection-to-right-gap",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ae,staticParameters:{direction:a.Direction.RIGHT,jumpOver:Fe.moveGap}},_c={id:gi.id,description:"shortcut.sheet.select-all",group:"3_sheet-view",binding:I.KeyCode.A|I.MetaKeys.CTRL_COMMAND,preconditions:ae,staticParameters:{expandToGapFirst:!0,loop:!0}},bc={id:Rt.id,description:"shortcut.sheet.set-bold",group:"4_sheet-edit",preconditions:n=>ae(n),binding:I.KeyCode.B|I.MetaKeys.CTRL_COMMAND},wc={id:Mt.id,description:"shortcut.sheet.set-italic",group:"4_sheet-edit",preconditions:n=>ae(n),binding:I.KeyCode.I|I.MetaKeys.CTRL_COMMAND},Ec={id:Pt.id,description:"shortcut.sheet.set-underline",group:"4_sheet-edit",preconditions:n=>ae(n),binding:I.KeyCode.U|I.MetaKeys.CTRL_COMMAND},Tc={id:Ot.id,description:"shortcut.sheet.set-strike-through",group:"4_sheet-edit",preconditions:n=>ae(n),binding:I.KeyCode.X|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND},yc={id:m.ClearSelectionContentCommand.id,preconditions:n=>ae(n),binding:I.KeyCode.DELETE,mac:I.KeyCode.BACKSPACE},Rc={id:m.ClearSelectionContentCommand.id,preconditions:n=>ae(n),mac:I.KeyCode.DELETE},Mc={id:m.ClearSelectionContentCommand.id,preconditions:n=>ae(n),binding:I.MetaKeys.SHIFT+I.KeyCode.BACKSPACE},Pc={id:ji.id,preconditions:n=>ae(n),binding:I.MetaKeys.SHIFT+I.KeyCode.DELETE},Oc={id:In.id,description:"shortcut.sheet.zoom-in",binding:I.KeyCode.EQUAL|I.MetaKeys.CTRL_COMMAND,group:"3_sheet-view",preconditions:ae,priority:1,staticParameters:{delta:.2}},Ac={id:a.NilCommand.id,binding:I.KeyCode.EQUAL|I.MetaKeys.CTRL_COMMAND},Dc={id:In.id,description:"shortcut.sheet.zoom-out",binding:I.KeyCode.MINUS|I.MetaKeys.CTRL_COMMAND,group:"3_sheet-view",preconditions:ae,priority:1,staticParameters:{delta:-.2}},kc={id:a.NilCommand.id,binding:I.KeyCode.MINUS|I.MetaKeys.CTRL_COMMAND},Nc={id:In.id,description:"shortcut.sheet.reset-zoom",binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND,preconditions:ae,group:"3_sheet-view",priority:1,staticParameters:{reset:!0}},Vc={id:a.NilCommand.id,binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND};var ZS=Object.getOwnPropertyDescriptor,GS=(n,o,e,t)=>{for(var i=t>1?void 0:t?ZS(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},St=(n,o)=>(e,t)=>o(e,t,n);T.SheetUIController=class extends a.Disposable{constructor(o,e,t,i,r,s,l,c){super(),this._injector=o,this._componentManager=e,this._layoutService=t,this._commandService=i,this._shortcutService=r,this._menuManagerService=s,this._uiPartsService=l,this._configService=c,this._init()}_init(){this._initComponents(),this._initCommands(),this._initMenus(),this._initShortcuts(),this._initWorkbenchParts(),this._initFocusHandler()}_initComponents(){const o=this._componentManager;this.disposeWithMe(o.register(je,Ol)),this.disposeWithMe(o.register(Vr,Kl)),this.disposeWithMe(o.register(bi,Jl)),this.disposeWithMe(o.register(us,ql)),this.disposeWithMe(o.register("HideGridlinesDoubleIcon",Rr))}_initCommands(){[Gr,gt,qr,Kr,In,De,Pe,ze,_i,ci,un,hn,ei,ti,Le,Sr,gi,oo,m.SetBoldCommand,Lt,Se,Ii,Rt,Mt,Pt,Ot,ur,hr,ni,Ki,qi,ln,cn,Qi,m.SetItalicCommand,m.SetStrikeThroughCommand,m.SetFontFamilyCommand,m.SetFontSizeCommand,di,no,gn,ui,$e,vn,Je,hi,mi,ro,m.SetUnderlineCommand,_n,Ye,vi,li,At,Tt,dn,an,so,dt,en,Ue,fr,ri,kt,Nt,si,ai,Ci,Vt,Ht,pi,pn,Xn,Yn].forEach(o=>{this.disposeWithMe(this._commandService.registerCommand(o))})}_initMenus(){this._menuManagerService.mergeMenu(zl)}_initShortcuts(){[tc,nc,ic,oc,rc,sc,ac,lc,cc,dc,uc,hc,mc,gc,Sc,fc,vc,pc,Cc,Ic,_c,Oc,Dc,Nc,Vc,Ac,kc,bc,wc,Ec,Tc,yc,Rc,Mc,Pc,...nl(),ol,il,rl,ll,cl,dl,hl,sl,al,ul,$l,ec].forEach(o=>{this.disposeWithMe(this._shortcutService.registerShortcut(o))})}_initWorkbenchParts(){const o=this._uiPartsService,e=this._injector;this.disposeWithMe(o.registerComponent(I.BuiltInUIPart.HEADER,()=>I.connectInjector(Qa,e))),this.disposeWithMe(o.registerComponent(I.BuiltInUIPart.FOOTER,()=>I.connectInjector(qa,e))),this.disposeWithMe(o.registerComponent(I.BuiltInUIPart.CONTENT,()=>I.connectInjector(Or,e)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(a.UniverInstanceType.UNIVER_SHEET,o=>{const e=this._injector.get(M.IRenderManagerService),t=this._injector.get(a.IUniverInstanceService),i=M.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_DOC,t,e),r=i==null?void 0:i.with(K.DocSelectionRenderService);r==null||r.focus()}))}},T.SheetUIController=GS([St(0,a.Inject(a.Injector)),St(1,a.Inject(I.ComponentManager)),St(2,I.ILayoutService),St(3,a.ICommandService),St(4,I.IShortcutService),St(5,I.IMenuManagerService),St(6,I.IUIPartsService),St(7,a.IConfigService)],T.SheetUIController);var KS=Object.getOwnPropertyDescriptor,qS=(n,o,e,t)=>{for(var i=t>1?void 0:t?KS(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},An=(n,o)=>(e,t)=>o(e,t,n);const QS=a.createInterceptorKey("statusBarPermissionCorrect");class JS{constructor(){y(this,"_sum",0);y(this,"_count",0);y(this,"_countNumber",0);y(this,"_min",Number.POSITIVE_INFINITY);y(this,"_max",Number.NEGATIVE_INFINITY)}add(o,e,t){if(!a.Tools.isDefine(o==null?void 0:o.v))return;const i=o==null?void 0:o.t;let{v:r}=o;const s=c=>{this._sum+=c,this._countNumber++,this._min=Math.min(this._min,c),this._max=Math.max(this._max,c)},l=(c,d,u)=>{var S;if(!((S=c==null?void 0:c.n)!=null&&S.pattern))return;const{pattern:h}=c.n;u[h]||(u[h]=a.numfmt.getFormatInfo(h)),u[h].isDate&&s(d)};if(typeof r=="string"&&i===a.CellValueType.NUMBER){const c=Number(r);Number.isNaN(c)||(r=c)}if(typeof r=="number"&&i!==a.CellValueType.STRING)s(r);else if(i===a.CellValueType.NUMBER&&o.s){const c=e.get(o.s);l(c,r,t)}this._count++}getResults(){return{sum:this._sum,count:this._countNumber,countA:this._count,min:this._min,max:this._max}}}function $S(n){const{sum:o,count:e,countA:t,min:i,max:r}=n.getResults();return[{func:q.FUNCTION_NAMES_STATISTICAL.MAX,value:r},{func:q.FUNCTION_NAMES_STATISTICAL.MIN,value:i},{func:q.FUNCTION_NAMES_MATH.SUM,value:o},{func:q.FUNCTION_NAMES_STATISTICAL.COUNTA,value:t},{func:q.FUNCTION_NAMES_STATISTICAL.COUNT,value:e},{func:q.FUNCTION_NAMES_STATISTICAL.AVERAGE,value:o/e}]}T.StatusBarController=class extends a.Disposable{constructor(e,t,i,r,s,l){super();y(this,"interceptor",new a.InterceptorManager({STATUS_BAR_PERMISSION_CORRECT:QS}));this._univerInstanceService=e,this._selectionManagerService=t,this._statusBarService=i,this._commandService=r,this._numfmtService=s,this._formulaDataModel=l,this._init()}_init(){this._registerSelectionListener()}_registerSelectionListener(){const e=a.debounce(i=>{var s;const r=(s=i[i.length-1])==null?void 0:s.primary;this._calculateSelection(i.map(l=>l.range),r)},100),t=a.debounce(i=>{var s;const r=(s=i[i.length-1])==null?void 0:s.primary;this._calculateSelection(i.map(l=>l.range),r)},500);this.disposeWithMe(a.toDisposable(this._selectionManagerService.selectionMoving$.subscribe(i=>{i&&t(i)}))),this.disposeWithMe(a.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(i=>{i&&e(i)}))),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===m.SetRangeValuesMutation.id){const r=this._selectionManagerService.getCurrentSelections();r&&e(r)}}))}_clearResult(){this._statusBarService.setState(null)}getRangeStartEndInfo(e,t){return e.rangeType===a.RANGE_TYPE.ALL?{startRow:0,startColumn:0,endRow:t.getRowCount()-1,endColumn:t.getColumnCount()-1}:e.rangeType===a.RANGE_TYPE.COLUMN?{startRow:0,startColumn:e.startColumn,endRow:t.getRowCount()-1,endColumn:e.endColumn}:e.rangeType===a.RANGE_TYPE.ROW?{startRow:e.startRow,startColumn:0,endRow:e.endRow,endColumn:t.getColumnCount()-1}:{startRow:e.startRow,startColumn:e.startColumn,endRow:e.endRow,endColumn:e.endColumn}}_getCellValue(e,t,i,r){var c,d,u,h;const s=i.getCellRaw(e,t),l=(c=r==null?void 0:r[e])==null?void 0:c[t];return l?{t:(d=l.t)!=null?d:s==null?void 0:s.t,v:(u=l.v)!=null?u:s==null?void 0:s.v,s:(h=l.s)!=null?h:s==null?void 0:s.s}:s}_calculateSelection(e,t){var d,u;const i=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!i)return this._clearResult();const r=i.getUnitId(),s=i.getActiveSheet(),l=s==null?void 0:s.getSheetId();if(!l)return this._clearResult();const c={};if(this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getSheets().forEach(h=>{const g=h.getConfig();c[h.getSheetId()]={cellData:new a.ObjectMatrix(g.cellData),rowCount:g.rowCount,columnCount:g.columnCount,rowData:g.rowData,columnData:g.columnData}}),e!=null&&e.length){const h=[];e.forEach(R=>{const{startRow:P,endRow:A}=R;let k=null;for(let N=P;N<=A;N++)s.getRowVisible(N)?k===null&&(k=N):k!==null&&(h.push({...R,startRow:k,endRow:N-1}),k=null);k!==null&&h.push({...R,startRow:k,endRow:A})});const g=a.splitIntoGrid(h),S=new JS,f=i.getStyles(),v={},p=this._formulaDataModel.getArrayFormulaCellData(),C=(d=p==null?void 0:p[r])==null?void 0:d[l];for(const R of g){const{startRow:P,startColumn:A,endColumn:k,endRow:N}=this.getRangeStartEndInfo(R,s);for(let V=P;V<=N;V++)for(let L=A;L<=k;L++){const H=this._getCellValue(V,L,s,C);S.add(H,f,v)}}const _=$S(S);if(_.every(R=>R===void 0))return;let w=null;if(t){const{actualRow:R,actualColumn:P}=t;w=(u=this._numfmtService.getValue(r,l,R,P))==null?void 0:u.pattern}const O={values:_.filter(R=>R!==void 0),pattern:w};this._statusBarService.setState(O)}else this._clearResult()}},T.StatusBarController=qS([An(0,a.IUniverInstanceService),An(1,a.Inject(m.SheetsSelectionsService)),An(2,wi),An(3,a.ICommandService),An(4,a.Inject(m.INumfmtService)),An(5,a.Inject(q.FormulaDataModel))],T.StatusBarController);const Hc=(n=[])=>{const o=I.useDependency(wt);x.useEffect(()=>{const e=n.map(t=>o.addShape({range:t,style:{fill:"rgba(73, 184, 17, 0.05)",strokeWidth:1,stroke:"#49B811",widgets:{}},primary:null}));return()=>{e.forEach(t=>{t&&o.removeShape(t)})}},[n])};var ef=Object.getOwnPropertyDescriptor,tf=(n,o,e,t)=>{for(var i=t>1?void 0:t?ef(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},Wc=(n,o)=>(e,t)=>o(e,t,n);let Dn=class extends a.Disposable{constructor(o,e){super();y(this,"_previousSheetIndex",-1);this._commandService=o,this._univerInstanceService=e,this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{if(t.id===m.RemoveSheetMutation.id)return this._beforeAdjustActiveSheetOnRemoveSheet(t)})),this.disposeWithMe(this._commandService.onCommandExecuted((t,i)=>{if(t.id===m.RemoveSheetMutation.id)return this._adjustActiveSheetOnRemoveSheet(t);if(t.id===m.SetWorksheetHideMutation.id&&t.params.hidden)return this._adjustActiveSheetOnHideSheet(t);if(i!=null&&i.fromCollab)return!1;if(t.id===m.InsertSheetMutation.id)return this._adjustActiveSheetOnInsertSheet(t);if(t.id===m.SetWorksheetHideMutation.id&&!t.params.hidden)return this._adjustActiveSheetOnShowSheet(t);if(t.id===m.SetSelectionsOperation.id)return this._adjustActiveSheetOnSelection(t)}))}_adjustActiveSheetOnHideSheet(o){var c;const{unitId:e,subUnitId:t}=o.params,i=this._univerInstanceService.getUniverSheetInstance(e);if(!i||((c=i.getActiveSheet())==null?void 0:c.getSheetId())!==t)return;const s=i.getActiveSheetIndex(),l=Lc(i,s);this._switchToNextSheet(e,l)}_beforeAdjustActiveSheetOnRemoveSheet(o){const{unitId:e,subUnitId:t}=o.params,i=this._univerInstanceService.getUniverSheetInstance(e);if(!i)return;const r=i.getSheetBySheetId(t);r&&(this._previousSheetIndex=i.getSheetIndex(r))}_adjustActiveSheetOnRemoveSheet(o){if(this._previousSheetIndex===-1)return;const{unitId:e}=o.params,t=this._univerInstanceService.getUniverSheetInstance(e);if(!t)return;if(t.getActiveSheet().getSheetId()===o.params.subUnitId){const r=this._previousSheetIndex,s=r>=1?r-1:0,l=Lc(t,s);this._switchToNextSheet(e,l)}}_adjustActiveSheetOnInsertSheet(o){const{unitId:e,sheet:t}=o.params;this._switchToNextSheet(e,t.id)}_adjustActiveSheetOnShowSheet(o){const{unitId:e,subUnitId:t}=o.params;this._switchToNextSheet(e,t)}_adjustActiveSheetOnSelection(o){var i;const{unitId:e,subUnitId:t}=o.params;t!==((i=this._univerInstanceService.getUnit(e))==null?void 0:i.getActiveSheet().getSheetId())&&this._switchToNextSheet(e,t)}_switchToNextSheet(o,e){this._commandService.executeCommand(m.SetWorksheetActiveOperation.id,{unitId:o,subUnitId:e})}};Dn=tf([Wc(0,a.ICommandService),Wc(1,a.IUniverInstanceService)],Dn);function Lc(n,o){const e=n.getSheetSize();for(let t=o;t>-1;t--){const i=n.getSheetByIndex(t);if(!i.getConfig().hidden)return i.getSheetId()}for(let t=o;t<e;t++){const i=n.getSheetByIndex(t);if(!i.getConfig().hidden)return i.getSheetId()}throw new Error("[ActiveWorksheetController]: could not find the next unhidden sheet! Collaboration error perhaps.")}var nf=Object.getOwnPropertyDescriptor,of=(n,o,e,t)=>{for(var i=t>1?void 0:t?nf(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},xc=(n,o)=>(e,t)=>o(e,t,n),kn=(n=>(n[n.INFO=0]="INFO",n[n.WARNING=1]="WARNING",n[n.ERROR=2]="ERROR",n))(kn||{});T.CellAlertManagerService=class extends a.Disposable{constructor(e,t){super();y(this,"_currentAlert$",new D.Subject);y(this,"_currentAlert",new Map);y(this,"currentAlert$",this._currentAlert$.asObservable());this._renderManagerService=e,this._cellPopupManagerService=t,this.disposeWithMe(()=>{this._currentAlert$.complete()})}get currentAlert(){return this._currentAlert}showAlert(e){var h;let t=this._currentAlert.get(e.key);t&&t.dispose.dispose(),t?t.dispose.dispose():(t={alert:e,dispose:{dispose(){}}},this._currentAlert.set(e.key,t));const{location:i}=e,{row:r,col:s,unitId:l,subUnitId:c}=i;if(!this._renderManagerService.getRenderById(l))return;const u=this._cellPopupManagerService.showPopup({unitId:l,subUnitId:c,row:r,col:s},{componentKey:Uc,direction:"horizontal",extraProps:{alert:e},priority:1});u&&(t&&((h=t.dispose)==null||h.dispose()),t.dispose=u),this._currentAlert$.next(Array.from(this._currentAlert.entries()))}removeAlert(e){const t=this._currentAlert.get(e);t&&(this._currentAlert.delete(e),t==null||t.dispose.dispose(),this._currentAlert$.next(Array.from(this._currentAlert.entries())))}clearAlert(){this._currentAlert.forEach(e=>{e.dispose.dispose()}),this._currentAlert.clear(),this._currentAlert$.next(Array.from(this._currentAlert.entries()))}},T.CellAlertManagerService=of([xc(0,M.IRenderManagerService),xc(1,a.Inject(T.CellPopupManagerService))],T.CellAlertManagerService);function rf({popup:n}){var s;const o=(s=n.extraProps)==null?void 0:s.alert;if(!o)return null;const{type:e,title:t,message:i}=o,r={[kn.ERROR]:b.jsx(br,{className:"univer-mr-1.5 univer-text-red-500"}),[kn.INFO]:b.jsx(Ha,{className:"univer-mr-1.5 univer-text-blue-500"}),[kn.WARNING]:b.jsx(xa,{className:"univer-mr-1.5 univer-text-yellow-500"})};return b.jsxs("div",{className:"univer-z-[100] univer-box-border univer-w-[156px] univer-rounded-lg univer-bg-white univer-px-2 univer-py-1 univer-text-gray-900 univer-shadow dark:!univer-bg-black dark:!univer-text-white",children:[b.jsxs("div",{className:"univer-mb-1.5 univer-flex univer-h-5 univer-flex-row univer-items-center univer-text-sm univer-font-medium",children:[e?r[e]:null,t]}),b.jsx("div",{className:"univer-text-sm",children:i})]})}const Uc="univer.sheet.cell-alert";var sf=Object.getOwnPropertyDescriptor,af=(n,o,e,t)=>{for(var i=t>1?void 0:t?sf(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},lf=(n,o)=>(e,t)=>o(e,t,n);let Co=class extends a.Disposable{constructor(n,o){super(),this._context=n,this._componentManager=o,this._initComponent()}_initComponent(){this.disposeWithMe(this._componentManager.register(Uc,rf))}};Co=af([lf(1,a.Inject(I.ComponentManager))],Co);var cf=Object.getOwnPropertyDescriptor,df=(n,o,e,t)=>{for(var i=t>1?void 0:t?cf(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},Bc=(n,o)=>(e,t)=>o(e,t,n);let Io=class extends a.Disposable{constructor(n,o,e){super(),this._context=n,this._editorBridgeService=o,this._cellPopupManagerService=e,this._initEditorVisibleListener()}_initEditorVisibleListener(){this.disposeWithMe(this._editorBridgeService.visible$.pipe(D.filter(n=>n.visible)).subscribe(()=>{const n=this._editorBridgeService.getEditLocation();n&&this._cellPopupManagerService.hidePopup(n.unitId,n.sheetId,n.row,n.column)}))}};Io=df([Bc(1,me),Bc(2,a.Inject(T.CellPopupManagerService))],Io);var uf=Object.getOwnPropertyDescriptor,hf=(n,o,e,t)=>{for(var i=t>1?void 0:t?uf(o,e):o,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=s(i)||i);return i},_o=(n,o)=>(e,t)=>o(e,t,n);let Nn=class extends a.Disposable{constructor(o,e,t,i){super();y(this,"_isPointer",!1);this._hoverManagerService=o,this._instanceService=e,this._commandService=t,this._renderManagerService=i,this._initPointerEvent(),this._initHover()}get _mainComponent(){var o;return(o=M.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET,this._instanceService,this._renderManagerService))==null?void 0:o.mainComponent}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichText$.subscribe(o=>{var e,t;o!=null&&o.bullet?(this._isPointer||(e=this._mainComponent)==null||e.setCursor(M.CURSOR_TYPE.POINTER),this._isPointer=!0):(this._isPointer&&((t=this._mainComponent)==null||t.setCursor(M.CURSOR_TYPE.AUTO)),this._isPointer=!1)}))}_initPointerEvent(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(o=>{const{location:e,bullet:t}=o;t&&this._commandService.executeCommand(m.ToggleCellCheckboxCommand.id,{unitId:e.unitId,subUnitId:e.subUnitId,row:e.row,col:e.col,paragraphIndex:t.startIndex})}))}};Nn=hf([_o(0,a.Inject(T.HoverManagerService)),_o(1,a.IUniverInstanceService),_o(2,a.ICommandService),_o(3,M.IRenderManagerService)],Nn);const Fc=2,mf=[{value:"DEFAULT_PASTE",label:"rightClick.paste"},{value:"SPECIAL_PASTE_VALUE",label:"rightClick.pasteValue"},{value:"SPECIAL_PASTE_FORMAT",label:"rightClick.pasteFormat"},{value:"SPECIAL_PASTE_COL_WIDTH",label:"rightClick.pasteColWidth"},{value:"SPECIAL_PASTE_BESIDES_BORDER",label:"rightClick.pasteBesidesBorder"},{value:"SPECIAL_PASTE_FORMULA",label:"formula.operation.pasteFormula"}],gf=n=>{var V,L,H,W,B;const o=I.useDependency(a.IUniverInstanceService),e=I.useDependency(M.IRenderManagerService),t=mt();if(!n||!t)return null;const i={startRow:n.rows[0],startCol:n.cols[0],endRow:n.rows[n.rows.length-1],endCol:n.cols[n.cols.length-1]};if(i.endRow<0||i.endCol<0)return null;const r=e.getRenderById(t.getUnitId()),s=r==null?void 0:r.with(T.SheetSkeletonManagerService),l=r==null?void 0:r.with(Ie),c=Ve(o,e);if(!c||!l)return null;const{scene:d}=c,u=s==null?void 0:s.getCurrentSkeleton(),h=l.getViewPort(),g=d==null?void 0:d.scaleX,S=d==null?void 0:d.scaleY,f=d==null?void 0:d.getViewportScrollXY(h),v=(V=d.getEngine())==null?void 0:V.getCanvas();if(!g||!d||!g||!S||!f)return null;const p=u==null?void 0:u.getNoMergeCellPositionByIndex(i.endRow,i.endCol),C=(L=p==null?void 0:p.endX)!=null?L:0,_=(H=p==null?void 0:p.endY)!=null?H:0,w=(W=M.convertTransformToOffsetX(C,g,f))!=null?W:-9999,E=(B=M.convertTransformToOffsetY(_,S,f))!=null?B:-9999,O=v==null?void 0:v.getWidth(),R=v==null?void 0:v.getHeight();if(!O||!R)return null;const P=w+50<=O,A=E+50<=R;let k=w,N=E;return P||(k=O-100),A||(N=R-100),{positionX:k,positionY:N}},Sf=()=>{const n=I.useDependency(Ne),o=I.useObservable(n.showMenu$,!1),e=I.useObservable(n.pasteOptionsCache$,null),t=I.useDependency(a.LocaleService),i=I.useDependency(a.ICommandService),[r,s]=x.useState(!1),[l,c]=x.useState(!1),d=e==null?void 0:e.target.pastedRange,u=gf(d);if(!u||!o||u.positionX<50||u.positionY<30)return null;const h=r||l,g=S=>{c(!1),i.executeCommand(ca.id,{type:S})};return b.jsx("div",{className:"univer-absolute univer-inset-0 univer-z-10 univer-size-0",children:b.jsx("div",{className:"univer-absolute",style:{left:u.positionX+Fc,top:u.positionY+Fc},onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),children:b.jsx(z.DropdownMenu,{align:"start",items:mf.map(S=>({type:"checkbox",value:S.value,label:t.t(S.label),checked:(e==null?void 0:e.pasteType)===ge[S.value],onSelect:()=>g(S.value)})),open:l,onOpenChange:c,children:b.jsxs("div",{className:z.clsx("univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-800",z.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-800":l,"univer-bg-white dark:!univer-bg-gray-900":!l}),children:[b.jsx(Fa,{className:"univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-white"}),h&&b.jsx(wn,{className:"dark:!univer-text-white"})]})})})})},ff=[Se.id,m.SetRangeValuesCommand.id,Ye.id,m.MoveRangeMutation.id,m.RemoveRowMutation.id,m.RemoveColMutation.id,m.InsertRowMutation.id,m.InsertColMutation.id,m.MoveRowsMutation.id,m.MoveColsMutation.id,m.SetWorksheetColWidthMutation.id,m.SetWorksheetRowHeightMutation.id,m.SetSelectionsOperation.id,a.UndoCommandId];function vf(n,o,e,t,i){const r=[],s=[];if(t.copyType===qe.CUT){const{undos:l,redos:c}=pf(n,o,i);r.push(...c),s.push(...l)}else{const{undos:l,redos:c}=Yc(o,e,i);r.push(...c),s.push(...l);const{undos:d,redos:u}=Cf(o,e,i);r.push(...u),s.push(...d);const{undos:h,redos:g}=zc(o,n,e,i);r.push(...g),s.push(...h);const{undos:S,redos:f}=Xc(o,n,e,i,!0);r.push(...f),s.push(...S);const{undos:v,redos:p}=gs(o,e,i);r.push(...p),s.push(...v)}return{undos:s,redos:r}}function pf(n,o,e){let t=[],i=[];const{range:r,subUnitId:s,unitId:l}=n,{range:c,subUnitId:d}=o,u=c?at(c):null,h=r?at(r):null;if(h&&u){const g=e.get(a.IUniverInstanceService),S=e.get(m.SheetInterceptorService),f=g.getUniverSheetInstance(l),v=f==null?void 0:f.getSheetBySheetId(s),p=f==null?void 0:f.getSheetBySheetId(d);if(v&&p){const C=new a.ObjectMatrix,_=new a.ObjectMatrix,w=v.getCellMatrix(),E=p.getCellMatrix();a.Range.foreach(h,(F,Y)=>{C.setValue(F,Y,a.cloneCellData(w.getValue(F,Y))),_.setValue(F,Y,null)});const O=new a.ObjectMatrix;a.Range.foreach(u,(F,Y)=>{O.setValue(F,Y,a.cloneCellData(E.getValue(F,Y)))});const R=new a.ObjectMatrix;a.Range.foreach(h,(F,Y)=>{const j=a.cellToRange(F,Y),Q=a.Rectangle.getRelativeRange(j,h),oe=a.Rectangle.getPositionRange(Q,u);R.setValue(oe.startRow,oe.startColumn,w.getValue(F,Y))});const P={fromRange:h,toRange:u,from:{value:_.getMatrix(),subUnitId:s},to:{value:R.getMatrix(),subUnitId:d},unitId:l},A={fromRange:u,toRange:h,from:{value:C.getMatrix(),subUnitId:s},to:{value:O.getMatrix(),subUnitId:d},unitId:l},k=S.onCommandExecute({id:m.MoveRangeCommand.id,params:{toRange:u,fromRange:h}}),N=v.getMergeData(),V=p.getMergeData(),L=N.filter(F=>a.Rectangle.intersects(F,h)),H=V.filter(F=>a.Rectangle.intersects(F,u)),W=L.map(F=>a.Rectangle.getRelativeRange(F,h)).map(F=>a.Rectangle.getPositionRange(F,u)),B=m.getAddMergeMutationRangeByType(W),U=[{id:m.RemoveWorksheetMergeMutation.id,params:{unitId:l,subUnitId:s,ranges:L}},{id:m.RemoveWorksheetMergeMutation.id,params:{unitId:l,subUnitId:s,ranges:H}},{id:m.AddWorksheetMergeMutation.id,params:{unitId:l,subUnitId:d,ranges:B}}],X=[{id:m.RemoveWorksheetMergeMutation.id,params:{unitId:l,subUnitId:d,ranges:B}},{id:m.AddWorksheetMergeMutation.id,params:{unitId:l,subUnitId:d,ranges:H}},{id:m.AddWorksheetMergeMutation.id,params:{unitId:l,subUnitId:s,ranges:L}}];t=[{id:m.MoveRangeMutation.id,params:P},...k.redos,...U,{id:m.SetSelectionsOperation.id,params:{unitId:l,subUnitId:d,selections:[{range:u}],type:m.SelectionMoveType.MOVE_END}}],i=[{id:m.MoveRangeMutation.id,params:A},...k.undos,...X,{id:m.SetSelectionsOperation.id,params:{unitId:l,subUnitId:s,type:m.SelectionMoveType.MOVE_END,selections:[{range:h}]}}]}}return{undos:i,redos:t}}function zc(n,o,e,t){var f;const{unitId:i,subUnitId:r,range:s}=n,l=(f=t.get(a.IUniverInstanceService).getUniverSheetInstance(i))==null?void 0:f.getSheetBySheetId(r),c=[],d=[],{mapFunc:u}=lt([s]),h=new a.ObjectMatrix;e.forValue((v,p,C)=>{var O,R;const{row:_,col:w}=u(v,p),E={v:C.v,t:C.t};if(!C.p&&C.v&&!o){const P=l==null?void 0:l.getCellStyle(_,w);if(a.isTextFormat((O=P==null?void 0:P.n)==null?void 0:O.pattern))E.t=a.CellValueType.STRING;else{const A=String(C.v),k=a.numfmt.parseValue(A);(k==null?void 0:k.v)!==void 0&&typeof k.v=="number"&&(!k.z&&a.willLoseNumericPrecision(A)?E.t=a.CellValueType.FORCE_STRING:E.v=k.v)}}if((R=C.p)!=null&&R.body&&Dr(C.p.body)){const P={p:a.cloneValue(C.p),v:C.v};h.setValue(_,w,P)}else h.setValue(_,w,E&&a.cloneCellData(E))});const g={unitId:i,subUnitId:r,cellValue:a.cloneCellDataMatrix(h.getMatrix())};c.push({id:m.SetRangeValuesMutation.id,params:g});const S=m.SetRangeValuesUndoMutationFactory(t,g);return d.push({id:m.SetRangeValuesMutation.id,params:S}),{undos:d,redos:c}}function Xc(n,o,e,t,i=!1){var v;const r=[],s=[],{unitId:l,subUnitId:c,range:d}=n,u=(v=t.get(a.IUniverInstanceService).getUniverSheetInstance(l))==null?void 0:v.getSheetBySheetId(c),h=new a.ObjectMatrix,{mapFunc:g}=lt([d]);e.forValue((p,C,_)=>{var A,k;const w={s:Object.assign({},{...a.DEFAULT_STYLES,pd:M.DEFAULT_PADDING_DATA,bg:null,cl:null},_.s)},E=w.s.bd;E&&(Object.keys(E).length>0||(w.s.bd={b:null,l:null,r:null,t:null}));const{row:O,col:R}=g(p,C),P=u==null?void 0:u.getCellStyle(O,R);if(_.v&&!o&&a.isTextFormat((A=P==null?void 0:P.n)==null?void 0:A.pattern))w.s||(w.s={}),w.s.n=P==null?void 0:P.n;else{const N=String(_.v),V=a.numfmt.parseValue(N);V!=null&&V.z&&(w.s||(w.s={}),typeof w.s=="object"&&((k=w.s)!=null&&k.n?w.s.n.pattern=V.z:w.s.n={pattern:V.z}))}h.setValue(O,R,w)});const S={unitId:l,subUnitId:c,cellValue:a.cloneCellDataMatrix(h.getMatrix())};r.push({id:m.SetRangeValuesMutation.id,params:S});const f=m.SetRangeValuesUndoMutationFactory(t,S);return s.push({id:m.SetRangeValuesMutation.id,params:f}),{undos:s,redos:r}}function Yc(n,o,e){const t=[],i=[],r=new a.ObjectMatrix,{unitId:s,subUnitId:l,range:c}=n,{mapFunc:d}=lt([c]);if(o.forEach((u,h)=>{Object.keys(h).forEach(g=>{const S=Number(g),{row:f,col:v}=d(u,S);r.setValue(f,v,{s:null})})}),r.getLength()>0){const u={subUnitId:l,unitId:s,cellValue:a.cloneCellDataMatrix(r.getMatrix())};t.push({id:m.SetRangeValuesMutation.id,params:u});const h=m.SetRangeValuesUndoMutationFactory(e,u);i.push({id:m.SetRangeValuesMutation.id,params:h})}return{undos:i,redos:t}}function Cf(n,o,e){const t=[],i=[],r=new a.ObjectMatrix,{unitId:s,subUnitId:l,range:c}=n,{mapFunc:d}=lt([c]);if(o.forValue((u,h,g)=>{const{row:S,col:f}=d(u,h);r.setValue(S,f,{v:null,p:null})}),r.getLength()>0){const u={subUnitId:l,unitId:s,cellValue:a.cloneCellDataMatrix(r.getMatrix())};t.push({id:m.SetRangeValuesMutation.id,params:u});const h=m.SetRangeValuesUndoMutationFactory(e,u);i.push({id:m.SetRangeValuesMutation.id,params:h})}return{undos:i,redos:t}}function gs(n,o,e){const t=[],i=[],{unitId:r,subUnitId:s,range:l}=n,{startColumn:c,startRow:d,endColumn:u,endRow:h}=at(l),g=[];o.forValue((_,w,E)=>{if(E.rowSpan&&E.rowSpan>1){const O=E.colSpan||1,R={startRow:d+_,endRow:d+_+E.rowSpan-1,startColumn:c+w,endColumn:c+w+O-1};g.push(R)}else if(E.colSpan&&E.colSpan>1){const O=E.rowSpan||1,R={startRow:d+_,endRow:d+_+O-1,startColumn:c+w,endColumn:c+w+E.colSpan-1};g.push(R)}});const f=e.get(a.IUniverInstanceService).getUniverSheetInstance(r),v=f==null?void 0:f.getSheetBySheetId(s);if(f&&v){const w=v.getMergeData().filter(R=>a.Rectangle.intersects({startRow:d,startColumn:c,endRow:h,endColumn:u},R)),E={unitId:r,subUnitId:s,ranges:w};t.push({id:m.RemoveWorksheetMergeMutation.id,params:E});const O=m.RemoveMergeUndoMutationFactory(e,E);i.push({id:m.AddWorksheetMergeMutation.id,params:O})}const p={unitId:r,subUnitId:s,ranges:g};g.length>0&&t.push({id:m.AddWorksheetMergeMutation.id,params:p});const C=m.AddMergeUndoMutationFactory(e,p);return g.length>0&&i.push({id:m.RemoveWorksheetMergeMutation.id,params:C}),{undos:i,redos:t}}function If(n){if(!n.includes("\r")&&a.Tools.isLegalUrl(n)){const t=a.generateRandomId(),i=`${n}`,r={startIndex:0,endIndex:i.length-1,rangeId:t,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:n}};return{dataStream:`${i}\r
13
13
  `,paragraphs:[{startIndex:i.length}],customRanges:[r]}}let o=n.replace(/(\r\n|\n)/g,"\r");o.endsWith(`\r
14
14
  `)||(o+=`\r
15
15
  `);const e=[];for(let t=0;t<o.length;t++)o[t]==="\r"&&e.push({startIndex:t});return{dataStream:o,paragraphs:e,sectionBreaks:[{startIndex:o.indexOf(`