@univerjs/docs-ui 0.6.3 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -36,4 +36,5 @@ ${i.DataStreamTreeTokenType.TABLE_CELL_END}`;break}}}_processBeforeLink(t,e){ret
36
36
  `,children:t.map(v=>Q.jsx(te.Tooltip,{title:v.label,placement:"bottom",children:Q.jsx("span",{className:te.clsx(Y.paragraphSettingIconListItem,{[Y.paragraphSettingIconListActive]:n===v.value}),onClick:()=>r(v.value),children:v.icon})},v.value))}),Q.jsx("div",{className:Y.paragraphSettingTitle,children:o.t("doc.paragraphSetting.indentation")}),Q.jsxs("div",{children:[Q.jsxs("div",{className:Y.paragraphSettingFlexCol,children:[Q.jsxs("div",{className:Y.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.left"),"(px)"]}),Q.jsx(De,{className:Y.paragraphSettingMtBase,value:s,onChange:v=>a(v!=null?v:0)})]}),Q.jsxs("div",{className:Y.paragraphSettingFlexCol,children:[Q.jsxs("div",{className:Y.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.right"),"(px)"]}),Q.jsx(De,{className:Y.paragraphSettingMtBase,value:c,onChange:v=>l(v!=null?v:0)})]}),Q.jsxs("div",{className:Y.paragraphSettingFlexCol,children:[Q.jsxs("div",{className:Y.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.firstLine"),"(px)"]}),Q.jsx(De,{className:Y.paragraphSettingMtBase,value:A,onChange:v=>d(v!=null?v:0)})]}),Q.jsxs("div",{className:Y.paragraphSettingFlexCol,children:[Q.jsxs("div",{className:Y.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.hanging"),"(px)"]}),Q.jsx(De,{className:Y.paragraphSettingMtBase,value:u,onChange:v=>h(v!=null?v:0)})]})]}),Q.jsx("div",{className:Y.paragraphSettingTitle,children:o.t("doc.paragraphSetting.spacing")}),Q.jsxs("div",{children:[Q.jsxs("div",{className:Y.paragraphSettingFlexCol,children:[Q.jsxs("div",{className:Y.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.before"),"(px)"]}),Q.jsx(De,{className:Y.paragraphSettingMtBase,value:g,onChange:v=>m(v!=null?v:0)})]}),Q.jsxs("div",{className:Y.paragraphSettingFlexCol,children:[Q.jsxs("div",{className:Y.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.after"),"(px)"]}),Q.jsx(De,{className:Y.paragraphSettingMtBase,value:p,onChange:v=>f(v!=null?v:0)})]}),Q.jsxs("div",{className:Y.paragraphSettingFlexCol,children:[Q.jsx("div",{className:Y.paragraphSettingLabel,children:o.t("doc.paragraphSetting.lineSpace")}),Q.jsxs("div",{className:`
37
37
  ${Y.paragraphSettingMtBase}
38
38
  ${Y.paragraphSettingSpaceLine}
39
- `,style:{width:162},children:[Q.jsx(te.Select,{value:`${C}`,options:[{label:o.t("doc.paragraphSetting.multiSpace"),value:`${i.SpacingRule.AUTO}`},{label:o.t("doc.paragraphSetting.fixedValue"),value:`${i.SpacingRule.AT_LEAST}`}],onChange:v=>T(Number(v))}),Q.jsx(De,{...b,value:S,onChange:v=>I(v!=null?v:0)})]})]})]})]})}const mc=(o,t)=>t.length===o.length&&o.some(e=>t.some(n=>n.startOffset===e.startOffset&&n.endOffset===e.endOffset));function pc(){const o=E.useDependency(i.ICommandService),t=E.useDependency(i.LocaleService),e=E.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(B.SetTextSelectionsOperation.id===l.id){const A=l.params.ranges;mc(A,a.current)||r(i.generateRandomId(4)),a.current=A}B.RichTextEditingMutation.id===l.id&&l.params.trigger!==pe.id&&s()});return()=>c.dispose()},[s]),L.useEffect(()=>{r(i.generateRandomId(4))},[e]),L.useEffect(()=>()=>s.cancel(),[s]),Q.jsx(hc,{},n)}var fc=Object.getOwnPropertyDescriptor,Sc=(o,t,e,n)=>{for(var r=n>1?void 0:n?fc(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Pn=(o,t)=>(e,n)=>t(e,n,o);const dr="doc_ui_paragraph-setting-panel";let et=class extends i.Disposable{constructor(t,e,n){super();D(this,"_id");this._commandService=t,this._componentManager=e,this._sidebarService=n,this._init()}_init(){this.disposeWithMe(this._componentManager.register(dr,pc))}openPanel(){const t={header:{title:"doc.slider.paragraphSetting"},id:this._id,children:{label:dr},width:300};this._sidebarService.open(t)}closePanel(){this._sidebarService.close(this._id)}};et=Sc([Pn(0,i.ICommandService),Pn(1,i.Inject(E.ComponentManager)),Pn(2,i.Inject(E.ISidebarService))],et);const Mo={id:"sidebar.operation.doc-paragraph-setting-panel",type:i.CommandType.OPERATION,handler:o=>(o.get(et).openPanel(),!0)},_o=o=>{const t=o.get(B.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 Ic(o){if(o.length<2)return!0;const t=o.map(e=>e.tableId);return t.every(e=>e===t[0])}function ur(o,t,e){var s;const n=t.getRectRanges(),r=t.getActiveTextRange();if(n&&n.length&&Ic(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(B.DocSelectionManagerService),e=o.get(i.IUniverInstanceService);return new _.Observable(n=>{const r=t.textSelection$.subscribe(()=>{ur(n,t,e)});return ur(n,t,e),()=>r.unsubscribe()})},Ec=o=>({id:pt.name,commandId:pt.id,type:E.MenuItemType.BUTTON,icon:"Copy",title:"rightClick.copy",disabled$:_o(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}),vc=o=>({id:Mo.id,type:E.MenuItemType.BUTTON,icon:"MenuSingle24",title:"doc.menu.paragraphSetting",hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}),Cc=o=>({id:gn.id,type:E.MenuItemType.BUTTON,icon:"Copy",title:"rightClick.cut",disabled$:_o(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}),Tc=o=>({id:hn.id,type:E.MenuItemType.BUTTON,icon:"PasteSpecial",title:"rightClick.paste",hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}),Rc=o=>({id:Ot.id,type:E.MenuItemType.BUTTON,icon:"PasteSpecial",title:"rightClick.delete",disabled$:_o(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}),ps="doc.menu.table-insert";function yc(o){return{id:ps,type:E.MenuItemType.SUBITEMS,title:"table.insert",icon:"Insert",hidden$:_.combineLatest(E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),Re(o),(t,e)=>t||e)}}function bc(o){return{id:Sn.id,type:E.MenuItemType.BUTTON,title:"table.insertRowAbove",icon:"InsertRowAbove",disabled$:Re(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Oc(o){return{id:In.id,type:E.MenuItemType.BUTTON,title:"table.insertRowBelow",icon:"InsertRowBelow",disabled$:Re(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function xc(o){return{id:En.id,type:E.MenuItemType.BUTTON,title:"table.insertColumnLeft",icon:"LeftInsertColumn",disabled$:Re(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Dc(o){return{id:vn.id,type:E.MenuItemType.BUTTON,title:"table.insertColumnRight",icon:"RightInsertColumn",disabled$:Re(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}const fs="doc.menu.table-delete";function Bc(o){return{id:fs,type:E.MenuItemType.SUBITEMS,title:"table.delete",icon:"Reduce",hidden$:_.combineLatest(E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),Re(o),(t,e)=>t||e)}}function Mc(o){return{id:pn.id,type:E.MenuItemType.BUTTON,title:"table.deleteRows",icon:"DeleteRow",disabled$:Re(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function _c(o){return{id:fn.id,type:E.MenuItemType.BUTTON,title:"table.deleteColumns",icon:"DeleteColumn",disabled$:Re(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Nc(o){return{id:at.id,type:E.MenuItemType.BUTTON,title:"table.deleteTable",icon:"GridSingle",disabled$:Re(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Pc(o){const t=o.get(i.IUniverInstanceService),e=o.get(x.IRenderManagerService);return new _.Observable(n=>{const r=t.focused$.subscribe(s=>{if(s==null||t.getUnitType(s)!==i.UniverInstanceType.UNIVER_DOC)return n.next(!0);const c=e.getRenderById(s);if(c==null)return n.next(!0);c.with(B.DocSkeletonManagerService).getViewModel().editAreaChange$.subscribe(A=>{n.next(A===x.DocumentEditArea.HEADER||A===x.DocumentEditArea.FOOTER)})});return()=>r.unsubscribe()})}function Uc(o){const t=o.get(i.IUniverInstanceService),e=o.get(i.ICommandService);return new _.Observable(n=>{const r=e.onCommandExecuted(l=>{if(l.id===B.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 wc(o){const t=o.get(B.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=ce(o,u.getUnitId());if(h==null){n.next(!0);return}if(h.getViewModel().getCustomRangeRaw(d)){n.next(!0);return}if(A!=null){const{path:p}=A;if(p.indexOf("cells")!==-1){n.next(!0);return}}n.next(!1)});return()=>r.unsubscribe()})}function ee(o){const t=o.get(B.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 Qc(o){const t=o.get(i.ICommandService);return{id:Fe.id,type:E.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===B.SetTextSelectionsOperation.id||s===Te.id){const c=xe(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Lc(o){const t=o.get(i.ICommandService);return{id:ke.id,type:E.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===B.SetTextSelectionsOperation.id||s===Te.id){const c=xe(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Fc(o){const t=o.get(i.ICommandService);return{id:He.id,type:E.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===B.SetTextSelectionsOperation.id||s===Te.id){const c=xe(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function kc(o){const t=o.get(i.ICommandService);return{id:Ve.id,type:E.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===B.SetTextSelectionsOperation.id||s===Te.id){const c=xe(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Hc(o){const t=o.get(i.ICommandService);return{id:Oe.id,type:E.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===Te.id){const c=xe(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Vc(o){const t=o.get(i.ICommandService);return{id:je.id,type:E.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===Te.id){const c=xe(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function jc(o){const t=o.get(i.ICommandService);return{id:Ue.id,tooltip:"toolbar.font",type:E.MenuItemType.SELECTOR,label:qr,selections:E.FONT_FAMILY_LIST.map(e=>({label:{name:Jr},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===B.SetTextSelectionsOperation.id||a===Ue.id){const l=xe(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Wc(o){const t=o.get(i.ICommandService);return{id:Pe.id,type:E.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Zr,props:{min:1,max:400}},selections:E.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===B.SetTextSelectionsOperation.id||a===Pe.id){const l=xe(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Kc(o){const t=o.get(i.ICommandService),e=o.get(i.ThemeService);return{id:we.id,icon:"FontColor",tooltip:"toolbar.textColor.main",type:E.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:mo,hoverable:!1,selectable:!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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function zc(o){return{id:go.id,type:E.MenuItemType.BUTTON,icon:"HeaderFooterSingle",tooltip:"toolbar.headerFooter",hidden$:_.combineLatest(E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY),Uc(o),(t,e)=>t||e)}}const Gc="GridSingle",Ss="doc.menu.table";function Xc(o){return{id:Ss,type:E.MenuItemType.SUBITEMS,icon:Gc,tooltip:"toolbar.table.main",disabled$:wc(o),hidden$:_.combineLatest(E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY),Pc(o),(t,e)=>t||e)}}function Yc(o){return{id:Cn.id,title:"toolbar.table.insert",type:E.MenuItemType.BUTTON,hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function qc(o){const t=o.get(i.ICommandService);return{id:Ct.id,type:E.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===B.SetTextSelectionsOperation.id||s===me.id){const c=Tn(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Jc(o){const t=o.get(i.ICommandService);return{id:Tt.id,type:E.MenuItemType.BUTTON,icon:"HorizontallySingle",tooltip:"toolbar.alignCenter",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===me.id){const c=Tn(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Zc(o){const t=o.get(i.ICommandService);return{id:Rt.id,type:E.MenuItemType.BUTTON,icon:"RightJustifyingSingle",tooltip:"toolbar.alignRight",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===me.id){const c=Tn(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function $c(o){const t=o.get(i.ICommandService);return{id:yt.id,type:E.MenuItemType.BUTTON,icon:"AlignTextBothSingle",tooltip:"toolbar.alignJustify",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===me.id){const c=Tn(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}const ft=o=>new _.Observable(t=>{const e=o.get(i.IUniverInstanceService),n=o.get(B.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),m=nn(A,(h=(u=g.getBody())==null?void 0:u.paragraphs)!=null?h:[]);let p;if(m.every(f=>{var S;return p||(p=(S=f.bullet)==null?void 0:S.listType),f.bullet&&f.bullet.listType===p})){t.next(p);return}}t.next(void 0)}))});return()=>{s.unsubscribe(),r==null||r.unsubscribe()}});function el(o){return{id:vt.id,type:E.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:es,hoverable:!1,selectable:!1},value$:ft(o)}],icon:"OrderSingle",tooltip:"toolbar.order",hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),disabled$:ee(o),activated$:ft(o).pipe(_.map(t=>t&&t.indexOf("ORDER_LIST")===0))}}function tl(o){return{id:Et.id,type:E.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:ts,hoverable:!1,selectable:!1},value$:ft(o)}],icon:"UnorderSingle",tooltip:"toolbar.unorder",disabled$:ee(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),activated$:ft(o).pipe(_.map(t=>t&&t.indexOf("BULLET_LIST")===0))}}function nl(o){return{id:en.id,type:E.MenuItemType.BUTTON,icon:"TodoList",tooltip:"toolbar.checklist",disabled$:ee(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),activated$:ft(o).pipe(_.map(t=>t&&t.indexOf("CHECK_LIST")===0))}}function ol(o){const t=o.get(i.ICommandService),e=o.get(i.IUniverInstanceService);return{id:mn.id,type:E.MenuItemType.BUTTON,icon:"KeyboardSingle",tooltip:"toolbar.documentFlavor",hidden$:E.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===B.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 rl(o){return{id:ot.id,type:E.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor"}}function sl(o){const t=o.get(i.ICommandService),e=o.get(i.ThemeService);return{id:Qe.id,tooltip:"toolbar.fillColor.main",type:E.MenuItemType.BUTTON_SELECTOR,icon:"PaintBucket",selections:[{label:{name:mo,hoverable:!1,selectable:!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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function xe(o){var h,g;const t=o.get(i.IUniverInstanceService),e=o.get(B.DocSelectionManagerService),n=o.get(Ce),r=t.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),s=e.getDocRanges(),a=(h=s.find(m=>m.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:{...os(d,a,c),...l}}}function Tn(o){var d,u;const t=o.get(i.IUniverInstanceService),e=o.get(B.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 Is={[E.RibbonStartGroup.FORMAT]:{[Fe.id]:{order:0,menuItemFactory:Qc},[ke.id]:{order:1,menuItemFactory:Lc},[He.id]:{order:2,menuItemFactory:Fc},[Ve.id]:{order:3,menuItemFactory:kc},[Oe.id]:{order:4,menuItemFactory:Hc},[je.id]:{order:5,menuItemFactory:Vc},[Pe.id]:{order:6,menuItemFactory:Wc},[Ue.id]:{order:7,menuItemFactory:jc},[we.id]:{order:8,menuItemFactory:Kc},[Qe.id]:{order:9,menuItemFactory:sl,[ot.id]:{order:0,menuItemFactory:rl}}},[E.RibbonStartGroup.LAYOUT]:{[Ss]:{order:1,menuItemFactory:Xc,[Cn.id]:{order:0,menuItemFactory:Yc}},[Ct.id]:{order:2,menuItemFactory:qc},[Tt.id]:{order:3,menuItemFactory:Jc},[Rt.id]:{order:4,menuItemFactory:Zc},[yt.id]:{order:5,menuItemFactory:$c},[vt.id]:{order:6,menuItemFactory:el},[Et.id]:{order:7,menuItemFactory:tl},[en.id]:{order:8,menuItemFactory:nl},[go.id]:{order:9,menuItemFactory:zc},[mn.id]:{order:10,menuItemFactory:ol}},[E.ContextMenuPosition.MAIN_AREA]:{[E.ContextMenuGroup.FORMAT]:{[pt.name]:{order:0,menuItemFactory:Ec},[gn.id]:{order:1,menuItemFactory:Cc},[hn.id]:{order:2,menuItemFactory:Tc},[Ot.id]:{order:3,menuItemFactory:Rc}},[E.ContextMenuGroup.LAYOUT]:{[Mo.id]:{order:0,menuItemFactory:vc},[ps]:{order:1,menuItemFactory:yc,[Sn.id]:{order:1,menuItemFactory:bc},[In.id]:{order:2,menuItemFactory:Oc},[En.id]:{order:3,menuItemFactory:xc},[vn.id]:{order:4,menuItemFactory:Dc}},[fs]:{order:2,menuItemFactory:Bc,[pn.id]:{order:1,menuItemFactory:Mc},[fn.id]:{order:2,menuItemFactory:_c},[at.id]:{order:3,menuItemFactory:Nc}}}}};var il=Object.getOwnPropertyDescriptor,al=(o,t,e,n)=>{for(var r=n>1?void 0:n?il(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},fe=(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(mo,te.ColorPicker)),this.disposeWithMe(t.register(qr,E.FontFamily)),this.disposeWithMe(t.register(Jr,E.FontFamilyItem)),this.disposeWithMe(t.register(Zr,E.FontSize)),this.disposeWithMe(t.register(ts,Fi)),this.disposeWithMe(t.register(es,Qi)),this.disposeWithMe(t.register("TodoList",Gr))}_initUiParts(){var e,n;const t=this._configService.getConfig(fo);(n=(e=t==null?void 0:t.layout)==null?void 0:e.docContainerConfig)!=null&&n.footer&&this.disposeWithMe(this._uiPartsService.registerComponent(E.BuiltInUIPart.FOOTER,()=>E.connectInjector(Ia,this._injector)))}_initMenus(){this._menuManagerService.mergeMenu(Is)}_initShortCut(){[Zi,$i,ea,ta,na,oa,ia,aa,sa,ra,ca,la,ji].forEach(t=>{this.disposeWithMe(this._shortcutService.registerShortcut(t))})}_init(){this._initCustomComponents(),this._initMenus(),this._initFocusHandler(),this._initCommands(),this._initUiParts(),this._initShortCut()}_initCommands(){[Yr,go,uo].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(i.UniverInstanceType.UNIVER_DOC,t=>{this._injector.get(x.IRenderManagerService).getRenderById(t).with(exports.DocSelectionRenderService).focus()}))}};exports.DocUIController=al([fe(0,i.Inject(i.Injector)),fe(1,i.Inject(E.ComponentManager)),fe(2,i.ICommandService),fe(3,E.ILayoutService),fe(4,E.IMenuManagerService),fe(5,E.IUIPartsService),fe(6,i.IUniverInstanceService),fe(7,E.IShortcutService),fe(8,i.IConfigService)],exports.DocUIController);var cl=Object.getOwnPropertyDescriptor,ll=(o,t,e,n)=>{for(var r=n>1?void 0:n?cl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Un=(o,t)=>(e,n)=>t(e,n,o);const gr=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}=ht(d),m=u+c,p=h+l,f=n.getViewport(he.VIEW_MAIN),S=this._editorService.getEditor(e);if(f==null)return;const{left:I,top:C,right:T,bottom:b}=f.getBounding().viewBound;let v=0,R=0;const y=S?(U=S.params.backScrollOffset)!=null?U:0:100;p<C?v=p-C-y:p>b-g&&(v=p-b+g+y),m<I?R=m-I:m>T-gr&&(R=m-T+gr);const M=f.transViewportScroll2ScrollValue(R,v);f.scrollByBarDeltaValue(M)}_scrollToSelection(){const t=this._textSelectionManagerService.getActiveTextRange();if(t==null)return;const{collapsed:e,startNodePosition:n}=t;e&&this.scrollToNode(n)}};exports.DocBackScrollRenderController=ll([Un(1,i.Inject(B.DocSelectionManagerService)),Un(2,ae),Un(3,i.Inject(B.DocSkeletonManagerService))],exports.DocBackScrollRenderController);var Al=Object.getOwnPropertyDescriptor,dl=(o,t,e,n)=>{for(var r=n>1?void 0:n?Al(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return 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(B.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 x.Viewport(he.VIEW_MAIN,t,{left:0,top:0,bottom:0,right:0,isWheelPreventDefaultX:!0});t.attachControl(),t.onMouseWheel$.subscribeEvent((s,a)=>{const c=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);if((c==null?void 0:c.getUnitId())!==this._context.unitId)return;const l=s;if(l.ctrlKey){const A=Math.abs(l.deltaX);let d=A<40?.2:A<80?.4:.2;d*=l.deltaY>0?-1:1,t.scaleX<1&&(d/=2),t.scaleX+d>4?t.scale(4,4):t.scaleX+d<.1?t.scale(.1,.1):l.preventDefault()}else n.onMouseWheel(l,a)}),new x.ScrollBar(n),t.addLayer(new x.Layer(t,[],wt),new x.Layer(t,[],Dr)),this._addComponent();const r=()=>t.render();this.disposeWithMe(this._context.activated$.subscribe(s=>{s?e.runRenderLoop(r):e.stopRenderLoop(r)})),this._docSelectionRenderService.__attachScrollEvent()}_addComponent(){const{scene:t,unit:e,components:n}=this._context,a={pageMarginLeft:20,pageMarginTop:20},c=new x.Documents(le.MAIN,void 0,a);c.zIndex=Qn;const l=new x.DocBackground(le.BACKGROUND,void 0,a);l.zIndex=Qn,this._context.mainComponent=c,n.set(le.MAIN,c),n.set(le.BACKGROUND,l),t.addObjects([c],wt),t.addObjects([l],xr),this._editorService.getEditor(e.getUnitId())==null&&t.enableLayerCache(wt)}_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(le.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=[B.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 m;const{mainComponent:e,scene:n,unitId:r,components:s}=this._context,a=e,c=s.get(le.BACKGROUND),l=(m=t.getSkeletonData())==null?void 0:m.pages;if(l==null)return;let A=0,d=0;const h=this._context.unit.getSnapshot().documentStyle.documentFlavor;for(let p=0,f=l.length;p<f;p++){const S=l[p];let{pageWidth:I,pageHeight:C}=S;if(h===i.DocumentFlavor.MODERN){const T=ul(S);I=T.pageWidth,C=T.pageHeight}a.pageLayoutType===x.PageLayoutType.VERTICAL?(d+=C,d+=a.pageMarginTop,p===f-1&&(d+=a.pageMarginTop),A=Math.max(A,I)):a.pageLayoutType===x.PageLayoutType.HORIZONTAL&&(A+=I,p!==f-1&&(A+=a.pageMarginLeft),d=Math.max(d,C))}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=dl([ze(1,i.ICommandService),ze(2,i.Inject(exports.DocSelectionRenderService)),ze(3,i.Inject(B.DocSkeletonManagerService)),ze(4,ae),ze(5,x.IRenderManagerService),ze(6,i.IUniverInstanceService)],exports.DocRenderController);function ul(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 No={id:"doc.command.select-all",type:i.CommandType.COMMAND,handler:async o=>{var h;const t=o.get(i.IUniverInstanceService),e=o.get(B.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:m,endIndex:p}=g;u!==m&&d.push({startOffset:u,endOffset:m-1,rangeType:i.DOC_RANGE_TYPE.TEXT}),d.push({startOffset:m+3,endOffset:p-5,rangeType:i.DOC_RANGE_TYPE.RECT}),u=p}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 xt extends i.RxDisposable{constructor(e){super();D(this,"_previousActiveRange",null);D(this,"_undoMutationParamsCache",[]);D(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 Po={id:"doc.command.ime-input",type:i.CommandType.COMMAND,handler:async(o,t)=>{var w,z,X;const{unitId:e,newText:n,oldTextLen:r,isCompositionEnd:s,isCompositionStart:a}=t,c=o.get(i.ICommandService),l=o.get(x.IRenderManagerService),A=o.get(i.IUniverInstanceService),d=o.get(Ce),u=(w=l.getRenderById(e))==null?void 0:w.with(xt),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:m,segmentId:p}=g,f=h.getSelfOrHeaderFooterModel(p).getBody();if(f==null)return!1;Object.assign(g,g);const{startOffset:I,endOffset:C}=g,T=n.length,b=[{startOffset:I+T,endOffset:I+T,collapsed:!0,style:m}],v={id:B.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:b}},R=d.getDefaultStyle(),y=d.getStyleCache(),M=ro((z=f.customRanges)!=null?z:[],I+r,i.SHEET_EDITOR_UNITS.includes(e)),U=Zt(f,a?C:I+r,R,y,i.SHEET_EDITOR_UNITS.includes(e)),O=so((X=f.customDecorations)!=null?X:[],I+r),P=new i.TextX,N=i.JSONX.getInstance();if(!g.collapsed&&a){const V=i.BuildTextUtils.selection.delete([g],f,0,null,!1);P.push(...V),v.params.textRanges=[{startOffset:I+T,endOffset:I+T,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:M?[{...M,startIndex:0,endIndex:n.length-1}]:[],customDecorations:O.map(V=>({...V,startIndex:0,endIndex:n.length-1}))},len:n.length});const F=Z(h,p);v.params.actions=N.editOp(P.serialize(),F),v.params.noHistory=!s,v.params.isCompositionEnd=s;const k=c.syncExecuteCommand(v.id,v.params);return u.pushUndoRedoMutationParams(k,v.params),!!k}},Wt={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=ua(o,l);return e.syncExecuteCommand(Ae.id,l)?(n.pushUndoRedo({unitID:s,undoMutations:[{id:Ae.id,params:A}],redoMutations:[{id:Ae.id,params:l}]}),!0):!1}},Uo={id:"doc.table.tab-in-table",type:i.CommandType.COMMAND,handler:async(o,t)=>{var m;const{shift:e}=t,n=o.get(B.DocSelectionManagerService),r=n.getDocRanges(),s=o.get(i.ICommandService),c=o.get(i.IUniverInstanceService).getCurrentUniverDocInstance();if(!c)return!1;const l=(m=r.find(p=>p.isActive))!=null?m:r[0],A=c.getUnitId(),d=ce(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=ir(h,l,zn.PREV):g=ir(h,l,zn.NEXT),g){const{startOffset:p,endOffset:f}=g,S=[{startOffset:p,endOffset:f}];return n.replaceDocRanges(S),!0}return e===!1?await s.executeCommand(Oo.id,{position:on.BELLOW}):!0}};var gl=Object.getOwnPropertyDescriptor,hl=(o,t,e,n)=>{for(var r=n>1?void 0:n?gl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},wn=(o,t)=>(e,n)=>t(e,n,o);let Xn=class{constructor(o,t,e){D(this,"_docContainer");D(this,"getComponent",o=>{if(this._docContainer=o,!o.getContentRef().current)throw new Error("container is not ready")});D(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(fo),changeLocale:this.changeLocale,getComponent:this.getComponent}}getContentRef(){return this._docContainer.getContentRef()}UIDidMount(o){if(this._docContainer)return o(this._docContainer)}getDocContainer(){return this._docContainer}};Xn=hl([wn(0,i.Inject(i.LocaleService)),wn(1,i.Inject(i.Injector)),wn(2,i.IConfigService)],Xn);var ml=Object.getOwnPropertyDescriptor,pl=(o,t,e,n)=>{for(var r=n>1?void 0:n?ml(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},fl=(o,t)=>(e,n)=>t(e,n,o);let Kt=class extends i.RxDisposable{constructor(t){super();D(this,"_docContainerController");this._injector=t,this._docContainerController=this._injector.createInstance(Xn)}};Kt=pl([fl(0,i.Inject(i.Injector))],Kt);var Sl=Object.getOwnPropertyDescriptor,Il=(o,t,e,n)=>{for(var r=n>1?void 0:n?Sl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},hr=(o,t)=>(e,n)=>t(e,n,o);let zt=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:Ne.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:jt.id,params:{type:t!=null&&t.shift?mt.decrease:mt.increase}}]},priority:100})),this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:Ne.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(B.DocSkeletonManagerService).getSkeleton();return a==null?!1:!!(n&&r&&Fr(a,n,r)||n&&!r&&n.path.indexOf("cells")>-1)},getMutations(o){const t=o.commandParams;return[{id:Uo.id,params:{shift:!!(t!=null&&t.shift)}}]},priority:99}))}_initListSpaceAutoFormat(){this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:St.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:po.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:jt.id,params:{type:mt.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:Do.id}]},priority:-9999}))}};zt=Il([hr(0,i.Inject(exports.DocAutoFormatService)),hr(1,x.IRenderManagerService)],zt);function El(o){return o.rows[0].cells[0].sections[0].columns[0].lines[0]}function vl(o){const t=o.rows[o.rows.length-1],e=t.cells[t.cells.length-1];return x.getLastLine(e)}function Cl(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 mr(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===x.DocumentSkeletonPageType.CELL?[t]:t.parent.pages;return x.lineIterator(a,c=>{c.st===s+1?n=c:c.ed===r-1&&(e=c)}),{lineBeforeTable:e,lineAfterTable:n}}function Es(o){return o.sections[0].columns[0].lines.length===0}function vs(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 m=g.get(u);if(m!=null&&m.rows.length){s=m.rows.find(p=>!p.isRepeatRow);break}}}}if(s!=null){const l=s.cells[r];return Es(l)?vs(l):l}}function Cs(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 Es(c)?Cs(c):c}}function Tl(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 Rl(o){return o.sections[0].columns[0].lines[0]}function yl(o){const t=x.getLastColumn(o);return t.lines[t.lines.length-1]}var bl=Object.getOwnPropertyDescriptor,Ol=(o,t,e,n)=>{for(var r=n>1?void 0:n?bl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Mt=(o,t)=>(e,n)=>t(e,n,o);let Gt=class extends i.Disposable{constructor(t,e,n,r){super();D(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 C,T,b;const e=this._textSelectionManagerService.getActiveTextRange(),n=this._textSelectionManagerService.getTextRanges(),r=this._univerInstanceService.getCurrentUniverDocInstance();if(r==null)return;const s=(C=this._renderManagerService.getRenderById(r.getUnitId()))==null?void 0:C.with(B.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:m,segmentPage:p}=e;if(n.length>1){let v=Number.POSITIVE_INFINITY,R=Number.NEGATIVE_INFINITY;for(const y of n)v=Math.min(v,y.startOffset),R=Math.max(R,y.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:t===i.Direction.LEFT||t===i.Direction.UP?R:v,endOffset:t===i.Direction.LEFT||t===i.Direction.UP?v:R,style:A}],!1);return}const f=d||u===i.RANGE_DIRECTION.FORWARD?c:l;let S=d||u===i.RANGE_DIRECTION.FORWARD?l:c;const I=(T=r.getSelfOrHeaderFooterModel(h).getBody().dataStream.length)!=null?T:Number.POSITIVE_INFINITY;if(t===i.Direction.LEFT||t===i.Direction.RIGHT){const v=s.findNodeByCharIndex(S-1,h,p),R=s.findNodeByCharIndex(S,h,p);S=t===i.Direction.RIGHT?S+R.count:S-((b=v==null?void 0:v.count)!=null?b:0),S=Math.min(I-2,Math.max(0,S)),this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:S,style:A}],!1),this._scrollToFocusNodePosition(r.getUnitId(),S)}else{const v=s.findNodeByCharIndex(S,h,p),R=a.document.getOffsetConfig(),y=d?g:u===i.RANGE_DIRECTION.FORWARD?m:g,M=this._getTopOrBottomPosition(s,v,y,t===i.Direction.DOWN,!0);if(M==null){const O=t===i.Direction.UP?0:I-2;if(O===S)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:O,style:A}],!1);return}const U=new Ie(R,s).getRangePointData(M,M).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:U.endOffset,style:A}],!1),this._scrollToFocusNodePosition(r.getUnitId(),U.endOffset)}}_handleMoveCursor(t){var I,C,T,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(B.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:m}=e,p=r.getSelfOrHeaderFooterModel(u).getBody();if(p==null)return;const f=(C=p.dataStream.length)!=null?C:Number.POSITIVE_INFINITY,S=(T=r.getCustomRanges())!=null?T:[];if(t===i.Direction.LEFT||t===i.Direction.RIGHT){let v;if(!e.collapsed||n.length>1){let M=Number.POSITIVE_INFINITY,U=Number.NEGATIVE_INFINITY;for(const O of n)M=Math.min(M,O.startOffset),U=Math.max(U,O.endOffset);v=t===i.Direction.LEFT?M:U}else{const M=s.findNodeByCharIndex(c-1,u,m),U=s.findNodeByCharIndex(c,u,m),O=s.findNodeByCharIndex(c+1,u,m);t===i.Direction.LEFT?v=Math.max(0,c-((b=M==null?void 0:M.count)!=null?b:1)):v=Math.min(f-2,l+U.count+((O==null?void 0:O.streamType)===i.DataStreamTreeTokenType.SECTION_BREAK?1:0))}const R=[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(;R.includes(p.dataStream[v]);)v--;else for(;R.includes(p.dataStream[v]);)v++;S.filter(M=>M.wholeEntity&&M.startIndex<v&&M.endIndex>=v).forEach(M=>{t===i.Direction.LEFT?v=Math.min(M.startIndex,v):v=Math.max(M.endIndex+1,v)}),this._textSelectionManagerService.replaceTextRanges([{startOffset:Math.max(0,v),endOffset:Math.max(0,v),style:A}],!1),this._scrollToFocusNodePosition(r.getUnitId(),v)}else{const v=s.findNodeByCharIndex(c,u,m),R=s.findNodeByCharIndex(l,u,m),y=a.document.getOffsetConfig(),M=this._getTopOrBottomPosition(s,t===i.Direction.UP||d?v:R,t===i.Direction.UP||d?h:g,t===i.Direction.DOWN);if(M==null){let O;d?O=t===i.Direction.UP?0:f-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(y,s).getRangePointData(M,M).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 p,f,S,I,C,T,b,v,R,y,M,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===x.DocumentSkeletonPageType.CELL&&n){const O=pr(l,e);if(O)return O}if(e===!0){d=a.lines[A+1];const O=Cl(s,l);if(O){const P=El(O);P&&(d=P)}}else{d=a.lines[A-1];const O=Tl(s,l);if(O){const P=vl(O);P&&(d=P)}}if(d!=null)return d;const u=c.columns.indexOf(a);if(u===-1)return;if(e===!0)d=(p=c.columns[u+1])==null?void 0:p.lines[0];else{const O=(S=(f=c.columns)==null?void 0:f[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=(C=(I=l.sections[h-1])==null?void 0:I.columns[0])==null?void 0:C.lines[0];else{const O=(b=(T=l.sections)==null?void 0:T[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===x.DocumentSkeletonPageType.CELL)return pr(l,e);const g=l.parent;if(g==null)return;const m=g.pages.indexOf(l);if(m!==-1){if(e===!0)d=(y=(R=(v=g.pages[m+1])==null?void 0:v.sections[0])==null?void 0:R.columns[0])==null?void 0:y.lines[0];else{const O=(M=g.pages[m-1])==null?void 0:M.sections;if(O==null)return;const P=(U=O[O.length-1])==null?void 0:U.columns,N=P[P.length-1],F=N==null?void 0:N.lines;d=F[F.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 Br(this._univerInstanceService,this._renderManagerService)}};Gt=Ol([Mt(0,i.IUniverInstanceService),Mt(1,x.IRenderManagerService),Mt(2,i.Inject(B.DocSelectionManagerService)),Mt(3,i.ICommandService)],Gt);function pr(o,t){var n,r;let e=null;if(t===!0){const s=vs(o);if(s)e=Rl(s);else{const a=(n=o.parent)==null?void 0:n.parent,{lineAfterTable:c}=mr(a);c&&(e=c)}}else{const s=Cs(o);if(s)e=yl(s);else{const a=(r=o.parent)==null?void 0:r.parent,{lineBeforeTable:c}=mr(a);c&&(e=c)}}return e}const xl="univer-create",Dl="univer-create-item",Bl="univer-create-label",Ml="univer-create-input",Be={create:xl,createItem:Dl,createLabel:Bl,createInput:Ml},_l=({handleRowColChange:o,tableCreateParams:t})=>{const e=E.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:Be.create,children:[Q.jsxs("div",{className:Be.createItem,children:[Q.jsx("span",{className:Be.createLabel,children:e.t("toolbar.table.rowCount")}),Q.jsx(te.InputNumber,{min:1,max:20,precision:0,value:n,onChange:l=>{c(l,s)},className:Be.createInput})]}),Q.jsxs("div",{className:Be.createItem,children:[Q.jsx("span",{className:Be.createLabel,children:e.t("toolbar.table.colCount")}),Q.jsx(te.InputNumber,{min:1,max:20,precision:0,value:s,onChange:l=>{c(n,l)},className:Be.createInput})]})]})};var Nl=Object.getOwnPropertyDescriptor,Pl=(o,t,e,n)=>{for(var r=n>1?void 0:n?Nl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},fr=(o,t)=>(e,n)=>t(e,n,o);let Xt=class extends i.Disposable{constructor(o,t){super(),this._commandService=o,this._componentManager=t,this._initialize()}_initialize(){this._init(),this._registerCommands(),this._initCustomComponents()}_registerCommands(){[Cn].forEach(o=>this.disposeWithMe(this._commandService.registerCommand(o)))}_initCustomComponents(){const o=this._componentManager;this.disposeWithMe(o.register(ms,_l))}_init(){}};Xt=Pl([fr(0,i.ICommandService),fr(1,i.Inject(E.ComponentManager))],Xt);const Yn=4;var Ul=Object.getOwnPropertyDescriptor,wl=(o,t,e,n)=>{for(var r=n>1?void 0:n?Ul(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},_t=(o,t)=>(e,n)=>t(e,n,o);function Ts(o,t){const e=Sr(o.left,o.top,t),n=Sr(o.right,o.bottom,t);return{left:e.x,top:e.y,right:n.x,bottom:n.y}}function Sr(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 Ir(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 kt=(o,t)=>{const{scene:e,mainComponent:n,engine:r}=t,s=t.with(B.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(),m=x.pxToNum(h.style.width),{top:p,left:f,width:S}=g,I=S/m,{scaleX:C,scaleY:T}=e.getAncestorScale(),b=new Ie(A,s),{borderBoxPointGroup:v}=b.getRangePointData(a,c);return $t(v).map(M=>Ts(M,e)).map(M=>({left:(M.left+d*C)*I+f,right:(M.right+d*C)*I+f,top:(M.top+u*T)*I+p,bottom:(M.bottom+u*T)*I+p}))};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,m={left:d,right:d+h,top:u,bottom:u+g},p=A.getCanvasElement(),f=p.getBoundingClientRect(),S=x.pxToNum(p.style.width),I=Ts(m,l),{top:C,left:T,width:b}=f,v=b/S;return{left:I.left*v+T,right:I.right*v+T,top:I.top*v+C,bottom:I.bottom*v+C}},r=n(),s=new _.BehaviorSubject(r),a=new i.DisposableCollection;a.add(this._commandService.onCommandExecuted(l=>{if(l.id===Ae.id||l.id===B.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=kt(t,e))!=null?c:[],r=new _.BehaviorSubject(n),s=new i.DisposableCollection;s.add(this._commandService.onCommandExecuted(l=>{if((l.id===Ae.id||l.id===B.RichTextEditingMutation.id)&&l.params.unitId===e.unitId){const d=kt(t,e);d&&r.next(d)}}));const a=e.scene.getViewport(he.VIEW_MAIN);return a&&s.add(a.onScrollAfter$.subscribeEvent(()=>{const l=kt(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=wl([_t(0,i.Inject(E.ICanvasPopupService)),_t(1,x.IRenderManagerService),_t(2,i.IUniverInstanceService),_t(3,i.ICommandService)],exports.DocCanvasPopManagerService);var 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=a(r)||r);return r},Fl=(o,t)=>(e,n)=>t(e,n,o);const kl=(o,t,e,n)=>{var h,g,m,p,f;const r=e.findNodePositionByCharIndex(o.startOffset,!0,o.segmentId,n),s=e.getSkeletonData();let a=o.endOffset;if(o.segmentId){const S=(f=Array.from((g=(h=s==null?void 0:s.skeFooters.get(o.segmentId))==null?void 0:h.values())!=null?g:[])[0])!=null?f:Array.from((p=(m=s==null?void 0:s.skeHeaders.get(o.segmentId))==null?void 0:m.values())!=null?p:[])[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 $t(d).map(S=>({top:S.top+l.docsTop-Yn,bottom:S.bottom+l.docsTop+Yn,left:S.left+l.docsLeft,right:S.right+l.docsLeft}))},Hl=(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=$t(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();D(this,"_hoverCustomRanges$",new _.BehaviorSubject([]));D(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))));D(this,"_clickCustomRanges$",new _.Subject);D(this,"clickCustomRanges$",this._clickCustomRanges$.asObservable());D(this,"_hoverBullet$",new _.Subject);D(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))));D(this,"_clickBullet$",new _.Subject);D(this,"clickBullets$",this._clickBullet$.asObservable());D(this,"_customRangeDirty",!0);D(this,"_bulletDirty",!0);D(this,"_customRangeBounds",[]);D(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=x.CURSOR_TYPE.TEXT;this.disposeWithMe(this.hoverCustomRanges$.subscribe(n=>{n.length?(e=this._context.scene.getCursor(),this._context.scene.setCursor(x.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===x.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,segmentId:e},u=kl(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}=Ir(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(m=>m.bullet&&m.bullet.listType.indexOf("CHECK_LIST")===0),a=[],c=this._skeleton.getSkeletonData();if(!c)return a;const l=m=>{var p,f,S;for(const I of m){const C=[...I.sections];if(I.skeTables){const T=Array.from(I.skeTables.values());C.push(...T.map(b=>b.rows.map(v=>v.cells.map(R=>R.sections))).flat(4))}for(const T of C)for(const b of T.columns)for(const v of b.lines)if(v.paragraphStart){const R=s.find(y=>y.startIndex===v.paragraphIndex);if(R){const y=v,M=(S=(f=(p=y==null?void 0:y.divides)==null?void 0:p[0])==null?void 0:f.glyphGroup)==null?void 0:S[0];if(!M)continue;const U=Hl(M,this._documents,this._skeleton,n);if(!U)continue;a.push({rect:U,segmentId:e,segmentPageIndex:n,paragraph:R})}}}return a};if(e){const m=(g=(u=c.skeFooters.get(e))==null?void 0:u.values())!=null?g:(h=c.skeHeaders.get(e))==null?void 0:h.values();return m?l(Array.from(m)):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}=Ir(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=Ll([Fl(1,i.Inject(B.DocSkeletonManagerService))],exports.DocEventManagerService);var Vl=Object.getOwnPropertyDescriptor,jl=(o,t,e,n)=>{for(var r=n>1?void 0:n?Vl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Nt=(o,t)=>(e,n)=>t(e,n,o);let qn=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(tn.id,{index:o.paragraph.startIndex,segmentId:o.segmentId,textRanges:t})})}_initHoverCursor(){this.disposeWithMe(this._docEventManagerService.hoverBullet$.subscribe(o=>{o?this._context.mainComponent.setCursor(x.CURSOR_TYPE.POINTER):this._context.mainComponent.setCursor(x.CURSOR_TYPE.TEXT)}))}_getTransformCoordForDocumentOffset(o,t,e,n){const{documentTransform:r}=o.getOffsetConfig(),s=t.transformVector2SceneCoord(x.Vector2.FromArray([e,n]));if(s)return r.clone().invert().applyPoint(s)}};qn=jl([Nt(1,i.Inject(B.DocSkeletonManagerService)),Nt(2,i.ICommandService),Nt(3,i.Inject(exports.DocEventManagerService)),Nt(4,i.Inject(B.DocSelectionManagerService))],qn);var 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=a(r)||r);return r},At=(o,t)=>(e,n)=>t(e,n,o);let Yt=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(!un(this._contextService))return;t.event.preventDefault();const e=t.event;let n=(c=e.clipboardData)==null?void 0:c.getData(E.HTML_CLIPBOARD_MIME_TYPE);const r=(l=e.clipboardData)==null?void 0:l.getData(E.PLAIN_TEXT_CLIPBOARD_MIME_TYPE),s=[...((A=e.clipboardData)==null?void 0:A.items)||[]].filter(d=>E.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})})}};Yt=Kl([At(1,i.ICommandService),At(2,it),At(3,i.Inject(exports.DocSelectionRenderService)),At(4,i.IContextService),At(5,ae)],Yt);var zl=Object.getOwnPropertyDescriptor,Gl=(o,t,e,n)=>{for(var r=n>1?void 0:n?zl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Er=(o,t)=>(e,n)=>t(e,n,o);const Xl=[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 Jn=class extends i.Disposable{constructor(o,t,e){super(),this._context=o,this._contextMenuService=t,this._commandService=e,Xl.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,E.ContextMenuPosition.MAIN_AREA)});this.disposeWithMe(t)}_initEditChange(){this.disposeWithMe(this._commandService.onCommandExecuted(o=>{o.id===B.RichTextEditingMutation.id&&this._contextMenuService.visible&&this._contextMenuService.hideContextMenu()}))}};Jn=Gl([Er(1,E.IContextMenuService),Er(2,i.ICommandService)],Jn);var Yl=Object.getOwnPropertyDescriptor,ql=(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=a(r)||r);return r},Ge=(o,t)=>(e,n)=>t(e,n,o);let qt=class extends i.Disposable{constructor(t,e,n,r,s,a,c){super();D(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:m}=e.getBoundingClientRect(),p=Math.max(h,g),f=Math.max(u,m);A.transformByState({width:p,height:f}),d==null||d.resize(p,f)}_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()}));const e=new i.DisposableCollection;this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(i.UniverInstanceType.UNIVER_SHEET).subscribe(n=>{if(e.dispose(),!n)return;const r=n.getUnitId(),s=this._renderManagerService.getRenderById(r),a=s==null?void 0:s.engine.getCanvas().getCanvasEle();if(a==null)return;const c=_.fromEvent(a,"mousedown").subscribe(l=>{l.stopPropagation()});e.add(c)})),this.disposeWithMe(()=>e.dispose())}_commandExecutedListener(){const t=[B.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)}}))}};qt=ql([Ge(1,i.IUniverInstanceService),Ge(2,ae),Ge(3,i.ICommandService),Ge(4,i.Inject(exports.DocSelectionRenderService)),Ge(5,i.Inject(B.DocSkeletonManagerService)),Ge(6,x.IRenderManagerService)],qt);var Jl=Object.getOwnPropertyDescriptor,Zl=(o,t,e,n)=>{for(var r=n>1?void 0:n?Jl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Pt=(o,t)=>(e,n)=>t(e,n,o);let Zn=class extends i.Disposable{constructor(t,e,n,r,s){super();D(this,"_previousIMEContent","");D(this,"_isCompositionStart",!0);D(this,"_onStartSubscription");D(this,"_onUpdateSubscription");D(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(Po.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)}};Zn=Zl([Pt(1,i.Inject(exports.DocSelectionRenderService)),Pt(2,i.Inject(xt)),Pt(3,i.Inject(B.DocSkeletonManagerService)),Pt(4,i.ICommandService)],Zn);var $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=a(r)||r);return r},Ut=(o,t)=>(e,n)=>t(e,n,o);let $n=class extends i.Disposable{constructor(t,e,n,r,s){super();D(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 f,S;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=ro((f=d==null?void 0:d.customRanges)!=null?f:[],s.endOffset,i.SHEET_EDITOR_UNITS.includes(e)),m=Zt(d,s.endOffset,u,h,i.SHEET_EDITOR_UNITS.includes(e)),p=so((S=d==null?void 0:d.customDecorations)!=null?S:[],s.endOffset);await this._commandService.executeCommand(cn.id,{unitId:e,body:{dataStream:r,textRuns:m?[{...m,st:0,ed:r.length}]:[],customRanges:g?[{...g,startIndex:0,endIndex:r.length-1}]:[],customDecorations:p.map(I=>({...I,startIndex:0,endIndex:r.length-1}))},range:s,segmentId:l}),r===" "&&await this._commandService.executeCommand(St.id)})}};$n=eA([Ut(1,i.Inject(exports.DocSelectionRenderService)),Ut(2,i.Inject(B.DocSkeletonManagerService)),Ut(3,i.ICommandService),Ut(4,i.Inject(Ce))],$n);class wo extends i.Disposable{constructor(t){super(),this._context=t}calculatePagePosition(){var T,b;const t=Se(this._context),n=(b=(T=this._context.unit.getSettings())==null?void 0:T.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 m=0,p=u,f=0,S=0,I=Number.POSITIVE_INFINITY;h>(l+d*2)*n?(m=h/2-l*n/2,m/=n,f=(h-d*2)/n,I=0):(m=d,f=l+d*2,I=(f-h/n)/2),g>A?S=(g-u*2)/n:S=A+u*2,s.resize(f,S),h<=1&&(m=-1e4,p=-1e4),r.translate(m,p),a.translate(m,p);const C=s.getViewport(he.VIEW_MAIN);return I!==Number.POSITIVE_INFINITY&&C!=null&&C.scrollToViewportPos({viewportScrollX:I}),this}}var tA=Object.getOwnPropertyDescriptor,nA=(o,t,e,n)=>{for(var r=n>1?void 0:n?tA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},vr=(o,t)=>(e,n)=>t(e,n,o);let eo=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===x.TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize),_.throttleTime(0,_.animationFrameScheduler)).subscribe(()=>{this._docPageLayoutService.calculatePagePosition(),this._textSelectionManagerService.refreshSelection()}))}};eo=nA([vr(1,i.Inject(wo)),vr(2,i.Inject(B.DocSelectionManagerService))],eo);var oA=Object.getOwnPropertyDescriptor,rA=(o,t,e,n)=>{for(var r=n>1?void 0:n?oA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Xe=(o,t)=>(e,n)=>t(e,n,o);let to=class extends i.Disposable{constructor(t,e,n,r,s,a,c){super();D(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=x.CURSOR_TYPE.TEXT)})),this.disposeWithMe(n.onPointerLeave$.subscribeEvent(()=>{n.cursor=x.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=x.PageLayoutType.VERTICAL,pageMarginLeft:g,pageMarginTop:m}=n.getOffsetConfig(),{editArea:p}=l.findEditAreaByCoord(u,h,g,m),f=this._docSkeletonManagerService.getViewModel(),S=f.getEditArea();S!==x.DocumentEditArea.BODY&&p!==x.DocumentEditArea.BODY&&p!==S&&f.setEditArea(p)}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(x.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=[Ae.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=Xr(s);this._docSelectionManagerService.replaceDocRanges([{startOffset:a,endOffset:a}],{unitId:e,subUnitId:e},!1)}}))}};to=rA([Xe(1,i.ICommandService),Xe(2,ae),Xe(3,i.IUniverInstanceService),Xe(4,i.Inject(exports.DocSelectionRenderService)),Xe(5,i.Inject(B.DocSkeletonManagerService)),Xe(6,i.Inject(B.DocSelectionManagerService))],to);var sA=Object.getOwnPropertyDescriptor,iA=(o,t,e,n)=>{for(var r=n>1?void 0:n?sA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Me=(o,t)=>(e,n)=>t(e,n,o);let no=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(Wt.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=[Ae.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===mn.id&&this._commandService.executeCommand(Wt.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()}};no=iA([Me(1,i.IContextService),Me(2,i.Inject(B.DocSkeletonManagerService)),Me(3,i.IUniverInstanceService),Me(4,i.ICommandService),Me(5,i.Inject(B.DocSelectionManagerService)),Me(6,ae),Me(7,i.Inject(wo))],no);var 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=a(r)||r);return r},dt=(o,t)=>(e,n)=>t(e,n,o);const Cr=300;exports.DocStateChangeManagerService=class extends i.RxDisposable{constructor(e,n,r,s,a){super();D(this,"_docStateChange$",new _.BehaviorSubject(null));D(this,"docStateChange$",this._docStateChange$.asObservable());D(this,"_historyStateCache",new Map);D(this,"_changeStateCache",new Map);D(this,"_historyTimer",null);D(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(xt);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)},Cr)):(this._changeStateCacheTimer&&clearTimeout(this._changeStateCacheTimer),this._changeStateCacheTimer=setTimeout(()=>{A(s)},Cr)):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((p,f)=>i.JSONX.compose(p,f.redoState.actions),null),textRanges:u.redoState.textRanges},g={unitId:e,actions:n.reverse().reduce((p,f)=>i.JSONX.compose(p,f.undoState.actions),null),textRanges:d.undoState.textRanges},m={commandId:s,unitId:e,trigger:a,redoState:h,undoState:g,segmentId:c,noHistory:l,debounce:A};n.length=0,this._docStateChange$.next(m)}};exports.DocStateChangeManagerService=cA([dt(0,i.Inject(i.IUndoRedoService)),dt(1,i.ICommandService),dt(2,i.IUniverInstanceService),dt(3,i.Inject(B.DocStateEmitService)),dt(4,x.IRenderManagerService)],exports.DocStateChangeManagerService);var lA=Object.getOwnPropertyDescriptor,AA=(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=a(r)||r);return r},Tr=(o,t)=>(e,n)=>t(e,n,o);const Rr="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(Rr),s.engine.getCanvas().getContext().setId(Rr))}),this._renderManagerService.has(e)||this._createRenderWithId(e)}_createRenderWithId(t){this._renderManagerService.createRender(t)}_disposeRenderer(t){const e=t.getUnitId();this._renderManagerService.removeRender(e)}};exports.DocsRenderService=AA([Tr(0,i.IUniverInstanceService),Tr(1,x.IRenderManagerService)],exports.DocsRenderService);class Rs extends i.Disposable{constructor(){super(...arguments);D(this,"_currentSelectorId");D(this,"_selectionChange$",new _.Subject);D(this,"selectionChange$",this._selectionChange$.asObservable());D(this,"_openSelector$",new _.Subject);D(this,"openSelector$",this._openSelector$.asObservable());D(this,"_selectorModalVisible$",new _.BehaviorSubject(!1));D(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 ys=i.createIdentifier("univer.range-selector.service"),dA={id:Je.id,preconditions:Vi,binding:E.KeyCode.ENTER},uA={id:Ot.id,preconditions:$,binding:E.KeyCode.BACKSPACE},gA={id:Co.id,preconditions:$,binding:E.KeyCode.DELETE},hA={id:Ee.id,binding:E.KeyCode.ARROW_UP,preconditions:$,staticParameters:{direction:i.Direction.UP}},mA={id:Ee.id,binding:E.KeyCode.ARROW_DOWN,preconditions:$,staticParameters:{direction:i.Direction.DOWN}},pA={id:Ee.id,binding:E.KeyCode.ARROW_LEFT,preconditions:$,staticParameters:{direction:i.Direction.LEFT}},fA={id:Ee.id,binding:E.KeyCode.ARROW_RIGHT,preconditions:$,staticParameters:{direction:i.Direction.RIGHT}},SA={id:ve.id,binding:E.KeyCode.ARROW_UP|E.MetaKeys.SHIFT,preconditions:$,staticParameters:{direction:i.Direction.UP}},IA={id:ve.id,binding:E.KeyCode.ARROW_DOWN|E.MetaKeys.SHIFT,preconditions:$,staticParameters:{direction:i.Direction.DOWN}},EA={id:ve.id,binding:E.KeyCode.ARROW_LEFT|E.MetaKeys.SHIFT,preconditions:$,staticParameters:{direction:i.Direction.LEFT}},vA={id:ve.id,binding:E.KeyCode.ARROW_RIGHT|E.MetaKeys.SHIFT,preconditions:$,staticParameters:{direction:i.Direction.RIGHT}},CA={id:No.id,binding:E.KeyCode.A|E.MetaKeys.CTRL_COMMAND,preconditions:o=>o.getContextValue(i.FOCUSING_UNIVER_EDITOR)&&(o.getContextValue(i.FOCUSING_DOC)||o.getContextValue(i.EDITOR_ACTIVATED))};var TA=Object.defineProperty,RA=Object.getOwnPropertyDescriptor,yA=(o,t,e)=>t in o?TA(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,bA=(o,t,e,n)=>{for(var r=n>1?void 0:n?RA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},ut=(o,t)=>(e,n)=>t(e,n,o),OA=(o,t,e)=>yA(o,t+"",e);exports.UniverDocsUIPlugin=class extends i.Plugin{constructor(t=sr,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({},sr,this._config);c&&this._configService.setConfig("menu",c,{merge:!0}),this._configService.setConfig(fo,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,[[zt],[Gt],[et],[Xt],[exports.DocUIController]])}_initCommand(){[Ot,Co,Fe,ke,He,Ve,Oe,je,Pe,Ue,we,ot,Qe,Te,Do,cn,Ze,ln,vo,An,Ae,vt,Et,rt,Ct,Tt,Rt,me,yt,Bo,Oo,Sn,In,hs,En,vn,pn,fn,at,ho,Uo,Ne,St,Je,jt,It,en,tn,po,Po,mn,pe,Eo,Le,Pr,io,Ur,Wt,No,Mo,Ee,ve,Qr].forEach(t=>{this._commandService.registerCommand(t)}),[pt,gn,hn].forEach(t=>this.disposeWithMe(this._commandService.registerMultipleCommand(t)))}_initializeShortcut(){[hA,mA,fA,pA,SA,IA,EA,vA,CA,uA,gA,dA,Wi].forEach(t=>{this._injector.get(E.IShortcutService).registerShortcut(t)})}_initDependencies(t){i.mergeOverrideWithDependencies([[Yt],[qt],[exports.DocUIController],[zt],[Xt],[Gt],[Kt],[et],[ae,{useClass:exports.EditorService}],[ys,{useClass:Rs}],[it,{useClass:Gn}],[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(ae);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(Kt)}_initRenderBasics(){[[B.DocSkeletonManagerService],[exports.DocSelectionRenderService],[B.DocInterceptorService],[wo],[xt],[exports.DocRenderController],[no]].forEach(t=>{this._renderManagerSrv.registerRenderModule(i.UniverInstanceType.UNIVER_DOC,t)})}_initRenderModules(){[[exports.DocEventManagerService],[exports.DocBackScrollRenderController],[to],[Wn],[eo],[Jn],[qn],[Yt],[$n],[Zn],[qt]].forEach(t=>{this._renderManagerSrv.registerRenderModule(i.UniverInstanceType.UNIVER_DOC,t)})}};OA(exports.UniverDocsUIPlugin,"pluginName",Or);exports.UniverDocsUIPlugin=bA([i.DependentOn(x.UniverRenderEnginePlugin),ut(1,i.Inject(i.Injector)),ut(2,x.IRenderManagerService),ut(3,i.ICommandService),ut(4,i.ILogService),ut(5,i.IConfigService)],exports.UniverDocsUIPlugin);exports.AfterSpaceCommand=St;exports.AlignCenterCommand=Tt;exports.AlignJustifyCommand=yt;exports.AlignLeftCommand=Ct;exports.AlignOperationCommand=me;exports.AlignRightCommand=Rt;exports.BreakLineCommand=Do;exports.BulletListCommand=Et;exports.ChangeListNestingLevelCommand=jt;exports.ChangeListNestingLevelType=mt;exports.ChangeListTypeCommand=It;exports.CheckListCommand=en;exports.CoverContentCommand=Ur;exports.CreateDocTableCommand=Bo;exports.CutContentCommand=Le;exports.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX=xr;exports.DOCS_COMPONENT_DEFAULT_Z_INDEX=Qn;exports.DOCS_COMPONENT_HEADER_LAYER_INDEX=Dr;exports.DOCS_COMPONENT_MAIN_LAYER_INDEX=wt;exports.DOCS_VIEW_KEY=le;exports.DOC_UI_PLUGIN_NAME=Or;exports.DOC_VERTICAL_PADDING=Yn;exports.DefaultDocContainerConfig=br;exports.DefaultToolbarConfig=yr;exports.DeleteCommand=Ze;exports.DeleteCustomBlockCommand=ln;exports.DeleteLeftCommand=Ot;exports.DeleteRightCommand=Co;exports.DocCopyCommand=pt;exports.DocCreateTableOperation=Cn;exports.DocCutCommand=gn;exports.DocIMEInputManagerService=xt;exports.DocPasteCommand=hn;exports.DocSelectAllCommand=No;exports.DocTableDeleteColumnsCommand=fn;exports.DocTableDeleteRowsCommand=pn;exports.DocTableDeleteTableCommand=at;exports.DocTableInsertColumnCommand=hs;exports.DocTableInsertColumnLeftCommand=En;exports.DocTableInsertColumnRightCommand=vn;exports.DocTableInsertRowAboveCommand=Sn;exports.DocTableInsertRowBellowCommand=In;exports.DocTableInsertRowCommand=Oo;exports.DocTableTabCommand=Uo;exports.DocsUIMenuSchema=Is;exports.Editor=Hr;exports.EditorInsertTextCommandId=cs;exports.EnterCommand=Je;exports.IDocClipboardService=it;exports.IEditorService=ae;exports.IMEInputCommand=Po;exports.IRangeSelectorService=ys;exports.InnerPasteCommand=Eo;exports.InsertCommand=cn;exports.ListOperationCommand=rt;exports.MergeTwoParagraphCommand=An;exports.MoveCursorOperation=Ee;exports.MoveSelectionOperation=ve;exports.NORMAL_TEXT_SELECTION_PLUGIN_NAME=Ps;exports.NodePositionConvertToCursor=Ie;exports.NodePositionConvertToRectRange=lo;exports.OrderListCommand=vt;exports.PastePluginLark=As;exports.PastePluginUniver=us;exports.PastePluginWord=gs;exports.QuickListCommand=po;exports.RangeSelectorService=Rs;exports.RectRange=Ao;exports.ReplaceContentCommand=Pr;exports.ReplaceSnapshotCommand=io;exports.ReplaceTextRunsCommand=Qr;exports.ResetInlineFormatTextBackgroundColorCommand=ot;exports.RichTextEditor=Ai;exports.SetDocZoomRatioCommand=Wt;exports.SetDocZoomRatioOperation=Ae;exports.SetInlineFormatBoldCommand=Fe;exports.SetInlineFormatCommand=Te;exports.SetInlineFormatFontFamilyCommand=Ue;exports.SetInlineFormatFontSizeCommand=Pe;exports.SetInlineFormatItalicCommand=ke;exports.SetInlineFormatStrikethroughCommand=Ve;exports.SetInlineFormatSubscriptCommand=Oe;exports.SetInlineFormatSuperscriptCommand=je;exports.SetInlineFormatTextBackgroundColorCommand=Qe;exports.SetInlineFormatTextColorCommand=we;exports.SetInlineFormatUnderlineCommand=He;exports.TEXT_RANGE_LAYER_INDEX=Ht;exports.TabCommand=Ne;exports.TextRange=_e;exports.ToggleCheckListCommand=tn;exports.UpdateCommand=vo;exports.VIEWPORT_KEY=he;exports.addCustomDecorationBySelectionFactory=ws;exports.addCustomDecorationFactory=Mr;exports.calcDocRangePositions=kt;exports.convertPositionsToRectRanges=Lt;exports.deleteCustomDecorationFactory=Qs;exports.docDrawingPositionToTransform=Fs;exports.genTableSource=Io;exports.generateParagraphs=xo;exports.getAnchorBounding=ht;exports.getCanvasOffsetByEngine=kr;exports.getCommandSkeleton=ce;exports.getCursorWhenDelete=dn;exports.getCustomBlockIdsInSelections=is;exports.getCutActionsFromDocRanges=as;exports.getDocObject=Br;exports.getDocObjectById=Us;exports.getEmptyTableCell=rn;exports.getEmptyTableRow=sn;exports.getLineBounding=$t;exports.getOneTextSelectionRange=Fn;exports.getParagraphsInRange=nn;exports.getParagraphsInRanges=st;exports.getRichTextEditPath=Z;exports.getTableColumn=an;exports.hasParagraphInTable=Ls;exports.isInSameTableCell=co;exports.isValidRectRange=Lr;exports.neoGetDocObject=Se;exports.transformToDocDrawingPosition=ks;exports.useKeyboardEvent=_r;exports.useResize=Nr;exports.whenDocAndEditorFocused=$;
39
+ `,style:{width:162},children:[Q.jsx(te.Select,{value:`${C}`,options:[{label:o.t("doc.paragraphSetting.multiSpace"),value:`${i.SpacingRule.AUTO}`},{label:o.t("doc.paragraphSetting.fixedValue"),value:`${i.SpacingRule.AT_LEAST}`}],onChange:v=>T(Number(v))}),Q.jsx(De,{...b,value:S,onChange:v=>I(v!=null?v:0)})]})]})]})]})}const mc=(o,t)=>t.length===o.length&&o.some(e=>t.some(n=>n.startOffset===e.startOffset&&n.endOffset===e.endOffset));function pc(){const o=E.useDependency(i.ICommandService),t=E.useDependency(i.LocaleService),e=E.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(B.SetTextSelectionsOperation.id===l.id){const A=l.params.ranges;mc(A,a.current)||r(i.generateRandomId(4)),a.current=A}B.RichTextEditingMutation.id===l.id&&l.params.trigger!==pe.id&&s()});return()=>c.dispose()},[s]),L.useEffect(()=>{r(i.generateRandomId(4))},[e]),L.useEffect(()=>()=>s.cancel(),[s]),Q.jsx(hc,{},n)}var fc=Object.getOwnPropertyDescriptor,Sc=(o,t,e,n)=>{for(var r=n>1?void 0:n?fc(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Pn=(o,t)=>(e,n)=>t(e,n,o);const dr="doc_ui_paragraph-setting-panel";let et=class extends i.Disposable{constructor(t,e,n){super();D(this,"_id");this._commandService=t,this._componentManager=e,this._sidebarService=n,this._init()}_init(){this.disposeWithMe(this._componentManager.register(dr,pc))}openPanel(){const t={header:{title:"doc.slider.paragraphSetting"},id:this._id,children:{label:dr},width:300};this._sidebarService.open(t)}closePanel(){this._sidebarService.close(this._id)}};et=Sc([Pn(0,i.ICommandService),Pn(1,i.Inject(E.ComponentManager)),Pn(2,i.Inject(E.ISidebarService))],et);const Mo={id:"sidebar.operation.doc-paragraph-setting-panel",type:i.CommandType.OPERATION,handler:o=>(o.get(et).openPanel(),!0)},_o=o=>{const t=o.get(B.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 Ic(o){if(o.length<2)return!0;const t=o.map(e=>e.tableId);return t.every(e=>e===t[0])}function ur(o,t,e){var s;const n=t.getRectRanges(),r=t.getActiveTextRange();if(n&&n.length&&Ic(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(B.DocSelectionManagerService),e=o.get(i.IUniverInstanceService);return new _.Observable(n=>{const r=t.textSelection$.subscribe(()=>{ur(n,t,e)});return ur(n,t,e),()=>r.unsubscribe()})},Ec=o=>({id:pt.name,commandId:pt.id,type:E.MenuItemType.BUTTON,icon:"Copy",title:"rightClick.copy",disabled$:_o(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}),vc=o=>({id:Mo.id,type:E.MenuItemType.BUTTON,icon:"MenuSingle24",title:"doc.menu.paragraphSetting",hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}),Cc=o=>({id:gn.id,type:E.MenuItemType.BUTTON,icon:"Copy",title:"rightClick.cut",disabled$:_o(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}),Tc=o=>({id:hn.id,type:E.MenuItemType.BUTTON,icon:"PasteSpecial",title:"rightClick.paste",hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}),Rc=o=>({id:Ot.id,type:E.MenuItemType.BUTTON,icon:"PasteSpecial",title:"rightClick.delete",disabled$:_o(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}),ps="doc.menu.table-insert";function yc(o){return{id:ps,type:E.MenuItemType.SUBITEMS,title:"table.insert",icon:"Insert",hidden$:_.combineLatest(E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),Re(o),(t,e)=>t||e)}}function bc(o){return{id:Sn.id,type:E.MenuItemType.BUTTON,title:"table.insertRowAbove",icon:"InsertRowAbove",disabled$:Re(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Oc(o){return{id:In.id,type:E.MenuItemType.BUTTON,title:"table.insertRowBelow",icon:"InsertRowBelow",disabled$:Re(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function xc(o){return{id:En.id,type:E.MenuItemType.BUTTON,title:"table.insertColumnLeft",icon:"LeftInsertColumn",disabled$:Re(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Dc(o){return{id:vn.id,type:E.MenuItemType.BUTTON,title:"table.insertColumnRight",icon:"RightInsertColumn",disabled$:Re(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}const fs="doc.menu.table-delete";function Bc(o){return{id:fs,type:E.MenuItemType.SUBITEMS,title:"table.delete",icon:"Reduce",hidden$:_.combineLatest(E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),Re(o),(t,e)=>t||e)}}function Mc(o){return{id:pn.id,type:E.MenuItemType.BUTTON,title:"table.deleteRows",icon:"DeleteRow",disabled$:Re(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function _c(o){return{id:fn.id,type:E.MenuItemType.BUTTON,title:"table.deleteColumns",icon:"DeleteColumn",disabled$:Re(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Nc(o){return{id:at.id,type:E.MenuItemType.BUTTON,title:"table.deleteTable",icon:"GridSingle",disabled$:Re(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Pc(o){const t=o.get(i.IUniverInstanceService),e=o.get(x.IRenderManagerService);return new _.Observable(n=>{const r=t.focused$.subscribe(s=>{if(s==null||t.getUnitType(s)!==i.UniverInstanceType.UNIVER_DOC)return n.next(!0);const c=e.getRenderById(s);if(c==null)return n.next(!0);c.with(B.DocSkeletonManagerService).getViewModel().editAreaChange$.subscribe(A=>{n.next(A===x.DocumentEditArea.HEADER||A===x.DocumentEditArea.FOOTER)})});return()=>r.unsubscribe()})}function Uc(o){const t=o.get(i.IUniverInstanceService),e=o.get(i.ICommandService);return new _.Observable(n=>{const r=e.onCommandExecuted(l=>{if(l.id===B.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 wc(o){const t=o.get(B.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=ce(o,u.getUnitId());if(h==null){n.next(!0);return}if(h.getViewModel().getCustomRangeRaw(d)){n.next(!0);return}if(A!=null){const{path:p}=A;if(p.indexOf("cells")!==-1){n.next(!0);return}}n.next(!1)});return()=>r.unsubscribe()})}function ee(o){const t=o.get(B.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 Qc(o){const t=o.get(i.ICommandService);return{id:Fe.id,type:E.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===B.SetTextSelectionsOperation.id||s===Te.id){const c=xe(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Lc(o){const t=o.get(i.ICommandService);return{id:ke.id,type:E.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===B.SetTextSelectionsOperation.id||s===Te.id){const c=xe(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Fc(o){const t=o.get(i.ICommandService);return{id:He.id,type:E.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===B.SetTextSelectionsOperation.id||s===Te.id){const c=xe(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function kc(o){const t=o.get(i.ICommandService);return{id:Ve.id,type:E.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===B.SetTextSelectionsOperation.id||s===Te.id){const c=xe(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Hc(o){const t=o.get(i.ICommandService);return{id:Oe.id,type:E.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===Te.id){const c=xe(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Vc(o){const t=o.get(i.ICommandService);return{id:je.id,type:E.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===Te.id){const c=xe(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function jc(o){const t=o.get(i.ICommandService);return{id:Ue.id,tooltip:"toolbar.font",type:E.MenuItemType.SELECTOR,label:qr,selections:E.FONT_FAMILY_LIST.map(e=>({label:{name:Jr},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===B.SetTextSelectionsOperation.id||a===Ue.id){const l=xe(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Wc(o){const t=o.get(i.ICommandService);return{id:Pe.id,type:E.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Zr,props:{min:1,max:400}},selections:E.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===B.SetTextSelectionsOperation.id||a===Pe.id){const l=xe(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Kc(o){const t=o.get(i.ICommandService),e=o.get(i.ThemeService);return{id:we.id,icon:"FontColor",tooltip:"toolbar.textColor.main",type:E.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:mo,hoverable:!1,selectable:!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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function zc(o){return{id:go.id,type:E.MenuItemType.BUTTON,icon:"HeaderFooterSingle",tooltip:"toolbar.headerFooter",hidden$:_.combineLatest(E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY),Uc(o),(t,e)=>t||e)}}const Gc="GridSingle",Ss="doc.menu.table";function Xc(o){return{id:Ss,type:E.MenuItemType.SUBITEMS,icon:Gc,tooltip:"toolbar.table.main",disabled$:wc(o),hidden$:_.combineLatest(E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY),Pc(o),(t,e)=>t||e)}}function Yc(o){return{id:Cn.id,title:"toolbar.table.insert",type:E.MenuItemType.BUTTON,hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function qc(o){const t=o.get(i.ICommandService);return{id:Ct.id,type:E.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===B.SetTextSelectionsOperation.id||s===me.id){const c=Tn(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Jc(o){const t=o.get(i.ICommandService);return{id:Tt.id,type:E.MenuItemType.BUTTON,icon:"HorizontallySingle",tooltip:"toolbar.alignCenter",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===me.id){const c=Tn(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Zc(o){const t=o.get(i.ICommandService);return{id:Rt.id,type:E.MenuItemType.BUTTON,icon:"RightJustifyingSingle",tooltip:"toolbar.alignRight",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===me.id){const c=Tn(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function $c(o){const t=o.get(i.ICommandService);return{id:yt.id,type:E.MenuItemType.BUTTON,icon:"AlignTextBothSingle",tooltip:"toolbar.alignJustify",activated$:new _.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===me.id){const c=Tn(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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}const ft=o=>new _.Observable(t=>{const e=o.get(i.IUniverInstanceService),n=o.get(B.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),m=nn(A,(h=(u=g.getBody())==null?void 0:u.paragraphs)!=null?h:[]);let p;if(m.every(f=>{var S;return p||(p=(S=f.bullet)==null?void 0:S.listType),f.bullet&&f.bullet.listType===p})){t.next(p);return}}t.next(void 0)}))});return()=>{s.unsubscribe(),r==null||r.unsubscribe()}});function el(o){return{id:vt.id,type:E.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:es,hoverable:!1,selectable:!1},value$:ft(o)}],icon:"OrderSingle",tooltip:"toolbar.order",hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),disabled$:ee(o),activated$:ft(o).pipe(_.map(t=>t&&t.indexOf("ORDER_LIST")===0))}}function tl(o){return{id:Et.id,type:E.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:ts,hoverable:!1,selectable:!1},value$:ft(o)}],icon:"UnorderSingle",tooltip:"toolbar.unorder",disabled$:ee(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),activated$:ft(o).pipe(_.map(t=>t&&t.indexOf("BULLET_LIST")===0))}}function nl(o){return{id:en.id,type:E.MenuItemType.BUTTON,icon:"TodoList",tooltip:"toolbar.checklist",disabled$:ee(o),hidden$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),activated$:ft(o).pipe(_.map(t=>t&&t.indexOf("CHECK_LIST")===0))}}function ol(o){const t=o.get(i.ICommandService),e=o.get(i.IUniverInstanceService);return{id:mn.id,type:E.MenuItemType.BUTTON,icon:"KeyboardSingle",tooltip:"toolbar.documentFlavor",hidden$:E.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===B.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 rl(o){return{id:ot.id,type:E.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor"}}function sl(o){const t=o.get(i.ICommandService),e=o.get(i.ThemeService);return{id:Qe.id,tooltip:"toolbar.fillColor.main",type:E.MenuItemType.BUTTON_SELECTOR,icon:"PaintBucket",selections:[{label:{name:mo,hoverable:!1,selectable:!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$:E.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function xe(o){var h,g;const t=o.get(i.IUniverInstanceService),e=o.get(B.DocSelectionManagerService),n=o.get(Ce),r=t.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),s=e.getDocRanges(),a=(h=s.find(m=>m.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:{...os(d,a,c),...l}}}function Tn(o){var d,u;const t=o.get(i.IUniverInstanceService),e=o.get(B.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 Is={[E.RibbonStartGroup.FORMAT]:{[Fe.id]:{order:0,menuItemFactory:Qc},[ke.id]:{order:1,menuItemFactory:Lc},[He.id]:{order:2,menuItemFactory:Fc},[Ve.id]:{order:3,menuItemFactory:kc},[Oe.id]:{order:4,menuItemFactory:Hc},[je.id]:{order:5,menuItemFactory:Vc},[Pe.id]:{order:6,menuItemFactory:Wc},[Ue.id]:{order:7,menuItemFactory:jc},[we.id]:{order:8,menuItemFactory:Kc},[Qe.id]:{order:9,menuItemFactory:sl,[ot.id]:{order:0,menuItemFactory:rl}}},[E.RibbonStartGroup.LAYOUT]:{[Ss]:{order:1,menuItemFactory:Xc,[Cn.id]:{order:0,menuItemFactory:Yc}},[Ct.id]:{order:2,menuItemFactory:qc},[Tt.id]:{order:3,menuItemFactory:Jc},[Rt.id]:{order:4,menuItemFactory:Zc},[yt.id]:{order:5,menuItemFactory:$c},[vt.id]:{order:6,menuItemFactory:el},[Et.id]:{order:7,menuItemFactory:tl},[en.id]:{order:8,menuItemFactory:nl},[go.id]:{order:9,menuItemFactory:zc},[mn.id]:{order:10,menuItemFactory:ol}},[E.ContextMenuPosition.MAIN_AREA]:{[E.ContextMenuGroup.FORMAT]:{[pt.name]:{order:0,menuItemFactory:Ec},[gn.id]:{order:1,menuItemFactory:Cc},[hn.id]:{order:2,menuItemFactory:Tc},[Ot.id]:{order:3,menuItemFactory:Rc}},[E.ContextMenuGroup.LAYOUT]:{[Mo.id]:{order:0,menuItemFactory:vc},[ps]:{order:1,menuItemFactory:yc,[Sn.id]:{order:1,menuItemFactory:bc},[In.id]:{order:2,menuItemFactory:Oc},[En.id]:{order:3,menuItemFactory:xc},[vn.id]:{order:4,menuItemFactory:Dc}},[fs]:{order:2,menuItemFactory:Bc,[pn.id]:{order:1,menuItemFactory:Mc},[fn.id]:{order:2,menuItemFactory:_c},[at.id]:{order:3,menuItemFactory:Nc}}}}};var il=Object.getOwnPropertyDescriptor,al=(o,t,e,n)=>{for(var r=n>1?void 0:n?il(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},fe=(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(mo,te.ColorPicker)),this.disposeWithMe(t.register(qr,E.FontFamily)),this.disposeWithMe(t.register(Jr,E.FontFamilyItem)),this.disposeWithMe(t.register(Zr,E.FontSize)),this.disposeWithMe(t.register(ts,Fi)),this.disposeWithMe(t.register(es,Qi)),this.disposeWithMe(t.register("TodoList",Gr))}_initUiParts(){var e,n;const t=this._configService.getConfig(fo);(n=(e=t==null?void 0:t.layout)==null?void 0:e.docContainerConfig)!=null&&n.footer&&this.disposeWithMe(this._uiPartsService.registerComponent(E.BuiltInUIPart.FOOTER,()=>E.connectInjector(Ia,this._injector)))}_initMenus(){this._menuManagerService.mergeMenu(Is)}_initShortCut(){[Zi,$i,ea,ta,na,oa,ia,aa,sa,ra,ca,la,ji].forEach(t=>{this.disposeWithMe(this._shortcutService.registerShortcut(t))})}_init(){this._initCustomComponents(),this._initMenus(),this._initFocusHandler(),this._initCommands(),this._initUiParts(),this._initShortCut()}_initCommands(){[Yr,go,uo].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(i.UniverInstanceType.UNIVER_DOC,t=>{this._injector.get(x.IRenderManagerService).getRenderById(t).with(exports.DocSelectionRenderService).focus()}))}};exports.DocUIController=al([fe(0,i.Inject(i.Injector)),fe(1,i.Inject(E.ComponentManager)),fe(2,i.ICommandService),fe(3,E.ILayoutService),fe(4,E.IMenuManagerService),fe(5,E.IUIPartsService),fe(6,i.IUniverInstanceService),fe(7,E.IShortcutService),fe(8,i.IConfigService)],exports.DocUIController);var cl=Object.getOwnPropertyDescriptor,ll=(o,t,e,n)=>{for(var r=n>1?void 0:n?cl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Un=(o,t)=>(e,n)=>t(e,n,o);const gr=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}=ht(d),m=u+c,p=h+l,f=n.getViewport(he.VIEW_MAIN),S=this._editorService.getEditor(e);if(f==null)return;const{left:I,top:C,right:T,bottom:b}=f.getBounding().viewBound;let v=0,R=0;const y=S?(U=S.params.backScrollOffset)!=null?U:0:100;p<C?v=p-C-y:p>b-g&&(v=p-b+g+y),m<I?R=m-I:m>T-gr&&(R=m-T+gr);const M=f.transViewportScroll2ScrollValue(R,v);f.scrollByBarDeltaValue(M)}_scrollToSelection(){const t=this._textSelectionManagerService.getActiveTextRange();if(t==null)return;const{collapsed:e,startNodePosition:n}=t;e&&this.scrollToNode(n)}};exports.DocBackScrollRenderController=ll([Un(1,i.Inject(B.DocSelectionManagerService)),Un(2,ae),Un(3,i.Inject(B.DocSkeletonManagerService))],exports.DocBackScrollRenderController);var Al=Object.getOwnPropertyDescriptor,dl=(o,t,e,n)=>{for(var r=n>1?void 0:n?Al(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return 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(B.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 x.Viewport(he.VIEW_MAIN,t,{left:0,top:0,bottom:0,right:0,isWheelPreventDefaultX:!0});t.attachControl(),t.onMouseWheel$.subscribeEvent((s,a)=>{const c=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);if((c==null?void 0:c.getUnitId())!==this._context.unitId)return;const l=s;if(l.ctrlKey){const A=Math.abs(l.deltaX);let d=A<40?.2:A<80?.4:.2;d*=l.deltaY>0?-1:1,t.scaleX<1&&(d/=2),t.scaleX+d>4?t.scale(4,4):t.scaleX+d<.1?t.scale(.1,.1):l.preventDefault()}else n.onMouseWheel(l,a)}),new x.ScrollBar(n),t.addLayer(new x.Layer(t,[],wt),new x.Layer(t,[],Dr)),this._addComponent();const r=()=>t.render();this.disposeWithMe(this._context.activated$.subscribe(s=>{s?e.runRenderLoop(r):e.stopRenderLoop(r)})),this._docSelectionRenderService.__attachScrollEvent()}_addComponent(){const{scene:t,unit:e,components:n}=this._context,a={pageMarginLeft:20,pageMarginTop:20},c=new x.Documents(le.MAIN,void 0,a);c.zIndex=Qn;const l=new x.DocBackground(le.BACKGROUND,void 0,a);l.zIndex=Qn,this._context.mainComponent=c,n.set(le.MAIN,c),n.set(le.BACKGROUND,l),t.addObjects([c],wt),t.addObjects([l],xr),this._editorService.getEditor(e.getUnitId())==null&&t.enableLayerCache(wt)}_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(le.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=[B.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 m;const{mainComponent:e,scene:n,unitId:r,components:s}=this._context,a=e,c=s.get(le.BACKGROUND),l=(m=t.getSkeletonData())==null?void 0:m.pages;if(l==null)return;let A=0,d=0;const h=this._context.unit.getSnapshot().documentStyle.documentFlavor;for(let p=0,f=l.length;p<f;p++){const S=l[p];let{pageWidth:I,pageHeight:C}=S;if(h===i.DocumentFlavor.MODERN){const T=ul(S);I=T.pageWidth,C=T.pageHeight}a.pageLayoutType===x.PageLayoutType.VERTICAL?(d+=C,d+=a.pageMarginTop,p===f-1&&(d+=a.pageMarginTop),A=Math.max(A,I)):a.pageLayoutType===x.PageLayoutType.HORIZONTAL&&(A+=I,p!==f-1&&(A+=a.pageMarginLeft),d=Math.max(d,C))}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=dl([ze(1,i.ICommandService),ze(2,i.Inject(exports.DocSelectionRenderService)),ze(3,i.Inject(B.DocSkeletonManagerService)),ze(4,ae),ze(5,x.IRenderManagerService),ze(6,i.IUniverInstanceService)],exports.DocRenderController);function ul(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 No={id:"doc.command.select-all",type:i.CommandType.COMMAND,handler:async o=>{var g;const t=o.get(i.IUniverInstanceService),e=o.get(B.DocSelectionManagerService),n=t.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),r=e.getDocRanges(),s=(g=r.find(m=>m.isActive))!=null?g: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=[],dataStream:d}=l;if(d===`\r
40
+ `)return!0;const u=[];let h=0;for(const m of A){const{startIndex:p,endIndex:f}=m;h!==p&&u.push({startOffset:h,endOffset:p-1,rangeType:i.DOC_RANGE_TYPE.TEXT}),u.push({startOffset:p+3,endOffset:f-5,rangeType:i.DOC_RANGE_TYPE.RECT}),h=f}return h!==l.dataStream.length-2&&u.push({startOffset:h,endOffset:l.dataStream.length-2,rangeType:i.DOC_RANGE_TYPE.TEXT}),e.replaceDocRanges(u,{unitId:c,subUnitId:c},!1),!0}};class xt extends i.RxDisposable{constructor(e){super();D(this,"_previousActiveRange",null);D(this,"_undoMutationParamsCache",[]);D(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 Po={id:"doc.command.ime-input",type:i.CommandType.COMMAND,handler:async(o,t)=>{var w,z,X;const{unitId:e,newText:n,oldTextLen:r,isCompositionEnd:s,isCompositionStart:a}=t,c=o.get(i.ICommandService),l=o.get(x.IRenderManagerService),A=o.get(i.IUniverInstanceService),d=o.get(Ce),u=(w=l.getRenderById(e))==null?void 0:w.with(xt),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:m,segmentId:p}=g,f=h.getSelfOrHeaderFooterModel(p).getBody();if(f==null)return!1;Object.assign(g,g);const{startOffset:I,endOffset:C}=g,T=n.length,b=[{startOffset:I+T,endOffset:I+T,collapsed:!0,style:m}],v={id:B.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:b}},R=d.getDefaultStyle(),y=d.getStyleCache(),M=ro((z=f.customRanges)!=null?z:[],I+r,i.SHEET_EDITOR_UNITS.includes(e)),U=Zt(f,a?C:I+r,R,y,i.SHEET_EDITOR_UNITS.includes(e)),O=so((X=f.customDecorations)!=null?X:[],I+r),P=new i.TextX,N=i.JSONX.getInstance();if(!g.collapsed&&a){const V=i.BuildTextUtils.selection.delete([g],f,0,null,!1);P.push(...V),v.params.textRanges=[{startOffset:I+T,endOffset:I+T,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:M?[{...M,startIndex:0,endIndex:n.length-1}]:[],customDecorations:O.map(V=>({...V,startIndex:0,endIndex:n.length-1}))},len:n.length});const F=Z(h,p);v.params.actions=N.editOp(P.serialize(),F),v.params.noHistory=!s,v.params.isCompositionEnd=s;const k=c.syncExecuteCommand(v.id,v.params);return u.pushUndoRedoMutationParams(k,v.params),!!k}},Wt={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=ua(o,l);return e.syncExecuteCommand(Ae.id,l)?(n.pushUndoRedo({unitID:s,undoMutations:[{id:Ae.id,params:A}],redoMutations:[{id:Ae.id,params:l}]}),!0):!1}},Uo={id:"doc.table.tab-in-table",type:i.CommandType.COMMAND,handler:async(o,t)=>{var m;const{shift:e}=t,n=o.get(B.DocSelectionManagerService),r=n.getDocRanges(),s=o.get(i.ICommandService),c=o.get(i.IUniverInstanceService).getCurrentUniverDocInstance();if(!c)return!1;const l=(m=r.find(p=>p.isActive))!=null?m:r[0],A=c.getUnitId(),d=ce(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=ir(h,l,zn.PREV):g=ir(h,l,zn.NEXT),g){const{startOffset:p,endOffset:f}=g,S=[{startOffset:p,endOffset:f}];return n.replaceDocRanges(S),!0}return e===!1?await s.executeCommand(Oo.id,{position:on.BELLOW}):!0}};var gl=Object.getOwnPropertyDescriptor,hl=(o,t,e,n)=>{for(var r=n>1?void 0:n?gl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},wn=(o,t)=>(e,n)=>t(e,n,o);let Xn=class{constructor(o,t,e){D(this,"_docContainer");D(this,"getComponent",o=>{if(this._docContainer=o,!o.getContentRef().current)throw new Error("container is not ready")});D(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(fo),changeLocale:this.changeLocale,getComponent:this.getComponent}}getContentRef(){return this._docContainer.getContentRef()}UIDidMount(o){if(this._docContainer)return o(this._docContainer)}getDocContainer(){return this._docContainer}};Xn=hl([wn(0,i.Inject(i.LocaleService)),wn(1,i.Inject(i.Injector)),wn(2,i.IConfigService)],Xn);var ml=Object.getOwnPropertyDescriptor,pl=(o,t,e,n)=>{for(var r=n>1?void 0:n?ml(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},fl=(o,t)=>(e,n)=>t(e,n,o);let Kt=class extends i.RxDisposable{constructor(t){super();D(this,"_docContainerController");this._injector=t,this._docContainerController=this._injector.createInstance(Xn)}};Kt=pl([fl(0,i.Inject(i.Injector))],Kt);var Sl=Object.getOwnPropertyDescriptor,Il=(o,t,e,n)=>{for(var r=n>1?void 0:n?Sl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},hr=(o,t)=>(e,n)=>t(e,n,o);let zt=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:Ne.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:jt.id,params:{type:t!=null&&t.shift?mt.decrease:mt.increase}}]},priority:100})),this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:Ne.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(B.DocSkeletonManagerService).getSkeleton();return a==null?!1:!!(n&&r&&Fr(a,n,r)||n&&!r&&n.path.indexOf("cells")>-1)},getMutations(o){const t=o.commandParams;return[{id:Uo.id,params:{shift:!!(t!=null&&t.shift)}}]},priority:99}))}_initListSpaceAutoFormat(){this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:St.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:po.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:jt.id,params:{type:mt.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:Do.id}]},priority:-9999}))}};zt=Il([hr(0,i.Inject(exports.DocAutoFormatService)),hr(1,x.IRenderManagerService)],zt);function El(o){return o.rows[0].cells[0].sections[0].columns[0].lines[0]}function vl(o){const t=o.rows[o.rows.length-1],e=t.cells[t.cells.length-1];return x.getLastLine(e)}function Cl(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 mr(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===x.DocumentSkeletonPageType.CELL?[t]:t.parent.pages;return x.lineIterator(a,c=>{c.st===s+1?n=c:c.ed===r-1&&(e=c)}),{lineBeforeTable:e,lineAfterTable:n}}function Es(o){return o.sections[0].columns[0].lines.length===0}function vs(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 m=g.get(u);if(m!=null&&m.rows.length){s=m.rows.find(p=>!p.isRepeatRow);break}}}}if(s!=null){const l=s.cells[r];return Es(l)?vs(l):l}}function Cs(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 Es(c)?Cs(c):c}}function Tl(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 Rl(o){return o.sections[0].columns[0].lines[0]}function yl(o){const t=x.getLastColumn(o);return t.lines[t.lines.length-1]}var bl=Object.getOwnPropertyDescriptor,Ol=(o,t,e,n)=>{for(var r=n>1?void 0:n?bl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Mt=(o,t)=>(e,n)=>t(e,n,o);let Gt=class extends i.Disposable{constructor(t,e,n,r){super();D(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 C,T,b;const e=this._textSelectionManagerService.getActiveTextRange(),n=this._textSelectionManagerService.getTextRanges(),r=this._univerInstanceService.getCurrentUniverDocInstance();if(r==null)return;const s=(C=this._renderManagerService.getRenderById(r.getUnitId()))==null?void 0:C.with(B.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:m,segmentPage:p}=e;if(n.length>1){let v=Number.POSITIVE_INFINITY,R=Number.NEGATIVE_INFINITY;for(const y of n)v=Math.min(v,y.startOffset),R=Math.max(R,y.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:t===i.Direction.LEFT||t===i.Direction.UP?R:v,endOffset:t===i.Direction.LEFT||t===i.Direction.UP?v:R,style:A}],!1);return}const f=d||u===i.RANGE_DIRECTION.FORWARD?c:l;let S=d||u===i.RANGE_DIRECTION.FORWARD?l:c;const I=(T=r.getSelfOrHeaderFooterModel(h).getBody().dataStream.length)!=null?T:Number.POSITIVE_INFINITY;if(t===i.Direction.LEFT||t===i.Direction.RIGHT){const v=s.findNodeByCharIndex(S-1,h,p),R=s.findNodeByCharIndex(S,h,p);S=t===i.Direction.RIGHT?S+R.count:S-((b=v==null?void 0:v.count)!=null?b:0),S=Math.min(I-2,Math.max(0,S)),this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:S,style:A}],!1),this._scrollToFocusNodePosition(r.getUnitId(),S)}else{const v=s.findNodeByCharIndex(S,h,p),R=a.document.getOffsetConfig(),y=d?g:u===i.RANGE_DIRECTION.FORWARD?m:g,M=this._getTopOrBottomPosition(s,v,y,t===i.Direction.DOWN,!0);if(M==null){const O=t===i.Direction.UP?0:I-2;if(O===S)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:O,style:A}],!1);return}const U=new Ie(R,s).getRangePointData(M,M).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:U.endOffset,style:A}],!1),this._scrollToFocusNodePosition(r.getUnitId(),U.endOffset)}}_handleMoveCursor(t){var I,C,T,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(B.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:m}=e,p=r.getSelfOrHeaderFooterModel(u).getBody();if(p==null)return;const f=(C=p.dataStream.length)!=null?C:Number.POSITIVE_INFINITY,S=(T=r.getCustomRanges())!=null?T:[];if(t===i.Direction.LEFT||t===i.Direction.RIGHT){let v;if(!e.collapsed||n.length>1){let M=Number.POSITIVE_INFINITY,U=Number.NEGATIVE_INFINITY;for(const O of n)M=Math.min(M,O.startOffset),U=Math.max(U,O.endOffset);v=t===i.Direction.LEFT?M:U}else{const M=s.findNodeByCharIndex(c-1,u,m),U=s.findNodeByCharIndex(c,u,m),O=s.findNodeByCharIndex(c+1,u,m);t===i.Direction.LEFT?v=Math.max(0,c-((b=M==null?void 0:M.count)!=null?b:1)):v=Math.min(f-2,l+U.count+((O==null?void 0:O.streamType)===i.DataStreamTreeTokenType.SECTION_BREAK?1:0))}const R=[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(;R.includes(p.dataStream[v]);)v--;else for(;R.includes(p.dataStream[v]);)v++;S.filter(M=>M.wholeEntity&&M.startIndex<v&&M.endIndex>=v).forEach(M=>{t===i.Direction.LEFT?v=Math.min(M.startIndex,v):v=Math.max(M.endIndex+1,v)}),this._textSelectionManagerService.replaceTextRanges([{startOffset:Math.max(0,v),endOffset:Math.max(0,v),style:A}],!1),this._scrollToFocusNodePosition(r.getUnitId(),v)}else{const v=s.findNodeByCharIndex(c,u,m),R=s.findNodeByCharIndex(l,u,m),y=a.document.getOffsetConfig(),M=this._getTopOrBottomPosition(s,t===i.Direction.UP||d?v:R,t===i.Direction.UP||d?h:g,t===i.Direction.DOWN);if(M==null){let O;d?O=t===i.Direction.UP?0:f-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(y,s).getRangePointData(M,M).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 p,f,S,I,C,T,b,v,R,y,M,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===x.DocumentSkeletonPageType.CELL&&n){const O=pr(l,e);if(O)return O}if(e===!0){d=a.lines[A+1];const O=Cl(s,l);if(O){const P=El(O);P&&(d=P)}}else{d=a.lines[A-1];const O=Tl(s,l);if(O){const P=vl(O);P&&(d=P)}}if(d!=null)return d;const u=c.columns.indexOf(a);if(u===-1)return;if(e===!0)d=(p=c.columns[u+1])==null?void 0:p.lines[0];else{const O=(S=(f=c.columns)==null?void 0:f[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=(C=(I=l.sections[h-1])==null?void 0:I.columns[0])==null?void 0:C.lines[0];else{const O=(b=(T=l.sections)==null?void 0:T[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===x.DocumentSkeletonPageType.CELL)return pr(l,e);const g=l.parent;if(g==null)return;const m=g.pages.indexOf(l);if(m!==-1){if(e===!0)d=(y=(R=(v=g.pages[m+1])==null?void 0:v.sections[0])==null?void 0:R.columns[0])==null?void 0:y.lines[0];else{const O=(M=g.pages[m-1])==null?void 0:M.sections;if(O==null)return;const P=(U=O[O.length-1])==null?void 0:U.columns,N=P[P.length-1],F=N==null?void 0:N.lines;d=F[F.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 Br(this._univerInstanceService,this._renderManagerService)}};Gt=Ol([Mt(0,i.IUniverInstanceService),Mt(1,x.IRenderManagerService),Mt(2,i.Inject(B.DocSelectionManagerService)),Mt(3,i.ICommandService)],Gt);function pr(o,t){var n,r;let e=null;if(t===!0){const s=vs(o);if(s)e=Rl(s);else{const a=(n=o.parent)==null?void 0:n.parent,{lineAfterTable:c}=mr(a);c&&(e=c)}}else{const s=Cs(o);if(s)e=yl(s);else{const a=(r=o.parent)==null?void 0:r.parent,{lineBeforeTable:c}=mr(a);c&&(e=c)}}return e}const xl="univer-create",Dl="univer-create-item",Bl="univer-create-label",Ml="univer-create-input",Be={create:xl,createItem:Dl,createLabel:Bl,createInput:Ml},_l=({handleRowColChange:o,tableCreateParams:t})=>{const e=E.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:Be.create,children:[Q.jsxs("div",{className:Be.createItem,children:[Q.jsx("span",{className:Be.createLabel,children:e.t("toolbar.table.rowCount")}),Q.jsx(te.InputNumber,{min:1,max:20,precision:0,value:n,onChange:l=>{c(l,s)},className:Be.createInput})]}),Q.jsxs("div",{className:Be.createItem,children:[Q.jsx("span",{className:Be.createLabel,children:e.t("toolbar.table.colCount")}),Q.jsx(te.InputNumber,{min:1,max:20,precision:0,value:s,onChange:l=>{c(n,l)},className:Be.createInput})]})]})};var Nl=Object.getOwnPropertyDescriptor,Pl=(o,t,e,n)=>{for(var r=n>1?void 0:n?Nl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},fr=(o,t)=>(e,n)=>t(e,n,o);let Xt=class extends i.Disposable{constructor(o,t){super(),this._commandService=o,this._componentManager=t,this._initialize()}_initialize(){this._init(),this._registerCommands(),this._initCustomComponents()}_registerCommands(){[Cn].forEach(o=>this.disposeWithMe(this._commandService.registerCommand(o)))}_initCustomComponents(){const o=this._componentManager;this.disposeWithMe(o.register(ms,_l))}_init(){}};Xt=Pl([fr(0,i.ICommandService),fr(1,i.Inject(E.ComponentManager))],Xt);const Yn=4;var Ul=Object.getOwnPropertyDescriptor,wl=(o,t,e,n)=>{for(var r=n>1?void 0:n?Ul(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},_t=(o,t)=>(e,n)=>t(e,n,o);function Ts(o,t){const e=Sr(o.left,o.top,t),n=Sr(o.right,o.bottom,t);return{left:e.x,top:e.y,right:n.x,bottom:n.y}}function Sr(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 Ir(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 kt=(o,t)=>{const{scene:e,mainComponent:n,engine:r}=t,s=t.with(B.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(),m=x.pxToNum(h.style.width),{top:p,left:f,width:S}=g,I=S/m,{scaleX:C,scaleY:T}=e.getAncestorScale(),b=new Ie(A,s),{borderBoxPointGroup:v}=b.getRangePointData(a,c);return $t(v).map(M=>Ts(M,e)).map(M=>({left:(M.left+d*C)*I+f,right:(M.right+d*C)*I+f,top:(M.top+u*T)*I+p,bottom:(M.bottom+u*T)*I+p}))};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,m={left:d,right:d+h,top:u,bottom:u+g},p=A.getCanvasElement(),f=p.getBoundingClientRect(),S=x.pxToNum(p.style.width),I=Ts(m,l),{top:C,left:T,width:b}=f,v=b/S;return{left:I.left*v+T,right:I.right*v+T,top:I.top*v+C,bottom:I.bottom*v+C}},r=n(),s=new _.BehaviorSubject(r),a=new i.DisposableCollection;a.add(this._commandService.onCommandExecuted(l=>{if(l.id===Ae.id||l.id===B.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=kt(t,e))!=null?c:[],r=new _.BehaviorSubject(n),s=new i.DisposableCollection;s.add(this._commandService.onCommandExecuted(l=>{if((l.id===Ae.id||l.id===B.RichTextEditingMutation.id)&&l.params.unitId===e.unitId){const d=kt(t,e);d&&r.next(d)}}));const a=e.scene.getViewport(he.VIEW_MAIN);return a&&s.add(a.onScrollAfter$.subscribeEvent(()=>{const l=kt(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=wl([_t(0,i.Inject(E.ICanvasPopupService)),_t(1,x.IRenderManagerService),_t(2,i.IUniverInstanceService),_t(3,i.ICommandService)],exports.DocCanvasPopManagerService);var 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=a(r)||r);return r},Fl=(o,t)=>(e,n)=>t(e,n,o);const kl=(o,t,e,n)=>{var h,g,m,p,f;const r=e.findNodePositionByCharIndex(o.startOffset,!0,o.segmentId,n),s=e.getSkeletonData();let a=o.endOffset;if(o.segmentId){const S=(f=Array.from((g=(h=s==null?void 0:s.skeFooters.get(o.segmentId))==null?void 0:h.values())!=null?g:[])[0])!=null?f:Array.from((p=(m=s==null?void 0:s.skeHeaders.get(o.segmentId))==null?void 0:m.values())!=null?p:[])[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 $t(d).map(S=>({top:S.top+l.docsTop-Yn,bottom:S.bottom+l.docsTop+Yn,left:S.left+l.docsLeft,right:S.right+l.docsLeft}))},Hl=(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=$t(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();D(this,"_hoverCustomRanges$",new _.BehaviorSubject([]));D(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))));D(this,"_clickCustomRanges$",new _.Subject);D(this,"clickCustomRanges$",this._clickCustomRanges$.asObservable());D(this,"_hoverBullet$",new _.Subject);D(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))));D(this,"_clickBullet$",new _.Subject);D(this,"clickBullets$",this._clickBullet$.asObservable());D(this,"_customRangeDirty",!0);D(this,"_bulletDirty",!0);D(this,"_customRangeBounds",[]);D(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=x.CURSOR_TYPE.TEXT;this.disposeWithMe(this.hoverCustomRanges$.subscribe(n=>{n.length?(e=this._context.scene.getCursor(),this._context.scene.setCursor(x.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===x.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,segmentId:e},u=kl(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}=Ir(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(m=>m.bullet&&m.bullet.listType.indexOf("CHECK_LIST")===0),a=[],c=this._skeleton.getSkeletonData();if(!c)return a;const l=m=>{var p,f,S;for(const I of m){const C=[...I.sections];if(I.skeTables){const T=Array.from(I.skeTables.values());C.push(...T.map(b=>b.rows.map(v=>v.cells.map(R=>R.sections))).flat(4))}for(const T of C)for(const b of T.columns)for(const v of b.lines)if(v.paragraphStart){const R=s.find(y=>y.startIndex===v.paragraphIndex);if(R){const y=v,M=(S=(f=(p=y==null?void 0:y.divides)==null?void 0:p[0])==null?void 0:f.glyphGroup)==null?void 0:S[0];if(!M)continue;const U=Hl(M,this._documents,this._skeleton,n);if(!U)continue;a.push({rect:U,segmentId:e,segmentPageIndex:n,paragraph:R})}}}return a};if(e){const m=(g=(u=c.skeFooters.get(e))==null?void 0:u.values())!=null?g:(h=c.skeHeaders.get(e))==null?void 0:h.values();return m?l(Array.from(m)):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}=Ir(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=Ll([Fl(1,i.Inject(B.DocSkeletonManagerService))],exports.DocEventManagerService);var Vl=Object.getOwnPropertyDescriptor,jl=(o,t,e,n)=>{for(var r=n>1?void 0:n?Vl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Nt=(o,t)=>(e,n)=>t(e,n,o);let qn=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(tn.id,{index:o.paragraph.startIndex,segmentId:o.segmentId,textRanges:t})})}_initHoverCursor(){this.disposeWithMe(this._docEventManagerService.hoverBullet$.subscribe(o=>{o?this._context.mainComponent.setCursor(x.CURSOR_TYPE.POINTER):this._context.mainComponent.setCursor(x.CURSOR_TYPE.TEXT)}))}_getTransformCoordForDocumentOffset(o,t,e,n){const{documentTransform:r}=o.getOffsetConfig(),s=t.transformVector2SceneCoord(x.Vector2.FromArray([e,n]));if(s)return r.clone().invert().applyPoint(s)}};qn=jl([Nt(1,i.Inject(B.DocSkeletonManagerService)),Nt(2,i.ICommandService),Nt(3,i.Inject(exports.DocEventManagerService)),Nt(4,i.Inject(B.DocSelectionManagerService))],qn);var 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=a(r)||r);return r},At=(o,t)=>(e,n)=>t(e,n,o);let Yt=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(!un(this._contextService))return;t.event.preventDefault();const e=t.event;let n=(c=e.clipboardData)==null?void 0:c.getData(E.HTML_CLIPBOARD_MIME_TYPE);const r=(l=e.clipboardData)==null?void 0:l.getData(E.PLAIN_TEXT_CLIPBOARD_MIME_TYPE),s=[...((A=e.clipboardData)==null?void 0:A.items)||[]].filter(d=>E.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})})}};Yt=Kl([At(1,i.ICommandService),At(2,it),At(3,i.Inject(exports.DocSelectionRenderService)),At(4,i.IContextService),At(5,ae)],Yt);var zl=Object.getOwnPropertyDescriptor,Gl=(o,t,e,n)=>{for(var r=n>1?void 0:n?zl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Er=(o,t)=>(e,n)=>t(e,n,o);const Xl=[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 Jn=class extends i.Disposable{constructor(o,t,e){super(),this._context=o,this._contextMenuService=t,this._commandService=e,Xl.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,E.ContextMenuPosition.MAIN_AREA)});this.disposeWithMe(t)}_initEditChange(){this.disposeWithMe(this._commandService.onCommandExecuted(o=>{o.id===B.RichTextEditingMutation.id&&this._contextMenuService.visible&&this._contextMenuService.hideContextMenu()}))}};Jn=Gl([Er(1,E.IContextMenuService),Er(2,i.ICommandService)],Jn);var Yl=Object.getOwnPropertyDescriptor,ql=(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=a(r)||r);return r},Ge=(o,t)=>(e,n)=>t(e,n,o);let qt=class extends i.Disposable{constructor(t,e,n,r,s,a,c){super();D(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:m}=e.getBoundingClientRect(),p=Math.max(h,g),f=Math.max(u,m);A.transformByState({width:p,height:f}),d==null||d.resize(p,f)}_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()}));const e=new i.DisposableCollection;this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(i.UniverInstanceType.UNIVER_SHEET).subscribe(n=>{if(e.dispose(),!n)return;const r=n.getUnitId(),s=this._renderManagerService.getRenderById(r),a=s==null?void 0:s.engine.getCanvas().getCanvasEle();if(a==null)return;const c=_.fromEvent(a,"mousedown").subscribe(l=>{l.stopPropagation()});e.add(c)})),this.disposeWithMe(()=>e.dispose())}_commandExecutedListener(){const t=[B.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)}}))}};qt=ql([Ge(1,i.IUniverInstanceService),Ge(2,ae),Ge(3,i.ICommandService),Ge(4,i.Inject(exports.DocSelectionRenderService)),Ge(5,i.Inject(B.DocSkeletonManagerService)),Ge(6,x.IRenderManagerService)],qt);var Jl=Object.getOwnPropertyDescriptor,Zl=(o,t,e,n)=>{for(var r=n>1?void 0:n?Jl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Pt=(o,t)=>(e,n)=>t(e,n,o);let Zn=class extends i.Disposable{constructor(t,e,n,r,s){super();D(this,"_previousIMEContent","");D(this,"_isCompositionStart",!0);D(this,"_onStartSubscription");D(this,"_onUpdateSubscription");D(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(Po.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)}};Zn=Zl([Pt(1,i.Inject(exports.DocSelectionRenderService)),Pt(2,i.Inject(xt)),Pt(3,i.Inject(B.DocSkeletonManagerService)),Pt(4,i.ICommandService)],Zn);var $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=a(r)||r);return r},Ut=(o,t)=>(e,n)=>t(e,n,o);let $n=class extends i.Disposable{constructor(t,e,n,r,s){super();D(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 f,S;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=ro((f=d==null?void 0:d.customRanges)!=null?f:[],s.endOffset,i.SHEET_EDITOR_UNITS.includes(e)),m=Zt(d,s.endOffset,u,h,i.SHEET_EDITOR_UNITS.includes(e)),p=so((S=d==null?void 0:d.customDecorations)!=null?S:[],s.endOffset);await this._commandService.executeCommand(cn.id,{unitId:e,body:{dataStream:r,textRuns:m?[{...m,st:0,ed:r.length}]:[],customRanges:g?[{...g,startIndex:0,endIndex:r.length-1}]:[],customDecorations:p.map(I=>({...I,startIndex:0,endIndex:r.length-1}))},range:s,segmentId:l}),r===" "&&await this._commandService.executeCommand(St.id)})}};$n=eA([Ut(1,i.Inject(exports.DocSelectionRenderService)),Ut(2,i.Inject(B.DocSkeletonManagerService)),Ut(3,i.ICommandService),Ut(4,i.Inject(Ce))],$n);class wo extends i.Disposable{constructor(t){super(),this._context=t}calculatePagePosition(){var T,b;const t=Se(this._context),n=(b=(T=this._context.unit.getSettings())==null?void 0:T.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 m=0,p=u,f=0,S=0,I=Number.POSITIVE_INFINITY;h>(l+d*2)*n?(m=h/2-l*n/2,m/=n,f=(h-d*2)/n,I=0):(m=d,f=l+d*2,I=(f-h/n)/2),g>A?S=(g-u*2)/n:S=A+u*2,s.resize(f,S),h<=1&&(m=-1e4,p=-1e4),r.translate(m,p),a.translate(m,p);const C=s.getViewport(he.VIEW_MAIN);return I!==Number.POSITIVE_INFINITY&&C!=null&&C.scrollToViewportPos({viewportScrollX:I}),this}}var tA=Object.getOwnPropertyDescriptor,nA=(o,t,e,n)=>{for(var r=n>1?void 0:n?tA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},vr=(o,t)=>(e,n)=>t(e,n,o);let eo=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===x.TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize),_.throttleTime(0,_.animationFrameScheduler)).subscribe(()=>{this._docPageLayoutService.calculatePagePosition(),this._textSelectionManagerService.refreshSelection()}))}};eo=nA([vr(1,i.Inject(wo)),vr(2,i.Inject(B.DocSelectionManagerService))],eo);var oA=Object.getOwnPropertyDescriptor,rA=(o,t,e,n)=>{for(var r=n>1?void 0:n?oA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Xe=(o,t)=>(e,n)=>t(e,n,o);let to=class extends i.Disposable{constructor(t,e,n,r,s,a,c){super();D(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=x.CURSOR_TYPE.TEXT)})),this.disposeWithMe(n.onPointerLeave$.subscribeEvent(()=>{n.cursor=x.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=x.PageLayoutType.VERTICAL,pageMarginLeft:g,pageMarginTop:m}=n.getOffsetConfig(),{editArea:p}=l.findEditAreaByCoord(u,h,g,m),f=this._docSkeletonManagerService.getViewModel(),S=f.getEditArea();S!==x.DocumentEditArea.BODY&&p!==x.DocumentEditArea.BODY&&p!==S&&f.setEditArea(p)}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(x.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=[Ae.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=Xr(s);this._docSelectionManagerService.replaceDocRanges([{startOffset:a,endOffset:a}],{unitId:e,subUnitId:e},!1)}}))}};to=rA([Xe(1,i.ICommandService),Xe(2,ae),Xe(3,i.IUniverInstanceService),Xe(4,i.Inject(exports.DocSelectionRenderService)),Xe(5,i.Inject(B.DocSkeletonManagerService)),Xe(6,i.Inject(B.DocSelectionManagerService))],to);var sA=Object.getOwnPropertyDescriptor,iA=(o,t,e,n)=>{for(var r=n>1?void 0:n?sA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Me=(o,t)=>(e,n)=>t(e,n,o);let no=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(Wt.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=[Ae.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===mn.id&&this._commandService.executeCommand(Wt.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()}};no=iA([Me(1,i.IContextService),Me(2,i.Inject(B.DocSkeletonManagerService)),Me(3,i.IUniverInstanceService),Me(4,i.ICommandService),Me(5,i.Inject(B.DocSelectionManagerService)),Me(6,ae),Me(7,i.Inject(wo))],no);var 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=a(r)||r);return r},dt=(o,t)=>(e,n)=>t(e,n,o);const Cr=300;exports.DocStateChangeManagerService=class extends i.RxDisposable{constructor(e,n,r,s,a){super();D(this,"_docStateChange$",new _.BehaviorSubject(null));D(this,"docStateChange$",this._docStateChange$.asObservable());D(this,"_historyStateCache",new Map);D(this,"_changeStateCache",new Map);D(this,"_historyTimer",null);D(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(xt);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)},Cr)):(this._changeStateCacheTimer&&clearTimeout(this._changeStateCacheTimer),this._changeStateCacheTimer=setTimeout(()=>{A(s)},Cr)):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((p,f)=>i.JSONX.compose(p,f.redoState.actions),null),textRanges:u.redoState.textRanges},g={unitId:e,actions:n.reverse().reduce((p,f)=>i.JSONX.compose(p,f.undoState.actions),null),textRanges:d.undoState.textRanges},m={commandId:s,unitId:e,trigger:a,redoState:h,undoState:g,segmentId:c,noHistory:l,debounce:A};n.length=0,this._docStateChange$.next(m)}};exports.DocStateChangeManagerService=cA([dt(0,i.Inject(i.IUndoRedoService)),dt(1,i.ICommandService),dt(2,i.IUniverInstanceService),dt(3,i.Inject(B.DocStateEmitService)),dt(4,x.IRenderManagerService)],exports.DocStateChangeManagerService);var lA=Object.getOwnPropertyDescriptor,AA=(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=a(r)||r);return r},Tr=(o,t)=>(e,n)=>t(e,n,o);const Rr="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(Rr),s.engine.getCanvas().getContext().setId(Rr))}),this._renderManagerService.has(e)||this._createRenderWithId(e)}_createRenderWithId(t){this._renderManagerService.createRender(t)}_disposeRenderer(t){const e=t.getUnitId();this._renderManagerService.removeRender(e)}};exports.DocsRenderService=AA([Tr(0,i.IUniverInstanceService),Tr(1,x.IRenderManagerService)],exports.DocsRenderService);class Rs extends i.Disposable{constructor(){super(...arguments);D(this,"_currentSelectorId");D(this,"_selectionChange$",new _.Subject);D(this,"selectionChange$",this._selectionChange$.asObservable());D(this,"_openSelector$",new _.Subject);D(this,"openSelector$",this._openSelector$.asObservable());D(this,"_selectorModalVisible$",new _.BehaviorSubject(!1));D(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 ys=i.createIdentifier("univer.range-selector.service"),dA={id:Je.id,preconditions:Vi,binding:E.KeyCode.ENTER},uA={id:Ot.id,preconditions:$,binding:E.KeyCode.BACKSPACE},gA={id:Co.id,preconditions:$,binding:E.KeyCode.DELETE},hA={id:Ee.id,binding:E.KeyCode.ARROW_UP,preconditions:$,staticParameters:{direction:i.Direction.UP}},mA={id:Ee.id,binding:E.KeyCode.ARROW_DOWN,preconditions:$,staticParameters:{direction:i.Direction.DOWN}},pA={id:Ee.id,binding:E.KeyCode.ARROW_LEFT,preconditions:$,staticParameters:{direction:i.Direction.LEFT}},fA={id:Ee.id,binding:E.KeyCode.ARROW_RIGHT,preconditions:$,staticParameters:{direction:i.Direction.RIGHT}},SA={id:ve.id,binding:E.KeyCode.ARROW_UP|E.MetaKeys.SHIFT,preconditions:$,staticParameters:{direction:i.Direction.UP}},IA={id:ve.id,binding:E.KeyCode.ARROW_DOWN|E.MetaKeys.SHIFT,preconditions:$,staticParameters:{direction:i.Direction.DOWN}},EA={id:ve.id,binding:E.KeyCode.ARROW_LEFT|E.MetaKeys.SHIFT,preconditions:$,staticParameters:{direction:i.Direction.LEFT}},vA={id:ve.id,binding:E.KeyCode.ARROW_RIGHT|E.MetaKeys.SHIFT,preconditions:$,staticParameters:{direction:i.Direction.RIGHT}},CA={id:No.id,binding:E.KeyCode.A|E.MetaKeys.CTRL_COMMAND,preconditions:o=>o.getContextValue(i.FOCUSING_UNIVER_EDITOR)&&(o.getContextValue(i.FOCUSING_DOC)||o.getContextValue(i.EDITOR_ACTIVATED))};var TA=Object.defineProperty,RA=Object.getOwnPropertyDescriptor,yA=(o,t,e)=>t in o?TA(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,bA=(o,t,e,n)=>{for(var r=n>1?void 0:n?RA(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},ut=(o,t)=>(e,n)=>t(e,n,o),OA=(o,t,e)=>yA(o,t+"",e);exports.UniverDocsUIPlugin=class extends i.Plugin{constructor(t=sr,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({},sr,this._config);c&&this._configService.setConfig("menu",c,{merge:!0}),this._configService.setConfig(fo,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,[[zt],[Gt],[et],[Xt],[exports.DocUIController]])}_initCommand(){[Ot,Co,Fe,ke,He,Ve,Oe,je,Pe,Ue,we,ot,Qe,Te,Do,cn,Ze,ln,vo,An,Ae,vt,Et,rt,Ct,Tt,Rt,me,yt,Bo,Oo,Sn,In,hs,En,vn,pn,fn,at,ho,Uo,Ne,St,Je,jt,It,en,tn,po,Po,mn,pe,Eo,Le,Pr,io,Ur,Wt,No,Mo,Ee,ve,Qr].forEach(t=>{this._commandService.registerCommand(t)}),[pt,gn,hn].forEach(t=>this.disposeWithMe(this._commandService.registerMultipleCommand(t)))}_initializeShortcut(){[hA,mA,fA,pA,SA,IA,EA,vA,CA,uA,gA,dA,Wi].forEach(t=>{this._injector.get(E.IShortcutService).registerShortcut(t)})}_initDependencies(t){i.mergeOverrideWithDependencies([[Yt],[qt],[exports.DocUIController],[zt],[Xt],[Gt],[Kt],[et],[ae,{useClass:exports.EditorService}],[ys,{useClass:Rs}],[it,{useClass:Gn}],[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(ae);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(Kt)}_initRenderBasics(){[[B.DocSkeletonManagerService],[exports.DocSelectionRenderService],[B.DocInterceptorService],[wo],[xt],[exports.DocRenderController],[no]].forEach(t=>{this._renderManagerSrv.registerRenderModule(i.UniverInstanceType.UNIVER_DOC,t)})}_initRenderModules(){[[exports.DocEventManagerService],[exports.DocBackScrollRenderController],[to],[Wn],[eo],[Jn],[qn],[Yt],[$n],[Zn],[qt]].forEach(t=>{this._renderManagerSrv.registerRenderModule(i.UniverInstanceType.UNIVER_DOC,t)})}};OA(exports.UniverDocsUIPlugin,"pluginName",Or);exports.UniverDocsUIPlugin=bA([i.DependentOn(x.UniverRenderEnginePlugin),ut(1,i.Inject(i.Injector)),ut(2,x.IRenderManagerService),ut(3,i.ICommandService),ut(4,i.ILogService),ut(5,i.IConfigService)],exports.UniverDocsUIPlugin);exports.AfterSpaceCommand=St;exports.AlignCenterCommand=Tt;exports.AlignJustifyCommand=yt;exports.AlignLeftCommand=Ct;exports.AlignOperationCommand=me;exports.AlignRightCommand=Rt;exports.BreakLineCommand=Do;exports.BulletListCommand=Et;exports.ChangeListNestingLevelCommand=jt;exports.ChangeListNestingLevelType=mt;exports.ChangeListTypeCommand=It;exports.CheckListCommand=en;exports.CoverContentCommand=Ur;exports.CreateDocTableCommand=Bo;exports.CutContentCommand=Le;exports.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX=xr;exports.DOCS_COMPONENT_DEFAULT_Z_INDEX=Qn;exports.DOCS_COMPONENT_HEADER_LAYER_INDEX=Dr;exports.DOCS_COMPONENT_MAIN_LAYER_INDEX=wt;exports.DOCS_VIEW_KEY=le;exports.DOC_UI_PLUGIN_NAME=Or;exports.DOC_VERTICAL_PADDING=Yn;exports.DefaultDocContainerConfig=br;exports.DefaultToolbarConfig=yr;exports.DeleteCommand=Ze;exports.DeleteCustomBlockCommand=ln;exports.DeleteLeftCommand=Ot;exports.DeleteRightCommand=Co;exports.DocCopyCommand=pt;exports.DocCreateTableOperation=Cn;exports.DocCutCommand=gn;exports.DocIMEInputManagerService=xt;exports.DocPasteCommand=hn;exports.DocSelectAllCommand=No;exports.DocTableDeleteColumnsCommand=fn;exports.DocTableDeleteRowsCommand=pn;exports.DocTableDeleteTableCommand=at;exports.DocTableInsertColumnCommand=hs;exports.DocTableInsertColumnLeftCommand=En;exports.DocTableInsertColumnRightCommand=vn;exports.DocTableInsertRowAboveCommand=Sn;exports.DocTableInsertRowBellowCommand=In;exports.DocTableInsertRowCommand=Oo;exports.DocTableTabCommand=Uo;exports.DocsUIMenuSchema=Is;exports.Editor=Hr;exports.EditorInsertTextCommandId=cs;exports.EnterCommand=Je;exports.IDocClipboardService=it;exports.IEditorService=ae;exports.IMEInputCommand=Po;exports.IRangeSelectorService=ys;exports.InnerPasteCommand=Eo;exports.InsertCommand=cn;exports.ListOperationCommand=rt;exports.MergeTwoParagraphCommand=An;exports.MoveCursorOperation=Ee;exports.MoveSelectionOperation=ve;exports.NORMAL_TEXT_SELECTION_PLUGIN_NAME=Ps;exports.NodePositionConvertToCursor=Ie;exports.NodePositionConvertToRectRange=lo;exports.OrderListCommand=vt;exports.PastePluginLark=As;exports.PastePluginUniver=us;exports.PastePluginWord=gs;exports.QuickListCommand=po;exports.RangeSelectorService=Rs;exports.RectRange=Ao;exports.ReplaceContentCommand=Pr;exports.ReplaceSnapshotCommand=io;exports.ReplaceTextRunsCommand=Qr;exports.ResetInlineFormatTextBackgroundColorCommand=ot;exports.RichTextEditor=Ai;exports.SetDocZoomRatioCommand=Wt;exports.SetDocZoomRatioOperation=Ae;exports.SetInlineFormatBoldCommand=Fe;exports.SetInlineFormatCommand=Te;exports.SetInlineFormatFontFamilyCommand=Ue;exports.SetInlineFormatFontSizeCommand=Pe;exports.SetInlineFormatItalicCommand=ke;exports.SetInlineFormatStrikethroughCommand=Ve;exports.SetInlineFormatSubscriptCommand=Oe;exports.SetInlineFormatSuperscriptCommand=je;exports.SetInlineFormatTextBackgroundColorCommand=Qe;exports.SetInlineFormatTextColorCommand=we;exports.SetInlineFormatUnderlineCommand=He;exports.TEXT_RANGE_LAYER_INDEX=Ht;exports.TabCommand=Ne;exports.TextRange=_e;exports.ToggleCheckListCommand=tn;exports.UpdateCommand=vo;exports.VIEWPORT_KEY=he;exports.addCustomDecorationBySelectionFactory=ws;exports.addCustomDecorationFactory=Mr;exports.calcDocRangePositions=kt;exports.convertPositionsToRectRanges=Lt;exports.deleteCustomDecorationFactory=Qs;exports.docDrawingPositionToTransform=Fs;exports.genTableSource=Io;exports.generateParagraphs=xo;exports.getAnchorBounding=ht;exports.getCanvasOffsetByEngine=kr;exports.getCommandSkeleton=ce;exports.getCursorWhenDelete=dn;exports.getCustomBlockIdsInSelections=is;exports.getCutActionsFromDocRanges=as;exports.getDocObject=Br;exports.getDocObjectById=Us;exports.getEmptyTableCell=rn;exports.getEmptyTableRow=sn;exports.getLineBounding=$t;exports.getOneTextSelectionRange=Fn;exports.getParagraphsInRange=nn;exports.getParagraphsInRanges=st;exports.getRichTextEditPath=Z;exports.getTableColumn=an;exports.hasParagraphInTable=Ls;exports.isInSameTableCell=co;exports.isValidRectRange=Lr;exports.neoGetDocObject=Se;exports.transformToDocDrawingPosition=ks;exports.useKeyboardEvent=_r;exports.useResize=Nr;exports.whenDocAndEditorFocused=$;
package/lib/es/index.js CHANGED
@@ -8648,34 +8648,38 @@ const va = {
8648
8648
  id: "doc.command.select-all",
8649
8649
  type: w.COMMAND,
8650
8650
  handler: async (n) => {
8651
- var h;
8652
- const e = n.get(N), t = n.get(G), o = e.getCurrentUnitForType(_.UNIVER_DOC), s = t.getDocRanges(), r = (h = s.find((u) => u.isActive)) != null ? h : s[0];
8651
+ var u;
8652
+ const e = n.get(N), t = n.get(G), o = e.getCurrentUnitForType(_.UNIVER_DOC), s = t.getDocRanges(), r = (u = s.find((g) => g.isActive)) != null ? u : s[0];
8653
8653
  if (o == null || r == null)
8654
8654
  return !1;
8655
8655
  const { segmentId: i } = r, a = o.getUnitId(), c = o.getSelfOrHeaderFooterModel(i).getSnapshot().body;
8656
8656
  if (c == null)
8657
8657
  return !1;
8658
- const { tables: A = [] } = c, l = [];
8659
- let d = 0;
8660
- for (const u of A) {
8661
- const { startIndex: g, endIndex: f } = u;
8662
- d !== g && l.push({
8663
- startOffset: d,
8664
- endOffset: g - 1,
8658
+ const { tables: A = [], dataStream: l } = c;
8659
+ if (l === `\r
8660
+ `)
8661
+ return !0;
8662
+ const d = [];
8663
+ let h = 0;
8664
+ for (const g of A) {
8665
+ const { startIndex: f, endIndex: p } = g;
8666
+ h !== f && d.push({
8667
+ startOffset: h,
8668
+ endOffset: f - 1,
8665
8669
  rangeType: Ye.TEXT
8666
- }), l.push({
8667
- startOffset: g + 3,
8670
+ }), d.push({
8671
+ startOffset: f + 3,
8668
8672
  // 3 is TABLE_START, ROW_START, CELL_START.
8669
- endOffset: f - 5,
8673
+ endOffset: p - 5,
8670
8674
  // 4 is CELL_END, ROW_END, TABLE_END AND \n.
8671
8675
  rangeType: Ye.RECT
8672
- }), d = f;
8676
+ }), h = p;
8673
8677
  }
8674
- return d !== c.dataStream.length - 2 && l.push({
8675
- startOffset: d,
8678
+ return h !== c.dataStream.length - 2 && d.push({
8679
+ startOffset: h,
8676
8680
  endOffset: c.dataStream.length - 2,
8677
8681
  rangeType: Ye.TEXT
8678
- }), t.replaceDocRanges(l, {
8682
+ }), t.replaceDocRanges(d, {
8679
8683
  unitId: a,
8680
8684
  subUnitId: a
8681
8685
  }, !1), !0;
package/lib/umd/index.js CHANGED
@@ -36,4 +36,5 @@ ${a.DataStreamTreeTokenType.TABLE_CELL_END}`;break}}}_processBeforeLink(t,e){ret
36
36
  `,children:t.map(v=>L.jsx(ne.Tooltip,{title:v.label,placement:"bottom",children:L.jsx("span",{className:ne.clsx(q.paragraphSettingIconListItem,{[q.paragraphSettingIconListActive]:n===v.value}),onClick:()=>i(v.value),children:v.icon})},v.value))}),L.jsx("div",{className:q.paragraphSettingTitle,children:o.t("doc.paragraphSetting.indentation")}),L.jsxs("div",{children:[L.jsxs("div",{className:q.paragraphSettingFlexCol,children:[L.jsxs("div",{className:q.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.left"),"(px)"]}),L.jsx(Ve,{className:q.paragraphSettingMtBase,value:s,onChange:v=>r(v!=null?v:0)})]}),L.jsxs("div",{className:q.paragraphSettingFlexCol,children:[L.jsxs("div",{className:q.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.right"),"(px)"]}),L.jsx(Ve,{className:q.paragraphSettingMtBase,value:c,onChange:v=>A(v!=null?v:0)})]}),L.jsxs("div",{className:q.paragraphSettingFlexCol,children:[L.jsxs("div",{className:q.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.firstLine"),"(px)"]}),L.jsx(Ve,{className:q.paragraphSettingMtBase,value:l,onChange:v=>d(v!=null?v:0)})]}),L.jsxs("div",{className:q.paragraphSettingFlexCol,children:[L.jsxs("div",{className:q.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.hanging"),"(px)"]}),L.jsx(Ve,{className:q.paragraphSettingMtBase,value:u,onChange:v=>g(v!=null?v:0)})]})]}),L.jsx("div",{className:q.paragraphSettingTitle,children:o.t("doc.paragraphSetting.spacing")}),L.jsxs("div",{children:[L.jsxs("div",{className:q.paragraphSettingFlexCol,children:[L.jsxs("div",{className:q.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.before"),"(px)"]}),L.jsx(Ve,{className:q.paragraphSettingMtBase,value:h,onChange:v=>m(v!=null?v:0)})]}),L.jsxs("div",{className:q.paragraphSettingFlexCol,children:[L.jsxs("div",{className:q.paragraphSettingLabel,children:[o.t("doc.paragraphSetting.after"),"(px)"]}),L.jsx(Ve,{className:q.paragraphSettingMtBase,value:f,onChange:v=>p(v!=null?v:0)})]}),L.jsxs("div",{className:q.paragraphSettingFlexCol,children:[L.jsx("div",{className:q.paragraphSettingLabel,children:o.t("doc.paragraphSetting.lineSpace")}),L.jsxs("div",{className:`
37
37
  ${q.paragraphSettingMtBase}
38
38
  ${q.paragraphSettingSpaceLine}
39
- `,style:{width:162},children:[L.jsx(ne.Select,{value:`${C}`,options:[{label:o.t("doc.paragraphSetting.multiSpace"),value:`${a.SpacingRule.AUTO}`},{label:o.t("doc.paragraphSetting.fixedValue"),value:`${a.SpacingRule.AT_LEAST}`}],onChange:v=>y(Number(v))}),L.jsx(Ve,{...R,value:S,onChange:v=>I(v!=null?v:0)})]})]})]})]})}const kr=(o,t)=>t.length===o.length&&o.some(e=>t.some(n=>n.startOffset===e.startOffset&&n.endOffset===e.endOffset));function Hr(){const o=E.useDependency(a.ICommandService),t=E.useDependency(a.LocaleService),e=E.useObservable(t.currentLocale$),[n,i]=F.useState(""),s=F.useMemo(()=>a.debounce(()=>i(a.generateRandomId(4)),300),[]),r=F.useRef([]);return F.useEffect(()=>{const c=o.onCommandExecuted(A=>{if(x.SetTextSelectionsOperation.id===A.id){const l=A.params.ranges;kr(l,r.current)||i(a.generateRandomId(4)),r.current=l}x.RichTextEditingMutation.id===A.id&&A.params.trigger!==me.id&&s()});return()=>c.dispose()},[s]),F.useEffect(()=>{i(a.generateRandomId(4))},[e]),F.useEffect(()=>()=>s.cancel(),[s]),L.jsx(Fr,{},n)}var Vr=Object.getOwnPropertyDescriptor,Wr=(o,t,e,n)=>{for(var i=n>1?void 0:n?Vr(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Io=(o,t)=>(e,n)=>t(e,n,o);const ts="doc_ui_paragraph-setting-panel";let st=class extends a.Disposable{constructor(t,e,n){super();M(this,"_id");this._commandService=t,this._componentManager=e,this._sidebarService=n,this._init()}_init(){this.disposeWithMe(this._componentManager.register(ts,Hr))}openPanel(){const t={header:{title:"doc.slider.paragraphSetting"},id:this._id,children:{label:ts},width:300};this._sidebarService.open(t)}closePanel(){this._sidebarService.close(this._id)}};st=Wr([Io(0,a.ICommandService),Io(1,a.Inject(E.ComponentManager)),Io(2,a.Inject(E.ISidebarService))],st);const Eo={id:"sidebar.operation.doc-paragraph-setting-panel",type:a.CommandType.OPERATION,handler:o=>(o.get(st).openPanel(),!0)},vo=o=>{const t=o.get(x.DocSelectionManagerService);return new N.Observable(e=>{const n=t.textSelection$.subscribe(()=>{t.getDocRanges().some(r=>r.collapsed===!1||r.rangeType===a.DOC_RANGE_TYPE.RECT)?e.next(!1):e.next(!0)});return()=>n.unsubscribe()})};function Kr(o){if(o.length<2)return!0;const t=o.map(e=>e.tableId);return t.every(e=>e===t[0])}function ns(o,t,e){var s;const n=t.getRectRanges(),i=t.getActiveTextRange();if(n&&n.length&&Kr(n)&&i==null){o.next(!1);return}if(i&&(n==null||n.length===0)){const{segmentId:r,startOffset:c,endOffset:A}=i,l=e.getCurrentUniverDocInstance(),d=(s=l==null?void 0:l.getSelfOrHeaderFooterModel(r).getBody())==null?void 0:s.tables;if(d&&d.length&&d.some(u=>{const{startIndex:g,endIndex:h}=u;return c>g&&c<h||A>g&&A<h})){o.next(!1);return}}o.next(!0)}const ye=o=>{const t=o.get(x.DocSelectionManagerService),e=o.get(a.IUniverInstanceService);return new N.Observable(n=>{const i=t.textSelection$.subscribe(()=>{ns(n,t,e)});return ns(n,t,e),()=>i.unsubscribe()})},zr=o=>({id:yt.name,commandId:yt.id,type:E.MenuItemType.BUTTON,icon:"Copy",title:"rightClick.copy",disabled$:vo(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}),jr=o=>({id:Eo.id,type:E.MenuItemType.BUTTON,icon:"MenuSingle24",title:"doc.menu.paragraphSetting",hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}),Gr=o=>({id:$t.id,type:E.MenuItemType.BUTTON,icon:"Copy",title:"rightClick.cut",disabled$:vo(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}),Xr=o=>({id:en.id,type:E.MenuItemType.BUTTON,icon:"PasteSpecial",title:"rightClick.paste",hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}),Yr=o=>({id:Ct.id,type:E.MenuItemType.BUTTON,icon:"PasteSpecial",title:"rightClick.delete",disabled$:vo(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}),os="doc.menu.table-insert";function qr(o){return{id:os,type:E.MenuItemType.SUBITEMS,title:"table.insert",icon:"Insert",hidden$:N.combineLatest(E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC),ye(o),(t,e)=>t||e)}}function Jr(o){return{id:sn.id,type:E.MenuItemType.BUTTON,title:"table.insertRowAbove",icon:"InsertRowAbove",disabled$:ye(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function Zr(o){return{id:an.id,type:E.MenuItemType.BUTTON,title:"table.insertRowBelow",icon:"InsertRowBelow",disabled$:ye(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function $r(o){return{id:rn.id,type:E.MenuItemType.BUTTON,title:"table.insertColumnLeft",icon:"LeftInsertColumn",disabled$:ye(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function ec(o){return{id:cn.id,type:E.MenuItemType.BUTTON,title:"table.insertColumnRight",icon:"RightInsertColumn",disabled$:ye(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}const is="doc.menu.table-delete";function tc(o){return{id:is,type:E.MenuItemType.SUBITEMS,title:"table.delete",icon:"Reduce",hidden$:N.combineLatest(E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC),ye(o),(t,e)=>t||e)}}function nc(o){return{id:nn.id,type:E.MenuItemType.BUTTON,title:"table.deleteRows",icon:"DeleteRow",disabled$:ye(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function oc(o){return{id:on.id,type:E.MenuItemType.BUTTON,title:"table.deleteColumns",icon:"DeleteColumn",disabled$:ye(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function ic(o){return{id:it.id,type:E.MenuItemType.BUTTON,title:"table.deleteTable",icon:"GridSingle",disabled$:ye(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function sc(o){const t=o.get(a.IUniverInstanceService),e=o.get(B.IRenderManagerService);return new N.Observable(n=>{const i=t.focused$.subscribe(s=>{if(s==null||t.getUnitType(s)!==a.UniverInstanceType.UNIVER_DOC)return n.next(!0);const c=e.getRenderById(s);if(c==null)return n.next(!0);c.with(x.DocSkeletonManagerService).getViewModel().editAreaChange$.subscribe(l=>{n.next(l===B.DocumentEditArea.HEADER||l===B.DocumentEditArea.FOOTER)})});return()=>i.unsubscribe()})}function ac(o){const t=o.get(a.IUniverInstanceService),e=o.get(a.ICommandService);return new N.Observable(n=>{const i=e.onCommandExecuted(A=>{if(A.id===x.RichTextEditingMutation.id){const{unitId:l}=A.params,d=t.getUnit(l);if(d==null){n.next(!0);return}const{documentStyle:u}=d.getSnapshot();n.next((u==null?void 0:u.documentFlavor)!==a.DocumentFlavor.TRADITIONAL)}}),s=t.focused$.subscribe(A=>{if(A==null)return n.next(!0);const l=t.getUniverDocInstance(A),d=l==null?void 0:l.getSnapshot().documentStyle.documentFlavor;n.next(d!==a.DocumentFlavor.TRADITIONAL)}),r=t.getCurrentUniverDocInstance();if(r==null)return n.next(!0);const c=r==null?void 0:r.getSnapshot().documentStyle.documentFlavor;return n.next(c!==a.DocumentFlavor.TRADITIONAL),()=>{i.dispose(),s.unsubscribe()}})}function rc(o){const t=o.get(x.DocSelectionManagerService),e=o.get(a.IUniverInstanceService);return new N.Observable(n=>{const i=t.textSelection$.subscribe(s=>{if(s==null){n.next(!0);return}const{textRanges:r}=s;if(r.length!==1){n.next(!0);return}const c=r[0],{collapsed:A,startNodePosition:l,startOffset:d}=c;if(!A||d==null){n.next(!0);return}const u=e.getCurrentUniverDocInstance();if(u==null){n.next(!0);return}const g=re(o,u.getUnitId());if(g==null){n.next(!0);return}if(g.getViewModel().getCustomRangeRaw(d)){n.next(!0);return}if(l!=null){const{path:f}=l;if(f.indexOf("cells")!==-1){n.next(!0);return}}n.next(!1)});return()=>i.unsubscribe()})}function te(o){const t=o.get(x.DocSelectionManagerService);return new N.Observable(e=>{const n=t.textSelection$.subscribe(i=>{if(i==null){e.next(!0);return}const{textRanges:s,rectRanges:r}=i;if(s.length===0&&r.length===0){e.next(!0);return}e.next(!1)});return()=>n.unsubscribe()})}function cc(o){const t=o.get(a.ICommandService);return{id:_e.id,type:E.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",activated$:new N.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===x.SetTextSelectionsOperation.id||s===Te.id){const c=De(o);if(c==null){e.next(!1);return}const A=(r=c.ts)==null?void 0:r.bl;e.next(A===a.BooleanNumber.TRUE)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function Ac(o){const t=o.get(a.ICommandService);return{id:Ne.id,type:E.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",activated$:new N.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===x.SetTextSelectionsOperation.id||s===Te.id){const c=De(o);if(c==null){e.next(!1);return}const A=(r=c.ts)==null?void 0:r.it;e.next(A===a.BooleanNumber.TRUE)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function lc(o){const t=o.get(a.ICommandService);return{id:Pe.id,type:E.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",activated$:new N.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===x.SetTextSelectionsOperation.id||s===Te.id){const c=De(o);if(c==null){e.next(!1);return}const A=(r=c.ts)==null?void 0:r.ul;e.next((A==null?void 0:A.s)===a.BooleanNumber.TRUE)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function dc(o){const t=o.get(a.ICommandService);return{id:Ue.id,type:E.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",activated$:new N.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===x.SetTextSelectionsOperation.id||s===Te.id){const c=De(o);if(c==null){e.next(!1);return}const A=(r=c.ts)==null?void 0:r.st;e.next((A==null?void 0:A.s)===a.BooleanNumber.TRUE)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function uc(o){const t=o.get(a.ICommandService);return{id:Re.id,type:E.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",activated$:new N.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===x.SetTextSelectionsOperation.id||s===Te.id){const c=De(o);if(c==null){e.next(!1);return}const A=(r=c.ts)==null?void 0:r.va;e.next(A===a.BaselineOffset.SUBSCRIPT)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function hc(o){const t=o.get(a.ICommandService);return{id:we.id,type:E.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",activated$:new N.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===x.SetTextSelectionsOperation.id||s===Te.id){const c=De(o);if(c==null){e.next(!1);return}const A=(r=c.ts)==null?void 0:r.va;e.next(A===a.BaselineOffset.SUPERSCRIPT)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function gc(o){const t=o.get(a.ICommandService);return{id:Le.id,tooltip:"toolbar.font",type:E.MenuItemType.SELECTOR,label:Si,selections:E.FONT_FAMILY_LIST.map(e=>({label:{name:Ii},value:e.value})),value$:new N.Observable(e=>{const n=a.DEFAULT_STYLES.ff,i=t.onCommandExecuted(s=>{var c;const r=s.id;if(r===x.SetTextSelectionsOperation.id||r===Le.id){const A=De(o);if(A==null){e.next(n);return}const l=(c=A.ts)==null?void 0:c.ff;e.next(l!=null?l:n)}});return e.next(n),i.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function mc(o){const t=o.get(a.ICommandService);return{id:Qe.id,type:E.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Ei,props:{min:1,max:400}},selections:E.FONT_SIZE_LIST,value$:new N.Observable(e=>{const n=a.DEFAULT_STYLES.fs,i=t.onCommandExecuted(s=>{var c;const r=s.id;if(r===x.SetTextSelectionsOperation.id||r===Qe.id){const A=De(o);if(A==null){e.next(n);return}const l=(c=A.ts)==null?void 0:c.fs;e.next(l!=null?l:n)}});return e.next(n),i.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function fc(o){const t=o.get(a.ICommandService),e=o.get(a.ThemeService);return{id:Fe.id,icon:"FontColor",tooltip:"toolbar.textColor.main",type:E.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:Xn,hoverable:!1,selectable:!1}}],value$:new N.Observable(n=>{const i=e.getCurrentTheme().textColor,s=t.onCommandExecuted(r=>{if(r.id===Fe.id){const c=r.params.value;n.next(c!=null?c:i)}});return n.next(i),s.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function pc(o){return{id:jn.id,type:E.MenuItemType.BUTTON,icon:"HeaderFooterSingle",tooltip:"toolbar.headerFooter",hidden$:N.combineLatest(E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY),ac(o),(t,e)=>t||e)}}const Sc="GridSingle",ss="doc.menu.table";function Ic(o){return{id:ss,type:E.MenuItemType.SUBITEMS,icon:Sc,tooltip:"toolbar.table.main",disabled$:rc(o),hidden$:N.combineLatest(E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY),sc(o),(t,e)=>t||e)}}function Ec(o){return{id:An.id,title:"toolbar.table.insert",type:E.MenuItemType.BUTTON,hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function vc(o){const t=o.get(a.ICommandService);return{id:pt.id,type:E.MenuItemType.BUTTON,icon:"LeftJustifyingSingle",tooltip:"toolbar.alignLeft",disabled$:te(o),activated$:new N.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===x.SetTextSelectionsOperation.id||s===ge.id){const c=ln(o);if(c==null)return;const A=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(A===a.HorizontalAlign.LEFT)}});return e.next(!1),n.dispose}),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Cc(o){const t=o.get(a.ICommandService);return{id:St.id,type:E.MenuItemType.BUTTON,icon:"HorizontallySingle",tooltip:"toolbar.alignCenter",activated$:new N.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===x.SetTextSelectionsOperation.id||s===ge.id){const c=ln(o);if(c==null)return;const A=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(A===a.HorizontalAlign.CENTER)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Tc(o){const t=o.get(a.ICommandService);return{id:It.id,type:E.MenuItemType.BUTTON,icon:"RightJustifyingSingle",tooltip:"toolbar.alignRight",activated$:new N.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===x.SetTextSelectionsOperation.id||s===ge.id){const c=ln(o);if(c==null)return;const A=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(A===a.HorizontalAlign.RIGHT)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function yc(o){const t=o.get(a.ICommandService);return{id:Et.id,type:E.MenuItemType.BUTTON,icon:"AlignTextBothSingle",tooltip:"toolbar.alignJustify",activated$:new N.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===x.SetTextSelectionsOperation.id||s===ge.id){const c=ln(o);if(c==null)return;const A=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(A===a.HorizontalAlign.JUSTIFIED)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}const bt=o=>new N.Observable(t=>{const e=o.get(a.IUniverInstanceService),n=o.get(x.DocSelectionManagerService);let i;const s=e.focused$.subscribe(r=>{if(i==null||i.unsubscribe(),r==null)return;const c=e.getUniverDocInstance(r);c!=null&&(i=n.textSelection$.subscribe(()=>{var d,u,g;const A=n.getDocRanges(),l=(d=A.find(h=>h.isActive))!=null?d:A[0];if(l){const h=c.getSelfOrHeaderFooterModel(l==null?void 0:l.segmentId),m=Wt(l,(g=(u=h.getBody())==null?void 0:u.paragraphs)!=null?g:[]);let f;if(m.every(p=>{var S;return f||(f=(S=p.bullet)==null?void 0:S.listType),p.bullet&&p.bullet.listType===f})){t.next(f);return}}t.next(void 0)}))});return()=>{s.unsubscribe(),i==null||i.unsubscribe()}});function bc(o){return{id:ft.id,type:E.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:Ci,hoverable:!1,selectable:!1},value$:bt(o)}],icon:"OrderSingle",tooltip:"toolbar.order",hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC),disabled$:te(o),activated$:bt(o).pipe(N.map(t=>t&&t.indexOf("ORDER_LIST")===0))}}function Oc(o){return{id:mt.id,type:E.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:Ti,hoverable:!1,selectable:!1},value$:bt(o)}],icon:"UnorderSingle",tooltip:"toolbar.unorder",disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC),activated$:bt(o).pipe(N.map(t=>t&&t.indexOf("BULLET_LIST")===0))}}function Rc(o){return{id:Ht.id,type:E.MenuItemType.BUTTON,icon:"TodoList",tooltip:"toolbar.checklist",disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC),activated$:bt(o).pipe(N.map(t=>t&&t.indexOf("CHECK_LIST")===0))}}function Dc(o){const t=o.get(a.ICommandService),e=o.get(a.IUniverInstanceService);return{id:tn.id,type:E.MenuItemType.BUTTON,icon:"KeyboardSingle",tooltip:"toolbar.documentFlavor",hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY),activated$:new N.Observable(n=>{var r;const i=t.onCommandExecuted(c=>{var A;if(c.id===x.RichTextEditingMutation.id){const l=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);n.next(((A=l==null?void 0:l.getSnapshot())==null?void 0:A.documentStyle.documentFlavor)===a.DocumentFlavor.MODERN)}}),s=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);return n.next(((r=s==null?void 0:s.getSnapshot())==null?void 0:r.documentStyle.documentFlavor)===a.DocumentFlavor.MODERN),()=>i.dispose()})}}function Bc(o){return{id:Je.id,type:E.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor"}}function Mc(o){const t=o.get(a.ICommandService),e=o.get(a.ThemeService);return{id:ke.id,tooltip:"toolbar.fillColor.main",type:E.MenuItemType.BUTTON_SELECTOR,icon:"PaintBucket",selections:[{label:{name:Xn,hoverable:!1,selectable:!1}}],value$:new N.Observable(n=>{const i=e.getCurrentTheme().primaryColor,s=t.onCommandExecuted(r=>{if(r.id===ke.id){const c=r.params.value;n.next(c!=null?c:i)}});return n.next(i),s.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function De(o){var g,h;const t=o.get(a.IUniverInstanceService),e=o.get(x.DocSelectionManagerService),n=o.get(Ce),i=t.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),s=e.getDocRanges(),r=(g=s.find(m=>m.isActive))!=null?g:s[0],c=n.getDefaultStyle(),A=(h=n.getStyleCache())!=null?h:{};if(i==null||r==null)return{ts:{...c,...A}};const{segmentId:l}=r,d=i.getSelfOrHeaderFooterModel(l).getBody();return d==null?{ts:{...c,...A}}:{ts:{...wi(d,r,c),...A}}}function ln(o){var d,u;const t=o.get(a.IUniverInstanceService),e=o.get(x.DocSelectionManagerService),n=t.getCurrentUniverDocInstance(),i=e.getDocRanges(),s=(d=i.find(g=>g.isActive))!=null?d:i[0];if(n==null||s==null)return;const{startOffset:r,segmentId:c}=s,A=(u=n.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:u.paragraphs;if(A==null)return;let l=-1;for(const g of A){const{startIndex:h}=g;if(r>l&&r<=h)return g;l=h}return null}const as={[E.RibbonStartGroup.FORMAT]:{[_e.id]:{order:0,menuItemFactory:cc},[Ne.id]:{order:1,menuItemFactory:Ac},[Pe.id]:{order:2,menuItemFactory:lc},[Ue.id]:{order:3,menuItemFactory:dc},[Re.id]:{order:4,menuItemFactory:uc},[we.id]:{order:5,menuItemFactory:hc},[Qe.id]:{order:6,menuItemFactory:mc},[Le.id]:{order:7,menuItemFactory:gc},[Fe.id]:{order:8,menuItemFactory:fc},[ke.id]:{order:9,menuItemFactory:Mc,[Je.id]:{order:0,menuItemFactory:Bc}}},[E.RibbonStartGroup.LAYOUT]:{[ss]:{order:1,menuItemFactory:Ic,[An.id]:{order:0,menuItemFactory:Ec}},[pt.id]:{order:2,menuItemFactory:vc},[St.id]:{order:3,menuItemFactory:Cc},[It.id]:{order:4,menuItemFactory:Tc},[Et.id]:{order:5,menuItemFactory:yc},[ft.id]:{order:6,menuItemFactory:bc},[mt.id]:{order:7,menuItemFactory:Oc},[Ht.id]:{order:8,menuItemFactory:Rc},[jn.id]:{order:9,menuItemFactory:pc},[tn.id]:{order:10,menuItemFactory:Dc}},[E.ContextMenuPosition.MAIN_AREA]:{[E.ContextMenuGroup.FORMAT]:{[yt.name]:{order:0,menuItemFactory:zr},[$t.id]:{order:1,menuItemFactory:Gr},[en.id]:{order:2,menuItemFactory:Xr},[Ct.id]:{order:3,menuItemFactory:Yr}},[E.ContextMenuGroup.LAYOUT]:{[Eo.id]:{order:0,menuItemFactory:jr},[os]:{order:1,menuItemFactory:qr,[sn.id]:{order:1,menuItemFactory:Jr},[an.id]:{order:2,menuItemFactory:Zr},[rn.id]:{order:3,menuItemFactory:$r},[cn.id]:{order:4,menuItemFactory:ec}},[is]:{order:2,menuItemFactory:tc,[nn.id]:{order:1,menuItemFactory:nc},[on.id]:{order:2,menuItemFactory:oc},[it.id]:{order:3,menuItemFactory:ic}}}}};var xc=Object.getOwnPropertyDescriptor,_c=(o,t,e,n)=>{for(var i=n>1?void 0:n?xc(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},be=(o,t)=>(e,n)=>t(e,n,o);T.DocUIController=class extends a.Disposable{constructor(t,e,n,i,s,r,c,A,l){super(),this._injector=t,this._componentManager=e,this._commandService=n,this._layoutService=i,this._menuManagerService=s,this._uiPartsService=r,this._univerInstanceService=c,this._shortcutService=A,this._configService=l,this._init()}_initCustomComponents(){const t=this._componentManager;this.disposeWithMe(t.register(Xn,ne.ColorPicker)),this.disposeWithMe(t.register(Si,E.FontFamily)),this.disposeWithMe(t.register(Ii,E.FontFamilyItem)),this.disposeWithMe(t.register(Ei,E.FontSize)),this.disposeWithMe(t.register(Ti,Ta)),this.disposeWithMe(t.register(Ci,va)),this.disposeWithMe(t.register("TodoList",li))}_initUiParts(){var e,n;const t=this._configService.getConfig($n);(n=(e=t==null?void 0:t.layout)==null?void 0:e.docContainerConfig)!=null&&n.footer&&this.disposeWithMe(this._uiPartsService.registerComponent(E.BuiltInUIPart.FOOTER,()=>E.connectInjector($a,this._injector)))}_initMenus(){this._menuManagerService.mergeMenu(as)}_initShortCut(){[Pa,Ua,wa,Qa,La,Fa,Va,Wa,Ha,ka,Ka,za,ba].forEach(t=>{this.disposeWithMe(this._shortcutService.registerShortcut(t))})}_init(){this._initCustomComponents(),this._initMenus(),this._initFocusHandler(),this._initCommands(),this._initUiParts(),this._initShortCut()}_initCommands(){[pi,jn,Kn].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(a.UniverInstanceType.UNIVER_DOC,t=>{this._injector.get(B.IRenderManagerService).getRenderById(t).with(T.DocSelectionRenderService).focus()}))}},T.DocUIController=_c([be(0,a.Inject(a.Injector)),be(1,a.Inject(E.ComponentManager)),be(2,a.ICommandService),be(3,E.ILayoutService),be(4,E.IMenuManagerService),be(5,E.IUIPartsService),be(6,a.IUniverInstanceService),be(7,E.IShortcutService),be(8,a.IConfigService)],T.DocUIController);var Nc=Object.getOwnPropertyDescriptor,Pc=(o,t,e,n)=>{for(var i=n>1?void 0:n?Nc(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Co=(o,t)=>(e,n)=>t(e,n,o);const rs=1.5;T.DocBackScrollRenderController=class extends a.RxDisposable{constructor(t,e,n,i){super(),this._context=t,this._textSelectionManagerService=e,this._editorService=n,this._docSkeletonManagerService=i,this._init()}_init(){this._textSelectionManagerService.textSelection$.pipe(N.takeUntil(this.dispose$)).subscribe(t=>{if(t==null)return;const{isEditing:e,unitId:n}=t;n!==this._context.unitId||!e||this._context.unitId!==a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._scrollToSelection()})}scrollToRange(t){const e=this._docSkeletonManagerService.getSkeleton();if(!e)return;const{startOffset:n}=t,i=e.findNodePositionByCharIndex(n);i&&this.scrollToNode(i)}scrollToNode(t){var w;const{unitId:e,scene:n,mainComponent:i}=this._context,s=this._docSkeletonManagerService.getSkeleton();if(i==null||s==null)return;const r=i.getOffsetConfig(),{docsLeft:c,docsTop:A}=r,l=new Ie(r,s),{contentBoxPointGroup:d}=l.getRangePointData(t,t),{left:u,top:g,height:h}=lt(d),m=u+c,f=g+A,p=n.getViewport(he.VIEW_MAIN),S=this._editorService.getEditor(e);if(p==null)return;const{left:I,top:C,right:y,bottom:R}=p.getBounding().viewBound;let v=0,b=0;const O=S?(w=S.params.backScrollOffset)!=null?w:0:100;f<C?v=f-C-O:f>R-h&&(v=f-R+h+O),m<I?b=m-I:m>y-rs&&(b=m-y+rs);const _=p.transViewportScroll2ScrollValue(b,v);p.scrollByBarDeltaValue(_)}_scrollToSelection(){const t=this._textSelectionManagerService.getActiveTextRange();if(t==null)return;const{collapsed:e,startNodePosition:n}=t;e&&this.scrollToNode(n)}},T.DocBackScrollRenderController=Pc([Co(1,a.Inject(x.DocSelectionManagerService)),Co(2,ce),Co(3,a.Inject(x.DocSkeletonManagerService))],T.DocBackScrollRenderController);var Uc=Object.getOwnPropertyDescriptor,wc=(o,t,e,n)=>{for(var i=n>1?void 0:n?Uc(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},at=(o,t)=>(e,n)=>t(e,n,o);T.DocRenderController=class extends a.RxDisposable{constructor(t,e,n,i,s,r,c){super(),this._context=t,this._commandService=e,this._docSelectionRenderService=n,this._docSkeletonManagerService=i,this._editorService=s,this._renderManagerService=r,this._univerInstanceService=c,this._addNewRender(),this._initRenderRefresh(),this._initCommandListener()}reRender(t){var r,c;const e=(r=this._renderManagerService.getRenderById(t))==null?void 0:r.with(x.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 B.Viewport(he.VIEW_MAIN,t,{left:0,top:0,bottom:0,right:0,isWheelPreventDefaultX:!0});t.attachControl(),t.onMouseWheel$.subscribeEvent((s,r)=>{const c=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if((c==null?void 0:c.getUnitId())!==this._context.unitId)return;const A=s;if(A.ctrlKey){const l=Math.abs(A.deltaX);let d=l<40?.2:l<80?.4:.2;d*=A.deltaY>0?-1:1,t.scaleX<1&&(d/=2),t.scaleX+d>4?t.scale(4,4):t.scaleX+d<.1?t.scale(.1,.1):A.preventDefault()}else n.onMouseWheel(A,r)}),new B.ScrollBar(n),t.addLayer(new B.Layer(t,[],Mt),new B.Layer(t,[],Wo)),this._addComponent();const i=()=>t.render();this.disposeWithMe(this._context.activated$.subscribe(s=>{s?e.runRenderLoop(i):e.stopRenderLoop(i)})),this._docSelectionRenderService.__attachScrollEvent()}_addComponent(){const{scene:t,unit:e,components:n}=this._context,r={pageMarginLeft:20,pageMarginTop:20},c=new B.Documents(le.MAIN,void 0,r);c.zIndex=On;const A=new B.DocBackground(le.BACKGROUND,void 0,r);A.zIndex=On,this._context.mainComponent=c,n.set(le.MAIN,c),n.set(le.BACKGROUND,A),t.addObjects([c],Mt),t.addObjects([A],Vo),this._editorService.getEditor(e.getUnitId())==null&&t.enableLayerCache(Mt)}_initRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(N.takeUntil(this.dispose$)).subscribe(t=>{this._create(t)})}_create(t){var A;if(!t)return;const{mainComponent:e,components:n}=this._context,i=e,s=n.get(le.BACKGROUND);i.changeSkeleton(t),s.changeSkeleton(t);const{unitId:r}=this._context,c=this._editorService.getEditor(r);if(this._editorService.isEditor(r)&&!(c!=null&&c.params.scrollBar)){(A=this._context.mainComponent)==null||A.makeDirty();return}this._recalculateSizeBySkeleton(t)}_initCommandListener(){const t=[x.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(t.includes(e.id)){const n=e.params,{unitId:i}=n;this.reRender(i)}}))}_recalculateSizeBySkeleton(t){var m;const{mainComponent:e,scene:n,unitId:i,components:s}=this._context,r=e,c=s.get(le.BACKGROUND),A=(m=t.getSkeletonData())==null?void 0:m.pages;if(A==null)return;let l=0,d=0;const g=this._context.unit.getSnapshot().documentStyle.documentFlavor;for(let f=0,p=A.length;f<p;f++){const S=A[f];let{pageWidth:I,pageHeight:C}=S;if(g===a.DocumentFlavor.MODERN){const y=Qc(S);I=y.pageWidth,C=y.pageHeight}r.pageLayoutType===B.PageLayoutType.VERTICAL?(d+=C,d+=r.pageMarginTop,f===p-1&&(d+=r.pageMarginTop),l=Math.max(l,I)):r.pageLayoutType===B.PageLayoutType.HORIZONTAL&&(l+=I,f!==p-1&&(l+=r.pageMarginLeft),d=Math.max(d,C))}r.resize(l,d),c.resize(l,d);const h=this._editorService.getEditor(i);(!this._editorService.isEditor(i)||h!=null&&h.params.scrollBar)&&n.resize(l,d)}},T.DocRenderController=wc([at(1,a.ICommandService),at(2,a.Inject(T.DocSelectionRenderService)),at(3,a.Inject(x.DocSkeletonManagerService)),at(4,ce),at(5,B.IRenderManagerService),at(6,a.IUniverInstanceService)],T.DocRenderController);function Qc(o){let{pageWidth:t,pageHeight:e}=o;const{marginLeft:n,marginRight:i,marginTop:s,marginBottom:r,skeDrawings:c,skeTables:A}=o;t===Number.POSITIVE_INFINITY&&(t=o.width+n+i),e===Number.POSITIVE_INFINITY&&(e=o.height+s+r);for(const l of c.values())t=Math.max(t,l.aLeft+l.width+n+i),e=Math.max(e,l.aTop+l.height+s+r);for(const l of A.values())t=Math.max(t,l.left+l.width+n+i),e=Math.max(e,l.top+l.height+s+r);return{pageWidth:t,pageHeight:e}}const To={id:"doc.command.select-all",type:a.CommandType.COMMAND,handler:async o=>{var g;const t=o.get(a.IUniverInstanceService),e=o.get(x.DocSelectionManagerService),n=t.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),i=e.getDocRanges(),s=(g=i.find(h=>h.isActive))!=null?g:i[0];if(n==null||s==null)return!1;const{segmentId:r}=s,c=n.getUnitId(),A=n.getSelfOrHeaderFooterModel(r).getSnapshot().body;if(A==null)return!1;const{tables:l=[]}=A,d=[];let u=0;for(const h of l){const{startIndex:m,endIndex:f}=h;u!==m&&d.push({startOffset:u,endOffset:m-1,rangeType:a.DOC_RANGE_TYPE.TEXT}),d.push({startOffset:m+3,endOffset:f-5,rangeType:a.DOC_RANGE_TYPE.RECT}),u=f}return u!==A.dataStream.length-2&&d.push({startOffset:u,endOffset:A.dataStream.length-2,rangeType:a.DOC_RANGE_TYPE.TEXT}),e.replaceDocRanges(d,{unitId:c,subUnitId:c},!1),!0}};class Ot extends a.RxDisposable{constructor(e){super();M(this,"_previousActiveRange",null);M(this,"_undoMutationParamsCache",[]);M(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,r)=>a.JSONX.compose(s,r.actions),null),textRanges:[]};return{redoMutationParams:{unitId:e,actions:this._redoMutationParamsCache.reduce((s,r)=>a.JSONX.compose(s,r.actions),null),textRanges:[]},undoMutationParams:n,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const yo={id:"doc.command.ime-input",type:a.CommandType.COMMAND,handler:async(o,t)=>{var Q,G,Y;const{unitId:e,newText:n,oldTextLen:i,isCompositionEnd:s,isCompositionStart:r}=t,c=o.get(a.ICommandService),A=o.get(B.IRenderManagerService),l=o.get(a.IUniverInstanceService),d=o.get(Ce),u=(Q=A.getRenderById(e))==null?void 0:Q.with(Ot),g=l.getUnit(e,a.UniverInstanceType.UNIVER_DOC);if(g==null||u==null)return!1;const h=u.getActiveRange();if(h==null)return!1;const{style:m,segmentId:f}=h,p=g.getSelfOrHeaderFooterModel(f).getBody();if(p==null)return!1;Object.assign(h,h);const{startOffset:I,endOffset:C}=h,y=n.length,R=[{startOffset:I+y,endOffset:I+y,collapsed:!0,style:m}],v={id:x.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:R}},b=d.getDefaultStyle(),O=d.getStyleCache(),_=Rn((G=p.customRanges)!=null?G:[],I+i,a.SHEET_EDITOR_UNITS.includes(e)),w=xt(p,r?C:I+i,b,O,a.SHEET_EDITOR_UNITS.includes(e)),D=Dn((Y=p.customDecorations)!=null?Y:[],I+i),U=new a.TextX,P=a.JSONX.getInstance();if(!h.collapsed&&r){const W=a.BuildTextUtils.selection.delete([h],p,0,null,!1);U.push(...W),v.params.textRanges=[{startOffset:I+y,endOffset:I+y,collapsed:!0}]}else U.push({t:a.TextXActionType.RETAIN,len:I});i>0&&U.push({t:a.TextXActionType.DELETE,len:i}),U.push({t:a.TextXActionType.INSERT,body:{dataStream:n,textRuns:w?[{...w,st:0,ed:n.length}]:[],customRanges:_?[{..._,startIndex:0,endIndex:n.length-1}]:[],customDecorations:D.map(W=>({...W,startIndex:0,endIndex:n.length-1}))},len:n.length});const k=$(g,f);v.params.actions=P.editOp(U.serialize(),k),v.params.noHistory=!s,v.params.isCompositionEnd=s;const H=c.syncExecuteCommand(v.id,v.params);return u.pushUndoRedoMutationParams(H,v.params),!!H}},dn={type:a.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(o,t)=>{var u,g,h;const e=o.get(a.ICommandService),n=o.get(a.IUndoRedoService),i=o.get(a.IUniverInstanceService);let s=(u=i.getCurrentUniverDocInstance())==null?void 0:u.getUnitId();if(!s)return!1;let r=1;if(t&&(s=(g=t.documentId)!=null?g:s,r=(h=t.zoomRatio)!=null?h:r),!i.getUniverDocInstance(s))return!1;const A={zoomRatio:r,unitId:s},l=Ga(o,A);return e.syncExecuteCommand(ue.id,A)?(n.pushUndoRedo({unitID:s,undoMutations:[{id:ue.id,params:l}],redoMutations:[{id:ue.id,params:A}]}),!0):!1}},bo={id:"doc.table.tab-in-table",type:a.CommandType.COMMAND,handler:async(o,t)=>{var m;const{shift:e}=t,n=o.get(x.DocSelectionManagerService),i=n.getDocRanges(),s=o.get(a.ICommandService),c=o.get(a.IUniverInstanceService).getCurrentUniverDocInstance();if(!c)return!1;const A=(m=i.find(f=>f.isActive))!=null?m:i[0],l=c.getUnitId(),d=re(o,l),u=d==null?void 0:d.getSkeleton(),g=u==null?void 0:u.getViewModel().getSelfOrHeaderFooterViewModel(A==null?void 0:A.segmentId);if(g==null||A==null)return!1;let h=null;if(e?h=ki(g,A,no.PREV):h=ki(g,A,no.NEXT),h){const{startOffset:f,endOffset:p}=h,S=[{startOffset:f,endOffset:p}];return n.replaceDocRanges(S),!0}return e===!1?await s.executeCommand(go.id,{position:Kt.BELLOW}):!0}};var Lc=Object.getOwnPropertyDescriptor,Fc=(o,t,e,n)=>{for(var i=n>1?void 0:n?Lc(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Oo=(o,t)=>(e,n)=>t(e,n,o);let Ro=class{constructor(o,t,e){M(this,"_docContainer");M(this,"getComponent",o=>{if(this._docContainer=o,!o.getContentRef().current)throw new Error("container is not ready")});M(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($n),changeLocale:this.changeLocale,getComponent:this.getComponent}}getContentRef(){return this._docContainer.getContentRef()}UIDidMount(o){if(this._docContainer)return o(this._docContainer)}getDocContainer(){return this._docContainer}};Ro=Fc([Oo(0,a.Inject(a.LocaleService)),Oo(1,a.Inject(a.Injector)),Oo(2,a.IConfigService)],Ro);var kc=Object.getOwnPropertyDescriptor,Hc=(o,t,e,n)=>{for(var i=n>1?void 0:n?kc(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Vc=(o,t)=>(e,n)=>t(e,n,o);let un=class extends a.RxDisposable{constructor(t){super();M(this,"_docContainerController");this._injector=t,this._docContainerController=this._injector.createInstance(Ro)}};un=Hc([Vc(0,a.Inject(a.Injector))],un);var Wc=Object.getOwnPropertyDescriptor,Kc=(o,t,e,n)=>{for(var i=n>1?void 0:n?Wc(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},cs=(o,t)=>(e,n)=>t(e,n,o);let hn=class extends a.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:xe.id,match:o=>{var i;const{selection:t,paragraphs:e,unit:n}=o;if(e.length===1&&t.startOffset===e[0].paragraphStart&&e[0].bullet){const s=(i=n.getBody())==null?void 0:i.paragraphs,r=s==null?void 0:s.filter(c=>{var A;return((A=c.bullet)==null?void 0:A.listId)===e[0].bullet.listId});return(r==null?void 0:r.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:kt.id,params:{type:t!=null&&t.shift?gt.decrease:gt.increase}}]},priority:100})),this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:xe.id,match:o=>{const{selection:t,unit:e}=o,{startNodePosition:n,endNodePosition:i}=t,s=this._renderManagerService.getRenderById(e.getUnitId()),r=s==null?void 0:s.with(x.DocSkeletonManagerService).getSkeleton();return r==null?!1:!!(n&&i&&$o(r,n,i)||n&&!i&&n.path.indexOf("cells")>-1)},getMutations(o){const t=o.commandParams;return[{id:bo.id,params:{shift:!!(t!=null&&t.shift)}}]},priority:99}))}_initListSpaceAutoFormat(){this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:ut.id,match:o=>{var s;const{selection:t,paragraphs:e,unit:n}=o;if(!t.collapsed||e.length!==1)return!1;const i=(s=n.getBody())==null?void 0:s.dataStream.slice(e[0].paragraphStart,e[0].paragraphEnd-1);return!!(i&&Object.keys(a.QuickListTypeMap).includes(i))},getMutations(o){var i;const{paragraphs:t,unit:e}=o,n=(i=e.getBody())==null?void 0:i.dataStream.slice(t[0].paragraphStart,t[0].paragraphEnd-1);if(n&&Object.keys(a.QuickListTypeMap).includes(n)){const s=a.QuickListTypeMap[n];return[{id:Zn.id,params:{listType:s,paragraph:t[0]}}]}return[]}}))}_initExitListAutoFormat(){this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:qe.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:kt.id,params:{type:gt.decrease}}]:[{id:Ze.id,params:{listType:o.paragraphs[0].bullet.listType}}]:[]}}))}_initDefaultEnterFormat(){this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:qe.id,match:()=>!0,getMutations(){return[{id:fo.id}]},priority:-9999}))}};hn=Kc([cs(0,a.Inject(T.DocAutoFormatService)),cs(1,B.IRenderManagerService)],hn);function zc(o){return o.rows[0].cells[0].sections[0].columns[0].lines[0]}function jc(o){const t=o.rows[o.rows.length-1],e=t.cells[t.cells.length-1];return B.getLastLine(e)}function Gc(o,t){const{ed:e}=o,{skeTables:n}=t;let i=null;for(const s of n.values())if(s.st===e+1){i=s;break}return i}function As(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:i,ed:s}=o,r=t.type===B.DocumentSkeletonPageType.CELL?[t]:t.parent.pages;return B.lineIterator(r,c=>{c.st===s+1?n=c:c.ed===i-1&&(e=c)}),{lineBeforeTable:e,lineAfterTable:n}}function ls(o){return o.sections[0].columns[0].lines.length===0}function ds(o){var r,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 i=t.cells.indexOf(o);let s=e.rows[e.rows.indexOf(t)+1];if(s==null&&n.indexOf("#-#")){const[A,l]=n.split("#-#"),d=(c=(r=e.parent)==null?void 0:r.parent)==null?void 0:c.pages,u=`${A}#-#${Number.parseInt(l)+1}`;if(d)for(const g of d){const{skeTables:h}=g;if(h.has(u)){const m=h.get(u);if(m!=null&&m.rows.length){s=m.rows.find(f=>!f.isRepeatRow);break}}}}if(s!=null){const A=s.cells[i];return ls(A)?ds(A):A}}function us(o){var s,r;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 i=t.cells.indexOf(o);if((n==null||n.isRepeatRow)&&e.tableId.indexOf("#-#")){const[c,A]=e.tableId.split("#-#"),l=(r=(s=e.parent)==null?void 0:s.parent)==null?void 0:r.pages,d=`${c}#-#${Number.parseInt(A)-1}`;if(l)for(const u of l){const{skeTables:g}=u;if(g.has(d)){const h=g.get(d);if(h!=null&&h.rows.length){n=h.rows[h.rows.length-1];break}}}}if(n!=null){const c=n.cells[i];return ls(c)?us(c):c}}function Xc(o,t){const{st:e}=o,{skeTables:n}=t;let i=null;for(const s of n.values())if(s.ed===e-1){i=s;break}return i}function Yc(o){return o.sections[0].columns[0].lines[0]}function qc(o){const t=B.getLastColumn(o);return t.lines[t.lines.length-1]}var Jc=Object.getOwnPropertyDescriptor,Zc=(o,t,e,n)=>{for(var i=n>1?void 0:n?Jc(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},gn=(o,t)=>(e,n)=>t(e,n,o);let mn=class extends a.Disposable{constructor(t,e,n,i){super();M(this,"_onInputSubscription");this._univerInstanceService=t,this._renderManagerService=e,this._textSelectionManagerService=n,this._commandService=i,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 C,y,R;const e=this._textSelectionManagerService.getActiveTextRange(),n=this._textSelectionManagerService.getTextRanges(),i=this._univerInstanceService.getCurrentUniverDocInstance();if(i==null)return;const s=(C=this._renderManagerService.getRenderById(i.getUnitId()))==null?void 0:C.with(x.DocSkeletonManagerService).getSkeleton(),r=this._getDocObject();if(e==null||s==null||r==null)return;const{startOffset:c,endOffset:A,style:l,collapsed:d,direction:u,segmentId:g,startNodePosition:h,endNodePosition:m,segmentPage:f}=e;if(n.length>1){let v=Number.POSITIVE_INFINITY,b=Number.NEGATIVE_INFINITY;for(const O of n)v=Math.min(v,O.startOffset),b=Math.max(b,O.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:t===a.Direction.LEFT||t===a.Direction.UP?b:v,endOffset:t===a.Direction.LEFT||t===a.Direction.UP?v:b,style:l}],!1);return}const p=d||u===a.RANGE_DIRECTION.FORWARD?c:A;let S=d||u===a.RANGE_DIRECTION.FORWARD?A:c;const I=(y=i.getSelfOrHeaderFooterModel(g).getBody().dataStream.length)!=null?y:Number.POSITIVE_INFINITY;if(t===a.Direction.LEFT||t===a.Direction.RIGHT){const v=s.findNodeByCharIndex(S-1,g,f),b=s.findNodeByCharIndex(S,g,f);S=t===a.Direction.RIGHT?S+b.count:S-((R=v==null?void 0:v.count)!=null?R:0),S=Math.min(I-2,Math.max(0,S)),this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:S,style:l}],!1),this._scrollToFocusNodePosition(i.getUnitId(),S)}else{const v=s.findNodeByCharIndex(S,g,f),b=r.document.getOffsetConfig(),O=d?h:u===a.RANGE_DIRECTION.FORWARD?m:h,_=this._getTopOrBottomPosition(s,v,O,t===a.Direction.DOWN,!0);if(_==null){const D=t===a.Direction.UP?0:I-2;if(D===S)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:D,style:l}],!1);return}const w=new Ie(b,s).getRangePointData(_,_).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:w.endOffset,style:l}],!1),this._scrollToFocusNodePosition(i.getUnitId(),w.endOffset)}}_handleMoveCursor(t){var I,C,y,R;const e=this._textSelectionManagerService.getActiveTextRange(),n=this._textSelectionManagerService.getTextRanges(),i=this._univerInstanceService.getCurrentUniverDocInstance();if(i==null)return!1;const s=(I=this._renderManagerService.getRenderById(i.getUnitId()))==null?void 0:I.with(x.DocSkeletonManagerService).getSkeleton(),r=this._getDocObject();if(e==null||s==null||r==null||n==null)return;const{startOffset:c,endOffset:A,style:l,collapsed:d,segmentId:u,startNodePosition:g,endNodePosition:h,segmentPage:m}=e,f=i.getSelfOrHeaderFooterModel(u).getBody();if(f==null)return;const p=(C=f.dataStream.length)!=null?C:Number.POSITIVE_INFINITY,S=(y=i.getCustomRanges())!=null?y:[];if(t===a.Direction.LEFT||t===a.Direction.RIGHT){let v;if(!e.collapsed||n.length>1){let _=Number.POSITIVE_INFINITY,w=Number.NEGATIVE_INFINITY;for(const D of n)_=Math.min(_,D.startOffset),w=Math.max(w,D.endOffset);v=t===a.Direction.LEFT?_:w}else{const _=s.findNodeByCharIndex(c-1,u,m),w=s.findNodeByCharIndex(c,u,m),D=s.findNodeByCharIndex(c+1,u,m);t===a.Direction.LEFT?v=Math.max(0,c-((R=_==null?void 0:_.count)!=null?R:1)):v=Math.min(p-2,A+w.count+((D==null?void 0:D.streamType)===a.DataStreamTreeTokenType.SECTION_BREAK?1:0))}const b=[a.DataStreamTreeTokenType.TABLE_START,a.DataStreamTreeTokenType.TABLE_END,a.DataStreamTreeTokenType.TABLE_ROW_START,a.DataStreamTreeTokenType.TABLE_ROW_END,a.DataStreamTreeTokenType.TABLE_CELL_START,a.DataStreamTreeTokenType.TABLE_CELL_END,a.DataStreamTreeTokenType.SECTION_BREAK];if(t===a.Direction.LEFT)for(;b.includes(f.dataStream[v]);)v--;else for(;b.includes(f.dataStream[v]);)v++;S.filter(_=>_.wholeEntity&&_.startIndex<v&&_.endIndex>=v).forEach(_=>{t===a.Direction.LEFT?v=Math.min(_.startIndex,v):v=Math.max(_.endIndex+1,v)}),this._textSelectionManagerService.replaceTextRanges([{startOffset:Math.max(0,v),endOffset:Math.max(0,v),style:l}],!1),this._scrollToFocusNodePosition(i.getUnitId(),v)}else{const v=s.findNodeByCharIndex(c,u,m),b=s.findNodeByCharIndex(A,u,m),O=r.document.getOffsetConfig(),_=this._getTopOrBottomPosition(s,t===a.Direction.UP||d?v:b,t===a.Direction.UP||d?g:h,t===a.Direction.DOWN);if(_==null){let D;d?D=t===a.Direction.UP?0:p-2:D=t===a.Direction.UP?c:A,this._textSelectionManagerService.replaceTextRanges([{startOffset:Math.max(0,D),endOffset:Math.max(0,D),style:l}],!1);return}const w=new Ie(O,s).getRangePointData(_,_).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...w,style:l}],!1),this._scrollToFocusNodePosition(i.getUnitId(),w.endOffset)}}_getTopOrBottomPosition(t,e,n,i,s=!1){if(e==null||n==null)return;const r=this._getGlyphLeftOffsetInLine(e),c=this._getNextOrPrevLine(e,i,s);if(c==null)return;const A=this._matchPositionByLeftOffset(t,c,r,n);if(A!=null)return{...A,isBack:!0}}_getGlyphLeftOffsetInLine(t){const e=t.parent;if(e==null)return Number.NEGATIVE_INFINITY;const n=e.left,{left:i}=t;return n+i}_matchPositionByLeftOffset(t,e,n,i){const s={distance:Number.POSITIVE_INFINITY};for(const c of e.divides){const A=c.left;for(const l of c.glyphGroup){if(l.streamType===a.DataStreamTreeTokenType.SECTION_BREAK)continue;const{left:d}=l,u=A+d,g=Math.abs(n-u);g<s.distance&&(s.glyph=l,s.distance=g)}}if(s.glyph==null)return;const{segmentPage:r}=i;return t.findPositionByGlyph(s.glyph,r)}_getNextOrPrevLine(t,e,n=!1){var f,p,S,I,C,y,R,v,b,O,_,w;const i=t.parent,s=i==null?void 0:i.parent,r=s==null?void 0:s.parent,c=r==null?void 0:r.parent,A=c==null?void 0:c.parent;if(i==null||s==null||r==null||c==null||A==null)return;const l=r.lines.indexOf(s);if(l===-1)return;let d;if(A.type===B.DocumentSkeletonPageType.CELL&&n){const D=hs(A,e);if(D)return D}if(e===!0){d=r.lines[l+1];const D=Gc(s,A);if(D){const U=zc(D);U&&(d=U)}}else{d=r.lines[l-1];const D=Xc(s,A);if(D){const U=jc(D);U&&(d=U)}}if(d!=null)return d;const u=c.columns.indexOf(r);if(u===-1)return;if(e===!0)d=(f=c.columns[u+1])==null?void 0:f.lines[0];else{const D=(S=(p=c.columns)==null?void 0:p[u-1])==null?void 0:S.lines;d=D==null?void 0:D[D.length-1]}if(d!=null)return d;const g=A.sections.indexOf(c);if(g===-1)return;if(e===!0)d=(C=(I=A.sections[g-1])==null?void 0:I.columns[0])==null?void 0:C.lines[0];else{const D=(R=(y=A.sections)==null?void 0:y[g-1])==null?void 0:R.columns,U=D==null?void 0:D[D.length-1],P=U==null?void 0:U.lines;d=P==null?void 0:P[P.length-1]}if(d!=null)return d;if(A.type===B.DocumentSkeletonPageType.CELL)return hs(A,e);const h=A.parent;if(h==null)return;const m=h.pages.indexOf(A);if(m!==-1){if(e===!0)d=(O=(b=(v=h.pages[m+1])==null?void 0:v.sections[0])==null?void 0:b.columns[0])==null?void 0:O.lines[0];else{const D=(_=h.pages[m-1])==null?void 0:_.sections;if(D==null)return;const U=(w=D[D.length-1])==null?void 0:w.columns,P=U[U.length-1],k=P==null?void 0:P.lines;d=k[k.length-1]}if(d!=null)return d}}_scrollToFocusNodePosition(t,e){var i;const n=(i=this._renderManagerService.getRenderById(t))==null?void 0:i.with(T.DocBackScrollRenderController);n!=null&&n.scrollToRange({startOffset:e,endOffset:e,collapsed:!0})}_getDocObject(){return Ko(this._univerInstanceService,this._renderManagerService)}};mn=Zc([gn(0,a.IUniverInstanceService),gn(1,B.IRenderManagerService),gn(2,a.Inject(x.DocSelectionManagerService)),gn(3,a.ICommandService)],mn);function hs(o,t){var n,i;let e=null;if(t===!0){const s=ds(o);if(s)e=Yc(s);else{const r=(n=o.parent)==null?void 0:n.parent,{lineAfterTable:c}=As(r);c&&(e=c)}}else{const s=us(o);if(s)e=qc(s);else{const r=(i=o.parent)==null?void 0:i.parent,{lineBeforeTable:c}=As(r);c&&(e=c)}}return e}const We={create:"univer-create",createItem:"univer-create-item",createLabel:"univer-create-label",createInput:"univer-create-input"},$c=({handleRowColChange:o,tableCreateParams:t})=>{const e=E.useDependency(a.LocaleService),[n,i]=F.useState(3),[s,r]=F.useState(5);function c(A,l){i(A),r(l),o(A,l)}return F.useEffect(()=>{i(t.rowCount),r(t.colCount)},[t]),L.jsxs("div",{className:We.create,children:[L.jsxs("div",{className:We.createItem,children:[L.jsx("span",{className:We.createLabel,children:e.t("toolbar.table.rowCount")}),L.jsx(ne.InputNumber,{min:1,max:20,precision:0,value:n,onChange:A=>{c(A,s)},className:We.createInput})]}),L.jsxs("div",{className:We.createItem,children:[L.jsx("span",{className:We.createLabel,children:e.t("toolbar.table.colCount")}),L.jsx(ne.InputNumber,{min:1,max:20,precision:0,value:s,onChange:A=>{c(n,A)},className:We.createInput})]})]})};var eA=Object.getOwnPropertyDescriptor,tA=(o,t,e,n)=>{for(var i=n>1?void 0:n?eA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},gs=(o,t)=>(e,n)=>t(e,n,o);let fn=class extends a.Disposable{constructor(o,t){super(),this._commandService=o,this._componentManager=t,this._initialize()}_initialize(){this._init(),this._registerCommands(),this._initCustomComponents()}_registerCommands(){[An].forEach(o=>this.disposeWithMe(this._commandService.registerCommand(o)))}_initCustomComponents(){const o=this._componentManager;this.disposeWithMe(o.register(es,$c))}_init(){}};fn=tA([gs(0,a.ICommandService),gs(1,a.Inject(E.ComponentManager))],fn);const Do=4;var nA=Object.getOwnPropertyDescriptor,oA=(o,t,e,n)=>{for(var i=n>1?void 0:n?nA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},pn=(o,t)=>(e,n)=>t(e,n,o);function ms(o,t){const e=fs(o.left,o.top,t),n=fs(o.right,o.bottom,t);return{left:e.x,top:e.y,right:n.x,bottom:n.y}}function fs(o,t,e){const{scaleX:n,scaleY:i}=e.getAncestorScale(),s=e.getViewport(he.VIEW_MAIN);if(!s)return{x:o,y:t};const{viewportScrollX:r,viewportScrollY:c}=s,A=(o-r)*n,l=(t-c)*i;return{x:A,y:l}}function ps(o,t,e){const{scaleX:n,scaleY:i}=e.getAncestorScale(),s=e.getViewport(he.VIEW_MAIN);if(!s)return{x:o,y:t};const{viewportScrollX:r,viewportScrollY:c}=s,A=o/n+r,l=t/i+c;return{x:A,y:l}}const Sn=(o,t)=>{const{scene:e,mainComponent:n,engine:i}=t,s=t.with(x.DocSkeletonManagerService).getSkeleton(),r=s.findNodePositionByCharIndex(o.startOffset,!0,o.segmentId,o.segmentPage),c=s.findNodePositionByCharIndex(o.endOffset,!0,o.segmentId,o.segmentPage),A=n;if(!c||!r)return;const l=A.getOffsetConfig(),{docsLeft:d,docsTop:u}=l,g=i.getCanvasElement(),h=g.getBoundingClientRect(),m=B.pxToNum(g.style.width),{top:f,left:p,width:S}=h,I=S/m,{scaleX:C,scaleY:y}=e.getAncestorScale(),R=new Ie(l,s),{borderBoxPointGroup:v}=R.getRangePointData(r,c);return Pt(v).map(_=>ms(_,e)).map(_=>({left:(_.left+d*C)*I+p,right:(_.right+d*C)*I+p,top:(_.top+u*y)*I+f,bottom:(_.bottom+u*y)*I+f}))};T.DocCanvasPopManagerService=class extends a.Disposable{constructor(t,e,n,i){super(),this._globalPopupManagerService=t,this._renderManagerService=e,this._univerInstanceService=n,this._commandService=i}_createObjectPositionObserver(t,e){const n=()=>{const{scene:A,engine:l}=e,{left:d,top:u,width:g,height:h}=t,m={left:d,right:d+g,top:u,bottom:u+h},f=l.getCanvasElement(),p=f.getBoundingClientRect(),S=B.pxToNum(f.style.width),I=ms(m,A),{top:C,left:y,width:R}=p,v=R/S;return{left:I.left*v+y,right:I.right*v+y,top:I.top*v+C,bottom:I.bottom*v+C}},i=n(),s=new N.BehaviorSubject(i),r=new a.DisposableCollection;r.add(this._commandService.onCommandExecuted(A=>{if(A.id===ue.id||A.id===x.RichTextEditingMutation.id){const l=n();l&&s.next(l)}}));const c=e.scene.getViewport(he.VIEW_MAIN);return c&&r.add(c.onScrollAfter$.subscribeEvent(()=>{s.next(n())})),{position:i,position$:s,disposable:r}}_createRangePositionObserver(t,e){var c;const n=(c=Sn(t,e))!=null?c:[],i=new N.BehaviorSubject(n),s=new a.DisposableCollection;s.add(this._commandService.onCommandExecuted(A=>{if((A.id===ue.id||A.id===x.RichTextEditingMutation.id)&&A.params.unitId===e.unitId){const d=Sn(t,e);d&&i.next(d)}}));const r=e.scene.getViewport(he.VIEW_MAIN);return r&&s.add(r.onScrollAfter$.subscribeEvent(()=>{const A=Sn(t,e);A&&i.next(A)})),{positions:n,positions$:i,disposable:s}}attachPopupToObject(t,e,n){const i=this._renderManagerService.getRenderById(n);if(!i)throw new Error(`Current render not found, unitId: ${n}`);const{position:s,position$:r,disposable:c}=this._createObjectPositionObserver(t,i),A=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:s,anchorRect$:r,canvasElement:i.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(A),r.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:r}=e,c=this._renderManagerService.getRenderById(n);if(!c)throw new Error(`Current render not found, unitId: ${n}`);const{positions:A,positions$:l,disposable:d}=this._createRangePositionObserver(t,c),u=l.pipe(N.map(h=>s.includes("top")?h[0]:h[h.length-1])),g=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:s.includes("top")?A[0]:A[A.length-1],anchorRect$:u,excludeRects:A,excludeRects$:l,direction:s.includes("top")||s.includes("bottom")?A.length>1?r:s:"bottom",canvasElement:c.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(g),l.complete(),d.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==g}}},T.DocCanvasPopManagerService=oA([pn(0,a.Inject(E.ICanvasPopupService)),pn(1,B.IRenderManagerService),pn(2,a.IUniverInstanceService),pn(3,a.ICommandService)],T.DocCanvasPopManagerService);var iA=Object.getOwnPropertyDescriptor,sA=(o,t,e,n)=>{for(var i=n>1?void 0:n?iA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},aA=(o,t)=>(e,n)=>t(e,n,o);const rA=(o,t,e,n)=>{var g,h,m,f,p;const i=e.findNodePositionByCharIndex(o.startOffset,!0,o.segmentId,n),s=e.getSkeletonData();let r=o.endOffset;if(o.segmentId){const S=(p=Array.from((h=(g=s==null?void 0:s.skeFooters.get(o.segmentId))==null?void 0:g.values())!=null?h:[])[0])!=null?p:Array.from((f=(m=s==null?void 0:s.skeHeaders.get(o.segmentId))==null?void 0:m.values())!=null?f:[])[0];S&&(r=Math.min(S.ed,r))}const c=e.findNodePositionByCharIndex(r,!0,o.segmentId,n);if(!c||!i)return;const A=t.getOffsetConfig(),l=new Ie(A,e),{borderBoxPointGroup:d}=l.getRangePointData(i,c);return Pt(d).map(S=>({top:S.top+A.docsTop-Do,bottom:S.bottom+A.docsTop+Do,left:S.left+A.docsLeft,right:S.right+A.docsLeft}))},cA=(o,t,e,n=-1)=>{const i=e.findPositionByGlyph(o,n);if(!i)return;const s=t.getOffsetConfig(),r={...i,isBack:!0},c=new Ie(s,e),{borderBoxPointGroup:A}=c.getRangePointData(r,r),d=Pt(A)[0];return{top:d.top+s.docsTop,bottom:d.bottom+s.docsTop,left:d.left+s.docsLeft,right:d.left+s.docsLeft+o.width}};T.DocEventManagerService=class extends a.Disposable{constructor(e,n){super();M(this,"_hoverCustomRanges$",new N.BehaviorSubject([]));M(this,"hoverCustomRanges$",this._hoverCustomRanges$.pipe(N.distinctUntilChanged((e,n)=>e.length===n.length&&e.every((i,s)=>n[s].range.rangeId===i.range.rangeId&&n[s].segmentId===i.segmentId&&n[s].segmentPageIndex===i.segmentPageIndex&&n[s].range.startIndex===i.range.startIndex))));M(this,"_clickCustomRanges$",new N.Subject);M(this,"clickCustomRanges$",this._clickCustomRanges$.asObservable());M(this,"_hoverBullet$",new N.Subject);M(this,"hoverBullet$",this._hoverBullet$.pipe(N.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))));M(this,"_clickBullet$",new N.Subject);M(this,"clickBullets$",this._clickBullet$.asObservable());M(this,"_customRangeDirty",!0);M(this,"_bulletDirty",!0);M(this,"_customRangeBounds",[]);M(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=B.CURSOR_TYPE.TEXT;this.disposeWithMe(this.hoverCustomRanges$.subscribe(n=>{n.length?(e=this._context.scene.getCursor(),this._context.scene.setCursor(B.CURSOR_TYPE.POINTER)):this._context.scene.setCursor(e)}))}_initResetDirty(){this.disposeWithMe(this._skeleton.dirty$.subscribe(()=>{this._customRangeDirty=!0,this._bulletDirty=!0})),this.disposeWithMe(a.fromEventSubject(this._context.engine.onTransformChange$).pipe(N.filter(e=>e.type===B.TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize)).subscribe(()=>{this._customRangeDirty=!0,this._bulletDirty=!0}))}_initEvents(){this.disposeWithMe(a.fromEventSubject(this._context.scene.onPointerMove$).pipe(N.throttleTime(30)).subscribe(i=>{this._hoverCustomRanges$.next(this._calcActiveRanges(i)),this._hoverBullet$.next(this._calcActiveBullet(i))})),this.disposeWithMe(this._context.scene.onPointerEnter$.subscribeEvent(()=>{this._hoverBullet$.next(null),this._hoverCustomRanges$.next([])}));const e=a.fromEventSubject(this._context.mainComponent.onPointerDown$),n=a.fromEventSubject(this._context.scene.onPointerUp$);this.disposeWithMe(e.pipe(N.switchMap(i=>n.pipe(N.take(1),N.map(s=>({down:i,up:s})))),N.filter(({down:i,up:s})=>i.target===s.target&&s.timeStamp-i.timeStamp<300)).subscribe(({down:i})=>{if(i.button===2)return;const s=this._calcActiveRanges(i);s.length&&this._clickCustomRanges$.next(s.pop());const r=this._calcActiveBullet(i);r&&this._clickBullet$.next(r)}))}_buildCustomRangeBoundsBySegment(e,n=-1){var r,c,A;const i=(A=(c=(r=this._context.unit.getSelfOrHeaderFooterModel(e))==null?void 0:r.getBody())==null?void 0:c.customRanges)!=null?A:[],s=[];return i.forEach(l=>{const d={startOffset:l.startIndex,endOffset:l.endIndex+1,segmentId:e},u=rA(d,this._documents,this._skeleton,n);if(!u)return null;s.push({customRange:l,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((i,s)=>{i.headerId&&e.push(...this._buildCustomRangeBoundsBySegment(i.headerId,s)),i.footerId&&e.push(...this._buildCustomRangeBoundsBySegment(i.footerId,s))}),this._customRangeBounds=e}_calcActiveRanges(e){this._buildCustomRangeBounds();const{offsetX:n,offsetY:i}=e,{x:s,y:r}=ps(n,i,this._context.scene);return this._customRangeBounds.filter(A=>A.rects.some(l=>{const{left:d,right:u,top:g,bottom:h}=l;return s>=d&&s<=u&&r>=g&&r<=h})).map(A=>({segmentId:A.segmentId,range:A.customRange,segmentPageIndex:A.segmentPageIndex,rects:A.rects}))}_buildBulletBoundsBySegment(e,n=-1){var l,d,u,g,h;const i=(l=this._context.unit.getSelfOrHeaderFooterModel(e))==null?void 0:l.getBody(),s=((d=i==null?void 0:i.paragraphs)!=null?d:[]).filter(m=>m.bullet&&m.bullet.listType.indexOf("CHECK_LIST")===0),r=[],c=this._skeleton.getSkeletonData();if(!c)return r;const A=m=>{var f,p,S;for(const I of m){const C=[...I.sections];if(I.skeTables){const y=Array.from(I.skeTables.values());C.push(...y.map(R=>R.rows.map(v=>v.cells.map(b=>b.sections))).flat(4))}for(const y of C)for(const R of y.columns)for(const v of R.lines)if(v.paragraphStart){const b=s.find(O=>O.startIndex===v.paragraphIndex);if(b){const O=v,_=(S=(p=(f=O==null?void 0:O.divides)==null?void 0:f[0])==null?void 0:p.glyphGroup)==null?void 0:S[0];if(!_)continue;const w=cA(_,this._documents,this._skeleton,n);if(!w)continue;r.push({rect:w,segmentId:e,segmentPageIndex:n,paragraph:b})}}}return r};if(e){const m=(h=(u=c.skeFooters.get(e))==null?void 0:u.values())!=null?h:(g=c.skeHeaders.get(e))==null?void 0:g.values();return m?A(Array.from(m)):r}return A(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,i)=>{n.headerId&&this._bulletBounds.push(...this._buildBulletBoundsBySegment(n.headerId,i)),n.footerId&&this._bulletBounds.push(...this._buildBulletBoundsBySegment(n.footerId,i))}))}_calcActiveBullet(e){this._buildBulletBounds();const{offsetX:n,offsetY:i}=e,{x:s,y:r}=ps(n,i,this._context.scene);return this._bulletBounds.find(A=>{const{left:l,right:d,top:u,bottom:g}=A.rect;return s>=l&&s<=d&&r>=u&&r<=g})}},T.DocEventManagerService=sA([aA(1,a.Inject(x.DocSkeletonManagerService))],T.DocEventManagerService);var AA=Object.getOwnPropertyDescriptor,lA=(o,t,e,n)=>{for(var i=n>1?void 0:n?AA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},In=(o,t)=>(e,n)=>t(e,n,o);let Bo=class extends a.Disposable{constructor(o,t,e,n,i){super(),this._context=o,this._docSkeletonManagerService=t,this._commandService=e,this._docEventManagerService=n,this._textSelectionManagerService=i,this._initPointerDownObserver(),this._initHoverCursor()}_initPointerDownObserver(){this._docEventManagerService.clickBullets$.subscribe(o=>{const t=this._textSelectionManagerService.getTextRanges();this._commandService.executeCommand(Vt.id,{index:o.paragraph.startIndex,segmentId:o.segmentId,textRanges:t})})}_initHoverCursor(){this.disposeWithMe(this._docEventManagerService.hoverBullet$.subscribe(o=>{o?this._context.mainComponent.setCursor(B.CURSOR_TYPE.POINTER):this._context.mainComponent.setCursor(B.CURSOR_TYPE.TEXT)}))}_getTransformCoordForDocumentOffset(o,t,e,n){const{documentTransform:i}=o.getOffsetConfig(),s=t.transformVector2SceneCoord(B.Vector2.FromArray([e,n]));if(s)return i.clone().invert().applyPoint(s)}};Bo=lA([In(1,a.Inject(x.DocSkeletonManagerService)),In(2,a.ICommandService),In(3,a.Inject(T.DocEventManagerService)),In(4,a.Inject(x.DocSelectionManagerService))],Bo);var dA=Object.getOwnPropertyDescriptor,uA=(o,t,e,n)=>{for(var i=n>1?void 0:n?dA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Rt=(o,t)=>(e,n)=>t(e,n,o);let En=class extends a.RxDisposable{constructor(o,t,e,n,i,s){super(),this._context=o,this._commandService=t,this._docClipboardService=e,this._docSelectionRenderService=n,this._contextService=i,this._editorService=s,this._init()}_init(){this._initLegacyPasteCommand()}_initLegacyPasteCommand(){var o;(o=this._docSelectionRenderService)==null||o.onPaste$.pipe(N.takeUntil(this.dispose$)).subscribe(t=>{var c,A,l;if(!Zt(this._contextService))return;t.event.preventDefault();const e=t.event;let n=(c=e.clipboardData)==null?void 0:c.getData(E.HTML_CLIPBOARD_MIME_TYPE);const i=(A=e.clipboardData)==null?void 0:A.getData(E.PLAIN_TEXT_CLIPBOARD_MIME_TYPE),s=[...((l=e.clipboardData)==null?void 0:l.items)||[]].filter(d=>E.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:i,files:s})})}};En=uA([Rt(1,a.ICommandService),Rt(2,ot),Rt(3,a.Inject(T.DocSelectionRenderService)),Rt(4,a.IContextService),Rt(5,ce)],En);var hA=Object.getOwnPropertyDescriptor,gA=(o,t,e,n)=>{for(var i=n>1?void 0:n?hA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Ss=(o,t)=>(e,n)=>t(e,n,o);const mA=[a.DEFAULT_EMPTY_DOCUMENT_VALUE,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let Mo=class extends a.Disposable{constructor(o,t,e){super(),this._context=o,this._contextMenuService=t,this._commandService=e,mA.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(i=>{i.button===2&&this._contextMenuService.triggerContextMenu(i,E.ContextMenuPosition.MAIN_AREA)});this.disposeWithMe(t)}_initEditChange(){this.disposeWithMe(this._commandService.onCommandExecuted(o=>{o.id===x.RichTextEditingMutation.id&&this._contextMenuService.visible&&this._contextMenuService.hideContextMenu()}))}};Mo=gA([Ss(1,E.IContextMenuService),Ss(2,a.ICommandService)],Mo);var fA=Object.getOwnPropertyDescriptor,pA=(o,t,e,n)=>{for(var i=n>1?void 0:n?fA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},rt=(o,t)=>(e,n)=>t(e,n,o);let vn=class extends a.Disposable{constructor(t,e,n,i,s,r,c){super();M(this,"_initialEditors",new Set);this._context=t,this._univerInstanceService=e,this._editorService=n,this._commandService=i,this._docSelectionRenderService=s,this._docSkeletonManagerService=r,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 i=this._docSkeletonManagerService.getSkeleton();if(e==null||e.render==null||i==null||n==null)return;i.calculate();const{marginTop:s=0,marginBottom:r=0,marginLeft:c=0,marginRight:A=0}=n.getSnapshot().documentStyle,{scene:l,mainComponent:d}=e.render;let{actualHeight:u,actualWidth:g}=i.getActualSize();u+=s+r,g+=c+A;const{width:h,height:m}=e.getBoundingClientRect(),f=Math.max(g,h),p=Math.max(u,m);l.transformByState({width:f,height:p}),d==null||d.resize(f,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(N.fromEvent(window,"mousedown").subscribe(n=>{const s=n.target.classList[0]||"";a.checkForSubstrings(s,t)&&n.stopPropagation()}));const e=new a.DisposableCollection;this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(n=>{if(e.dispose(),!n)return;const i=n.getUnitId(),s=this._renderManagerService.getRenderById(i),r=s==null?void 0:s.engine.getCanvas().getCanvasEle();if(r==null)return;const c=N.fromEvent(r,"mousedown").subscribe(A=>{A.stopPropagation()});e.add(c)})),this.disposeWithMe(()=>e.dispose())}_commandExecutedListener(){const t=[x.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(t.includes(e.id)){const n=e.params,{unitId:i}=n;if(this._editorService.isSheetEditor(i)||i!==this._context.unitId)return;const s=this._editorService.getEditor(i);s&&!s.params.scrollBar&&this._resize(i)}}))}};vn=pA([rt(1,a.IUniverInstanceService),rt(2,ce),rt(3,a.ICommandService),rt(4,a.Inject(T.DocSelectionRenderService)),rt(5,a.Inject(x.DocSkeletonManagerService)),rt(6,B.IRenderManagerService)],vn);var SA=Object.getOwnPropertyDescriptor,IA=(o,t,e,n)=>{for(var i=n>1?void 0:n?SA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Cn=(o,t)=>(e,n)=>t(e,n,o);let xo=class extends a.Disposable{constructor(t,e,n,i,s){super();M(this,"_previousIMEContent","");M(this,"_isCompositionStart",!0);M(this,"_onStartSubscription");M(this,"_onUpdateSubscription");M(this,"_onEndSubscription");this._context=t,this._docSelectionRenderService=e,this._docImeInputManagerService=n,this._docSkeletonManagerService=i,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(a.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,i=this._docSkeletonManagerService.getSkeleton(),{event:s,activeRange:r}=t;if(i==null||r==null)return;const A=s.data;A===this._previousIMEContent&&e||(await this._commandService.executeCommand(yo.id,{unitId:n,newText:A,oldTextLen:this._previousIMEContent.length,isCompositionStart:this._isCompositionStart,isCompositionEnd:!e}),e?(this._isCompositionStart&&(this._isCompositionStart=!1),this._previousIMEContent=A):this._resetIME())}_resetIME(){this._previousIMEContent="",this._isCompositionStart=!0,this._docImeInputManagerService.clearUndoRedoMutationParamsCache(),this._docImeInputManagerService.setActiveRange(null)}};xo=IA([Cn(1,a.Inject(T.DocSelectionRenderService)),Cn(2,a.Inject(Ot)),Cn(3,a.Inject(x.DocSkeletonManagerService)),Cn(4,a.ICommandService)],xo);var EA=Object.getOwnPropertyDescriptor,vA=(o,t,e,n)=>{for(var i=n>1?void 0:n?EA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Tn=(o,t)=>(e,n)=>t(e,n,o);let _o=class extends a.Disposable{constructor(t,e,n,i,s){super();M(this,"_onInputSubscription");this._context=t,this._docSelectionRenderService=e,this._docSkeletonManagerService=n,this._commandService=i,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;if(t==null)return;const{unitId:e}=this._context,{event:n,content:i="",activeRange:s}=t,r=n,c=this._docSkeletonManagerService.getSkeleton();if(r.data==null||c==null||s==null)return;const{segmentId:A}=s,d=this._context.unit.getSelfOrHeaderFooterModel(A).getBody(),u=this._docMenuStyleService.getDefaultStyle(),g=this._docMenuStyleService.getStyleCache(),h=Rn((p=d==null?void 0:d.customRanges)!=null?p:[],s.endOffset,a.SHEET_EDITOR_UNITS.includes(e)),m=xt(d,s.endOffset,u,g,a.SHEET_EDITOR_UNITS.includes(e)),f=Dn((S=d==null?void 0:d.customDecorations)!=null?S:[],s.endOffset);await this._commandService.executeCommand(Xt.id,{unitId:e,body:{dataStream:i,textRuns:m?[{...m,st:0,ed:i.length}]:[],customRanges:h?[{...h,startIndex:0,endIndex:i.length-1}]:[],customDecorations:f.map(I=>({...I,startIndex:0,endIndex:i.length-1}))},range:s,segmentId:A}),i===" "&&await this._commandService.executeCommand(ut.id)})}};_o=vA([Tn(1,a.Inject(T.DocSelectionRenderService)),Tn(2,a.Inject(x.DocSkeletonManagerService)),Tn(3,a.ICommandService),Tn(4,a.Inject(Ce))],_o);class No extends a.Disposable{constructor(t){super(),this._context=t}calculatePagePosition(){var y,R;const t=Se(this._context),n=(R=(y=this._context.unit.getSettings())==null?void 0:y.zoomRatio)!=null?R:1,{document:i,scene:s,docBackground:r}=t,c=s==null?void 0:s.getParent(),{width:A,height:l,pageMarginLeft:d,pageMarginTop:u}=i;if(c==null||A===Number.POSITIVE_INFINITY||l===Number.POSITIVE_INFINITY)return;const{width:g,height:h}=c;let m=0,f=u,p=0,S=0,I=Number.POSITIVE_INFINITY;g>(A+d*2)*n?(m=g/2-A*n/2,m/=n,p=(g-d*2)/n,I=0):(m=d,p=A+d*2,I=(p-g/n)/2),h>l?S=(h-u*2)/n:S=l+u*2,s.resize(p,S),g<=1&&(m=-1e4,f=-1e4),i.translate(m,f),r.translate(m,f);const C=s.getViewport(he.VIEW_MAIN);return I!==Number.POSITIVE_INFINITY&&C!=null&&C.scrollToViewportPos({viewportScrollX:I}),this}}var CA=Object.getOwnPropertyDescriptor,TA=(o,t,e,n)=>{for(var i=n>1?void 0:n?CA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Is=(o,t)=>(e,n)=>t(e,n,o);let Po=class extends a.Disposable{constructor(o,t,e){super(),this._context=o,this._docPageLayoutService=t,this._textSelectionManagerService=e;const n=this._context.unitId;if(a.isInternalEditorID(n)&&n!==a.DOCS_ZEN_EDITOR_UNIT_ID_KEY)return this;this._initResize()}_initResize(){this.disposeWithMe(a.fromEventSubject(this._context.engine.onTransformChange$).pipe(N.filter(o=>o.type===B.TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize),N.throttleTime(0,N.animationFrameScheduler)).subscribe(()=>{this._docPageLayoutService.calculatePagePosition(),this._textSelectionManagerService.refreshSelection()}))}};Po=TA([Is(1,a.Inject(No)),Is(2,a.Inject(x.DocSelectionManagerService))],Po);var yA=Object.getOwnPropertyDescriptor,bA=(o,t,e,n)=>{for(var i=n>1?void 0:n?yA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},ct=(o,t)=>(e,n)=>t(e,n,o);let Uo=class extends a.Disposable{constructor(t,e,n,i,s,r,c){super();M(this,"_loadedMap",new WeakSet);this._context=t,this._commandService=e,this._editorService=n,this._instanceSrv=i,this._docSelectionRenderService=s,this._docSkeletonManagerService=r,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:i,options:s}=t;e===this._context.unitId&&(this._docSelectionRenderService.removeAllRanges(),this._docSelectionRenderService.addDocRanges(n,i,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:i}=e;this.disposeWithMe(n.onPointerEnter$.subscribeEvent(()=>{this._isEditorReadOnly(t)||(n.cursor=B.CURSOR_TYPE.TEXT)})),this.disposeWithMe(n.onPointerLeave$.subscribeEvent(()=>{n.cursor=B.CURSOR_TYPE.DEFAULT,i.resetCursor()})),this.disposeWithMe(n.onPointerDown$.subscribeEvent((s,r)=>{if(this._isEditorReadOnly(t))return;const c=this._instanceSrv.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);(c==null?void 0:c.getUnitId())!==t&&this._instanceSrv.setCurrentUnitForType(t);const A=this._docSkeletonManagerService.getSkeleton(),{offsetX:l,offsetY:d}=s,u=this._getTransformCoordForDocumentOffset(l,d);if(u!=null){const{pageLayoutType:g=B.PageLayoutType.VERTICAL,pageMarginLeft:h,pageMarginTop:m}=n.getOffsetConfig(),{editArea:f}=A.findEditAreaByCoord(u,g,h,m),p=this._docSkeletonManagerService.getViewModel(),S=p.getEditArea();S!==B.DocumentEditArea.BODY&&f!==B.DocumentEditArea.BODY&&f!==S&&p.setEditArea(f)}if(this._docSelectionRenderService.__onPointDown(s),this._editorService.getEditor(t)){this._setEditorFocus(t);const{offsetX:g,offsetY:h}=s;setTimeout(()=>{t!==this._editorService.getFocusId()&&(this._setEditorFocus(t),this._docSelectionRenderService.setCursorManually(g,h))},0)}s.button!==2&&r.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:i,scene:s}=n,{documentTransform:r}=i.getOffsetConfig(),c=s.getViewports()[0];if(c==null)return;const A=c.transformVector2SceneCoord(B.Vector2.FromArray([t,e]));return r.clone().invert().applyPoint(A)}_isEditorReadOnly(t){const e=this._editorService.getEditor(t);return e?e.isReadOnly():!1}_setEditorFocus(t){this._editorService.focus(t)}_commandExecutedListener(){const t=[ue.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var n;if(t.includes(e.id)){const i=e.params,{unitId:s}=i,r=(n=this._docSelectionManagerService.__getCurrentSelection())==null?void 0:n.unitId;if(s!==r)return;this._docSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe(t=>{if(!t)return;const{unitId:e}=this._context;if(!a.isInternalEditorID(e)){this._docSelectionRenderService.focus();const s=this._context.unit.getSnapshot(),r=di(s);this._docSelectionManagerService.replaceDocRanges([{startOffset:r,endOffset:r}],{unitId:e,subUnitId:e},!1)}}))}};Uo=bA([ct(1,a.ICommandService),ct(2,ce),ct(3,a.IUniverInstanceService),ct(4,a.Inject(T.DocSelectionRenderService)),ct(5,a.Inject(x.DocSkeletonManagerService)),ct(6,a.Inject(x.DocSelectionManagerService))],Uo);var OA=Object.getOwnPropertyDescriptor,RA=(o,t,e,n)=>{for(var i=n>1?void 0:n?OA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Ke=(o,t)=>(e,n)=>t(e,n,o);let wo=class extends a.Disposable{constructor(o,t,e,n,i,s,r,c){super(),this._context=o,this._contextService=t,this._docSkeletonManagerService=e,this._univerInstanceService=n,this._commandService=i,this._textSelectionManagerService=s,this._editorService=r,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(a.FOCUSING_DOC))return;const i=this._univerInstanceService.getCurrentUniverDocInstance();if(!i)return;const{documentFlavor:s}=i.getSnapshot().documentStyle;if(s===a.DocumentFlavor.MODERN)return;const r=Math.abs(n.deltaX);let c=r<40?.2:r<80?.4:.2;c*=n.deltaY>0?-1:1,e.scaleX<1&&(c/=2);const A=i.zoomRatio;let l=+Number.parseFloat(`${A+c}`).toFixed(1);l=l>=4?4:l<=.1?.1:l,this._commandService.executeCommand(dn.id,{zoomRatio:l,unitId:i.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=[ue.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===tn.id&&this._commandService.executeCommand(dn.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()}};wo=RA([Ke(1,a.IContextService),Ke(2,a.Inject(x.DocSkeletonManagerService)),Ke(3,a.IUniverInstanceService),Ke(4,a.ICommandService),Ke(5,a.Inject(x.DocSelectionManagerService)),Ke(6,ce),Ke(7,a.Inject(No))],wo);var DA=Object.getOwnPropertyDescriptor,BA=(o,t,e,n)=>{for(var i=n>1?void 0:n?DA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Dt=(o,t)=>(e,n)=>t(e,n,o);const Es=300;T.DocStateChangeManagerService=class extends a.RxDisposable{constructor(e,n,i,s,r){super();M(this,"_docStateChange$",new N.BehaviorSubject(null));M(this,"docStateChange$",this._docStateChange$.asObservable());M(this,"_historyStateCache",new Map);M(this,"_changeStateCache",new Map);M(this,"_historyTimer",null);M(this,"_changeStateCacheTimer",null);this._undoRedoService=e,this._commandService=n,this._univerInstanceService=i,this._docStateEmitService=s,this._renderManagerService=r,this._initialize(),this._listenDocStateChange()}getStateCache(e){var n,i;return{history:(n=this._historyStateCache.get(e))!=null?n:[],collaboration:(i=this._changeStateCache.get(e))!=null?i:[]}}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===a.UndoCommandId||e.id===a.RedoCommandId){const n=this._univerInstanceService.getCurrentUniverDocInstance();if(n==null)return;const i=n.getUnitId();this._pushHistory(i),this._emitChangeState(i)}}))}_listenDocStateChange(){this._docStateEmitService.docStateChangeParams$.pipe(N.takeUntil(this.dispose$)).subscribe(e=>{var A;if(e==null)return;const{isCompositionEnd:n,isSync:i,syncer:s,...r}=e,c=(A=this._renderManagerService.getRenderById(i?s:e.unitId))==null?void 0:A.with(Ot);if(c!=null){if(n){const l=c.fetchComposedUndoRedoMutationParams();if(l==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:d,redoMutationParams:u,previousActiveRange:g}=l;r.redoState.actions=u.actions,r.undoState.actions=d.actions,r.undoState.textRanges=[g]}this._setChangeState(r)}})}_cacheChangeState(e,n="history"){const{trigger:i,unitId:s,noHistory:r,debounce:c=!1}=e;if(r||i==null||n==="history"&&(i===a.RedoCommandId||i===a.UndoCommandId))return;const A=n==="history"?this._historyStateCache:this._changeStateCache,l=n==="history"?this._pushHistory.bind(this):this._emitChangeState.bind(this);if(A.has(s)){const d=A.get(s);d==null||d.push(e)}else A.set(s,[e]);c?n==="history"?(this._historyTimer&&clearTimeout(this._historyTimer),this._historyTimer=setTimeout(()=>{l(s)},Es)):(this._changeStateCacheTimer&&clearTimeout(this._changeStateCacheTimer),this._changeStateCacheTimer=setTimeout(()=>{l(s)},Es)):l(s)}_pushHistory(e){const n=this._undoRedoService,i=this._historyStateCache.get(e);if(!Array.isArray(i)||i.length===0)return;const s=i.length,r=i[0].commandId,c=i[0],A=i[s-1],l={unitId:e,actions:i.reduce((u,g)=>a.JSONX.compose(u,g.redoState.actions),null),textRanges:A.redoState.textRanges},d={unitId:e,actions:i.reverse().reduce((u,g)=>a.JSONX.compose(u,g.undoState.actions),null),textRanges:c.undoState.textRanges};n.pushUndoRedo({unitID:e,undoMutations:[{id:r,params:d}],redoMutations:[{id:r,params:l}]}),i.length=0}_emitChangeState(e){const n=this._changeStateCache.get(e);if(!Array.isArray(n)||n.length===0)return;const i=n.length,{commandId:s,trigger:r,segmentId:c,noHistory:A,debounce:l}=n[0],d=n[0],u=n[i-1],g={unitId:e,actions:n.reduce((f,p)=>a.JSONX.compose(f,p.redoState.actions),null),textRanges:u.redoState.textRanges},h={unitId:e,actions:n.reverse().reduce((f,p)=>a.JSONX.compose(f,p.undoState.actions),null),textRanges:d.undoState.textRanges},m={commandId:s,unitId:e,trigger:r,redoState:g,undoState:h,segmentId:c,noHistory:A,debounce:l};n.length=0,this._docStateChange$.next(m)}},T.DocStateChangeManagerService=BA([Dt(0,a.Inject(a.IUndoRedoService)),Dt(1,a.ICommandService),Dt(2,a.IUniverInstanceService),Dt(3,a.Inject(x.DocStateEmitService)),Dt(4,B.IRenderManagerService)],T.DocStateChangeManagerService);var MA=Object.getOwnPropertyDescriptor,xA=(o,t,e,n)=>{for(var i=n>1?void 0:n?MA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},vs=(o,t)=>(e,n)=>t(e,n,o);const Cs="univer-doc-main-canvas";T.DocsRenderService=class extends a.RxDisposable{constructor(t,e){super(),this._instanceSrv=t,this._renderManagerService=e,this._init()}_init(){this._renderManagerService.createRender$.pipe(N.takeUntil(this.dispose$)).subscribe(t=>this._createRenderWithId(t)),this._instanceSrv.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC).forEach(t=>this._createRenderer(t)),this._instanceSrv.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_DOC).pipe(N.takeUntil(this.dispose$)).subscribe(t=>this._createRenderer(t)),this._instanceSrv.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_DOC).pipe(N.takeUntil(this.dispose$)).subscribe(t=>this._disposeRenderer(t))}_createRenderer(t){var i;const e=t.getUnitId(),n=(i=this._instanceSrv.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC))==null?void 0:i.getUnitId();this._renderManagerService.created$.subscribe(s=>{s.unitId===n&&(s.engine.getCanvas().setId(Cs),s.engine.getCanvas().getContext().setId(Cs))}),this._renderManagerService.has(e)||this._createRenderWithId(e)}_createRenderWithId(t){this._renderManagerService.createRender(t)}_disposeRenderer(t){const e=t.getUnitId();this._renderManagerService.removeRender(e)}},T.DocsRenderService=xA([vs(0,a.IUniverInstanceService),vs(1,B.IRenderManagerService)],T.DocsRenderService);class Ts extends a.Disposable{constructor(){super(...arguments);M(this,"_currentSelectorId");M(this,"_selectionChange$",new N.Subject);M(this,"selectionChange$",this._selectionChange$.asObservable());M(this,"_openSelector$",new N.Subject);M(this,"openSelector$",this._openSelector$.asObservable());M(this,"_selectorModalVisible$",new N.BehaviorSubject(!1));M(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 ys=a.createIdentifier("univer.range-selector.service"),_A={id:qe.id,preconditions:ya,binding:E.KeyCode.ENTER},NA={id:Ct.id,preconditions:ee,binding:E.KeyCode.BACKSPACE},PA={id:so.id,preconditions:ee,binding:E.KeyCode.DELETE},UA={id:Ee.id,binding:E.KeyCode.ARROW_UP,preconditions:ee,staticParameters:{direction:a.Direction.UP}},wA={id:Ee.id,binding:E.KeyCode.ARROW_DOWN,preconditions:ee,staticParameters:{direction:a.Direction.DOWN}},QA={id:Ee.id,binding:E.KeyCode.ARROW_LEFT,preconditions:ee,staticParameters:{direction:a.Direction.LEFT}},LA={id:Ee.id,binding:E.KeyCode.ARROW_RIGHT,preconditions:ee,staticParameters:{direction:a.Direction.RIGHT}},FA={id:ve.id,binding:E.KeyCode.ARROW_UP|E.MetaKeys.SHIFT,preconditions:ee,staticParameters:{direction:a.Direction.UP}},kA={id:ve.id,binding:E.KeyCode.ARROW_DOWN|E.MetaKeys.SHIFT,preconditions:ee,staticParameters:{direction:a.Direction.DOWN}},HA={id:ve.id,binding:E.KeyCode.ARROW_LEFT|E.MetaKeys.SHIFT,preconditions:ee,staticParameters:{direction:a.Direction.LEFT}},VA={id:ve.id,binding:E.KeyCode.ARROW_RIGHT|E.MetaKeys.SHIFT,preconditions:ee,staticParameters:{direction:a.Direction.RIGHT}},WA={id:To.id,binding:E.KeyCode.A|E.MetaKeys.CTRL_COMMAND,preconditions:o=>o.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&(o.getContextValue(a.FOCUSING_DOC)||o.getContextValue(a.EDITOR_ACTIVATED))};var KA=Object.defineProperty,zA=Object.getOwnPropertyDescriptor,jA=(o,t,e)=>t in o?KA(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,GA=(o,t,e,n)=>{for(var i=n>1?void 0:n?zA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Bt=(o,t)=>(e,n)=>t(e,n,o),XA=(o,t,e)=>jA(o,t+"",e);T.UniverDocsUIPlugin=class extends a.Plugin{constructor(t=Qi,e,n,i,s,r){super(),this._config=t,this._injector=e,this._renderManagerSrv=n,this._commandService=i,this._logService=s,this._configService=r;const{menu:c,...A}=a.merge({},Qi,this._config);c&&this._configService.setConfig("menu",c,{merge:!0}),this._configService.setConfig($n,A),this._initDependencies(e),this._initializeShortcut(),this._initCommand()}onReady(){this._initRenderBasics(),this._markDocAsFocused(),a.touchDependencies(this._injector,[[T.DocStateChangeManagerService],[T.DocsRenderService]])}onRendered(){this._initUI(),this._initRenderModules(),a.touchDependencies(this._injector,[[hn],[mn],[st],[fn],[T.DocUIController]])}_initCommand(){[Ct,so,_e,Ne,Pe,Ue,Re,we,Qe,Le,Fe,Je,ke,Te,fo,Xt,et,Yt,io,qt,ue,ft,mt,Ze,pt,St,It,ge,Et,po,go,sn,an,$i,rn,cn,nn,on,it,Gn,bo,xe,ut,qe,kt,ht,Ht,Vt,Zn,yo,tn,me,oo,He,Xo,Bn,Yo,dn,To,Eo,Ee,ve,Jo].forEach(t=>{this._commandService.registerCommand(t)}),[yt,$t,en].forEach(t=>this.disposeWithMe(this._commandService.registerMultipleCommand(t)))}_initializeShortcut(){[UA,wA,LA,QA,FA,kA,HA,VA,WA,NA,PA,_A,Oa].forEach(t=>{this._injector.get(E.IShortcutService).registerShortcut(t)})}_initDependencies(t){a.mergeOverrideWithDependencies([[En],[vn],[T.DocUIController],[hn],[fn],[mn],[un],[st],[ce,{useClass:T.EditorService}],[ys,{useClass:Ts}],[ot,{useClass:Ao}],[T.DocCanvasPopManagerService],[T.DocsRenderService],[T.DocStateChangeManagerService],[T.DocAutoFormatService],[Ce]],this._config.override).forEach(n=>t.add(n))}_markDocAsFocused(){const t=this._injector.get(a.IUniverInstanceService),e=this._injector.get(ce);try{const n=t.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(!n)return;const i=n.getUnitId();e.isEditor(i)||t.focusUnit(n.getUnitId())}catch(n){this._logService.warn(n)}}_initUI(){this._injector.get(un)}_initRenderBasics(){[[x.DocSkeletonManagerService],[T.DocSelectionRenderService],[x.DocInterceptorService],[No],[Ot],[T.DocRenderController],[wo]].forEach(t=>{this._renderManagerSrv.registerRenderModule(a.UniverInstanceType.UNIVER_DOC,t)})}_initRenderModules(){[[T.DocEventManagerService],[T.DocBackScrollRenderController],[Uo],[Wn],[Po],[Mo],[Bo],[En],[_o],[xo],[vn]].forEach(t=>{this._renderManagerSrv.registerRenderModule(a.UniverInstanceType.UNIVER_DOC,t)})}},XA(T.UniverDocsUIPlugin,"pluginName",Ho),T.UniverDocsUIPlugin=GA([a.DependentOn(B.UniverRenderEnginePlugin),Bt(1,a.Inject(a.Injector)),Bt(2,B.IRenderManagerService),Bt(3,a.ICommandService),Bt(4,a.ILogService),Bt(5,a.IConfigService)],T.UniverDocsUIPlugin),T.AfterSpaceCommand=ut,T.AlignCenterCommand=St,T.AlignJustifyCommand=Et,T.AlignLeftCommand=pt,T.AlignOperationCommand=ge,T.AlignRightCommand=It,T.BreakLineCommand=fo,T.BulletListCommand=mt,T.ChangeListNestingLevelCommand=kt,T.ChangeListNestingLevelType=gt,T.ChangeListTypeCommand=ht,T.CheckListCommand=Ht,T.CoverContentCommand=Yo,T.CreateDocTableCommand=po,T.CutContentCommand=He,T.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX=Vo,T.DOCS_COMPONENT_DEFAULT_Z_INDEX=On,T.DOCS_COMPONENT_HEADER_LAYER_INDEX=Wo,T.DOCS_COMPONENT_MAIN_LAYER_INDEX=Mt,T.DOCS_VIEW_KEY=le,T.DOC_UI_PLUGIN_NAME=Ho,T.DOC_VERTICAL_PADDING=Do,T.DefaultDocContainerConfig=ko,T.DefaultToolbarConfig=Fo,T.DeleteCommand=et,T.DeleteCustomBlockCommand=Yt,T.DeleteLeftCommand=Ct,T.DeleteRightCommand=so,T.DocCopyCommand=yt,T.DocCreateTableOperation=An,T.DocCutCommand=$t,T.DocIMEInputManagerService=Ot,T.DocPasteCommand=en,T.DocSelectAllCommand=To,T.DocTableDeleteColumnsCommand=on,T.DocTableDeleteRowsCommand=nn,T.DocTableDeleteTableCommand=it,T.DocTableInsertColumnCommand=$i,T.DocTableInsertColumnLeftCommand=rn,T.DocTableInsertColumnRightCommand=cn,T.DocTableInsertRowAboveCommand=sn,T.DocTableInsertRowBellowCommand=an,T.DocTableInsertRowCommand=go,T.DocTableTabCommand=bo,T.DocsUIMenuSchema=as,T.Editor=ii,T.EditorInsertTextCommandId=Wi,T.EnterCommand=qe,T.IDocClipboardService=ot,T.IEditorService=ce,T.IMEInputCommand=yo,T.IRangeSelectorService=ys,T.InnerPasteCommand=oo,T.InsertCommand=Xt,T.ListOperationCommand=Ze,T.MergeTwoParagraphCommand=qt,T.MoveCursorOperation=Ee,T.MoveSelectionOperation=ve,T.NORMAL_TEXT_SELECTION_PLUGIN_NAME=Ms,T.NodePositionConvertToCursor=Ie,T.NodePositionConvertToRectRange=wn,T.OrderListCommand=ft,T.PastePluginLark=Gi,T.PastePluginUniver=Yi,T.PastePluginWord=qi,T.QuickListCommand=Zn,T.RangeSelectorService=Ts,T.RectRange=Ln,T.ReplaceContentCommand=Xo,T.ReplaceSnapshotCommand=Bn,T.ReplaceTextRunsCommand=Jo,T.ResetInlineFormatTextBackgroundColorCommand=Je,T.RichTextEditor=na,T.SetDocZoomRatioCommand=dn,T.SetDocZoomRatioOperation=ue,T.SetInlineFormatBoldCommand=_e,T.SetInlineFormatCommand=Te,T.SetInlineFormatFontFamilyCommand=Le,T.SetInlineFormatFontSizeCommand=Qe,T.SetInlineFormatItalicCommand=Ne,T.SetInlineFormatStrikethroughCommand=Ue,T.SetInlineFormatSubscriptCommand=Re,T.SetInlineFormatSuperscriptCommand=we,T.SetInlineFormatTextBackgroundColorCommand=ke,T.SetInlineFormatTextColorCommand=Fe,T.SetInlineFormatUnderlineCommand=Pe,T.TEXT_RANGE_LAYER_INDEX=Nt,T.TabCommand=xe,T.TextRange=Me,T.ToggleCheckListCommand=Vt,T.UpdateCommand=io,T.VIEWPORT_KEY=he,T.addCustomDecorationBySelectionFactory=_s,T.addCustomDecorationFactory=zo,T.calcDocRangePositions=Sn,T.convertPositionsToRectRanges=Ut,T.deleteCustomDecorationFactory=Ns,T.docDrawingPositionToTransform=Us,T.genTableSource=to,T.generateParagraphs=mo,T.getAnchorBounding=lt,T.getCanvasOffsetByEngine=ni,T.getCommandSkeleton=re,T.getCursorWhenDelete=Jt,T.getCustomBlockIdsInSelections=Hi,T.getCutActionsFromDocRanges=Vi,T.getDocObject=Ko,T.getDocObjectById=xs,T.getEmptyTableCell=zt,T.getEmptyTableRow=jt,T.getLineBounding=Pt,T.getOneTextSelectionRange=_n,T.getParagraphsInRange=Wt,T.getParagraphsInRanges=$e,T.getRichTextEditPath=$,T.getTableColumn=Gt,T.hasParagraphInTable=Ps,T.isInSameTableCell=Pn,T.isValidRectRange=Zo,T.neoGetDocObject=Se,T.transformToDocDrawingPosition=ws,T.useKeyboardEvent=jo,T.useResize=Go,T.whenDocAndEditorFocused=ee,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});
39
+ `,style:{width:162},children:[L.jsx(ne.Select,{value:`${C}`,options:[{label:o.t("doc.paragraphSetting.multiSpace"),value:`${a.SpacingRule.AUTO}`},{label:o.t("doc.paragraphSetting.fixedValue"),value:`${a.SpacingRule.AT_LEAST}`}],onChange:v=>y(Number(v))}),L.jsx(Ve,{...R,value:S,onChange:v=>I(v!=null?v:0)})]})]})]})]})}const kr=(o,t)=>t.length===o.length&&o.some(e=>t.some(n=>n.startOffset===e.startOffset&&n.endOffset===e.endOffset));function Hr(){const o=E.useDependency(a.ICommandService),t=E.useDependency(a.LocaleService),e=E.useObservable(t.currentLocale$),[n,i]=F.useState(""),s=F.useMemo(()=>a.debounce(()=>i(a.generateRandomId(4)),300),[]),r=F.useRef([]);return F.useEffect(()=>{const c=o.onCommandExecuted(A=>{if(x.SetTextSelectionsOperation.id===A.id){const l=A.params.ranges;kr(l,r.current)||i(a.generateRandomId(4)),r.current=l}x.RichTextEditingMutation.id===A.id&&A.params.trigger!==me.id&&s()});return()=>c.dispose()},[s]),F.useEffect(()=>{i(a.generateRandomId(4))},[e]),F.useEffect(()=>()=>s.cancel(),[s]),L.jsx(Fr,{},n)}var Vr=Object.getOwnPropertyDescriptor,Wr=(o,t,e,n)=>{for(var i=n>1?void 0:n?Vr(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Io=(o,t)=>(e,n)=>t(e,n,o);const ts="doc_ui_paragraph-setting-panel";let st=class extends a.Disposable{constructor(t,e,n){super();M(this,"_id");this._commandService=t,this._componentManager=e,this._sidebarService=n,this._init()}_init(){this.disposeWithMe(this._componentManager.register(ts,Hr))}openPanel(){const t={header:{title:"doc.slider.paragraphSetting"},id:this._id,children:{label:ts},width:300};this._sidebarService.open(t)}closePanel(){this._sidebarService.close(this._id)}};st=Wr([Io(0,a.ICommandService),Io(1,a.Inject(E.ComponentManager)),Io(2,a.Inject(E.ISidebarService))],st);const Eo={id:"sidebar.operation.doc-paragraph-setting-panel",type:a.CommandType.OPERATION,handler:o=>(o.get(st).openPanel(),!0)},vo=o=>{const t=o.get(x.DocSelectionManagerService);return new N.Observable(e=>{const n=t.textSelection$.subscribe(()=>{t.getDocRanges().some(r=>r.collapsed===!1||r.rangeType===a.DOC_RANGE_TYPE.RECT)?e.next(!1):e.next(!0)});return()=>n.unsubscribe()})};function Kr(o){if(o.length<2)return!0;const t=o.map(e=>e.tableId);return t.every(e=>e===t[0])}function ns(o,t,e){var s;const n=t.getRectRanges(),i=t.getActiveTextRange();if(n&&n.length&&Kr(n)&&i==null){o.next(!1);return}if(i&&(n==null||n.length===0)){const{segmentId:r,startOffset:c,endOffset:A}=i,l=e.getCurrentUniverDocInstance(),d=(s=l==null?void 0:l.getSelfOrHeaderFooterModel(r).getBody())==null?void 0:s.tables;if(d&&d.length&&d.some(u=>{const{startIndex:g,endIndex:h}=u;return c>g&&c<h||A>g&&A<h})){o.next(!1);return}}o.next(!0)}const ye=o=>{const t=o.get(x.DocSelectionManagerService),e=o.get(a.IUniverInstanceService);return new N.Observable(n=>{const i=t.textSelection$.subscribe(()=>{ns(n,t,e)});return ns(n,t,e),()=>i.unsubscribe()})},zr=o=>({id:yt.name,commandId:yt.id,type:E.MenuItemType.BUTTON,icon:"Copy",title:"rightClick.copy",disabled$:vo(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}),jr=o=>({id:Eo.id,type:E.MenuItemType.BUTTON,icon:"MenuSingle24",title:"doc.menu.paragraphSetting",hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}),Gr=o=>({id:$t.id,type:E.MenuItemType.BUTTON,icon:"Copy",title:"rightClick.cut",disabled$:vo(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}),Xr=o=>({id:en.id,type:E.MenuItemType.BUTTON,icon:"PasteSpecial",title:"rightClick.paste",hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}),Yr=o=>({id:Ct.id,type:E.MenuItemType.BUTTON,icon:"PasteSpecial",title:"rightClick.delete",disabled$:vo(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}),os="doc.menu.table-insert";function qr(o){return{id:os,type:E.MenuItemType.SUBITEMS,title:"table.insert",icon:"Insert",hidden$:N.combineLatest(E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC),ye(o),(t,e)=>t||e)}}function Jr(o){return{id:sn.id,type:E.MenuItemType.BUTTON,title:"table.insertRowAbove",icon:"InsertRowAbove",disabled$:ye(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function Zr(o){return{id:an.id,type:E.MenuItemType.BUTTON,title:"table.insertRowBelow",icon:"InsertRowBelow",disabled$:ye(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function $r(o){return{id:rn.id,type:E.MenuItemType.BUTTON,title:"table.insertColumnLeft",icon:"LeftInsertColumn",disabled$:ye(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function ec(o){return{id:cn.id,type:E.MenuItemType.BUTTON,title:"table.insertColumnRight",icon:"RightInsertColumn",disabled$:ye(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}const is="doc.menu.table-delete";function tc(o){return{id:is,type:E.MenuItemType.SUBITEMS,title:"table.delete",icon:"Reduce",hidden$:N.combineLatest(E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC),ye(o),(t,e)=>t||e)}}function nc(o){return{id:nn.id,type:E.MenuItemType.BUTTON,title:"table.deleteRows",icon:"DeleteRow",disabled$:ye(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function oc(o){return{id:on.id,type:E.MenuItemType.BUTTON,title:"table.deleteColumns",icon:"DeleteColumn",disabled$:ye(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function ic(o){return{id:it.id,type:E.MenuItemType.BUTTON,title:"table.deleteTable",icon:"GridSingle",disabled$:ye(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function sc(o){const t=o.get(a.IUniverInstanceService),e=o.get(B.IRenderManagerService);return new N.Observable(n=>{const i=t.focused$.subscribe(s=>{if(s==null||t.getUnitType(s)!==a.UniverInstanceType.UNIVER_DOC)return n.next(!0);const c=e.getRenderById(s);if(c==null)return n.next(!0);c.with(x.DocSkeletonManagerService).getViewModel().editAreaChange$.subscribe(l=>{n.next(l===B.DocumentEditArea.HEADER||l===B.DocumentEditArea.FOOTER)})});return()=>i.unsubscribe()})}function ac(o){const t=o.get(a.IUniverInstanceService),e=o.get(a.ICommandService);return new N.Observable(n=>{const i=e.onCommandExecuted(A=>{if(A.id===x.RichTextEditingMutation.id){const{unitId:l}=A.params,d=t.getUnit(l);if(d==null){n.next(!0);return}const{documentStyle:u}=d.getSnapshot();n.next((u==null?void 0:u.documentFlavor)!==a.DocumentFlavor.TRADITIONAL)}}),s=t.focused$.subscribe(A=>{if(A==null)return n.next(!0);const l=t.getUniverDocInstance(A),d=l==null?void 0:l.getSnapshot().documentStyle.documentFlavor;n.next(d!==a.DocumentFlavor.TRADITIONAL)}),r=t.getCurrentUniverDocInstance();if(r==null)return n.next(!0);const c=r==null?void 0:r.getSnapshot().documentStyle.documentFlavor;return n.next(c!==a.DocumentFlavor.TRADITIONAL),()=>{i.dispose(),s.unsubscribe()}})}function rc(o){const t=o.get(x.DocSelectionManagerService),e=o.get(a.IUniverInstanceService);return new N.Observable(n=>{const i=t.textSelection$.subscribe(s=>{if(s==null){n.next(!0);return}const{textRanges:r}=s;if(r.length!==1){n.next(!0);return}const c=r[0],{collapsed:A,startNodePosition:l,startOffset:d}=c;if(!A||d==null){n.next(!0);return}const u=e.getCurrentUniverDocInstance();if(u==null){n.next(!0);return}const g=re(o,u.getUnitId());if(g==null){n.next(!0);return}if(g.getViewModel().getCustomRangeRaw(d)){n.next(!0);return}if(l!=null){const{path:f}=l;if(f.indexOf("cells")!==-1){n.next(!0);return}}n.next(!1)});return()=>i.unsubscribe()})}function te(o){const t=o.get(x.DocSelectionManagerService);return new N.Observable(e=>{const n=t.textSelection$.subscribe(i=>{if(i==null){e.next(!0);return}const{textRanges:s,rectRanges:r}=i;if(s.length===0&&r.length===0){e.next(!0);return}e.next(!1)});return()=>n.unsubscribe()})}function cc(o){const t=o.get(a.ICommandService);return{id:_e.id,type:E.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",activated$:new N.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===x.SetTextSelectionsOperation.id||s===Te.id){const c=De(o);if(c==null){e.next(!1);return}const A=(r=c.ts)==null?void 0:r.bl;e.next(A===a.BooleanNumber.TRUE)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function Ac(o){const t=o.get(a.ICommandService);return{id:Ne.id,type:E.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",activated$:new N.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===x.SetTextSelectionsOperation.id||s===Te.id){const c=De(o);if(c==null){e.next(!1);return}const A=(r=c.ts)==null?void 0:r.it;e.next(A===a.BooleanNumber.TRUE)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function lc(o){const t=o.get(a.ICommandService);return{id:Pe.id,type:E.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",activated$:new N.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===x.SetTextSelectionsOperation.id||s===Te.id){const c=De(o);if(c==null){e.next(!1);return}const A=(r=c.ts)==null?void 0:r.ul;e.next((A==null?void 0:A.s)===a.BooleanNumber.TRUE)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function dc(o){const t=o.get(a.ICommandService);return{id:Ue.id,type:E.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",activated$:new N.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===x.SetTextSelectionsOperation.id||s===Te.id){const c=De(o);if(c==null){e.next(!1);return}const A=(r=c.ts)==null?void 0:r.st;e.next((A==null?void 0:A.s)===a.BooleanNumber.TRUE)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function uc(o){const t=o.get(a.ICommandService);return{id:Re.id,type:E.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",activated$:new N.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===x.SetTextSelectionsOperation.id||s===Te.id){const c=De(o);if(c==null){e.next(!1);return}const A=(r=c.ts)==null?void 0:r.va;e.next(A===a.BaselineOffset.SUBSCRIPT)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function hc(o){const t=o.get(a.ICommandService);return{id:we.id,type:E.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",activated$:new N.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===x.SetTextSelectionsOperation.id||s===Te.id){const c=De(o);if(c==null){e.next(!1);return}const A=(r=c.ts)==null?void 0:r.va;e.next(A===a.BaselineOffset.SUPERSCRIPT)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function gc(o){const t=o.get(a.ICommandService);return{id:Le.id,tooltip:"toolbar.font",type:E.MenuItemType.SELECTOR,label:Si,selections:E.FONT_FAMILY_LIST.map(e=>({label:{name:Ii},value:e.value})),value$:new N.Observable(e=>{const n=a.DEFAULT_STYLES.ff,i=t.onCommandExecuted(s=>{var c;const r=s.id;if(r===x.SetTextSelectionsOperation.id||r===Le.id){const A=De(o);if(A==null){e.next(n);return}const l=(c=A.ts)==null?void 0:c.ff;e.next(l!=null?l:n)}});return e.next(n),i.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function mc(o){const t=o.get(a.ICommandService);return{id:Qe.id,type:E.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Ei,props:{min:1,max:400}},selections:E.FONT_SIZE_LIST,value$:new N.Observable(e=>{const n=a.DEFAULT_STYLES.fs,i=t.onCommandExecuted(s=>{var c;const r=s.id;if(r===x.SetTextSelectionsOperation.id||r===Qe.id){const A=De(o);if(A==null){e.next(n);return}const l=(c=A.ts)==null?void 0:c.fs;e.next(l!=null?l:n)}});return e.next(n),i.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function fc(o){const t=o.get(a.ICommandService),e=o.get(a.ThemeService);return{id:Fe.id,icon:"FontColor",tooltip:"toolbar.textColor.main",type:E.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:Xn,hoverable:!1,selectable:!1}}],value$:new N.Observable(n=>{const i=e.getCurrentTheme().textColor,s=t.onCommandExecuted(r=>{if(r.id===Fe.id){const c=r.params.value;n.next(c!=null?c:i)}});return n.next(i),s.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function pc(o){return{id:jn.id,type:E.MenuItemType.BUTTON,icon:"HeaderFooterSingle",tooltip:"toolbar.headerFooter",hidden$:N.combineLatest(E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY),ac(o),(t,e)=>t||e)}}const Sc="GridSingle",ss="doc.menu.table";function Ic(o){return{id:ss,type:E.MenuItemType.SUBITEMS,icon:Sc,tooltip:"toolbar.table.main",disabled$:rc(o),hidden$:N.combineLatest(E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY),sc(o),(t,e)=>t||e)}}function Ec(o){return{id:An.id,title:"toolbar.table.insert",type:E.MenuItemType.BUTTON,hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function vc(o){const t=o.get(a.ICommandService);return{id:pt.id,type:E.MenuItemType.BUTTON,icon:"LeftJustifyingSingle",tooltip:"toolbar.alignLeft",disabled$:te(o),activated$:new N.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===x.SetTextSelectionsOperation.id||s===ge.id){const c=ln(o);if(c==null)return;const A=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(A===a.HorizontalAlign.LEFT)}});return e.next(!1),n.dispose}),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Cc(o){const t=o.get(a.ICommandService);return{id:St.id,type:E.MenuItemType.BUTTON,icon:"HorizontallySingle",tooltip:"toolbar.alignCenter",activated$:new N.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===x.SetTextSelectionsOperation.id||s===ge.id){const c=ln(o);if(c==null)return;const A=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(A===a.HorizontalAlign.CENTER)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Tc(o){const t=o.get(a.ICommandService);return{id:It.id,type:E.MenuItemType.BUTTON,icon:"RightJustifyingSingle",tooltip:"toolbar.alignRight",activated$:new N.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===x.SetTextSelectionsOperation.id||s===ge.id){const c=ln(o);if(c==null)return;const A=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(A===a.HorizontalAlign.RIGHT)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function yc(o){const t=o.get(a.ICommandService);return{id:Et.id,type:E.MenuItemType.BUTTON,icon:"AlignTextBothSingle",tooltip:"toolbar.alignJustify",activated$:new N.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===x.SetTextSelectionsOperation.id||s===ge.id){const c=ln(o);if(c==null)return;const A=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(A===a.HorizontalAlign.JUSTIFIED)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}const bt=o=>new N.Observable(t=>{const e=o.get(a.IUniverInstanceService),n=o.get(x.DocSelectionManagerService);let i;const s=e.focused$.subscribe(r=>{if(i==null||i.unsubscribe(),r==null)return;const c=e.getUniverDocInstance(r);c!=null&&(i=n.textSelection$.subscribe(()=>{var d,u,g;const A=n.getDocRanges(),l=(d=A.find(h=>h.isActive))!=null?d:A[0];if(l){const h=c.getSelfOrHeaderFooterModel(l==null?void 0:l.segmentId),m=Wt(l,(g=(u=h.getBody())==null?void 0:u.paragraphs)!=null?g:[]);let f;if(m.every(p=>{var S;return f||(f=(S=p.bullet)==null?void 0:S.listType),p.bullet&&p.bullet.listType===f})){t.next(f);return}}t.next(void 0)}))});return()=>{s.unsubscribe(),i==null||i.unsubscribe()}});function bc(o){return{id:ft.id,type:E.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:Ci,hoverable:!1,selectable:!1},value$:bt(o)}],icon:"OrderSingle",tooltip:"toolbar.order",hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC),disabled$:te(o),activated$:bt(o).pipe(N.map(t=>t&&t.indexOf("ORDER_LIST")===0))}}function Oc(o){return{id:mt.id,type:E.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:Ti,hoverable:!1,selectable:!1},value$:bt(o)}],icon:"UnorderSingle",tooltip:"toolbar.unorder",disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC),activated$:bt(o).pipe(N.map(t=>t&&t.indexOf("BULLET_LIST")===0))}}function Rc(o){return{id:Ht.id,type:E.MenuItemType.BUTTON,icon:"TodoList",tooltip:"toolbar.checklist",disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC),activated$:bt(o).pipe(N.map(t=>t&&t.indexOf("CHECK_LIST")===0))}}function Dc(o){const t=o.get(a.ICommandService),e=o.get(a.IUniverInstanceService);return{id:tn.id,type:E.MenuItemType.BUTTON,icon:"KeyboardSingle",tooltip:"toolbar.documentFlavor",hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY),activated$:new N.Observable(n=>{var r;const i=t.onCommandExecuted(c=>{var A;if(c.id===x.RichTextEditingMutation.id){const l=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);n.next(((A=l==null?void 0:l.getSnapshot())==null?void 0:A.documentStyle.documentFlavor)===a.DocumentFlavor.MODERN)}}),s=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);return n.next(((r=s==null?void 0:s.getSnapshot())==null?void 0:r.documentStyle.documentFlavor)===a.DocumentFlavor.MODERN),()=>i.dispose()})}}function Bc(o){return{id:Je.id,type:E.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor"}}function Mc(o){const t=o.get(a.ICommandService),e=o.get(a.ThemeService);return{id:ke.id,tooltip:"toolbar.fillColor.main",type:E.MenuItemType.BUTTON_SELECTOR,icon:"PaintBucket",selections:[{label:{name:Xn,hoverable:!1,selectable:!1}}],value$:new N.Observable(n=>{const i=e.getCurrentTheme().primaryColor,s=t.onCommandExecuted(r=>{if(r.id===ke.id){const c=r.params.value;n.next(c!=null?c:i)}});return n.next(i),s.dispose}),disabled$:te(o),hidden$:E.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function De(o){var g,h;const t=o.get(a.IUniverInstanceService),e=o.get(x.DocSelectionManagerService),n=o.get(Ce),i=t.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),s=e.getDocRanges(),r=(g=s.find(m=>m.isActive))!=null?g:s[0],c=n.getDefaultStyle(),A=(h=n.getStyleCache())!=null?h:{};if(i==null||r==null)return{ts:{...c,...A}};const{segmentId:l}=r,d=i.getSelfOrHeaderFooterModel(l).getBody();return d==null?{ts:{...c,...A}}:{ts:{...wi(d,r,c),...A}}}function ln(o){var d,u;const t=o.get(a.IUniverInstanceService),e=o.get(x.DocSelectionManagerService),n=t.getCurrentUniverDocInstance(),i=e.getDocRanges(),s=(d=i.find(g=>g.isActive))!=null?d:i[0];if(n==null||s==null)return;const{startOffset:r,segmentId:c}=s,A=(u=n.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:u.paragraphs;if(A==null)return;let l=-1;for(const g of A){const{startIndex:h}=g;if(r>l&&r<=h)return g;l=h}return null}const as={[E.RibbonStartGroup.FORMAT]:{[_e.id]:{order:0,menuItemFactory:cc},[Ne.id]:{order:1,menuItemFactory:Ac},[Pe.id]:{order:2,menuItemFactory:lc},[Ue.id]:{order:3,menuItemFactory:dc},[Re.id]:{order:4,menuItemFactory:uc},[we.id]:{order:5,menuItemFactory:hc},[Qe.id]:{order:6,menuItemFactory:mc},[Le.id]:{order:7,menuItemFactory:gc},[Fe.id]:{order:8,menuItemFactory:fc},[ke.id]:{order:9,menuItemFactory:Mc,[Je.id]:{order:0,menuItemFactory:Bc}}},[E.RibbonStartGroup.LAYOUT]:{[ss]:{order:1,menuItemFactory:Ic,[An.id]:{order:0,menuItemFactory:Ec}},[pt.id]:{order:2,menuItemFactory:vc},[St.id]:{order:3,menuItemFactory:Cc},[It.id]:{order:4,menuItemFactory:Tc},[Et.id]:{order:5,menuItemFactory:yc},[ft.id]:{order:6,menuItemFactory:bc},[mt.id]:{order:7,menuItemFactory:Oc},[Ht.id]:{order:8,menuItemFactory:Rc},[jn.id]:{order:9,menuItemFactory:pc},[tn.id]:{order:10,menuItemFactory:Dc}},[E.ContextMenuPosition.MAIN_AREA]:{[E.ContextMenuGroup.FORMAT]:{[yt.name]:{order:0,menuItemFactory:zr},[$t.id]:{order:1,menuItemFactory:Gr},[en.id]:{order:2,menuItemFactory:Xr},[Ct.id]:{order:3,menuItemFactory:Yr}},[E.ContextMenuGroup.LAYOUT]:{[Eo.id]:{order:0,menuItemFactory:jr},[os]:{order:1,menuItemFactory:qr,[sn.id]:{order:1,menuItemFactory:Jr},[an.id]:{order:2,menuItemFactory:Zr},[rn.id]:{order:3,menuItemFactory:$r},[cn.id]:{order:4,menuItemFactory:ec}},[is]:{order:2,menuItemFactory:tc,[nn.id]:{order:1,menuItemFactory:nc},[on.id]:{order:2,menuItemFactory:oc},[it.id]:{order:3,menuItemFactory:ic}}}}};var xc=Object.getOwnPropertyDescriptor,_c=(o,t,e,n)=>{for(var i=n>1?void 0:n?xc(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},be=(o,t)=>(e,n)=>t(e,n,o);T.DocUIController=class extends a.Disposable{constructor(t,e,n,i,s,r,c,A,l){super(),this._injector=t,this._componentManager=e,this._commandService=n,this._layoutService=i,this._menuManagerService=s,this._uiPartsService=r,this._univerInstanceService=c,this._shortcutService=A,this._configService=l,this._init()}_initCustomComponents(){const t=this._componentManager;this.disposeWithMe(t.register(Xn,ne.ColorPicker)),this.disposeWithMe(t.register(Si,E.FontFamily)),this.disposeWithMe(t.register(Ii,E.FontFamilyItem)),this.disposeWithMe(t.register(Ei,E.FontSize)),this.disposeWithMe(t.register(Ti,Ta)),this.disposeWithMe(t.register(Ci,va)),this.disposeWithMe(t.register("TodoList",li))}_initUiParts(){var e,n;const t=this._configService.getConfig($n);(n=(e=t==null?void 0:t.layout)==null?void 0:e.docContainerConfig)!=null&&n.footer&&this.disposeWithMe(this._uiPartsService.registerComponent(E.BuiltInUIPart.FOOTER,()=>E.connectInjector($a,this._injector)))}_initMenus(){this._menuManagerService.mergeMenu(as)}_initShortCut(){[Pa,Ua,wa,Qa,La,Fa,Va,Wa,Ha,ka,Ka,za,ba].forEach(t=>{this.disposeWithMe(this._shortcutService.registerShortcut(t))})}_init(){this._initCustomComponents(),this._initMenus(),this._initFocusHandler(),this._initCommands(),this._initUiParts(),this._initShortCut()}_initCommands(){[pi,jn,Kn].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(a.UniverInstanceType.UNIVER_DOC,t=>{this._injector.get(B.IRenderManagerService).getRenderById(t).with(T.DocSelectionRenderService).focus()}))}},T.DocUIController=_c([be(0,a.Inject(a.Injector)),be(1,a.Inject(E.ComponentManager)),be(2,a.ICommandService),be(3,E.ILayoutService),be(4,E.IMenuManagerService),be(5,E.IUIPartsService),be(6,a.IUniverInstanceService),be(7,E.IShortcutService),be(8,a.IConfigService)],T.DocUIController);var Nc=Object.getOwnPropertyDescriptor,Pc=(o,t,e,n)=>{for(var i=n>1?void 0:n?Nc(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Co=(o,t)=>(e,n)=>t(e,n,o);const rs=1.5;T.DocBackScrollRenderController=class extends a.RxDisposable{constructor(t,e,n,i){super(),this._context=t,this._textSelectionManagerService=e,this._editorService=n,this._docSkeletonManagerService=i,this._init()}_init(){this._textSelectionManagerService.textSelection$.pipe(N.takeUntil(this.dispose$)).subscribe(t=>{if(t==null)return;const{isEditing:e,unitId:n}=t;n!==this._context.unitId||!e||this._context.unitId!==a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._scrollToSelection()})}scrollToRange(t){const e=this._docSkeletonManagerService.getSkeleton();if(!e)return;const{startOffset:n}=t,i=e.findNodePositionByCharIndex(n);i&&this.scrollToNode(i)}scrollToNode(t){var w;const{unitId:e,scene:n,mainComponent:i}=this._context,s=this._docSkeletonManagerService.getSkeleton();if(i==null||s==null)return;const r=i.getOffsetConfig(),{docsLeft:c,docsTop:A}=r,l=new Ie(r,s),{contentBoxPointGroup:d}=l.getRangePointData(t,t),{left:u,top:g,height:h}=lt(d),m=u+c,f=g+A,p=n.getViewport(he.VIEW_MAIN),S=this._editorService.getEditor(e);if(p==null)return;const{left:I,top:C,right:y,bottom:R}=p.getBounding().viewBound;let v=0,b=0;const O=S?(w=S.params.backScrollOffset)!=null?w:0:100;f<C?v=f-C-O:f>R-h&&(v=f-R+h+O),m<I?b=m-I:m>y-rs&&(b=m-y+rs);const _=p.transViewportScroll2ScrollValue(b,v);p.scrollByBarDeltaValue(_)}_scrollToSelection(){const t=this._textSelectionManagerService.getActiveTextRange();if(t==null)return;const{collapsed:e,startNodePosition:n}=t;e&&this.scrollToNode(n)}},T.DocBackScrollRenderController=Pc([Co(1,a.Inject(x.DocSelectionManagerService)),Co(2,ce),Co(3,a.Inject(x.DocSkeletonManagerService))],T.DocBackScrollRenderController);var Uc=Object.getOwnPropertyDescriptor,wc=(o,t,e,n)=>{for(var i=n>1?void 0:n?Uc(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},at=(o,t)=>(e,n)=>t(e,n,o);T.DocRenderController=class extends a.RxDisposable{constructor(t,e,n,i,s,r,c){super(),this._context=t,this._commandService=e,this._docSelectionRenderService=n,this._docSkeletonManagerService=i,this._editorService=s,this._renderManagerService=r,this._univerInstanceService=c,this._addNewRender(),this._initRenderRefresh(),this._initCommandListener()}reRender(t){var r,c;const e=(r=this._renderManagerService.getRenderById(t))==null?void 0:r.with(x.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 B.Viewport(he.VIEW_MAIN,t,{left:0,top:0,bottom:0,right:0,isWheelPreventDefaultX:!0});t.attachControl(),t.onMouseWheel$.subscribeEvent((s,r)=>{const c=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if((c==null?void 0:c.getUnitId())!==this._context.unitId)return;const A=s;if(A.ctrlKey){const l=Math.abs(A.deltaX);let d=l<40?.2:l<80?.4:.2;d*=A.deltaY>0?-1:1,t.scaleX<1&&(d/=2),t.scaleX+d>4?t.scale(4,4):t.scaleX+d<.1?t.scale(.1,.1):A.preventDefault()}else n.onMouseWheel(A,r)}),new B.ScrollBar(n),t.addLayer(new B.Layer(t,[],Mt),new B.Layer(t,[],Wo)),this._addComponent();const i=()=>t.render();this.disposeWithMe(this._context.activated$.subscribe(s=>{s?e.runRenderLoop(i):e.stopRenderLoop(i)})),this._docSelectionRenderService.__attachScrollEvent()}_addComponent(){const{scene:t,unit:e,components:n}=this._context,r={pageMarginLeft:20,pageMarginTop:20},c=new B.Documents(le.MAIN,void 0,r);c.zIndex=On;const A=new B.DocBackground(le.BACKGROUND,void 0,r);A.zIndex=On,this._context.mainComponent=c,n.set(le.MAIN,c),n.set(le.BACKGROUND,A),t.addObjects([c],Mt),t.addObjects([A],Vo),this._editorService.getEditor(e.getUnitId())==null&&t.enableLayerCache(Mt)}_initRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(N.takeUntil(this.dispose$)).subscribe(t=>{this._create(t)})}_create(t){var A;if(!t)return;const{mainComponent:e,components:n}=this._context,i=e,s=n.get(le.BACKGROUND);i.changeSkeleton(t),s.changeSkeleton(t);const{unitId:r}=this._context,c=this._editorService.getEditor(r);if(this._editorService.isEditor(r)&&!(c!=null&&c.params.scrollBar)){(A=this._context.mainComponent)==null||A.makeDirty();return}this._recalculateSizeBySkeleton(t)}_initCommandListener(){const t=[x.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(t.includes(e.id)){const n=e.params,{unitId:i}=n;this.reRender(i)}}))}_recalculateSizeBySkeleton(t){var m;const{mainComponent:e,scene:n,unitId:i,components:s}=this._context,r=e,c=s.get(le.BACKGROUND),A=(m=t.getSkeletonData())==null?void 0:m.pages;if(A==null)return;let l=0,d=0;const g=this._context.unit.getSnapshot().documentStyle.documentFlavor;for(let f=0,p=A.length;f<p;f++){const S=A[f];let{pageWidth:I,pageHeight:C}=S;if(g===a.DocumentFlavor.MODERN){const y=Qc(S);I=y.pageWidth,C=y.pageHeight}r.pageLayoutType===B.PageLayoutType.VERTICAL?(d+=C,d+=r.pageMarginTop,f===p-1&&(d+=r.pageMarginTop),l=Math.max(l,I)):r.pageLayoutType===B.PageLayoutType.HORIZONTAL&&(l+=I,f!==p-1&&(l+=r.pageMarginLeft),d=Math.max(d,C))}r.resize(l,d),c.resize(l,d);const h=this._editorService.getEditor(i);(!this._editorService.isEditor(i)||h!=null&&h.params.scrollBar)&&n.resize(l,d)}},T.DocRenderController=wc([at(1,a.ICommandService),at(2,a.Inject(T.DocSelectionRenderService)),at(3,a.Inject(x.DocSkeletonManagerService)),at(4,ce),at(5,B.IRenderManagerService),at(6,a.IUniverInstanceService)],T.DocRenderController);function Qc(o){let{pageWidth:t,pageHeight:e}=o;const{marginLeft:n,marginRight:i,marginTop:s,marginBottom:r,skeDrawings:c,skeTables:A}=o;t===Number.POSITIVE_INFINITY&&(t=o.width+n+i),e===Number.POSITIVE_INFINITY&&(e=o.height+s+r);for(const l of c.values())t=Math.max(t,l.aLeft+l.width+n+i),e=Math.max(e,l.aTop+l.height+s+r);for(const l of A.values())t=Math.max(t,l.left+l.width+n+i),e=Math.max(e,l.top+l.height+s+r);return{pageWidth:t,pageHeight:e}}const To={id:"doc.command.select-all",type:a.CommandType.COMMAND,handler:async o=>{var h;const t=o.get(a.IUniverInstanceService),e=o.get(x.DocSelectionManagerService),n=t.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),i=e.getDocRanges(),s=(h=i.find(m=>m.isActive))!=null?h:i[0];if(n==null||s==null)return!1;const{segmentId:r}=s,c=n.getUnitId(),A=n.getSelfOrHeaderFooterModel(r).getSnapshot().body;if(A==null)return!1;const{tables:l=[],dataStream:d}=A;if(d===`\r
40
+ `)return!0;const u=[];let g=0;for(const m of l){const{startIndex:f,endIndex:p}=m;g!==f&&u.push({startOffset:g,endOffset:f-1,rangeType:a.DOC_RANGE_TYPE.TEXT}),u.push({startOffset:f+3,endOffset:p-5,rangeType:a.DOC_RANGE_TYPE.RECT}),g=p}return g!==A.dataStream.length-2&&u.push({startOffset:g,endOffset:A.dataStream.length-2,rangeType:a.DOC_RANGE_TYPE.TEXT}),e.replaceDocRanges(u,{unitId:c,subUnitId:c},!1),!0}};class Ot extends a.RxDisposable{constructor(e){super();M(this,"_previousActiveRange",null);M(this,"_undoMutationParamsCache",[]);M(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,r)=>a.JSONX.compose(s,r.actions),null),textRanges:[]};return{redoMutationParams:{unitId:e,actions:this._redoMutationParamsCache.reduce((s,r)=>a.JSONX.compose(s,r.actions),null),textRanges:[]},undoMutationParams:n,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const yo={id:"doc.command.ime-input",type:a.CommandType.COMMAND,handler:async(o,t)=>{var Q,G,Y;const{unitId:e,newText:n,oldTextLen:i,isCompositionEnd:s,isCompositionStart:r}=t,c=o.get(a.ICommandService),A=o.get(B.IRenderManagerService),l=o.get(a.IUniverInstanceService),d=o.get(Ce),u=(Q=A.getRenderById(e))==null?void 0:Q.with(Ot),g=l.getUnit(e,a.UniverInstanceType.UNIVER_DOC);if(g==null||u==null)return!1;const h=u.getActiveRange();if(h==null)return!1;const{style:m,segmentId:f}=h,p=g.getSelfOrHeaderFooterModel(f).getBody();if(p==null)return!1;Object.assign(h,h);const{startOffset:I,endOffset:C}=h,y=n.length,R=[{startOffset:I+y,endOffset:I+y,collapsed:!0,style:m}],v={id:x.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:R}},b=d.getDefaultStyle(),O=d.getStyleCache(),_=Rn((G=p.customRanges)!=null?G:[],I+i,a.SHEET_EDITOR_UNITS.includes(e)),w=xt(p,r?C:I+i,b,O,a.SHEET_EDITOR_UNITS.includes(e)),D=Dn((Y=p.customDecorations)!=null?Y:[],I+i),U=new a.TextX,P=a.JSONX.getInstance();if(!h.collapsed&&r){const W=a.BuildTextUtils.selection.delete([h],p,0,null,!1);U.push(...W),v.params.textRanges=[{startOffset:I+y,endOffset:I+y,collapsed:!0}]}else U.push({t:a.TextXActionType.RETAIN,len:I});i>0&&U.push({t:a.TextXActionType.DELETE,len:i}),U.push({t:a.TextXActionType.INSERT,body:{dataStream:n,textRuns:w?[{...w,st:0,ed:n.length}]:[],customRanges:_?[{..._,startIndex:0,endIndex:n.length-1}]:[],customDecorations:D.map(W=>({...W,startIndex:0,endIndex:n.length-1}))},len:n.length});const k=$(g,f);v.params.actions=P.editOp(U.serialize(),k),v.params.noHistory=!s,v.params.isCompositionEnd=s;const H=c.syncExecuteCommand(v.id,v.params);return u.pushUndoRedoMutationParams(H,v.params),!!H}},dn={type:a.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(o,t)=>{var u,g,h;const e=o.get(a.ICommandService),n=o.get(a.IUndoRedoService),i=o.get(a.IUniverInstanceService);let s=(u=i.getCurrentUniverDocInstance())==null?void 0:u.getUnitId();if(!s)return!1;let r=1;if(t&&(s=(g=t.documentId)!=null?g:s,r=(h=t.zoomRatio)!=null?h:r),!i.getUniverDocInstance(s))return!1;const A={zoomRatio:r,unitId:s},l=Ga(o,A);return e.syncExecuteCommand(ue.id,A)?(n.pushUndoRedo({unitID:s,undoMutations:[{id:ue.id,params:l}],redoMutations:[{id:ue.id,params:A}]}),!0):!1}},bo={id:"doc.table.tab-in-table",type:a.CommandType.COMMAND,handler:async(o,t)=>{var m;const{shift:e}=t,n=o.get(x.DocSelectionManagerService),i=n.getDocRanges(),s=o.get(a.ICommandService),c=o.get(a.IUniverInstanceService).getCurrentUniverDocInstance();if(!c)return!1;const A=(m=i.find(f=>f.isActive))!=null?m:i[0],l=c.getUnitId(),d=re(o,l),u=d==null?void 0:d.getSkeleton(),g=u==null?void 0:u.getViewModel().getSelfOrHeaderFooterViewModel(A==null?void 0:A.segmentId);if(g==null||A==null)return!1;let h=null;if(e?h=ki(g,A,no.PREV):h=ki(g,A,no.NEXT),h){const{startOffset:f,endOffset:p}=h,S=[{startOffset:f,endOffset:p}];return n.replaceDocRanges(S),!0}return e===!1?await s.executeCommand(go.id,{position:Kt.BELLOW}):!0}};var Lc=Object.getOwnPropertyDescriptor,Fc=(o,t,e,n)=>{for(var i=n>1?void 0:n?Lc(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Oo=(o,t)=>(e,n)=>t(e,n,o);let Ro=class{constructor(o,t,e){M(this,"_docContainer");M(this,"getComponent",o=>{if(this._docContainer=o,!o.getContentRef().current)throw new Error("container is not ready")});M(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($n),changeLocale:this.changeLocale,getComponent:this.getComponent}}getContentRef(){return this._docContainer.getContentRef()}UIDidMount(o){if(this._docContainer)return o(this._docContainer)}getDocContainer(){return this._docContainer}};Ro=Fc([Oo(0,a.Inject(a.LocaleService)),Oo(1,a.Inject(a.Injector)),Oo(2,a.IConfigService)],Ro);var kc=Object.getOwnPropertyDescriptor,Hc=(o,t,e,n)=>{for(var i=n>1?void 0:n?kc(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Vc=(o,t)=>(e,n)=>t(e,n,o);let un=class extends a.RxDisposable{constructor(t){super();M(this,"_docContainerController");this._injector=t,this._docContainerController=this._injector.createInstance(Ro)}};un=Hc([Vc(0,a.Inject(a.Injector))],un);var Wc=Object.getOwnPropertyDescriptor,Kc=(o,t,e,n)=>{for(var i=n>1?void 0:n?Wc(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},cs=(o,t)=>(e,n)=>t(e,n,o);let hn=class extends a.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:xe.id,match:o=>{var i;const{selection:t,paragraphs:e,unit:n}=o;if(e.length===1&&t.startOffset===e[0].paragraphStart&&e[0].bullet){const s=(i=n.getBody())==null?void 0:i.paragraphs,r=s==null?void 0:s.filter(c=>{var A;return((A=c.bullet)==null?void 0:A.listId)===e[0].bullet.listId});return(r==null?void 0:r.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:kt.id,params:{type:t!=null&&t.shift?gt.decrease:gt.increase}}]},priority:100})),this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:xe.id,match:o=>{const{selection:t,unit:e}=o,{startNodePosition:n,endNodePosition:i}=t,s=this._renderManagerService.getRenderById(e.getUnitId()),r=s==null?void 0:s.with(x.DocSkeletonManagerService).getSkeleton();return r==null?!1:!!(n&&i&&$o(r,n,i)||n&&!i&&n.path.indexOf("cells")>-1)},getMutations(o){const t=o.commandParams;return[{id:bo.id,params:{shift:!!(t!=null&&t.shift)}}]},priority:99}))}_initListSpaceAutoFormat(){this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:ut.id,match:o=>{var s;const{selection:t,paragraphs:e,unit:n}=o;if(!t.collapsed||e.length!==1)return!1;const i=(s=n.getBody())==null?void 0:s.dataStream.slice(e[0].paragraphStart,e[0].paragraphEnd-1);return!!(i&&Object.keys(a.QuickListTypeMap).includes(i))},getMutations(o){var i;const{paragraphs:t,unit:e}=o,n=(i=e.getBody())==null?void 0:i.dataStream.slice(t[0].paragraphStart,t[0].paragraphEnd-1);if(n&&Object.keys(a.QuickListTypeMap).includes(n)){const s=a.QuickListTypeMap[n];return[{id:Zn.id,params:{listType:s,paragraph:t[0]}}]}return[]}}))}_initExitListAutoFormat(){this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:qe.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:kt.id,params:{type:gt.decrease}}]:[{id:Ze.id,params:{listType:o.paragraphs[0].bullet.listType}}]:[]}}))}_initDefaultEnterFormat(){this.disposeWithMe(this._docAutoFormatService.registerAutoFormat({id:qe.id,match:()=>!0,getMutations(){return[{id:fo.id}]},priority:-9999}))}};hn=Kc([cs(0,a.Inject(T.DocAutoFormatService)),cs(1,B.IRenderManagerService)],hn);function zc(o){return o.rows[0].cells[0].sections[0].columns[0].lines[0]}function jc(o){const t=o.rows[o.rows.length-1],e=t.cells[t.cells.length-1];return B.getLastLine(e)}function Gc(o,t){const{ed:e}=o,{skeTables:n}=t;let i=null;for(const s of n.values())if(s.st===e+1){i=s;break}return i}function As(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:i,ed:s}=o,r=t.type===B.DocumentSkeletonPageType.CELL?[t]:t.parent.pages;return B.lineIterator(r,c=>{c.st===s+1?n=c:c.ed===i-1&&(e=c)}),{lineBeforeTable:e,lineAfterTable:n}}function ls(o){return o.sections[0].columns[0].lines.length===0}function ds(o){var r,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 i=t.cells.indexOf(o);let s=e.rows[e.rows.indexOf(t)+1];if(s==null&&n.indexOf("#-#")){const[A,l]=n.split("#-#"),d=(c=(r=e.parent)==null?void 0:r.parent)==null?void 0:c.pages,u=`${A}#-#${Number.parseInt(l)+1}`;if(d)for(const g of d){const{skeTables:h}=g;if(h.has(u)){const m=h.get(u);if(m!=null&&m.rows.length){s=m.rows.find(f=>!f.isRepeatRow);break}}}}if(s!=null){const A=s.cells[i];return ls(A)?ds(A):A}}function us(o){var s,r;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 i=t.cells.indexOf(o);if((n==null||n.isRepeatRow)&&e.tableId.indexOf("#-#")){const[c,A]=e.tableId.split("#-#"),l=(r=(s=e.parent)==null?void 0:s.parent)==null?void 0:r.pages,d=`${c}#-#${Number.parseInt(A)-1}`;if(l)for(const u of l){const{skeTables:g}=u;if(g.has(d)){const h=g.get(d);if(h!=null&&h.rows.length){n=h.rows[h.rows.length-1];break}}}}if(n!=null){const c=n.cells[i];return ls(c)?us(c):c}}function Xc(o,t){const{st:e}=o,{skeTables:n}=t;let i=null;for(const s of n.values())if(s.ed===e-1){i=s;break}return i}function Yc(o){return o.sections[0].columns[0].lines[0]}function qc(o){const t=B.getLastColumn(o);return t.lines[t.lines.length-1]}var Jc=Object.getOwnPropertyDescriptor,Zc=(o,t,e,n)=>{for(var i=n>1?void 0:n?Jc(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},gn=(o,t)=>(e,n)=>t(e,n,o);let mn=class extends a.Disposable{constructor(t,e,n,i){super();M(this,"_onInputSubscription");this._univerInstanceService=t,this._renderManagerService=e,this._textSelectionManagerService=n,this._commandService=i,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 C,y,R;const e=this._textSelectionManagerService.getActiveTextRange(),n=this._textSelectionManagerService.getTextRanges(),i=this._univerInstanceService.getCurrentUniverDocInstance();if(i==null)return;const s=(C=this._renderManagerService.getRenderById(i.getUnitId()))==null?void 0:C.with(x.DocSkeletonManagerService).getSkeleton(),r=this._getDocObject();if(e==null||s==null||r==null)return;const{startOffset:c,endOffset:A,style:l,collapsed:d,direction:u,segmentId:g,startNodePosition:h,endNodePosition:m,segmentPage:f}=e;if(n.length>1){let v=Number.POSITIVE_INFINITY,b=Number.NEGATIVE_INFINITY;for(const O of n)v=Math.min(v,O.startOffset),b=Math.max(b,O.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:t===a.Direction.LEFT||t===a.Direction.UP?b:v,endOffset:t===a.Direction.LEFT||t===a.Direction.UP?v:b,style:l}],!1);return}const p=d||u===a.RANGE_DIRECTION.FORWARD?c:A;let S=d||u===a.RANGE_DIRECTION.FORWARD?A:c;const I=(y=i.getSelfOrHeaderFooterModel(g).getBody().dataStream.length)!=null?y:Number.POSITIVE_INFINITY;if(t===a.Direction.LEFT||t===a.Direction.RIGHT){const v=s.findNodeByCharIndex(S-1,g,f),b=s.findNodeByCharIndex(S,g,f);S=t===a.Direction.RIGHT?S+b.count:S-((R=v==null?void 0:v.count)!=null?R:0),S=Math.min(I-2,Math.max(0,S)),this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:S,style:l}],!1),this._scrollToFocusNodePosition(i.getUnitId(),S)}else{const v=s.findNodeByCharIndex(S,g,f),b=r.document.getOffsetConfig(),O=d?h:u===a.RANGE_DIRECTION.FORWARD?m:h,_=this._getTopOrBottomPosition(s,v,O,t===a.Direction.DOWN,!0);if(_==null){const D=t===a.Direction.UP?0:I-2;if(D===S)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:D,style:l}],!1);return}const w=new Ie(b,s).getRangePointData(_,_).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:w.endOffset,style:l}],!1),this._scrollToFocusNodePosition(i.getUnitId(),w.endOffset)}}_handleMoveCursor(t){var I,C,y,R;const e=this._textSelectionManagerService.getActiveTextRange(),n=this._textSelectionManagerService.getTextRanges(),i=this._univerInstanceService.getCurrentUniverDocInstance();if(i==null)return!1;const s=(I=this._renderManagerService.getRenderById(i.getUnitId()))==null?void 0:I.with(x.DocSkeletonManagerService).getSkeleton(),r=this._getDocObject();if(e==null||s==null||r==null||n==null)return;const{startOffset:c,endOffset:A,style:l,collapsed:d,segmentId:u,startNodePosition:g,endNodePosition:h,segmentPage:m}=e,f=i.getSelfOrHeaderFooterModel(u).getBody();if(f==null)return;const p=(C=f.dataStream.length)!=null?C:Number.POSITIVE_INFINITY,S=(y=i.getCustomRanges())!=null?y:[];if(t===a.Direction.LEFT||t===a.Direction.RIGHT){let v;if(!e.collapsed||n.length>1){let _=Number.POSITIVE_INFINITY,w=Number.NEGATIVE_INFINITY;for(const D of n)_=Math.min(_,D.startOffset),w=Math.max(w,D.endOffset);v=t===a.Direction.LEFT?_:w}else{const _=s.findNodeByCharIndex(c-1,u,m),w=s.findNodeByCharIndex(c,u,m),D=s.findNodeByCharIndex(c+1,u,m);t===a.Direction.LEFT?v=Math.max(0,c-((R=_==null?void 0:_.count)!=null?R:1)):v=Math.min(p-2,A+w.count+((D==null?void 0:D.streamType)===a.DataStreamTreeTokenType.SECTION_BREAK?1:0))}const b=[a.DataStreamTreeTokenType.TABLE_START,a.DataStreamTreeTokenType.TABLE_END,a.DataStreamTreeTokenType.TABLE_ROW_START,a.DataStreamTreeTokenType.TABLE_ROW_END,a.DataStreamTreeTokenType.TABLE_CELL_START,a.DataStreamTreeTokenType.TABLE_CELL_END,a.DataStreamTreeTokenType.SECTION_BREAK];if(t===a.Direction.LEFT)for(;b.includes(f.dataStream[v]);)v--;else for(;b.includes(f.dataStream[v]);)v++;S.filter(_=>_.wholeEntity&&_.startIndex<v&&_.endIndex>=v).forEach(_=>{t===a.Direction.LEFT?v=Math.min(_.startIndex,v):v=Math.max(_.endIndex+1,v)}),this._textSelectionManagerService.replaceTextRanges([{startOffset:Math.max(0,v),endOffset:Math.max(0,v),style:l}],!1),this._scrollToFocusNodePosition(i.getUnitId(),v)}else{const v=s.findNodeByCharIndex(c,u,m),b=s.findNodeByCharIndex(A,u,m),O=r.document.getOffsetConfig(),_=this._getTopOrBottomPosition(s,t===a.Direction.UP||d?v:b,t===a.Direction.UP||d?g:h,t===a.Direction.DOWN);if(_==null){let D;d?D=t===a.Direction.UP?0:p-2:D=t===a.Direction.UP?c:A,this._textSelectionManagerService.replaceTextRanges([{startOffset:Math.max(0,D),endOffset:Math.max(0,D),style:l}],!1);return}const w=new Ie(O,s).getRangePointData(_,_).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...w,style:l}],!1),this._scrollToFocusNodePosition(i.getUnitId(),w.endOffset)}}_getTopOrBottomPosition(t,e,n,i,s=!1){if(e==null||n==null)return;const r=this._getGlyphLeftOffsetInLine(e),c=this._getNextOrPrevLine(e,i,s);if(c==null)return;const A=this._matchPositionByLeftOffset(t,c,r,n);if(A!=null)return{...A,isBack:!0}}_getGlyphLeftOffsetInLine(t){const e=t.parent;if(e==null)return Number.NEGATIVE_INFINITY;const n=e.left,{left:i}=t;return n+i}_matchPositionByLeftOffset(t,e,n,i){const s={distance:Number.POSITIVE_INFINITY};for(const c of e.divides){const A=c.left;for(const l of c.glyphGroup){if(l.streamType===a.DataStreamTreeTokenType.SECTION_BREAK)continue;const{left:d}=l,u=A+d,g=Math.abs(n-u);g<s.distance&&(s.glyph=l,s.distance=g)}}if(s.glyph==null)return;const{segmentPage:r}=i;return t.findPositionByGlyph(s.glyph,r)}_getNextOrPrevLine(t,e,n=!1){var f,p,S,I,C,y,R,v,b,O,_,w;const i=t.parent,s=i==null?void 0:i.parent,r=s==null?void 0:s.parent,c=r==null?void 0:r.parent,A=c==null?void 0:c.parent;if(i==null||s==null||r==null||c==null||A==null)return;const l=r.lines.indexOf(s);if(l===-1)return;let d;if(A.type===B.DocumentSkeletonPageType.CELL&&n){const D=hs(A,e);if(D)return D}if(e===!0){d=r.lines[l+1];const D=Gc(s,A);if(D){const U=zc(D);U&&(d=U)}}else{d=r.lines[l-1];const D=Xc(s,A);if(D){const U=jc(D);U&&(d=U)}}if(d!=null)return d;const u=c.columns.indexOf(r);if(u===-1)return;if(e===!0)d=(f=c.columns[u+1])==null?void 0:f.lines[0];else{const D=(S=(p=c.columns)==null?void 0:p[u-1])==null?void 0:S.lines;d=D==null?void 0:D[D.length-1]}if(d!=null)return d;const g=A.sections.indexOf(c);if(g===-1)return;if(e===!0)d=(C=(I=A.sections[g-1])==null?void 0:I.columns[0])==null?void 0:C.lines[0];else{const D=(R=(y=A.sections)==null?void 0:y[g-1])==null?void 0:R.columns,U=D==null?void 0:D[D.length-1],P=U==null?void 0:U.lines;d=P==null?void 0:P[P.length-1]}if(d!=null)return d;if(A.type===B.DocumentSkeletonPageType.CELL)return hs(A,e);const h=A.parent;if(h==null)return;const m=h.pages.indexOf(A);if(m!==-1){if(e===!0)d=(O=(b=(v=h.pages[m+1])==null?void 0:v.sections[0])==null?void 0:b.columns[0])==null?void 0:O.lines[0];else{const D=(_=h.pages[m-1])==null?void 0:_.sections;if(D==null)return;const U=(w=D[D.length-1])==null?void 0:w.columns,P=U[U.length-1],k=P==null?void 0:P.lines;d=k[k.length-1]}if(d!=null)return d}}_scrollToFocusNodePosition(t,e){var i;const n=(i=this._renderManagerService.getRenderById(t))==null?void 0:i.with(T.DocBackScrollRenderController);n!=null&&n.scrollToRange({startOffset:e,endOffset:e,collapsed:!0})}_getDocObject(){return Ko(this._univerInstanceService,this._renderManagerService)}};mn=Zc([gn(0,a.IUniverInstanceService),gn(1,B.IRenderManagerService),gn(2,a.Inject(x.DocSelectionManagerService)),gn(3,a.ICommandService)],mn);function hs(o,t){var n,i;let e=null;if(t===!0){const s=ds(o);if(s)e=Yc(s);else{const r=(n=o.parent)==null?void 0:n.parent,{lineAfterTable:c}=As(r);c&&(e=c)}}else{const s=us(o);if(s)e=qc(s);else{const r=(i=o.parent)==null?void 0:i.parent,{lineBeforeTable:c}=As(r);c&&(e=c)}}return e}const We={create:"univer-create",createItem:"univer-create-item",createLabel:"univer-create-label",createInput:"univer-create-input"},$c=({handleRowColChange:o,tableCreateParams:t})=>{const e=E.useDependency(a.LocaleService),[n,i]=F.useState(3),[s,r]=F.useState(5);function c(A,l){i(A),r(l),o(A,l)}return F.useEffect(()=>{i(t.rowCount),r(t.colCount)},[t]),L.jsxs("div",{className:We.create,children:[L.jsxs("div",{className:We.createItem,children:[L.jsx("span",{className:We.createLabel,children:e.t("toolbar.table.rowCount")}),L.jsx(ne.InputNumber,{min:1,max:20,precision:0,value:n,onChange:A=>{c(A,s)},className:We.createInput})]}),L.jsxs("div",{className:We.createItem,children:[L.jsx("span",{className:We.createLabel,children:e.t("toolbar.table.colCount")}),L.jsx(ne.InputNumber,{min:1,max:20,precision:0,value:s,onChange:A=>{c(n,A)},className:We.createInput})]})]})};var eA=Object.getOwnPropertyDescriptor,tA=(o,t,e,n)=>{for(var i=n>1?void 0:n?eA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},gs=(o,t)=>(e,n)=>t(e,n,o);let fn=class extends a.Disposable{constructor(o,t){super(),this._commandService=o,this._componentManager=t,this._initialize()}_initialize(){this._init(),this._registerCommands(),this._initCustomComponents()}_registerCommands(){[An].forEach(o=>this.disposeWithMe(this._commandService.registerCommand(o)))}_initCustomComponents(){const o=this._componentManager;this.disposeWithMe(o.register(es,$c))}_init(){}};fn=tA([gs(0,a.ICommandService),gs(1,a.Inject(E.ComponentManager))],fn);const Do=4;var nA=Object.getOwnPropertyDescriptor,oA=(o,t,e,n)=>{for(var i=n>1?void 0:n?nA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},pn=(o,t)=>(e,n)=>t(e,n,o);function ms(o,t){const e=fs(o.left,o.top,t),n=fs(o.right,o.bottom,t);return{left:e.x,top:e.y,right:n.x,bottom:n.y}}function fs(o,t,e){const{scaleX:n,scaleY:i}=e.getAncestorScale(),s=e.getViewport(he.VIEW_MAIN);if(!s)return{x:o,y:t};const{viewportScrollX:r,viewportScrollY:c}=s,A=(o-r)*n,l=(t-c)*i;return{x:A,y:l}}function ps(o,t,e){const{scaleX:n,scaleY:i}=e.getAncestorScale(),s=e.getViewport(he.VIEW_MAIN);if(!s)return{x:o,y:t};const{viewportScrollX:r,viewportScrollY:c}=s,A=o/n+r,l=t/i+c;return{x:A,y:l}}const Sn=(o,t)=>{const{scene:e,mainComponent:n,engine:i}=t,s=t.with(x.DocSkeletonManagerService).getSkeleton(),r=s.findNodePositionByCharIndex(o.startOffset,!0,o.segmentId,o.segmentPage),c=s.findNodePositionByCharIndex(o.endOffset,!0,o.segmentId,o.segmentPage),A=n;if(!c||!r)return;const l=A.getOffsetConfig(),{docsLeft:d,docsTop:u}=l,g=i.getCanvasElement(),h=g.getBoundingClientRect(),m=B.pxToNum(g.style.width),{top:f,left:p,width:S}=h,I=S/m,{scaleX:C,scaleY:y}=e.getAncestorScale(),R=new Ie(l,s),{borderBoxPointGroup:v}=R.getRangePointData(r,c);return Pt(v).map(_=>ms(_,e)).map(_=>({left:(_.left+d*C)*I+p,right:(_.right+d*C)*I+p,top:(_.top+u*y)*I+f,bottom:(_.bottom+u*y)*I+f}))};T.DocCanvasPopManagerService=class extends a.Disposable{constructor(t,e,n,i){super(),this._globalPopupManagerService=t,this._renderManagerService=e,this._univerInstanceService=n,this._commandService=i}_createObjectPositionObserver(t,e){const n=()=>{const{scene:A,engine:l}=e,{left:d,top:u,width:g,height:h}=t,m={left:d,right:d+g,top:u,bottom:u+h},f=l.getCanvasElement(),p=f.getBoundingClientRect(),S=B.pxToNum(f.style.width),I=ms(m,A),{top:C,left:y,width:R}=p,v=R/S;return{left:I.left*v+y,right:I.right*v+y,top:I.top*v+C,bottom:I.bottom*v+C}},i=n(),s=new N.BehaviorSubject(i),r=new a.DisposableCollection;r.add(this._commandService.onCommandExecuted(A=>{if(A.id===ue.id||A.id===x.RichTextEditingMutation.id){const l=n();l&&s.next(l)}}));const c=e.scene.getViewport(he.VIEW_MAIN);return c&&r.add(c.onScrollAfter$.subscribeEvent(()=>{s.next(n())})),{position:i,position$:s,disposable:r}}_createRangePositionObserver(t,e){var c;const n=(c=Sn(t,e))!=null?c:[],i=new N.BehaviorSubject(n),s=new a.DisposableCollection;s.add(this._commandService.onCommandExecuted(A=>{if((A.id===ue.id||A.id===x.RichTextEditingMutation.id)&&A.params.unitId===e.unitId){const d=Sn(t,e);d&&i.next(d)}}));const r=e.scene.getViewport(he.VIEW_MAIN);return r&&s.add(r.onScrollAfter$.subscribeEvent(()=>{const A=Sn(t,e);A&&i.next(A)})),{positions:n,positions$:i,disposable:s}}attachPopupToObject(t,e,n){const i=this._renderManagerService.getRenderById(n);if(!i)throw new Error(`Current render not found, unitId: ${n}`);const{position:s,position$:r,disposable:c}=this._createObjectPositionObserver(t,i),A=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:s,anchorRect$:r,canvasElement:i.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(A),r.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:r}=e,c=this._renderManagerService.getRenderById(n);if(!c)throw new Error(`Current render not found, unitId: ${n}`);const{positions:A,positions$:l,disposable:d}=this._createRangePositionObserver(t,c),u=l.pipe(N.map(h=>s.includes("top")?h[0]:h[h.length-1])),g=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:s.includes("top")?A[0]:A[A.length-1],anchorRect$:u,excludeRects:A,excludeRects$:l,direction:s.includes("top")||s.includes("bottom")?A.length>1?r:s:"bottom",canvasElement:c.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(g),l.complete(),d.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==g}}},T.DocCanvasPopManagerService=oA([pn(0,a.Inject(E.ICanvasPopupService)),pn(1,B.IRenderManagerService),pn(2,a.IUniverInstanceService),pn(3,a.ICommandService)],T.DocCanvasPopManagerService);var iA=Object.getOwnPropertyDescriptor,sA=(o,t,e,n)=>{for(var i=n>1?void 0:n?iA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},aA=(o,t)=>(e,n)=>t(e,n,o);const rA=(o,t,e,n)=>{var g,h,m,f,p;const i=e.findNodePositionByCharIndex(o.startOffset,!0,o.segmentId,n),s=e.getSkeletonData();let r=o.endOffset;if(o.segmentId){const S=(p=Array.from((h=(g=s==null?void 0:s.skeFooters.get(o.segmentId))==null?void 0:g.values())!=null?h:[])[0])!=null?p:Array.from((f=(m=s==null?void 0:s.skeHeaders.get(o.segmentId))==null?void 0:m.values())!=null?f:[])[0];S&&(r=Math.min(S.ed,r))}const c=e.findNodePositionByCharIndex(r,!0,o.segmentId,n);if(!c||!i)return;const A=t.getOffsetConfig(),l=new Ie(A,e),{borderBoxPointGroup:d}=l.getRangePointData(i,c);return Pt(d).map(S=>({top:S.top+A.docsTop-Do,bottom:S.bottom+A.docsTop+Do,left:S.left+A.docsLeft,right:S.right+A.docsLeft}))},cA=(o,t,e,n=-1)=>{const i=e.findPositionByGlyph(o,n);if(!i)return;const s=t.getOffsetConfig(),r={...i,isBack:!0},c=new Ie(s,e),{borderBoxPointGroup:A}=c.getRangePointData(r,r),d=Pt(A)[0];return{top:d.top+s.docsTop,bottom:d.bottom+s.docsTop,left:d.left+s.docsLeft,right:d.left+s.docsLeft+o.width}};T.DocEventManagerService=class extends a.Disposable{constructor(e,n){super();M(this,"_hoverCustomRanges$",new N.BehaviorSubject([]));M(this,"hoverCustomRanges$",this._hoverCustomRanges$.pipe(N.distinctUntilChanged((e,n)=>e.length===n.length&&e.every((i,s)=>n[s].range.rangeId===i.range.rangeId&&n[s].segmentId===i.segmentId&&n[s].segmentPageIndex===i.segmentPageIndex&&n[s].range.startIndex===i.range.startIndex))));M(this,"_clickCustomRanges$",new N.Subject);M(this,"clickCustomRanges$",this._clickCustomRanges$.asObservable());M(this,"_hoverBullet$",new N.Subject);M(this,"hoverBullet$",this._hoverBullet$.pipe(N.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))));M(this,"_clickBullet$",new N.Subject);M(this,"clickBullets$",this._clickBullet$.asObservable());M(this,"_customRangeDirty",!0);M(this,"_bulletDirty",!0);M(this,"_customRangeBounds",[]);M(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=B.CURSOR_TYPE.TEXT;this.disposeWithMe(this.hoverCustomRanges$.subscribe(n=>{n.length?(e=this._context.scene.getCursor(),this._context.scene.setCursor(B.CURSOR_TYPE.POINTER)):this._context.scene.setCursor(e)}))}_initResetDirty(){this.disposeWithMe(this._skeleton.dirty$.subscribe(()=>{this._customRangeDirty=!0,this._bulletDirty=!0})),this.disposeWithMe(a.fromEventSubject(this._context.engine.onTransformChange$).pipe(N.filter(e=>e.type===B.TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize)).subscribe(()=>{this._customRangeDirty=!0,this._bulletDirty=!0}))}_initEvents(){this.disposeWithMe(a.fromEventSubject(this._context.scene.onPointerMove$).pipe(N.throttleTime(30)).subscribe(i=>{this._hoverCustomRanges$.next(this._calcActiveRanges(i)),this._hoverBullet$.next(this._calcActiveBullet(i))})),this.disposeWithMe(this._context.scene.onPointerEnter$.subscribeEvent(()=>{this._hoverBullet$.next(null),this._hoverCustomRanges$.next([])}));const e=a.fromEventSubject(this._context.mainComponent.onPointerDown$),n=a.fromEventSubject(this._context.scene.onPointerUp$);this.disposeWithMe(e.pipe(N.switchMap(i=>n.pipe(N.take(1),N.map(s=>({down:i,up:s})))),N.filter(({down:i,up:s})=>i.target===s.target&&s.timeStamp-i.timeStamp<300)).subscribe(({down:i})=>{if(i.button===2)return;const s=this._calcActiveRanges(i);s.length&&this._clickCustomRanges$.next(s.pop());const r=this._calcActiveBullet(i);r&&this._clickBullet$.next(r)}))}_buildCustomRangeBoundsBySegment(e,n=-1){var r,c,A;const i=(A=(c=(r=this._context.unit.getSelfOrHeaderFooterModel(e))==null?void 0:r.getBody())==null?void 0:c.customRanges)!=null?A:[],s=[];return i.forEach(l=>{const d={startOffset:l.startIndex,endOffset:l.endIndex+1,segmentId:e},u=rA(d,this._documents,this._skeleton,n);if(!u)return null;s.push({customRange:l,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((i,s)=>{i.headerId&&e.push(...this._buildCustomRangeBoundsBySegment(i.headerId,s)),i.footerId&&e.push(...this._buildCustomRangeBoundsBySegment(i.footerId,s))}),this._customRangeBounds=e}_calcActiveRanges(e){this._buildCustomRangeBounds();const{offsetX:n,offsetY:i}=e,{x:s,y:r}=ps(n,i,this._context.scene);return this._customRangeBounds.filter(A=>A.rects.some(l=>{const{left:d,right:u,top:g,bottom:h}=l;return s>=d&&s<=u&&r>=g&&r<=h})).map(A=>({segmentId:A.segmentId,range:A.customRange,segmentPageIndex:A.segmentPageIndex,rects:A.rects}))}_buildBulletBoundsBySegment(e,n=-1){var l,d,u,g,h;const i=(l=this._context.unit.getSelfOrHeaderFooterModel(e))==null?void 0:l.getBody(),s=((d=i==null?void 0:i.paragraphs)!=null?d:[]).filter(m=>m.bullet&&m.bullet.listType.indexOf("CHECK_LIST")===0),r=[],c=this._skeleton.getSkeletonData();if(!c)return r;const A=m=>{var f,p,S;for(const I of m){const C=[...I.sections];if(I.skeTables){const y=Array.from(I.skeTables.values());C.push(...y.map(R=>R.rows.map(v=>v.cells.map(b=>b.sections))).flat(4))}for(const y of C)for(const R of y.columns)for(const v of R.lines)if(v.paragraphStart){const b=s.find(O=>O.startIndex===v.paragraphIndex);if(b){const O=v,_=(S=(p=(f=O==null?void 0:O.divides)==null?void 0:f[0])==null?void 0:p.glyphGroup)==null?void 0:S[0];if(!_)continue;const w=cA(_,this._documents,this._skeleton,n);if(!w)continue;r.push({rect:w,segmentId:e,segmentPageIndex:n,paragraph:b})}}}return r};if(e){const m=(h=(u=c.skeFooters.get(e))==null?void 0:u.values())!=null?h:(g=c.skeHeaders.get(e))==null?void 0:g.values();return m?A(Array.from(m)):r}return A(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,i)=>{n.headerId&&this._bulletBounds.push(...this._buildBulletBoundsBySegment(n.headerId,i)),n.footerId&&this._bulletBounds.push(...this._buildBulletBoundsBySegment(n.footerId,i))}))}_calcActiveBullet(e){this._buildBulletBounds();const{offsetX:n,offsetY:i}=e,{x:s,y:r}=ps(n,i,this._context.scene);return this._bulletBounds.find(A=>{const{left:l,right:d,top:u,bottom:g}=A.rect;return s>=l&&s<=d&&r>=u&&r<=g})}},T.DocEventManagerService=sA([aA(1,a.Inject(x.DocSkeletonManagerService))],T.DocEventManagerService);var AA=Object.getOwnPropertyDescriptor,lA=(o,t,e,n)=>{for(var i=n>1?void 0:n?AA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},In=(o,t)=>(e,n)=>t(e,n,o);let Bo=class extends a.Disposable{constructor(o,t,e,n,i){super(),this._context=o,this._docSkeletonManagerService=t,this._commandService=e,this._docEventManagerService=n,this._textSelectionManagerService=i,this._initPointerDownObserver(),this._initHoverCursor()}_initPointerDownObserver(){this._docEventManagerService.clickBullets$.subscribe(o=>{const t=this._textSelectionManagerService.getTextRanges();this._commandService.executeCommand(Vt.id,{index:o.paragraph.startIndex,segmentId:o.segmentId,textRanges:t})})}_initHoverCursor(){this.disposeWithMe(this._docEventManagerService.hoverBullet$.subscribe(o=>{o?this._context.mainComponent.setCursor(B.CURSOR_TYPE.POINTER):this._context.mainComponent.setCursor(B.CURSOR_TYPE.TEXT)}))}_getTransformCoordForDocumentOffset(o,t,e,n){const{documentTransform:i}=o.getOffsetConfig(),s=t.transformVector2SceneCoord(B.Vector2.FromArray([e,n]));if(s)return i.clone().invert().applyPoint(s)}};Bo=lA([In(1,a.Inject(x.DocSkeletonManagerService)),In(2,a.ICommandService),In(3,a.Inject(T.DocEventManagerService)),In(4,a.Inject(x.DocSelectionManagerService))],Bo);var dA=Object.getOwnPropertyDescriptor,uA=(o,t,e,n)=>{for(var i=n>1?void 0:n?dA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Rt=(o,t)=>(e,n)=>t(e,n,o);let En=class extends a.RxDisposable{constructor(o,t,e,n,i,s){super(),this._context=o,this._commandService=t,this._docClipboardService=e,this._docSelectionRenderService=n,this._contextService=i,this._editorService=s,this._init()}_init(){this._initLegacyPasteCommand()}_initLegacyPasteCommand(){var o;(o=this._docSelectionRenderService)==null||o.onPaste$.pipe(N.takeUntil(this.dispose$)).subscribe(t=>{var c,A,l;if(!Zt(this._contextService))return;t.event.preventDefault();const e=t.event;let n=(c=e.clipboardData)==null?void 0:c.getData(E.HTML_CLIPBOARD_MIME_TYPE);const i=(A=e.clipboardData)==null?void 0:A.getData(E.PLAIN_TEXT_CLIPBOARD_MIME_TYPE),s=[...((l=e.clipboardData)==null?void 0:l.items)||[]].filter(d=>E.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:i,files:s})})}};En=uA([Rt(1,a.ICommandService),Rt(2,ot),Rt(3,a.Inject(T.DocSelectionRenderService)),Rt(4,a.IContextService),Rt(5,ce)],En);var hA=Object.getOwnPropertyDescriptor,gA=(o,t,e,n)=>{for(var i=n>1?void 0:n?hA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Ss=(o,t)=>(e,n)=>t(e,n,o);const mA=[a.DEFAULT_EMPTY_DOCUMENT_VALUE,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let Mo=class extends a.Disposable{constructor(o,t,e){super(),this._context=o,this._contextMenuService=t,this._commandService=e,mA.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(i=>{i.button===2&&this._contextMenuService.triggerContextMenu(i,E.ContextMenuPosition.MAIN_AREA)});this.disposeWithMe(t)}_initEditChange(){this.disposeWithMe(this._commandService.onCommandExecuted(o=>{o.id===x.RichTextEditingMutation.id&&this._contextMenuService.visible&&this._contextMenuService.hideContextMenu()}))}};Mo=gA([Ss(1,E.IContextMenuService),Ss(2,a.ICommandService)],Mo);var fA=Object.getOwnPropertyDescriptor,pA=(o,t,e,n)=>{for(var i=n>1?void 0:n?fA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},rt=(o,t)=>(e,n)=>t(e,n,o);let vn=class extends a.Disposable{constructor(t,e,n,i,s,r,c){super();M(this,"_initialEditors",new Set);this._context=t,this._univerInstanceService=e,this._editorService=n,this._commandService=i,this._docSelectionRenderService=s,this._docSkeletonManagerService=r,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 i=this._docSkeletonManagerService.getSkeleton();if(e==null||e.render==null||i==null||n==null)return;i.calculate();const{marginTop:s=0,marginBottom:r=0,marginLeft:c=0,marginRight:A=0}=n.getSnapshot().documentStyle,{scene:l,mainComponent:d}=e.render;let{actualHeight:u,actualWidth:g}=i.getActualSize();u+=s+r,g+=c+A;const{width:h,height:m}=e.getBoundingClientRect(),f=Math.max(g,h),p=Math.max(u,m);l.transformByState({width:f,height:p}),d==null||d.resize(f,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(N.fromEvent(window,"mousedown").subscribe(n=>{const s=n.target.classList[0]||"";a.checkForSubstrings(s,t)&&n.stopPropagation()}));const e=new a.DisposableCollection;this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(n=>{if(e.dispose(),!n)return;const i=n.getUnitId(),s=this._renderManagerService.getRenderById(i),r=s==null?void 0:s.engine.getCanvas().getCanvasEle();if(r==null)return;const c=N.fromEvent(r,"mousedown").subscribe(A=>{A.stopPropagation()});e.add(c)})),this.disposeWithMe(()=>e.dispose())}_commandExecutedListener(){const t=[x.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(t.includes(e.id)){const n=e.params,{unitId:i}=n;if(this._editorService.isSheetEditor(i)||i!==this._context.unitId)return;const s=this._editorService.getEditor(i);s&&!s.params.scrollBar&&this._resize(i)}}))}};vn=pA([rt(1,a.IUniverInstanceService),rt(2,ce),rt(3,a.ICommandService),rt(4,a.Inject(T.DocSelectionRenderService)),rt(5,a.Inject(x.DocSkeletonManagerService)),rt(6,B.IRenderManagerService)],vn);var SA=Object.getOwnPropertyDescriptor,IA=(o,t,e,n)=>{for(var i=n>1?void 0:n?SA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Cn=(o,t)=>(e,n)=>t(e,n,o);let xo=class extends a.Disposable{constructor(t,e,n,i,s){super();M(this,"_previousIMEContent","");M(this,"_isCompositionStart",!0);M(this,"_onStartSubscription");M(this,"_onUpdateSubscription");M(this,"_onEndSubscription");this._context=t,this._docSelectionRenderService=e,this._docImeInputManagerService=n,this._docSkeletonManagerService=i,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(a.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,i=this._docSkeletonManagerService.getSkeleton(),{event:s,activeRange:r}=t;if(i==null||r==null)return;const A=s.data;A===this._previousIMEContent&&e||(await this._commandService.executeCommand(yo.id,{unitId:n,newText:A,oldTextLen:this._previousIMEContent.length,isCompositionStart:this._isCompositionStart,isCompositionEnd:!e}),e?(this._isCompositionStart&&(this._isCompositionStart=!1),this._previousIMEContent=A):this._resetIME())}_resetIME(){this._previousIMEContent="",this._isCompositionStart=!0,this._docImeInputManagerService.clearUndoRedoMutationParamsCache(),this._docImeInputManagerService.setActiveRange(null)}};xo=IA([Cn(1,a.Inject(T.DocSelectionRenderService)),Cn(2,a.Inject(Ot)),Cn(3,a.Inject(x.DocSkeletonManagerService)),Cn(4,a.ICommandService)],xo);var EA=Object.getOwnPropertyDescriptor,vA=(o,t,e,n)=>{for(var i=n>1?void 0:n?EA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Tn=(o,t)=>(e,n)=>t(e,n,o);let _o=class extends a.Disposable{constructor(t,e,n,i,s){super();M(this,"_onInputSubscription");this._context=t,this._docSelectionRenderService=e,this._docSkeletonManagerService=n,this._commandService=i,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;if(t==null)return;const{unitId:e}=this._context,{event:n,content:i="",activeRange:s}=t,r=n,c=this._docSkeletonManagerService.getSkeleton();if(r.data==null||c==null||s==null)return;const{segmentId:A}=s,d=this._context.unit.getSelfOrHeaderFooterModel(A).getBody(),u=this._docMenuStyleService.getDefaultStyle(),g=this._docMenuStyleService.getStyleCache(),h=Rn((p=d==null?void 0:d.customRanges)!=null?p:[],s.endOffset,a.SHEET_EDITOR_UNITS.includes(e)),m=xt(d,s.endOffset,u,g,a.SHEET_EDITOR_UNITS.includes(e)),f=Dn((S=d==null?void 0:d.customDecorations)!=null?S:[],s.endOffset);await this._commandService.executeCommand(Xt.id,{unitId:e,body:{dataStream:i,textRuns:m?[{...m,st:0,ed:i.length}]:[],customRanges:h?[{...h,startIndex:0,endIndex:i.length-1}]:[],customDecorations:f.map(I=>({...I,startIndex:0,endIndex:i.length-1}))},range:s,segmentId:A}),i===" "&&await this._commandService.executeCommand(ut.id)})}};_o=vA([Tn(1,a.Inject(T.DocSelectionRenderService)),Tn(2,a.Inject(x.DocSkeletonManagerService)),Tn(3,a.ICommandService),Tn(4,a.Inject(Ce))],_o);class No extends a.Disposable{constructor(t){super(),this._context=t}calculatePagePosition(){var y,R;const t=Se(this._context),n=(R=(y=this._context.unit.getSettings())==null?void 0:y.zoomRatio)!=null?R:1,{document:i,scene:s,docBackground:r}=t,c=s==null?void 0:s.getParent(),{width:A,height:l,pageMarginLeft:d,pageMarginTop:u}=i;if(c==null||A===Number.POSITIVE_INFINITY||l===Number.POSITIVE_INFINITY)return;const{width:g,height:h}=c;let m=0,f=u,p=0,S=0,I=Number.POSITIVE_INFINITY;g>(A+d*2)*n?(m=g/2-A*n/2,m/=n,p=(g-d*2)/n,I=0):(m=d,p=A+d*2,I=(p-g/n)/2),h>l?S=(h-u*2)/n:S=l+u*2,s.resize(p,S),g<=1&&(m=-1e4,f=-1e4),i.translate(m,f),r.translate(m,f);const C=s.getViewport(he.VIEW_MAIN);return I!==Number.POSITIVE_INFINITY&&C!=null&&C.scrollToViewportPos({viewportScrollX:I}),this}}var CA=Object.getOwnPropertyDescriptor,TA=(o,t,e,n)=>{for(var i=n>1?void 0:n?CA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Is=(o,t)=>(e,n)=>t(e,n,o);let Po=class extends a.Disposable{constructor(o,t,e){super(),this._context=o,this._docPageLayoutService=t,this._textSelectionManagerService=e;const n=this._context.unitId;if(a.isInternalEditorID(n)&&n!==a.DOCS_ZEN_EDITOR_UNIT_ID_KEY)return this;this._initResize()}_initResize(){this.disposeWithMe(a.fromEventSubject(this._context.engine.onTransformChange$).pipe(N.filter(o=>o.type===B.TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize),N.throttleTime(0,N.animationFrameScheduler)).subscribe(()=>{this._docPageLayoutService.calculatePagePosition(),this._textSelectionManagerService.refreshSelection()}))}};Po=TA([Is(1,a.Inject(No)),Is(2,a.Inject(x.DocSelectionManagerService))],Po);var yA=Object.getOwnPropertyDescriptor,bA=(o,t,e,n)=>{for(var i=n>1?void 0:n?yA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},ct=(o,t)=>(e,n)=>t(e,n,o);let Uo=class extends a.Disposable{constructor(t,e,n,i,s,r,c){super();M(this,"_loadedMap",new WeakSet);this._context=t,this._commandService=e,this._editorService=n,this._instanceSrv=i,this._docSelectionRenderService=s,this._docSkeletonManagerService=r,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:i,options:s}=t;e===this._context.unitId&&(this._docSelectionRenderService.removeAllRanges(),this._docSelectionRenderService.addDocRanges(n,i,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:i}=e;this.disposeWithMe(n.onPointerEnter$.subscribeEvent(()=>{this._isEditorReadOnly(t)||(n.cursor=B.CURSOR_TYPE.TEXT)})),this.disposeWithMe(n.onPointerLeave$.subscribeEvent(()=>{n.cursor=B.CURSOR_TYPE.DEFAULT,i.resetCursor()})),this.disposeWithMe(n.onPointerDown$.subscribeEvent((s,r)=>{if(this._isEditorReadOnly(t))return;const c=this._instanceSrv.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);(c==null?void 0:c.getUnitId())!==t&&this._instanceSrv.setCurrentUnitForType(t);const A=this._docSkeletonManagerService.getSkeleton(),{offsetX:l,offsetY:d}=s,u=this._getTransformCoordForDocumentOffset(l,d);if(u!=null){const{pageLayoutType:g=B.PageLayoutType.VERTICAL,pageMarginLeft:h,pageMarginTop:m}=n.getOffsetConfig(),{editArea:f}=A.findEditAreaByCoord(u,g,h,m),p=this._docSkeletonManagerService.getViewModel(),S=p.getEditArea();S!==B.DocumentEditArea.BODY&&f!==B.DocumentEditArea.BODY&&f!==S&&p.setEditArea(f)}if(this._docSelectionRenderService.__onPointDown(s),this._editorService.getEditor(t)){this._setEditorFocus(t);const{offsetX:g,offsetY:h}=s;setTimeout(()=>{t!==this._editorService.getFocusId()&&(this._setEditorFocus(t),this._docSelectionRenderService.setCursorManually(g,h))},0)}s.button!==2&&r.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:i,scene:s}=n,{documentTransform:r}=i.getOffsetConfig(),c=s.getViewports()[0];if(c==null)return;const A=c.transformVector2SceneCoord(B.Vector2.FromArray([t,e]));return r.clone().invert().applyPoint(A)}_isEditorReadOnly(t){const e=this._editorService.getEditor(t);return e?e.isReadOnly():!1}_setEditorFocus(t){this._editorService.focus(t)}_commandExecutedListener(){const t=[ue.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var n;if(t.includes(e.id)){const i=e.params,{unitId:s}=i,r=(n=this._docSelectionManagerService.__getCurrentSelection())==null?void 0:n.unitId;if(s!==r)return;this._docSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe(t=>{if(!t)return;const{unitId:e}=this._context;if(!a.isInternalEditorID(e)){this._docSelectionRenderService.focus();const s=this._context.unit.getSnapshot(),r=di(s);this._docSelectionManagerService.replaceDocRanges([{startOffset:r,endOffset:r}],{unitId:e,subUnitId:e},!1)}}))}};Uo=bA([ct(1,a.ICommandService),ct(2,ce),ct(3,a.IUniverInstanceService),ct(4,a.Inject(T.DocSelectionRenderService)),ct(5,a.Inject(x.DocSkeletonManagerService)),ct(6,a.Inject(x.DocSelectionManagerService))],Uo);var OA=Object.getOwnPropertyDescriptor,RA=(o,t,e,n)=>{for(var i=n>1?void 0:n?OA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Ke=(o,t)=>(e,n)=>t(e,n,o);let wo=class extends a.Disposable{constructor(o,t,e,n,i,s,r,c){super(),this._context=o,this._contextService=t,this._docSkeletonManagerService=e,this._univerInstanceService=n,this._commandService=i,this._textSelectionManagerService=s,this._editorService=r,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(a.FOCUSING_DOC))return;const i=this._univerInstanceService.getCurrentUniverDocInstance();if(!i)return;const{documentFlavor:s}=i.getSnapshot().documentStyle;if(s===a.DocumentFlavor.MODERN)return;const r=Math.abs(n.deltaX);let c=r<40?.2:r<80?.4:.2;c*=n.deltaY>0?-1:1,e.scaleX<1&&(c/=2);const A=i.zoomRatio;let l=+Number.parseFloat(`${A+c}`).toFixed(1);l=l>=4?4:l<=.1?.1:l,this._commandService.executeCommand(dn.id,{zoomRatio:l,unitId:i.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=[ue.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===tn.id&&this._commandService.executeCommand(dn.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()}};wo=RA([Ke(1,a.IContextService),Ke(2,a.Inject(x.DocSkeletonManagerService)),Ke(3,a.IUniverInstanceService),Ke(4,a.ICommandService),Ke(5,a.Inject(x.DocSelectionManagerService)),Ke(6,ce),Ke(7,a.Inject(No))],wo);var DA=Object.getOwnPropertyDescriptor,BA=(o,t,e,n)=>{for(var i=n>1?void 0:n?DA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Dt=(o,t)=>(e,n)=>t(e,n,o);const Es=300;T.DocStateChangeManagerService=class extends a.RxDisposable{constructor(e,n,i,s,r){super();M(this,"_docStateChange$",new N.BehaviorSubject(null));M(this,"docStateChange$",this._docStateChange$.asObservable());M(this,"_historyStateCache",new Map);M(this,"_changeStateCache",new Map);M(this,"_historyTimer",null);M(this,"_changeStateCacheTimer",null);this._undoRedoService=e,this._commandService=n,this._univerInstanceService=i,this._docStateEmitService=s,this._renderManagerService=r,this._initialize(),this._listenDocStateChange()}getStateCache(e){var n,i;return{history:(n=this._historyStateCache.get(e))!=null?n:[],collaboration:(i=this._changeStateCache.get(e))!=null?i:[]}}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===a.UndoCommandId||e.id===a.RedoCommandId){const n=this._univerInstanceService.getCurrentUniverDocInstance();if(n==null)return;const i=n.getUnitId();this._pushHistory(i),this._emitChangeState(i)}}))}_listenDocStateChange(){this._docStateEmitService.docStateChangeParams$.pipe(N.takeUntil(this.dispose$)).subscribe(e=>{var A;if(e==null)return;const{isCompositionEnd:n,isSync:i,syncer:s,...r}=e,c=(A=this._renderManagerService.getRenderById(i?s:e.unitId))==null?void 0:A.with(Ot);if(c!=null){if(n){const l=c.fetchComposedUndoRedoMutationParams();if(l==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:d,redoMutationParams:u,previousActiveRange:g}=l;r.redoState.actions=u.actions,r.undoState.actions=d.actions,r.undoState.textRanges=[g]}this._setChangeState(r)}})}_cacheChangeState(e,n="history"){const{trigger:i,unitId:s,noHistory:r,debounce:c=!1}=e;if(r||i==null||n==="history"&&(i===a.RedoCommandId||i===a.UndoCommandId))return;const A=n==="history"?this._historyStateCache:this._changeStateCache,l=n==="history"?this._pushHistory.bind(this):this._emitChangeState.bind(this);if(A.has(s)){const d=A.get(s);d==null||d.push(e)}else A.set(s,[e]);c?n==="history"?(this._historyTimer&&clearTimeout(this._historyTimer),this._historyTimer=setTimeout(()=>{l(s)},Es)):(this._changeStateCacheTimer&&clearTimeout(this._changeStateCacheTimer),this._changeStateCacheTimer=setTimeout(()=>{l(s)},Es)):l(s)}_pushHistory(e){const n=this._undoRedoService,i=this._historyStateCache.get(e);if(!Array.isArray(i)||i.length===0)return;const s=i.length,r=i[0].commandId,c=i[0],A=i[s-1],l={unitId:e,actions:i.reduce((u,g)=>a.JSONX.compose(u,g.redoState.actions),null),textRanges:A.redoState.textRanges},d={unitId:e,actions:i.reverse().reduce((u,g)=>a.JSONX.compose(u,g.undoState.actions),null),textRanges:c.undoState.textRanges};n.pushUndoRedo({unitID:e,undoMutations:[{id:r,params:d}],redoMutations:[{id:r,params:l}]}),i.length=0}_emitChangeState(e){const n=this._changeStateCache.get(e);if(!Array.isArray(n)||n.length===0)return;const i=n.length,{commandId:s,trigger:r,segmentId:c,noHistory:A,debounce:l}=n[0],d=n[0],u=n[i-1],g={unitId:e,actions:n.reduce((f,p)=>a.JSONX.compose(f,p.redoState.actions),null),textRanges:u.redoState.textRanges},h={unitId:e,actions:n.reverse().reduce((f,p)=>a.JSONX.compose(f,p.undoState.actions),null),textRanges:d.undoState.textRanges},m={commandId:s,unitId:e,trigger:r,redoState:g,undoState:h,segmentId:c,noHistory:A,debounce:l};n.length=0,this._docStateChange$.next(m)}},T.DocStateChangeManagerService=BA([Dt(0,a.Inject(a.IUndoRedoService)),Dt(1,a.ICommandService),Dt(2,a.IUniverInstanceService),Dt(3,a.Inject(x.DocStateEmitService)),Dt(4,B.IRenderManagerService)],T.DocStateChangeManagerService);var MA=Object.getOwnPropertyDescriptor,xA=(o,t,e,n)=>{for(var i=n>1?void 0:n?MA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},vs=(o,t)=>(e,n)=>t(e,n,o);const Cs="univer-doc-main-canvas";T.DocsRenderService=class extends a.RxDisposable{constructor(t,e){super(),this._instanceSrv=t,this._renderManagerService=e,this._init()}_init(){this._renderManagerService.createRender$.pipe(N.takeUntil(this.dispose$)).subscribe(t=>this._createRenderWithId(t)),this._instanceSrv.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC).forEach(t=>this._createRenderer(t)),this._instanceSrv.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_DOC).pipe(N.takeUntil(this.dispose$)).subscribe(t=>this._createRenderer(t)),this._instanceSrv.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_DOC).pipe(N.takeUntil(this.dispose$)).subscribe(t=>this._disposeRenderer(t))}_createRenderer(t){var i;const e=t.getUnitId(),n=(i=this._instanceSrv.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC))==null?void 0:i.getUnitId();this._renderManagerService.created$.subscribe(s=>{s.unitId===n&&(s.engine.getCanvas().setId(Cs),s.engine.getCanvas().getContext().setId(Cs))}),this._renderManagerService.has(e)||this._createRenderWithId(e)}_createRenderWithId(t){this._renderManagerService.createRender(t)}_disposeRenderer(t){const e=t.getUnitId();this._renderManagerService.removeRender(e)}},T.DocsRenderService=xA([vs(0,a.IUniverInstanceService),vs(1,B.IRenderManagerService)],T.DocsRenderService);class Ts extends a.Disposable{constructor(){super(...arguments);M(this,"_currentSelectorId");M(this,"_selectionChange$",new N.Subject);M(this,"selectionChange$",this._selectionChange$.asObservable());M(this,"_openSelector$",new N.Subject);M(this,"openSelector$",this._openSelector$.asObservable());M(this,"_selectorModalVisible$",new N.BehaviorSubject(!1));M(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 ys=a.createIdentifier("univer.range-selector.service"),_A={id:qe.id,preconditions:ya,binding:E.KeyCode.ENTER},NA={id:Ct.id,preconditions:ee,binding:E.KeyCode.BACKSPACE},PA={id:so.id,preconditions:ee,binding:E.KeyCode.DELETE},UA={id:Ee.id,binding:E.KeyCode.ARROW_UP,preconditions:ee,staticParameters:{direction:a.Direction.UP}},wA={id:Ee.id,binding:E.KeyCode.ARROW_DOWN,preconditions:ee,staticParameters:{direction:a.Direction.DOWN}},QA={id:Ee.id,binding:E.KeyCode.ARROW_LEFT,preconditions:ee,staticParameters:{direction:a.Direction.LEFT}},LA={id:Ee.id,binding:E.KeyCode.ARROW_RIGHT,preconditions:ee,staticParameters:{direction:a.Direction.RIGHT}},FA={id:ve.id,binding:E.KeyCode.ARROW_UP|E.MetaKeys.SHIFT,preconditions:ee,staticParameters:{direction:a.Direction.UP}},kA={id:ve.id,binding:E.KeyCode.ARROW_DOWN|E.MetaKeys.SHIFT,preconditions:ee,staticParameters:{direction:a.Direction.DOWN}},HA={id:ve.id,binding:E.KeyCode.ARROW_LEFT|E.MetaKeys.SHIFT,preconditions:ee,staticParameters:{direction:a.Direction.LEFT}},VA={id:ve.id,binding:E.KeyCode.ARROW_RIGHT|E.MetaKeys.SHIFT,preconditions:ee,staticParameters:{direction:a.Direction.RIGHT}},WA={id:To.id,binding:E.KeyCode.A|E.MetaKeys.CTRL_COMMAND,preconditions:o=>o.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&(o.getContextValue(a.FOCUSING_DOC)||o.getContextValue(a.EDITOR_ACTIVATED))};var KA=Object.defineProperty,zA=Object.getOwnPropertyDescriptor,jA=(o,t,e)=>t in o?KA(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,GA=(o,t,e,n)=>{for(var i=n>1?void 0:n?zA(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Bt=(o,t)=>(e,n)=>t(e,n,o),XA=(o,t,e)=>jA(o,t+"",e);T.UniverDocsUIPlugin=class extends a.Plugin{constructor(t=Qi,e,n,i,s,r){super(),this._config=t,this._injector=e,this._renderManagerSrv=n,this._commandService=i,this._logService=s,this._configService=r;const{menu:c,...A}=a.merge({},Qi,this._config);c&&this._configService.setConfig("menu",c,{merge:!0}),this._configService.setConfig($n,A),this._initDependencies(e),this._initializeShortcut(),this._initCommand()}onReady(){this._initRenderBasics(),this._markDocAsFocused(),a.touchDependencies(this._injector,[[T.DocStateChangeManagerService],[T.DocsRenderService]])}onRendered(){this._initUI(),this._initRenderModules(),a.touchDependencies(this._injector,[[hn],[mn],[st],[fn],[T.DocUIController]])}_initCommand(){[Ct,so,_e,Ne,Pe,Ue,Re,we,Qe,Le,Fe,Je,ke,Te,fo,Xt,et,Yt,io,qt,ue,ft,mt,Ze,pt,St,It,ge,Et,po,go,sn,an,$i,rn,cn,nn,on,it,Gn,bo,xe,ut,qe,kt,ht,Ht,Vt,Zn,yo,tn,me,oo,He,Xo,Bn,Yo,dn,To,Eo,Ee,ve,Jo].forEach(t=>{this._commandService.registerCommand(t)}),[yt,$t,en].forEach(t=>this.disposeWithMe(this._commandService.registerMultipleCommand(t)))}_initializeShortcut(){[UA,wA,LA,QA,FA,kA,HA,VA,WA,NA,PA,_A,Oa].forEach(t=>{this._injector.get(E.IShortcutService).registerShortcut(t)})}_initDependencies(t){a.mergeOverrideWithDependencies([[En],[vn],[T.DocUIController],[hn],[fn],[mn],[un],[st],[ce,{useClass:T.EditorService}],[ys,{useClass:Ts}],[ot,{useClass:Ao}],[T.DocCanvasPopManagerService],[T.DocsRenderService],[T.DocStateChangeManagerService],[T.DocAutoFormatService],[Ce]],this._config.override).forEach(n=>t.add(n))}_markDocAsFocused(){const t=this._injector.get(a.IUniverInstanceService),e=this._injector.get(ce);try{const n=t.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(!n)return;const i=n.getUnitId();e.isEditor(i)||t.focusUnit(n.getUnitId())}catch(n){this._logService.warn(n)}}_initUI(){this._injector.get(un)}_initRenderBasics(){[[x.DocSkeletonManagerService],[T.DocSelectionRenderService],[x.DocInterceptorService],[No],[Ot],[T.DocRenderController],[wo]].forEach(t=>{this._renderManagerSrv.registerRenderModule(a.UniverInstanceType.UNIVER_DOC,t)})}_initRenderModules(){[[T.DocEventManagerService],[T.DocBackScrollRenderController],[Uo],[Wn],[Po],[Mo],[Bo],[En],[_o],[xo],[vn]].forEach(t=>{this._renderManagerSrv.registerRenderModule(a.UniverInstanceType.UNIVER_DOC,t)})}},XA(T.UniverDocsUIPlugin,"pluginName",Ho),T.UniverDocsUIPlugin=GA([a.DependentOn(B.UniverRenderEnginePlugin),Bt(1,a.Inject(a.Injector)),Bt(2,B.IRenderManagerService),Bt(3,a.ICommandService),Bt(4,a.ILogService),Bt(5,a.IConfigService)],T.UniverDocsUIPlugin),T.AfterSpaceCommand=ut,T.AlignCenterCommand=St,T.AlignJustifyCommand=Et,T.AlignLeftCommand=pt,T.AlignOperationCommand=ge,T.AlignRightCommand=It,T.BreakLineCommand=fo,T.BulletListCommand=mt,T.ChangeListNestingLevelCommand=kt,T.ChangeListNestingLevelType=gt,T.ChangeListTypeCommand=ht,T.CheckListCommand=Ht,T.CoverContentCommand=Yo,T.CreateDocTableCommand=po,T.CutContentCommand=He,T.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX=Vo,T.DOCS_COMPONENT_DEFAULT_Z_INDEX=On,T.DOCS_COMPONENT_HEADER_LAYER_INDEX=Wo,T.DOCS_COMPONENT_MAIN_LAYER_INDEX=Mt,T.DOCS_VIEW_KEY=le,T.DOC_UI_PLUGIN_NAME=Ho,T.DOC_VERTICAL_PADDING=Do,T.DefaultDocContainerConfig=ko,T.DefaultToolbarConfig=Fo,T.DeleteCommand=et,T.DeleteCustomBlockCommand=Yt,T.DeleteLeftCommand=Ct,T.DeleteRightCommand=so,T.DocCopyCommand=yt,T.DocCreateTableOperation=An,T.DocCutCommand=$t,T.DocIMEInputManagerService=Ot,T.DocPasteCommand=en,T.DocSelectAllCommand=To,T.DocTableDeleteColumnsCommand=on,T.DocTableDeleteRowsCommand=nn,T.DocTableDeleteTableCommand=it,T.DocTableInsertColumnCommand=$i,T.DocTableInsertColumnLeftCommand=rn,T.DocTableInsertColumnRightCommand=cn,T.DocTableInsertRowAboveCommand=sn,T.DocTableInsertRowBellowCommand=an,T.DocTableInsertRowCommand=go,T.DocTableTabCommand=bo,T.DocsUIMenuSchema=as,T.Editor=ii,T.EditorInsertTextCommandId=Wi,T.EnterCommand=qe,T.IDocClipboardService=ot,T.IEditorService=ce,T.IMEInputCommand=yo,T.IRangeSelectorService=ys,T.InnerPasteCommand=oo,T.InsertCommand=Xt,T.ListOperationCommand=Ze,T.MergeTwoParagraphCommand=qt,T.MoveCursorOperation=Ee,T.MoveSelectionOperation=ve,T.NORMAL_TEXT_SELECTION_PLUGIN_NAME=Ms,T.NodePositionConvertToCursor=Ie,T.NodePositionConvertToRectRange=wn,T.OrderListCommand=ft,T.PastePluginLark=Gi,T.PastePluginUniver=Yi,T.PastePluginWord=qi,T.QuickListCommand=Zn,T.RangeSelectorService=Ts,T.RectRange=Ln,T.ReplaceContentCommand=Xo,T.ReplaceSnapshotCommand=Bn,T.ReplaceTextRunsCommand=Jo,T.ResetInlineFormatTextBackgroundColorCommand=Je,T.RichTextEditor=na,T.SetDocZoomRatioCommand=dn,T.SetDocZoomRatioOperation=ue,T.SetInlineFormatBoldCommand=_e,T.SetInlineFormatCommand=Te,T.SetInlineFormatFontFamilyCommand=Le,T.SetInlineFormatFontSizeCommand=Qe,T.SetInlineFormatItalicCommand=Ne,T.SetInlineFormatStrikethroughCommand=Ue,T.SetInlineFormatSubscriptCommand=Re,T.SetInlineFormatSuperscriptCommand=we,T.SetInlineFormatTextBackgroundColorCommand=ke,T.SetInlineFormatTextColorCommand=Fe,T.SetInlineFormatUnderlineCommand=Pe,T.TEXT_RANGE_LAYER_INDEX=Nt,T.TabCommand=xe,T.TextRange=Me,T.ToggleCheckListCommand=Vt,T.UpdateCommand=io,T.VIEWPORT_KEY=he,T.addCustomDecorationBySelectionFactory=_s,T.addCustomDecorationFactory=zo,T.calcDocRangePositions=Sn,T.convertPositionsToRectRanges=Ut,T.deleteCustomDecorationFactory=Ns,T.docDrawingPositionToTransform=Us,T.genTableSource=to,T.generateParagraphs=mo,T.getAnchorBounding=lt,T.getCanvasOffsetByEngine=ni,T.getCommandSkeleton=re,T.getCursorWhenDelete=Jt,T.getCustomBlockIdsInSelections=Hi,T.getCutActionsFromDocRanges=Vi,T.getDocObject=Ko,T.getDocObjectById=xs,T.getEmptyTableCell=zt,T.getEmptyTableRow=jt,T.getLineBounding=Pt,T.getOneTextSelectionRange=_n,T.getParagraphsInRange=Wt,T.getParagraphsInRanges=$e,T.getRichTextEditPath=$,T.getTableColumn=Gt,T.hasParagraphInTable=Ps,T.isInSameTableCell=Pn,T.isValidRectRange=Zo,T.neoGetDocObject=Se,T.transformToDocDrawingPosition=ws,T.useKeyboardEvent=jo,T.useResize=Go,T.whenDocAndEditorFocused=ee,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/docs-ui",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "private": false,
5
5
  "description": "Univer normal ui-plugin-docs",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -60,12 +60,12 @@
60
60
  },
61
61
  "dependencies": {
62
62
  "@univerjs/icons": "^0.2.20",
63
- "@univerjs/core": "0.6.3",
64
- "@univerjs/design": "0.6.3",
65
- "@univerjs/docs": "0.6.3",
66
- "@univerjs/drawing": "0.6.3",
67
- "@univerjs/engine-render": "0.6.3",
68
- "@univerjs/ui": "0.6.3"
63
+ "@univerjs/core": "0.6.4",
64
+ "@univerjs/design": "0.6.4",
65
+ "@univerjs/engine-render": "0.6.4",
66
+ "@univerjs/drawing": "0.6.4",
67
+ "@univerjs/ui": "0.6.4",
68
+ "@univerjs/docs": "0.6.4"
69
69
  },
70
70
  "devDependencies": {
71
71
  "less": "^4.2.2",
@@ -76,8 +76,8 @@
76
76
  "typescript": "^5.8.2",
77
77
  "vite": "^6.2.0",
78
78
  "vitest": "^3.0.7",
79
- "@univerjs/docs-drawing": "0.6.3",
80
- "@univerjs-infra/shared": "0.6.3"
79
+ "@univerjs-infra/shared": "0.6.4",
80
+ "@univerjs/docs-drawing": "0.6.4"
81
81
  },
82
82
  "scripts": {
83
83
  "test": "vitest run",