@univerjs/sheets-ui 0.12.3-experimental.20251205-8c9a6bf → 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/cjs/index.js +1 -1
- package/lib/es/index.js +1 -10
- package/lib/index.js +1 -10
- package/lib/umd/index.js +1 -1
- package/package.json +11 -11
package/lib/cjs/index.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
`)}),o}function yu(n){return a.isNotNullOrUndefined(n.displayV)?n.displayV:a.extractPureTextFromCell(n)}function Mu(n,o,e,t){return t.getMergeData().some(r=>r.startRow<=n&&n<r.endRow&&o<=r.startColumn&&r.startColumn<=e)}function Pu(n,o,e,t){return t.getMergeData().some(r=>r.startColumn<=n&&n<r.endColumn&&o<=r.startRow&&r.startRow<=e)}function xu(n){let o=0;return n.forValue((e,t,r)=>{if(r&&o++,o>1)return!1}),o>1}function zn(){return{p:null,v:null,s:null,f:null,si:null,t:null}}const ts=998,Ne={id:I.CopyCommand.id,name:"sheet.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:ts,preconditions:Qi,handler:async n=>n.get(ke).copy()},Oo={id:I.CutCommand.id,name:"sheet.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:ts,preconditions:Qi,handler:async n=>n.get(ke).cut()},Ve={id:I.PasteCommand.id,type:a.CommandType.COMMAND,multi:!0,name:"sheet.command.paste",priority:ts,preconditions:Qi,handler:async(n,o)=>{const t=await n.get(I.IClipboardInterfaceService).read(),r=n.get(ke);return t.length!==0?r.paste(t[0],o==null?void 0:o.value):!1}},to={id:I.SheetPasteShortKeyCommandName,type:a.CommandType.COMMAND,handler:async(n,o)=>{const e=n.get(ke),{htmlContent:t,textContent:r,files:i}=o;return e.legacyPaste(t,r,i),!0}},an={id:"sheet.command.paste-value",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Ve.id,{value:ge.SPECIAL_PASTE_VALUE})},ln={id:"sheet.command.paste-format",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Ve.id,{value:ge.SPECIAL_PASTE_FORMAT})},yt={id:"sheet.command.paste-col-width",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Ve.id,{value:ge.SPECIAL_PASTE_COL_WIDTH})},cn={id:"sheet.command.paste-besides-border",type:a.CommandType.COMMAND,handler:async n=>n.get(a.ICommandService).executeCommand(Ve.id,{value:ge.SPECIAL_PASTE_BESIDES_BORDER})},Ka={id:"sheet.command.optional-paste",type:a.CommandType.COMMAND,handler:async(n,{type:o})=>n.get(ke).rePasteWithPasteType(o)},Dn={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),r=n.get(m.SheetsSelectionsService),i=n.get(a.IUniverInstanceService),s=r.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(i);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.DeleteRangeMoveLeftCommand.id):!0}},Nt={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),r=n.get(m.SheetsSelectionsService),i=n.get(a.IUniverInstanceService),s=r.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(i);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:Nt.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:Nt.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 Ao=(n=>(n.MergeAll="mergeAll",n.MergeVertical="mergeVertical",n.MergeHorizontal="mergeHorizontal",n))(Ao||{});function ut(n,o,e,t,r=!0,i=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-i;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,r&&(l=ut(l,a.Direction.LEFT,e,t,!1)));break;case a.Direction.DOWN:for(c=n.endRow+i;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,r&&(l=ut(l,a.Direction.RIGHT,e,t,!1)));break;case a.Direction.LEFT:for(c=n.startColumn-i;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,r&&(l=ut(l,a.Direction.UP,e,t,!1)));break;case a.Direction.RIGHT:for(c=n.endColumn+i;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,r&&(l=ut(l,a.Direction.DOWN,e,t,!1)));break}return l}function ns(n,o,e){const t={...n},{startRow:r,startColumn:i,endRow:s,endColumn:l}=ir(n,o,e);let c=Xn(e,r,i,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}=Xn(e,h,t.startColumn,h,t.endColumn);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue(p=>{f=Math.min(p,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}=Xn(e,h,t.startColumn,h,t.endColumn);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((p,v,C)=>{f=Math.max(p+(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}=Xn(e,t.startRow,h,t.endRow,h);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((p,v)=>{f=Math.min(v,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}=Xn(e,t.startRow,h,t.endRow,h);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((p,v,C)=>{f=Math.max(v+(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 qa(n,o,e){return ut(n,o,e,void 0,!1,1,!1)}function Ou(n,o,e){const t=ns(n,o,e);return m.alignToMergedCellsBorders(a.Rectangle.union(t,n),e,!0)}function Au(n,o,e){const t=qa(n,o,e),r={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,r),e)}function Du(n,o,e,t){const r=a.getReverseDirection(e),i=ns(ir(n,r,t),e,t);return e===a.Direction.UP&&i.startRow<=n.startRow?m.alignToMergedCellsBorders({...o,startColumn:n.startColumn,endColumn:n.endColumn},t,!0):e===a.Direction.DOWN&&i.endRow>=n.endRow?m.alignToMergedCellsBorders({...o,startColumn:n.startColumn,endColumn:n.endColumn},t,!0):e===a.Direction.LEFT&&i.startColumn<=n.startColumn?m.alignToMergedCellsBorders({...o,startRow:n.startRow,endRow:n.endRow},t,!0):e===a.Direction.RIGHT&&i.endColumn>=n.endColumn?m.alignToMergedCellsBorders({...o,startRow:n.startRow,endRow:n.endRow},t,!0):a.Rectangle.union(a.Rectangle.clone(o),i)}function ku(n,o,e){const t=a.getReverseDirection(o),r=ir(n,t,e),i=ir(n,o,e),s=qa(r,o,e);return m.alignToMergedCellsBorders(a.Rectangle.union(i,s),e,!1)}function Js(n){return{startRow:0,startColumn:0,endRow:n.getRowCount()-1,endColumn:n.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL}}function ir(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 Xn(n,o,e,t,r){let i=!1;const s=n.getMatrixWithMergedCells(o,e,t,r).forValue((l,c,d)=>{if(Vu(d))return i=!0,!1});return{hasValue:i,matrix:s}}function Di(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 Nu(n,o,e){var l,c,d,u;const{primary:t,range:r}=n,i=a.Rectangle.clone(r);switch(o){case a.Direction.UP:case a.Direction.DOWN:i.startRow=(l=t==null?void 0:t.startRow)!=null?l:r.startRow,i.endRow=(c=t==null?void 0:t.endRow)!=null?c:r.startRow;break;case a.Direction.LEFT:case a.Direction.RIGHT:i.startColumn=(d=t==null?void 0:t.startColumn)!=null?d:r.startColumn,i.endColumn=(u=t==null?void 0:t.endColumn)!=null?u:r.startColumn;break}const s=ir(i,o,e);switch(o){case a.Direction.DOWN:return r.startRow<s.startRow;case a.Direction.UP:return r.endRow>s.endRow;case a.Direction.LEFT:return s.endColumn<r.endColumn;case a.Direction.RIGHT:return s.startColumn>r.startColumn}}function Qa(n,o){let e=n[0].startRow,t=n[0].endRow;n.forEach(i=>{const{startRow:s,endRow:l}=i;e=Math.min(e,s),t=Math.max(t,l)});const r=new Array(t-e+1).fill(!1);return o.forEach(i=>{const{startRow:s,endRow:l}=i;for(let c=Math.max(s,e);c<=Math.min(l,t);c++)r[c-e]=!0}),n.every(i=>{const{startRow:s,endRow:l}=i;for(let c=s;c<=l;c++)if(!r[c-e])return!1;return!0})}function Ja(n,o){let e=n[0].startColumn,t=n[0].endColumn;n.forEach(i=>{const{startColumn:s,endColumn:l}=i;e=Math.min(e,s),t=Math.max(t,l)});const r=new Array(t-e+1).fill(!1);return o.forEach(i=>{const{startColumn:s,endColumn:l}=i;for(let c=Math.max(s,e);c<=Math.min(l,t);c++)r[c-e]=!0}),n.every(i=>{const{startColumn:s,endColumn:l}=i;for(let c=s;c<=l;c++)if(!r[c-e])return!1;return!0})}function rs(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 Vu(n){return n.v!==void 0&&n.v!==null&&n.v!==""||n.p!==void 0}const Sr={id:"sheet.command.hide-row-confirm",type:a.CommandType.COMMAND,handler:async n=>{var c;const e=(c=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:c.map(d=>d.range);if(!(e!=null&&e.length))return!1;const t=n.get(a.ICommandService),r=n.get(a.IUniverInstanceService),i=m.getSheetCommandTarget(r);if(!i)return!1;const{worksheet:s}=i,l=s.getVisibleRows();if(Qa(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}},fr={id:"sheet.command.hide-col-confirm",type:a.CommandType.COMMAND,handler:async n=>{var c;const e=(c=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:c.map(d=>d.range);if(!(e!=null&&e.length))return!1;const t=n.get(a.ICommandService),r=n.get(a.IUniverInstanceService),i=m.getSheetCommandTarget(r);if(!i)return!1;const{worksheet:s}=i,l=s.getVisibleCols();if(Ja(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 Bt(n){var c;const o=n.get(a.IUniverInstanceService),e=n.get(ve.DocSelectionManagerService),t=o.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),r=e.getActiveTextRange();if(t==null||r==null)return null;const i=(c=t.getBody())==null?void 0:c.textRuns;if(i==null)return;const{startOffset:s}=r;return i.find(({st:d,ed:u})=>s>=d&&s<=u)}const Ft={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(Q.SetInlineFormatBoldCommand.id):o.executeCommand(m.SetBoldCommand.id)}},jt={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(Q.SetInlineFormatItalicCommand.id):o.executeCommand(m.SetItalicCommand.id)}},zt={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(Q.SetInlineFormatUnderlineCommand.id):o.executeCommand(m.SetUnderlineCommand.id)}},Xt={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(Q.SetInlineFormatStrikethroughCommand.id):o.executeCommand(m.SetStrikeThroughCommand.id)}},os={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(Q.SetInlineFormatSubscriptCommand.id):!1}},is={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(Q.SetInlineFormatSuperscriptCommand.id):!1}},pr={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(Q.SetInlineFormatFontSizeCommand.id,o):e.executeCommand(m.SetFontSizeCommand.id,o)}},Do={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),r=n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED),i=n.get(m.SheetsSelectionsService),s=a.DEFAULT_STYLES.fs,c=o.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet(),d=(h=i.getCurrentLastSelection())==null?void 0:h.primary,u={value:s};if(r){const p=Bt(n);if(p!=null){const v=(S=(g=p.ts)==null?void 0:g.fs)!=null?S:s;u.value=v>=400?400:v+1}return e.executeCommand(Q.SetInlineFormatFontSizeCommand.id,u)}if(d!=null){const v=(f=c.getComposedCellStyle(d.startRow,d.startColumn).fs)!=null?f:s;return u.value=v>=400?400:v+1,e.executeCommand(m.SetFontSizeCommand.id,u)}return!1}},ko={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),r=n.get(a.IContextService).getContextValue(a.EDITOR_ACTIVATED),i=n.get(m.SheetsSelectionsService),s=a.DEFAULT_STYLES.fs,c=o.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet(),d=(h=i.getCurrentLastSelection())==null?void 0:h.primary,u={value:s};if(r){const p=Bt(n);if(p!=null){const v=(S=(g=p.ts)==null?void 0:g.fs)!=null?S:s;u.value=v<=6?6:v-1}return e.executeCommand(Q.SetInlineFormatFontSizeCommand.id,u)}if(d!=null){const v=(f=c.getComposedCellStyle(d.startRow,d.startColumn).fs)!=null?f:s;return u.value=v<=6?6:v-1,e.executeCommand(m.SetFontSizeCommand.id,u)}return!1}},vn={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(Q.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(Q.SetInlineFormatTextColorCommand.id,o):e.executeCommand(m.SetTextColorCommand.id,o)}},No={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),r=n.get(a.ThemeService);return t?o.executeCommand(Q.SetInlineFormatTextColorCommand.id,{value:null}):o.executeCommand(m.SetTextColorCommand.id,{value:r.getColorFromTheme("gray.900")})}},Vt={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),r=n.get(m.SheetsSelectionsService),i=n.get(a.IUniverInstanceService),s=r.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(i);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:Vt.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:Vt.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}},kn={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),r=n.get(m.SheetsSelectionsService),i=n.get(a.IUniverInstanceService),s=r.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(i);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:kn.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 $a=(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))($a||{}),J=(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))(J||{}),Pe=(n=>(n[n.Reader=0]="Reader",n[n.Editor=1]="Editor",n[n.Owner=2]="Owner",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(Pe||{}),et=(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))(et||{}),Ue=(n=>(n[n.SomeCollaborator=0]="SomeCollaborator",n[n.AllCollaborator=1]="AllCollaborator",n[n.OneSelf=2]="OneSelf",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(Ue||{});const sr="UNIVER_SHEET_PERMISSION_PANEL",vr="UNIVER_SHEET_PERMISSION_USER_PART",el="UNIVER_SHEET_PERMISSION_USER_DIALOG",tl="UNIVER_SHEET_PERMISSION_DIALOG",no="UNIVER_SHEET_PERMISSION_USER_DIALOG_ID",ro="UNIVER_SHEET_PERMISSION_DIALOG_ID",Wr={[J.Copy]:"Copy",[J.SetCellStyle]:"SetCellStyle",[J.SetCellValue]:"SetCellValue",[J.SetRowStyle]:"SetRowStyle",[J.SetColumnStyle]:"SetColumnStyle",[J.InsertRow]:"InsertRow",[J.InsertColumn]:"InsertColumn",[J.InsertHyperlink]:"InsertHyperlink",[J.DeleteRow]:"DeleteRow",[J.DeleteColumn]:"DeleteColumn",[J.Sort]:"Sort",[J.Filter]:"Filter",[J.PivotTable]:"PivotTable",[J.EditExtraObject]:"EditExtraObject"},Hu=[J.Copy,J.SetCellStyle,J.SetCellValue,J.SetRowStyle,J.SetColumnStyle,J.InsertRow,J.InsertColumn,J.InsertHyperlink,J.DeleteRow,J.DeleteColumn,J.Sort,J.Filter,J.PivotTable,J.EditExtraObject,J.View],nl="sheet-permission-menu-icon",Wu="sheet-permission-delete-icon",Uu="sheet-permission-edit-icon",Lu="sheet-permission-check-icon",rl="sheet-permission-lock-icon",Bu={unitId:"",subUnitId:"",permissionId:"",unitType:m.UnitObject.SelectRange,id:"",ranges:[],viewState:m.ViewStateEnum.OthersCanView,editState:m.EditStateEnum.OnlyMe};class Ht{constructor(){E(this,"_rule",Bu);E(this,"_visible",!1)}setVisible(o){this._visible=o}getVisible(){return this._visible}reset(){this.setVisible(!1)}}class pt{constructor(){E(this,"_userList",[]);E(this,"_userList$",new O.BehaviorSubject(this._userList));E(this,"userList$",this._userList$.asObservable());E(this,"_oldCollaboratorList",[]);E(this,"_selectUserList",[]);E(this,"_selectUserList$",new O.BehaviorSubject(this._selectUserList));E(this,"selectUserList$",this._selectUserList$.asObservable())}get userList(){return this._userList}setCanEditUserList(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 Be={type:a.CommandType.OPERATION,id:"sheet-permission.operation.openPanel",async handler(n,o={}){const e=n.get(I.ISidebarService),t=n.get(Ht),r=n.get(pt),{showDetail:i=!0,fromSheetBar:s=!1,rule:l,oldRule:c}=o,d={header:{title:"permission.panel.title"},children:{label:sr,showDetail:i,fromSheetBar:s,rule:l,oldRule:c},width:330,onClose:()=>{t.reset(),r.reset()}};return t.setVisible(!0),e.open(d),!0}},Cr={type:a.CommandType.COMMAND,id:"sheet.command.add-range-protection-from-toolbar",async handler(n){return await n.get(a.ICommandService).executeCommand(Be.id,{showDetail:!0}),!0}},Mt={type:a.CommandType.COMMAND,id:"sheet.command.add-range-protection-from-context-menu",async handler(n){return await n.get(a.ICommandService).executeCommand(Be.id,{showDetail:!0}),!0}},Pt={type:a.CommandType.COMMAND,id:"sheet.command.view-sheet-permission-from-context-menu",async handler(n){return await n.get(a.ICommandService).executeCommand(Be.id,{showDetail:!1}),!0}},Ir={type:a.CommandType.COMMAND,id:"sheet.command.add-range-protection-from-sheet-bar",async handler(n){return await n.get(a.ICommandService).executeCommand(Be.id,{fromSheetBar:!0,showDetail:!0}),!0}},_r={type:a.CommandType.COMMAND,id:"sheet.command.view-sheet-permission-from-sheet-bar",async handler(n){return await n.get(a.ICommandService).executeCommand(Be.id,{showDetail:!1}),!0}},xt={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),r=n.get(m.SheetsSelectionsService),i=n.get(m.WorksheetProtectionRuleModel),s=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),l=s.getActiveSheet(),c=s.getUnitId(),d=l.getSheetId(),u=i.getRule(c,d);if(u!=null&&u.permissionId)return o.executeCommand(m.DeleteWorksheetProtectionCommand.id,{unitId:c,subUnitId:d,rule:u});{const g=(h=r.getCurrentLastSelection())==null?void 0:h.range;if(!g)return!1;const p=n.get(m.RangeProtectionRuleModel).getSubunitRuleList(c,d).find(v=>v.ranges.some(C=>a.Rectangle.intersects(C,g)));if(p){const v={unitId:c,subUnitId:d,ruleIds:[p.id]};return await o.executeCommand(m.DeleteRangeProtectionMutation.id,v)&&t.pushUndoRedo({unitID:c,redoMutations:[{id:m.DeleteRangeProtectionMutation.id,params:v}],undoMutations:[{id:m.AddRangeProtectionMutation.id,params:{unitId:c,subUnitId:d,rules:[p]}}]}),!0}else return!1}}},Ot={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),r=n.get(m.WorksheetProtectionRuleModel),i=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=i.getActiveSheet(),l=i.getUnitId(),c=s.getSheetId(),d=r.getRule(l,c);if(d!=null&&d.permissionId){const h={...d,unitId:l,subUnitId:c,ranges:[]};return await o.executeCommand(Be.id,{showDetail:!0,rule:a.Tools.deepClone(h),oldRule:a.Tools.deepClone(h)}),!0}else{const h=(u=t.getCurrentLastSelection())==null?void 0:u.range;if(!h)return!1;const f=n.get(m.RangeProtectionRuleModel).getSubunitRuleList(l,c).find(p=>{var v;return(v=p==null?void 0:p.ranges)==null?void 0:v.some(C=>a.Rectangle.intersects(C,h))});if(f){const p={...f,unitId:l,subUnitId:c};return await o.executeCommand(Be.id,{showDetail:!0,rule:a.Tools.deepClone(p),oldRule:a.Tools.deepClone(p)}),!0}else return!1}}},br={id:"sheet.command.refill",type:a.CommandType.COMMAND,handler:async(n,o)=>n.get(ft).fillData(o.type)},In={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 r=n.get(a.ICommandService),i=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(i);if(!s)return!1;const{worksheet:l}=s,c=l.getVisibleRows();if(Qa(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 r.executeCommand(m.RemoveRowCommand.id,{range:t}),!0}},_n={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 r=n.get(a.ICommandService),i=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(i);if(!s)return!1;const{worksheet:l}=s,c=l.getVisibleCols();if(Ja(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 r.executeCommand(m.RemoveColCommand.id,{range:t}),!0}},Rr={id:"sheet.command.remove-sheet-confirm",type:a.CommandType.COMMAND,handler:async(n,o)=>{const{subUnitId:e}=o,t=n.get(I.IConfirmService),r=n.get(a.ICommandService),i=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:i.t("sheetConfig.deleteSheet")},children:{title:S?i.t("sheetConfig.deleteLargeSheetContent"):i.t("sheetConfig.deleteSheetContent")},cancelText:i.t("button.cancel"),confirmText:i.t("button.confirm")})?(await r.executeCommand(m.RemoveSheetCommand.id,{subUnitId:e}),!0):!1}};var Fu=Object.getOwnPropertyDescriptor,ju=(n,o,e,t)=>{for(var r=t>1?void 0:t?Fu(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Qt=(n,o)=>(e,t)=>o(e,t,n),xe=(n=>(n[n.OFF=0]="OFF",n[n.ONCE=1]="ONCE",n[n.INFINITE=2]="INFINITE",n))(xe||{});const je=a.createIdentifier("univer.format-painter-service");let oo=class extends a.Disposable{constructor(o,e,t,r,i,s){super();E(this,"status$");E(this,"_selectionFormat");E(this,"_markId",null);E(this,"_status$");E(this,"_defaultHook",null);E(this,"_extendHooks",[]);this._selectionManagerService=o,this._themeService=e,this._markSelectionService=t,this._logService=r,this._commandService=i,this._undoRedoService=s,this._status$=new O.BehaviorSubject(0),this.status$=this._status$.asObservable(),this._selectionFormat={styles:new a.ObjectMatrix,merges:[]}}addHook(o){var e,t,r;o.isDefaultHook&&((e=o.priority)!=null?e:0)>((r=(t=this._defaultHook)==null?void 0:t.priority)!=null?r:-1)?this._defaultHook=o:(this._extendHooks.push(o),this._extendHooks.sort((i,s)=>(i.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 r=this.getHooks(),i=[],s=[];r.forEach(c=>{if(c.onApply!==void 0){const d=c.onApply(o,e,t,this._selectionFormat);d&&(i.push(...d.redos),s.push(...d.undos))}});for(const c of r)if(c.onBeforeApply!==void 0&&!c.onBeforeApply({unitId:o,subUnitId:e,range:t,redoMutationsInfo:i,format:this._selectionFormat,undoMutationsInfo:s}))return!1;this._logService.log("[FormatPainterService]","apply mutations",{undoMutationsInfo:s,redoMutationsInfo:i});const l=i.every(c=>this._commandService.executeCommand(c.id,c.params));return l&&this._undoRedoService.pushUndoRedo({unitID:o,undoMutations:s,redoMutations:i}),l}_updateRangeMark(o){if(this._markSelectionService.removeAllShapes(),o!==0){const e=this._selectionManagerService.getCurrentLastSelection();if(e){const t=Xa(this._themeService);o===2?this._markId=this._markSelectionService.addShape({...e,style:t}):this._markId=this._markSelectionService.addShape({...e,style:t},[m.SetRangeValuesMutation.id])}}}};oo=ju([Qt(0,a.Inject(m.SheetsSelectionsService)),Qt(1,a.Inject(a.ThemeService)),Qt(2,Lt),Qt(3,a.ILogService),Qt(4,a.ICommandService),Qt(5,a.IUndoRedoService)],oo);const wr={id:"sheet.operation.set-format-painter",type:a.CommandType.OPERATION,handler:(n,o)=>o?(n.get(je).setStatus(o.status),!0):!1},Vo={type:a.CommandType.COMMAND,id:"sheet.command.set-infinite-format-painter",handler:async n=>{const e=n.get(je).getStatus();let t;return e!==xe.OFF?t=xe.OFF:t=xe.INFINITE,n.get(a.ICommandService).executeCommand(wr.id,{status:t})}},Nn={type:a.CommandType.COMMAND,id:"sheet.command.set-once-format-painter",handler:async n=>{const e=n.get(je).getStatus();let t;return e!==xe.OFF?t=xe.OFF:t=xe.ONCE,n.get(a.ICommandService).executeCommand(wr.id,{status:t})}},Er={type:a.CommandType.COMMAND,id:"sheet.command.apply-format-painter",handler:async(n,o)=>n.get(je).applyFormatPainter(o.unitId,o.subUnitId,o.range)};var zu=Object.getOwnPropertyDescriptor,Xu=(n,o,e,t)=>{for(var r=t>1?void 0:t?zu(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Yu=(n,o)=>(e,t)=>o(e,t,n);exports.SheetScrollManagerService=class{constructor(o,e){E(this,"_scrollStateMap",new Map);E(this,"_rawScrollInfo$",new O.BehaviorSubject(null));E(this,"rawScrollInfo$",this._rawScrollInfo$.asObservable());E(this,"validViewportScrollInfo$",new O.BehaviorSubject(null));E(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:r,offsetY:i}=o;t=t||0,i=i||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)+r,u=l+i;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:r,sheetViewStartRow:i,offsetX:s,offsetY:l}=o;this._scrollStateMap.has(e)||this._scrollStateMap.set(e,new Map);const c=this._scrollStateMap.get(e),d={sheetViewStartRow:i,sheetViewStartColumn:r,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:r}=o;return((s=this._scrollStateMap.get(t))==null?void 0:s.get(r))||e}_emitRawScroll(o){this._rawScrollInfo$.next(o)}};exports.SheetScrollManagerService=Xu([Yu(1,a.Inject(exports.SheetSkeletonManagerService))],exports.SheetScrollManagerService);const nt={type:a.CommandType.COMMAND,id:"sheet.command.set-selection-frozen",handler:async(n,o)=>{const{type:e}=o||{},t=n.get(a.IUniverInstanceService),r=n.get(a.IUndoRedoService),i=m.getSheetCommandTarget(t);if(!i)return!1;const{unitId:s,subUnitId:l}=i,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(y.IRenderManagerService).getRenderById(s).with(exports.SheetScrollManagerService),{sheetViewStartRow:p=0,sheetViewStartColumn:v=0}=f.getCurrentScrollState()||{};let C,_,R,w;const{startRow:P,startColumn:T,rangeType:M}=g;if(M===a.RANGE_TYPE.ROW||e===1)C=P,R=P-p,_=-1,w=0;else if(M===a.RANGE_TYPE.COLUMN||e===2)C=-1,R=0,_=T,w=T-v;else if(M===a.RANGE_TYPE.NORMAL)C=P,R=P-p,_=T,w=T-v;else return!1;const x={unitId:s,subUnitId:l,startRow:C,startColumn:_,xSplit:_>0?Math.max(1,w):w,ySplit:C>0?Math.max(1,R):R},A=m.SetFrozenMutationFactory(n,x);return c.syncExecuteCommand(m.SetFrozenMutation.id,x)&&r.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetFrozenMutation.id,params:A}],redoMutations:[{id:m.SetFrozenMutation.id,params:x}]}),!0}},Tr={type:a.CommandType.COMMAND,id:"sheet.command.set-row-frozen",handler:async n=>(n.get(a.ICommandService).executeCommand(nt.id,{type:1}),!0)},yr={type:a.CommandType.COMMAND,id:"sheet.command.set-col-frozen",handler:async n=>(n.get(a.ICommandService).executeCommand(nt.id,{type:2}),!0)};class ss extends a.Disposable{constructor(){super(...arguments);E(this,"rangesStack",[]);E(this,"selectedRangeWorksheet","")}}var Zu=Object.getOwnPropertyDescriptor,Gu=(n,o,e,t)=>{for(var r=t>1?void 0:t?Zu(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},$s=(n,o)=>(e,t)=>o(e,t,n);let bn=class{constructor(n,o){E(this,"_current",null);E(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)}};bn=Gu([$s(0,a.IUniverInstanceService),$s(1,a.Inject(a.LocaleService))],bn);var ze=(n=>(n[n.moveStopeOne=0]="moveStopeOne",n[n.moveGap=1]="moveGap",n[n.moveStepPage=2]="moveStepPage",n[n.moveStepEnd=3]="moveStepEnd",n))(ze||{});const Me={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:r}=e,i=m.getSelectionsService(n,o.fromCurrentSelection).getCurrentLastSelection();if(!i)return!1;const{direction:s,jumpOver:l,extra:c}=o,{range:d,primary:u}=i,h=Di(d,u,s),g=l===1?ns(h,s,r):ut(h,s,r),S=m.getCellAtRowCol(g.startRow,g.startColumn,r);if(a.Rectangle.equals(S,h))return!1;const f=t.getUnitId();n.get(bn).remove({unitId:f,sheetId:r.getSheetId(),keycode:I.KeyCode.TAB});const p=[{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:r.getSheetId(),selections:p,type:m.SelectionMoveType.MOVE_END,extra:c,reveal:!0})}},Xe={id:"sheet.command.move-selection-enter-tab",type:a.CommandType.COMMAND,handler:(n,o)=>{var L;if(!o)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{workbook:t,worksheet:r}=e,i=m.getSelectionsService(n),{direction:s,keycode:l}=o,c=s===a.Direction.LEFT||s===a.Direction.UP,d=i.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),p=t.getUnitId(),v=r.getSheetId();if(!h)return!1;const{range:C}=h,_=h.primary;let R=Di(C,_,s);const w=n.get(bn),P=w.getCurrentBySearch({unitId:p,sheetId:v,keycode:I.KeyCode.TAB});let T;const{startRow:M,endRow:x,startColumn:A,endColumn:D}=C,k=c?_.startRow===M&&_.startColumn===A:_.endRow===x&&_.endColumn===D;if(a.Rectangle.equals(C,_)){if(l===I.KeyCode.TAB)P==null&&w.addOrUpdate({unitId:p,sheetId:v,keycode:I.KeyCode.TAB,selection:h});else{const B=P==null?void 0:P.selection;if(B!=null){const{range:z,primary:X}=B;R=Di(z,X,s)}w.remove({unitId:p,sheetId:v,keycode:I.KeyCode.TAB})}const U=ut(R,s,r),F=m.getCellAtRowCol(U.startRow,U.startColumn,r);if(a.Rectangle.equals(F,R))return!1;T={range:a.Rectangle.clone(F),primary:{startRow:F.startRow,startColumn:F.startColumn,endRow:F.endRow,endColumn:F.endColumn,actualRow:U.startRow,actualColumn:U.startColumn,isMerged:F.isMerged,isMergedMainCell:F.startRow===U.startRow&&F.startColumn===U.startColumn}}}else{w.remove({unitId:p,sheetId:v,keycode:I.KeyCode.TAB});const U=a.Tools.deepClone(_),F=k?S.range:ut({startRow:U.startRow,startColumn:U.startColumn,endRow:U.endRow,endColumn:U.endColumn},s,r,{startRow:M,endRow:x,startColumn:A,endColumn:D}),B=k&&c,z=B?m.getCellAtRowCol(F.endRow,F.endColumn,r):m.getCellAtRowCol(F.startRow,F.startColumn,r);T={range:k?S.range:a.Rectangle.clone(C),primary:{startRow:z.startRow,startColumn:z.startColumn,endRow:z.endRow,endColumn:z.endColumn,actualRow:B?z.startRow:F.startRow,actualColumn:B?z.startColumn:F.startColumn,isMerged:z.isMerged,isMergedMainCell:z.startRow===F.startRow&&z.startColumn===F.startColumn},style:k?S.style:h.style}}k?(d[u].primary=null,d[f]=T,i.setSelections(p,v,[],m.SelectionMoveType.MOVE_END)):d[u]=T;const H=n.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:p,subUnitId:v,type:m.SelectionMoveType.MOVE_END,selections:d,reveal:!0,extra:o.extra}),V=(L=n.get(y.IRenderManagerService).getRenderById(p))==null?void 0:L.with(Ce);return V==null||V.refreshSelectionMoveEnd(),H}},Oe={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:r,subUnitId:i}=e,s=m.getSelectionsService(n).getCurrentLastSelection();if(!s)return!1;const{range:l,primary:c}=s,{jumpOver:d,direction:u,extra:h}=o,S=Nu(s,u,t)?d===1?Du(l,{...a.Rectangle.clone(c),rangeType:a.RANGE_TYPE.NORMAL},u,t):ku(l,u,t):d===1?Ou(l,u,t):Au(l,u,t);return S.rangeType=s.range.rangeType,a.Rectangle.equals(S,l)?!1:n.get(a.ICommandService).syncExecuteCommand(m.SetSelectionsOperation.id,{unitId:r,subUnitId:i,type:m.SelectionMoveType.MOVE_END,selections:[{range:S,primary:c}],extra:h,reveal:!0})}},Mr={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 r=n.get(ss),{worksheet:i,unitId:s,subUnitId:l}=e,c=`${s}|${l}`;c!==r.selectedRangeWorksheet&&(r.rangesStack=[],r.selectedRangeWorksheet=c);const d=i.getMaxRows(),u=i.getMaxColumns(),{expandToGapFirst:h,loop:g}=o,{range:S,primary:f}=t,p=S.endColumn===u-1&&S.endRow===d-1&&S.startRow===0&&S.startColumn===0;r.rangesStack.some(P=>a.Rectangle.equals(P,S))||(r.rangesStack=[],r.rangesStack.push(S));let v;if(p)if(g){if(r.rangesStack.findIndex(T=>a.Rectangle.equals(T,S))!==r.rangesStack.length-1)return!1;v=r.rangesStack[0]}else return!1;else h?(v=m.expandToContinuousRange(S,{left:!0,right:!0,up:!0,down:!0},i),a.Rectangle.equals(v,S)&&(v=Js(i))):v=Js(i);r.rangesStack.some(P=>a.Rectangle.equals(P,v))||r.rangesStack.push(v);const C=[];C.push({id:m.SetSelectionsOperation.id,params:{unitId:s,subUnitId:l,reveal:!0,selections:[{range:v,primary:f}]}});const R=n.get(m.SheetInterceptorService).onCommandExecute({id:Mr.id,params:{range:S}});R.redos.length&&C.push(...R.redos);const w=n.get(a.ICommandService);return a.sequenceExecute(C,w),!0}};function Ku(n){return typeof n.isMainScene>"u"}function De(n,o){const e=n instanceof a.Workbook?n:n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!e)return null;const t=e.getUnitId();let r,i,s,l;if(Ku(o)){const g=o.getRenderById(t);if(g==null)return null;r=g.components,r=g.components,i=g.mainComponent,s=g.scene,l=g.engine}else r=o.components,i=o.mainComponent,s=o.scene,l=o.engine;if(!r||!i)return null;const c=i,d=r.get(ue.ROW),u=r.get(ue.COLUMN),h=r.get(ue.LEFT_TOP);return{spreadsheet:c,spreadsheetRowHeader:d,spreadsheetColumnHeader:u,spreadsheetLeftTopPlaceholder:h,scene:s,engine:l}}function ki(n,o,e,t){const{startX:r,startY:i,endX:s,endY:l}=t.getCellWithCoordByIndex(n,o);return{startX:r,startY:i,endX:s,endY:l}}function Fe(n,o,e,t,r,i){const s=e.getCoordRelativeToViewport(y.Vector2.FromArray([n,o])),{x:l,y:c}=s,d=e.getScrollXYInfoByViewport(s,r),{scaleX:u,scaleY:h}=e.getAncestorScale(),g=t.getCellIndexByOffset(l,c,u,h,d,{closeFirst:i}),{row:S,column:f}=g,p=t.getNoMergeCellWithCoordByIndex(S,f),{startX:v,startY:C,endX:_,endY:R}=p;return{startX:v,startY:C,endX:_,endY:R,row:S,column:f}}function nr(n,o,e,t){const r=e.getCoordRelativeToViewport(y.Vector2.FromArray([n,o])),i=e.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN),s=e.getScrollXYInfoByViewport(r,i),{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 qu=Object.getOwnPropertyDescriptor,Qu=(n,o,e,t)=>{for(var r=t>1?void 0:t?qu(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Jt=(n,o)=>(e,t)=>o(e,t,n);Me.id,Xe.id;const Ju=3;exports.SheetsScrollRenderController=class extends a.Disposable{constructor(o,e,t,r,i,s,l){super(),this._context=o,this._injector=e,this._sheetSkeletonManagerService=t,this._contextService=r,this._commandService=i,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(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);e&&this.disposeWithMe(o.onMouseWheel$.subscribeEvent((t,r)=>{if(t.ctrlKey||!this._contextService.getContextValue(a.FOCUSING_SHEET))return;let i=0,s=0;i=t.deltaX,t.shiftKey?i=(t.deltaY||t.deltaX)*Ju:s=t.deltaY,this._commandService.executeCommand(Rn.id,{offsetX:i,offsetY:s}),this._context.scene.makeDirty(!0);const l=e.limitedScroll(e.scrollX+i,e.scrollY+s);l&&!l.isLimitedX&&!l.isLimitedY&&(t.preventDefault(),o.getParent().classType===y.RENDER_CLASS_TYPE.SCENE_VIEWER&&r.stopPropagation()),e.isWheelPreventDefaultX&&e.isWheelPreventDefaultY&&t.preventDefault()}))}_scrollBarEventListener(){const{scene:o}=this._context;if(o==null)return;const e=o.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);e&&(this.disposeWithMe(a.toDisposable(this._scrollManagerService.rawScrollInfo$.subscribe(t=>{var f;const r=(f=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:f.skeleton;if(!r)return;if(t==null){e.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});return}const{sheetViewStartRow:i,sheetViewStartColumn:s,offsetX:l,offsetY:c,duration:d}=t,{startX:u,startY:h}=r.getCellWithCoordByIndex(i,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 p;const r=(p=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:p.skeleton;if(r==null||t.isTrigger===!1)return;const i=this._getSheetObject();if(r==null||i==null)return;const{viewportScrollX:s,viewportScrollY:l,scrollX:c,scrollY:d}=t,{row:u,column:h,rowOffset:g,columnOffset:S}=r.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 r=(g=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:g.skeleton;if(r==null||t.isTrigger===!1)return;const i=this._getSheetObject();if(r==null||i==null)return;const{viewportScrollX:s=0,viewportScrollY:l=0}=t;this._getFreeze();const{row:c,column:d,rowOffset:u,columnOffset:h}=r.getOffsetRelativeToRowCol(s,l);this._commandService.executeCommand(He.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 r=this._scrollManagerService.getScrollStateByParam(e),{viewportScrollX:i,viewportScrollY:s}=this._scrollManagerService.calcViewportScrollFromRowColOffset(r);r&&this._updateViewportScroll(i,s)})))}_smoothScrollToViewportPos(o){const{viewportMain:e,viewportScrollX:t,viewportScrollY:r,duration:i}=o,s=performance.now(),l=e.viewportScrollX,c=e.viewportScrollY,d=t-l,u=r-c;function h(g){const S=g-s,f=Math.min(S/i,1),p=1-(1-f)**3,v=l+d*p,C=c+u*p;e.scrollToViewportPos({viewportScrollX:v,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 r=t.scene,i=r.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN),s=r.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT),l=r.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM),c=r.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT),d=r.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);i&&(i.viewportScrollX=o,i.viewportScrollY=e),l&&(l.viewportScrollY=e),s&&(s.viewportScrollX=o),c&&(c.viewportScrollY=e),d&&(d.viewportScrollX=o)}scrollToRange(o,e,t){let{endRow:r,endColumn:i,startColumn:s,startRow:l}=o;const c=this._getViewportBounding();if(o.rangeType===a.RANGE_TYPE.ROW?(s=0,i=0):o.rangeType===a.RANGE_TYPE.COLUMN&&(l=0,r=0),c&&!e&&!t){const d=c.startRow>r?l:r,u=c.startColumn>i?s:i;return this._scrollToCell(d,u)}else return this._scrollToCell(l,s,e,t)}scrollToCell(o,e,t){const r=this._context.unit.getActiveSheet(),{ySplit:i,xSplit:s}=r.getFreeze();return this._commandService.syncExecuteCommand(He.id,{sheetViewStartRow:o-i,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 Oe.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:r,endRow:i,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=i:i<u?g=t:g=c,r>d?S=s:s<h?S=r:S=d,o.direction===a.Direction.DOWN?g=i:o.direction===a.Direction.UP?g=t:o.direction===a.Direction.RIGHT?S=s:o.direction===a.Direction.LEFT&&(S=r),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,r=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.scene;if(t==null||r==null)return;const{rowTotalHeight:i,columnTotalWidth:s,rowHeaderWidthAndMarginLeft:l,columnHeaderHeightAndMarginTop:c}=t;this._context.unit.getActiveSheet()&&(r==null||r.transformByState({width:l+s,height:c+i}))}_getSheetObject(){return De(this._context.unit,this._context)}_scrollToSelectionByDirection(o){const e=this._getViewportBounding();if(e==null)return!1;const{startRow:t,startColumn:r,endRow:i,endColumn:s}=e;let l=0,c=0;const{startRow:d,startColumn:u,endRow:h,endColumn:g}=o;d>=t&&(l=h),h<=i&&(l=d),u>=r&&(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:r,actualRow:i,actualColumn:s}=(d=e.primary)!=null?d:e.range,l=o&&i!=null?i:t,c=o&&s!=null?s:r;this._scrollToCell(l,c)}_getSelectionsService(){return m.getSelectionsService(this._injector)}_getViewportBounding(){var i,s;const o=(i=this._getSheetObject())==null?void 0:i.scene;if(o==null)return;const e=o.getViewport(y.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 r=e.calcViewportInfo();return t.getRangeByViewBound(r.viewBound)}_scrollToCell(o,e,t=!1,r=!1){var D,k,H;const{rowHeightAccumulation:i,columnWidthAccumulation:s}=(D=this._sheetSkeletonManagerService.getCurrentSkeleton())!=null?D:{};if(i==null||s==null)return!1;const l=(k=this._getSheetObject())==null?void 0:k.scene;if(l==null)return!1;const c=l.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(c==null)return!1;const d=(H=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:H.skeleton;if(d==null)return!1;const u=this._context.unit.getActiveSheet();if(!u)return!1;o=a.Tools.clamp(o,0,i.length-1),e=a.Tools.clamp(e,0,s.length-1);const{startColumn:h,startRow:g,ySplit:S,xSplit:f}=u.getFreeze(),p=this._getViewportBounding();if(p==null)return!1;const{startRow:v,startColumn:C,endRow:_,endColumn:R}=p;let w,P;if(o>=g&&e>=h-S&&(o<=v&&(w=o,t=!0),o>=_)){const N=i[o]-c.height;for(let V=v;V<=o&&(w=V+1,!(i[V]>=N));V++);}if(e>=h&&o>=g-S&&(e<=C&&(P=e,r=!0),e>=R)){const N=s[e]-c.width;for(let V=C;V<=e&&(P=V+1,!(s[V]>=N));V++);}if(w===void 0&&P===void 0)return!1;let{offsetX:T,offsetY:M,sheetViewStartRow:x,sheetViewStartColumn:A}=this._scrollManagerService.getCurrentScrollState()||{};if(w=w?Math.min(w,o):x+S,P=P?Math.min(P,e):A+f,r){T=0,P=e;const N=d.getHiddenColumnsInRange({startColumn:P-f,endColumn:P});P=P-N.length}if(t){M=0,w=o;const N=d.getHiddenRowsInRange({startRow:w-S,endRow:w});w=w-N.length}return this._commandService.syncExecuteCommand(He.id,{sheetViewStartRow:Math.max(0,w-S),sheetViewStartColumn:Math.max(0,P-f),offsetX:T,offsetY:M})}};exports.SheetsScrollRenderController=Qu([Jt(1,a.Inject(a.Injector)),Jt(2,a.Inject(exports.SheetSkeletonManagerService)),Jt(3,a.IContextService),Jt(4,a.ICommandService),Jt(5,y.IRenderManagerService),Jt(6,a.Inject(exports.SheetScrollManagerService))],exports.SheetsScrollRenderController);const rt={id:"sheet.operation.set-scroll",type:a.CommandType.OPERATION,handler:(n,o)=>{if(!o)return!1;const{unitId:e,sheetId:t,offsetX:r=0,offsetY:i=0,sheetViewStartColumn:s,sheetViewStartRow:l,duration:c,screenRatioX:d,screenRatioY:u}=o,h=n.get(y.IRenderManagerService),g=h.getRenderById(e).with(exports.SheetScrollManagerService),S=h.getRenderById(e);if(!S)return!1;const f=S.engine,p=f.width,v=f.height,C=d!==void 0?p*d+r:r,_=u!==void 0?v*u+i:i;return g.emitRawScrollParam({unitId:e,sheetId:t,offsetX:C,offsetY:_,sheetViewStartRow:l,sheetViewStartColumn:s,duration:c}),!0}},Rn={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),r=n.get(y.IRenderManagerService),i=m.getSheetCommandTarget(t);if(!i)return!1;const{unitId:s,subUnitId:l}=i,d=r.getRenderById(s).with(exports.SheetScrollManagerService).getCurrentScrollState(),{offsetX:u=0,offsetY:h=0}=o||{},{sheetViewStartRow:g=0,sheetViewStartColumn:S=0,offsetX:f=0,offsetY:p=0}=d||{};return e.executeCommand(rt.id,{unitId:s,sheetId:l,sheetViewStartRow:g,sheetViewStartColumn:S,offsetX:f+u,offsetY:p+h})}},He={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(y.IRenderManagerService),r=m.getSheetCommandTarget(e);if(!r)return!1;const{workbook:i,worksheet:s,unitId:l}=r,d=t.getRenderById(l).with(exports.SheetScrollManagerService).getCurrentScrollState();if(!s)return!1;const{sheetViewStartRow:u,sheetViewStartColumn:h,offsetX:g,offsetY:S,duration:f}=o,{sheetViewStartColumn:p,sheetViewStartRow:v,offsetX:C,offsetY:_}=d||{},{xSplit:R,ySplit:w}=r.worksheet.getConfig().freeze;return n.get(a.ICommandService).syncExecuteCommand(rt.id,{unitId:i.getUnitId(),sheetId:s.getSheetId(),sheetViewStartRow:u!=null?u:v!=null?v:0+w,sheetViewStartColumn:h!=null?h:p!=null?p:0+R,offsetX:g!=null?g:C,offsetY:S!=null?S:_,duration:f})}},as={id:"sheet.command.scroll-to-cell",type:a.CommandType.COMMAND,handler:(n,o)=>{const e=n.get(a.IUniverInstanceService);return n.get(y.IRenderManagerService).getRenderById(e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(exports.SheetsScrollRenderController).scrollToRange(o.range,o.forceTop,o.forceLeft)}},$u={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:r}=e;return n.get(a.ICommandService).executeCommand(rt.id,{unitId:r,sheetId:t,sheetViewStartRow:0,sheetViewStartColumn:0})}};var eh=Object.getOwnPropertyDescriptor,th=(n,o,e,t)=>{for(var r=t>1?void 0:t?eh(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},ea=(n,o)=>(e,t)=>o(e,t,n);const nh=(n,o)=>{const{unitId:e,subUnitId:t,ranges:r}=n,i={},s=o.getColumnManager();for(let l=0;l<r.length;l++){const c=r[l];for(let d=c.startColumn;d<c.endColumn+1;d++)i[d]=s.getColumnWidth(d)}return{unitId:e,subUnitId:t,ranges:r,colWidth:i}};exports.AutoWidthController=class extends a.Disposable{constructor(o,e){super(),this._renderManagerService=o,this._univerInstanceService=e}getUndoRedoParamsOfColWidth(o){const e={redos:[],undos:[]},{_univerInstanceService:t}=this,r=m.getSheetCommandTarget(t);if(!r)return e;const{unitId:i,subUnitId:s,worksheet:l}=r,c=this._renderManagerService.getRenderById(i).with(exports.SheetSkeletonManagerService);if(!c.getCurrentParam())return e;const{skeleton:d}=c.getCurrentParam(),u=d.calculateAutoWidthInRange(o.ranges),h={};for(const{col:f,width:p}of u)h[f]=p;const g={subUnitId:s,unitId:i,ranges:o.ranges,colWidth:h},S=nh(g,l);return{undos:[{id:m.SetWorksheetColWidthMutation.id,params:S}],redos:[{id:m.SetWorksheetColWidthMutation.id,params:g}]}}};exports.AutoWidthController=th([ea(0,y.IRenderManagerService),ea(1,a.Inject(a.IUniverInstanceService))],exports.AutoWidthController);const Vn={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),r=n.get(m.SheetsSelectionsService),i=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(i,o);if(!s)return!1;const{unitId:l,subUnitId:c}=s;let d=[];if(o!=null&&o.ranges)d=[...o.ranges];else{const f=r.getCurrentSelections();for(let p=0;p<f.length;p++)d.push(f[p].range)}if(!(d!=null&&d.length))return!1;const u={unitId:l,subUnitId:c,ranges:d},{redos:h,undos:g}=n.get(exports.AutoWidthController).getUndoRedoParamsOfColWidth(u);return a.sequenceExecute([...h],e).result?(t.pushUndoRedo({unitID:l,undoMutations:[...g],redoMutations:[...h]}),!0):!1}};var rh=Object.getOwnPropertyDescriptor,oh=(n,o,e,t)=>{for(var r=t>1?void 0:t?rh(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},$t=(n,o)=>(e,t)=>o(e,t,n);exports.EditorBridgeService=class extends a.Disposable{constructor(e,t,r,i,s,l){super();E(this,"_editorUnitId",a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);E(this,"_editorIsDirty",!1);E(this,"_visibleParams",{visible:!1,eventType:y.DeviceInputEventType.Dblclick,unitId:""});E(this,"_currentEditCell",null);E(this,"_currentEditCellState",null);E(this,"_currentEditCellLayout",null);E(this,"helpFunctionVisible$",new O.BehaviorSubject(!0));E(this,"_currentEditCellState$",new O.BehaviorSubject(null));E(this,"currentEditCellState$",this._currentEditCellState$.asObservable());E(this,"_currentEditCellLayout$",new O.BehaviorSubject(null));E(this,"currentEditCellLayout$",this._currentEditCellLayout$.asObservable());E(this,"currentEditCell$",this._currentEditCellState$.pipe(O.switchMap(e=>this._currentEditCellLayout$.pipe(O.map(t=>e&&t?{...e,...t}:null)))));E(this,"_visibleParams$",new O.BehaviorSubject(this._visibleParams));E(this,"visible$",this._visibleParams$.asObservable());E(this,"_afterVisibleParams$",new O.BehaviorSubject(this._visibleParams));E(this,"afterVisible$",this._afterVisibleParams$.asObservable());E(this,"_forceKeepVisible$",new O.BehaviorSubject(!1));E(this,"forceKeepVisible$",this._forceKeepVisible$.asObservable());this._sheetInterceptorService=e,this._renderManagerService=t,this._themeService=r,this._univerInstanceService=i,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:r,scaleY:i,canvasOffset:s,...l}=e;this._currentEditCellState=l,this._currentEditCellLayout={position:t,scaleX:r,scaleY:i,canvasOffset:s},this._currentEditCellState$.next(this._currentEditCellState),this._currentEditCellLayout$.next(this._currentEditCellLayout)}refreshEditCellPosition(e){var P;const t=this._currentEditCell;if(t==null)return;const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!r)return;const i=this._renderManagerService.getRenderUnitById(r.getUnitId());if(!i)return;const s=(P=i.with(exports.SheetSkeletonManagerService).getSkeletonParam(t.sheetId))==null?void 0:P.skeleton,l=i.with(Ce);if(!s||!this._currentEditCellState)return;const{primary:c,scene:d,engine:u}=t,h=or(s,c);if(h==null)return;const g=a.convertCellToRange(h),S=Q.getCanvasOffsetByEngine(u);let{startX:f,startY:p,endX:v,endY:C}=g;const{scaleX:_,scaleY:R}=d.getAncestorScale(),w=d.getViewportScrollXY(l.getViewPort());f=y.convertTransformToOffsetX(f,_,w),p=y.convertTransformToOffsetY(p,R,w),v=y.convertTransformToOffsetX(v,_,w),C=y.convertTransformToOffsetY(C,R,w),e&&this._currentEditCellLayout&&(v=v-f+this._currentEditCellLayout.position.startX,C=C-p+this._currentEditCellLayout.position.startY,f=this._currentEditCellLayout.position.startX,p=this._currentEditCellLayout.position.startY),this._currentEditCellLayout={position:{startX:f,startY:p,endX:v,endY:C},canvasOffset:S,scaleX:_,scaleY:R},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:r,canvasOffset:i,scaleX:s,scaleY:l,...c}=t;this._currentEditCellState=c,this._currentEditCellLayout={position:r,canvasOffset:i,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 N,V,L;const e=this._currentEditCell;if(e==null)return;const t=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!t)return;const r=this._renderManagerService.getRenderUnitById(t.getUnitId());if(!r)return;const i=r.with(exports.SheetSkeletonManagerService).getCurrentSkeleton(),s=r.with(Ce);if(!i)return;const{primary:l,unitId:c,sheetId:d,scene:u,engine:h}=e,{startRow:g,startColumn:S}=l,f=or(i,l);if(f==null)return;const p=a.convertCellToRange(f),v=Q.getCanvasOffsetByEngine(h);let{startX:C,startY:_,endX:R,endY:w}=p;const{scaleX:P,scaleY:T}=u.getAncestorScale(),M=u.getViewportScrollXY(s.getViewPort());C=y.convertTransformToOffsetX(C,P,M),_=y.convertTransformToOffsetY(_,T,M),R=y.convertTransformToOffsetX(R,P,M),w=y.convertTransformToOffsetY(w,T,M);const x=t.getActiveSheet();if(!x)return;const A={workbook:t,worksheet:x,unitId:t.getUnitId(),subUnitId:x.getSheetId(),row:g,col:S,origin:x.getCellRaw(g,S)};let D;const k=this._sheetInterceptorService.writeCellInterceptor.fetchThroughInterceptors(m.BEFORE_CELL_EDIT)(x.getCell(g,S),A);D=k&&x.getCellDocumentModelWithFormula(k,A.row,A.col);const H=(N=D==null?void 0:D.documentModel)==null?void 0:N.documentStyle.renderConfig;if(H!=null&&(H.cellValueType=a.CellValueType.STRING),!D||D.documentModel==null){const U=x.getBlankCellDocumentModel(k,A.row,A.col);if(D!=null){const{verticalAlign:F,horizontalAlign:B,wrapStrategy:z,textRotation:X,fill:K}=D,{centerAngle:re,vertexAngle:oe}=y.convertTextRotation(X);U.documentModel.documentStyle.renderConfig={...H,verticalAlign:F,horizontalAlign:B,wrapStrategy:z,background:{rgb:K},centerAngle:re,vertexAngle:oe}}D=U}if(D.fill=D.fill||"#fff",(V=D.documentModel)==null||V.setZoomRatio(Math.max(P,T)),(k==null?void 0:k.isInArrayFormulaRange)===!0){const U=(L=D.documentModel)==null?void 0:L.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:R,endY:w},scaleX:P,scaleY:T,canvasOffset:v,row:g,column:S,unitId:c,sheetId:d,documentLayoutObject:D,editorUnitId:this._editorUnitId,isInArrayFormulaRange:k==null?void 0:k.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}};exports.EditorBridgeService=oh([$t(0,a.Inject(m.SheetInterceptorService)),$t(1,y.IRenderManagerService),$t(2,a.Inject(a.ThemeService)),$t(3,a.IUniverInstanceService),$t(4,Q.IEditorService),$t(5,a.IContextService)],exports.EditorBridgeService);const he=a.createIdentifier("univer.sheet-editor-bridge.service");var ih=Object.getOwnPropertyDescriptor,sh=(n,o,e,t)=>{for(var r=t>1?void 0:t?ih(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Ur=(n,o)=>(e,t)=>o(e,t,n);let ar=class extends a.Disposable{constructor(o,e,t,r,i){super();E(this,"_zoom");this._context=o,this._sheetSkeletonManagerService=e,this._commandService=t,this._contextService=r,this._editorBridgeService=i,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=De(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 r=t<40?.2:t<80?.4:.2;r*=e.deltaY>0?-1:1,o.scaleX<1&&(r/=2);const i=this._context.unit,s=i.getActiveSheet();if(!s)return;const l=s.getZoomRatio();let c=+Number.parseFloat(`${l+r}`).toFixed(1);c=c>=4?4:c<=.1?.1:c,this._commandService.executeCommand(Wn.id,{zoomRatio:Math.round(c*10)/10,unitId:i.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 r=t.getZoomRatio()||1;this._zoom!==r&&this._updateViewZoom(r)}))}_updateViewZoom(o){this._zoom=o;const e=De(this._context.unit,this._context);e==null||e.scene.scale(o,o),e==null||e.spreadsheet.makeForceDirty()}};ar=sh([Ur(1,a.Inject(exports.SheetSkeletonManagerService)),Ur(2,a.ICommandService),Ur(3,a.IContextService),Ur(4,a.Optional(he))],ar);const Ye={id:"sheet.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(n,o)=>{const t=n.get(y.IRenderManagerService).getRenderById(o.unitId);return t?t.with(ar).updateZoom(o.subUnitId,o.zoomRatio):!1}},Hn={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:r,subUnitId:i,unitId:s}=t,{delta:l,reset:c}=o;let d=c?100:Math.round((r.getConfig().zoomRatio+l)*100);d=Math.max(yi[0],d),d=Math.min(yi[1],d);const u=d/100,g=n.get(he).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:i,zoomRatio:u})}},Wn={id:"sheet.command.set-zoom-ratio",type:a.CommandType.COMMAND,handler:(n,o)=>{if(!o)return!1;const{unitId:e,subUnitId:t,zoomRatio:r}=o,s=n.get(he).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:r})}},Yt=a.createIdentifier("univer.sheetbar-service");class ol extends a.Disposable{constructor(){super();E(this,"renameId$");E(this,"removeId$");E(this,"scroll$");E(this,"scrollX$");E(this,"addSheet$");E(this,"_renameId$");E(this,"_removeId$");E(this,"_scroll$");E(this,"_scrollX$");E(this,"_addSheet$");E(this,"_currentHandler",null);this._renameId$=new O.Subject,this.renameId$=this._renameId$.asObservable(),this._removeId$=new O.Subject,this.removeId$=this._removeId$.asObservable(),this._scroll$=new O.Subject,this.scroll$=this._scroll$.asObservable(),this._scrollX$=new O.Subject,this.scrollX$=this._scrollX$.asObservable(),this._addSheet$=new O.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 Pr={id:"ui-sheet.command.show-menu-list",type:a.CommandType.OPERATION,handler:async n=>(n.get(Yt).triggerSheetBarMenu(),!0)},xr={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),r=n.get(m.WorksheetProtectionRuleModel),s=n.get(a.IUniverInstanceService).getCurrentUnitForType($a.UNIVER_SHEET),l=s==null?void 0:s.getActiveSheet(),c=s.getUnitId();if(!l)return!1;const d=l.getSheetId(),u=r.getRule(c,d);if(await e.executeCommand(m.DeleteWorksheetProtectionCommand.id,{unitId:c,subUnitId:d})){const g=[{id:m.DeleteWorksheetProtectionCommand.id,params:{unitId:c,subUnitId:d}}],S=[{id:m.AddWorksheetProtectionCommand.id,params:{unitId:c,rule:u}}];t.pushUndoRedo({unitID:c,redoMutations:g,undoMutations:S})}return!0}},Or={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}},Ho={id:"sheet.operation.set-activate-cell-edit",type:a.CommandType.OPERATION,handler:(n,o)=>(n.get(he).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,r=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);return r?(n.get(he).changeVisible({...o,unitId:e!=null?e:r.getUnitId()}),!0):!1}},Ar={id:"sheet.operation.set-cell-edit-visible-f2",type:a.CommandType.OPERATION,handler:(n,o)=>{const e=n.get(a.ICommandService),r=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);return r?e.syncExecuteCommand(Se.id,{...o,unitId:r.getUnitId()}):!1}},Wt={id:"sheet.operation.set-cell-edit-visible-arrow",type:a.CommandType.OPERATION,handler:()=>!0},Dr={id:"sheet.operation.rename-sheet",type:a.CommandType.OPERATION,handler:async(n,o)=>{const e=n.get(Yt);return o&&e.setRenameId(o.subUnitId),!0}},Wo={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(y.IRenderManagerService).getRenderById(e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(exports.SheetsScrollRenderController).scrollToRange(o.range,o.forceTop,o.forceLeft)}},ls={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:ro,title:{title:"permission.dialog.allowedPermissionType"},children:{label:tl},width:393,destroyOnClose:!0,onClose:()=>e.close(ro)}),!0}},lr="DefinedNameContainer",Uo={id:"sidebar.operation.defined-name",type:a.CommandType.COMMAND,handler:async(n,o)=>{const e=n.get(I.ISidebarService);n.get(Q.IEditorService);const t=n.get(a.LocaleService),r=n.get(a.IUniverInstanceService),i=m.getSheetCommandTarget(r);if(!i)return!1;const{unitId:s}=i;switch(o.value){case"open":e.open({id:lr,header:{title:t.t("definedName.featureTitle")},children:{label:lr},onClose:()=>{},width:333});break;case"close":default:e.close();break}return!0}};function ah(n,o){if(n.length!==o.length)return!1;const e=n.sort((r,i)=>r.id.localeCompare(i.id)),t=o.sort((r,i)=>r.id.localeCompare(i.id));return e.every((r,i)=>{var s,l;return((s=r.subject)==null?void 0:s.userID)===((l=t[i].subject)==null?void 0:l.userID)&&r.role===t[i].role})}function il(n,o){return o.some(e=>lh(n,e))}function lh(n,o){const{startRow:e,startColumn:t,endColumn:r,endRow:i}=o,s=n.getMatrixWithMergedCells(e,t,i,r);let l=!1;return s.forValue((c,d,u)=>{if(u&&(c!==e||d!==t)&&n.cellHasValue(u))return l=!0,!1}),l}function sl(n,o,e,t){const r=[],i=[],s=e.getSheetId();return t.forEach(l=>{const c=ch(e,l),d={unitId:o,subUnitId:s,cellValue:c.getData()},u=m.SetRangeValuesUndoMutationFactory(n,d);r.push({id:m.SetRangeValuesMutation.id,params:u}),i.push({id:m.SetRangeValuesMutation.id,params:d})}),{undos:r,redos:i}}function ch(n,o){const{startRow:e,startColumn:t,endColumn:r,endRow:i}=o,s=n.getMatrixWithMergedCells(e,t,i,r,a.CellModeEnum.Raw),l=new a.ObjectMatrix;let c=null;return s.forValue((d,u,h)=>{var g,S,f,p;h&&d>=e&&u>=t&&(!c&&n.cellHasValue(h)&&(h.v!==""||((p=(f=(S=(g=h.p)==null?void 0:g.body)==null?void 0:S.dataStream)==null?void 0:f.length)!=null?p:0)>2)&&(c=h),l.setValue(d,u,null))}),l.setValue(e,t,c),l}function dh(n,o,e,t){const r=e.getActiveViewportByCoord(y.Vector2.FromArray([n,o]));if(!r)return;const{scaleX:i,scaleY:s}=e.getAncestorScale(),l={x:r.viewportScrollX,y:r.viewportScrollY},c=t.getCellIndexByOffset(n,o,i,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 ta(n,o,e,t){const r=t.getFreeze();if(!r||r.startRow<=0&&r.startColumn<=0||n>=r.startRow&&o>=r.startColumn)return e.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(n<r.startRow&&o<r.startColumn)return e.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP);if(n<r.startRow&&o>=r.startColumn)return e.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(n>=r.startRow&&o<r.startColumn)return e.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)}function uh(n,o,e,t){const r=na(n.left,n.top,o,e,t),i=na(n.right,n.bottom,o,e,t);return{left:r.x,top:r.y,right:i.x,bottom:i.y}}function na(n,o,e,t,r){const{scaleX:i,scaleY:s}=e.getAncestorScale(),l=e.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!l)return{x:n,y:o};const c=r.getFreeze(),{startColumn:d,startRow:u,xSplit:h,ySplit:g}=c,S=t.getNoMergeCellWithCoordByIndex(u-g,d-h,!1),f=t.getNoMergeCellWithCoordByIndex(u,d,!1),{rowHeaderWidth:p,columnHeaderHeight:v}=t,C=f.startX-S.startX,_=f.startY-S.startY,{top:R,left:w,viewportScrollX:P,viewportScrollY:T}=l;let M;n>w?M=(n-P)*i:M=(C+p-(w-n))*i;let x;return o>R?x=(o-T)*s:x=(_+v-(R-o))*i,{x:M,y:x}}function al(n,o,e,t,r){let i=t,s=r;e.overflowCache.forValue((d,u,h)=>{h.startRow<=i&&h.endRow>=i&&h.startColumn<=s&&h.endColumn>=s&&(s=u,i=d)});const l=e.getCellWithCoordByIndex(i,s);return{unitId:n.getUnitId(),subUnitId:o.getSheetId(),workbook:n,worksheet:o,row:l.actualRow,col:l.actualColumn}}function ll(n,o,e,t,r,i){const{scene:s}=n,l=o.getUnitId(),{skeleton:c,sheetId:d}=t,u=dh(r,i,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((T,M,x)=>{x.startRow<=g&&x.endRow>=g&&x.startColumn<=h&&x.endColumn>=h&&(h=M,g=T)});const f=c.getCellWithCoordByIndex(g,h),p=al(o,e,c,g,h);let v;f.mergeInfo?v=f.mergeInfo:v={startRow:p.row,endRow:p.row,startColumn:p.col,endColumn:p.col};const C=s.getActiveViewportByCoord(y.Vector2.FromArray([r,i]));if(!C)return;const{scaleX:_,scaleY:R}=s.getAncestorScale(),w={x:C.viewportScrollX,y:C.viewportScrollY};return{position:{startX:(c.getOffsetByColumn(v.startColumn-1)-w.x)*_,endX:(c.getOffsetByColumn(v.endColumn)-w.x)*_,startY:(c.getOffsetByRow(v.startRow-1)-w.y)*R,endY:(c.getOffsetByRow(v.endRow)-w.y)*R},location:S,overflowLocation:p}}function vt(){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 hh(n){return I.useObservable(()=>{var e;return(e=n==null?void 0:n.activeSheet$)!=null?e:O.of(null)},void 0,void 0,[n])}function mh(){const n=I.useDependency(a.IUniverInstanceService);return I.useObservable(()=>O.merge([n.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET),n.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET)]).pipe(O.map(()=>n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET)),O.startWith(n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET))),[],void 0,[n])}const gh="SheetUI";var cs=(n=>(n.FILTER_PANEL_EMBED_POINT="filter-panel-embed-point",n.SHEETS_FOOTER="sheets-footer",n.FORMULA_AUX="formula-aux",n))(cs||{}),Sh=Object.getOwnPropertyDescriptor,fh=(n,o,e,t)=>{for(var r=t>1?void 0:t?Sh(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Lr=(n,o)=>(e,t)=>o(e,t,n);const ra="univer-sheet-main-canvas";exports.SheetsRenderService=class extends a.RxDisposable{constructor(e,t,r,i){super();E(this,"_skeletonChangeMutations",new Set);this._contextService=e,this._instanceSrv=t,this._renderManagerService=r,this._themeService=i,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(O.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(O.takeUntil(this.dispose$)).subscribe(e=>this._disposeRenderer(e))}_createRenderer(e){const t=e.getUnitId();this._renderManagerService.created$.subscribe(r=>{r.unitId===t&&(r.engine.getCanvas().setId(`${ra}_${t}`),r.engine.getCanvas().getContext().setId(`${ra}_${t}`))}),this._renderManagerService.createRender(t)}_disposeRenderer(e){const t=e.getUnitId();this._renderManagerService.removeRender(t)}_initContextListener(){this.disposeWithMe(this._contextService.subscribeContextValue$(y.RENDER_RAW_FORMULA_KEY).pipe(O.distinctUntilChanged()).subscribe(()=>{this._renderManagerService.getRenderAll().forEach(e=>{e.mainComponent instanceof y.Spreadsheet&&e.mainComponent.makeForceDirty(!0)})}))}};exports.SheetsRenderService=fh([Lr(0,a.IContextService),Lr(1,a.IUniverInstanceService),Lr(2,y.IRenderManagerService),Lr(3,a.Inject(a.ThemeService))],exports.SheetsRenderService);var ph=Object.getOwnPropertyDescriptor,vh=(n,o,e,t)=>{for(var r=t>1?void 0:t?ph(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},_t=(n,o)=>(e,t)=>o(e,t,n);exports.AutoFillController=class extends a.Disposable{constructor(e,t,r,i,s,l,c){super();E(this,"_beforeApplyData",[]);E(this,"_currentLocation",null);E(this,"_copyData",[]);E(this,"_defaultHook");this._univerInstanceService=e,this._commandService=t,this._autoFillService=r,this._editorBridgeService=i,this._renderManagerService=s,this._injector=l,this._sheetsRenderService=c,this._defaultHook={id:"default",type:on.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,Sn.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,r)=>{var c,d;const i=r==null?void 0:r.fromCollab,s=r==null?void 0:r.fromSync,l=r==null?void 0:r.fromFormula;e.includes(t.id)&&!i&&!s&&!l&&t.params.trigger!==dt.id&&t.params.trigger!==br.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 r;t.getUnitId()===((r=this._currentLocation)==null?void 0:r.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 r=y.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService);if(!r)return;r.with(Ce).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:y.DeviceInputEventType.PointerDown,unitId:r.unitId})}))})};t(),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{r.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,p,v,C;const{startRow:t,endRow:r,startColumn:i,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=r;if(i>0&&((S=c.getValue(t,i-1))==null?void 0:S.v)!=null){let _=t;for(;((f=c.getValue(_,i-1))==null?void 0:f.v)!=null&&_<d;)_+=1;h=_-1}else if(s<u&&((p=c.getValue(r,s+1))==null?void 0:p.v)!=null){let _=t;for(;((v=c.getValue(_,s+1))==null?void 0:v.v)!=null&&_<d;)_+=1;h=_-1}for(let _=r+1;_<=h;_++)for(let R=i;R<=s;R++)if(((C=c.getValue(_,R))==null?void 0:C.v)!=null){h=_-1;break}return{startColumn:i,endColumn:s,startRow:t,endRow:h}}_getApplyData(e,t,r,i,s,l=!0,c){const d=[],u=Math.floor(r/t),h=r%t,g=this._autoFillService.getRules();if(!l&&s===ae.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:p,applyFunctions:v={}}=f,C=e[p];C&&C.forEach(_=>{const R=Dd(_.index,h),w=_.index.length*u+R,P=this._applyFunctions(_,w,i,s,v,e,c),T=kd(t,r,_.index);S[p].push({data:P,index:T})})});for(let f=0;f<r;f++)g.forEach(p=>{const{type:v}=p,C=S[v];for(let _=0;_<C.length;_++)f in C[_].index&&d.push(C[_].data[C[_].index[f]])});return d}_applyFunctions(e,t,r,i,s,l,c){const{data:d}=e,u=r===a.Direction.UP||r===a.Direction.LEFT;if(i===ae.COPY){const h=s==null?void 0:s[ae.COPY];return h?h(e,t,r,l,c):(u&&d.reverse(),Dt(d,t))}if(i===ae.SERIES){const h=s==null?void 0:s[ae.SERIES];return h?h(e,t,r,l):(u&&d.reverse(),s!=null&&s[ae.COPY]?s[ae.COPY](e,t,r,l,c):Dt(d,t))}if(i===ae.ONLY_FORMAT){const h=s==null?void 0:s[ae.ONLY_FORMAT];return h?h(e,t,r,l):Nd(d,t)}}_getCopyData(e,t){var f;const{unitId:r,subUnitId:i,source:s}=e,l=(f=this._univerInstanceService.getUnit(r))==null?void 0:f.getSheetBySheetId(i);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(p=>{const v=this._getEmptyCopyDataPiece(),C={type:void 0,cellData:void 0};S.forEach(_=>{let R;h?R=c.getValue(_,p):R=c.getValue(p,_);const{type:w,isContinue:P}=d.find(T=>T.match(R,this._injector))||ja;if(P(C,R)){const T=v[w],M=T[T.length-1];M.data.push(R),M.index.push(_-S[0])}else{const T=v[w];T?T.push({data:[R],index:[_-S[0]]}):v[w]=[{data:[R],index:[_-S[0]]}]}C.type=w,C.cellData=R}),u.push(v)}),u}_getEmptyCopyDataPiece(){const e={};return this._autoFillService.getRules().forEach(t=>{e[t.type]=[]}),e}_getMergeApplyData(e,t,r,i,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:p,startColumn:v,endRow:C,endColumn:_}=d.getCellInfoInMergeData(g,S);if(f){if(r===a.Direction.DOWN){let R=p+i,w=C+i;for(;w<=t.endRow;)u.push({startRow:R,startColumn:v,endRow:w,endColumn:_}),R+=i,w+=i}else if(r===a.Direction.UP){let R=p-i,w=C-i;for(;R>=t.startRow;)u.push({startRow:R,startColumn:v,endRow:w,endColumn:_}),R-=i,w-=i}else if(r===a.Direction.RIGHT){let R=v+i,w=_+i;for(;w<=t.endColumn;)u.push({startRow:p,startColumn:R,endRow:C,endColumn:w}),R+=i,w+=i}else if(r===a.Direction.LEFT){let R=v-i,w=_-i;for(;R>=t.startColumn;)u.push({startRow:p,startColumn:R,endRow:C,endColumn:w}),R-=i,w-=i}}}return u}_presetAndCacheData(e,t){var u;const{unitId:r,subUnitId:i,target:s}=e,l=(u=this._univerInstanceService.getUnit(r))==null?void 0:u.getSheetBySheetId(i);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(ae.SERIES,!0),ae.COPY):(this._autoFillService.setDisableApplyType(ae.SERIES,!1),this._getPreferredApplyType(this._copyData))}_fillData(e,t,r){var N,V,L;const i=[],s=[];let l=!0;r===ae.NO_FORMAT&&(l=!1,r=ae.SERIES);const{source:c,target:d,unitId:u,subUnitId:h}=e;if(!c||!d||t==null)return{undos:i,redos:s};const g=gt(c),S=gt(d),{cols:f,rows:p}=d,{cols:v,rows:C}=c,_=this._copyData;let R;t===a.Direction.DOWN||t===a.Direction.UP?R=C.length:R=v.length;const w=[];if(t===a.Direction.DOWN||t===a.Direction.UP){const U=p.length,F=[];f.forEach((B,z)=>{const X=_[z],K=this._getApplyData(X,R,U,t,r,l,e);F.push(K)});for(let B=0;B<F[0].length;B++){const z=[];for(let X=0;X<F.length;X++)z.push({s:null,...F[X][B]});w.push(z)}}else{const U=f.length;p.forEach((F,B)=>{const z=_[B],X=this._getApplyData(z,R,U,t,r,l,e),K=[];for(let re=0;re<X.length;re++)K.push({s:null,...X[re]});w.push(K)})}let P=[];const T=(N=this._univerInstanceService.getUnit(u))==null?void 0:N.getStyles();if(l?(P=this._getMergeApplyData(g,S,t,R,e),w.forEach(U=>{U.forEach(F=>{F&&T&&T&&(F.s=T.getStyleByCell(F))})})):w.forEach((U,F)=>{U.forEach((B,z)=>{B&&T&&(B.s=T.getStyleByCell(this._beforeApplyData[F][z])||null)})}),r===ae.ONLY_FORMAT&&w.forEach((U,F)=>{U.forEach((B,z)=>{if(B){const X=this._beforeApplyData[F][z]||{};B.f=X.f,B.si=X.si,B.t=X.t,B.v=X.v}})}),l){const U=[],F=(L=(V=this._univerInstanceService.getUniverSheetInstance(u))==null?void 0:V.getSheetBySheetId(h))==null?void 0:L.getMergeData();F&&F.forEach(X=>{a.Rectangle.intersects(X,S)&&U.push(X)});const B={unitId:u,subUnitId:h,ranges:U},z=this._injector.invoke(m.RemoveMergeUndoMutationFactory,B);U.length&&(s.push({id:m.RemoveWorksheetMergeMutation.id,params:B}),i.unshift({id:m.AddWorksheetMergeMutation.id,params:z}))}const M={subUnitId:h,unitId:u,cellValue:Td([d])},x=this._injector.invoke(m.SetRangeValuesUndoMutationFactory,M);s.push({id:m.SetRangeValuesMutation.id,params:M}),i.unshift({id:m.SetRangeValuesMutation.id,params:x});const A=new a.ObjectMatrix;p.forEach((U,F)=>{f.forEach((B,z)=>{w[F][z]&&A.setValue(U,B,w[F][z])})});const D=A.getMatrix(),k={subUnitId:h,unitId:u,cellValue:D},H=this._injector.invoke(m.SetRangeValuesUndoMutationFactory,k);if(this._autoFillService.getActiveHooks().forEach(U=>{var F;(F=U.onBeforeSubmit)==null||F.call(U,e,t,r,D)}),i.unshift({id:m.SetRangeValuesMutation.id,params:H}),s.push({id:m.SetRangeValuesMutation.id,params:k}),P!=null&&P.length){const U=m.getAddMergeMutationRangeByType(P),F={unitId:u,subUnitId:h,ranges:U},B=this._injector.invoke(m.AddMergeUndoMutationFactory,F);i.unshift({id:m.RemoveWorksheetMergeMutation.id,params:B}),s.push({id:m.AddWorksheetMergeMutation.id,params:F})}return{undos:i,redos:s}}_shouldDisableSeries(e){return e.every(t=>Object.keys(t).every(r=>{var i;return((i=t[r])==null?void 0:i.length)===0||[Ie.OTHER,Ie.FORMULA].includes(r)}))}_getPreferredApplyType(e){return e.every(r=>Object.keys(r).every(i=>{var s,l;return((s=r[i])==null?void 0:s.length)===0||((l=r[i])==null?void 0:l.length)===1&&r[i][0].data.length===1&&Ie.NUMBER===i}))?ae.COPY:ae.SERIES}};exports.AutoFillController=vh([_t(0,a.IUniverInstanceService),_t(1,a.ICommandService),_t(2,ft),_t(3,he),_t(4,y.IRenderManagerService),_t(5,a.Inject(a.Injector)),_t(6,a.Inject(exports.SheetsRenderService))],exports.AutoFillController);var Ch=Object.getOwnPropertyDescriptor,Ih=(n,o,e,t)=>{for(var r=t>1?void 0:t?Ch(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Yo=(n,o)=>(e,t)=>o(e,t,n);exports.CellCustomRenderController=class extends a.Disposable{constructor(e,t,r,i){super();E(this,"_enterActiveRender");this._context=e,this._sheetSkeletonManagerService=t,this._renderManagerService=r,this._permissionService=i,this._initEventBinding()}_initEventBinding(){const e=new a.DisposableCollection,t=this._context.unit,r=i=>{if(e.dispose(),!i)return;const s=this._context.unitId,{skeleton:l}=i,c=this._renderManagerService.getRenderById(s);if(c&&c.mainComponent){const d=c.mainComponent,u=S=>{const{offsetX:f,offsetY:p}=S,v=c.scene,C=t.getActiveSheet();if(!C)return;const _=v.getActiveViewportByCoord(y.Vector2.FromArray([f,p]));if(!_)return;const{scaleX:R,scaleY:w}=v.getAncestorScale(),P={x:_.viewportScrollX,y:_.viewportScrollY},T=l.getCellIndexByOffset(f,p,R,w,P),M=l.worksheet.getMergedCell(T.row,T.column),x={actualRow:M?M.startRow:T.row,actualCol:M?M.startColumn:T.column,row:T.row,col:T.column};if(!x||!l)return;const A=C.getCell(x.actualRow,x.actualCol);if(!A)return;const D=A.customRender;if(!(D!=null&&D.length))return;const k=x.actualRow,H=x.actualCol,N=D.sort(a.sortRules),V=C.getSheetId(),L={data:A,style:l.getStyles().getStyleByCell(A),primaryWithCoord:l.getCellWithCoordByIndex(x.actualRow,x.actualCol),unitId:s,subUnitId:V,row:k,col:H,workbook:t,worksheet:C},U={x:P.x+f/R,y:P.y+p/w},F=N.find(B=>{var z;return(z=B.isHit)==null?void 0:z.call(B,U,L)});if(F)return[F,L]},h=d.onPointerDown$.subscribeEvent(S=>{var p,v,C,_;const f=u(S);if(f){const[R,w]=f,{row:P,col:T,worksheet:M,unitId:x,subUnitId:A}=w;if(!((p=this._permissionService.composePermission([new m.WorkbookEditablePermission(x).id,new m.WorksheetEditPermission(x,A).id]))==null?void 0:p.every(H=>H.value)))return!1;const k=(C=(v=M.getCell(P,T))==null?void 0:v.selectionProtection)==null?void 0:C[0];if((k==null?void 0:k[m.UnitAction.Edit])===!1)return!1;(_=R.onPointerDown)==null||_.call(R,w,S)}}),g=a.fromEventSubject(d.onPointerMove$).pipe(O.throttleTime(30)).subscribe(S=>{var p,v,C,_,R,w;const f=u(S);if(f){const[P,T]=f;this._enterActiveRender?this._enterActiveRender.render!==P&&((v=(p=this._enterActiveRender.render).onPointerLeave)==null||v.call(p,this._enterActiveRender.cellContext,S),this._enterActiveRender={render:P,cellContext:T},(C=P.onPointerEnter)==null||C.call(P,T,S)):(this._enterActiveRender={render:P,cellContext:T},(_=P.onPointerEnter)==null||_.call(P,T,S))}else this._enterActiveRender&&((w=(R=this._enterActiveRender.render).onPointerLeave)==null||w.call(R,this._enterActiveRender.cellContext,S),this._enterActiveRender=null)});h&&e.add(h),g&&e.add(g)}};this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(r)),r(this._sheetSkeletonManagerService.getCurrentParam()),this.disposeWithMe(e)}};exports.CellCustomRenderController=Ih([Yo(1,a.Inject(exports.SheetSkeletonManagerService)),Yo(2,y.IRenderManagerService),Yo(3,a.IPermissionService)],exports.CellCustomRenderController);var _h=Object.getOwnPropertyDescriptor,bh=(n,o,e,t)=>{for(var r=t>1?void 0:t?_h(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},oa=(n,o)=>(e,t)=>o(e,t,n);exports.DragManagerService=class extends a.Disposable{constructor(e,t){super();E(this,"_currentCell$",new O.Subject);E(this,"currentCell$",this._currentCell$.asObservable().pipe(O.distinctUntilChanged((e,t)=>{var r,i,s,l,c,d,u,h;return((r=e==null?void 0:e.location)==null?void 0:r.unitId)===((i=t==null?void 0:t.location)==null?void 0:i.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)})));E(this,"_endCell$",new O.Subject);E(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 r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!r)return null;const i=r.getActiveSheet();if(!i)return;const s=this._renderManagerService.getRenderById(r.getUnitId());if(!s)return;const l=s.with(exports.SheetSkeletonManagerService).getCurrentParam(),d=s.with(exports.SheetScrollManagerService).getCurrentScrollState();if(!(!l||!d||!s))return ll(s,r,i,l,e,t)}onDragOver(e){const{offsetX:t,offsetY:r,dataTransfer:i}=e,s=this._calcActiveCell(t,r);if(!s){this._currentCell$.next(null);return}const{location:l,position:c}=s;this._currentCell$.next({location:l,position:c,dataTransfer:i})}onDrop(e){const{offsetX:t,offsetY:r,dataTransfer:i}=e,s=this._calcActiveCell(t,r);if(!s){this._endCell$.next(null);return}const{location:l,position:c}=s;this._endCell$.next({location:l,position:c,dataTransfer:i})}};exports.DragManagerService=bh([oa(0,a.IUniverInstanceService),oa(1,y.IRenderManagerService)],exports.DragManagerService);var Rh=Object.getOwnPropertyDescriptor,wh=(n,o,e,t)=>{for(var r=t>1?void 0:t?Rh(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Zo=(n,o)=>(e,t)=>o(e,t,n);exports.DragRenderController=class extends a.Disposable{constructor(o,e,t,r){super(),this._context=o,this._renderManagerService=e,this._dragManagerService=t,this._sheetSkeletonManagerService=r,this._initDragEvent()}_initDragEvent(){const o=new a.DisposableCollection,e=t=>{if(o.dispose(),!t)return;const{scene:r}=this._context,i=r.onDragOver$.subscribeEvent(l=>{this._dragManagerService.onDragOver(l)}),s=r.onDrop$.subscribeEvent(l=>{this._dragManagerService.onDrop(l)});o.add({dispose(){i.unsubscribe(),s.unsubscribe()}})};e(this._sheetSkeletonManagerService.getCurrentParam()),this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(t=>{e(t)}))}};exports.DragRenderController=wh([Zo(1,y.IRenderManagerService),Zo(2,a.Inject(exports.DragManagerService)),Zo(3,a.Inject(exports.SheetSkeletonManagerService))],exports.DragRenderController);class ds{constructor(){E(this,"_state",null);E(this,"_rect",null);E(this,"_state$",new O.BehaviorSubject(null));E(this,"state$",this._state$.asObservable());E(this,"_rect$",new O.BehaviorSubject(null));E(this,"rect$",this._rect$.asObservable());E(this,"_focus",!1);E(this,"_focus$",new O.BehaviorSubject(this._focus));E(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 Un=a.createIdentifier("univer.sheet-cell-editor-manager.service"),Ee="sheets-ui.config",io={formulaBar:!0,statusBarStatistic:!0,protectedRangeShadow:!0,maxAutoHeightCount:1e3};function us(n){return n===!0?"always":n===!1?"none":n||"always"}function pe({ref:n,...o}){const{icon:e,id:t,className:r,extend:i,...s}=o,l=`univerjs-icon univerjs-icon-${t} ${r||""}`.trim(),c=W.useRef(`_${yh()}`);return cl(e,`${t}`,{defIds:e.defIds,idSuffix:c.current},{ref:n,className:l,...s},i)}function cl(n,o,e,t,r){return W.createElement(n.tag,{key:o,...Eh(n,e,r),...t},(Th(n,e).children||[]).map((i,s)=>cl(i,`${o}-${n.tag}-${s}`,e,void 0,r)))}function Eh(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(([i,s])=>{i==="mask"&&typeof s=="string"&&(t[i]=s.replace(/url\(#(.*)\)/,`url(#$1${o.idSuffix})`))});const{defIds:r}=o;return!r||r.length===0||(n.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+o.idSuffix),Object.entries(t).forEach(([i,s])=>{typeof s=="string"&&(t[i]=s.replace(/url\(#(.*)\)/,`url(#$1${o.idSuffix})`))})),t}function Th(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(r=>typeof r.attrs.id=="string"&&e&&e.includes(r.attrs.id)?{...r,attrs:{...r.attrs,id:r.attrs.id+o.idSuffix}}:r)}:n}function yh(){return Math.random().toString(36).substring(2,8)}pe.displayName="UniverIcon";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:"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"}}]},Zt=W.forwardRef(function(o,e){return W.createElement(pe,Object.assign({},o,{id:"check-mark-icon",ref:e,icon:Mh}))});Zt.displayName="CheckMarkIcon";const Ph={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"}}]},dl=W.forwardRef(function(o,e){return W.createElement(pe,Object.assign({},o,{id:"close-icon",ref:e,icon:Ph}))});dl.displayName="CloseIcon";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:"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"]},ul=W.forwardRef(function(o,e){return W.createElement(pe,Object.assign({},o,{id:"convert-icon",ref:e,icon:xh}))});ul.displayName="ConvertIcon";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:"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"}}]},Lo=W.forwardRef(function(o,e){return W.createElement(pe,Object.assign({},o,{id:"delete-icon",ref:e,icon:Oh}))});Lo.displayName="DeleteIcon";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.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"}}]},hl=W.forwardRef(function(o,e){return W.createElement(pe,Object.assign({},o,{id:"dropdown-icon",ref:e,icon:Ah}))});hl.displayName="DropdownIcon";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:"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"}}]},hs=W.forwardRef(function(o,e){return W.createElement(pe,Object.assign({},o,{id:"error-icon",ref:e,icon:Dh}))});hs.displayName="ErrorIcon";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:"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"}}]},ml=W.forwardRef(function(o,e){return W.createElement(pe,Object.assign({},o,{id:"eyelash-icon",ref:e,icon:kh}))});ml.displayName="EyelashIcon";const Nh={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"}}]},gl=W.forwardRef(function(o,e){return W.createElement(pe,Object.assign({},o,{id:"fx-icon",ref:e,icon:Nh}))});gl.displayName="FxIcon";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:"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"}}]},ms=W.forwardRef(function(o,e){return W.createElement(pe,Object.assign({},o,{id:"increase-icon",ref:e,icon:Vh}))});ms.displayName="IncreaseIcon";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:"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"}}]},Sl=W.forwardRef(function(o,e){return W.createElement(pe,Object.assign({},o,{id:"info-icon",ref:e,icon:Hh}))});Sl.displayName="InfoIcon";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:"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"}}]},gs=W.forwardRef(function(o,e){return W.createElement(pe,Object.assign({},o,{id:"lock-icon",ref:e,icon:Wh}))});gs.displayName="LockIcon";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:"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=W.forwardRef(function(o,e){return W.createElement(pe,Object.assign({},o,{id:"more-down-icon",ref:e,icon:Uh}))});wn.displayName="MoreDownIcon";const Lh={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"}}]},Ni=W.forwardRef(function(o,e){return W.createElement(pe,Object.assign({},o,{id:"more-icon",ref:e,icon:Lh}))});Ni.displayName="MoreIcon";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:"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"}}]},fl=W.forwardRef(function(o,e){return W.createElement(pe,Object.assign({},o,{id:"pen-icon",ref:e,icon:Bh}))});fl.displayName="PenIcon";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:"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"}}]},pl=W.forwardRef(function(o,e){return W.createElement(pe,Object.assign({},o,{id:"protect-icon",ref:e,icon:Fh}))});pl.displayName="ProtectIcon";const jh={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"}}]},vl=W.forwardRef(function(o,e){return W.createElement(pe,Object.assign({},o,{id:"warning-icon",ref:e,icon:jh}))});vl.displayName="WarningIcon";const zh={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"}}]},Ss=W.forwardRef(function(o,e){return W.createElement(pe,Object.assign({},o,{id:"write-icon",ref:e,icon:zh}))});Ss.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"}}]},Cl=W.forwardRef(function(o,e){return W.createElement(pe,Object.assign({},o,{id:"autofill-double-icon",ref:e,icon:Xh}))});Cl.displayName="AutofillDoubleIcon";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:"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"}}]},fs=W.forwardRef(function(o,e){return W.createElement(pe,Object.assign({},o,{id:"hide-gridlines-double-icon",ref:e,icon:Yh}))});fs.displayName="HideGridlinesDoubleIcon";const Zh={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"}}]},Il=W.forwardRef(function(o,e){return W.createElement(pe,Object.assign({},o,{id:"paint-bucket-double-icon",ref:e,icon:Zh}))});Il.displayName="PaintBucketDoubleIcon";const Gh={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"}}]},_l=W.forwardRef(function(o,e){return W.createElement(pe,Object.assign({},o,{id:"paste-special-double-icon",ref:e,icon:Gh}))});_l.displayName="PasteSpecialDoubleIcon";const Kh=()=>{const[,n]=W.useState({});return W.useCallback(()=>n(o=>!o),[])};function qh(){const n=I.useDependency(a.ICommandService),o=I.useDependency(a.IUniverInstanceService),e=I.useDependency(y.IRenderManagerService),t=I.useDependency(ft),r=I.useDependency(a.LocaleService),[i,s]=W.useState([]),[l,c]=W.useState(!1),[d,u]=W.useState({row:-1,col:-1}),[h,g]=W.useState(ae.SERIES),[S,f]=W.useState(!1),p=vt(),{sheetSkeletonManagerService:v,selectionRenderService:C}=W.useMemo(()=>{if(p){const X=e.getRenderById(p.getUnitId());return{sheetSkeletonManagerService:X==null?void 0:X.with(exports.SheetSkeletonManagerService),selectionRenderService:X==null?void 0:X.with(Ce)}}return{sheetSkeletonManagerService:null,selectionRenderService:null}},[p,e]),_=()=>{f(!0)},R=()=>{f(!1)},w=Kh();if(W.useEffect(()=>n.onCommandExecuted((K,re)=>{K.id===rt.id&&w()}).dispose,[w,n]),W.useEffect(()=>{const X=v&&a.toDisposable(v.currentSkeleton$.subscribe(K=>{K&&w()}));return X==null?void 0:X.dispose},[v,w]),W.useEffect(()=>a.toDisposable(t.menu$.subscribe(K=>{s(K.map(re=>({...re,index:K.indexOf(re)})))})).dispose,[t]),W.useEffect(()=>a.toDisposable(t.showMenu$.subscribe(K=>{const{source:re,target:oe}=t.autoFillLocation||{source:null,target:null};if(K&&re&&oe){const le=Math.max(re.rows[re.rows.length-1],oe.rows[oe.rows.length-1]),Z=Math.max(re.cols[re.cols.length-1],oe.cols[oe.cols.length-1]);u({row:le,col:Z})}else u({row:-1,col:-1})})).dispose,[t]),W.useEffect(()=>a.toDisposable(t.applyType$.subscribe(K=>{g(K)})).dispose,[t]),W.useEffect(()=>{function X(){c(!1)}return document.addEventListener("wheel",X),()=>{document.removeEventListener("wheel",X)}},[l]),d.col<0||d.row<0)return null;const P=De(o,e);if(!P||!C)return null;const{scene:T}=P,M=v==null?void 0:v.getCurrentSkeleton(),x=C.getViewPort(),A=T==null?void 0:T.scaleX,D=T==null?void 0:T.scaleY,k=T==null?void 0:T.getViewportScrollXY(x);if(!A||!T||!A||!D||!k)return null;const H=(M==null?void 0:M.getNoMergeCellWithCoordByIndex(d.row,d.col).endX)||0,N=(M==null?void 0:M.getNoMergeCellWithCoordByIndex(d.row,d.col).endY)||0,V=y.convertTransformToOffsetX(H,A,k),L=y.convertTransformToOffsetY(N,D,k);if(V==null||L==null)return null;const U=X=>{c(X)},F=X=>{n.executeCommand(br.id,{type:X.value}),c(!1)},B=l||S,z=i.filter(X=>!X.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:`${V+2}px`,top:`${L+2}px`},onMouseEnter:_,onMouseLeave:R,children:b.jsx(j.DropdownMenu,{align:"start",items:z.map(X=>({type:"radio",value:h,options:[{label:r.t(X.label),value:X.value}],onSelect:()=>F(X)})),open:l,onOpenChange:U,children:b.jsxs("div",{className:j.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",j.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-800":l,"univer-bg-white dark:!univer-bg-gray-900":!l}),children:[b.jsx(Cl,{className:"univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-white"}),B&&b.jsx(wn,{className:"dark:!univer-text-white"})]})})})})}function ps(n,o){const e=I.useDependency(he),t=I.useDependency(a.ICommandService);return W.useMemo(()=>({keyCodes:[{keyCode:I.KeyCode.ENTER},{keyCode:I.KeyCode.ESC},{keyCode:I.KeyCode.TAB}],handler:i=>{(i===I.KeyCode.ENTER||i===I.KeyCode.ESC||i===I.KeyCode.TAB)&&(e.disableForceKeepVisible(),t.syncExecuteCommand(Se.id,{visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:i,unitId:o}))}}),[t,e,o])}const so=-1e3,ia={width:0,height:0,top:so,left:so},Qh=()=>{const[n,o]=W.useState({...ia}),e=I.useDependency(Un),t=I.useDependency(Q.IEditorService),r=I.useDependency(a.IContextService),i=I.useDependency(I.ComponentManager),s=I.useDependency(he),l=I.useObservable(s.visible$),c=I.useDependency(a.ICommandService),d=W.useRef(0),u=I.useObservable(()=>r.subscribeContextValue$(I.DISABLE_AUTO_FOCUS_KEY),!1,void 0,[r,I.DISABLE_AUTO_FOCUS_KEY]),h=i.get(Mo),g=s.getEditLocation();W.useEffect(()=>{const v=e.state$.subscribe(C=>{if(C==null)return;const{startX:_=so,startY:R=so,endX:w=0,endY:P=0,show:T=!1}=C;if(!T)o({...ia});else{o({width:w-_,height:P-R,left:_,top:R});const M=t.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(M==null)return;const{left:x,top:A,width:D,height:k}=M.getBoundingClientRect();e.setRect({left:x,top:A,width:D,height:k})}});return()=>{v.unsubscribe()}},[]),W.useEffect(()=>{u||e.setFocus(!0)},[u,n]);const S=I.useEvent(()=>{s.isVisible().visible&&c.executeCommand(Se.id,{visible:!1,eventType:y.DeviceInputEventType.PointerUp,unitId:g==null?void 0:g.unitId})});I.useSidebarClick(S);const f=ps(d,g==null?void 0:g.unitId),p=I.useEvent((v,C)=>{c.executeCommand(Wt.id,{keycode:v,visible:!1,eventType:y.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:p,isSupportAcrossSheet:!0,resetSelectionOnBlur:!1,isSingle:!1,autoScrollbar:!1,onFormulaSelectingChange:(v,C)=>{d.current=v,C&&(v?s.enableForceKeepVisible():s.disableForceKeepVisible())},disableSelectionOnClick:!0,disableContextMenu:!1})})};class bl{constructor(){E(this,"_position",null);E(this,"_position$",new O.BehaviorSubject(null));E(this,"position$",this._position$.asObservable());E(this,"_focus",!1);E(this,"_focus$",new O.BehaviorSubject(this._focus));E(this,"focus$",this._focus$.asObservable());E(this,"_fxBtnClick$",new O.Subject);E(this,"fxBtnClick$",this._fxBtnClick$.asObservable());E(this,"_foldBtnStatus$",new O.Subject);E(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 Ln=a.createIdentifier("univer.sheet-formula-editor-manager.service");function Jh(){const n=I.useDependency(a.ICommandService),o=I.useDependency(a.LocaleService),e=I.useDependency(G.IDefinedNamesService),t=I.useDependency(a.IUniverInstanceService),r=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]=W.useState(l());W.useEffect(()=>{const g=e.update$.subscribe(()=>{d(l())});return()=>{g.unsubscribe()}},[]),W.useEffect(()=>{const g=r.sidebarOptions$.subscribe(S=>{S.id===lr&&(S.visible||setTimeout(()=>{r.sidebarOptions$.next({visible:!1})}))});return()=>{g.unsubscribe()}},[]);const u=()=>{n.executeCommand(Uo.id,{value:"open"})},h=async g=>{const{formulaOrRefString:S,id:f}=g,p=e.getWorksheetByRef(s,S);if(!p)return;p.isSheetHidden()&&await n.executeCommand(m.SetWorksheetShowCommand.id,{unitId:s,subUnitId:p.getSheetId()}),e.focusRange(s,f)};return b.jsxs("div",{className:"univer-w-[300px]",children:[b.jsx("ul",{className:j.clsx("univer-m-0 univer-max-h-[360px] univer-list-none univer-overflow-y-auto univer-p-0",j.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:j.clsx("univer-flex univer-items-center univer-justify-between univer-gap-2 univer-py-1",j.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 $h({disable:n}){const[o,e]=W.useState(""),t=I.useDependency(G.IDefinedNamesService);W.useEffect(()=>{const i=t.currentRange$.subscribe(()=>{e(t.getCurrentRangeForString())});return()=>{i.unsubscribe()}},[]);function r(){}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:j.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",j.borderRightClassName,{"univer-cursor-not-allowed":n}),type:"text",value:o,onChange:r}),b.jsx(j.Dropdown,{overlay:b.jsx("div",{className:"univer-z-[1001]",children:b.jsx(Jh,{})}),disabled:n,children:b.jsx("a",{className:j.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 Rl(n){var q,te,ce,ne;const{className:o,disableDefinedName:e}=n,[t,r]=W.useState(!1),[i,s]=W.useState(0),l=I.useDependency(Ln),c=I.useDependency(he),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),p=I.useDependency(a.ICommandService),[v,C]=W.useState({editDisable:!1,viewDisable:!1}),[_,R]=W.useState(!1),w=I.useDependency(I.ComponentManager),P=I.useObservable(()=>h.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),T=W.useRef(0),M=I.useObservable(c.currentEditCellState$),x=ps(T,(q=M==null?void 0:M.unitId)!=null?q:""),A=w.get(Mo),D=I.useComponentsOfPart(cs.FORMULA_AUX),k=I.useDependency(a.IContextService);I.useObservable(W.useMemo(()=>k.subscribeContextValue$(a.FOCUSING_FX_BAR_EDITOR),[k]));const H=k.getContextValue(a.FOCUSING_FX_BAR_EDITOR),N=W.useRef(null),V=I.useDependency(Q.IEditorService);W.useLayoutEffect(()=>{const ie=P.activeSheet$.pipe(O.switchMap(ee=>ee?O.merge(d.ruleChange$,u.ruleChange$,g.selectionMoveEnd$,g.selectionSet$).pipe(O.switchMap(()=>{var ot,it;const me=P.getUnitId(),fe=ee.getSheetId();if(!((ot=g.getCurrentLastSelection())==null?void 0:ot.range))return O.EMPTY;const Re=(it=g.getCurrentLastSelection())==null?void 0:it.primary;return Re?O.of({unitId:me,subUnitId:fe,primary:Re}):O.of(null)})):O.EMPTY)).subscribe(ee=>{var me,fe,be,Re,ot,it;if(ee){const{unitId:It,subUnitId:Vr,primary:dd}=ee;if(d.getRule(It,Vr)){const md=!((fe=(me=S.getPermissionPoint(new m.WorksheetEditPermission(It,Vr).id))==null?void 0:me.value)==null||fe),gd=!((Re=(be=S.getPermissionPoint(new m.WorksheetViewPermission(It,Vr).id))==null?void 0:be.value)==null||Re);C({viewDisable:gd,editDisable:md});return}const{actualRow:ud,actualColumn:hd}=dd,Kt=f.getCellInfo(It,Vr,ud,hd);C({editDisable:!((ot=Kt==null?void 0:Kt[m.UnitAction.Edit])==null||ot),viewDisable:!((it=Kt==null?void 0:Kt[m.UnitAction.View])==null||it)})}else C({viewDisable:!1,editDisable:!1})});return()=>{ie.unsubscribe()}},[P]),W.useEffect(()=>{const ie=c.visible$.subscribe(ee=>{r(ee.visible)});return()=>ie.unsubscribe()},[c.visible$]),W.useEffect(()=>{const ie=c.currentEditCellState$.subscribe(ee=>{var me,fe,be;(be=(fe=(me=ee==null?void 0:ee.documentLayoutObject.documentModel)==null?void 0:me.getBody())==null?void 0:fe.customBlocks)!=null&&be.length?R(!0):R(!1)});return()=>ie.unsubscribe()},[c.currentEditCellState$]),W.useEffect(()=>{const ie=()=>{if(!N.current)return;const ee=N.current.getBoundingClientRect();l.setPosition(ee)};if(N.current){ie();const ee=new ResizeObserver(ie);return ee.observe(N.current),()=>ee.disconnect()}},[l]);function L(){s(i===0?1:0),setTimeout(()=>{l.handleFoldBtnClick(i===1)},150)}function U(){c.isVisible().visible&&p.executeCommand(Se.id,{visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ESC,unitId:M.unitId})}function F(){c.isVisible().visible&&p.executeCommand(Se.id,{visible:!1,eventType:y.DeviceInputEventType.PointerDown,unitId:M.unitId})}function B(){l.handleFxBtnClick(!0)}const{viewDisable:z,editDisable:X}=v,K=X||_,re=W.useRef(!1),oe=()=>{try{if(c.isVisible().visible===!1&&!p.syncExecuteCommand(Se.id,{visible:!0,eventType:y.DeviceInputEventType.PointerDown,unitId:M.unitId})){re.current=!0;return}k.setContextValue(a.FOCUSING_FX_BAR_EDITOR,!0)}catch(ie){throw re.current=!0,ie}},le=()=>{re.current&&setTimeout(()=>{V.blur(!0)},30),re.current=!1},Y=((ne=(ce=(te=M==null?void 0:M.documentLayoutObject.documentModel)==null?void 0:te.getDrawingsOrder())==null?void 0:ce.length)!=null?ne:0)>0||z;return b.jsxs("div",{"data-u-comp":"formula-bar",className:j.clsx("univer-box-border univer-flex univer-bg-white univer-transition-[height] univer-ease-linear dark:!univer-bg-gray-900",j.borderBottomClassName,o,{"univer-h-7":i===0,"univer-h-20":i===1,"univer-pointer-events-none":X}),children:[b.jsx("div",{className:"univer-relative univer-box-border univer-h-full univer-w-[100px]",children:b.jsx($h,{disable:e!=null?e:X})}),b.jsxs("div",{className:"univer-flex univer-h-full univer-w-full",children:[b.jsx("div",{className:j.clsx("univer-py-1.5",{"univer-cursor-not-allowed univer-text-gray-200":K}),children:b.jsxs("div",{className:j.clsx("univer-relative univer-box-border univer-flex univer-h-full univer-w-20 univer-items-center univer-justify-center univer-text-xs",j.borderRightClassName),children:[b.jsx("span",{className:j.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(dl,{})}),b.jsx("span",{className:j.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:F,children:b.jsx(Zt,{})}),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:B,children:b.jsx(gl,{})})]})}),b.jsxs("div",{className:"univer-flex univer-w-full univer-flex-1 univer-overflow-hidden univer-pl-3",children:[b.jsxs("div",{ref:N,className:"univer-relative univer-flex-1",onPointerDown:oe,onPointerUp:le,style:{pointerEvents:Y?"none":"auto"},children:[A&&b.jsx(A,{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:H,unitId:M==null?void 0:M.unitId,subUnitId:M==null?void 0:M.sheetId,isSupportAcrossSheet:!0,resetSelectionOnBlur:!1,isSingle:!1,keyboardEventConfig:x,onFormulaSelectingChange:(ie,ee)=>{T.current=ie,ee&&(ie?c.enableForceKeepVisible():c.disableForceKeepVisible())},autoScrollbar:!1,disableContextMenu:!1}),Y&&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:j.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":X}),onClick:L,children:b.jsx(hl,{className:j.clsx({"univer-rotate-180":i===1})})})]})]}),b.jsx(I.ComponentContainer,{components:D},"formula-aux")]})}function Zr(n){const{children:o,className:e,style:t,disabled:r=!1,onClick:i,...s}=n,l=c=>{if(r){c.preventDefault();return}i&&i(c)};return b.jsx(j.Button,{"data-u-comp":"sheet-bar-append-button",className:e,size:"small",disabled:r,style:t,variant:"text",onClick:l,...s,children:o})}function em(){const[n,o]=W.useState([]),[e,t]=W.useState(!1),r=I.useDependency(a.IUniverInstanceService),i=I.useDependency(a.ICommandService),s=I.useDependency(Yt),l=I.useDependency(m.WorksheetProtectionRuleModel),c=I.useObservable(()=>r.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),null,!1,[]),d=p=>{const{sheetId:v}=p;!v||!c||(p.hidden?i.executeCommand(m.SetWorksheetShowCommand.id,{unitId:c.getUnitId(),subUnitId:v,value:v}):p.selected||i.executeCommand(m.SetWorksheetActivateCommand.id,{unitId:c.getUnitId(),subUnitId:v}),t(!1))},u=W.useCallback(()=>{if(!c)return;const p=c.getSheets(),v=c.getActiveSheet(),C=p.map((_,R)=>({label:_.getName(),index:`${R}`,sheetId:_.getSheetId(),hidden:_.isSheetHidden()===a.BooleanNumber.TRUE,selected:v===_}));o(C)},[c,l]),h=W.useCallback(()=>i.onCommandExecuted(p=>{switch(p.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}}),[i,u]);function g(){t(!0)}const S=p=>{t(p)};W.useEffect(()=>{u();const p=new a.DisposableCollection;return p.add(h()),p.add(s.registerSheetBarMenuHandler({handleSheetBarMenu:g})),()=>p.dispose()},[h,s,u,c]);const f=W.useMemo(()=>n.map(p=>({type:"item",children:b.jsxs("div",{className:"univer-relative univer-box-border univer-pl-6",children:[(p.selected||p.hidden)&&b.jsxs("span",{className:"univer-absolute univer-left-1 univer-top-0.5",children:[p.selected&&b.jsx(Zt,{className:"univer-size-4 univer-text-primary-600"}),p.hidden&&b.jsx(ml,{className:"univer-size-4 univer-text-gray-400"})]}),b.jsx("span",{className:j.clsx({"univer-text-primary-600":p.selected}),children:p.label})]}),onSelect:()=>{d(p)}})),[n]);return b.jsx(j.DropdownMenu,{align:"start",items:f,open:e,onOpenChange:S,children:b.jsx("div",{children:b.jsx(Zr,{children:b.jsx(ul,{})})})})}function tm(n){const{sheetId:o,label:e,color:t,selected:r,menuOverlay:i}=n,[s,l]=W.useState(r),c=I.useDependency(a.ThemeService);W.useEffect(()=>{l(r)},[r]);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:j.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 nm={easeOutStrong(n,o,e,t){return-e*((n=n/t-1)*n*n*n-1)+o},backOut(n,o,e,t,r){return typeof r>"u"&&(r=.7),e*((n=n/t-1)*n*((r+1)*n+r)+1)+o}},rm={loop:!1,begin:0,end:0,duration:300,delay:0,type:"easeOutStrong",receive(n){},success(n){},cancel(n){},complete(n){}};class om{constructor(o){E(this,"_config");E(this,"_status",0);E(this,"_start",0);E(this,"_handle",0);E(this,"_delayHandle",null);this._config={...rm,...o},this._config.loop&&(this._config.complete=()=>{},this._config.success=()=>{this.request()})}static success(...o){let e=0;return new Promise(t=>{for(let r=0;r<o.length;r++){const i=o[r],s=i._config,l=s.success;s.loop||(s.success=d=>{e++,l&&l.call(i,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=nm[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 At{constructor(o,e){E(this,"_slideTabItem");E(this,"_animate");E(this,"_midline",0);E(this,"_translateX");E(this,"_scrollbar");E(this,"_slideTabBar");E(this,"_editMode");E(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(r=>t.push(new At(r,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&&dn.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"),r=d=>{if(!this.nameCheck()){if(this._editMode=!1,t&&(t.removeAttribute("contentEditable"),t.removeEventListener("focusout",r),t.removeEventListener("compositionstart",s),t.removeEventListener("compositionend",l),t.removeEventListener("input",c),t.removeEventListener("keydown",i)),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 i=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),dn.keepLastIndex(t))}},0)};t&&(t.setAttribute("contentEditable","true"),t.addEventListener("focusout",r),t.addEventListener("compositionstart",s),t.addEventListener("compositionend",l),t.addEventListener("input",c),t.addEventListener("keydown",i),this._editMode=!0,dn.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 om({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=At.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),r=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,r){const i=getComputedStyle(r).padding;this._slideTabItem.style.padding=i}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=At.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 im{constructor(o){E(this,"_slideTabBar");E(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 sn=class sn{constructor(o){E(this,"_activeTabItemIndex",0);E(this,"_slideTabBar");E(this,"_slideTabItems",[]);E(this,"_config");E(this,"_downActionX",0);E(this,"_moveActionX",0);E(this,"_compareIndex",0);E(this,"_activeTabItem",null);E(this,"_moveAction");E(this,"_upAction");E(this,"_downAction");E(this,"_wheelAction");E(this,"_scrollIncremental",0);E(this,"_compareDirection",0);E(this,"_autoScrollTime",null);E(this,"_slideScrollbar");E(this,"_longPressTimer",null);E(this,"_leftBoundingLine",0);E(this,"_rightBoundingLine",0);E(this,"_leftMoveX",0);E(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 im(this),this._config=o,this._initConfig();let t=0,r=0,i=0;this._downAction=s=>{var P,T,M,x,A,D;if((P=this._activeTabItem)!=null&&P.isEditMode())return;this._longPressTimer&&(clearTimeout(this._longPressTimer),this._longPressTimer=null);const l=(M=(T=s.target)==null?void 0:T.closest(`${o.slideTabBarItemSelector}`))==null?void 0:M.getAttribute("data-id"),c=this._slideTabItems.findIndex(k=>k.getId()===l);if(l==null||c===-1)return;if(this._activeTabItemIndex!==c){(x=this._activeTabItem)==null||x.removeEventListener("pointermove",this._moveAction),(A=this._activeTabItem)==null||A.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),(D=this._activeTabItem)==null||D.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:p,pageY:v}=s,C=Date.now(),_=C-i<=sn.DoubleClickDelay,R=Math.abs(p-t)<10,w=Math.abs(v-r)<10;_&&R&&w&&this._activeTabItem.setEditor(),t=p,r=v,i=C,this._longPressTimer=setTimeout(()=>{var k,H,N;!d||(k=this._activeTabItem)!=null&&k.isEditMode()||((H=this._activeTabItem)==null||H.enableFixed(),this._startAutoScroll(),d.setPointerCapture(s.pointerId),d.style.cursor="move",(N=this._activeTabItem)==null||N.addEventListener("pointermove",this._moveAction))},sn.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(r=>{const i=this._slideTabBar.getBoundingClientRect(),s=i.left+i.width,l=r.getSlideTabItem().getBoundingClientRect(),c=l.left,d=l.width;return c<s&&c+d+t*2>s?(e=o?c-i.left-t:c+d-s+t,!0):!1}),e}calculateRightScrollX(o){let e=0;const t=4;return this._slideTabItems.some(r=>{const i=this._slideTabBar.getBoundingClientRect(),s=i.left,l=r.getSlideTabItem().getBoundingClientRect(),c=l.left,d=l.width;return c-t*2<s&&c+d>s?(e=o?c+d-i.left-i.width+t:c-s-t,!0):!1}),e}calculateTabItemScrollX(o){let e=0;const t=4,r=this._slideTabBar.getBoundingClientRect(),i=r.left,s=r.left+r.width,l=this._slideTabItems[o].getSlideTabItem().getBoundingClientRect(),c=l.left,d=l.width;return c-t*2<i&&(e=c-i-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(),r=t.left,i=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<r&&l+c>r&&(o=l-r-e),l<i&&l+c+e*2>i&&(o=l+c-i+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(i=>i.equals(this._activeTabItem)),e=this._slideTabItems.length,t=[];for(let i=0;i<o&&!(i>=o);i++)t.push(this._slideTabItems[i]);for(let i=o+1;i<e;i++)this._slideTabItems[i].animate().translateX(0);let r=!0;for(let i=t.length-1;i>=0;i--){const s=t[i];At.leftLine(this._activeTabItem)<s.getMidLine()?(s.animate().translateX(this._activeTabItem.getWidth()),this._compareIndex=i,r=!1):(s.animate().translateX(0),r&&(this._compareIndex=this._activeTabItemIndex))}}}_compareRight(){if(this._activeTabItem){const o=this._slideTabItems.findIndex(i=>i.equals(this._activeTabItem)),e=this._slideTabItems.length,t=[];for(let i=o+1;i<e;i++)t.push(this._slideTabItems[i]);for(let i=0;i<o;i++)this._slideTabItems[i].animate().translateX(0);let r=!0;for(let i=0;i<t.length;i++){const s=t[i];At.rightLine(this._activeTabItem)>s.getMidLine()?(s.animate().translateX(-this._activeTabItem.getWidth()),this._compareIndex=o+i+1,r=!1):(s.animate().translateX(0),r&&(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=At.make(o,this),this._activeTabItemIndex=this._config.currentIndex,this._activeTabItem=this._slideTabItems[this._activeTabItemIndex]}};E(sn,"LongPressDelay",500),E(sn,"DoubleClickDelay",300);let dn=sn;function sm(){var le;const[n,o]=W.useState([]),[e,t]=W.useState(""),[r,i]=W.useState(""),[s,l]=W.useState(!1),[c,d]=W.useState([0,0]),u=W.useRef({slideTabBar:null}),h=W.useRef(null),g=I.useDependency(a.ICommandService),S=I.useDependency(Yt),f=I.useDependency(a.LocaleService),p=I.useDependency(I.IConfirmService),v=I.useDependency(he,a.Quantity.OPTIONAL),C=I.useDependency(m.WorksheetProtectionRuleModel),_=I.useDependency(m.RangeProtectionRuleModel),R=I.useObservable(C.resetOrder$),w=vt(),P=I.useDependency(a.IPermissionService),T=W.useCallback(()=>{var ce;const Z=((ce=w.getActiveSheet())==null?void 0:ce.getSheetId())||"";t(Z);const Y=w.getSheets(),q=w.getActiveSheet(),te=Y.filter(ne=>!ne.isSheetHidden()).map((ne,ie)=>{var Re;const ee=C.getRule(w.getUnitId(),ne.getSheetId()),me=_.getSubunitRuleList(w.getUnitId(),ne.getSheetId()).length>0,be=(ee==null?void 0:ee.permissionId)||me?b.jsxs(b.Fragment,{children:[b.jsx(gs,{}),b.jsx("span",{className:"univer-outline-none",children:ne.getName()})]}):b.jsx("span",{className:"univer-outline-none",children:ne.getName()});return{sheetId:ne.getSheetId(),label:be,index:ie,selected:q===ne,color:(Re=ne.getTabColor())!=null?Re:void 0}});o(te),t(Z)},[_,w,C]);W.useEffect(()=>{T();const{slideTabBar:Z,disconnectResizeObserver:Y}=M(),q=U(),te=[F(),B(),z()];return()=>{q.dispose(),Z.destroy(),te.forEach(ce=>ce.unsubscribe()),Y&&Y()}},[R,w]),W.useEffect(()=>{n.length>0&&L()},[n]),W.useEffect(()=>{const Z=O.merge(C.ruleChange$,_.ruleChange$).subscribe(()=>{T()});return()=>{Z.unsubscribe()}},[C,T]);const M=()=>{const Z=new dn({slideTabBarSelector:"[data-u-comp=slide-tab-bar]",slideTabBarItemSelector:"[data-u-comp=slide-tab-item]",slideTabBarItemAutoSort:!0,slideTabBarContainer:h.current,currentIndex:0,onChangeName:(q,te)=>{g.executeCommand(m.SetWorksheetNameCommand.id,{subUnitId:q,name:te})},onSlideEnd:async(q,te)=>{await g.executeCommand(m.SetWorksheetOrderCommand.id,{order:te})},onChangeTab:(q,te)=>{g.executeCommand(m.SetWorksheetActiveOperation.id,{subUnitId:te,unitId:w.getUnitId()}).then(()=>{q.button===2&&oe(!0)})},onScroll:q=>{S.setScroll(q)},onNameCheckAlert:q=>D(q)||k(q)||H(q),onNameChangeCheck:()=>{var ee,me,fe,be;const q=w.getUnitId(),te=w==null?void 0:w.getActiveSheet();if(!te)throw new Error("No active sheet found");const ce=te.getSheetId(),ne=C.getRule(q,ce),ie=_.getSubunitRuleList(q,ce).length>0;return ne||ie?(me=(ee=P.getPermissionPoint(new m.WorkbookManageCollaboratorPermission(q).id))==null?void 0:ee.value)!=null?me:!1:(be=(fe=P.getPermissionPoint(new m.WorkbookRenameSheetPermission(q).id))==null?void 0:fe.value)!=null?be:!1}});u.current.slideTabBar=Z;const Y=re(Z);return{slideTabBar:Z,disconnectResizeObserver:Y}},x=I.useConfigValue(I.UI_PLUGIN_CONFIG_KEY),A=(le=x==null?void 0:x.contextMenu)!=null?le:!0,D=Z=>{if(Z.trim()===""){const Y="sheetNameEmptyAlert";return p.open({id:Y,title:{title:f.t("sheetConfig.sheetNameErrorTitle")},children:{title:f.t("sheetConfig.sheetNameCannotIsEmptyError")},cancelText:f.t("button.cancel"),confirmText:f.t("button.confirm"),onClose(){N(),p.close(Y)},onConfirm(){N(),p.close(Y)}}),!0}return!1},k=Z=>{if(!a.nameCharacterCheck(Z)){const Y="sheetNameSpecCharAlert";return p.open({id:Y,title:{title:f.t("sheetConfig.sheetNameErrorTitle")},children:{title:f.t("sheetConfig.sheetNameSpecCharError")},cancelText:f.t("button.cancel"),confirmText:f.t("button.confirm"),onClose(){N(),p.close(Y)},onConfirm(){N(),p.close(Y)}}),!0}return!1},H=Z=>{const Y=w.getActiveSheet();if((Y==null?void 0:Y.getName())===Z)return!1;const te=w.checkSheetName(Z);if(te){const ce="sheetNameRepeatAlert";p.open({id:ce,title:{title:f.t("sheetConfig.sheetNameErrorTitle")},children:{title:f.t("sheetConfig.sheetNameAlreadyExistsError")},cancelText:f.t("button.cancel"),confirmText:f.t("button.confirm"),onClose(){p.close(ce),N()},onConfirm(){p.close(ce),N()}})}return te},N=()=>{setTimeout(()=>{var Y;const Z=(Y=u.current.slideTabBar)==null?void 0:Y.getActiveItem();Z&&(Z.focus(),Z.selectAll())},0)},V=()=>{var Z,Y;(Y=(Z=u.current.slideTabBar)==null?void 0:Z.getActiveItem())==null||Y.setEditor()},L=()=>{var Y;const Z=n.findIndex(q=>q.selected);(Y=u.current.slideTabBar)==null||Y.update(Z)},U=()=>g.onCommandExecuted(Z=>{switch(Z.id){case m.SetTabColorMutation.id:case m.SetWorksheetHideMutation.id:case m.RemoveSheetMutation.id:case m.SetWorksheetNameMutation.id:case m.InsertSheetMutation.id:case m.SetWorksheetOrderMutation.id:case m.SetWorksheetActiveOperation.id:T();break}}),F=()=>S.scroll$.subscribe(Z=>{X(Z)}),B=()=>S.scrollX$.subscribe(Z=>{var Y;(Y=u.current.slideTabBar)==null||Y.flipPage(Z)}),z=()=>S.renameId$.subscribe(()=>{V()}),X=Z=>{const{leftEnd:Y,rightEnd:q}=Z;let te="";Y&&q?te="":Y&&!q?te="inset -10px 0px 10px -10px rgba(0, 0, 0, 0.2)":!Y&&q?te="inset 10px 0px 10px -10px rgba(0, 0, 0, 0.2)":!Y&&!q&&(te="inset 10px 0px 10px -10px rgba(0, 0, 0, 0.2), inset -10px 0px 10px -10px rgba(0, 0, 0, 0.2)"),i(te)},K=Z=>{const Y=Z.calculateActiveTabItemScrollX();if(Y){const q=Z.getScrollbar();q.scrollX(q.getScrollX()+Y)}S.setScroll({leftEnd:Z.isLeftEnd(),rightEnd:Z.isRightEnd()})},re=Z=>{var te;const Y=(te=h.current)==null?void 0:te.querySelector("[data-u-comp=slide-tab-bar]");if(!Y)return;const q=new ResizeObserver(()=>{K(Z)});return q.observe(Y),()=>q.disconnect()},oe=Z=>{var Y,q,te,ce,ne;if(A&&!(v!=null&&v.isForceKeepVisible())){if(Z){const{left:ie}=(q=(Y=h.current)==null?void 0:Y.getBoundingClientRect())!=null?q:{},{left:ee}=(ne=(ce=(te=u.current.slideTabBar)==null?void 0:te.getActiveItem())==null?void 0:ce.getSlideTabItem().getBoundingClientRect())!=null?ne:{};ie!==void 0&&ee!==void 0&&d([ee-ie,0])}l(Z)}};return b.jsx(j.DropdownLegacy,{className:"univer-select-none",visible:s,align:{offset:c},trigger:["contextMenu"],overlay:b.jsx(I.UIMenu,{menuType:I.ContextMenuPosition.FOOTER_TABS,onOptionSelect:Z=>{const{label:Y,value:q,commandId:te}=Z;g.executeCommand(te!=null?te:Y,{value:q,subUnitId:e}),l(!1)}}),onVisibleChange:oe,children:b.jsx("div",{className:"univer-max-w-[calc(100%-112px)] univer-overflow-hidden",ref:h,onDragStart:Z=>Z.preventDefault(),onContextMenu:Z=>Z.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:r},children:n.map(Z=>W.createElement(tm,{...Z,key:Z.sheetId,selected:e===Z.sheetId}))})})})}const sa=100,wl=()=>{var p,v;const[n,o]=W.useState(!0),[e,t]=W.useState(!0),r=I.useDependency(a.ICommandService),i=I.useDependency(Yt),s=I.useDependency(a.IPermissionService),c=vt().getUnitId(),d=I.useObservable(s.getPermissionPoint$((p=new m.WorkbookEditablePermission(c))==null?void 0:p.id)),u=I.useObservable(s.getPermissionPoint$((v=new m.WorkbookCreateSheetPermission(c))==null?void 0:v.id)),h=C=>{const{leftEnd:_,rightEnd:R}=C;o(_),t(R)};W.useEffect(()=>{const C=i.scroll$.subscribe(a.throttle(_=>{h(_)},100));return()=>{C.unsubscribe()}},[]);const g=()=>{r.executeCommand(m.InsertSheetCommand.id),setTimeout(()=>{i.setAddSheet(0)},0)},S=()=>{i.setScrollX(-sa)},f=()=>{i.setScrollX(sa)};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(Zr,{className:"univer-mr-2",onClick:g,disabled:!(u!=null&&u.value&&(d!=null&&d.value)),children:b.jsx(ms,{})}),b.jsx(em,{})]}),b.jsx(sm,{}),(!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(Zr,{disabled:n,onClick:S,children:b.jsx(Ni,{className:"univer-rotate-180"})}),b.jsx(Zr,{disabled:e,onClick:f,children:b.jsx(Ni,{})})]})]})},am=[50,75,100,125,150,175,200,400];function lm(){const n=I.useDependency(a.ICommandService),o=I.useDependency(a.IUniverInstanceService),e=vt(),t=I.useDependency(he),r=I.useObservable(t.visible$),i=W.useCallback(()=>{if(!e)return 100;const u=e.getActiveSheet(),h=u&&u.getZoomRatio()*100||100;return Math.round(h)},[e]),[s,l]=W.useState(()=>i());W.useEffect(()=>(l(i()),n.onCommandExecuted(h=>{if(h.id===Ye.id||h.id===m.SetWorksheetActiveOperation.id){const g=i();l(g)}}).dispose),[n,i]);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(Wn.id,{unitId:h.getUnitId(),subUnitId:g.getSheetId(),zoomRatio:S})}const d=(r==null?void 0:r.visible)&&(r.unitId===(e==null?void 0:e.getUnitId())||r.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);return b.jsx(I.Slider,{disabled:d,min:yi[0],value:s,shortcuts:am,onChange:c})}function cm(){return b.jsx("section",{className:"univer-flex univer-flex-shrink-0 univer-justify-end",children:b.jsx(lm,{})})}class vs{constructor(){E(this,"_functions",[{func:G.FUNCTION_NAMES_STATISTICAL.MAX,filter:o=>{var e,t,r,i;return((t=(e=o.values.find(s=>s.func===G.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1&&((i=(r=o.values.find(s=>s.func===G.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:r.value)!=null?i:0)>0}},{func:G.FUNCTION_NAMES_STATISTICAL.MIN,filter:o=>{var e,t,r,i;return((t=(e=o.values.find(s=>s.func===G.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1&&((i=(r=o.values.find(s=>s.func===G.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:r.value)!=null?i:0)>0}},{func:G.FUNCTION_NAMES_MATH.SUM,filter:o=>{var e,t,r,i;return((t=(e=o.values.find(s=>s.func===G.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1&&((i=(r=o.values.find(s=>s.func===G.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:r.value)!=null?i:0)>0}},{func:G.FUNCTION_NAMES_STATISTICAL.COUNTA,filter:o=>{var e,t;return((t=(e=o.values.find(r=>r.func===G.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1}},{func:G.FUNCTION_NAMES_STATISTICAL.COUNT,filter:o=>{var e,t,r,i;return((t=(e=o.values.find(s=>s.func===G.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1&&((i=(r=o.values.find(s=>s.func===G.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:r.value)!=null?i:0)>0}},{func:G.FUNCTION_NAMES_STATISTICAL.AVERAGE,filter:o=>{var e,t,r,i;return((t=(e=o.values.find(s=>s.func===G.FUNCTION_NAMES_STATISTICAL.COUNTA))==null?void 0:e.value)!=null?t:0)>1&&((i=(r=o.values.find(s=>s.func===G.FUNCTION_NAMES_STATISTICAL.COUNT))==null?void 0:r.value)!=null?i:0)>0}}]);E(this,"_state$",new O.BehaviorSubject(null));E(this,"state$",this._state$.asObservable())}dispose(){this._state$.complete()}setState(o){var t;const e={values:[],pattern:null};o==null||o.values.forEach(r=>{const i=this._functions.find(s=>s.func===r.func);i&&(i.filter===void 0||i.filter(o))&&e.values.push(r)}),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 kr=a.createIdentifier("univer.sheet-status-bar.service"),dm=[G.FUNCTION_NAMES_MATH.SUM,G.FUNCTION_NAMES_STATISTICAL.AVERAGE,G.FUNCTION_NAMES_STATISTICAL.MIN,G.FUNCTION_NAMES_STATISTICAL.MAX],Gr={[G.FUNCTION_NAMES_MATH.SUM]:"statusbar.sum",[G.FUNCTION_NAMES_STATISTICAL.AVERAGE]:"statusbar.average",[G.FUNCTION_NAMES_STATISTICAL.MIN]:"statusbar.min",[G.FUNCTION_NAMES_STATISTICAL.MAX]:"statusbar.max",[G.FUNCTION_NAMES_STATISTICAL.COUNT]:"statusbar.count",[G.FUNCTION_NAMES_STATISTICAL.COUNTA]:"statusbar.countA",[G.FUNCTION_NAMES_TEXT.CONCATENATE]:"concatenate"},um=n=>{const o=I.useDependency(a.LocaleService),e=I.useDependency(I.IMessageService),t=I.useDependency(I.IClipboardInterfaceService),r=hm(n),i=async()=>{await t.writeText(n.value.toString()),e.show({type:j.MessageType.Success,content:o.t("statusbar.copied")})};return b.jsx(j.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:i,children:b.jsx("span",{children:`${o.t((Gr==null?void 0:Gr[n.name])||n.name)}: ${r}`})},n.name)})};function hm(n){const{pattern:o,value:e}=n;return typeof e!="number"?0:e>=1e8?e.toExponential(2):o&&dm.includes(n.name)?a.numfmt.format(o,e,{throws:!1}):e.toLocaleString()}const aa=800,mm=3,gm=()=>{var h,g;const n=(g=(h=I.useConfigValue(Ee))==null?void 0:h.statusBarStatistic)!=null?g:!0,[o,e]=W.useState(window.innerWidth<aa),t=I.useDependency(kr),r=t.getFunctions().map((S,f)=>({name:S.func,value:0,show:!0,disable:!1,pattern:null})),i=(S,f,p,v)=>{const[C,_]=W.useState(S),[R,w]=W.useState(!0),P=W.useMemo(()=>C.filter(A=>A.show&&!A.disable),[C]),T=W.useMemo(()=>P.find(A=>A.show&&!A.disable),[P]),M=W.useMemo(()=>p&&T?[T]:P,[p,T,P]),x=W.useCallback(A=>{const D=A==null?void 0:A.values;if(!(D!=null&&D.length)){w(!1);return}w(!0),_(k=>k.map(H=>{var N,V,L;return{...H,value:(V=(N=D.find(U=>U.func===H.name))==null?void 0:N.value)!=null?V:H.value,disable:!D.some(U=>U.func===H.name),pattern:(L=A==null?void 0:A.pattern)!=null?L:null}}))},[]);return W.useEffect(()=>{if(!v)return;const A=f.state$.subscribe(x);return()=>A.unsubscribe()},[v,f,x]),{statistics:C,showList:M,show:R}},{showList:s,show:l}=i(r,t,o,n),c=a.debounce(()=>{const S=window.innerWidth<aa;o!==S&&e(S)},100);W.useEffect(()=>(window.addEventListener("resize",c),()=>{window.removeEventListener("resize",c)}),[o]);const u=((S,f,p)=>n?W.useMemo(()=>S.length>f?S.reduce((_,R,w)=>(w%2===0&&_.push(S.slice(w,w+2)),_),[]).map((_,R)=>b.jsxs("div",{className:"univer-grid univer-h-full univer-items-center",children:[_[0]&&b.jsx(p,{..._[0]},_[0].name),_[1]&&b.jsx(p,{..._[1]},_[1].name)]},`stat-col-${R}`)):S.map(C=>b.jsx("div",{className:"univer-grid univer-h-full univer-items-center",children:b.jsx(p,{...C})},C.name)),[S,f,p]):null)(s,mm,um);return l&&b.jsx("div",{className:j.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})})},El=36;function Tl(){var d;const n=I.useConfigValue(Ee),o=I.useDependency(I.IMenuManagerService),e=(d=n==null?void 0:n.footer)!=null?d:!0;if(!vt()||!e)return null;const r=o.getMenuByPositionKey(I.ContextMenuPosition.FOOTER_MENU),{sheetBar:i=!0,statisticBar:s=!0,menus:l=!0,zoomSlider:c=!0}=(n==null?void 0:n.footer)||{};return!i&&!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:El},"data-range-selector":!0,children:[i&&b.jsx(wl,{}),s&&b.jsx(gm,{}),l&&r.length>0&&b.jsx("div",{className:"univer-box-border univer-flex univer-gap-2 univer-px-2",children:r.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(cm,{})]})}function yl(){const n=I.useConfigValue(Ee);return Ml()&&(n==null?void 0:n.formulaBar)!==!1?b.jsx(Rl,{}):null}function Cs(){return Ml()?b.jsxs(b.Fragment,{children:[b.jsx(Qh,{}),b.jsx(qh,{})]}):null}function Ml(){const n=I.useDependency(a.IUniverInstanceService),e=!!I.useObservable(()=>n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),null,!1,[]);return W.useMemo(()=>n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).length>0,[n,e])}var Sm=Object.getOwnPropertyDescriptor,fm=(n,o,e,t)=>{for(var r=t>1?void 0:t?Sm(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},en=(n,o)=>(e,t)=>o(e,t,n);const la=5,ca=2;exports.SheetCellEditorResizeService=class extends a.Disposable{constructor(o,e,t,r,i,s){super(),this._layoutService=o,this._cellEditorManagerService=e,this._editorBridgeService=t,this._renderManagerService=r,this._univerInstanceService=i,this._configService=s}get _currentRenderer(){return y.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(exports.SheetSkeletonManagerService)}get engine(){var o;return(o=this._renderer)==null?void 0:o.engine}fitTextSize(o){var A,D,k,H;const e=this._editorBridgeService.getEditCellState();if(!e)return;const{position:t,documentLayoutObject:r,canvasOffset:i,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,i,S,r,s,l);if(!f||f.actualWidth<=0)return;let{actualWidth:p,actualHeight:v}=f;const{verticalAlign:C,horizontalAlign:_,paddingData:R,fill:w}=r;p=p+((A=R.l)!=null?A:0)+((D=R.r)!=null?D:0),v=v+((k=R.t)!=null?k:0)+((H=R.b)!=null?H:0);let P=u-c,T=h-d;P<p&&(P=Math.ceil(p)),T<v&&(T=Math.ceil(v));let M=0;C===a.VerticalAlign.MIDDLE?M=(T-v)/2/l:C===a.VerticalAlign.TOP?M=R.t||0:M=(T-v)/l;let x=0;_===a.HorizontalAlign.CENTER||(_===a.HorizontalAlign.RIGHT?x=(P-p)/s:x=R.l||0),M=M<(R.t||0)?R.t||0:M,x=x<(R.l||0)?R.l||0:x,g.updateDocumentDataMargin({t:M,l:x}),S.calculate(),this._editAreaProcessing(P,T,t,i,w,s,l,_,o)}_predictingSize(o,e,t,r,i=1,s=1){const{startX:l,endX:c}=o,{textRotation:d,wrapStrategy:u,paddingData:h}=r,g=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC),{vertexAngle:S}=y.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*i,actualHeight:_*s}}const f=this._getEditorMaxSize(o,e,r.horizontalAlign);if(!f)return;g==null||g.updateDocumentDataPageSize(f.width/i),t.calculate();const p=t.getActualSize();let v=c-l;return v<p.actualWidth*i+la*i&&(v=p.actualWidth*i+la*i),g==null||g.updateDocumentDataPageSize(v/i),g==null||g.updateDocumentRenderConfig({horizontalAlign:a.HorizontalAlign.UNSPECIFIED,cellValueType:void 0}),{actualWidth:p.actualWidth*i,actualHeight:p.actualHeight*s}}_getEditorMaxSize(o,e,t){var R,w,P,T;if(this._getEditorObject()==null)return;function i(M){return Number.parseInt(M.replace("px",""))}const s=this.engine;if(!s)return;const l=s.getCanvasElement(),c=l.getBoundingClientRect(),d=i(l.style.width),{width:u}=c,h=u/d,{startX:g,startY:S,endX:f}=o,p=s.width,v=((w=(R=this._configService.getConfig(I.UI_PLUGIN_CONFIG_KEY))==null?void 0:R.footer)==null||w)&&((T=(P=this._configService.getConfig(Ee))==null?void 0:P.footer)==null||T)?El:0,C=document.body.clientHeight-S-v-e.top-ca*2;let _=u-g;if(t===a.HorizontalAlign.CENTER){const M=p-f,x=g;_=f-g+Math.min(x,M)*2}else t===a.HorizontalAlign.RIGHT&&(_=f);return{height:C,width:_-ca,scaleAdjust:h}}_editAreaProcessing(o,e,t,r,i,s=1,l=1,c,d){var V;const u=this._getEditorObject();if(u==null)return;const h=this.engine;if(!h)return;const g=h.getCanvasElement();let{startX:S,startY:f}=t;const{document:p,scene:v,engine:C}=u,_=v.getViewport(Q.VIEWPORT_KEY.VIEW_MAIN),R=this._getEditorMaxSize(t,r,c),{height:w,width:P,scaleAdjust:T}=R;let M=e,x=_==null?void 0:_.getScrollBar();M>w?(x==null?_&&new y.ScrollBar(_,{enableHorizontal:!1,barSize:8}):_==null||_.resetCanvasSizeAndUpdateScroll(),_==null||_.scrollToViewportPos({viewportScrollY:M-w}),M=w):(x=null,(V=_==null?void 0:_.getScrollBar())==null||V.dispose()),o+=(x==null?void 0:x.barSize)||0,o>P&&(o=P),this._addBackground(v,o/s,e/l,i);const{scaleX:A,scaleY:D}=v.getPrecisionScale();v.transformByState({width:o*T/s,height:e*T/l,scaleX:s*T,scaleY:l*T}),p.resize(o*T/s,e*T/l),setTimeout(()=>{C.resizeBySize(y.fixLineWidthByScale(o,A),y.fixLineWidthByScale(M,D)),d==null||d()},0);const k=this._layoutService.getContentElement().getBoundingClientRect(),H=g.getBoundingClientRect();S=S*T+(H.left-k.left),f=f*T+(H.top-k.top);const N=t.endX-t.startX;c===a.HorizontalAlign.RIGHT?S+=(N-o)*T:c===a.HorizontalAlign.CENTER&&(S+=(N-o*T)/2),this._cellEditorManagerService.setState({startX:S,startY:f,endX:o*T+S,endY:M*T+f,show:!0})}_addBackground(o,e,t,r){const i="_backgroundRectHelperColor_",s=o.getObject(i);s==null&&r==null||(s==null?o.addObjects([new y.Rect(i,{width:e,height:t,fill:r,evented:!1})],Q.DOCS_COMPONENT_MAIN_LAYER_INDEX):r==null?s.dispose():(s.setProps({fill:r}),s.transformByState({width:e,height:t})))}resizeCellEditor(o){var T,M;const e=this._cellEditorManagerService.getState();if(!e||!this._editorBridgeService.isVisible().visible)return;this._editorBridgeService.refreshEditCellPosition(!0);const t=this._editorBridgeService.getEditCellState();if(!t)return;const r=(M=(T=this._sheetSkeletonManagerService)==null?void 0:T.getSkeletonParam(t.sheetId))==null?void 0:M.skeleton;if(!r)return;const{row:i,column:s,scaleX:l,scaleY:c,position:d,canvasOffset:u,documentLayoutObject:h}=t,{horizontalAlign:g}=h,S=this._getEditorMaxSize(d,u,g);if(!S)return;const{height:f,width:p,scaleAdjust:v}=S,C=r.getCellWithCoordByIndex(i,s),_=Math.min((C.mergeInfo.endY-C.mergeInfo.startY)*c,f)*v,R=Math.min((C.mergeInfo.endX-C.mergeInfo.startX)*l,p)*v,w=e.endY-e.startY,P=e.endX-e.startX;if(w!==_||P!==R){if(this._editorBridgeService.refreshEditCellPosition(!0),!this._getEditorSkeleton())return;this.fitTextSize(o)}}_getEditorObject(){return yo(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(ve.DocSkeletonManagerService).getSkeleton()}};exports.SheetCellEditorResizeService=fm([en(0,I.ILayoutService),en(1,Un),en(2,he),en(3,y.IRenderManagerService),en(4,a.IUniverInstanceService),en(5,a.IConfigService)],exports.SheetCellEditorResizeService);var pm=Object.getOwnPropertyDescriptor,vm=(n,o,e,t)=>{for(var r=t>1?void 0:t?pm(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},bt=(n,o)=>(e,t)=>o(e,t,n);let cr=class extends a.RxDisposable{constructor(o,e,t,r,i,s,l,c){super();E(this,"_d");this._context=o,this._instanceSrv=e,this._commandService=t,this._editorBridgeService=r,this._selectionManagerService=i,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(O.merge(this._selectionManagerService.selectionMoveEnd$,this._selectionManagerService.selectionSet$,this._selectionManagerService.selectionMoveStart$).subscribe(e=>this._updateEditorPosition(e)))}_updateEditorPosition(o){var t,r,i;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=(r=this._context.unit.getActiveSheet())==null?void 0:r.getSheetId();if(!u)return;const h=(i=this._sheetSkeletonManagerService.getSkeletonParam(u))==null?void 0:i.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(Ho.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:r,spreadsheetLeftTopPlaceholder:i,spreadsheetRowHeader:s}=e;o.add(t.onDblclick$.subscribeEvent(l=>{l.button!==2&&this._commandService.executeCommand(Se.id,{visible:!0,eventType:y.DeviceInputEventType.Dblclick,unitId:this._context.unitId})})),o.add(t.onPointerDown$.subscribeEvent({next:this._tryHideEditor.bind(this),priority:-1})),o.add(r.onPointerDown$.subscribeEvent({next:this._tryHideEditor.bind(this),priority:-1})),o.add(i.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=i=>{const s=i.with(Q.DocSelectionRenderService);s&&(e=a.toDisposable(s.onInputBefore$.subscribe(l=>{if(!this._isCurrentSheetFocused())return;const c=this._contextService.getContextValue(a.FOCUSING_FX_BAR_EDITOR),d=this._contextService.getContextValue(a.FOCUSING_SHEET),u=i.unitId;this._editorBridgeService.isVisible().visible||u&&d&&!c&&this._showEditorByKeyboard(l)})),o.add(e))},r=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);r?t(r):this.disposeWithMe(this._renderManagerService.created$.pipe(O.filter(i=>i.unitId===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)).subscribe(i=>{e==null||e.dispose(),t(i)}))}_commandExecutedListener(o){const e=new Set([m.ClearSelectionFormatCommand.id,Wn.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 r=t.params,{cellValue:i,unitId:s,subUnitId:l}=r;if(!i)return;const c=this._editorBridgeService.getEditLocation();if(c){const{unitId:d,sheetId:u,row:h,column:g}=c;s===d&&l===u&&i&&i[h]&&Object.prototype.hasOwnProperty.call(i[h],g)&&this._editorBridgeService.refreshEditCellState()}}})),o.add(this._commandService.beforeCommandExecuted((t,r)=>{r!=null&&r.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:y.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:y.DeviceInputEventType.PointerDown,unitId:this._context.unitId})}_getSheetObject(){return De(this._context.unit,this._context)}_isCurrentSheetFocused(){var o;return((o=this._instanceSrv.getFocusedUnit())==null?void 0:o.getUnitId())===this._context.unitId}};cr=vm([bt(1,a.IUniverInstanceService),bt(2,a.ICommandService),bt(3,he),bt(4,a.Inject(m.SheetsSelectionsService)),bt(5,a.IContextService),bt(6,y.IRenderManagerService),bt(7,a.Inject(exports.SheetSkeletonManagerService))],cr);const Pl=[I.KeyCode.ARROW_DOWN,I.KeyCode.ARROW_UP,I.KeyCode.ARROW_LEFT,I.KeyCode.ARROW_RIGHT],Cm=[I.KeyCode.ENTER,I.KeyCode.TAB,...Pl];function xl(){const n=[];for(const o of Pl)n.push({id:Wt.id,binding:o,preconditions:e=>fn(e),staticParameters:{visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:o,isShift:!1}}),n.push({id:Wt.id,binding:o|I.MetaKeys.SHIFT,preconditions:e=>fn(e),staticParameters:{visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:o,isShift:!0}});return n}const Ol={id:Ar.id,binding:I.KeyCode.F2,description:"shortcut.sheet.start-editing",group:"4_sheet-edit",preconditions:se,staticParameters:{visible:!0,eventType:y.DeviceInputEventType.Keyboard,keycode:I.KeyCode.F2}},Al={id:Se.id,binding:I.KeyCode.ENTER,description:"shortcut.sheet.toggle-editing",group:"4_sheet-edit",preconditions:n=>fn(n),staticParameters:{visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ENTER}},Dl={id:Se.id,binding:I.KeyCode.TAB,preconditions:n=>fn(n),staticParameters:{visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:I.KeyCode.TAB}},kl={id:Se.id,binding:I.KeyCode.ESC,description:"shortcut.sheet.abort-editing",group:"4_sheet-edit",preconditions:n=>fn(n),staticParameters:{visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ESC}},Nl={id:Se.id,binding:I.KeyCode.ENTER|I.MetaKeys.CTRL_COMMAND,mac:I.KeyCode.ENTER|I.MetaKeys.MAC_CTRL,preconditions:n=>fn(n),staticParameters:{visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ENTER|I.MetaKeys.CTRL_COMMAND}},Vl={id:Q.BreakLineCommand.id,description:"shortcut.sheet.break-line",group:"4_sheet-edit",preconditions:n=>qd(n),binding:I.KeyCode.ENTER|I.MetaKeys.ALT},Hl={id:Q.DeleteLeftCommand.id,preconditions:n=>Ji(n)||xo(n),binding:I.KeyCode.BACKSPACE},Wl={id:Q.DeleteRightCommand.id,preconditions:n=>Ji(n)||xo(n),binding:I.KeyCode.DELETE},Ul={id:Q.DeleteLeftCommand.id,preconditions:n=>Ji(n)||xo(n),binding:I.KeyCode.BACKSPACE|I.MetaKeys.SHIFT},Ll={id:Se.id,description:"shortcut.sheet.delete-and-start-editing",group:"4_sheet-edit",preconditions:n=>se(n)&&!xo(n),binding:I.KeyCode.BACKSPACE,staticParameters:{visible:!0,eventType:y.DeviceInputEventType.Keyboard,keycode:I.KeyCode.BACKSPACE}};function Im(n){return n.startsWith("'")}function _m(n){return n.slice(1)}const bm={"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","%":"%","-":"-",".":".",":":":","/":"/","+":"+","@":"@","&":"&","*":"*","#":"#","=":"=",">":">","<":"<","$":"$",""":'"',"'":"'","(":"(",")":")"," ":" ",",":",","!":"!","?":"?",";":";","[":"[","]":"]","{":"{","}":"}"},Vi={true:"TRUE",false:"FALSE"};function Rm(n){return[a.LocaleType.ZH_CN,a.LocaleType.ZH_TW].includes(n)}function wm(n,o,e,t){let r=n;if(Rm(e)){if(n.startsWith("'")||n.startsWith("'"))return`'${n.slice(1)}`;r=Em(r)}if(r.startsWith("="))return Tm(n,r,o,t);const i=r.toLowerCase();return Vi[i]?Vi[i]:a.numfmt.parseValue(r)==null?n:r}function Em(n){const o=/['"].*?['"]/g,e=[],t=n.split(o);n.replace(o,i=>(e.push(i),""));let r=t.join("").split("").map(Pm).join("");return e.forEach((i,s)=>{r=r.slice(0,s*2)+i+r.slice((s+1)*2)}),r}function Tm(n,o,e,t){const r=e.sequenceNodesBuilder(o);if(!r)return n;let i=o,s=0;return r.forEach((l,c)=>{if(typeof l=="object"){const d=l.token;if(Vi[d.toLowerCase()]){const u=l.startIndex+s+1,h=l.endIndex+s+2;i=tn(d.toLocaleUpperCase(),i,u,h)}else if(l.nodeType===G.sequenceNodeType.FUNCTION&&ym(d,t,r,c)||l.nodeType===G.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;i=tn(h.toLocaleUpperCase(),i,g,S)}else{const h=l.startIndex+s+1,g=l.endIndex+s+2;i=tn(d.toLocaleUpperCase(),i,h,g)}}else if(d.startsWith('"')&&d.endsWith('"')||d.startsWith("'")&&d.endsWith("'")){const u=l.startIndex+s+2,h=l.endIndex+s+1;i=tn(n.slice(u,h),i,u,h)}else if(l.nodeType!==G.sequenceNodeType.ARRAY){const u=a.numfmt.parseValue(d);if(u==null){const h=l.startIndex+s+1,g=l.endIndex+s+2;i=tn(n.slice(h,g),i,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:p}=xm(d,h);i=tn(f,i,g,S),s+=p}}}}),i}function ym(n,o,e,t){const r=o.getDescriptions();return e[t+1]!==G.matchToken.OPEN_BRACKET?!1:r.get(Mm(n).toLocaleUpperCase())!==void 0}function Mm(n){const o=/^@+/;return n.replace(o,"")}function Pm(n){return bm[n]||n}function tn(n,o,e,t){return o.substring(0,e)+n+o.substring(t)}function xm(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])||"",r=e+o+t,i=r.length-n.length;return{processedString:r,offset:i}}const Bl="range_selector",Fl=n=>n.includes(Bl);var Om=Object.getOwnPropertyDescriptor,Am=(n,o,e,t)=>{for(var r=t>1?void 0:t?Om(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},we=(n,o)=>(e,t)=>o(e,t,n);const da=-1e3;exports.EditingRenderController=class extends a.Disposable{constructor(e,t,r,i,s,l,c,d,u,h,g,S,f,p,v){super();E(this,"_cursorChange",0);E(this,"_editingUnit","");E(this,"_cursorTimeout");this._undoRedoService=e,this._contextService=t,this._renderManagerService=r,this._editorBridgeService=i,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=p,this._selectionManagerService=v,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:y.DeviceInputEventType.Keyboard,keycode:I.KeyCode.ESC,unitId:this._editingUnit});const r=(t=this._renderManagerService.getRenderById(e.getUnitId()))==null?void 0:t.with(cr);r&&r.refreshEditorPosition()}})),this.disposeWithMe(this._editorBridgeService.visible$.pipe(O.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 r;if(this._editingUnit&&this._editorBridgeService.isVisible()){const i=this._editorBridgeService.getEditCellState(),s=this._editorBridgeService.getCurrentEditorId();if(!i||!s)return;(r=this._sheetCellEditorResizeService)==null||r.fitTextSize()}}))}_initialCursorSync(e){e.add(this._cellEditorManagerService.focus$.pipe(O.filter(t=>!!t)).subscribe(()=>{var i;const t=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(!t)return;const r=(i=this._renderManagerService.getRenderById(t==null?void 0:t.getUnitId()))==null?void 0:i.with(Q.DocSelectionRenderService);r&&r.sync()}))}_initSkeletonListener(e){const t=new Set(m.COMMAND_LISTENER_SKELETON_CHANGE);t.delete(m.SetWorksheetActiveOperation.id),e.add(this._commandService.onCommandExecuted(r=>{var i;if(t.has(r.id)){switch(r.id){case m.MoveRowsMutation.id:case m.MoveColsMutation.id:case m.RemoveColMutation.id:case m.RemoveRowMutation.id:case m.InsertColMutation.id:case m.InsertRowMutation.id:{const 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,r);if(!c)break;const d=c.startRow,u=c.startColumn;this._editorBridgeService.updateEditLocation(d,u);break}}(i=this._sheetCellEditorResizeService)==null||i.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 _,R;if(t==null||this._editorBridgeService.isForceKeepVisible())return;const r=this._editorBridgeService.getEditCellState();if(r==null)return;const{position:i,documentLayoutObject:s,scaleX:l,editorUnitId:c}=r;if(this._contextService.getContextValue(a.FOCUSING_EDITOR_STANDALONE))return;const d=this._getDocumentDataModel();if(d==null)return;const{startX:u,endX:h}=i,{textRotation:g,wrapStrategy:S,documentModel:f}=s,{vertexAngle:p}=y.convertTextRotation(g);S===a.WrapStrategy.WRAP&&p===0&&d.updateDocumentDataPageSize((h-u)/l),this._commandService.syncExecuteCommand(Q.ReplaceSnapshotCommand.id,{unitId:c,snapshot:f.getSnapshot()}),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!0),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});const v=(_=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:_.with(Q.DocSelectionRenderService),C=(R=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:R.with(Q.DocSelectionRenderService);(v!=null&&v.canFocusing||C!=null&&C.canFocusing)&&(this._univerInstanceService.setCurrentUnitForType(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),v==null||v.activate(da,da,!0))}))}_commandExecutedListener(e){e.add(this._commandService.onCommandExecuted(r=>{var i;if(r.id===ve.RichTextEditingMutation.id){const s=r.params,{unitId:l}=s;if(Fl(l)||(this._editorBridgeService.changeEditorDirty(!0),!this._editorBridgeService.isVisible().visible))return;l===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&((i=this._sheetCellEditorResizeService)==null||i.fitTextSize())}}));const t=[Wt.id];e.add(this._commandService.onCommandExecuted(r=>{if(t.includes(r.id)){const i=r.params,{keycode:s,isShift:l}=i;if(s!=null&&(this._cursorChange===2||this._contextService.getContextValue(a.FOCUSING_FX_BAR_EDITOR))){this._moveInEditor(s,l);return}this._commandService.syncExecuteCommand(Se.id,i)}r.id===Ar.id&&(this._cursorChange=2)}))}_handleEditorVisible(e){var f,p,v,C;const{eventType:t,keycode:r}=e;this._cursorChange=t===y.DeviceInputEventType.PointerDown||t===y.DeviceInputEventType.Dblclick?2:1;const i=this._editorBridgeService.getEditLocation();if(i==null)return;this._commandService.syncExecuteCommand(Wo.id,{range:{startRow:i.row,startColumn:i.column,endRow:i.row,endColumn:i.column}}),this._editorBridgeService.refreshEditCellPosition(!1);const{unitId:s,isInArrayFormulaRange:l=!1}=i,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(Q.VIEWPORT_KEY.VIEW_MAIN);_==null||_.scrollToViewportPos({viewportScrollX:Number.POSITIVE_INFINITY,viewportScrollY:Number.POSITIVE_INFINITY})});const S=()=>{this._emptyDocumentDataModel(h.getSnapshot().documentStyle,!!l),d.makeDirty(),(r===I.KeyCode.BACKSPACE||t===y.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===y.DeviceInputEventType.Keyboard&&r===I.KeyCode.F2){d.makeDirty(),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}]);const _=((v=(p=h.getBody())==null?void 0:p.dataStream.length)!=null?v: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===y.DeviceInputEventType.Keyboard||t===y.DeviceInputEventType.Dblclick&&l)S();else if(t===y.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 v,C;const t=this._editorBridgeService.getEditCellState(),r=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),i=a.Tools.deepClone(r==null?void 0:r.getSnapshot()),{keycode:s}=e;this._cursorChange=0;const l=(v=t==null?void 0:t.unitId)!=null?v:"";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=i==null?void 0:i.body)==null?void 0:C.dataStream.length)===2,p=t.documentLayoutObject.documentModel?this._isCellImageData(t.documentLayoutObject.documentModel.getSnapshot()):!1;i&&!(f&&p)&&await this._submitEdit(i,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 yo(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}_isCellImageData(e){var r,i;return((i=(r=e.drawingsOrder)==null?void 0:r.length)!=null?i:0)>0}submitCellData(e){return this._submitEdit(e.getSnapshot())}async _submitEdit(e,t=!1){var C;const r=this._editorBridgeService.getEditCellState();if(r==null)return!0;const{unitId:i,sheetId:s,row:l,column:c}=r,d=this._univerInstanceService.getUnit(i,a.UniverInstanceType.UNIVER_SHEET);if(!d)return!0;let u=d.getActiveSheet();if(!d.getSheetBySheetId(s))return!0;u=d.getActiveSheet();const g=Dm({...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(ha(S),ha(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},p=a.generateRandomId(6);return this._commandService.syncExecuteCommand(m.SetRangeValuesCommand.id,{subUnitId:s,unitId:i,range:f,value:S,redoUndoId:p})&&await this._sheetInterceptorService.onValidateCell(d,u,l,c)===!1?(this._undoRedoService.rollback(p,i),!1):!0}_removeComposedCellStyleInCellData(e,t){if(!e.s||typeof e.s=="string")return;const r=Object.keys(e.s);for(const i of r)t[i]!==void 0&&a.Tools.diffValue(e.s[i],t[i])&&delete e.s[i]}_exitInput(e){var i,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();(i=t==null?void 0:t.scene.getViewport(Q.VIEWPORT_KEY.VIEW_MAIN))==null||i.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});const r=this._editorBridgeService.getCurrentEditorId();r==null||!this._editorService.isSheetEditor(r)||(r===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&((s=this._getEditorSkeleton(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null||s.resetInitialWidth()),this._undoRedoService.clearUndoRedo(r),this._undoRedoService.clearUndoRedo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))}_moveSelection(e,t,r){if(e==null||!Cm.includes(e)){this._refreshCurrentSelections(r);return}let i=a.Direction.LEFT;switch(e){case I.KeyCode.ENTER:i=a.Direction.DOWN;break;case I.KeyCode.TAB:i=a.Direction.RIGHT;break;case I.KeyCode.ARROW_DOWN:i=a.Direction.DOWN;break;case I.KeyCode.ARROW_UP:i=a.Direction.UP;break;case I.KeyCode.ARROW_LEFT:i=a.Direction.LEFT;break;case I.KeyCode.ARROW_RIGHT:i=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(Xe.id,{keycode:e,direction:i}):this._commandService.executeCommand(Me.id,{direction:i})}_cursorStateListener(e){const t=this._getEditorObject();if(!(t!=null&&t.document))return;const{document:r}=t;e.add(a.toDisposable(r.onPointerDown$.subscribeEvent(()=>{this._cursorChange===1&&(this._cursorChange=2)})))}_moveInEditor(e,t){let r=a.Direction.LEFT;e===I.KeyCode.ARROW_DOWN?r=a.Direction.DOWN:e===I.KeyCode.ARROW_UP?r=a.Direction.UP:e===I.KeyCode.ARROW_RIGHT&&(r=a.Direction.RIGHT),t?this._commandService.executeCommand(Q.MoveSelectionOperation.id,{direction:r}):this._commandService.executeCommand(Q.MoveCursorOperation.id,{direction:r})}_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(ve.DocSkeletonManagerService).getSkeleton()}_getEditorViewModel(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(ve.DocSkeletonManagerService).getViewModel()}_getEditingUnit(){return this._editingUnit?this._univerInstanceService.getUnit(this._editingUnit,a.UniverInstanceType.UNIVER_SHEET):null}_emptyDocumentDataModel(e,t){const r=(l,c)=>{const d=a.Tools.deepClone(l.getSnapshot()),u=this._getEditorViewModel(l.getUnitId());u!=null&&(km(d.body,t),c&&(d.documentStyle=e),d.drawings={},d.drawingsOrder=[],l.reset(d),u.reset(l))},i=this._getDocumentDataModel();i&&r(i,!0);const s=this._univerInstanceService.getUnit(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);s&&r(s)}};exports.EditingRenderController=Am([we(0,a.IUndoRedoService),we(1,a.IContextService),we(2,y.IRenderManagerService),we(3,he),we(4,Un),we(5,a.Inject(G.LexerTreeBuilder)),we(6,G.IFunctionService),we(7,a.Inject(ve.DocSelectionManagerService)),we(8,a.ICommandService),we(9,a.Inject(a.LocaleService)),we(10,Q.IEditorService),we(11,a.IUniverInstanceService),we(12,a.Inject(m.SheetInterceptorService)),we(13,a.Inject(exports.SheetCellEditorResizeService)),we(14,a.Inject(m.SheetsSelectionsService))],exports.EditingRenderController);function Dm(n,o,e,t,r,i){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=wm(d,e,u,r),(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=i==null?void 0:i.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,Hi(s)&&s.dataStream!==`\r
|
|
10
10
|
`&&(n.p=o);const f=ua(o);f&&(n.s=f)}else if(a.isFormulaString(d)){if(n.f===d)return null;const f=e.checkIfAddBracket(d);for(let p=0;p<f;p++)d+=G.matchToken.CLOSE_BRACKET;n.f=d,n.si=null,n.v=null,n.p=null}else if(Im(d)){const f=_m(d);n.v=f,n.f=null,n.si=null,n.p=null,n.t=a.CellValueType.FORCE_STRING}else if(Hi(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=ua(o);f&&(n.s=f)}return n}function Hi(n){const{textRuns:o=[],paragraphs:e=[],customRanges:t,customBlocks:r=[]}=n,i=n.dataStream.replace(/(\r\n)+$/,""),s=["va"];return o.filter(l=>l.st<i.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<i.length})||e.some(l=>l.bullet)||e.length>=2||!!(t!=null&&t.length)||r.length>0}function ua(n){const{body:o}=n;if(!o)return null;const{textRuns:e=[]}=o;let t={};const r=o.dataStream.replace(`\r
|
|
12
|
-
`,"");return e.forEach(i=>{const{st:s,ed:l,ts:c}=i;l-s>=r.length&&(t={...t,...c})}),Object.keys(t).length?t:null}function km(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 ha(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 Nm=Object.getOwnPropertyDescriptor,Vm=(n,o,e,t)=>{for(var r=t>1?void 0:t?Nm(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Ge=(n,o)=>(e,t)=>o(e,t,n);exports.FormulaEditorController=class extends a.RxDisposable{constructor(e,t,r,i,s,l,c,d,u){super();E(this,"_loadedMap",new WeakSet);E(this,"_scheduledCallback",-1);this._univerInstanceService=e,this._renderManagerService=t,this._editorBridgeService=r,this._commandService=i,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(O.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===ve.RichTextEditingMutation.id){const t=e.params,{unitId:r}=t;r===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:r}=t;r!=null&&(this._loadedMap.has(r)||this._loadedMap.add(r))}_listenFxBtnClick(){this._formulaEditorManagerService.fxBtnClick$.pipe(O.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 r=this._univerInstanceService.getUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);this._editorBridgeService.isVisible().visible===!1&&this._commandService.syncExecuteCommand(Se.id,{visible:!0,eventType:y.DeviceInputEventType.PointerDown,unitId:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY});const s=(t=r==null?void 0:r.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(Q.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(O.filter(t=>t.getUnitId()===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY));this.disposeWithMe(O.combineLatest([this._formulaEditorManagerService.position$,e]).subscribe(([t])=>{if(!t)return this._clearScheduledCallback();const r=yo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,this._renderManagerService),i=this._univerInstanceService.getUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);if(r==null||i==null)return this._clearScheduledCallback();const{width:s,height:l}=t;if(s===0||l===0)return this._clearScheduledCallback();const{engine:c}=r;i.updateDocumentDataPageSize(s),this.autoScroll(),this._scheduledCallback=requestIdleCallback(()=>c.resizeBySize(s,l))}))}_clearScheduledCallback(){this._scheduledCallback!==-1&&cancelIdleCallback(this._scheduledCallback),this._scheduledCallback=-1}autoScroll(){var p,v;const e=this._formulaEditorManagerService.getPosition(),t=(p=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:p.with(ve.DocSkeletonManagerService).getSkeleton(),r=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),i=this._univerInstanceService.getUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);if(t==null||e==null||r==null||i==null)return;const{marginTop:s=0,marginBottom:l=0}=i.getSnapshot().documentStyle,{scene:c,mainComponent:d}=r;let{actualHeight:u}=t.getActualSize();u+=s+l;const{width:h,height:g}=e,S=c.getViewport(Q.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 y.ScrollBar(S,{enableHorizontal:!1,barSize:8}):S==null||S.resetCanvasSizeAndUpdateScroll():(f=null,S==null||S.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0}),(v=S==null?void 0:S.getScrollBar())==null||v.dispose())}};exports.FormulaEditorController=Vm([Ge(0,a.IUniverInstanceService),Ge(1,y.IRenderManagerService),Ge(2,he),Ge(3,a.ICommandService),Ge(4,a.IContextService),Ge(5,Ln),Ge(6,a.IUndoRedoService),Ge(7,a.Inject(ve.DocSelectionManagerService)),Ge(8,Q.IEditorService)],exports.FormulaEditorController);const jl="embedding_formula_editor",Hm=n=>n.includes(jl),Is=(n,o)=>{var h,g,S,f,p;const t=o.findNodePositionByCharIndex(n.startOffset,!0,n.segmentId,-1),r=o.getSkeletonData();let i=n.endOffset;if(n.segmentId){const v=(p=Array.from((g=(h=r==null?void 0:r.skeFooters.get(n.segmentId))==null?void 0:h.values())!=null?g:[])[0])!=null?p:Array.from((f=(S=r==null?void 0:r.skeHeaders.get(n.segmentId))==null?void 0:S.values())!=null?f:[])[0];v&&(i=Math.min(v.ed,i))}const s=o.findNodePositionByCharIndex(i,!0,n.segmentId,-1);if(!s||!t)return;const l={docsLeft:0,docsTop:0,pageMarginLeft:0,pageMarginTop:0},c=new Q.NodePositionConvertToCursor(l,o),{borderBoxPointGroup:d}=c.getRangePointData(t,s);return Q.getLineBounding(d).map(v=>({top:v.top,bottom:v.bottom,left:v.left,right:v.right}))},Wm=(n,o,e=-1)=>{const t=o.findPositionByGlyph(n,e);if(!t)return;const r={...t,isBack:!0},i={docsLeft:0,docsTop:0,pageMarginLeft:0,pageMarginTop:0},s=new Q.NodePositionConvertToCursor(i,o),{borderBoxPointGroup:l}=s.getRangePointData(r,r),d=Q.getLineBounding(l)[0];return{top:d.top,bottom:d.bottom,left:d.left,right:d.right}},Um=(n,o,e=0,t=0)=>{const r=Is({startOffset:o.startIndex,endOffset:o.endIndex+1},n);if(r)return{rects:r.map(i=>({top:i.top+t,bottom:i.bottom+t,left:i.left+e,right:i.right+e})),range:o}},Lm=(n,o,e=0,t=0)=>{var h,g,S;const r=n.findNodeByCharIndex(o.startIndex),i=r==null?void 0:r.parent,s=i==null?void 0:i.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=Wm(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}},zl=(n,o=0,e=0)=>{var l,c,d,u,h,g,S;const t=n.getViewModel().getDataModel(),r=(d=(c=(l=t.getBody())==null?void 0:l.customRanges)==null?void 0:c.filter(f=>f.rangeType===a.CustomRangeType.HYPERLINK))!=null?d:[],i=(g=(h=(u=t.getBody())==null?void 0:u.paragraphs)==null?void 0:h.filter(f=>{var p;return((p=f.bullet)==null?void 0:p.listType.indexOf(a.PresetListType.CHECK_LIST))===0}))!=null?g:[],s=(S=n.getSkeletonData())==null?void 0:S.pages[0].skeDrawings;return{links:r.map(f=>Um(n,f,o,e)).filter(Boolean),checkLists:i.map(f=>Lm(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 Xl(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,r=(f=(S=(g=o.documentSkeleton)==null?void 0:g.getSkeletonData())==null?void 0:S.pages[0].width)!=null?f:0,i=o.verticalAlign,s=o.horizontalAlign;let l=0;switch(i){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-r;break;case a.HorizontalAlign.CENTER:c=(n.mergeInfo.endX-n.mergeInfo.startX-r)/2;break;case a.HorizontalAlign.UNSPECIFIED:{e&&(c=n.mergeInfo.endX-n.mergeInfo.startX-r);break}}return{paddingLeft:c,paddingTop:l}}const Bm=(n,o,e,t,r,i)=>{var k,H,N;const s=n.get(a.IUniverInstanceService),l=n.get(y.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(exports.SheetSkeletonManagerService).getSkeletonParam(d.getSheetId()),g=h==null?void 0:h.skeleton;if(!g||!u)return;const S=g.getFont(t,r),f=S==null?void 0:S.documentSkeleton;if(!f)return null;const p=(H=(k=f.getViewModel().getBody())==null?void 0:k.customRanges)==null?void 0:H.find(V=>V.rangeId===i);if(!p)return null;const v=Q.DOC_VERTICAL_PADDING,C=g.getCellWithCoordByIndex(t,r);let{actualColumn:_,actualRow:R}=C;g.overflowCache.forValue((V,L,U)=>{U.startRow<=R&&U.endRow>=R&&U.startColumn<=_&&U.endColumn>=_&&(_=L,R=V)});const w=g.getCellWithCoordByIndex(R,_),P=d.getCell(w.actualRow,w.actualColumn),{topOffset:T=0,leftOffset:M=0}=(N=P==null?void 0:P.fontRenderExtension)!=null?N:{},{paddingLeft:x,paddingTop:A}=Xl(w,S,!1),D=Is({startOffset:p.startIndex,endOffset:p.endIndex},f);return{rects:D==null?void 0:D.map(V=>({top:V.top+w.mergeInfo.startY+A+T+v,bottom:V.bottom+w.mergeInfo.startY+A+T+v,left:V.left+w.mergeInfo.startX+x+M,right:V.right+w.mergeInfo.startX+x+M})),customRange:p,label:f.getViewModel().getBody().dataStream.slice(p.startIndex,p.endIndex+1)}},Fm=(n,o,e,t,r,i)=>{var M,x,A;const s=n.get(he),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!==r)return null;const f=n.get(y.IRenderManagerService),p=f.getRenderById(d),v=f.getRenderById(o);if(!p||!v)return null;const C=p.with(ve.DocSkeletonManagerService).getSkeleton(),_=(M=v.with(exports.SheetSkeletonManagerService).getSkeletonParam(h))==null?void 0:M.skeleton;if(!C||!_)return null;const R=(A=(x=C.getViewModel().getBody())==null?void 0:x.customRanges)==null?void 0:A.find(D=>D.rangeId===i);if(!R)return null;const w=4,P=Is({startOffset:R.startIndex,endOffset:R.endIndex},C),T=p.engine.getCanvasElement().getBoundingClientRect();return{rects:P==null?void 0:P.map(D=>({top:D.top+T.top-w,bottom:D.bottom+T.top+w,left:D.left+T.left,right:D.right+T.left})),customRange:R,label:C.getViewModel().getBody().dataStream.slice(R.startIndex,R.endIndex+1)}};var jm=Object.getOwnPropertyDescriptor,zm=(n,o,e,t)=>{for(var r=t>1?void 0:t?jm(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},ma=(n,o)=>(e,t)=>o(e,t,n);function Rt(n){const{workbook:o,worksheet:e,...t}=n;return t}exports.HoverManagerService=class extends a.Disposable{constructor(e,t){super();E(this,"_currentCell$",new O.BehaviorSubject(null));E(this,"_currentRichText$",new O.BehaviorSubject(null));E(this,"_currentClickedCell$",new O.Subject);E(this,"_currentDbClickedCell$",new O.Subject);E(this,"_currentCellWithEvent$",new O.Subject);E(this,"_currentPointerDownCell$",new O.Subject);E(this,"_currentPointerUpCell$",new O.Subject);E(this,"_currentHoveredRowHeader$",new O.BehaviorSubject(null));E(this,"_currentHoveredColHeader$",new O.BehaviorSubject(null));E(this,"_currentRowHeaderClick$",new O.Subject);E(this,"_currentColHeaderClick$",new O.Subject);E(this,"_currentRowHeaderDbClick$",new O.Subject);E(this,"_currentColHeaderDbClick$",new O.Subject);E(this,"_currentRowHeaderPointerDown$",new O.Subject);E(this,"_currentColHeaderPointerDown$",new O.Subject);E(this,"_currentRowHeaderPointerUp$",new O.Subject);E(this,"_currentColHeaderPointerUp$",new O.Subject);E(this,"currentCell$",this._currentCell$.asObservable().pipe(O.distinctUntilChanged((e,t)=>{var r,i,s,l,c,d,u,h;return((r=e==null?void 0:e.location)==null?void 0:r.unitId)===((i=t==null?void 0:t.location)==null?void 0:i.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)})));E(this,"currentRichTextNoDistinct$",this._currentRichText$.pipe(O.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})));E(this,"currentRichText$",this._currentRichText$.pipe(O.distinctUntilChanged((e,t)=>{var r,i,s,l,c,d,u,h,g,S,f,p,v,C,_,R,w,P;return((r=e==null?void 0:e.location)==null?void 0:r.unitId)===((i=t==null?void 0:t.location)==null?void 0:i.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)===((p=t==null?void 0:t.bullet)==null?void 0:p.startIndex)&&((v=e==null?void 0:e.customRange)==null?void 0:v.startIndex)===((C=t==null?void 0:t.customRange)==null?void 0:C.startIndex)&&((_=e==null?void 0:e.customRange)==null?void 0:_.endIndex)===((R=t==null?void 0:t.customRange)==null?void 0:R.endIndex)&&((w=e==null?void 0:e.drawing)==null?void 0:w.drawingId)===((P=t==null?void 0:t.drawing)==null?void 0:P.drawingId)}),O.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})));E(this,"currentCellPosWithEvent$",this._currentCellWithEvent$.pipe(O.distinctUntilChanged((e,t)=>{var r,i,s,l,c,d,u,h;return((r=e==null?void 0:e.location)==null?void 0:r.unitId)===((i=t==null?void 0:t.location)==null?void 0:i.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)}),O.map(e=>e&&{unitId:e.location.unitId,subUnitId:e.location.subUnitId,row:e.location.row,col:e.location.col,event:e.event})));E(this,"currentPosition$",this._currentCell$.asObservable());E(this,"currentClickedCell$",this._currentClickedCell$.asObservable());E(this,"currentDbClickedCell$",this._currentDbClickedCell$.asObservable());E(this,"currentPointerDownCell$",this._currentPointerDownCell$.asObservable());E(this,"currentPointerUpCell$",this._currentPointerUpCell$.asObservable());E(this,"currentHoveredRowHeader$",this._currentHoveredRowHeader$.asObservable());E(this,"currentHoveredColHeader$",this._currentHoveredColHeader$.asObservable());E(this,"currentRowHeaderClick$",this._currentRowHeaderClick$.asObservable());E(this,"currentColHeaderClick$",this._currentColHeaderClick$.asObservable());E(this,"currentRowHeaderDbClick$",this._currentRowHeaderDbClick$.asObservable());E(this,"currentColHeaderDbClick$",this._currentColHeaderDbClick$.asObservable());E(this,"currentRowHeaderPointerDown$",this._currentRowHeaderPointerDown$.asObservable());E(this,"currentColHeaderPointerDown$",this._currentColHeaderPointerDown$.asObservable());E(this,"currentRowHeaderPointerUp$",this._currentRowHeaderPointerUp$.asObservable());E(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$=O.of(null),this.currentRichText$=O.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,r;((t=this._currentCell$.getValue())==null?void 0:t.location.unitId)===e.getUnitId()&&this._currentCell$.next(null),((r=this._currentRichText$.getValue())==null?void 0:r.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 r=t.getActiveSheet();if(!r)return null;const i=this._renderManagerService.getRenderById(t.getUnitId());if(!i)return null;const s=i.with(exports.SheetSkeletonManagerService).getSkeletonParam(r.getSheetId());if(!s)return null;const l=i.with(exports.SheetScrollManagerService);if(!(!(l!=null&&l.getCurrentScrollState())||!i))return{currentRender:i,workbook:t,worksheet:r,skeletonParam:s}}_calcActiveCell(e,t,r,i,s,l){var M,x,A;const c=ll(e,t,r,i,s,l),d=i.skeleton;if(!c)return null;const{position:u,overflowLocation:h,location:g}=c,S=d.getFont(h.row,h.col);let f=null,p=null,v=null;const C=d.getCellWithCoordByIndex(h.row,h.col),_=r.getCell(h.row,h.col),{topOffset:R=0,leftOffset:w=0}=(M=_==null?void 0:_.fontRenderExtension)!=null?M:{};if(S!=null&&S.documentSkeleton){const{paddingLeft:D,paddingTop:k}=Xl(C,S,(_==null?void 0:_.v)!==null&&(_==null?void 0:_.v)!==void 0?!Number.isNaN(+_.v):!1),H=zl(S.documentSkeleton,D,k),N=s-u.startX-w,V=l-u.startY-R;f=H.links.find(L=>L.rects.some(U=>U.left<=N&&N<=U.right&&U.top<=V&&V<=U.bottom)),p=H.checkLists.find(L=>L.rect.left<=N&&N<=L.rect.right&&L.rect.top<=V&&V<=L.rect.bottom),v=H.drawings.find(L=>L.rect.left<=N&&N<=L.rect.right&&L.rect.top<=V&&V<=L.rect.bottom)}const P=(A=(x=f==null?void 0:f.rects.pop())!=null?x:p==null?void 0:p.rect)!=null?A:v==null?void 0:v.rect,T=P&&(()=>{const D=P.top+C.mergeInfo.startY+R,k=P.bottom+C.mergeInfo.startY+R,H=P.left+C.mergeInfo.startX+w,N=P.right+C.mergeInfo.startX+w,V=C.mergeInfo.startY+R,L=C.mergeInfo.endY+R,U=C.mergeInfo.startX+w,F=C.mergeInfo.endX+w,B=Math.min(Math.max(D,V),V),z=Math.min(k,L),X=Math.min(Math.max(H,U),U),K=Math.min(N,F);return{top:B,bottom:z,left:X,right:K}})();return{location:g,position:u,overflowLocation:h,customRange:f==null?void 0:f.range,bullet:p==null?void 0:p.paragraph,drawing:v,rect:T}}_calcActiveRowHeader(e,t,r){const i=this._getCalcDeps(e);if(!i)return;const{currentRender:s,worksheet:l,skeletonParam:c}=i,{scaleY:d}=s.scene.getAncestorScale(),u=s.scene.getViewports().find(S=>S.isHit(new y.Vector2(t,r)));if(!u||u.viewportKey!==y.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP&&u.viewportKey!==y.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM)return;const h={x:u.viewportScrollX,y:u.viewportScrollY},g=c.skeleton.getRowIndexByOffsetY(r,d,h);return{unitId:e,index:g,subUnitId:l.getSheetId()}}_calcActiveColHeader(e,t,r){const i=this._getCalcDeps(e);if(!i)return;const{currentRender:s,worksheet:l,skeletonParam:c}=i,{scaleX:d}=s.scene.getAncestorScale(),u=s.scene.getViewports().find(S=>S.isHit(new y.Vector2(t,r)));if(!u||u.viewportKey!==y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT&&u.viewportKey!==y.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 r=this._getCalcDeps(e);if(!r)return;const{currentRender:i,workbook:s,worksheet:l,skeletonParam:c}=r,d=this._calcActiveCell(i,s,l,c,t.offsetX,t.offsetY);if(d&&d.location){const{unitId:u,subUnitId:h,row:g,col:S}=Rt(d.location);this._currentPointerDownCell$.next({unitId:u,subUnitId:h,row:g,col:S,event:t})}}triggerPointerUp(e,t){const r=this._getCalcDeps(e);if(!r)return;const{currentRender:i,workbook:s,worksheet:l,skeletonParam:c}=r,d=this._calcActiveCell(i,s,l,c,t.offsetX,t.offsetY);if(d){const u=Rt(d.location);this._currentPointerUpCell$.next({...u,event:t})}}triggerMouseMove(e,t){const r=this._getCalcDeps(e);if(!r)return;const{currentRender:i,workbook:s,worksheet:l,skeletonParam:c}=r,d=this._calcActiveCell(i,s,l,c,t.offsetX,t.offsetY);this._currentCell$.next(d&&{location:Rt(d.location),position:d.position}),this._currentRichText$.next(d&&{...d,location:Rt(d.overflowLocation)}),this._currentCellWithEvent$.next(d&&{...d,location:Rt(d.location),event:t})}triggerClick(e,t,r){const i=this._getCalcDeps(e);if(!i)return;const{currentRender:s,workbook:l,worksheet:c,skeletonParam:d}=i,u=this._calcActiveCell(s,l,c,d,t,r);u&&this._currentClickedCell$.next({...u,location:Rt(u.location)})}triggerDbClick(e,t,r){const i=this._getCalcDeps(e);if(!i)return;const{currentRender:s,workbook:l,worksheet:c,skeletonParam:d}=i,u=this._calcActiveCell(s,l,c,d,t,r);u&&this._currentDbClickedCell$.next({...u,location:Rt(u.location)})}triggerScroll(){this._currentCell$.next(null)}triggerRowHeaderClick(e,t,r){const i=this._calcActiveRowHeader(e,t,r);i&&this._currentRowHeaderClick$.next(i)}triggerColHeaderClick(e,t,r){const i=this._calcActiveColHeader(e,t,r);i&&this._currentColHeaderClick$.next(i)}triggerRowHeaderDbClick(e,t,r){const i=this._calcActiveRowHeader(e,t,r);i&&this._currentRowHeaderDbClick$.next(i)}triggerColHeaderDbClick(e,t,r){const i=this._calcActiveColHeader(e,t,r);i&&this._currentColHeaderDbClick$.next(i)}triggerRowHeaderMouseMove(e,t,r){this._currentHoveredRowHeader$.next(this._calcActiveRowHeader(e,t,r))}triggerColHeaderMouseMove(e,t,r){this._currentHoveredColHeader$.next(this._calcActiveColHeader(e,t,r))}triggerRowHeaderPoniterDown(e,t,r){const i=this._calcActiveRowHeader(e,t,r);i&&this._currentRowHeaderPointerDown$.next(i)}triggerColHeaderPoniterDown(e,t,r){const i=this._calcActiveColHeader(e,t,r);i&&this._currentColHeaderPointerDown$.next(i)}triggerRowHeaderPoniterUp(e,t,r){const i=this._calcActiveRowHeader(e,t,r);i&&this._currentRowHeaderPointerUp$.next(i)}triggerColHeaderPoniterUp(e,t,r){const i=this._calcActiveColHeader(e,t,r);i&&this._currentColHeaderPointerUp$.next(i)}};exports.HoverManagerService=zm([ma(0,a.IUniverInstanceService),ma(1,y.IRenderManagerService)],exports.HoverManagerService);var Xm=Object.getOwnPropertyDescriptor,Ym=(n,o,e,t)=>{for(var r=t>1?void 0:t?Xm(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Go=(n,o)=>(e,t)=>o(e,t,n);exports.HoverRenderController=class extends a.Disposable{constructor(e,t,r,i){super();E(this,"_active",!1);this._context=e,this._hoverManagerService=t,this._sheetSkeletonManagerService=r,this._scrollManagerService=i,this._initPointerEvent(),this._initScrollEvent()}get active(){return this._active}_initPointerEvent(){const e=new a.DisposableCollection,t=r=>{if(e.dispose(),!r)return;const{mainComponent:i,unitId:s,components:l}=this._context;if(!i)return;e.add(i.onPointerEnter$.subscribeEvent(u=>{this._active=!0})),e.add(a.fromEventSubject(i.onPointerMove$).subscribe(u=>{this._active=!0,this._hoverManagerService.triggerMouseMove(s,u)})),e.add(i.onPointerDown$.subscribeEvent(u=>{this._hoverManagerService.triggerPointerDown(s,u)})),e.add(i.onPointerUp$.subscribeEvent(u=>{this._hoverManagerService.triggerPointerUp(s,u)})),e.add(i.onClick$.subscribeEvent(u=>{this._hoverManagerService.triggerClick(s,u.offsetX,u.offsetY)})),e.add(i.onDblclick$.subscribeEvent(u=>{this._hoverManagerService.triggerDbClick(s,u.offsetX,u.offsetY)})),e.add(i.onPointerLeave$.subscribeEvent(()=>{this._active=!1}));const c=l.get(ue.ROW),d=l.get(ue.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(r=>{t(r)}))}_initScrollEvent(){this.disposeWithMe(this._scrollManagerService.validViewportScrollInfo$.subscribe(()=>this._hoverManagerService.triggerScroll()))}};exports.HoverRenderController=Ym([Go(1,a.Inject(exports.HoverManagerService)),Go(2,a.Inject(exports.SheetSkeletonManagerService)),Go(3,a.Inject(exports.SheetScrollManagerService))],exports.HoverRenderController);const Yl="UI_PLUGIN_SHEETS",_s=`${Yl}_BORDER_PANEL_COMPONENT`,Zl=[{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 Zm(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)):O.of(null)))}function _e(n,o,e){return Zm(n).pipe(de.switchMap(t=>t?e(t):O.of(o)))}function Gl(n,o){const e=n.get(a.IUniverInstanceService),t=n.get(m.IExclusiveRangeService),r=n.get(m.SheetsSelectionsService);return e.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(de.switchMap(s=>s?O.combineLatest([r.selectionMoveEnd$,s.activeSheet$]).pipe(de.switchMap(([l,c])=>{if(!c||l.length===0)return O.of(!1);const d=t.getInterestGroupId(l);if(o){const u=d.filter(h=>o.has(h));return O.of(u.length>0)}else return O.of(d.length>0)})):O.of(!1)))}function Gt(n,o,e){return O.combineLatest([o,Gl(n,e)]).pipe(de.map(([t,r])=>t||r))}function $(n,o={},e=!1){var g;const r=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),i=n.get(a.UserManagerService),s=n.has(he)?n.get(he):null,l=n.get(a.IContextService),d=((g=s==null?void 0:s.visible$)!=null?g:O.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 O.combineLatest([i.currentUser$,r,d,u]).pipe(de.switchMap(([S,f,p,v])=>!f||p!=null&&p.visible&&p.unitId===f.getUnitId()&&!e||v&&!e?O.of(!0):f.activeSheet$.pipe(de.switchMap(C=>{if(!C)return O.of(!0);const _=n.get(m.SheetsSelectionsService),R=n.get(m.RangeProtectionRuleModel),w=n.get(m.WorksheetProtectionRuleModel),T=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_COMMON_DRAWINGS).pipe(de.startWith(!1));return O.combineLatest([_.selectionMoveEnd$,T]).pipe(de.switchMap(([M,x])=>{if(x)return O.of(!0);const A=f.getUnitId(),D=C.getSheetId(),k=n.get(a.IPermissionService),{workbookTypes:H=[m.WorkbookEditablePermission],worksheetTypes:N,rangeTypes:V}=o,L=[];if(H==null||H.forEach(z=>{L.push(new z(A).id)}),N==null||N.forEach(z=>{L.push(new z(A,D).id)}),w.getRule(A,D))return k.composePermission$(L).pipe(de.map(z=>z.some(X=>X.value===!1)));const F=M==null?void 0:M.map(z=>z.range),B=R.getSubunitRuleList(A,D).filter(z=>F==null?void 0:F.some(X=>z.ranges.some(K=>a.Rectangle.intersects(X,K))));return V==null||V.forEach(z=>{B.forEach(X=>{L.push(new z(A,D,X.permissionId).id)})}),k.composePermission$(L).pipe(de.map(z=>z.some(X=>X.value===!1)))}))}))))}function Bn(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(m.RangeProtectionRuleModel),r=n.get(a.IPermissionService);return O.merge(e.selectionMoveEnd$,r.permissionPointUpdate$.pipe(de.debounceTime(100))).pipe(de.map(()=>{var h;const i=(h=e.getCurrentLastSelection())==null?void 0:h.range;if(!i)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(i,S))).forEach(g=>{u.push(new m.RangeProtectionPermissionEditPoint(c,d,g.permissionId).id)}),r.composePermission(u).some(g=>g.value===!1)}))}function Kl(n,o){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.RangeProtectionRuleModel),i=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,i.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 r.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)}),i.composePermission(h).some(S=>S.value===!1)}))}function ql(n,o){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.RangeProtectionRuleModel),i=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,i.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),r.getSubunitRuleList(d,u).filter(f=>f.ranges.some(p=>a.Rectangle.intersects(g,p))).forEach(f=>{h.push(new m.RangeProtectionPermissionEditPoint(d,u,f.permissionId).id)}),i.composePermission(h).some(f=>f.value===!1)}))}function Bo(n,o){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.RangeProtectionRuleModel),i=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,i.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,r.getSubunitRuleList(d,u).filter(f=>f.ranges.some(p=>a.Rectangle.intersects(g,p))).forEach(f=>{h.push(new m.RangeProtectionPermissionEditPoint(d,u,f.permissionId).id)}),i.composePermission(h).some(f=>f.value===!1)}))}function Fn(n,o){const t=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(m.WorksheetProtectionRuleModel),i=n.get(m.RangeProtectionRuleModel),s=n.get(a.IPermissionService),l=n.get(a.UserManagerService);return O.combineLatest([l.currentUser$,t]).pipe(de.switchMap(([c,d])=>d?d.activeSheet$.pipe(de.switchMap(u=>{if(!u)return O.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(p=>p.value===!0))).pipe(de.map(f=>{if(!f)return!0;const p=u.getSheetId(),v=r.getRule(h,p),C=i.getSubunitRuleList(h,p);return!!(v||C.length)}))})):O.of(!0)))}function Gm(n){const o=n.get(m.BorderStyleManagerService),e=$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]});return{id:m.SetBorderBasicCommand.id,icon:new O.Observable(t=>{const r="AllBorderIcon",i=n.get(m.BorderStyleManagerService),s=n.get(a.ICommandService).onCommandExecuted(l=>{var g;if(l.id!==m.SetBorderBasicCommand.id)return;const{type:d}=i.getBorderInfo(),u=Zl.find(S=>S.value===d),h=(g=u==null?void 0:u.icon)!=null?g:r;t.next(h)});return t.next(r),s.dispose}),tooltip:"toolbar.border.main",type:I.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:_s,hoverable:!1,selectable:!1},value$:o.borderInfo$}],value$:o.borderInfo$,hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:e}}const Kr="sheet.menu.clear-selection";function Ko(n){return{id:Kr,type:I.MenuItemType.SUBITEMS,icon:"ClearFormatDoubleIcon",title:"rightClick.clearSelection",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function qo(n){return{id:m.ClearSelectionContentCommand.id,type:I.MenuItemType.BUTTON,icon:"ClearFormatDoubleIcon",title:"rightClick.clearContent",disabled$:Gt(n,$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellValuePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Qo(n){return{id:m.ClearSelectionFormatCommand.id,type:I.MenuItemType.BUTTON,icon:"ClearFormatDoubleIcon",title:"rightClick.clearFormat",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Br(n){return{id:m.ClearSelectionAllCommand.id,type:I.MenuItemType.BUTTON,icon:"ClearFormatDoubleIcon",title:"rightClick.clearAll",tooltip:"rightClick.clearAll",disabled$:Gt(n,$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellValuePermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Ql="sheet.menu.delete";function Km(n){return{id:Ql,type:I.MenuItemType.SUBITEMS,title:"rightClick.delete",icon:"ReduceDoubleIcon",hidden$:Gt(n,Bn(n)),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission]})}}function ga(n){return{id:_n.id,type:I.MenuItemType.BUTTON,icon:"DeleteColumnDoubleIcon",title:"rightClick.deleteSelectedColumn",hidden$:ql(n,"col"),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookDeleteColumnPermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetDeleteColumnPermission]})}}function Sa(n){return{id:In.id,type:I.MenuItemType.BUTTON,icon:"DeleteRowDoubleIcon",title:"rightClick.deleteSelectedRow",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookDeleteRowPermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetDeleteRowPermission]}),hidden$:ql(n,"row")}}function qm(n){return{id:Dn.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveLeft",icon:"DeleteCellShiftLeftDoubleIcon",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:Bo(n,"col")}}function Qm(n){return{id:Nt.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveUp",icon:"DeleteCellShiftUpDoubleIcon",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:Bo(n,"row")}}function Jm(n,o){const e=n.get(m.SheetsSelectionsService),t=n.get(a.IUniverInstanceService),r=n.get(a.ICommandService),i=n.get(a.IContextService);return _e(t,o,({worksheet:s})=>new O.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=Bt(n);if(h!=null){const f=(S=(g=h.ts)==null?void 0:g.fs)!=null?S:o;l.next(f)}},u=r.onCommandExecuted(h=>{const g=h.id;(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id)&&c(),(g===ve.SetTextSelectionsOperation.id||g===Q.SetInlineFormatCommand.id)&&i.getContextValue(a.EDITOR_ACTIVATED)&&i.getContextValue(a.FOCUSING_SHEET)&&d()});return c(),u.dispose}))}function $m(n){const o=a.DEFAULT_STYLES.fs,e=$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0);return{id:pr.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 eg(n){const o=$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0);return{id:Do.id,type:I.MenuItemType.BUTTON,icon:"FontSizeIncreaseIcon",tooltip:"toolbar.fontSizeIncrease",disabled$:o,hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function tg(n){const o=$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0);return{id:ko.id,type:I.MenuItemType.BUTTON,icon:"FontSizeReduceIcon",tooltip:"toolbar.fontSizeDecrease",disabled$:o,hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function ng(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 O.Observable(t=>{const r=()=>{const s=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);return s?s.getActiveSheet().getConfig().showGridlines===a.BooleanNumber.TRUE:!1},i=new a.DisposableCollection;return i.add(o.onCommandExecuted(s=>{(s.id===m.ToggleGridlinesMutation.id||s.id===m.SetWorksheetActiveOperation.id)&&t.next(r())})),i.add(e.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(()=>{t.next(r())})),t.next(r()),()=>i.dispose()}),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission]})}}const Ze=`${Yl}_MENU_ITEM_INPUT_COMPONENT`,Jl=n=>{const{prefix:o,suffix:e,value:t,min:r=Number.MIN_SAFE_INTEGER,max:i=Number.MAX_SAFE_INTEGER,disabled$:s,onChange:l}=n,c=I.useDependency(a.LocaleService),d=I.useDependency(I.IContextMenuService),[u,h]=W.useState(!1),[g,S]=W.useState(),f=v=>{if(!v){S(r.toString());return}const C=v.toString();S(C),l(C)};W.useEffect(()=>{if(!s)return;const v=s.subscribe(C=>{h(C)});return()=>{v.unsubscribe()}},[]),W.useEffect(()=>{d.visible||S(t)},[d.visible]),W.useEffect(()=>{+t<r?S(r.toString()):+t>i?S(i.toString()):S(t)},[t]);function p(){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:v=>v.stopPropagation(),children:b.jsx(j.InputNumber,{value:Number(g),size:"mini",precision:0,min:r,max:i,disabled:u,onPressEnter:p,onChange:f})}),c.t(e)]})},$l="sheet.menu.cell-insert";function rg(n){return{id:$l,type:I.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"InsertDoubleIcon",hidden$:Gt(n,Bn(n)),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookInsertColumnPermission,m.WorkbookInsertRowPermission],worksheetTypes:[m.WorksheetInsertColumnPermission,m.WorksheetInsertRowPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function og(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=1,i=$(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:Ze,props:{prefix:"rightClick.insertRowsAbove",min:1,max:1e3,suffix:"rightClick.insertRowsAboveSuffix",disabled$:i}},value$:_e(o,r,()=>new O.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=r;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$:i,hidden$:Kl(n,"row")}}function ig(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=1,i=$(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:Ze,props:{prefix:"rightClick.insertColsLeft",min:1,max:1e3,suffix:"rightClick.insertColsLeftSuffix",disabled$:i}},value$:_e(o,r,()=>new O.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=r;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$:i,hidden$:Kl(n,"col")}}function sg(n){return{id:kn.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveRight",icon:"InsertCellShiftRightDoubleIcon",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:Bo(n,"col")}}function ag(n){return{id:Vt.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveDown",icon:"InsertCellDownDoubleIcon",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:Bo(n,"row")}}function lg(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=1,i=$(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:Ze,props:{prefix:"rightClick.insertRowsAfter",min:1,max:1e3,suffix:"rightClick.insertRowsAfterSuffix",disabled$:i}},value$:_e(o,r,()=>new O.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=r;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$:i,hidden$:Bn(n)}}function cg(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=1,i=$(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:Ze,props:{prefix:"rightClick.insertRowsAbove",min:1,max:1e3,suffix:"rightClick.insertRowsAboveSuffix",disabled$:i}},value$:_e(o,r,()=>new O.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=r;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$:i,hidden$:Bn(n)}}function dg(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=1,i=$(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:Ze,props:{prefix:"rightClick.insertColsLeft",min:1,max:1e3,suffix:"rightClick.insertColsLeftSuffix",disabled$:i}},value$:_e(o,r,()=>new O.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=r;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$:i,hidden$:Bn(n)}}function ug(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=1,i=$(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:Ze,props:{prefix:"rightClick.insertColsRight",min:1,max:1e3,suffix:"rightClick.insertColsRightSuffix",disabled$:i}},value$:_e(o,r,()=>new O.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=r;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$:i,hidden$:Bn(n)}}var ec=(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))(ec||{});function hg(n){const o=n.get(je);return{id:Nn.id,subId:Vo.id,type:I.MenuItemType.BUTTON,icon:"BrushIcon",title:"Format Painter",tooltip:"toolbar.formatPainter",activated$:new O.Observable(e=>{let t=!1;const r=o.status$.subscribe(i=>{t=i!==xe.OFF,e.next(t)});return e.next(t),()=>{r.unsubscribe()}}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetCopyPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0)}}function mg(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(a.IContextService),r=n.get(m.SheetsSelectionsService);return{id:Ft.id,type:I.MenuItemType.BUTTON,icon:"BoldIcon",title:"Set bold",tooltip:"toolbar.bold",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:_e(e,!1,({worksheet:i})=>new O.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 p=(S=r.getCurrentLastSelection())==null?void 0:S.primary;let v=a.FontWeight.NORMAL;if(p!=null){const C=i.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getFontWeight()}s.next(v===a.FontWeight.BOLD)}if((g===ve.SetTextSelectionsOperation.id||g===Q.SetInlineFormatCommand.id)&&t.getContextValue(a.EDITOR_ACTIVATED)&&t.getContextValue(a.FOCUSING_SHEET)){const p=Bt(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.bl;s.next(v===a.BooleanNumber.TRUE)}}),c=(u=r.getCurrentLastSelection())==null?void 0:u.primary;if(!i){s.next(!1);return}let d=a.FontWeight.NORMAL;if(c!=null){const h=i.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 gg(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService);return{id:jt.id,type:I.MenuItemType.BUTTON,icon:"ItalicIcon",title:"Set italic",tooltip:"toolbar.italic",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:_e(e,!1,({worksheet:i})=>new O.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 p=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let v=a.FontItalic.NORMAL;if(p!=null){const C=i.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getFontStyle()}s.next(v===a.FontItalic.ITALIC)}if((g===ve.SetTextSelectionsOperation.id||g===Q.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const p=Bt(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.it;s.next(v===a.BooleanNumber.TRUE)}}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d=a.FontItalic.NORMAL;if(c!=null){const h=i.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 Sg(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService);return{id:zt.id,type:I.MenuItemType.BUTTON,icon:"UnderlineIcon",title:"Set underline",tooltip:"toolbar.underline",activated$:_e(e,!1,({worksheet:i})=>new O.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 p=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let v;if(p!=null){const C=i.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getUnderline()}s.next(!!(v&&v.s))}if((g===ve.SetTextSelectionsOperation.id||g===Q.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const p=Bt(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.ul;s.next((v==null?void 0:v.s)===a.BooleanNumber.TRUE)}}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d;if(c!=null){const h=i.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getUnderline()}return s.next(!!(d&&d.s)),l.dispose})),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function fg(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService);return{id:Xt.id,type:I.MenuItemType.BUTTON,icon:"StrikethroughIcon",title:"Set strike through",tooltip:"toolbar.strikethrough",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:_e(e,!1,({worksheet:i})=>new O.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 p=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let v;if(p!=null){const C=i.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getStrikeThrough()}s.next(!!(v&&v.s))}if((g===ve.SetTextSelectionsOperation.id||g===Q.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const p=Bt(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.st;s.next((v==null?void 0:v.s)===a.BooleanNumber.TRUE)}}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d;if(c!=null){const h=i.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 pg(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=a.DEFAULT_STYLES.ff;return{id:vn.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:vn.id}}}],disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),value$:_e(e,r,({worksheet:i})=>new O.Observable(s=>{const l=()=>{var h;let d=r;const u=(h=t.getCurrentLastSelection())==null?void 0:h.primary;if(u!=null){const g=i.getCellStyle(u.startRow,u.startColumn),S=i.getDefaultCellStyleInternal(),f=i.getRowStyle(u.startRow),p=i.getColumnStyle(u.startColumn),v=a.composeStyles(S,f,p,g);v.ff&&(d=v.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 vg(n){return{id:No.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColorDoubleIcon",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Cg(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 O.Observable(r=>{var c;const i=a.DEFAULT_STYLES.cl.rgb,{isAllValuesSame:s,value:l}=t.getCellStylesProperty("cl");s?r.next((c=l==null?void 0:l.rgb)!=null?c:i):r.next(i)})}],value$:new O.Observable(r=>{const i=e.getColorFromTheme("gray.900"),s=o.onCommandExecuted(l=>{if(l.id===Cn.id){const c=l.params.value;r.next(c!=null?c:i)}});return r.next(i),s.dispose}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0)}}function Ig(n){return{id:m.ResetBackgroundColorCommand.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColorDoubleIcon",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function _g(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 O.Observable(r=>{var c;const i=a.DEFAULT_STYLES.bg.rgb,{isAllValuesSame:s,value:l}=t.getCellStylesProperty("bg");s?r.next((c=l==null?void 0:l.rgb)!=null?c:i):r.next(i)})}],value$:new O.Observable(r=>{const i=e.getColorFromTheme("primary.600"),s=o.onCommandExecuted(l=>{if(l.id===m.SetBackgroundColorCommand.id){const c=l.params.value;r.next(c!=null?c:i)}});return r.next(i),s.dispose}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const fa=[{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 bg(n){var s,l;const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=o.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET),r=t==null?void 0:t.getActiveSheet().getDefaultCellStyleInternal(),i=(s=r==null?void 0:r.ht)!=null?s:a.HorizontalAlign.LEFT;return{id:m.SetHorizontalTextAlignCommand.id,icon:(l=fa.find(c=>c.value===i))==null?void 0:l.icon,tooltip:"toolbar.horizontalAlignMode.main",type:I.MenuItemType.SELECTOR,selections:fa,value$:_e(o,i,({worksheet:c})=>new O.Observable(d=>{var S,f;const u=n.get(a.ICommandService).onCommandExecuted(p=>{var R,w;const v=p.id;if(v!==m.SetHorizontalTextAlignCommand.id&&v!==m.SetSelectionsOperation.id&&v!==m.SetWorksheetActiveOperation.id)return;const C=(R=e.getCurrentLastSelection())==null?void 0:R.primary;let _;if(C!=null){const P=c.getRange(C.startRow,C.startColumn),T=t==null?void 0:t.getActiveSheet().getComposedCellStyle(C.startRow,C.startColumn);_=(w=T==null?void 0:T.ht)!=null?w:P==null?void 0:P.getHorizontalAlignment()}d.next(_!=null?_:i)}),h=(S=e.getCurrentLastSelection())==null?void 0:S.primary;let g;if(h!=null){const p=c.getRange(h.startRow,h.startColumn),v=t==null?void 0:t.getActiveSheet().getComposedCellStyle(h.startRow,h.startColumn);g=(f=v==null?void 0:v.ht)!=null?f:p==null?void 0:p.getHorizontalAlignment()}return d.next(g!=null?g:i),u.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const pa=[{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 Rg(n){var s,l;const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=o.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET),r=t==null?void 0:t.getActiveSheet().getDefaultCellStyleInternal(),i=(s=r==null?void 0:r.vt)!=null?s:a.VerticalAlign.BOTTOM;return{id:m.SetVerticalTextAlignCommand.id,icon:(l=pa.find(c=>c.value===i))==null?void 0:l.icon,tooltip:"toolbar.verticalAlignMode.main",type:I.MenuItemType.SELECTOR,selections:pa,value$:_e(o,i,({worksheet:c})=>new O.Observable(d=>{var S,f;const u=n.get(a.ICommandService).onCommandExecuted(p=>{var R,w;const v=p.id;if(v!==m.SetVerticalTextAlignCommand.id&&v!==m.SetSelectionsOperation.id&&v!==m.SetWorksheetActiveOperation.id)return;const C=(R=e.getCurrentLastSelection())==null?void 0:R.primary;let _;if(C!=null){const P=c.getRange(C.startRow,C.startColumn),T=t==null?void 0:t.getActiveSheet().getComposedCellStyle(C.startRow,C.startColumn);_=(w=T==null?void 0:T.vt)!=null?w:P==null?void 0:P.getVerticalAlignment()}d.next(_!=null?_:i)}),h=(S=e.getCurrentLastSelection())==null?void 0:S.primary;let g;if(h!=null){const p=c.getRange(h.startRow,h.startColumn),v=t==null?void 0:t.getActiveSheet().getComposedCellStyle(h.startRow,h.startColumn);g=(f=v==null?void 0:v.vt)!=null?f:p==null?void 0:p.getVerticalAlignment()}return d.next(g!=null?g:i),u.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const va=[{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 wg(n){var s,l;const o=n.get(m.SheetsSelectionsService),e=n.get(a.IUniverInstanceService),t=e.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET),r=t==null?void 0:t.getActiveSheet().getDefaultCellStyleInternal(),i=(s=r==null?void 0:r.tb)!=null?s:a.WrapStrategy.OVERFLOW;return{id:m.SetTextWrapCommand.id,tooltip:"toolbar.textWrapMode.main",icon:(l=va.find(c=>c.value===i))==null?void 0:l.icon,type:I.MenuItemType.SELECTOR,selections:va,value$:_e(e,i,({worksheet:c})=>new O.Observable(d=>{var S,f;const u=n.get(a.ICommandService).onCommandExecuted(p=>{var R,w;const v=p.id;if(v!==m.SetTextWrapCommand.id&&v!==m.SetSelectionsOperation.id&&v!==m.SetWorksheetActiveOperation.id)return;const C=(R=o.getCurrentLastSelection())==null?void 0:R.primary;let _;if(C!=null){const P=c.getRange(C.startRow,C.startColumn),T=t==null?void 0:t.getActiveSheet().getComposedCellStyle(C.startRow,C.startColumn);_=(w=T==null?void 0:T.tb)!=null?w:P==null?void 0:P.getWrapStrategy()}d.next(_!=null?_:i)}),h=(S=o.getCurrentLastSelection())==null?void 0:S.primary;let g;if(h!=null){const p=c.getRange(h.startRow,h.startColumn),v=t==null?void 0:t.getActiveSheet().getComposedCellStyle(h.startRow,h.startColumn);g=(f=v==null?void 0:v.tb)!=null?f:p==null?void 0:p.getWrapStrategy()}return d.next(g!=null?g:i),u.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const Ca=[{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 Eg(n){const o=n.get(m.SheetsSelectionsService),e=n.get(a.IUniverInstanceService),t=0;return{id:m.SetTextRotationCommand.id,tooltip:"toolbar.textRotateMode.main",icon:Ca[0].icon,type:I.MenuItemType.SELECTOR,selections:Ca,value$:_e(e,t,({worksheet:r})=>new O.Observable(i=>{var d,u;const s=n.get(a.ICommandService).onCommandExecuted(h=>{var p,v;const g=h.id;if(g!==m.SetTextRotationCommand.id&&g!==m.SetSelectionsOperation.id&&g!==m.SetWorksheetActiveOperation.id)return;const S=(p=o.getCurrentLastSelection())==null?void 0:p.primary;let f;if(S!=null){const C=r.getRange(S.startRow,S.startColumn);f=C==null?void 0:C.getTextRotation()}(f==null?void 0:f.v)===a.BooleanNumber.TRUE?i.next("v"):i.next((v=f&&f.a)!=null?v:t)}),l=(d=o.getCurrentLastSelection())==null?void 0:d.primary;let c;if(l!=null){const h=r.getRange(l.startRow,l.startColumn);c=h==null?void 0:h.getTextRotation()}return(c==null?void 0:c.v)===a.BooleanNumber.TRUE?i.next("v"):i.next((u=c&&c.a)!=null?u:t),s.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Nr(n){return new O.Observable(e=>e.next(!n.get(I.IClipboardInterfaceService).supportClipboard))}function un(n){return{id:Ne.name,commandId:Ne.id,type:I.MenuItemType.BUTTON,title:"rightClick.copy",icon:"CopyDoubleIcon",disabled$:$(n,{workbookTypes:[m.WorkbookCopyPermission],worksheetTypes:[m.WorksheetCopyPermission],rangeTypes:[m.RangeProtectionPermissionViewPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Jo(n){return{id:Ve.name,commandId:Ve.id,type:I.MenuItemType.BUTTON,title:"rightClick.paste",icon:"PasteSpecialDoubleIcon",disabled$:Nr(n).pipe(O.combineLatestWith($(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission,m.WorksheetSetCellValuePermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([o,e])=>o||e)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const rr="sheet.menu.paste-special";function $o(n){return{id:rr,type:I.MenuItemType.SUBITEMS,icon:"PasteSpecialDoubleIcon",title:"rightClick.pasteSpecial",hidden$:Gt(n,I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET))}}function ei(n){return{id:an.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteValue",disabled$:Nr(n).pipe(O.combineLatestWith($(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellValuePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([o,e])=>o||e)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function ti(n){return{id:ln.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteFormat",disabled$:Nr(n).pipe(O.combineLatestWith($(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellStylePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([o,e])=>o||e)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function ni(n){return{id:yt.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteColWidth",disabled$:Nr(n).pipe(O.combineLatestWith($(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetColumnStylePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([o,e])=>o||e))}}function ri(n){return{id:cn.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteBesidesBorder",disabled$:Nr(n).pipe(O.combineLatestWith($(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission,m.WorksheetSetCellValuePermission,m.WorksheetSetRowStylePermission,m.WorksheetSetColumnStylePermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([o,e])=>o||e)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Tg(n){return{id:m.SetWorksheetRowIsAutoHeightCommand.id,type:I.MenuItemType.BUTTON,icon:"AutoHeightDoubleIcon",title:"rightClick.fitContent",disabled$:$(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:Vn.id,type:I.MenuItemType.BUTTON,icon:"AutoWidthDoubleIcon",title:"rightClick.fitContent",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const tc="sheet.menu.sheet-frozen";function Mg(n){return{id:tc,type:I.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Wi="sheet.header-menu.sheet-frozen";function Ia(n){return{id:Wi,type:I.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function oi(n){return{id:nt.id,type:I.MenuItemType.BUTTON,title:"rightClick.freeze",icon:"FreezeToSelectedIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Pg(n){return{id:Tr.id,type:I.MenuItemType.BUTTON,title:"rightClick.freezeRow",icon:"FreezeRowIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function xg(n){return{id:yr.id,type:I.MenuItemType.BUTTON,title:"rightClick.freezeCol",icon:"FreezeColumnIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function ii(n){return{id:m.CancelFrozenCommand.id,type:I.MenuItemType.BUTTON,title:"rightClick.cancelFreeze",icon:"CancelFreezeIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Og(n){return{id:Sr.id,type:I.MenuItemType.BUTTON,icon:"HideDoubleIcon",title:"rightClick.hideSelectedRow",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Ag(n){return{id:fr.id,type:I.MenuItemType.BUTTON,icon:"HideDoubleIcon",title:"rightClick.hideSelectedColumn",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Dg(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=[m.SetSelectionsOperation,m.SetRowHiddenMutation,m.SetRowVisibleMutation].map(i=>i.id);return{id:m.SetSelectedRowsVisibleCommand.id,type:I.MenuItemType.BUTTON,icon:"EyeOutlineIcon",title:"rightClick.showHideRow",hidden$:_e(o,!0,({worksheet:i})=>new O.Observable(s=>{function l(){var u;const d=(u=e.getCurrentSelections())==null?void 0:u.map(h=>h.range).filter(h=>h.rangeType===a.RANGE_TYPE.ROW);return!!(d!=null&&d.some(h=>{for(let g=h.startRow;g<=h.endRow;g++)if(!i.getRowRawVisible(g))return!0;return!1}))}const c=t.onCommandExecuted(d=>{r.findIndex(u=>u===d.id)!==-1&&s.next(!l())});return s.next(!l()),()=>c.dispose()})),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetRowStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function kg(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=[m.SetSelectionsOperation,m.SetColHiddenMutation,m.SetColVisibleMutation].map(i=>i.id);return{id:m.SetSelectedColsVisibleCommand.id,type:I.MenuItemType.BUTTON,icon:"EyeOutlineIcon",title:"rightClick.showHideColumn",hidden$:_e(o,!0,({worksheet:i})=>new O.Observable(s=>{function l(){var u;const d=(u=e.getCurrentSelections())==null?void 0:u.map(h=>h.range).filter(h=>h.rangeType===a.RANGE_TYPE.COLUMN);return!d||d.length===0?!1:!!d.some(h=>{for(let g=h.startColumn;g<=h.endColumn;g++)if(!i.getColVisible(g))return!0;return!1})}const c=t.onCommandExecuted(d=>{r.findIndex(u=>u===d.id)!==-1&&s.next(!l())});return s.next(!l()),()=>c.dispose()})),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetColumnStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Ng(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=2;return{id:m.SetRowHeightCommand.id,type:I.MenuItemType.BUTTON,icon:"AdjustHeightDoubleIcon",label:{name:Ze,props:{prefix:"rightClick.rowHeight",suffix:"px",min:r,max:1e3}},value$:_e(e,r,({worksheet:i})=>new O.Observable(s=>{function l(){var h;const d=(h=t.getCurrentLastSelection())==null?void 0:h.primary,u=d?i.getRowHeight(d.startRow):i.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$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetRowStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Vg(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=2;return{id:m.SetColWidthCommand.id,type:I.MenuItemType.BUTTON,icon:"AdjustWidthDoubleIcon",label:{name:Ze,props:{prefix:"rightClick.columnWidth",suffix:"px",min:r,max:1e3}},value$:_e(e,r,({worksheet:i})=>new O.Observable(s=>{function l(){var h;const d=(h=t.getCurrentLastSelection())==null?void 0:h.primary,u=d?i.getColumnWidth(d.startColumn):i.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$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const Ct={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),r=n.get(a.IUniverInstanceService),i=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=r.getUniverSheetInstance(l).getSheetBySheetId(c),g=[],S=[],f=il(h,u);if(f&&!o.defaultMerge&&!await i.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 p={unitId:l,subUnitId:c,ranges:a.Tools.deepClone(u)},v={unitId:l,subUnitId:c,ranges:a.Tools.deepClone(u)},C=m.RemoveMergeUndoMutationFactory(n,p),_=m.AddMergeUndoMutationFactory(n,v);if(C.ranges.length>0&&g.push({id:m.RemoveWorksheetMergeMutation.id,params:C}),g.push({id:m.AddWorksheetMergeMutation.id,params:v}),S.push({id:m.RemoveWorksheetMergeMutation.id,params:_}),C.ranges.length>0&&S.push({id:m.AddWorksheetMergeMutation.id,params:C}),f){const x=sl(n,l,h,u);g.unshift(...x.redos),S.push(...x.undos)}const R=m.AddMergeRedoSelectionsOperationFactory(n,o,u);R&&g.push(R);const w=m.AddMergeUndoSelectionsOperationFactory(n,o);w&&S.push(w);const T=n.get(m.SheetInterceptorService).onCommandExecute({id:Ct.id,params:{unitId:l,subUnitId:c,ranges:u}});return g.push(...T.redos),S.push(...T.undos),a.sequenceExecute(g,e).result?(t.pushUndoRedo({unitID:l,undoMutations:S,redoMutations:g}),!0):!1}},bs={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),r=rs(Ao.MergeAll,t);if(!(r!=null&&r.length))return!1;const s=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;const l=s.getActiveSheet();if(!l)return!1;const c=s.getUnitId(),d=l.getSheetId();return o.executeCommand(Ct.id,{selections:r,unitId:c,subUnitId:d})}},Rs={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),r=rs(Ao.MergeVertical,t);if(!(r!=null&&r.length))return!1;const s=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;const l=s.getActiveSheet();if(!l)return!1;const c=s.getUnitId(),d=l.getSheetId();return o.executeCommand(Ct.id,{value:a.Dimension.COLUMNS,selections:r,unitId:c,subUnitId:d})}},ws={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),r=rs(Ao.MergeHorizontal,t);if(!(r!=null&&r.length))return!1;const s=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;const l=s.getActiveSheet();if(!l)return!1;const c=s.getUnitId(),d=l.getSheetId();return o.executeCommand(Ct.id,{value:a.Dimension.ROWS,selections:r,unitId:c,subUnitId:d})}};function Hg(n){const o=n.get(m.SheetsSelectionsService),e=n.get(m.RangeProtectionRuleModel),t=n.get(a.IUniverInstanceService),r=n.get(m.MergeCellController),i=t.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET);return O.combineLatest([o.selectionMoveEnd$,i.pipe(O.map(s=>{var l;return(l=s==null?void 0:s.getUnitId())!=null?l:""})),i.pipe(O.switchMap(s=>{var l;return(l=s==null?void 0:s.activeSheet$)!=null?l:O.of(null)}))]).pipe(O.map(([s,l,c])=>{if(!c||!s||s.length===0)return!1;const d=c.getSheetId(),u=s.map(S=>S.range);if(r.interceptor.fetchThroughInterceptors(m.MERGE_CELL_INTERCEPTOR_CHECK)(!1,u))return!0;const g=e.getSubunitRuleList(l,d).map(S=>S.ranges).flat();if(s.length<2){const S=s[0].range;return g.some(p=>a.Rectangle.intersects(p,S)&&!a.Rectangle.contains(p,S))}for(let S=0;S<s.length;S++)for(let f=S+1;f<s.length;f++)if(a.Rectangle.intersects(s[S].range,s[f].range))return!0;return!1}))}function nc(n,o){return!!dr(n,o,a.RANGE_TYPE.ROW)}function rc(n,o){return!!dr(n,o,a.RANGE_TYPE.COLUMN)}function dr(n,o,e){return n.find(r=>{const i=r.range,{startRow:s,endRow:l,startColumn:c,endColumn:d,rangeType:u}=i;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 Wg(n){const o=Gt(n,$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellValuePermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})),e=Hg(n);return{id:Ct.id,icon:"MergeAllIcon",tooltip:"toolbar.mergeCell.main",type:I.MenuItemType.SUBITEMS,hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:o.pipe(O.combineLatestWith(e),O.map(([t,r])=>t||r))}}function Ug(n){return{id:bs.id,type:I.MenuItemType.BUTTON,title:"merge.all",icon:"MergeAllIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Lg(n){return{id:Rs.id,type:I.MenuItemType.BUTTON,title:"merge.vertical",icon:"VerticalIntegrationIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Bg(n){return{id:ws.id,type:I.MenuItemType.BUTTON,title:"merge.horizontal",icon:"HorizontalMergeIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Fg(n){return{id:m.RemoveWorksheetMergeCommand.id,type:I.MenuItemType.BUTTON,title:"merge.cancel",icon:"CancelMergeIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function jg(n){const e=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),t=n.get(a.UserManagerService);return O.combineLatest([e,t.currentUser$]).pipe(O.switchMap(([r,i])=>r?r.activeSheet$.pipe(O.switchMap(s=>{if(!s)return O.of(!0);const l=n.get(m.RangeProtectionRuleModel),c=n.get(m.WorksheetProtectionRuleModel),d=n.get(m.SheetsSelectionsService);return O.merge(d.selectionMoveEnd$,l.ruleChange$,c.ruleChange$).pipe(O.map(()=>{const u=r.getUnitId(),h=s.getSheetId(),g=l.getSubunitRuleList(u,h),S=d.getCurrentSelections(),f=S==null?void 0:S.map(C=>C.range),p=g.map(C=>C.ranges).flat();if(!f)return!1;const v=c.getRule(u,h);return v!=null&&v.permissionId?!0:f==null?void 0:f.some(C=>p.some(_=>a.Rectangle.intersects(C,_)))}))})):O.of(!0)))}function zg(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.RangeProtectionRuleModel),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(a.UserManagerService);return O.combineLatest([t,r.currentUser$]).pipe(O.switchMap(([i,s])=>i?i.activeSheet$.pipe(O.switchMap(l=>{if(!l)return O.of(!0);const c=n.get(m.RangeProtectionRuleModel),d=n.get(m.WorksheetProtectionRuleModel),u=n.get(a.IPermissionService),h=n.get(m.SheetsSelectionsService);return O.merge(h.selectionMoveEnd$,c.ruleChange$,d.ruleChange$).pipe(O.map(()=>{var x,A;const g=i.getUnitId(),S=l.getSheetId(),f=e.getSubunitRuleList(g,S),p=(x=h.getCurrentSelections())==null?void 0:x.map(D=>D.range);if(f.map(D=>D.ranges).flat(),!(p!=null&&p.length)||p.length>1)return!0;const v=p[0];if((v==null?void 0:v.rangeType)===a.RANGE_TYPE.ALL||(v==null?void 0:v.rangeType)===a.RANGE_TYPE.COLUMN||(v==null?void 0:v.rangeType)===a.RANGE_TYPE.ROW)return!0;const C=d.getRule(g,S);if(C!=null&&C.permissionId)return((A=u.getPermissionPoint(new m.WorksheetManageCollaboratorPermission(g,S).id))==null?void 0:A.value)===!1;if(f.filter(D=>D.ranges.some(k=>a.Rectangle.intersects(k,v))).length!==1)return!0;const{startRow:R,endRow:w,startColumn:P,endColumn:T}=v,M=n.get(m.RangeProtectionCache);for(let D=R;D<=w;D++)for(let k=P;k<=T;k++){const H=M.getCellInfo(g,S,D,k);if(H)return H[m.UnitAction.ManageCollaborator]===!1}return!1}))})):O.of(!0)))}function Xg(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(a.UserManagerService);return O.combineLatest([t,r.currentUser$]).pipe(O.switchMap(([i,s])=>i?i.activeSheet$.pipe(O.switchMap(l=>{var f;if(!l)return O.of(!0);const c=i.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(O.map(p=>p.every(v=>v.value))))!=null?f:O.of(!1),S=O.merge(u.ruleChange$,h.ruleChange$).pipe(O.startWith(null));return O.combineLatest([g,S,d.selectionMoveEnd$]).pipe(O.map(([p,v,C])=>{if(!p)return!0;const _=d.getCurrentSelections(),R=_==null?void 0:_.map(w=>w.range);return R!=null&&R.length?R.length>1:!1}))})):O.of(!0)))}function oc(n){var d;const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(a.UserManagerService),i=n.has(he)?n.get(he):null,l=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_FX_BAR_EDITOR).pipe(O.startWith(!1),O.shareReplay(1)),c=(d=i==null?void 0:i.visible$.pipe(O.startWith(null),O.shareReplay(1)))!=null?d:O.of(null);return O.combineLatest([t,r.currentUser$,c,l]).pipe(O.switchMap(([u,h,g,S])=>!u||g!=null&&g.visible&&g.unitId===u.getUnitId()||S?O.of(!0):u.activeSheet$.pipe(O.switchMap(f=>{var x;if(!f)return O.of(!0);const v=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_COMMON_DRAWINGS).pipe(O.startWith(!1)),C=u.getUnitId(),_=f.getSheetId(),R=n.get(m.RangeProtectionRuleModel),w=n.get(m.WorksheetProtectionRuleModel),P=n.get(m.SheetsSelectionsService),T=(x=e.composePermission$([new m.WorkbookCreateProtectPermission(C).id]).pipe(O.map(A=>A.every(D=>D.value))))!=null?x:O.of(!1),M=O.merge(R.ruleChange$,w.ruleChange$).pipe(O.startWith(null));return O.combineLatest([T,M,P.selectionMoveEnd$,v]).pipe(O.map(([A,D,k,H])=>{if(!A||H)return!0;const N=P.getCurrentSelections(),V=N==null?void 0:N.map(B=>B.range);if(!(V!=null&&V.length))return!0;const L=w.getRule(C,_);if(L!=null&&L.permissionId)return!0;const U=R.getSubunitRuleList(C,_);return V==null?void 0:V.some(B=>U.some(z=>z.ranges.some(X=>a.Rectangle.intersects(B,X))))}))}))))}function Yg(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(a.UserManagerService);return O.combineLatest([t,r.currentUser$]).pipe(O.switchMap(([i,s])=>i?i.activeSheet$.pipe(O.switchMap(l=>{var f;if(!l)return O.of(!0);const c=i.getUnitId(),d=l.getSheetId(),u=n.get(m.RangeProtectionRuleModel),h=n.get(m.WorksheetProtectionRuleModel),g=(f=e.composePermission$([new m.WorkbookCreateProtectPermission(c).id]).pipe(O.map(p=>p.every(v=>v.value))))!=null?f:O.of(!1),S=O.merge(u.ruleChange$,h.ruleChange$).pipe(O.startWith(null));return O.combineLatest([g,S]).pipe(O.map(([p,v])=>{var R;if(!p)return!0;const C=h.getRule(c,d);return C!=null&&C.permissionId?!0:((R=u.getSubunitRuleList(c,d))==null?void 0:R.filter(w=>w==null?void 0:w.permissionId)).length>0}))})):O.of(!0)))}function Zg(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(a.UserManagerService);return O.combineLatest([t,r.currentUser$]).pipe(O.switchMap(([i,s])=>i?i.activeSheet$.pipe(O.switchMap(l=>{if(!l)return O.of(!0);const c=i.getUnitId(),d=l.getSheetId(),u=n.get(m.WorksheetProtectionRuleModel);return u.ruleChange$.pipe(O.startWith(null)).pipe(O.map(()=>{var g;return u.getRule(c,d)?((g=e.getPermissionPoint(new m.WorksheetDeleteProtectionPermission(c,d).id))==null?void 0:g.value)===!1:!0}))})):O.of(!0)))}function Gg(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(a.UserManagerService);return O.combineLatest([t,r.currentUser$]).pipe(O.switchMap(([i,s])=>i?i.activeSheet$.pipe(O.switchMap(l=>{var f;if(!l)return O.of(!0);const c=i.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(O.map(p=>p.every(v=>v.value))))!=null?f:O.of(!1),g=u.ruleChange$.pipe(O.startWith(null)),S=d.ruleChange$.pipe(O.startWith(null));return O.combineLatest([h,g,S]).pipe(O.map(([p,v,C])=>{if(!p)return!0;const _=l.getSheetId(),R=u.getRule(c,_),w=d.getSubunitRuleList(c,_);return!(R||w.length)}))})):O.of(!0)))}function Kg(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(a.UserManagerService);return O.combineLatest([t,r.currentUser$]).pipe(O.switchMap(([i,s])=>i?i.activeSheet$.pipe(O.switchMap(l=>{if(!l)return O.of(!0);const c=i.getUnitId(),d=l.getSheetId(),u=n.get(m.SheetsSelectionsService),h=n.get(m.RangeProtectionRuleModel),g=n.get(m.WorksheetProtectionRuleModel),S=O.merge(h.ruleChange$,g.ruleChange$,u.selectionMoveEnd$).pipe(O.startWith(null));return O.combineLatest([S]).pipe(O.map(([f])=>{var A;const p=n.get(m.SheetsSelectionsService).getCurrentSelections(),v=p==null?void 0:p.map(D=>D.range);if(!(v!=null&&v.length)||v.length>1)return!0;const C=v[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((A=e.getPermissionPoint(new m.WorksheetDeleteProtectionPermission(c,d).id))==null?void 0:A.value)===!1;if(h.getSubunitRuleList(c,d).filter(D=>D.ranges.some(k=>a.Rectangle.intersects(k,C))).length!==1)return!0;const{startRow:w,endRow:P,startColumn:T,endColumn:M}=C,x=n.get(m.RangeProtectionCache);for(let D=w;D<=P;D++)for(let k=T;k<=M;k++){const H=x.getCellInfo(c,d,D,k);if(H)return H[m.UnitAction.Delete]===!1}return!1}))})):O.of(!0)))}function ic(n){var d;const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(a.UserManagerService),i=n.has(he)?n.get(he):null,l=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_FX_BAR_EDITOR),c=(d=i==null?void 0:i.visible$)!=null?d:O.of(null);return O.combineLatest([t,r.currentUser$,c,l]).pipe(O.switchMap(([u,h,g,S])=>!u||g!=null&&g.visible&&g.unitId===u.getUnitId()||S?O.of(!0):u.activeSheet$.pipe(O.switchMap(f=>{var C,_;if(!f)return O.of(!0);const p=u.getUnitId();return((_=(C=e.getPermissionPoint$(new m.WorkbookEditablePermission(p).id))==null?void 0:C.pipe(O.map(R=>!!R.value)))!=null?_:O.of(!1)).pipe(O.map(R=>!R))}))))}const qr="sheet.contextMenu.permission";function qg(n){return{id:Cr.id,type:I.MenuItemType.BUTTON,icon:nl,tooltip:"permission.toolbarMenu",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:oc(n)}}function si(n){return{id:qr,type:I.MenuItemType.SUBITEMS,title:"rightClick.protectRange",icon:rl,hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function ai(n){return{id:Mt.id,type:I.MenuItemType.BUTTON,title:"rightClick.turnOnProtectRange",hidden$:jg(n),disabled$:oc(n)}}function li(n){return{id:Ot.id,type:I.MenuItemType.BUTTON,title:"rightClick.editProtectRange",disabled$:Xg(n),hidden$:zg(n)}}function ci(n){return{id:xt.id,type:I.MenuItemType.BUTTON,title:"rightClick.removeProtectRange",disabled$:Kg(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function di(n){return{id:Pt.id,type:I.MenuItemType.BUTTON,title:"rightClick.viewAllProtectArea",disabled$:ic(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Qg(n){return{id:Ir.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.addProtectSheet",disabled$:Yg(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Jg(n){return{id:xr.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.removeProtectSheet",disabled$:Zg(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function $g(n){return{id:Or.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.changeSheetPermission",disabled$:Gg(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function eS(n){return{id:_r.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.viewAllProtectArea",disabled$:ic(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function tS(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.ICommandService),t=new O.Observable(i=>{const s=e.onCommandExecuted(l=>{const c=l.id;(c===m.RemoveSheetMutation.id||c===m.InsertSheetMutation.id||c===m.SetWorksheetHideMutation.id)&&ao(o,i)});return ao(o,i),s.dispose}),r=Fn(n,[m.WorkbookEditablePermission,m.WorkbookDeleteSheetPermission]);return{id:Rr.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.delete",disabled$:O.combineLatest([t,r]).pipe(O.map(([i,s])=>i||s)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function nS(n){return{id:m.CopySheetCommand.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.copy",disabled$:Fn(n,[m.WorkbookEditablePermission,m.WorkbookCreateSheetPermission]),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function rS(n){return{id:Dr.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.rename",disabled$:Fn(n,[m.WorkbookEditablePermission,m.WorkbookRenameSheetPermission]),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function oS(n){return{id:m.SetTabColorCommand.id,title:"sheetConfig.changeColor",type:I.MenuItemType.SELECTOR,selections:[{label:{name:I.COLOR_PICKER_COMPONENT,hoverable:!1}}],hidden$:Fn(n,[m.WorkbookEditablePermission])}}function iS(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 O.Observable(t=>{const r=e.onCommandExecuted(i=>{const s=i.id;(s===m.RemoveSheetMutation.id||s===m.InsertSheetMutation.id||s===m.SetWorksheetHideMutation.id)&&ao(o,t)});return ao(o,t),r.dispose}).pipe(O.combineLatestWith(Fn(n,[m.WorkbookEditablePermission,m.WorkbookHideSheetPermission])),O.map(([t,r])=>t||r)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function sS(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.ICommandService);return{id:Pr.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.unhide",disabled$:new O.Observable(t=>{function r(){const s=o.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getWorksheets(),l=Array.from(s.values());t.next(l.length===1)}const i=e.onCommandExecuted(s=>{const l=s.id;(l===m.RemoveSheetMutation.id||l===m.InsertSheetMutation.id||l===m.SetWorksheetHideMutation.id)&&r()});return r(),i.dispose}).pipe(O.combineLatestWith(Fn(n,[m.WorkbookEditablePermission,m.WorkbookHideSheetPermission])),O.map(([t,r])=>t||r)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function ao(n,o){const e=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getWorksheets(),t=Array.from(e.values()).filter(r=>r.getConfig().hidden===a.BooleanNumber.FALSE);o.next(t.length===1)}const sc={[I.RibbonPosition.START]:{[I.RibbonStartGroup.HISTORY]:{[Nn.id]:{order:2,menuItemFactory:hg},[m.ClearSelectionAllCommand.id]:{order:3,menuItemFactory:Br}},[I.RibbonStartGroup.FORMAT]:{[vn.id]:{order:1,menuItemFactory:pg},[pr.id]:{order:2,menuItemFactory:$m},[Do.id]:{order:2.1,menuItemFactory:eg},[ko.id]:{order:2.2,menuItemFactory:tg},[Ft.id]:{order:5,menuItemFactory:mg},[jt.id]:{order:6,menuItemFactory:gg},[zt.id]:{order:7,menuItemFactory:Sg},[Xt.id]:{order:8,menuItemFactory:fg},[Cn.id]:{order:9,menuItemFactory:Cg,[m.ResetTextColorCommand.id]:{order:0,menuItemFactory:vg}},[m.SetBackgroundColorCommand.id]:{order:10,menuItemFactory:_g,[m.ResetBackgroundColorCommand.id]:{order:0,menuItemFactory:Ig}},[m.SetBorderBasicCommand.id]:{order:11,menuItemFactory:Gm}},[I.RibbonStartGroup.LAYOUT]:{[m.SetHorizontalTextAlignCommand.id]:{order:0,menuItemFactory:bg},[m.SetVerticalTextAlignCommand.id]:{order:3,menuItemFactory:Rg},[m.SetTextWrapCommand.id]:{order:6,menuItemFactory:wg},[m.SetTextRotationCommand.id]:{order:7,menuItemFactory:Eg},[m.AddWorksheetMergeCommand.id]:{order:8,menuItemFactory:Wg,[m.AddWorksheetMergeAllCommand.id]:{order:0,menuItemFactory:Ug},[m.AddWorksheetMergeVerticalCommand.id]:{order:1,menuItemFactory:Lg},[m.AddWorksheetMergeHorizontalCommand.id]:{order:2,menuItemFactory:Bg},[m.RemoveWorksheetMergeCommand.id]:{order:3,menuItemFactory:Fg}}},[I.RibbonStartGroup.OTHERS]:{[Cr.id]:{order:0,menuItemFactory:qg}}},[I.ContextMenuPosition.MAIN_AREA]:{[I.ContextMenuGroup.FORMAT]:{[Ne.name]:{order:0,menuItemFactory:un},[Ve.name]:{order:2,menuItemFactory:Jo},[rr]:{order:3,menuItemFactory:$o,[an.id]:{order:0,menuItemFactory:ei},[ln.id]:{order:1,menuItemFactory:ti},[yt.id]:{order:2,menuItemFactory:ni},[cn.id]:{order:3,menuItemFactory:ri}},[Kr]:{order:4,menuItemFactory:Ko,[m.ClearSelectionContentCommand.id]:{order:0,menuItemFactory:qo},[m.ClearSelectionFormatCommand.id]:{order:1,menuItemFactory:Qo},[m.ClearSelectionAllCommand.id]:{order:2,menuItemFactory:Br}}},[I.ContextMenuGroup.LAYOUT]:{order:1,[$l]:{order:0,menuItemFactory:rg,[m.InsertRowBeforeCommand.id]:{order:0,menuItemFactory:og},[m.InsertColBeforeCommand.id]:{order:1,menuItemFactory:ig},[kn.id]:{order:2,menuItemFactory:sg},[Vt.id]:{order:3,menuItemFactory:ag}},[Ql]:{order:0,menuItemFactory:Km,[_n.id]:{order:0,menuItemFactory:ga},[In.id]:{order:1,menuItemFactory:Sa},[Dn.id]:{order:2,menuItemFactory:qm},[Nt.id]:{order:3,menuItemFactory:Qm}},[tc]:{order:2,menuItemFactory:Mg,[nt.id]:{order:0,menuItemFactory:oi},[Tr.id]:{order:1,menuItemFactory:Pg},[yr.id]:{order:2,menuItemFactory:xg},[m.CancelFrozenCommand.id]:{order:3,menuItemFactory:ii}},[qr]:{order:3,menuItemFactory:si,[Mt.id]:{order:0,menuItemFactory:ai},[Ot.id]:{order:1,menuItemFactory:li},[xt.id]:{order:2,menuItemFactory:ci},[Pt.id]:{order:3,menuItemFactory:di}}},[I.ContextMenuGroup.DATA]:{order:2},[I.ContextMenuGroup.OTHERS]:{order:3}},[I.ContextMenuPosition.COL_HEADER]:{[I.ContextMenuGroup.FORMAT]:{[Ne.name]:{order:0,menuItemFactory:un},[Ve.name]:{order:2,menuItemFactory:Jo},[rr]:{order:3,menuItemFactory:$o,[an.id]:{order:0,menuItemFactory:ei},[ln.id]:{order:1,menuItemFactory:ti},[yt.id]:{order:2,menuItemFactory:ni},[cn.id]:{order:3,menuItemFactory:ri}},[Kr]:{order:4,menuItemFactory:Ko,[m.ClearSelectionContentCommand.id]:{order:0,menuItemFactory:qo},[m.ClearSelectionFormatCommand.id]:{order:1,menuItemFactory:Qo},[m.ClearSelectionAllCommand.id]:{order:2,menuItemFactory:Br}}},[I.ContextMenuGroup.LAYOUT]:{order:1,[m.InsertMultiColsLeftCommand.id]:{order:0,menuItemFactory:dg},[m.InsertMultiColsRightCommand.id]:{order:0,menuItemFactory:ug},[fr.id]:{order:1,menuItemFactory:Ag},[m.SetSelectedColsVisibleCommand.id]:{order:2,menuItemFactory:kg},[_n.id]:{order:2,menuItemFactory:ga},[m.SetColWidthCommand.id]:{order:3,menuItemFactory:Vg},[Vn.id]:{order:4,menuItemFactory:yg},[Wi]:{order:5,menuItemFactory:Ia,[nt.id]:{order:0,menuItemFactory:oi},[m.CancelFrozenCommand.id]:{order:3,menuItemFactory:ii}},[qr]:{order:6,menuItemFactory:si,[Mt.id]:{order:0,menuItemFactory:ai},[Ot.id]:{order:1,menuItemFactory:li},[xt.id]:{order:2,menuItemFactory:ci},[Pt.id]:{order:3,menuItemFactory:di}}},[I.ContextMenuGroup.DATA]:{order:2},[I.ContextMenuGroup.OTHERS]:{order:3}},[I.ContextMenuPosition.ROW_HEADER]:{[I.ContextMenuGroup.FORMAT]:{[Ne.name]:{order:0,menuItemFactory:un},[Ve.name]:{order:2,menuItemFactory:Jo},[rr]:{order:3,menuItemFactory:$o,[an.id]:{order:0,menuItemFactory:ei},[ln.id]:{order:1,menuItemFactory:ti},[yt.id]:{order:2,menuItemFactory:ni},[cn.id]:{order:3,menuItemFactory:ri}},[Kr]:{order:4,menuItemFactory:Ko,[m.ClearSelectionContentCommand.id]:{order:0,menuItemFactory:qo},[m.ClearSelectionFormatCommand.id]:{order:1,menuItemFactory:Qo},[m.ClearSelectionAllCommand.id]:{order:2,menuItemFactory:Br}}},[I.ContextMenuGroup.LAYOUT]:{order:1,[m.InsertMultiRowsAboveCommand.id]:{order:0,menuItemFactory:cg},[m.InsertMultiRowsAfterCommand.id]:{order:1,menuItemFactory:lg},[In.id]:{order:1,menuItemFactory:Sa},[Sr.id]:{order:2,menuItemFactory:Og},[m.SetSelectedRowsVisibleCommand.id]:{order:2,menuItemFactory:Dg},[m.SetRowHeightCommand.id]:{order:3,menuItemFactory:Ng},[m.SetWorksheetRowIsAutoHeightCommand.id]:{order:4,menuItemFactory:Tg},[Wi]:{order:5,menuItemFactory:Ia,[nt.id]:{order:0,menuItemFactory:oi},[m.CancelFrozenCommand.id]:{order:3,menuItemFactory:ii}},[qr]:{order:6,menuItemFactory:si,[Mt.id]:{order:0,menuItemFactory:ai},[Ot.id]:{order:1,menuItemFactory:li},[xt.id]:{order:2,menuItemFactory:ci},[Pt.id]:{order:3,menuItemFactory:di}}},[I.ContextMenuGroup.DATA]:{order:2},[I.ContextMenuGroup.OTHERS]:{order:3}},[I.ContextMenuPosition.FOOTER_TABS]:{[I.ContextMenuGroup.OTHERS]:{order:0,[Rr.id]:{order:0,menuItemFactory:tS},[m.CopySheetCommand.id]:{order:1,menuItemFactory:nS},[Dr.id]:{order:2,menuItemFactory:rS},[m.SetTabColorCommand.id]:{order:3,menuItemFactory:oS},[m.SetWorksheetHideCommand.id]:{order:4,menuItemFactory:iS},[Pr.id]:{order:6,menuItemFactory:sS},[Ir.id]:{order:7,menuItemFactory:Qg},[xr.id]:{order:8,menuItemFactory:Jg},[Or.id]:{order:9,menuItemFactory:$g},[_r.id]:{order:10,menuItemFactory:eS}}},[I.ContextMenuPosition.FOOTER_MENU]:{[I.ContextMenuGroup.OTHERS]:{[m.ToggleGridlinesCommand.id]:{order:1,menuItemFactory:ng}}}},ui="UNIVER_SHEET_PERMISSION_ALERT_DIALOG_ID",ac="UNIVER_SHEET_PERMISSION_ALERT_DIALOG";var aS=Object.getOwnPropertyDescriptor,lS=(n,o,e,t)=>{for(var r=t>1?void 0:t?aS(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Ke=(n,o)=>(e,t)=>o(e,t,n);exports.SheetPermissionCheckUIController=class extends a.Disposable{constructor(e,t,r,i,s,l,c,d,u){super();E(this,"disposableCollection",new a.DisposableCollection);this._commandService=e,this._univerInstanceService=t,this._permissionService=r,this._dialogService=i,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:ui,title:{title:"permission.dialog.alert"},children:{label:ac,errorMsg:e},width:320,destroyOnClose:!0,showOk:!0,onClose:()=>{this._dialogService.close(ui)},onOk:()=>{this._dialogService.close(ui)},className:"sheet-permission-user-dialog"};this._permissionService.getShowComponents()&&this._dialogService.open(t)}_getPermissionCheck(e,t){var s,l;let r=!0,i="";switch(e){case Q.InsertCommand.id:case Q.IMEInputCommand.id:if(this._contextService.getContextValue(a.FOCUSING_EDITOR_STANDALONE)===!0)break;r=this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellValuePermission,m.WorksheetEditPermission]}),i=this._localeService.t("permission.dialog.editErr");break;case Se.id:if(t.visible===!1)break;r=this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellValuePermission,m.WorksheetEditPermission]}),i=this._localeService.t("permission.dialog.editErr");break;case yt.id:r=this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission]}),i=this._localeService.t("permission.dialog.pasteErr");break;case to.id:r=this._permissionCheckByPaste(t),i=this._localeService.t("permission.dialog.pasteErr");break;case Er.id:r=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellValuePermission,m.WorksheetSetCellStylePermission]}),i=this._localeService.t("permission.dialog.commonErr");break;case m.SetBackgroundColorCommand.id:case Ft.id:case jt.id:case zt.id:case Xt.id:r=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellStylePermission,m.WorksheetEditPermission]}),i=this._localeService.t("permission.dialog.setStyleErr");break;case Ne.id:r=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookCopyPermission],rangeTypes:[m.RangeProtectionPermissionViewPoint],worksheetTypes:[m.WorksheetCopyPermission]}),i=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||(i=this._localeService.t("permission.dialog.workbookCopyErr"));break;case Oo.id:r=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookCopyPermission,m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionViewPoint,m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetCopyPermission,m.WorksheetEditPermission]}),i=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||(i=this._localeService.t("permission.dialog.workbookCopyErr"));break;case dt.id:r=this._permissionCheckByAutoFillCommand(t),i=this._localeService.t("permission.dialog.autoFillErr");break}r||this._sheetPermissionCheckController.blockExecuteWithoutPermission(i)}_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,r=m.getSheetCommandTarget(this._univerInstanceService);if(!r)return!1;const{worksheet:i,unitId:s,subUnitId:l}=r;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 p=(g=(h=i.getCell(S,f))==null?void 0:h.selectionProtection)==null?void 0:g[0];if((p==null?void 0:p[J.Edit])===!1)return!0}return!1})}};exports.SheetPermissionCheckUIController=lS([Ke(0,a.ICommandService),Ke(1,a.IUniverInstanceService),Ke(2,a.IPermissionService),Ke(3,I.IDialogService),Ke(4,a.Inject(m.RangeProtectionRuleModel)),Ke(5,ft),Ke(6,a.Inject(a.LocaleService)),Ke(7,a.IContextService),Ke(8,a.Inject(m.SheetPermissionCheckController))],exports.SheetPermissionCheckUIController);var cS=Object.getOwnPropertyDescriptor,dS=(n,o,e,t)=>{for(var r=t>1?void 0:t?cS(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},wt=(n,o)=>(e,t)=>o(e,t,n);const uS="__SpreadsheetFreezeRowMainName__",hS="__SpreadsheetFreezeRowHeaderName__",mS="__SpreadsheetFreezeColumnMainName__",gS="__SpreadsheetFreezeColumnHeaderName__",hi=2,SS=.01,Yn=a.createInterceptorKey("freezePermissionCheck");exports.HeaderFreezeRenderController=class extends a.Disposable{constructor(e,t,r,i,s,l,c,d){super();E(this,"_rowFreezeHeaderRect");E(this,"_rowFreezeMainRect");E(this,"_columnFreezeHeaderRect");E(this,"_columnFreezeMainRect");E(this,"_freezeDownSubs");E(this,"_freezePointerEnterSubs");E(this,"_freezePointerLeaveSubs");E(this,"_scenePointerMoveSub");E(this,"_scenePointerUpSub");E(this,"_changeToRow",-1);E(this,"_changeToColumn",-1);E(this,"_changeToOffsetX",0);E(this,"_changeToOffsetY",0);E(this,"_activeViewport",null);E(this,"_freezeNormalHeaderColor","");E(this,"_freezeNormalMainColor","");E(this,"_freezeActiveColor","");E(this,"_freezeHoverColor","");E(this,"_lastFreeze");E(this,"interceptor",new a.InterceptorManager({FREEZE_PERMISSION_CHECK:Yn}));this._context=e,this._sheetSkeletonManagerService=t,this._commandService=r,this._selectionManagerService=i,this._scrollManagerService=s,this._themeService=l,this._sheetInterceptorService=c,this._injector=d,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._themeChangeListener(),this._interceptorCommands(),this._bindViewportScroll(),this._zoomRefresh()}_createFreeze(e=0,t){var x;const r=t!=null?t:this._getFreeze();if(r==null)return null;const i=(x=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:x.skeleton,{startRow:s,startColumn:l}=r,c=this._getPositionByIndex(s,l);if(c==null||i==null)return null;const d=this._getSheetObject(),u=d.engine,h=(u==null?void 0:u.width)||0,g=(u==null?void 0:u.height)||0,S=d.scene,{startX:f,startY:p}=c,{rowTotalHeight:v,columnTotalWidth:C,rowHeaderWidthAndMarginLeft:_,columnHeaderHeightAndMarginTop:R}=i,w=h>C+_?h:C+R,P=g>v+R?g:v+R;this._changeToRow=s,this._changeToColumn=l,this._changeToOffsetX=f,this._changeToOffsetY=p;const T=Math.max(S.scaleX,S.scaleY);let M=hi/Math.max(1,T);if(e===0){(s===-1||s===0)&&(M=M*2);const A=M;this._rowFreezeHeaderRect=new y.Rect(hS,{fill:this._freezeNormalHeaderColor,width:_,height:M,left:0,top:p-A,zIndex:3});let D=this._freezeNormalHeaderColor;(s===-1||s===0)&&(D=this._freezeNormalMainColor),this._rowFreezeMainRect=new y.Rect(uS,{fill:D,width:w*2/T,height:M,left:_,top:p-A,zIndex:3}),S.addObjects([this._rowFreezeHeaderRect,this._rowFreezeMainRect],ht)}else{(l===-1||l===0)&&(M=M*2);const A=M;this._columnFreezeHeaderRect=new y.Rect(gS,{fill:this._freezeNormalHeaderColor,width:M,height:R,left:f-A,top:0,zIndex:3});let D=this._freezeNormalHeaderColor;(l===-1||l===0)&&(D=this._freezeNormalMainColor),this._columnFreezeMainRect=new y.Rect(mS,{fill:D,width:M,height:P*2/T,left:f-A,top:R,zIndex:3}),S.addObjects([this._columnFreezeHeaderRect,this._columnFreezeMainRect],ht)}this._eventBinding(e)}_eventBinding(e=0){let t=this._rowFreezeHeaderRect,r=this._rowFreezeMainRect;e===1&&(t=this._columnFreezeHeaderRect,r=this._columnFreezeMainRect);const i=this._getSheetObject();if(i==null)return;const{scene:s}=i;if(this._freezePointerEnterSubs=new O.Subscription,this._freezePointerLeaveSubs=new O.Subscription,this._freezeDownSubs=new O.Subscription,r){const d=r.onPointerEnter$.subscribeEvent(()=>{if(!this.interceptor.fetchThroughInterceptors(Yn)(!0,null))return!1;t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),s.setCursor(y.CURSOR_TYPE.GRAB)});this._freezePointerEnterSubs.add(d);const u=r.onPointerLeave$.subscribeEvent(()=>{t==null||t.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),s.resetCursor()});this._freezePointerLeaveSubs.add(u)}if(t){const d=t.onPointerEnter$.subscribeEvent(()=>{if(!this.interceptor.fetchThroughInterceptors(Yn)(!0,null))return!1;t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),s.setCursor(y.CURSOR_TYPE.GRAB)});this._freezePointerEnterSubs.add(d);const u=t.onPointerLeave$.subscribeEvent(()=>{t==null||t.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),s.resetCursor()});this._freezePointerLeaveSubs.add(u)}const l=t==null?void 0:t.onPointerDown$.subscribeEvent(d=>{this._freezeDown(d,t,r,e)});l&&this._freezeDownSubs.add(l);const c=r==null?void 0:r.onPointerDown$.subscribeEvent(d=>{this._freezeDown(d,t,r,e)});c&&this._freezeDownSubs.add(c)}_getCurrentLastVisible(){var C,_,R,w,P,T,M;const e=this._getSheetObject();if(e==null)return;const t=(C=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:C.skeleton;if(t==null)return;const r=e.scene,i=Math.max(r.scaleX,r.scaleY),s=this._scrollManagerService.getCurrentScrollState(),l=(e.engine.height-t.columnHeaderHeight)/i,c=(e.engine.width-t.rowHeaderWidth)/i,d=(_=s==null?void 0:s.sheetViewStartRow)!=null?_:0,u=d===0?-((R=s==null?void 0:s.offsetY)!=null?R:0):t.rowHeightAccumulation[d-1]-((w=s==null?void 0:s.offsetY)!=null?w:0);let h=0,g=!1;for(let x=d,A=t.rowHeightAccumulation.length;x<A;x++)if(t.rowHeightAccumulation[x]-u>l){h=x,g=!0;break}g||(h=t.rowHeightAccumulation.length-1);const S=(P=s==null?void 0:s.sheetViewStartColumn)!=null?P:0,f=S===0?-((T=s==null?void 0:s.offsetX)!=null?T:0):t.columnWidthAccumulation[S-1]-((M=s==null?void 0:s.offsetX)!=null?M:0);let p=0,v=!1;for(let x=S,A=t.columnWidthAccumulation.length;x<A;x++)if(t.columnWidthAccumulation[x]-f>c){p=x,v=!0;break}return v||(p=t.columnWidthAccumulation.length-1),{lastRow:h,lastColumn:p}}_getActiveViewport(e){var r;const t=(r=this._getSheetObject())==null?void 0:r.scene.getViewports();return t&&t.find(i=>i.isHit(new y.Vector2(e.offsetX,e.offsetY)))||null}_freezeDown(e,t,r,i=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(Yn)(!0,null))return!1;const{scene:d}=l;d.setCursor(y.CURSOR_TYPE.GRABBING),d.disableObjectsEvent();const u=this._getCurrentLastVisible(),h=u===void 0?Number.POSITIVE_INFINITY:s.rowHeightAccumulation[u.lastRow],g=u===void 0?Number.POSITIVE_INFINITY:s.columnWidthAccumulation[u.lastColumn-1]+s.rowHeaderWidth;this._activeViewport=null;const S=this._getFreeze();S&&(this._changeToColumn=S.startColumn,this._changeToRow=S.startRow),this._scenePointerMoveSub=d.onPointerMove$.subscribeEvent(p=>{var M,x,A,D;const v=this._getActiveViewport(p),{startX:C,startY:_,row:R,column:w}=Fe(p.offsetX,p.offsetY,d,s,v||void 0,!0);if(!this.interceptor.fetchThroughInterceptors(Yn)(!0,null))return!1;d.setCursor(y.CURSOR_TYPE.GRABBING);const T=hi/Math.max(d.scaleX,d.scaleY);i===0?((M=t.transformByState({top:Math.min(_,h)-T/2}))==null||M.setProps({fill:this._freezeActiveColor}),(x=r.transformByState({top:Math.min(_,h)-T/2}))==null||x.setProps({fill:this._freezeNormalHeaderColor}),this._changeToRow=u===void 0?R:Math.min(R,u.lastRow),this._changeToOffsetY=Math.min(_,h),this._activeViewport=v):((A=t.transformByState({left:Math.min(C,g)-T/2}))==null||A.setProps({fill:this._freezeActiveColor}),(D=r.transformByState({left:Math.min(C,g)-T/2}))==null||D.setProps({fill:this._freezeNormalHeaderColor}),this._changeToColumn=u===void 0?w:Math.min(w,u.lastColumn),this._changeToOffsetX=C,this._activeViewport=v)}),this._scenePointerUpSub=d.onPointerUp$.subscribeEvent(()=>{var k,H;d.resetCursor(),d.enableObjectsEvent(),this._clearObserverEvent();const{rowHeaderWidthAndMarginLeft:p,columnHeaderHeightAndMarginTop:v}=s;i===0&&(this._changeToRow===0||this._changeToRow===-1)||i===1&&(this._changeToColumn===0||this._changeToColumn===-1)?(t.setProps({fill:this._freezeNormalHeaderColor}),r.setProps({fill:this._freezeNormalMainColor})):(t==null||t.setProps({fill:this._freezeNormalHeaderColor}),r==null||r.setProps({fill:this._freezeNormalHeaderColor}));const C=hi/Math.max(d.scaleX,d.scaleY);i===0?(this._changeToRow===0||this._changeToRow===-1)&&(t.transformByState({top:v-C}),r.transformByState({top:v-C})):(this._changeToColumn===0||this._changeToColumn===-1)&&(t.transformByState({left:p-C}),r.transformByState({left:p-C}));const _=this._scrollManagerService.getCurrentScrollState()||{sheetViewStartRow:0,sheetViewStartColumn:0},{sheetViewStartRow:R,sheetViewStartColumn:w}=_;if(w==null||R==null)return;const P=this._context.unit,T=P.getActiveSheet();if(!T)return;const M=(k=T.getConfig())==null?void 0:k.freeze;let x=(M==null?void 0:M.xSplit)||0,A=(M==null?void 0:M.ySplit)||0;const D=(H=this._activeViewport)==null?void 0:H.viewportKey;i===0&&(!D||D===y.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP||D===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP||D===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||D===y.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP?A=this._changeToRow-(M.startRow-M.ySplit):A=this._changeToRow-R,A=A<0?0:A),i===1&&(!D||D===y.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP||D===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP||D===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||D===y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT?x=this._changeToColumn-(M.startColumn-M.xSplit):x=this._changeToColumn-w,x=x<0?0:x),this._commandService.executeCommand(m.SetFrozenCommand.id,{startRow:A===0?-1:this._changeToRow,startColumn:x===0?-1:this._changeToColumn,ySplit:A,xSplit:x,unitId:P.getUnitId(),subUnitId:T.getSheetId()})})}_getViewports(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e,r=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT),i=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT),s=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP),l=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM),c=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP),d=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN),u=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP),h=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT),g=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(!(r==null||i==null||s==null||l==null||c==null||d==null||u==null||h==null||g==null))return{viewMain:d,viewMainLeftTop:u,viewMainLeft:h,viewMainTop:g,viewColumnLeft:r,viewColumnRight:i,viewRowTop:s,viewRowBottom:l,viewLeftTop:c}}_bindViewportScroll(){const e=this._getViewports();if(!e)return;const{viewRowBottom:t,viewColumnRight:r,viewMainLeft:i,viewMainTop:s}=e;this.disposeWithMe(this._scrollManagerService.validViewportScrollInfo$.subscribe(l=>{if(!l)return;const{scrollX:c,scrollY:d,viewportScrollX:u,viewportScrollY:h}=l;t.isActive&&t.updateScrollVal({scrollY:d,viewportScrollY:h}),r.isActive&&r.updateScrollVal({scrollX:c,viewportScrollX:u}),i.isActive&&i.updateScrollVal({scrollY:d,viewportScrollY:h}),s.isActive&&s.updateScrollVal({scrollX:c,viewportScrollX:u})}))}_updateViewport(e=-1,t=-1,r=0,i=0,s=3){var x;const l=(x=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:x.skeleton;if(l==null)return;const{rowHeaderWidthAndMarginLeft:c,columnHeaderHeightAndMarginTop:d}=l,u=this._getViewports();if(!u)return;const{viewMain:h,viewMainLeftTop:g,viewMainLeft:S,viewMainTop:f,viewColumnLeft:p,viewColumnRight:v,viewRowTop:C,viewRowBottom:_,viewLeftTop:R}=u;v.resizeWhenFreezeChange({left:c,top:0,height:d+1,right:0}),_.resizeWhenFreezeChange({left:0,top:d,bottom:0,width:c+1}),R.resizeWhenFreezeChange({left:0,top:0,width:c+1,height:d});let w=!0,P=!0;g.enable(),(e===-1||e===0)&&(w=!1),(t===-1||t===0)&&(P=!1);const T=l.getNoMergeCellWithCoordByIndex(e-r,t-i,!1),M=l.getNoMergeCellWithCoordByIndex(e,t,!1);if(g.disable(),f.disable(),S.disable(),C.disable(),p.disable(),g.resetPadding(),f.resetPadding(),S.resetPadding(),C.resetPadding(),p.resetPadding(),w===!1&&P===!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}),p.resizeWhenFreezeChange({left:0,top:0,height:d+1,width:0});else if(w===!0&&P===!1){const A=M.startY-T.startY;h.resizeWhenFreezeChange({left:c,top:d+A,bottom:0,right:0}),h.setPadding({startY:T.startY,endY:M.startY,startX:0,endX:0}),s&2&&this._commandService.executeCommand(He.id,{sheetViewStartRow:0,offsetY:0}),f.resizeWhenFreezeChange({left:c,top:d,height:A,right:0}),f.updateScrollVal({viewportScrollY:T.startY,rawScrollX:h.scrollX,viewportScrollX:h.viewportScrollX}),C.resizeWhenFreezeChange({left:0,top:d,width:c+1,height:A}),C.updateScrollVal({viewportScrollY:T.startY}),_.resizeWhenFreezeChange({left:0,top:d+A,bottom:0,width:c+1}),f.enable(),C.enable()}else if(w===!1&&P===!0){const A=M.startX-T.startX;h.resizeWhenFreezeChange({left:c+A,top:d,bottom:0,right:0}),h.setPadding({startX:T.startX,endX:M.startX,startY:0,endY:0}),s&1&&this._commandService.executeCommand(He.id,{sheetViewStartColumn:0,offsetX:0}),S.resizeWhenFreezeChange({left:c,top:d,width:A,bottom:0,right:0}),S.updateScrollVal({viewportScrollX:T.startX,rawScrollY:h.scrollY,viewportScrollY:h.viewportScrollY}),p.resizeWhenFreezeChange({left:c,top:0,width:A,height:d+1}),p.updateScrollVal({viewportScrollX:T.startX}),v.resizeWhenFreezeChange({left:c+A,top:0,height:d+1,right:0}),S.enable(),p.enable()}else{const A=M.startX-T.startX,D=M.startY-T.startY;h.resizeWhenFreezeChange({left:c+A,top:d+D,bottom:0,right:0}),h.setPadding({startY:T.startY,endY:M.startY,startX:T.startX,endX:M.startX}),s&&this._commandService.executeCommand(He.id,{...s&1?{sheetViewStartColumn:0,offsetX:0}:null,...s&2?{sheetViewStartRow:0,offsetY:0}:null}),S.resizeWhenFreezeChange({left:c,top:d+D,width:A,bottom:0}),S.updateScrollVal({viewportScrollX:T.startX,rawScrollY:h.scrollY,viewportScrollY:h.viewportScrollY}),f.resizeWhenFreezeChange({left:c+A,top:d,height:D,right:0}),f.updateScrollVal({viewportScrollY:T.startY,rawScrollX:h.scrollX,viewportScrollX:h.viewportScrollX}),g.resizeWhenFreezeChange({left:c,top:d,width:A,height:D}),g.updateScrollVal({viewportScrollX:T.startX,viewportScrollY:T.startY}),C.resizeWhenFreezeChange({left:0,top:d,width:c+1,height:D}),C.updateScrollVal({viewportScrollY:T.startY}),_.resizeWhenFreezeChange({left:0,top:d+D,bottom:0,width:c+1}),p.resizeWhenFreezeChange({left:c,top:0,width:A,height:d+1}),p.updateScrollVal({viewportScrollX:T.startX}),v.resizeWhenFreezeChange({left:c+A,top:0,height:d+1,right:0}),g.enable(),f.enable(),S.enable(),C.enable(),p.enable()}}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(e=>{[m.SetWorksheetActiveOperation.id,m.InsertRangeMoveDownCommand.id,m.InsertRangeMoveRightCommand.id].includes((e==null?void 0:e.commandId)||"")&&this._refreshCurrent()})))}_refreshCurrent(){const t=this._context.unit.getActiveSheet();if(!t)return;const r=t.getConfig().freeze,{startRow:i=-1,startColumn:s=-1,ySplit:l=0,xSplit:c=0}=r;this._refreshFreeze(i,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(SS).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:[]},r=this._getFreeze();if(!r)return t;const i=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<r.startRow||l.startRow+1===r.startRow&&c===a.Direction.UP){const u={...r,startRow:Math.max(1,r.startRow+d),ySplit:Math.max(1,r.ySplit+d)};return i(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<r.startColumn||l.startColumn+1===r.startColumn&&c===a.Direction.LEFT){const u={...r,startColumn:Math.max(1,r.startColumn+d),xSplit:Math.max(1,r.xSplit+d)};return i(u)}}if(e.id===m.MoveColsCommand.id){const s=this._selectionManagerService.getCurrentSelections(),{fromRange:{startColumn:l},toRange:{startColumn:c}}=e.params,d=s==null?void 0:s.filter(C=>C.range.rangeType===a.RANGE_TYPE.COLUMN&&C.range.startColumn<=l&&l<=C.range.endColumn);if(!(d!=null&&d.length))return t;const u=d[0].range,h={...u,startColumn:c,endColumn:c+u.endColumn-u.startColumn};if(!r||r.startColumn<=0||u.startColumn>=r.startColumn&&h.startColumn>=r.startColumn||u.startColumn===h.startColumn||u.endColumn<r.startColumn&&h.startColumn<r.startColumn)return t;const g=u.endColumn-u.startColumn+1,S=Math.max(Math.min(r.startColumn,u.endColumn+1)-u.startColumn,0);let f,p;h.startColumn>=r.startColumn?(f=Math.max(r.startColumn-S,1),p=Math.max(r.xSplit-S,1)):(f=r.startColumn+g-S,p=r.xSplit+g-S);const v={...r,startColumn:f,xSplit:p};return i(v)}if(e.id===m.MoveRowsCommand.id){const s=this._selectionManagerService.getCurrentSelections(),{fromRange:{startRow:l},toRange:{startRow:c}}=e.params,d=s==null?void 0:s.filter(C=>C.range.rangeType===a.RANGE_TYPE.ROW&&C.range.startRow<=l&&l<=C.range.endRow);if(!(d!=null&&d.length))return t;const u=d[0].range,h={...u,startRow:c,endRow:c+u.endRow-u.startRow};if(!r||r.startRow<=0||u.startRow>=r.startRow&&h.startRow>=r.startRow||u.startRow===h.startRow||u.endRow<r.startRow&&h.startRow<r.startRow)return t;const g=u.endRow-u.startRow+1,S=Math.max(Math.min(r.startRow,u.endRow+1)-u.startRow,0);let f,p;h.startRow>=r.startRow?(f=Math.max(r.startRow-S,1),p=Math.max(r.ySplit-S,1)):(f=r.startRow+g-S,p=r.ySplit+g-S);const v={...r,startRow:f,ySplit:p};return i(v)}if(e.id===m.RemoveColCommand.id||e.id===m.RemoveRowCommand.id){const s=e.params,l=s.range;if(l.rangeType===a.RANGE_TYPE.COLUMN&&l.startColumn<r.startColumn){const c=Math.min(r.startColumn,l.endColumn+1)-l.startColumn,d={...r,startColumn:Math.max(1,r.startColumn-c),xSplit:Math.max(1,r.xSplit-c)};return i(d)}if(s.range.rangeType===a.RANGE_TYPE.ROW&&l.startRow<r.startRow){const c=Math.min(r.startRow,l.endRow+1)-l.startRow,d={...r,startRow:Math.max(1,r.startRow-c),ySplit:Math.max(1,r.ySplit-c)};return i(d)}}return t}}))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{switch(e.id){case m.SetFrozenMutation.id:case Ye.id:{const t=this._lastFreeze,r=this._context.unit,i=r.getActiveSheet(),s=e.params,{unitId:l,subUnitId:c}=s;if(!(l===r.getUnitId()&&c===(i==null?void 0:i.getSheetId())))return;const d=i.getConfig().freeze;if(this._lastFreeze=d,d==null)return;let u=0;const{startRow:h=-1,startColumn:g=-1,ySplit:S=0,xSplit:f=0}=d;(!t||t.startRow!==h||t.ySplit!==S)&&(u|=2),(!t||t.startColumn!==g||t.xSplit!==f)&&(u|=1),s.resetScroll===!1&&(u=0),this._refreshFreeze(h,g,S,f,u)}break;case m.SetWorksheetRowHeightMutation.id:{const t=this._getFreeze(),r=t&&e.params.ranges.some(i=>i.startRow<t.startRow);e.params&&r&&this._refreshCurrent()}break;case m.SetWorksheetColWidthMutation.id:{const t=this._getFreeze();e.params&&t&&e.params.ranges.some(r=>r.startColumn<t.startColumn)&&this._refreshCurrent()}break;case m.SetWorksheetRowAutoHeightMutation.id:{const t=e.params,r=this._getFreeze();if(r&&r.startRow>-1&&t.rowsAutoHeightInfo.some(i=>i.row<r.startRow)){const i=this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._refreshCurrent(),setTimeout(()=>{i.unsubscribe()})})}}break;case m.SetColHiddenMutation.id:case m.SetColVisibleMutation.id:{const t=e.params,r=this._getFreeze(),i=t.ranges;r&&r.startColumn>-1&&i.some(s=>s.startColumn<r.startColumn)&&this._refreshCurrent()}break;case m.SetRowHiddenMutation.id:case m.SetRowVisibleMutation.id:{const t=e.params,r=this._getFreeze(),i=t.ranges;r&&r.startRow>-1&&i.some(s=>s.startRow<r.startRow)&&this._refreshCurrent()}break;case ur.id:case hr.id:this._refreshCurrent()}}))}_zoomRefresh(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;this.disposeWithMe(t.onTransformChange$.subscribeEvent(r=>{[y.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale,y.TRANSFORM_CHANGE_OBSERVABLE_TYPE.all].includes(r.type)&&this._refreshCurrent()}))}_clearObserverEvent(){var t,r;this._getSheetObject()!=null&&((t=this._scenePointerMoveSub)==null||t.unsubscribe(),(r=this._scenePointerUpSub)==null||r.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null)}_clearFreeze(){var t,r,i,s,l,c;(t=this._rowFreezeHeaderRect)==null||t.dispose(),(r=this._rowFreezeMainRect)==null||r.dispose(),(i=this._columnFreezeHeaderRect)==null||i.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 i=(d=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:d.skeleton,s=i==null?void 0:i.getNoMergeCellWithCoordByIndex(e,t);if(i==null)return;if(s!=null&&(!isNaN(s.endX)||!isNaN(s.endY)))return s;const{rowHeaderWidthAndMarginLeft:l,columnHeaderHeightAndMarginTop:c}=i;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 De(this._context.unit,this._context)}_refreshFreeze(e,t,r,i,s){var c;const l={startRow:e,startColumn:t,ySplit:r,xSplit:i};this._clearFreeze(),this._createFreeze(0,l),this._createFreeze(1,l),this._updateViewport(e,t,r,i,s),(c=this._getSheetObject())==null||c.spreadsheet.makeForceDirty()}};exports.HeaderFreezeRenderController=dS([wt(1,a.Inject(exports.SheetSkeletonManagerService)),wt(2,a.ICommandService),wt(3,a.Inject(m.SheetsSelectionsService)),wt(4,a.Inject(exports.SheetScrollManagerService)),wt(5,a.Inject(a.ThemeService)),wt(6,a.Inject(m.SheetInterceptorService)),wt(7,a.Inject(a.Injector))],exports.HeaderFreezeRenderController);var fS=Object.getOwnPropertyDescriptor,pS=(n,o,e,t)=>{for(var r=t>1?void 0:t?fS(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},mi=(n,o)=>(e,t)=>o(e,t,n);const vS="__SpreadsheetHeaderMoveControllerBackground__",CS="__SpreadsheetHeaderMoveControllerShapeLine__",IS="rgba(0, 0, 0, 0.1)",_S="rgb(119, 119, 119)",bS=4,gi=a.createInterceptorKey("headerMovePermissionCheck");exports.HeaderMoveRenderController=class extends a.Disposable{constructor(e,t,r,i){super();E(this,"_startOffsetX",Number.NEGATIVE_INFINITY);E(this,"_startOffsetY",Number.NEGATIVE_INFINITY);E(this,"_moveHelperBackgroundShape");E(this,"_moveHelperLineShape");E(this,"_headerPointerDownSubs");E(this,"_headerPointerMoveSubs");E(this,"_headerPointerLeaveSubs");E(this,"_dragHeaderMoveSub");E(this,"_scenePointerUpSub");E(this,"_scrollTimer");E(this,"_changeFromColumn",-1);E(this,"_changeFromRow",-1);E(this,"_changeToColumn",-1);E(this,"_changeToRow",-1);E(this,"interceptor",new a.InterceptorManager({HEADER_MOVE_PERMISSION_CHECK:gi}));E(this,"_workbookSelections");this._context=e,this._sheetSkeletonManagerService=r,this._commandService=i,this._workbookSelections=t.getWorkbookSelections(this._context.unitId),this._init()}dispose(){var e,t,r,i,s,l,c,d;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(t=this._moveHelperLineShape)==null||t.dispose(),(r=this._headerPointerMoveSubs)==null||r.unsubscribe(),(i=this._headerPointerLeaveSubs)==null||i.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(ue.COLUMN),r=this._context.components.get(ue.ROW),i=this._context.scene,s=e===a.RANGE_TYPE.ROW?r:t,l=u=>{var _,R;const h=(_=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:_.skeleton;if(h==null)return;const g=(R=this._workbookSelections.getCurrentLastSelection())==null?void 0:R.range;if(!g||!this.interceptor.fetchThroughInterceptors(gi)(!1,g))return;const f=this._workbookSelections.getCurrentSelections(),{row:p,column:v}=Fe(u.offsetX,u.offsetY,i,h);if(!dr(f,e===a.RANGE_TYPE.ROW?p:v,e)){i.resetCursor();return}i.setCursor(y.CURSOR_TYPE.GRAB)},c=()=>{var u,h;(u=this._moveHelperBackgroundShape)==null||u.hide(),(h=this._moveHelperLineShape)==null||h.hide(),i.resetCursor()},d=(u,h)=>{var N,V;if(h.isStopPropagation)return;const g=(N=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:N.skeleton;if(g==null)return;const S=(V=this._workbookSelections.getCurrentLastSelection())==null?void 0:V.range;if(!S||!this.interceptor.fetchThroughInterceptors(gi)(!1,S))return;const{offsetX:p,offsetY:v}=u,C=i.getCoordRelativeToViewport(y.Vector2.FromArray([p,v])),{x:_,y:R}=C;this._startOffsetX=_,this._startOffsetY=R;const{row:w,column:P}=Fe(u.offsetX,u.offsetY,i,g);let T;e===a.RANGE_TYPE.ROW?(this._changeFromRow=w,T=y.ScrollTimerType.Y):(this._changeFromColumn=P,T=y.ScrollTimerType.X);const M=this._workbookSelections.getCurrentSelections(),x=dr(M,e===a.RANGE_TYPE.ROW?w:P,e);if(!x)return;const A=i.getScrollXYInfoByViewport(y.Vector2.FromArray([this._startOffsetX,this._startOffsetY]));this._newBackgroundAndLine(),i.setCursor(y.CURSOR_TYPE.GRABBING),i.disableObjectsEvent();let D=!1,k;const H=()=>{if(D)return;k=y.ScrollTimer.create(i,T),this._scrollTimer=k;const L=i.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);k.startScroll(_,R,L),D=!0};this._dragHeaderMoveSub=i.onPointerMove$.subscribeEvent(L=>{H();const{offsetX:U,offsetY:F}=L,{x:B,y:z}=i.getCoordRelativeToViewport(y.Vector2.FromArray([U,F]));this._rowColumnMoving(B,z,x,A,e),k.scrolling(B,z,()=>{this._rowColumnMoving(B,z,x,A,e)})}),this._scenePointerUpSub=i.onPointerUp$.subscribeEvent(()=>{var U,F,B;this._disposeBackgroundAndLine(),i.resetCursor(),i.enableObjectsEvent(),this._clearObserverEvent(),(U=this._scrollTimer)==null||U.dispose();const L=this._workbookSelections.getCurrentSelections();if(e===a.RANGE_TYPE.ROW){if(this._changeFromRow!==this._changeToRow&&this._changeToRow!==-1){const X=(F=((L==null?void 0:L.filter(K=>K.range.rangeType===a.RANGE_TYPE.ROW&&K.range.startRow<=this._changeFromRow&&this._changeFromRow<=K.range.endRow))||[])[0])==null?void 0:F.range;X&&this._commandService.executeCommand(m.MoveRowsCommand.id,{fromRange:X,toRange:{...X,startRow:this._changeToRow,endRow:this._changeToRow+X.endRow-X.startRow}})}this._changeToRow=this._changeFromRow=-1}else{if(this._changeFromColumn!==this._changeToColumn&&this._changeToColumn!==-1){const X=(B=((L==null?void 0:L.filter(K=>K.range.rangeType===a.RANGE_TYPE.COLUMN&&K.range.startColumn<=this._changeFromColumn&&this._changeFromColumn<=K.range.endColumn))||[])[0])==null?void 0:B.range;X&&this._commandService.executeCommand(m.MoveColsCommand.id,{fromRange:X,toRange:{...X,startColumn:this._changeToColumn,endColumn:this._changeToColumn+X.endColumn-X.startColumn}})}this._changeToColumn=this._changeFromColumn=-1}})};this._headerPointerMoveSubs=new O.Subscription,this._headerPointerMoveSubs.add(s.onPointerMove$.subscribeEvent(l)),this._headerPointerLeaveSubs=new O.Subscription,this._headerPointerLeaveSubs.add(s==null?void 0:s.onPointerLeave$.subscribeEvent(c)),this._headerPointerDownSubs=new O.Subscription,this._headerPointerDownSubs.add(s==null?void 0:s.onPointerDown$.subscribeEvent(d))}_rowColumnMoving(e,t,r,i,s){var z,X,K,re,oe,le,Z;const l=this._context.scene,c=(z=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:z.skeleton;if(c==null)return;const{rowHeaderWidth:d,columnHeaderHeight:u,rowTotalHeight:h,columnTotalWidth:g}=c,S=l.getViewportScrollXY(l.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:f,scaleY:p}=l.getAncestorScale(),v=c.getCellIndexByOffset(e,t,f,p,S),{row:C,column:_}=v,R=c.getNoMergeCellWithCoordByIndex(C,_),{startX:w,startY:P,endX:T,endY:M}=R,x=this._sheetSkeletonManagerService.attachRangeWithCoord(r.range);if(x==null)return;const A=Math.max(f,f),{startX:D,endX:k,startY:H,endY:N,startRow:V,startColumn:L,endRow:U,endColumn:F}=x;s===a.RANGE_TYPE.ROW?(X=this._moveHelperBackgroundShape)==null||X.transformByState({height:N-H,width:g+d,left:0,top:H+(t-this._startOffsetY)/A+S.y-i.y}):(K=this._moveHelperBackgroundShape)==null||K.transformByState({height:h+u,width:k-D,left:D+(e-this._startOffsetX)/A+S.x-i.x,top:0}),(re=this._moveHelperBackgroundShape)==null||re.show();const B=bS/A;if(s===a.RANGE_TYPE.ROW){let Y=0;if(C<=V)Y=P-B/2,this._changeToRow=C;else if(C>U)Y=M-B/2,this._changeToRow=C+1;else return;(oe=this._moveHelperLineShape)==null||oe.transformByState({height:B,width:g,left:d,top:Y})}else{let Y=0;if(_<=L)Y=w-B/2,this._changeToColumn=_;else if(_>F)Y=T-B/2,this._changeToColumn=_+1;else return;(le=this._moveHelperLineShape)==null||le.transformByState({height:h,width:B,left:Y,top:u})}(Z=this._moveHelperLineShape)==null||Z.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 y.Rect(vS,{fill:IS,evented:!1,zIndex:100}),this._moveHelperLineShape=new y.Rect(CS,{fill:_S,evented:!1,zIndex:100}),e.addObjects([this._moveHelperBackgroundShape,this._moveHelperLineShape],ht)}_disposeBackgroundAndLine(){var e,t;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(t=this._moveHelperLineShape)==null||t.dispose()}};exports.HeaderMoveRenderController=pS([mi(1,a.Inject(m.SheetsSelectionsService)),mi(2,a.Inject(exports.SheetSkeletonManagerService)),mi(3,a.ICommandService)],exports.HeaderMoveRenderController);var Ui=(n=>(n[n.VERTICAL=0]="VERTICAL",n[n.HORIZONTAL=1]="HORIZONTAL",n))(Ui||{});const RS="rgba(120, 120, 120, 0.01)",Si="rgb(68, 71, 70)",$n=12,wS=44,Li=4;class _a extends y.Shape{constructor(e,t){super(e,t);E(this,"_size",$n);E(this,"_color",Si);E(this,"_mode",0);this.setShapeProps(t)}get size(){return this._size}get mode(){return this._mode}get color(){return this._color}_draw(e){const t=this.getScene();if(!t)return;const{scaleX:r,scaleY:i}=t.getAncestorScale(),s=Math.max(r,i),l=$n/s,c=Li/s;let{width:d,height:u}=this,h=0,g=0;this.mode===0?(d=c,h=l-c):(u=c,g=l-c),y.Rect.drawWith(e,{width:this.width,height:this.height,left:0,top:0,fill:RS}),y.Rect.drawWith(e,{width:d,height:u,fill:Si,radius:c}),e.save(),e.transform(1,0,0,1,h,g),y.Rect.drawWith(e,{width:d,height:u,fill:Si,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:$n,height:this.size}):this.transformByState({width:this.size,height:$n}),this}}var ES=Object.getOwnPropertyDescriptor,TS=(n,o,e,t)=>{for(var r=t>1?void 0:t?ES(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},fi=(n,o)=>(e,t)=>o(e,t,n);const yS="__SpreadsheetHeaderResizeControllerShapeRow__",MS="__SpreadsheetHeaderResizeControllerShapeColumn__",ba="__SpreadsheetHeaderResizeControllerShapeHelper__",Ra="rgb(199, 199, 199)",PS=2,pi=a.createInterceptorKey("headerResizePermissionCheck");exports.HeaderResizeRenderController=class extends a.Disposable{constructor(e,t,r,i){super();E(this,"_currentRow",0);E(this,"_currentColumn",0);E(this,"_rowResizeRect");E(this,"_columnResizeRect");E(this,"_headerPointerSubs");E(this,"_scenePointerMoveSub");E(this,"_scenePointerUpSub");E(this,"_resizeHelperShape");E(this,"_startOffsetX",Number.POSITIVE_INFINITY);E(this,"_startOffsetY",Number.POSITIVE_INFINITY);E(this,"interceptor",new a.InterceptorManager({HEADER_RESIZE_PERMISSION_CHECK:pi}));this._context=e,this._sheetSkeletonManagerService=t,this._selectionManagerService=r,this._commandService=i,this._init()}dispose(){var e,t,r;(e=this._rowResizeRect)==null||e.dispose(),this._rowResizeRect=null,(t=this._columnResizeRect)==null||t.dispose(),this._columnResizeRect=null,(r=this._headerPointerSubs)==null||r.unsubscribe(),this._headerPointerSubs=null}_init(){const e=this._context.scene;this._rowResizeRect=new _a(yS,{visible:!1,mode:Ui.HORIZONTAL,zIndex:100}),this._columnResizeRect=new _a(MS,{visible:!1,mode:Ui.VERTICAL,zIndex:100}),e.addObjects([this._rowResizeRect,this._columnResizeRect],ht),this._initialHover(0),this._initialHover(1),this._initialHoverResize(0),this._initialHoverResize(1)}_initialHover(e=0){const t=this._context.components.get(ue.COLUMN),r=this._context.components.get(ue.ROW),i=this._context.scene,s=e===0?r:t,l=(d,u)=>{var h,g;(h=this._rowResizeRect)==null||h.hide(),(g=this._columnResizeRect)==null||g.hide()},c=(d,u)=>{var A;const h=(A=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:A.skeleton;if(h==null||this._rowResizeRect==null||this._columnResizeRect==null)return;const{rowHeaderWidth:g,columnHeaderHeight:S}=h,{startX:f,startY:p,endX:v,endY:C,row:_,column:R}=Fe(d.offsetX,d.offsetY,i,h),w=nr(d.offsetX,d.offsetY,i),{scaleX:P,scaleY:T}=i.getAncestorScale(),M=Math.max(P,T),x=$n/M;if(e===0){let D=p-x/2;if(w.y<=p+x/2&&w.y>=p)this._currentRow=_-1;else if(w.y>=C-x/2&&w.y<=C)this._currentRow=_,D=C-x/2;else{this._rowResizeRect.hide();return}if(this._currentRow===-1)return;if(!this.interceptor.fetchThroughInterceptors(pi)(null,{row:this._currentRow}))return!1;const H=Math.min(wS,g/3);this._rowResizeRect.transformByState({left:g/2-H/2,top:D}),this._rowResizeRect.setShapeProps({size:H}),this._rowResizeRect.show()}else{let D=f-x/2;if(w.x<=f+x/2&&w.x>=f)this._currentColumn=R-1;else if(w.x>=v-x/2&&w.x<=v)this._currentColumn=R,D=v-x/2;else{this._columnResizeRect.hide();return}if(this._currentColumn===-1)return;if(!this.interceptor.fetchThroughInterceptors(pi)(null,{col:this._currentColumn}))return!1;const H=S*.7;this._columnResizeRect.transformByState({left:D,top:S/2-H/2}),this._columnResizeRect.setShapeProps({size:H}),this._columnResizeRect.show()}};this._headerPointerSubs=new O.Subscription,this._headerPointerSubs.add(s==null?void 0:s.onPointerMove$.subscribeEvent(c)),this._headerPointerSubs.add(s==null?void 0:s.onPointerLeave$.subscribeEvent(l))}_initialHoverResize(e=0){const t=this._context.scene,r=e===0?this._rowResizeRect:this._columnResizeRect;r!=null&&(this.disposeWithMe(r.onPointerEnter$.subscribeEvent(()=>{r!=null&&(r.show(),t.setCursor(e===0?y.CURSOR_TYPE.ROW_RESIZE:y.CURSOR_TYPE.COLUMN_RESIZE))})),this.disposeWithMe(r.onPointerLeave$.subscribeEvent(()=>{r!=null&&(r.hide(),t.resetCursor())})),this.disposeWithMe(r.onPointerDown$.subscribeEvent(i=>{var F,B,z,X,K,re,oe;const s=(F=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:F.skeleton;if(s==null)return;const l=this._context.scene,c=l.getEngine(),d=(c==null?void 0:c.height)||0,u=(c==null?void 0:c.width)||0,h=l.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=(((z=(B=h==null?void 0:h.getScrollBar())==null?void 0:B.horizonScrollTrack)==null?void 0:z.height)||0)+10,S=(((K=(X=h==null?void 0:h.getScrollBar())==null?void 0:X.verticalScrollTrack)==null?void 0:K.width)||0)+10,f=nr(i.offsetX,i.offsetY,l),{scaleX:p,scaleY:v}=l.getAncestorScale();this._startOffsetX=f.x,this._startOffsetY=f.y;const C=s.getOffsetByColumn(this._currentColumn),_=s.getOffsetByRow(this._currentRow),R=s.getNoMergeCellWithCoordByIndex(this._currentRow,this._currentColumn);let w=!1,P=0,T=0;const{columnTotalWidth:M,rowHeaderWidth:x,rowTotalHeight:A,columnHeaderHeight:D}=s,k=u>M+x?u:M+x,H=d>A+D?d:A+D,N=Math.max(p,v),V=Li/N;e===0?this._resizeHelperShape=new y.Rect(ba,{width:k,height:V,fill:Ra,left:0,top:_-V/2}):this._resizeHelperShape=new y.Rect(ba,{width:V,height:H,fill:Ra,left:C-V/2,top:0});const L=((re=this._columnResizeRect)==null?void 0:re.left)||0,U=((oe=this._rowResizeRect)==null?void 0:oe.top)||0;l.addObject(this._resizeHelperShape,ht),l.disableObjectsEvent(),this._scenePointerMoveSub=l.onPointerMove$.subscribeEvent(le=>{var fe,be,Re,ot,it,It;const Z=l.getCoordRelativeToViewport(y.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),Y=l.getScrollXYInfoByViewport(Z,h),q=nr(le.offsetX,le.offsetY,l),{x:te,y:ce}=q,{scaleX:ne,scaleY:ie}=l.getAncestorScale(),ee=Math.max(ne,ie),me=Li/ee;P=te-this._startOffsetX-me/2,T=ce-this._startOffsetY-me/2,Math.abs(e===0?T:P)>=PS&&(w=!0),e===0?(T>d-g+Y.y-R.startY&&(T=d-g+Y.y-R.startY),T<-(R.endY-R.startY)+2&&(T=-(R.endY-R.startY)+2),w&&((fe=this._resizeHelperShape)==null||fe.transformByState({top:_+T}),(be=this._rowResizeRect)==null||be.transformByState({top:U+T+me/2}),(Re=this._rowResizeRect)==null||Re.show(),l.setCursor(y.CURSOR_TYPE.ROW_RESIZE))):(P>u-S+Y.x-R.startX&&(P=u-S+Y.x-R.startX),P<-(R.endX-R.startX)+2&&(P=-(R.endX-R.startX)+2),w&&((ot=this._resizeHelperShape)==null||ot.transformByState({left:C+P}),(it=this._columnResizeRect)==null||it.transformByState({left:L+P+me/2}),(It=this._columnResizeRect)==null||It.show(),l.setCursor(y.CURSOR_TYPE.COLUMN_RESIZE)))}),this._scenePointerUpSub=l.onPointerUp$.subscribeEvent(le=>{var Y,q,te;const Z=this._context.scene;this._clearObserverEvent(),(Y=this._resizeHelperShape)==null||Y.dispose(),this._resizeHelperShape=null,Z.enableObjectsEvent(),w&&(Z.resetCursor(),(q=this._rowResizeRect)==null||q.hide(),(te=this._columnResizeRect)==null||te.hide(),e===0?this._commandService.executeCommand(m.DeltaRowHeightCommand.id,{deltaY:T,anchorRow:this._currentRow}):this._commandService.executeCommand(m.DeltaColumnWidthCommand.id,{deltaX:P,anchorCol:this._currentColumn}))})})),this.disposeWithMe(r.onDblclick$.subscribeEvent(()=>{var h,g,S;this._context.scene.resetCursor();const s=(h=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:h.skeleton;if(!s)return;const l=0,c=0,d=s.worksheet.getRowCount()-1||0,u=s.worksheet.getColumnCount()-1||0;switch(e){case 1:{const f=this._selectionManagerService.getCurrentSelections(),p=[];for(let v=0;v<f.length;v++){const C=f[v];C.range.rangeType===a.RANGE_TYPE.COLUMN&&this._currentColumn<=C.range.endColumn&&this._currentColumn>=C.range.startColumn&&p.push({startColumn:C.range.startColumn,endColumn:C.range.endColumn,startRow:l,endRow:d})}p.length===0&&p.push({startColumn:this._currentColumn,endColumn:this._currentColumn,startRow:l,endRow:d}),this._commandService.executeCommand(Vn.id,{ranges:p}),(g=this._columnResizeRect)==null||g.hide();break}case 0:this._commandService.executeCommand(m.SetWorksheetRowIsAutoHeightCommand.id,{ranges:[{startRow:this._currentRow,endRow:this._currentRow,startColumn:c,endColumn:u}]}),(S=this._rowResizeRect)==null||S.hide();break}})))}_clearObserverEvent(){var e,t;(e=this._scenePointerMoveSub)==null||e.unsubscribe(),(t=this._scenePointerUpSub)==null||t.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null}};exports.HeaderResizeRenderController=TS([fi(1,a.Inject(exports.SheetSkeletonManagerService)),fi(2,a.Inject(m.SheetsSelectionsService)),fi(3,a.ICommandService)],exports.HeaderResizeRenderController);var xS=Object.getOwnPropertyDescriptor,OS=(n,o,e,t)=>{for(var r=t>1?void 0:t?xS(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Zn=(n,o)=>(e,t)=>o(e,t,n);const AS=60;exports.SheetRenderController=class extends a.RxDisposable{constructor(e,t,r,i,s,l){super();E(this,"_renderMetric$",new O.Subject);E(this,"renderMetric$",this._renderMetric$.asObservable());E(this,"_renderFrameTimeMetric",null);E(this,"_renderFrameTags",{});E(this,"_afterRenderMetric$",new O.Subject);this._context=e,this._configService=t,this._sheetSkeletonManagerService=r,this._sheetRenderService=i,this._commandService=s,this._telemetryService=l,this._addNewRender(),this._initRenderMetricSubscriber()}_addNewRender(){const{scene:e,engine:t,unit:r}=this._context;this._addComponent(r),this._initRerenderScheduler(),this._initCommandListener();const i=this._context.unit.getActiveSheet();if(!i)throw new Error("No active sheet found");const s=i.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(i=>i.startsWith(y.SHEET_EXTENSION_PREFIX)).length>0&&this._afterRenderMetric$.next({frameTimeMetric:this._renderFrameTimeMetric,tags:this._renderFrameTags})}),e.renderFrameTimeMetric$.subscribe(([r,i])=>{this._renderFrameTimeMetric||(this._renderFrameTimeMetric={}),this._renderFrameTimeMetric[r]||(this._renderFrameTimeMetric[r]=[]),this._renderFrameTimeMetric[r].push(Math.round(i*100)/100)}),e.renderFrameTags$.subscribe(([r,i])=>{this._renderFrameTags[r]=i});const t=[];this._afterRenderMetric$.pipe(O.withLatestFrom(e.endFrame$)).subscribe(([r,i])=>{t.push({FPS:i.FPS,elapsedTime:i.elapsedTime,frameTime:Math.round(i.frameTime*100)/100,...r.frameTimeMetric,...r.tags}),t.length>AS&&(this._captureRenderMetric(t),t.length=0)})}_captureRenderMetric(e){var g;const t=e;if(t.length===0)return;const r=S=>{let f=0;const v=Object.entries(S).filter(([_,R])=>Array.isArray(R)).map(([_])=>_).reduce((_,R)=>{const w=S[R].reduce((P,T)=>P+T,0);return _[R]=w,_},{});return Object.keys(S).filter(_=>_.startsWith(y.SHEET_EXTENSION_PREFIX)).forEach(_=>{f+=v[_]}),{...v,extensionTotal:f}},i=e.map(S=>({...S,...r(S)})),l=(S=>Object.entries(S[0]).filter(([v,C])=>!["elapsedTime"].includes(v)).filter(([v,C])=>typeof C=="number").map(([v])=>v).reduce((v,C)=>{const _=S.map(T=>T[C]),R=Math.max(..._),w=Math.min(..._),P=_.reduce((T,M)=>T+M,0)/_.length;return v[C]={max:Math.round(R*100)/100,min:Math.round(w*100)/100,avg:Math.round(P*100)/100},v},{}))(i),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:r}=this._context,i=e.getActiveSheet(),s=new y.Spreadsheet(ue.MAIN);this._addViewport(i);const l=new y.SpreadsheetRowHeader(ue.ROW),c=new y.SpreadsheetColumnHeader(ue.COLUMN),d=new y.Rect(ue.LEFT_TOP,{zIndex:2,left:-1,top:-1,fill:"rgb(248, 249, 250)",stroke:"rgb(217, 217, 217)",strokeWidth:1});this._context.mainComponent=s,r.set(ue.MAIN,s),r.set(ue.ROW,l),r.set(ue.COLUMN,c),r.set(ue.LEFT_TOP,d),t.addObjects([s],As),t.addObjects([l,c,d],ht),t.enableLayerCache(As,ht)}_initViewports(e,t,r){const l=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN,e,{left:t.width,top:r.height,bottom:0,right:0,isWheelPreventDefaultX:!0,allowCache:!0,bufferEdgeX:100,bufferEdgeY:100}),c=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:0,bufferEdgeY:0}),d=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:0,bufferEdgeY:100}),u=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:100,bufferEdgeY:0}),h=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP,e,{active:!1,isWheelPreventDefaultX:!0}),g=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM,e,{left:0,top:r.height,bottom:0,width:t.width+1,isWheelPreventDefaultX:!0}),S=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT,e,{active:!1,isWheelPreventDefaultX:!0}),f=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT,e,{left:t.width,top:0,height:r.height+1,right:0,isWheelPreventDefaultX:!0}),p=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP,e,{left:0,top:0,width:t.width,height:r.height,isWheelPreventDefaultX:!0});return{viewMain:l,viewLeftTop:p,viewMainLeftTop:c,viewMainLeft:d,viewMainTop:u,viewColumnLeft:S,viewRowTop:h,viewRowBottom:g,viewColumnRight:f}}_addViewport(e){const t=this._context.scene,{rowHeader:r,columnHeader:i}=e.getConfig(),{viewMain:s}=this._initViewports(t,r,i),l=this._configService.getConfig(Ee),c=l==null?void 0:l.scrollConfig;return new y.ScrollBar(s,c),t.attachControl(),s}_initRerenderScheduler(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(!e)return null;const{skeleton:t,sheetId:r}=e,i=this._context.unit,s=i==null?void 0:i.getSheetBySheetId(r);if(i==null||s==null)return;const{mainComponent:l,components:c}=this._context,d=l,u=c.get(ue.ROW),h=c.get(ue.COLUMN),g=c.get(ue.LEFT_TOP),{rowHeaderWidth:S,columnHeaderHeight:f}=t;d==null||d.updateSkeleton(t),u==null||u.updateSkeleton(t),h==null||h.updateSkeleton(t),g==null||g.transformByState({width:S,height:f})}))}_initCommandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{const{unit:t}=this._context,{id:r}=e;if(m.COMMAND_LISTENER_SKELETON_CHANGE.includes(r)||this._sheetRenderService.checkMutationShouldTriggerRerender(r)){const i=e.params,{unitId:s,subUnitId:l}=i,c=t.getActiveSheet();if(!c)return;const d=this._context.unitId,u=c.getSheetId();if(s!==d||l!==u)return;this._sheetSkeletonManagerService.makeDirty({sheetId:u,commandId:r},!0),this._sheetSkeletonManagerService.setCurrent({sheetId:u,commandId:r})}else m.COMMAND_LISTENER_VALUE_CHANGE.includes(r)&&this._sheetSkeletonManagerService.reCalculate();e.type===a.CommandType.MUTATION&&this._markUnitDirty(e)}))}_markUnitDirty(e){if(e.id.substring(0,3)==="doc")return;const{mainComponent:t,scene:r}=this._context;if(e.id===G.SetFormulaCalculationNotificationMutation.id&&e.params.stageInfo!=null||(t&&t.makeDirty(),r.makeDirty(),!e.params))return;const i=e.params,s=this._spreadsheetViewports(r);if(e.id===m.SetRangeValuesMutation.id&&i.cellValue){const l=this._cellValueToRange(i.cellValue),c=this._rangeToBounds([l]);this._markViewportDirty(s,c),t.setDirtyArea(c)}if(e.id===m.MoveRangeMutation.id&&i.from&&i.to){const l=i.fromRange||this._cellValueToRange(i.from.value),c=i.toRange||this._cellValueToRange(i.to.value),d=this._rangeToBounds([l,c]);this._markViewportDirty(s,d),t.setDirtyArea(d)}}_cellValueToRange(e){let t=0,r=0,i=0,s=0;for(const[h,g]of Object.entries(e)){for(const S in g)t>Number(S)&&(t=Number(S)),r<Number(S)&&(r=Number(S));i>Number(h)&&(i=Number(h)),s<Number(h)&&(s=Number(h))}return{startRow:i,endRow:s,startColumn:t,endColumn:r}}_rangeToBounds(e){const t=this._sheetSkeletonManagerService.getCurrentParam().skeleton,{rowHeightAccumulation:r,columnWidthAccumulation:i,rowHeaderWidth:s,columnHeaderHeight:l}=t,c=[];for(const d of e){const{startRow:u,endRow:h,startColumn:g,endColumn:S}=d,f=u===0?0:r[u-1]+l,p=r[h]+l,v=g===0?0:i[g-1]+s,C=i[S]+s;c.push({top:f,left:v,bottom:p,right:C,width:C-v,height:p-f})}return c}_markViewportDirty(e,t){const r=e.filter(i=>i.isActive&&i.cacheBound);for(const i of r)for(const s of t)a.Rectangle.hasIntersectionBetweenTwoRect(i.cacheBound,s)&&i.markDirty(!0)}_spreadsheetViewports(e){return e.getViewports().filter(t=>["viewMain","viewMainLeftTop","viewMainTop","viewMainLeft"].includes(t.viewportKey))}};exports.SheetRenderController=OS([Zn(1,a.Inject(a.IConfigService)),Zn(2,a.Inject(exports.SheetSkeletonManagerService)),Zn(3,a.Inject(exports.SheetsRenderService)),Zn(4,a.ICommandService),Zn(5,a.Optional(pd.ITelemetryService))],exports.SheetRenderController);const DS=({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"})]}),kS=({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"})]}),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.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"})]}),VS=({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"})]}),HS=({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"})]}),WS=({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"})}),US=({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"})]}),LS=({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"})]}),BS=({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"})]}),FS=({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"})}),jS=({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 wa(n){const{type:o=a.BorderStyleTypes.THIN,className:e}=n;switch(o){case a.BorderStyleTypes.DASH_DOT:return b.jsx(DS,{className:e});case a.BorderStyleTypes.DASH_DOT_DOT:return b.jsx(kS,{className:e});case a.BorderStyleTypes.DASHED:return b.jsx(NS,{className:e});case a.BorderStyleTypes.HAIR:return b.jsx(HS,{className:e});case a.BorderStyleTypes.MEDIUM:return b.jsx(WS,{className:e});case a.BorderStyleTypes.MEDIUM_DASH_DOT:return b.jsx(US,{className:e});case a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT:return b.jsx(LS,{className:e});case a.BorderStyleTypes.MEDIUM_DASHED:return b.jsx(BS,{className:e});case a.BorderStyleTypes.THICK:return b.jsx(FS,{className:e});case a.BorderStyleTypes.DOUBLE:return b.jsx(VS,{className:e});case a.BorderStyleTypes.THIN:default:return b.jsx(jS,{className:e})}}const zS=[{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 YS(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 lc(n){var g;const o=I.useDependency(I.ComponentManager),e=I.useDependency(m.BorderStyleManagerService),t=I.useDependency(m.SheetsSelectionsService),{isAllValuesSame:r,value:i}=t.getCellStylesProperty("bd"),s=r?XS(i):void 0,l=r?YS(i):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:Zl.map(S=>b.jsx("a",{className:j.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(j.Separator,{}),b.jsxs("div",{className:"univer-flex univer-items-center univer-gap-2",children:[b.jsx("div",{children:b.jsx(j.Dropdown,{overlay:b.jsx("div",{className:"univer-rounded-lg univer-p-4",children:b.jsx(j.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(Il,{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(j.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:zS.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(Zt,{className:"univer-absolute univer-left-3 univer-text-primary-600"}),b.jsx(wa,{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(wa,{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 Es="sheets.component.cell-popup";var ZS=Object.getOwnPropertyDescriptor,GS=(n,o,e,t)=>{for(var r=t>1?void 0:t?ZS(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Et=(n,o)=>(e,t)=>o(e,t,n);exports.SheetCanvasPopManagerService=class extends a.Disposable{constructor(e,t,r,i,s,l,c){super();E(this,"_popupMenuFeatureMap",new Map);E(this,"_isSelectionMoving",!1);this._globalPopupManagerService=e,this._renderManagerService=t,this._univerInstanceService=r,this._refRangeService=i,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,r,i){const s=this._popupMenuFeatureMap.get(i);if(s)return s(e,t,r,i)}dispose(){super.dispose(),this._popupMenuFeatureMap.clear()}_createHiddenRectObserver(e){const{row:t,column:r,worksheet:i,skeleton:s,currentRender:l}=e,c=()=>{var z,X;const g=i.getFreeze(),{startRow:S,startColumn:f,xSplit:p,ySplit:v}=g,C=S-v,_=f-p,{rowHeightAccumulation:R,columnWidthAccumulation:w,rowHeaderWidth:P,columnHeaderHeight:T}=s,M=P+(_===-1?0:w[_+p-1]-((z=w[_-1])!=null?z:0)),x=T+(C===-1?0:R[C+v-1]-((X=R[C])!=null?X:0)),A=l.engine.getCanvasElement(),D=A.getBoundingClientRect(),k=vi(A.style.width),H=D.width/k,N=l.scene.getAncestorScale().scaleX,V=M*H*N,L=x*H*N,U={left:-1/0,top:-1/0,right:D.left+V,bottom:D.top+L},F={left:D.left+V,top:-1/0,right:1/0,bottom:D.top+L},B={left:-1/0,top:D.top+L,right:D.left+V,bottom:1/0};return t<S&&r<f?[]:t<S?[U]:r<f?[U]:[U,F,B]},d=c(),u=new O.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(O.throttleTime(16)).subscribe(()=>{u.next(c())})),{rects$:u,disposable:h}}_createPositionObserver(e,t,r,i){const s=()=>{const{scene:u}=t,h=uh(e,u,r,i),g=t.engine.getCanvasElement(),S=g.getBoundingClientRect(),f=vi(g.style.width),p=S.width/f;return{left:h.left*p+S.left,right:h.right*p+S.left,top:h.top*p+S.top,bottom:h.bottom*p+S.top}},l=s(),c=new O.BehaviorSubject(l),d=new a.DisposableCollection;return d.add(this._commandService.onCommandExecuted(u=>{Ci(u.id)&&c.next(s())})),{position:l,position$:c,disposable:d}}attachPopupToObject(e,t){var R;const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),i=r.getActiveSheet();if(!i||this._isSelectionMoving&&!t.showOnSelectionMoving)return{dispose:()=>{},canDispose:()=>!0};const s=r.getUnitId(),l=i.getSheetId(),c=(R=this._renderManagerService.getRenderById(s))==null?void 0:R.with(exports.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:p,position$:v,disposable:C}=this._createPositionObserver(f,d,c,i),_=this._globalPopupManagerService.addPopup({...t,unitId:s,subUnitId:l,anchorRect:p,anchorRect$:v,canvasElement:d.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(_),v.complete(),C.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==_}}attachPopupByPosition(e,t,r){var C;let i=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=i.getActiveSheet();if(!s)return null;const l=i.getUnitId(),c=s.getSheetId();if(l!==r.unitId||r.subUnitId!==c)return null;if(this._isSelectionMoving&&!t.showOnSelectionMoving)return;const d=(C=this._renderManagerService.getRenderById(l))==null?void 0:C.with(exports.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:p}=this._createHiddenRectObserver({row:r.row,column:r.col,worksheet:s,skeleton:d,currentRender:u}),v=this._globalPopupManagerService.addPopup({...t,unitId:l,subUnitId:c,anchorRect:h,anchorRect$:g,hiddenRects$:f,canvasElement:u.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(v),g.complete(),S.dispose(),p.dispose(),i=null,s=null},canDispose:()=>this._globalPopupManagerService.activePopupId!==v}}attachPopupToAbsolutePosition(e,t,r,i){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(r&&c!==r||i&&i!==d)return null;const u=(f=this._renderManagerService.getRenderById(c))==null?void 0:f.with(exports.SheetSkeletonManagerService).ensureSkeleton(d),h=this._renderManagerService.getRenderById(c);if(!h||!u)return null;if(this._isSelectionMoving&&!t.showOnSelectionMoving)return;const g=new O.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,r,i,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(i&&u!==i||s&&h!==s)return null;const g=this._renderManagerService.getRenderById(u),S=g==null?void 0:g.with(exports.SheetSkeletonManagerService).ensureSkeleton(h),f=g==null?void 0:g.with(Ce);if(!g||!S||!f)return null;if(this._isSelectionMoving&&!r.showOnSelectionMoving)return;const p=l!=null?l:ta(e,t,g.scene,d);if(!p)return null;const{position:v,position$:C,disposable:_,updateRowCol:R}=this._createCellPositionObserver(e,t,g,S,p),{rects$:w,disposable:P}=this._createHiddenRectObserver({row:e,column:t,worksheet:d,skeleton:S,currentRender:g}),T=this._globalPopupManagerService.addPopup({...r,unitId:u,subUnitId:h,anchorRect:v,anchorRect$:C,canvasElement:g.engine.getCanvasElement(),hiddenRects$:w}),M=new a.DisposableCollection;M.add(_),M.add(a.toDisposable(()=>{this._globalPopupManagerService.removePopup(T),C.complete()})),M.add(P);const x={startRow:e,endRow:e,startColumn:t,endColumn:t};return M.add(this._refRangeService.watchRange(u,h,x,(A,D)=>{D?R(D.startRow,D.startColumn):M.dispose()})),{dispose(){M.dispose(),d=null,c=null},canDispose:()=>this._globalPopupManagerService.activePopupId!==T}}attachRangePopup(e,t,r,i,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(r&&u!==r||i&&h!==i)return null;const g=this._renderManagerService.getRenderById(u),S=g==null?void 0:g.with(exports.SheetSkeletonManagerService).getOrCreateSkeleton({sheetId:h}),f=g==null?void 0:g.with(Ce);if(!g||!S||!f)return null;if(f.selectionMoving&&!l)return;const p=s!=null?s:ta(e.startRow,e.startColumn,g.scene,d);if(!p)return null;const{position:v,position$:C,disposable:_,updateRange:R,topLeftPos$:w,rightBottomPos$:P}=this._createRangePositionObserver(e,g,S,p),{rects$:T,disposable:M}=this._createHiddenRectObserver({row:e.startRow,column:e.startColumn,worksheet:d,skeleton:S,currentRender:g}),x=this._globalPopupManagerService.addPopup({...t,unitId:u,subUnitId:h,anchorRect:v,anchorRect$:C,canvasElement:g.engine.getCanvasElement(),hiddenRects$:T}),A=new a.DisposableCollection;A.add(_),A.add(a.toDisposable(()=>{this._globalPopupManagerService.removePopup(x),w.complete(),P.complete()})),A.add(M);const D={...e};return A.add(this._refRangeService.watchRange(u,h,D,(k,H)=>{H?R(H):A.dispose()})),{dispose(){A.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==x}}_createCellPositionObserver(e,t,r,i,s){let l=e,c=t;const d=this._calcCellPositionByCell(l,c,r,i,s),u=new O.BehaviorSubject(d),h=()=>u.next(this._calcCellPositionByCell(l,c,r,i,s)),g=new a.DisposableCollection;return g.add(r.engine.clientRect$.subscribe(()=>h())),g.add(a.fromEventSubject(r.engine.onTransformChange$).pipe(O.throttleTime(16)).subscribe(()=>h())),g.add(this._commandService.onCommandExecuted(f=>{if(f.id===m.SetWorksheetRowAutoHeightMutation.id&&f.params.rowsAutoHeightInfo.findIndex(v=>v.row===l)>-1){h();return}Ci(f.id)&&h()})),{position$:u,disposable:g,position:d,updateRowCol:(f,p)=>{l=f,c=p,h()}}}_calcCellPositionByCell(e,t,r,i,s){const{scene:l,engine:c}=r;if(i._disposed||l._disposed)return{left:0,right:0,top:0,bottom:0};const d=i.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 p=f.getBoundingClientRect(),v=vi(f.style.width),{top:C,left:_,width:R}=p,w=R/v;return{left:(u.startX-S.x)*w*h+_,right:(u.endX-S.x)*w*h+_,top:(u.startY-S.y)*w*g+C,bottom:(u.endY-S.y)*w*g+C}}_createRangePositionObserver(e,t,r,i){let{startRow:s,startColumn:l,endRow:c,endColumn:d}=e;const u=this._calcCellPositionByCell(s,l,t,r,i),h=new O.BehaviorSubject(u),g=this._calcCellPositionByCell(c,d,t,r,i),S=new O.BehaviorSubject(g),f=()=>{const R=this._calcCellPositionByCell(s,l,t,r,i),w=this._calcCellPositionByCell(c,d,t,r,i);h.next(R),S.next(w)},p=new a.DisposableCollection;p.add(t.engine.clientRect$.subscribe(()=>f())),p.add(this._commandService.onCommandExecuted(R=>{if(R.id===m.SetWorksheetRowAutoHeightMutation.id&&R.params.rowsAutoHeightInfo.findIndex(P=>P.row===s)>-1){f();return}Ci(R.id)&&f()}));const v=R=>{s=R.startRow,l=R.startColumn,c=R.endRow,d=R.endColumn,f()},C=h.pipe(O.map(R=>{const w=this._calcCellPositionByCell(c,d,t,r,i);return{top:R.top,left:R.left,right:w.right,bottom:w.bottom}})),_={top:u.top,left:u.left,right:g.right,bottom:g.bottom};return{position$:C,position:_,updateRange:v,topLeftPos$:h,rightBottomPos$:S,disposable:p}}};exports.SheetCanvasPopManagerService=GS([Et(0,a.Inject(I.ICanvasPopupService)),Et(1,y.IRenderManagerService),Et(2,a.IUniverInstanceService),Et(3,a.Inject(m.RefRangeService)),Et(4,a.ICommandService),Et(5,m.IRefSelectionsService),Et(6,a.Inject(m.SheetsSelectionsService))],exports.SheetCanvasPopManagerService);function vi(n){return Number.parseInt(n.replace("px",""))}const KS=new Set([rt.id,Ye.id,m.SetSelectionsOperation.id]);function Ci(n){return KS.has(n)||m.COMMAND_LISTENER_SKELETON_CHANGE.includes(n)}var qS=Object.getOwnPropertyDescriptor,QS=(n,o,e,t)=>{for(var r=t>1?void 0:t?qS(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},JS=(n,o)=>(e,t)=>o(e,t,n);exports.CellPopupManagerService=class extends a.Disposable{constructor(e){super();E(this,"_cellPopupMap",new Map);E(this,"_change$",new O.Subject);E(this,"change$",this._change$.asObservable());this._sheetCanvasPopManagerService=e}_ensureCellPopupMap(e,t){let r=this._cellPopupMap.get(e);r||(r=new Map,this._cellPopupMap.set(e,r));let i=r.get(t);return i||(i=new a.ObjectMatrix,r.set(t,i)),i}showPopup(e,t){var g,S;const{direction:r="horizontal"}=t,{unitId:i,subUnitId:s,row:l,col:c}=e,d=this._ensureCellPopupMap(i,s),u=(g=d.getValue(l,c))==null?void 0:g[r];t.id=(S=t.id)!=null?S:a.generateRandomId();const h=()=>{var C;const f=d.getValue(l,c);if(!f)return;const p=f[r];if(!p)return;const v=p==null?void 0:p.popups.findIndex(_=>_.id===t.id&&_.componentKey===t.componentKey);p==null||p.popups.splice(v,1),p.popups.length===0&&((C=p.disposable)==null||C.dispose(),f[r]=void 0),this._change$.next({...e,direction:r})};if(u)u.popups.push(t),u.popups.sort((f,p)=>f.priority-p.priority);else{const f=this._sheetCanvasPopManagerService.attachPopupToCell(l,c,{...t,direction:r,componentKey:Es,extraProps:{...e,direction:r},noPushMinimumGap:!0,autoRelayout:!1,zIndex:90},i,s);d.setValue(l,c,{...d.getValue(l,c),[r]:{disposable:f,popups:[t]}})}return this._change$.next({...e,direction:r}),a.toDisposable(h)}getPopups(e,t,r,i,s){var c,d;return((d=(c=this._ensureCellPopupMap(e,t).getValue(r,i))==null?void 0:c[s])==null?void 0:d.popups)||[]}hidePopup(e,t,r,i){var c,d;const s=this._ensureCellPopupMap(e,t),l=s.getValue(r,i);l&&(l.horizontal&&((c=l.horizontal.disposable)==null||c.dispose(),l.horizontal=void 0,this._change$.next({unitId:e,subUnitId:t,row:r,col:i,direction:"horizontal"})),l.vertical&&((d=l.vertical.disposable)==null||d.dispose(),l.vertical=void 0,this._change$.next({unitId:e,subUnitId:t,row:r,col:i,direction:"vertical"})),!l.horizontal&&!l.vertical&&s.realDeleteValue(r,i))}};exports.CellPopupManagerService=QS([JS(0,a.Inject(exports.SheetCanvasPopManagerService))],exports.CellPopupManagerService);const cc=n=>{const{popup:o}=n,e=o.extraProps,{row:t,col:r,direction:i,unitId:s,subUnitId:l}=e,c=I.useDependency(exports.CellPopupManagerService);I.useObservable(W.useMemo(()=>c.change$.pipe(O.filter(h=>h.row===t&&h.col===r&&h.direction===i)),[c,t,r,i]));const d=c.getPopups(s,l,t,r,i),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})})},Ea=n=>{const{inputId:o,state:e=!1,type:t="range",confirm:r,cancel:i,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),p=I.useDependency(G.IDefinedNamesService),v=I.useDependency(G.IFunctionService),C=I.useDependency(G.LexerTreeBuilder),_=I.useDependency(I.ComponentManager),R=W.useMemo(()=>_.get(Zi),[]),w=W.useMemo(()=>_.get(Mo),[]);if(S==null)return;const P=W.useMemo(()=>S.getUnitId(),[]),T=W.useMemo(()=>S.getActiveSheet().getSheetId(),[]),[M,x]=W.useState(s),[A,D]=W.useState(l),[k,H]=W.useState(c),[N,V]=W.useState(d),[L,U]=W.useState(""),[F,B]=W.useState(t),[z,X]=W.useState(!0),K=[{label:f.t("definedName.scopeWorkbook"),value:m.SCOPE_WORKBOOK_VALUE_DEFINED_NAME}],re=ne=>!G.isReferenceStrings(ne);W.useEffect(()=>{X(!0),x(s),H(c),V(d);let ne=l;l.substring(0,1)===G.operatorToken.EQUALS?B("formula"):re(l)?(B("formula"),ne=G.operatorToken.EQUALS+l):B("range"),D(ne),U("")},[e]),S.getSheetOrders().forEach(ne=>{const ie=S.getSheetBySheetId(ne);K.push({label:(ie==null?void 0:ie.getName())||"",value:ne})});const oe=ne=>{D(ne)},le=ne=>{D(ne||"")},Z=()=>{if(M.length===0){U(f.t("definedName.nameEmpty"));return}if(p.getValueByName(P,M)!=null&&(h==null||h.length===0)){U(f.t("definedName.nameDuplicate"));return}if(!a.Tools.isValidParameter(M)||G.isReferenceStringWithEffectiveColumn(M)||!a.Tools.isStartValidPosition(M)&&!y.hasCJKText(M.substring(0,1))){U(f.t("definedName.nameInvalid"));return}if(S.getSheetOrders().map(ee=>{var me;return((me=S.getSheetBySheetId(ee))==null?void 0:me.getName())||""}).includes(M)){U(f.t("definedName.nameSheetConflict"));return}if(A.length===0){U(f.t("definedName.formulaOrRefStringEmpty"));return}if(!z){U(f.t("definedName.formulaOrRefStringInvalid"));return}if(v.hasExecutor(M.toUpperCase())){U(f.t("definedName.nameConflict"));return}const ie=S.getActiveSheet().getName();r&&r({id:h||"",name:M,formulaOrRefString:C.convertRefersToAbsolute(A,a.AbsoluteRefType.ALL,a.AbsoluteRefType.ALL,ie),comment:k,localSheetId:N})},Y=ne=>{const ie=ne;ie==="formula"?l[0]===G.operatorToken.EQUALS?D(l):D(`${G.operatorToken.EQUALS}`):l[0]===G.operatorToken.EQUALS?D(""):D(l),B(ie)},q=W.useRef(null),[te,ce]=W.useState(!1);return I.useSidebarClick(ne=>{var ee;((ee=q.current)==null?void 0:ee.isClickOutSide(ne))&&ce(!1)}),b.jsxs("div",{className:j.clsx("univer-grid univer-space-y-2 univer-pb-1",j.borderBottomClassName,{"univer-hidden":!e}),children:[b.jsx("div",{children:b.jsx(j.Input,{className:"univer-w-full",placeholder:f.t("definedName.inputNamePlaceholder"),value:M,allowClear:!0,onChange:x})}),b.jsx("div",{children:b.jsxs(j.RadioGroup,{value:F,onChange:Y,children:[b.jsx(j.Radio,{value:"range",children:f.t("definedName.ratioRange")}),b.jsx(j.Radio,{value:"formula",children:f.t("definedName.ratioFormula")})]})}),F==="range"?R&&b.jsx(R,{unitId:P,subUnitId:T,initialValue:A,onChange:(ne,ie)=>oe(ie),supportAcrossSheet:!0}):w&&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(w,{ref:q,className:j.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",j.borderClassName),initValue:A,unitId:P,subUnitId:T,isFocus:te,isSupportAcrossSheet:!0,onChange:(ne="")=>{le(ne||"")},onVerify:ne=>{X(ne)},onFocus:()=>ce(!0)})})}),b.jsx("div",{children:b.jsx(j.Select,{className:"univer-w-full",value:N,options:K,onChange:V})}),b.jsx("div",{children:b.jsx(j.Input,{className:"univer-w-full",placeholder:f.t("definedName.inputCommentPlaceholder"),value:k,onChange:H,allowClear:!0})}),b.jsxs("div",{className:j.clsx("univer-items-center univer-gap-1 univer-text-sm univer-text-red-500",{"univer-hidden":L.length===0,"univer-flex":L.length!==0}),children:[b.jsx("span",{children:L}),b.jsx(hs,{})]}),b.jsxs("div",{className:"univer-flex univer-gap-2",children:[b.jsx(j.Button,{onClick:()=>{i==null||i()},children:f.t("definedName.cancel")}),b.jsx(j.Button,{variant:"primary",onClick:Z,children:f.t("definedName.confirm")})]})]})},dc=()=>{const n=I.useDependency(a.ICommandService),e=I.useDependency(a.IUniverInstanceService).getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET),t=I.useDependency(a.LocaleService),r=I.useDependency(G.IDefinedNamesService),i=I.useDependency(m.SheetsSelectionsService);if(e==null)return;const s=e.getUnitId(),l=()=>{const k=r.getDefinedNameMap(s);return k?Array.from(Object.values(k)):[]},[c,d]=W.useState(!1),[u,h]=W.useState(l()),[g,S]=W.useState(null),[f,p]=W.useState();W.useEffect(()=>{const k=r.update$.subscribe(()=>{h(l())});return()=>{k.unsubscribe()}},[]);const v=k=>{const{name:H,formulaOrRefString:N,comment:V,localSheetId:L,hidden:U}=k;let F=k.id;if(F==null||F.length===0)F=a.generateRandomId(10),n.executeCommand(m.InsertDefinedNameCommand.id,{id:F,unitId:s,name:H,formulaOrRefString:N,comment:V,localSheetId:L,hidden:U});else{const B={id:F,unitId:s,name:H,formulaOrRefString:N,comment:V,localSheetId:L,hidden:U};n.executeCommand(m.SetDefinedNameCommand.id,B)}d(!1),S(null)},C=k=>{p(k)};function _(){p(null)}function R(k){const H=r.getValueById(s,k);n.executeCommand(m.RemoveDefinedNameCommand.id,{...H,unitId:s}),p(null)}const w=async k=>{const{formulaOrRefString:H,id:N}=k,V=r.getWorksheetByRef(s,H);if(!V)return;V.isSheetHidden()&&await n.executeCommand(m.SetWorksheetShowCommand.id,{unitId:s,subUnitId:V.getSheetId()}),r.focusRange(s,N)},P=()=>{const k=u.length+1,H=t.t("definedName.defaultName")+k;if(r.getValueByName(s,H)==null)return H;let N=k+1;for(;;){const V=t.t("definedName.defaultName")+N;if(r.getValueByName(s,V)==null)return V;N++}},T=()=>{var V;const k=(V=e.getActiveSheet())==null?void 0:V.getName();if(!k)return"";const H=i.getCurrentSelections();return H==null?"":H.map(L=>G.serializeRangeWithSheet(k,L.range)).join(",")},M=()=>{d(!1),S(null)},x=()=>{d(!0),S(null)},A=k=>{d(!1),S(k)},D=k=>{const H=e.getSheetBySheetId(k);return H==null?"":H.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:j.clsx("univer-w-full univer-overflow-hidden univer-overflow-y-auto",j.scrollbarClassName),children:[b.jsxs("div",{className:"univer-mb-4",children:[b.jsxs(j.Button,{className:j.clsx("univer-w-full",{"univer-hidden":c}),onClick:x,children:[b.jsx(ms,{}),b.jsx("span",{className:"univer-ml-1",children:t.t("definedName.addButton")})]}),c&&b.jsx(Ea,{confirm:v,cancel:M,state:c,inputId:"insertDefinedName",name:P(),formulaOrRefString:T()})]},"insertDefinedName"),u.map((k,H)=>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:j.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":k.id===g}),onClick:()=>{w(k)},children:[b.jsxs("div",{title:k.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:[k.name,b.jsx("span",{className:"univer-text-xxs univer-ml-1 univer-text-gray-400",children:k.localSheetId===m.SCOPE_WORKBOOK_VALUE_DEFINED_NAME||k.localSheetId==null?"":D(k.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:k.formulaOrRefString,children:k.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(j.Tooltip,{title:t.t("definedName.updateButton"),placement:"top",children:b.jsx("a",{className:"univer-rounded univer-p-1 hover:univer-bg-gray-100",onClick:N=>{N.stopPropagation(),A(k.id)},children:b.jsx(fl,{})})}),b.jsx(j.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:N=>{N.stopPropagation(),C(k.id)},children:b.jsx(Lo,{})})})]})]}),b.jsx(j.Confirm,{visible:f===k.id,onClose:_,onConfirm:()=>{R(k.id)},children:t.t("definedName.deleteConfirmText")}),k.id===g&&b.jsx(Ea,{confirm:v,cancel:M,state:k.id===g,id:k.id,inputId:k.id+H,name:k.name,formulaOrRefString:k.formulaOrRefString,comment:k.comment,localSheetId:k.localSheetId})]},H))]})})},uc={id:m.SetRowHiddenCommand.id,preconditions:n=>se(n),binding:I.KeyCode.Digit9|I.MetaKeys.CTRL_COMMAND},hc={id:m.SetColHiddenCommand.id,preconditions:n=>se(n),binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT},mc={id:Me.id,description:"shortcut.sheet.select-below-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN,priority:100,preconditions:se,staticParameters:{direction:a.Direction.DOWN}},gc={id:Me.id,description:"shortcut.sheet.select-up-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP,priority:100,preconditions:se,staticParameters:{direction:a.Direction.UP}},Sc={id:Me.id,description:"shortcut.sheet.select-left-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT,priority:100,preconditions:za,staticParameters:{direction:a.Direction.LEFT}},fc={id:Me.id,description:"shortcut.sheet.select-right-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT,priority:100,preconditions:za,staticParameters:{direction:a.Direction.RIGHT}},pc={id:Xe.id,description:"shortcut.sheet.select-next-cell",group:"3_sheet-view",binding:I.KeyCode.TAB,priority:100,preconditions:se,staticParameters:{direction:a.Direction.RIGHT,keycode:I.KeyCode.TAB}},vc={id:Xe.id,description:"shortcut.sheet.select-previous-cell",group:"3_sheet-view",binding:I.KeyCode.TAB|I.MetaKeys.SHIFT,priority:100,preconditions:se,staticParameters:{direction:a.Direction.LEFT,keycode:I.KeyCode.TAB}},Cc={id:Xe.id,description:"shortcut.sheet.select-below-cell",group:"3_sheet-view",binding:I.KeyCode.ENTER,priority:100,preconditions:se,staticParameters:{direction:a.Direction.DOWN,keycode:I.KeyCode.ENTER}},Ic={id:Xe.id,description:"shortcut.sheet.select-up-cell",group:"3_sheet-view",binding:I.KeyCode.ENTER|I.MetaKeys.SHIFT,priority:100,preconditions:se,staticParameters:{direction:a.Direction.UP,keycode:I.KeyCode.ENTER}},_c={id:Me.id,description:"shortcut.sheet.select-below-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN|I.MetaKeys.CTRL_COMMAND,preconditions:se,staticParameters:{direction:a.Direction.DOWN,jumpOver:ze.moveGap}},bc={id:Me.id,description:"shortcut.sheet.select-up-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP|I.MetaKeys.CTRL_COMMAND,preconditions:se,staticParameters:{direction:a.Direction.UP,jumpOver:ze.moveGap}},Rc={id:Me.id,description:"shortcut.sheet.select-left-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT|I.MetaKeys.CTRL_COMMAND,preconditions:se,staticParameters:{direction:a.Direction.LEFT,jumpOver:ze.moveGap}},wc={id:Me.id,description:"shortcut.sheet.select-right-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT|I.MetaKeys.CTRL_COMMAND,preconditions:se,staticParameters:{direction:a.Direction.RIGHT,jumpOver:ze.moveGap}},Ec={id:Oe.id,description:"shortcut.sheet.expand-selection-down",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN|I.MetaKeys.SHIFT,preconditions:se,staticParameters:{direction:a.Direction.DOWN}},Tc={id:Oe.id,description:"shortcut.sheet.expand-selection-up",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP|I.MetaKeys.SHIFT,preconditions:se,staticParameters:{direction:a.Direction.UP}},yc={id:Oe.id,description:"shortcut.sheet.expand-selection-left",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT|I.MetaKeys.SHIFT,preconditions:se,staticParameters:{direction:a.Direction.LEFT}},Mc={id:Oe.id,description:"shortcut.sheet.expand-selection-right",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT|I.MetaKeys.SHIFT,preconditions:se,staticParameters:{direction:a.Direction.RIGHT}},Pc={id:Oe.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:se,staticParameters:{direction:a.Direction.DOWN,jumpOver:ze.moveGap}},xc={id:Oe.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:se,staticParameters:{direction:a.Direction.UP,jumpOver:ze.moveGap}},Oc={id:Oe.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:se,staticParameters:{direction:a.Direction.LEFT,jumpOver:ze.moveGap}},Ac={id:Oe.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:se,staticParameters:{direction:a.Direction.RIGHT,jumpOver:ze.moveGap}},Dc={id:Mr.id,description:"shortcut.sheet.select-all",group:"3_sheet-view",binding:I.KeyCode.A|I.MetaKeys.CTRL_COMMAND,preconditions:se,staticParameters:{expandToGapFirst:!0,loop:!0}},kc={id:Ft.id,description:"shortcut.sheet.set-bold",group:"4_sheet-edit",preconditions:n=>se(n),binding:I.KeyCode.B|I.MetaKeys.CTRL_COMMAND},Nc={id:jt.id,description:"shortcut.sheet.set-italic",group:"4_sheet-edit",preconditions:n=>se(n),binding:I.KeyCode.I|I.MetaKeys.CTRL_COMMAND},Vc={id:zt.id,description:"shortcut.sheet.set-underline",group:"4_sheet-edit",preconditions:n=>se(n),binding:I.KeyCode.U|I.MetaKeys.CTRL_COMMAND},Hc={id:Xt.id,description:"shortcut.sheet.set-strike-through",group:"4_sheet-edit",preconditions:n=>se(n),binding:I.KeyCode.X|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND},Wc={id:m.ClearSelectionContentCommand.id,preconditions:n=>se(n),binding:I.KeyCode.DELETE,mac:I.KeyCode.BACKSPACE},Uc={id:m.ClearSelectionContentCommand.id,preconditions:n=>se(n),mac:I.KeyCode.DELETE},Lc={id:m.ClearSelectionContentCommand.id,preconditions:n=>se(n),binding:I.MetaKeys.SHIFT+I.KeyCode.BACKSPACE},Bc={id:Oo.id,preconditions:n=>se(n),binding:I.MetaKeys.SHIFT+I.KeyCode.DELETE},Fc={id:Hn.id,description:"shortcut.sheet.zoom-in",binding:I.KeyCode.EQUAL|I.MetaKeys.CTRL_COMMAND,group:"3_sheet-view",preconditions:se,priority:1,staticParameters:{delta:.2}},jc={id:a.NilCommand.id,binding:I.KeyCode.EQUAL|I.MetaKeys.CTRL_COMMAND},zc={id:Hn.id,description:"shortcut.sheet.zoom-out",binding:I.KeyCode.MINUS|I.MetaKeys.CTRL_COMMAND,group:"3_sheet-view",preconditions:se,priority:1,staticParameters:{delta:-.2}},Xc={id:a.NilCommand.id,binding:I.KeyCode.MINUS|I.MetaKeys.CTRL_COMMAND},Yc={id:Hn.id,description:"shortcut.sheet.reset-zoom",binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND,preconditions:se,group:"3_sheet-view",priority:1,staticParameters:{reset:!0}},Zc={id:a.NilCommand.id,binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND};var $S=Object.getOwnPropertyDescriptor,ef=(n,o,e,t)=>{for(var r=t>1?void 0:t?$S(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},st=(n,o)=>(e,t)=>o(e,t,n);exports.SheetUIController=class extends a.Disposable{constructor(o,e,t,r,i,s,l,c){super(),this._injector=o,this._componentManager=e,this._layoutService=t,this._commandService=r,this._shortcutService=i,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(Ze,Jl)),this.disposeWithMe(o.register(_s,lc)),this.disposeWithMe(o.register(lr,dc)),this.disposeWithMe(o.register(Es,cc)),this.disposeWithMe(o.register("HideGridlinesDoubleIcon",fs))}_initCommands(){[bs,Ct,ws,Rs,Hn,Oe,Me,Xe,Dr,Rr,In,_n,Sr,fr,He,as,Mr,Ho,m.SetBoldCommand,Wt,Se,Ar,Ft,jt,zt,Xt,os,is,pr,Do,ko,vn,Cn,No,m.SetItalicCommand,m.SetStrikeThroughCommand,m.SetFontFamilyCommand,m.SetFontSizeCommand,wr,Vo,Nn,Er,rt,Rn,nt,Tr,yr,Wo,m.SetUnderlineCommand,Wn,Ye,Pr,br,Vt,Nt,kn,Dn,Uo,dt,Sn,Be,ls,Cr,Mt,Pt,Ir,_r,Or,xt,Ot,xr,Vn,ur,hr].forEach(o=>{this.disposeWithMe(this._commandService.registerCommand(o))})}_initMenus(){this._menuManagerService.mergeMenu(sc)}_initShortcuts(){[mc,gc,Sc,fc,pc,vc,Cc,Ic,_c,bc,Rc,wc,Ec,Tc,yc,Mc,Pc,xc,Oc,Ac,Dc,Fc,zc,Yc,Zc,jc,Xc,kc,Nc,Vc,Hc,Wc,Uc,Lc,Bc,...xl(),Al,Ol,Dl,Vl,Hl,Wl,Ll,kl,Nl,Ul,uc,hc].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(yl,e))),this.disposeWithMe(o.registerComponent(I.BuiltInUIPart.FOOTER,()=>I.connectInjector(Tl,e))),this.disposeWithMe(o.registerComponent(I.BuiltInUIPart.CONTENT,()=>I.connectInjector(Cs,e)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(a.UniverInstanceType.UNIVER_SHEET,o=>{const e=this._injector.get(y.IRenderManagerService),t=this._injector.get(a.IUniverInstanceService),r=y.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_DOC,t,e),i=r==null?void 0:r.with(Q.DocSelectionRenderService);i==null||i.focus()}))}};exports.SheetUIController=ef([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)],exports.SheetUIController);var tf=Object.getOwnPropertyDescriptor,nf=(n,o,e,t)=>{for(var r=t>1?void 0:t?tf(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},nn=(n,o)=>(e,t)=>o(e,t,n);const rf=a.createInterceptorKey("statusBarPermissionCorrect");class of{constructor(){E(this,"_sum",0);E(this,"_count",0);E(this,"_countNumber",0);E(this,"_min",Number.POSITIVE_INFINITY);E(this,"_max",Number.NEGATIVE_INFINITY)}add(o,e,t){if(!a.Tools.isDefine(o==null?void 0:o.v))return;const r=o==null?void 0:o.t;let{v:i}=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 i=="string"&&r===a.CellValueType.NUMBER){const c=Number(i);Number.isNaN(c)||(i=c)}if(typeof i=="number"&&r!==a.CellValueType.STRING)s(i);else if(r===a.CellValueType.NUMBER&&o.s){const c=e.get(o.s);l(c,i,t)}this._count++}getResults(){return{sum:this._sum,count:this._countNumber,countA:this._count,min:this._min,max:this._max}}}function sf(n){const{sum:o,count:e,countA:t,min:r,max:i}=n.getResults();return[{func:G.FUNCTION_NAMES_STATISTICAL.MAX,value:i},{func:G.FUNCTION_NAMES_STATISTICAL.MIN,value:r},{func:G.FUNCTION_NAMES_MATH.SUM,value:o},{func:G.FUNCTION_NAMES_STATISTICAL.COUNTA,value:t},{func:G.FUNCTION_NAMES_STATISTICAL.COUNT,value:e},{func:G.FUNCTION_NAMES_STATISTICAL.AVERAGE,value:o/e}]}exports.StatusBarController=class extends a.Disposable{constructor(e,t,r,i,s,l){super();E(this,"interceptor",new a.InterceptorManager({STATUS_BAR_PERMISSION_CORRECT:rf}));this._univerInstanceService=e,this._selectionManagerService=t,this._statusBarService=r,this._commandService=i,this._numfmtService=s,this._formulaDataModel=l,this._init()}_init(){this._registerSelectionListener()}_registerSelectionListener(){const e=a.debounce(r=>{var s;const i=(s=r[r.length-1])==null?void 0:s.primary;this._calculateSelection(r.map(l=>l.range),i)},100),t=a.debounce(r=>{var s;const i=(s=r[r.length-1])==null?void 0:s.primary;this._calculateSelection(r.map(l=>l.range),i)},500);this.disposeWithMe(a.toDisposable(this._selectionManagerService.selectionMoving$.subscribe(r=>{r&&t(r)}))),this.disposeWithMe(a.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(r=>{r&&e(r)}))),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===m.SetRangeValuesMutation.id){const i=this._selectionManagerService.getCurrentSelections();i&&e(i)}}))}_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,r,i){var c,d,u,h;const s=r.getCellRaw(e,t),l=(c=i==null?void 0:i[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 r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!r)return this._clearResult();const i=r.getUnitId(),s=r.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(T=>{const{startRow:M,endRow:x}=T;let A=null;for(let D=M;D<=x;D++)s.getRowVisible(D)?A===null&&(A=D):A!==null&&(h.push({...T,startRow:A,endRow:D-1}),A=null);A!==null&&h.push({...T,startRow:A,endRow:x})});const g=a.splitIntoGrid(h),S=new of,f=r.getStyles(),p={},v=this._formulaDataModel.getArrayFormulaCellData(),C=(d=v==null?void 0:v[i])==null?void 0:d[l];for(const T of g){const{startRow:M,startColumn:x,endColumn:A,endRow:D}=this.getRangeStartEndInfo(T,s);for(let k=M;k<=D;k++)for(let H=x;H<=A;H++){const N=this._getCellValue(k,H,s,C);S.add(N,f,p)}}const _=sf(S);if(_.every(T=>T===void 0))return;let R=null;if(t){const{actualRow:T,actualColumn:M}=t;R=(u=this._numfmtService.getValue(i,l,T,M))==null?void 0:u.pattern}const P={values:_.filter(T=>T!==void 0),pattern:R};this._statusBarService.setState(P)}else this._clearResult()}};exports.StatusBarController=nf([nn(0,a.IUniverInstanceService),nn(1,a.Inject(m.SheetsSelectionsService)),nn(2,kr),nn(3,a.ICommandService),nn(4,a.Inject(m.INumfmtService)),nn(5,a.Inject(G.FormulaDataModel))],exports.StatusBarController);const Gc=(n=[])=>{const o=I.useDependency(Lt);W.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 af=Object.getOwnPropertyDescriptor,lf=(n,o,e,t)=>{for(var r=t>1?void 0:t?af(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Ta=(n,o)=>(e,t)=>o(e,t,n);let En=class extends a.Disposable{constructor(o,e){super();E(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,r)=>{if(t.id===m.RemoveSheetMutation.id)return this._adjustActiveSheetOnRemoveSheet(t);if(t.id===m.SetWorksheetHideMutation.id&&t.params.hidden)return this._adjustActiveSheetOnHideSheet(t);if(r!=null&&r.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,r=this._univerInstanceService.getUniverSheetInstance(e);if(!r||((c=r.getActiveSheet())==null?void 0:c.getSheetId())!==t)return;const s=r.getActiveSheetIndex(),l=ya(r,s);this._switchToNextSheet(e,l)}_beforeAdjustActiveSheetOnRemoveSheet(o){const{unitId:e,subUnitId:t}=o.params,r=this._univerInstanceService.getUniverSheetInstance(e);if(!r)return;const i=r.getSheetBySheetId(t);i&&(this._previousSheetIndex=r.getSheetIndex(i))}_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 i=this._previousSheetIndex,s=i>=1?i-1:0,l=ya(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 r;const{unitId:e,subUnitId:t}=o.params;t!==((r=this._univerInstanceService.getUnit(e))==null?void 0:r.getActiveSheet().getSheetId())&&this._switchToNextSheet(e,t)}_switchToNextSheet(o,e){this._commandService.executeCommand(m.SetWorksheetActiveOperation.id,{unitId:o,subUnitId:e})}};En=lf([Ta(0,a.ICommandService),Ta(1,a.IUniverInstanceService)],En);function ya(n,o){const e=n.getSheetSize();for(let t=o;t>-1;t--){const r=n.getSheetByIndex(t);if(!r.getConfig().hidden)return r.getSheetId()}for(let t=o;t<e;t++){const r=n.getSheetByIndex(t);if(!r.getConfig().hidden)return r.getSheetId()}throw new Error("[ActiveWorksheetController]: could not find the next unhidden sheet! Collaboration error perhaps.")}var cf=Object.getOwnPropertyDescriptor,df=(n,o,e,t)=>{for(var r=t>1?void 0:t?cf(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Ma=(n,o)=>(e,t)=>o(e,t,n),hn=(n=>(n[n.INFO=0]="INFO",n[n.WARNING=1]="WARNING",n[n.ERROR=2]="ERROR",n))(hn||{});exports.CellAlertManagerService=class extends a.Disposable{constructor(e,t){super();E(this,"_currentAlert$",new O.Subject);E(this,"_currentAlert",new Map);E(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:r}=e,{row:i,col:s,unitId:l,subUnitId:c}=r;if(!this._renderManagerService.getRenderById(l))return;const u=this._cellPopupManagerService.showPopup({unitId:l,subUnitId:c,row:i,col:s},{componentKey:Kc,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()))}};exports.CellAlertManagerService=df([Ma(0,y.IRenderManagerService),Ma(1,a.Inject(exports.CellPopupManagerService))],exports.CellAlertManagerService);function uf({popup:n}){var s;const o=(s=n.extraProps)==null?void 0:s.alert;if(!o)return null;const{type:e,title:t,message:r}=o,i={[hn.ERROR]:b.jsx(hs,{className:"univer-mr-1.5 univer-text-red-500"}),[hn.INFO]:b.jsx(Sl,{className:"univer-mr-1.5 univer-text-blue-500"}),[hn.WARNING]:b.jsx(vl,{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?i[e]:null,t]}),b.jsx("div",{className:"univer-text-sm",children:r})]})}const Kc="univer.sheet.cell-alert";var hf=Object.getOwnPropertyDescriptor,mf=(n,o,e,t)=>{for(var r=t>1?void 0:t?hf(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},gf=(n,o)=>(e,t)=>o(e,t,n);let lo=class extends a.Disposable{constructor(n,o){super(),this._context=n,this._componentManager=o,this._initComponent()}_initComponent(){this.disposeWithMe(this._componentManager.register(Kc,uf))}};lo=mf([gf(1,a.Inject(I.ComponentManager))],lo);var Sf=Object.getOwnPropertyDescriptor,ff=(n,o,e,t)=>{for(var r=t>1?void 0:t?Sf(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Pa=(n,o)=>(e,t)=>o(e,t,n);let co=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(O.filter(n=>n.visible)).subscribe(()=>{const n=this._editorBridgeService.getEditLocation();n&&this._cellPopupManagerService.hidePopup(n.unitId,n.sheetId,n.row,n.column)}))}};co=ff([Pa(1,he),Pa(2,a.Inject(exports.CellPopupManagerService))],co);var pf=Object.getOwnPropertyDescriptor,vf=(n,o,e,t)=>{for(var r=t>1?void 0:t?pf(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Fr=(n,o)=>(e,t)=>o(e,t,n);let Tn=class extends a.Disposable{constructor(o,e,t,r){super();E(this,"_isPointer",!1);this._hoverManagerService=o,this._instanceService=e,this._commandService=t,this._renderManagerService=r,this._initPointerEvent(),this._initHover()}get _mainComponent(){var o;return(o=y.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(y.CURSOR_TYPE.POINTER),this._isPointer=!0):(this._isPointer&&((t=this._mainComponent)==null||t.setCursor(y.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})}))}};Tn=vf([Fr(0,a.Inject(exports.HoverManagerService)),Fr(1,a.IUniverInstanceService),Fr(2,a.ICommandService),Fr(3,y.IRenderManagerService)],Tn);const xa=2,Cf=[{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"}],If=n=>{var k,H,N,V,L;const o=I.useDependency(a.IUniverInstanceService),e=I.useDependency(y.IRenderManagerService),t=vt();if(!n||!t)return null;const r={startRow:n.rows[0],startCol:n.cols[0],endRow:n.rows[n.rows.length-1],endCol:n.cols[n.cols.length-1]};if(r.endRow<0||r.endCol<0)return null;const i=e.getRenderById(t.getUnitId()),s=i==null?void 0:i.with(exports.SheetSkeletonManagerService),l=i==null?void 0:i.with(Ce),c=De(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),p=(k=d.getEngine())==null?void 0:k.getCanvas();if(!g||!d||!g||!S||!f)return null;const v=u==null?void 0:u.getNoMergeCellPositionByIndex(r.endRow,r.endCol),C=(H=v==null?void 0:v.endX)!=null?H:0,_=(N=v==null?void 0:v.endY)!=null?N:0,R=(V=y.convertTransformToOffsetX(C,g,f))!=null?V:-9999,w=(L=y.convertTransformToOffsetY(_,S,f))!=null?L:-9999,P=p==null?void 0:p.getWidth(),T=p==null?void 0:p.getHeight();if(!P||!T)return null;const M=R+50<=P,x=w+50<=T;let A=R,D=w;return M||(A=P-100),x||(D=T-100),{positionX:A,positionY:D}},_f=()=>{const n=I.useDependency(ke),o=I.useObservable(n.showMenu$,!1),e=I.useObservable(n.pasteOptionsCache$,null),t=I.useDependency(a.LocaleService),r=I.useDependency(a.ICommandService),[i,s]=W.useState(!1),[l,c]=W.useState(!1),d=e==null?void 0:e.target.pastedRange,u=If(d);if(!u||!o||u.positionX<50||u.positionY<30)return null;const h=i||l,g=S=>{c(!1),r.executeCommand(Ka.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+xa,top:u.positionY+xa},onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),children:b.jsx(j.DropdownMenu,{align:"start",items:Cf.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:j.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",j.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-800":l,"univer-bg-white dark:!univer-bg-gray-900":!l}),children:[b.jsx(_l,{className:"univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-white"}),h&&b.jsx(wn,{className:"dark:!univer-text-white"})]})})})})},bf=[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 Rf(n,o,e,t,r){const i=[],s=[];if(t.copyType===$e.CUT){const{undos:l,redos:c}=wf(n,o,r);i.push(...c),s.push(...l)}else{const{undos:l,redos:c}=Jc(o,e,r);i.push(...c),s.push(...l);const{undos:d,redos:u}=Ef(o,e,r);i.push(...u),s.push(...d);const{undos:h,redos:g}=qc(o,n,e,r);i.push(...g),s.push(...h);const{undos:S,redos:f}=Qc(o,n,e,r,!0);i.push(...f),s.push(...S);const{undos:p,redos:v}=Bi(o,e,r);i.push(...v),s.push(...p)}return{undos:s,redos:i}}function wf(n,o,e){let t=[],r=[];const{range:i,subUnitId:s,unitId:l}=n,{range:c,subUnitId:d}=o,u=c?gt(c):null,h=i?gt(i):null;if(h&&u){const g=e.get(a.IUniverInstanceService),S=e.get(m.SheetInterceptorService),f=g.getUniverSheetInstance(l),p=f==null?void 0:f.getSheetBySheetId(s),v=f==null?void 0:f.getSheetBySheetId(d);if(p&&v){const C=new a.ObjectMatrix,_=new a.ObjectMatrix,R=p.getCellMatrix(),w=v.getCellMatrix();a.Range.foreach(h,(B,z)=>{C.setValue(B,z,a.cloneCellData(R.getValue(B,z))),_.setValue(B,z,null)});const P=new a.ObjectMatrix;a.Range.foreach(u,(B,z)=>{P.setValue(B,z,a.cloneCellData(w.getValue(B,z)))});const T=new a.ObjectMatrix;a.Range.foreach(h,(B,z)=>{const X=a.cellToRange(B,z),K=a.Rectangle.getRelativeRange(X,h),re=a.Rectangle.getPositionRange(K,u);T.setValue(re.startRow,re.startColumn,R.getValue(B,z))});const M={fromRange:h,toRange:u,from:{value:_.getMatrix(),subUnitId:s},to:{value:T.getMatrix(),subUnitId:d},unitId:l},x={fromRange:u,toRange:h,from:{value:C.getMatrix(),subUnitId:s},to:{value:P.getMatrix(),subUnitId:d},unitId:l},A=S.onCommandExecute({id:m.MoveRangeCommand.id,params:{toRange:u,fromRange:h}}),D=p.getMergeData(),k=v.getMergeData(),H=D.filter(B=>a.Rectangle.intersects(B,h)),N=k.filter(B=>a.Rectangle.intersects(B,u)),V=H.map(B=>a.Rectangle.getRelativeRange(B,h)).map(B=>a.Rectangle.getPositionRange(B,u)),L=m.getAddMergeMutationRangeByType(V),U=[{id:m.RemoveWorksheetMergeMutation.id,params:{unitId:l,subUnitId:s,ranges:H}},{id:m.RemoveWorksheetMergeMutation.id,params:{unitId:l,subUnitId:s,ranges:N}},{id:m.AddWorksheetMergeMutation.id,params:{unitId:l,subUnitId:d,ranges:L}}],F=[{id:m.RemoveWorksheetMergeMutation.id,params:{unitId:l,subUnitId:d,ranges:L}},{id:m.AddWorksheetMergeMutation.id,params:{unitId:l,subUnitId:d,ranges:N}},{id:m.AddWorksheetMergeMutation.id,params:{unitId:l,subUnitId:s,ranges:H}}];t=[{id:m.MoveRangeMutation.id,params:M},...A.redos,...U,{id:m.SetSelectionsOperation.id,params:{unitId:l,subUnitId:d,selections:[{range:u}],type:m.SelectionMoveType.MOVE_END}}],r=[{id:m.MoveRangeMutation.id,params:x},...A.undos,...F,{id:m.SetSelectionsOperation.id,params:{unitId:l,subUnitId:s,type:m.SelectionMoveType.MOVE_END,selections:[{range:h}]}}]}}return{undos:r,redos:t}}function qc(n,o,e,t){var f;const{unitId:r,subUnitId:i,range:s}=n,l=(f=t.get(a.IUniverInstanceService).getUniverSheetInstance(r))==null?void 0:f.getSheetBySheetId(i),c=[],d=[],{mapFunc:u}=St([s]),h=new a.ObjectMatrix;e.forValue((p,v,C)=>{var P,T;const{row:_,col:R}=u(p,v),w={v:C.v,t:C.t};if(!C.p&&C.v&&!o){const M=l==null?void 0:l.getCellStyle(_,R);if(a.isTextFormat((P=M==null?void 0:M.n)==null?void 0:P.pattern))w.t=a.CellValueType.STRING;else{const x=String(C.v),A=a.numfmt.parseValue(x);(A==null?void 0:A.v)!==void 0&&typeof A.v=="number"&&(!A.z&&a.willLoseNumericPrecision(x)?w.t=a.CellValueType.FORCE_STRING:w.v=A.v)}}if((T=C.p)!=null&&T.body&&Hi(C.p.body)){const M={p:a.cloneValue(C.p),v:C.v};h.setValue(_,R,M)}else h.setValue(_,R,w&&a.cloneCellData(w))});const g={unitId:r,subUnitId:i,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 Qc(n,o,e,t,r=!1){var p;const i=[],s=[],{unitId:l,subUnitId:c,range:d}=n,u=(p=t.get(a.IUniverInstanceService).getUniverSheetInstance(l))==null?void 0:p.getSheetBySheetId(c),h=new a.ObjectMatrix,{mapFunc:g}=St([d]);e.forValue((v,C,_)=>{var x,A;const R={s:Object.assign({},{...a.DEFAULT_STYLES,pd:y.DEFAULT_PADDING_DATA,bg:null,cl:null},_.s)},w=R.s.bd;w&&(Object.keys(w).length>0||(R.s.bd={b:null,l:null,r:null,t:null}));const{row:P,col:T}=g(v,C),M=u==null?void 0:u.getCellStyle(P,T);if(_.v&&!o&&a.isTextFormat((x=M==null?void 0:M.n)==null?void 0:x.pattern))R.s||(R.s={}),R.s.n=M==null?void 0:M.n;else{const D=String(_.v),k=a.numfmt.parseValue(D);k!=null&&k.z&&(R.s||(R.s={}),typeof R.s=="object"&&((A=R.s)!=null&&A.n?R.s.n.pattern=k.z:R.s.n={pattern:k.z}))}h.setValue(P,T,R)});const S={unitId:l,subUnitId:c,cellValue:a.cloneCellDataMatrix(h.getMatrix())};i.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:i}}function Jc(n,o,e){const t=[],r=[],i=new a.ObjectMatrix,{unitId:s,subUnitId:l,range:c}=n,{mapFunc:d}=St([c]);if(o.forEach((u,h)=>{Object.keys(h).forEach(g=>{const S=Number(g),{row:f,col:p}=d(u,S);i.setValue(f,p,{s:null})})}),i.getLength()>0){const u={subUnitId:l,unitId:s,cellValue:a.cloneCellDataMatrix(i.getMatrix())};t.push({id:m.SetRangeValuesMutation.id,params:u});const h=m.SetRangeValuesUndoMutationFactory(e,u);r.push({id:m.SetRangeValuesMutation.id,params:h})}return{undos:r,redos:t}}function Ef(n,o,e){const t=[],r=[],i=new a.ObjectMatrix,{unitId:s,subUnitId:l,range:c}=n,{mapFunc:d}=St([c]);if(o.forValue((u,h,g)=>{const{row:S,col:f}=d(u,h);i.setValue(S,f,{v:null,p:null})}),i.getLength()>0){const u={subUnitId:l,unitId:s,cellValue:a.cloneCellDataMatrix(i.getMatrix())};t.push({id:m.SetRangeValuesMutation.id,params:u});const h=m.SetRangeValuesUndoMutationFactory(e,u);r.push({id:m.SetRangeValuesMutation.id,params:h})}return{undos:r,redos:t}}function Bi(n,o,e){const t=[],r=[],{unitId:i,subUnitId:s,range:l}=n,{startColumn:c,startRow:d,endColumn:u,endRow:h}=gt(l),g=[];o.forValue((_,R,w)=>{if(w.rowSpan&&w.rowSpan>1){const P=w.colSpan||1,T={startRow:d+_,endRow:d+_+w.rowSpan-1,startColumn:c+R,endColumn:c+R+P-1};g.push(T)}else if(w.colSpan&&w.colSpan>1){const P=w.rowSpan||1,T={startRow:d+_,endRow:d+_+P-1,startColumn:c+R,endColumn:c+R+w.colSpan-1};g.push(T)}});const f=e.get(a.IUniverInstanceService).getUniverSheetInstance(i),p=f==null?void 0:f.getSheetBySheetId(s);if(f&&p){const R=p.getMergeData().filter(T=>a.Rectangle.intersects({startRow:d,startColumn:c,endRow:h,endColumn:u},T)),w={unitId:i,subUnitId:s,ranges:R};t.push({id:m.RemoveWorksheetMergeMutation.id,params:w});const P=m.RemoveMergeUndoMutationFactory(e,w);r.push({id:m.AddWorksheetMergeMutation.id,params:P})}const v={unitId:i,subUnitId:s,ranges:g};g.length>0&&t.push({id:m.AddWorksheetMergeMutation.id,params:v});const C=m.AddMergeUndoMutationFactory(e,v);return g.length>0&&r.push({id:m.RemoveWorksheetMergeMutation.id,params:C}),{undos:r,redos:t}}function Tf(n){if(!n.includes("\r")&&a.Tools.isLegalUrl(n)){const t=a.generateRandomId(),r=`${n}`,i={startIndex:0,endIndex:r.length-1,rangeId:t,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:n}};return{dataStream:`${r}\r
|
|
12
|
+
`,"");return e.forEach(i=>{const{st:s,ed:l,ts:c}=i;l-s>=r.length&&(t={...t,...c})}),Object.keys(t).length?t:null}function km(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 ha(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 Nm=Object.getOwnPropertyDescriptor,Vm=(n,o,e,t)=>{for(var r=t>1?void 0:t?Nm(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Ge=(n,o)=>(e,t)=>o(e,t,n);exports.FormulaEditorController=class extends a.RxDisposable{constructor(e,t,r,i,s,l,c,d,u){super();E(this,"_loadedMap",new WeakSet);E(this,"_scheduledCallback",-1);this._univerInstanceService=e,this._renderManagerService=t,this._editorBridgeService=r,this._commandService=i,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(O.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===ve.RichTextEditingMutation.id){const t=e.params,{unitId:r}=t;r===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:r}=t;r!=null&&(this._loadedMap.has(r)||this._loadedMap.add(r))}_listenFxBtnClick(){this._formulaEditorManagerService.fxBtnClick$.pipe(O.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 r=this._univerInstanceService.getUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);this._editorBridgeService.isVisible().visible===!1&&this._commandService.syncExecuteCommand(Se.id,{visible:!0,eventType:y.DeviceInputEventType.PointerDown,unitId:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY});const s=(t=r==null?void 0:r.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(Q.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(O.filter(t=>t.getUnitId()===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY));this.disposeWithMe(O.combineLatest([this._formulaEditorManagerService.position$,e]).subscribe(([t])=>{if(!t)return this._clearScheduledCallback();const r=yo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,this._renderManagerService),i=this._univerInstanceService.getUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);if(r==null||i==null)return this._clearScheduledCallback();const{width:s,height:l}=t;if(s===0||l===0)return this._clearScheduledCallback();const{engine:c}=r;i.updateDocumentDataPageSize(s),this.autoScroll(),this._scheduledCallback=requestIdleCallback(()=>c.resizeBySize(s,l))}))}_clearScheduledCallback(){this._scheduledCallback!==-1&&cancelIdleCallback(this._scheduledCallback),this._scheduledCallback=-1}autoScroll(){var p,v;const e=this._formulaEditorManagerService.getPosition(),t=(p=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:p.with(ve.DocSkeletonManagerService).getSkeleton(),r=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),i=this._univerInstanceService.getUniverDocInstance(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);if(t==null||e==null||r==null||i==null)return;const{marginTop:s=0,marginBottom:l=0}=i.getSnapshot().documentStyle,{scene:c,mainComponent:d}=r;let{actualHeight:u}=t.getActualSize();u+=s+l;const{width:h,height:g}=e,S=c.getViewport(Q.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 y.ScrollBar(S,{enableHorizontal:!1,barSize:8}):S==null||S.resetCanvasSizeAndUpdateScroll():(f=null,S==null||S.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0}),(v=S==null?void 0:S.getScrollBar())==null||v.dispose())}};exports.FormulaEditorController=Vm([Ge(0,a.IUniverInstanceService),Ge(1,y.IRenderManagerService),Ge(2,he),Ge(3,a.ICommandService),Ge(4,a.IContextService),Ge(5,Ln),Ge(6,a.IUndoRedoService),Ge(7,a.Inject(ve.DocSelectionManagerService)),Ge(8,Q.IEditorService)],exports.FormulaEditorController);const jl="embedding_formula_editor",Hm=n=>n.includes(jl),Is=(n,o)=>{var h,g,S,f,p;const t=o.findNodePositionByCharIndex(n.startOffset,!0,n.segmentId,-1),r=o.getSkeletonData();let i=n.endOffset;if(n.segmentId){const v=(p=Array.from((g=(h=r==null?void 0:r.skeFooters.get(n.segmentId))==null?void 0:h.values())!=null?g:[])[0])!=null?p:Array.from((f=(S=r==null?void 0:r.skeHeaders.get(n.segmentId))==null?void 0:S.values())!=null?f:[])[0];v&&(i=Math.min(v.ed,i))}const s=o.findNodePositionByCharIndex(i,!0,n.segmentId,-1);if(!s||!t)return;const l={docsLeft:0,docsTop:0,pageMarginLeft:0,pageMarginTop:0},c=new Q.NodePositionConvertToCursor(l,o),{borderBoxPointGroup:d}=c.getRangePointData(t,s);return Q.getLineBounding(d).map(v=>({top:v.top,bottom:v.bottom,left:v.left,right:v.right}))},Wm=(n,o,e=-1)=>{const t=o.findPositionByGlyph(n,e);if(!t)return;const r={...t,isBack:!0},i={docsLeft:0,docsTop:0,pageMarginLeft:0,pageMarginTop:0},s=new Q.NodePositionConvertToCursor(i,o),{borderBoxPointGroup:l}=s.getRangePointData(r,r),d=Q.getLineBounding(l)[0];return{top:d.top,bottom:d.bottom,left:d.left,right:d.right}},Um=(n,o,e=0,t=0)=>{const r=Is({startOffset:o.startIndex,endOffset:o.endIndex+1},n);if(r)return{rects:r.map(i=>({top:i.top+t,bottom:i.bottom+t,left:i.left+e,right:i.right+e})),range:o}},Lm=(n,o,e=0,t=0)=>{var h,g,S;const r=n.findNodeByCharIndex(o.startIndex),i=r==null?void 0:r.parent,s=i==null?void 0:i.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=Wm(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}},zl=(n,o=0,e=0)=>{var l,c,d,u,h,g,S;const t=n.getViewModel().getDataModel(),r=(d=(c=(l=t.getBody())==null?void 0:l.customRanges)==null?void 0:c.filter(f=>f.rangeType===a.CustomRangeType.HYPERLINK))!=null?d:[],i=(g=(h=(u=t.getBody())==null?void 0:u.paragraphs)==null?void 0:h.filter(f=>{var p;return((p=f.bullet)==null?void 0:p.listType.indexOf(a.PresetListType.CHECK_LIST))===0}))!=null?g:[],s=(S=n.getSkeletonData())==null?void 0:S.pages[0].skeDrawings;return{links:r.map(f=>Um(n,f,o,e)).filter(Boolean),checkLists:i.map(f=>Lm(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 Xl(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,r=(f=(S=(g=o.documentSkeleton)==null?void 0:g.getSkeletonData())==null?void 0:S.pages[0].width)!=null?f:0,i=o.verticalAlign,s=o.horizontalAlign;let l=0;switch(i){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-r;break;case a.HorizontalAlign.CENTER:c=(n.mergeInfo.endX-n.mergeInfo.startX-r)/2;break;case a.HorizontalAlign.UNSPECIFIED:{e&&(c=n.mergeInfo.endX-n.mergeInfo.startX-r);break}}return{paddingLeft:c,paddingTop:l}}const Bm=(n,o,e,t,r,i)=>{var k,H,N;const s=n.get(a.IUniverInstanceService),l=n.get(y.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(exports.SheetSkeletonManagerService).getSkeletonParam(d.getSheetId()),g=h==null?void 0:h.skeleton;if(!g||!u)return;const S=g.getFont(t,r),f=S==null?void 0:S.documentSkeleton;if(!f)return null;const p=(H=(k=f.getViewModel().getBody())==null?void 0:k.customRanges)==null?void 0:H.find(V=>V.rangeId===i);if(!p)return null;const v=Q.DOC_VERTICAL_PADDING,C=g.getCellWithCoordByIndex(t,r);let{actualColumn:_,actualRow:R}=C;g.overflowCache.forValue((V,L,U)=>{U.startRow<=R&&U.endRow>=R&&U.startColumn<=_&&U.endColumn>=_&&(_=L,R=V)});const w=g.getCellWithCoordByIndex(R,_),P=d.getCell(w.actualRow,w.actualColumn),{topOffset:T=0,leftOffset:M=0}=(N=P==null?void 0:P.fontRenderExtension)!=null?N:{},{paddingLeft:x,paddingTop:A}=Xl(w,S,!1),D=Is({startOffset:p.startIndex,endOffset:p.endIndex},f);return{rects:D==null?void 0:D.map(V=>({top:V.top+w.mergeInfo.startY+A+T+v,bottom:V.bottom+w.mergeInfo.startY+A+T+v,left:V.left+w.mergeInfo.startX+x+M,right:V.right+w.mergeInfo.startX+x+M})),customRange:p,label:f.getViewModel().getBody().dataStream.slice(p.startIndex,p.endIndex+1)}},Fm=(n,o,e,t,r,i)=>{var M,x,A;const s=n.get(he),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!==r)return null;const f=n.get(y.IRenderManagerService),p=f.getRenderById(d),v=f.getRenderById(o);if(!p||!v)return null;const C=p.with(ve.DocSkeletonManagerService).getSkeleton(),_=(M=v.with(exports.SheetSkeletonManagerService).getSkeletonParam(h))==null?void 0:M.skeleton;if(!C||!_)return null;const R=(A=(x=C.getViewModel().getBody())==null?void 0:x.customRanges)==null?void 0:A.find(D=>D.rangeId===i);if(!R)return null;const w=4,P=Is({startOffset:R.startIndex,endOffset:R.endIndex},C),T=p.engine.getCanvasElement().getBoundingClientRect();return{rects:P==null?void 0:P.map(D=>({top:D.top+T.top-w,bottom:D.bottom+T.top+w,left:D.left+T.left,right:D.right+T.left})),customRange:R,label:C.getViewModel().getBody().dataStream.slice(R.startIndex,R.endIndex+1)}};var jm=Object.getOwnPropertyDescriptor,zm=(n,o,e,t)=>{for(var r=t>1?void 0:t?jm(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},ma=(n,o)=>(e,t)=>o(e,t,n);function Rt(n){const{workbook:o,worksheet:e,...t}=n;return t}exports.HoverManagerService=class extends a.Disposable{constructor(e,t){super();E(this,"_currentCell$",new O.BehaviorSubject(null));E(this,"_currentRichText$",new O.BehaviorSubject(null));E(this,"_currentClickedCell$",new O.Subject);E(this,"_currentDbClickedCell$",new O.Subject);E(this,"_currentCellWithEvent$",new O.Subject);E(this,"_currentPointerDownCell$",new O.Subject);E(this,"_currentPointerUpCell$",new O.Subject);E(this,"_currentHoveredRowHeader$",new O.BehaviorSubject(null));E(this,"_currentHoveredColHeader$",new O.BehaviorSubject(null));E(this,"_currentRowHeaderClick$",new O.Subject);E(this,"_currentColHeaderClick$",new O.Subject);E(this,"_currentRowHeaderDbClick$",new O.Subject);E(this,"_currentColHeaderDbClick$",new O.Subject);E(this,"_currentRowHeaderPointerDown$",new O.Subject);E(this,"_currentColHeaderPointerDown$",new O.Subject);E(this,"_currentRowHeaderPointerUp$",new O.Subject);E(this,"_currentColHeaderPointerUp$",new O.Subject);E(this,"currentCell$",this._currentCell$.asObservable().pipe(O.distinctUntilChanged((e,t)=>{var r,i,s,l,c,d,u,h;return((r=e==null?void 0:e.location)==null?void 0:r.unitId)===((i=t==null?void 0:t.location)==null?void 0:i.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)})));E(this,"currentRichTextNoDistinct$",this._currentRichText$.pipe(O.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})));E(this,"currentRichText$",this._currentRichText$.pipe(O.distinctUntilChanged((e,t)=>{var r,i,s,l,c,d,u,h,g,S,f,p,v,C,_,R,w,P;return((r=e==null?void 0:e.location)==null?void 0:r.unitId)===((i=t==null?void 0:t.location)==null?void 0:i.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)===((p=t==null?void 0:t.bullet)==null?void 0:p.startIndex)&&((v=e==null?void 0:e.customRange)==null?void 0:v.startIndex)===((C=t==null?void 0:t.customRange)==null?void 0:C.startIndex)&&((_=e==null?void 0:e.customRange)==null?void 0:_.endIndex)===((R=t==null?void 0:t.customRange)==null?void 0:R.endIndex)&&((w=e==null?void 0:e.drawing)==null?void 0:w.drawingId)===((P=t==null?void 0:t.drawing)==null?void 0:P.drawingId)}),O.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})));E(this,"currentCellPosWithEvent$",this._currentCellWithEvent$.pipe(O.distinctUntilChanged((e,t)=>{var r,i,s,l,c,d,u,h;return((r=e==null?void 0:e.location)==null?void 0:r.unitId)===((i=t==null?void 0:t.location)==null?void 0:i.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)}),O.map(e=>e&&{unitId:e.location.unitId,subUnitId:e.location.subUnitId,row:e.location.row,col:e.location.col,event:e.event})));E(this,"currentPosition$",this._currentCell$.asObservable());E(this,"currentClickedCell$",this._currentClickedCell$.asObservable());E(this,"currentDbClickedCell$",this._currentDbClickedCell$.asObservable());E(this,"currentPointerDownCell$",this._currentPointerDownCell$.asObservable());E(this,"currentPointerUpCell$",this._currentPointerUpCell$.asObservable());E(this,"currentHoveredRowHeader$",this._currentHoveredRowHeader$.asObservable());E(this,"currentHoveredColHeader$",this._currentHoveredColHeader$.asObservable());E(this,"currentRowHeaderClick$",this._currentRowHeaderClick$.asObservable());E(this,"currentColHeaderClick$",this._currentColHeaderClick$.asObservable());E(this,"currentRowHeaderDbClick$",this._currentRowHeaderDbClick$.asObservable());E(this,"currentColHeaderDbClick$",this._currentColHeaderDbClick$.asObservable());E(this,"currentRowHeaderPointerDown$",this._currentRowHeaderPointerDown$.asObservable());E(this,"currentColHeaderPointerDown$",this._currentColHeaderPointerDown$.asObservable());E(this,"currentRowHeaderPointerUp$",this._currentRowHeaderPointerUp$.asObservable());E(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$=O.of(null),this.currentRichText$=O.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,r;((t=this._currentCell$.getValue())==null?void 0:t.location.unitId)===e.getUnitId()&&this._currentCell$.next(null),((r=this._currentRichText$.getValue())==null?void 0:r.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 r=t.getActiveSheet();if(!r)return null;const i=this._renderManagerService.getRenderById(t.getUnitId());if(!i)return null;const s=i.with(exports.SheetSkeletonManagerService).getSkeletonParam(r.getSheetId());if(!s)return null;const l=i.with(exports.SheetScrollManagerService);if(!(!(l!=null&&l.getCurrentScrollState())||!i))return{currentRender:i,workbook:t,worksheet:r,skeletonParam:s}}_calcActiveCell(e,t,r,i,s,l){var M,x,A;const c=ll(e,t,r,i,s,l),d=i.skeleton;if(!c)return null;const{position:u,overflowLocation:h,location:g}=c,S=d.getFont(h.row,h.col);let f=null,p=null,v=null;const C=d.getCellWithCoordByIndex(h.row,h.col),_=r.getCell(h.row,h.col),{topOffset:R=0,leftOffset:w=0}=(M=_==null?void 0:_.fontRenderExtension)!=null?M:{};if(S!=null&&S.documentSkeleton){const{paddingLeft:D,paddingTop:k}=Xl(C,S,(_==null?void 0:_.v)!==null&&(_==null?void 0:_.v)!==void 0?!Number.isNaN(+_.v):!1),H=zl(S.documentSkeleton,D,k),N=s-u.startX-w,V=l-u.startY-R;f=H.links.find(L=>L.rects.some(U=>U.left<=N&&N<=U.right&&U.top<=V&&V<=U.bottom)),p=H.checkLists.find(L=>L.rect.left<=N&&N<=L.rect.right&&L.rect.top<=V&&V<=L.rect.bottom),v=H.drawings.find(L=>L.rect.left<=N&&N<=L.rect.right&&L.rect.top<=V&&V<=L.rect.bottom)}const P=(A=(x=f==null?void 0:f.rects.pop())!=null?x:p==null?void 0:p.rect)!=null?A:v==null?void 0:v.rect,T=P&&(()=>{const D=P.top+C.mergeInfo.startY+R,k=P.bottom+C.mergeInfo.startY+R,H=P.left+C.mergeInfo.startX+w,N=P.right+C.mergeInfo.startX+w,V=C.mergeInfo.startY+R,L=C.mergeInfo.endY+R,U=C.mergeInfo.startX+w,F=C.mergeInfo.endX+w,B=Math.min(Math.max(D,V),V),z=Math.min(k,L),X=Math.min(Math.max(H,U),U),K=Math.min(N,F);return{top:B,bottom:z,left:X,right:K}})();return{location:g,position:u,overflowLocation:h,customRange:f==null?void 0:f.range,bullet:p==null?void 0:p.paragraph,drawing:v,rect:T}}_calcActiveRowHeader(e,t,r){const i=this._getCalcDeps(e);if(!i)return;const{currentRender:s,worksheet:l,skeletonParam:c}=i,{scaleY:d}=s.scene.getAncestorScale(),u=s.scene.getViewports().find(S=>S.isHit(new y.Vector2(t,r)));if(!u||u.viewportKey!==y.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP&&u.viewportKey!==y.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM)return;const h={x:u.viewportScrollX,y:u.viewportScrollY},g=c.skeleton.getRowIndexByOffsetY(r,d,h);return{unitId:e,index:g,subUnitId:l.getSheetId()}}_calcActiveColHeader(e,t,r){const i=this._getCalcDeps(e);if(!i)return;const{currentRender:s,worksheet:l,skeletonParam:c}=i,{scaleX:d}=s.scene.getAncestorScale(),u=s.scene.getViewports().find(S=>S.isHit(new y.Vector2(t,r)));if(!u||u.viewportKey!==y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT&&u.viewportKey!==y.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 r=this._getCalcDeps(e);if(!r)return;const{currentRender:i,workbook:s,worksheet:l,skeletonParam:c}=r,d=this._calcActiveCell(i,s,l,c,t.offsetX,t.offsetY);if(d&&d.location){const{unitId:u,subUnitId:h,row:g,col:S}=Rt(d.location);this._currentPointerDownCell$.next({unitId:u,subUnitId:h,row:g,col:S,event:t})}}triggerPointerUp(e,t){const r=this._getCalcDeps(e);if(!r)return;const{currentRender:i,workbook:s,worksheet:l,skeletonParam:c}=r,d=this._calcActiveCell(i,s,l,c,t.offsetX,t.offsetY);if(d){const u=Rt(d.location);this._currentPointerUpCell$.next({...u,event:t})}}triggerMouseMove(e,t){const r=this._getCalcDeps(e);if(!r)return;const{currentRender:i,workbook:s,worksheet:l,skeletonParam:c}=r,d=this._calcActiveCell(i,s,l,c,t.offsetX,t.offsetY);this._currentCell$.next(d&&{location:Rt(d.location),position:d.position}),this._currentRichText$.next(d&&{...d,location:Rt(d.overflowLocation)}),this._currentCellWithEvent$.next(d&&{...d,location:Rt(d.location),event:t})}triggerClick(e,t,r){const i=this._getCalcDeps(e);if(!i)return;const{currentRender:s,workbook:l,worksheet:c,skeletonParam:d}=i,u=this._calcActiveCell(s,l,c,d,t,r);u&&this._currentClickedCell$.next({...u,location:Rt(u.location)})}triggerDbClick(e,t,r){const i=this._getCalcDeps(e);if(!i)return;const{currentRender:s,workbook:l,worksheet:c,skeletonParam:d}=i,u=this._calcActiveCell(s,l,c,d,t,r);u&&this._currentDbClickedCell$.next({...u,location:Rt(u.location)})}triggerScroll(){this._currentCell$.next(null)}triggerRowHeaderClick(e,t,r){const i=this._calcActiveRowHeader(e,t,r);i&&this._currentRowHeaderClick$.next(i)}triggerColHeaderClick(e,t,r){const i=this._calcActiveColHeader(e,t,r);i&&this._currentColHeaderClick$.next(i)}triggerRowHeaderDbClick(e,t,r){const i=this._calcActiveRowHeader(e,t,r);i&&this._currentRowHeaderDbClick$.next(i)}triggerColHeaderDbClick(e,t,r){const i=this._calcActiveColHeader(e,t,r);i&&this._currentColHeaderDbClick$.next(i)}triggerRowHeaderMouseMove(e,t,r){this._currentHoveredRowHeader$.next(this._calcActiveRowHeader(e,t,r))}triggerColHeaderMouseMove(e,t,r){this._currentHoveredColHeader$.next(this._calcActiveColHeader(e,t,r))}triggerRowHeaderPoniterDown(e,t,r){const i=this._calcActiveRowHeader(e,t,r);i&&this._currentRowHeaderPointerDown$.next(i)}triggerColHeaderPoniterDown(e,t,r){const i=this._calcActiveColHeader(e,t,r);i&&this._currentColHeaderPointerDown$.next(i)}triggerRowHeaderPoniterUp(e,t,r){const i=this._calcActiveRowHeader(e,t,r);i&&this._currentRowHeaderPointerUp$.next(i)}triggerColHeaderPoniterUp(e,t,r){const i=this._calcActiveColHeader(e,t,r);i&&this._currentColHeaderPointerUp$.next(i)}};exports.HoverManagerService=zm([ma(0,a.IUniverInstanceService),ma(1,y.IRenderManagerService)],exports.HoverManagerService);var Xm=Object.getOwnPropertyDescriptor,Ym=(n,o,e,t)=>{for(var r=t>1?void 0:t?Xm(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Go=(n,o)=>(e,t)=>o(e,t,n);exports.HoverRenderController=class extends a.Disposable{constructor(e,t,r,i){super();E(this,"_active",!1);this._context=e,this._hoverManagerService=t,this._sheetSkeletonManagerService=r,this._scrollManagerService=i,this._initPointerEvent(),this._initScrollEvent()}get active(){return this._active}_initPointerEvent(){const e=new a.DisposableCollection,t=r=>{if(e.dispose(),!r)return;const{mainComponent:i,unitId:s,components:l}=this._context;if(!i)return;e.add(i.onPointerEnter$.subscribeEvent(u=>{this._active=!0})),e.add(a.fromEventSubject(i.onPointerMove$).subscribe(u=>{this._active=!0,this._hoverManagerService.triggerMouseMove(s,u)})),e.add(i.onPointerDown$.subscribeEvent(u=>{this._hoverManagerService.triggerPointerDown(s,u)})),e.add(i.onPointerUp$.subscribeEvent(u=>{this._hoverManagerService.triggerPointerUp(s,u)})),e.add(i.onClick$.subscribeEvent(u=>{this._hoverManagerService.triggerClick(s,u.offsetX,u.offsetY)})),e.add(i.onDblclick$.subscribeEvent(u=>{this._hoverManagerService.triggerDbClick(s,u.offsetX,u.offsetY)})),e.add(i.onPointerLeave$.subscribeEvent(()=>{this._active=!1}));const c=l.get(ue.ROW),d=l.get(ue.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(r=>{t(r)}))}_initScrollEvent(){this.disposeWithMe(this._scrollManagerService.validViewportScrollInfo$.subscribe(()=>this._hoverManagerService.triggerScroll()))}};exports.HoverRenderController=Ym([Go(1,a.Inject(exports.HoverManagerService)),Go(2,a.Inject(exports.SheetSkeletonManagerService)),Go(3,a.Inject(exports.SheetScrollManagerService))],exports.HoverRenderController);const Yl="UI_PLUGIN_SHEETS",_s=`${Yl}_BORDER_PANEL_COMPONENT`,Zl=[{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 Zm(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)):O.of(null)))}function _e(n,o,e){return Zm(n).pipe(de.switchMap(t=>t?e(t):O.of(o)))}function Gl(n,o){const e=n.get(a.IUniverInstanceService),t=n.get(m.IExclusiveRangeService),r=n.get(m.SheetsSelectionsService);return e.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(de.switchMap(s=>s?O.combineLatest([r.selectionMoveEnd$,s.activeSheet$]).pipe(de.switchMap(([l,c])=>{if(!c||l.length===0)return O.of(!1);const d=t.getInterestGroupId(l);if(o){const u=d.filter(h=>o.has(h));return O.of(u.length>0)}else return O.of(d.length>0)})):O.of(!1)))}function Gt(n,o,e){return O.combineLatest([o,Gl(n,e)]).pipe(de.map(([t,r])=>t||r))}function $(n,o={},e=!1){var g;const r=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),i=n.get(a.UserManagerService),s=n.has(he)?n.get(he):null,l=n.get(a.IContextService),d=((g=s==null?void 0:s.visible$)!=null?g:O.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 O.combineLatest([i.currentUser$,r,d,u]).pipe(de.switchMap(([S,f,p,v])=>!f||p!=null&&p.visible&&p.unitId===f.getUnitId()&&!e||v&&!e?O.of(!0):f.activeSheet$.pipe(de.switchMap(C=>{if(!C)return O.of(!0);const _=n.get(m.SheetsSelectionsService),R=n.get(m.RangeProtectionRuleModel),w=n.get(m.WorksheetProtectionRuleModel),T=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_COMMON_DRAWINGS).pipe(de.startWith(!1));return O.combineLatest([_.selectionMoveEnd$,T]).pipe(de.switchMap(([M,x])=>{if(x)return O.of(!0);const A=f.getUnitId(),D=C.getSheetId(),k=n.get(a.IPermissionService),{workbookTypes:H=[m.WorkbookEditablePermission],worksheetTypes:N,rangeTypes:V}=o,L=[];if(H==null||H.forEach(z=>{L.push(new z(A).id)}),N==null||N.forEach(z=>{L.push(new z(A,D).id)}),w.getRule(A,D))return k.composePermission$(L).pipe(de.map(z=>z.some(X=>X.value===!1)));const F=M==null?void 0:M.map(z=>z.range),B=R.getSubunitRuleList(A,D).filter(z=>F==null?void 0:F.some(X=>z.ranges.some(K=>a.Rectangle.intersects(X,K))));return V==null||V.forEach(z=>{B.forEach(X=>{L.push(new z(A,D,X.permissionId).id)})}),k.composePermission$(L).pipe(de.map(z=>z.some(X=>X.value===!1)))}))}))))}function Bn(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(m.RangeProtectionRuleModel),r=n.get(a.IPermissionService);return O.merge(e.selectionMoveEnd$,r.permissionPointUpdate$.pipe(de.debounceTime(100))).pipe(de.map(()=>{var h;const i=(h=e.getCurrentLastSelection())==null?void 0:h.range;if(!i)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(i,S))).forEach(g=>{u.push(new m.RangeProtectionPermissionEditPoint(c,d,g.permissionId).id)}),r.composePermission(u).some(g=>g.value===!1)}))}function Kl(n,o){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.RangeProtectionRuleModel),i=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,i.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 r.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)}),i.composePermission(h).some(S=>S.value===!1)}))}function ql(n,o){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.RangeProtectionRuleModel),i=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,i.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),r.getSubunitRuleList(d,u).filter(f=>f.ranges.some(p=>a.Rectangle.intersects(g,p))).forEach(f=>{h.push(new m.RangeProtectionPermissionEditPoint(d,u,f.permissionId).id)}),i.composePermission(h).some(f=>f.value===!1)}))}function Bo(n,o){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(m.RangeProtectionRuleModel),i=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,i.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,r.getSubunitRuleList(d,u).filter(f=>f.ranges.some(p=>a.Rectangle.intersects(g,p))).forEach(f=>{h.push(new m.RangeProtectionPermissionEditPoint(d,u,f.permissionId).id)}),i.composePermission(h).some(f=>f.value===!1)}))}function Fn(n,o){const t=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(m.WorksheetProtectionRuleModel),i=n.get(m.RangeProtectionRuleModel),s=n.get(a.IPermissionService),l=n.get(a.UserManagerService);return O.combineLatest([l.currentUser$,t]).pipe(de.switchMap(([c,d])=>d?d.activeSheet$.pipe(de.switchMap(u=>{if(!u)return O.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(p=>p.value===!0))).pipe(de.map(f=>{if(!f)return!0;const p=u.getSheetId(),v=r.getRule(h,p),C=i.getSubunitRuleList(h,p);return!!(v||C.length)}))})):O.of(!0)))}function Gm(n){const o=n.get(m.BorderStyleManagerService),e=$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]});return{id:m.SetBorderBasicCommand.id,icon:new O.Observable(t=>{const r="AllBorderIcon",i=n.get(m.BorderStyleManagerService),s=n.get(a.ICommandService).onCommandExecuted(l=>{var g;if(l.id!==m.SetBorderBasicCommand.id)return;const{type:d}=i.getBorderInfo(),u=Zl.find(S=>S.value===d),h=(g=u==null?void 0:u.icon)!=null?g:r;t.next(h)});return t.next(r),s.dispose}),tooltip:"toolbar.border.main",type:I.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:_s,hoverable:!1,selectable:!1},value$:o.borderInfo$}],value$:o.borderInfo$,hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:e}}const Kr="sheet.menu.clear-selection";function Ko(n){return{id:Kr,type:I.MenuItemType.SUBITEMS,icon:"ClearFormatDoubleIcon",title:"rightClick.clearSelection",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function qo(n){return{id:m.ClearSelectionContentCommand.id,type:I.MenuItemType.BUTTON,icon:"ClearFormatDoubleIcon",title:"rightClick.clearContent",disabled$:Gt(n,$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellValuePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Qo(n){return{id:m.ClearSelectionFormatCommand.id,type:I.MenuItemType.BUTTON,icon:"ClearFormatDoubleIcon",title:"rightClick.clearFormat",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Br(n){return{id:m.ClearSelectionAllCommand.id,type:I.MenuItemType.BUTTON,icon:"ClearFormatDoubleIcon",title:"rightClick.clearAll",tooltip:"rightClick.clearAll",disabled$:Gt(n,$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellValuePermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Ql="sheet.menu.delete";function Km(n){return{id:Ql,type:I.MenuItemType.SUBITEMS,title:"rightClick.delete",icon:"ReduceDoubleIcon",hidden$:Gt(n,Bn(n)),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission]})}}function ga(n){return{id:_n.id,type:I.MenuItemType.BUTTON,icon:"DeleteColumnDoubleIcon",title:"rightClick.deleteSelectedColumn",hidden$:ql(n,"col"),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookDeleteColumnPermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetDeleteColumnPermission]})}}function Sa(n){return{id:In.id,type:I.MenuItemType.BUTTON,icon:"DeleteRowDoubleIcon",title:"rightClick.deleteSelectedRow",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookDeleteRowPermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetDeleteRowPermission]}),hidden$:ql(n,"row")}}function qm(n){return{id:Dn.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveLeft",icon:"DeleteCellShiftLeftDoubleIcon",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:Bo(n,"col")}}function Qm(n){return{id:Nt.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveUp",icon:"DeleteCellShiftUpDoubleIcon",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:Bo(n,"row")}}function Jm(n,o){const e=n.get(m.SheetsSelectionsService),t=n.get(a.IUniverInstanceService),r=n.get(a.ICommandService),i=n.get(a.IContextService);return _e(t,o,({worksheet:s})=>new O.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=Bt(n);if(h!=null){const f=(S=(g=h.ts)==null?void 0:g.fs)!=null?S:o;l.next(f)}},u=r.onCommandExecuted(h=>{const g=h.id;(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id)&&c(),(g===ve.SetTextSelectionsOperation.id||g===Q.SetInlineFormatCommand.id)&&i.getContextValue(a.EDITOR_ACTIVATED)&&i.getContextValue(a.FOCUSING_SHEET)&&d()});return c(),u.dispose}))}function $m(n){const o=a.DEFAULT_STYLES.fs,e=$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0);return{id:pr.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 eg(n){const o=$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0);return{id:Do.id,type:I.MenuItemType.BUTTON,icon:"FontSizeIncreaseIcon",tooltip:"toolbar.fontSizeIncrease",disabled$:o,hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function tg(n){const o=$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0);return{id:ko.id,type:I.MenuItemType.BUTTON,icon:"FontSizeReduceIcon",tooltip:"toolbar.fontSizeDecrease",disabled$:o,hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function ng(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 O.Observable(t=>{const r=()=>{const s=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);return s?s.getActiveSheet().getConfig().showGridlines===a.BooleanNumber.TRUE:!1},i=new a.DisposableCollection;return i.add(o.onCommandExecuted(s=>{(s.id===m.ToggleGridlinesMutation.id||s.id===m.SetWorksheetActiveOperation.id)&&t.next(r())})),i.add(e.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(()=>{t.next(r())})),t.next(r()),()=>i.dispose()}),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission]})}}const Ze=`${Yl}_MENU_ITEM_INPUT_COMPONENT`,Jl=n=>{const{prefix:o,suffix:e,value:t,min:r=Number.MIN_SAFE_INTEGER,max:i=Number.MAX_SAFE_INTEGER,disabled$:s,onChange:l}=n,c=I.useDependency(a.LocaleService),d=I.useDependency(I.IContextMenuService),[u,h]=W.useState(!1),[g,S]=W.useState(),f=v=>{if(!v){S(r.toString());return}const C=v.toString();S(C),l(C)};W.useEffect(()=>{if(!s)return;const v=s.subscribe(C=>{h(C)});return()=>{v.unsubscribe()}},[]),W.useEffect(()=>{d.visible||S(t)},[d.visible]),W.useEffect(()=>{+t<r?S(r.toString()):+t>i?S(i.toString()):S(t)},[t]);function p(){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:v=>v.stopPropagation(),children:b.jsx(j.InputNumber,{value:Number(g),size:"mini",precision:0,min:r,max:i,disabled:u,onPressEnter:p,onChange:f})}),c.t(e)]})},$l="sheet.menu.cell-insert";function rg(n){return{id:$l,type:I.MenuItemType.SUBITEMS,title:"rightClick.insert",icon:"InsertDoubleIcon",hidden$:Gt(n,Bn(n)),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission,m.WorkbookInsertColumnPermission,m.WorkbookInsertRowPermission],worksheetTypes:[m.WorksheetInsertColumnPermission,m.WorksheetInsertRowPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function og(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=1,i=$(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:Ze,props:{prefix:"rightClick.insertRowsAbove",min:1,max:1e3,suffix:"rightClick.insertRowsAboveSuffix",disabled$:i}},value$:_e(o,r,()=>new O.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=r;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$:i,hidden$:Kl(n,"row")}}function ig(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=1,i=$(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:Ze,props:{prefix:"rightClick.insertColsLeft",min:1,max:1e3,suffix:"rightClick.insertColsLeftSuffix",disabled$:i}},value$:_e(o,r,()=>new O.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=r;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$:i,hidden$:Kl(n,"col")}}function sg(n){return{id:kn.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveRight",icon:"InsertCellShiftRightDoubleIcon",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:Bo(n,"col")}}function ag(n){return{id:Vt.id,type:I.MenuItemType.BUTTON,title:"rightClick.moveDown",icon:"InsertCellDownDoubleIcon",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:Bo(n,"row")}}function lg(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=1,i=$(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:Ze,props:{prefix:"rightClick.insertRowsAfter",min:1,max:1e3,suffix:"rightClick.insertRowsAfterSuffix",disabled$:i}},value$:_e(o,r,()=>new O.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=r;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$:i,hidden$:Bn(n)}}function cg(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=1,i=$(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:Ze,props:{prefix:"rightClick.insertRowsAbove",min:1,max:1e3,suffix:"rightClick.insertRowsAboveSuffix",disabled$:i}},value$:_e(o,r,()=>new O.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=r;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$:i,hidden$:Bn(n)}}function dg(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=1,i=$(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:Ze,props:{prefix:"rightClick.insertColsLeft",min:1,max:1e3,suffix:"rightClick.insertColsLeftSuffix",disabled$:i}},value$:_e(o,r,()=>new O.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=r;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$:i,hidden$:Bn(n)}}function ug(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=1,i=$(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:Ze,props:{prefix:"rightClick.insertColsRight",min:1,max:1e3,suffix:"rightClick.insertColsRightSuffix",disabled$:i}},value$:_e(o,r,()=>new O.Observable(s=>{function l(){var h;const d=(h=e.getCurrentLastSelection())==null?void 0:h.range;let u=r;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$:i,hidden$:Bn(n)}}var ec=(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))(ec||{});function hg(n){const o=n.get(je);return{id:Nn.id,subId:Vo.id,type:I.MenuItemType.BUTTON,icon:"BrushIcon",title:"Format Painter",tooltip:"toolbar.formatPainter",activated$:new O.Observable(e=>{let t=!1;const r=o.status$.subscribe(i=>{t=i!==xe.OFF,e.next(t)});return e.next(t),()=>{r.unsubscribe()}}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetCopyPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0)}}function mg(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(a.IContextService),r=n.get(m.SheetsSelectionsService);return{id:Ft.id,type:I.MenuItemType.BUTTON,icon:"BoldIcon",title:"Set bold",tooltip:"toolbar.bold",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:_e(e,!1,({worksheet:i})=>new O.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 p=(S=r.getCurrentLastSelection())==null?void 0:S.primary;let v=a.FontWeight.NORMAL;if(p!=null){const C=i.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getFontWeight()}s.next(v===a.FontWeight.BOLD)}if((g===ve.SetTextSelectionsOperation.id||g===Q.SetInlineFormatCommand.id)&&t.getContextValue(a.EDITOR_ACTIVATED)&&t.getContextValue(a.FOCUSING_SHEET)){const p=Bt(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.bl;s.next(v===a.BooleanNumber.TRUE)}}),c=(u=r.getCurrentLastSelection())==null?void 0:u.primary;if(!i){s.next(!1);return}let d=a.FontWeight.NORMAL;if(c!=null){const h=i.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 gg(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService);return{id:jt.id,type:I.MenuItemType.BUTTON,icon:"ItalicIcon",title:"Set italic",tooltip:"toolbar.italic",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:_e(e,!1,({worksheet:i})=>new O.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 p=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let v=a.FontItalic.NORMAL;if(p!=null){const C=i.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getFontStyle()}s.next(v===a.FontItalic.ITALIC)}if((g===ve.SetTextSelectionsOperation.id||g===Q.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const p=Bt(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.it;s.next(v===a.BooleanNumber.TRUE)}}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d=a.FontItalic.NORMAL;if(c!=null){const h=i.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 Sg(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService);return{id:zt.id,type:I.MenuItemType.BUTTON,icon:"UnderlineIcon",title:"Set underline",tooltip:"toolbar.underline",activated$:_e(e,!1,({worksheet:i})=>new O.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 p=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let v;if(p!=null){const C=i.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getUnderline()}s.next(!!(v&&v.s))}if((g===ve.SetTextSelectionsOperation.id||g===Q.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const p=Bt(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.ul;s.next((v==null?void 0:v.s)===a.BooleanNumber.TRUE)}}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d;if(c!=null){const h=i.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getUnderline()}return s.next(!!(d&&d.s)),l.dispose})),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function fg(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=n.get(a.IContextService);return{id:Xt.id,type:I.MenuItemType.BUTTON,icon:"StrikethroughIcon",title:"Set strike through",tooltip:"toolbar.strikethrough",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:_e(e,!1,({worksheet:i})=>new O.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 p=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let v;if(p!=null){const C=i.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getStrikeThrough()}s.next(!!(v&&v.s))}if((g===ve.SetTextSelectionsOperation.id||g===Q.SetInlineFormatCommand.id)&&r.getContextValue(a.EDITOR_ACTIVATED)&&r.getContextValue(a.FOCUSING_SHEET)){const p=Bt(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.st;s.next((v==null?void 0:v.s)===a.BooleanNumber.TRUE)}}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d;if(c!=null){const h=i.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 pg(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=a.DEFAULT_STYLES.ff;return{id:vn.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:vn.id}}}],disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),value$:_e(e,r,({worksheet:i})=>new O.Observable(s=>{const l=()=>{var h;let d=r;const u=(h=t.getCurrentLastSelection())==null?void 0:h.primary;if(u!=null){const g=i.getCellStyle(u.startRow,u.startColumn),S=i.getDefaultCellStyleInternal(),f=i.getRowStyle(u.startRow),p=i.getColumnStyle(u.startColumn),v=a.composeStyles(S,f,p,g);v.ff&&(d=v.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 vg(n){return{id:No.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColorDoubleIcon",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Cg(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 O.Observable(r=>{var c;const i=a.DEFAULT_STYLES.cl.rgb,{isAllValuesSame:s,value:l}=t.getCellStylesProperty("cl");s?r.next((c=l==null?void 0:l.rgb)!=null?c:i):r.next(i)})}],value$:new O.Observable(r=>{const i=e.getColorFromTheme("gray.900"),s=o.onCommandExecuted(l=>{if(l.id===Cn.id){const c=l.params.value;r.next(c!=null?c:i)}});return r.next(i),s.dispose}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0)}}function Ig(n){return{id:m.ResetBackgroundColorCommand.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColorDoubleIcon",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function _g(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 O.Observable(r=>{var c;const i=a.DEFAULT_STYLES.bg.rgb,{isAllValuesSame:s,value:l}=t.getCellStylesProperty("bg");s?r.next((c=l==null?void 0:l.rgb)!=null?c:i):r.next(i)})}],value$:new O.Observable(r=>{const i=e.getColorFromTheme("primary.600"),s=o.onCommandExecuted(l=>{if(l.id===m.SetBackgroundColorCommand.id){const c=l.params.value;r.next(c!=null?c:i)}});return r.next(i),s.dispose}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const fa=[{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 bg(n){var s,l;const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=o.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET),r=t==null?void 0:t.getActiveSheet().getDefaultCellStyleInternal(),i=(s=r==null?void 0:r.ht)!=null?s:a.HorizontalAlign.LEFT;return{id:m.SetHorizontalTextAlignCommand.id,icon:(l=fa.find(c=>c.value===i))==null?void 0:l.icon,tooltip:"toolbar.horizontalAlignMode.main",type:I.MenuItemType.SELECTOR,selections:fa,value$:_e(o,i,({worksheet:c})=>new O.Observable(d=>{var S,f;const u=n.get(a.ICommandService).onCommandExecuted(p=>{var R,w;const v=p.id;if(v!==m.SetHorizontalTextAlignCommand.id&&v!==m.SetSelectionsOperation.id&&v!==m.SetWorksheetActiveOperation.id)return;const C=(R=e.getCurrentLastSelection())==null?void 0:R.primary;let _;if(C!=null){const P=c.getRange(C.startRow,C.startColumn),T=t==null?void 0:t.getActiveSheet().getComposedCellStyle(C.startRow,C.startColumn);_=(w=T==null?void 0:T.ht)!=null?w:P==null?void 0:P.getHorizontalAlignment()}d.next(_!=null?_:i)}),h=(S=e.getCurrentLastSelection())==null?void 0:S.primary;let g;if(h!=null){const p=c.getRange(h.startRow,h.startColumn),v=t==null?void 0:t.getActiveSheet().getComposedCellStyle(h.startRow,h.startColumn);g=(f=v==null?void 0:v.ht)!=null?f:p==null?void 0:p.getHorizontalAlignment()}return d.next(g!=null?g:i),u.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const pa=[{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 Rg(n){var s,l;const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=o.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET),r=t==null?void 0:t.getActiveSheet().getDefaultCellStyleInternal(),i=(s=r==null?void 0:r.vt)!=null?s:a.VerticalAlign.BOTTOM;return{id:m.SetVerticalTextAlignCommand.id,icon:(l=pa.find(c=>c.value===i))==null?void 0:l.icon,tooltip:"toolbar.verticalAlignMode.main",type:I.MenuItemType.SELECTOR,selections:pa,value$:_e(o,i,({worksheet:c})=>new O.Observable(d=>{var S,f;const u=n.get(a.ICommandService).onCommandExecuted(p=>{var R,w;const v=p.id;if(v!==m.SetVerticalTextAlignCommand.id&&v!==m.SetSelectionsOperation.id&&v!==m.SetWorksheetActiveOperation.id)return;const C=(R=e.getCurrentLastSelection())==null?void 0:R.primary;let _;if(C!=null){const P=c.getRange(C.startRow,C.startColumn),T=t==null?void 0:t.getActiveSheet().getComposedCellStyle(C.startRow,C.startColumn);_=(w=T==null?void 0:T.vt)!=null?w:P==null?void 0:P.getVerticalAlignment()}d.next(_!=null?_:i)}),h=(S=e.getCurrentLastSelection())==null?void 0:S.primary;let g;if(h!=null){const p=c.getRange(h.startRow,h.startColumn),v=t==null?void 0:t.getActiveSheet().getComposedCellStyle(h.startRow,h.startColumn);g=(f=v==null?void 0:v.vt)!=null?f:p==null?void 0:p.getVerticalAlignment()}return d.next(g!=null?g:i),u.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const va=[{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 wg(n){var s,l;const o=n.get(m.SheetsSelectionsService),e=n.get(a.IUniverInstanceService),t=e.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET),r=t==null?void 0:t.getActiveSheet().getDefaultCellStyleInternal(),i=(s=r==null?void 0:r.tb)!=null?s:a.WrapStrategy.OVERFLOW;return{id:m.SetTextWrapCommand.id,tooltip:"toolbar.textWrapMode.main",icon:(l=va.find(c=>c.value===i))==null?void 0:l.icon,type:I.MenuItemType.SELECTOR,selections:va,value$:_e(e,i,({worksheet:c})=>new O.Observable(d=>{var S,f;const u=n.get(a.ICommandService).onCommandExecuted(p=>{var R,w;const v=p.id;if(v!==m.SetTextWrapCommand.id&&v!==m.SetSelectionsOperation.id&&v!==m.SetWorksheetActiveOperation.id)return;const C=(R=o.getCurrentLastSelection())==null?void 0:R.primary;let _;if(C!=null){const P=c.getRange(C.startRow,C.startColumn),T=t==null?void 0:t.getActiveSheet().getComposedCellStyle(C.startRow,C.startColumn);_=(w=T==null?void 0:T.tb)!=null?w:P==null?void 0:P.getWrapStrategy()}d.next(_!=null?_:i)}),h=(S=o.getCurrentLastSelection())==null?void 0:S.primary;let g;if(h!=null){const p=c.getRange(h.startRow,h.startColumn),v=t==null?void 0:t.getActiveSheet().getComposedCellStyle(h.startRow,h.startColumn);g=(f=v==null?void 0:v.tb)!=null?f:p==null?void 0:p.getWrapStrategy()}return d.next(g!=null?g:i),u.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const Ca=[{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 Eg(n){const o=n.get(m.SheetsSelectionsService),e=n.get(a.IUniverInstanceService),t=0;return{id:m.SetTextRotationCommand.id,tooltip:"toolbar.textRotateMode.main",icon:Ca[0].icon,type:I.MenuItemType.SELECTOR,selections:Ca,value$:_e(e,t,({worksheet:r})=>new O.Observable(i=>{var d,u;const s=n.get(a.ICommandService).onCommandExecuted(h=>{var p,v;const g=h.id;if(g!==m.SetTextRotationCommand.id&&g!==m.SetSelectionsOperation.id&&g!==m.SetWorksheetActiveOperation.id)return;const S=(p=o.getCurrentLastSelection())==null?void 0:p.primary;let f;if(S!=null){const C=r.getRange(S.startRow,S.startColumn);f=C==null?void 0:C.getTextRotation()}(f==null?void 0:f.v)===a.BooleanNumber.TRUE?i.next("v"):i.next((v=f&&f.a)!=null?v:t)}),l=(d=o.getCurrentLastSelection())==null?void 0:d.primary;let c;if(l!=null){const h=r.getRange(l.startRow,l.startColumn);c=h==null?void 0:h.getTextRotation()}return(c==null?void 0:c.v)===a.BooleanNumber.TRUE?i.next("v"):i.next((u=c&&c.a)!=null?u:t),s.dispose})),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Nr(n){return new O.Observable(e=>e.next(!n.get(I.IClipboardInterfaceService).supportClipboard))}function un(n){return{id:Ne.name,commandId:Ne.id,type:I.MenuItemType.BUTTON,title:"rightClick.copy",icon:"CopyDoubleIcon",disabled$:$(n,{workbookTypes:[m.WorkbookCopyPermission],worksheetTypes:[m.WorksheetCopyPermission],rangeTypes:[m.RangeProtectionPermissionViewPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Jo(n){return{id:Ve.name,commandId:Ve.id,type:I.MenuItemType.BUTTON,title:"rightClick.paste",icon:"PasteSpecialDoubleIcon",disabled$:Nr(n).pipe(O.combineLatestWith($(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission,m.WorksheetSetCellValuePermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([o,e])=>o||e)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const rr="sheet.menu.paste-special";function $o(n){return{id:rr,type:I.MenuItemType.SUBITEMS,icon:"PasteSpecialDoubleIcon",title:"rightClick.pasteSpecial",hidden$:Gt(n,I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET))}}function ei(n){return{id:an.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteValue",disabled$:Nr(n).pipe(O.combineLatestWith($(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellValuePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([o,e])=>o||e)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function ti(n){return{id:ln.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteFormat",disabled$:Nr(n).pipe(O.combineLatestWith($(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellStylePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([o,e])=>o||e)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function ni(n){return{id:yt.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteColWidth",disabled$:Nr(n).pipe(O.combineLatestWith($(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetColumnStylePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([o,e])=>o||e))}}function ri(n){return{id:cn.id,type:I.MenuItemType.BUTTON,title:"rightClick.pasteBesidesBorder",disabled$:Nr(n).pipe(O.combineLatestWith($(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission,m.WorksheetSetCellValuePermission,m.WorksheetSetRowStylePermission,m.WorksheetSetColumnStylePermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([o,e])=>o||e)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Tg(n){return{id:m.SetWorksheetRowIsAutoHeightCommand.id,type:I.MenuItemType.BUTTON,icon:"AutoHeightDoubleIcon",title:"rightClick.fitContent",disabled$:$(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:Vn.id,type:I.MenuItemType.BUTTON,icon:"AutoWidthDoubleIcon",title:"rightClick.fitContent",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const tc="sheet.menu.sheet-frozen";function Mg(n){return{id:tc,type:I.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Wi="sheet.header-menu.sheet-frozen";function Ia(n){return{id:Wi,type:I.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function oi(n){return{id:nt.id,type:I.MenuItemType.BUTTON,title:"rightClick.freeze",icon:"FreezeToSelectedIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Pg(n){return{id:Tr.id,type:I.MenuItemType.BUTTON,title:"rightClick.freezeRow",icon:"FreezeRowIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function xg(n){return{id:yr.id,type:I.MenuItemType.BUTTON,title:"rightClick.freezeCol",icon:"FreezeColumnIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function ii(n){return{id:m.CancelFrozenCommand.id,type:I.MenuItemType.BUTTON,title:"rightClick.cancelFreeze",icon:"CancelFreezeIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Og(n){return{id:Sr.id,type:I.MenuItemType.BUTTON,icon:"HideDoubleIcon",title:"rightClick.hideSelectedRow",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Ag(n){return{id:fr.id,type:I.MenuItemType.BUTTON,icon:"HideDoubleIcon",title:"rightClick.hideSelectedColumn",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Dg(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=[m.SetSelectionsOperation,m.SetRowHiddenMutation,m.SetRowVisibleMutation].map(i=>i.id);return{id:m.SetSelectedRowsVisibleCommand.id,type:I.MenuItemType.BUTTON,icon:"EyeOutlineIcon",title:"rightClick.showHideRow",hidden$:_e(o,!0,({worksheet:i})=>new O.Observable(s=>{function l(){var u;const d=(u=e.getCurrentSelections())==null?void 0:u.map(h=>h.range).filter(h=>h.rangeType===a.RANGE_TYPE.ROW);return!!(d!=null&&d.some(h=>{for(let g=h.startRow;g<=h.endRow;g++)if(!i.getRowRawVisible(g))return!0;return!1}))}const c=t.onCommandExecuted(d=>{r.findIndex(u=>u===d.id)!==-1&&s.next(!l())});return s.next(!l()),()=>c.dispose()})),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetRowStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function kg(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),r=[m.SetSelectionsOperation,m.SetColHiddenMutation,m.SetColVisibleMutation].map(i=>i.id);return{id:m.SetSelectedColsVisibleCommand.id,type:I.MenuItemType.BUTTON,icon:"EyeOutlineIcon",title:"rightClick.showHideColumn",hidden$:_e(o,!0,({worksheet:i})=>new O.Observable(s=>{function l(){var u;const d=(u=e.getCurrentSelections())==null?void 0:u.map(h=>h.range).filter(h=>h.rangeType===a.RANGE_TYPE.COLUMN);return!d||d.length===0?!1:!!d.some(h=>{for(let g=h.startColumn;g<=h.endColumn;g++)if(!i.getColVisible(g))return!0;return!1})}const c=t.onCommandExecuted(d=>{r.findIndex(u=>u===d.id)!==-1&&s.next(!l())});return s.next(!l()),()=>c.dispose()})),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetColumnStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Ng(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=2;return{id:m.SetRowHeightCommand.id,type:I.MenuItemType.BUTTON,icon:"AdjustHeightDoubleIcon",label:{name:Ze,props:{prefix:"rightClick.rowHeight",suffix:"px",min:r,max:1e3}},value$:_e(e,r,({worksheet:i})=>new O.Observable(s=>{function l(){var h;const d=(h=t.getCurrentLastSelection())==null?void 0:h.primary,u=d?i.getRowHeight(d.startRow):i.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$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetRowStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Vg(n){const o=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),r=2;return{id:m.SetColWidthCommand.id,type:I.MenuItemType.BUTTON,icon:"AdjustWidthDoubleIcon",label:{name:Ze,props:{prefix:"rightClick.columnWidth",suffix:"px",min:r,max:1e3}},value$:_e(e,r,({worksheet:i})=>new O.Observable(s=>{function l(){var h;const d=(h=t.getCurrentLastSelection())==null?void 0:h.primary,u=d?i.getColumnWidth(d.startColumn):i.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$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const Ct={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),r=n.get(a.IUniverInstanceService),i=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=r.getUniverSheetInstance(l).getSheetBySheetId(c),g=[],S=[],f=il(h,u);if(f&&!o.defaultMerge&&!await i.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 p={unitId:l,subUnitId:c,ranges:a.Tools.deepClone(u)},v={unitId:l,subUnitId:c,ranges:a.Tools.deepClone(u)},C=m.RemoveMergeUndoMutationFactory(n,p),_=m.AddMergeUndoMutationFactory(n,v);if(C.ranges.length>0&&g.push({id:m.RemoveWorksheetMergeMutation.id,params:C}),g.push({id:m.AddWorksheetMergeMutation.id,params:v}),S.push({id:m.RemoveWorksheetMergeMutation.id,params:_}),C.ranges.length>0&&S.push({id:m.AddWorksheetMergeMutation.id,params:C}),f){const x=sl(n,l,h,u);g.unshift(...x.redos),S.push(...x.undos)}const R=m.AddMergeRedoSelectionsOperationFactory(n,o,u);R&&g.push(R);const w=m.AddMergeUndoSelectionsOperationFactory(n,o);w&&S.push(w);const T=n.get(m.SheetInterceptorService).onCommandExecute({id:Ct.id,params:{unitId:l,subUnitId:c,ranges:u}});return g.push(...T.redos),S.push(...T.undos),a.sequenceExecute(g,e).result?(t.pushUndoRedo({unitID:l,undoMutations:S,redoMutations:g}),!0):!1}},bs={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),r=rs(Ao.MergeAll,t);if(!(r!=null&&r.length))return!1;const s=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;const l=s.getActiveSheet();if(!l)return!1;const c=s.getUnitId(),d=l.getSheetId();return o.executeCommand(Ct.id,{selections:r,unitId:c,subUnitId:d})}},Rs={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),r=rs(Ao.MergeVertical,t);if(!(r!=null&&r.length))return!1;const s=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;const l=s.getActiveSheet();if(!l)return!1;const c=s.getUnitId(),d=l.getSheetId();return o.executeCommand(Ct.id,{value:a.Dimension.COLUMNS,selections:r,unitId:c,subUnitId:d})}},ws={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),r=rs(Ao.MergeHorizontal,t);if(!(r!=null&&r.length))return!1;const s=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;const l=s.getActiveSheet();if(!l)return!1;const c=s.getUnitId(),d=l.getSheetId();return o.executeCommand(Ct.id,{value:a.Dimension.ROWS,selections:r,unitId:c,subUnitId:d})}};function Hg(n){const o=n.get(m.SheetsSelectionsService),e=n.get(m.RangeProtectionRuleModel),t=n.get(a.IUniverInstanceService),r=n.get(m.MergeCellController),i=t.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET);return O.combineLatest([o.selectionMoveEnd$,i.pipe(O.map(s=>{var l;return(l=s==null?void 0:s.getUnitId())!=null?l:""})),i.pipe(O.switchMap(s=>{var l;return(l=s==null?void 0:s.activeSheet$)!=null?l:O.of(null)}))]).pipe(O.map(([s,l,c])=>{if(!c||!s||s.length===0)return!1;const d=c.getSheetId(),u=s.map(S=>S.range);if(r.interceptor.fetchThroughInterceptors(m.MERGE_CELL_INTERCEPTOR_CHECK)(!1,u))return!0;const g=e.getSubunitRuleList(l,d).map(S=>S.ranges).flat();if(s.length<2){const S=s[0].range;return g.some(p=>a.Rectangle.intersects(p,S)&&!a.Rectangle.contains(p,S))}for(let S=0;S<s.length;S++)for(let f=S+1;f<s.length;f++)if(a.Rectangle.intersects(s[S].range,s[f].range))return!0;return!1}))}function nc(n,o){return!!dr(n,o,a.RANGE_TYPE.ROW)}function rc(n,o){return!!dr(n,o,a.RANGE_TYPE.COLUMN)}function dr(n,o,e){return n.find(r=>{const i=r.range,{startRow:s,endRow:l,startColumn:c,endColumn:d,rangeType:u}=i;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 Wg(n){const o=Gt(n,$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellValuePermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})),e=Hg(n);return{id:Ct.id,icon:"MergeAllIcon",tooltip:"toolbar.mergeCell.main",type:I.MenuItemType.SUBITEMS,hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:o.pipe(O.combineLatestWith(e),O.map(([t,r])=>t||r))}}function Ug(n){return{id:bs.id,type:I.MenuItemType.BUTTON,title:"merge.all",icon:"MergeAllIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Lg(n){return{id:Rs.id,type:I.MenuItemType.BUTTON,title:"merge.vertical",icon:"VerticalIntegrationIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Bg(n){return{id:ws.id,type:I.MenuItemType.BUTTON,title:"merge.horizontal",icon:"HorizontalMergeIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Fg(n){return{id:m.RemoveWorksheetMergeCommand.id,type:I.MenuItemType.BUTTON,title:"merge.cancel",icon:"CancelMergeIcon",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function jg(n){const e=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),t=n.get(a.UserManagerService);return O.combineLatest([e,t.currentUser$]).pipe(O.switchMap(([r,i])=>r?r.activeSheet$.pipe(O.switchMap(s=>{if(!s)return O.of(!0);const l=n.get(m.RangeProtectionRuleModel),c=n.get(m.WorksheetProtectionRuleModel),d=n.get(m.SheetsSelectionsService);return O.merge(d.selectionMoveEnd$,l.ruleChange$,c.ruleChange$).pipe(O.map(()=>{const u=r.getUnitId(),h=s.getSheetId(),g=l.getSubunitRuleList(u,h),S=d.getCurrentSelections(),f=S==null?void 0:S.map(C=>C.range),p=g.map(C=>C.ranges).flat();if(!f)return!1;const v=c.getRule(u,h);return v!=null&&v.permissionId?!0:f==null?void 0:f.some(C=>p.some(_=>a.Rectangle.intersects(C,_)))}))})):O.of(!0)))}function zg(n){const o=n.get(a.IUniverInstanceService),e=n.get(m.RangeProtectionRuleModel),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(a.UserManagerService);return O.combineLatest([t,r.currentUser$]).pipe(O.switchMap(([i,s])=>i?i.activeSheet$.pipe(O.switchMap(l=>{if(!l)return O.of(!0);const c=n.get(m.RangeProtectionRuleModel),d=n.get(m.WorksheetProtectionRuleModel),u=n.get(a.IPermissionService),h=n.get(m.SheetsSelectionsService);return O.merge(h.selectionMoveEnd$,c.ruleChange$,d.ruleChange$).pipe(O.map(()=>{var x,A;const g=i.getUnitId(),S=l.getSheetId(),f=e.getSubunitRuleList(g,S),p=(x=h.getCurrentSelections())==null?void 0:x.map(D=>D.range);if(f.map(D=>D.ranges).flat(),!(p!=null&&p.length)||p.length>1)return!0;const v=p[0];if((v==null?void 0:v.rangeType)===a.RANGE_TYPE.ALL||(v==null?void 0:v.rangeType)===a.RANGE_TYPE.COLUMN||(v==null?void 0:v.rangeType)===a.RANGE_TYPE.ROW)return!0;const C=d.getRule(g,S);if(C!=null&&C.permissionId)return((A=u.getPermissionPoint(new m.WorksheetManageCollaboratorPermission(g,S).id))==null?void 0:A.value)===!1;if(f.filter(D=>D.ranges.some(k=>a.Rectangle.intersects(k,v))).length!==1)return!0;const{startRow:R,endRow:w,startColumn:P,endColumn:T}=v,M=n.get(m.RangeProtectionCache);for(let D=R;D<=w;D++)for(let k=P;k<=T;k++){const H=M.getCellInfo(g,S,D,k);if(H)return H[m.UnitAction.ManageCollaborator]===!1}return!1}))})):O.of(!0)))}function Xg(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(a.UserManagerService);return O.combineLatest([t,r.currentUser$]).pipe(O.switchMap(([i,s])=>i?i.activeSheet$.pipe(O.switchMap(l=>{var f;if(!l)return O.of(!0);const c=i.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(O.map(p=>p.every(v=>v.value))))!=null?f:O.of(!1),S=O.merge(u.ruleChange$,h.ruleChange$).pipe(O.startWith(null));return O.combineLatest([g,S,d.selectionMoveEnd$]).pipe(O.map(([p,v,C])=>{if(!p)return!0;const _=d.getCurrentSelections(),R=_==null?void 0:_.map(w=>w.range);return R!=null&&R.length?R.length>1:!1}))})):O.of(!0)))}function oc(n){var d;const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(a.UserManagerService),i=n.has(he)?n.get(he):null,l=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_FX_BAR_EDITOR).pipe(O.startWith(!1),O.shareReplay(1)),c=(d=i==null?void 0:i.visible$.pipe(O.startWith(null),O.shareReplay(1)))!=null?d:O.of(null);return O.combineLatest([t,r.currentUser$,c,l]).pipe(O.switchMap(([u,h,g,S])=>!u||g!=null&&g.visible&&g.unitId===u.getUnitId()||S?O.of(!0):u.activeSheet$.pipe(O.switchMap(f=>{var x;if(!f)return O.of(!0);const v=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_COMMON_DRAWINGS).pipe(O.startWith(!1)),C=u.getUnitId(),_=f.getSheetId(),R=n.get(m.RangeProtectionRuleModel),w=n.get(m.WorksheetProtectionRuleModel),P=n.get(m.SheetsSelectionsService),T=(x=e.composePermission$([new m.WorkbookCreateProtectPermission(C).id]).pipe(O.map(A=>A.every(D=>D.value))))!=null?x:O.of(!1),M=O.merge(R.ruleChange$,w.ruleChange$).pipe(O.startWith(null));return O.combineLatest([T,M,P.selectionMoveEnd$,v]).pipe(O.map(([A,D,k,H])=>{if(!A||H)return!0;const N=P.getCurrentSelections(),V=N==null?void 0:N.map(B=>B.range);if(!(V!=null&&V.length))return!0;const L=w.getRule(C,_);if(L!=null&&L.permissionId)return!0;const U=R.getSubunitRuleList(C,_);return V==null?void 0:V.some(B=>U.some(z=>z.ranges.some(X=>a.Rectangle.intersects(B,X))))}))}))))}function Yg(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(a.UserManagerService);return O.combineLatest([t,r.currentUser$]).pipe(O.switchMap(([i,s])=>i?i.activeSheet$.pipe(O.switchMap(l=>{var f;if(!l)return O.of(!0);const c=i.getUnitId(),d=l.getSheetId(),u=n.get(m.RangeProtectionRuleModel),h=n.get(m.WorksheetProtectionRuleModel),g=(f=e.composePermission$([new m.WorkbookCreateProtectPermission(c).id]).pipe(O.map(p=>p.every(v=>v.value))))!=null?f:O.of(!1),S=O.merge(u.ruleChange$,h.ruleChange$).pipe(O.startWith(null));return O.combineLatest([g,S]).pipe(O.map(([p,v])=>{var R;if(!p)return!0;const C=h.getRule(c,d);return C!=null&&C.permissionId?!0:((R=u.getSubunitRuleList(c,d))==null?void 0:R.filter(w=>w==null?void 0:w.permissionId)).length>0}))})):O.of(!0)))}function Zg(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(a.UserManagerService);return O.combineLatest([t,r.currentUser$]).pipe(O.switchMap(([i,s])=>i?i.activeSheet$.pipe(O.switchMap(l=>{if(!l)return O.of(!0);const c=i.getUnitId(),d=l.getSheetId(),u=n.get(m.WorksheetProtectionRuleModel);return u.ruleChange$.pipe(O.startWith(null)).pipe(O.map(()=>{var g;return u.getRule(c,d)?((g=e.getPermissionPoint(new m.WorksheetDeleteProtectionPermission(c,d).id))==null?void 0:g.value)===!1:!0}))})):O.of(!0)))}function Gg(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(a.UserManagerService);return O.combineLatest([t,r.currentUser$]).pipe(O.switchMap(([i,s])=>i?i.activeSheet$.pipe(O.switchMap(l=>{var f;if(!l)return O.of(!0);const c=i.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(O.map(p=>p.every(v=>v.value))))!=null?f:O.of(!1),g=u.ruleChange$.pipe(O.startWith(null)),S=d.ruleChange$.pipe(O.startWith(null));return O.combineLatest([h,g,S]).pipe(O.map(([p,v,C])=>{if(!p)return!0;const _=l.getSheetId(),R=u.getRule(c,_),w=d.getSubunitRuleList(c,_);return!(R||w.length)}))})):O.of(!0)))}function Kg(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(a.UserManagerService);return O.combineLatest([t,r.currentUser$]).pipe(O.switchMap(([i,s])=>i?i.activeSheet$.pipe(O.switchMap(l=>{if(!l)return O.of(!0);const c=i.getUnitId(),d=l.getSheetId(),u=n.get(m.SheetsSelectionsService),h=n.get(m.RangeProtectionRuleModel),g=n.get(m.WorksheetProtectionRuleModel),S=O.merge(h.ruleChange$,g.ruleChange$,u.selectionMoveEnd$).pipe(O.startWith(null));return O.combineLatest([S]).pipe(O.map(([f])=>{var A;const p=n.get(m.SheetsSelectionsService).getCurrentSelections(),v=p==null?void 0:p.map(D=>D.range);if(!(v!=null&&v.length)||v.length>1)return!0;const C=v[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((A=e.getPermissionPoint(new m.WorksheetDeleteProtectionPermission(c,d).id))==null?void 0:A.value)===!1;if(h.getSubunitRuleList(c,d).filter(D=>D.ranges.some(k=>a.Rectangle.intersects(k,C))).length!==1)return!0;const{startRow:w,endRow:P,startColumn:T,endColumn:M}=C,x=n.get(m.RangeProtectionCache);for(let D=w;D<=P;D++)for(let k=T;k<=M;k++){const H=x.getCellInfo(c,d,D,k);if(H)return H[m.UnitAction.Delete]===!1}return!1}))})):O.of(!0)))}function ic(n){var d;const o=n.get(a.IUniverInstanceService),e=n.get(a.IPermissionService),t=o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),r=n.get(a.UserManagerService),i=n.has(he)?n.get(he):null,l=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_FX_BAR_EDITOR),c=(d=i==null?void 0:i.visible$)!=null?d:O.of(null);return O.combineLatest([t,r.currentUser$,c,l]).pipe(O.switchMap(([u,h,g,S])=>!u||g!=null&&g.visible&&g.unitId===u.getUnitId()||S?O.of(!0):u.activeSheet$.pipe(O.switchMap(f=>{var C,_;if(!f)return O.of(!0);const p=u.getUnitId();return((_=(C=e.getPermissionPoint$(new m.WorkbookEditablePermission(p).id))==null?void 0:C.pipe(O.map(R=>!!R.value)))!=null?_:O.of(!1)).pipe(O.map(R=>!R))}))))}const qr="sheet.contextMenu.permission";function qg(n){return{id:Cr.id,type:I.MenuItemType.BUTTON,icon:nl,tooltip:"permission.toolbarMenu",hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:oc(n)}}function si(n){return{id:qr,type:I.MenuItemType.SUBITEMS,title:"rightClick.protectRange",icon:rl,hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function ai(n){return{id:Mt.id,type:I.MenuItemType.BUTTON,title:"rightClick.turnOnProtectRange",hidden$:jg(n),disabled$:oc(n)}}function li(n){return{id:Ot.id,type:I.MenuItemType.BUTTON,title:"rightClick.editProtectRange",disabled$:Xg(n),hidden$:zg(n)}}function ci(n){return{id:xt.id,type:I.MenuItemType.BUTTON,title:"rightClick.removeProtectRange",disabled$:Kg(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function di(n){return{id:Pt.id,type:I.MenuItemType.BUTTON,title:"rightClick.viewAllProtectArea",disabled$:ic(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Qg(n){return{id:Ir.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.addProtectSheet",disabled$:Yg(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Jg(n){return{id:xr.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.removeProtectSheet",disabled$:Zg(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function $g(n){return{id:Or.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.changeSheetPermission",disabled$:Gg(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function eS(n){return{id:_r.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.viewAllProtectArea",disabled$:ic(n),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function tS(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.ICommandService),t=new O.Observable(i=>{const s=e.onCommandExecuted(l=>{const c=l.id;(c===m.RemoveSheetMutation.id||c===m.InsertSheetMutation.id||c===m.SetWorksheetHideMutation.id)&&ao(o,i)});return ao(o,i),s.dispose}),r=Fn(n,[m.WorkbookEditablePermission,m.WorkbookDeleteSheetPermission]);return{id:Rr.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.delete",disabled$:O.combineLatest([t,r]).pipe(O.map(([i,s])=>i||s)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function nS(n){return{id:m.CopySheetCommand.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.copy",disabled$:Fn(n,[m.WorkbookEditablePermission,m.WorkbookCreateSheetPermission]),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function rS(n){return{id:Dr.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.rename",disabled$:Fn(n,[m.WorkbookEditablePermission,m.WorkbookRenameSheetPermission]),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function oS(n){return{id:m.SetTabColorCommand.id,title:"sheetConfig.changeColor",type:I.MenuItemType.SELECTOR,selections:[{label:{name:I.COLOR_PICKER_COMPONENT,hoverable:!1}}],hidden$:Fn(n,[m.WorkbookEditablePermission])}}function iS(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 O.Observable(t=>{const r=e.onCommandExecuted(i=>{const s=i.id;(s===m.RemoveSheetMutation.id||s===m.InsertSheetMutation.id||s===m.SetWorksheetHideMutation.id)&&ao(o,t)});return ao(o,t),r.dispose}).pipe(O.combineLatestWith(Fn(n,[m.WorkbookEditablePermission,m.WorkbookHideSheetPermission])),O.map(([t,r])=>t||r)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function sS(n){const o=n.get(a.IUniverInstanceService),e=n.get(a.ICommandService);return{id:Pr.id,type:I.MenuItemType.BUTTON,title:"sheetConfig.unhide",disabled$:new O.Observable(t=>{function r(){const s=o.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getWorksheets(),l=Array.from(s.values());t.next(l.length===1)}const i=e.onCommandExecuted(s=>{const l=s.id;(l===m.RemoveSheetMutation.id||l===m.InsertSheetMutation.id||l===m.SetWorksheetHideMutation.id)&&r()});return r(),i.dispose}).pipe(O.combineLatestWith(Fn(n,[m.WorkbookEditablePermission,m.WorkbookHideSheetPermission])),O.map(([t,r])=>t||r)),hidden$:I.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function ao(n,o){const e=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getWorksheets(),t=Array.from(e.values()).filter(r=>r.getConfig().hidden===a.BooleanNumber.FALSE);o.next(t.length===1)}const sc={[I.RibbonPosition.START]:{[I.RibbonStartGroup.HISTORY]:{[Nn.id]:{order:2,menuItemFactory:hg},[m.ClearSelectionAllCommand.id]:{order:3,menuItemFactory:Br}},[I.RibbonStartGroup.FORMAT]:{[vn.id]:{order:1,menuItemFactory:pg},[pr.id]:{order:2,menuItemFactory:$m},[Do.id]:{order:2.1,menuItemFactory:eg},[ko.id]:{order:2.2,menuItemFactory:tg},[Ft.id]:{order:5,menuItemFactory:mg},[jt.id]:{order:6,menuItemFactory:gg},[zt.id]:{order:7,menuItemFactory:Sg},[Xt.id]:{order:8,menuItemFactory:fg},[Cn.id]:{order:9,menuItemFactory:Cg,[m.ResetTextColorCommand.id]:{order:0,menuItemFactory:vg}},[m.SetBackgroundColorCommand.id]:{order:10,menuItemFactory:_g,[m.ResetBackgroundColorCommand.id]:{order:0,menuItemFactory:Ig}},[m.SetBorderBasicCommand.id]:{order:11,menuItemFactory:Gm}},[I.RibbonStartGroup.LAYOUT]:{[m.SetHorizontalTextAlignCommand.id]:{order:0,menuItemFactory:bg},[m.SetVerticalTextAlignCommand.id]:{order:3,menuItemFactory:Rg},[m.SetTextWrapCommand.id]:{order:6,menuItemFactory:wg},[m.SetTextRotationCommand.id]:{order:7,menuItemFactory:Eg},[m.AddWorksheetMergeCommand.id]:{order:8,menuItemFactory:Wg,[m.AddWorksheetMergeAllCommand.id]:{order:0,menuItemFactory:Ug},[m.AddWorksheetMergeVerticalCommand.id]:{order:1,menuItemFactory:Lg},[m.AddWorksheetMergeHorizontalCommand.id]:{order:2,menuItemFactory:Bg},[m.RemoveWorksheetMergeCommand.id]:{order:3,menuItemFactory:Fg}}},[I.RibbonStartGroup.OTHERS]:{[Cr.id]:{order:0,menuItemFactory:qg}}},[I.ContextMenuPosition.MAIN_AREA]:{[I.ContextMenuGroup.FORMAT]:{[Ne.name]:{order:0,menuItemFactory:un},[Ve.name]:{order:2,menuItemFactory:Jo},[rr]:{order:3,menuItemFactory:$o,[an.id]:{order:0,menuItemFactory:ei},[ln.id]:{order:1,menuItemFactory:ti},[yt.id]:{order:2,menuItemFactory:ni},[cn.id]:{order:3,menuItemFactory:ri}},[Kr]:{order:4,menuItemFactory:Ko,[m.ClearSelectionContentCommand.id]:{order:0,menuItemFactory:qo},[m.ClearSelectionFormatCommand.id]:{order:1,menuItemFactory:Qo},[m.ClearSelectionAllCommand.id]:{order:2,menuItemFactory:Br}}},[I.ContextMenuGroup.LAYOUT]:{order:1,[$l]:{order:0,menuItemFactory:rg,[m.InsertRowBeforeCommand.id]:{order:0,menuItemFactory:og},[m.InsertColBeforeCommand.id]:{order:1,menuItemFactory:ig},[kn.id]:{order:2,menuItemFactory:sg},[Vt.id]:{order:3,menuItemFactory:ag}},[Ql]:{order:0,menuItemFactory:Km,[_n.id]:{order:0,menuItemFactory:ga},[In.id]:{order:1,menuItemFactory:Sa},[Dn.id]:{order:2,menuItemFactory:qm},[Nt.id]:{order:3,menuItemFactory:Qm}},[tc]:{order:2,menuItemFactory:Mg,[nt.id]:{order:0,menuItemFactory:oi},[Tr.id]:{order:1,menuItemFactory:Pg},[yr.id]:{order:2,menuItemFactory:xg},[m.CancelFrozenCommand.id]:{order:3,menuItemFactory:ii}},[qr]:{order:3,menuItemFactory:si,[Mt.id]:{order:0,menuItemFactory:ai},[Ot.id]:{order:1,menuItemFactory:li},[xt.id]:{order:2,menuItemFactory:ci},[Pt.id]:{order:3,menuItemFactory:di}}},[I.ContextMenuGroup.DATA]:{order:2},[I.ContextMenuGroup.OTHERS]:{order:3}},[I.ContextMenuPosition.COL_HEADER]:{[I.ContextMenuGroup.FORMAT]:{[Ne.name]:{order:0,menuItemFactory:un},[Ve.name]:{order:2,menuItemFactory:Jo},[rr]:{order:3,menuItemFactory:$o,[an.id]:{order:0,menuItemFactory:ei},[ln.id]:{order:1,menuItemFactory:ti},[yt.id]:{order:2,menuItemFactory:ni},[cn.id]:{order:3,menuItemFactory:ri}},[Kr]:{order:4,menuItemFactory:Ko,[m.ClearSelectionContentCommand.id]:{order:0,menuItemFactory:qo},[m.ClearSelectionFormatCommand.id]:{order:1,menuItemFactory:Qo},[m.ClearSelectionAllCommand.id]:{order:2,menuItemFactory:Br}}},[I.ContextMenuGroup.LAYOUT]:{order:1,[m.InsertMultiColsLeftCommand.id]:{order:0,menuItemFactory:dg},[m.InsertMultiColsRightCommand.id]:{order:0,menuItemFactory:ug},[fr.id]:{order:1,menuItemFactory:Ag},[m.SetSelectedColsVisibleCommand.id]:{order:2,menuItemFactory:kg},[_n.id]:{order:2,menuItemFactory:ga},[m.SetColWidthCommand.id]:{order:3,menuItemFactory:Vg},[Vn.id]:{order:4,menuItemFactory:yg},[Wi]:{order:5,menuItemFactory:Ia,[nt.id]:{order:0,menuItemFactory:oi},[m.CancelFrozenCommand.id]:{order:3,menuItemFactory:ii}},[qr]:{order:6,menuItemFactory:si,[Mt.id]:{order:0,menuItemFactory:ai},[Ot.id]:{order:1,menuItemFactory:li},[xt.id]:{order:2,menuItemFactory:ci},[Pt.id]:{order:3,menuItemFactory:di}}},[I.ContextMenuGroup.DATA]:{order:2},[I.ContextMenuGroup.OTHERS]:{order:3}},[I.ContextMenuPosition.ROW_HEADER]:{[I.ContextMenuGroup.FORMAT]:{[Ne.name]:{order:0,menuItemFactory:un},[Ve.name]:{order:2,menuItemFactory:Jo},[rr]:{order:3,menuItemFactory:$o,[an.id]:{order:0,menuItemFactory:ei},[ln.id]:{order:1,menuItemFactory:ti},[yt.id]:{order:2,menuItemFactory:ni},[cn.id]:{order:3,menuItemFactory:ri}},[Kr]:{order:4,menuItemFactory:Ko,[m.ClearSelectionContentCommand.id]:{order:0,menuItemFactory:qo},[m.ClearSelectionFormatCommand.id]:{order:1,menuItemFactory:Qo},[m.ClearSelectionAllCommand.id]:{order:2,menuItemFactory:Br}}},[I.ContextMenuGroup.LAYOUT]:{order:1,[m.InsertMultiRowsAboveCommand.id]:{order:0,menuItemFactory:cg},[m.InsertMultiRowsAfterCommand.id]:{order:1,menuItemFactory:lg},[In.id]:{order:1,menuItemFactory:Sa},[Sr.id]:{order:2,menuItemFactory:Og},[m.SetSelectedRowsVisibleCommand.id]:{order:2,menuItemFactory:Dg},[m.SetRowHeightCommand.id]:{order:3,menuItemFactory:Ng},[m.SetWorksheetRowIsAutoHeightCommand.id]:{order:4,menuItemFactory:Tg},[Wi]:{order:5,menuItemFactory:Ia,[nt.id]:{order:0,menuItemFactory:oi},[m.CancelFrozenCommand.id]:{order:3,menuItemFactory:ii}},[qr]:{order:6,menuItemFactory:si,[Mt.id]:{order:0,menuItemFactory:ai},[Ot.id]:{order:1,menuItemFactory:li},[xt.id]:{order:2,menuItemFactory:ci},[Pt.id]:{order:3,menuItemFactory:di}}},[I.ContextMenuGroup.DATA]:{order:2},[I.ContextMenuGroup.OTHERS]:{order:3}},[I.ContextMenuPosition.FOOTER_TABS]:{[I.ContextMenuGroup.OTHERS]:{order:0,[Rr.id]:{order:0,menuItemFactory:tS},[m.CopySheetCommand.id]:{order:1,menuItemFactory:nS},[Dr.id]:{order:2,menuItemFactory:rS},[m.SetTabColorCommand.id]:{order:3,menuItemFactory:oS},[m.SetWorksheetHideCommand.id]:{order:4,menuItemFactory:iS},[Pr.id]:{order:6,menuItemFactory:sS},[Ir.id]:{order:7,menuItemFactory:Qg},[xr.id]:{order:8,menuItemFactory:Jg},[Or.id]:{order:9,menuItemFactory:$g},[_r.id]:{order:10,menuItemFactory:eS}}},[I.ContextMenuPosition.FOOTER_MENU]:{[I.ContextMenuGroup.OTHERS]:{[m.ToggleGridlinesCommand.id]:{order:1,menuItemFactory:ng}}}},ui="UNIVER_SHEET_PERMISSION_ALERT_DIALOG_ID",ac="UNIVER_SHEET_PERMISSION_ALERT_DIALOG";var aS=Object.getOwnPropertyDescriptor,lS=(n,o,e,t)=>{for(var r=t>1?void 0:t?aS(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Ke=(n,o)=>(e,t)=>o(e,t,n);exports.SheetPermissionCheckUIController=class extends a.Disposable{constructor(e,t,r,i,s,l,c,d,u){super();E(this,"disposableCollection",new a.DisposableCollection);this._commandService=e,this._univerInstanceService=t,this._permissionService=r,this._dialogService=i,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:ui,title:{title:"permission.dialog.alert"},children:{label:ac,errorMsg:e},width:320,destroyOnClose:!0,showOk:!0,onClose:()=>{this._dialogService.close(ui)},onOk:()=>{this._dialogService.close(ui)},className:"sheet-permission-user-dialog"};this._permissionService.getShowComponents()&&this._dialogService.open(t)}_getPermissionCheck(e,t){var s,l;let r=!0,i="";switch(e){case Q.InsertCommand.id:case Q.IMEInputCommand.id:if(this._contextService.getContextValue(a.FOCUSING_EDITOR_STANDALONE)===!0)break;r=this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellValuePermission,m.WorksheetEditPermission]}),i=this._localeService.t("permission.dialog.editErr");break;case Se.id:if(t.visible===!1)break;r=this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellValuePermission,m.WorksheetEditPermission]}),i=this._localeService.t("permission.dialog.editErr");break;case yt.id:r=this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission]}),i=this._localeService.t("permission.dialog.pasteErr");break;case to.id:r=this._permissionCheckByPaste(t),i=this._localeService.t("permission.dialog.pasteErr");break;case Er.id:r=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellValuePermission,m.WorksheetSetCellStylePermission]}),i=this._localeService.t("permission.dialog.commonErr");break;case m.SetBackgroundColorCommand.id:case Ft.id:case jt.id:case zt.id:case Xt.id:r=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellStylePermission,m.WorksheetEditPermission]}),i=this._localeService.t("permission.dialog.setStyleErr");break;case Ne.id:r=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookCopyPermission],rangeTypes:[m.RangeProtectionPermissionViewPoint],worksheetTypes:[m.WorksheetCopyPermission]}),i=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||(i=this._localeService.t("permission.dialog.workbookCopyErr"));break;case Oo.id:r=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[m.WorkbookCopyPermission,m.WorkbookEditablePermission],rangeTypes:[m.RangeProtectionPermissionViewPoint,m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetCopyPermission,m.WorksheetEditPermission]}),i=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||(i=this._localeService.t("permission.dialog.workbookCopyErr"));break;case dt.id:r=this._permissionCheckByAutoFillCommand(t),i=this._localeService.t("permission.dialog.autoFillErr");break}r||this._sheetPermissionCheckController.blockExecuteWithoutPermission(i)}_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,r=m.getSheetCommandTarget(this._univerInstanceService);if(!r)return!1;const{worksheet:i,unitId:s,subUnitId:l}=r;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 p=(g=(h=i.getCell(S,f))==null?void 0:h.selectionProtection)==null?void 0:g[0];if((p==null?void 0:p[J.Edit])===!1)return!0}return!1})}};exports.SheetPermissionCheckUIController=lS([Ke(0,a.ICommandService),Ke(1,a.IUniverInstanceService),Ke(2,a.IPermissionService),Ke(3,I.IDialogService),Ke(4,a.Inject(m.RangeProtectionRuleModel)),Ke(5,ft),Ke(6,a.Inject(a.LocaleService)),Ke(7,a.IContextService),Ke(8,a.Inject(m.SheetPermissionCheckController))],exports.SheetPermissionCheckUIController);var cS=Object.getOwnPropertyDescriptor,dS=(n,o,e,t)=>{for(var r=t>1?void 0:t?cS(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},wt=(n,o)=>(e,t)=>o(e,t,n);const uS="__SpreadsheetFreezeRowMainName__",hS="__SpreadsheetFreezeRowHeaderName__",mS="__SpreadsheetFreezeColumnMainName__",gS="__SpreadsheetFreezeColumnHeaderName__",hi=2,SS=.01,Yn=a.createInterceptorKey("freezePermissionCheck");exports.HeaderFreezeRenderController=class extends a.Disposable{constructor(e,t,r,i,s,l,c,d){super();E(this,"_rowFreezeHeaderRect");E(this,"_rowFreezeMainRect");E(this,"_columnFreezeHeaderRect");E(this,"_columnFreezeMainRect");E(this,"_freezeDownSubs");E(this,"_freezePointerEnterSubs");E(this,"_freezePointerLeaveSubs");E(this,"_scenePointerMoveSub");E(this,"_scenePointerUpSub");E(this,"_changeToRow",-1);E(this,"_changeToColumn",-1);E(this,"_changeToOffsetX",0);E(this,"_changeToOffsetY",0);E(this,"_activeViewport",null);E(this,"_freezeNormalHeaderColor","");E(this,"_freezeNormalMainColor","");E(this,"_freezeActiveColor","");E(this,"_freezeHoverColor","");E(this,"_lastFreeze");E(this,"interceptor",new a.InterceptorManager({FREEZE_PERMISSION_CHECK:Yn}));this._context=e,this._sheetSkeletonManagerService=t,this._commandService=r,this._selectionManagerService=i,this._scrollManagerService=s,this._themeService=l,this._sheetInterceptorService=c,this._injector=d,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._themeChangeListener(),this._interceptorCommands(),this._bindViewportScroll(),this._zoomRefresh()}_createFreeze(e=0,t){var x;const r=t!=null?t:this._getFreeze();if(r==null)return null;const i=(x=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:x.skeleton,{startRow:s,startColumn:l}=r,c=this._getPositionByIndex(s,l);if(c==null||i==null)return null;const d=this._getSheetObject(),u=d.engine,h=(u==null?void 0:u.width)||0,g=(u==null?void 0:u.height)||0,S=d.scene,{startX:f,startY:p}=c,{rowTotalHeight:v,columnTotalWidth:C,rowHeaderWidthAndMarginLeft:_,columnHeaderHeightAndMarginTop:R}=i,w=h>C+_?h:C+R,P=g>v+R?g:v+R;this._changeToRow=s,this._changeToColumn=l,this._changeToOffsetX=f,this._changeToOffsetY=p;const T=Math.max(S.scaleX,S.scaleY);let M=hi/Math.max(1,T);if(e===0){(s===-1||s===0)&&(M=M*2);const A=M;this._rowFreezeHeaderRect=new y.Rect(hS,{fill:this._freezeNormalHeaderColor,width:_,height:M,left:0,top:p-A,zIndex:3});let D=this._freezeNormalHeaderColor;(s===-1||s===0)&&(D=this._freezeNormalMainColor),this._rowFreezeMainRect=new y.Rect(uS,{fill:D,width:w*2/T,height:M,left:_,top:p-A,zIndex:3}),S.addObjects([this._rowFreezeHeaderRect,this._rowFreezeMainRect],ht)}else{(l===-1||l===0)&&(M=M*2);const A=M;this._columnFreezeHeaderRect=new y.Rect(gS,{fill:this._freezeNormalHeaderColor,width:M,height:R,left:f-A,top:0,zIndex:3});let D=this._freezeNormalHeaderColor;(l===-1||l===0)&&(D=this._freezeNormalMainColor),this._columnFreezeMainRect=new y.Rect(mS,{fill:D,width:M,height:P*2/T,left:f-A,top:R,zIndex:3}),S.addObjects([this._columnFreezeHeaderRect,this._columnFreezeMainRect],ht)}this._eventBinding(e)}_eventBinding(e=0){let t=this._rowFreezeHeaderRect,r=this._rowFreezeMainRect;e===1&&(t=this._columnFreezeHeaderRect,r=this._columnFreezeMainRect);const i=this._getSheetObject();if(i==null)return;const{scene:s}=i;if(this._freezePointerEnterSubs=new O.Subscription,this._freezePointerLeaveSubs=new O.Subscription,this._freezeDownSubs=new O.Subscription,r){const d=r.onPointerEnter$.subscribeEvent(()=>{if(!this.interceptor.fetchThroughInterceptors(Yn)(!0,null))return!1;t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),s.setCursor(y.CURSOR_TYPE.GRAB)});this._freezePointerEnterSubs.add(d);const u=r.onPointerLeave$.subscribeEvent(()=>{t==null||t.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),s.resetCursor()});this._freezePointerLeaveSubs.add(u)}if(t){const d=t.onPointerEnter$.subscribeEvent(()=>{if(!this.interceptor.fetchThroughInterceptors(Yn)(!0,null))return!1;t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),s.setCursor(y.CURSOR_TYPE.GRAB)});this._freezePointerEnterSubs.add(d);const u=t.onPointerLeave$.subscribeEvent(()=>{t==null||t.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),s.resetCursor()});this._freezePointerLeaveSubs.add(u)}const l=t==null?void 0:t.onPointerDown$.subscribeEvent(d=>{this._freezeDown(d,t,r,e)});l&&this._freezeDownSubs.add(l);const c=r==null?void 0:r.onPointerDown$.subscribeEvent(d=>{this._freezeDown(d,t,r,e)});c&&this._freezeDownSubs.add(c)}_getCurrentLastVisible(){var C,_,R,w,P,T,M;const e=this._getSheetObject();if(e==null)return;const t=(C=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:C.skeleton;if(t==null)return;const r=e.scene,i=Math.max(r.scaleX,r.scaleY),s=this._scrollManagerService.getCurrentScrollState(),l=(e.engine.height-t.columnHeaderHeight)/i,c=(e.engine.width-t.rowHeaderWidth)/i,d=(_=s==null?void 0:s.sheetViewStartRow)!=null?_:0,u=d===0?-((R=s==null?void 0:s.offsetY)!=null?R:0):t.rowHeightAccumulation[d-1]-((w=s==null?void 0:s.offsetY)!=null?w:0);let h=0,g=!1;for(let x=d,A=t.rowHeightAccumulation.length;x<A;x++)if(t.rowHeightAccumulation[x]-u>l){h=x,g=!0;break}g||(h=t.rowHeightAccumulation.length-1);const S=(P=s==null?void 0:s.sheetViewStartColumn)!=null?P:0,f=S===0?-((T=s==null?void 0:s.offsetX)!=null?T:0):t.columnWidthAccumulation[S-1]-((M=s==null?void 0:s.offsetX)!=null?M:0);let p=0,v=!1;for(let x=S,A=t.columnWidthAccumulation.length;x<A;x++)if(t.columnWidthAccumulation[x]-f>c){p=x,v=!0;break}return v||(p=t.columnWidthAccumulation.length-1),{lastRow:h,lastColumn:p}}_getActiveViewport(e){var r;const t=(r=this._getSheetObject())==null?void 0:r.scene.getViewports();return t&&t.find(i=>i.isHit(new y.Vector2(e.offsetX,e.offsetY)))||null}_freezeDown(e,t,r,i=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(Yn)(!0,null))return!1;const{scene:d}=l;d.setCursor(y.CURSOR_TYPE.GRABBING),d.disableObjectsEvent();const u=this._getCurrentLastVisible(),h=u===void 0?Number.POSITIVE_INFINITY:s.rowHeightAccumulation[u.lastRow],g=u===void 0?Number.POSITIVE_INFINITY:s.columnWidthAccumulation[u.lastColumn-1]+s.rowHeaderWidth;this._activeViewport=null;const S=this._getFreeze();S&&(this._changeToColumn=S.startColumn,this._changeToRow=S.startRow),this._scenePointerMoveSub=d.onPointerMove$.subscribeEvent(p=>{var M,x,A,D;const v=this._getActiveViewport(p),{startX:C,startY:_,row:R,column:w}=Fe(p.offsetX,p.offsetY,d,s,v||void 0,!0);if(!this.interceptor.fetchThroughInterceptors(Yn)(!0,null))return!1;d.setCursor(y.CURSOR_TYPE.GRABBING);const T=hi/Math.max(d.scaleX,d.scaleY);i===0?((M=t.transformByState({top:Math.min(_,h)-T/2}))==null||M.setProps({fill:this._freezeActiveColor}),(x=r.transformByState({top:Math.min(_,h)-T/2}))==null||x.setProps({fill:this._freezeNormalHeaderColor}),this._changeToRow=u===void 0?R:Math.min(R,u.lastRow),this._changeToOffsetY=Math.min(_,h),this._activeViewport=v):((A=t.transformByState({left:Math.min(C,g)-T/2}))==null||A.setProps({fill:this._freezeActiveColor}),(D=r.transformByState({left:Math.min(C,g)-T/2}))==null||D.setProps({fill:this._freezeNormalHeaderColor}),this._changeToColumn=u===void 0?w:Math.min(w,u.lastColumn),this._changeToOffsetX=C,this._activeViewport=v)}),this._scenePointerUpSub=d.onPointerUp$.subscribeEvent(()=>{var k,H;d.resetCursor(),d.enableObjectsEvent(),this._clearObserverEvent();const{rowHeaderWidthAndMarginLeft:p,columnHeaderHeightAndMarginTop:v}=s;i===0&&(this._changeToRow===0||this._changeToRow===-1)||i===1&&(this._changeToColumn===0||this._changeToColumn===-1)?(t.setProps({fill:this._freezeNormalHeaderColor}),r.setProps({fill:this._freezeNormalMainColor})):(t==null||t.setProps({fill:this._freezeNormalHeaderColor}),r==null||r.setProps({fill:this._freezeNormalHeaderColor}));const C=hi/Math.max(d.scaleX,d.scaleY);i===0?(this._changeToRow===0||this._changeToRow===-1)&&(t.transformByState({top:v-C}),r.transformByState({top:v-C})):(this._changeToColumn===0||this._changeToColumn===-1)&&(t.transformByState({left:p-C}),r.transformByState({left:p-C}));const _=this._scrollManagerService.getCurrentScrollState()||{sheetViewStartRow:0,sheetViewStartColumn:0},{sheetViewStartRow:R,sheetViewStartColumn:w}=_;if(w==null||R==null)return;const P=this._context.unit,T=P.getActiveSheet();if(!T)return;const M=(k=T.getConfig())==null?void 0:k.freeze;let x=(M==null?void 0:M.xSplit)||0,A=(M==null?void 0:M.ySplit)||0;const D=(H=this._activeViewport)==null?void 0:H.viewportKey;i===0&&(!D||D===y.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP||D===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP||D===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||D===y.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP?A=this._changeToRow-(M.startRow-M.ySplit):A=this._changeToRow-R,A=A<0?0:A),i===1&&(!D||D===y.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP||D===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP||D===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||D===y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT?x=this._changeToColumn-(M.startColumn-M.xSplit):x=this._changeToColumn-w,x=x<0?0:x),this._commandService.executeCommand(m.SetFrozenCommand.id,{startRow:A===0?-1:this._changeToRow,startColumn:x===0?-1:this._changeToColumn,ySplit:A,xSplit:x,unitId:P.getUnitId(),subUnitId:T.getSheetId()})})}_getViewports(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e,r=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT),i=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT),s=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP),l=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM),c=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP),d=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN),u=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP),h=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT),g=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(!(r==null||i==null||s==null||l==null||c==null||d==null||u==null||h==null||g==null))return{viewMain:d,viewMainLeftTop:u,viewMainLeft:h,viewMainTop:g,viewColumnLeft:r,viewColumnRight:i,viewRowTop:s,viewRowBottom:l,viewLeftTop:c}}_bindViewportScroll(){const e=this._getViewports();if(!e)return;const{viewRowBottom:t,viewColumnRight:r,viewMainLeft:i,viewMainTop:s}=e;this.disposeWithMe(this._scrollManagerService.validViewportScrollInfo$.subscribe(l=>{if(!l)return;const{scrollX:c,scrollY:d,viewportScrollX:u,viewportScrollY:h}=l;t.isActive&&t.updateScrollVal({scrollY:d,viewportScrollY:h}),r.isActive&&r.updateScrollVal({scrollX:c,viewportScrollX:u}),i.isActive&&i.updateScrollVal({scrollY:d,viewportScrollY:h}),s.isActive&&s.updateScrollVal({scrollX:c,viewportScrollX:u})}))}_updateViewport(e=-1,t=-1,r=0,i=0,s=3){var x;const l=(x=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:x.skeleton;if(l==null)return;const{rowHeaderWidthAndMarginLeft:c,columnHeaderHeightAndMarginTop:d}=l,u=this._getViewports();if(!u)return;const{viewMain:h,viewMainLeftTop:g,viewMainLeft:S,viewMainTop:f,viewColumnLeft:p,viewColumnRight:v,viewRowTop:C,viewRowBottom:_,viewLeftTop:R}=u;v.resizeWhenFreezeChange({left:c,top:0,height:d+1,right:0}),_.resizeWhenFreezeChange({left:0,top:d,bottom:0,width:c+1}),R.resizeWhenFreezeChange({left:0,top:0,width:c+1,height:d});let w=!0,P=!0;g.enable(),(e===-1||e===0)&&(w=!1),(t===-1||t===0)&&(P=!1);const T=l.getNoMergeCellWithCoordByIndex(e-r,t-i,!1),M=l.getNoMergeCellWithCoordByIndex(e,t,!1);if(g.disable(),f.disable(),S.disable(),C.disable(),p.disable(),g.resetPadding(),f.resetPadding(),S.resetPadding(),C.resetPadding(),p.resetPadding(),w===!1&&P===!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}),p.resizeWhenFreezeChange({left:0,top:0,height:d+1,width:0});else if(w===!0&&P===!1){const A=M.startY-T.startY;h.resizeWhenFreezeChange({left:c,top:d+A,bottom:0,right:0}),h.setPadding({startY:T.startY,endY:M.startY,startX:0,endX:0}),s&2&&this._commandService.executeCommand(He.id,{sheetViewStartRow:0,offsetY:0}),f.resizeWhenFreezeChange({left:c,top:d,height:A,right:0}),f.updateScrollVal({viewportScrollY:T.startY,rawScrollX:h.scrollX,viewportScrollX:h.viewportScrollX}),C.resizeWhenFreezeChange({left:0,top:d,width:c+1,height:A}),C.updateScrollVal({viewportScrollY:T.startY}),_.resizeWhenFreezeChange({left:0,top:d+A,bottom:0,width:c+1}),f.enable(),C.enable()}else if(w===!1&&P===!0){const A=M.startX-T.startX;h.resizeWhenFreezeChange({left:c+A,top:d,bottom:0,right:0}),h.setPadding({startX:T.startX,endX:M.startX,startY:0,endY:0}),s&1&&this._commandService.executeCommand(He.id,{sheetViewStartColumn:0,offsetX:0}),S.resizeWhenFreezeChange({left:c,top:d,width:A,bottom:0,right:0}),S.updateScrollVal({viewportScrollX:T.startX,rawScrollY:h.scrollY,viewportScrollY:h.viewportScrollY}),p.resizeWhenFreezeChange({left:c,top:0,width:A,height:d+1}),p.updateScrollVal({viewportScrollX:T.startX}),v.resizeWhenFreezeChange({left:c+A,top:0,height:d+1,right:0}),S.enable(),p.enable()}else{const A=M.startX-T.startX,D=M.startY-T.startY;h.resizeWhenFreezeChange({left:c+A,top:d+D,bottom:0,right:0}),h.setPadding({startY:T.startY,endY:M.startY,startX:T.startX,endX:M.startX}),s&&this._commandService.executeCommand(He.id,{...s&1?{sheetViewStartColumn:0,offsetX:0}:null,...s&2?{sheetViewStartRow:0,offsetY:0}:null}),S.resizeWhenFreezeChange({left:c,top:d+D,width:A,bottom:0}),S.updateScrollVal({viewportScrollX:T.startX,rawScrollY:h.scrollY,viewportScrollY:h.viewportScrollY}),f.resizeWhenFreezeChange({left:c+A,top:d,height:D,right:0}),f.updateScrollVal({viewportScrollY:T.startY,rawScrollX:h.scrollX,viewportScrollX:h.viewportScrollX}),g.resizeWhenFreezeChange({left:c,top:d,width:A,height:D}),g.updateScrollVal({viewportScrollX:T.startX,viewportScrollY:T.startY}),C.resizeWhenFreezeChange({left:0,top:d,width:c+1,height:D}),C.updateScrollVal({viewportScrollY:T.startY}),_.resizeWhenFreezeChange({left:0,top:d+D,bottom:0,width:c+1}),p.resizeWhenFreezeChange({left:c,top:0,width:A,height:d+1}),p.updateScrollVal({viewportScrollX:T.startX}),v.resizeWhenFreezeChange({left:c+A,top:0,height:d+1,right:0}),g.enable(),f.enable(),S.enable(),C.enable(),p.enable()}}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(e=>{[m.SetWorksheetActiveOperation.id,m.InsertRangeMoveDownCommand.id,m.InsertRangeMoveRightCommand.id].includes((e==null?void 0:e.commandId)||"")&&this._refreshCurrent()})))}_refreshCurrent(){const t=this._context.unit.getActiveSheet();if(!t)return;const r=t.getConfig().freeze,{startRow:i=-1,startColumn:s=-1,ySplit:l=0,xSplit:c=0}=r;this._refreshFreeze(i,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(SS).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:[]},r=this._getFreeze();if(!r)return t;const i=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<r.startRow||l.startRow+1===r.startRow&&c===a.Direction.UP){const u={...r,startRow:Math.max(1,r.startRow+d),ySplit:Math.max(1,r.ySplit+d)};return i(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<r.startColumn||l.startColumn+1===r.startColumn&&c===a.Direction.LEFT){const u={...r,startColumn:Math.max(1,r.startColumn+d),xSplit:Math.max(1,r.xSplit+d)};return i(u)}}if(e.id===m.MoveColsCommand.id){const s=this._selectionManagerService.getCurrentSelections(),{fromRange:{startColumn:l},toRange:{startColumn:c}}=e.params,d=s==null?void 0:s.filter(C=>C.range.rangeType===a.RANGE_TYPE.COLUMN&&C.range.startColumn<=l&&l<=C.range.endColumn);if(!(d!=null&&d.length))return t;const u=d[0].range,h={...u,startColumn:c,endColumn:c+u.endColumn-u.startColumn};if(!r||r.startColumn<=0||u.startColumn>=r.startColumn&&h.startColumn>=r.startColumn||u.startColumn===h.startColumn||u.endColumn<r.startColumn&&h.startColumn<r.startColumn)return t;const g=u.endColumn-u.startColumn+1,S=Math.max(Math.min(r.startColumn,u.endColumn+1)-u.startColumn,0);let f,p;h.startColumn>=r.startColumn?(f=Math.max(r.startColumn-S,1),p=Math.max(r.xSplit-S,1)):(f=r.startColumn+g-S,p=r.xSplit+g-S);const v={...r,startColumn:f,xSplit:p};return i(v)}if(e.id===m.MoveRowsCommand.id){const s=this._selectionManagerService.getCurrentSelections(),{fromRange:{startRow:l},toRange:{startRow:c}}=e.params,d=s==null?void 0:s.filter(C=>C.range.rangeType===a.RANGE_TYPE.ROW&&C.range.startRow<=l&&l<=C.range.endRow);if(!(d!=null&&d.length))return t;const u=d[0].range,h={...u,startRow:c,endRow:c+u.endRow-u.startRow};if(!r||r.startRow<=0||u.startRow>=r.startRow&&h.startRow>=r.startRow||u.startRow===h.startRow||u.endRow<r.startRow&&h.startRow<r.startRow)return t;const g=u.endRow-u.startRow+1,S=Math.max(Math.min(r.startRow,u.endRow+1)-u.startRow,0);let f,p;h.startRow>=r.startRow?(f=Math.max(r.startRow-S,1),p=Math.max(r.ySplit-S,1)):(f=r.startRow+g-S,p=r.ySplit+g-S);const v={...r,startRow:f,ySplit:p};return i(v)}if(e.id===m.RemoveColCommand.id||e.id===m.RemoveRowCommand.id){const s=e.params,l=s.range;if(l.rangeType===a.RANGE_TYPE.COLUMN&&l.startColumn<r.startColumn){const c=Math.min(r.startColumn,l.endColumn+1)-l.startColumn,d={...r,startColumn:Math.max(1,r.startColumn-c),xSplit:Math.max(1,r.xSplit-c)};return i(d)}if(s.range.rangeType===a.RANGE_TYPE.ROW&&l.startRow<r.startRow){const c=Math.min(r.startRow,l.endRow+1)-l.startRow,d={...r,startRow:Math.max(1,r.startRow-c),ySplit:Math.max(1,r.ySplit-c)};return i(d)}}return t}}))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{switch(e.id){case m.SetFrozenMutation.id:case Ye.id:{const t=this._lastFreeze,r=this._context.unit,i=r.getActiveSheet(),s=e.params,{unitId:l,subUnitId:c}=s;if(!(l===r.getUnitId()&&c===(i==null?void 0:i.getSheetId())))return;const d=i.getConfig().freeze;if(this._lastFreeze=d,d==null)return;let u=0;const{startRow:h=-1,startColumn:g=-1,ySplit:S=0,xSplit:f=0}=d;(!t||t.startRow!==h||t.ySplit!==S)&&(u|=2),(!t||t.startColumn!==g||t.xSplit!==f)&&(u|=1),s.resetScroll===!1&&(u=0),this._refreshFreeze(h,g,S,f,u)}break;case m.SetWorksheetRowHeightMutation.id:{const t=this._getFreeze(),r=t&&e.params.ranges.some(i=>i.startRow<t.startRow);e.params&&r&&this._refreshCurrent()}break;case m.SetWorksheetColWidthMutation.id:{const t=this._getFreeze();e.params&&t&&e.params.ranges.some(r=>r.startColumn<t.startColumn)&&this._refreshCurrent()}break;case m.SetWorksheetRowAutoHeightMutation.id:{const t=e.params,r=this._getFreeze();if(r&&r.startRow>-1&&t.rowsAutoHeightInfo.some(i=>i.row<r.startRow)){const i=this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._refreshCurrent(),setTimeout(()=>{i.unsubscribe()})})}}break;case m.SetColHiddenMutation.id:case m.SetColVisibleMutation.id:{const t=e.params,r=this._getFreeze(),i=t.ranges;r&&r.startColumn>-1&&i.some(s=>s.startColumn<r.startColumn)&&this._refreshCurrent()}break;case m.SetRowHiddenMutation.id:case m.SetRowVisibleMutation.id:{const t=e.params,r=this._getFreeze(),i=t.ranges;r&&r.startRow>-1&&i.some(s=>s.startRow<r.startRow)&&this._refreshCurrent()}break;case ur.id:case hr.id:this._refreshCurrent()}}))}_zoomRefresh(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;this.disposeWithMe(t.onTransformChange$.subscribeEvent(r=>{[y.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale,y.TRANSFORM_CHANGE_OBSERVABLE_TYPE.all].includes(r.type)&&this._refreshCurrent()}))}_clearObserverEvent(){var t,r;this._getSheetObject()!=null&&((t=this._scenePointerMoveSub)==null||t.unsubscribe(),(r=this._scenePointerUpSub)==null||r.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null)}_clearFreeze(){var t,r,i,s,l,c;(t=this._rowFreezeHeaderRect)==null||t.dispose(),(r=this._rowFreezeMainRect)==null||r.dispose(),(i=this._columnFreezeHeaderRect)==null||i.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 i=(d=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:d.skeleton,s=i==null?void 0:i.getNoMergeCellWithCoordByIndex(e,t);if(i==null)return;if(s!=null&&(!isNaN(s.endX)||!isNaN(s.endY)))return s;const{rowHeaderWidthAndMarginLeft:l,columnHeaderHeightAndMarginTop:c}=i;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 De(this._context.unit,this._context)}_refreshFreeze(e,t,r,i,s){var c;const l={startRow:e,startColumn:t,ySplit:r,xSplit:i};this._clearFreeze(),this._createFreeze(0,l),this._createFreeze(1,l),this._updateViewport(e,t,r,i,s),(c=this._getSheetObject())==null||c.spreadsheet.makeForceDirty()}};exports.HeaderFreezeRenderController=dS([wt(1,a.Inject(exports.SheetSkeletonManagerService)),wt(2,a.ICommandService),wt(3,a.Inject(m.SheetsSelectionsService)),wt(4,a.Inject(exports.SheetScrollManagerService)),wt(5,a.Inject(a.ThemeService)),wt(6,a.Inject(m.SheetInterceptorService)),wt(7,a.Inject(a.Injector))],exports.HeaderFreezeRenderController);var fS=Object.getOwnPropertyDescriptor,pS=(n,o,e,t)=>{for(var r=t>1?void 0:t?fS(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},mi=(n,o)=>(e,t)=>o(e,t,n);const vS="__SpreadsheetHeaderMoveControllerBackground__",CS="__SpreadsheetHeaderMoveControllerShapeLine__",IS="rgba(0, 0, 0, 0.1)",_S="rgb(119, 119, 119)",bS=4,gi=a.createInterceptorKey("headerMovePermissionCheck");exports.HeaderMoveRenderController=class extends a.Disposable{constructor(e,t,r,i){super();E(this,"_startOffsetX",Number.NEGATIVE_INFINITY);E(this,"_startOffsetY",Number.NEGATIVE_INFINITY);E(this,"_moveHelperBackgroundShape");E(this,"_moveHelperLineShape");E(this,"_headerPointerDownSubs");E(this,"_headerPointerMoveSubs");E(this,"_headerPointerLeaveSubs");E(this,"_dragHeaderMoveSub");E(this,"_scenePointerUpSub");E(this,"_scrollTimer");E(this,"_changeFromColumn",-1);E(this,"_changeFromRow",-1);E(this,"_changeToColumn",-1);E(this,"_changeToRow",-1);E(this,"interceptor",new a.InterceptorManager({HEADER_MOVE_PERMISSION_CHECK:gi}));E(this,"_workbookSelections");this._context=e,this._sheetSkeletonManagerService=r,this._commandService=i,this._workbookSelections=t.getWorkbookSelections(this._context.unitId),this._init()}dispose(){var e,t,r,i,s,l,c,d;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(t=this._moveHelperLineShape)==null||t.dispose(),(r=this._headerPointerMoveSubs)==null||r.unsubscribe(),(i=this._headerPointerLeaveSubs)==null||i.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(ue.COLUMN),r=this._context.components.get(ue.ROW),i=this._context.scene,s=e===a.RANGE_TYPE.ROW?r:t,l=u=>{var _,R;const h=(_=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:_.skeleton;if(h==null)return;const g=(R=this._workbookSelections.getCurrentLastSelection())==null?void 0:R.range;if(!g||!this.interceptor.fetchThroughInterceptors(gi)(!1,g))return;const f=this._workbookSelections.getCurrentSelections(),{row:p,column:v}=Fe(u.offsetX,u.offsetY,i,h);if(!dr(f,e===a.RANGE_TYPE.ROW?p:v,e)){i.resetCursor();return}i.setCursor(y.CURSOR_TYPE.GRAB)},c=()=>{var u,h;(u=this._moveHelperBackgroundShape)==null||u.hide(),(h=this._moveHelperLineShape)==null||h.hide(),i.resetCursor()},d=(u,h)=>{var N,V;if(h.isStopPropagation)return;const g=(N=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:N.skeleton;if(g==null)return;const S=(V=this._workbookSelections.getCurrentLastSelection())==null?void 0:V.range;if(!S||!this.interceptor.fetchThroughInterceptors(gi)(!1,S))return;const{offsetX:p,offsetY:v}=u,C=i.getCoordRelativeToViewport(y.Vector2.FromArray([p,v])),{x:_,y:R}=C;this._startOffsetX=_,this._startOffsetY=R;const{row:w,column:P}=Fe(u.offsetX,u.offsetY,i,g);let T;e===a.RANGE_TYPE.ROW?(this._changeFromRow=w,T=y.ScrollTimerType.Y):(this._changeFromColumn=P,T=y.ScrollTimerType.X);const M=this._workbookSelections.getCurrentSelections(),x=dr(M,e===a.RANGE_TYPE.ROW?w:P,e);if(!x)return;const A=i.getScrollXYInfoByViewport(y.Vector2.FromArray([this._startOffsetX,this._startOffsetY]));this._newBackgroundAndLine(),i.setCursor(y.CURSOR_TYPE.GRABBING),i.disableObjectsEvent();let D=!1,k;const H=()=>{if(D)return;k=y.ScrollTimer.create(i,T),this._scrollTimer=k;const L=i.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);k.startScroll(_,R,L),D=!0};this._dragHeaderMoveSub=i.onPointerMove$.subscribeEvent(L=>{H();const{offsetX:U,offsetY:F}=L,{x:B,y:z}=i.getCoordRelativeToViewport(y.Vector2.FromArray([U,F]));this._rowColumnMoving(B,z,x,A,e),k.scrolling(B,z,()=>{this._rowColumnMoving(B,z,x,A,e)})}),this._scenePointerUpSub=i.onPointerUp$.subscribeEvent(()=>{var U,F,B;this._disposeBackgroundAndLine(),i.resetCursor(),i.enableObjectsEvent(),this._clearObserverEvent(),(U=this._scrollTimer)==null||U.dispose();const L=this._workbookSelections.getCurrentSelections();if(e===a.RANGE_TYPE.ROW){if(this._changeFromRow!==this._changeToRow&&this._changeToRow!==-1){const X=(F=((L==null?void 0:L.filter(K=>K.range.rangeType===a.RANGE_TYPE.ROW&&K.range.startRow<=this._changeFromRow&&this._changeFromRow<=K.range.endRow))||[])[0])==null?void 0:F.range;X&&this._commandService.executeCommand(m.MoveRowsCommand.id,{fromRange:X,toRange:{...X,startRow:this._changeToRow,endRow:this._changeToRow+X.endRow-X.startRow}})}this._changeToRow=this._changeFromRow=-1}else{if(this._changeFromColumn!==this._changeToColumn&&this._changeToColumn!==-1){const X=(B=((L==null?void 0:L.filter(K=>K.range.rangeType===a.RANGE_TYPE.COLUMN&&K.range.startColumn<=this._changeFromColumn&&this._changeFromColumn<=K.range.endColumn))||[])[0])==null?void 0:B.range;X&&this._commandService.executeCommand(m.MoveColsCommand.id,{fromRange:X,toRange:{...X,startColumn:this._changeToColumn,endColumn:this._changeToColumn+X.endColumn-X.startColumn}})}this._changeToColumn=this._changeFromColumn=-1}})};this._headerPointerMoveSubs=new O.Subscription,this._headerPointerMoveSubs.add(s.onPointerMove$.subscribeEvent(l)),this._headerPointerLeaveSubs=new O.Subscription,this._headerPointerLeaveSubs.add(s==null?void 0:s.onPointerLeave$.subscribeEvent(c)),this._headerPointerDownSubs=new O.Subscription,this._headerPointerDownSubs.add(s==null?void 0:s.onPointerDown$.subscribeEvent(d))}_rowColumnMoving(e,t,r,i,s){var z,X,K,re,oe,le,Z;const l=this._context.scene,c=(z=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:z.skeleton;if(c==null)return;const{rowHeaderWidth:d,columnHeaderHeight:u,rowTotalHeight:h,columnTotalWidth:g}=c,S=l.getViewportScrollXY(l.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:f,scaleY:p}=l.getAncestorScale(),v=c.getCellIndexByOffset(e,t,f,p,S),{row:C,column:_}=v,R=c.getNoMergeCellWithCoordByIndex(C,_),{startX:w,startY:P,endX:T,endY:M}=R,x=this._sheetSkeletonManagerService.attachRangeWithCoord(r.range);if(x==null)return;const A=Math.max(f,f),{startX:D,endX:k,startY:H,endY:N,startRow:V,startColumn:L,endRow:U,endColumn:F}=x;s===a.RANGE_TYPE.ROW?(X=this._moveHelperBackgroundShape)==null||X.transformByState({height:N-H,width:g+d,left:0,top:H+(t-this._startOffsetY)/A+S.y-i.y}):(K=this._moveHelperBackgroundShape)==null||K.transformByState({height:h+u,width:k-D,left:D+(e-this._startOffsetX)/A+S.x-i.x,top:0}),(re=this._moveHelperBackgroundShape)==null||re.show();const B=bS/A;if(s===a.RANGE_TYPE.ROW){let Y=0;if(C<=V)Y=P-B/2,this._changeToRow=C;else if(C>U)Y=M-B/2,this._changeToRow=C+1;else return;(oe=this._moveHelperLineShape)==null||oe.transformByState({height:B,width:g,left:d,top:Y})}else{let Y=0;if(_<=L)Y=w-B/2,this._changeToColumn=_;else if(_>F)Y=T-B/2,this._changeToColumn=_+1;else return;(le=this._moveHelperLineShape)==null||le.transformByState({height:h,width:B,left:Y,top:u})}(Z=this._moveHelperLineShape)==null||Z.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 y.Rect(vS,{fill:IS,evented:!1,zIndex:100}),this._moveHelperLineShape=new y.Rect(CS,{fill:_S,evented:!1,zIndex:100}),e.addObjects([this._moveHelperBackgroundShape,this._moveHelperLineShape],ht)}_disposeBackgroundAndLine(){var e,t;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(t=this._moveHelperLineShape)==null||t.dispose()}};exports.HeaderMoveRenderController=pS([mi(1,a.Inject(m.SheetsSelectionsService)),mi(2,a.Inject(exports.SheetSkeletonManagerService)),mi(3,a.ICommandService)],exports.HeaderMoveRenderController);var Ui=(n=>(n[n.VERTICAL=0]="VERTICAL",n[n.HORIZONTAL=1]="HORIZONTAL",n))(Ui||{});const RS="rgba(120, 120, 120, 0.01)",Si="rgb(68, 71, 70)",$n=12,wS=44,Li=4;class _a extends y.Shape{constructor(e,t){super(e,t);E(this,"_size",$n);E(this,"_color",Si);E(this,"_mode",0);this.setShapeProps(t)}get size(){return this._size}get mode(){return this._mode}get color(){return this._color}_draw(e){const t=this.getScene();if(!t)return;const{scaleX:r,scaleY:i}=t.getAncestorScale(),s=Math.max(r,i),l=$n/s,c=Li/s;let{width:d,height:u}=this,h=0,g=0;this.mode===0?(d=c,h=l-c):(u=c,g=l-c),y.Rect.drawWith(e,{width:this.width,height:this.height,left:0,top:0,fill:RS}),y.Rect.drawWith(e,{width:d,height:u,fill:Si,radius:c}),e.save(),e.transform(1,0,0,1,h,g),y.Rect.drawWith(e,{width:d,height:u,fill:Si,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:$n,height:this.size}):this.transformByState({width:this.size,height:$n}),this}}var ES=Object.getOwnPropertyDescriptor,TS=(n,o,e,t)=>{for(var r=t>1?void 0:t?ES(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},fi=(n,o)=>(e,t)=>o(e,t,n);const yS="__SpreadsheetHeaderResizeControllerShapeRow__",MS="__SpreadsheetHeaderResizeControllerShapeColumn__",ba="__SpreadsheetHeaderResizeControllerShapeHelper__",Ra="rgb(199, 199, 199)",PS=2,pi=a.createInterceptorKey("headerResizePermissionCheck");exports.HeaderResizeRenderController=class extends a.Disposable{constructor(e,t,r,i){super();E(this,"_currentRow",0);E(this,"_currentColumn",0);E(this,"_rowResizeRect");E(this,"_columnResizeRect");E(this,"_headerPointerSubs");E(this,"_scenePointerMoveSub");E(this,"_scenePointerUpSub");E(this,"_resizeHelperShape");E(this,"_startOffsetX",Number.POSITIVE_INFINITY);E(this,"_startOffsetY",Number.POSITIVE_INFINITY);E(this,"interceptor",new a.InterceptorManager({HEADER_RESIZE_PERMISSION_CHECK:pi}));this._context=e,this._sheetSkeletonManagerService=t,this._selectionManagerService=r,this._commandService=i,this._init()}dispose(){var e,t,r;(e=this._rowResizeRect)==null||e.dispose(),this._rowResizeRect=null,(t=this._columnResizeRect)==null||t.dispose(),this._columnResizeRect=null,(r=this._headerPointerSubs)==null||r.unsubscribe(),this._headerPointerSubs=null}_init(){const e=this._context.scene;this._rowResizeRect=new _a(yS,{visible:!1,mode:Ui.HORIZONTAL,zIndex:100}),this._columnResizeRect=new _a(MS,{visible:!1,mode:Ui.VERTICAL,zIndex:100}),e.addObjects([this._rowResizeRect,this._columnResizeRect],ht),this._initialHover(0),this._initialHover(1),this._initialHoverResize(0),this._initialHoverResize(1)}_initialHover(e=0){const t=this._context.components.get(ue.COLUMN),r=this._context.components.get(ue.ROW),i=this._context.scene,s=e===0?r:t,l=(d,u)=>{var h,g;(h=this._rowResizeRect)==null||h.hide(),(g=this._columnResizeRect)==null||g.hide()},c=(d,u)=>{var A;const h=(A=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:A.skeleton;if(h==null||this._rowResizeRect==null||this._columnResizeRect==null)return;const{rowHeaderWidth:g,columnHeaderHeight:S}=h,{startX:f,startY:p,endX:v,endY:C,row:_,column:R}=Fe(d.offsetX,d.offsetY,i,h),w=nr(d.offsetX,d.offsetY,i),{scaleX:P,scaleY:T}=i.getAncestorScale(),M=Math.max(P,T),x=$n/M;if(e===0){let D=p-x/2;if(w.y<=p+x/2&&w.y>=p)this._currentRow=_-1;else if(w.y>=C-x/2&&w.y<=C)this._currentRow=_,D=C-x/2;else{this._rowResizeRect.hide();return}if(this._currentRow===-1)return;if(!this.interceptor.fetchThroughInterceptors(pi)(null,{row:this._currentRow}))return!1;const H=Math.min(wS,g/3);this._rowResizeRect.transformByState({left:g/2-H/2,top:D}),this._rowResizeRect.setShapeProps({size:H}),this._rowResizeRect.show()}else{let D=f-x/2;if(w.x<=f+x/2&&w.x>=f)this._currentColumn=R-1;else if(w.x>=v-x/2&&w.x<=v)this._currentColumn=R,D=v-x/2;else{this._columnResizeRect.hide();return}if(this._currentColumn===-1)return;if(!this.interceptor.fetchThroughInterceptors(pi)(null,{col:this._currentColumn}))return!1;const H=S*.7;this._columnResizeRect.transformByState({left:D,top:S/2-H/2}),this._columnResizeRect.setShapeProps({size:H}),this._columnResizeRect.show()}};this._headerPointerSubs=new O.Subscription,this._headerPointerSubs.add(s==null?void 0:s.onPointerMove$.subscribeEvent(c)),this._headerPointerSubs.add(s==null?void 0:s.onPointerLeave$.subscribeEvent(l))}_initialHoverResize(e=0){const t=this._context.scene,r=e===0?this._rowResizeRect:this._columnResizeRect;r!=null&&(this.disposeWithMe(r.onPointerEnter$.subscribeEvent(()=>{r!=null&&(r.show(),t.setCursor(e===0?y.CURSOR_TYPE.ROW_RESIZE:y.CURSOR_TYPE.COLUMN_RESIZE))})),this.disposeWithMe(r.onPointerLeave$.subscribeEvent(()=>{r!=null&&(r.hide(),t.resetCursor())})),this.disposeWithMe(r.onPointerDown$.subscribeEvent(i=>{var F,B,z,X,K,re,oe;const s=(F=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:F.skeleton;if(s==null)return;const l=this._context.scene,c=l.getEngine(),d=(c==null?void 0:c.height)||0,u=(c==null?void 0:c.width)||0,h=l.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=(((z=(B=h==null?void 0:h.getScrollBar())==null?void 0:B.horizonScrollTrack)==null?void 0:z.height)||0)+10,S=(((K=(X=h==null?void 0:h.getScrollBar())==null?void 0:X.verticalScrollTrack)==null?void 0:K.width)||0)+10,f=nr(i.offsetX,i.offsetY,l),{scaleX:p,scaleY:v}=l.getAncestorScale();this._startOffsetX=f.x,this._startOffsetY=f.y;const C=s.getOffsetByColumn(this._currentColumn),_=s.getOffsetByRow(this._currentRow),R=s.getNoMergeCellWithCoordByIndex(this._currentRow,this._currentColumn);let w=!1,P=0,T=0;const{columnTotalWidth:M,rowHeaderWidth:x,rowTotalHeight:A,columnHeaderHeight:D}=s,k=u>M+x?u:M+x,H=d>A+D?d:A+D,N=Math.max(p,v),V=Li/N;e===0?this._resizeHelperShape=new y.Rect(ba,{width:k,height:V,fill:Ra,left:0,top:_-V/2}):this._resizeHelperShape=new y.Rect(ba,{width:V,height:H,fill:Ra,left:C-V/2,top:0});const L=((re=this._columnResizeRect)==null?void 0:re.left)||0,U=((oe=this._rowResizeRect)==null?void 0:oe.top)||0;l.addObject(this._resizeHelperShape,ht),l.disableObjectsEvent(),this._scenePointerMoveSub=l.onPointerMove$.subscribeEvent(le=>{var fe,be,Re,ot,it,It;const Z=l.getCoordRelativeToViewport(y.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),Y=l.getScrollXYInfoByViewport(Z,h),q=nr(le.offsetX,le.offsetY,l),{x:te,y:ce}=q,{scaleX:ne,scaleY:ie}=l.getAncestorScale(),ee=Math.max(ne,ie),me=Li/ee;P=te-this._startOffsetX-me/2,T=ce-this._startOffsetY-me/2,Math.abs(e===0?T:P)>=PS&&(w=!0),e===0?(T>d-g+Y.y-R.startY&&(T=d-g+Y.y-R.startY),T<-(R.endY-R.startY)+2&&(T=-(R.endY-R.startY)+2),w&&((fe=this._resizeHelperShape)==null||fe.transformByState({top:_+T}),(be=this._rowResizeRect)==null||be.transformByState({top:U+T+me/2}),(Re=this._rowResizeRect)==null||Re.show(),l.setCursor(y.CURSOR_TYPE.ROW_RESIZE))):(P>u-S+Y.x-R.startX&&(P=u-S+Y.x-R.startX),P<-(R.endX-R.startX)+2&&(P=-(R.endX-R.startX)+2),w&&((ot=this._resizeHelperShape)==null||ot.transformByState({left:C+P}),(it=this._columnResizeRect)==null||it.transformByState({left:L+P+me/2}),(It=this._columnResizeRect)==null||It.show(),l.setCursor(y.CURSOR_TYPE.COLUMN_RESIZE)))}),this._scenePointerUpSub=l.onPointerUp$.subscribeEvent(le=>{var Y,q,te;const Z=this._context.scene;this._clearObserverEvent(),(Y=this._resizeHelperShape)==null||Y.dispose(),this._resizeHelperShape=null,Z.enableObjectsEvent(),w&&(Z.resetCursor(),(q=this._rowResizeRect)==null||q.hide(),(te=this._columnResizeRect)==null||te.hide(),e===0?this._commandService.executeCommand(m.DeltaRowHeightCommand.id,{deltaY:T,anchorRow:this._currentRow}):this._commandService.executeCommand(m.DeltaColumnWidthCommand.id,{deltaX:P,anchorCol:this._currentColumn}))})})),this.disposeWithMe(r.onDblclick$.subscribeEvent(()=>{var h,g,S;this._context.scene.resetCursor();const s=(h=this._sheetSkeletonManagerService.getCurrentParam())==null?void 0:h.skeleton;if(!s)return;const l=0,c=0,d=s.worksheet.getRowCount()-1||0,u=s.worksheet.getColumnCount()-1||0;switch(e){case 1:{const f=this._selectionManagerService.getCurrentSelections(),p=[];for(let v=0;v<f.length;v++){const C=f[v];C.range.rangeType===a.RANGE_TYPE.COLUMN&&this._currentColumn<=C.range.endColumn&&this._currentColumn>=C.range.startColumn&&p.push({startColumn:C.range.startColumn,endColumn:C.range.endColumn,startRow:l,endRow:d})}p.length===0&&p.push({startColumn:this._currentColumn,endColumn:this._currentColumn,startRow:l,endRow:d}),this._commandService.executeCommand(Vn.id,{ranges:p}),(g=this._columnResizeRect)==null||g.hide();break}case 0:this._commandService.executeCommand(m.SetWorksheetRowIsAutoHeightCommand.id,{ranges:[{startRow:this._currentRow,endRow:this._currentRow,startColumn:c,endColumn:u}]}),(S=this._rowResizeRect)==null||S.hide();break}})))}_clearObserverEvent(){var e,t;(e=this._scenePointerMoveSub)==null||e.unsubscribe(),(t=this._scenePointerUpSub)==null||t.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null}};exports.HeaderResizeRenderController=TS([fi(1,a.Inject(exports.SheetSkeletonManagerService)),fi(2,a.Inject(m.SheetsSelectionsService)),fi(3,a.ICommandService)],exports.HeaderResizeRenderController);var xS=Object.getOwnPropertyDescriptor,OS=(n,o,e,t)=>{for(var r=t>1?void 0:t?xS(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Zn=(n,o)=>(e,t)=>o(e,t,n);const AS=60;exports.SheetRenderController=class extends a.RxDisposable{constructor(e,t,r,i,s,l){super();E(this,"_renderMetric$",new O.Subject);E(this,"renderMetric$",this._renderMetric$.asObservable());E(this,"_renderFrameTimeMetric",null);E(this,"_renderFrameTags",{});E(this,"_afterRenderMetric$",new O.Subject);this._context=e,this._configService=t,this._sheetSkeletonManagerService=r,this._sheetRenderService=i,this._commandService=s,this._telemetryService=l,this._addNewRender(),this._initRenderMetricSubscriber()}_addNewRender(){const{scene:e,engine:t,unit:r}=this._context;this._addComponent(r),this._initRerenderScheduler(),this._initCommandListener();const i=this._context.unit.getActiveSheet();if(!i)throw new Error("No active sheet found");const s=i.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(i=>i.startsWith(y.SHEET_EXTENSION_PREFIX)).length>0&&this._afterRenderMetric$.next({frameTimeMetric:this._renderFrameTimeMetric,tags:this._renderFrameTags})}),e.renderFrameTimeMetric$.subscribe(([r,i])=>{this._renderFrameTimeMetric||(this._renderFrameTimeMetric={}),this._renderFrameTimeMetric[r]||(this._renderFrameTimeMetric[r]=[]),this._renderFrameTimeMetric[r].push(Math.round(i*100)/100)}),e.renderFrameTags$.subscribe(([r,i])=>{this._renderFrameTags[r]=i});const t=[];this._afterRenderMetric$.pipe(O.withLatestFrom(e.endFrame$)).subscribe(([r,i])=>{t.push({FPS:i.FPS,elapsedTime:i.elapsedTime,frameTime:Math.round(i.frameTime*100)/100,...r.frameTimeMetric,...r.tags}),t.length>AS&&(this._captureRenderMetric(t),t.length=0)})}_captureRenderMetric(e){var g;const t=e;if(t.length===0)return;const r=S=>{let f=0;const v=Object.entries(S).filter(([_,R])=>Array.isArray(R)).map(([_])=>_).reduce((_,R)=>{const w=S[R].reduce((P,T)=>P+T,0);return _[R]=w,_},{});return Object.keys(S).filter(_=>_.startsWith(y.SHEET_EXTENSION_PREFIX)).forEach(_=>{f+=v[_]}),{...v,extensionTotal:f}},i=e.map(S=>({...S,...r(S)})),l=(S=>Object.entries(S[0]).filter(([v,C])=>!["elapsedTime"].includes(v)).filter(([v,C])=>typeof C=="number").map(([v])=>v).reduce((v,C)=>{const _=S.map(T=>T[C]),R=Math.max(..._),w=Math.min(..._),P=_.reduce((T,M)=>T+M,0)/_.length;return v[C]={max:Math.round(R*100)/100,min:Math.round(w*100)/100,avg:Math.round(P*100)/100},v},{}))(i),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:r}=this._context,i=e.getActiveSheet(),s=new y.Spreadsheet(ue.MAIN);this._addViewport(i);const l=new y.SpreadsheetRowHeader(ue.ROW),c=new y.SpreadsheetColumnHeader(ue.COLUMN),d=new y.Rect(ue.LEFT_TOP,{zIndex:2,left:-1,top:-1,fill:"rgb(248, 249, 250)",stroke:"rgb(217, 217, 217)",strokeWidth:1});this._context.mainComponent=s,r.set(ue.MAIN,s),r.set(ue.ROW,l),r.set(ue.COLUMN,c),r.set(ue.LEFT_TOP,d),t.addObjects([s],As),t.addObjects([l,c,d],ht),t.enableLayerCache(As,ht)}_initViewports(e,t,r){const l=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN,e,{left:t.width,top:r.height,bottom:0,right:0,isWheelPreventDefaultX:!0,allowCache:!0,bufferEdgeX:100,bufferEdgeY:100}),c=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:0,bufferEdgeY:0}),d=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:0,bufferEdgeY:100}),u=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:100,bufferEdgeY:0}),h=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP,e,{active:!1,isWheelPreventDefaultX:!0}),g=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM,e,{left:0,top:r.height,bottom:0,width:t.width+1,isWheelPreventDefaultX:!0}),S=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT,e,{active:!1,isWheelPreventDefaultX:!0}),f=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT,e,{left:t.width,top:0,height:r.height+1,right:0,isWheelPreventDefaultX:!0}),p=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP,e,{left:0,top:0,width:t.width,height:r.height,isWheelPreventDefaultX:!0});return{viewMain:l,viewLeftTop:p,viewMainLeftTop:c,viewMainLeft:d,viewMainTop:u,viewColumnLeft:S,viewRowTop:h,viewRowBottom:g,viewColumnRight:f}}_addViewport(e){const t=this._context.scene,{rowHeader:r,columnHeader:i}=e.getConfig(),{viewMain:s}=this._initViewports(t,r,i),l=this._configService.getConfig(Ee),c=l==null?void 0:l.scrollConfig;return new y.ScrollBar(s,c),t.attachControl(),s}_initRerenderScheduler(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(!e)return null;const{skeleton:t,sheetId:r}=e,i=this._context.unit,s=i==null?void 0:i.getSheetBySheetId(r);if(i==null||s==null)return;const{mainComponent:l,components:c}=this._context,d=l,u=c.get(ue.ROW),h=c.get(ue.COLUMN),g=c.get(ue.LEFT_TOP),{rowHeaderWidth:S,columnHeaderHeight:f}=t;d==null||d.updateSkeleton(t),u==null||u.updateSkeleton(t),h==null||h.updateSkeleton(t),g==null||g.transformByState({width:S,height:f})}))}_initCommandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{const{unit:t}=this._context,{id:r}=e;if(m.COMMAND_LISTENER_SKELETON_CHANGE.includes(r)||this._sheetRenderService.checkMutationShouldTriggerRerender(r)){const i=e.params,{unitId:s,subUnitId:l}=i,c=t.getActiveSheet();if(!c)return;const d=this._context.unitId,u=c.getSheetId();if(s!==d||l!==u)return;this._sheetSkeletonManagerService.makeDirty({sheetId:u,commandId:r},!0),this._sheetSkeletonManagerService.setCurrent({sheetId:u,commandId:r})}else m.COMMAND_LISTENER_VALUE_CHANGE.includes(r)&&this._sheetSkeletonManagerService.reCalculate();e.type===a.CommandType.MUTATION&&this._markUnitDirty(e)}))}_markUnitDirty(e){if(e.id.substring(0,3)==="doc")return;const{mainComponent:t,scene:r}=this._context;if(e.id===G.SetFormulaCalculationNotificationMutation.id&&e.params.stageInfo!=null||(t&&t.makeDirty(),r.makeDirty(),!e.params))return;const i=e.params,s=this._spreadsheetViewports(r);if(e.id===m.SetRangeValuesMutation.id&&i.cellValue){const l=this._cellValueToRange(i.cellValue),c=this._rangeToBounds([l]);this._markViewportDirty(s,c),t.setDirtyArea(c)}if(e.id===m.MoveRangeMutation.id&&i.from&&i.to){const l=i.fromRange||this._cellValueToRange(i.from.value),c=i.toRange||this._cellValueToRange(i.to.value),d=this._rangeToBounds([l,c]);this._markViewportDirty(s,d),t.setDirtyArea(d)}}_cellValueToRange(e){let t=0,r=0,i=0,s=0;for(const[h,g]of Object.entries(e)){for(const S in g)t>Number(S)&&(t=Number(S)),r<Number(S)&&(r=Number(S));i>Number(h)&&(i=Number(h)),s<Number(h)&&(s=Number(h))}return{startRow:i,endRow:s,startColumn:t,endColumn:r}}_rangeToBounds(e){const t=this._sheetSkeletonManagerService.getCurrentParam().skeleton,{rowHeightAccumulation:r,columnWidthAccumulation:i,rowHeaderWidth:s,columnHeaderHeight:l}=t,c=[];for(const d of e){const{startRow:u,endRow:h,startColumn:g,endColumn:S}=d,f=u===0?0:r[u-1]+l,p=r[h]+l,v=g===0?0:i[g-1]+s,C=i[S]+s;c.push({top:f,left:v,bottom:p,right:C,width:C-v,height:p-f})}return c}_markViewportDirty(e,t){const r=e.filter(i=>i.isActive&&i.cacheBound);for(const i of r)for(const s of t)a.Rectangle.hasIntersectionBetweenTwoRect(i.cacheBound,s)&&i.markDirty(!0)}_spreadsheetViewports(e){return e.getViewports().filter(t=>["viewMain","viewMainLeftTop","viewMainTop","viewMainLeft"].includes(t.viewportKey))}};exports.SheetRenderController=OS([Zn(1,a.Inject(a.IConfigService)),Zn(2,a.Inject(exports.SheetSkeletonManagerService)),Zn(3,a.Inject(exports.SheetsRenderService)),Zn(4,a.ICommandService),Zn(5,a.Optional(pd.ITelemetryService))],exports.SheetRenderController);const DS=({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"})]}),kS=({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"})]}),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.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"})]}),VS=({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"})]}),HS=({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"})]}),WS=({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"})}),US=({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"})]}),LS=({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"})]}),BS=({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"})]}),FS=({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"})}),jS=({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 wa(n){const{type:o=a.BorderStyleTypes.THIN,className:e}=n;switch(o){case a.BorderStyleTypes.DASH_DOT:return b.jsx(DS,{className:e});case a.BorderStyleTypes.DASH_DOT_DOT:return b.jsx(kS,{className:e});case a.BorderStyleTypes.DASHED:return b.jsx(NS,{className:e});case a.BorderStyleTypes.HAIR:return b.jsx(HS,{className:e});case a.BorderStyleTypes.MEDIUM:return b.jsx(WS,{className:e});case a.BorderStyleTypes.MEDIUM_DASH_DOT:return b.jsx(US,{className:e});case a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT:return b.jsx(LS,{className:e});case a.BorderStyleTypes.MEDIUM_DASHED:return b.jsx(BS,{className:e});case a.BorderStyleTypes.THICK:return b.jsx(FS,{className:e});case a.BorderStyleTypes.DOUBLE:return b.jsx(VS,{className:e});case a.BorderStyleTypes.THIN:default:return b.jsx(jS,{className:e})}}const zS=[{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 YS(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 lc(n){var g;const o=I.useDependency(I.ComponentManager),e=I.useDependency(m.BorderStyleManagerService),t=I.useDependency(m.SheetsSelectionsService),{isAllValuesSame:r,value:i}=t.getCellStylesProperty("bd"),s=r?XS(i):void 0,l=r?YS(i):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:Zl.map(S=>b.jsx("a",{className:j.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(j.Separator,{}),b.jsxs("div",{className:"univer-flex univer-items-center univer-gap-2",children:[b.jsx("div",{children:b.jsx(j.Dropdown,{overlay:b.jsx("div",{className:"univer-rounded-lg univer-p-4",children:b.jsx(j.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(Il,{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(j.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:zS.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(Zt,{className:"univer-absolute univer-left-3 univer-text-primary-600"}),b.jsx(wa,{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(wa,{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 Es="sheets.component.cell-popup";var ZS=Object.getOwnPropertyDescriptor,GS=(n,o,e,t)=>{for(var r=t>1?void 0:t?ZS(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Et=(n,o)=>(e,t)=>o(e,t,n);exports.SheetCanvasPopManagerService=class extends a.Disposable{constructor(e,t,r,i,s,l,c){super();E(this,"_popupMenuFeatureMap",new Map);E(this,"_isSelectionMoving",!1);this._globalPopupManagerService=e,this._renderManagerService=t,this._univerInstanceService=r,this._refRangeService=i,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,r,i){const s=this._popupMenuFeatureMap.get(i);if(s)return s(e,t,r,i)}dispose(){super.dispose(),this._popupMenuFeatureMap.clear()}_createHiddenRectObserver(e){const{row:t,column:r,worksheet:i,skeleton:s,currentRender:l}=e,c=()=>{var z,X;const g=i.getFreeze(),{startRow:S,startColumn:f,xSplit:p,ySplit:v}=g,C=S-v,_=f-p,{rowHeightAccumulation:R,columnWidthAccumulation:w,rowHeaderWidth:P,columnHeaderHeight:T}=s,M=P+(_===-1?0:w[_+p-1]-((z=w[_-1])!=null?z:0)),x=T+(C===-1?0:R[C+v-1]-((X=R[C])!=null?X:0)),A=l.engine.getCanvasElement(),D=A.getBoundingClientRect(),k=vi(A.style.width),H=D.width/k,N=l.scene.getAncestorScale().scaleX,V=M*H*N,L=x*H*N,U={left:-1/0,top:-1/0,right:D.left+V,bottom:D.top+L},F={left:D.left+V,top:-1/0,right:1/0,bottom:D.top+L},B={left:-1/0,top:D.top+L,right:D.left+V,bottom:1/0};return t<S&&r<f?[]:t<S?[U]:r<f?[U]:[U,F,B]},d=c(),u=new O.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(O.throttleTime(16)).subscribe(()=>{u.next(c())})),{rects$:u,disposable:h}}_createPositionObserver(e,t,r,i){const s=()=>{const{scene:u}=t,h=uh(e,u,r,i),g=t.engine.getCanvasElement(),S=g.getBoundingClientRect(),f=vi(g.style.width),p=S.width/f;return{left:h.left*p+S.left,right:h.right*p+S.left,top:h.top*p+S.top,bottom:h.bottom*p+S.top}},l=s(),c=new O.BehaviorSubject(l),d=new a.DisposableCollection;return d.add(this._commandService.onCommandExecuted(u=>{Ci(u.id)&&c.next(s())})),{position:l,position$:c,disposable:d}}attachPopupToObject(e,t){var R;const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),i=r.getActiveSheet();if(!i||this._isSelectionMoving&&!t.showOnSelectionMoving)return{dispose:()=>{},canDispose:()=>!0};const s=r.getUnitId(),l=i.getSheetId(),c=(R=this._renderManagerService.getRenderById(s))==null?void 0:R.with(exports.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:p,position$:v,disposable:C}=this._createPositionObserver(f,d,c,i),_=this._globalPopupManagerService.addPopup({...t,unitId:s,subUnitId:l,anchorRect:p,anchorRect$:v,canvasElement:d.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(_),v.complete(),C.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==_}}attachPopupByPosition(e,t,r){var C;let i=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=i.getActiveSheet();if(!s)return null;const l=i.getUnitId(),c=s.getSheetId();if(l!==r.unitId||r.subUnitId!==c)return null;if(this._isSelectionMoving&&!t.showOnSelectionMoving)return;const d=(C=this._renderManagerService.getRenderById(l))==null?void 0:C.with(exports.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:p}=this._createHiddenRectObserver({row:r.row,column:r.col,worksheet:s,skeleton:d,currentRender:u}),v=this._globalPopupManagerService.addPopup({...t,unitId:l,subUnitId:c,anchorRect:h,anchorRect$:g,hiddenRects$:f,canvasElement:u.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(v),g.complete(),S.dispose(),p.dispose(),i=null,s=null},canDispose:()=>this._globalPopupManagerService.activePopupId!==v}}attachPopupToAbsolutePosition(e,t,r,i){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(r&&c!==r||i&&i!==d)return null;const u=(f=this._renderManagerService.getRenderById(c))==null?void 0:f.with(exports.SheetSkeletonManagerService).ensureSkeleton(d),h=this._renderManagerService.getRenderById(c);if(!h||!u)return null;if(this._isSelectionMoving&&!t.showOnSelectionMoving)return;const g=new O.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,r,i,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(i&&u!==i||s&&h!==s)return null;const g=this._renderManagerService.getRenderById(u),S=g==null?void 0:g.with(exports.SheetSkeletonManagerService).ensureSkeleton(h),f=g==null?void 0:g.with(Ce);if(!g||!S||!f)return null;if(this._isSelectionMoving&&!r.showOnSelectionMoving)return;const p=l!=null?l:ta(e,t,g.scene,d);if(!p)return null;const{position:v,position$:C,disposable:_,updateRowCol:R}=this._createCellPositionObserver(e,t,g,S,p),{rects$:w,disposable:P}=this._createHiddenRectObserver({row:e,column:t,worksheet:d,skeleton:S,currentRender:g}),T=this._globalPopupManagerService.addPopup({...r,unitId:u,subUnitId:h,anchorRect:v,anchorRect$:C,canvasElement:g.engine.getCanvasElement(),hiddenRects$:w}),M=new a.DisposableCollection;M.add(_),M.add(a.toDisposable(()=>{this._globalPopupManagerService.removePopup(T),C.complete()})),M.add(P);const x={startRow:e,endRow:e,startColumn:t,endColumn:t};return M.add(this._refRangeService.watchRange(u,h,x,(A,D)=>{D?R(D.startRow,D.startColumn):M.dispose()})),{dispose(){M.dispose(),d=null,c=null},canDispose:()=>this._globalPopupManagerService.activePopupId!==T}}attachRangePopup(e,t,r,i,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(r&&u!==r||i&&h!==i)return null;const g=this._renderManagerService.getRenderById(u),S=g==null?void 0:g.with(exports.SheetSkeletonManagerService).getOrCreateSkeleton({sheetId:h}),f=g==null?void 0:g.with(Ce);if(!g||!S||!f)return null;if(f.selectionMoving&&!l)return;const p=s!=null?s:ta(e.startRow,e.startColumn,g.scene,d);if(!p)return null;const{position:v,position$:C,disposable:_,updateRange:R,topLeftPos$:w,rightBottomPos$:P}=this._createRangePositionObserver(e,g,S,p),{rects$:T,disposable:M}=this._createHiddenRectObserver({row:e.startRow,column:e.startColumn,worksheet:d,skeleton:S,currentRender:g}),x=this._globalPopupManagerService.addPopup({...t,unitId:u,subUnitId:h,anchorRect:v,anchorRect$:C,canvasElement:g.engine.getCanvasElement(),hiddenRects$:T}),A=new a.DisposableCollection;A.add(_),A.add(a.toDisposable(()=>{this._globalPopupManagerService.removePopup(x),w.complete(),P.complete()})),A.add(M);const D={...e};return A.add(this._refRangeService.watchRange(u,h,D,(k,H)=>{H?R(H):A.dispose()})),{dispose(){A.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==x}}_createCellPositionObserver(e,t,r,i,s){let l=e,c=t;const d=this._calcCellPositionByCell(l,c,r,i,s),u=new O.BehaviorSubject(d),h=()=>u.next(this._calcCellPositionByCell(l,c,r,i,s)),g=new a.DisposableCollection;return g.add(r.engine.clientRect$.subscribe(()=>h())),g.add(a.fromEventSubject(r.engine.onTransformChange$).pipe(O.throttleTime(16)).subscribe(()=>h())),g.add(this._commandService.onCommandExecuted(f=>{if(f.id===m.SetWorksheetRowAutoHeightMutation.id&&f.params.rowsAutoHeightInfo.findIndex(v=>v.row===l)>-1){h();return}Ci(f.id)&&h()})),{position$:u,disposable:g,position:d,updateRowCol:(f,p)=>{l=f,c=p,h()}}}_calcCellPositionByCell(e,t,r,i,s){const{scene:l,engine:c}=r;if(i._disposed||l._disposed)return{left:0,right:0,top:0,bottom:0};const d=i.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 p=f.getBoundingClientRect(),v=vi(f.style.width),{top:C,left:_,width:R}=p,w=R/v;return{left:(u.startX-S.x)*w*h+_,right:(u.endX-S.x)*w*h+_,top:(u.startY-S.y)*w*g+C,bottom:(u.endY-S.y)*w*g+C}}_createRangePositionObserver(e,t,r,i){let{startRow:s,startColumn:l,endRow:c,endColumn:d}=e;const u=this._calcCellPositionByCell(s,l,t,r,i),h=new O.BehaviorSubject(u),g=this._calcCellPositionByCell(c,d,t,r,i),S=new O.BehaviorSubject(g),f=()=>{const R=this._calcCellPositionByCell(s,l,t,r,i),w=this._calcCellPositionByCell(c,d,t,r,i);h.next(R),S.next(w)},p=new a.DisposableCollection;p.add(t.engine.clientRect$.subscribe(()=>f())),p.add(this._commandService.onCommandExecuted(R=>{if(R.id===m.SetWorksheetRowAutoHeightMutation.id&&R.params.rowsAutoHeightInfo.findIndex(P=>P.row===s)>-1){f();return}Ci(R.id)&&f()}));const v=R=>{s=R.startRow,l=R.startColumn,c=R.endRow,d=R.endColumn,f()},C=h.pipe(O.map(R=>{const w=this._calcCellPositionByCell(c,d,t,r,i);return{top:R.top,left:R.left,right:w.right,bottom:w.bottom}})),_={top:u.top,left:u.left,right:g.right,bottom:g.bottom};return{position$:C,position:_,updateRange:v,topLeftPos$:h,rightBottomPos$:S,disposable:p}}};exports.SheetCanvasPopManagerService=GS([Et(0,a.Inject(I.ICanvasPopupService)),Et(1,y.IRenderManagerService),Et(2,a.IUniverInstanceService),Et(3,a.Inject(m.RefRangeService)),Et(4,a.ICommandService),Et(5,m.IRefSelectionsService),Et(6,a.Inject(m.SheetsSelectionsService))],exports.SheetCanvasPopManagerService);function vi(n){return Number.parseInt(n.replace("px",""))}const KS=new Set([rt.id,Ye.id,m.SetSelectionsOperation.id]);function Ci(n){return KS.has(n)||m.COMMAND_LISTENER_SKELETON_CHANGE.includes(n)}var qS=Object.getOwnPropertyDescriptor,QS=(n,o,e,t)=>{for(var r=t>1?void 0:t?qS(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},JS=(n,o)=>(e,t)=>o(e,t,n);exports.CellPopupManagerService=class extends a.Disposable{constructor(e){super();E(this,"_cellPopupMap",new Map);E(this,"_change$",new O.Subject);E(this,"change$",this._change$.asObservable());this._sheetCanvasPopManagerService=e}_ensureCellPopupMap(e,t){let r=this._cellPopupMap.get(e);r||(r=new Map,this._cellPopupMap.set(e,r));let i=r.get(t);return i||(i=new a.ObjectMatrix,r.set(t,i)),i}showPopup(e,t){var g,S;const{direction:r="horizontal"}=t,{unitId:i,subUnitId:s,row:l,col:c}=e,d=this._ensureCellPopupMap(i,s),u=(g=d.getValue(l,c))==null?void 0:g[r];t.id=(S=t.id)!=null?S:a.generateRandomId();const h=()=>{var C;const f=d.getValue(l,c);if(!f)return;const p=f[r];if(!p)return;const v=p==null?void 0:p.popups.findIndex(_=>_.id===t.id&&_.componentKey===t.componentKey);p==null||p.popups.splice(v,1),p.popups.length===0&&((C=p.disposable)==null||C.dispose(),f[r]=void 0),this._change$.next({...e,direction:r})};if(u)u.popups.push(t),u.popups.sort((f,p)=>f.priority-p.priority);else{const f=this._sheetCanvasPopManagerService.attachPopupToCell(l,c,{...t,direction:r,componentKey:Es,extraProps:{...e,direction:r},noPushMinimumGap:!0,autoRelayout:!1,zIndex:90},i,s);d.setValue(l,c,{...d.getValue(l,c),[r]:{disposable:f,popups:[t]}})}return this._change$.next({...e,direction:r}),a.toDisposable(h)}getPopups(e,t,r,i,s){var c,d;return((d=(c=this._ensureCellPopupMap(e,t).getValue(r,i))==null?void 0:c[s])==null?void 0:d.popups)||[]}hidePopup(e,t,r,i){var c,d;const s=this._ensureCellPopupMap(e,t),l=s.getValue(r,i);l&&(l.horizontal&&((c=l.horizontal.disposable)==null||c.dispose(),l.horizontal=void 0,this._change$.next({unitId:e,subUnitId:t,row:r,col:i,direction:"horizontal"})),l.vertical&&((d=l.vertical.disposable)==null||d.dispose(),l.vertical=void 0,this._change$.next({unitId:e,subUnitId:t,row:r,col:i,direction:"vertical"})),!l.horizontal&&!l.vertical&&s.realDeleteValue(r,i))}};exports.CellPopupManagerService=QS([JS(0,a.Inject(exports.SheetCanvasPopManagerService))],exports.CellPopupManagerService);const cc=n=>{const{popup:o}=n,e=o.extraProps,{row:t,col:r,direction:i,unitId:s,subUnitId:l}=e,c=I.useDependency(exports.CellPopupManagerService);I.useObservable(W.useMemo(()=>c.change$.pipe(O.filter(h=>h.row===t&&h.col===r&&h.direction===i)),[c,t,r,i]));const d=c.getPopups(s,l,t,r,i),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})})},Ea=n=>{const{inputId:o,state:e=!1,type:t="range",confirm:r,cancel:i,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),p=I.useDependency(G.IDefinedNamesService),v=I.useDependency(G.IFunctionService),C=I.useDependency(G.LexerTreeBuilder),_=I.useDependency(I.ComponentManager),R=W.useMemo(()=>_.get(Zi),[]),w=W.useMemo(()=>_.get(Mo),[]);if(S==null)return;const P=W.useMemo(()=>S.getUnitId(),[]),T=W.useMemo(()=>S.getActiveSheet().getSheetId(),[]),[M,x]=W.useState(s),[A,D]=W.useState(l),[k,H]=W.useState(c),[N,V]=W.useState(d),[L,U]=W.useState(""),[F,B]=W.useState(t),[z,X]=W.useState(!0),K=[{label:f.t("definedName.scopeWorkbook"),value:m.SCOPE_WORKBOOK_VALUE_DEFINED_NAME}],re=ne=>!G.isReferenceStrings(ne);W.useEffect(()=>{X(!0),x(s),H(c),V(d);let ne=l;l.substring(0,1)===G.operatorToken.EQUALS?B("formula"):re(l)?(B("formula"),ne=G.operatorToken.EQUALS+l):B("range"),D(ne),U("")},[e]),S.getSheetOrders().forEach(ne=>{const ie=S.getSheetBySheetId(ne);K.push({label:(ie==null?void 0:ie.getName())||"",value:ne})});const oe=ne=>{D(ne)},le=ne=>{D(ne||"")},Z=()=>{if(M.length===0){U(f.t("definedName.nameEmpty"));return}if(p.getValueByName(P,M)!=null&&(h==null||h.length===0)){U(f.t("definedName.nameDuplicate"));return}if(!a.Tools.isValidParameter(M)||G.isReferenceStringWithEffectiveColumn(M)||!a.Tools.isStartValidPosition(M)&&!y.hasCJKText(M.substring(0,1))){U(f.t("definedName.nameInvalid"));return}if(S.getSheetOrders().map(ee=>{var me;return((me=S.getSheetBySheetId(ee))==null?void 0:me.getName())||""}).includes(M)){U(f.t("definedName.nameSheetConflict"));return}if(A.length===0){U(f.t("definedName.formulaOrRefStringEmpty"));return}if(!z){U(f.t("definedName.formulaOrRefStringInvalid"));return}if(v.hasExecutor(M.toUpperCase())){U(f.t("definedName.nameConflict"));return}const ie=S.getActiveSheet().getName();r&&r({id:h||"",name:M,formulaOrRefString:C.convertRefersToAbsolute(A,a.AbsoluteRefType.ALL,a.AbsoluteRefType.ALL,ie),comment:k,localSheetId:N})},Y=ne=>{const ie=ne;ie==="formula"?l[0]===G.operatorToken.EQUALS?D(l):D(`${G.operatorToken.EQUALS}`):l[0]===G.operatorToken.EQUALS?D(""):D(l),B(ie)},q=W.useRef(null),[te,ce]=W.useState(!1);return I.useSidebarClick(ne=>{var ee;((ee=q.current)==null?void 0:ee.isClickOutSide(ne))&&ce(!1)}),b.jsxs("div",{className:j.clsx("univer-grid univer-space-y-2 univer-pb-1",j.borderBottomClassName,{"univer-hidden":!e}),children:[b.jsx("div",{children:b.jsx(j.Input,{className:"univer-w-full",placeholder:f.t("definedName.inputNamePlaceholder"),value:M,allowClear:!0,onChange:x})}),b.jsx("div",{children:b.jsxs(j.RadioGroup,{value:F,onChange:Y,children:[b.jsx(j.Radio,{value:"range",children:f.t("definedName.ratioRange")}),b.jsx(j.Radio,{value:"formula",children:f.t("definedName.ratioFormula")})]})}),F==="range"?R&&b.jsx(R,{unitId:P,subUnitId:T,initialValue:A,onChange:(ne,ie)=>oe(ie),supportAcrossSheet:!0}):w&&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(w,{ref:q,className:j.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",j.borderClassName),initValue:A,unitId:P,subUnitId:T,isFocus:te,isSupportAcrossSheet:!0,onChange:(ne="")=>{le(ne||"")},onVerify:ne=>{X(ne)},onFocus:()=>ce(!0)})})}),b.jsx("div",{children:b.jsx(j.Select,{className:"univer-w-full",value:N,options:K,onChange:V})}),b.jsx("div",{children:b.jsx(j.Input,{className:"univer-w-full",placeholder:f.t("definedName.inputCommentPlaceholder"),value:k,onChange:H,allowClear:!0})}),b.jsxs("div",{className:j.clsx("univer-items-center univer-gap-1 univer-text-sm univer-text-red-500",{"univer-hidden":L.length===0,"univer-flex":L.length!==0}),children:[b.jsx("span",{children:L}),b.jsx(hs,{})]}),b.jsxs("div",{className:"univer-flex univer-gap-2",children:[b.jsx(j.Button,{onClick:()=>{i==null||i()},children:f.t("definedName.cancel")}),b.jsx(j.Button,{variant:"primary",onClick:Z,children:f.t("definedName.confirm")})]})]})},dc=()=>{const n=I.useDependency(a.ICommandService),e=I.useDependency(a.IUniverInstanceService).getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET),t=I.useDependency(a.LocaleService),r=I.useDependency(G.IDefinedNamesService),i=I.useDependency(m.SheetsSelectionsService);if(e==null)return;const s=e.getUnitId(),l=()=>{const k=r.getDefinedNameMap(s);return k?Array.from(Object.values(k)):[]},[c,d]=W.useState(!1),[u,h]=W.useState(l()),[g,S]=W.useState(null),[f,p]=W.useState();W.useEffect(()=>{const k=r.update$.subscribe(()=>{h(l())});return()=>{k.unsubscribe()}},[]);const v=k=>{const{name:H,formulaOrRefString:N,comment:V,localSheetId:L,hidden:U}=k;let F=k.id;if(F==null||F.length===0)F=a.generateRandomId(10),n.executeCommand(m.InsertDefinedNameCommand.id,{id:F,unitId:s,name:H,formulaOrRefString:N,comment:V,localSheetId:L,hidden:U});else{const B={id:F,unitId:s,name:H,formulaOrRefString:N,comment:V,localSheetId:L,hidden:U};n.executeCommand(m.SetDefinedNameCommand.id,B)}d(!1),S(null)},C=k=>{p(k)};function _(){p(null)}function R(k){const H=r.getValueById(s,k);n.executeCommand(m.RemoveDefinedNameCommand.id,{...H,unitId:s}),p(null)}const w=async k=>{const{formulaOrRefString:H,id:N}=k,V=r.getWorksheetByRef(s,H);if(!V)return;V.isSheetHidden()&&await n.executeCommand(m.SetWorksheetShowCommand.id,{unitId:s,subUnitId:V.getSheetId()}),r.focusRange(s,N)},P=()=>{const k=u.length+1,H=t.t("definedName.defaultName")+k;if(r.getValueByName(s,H)==null)return H;let N=k+1;for(;;){const V=t.t("definedName.defaultName")+N;if(r.getValueByName(s,V)==null)return V;N++}},T=()=>{var V;const k=(V=e.getActiveSheet())==null?void 0:V.getName();if(!k)return"";const H=i.getCurrentSelections();return H==null?"":H.map(L=>G.serializeRangeWithSheet(k,L.range)).join(",")},M=()=>{d(!1),S(null)},x=()=>{d(!0),S(null)},A=k=>{d(!1),S(k)},D=k=>{const H=e.getSheetBySheetId(k);return H==null?"":H.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:j.clsx("univer-w-full univer-overflow-hidden univer-overflow-y-auto",j.scrollbarClassName),children:[b.jsxs("div",{className:"univer-mb-4",children:[b.jsxs(j.Button,{className:j.clsx("univer-w-full",{"univer-hidden":c}),onClick:x,children:[b.jsx(ms,{}),b.jsx("span",{className:"univer-ml-1",children:t.t("definedName.addButton")})]}),c&&b.jsx(Ea,{confirm:v,cancel:M,state:c,inputId:"insertDefinedName",name:P(),formulaOrRefString:T()})]},"insertDefinedName"),u.map((k,H)=>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:j.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":k.id===g}),onClick:()=>{w(k)},children:[b.jsxs("div",{title:k.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:[k.name,b.jsx("span",{className:"univer-text-xxs univer-ml-1 univer-text-gray-400",children:k.localSheetId===m.SCOPE_WORKBOOK_VALUE_DEFINED_NAME||k.localSheetId==null?"":D(k.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:k.formulaOrRefString,children:k.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(j.Tooltip,{title:t.t("definedName.updateButton"),placement:"top",children:b.jsx("a",{className:"univer-rounded univer-p-1 hover:univer-bg-gray-100",onClick:N=>{N.stopPropagation(),A(k.id)},children:b.jsx(fl,{})})}),b.jsx(j.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:N=>{N.stopPropagation(),C(k.id)},children:b.jsx(Lo,{})})})]})]}),b.jsx(j.Confirm,{visible:f===k.id,onClose:_,onConfirm:()=>{R(k.id)},children:t.t("definedName.deleteConfirmText")}),k.id===g&&b.jsx(Ea,{confirm:v,cancel:M,state:k.id===g,id:k.id,inputId:k.id+H,name:k.name,formulaOrRefString:k.formulaOrRefString,comment:k.comment,localSheetId:k.localSheetId})]},H))]})})},uc={id:m.SetRowHiddenCommand.id,preconditions:n=>se(n),binding:I.KeyCode.Digit9|I.MetaKeys.CTRL_COMMAND},hc={id:m.SetColHiddenCommand.id,preconditions:n=>se(n),binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT},mc={id:Me.id,description:"shortcut.sheet.select-below-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN,priority:100,preconditions:se,staticParameters:{direction:a.Direction.DOWN}},gc={id:Me.id,description:"shortcut.sheet.select-up-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP,priority:100,preconditions:se,staticParameters:{direction:a.Direction.UP}},Sc={id:Me.id,description:"shortcut.sheet.select-left-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT,priority:100,preconditions:za,staticParameters:{direction:a.Direction.LEFT}},fc={id:Me.id,description:"shortcut.sheet.select-right-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT,priority:100,preconditions:za,staticParameters:{direction:a.Direction.RIGHT}},pc={id:Xe.id,description:"shortcut.sheet.select-next-cell",group:"3_sheet-view",binding:I.KeyCode.TAB,priority:100,preconditions:se,staticParameters:{direction:a.Direction.RIGHT,keycode:I.KeyCode.TAB}},vc={id:Xe.id,description:"shortcut.sheet.select-previous-cell",group:"3_sheet-view",binding:I.KeyCode.TAB|I.MetaKeys.SHIFT,priority:100,preconditions:se,staticParameters:{direction:a.Direction.LEFT,keycode:I.KeyCode.TAB}},Cc={id:Xe.id,description:"shortcut.sheet.select-below-cell",group:"3_sheet-view",binding:I.KeyCode.ENTER,priority:100,preconditions:se,staticParameters:{direction:a.Direction.DOWN,keycode:I.KeyCode.ENTER}},Ic={id:Xe.id,description:"shortcut.sheet.select-up-cell",group:"3_sheet-view",binding:I.KeyCode.ENTER|I.MetaKeys.SHIFT,priority:100,preconditions:se,staticParameters:{direction:a.Direction.UP,keycode:I.KeyCode.ENTER}},_c={id:Me.id,description:"shortcut.sheet.select-below-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN|I.MetaKeys.CTRL_COMMAND,preconditions:se,staticParameters:{direction:a.Direction.DOWN,jumpOver:ze.moveGap}},bc={id:Me.id,description:"shortcut.sheet.select-up-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP|I.MetaKeys.CTRL_COMMAND,preconditions:se,staticParameters:{direction:a.Direction.UP,jumpOver:ze.moveGap}},Rc={id:Me.id,description:"shortcut.sheet.select-left-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT|I.MetaKeys.CTRL_COMMAND,preconditions:se,staticParameters:{direction:a.Direction.LEFT,jumpOver:ze.moveGap}},wc={id:Me.id,description:"shortcut.sheet.select-right-value-cell",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT|I.MetaKeys.CTRL_COMMAND,preconditions:se,staticParameters:{direction:a.Direction.RIGHT,jumpOver:ze.moveGap}},Ec={id:Oe.id,description:"shortcut.sheet.expand-selection-down",group:"3_sheet-view",binding:I.KeyCode.ARROW_DOWN|I.MetaKeys.SHIFT,preconditions:se,staticParameters:{direction:a.Direction.DOWN}},Tc={id:Oe.id,description:"shortcut.sheet.expand-selection-up",group:"3_sheet-view",binding:I.KeyCode.ARROW_UP|I.MetaKeys.SHIFT,preconditions:se,staticParameters:{direction:a.Direction.UP}},yc={id:Oe.id,description:"shortcut.sheet.expand-selection-left",group:"3_sheet-view",binding:I.KeyCode.ARROW_LEFT|I.MetaKeys.SHIFT,preconditions:se,staticParameters:{direction:a.Direction.LEFT}},Mc={id:Oe.id,description:"shortcut.sheet.expand-selection-right",group:"3_sheet-view",binding:I.KeyCode.ARROW_RIGHT|I.MetaKeys.SHIFT,preconditions:se,staticParameters:{direction:a.Direction.RIGHT}},Pc={id:Oe.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:se,staticParameters:{direction:a.Direction.DOWN,jumpOver:ze.moveGap}},xc={id:Oe.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:se,staticParameters:{direction:a.Direction.UP,jumpOver:ze.moveGap}},Oc={id:Oe.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:se,staticParameters:{direction:a.Direction.LEFT,jumpOver:ze.moveGap}},Ac={id:Oe.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:se,staticParameters:{direction:a.Direction.RIGHT,jumpOver:ze.moveGap}},Dc={id:Mr.id,description:"shortcut.sheet.select-all",group:"3_sheet-view",binding:I.KeyCode.A|I.MetaKeys.CTRL_COMMAND,preconditions:se,staticParameters:{expandToGapFirst:!0,loop:!0}},kc={id:Ft.id,description:"shortcut.sheet.set-bold",group:"4_sheet-edit",preconditions:n=>se(n),binding:I.KeyCode.B|I.MetaKeys.CTRL_COMMAND},Nc={id:jt.id,description:"shortcut.sheet.set-italic",group:"4_sheet-edit",preconditions:n=>se(n),binding:I.KeyCode.I|I.MetaKeys.CTRL_COMMAND},Vc={id:zt.id,description:"shortcut.sheet.set-underline",group:"4_sheet-edit",preconditions:n=>se(n),binding:I.KeyCode.U|I.MetaKeys.CTRL_COMMAND},Hc={id:Xt.id,description:"shortcut.sheet.set-strike-through",group:"4_sheet-edit",preconditions:n=>se(n),binding:I.KeyCode.X|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND},Wc={id:m.ClearSelectionContentCommand.id,preconditions:n=>se(n),binding:I.KeyCode.DELETE,mac:I.KeyCode.BACKSPACE},Uc={id:m.ClearSelectionContentCommand.id,preconditions:n=>se(n),mac:I.KeyCode.DELETE},Lc={id:m.ClearSelectionContentCommand.id,preconditions:n=>se(n),binding:I.MetaKeys.SHIFT+I.KeyCode.BACKSPACE},Bc={id:Oo.id,preconditions:n=>se(n),binding:I.MetaKeys.SHIFT+I.KeyCode.DELETE},Fc={id:Hn.id,description:"shortcut.sheet.zoom-in",binding:I.KeyCode.EQUAL|I.MetaKeys.CTRL_COMMAND,group:"3_sheet-view",preconditions:se,priority:1,staticParameters:{delta:.2}},jc={id:a.NilCommand.id,binding:I.KeyCode.EQUAL|I.MetaKeys.CTRL_COMMAND},zc={id:Hn.id,description:"shortcut.sheet.zoom-out",binding:I.KeyCode.MINUS|I.MetaKeys.CTRL_COMMAND,group:"3_sheet-view",preconditions:se,priority:1,staticParameters:{delta:-.2}},Xc={id:a.NilCommand.id,binding:I.KeyCode.MINUS|I.MetaKeys.CTRL_COMMAND},Yc={id:Hn.id,description:"shortcut.sheet.reset-zoom",binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND,preconditions:se,group:"3_sheet-view",priority:1,staticParameters:{reset:!0}},Zc={id:a.NilCommand.id,binding:I.KeyCode.Digit0|I.MetaKeys.CTRL_COMMAND};var $S=Object.getOwnPropertyDescriptor,ef=(n,o,e,t)=>{for(var r=t>1?void 0:t?$S(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},st=(n,o)=>(e,t)=>o(e,t,n);exports.SheetUIController=class extends a.Disposable{constructor(o,e,t,r,i,s,l,c){super(),this._injector=o,this._componentManager=e,this._layoutService=t,this._commandService=r,this._shortcutService=i,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(Ze,Jl)),this.disposeWithMe(o.register(_s,lc)),this.disposeWithMe(o.register(lr,dc)),this.disposeWithMe(o.register(Es,cc)),this.disposeWithMe(o.register("HideGridlinesDoubleIcon",fs))}_initCommands(){[bs,Ct,ws,Rs,Hn,Oe,Me,Xe,Dr,Rr,In,_n,Sr,fr,He,as,Mr,Ho,m.SetBoldCommand,Wt,Se,Ar,Ft,jt,zt,Xt,os,is,pr,Do,ko,vn,Cn,No,m.SetItalicCommand,m.SetStrikeThroughCommand,m.SetFontFamilyCommand,m.SetFontSizeCommand,wr,Vo,Nn,Er,rt,Rn,nt,Tr,yr,Wo,m.SetUnderlineCommand,Wn,Ye,Pr,br,Vt,Nt,kn,Dn,Uo,dt,Sn,Be,ls,Cr,Mt,Pt,Ir,_r,Or,xt,Ot,xr,Vn,ur,hr].forEach(o=>{this.disposeWithMe(this._commandService.registerCommand(o))})}_initMenus(){this._menuManagerService.mergeMenu(sc)}_initShortcuts(){[mc,gc,Sc,fc,pc,vc,Cc,Ic,_c,bc,Rc,wc,Ec,Tc,yc,Mc,Pc,xc,Oc,Ac,Dc,Fc,zc,Yc,Zc,jc,Xc,kc,Nc,Vc,Hc,Wc,Uc,Lc,Bc,...xl(),Al,Ol,Dl,Vl,Hl,Wl,Ll,kl,Nl,Ul,uc,hc].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(yl,e))),this.disposeWithMe(o.registerComponent(I.BuiltInUIPart.FOOTER,()=>I.connectInjector(Tl,e))),this.disposeWithMe(o.registerComponent(I.BuiltInUIPart.CONTENT,()=>I.connectInjector(Cs,e)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(a.UniverInstanceType.UNIVER_SHEET,o=>{const e=this._injector.get(y.IRenderManagerService),t=this._injector.get(a.IUniverInstanceService),r=y.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_DOC,t,e),i=r==null?void 0:r.with(Q.DocSelectionRenderService);i==null||i.focus()}))}};exports.SheetUIController=ef([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)],exports.SheetUIController);var tf=Object.getOwnPropertyDescriptor,nf=(n,o,e,t)=>{for(var r=t>1?void 0:t?tf(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},nn=(n,o)=>(e,t)=>o(e,t,n);const rf=a.createInterceptorKey("statusBarPermissionCorrect");class of{constructor(){E(this,"_sum",0);E(this,"_count",0);E(this,"_countNumber",0);E(this,"_min",Number.POSITIVE_INFINITY);E(this,"_max",Number.NEGATIVE_INFINITY)}add(o,e,t){if(!a.Tools.isDefine(o==null?void 0:o.v))return;const r=o==null?void 0:o.t;let{v:i}=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 i=="string"&&r===a.CellValueType.NUMBER){const c=Number(i);Number.isNaN(c)||(i=c)}if(typeof i=="number"&&r!==a.CellValueType.STRING)s(i);else if(r===a.CellValueType.NUMBER&&o.s){const c=e.get(o.s);l(c,i,t)}this._count++}getResults(){return{sum:this._sum,count:this._countNumber,countA:this._count,min:this._min,max:this._max}}}function sf(n){const{sum:o,count:e,countA:t,min:r,max:i}=n.getResults();return[{func:G.FUNCTION_NAMES_STATISTICAL.MAX,value:i},{func:G.FUNCTION_NAMES_STATISTICAL.MIN,value:r},{func:G.FUNCTION_NAMES_MATH.SUM,value:o},{func:G.FUNCTION_NAMES_STATISTICAL.COUNTA,value:t},{func:G.FUNCTION_NAMES_STATISTICAL.COUNT,value:e},{func:G.FUNCTION_NAMES_STATISTICAL.AVERAGE,value:o/e}]}exports.StatusBarController=class extends a.Disposable{constructor(e,t,r,i,s,l){super();E(this,"interceptor",new a.InterceptorManager({STATUS_BAR_PERMISSION_CORRECT:rf}));this._univerInstanceService=e,this._selectionManagerService=t,this._statusBarService=r,this._commandService=i,this._numfmtService=s,this._formulaDataModel=l,this._init()}_init(){this._registerSelectionListener()}_registerSelectionListener(){const e=a.debounce(r=>{var s;const i=(s=r[r.length-1])==null?void 0:s.primary;this._calculateSelection(r.map(l=>l.range),i)},100),t=a.debounce(r=>{var s;const i=(s=r[r.length-1])==null?void 0:s.primary;this._calculateSelection(r.map(l=>l.range),i)},500);this.disposeWithMe(a.toDisposable(this._selectionManagerService.selectionMoving$.subscribe(r=>{r&&t(r)}))),this.disposeWithMe(a.toDisposable(this._selectionManagerService.selectionMoveEnd$.subscribe(r=>{r&&e(r)}))),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===m.SetRangeValuesMutation.id){const i=this._selectionManagerService.getCurrentSelections();i&&e(i)}}))}_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,r,i){var c,d,u,h;const s=r.getCellRaw(e,t),l=(c=i==null?void 0:i[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 r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!r)return this._clearResult();const i=r.getUnitId(),s=r.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(T=>{const{startRow:M,endRow:x}=T;let A=null;for(let D=M;D<=x;D++)s.getRowVisible(D)?A===null&&(A=D):A!==null&&(h.push({...T,startRow:A,endRow:D-1}),A=null);A!==null&&h.push({...T,startRow:A,endRow:x})});const g=a.splitIntoGrid(h),S=new of,f=r.getStyles(),p={},v=this._formulaDataModel.getArrayFormulaCellData(),C=(d=v==null?void 0:v[i])==null?void 0:d[l];for(const T of g){const{startRow:M,startColumn:x,endColumn:A,endRow:D}=this.getRangeStartEndInfo(T,s);for(let k=M;k<=D;k++)for(let H=x;H<=A;H++){const N=this._getCellValue(k,H,s,C);S.add(N,f,p)}}const _=sf(S);if(_.every(T=>T===void 0))return;let R=null;if(t){const{actualRow:T,actualColumn:M}=t;R=(u=this._numfmtService.getValue(i,l,T,M))==null?void 0:u.pattern}const P={values:_.filter(T=>T!==void 0),pattern:R};this._statusBarService.setState(P)}else this._clearResult()}};exports.StatusBarController=nf([nn(0,a.IUniverInstanceService),nn(1,a.Inject(m.SheetsSelectionsService)),nn(2,kr),nn(3,a.ICommandService),nn(4,a.Inject(m.INumfmtService)),nn(5,a.Inject(G.FormulaDataModel))],exports.StatusBarController);const Gc=(n=[])=>{const o=I.useDependency(Lt);W.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 af=Object.getOwnPropertyDescriptor,lf=(n,o,e,t)=>{for(var r=t>1?void 0:t?af(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Ta=(n,o)=>(e,t)=>o(e,t,n);let En=class extends a.Disposable{constructor(o,e){super();E(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,r)=>{if(t.id===m.RemoveSheetMutation.id)return this._adjustActiveSheetOnRemoveSheet(t);if(t.id===m.SetWorksheetHideMutation.id&&t.params.hidden)return this._adjustActiveSheetOnHideSheet(t);if(r!=null&&r.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,r=this._univerInstanceService.getUniverSheetInstance(e);if(!r||((c=r.getActiveSheet())==null?void 0:c.getSheetId())!==t)return;const s=r.getActiveSheetIndex(),l=ya(r,s);this._switchToNextSheet(e,l)}_beforeAdjustActiveSheetOnRemoveSheet(o){const{unitId:e,subUnitId:t}=o.params,r=this._univerInstanceService.getUniverSheetInstance(e);if(!r)return;const i=r.getSheetBySheetId(t);i&&(this._previousSheetIndex=r.getSheetIndex(i))}_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 i=this._previousSheetIndex,s=i>=1?i-1:0,l=ya(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 r;const{unitId:e,subUnitId:t}=o.params;t!==((r=this._univerInstanceService.getUnit(e))==null?void 0:r.getActiveSheet().getSheetId())&&this._switchToNextSheet(e,t)}_switchToNextSheet(o,e){this._commandService.executeCommand(m.SetWorksheetActiveOperation.id,{unitId:o,subUnitId:e})}};En=lf([Ta(0,a.ICommandService),Ta(1,a.IUniverInstanceService)],En);function ya(n,o){const e=n.getSheetSize();for(let t=o;t>-1;t--){const r=n.getSheetByIndex(t);if(!r.getConfig().hidden)return r.getSheetId()}for(let t=o;t<e;t++){const r=n.getSheetByIndex(t);if(!r.getConfig().hidden)return r.getSheetId()}throw new Error("[ActiveWorksheetController]: could not find the next unhidden sheet! Collaboration error perhaps.")}var cf=Object.getOwnPropertyDescriptor,df=(n,o,e,t)=>{for(var r=t>1?void 0:t?cf(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Ma=(n,o)=>(e,t)=>o(e,t,n),hn=(n=>(n[n.INFO=0]="INFO",n[n.WARNING=1]="WARNING",n[n.ERROR=2]="ERROR",n))(hn||{});exports.CellAlertManagerService=class extends a.Disposable{constructor(e,t){super();E(this,"_currentAlert$",new O.Subject);E(this,"_currentAlert",new Map);E(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:r}=e,{row:i,col:s,unitId:l,subUnitId:c}=r;if(!this._renderManagerService.getRenderById(l))return;const u=this._cellPopupManagerService.showPopup({unitId:l,subUnitId:c,row:i,col:s},{componentKey:Kc,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()))}};exports.CellAlertManagerService=df([Ma(0,y.IRenderManagerService),Ma(1,a.Inject(exports.CellPopupManagerService))],exports.CellAlertManagerService);function uf({popup:n}){var s;const o=(s=n.extraProps)==null?void 0:s.alert;if(!o)return null;const{type:e,title:t,message:r}=o,i={[hn.ERROR]:b.jsx(hs,{className:"univer-mr-1.5 univer-text-red-500"}),[hn.INFO]:b.jsx(Sl,{className:"univer-mr-1.5 univer-text-blue-500"}),[hn.WARNING]:b.jsx(vl,{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?i[e]:null,t]}),b.jsx("div",{className:"univer-text-sm",children:r})]})}const Kc="univer.sheet.cell-alert";var hf=Object.getOwnPropertyDescriptor,mf=(n,o,e,t)=>{for(var r=t>1?void 0:t?hf(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},gf=(n,o)=>(e,t)=>o(e,t,n);let lo=class extends a.Disposable{constructor(n,o){super(),this._context=n,this._componentManager=o,this._initComponent()}_initComponent(){this.disposeWithMe(this._componentManager.register(Kc,uf))}};lo=mf([gf(1,a.Inject(I.ComponentManager))],lo);var Sf=Object.getOwnPropertyDescriptor,ff=(n,o,e,t)=>{for(var r=t>1?void 0:t?Sf(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Pa=(n,o)=>(e,t)=>o(e,t,n);let co=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(O.filter(n=>n.visible)).subscribe(()=>{const n=this._editorBridgeService.getEditLocation();n&&this._cellPopupManagerService.hidePopup(n.unitId,n.sheetId,n.row,n.column)}))}};co=ff([Pa(1,he),Pa(2,a.Inject(exports.CellPopupManagerService))],co);var pf=Object.getOwnPropertyDescriptor,vf=(n,o,e,t)=>{for(var r=t>1?void 0:t?pf(o,e):o,i=n.length-1,s;i>=0;i--)(s=n[i])&&(r=s(r)||r);return r},Fr=(n,o)=>(e,t)=>o(e,t,n);let Tn=class extends a.Disposable{constructor(o,e,t,r){super();E(this,"_isPointer",!1);this._hoverManagerService=o,this._instanceService=e,this._commandService=t,this._renderManagerService=r,this._initPointerEvent(),this._initHover()}get _mainComponent(){var o;return(o=y.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(y.CURSOR_TYPE.POINTER),this._isPointer=!0):(this._isPointer&&((t=this._mainComponent)==null||t.setCursor(y.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})}))}};Tn=vf([Fr(0,a.Inject(exports.HoverManagerService)),Fr(1,a.IUniverInstanceService),Fr(2,a.ICommandService),Fr(3,y.IRenderManagerService)],Tn);const xa=2,Cf=[{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"}],If=n=>{var k,H,N,V,L;const o=I.useDependency(a.IUniverInstanceService),e=I.useDependency(y.IRenderManagerService),t=vt();if(!n||!t)return null;const r={startRow:n.rows[0],startCol:n.cols[0],endRow:n.rows[n.rows.length-1],endCol:n.cols[n.cols.length-1]};if(r.endRow<0||r.endCol<0)return null;const i=e.getRenderById(t.getUnitId()),s=i==null?void 0:i.with(exports.SheetSkeletonManagerService),l=i==null?void 0:i.with(Ce),c=De(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),p=(k=d.getEngine())==null?void 0:k.getCanvas();if(!g||!d||!g||!S||!f)return null;const v=u==null?void 0:u.getNoMergeCellPositionByIndex(r.endRow,r.endCol),C=(H=v==null?void 0:v.endX)!=null?H:0,_=(N=v==null?void 0:v.endY)!=null?N:0,R=(V=y.convertTransformToOffsetX(C,g,f))!=null?V:-9999,w=(L=y.convertTransformToOffsetY(_,S,f))!=null?L:-9999,P=p==null?void 0:p.getWidth(),T=p==null?void 0:p.getHeight();if(!P||!T)return null;const M=R+50<=P,x=w+50<=T;let A=R,D=w;return M||(A=P-100),x||(D=T-100),{positionX:A,positionY:D}},_f=()=>{const n=I.useDependency(ke),o=I.useObservable(n.showMenu$,!1),e=I.useObservable(n.pasteOptionsCache$,null),t=I.useDependency(a.LocaleService),r=I.useDependency(a.ICommandService),[i,s]=W.useState(!1),[l,c]=W.useState(!1),d=e==null?void 0:e.target.pastedRange,u=If(d);if(!u||!o||u.positionX<50||u.positionY<30)return null;const h=i||l,g=S=>{c(!1),r.executeCommand(Ka.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+xa,top:u.positionY+xa},onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),children:b.jsx(j.DropdownMenu,{align:"start",items:Cf.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:j.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",j.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-800":l,"univer-bg-white dark:!univer-bg-gray-900":!l}),children:[b.jsx(_l,{className:"univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-white"}),h&&b.jsx(wn,{className:"dark:!univer-text-white"})]})})})})},bf=[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 Rf(n,o,e,t,r){const i=[],s=[];if(t.copyType===$e.CUT){const{undos:l,redos:c}=wf(n,o,r);i.push(...c),s.push(...l)}else{const{undos:l,redos:c}=Jc(o,e,r);i.push(...c),s.push(...l);const{undos:d,redos:u}=Ef(o,e,r);i.push(...u),s.push(...d);const{undos:h,redos:g}=qc(o,n,e,r);i.push(...g),s.push(...h);const{undos:S,redos:f}=Qc(o,n,e,r,!0);i.push(...f),s.push(...S);const{undos:p,redos:v}=Bi(o,e,r);i.push(...v),s.push(...p)}return{undos:s,redos:i}}function wf(n,o,e){let t=[],r=[];const{range:i,subUnitId:s,unitId:l}=n,{range:c,subUnitId:d}=o,u=c?gt(c):null,h=i?gt(i):null;if(h&&u){const g=e.get(a.IUniverInstanceService),S=e.get(m.SheetInterceptorService),f=g.getUniverSheetInstance(l),p=f==null?void 0:f.getSheetBySheetId(s),v=f==null?void 0:f.getSheetBySheetId(d);if(p&&v){const C=new a.ObjectMatrix,_=new a.ObjectMatrix,R=p.getCellMatrix(),w=v.getCellMatrix();a.Range.foreach(h,(B,z)=>{C.setValue(B,z,a.cloneCellData(R.getValue(B,z))),_.setValue(B,z,null)});const P=new a.ObjectMatrix;a.Range.foreach(u,(B,z)=>{P.setValue(B,z,a.cloneCellData(w.getValue(B,z)))});const T=new a.ObjectMatrix;a.Range.foreach(h,(B,z)=>{const X=a.cellToRange(B,z),K=a.Rectangle.getRelativeRange(X,h),re=a.Rectangle.getPositionRange(K,u);T.setValue(re.startRow,re.startColumn,R.getValue(B,z))});const M={fromRange:h,toRange:u,from:{value:_.getMatrix(),subUnitId:s},to:{value:T.getMatrix(),subUnitId:d},unitId:l},x={fromRange:u,toRange:h,from:{value:C.getMatrix(),subUnitId:s},to:{value:P.getMatrix(),subUnitId:d},unitId:l},A=S.onCommandExecute({id:m.MoveRangeCommand.id,params:{toRange:u,fromRange:h}}),D=p.getMergeData(),k=v.getMergeData(),H=D.filter(B=>a.Rectangle.intersects(B,h)),N=k.filter(B=>a.Rectangle.intersects(B,u)),V=H.map(B=>a.Rectangle.getRelativeRange(B,h)).map(B=>a.Rectangle.getPositionRange(B,u)),L=m.getAddMergeMutationRangeByType(V),U=[{id:m.RemoveWorksheetMergeMutation.id,params:{unitId:l,subUnitId:s,ranges:H}},{id:m.RemoveWorksheetMergeMutation.id,params:{unitId:l,subUnitId:s,ranges:N}},{id:m.AddWorksheetMergeMutation.id,params:{unitId:l,subUnitId:d,ranges:L}}],F=[{id:m.RemoveWorksheetMergeMutation.id,params:{unitId:l,subUnitId:d,ranges:L}},{id:m.AddWorksheetMergeMutation.id,params:{unitId:l,subUnitId:d,ranges:N}},{id:m.AddWorksheetMergeMutation.id,params:{unitId:l,subUnitId:s,ranges:H}}];t=[{id:m.MoveRangeMutation.id,params:M},...A.redos,...U,{id:m.SetSelectionsOperation.id,params:{unitId:l,subUnitId:d,selections:[{range:u}],type:m.SelectionMoveType.MOVE_END}}],r=[{id:m.MoveRangeMutation.id,params:x},...A.undos,...F,{id:m.SetSelectionsOperation.id,params:{unitId:l,subUnitId:s,type:m.SelectionMoveType.MOVE_END,selections:[{range:h}]}}]}}return{undos:r,redos:t}}function qc(n,o,e,t){var f;const{unitId:r,subUnitId:i,range:s}=n,l=(f=t.get(a.IUniverInstanceService).getUniverSheetInstance(r))==null?void 0:f.getSheetBySheetId(i),c=[],d=[],{mapFunc:u}=St([s]),h=new a.ObjectMatrix;e.forValue((p,v,C)=>{var P,T;const{row:_,col:R}=u(p,v),w={v:C.v,t:C.t};if(!C.p&&C.v&&!o){const M=l==null?void 0:l.getCellStyle(_,R);if(a.isTextFormat((P=M==null?void 0:M.n)==null?void 0:P.pattern))w.t=a.CellValueType.STRING;else{const x=String(C.v),A=a.numfmt.parseValue(x);(A==null?void 0:A.v)!==void 0&&typeof A.v=="number"&&(!A.z&&a.willLoseNumericPrecision(x)?w.t=a.CellValueType.FORCE_STRING:w.v=A.v)}}if((T=C.p)!=null&&T.body&&Hi(C.p.body)){const M={p:a.cloneValue(C.p),v:C.v};h.setValue(_,R,M)}else h.setValue(_,R,w&&a.cloneCellData(w))});const g={unitId:r,subUnitId:i,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 Qc(n,o,e,t,r=!1){var p;const i=[],s=[],{unitId:l,subUnitId:c,range:d}=n,u=(p=t.get(a.IUniverInstanceService).getUniverSheetInstance(l))==null?void 0:p.getSheetBySheetId(c),h=new a.ObjectMatrix,{mapFunc:g}=St([d]);e.forValue((v,C,_)=>{var x,A;const R={s:Object.assign({},{...a.DEFAULT_STYLES,pd:y.DEFAULT_PADDING_DATA,bg:null,cl:null},_.s)},w=R.s.bd;w&&(Object.keys(w).length>0||(R.s.bd={b:null,l:null,r:null,t:null}));const{row:P,col:T}=g(v,C),M=u==null?void 0:u.getCellStyle(P,T);if(_.v&&!o&&a.isTextFormat((x=M==null?void 0:M.n)==null?void 0:x.pattern))R.s||(R.s={}),R.s.n=M==null?void 0:M.n;else{const D=String(_.v),k=a.numfmt.parseValue(D);k!=null&&k.z&&(R.s||(R.s={}),typeof R.s=="object"&&((A=R.s)!=null&&A.n?R.s.n.pattern=k.z:R.s.n={pattern:k.z}))}h.setValue(P,T,R)});const S={unitId:l,subUnitId:c,cellValue:a.cloneCellDataMatrix(h.getMatrix())};i.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:i}}function Jc(n,o,e){const t=[],r=[],i=new a.ObjectMatrix,{unitId:s,subUnitId:l,range:c}=n,{mapFunc:d}=St([c]);if(o.forEach((u,h)=>{Object.keys(h).forEach(g=>{const S=Number(g),{row:f,col:p}=d(u,S);i.setValue(f,p,{s:null})})}),i.getLength()>0){const u={subUnitId:l,unitId:s,cellValue:a.cloneCellDataMatrix(i.getMatrix())};t.push({id:m.SetRangeValuesMutation.id,params:u});const h=m.SetRangeValuesUndoMutationFactory(e,u);r.push({id:m.SetRangeValuesMutation.id,params:h})}return{undos:r,redos:t}}function Ef(n,o,e){const t=[],r=[],i=new a.ObjectMatrix,{unitId:s,subUnitId:l,range:c}=n,{mapFunc:d}=St([c]);if(o.forValue((u,h,g)=>{const{row:S,col:f}=d(u,h);i.setValue(S,f,{v:null,p:null})}),i.getLength()>0){const u={subUnitId:l,unitId:s,cellValue:a.cloneCellDataMatrix(i.getMatrix())};t.push({id:m.SetRangeValuesMutation.id,params:u});const h=m.SetRangeValuesUndoMutationFactory(e,u);r.push({id:m.SetRangeValuesMutation.id,params:h})}return{undos:r,redos:t}}function Bi(n,o,e){const t=[],r=[],{unitId:i,subUnitId:s,range:l}=n,{startColumn:c,startRow:d,endColumn:u,endRow:h}=gt(l),g=[];o.forValue((_,R,w)=>{if(w.rowSpan&&w.rowSpan>1){const P=w.colSpan||1,T={startRow:d+_,endRow:d+_+w.rowSpan-1,startColumn:c+R,endColumn:c+R+P-1};g.push(T)}else if(w.colSpan&&w.colSpan>1){const P=w.rowSpan||1,T={startRow:d+_,endRow:d+_+P-1,startColumn:c+R,endColumn:c+R+w.colSpan-1};g.push(T)}});const f=e.get(a.IUniverInstanceService).getUniverSheetInstance(i),p=f==null?void 0:f.getSheetBySheetId(s);if(f&&p){const R=p.getMergeData().filter(T=>a.Rectangle.intersects({startRow:d,startColumn:c,endRow:h,endColumn:u},T)),w={unitId:i,subUnitId:s,ranges:R};t.push({id:m.RemoveWorksheetMergeMutation.id,params:w});const P=m.RemoveMergeUndoMutationFactory(e,w);r.push({id:m.AddWorksheetMergeMutation.id,params:P})}const v={unitId:i,subUnitId:s,ranges:g};g.length>0&&t.push({id:m.AddWorksheetMergeMutation.id,params:v});const C=m.AddMergeUndoMutationFactory(e,v);return g.length>0&&r.push({id:m.RemoveWorksheetMergeMutation.id,params:C}),{undos:r,redos:t}}function Tf(n){if(!n.includes("\r")&&a.Tools.isLegalUrl(n)){const t=a.generateRandomId(),r=`${n}`,i={startIndex:0,endIndex:r.length-1,rangeId:t,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:n}};return{dataStream:`${r}\r
|
|
13
13
|
`,paragraphs:[{startIndex:r.length}],customRanges:[i]}}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(`
|