@univerjs/docs-ui 0.5.5-nightly.202501211606 → 0.5.5
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/LICENSE +176 -0
- package/lib/cjs/index.js +1 -1
- package/lib/es/facade.js +58 -61
- package/lib/es/index.js +7346 -7538
- package/lib/es/locale/en-US.js +2 -2
- package/lib/es/locale/fa-IR.js +2 -2
- package/lib/es/locale/fr-FR.js +2 -2
- package/lib/es/locale/ru-RU.js +2 -2
- package/lib/es/locale/vi-VN.js +2 -2
- package/lib/es/locale/zh-CN.js +2 -2
- package/lib/es/locale/zh-TW.js +2 -2
- package/lib/types/facade/f-document.d.ts +0 -3
- package/lib/umd/index.js +1 -1
- package/package.json +8 -8
package/lib/cjs/index.js
CHANGED
|
@@ -43,4 +43,4 @@ ${i.DataStreamTreeTokenType.TABLE_CELL_END}`;break}}}_processBeforeLink(t,e){ret
|
|
|
43
43
|
`,children:t.map(E=>Q.jsx(ae.Tooltip,{title:E.label,placement:"bottom",children:Q.jsx("span",{className:Vt(G.paragraphSettingIconListItem,{[G.paragraphSettingIconListActive]:n===E.value}),onClick:()=>r(E.value),children:E.icon})},E.value))}),Q.jsx("div",{className:G.paragraphSettingTitle,children:o.t("doc.paragraphSetting.indentation")}),Q.jsxs("div",{children:[Q.jsxs("div",{className:G.paragraphSettingFlexCol,children:[Q.jsxs("div",{className:G.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.left"),"(px)"]}),Q.jsx(De,{className:G.paragraphSettingMtBase,value:s,onChange:E=>a(E!=null?E:0)})]}),Q.jsxs("div",{className:G.paragraphSettingFlexCol,children:[Q.jsxs("div",{className:G.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.right"),"(px)"]}),Q.jsx(De,{className:G.paragraphSettingMtBase,value:c,onChange:E=>l(E!=null?E:0)})]}),Q.jsxs("div",{className:G.paragraphSettingFlexCol,children:[Q.jsxs("div",{className:G.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.firstLine"),"(px)"]}),Q.jsx(De,{className:G.paragraphSettingMtBase,value:A,onChange:E=>d(E!=null?E:0)})]}),Q.jsxs("div",{className:G.paragraphSettingFlexCol,children:[Q.jsxs("div",{className:G.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.hanging"),"(px)"]}),Q.jsx(De,{className:G.paragraphSettingMtBase,value:u,onChange:E=>h(E!=null?E:0)})]})]}),Q.jsx("div",{className:G.paragraphSettingTitle,children:o.t("doc.paragraphSetting.spacing")}),Q.jsxs("div",{children:[Q.jsxs("div",{className:G.paragraphSettingFlexCol,children:[Q.jsxs("div",{className:G.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.before"),"(px)"]}),Q.jsx(De,{className:G.paragraphSettingMtBase,value:g,onChange:E=>f(E!=null?E:0)})]}),Q.jsxs("div",{className:G.paragraphSettingFlexCol,children:[Q.jsxs("div",{className:G.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.after"),"(px)"]}),Q.jsx(De,{className:G.paragraphSettingMtBase,value:m,onChange:E=>p(E!=null?E:0)})]}),Q.jsxs("div",{className:G.paragraphSettingFlexCol,children:[Q.jsx("div",{className:G.paragraphSettingLabel,children:o.t("doc.paragraphSetting.lineSpace")}),Q.jsxs("div",{className:`
|
|
44
44
|
${G.paragraphSettingMtBase}
|
|
45
45
|
${G.paragraphSettingSpaceLine}
|
|
46
|
-
`,style:{width:162},children:[Q.jsx(ae.Select,{value:`${v}`,options:[{label:o.t("doc.paragraphSetting.multiSpace"),value:`${i.SpacingRule.AUTO}`},{label:o.t("doc.paragraphSetting.fixedValue"),value:`${i.SpacingRule.AT_LEAST}`}],onChange:E=>R(Number(E))}),Q.jsx(De,{...b,value:S,onChange:E=>I(E!=null?E:0)})]})]})]})]})}const Pc=(o,t)=>t.length===o.length&&o.some(e=>t.some(n=>n.startOffset===e.startOffset&&n.endOffset===e.endOffset));function Nc(){const o=i.useDependency(i.ICommandService),t=i.useDependency(i.LocaleService),e=i.useObservable(t.currentLocale$),[n,r]=L.useState(""),s=L.useMemo(()=>i.debounce(()=>r(i.generateRandomId(4)),300),[]),a=L.useRef([]);return L.useEffect(()=>{const c=o.onCommandExecuted(l=>{if(M.SetTextSelectionsOperation.id===l.id){const A=l.params.ranges;Pc(A,a.current)||r(i.generateRandomId(4)),a.current=A}M.RichTextEditingMutation.id===l.id&&l.params.trigger!==fe.id&&s()});return()=>c.dispose()},[s]),L.useEffect(()=>{r(i.generateRandomId(4))},[e]),L.useEffect(()=>()=>s.cancel(),[s]),Q.jsx(_c,{},n)}var Uc=Object.defineProperty,wc=Object.getOwnPropertyDescriptor,Qc=(o,t,e,n)=>{for(var r=n>1?void 0:n?wc(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Uc(t,e,r),r},Qn=(o,t)=>(e,n)=>t(e,n,o);const mr="doc_ui_paragraph-setting-panel";let et=class extends i.Disposable{constructor(t,e,n){super();x(this,"_id");this._commandService=t,this._componentManager=e,this._sidebarService=n,this._init()}_init(){this.disposeWithMe(this._componentManager.register(mr,Nc))}openPanel(){const t={header:{title:"doc.slider.paragraphSetting"},id:this._id,children:{label:mr},width:300};this._sidebarService.open(t)}closePanel(){this._sidebarService.close(this._id)}};et=Qc([Qn(0,i.ICommandService),Qn(1,i.Inject(C.ComponentManager)),Qn(2,i.Inject(C.ISidebarService))],et);const Po={id:"sidebar.operation.doc-paragraph-setting-panel",type:i.CommandType.OPERATION,handler:o=>(o.get(et).openPanel(),!0)},No=o=>{const t=o.get(M.DocSelectionManagerService);return new _.Observable(e=>{const n=t.textSelection$.subscribe(()=>{t.getDocRanges().some(a=>a.collapsed===!1||a.rangeType===i.DOC_RANGE_TYPE.RECT)?e.next(!1):e.next(!0)});return()=>n.unsubscribe()})};function Lc(o){if(o.length<2)return!0;const t=o.map(e=>e.tableId);return t.every(e=>e===t[0])}function fr(o,t,e){var s;const n=t.getRectRanges(),r=t.getActiveTextRange();if(n&&n.length&&Lc(n)&&r==null){o.next(!1);return}if(r&&(n==null||n.length===0)){const{segmentId:a,startOffset:c,endOffset:l}=r,A=e.getCurrentUniverDocInstance(),d=(s=A==null?void 0:A.getSelfOrHeaderFooterModel(a).getBody())==null?void 0:s.tables;if(d&&d.length&&d.some(u=>{const{startIndex:h,endIndex:g}=u;return c>h&&c<g||l>h&&l<g})){o.next(!1);return}}o.next(!0)}const Re=o=>{const t=o.get(M.DocSelectionManagerService),e=o.get(i.IUniverInstanceService);return new _.Observable(n=>{const r=t.textSelection$.subscribe(()=>{fr(n,t,e)});return fr(n,t,e),()=>r.unsubscribe()})},Fc=o=>({id:St.name,commandId:St.id,type:C.MenuItemType.BUTTON,icon:"Copy",title:"rightClick.copy",disabled$:No(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}),Hc=o=>({id:Po.id,type:C.MenuItemType.BUTTON,icon:"MenuSingle24",title:"doc.menu.paragraphSetting",hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}),kc=o=>({id:fn.id,type:C.MenuItemType.BUTTON,icon:"Copy",title:"rightClick.cut",disabled$:No(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}),jc=o=>({id:pn.id,type:C.MenuItemType.BUTTON,icon:"PasteSpecial",title:"rightClick.paste",hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}),Vc=o=>({id:Dt.id,type:C.MenuItemType.BUTTON,icon:"PasteSpecial",title:"rightClick.delete",disabled$:No(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}),Ci="doc.menu.table-insert";function Wc(o){return{id:Ci,type:C.MenuItemType.SUBITEMS,title:"table.insert",icon:"Insert",hidden$:_.combineLatest(C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),Re(o),(t,e)=>t||e)}}function Kc(o){return{id:vn.id,type:C.MenuItemType.BUTTON,title:"table.insertRowAbove",icon:"InsertRowAbove",disabled$:Re(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function zc(o){return{id:Cn.id,type:C.MenuItemType.BUTTON,title:"table.insertRowBelow",icon:"InsertRowBelow",disabled$:Re(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Gc(o){return{id:Tn.id,type:C.MenuItemType.BUTTON,title:"table.insertColumnLeft",icon:"LeftInsertColumn",disabled$:Re(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Xc(o){return{id:Rn.id,type:C.MenuItemType.BUTTON,title:"table.insertColumnRight",icon:"RightInsertColumn",disabled$:Re(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}const Ti="doc.menu.table-delete";function Yc(o){return{id:Ti,type:C.MenuItemType.SUBITEMS,title:"table.delete",icon:"Reduce",hidden$:_.combineLatest(C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),Re(o),(t,e)=>t||e)}}function qc(o){return{id:In.id,type:C.MenuItemType.BUTTON,title:"table.deleteRows",icon:"DeleteRow",disabled$:Re(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Jc(o){return{id:En.id,type:C.MenuItemType.BUTTON,title:"table.deleteColumns",icon:"DeleteColumn",disabled$:Re(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Zc(o){return{id:at.id,type:C.MenuItemType.BUTTON,title:"table.deleteTable",icon:"GridSingle",disabled$:Re(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function $c(o){const t=o.get(i.IUniverInstanceService),e=o.get(y.IRenderManagerService);return new _.Observable(n=>{const r=t.focused$.subscribe(c=>{if(c==null||t.getUnitType(c)!==i.UniverInstanceType.UNIVER_DOC)return n.next(!0);const A=e.getRenderById(c);if(A==null)return n.next(!0);A.with(M.DocSkeletonManagerService).getViewModel().editAreaChange$.subscribe(u=>{n.next(u===y.DocumentEditArea.HEADER||u===y.DocumentEditArea.FOOTER)})}),s=e.getCurrentTypeOfRenderer(i.UniverInstanceType.UNIVER_DOC);if(s==null)return n.next(!0);const a=s.with(M.DocSkeletonManagerService).getViewModel();return n.next(a.getEditArea()!==y.DocumentEditArea.BODY),()=>r.unsubscribe()})}function el(o){const t=o.get(i.IUniverInstanceService),e=o.get(i.ICommandService);return new _.Observable(n=>{const r=e.onCommandExecuted(l=>{if(l.id===M.RichTextEditingMutation.id){const{unitId:A}=l.params,d=t.getUnit(A);if(d==null){n.next(!0);return}const{documentStyle:u}=d.getSnapshot();n.next((u==null?void 0:u.documentFlavor)!==i.DocumentFlavor.TRADITIONAL)}}),s=t.focused$.subscribe(l=>{if(l==null)return n.next(!0);const A=t.getUniverDocInstance(l),d=A==null?void 0:A.getSnapshot().documentStyle.documentFlavor;n.next(d!==i.DocumentFlavor.TRADITIONAL)}),a=t.getCurrentUniverDocInstance();if(a==null)return n.next(!0);const c=a==null?void 0:a.getSnapshot().documentStyle.documentFlavor;return n.next(c!==i.DocumentFlavor.TRADITIONAL),()=>{r.dispose(),s.unsubscribe()}})}function tl(o){const t=o.get(M.DocSelectionManagerService),e=o.get(i.IUniverInstanceService);return new _.Observable(n=>{const r=t.textSelection$.subscribe(s=>{if(s==null){n.next(!0);return}const{textRanges:a}=s;if(a.length!==1){n.next(!0);return}const c=a[0],{collapsed:l,startNodePosition:A,startOffset:d}=c;if(!l||d==null){n.next(!0);return}const u=e.getCurrentUniverDocInstance();if(u==null){n.next(!0);return}const h=le(o,u.getUnitId());if(h==null){n.next(!0);return}if(h.getViewModel().getCustomRangeRaw(d)){n.next(!0);return}if(A!=null){const{path:m}=A;if(m.indexOf("cells")!==-1){n.next(!0);return}}n.next(!1)});return()=>r.unsubscribe()})}function ee(o){const t=o.get(M.DocSelectionManagerService);return new _.Observable(e=>{const n=t.textSelection$.subscribe(r=>{if(r==null){e.next(!0);return}const{textRanges:s,rectRanges:a}=r;if(s.length===0&&a.length===0){e.next(!0);return}e.next(!1)});return()=>n.unsubscribe()})}function nl(o){const t=o.get(i.ICommandService);return{id:Fe.id,type:C.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===M.SetTextSelectionsOperation.id||s===Te.id){const c=Oe(o);if(c==null){e.next(!1);return}const l=(a=c.ts)==null?void 0:a.bl;e.next(l===i.BooleanNumber.TRUE)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function ol(o){const t=o.get(i.ICommandService);return{id:He.id,type:C.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===M.SetTextSelectionsOperation.id||s===Te.id){const c=Oe(o);if(c==null){e.next(!1);return}const l=(a=c.ts)==null?void 0:a.it;e.next(l===i.BooleanNumber.TRUE)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function rl(o){const t=o.get(i.ICommandService);return{id:ke.id,type:C.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===M.SetTextSelectionsOperation.id||s===Te.id){const c=Oe(o);if(c==null){e.next(!1);return}const l=(a=c.ts)==null?void 0:a.ul;e.next((l==null?void 0:l.s)===i.BooleanNumber.TRUE)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function il(o){const t=o.get(i.ICommandService);return{id:je.id,type:C.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===M.SetTextSelectionsOperation.id||s===Te.id){const c=Oe(o);if(c==null){e.next(!1);return}const l=(a=c.ts)==null?void 0:a.st;e.next((l==null?void 0:l.s)===i.BooleanNumber.TRUE)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function sl(o){const t=o.get(i.ICommandService);return{id:ye.id,type:C.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===M.SetTextSelectionsOperation.id||s===Te.id){const c=Oe(o);if(c==null){e.next(!1);return}const l=(a=c.ts)==null?void 0:a.va;e.next(l===i.BaselineOffset.SUBSCRIPT)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function al(o){const t=o.get(i.ICommandService);return{id:Ve.id,type:C.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===M.SetTextSelectionsOperation.id||s===Te.id){const c=Oe(o);if(c==null){e.next(!1);return}const l=(a=c.ts)==null?void 0:a.va;e.next(l===i.BaselineOffset.SUPERSCRIPT)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function cl(o){const t=o.get(i.ICommandService);return{id:Ue.id,tooltip:"toolbar.font",type:C.MenuItemType.SELECTOR,label:ni,selections:C.FONT_FAMILY_LIST.map(e=>({label:{name:oi,hoverable:!0},value:e.value})),value$:new _.Observable(e=>{const n=i.DEFAULT_STYLES.ff,r=t.onCommandExecuted(s=>{var c;const a=s.id;if(a===M.SetTextSelectionsOperation.id||a===Ue.id){const l=Oe(o);if(l==null){e.next(n);return}const A=(c=l.ts)==null?void 0:c.ff;e.next(A!=null?A:n)}});return e.next(n),r.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function ll(o){const t=o.get(i.ICommandService);return{id:Ne.id,type:C.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:ri,props:{min:1,max:400}},selections:C.FONT_SIZE_LIST,value$:new _.Observable(e=>{const n=i.DEFAULT_STYLES.fs,r=t.onCommandExecuted(s=>{var c;const a=s.id;if(a===M.SetTextSelectionsOperation.id||a===Ne.id){const l=Oe(o);if(l==null){e.next(n);return}const A=(c=l.ts)==null?void 0:c.fs;e.next(A!=null?A:n)}});return e.next(n),r.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Al(o){const t=o.get(i.ICommandService),e=o.get(i.ThemeService);return{id:we.id,icon:"FontColor",tooltip:"toolbar.textColor.main",type:C.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:po,hoverable:!1}}],value$:new _.Observable(n=>{const r=e.getCurrentTheme().textColor,s=t.onCommandExecuted(a=>{if(a.id===we.id){const c=a.params.value;n.next(c!=null?c:r)}});return n.next(r),s.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function dl(o){return{id:mo.id,type:C.MenuItemType.BUTTON,icon:"HeaderFooterSingle",tooltip:"toolbar.headerFooter",hidden$:_.combineLatest(C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY),el(o),(t,e)=>t||e)}}const ul="GridSingle",Ri="doc.menu.table";function gl(o){return{id:Ri,type:C.MenuItemType.SUBITEMS,icon:ul,tooltip:"toolbar.table.main",disabled$:tl(o),hidden$:_.combineLatest(C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY),$c(o),(t,e)=>t||e)}}function hl(o){return{id:bn.id,title:"toolbar.table.insert",type:C.MenuItemType.BUTTON,hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function ml(o){const t=o.get(i.ICommandService);return{id:Rt.id,type:C.MenuItemType.BUTTON,icon:"LeftJustifyingSingle",tooltip:"toolbar.alignLeft",disabled$:ee(o),activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===M.SetTextSelectionsOperation.id||s===me.id){const c=yn(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.LEFT)}});return e.next(!1),n.dispose}),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function fl(o){const t=o.get(i.ICommandService);return{id:bt.id,type:C.MenuItemType.BUTTON,icon:"HorizontallySingle",tooltip:"toolbar.alignCenter",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===M.SetTextSelectionsOperation.id||s===me.id){const c=yn(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.CENTER)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function pl(o){const t=o.get(i.ICommandService);return{id:yt.id,type:C.MenuItemType.BUTTON,icon:"RightJustifyingSingle",tooltip:"toolbar.alignRight",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===M.SetTextSelectionsOperation.id||s===me.id){const c=yn(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.RIGHT)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Sl(o){const t=o.get(i.ICommandService);return{id:Ot.id,type:C.MenuItemType.BUTTON,icon:"AlignTextBothSingle",tooltip:"toolbar.alignJustify",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===M.SetTextSelectionsOperation.id||s===me.id){const c=yn(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.JUSTIFIED)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}const It=o=>new _.Observable(t=>{const e=o.get(i.IUniverInstanceService),n=o.get(M.DocSelectionManagerService);let r;const s=e.focused$.subscribe(a=>{if(r==null||r.unsubscribe(),a==null)return;const c=e.getUniverDocInstance(a);c!=null&&(r=n.textSelection$.subscribe(()=>{var d,u,h;const l=n.getDocRanges(),A=(d=l.find(g=>g.isActive))!=null?d:l[0];if(A){const g=c.getSelfOrHeaderFooterModel(A==null?void 0:A.segmentId),f=sn(A,(h=(u=g.getBody())==null?void 0:u.paragraphs)!=null?h:[]);let m;if(f.every(p=>{var S;return m||(m=(S=p.bullet)==null?void 0:S.listType),p.bullet&&p.bullet.listType===m})){t.next(m);return}}t.next(void 0)}))});return()=>{s.unsubscribe(),r==null||r.unsubscribe()}});function Il(o){return{id:Tt.id,type:C.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:si,hoverable:!1},value$:It(o)}],icon:"OrderSingle",tooltip:"toolbar.order",hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),disabled$:ee(o),activated$:It(o).pipe(_.map(t=>t&&t.indexOf("ORDER_LIST")===0))}}function El(o){return{id:Ct.id,type:C.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:ai,hoverable:!1},value$:It(o)}],icon:"UnorderSingle",tooltip:"toolbar.unorder",disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),activated$:It(o).pipe(_.map(t=>t&&t.indexOf("BULLET_LIST")===0))}}function vl(o){return{id:on.id,type:C.MenuItemType.BUTTON,icon:"TodoList",tooltip:"toolbar.checklist",disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),activated$:It(o).pipe(_.map(t=>t&&t.indexOf("CHECK_LIST")===0))}}function Cl(o){const t=o.get(i.ICommandService),e=o.get(i.IUniverInstanceService);return{id:Sn.id,type:C.MenuItemType.BUTTON,icon:"KeyboardSingle",tooltip:"toolbar.documentFlavor",hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY),activated$:new _.Observable(n=>{var a;const r=t.onCommandExecuted(c=>{var l;if(c.id===M.RichTextEditingMutation.id){const A=e.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);n.next(((l=A==null?void 0:A.getSnapshot())==null?void 0:l.documentStyle.documentFlavor)===i.DocumentFlavor.MODERN)}}),s=e.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);return n.next(((a=s==null?void 0:s.getSnapshot())==null?void 0:a.documentStyle.documentFlavor)===i.DocumentFlavor.MODERN),()=>r.dispose()})}}function Tl(o){return{id:ot.id,type:C.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor"}}function Rl(o){const t=o.get(i.ICommandService),e=o.get(i.ThemeService);return{id:Qe.id,tooltip:"toolbar.fillColor.main",type:C.MenuItemType.BUTTON_SELECTOR,icon:"PaintBucket",selections:[{label:{name:po,hoverable:!1}}],value$:new _.Observable(n=>{const r=e.getCurrentTheme().primaryColor,s=t.onCommandExecuted(a=>{if(a.id===Qe.id){const c=a.params.value;n.next(c!=null?c:r)}});return n.next(r),s.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Oe(o){var h,g;const t=o.get(i.IUniverInstanceService),e=o.get(M.DocSelectionManagerService),n=o.get(Ce),r=t.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),s=e.getDocRanges(),a=(h=s.find(f=>f.isActive))!=null?h:s[0],c=n.getDefaultStyle(),l=(g=n.getStyleCache())!=null?g:{};if(r==null||a==null)return{ts:{...c,...l}};const{segmentId:A}=a,d=r.getSelfOrHeaderFooterModel(A).getBody();return d==null?{ts:{...c,...l}}:{ts:{...li(d,a,c),...l}}}function yn(o){var d,u;const t=o.get(i.IUniverInstanceService),e=o.get(M.DocSelectionManagerService),n=t.getCurrentUniverDocInstance(),r=e.getDocRanges(),s=(d=r.find(h=>h.isActive))!=null?d:r[0];if(n==null||s==null)return;const{startOffset:a,segmentId:c}=s,l=(u=n.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:u.paragraphs;if(l==null)return;let A=-1;for(const h of l){const{startIndex:g}=h;if(a>A&&a<=g)return h;A=g}return null}const bi={[C.RibbonStartGroup.FORMAT]:{[Fe.id]:{order:0,menuItemFactory:nl},[He.id]:{order:1,menuItemFactory:ol},[ke.id]:{order:2,menuItemFactory:rl},[je.id]:{order:3,menuItemFactory:il},[ye.id]:{order:4,menuItemFactory:sl},[Ve.id]:{order:5,menuItemFactory:al},[Ne.id]:{order:6,menuItemFactory:ll},[Ue.id]:{order:7,menuItemFactory:cl},[we.id]:{order:8,menuItemFactory:Al},[Qe.id]:{order:9,menuItemFactory:Rl,[ot.id]:{order:0,menuItemFactory:Tl}}},[C.RibbonStartGroup.LAYOUT]:{[Ri]:{order:1,menuItemFactory:gl,[bn.id]:{order:0,menuItemFactory:hl}},[Rt.id]:{order:2,menuItemFactory:ml},[bt.id]:{order:3,menuItemFactory:fl},[yt.id]:{order:4,menuItemFactory:pl},[Ot.id]:{order:5,menuItemFactory:Sl},[Tt.id]:{order:6,menuItemFactory:Il},[Ct.id]:{order:7,menuItemFactory:El},[on.id]:{order:8,menuItemFactory:vl},[mo.id]:{order:9,menuItemFactory:dl},[Sn.id]:{order:10,menuItemFactory:Cl}},[C.ContextMenuPosition.MAIN_AREA]:{[C.ContextMenuGroup.FORMAT]:{[St.name]:{order:0,menuItemFactory:Fc},[fn.id]:{order:1,menuItemFactory:kc},[pn.id]:{order:2,menuItemFactory:jc},[Dt.id]:{order:3,menuItemFactory:Vc}},[C.ContextMenuGroup.LAYOUT]:{[Po.id]:{order:0,menuItemFactory:Hc},[Ci]:{order:1,menuItemFactory:Wc,[vn.id]:{order:1,menuItemFactory:Kc},[Cn.id]:{order:2,menuItemFactory:zc},[Tn.id]:{order:3,menuItemFactory:Gc},[Rn.id]:{order:4,menuItemFactory:Xc}},[Ti]:{order:2,menuItemFactory:Yc,[In.id]:{order:1,menuItemFactory:qc},[En.id]:{order:2,menuItemFactory:Jc},[at.id]:{order:3,menuItemFactory:Zc}}}}};var bl=Object.defineProperty,yl=Object.getOwnPropertyDescriptor,Ol=(o,t,e,n)=>{for(var r=n>1?void 0:n?yl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&bl(t,e,r),r},pe=(o,t)=>(e,n)=>t(e,n,o);exports.DocUIController=class extends i.Disposable{constructor(t,e,n,r,s,a,c,l,A){super(),this._injector=t,this._componentManager=e,this._commandService=n,this._layoutService=r,this._menuManagerService=s,this._uiPartsService=a,this._univerInstanceService=c,this._shortcutService=l,this._configService=A,this._init()}_initCustomComponents(){const t=this._componentManager;this.disposeWithMe(t.register(po,ae.ColorPicker)),this.disposeWithMe(t.register(ni,C.FontFamily)),this.disposeWithMe(t.register(oi,C.FontFamilyItem)),this.disposeWithMe(t.register(ri,C.FontSize)),this.disposeWithMe(t.register(ai,ta)),this.disposeWithMe(t.register(si,$s)),this.disposeWithMe(t.register("TodoList",Zr))}_initUiParts(){var n,r;const t=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET),e=this._configService.getConfig(Io);(r=(n=e==null?void 0:e.layout)==null?void 0:n.docContainerConfig)!=null&&r.footer&&!t&&this.disposeWithMe(this._uiPartsService.registerComponent(C.BuiltInUIPart.FOOTER,()=>i.connectInjector(wa,this._injector)))}_initMenus(){this._menuManagerService.mergeMenu(bi)}_initShortCut(){[ma,fa,pa,Sa,Ia,Ea,Ta,Ra,Ca,va,ba,ya,ia].forEach(t=>{this.disposeWithMe(this._shortcutService.registerShortcut(t))})}_init(){this._initCustomComponents(),this._initMenus(),this._initFocusHandler(),this._initCommands(),this._initUiParts(),this._initShortCut()}_initCommands(){[ti,mo,ho].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(i.UniverInstanceType.UNIVER_DOC,t=>{this._injector.get(y.IRenderManagerService).getRenderById(t).with(exports.DocSelectionRenderService).focus()}))}};exports.DocUIController=Ol([pe(0,i.Inject(i.Injector)),pe(1,i.Inject(C.ComponentManager)),pe(2,i.ICommandService),pe(3,C.ILayoutService),pe(4,C.IMenuManagerService),pe(5,C.IUIPartsService),pe(6,i.IUniverInstanceService),pe(7,C.IShortcutService),pe(8,i.IConfigService)],exports.DocUIController);var xl=Object.defineProperty,Dl=Object.getOwnPropertyDescriptor,Ml=(o,t,e,n)=>{for(var r=n>1?void 0:n?Dl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&xl(t,e,r),r},Ln=(o,t)=>(e,n)=>t(e,n,o);const pr=1.5;exports.DocBackScrollRenderController=class extends i.RxDisposable{constructor(t,e,n,r){super(),this._context=t,this._textSelectionManagerService=e,this._editorService=n,this._docSkeletonManagerService=r,this._init()}_init(){this._textSelectionManagerService.textSelection$.pipe(_.takeUntil(this.dispose$)).subscribe(t=>{if(t==null)return;const{isEditing:e,unitId:n}=t;n!==this._context.unitId||!e||this._context.unitId!==i.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._scrollToSelection()})}scrollToRange(t){const e=this._docSkeletonManagerService.getSkeleton();if(!e)return;const{startOffset:n}=t,r=e.findNodePositionByCharIndex(n);r&&this.scrollToNode(r)}scrollToNode(t){var U;const{unitId:e,scene:n,mainComponent:r}=this._context,s=this._docSkeletonManagerService.getSkeleton();if(r==null||s==null)return;const a=r.getOffsetConfig(),{docsLeft:c,docsTop:l}=a,A=new Ie(a,s),{contentBoxPointGroup:d}=A.getRangePointData(t,t),{left:u,top:h,height:g}=ft(d),f=u+c,m=h+l,p=n.getViewport(he.VIEW_MAIN),S=this._editorService.getEditor(e);if(p==null)return;const{left:I,top:v,right:R,bottom:b}=p.getBounding().viewBound;let E=0,T=0;const B=S?(U=S.params.backScrollOffset)!=null?U:0:100;m<v?E=m-v-B:m>b-g&&(E=m-b+g+B),f<I?T=f-I:f>R-pr&&(T=f-R+pr);const D=p.transViewportScroll2ScrollValue(T,E);p.scrollByBarDeltaValue(D)}_scrollToSelection(){const t=this._textSelectionManagerService.getActiveTextRange();if(t==null)return;const{collapsed:e,startNodePosition:n}=t;e&&this.scrollToNode(n)}};exports.DocBackScrollRenderController=Ml([Ln(1,i.Inject(M.DocSelectionManagerService)),Ln(2,ce),Ln(3,i.Inject(M.DocSkeletonManagerService))],exports.DocBackScrollRenderController);var Bl=Object.defineProperty,_l=Object.getOwnPropertyDescriptor,Pl=(o,t,e,n)=>{for(var r=n>1?void 0:n?_l(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Bl(t,e,r),r},ze=(o,t)=>(e,n)=>t(e,n,o);exports.DocRenderController=class extends i.RxDisposable{constructor(t,e,n,r,s,a,c){super(),this._context=t,this._commandService=e,this._docSelectionRenderService=n,this._docSkeletonManagerService=r,this._editorService=s,this._renderManagerService=a,this._univerInstanceService=c,this._addNewRender(),this._initRenderRefresh(),this._initCommandListener()}reRender(t){var a,c;const e=(a=this._renderManagerService.getRenderById(t))==null?void 0:a.with(M.DocSkeletonManagerService),n=e==null?void 0:e.getSkeleton();if(!n||!!n.getViewModel().getDataModel().getSnapshot().disabled)return;n.calculate();const s=this._editorService.getEditor(t);if(this._editorService.isEditor(t)&&!(s!=null&&s.params.scrollBar)){(c=this._context.mainComponent)==null||c.makeDirty();return}this._recalculateSizeBySkeleton(n)}_addNewRender(){const{scene:t,engine:e}=this._context,n=new y.Viewport(he.VIEW_MAIN,t,{left:0,top:0,bottom:0,right:0,isWheelPreventDefaultX:!0});t.attachControl(),t.onMouseWheel$.subscribeEvent((r,s)=>{const a=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);if((a==null?void 0:a.getUnitId())!==this._context.unitId)return;const c=r;if(c.ctrlKey){const l=Math.abs(c.deltaX);let A=l<40?.2:l<80?.4:.2;A*=c.deltaY>0?-1:1,t.scaleX<1&&(A/=2),t.scaleX+A>4?t.scale(4,4):t.scaleX+A<.1?t.scale(.1,.1):c.preventDefault()}else n.onMouseWheel(c,s)}),new y.ScrollBar(n),t.addLayer(new y.Layer(t,[],Lt),new y.Layer(t,[],Pr)),this._addComponent(),e.runRenderLoop(()=>{t.render()}),this._docSelectionRenderService.__attachScrollEvent()}_addComponent(){const{scene:t,unit:e,components:n}=this._context,a={pageMarginLeft:20,pageMarginTop:20},c=new y.Documents(Ae.MAIN,void 0,a);c.zIndex=Hn;const l=new y.DocBackground(Ae.BACKGROUND,void 0,a);l.zIndex=Hn,this._context.mainComponent=c,n.set(Ae.MAIN,c),n.set(Ae.BACKGROUND,l),t.addObjects([c],Lt),t.addObjects([l],_r),this._editorService.getEditor(e.getUnitId())==null&&t.enableLayerCache(Lt)}_initRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(_.takeUntil(this.dispose$)).subscribe(t=>{this._create(t)})}_create(t){var l;if(!t)return;const{mainComponent:e,components:n}=this._context,r=e,s=n.get(Ae.BACKGROUND);r.changeSkeleton(t),s.changeSkeleton(t);const{unitId:a}=this._context,c=this._editorService.getEditor(a);if(this._editorService.isEditor(a)&&!(c!=null&&c.params.scrollBar)){(l=this._context.mainComponent)==null||l.makeDirty();return}this._recalculateSizeBySkeleton(t)}_initCommandListener(){const t=[M.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(t.includes(e.id)){const n=e.params,{unitId:r}=n;this.reRender(r)}}))}_recalculateSizeBySkeleton(t){var f;const{mainComponent:e,scene:n,unitId:r,components:s}=this._context,a=e,c=s.get(Ae.BACKGROUND),l=(f=t.getSkeletonData())==null?void 0:f.pages;if(l==null)return;let A=0,d=0;const h=this._context.unit.getSnapshot().documentStyle.documentFlavor;for(let m=0,p=l.length;m<p;m++){const S=l[m];let{pageWidth:I,pageHeight:v}=S;if(h===i.DocumentFlavor.MODERN){const R=Nl(S);I=R.pageWidth,v=R.pageHeight}a.pageLayoutType===y.PageLayoutType.VERTICAL?(d+=v,d+=a.pageMarginTop,m===p-1&&(d+=a.pageMarginTop),A=Math.max(A,I)):a.pageLayoutType===y.PageLayoutType.HORIZONTAL&&(A+=I,m!==p-1&&(A+=a.pageMarginLeft),d=Math.max(d,v))}a.resize(A,d),c.resize(A,d);const g=this._editorService.getEditor(r);(!this._editorService.isEditor(r)||g!=null&&g.params.scrollBar)&&n.resize(A,d)}};exports.DocRenderController=Pl([ze(1,i.ICommandService),ze(2,i.Inject(exports.DocSelectionRenderService)),ze(3,i.Inject(M.DocSkeletonManagerService)),ze(4,ce),ze(5,y.IRenderManagerService),ze(6,i.IUniverInstanceService)],exports.DocRenderController);function Nl(o){let{pageWidth:t,pageHeight:e}=o;const{marginLeft:n,marginRight:r,marginTop:s,marginBottom:a,skeDrawings:c,skeTables:l}=o;t===Number.POSITIVE_INFINITY&&(t=o.width+n+r),e===Number.POSITIVE_INFINITY&&(e=o.height+s+a);for(const A of c.values())t=Math.max(t,A.aLeft+A.width+n+r),e=Math.max(e,A.aTop+A.height+s+a);for(const A of l.values())t=Math.max(t,A.left+A.width+n+r),e=Math.max(e,A.top+A.height+s+a);return{pageWidth:t,pageHeight:e}}const Uo={id:"doc.command.select-all",type:i.CommandType.COMMAND,handler:async o=>{var h;const t=o.get(i.IUniverInstanceService),e=o.get(M.DocSelectionManagerService),n=t.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),r=e.getDocRanges(),s=(h=r.find(g=>g.isActive))!=null?h:r[0];if(n==null||s==null)return!1;const{segmentId:a}=s,c=n.getUnitId(),l=n.getSelfOrHeaderFooterModel(a).getSnapshot().body;if(l==null)return!1;const{tables:A=[]}=l,d=[];let u=0;for(const g of A){const{startIndex:f,endIndex:m}=g;u!==f&&d.push({startOffset:u,endOffset:f-1,rangeType:i.DOC_RANGE_TYPE.TEXT}),d.push({startOffset:f+3,endOffset:m-5,rangeType:i.DOC_RANGE_TYPE.RECT}),u=m}return u!==l.dataStream.length-2&&d.push({startOffset:u,endOffset:l.dataStream.length-2,rangeType:i.DOC_RANGE_TYPE.TEXT}),e.replaceDocRanges(d,{unitId:c,subUnitId:c},!1),!0}};class Mt extends i.RxDisposable{constructor(e){super();x(this,"_previousActiveRange",null);x(this,"_undoMutationParamsCache",[]);x(this,"_redoMutationParamsCache",[]);this._context=e}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache:e=[],redoCache:n=[]}){this._undoMutationParamsCache=e,this._redoMutationParamsCache=n}getActiveRange(){return this._previousActiveRange}setActiveRange(e){this._previousActiveRange=e}pushUndoRedoMutationParams(e,n){this._undoMutationParamsCache.push(e),this._redoMutationParamsCache.push(n)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:e}=this._undoMutationParamsCache[0],n={unitId:e,actions:this._undoMutationParamsCache.reverse().reduce((s,a)=>i.JSONX.compose(s,a.actions),null),textRanges:[]};return{redoMutationParams:{unitId:e,actions:this._redoMutationParamsCache.reduce((s,a)=>i.JSONX.compose(s,a.actions),null),textRanges:[]},undoMutationParams:n,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Ul=i.SHEET_EDITOR_UNITS,wo={id:"doc.command.ime-input",type:i.CommandType.COMMAND,handler:async(o,t)=>{var w,W,V,k;const{unitId:e,newText:n,oldTextLen:r,isCompositionEnd:s,isCompositionStart:a}=t,c=o.get(i.ICommandService),l=o.get(y.IRenderManagerService),A=o.get(i.IUniverInstanceService),d=o.get(Ce),u=(w=l.getRenderById(e))==null?void 0:w.with(Mt),h=A.getUnit(e,i.UniverInstanceType.UNIVER_DOC);if(h==null||u==null)return!1;const g=u.getActiveRange();if(g==null)return!1;const{style:f,segmentId:m}=g,p=h.getSelfOrHeaderFooterModel(m).getBody();if(p==null)return!1;Object.assign(g,g);const{startOffset:I,endOffset:v}=g,R=n.length,b=[{startOffset:I+R,endOffset:I+R,collapsed:!0,style:f}],E={id:M.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:b}},T=d.getDefaultStyle(),B=d.getStyleCache(),D=so((W=p.customRanges)!=null?W:[],I+r,Ul.includes(e)),U=tn((V=p.textRuns)!=null?V:[],a?v:I+r,T,B),O=ao((k=p.customDecorations)!=null?k:[],I+r),P=new i.TextX,N=i.JSONX.getInstance();if(!g.collapsed&&a){const j=i.BuildTextUtils.selection.delete([g],p,0,null,!1);P.push(...j),E.params.textRanges=[{startOffset:I+R,endOffset:I+R,collapsed:!0}]}else P.push({t:i.TextXActionType.RETAIN,len:I});r>0&&P.push({t:i.TextXActionType.DELETE,len:r}),P.push({t:i.TextXActionType.INSERT,body:{dataStream:n,textRuns:U?[{...U,st:0,ed:n.length}]:[],customRanges:D?[{...D,startIndex:0,endIndex:n.length-1}]:[],customDecorations:O.map(j=>({...j,startIndex:0,endIndex:n.length-1}))},len:n.length});const H=q(h,m);E.params.actions=N.editOp(P.serialize(),H),E.params.noHistory=!s,E.params.isCompositionEnd=s;const F=c.syncExecuteCommand(E.id,E.params);return u.pushUndoRedoMutationParams(F,E.params),!!F}},Gt={type:i.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(o,t)=>{var u,h,g;const e=o.get(i.ICommandService),n=o.get(i.IUndoRedoService),r=o.get(i.IUniverInstanceService);let s=(u=r.getCurrentUniverDocInstance())==null?void 0:u.getUnitId();if(!s)return!1;let a=1;if(t&&(s=(h=t.documentId)!=null?h:s,a=(g=t.zoomRatio)!=null?g:a),!r.getUniverDocInstance(s))return!1;const l={zoomRatio:a,unitId:s},A=Da(o,l);return e.syncExecuteCommand(de.id,l)?(n.pushUndoRedo({unitID:s,undoMutations:[{id:de.id,params:A}],redoMutations:[{id:de.id,params:l}]}),!0):!1}},Qo={id:"doc.table.tab-in-table",type:i.CommandType.COMMAND,handler:async(o,t)=>{var f;const{shift:e}=t,n=o.get(M.DocSelectionManagerService),r=n.getDocRanges(),s=o.get(i.ICommandService),c=o.get(i.IUniverInstanceService).getCurrentUniverDocInstance();if(!c)return!1;const l=(f=r.find(m=>m.isActive))!=null?f:r[0],A=c.getUnitId(),d=le(o,A),u=d==null?void 0:d.getSkeleton(),h=u==null?void 0:u.getViewModel().getSelfOrHeaderFooterViewModel(l==null?void 0:l.segmentId);if(h==null||l==null)return!1;let g=null;if(e?g=Ar(h,l,Xn.PREV):g=Ar(h,l,Xn.NEXT),g){const{startOffset:m,endOffset:p}=g,S=[{startOffset:m,endOffset:p}];return n.replaceDocRanges(S),!0}return e===!1?await s.executeCommand(Do.id,{position:an.BELLOW}):!0}};var wl=Object.defineProperty,Ql=Object.getOwnPropertyDescriptor,Ll=(o,t,e,n)=>{for(var r=n>1?void 0:n?Ql(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&wl(t,e,r),r},Fn=(o,t)=>(e,n)=>t(e,n,o);let qn=class{constructor(o,t,e){x(this,"_docContainer");x(this,"getComponent",o=>{if(this._docContainer=o,!o.getContentRef().current)throw new Error("container is not ready")});x(this,"changeLocale",o=>{this._localeService.setLocale(o)});this._localeService=o,this._injector=t,this._configService=e}getUIConfig(){return{injector:this._injector,config:this._configService.getConfig(Io),changeLocale:this.changeLocale,getComponent:this.getComponent}}getContentRef(){return this._docContainer.getContentRef()}UIDidMount(o){if(this._docContainer)return o(this._docContainer)}getDocContainer(){return this._docContainer}};qn=Ll([Fn(0,i.Inject(i.LocaleService)),Fn(1,i.Inject(i.Injector)),Fn(2,i.IConfigService)],qn);var Fl=Object.defineProperty,Hl=Object.getOwnPropertyDescriptor,kl=(o,t,e,n)=>{for(var r=n>1?void 0:n?Hl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Fl(t,e,r),r},jl=(o,t)=>(e,n)=>t(e,n,o);let Xt=class extends i.RxDisposable{constructor(t){super();x(this,"_docContainerController");this._injector=t,this._docContainerController=this._injector.createInstance(qn)}};Xt=kl([jl(0,i.Inject(i.Injector))],Xt);var Vl=Object.defineProperty,Wl=Object.getOwnPropertyDescriptor,Kl=(o,t,e,n)=>{for(var r=n>1?void 0:n?Wl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Vl(t,e,r),r},Sr=(o,t)=>(e,n)=>t(e,n,o);let Yt=class extends i.Disposable{constructor(o,t){super(),this._docAutoFormatService=o,this._renderManagerService=t,this._initListTabAutoFormat(),this._initListSpaceAutoFormat(),this._initDefaultEnterFormat(),this._initExitListAutoFormat()}_initListTabAutoFormat(){this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:Pe.id,match:o=>{var r;const{selection:t,paragraphs:e,unit:n}=o;if(e.length===1&&t.startOffset===e[0].paragraphStart&&e[0].bullet){const s=(r=n.getBody())==null?void 0:r.paragraphs,a=s==null?void 0:s.filter(c=>{var l;return((l=c.bullet)==null?void 0:l.listId)===e[0].bullet.listId});return(a==null?void 0:a.findIndex(c=>c.startIndex===e[0].startIndex))!==0}else if(e.length>1&&e.some(s=>s.bullet))return!0;return!1},getMutations(o){const t=o.commandParams;return[{id:zt.id,params:{type:t!=null&&t.shift?pt.decrease:pt.increase}}]},priority:100})),this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:Pe.id,match:o=>{const{selection:t,unit:e}=o,{startNodePosition:n,endNodePosition:r}=t,s=this._renderManagerService.getRenderById(e.getUnitId()),a=s==null?void 0:s.with(M.DocSkeletonManagerService).getSkeleton();return a==null?!1:!!(n&&r&&Wr(a,n,r)||n&&!r&&n.path.indexOf("cells")>-1)},getMutations(o){const t=o.commandParams;return[{id:Qo.id,params:{shift:!!(t!=null&&t.shift)}}]},priority:99}))}_initListSpaceAutoFormat(){this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:Et.id,match:o=>{var s;const{selection:t,paragraphs:e,unit:n}=o;if(!t.collapsed||e.length!==1)return!1;const r=(s=n.getBody())==null?void 0:s.dataStream.slice(e[0].paragraphStart,e[0].paragraphEnd-1);return!!(r&&Object.keys(i.QuickListTypeMap).includes(r))},getMutations(o){var r;const{paragraphs:t,unit:e}=o,n=(r=e.getBody())==null?void 0:r.dataStream.slice(t[0].paragraphStart,t[0].paragraphEnd-1);if(n&&Object.keys(i.QuickListTypeMap).includes(n)){const s=i.QuickListTypeMap[n];return[{id:So.id,params:{listType:s,paragraph:t[0]}}]}return[]}}))}_initExitListAutoFormat(){this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:Je.id,match:o=>{const{paragraphs:t}=o;return!!(t.length===1&&t[0].bullet&&t[0].paragraphStart===t[0].paragraphEnd)},getMutations:o=>{const t=o.paragraphs[0].bullet;return t?t.nestingLevel>0?[{id:zt.id,params:{type:pt.decrease}}]:[{id:rt.id,params:{listType:o.paragraphs[0].bullet.listType}}]:[]}}))}_initDefaultEnterFormat(){this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:Je.id,match:()=>!0,getMutations(){return[{id:Bo.id}]},priority:-9999}))}};Yt=Kl([Sr(0,i.Inject(exports.DocAutoFormatService)),Sr(1,y.IRenderManagerService)],Yt);function zl(o){return o.rows[0].cells[0].sections[0].columns[0].lines[0]}function Gl(o){const t=o.rows[o.rows.length-1],e=t.cells[t.cells.length-1];return y.getLastLine(e)}function Xl(o,t){const{ed:e}=o,{skeTables:n}=t;let r=null;for(const s of n.values())if(s.st===e+1){r=s;break}return r}function Ir(o){const t=o==null?void 0:o.parent;let e=null,n=null;if(o==null||t==null)return{lineBeforeTable:e,lineAfterTable:n};const{st:r,ed:s}=o,a=t.type===y.DocumentSkeletonPageType.CELL?[t]:t.parent.pages;return y.lineIterator(a,c=>{c.st===s+1?n=c:c.ed===r-1&&(e=c)}),{lineBeforeTable:e,lineAfterTable:n}}function yi(o){return o.sections[0].columns[0].lines.length===0}function Oi(o){var a,c;const t=o.parent,e=t==null?void 0:t.parent,n=e==null?void 0:e.tableId;if(t==null||e==null)return;const r=t.cells.indexOf(o);let s=e.rows[e.rows.indexOf(t)+1];if(s==null&&n.indexOf("#-#")){const[l,A]=n.split("#-#"),d=(c=(a=e.parent)==null?void 0:a.parent)==null?void 0:c.pages,u=`${l}#-#${Number.parseInt(A)+1}`;if(d)for(const h of d){const{skeTables:g}=h;if(g.has(u)){const f=g.get(u);if(f!=null&&f.rows.length){s=f.rows.find(m=>!m.isRepeatRow);break}}}}if(s!=null){const l=s.cells[r];return yi(l)?Oi(l):l}}function xi(o){var s,a;const t=o.parent,e=t==null?void 0:t.parent;if(t==null||e==null)return;let n=e.rows[e.rows.indexOf(t)-1];const r=t.cells.indexOf(o);if((n==null||n.isRepeatRow)&&e.tableId.indexOf("#-#")){const[c,l]=e.tableId.split("#-#"),A=(a=(s=e.parent)==null?void 0:s.parent)==null?void 0:a.pages,d=`${c}#-#${Number.parseInt(l)-1}`;if(A)for(const u of A){const{skeTables:h}=u;if(h.has(d)){const g=h.get(d);if(g!=null&&g.rows.length){n=g.rows[g.rows.length-1];break}}}}if(n!=null){const c=n.cells[r];return yi(c)?xi(c):c}}function Yl(o,t){const{st:e}=o,{skeTables:n}=t;let r=null;for(const s of n.values())if(s.ed===e-1){r=s;break}return r}function ql(o){return o.sections[0].columns[0].lines[0]}function Jl(o){const t=y.getLastColumn(o);return t.lines[t.lines.length-1]}var Zl=Object.defineProperty,$l=Object.getOwnPropertyDescriptor,eA=(o,t,e,n)=>{for(var r=n>1?void 0:n?$l(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Zl(t,e,r),r},Pt=(o,t)=>(e,n)=>t(e,n,o);let qt=class extends i.Disposable{constructor(t,e,n,r){super();x(this,"_onInputSubscription");this._univerInstanceService=t,this._renderManagerService=e,this._textSelectionManagerService=n,this._commandService=r,this._commandExecutedListener()}dispose(){var t;super.dispose(),(t=this._onInputSubscription)==null||t.unsubscribe()}_commandExecutedListener(){const t=[Ee.id,ve.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!t.includes(e.id))return;const n=e.params;switch(e.id){case Ee.id:return this._handleMoveCursor(n.direction);case ve.id:return this._handleShiftMoveSelection(n.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(t){var v,R,b;const e=this._textSelectionManagerService.getActiveTextRange(),n=this._textSelectionManagerService.getTextRanges(),r=this._univerInstanceService.getCurrentUniverDocInstance();if(r==null)return;const s=(v=this._renderManagerService.getRenderById(r.getUnitId()))==null?void 0:v.with(M.DocSkeletonManagerService).getSkeleton(),a=this._getDocObject();if(e==null||s==null||a==null)return;const{startOffset:c,endOffset:l,style:A,collapsed:d,direction:u,segmentId:h,startNodePosition:g,endNodePosition:f,segmentPage:m}=e;if(n.length>1){let E=Number.POSITIVE_INFINITY,T=Number.NEGATIVE_INFINITY;for(const B of n)E=Math.min(E,B.startOffset),T=Math.max(T,B.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:t===i.Direction.LEFT||t===i.Direction.UP?T:E,endOffset:t===i.Direction.LEFT||t===i.Direction.UP?E:T,style:A}],!1);return}const p=d||u===i.RANGE_DIRECTION.FORWARD?c:l;let S=d||u===i.RANGE_DIRECTION.FORWARD?l:c;const I=(R=r.getSelfOrHeaderFooterModel(h).getBody().dataStream.length)!=null?R:Number.POSITIVE_INFINITY;if(t===i.Direction.LEFT||t===i.Direction.RIGHT){const E=s.findNodeByCharIndex(S-1,h,m),T=s.findNodeByCharIndex(S,h,m);S=t===i.Direction.RIGHT?S+T.count:S-((b=E==null?void 0:E.count)!=null?b:0),S=Math.min(I-2,Math.max(0,S)),this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:S,style:A}],!1),this._scrollToFocusNodePosition(r.getUnitId(),S)}else{const E=s.findNodeByCharIndex(S,h,m),T=a.document.getOffsetConfig(),B=d?g:u===i.RANGE_DIRECTION.FORWARD?f:g,D=this._getTopOrBottomPosition(s,E,B,t===i.Direction.DOWN,!0);if(D==null){const O=t===i.Direction.UP?0:I-2;if(O===S)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:O,style:A}],!1);return}const U=new Ie(T,s).getRangePointData(D,D).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:U.endOffset,style:A}],!1),this._scrollToFocusNodePosition(r.getUnitId(),U.endOffset)}}_handleMoveCursor(t){var I,v,R,b;const e=this._textSelectionManagerService.getActiveTextRange(),n=this._textSelectionManagerService.getTextRanges(),r=this._univerInstanceService.getCurrentUniverDocInstance();if(r==null)return!1;const s=(I=this._renderManagerService.getRenderById(r.getUnitId()))==null?void 0:I.with(M.DocSkeletonManagerService).getSkeleton(),a=this._getDocObject();if(e==null||s==null||a==null||n==null)return;const{startOffset:c,endOffset:l,style:A,collapsed:d,segmentId:u,startNodePosition:h,endNodePosition:g,segmentPage:f}=e,m=r.getSelfOrHeaderFooterModel(u).getBody();if(m==null)return;const p=(v=m.dataStream.length)!=null?v:Number.POSITIVE_INFINITY,S=(R=r.getCustomRanges())!=null?R:[];if(t===i.Direction.LEFT||t===i.Direction.RIGHT){let E;if(!e.collapsed||n.length>1){let D=Number.POSITIVE_INFINITY,U=Number.NEGATIVE_INFINITY;for(const O of n)D=Math.min(D,O.startOffset),U=Math.max(U,O.endOffset);E=t===i.Direction.LEFT?D:U}else{const D=s.findNodeByCharIndex(c-1,u,f),U=s.findNodeByCharIndex(c,u,f),O=s.findNodeByCharIndex(c+1,u,f);t===i.Direction.LEFT?E=Math.max(0,c-((b=D==null?void 0:D.count)!=null?b:1)):E=Math.min(p-2,l+U.count+((O==null?void 0:O.streamType)===i.DataStreamTreeTokenType.SECTION_BREAK?1:0))}const T=[i.DataStreamTreeTokenType.TABLE_START,i.DataStreamTreeTokenType.TABLE_END,i.DataStreamTreeTokenType.TABLE_ROW_START,i.DataStreamTreeTokenType.TABLE_ROW_END,i.DataStreamTreeTokenType.TABLE_CELL_START,i.DataStreamTreeTokenType.TABLE_CELL_END,i.DataStreamTreeTokenType.SECTION_BREAK];if(t===i.Direction.LEFT)for(;T.includes(m.dataStream[E]);)E--;else for(;T.includes(m.dataStream[E]);)E++;S.filter(D=>D.wholeEntity&&D.startIndex<E&&D.endIndex>=E).forEach(D=>{t===i.Direction.LEFT?E=Math.min(D.startIndex,E):E=Math.max(D.endIndex+1,E)}),this._textSelectionManagerService.replaceTextRanges([{startOffset:Math.max(0,E),endOffset:Math.max(0,E),style:A}],!1),this._scrollToFocusNodePosition(r.getUnitId(),E)}else{const E=s.findNodeByCharIndex(c,u,f),T=s.findNodeByCharIndex(l,u,f),B=a.document.getOffsetConfig(),D=this._getTopOrBottomPosition(s,t===i.Direction.UP||d?E:T,t===i.Direction.UP||d?h:g,t===i.Direction.DOWN);if(D==null){let O;d?O=t===i.Direction.UP?0:p-2:O=t===i.Direction.UP?c:l,this._textSelectionManagerService.replaceTextRanges([{startOffset:Math.max(0,O),endOffset:Math.max(0,O),style:A}],!1);return}const U=new Ie(B,s).getRangePointData(D,D).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...U,style:A}],!1),this._scrollToFocusNodePosition(r.getUnitId(),U.endOffset)}}_getTopOrBottomPosition(t,e,n,r,s=!1){if(e==null||n==null)return;const a=this._getGlyphLeftOffsetInLine(e),c=this._getNextOrPrevLine(e,r,s);if(c==null)return;const l=this._matchPositionByLeftOffset(t,c,a,n);if(l!=null)return{...l,isBack:!0}}_getGlyphLeftOffsetInLine(t){const e=t.parent;if(e==null)return Number.NEGATIVE_INFINITY;const n=e.left,{left:r}=t;return n+r}_matchPositionByLeftOffset(t,e,n,r){const s={distance:Number.POSITIVE_INFINITY};for(const c of e.divides){const l=c.left;for(const A of c.glyphGroup){if(A.streamType===i.DataStreamTreeTokenType.SECTION_BREAK)continue;const{left:d}=A,u=l+d,h=Math.abs(n-u);h<s.distance&&(s.glyph=A,s.distance=h)}}if(s.glyph==null)return;const{segmentPage:a}=r;return t.findPositionByGlyph(s.glyph,a)}_getNextOrPrevLine(t,e,n=!1){var m,p,S,I,v,R,b,E,T,B,D,U;const r=t.parent,s=r==null?void 0:r.parent,a=s==null?void 0:s.parent,c=a==null?void 0:a.parent,l=c==null?void 0:c.parent;if(r==null||s==null||a==null||c==null||l==null)return;const A=a.lines.indexOf(s);if(A===-1)return;let d;if(l.type===y.DocumentSkeletonPageType.CELL&&n){const O=Er(l,e);if(O)return O}if(e===!0){d=a.lines[A+1];const O=Xl(s,l);if(O){const P=zl(O);P&&(d=P)}}else{d=a.lines[A-1];const O=Yl(s,l);if(O){const P=Gl(O);P&&(d=P)}}if(d!=null)return d;const u=c.columns.indexOf(a);if(u===-1)return;if(e===!0)d=(m=c.columns[u+1])==null?void 0:m.lines[0];else{const O=(S=(p=c.columns)==null?void 0:p[u-1])==null?void 0:S.lines;d=O==null?void 0:O[O.length-1]}if(d!=null)return d;const h=l.sections.indexOf(c);if(h===-1)return;if(e===!0)d=(v=(I=l.sections[h-1])==null?void 0:I.columns[0])==null?void 0:v.lines[0];else{const O=(b=(R=l.sections)==null?void 0:R[h-1])==null?void 0:b.columns,P=O==null?void 0:O[O.length-1],N=P==null?void 0:P.lines;d=N==null?void 0:N[N.length-1]}if(d!=null)return d;if(l.type===y.DocumentSkeletonPageType.CELL)return Er(l,e);const g=l.parent;if(g==null)return;const f=g.pages.indexOf(l);if(f!==-1){if(e===!0)d=(B=(T=(E=g.pages[f+1])==null?void 0:E.sections[0])==null?void 0:T.columns[0])==null?void 0:B.lines[0];else{const O=(D=g.pages[f-1])==null?void 0:D.sections;if(O==null)return;const P=(U=O[O.length-1])==null?void 0:U.columns,N=P[P.length-1],H=N==null?void 0:N.lines;d=H[H.length-1]}if(d!=null)return d}}_scrollToFocusNodePosition(t,e){var r;const n=(r=this._renderManagerService.getRenderById(t))==null?void 0:r.with(exports.DocBackScrollRenderController);n!=null&&n.scrollToRange({startOffset:e,endOffset:e,collapsed:!0})}_getDocObject(){return Nr(this._univerInstanceService,this._renderManagerService)}};qt=eA([Pt(0,i.IUniverInstanceService),Pt(1,y.IRenderManagerService),Pt(2,i.Inject(M.DocSelectionManagerService)),Pt(3,i.ICommandService)],qt);function Er(o,t){var n,r;let e=null;if(t===!0){const s=Oi(o);if(s)e=ql(s);else{const a=(n=o.parent)==null?void 0:n.parent,{lineAfterTable:c}=Ir(a);c&&(e=c)}}else{const s=xi(o);if(s)e=Jl(s);else{const a=(r=o.parent)==null?void 0:r.parent,{lineBeforeTable:c}=Ir(a);c&&(e=c)}}return e}const tA="univer-create",nA="univer-create-item",oA="univer-create-label",rA="univer-create-input",Me={create:tA,createItem:nA,createLabel:oA,createInput:rA},iA=({handleRowColChange:o,tableCreateParams:t})=>{const e=i.useDependency(i.LocaleService),[n,r]=L.useState(3),[s,a]=L.useState(5);function c(l,A){r(l),a(A),o(l,A)}return L.useEffect(()=>{r(t.rowCount),a(t.colCount)},[t]),Q.jsxs("div",{className:Me.create,children:[Q.jsxs("div",{className:Me.createItem,children:[Q.jsx("span",{className:Me.createLabel,children:e.t("toolbar.table.rowCount")}),Q.jsx(ae.InputNumber,{min:1,max:20,precision:0,value:n,onChange:l=>{c(l,s)},className:Me.createInput})]}),Q.jsxs("div",{className:Me.createItem,children:[Q.jsx("span",{className:Me.createLabel,children:e.t("toolbar.table.colCount")}),Q.jsx(ae.InputNumber,{min:1,max:20,precision:0,value:s,onChange:l=>{c(n,l)},className:Me.createInput})]})]})};var sA=Object.defineProperty,aA=Object.getOwnPropertyDescriptor,cA=(o,t,e,n)=>{for(var r=n>1?void 0:n?aA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&sA(t,e,r),r},vr=(o,t)=>(e,n)=>t(e,n,o);let Jt=class extends i.Disposable{constructor(o,t){super(),this._commandService=o,this._componentManager=t,this._initialize()}_initialize(){this._init(),this._registerCommands(),this._initCustomComponents()}_registerCommands(){[bn].forEach(o=>this.disposeWithMe(this._commandService.registerCommand(o)))}_initCustomComponents(){const o=this._componentManager;this.disposeWithMe(o.register(vi,iA))}_init(){}};Jt=cA([vr(0,i.ICommandService),vr(1,i.Inject(C.ComponentManager))],Jt);const Jn=4;var lA=Object.defineProperty,AA=Object.getOwnPropertyDescriptor,dA=(o,t,e,n)=>{for(var r=n>1?void 0:n?AA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&lA(t,e,r),r},Nt=(o,t)=>(e,n)=>t(e,n,o);function Di(o,t){const e=Cr(o.left,o.top,t),n=Cr(o.right,o.bottom,t);return{left:e.x,top:e.y,right:n.x,bottom:n.y}}function Cr(o,t,e){const{scaleX:n,scaleY:r}=e.getAncestorScale(),s=e.getViewport(he.VIEW_MAIN);if(!s)return{x:o,y:t};const{viewportScrollX:a,viewportScrollY:c}=s,l=(o-a)*n,A=(t-c)*r;return{x:l,y:A}}function Tr(o,t,e){const{scaleX:n,scaleY:r}=e.getAncestorScale(),s=e.getViewport(he.VIEW_MAIN);if(!s)return{x:o,y:t};const{viewportScrollX:a,viewportScrollY:c}=s,l=o/n+a,A=t/r+c;return{x:l,y:A}}const jt=(o,t)=>{const{scene:e,mainComponent:n,engine:r}=t,s=t.with(M.DocSkeletonManagerService).getSkeleton(),a=s.findNodePositionByCharIndex(o.startOffset,!0,o.segmentId,o.segmentPage),c=s.findNodePositionByCharIndex(o.endOffset,!0,o.segmentId,o.segmentPage),l=n;if(!c||!a)return;const A=l.getOffsetConfig(),{docsLeft:d,docsTop:u}=A,h=r.getCanvasElement(),g=h.getBoundingClientRect(),f=y.pxToNum(h.style.width),{top:m,left:p,width:S}=g,I=S/f,{scaleX:v,scaleY:R}=e.getAncestorScale(),b=new Ie(A,s),{borderBoxPointGroup:E}=b.getRangePointData(a,c);return nn(E).map(D=>Di(D,e)).map(D=>({left:(D.left+d*v)*I+p,right:(D.right+d*v)*I+p,top:(D.top+u*R)*I+m,bottom:(D.bottom+u*R)*I+m}))};exports.DocCanvasPopManagerService=class extends i.Disposable{constructor(t,e,n,r){super(),this._globalPopupManagerService=t,this._renderManagerService=e,this._univerInstanceService=n,this._commandService=r}_createObjectPositionObserver(t,e){const n=()=>{const{scene:l,engine:A}=e,{left:d,top:u,width:h,height:g}=t,f={left:d,right:d+h,top:u,bottom:u+g},m=A.getCanvasElement(),p=m.getBoundingClientRect(),S=y.pxToNum(m.style.width),I=Di(f,l),{top:v,left:R,width:b}=p,E=b/S;return{left:I.left*E+R,right:I.right*E+R,top:I.top*E+v,bottom:I.bottom*E+v}},r=n(),s=new _.BehaviorSubject(r),a=new i.DisposableCollection;a.add(this._commandService.onCommandExecuted(l=>{if(l.id===de.id||l.id===M.RichTextEditingMutation.id){const A=n();A&&s.next(A)}}));const c=e.scene.getViewport(he.VIEW_MAIN);return c&&a.add(c.onScrollAfter$.subscribeEvent(()=>{s.next(n())})),{position:r,position$:s,disposable:a}}_createRangePositionObserver(t,e){var c;const n=(c=jt(t,e))!=null?c:[],r=new _.BehaviorSubject(n),s=new i.DisposableCollection;s.add(this._commandService.onCommandExecuted(l=>{if((l.id===de.id||l.id===M.RichTextEditingMutation.id)&&l.params.unitId===e.unitId){const d=jt(t,e);d&&r.next(d)}}));const a=e.scene.getViewport(he.VIEW_MAIN);return a&&s.add(a.onScrollAfter$.subscribeEvent(()=>{const l=jt(t,e);l&&r.next(l)})),{positions:n,positions$:r,disposable:s}}attachPopupToObject(t,e,n){const r=this._renderManagerService.getRenderById(n);if(!r)throw new Error(`Current render not found, unitId: ${n}`);const{position:s,position$:a,disposable:c}=this._createObjectPositionObserver(t,r),l=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:s,anchorRect$:a,canvasElement:r.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(l),a.complete(),c.dispose()}}}attachPopupToRange(t,e,n){if(!this._univerInstanceService.getUnit(n))throw new Error(`Document not found, unitId: ${n}`);const{direction:s="top",multipleDirection:a}=e,c=this._renderManagerService.getRenderById(n);if(!c)throw new Error(`Current render not found, unitId: ${n}`);const{positions:l,positions$:A,disposable:d}=this._createRangePositionObserver(t,c),u=A.pipe(_.map(g=>s.includes("top")?g[0]:g[g.length-1])),h=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:s.includes("top")?l[0]:l[l.length-1],anchorRect$:u,excludeRects:l,excludeRects$:A,direction:s.includes("top")||s.includes("bottom")?l.length>1?a:s:"bottom",canvasElement:c.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(h),A.complete(),d.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==h}}};exports.DocCanvasPopManagerService=dA([Nt(0,i.Inject(C.ICanvasPopupService)),Nt(1,y.IRenderManagerService),Nt(2,i.IUniverInstanceService),Nt(3,i.ICommandService)],exports.DocCanvasPopManagerService);var uA=Object.defineProperty,gA=Object.getOwnPropertyDescriptor,hA=(o,t,e,n)=>{for(var r=n>1?void 0:n?gA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&uA(t,e,r),r},mA=(o,t)=>(e,n)=>t(e,n,o);const fA=(o,t,e,n)=>{var h,g,f,m,p;const r=e.findNodePositionByCharIndex(o.startOffset,!0,o.segmentId,n),s=e.getSkeletonData();let a=o.endOffset;if(o.segmentId){const S=(p=Array.from((g=(h=s==null?void 0:s.skeFooters.get(o.segmentId))==null?void 0:h.values())!=null?g:[])[0])!=null?p:Array.from((m=(f=s==null?void 0:s.skeHeaders.get(o.segmentId))==null?void 0:f.values())!=null?m:[])[0];S&&(a=Math.min(S.ed,a))}const c=e.findNodePositionByCharIndex(a,!0,o.segmentId,n);if(!c||!r)return;const l=t.getOffsetConfig(),A=new Ie(l,e),{borderBoxPointGroup:d}=A.getRangePointData(r,c);return nn(d).map(S=>({top:S.top+l.docsTop-Jn,bottom:S.bottom+l.docsTop+Jn,left:S.left+l.docsLeft,right:S.right+l.docsLeft}))},pA=(o,t,e,n=-1)=>{const r=e.findPositionByGlyph(o,n);if(!r)return;const s=t.getOffsetConfig(),a={...r,isBack:!0},c=new Ie(s,e),{borderBoxPointGroup:l}=c.getRangePointData(a,a),d=nn(l)[0];return{top:d.top+s.docsTop,bottom:d.bottom+s.docsTop,left:d.left+s.docsLeft,right:d.left+s.docsLeft+o.width}};exports.DocEventManagerService=class extends i.Disposable{constructor(e,n){super();x(this,"_hoverCustomRanges$",new _.BehaviorSubject([]));x(this,"hoverCustomRanges$",this._hoverCustomRanges$.pipe(_.distinctUntilChanged((e,n)=>e.length===n.length&&e.every((r,s)=>n[s].range.rangeId===r.range.rangeId&&n[s].segmentId===r.segmentId&&n[s].segmentPageIndex===r.segmentPageIndex&&n[s].range.startIndex===r.range.startIndex))));x(this,"_clickCustomRanges$",new _.Subject);x(this,"clickCustomRanges$",this._clickCustomRanges$.asObservable());x(this,"_hoverBullet$",new _.Subject);x(this,"hoverBullet$",this._hoverBullet$.pipe(_.distinctUntilChanged((e,n)=>(e==null?void 0:e.paragraph.startIndex)===(n==null?void 0:n.paragraph.startIndex)&&(e==null?void 0:e.segmentId)===(n==null?void 0:n.segmentId)&&(e==null?void 0:e.segmentPageIndex)===(n==null?void 0:n.segmentPageIndex))));x(this,"_clickBullet$",new _.Subject);x(this,"clickBullets$",this._clickBullet$.asObservable());x(this,"_customRangeDirty",!0);x(this,"_bulletDirty",!0);x(this,"_customRangeBounds",[]);x(this,"_bulletBounds",[]);this._context=e,this._docSkeletonManagerService=n,this._initResetDirty(),this._initEvents(),this._initPointer()}get _skeleton(){return this._docSkeletonManagerService.getSkeleton()}get _documents(){return this._context.mainComponent}dispose(){this._hoverCustomRanges$.complete(),this._clickCustomRanges$.complete(),super.dispose()}_initPointer(){let e=y.CURSOR_TYPE.TEXT;this.disposeWithMe(this.hoverCustomRanges$.subscribe(n=>{n.length?(e=this._context.scene.getCursor(),this._context.scene.setCursor(y.CURSOR_TYPE.POINTER)):this._context.scene.setCursor(e)}))}_initResetDirty(){this.disposeWithMe(this._skeleton.dirty$.subscribe(()=>{this._customRangeDirty=!0,this._bulletDirty=!0})),this.disposeWithMe(i.fromEventSubject(this._context.engine.onTransformChange$).pipe(_.filter(e=>e.type===y.TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize)).subscribe(()=>{this._customRangeDirty=!0,this._bulletDirty=!0}))}_initEvents(){this.disposeWithMe(i.fromEventSubject(this._context.scene.onPointerMove$).pipe(_.throttleTime(30)).subscribe(r=>{this._hoverCustomRanges$.next(this._calcActiveRanges(r)),this._hoverBullet$.next(this._calcActiveBullet(r))})),this.disposeWithMe(this._context.scene.onPointerEnter$.subscribeEvent(()=>{this._hoverBullet$.next(null),this._hoverCustomRanges$.next([])}));const e=i.fromEventSubject(this._context.mainComponent.onPointerDown$),n=i.fromEventSubject(this._context.scene.onPointerUp$);this.disposeWithMe(e.pipe(_.switchMap(r=>n.pipe(_.take(1),_.map(s=>({down:r,up:s})))),_.filter(({down:r,up:s})=>r.target===s.target&&s.timeStamp-r.timeStamp<300)).subscribe(({down:r})=>{if(r.button===2)return;const s=this._calcActiveRanges(r);s.length&&this._clickCustomRanges$.next(s.pop());const a=this._calcActiveBullet(r);a&&this._clickBullet$.next(a)}))}_buildCustomRangeBoundsBySegment(e,n=-1){var a,c,l;const r=(l=(c=(a=this._context.unit.getSelfOrHeaderFooterModel(e))==null?void 0:a.getBody())==null?void 0:c.customRanges)!=null?l:[],s=[];return r.forEach(A=>{const d={startOffset:A.startIndex,endOffset:A.endIndex+1,collapsed:!1,segmentId:e},u=fA(d,this._documents,this._skeleton,n);if(!u)return null;s.push({customRange:A,rects:u,segmentId:e,segmentPageIndex:n})}),s}_buildCustomRangeBounds(){var n;if(!this._customRangeDirty)return;this._customRangeDirty=!1;const e=[];e.push(...this._buildCustomRangeBoundsBySegment()),(n=this._skeleton.getSkeletonData())==null||n.pages.forEach((r,s)=>{r.headerId&&e.push(...this._buildCustomRangeBoundsBySegment(r.headerId,s)),r.footerId&&e.push(...this._buildCustomRangeBoundsBySegment(r.footerId,s))}),this._customRangeBounds=e}_calcActiveRanges(e){this._buildCustomRangeBounds();const{offsetX:n,offsetY:r}=e,{x:s,y:a}=Tr(n,r,this._context.scene);return this._customRangeBounds.filter(l=>l.rects.some(A=>{const{left:d,right:u,top:h,bottom:g}=A;return s>=d&&s<=u&&a>=h&&a<=g})).map(l=>({segmentId:l.segmentId,range:l.customRange,segmentPageIndex:l.segmentPageIndex,rects:l.rects}))}_buildBulletBoundsBySegment(e,n=-1){var A,d,u,h,g;const r=(A=this._context.unit.getSelfOrHeaderFooterModel(e))==null?void 0:A.getBody(),s=((d=r==null?void 0:r.paragraphs)!=null?d:[]).filter(f=>f.bullet&&f.bullet.listType.indexOf("CHECK_LIST")===0),a=[],c=this._skeleton.getSkeletonData();if(!c)return a;const l=f=>{var m,p,S;for(const I of f){const v=[...I.sections];if(I.skeTables){const R=Array.from(I.skeTables.values());v.push(...R.map(b=>b.rows.map(E=>E.cells.map(T=>T.sections))).flat(4))}for(const R of v)for(const b of R.columns)for(const E of b.lines)if(E.paragraphStart){const T=s.find(B=>B.startIndex===E.paragraphIndex);if(T){const B=E,D=(S=(p=(m=B==null?void 0:B.divides)==null?void 0:m[0])==null?void 0:p.glyphGroup)==null?void 0:S[0];if(!D)continue;const U=pA(D,this._documents,this._skeleton,n);if(!U)continue;a.push({rect:U,segmentId:e,segmentPageIndex:n,paragraph:T})}}}return a};if(e){const f=(g=(u=c.skeFooters.get(e))==null?void 0:u.values())!=null?g:(h=c.skeHeaders.get(e))==null?void 0:h.values();return f?l(Array.from(f)):a}return l(c.pages)}_buildBulletBounds(){var e;this._bulletDirty&&(this._bulletDirty=!1,this._bulletBounds=[],this._bulletBounds.push(...this._buildBulletBoundsBySegment()),(e=this._skeleton.getSkeletonData())==null||e.pages.forEach((n,r)=>{n.headerId&&this._bulletBounds.push(...this._buildBulletBoundsBySegment(n.headerId,r)),n.footerId&&this._bulletBounds.push(...this._buildBulletBoundsBySegment(n.footerId,r))}))}_calcActiveBullet(e){this._buildBulletBounds();const{offsetX:n,offsetY:r}=e,{x:s,y:a}=Tr(n,r,this._context.scene);return this._bulletBounds.find(l=>{const{left:A,right:d,top:u,bottom:h}=l.rect;return s>=A&&s<=d&&a>=u&&a<=h})}};exports.DocEventManagerService=hA([mA(1,i.Inject(M.DocSkeletonManagerService))],exports.DocEventManagerService);var SA=Object.defineProperty,IA=Object.getOwnPropertyDescriptor,EA=(o,t,e,n)=>{for(var r=n>1?void 0:n?IA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&SA(t,e,r),r},Ut=(o,t)=>(e,n)=>t(e,n,o);let Zn=class extends i.Disposable{constructor(o,t,e,n,r){super(),this._context=o,this._docSkeletonManagerService=t,this._commandService=e,this._docEventManagerService=n,this._textSelectionManagerService=r,this._initPointerDownObserver(),this._initHoverCursor()}_initPointerDownObserver(){this._docEventManagerService.clickBullets$.subscribe(o=>{const t=this._textSelectionManagerService.getTextRanges();this._commandService.executeCommand(rn.id,{index:o.paragraph.startIndex,segmentId:o.segmentId,textRanges:t})})}_initHoverCursor(){this.disposeWithMe(this._docEventManagerService.hoverBullet$.subscribe(o=>{o?this._context.mainComponent.setCursor(y.CURSOR_TYPE.POINTER):this._context.mainComponent.setCursor(y.CURSOR_TYPE.TEXT)}))}_getTransformCoordForDocumentOffset(o,t,e,n){const{documentTransform:r}=o.getOffsetConfig(),s=t.transformVector2SceneCoord(y.Vector2.FromArray([e,n]));if(s)return r.clone().invert().applyPoint(s)}};Zn=EA([Ut(1,i.Inject(M.DocSkeletonManagerService)),Ut(2,i.ICommandService),Ut(3,i.Inject(exports.DocEventManagerService)),Ut(4,i.Inject(M.DocSelectionManagerService))],Zn);var vA=Object.defineProperty,CA=Object.getOwnPropertyDescriptor,TA=(o,t,e,n)=>{for(var r=n>1?void 0:n?CA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&vA(t,e,r),r},ut=(o,t)=>(e,n)=>t(e,n,o);let Zt=class extends i.RxDisposable{constructor(o,t,e,n,r,s){super(),this._context=o,this._commandService=t,this._docClipboardService=e,this._docSelectionRenderService=n,this._contextService=r,this._editorService=s,this._init()}_init(){this._initLegacyPasteCommand()}_initLegacyPasteCommand(){var o;(o=this._docSelectionRenderService)==null||o.onPaste$.pipe(_.takeUntil(this.dispose$)).subscribe(t=>{var c,l,A;if(!mn(this._contextService))return;t.event.preventDefault();const e=t.event;let n=(c=e.clipboardData)==null?void 0:c.getData(C.HTML_CLIPBOARD_MIME_TYPE);const r=(l=e.clipboardData)==null?void 0:l.getData(C.PLAIN_TEXT_CLIPBOARD_MIME_TYPE),s=[...((A=e.clipboardData)==null?void 0:A.items)||[]].filter(d=>C.imageMimeTypeSet.has(d.type)).map(d=>d.getAsFile()).filter(d=>!!d);this._editorService.getEditor(this._context.unitId)&&(n!=null?n:"").indexOf("</table>")>-1&&(n=""),this._docClipboardService.legacyPaste({html:n,text:r,files:s})})}};Zt=TA([ut(1,i.ICommandService),ut(2,st),ut(3,i.Inject(exports.DocSelectionRenderService)),ut(4,i.IContextService),ut(5,ce)],Zt);var RA=Object.defineProperty,bA=Object.getOwnPropertyDescriptor,yA=(o,t,e,n)=>{for(var r=n>1?void 0:n?bA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&RA(t,e,r),r},Rr=(o,t)=>(e,n)=>t(e,n,o);const OA=[i.DEFAULT_EMPTY_DOCUMENT_VALUE,i.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,i.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let $n=class extends i.Disposable{constructor(o,t,e){super(),this._context=o,this._contextMenuService=t,this._commandService=e,OA.includes(this._context.unitId)||(this._initPointerDown(),this._initEditChange())}_initPointerDown(){var e,n;const t=((n=(e=this._context)==null?void 0:e.mainComponent)==null?void 0:n.onPointerDown$).subscribeEvent(r=>{r.button===2&&this._contextMenuService.triggerContextMenu(r,C.ContextMenuPosition.MAIN_AREA)});this.disposeWithMe(t)}_initEditChange(){this.disposeWithMe(this._commandService.onCommandExecuted(o=>{o.id===M.RichTextEditingMutation.id&&this._contextMenuService.visible&&this._contextMenuService.hideContextMenu()}))}};$n=yA([Rr(1,C.IContextMenuService),Rr(2,i.ICommandService)],$n);var xA=Object.defineProperty,DA=Object.getOwnPropertyDescriptor,MA=(o,t,e,n)=>{for(var r=n>1?void 0:n?DA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&xA(t,e,r),r},Ge=(o,t)=>(e,n)=>t(e,n,o);let $t=class extends i.Disposable{constructor(t,e,n,r,s,a,c){super();x(this,"_initialEditors",new Set);this._context=t,this._univerInstanceService=e,this._editorService=n,this._commandService=r,this._docSelectionRenderService=s,this._docSkeletonManagerService=a,this._renderManagerService=c,this._initialize()}_initialize(){this._editorService.getAllEditor().forEach(t=>{const e=t.getEditorId();e===this._context.unitId&&(this._initialEditors.has(e)||(this._initialEditors.add(e),this._resize(e)))}),this._commandExecutedListener(),this._initialBlur(),this._initialFocus()}_resize(t){if(t==null)return;const e=this._editorService.getEditor(t);if((e==null?void 0:e.cancelDefaultResizeListener)===!0)return;const n=this._univerInstanceService.getUniverDocInstance(t);if(!n)return;const r=this._docSkeletonManagerService.getSkeleton();if(e==null||e.render==null||r==null||n==null)return;r.calculate();const{marginTop:s=0,marginBottom:a=0,marginLeft:c=0,marginRight:l=0}=n.getSnapshot().documentStyle,{scene:A,mainComponent:d}=e.render;let{actualHeight:u,actualWidth:h}=r.getActualSize();u+=s+a,h+=c+l;const{width:g,height:f}=e.getBoundingClientRect(),m=Math.max(h,g),p=Math.max(u,f);A.transformByState({width:m,height:p}),d==null||d.resize(m,p)}_initialBlur(){this.disposeWithMe(this._editorService.blur$.subscribe(()=>{this._docSelectionRenderService.blur()})),this.disposeWithMe(this._docSelectionRenderService.onBlur$.subscribe(()=>{const{unitId:t}=this._context,e=this._editorService.getEditor(t),n=this._editorService.getFocusEditor();e==null||e.isSheetEditor()||n&&n.getEditorId()===t||t.includes("range_selector")||t.includes("embedding_formula_editor")||this._editorService.blur()}))}_initialFocus(){const t=["univer-formula-search","univer-formula-help","formula-help-decorator","univer-formula-help-param"];this.disposeWithMe(_.fromEvent(window,"mousedown").subscribe(n=>{const s=n.target.classList[0]||"";i.checkForSubstrings(s,t)&&n.stopPropagation()})),this._univerInstanceService.getAllUnitsForType(i.UniverInstanceType.UNIVER_SHEET).forEach(n=>{const r=n.getUnitId(),s=this._renderManagerService.getRenderById(r),a=s==null?void 0:s.engine.getCanvas().getCanvasEle();a!=null&&_.fromEvent(a,"mousedown").subscribe(c=>{c.stopPropagation()})})}_commandExecutedListener(){const t=[M.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(t.includes(e.id)){const n=e.params,{unitId:r}=n;if(this._editorService.isSheetEditor(r)||r!==this._context.unitId)return;const s=this._editorService.getEditor(r);s&&!s.params.scrollBar&&this._resize(r)}}))}};$t=MA([Ge(1,i.IUniverInstanceService),Ge(2,ce),Ge(3,i.ICommandService),Ge(4,i.Inject(exports.DocSelectionRenderService)),Ge(5,i.Inject(M.DocSkeletonManagerService)),Ge(6,y.IRenderManagerService)],$t);var BA=Object.defineProperty,_A=Object.getOwnPropertyDescriptor,PA=(o,t,e,n)=>{for(var r=n>1?void 0:n?_A(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&BA(t,e,r),r},wt=(o,t)=>(e,n)=>t(e,n,o);let eo=class extends i.Disposable{constructor(t,e,n,r,s){super();x(this,"_previousIMEContent","");x(this,"_isCompositionStart",!0);x(this,"_onStartSubscription");x(this,"_onUpdateSubscription");x(this,"_onEndSubscription");this._context=t,this._docSelectionRenderService=e,this._docImeInputManagerService=n,this._docSkeletonManagerService=r,this._commandService=s,this._initialize()}dispose(){var t,e,n;(t=this._onStartSubscription)==null||t.unsubscribe(),(e=this._onUpdateSubscription)==null||e.unsubscribe(),(n=this._onEndSubscription)==null||n.unsubscribe()}_initialize(){this._initialOnCompositionstart(),this._initialOnCompositionUpdate(),this._initialOnCompositionend()}_initialOnCompositionstart(){this._onStartSubscription=this._docSelectionRenderService.onCompositionstart$.subscribe(t=>{if(t==null)return;this._resetIME();const{activeRange:e}=t;e!=null&&this._docImeInputManagerService.setActiveRange(i.Tools.deepClone(e))})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._docSelectionRenderService.onCompositionupdate$.subscribe(t=>{this._updateContent(t,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._docSelectionRenderService.onCompositionend$.subscribe(t=>{this._updateContent(t,!1)})}async _updateContent(t,e){if(t==null)return;const n=this._context.unitId,r=this._docSkeletonManagerService.getSkeleton(),{event:s,activeRange:a}=t;if(r==null||a==null)return;const l=s.data;l===this._previousIMEContent&&e||(await this._commandService.executeCommand(wo.id,{unitId:n,newText:l,oldTextLen:this._previousIMEContent.length,isCompositionStart:this._isCompositionStart,isCompositionEnd:!e}),e?(this._isCompositionStart&&(this._isCompositionStart=!1),this._previousIMEContent=l):this._resetIME())}_resetIME(){this._previousIMEContent="",this._isCompositionStart=!0,this._docImeInputManagerService.clearUndoRedoMutationParamsCache(),this._docImeInputManagerService.setActiveRange(null)}};eo=PA([wt(1,i.Inject(exports.DocSelectionRenderService)),wt(2,i.Inject(Mt)),wt(3,i.Inject(M.DocSkeletonManagerService)),wt(4,i.ICommandService)],eo);var NA=Object.defineProperty,UA=Object.getOwnPropertyDescriptor,wA=(o,t,e,n)=>{for(var r=n>1?void 0:n?UA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&NA(t,e,r),r},Qt=(o,t)=>(e,n)=>t(e,n,o);let to=class extends i.Disposable{constructor(t,e,n,r,s){super();x(this,"_onInputSubscription");this._context=t,this._docSelectionRenderService=e,this._docSkeletonManagerService=n,this._commandService=r,this._docMenuStyleService=s,this._init()}dispose(){var t;super.dispose(),(t=this._onInputSubscription)==null||t.unsubscribe()}_init(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._docSelectionRenderService.onInput$.subscribe(async t=>{var p,S,I;if(t==null)return;const{unitId:e}=this._context,{event:n,content:r="",activeRange:s}=t,a=n,c=this._docSkeletonManagerService.getSkeleton();if(a.data==null||c==null||s==null)return;const{segmentId:l}=s,d=this._context.unit.getSelfOrHeaderFooterModel(l).getBody(),u=this._docMenuStyleService.getDefaultStyle(),h=this._docMenuStyleService.getStyleCache(),g=so((p=d==null?void 0:d.customRanges)!=null?p:[],s.endOffset,i.SHEET_EDITOR_UNITS.includes(e)),f=tn((S=d==null?void 0:d.textRuns)!=null?S:[],s.endOffset,u,h),m=ao((I=d==null?void 0:d.customDecorations)!=null?I:[],s.endOffset);await this._commandService.executeCommand(dn.id,{unitId:e,body:{dataStream:r,textRuns:f?[{...f,st:0,ed:r.length}]:[],customRanges:g?[{...g,startIndex:0,endIndex:r.length-1}]:[],customDecorations:m.map(v=>({...v,startIndex:0,endIndex:r.length-1}))},range:s,segmentId:l}),r===" "&&await this._commandService.executeCommand(Et.id)})}};to=wA([Qt(1,i.Inject(exports.DocSelectionRenderService)),Qt(2,i.Inject(M.DocSkeletonManagerService)),Qt(3,i.ICommandService),Qt(4,i.Inject(Ce))],to);class Lo extends i.Disposable{constructor(t){super(),this._context=t}calculatePagePosition(){var R,b;const t=Se(this._context),n=(b=(R=this._context.unit.getSettings())==null?void 0:R.zoomRatio)!=null?b:1,{document:r,scene:s,docBackground:a}=t,c=s==null?void 0:s.getParent(),{width:l,height:A,pageMarginLeft:d,pageMarginTop:u}=r;if(c==null||l===Number.POSITIVE_INFINITY||A===Number.POSITIVE_INFINITY)return;const{width:h,height:g}=c;let f=0,m=u,p=0,S=0,I=Number.POSITIVE_INFINITY;h>(l+d*2)*n?(f=h/2-l*n/2,f/=n,p=(h-d*2)/n,I=0):(f=d,p=l+d*2,I=(p-h/n)/2),g>A?S=(g-u*2)/n:S=A+u*2,s.resize(p,S),h<=1&&(f=-1e4,m=-1e4),r.translate(f,m),a.translate(f,m);const v=s.getViewport(he.VIEW_MAIN);return I!==Number.POSITIVE_INFINITY&&v!=null&&v.scrollToViewportPos({viewportScrollX:I}),this}}var QA=Object.defineProperty,LA=Object.getOwnPropertyDescriptor,FA=(o,t,e,n)=>{for(var r=n>1?void 0:n?LA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&QA(t,e,r),r},br=(o,t)=>(e,n)=>t(e,n,o);let no=class extends i.Disposable{constructor(o,t,e){super(),this._context=o,this._docPageLayoutService=t,this._textSelectionManagerService=e;const n=this._context.unitId;if(i.isInternalEditorID(n)&&n!==i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)return this;this._initResize()}_initResize(){this.disposeWithMe(i.fromEventSubject(this._context.engine.onTransformChange$).pipe(_.filter(o=>o.type===y.TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize),_.throttleTime(0,_.animationFrameScheduler)).subscribe(()=>{this._docPageLayoutService.calculatePagePosition(),this._textSelectionManagerService.refreshSelection()}))}};no=FA([br(1,i.Inject(Lo)),br(2,i.Inject(M.DocSelectionManagerService))],no);var HA=Object.defineProperty,kA=Object.getOwnPropertyDescriptor,jA=(o,t,e,n)=>{for(var r=n>1?void 0:n?kA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&HA(t,e,r),r},Xe=(o,t)=>(e,n)=>t(e,n,o);let oo=class extends i.Disposable{constructor(t,e,n,r,s,a,c){super();x(this,"_loadedMap",new WeakSet);this._context=t,this._commandService=e,this._editorService=n,this._instanceSrv=r,this._docSelectionRenderService=s,this._docSkeletonManagerService=a,this._docSelectionManagerService=c,this._initialize()}_initialize(){this._init(),this._skeletonListener(),this._commandExecutedListener(),this._refreshListener(),this._syncSelection()}_init(){const{unitId:t}=this._context,e=Se(this._context);e==null||e.document==null||this._loadedMap.has(e.document)||(this._initialMain(t),this._loadedMap.add(e.document))}_refreshListener(){this.disposeWithMe(this._docSelectionManagerService.refreshSelection$.subscribe(t=>{if(t==null)return;const{unitId:e,docRanges:n,isEditing:r,options:s}=t;e===this._context.unitId&&(this._docSelectionRenderService.removeAllRanges(),this._docSelectionRenderService.addDocRanges(n,r,s))}))}_syncSelection(){this.disposeWithMe(this._docSelectionRenderService.textSelectionInner$.subscribe(t=>{t!=null&&this._docSelectionManagerService.__replaceTextRangesWithNoRefresh(t,{unitId:this._context.unitId,subUnitId:this._context.unitId})}))}_initialMain(t){const e=Se(this._context),{document:n,scene:r}=e;this.disposeWithMe(n.onPointerEnter$.subscribeEvent(()=>{this._isEditorReadOnly(t)||(n.cursor=y.CURSOR_TYPE.TEXT)})),this.disposeWithMe(n.onPointerLeave$.subscribeEvent(()=>{n.cursor=y.CURSOR_TYPE.DEFAULT,r.resetCursor()})),this.disposeWithMe(n.onPointerDown$.subscribeEvent((s,a)=>{if(this._isEditorReadOnly(t))return;const c=this._instanceSrv.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);(c==null?void 0:c.getUnitId())!==t&&this._instanceSrv.setCurrentUnitForType(t);const l=this._docSkeletonManagerService.getSkeleton(),{offsetX:A,offsetY:d}=s,u=this._getTransformCoordForDocumentOffset(A,d);if(u!=null){const{pageLayoutType:h=y.PageLayoutType.VERTICAL,pageMarginLeft:g,pageMarginTop:f}=n.getOffsetConfig(),{editArea:m}=l.findEditAreaByCoord(u,h,g,f),p=this._docSkeletonManagerService.getViewModel(),S=p.getEditArea();S!==y.DocumentEditArea.BODY&&m!==y.DocumentEditArea.BODY&&m!==S&&p.setEditArea(m)}if(this._docSelectionRenderService.__onPointDown(s),this._editorService.getEditor(t)){this._setEditorFocus(t);const{offsetX:h,offsetY:g}=s;setTimeout(()=>{t!==this._editorService.getFocusId()&&(this._setEditorFocus(t),this._docSelectionRenderService.setCursorManually(h,g))},0)}s.button!==2&&a.stopPropagation()})),this.disposeWithMe(n.onDblclick$.subscribeEvent(s=>{this._isEditorReadOnly(t)||this._docSelectionRenderService.__handleDblClick(s)})),this.disposeWithMe(n.onTripleClick$.subscribeEvent(s=>{this._isEditorReadOnly(t)||this._docSelectionRenderService.__handleTripleClick(s)}))}_getTransformCoordForDocumentOffset(t,e){const n=Se(this._context),{document:r,scene:s}=n,{documentTransform:a}=r.getOffsetConfig(),c=s.getViewports()[0];if(c==null)return;const l=c.transformVector2SceneCoord(y.Vector2.FromArray([t,e]));return a.clone().invert().applyPoint(l)}_isEditorReadOnly(t){const e=this._editorService.getEditor(t);return e?e.isReadOnly():!1}_setEditorFocus(t){this._editorService.focus(t)}_commandExecutedListener(){const t=[de.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var n;if(t.includes(e.id)){const r=e.params,{unitId:s}=r,a=(n=this._docSelectionManagerService.__getCurrentSelection())==null?void 0:n.unitId;if(s!==a)return;this._docSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe(t=>{if(!t)return;const{unitId:e}=this._context;if(!i.isInternalEditorID(e)){this._docSelectionRenderService.focus();const s=this._context.unit.getSnapshot(),a=$r(s);this._docSelectionManagerService.replaceDocRanges([{startOffset:a,endOffset:a}],{unitId:e,subUnitId:e},!1)}}))}};oo=jA([Xe(1,i.ICommandService),Xe(2,ce),Xe(3,i.IUniverInstanceService),Xe(4,i.Inject(exports.DocSelectionRenderService)),Xe(5,i.Inject(M.DocSkeletonManagerService)),Xe(6,i.Inject(M.DocSelectionManagerService))],oo);var VA=Object.defineProperty,WA=Object.getOwnPropertyDescriptor,KA=(o,t,e,n)=>{for(var r=n>1?void 0:n?WA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&VA(t,e,r),r},Be=(o,t)=>(e,n)=>t(e,n,o);let ro=class extends i.Disposable{constructor(o,t,e,n,r,s,a,c){super(),this._context=o,this._contextService=t,this._docSkeletonManagerService=e,this._univerInstanceService=n,this._commandService=r,this._textSelectionManagerService=s,this._editorService=a,this._docPageLayoutService=c,this._initSkeletonListener(),this._initCommandExecutedListener(),this._initRenderRefresher(),setTimeout(()=>this.updateViewZoom(1,!0),20)}_initRenderRefresher(){this._docSkeletonManagerService.currentSkeleton$.subscribe(o=>{if(o==null)return;const{unitId:t,scene:e}=this._context;this._editorService.isEditor(t)||this.disposeWithMe(e.onMouseWheel$.subscribeEvent(n=>{if(!n.ctrlKey||!this._contextService.getContextValue(i.FOCUSING_DOC))return;const r=this._univerInstanceService.getCurrentUniverDocInstance();if(!r)return;const{documentFlavor:s}=r.getSnapshot().documentStyle;if(s===i.DocumentFlavor.MODERN)return;const a=Math.abs(n.deltaX);let c=a<40?.2:a<80?.4:.2;c*=n.deltaY>0?-1:1,e.scaleX<1&&(c/=2);const l=r.zoomRatio;let A=+Number.parseFloat(`${l+c}`).toFixed(1);A=A>=4?4:A<=.1?.1:A,this._commandService.executeCommand(Gt.id,{zoomRatio:A,unitId:r.getUnitId()}),n.preventDefault()}))})}_initSkeletonListener(){this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe(o=>{if(o==null)return;const t=this._univerInstanceService.getCurrentUniverDocInstance();if(!t)return;const e=t.zoomRatio||1;this.updateViewZoom(e,!1)}))}_initCommandExecutedListener(){const o=[de.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(o.includes(t.id)&&t.params.unitId===this._context.unitId){const n=this._context.unit.zoomRatio||1;this.updateViewZoom(n)}})),this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{t.id===Sn.id&&this._commandService.executeCommand(Gt.id,{zoomRatio:1,unitId:this._context.unitId})}))}updateViewZoom(o,t=!0){var n;const e=Se(this._context);e.scene.scale(o,o),this._editorService.isEditor(this._context.unitId)||this._docPageLayoutService.calculatePagePosition(),t&&!this._editorService.isEditor(this._context.unitId)&&this._textSelectionManagerService.refreshSelection(),(n=e.scene.getTransformer())==null||n.clearSelectedObjects()}};ro=KA([Be(1,i.IContextService),Be(2,i.Inject(M.DocSkeletonManagerService)),Be(3,i.IUniverInstanceService),Be(4,i.ICommandService),Be(5,i.Inject(M.DocSelectionManagerService)),Be(6,ce),Be(7,i.Inject(Lo))],ro);var zA=Object.defineProperty,GA=Object.getOwnPropertyDescriptor,XA=(o,t,e,n)=>{for(var r=n>1?void 0:n?GA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&zA(t,e,r),r},gt=(o,t)=>(e,n)=>t(e,n,o);const yr=300;exports.DocStateChangeManagerService=class extends i.RxDisposable{constructor(e,n,r,s,a){super();x(this,"_docStateChange$",new _.BehaviorSubject(null));x(this,"docStateChange$",this._docStateChange$.asObservable());x(this,"_historyStateCache",new Map);x(this,"_changeStateCache",new Map);x(this,"_historyTimer",null);x(this,"_changeStateCacheTimer",null);this._undoRedoService=e,this._commandService=n,this._univerInstanceService=r,this._docStateEmitService=s,this._renderManagerService=a,this._initialize(),this._listenDocStateChange()}getStateCache(e){var n,r;return{history:(n=this._historyStateCache.get(e))!=null?n:[],collaboration:(r=this._changeStateCache.get(e))!=null?r:[]}}setStateCache(e,n){this._historyStateCache.set(e,n.history),this._changeStateCache.set(e,n.collaboration)}_setChangeState(e){this._cacheChangeState(e,"history"),this._cacheChangeState(e,"collaboration")}_initialize(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===i.UndoCommandId||e.id===i.RedoCommandId){const n=this._univerInstanceService.getCurrentUniverDocInstance();if(n==null)return;const r=n.getUnitId();this._pushHistory(r),this._emitChangeState(r)}}))}_listenDocStateChange(){this._docStateEmitService.docStateChangeParams$.pipe(_.takeUntil(this.dispose$)).subscribe(e=>{var l;if(e==null)return;const{isCompositionEnd:n,isSync:r,syncer:s,...a}=e,c=(l=this._renderManagerService.getRenderById(r?s:e.unitId))==null?void 0:l.with(Mt);if(c!=null){if(n){const A=c.fetchComposedUndoRedoMutationParams();if(A==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:d,redoMutationParams:u,previousActiveRange:h}=A;a.redoState.actions=u.actions,a.undoState.actions=d.actions,a.undoState.textRanges=[h]}this._setChangeState(a)}})}_cacheChangeState(e,n="history"){const{trigger:r,unitId:s,noHistory:a,debounce:c=!1}=e;if(a||r==null||n==="history"&&(r===i.RedoCommandId||r===i.UndoCommandId))return;const l=n==="history"?this._historyStateCache:this._changeStateCache,A=n==="history"?this._pushHistory.bind(this):this._emitChangeState.bind(this);if(l.has(s)){const d=l.get(s);d==null||d.push(e)}else l.set(s,[e]);c?n==="history"?(this._historyTimer&&clearTimeout(this._historyTimer),this._historyTimer=setTimeout(()=>{A(s)},yr)):(this._changeStateCacheTimer&&clearTimeout(this._changeStateCacheTimer),this._changeStateCacheTimer=setTimeout(()=>{A(s)},yr)):A(s)}_pushHistory(e){const n=this._undoRedoService,r=this._historyStateCache.get(e);if(!Array.isArray(r)||r.length===0)return;const s=r.length,a=r[0].commandId,c=r[0],l=r[s-1],A={unitId:e,actions:r.reduce((u,h)=>i.JSONX.compose(u,h.redoState.actions),null),textRanges:l.redoState.textRanges},d={unitId:e,actions:r.reverse().reduce((u,h)=>i.JSONX.compose(u,h.undoState.actions),null),textRanges:c.undoState.textRanges};n.pushUndoRedo({unitID:e,undoMutations:[{id:a,params:d}],redoMutations:[{id:a,params:A}]}),r.length=0}_emitChangeState(e){const n=this._changeStateCache.get(e);if(!Array.isArray(n)||n.length===0)return;const r=n.length,{commandId:s,trigger:a,segmentId:c,noHistory:l,debounce:A}=n[0],d=n[0],u=n[r-1],h={unitId:e,actions:n.reduce((m,p)=>i.JSONX.compose(m,p.redoState.actions),null),textRanges:u.redoState.textRanges},g={unitId:e,actions:n.reverse().reduce((m,p)=>i.JSONX.compose(m,p.undoState.actions),null),textRanges:d.undoState.textRanges},f={commandId:s,unitId:e,trigger:a,redoState:h,undoState:g,segmentId:c,noHistory:l,debounce:A};n.length=0,this._docStateChange$.next(f)}};exports.DocStateChangeManagerService=XA([gt(0,i.Inject(i.IUndoRedoService)),gt(1,i.ICommandService),gt(2,i.IUniverInstanceService),gt(3,i.Inject(M.DocStateEmitService)),gt(4,y.IRenderManagerService)],exports.DocStateChangeManagerService);var YA=Object.defineProperty,qA=Object.getOwnPropertyDescriptor,JA=(o,t,e,n)=>{for(var r=n>1?void 0:n?qA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&YA(t,e,r),r},Or=(o,t)=>(e,n)=>t(e,n,o);const xr="univer-doc-main-canvas";exports.DocsRenderService=class extends i.RxDisposable{constructor(t,e){super(),this._instanceSrv=t,this._renderManagerService=e,this._init()}_init(){this._renderManagerService.createRender$.pipe(_.takeUntil(this.dispose$)).subscribe(t=>this._createRenderWithId(t)),this._instanceSrv.getAllUnitsForType(i.UniverInstanceType.UNIVER_DOC).forEach(t=>this._createRenderer(t)),this._instanceSrv.getTypeOfUnitAdded$(i.UniverInstanceType.UNIVER_DOC).pipe(_.takeUntil(this.dispose$)).subscribe(t=>this._createRenderer(t)),this._instanceSrv.getTypeOfUnitDisposed$(i.UniverInstanceType.UNIVER_DOC).pipe(_.takeUntil(this.dispose$)).subscribe(t=>this._disposeRenderer(t))}_createRenderer(t){var r;const e=t.getUnitId(),n=(r=this._instanceSrv.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC))==null?void 0:r.getUnitId();this._renderManagerService.created$.subscribe(s=>{s.unitId===n&&(s.engine.getCanvas().setId(xr),s.engine.getCanvas().getContext().setId(xr))}),this._renderManagerService.has(e)||(this._createRenderWithId(e),this._renderManagerService.setCurrent(e))}_createRenderWithId(t){this._renderManagerService.createRender(t)}_disposeRenderer(t){const e=t.getUnitId();this._renderManagerService.removeRender(e)}};exports.DocsRenderService=JA([Or(0,i.IUniverInstanceService),Or(1,y.IRenderManagerService)],exports.DocsRenderService);class Mi extends i.Disposable{constructor(){super(...arguments);x(this,"_currentSelectorId");x(this,"_selectionChange$",new _.Subject);x(this,"selectionChange$",this._selectionChange$.asObservable());x(this,"_openSelector$",new _.Subject);x(this,"openSelector$",this._openSelector$.asObservable());x(this,"_selectorModalVisible$",new _.BehaviorSubject(!1));x(this,"selectorModalVisible$",this._selectorModalVisible$.asObservable())}get selectorModalVisible(){return this._selectorModalVisible$.getValue()}setCurrentSelectorId(e){this._currentSelectorId=e}getCurrentSelectorId(){return this._currentSelectorId}selectionChange(e){this._currentSelectorId&&this._selectionChange$.next(e)}openSelector(){this._openSelector$.next(null)}triggerModalVisibleChange(e){this._selectorModalVisible$.next(e)}}const Bi=i.createIdentifier("univer.range-selector.service"),ZA={id:Je.id,preconditions:ra,binding:C.KeyCode.ENTER},$A={id:Dt.id,preconditions:Z,binding:C.KeyCode.BACKSPACE},ed={id:Ro.id,preconditions:Z,binding:C.KeyCode.DELETE},td={id:Ee.id,binding:C.KeyCode.ARROW_UP,preconditions:Z,staticParameters:{direction:i.Direction.UP}},nd={id:Ee.id,binding:C.KeyCode.ARROW_DOWN,preconditions:Z,staticParameters:{direction:i.Direction.DOWN}},od={id:Ee.id,binding:C.KeyCode.ARROW_LEFT,preconditions:Z,staticParameters:{direction:i.Direction.LEFT}},rd={id:Ee.id,binding:C.KeyCode.ARROW_RIGHT,preconditions:Z,staticParameters:{direction:i.Direction.RIGHT}},id={id:ve.id,binding:C.KeyCode.ARROW_UP|C.MetaKeys.SHIFT,preconditions:Z,staticParameters:{direction:i.Direction.UP}},sd={id:ve.id,binding:C.KeyCode.ARROW_DOWN|C.MetaKeys.SHIFT,preconditions:Z,staticParameters:{direction:i.Direction.DOWN}},ad={id:ve.id,binding:C.KeyCode.ARROW_LEFT|C.MetaKeys.SHIFT,preconditions:Z,staticParameters:{direction:i.Direction.LEFT}},cd={id:ve.id,binding:C.KeyCode.ARROW_RIGHT|C.MetaKeys.SHIFT,preconditions:Z,staticParameters:{direction:i.Direction.RIGHT}},ld={id:Uo.id,binding:C.KeyCode.A|C.MetaKeys.CTRL_COMMAND,preconditions:o=>o.getContextValue(i.FOCUSING_UNIVER_EDITOR)&&(o.getContextValue(i.FOCUSING_DOC)||o.getContextValue(i.EDITOR_ACTIVATED))};var _i=Object.defineProperty,Ad=Object.getOwnPropertyDescriptor,dd=(o,t,e)=>t in o?_i(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,ud=(o,t,e,n)=>{for(var r=n>1?void 0:n?Ad(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&_i(t,e,r),r},ht=(o,t)=>(e,n)=>t(e,n,o),gd=(o,t,e)=>dd(o,t+"",e);exports.UniverDocsUIPlugin=class extends i.Plugin{constructor(t=lr,e,n,r,s,a){super(),this._config=t,this._injector=e,this._renderManagerSrv=n,this._commandService=r,this._logService=s,this._configService=a;const{menu:c,...l}=i.merge({},lr,this._config);c&&this._configService.setConfig("menu",c,{merge:!0}),this._configService.setConfig(Io,l),this._initDependencies(e),this._initializeShortcut(),this._initCommand()}onReady(){this._initRenderBasics(),this._markDocAsFocused(),i.touchDependencies(this._injector,[[exports.DocStateChangeManagerService],[exports.DocsRenderService]])}onRendered(){this._initUI(),this._initRenderModules(),i.touchDependencies(this._injector,[[Yt],[qt],[et],[Jt],[exports.DocUIController]])}_initCommand(){[Dt,Ro,Fe,He,ke,je,ye,Ve,Ne,Ue,we,ot,Qe,Te,Bo,dn,Ze,un,To,gn,de,Tt,Ct,rt,Rt,bt,yt,me,Ot,_o,Do,vn,Cn,Ei,Tn,Rn,In,En,at,fo,Qo,Pe,Et,Je,zt,vt,on,rn,So,wo,Sn,fe,Co,Le,Fr,co,Hr,Gt,Uo,Po,Ee,ve,jr].forEach(t=>{this._commandService.registerCommand(t)}),[St,fn,pn].forEach(t=>this.disposeWithMe(this._commandService.registerMultipleCommand(t)))}_initializeShortcut(){[td,nd,rd,od,id,sd,ad,cd,ld,$A,ed,ZA,sa].forEach(t=>{this._injector.get(C.IShortcutService).registerShortcut(t)})}_initDependencies(t){i.mergeOverrideWithDependencies([[Zt],[$t],[exports.DocUIController],[Yt],[Jt],[qt],[Xt],[et],[ce,{useClass:exports.EditorService}],[Bi,{useClass:Mi}],[st,{useClass:Yn}],[exports.DocCanvasPopManagerService],[exports.DocsRenderService],[exports.DocStateChangeManagerService],[exports.DocAutoFormatService],[Ce]],this._config.override).forEach(n=>t.add(n))}_markDocAsFocused(){const t=this._injector.get(i.IUniverInstanceService),e=this._injector.get(ce);try{const n=t.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);if(!n)return;const r=n.getUnitId();e.isEditor(r)||t.focusUnit(n.getUnitId())}catch(n){this._logService.warn(n)}}_initUI(){this._injector.get(Xt)}_initRenderBasics(){[[M.DocSkeletonManagerService],[exports.DocSelectionRenderService],[M.DocInterceptorService],[Lo],[Mt],[exports.DocRenderController],[ro]].forEach(t=>{this._renderManagerSrv.registerRenderModule(i.UniverInstanceType.UNIVER_DOC,t)})}_initRenderModules(){[[exports.DocEventManagerService],[exports.DocBackScrollRenderController],[oo],[zn],[no],[$n],[Zn],[Zt],[to],[eo],[$t]].forEach(t=>{this._renderManagerSrv.registerRenderModule(i.UniverInstanceType.UNIVER_DOC,t)})}};gd(exports.UniverDocsUIPlugin,"pluginName",Br);exports.UniverDocsUIPlugin=ud([i.DependentOn(y.UniverRenderEnginePlugin),ht(1,i.Inject(i.Injector)),ht(2,y.IRenderManagerService),ht(3,i.ICommandService),ht(4,i.ILogService),ht(5,i.IConfigService)],exports.UniverDocsUIPlugin);exports.AfterSpaceCommand=Et;exports.AlignCenterCommand=bt;exports.AlignJustifyCommand=Ot;exports.AlignLeftCommand=Rt;exports.AlignOperationCommand=me;exports.AlignRightCommand=yt;exports.BreakLineCommand=Bo;exports.BulletListCommand=Ct;exports.ChangeListNestingLevelCommand=zt;exports.ChangeListNestingLevelType=pt;exports.ChangeListTypeCommand=vt;exports.CheckListCommand=on;exports.CoverContentCommand=Hr;exports.CreateDocTableCommand=_o;exports.CutContentCommand=Le;exports.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX=_r;exports.DOCS_COMPONENT_DEFAULT_Z_INDEX=Hn;exports.DOCS_COMPONENT_HEADER_LAYER_INDEX=Pr;exports.DOCS_COMPONENT_MAIN_LAYER_INDEX=Lt;exports.DOCS_VIEW_KEY=Ae;exports.DOC_UI_PLUGIN_NAME=Br;exports.DOC_VERTICAL_PADDING=Jn;exports.DefaultDocContainerConfig=Mr;exports.DefaultToolbarConfig=Dr;exports.DeleteCommand=Ze;exports.DeleteCustomBlockCommand=un;exports.DeleteLeftCommand=Dt;exports.DeleteRightCommand=Ro;exports.DocCopyCommand=St;exports.DocCreateTableOperation=bn;exports.DocCutCommand=fn;exports.DocIMEInputManagerService=Mt;exports.DocPasteCommand=pn;exports.DocSelectAllCommand=Uo;exports.DocTableDeleteColumnsCommand=En;exports.DocTableDeleteRowsCommand=In;exports.DocTableDeleteTableCommand=at;exports.DocTableInsertColumnCommand=Ei;exports.DocTableInsertColumnLeftCommand=Tn;exports.DocTableInsertColumnRightCommand=Rn;exports.DocTableInsertRowAboveCommand=vn;exports.DocTableInsertRowBellowCommand=Cn;exports.DocTableInsertRowCommand=Do;exports.DocTableTabCommand=Qo;exports.DocsUIMenuSchema=bi;exports.Editor=zr;exports.EditorInsertTextCommandId=hi;exports.EnterCommand=Je;exports.IDocClipboardService=st;exports.IEditorService=ce;exports.IMEInputCommand=wo;exports.IRangeSelectorService=Bi;exports.InnerPasteCommand=Co;exports.InsertCommand=dn;exports.ListOperationCommand=rt;exports.MergeTwoParagraphCommand=gn;exports.MoveCursorOperation=Ee;exports.MoveSelectionOperation=ve;exports.NORMAL_TEXT_SELECTION_PLUGIN_NAME=Wi;exports.NodePositionConvertToCursor=Ie;exports.NodePositionConvertToRectRange=uo;exports.OrderListCommand=Tt;exports.PastePluginLark=fi;exports.PastePluginUniver=Si;exports.PastePluginWord=Ii;exports.QuickListCommand=So;exports.RangeSelectorService=Mi;exports.RectRange=go;exports.ReplaceContentCommand=Fr;exports.ReplaceSnapshotCommand=co;exports.ReplaceTextRunsCommand=jr;exports.ResetInlineFormatTextBackgroundColorCommand=ot;exports.RichTextEditor=bs;exports.SetDocZoomRatioCommand=Gt;exports.SetDocZoomRatioOperation=de;exports.SetInlineFormatBoldCommand=Fe;exports.SetInlineFormatCommand=Te;exports.SetInlineFormatFontFamilyCommand=Ue;exports.SetInlineFormatFontSizeCommand=Ne;exports.SetInlineFormatItalicCommand=He;exports.SetInlineFormatStrikethroughCommand=je;exports.SetInlineFormatSubscriptCommand=ye;exports.SetInlineFormatSuperscriptCommand=Ve;exports.SetInlineFormatTextBackgroundColorCommand=Qe;exports.SetInlineFormatTextColorCommand=we;exports.SetInlineFormatUnderlineCommand=ke;exports.TEXT_RANGE_LAYER_INDEX=Wt;exports.TabCommand=Pe;exports.TextRange=_e;exports.ToggleCheckListCommand=rn;exports.UpdateCommand=To;exports.VIEWPORT_KEY=he;exports.addCustomDecorationBySelectionFactory=zi;exports.addCustomDecorationFactory=Ur;exports.calcDocRangePositions=jt;exports.convertPositionsToRectRanges=Ht;exports.deleteCustomDecorationFactory=Gi;exports.docDrawingPositionToTransform=Yi;exports.genTableSource=vo;exports.generateParagraphs=Mo;exports.getAnchorBounding=ft;exports.getCanvasOffsetByEngine=Kr;exports.getCommandSkeleton=le;exports.getCursorWhenDelete=hn;exports.getCustomBlockIdsInSelections=ui;exports.getCutActionsFromDocRanges=gi;exports.getDocObject=Nr;exports.getDocObjectById=Ki;exports.getEmptyTableCell=cn;exports.getEmptyTableRow=ln;exports.getLineBounding=nn;exports.getOneTextSelectionRange=jn;exports.getParagraphsInRange=sn;exports.getParagraphsInRanges=it;exports.getRichTextEditPath=q;exports.getTableColumn=An;exports.hasParagraphInTable=Xi;exports.isInSameTableCell=Ao;exports.isValidRectRange=Vr;exports.neoGetDocObject=Se;exports.transformToDocDrawingPosition=qi;exports.useKeyboardEvent=wr;exports.useResize=Qr;exports.whenDocAndEditorFocused=Z;
|
|
46
|
+
`,style:{width:162},children:[Q.jsx(ae.Select,{value:`${v}`,options:[{label:o.t("doc.paragraphSetting.multiSpace"),value:`${i.SpacingRule.AUTO}`},{label:o.t("doc.paragraphSetting.fixedValue"),value:`${i.SpacingRule.AT_LEAST}`}],onChange:E=>R(Number(E))}),Q.jsx(De,{...b,value:S,onChange:E=>I(E!=null?E:0)})]})]})]})]})}const Pc=(o,t)=>t.length===o.length&&o.some(e=>t.some(n=>n.startOffset===e.startOffset&&n.endOffset===e.endOffset));function Nc(){const o=i.useDependency(i.ICommandService),t=i.useDependency(i.LocaleService),e=i.useObservable(t.currentLocale$),[n,r]=L.useState(""),s=L.useMemo(()=>i.debounce(()=>r(i.generateRandomId(4)),300),[]),a=L.useRef([]);return L.useEffect(()=>{const c=o.onCommandExecuted(l=>{if(M.SetTextSelectionsOperation.id===l.id){const A=l.params.ranges;Pc(A,a.current)||r(i.generateRandomId(4)),a.current=A}M.RichTextEditingMutation.id===l.id&&l.params.trigger!==fe.id&&s()});return()=>c.dispose()},[s]),L.useEffect(()=>{r(i.generateRandomId(4))},[e]),L.useEffect(()=>()=>s.cancel(),[s]),Q.jsx(_c,{},n)}var Uc=Object.defineProperty,wc=Object.getOwnPropertyDescriptor,Qc=(o,t,e,n)=>{for(var r=n>1?void 0:n?wc(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Uc(t,e,r),r},Qn=(o,t)=>(e,n)=>t(e,n,o);const mr="doc_ui_paragraph-setting-panel";let et=class extends i.Disposable{constructor(t,e,n){super();x(this,"_id");this._commandService=t,this._componentManager=e,this._sidebarService=n,this._init()}_init(){this.disposeWithMe(this._componentManager.register(mr,Nc))}openPanel(){const t={header:{title:"doc.slider.paragraphSetting"},id:this._id,children:{label:mr},width:300};this._sidebarService.open(t)}closePanel(){this._sidebarService.close(this._id)}};et=Qc([Qn(0,i.ICommandService),Qn(1,i.Inject(C.ComponentManager)),Qn(2,i.Inject(C.ISidebarService))],et);const Po={id:"sidebar.operation.doc-paragraph-setting-panel",type:i.CommandType.OPERATION,handler:o=>(o.get(et).openPanel(),!0)},No=o=>{const t=o.get(M.DocSelectionManagerService);return new _.Observable(e=>{const n=t.textSelection$.subscribe(()=>{t.getDocRanges().some(a=>a.collapsed===!1||a.rangeType===i.DOC_RANGE_TYPE.RECT)?e.next(!1):e.next(!0)});return()=>n.unsubscribe()})};function Lc(o){if(o.length<2)return!0;const t=o.map(e=>e.tableId);return t.every(e=>e===t[0])}function fr(o,t,e){var s;const n=t.getRectRanges(),r=t.getActiveTextRange();if(n&&n.length&&Lc(n)&&r==null){o.next(!1);return}if(r&&(n==null||n.length===0)){const{segmentId:a,startOffset:c,endOffset:l}=r,A=e.getCurrentUniverDocInstance(),d=(s=A==null?void 0:A.getSelfOrHeaderFooterModel(a).getBody())==null?void 0:s.tables;if(d&&d.length&&d.some(u=>{const{startIndex:h,endIndex:g}=u;return c>h&&c<g||l>h&&l<g})){o.next(!1);return}}o.next(!0)}const Re=o=>{const t=o.get(M.DocSelectionManagerService),e=o.get(i.IUniverInstanceService);return new _.Observable(n=>{const r=t.textSelection$.subscribe(()=>{fr(n,t,e)});return fr(n,t,e),()=>r.unsubscribe()})},Fc=o=>({id:St.name,commandId:St.id,type:C.MenuItemType.BUTTON,icon:"Copy",title:"rightClick.copy",disabled$:No(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}),Hc=o=>({id:Po.id,type:C.MenuItemType.BUTTON,icon:"MenuSingle24",title:"doc.menu.paragraphSetting",hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}),kc=o=>({id:fn.id,type:C.MenuItemType.BUTTON,icon:"Copy",title:"rightClick.cut",disabled$:No(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}),jc=o=>({id:pn.id,type:C.MenuItemType.BUTTON,icon:"PasteSpecial",title:"rightClick.paste",hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}),Vc=o=>({id:Dt.id,type:C.MenuItemType.BUTTON,icon:"PasteSpecial",title:"rightClick.delete",disabled$:No(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}),Ci="doc.menu.table-insert";function Wc(o){return{id:Ci,type:C.MenuItemType.SUBITEMS,title:"table.insert",icon:"Insert",hidden$:_.combineLatest(C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),Re(o),(t,e)=>t||e)}}function Kc(o){return{id:vn.id,type:C.MenuItemType.BUTTON,title:"table.insertRowAbove",icon:"InsertRowAbove",disabled$:Re(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function zc(o){return{id:Cn.id,type:C.MenuItemType.BUTTON,title:"table.insertRowBelow",icon:"InsertRowBelow",disabled$:Re(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Gc(o){return{id:Tn.id,type:C.MenuItemType.BUTTON,title:"table.insertColumnLeft",icon:"LeftInsertColumn",disabled$:Re(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Xc(o){return{id:Rn.id,type:C.MenuItemType.BUTTON,title:"table.insertColumnRight",icon:"RightInsertColumn",disabled$:Re(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}const Ti="doc.menu.table-delete";function Yc(o){return{id:Ti,type:C.MenuItemType.SUBITEMS,title:"table.delete",icon:"Reduce",hidden$:_.combineLatest(C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),Re(o),(t,e)=>t||e)}}function qc(o){return{id:In.id,type:C.MenuItemType.BUTTON,title:"table.deleteRows",icon:"DeleteRow",disabled$:Re(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Jc(o){return{id:En.id,type:C.MenuItemType.BUTTON,title:"table.deleteColumns",icon:"DeleteColumn",disabled$:Re(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Zc(o){return{id:at.id,type:C.MenuItemType.BUTTON,title:"table.deleteTable",icon:"GridSingle",disabled$:Re(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function $c(o){const t=o.get(i.IUniverInstanceService),e=o.get(y.IRenderManagerService);return new _.Observable(n=>{const r=t.focused$.subscribe(c=>{if(c==null||t.getUnitType(c)!==i.UniverInstanceType.UNIVER_DOC)return n.next(!0);const A=e.getRenderById(c);if(A==null)return n.next(!0);A.with(M.DocSkeletonManagerService).getViewModel().editAreaChange$.subscribe(u=>{n.next(u===y.DocumentEditArea.HEADER||u===y.DocumentEditArea.FOOTER)})}),s=e.getCurrentTypeOfRenderer(i.UniverInstanceType.UNIVER_DOC);if(s==null)return n.next(!0);const a=s.with(M.DocSkeletonManagerService).getViewModel();return n.next(a.getEditArea()!==y.DocumentEditArea.BODY),()=>r.unsubscribe()})}function el(o){const t=o.get(i.IUniverInstanceService),e=o.get(i.ICommandService);return new _.Observable(n=>{const r=e.onCommandExecuted(l=>{if(l.id===M.RichTextEditingMutation.id){const{unitId:A}=l.params,d=t.getUnit(A);if(d==null){n.next(!0);return}const{documentStyle:u}=d.getSnapshot();n.next((u==null?void 0:u.documentFlavor)!==i.DocumentFlavor.TRADITIONAL)}}),s=t.focused$.subscribe(l=>{if(l==null)return n.next(!0);const A=t.getUniverDocInstance(l),d=A==null?void 0:A.getSnapshot().documentStyle.documentFlavor;n.next(d!==i.DocumentFlavor.TRADITIONAL)}),a=t.getCurrentUniverDocInstance();if(a==null)return n.next(!0);const c=a==null?void 0:a.getSnapshot().documentStyle.documentFlavor;return n.next(c!==i.DocumentFlavor.TRADITIONAL),()=>{r.dispose(),s.unsubscribe()}})}function tl(o){const t=o.get(M.DocSelectionManagerService),e=o.get(i.IUniverInstanceService);return new _.Observable(n=>{const r=t.textSelection$.subscribe(s=>{if(s==null){n.next(!0);return}const{textRanges:a}=s;if(a.length!==1){n.next(!0);return}const c=a[0],{collapsed:l,startNodePosition:A,startOffset:d}=c;if(!l||d==null){n.next(!0);return}const u=e.getCurrentUniverDocInstance();if(u==null){n.next(!0);return}const h=le(o,u.getUnitId());if(h==null){n.next(!0);return}if(h.getViewModel().getCustomRangeRaw(d)){n.next(!0);return}if(A!=null){const{path:m}=A;if(m.indexOf("cells")!==-1){n.next(!0);return}}n.next(!1)});return()=>r.unsubscribe()})}function ee(o){const t=o.get(M.DocSelectionManagerService);return new _.Observable(e=>{const n=t.textSelection$.subscribe(r=>{if(r==null){e.next(!0);return}const{textRanges:s,rectRanges:a}=r;if(s.length===0&&a.length===0){e.next(!0);return}e.next(!1)});return()=>n.unsubscribe()})}function nl(o){const t=o.get(i.ICommandService);return{id:Fe.id,type:C.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===M.SetTextSelectionsOperation.id||s===Te.id){const c=Oe(o);if(c==null){e.next(!1);return}const l=(a=c.ts)==null?void 0:a.bl;e.next(l===i.BooleanNumber.TRUE)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function ol(o){const t=o.get(i.ICommandService);return{id:He.id,type:C.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===M.SetTextSelectionsOperation.id||s===Te.id){const c=Oe(o);if(c==null){e.next(!1);return}const l=(a=c.ts)==null?void 0:a.it;e.next(l===i.BooleanNumber.TRUE)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function rl(o){const t=o.get(i.ICommandService);return{id:ke.id,type:C.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===M.SetTextSelectionsOperation.id||s===Te.id){const c=Oe(o);if(c==null){e.next(!1);return}const l=(a=c.ts)==null?void 0:a.ul;e.next((l==null?void 0:l.s)===i.BooleanNumber.TRUE)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function il(o){const t=o.get(i.ICommandService);return{id:je.id,type:C.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===M.SetTextSelectionsOperation.id||s===Te.id){const c=Oe(o);if(c==null){e.next(!1);return}const l=(a=c.ts)==null?void 0:a.st;e.next((l==null?void 0:l.s)===i.BooleanNumber.TRUE)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function sl(o){const t=o.get(i.ICommandService);return{id:ye.id,type:C.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===M.SetTextSelectionsOperation.id||s===Te.id){const c=Oe(o);if(c==null){e.next(!1);return}const l=(a=c.ts)==null?void 0:a.va;e.next(l===i.BaselineOffset.SUBSCRIPT)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function al(o){const t=o.get(i.ICommandService);return{id:Ve.id,type:C.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===M.SetTextSelectionsOperation.id||s===Te.id){const c=Oe(o);if(c==null){e.next(!1);return}const l=(a=c.ts)==null?void 0:a.va;e.next(l===i.BaselineOffset.SUPERSCRIPT)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function cl(o){const t=o.get(i.ICommandService);return{id:Ue.id,tooltip:"toolbar.font",type:C.MenuItemType.SELECTOR,label:ni,selections:C.FONT_FAMILY_LIST.map(e=>({label:{name:oi,hoverable:!0},value:e.value})),value$:new _.Observable(e=>{const n=i.DEFAULT_STYLES.ff,r=t.onCommandExecuted(s=>{var c;const a=s.id;if(a===M.SetTextSelectionsOperation.id||a===Ue.id){const l=Oe(o);if(l==null){e.next(n);return}const A=(c=l.ts)==null?void 0:c.ff;e.next(A!=null?A:n)}});return e.next(n),r.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function ll(o){const t=o.get(i.ICommandService);return{id:Ne.id,type:C.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:ri,props:{min:1,max:400}},selections:C.FONT_SIZE_LIST,value$:new _.Observable(e=>{const n=i.DEFAULT_STYLES.fs,r=t.onCommandExecuted(s=>{var c;const a=s.id;if(a===M.SetTextSelectionsOperation.id||a===Ne.id){const l=Oe(o);if(l==null){e.next(n);return}const A=(c=l.ts)==null?void 0:c.fs;e.next(A!=null?A:n)}});return e.next(n),r.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Al(o){const t=o.get(i.ICommandService),e=o.get(i.ThemeService);return{id:we.id,icon:"FontColor",tooltip:"toolbar.textColor.main",type:C.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:po,hoverable:!1}}],value$:new _.Observable(n=>{const r=e.getCurrentTheme().textColor,s=t.onCommandExecuted(a=>{if(a.id===we.id){const c=a.params.value;n.next(c!=null?c:r)}});return n.next(r),s.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function dl(o){return{id:mo.id,type:C.MenuItemType.BUTTON,icon:"HeaderFooterSingle",tooltip:"toolbar.headerFooter",hidden$:_.combineLatest(C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY),el(o),(t,e)=>t||e)}}const ul="GridSingle",Ri="doc.menu.table";function gl(o){return{id:Ri,type:C.MenuItemType.SUBITEMS,icon:ul,tooltip:"toolbar.table.main",disabled$:tl(o),hidden$:_.combineLatest(C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY),$c(o),(t,e)=>t||e)}}function hl(o){return{id:bn.id,title:"toolbar.table.insert",type:C.MenuItemType.BUTTON,hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function ml(o){const t=o.get(i.ICommandService);return{id:Rt.id,type:C.MenuItemType.BUTTON,icon:"LeftJustifyingSingle",tooltip:"toolbar.alignLeft",disabled$:ee(o),activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===M.SetTextSelectionsOperation.id||s===me.id){const c=yn(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.LEFT)}});return e.next(!1),n.dispose}),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function fl(o){const t=o.get(i.ICommandService);return{id:bt.id,type:C.MenuItemType.BUTTON,icon:"HorizontallySingle",tooltip:"toolbar.alignCenter",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===M.SetTextSelectionsOperation.id||s===me.id){const c=yn(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.CENTER)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function pl(o){const t=o.get(i.ICommandService);return{id:yt.id,type:C.MenuItemType.BUTTON,icon:"RightJustifyingSingle",tooltip:"toolbar.alignRight",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===M.SetTextSelectionsOperation.id||s===me.id){const c=yn(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.RIGHT)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Sl(o){const t=o.get(i.ICommandService);return{id:Ot.id,type:C.MenuItemType.BUTTON,icon:"AlignTextBothSingle",tooltip:"toolbar.alignJustify",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===M.SetTextSelectionsOperation.id||s===me.id){const c=yn(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.JUSTIFIED)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}const It=o=>new _.Observable(t=>{const e=o.get(i.IUniverInstanceService),n=o.get(M.DocSelectionManagerService);let r;const s=e.focused$.subscribe(a=>{if(r==null||r.unsubscribe(),a==null)return;const c=e.getUniverDocInstance(a);c!=null&&(r=n.textSelection$.subscribe(()=>{var d,u,h;const l=n.getDocRanges(),A=(d=l.find(g=>g.isActive))!=null?d:l[0];if(A){const g=c.getSelfOrHeaderFooterModel(A==null?void 0:A.segmentId),f=sn(A,(h=(u=g.getBody())==null?void 0:u.paragraphs)!=null?h:[]);let m;if(f.every(p=>{var S;return m||(m=(S=p.bullet)==null?void 0:S.listType),p.bullet&&p.bullet.listType===m})){t.next(m);return}}t.next(void 0)}))});return()=>{s.unsubscribe(),r==null||r.unsubscribe()}});function Il(o){return{id:Tt.id,type:C.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:si,hoverable:!1},value$:It(o)}],icon:"OrderSingle",tooltip:"toolbar.order",hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),disabled$:ee(o),activated$:It(o).pipe(_.map(t=>t&&t.indexOf("ORDER_LIST")===0))}}function El(o){return{id:Ct.id,type:C.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:ai,hoverable:!1},value$:It(o)}],icon:"UnorderSingle",tooltip:"toolbar.unorder",disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),activated$:It(o).pipe(_.map(t=>t&&t.indexOf("BULLET_LIST")===0))}}function vl(o){return{id:on.id,type:C.MenuItemType.BUTTON,icon:"TodoList",tooltip:"toolbar.checklist",disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),activated$:It(o).pipe(_.map(t=>t&&t.indexOf("CHECK_LIST")===0))}}function Cl(o){const t=o.get(i.ICommandService),e=o.get(i.IUniverInstanceService);return{id:Sn.id,type:C.MenuItemType.BUTTON,icon:"KeyboardSingle",tooltip:"toolbar.documentFlavor",hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY),activated$:new _.Observable(n=>{var a;const r=t.onCommandExecuted(c=>{var l;if(c.id===M.RichTextEditingMutation.id){const A=e.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);n.next(((l=A==null?void 0:A.getSnapshot())==null?void 0:l.documentStyle.documentFlavor)===i.DocumentFlavor.MODERN)}}),s=e.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);return n.next(((a=s==null?void 0:s.getSnapshot())==null?void 0:a.documentStyle.documentFlavor)===i.DocumentFlavor.MODERN),()=>r.dispose()})}}function Tl(o){return{id:ot.id,type:C.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor"}}function Rl(o){const t=o.get(i.ICommandService),e=o.get(i.ThemeService);return{id:Qe.id,tooltip:"toolbar.fillColor.main",type:C.MenuItemType.BUTTON_SELECTOR,icon:"PaintBucket",selections:[{label:{name:po,hoverable:!1}}],value$:new _.Observable(n=>{const r=e.getCurrentTheme().primaryColor,s=t.onCommandExecuted(a=>{if(a.id===Qe.id){const c=a.params.value;n.next(c!=null?c:r)}});return n.next(r),s.dispose}),disabled$:ee(o),hidden$:C.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Oe(o){var h,g;const t=o.get(i.IUniverInstanceService),e=o.get(M.DocSelectionManagerService),n=o.get(Ce),r=t.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),s=e.getDocRanges(),a=(h=s.find(f=>f.isActive))!=null?h:s[0],c=n.getDefaultStyle(),l=(g=n.getStyleCache())!=null?g:{};if(r==null||a==null)return{ts:{...c,...l}};const{segmentId:A}=a,d=r.getSelfOrHeaderFooterModel(A).getBody();return d==null?{ts:{...c,...l}}:{ts:{...li(d,a,c),...l}}}function yn(o){var d,u;const t=o.get(i.IUniverInstanceService),e=o.get(M.DocSelectionManagerService),n=t.getCurrentUniverDocInstance(),r=e.getDocRanges(),s=(d=r.find(h=>h.isActive))!=null?d:r[0];if(n==null||s==null)return;const{startOffset:a,segmentId:c}=s,l=(u=n.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:u.paragraphs;if(l==null)return;let A=-1;for(const h of l){const{startIndex:g}=h;if(a>A&&a<=g)return h;A=g}return null}const bi={[C.RibbonStartGroup.FORMAT]:{[Fe.id]:{order:0,menuItemFactory:nl},[He.id]:{order:1,menuItemFactory:ol},[ke.id]:{order:2,menuItemFactory:rl},[je.id]:{order:3,menuItemFactory:il},[ye.id]:{order:4,menuItemFactory:sl},[Ve.id]:{order:5,menuItemFactory:al},[Ne.id]:{order:6,menuItemFactory:ll},[Ue.id]:{order:7,menuItemFactory:cl},[we.id]:{order:8,menuItemFactory:Al},[Qe.id]:{order:9,menuItemFactory:Rl,[ot.id]:{order:0,menuItemFactory:Tl}}},[C.RibbonStartGroup.LAYOUT]:{[Ri]:{order:1,menuItemFactory:gl,[bn.id]:{order:0,menuItemFactory:hl}},[Rt.id]:{order:2,menuItemFactory:ml},[bt.id]:{order:3,menuItemFactory:fl},[yt.id]:{order:4,menuItemFactory:pl},[Ot.id]:{order:5,menuItemFactory:Sl},[Tt.id]:{order:6,menuItemFactory:Il},[Ct.id]:{order:7,menuItemFactory:El},[on.id]:{order:8,menuItemFactory:vl},[mo.id]:{order:9,menuItemFactory:dl},[Sn.id]:{order:10,menuItemFactory:Cl}},[C.ContextMenuPosition.MAIN_AREA]:{[C.ContextMenuGroup.FORMAT]:{[St.name]:{order:0,menuItemFactory:Fc},[fn.id]:{order:1,menuItemFactory:kc},[pn.id]:{order:2,menuItemFactory:jc},[Dt.id]:{order:3,menuItemFactory:Vc}},[C.ContextMenuGroup.LAYOUT]:{[Po.id]:{order:0,menuItemFactory:Hc},[Ci]:{order:1,menuItemFactory:Wc,[vn.id]:{order:1,menuItemFactory:Kc},[Cn.id]:{order:2,menuItemFactory:zc},[Tn.id]:{order:3,menuItemFactory:Gc},[Rn.id]:{order:4,menuItemFactory:Xc}},[Ti]:{order:2,menuItemFactory:Yc,[In.id]:{order:1,menuItemFactory:qc},[En.id]:{order:2,menuItemFactory:Jc},[at.id]:{order:3,menuItemFactory:Zc}}}}};var bl=Object.defineProperty,yl=Object.getOwnPropertyDescriptor,Ol=(o,t,e,n)=>{for(var r=n>1?void 0:n?yl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&bl(t,e,r),r},pe=(o,t)=>(e,n)=>t(e,n,o);exports.DocUIController=class extends i.Disposable{constructor(t,e,n,r,s,a,c,l,A){super(),this._injector=t,this._componentManager=e,this._commandService=n,this._layoutService=r,this._menuManagerService=s,this._uiPartsService=a,this._univerInstanceService=c,this._shortcutService=l,this._configService=A,this._init()}_initCustomComponents(){const t=this._componentManager;this.disposeWithMe(t.register(po,ae.ColorPicker)),this.disposeWithMe(t.register(ni,C.FontFamily)),this.disposeWithMe(t.register(oi,C.FontFamilyItem)),this.disposeWithMe(t.register(ri,C.FontSize)),this.disposeWithMe(t.register(ai,ta)),this.disposeWithMe(t.register(si,$s)),this.disposeWithMe(t.register("TodoList",Zr))}_initUiParts(){var n,r;const t=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_SHEET),e=this._configService.getConfig(Io);(r=(n=e==null?void 0:e.layout)==null?void 0:n.docContainerConfig)!=null&&r.footer&&!t&&this.disposeWithMe(this._uiPartsService.registerComponent(C.BuiltInUIPart.FOOTER,()=>i.connectInjector(wa,this._injector)))}_initMenus(){this._menuManagerService.mergeMenu(bi)}_initShortCut(){[ma,fa,pa,Sa,Ia,Ea,Ta,Ra,Ca,va,ba,ya,ia].forEach(t=>{this.disposeWithMe(this._shortcutService.registerShortcut(t))})}_init(){this._initCustomComponents(),this._initMenus(),this._initFocusHandler(),this._initCommands(),this._initUiParts(),this._initShortCut()}_initCommands(){[ti,mo,ho].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(i.UniverInstanceType.UNIVER_DOC,t=>{this._injector.get(y.IRenderManagerService).getRenderById(t).with(exports.DocSelectionRenderService).focus()}))}};exports.DocUIController=Ol([pe(0,i.Inject(i.Injector)),pe(1,i.Inject(C.ComponentManager)),pe(2,i.ICommandService),pe(3,C.ILayoutService),pe(4,C.IMenuManagerService),pe(5,C.IUIPartsService),pe(6,i.IUniverInstanceService),pe(7,C.IShortcutService),pe(8,i.IConfigService)],exports.DocUIController);var xl=Object.defineProperty,Dl=Object.getOwnPropertyDescriptor,Ml=(o,t,e,n)=>{for(var r=n>1?void 0:n?Dl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&xl(t,e,r),r},Ln=(o,t)=>(e,n)=>t(e,n,o);const pr=1.5;exports.DocBackScrollRenderController=class extends i.RxDisposable{constructor(t,e,n,r){super(),this._context=t,this._textSelectionManagerService=e,this._editorService=n,this._docSkeletonManagerService=r,this._init()}_init(){this._textSelectionManagerService.textSelection$.pipe(_.takeUntil(this.dispose$)).subscribe(t=>{if(t==null)return;const{isEditing:e,unitId:n}=t;n!==this._context.unitId||!e||this._context.unitId!==i.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._scrollToSelection()})}scrollToRange(t){const e=this._docSkeletonManagerService.getSkeleton();if(!e)return;const{startOffset:n}=t,r=e.findNodePositionByCharIndex(n);r&&this.scrollToNode(r)}scrollToNode(t){var U;const{unitId:e,scene:n,mainComponent:r}=this._context,s=this._docSkeletonManagerService.getSkeleton();if(r==null||s==null)return;const a=r.getOffsetConfig(),{docsLeft:c,docsTop:l}=a,A=new Ie(a,s),{contentBoxPointGroup:d}=A.getRangePointData(t,t),{left:u,top:h,height:g}=ft(d),f=u+c,m=h+l,p=n.getViewport(he.VIEW_MAIN),S=this._editorService.getEditor(e);if(p==null)return;const{left:I,top:v,right:R,bottom:b}=p.getBounding().viewBound;let E=0,T=0;const B=S?(U=S.params.backScrollOffset)!=null?U:0:100;m<v?E=m-v-B:m>b-g&&(E=m-b+g+B),f<I?T=f-I:f>R-pr&&(T=f-R+pr);const D=p.transViewportScroll2ScrollValue(T,E);p.scrollByBarDeltaValue(D)}_scrollToSelection(){const t=this._textSelectionManagerService.getActiveTextRange();if(t==null)return;const{collapsed:e,startNodePosition:n}=t;e&&this.scrollToNode(n)}};exports.DocBackScrollRenderController=Ml([Ln(1,i.Inject(M.DocSelectionManagerService)),Ln(2,ce),Ln(3,i.Inject(M.DocSkeletonManagerService))],exports.DocBackScrollRenderController);var Bl=Object.defineProperty,_l=Object.getOwnPropertyDescriptor,Pl=(o,t,e,n)=>{for(var r=n>1?void 0:n?_l(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Bl(t,e,r),r},ze=(o,t)=>(e,n)=>t(e,n,o);exports.DocRenderController=class extends i.RxDisposable{constructor(t,e,n,r,s,a,c){super(),this._context=t,this._commandService=e,this._docSelectionRenderService=n,this._docSkeletonManagerService=r,this._editorService=s,this._renderManagerService=a,this._univerInstanceService=c,this._addNewRender(),this._initRenderRefresh(),this._initCommandListener()}reRender(t){var a,c;const e=(a=this._renderManagerService.getRenderById(t))==null?void 0:a.with(M.DocSkeletonManagerService),n=e==null?void 0:e.getSkeleton();if(!n||!!n.getViewModel().getDataModel().getSnapshot().disabled)return;n.calculate();const s=this._editorService.getEditor(t);if(this._editorService.isEditor(t)&&!(s!=null&&s.params.scrollBar)){(c=this._context.mainComponent)==null||c.makeDirty();return}this._recalculateSizeBySkeleton(n)}_addNewRender(){const{scene:t,engine:e}=this._context,n=new y.Viewport(he.VIEW_MAIN,t,{left:0,top:0,bottom:0,right:0,isWheelPreventDefaultX:!0});t.attachControl(),t.onMouseWheel$.subscribeEvent((r,s)=>{const a=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);if((a==null?void 0:a.getUnitId())!==this._context.unitId)return;const c=r;if(c.ctrlKey){const l=Math.abs(c.deltaX);let A=l<40?.2:l<80?.4:.2;A*=c.deltaY>0?-1:1,t.scaleX<1&&(A/=2),t.scaleX+A>4?t.scale(4,4):t.scaleX+A<.1?t.scale(.1,.1):c.preventDefault()}else n.onMouseWheel(c,s)}),new y.ScrollBar(n),t.addLayer(new y.Layer(t,[],Lt),new y.Layer(t,[],Pr)),this._addComponent(),e.runRenderLoop(()=>{t.render()}),this._docSelectionRenderService.__attachScrollEvent()}_addComponent(){const{scene:t,unit:e,components:n}=this._context,a={pageMarginLeft:20,pageMarginTop:20},c=new y.Documents(Ae.MAIN,void 0,a);c.zIndex=Hn;const l=new y.DocBackground(Ae.BACKGROUND,void 0,a);l.zIndex=Hn,this._context.mainComponent=c,n.set(Ae.MAIN,c),n.set(Ae.BACKGROUND,l),t.addObjects([c],Lt),t.addObjects([l],_r),this._editorService.getEditor(e.getUnitId())==null&&t.enableLayerCache(Lt)}_initRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(_.takeUntil(this.dispose$)).subscribe(t=>{this._create(t)})}_create(t){var l;if(!t)return;const{mainComponent:e,components:n}=this._context,r=e,s=n.get(Ae.BACKGROUND);r.changeSkeleton(t),s.changeSkeleton(t);const{unitId:a}=this._context,c=this._editorService.getEditor(a);if(this._editorService.isEditor(a)&&!(c!=null&&c.params.scrollBar)){(l=this._context.mainComponent)==null||l.makeDirty();return}this._recalculateSizeBySkeleton(t)}_initCommandListener(){const t=[M.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(t.includes(e.id)){const n=e.params,{unitId:r}=n;this.reRender(r)}}))}_recalculateSizeBySkeleton(t){var f;const{mainComponent:e,scene:n,unitId:r,components:s}=this._context,a=e,c=s.get(Ae.BACKGROUND),l=(f=t.getSkeletonData())==null?void 0:f.pages;if(l==null)return;let A=0,d=0;const h=this._context.unit.getSnapshot().documentStyle.documentFlavor;for(let m=0,p=l.length;m<p;m++){const S=l[m];let{pageWidth:I,pageHeight:v}=S;if(h===i.DocumentFlavor.MODERN){const R=Nl(S);I=R.pageWidth,v=R.pageHeight}a.pageLayoutType===y.PageLayoutType.VERTICAL?(d+=v,d+=a.pageMarginTop,m===p-1&&(d+=a.pageMarginTop),A=Math.max(A,I)):a.pageLayoutType===y.PageLayoutType.HORIZONTAL&&(A+=I,m!==p-1&&(A+=a.pageMarginLeft),d=Math.max(d,v))}a.resize(A,d),c.resize(A,d);const g=this._editorService.getEditor(r);(!this._editorService.isEditor(r)||g!=null&&g.params.scrollBar)&&n.resize(A,d)}};exports.DocRenderController=Pl([ze(1,i.ICommandService),ze(2,i.Inject(exports.DocSelectionRenderService)),ze(3,i.Inject(M.DocSkeletonManagerService)),ze(4,ce),ze(5,y.IRenderManagerService),ze(6,i.IUniverInstanceService)],exports.DocRenderController);function Nl(o){let{pageWidth:t,pageHeight:e}=o;const{marginLeft:n,marginRight:r,marginTop:s,marginBottom:a,skeDrawings:c,skeTables:l}=o;t===Number.POSITIVE_INFINITY&&(t=o.width+n+r),e===Number.POSITIVE_INFINITY&&(e=o.height+s+a);for(const A of c.values())t=Math.max(t,A.aLeft+A.width+n+r),e=Math.max(e,A.aTop+A.height+s+a);for(const A of l.values())t=Math.max(t,A.left+A.width+n+r),e=Math.max(e,A.top+A.height+s+a);return{pageWidth:t,pageHeight:e}}const Uo={id:"doc.command.select-all",type:i.CommandType.COMMAND,handler:async o=>{var h;const t=o.get(i.IUniverInstanceService),e=o.get(M.DocSelectionManagerService),n=t.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),r=e.getDocRanges(),s=(h=r.find(g=>g.isActive))!=null?h:r[0];if(n==null||s==null)return!1;const{segmentId:a}=s,c=n.getUnitId(),l=n.getSelfOrHeaderFooterModel(a).getSnapshot().body;if(l==null)return!1;const{tables:A=[]}=l,d=[];let u=0;for(const g of A){const{startIndex:f,endIndex:m}=g;u!==f&&d.push({startOffset:u,endOffset:f-1,rangeType:i.DOC_RANGE_TYPE.TEXT}),d.push({startOffset:f+3,endOffset:m-5,rangeType:i.DOC_RANGE_TYPE.RECT}),u=m}return u!==l.dataStream.length-2&&d.push({startOffset:u,endOffset:l.dataStream.length-2,rangeType:i.DOC_RANGE_TYPE.TEXT}),e.replaceDocRanges(d,{unitId:c,subUnitId:c},!1),!0}};class Mt extends i.RxDisposable{constructor(e){super();x(this,"_previousActiveRange",null);x(this,"_undoMutationParamsCache",[]);x(this,"_redoMutationParamsCache",[]);this._context=e}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache:e=[],redoCache:n=[]}){this._undoMutationParamsCache=e,this._redoMutationParamsCache=n}getActiveRange(){return this._previousActiveRange}setActiveRange(e){this._previousActiveRange=e}pushUndoRedoMutationParams(e,n){this._undoMutationParamsCache.push(e),this._redoMutationParamsCache.push(n)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:e}=this._undoMutationParamsCache[0],n={unitId:e,actions:this._undoMutationParamsCache.reverse().reduce((s,a)=>i.JSONX.compose(s,a.actions),null),textRanges:[]};return{redoMutationParams:{unitId:e,actions:this._redoMutationParamsCache.reduce((s,a)=>i.JSONX.compose(s,a.actions),null),textRanges:[]},undoMutationParams:n,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Ul=i.SHEET_EDITOR_UNITS,wo={id:"doc.command.ime-input",type:i.CommandType.COMMAND,handler:async(o,t)=>{var w,W,V,k;const{unitId:e,newText:n,oldTextLen:r,isCompositionEnd:s,isCompositionStart:a}=t,c=o.get(i.ICommandService),l=o.get(y.IRenderManagerService),A=o.get(i.IUniverInstanceService),d=o.get(Ce),u=(w=l.getRenderById(e))==null?void 0:w.with(Mt),h=A.getUnit(e,i.UniverInstanceType.UNIVER_DOC);if(h==null||u==null)return!1;const g=u.getActiveRange();if(g==null)return!1;const{style:f,segmentId:m}=g,p=h.getSelfOrHeaderFooterModel(m).getBody();if(p==null)return!1;Object.assign(g,g);const{startOffset:I,endOffset:v}=g,R=n.length,b=[{startOffset:I+R,endOffset:I+R,collapsed:!0,style:f}],E={id:M.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:b}},T=d.getDefaultStyle(),B=d.getStyleCache(),D=so((W=p.customRanges)!=null?W:[],I+r,Ul.includes(e)),U=tn((V=p.textRuns)!=null?V:[],a?v:I+r,T,B),O=ao((k=p.customDecorations)!=null?k:[],I+r),P=new i.TextX,N=i.JSONX.getInstance();if(!g.collapsed&&a){const j=i.BuildTextUtils.selection.delete([g],p,0,null,!1);P.push(...j),E.params.textRanges=[{startOffset:I+R,endOffset:I+R,collapsed:!0}]}else P.push({t:i.TextXActionType.RETAIN,len:I});r>0&&P.push({t:i.TextXActionType.DELETE,len:r}),P.push({t:i.TextXActionType.INSERT,body:{dataStream:n,textRuns:U?[{...U,st:0,ed:n.length}]:[],customRanges:D?[{...D,startIndex:0,endIndex:n.length-1}]:[],customDecorations:O.map(j=>({...j,startIndex:0,endIndex:n.length-1}))},len:n.length});const H=q(h,m);E.params.actions=N.editOp(P.serialize(),H),E.params.noHistory=!s,E.params.isCompositionEnd=s;const F=c.syncExecuteCommand(E.id,E.params);return u.pushUndoRedoMutationParams(F,E.params),!!F}},Gt={type:i.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(o,t)=>{var u,h,g;const e=o.get(i.ICommandService),n=o.get(i.IUndoRedoService),r=o.get(i.IUniverInstanceService);let s=(u=r.getCurrentUniverDocInstance())==null?void 0:u.getUnitId();if(!s)return!1;let a=1;if(t&&(s=(h=t.documentId)!=null?h:s,a=(g=t.zoomRatio)!=null?g:a),!r.getUniverDocInstance(s))return!1;const l={zoomRatio:a,unitId:s},A=Da(o,l);return e.syncExecuteCommand(de.id,l)?(n.pushUndoRedo({unitID:s,undoMutations:[{id:de.id,params:A}],redoMutations:[{id:de.id,params:l}]}),!0):!1}},Qo={id:"doc.table.tab-in-table",type:i.CommandType.COMMAND,handler:async(o,t)=>{var f;const{shift:e}=t,n=o.get(M.DocSelectionManagerService),r=n.getDocRanges(),s=o.get(i.ICommandService),c=o.get(i.IUniverInstanceService).getCurrentUniverDocInstance();if(!c)return!1;const l=(f=r.find(m=>m.isActive))!=null?f:r[0],A=c.getUnitId(),d=le(o,A),u=d==null?void 0:d.getSkeleton(),h=u==null?void 0:u.getViewModel().getSelfOrHeaderFooterViewModel(l==null?void 0:l.segmentId);if(h==null||l==null)return!1;let g=null;if(e?g=Ar(h,l,Xn.PREV):g=Ar(h,l,Xn.NEXT),g){const{startOffset:m,endOffset:p}=g,S=[{startOffset:m,endOffset:p}];return n.replaceDocRanges(S),!0}return e===!1?await s.executeCommand(Do.id,{position:an.BELLOW}):!0}};var wl=Object.defineProperty,Ql=Object.getOwnPropertyDescriptor,Ll=(o,t,e,n)=>{for(var r=n>1?void 0:n?Ql(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&wl(t,e,r),r},Fn=(o,t)=>(e,n)=>t(e,n,o);let qn=class{constructor(o,t,e){x(this,"_docContainer");x(this,"getComponent",o=>{if(this._docContainer=o,!o.getContentRef().current)throw new Error("container is not ready")});x(this,"changeLocale",o=>{this._localeService.setLocale(o)});this._localeService=o,this._injector=t,this._configService=e}getUIConfig(){return{injector:this._injector,config:this._configService.getConfig(Io),changeLocale:this.changeLocale,getComponent:this.getComponent}}getContentRef(){return this._docContainer.getContentRef()}UIDidMount(o){if(this._docContainer)return o(this._docContainer)}getDocContainer(){return this._docContainer}};qn=Ll([Fn(0,i.Inject(i.LocaleService)),Fn(1,i.Inject(i.Injector)),Fn(2,i.IConfigService)],qn);var Fl=Object.defineProperty,Hl=Object.getOwnPropertyDescriptor,kl=(o,t,e,n)=>{for(var r=n>1?void 0:n?Hl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Fl(t,e,r),r},jl=(o,t)=>(e,n)=>t(e,n,o);let Xt=class extends i.RxDisposable{constructor(t){super();x(this,"_docContainerController");this._injector=t,this._docContainerController=this._injector.createInstance(qn)}};Xt=kl([jl(0,i.Inject(i.Injector))],Xt);var Vl=Object.defineProperty,Wl=Object.getOwnPropertyDescriptor,Kl=(o,t,e,n)=>{for(var r=n>1?void 0:n?Wl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Vl(t,e,r),r},Sr=(o,t)=>(e,n)=>t(e,n,o);let Yt=class extends i.Disposable{constructor(o,t){super(),this._docAutoFormatService=o,this._renderManagerService=t,this._initListTabAutoFormat(),this._initListSpaceAutoFormat(),this._initDefaultEnterFormat(),this._initExitListAutoFormat()}_initListTabAutoFormat(){this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:Pe.id,match:o=>{var r;const{selection:t,paragraphs:e,unit:n}=o;if(e.length===1&&t.startOffset===e[0].paragraphStart&&e[0].bullet){const s=(r=n.getBody())==null?void 0:r.paragraphs,a=s==null?void 0:s.filter(c=>{var l;return((l=c.bullet)==null?void 0:l.listId)===e[0].bullet.listId});return(a==null?void 0:a.findIndex(c=>c.startIndex===e[0].startIndex))!==0}else if(e.length>1&&e.some(s=>s.bullet))return!0;return!1},getMutations(o){const t=o.commandParams;return[{id:zt.id,params:{type:t!=null&&t.shift?pt.decrease:pt.increase}}]},priority:100})),this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:Pe.id,match:o=>{const{selection:t,unit:e}=o,{startNodePosition:n,endNodePosition:r}=t,s=this._renderManagerService.getRenderById(e.getUnitId()),a=s==null?void 0:s.with(M.DocSkeletonManagerService).getSkeleton();return a==null?!1:!!(n&&r&&Wr(a,n,r)||n&&!r&&n.path.indexOf("cells")>-1)},getMutations(o){const t=o.commandParams;return[{id:Qo.id,params:{shift:!!(t!=null&&t.shift)}}]},priority:99}))}_initListSpaceAutoFormat(){this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:Et.id,match:o=>{var s;const{selection:t,paragraphs:e,unit:n}=o;if(!t.collapsed||e.length!==1)return!1;const r=(s=n.getBody())==null?void 0:s.dataStream.slice(e[0].paragraphStart,e[0].paragraphEnd-1);return!!(r&&Object.keys(i.QuickListTypeMap).includes(r))},getMutations(o){var r;const{paragraphs:t,unit:e}=o,n=(r=e.getBody())==null?void 0:r.dataStream.slice(t[0].paragraphStart,t[0].paragraphEnd-1);if(n&&Object.keys(i.QuickListTypeMap).includes(n)){const s=i.QuickListTypeMap[n];return[{id:So.id,params:{listType:s,paragraph:t[0]}}]}return[]}}))}_initExitListAutoFormat(){this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:Je.id,match:o=>{const{paragraphs:t}=o;return!!(t.length===1&&t[0].bullet&&t[0].paragraphStart===t[0].paragraphEnd)},getMutations:o=>{const t=o.paragraphs[0].bullet;return t?t.nestingLevel>0?[{id:zt.id,params:{type:pt.decrease}}]:[{id:rt.id,params:{listType:o.paragraphs[0].bullet.listType}}]:[]}}))}_initDefaultEnterFormat(){this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:Je.id,match:()=>!0,getMutations(){return[{id:Bo.id}]},priority:-9999}))}};Yt=Kl([Sr(0,i.Inject(exports.DocAutoFormatService)),Sr(1,y.IRenderManagerService)],Yt);function zl(o){return o.rows[0].cells[0].sections[0].columns[0].lines[0]}function Gl(o){const t=o.rows[o.rows.length-1],e=t.cells[t.cells.length-1];return y.getLastLine(e)}function Xl(o,t){const{ed:e}=o,{skeTables:n}=t;let r=null;for(const s of n.values())if(s.st===e+1){r=s;break}return r}function Ir(o){const t=o==null?void 0:o.parent;let e=null,n=null;if(o==null||t==null)return{lineBeforeTable:e,lineAfterTable:n};const{st:r,ed:s}=o,a=t.type===y.DocumentSkeletonPageType.CELL?[t]:t.parent.pages;return y.lineIterator(a,c=>{c.st===s+1?n=c:c.ed===r-1&&(e=c)}),{lineBeforeTable:e,lineAfterTable:n}}function yi(o){return o.sections[0].columns[0].lines.length===0}function Oi(o){var a,c;const t=o.parent,e=t==null?void 0:t.parent,n=e==null?void 0:e.tableId;if(t==null||e==null)return;const r=t.cells.indexOf(o);let s=e.rows[e.rows.indexOf(t)+1];if(s==null&&n.indexOf("#-#")){const[l,A]=n.split("#-#"),d=(c=(a=e.parent)==null?void 0:a.parent)==null?void 0:c.pages,u=`${l}#-#${Number.parseInt(A)+1}`;if(d)for(const h of d){const{skeTables:g}=h;if(g.has(u)){const f=g.get(u);if(f!=null&&f.rows.length){s=f.rows.find(m=>!m.isRepeatRow);break}}}}if(s!=null){const l=s.cells[r];return yi(l)?Oi(l):l}}function xi(o){var s,a;const t=o.parent,e=t==null?void 0:t.parent;if(t==null||e==null)return;let n=e.rows[e.rows.indexOf(t)-1];const r=t.cells.indexOf(o);if((n==null||n.isRepeatRow)&&e.tableId.indexOf("#-#")){const[c,l]=e.tableId.split("#-#"),A=(a=(s=e.parent)==null?void 0:s.parent)==null?void 0:a.pages,d=`${c}#-#${Number.parseInt(l)-1}`;if(A)for(const u of A){const{skeTables:h}=u;if(h.has(d)){const g=h.get(d);if(g!=null&&g.rows.length){n=g.rows[g.rows.length-1];break}}}}if(n!=null){const c=n.cells[r];return yi(c)?xi(c):c}}function Yl(o,t){const{st:e}=o,{skeTables:n}=t;let r=null;for(const s of n.values())if(s.ed===e-1){r=s;break}return r}function ql(o){return o.sections[0].columns[0].lines[0]}function Jl(o){const t=y.getLastColumn(o);return t.lines[t.lines.length-1]}var Zl=Object.defineProperty,$l=Object.getOwnPropertyDescriptor,eA=(o,t,e,n)=>{for(var r=n>1?void 0:n?$l(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Zl(t,e,r),r},Pt=(o,t)=>(e,n)=>t(e,n,o);let qt=class extends i.Disposable{constructor(t,e,n,r){super();x(this,"_onInputSubscription");this._univerInstanceService=t,this._renderManagerService=e,this._textSelectionManagerService=n,this._commandService=r,this._commandExecutedListener()}dispose(){var t;super.dispose(),(t=this._onInputSubscription)==null||t.unsubscribe()}_commandExecutedListener(){const t=[Ee.id,ve.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!t.includes(e.id))return;const n=e.params;switch(e.id){case Ee.id:return this._handleMoveCursor(n.direction);case ve.id:return this._handleShiftMoveSelection(n.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(t){var v,R,b;const e=this._textSelectionManagerService.getActiveTextRange(),n=this._textSelectionManagerService.getTextRanges(),r=this._univerInstanceService.getCurrentUniverDocInstance();if(r==null)return;const s=(v=this._renderManagerService.getRenderById(r.getUnitId()))==null?void 0:v.with(M.DocSkeletonManagerService).getSkeleton(),a=this._getDocObject();if(e==null||s==null||a==null)return;const{startOffset:c,endOffset:l,style:A,collapsed:d,direction:u,segmentId:h,startNodePosition:g,endNodePosition:f,segmentPage:m}=e;if(n.length>1){let E=Number.POSITIVE_INFINITY,T=Number.NEGATIVE_INFINITY;for(const B of n)E=Math.min(E,B.startOffset),T=Math.max(T,B.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:t===i.Direction.LEFT||t===i.Direction.UP?T:E,endOffset:t===i.Direction.LEFT||t===i.Direction.UP?E:T,style:A}],!1);return}const p=d||u===i.RANGE_DIRECTION.FORWARD?c:l;let S=d||u===i.RANGE_DIRECTION.FORWARD?l:c;const I=(R=r.getSelfOrHeaderFooterModel(h).getBody().dataStream.length)!=null?R:Number.POSITIVE_INFINITY;if(t===i.Direction.LEFT||t===i.Direction.RIGHT){const E=s.findNodeByCharIndex(S-1,h,m),T=s.findNodeByCharIndex(S,h,m);S=t===i.Direction.RIGHT?S+T.count:S-((b=E==null?void 0:E.count)!=null?b:0),S=Math.min(I-2,Math.max(0,S)),this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:S,style:A}],!1),this._scrollToFocusNodePosition(r.getUnitId(),S)}else{const E=s.findNodeByCharIndex(S,h,m),T=a.document.getOffsetConfig(),B=d?g:u===i.RANGE_DIRECTION.FORWARD?f:g,D=this._getTopOrBottomPosition(s,E,B,t===i.Direction.DOWN,!0);if(D==null){const O=t===i.Direction.UP?0:I-2;if(O===S)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:O,style:A}],!1);return}const U=new Ie(T,s).getRangePointData(D,D).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:U.endOffset,style:A}],!1),this._scrollToFocusNodePosition(r.getUnitId(),U.endOffset)}}_handleMoveCursor(t){var I,v,R,b;const e=this._textSelectionManagerService.getActiveTextRange(),n=this._textSelectionManagerService.getTextRanges(),r=this._univerInstanceService.getCurrentUniverDocInstance();if(r==null)return!1;const s=(I=this._renderManagerService.getRenderById(r.getUnitId()))==null?void 0:I.with(M.DocSkeletonManagerService).getSkeleton(),a=this._getDocObject();if(e==null||s==null||a==null||n==null)return;const{startOffset:c,endOffset:l,style:A,collapsed:d,segmentId:u,startNodePosition:h,endNodePosition:g,segmentPage:f}=e,m=r.getSelfOrHeaderFooterModel(u).getBody();if(m==null)return;const p=(v=m.dataStream.length)!=null?v:Number.POSITIVE_INFINITY,S=(R=r.getCustomRanges())!=null?R:[];if(t===i.Direction.LEFT||t===i.Direction.RIGHT){let E;if(!e.collapsed||n.length>1){let D=Number.POSITIVE_INFINITY,U=Number.NEGATIVE_INFINITY;for(const O of n)D=Math.min(D,O.startOffset),U=Math.max(U,O.endOffset);E=t===i.Direction.LEFT?D:U}else{const D=s.findNodeByCharIndex(c-1,u,f),U=s.findNodeByCharIndex(c,u,f),O=s.findNodeByCharIndex(c+1,u,f);t===i.Direction.LEFT?E=Math.max(0,c-((b=D==null?void 0:D.count)!=null?b:1)):E=Math.min(p-2,l+U.count+((O==null?void 0:O.streamType)===i.DataStreamTreeTokenType.SECTION_BREAK?1:0))}const T=[i.DataStreamTreeTokenType.TABLE_START,i.DataStreamTreeTokenType.TABLE_END,i.DataStreamTreeTokenType.TABLE_ROW_START,i.DataStreamTreeTokenType.TABLE_ROW_END,i.DataStreamTreeTokenType.TABLE_CELL_START,i.DataStreamTreeTokenType.TABLE_CELL_END,i.DataStreamTreeTokenType.SECTION_BREAK];if(t===i.Direction.LEFT)for(;T.includes(m.dataStream[E]);)E--;else for(;T.includes(m.dataStream[E]);)E++;S.filter(D=>D.wholeEntity&&D.startIndex<E&&D.endIndex>=E).forEach(D=>{t===i.Direction.LEFT?E=Math.min(D.startIndex,E):E=Math.max(D.endIndex+1,E)}),this._textSelectionManagerService.replaceTextRanges([{startOffset:Math.max(0,E),endOffset:Math.max(0,E),style:A}],!1),this._scrollToFocusNodePosition(r.getUnitId(),E)}else{const E=s.findNodeByCharIndex(c,u,f),T=s.findNodeByCharIndex(l,u,f),B=a.document.getOffsetConfig(),D=this._getTopOrBottomPosition(s,t===i.Direction.UP||d?E:T,t===i.Direction.UP||d?h:g,t===i.Direction.DOWN);if(D==null){let O;d?O=t===i.Direction.UP?0:p-2:O=t===i.Direction.UP?c:l,this._textSelectionManagerService.replaceTextRanges([{startOffset:Math.max(0,O),endOffset:Math.max(0,O),style:A}],!1);return}const U=new Ie(B,s).getRangePointData(D,D).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...U,style:A}],!1),this._scrollToFocusNodePosition(r.getUnitId(),U.endOffset)}}_getTopOrBottomPosition(t,e,n,r,s=!1){if(e==null||n==null)return;const a=this._getGlyphLeftOffsetInLine(e),c=this._getNextOrPrevLine(e,r,s);if(c==null)return;const l=this._matchPositionByLeftOffset(t,c,a,n);if(l!=null)return{...l,isBack:!0}}_getGlyphLeftOffsetInLine(t){const e=t.parent;if(e==null)return Number.NEGATIVE_INFINITY;const n=e.left,{left:r}=t;return n+r}_matchPositionByLeftOffset(t,e,n,r){const s={distance:Number.POSITIVE_INFINITY};for(const c of e.divides){const l=c.left;for(const A of c.glyphGroup){if(A.streamType===i.DataStreamTreeTokenType.SECTION_BREAK)continue;const{left:d}=A,u=l+d,h=Math.abs(n-u);h<s.distance&&(s.glyph=A,s.distance=h)}}if(s.glyph==null)return;const{segmentPage:a}=r;return t.findPositionByGlyph(s.glyph,a)}_getNextOrPrevLine(t,e,n=!1){var m,p,S,I,v,R,b,E,T,B,D,U;const r=t.parent,s=r==null?void 0:r.parent,a=s==null?void 0:s.parent,c=a==null?void 0:a.parent,l=c==null?void 0:c.parent;if(r==null||s==null||a==null||c==null||l==null)return;const A=a.lines.indexOf(s);if(A===-1)return;let d;if(l.type===y.DocumentSkeletonPageType.CELL&&n){const O=Er(l,e);if(O)return O}if(e===!0){d=a.lines[A+1];const O=Xl(s,l);if(O){const P=zl(O);P&&(d=P)}}else{d=a.lines[A-1];const O=Yl(s,l);if(O){const P=Gl(O);P&&(d=P)}}if(d!=null)return d;const u=c.columns.indexOf(a);if(u===-1)return;if(e===!0)d=(m=c.columns[u+1])==null?void 0:m.lines[0];else{const O=(S=(p=c.columns)==null?void 0:p[u-1])==null?void 0:S.lines;d=O==null?void 0:O[O.length-1]}if(d!=null)return d;const h=l.sections.indexOf(c);if(h===-1)return;if(e===!0)d=(v=(I=l.sections[h-1])==null?void 0:I.columns[0])==null?void 0:v.lines[0];else{const O=(b=(R=l.sections)==null?void 0:R[h-1])==null?void 0:b.columns,P=O==null?void 0:O[O.length-1],N=P==null?void 0:P.lines;d=N==null?void 0:N[N.length-1]}if(d!=null)return d;if(l.type===y.DocumentSkeletonPageType.CELL)return Er(l,e);const g=l.parent;if(g==null)return;const f=g.pages.indexOf(l);if(f!==-1){if(e===!0)d=(B=(T=(E=g.pages[f+1])==null?void 0:E.sections[0])==null?void 0:T.columns[0])==null?void 0:B.lines[0];else{const O=(D=g.pages[f-1])==null?void 0:D.sections;if(O==null)return;const P=(U=O[O.length-1])==null?void 0:U.columns,N=P[P.length-1],H=N==null?void 0:N.lines;d=H[H.length-1]}if(d!=null)return d}}_scrollToFocusNodePosition(t,e){var r;const n=(r=this._renderManagerService.getRenderById(t))==null?void 0:r.with(exports.DocBackScrollRenderController);n!=null&&n.scrollToRange({startOffset:e,endOffset:e,collapsed:!0})}_getDocObject(){return Nr(this._univerInstanceService,this._renderManagerService)}};qt=eA([Pt(0,i.IUniverInstanceService),Pt(1,y.IRenderManagerService),Pt(2,i.Inject(M.DocSelectionManagerService)),Pt(3,i.ICommandService)],qt);function Er(o,t){var n,r;let e=null;if(t===!0){const s=Oi(o);if(s)e=ql(s);else{const a=(n=o.parent)==null?void 0:n.parent,{lineAfterTable:c}=Ir(a);c&&(e=c)}}else{const s=xi(o);if(s)e=Jl(s);else{const a=(r=o.parent)==null?void 0:r.parent,{lineBeforeTable:c}=Ir(a);c&&(e=c)}}return e}const tA="univer-create",nA="univer-create-item",oA="univer-create-label",rA="univer-create-input",Me={create:tA,createItem:nA,createLabel:oA,createInput:rA},iA=({handleRowColChange:o,tableCreateParams:t})=>{const e=i.useDependency(i.LocaleService),[n,r]=L.useState(3),[s,a]=L.useState(5);function c(l,A){r(l),a(A),o(l,A)}return L.useEffect(()=>{r(t.rowCount),a(t.colCount)},[t]),Q.jsxs("div",{className:Me.create,children:[Q.jsxs("div",{className:Me.createItem,children:[Q.jsx("span",{className:Me.createLabel,children:e.t("toolbar.table.rowCount")}),Q.jsx(ae.InputNumber,{min:1,max:20,precision:0,value:n,onChange:l=>{c(l,s)},className:Me.createInput})]}),Q.jsxs("div",{className:Me.createItem,children:[Q.jsx("span",{className:Me.createLabel,children:e.t("toolbar.table.colCount")}),Q.jsx(ae.InputNumber,{min:1,max:20,precision:0,value:s,onChange:l=>{c(n,l)},className:Me.createInput})]})]})};var sA=Object.defineProperty,aA=Object.getOwnPropertyDescriptor,cA=(o,t,e,n)=>{for(var r=n>1?void 0:n?aA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&sA(t,e,r),r},vr=(o,t)=>(e,n)=>t(e,n,o);let Jt=class extends i.Disposable{constructor(o,t){super(),this._commandService=o,this._componentManager=t,this._initialize()}_initialize(){this._init(),this._registerCommands(),this._initCustomComponents()}_registerCommands(){[bn].forEach(o=>this.disposeWithMe(this._commandService.registerCommand(o)))}_initCustomComponents(){const o=this._componentManager;this.disposeWithMe(o.register(vi,iA))}_init(){}};Jt=cA([vr(0,i.ICommandService),vr(1,i.Inject(C.ComponentManager))],Jt);const Jn=4;var lA=Object.defineProperty,AA=Object.getOwnPropertyDescriptor,dA=(o,t,e,n)=>{for(var r=n>1?void 0:n?AA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&lA(t,e,r),r},Nt=(o,t)=>(e,n)=>t(e,n,o);function Di(o,t){const e=Cr(o.left,o.top,t),n=Cr(o.right,o.bottom,t);return{left:e.x,top:e.y,right:n.x,bottom:n.y}}function Cr(o,t,e){const{scaleX:n,scaleY:r}=e.getAncestorScale(),s=e.getViewport(he.VIEW_MAIN);if(!s)return{x:o,y:t};const{viewportScrollX:a,viewportScrollY:c}=s,l=(o-a)*n,A=(t-c)*r;return{x:l,y:A}}function Tr(o,t,e){const{scaleX:n,scaleY:r}=e.getAncestorScale(),s=e.getViewport(he.VIEW_MAIN);if(!s)return{x:o,y:t};const{viewportScrollX:a,viewportScrollY:c}=s,l=o/n+a,A=t/r+c;return{x:l,y:A}}const jt=(o,t)=>{const{scene:e,mainComponent:n,engine:r}=t,s=t.with(M.DocSkeletonManagerService).getSkeleton(),a=s.findNodePositionByCharIndex(o.startOffset,!0,o.segmentId,o.segmentPage),c=s.findNodePositionByCharIndex(o.endOffset,!0,o.segmentId,o.segmentPage),l=n;if(!c||!a)return;const A=l.getOffsetConfig(),{docsLeft:d,docsTop:u}=A,h=r.getCanvasElement(),g=h.getBoundingClientRect(),f=y.pxToNum(h.style.width),{top:m,left:p,width:S}=g,I=S/f,{scaleX:v,scaleY:R}=e.getAncestorScale(),b=new Ie(A,s),{borderBoxPointGroup:E}=b.getRangePointData(a,c);return nn(E).map(D=>Di(D,e)).map(D=>({left:(D.left+d*v)*I+p,right:(D.right+d*v)*I+p,top:(D.top+u*R)*I+m,bottom:(D.bottom+u*R)*I+m}))};exports.DocCanvasPopManagerService=class extends i.Disposable{constructor(t,e,n,r){super(),this._globalPopupManagerService=t,this._renderManagerService=e,this._univerInstanceService=n,this._commandService=r}_createObjectPositionObserver(t,e){const n=()=>{const{scene:l,engine:A}=e,{left:d,top:u,width:h,height:g}=t,f={left:d,right:d+h,top:u,bottom:u+g},m=A.getCanvasElement(),p=m.getBoundingClientRect(),S=y.pxToNum(m.style.width),I=Di(f,l),{top:v,left:R,width:b}=p,E=b/S;return{left:I.left*E+R,right:I.right*E+R,top:I.top*E+v,bottom:I.bottom*E+v}},r=n(),s=new _.BehaviorSubject(r),a=new i.DisposableCollection;a.add(this._commandService.onCommandExecuted(l=>{if(l.id===de.id||l.id===M.RichTextEditingMutation.id){const A=n();A&&s.next(A)}}));const c=e.scene.getViewport(he.VIEW_MAIN);return c&&a.add(c.onScrollAfter$.subscribeEvent(()=>{s.next(n())})),{position:r,position$:s,disposable:a}}_createRangePositionObserver(t,e){var c;const n=(c=jt(t,e))!=null?c:[],r=new _.BehaviorSubject(n),s=new i.DisposableCollection;s.add(this._commandService.onCommandExecuted(l=>{if((l.id===de.id||l.id===M.RichTextEditingMutation.id)&&l.params.unitId===e.unitId){const d=jt(t,e);d&&r.next(d)}}));const a=e.scene.getViewport(he.VIEW_MAIN);return a&&s.add(a.onScrollAfter$.subscribeEvent(()=>{const l=jt(t,e);l&&r.next(l)})),{positions:n,positions$:r,disposable:s}}attachPopupToObject(t,e,n){const r=this._renderManagerService.getRenderById(n);if(!r)throw new Error(`Current render not found, unitId: ${n}`);const{position:s,position$:a,disposable:c}=this._createObjectPositionObserver(t,r),l=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:s,anchorRect$:a,canvasElement:r.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(l),a.complete(),c.dispose()}}}attachPopupToRange(t,e,n){if(!this._univerInstanceService.getUnit(n))throw new Error(`Document not found, unitId: ${n}`);const{direction:s="top",multipleDirection:a}=e,c=this._renderManagerService.getRenderById(n);if(!c)throw new Error(`Current render not found, unitId: ${n}`);const{positions:l,positions$:A,disposable:d}=this._createRangePositionObserver(t,c),u=A.pipe(_.map(g=>s.includes("top")?g[0]:g[g.length-1])),h=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:s.includes("top")?l[0]:l[l.length-1],anchorRect$:u,excludeRects:l,excludeRects$:A,direction:s.includes("top")||s.includes("bottom")?l.length>1?a:s:"bottom",canvasElement:c.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(h),A.complete(),d.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==h}}};exports.DocCanvasPopManagerService=dA([Nt(0,i.Inject(C.ICanvasPopupService)),Nt(1,y.IRenderManagerService),Nt(2,i.IUniverInstanceService),Nt(3,i.ICommandService)],exports.DocCanvasPopManagerService);var uA=Object.defineProperty,gA=Object.getOwnPropertyDescriptor,hA=(o,t,e,n)=>{for(var r=n>1?void 0:n?gA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&uA(t,e,r),r},mA=(o,t)=>(e,n)=>t(e,n,o);const fA=(o,t,e,n)=>{var h,g,f,m,p;const r=e.findNodePositionByCharIndex(o.startOffset,!0,o.segmentId,n),s=e.getSkeletonData();let a=o.endOffset;if(o.segmentId){const S=(p=Array.from((g=(h=s==null?void 0:s.skeFooters.get(o.segmentId))==null?void 0:h.values())!=null?g:[])[0])!=null?p:Array.from((m=(f=s==null?void 0:s.skeHeaders.get(o.segmentId))==null?void 0:f.values())!=null?m:[])[0];S&&(a=Math.min(S.ed,a))}const c=e.findNodePositionByCharIndex(a,!0,o.segmentId,n);if(!c||!r)return;const l=t.getOffsetConfig(),A=new Ie(l,e),{borderBoxPointGroup:d}=A.getRangePointData(r,c);return nn(d).map(S=>({top:S.top+l.docsTop-Jn,bottom:S.bottom+l.docsTop+Jn,left:S.left+l.docsLeft,right:S.right+l.docsLeft}))},pA=(o,t,e,n=-1)=>{const r=e.findPositionByGlyph(o,n);if(!r)return;const s=t.getOffsetConfig(),a={...r,isBack:!0},c=new Ie(s,e),{borderBoxPointGroup:l}=c.getRangePointData(a,a),d=nn(l)[0];return{top:d.top+s.docsTop,bottom:d.bottom+s.docsTop,left:d.left+s.docsLeft,right:d.left+s.docsLeft+o.width}};exports.DocEventManagerService=class extends i.Disposable{constructor(e,n){super();x(this,"_hoverCustomRanges$",new _.BehaviorSubject([]));x(this,"hoverCustomRanges$",this._hoverCustomRanges$.pipe(_.distinctUntilChanged((e,n)=>e.length===n.length&&e.every((r,s)=>n[s].range.rangeId===r.range.rangeId&&n[s].segmentId===r.segmentId&&n[s].segmentPageIndex===r.segmentPageIndex&&n[s].range.startIndex===r.range.startIndex))));x(this,"_clickCustomRanges$",new _.Subject);x(this,"clickCustomRanges$",this._clickCustomRanges$.asObservable());x(this,"_hoverBullet$",new _.Subject);x(this,"hoverBullet$",this._hoverBullet$.pipe(_.distinctUntilChanged((e,n)=>(e==null?void 0:e.paragraph.startIndex)===(n==null?void 0:n.paragraph.startIndex)&&(e==null?void 0:e.segmentId)===(n==null?void 0:n.segmentId)&&(e==null?void 0:e.segmentPageIndex)===(n==null?void 0:n.segmentPageIndex))));x(this,"_clickBullet$",new _.Subject);x(this,"clickBullets$",this._clickBullet$.asObservable());x(this,"_customRangeDirty",!0);x(this,"_bulletDirty",!0);x(this,"_customRangeBounds",[]);x(this,"_bulletBounds",[]);this._context=e,this._docSkeletonManagerService=n,this._initResetDirty(),this._initEvents(),this._initPointer()}get _skeleton(){return this._docSkeletonManagerService.getSkeleton()}get _documents(){return this._context.mainComponent}dispose(){this._hoverCustomRanges$.complete(),this._clickCustomRanges$.complete(),super.dispose()}_initPointer(){let e=y.CURSOR_TYPE.TEXT;this.disposeWithMe(this.hoverCustomRanges$.subscribe(n=>{n.length?(e=this._context.scene.getCursor(),this._context.scene.setCursor(y.CURSOR_TYPE.POINTER)):this._context.scene.setCursor(e)}))}_initResetDirty(){this.disposeWithMe(this._skeleton.dirty$.subscribe(()=>{this._customRangeDirty=!0,this._bulletDirty=!0})),this.disposeWithMe(i.fromEventSubject(this._context.engine.onTransformChange$).pipe(_.filter(e=>e.type===y.TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize)).subscribe(()=>{this._customRangeDirty=!0,this._bulletDirty=!0}))}_initEvents(){this.disposeWithMe(i.fromEventSubject(this._context.scene.onPointerMove$).pipe(_.throttleTime(30)).subscribe(r=>{this._hoverCustomRanges$.next(this._calcActiveRanges(r)),this._hoverBullet$.next(this._calcActiveBullet(r))})),this.disposeWithMe(this._context.scene.onPointerEnter$.subscribeEvent(()=>{this._hoverBullet$.next(null),this._hoverCustomRanges$.next([])}));const e=i.fromEventSubject(this._context.mainComponent.onPointerDown$),n=i.fromEventSubject(this._context.scene.onPointerUp$);this.disposeWithMe(e.pipe(_.switchMap(r=>n.pipe(_.take(1),_.map(s=>({down:r,up:s})))),_.filter(({down:r,up:s})=>r.target===s.target&&s.timeStamp-r.timeStamp<300)).subscribe(({down:r})=>{if(r.button===2)return;const s=this._calcActiveRanges(r);s.length&&this._clickCustomRanges$.next(s.pop());const a=this._calcActiveBullet(r);a&&this._clickBullet$.next(a)}))}_buildCustomRangeBoundsBySegment(e,n=-1){var a,c,l;const r=(l=(c=(a=this._context.unit.getSelfOrHeaderFooterModel(e))==null?void 0:a.getBody())==null?void 0:c.customRanges)!=null?l:[],s=[];return r.forEach(A=>{const d={startOffset:A.startIndex,endOffset:A.endIndex+1,collapsed:!1,segmentId:e},u=fA(d,this._documents,this._skeleton,n);if(!u)return null;s.push({customRange:A,rects:u,segmentId:e,segmentPageIndex:n})}),s}_buildCustomRangeBounds(){var n;if(!this._customRangeDirty)return;this._customRangeDirty=!1;const e=[];e.push(...this._buildCustomRangeBoundsBySegment()),(n=this._skeleton.getSkeletonData())==null||n.pages.forEach((r,s)=>{r.headerId&&e.push(...this._buildCustomRangeBoundsBySegment(r.headerId,s)),r.footerId&&e.push(...this._buildCustomRangeBoundsBySegment(r.footerId,s))}),this._customRangeBounds=e}_calcActiveRanges(e){this._buildCustomRangeBounds();const{offsetX:n,offsetY:r}=e,{x:s,y:a}=Tr(n,r,this._context.scene);return this._customRangeBounds.filter(l=>l.rects.some(A=>{const{left:d,right:u,top:h,bottom:g}=A;return s>=d&&s<=u&&a>=h&&a<=g})).map(l=>({segmentId:l.segmentId,range:l.customRange,segmentPageIndex:l.segmentPageIndex,rects:l.rects}))}_buildBulletBoundsBySegment(e,n=-1){var A,d,u,h,g;const r=(A=this._context.unit.getSelfOrHeaderFooterModel(e))==null?void 0:A.getBody(),s=((d=r==null?void 0:r.paragraphs)!=null?d:[]).filter(f=>f.bullet&&f.bullet.listType.indexOf("CHECK_LIST")===0),a=[],c=this._skeleton.getSkeletonData();if(!c)return a;const l=f=>{var m,p,S;for(const I of f){const v=[...I.sections];if(I.skeTables){const R=Array.from(I.skeTables.values());v.push(...R.map(b=>b.rows.map(E=>E.cells.map(T=>T.sections))).flat(4))}for(const R of v)for(const b of R.columns)for(const E of b.lines)if(E.paragraphStart){const T=s.find(B=>B.startIndex===E.paragraphIndex);if(T){const B=E,D=(S=(p=(m=B==null?void 0:B.divides)==null?void 0:m[0])==null?void 0:p.glyphGroup)==null?void 0:S[0];if(!D)continue;const U=pA(D,this._documents,this._skeleton,n);if(!U)continue;a.push({rect:U,segmentId:e,segmentPageIndex:n,paragraph:T})}}}return a};if(e){const f=(g=(u=c.skeFooters.get(e))==null?void 0:u.values())!=null?g:(h=c.skeHeaders.get(e))==null?void 0:h.values();return f?l(Array.from(f)):a}return l(c.pages)}_buildBulletBounds(){var e;this._bulletDirty&&(this._bulletDirty=!1,this._bulletBounds=[],this._bulletBounds.push(...this._buildBulletBoundsBySegment()),(e=this._skeleton.getSkeletonData())==null||e.pages.forEach((n,r)=>{n.headerId&&this._bulletBounds.push(...this._buildBulletBoundsBySegment(n.headerId,r)),n.footerId&&this._bulletBounds.push(...this._buildBulletBoundsBySegment(n.footerId,r))}))}_calcActiveBullet(e){this._buildBulletBounds();const{offsetX:n,offsetY:r}=e,{x:s,y:a}=Tr(n,r,this._context.scene);return this._bulletBounds.find(l=>{const{left:A,right:d,top:u,bottom:h}=l.rect;return s>=A&&s<=d&&a>=u&&a<=h})}};exports.DocEventManagerService=hA([mA(1,i.Inject(M.DocSkeletonManagerService))],exports.DocEventManagerService);var SA=Object.defineProperty,IA=Object.getOwnPropertyDescriptor,EA=(o,t,e,n)=>{for(var r=n>1?void 0:n?IA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&SA(t,e,r),r},Ut=(o,t)=>(e,n)=>t(e,n,o);let Zn=class extends i.Disposable{constructor(o,t,e,n,r){super(),this._context=o,this._docSkeletonManagerService=t,this._commandService=e,this._docEventManagerService=n,this._textSelectionManagerService=r,this._initPointerDownObserver(),this._initHoverCursor()}_initPointerDownObserver(){this._docEventManagerService.clickBullets$.subscribe(o=>{const t=this._textSelectionManagerService.getTextRanges();this._commandService.executeCommand(rn.id,{index:o.paragraph.startIndex,segmentId:o.segmentId,textRanges:t})})}_initHoverCursor(){this.disposeWithMe(this._docEventManagerService.hoverBullet$.subscribe(o=>{o?this._context.mainComponent.setCursor(y.CURSOR_TYPE.POINTER):this._context.mainComponent.setCursor(y.CURSOR_TYPE.TEXT)}))}_getTransformCoordForDocumentOffset(o,t,e,n){const{documentTransform:r}=o.getOffsetConfig(),s=t.transformVector2SceneCoord(y.Vector2.FromArray([e,n]));if(s)return r.clone().invert().applyPoint(s)}};Zn=EA([Ut(1,i.Inject(M.DocSkeletonManagerService)),Ut(2,i.ICommandService),Ut(3,i.Inject(exports.DocEventManagerService)),Ut(4,i.Inject(M.DocSelectionManagerService))],Zn);var vA=Object.defineProperty,CA=Object.getOwnPropertyDescriptor,TA=(o,t,e,n)=>{for(var r=n>1?void 0:n?CA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&vA(t,e,r),r},ut=(o,t)=>(e,n)=>t(e,n,o);let Zt=class extends i.RxDisposable{constructor(o,t,e,n,r,s){super(),this._context=o,this._commandService=t,this._docClipboardService=e,this._docSelectionRenderService=n,this._contextService=r,this._editorService=s,this._init()}_init(){this._initLegacyPasteCommand()}_initLegacyPasteCommand(){var o;(o=this._docSelectionRenderService)==null||o.onPaste$.pipe(_.takeUntil(this.dispose$)).subscribe(t=>{var l,A,d;if(!mn(this._contextService))return;t.event.preventDefault();const e=t.event;let n=(l=e.clipboardData)==null?void 0:l.getData(C.HTML_CLIPBOARD_MIME_TYPE);const r=(A=e.clipboardData)==null?void 0:A.getData(C.PLAIN_TEXT_CLIPBOARD_MIME_TYPE),s=[C.FILE__BMP_CLIPBOARD_MIME_TYPE,C.FILE__JPEG_CLIPBOARD_MIME_TYPE,C.FILE__WEBP_CLIPBOARD_MIME_TYPE,C.FILE_PNG_CLIPBOARD_MIME_TYPE],a=[...((d=e.clipboardData)==null?void 0:d.items)||[]].filter(u=>s.includes(u.type)).map(u=>u.getAsFile()).filter(u=>!!u);this._editorService.getEditor(this._context.unitId)&&(n!=null?n:"").indexOf("</table>")>-1&&(n=""),this._docClipboardService.legacyPaste({html:n,text:r,files:a})})}};Zt=TA([ut(1,i.ICommandService),ut(2,st),ut(3,i.Inject(exports.DocSelectionRenderService)),ut(4,i.IContextService),ut(5,ce)],Zt);var RA=Object.defineProperty,bA=Object.getOwnPropertyDescriptor,yA=(o,t,e,n)=>{for(var r=n>1?void 0:n?bA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&RA(t,e,r),r},Rr=(o,t)=>(e,n)=>t(e,n,o);const OA=[i.DEFAULT_EMPTY_DOCUMENT_VALUE,i.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,i.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let $n=class extends i.Disposable{constructor(o,t,e){super(),this._context=o,this._contextMenuService=t,this._commandService=e,OA.includes(this._context.unitId)||(this._initPointerDown(),this._initEditChange())}_initPointerDown(){var e,n;const t=((n=(e=this._context)==null?void 0:e.mainComponent)==null?void 0:n.onPointerDown$).subscribeEvent(r=>{r.button===2&&this._contextMenuService.triggerContextMenu(r,C.ContextMenuPosition.MAIN_AREA)});this.disposeWithMe(t)}_initEditChange(){this.disposeWithMe(this._commandService.onCommandExecuted(o=>{o.id===M.RichTextEditingMutation.id&&this._contextMenuService.visible&&this._contextMenuService.hideContextMenu()}))}};$n=yA([Rr(1,C.IContextMenuService),Rr(2,i.ICommandService)],$n);var xA=Object.defineProperty,DA=Object.getOwnPropertyDescriptor,MA=(o,t,e,n)=>{for(var r=n>1?void 0:n?DA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&xA(t,e,r),r},Ge=(o,t)=>(e,n)=>t(e,n,o);let $t=class extends i.Disposable{constructor(t,e,n,r,s,a,c){super();x(this,"_initialEditors",new Set);this._context=t,this._univerInstanceService=e,this._editorService=n,this._commandService=r,this._docSelectionRenderService=s,this._docSkeletonManagerService=a,this._renderManagerService=c,this._initialize()}_initialize(){this._editorService.getAllEditor().forEach(t=>{const e=t.getEditorId();e===this._context.unitId&&(this._initialEditors.has(e)||(this._initialEditors.add(e),this._resize(e)))}),this._commandExecutedListener(),this._initialBlur(),this._initialFocus()}_resize(t){if(t==null)return;const e=this._editorService.getEditor(t);if((e==null?void 0:e.cancelDefaultResizeListener)===!0)return;const n=this._univerInstanceService.getUniverDocInstance(t);if(!n)return;const r=this._docSkeletonManagerService.getSkeleton();if(e==null||e.render==null||r==null||n==null)return;r.calculate();const{marginTop:s=0,marginBottom:a=0,marginLeft:c=0,marginRight:l=0}=n.getSnapshot().documentStyle,{scene:A,mainComponent:d}=e.render;let{actualHeight:u,actualWidth:h}=r.getActualSize();u+=s+a,h+=c+l;const{width:g,height:f}=e.getBoundingClientRect(),m=Math.max(h,g),p=Math.max(u,f);A.transformByState({width:m,height:p}),d==null||d.resize(m,p)}_initialBlur(){this.disposeWithMe(this._editorService.blur$.subscribe(()=>{this._docSelectionRenderService.blur()})),this.disposeWithMe(this._docSelectionRenderService.onBlur$.subscribe(()=>{const{unitId:t}=this._context,e=this._editorService.getEditor(t),n=this._editorService.getFocusEditor();e==null||e.isSheetEditor()||n&&n.getEditorId()===t||t.includes("range_selector")||t.includes("embedding_formula_editor")||this._editorService.blur()}))}_initialFocus(){const t=["univer-formula-search","univer-formula-help","formula-help-decorator","univer-formula-help-param"];this.disposeWithMe(_.fromEvent(window,"mousedown").subscribe(n=>{const s=n.target.classList[0]||"";i.checkForSubstrings(s,t)&&n.stopPropagation()})),this._univerInstanceService.getAllUnitsForType(i.UniverInstanceType.UNIVER_SHEET).forEach(n=>{const r=n.getUnitId(),s=this._renderManagerService.getRenderById(r),a=s==null?void 0:s.engine.getCanvas().getCanvasEle();a!=null&&_.fromEvent(a,"mousedown").subscribe(c=>{c.stopPropagation()})})}_commandExecutedListener(){const t=[M.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(t.includes(e.id)){const n=e.params,{unitId:r}=n;if(this._editorService.isSheetEditor(r)||r!==this._context.unitId)return;const s=this._editorService.getEditor(r);s&&!s.params.scrollBar&&this._resize(r)}}))}};$t=MA([Ge(1,i.IUniverInstanceService),Ge(2,ce),Ge(3,i.ICommandService),Ge(4,i.Inject(exports.DocSelectionRenderService)),Ge(5,i.Inject(M.DocSkeletonManagerService)),Ge(6,y.IRenderManagerService)],$t);var BA=Object.defineProperty,_A=Object.getOwnPropertyDescriptor,PA=(o,t,e,n)=>{for(var r=n>1?void 0:n?_A(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&BA(t,e,r),r},wt=(o,t)=>(e,n)=>t(e,n,o);let eo=class extends i.Disposable{constructor(t,e,n,r,s){super();x(this,"_previousIMEContent","");x(this,"_isCompositionStart",!0);x(this,"_onStartSubscription");x(this,"_onUpdateSubscription");x(this,"_onEndSubscription");this._context=t,this._docSelectionRenderService=e,this._docImeInputManagerService=n,this._docSkeletonManagerService=r,this._commandService=s,this._initialize()}dispose(){var t,e,n;(t=this._onStartSubscription)==null||t.unsubscribe(),(e=this._onUpdateSubscription)==null||e.unsubscribe(),(n=this._onEndSubscription)==null||n.unsubscribe()}_initialize(){this._initialOnCompositionstart(),this._initialOnCompositionUpdate(),this._initialOnCompositionend()}_initialOnCompositionstart(){this._onStartSubscription=this._docSelectionRenderService.onCompositionstart$.subscribe(t=>{if(t==null)return;this._resetIME();const{activeRange:e}=t;e!=null&&this._docImeInputManagerService.setActiveRange(i.Tools.deepClone(e))})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._docSelectionRenderService.onCompositionupdate$.subscribe(t=>{this._updateContent(t,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._docSelectionRenderService.onCompositionend$.subscribe(t=>{this._updateContent(t,!1)})}async _updateContent(t,e){if(t==null)return;const n=this._context.unitId,r=this._docSkeletonManagerService.getSkeleton(),{event:s,activeRange:a}=t;if(r==null||a==null)return;const l=s.data;l===this._previousIMEContent&&e||(await this._commandService.executeCommand(wo.id,{unitId:n,newText:l,oldTextLen:this._previousIMEContent.length,isCompositionStart:this._isCompositionStart,isCompositionEnd:!e}),e?(this._isCompositionStart&&(this._isCompositionStart=!1),this._previousIMEContent=l):this._resetIME())}_resetIME(){this._previousIMEContent="",this._isCompositionStart=!0,this._docImeInputManagerService.clearUndoRedoMutationParamsCache(),this._docImeInputManagerService.setActiveRange(null)}};eo=PA([wt(1,i.Inject(exports.DocSelectionRenderService)),wt(2,i.Inject(Mt)),wt(3,i.Inject(M.DocSkeletonManagerService)),wt(4,i.ICommandService)],eo);var NA=Object.defineProperty,UA=Object.getOwnPropertyDescriptor,wA=(o,t,e,n)=>{for(var r=n>1?void 0:n?UA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&NA(t,e,r),r},Qt=(o,t)=>(e,n)=>t(e,n,o);let to=class extends i.Disposable{constructor(t,e,n,r,s){super();x(this,"_onInputSubscription");this._context=t,this._docSelectionRenderService=e,this._docSkeletonManagerService=n,this._commandService=r,this._docMenuStyleService=s,this._init()}dispose(){var t;super.dispose(),(t=this._onInputSubscription)==null||t.unsubscribe()}_init(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._docSelectionRenderService.onInput$.subscribe(async t=>{var p,S,I;if(t==null)return;const{unitId:e}=this._context,{event:n,content:r="",activeRange:s}=t,a=n,c=this._docSkeletonManagerService.getSkeleton();if(a.data==null||c==null||s==null)return;const{segmentId:l}=s,d=this._context.unit.getSelfOrHeaderFooterModel(l).getBody(),u=this._docMenuStyleService.getDefaultStyle(),h=this._docMenuStyleService.getStyleCache(),g=so((p=d==null?void 0:d.customRanges)!=null?p:[],s.endOffset,i.SHEET_EDITOR_UNITS.includes(e)),f=tn((S=d==null?void 0:d.textRuns)!=null?S:[],s.endOffset,u,h),m=ao((I=d==null?void 0:d.customDecorations)!=null?I:[],s.endOffset);await this._commandService.executeCommand(dn.id,{unitId:e,body:{dataStream:r,textRuns:f?[{...f,st:0,ed:r.length}]:[],customRanges:g?[{...g,startIndex:0,endIndex:r.length-1}]:[],customDecorations:m.map(v=>({...v,startIndex:0,endIndex:r.length-1}))},range:s,segmentId:l}),r===" "&&await this._commandService.executeCommand(Et.id)})}};to=wA([Qt(1,i.Inject(exports.DocSelectionRenderService)),Qt(2,i.Inject(M.DocSkeletonManagerService)),Qt(3,i.ICommandService),Qt(4,i.Inject(Ce))],to);class Lo extends i.Disposable{constructor(t){super(),this._context=t}calculatePagePosition(){var R,b;const t=Se(this._context),n=(b=(R=this._context.unit.getSettings())==null?void 0:R.zoomRatio)!=null?b:1,{document:r,scene:s,docBackground:a}=t,c=s==null?void 0:s.getParent(),{width:l,height:A,pageMarginLeft:d,pageMarginTop:u}=r;if(c==null||l===Number.POSITIVE_INFINITY||A===Number.POSITIVE_INFINITY)return;const{width:h,height:g}=c;let f=0,m=u,p=0,S=0,I=Number.POSITIVE_INFINITY;h>(l+d*2)*n?(f=h/2-l*n/2,f/=n,p=(h-d*2)/n,I=0):(f=d,p=l+d*2,I=(p-h/n)/2),g>A?S=(g-u*2)/n:S=A+u*2,s.resize(p,S),h<=1&&(f=-1e4,m=-1e4),r.translate(f,m),a.translate(f,m);const v=s.getViewport(he.VIEW_MAIN);return I!==Number.POSITIVE_INFINITY&&v!=null&&v.scrollToViewportPos({viewportScrollX:I}),this}}var QA=Object.defineProperty,LA=Object.getOwnPropertyDescriptor,FA=(o,t,e,n)=>{for(var r=n>1?void 0:n?LA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&QA(t,e,r),r},br=(o,t)=>(e,n)=>t(e,n,o);let no=class extends i.Disposable{constructor(o,t,e){super(),this._context=o,this._docPageLayoutService=t,this._textSelectionManagerService=e;const n=this._context.unitId;if(i.isInternalEditorID(n)&&n!==i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)return this;this._initResize()}_initResize(){this.disposeWithMe(i.fromEventSubject(this._context.engine.onTransformChange$).pipe(_.filter(o=>o.type===y.TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize),_.throttleTime(0,_.animationFrameScheduler)).subscribe(()=>{this._docPageLayoutService.calculatePagePosition(),this._textSelectionManagerService.refreshSelection()}))}};no=FA([br(1,i.Inject(Lo)),br(2,i.Inject(M.DocSelectionManagerService))],no);var HA=Object.defineProperty,kA=Object.getOwnPropertyDescriptor,jA=(o,t,e,n)=>{for(var r=n>1?void 0:n?kA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&HA(t,e,r),r},Xe=(o,t)=>(e,n)=>t(e,n,o);let oo=class extends i.Disposable{constructor(t,e,n,r,s,a,c){super();x(this,"_loadedMap",new WeakSet);this._context=t,this._commandService=e,this._editorService=n,this._instanceSrv=r,this._docSelectionRenderService=s,this._docSkeletonManagerService=a,this._docSelectionManagerService=c,this._initialize()}_initialize(){this._init(),this._skeletonListener(),this._commandExecutedListener(),this._refreshListener(),this._syncSelection()}_init(){const{unitId:t}=this._context,e=Se(this._context);e==null||e.document==null||this._loadedMap.has(e.document)||(this._initialMain(t),this._loadedMap.add(e.document))}_refreshListener(){this.disposeWithMe(this._docSelectionManagerService.refreshSelection$.subscribe(t=>{if(t==null)return;const{unitId:e,docRanges:n,isEditing:r,options:s}=t;e===this._context.unitId&&(this._docSelectionRenderService.removeAllRanges(),this._docSelectionRenderService.addDocRanges(n,r,s))}))}_syncSelection(){this.disposeWithMe(this._docSelectionRenderService.textSelectionInner$.subscribe(t=>{t!=null&&this._docSelectionManagerService.__replaceTextRangesWithNoRefresh(t,{unitId:this._context.unitId,subUnitId:this._context.unitId})}))}_initialMain(t){const e=Se(this._context),{document:n,scene:r}=e;this.disposeWithMe(n.onPointerEnter$.subscribeEvent(()=>{this._isEditorReadOnly(t)||(n.cursor=y.CURSOR_TYPE.TEXT)})),this.disposeWithMe(n.onPointerLeave$.subscribeEvent(()=>{n.cursor=y.CURSOR_TYPE.DEFAULT,r.resetCursor()})),this.disposeWithMe(n.onPointerDown$.subscribeEvent((s,a)=>{if(this._isEditorReadOnly(t))return;const c=this._instanceSrv.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);(c==null?void 0:c.getUnitId())!==t&&this._instanceSrv.setCurrentUnitForType(t);const l=this._docSkeletonManagerService.getSkeleton(),{offsetX:A,offsetY:d}=s,u=this._getTransformCoordForDocumentOffset(A,d);if(u!=null){const{pageLayoutType:h=y.PageLayoutType.VERTICAL,pageMarginLeft:g,pageMarginTop:f}=n.getOffsetConfig(),{editArea:m}=l.findEditAreaByCoord(u,h,g,f),p=this._docSkeletonManagerService.getViewModel(),S=p.getEditArea();S!==y.DocumentEditArea.BODY&&m!==y.DocumentEditArea.BODY&&m!==S&&p.setEditArea(m)}if(this._docSelectionRenderService.__onPointDown(s),this._editorService.getEditor(t)){this._setEditorFocus(t);const{offsetX:h,offsetY:g}=s;setTimeout(()=>{t!==this._editorService.getFocusId()&&(this._setEditorFocus(t),this._docSelectionRenderService.setCursorManually(h,g))},0)}s.button!==2&&a.stopPropagation()})),this.disposeWithMe(n.onDblclick$.subscribeEvent(s=>{this._isEditorReadOnly(t)||this._docSelectionRenderService.__handleDblClick(s)})),this.disposeWithMe(n.onTripleClick$.subscribeEvent(s=>{this._isEditorReadOnly(t)||this._docSelectionRenderService.__handleTripleClick(s)}))}_getTransformCoordForDocumentOffset(t,e){const n=Se(this._context),{document:r,scene:s}=n,{documentTransform:a}=r.getOffsetConfig(),c=s.getViewports()[0];if(c==null)return;const l=c.transformVector2SceneCoord(y.Vector2.FromArray([t,e]));return a.clone().invert().applyPoint(l)}_isEditorReadOnly(t){const e=this._editorService.getEditor(t);return e?e.isReadOnly():!1}_setEditorFocus(t){this._editorService.focus(t)}_commandExecutedListener(){const t=[de.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var n;if(t.includes(e.id)){const r=e.params,{unitId:s}=r,a=(n=this._docSelectionManagerService.__getCurrentSelection())==null?void 0:n.unitId;if(s!==a)return;this._docSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe(t=>{if(!t)return;const{unitId:e}=this._context;if(!i.isInternalEditorID(e)){this._docSelectionRenderService.focus();const s=this._context.unit.getSnapshot(),a=$r(s);this._docSelectionManagerService.replaceDocRanges([{startOffset:a,endOffset:a}],{unitId:e,subUnitId:e},!1)}}))}};oo=jA([Xe(1,i.ICommandService),Xe(2,ce),Xe(3,i.IUniverInstanceService),Xe(4,i.Inject(exports.DocSelectionRenderService)),Xe(5,i.Inject(M.DocSkeletonManagerService)),Xe(6,i.Inject(M.DocSelectionManagerService))],oo);var VA=Object.defineProperty,WA=Object.getOwnPropertyDescriptor,KA=(o,t,e,n)=>{for(var r=n>1?void 0:n?WA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&VA(t,e,r),r},Be=(o,t)=>(e,n)=>t(e,n,o);let ro=class extends i.Disposable{constructor(o,t,e,n,r,s,a,c){super(),this._context=o,this._contextService=t,this._docSkeletonManagerService=e,this._univerInstanceService=n,this._commandService=r,this._textSelectionManagerService=s,this._editorService=a,this._docPageLayoutService=c,this._initSkeletonListener(),this._initCommandExecutedListener(),this._initRenderRefresher(),setTimeout(()=>this.updateViewZoom(1,!0),20)}_initRenderRefresher(){this._docSkeletonManagerService.currentSkeleton$.subscribe(o=>{if(o==null)return;const{unitId:t,scene:e}=this._context;this._editorService.isEditor(t)||this.disposeWithMe(e.onMouseWheel$.subscribeEvent(n=>{if(!n.ctrlKey||!this._contextService.getContextValue(i.FOCUSING_DOC))return;const r=this._univerInstanceService.getCurrentUniverDocInstance();if(!r)return;const{documentFlavor:s}=r.getSnapshot().documentStyle;if(s===i.DocumentFlavor.MODERN)return;const a=Math.abs(n.deltaX);let c=a<40?.2:a<80?.4:.2;c*=n.deltaY>0?-1:1,e.scaleX<1&&(c/=2);const l=r.zoomRatio;let A=+Number.parseFloat(`${l+c}`).toFixed(1);A=A>=4?4:A<=.1?.1:A,this._commandService.executeCommand(Gt.id,{zoomRatio:A,unitId:r.getUnitId()}),n.preventDefault()}))})}_initSkeletonListener(){this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe(o=>{if(o==null)return;const t=this._univerInstanceService.getCurrentUniverDocInstance();if(!t)return;const e=t.zoomRatio||1;this.updateViewZoom(e,!1)}))}_initCommandExecutedListener(){const o=[de.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(o.includes(t.id)&&t.params.unitId===this._context.unitId){const n=this._context.unit.zoomRatio||1;this.updateViewZoom(n)}})),this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{t.id===Sn.id&&this._commandService.executeCommand(Gt.id,{zoomRatio:1,unitId:this._context.unitId})}))}updateViewZoom(o,t=!0){var n;const e=Se(this._context);e.scene.scale(o,o),this._editorService.isEditor(this._context.unitId)||this._docPageLayoutService.calculatePagePosition(),t&&!this._editorService.isEditor(this._context.unitId)&&this._textSelectionManagerService.refreshSelection(),(n=e.scene.getTransformer())==null||n.clearSelectedObjects()}};ro=KA([Be(1,i.IContextService),Be(2,i.Inject(M.DocSkeletonManagerService)),Be(3,i.IUniverInstanceService),Be(4,i.ICommandService),Be(5,i.Inject(M.DocSelectionManagerService)),Be(6,ce),Be(7,i.Inject(Lo))],ro);var zA=Object.defineProperty,GA=Object.getOwnPropertyDescriptor,XA=(o,t,e,n)=>{for(var r=n>1?void 0:n?GA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&zA(t,e,r),r},gt=(o,t)=>(e,n)=>t(e,n,o);const yr=300;exports.DocStateChangeManagerService=class extends i.RxDisposable{constructor(e,n,r,s,a){super();x(this,"_docStateChange$",new _.BehaviorSubject(null));x(this,"docStateChange$",this._docStateChange$.asObservable());x(this,"_historyStateCache",new Map);x(this,"_changeStateCache",new Map);x(this,"_historyTimer",null);x(this,"_changeStateCacheTimer",null);this._undoRedoService=e,this._commandService=n,this._univerInstanceService=r,this._docStateEmitService=s,this._renderManagerService=a,this._initialize(),this._listenDocStateChange()}getStateCache(e){var n,r;return{history:(n=this._historyStateCache.get(e))!=null?n:[],collaboration:(r=this._changeStateCache.get(e))!=null?r:[]}}setStateCache(e,n){this._historyStateCache.set(e,n.history),this._changeStateCache.set(e,n.collaboration)}_setChangeState(e){this._cacheChangeState(e,"history"),this._cacheChangeState(e,"collaboration")}_initialize(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===i.UndoCommandId||e.id===i.RedoCommandId){const n=this._univerInstanceService.getCurrentUniverDocInstance();if(n==null)return;const r=n.getUnitId();this._pushHistory(r),this._emitChangeState(r)}}))}_listenDocStateChange(){this._docStateEmitService.docStateChangeParams$.pipe(_.takeUntil(this.dispose$)).subscribe(e=>{var l;if(e==null)return;const{isCompositionEnd:n,isSync:r,syncer:s,...a}=e,c=(l=this._renderManagerService.getRenderById(r?s:e.unitId))==null?void 0:l.with(Mt);if(c!=null){if(n){const A=c.fetchComposedUndoRedoMutationParams();if(A==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:d,redoMutationParams:u,previousActiveRange:h}=A;a.redoState.actions=u.actions,a.undoState.actions=d.actions,a.undoState.textRanges=[h]}this._setChangeState(a)}})}_cacheChangeState(e,n="history"){const{trigger:r,unitId:s,noHistory:a,debounce:c=!1}=e;if(a||r==null||n==="history"&&(r===i.RedoCommandId||r===i.UndoCommandId))return;const l=n==="history"?this._historyStateCache:this._changeStateCache,A=n==="history"?this._pushHistory.bind(this):this._emitChangeState.bind(this);if(l.has(s)){const d=l.get(s);d==null||d.push(e)}else l.set(s,[e]);c?n==="history"?(this._historyTimer&&clearTimeout(this._historyTimer),this._historyTimer=setTimeout(()=>{A(s)},yr)):(this._changeStateCacheTimer&&clearTimeout(this._changeStateCacheTimer),this._changeStateCacheTimer=setTimeout(()=>{A(s)},yr)):A(s)}_pushHistory(e){const n=this._undoRedoService,r=this._historyStateCache.get(e);if(!Array.isArray(r)||r.length===0)return;const s=r.length,a=r[0].commandId,c=r[0],l=r[s-1],A={unitId:e,actions:r.reduce((u,h)=>i.JSONX.compose(u,h.redoState.actions),null),textRanges:l.redoState.textRanges},d={unitId:e,actions:r.reverse().reduce((u,h)=>i.JSONX.compose(u,h.undoState.actions),null),textRanges:c.undoState.textRanges};n.pushUndoRedo({unitID:e,undoMutations:[{id:a,params:d}],redoMutations:[{id:a,params:A}]}),r.length=0}_emitChangeState(e){const n=this._changeStateCache.get(e);if(!Array.isArray(n)||n.length===0)return;const r=n.length,{commandId:s,trigger:a,segmentId:c,noHistory:l,debounce:A}=n[0],d=n[0],u=n[r-1],h={unitId:e,actions:n.reduce((m,p)=>i.JSONX.compose(m,p.redoState.actions),null),textRanges:u.redoState.textRanges},g={unitId:e,actions:n.reverse().reduce((m,p)=>i.JSONX.compose(m,p.undoState.actions),null),textRanges:d.undoState.textRanges},f={commandId:s,unitId:e,trigger:a,redoState:h,undoState:g,segmentId:c,noHistory:l,debounce:A};n.length=0,this._docStateChange$.next(f)}};exports.DocStateChangeManagerService=XA([gt(0,i.Inject(i.IUndoRedoService)),gt(1,i.ICommandService),gt(2,i.IUniverInstanceService),gt(3,i.Inject(M.DocStateEmitService)),gt(4,y.IRenderManagerService)],exports.DocStateChangeManagerService);var YA=Object.defineProperty,qA=Object.getOwnPropertyDescriptor,JA=(o,t,e,n)=>{for(var r=n>1?void 0:n?qA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&YA(t,e,r),r},Or=(o,t)=>(e,n)=>t(e,n,o);const xr="univer-doc-main-canvas";exports.DocsRenderService=class extends i.RxDisposable{constructor(t,e){super(),this._instanceSrv=t,this._renderManagerService=e,this._init()}_init(){this._renderManagerService.createRender$.pipe(_.takeUntil(this.dispose$)).subscribe(t=>this._createRenderWithId(t)),this._instanceSrv.getAllUnitsForType(i.UniverInstanceType.UNIVER_DOC).forEach(t=>this._createRenderer(t)),this._instanceSrv.getTypeOfUnitAdded$(i.UniverInstanceType.UNIVER_DOC).pipe(_.takeUntil(this.dispose$)).subscribe(t=>this._createRenderer(t)),this._instanceSrv.getTypeOfUnitDisposed$(i.UniverInstanceType.UNIVER_DOC).pipe(_.takeUntil(this.dispose$)).subscribe(t=>this._disposeRenderer(t))}_createRenderer(t){var r;const e=t.getUnitId(),n=(r=this._instanceSrv.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC))==null?void 0:r.getUnitId();this._renderManagerService.created$.subscribe(s=>{s.unitId===n&&(s.engine.getCanvas().setId(xr),s.engine.getCanvas().getContext().setId(xr))}),this._renderManagerService.has(e)||(this._createRenderWithId(e),this._renderManagerService.setCurrent(e))}_createRenderWithId(t){this._renderManagerService.createRender(t)}_disposeRenderer(t){const e=t.getUnitId();this._renderManagerService.removeRender(e)}};exports.DocsRenderService=JA([Or(0,i.IUniverInstanceService),Or(1,y.IRenderManagerService)],exports.DocsRenderService);class Mi extends i.Disposable{constructor(){super(...arguments);x(this,"_currentSelectorId");x(this,"_selectionChange$",new _.Subject);x(this,"selectionChange$",this._selectionChange$.asObservable());x(this,"_openSelector$",new _.Subject);x(this,"openSelector$",this._openSelector$.asObservable());x(this,"_selectorModalVisible$",new _.BehaviorSubject(!1));x(this,"selectorModalVisible$",this._selectorModalVisible$.asObservable())}get selectorModalVisible(){return this._selectorModalVisible$.getValue()}setCurrentSelectorId(e){this._currentSelectorId=e}getCurrentSelectorId(){return this._currentSelectorId}selectionChange(e){this._currentSelectorId&&this._selectionChange$.next(e)}openSelector(){this._openSelector$.next(null)}triggerModalVisibleChange(e){this._selectorModalVisible$.next(e)}}const Bi=i.createIdentifier("univer.range-selector.service"),ZA={id:Je.id,preconditions:ra,binding:C.KeyCode.ENTER},$A={id:Dt.id,preconditions:Z,binding:C.KeyCode.BACKSPACE},ed={id:Ro.id,preconditions:Z,binding:C.KeyCode.DELETE},td={id:Ee.id,binding:C.KeyCode.ARROW_UP,preconditions:Z,staticParameters:{direction:i.Direction.UP}},nd={id:Ee.id,binding:C.KeyCode.ARROW_DOWN,preconditions:Z,staticParameters:{direction:i.Direction.DOWN}},od={id:Ee.id,binding:C.KeyCode.ARROW_LEFT,preconditions:Z,staticParameters:{direction:i.Direction.LEFT}},rd={id:Ee.id,binding:C.KeyCode.ARROW_RIGHT,preconditions:Z,staticParameters:{direction:i.Direction.RIGHT}},id={id:ve.id,binding:C.KeyCode.ARROW_UP|C.MetaKeys.SHIFT,preconditions:Z,staticParameters:{direction:i.Direction.UP}},sd={id:ve.id,binding:C.KeyCode.ARROW_DOWN|C.MetaKeys.SHIFT,preconditions:Z,staticParameters:{direction:i.Direction.DOWN}},ad={id:ve.id,binding:C.KeyCode.ARROW_LEFT|C.MetaKeys.SHIFT,preconditions:Z,staticParameters:{direction:i.Direction.LEFT}},cd={id:ve.id,binding:C.KeyCode.ARROW_RIGHT|C.MetaKeys.SHIFT,preconditions:Z,staticParameters:{direction:i.Direction.RIGHT}},ld={id:Uo.id,binding:C.KeyCode.A|C.MetaKeys.CTRL_COMMAND,preconditions:o=>o.getContextValue(i.FOCUSING_UNIVER_EDITOR)&&(o.getContextValue(i.FOCUSING_DOC)||o.getContextValue(i.EDITOR_ACTIVATED))};var _i=Object.defineProperty,Ad=Object.getOwnPropertyDescriptor,dd=(o,t,e)=>t in o?_i(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,ud=(o,t,e,n)=>{for(var r=n>1?void 0:n?Ad(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&_i(t,e,r),r},ht=(o,t)=>(e,n)=>t(e,n,o),gd=(o,t,e)=>dd(o,t+"",e);exports.UniverDocsUIPlugin=class extends i.Plugin{constructor(t=lr,e,n,r,s,a){super(),this._config=t,this._injector=e,this._renderManagerSrv=n,this._commandService=r,this._logService=s,this._configService=a;const{menu:c,...l}=i.merge({},lr,this._config);c&&this._configService.setConfig("menu",c,{merge:!0}),this._configService.setConfig(Io,l),this._initDependencies(e),this._initializeShortcut(),this._initCommand()}onReady(){this._initRenderBasics(),this._markDocAsFocused(),i.touchDependencies(this._injector,[[exports.DocStateChangeManagerService],[exports.DocsRenderService]])}onRendered(){this._initUI(),this._initRenderModules(),i.touchDependencies(this._injector,[[Yt],[qt],[et],[Jt],[exports.DocUIController]])}_initCommand(){[Dt,Ro,Fe,He,ke,je,ye,Ve,Ne,Ue,we,ot,Qe,Te,Bo,dn,Ze,un,To,gn,de,Tt,Ct,rt,Rt,bt,yt,me,Ot,_o,Do,vn,Cn,Ei,Tn,Rn,In,En,at,fo,Qo,Pe,Et,Je,zt,vt,on,rn,So,wo,Sn,fe,Co,Le,Fr,co,Hr,Gt,Uo,Po,Ee,ve,jr].forEach(t=>{this._commandService.registerCommand(t)}),[St,fn,pn].forEach(t=>this.disposeWithMe(this._commandService.registerMultipleCommand(t)))}_initializeShortcut(){[td,nd,rd,od,id,sd,ad,cd,ld,$A,ed,ZA,sa].forEach(t=>{this._injector.get(C.IShortcutService).registerShortcut(t)})}_initDependencies(t){i.mergeOverrideWithDependencies([[Zt],[$t],[exports.DocUIController],[Yt],[Jt],[qt],[Xt],[et],[ce,{useClass:exports.EditorService}],[Bi,{useClass:Mi}],[st,{useClass:Yn}],[exports.DocCanvasPopManagerService],[exports.DocsRenderService],[exports.DocStateChangeManagerService],[exports.DocAutoFormatService],[Ce]],this._config.override).forEach(n=>t.add(n))}_markDocAsFocused(){const t=this._injector.get(i.IUniverInstanceService),e=this._injector.get(ce);try{const n=t.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);if(!n)return;const r=n.getUnitId();e.isEditor(r)||t.focusUnit(n.getUnitId())}catch(n){this._logService.warn(n)}}_initUI(){this._injector.get(Xt)}_initRenderBasics(){[[M.DocSkeletonManagerService],[exports.DocSelectionRenderService],[M.DocInterceptorService],[Lo],[Mt],[exports.DocRenderController],[ro]].forEach(t=>{this._renderManagerSrv.registerRenderModule(i.UniverInstanceType.UNIVER_DOC,t)})}_initRenderModules(){[[exports.DocEventManagerService],[exports.DocBackScrollRenderController],[oo],[zn],[no],[$n],[Zn],[Zt],[to],[eo],[$t]].forEach(t=>{this._renderManagerSrv.registerRenderModule(i.UniverInstanceType.UNIVER_DOC,t)})}};gd(exports.UniverDocsUIPlugin,"pluginName",Br);exports.UniverDocsUIPlugin=ud([i.DependentOn(y.UniverRenderEnginePlugin),ht(1,i.Inject(i.Injector)),ht(2,y.IRenderManagerService),ht(3,i.ICommandService),ht(4,i.ILogService),ht(5,i.IConfigService)],exports.UniverDocsUIPlugin);exports.AfterSpaceCommand=Et;exports.AlignCenterCommand=bt;exports.AlignJustifyCommand=Ot;exports.AlignLeftCommand=Rt;exports.AlignOperationCommand=me;exports.AlignRightCommand=yt;exports.BreakLineCommand=Bo;exports.BulletListCommand=Ct;exports.ChangeListNestingLevelCommand=zt;exports.ChangeListNestingLevelType=pt;exports.ChangeListTypeCommand=vt;exports.CheckListCommand=on;exports.CoverContentCommand=Hr;exports.CreateDocTableCommand=_o;exports.CutContentCommand=Le;exports.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX=_r;exports.DOCS_COMPONENT_DEFAULT_Z_INDEX=Hn;exports.DOCS_COMPONENT_HEADER_LAYER_INDEX=Pr;exports.DOCS_COMPONENT_MAIN_LAYER_INDEX=Lt;exports.DOCS_VIEW_KEY=Ae;exports.DOC_UI_PLUGIN_NAME=Br;exports.DOC_VERTICAL_PADDING=Jn;exports.DefaultDocContainerConfig=Mr;exports.DefaultToolbarConfig=Dr;exports.DeleteCommand=Ze;exports.DeleteCustomBlockCommand=un;exports.DeleteLeftCommand=Dt;exports.DeleteRightCommand=Ro;exports.DocCopyCommand=St;exports.DocCreateTableOperation=bn;exports.DocCutCommand=fn;exports.DocIMEInputManagerService=Mt;exports.DocPasteCommand=pn;exports.DocSelectAllCommand=Uo;exports.DocTableDeleteColumnsCommand=En;exports.DocTableDeleteRowsCommand=In;exports.DocTableDeleteTableCommand=at;exports.DocTableInsertColumnCommand=Ei;exports.DocTableInsertColumnLeftCommand=Tn;exports.DocTableInsertColumnRightCommand=Rn;exports.DocTableInsertRowAboveCommand=vn;exports.DocTableInsertRowBellowCommand=Cn;exports.DocTableInsertRowCommand=Do;exports.DocTableTabCommand=Qo;exports.DocsUIMenuSchema=bi;exports.Editor=zr;exports.EditorInsertTextCommandId=hi;exports.EnterCommand=Je;exports.IDocClipboardService=st;exports.IEditorService=ce;exports.IMEInputCommand=wo;exports.IRangeSelectorService=Bi;exports.InnerPasteCommand=Co;exports.InsertCommand=dn;exports.ListOperationCommand=rt;exports.MergeTwoParagraphCommand=gn;exports.MoveCursorOperation=Ee;exports.MoveSelectionOperation=ve;exports.NORMAL_TEXT_SELECTION_PLUGIN_NAME=Wi;exports.NodePositionConvertToCursor=Ie;exports.NodePositionConvertToRectRange=uo;exports.OrderListCommand=Tt;exports.PastePluginLark=fi;exports.PastePluginUniver=Si;exports.PastePluginWord=Ii;exports.QuickListCommand=So;exports.RangeSelectorService=Mi;exports.RectRange=go;exports.ReplaceContentCommand=Fr;exports.ReplaceSnapshotCommand=co;exports.ReplaceTextRunsCommand=jr;exports.ResetInlineFormatTextBackgroundColorCommand=ot;exports.RichTextEditor=bs;exports.SetDocZoomRatioCommand=Gt;exports.SetDocZoomRatioOperation=de;exports.SetInlineFormatBoldCommand=Fe;exports.SetInlineFormatCommand=Te;exports.SetInlineFormatFontFamilyCommand=Ue;exports.SetInlineFormatFontSizeCommand=Ne;exports.SetInlineFormatItalicCommand=He;exports.SetInlineFormatStrikethroughCommand=je;exports.SetInlineFormatSubscriptCommand=ye;exports.SetInlineFormatSuperscriptCommand=Ve;exports.SetInlineFormatTextBackgroundColorCommand=Qe;exports.SetInlineFormatTextColorCommand=we;exports.SetInlineFormatUnderlineCommand=ke;exports.TEXT_RANGE_LAYER_INDEX=Wt;exports.TabCommand=Pe;exports.TextRange=_e;exports.ToggleCheckListCommand=rn;exports.UpdateCommand=To;exports.VIEWPORT_KEY=he;exports.addCustomDecorationBySelectionFactory=zi;exports.addCustomDecorationFactory=Ur;exports.calcDocRangePositions=jt;exports.convertPositionsToRectRanges=Ht;exports.deleteCustomDecorationFactory=Gi;exports.docDrawingPositionToTransform=Yi;exports.genTableSource=vo;exports.generateParagraphs=Mo;exports.getAnchorBounding=ft;exports.getCanvasOffsetByEngine=Kr;exports.getCommandSkeleton=le;exports.getCursorWhenDelete=hn;exports.getCustomBlockIdsInSelections=ui;exports.getCutActionsFromDocRanges=gi;exports.getDocObject=Nr;exports.getDocObjectById=Ki;exports.getEmptyTableCell=cn;exports.getEmptyTableRow=ln;exports.getLineBounding=nn;exports.getOneTextSelectionRange=jn;exports.getParagraphsInRange=sn;exports.getParagraphsInRanges=it;exports.getRichTextEditPath=q;exports.getTableColumn=An;exports.hasParagraphInTable=Xi;exports.isInSameTableCell=Ao;exports.isValidRectRange=Vr;exports.neoGetDocObject=Se;exports.transformToDocDrawingPosition=qi;exports.useKeyboardEvent=wr;exports.useResize=Qr;exports.whenDocAndEditorFocused=Z;
|