@univerjs/preset-docs-core 0.8.1-nightly.202506161607 → 0.8.1-nightly.202506181607
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/umd/index.js +2 -2
- package/package.json +9 -9
package/lib/umd/index.js
CHANGED
|
@@ -9,7 +9,7 @@ hover:univer-bg-gray-100 whitespace-nowrap univer-w-max
|
|
|
9
9
|
`;function g6(e){const{children:t,className:n,style:r,disabled:i=!1,active:l=!1,noIcon:o,onClick:c,onDoubleClick:v,...m}=e,b=w=>{if(i){w.preventDefault();return}c&&c(w)},d=w=>{if(i){w.preventDefault();return}v&&v(w)};return C.jsx("button",{type:"button",className:Z.clsx(v6,{"univer-px-2":o,"!univer-bg-gray-200 dark:!univer-bg-gray-500":l}),style:r,disabled:i,onClick:b,onDoubleClick:d,...m,children:t})}function m6(e){const{disabled$:t,hidden$:n,activated$:r,value$:i}=e,[l,o]=a.useState(),[c,v]=a.useState(!1),[m,b]=a.useState(!1),[d,w]=a.useState(!1);return a.useEffect(()=>{const y=[];return t&&y.push(t.subscribe(S=>v(S))),n&&y.push(n.subscribe(S=>w(S))),r&&y.push(r.subscribe(S=>b(S))),i&&y.push(i.subscribe(S=>o(S))),()=>y.forEach(S=>S.unsubscribe())},[r,t,n,i]),{disabled:c,value:l,activated:m,hidden:d}}const We=a.createContext({dropdownVisible:!1,setDropdownVisible:e=>{}}),f0=a.forwardRef((e,t)=>{const{children:n,...r}=e,i=a.useRef(null),[l,o]=a.useState(!1),[c,v]=a.useState(!1);function m(w){o(c?!1:w)}function b(w){v(w),o(!1)}const d=a.useMemo(()=>({dropdownVisible:c,setDropdownVisible:b}),[c]);return a.useImperativeHandle(t,()=>({el:i.current})),r.title?C.jsx(Z.Tooltip,{visible:l,onVisibleChange:m,...r,children:C.jsx("span",{ref:i,children:C.jsx(We.Provider,{value:d,children:n})})}):C.jsx("span",{ref:i,children:n})});function h0(e){const{children:t,overlay:n,disabled:r,align:i="start"}=e,{dropdownVisible:l,setDropdownVisible:o}=a.useContext(We);function c(v){o(v)}return C.jsx(Z.Dropdown,{align:i,overlay:C.jsx("div",{className:"univer-grid univer-gap-2",children:n}),disabled:r,open:l,onOpenChange:c,children:C.jsx("div",{className:"univer-h-full",onClick:v=>v.stopPropagation(),children:t})})}function pe({icon:e,value:t,option:n,onOptionSelect:r}){var o;const i=c=>{r==null||r({value:c,label:n==null?void 0:n.label,commandId:n==null?void 0:n.commandId})},l=typeof n.label=="string"||typeof n.label=="object"&&((o=n.label)==null?void 0:o.selectable)!==!1;return C.jsxs("div",{className:Z.clsx("univer-relative univer-flex univer-items-center univer-gap-2",{"univer-pl-6":l}),children:[l&&String(t)===String(n.value)&&C.jsx(Ve,{className:"univer-absolute univer-left-1 univer-top-0.5 univer-text-primary-600"}),C.jsx(d1,{className:"univer-text-sm",icon:e,value$:n.value$,value:n.value,label:n.label,onChange:i})]})}function p6({menuId:e,slot:t,value:n,options:r,children:i,disabled:l,onOptionSelect:o}){var T;const{dropdownVisible:c,setDropdownVisible:v}=a.useContext(We),m=R.useDependency(S1),[b,d]=a.useState({}),w=a.useMemo(()=>e?m.getMenuByPositionKey(e):[],[e]),y=a.useMemo(()=>w.filter(D=>{var V;if(!D.children)return!b[D.key];const I=((V=D.key)==null?void 0:V.toString())||"";return!b[I]}),[w,b]);function S(D){v(D)}if(a.useEffect(()=>{const D=[];return w.forEach(I=>{var V;if(I.children){const O=I.children.map(M=>{var x,$;return($=(x=M.item)==null?void 0:x.hidden$)!=null?$:z.of(!1)}),U=z.combineLatest(O).subscribe(M=>{const x=M.every($=>$===!0);d($=>({...$,[I.key]:x}))});D.push(U)}else if((V=I.item)!=null&&V.hidden$){const O=I.item.hidden$.subscribe(U=>{d(M=>({...M,[I.key]:U}))});D.push(O)}}),()=>{D.forEach(I=>I==null?void 0:I.unsubscribe()),d({})}},[w]),t)return C.jsx(h0,{disabled:l,overlay:r.map((D,I)=>C.jsx(pe,{value:n,option:D,onOptionSelect:o},I)),children:i});if(r!=null&&r.length){const D=r.map(I=>{var V;return{type:"item",className:Z.clsx({"focus:univer-bg-white":typeof I.label!="string"&&((V=I.label)==null?void 0:V.hoverable)===!1}),children:C.jsx(pe,{icon:I.icon,value:n,option:I,onOptionSelect:o}),disabled:I.disabled,onSelect:()=>{typeof I.value>"u"||o==null||o({...I})}}});for(const I of y){if(!I.item)continue;const{title:V,id:O,commandId:U,icon:M}=I.item;if(!V)throw new Error("Menu item title is required");D.push({type:"item",children:C.jsx(pe,{icon:M,value:n,option:{label:{name:V,selectable:!1}}}),onSelect:()=>{o==null||o({commandId:U,id:O})}})}return C.jsx(Z.DropdownMenu,{align:"start",items:D,disabled:l,open:c,onOpenChange:S,children:i})}else{const D=[];for(const I of y)if(I.item){const{title:V,id:O,commandId:U,icon:M}=I.item;if(!V)throw new Error("Menu item title is required");D.push({type:"item",children:C.jsx(pe,{icon:M,value:n,option:{label:{name:V,selectable:!1}}}),onSelect:()=>{o==null||o({commandId:U,id:O})}})}else(T=I.children)!=null&&T.length;return C.jsx(Z.DropdownMenu,{align:"start",items:D,disabled:l,open:c,onOpenChange:S,children:i})}}const ne=a.forwardRef((e,t)=>{const n=R.useDependency(h.LocaleService),r=R.useDependency(h.ICommandService),i=R.useDependency(H1),l=R.useDependency(v1),{value:o,hidden:c,disabled:v,activated:m}=m6(e),b=(W,Y)=>{i.focus(),r.executeCommand(W,Y)},{tooltip:d,shortcut:w,icon:y,title:S,label:T,id:D,commandId:I,type:V,slot:O,params:U}=e,M=n.t(d!=null?d:"")+(w?` (${w})`:""),{selections:x}=e,$=a.useMemo(()=>z.isObservable(x)?x:new z.Observable(W=>{W.next(x)}),[x]),X=R.useObservable($),B=a.useMemo(()=>z.isObservable(y)?y:new z.Observable(W=>{var e1,l1;const Y=(l1=(e1=X==null?void 0:X.find(C1=>C1.value===o))==null?void 0:e1.icon)!=null?l1:y;W.next(Y)}),[y,X,o]),G=R.useObservable(B,void 0,!0);function q(W){var a1;const Y=e.selectionsCommandId,e1=I!=null?I:D,l1=(a1=Y!=null?Y:I)!=null?a1:D;function C1(r1){if(v)return;let u1=l1;r1.id&&(u1=r1.id),b(u1,{value:r1.value})}function b1(r1){v||b(l1,{value:r1})}function y1(){v||W===g1.BUTTON_SELECTOR&&b(e1,{value:o})}return W===g1.BUTTON_SELECTOR?C.jsxs("div",{"data-u-command":D,"data-disabled":v,className:Z.clsx("univer-animate-in univer-fade-in univer-group univer-relative univer-flex univer-h-6 univer-cursor-pointer univer-items-center univer-rounded univer-pr-5 univer-text-sm univer-transition-colors hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",{"univer-text-gray-900 dark:!univer-text-white":!v,"univer-pointer-events-none univer-cursor-not-allowed univer-text-gray-300 dark:!univer-text-gray-600":v}),children:[C.jsx("div",{className:Z.clsx("univer-relative univer-z-[1] univer-flex univer-h-full univer-items-center univer-rounded-l univer-px-1 univer-transition-colors hover:univer-bg-gray-200 dark:hover:!univer-bg-gray-600",{"univer-bg-gray-200 dark:!univer-bg-gray-500":m,"univer-bg-gray-100":m&&v}),onClick:y1,children:C.jsx(d1,{icon:G,title:S,value:o,label:T,onChange:b1})}),C.jsx(p6,{menuId:D,slot:O,value:o,options:X,disabled:v,onOptionSelect:C1,children:C.jsx("div",{className:Z.clsx("univer-absolute univer-right-0 univer-top-0 univer-box-border univer-flex univer-h-6 univer-w-5 univer-items-center univer-justify-center univer-rounded-r univer-transition-colors hover:univer-bg-gray-200 dark:hover:!univer-bg-gray-600",{"univer-pointer-events-none univer-cursor-not-allowed univer-text-gray-300 dark:!univer-text-gray-600":v,"univer-bg-gray-200 dark:!univer-bg-gray-500":m,"univer-bg-gray-100":m&&v}),"data-disabled":v,children:C.jsx(G1,{})})})]}):C.jsx(p6,{menuId:D,slot:O,value:o,options:X,disabled:v,onOptionSelect:C1,children:C.jsxs("div",{"data-u-command":D,className:Z.clsx("univer-animate-in univer-fade-in univer-relative univer-flex univer-h-6 univer-cursor-pointer univer-items-center univer-gap-2 univer-whitespace-nowrap univer-rounded univer-px-1 univer-transition-colors hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",{"univer-text-gray-900 dark:!univer-text-white":!v,"univer-pointer-events-none univer-cursor-not-allowed univer-text-gray-300 dark:!univer-text-gray-600":v,"univer-bg-gray-200":m,"univer-bg-gray-100":m&&v}),children:[C.jsx(d1,{icon:G,title:S,value:o,label:T,onChange:b1}),C.jsx("div",{className:Z.clsx("univer-flex univer-h-full univer-items-center",{"univer-pointer-events-none univer-cursor-not-allowed univer-text-gray-300 dark:!univer-text-gray-600":v}),children:C.jsx(G1,{})})]})})}function J(){var Y;const W=l.get(typeof T=="string"?T:(Y=T==null?void 0:T.name)!=null?Y:"");return C.jsx(g6,{"data-u-command":D,className:"univer-text-sm",noIcon:!y,active:m,disabled:v,onClick:()=>{var e1;return b((e1=e.commandId)!=null?e1:e.id,o!=null?o:U)},onDoubleClick:()=>e.subId&&b(e.subId),children:W?C.jsx(d1,{title:S,value:o,label:T}):y?C.jsx(d1,{icon:y}):C.jsx(d1,{title:S})})}function K(){switch(V){case g1.BUTTON_SELECTOR:case g1.SELECTOR:case g1.SUBITEMS:return q(V);case g1.BUTTON:default:return J()}}return!c&&C.jsx(f0,{ref:t,title:M,placement:"bottom",children:K()})}),C0={[f1.START]:bt,[f1.INSERT]:Et,[f1.FORMULAS]:Re,[f1.DATA]:X3,[f1.VIEW]:lt,[f1.OTHERS]:Te};function b6(e){const{ribbonType:t,headerMenuComponents:n,headerMenu:r=!0}=e,i=R.useDependency(S1),l=R.useDependency(h.IUniverInstanceService),o=R.useDependency(h.LocaleService),[c,v]=a.useState(0),m=R.useObservable(l.focused$);a.useEffect(()=>{const B=i.menuChanged$.subscribe(()=>{v(G=>G+1)});return()=>{B.unsubscribe()}},[]);const b=a.useRef(null),d=a.useRef({}),[w,y]=a.useState([]),[S,T]=a.useState(f1.START),[D,I]=a.useState(!1),[V,O]=a.useState([]),[U,M]=a.useState(!1),x=a.useCallback(B=>{d.current={},T(B.key),I(!1)},[]);a.useEffect(()=>{var J;const B=i.getMenuByPositionKey(X1.RIBBON),G=[],q=[];for(const K of B)if(K.children){for(const W of K.children)if(W.children)for(const Y of W.children)(J=Y.item)!=null&&J.hidden$&&(G.push(Y.item.hidden$),q.push(`${K.key}/${W.key}/${Y.key}`))}z.combineLatest(G).subscribe(K=>{var e1,l1,C1,b1,y1,a1;const W=[],Y=K.map((r1,u1)=>r1?q[u1]:null).filter(r1=>!!r1);for(const r1 of B){const u1={...r1,children:[]};if((e1=r1.children)!=null&&e1.length)for(const L1 of r1.children){const I1={...L1,children:[]};let Z1=!0;if((l1=L1.children)!=null&&l1.length){for(const B1 of L1.children){const F1=`${r1.key}/${L1.key}/${B1.key}`;Y.includes(F1)||(C1=I1.children)==null||C1.push(B1)}(b1=I1.children)!=null&&b1.every(B1=>{var F1;return((F1=B1.children)==null?void 0:F1.length)===0})&&(Z1=!1)}Z1&&((y1=u1.children)==null||y1.push(I1))}(a1=u1.children)!=null&&a1.length&&u1.children.every(L1=>{var I1;return(I1=L1.children)==null?void 0:I1.length})&&W.push(u1)}if(t==="simple"){const r1=[{key:f1.START,children:[],order:0}];W.forEach(u1=>{var L1;(L1=u1.children)==null||L1.forEach(I1=>{var Z1;(Z1=r1[0].children)==null||Z1.push(I1)})}),y(r1)}else y(W)}).unsubscribe()},[c,m]);const $=a.useMemo(()=>{var J,K;const B=(K=(J=w.find(W=>W.key===S))==null?void 0:J.children)!=null?K:[],G=[],q=[];for(const W of B)if(W.children){const Y=W.children.filter(e1=>!V.includes(e1.key));Y.length>0&&G.push({...W,children:Y}),Y.length<W.children.length&&q.push({...W,children:W.children.filter(e1=>V.includes(e1.key))})}return{allGroups:B,visibleGroups:G,hiddenGroups:q}},[V,w,S]);a.useEffect(()=>{let B=null;const G=new ResizeObserver(h.throttle(q=>{for(const J of q)M(!0),B=requestAnimationFrame(()=>{var y1,a1;const{width:K}=J.contentRect,Y=Object.values(d.current).sort((r1,u1)=>r1.order-u1.order||r1.groupOrder-u1.groupOrder||r1.itemOrder-u1.itemOrder),e1=[];let l1=32;const b1=(((a1=(y1=w.find(r1=>r1.key===S))==null?void 0:y1.children)!=null?a1:[]).length-1)*8;l1+=b1;for(const{el:r1,key:u1}of Y){const{width:L1}=r1.getBoundingClientRect();l1+=L1+8,l1>K&&e1.push(u1)}O(e1),M(!1)})},100));return G.observe(b.current),()=>{B&&cancelAnimationFrame(B),G.disconnect()}},[w,S]);const X=a.useMemo(()=>C.jsx("div",{"aria-hidden":"true",className:Z.clsx("univer-invisible univer-absolute -univer-left-[99999] -univer-top-[99999] univer-box-border univer-flex univer-h-10 univer-min-w-min univer-items-center univer-px-3 univer-opacity-0",{"univer-hidden":!U},Z.divideXClassName,Z.borderBottomClassName),children:$.allGroups.map((B,G)=>{var q,J;return(((q=B.children)==null?void 0:q.length)||B.item)&&C.jsx(a.Fragment,{children:C.jsx("div",{className:"univer-grid univer-grid-flow-col univer-gap-2 univer-px-2",children:B.children&&((J=B.children)==null?void 0:J.map(K=>K.item&&C.jsx(ne,{...K.item,ref:W=>{W!=null&&W.el&&(d.current[K.key]={el:W.el,key:K.key,order:G,groupOrder:B.order,itemOrder:K.order})}},K.key)))})},B.key)})}),[$.allGroups,U]);return C.jsxs(C.Fragment,{children:[r&&n&&n.size>0&&C.jsx("header",{className:Z.clsx("univer-relative univer-h-11 univer-select-none",Z.borderBottomClassName),children:C.jsx("div",{className:"univer-absolute univer-right-2 univer-top-0 univer-flex univer-h-full univer-items-center univer-gap-2 [&>*]:univer-inline-flex [&>*]:univer-h-6 [&>*]:univer-items-center [&>*]:univer-rounded [&>*]:univer-px-1 [&>*]:univer-transition-colors hover:[&>*]:univer-bg-gray-100",children:C.jsx(m1,{components:n})})}),C.jsxs("div",{className:Z.clsx("univer-box-border univer-grid univer-h-10 univer-grid-flow-col univer-items-center univer-px-3",{"univer-grid-cols-[auto,1fr]":w.length>1,"univer-grid-cols-none":w.length===1},Z.borderBottomClassName),children:[w.length>1&&C.jsx(Z.HoverCard,{className:"univer-max-w-96 !univer-rounded-xl",align:"start",open:D,overlay:C.jsx("div",{className:"univer-grid univer-gap-1 univer-px-2 univer-py-1",children:w.map(B=>{const G=C0[B.key];return C.jsxs("a",{"data-u-comp":"ribbon-group-btn",className:"univer-box-border univer-flex univer-cursor-pointer univer-items-center univer-gap-2.5 univer-rounded-lg univer-px-2 univer-py-1.5 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",onClick:()=>x(B),children:[C.jsx("span",{className:Z.clsx("univer-box-border univer-flex univer-size-9 univer-flex-shrink-0 univer-items-center univer-justify-center univer-rounded-lg",Z.borderClassName),children:C.jsx(G,{className:"univer-text-gray-500 dark:!univer-text-gray-300"})}),C.jsxs("span",{className:"univer-flex univer-flex-col",children:[C.jsx("strong",{className:"univer-text-sm univer-font-semibold univer-text-gray-800 dark:!univer-text-gray-200",children:o.t(B.key)}),C.jsx("span",{className:"univer-text-xs univer-text-gray-400",children:o.t(`${B.key}Desc`)})]})]},B.key)})}),onOpenChange:I,children:C.jsxs("a",{className:"univer-mr-2 univer-flex univer-h-7 univer-cursor-pointer univer-items-center univer-gap-1.5 univer-whitespace-nowrap !univer-rounded-full univer-bg-gray-700 univer-pl-3 univer-pr-2 univer-text-sm univer-text-white dark:!univer-bg-gray-200 dark:!univer-text-gray-800",onClick:()=>I(!0),children:[o.t(S),C.jsx(G1,{className:"univer-text-gray-200 dark:!univer-text-gray-500"})]})}),C.jsxs("div",{"data-u-comp":"ribbon-toolbar",ref:b,className:Z.clsx("univer-flex univer-overflow-hidden",Z.divideXClassName),children:[$.visibleGroups.map(B=>{var G,q;return(((G=B.children)==null?void 0:G.length)||B.item)&&C.jsx(a.Fragment,{children:C.jsx("div",{className:"univer-grid univer-grid-flow-col univer-gap-2 univer-px-2",children:B.children&&((q=B.children)==null?void 0:q.map(J=>J.item&&C.jsx(ne,{...J.item},J.key)))})},B.key)}),V.length>0&&C.jsx("div",{"data-u-comp":"ribbon-toolbar-more",className:"univer-pl-2 rtl:univer-pr-2",children:C.jsx(Z.Dropdown,{collisionPadding:{right:12,left:12},overlay:C.jsx("div",{className:"univer-box-border univer-grid univer-max-w-[var(--radix-popper-available-width)] univer-gap-2 univer-p-2",children:$.hiddenGroups.map(B=>{var G;return C.jsx("div",{className:"univer-flex univer-items-center univer-gap-2",children:C.jsx("div",{className:"univer-flex univer-flex-wrap univer-gap-2",children:B.children?(G=B.children)==null?void 0:G.map(q=>q.item&&C.jsx(ne,{...q.item},q.key)):B.item&&C.jsx(ne,{...B.item},B.key)})},B.key)})}),children:C.jsx("a",{className:v6,type:"button",children:C.jsx(Te,{})})})})]})]}),X]})}class re extends h.Disposable{constructor(){super(...arguments);j(this,"_styleSheetId","univer-theme-css-variables")}injectThemeToHead(n){function r(c,v="--univer"){const m=[];function b(d,w=""){for(const y in d){const S=d[y],T=w?`${w}-${y}`:y;typeof S=="object"&&S!==null?b(S,T):m.push(`${v}-${T}: ${S};`)}}return b(c),m.join(`
|
|
10
10
|
`)}const i=r(n),l=document.getElementById(this._styleSheetId);l&&l.remove();const o=document.createElement("style");o.setAttribute("id",this._styleSheetId),o.innerHTML=`:root {
|
|
11
11
|
${i}
|
|
12
|
-
}`,document.head.appendChild(o)}dispose(){super.dispose()}}const ie=h.createIdentifier("ui.contextmenu.service");class Ye extends h.Disposable{constructor(){super(...arguments);j(this,"_currentHandler",null);j(this,"disabled",!1)}get visible(){var n,r;return(r=(n=this._currentHandler)==null?void 0:n.visible)!=null?r:!1}disable(){this.disabled=!0}enable(){this.disabled=!1}triggerContextMenu(n,r){var i;n.stopPropagation(),!this.disabled&&((i=this._currentHandler)==null||i.handleContextMenu(n,r))}hideContextMenu(){var n;(n=this._currentHandler)==null||n.hideContextMenu()}registerContextMenuHandler(n){if(this._currentHandler)throw new Error("There is already a context menu handler!");return this._currentHandler=n,h.toDisposable(()=>this._currentHandler=null)}}function L6(){const e=a.useRef(null),[t,n]=a.useState(!1),[r,i]=a.useState(""),[l,o]=a.useState([0,0]),c=a.useRef(t),v=R.useDependency(ie),m=R.useDependency(h.ICommandService),b=R.useInjector();c.current=t,a.useEffect(()=>{const y=v.registerContextMenuHandler({handleContextMenu:d,hideContextMenu(){n(!1)},get visible(){return c.current}});function S(T){e.current&&!e.current.contains(T.target)&&w()}return document.addEventListener("pointerdown",S),document.addEventListener("wheel",w),()=>{document.removeEventListener("pointerdown",S),document.removeEventListener("wheel",w),y.dispose()}},[v]);function d(y,S){n(!1),requestAnimationFrame(()=>{i(S),o([y.clientX,y.clientY]),n(!0)})}function w(){n(!1)}return C.jsx(Z.Popup,{visible:t,offset:l,children:C.jsx("section",{ref:e,children:r&&C.jsx(Ae,{menuType:r,onOptionSelect:y=>{const{label:S,commandId:T,value:D}=y;m&&m.executeCommand(T!=null?T:S,{value:D}),b.get(H1).focus(),n(!1)}})})})}const be=h.createIdentifier("univer.global-zone-service");function Xe(){const e=R.useDependency(be),[t,n]=a.useState(!1),r=R.useObservable(e.componentKey$,e.componentKey),i=R.useDependency(v1),l=a.useMemo(()=>{const o=i.get(r!=null?r:"");if(o)return o},[r,i]);return a.useEffect(()=>{const o=e.visible$.subscribe(c=>{n(c)});return()=>{o.unsubscribe()}},[e.visible$]),t?C.jsx("section",{className:Z.clsx("univer-absolute univer-bg-gray-100",{"univer-hidden":!t,"univer-inset-0 univer-z-[100] univer-block univer-size-full":t}),children:l&&C.jsx(l,{})}):null}function qe(){const e=R.useDependency($1),t=R.useObservable(e.sidebarOptions$),n=a.useRef(null),r=a.useMemo(()=>{if(!t)return null;const o={...t};for(const c of["children","header","footer"]){const v=c;if(t[v]){const{key:m,...b}=t[v];b&&(o[v]=C.jsx(d1,{...b},m))}}return o},[t]);a.useEffect(()=>(n.current&&e.setContainer(n.current),()=>{e.setContainer(void 0)}),[e]),a.useEffect(()=>{const o=v=>{e.scrollEvent$.next(v)},c=n.current;return c&&c.addEventListener("scroll",o),()=>{c==null||c.removeEventListener("scroll",o)}},[e]);const i=a.useMemo(()=>r!=null&&r.visible?typeof r.width=="number"?`${r.width}px`:r.width:0,[r]);function l(){var c;const o={...t,visible:!1};e.options.visible=!1,e.sidebarOptions$.next(o),(c=o==null?void 0:o.onClose)==null||c.call(o)}return C.jsx("section",{"data-u-comp":"sidebar",className:Z.clsx("univer-relative univer-h-full univer-bg-white univer-text-gray-900 dark:!univer-bg-gray-900 dark:!univer-text-white",{"univer-w-96 univer-translate-x-0":r==null?void 0:r.visible,"univer-w-0 univer-translate-x-full":!(r!=null&&r.visible)}),style:{width:i},children:C.jsxs("section",{ref:n,className:Z.clsx("univer-box-border univer-grid univer-h-0 univer-min-h-full univer-grid-rows-[auto_1fr_auto] univer-overflow-y-auto",Z.borderLeftBottomClassName,Z.scrollbarClassName),children:[C.jsxs("header",{className:"univer-sticky univer-top-0 univer-z-10 univer-box-border univer-flex univer-items-center univer-justify-between univer-bg-white univer-p-4 univer-pb-2 univer-text-base univer-font-medium univer-text-gray-800 dark:!univer-bg-gray-900 dark:!univer-text-white",children:[r==null?void 0:r.header,C.jsx("a",{className:"univer-cursor-pointer univer-text-gray-500 dark:!univer-text-gray-300",onClick:l,children:C.jsx(Ne,{})})]}),C.jsx("section",{className:"univer-box-border univer-px-4",style:r==null?void 0:r.bodyStyle,children:r==null?void 0:r.children}),(r==null?void 0:r.footer)&&C.jsx("footer",{className:"univer-sticky univer-bottom-0 univer-box-border univer-bg-white univer-p-4 dark:!univer-bg-gray-900",children:r.footer})]})})}const Le=h.createIdentifier("univer.zen-zone-service");function Je(){const e=R.useDependency(Le),[t,n]=a.useState(!1),[r,i]=a.useState(),l=R.useObservable(e.temporaryHidden$),o=R.useDependency(v1);a.useEffect(()=>{const v=[e.visible$.subscribe(m=>{n(m)}),e.componentKey$.subscribe(m=>{i(m)})];return()=>{v.forEach(m=>{m.unsubscribe()})}},[]);const c=a.useMemo(()=>{const v=o.get(r!=null?r:"");if(v)return v},[r]);return C.jsx("section",{className:Z.clsx("univer-absolute univer-z-[-1] univer-flex",{"univer-animate-in univer-fade-in univer-inset-0 univer-z-[100] univer-bg-gray-100":t,"univer-hidden":l}),children:C.jsx("div",{className:"univer-relative univer-flex-1",children:c&&C.jsx(c,{})})})}function v0(e){const t=T9(Y1);return C.jsx(g0,{...e,...t})}function g0(e){var K;const{header:t=!0,toolbar:n=!0,footer:r=!0,headerMenu:i=!0,contextMenu:l=!0,ribbonType:o="default",mountContainer:c,onRendered:v}=e,m=R.useDependency(h.LocaleService),b=R.useDependency(h.ThemeService),d=R.useDependency(re),w=a.useRef(null),S=R.useDependency(h.IConfigService).getConfig(Y1),T=p1(o1.CUSTOM_HEADER),D=p1(o1.FOOTER),I=p1(o1.HEADER),V=p1(o1.HEADER_MENU),O=p1(o1.CONTENT),U=p1(o1.LEFT_SIDEBAR),M=p1(o1.GLOBAL),x=p1(o1.TOOLBAR),$=(K=S==null?void 0:S.popupRootId)!=null?K:"univer-popup-portal";a.useLayoutEffect(()=>{const W=b.currentTheme$.subscribe(Y=>{d.injectThemeToHead(Y)});return()=>{W.unsubscribe()}},[]);const[X,B]=a.useState(!1);a.useLayoutEffect(()=>{const W=b.darkMode$.subscribe(Y=>{B(Y),Y?document.documentElement.classList.add("univer-dark"):document.documentElement.classList.remove("univer-dark")});return()=>{W.unsubscribe()}},[]),a.useEffect(()=>{w.current&&(v==null||v(w.current))},[v]);const[G,q]=a.useState(m.getLocales()),J=a.useMemo(()=>document.createElement("div"),[]);return a.useEffect(()=>{document.body.appendChild(J);const W=[m.localeChanged$.subscribe(()=>{q(m.getLocales())})];return()=>{W.forEach(Y=>Y.unsubscribe()),document.body.removeChild(J)}},[m,c,J]),C.jsxs(Z.ConfigProvider,{locale:G==null?void 0:G.design,mountContainer:J,children:[C.jsxs("div",{"data-u-comp":"workbench-layout",className:Z.clsx("univer-flex univer-h-full univer-min-h-0 univer-flex-col univer-bg-white dark:!univer-bg-gray-800",{"univer-dark":X}),tabIndex:-1,onBlur:W=>W.stopPropagation(),onContextMenu:W=>W.preventDefault(),children:[C.jsx("div",{className:"univer-relative univer-flex univer-min-h-0 univer-flex-col univer-bg-white",children:C.jsx(m1,{components:T},"custom-header")}),t&&n&&C.jsx("header",{"data-u-comp":"headerbar",className:"univer-relative univer-z-10 univer-w-full",children:C.jsx(m1,{components:x,sharedProps:{ribbonType:o,headerMenuComponents:V,headerMenu:i}},"toolbar")}),C.jsxs("section",{className:"univer-relative univer-flex univer-min-h-0 univer-flex-1 univer-flex-col",children:[C.jsxs("div",{className:"univer-grid univer-h-full univer-grid-cols-[auto_1fr_auto] univer-grid-rows-[100%] univer-overflow-hidden",children:[C.jsx("aside",{"data-u-comp":"left-sidebar",className:"univer-h-full",children:C.jsx(m1,{components:U},"left-sidebar")}),C.jsxs("section",{className:Z.clsx("univer-relative univer-grid univer-flex-1 univer-grid-rows-[auto_1fr] univer-overflow-hidden univer-bg-white",Z.borderBottomClassName),children:[C.jsx("header",{children:t&&C.jsx(m1,{components:I},"header")}),C.jsx("section",{className:"univer-relative univer-overflow-hidden dark:!univer-bg-gray-900",ref:w,"data-range-selector":!0,onContextMenu:W=>W.preventDefault(),children:C.jsx(m1,{components:O},"content")})]}),C.jsx("aside",{"data-u-comp":"right-sidebar",className:"univer-h-full",children:C.jsx(qe,{})})]}),r&&C.jsx("footer",{children:C.jsx(m1,{components:D,sharedProps:{contextMenu:l}},"footer")}),C.jsx(Je,{})]})]}),C.jsx(m1,{components:M},"global"),C.jsx(Xe,{}),l&&C.jsx(L6,{}),C.jsx(m0,{}),C.jsx("div",{id:$})]})}function m0(){const{mountContainer:e}=a.useContext(Z.ConfigContext),t=p1(o1.FLOATING);return _3.createPortal(C.jsx(m1,{components:t},"floating"),e)}const p0=3e3;class Qe extends h.Disposable{constructor(n,r,i,l,o){super();j(this,"_steadyTimeout");j(this,"_renderTimeout");j(this,"_currentRenderId",null);this._injector=n,this._instanceService=r,this._layoutService=i,this._lifecycleService=l,this._renderManagerService=o}dispose(){super.dispose(),clearTimeout(this._steadyTimeout),clearTimeout(this._renderTimeout)}_bootstrapWorkbench(){this.disposeWithMe(this.bootstrap(async(n,r)=>{this._layoutService&&(this.disposeWithMe(this._layoutService.registerRootContainerElement(r)),this.disposeWithMe(this._layoutService.registerContentElement(n)));try{await this._lifecycleService.onStage(h.LifecycleStages.Ready),this._renderTimeout=window.setTimeout(()=>{const i=this._renderManagerService.getRenderAll();for(const[l]of i)if(this._changeRenderUnit(l,n))break;this.disposeWithMe(this._instanceService.focused$.subscribe(l=>{l&&this._changeRenderUnit(l,n)})),this.disposeWithMe(this._renderManagerService.created$.subscribe(l=>{var o;l.unitId===((o=this._instanceService.getFocusedUnit())==null?void 0:o.getUnitId())&&this._changeRenderUnit(l.unitId,n)})),this.disposeWithMe(this._renderManagerService.disposed$.subscribe(l=>{this._currentRenderId===l&&(this._currentRenderId=null)})),this._lifecycleService.stage=h.LifecycleStages.Rendered,this._steadyTimeout=window.setTimeout(()=>{this._lifecycleService.stage=h.LifecycleStages.Steady},p0)},300)}catch(i){if(i instanceof h.LifecycleUnreachableError)return;throw i}}))}_changeRenderUnit(n,r){if(this._currentRenderId===n)return!1;const i=this._renderManagerService.getRenderById(n);if(!i||!i.unitId||h.isInternalEditorID(i.unitId))return!1;const l=this._currentRenderId?this._renderManagerService.getRenderById(this._currentRenderId):null;return l==null||l.deactivate(),l==null||l.engine.unmount(),i.engine.mount(r),i.activate(),this._currentRenderId=n,!0}}var b0=Object.getOwnPropertyDescriptor,L0=(e,t,n,r)=>{for(var i=r>1?void 0:r?b0(t,n):t,l=e.length-1,o;l>=0;l--)(o=e[l])&&(i=o(i)||i);return i},V1=(e,t)=>(n,r)=>t(n,r,e);f.DesktopUIController=class extends Qe{constructor(t,n,r,i,l,o,c,v,m){super(n,o,l,r,i),this._config=t,this._componentManager=m,c.mergeMenu(n6),this._initBuiltinComponents(v),this._registerComponents(),this._bootstrapWorkbench()}_registerComponents(){[[O9,D9],[N9,V9],[P9,k9],[U9,A9],[$9,Z9],[x9,Z.ColorPicker]].forEach(([t,n])=>{this.disposeWithMe(this._componentManager.register(t,n))})}bootstrap(t){return w0(this._injector,this._config,t)}_initBuiltinComponents(t){this.disposeWithMe(t.registerComponent(o1.FLOATING,()=>R.connectInjector(Ge,this._injector))),this.disposeWithMe(t.registerComponent(o1.CONTENT,()=>R.connectInjector(je,this._injector))),this.disposeWithMe(t.registerComponent(o1.TOOLBAR,()=>R.connectInjector(b6,this._injector)))}},f.DesktopUIController=L0([V1(1,h.Inject(h.Injector)),V1(2,h.Inject(h.LifecycleService)),V1(3,z1.IRenderManagerService),V1(4,H1),V1(5,h.IUniverInstanceService),V1(6,S1),V1(7,_1),V1(8,h.Inject(v1))],f.DesktopUIController);function w0(e,t,n){let r;const i=t.container;if(typeof i=="string"){const v=document.getElementById(i);v?r=v:r=w6(i)}else i instanceof HTMLElement?r=i:r=w6("univer");const l=R.connectInjector(v0,e),o=v=>n(v,r);function c(){Z.render(C.jsx(l,{...t,mountContainer:r,onRendered:o}),r)}return c(),h.toDisposable(()=>{Z.render(C.jsx("div",{}),r),setTimeout(()=>Z.render(C.jsx("div",{}),r),200),setTimeout(()=>Z.unmount(r),500)})}function w6(e){const t=document.createElement("div");return t.id=e,t}function _0(e){const{menuType:t,onOptionSelect:n}=e,r=R.useDependency(S1);if(!t)return null;const i=a.useMemo(()=>{const l=r.getMenuByPositionKey(t);function o(c){return c.reduce((v,m)=>m.children?[...v,...o(m.children)]:[...v,m],[])}return o(l)},[t]);return C.jsx("div",{className:"univer-box-border univer-grid univer-min-w-8 univer-max-w-52 univer-gap-1 univer-rounded univer-bg-gray-900 univer-px-2 univer-py-1",style:{gridTemplateColumns:`repeat(${Math.min(2,i.length)}, 72px)`},children:i.map(l=>l.item&&C.jsx(y0,{menuItem:l.item,onClick:o=>n==null?void 0:n({value:"",label:l.key,...o})},l.key))})}function y0(e){const{menuItem:t,onClick:n}=e,{id:r,type:i,title:l,label:o,icon:c}=t;if(i!==g1.BUTTON)throw new Error(`[MobileMenuItem]: on mobile devices only "BUTTON" type menu items are supported. Please check "${r}".`);const v=R.useObservable(t.disabled$,!1),m=R.useObservable(t.value$);return C.jsx("button",{type:"button",className:Z.clsx("univer-w-18 univer-flex univer-flex-col univer-items-center univer-justify-center univer-border-none univer-bg-transparent univer-text-white [&>span]:univer-mt-0.5 [&>span]:univer-w-full [&>span]:univer-truncate [&>span]:univer-text-sm [&>svg]:univer-size-[18px] [&>svg]:univer-text-lg"),disabled:v,onClick:()=>n({id:r}),children:C.jsx(d1,{value:m,title:l,label:o,icon:c})},r)}function _6(){const[e,t]=a.useState(!1),[n,r]=a.useState(""),[i,l]=a.useState([0,0]),o=a.useRef(e),c=R.useDependency(ie),v=R.useDependency(h.ICommandService);o.current=e,a.useEffect(()=>{const d=c.registerContextMenuHandler({handleContextMenu:m,hideContextMenu(){t(!1)},get visible(){return o.current}});return document.addEventListener("pointerdown",b),document.addEventListener("wheel",b),()=>{document.removeEventListener("pointerdown",b),document.removeEventListener("wheel",b),d.dispose()}},[c]);function m(d,w){r(w),l([d.clientX,d.clientY]),t(!0)}function b(){t(!1)}return C.jsx(Z.Popup,{visible:e,offset:i,children:C.jsx("section",{onPointerDown:d=>d.stopPropagation(),children:n&&C.jsx(_0,{menuType:n,onOptionSelect:d=>{const{label:w,value:y,commandId:S}=d;v&&v.executeCommand(S!=null?S:w,{value:y}),t(!1)}})})})}function M0(e){const{header:t=!0,footer:n=!0,contextMenu:r=!0,mountContainer:i,onRendered:l}=e,o=R.useDependency(h.LocaleService),c=R.useDependency(h.ThemeService),v=R.useDependency(re),m=a.useRef(null),b=p1(o1.FOOTER),d=p1(o1.HEADER),w=p1(o1.CONTENT),y=p1(o1.LEFT_SIDEBAR),S=p1(o1.GLOBAL),[T,D]=a.useState(!1);a.useEffect(()=>{const U=c.darkMode$.subscribe(M=>{D(M)});return()=>{U.unsubscribe()}},[]),a.useEffect(()=>{m.current&&(l==null||l(m.current))},[l]);const[I,V]=a.useState(o.getLocales()),O=a.useMemo(()=>document.createElement("div"),[]);return a.useLayoutEffect(()=>{const U=c.currentTheme$.subscribe(M=>{v.injectThemeToHead(M)});return()=>{U.unsubscribe()}},[]),a.useEffect(()=>{document.body.appendChild(O);const U=[o.localeChanged$.subscribe(()=>{V(o.getLocales())})];return()=>{U.forEach(M=>M.unsubscribe()),document.body.removeChild(O)}},[o,i,O]),C.jsxs(Z.ConfigProvider,{locale:I==null?void 0:I.design,mountContainer:O,children:[C.jsxs("div",{"data-u-comp":"app-layout",className:Z.clsx("univer-relative univer-flex univer-h-full univer-min-h-0 univer-flex-col univer-bg-white dark:!univer-bg-gray-800",{"univer-dark":T}),tabIndex:-1,onBlur:U=>U.stopPropagation(),children:[t&&C.jsx("header",{className:"univer-relative univer-z-10 univer-w-full"}),C.jsxs("section",{className:"univer-relative univer-flex univer-min-h-0 univer-flex-1 univer-flex-col",children:[C.jsxs("div",{className:"univer-grid univer-h-full univer-grid-cols-[auto_1fr_auto] univer-grid-rows-[100%] univer-overflow-hidden",children:[C.jsx("aside",{className:"univer-h-full",children:C.jsx(m1,{components:y},"left-sidebar")}),C.jsxs("section",{className:Z.clsx("univer-relative univer-grid univer-flex-1 univer-grid-rows-[auto_1fr] univer-overflow-hidden univer-bg-white",Z.borderBottomClassName),children:[C.jsx("header",{className:"univer-w-screen",children:t&&C.jsx(m1,{components:d},"header")}),C.jsx("section",{ref:m,className:"univer-relative univer-overflow-hidden","data-range-selector":!0,onContextMenu:U=>U.preventDefault(),children:C.jsx(m1,{components:w},"content")})]}),C.jsx("aside",{className:"univer-h-full",children:C.jsx(qe,{})})]}),n&&C.jsx("footer",{children:C.jsx(m1,{components:b},"footer")}),C.jsx(Xe,{}),C.jsx(Je,{})]})]}),C.jsx(m1,{components:S},"global"),r&&C.jsx(_6,{})]})}var S0=Object.getOwnPropertyDescriptor,I0=(e,t,n,r)=>{for(var i=r>1?void 0:r?S0(t,n):t,l=e.length-1,o;l>=0;l--)(o=e[l])&&(i=o(i)||i);return i},U1=(e,t)=>(n,r)=>t(n,r,e);let Ke=class extends Qe{constructor(e,t,n,r,i,l,o){super(t,l,i,n,r),this._config=e,this._initBuiltinComponents(o),this._bootstrapWorkbench()}bootstrap(e){return H0(this._injector,this._config,e)}_initBuiltinComponents(e){this.disposeWithMe(e.registerComponent(o1.CONTENT,()=>R.connectInjector(Ge,this._injector))),this.disposeWithMe(e.registerComponent(o1.CONTENT,()=>R.connectInjector(je,this._injector)))}};Ke=I0([U1(1,h.Inject(h.Injector)),U1(2,h.Inject(h.LifecycleService)),U1(3,z1.IRenderManagerService),U1(4,H1),U1(5,h.IUniverInstanceService),U1(6,_1)],Ke);function H0(e,t,n){let r;const i=t.container;if(typeof i=="string"){const v=document.getElementById(i);v?r=v:r=y6(i)}else i instanceof HTMLElement?r=i:r=y6("univer");const l=R.connectInjector(M0,e),o=v=>n(v,r);function c(){Z.render(C.jsx(l,{...t,mountContainer:r,onRendered:o}),r)}return c(),h.toDisposable(()=>{Z.unmount(r)})}function y6(e){const t=document.createElement("div");return t.id=e,t}const oe=h.createIdentifier("ui.notification.service");var E0=Object.getOwnPropertyDescriptor,D0=(e,t,n,r)=>{for(var i=r>1?void 0:r?E0(t,n):t,l=e.length-1,o;l>=0;l--)(o=e[l])&&(i=o(i)||i);return i},O0=(e,t)=>(n,r)=>t(n,r,e);const e3=h.createIdentifier("univer.ui.before-close-service");f.DesktopBeforeCloseService=class{constructor(t){j(this,"_beforeUnloadCallbacks",[]);j(this,"_onCloseCallbacks",[]);this._notificationService=t,this._init()}registerBeforeClose(t){return this._beforeUnloadCallbacks.push(t),{dispose:()=>{this._beforeUnloadCallbacks=this._beforeUnloadCallbacks.filter(n=>n!==t)}}}registerOnClose(t){return this._onCloseCallbacks.push(t),{dispose:()=>{this._onCloseCallbacks=this._onCloseCallbacks.filter(n=>n!==t)}}}_init(){window.addEventListener("beforeunload",t=>{let n=t;const r=this._beforeUnloadCallbacks.map(i=>i()).filter(i=>!!i).join(`
|
|
12
|
+
}`,document.head.appendChild(o)}dispose(){super.dispose()}}const ie=h.createIdentifier("ui.contextmenu.service");class Ye extends h.Disposable{constructor(){super(...arguments);j(this,"_currentHandler",null);j(this,"disabled",!1)}get visible(){var n,r;return(r=(n=this._currentHandler)==null?void 0:n.visible)!=null?r:!1}disable(){this.disabled=!0}enable(){this.disabled=!1}triggerContextMenu(n,r){var i;n.stopPropagation(),!this.disabled&&((i=this._currentHandler)==null||i.handleContextMenu(n,r))}hideContextMenu(){var n;(n=this._currentHandler)==null||n.hideContextMenu()}registerContextMenuHandler(n){if(this._currentHandler)throw new Error("There is already a context menu handler!");return this._currentHandler=n,h.toDisposable(()=>this._currentHandler=null)}}function L6(){const e=a.useRef(null),[t,n]=a.useState(!1),[r,i]=a.useState(""),[l,o]=a.useState([0,0]),c=a.useRef(t),v=R.useDependency(ie),m=R.useDependency(h.ICommandService),b=R.useInjector();c.current=t,a.useEffect(()=>{const y=v.registerContextMenuHandler({handleContextMenu:d,hideContextMenu(){n(!1)},get visible(){return c.current}});function S(T){e.current&&!e.current.contains(T.target)&&w()}return document.addEventListener("pointerdown",S),document.addEventListener("wheel",w),()=>{document.removeEventListener("pointerdown",S),document.removeEventListener("wheel",w),y.dispose()}},[v]);function d(y,S){n(!1),requestAnimationFrame(()=>{i(S),o([y.clientX,y.clientY]),n(!0)})}function w(){n(!1)}return C.jsx(Z.Popup,{visible:t,offset:l,children:C.jsx("section",{ref:e,children:r&&C.jsx(Ae,{menuType:r,onOptionSelect:y=>{const{label:S,commandId:T,value:D}=y;m&&m.executeCommand(T!=null?T:S,{value:D}),b.get(H1).focus(),n(!1)}})})})}const be=h.createIdentifier("univer.global-zone-service");function Xe(){const e=R.useDependency(be),[t,n]=a.useState(!1),r=R.useObservable(e.componentKey$,e.componentKey),i=R.useDependency(v1),l=a.useMemo(()=>{const o=i.get(r!=null?r:"");if(o)return o},[r,i]);return a.useEffect(()=>{const o=e.visible$.subscribe(c=>{n(c)});return()=>{o.unsubscribe()}},[e.visible$]),t?C.jsx("section",{className:Z.clsx("univer-absolute univer-bg-gray-100",{"univer-hidden":!t,"univer-inset-0 univer-z-[100] univer-block univer-size-full":t}),children:l&&C.jsx(l,{})}):null}function qe(){const e=R.useDependency($1),t=R.useObservable(e.sidebarOptions$),n=a.useRef(null),r=a.useMemo(()=>{if(!t)return null;const o={...t};for(const c of["children","header","footer"]){const v=c;if(t[v]){const{key:m,...b}=t[v];b&&(o[v]=C.jsx(d1,{...b},m))}}return o},[t]);a.useEffect(()=>(n.current&&e.setContainer(n.current),()=>{e.setContainer(void 0)}),[e]),a.useEffect(()=>{const o=v=>{e.scrollEvent$.next(v)},c=n.current;return c&&c.addEventListener("scroll",o),()=>{c==null||c.removeEventListener("scroll",o)}},[e]);const i=a.useMemo(()=>r!=null&&r.visible?typeof r.width=="number"?`${r.width}px`:r.width:0,[r]);function l(){var c;const o={...t,visible:!1};e.options.visible=!1,e.sidebarOptions$.next(o),(c=o==null?void 0:o.onClose)==null||c.call(o)}return C.jsx("section",{"data-u-comp":"sidebar",className:Z.clsx("univer-relative univer-h-full univer-bg-white univer-text-gray-900 dark:!univer-bg-gray-900 dark:!univer-text-white",{"univer-w-96 univer-translate-x-0":r==null?void 0:r.visible,"univer-w-0 univer-translate-x-full":!(r!=null&&r.visible)}),style:{width:i},children:C.jsxs("section",{ref:n,className:Z.clsx("univer-box-border univer-grid univer-h-0 univer-min-h-full univer-grid-rows-[auto_1fr_auto] univer-overflow-y-auto",Z.borderLeftBottomClassName,Z.scrollbarClassName),children:[C.jsxs("header",{className:"univer-sticky univer-top-0 univer-z-10 univer-box-border univer-flex univer-items-center univer-justify-between univer-bg-white univer-p-4 univer-pb-2 univer-text-base univer-font-medium univer-text-gray-800 dark:!univer-bg-gray-900 dark:!univer-text-white",children:[r==null?void 0:r.header,C.jsx("a",{className:"univer-cursor-pointer univer-text-gray-500 dark:!univer-text-gray-300",onClick:l,children:C.jsx(Ne,{})})]}),C.jsx("section",{className:"univer-box-border univer-px-4",style:r==null?void 0:r.bodyStyle,children:r==null?void 0:r.children}),(r==null?void 0:r.footer)&&C.jsx("footer",{className:"univer-sticky univer-bottom-0 univer-box-border univer-bg-white univer-p-4 dark:!univer-bg-gray-900",children:r.footer})]})})}const Le=h.createIdentifier("univer.zen-zone-service");function Je(){const e=R.useDependency(Le),[t,n]=a.useState(!1),[r,i]=a.useState(),l=R.useObservable(e.temporaryHidden$),o=R.useDependency(v1);a.useEffect(()=>{const v=[e.visible$.subscribe(m=>{n(m)}),e.componentKey$.subscribe(m=>{i(m)})];return()=>{v.forEach(m=>{m.unsubscribe()})}},[]);const c=a.useMemo(()=>{const v=o.get(r!=null?r:"");if(v)return v},[r]);return C.jsx("section",{className:Z.clsx("univer-absolute univer-z-[-1] univer-flex",{"univer-animate-in univer-fade-in univer-inset-0 univer-z-[100] univer-bg-gray-100":t,"univer-hidden":l}),children:C.jsx("div",{className:"univer-relative univer-flex-1",children:c&&C.jsx(c,{})})})}function v0(e){const t=T9(Y1);return C.jsx(g0,{...e,...t})}function g0(e){var K;const{header:t=!0,toolbar:n=!0,footer:r=!0,headerMenu:i=!0,contextMenu:l=!0,ribbonType:o="default",mountContainer:c,onRendered:v}=e,m=R.useDependency(h.LocaleService),b=R.useDependency(h.ThemeService),d=R.useDependency(re),w=a.useRef(null),S=R.useDependency(h.IConfigService).getConfig(Y1),T=p1(o1.CUSTOM_HEADER),D=p1(o1.FOOTER),I=p1(o1.HEADER),V=p1(o1.HEADER_MENU),O=p1(o1.CONTENT),U=p1(o1.LEFT_SIDEBAR),M=p1(o1.GLOBAL),x=p1(o1.TOOLBAR),$=(K=S==null?void 0:S.popupRootId)!=null?K:"univer-popup-portal";a.useLayoutEffect(()=>{const W=b.currentTheme$.subscribe(Y=>{d.injectThemeToHead(Y)});return()=>{W.unsubscribe()}},[]);const[X,B]=a.useState(!1);a.useLayoutEffect(()=>{const W=b.darkMode$.subscribe(Y=>{B(Y),Y?document.documentElement.classList.add("univer-dark"):document.documentElement.classList.remove("univer-dark")});return()=>{W.unsubscribe()}},[]),a.useEffect(()=>{w.current&&(v==null||v(w.current))},[v]);const[G,q]=a.useState(m.getLocales()),J=a.useMemo(()=>document.createElement("div"),[]);return a.useEffect(()=>{document.body.appendChild(J);const W=[m.localeChanged$.subscribe(()=>{q(m.getLocales())})];return()=>{W.forEach(Y=>Y.unsubscribe()),document.body.removeChild(J)}},[m,c,J]),C.jsxs(Z.ConfigProvider,{locale:G==null?void 0:G.design,mountContainer:J,children:[C.jsxs("div",{"data-u-comp":"workbench-layout",className:Z.clsx("univer-flex univer-h-full univer-min-h-0 univer-flex-col univer-bg-white dark:!univer-bg-gray-800",{"univer-dark":X}),tabIndex:-1,onBlur:W=>W.stopPropagation(),onContextMenu:W=>W.preventDefault(),children:[C.jsx("div",{className:"univer-relative univer-flex univer-min-h-0 univer-flex-col univer-bg-white",children:C.jsx(m1,{components:T},"custom-header")}),t&&n&&C.jsx("header",{"data-u-comp":"headerbar",className:"univer-relative univer-z-10 univer-w-full univer-overflow-hidden",children:C.jsx(m1,{components:x,sharedProps:{ribbonType:o,headerMenuComponents:V,headerMenu:i}},"toolbar")}),C.jsxs("section",{className:"univer-relative univer-flex univer-min-h-0 univer-flex-1 univer-flex-col",children:[C.jsxs("div",{className:"univer-grid univer-h-full univer-grid-cols-[auto_1fr_auto] univer-grid-rows-[100%] univer-overflow-hidden",children:[C.jsx("aside",{"data-u-comp":"left-sidebar",className:"univer-h-full",children:C.jsx(m1,{components:U},"left-sidebar")}),C.jsxs("section",{className:Z.clsx("univer-relative univer-grid univer-flex-1 univer-grid-rows-[auto_1fr] univer-overflow-hidden univer-bg-white",Z.borderBottomClassName),children:[C.jsx("header",{children:t&&C.jsx(m1,{components:I},"header")}),C.jsx("section",{className:"univer-relative univer-overflow-hidden dark:!univer-bg-gray-900",ref:w,"data-range-selector":!0,onContextMenu:W=>W.preventDefault(),children:C.jsx(m1,{components:O},"content")})]}),C.jsx("aside",{"data-u-comp":"right-sidebar",className:"univer-h-full",children:C.jsx(qe,{})})]}),r&&C.jsx("footer",{children:C.jsx(m1,{components:D,sharedProps:{contextMenu:l}},"footer")}),C.jsx(Je,{})]})]}),C.jsx(m1,{components:M},"global"),C.jsx(Xe,{}),l&&C.jsx(L6,{}),C.jsx(m0,{}),C.jsx("div",{id:$})]})}function m0(){const{mountContainer:e}=a.useContext(Z.ConfigContext),t=p1(o1.FLOATING);return _3.createPortal(C.jsx(m1,{components:t},"floating"),e)}const p0=3e3;class Qe extends h.Disposable{constructor(n,r,i,l,o){super();j(this,"_steadyTimeout");j(this,"_renderTimeout");j(this,"_currentRenderId",null);this._injector=n,this._instanceService=r,this._layoutService=i,this._lifecycleService=l,this._renderManagerService=o}dispose(){super.dispose(),clearTimeout(this._steadyTimeout),clearTimeout(this._renderTimeout)}_bootstrapWorkbench(){this.disposeWithMe(this.bootstrap(async(n,r)=>{this._layoutService&&(this.disposeWithMe(this._layoutService.registerRootContainerElement(r)),this.disposeWithMe(this._layoutService.registerContentElement(n)));try{await this._lifecycleService.onStage(h.LifecycleStages.Ready),this._renderTimeout=window.setTimeout(()=>{const i=this._renderManagerService.getRenderAll();for(const[l]of i)if(this._changeRenderUnit(l,n))break;this.disposeWithMe(this._instanceService.focused$.subscribe(l=>{l&&this._changeRenderUnit(l,n)})),this.disposeWithMe(this._renderManagerService.created$.subscribe(l=>{var o;l.unitId===((o=this._instanceService.getFocusedUnit())==null?void 0:o.getUnitId())&&this._changeRenderUnit(l.unitId,n)})),this.disposeWithMe(this._renderManagerService.disposed$.subscribe(l=>{this._currentRenderId===l&&(this._currentRenderId=null)})),this._lifecycleService.stage=h.LifecycleStages.Rendered,this._steadyTimeout=window.setTimeout(()=>{this._lifecycleService.stage=h.LifecycleStages.Steady},p0)},300)}catch(i){if(i instanceof h.LifecycleUnreachableError)return;throw i}}))}_changeRenderUnit(n,r){if(this._currentRenderId===n)return!1;const i=this._renderManagerService.getRenderById(n);if(!i||!i.unitId||h.isInternalEditorID(i.unitId))return!1;const l=this._currentRenderId?this._renderManagerService.getRenderById(this._currentRenderId):null;return l==null||l.deactivate(),l==null||l.engine.unmount(),i.engine.mount(r),i.activate(),this._currentRenderId=n,!0}}var b0=Object.getOwnPropertyDescriptor,L0=(e,t,n,r)=>{for(var i=r>1?void 0:r?b0(t,n):t,l=e.length-1,o;l>=0;l--)(o=e[l])&&(i=o(i)||i);return i},V1=(e,t)=>(n,r)=>t(n,r,e);f.DesktopUIController=class extends Qe{constructor(t,n,r,i,l,o,c,v,m){super(n,o,l,r,i),this._config=t,this._componentManager=m,c.mergeMenu(n6),this._initBuiltinComponents(v),this._registerComponents(),this._bootstrapWorkbench()}_registerComponents(){[[O9,D9],[N9,V9],[P9,k9],[U9,A9],[$9,Z9],[x9,Z.ColorPicker]].forEach(([t,n])=>{this.disposeWithMe(this._componentManager.register(t,n))})}bootstrap(t){return w0(this._injector,this._config,t)}_initBuiltinComponents(t){this.disposeWithMe(t.registerComponent(o1.FLOATING,()=>R.connectInjector(Ge,this._injector))),this.disposeWithMe(t.registerComponent(o1.CONTENT,()=>R.connectInjector(je,this._injector))),this.disposeWithMe(t.registerComponent(o1.TOOLBAR,()=>R.connectInjector(b6,this._injector)))}},f.DesktopUIController=L0([V1(1,h.Inject(h.Injector)),V1(2,h.Inject(h.LifecycleService)),V1(3,z1.IRenderManagerService),V1(4,H1),V1(5,h.IUniverInstanceService),V1(6,S1),V1(7,_1),V1(8,h.Inject(v1))],f.DesktopUIController);function w0(e,t,n){let r;const i=t.container;if(typeof i=="string"){const v=document.getElementById(i);v?r=v:r=w6(i)}else i instanceof HTMLElement?r=i:r=w6("univer");const l=R.connectInjector(v0,e),o=v=>n(v,r);function c(){Z.render(C.jsx(l,{...t,mountContainer:r,onRendered:o}),r)}return c(),h.toDisposable(()=>{Z.render(C.jsx("div",{}),r),setTimeout(()=>Z.render(C.jsx("div",{}),r),200),setTimeout(()=>Z.unmount(r),500)})}function w6(e){const t=document.createElement("div");return t.id=e,t}function _0(e){const{menuType:t,onOptionSelect:n}=e,r=R.useDependency(S1);if(!t)return null;const i=a.useMemo(()=>{const l=r.getMenuByPositionKey(t);function o(c){return c.reduce((v,m)=>m.children?[...v,...o(m.children)]:[...v,m],[])}return o(l)},[t]);return C.jsx("div",{className:"univer-box-border univer-grid univer-min-w-8 univer-max-w-52 univer-gap-1 univer-rounded univer-bg-gray-900 univer-px-2 univer-py-1",style:{gridTemplateColumns:`repeat(${Math.min(2,i.length)}, 72px)`},children:i.map(l=>l.item&&C.jsx(y0,{menuItem:l.item,onClick:o=>n==null?void 0:n({value:"",label:l.key,...o})},l.key))})}function y0(e){const{menuItem:t,onClick:n}=e,{id:r,type:i,title:l,label:o,icon:c}=t;if(i!==g1.BUTTON)throw new Error(`[MobileMenuItem]: on mobile devices only "BUTTON" type menu items are supported. Please check "${r}".`);const v=R.useObservable(t.disabled$,!1),m=R.useObservable(t.value$);return C.jsx("button",{type:"button",className:Z.clsx("univer-w-18 univer-flex univer-flex-col univer-items-center univer-justify-center univer-border-none univer-bg-transparent univer-text-white [&>span]:univer-mt-0.5 [&>span]:univer-w-full [&>span]:univer-truncate [&>span]:univer-text-sm [&>svg]:univer-size-[18px] [&>svg]:univer-text-lg"),disabled:v,onClick:()=>n({id:r}),children:C.jsx(d1,{value:m,title:l,label:o,icon:c})},r)}function _6(){const[e,t]=a.useState(!1),[n,r]=a.useState(""),[i,l]=a.useState([0,0]),o=a.useRef(e),c=R.useDependency(ie),v=R.useDependency(h.ICommandService);o.current=e,a.useEffect(()=>{const d=c.registerContextMenuHandler({handleContextMenu:m,hideContextMenu(){t(!1)},get visible(){return o.current}});return document.addEventListener("pointerdown",b),document.addEventListener("wheel",b),()=>{document.removeEventListener("pointerdown",b),document.removeEventListener("wheel",b),d.dispose()}},[c]);function m(d,w){r(w),l([d.clientX,d.clientY]),t(!0)}function b(){t(!1)}return C.jsx(Z.Popup,{visible:e,offset:i,children:C.jsx("section",{onPointerDown:d=>d.stopPropagation(),children:n&&C.jsx(_0,{menuType:n,onOptionSelect:d=>{const{label:w,value:y,commandId:S}=d;v&&v.executeCommand(S!=null?S:w,{value:y}),t(!1)}})})})}function M0(e){const{header:t=!0,footer:n=!0,contextMenu:r=!0,mountContainer:i,onRendered:l}=e,o=R.useDependency(h.LocaleService),c=R.useDependency(h.ThemeService),v=R.useDependency(re),m=a.useRef(null),b=p1(o1.FOOTER),d=p1(o1.HEADER),w=p1(o1.CONTENT),y=p1(o1.LEFT_SIDEBAR),S=p1(o1.GLOBAL),[T,D]=a.useState(!1);a.useEffect(()=>{const U=c.darkMode$.subscribe(M=>{D(M)});return()=>{U.unsubscribe()}},[]),a.useEffect(()=>{m.current&&(l==null||l(m.current))},[l]);const[I,V]=a.useState(o.getLocales()),O=a.useMemo(()=>document.createElement("div"),[]);return a.useLayoutEffect(()=>{const U=c.currentTheme$.subscribe(M=>{v.injectThemeToHead(M)});return()=>{U.unsubscribe()}},[]),a.useEffect(()=>{document.body.appendChild(O);const U=[o.localeChanged$.subscribe(()=>{V(o.getLocales())})];return()=>{U.forEach(M=>M.unsubscribe()),document.body.removeChild(O)}},[o,i,O]),C.jsxs(Z.ConfigProvider,{locale:I==null?void 0:I.design,mountContainer:O,children:[C.jsxs("div",{"data-u-comp":"app-layout",className:Z.clsx("univer-relative univer-flex univer-h-full univer-min-h-0 univer-flex-col univer-bg-white dark:!univer-bg-gray-800",{"univer-dark":T}),tabIndex:-1,onBlur:U=>U.stopPropagation(),children:[t&&C.jsx("header",{className:"univer-relative univer-z-10 univer-w-full"}),C.jsxs("section",{className:"univer-relative univer-flex univer-min-h-0 univer-flex-1 univer-flex-col",children:[C.jsxs("div",{className:"univer-grid univer-h-full univer-grid-cols-[auto_1fr_auto] univer-grid-rows-[100%] univer-overflow-hidden",children:[C.jsx("aside",{className:"univer-h-full",children:C.jsx(m1,{components:y},"left-sidebar")}),C.jsxs("section",{className:Z.clsx("univer-relative univer-grid univer-flex-1 univer-grid-rows-[auto_1fr] univer-overflow-hidden univer-bg-white",Z.borderBottomClassName),children:[C.jsx("header",{className:"univer-w-screen",children:t&&C.jsx(m1,{components:d},"header")}),C.jsx("section",{ref:m,className:"univer-relative univer-overflow-hidden","data-range-selector":!0,onContextMenu:U=>U.preventDefault(),children:C.jsx(m1,{components:w},"content")})]}),C.jsx("aside",{className:"univer-h-full",children:C.jsx(qe,{})})]}),n&&C.jsx("footer",{children:C.jsx(m1,{components:b},"footer")}),C.jsx(Xe,{}),C.jsx(Je,{})]})]}),C.jsx(m1,{components:S},"global"),r&&C.jsx(_6,{})]})}var S0=Object.getOwnPropertyDescriptor,I0=(e,t,n,r)=>{for(var i=r>1?void 0:r?S0(t,n):t,l=e.length-1,o;l>=0;l--)(o=e[l])&&(i=o(i)||i);return i},U1=(e,t)=>(n,r)=>t(n,r,e);let Ke=class extends Qe{constructor(e,t,n,r,i,l,o){super(t,l,i,n,r),this._config=e,this._initBuiltinComponents(o),this._bootstrapWorkbench()}bootstrap(e){return H0(this._injector,this._config,e)}_initBuiltinComponents(e){this.disposeWithMe(e.registerComponent(o1.CONTENT,()=>R.connectInjector(Ge,this._injector))),this.disposeWithMe(e.registerComponent(o1.CONTENT,()=>R.connectInjector(je,this._injector)))}};Ke=I0([U1(1,h.Inject(h.Injector)),U1(2,h.Inject(h.LifecycleService)),U1(3,z1.IRenderManagerService),U1(4,H1),U1(5,h.IUniverInstanceService),U1(6,_1)],Ke);function H0(e,t,n){let r;const i=t.container;if(typeof i=="string"){const v=document.getElementById(i);v?r=v:r=y6(i)}else i instanceof HTMLElement?r=i:r=y6("univer");const l=R.connectInjector(M0,e),o=v=>n(v,r);function c(){Z.render(C.jsx(l,{...t,mountContainer:r,onRendered:o}),r)}return c(),h.toDisposable(()=>{Z.unmount(r)})}function y6(e){const t=document.createElement("div");return t.id=e,t}const oe=h.createIdentifier("ui.notification.service");var E0=Object.getOwnPropertyDescriptor,D0=(e,t,n,r)=>{for(var i=r>1?void 0:r?E0(t,n):t,l=e.length-1,o;l>=0;l--)(o=e[l])&&(i=o(i)||i);return i},O0=(e,t)=>(n,r)=>t(n,r,e);const e3=h.createIdentifier("univer.ui.before-close-service");f.DesktopBeforeCloseService=class{constructor(t){j(this,"_beforeUnloadCallbacks",[]);j(this,"_onCloseCallbacks",[]);this._notificationService=t,this._init()}registerBeforeClose(t){return this._beforeUnloadCallbacks.push(t),{dispose:()=>{this._beforeUnloadCallbacks=this._beforeUnloadCallbacks.filter(n=>n!==t)}}}registerOnClose(t){return this._onCloseCallbacks.push(t),{dispose:()=>{this._onCloseCallbacks=this._onCloseCallbacks.filter(n=>n!==t)}}}_init(){window.addEventListener("beforeunload",t=>{let n=t;const r=this._beforeUnloadCallbacks.map(i=>i()).filter(i=>!!i).join(`
|
|
13
13
|
`);if(r)return this._notificationService.show({type:"error",title:"Some changes are not saved",content:r}),typeof n>"u"&&(n=window.event),n.returnValue=r,r}),window.addEventListener("unload",()=>{this._onCloseCallbacks.forEach(t=>t())})}},f.DesktopBeforeCloseService=D0([O0(0,oe)],f.DesktopBeforeCloseService);function M6(){return typeof navigator.clipboard<"u"&&typeof navigator.clipboard.readText<"u"}var V0=Object.getOwnPropertyDescriptor,N0=(e,t,n,r)=>{for(var i=r>1?void 0:r?V0(t,n):t,l=e.length-1,o;l>=0;l--)(o=e[l])&&(i=o(i)||i);return i},t3=(e,t)=>(n,r)=>t(n,r,e);const n3="text/plain",r3="text/html",S6="image/png",I6="image/jpeg",H6="image/bmp",E6="image/webp",R0="image/svg+xml",T0=new Set([H6,I6,E6,S6]),i3=h.createIdentifier("univer.clipboard-interface-service");f.BrowserClipboardService=class extends h.Disposable{constructor(t,n,r){super(),this._localeService=t,this._logService=n,this._notificationService=r}get supportClipboard(){return M6()}async write(t,n){if(!this.supportClipboard)return this._legacyCopyHtml(n);try{return await navigator.clipboard.write([new ClipboardItem({[n3]:new Blob([t],{type:n3}),[r3]:new Blob([n],{type:r3})})])}catch(r){this._logService.error("[BrowserClipboardService]",r),this._showClipboardAuthenticationNotification()}}async writeText(t){if(!this.supportClipboard)return this._legacyCopyText(t);try{return await navigator.clipboard.writeText(t)}catch(n){this._logService.error("[BrowserClipboardService]",n),this._showClipboardAuthenticationNotification()}}async read(){if(!this.supportClipboard)throw new Error("[BrowserClipboardService] read() is not supported on this platform.");try{return navigator.clipboard.read()}catch(t){return this._logService.error("[BrowserClipboardService]",t),this._showClipboardAuthenticationNotification(),[]}}async readText(){if(!this.supportClipboard)throw new Error("[BrowserClipboardService] read() is not supported on this platform.");try{return await navigator.clipboard.readText()}catch(t){return this._logService.error("[BrowserClipboardService]",t),this._showClipboardAuthenticationNotification(),""}}_legacyCopyHtml(t){const n=document.activeElement,r=Z0();document.body.appendChild(r),r.innerHTML=t;try{D6(r),document.execCommand("copy")}finally{n instanceof HTMLElement&&n.focus(),document.body.removeChild(r)}}_legacyCopyText(t){const n=document.activeElement,r=x0();document.body.appendChild(r),r.value=t;try{D6(r),document.execCommand("copy")}finally{n instanceof HTMLElement&&n.focus(),document.body.removeChild(r)}}_showClipboardAuthenticationNotification(){var t;(t=this._notificationService)==null||t.show({type:"warning",title:this._localeService.t("clipboard.authentication.title"),content:this._localeService.t("clipboard.authentication.content")})}},f.BrowserClipboardService=N0([t3(0,h.Inject(h.LocaleService)),t3(1,h.ILogService),t3(2,h.Optional(oe))],f.BrowserClipboardService);function x0(){const e=document.createElement("textarea");return e.style.position="absolute",e.style.height="1px",e.style.width="1px",e.style.opacity="0",e.readOnly=!0,e}function Z0(){const e=document.createElement("div");return e.contentEditable="true",e.style.position="absolute",e.style.opacity="0",e.style.height="1px",e.style.width="1px",e}function D6(e){if(e instanceof HTMLTextAreaElement){const r=e.hasAttribute("readonly");return r||e.setAttribute("readonly",""),e.select(),e.setSelectionRange(0,e.value.length),r||e.removeAttribute("readonly"),e.value}e.hasAttribute("contenteditable")&&e.focus();const t=document.createRange();t.selectNodeContents(e);const n=window.getSelection();if(!n)throw new Error;return n.removeAllRanges(),n.addRange(t),n.toString()}const we=h.createIdentifier("univer.confirm-service");class k0{constructor(){j(this,"confirmOptions$",new z.Subject)}dispose(){this.confirmOptions$.complete()}open(t){throw new Error("This is not implemented in the test service!")}confirm(t){return Promise.resolve(!0)}close(t){throw new Error("This is not implemented in the test service!")}}const A0=e=>{const{children:t,onClose:n,onConfirm:r}=e,[i]=a.useState({}),l=t?a.cloneElement(t,{hooks:i}):null;return C.jsx(Z.Confirm,{...e,children:l,onClose:()=>{const o=i.beforeClose;if(o){const c=o();if(c.cancel)return;n==null||n(c);return}n==null||n()},onConfirm:()=>{const o=i.beforeConfirm;if(o){const c=o();if(c.cancel)return;r==null||r(c);return}r==null||r()}})};function $0(){const e=R.useDependency(we),[t,n]=a.useState([]);a.useEffect(()=>{const i=e.confirmOptions$.subscribe(l=>{n(l)});return()=>{i.unsubscribe()}},[]);const r=t.map(i=>{const{children:l,title:o,...c}=i,v=c;for(const m of["children","title"]){const b=m,d=i[b];d&&(v[b]=C.jsx(d1,{...d}))}return v});return r==null?void 0:r.map((i,l)=>C.jsx(A0,{...i,children:i.children},l))}var P0=Object.getOwnPropertyDescriptor,U0=(e,t,n,r)=>{for(var i=r>1?void 0:r?P0(t,n):t,l=e.length-1,o;l>=0;l--)(o=e[l])&&(i=o(i)||i);return i},O6=(e,t)=>(n,r)=>t(n,r,e);f.DesktopConfirmService=class extends h.Disposable{constructor(n,r){super();j(this,"_confirmOptions",[]);j(this,"confirmOptions$",new z.BehaviorSubject([]));this._injector=n,this._uiPartsService=r,this._initUIPart()}open(n){return this._confirmOptions.find(r=>r.id===n.id)?this._confirmOptions=this._confirmOptions.map(r=>({...r.id===n.id?n:r,visible:r.id===n.id?!0:r.visible})):this._confirmOptions.push({...n,visible:!0}),this.confirmOptions$.next(this._confirmOptions),h.toDisposable(()=>{this._confirmOptions=[],this.confirmOptions$.next([])})}confirm(n){return new Promise(r=>{const i=this.open({...n,onConfirm:()=>{i.dispose(),r(!0)},onClose:()=>{i.dispose(),r(!1)}})})}close(n){this._confirmOptions=this._confirmOptions.map(r=>({...r,visible:r.id===n?!1:r.visible})),this.confirmOptions$.next([...this._confirmOptions])}_initUIPart(){this.disposeWithMe(this._uiPartsService.registerComponent(o1.GLOBAL,()=>R.connectInjector($0,this._injector)))}},f.DesktopConfirmService=U0([O6(0,h.Inject(h.Injector)),O6(1,_1)],f.DesktopConfirmService);const _e=h.createIdentifier("univer.ui.dialog-service");function B0(){const e=R.useDependency(_e),[t,n]=a.useState([]);a.useEffect(()=>{const l=e.getDialogs$().subscribe(o=>{n(o)});return()=>l.unsubscribe()},[]);const r=a.useMemo(()=>t.map(i=>{const{children:l,title:o,footer:c,...v}=i,m=v;for(const b of["children","title","footer"]){const d=b,w=i[d];w&&(m[d]=C.jsx(d1,{...w}))}return m}),[t]);return r==null?void 0:r.map(i=>C.jsx(Z.Dialog,{...i},i.id))}var F0=Object.getOwnPropertyDescriptor,j0=(e,t,n,r)=>{for(var i=r>1?void 0:r?F0(t,n):t,l=e.length-1,o;l>=0;l--)(o=e[l])&&(i=o(i)||i);return i},V6=(e,t)=>(n,r)=>t(n,r,e);f.DesktopDialogService=class extends h.Disposable{constructor(n,r){super();j(this,"_dialogOptions",[]);j(this,"_dialogOptions$",new z.Subject);this._injector=n,this._uiPartsService=r,this._initUIPart()}dispose(){super.dispose(),this._dialogOptions=[],this._dialogOptions$.complete()}open(n){return this._dialogOptions.find(r=>r.id===n.id)?this._dialogOptions=this._dialogOptions.map(r=>({...r.id===n.id?n:r,open:r.id===n.id?!0:r.open})):this._dialogOptions.push({...n,open:!0}),this._dialogOptions$.next(this._dialogOptions),h.toDisposable(()=>{this._dialogOptions=[],this._dialogOptions$.next([])})}close(n){this._dialogOptions=this._dialogOptions.map(r=>({...r,open:r.id===n?!1:r.open})),this._dialogOptions$.next([...this._dialogOptions])}closeAll(n){const r=new Set(n);this._dialogOptions=this._dialogOptions.map(i=>({...i,open:r.has(i.id)?i.open:!1})),this._dialogOptions$.next([...this._dialogOptions])}getDialogs$(){return this._dialogOptions$.asObservable()}_initUIPart(){this.disposeWithMe(this._uiPartsService.registerComponent(o1.GLOBAL,()=>R.connectInjector(B0,this._injector)))}},f.DesktopDialogService=j0([V6(0,h.Inject(h.Injector)),V6(1,_1)],f.DesktopDialogService);const ye=h.createIdentifier("univer.ui.gallery-service");function z0(){const e=R.useDependency(ye),t=R.useObservable(e.gallery$);return t?C.jsx(Z.Gallery,{...t}):null}var G0=Object.getOwnPropertyDescriptor,W0=(e,t,n,r)=>{for(var i=r>1?void 0:r?G0(t,n):t,l=e.length-1,o;l>=0;l--)(o=e[l])&&(i=o(i)||i);return i},N6=(e,t)=>(n,r)=>t(n,r,e);f.DesktopGalleryService=class extends h.Disposable{constructor(n,r){super();j(this,"gallery$",new z.Subject);this._injector=n,this._uiPartsService=r,this._initUIPart()}dispose(){super.dispose()}open(n){return this.gallery$.next({open:!0,...n}),h.toDisposable(()=>{this.gallery$.complete()})}close(){this.gallery$.next({open:!1,images:[]})}_initUIPart(){this.disposeWithMe(this._uiPartsService.registerComponent(o1.GLOBAL,()=>R.connectInjector(z0,this._injector)))}},f.DesktopGalleryService=W0([N6(0,h.Inject(h.Injector)),N6(1,_1)],f.DesktopGalleryService);var Y0=Object.getOwnPropertyDescriptor,X0=(e,t,n,r)=>{for(var i=r>1?void 0:r?Y0(t,n):t,l=e.length-1,o;l>=0;l--)(o=e[l])&&(i=o(i)||i);return i},q0=(e,t)=>(n,r)=>t(n,r,e);f.DesktopGlobalZoneService=class{constructor(t){j(this,"visible$",new z.Subject);j(this,"componentKey$",new z.Subject);j(this,"_componentKey","");this._componentManager=t}get componentKey(){return this._componentKey}set(t,n){return this._componentManager.register(t,n),this.componentKey$.next(t),this._componentKey=t,h.toDisposable(()=>{this._componentManager.delete(t),this.visible$.complete(),this.componentKey$.complete()})}open(){this.visible$.next(!0)}close(){this.visible$.next(!1)}},f.DesktopGlobalZoneService=X0([q0(0,h.Inject(v1))],f.DesktopGlobalZoneService);var Me=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function J0(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Se(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var o3={exports:{}};/*!
|
|
14
14
|
localForage -- Offline Storage, Improved
|
|
15
15
|
Version 1.10.0
|
|
@@ -62,7 +62,7 @@ ${a.DataStreamTreeTokenType.TABLE_CELL_END}`;break}}}_processBeforeLink(t,e){ret
|
|
|
62
62
|
`)||(i+=`\r
|
|
63
63
|
`,e.push({startIndex:i.length-2}),n.push({startIndex:i.length-1}),t.dataStream=i,t.paragraphs=e,t.sectionBreaks=n);const s={html:""},r=_.parseDataStreamToTree(i).sectionList;for(const c of r)$e(c,o,s);return s.html}function $e(o,t,e){var n,i;switch(o.nodeType){case a.DataStreamTreeNodeType.SECTION_BREAK:{for(const s of o.children)$e(s,t,e);break}case a.DataStreamTreeNodeType.PARAGRAPH:{const{children:s,startIndex:r,endIndex:c}=o,l=(i=(n=t.body)==null?void 0:n.paragraphs.find(g=>g.startIndex===c))!=null?i:{},{paragraphStyle:A={}}=l,{spaceAbove:d,spaceBelow:u,lineSpacing:m}=A,h=[];if(d!=null&&(typeof d=="number"?h.push(`margin-top: ${d}px`):h.push(`margin-top: ${d.v}px`)),u!=null&&(typeof u=="number"?h.push(`margin-bottom: ${u}px`):h.push(`margin-bottom: ${u.v}px`)),m!=null&&h.push(`line-height: ${m}`),e.html+=`<p class="UniverNormal" ${h.length?`style="${h.join("; ")};"`:""}>`,s.length)for(const g of s)$e(g,t,e);e.html+=`${Wr(t,r,c)}</p>`;break}case a.DataStreamTreeNodeType.TABLE:{const{children:s}=o;e.html+='<table class="UniverTable" style="width: 100%; border-collapse: collapse;"><tbody>';for(const r of s)$e(r,t,e);e.html+="</tbody></table>";break}case a.DataStreamTreeNodeType.TABLE_ROW:{const{children:s}=o;e.html+='<tr class="UniverTableRow">';for(const r of s)$e(r,t,e);e.html+="</tr>";break}case a.DataStreamTreeNodeType.TABLE_CELL:{const{children:s}=o;e.html+='<td class="UniverTableCell">';for(const r of s)$e(r,t,e);e.html+="</td>";break}default:throw new Error(`Unknown node type: ${o.nodeType}`)}}class Gr{convert(t){if(t.length===0)throw new Error("The bodyList length at least to be 1");let e="";for(const n of a.Tools.deepClone(t))e+=ha(n);return e}}var jr=Object.getOwnPropertyDescriptor,Xr=(o,t,e,n)=>{for(var i=n>1?void 0:n?jr(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},pt=(o,t)=>(e,n)=>t(e,n,o);Ze.use(Aa),Ze.use(ca),Ze.use(da);function ga(o,t,e){var s,r,c;const n=a.getBodySlice(o,t,e+2),i=a.DataStreamTreeTokenType.TABLE_START+a.DataStreamTreeTokenType.TABLE_ROW_START+a.DataStreamTreeTokenType.TABLE_CELL_START+n.dataStream+a.DataStreamTreeTokenType.TABLE_CELL_END+a.DataStreamTreeTokenType.TABLE_ROW_END+a.DataStreamTreeTokenType.TABLE_END;return n.dataStream=i,(s=n.textRuns)==null||s.forEach(l=>{const{st:A,ed:d}=l;l.st=A+3,l.ed=d+3}),(r=n.tables)==null||r.forEach(l=>{const{startIndex:A,endIndex:d}=l;l.startIndex=A+3,l.endIndex=d+3}),(c=n.paragraphs)==null||c.forEach(l=>{const{startIndex:A}=l;l.startIndex=A+3}),n}const xe=a.createIdentifier("doc.clipboard-service");let Ao=class extends a.Disposable{constructor(t,e,n,i,s){super();B(this,"_clipboardHooks",[]);B(this,"_htmlToUDM",new Ze);B(this,"_umdToHtml",new Gr);this._univerInstanceService=t,this._logService=e,this._commandService=n,this._clipboardInterfaceService=i,this._docSelectionManagerService=s}async copy(t=a.SliceBodyType.copy,e){var c,l;const{newSnapshotList:n=[],needCache:i=!1,snapshot:s,ranges:r}=(c=this._getDocumentBodyInRanges(t,e))!=null?c:{};if(n.length===0||s==null)return!1;try{const A=!!((l=r==null?void 0:r[0])!=null&&l.segmentId);this._setClipboardData(n,!A&&i)}catch(A){return this._logService.error("[DocClipboardService] copy failed",A),!1}return!0}async cut(t){return this._cut(t)}async paste(t){const e=await this._genDocDataFromClipboardItems(t);return this._paste(e)}async legacyPaste(t){let{html:e,text:n,files:i}=t;const s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),r=(s==null?void 0:s.getUnitId())||"";if(!e&&!n&&i.length&&(e=await this._createImagePasteHtml(i)),!e&&!n)return this._logService.warn("[DocClipboardController] html and text cannot be both empty!"),!1;const c=this._genDocDataFromHtmlAndText(e,n,r);if(r===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)if(n){const l=a.BuildTextUtils.transform.fromPlainText(n);return this._paste({body:l})}else c.body.textRuns=[];return this._paste(c)}async _cut(t){var c,l,A,d,u;const e=(l=(c=t==null?void 0:t.filter(m=>m.rangeType===a.DOC_RANGE_TYPE.TEXT))!=null?c:this._docSelectionManagerService.getTextRanges())!=null?l:[],n=(d=(A=t==null?void 0:t.filter(m=>m.rangeType===a.DOC_RANGE_TYPE.RECT))!=null?A:this._docSelectionManagerService.getRectRanges())!=null?d:[],{segmentId:i,endOffset:s,style:r}=(u=e[0])!=null?u:{};if(i==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),e.length===0&&n.length===0)return!1;this.copy(a.SliceBodyType.cut,t);try{let m=0;if(n.length>0)m=Jt(e,n);else if(s!=null){m=s;for(const g of e){const{startOffset:p,endOffset:f}=g;p==null||f==null||f<=s&&(m-=f-p)}}const h=[{startOffset:m,endOffset:m,style:r}];return this._commandService.executeCommand(Ve.id,{segmentId:i,textRanges:h,rectRanges:n,selections:e})}catch{return this._logService.error("[DocClipboardController] cut content failed"),!1}}async _paste(t){var d,u,m;const{body:e}=t;if(e==null)return!1;let n=a.normalizeBody(e);if(!((d=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC))==null?void 0:d.getUnitId()))return!1;this._clipboardHooks.forEach(h=>{h.onBeforePaste&&(n=h.onBeforePaste(n))}),n.customRanges=(u=n.customRanges)==null?void 0:u.map(a.BuildTextUtils.customRange.copyCustomRange),(m=n.paragraphs)==null||m.forEach(h=>{var g;(g=h.paragraphStyle)!=null&&g.headingId&&(h.paragraphStyle.headingId=a.generateRandomId(6))});const s=this._docSelectionManagerService.getActiveTextRange(),{segmentId:r,endOffset:c,style:l}=s||{},A=this._docSelectionManagerService.getTextRanges();if(r==null&&this._logService.error("[DocClipboardController] segmentId does not exist!"),c==null||A==null)return!1;try{let h=c;for(const p of A){const{startOffset:f,endOffset:S}=p;f==null||S==null||S<=c&&(h+=n.dataStream.length-(S-f))}const g=[{startOffset:h,endOffset:h,style:l}];return this._commandService.executeCommand(no.id,{doc:{...t,body:n},segmentId:r,textRanges:g})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(t,e=!0){var r,c,l,A;const n=Qr(),i=(t.length>1?t.map(d=>{var u;return((u=d.body)==null?void 0:u.dataStream)||""}).join(`
|
|
64
64
|
`):((r=t[0].body)==null?void 0:r.dataStream)||"").replaceAll(a.DataStreamTreeTokenType.TABLE_START,"").replaceAll(a.DataStreamTreeTokenType.TABLE_END,"").replaceAll(a.DataStreamTreeTokenType.TABLE_ROW_START,"").replaceAll(a.DataStreamTreeTokenType.TABLE_ROW_END,"").replaceAll(a.DataStreamTreeTokenType.TABLE_CELL_START,"").replaceAll(a.DataStreamTreeTokenType.TABLE_CELL_END,"").replaceAll(`\r
|
|
65
|
-
`," ");let s=this._umdToHtml.convert(t);if(t.length===1&&e){s=s.replace(/(<[a-z]+)/,(m,h)=>`${h} data-copy-id="${n}"`);const d=t[0],u={body:d.body};if((l=(c=d.body)==null?void 0:c.customBlocks)!=null&&l.length){u.drawings={};for(const m of d.body.customBlocks){const{blockId:h}=m,g=(A=d.drawings)==null?void 0:A[h];if(g){const p=a.Tools.generateRandomId(6);m.blockId=p,u.drawings[p]={...a.Tools.deepClone(g),drawingId:p}}}}ro.set(n,u)}return this._clipboardInterfaceService.write(i,s)}addClipboardHook(t){return this._clipboardHooks.push(t),a.toDisposable(()=>{const e=this._clipboardHooks.indexOf(t);e>-1&&this._clipboardHooks.splice(e,1)})}_getDocumentBodyInRanges(t,e){var d;const n=this._univerInstanceService.getCurrentUniverDocInstance(),i=e!=null?e:this._docSelectionManagerService.getDocRanges(),s=[];let r=!0;if(n==null||i.length===0)return;const c=i[0].segmentId,l=(d=n==null?void 0:n.getSelfOrHeaderFooterModel(c))==null?void 0:d.getBody(),A=n.getSnapshot();if(l!=null){for(const u of i){const{startOffset:m,endOffset:h,collapsed:g,rangeType:p}=u;if(g||m==null||h==null)continue;if(p===a.DOC_RANGE_TYPE.RECT){r=!1;const{spanEntireRow:E}=u;let C;C=ga(l,m,h),s.push(C);continue}const f={startOffset:m,endOffset:h},S=n.getSelfOrHeaderFooterModel(c).sliceBody(f.startOffset,f.endOffset,t);S!=null&&s.push(S)}return{newSnapshotList:s.map(u=>({...A,body:u})),needCache:r,snapshot:A,ranges:i}}}async _genDocDataFromClipboardItems(t){try{let e="",n="";const i=[];for(const s of t)for(const r of s.types)switch(r){case I.PLAIN_TEXT_CLIPBOARD_MIME_TYPE:{n=await s.getType(r).then(c=>c&&c.text());break}case I.HTML_CLIPBOARD_MIME_TYPE:{e=await s.getType(r).then(c=>c&&c.text());break}case I.FILE__BMP_CLIPBOARD_MIME_TYPE:case I.FILE__JPEG_CLIPBOARD_MIME_TYPE:case I.FILE__WEBP_CLIPBOARD_MIME_TYPE:case I.FILE_PNG_CLIPBOARD_MIME_TYPE:{const c=await s.getType(r),l=new File([c],`pasted_image.${r.split("/")[1]}`,{type:r});i.push(l);break}}return!e&&!n&&i.length&&(e=await this._createImagePasteHtml(i)),this._genDocDataFromHtmlAndText(e,n)}catch(e){return Promise.reject(e)}}_genDocDataFromHtmlAndText(t,e,n){if(!t){if(e)return{body:a.BuildTextUtils.transform.fromPlainText(e)};throw new Error("[DocClipboardService] html and text cannot be both empty!")}const i=Fr(t);if(i){const r=ro.get(i);if(r)return r}if(!n){const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);n=(r==null?void 0:r.getUnitId())||""}const s=this._htmlToUDM.convert(t,{unitId:n});return i&&ro.set(i,s),s}async _createImagePasteHtml(t){var c,l;const e={id:"",documentStyle:{},body:{dataStream:"",customBlocks:[]},drawings:{}},n=async A=>{const d=new FileReader;return new Promise(u=>{d.onloadend=function(){u({source:d.result,imageSourceType:xn.ImageSourceType.BASE64})},d.readAsDataURL(A)})},i=A=>{const d=new Image,u=500;return new Promise(m=>{d.src=typeof A=="string"?A:URL.createObjectURL(A),d.onload=()=>{const h=Math.min(u,d.naturalWidth),g=d.naturalHeight/d.naturalWidth;m({width:h,height:h*g})}})},s=(l=(c=this._clipboardHooks.find(A=>A.onBeforePasteImage))==null?void 0:c.onBeforePasteImage)!=null?l:n;return await Promise.all(t.map(async(A,d)=>{var S;const u=await s(A);if(!u)return Promise.resolve();const{width:m=100,height:h=100}=await i(A),g=`paste_image_id_${d}`,p=e.body,f=e.drawings;p.dataStream+="\b",(S=p.customBlocks)==null||S.push({startIndex:d,blockId:g}),f[g]={drawingId:g,unitId:"",subUnitId:"",imageSourceType:u.imageSourceType,title:"",source:u.source,description:"",layoutType:a.PositionedObjectLayoutType.INLINE,drawingType:a.DrawingTypeEnum.DRAWING_IMAGE,transform:{width:m,height:h,angle:0},docTransform:{angle:0,size:{width:m,height:h},positionH:{relativeFrom:a.ObjectRelativeFromH.CHARACTER,posOffset:0},positionV:{relativeFrom:a.ObjectRelativeFromV.LINE,posOffset:0}}}})),this._umdToHtml.convert([e])}};Ao=Xr([pt(0,a.IUniverInstanceService),pt(1,a.ILogService),pt(2,a.ICommandService),pt(3,I.IClipboardInterfaceService),pt(4,a.Inject(D.DocSelectionManagerService))],Ao);function Zt(o){return o.getContextValue(a.FOCUSING_DOC)||o.getContextValue(a.EDITOR_ACTIVATED)}const uo=999,ft={id:I.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:uo,preconditions:Zt,handler:async o=>o.get(xe).copy()},ho={id:"doc.command.copy-current-paragraph",type:a.CommandType.COMMAND,handler:async o=>{const t=o.get(xe),e=gt(o);return e?t.copy(a.SliceBodyType.copy,[{startOffset:e.paragraphStart,endOffset:e.paragraphEnd+1,collapsed:!1}]):!1}},$t={id:I.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:uo,preconditions:Zt,handler:async o=>o.get(xe).cut()},go={id:"doc.command.cut-current-paragraph",type:a.CommandType.COMMAND,handler:async o=>{const t=o.get(xe),e=gt(o);return e?t.cut([{startOffset:e.paragraphStart,endOffset:e.paragraphEnd+1,collapsed:!1,rangeType:a.DOC_RANGE_TYPE.TEXT}]):!1}},en={id:I.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:uo,preconditions:Zt,handler:async o=>{const t=o.get(xe),n=await o.get(I.IClipboardInterfaceService).read();return n.length===0?!1:t.paste(n)}};var Kr=Object.getOwnPropertyDescriptor,zr=(o,t,e,n)=>{for(var i=n>1?void 0:n?Kr(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},mo=(o,t)=>(e,n)=>t(e,n,o);const Yr=11,qr=9,tn={ff:"Arial",fs:Yr};let Te=class extends a.Disposable{constructor(t,e,n){super();B(this,"_cacheStyle",null);this._textSelectionManagerService=t,this._univerInstanceService=e,this._renderManagerService=n,this._init()}_init(){this._listenDocRangeChange()}_listenDocRangeChange(){this.disposeWithMe(this._textSelectionManagerService.textSelection$.subscribe(()=>{this._clearStyleCache()}))}getStyleCache(){return this._cacheStyle}getDefaultStyle(){var r;const t=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(t==null)return{...tn};const e=t==null?void 0:t.getUnitId(),n=(r=this._renderManagerService.getRenderById(e))==null?void 0:r.with(D.DocSkeletonManagerService),i=n==null?void 0:n.getViewModel();return i==null?{...tn}:i.getEditArea()===_.DocumentEditArea.BODY?{...tn}:{...tn,fs:qr}}setStyleCache(t){this._cacheStyle={...this._cacheStyle,...t}}_clearStyleCache(){this._cacheStyle=null}};Te=zr([mo(0,a.Inject(D.DocSelectionManagerService)),mo(1,a.IUniverInstanceService),mo(2,_.IRenderManagerService)],Te);function po(o,t,e){const n=[];for(let i=0,s=o.length;i<s;i++)o[i]===a.DataStreamTreeTokenType.PARAGRAPH&&n.push({startIndex:i});if(t)for(const i of n)t.bullet&&(i.bullet=a.Tools.deepClone(t.bullet)),t.paragraphStyle&&(i.paragraphStyle=a.Tools.deepClone(t.paragraphStyle),delete i.paragraphStyle.borderBottom,t.paragraphStyle.headingId&&(i.paragraphStyle.headingId=a.generateRandomId(6)));if(e)for(const i of n)i.paragraphStyle||(i.paragraphStyle={}),i.paragraphStyle.borderBottom=e;return n}const nn={id:"doc.command.break-line",type:a.CommandType.COMMAND,handler:(o,t)=>{var Q,X,j,k,W;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),s=o.get(Te),r=(Q=t==null?void 0:t.textRange)!=null?Q:e.getActiveTextRange(),c=e.getRectRanges();if(r==null)return!1;if(c&&c.length){const{startOffset:G}=r;return e.replaceDocRanges([{startOffset:G,endOffset:G}]),!0}const{horizontalLine:l}=t!=null?t:{},{segmentId:A}=r,d=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(A!=null?A:"").getBody();if(d==null||u==null)return!1;const m=d.getUnitId(),{startOffset:h,endOffset:g}=r,f=((X=u.paragraphs)!=null?X:[]).find(G=>G.startIndex>=h);if(!f)return!1;const S=h===f.startIndex,E=f.startIndex,C=s.getDefaultStyle(),T=s.getStyleCache(),R=Lt(u,g,C,T),v={dataStream:a.DataStreamTreeTokenType.PARAGRAPH,paragraphs:po(a.DataStreamTreeTokenType.PARAGRAPH,f,l),textRuns:[{st:0,ed:1,ts:{...R.ts}}]};if(d==null)return!1;const O=e.getActiveTextRange();if(u==null)return!1;const{collapsed:M}=r,b=v.dataStream.length,N=[{startOffset:h+b,endOffset:h+b,style:O==null?void 0:O.style,collapsed:M}],x={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:N,debounce:!0}},U=new a.TextX,F=a.JSONX.getInstance();if(M)h>0&&U.push({t:a.TextXActionType.RETAIN,len:h}),U.push({t:a.TextXActionType.INSERT,body:v,len:v.dataStream.length});else{const G=a.BuildTextUtils.selection.delete([r],u,0,v);U.push(...G)}(((j=f.bullet)==null?void 0:j.listType)===a.PresetListType.CHECK_LIST_CHECKED||(k=f.paragraphStyle)!=null&&k.headingId)&&(r.endOffset<E&&U.push({t:a.TextXActionType.RETAIN,len:E-r.endOffset}),U.push({t:a.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...f,paragraphStyle:{...f.paragraphStyle,...S?{headingId:void 0,namedStyleType:void 0}:null},startIndex:0,bullet:(W=f.paragraphStyle)!=null&&W.headingId?void 0:{...f.bullet,listType:a.PresetListType.CHECK_LIST}}]},coverType:a.UpdateDocsAttributeType.REPLACE})),x.params.textRanges=[{startOffset:h+b,endOffset:h+b,collapsed:M}];const V=Z(d,A);return x.params.actions=F.editOp(U.serialize(),V),!!i.syncExecuteCommand(x.id,x.params)}},St={id:"doc.command.horizontal-line",type:a.CommandType.COMMAND,handler:(o,t)=>o.get(a.ICommandService).syncExecuteCommand(nn.id,{horizontalLine:{padding:5,color:{rgb:"#CDD0D8"},width:1,dashStyle:a.DashStyleType.SOLID},textRange:t==null?void 0:t.insertRange})},fo={id:"doc.command.insert-horizontal-line-bellow",type:a.CommandType.COMMAND,handler:o=>{const t=o.get(a.ICommandService),e=gt(o);return e?t.syncExecuteCommand(St.id,{insertRange:{startOffset:e.startIndex+1,endOffset:e.startIndex+1}}):!1}};function ue(o,t,e){return e.executeCommand(be.id,{preCommandId:o,...t!=null?t:{}})}const ma="doc.command.set-inline-format-bold",De={id:ma,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(ma,t,e)}},pa="doc.command.set-inline-format-italic",Be={id:pa,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(pa,t,e)}},fa="doc.command.set-inline-format-underline",_e={id:fa,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(fa,t,e)}},Sa="doc.command.set-inline-format-strikethrough",Ne={id:Sa,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Sa,t,e)}},Ia="doc.command.set-inline-format-subscript",ye={id:Ia,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Ia,t,e)}},va="doc.command.set-inline-format-superscript",Pe={id:va,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(va,t,e)}},Ea="doc.command.set-inline-format-fontsize",ge={id:Ea,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Ea,t,e)}},Ca="doc.command.set-inline-format-font-family",We={id:Ca,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Ca,t,e)}},Ta="doc.command.set-inline-format-text-color",we={id:Ta,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Ta,t,e)}},ya="doc.command.set-inline-format-text-background-color",Ue={id:ya,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(ya,t,e)}},ba="doc.command.reset-inline-format-text-background-color",et={id:ba,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(ba,t,e)}},So={[De.id]:"bl",[Be.id]:"it",[_e.id]:"ul",[Ne.id]:"st",[ge.id]:"fs",[We.id]:"ff",[we.id]:"cl",[Ue.id]:"bg",[et.id]:"bg",[ye.id]:"va",[Pe.id]:"va"},be={id:"doc.command.set-inline-format",type:a.CommandType.COMMAND,handler:async(o,t)=>{var R;const{value:e,preCommandId:n}=t,i=o.get(a.ICommandService),s=o.get(D.DocSelectionManagerService),r=o.get(a.IUniverInstanceService),c=o.get(Te),l=s.getDocRanges(),A=(R=l.find(v=>v.isActive))!=null?R:l[0];if(l.length===0)return!1;const{segmentId:d}=l[0],u=r.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(u==null)return!1;const m=u.getSelfOrHeaderFooterModel(d).getBody();if(m==null)return!1;const h=u.getUnitId();let g;switch(n){case De.id:case Be.id:case _e.id:case Ne.id:case ye.id:case Pe.id:{const v=c.getDefaultStyle(),O=Ra(m,A,v);g=Zr(O,n);break}case ge.id:case We.id:{g=e;break}case we.id:case Ue.id:{g={rgb:e};break}case et.id:{g={rgb:null};break}default:throw new Error(`Unknown command: ${n} in handleInlineFormat`)}const p={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:l}},f=new a.TextX,S=a.JSONX.getInstance(),E=new a.MemoryCursor;E.reset();for(const v of l){let{startOffset:O,endOffset:M,rangeType:b}=v;if(O==null||M==null)continue;if(b===a.DOC_RANGE_TYPE.RECT&&(O=O-1),O===M){const U=c.getStyleCache(),F=So[n];c.setStyleCache({[F]:(U==null?void 0:U[F])!==void 0?Oa(U,F,n):g});continue}const N={dataStream:"",textRuns:[{st:0,ed:M-O,ts:{[So[n]]:g}}]},x=O-E.cursor;x!==0&&f.push({t:a.TextXActionType.RETAIN,len:x}),f.push({t:a.TextXActionType.RETAIN,body:N,len:M-O}),E.reset(),E.moveCursor(M)}const C=Z(u,d);return p.params.actions=S.editOp(f.serialize(),C),!!i.syncExecuteCommand(p.id,p.params)}};function Jr(o){return o!==null&&typeof o=="object"}function Oa(o,t,e){if(/bl|it/.test(t))return(o==null?void 0:o[t])===a.BooleanNumber.TRUE?a.BooleanNumber.FALSE:a.BooleanNumber.TRUE;if(/ul|st/.test(t))return Jr(o==null?void 0:o[t])&&(o==null?void 0:o[t]).s===a.BooleanNumber.TRUE?{s:a.BooleanNumber.FALSE}:{s:a.BooleanNumber.TRUE};if(/va/.test(t))return e===ye.id?(o==null?void 0:o[t])===a.BaselineOffset.SUBSCRIPT?a.BaselineOffset.NORMAL:a.BaselineOffset.SUBSCRIPT:(o==null?void 0:o[t])===a.BaselineOffset.SUPERSCRIPT?a.BaselineOffset.NORMAL:a.BaselineOffset.SUPERSCRIPT}function Ra(o,t,e){var d,u,m,h,g,p,f,S,E,C,T,R,v,O;const{startOffset:n,endOffset:i,collapsed:s}=t;if(s){const M=(d=o.textRuns)!=null?d:[];let b=null;for(let N=M.length-1;N>=0;N--){const x=M[N];if(x.st<n&&n<=x.ed){b=x;break}}return b!=null&&b.ts?{...e,...b.ts}:e}const{textRuns:r=[]}=a.getBodySlice(o,n,i),c=a.Tools.deepClone(e),l=r.map(M=>{var b;return(b=M==null?void 0:M.ts)==null?void 0:b.fs}).filter(Boolean);c.fs=c.fs?Math.max(c.fs,...l):l.length?Math.max(...l):void 0,c.fs=!c.fs||Number.isNaN(c.fs)?void 0:c.fs,c.ff=(h=(m=(u=r.find(M=>{var b;return((b=M.ts)==null?void 0:b.ff)!=null}))==null?void 0:u.ts)==null?void 0:m.ff)!=null?h:c.ff,c.it=r.length&&r.every(M=>{var b;return((b=M.ts)==null?void 0:b.it)===a.BooleanNumber.TRUE})?a.BooleanNumber.TRUE:a.BooleanNumber.FALSE,c.bl=r.length&&r.every(M=>{var b;return((b=M.ts)==null?void 0:b.bl)===a.BooleanNumber.TRUE})?a.BooleanNumber.TRUE:a.BooleanNumber.FALSE,c.ul=r.length&&r.every(M=>{var b,N;return((N=(b=M.ts)==null?void 0:b.ul)==null?void 0:N.s)===a.BooleanNumber.TRUE})?(g=r[0].ts)==null?void 0:g.ul:c.ul,c.st=r.length&&r.every(M=>{var b,N;return((N=(b=M.ts)==null?void 0:b.st)==null?void 0:N.s)===a.BooleanNumber.TRUE})?(p=r[0].ts)==null?void 0:p.st:c.st,c.bg=(E=(S=(f=r.find(M=>{var b;return((b=M.ts)==null?void 0:b.bg)!=null}))==null?void 0:f.ts)==null?void 0:S.bg)!=null?E:c.bg,c.cl=(R=(T=(C=r.find(M=>{var b;return((b=M.ts)==null?void 0:b.cl)!=null}))==null?void 0:C.ts)==null?void 0:T.cl)!=null?R:c.cl;const A=r.filter(M=>{var b;return((b=M==null?void 0:M.ts)==null?void 0:b.va)!=null});if(A.length>0&&A.length===r.length){const M=(v=A[0].ts)==null?void 0:v.va;let b=!0;for(let N=1;N<A.length;N++)if(((O=A[N].ts)==null?void 0:O.va)!==M){b=!1;break}b&&(c.va=M)}return c}function Zr(o,t){const e=So[t];return Oa(o,e,t)}const tt={id:"doc.command.list-operation",type:a.CommandType.COMMAND,handler:(o,t)=>{var T,R,v,O,M,b;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),s=t.listType,r=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),c=(R=(T=t.docRange)!=null?T:e.getDocRanges())!=null?R:[];if(r==null||c.length===0)return!1;const l=c[0].segmentId,A=r.getSelfOrHeaderFooterModel(l),d=(O=(v=A.getBody())==null?void 0:v.paragraphs)!=null?O:[],u=(b=(M=A.getBody())==null?void 0:M.dataStream)!=null?b:"";if(!d.length)return!1;const m=a.BuildTextUtils.range.getParagraphsInRanges(c,d,u),h=r.getUnitId(),g={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:c,isEditing:!1}};new a.MemoryCursor().reset();const f=a.BuildTextUtils.paragraph.bullet.switch({paragraphs:m,listType:s,document:r,segmentId:l}),S=a.JSONX.getInstance(),E=Z(r,l);return g.params.actions=S.editOp(f.serialize(),E),!!i.syncExecuteCommand(g.id,g.params)}},It={id:"doc.command.change-list-type",type:a.CommandType.COMMAND,handler:(o,t)=>{var C,T,R,v,O;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),{listType:s}=t,r=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),c=(C=t.docRange)!=null?C:e.getDocRanges();if(r==null||c==null||!c.length)return!1;const{segmentId:l}=c[0],A=r.getSelfOrHeaderFooterModel(l),d=(R=(T=A.getBody())==null?void 0:T.paragraphs)!=null?R:[],u=(O=(v=A.getBody())==null?void 0:v.dataStream)!=null?O:"";if(!d.length)return!1;const m=a.BuildTextUtils.range.getParagraphsInRanges(c,d,u),h=r.getUnitId(),g=a.BuildTextUtils.paragraph.bullet.set({paragraphs:m,listType:s,segmentId:l,document:r});if(!g)return!1;const p=a.JSONX.getInstance(),f={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:c,isEditing:!1}},S=Z(r,l);return f.params.actions=p.editOp(g.serialize(),S),!!i.syncExecuteCommand(f.id,f.params)}};var vt=(o=>(o[o.increase=1]="increase",o[o.decrease=-1]="decrease",o))(vt||{});const on={id:"doc.command.change-list-nesting-level",type:a.CommandType.COMMAND,handler:(o,t)=>{var T,R,v,O,M;if(!t)return!1;const{type:e}=t,n=o.get(D.DocSelectionManagerService),i=o.get(a.IUniverInstanceService),s=o.get(a.ICommandService),r=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),c=n.getActiveTextRange();if(r==null||c==null)return!1;const{segmentId:l}=c,A=(T=n.getDocRanges())!=null?T:[],d=r.getSelfOrHeaderFooterModel(l),u=(v=(R=d.getBody())==null?void 0:R.paragraphs)!=null?v:[],m=(M=(O=d.getBody())==null?void 0:O.dataStream)!=null?M:"";if(!u.length)return!1;const h=a.BuildTextUtils.range.getParagraphsInRange(c,u,m),g=r.getUnitId(),p=a.JSONX.getInstance(),f=a.BuildTextUtils.paragraph.bullet.changeNestLevel({paragraphs:h,type:e,segmentId:l,document:r}),S={id:D.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:A,isEditing:!1}},E=Z(r,l);return S.params.actions=p.editOp(f.serialize(),E),!!s.syncExecuteCommand(S.id,S.params)}},nt={id:"doc.command.bullet-list",type:a.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(a.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(It.id,{listType:t.value,docRange:t.docRange}):e.syncExecuteCommand(tt.id,{listType:a.PresetListType.BULLET_LIST,docRange:t==null?void 0:t.docRange})}},Et={id:"doc.command.check-list",type:a.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(a.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(It.id,{listType:t.value,docRange:t.docRange}):e.syncExecuteCommand(tt.id,{listType:a.PresetListType.CHECK_LIST,docRange:t==null?void 0:t.docRange})}},Io={id:"doc.command.toggle-check-list",type:a.CommandType.COMMAND,handler:(o,t)=>{var p;if(!t)return!1;const e=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService),{index:i,segmentId:s,textRanges:r}=t,c=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(c==null||((p=c.getSelfOrHeaderFooterModel(s).getBody())==null?void 0:p.paragraphs)==null)return!1;const A=c.getUnitId(),d={id:D.RichTextEditingMutation.id,params:{unitId:A,actions:[],textRanges:r!=null?r:[],segmentId:s,isEditing:!1}},u=a.BuildTextUtils.paragraph.bullet.toggleChecklist({document:c,paragraphIndex:i,segmentId:s});if(!u)return!1;const m=a.JSONX.getInstance(),h=Z(c,s);return d.params.actions=m.editOp(u.serialize(),h),!!n.syncExecuteCommand(d.id,d.params)}},ot={id:"doc.command.order-list",type:a.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(a.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(It.id,{listType:t.value}):e.syncExecuteCommand(tt.id,{listType:a.PresetListType.ORDER_LIST})}},vo={id:"doc.command.quick-list",type:a.CommandType.COMMAND,handler(o,t){var x,U,F;if(!t)return!1;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),s=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),r=e.getActiveTextRange();if(s==null||r==null)return!1;const{segmentId:c,startOffset:l}=r,{listType:A,paragraph:d}=t,{paragraphStart:u,paragraphEnd:m}=d,h=new a.TextX,g=a.JSONX.getInstance(),{paragraphStyle:p={}}=d,S=(a.PRESET_LIST_TYPE[A].nestingLevel[0].paragraphProperties||{}).textStyle;let C=a.Tools.generateRandomId(6);const T=(U=(x=s.getBody())==null?void 0:x.paragraphs)!=null?U:[],R=T.findIndex(V=>V.startIndex===d.startIndex),v=T[R-1],O=T[R+1];v&&v.bullet&&v.bullet.listType.indexOf(A)===0?C=v.bullet.listId:O&&O.bullet&&O.bullet.listType.indexOf(A)===0&&(C=O.bullet.listId);const M={id:D.RichTextEditingMutation.id,params:{unitId:s.getUnitId(),actions:[],textRanges:[{startOffset:u,endOffset:u,collapsed:!0}],isEditing:!1}};h.push({t:a.TextXActionType.RETAIN,len:u}),h.push({t:a.TextXActionType.DELETE,len:l-u}),m>l&&h.push({t:a.TextXActionType.RETAIN,len:m-l}),h.push({t:a.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{startIndex:0,paragraphStyle:{...p,textStyle:{...p.textStyle,...S},indentFirstLine:void 0},bullet:{...(F=d.bullet)!=null?F:{nestingLevel:0,textStyle:{fs:20}},listType:A,listId:C}}]}});const b=Z(s,c);return M.params.actions=g.editOp(h.serialize(),b),!!i.syncExecuteCommand(M.id,M.params)}};function Eo(o,t){var d,u;const e=o.get(a.ICommandService),n=gt(o);if(!n)return!1;const i=o.get(a.IUniverInstanceService).getCurrentUnitOfType(a.UniverInstanceType.UNIVER_DOC);if(!i)return!1;const s=a.BuildTextUtils.selection.replace({doc:i,selection:{startOffset:n.startIndex+1,endOffset:n.startIndex+1,collapsed:!0},body:{dataStream:"\r",paragraphs:[{startIndex:0,paragraphStyle:{...n.paragraphStyle},bullet:{listType:t,listId:((d=n.bullet)==null?void 0:d.listType)===t?n.bullet.listId:a.Tools.generateRandomId(6),nestingLevel:((u=n.bullet)==null?void 0:u.listType)===t?n.bullet.nestingLevel:0}}]}});if(!s)return!1;const r={id:D.RichTextEditingMutation.id,params:{unitId:i.getUnitId(),actions:[],textRanges:[{startOffset:n.startIndex+1,endOffset:n.startIndex+1,collapsed:!0}],isEditing:!1}},c=a.JSONX.getInstance(),l=Z(i);return r.params.actions=c.editOp(s.serialize(),l),!!e.syncExecuteCommand(r.id,r.params)}const Co={id:"doc.command.insert-bullet-list-bellow",type:a.CommandType.COMMAND,handler:o=>Eo(o,a.PresetListType.BULLET_LIST)},To={id:"doc.command.insert-order-list-bellow",type:a.CommandType.COMMAND,handler:o=>Eo(o,a.PresetListType.ORDER_LIST)},yo={id:"doc.command.insert-check-list-bellow",type:a.CommandType.COMMAND,handler:o=>Eo(o,a.PresetListType.CHECK_LIST)},de={id:"doc.command.set-paragraph-named-style",type:a.CommandType.COMMAND,handler(o,t){var g;if(!t)return!1;const n=o.get(a.IUniverInstanceService).getCurrentUnitOfType(a.UniverInstanceType.UNIVER_DOC);if(!n)return!1;const i=n.getUnitId(),s=o.get(D.DocSelectionManagerService),r=(g=t.textRanges)!=null?g:s.getTextRanges({unitId:i,subUnitId:i});if(!(r!=null&&r.length))return!1;const c=r[0].segmentId,l=a.BuildTextUtils.paragraph.style.set({document:n.getSelfOrHeaderFooterModel(c),textRanges:r,style:{namedStyleType:t.value,headingId:!t.value||t.value===a.NamedStyleType.NORMAL_TEXT?void 0:a.generateRandomId(6),spaceAbove:void 0,spaceBelow:void 0,lineSpacing:void 0},paragraphTextRun:{}}),A={id:D.RichTextEditingMutation.id,params:{actions:[],textRanges:r,unitId:i,segmentId:c}},d=a.JSONX.getInstance(),u=Z(n,c);return A.params.actions=d.editOp(l.serialize(),u),!!o.get(a.ICommandService).syncExecuteCommand(A.id,A.params)}},Ma={id:"doc.command.quick-heading",type:a.CommandType.COMMAND,handler(o,t){var R,v,O,M;if(!t)return!1;const{value:e}=t,n=o.get(D.DocSelectionManagerService),i=o.get(a.IUniverInstanceService),s=o.get(a.ICommandService),r=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),c=n.getActiveTextRange();if(r==null||c==null||!c.collapsed)return!1;const{segmentId:l,startOffset:A}=c,d=r.getSelfOrHeaderFooterModel(l),u=(v=(R=d.getBody())==null?void 0:R.paragraphs)!=null?v:[],m=(M=(O=d.getBody())==null?void 0:O.dataStream)!=null?M:"",h=a.BuildTextUtils.paragraph.util.getParagraphsInRange(c,u,m)[0];if(!h)return!1;const{paragraphStart:g}=h,p=new a.TextX,f=a.JSONX.getInstance(),{paragraphStyle:S={}}=h,E={id:D.RichTextEditingMutation.id,params:{unitId:r.getUnitId(),actions:[],textRanges:[{startOffset:g,endOffset:g,collapsed:!0}],isEditing:!1}};p.push({t:a.TextXActionType.RETAIN,len:g}),a.BuildTextUtils.paragraph.style.set({textRanges:[c],document:r,style:{...S,headingId:a.generateRandomId(6),namedStyleType:e},cursor:A,deleteLen:A-g,textX:p,paragraphTextRun:{}});const C=Z(r,l);return E.params.actions=f.editOp(p.serialize(),C),!!s.syncExecuteCommand(E.id,E.params)}},bo={"#":a.NamedStyleType.HEADING_1,"##":a.NamedStyleType.HEADING_2,"###":a.NamedStyleType.HEADING_3,"####":a.NamedStyleType.HEADING_4,"#####":a.NamedStyleType.HEADING_5},Oo={id:"doc.command.h1-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(de.id,{value:a.NamedStyleType.HEADING_1})},Ro={id:"doc.command.h2-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(de.id,{value:a.NamedStyleType.HEADING_2})},Mo={id:"doc.command.h3-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(de.id,{value:a.NamedStyleType.HEADING_3})},xo={id:"doc.command.h4-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(de.id,{value:a.NamedStyleType.HEADING_4})},Do={id:"doc.command.h5-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(de.id,{value:a.NamedStyleType.HEADING_5})},an={id:"doc.command.normal-text-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(de.id,{value:a.NamedStyleType.NORMAL_TEXT})},xa={id:"doc.command.title",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(de.id,{value:a.NamedStyleType.TITLE})},Da={id:"doc.command.subtitle-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(de.id,{value:a.NamedStyleType.SUBTITLE})},me={id:"doc.command.align-action",type:a.CommandType.COMMAND,handler:(o,t)=>{var R,v,O,M;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),{alignType:s}=t,r=n.getCurrentUniverDocInstance();if(r==null)return!1;const c=e.getDocRanges();if(c.length===0)return!1;const l=c[0].segmentId,A=r.getSelfOrHeaderFooterModel(l),d=(v=(R=A.getBody())==null?void 0:R.paragraphs)!=null?v:[],u=(M=(O=A.getBody())==null?void 0:O.dataStream)!=null?M:"";if(d==null)return!1;const m=a.BuildTextUtils.range.getParagraphsInRanges(c,d,u),h=r.getUnitId(),g=m.every(b=>{var N;return((N=b.paragraphStyle)==null?void 0:N.horizontalAlign)===s}),p={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:c}},f=new a.MemoryCursor;f.reset();const S=new a.TextX,E=a.JSONX.getInstance();for(const b of m){const{startIndex:N}=b;S.push({t:a.TextXActionType.RETAIN,len:N-f.cursor});const x={...b.paragraphStyle,horizontalAlign:g?a.HorizontalAlign.UNSPECIFIED:s};S.push({t:a.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...b,paragraphStyle:x,startIndex:0}]},coverType:a.UpdateDocsAttributeType.REPLACE}),f.moveCursorTo(N+1)}const C=Z(r,l);return p.params.actions=E.editOp(S.serialize(),C),!!i.syncExecuteCommand(p.id,p.params)}},Ct={id:"doc.command.align-left",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(me.id,{alignType:a.HorizontalAlign.LEFT})},Tt={id:"doc.command.align-center",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(me.id,{alignType:a.HorizontalAlign.CENTER})},yt={id:"doc.command.align-right",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(me.id,{alignType:a.HorizontalAlign.RIGHT})},bt={id:"doc.command.align-justify",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(me.id,{alignType:a.HorizontalAlign.JUSTIFIED})},Ot={id:"doc.command.switch-mode",type:a.CommandType.COMMAND,handler:o=>{var E,C,T,R,v;const t=o.get(a.ICommandService),e=o.get(_.IRenderManagerService),n=o.get(D.DocSelectionManagerService),s=o.get(a.IUniverInstanceService).getCurrentUniverDocInstance();if(s==null)return!1;const r=s.getUnitId(),c=(E=e.getRenderById(r))==null?void 0:E.with(D.DocSkeletonManagerService).getSkeleton(),l=(C=e.getRenderById(r))==null?void 0:C.with(y.DocSelectionRenderService);if(c==null||l==null)return!1;const A=l==null?void 0:l.getSegment(),d=l==null?void 0:l.getSegmentPage(),u=s.getSnapshot().documentStyle.documentFlavor,m=n.getDocRanges(),h={id:D.RichTextEditingMutation.id,params:{unitId:r,actions:[],textRanges:u===a.DocumentFlavor.TRADITIONAL&&A?[]:m}},g=a.JSONX.getInstance(),p=[];let f;if(u===void 0?f=g.insertOp(["documentStyle","documentFlavor"],a.DocumentFlavor.MODERN):u===a.DocumentFlavor.MODERN?f=g.replaceOp(["documentStyle","documentFlavor"],u,a.DocumentFlavor.TRADITIONAL):f=g.replaceOp(["documentStyle","documentFlavor"],u,a.DocumentFlavor.MODERN),f)p.push(f);else return!1;if(u!==a.DocumentFlavor.MODERN){const O=s.getSnapshot(),{drawings:M={},body:b}=O,N=(T=b==null?void 0:b.customBlocks)!=null?T:[];for(const x in M){const U=M[x],F=N.find($=>$.blockId===x);if(F==null)continue;const V=U.docTransform.positionV,{relativeFrom:H,posOffset:Q}=V;if(H===a.ObjectRelativeFromV.PARAGRAPH)continue;const{startIndex:X}=F,j=c.findNodeByCharIndex(X,A,d),k=(R=j==null?void 0:j.parent)==null?void 0:R.parent,W=k==null?void 0:k.parent,G=W==null?void 0:W.lines.find($=>$.paragraphIndex===(k==null?void 0:k.paragraphIndex)&&$.paragraphStart),K=(v=W==null?void 0:W.parent)==null?void 0:v.parent;if(j==null||k==null||G==null||W==null||K==null)continue;let Y=0;H===a.ObjectRelativeFromV.LINE?Y-=k.top:H===a.ObjectRelativeFromV.PAGE&&(Y+=K.marginTop),Y+=G.top;const q={...V,relativeFrom:a.ObjectRelativeFromV.PARAGRAPH,posOffset:(Q!=null?Q:0)-Y},z=g.replaceOp(["drawings",x,"docTransform","positionV"],V,q);z&&p.push(z)}}return h.params.actions=p.reduce((O,M)=>a.JSONX.compose(O,M),null),!!t.syncExecuteCommand(h.id,h.params)}},Ba="COMPONENT_DOC_CREATE_TABLE_CONFIRM",Bo={id:"doc.command.create-table",type:a.CommandType.COMMAND,handler:async(o,t)=>{var q,z,$,ie,fe;const{rowCount:e,colCount:n}=t,i=o.get(D.DocSelectionManagerService),s=o.get(a.IUniverInstanceService),r=o.get(a.ICommandService),c=o.get(Te),l=i.getActiveTextRange();if(l==null)return!1;const{segmentId:A,segmentPage:d}=l,u=s.getCurrentUniverDocInstance(),m=u==null?void 0:u.getSelfOrHeaderFooterModel(A).getBody();if(u==null||m==null)return!1;const h=u.getUnitId(),g=re(o,h),p=g==null?void 0:g.getSkeleton();if(p==null)return!1;const{startOffset:f}=l,E=((q=m.paragraphs)!=null?q:[]).find(Fe=>Fe.startIndex>=f),C=p.findNodeByCharIndex(f,A,d);if(C==null)return!1;const T=new a.TextX,R=a.JSONX.getInstance(),v=[],O=f+4,M=[{startOffset:O,endOffset:O,collapsed:!0}],b={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:M}};f>0&&T.push({t:a.TextXActionType.RETAIN,len:f}),T.push({t:a.TextXActionType.INSERT,body:{dataStream:a.DataStreamTreeTokenType.PARAGRAPH,paragraphs:po(a.DataStreamTreeTokenType.PARAGRAPH,E)},len:1});const N=c.getDefaultStyle(),x=c.getStyleCache(),U=Lt(m,f,N,x),{dataStream:F,paragraphs:V,sectionBreaks:H}=Tr(e,n),Q=(fe=(ie=($=(z=C.parent)==null?void 0:z.parent)==null?void 0:$.parent)==null?void 0:ie.parent)==null?void 0:fe.parent;if(Q==null)return!1;const{pageWidth:X,marginLeft:j,marginRight:k}=Q,W=eo(e,n,X-j-k);T.push({t:a.TextXActionType.INSERT,body:{dataStream:F,paragraphs:V,sectionBreaks:H,textRuns:[{...U,st:0,ed:F.length}],tables:[{startIndex:0,endIndex:F.length,tableId:W.tableId}]},len:F.length});const G=Z(u,A);v.push(R.editOp(T.serialize(),G));const K=R.insertOp(["tableSource",W.tableId],W);return v.push(K),b.params.actions=v.reduce((Fe,Se)=>a.JSONX.compose(Fe,Se),null),!!r.syncExecuteCommand(b.id,b.params)}},_o="doc.component.create-table-confirm",sn={id:"doc.operation.create-table",type:a.CommandType.COMMAND,handler:async o=>{const t=o.get(a.LocaleService),e=o.get(I.IConfirmService),n=o.get(a.ICommandService),i={rowCount:3,colCount:5},s=(r,c)=>{i.rowCount=r,i.colCount=c};return await e.open({id:_o,children:{label:{name:Ba,props:{handleRowColChange:s,tableCreateParams:i}}},width:400,title:{title:t.t("toolbar.table.insert")},onConfirm:()=>{n.executeCommand(Bo.id,i),e.close(_o)},onClose:()=>{e.close(_o)}}),!0}},$r=o=>{const e=Object.keys(a.PAGE_SIZE).find(n=>{const{width:i,height:s}=a.PAGE_SIZE[n];return o.width===i&&o.height===s});return e!=null?e:"A4"};function ec(o){const{hooks:t}=o,i=I.useDependency(a.IUniverInstanceService).getCurrentUnitOfType(a.UniverInstanceType.UNIVER_DOC).getDocumentStyle(),s=I.useDependency(a.LocaleService),[r,c]=w.useState(()=>{var d,u,m,h,g;return{paperSize:$r(i.pageSize),orientation:(d=i.pageOrient)!=null?d:a.PageOrientType.PORTRAIT,margins:{top:(u=i.marginTop)!=null?u:0,bottom:(m=i.marginBottom)!=null?m:0,left:(h=i.marginLeft)!=null?h:0,right:(g=i.marginRight)!=null?g:0}}});w.useEffect(()=>{t.beforeClose=()=>r,t.beforeConfirm=()=>r},[r]);const l=d=>{c(u=>({...u,paperSize:d}))},A=(d,u)=>{c(m=>({...m,margins:{...m.margins,[d]:u||0}}))};return P.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-4",children:[P.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white",children:s.t("page-settings.paper-size")}),P.jsx(J.Select,{value:r.paperSize,onChange:l,options:a.PAPER_TYPES.map(d=>({label:s.t(`page-settings.page-size.${d.toLocaleLowerCase()}`),value:d}))})]}),P.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white",children:s.t("page-settings.custom-paper-size")}),P.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-2.5",children:[P.jsxs("div",{className:"univer-flex univer-gap-2.5",children:[P.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:s.t("page-settings.top")}),P.jsx(J.InputNumber,{value:r.margins.top,onChange:d=>A("top",d)})]}),P.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:s.t("page-settings.bottom")}),P.jsx(J.InputNumber,{value:r.margins.bottom,onChange:d=>A("bottom",d)})]})]}),P.jsxs("div",{className:"univer-flex univer-gap-2.5",children:[P.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:s.t("page-settings.left")}),P.jsx(J.InputNumber,{value:r.margins.left,onChange:d=>A("left",d)})]}),P.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:s.t("page-settings.right")}),P.jsx(J.InputNumber,{value:r.margins.right,onChange:d=>A("right",d)})]})]})]})]})]})}const No="docs.component.page-setting",_a={id:"docs.command.page-setup",type:a.CommandType.COMMAND,handler:(o,t)=>{if(!t)return!1;const e=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService),i=e.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_DOC);if(!i)return!1;const{marginLeft:s,marginRight:r,marginBottom:c,marginTop:l,pageOrient:A,pageSize:d}=t,u=a.JSONX.getInstance(),m=i.getDocumentStyle(),{marginBottom:h,marginLeft:g,marginRight:p,marginTop:f,pageOrient:S,pageSize:E}=m,C=[];if(h===void 0){const v=u.insertOp(["documentStyle","marginBottom"],c);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","marginBottom"],h,c);v&&C.push(v)}if(g===void 0){const v=u.insertOp(["documentStyle","marginLeft"],s);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","marginLeft"],g,s);v&&C.push(v)}if(p===void 0){const v=u.insertOp(["documentStyle","marginRight"],r);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","marginRight"],p,r);v&&C.push(v)}if(f===void 0){const v=u.insertOp(["documentStyle","marginTop"],l);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","marginTop"],f,l);v&&C.push(v)}if(E===void 0){const v=u.insertOp(["documentStyle","pageSize"],d);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","pageSize"],E,d);v&&C.push(v)}if(S===void 0){const v=u.insertOp(["documentStyle","pageOrient"],A);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","pageOrient"],S,A);v&&C.push(v)}const T={id:D.RichTextEditingMutation.id,params:{unitId:i.getUnitId(),actions:[],textRanges:void 0}};return T.params.actions=C.reduce((v,O)=>a.JSONX.compose(v,O),null),!!n.syncExecuteCommand(T.id,T.params)}},Po={id:"docs.operation.open-page-setting",type:a.CommandType.OPERATION,handler:o=>{const t=o.get(I.IConfirmService),e=o.get(a.ICommandService),n=o.get(a.LocaleService),i=t.open({id:No,title:{label:n.t("page-settings.document-setting")},children:{label:No},width:528,onClose:()=>{i.dispose()},onConfirm:s=>{if(i.dispose(),!s)return;const r=a.PAGE_SIZE[s.paperSize];e.executeCommand(_a.id,{pageOrient:s.orientation,marginTop:s.margins.top,marginBottom:s.margins.bottom,marginLeft:s.margins.left,marginRight:s.margins.right,pageSize:r})}});return!0}};function tc(o){const t=o.get(a.IUniverInstanceService),e=o.get(_.IRenderManagerService);return new L.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(D.DocSkeletonManagerService).getViewModel().editAreaChange$.subscribe(A=>{n.next(A===_.DocumentEditArea.HEADER||A===_.DocumentEditArea.FOOTER)})});return()=>i.unsubscribe()})}function nc(o){const t=o.get(a.IUniverInstanceService),e=o.get(a.ICommandService);return new L.Observable(n=>{const i=e.onCommandExecuted(l=>{if(l.id===D.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)!==a.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!==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 oc(o){const t=o.get(D.DocSelectionManagerService),e=o.get(a.IUniverInstanceService);return new L.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: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 m=re(o,u.getUnitId());if(m==null){n.next(!0);return}if(m.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()=>i.unsubscribe()})}function te(o){const t=o.get(D.DocSelectionManagerService);return new L.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 ic(o){const t=o.get(a.ICommandService);return{id:De.id,type:I.MenuItemType.BUTTON,icon:"BoldIcon",title:"Set bold",tooltip:"toolbar.bold",activated$:new L.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const r=(c=s.ts)==null?void 0:c.bl;e.next(r===a.BooleanNumber.TRUE)},i=t.onCommandExecuted(s=>{const r=s.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),i.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function ac(o){const t=o.get(a.ICommandService);return{id:Be.id,type:I.MenuItemType.BUTTON,icon:"ItalicIcon",title:"Set italic",tooltip:"toolbar.italic",activated$:new L.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const r=(c=s.ts)==null?void 0:c.it;e.next(r===a.BooleanNumber.TRUE)},i=t.onCommandExecuted(s=>{const r=s.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),i.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function sc(o){const t=o.get(a.ICommandService);return{id:_e.id,type:I.MenuItemType.BUTTON,icon:"UnderlineIcon",title:"Set underline",tooltip:"toolbar.underline",activated$:new L.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const r=(c=s.ts)==null?void 0:c.ul;e.next((r==null?void 0:r.s)===a.BooleanNumber.TRUE)},i=t.onCommandExecuted(s=>{const r=s.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),i.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function rc(o){const t=o.get(a.ICommandService);return{id:Ne.id,type:I.MenuItemType.BUTTON,icon:"StrikethroughIcon",title:"Set strike through",tooltip:"toolbar.strikethrough",activated$:new L.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const r=(c=s.ts)==null?void 0:c.st;e.next((r==null?void 0:r.s)===a.BooleanNumber.TRUE)},i=t.onCommandExecuted(s=>{const r=s.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),i.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function cc(o){const t=o.get(a.ICommandService);return{id:ye.id,type:I.MenuItemType.BUTTON,icon:"SubscriptIcon",tooltip:"toolbar.subscript",activated$:new L.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const r=(c=s.ts)==null?void 0:c.va;e.next(r===a.BaselineOffset.SUBSCRIPT)},i=t.onCommandExecuted(s=>{const r=s.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),i.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function lc(o){const t=o.get(a.ICommandService);return{id:Pe.id,type:I.MenuItemType.BUTTON,icon:"SuperscriptIcon",tooltip:"toolbar.superscript",activated$:new L.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const r=(c=s.ts)==null?void 0:c.va;e.next(r===a.BaselineOffset.SUPERSCRIPT)},i=t.onCommandExecuted(s=>{const r=s.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),i.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function dc(o){const t=o.get(a.ICommandService);return{id:We.id,tooltip:"toolbar.font",type:I.MenuItemType.SELECTOR,label:I.FONT_FAMILY_COMPONENT,selections:I.FONT_FAMILY_LIST.map(e=>({label:{name:I.FONT_FAMILY_ITEM_COMPONENT},value:e.value})),value$:new L.Observable(e=>{const n=a.DEFAULT_STYLES.ff,i=()=>{var l;const r=Le(o);if(r==null){e.next(n);return}const c=(l=r.ts)==null?void 0:l.ff;e.next(c!=null?c:n)},s=t.onCommandExecuted(r=>{const c=r.id;(c===D.SetTextSelectionsOperation.id||c===We.id)&&i()});return i(),s.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function Ac(o){const t=o.get(a.ICommandService);return{id:ge.id,type:I.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:I.FONT_SIZE_COMPONENT,props:{min:1,max:400}},selections:I.FONT_SIZE_LIST,value$:new L.Observable(e=>{const n=a.DEFAULT_STYLES.fs,i=()=>{var l;const r=Le(o);if(r==null){e.next(n);return}const c=(l=r.ts)==null?void 0:l.fs;e.next(c!=null?c:n)},s=t.onCommandExecuted(r=>{const c=r.id;(c===D.SetTextSelectionsOperation.id||c===ge.id)&&i()});return i(),s.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function uc(o){const t=o.get(a.ICommandService);return{id:de.id,type:I.MenuItemType.SELECTOR,tooltip:"toolbar.heading.tooltip",label:{name:I.COMMON_LABEL_COMPONENT,props:{selections:I.HEADING_LIST}},selections:I.HEADING_LIST.map(e=>({label:{name:I.HEADING_ITEM_COMPONENT,props:{value:e.value,text:e.label}},value:e.value})),value$:new L.Observable(e=>{const n=a.NamedStyleType.NORMAL_TEXT,i=()=>{var l,A;const r=Ge(o);if(r==null){e.next(n);return}const c=(A=(l=r.paragraphStyle)==null?void 0:l.namedStyleType)!=null?A:n;e.next(c)},s=t.onCommandExecuted(r=>{const c=r.id;(c===D.SetTextSelectionsOperation.id||c===ge.id)&&i()});return i(),s.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function hc(o){const t=o.get(a.ICommandService),e=o.get(a.ThemeService);return{id:we.id,icon:"FontColorDoubleIcon",tooltip:"toolbar.textColor.main",type:I.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:I.COLOR_PICKER_COMPONENT,hoverable:!1,selectable:!1}}],value$:new L.Observable(n=>{const i=e.getColorFromTheme("gray.900"),s=t.onCommandExecuted(r=>{if(r.id===we.id){const c=r.params.value;n.next(c!=null?c:i)}});return n.next(i),s.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function gc(o){return{id:Jn.id,type:I.MenuItemType.BUTTON,icon:"HeaderFooterIcon",tooltip:"toolbar.headerFooter",hidden$:L.combineLatest(I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY),nc(o),(t,e)=>t||e)}}const mc="GridIcon",Na="doc.menu.table";function pc(o){return{id:Na,type:I.MenuItemType.SUBITEMS,icon:mc,tooltip:"toolbar.table.main",disabled$:oc(o),hidden$:L.combineLatest(I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY),tc(o),(t,e)=>t||e)}}function fc(o){return{id:sn.id,title:"toolbar.table.insert",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function Sc(o){const t=o.get(a.ICommandService);return{id:Ct.id,type:I.MenuItemType.BUTTON,icon:"LeftJustifyingIcon",tooltip:"toolbar.alignLeft",disabled$:te(o),activated$:new L.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===D.SetTextSelectionsOperation.id||s===me.id){const c=Ge(o);if(c==null)return;const l=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(l===a.HorizontalAlign.LEFT)}});return e.next(!1),n.dispose}),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Ic(o){const t=o.get(a.ICommandService);return{id:Tt.id,type:I.MenuItemType.BUTTON,icon:"HorizontallyIcon",tooltip:"toolbar.alignCenter",activated$:new L.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===D.SetTextSelectionsOperation.id||s===me.id){const c=Ge(o);if(c==null)return;const l=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(l===a.HorizontalAlign.CENTER)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function vc(o){const t=o.get(a.ICommandService);return{id:yt.id,type:I.MenuItemType.BUTTON,icon:"RightJustifyingIcon",tooltip:"toolbar.alignRight",activated$:new L.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===D.SetTextSelectionsOperation.id||s===me.id){const c=Ge(o);if(c==null)return;const l=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(l===a.HorizontalAlign.RIGHT)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Ec(o){const t=o.get(a.ICommandService);return{id:bt.id,type:I.MenuItemType.BUTTON,icon:"AlignTextBothIcon",tooltip:"toolbar.alignJustify",activated$:new L.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===D.SetTextSelectionsOperation.id||s===me.id){const c=Ge(o);if(c==null)return;const l=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(l===a.HorizontalAlign.JUSTIFIED)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Cc(o){return{id:St.id,type:I.MenuItemType.BUTTON,icon:"ReduceIcon",tooltip:"toolbar.horizontalLine",disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}const Rt=o=>new L.Observable(t=>{const e=o.get(a.IUniverInstanceService),n=o.get(D.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,m,h,g;const l=n.getDocRanges(),A=(d=l.find(p=>p.isActive))!=null?d:l[0];if(A){const p=c.getSelfOrHeaderFooterModel(A==null?void 0:A.segmentId),f=a.BuildTextUtils.range.getParagraphsInRange(A,(m=(u=p.getBody())==null?void 0:u.paragraphs)!=null?m:[],(g=(h=p.getBody())==null?void 0:h.dataStream)!=null?g:"");let S;if(f.every(E=>{var C;return S||(S=(C=E.bullet)==null?void 0:C.listType),E.bullet&&E.bullet.listType===S})){t.next(S);return}}t.next(void 0)}))});return()=>{s.unsubscribe(),i==null||i.unsubscribe()}});function Pa(o){return{id:ot.id,type:I.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:qi,hoverable:!1,selectable:!1},value$:Rt(o)}],icon:"OrderIcon",tooltip:"toolbar.order",hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC),disabled$:te(o),activated$:Rt(o).pipe(L.map(t=>!!(t&&t.indexOf("ORDER_LIST")===0)))}}function wa(o){return{id:nt.id,type:I.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:Ji,hoverable:!1,selectable:!1},value$:Rt(o)}],icon:"UnorderIcon",tooltip:"toolbar.unorder",disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC),activated$:Rt(o).pipe(L.map(t=>!!(t&&t.indexOf("BULLET_LIST")===0)))}}function Ua(o){return{id:Et.id,type:I.MenuItemType.BUTTON,icon:"TodoListDoubleIcon",tooltip:"toolbar.checklist",disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC),activated$:Rt(o).pipe(L.map(t=>!!(t&&t.indexOf("CHECK_LIST")===0)))}}function Tc(o){const t=o.get(a.ICommandService),e=o.get(a.IUniverInstanceService);return{id:Ot.id,type:I.MenuItemType.BUTTON,icon:"KeyboardIcon",tooltip:"toolbar.documentFlavor",hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY),activated$:new L.Observable(n=>{var r;const i=t.onCommandExecuted(c=>{var l;if(c.id===D.RichTextEditingMutation.id){const A=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);n.next(((l=A==null?void 0:A.getSnapshot())==null?void 0:l.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 yc(o){return{id:et.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColorDoubleIcon"}}function bc(o){const t=o.get(a.ICommandService),e=o.get(a.ThemeService);return{id:Ue.id,tooltip:"toolbar.fillColor.main",type:I.MenuItemType.BUTTON_SELECTOR,icon:"PaintBucketDoubleIcon",selections:[{label:{name:I.COLOR_PICKER_COMPONENT,hoverable:!1,selectable:!1}}],value$:new L.Observable(n=>{const i=e.getColorFromTheme("primary.600"),s=t.onCommandExecuted(r=>{if(r.id===Ue.id){const c=r.params.value;n.next(c!=null?c:i)}});return n.next(i),s.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function Le(o){var g,p,f,S;const t=o.get(a.IUniverInstanceService),e=o.get(D.DocSelectionManagerService),n=o.get(Te),i=t.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),s=e.getDocRanges(),r=(g=s.find(E=>E.isActive))!=null?g:s[0],c=n.getDefaultStyle(),l=(p=n.getStyleCache())!=null?p:{},A=Ge(o),d=(f=A==null?void 0:A.paragraphStyle)!=null&&f.namedStyleType?a.NAMED_STYLE_MAP[(S=A==null?void 0:A.paragraphStyle)==null?void 0:S.namedStyleType]:null;if(i==null||r==null)return{ts:{...c,...d,...l}};const{segmentId:u}=r,m=i.getSelfOrHeaderFooterModel(u).getBody();if(m==null)return{ts:{...c,...d,...l}};const h=Ra(m,r,{});return a.Tools.deleteNull(h),{ts:{...c,...d,...h,...l}}}function Ge(o){var d,u;const t=o.get(a.IUniverInstanceService),e=o.get(D.DocSelectionManagerService),n=t.getCurrentUniverDocInstance(),i=e.getDocRanges(),s=(d=i.find(m=>m.isActive))!=null?d:i[0];if(n==null||s==null)return;const{startOffset:r,segmentId:c}=s,l=(u=n.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:u.paragraphs;if(l==null)return;let A=-1;for(const m of l){const{startIndex:h}=m;if(r>A&&r<=h)return m;A=h}return null}function Oc(o){return{id:Po.id,type:I.MenuItemType.BUTTON,icon:"DocumentSettingIcon",tooltip:"toolbar.pageSetup",hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}const Rc={[a.NamedStyleType.HEADING_1]:Oo,[a.NamedStyleType.HEADING_2]:Ro,[a.NamedStyleType.HEADING_3]:Mo,[a.NamedStyleType.HEADING_4]:xo,[a.NamedStyleType.HEADING_5]:Do,[a.NamedStyleType.NORMAL_TEXT]:an,[a.NamedStyleType.TITLE]:xa,[a.NamedStyleType.SUBTITLE]:Da,[a.NamedStyleType.NAMED_STYLE_TYPE_UNSPECIFIED]:an},La={[a.NamedStyleType.HEADING_1]:{key:"H1Icon",component:Bi},[a.NamedStyleType.HEADING_2]:{key:"H2Icon",component:_i},[a.NamedStyleType.HEADING_3]:{key:"H3Icon",component:Ni},[a.NamedStyleType.HEADING_4]:{key:"H4Icon",component:Pi},[a.NamedStyleType.HEADING_5]:{key:"H5Icon",component:wi},[a.NamedStyleType.NORMAL_TEXT]:{key:"TextTypeIcon",component:ut},[a.NamedStyleType.TITLE]:{key:"TextTypeIcon",component:ut},[a.NamedStyleType.SUBTITLE]:{key:"TextTypeIcon",component:ut},[a.NamedStyleType.NAMED_STYLE_TYPE_UNSPECIFIED]:{key:"TextTypeIcon",component:ut}},Qe=o=>t=>{const e=t.get(a.ICommandService),n=t.get(I.ComponentManager),i=La[o];return n.get(i.key)||n.register(i.key,i.component),{id:Rc[o].id,type:I.MenuItemType.BUTTON,icon:i.key,tooltip:"toolbar.heading.tooltip",disabled$:te(t),hidden$:I.getMenuHiddenObservable(t,a.UniverInstanceType.UNIVER_DOC),activated$:new L.Observable(s=>{const r=a.NamedStyleType.NORMAL_TEXT,c=()=>{var u,m;const A=Ge(t);if(A==null){s.next(r===o);return}const d=(m=(u=A.paragraphStyle)==null?void 0:u.namedStyleType)!=null?m:r;s.next(d===o)},l=e.onCommandExecuted(A=>{const d=A.id;(d===D.SetTextSelectionsOperation.id||d===ge.id)&&c()});return c(),l.dispose})}},Mc=Qe(a.NamedStyleType.HEADING_1),xc=Qe(a.NamedStyleType.HEADING_2),Dc=Qe(a.NamedStyleType.HEADING_3),Bc=Qe(a.NamedStyleType.HEADING_4),_c=Qe(a.NamedStyleType.HEADING_5),Nc=Qe(a.NamedStyleType.NORMAL_TEXT);Qe(a.NamedStyleType.TITLE),Qe(a.NamedStyleType.SUBTITLE);const Pc=o=>({id:ho.id,type:I.MenuItemType.BUTTON,icon:"CopyDoubleIcon",title:"rightClick.copy"}),wc=o=>({id:go.id,type:I.MenuItemType.BUTTON,icon:"CutIcon",title:"rightClick.cut"}),Uc=o=>({id:so.id,type:I.MenuItemType.BUTTON,icon:"DeleteIcon",title:"rightClick.delete"}),Lc=o=>({id:Co.id,type:I.MenuItemType.BUTTON,icon:"UnorderIcon",title:"rightClick.bulletList"}),Qc=o=>({id:To.id,type:I.MenuItemType.BUTTON,icon:"OrderIcon",title:"rightClick.orderList"}),Fc=o=>({id:yo.id,type:I.MenuItemType.BUTTON,icon:"TodoListDoubleIcon",title:"rightClick.checkList"}),Hc=o=>({id:fo.id,type:I.MenuItemType.BUTTON,icon:"ReduceIcon",title:"toolbar.horizontalLine"}),Qa="doc.menu.insert-bellow";function kc(o){return{id:Qa,type:I.MenuItemType.SUBITEMS,title:"rightClick.insertBellow"}}const wo=4,Vc=(o,t)=>{const e=o.get(a.IUniverInstanceService).getUniverDocInstance(t.unitId),n=(e==null?void 0:e.zoomRatio)||1;return{...a.Tools.deepClone(t),zoomRatio:n}},he={id:"doc.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(o,t)=>{const e=o.get(a.IUniverInstanceService).getUniverDocInstance(t.unitId);if(!e)return!1;const n=e.getSnapshot();return n.settings==null?n.settings={zoomRatio:t.zoomRatio}:n.settings.zoomRatio=t.zoomRatio,!0}};var Wc=Object.getOwnPropertyDescriptor,Gc=(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},rn=(o,t)=>(e,n)=>t(e,n,o);function Fa(o,t){const e=Ha(o.left,o.top,t),n=Ha(o.right,o.bottom,t);return{left:e.x,top:e.y,right:n.x,bottom:n.y}}function Ha(o,t,e){const{scaleX:n,scaleY:i}=e.getAncestorScale(),s=e.getViewport(se.VIEW_MAIN);if(!s)return{x:o,y:t};const{viewportScrollX:r,viewportScrollY:c}=s,l=(o-r)*n,A=(t-c)*i;return{x:l,y:A}}function ka(o,t,e){const{scaleX:n,scaleY:i}=e.getAncestorScale(),s=e.getViewport(se.VIEW_MAIN);if(!s)return{x:o,y:t};const{viewportScrollX:r,viewportScrollY:c}=s,l=o/n+r,A=t/i+c;return{x:l,y:A}}const cn=(o,t)=>{const{scene:e,mainComponent:n,engine:i}=t,s=t.with(D.DocSkeletonManagerService).getSkeleton(),r=s.findNodePositionByCharIndex(o.startOffset,!0,o.segmentId,o.segmentPage),c=o.collapsed?o.startOffset:o.endOffset-1,l=s.findNodePositionByCharIndex(c,!0,o.segmentId,o.segmentPage),A=n;if(!l||!r)return;const d=A.getOffsetConfig(),{docsLeft:u,docsTop:m}=d,h=i.getCanvasElement(),g=h.getBoundingClientRect(),p=_.pxToNum(h.style.width),{top:f,left:S,width:E}=g,C=E/p,{scaleX:T,scaleY:R}=e.getAncestorScale(),v=new ve(d,s),{borderBoxPointGroup:O}=v.getRangePointData(r,l);return Ht(O).map(N=>Fa(N,e)).map(N=>({left:(N.left+u*T)*C+S,right:(N.right+u*T)*C+S,top:(N.top+m*R)*C+f,bottom:(N.bottom+m*R)*C+f}))};y.DocCanvasPopManagerService=class extends a.Disposable{constructor(t,e,n,i){super(),this._globalPopupManagerService=t,this._renderManagerService=e,this._univerInstanceService=n,this._commandService=i}_createRectPositionObserver(t,e){const n=()=>{const{scene:l,engine:A}=e,d=typeof t=="function"?t():t,u=A.getCanvasElement(),m=u.getBoundingClientRect(),h=_.pxToNum(u.style.width),g=Fa(d,l),{top:p,left:f,width:S}=m,E=S/h;return{left:g.left*E+f,right:g.right*E+f,top:g.top*E+p,bottom:g.bottom*E+p}},i=n(),s=new L.BehaviorSubject(i),r=new a.DisposableCollection;r.add(this._commandService.onCommandExecuted(l=>{if(l.id===he.id||l.id===D.RichTextEditingMutation.id){const A=n();A&&s.next(A)}}));const c=e.scene.getViewport(se.VIEW_MAIN);return c&&r.add(c.onScrollAfter$.subscribeEvent(()=>{s.next(n())})),{position:i,position$:s,disposable:r}}_createObjectPositionObserver(t,e){const n=()=>{const{left:i,top:s,width:r,height:c}=t;return{left:i,right:i+r,top:s,bottom:s+c}};return this._createRectPositionObserver(n,e)}_createRangePositionObserver(t,e){var c;const n=(c=cn(t,e))!=null?c:[],i=new L.BehaviorSubject(n),s=new a.DisposableCollection;s.add(this._commandService.onCommandExecuted(l=>{if((l.id===he.id||l.id===D.RichTextEditingMutation.id)&&l.params.unitId===e.unitId){const d=cn(t,e);d&&i.next(d)}}));const r=e.scene.getViewport(se.VIEW_MAIN);return r&&s.add(r.onScrollAfter$.subscribeEvent(()=>{const l=cn(t,e);l&&i.next(l)})),{positions:n,positions$:i,disposable:s}}attachPopupToRect(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._createRectPositionObserver(t,i),l=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:s,anchorRect$:r,canvasElement:i.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(l),r.complete(),c.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==l}}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),l=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:s,anchorRect$:r,canvasElement:i.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(l),r.complete(),c.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==l}}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:l,positions$:A,disposable:d}=this._createRangePositionObserver(t,c),u=A.pipe(L.map(h=>s.includes("top")?h[0]:h[h.length-1])),m=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:["top","bottom","horizontal"].some(h=>s.includes(h))&&l.length>1&&r!=null?r:s,canvasElement:c.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(m),A.complete(),d.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==m}}},y.DocCanvasPopManagerService=Gc([rn(0,a.Inject(I.ICanvasPopupService)),rn(1,_.IRenderManagerService),rn(2,a.IUniverInstanceService),rn(3,a.ICommandService)],y.DocCanvasPopManagerService);var jc=Object.getOwnPropertyDescriptor,Xc=(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},Kc=(o,t)=>(e,n)=>t(e,n,o);const zc=(o,t,e,n)=>{var m,h,g,p,f;const i=e.findNodePositionByCharIndex(o.startOffset,!0,o.segmentId,n),s=e.getSkeletonData();let r=o.endOffset-1;if(o.segmentId){const S=(f=Array.from((h=(m=s==null?void 0:s.skeFooters.get(o.segmentId))==null?void 0:m.values())!=null?h:[])[0])!=null?f:Array.from((p=(g=s==null?void 0:s.skeHeaders.get(o.segmentId))==null?void 0:g.values())!=null?p:[])[0];S&&(r=Math.min(S.ed,r))}const c=e.findNodePositionByCharIndex(r,!0,o.segmentId,n);if(!c||!i)return;const l=t.getOffsetConfig(),A=new ve(l,e),{borderBoxPointGroup:d}=A.getRangePointData(i,c);return Ht(d).map(S=>({top:S.top+l.docsTop-wo,bottom:S.bottom+l.docsTop+wo,left:S.left+l.docsLeft,right:S.right+l.docsLeft}))},Va=(o,t,e,n)=>{const i=[];for(const s of o){const r=s.top;for(const c of s.columns){const l=c.left,A=s.colCount===1?n:c.width;let d=null;for(const u of c.lines){const m=u.paragraphIndex;if(u.paragraphStart){d&&(i.push(d),d=null);const h={top:t+r+u.top,left:e+l,right:e+l+A,bottom:t+r+u.top+u.lineHeight};d={paragraphStart:u.st,paragraphEnd:m,startIndex:m,rect:h,fisrtLine:{top:t+r+u.top+u.marginTop+u.paddingTop,left:e+l,right:e+l+A,bottom:t+r+u.top+u.marginTop+u.paddingTop+u.contentHeight}}}else d&&d.startIndex===m&&(d.rect.bottom=t+r+u.top+u.lineHeight)}d&&i.push(d)}}return i},Yc=(o,t,e,n=-1)=>{const i=e.findPositionByGlyph(o,n);if(!i)return;const s=t.getOffsetConfig(),r={...i,isBack:!0},c=new ve(s,e),{borderBoxPointGroup:l}=c.getRangePointData(r,r),d=Ht(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}};function je(o,t,e){const{left:n,right:i,top:s,bottom:r}=e;return o>=n&&o<=i&&t>=s&&t<=r}y.DocEventManagerService=class extends a.Disposable{constructor(e,n){super();B(this,"_hoverCustomRanges$",new L.BehaviorSubject([]));B(this,"hoverCustomRanges$",this._hoverCustomRanges$.pipe(L.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))));B(this,"_clickCustomRanges$",new L.Subject);B(this,"clickCustomRanges$",this._clickCustomRanges$.asObservable());B(this,"_hoverBullet$",new L.Subject);B(this,"hoverBullet$",this._hoverBullet$.pipe(L.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))));B(this,"_clickBullet$",new L.Subject);B(this,"clickBullets$",this._clickBullet$.asObservable());B(this,"_hoverParagraph$",new L.BehaviorSubject(null));B(this,"hoverParagraph$",this._hoverParagraph$.pipe(L.distinctUntilChanged((e,n)=>(e==null?void 0:e.startIndex)===(n==null?void 0:n.startIndex)&&(e==null?void 0:e.segmentId)===(n==null?void 0:n.segmentId)&&(e==null?void 0:e.pageIndex)===(n==null?void 0:n.pageIndex))));B(this,"hoverParagraphRealTime$",this._hoverParagraph$.asObservable());B(this,"_hoverParagraphLeft$",new L.BehaviorSubject(null));B(this,"hoverParagraphLeft$",this._hoverParagraphLeft$.pipe(L.distinctUntilChanged((e,n)=>(e==null?void 0:e.startIndex)===(n==null?void 0:n.startIndex)&&(e==null?void 0:e.segmentId)===(n==null?void 0:n.segmentId)&&(e==null?void 0:e.pageIndex)===(n==null?void 0:n.pageIndex))));B(this,"hoverParagraphLeftRealTime$",this._hoverParagraphLeft$.asObservable());B(this,"_hoverTableCell$",new L.Subject);B(this,"hoverTableCell$",this._hoverTableCell$.pipe(L.distinctUntilChanged((e,n)=>(e==null?void 0:e.rowIndex)===(n==null?void 0:n.rowIndex)&&(e==null?void 0:e.colIndex)===(n==null?void 0:n.colIndex)&&(e==null?void 0:e.tableId)===(n==null?void 0:n.tableId)&&(e==null?void 0:e.pageIndex)===(n==null?void 0:n.pageIndex))));B(this,"hoverTableCellRealTime$",this._hoverTableCell$.asObservable());B(this,"_hoverTable$",new L.Subject);B(this,"hoverTable$",this._hoverTable$.pipe(L.distinctUntilChanged((e,n)=>(e==null?void 0:e.tableId)===(n==null?void 0:n.tableId)&&(e==null?void 0:e.pageIndex)===(n==null?void 0:n.pageIndex))));B(this,"hoverTableRealTime$",this._hoverTable$.asObservable());B(this,"_customRangeDirty",!0);B(this,"_bulletDirty",!0);B(this,"_paragraphDirty",!0);B(this,"_customRangeBounds",[]);B(this,"_bulletBounds",[]);B(this,"_paragraphBounds",new Map);B(this,"_paragraphLeftBounds",[]);B(this,"_tableParagraphBounds",new Map);B(this,"_segmentParagraphBounds",new Map);B(this,"_tableCellBounds",new Map);B(this,"_tableBounds",new Map);this._context=e,this._docSkeletonManagerService=n,this._initResetDirty(),this._initEvents(),this._initPointer()}get hoverParagraph(){return this._hoverParagraph$.value}get hoverParagraphLeft(){return this._hoverParagraphLeft$.value}get _skeleton(){return this._docSkeletonManagerService.getSkeleton()}get _documents(){return this._context.mainComponent}dispose(){this._hoverCustomRanges$.complete(),this._clickCustomRanges$.complete(),super.dispose()}_initPointer(){let e=_.CURSOR_TYPE.TEXT;this.disposeWithMe(this.hoverCustomRanges$.subscribe(n=>{n.length?(e=this._context.scene.getCursor(),this._context.scene.setCursor(_.CURSOR_TYPE.POINTER)):this._context.scene.setCursor(e)}))}_initResetDirty(){this.disposeWithMe(this._skeleton.dirty$.subscribe(()=>{this._customRangeDirty=!0,this._bulletDirty=!0,this._paragraphDirty=!0})),this.disposeWithMe(a.fromEventSubject(this._context.engine.onTransformChange$).pipe(L.filter(e=>e.type===_.TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize)).subscribe(()=>{this._customRangeDirty=!0,this._bulletDirty=!0,this._paragraphDirty=!0}))}_initEvents(){this.disposeWithMe(a.fromEventSubject(this._context.scene.onPointerMove$).pipe(L.throttleTime(30)).subscribe(i=>{if(i.buttons>0){this._hoverBullet$.next(null),this._hoverCustomRanges$.next([]),this._hoverParagraph$.next(null),this._hoverParagraphLeft$.next(null),this._hoverTableCell$.next(null),this._hoverTable$.next(null);return}const{x:s,y:r}=ka(i.offsetX,i.offsetY,this._context.scene);this._hoverCustomRanges$.next(this._calcActiveRanges({x:s,y:r})),this._hoverParagraph$.next(this._calcActiveParagraph({x:s,y:r})),this._hoverParagraphLeft$.next(this._calcActiveParagraphLeft({x:s,y:r})),this._hoverBullet$.next(this._calcActiveBullet({x:s,y:r}))})),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(L.switchMap(i=>n.pipe(L.take(1),L.map(s=>({down:i,up:s})))),L.filter(({down:i,up:s})=>i.target===s.target&&s.timeStamp-i.timeStamp<300)).subscribe(({down:i})=>{if(i.button===2)return;const s=ka(i.offsetX,i.offsetY,this._context.scene),r=this._calcActiveRanges(s);r.length&&this._clickCustomRanges$.next(r.pop());const c=this._calcActiveBullet(s);c&&this._clickBullet$.next(c)}))}_buildCustomRangeBoundsBySegment(e,n=-1){var r,c,l;const i=(l=(c=(r=this._context.unit.getSelfOrHeaderFooterModel(e))==null?void 0:r.getBody())==null?void 0:c.customRanges)!=null?l:[],s=[];return i.forEach(A=>{const d={startOffset:A.startIndex,endOffset:A.endIndex+1,segmentId:e},u=zc(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((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{x:n,y:i}=e;return this._customRangeBounds.filter(r=>r.rects.some(c=>je(n,i,c))).map(r=>({segmentId:r.segmentId,range:r.customRange,segmentPageIndex:r.segmentPageIndex,rects:r.rects}))}_buildBulletBoundsBySegment(e,n=-1){var A,d,u,m,h;const i=(A=this._context.unit.getSelfOrHeaderFooterModel(e))==null?void 0:A.getBody(),s=((d=i==null?void 0:i.paragraphs)!=null?d:[]).filter(g=>g.bullet&&g.bullet.listType.indexOf("CHECK_LIST")===0),r=[],c=this._skeleton.getSkeletonData();if(!c)return r;const l=g=>{var p,f,S;for(const E of g){const C=[...E.sections];if(E.skeTables){const T=Array.from(E.skeTables.values());C.push(...T.map(R=>R.rows.map(v=>v.cells.map(O=>O.sections))).flat(4))}for(const T of C)for(const R of T.columns)for(const v of R.lines)if(v.paragraphStart){const O=s.find(M=>M.startIndex===v.paragraphIndex);if(O){const M=v,b=(S=(f=(p=M==null?void 0:M.divides)==null?void 0:p[0])==null?void 0:f.glyphGroup)==null?void 0:S[0];if(!b)continue;const N=Yc(b,this._documents,this._skeleton,n);if(!N)continue;r.push({rect:N,segmentId:e,segmentPageIndex:n,paragraph:O})}}}return r};if(e){const g=(h=(u=c.skeFooters.get(e))==null?void 0:u.values())!=null?h:(m=c.skeHeaders.get(e))==null?void 0:m.values();return g?l(Array.from(g)):r}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,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{x:n,y:i}=e;return this._bulletBounds.find(r=>je(n,i,r.rect))}_buildParagraphBoundsBySegment(e){var c,l,A;const n=this._skeleton.getSkeletonData(),s=this._documents.getOffsetConfig();if(!n)return null;const r=d=>{const u=new Map,m=(h,g,p,f)=>{Va(h.sections,p,f,h.pageWidth-h.marginLeft-h.marginRight).forEach(E=>{if(!u.has(E.startIndex))u.set(E.startIndex,{rect:E.rect,paragraphStart:E.paragraphStart,paragraphEnd:E.paragraphEnd,startIndex:E.startIndex,rects:[E.rect],pageIndex:g,segmentId:e,firstLine:E.fisrtLine});else{const C=u.get(E.startIndex);C&&(C.rect.bottom=E.rect.bottom,C.rects.push(E.rect))}})};for(let h=0;h<d.length;h++){const g=d[h],p=((g.pageHeight===1/0?0:g.pageHeight)+s.pageMarginTop)*h+g.marginTop+s.docsTop,f=g.marginLeft+s.docsLeft;g.skeTables&&Array.from(g.skeTables.values()).forEach(S=>{const E=S.left+f,C=S.top+p,T=E+S.width,R=C+S.height,v=S.tableId;this._tableBounds.set(v,{rect:{left:E,top:C,right:T,bottom:R},pageIndex:h,tableId:v}),S.rows.forEach((O,M)=>{O.cells.forEach((b,N)=>{const x=((g.pageHeight===1/0?0:g.pageHeight)+s.pageMarginTop)*h+S.top+s.docsTop+g.marginTop+O.top+b.marginTop,U=S.left+s.docsLeft+g.marginLeft+b.left+b.marginLeft,F=Va(b.sections,x,U,b.pageWidth-b.marginLeft-b.marginRight);let V=this._tableParagraphBounds.get(v);V||(V=[],this._tableParagraphBounds.set(v,V)),V.push(...F.map(Q=>({rect:Q.rect,paragraphStart:Q.paragraphStart,paragraphEnd:Q.paragraphEnd,startIndex:Q.startIndex,pageIndex:h,segmentId:e,rowIndex:M,colIndex:N,firstLine:Q.fisrtLine,tableId:v})));let H=this._tableCellBounds.get(v);H||(H=[],this._tableCellBounds.set(v,H)),H.push({rect:{top:x,left:U,right:U+b.pageWidth-b.marginLeft-b.marginRight,bottom:x+b.pageHeight-b.marginBottom-b.marginTop},pageIndex:h,rowIndex:M,colIndex:N,tableId:v})})})}),m(g,h,p,f)}return u};if(e){const d=(A=(c=n.skeFooters.get(e))==null?void 0:c.values())!=null?A:(l=n.skeHeaders.get(e))==null?void 0:l.values();return d?r(Array.from(d)):null}return r(n.pages)}_buildParagraphBounds(){var n,i;if(!this._paragraphDirty)return;this._paragraphDirty=!1,this._tableParagraphBounds=new Map,this._tableCellBounds=new Map,this._tableBounds=new Map,this._paragraphBounds=(n=this._buildParagraphBoundsBySegment())!=null?n:new Map,this._paragraphLeftBounds=Array.from(this._paragraphBounds.values()).map(s=>({...s,rect:{left:s.rect.left-60,right:s.rect.left,top:s.rect.top,bottom:s.rect.bottom}}));const e=s=>{var r;this._segmentParagraphBounds.set(s,(r=this._buildParagraphBoundsBySegment(s))!=null?r:new Map)};(i=this._skeleton.getSkeletonData())==null||i.pages.forEach(s=>{s.headerId&&e(s.headerId),s.footerId&&e(s.footerId)})}_calcActiveParagraph(e){var c,l;this._buildParagraphBounds();const{x:n,y:i}=e,s=Array.from(this._tableBounds.values()).find(A=>je(n,i,A.rect));if(this._hoverTable$.next(s),s){const A=(c=this._tableCellBounds.get(s.tableId))==null?void 0:c.find(m=>je(n,i,m.rect));if(this._hoverTableCell$.next(A),!A)return null;const d=(l=this._tableParagraphBounds.get(A.tableId))==null?void 0:l.filter(m=>m.colIndex===A.colIndex&&m.rowIndex===A.rowIndex),u=d==null?void 0:d.find(m=>je(n,i,m.rect));return u&&{...u,rects:[u.rect]}}let r;for(const A of this._paragraphBounds){const d=A[1];if(d.rects.some(u=>je(n,i,u))){r=d;break}}return r}_calcActiveParagraphLeft(e){this._buildParagraphBounds();const{x:n,y:i}=e;return this._paragraphLeftBounds.find(r=>je(n,i,r.rect))}get paragraphBounds(){return this._buildParagraphBounds(),this._paragraphBounds}findParagraphBoundByIndex(e){this._buildParagraphBounds();const n=this._paragraphBounds.get(e);return n||Array.from(this._tableParagraphBounds.values()).flat().find(s=>s.startIndex===e)}},y.DocEventManagerService=Xc([Kc(1,a.Inject(D.DocSkeletonManagerService))],y.DocEventManagerService);const qc=[ge.id,De.id,Be.id,_e.id,Ne.id,ye.id,Pe.id,we.id,Ue.id];function Jc(o){const{avaliableMenus:t=qc}=o,e=I.useDependency(I.IMenuManagerService),[n,i]=w.useState([]);return w.useEffect(()=>{function s(){const c=e.getFlatMenuByPositionKey(I.MenuManagerPosition.RIBBON),l=[];for(const A of t){const d=c.find(u=>u.key===A);d&&l.push(d)}i(l)}s();const r=e.menuChanged$.subscribe(s);return()=>{r.unsubscribe()}},[e]),P.jsx("div",{className:J.clsx("univer-box-border univer-flex univer-rounded univer-bg-white univer-py-1.5 univer-shadow-sm dark:!univer-border-gray-700 dark:!univer-bg-gray-900",J.borderClassName),children:n.map(s=>s.item&&P.jsx("div",{className:"univer-flex univer-flex-nowrap univer-gap-2 univer-px-2",children:P.jsx(I.ToolbarItem,{...s.item},s.key)},s.key))})}var Zc=Object.getOwnPropertyDescriptor,$c=(o,t,e,n)=>{for(var i=n>1?void 0:n?Zc(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Mt=(o,t)=>(e,n)=>t(e,n,o);const Wa="univer.doc.float-menu";function el(o,t){if(o==null||t==null)return!1;const{glyph:e,...n}=o,{glyph:i,...s}=t;return a.deepCompare(n,s)}const tl=[a.DataStreamTreeTokenType.CUSTOM_BLOCK,a.DataStreamTreeTokenType.PARAGRAPH];let ln=class extends a.Disposable{constructor(t,e,n,i,s,r){super();B(this,"_floatMenu",null);this._context=t,this._docSelectionManagerService=e,this._docCanvasPopManagerService=n,this._componentManager=i,this._univerInstanceService=s,this._docSelectionRenderService=r,!a.isInternalEditorID(this._context.unitId)&&(this._registerFloatMenu(),this._initSelectionChange(),this.disposeWithMe(()=>{this._hideFloatMenu()}))}get floatMenu(){return this._floatMenu}_registerFloatMenu(){this.disposeWithMe(this._componentManager.register(Wa,Jc))}_initSelectionChange(){this.disposeWithMe(this._docSelectionRenderService.onSelectionStart$.subscribe(()=>{this._hideFloatMenu()})),this.disposeWithMe(this._docSelectionManagerService.textSelection$.subscribe(t=>{var s,r;const{unitId:e,textRanges:n}=t;if(e!==this._context.unitId)return;const i=n.length>0&&n.find(c=>!c.collapsed);if(i){if(i.startOffset===((s=this._floatMenu)==null?void 0:s.start)&&i.endOffset===((r=this._floatMenu)==null?void 0:r.end))return;this._hideFloatMenu(),this._showFloatMenu(e,i);return}this._hideFloatMenu()}))}_hideFloatMenu(){var t;(t=this._floatMenu)==null||t.disposable.dispose(),this._floatMenu=null}_showFloatMenu(t,e){var r,c,l;const n=this._univerInstanceService.getUnit(t,a.UniverInstanceType.UNIVER_DOC);if(!n||n.getDisabled())return;const i=(r=n.getBody())==null?void 0:r.dataStream[e.startOffset];if(e.endOffset-e.startOffset===1&&i&&tl.includes(i))return;const s=(l=(c=n.getBody())==null?void 0:c.customRanges)==null?void 0:l.filter(A=>A.wholeEntity);if(!(s!=null&&s.some(A=>A.startIndex===e.startOffset&&A.endIndex===e.endOffset-1)))return this._floatMenu={disposable:this._docCanvasPopManagerService.attachPopupToRange(e,{componentKey:Wa,direction:e.direction==="backward"||el(e.startNodePosition,e.endNodePosition)?"top-center":"bottom-center",offset:[0,4]},t),start:e.startOffset,end:e.endOffset},a.toDisposable(()=>this._hideFloatMenu())}};ln=$c([Mt(1,a.Inject(D.DocSelectionManagerService)),Mt(2,a.Inject(y.DocCanvasPopManagerService)),Mt(3,a.Inject(I.ComponentManager)),Mt(4,a.Inject(a.IUniverInstanceService)),Mt(5,a.Inject(y.DocSelectionRenderService))],ln);var nl=Object.getOwnPropertyDescriptor,ol=(o,t,e,n)=>{for(var i=n>1?void 0:n?nl(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},xt=(o,t)=>(e,n)=>t(e,n,o);let dn=class extends a.Disposable{constructor(t,e,n,i,s,r){super();B(this,"_paragrahMenu",null);this._context=t,this._docSelectionManagerService=e,this._docEventManagerService=n,this._docPopupManagerService=i,this._docSkeletonManagerService=s,this._floatMenuService=r,!a.isInternalEditorID(this._context.unitId)&&this._init()}get activeParagraph(){var t;return(t=this._paragrahMenu)==null?void 0:t.paragraph}_isCursorInActiveParagraph(){if(!this._paragrahMenu)return!1;const t=this._docSelectionManagerService.getActiveTextRange();return!(!(t!=null&&t.collapsed)||!(t!=null&&t.collapsed)||t.startOffset<this._paragrahMenu.paragraph.paragraphStart||t.startOffset>this._paragrahMenu.paragraph.paragraphEnd)}setParagraphMenuActive(t){this._paragrahMenu&&(this._paragrahMenu.active=t,this._isCursorInActiveParagraph()||this._docSelectionManagerService.replaceDocRanges([{startOffset:this._paragrahMenu.paragraph.paragraphStart,endOffset:this._paragrahMenu.paragraph.paragraphStart}]))}_init(){const t=n=>{var s;if(this._docSkeletonManagerService.getViewModel().getEditArea()===_.DocumentEditArea.BODY&&!this._floatMenuService.floatMenu&&!this._context.unit.getDisabled()){if((s=this._paragrahMenu)!=null&&s.active)return;if(n){this.showParagraphMenu(n);return}}this.hideParagraphMenu(!0)};this.disposeWithMe(L.combineLatest([this._docEventManagerService.hoverParagraphRealTime$,this._docEventManagerService.hoverParagraphLeft$]).pipe(L.throttleTime(16)).subscribe(([n,i])=>{const s=n!=null?n:i;t(s)}));let e=0;this.disposeWithMe(this._context.scene.getViewport(se.VIEW_MAIN).onScrollAfter$.subscribeEvent(n=>{e!==n.scrollY&&(e=n.scrollY,this.hideParagraphMenu(!0))})),this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe(()=>{this.hideParagraphMenu(!0)}))}showParagraphMenu(t){var l,A,d;if(((l=this._paragrahMenu)==null?void 0:l.paragraph.startIndex)===t.startIndex)return;this.hideParagraphMenu(!0);const e=(d=(A=this._context.unit.getBody())==null?void 0:A.dataStream)!=null?d:"",n=t?e.slice(t.paragraphStart,t.paragraphEnd):"";if(n==="\b"||n==="")return;const c=this._docPopupManagerService.attachPopupToRect(t.firstLine,{componentKey:"doc.paragraph.menu",direction:"left-center",onClickOutside:()=>{this._docSelectionManagerService.textSelection$.pipe(L.first()).subscribe(()=>{this._isCursorInActiveParagraph()||this.hideParagraphMenu(!0)})},zIndex:101},this._context.unitId);this._paragrahMenu={paragraph:t,disposable:c,active:!1}}hideParagraphMenu(t=!1){this._paragrahMenu&&(this._paragrahMenu.disposable.canDispose()||t)&&(this._paragrahMenu.disposable.dispose(),this._paragrahMenu=null)}};dn=ol([xt(1,a.Inject(D.DocSelectionManagerService)),xt(2,a.Inject(y.DocEventManagerService)),xt(3,a.Inject(y.DocCanvasPopManagerService)),xt(4,a.Inject(D.DocSkeletonManagerService)),xt(5,a.Inject(ln))],dn);const il=({popup:o})=>{var v,O;const[t,e]=w.useState(!1),n=w.useRef(null),i=I.useDependency(a.ICommandService),s=I.useDependency(I.ILayoutService),r=w.useRef(null),c=w.useRef(!1),l=I.useDependency(_.IRenderManagerService),A=I.useDependency(a.IUniverInstanceService),d=l.getRenderById(o.unitId),u=A.getUnit(o.unitId,a.UniverInstanceType.UNIVER_DOC),m=d==null?void 0:d.with(dn),h=d==null?void 0:d.with(y.DocEventManagerService),g=I.useObservable(h==null?void 0:h.hoverParagraph$),p=I.useObservable(h==null?void 0:h.hoverParagraphLeft$),f=(v=g!=null?g:p)==null?void 0:v.startIndex,S=w.useMemo(()=>{var M,b;return(b=(M=u==null?void 0:u.getBody())==null?void 0:M.paragraphs)==null?void 0:b.find(N=>N.startIndex===f)},[u,g]),E=(O=S==null?void 0:S.paragraphStyle)==null?void 0:O.namedStyleType,C=La[E!=null?E:a.NamedStyleType.NORMAL_TEXT],T=w.useMemo(()=>new L.BehaviorSubject({left:0,right:0,top:0,bottom:0}),[]),R=()=>{e(!1),m==null||m.hideParagraphMenu(!0)};return P.jsxs(P.Fragment,{children:[P.jsxs("div",{"data-u-comp":"paragraph-menu",ref:r,className:J.clsx("univer-mr-1 univer-inline-flex univer-h-7 univer-cursor-pointer univer-items-center univer-gap-1 univer-rounded-full univer-px-2.5 univer-py-0 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-600",J.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-700":t,"univer-bg-white dark:!univer-bg-gray-700":!t}),onMouseEnter:M=>{var N,x,U,F,V,H;(N=o.onPointerEnter)==null||N.call(o,M),c.current=!0;const b=(x=r.current)==null?void 0:x.getBoundingClientRect();T.next({left:((U=b==null?void 0:b.left)!=null?U:0)-4,right:(F=b==null?void 0:b.right)!=null?F:0,top:(V=b==null?void 0:b.top)!=null?V:0,bottom:(H=b==null?void 0:b.bottom)!=null?H:0})},onMouseLeave:()=>{c.current=!1},onClick:()=>{e(!0),m==null||m.setParagraphMenuActive(!0)},children:[P.jsx(C.component,{className:"univer-size-4 univer-text-gray-900 dark:!univer-text-white"}),P.jsx(Di,{className:"univer-size-3 univer-text-gray-600 dark:!univer-text-gray-200"})]}),t&&P.jsx(I.RectPopup,{portal:!0,mask:!0,maskZIndex:100,anchorRect$:T,direction:"left",onMaskClick:R,children:P.jsx("section",{ref:n,onMouseEnter:M=>{var b;(b=o.onPointerEnter)==null||b.call(o,M),c.current=!0},onMouseLeave:()=>{c.current=!1},children:P.jsx(I.DesktopMenu,{style:{width:212},menuType:I.ContextMenuPosition.PARAGRAPH,onOptionSelect:M=>{const{label:b,commandId:N,value:x}=M;i&&i.executeCommand(N!=null?N:b,{value:x}),s.focus(),R()}})})})]})},Xe={id:"doc.command.tab",type:a.CommandType.COMMAND,async handler(o,t){const n=o.get(y.DocAutoFormatService).onAutoFormat(Xe.id,t);return(await a.sequenceExecuteAsync(n,o.get(a.ICommandService))).result}},Dt={id:"doc.command.after-space",type:a.CommandType.COMMAND,async handler(o){const e=o.get(y.DocAutoFormatService).onAutoFormat(Dt.id);return(await a.sequenceExecuteAsync(e,o.get(a.ICommandService))).result}},it={id:"doc.command.enter",type:a.CommandType.COMMAND,async handler(o){const e=o.get(y.DocAutoFormatService).onAutoFormat(it.id);return(await a.sequenceExecuteAsync(e,o.get(a.ICommandService))).result}};function ee(o){return o.getContextValue(a.FOCUSING_DOC)&&o.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!o.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function al(o){return o.getContextValue(a.FOCUSING_DOC)&&o.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!o.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}const sl={id:Xe.id,binding:I.KeyCode.TAB,preconditions:ee},rl={id:Xe.id,binding:I.KeyCode.TAB|I.MetaKeys.SHIFT,preconditions:ee,staticParameters:{shift:!0}},cl={id:De.id,binding:I.KeyCode.B|I.MetaKeys.CTRL_COMMAND,preconditions:ee},ll={id:Be.id,binding:I.KeyCode.I|I.MetaKeys.CTRL_COMMAND,preconditions:ee},dl={id:_e.id,binding:I.KeyCode.U|I.MetaKeys.CTRL_COMMAND,preconditions:ee},Al={id:Ne.id,binding:I.KeyCode.X|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ee},ul={id:ye.id,binding:I.KeyCode.COMMA|I.MetaKeys.CTRL_COMMAND,preconditions:ee},hl={id:Pe.id,binding:I.KeyCode.PERIOD|I.MetaKeys.CTRL_COMMAND,preconditions:ee},gl={id:Ct.id,binding:I.KeyCode.L|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:ee},ml={id:yt.id,binding:I.KeyCode.R|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:ee},pl={id:Tt.id,binding:I.KeyCode.E|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:ee},fl={id:bt.id,binding:I.KeyCode.J|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:ee},Sl={id:ot.id,binding:I.KeyCode.Digit7|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:ee},Il={id:nt.id,binding:I.KeyCode.Digit8|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:ee},An="docs-ui.config",Ga={layout:{docContainerConfig:ai,toolbarConfig:ii}},vl=[50,80,100,130,150,170,200,400],El=[10,400];function Cl(){const o=I.useDependency(a.ICommandService),t=I.useDependency(a.IUniverInstanceService),e=w.useMemo(()=>t.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC),[]),n=I.useObservable(e),i=w.useCallback(()=>{var A,d;if(!n)return 100;const l=((d=(A=n.getSettings())==null?void 0:A.zoomRatio)!=null?d:1)*100;return Math.round(l)},[n]),[s,r]=w.useState(()=>i());w.useEffect(()=>(r(i()),o.onCommandExecuted(A=>{if(A.id===he.id){const d=i();r(d)}}).dispose),[o,i]);function c(l){if(r(l),n==null)return;const A=l/100;o.executeCommand(he.id,{unitId:n.getUnitId(),zoomRatio:A})}return P.jsx(I.Slider,{min:El[0],value:s,shortcuts:vl,onChange:c})}function Tl(o){return P.jsx("section",{className:"univer-flex univer-flex-shrink-0 univer-justify-end",children:P.jsx(Cl,{})})}function yl(){var i,s,r;const o=I.useDependency(a.IUniverInstanceService),t=I.useConfigValue(An),e=I.useObservable(()=>o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),n=(r=(s=(i=t==null?void 0:t.layout)==null?void 0:i.docContainerConfig)==null?void 0:s.footer)!=null?r:!0;return e?null:n&&P.jsxs("div",{className:"univer-box-border univer-flex univer-items-center univer-justify-between univer-px-5 univer-py-1.5",children:[P.jsx("div",{}),P.jsx(Tl,{})]})}const bl="univer-overflow-hidden univer-font-[500] univer-truncate univer-h-[24px] univer-mb-2 univer-leading-[24px] univer-ellipsis univer-cursor-pointer",Ol="univer-text-base univer-font-semibold",Rl="univer-text-sm univer-font-semibold",Ml="univer-text-sm",xl=w.forwardRef((o,t)=>{const{menus:e,onClick:n,className:i,style:s,mode:r,maxHeight:c,activeId:l,open:A,onOpenChange:d,maxWidth:u,wrapperClass:m,wrapperStyle:h,iconClass:g,iconStyle:p}=o,f=r==="side-bar",S=w.useRef(null),E=w.useRef(e);E.current=e;const C=w.useMemo(()=>({scrollTo:T=>{var x;if(!E.current||E.current.findIndex(U=>U.id===T)===-1||!S.current)return;const v=document.getElementById(`univer-side-menu-${T}`);if(!v)return;const O=v.offsetTop,M=S.current.clientHeight,b=S.current.scrollHeight-M,N=Math.max(0,Math.min(O-M/2+v.clientHeight/2,b));(x=S.current)==null||x.scrollTo({behavior:"smooth",top:N})}}),[]);return w.useImperativeHandle(t,()=>C),w.useEffect(()=>{l&&C.scrollTo(l)},[l,C]),P.jsxs("div",{className:J.clsx("univer-relative",m),style:h,children:[P.jsx("div",{onClick:()=>d==null?void 0:d(!A),className:J.clsx("univer-absolute univer-left-5 univer-top-4 univer-z-[100] univer-flex univer-h-8 univer-w-8 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-full univer-bg-white univer-text-gray-800 univer-shadow-sm dark:!univer-bg-gray-600 dark:!univer-text-gray-200",g),style:p,children:A?P.jsx(Li,{}):P.jsx(Oi,{})}),P.jsx("div",{className:J.clsx(i,`
|
|
65
|
+
`," ");let s=this._umdToHtml.convert(t);if(t.length===1&&e){s=s.replace(/(<[a-z]+)/,(m,h)=>`${h} data-copy-id="${n}"`);const d=t[0],u={body:d.body};if((l=(c=d.body)==null?void 0:c.customBlocks)!=null&&l.length){u.drawings={};for(const m of d.body.customBlocks){const{blockId:h}=m,g=(A=d.drawings)==null?void 0:A[h];if(g){const p=a.Tools.generateRandomId(6);m.blockId=p,u.drawings[p]={...a.Tools.deepClone(g),drawingId:p}}}}ro.set(n,u)}return this._clipboardInterfaceService.write(i,s)}addClipboardHook(t){return this._clipboardHooks.push(t),a.toDisposable(()=>{const e=this._clipboardHooks.indexOf(t);e>-1&&this._clipboardHooks.splice(e,1)})}_getDocumentBodyInRanges(t,e){var d;const n=this._univerInstanceService.getCurrentUniverDocInstance(),i=e!=null?e:this._docSelectionManagerService.getDocRanges(),s=[];let r=!0;if(n==null||i.length===0)return;const c=i[0].segmentId,l=(d=n==null?void 0:n.getSelfOrHeaderFooterModel(c))==null?void 0:d.getBody(),A=n.getSnapshot();if(l!=null){for(const u of i){const{startOffset:m,endOffset:h,collapsed:g,rangeType:p}=u;if(g||m==null||h==null)continue;if(p===a.DOC_RANGE_TYPE.RECT){r=!1;const{spanEntireRow:E}=u;let C;C=ga(l,m,h),s.push(C);continue}const f={startOffset:m,endOffset:h},S=n.getSelfOrHeaderFooterModel(c).sliceBody(f.startOffset,f.endOffset,t);S!=null&&s.push(S)}return{newSnapshotList:s.map(u=>({...A,body:u})),needCache:r,snapshot:A,ranges:i}}}async _genDocDataFromClipboardItems(t){try{let e="",n="";const i=[];for(const s of t)for(const r of s.types)switch(r){case I.PLAIN_TEXT_CLIPBOARD_MIME_TYPE:{n=await s.getType(r).then(c=>c&&c.text());break}case I.HTML_CLIPBOARD_MIME_TYPE:{e=await s.getType(r).then(c=>c&&c.text());break}case I.FILE__BMP_CLIPBOARD_MIME_TYPE:case I.FILE__JPEG_CLIPBOARD_MIME_TYPE:case I.FILE__WEBP_CLIPBOARD_MIME_TYPE:case I.FILE_PNG_CLIPBOARD_MIME_TYPE:{const c=await s.getType(r),l=new File([c],`pasted_image.${r.split("/")[1]}`,{type:r});i.push(l);break}}return!e&&!n&&i.length&&(e=await this._createImagePasteHtml(i)),this._genDocDataFromHtmlAndText(e,n)}catch(e){return Promise.reject(e)}}_genDocDataFromHtmlAndText(t,e,n){if(!t){if(e)return{body:a.BuildTextUtils.transform.fromPlainText(e)};throw new Error("[DocClipboardService] html and text cannot be both empty!")}const i=Fr(t);if(i){const r=ro.get(i);if(r)return r}if(!n){const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);n=(r==null?void 0:r.getUnitId())||""}const s=this._htmlToUDM.convert(t,{unitId:n});return i&&ro.set(i,s),s}async _createImagePasteHtml(t){var c,l;const e={id:"",documentStyle:{},body:{dataStream:"",customBlocks:[]},drawings:{}},n=async A=>{const d=new FileReader;return new Promise(u=>{d.onloadend=function(){u({source:d.result,imageSourceType:xn.ImageSourceType.BASE64})},d.readAsDataURL(A)})},i=A=>{const d=new Image,u=500;return new Promise(m=>{d.src=typeof A=="string"?A:URL.createObjectURL(A),d.onload=()=>{const h=Math.min(u,d.naturalWidth),g=d.naturalHeight/d.naturalWidth;m({width:h,height:h*g})}})},s=(l=(c=this._clipboardHooks.find(A=>A.onBeforePasteImage))==null?void 0:c.onBeforePasteImage)!=null?l:n;return await Promise.all(t.map(async(A,d)=>{var S;const u=await s(A);if(!u)return Promise.resolve();const{width:m=100,height:h=100}=await i(A),g=`paste_image_id_${d}`,p=e.body,f=e.drawings;p.dataStream+="\b",(S=p.customBlocks)==null||S.push({startIndex:d,blockId:g}),f[g]={drawingId:g,unitId:"",subUnitId:"",imageSourceType:u.imageSourceType,title:"",source:u.source,description:"",layoutType:a.PositionedObjectLayoutType.INLINE,drawingType:a.DrawingTypeEnum.DRAWING_IMAGE,transform:{width:m,height:h,angle:0},docTransform:{angle:0,size:{width:m,height:h},positionH:{relativeFrom:a.ObjectRelativeFromH.CHARACTER,posOffset:0},positionV:{relativeFrom:a.ObjectRelativeFromV.LINE,posOffset:0}}}})),this._umdToHtml.convert([e])}};Ao=Xr([pt(0,a.IUniverInstanceService),pt(1,a.ILogService),pt(2,a.ICommandService),pt(3,I.IClipboardInterfaceService),pt(4,a.Inject(D.DocSelectionManagerService))],Ao);function Zt(o){return o.getContextValue(a.FOCUSING_DOC)||o.getContextValue(a.EDITOR_ACTIVATED)}const uo=999,ft={id:I.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:uo,preconditions:Zt,handler:async o=>o.get(xe).copy()},ho={id:"doc.command.copy-current-paragraph",type:a.CommandType.COMMAND,handler:async o=>{const t=o.get(xe),e=gt(o);return e?t.copy(a.SliceBodyType.copy,[{startOffset:e.paragraphStart,endOffset:e.paragraphEnd+1,collapsed:!1}]):!1}},$t={id:I.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:uo,preconditions:Zt,handler:async o=>o.get(xe).cut()},go={id:"doc.command.cut-current-paragraph",type:a.CommandType.COMMAND,handler:async o=>{const t=o.get(xe),e=gt(o);return e?t.cut([{startOffset:e.paragraphStart,endOffset:e.paragraphEnd+1,collapsed:!1,rangeType:a.DOC_RANGE_TYPE.TEXT}]):!1}},en={id:I.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:uo,preconditions:Zt,handler:async o=>{const t=o.get(xe),n=await o.get(I.IClipboardInterfaceService).read();return n.length===0?!1:t.paste(n)}};var Kr=Object.getOwnPropertyDescriptor,zr=(o,t,e,n)=>{for(var i=n>1?void 0:n?Kr(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},mo=(o,t)=>(e,n)=>t(e,n,o);const Yr=11,qr=9,tn={ff:"Arial",fs:Yr};let Te=class extends a.Disposable{constructor(t,e,n){super();B(this,"_cacheStyle",null);this._textSelectionManagerService=t,this._univerInstanceService=e,this._renderManagerService=n,this._init()}_init(){this._listenDocRangeChange()}_listenDocRangeChange(){this.disposeWithMe(this._textSelectionManagerService.textSelection$.subscribe(()=>{this._clearStyleCache()}))}getStyleCache(){return this._cacheStyle}getDefaultStyle(){var r;const t=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(t==null)return{...tn};const e=t==null?void 0:t.getUnitId(),n=(r=this._renderManagerService.getRenderById(e))==null?void 0:r.with(D.DocSkeletonManagerService),i=n==null?void 0:n.getViewModel();return i==null?{...tn}:i.getEditArea()===_.DocumentEditArea.BODY?{...tn}:{...tn,fs:qr}}setStyleCache(t){this._cacheStyle={...this._cacheStyle,...t}}_clearStyleCache(){this._cacheStyle=null}};Te=zr([mo(0,a.Inject(D.DocSelectionManagerService)),mo(1,a.IUniverInstanceService),mo(2,_.IRenderManagerService)],Te);function po(o,t,e){const n=[];for(let i=0,s=o.length;i<s;i++)o[i]===a.DataStreamTreeTokenType.PARAGRAPH&&n.push({startIndex:i});if(t)for(const i of n)t.bullet&&(i.bullet=a.Tools.deepClone(t.bullet)),t.paragraphStyle&&(i.paragraphStyle=a.Tools.deepClone(t.paragraphStyle),delete i.paragraphStyle.borderBottom,t.paragraphStyle.headingId&&(i.paragraphStyle.headingId=a.generateRandomId(6)));if(e)for(const i of n)i.paragraphStyle||(i.paragraphStyle={}),i.paragraphStyle.borderBottom=e;return n}const nn={id:"doc.command.break-line",type:a.CommandType.COMMAND,handler:(o,t)=>{var Q,X,j,k,W;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),s=o.get(Te),r=(Q=t==null?void 0:t.textRange)!=null?Q:e.getActiveTextRange(),c=e.getRectRanges();if(r==null)return!1;if(c&&c.length){const{startOffset:G}=r;return e.replaceDocRanges([{startOffset:G,endOffset:G}]),!0}const{horizontalLine:l}=t!=null?t:{},{segmentId:A}=r,d=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(A!=null?A:"").getBody();if(d==null||u==null)return!1;const m=d.getUnitId(),{startOffset:h,endOffset:g}=r,f=((X=u.paragraphs)!=null?X:[]).find(G=>G.startIndex>=h);if(!f)return!1;const S=h===f.startIndex,E=f.startIndex,C=s.getDefaultStyle(),T=s.getStyleCache(),R=Lt(u,g,C,T),v={dataStream:a.DataStreamTreeTokenType.PARAGRAPH,paragraphs:po(a.DataStreamTreeTokenType.PARAGRAPH,f,l),textRuns:[{st:0,ed:1,ts:{...R.ts}}]};if(d==null)return!1;const O=e.getActiveTextRange();if(u==null)return!1;const{collapsed:M}=r,b=v.dataStream.length,N=[{startOffset:h+b,endOffset:h+b,style:O==null?void 0:O.style,collapsed:M}],x={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:N,debounce:!0}},U=new a.TextX,F=a.JSONX.getInstance();if(M)h>0&&U.push({t:a.TextXActionType.RETAIN,len:h}),U.push({t:a.TextXActionType.INSERT,body:v,len:v.dataStream.length});else{const G=a.BuildTextUtils.selection.delete([r],u,0,v);U.push(...G)}(((j=f.bullet)==null?void 0:j.listType)===a.PresetListType.CHECK_LIST_CHECKED||(k=f.paragraphStyle)!=null&&k.headingId)&&(r.endOffset<E&&U.push({t:a.TextXActionType.RETAIN,len:E-r.endOffset}),U.push({t:a.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...f,paragraphStyle:{...f.paragraphStyle,...S?{headingId:void 0,namedStyleType:void 0}:null},startIndex:0,bullet:(W=f.paragraphStyle)!=null&&W.headingId?void 0:{...f.bullet,listType:a.PresetListType.CHECK_LIST}}]},coverType:a.UpdateDocsAttributeType.REPLACE})),x.params.textRanges=[{startOffset:h+b,endOffset:h+b,collapsed:M}];const V=Z(d,A);return x.params.actions=F.editOp(U.serialize(),V),!!i.syncExecuteCommand(x.id,x.params)}},St={id:"doc.command.horizontal-line",type:a.CommandType.COMMAND,handler:(o,t)=>o.get(a.ICommandService).syncExecuteCommand(nn.id,{horizontalLine:{padding:5,color:{rgb:"#CDD0D8"},width:1,dashStyle:a.DashStyleType.SOLID},textRange:t==null?void 0:t.insertRange})},fo={id:"doc.command.insert-horizontal-line-bellow",type:a.CommandType.COMMAND,handler:o=>{const t=o.get(a.ICommandService),e=gt(o);return e?t.syncExecuteCommand(St.id,{insertRange:{startOffset:e.startIndex+1,endOffset:e.startIndex+1}}):!1}};function ue(o,t,e){return e.executeCommand(be.id,{preCommandId:o,...t!=null?t:{}})}const ma="doc.command.set-inline-format-bold",De={id:ma,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(ma,t,e)}},pa="doc.command.set-inline-format-italic",Be={id:pa,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(pa,t,e)}},fa="doc.command.set-inline-format-underline",_e={id:fa,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(fa,t,e)}},Sa="doc.command.set-inline-format-strikethrough",Ne={id:Sa,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Sa,t,e)}},Ia="doc.command.set-inline-format-subscript",ye={id:Ia,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Ia,t,e)}},va="doc.command.set-inline-format-superscript",Pe={id:va,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(va,t,e)}},Ea="doc.command.set-inline-format-fontsize",ge={id:Ea,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Ea,t,e)}},Ca="doc.command.set-inline-format-font-family",We={id:Ca,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Ca,t,e)}},Ta="doc.command.set-inline-format-text-color",we={id:Ta,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Ta,t,e)}},ya="doc.command.set-inline-format-text-background-color",Ue={id:ya,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(ya,t,e)}},ba="doc.command.reset-inline-format-text-background-color",et={id:ba,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(ba,t,e)}},So={[De.id]:"bl",[Be.id]:"it",[_e.id]:"ul",[Ne.id]:"st",[ge.id]:"fs",[We.id]:"ff",[we.id]:"cl",[Ue.id]:"bg",[et.id]:"bg",[ye.id]:"va",[Pe.id]:"va"},be={id:"doc.command.set-inline-format",type:a.CommandType.COMMAND,handler:async(o,t)=>{var R;const{value:e,preCommandId:n}=t,i=o.get(a.ICommandService),s=o.get(D.DocSelectionManagerService),r=o.get(a.IUniverInstanceService),c=o.get(Te),l=s.getDocRanges(),A=(R=l.find(v=>v.isActive))!=null?R:l[0];if(l.length===0)return!1;const{segmentId:d}=l[0],u=r.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(u==null)return!1;const m=u.getSelfOrHeaderFooterModel(d).getBody();if(m==null)return!1;const h=u.getUnitId();let g;switch(n){case De.id:case Be.id:case _e.id:case Ne.id:case ye.id:case Pe.id:{const v=c.getDefaultStyle(),O=Ra(m,A,v);g=Zr(O,n);break}case ge.id:case We.id:{g=e;break}case we.id:case Ue.id:{g={rgb:e};break}case et.id:{g={rgb:null};break}default:throw new Error(`Unknown command: ${n} in handleInlineFormat`)}const p={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:l}},f=new a.TextX,S=a.JSONX.getInstance(),E=new a.MemoryCursor;E.reset();for(const v of l){let{startOffset:O,endOffset:M,rangeType:b}=v;if(O==null||M==null)continue;if(b===a.DOC_RANGE_TYPE.RECT&&(O=O-1),O===M){const U=c.getStyleCache(),F=So[n];c.setStyleCache({[F]:(U==null?void 0:U[F])!==void 0?Oa(U,F,n):g});continue}const N={dataStream:"",textRuns:[{st:0,ed:M-O,ts:{[So[n]]:g}}]},x=O-E.cursor;x!==0&&f.push({t:a.TextXActionType.RETAIN,len:x}),f.push({t:a.TextXActionType.RETAIN,body:N,len:M-O}),E.reset(),E.moveCursor(M)}const C=Z(u,d);return p.params.actions=S.editOp(f.serialize(),C),!!i.syncExecuteCommand(p.id,p.params)}};function Jr(o){return o!==null&&typeof o=="object"}function Oa(o,t,e){if(/bl|it/.test(t))return(o==null?void 0:o[t])===a.BooleanNumber.TRUE?a.BooleanNumber.FALSE:a.BooleanNumber.TRUE;if(/ul|st/.test(t))return Jr(o==null?void 0:o[t])&&(o==null?void 0:o[t]).s===a.BooleanNumber.TRUE?{s:a.BooleanNumber.FALSE}:{s:a.BooleanNumber.TRUE};if(/va/.test(t))return e===ye.id?(o==null?void 0:o[t])===a.BaselineOffset.SUBSCRIPT?a.BaselineOffset.NORMAL:a.BaselineOffset.SUBSCRIPT:(o==null?void 0:o[t])===a.BaselineOffset.SUPERSCRIPT?a.BaselineOffset.NORMAL:a.BaselineOffset.SUPERSCRIPT}function Ra(o,t,e){var d,u,m,h,g,p,f,S,E,C,T,R,v,O;const{startOffset:n,endOffset:i,collapsed:s}=t;if(s){const M=(d=o.textRuns)!=null?d:[];let b=null;for(let N=M.length-1;N>=0;N--){const x=M[N];if(x.st<n&&n<=x.ed){b=x;break}}return b!=null&&b.ts?{...e,...b.ts}:e}const{textRuns:r=[]}=a.getBodySlice(o,n,i),c=a.Tools.deepClone(e),l=r.map(M=>{var b;return(b=M==null?void 0:M.ts)==null?void 0:b.fs}).filter(Boolean);c.fs=c.fs?Math.max(c.fs,...l):l.length?Math.max(...l):void 0,c.fs=!c.fs||Number.isNaN(c.fs)?void 0:c.fs,c.ff=(h=(m=(u=r.find(M=>{var b;return((b=M.ts)==null?void 0:b.ff)!=null}))==null?void 0:u.ts)==null?void 0:m.ff)!=null?h:c.ff,c.it=r.length&&r.every(M=>{var b;return((b=M.ts)==null?void 0:b.it)===a.BooleanNumber.TRUE})?a.BooleanNumber.TRUE:a.BooleanNumber.FALSE,c.bl=r.length&&r.every(M=>{var b;return((b=M.ts)==null?void 0:b.bl)===a.BooleanNumber.TRUE})?a.BooleanNumber.TRUE:a.BooleanNumber.FALSE,c.ul=r.length&&r.every(M=>{var b,N;return((N=(b=M.ts)==null?void 0:b.ul)==null?void 0:N.s)===a.BooleanNumber.TRUE})?(g=r[0].ts)==null?void 0:g.ul:c.ul,c.st=r.length&&r.every(M=>{var b,N;return((N=(b=M.ts)==null?void 0:b.st)==null?void 0:N.s)===a.BooleanNumber.TRUE})?(p=r[0].ts)==null?void 0:p.st:c.st,c.bg=(E=(S=(f=r.find(M=>{var b;return((b=M.ts)==null?void 0:b.bg)!=null}))==null?void 0:f.ts)==null?void 0:S.bg)!=null?E:c.bg,c.cl=(R=(T=(C=r.find(M=>{var b;return((b=M.ts)==null?void 0:b.cl)!=null}))==null?void 0:C.ts)==null?void 0:T.cl)!=null?R:c.cl;const A=r.filter(M=>{var b;return((b=M==null?void 0:M.ts)==null?void 0:b.va)!=null});if(A.length>0&&A.length===r.length){const M=(v=A[0].ts)==null?void 0:v.va;let b=!0;for(let N=1;N<A.length;N++)if(((O=A[N].ts)==null?void 0:O.va)!==M){b=!1;break}b&&(c.va=M)}return c}function Zr(o,t){const e=So[t];return Oa(o,e,t)}const tt={id:"doc.command.list-operation",type:a.CommandType.COMMAND,handler:(o,t)=>{var T,R,v,O,M,b;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),s=t.listType,r=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),c=(R=(T=t.docRange)!=null?T:e.getDocRanges())!=null?R:[];if(r==null||c.length===0)return!1;const l=c[0].segmentId,A=r.getSelfOrHeaderFooterModel(l),d=(O=(v=A.getBody())==null?void 0:v.paragraphs)!=null?O:[],u=(b=(M=A.getBody())==null?void 0:M.dataStream)!=null?b:"";if(!d.length)return!1;const m=a.BuildTextUtils.range.getParagraphsInRanges(c,d,u),h=r.getUnitId(),g={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:c,isEditing:!1}};new a.MemoryCursor().reset();const f=a.BuildTextUtils.paragraph.bullet.switch({paragraphs:m,listType:s,document:r,segmentId:l}),S=a.JSONX.getInstance(),E=Z(r,l);return g.params.actions=S.editOp(f.serialize(),E),!!i.syncExecuteCommand(g.id,g.params)}},It={id:"doc.command.change-list-type",type:a.CommandType.COMMAND,handler:(o,t)=>{var C,T,R,v,O;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),{listType:s}=t,r=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),c=(C=t.docRange)!=null?C:e.getDocRanges();if(r==null||c==null||!c.length)return!1;const{segmentId:l}=c[0],A=r.getSelfOrHeaderFooterModel(l),d=(R=(T=A.getBody())==null?void 0:T.paragraphs)!=null?R:[],u=(O=(v=A.getBody())==null?void 0:v.dataStream)!=null?O:"";if(!d.length)return!1;const m=a.BuildTextUtils.range.getParagraphsInRanges(c,d,u),h=r.getUnitId(),g=a.BuildTextUtils.paragraph.bullet.set({paragraphs:m,listType:s,segmentId:l,document:r});if(!g)return!1;const p=a.JSONX.getInstance(),f={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:c,isEditing:!1}},S=Z(r,l);return f.params.actions=p.editOp(g.serialize(),S),!!i.syncExecuteCommand(f.id,f.params)}};var vt=(o=>(o[o.increase=1]="increase",o[o.decrease=-1]="decrease",o))(vt||{});const on={id:"doc.command.change-list-nesting-level",type:a.CommandType.COMMAND,handler:(o,t)=>{var T,R,v,O,M;if(!t)return!1;const{type:e}=t,n=o.get(D.DocSelectionManagerService),i=o.get(a.IUniverInstanceService),s=o.get(a.ICommandService),r=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),c=n.getActiveTextRange();if(r==null||c==null)return!1;const{segmentId:l}=c,A=(T=n.getDocRanges())!=null?T:[],d=r.getSelfOrHeaderFooterModel(l),u=(v=(R=d.getBody())==null?void 0:R.paragraphs)!=null?v:[],m=(M=(O=d.getBody())==null?void 0:O.dataStream)!=null?M:"";if(!u.length)return!1;const h=a.BuildTextUtils.range.getParagraphsInRange(c,u,m),g=r.getUnitId(),p=a.JSONX.getInstance(),f=a.BuildTextUtils.paragraph.bullet.changeNestLevel({paragraphs:h,type:e,segmentId:l,document:r}),S={id:D.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:A,isEditing:!1}},E=Z(r,l);return S.params.actions=p.editOp(f.serialize(),E),!!s.syncExecuteCommand(S.id,S.params)}},nt={id:"doc.command.bullet-list",type:a.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(a.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(It.id,{listType:t.value,docRange:t.docRange}):e.syncExecuteCommand(tt.id,{listType:a.PresetListType.BULLET_LIST,docRange:t==null?void 0:t.docRange})}},Et={id:"doc.command.check-list",type:a.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(a.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(It.id,{listType:t.value,docRange:t.docRange}):e.syncExecuteCommand(tt.id,{listType:a.PresetListType.CHECK_LIST,docRange:t==null?void 0:t.docRange})}},Io={id:"doc.command.toggle-check-list",type:a.CommandType.COMMAND,handler:(o,t)=>{var p;if(!t)return!1;const e=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService),{index:i,segmentId:s,textRanges:r}=t,c=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(c==null||((p=c.getSelfOrHeaderFooterModel(s).getBody())==null?void 0:p.paragraphs)==null)return!1;const A=c.getUnitId(),d={id:D.RichTextEditingMutation.id,params:{unitId:A,actions:[],textRanges:r!=null?r:[],segmentId:s,isEditing:!1}},u=a.BuildTextUtils.paragraph.bullet.toggleChecklist({document:c,paragraphIndex:i,segmentId:s});if(!u)return!1;const m=a.JSONX.getInstance(),h=Z(c,s);return d.params.actions=m.editOp(u.serialize(),h),!!n.syncExecuteCommand(d.id,d.params)}},ot={id:"doc.command.order-list",type:a.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(a.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(It.id,{listType:t.value}):e.syncExecuteCommand(tt.id,{listType:a.PresetListType.ORDER_LIST})}},vo={id:"doc.command.quick-list",type:a.CommandType.COMMAND,handler(o,t){var x,U,F;if(!t)return!1;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),s=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),r=e.getActiveTextRange();if(s==null||r==null)return!1;const{segmentId:c,startOffset:l}=r,{listType:A,paragraph:d}=t,{paragraphStart:u,paragraphEnd:m}=d,h=new a.TextX,g=a.JSONX.getInstance(),{paragraphStyle:p={}}=d,S=(a.PRESET_LIST_TYPE[A].nestingLevel[0].paragraphProperties||{}).textStyle;let C=a.Tools.generateRandomId(6);const T=(U=(x=s.getBody())==null?void 0:x.paragraphs)!=null?U:[],R=T.findIndex(V=>V.startIndex===d.startIndex),v=T[R-1],O=T[R+1];v&&v.bullet&&v.bullet.listType.indexOf(A)===0?C=v.bullet.listId:O&&O.bullet&&O.bullet.listType.indexOf(A)===0&&(C=O.bullet.listId);const M={id:D.RichTextEditingMutation.id,params:{unitId:s.getUnitId(),actions:[],textRanges:[{startOffset:u,endOffset:u,collapsed:!0}],isEditing:!1}};h.push({t:a.TextXActionType.RETAIN,len:u}),h.push({t:a.TextXActionType.DELETE,len:l-u}),m>l&&h.push({t:a.TextXActionType.RETAIN,len:m-l}),h.push({t:a.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{startIndex:0,paragraphStyle:{...p,textStyle:{...p.textStyle,...S},indentFirstLine:void 0},bullet:{...(F=d.bullet)!=null?F:{nestingLevel:0,textStyle:{fs:20}},listType:A,listId:C}}]}});const b=Z(s,c);return M.params.actions=g.editOp(h.serialize(),b),!!i.syncExecuteCommand(M.id,M.params)}};function Eo(o,t){var d,u;const e=o.get(a.ICommandService),n=gt(o);if(!n)return!1;const i=o.get(a.IUniverInstanceService).getCurrentUnitOfType(a.UniverInstanceType.UNIVER_DOC);if(!i)return!1;const s=a.BuildTextUtils.selection.replace({doc:i,selection:{startOffset:n.startIndex+1,endOffset:n.startIndex+1,collapsed:!0},body:{dataStream:"\r",paragraphs:[{startIndex:0,paragraphStyle:{...n.paragraphStyle},bullet:{listType:t,listId:((d=n.bullet)==null?void 0:d.listType)===t?n.bullet.listId:a.Tools.generateRandomId(6),nestingLevel:((u=n.bullet)==null?void 0:u.listType)===t?n.bullet.nestingLevel:0}}]}});if(!s)return!1;const r={id:D.RichTextEditingMutation.id,params:{unitId:i.getUnitId(),actions:[],textRanges:[{startOffset:n.startIndex+1,endOffset:n.startIndex+1,collapsed:!0}],isEditing:!1}},c=a.JSONX.getInstance(),l=Z(i);return r.params.actions=c.editOp(s.serialize(),l),!!e.syncExecuteCommand(r.id,r.params)}const Co={id:"doc.command.insert-bullet-list-bellow",type:a.CommandType.COMMAND,handler:o=>Eo(o,a.PresetListType.BULLET_LIST)},To={id:"doc.command.insert-order-list-bellow",type:a.CommandType.COMMAND,handler:o=>Eo(o,a.PresetListType.ORDER_LIST)},yo={id:"doc.command.insert-check-list-bellow",type:a.CommandType.COMMAND,handler:o=>Eo(o,a.PresetListType.CHECK_LIST)},de={id:"doc.command.set-paragraph-named-style",type:a.CommandType.COMMAND,handler(o,t){var g;if(!t)return!1;const n=o.get(a.IUniverInstanceService).getCurrentUnitOfType(a.UniverInstanceType.UNIVER_DOC);if(!n)return!1;const i=n.getUnitId(),s=o.get(D.DocSelectionManagerService),r=(g=t.textRanges)!=null?g:s.getTextRanges({unitId:i,subUnitId:i});if(!(r!=null&&r.length))return!1;const c=r[0].segmentId,l=a.BuildTextUtils.paragraph.style.set({document:n.getSelfOrHeaderFooterModel(c),textRanges:r,style:{namedStyleType:t.value,headingId:!t.value||t.value===a.NamedStyleType.NORMAL_TEXT?void 0:a.generateRandomId(6),spaceAbove:void 0,spaceBelow:void 0,lineSpacing:void 0},paragraphTextRun:{}}),A={id:D.RichTextEditingMutation.id,params:{actions:[],textRanges:r,unitId:i,segmentId:c}},d=a.JSONX.getInstance(),u=Z(n,c);return A.params.actions=d.editOp(l.serialize(),u),!!o.get(a.ICommandService).syncExecuteCommand(A.id,A.params)}},Ma={id:"doc.command.quick-heading",type:a.CommandType.COMMAND,handler(o,t){var R,v,O,M;if(!t)return!1;const{value:e}=t,n=o.get(D.DocSelectionManagerService),i=o.get(a.IUniverInstanceService),s=o.get(a.ICommandService),r=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),c=n.getActiveTextRange();if(r==null||c==null||!c.collapsed)return!1;const{segmentId:l,startOffset:A}=c,d=r.getSelfOrHeaderFooterModel(l),u=(v=(R=d.getBody())==null?void 0:R.paragraphs)!=null?v:[],m=(M=(O=d.getBody())==null?void 0:O.dataStream)!=null?M:"",h=a.BuildTextUtils.paragraph.util.getParagraphsInRange(c,u,m)[0];if(!h)return!1;const{paragraphStart:g}=h,p=new a.TextX,f=a.JSONX.getInstance(),{paragraphStyle:S={}}=h,E={id:D.RichTextEditingMutation.id,params:{unitId:r.getUnitId(),actions:[],textRanges:[{startOffset:g,endOffset:g,collapsed:!0}],isEditing:!1}};p.push({t:a.TextXActionType.RETAIN,len:g}),a.BuildTextUtils.paragraph.style.set({textRanges:[c],document:r,style:{...S,headingId:a.generateRandomId(6),namedStyleType:e},cursor:A,deleteLen:A-g,textX:p,paragraphTextRun:{}});const C=Z(r,l);return E.params.actions=f.editOp(p.serialize(),C),!!s.syncExecuteCommand(E.id,E.params)}},bo={"#":a.NamedStyleType.HEADING_1,"##":a.NamedStyleType.HEADING_2,"###":a.NamedStyleType.HEADING_3,"####":a.NamedStyleType.HEADING_4,"#####":a.NamedStyleType.HEADING_5},Oo={id:"doc.command.h1-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(de.id,{value:a.NamedStyleType.HEADING_1})},Ro={id:"doc.command.h2-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(de.id,{value:a.NamedStyleType.HEADING_2})},Mo={id:"doc.command.h3-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(de.id,{value:a.NamedStyleType.HEADING_3})},xo={id:"doc.command.h4-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(de.id,{value:a.NamedStyleType.HEADING_4})},Do={id:"doc.command.h5-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(de.id,{value:a.NamedStyleType.HEADING_5})},an={id:"doc.command.normal-text-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(de.id,{value:a.NamedStyleType.NORMAL_TEXT})},xa={id:"doc.command.title",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(de.id,{value:a.NamedStyleType.TITLE})},Da={id:"doc.command.subtitle-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(de.id,{value:a.NamedStyleType.SUBTITLE})},me={id:"doc.command.align-action",type:a.CommandType.COMMAND,handler:(o,t)=>{var R,v,O,M;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),{alignType:s}=t,r=n.getCurrentUniverDocInstance();if(r==null)return!1;const c=e.getDocRanges();if(c.length===0)return!1;const l=c[0].segmentId,A=r.getSelfOrHeaderFooterModel(l),d=(v=(R=A.getBody())==null?void 0:R.paragraphs)!=null?v:[],u=(M=(O=A.getBody())==null?void 0:O.dataStream)!=null?M:"";if(d==null)return!1;const m=a.BuildTextUtils.range.getParagraphsInRanges(c,d,u),h=r.getUnitId(),g=m.every(b=>{var N;return((N=b.paragraphStyle)==null?void 0:N.horizontalAlign)===s}),p={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:c}},f=new a.MemoryCursor;f.reset();const S=new a.TextX,E=a.JSONX.getInstance();for(const b of m){const{startIndex:N}=b;S.push({t:a.TextXActionType.RETAIN,len:N-f.cursor});const x={...b.paragraphStyle,horizontalAlign:g?a.HorizontalAlign.UNSPECIFIED:s};S.push({t:a.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...b,paragraphStyle:x,startIndex:0}]},coverType:a.UpdateDocsAttributeType.REPLACE}),f.moveCursorTo(N+1)}const C=Z(r,l);return p.params.actions=E.editOp(S.serialize(),C),!!i.syncExecuteCommand(p.id,p.params)}},Ct={id:"doc.command.align-left",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(me.id,{alignType:a.HorizontalAlign.LEFT})},Tt={id:"doc.command.align-center",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(me.id,{alignType:a.HorizontalAlign.CENTER})},yt={id:"doc.command.align-right",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(me.id,{alignType:a.HorizontalAlign.RIGHT})},bt={id:"doc.command.align-justify",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(me.id,{alignType:a.HorizontalAlign.JUSTIFIED})},Ot={id:"doc.command.switch-mode",type:a.CommandType.COMMAND,handler:o=>{var E,C,T,R,v;const t=o.get(a.ICommandService),e=o.get(_.IRenderManagerService),n=o.get(D.DocSelectionManagerService),s=o.get(a.IUniverInstanceService).getCurrentUniverDocInstance();if(s==null)return!1;const r=s.getUnitId(),c=(E=e.getRenderById(r))==null?void 0:E.with(D.DocSkeletonManagerService).getSkeleton(),l=(C=e.getRenderById(r))==null?void 0:C.with(y.DocSelectionRenderService);if(c==null||l==null)return!1;const A=l==null?void 0:l.getSegment(),d=l==null?void 0:l.getSegmentPage(),u=s.getSnapshot().documentStyle.documentFlavor,m=n.getDocRanges(),h={id:D.RichTextEditingMutation.id,params:{unitId:r,actions:[],textRanges:u===a.DocumentFlavor.TRADITIONAL&&A?[]:m}},g=a.JSONX.getInstance(),p=[];let f;if(u===void 0?f=g.insertOp(["documentStyle","documentFlavor"],a.DocumentFlavor.MODERN):u===a.DocumentFlavor.MODERN?f=g.replaceOp(["documentStyle","documentFlavor"],u,a.DocumentFlavor.TRADITIONAL):f=g.replaceOp(["documentStyle","documentFlavor"],u,a.DocumentFlavor.MODERN),f)p.push(f);else return!1;if(u!==a.DocumentFlavor.MODERN){const O=s.getSnapshot(),{drawings:M={},body:b}=O,N=(T=b==null?void 0:b.customBlocks)!=null?T:[];for(const x in M){const U=M[x],F=N.find($=>$.blockId===x);if(F==null)continue;const V=U.docTransform.positionV,{relativeFrom:H,posOffset:Q}=V;if(H===a.ObjectRelativeFromV.PARAGRAPH)continue;const{startIndex:X}=F,j=c.findNodeByCharIndex(X,A,d),k=(R=j==null?void 0:j.parent)==null?void 0:R.parent,W=k==null?void 0:k.parent,G=W==null?void 0:W.lines.find($=>$.paragraphIndex===(k==null?void 0:k.paragraphIndex)&&$.paragraphStart),K=(v=W==null?void 0:W.parent)==null?void 0:v.parent;if(j==null||k==null||G==null||W==null||K==null)continue;let Y=0;H===a.ObjectRelativeFromV.LINE?Y-=k.top:H===a.ObjectRelativeFromV.PAGE&&(Y+=K.marginTop),Y+=G.top;const q={...V,relativeFrom:a.ObjectRelativeFromV.PARAGRAPH,posOffset:(Q!=null?Q:0)-Y},z=g.replaceOp(["drawings",x,"docTransform","positionV"],V,q);z&&p.push(z)}}return h.params.actions=p.reduce((O,M)=>a.JSONX.compose(O,M),null),!!t.syncExecuteCommand(h.id,h.params)}},Ba="COMPONENT_DOC_CREATE_TABLE_CONFIRM",Bo={id:"doc.command.create-table",type:a.CommandType.COMMAND,handler:async(o,t)=>{var q,z,$,ie,fe;const{rowCount:e,colCount:n}=t,i=o.get(D.DocSelectionManagerService),s=o.get(a.IUniverInstanceService),r=o.get(a.ICommandService),c=o.get(Te),l=i.getActiveTextRange();if(l==null)return!1;const{segmentId:A,segmentPage:d}=l,u=s.getCurrentUniverDocInstance(),m=u==null?void 0:u.getSelfOrHeaderFooterModel(A).getBody();if(u==null||m==null)return!1;const h=u.getUnitId(),g=re(o,h),p=g==null?void 0:g.getSkeleton();if(p==null)return!1;const{startOffset:f}=l,E=((q=m.paragraphs)!=null?q:[]).find(Fe=>Fe.startIndex>=f),C=p.findNodeByCharIndex(f,A,d);if(C==null)return!1;const T=new a.TextX,R=a.JSONX.getInstance(),v=[],O=f+4,M=[{startOffset:O,endOffset:O,collapsed:!0}],b={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:M}};f>0&&T.push({t:a.TextXActionType.RETAIN,len:f}),T.push({t:a.TextXActionType.INSERT,body:{dataStream:a.DataStreamTreeTokenType.PARAGRAPH,paragraphs:po(a.DataStreamTreeTokenType.PARAGRAPH,E)},len:1});const N=c.getDefaultStyle(),x=c.getStyleCache(),U=Lt(m,f,N,x),{dataStream:F,paragraphs:V,sectionBreaks:H}=Tr(e,n),Q=(fe=(ie=($=(z=C.parent)==null?void 0:z.parent)==null?void 0:$.parent)==null?void 0:ie.parent)==null?void 0:fe.parent;if(Q==null)return!1;const{pageWidth:X,marginLeft:j,marginRight:k}=Q,W=eo(e,n,X-j-k);T.push({t:a.TextXActionType.INSERT,body:{dataStream:F,paragraphs:V,sectionBreaks:H,textRuns:[{...U,st:0,ed:F.length}],tables:[{startIndex:0,endIndex:F.length,tableId:W.tableId}]},len:F.length});const G=Z(u,A);v.push(R.editOp(T.serialize(),G));const K=R.insertOp(["tableSource",W.tableId],W);return v.push(K),b.params.actions=v.reduce((Fe,Se)=>a.JSONX.compose(Fe,Se),null),!!r.syncExecuteCommand(b.id,b.params)}},_o="doc.component.create-table-confirm",sn={id:"doc.operation.create-table",type:a.CommandType.COMMAND,handler:async o=>{const t=o.get(a.LocaleService),e=o.get(I.IConfirmService),n=o.get(a.ICommandService),i={rowCount:3,colCount:5},s=(r,c)=>{i.rowCount=r,i.colCount=c};return await e.open({id:_o,children:{label:{name:Ba,props:{handleRowColChange:s,tableCreateParams:i}}},width:400,title:{title:t.t("toolbar.table.insert")},onConfirm:()=>{n.executeCommand(Bo.id,i),e.close(_o)},onClose:()=>{e.close(_o)}}),!0}},$r=o=>{const e=Object.keys(a.PAGE_SIZE).find(n=>{const{width:i,height:s}=a.PAGE_SIZE[n];return o.width===i&&o.height===s});return e!=null?e:"A4"};function ec(o){const{hooks:t}=o,i=I.useDependency(a.IUniverInstanceService).getCurrentUnitOfType(a.UniverInstanceType.UNIVER_DOC).getDocumentStyle(),s=I.useDependency(a.LocaleService),[r,c]=w.useState(()=>{var d,u,m,h,g;return{paperSize:$r(i.pageSize),orientation:(d=i.pageOrient)!=null?d:a.PageOrientType.PORTRAIT,margins:{top:(u=i.marginTop)!=null?u:0,bottom:(m=i.marginBottom)!=null?m:0,left:(h=i.marginLeft)!=null?h:0,right:(g=i.marginRight)!=null?g:0}}});w.useEffect(()=>{t.beforeClose=()=>r,t.beforeConfirm=()=>r},[r]);const l=d=>{c(u=>({...u,paperSize:d}))},A=(d,u)=>{c(m=>({...m,margins:{...m.margins,[d]:u||0}}))};return P.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-4",children:[P.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white",children:s.t("page-settings.paper-size")}),P.jsx(J.Select,{value:r.paperSize,onChange:l,options:a.PAPER_TYPES.map(d=>({label:s.t(`page-settings.page-size.${d.toLocaleLowerCase()}`),value:d}))})]}),P.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white",children:s.t("page-settings.custom-paper-size")}),P.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-2.5",children:[P.jsxs("div",{className:"univer-flex univer-gap-2.5",children:[P.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:s.t("page-settings.top")}),P.jsx(J.InputNumber,{value:r.margins.top,onChange:d=>A("top",d)})]}),P.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:s.t("page-settings.bottom")}),P.jsx(J.InputNumber,{value:r.margins.bottom,onChange:d=>A("bottom",d)})]})]}),P.jsxs("div",{className:"univer-flex univer-gap-2.5",children:[P.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:s.t("page-settings.left")}),P.jsx(J.InputNumber,{value:r.margins.left,onChange:d=>A("left",d)})]}),P.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[P.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:s.t("page-settings.right")}),P.jsx(J.InputNumber,{value:r.margins.right,onChange:d=>A("right",d)})]})]})]})]})]})}const No="docs.component.page-setting",_a={id:"docs.command.page-setup",type:a.CommandType.COMMAND,handler:(o,t)=>{if(!t)return!1;const e=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService),i=e.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_DOC);if(!i)return!1;const{marginLeft:s,marginRight:r,marginBottom:c,marginTop:l,pageOrient:A,pageSize:d}=t,u=a.JSONX.getInstance(),m=i.getDocumentStyle(),{marginBottom:h,marginLeft:g,marginRight:p,marginTop:f,pageOrient:S,pageSize:E}=m,C=[];if(h===void 0){const v=u.insertOp(["documentStyle","marginBottom"],c);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","marginBottom"],h,c);v&&C.push(v)}if(g===void 0){const v=u.insertOp(["documentStyle","marginLeft"],s);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","marginLeft"],g,s);v&&C.push(v)}if(p===void 0){const v=u.insertOp(["documentStyle","marginRight"],r);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","marginRight"],p,r);v&&C.push(v)}if(f===void 0){const v=u.insertOp(["documentStyle","marginTop"],l);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","marginTop"],f,l);v&&C.push(v)}if(E===void 0){const v=u.insertOp(["documentStyle","pageSize"],d);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","pageSize"],E,d);v&&C.push(v)}if(S===void 0){const v=u.insertOp(["documentStyle","pageOrient"],A);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","pageOrient"],S,A);v&&C.push(v)}const T={id:D.RichTextEditingMutation.id,params:{unitId:i.getUnitId(),actions:[],textRanges:void 0}};return T.params.actions=C.reduce((v,O)=>a.JSONX.compose(v,O),null),!!n.syncExecuteCommand(T.id,T.params)}},Po={id:"docs.operation.open-page-setting",type:a.CommandType.OPERATION,handler:o=>{const t=o.get(I.IConfirmService),e=o.get(a.ICommandService),n=o.get(a.LocaleService),i=t.open({id:No,title:{label:n.t("page-settings.document-setting")},children:{label:No},width:528,onClose:()=>{i.dispose()},onConfirm:s=>{if(i.dispose(),!s)return;const r=a.PAGE_SIZE[s.paperSize];e.executeCommand(_a.id,{pageOrient:s.orientation,marginTop:s.margins.top,marginBottom:s.margins.bottom,marginLeft:s.margins.left,marginRight:s.margins.right,pageSize:r})},confirmText:n.t("page-settings.confirm"),cancelText:n.t("page-settings.cancel")});return!0}};function tc(o){const t=o.get(a.IUniverInstanceService),e=o.get(_.IRenderManagerService);return new L.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(D.DocSkeletonManagerService).getViewModel().editAreaChange$.subscribe(A=>{n.next(A===_.DocumentEditArea.HEADER||A===_.DocumentEditArea.FOOTER)})});return()=>i.unsubscribe()})}function nc(o){const t=o.get(a.IUniverInstanceService),e=o.get(a.ICommandService);return new L.Observable(n=>{const i=e.onCommandExecuted(l=>{if(l.id===D.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)!==a.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!==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 oc(o){const t=o.get(D.DocSelectionManagerService),e=o.get(a.IUniverInstanceService);return new L.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: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 m=re(o,u.getUnitId());if(m==null){n.next(!0);return}if(m.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()=>i.unsubscribe()})}function te(o){const t=o.get(D.DocSelectionManagerService);return new L.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 ic(o){const t=o.get(a.ICommandService);return{id:De.id,type:I.MenuItemType.BUTTON,icon:"BoldIcon",title:"Set bold",tooltip:"toolbar.bold",activated$:new L.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const r=(c=s.ts)==null?void 0:c.bl;e.next(r===a.BooleanNumber.TRUE)},i=t.onCommandExecuted(s=>{const r=s.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),i.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function ac(o){const t=o.get(a.ICommandService);return{id:Be.id,type:I.MenuItemType.BUTTON,icon:"ItalicIcon",title:"Set italic",tooltip:"toolbar.italic",activated$:new L.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const r=(c=s.ts)==null?void 0:c.it;e.next(r===a.BooleanNumber.TRUE)},i=t.onCommandExecuted(s=>{const r=s.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),i.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function sc(o){const t=o.get(a.ICommandService);return{id:_e.id,type:I.MenuItemType.BUTTON,icon:"UnderlineIcon",title:"Set underline",tooltip:"toolbar.underline",activated$:new L.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const r=(c=s.ts)==null?void 0:c.ul;e.next((r==null?void 0:r.s)===a.BooleanNumber.TRUE)},i=t.onCommandExecuted(s=>{const r=s.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),i.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function rc(o){const t=o.get(a.ICommandService);return{id:Ne.id,type:I.MenuItemType.BUTTON,icon:"StrikethroughIcon",title:"Set strike through",tooltip:"toolbar.strikethrough",activated$:new L.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const r=(c=s.ts)==null?void 0:c.st;e.next((r==null?void 0:r.s)===a.BooleanNumber.TRUE)},i=t.onCommandExecuted(s=>{const r=s.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),i.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function cc(o){const t=o.get(a.ICommandService);return{id:ye.id,type:I.MenuItemType.BUTTON,icon:"SubscriptIcon",tooltip:"toolbar.subscript",activated$:new L.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const r=(c=s.ts)==null?void 0:c.va;e.next(r===a.BaselineOffset.SUBSCRIPT)},i=t.onCommandExecuted(s=>{const r=s.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),i.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function lc(o){const t=o.get(a.ICommandService);return{id:Pe.id,type:I.MenuItemType.BUTTON,icon:"SuperscriptIcon",tooltip:"toolbar.superscript",activated$:new L.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const r=(c=s.ts)==null?void 0:c.va;e.next(r===a.BaselineOffset.SUPERSCRIPT)},i=t.onCommandExecuted(s=>{const r=s.id;(r===D.SetTextSelectionsOperation.id||r===be.id)&&n()});return n(),i.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function dc(o){const t=o.get(a.ICommandService);return{id:We.id,tooltip:"toolbar.font",type:I.MenuItemType.SELECTOR,label:I.FONT_FAMILY_COMPONENT,selections:I.FONT_FAMILY_LIST.map(e=>({label:{name:I.FONT_FAMILY_ITEM_COMPONENT},value:e.value})),value$:new L.Observable(e=>{const n=a.DEFAULT_STYLES.ff,i=()=>{var l;const r=Le(o);if(r==null){e.next(n);return}const c=(l=r.ts)==null?void 0:l.ff;e.next(c!=null?c:n)},s=t.onCommandExecuted(r=>{const c=r.id;(c===D.SetTextSelectionsOperation.id||c===We.id)&&i()});return i(),s.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function Ac(o){const t=o.get(a.ICommandService);return{id:ge.id,type:I.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:I.FONT_SIZE_COMPONENT,props:{min:1,max:400}},selections:I.FONT_SIZE_LIST,value$:new L.Observable(e=>{const n=a.DEFAULT_STYLES.fs,i=()=>{var l;const r=Le(o);if(r==null){e.next(n);return}const c=(l=r.ts)==null?void 0:l.fs;e.next(c!=null?c:n)},s=t.onCommandExecuted(r=>{const c=r.id;(c===D.SetTextSelectionsOperation.id||c===ge.id)&&i()});return i(),s.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function uc(o){const t=o.get(a.ICommandService);return{id:de.id,type:I.MenuItemType.SELECTOR,tooltip:"toolbar.heading.tooltip",label:{name:I.COMMON_LABEL_COMPONENT,props:{selections:I.HEADING_LIST}},selections:I.HEADING_LIST.map(e=>({label:{name:I.HEADING_ITEM_COMPONENT,props:{value:e.value,text:e.label}},value:e.value})),value$:new L.Observable(e=>{const n=a.NamedStyleType.NORMAL_TEXT,i=()=>{var l,A;const r=Ge(o);if(r==null){e.next(n);return}const c=(A=(l=r.paragraphStyle)==null?void 0:l.namedStyleType)!=null?A:n;e.next(c)},s=t.onCommandExecuted(r=>{const c=r.id;(c===D.SetTextSelectionsOperation.id||c===ge.id)&&i()});return i(),s.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function hc(o){const t=o.get(a.ICommandService),e=o.get(a.ThemeService);return{id:we.id,icon:"FontColorDoubleIcon",tooltip:"toolbar.textColor.main",type:I.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:I.COLOR_PICKER_COMPONENT,hoverable:!1,selectable:!1}}],value$:new L.Observable(n=>{const i=e.getColorFromTheme("gray.900"),s=t.onCommandExecuted(r=>{if(r.id===we.id){const c=r.params.value;n.next(c!=null?c:i)}});return n.next(i),s.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function gc(o){return{id:Jn.id,type:I.MenuItemType.BUTTON,icon:"HeaderFooterIcon",tooltip:"toolbar.headerFooter",hidden$:L.combineLatest(I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY),nc(o),(t,e)=>t||e)}}const mc="GridIcon",Na="doc.menu.table";function pc(o){return{id:Na,type:I.MenuItemType.SUBITEMS,icon:mc,tooltip:"toolbar.table.main",disabled$:oc(o),hidden$:L.combineLatest(I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY),tc(o),(t,e)=>t||e)}}function fc(o){return{id:sn.id,title:"toolbar.table.insert",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function Sc(o){const t=o.get(a.ICommandService);return{id:Ct.id,type:I.MenuItemType.BUTTON,icon:"LeftJustifyingIcon",tooltip:"toolbar.alignLeft",disabled$:te(o),activated$:new L.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===D.SetTextSelectionsOperation.id||s===me.id){const c=Ge(o);if(c==null)return;const l=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(l===a.HorizontalAlign.LEFT)}});return e.next(!1),n.dispose}),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Ic(o){const t=o.get(a.ICommandService);return{id:Tt.id,type:I.MenuItemType.BUTTON,icon:"HorizontallyIcon",tooltip:"toolbar.alignCenter",activated$:new L.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===D.SetTextSelectionsOperation.id||s===me.id){const c=Ge(o);if(c==null)return;const l=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(l===a.HorizontalAlign.CENTER)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function vc(o){const t=o.get(a.ICommandService);return{id:yt.id,type:I.MenuItemType.BUTTON,icon:"RightJustifyingIcon",tooltip:"toolbar.alignRight",activated$:new L.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===D.SetTextSelectionsOperation.id||s===me.id){const c=Ge(o);if(c==null)return;const l=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(l===a.HorizontalAlign.RIGHT)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Ec(o){const t=o.get(a.ICommandService);return{id:bt.id,type:I.MenuItemType.BUTTON,icon:"AlignTextBothIcon",tooltip:"toolbar.alignJustify",activated$:new L.Observable(e=>{const n=t.onCommandExecuted(i=>{var r;const s=i.id;if(s===D.SetTextSelectionsOperation.id||s===me.id){const c=Ge(o);if(c==null)return;const l=(r=c.paragraphStyle)==null?void 0:r.horizontalAlign;e.next(l===a.HorizontalAlign.JUSTIFIED)}});return e.next(!1),n.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Cc(o){return{id:St.id,type:I.MenuItemType.BUTTON,icon:"ReduceIcon",tooltip:"toolbar.horizontalLine",disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}const Rt=o=>new L.Observable(t=>{const e=o.get(a.IUniverInstanceService),n=o.get(D.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,m,h,g;const l=n.getDocRanges(),A=(d=l.find(p=>p.isActive))!=null?d:l[0];if(A){const p=c.getSelfOrHeaderFooterModel(A==null?void 0:A.segmentId),f=a.BuildTextUtils.range.getParagraphsInRange(A,(m=(u=p.getBody())==null?void 0:u.paragraphs)!=null?m:[],(g=(h=p.getBody())==null?void 0:h.dataStream)!=null?g:"");let S;if(f.every(E=>{var C;return S||(S=(C=E.bullet)==null?void 0:C.listType),E.bullet&&E.bullet.listType===S})){t.next(S);return}}t.next(void 0)}))});return()=>{s.unsubscribe(),i==null||i.unsubscribe()}});function Pa(o){return{id:ot.id,type:I.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:qi,hoverable:!1,selectable:!1},value$:Rt(o)}],icon:"OrderIcon",tooltip:"toolbar.order",hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC),disabled$:te(o),activated$:Rt(o).pipe(L.map(t=>!!(t&&t.indexOf("ORDER_LIST")===0)))}}function wa(o){return{id:nt.id,type:I.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:Ji,hoverable:!1,selectable:!1},value$:Rt(o)}],icon:"UnorderIcon",tooltip:"toolbar.unorder",disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC),activated$:Rt(o).pipe(L.map(t=>!!(t&&t.indexOf("BULLET_LIST")===0)))}}function Ua(o){return{id:Et.id,type:I.MenuItemType.BUTTON,icon:"TodoListDoubleIcon",tooltip:"toolbar.checklist",disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC),activated$:Rt(o).pipe(L.map(t=>!!(t&&t.indexOf("CHECK_LIST")===0)))}}function Tc(o){const t=o.get(a.ICommandService),e=o.get(a.IUniverInstanceService);return{id:Ot.id,type:I.MenuItemType.BUTTON,icon:"KeyboardIcon",tooltip:"toolbar.documentFlavor",hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC,void 0,a.DOCS_ZEN_EDITOR_UNIT_ID_KEY),activated$:new L.Observable(n=>{var r;const i=t.onCommandExecuted(c=>{var l;if(c.id===D.RichTextEditingMutation.id){const A=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);n.next(((l=A==null?void 0:A.getSnapshot())==null?void 0:l.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 yc(o){return{id:et.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColorDoubleIcon"}}function bc(o){const t=o.get(a.ICommandService),e=o.get(a.ThemeService);return{id:Ue.id,tooltip:"toolbar.fillColor.main",type:I.MenuItemType.BUTTON_SELECTOR,icon:"PaintBucketDoubleIcon",selections:[{label:{name:I.COLOR_PICKER_COMPONENT,hoverable:!1,selectable:!1}}],value$:new L.Observable(n=>{const i=e.getColorFromTheme("primary.600"),s=t.onCommandExecuted(r=>{if(r.id===Ue.id){const c=r.params.value;n.next(c!=null?c:i)}});return n.next(i),s.dispose}),disabled$:te(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function Le(o){var g,p,f,S;const t=o.get(a.IUniverInstanceService),e=o.get(D.DocSelectionManagerService),n=o.get(Te),i=t.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),s=e.getDocRanges(),r=(g=s.find(E=>E.isActive))!=null?g:s[0],c=n.getDefaultStyle(),l=(p=n.getStyleCache())!=null?p:{},A=Ge(o),d=(f=A==null?void 0:A.paragraphStyle)!=null&&f.namedStyleType?a.NAMED_STYLE_MAP[(S=A==null?void 0:A.paragraphStyle)==null?void 0:S.namedStyleType]:null;if(i==null||r==null)return{ts:{...c,...d,...l}};const{segmentId:u}=r,m=i.getSelfOrHeaderFooterModel(u).getBody();if(m==null)return{ts:{...c,...d,...l}};const h=Ra(m,r,{});return a.Tools.deleteNull(h),{ts:{...c,...d,...h,...l}}}function Ge(o){var d,u;const t=o.get(a.IUniverInstanceService),e=o.get(D.DocSelectionManagerService),n=t.getCurrentUniverDocInstance(),i=e.getDocRanges(),s=(d=i.find(m=>m.isActive))!=null?d:i[0];if(n==null||s==null)return;const{startOffset:r,segmentId:c}=s,l=(u=n.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:u.paragraphs;if(l==null)return;let A=-1;for(const m of l){const{startIndex:h}=m;if(r>A&&r<=h)return m;A=h}return null}function Oc(o){return{id:Po.id,type:I.MenuItemType.BUTTON,icon:"DocumentSettingIcon",tooltip:"toolbar.pageSetup",hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}const Rc={[a.NamedStyleType.HEADING_1]:Oo,[a.NamedStyleType.HEADING_2]:Ro,[a.NamedStyleType.HEADING_3]:Mo,[a.NamedStyleType.HEADING_4]:xo,[a.NamedStyleType.HEADING_5]:Do,[a.NamedStyleType.NORMAL_TEXT]:an,[a.NamedStyleType.TITLE]:xa,[a.NamedStyleType.SUBTITLE]:Da,[a.NamedStyleType.NAMED_STYLE_TYPE_UNSPECIFIED]:an},La={[a.NamedStyleType.HEADING_1]:{key:"H1Icon",component:Bi},[a.NamedStyleType.HEADING_2]:{key:"H2Icon",component:_i},[a.NamedStyleType.HEADING_3]:{key:"H3Icon",component:Ni},[a.NamedStyleType.HEADING_4]:{key:"H4Icon",component:Pi},[a.NamedStyleType.HEADING_5]:{key:"H5Icon",component:wi},[a.NamedStyleType.NORMAL_TEXT]:{key:"TextTypeIcon",component:ut},[a.NamedStyleType.TITLE]:{key:"TextTypeIcon",component:ut},[a.NamedStyleType.SUBTITLE]:{key:"TextTypeIcon",component:ut},[a.NamedStyleType.NAMED_STYLE_TYPE_UNSPECIFIED]:{key:"TextTypeIcon",component:ut}},Qe=o=>t=>{const e=t.get(a.ICommandService),n=t.get(I.ComponentManager),i=La[o];return n.get(i.key)||n.register(i.key,i.component),{id:Rc[o].id,type:I.MenuItemType.BUTTON,icon:i.key,tooltip:"toolbar.heading.tooltip",disabled$:te(t),hidden$:I.getMenuHiddenObservable(t,a.UniverInstanceType.UNIVER_DOC),activated$:new L.Observable(s=>{const r=a.NamedStyleType.NORMAL_TEXT,c=()=>{var u,m;const A=Ge(t);if(A==null){s.next(r===o);return}const d=(m=(u=A.paragraphStyle)==null?void 0:u.namedStyleType)!=null?m:r;s.next(d===o)},l=e.onCommandExecuted(A=>{const d=A.id;(d===D.SetTextSelectionsOperation.id||d===ge.id)&&c()});return c(),l.dispose})}},Mc=Qe(a.NamedStyleType.HEADING_1),xc=Qe(a.NamedStyleType.HEADING_2),Dc=Qe(a.NamedStyleType.HEADING_3),Bc=Qe(a.NamedStyleType.HEADING_4),_c=Qe(a.NamedStyleType.HEADING_5),Nc=Qe(a.NamedStyleType.NORMAL_TEXT);Qe(a.NamedStyleType.TITLE),Qe(a.NamedStyleType.SUBTITLE);const Pc=o=>({id:ho.id,type:I.MenuItemType.BUTTON,icon:"CopyDoubleIcon",title:"rightClick.copy"}),wc=o=>({id:go.id,type:I.MenuItemType.BUTTON,icon:"CutIcon",title:"rightClick.cut"}),Uc=o=>({id:so.id,type:I.MenuItemType.BUTTON,icon:"DeleteIcon",title:"rightClick.delete"}),Lc=o=>({id:Co.id,type:I.MenuItemType.BUTTON,icon:"UnorderIcon",title:"rightClick.bulletList"}),Qc=o=>({id:To.id,type:I.MenuItemType.BUTTON,icon:"OrderIcon",title:"rightClick.orderList"}),Fc=o=>({id:yo.id,type:I.MenuItemType.BUTTON,icon:"TodoListDoubleIcon",title:"rightClick.checkList"}),Hc=o=>({id:fo.id,type:I.MenuItemType.BUTTON,icon:"ReduceIcon",title:"toolbar.horizontalLine"}),Qa="doc.menu.insert-bellow";function kc(o){return{id:Qa,type:I.MenuItemType.SUBITEMS,title:"rightClick.insertBellow"}}const wo=4,Vc=(o,t)=>{const e=o.get(a.IUniverInstanceService).getUniverDocInstance(t.unitId),n=(e==null?void 0:e.zoomRatio)||1;return{...a.Tools.deepClone(t),zoomRatio:n}},he={id:"doc.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(o,t)=>{const e=o.get(a.IUniverInstanceService).getUniverDocInstance(t.unitId);if(!e)return!1;const n=e.getSnapshot();return n.settings==null?n.settings={zoomRatio:t.zoomRatio}:n.settings.zoomRatio=t.zoomRatio,!0}};var Wc=Object.getOwnPropertyDescriptor,Gc=(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},rn=(o,t)=>(e,n)=>t(e,n,o);function Fa(o,t){const e=Ha(o.left,o.top,t),n=Ha(o.right,o.bottom,t);return{left:e.x,top:e.y,right:n.x,bottom:n.y}}function Ha(o,t,e){const{scaleX:n,scaleY:i}=e.getAncestorScale(),s=e.getViewport(se.VIEW_MAIN);if(!s)return{x:o,y:t};const{viewportScrollX:r,viewportScrollY:c}=s,l=(o-r)*n,A=(t-c)*i;return{x:l,y:A}}function ka(o,t,e){const{scaleX:n,scaleY:i}=e.getAncestorScale(),s=e.getViewport(se.VIEW_MAIN);if(!s)return{x:o,y:t};const{viewportScrollX:r,viewportScrollY:c}=s,l=o/n+r,A=t/i+c;return{x:l,y:A}}const cn=(o,t)=>{const{scene:e,mainComponent:n,engine:i}=t,s=t.with(D.DocSkeletonManagerService).getSkeleton(),r=s.findNodePositionByCharIndex(o.startOffset,!0,o.segmentId,o.segmentPage),c=o.collapsed?o.startOffset:o.endOffset-1,l=s.findNodePositionByCharIndex(c,!0,o.segmentId,o.segmentPage),A=n;if(!l||!r)return;const d=A.getOffsetConfig(),{docsLeft:u,docsTop:m}=d,h=i.getCanvasElement(),g=h.getBoundingClientRect(),p=_.pxToNum(h.style.width),{top:f,left:S,width:E}=g,C=E/p,{scaleX:T,scaleY:R}=e.getAncestorScale(),v=new ve(d,s),{borderBoxPointGroup:O}=v.getRangePointData(r,l);return Ht(O).map(N=>Fa(N,e)).map(N=>({left:(N.left+u*T)*C+S,right:(N.right+u*T)*C+S,top:(N.top+m*R)*C+f,bottom:(N.bottom+m*R)*C+f}))};y.DocCanvasPopManagerService=class extends a.Disposable{constructor(t,e,n,i){super(),this._globalPopupManagerService=t,this._renderManagerService=e,this._univerInstanceService=n,this._commandService=i}_createRectPositionObserver(t,e){const n=()=>{const{scene:l,engine:A}=e,d=typeof t=="function"?t():t,u=A.getCanvasElement(),m=u.getBoundingClientRect(),h=_.pxToNum(u.style.width),g=Fa(d,l),{top:p,left:f,width:S}=m,E=S/h;return{left:g.left*E+f,right:g.right*E+f,top:g.top*E+p,bottom:g.bottom*E+p}},i=n(),s=new L.BehaviorSubject(i),r=new a.DisposableCollection;r.add(this._commandService.onCommandExecuted(l=>{if(l.id===he.id||l.id===D.RichTextEditingMutation.id){const A=n();A&&s.next(A)}}));const c=e.scene.getViewport(se.VIEW_MAIN);return c&&r.add(c.onScrollAfter$.subscribeEvent(()=>{s.next(n())})),{position:i,position$:s,disposable:r}}_createObjectPositionObserver(t,e){const n=()=>{const{left:i,top:s,width:r,height:c}=t;return{left:i,right:i+r,top:s,bottom:s+c}};return this._createRectPositionObserver(n,e)}_createRangePositionObserver(t,e){var c;const n=(c=cn(t,e))!=null?c:[],i=new L.BehaviorSubject(n),s=new a.DisposableCollection;s.add(this._commandService.onCommandExecuted(l=>{if((l.id===he.id||l.id===D.RichTextEditingMutation.id)&&l.params.unitId===e.unitId){const d=cn(t,e);d&&i.next(d)}}));const r=e.scene.getViewport(se.VIEW_MAIN);return r&&s.add(r.onScrollAfter$.subscribeEvent(()=>{const l=cn(t,e);l&&i.next(l)})),{positions:n,positions$:i,disposable:s}}attachPopupToRect(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._createRectPositionObserver(t,i),l=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:s,anchorRect$:r,canvasElement:i.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(l),r.complete(),c.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==l}}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),l=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:s,anchorRect$:r,canvasElement:i.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(l),r.complete(),c.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==l}}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:l,positions$:A,disposable:d}=this._createRangePositionObserver(t,c),u=A.pipe(L.map(h=>s.includes("top")?h[0]:h[h.length-1])),m=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:["top","bottom","horizontal"].some(h=>s.includes(h))&&l.length>1&&r!=null?r:s,canvasElement:c.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(m),A.complete(),d.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==m}}},y.DocCanvasPopManagerService=Gc([rn(0,a.Inject(I.ICanvasPopupService)),rn(1,_.IRenderManagerService),rn(2,a.IUniverInstanceService),rn(3,a.ICommandService)],y.DocCanvasPopManagerService);var jc=Object.getOwnPropertyDescriptor,Xc=(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},Kc=(o,t)=>(e,n)=>t(e,n,o);const zc=(o,t,e,n)=>{var m,h,g,p,f;const i=e.findNodePositionByCharIndex(o.startOffset,!0,o.segmentId,n),s=e.getSkeletonData();let r=o.endOffset-1;if(o.segmentId){const S=(f=Array.from((h=(m=s==null?void 0:s.skeFooters.get(o.segmentId))==null?void 0:m.values())!=null?h:[])[0])!=null?f:Array.from((p=(g=s==null?void 0:s.skeHeaders.get(o.segmentId))==null?void 0:g.values())!=null?p:[])[0];S&&(r=Math.min(S.ed,r))}const c=e.findNodePositionByCharIndex(r,!0,o.segmentId,n);if(!c||!i)return;const l=t.getOffsetConfig(),A=new ve(l,e),{borderBoxPointGroup:d}=A.getRangePointData(i,c);return Ht(d).map(S=>({top:S.top+l.docsTop-wo,bottom:S.bottom+l.docsTop+wo,left:S.left+l.docsLeft,right:S.right+l.docsLeft}))},Va=(o,t,e,n)=>{const i=[];for(const s of o){const r=s.top;for(const c of s.columns){const l=c.left,A=s.colCount===1?n:c.width;let d=null;for(const u of c.lines){const m=u.paragraphIndex;if(u.paragraphStart){d&&(i.push(d),d=null);const h={top:t+r+u.top,left:e+l,right:e+l+A,bottom:t+r+u.top+u.lineHeight};d={paragraphStart:u.st,paragraphEnd:m,startIndex:m,rect:h,fisrtLine:{top:t+r+u.top+u.marginTop+u.paddingTop,left:e+l,right:e+l+A,bottom:t+r+u.top+u.marginTop+u.paddingTop+u.contentHeight}}}else d&&d.startIndex===m&&(d.rect.bottom=t+r+u.top+u.lineHeight)}d&&i.push(d)}}return i},Yc=(o,t,e,n=-1)=>{const i=e.findPositionByGlyph(o,n);if(!i)return;const s=t.getOffsetConfig(),r={...i,isBack:!0},c=new ve(s,e),{borderBoxPointGroup:l}=c.getRangePointData(r,r),d=Ht(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}};function je(o,t,e){const{left:n,right:i,top:s,bottom:r}=e;return o>=n&&o<=i&&t>=s&&t<=r}y.DocEventManagerService=class extends a.Disposable{constructor(e,n){super();B(this,"_hoverCustomRanges$",new L.BehaviorSubject([]));B(this,"hoverCustomRanges$",this._hoverCustomRanges$.pipe(L.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))));B(this,"_clickCustomRanges$",new L.Subject);B(this,"clickCustomRanges$",this._clickCustomRanges$.asObservable());B(this,"_hoverBullet$",new L.Subject);B(this,"hoverBullet$",this._hoverBullet$.pipe(L.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))));B(this,"_clickBullet$",new L.Subject);B(this,"clickBullets$",this._clickBullet$.asObservable());B(this,"_hoverParagraph$",new L.BehaviorSubject(null));B(this,"hoverParagraph$",this._hoverParagraph$.pipe(L.distinctUntilChanged((e,n)=>(e==null?void 0:e.startIndex)===(n==null?void 0:n.startIndex)&&(e==null?void 0:e.segmentId)===(n==null?void 0:n.segmentId)&&(e==null?void 0:e.pageIndex)===(n==null?void 0:n.pageIndex))));B(this,"hoverParagraphRealTime$",this._hoverParagraph$.asObservable());B(this,"_hoverParagraphLeft$",new L.BehaviorSubject(null));B(this,"hoverParagraphLeft$",this._hoverParagraphLeft$.pipe(L.distinctUntilChanged((e,n)=>(e==null?void 0:e.startIndex)===(n==null?void 0:n.startIndex)&&(e==null?void 0:e.segmentId)===(n==null?void 0:n.segmentId)&&(e==null?void 0:e.pageIndex)===(n==null?void 0:n.pageIndex))));B(this,"hoverParagraphLeftRealTime$",this._hoverParagraphLeft$.asObservable());B(this,"_hoverTableCell$",new L.Subject);B(this,"hoverTableCell$",this._hoverTableCell$.pipe(L.distinctUntilChanged((e,n)=>(e==null?void 0:e.rowIndex)===(n==null?void 0:n.rowIndex)&&(e==null?void 0:e.colIndex)===(n==null?void 0:n.colIndex)&&(e==null?void 0:e.tableId)===(n==null?void 0:n.tableId)&&(e==null?void 0:e.pageIndex)===(n==null?void 0:n.pageIndex))));B(this,"hoverTableCellRealTime$",this._hoverTableCell$.asObservable());B(this,"_hoverTable$",new L.Subject);B(this,"hoverTable$",this._hoverTable$.pipe(L.distinctUntilChanged((e,n)=>(e==null?void 0:e.tableId)===(n==null?void 0:n.tableId)&&(e==null?void 0:e.pageIndex)===(n==null?void 0:n.pageIndex))));B(this,"hoverTableRealTime$",this._hoverTable$.asObservable());B(this,"_customRangeDirty",!0);B(this,"_bulletDirty",!0);B(this,"_paragraphDirty",!0);B(this,"_customRangeBounds",[]);B(this,"_bulletBounds",[]);B(this,"_paragraphBounds",new Map);B(this,"_paragraphLeftBounds",[]);B(this,"_tableParagraphBounds",new Map);B(this,"_segmentParagraphBounds",new Map);B(this,"_tableCellBounds",new Map);B(this,"_tableBounds",new Map);this._context=e,this._docSkeletonManagerService=n,this._initResetDirty(),this._initEvents(),this._initPointer()}get hoverParagraph(){return this._hoverParagraph$.value}get hoverParagraphLeft(){return this._hoverParagraphLeft$.value}get _skeleton(){return this._docSkeletonManagerService.getSkeleton()}get _documents(){return this._context.mainComponent}dispose(){this._hoverCustomRanges$.complete(),this._clickCustomRanges$.complete(),super.dispose()}_initPointer(){let e=_.CURSOR_TYPE.TEXT;this.disposeWithMe(this.hoverCustomRanges$.subscribe(n=>{n.length?(e=this._context.scene.getCursor(),this._context.scene.setCursor(_.CURSOR_TYPE.POINTER)):this._context.scene.setCursor(e)}))}_initResetDirty(){this.disposeWithMe(this._skeleton.dirty$.subscribe(()=>{this._customRangeDirty=!0,this._bulletDirty=!0,this._paragraphDirty=!0})),this.disposeWithMe(a.fromEventSubject(this._context.engine.onTransformChange$).pipe(L.filter(e=>e.type===_.TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize)).subscribe(()=>{this._customRangeDirty=!0,this._bulletDirty=!0,this._paragraphDirty=!0}))}_initEvents(){this.disposeWithMe(a.fromEventSubject(this._context.scene.onPointerMove$).pipe(L.throttleTime(30)).subscribe(i=>{if(i.buttons>0){this._hoverBullet$.next(null),this._hoverCustomRanges$.next([]),this._hoverParagraph$.next(null),this._hoverParagraphLeft$.next(null),this._hoverTableCell$.next(null),this._hoverTable$.next(null);return}const{x:s,y:r}=ka(i.offsetX,i.offsetY,this._context.scene);this._hoverCustomRanges$.next(this._calcActiveRanges({x:s,y:r})),this._hoverParagraph$.next(this._calcActiveParagraph({x:s,y:r})),this._hoverParagraphLeft$.next(this._calcActiveParagraphLeft({x:s,y:r})),this._hoverBullet$.next(this._calcActiveBullet({x:s,y:r}))})),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(L.switchMap(i=>n.pipe(L.take(1),L.map(s=>({down:i,up:s})))),L.filter(({down:i,up:s})=>i.target===s.target&&s.timeStamp-i.timeStamp<300)).subscribe(({down:i})=>{if(i.button===2)return;const s=ka(i.offsetX,i.offsetY,this._context.scene),r=this._calcActiveRanges(s);r.length&&this._clickCustomRanges$.next(r.pop());const c=this._calcActiveBullet(s);c&&this._clickBullet$.next(c)}))}_buildCustomRangeBoundsBySegment(e,n=-1){var r,c,l;const i=(l=(c=(r=this._context.unit.getSelfOrHeaderFooterModel(e))==null?void 0:r.getBody())==null?void 0:c.customRanges)!=null?l:[],s=[];return i.forEach(A=>{const d={startOffset:A.startIndex,endOffset:A.endIndex+1,segmentId:e},u=zc(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((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{x:n,y:i}=e;return this._customRangeBounds.filter(r=>r.rects.some(c=>je(n,i,c))).map(r=>({segmentId:r.segmentId,range:r.customRange,segmentPageIndex:r.segmentPageIndex,rects:r.rects}))}_buildBulletBoundsBySegment(e,n=-1){var A,d,u,m,h;const i=(A=this._context.unit.getSelfOrHeaderFooterModel(e))==null?void 0:A.getBody(),s=((d=i==null?void 0:i.paragraphs)!=null?d:[]).filter(g=>g.bullet&&g.bullet.listType.indexOf("CHECK_LIST")===0),r=[],c=this._skeleton.getSkeletonData();if(!c)return r;const l=g=>{var p,f,S;for(const E of g){const C=[...E.sections];if(E.skeTables){const T=Array.from(E.skeTables.values());C.push(...T.map(R=>R.rows.map(v=>v.cells.map(O=>O.sections))).flat(4))}for(const T of C)for(const R of T.columns)for(const v of R.lines)if(v.paragraphStart){const O=s.find(M=>M.startIndex===v.paragraphIndex);if(O){const M=v,b=(S=(f=(p=M==null?void 0:M.divides)==null?void 0:p[0])==null?void 0:f.glyphGroup)==null?void 0:S[0];if(!b)continue;const N=Yc(b,this._documents,this._skeleton,n);if(!N)continue;r.push({rect:N,segmentId:e,segmentPageIndex:n,paragraph:O})}}}return r};if(e){const g=(h=(u=c.skeFooters.get(e))==null?void 0:u.values())!=null?h:(m=c.skeHeaders.get(e))==null?void 0:m.values();return g?l(Array.from(g)):r}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,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{x:n,y:i}=e;return this._bulletBounds.find(r=>je(n,i,r.rect))}_buildParagraphBoundsBySegment(e){var c,l,A;const n=this._skeleton.getSkeletonData(),s=this._documents.getOffsetConfig();if(!n)return null;const r=d=>{const u=new Map,m=(h,g,p,f)=>{Va(h.sections,p,f,h.pageWidth-h.marginLeft-h.marginRight).forEach(E=>{if(!u.has(E.startIndex))u.set(E.startIndex,{rect:E.rect,paragraphStart:E.paragraphStart,paragraphEnd:E.paragraphEnd,startIndex:E.startIndex,rects:[E.rect],pageIndex:g,segmentId:e,firstLine:E.fisrtLine});else{const C=u.get(E.startIndex);C&&(C.rect.bottom=E.rect.bottom,C.rects.push(E.rect))}})};for(let h=0;h<d.length;h++){const g=d[h],p=((g.pageHeight===1/0?0:g.pageHeight)+s.pageMarginTop)*h+g.marginTop+s.docsTop,f=g.marginLeft+s.docsLeft;g.skeTables&&Array.from(g.skeTables.values()).forEach(S=>{const E=S.left+f,C=S.top+p,T=E+S.width,R=C+S.height,v=S.tableId;this._tableBounds.set(v,{rect:{left:E,top:C,right:T,bottom:R},pageIndex:h,tableId:v}),S.rows.forEach((O,M)=>{O.cells.forEach((b,N)=>{const x=((g.pageHeight===1/0?0:g.pageHeight)+s.pageMarginTop)*h+S.top+s.docsTop+g.marginTop+O.top+b.marginTop,U=S.left+s.docsLeft+g.marginLeft+b.left+b.marginLeft,F=Va(b.sections,x,U,b.pageWidth-b.marginLeft-b.marginRight);let V=this._tableParagraphBounds.get(v);V||(V=[],this._tableParagraphBounds.set(v,V)),V.push(...F.map(Q=>({rect:Q.rect,paragraphStart:Q.paragraphStart,paragraphEnd:Q.paragraphEnd,startIndex:Q.startIndex,pageIndex:h,segmentId:e,rowIndex:M,colIndex:N,firstLine:Q.fisrtLine,tableId:v})));let H=this._tableCellBounds.get(v);H||(H=[],this._tableCellBounds.set(v,H)),H.push({rect:{top:x,left:U,right:U+b.pageWidth-b.marginLeft-b.marginRight,bottom:x+b.pageHeight-b.marginBottom-b.marginTop},pageIndex:h,rowIndex:M,colIndex:N,tableId:v})})})}),m(g,h,p,f)}return u};if(e){const d=(A=(c=n.skeFooters.get(e))==null?void 0:c.values())!=null?A:(l=n.skeHeaders.get(e))==null?void 0:l.values();return d?r(Array.from(d)):null}return r(n.pages)}_buildParagraphBounds(){var n,i;if(!this._paragraphDirty)return;this._paragraphDirty=!1,this._tableParagraphBounds=new Map,this._tableCellBounds=new Map,this._tableBounds=new Map,this._paragraphBounds=(n=this._buildParagraphBoundsBySegment())!=null?n:new Map,this._paragraphLeftBounds=Array.from(this._paragraphBounds.values()).map(s=>({...s,rect:{left:s.rect.left-60,right:s.rect.left,top:s.rect.top,bottom:s.rect.bottom}}));const e=s=>{var r;this._segmentParagraphBounds.set(s,(r=this._buildParagraphBoundsBySegment(s))!=null?r:new Map)};(i=this._skeleton.getSkeletonData())==null||i.pages.forEach(s=>{s.headerId&&e(s.headerId),s.footerId&&e(s.footerId)})}_calcActiveParagraph(e){var c,l;this._buildParagraphBounds();const{x:n,y:i}=e,s=Array.from(this._tableBounds.values()).find(A=>je(n,i,A.rect));if(this._hoverTable$.next(s),s){const A=(c=this._tableCellBounds.get(s.tableId))==null?void 0:c.find(m=>je(n,i,m.rect));if(this._hoverTableCell$.next(A),!A)return null;const d=(l=this._tableParagraphBounds.get(A.tableId))==null?void 0:l.filter(m=>m.colIndex===A.colIndex&&m.rowIndex===A.rowIndex),u=d==null?void 0:d.find(m=>je(n,i,m.rect));return u&&{...u,rects:[u.rect]}}let r;for(const A of this._paragraphBounds){const d=A[1];if(d.rects.some(u=>je(n,i,u))){r=d;break}}return r}_calcActiveParagraphLeft(e){this._buildParagraphBounds();const{x:n,y:i}=e;return this._paragraphLeftBounds.find(r=>je(n,i,r.rect))}get paragraphBounds(){return this._buildParagraphBounds(),this._paragraphBounds}findParagraphBoundByIndex(e){this._buildParagraphBounds();const n=this._paragraphBounds.get(e);return n||Array.from(this._tableParagraphBounds.values()).flat().find(s=>s.startIndex===e)}},y.DocEventManagerService=Xc([Kc(1,a.Inject(D.DocSkeletonManagerService))],y.DocEventManagerService);const qc=[ge.id,De.id,Be.id,_e.id,Ne.id,ye.id,Pe.id,we.id,Ue.id];function Jc(o){const{avaliableMenus:t=qc}=o,e=I.useDependency(I.IMenuManagerService),[n,i]=w.useState([]);return w.useEffect(()=>{function s(){const c=e.getFlatMenuByPositionKey(I.MenuManagerPosition.RIBBON),l=[];for(const A of t){const d=c.find(u=>u.key===A);d&&l.push(d)}i(l)}s();const r=e.menuChanged$.subscribe(s);return()=>{r.unsubscribe()}},[e]),P.jsx("div",{className:J.clsx("univer-box-border univer-flex univer-rounded univer-bg-white univer-py-1.5 univer-shadow-sm dark:!univer-border-gray-700 dark:!univer-bg-gray-900",J.borderClassName),children:n.map(s=>s.item&&P.jsx("div",{className:"univer-flex univer-flex-nowrap univer-gap-2 univer-px-2",children:P.jsx(I.ToolbarItem,{...s.item},s.key)},s.key))})}var Zc=Object.getOwnPropertyDescriptor,$c=(o,t,e,n)=>{for(var i=n>1?void 0:n?Zc(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Mt=(o,t)=>(e,n)=>t(e,n,o);const Wa="univer.doc.float-menu";function el(o,t){if(o==null||t==null)return!1;const{glyph:e,...n}=o,{glyph:i,...s}=t;return a.deepCompare(n,s)}const tl=[a.DataStreamTreeTokenType.CUSTOM_BLOCK,a.DataStreamTreeTokenType.PARAGRAPH];let ln=class extends a.Disposable{constructor(t,e,n,i,s,r){super();B(this,"_floatMenu",null);this._context=t,this._docSelectionManagerService=e,this._docCanvasPopManagerService=n,this._componentManager=i,this._univerInstanceService=s,this._docSelectionRenderService=r,!a.isInternalEditorID(this._context.unitId)&&(this._registerFloatMenu(),this._initSelectionChange(),this.disposeWithMe(()=>{this._hideFloatMenu()}))}get floatMenu(){return this._floatMenu}_registerFloatMenu(){this.disposeWithMe(this._componentManager.register(Wa,Jc))}_initSelectionChange(){this.disposeWithMe(this._docSelectionRenderService.onSelectionStart$.subscribe(()=>{this._hideFloatMenu()})),this.disposeWithMe(this._docSelectionManagerService.textSelection$.subscribe(t=>{var s,r;const{unitId:e,textRanges:n}=t;if(e!==this._context.unitId)return;const i=n.length>0&&n.find(c=>!c.collapsed);if(i){if(i.startOffset===((s=this._floatMenu)==null?void 0:s.start)&&i.endOffset===((r=this._floatMenu)==null?void 0:r.end))return;this._hideFloatMenu(),this._showFloatMenu(e,i);return}this._hideFloatMenu()}))}_hideFloatMenu(){var t;(t=this._floatMenu)==null||t.disposable.dispose(),this._floatMenu=null}_showFloatMenu(t,e){var r,c,l;const n=this._univerInstanceService.getUnit(t,a.UniverInstanceType.UNIVER_DOC);if(!n||n.getDisabled())return;const i=(r=n.getBody())==null?void 0:r.dataStream[e.startOffset];if(e.endOffset-e.startOffset===1&&i&&tl.includes(i))return;const s=(l=(c=n.getBody())==null?void 0:c.customRanges)==null?void 0:l.filter(A=>A.wholeEntity);if(!(s!=null&&s.some(A=>A.startIndex===e.startOffset&&A.endIndex===e.endOffset-1)))return this._floatMenu={disposable:this._docCanvasPopManagerService.attachPopupToRange(e,{componentKey:Wa,direction:e.direction==="backward"||el(e.startNodePosition,e.endNodePosition)?"top-center":"bottom-center",offset:[0,4]},t),start:e.startOffset,end:e.endOffset},a.toDisposable(()=>this._hideFloatMenu())}};ln=$c([Mt(1,a.Inject(D.DocSelectionManagerService)),Mt(2,a.Inject(y.DocCanvasPopManagerService)),Mt(3,a.Inject(I.ComponentManager)),Mt(4,a.Inject(a.IUniverInstanceService)),Mt(5,a.Inject(y.DocSelectionRenderService))],ln);var nl=Object.getOwnPropertyDescriptor,ol=(o,t,e,n)=>{for(var i=n>1?void 0:n?nl(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},xt=(o,t)=>(e,n)=>t(e,n,o);let dn=class extends a.Disposable{constructor(t,e,n,i,s,r){super();B(this,"_paragrahMenu",null);this._context=t,this._docSelectionManagerService=e,this._docEventManagerService=n,this._docPopupManagerService=i,this._docSkeletonManagerService=s,this._floatMenuService=r,!a.isInternalEditorID(this._context.unitId)&&this._init()}get activeParagraph(){var t;return(t=this._paragrahMenu)==null?void 0:t.paragraph}_isCursorInActiveParagraph(){if(!this._paragrahMenu)return!1;const t=this._docSelectionManagerService.getActiveTextRange();return!(!(t!=null&&t.collapsed)||!(t!=null&&t.collapsed)||t.startOffset<this._paragrahMenu.paragraph.paragraphStart||t.startOffset>this._paragrahMenu.paragraph.paragraphEnd)}setParagraphMenuActive(t){this._paragrahMenu&&(this._paragrahMenu.active=t,this._isCursorInActiveParagraph()||this._docSelectionManagerService.replaceDocRanges([{startOffset:this._paragrahMenu.paragraph.paragraphStart,endOffset:this._paragrahMenu.paragraph.paragraphStart}]))}_init(){const t=n=>{var s;if(this._docSkeletonManagerService.getViewModel().getEditArea()===_.DocumentEditArea.BODY&&!this._floatMenuService.floatMenu&&!this._context.unit.getDisabled()){if((s=this._paragrahMenu)!=null&&s.active)return;if(n){this.showParagraphMenu(n);return}}this.hideParagraphMenu(!0)};this.disposeWithMe(L.combineLatest([this._docEventManagerService.hoverParagraphRealTime$,this._docEventManagerService.hoverParagraphLeft$]).pipe(L.throttleTime(16)).subscribe(([n,i])=>{const s=n!=null?n:i;t(s)}));let e=0;this.disposeWithMe(this._context.scene.getViewport(se.VIEW_MAIN).onScrollAfter$.subscribeEvent(n=>{e!==n.scrollY&&(e=n.scrollY,this.hideParagraphMenu(!0))})),this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe(()=>{this.hideParagraphMenu(!0)}))}showParagraphMenu(t){var l,A,d;if(((l=this._paragrahMenu)==null?void 0:l.paragraph.startIndex)===t.startIndex)return;this.hideParagraphMenu(!0);const e=(d=(A=this._context.unit.getBody())==null?void 0:A.dataStream)!=null?d:"",n=t?e.slice(t.paragraphStart,t.paragraphEnd):"";if(n==="\b"||n==="")return;const c=this._docPopupManagerService.attachPopupToRect(t.firstLine,{componentKey:"doc.paragraph.menu",direction:"left-center",onClickOutside:()=>{this._docSelectionManagerService.textSelection$.pipe(L.first()).subscribe(()=>{this._isCursorInActiveParagraph()||this.hideParagraphMenu(!0)})},zIndex:101},this._context.unitId);this._paragrahMenu={paragraph:t,disposable:c,active:!1}}hideParagraphMenu(t=!1){this._paragrahMenu&&(this._paragrahMenu.disposable.canDispose()||t)&&(this._paragrahMenu.disposable.dispose(),this._paragrahMenu=null)}};dn=ol([xt(1,a.Inject(D.DocSelectionManagerService)),xt(2,a.Inject(y.DocEventManagerService)),xt(3,a.Inject(y.DocCanvasPopManagerService)),xt(4,a.Inject(D.DocSkeletonManagerService)),xt(5,a.Inject(ln))],dn);const il=({popup:o})=>{var v,O;const[t,e]=w.useState(!1),n=w.useRef(null),i=I.useDependency(a.ICommandService),s=I.useDependency(I.ILayoutService),r=w.useRef(null),c=w.useRef(!1),l=I.useDependency(_.IRenderManagerService),A=I.useDependency(a.IUniverInstanceService),d=l.getRenderById(o.unitId),u=A.getUnit(o.unitId,a.UniverInstanceType.UNIVER_DOC),m=d==null?void 0:d.with(dn),h=d==null?void 0:d.with(y.DocEventManagerService),g=I.useObservable(h==null?void 0:h.hoverParagraph$),p=I.useObservable(h==null?void 0:h.hoverParagraphLeft$),f=(v=g!=null?g:p)==null?void 0:v.startIndex,S=w.useMemo(()=>{var M,b;return(b=(M=u==null?void 0:u.getBody())==null?void 0:M.paragraphs)==null?void 0:b.find(N=>N.startIndex===f)},[u,g]),E=(O=S==null?void 0:S.paragraphStyle)==null?void 0:O.namedStyleType,C=La[E!=null?E:a.NamedStyleType.NORMAL_TEXT],T=w.useMemo(()=>new L.BehaviorSubject({left:0,right:0,top:0,bottom:0}),[]),R=()=>{e(!1),m==null||m.hideParagraphMenu(!0)};return P.jsxs(P.Fragment,{children:[P.jsxs("div",{"data-u-comp":"paragraph-menu",ref:r,className:J.clsx("univer-mr-1 univer-inline-flex univer-h-7 univer-cursor-pointer univer-items-center univer-gap-1 univer-rounded-full univer-px-2.5 univer-py-0 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-600",J.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-700":t,"univer-bg-white dark:!univer-bg-gray-700":!t}),onMouseEnter:M=>{var N,x,U,F,V,H;(N=o.onPointerEnter)==null||N.call(o,M),c.current=!0;const b=(x=r.current)==null?void 0:x.getBoundingClientRect();T.next({left:((U=b==null?void 0:b.left)!=null?U:0)-4,right:(F=b==null?void 0:b.right)!=null?F:0,top:(V=b==null?void 0:b.top)!=null?V:0,bottom:(H=b==null?void 0:b.bottom)!=null?H:0})},onMouseLeave:()=>{c.current=!1},onClick:()=>{e(!0),m==null||m.setParagraphMenuActive(!0)},children:[P.jsx(C.component,{className:"univer-size-4 univer-text-gray-900 dark:!univer-text-white"}),P.jsx(Di,{className:"univer-size-3 univer-text-gray-600 dark:!univer-text-gray-200"})]}),t&&P.jsx(I.RectPopup,{portal:!0,mask:!0,maskZIndex:100,anchorRect$:T,direction:"left",onMaskClick:R,children:P.jsx("section",{ref:n,onMouseEnter:M=>{var b;(b=o.onPointerEnter)==null||b.call(o,M),c.current=!0},onMouseLeave:()=>{c.current=!1},children:P.jsx(I.DesktopMenu,{style:{width:212},menuType:I.ContextMenuPosition.PARAGRAPH,onOptionSelect:M=>{const{label:b,commandId:N,value:x}=M;i&&i.executeCommand(N!=null?N:b,{value:x}),s.focus(),R()}})})})]})},Xe={id:"doc.command.tab",type:a.CommandType.COMMAND,async handler(o,t){const n=o.get(y.DocAutoFormatService).onAutoFormat(Xe.id,t);return(await a.sequenceExecuteAsync(n,o.get(a.ICommandService))).result}},Dt={id:"doc.command.after-space",type:a.CommandType.COMMAND,async handler(o){const e=o.get(y.DocAutoFormatService).onAutoFormat(Dt.id);return(await a.sequenceExecuteAsync(e,o.get(a.ICommandService))).result}},it={id:"doc.command.enter",type:a.CommandType.COMMAND,async handler(o){const e=o.get(y.DocAutoFormatService).onAutoFormat(it.id);return(await a.sequenceExecuteAsync(e,o.get(a.ICommandService))).result}};function ee(o){return o.getContextValue(a.FOCUSING_DOC)&&o.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!o.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function al(o){return o.getContextValue(a.FOCUSING_DOC)&&o.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!o.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}const sl={id:Xe.id,binding:I.KeyCode.TAB,preconditions:ee},rl={id:Xe.id,binding:I.KeyCode.TAB|I.MetaKeys.SHIFT,preconditions:ee,staticParameters:{shift:!0}},cl={id:De.id,binding:I.KeyCode.B|I.MetaKeys.CTRL_COMMAND,preconditions:ee},ll={id:Be.id,binding:I.KeyCode.I|I.MetaKeys.CTRL_COMMAND,preconditions:ee},dl={id:_e.id,binding:I.KeyCode.U|I.MetaKeys.CTRL_COMMAND,preconditions:ee},Al={id:Ne.id,binding:I.KeyCode.X|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:ee},ul={id:ye.id,binding:I.KeyCode.COMMA|I.MetaKeys.CTRL_COMMAND,preconditions:ee},hl={id:Pe.id,binding:I.KeyCode.PERIOD|I.MetaKeys.CTRL_COMMAND,preconditions:ee},gl={id:Ct.id,binding:I.KeyCode.L|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:ee},ml={id:yt.id,binding:I.KeyCode.R|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:ee},pl={id:Tt.id,binding:I.KeyCode.E|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:ee},fl={id:bt.id,binding:I.KeyCode.J|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:ee},Sl={id:ot.id,binding:I.KeyCode.Digit7|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:ee},Il={id:nt.id,binding:I.KeyCode.Digit8|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:ee},An="docs-ui.config",Ga={layout:{docContainerConfig:ai,toolbarConfig:ii}},vl=[50,80,100,130,150,170,200,400],El=[10,400];function Cl(){const o=I.useDependency(a.ICommandService),t=I.useDependency(a.IUniverInstanceService),e=w.useMemo(()=>t.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC),[]),n=I.useObservable(e),i=w.useCallback(()=>{var A,d;if(!n)return 100;const l=((d=(A=n.getSettings())==null?void 0:A.zoomRatio)!=null?d:1)*100;return Math.round(l)},[n]),[s,r]=w.useState(()=>i());w.useEffect(()=>(r(i()),o.onCommandExecuted(A=>{if(A.id===he.id){const d=i();r(d)}}).dispose),[o,i]);function c(l){if(r(l),n==null)return;const A=l/100;o.executeCommand(he.id,{unitId:n.getUnitId(),zoomRatio:A})}return P.jsx(I.Slider,{min:El[0],value:s,shortcuts:vl,onChange:c})}function Tl(o){return P.jsx("section",{className:"univer-flex univer-flex-shrink-0 univer-justify-end",children:P.jsx(Cl,{})})}function yl(){var i,s,r;const o=I.useDependency(a.IUniverInstanceService),t=I.useConfigValue(An),e=I.useObservable(()=>o.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),n=(r=(s=(i=t==null?void 0:t.layout)==null?void 0:i.docContainerConfig)==null?void 0:s.footer)!=null?r:!0;return e?null:n&&P.jsxs("div",{className:"univer-box-border univer-flex univer-items-center univer-justify-between univer-px-5 univer-py-1.5",children:[P.jsx("div",{}),P.jsx(Tl,{})]})}const bl="univer-overflow-hidden univer-font-[500] univer-truncate univer-h-[24px] univer-mb-2 univer-leading-[24px] univer-ellipsis univer-cursor-pointer",Ol="univer-text-base univer-font-semibold",Rl="univer-text-sm univer-font-semibold",Ml="univer-text-sm",xl=w.forwardRef((o,t)=>{const{menus:e,onClick:n,className:i,style:s,mode:r,maxHeight:c,activeId:l,open:A,onOpenChange:d,maxWidth:u,wrapperClass:m,wrapperStyle:h,iconClass:g,iconStyle:p}=o,f=r==="side-bar",S=w.useRef(null),E=w.useRef(e);E.current=e;const C=w.useMemo(()=>({scrollTo:T=>{var x;if(!E.current||E.current.findIndex(U=>U.id===T)===-1||!S.current)return;const v=document.getElementById(`univer-side-menu-${T}`);if(!v)return;const O=v.offsetTop,M=S.current.clientHeight,b=S.current.scrollHeight-M,N=Math.max(0,Math.min(O-M/2+v.clientHeight/2,b));(x=S.current)==null||x.scrollTo({behavior:"smooth",top:N})}}),[]);return w.useImperativeHandle(t,()=>C),w.useEffect(()=>{l&&C.scrollTo(l)},[l,C]),P.jsxs("div",{className:J.clsx("univer-relative",m),style:h,children:[P.jsx("div",{onClick:()=>d==null?void 0:d(!A),className:J.clsx("univer-absolute univer-left-5 univer-top-4 univer-z-[100] univer-flex univer-h-8 univer-w-8 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-full univer-bg-white univer-text-gray-800 univer-shadow-sm dark:!univer-bg-gray-600 dark:!univer-text-gray-200",g),style:p,children:A?P.jsx(Li,{}):P.jsx(Oi,{})}),P.jsx("div",{className:J.clsx(i,`
|
|
66
66
|
univer-absolute univer-left-0 univer-top-0 univer-box-border univer-flex univer-min-w-[180px]
|
|
67
67
|
univer-flex-col univer-px-4 univer-pb-4 univer-pt-14 univer-transition-all univer-duration-300
|
|
68
68
|
`,{"univer-rounded-r-2xl univer-bg-white univer-shadow univer-backdrop-blur-[10px] dark:!univer-bg-gray-900":f}),style:{...s,transform:A?"translateX(0)":"translateX(-100%)",maxHeight:c,opacity:A?1:0,maxWidth:u!=null?u:r==="side-bar"?320:180,paddingRight:r==="float"?void 0:0},children:P.jsx("div",{ref:S,className:J.clsx("univer-flex-1 univer-overflow-y-auto univer-overflow-x-hidden",J.scrollbarClassName),children:e==null?void 0:e.map(T=>P.jsx("div",{id:`univer-side-menu-${T.id}`,className:J.clsx(bl,{[Ol]:T.isTitle,[Rl]:T.level===1,[Ml]:T.level>1,"univer-text-gray-500 dark:!univer-text-gray-400":T.id!==l,"univer-text-gray-800 dark:!univer-text-gray-200":T.id===l}),style:{paddingLeft:(T.level-1)*12},onClick:()=>{n==null||n(T)},children:T.text},T.id))})})]})}),Dl=o=>{switch(o){case a.NamedStyleType.HEADING_1:return 1;case a.NamedStyleType.HEADING_2:return 2;case a.NamedStyleType.HEADING_3:return 3;case a.NamedStyleType.HEADING_4:return 4;case a.NamedStyleType.HEADING_5:return 5;case a.NamedStyleType.TITLE:return 1;default:return 1}};function Bl(o,t,e,n){var c,l;if(!o)return;const i=Array.from(o.values()),s=i.findIndex(A=>A.paragraphStart!==A.paragraphEnd&&A.rect.top<n&&A.rect.bottom>e);if(s===-1)return;const r=i==null?void 0:i.findLastIndex(A=>A.paragraphStart!==A.paragraphEnd&&A.rect.top<n&&A.rect.bottom>e);for(let A=s;A<=r;A++){const d=i[A],u=t.get(d.startIndex);if((c=u==null?void 0:u.paragraphStyle)!=null&&c.headingId)return u.paragraphStyle.headingId}for(let A=s;A>=0;A--){const d=i[A],u=t.get(d.startIndex);if((l=u==null?void 0:u.paragraphStyle)!=null&&l.headingId)return u.paragraphStyle.headingId}}const ja="__title";function _l(){var t,e,n;const o=I.useConfigValue(An);return(n=(e=(t=o==null?void 0:o.layout)==null?void 0:t.docContainerConfig)==null?void 0:e.sideMenu)==null||n?P.jsx(Nl,{}):null}function Nl(){var N,x,U,F,V,H,Q,X,j;const o=I.useDependency(a.ICommandService),t=I.useDependency(a.IUniverInstanceService),e=I.useObservable(w.useMemo(()=>t.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC),[])),n=I.useDependency(_.IRenderManagerService),i=(x=(N=e==null?void 0:e.getBody())==null?void 0:N.dataStream)!=null?x:"",[s,r]=w.useState(0),[c,l]=w.useState(void 0),A=(U=e==null?void 0:e.getUnitId())!=null?U:"",d=n.getRenderById(A),u=e==null?void 0:e.getTitle(),m=d==null?void 0:d.with(y.DocEventManagerService),h=m==null?void 0:m.paragraphBounds,g=(V=(F=d==null?void 0:d.mainComponent)==null?void 0:F.left)!=null?V:0,p=(H=d==null?void 0:d.engine.height)!=null?H:0,f=(Q=d==null?void 0:d.scene.scaleY)!=null?Q:1,S=(j=(X=e==null?void 0:e.getBody())==null?void 0:X.paragraphs)!=null?j:[],E=w.useMemo(()=>{const k=new Map;return S.forEach(W=>{k.set(W.startIndex,W)}),k},[S]);I.useObservable(w.useMemo(()=>d!=null&&d.engine.onTransformChange$?a.fromEventSubject(d==null?void 0:d.engine.onTransformChange$).pipe(L.throttleTime(33)):L.of(null),[d==null?void 0:d.engine.onTransformChange$]));const C=g<180?"float":"side-bar",T=S==null?void 0:S.filter(k=>{var W;return((W=k.paragraphStyle)==null?void 0:W.namedStyleType)!==void 0&&k.paragraphStyle.namedStyleType!==a.NamedStyleType.SUBTITLE&&k.paragraphStyle.namedStyleType!==a.NamedStyleType.NORMAL_TEXT}).map(k=>{var q;const W=Dl(k.paragraphStyle.namedStyleType),G=h==null?void 0:h.get(k.startIndex);if(!G)return null;const{paragraphStart:K,paragraphEnd:Y}=G;return{id:k.paragraphStyle.headingId,text:a.getPlainText(i.slice(K,Y)),level:W,isTitle:((q=k.paragraphStyle)==null?void 0:q.namedStyleType)===a.NamedStyleType.TITLE}}).filter(k=>k==null?void 0:k.text),R=I.useEvent(k=>{const W=k.viewportScrollY,G=W+p/f,K=Bl(h,E,W,G);K&&l(K)}),v=T!=null&&T.find(k=>k.isTitle)?T:[...u?[{id:ja,text:u,level:1,isTitle:!0}]:[],...T!=null?T:[]].filter(Boolean),[O,M]=w.useState(!0);w.useEffect(()=>{const k=a.debounce(r,100),W=o.onCommandExecuted(G=>{G.id===D.RichTextEditingMutation.id&&G.params.unitId===(e==null?void 0:e.getUnitId())&&k(Y=>Y+1)});return()=>{W.dispose()}},[o,e]),w.useEffect(()=>{const k=d==null?void 0:d.scene.getViewport(se.VIEW_MAIN);if(!k)return;const W=a.fromEventSubject(k.onScrollAfter$).pipe(L.throttleTime(33)).subscribe(R);return()=>{W.unsubscribe()}},[d]);const b=I.useEvent(k=>{const W=d==null?void 0:d.scene.getViewport(se.VIEW_MAIN);if(!W)return;if(k.id===ja){W.scrollToViewportPos({viewportScrollY:0});return}const G=S.find(Y=>{var q;return((q=Y.paragraphStyle)==null?void 0:q.headingId)===k.id});if(!G)return;const K=h==null?void 0:h.get(G.startIndex);K&&(W.scrollToViewportPos({viewportScrollY:K.rect.top}),l(k.id))});return!e||a.isInternalEditorID(A)||!(v!=null&&v.length)?null:P.jsx("div",{className:"univer-absolute univer-bottom-0 univer-left-0 univer-top-0 univer-z-[100] univer-w-[0px]",children:P.jsx(xl,{menus:v,open:O,onOpenChange:M,mode:C,maxWidth:C==="float"?void 0:Math.floor(g),wrapperClass:"univer-mt-12",activeId:c,onClick:b,maxHeight:p-48})})}const un={id:"doc.table.delete-rows",type:a.CommandType.COMMAND,handler:async o=>{const t=o.get(D.DocSelectionManagerService),e=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService),i=t.getRectRanges(),s=t.getActiveTextRange(),r=ht(s,i);if(r==null)return!1;const{segmentId:c}=r,l=e.getCurrentUniverDocInstance(),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c).getBody();if(l==null||A==null)return!1;const d=re(o,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),h=new a.TextX,g=a.JSONX.getInstance(),p=Zi(r,u);if(p==null)return!1;const{offset:f,rowIndexes:S,len:E,tableId:C,cursor:T,selectWholeTable:R}=p;if(R)return n.executeCommand(at.id);const v=[],O=[{startOffset:T,endOffset:T,collapsed:!0}],M={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:O}};f>0&&h.push({t:a.TextXActionType.RETAIN,len:f}),h.push({t:a.TextXActionType.DELETE,len:E});const b=Z(l,c);v.push(g.editOp(h.serialize(),b));for(const x of S.reverse()){const U=g.removeOp(["tableSource",C,"tableRows",x]);v.push(U)}return M.params.actions=v.reduce((x,U)=>a.JSONX.compose(x,U),null),!!n.syncExecuteCommand(M.id,M.params)}},hn={id:"doc.table.delete-columns",type:a.CommandType.COMMAND,handler:async o=>{const t=o.get(D.DocSelectionManagerService),e=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService),i=t.getRectRanges(),s=t.getActiveTextRange(),r=ht(s,i);if(r==null)return!1;const{segmentId:c}=r,l=e.getCurrentUniverDocInstance(),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c).getBody();if(l==null||A==null)return!1;const d=re(o,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),h=new a.TextX,g=a.JSONX.getInstance(),p=xr(r,u);if(p==null)return!1;const{offsets:f,columnIndexes:S,tableId:E,cursor:C,rowCount:T,selectWholeTable:R}=p;if(R)return n.executeCommand(at.id);const v=[],O=[{startOffset:C,endOffset:C,collapsed:!0}],M={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:O}};for(const x of f){const{retain:U,delete:F}=x;U>0&&h.push({t:a.TextXActionType.RETAIN,len:U}),h.push({t:a.TextXActionType.DELETE,len:F})}const b=Z(l,c);v.push(g.editOp(h.serialize(),b)),S.reverse();for(let x=0;x<T;x++)for(const U of S){const F=g.removeOp(["tableSource",E,"tableRows",x,"tableCells",U]);v.push(F)}for(const x of S){const U=g.removeOp(["tableSource",E,"tableColumns",x]);v.push(U)}return M.params.actions=v.reduce((x,U)=>a.JSONX.compose(x,U),null),!!n.syncExecuteCommand(M.id,M.params)}},at={id:"doc.table.delete-table",type:a.CommandType.COMMAND,handler:async o=>{const t=o.get(D.DocSelectionManagerService),e=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService),i=t.getRectRanges(),s=t.getActiveTextRange(),r=ht(s,i);if(r==null)return!1;const{segmentId:c}=r,l=e.getCurrentUniverDocInstance(),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c).getBody();if(l==null||A==null)return!1;const d=re(o,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),h=new a.TextX,g=a.JSONX.getInstance(),p=$i(r,u);if(p==null)return!1;const{offset:f,len:S,tableId:E,cursor:C}=p,T=[],R=[{startOffset:C,endOffset:C,collapsed:!0}],v={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:R}};f>0&&h.push({t:a.TextXActionType.RETAIN,len:f}),h.push({t:a.TextXActionType.DELETE,len:S});const O=Z(l,c);T.push(g.editOp(h.serialize(),O));const M=g.removeOp(["tableSource",E]);return T.push(M),v.params.actions=T.reduce((N,x)=>a.JSONX.compose(N,x),null),!!n.syncExecuteCommand(v.id,v.params)}},Uo="doc.command.table-insert-row",Lo="doc.command.table-insert-column",Pl="doc.command.table-insert-row-above",wl="doc.command.table-insert-row-bellow",Ul="doc.command.table-insert-column-left",Ll="doc.command.table-insert-column-right",gn={id:Pl,type:a.CommandType.COMMAND,handler:async o=>o.get(a.ICommandService).executeCommand(Uo,{position:jt.ABOVE})},mn={id:wl,type:a.CommandType.COMMAND,handler:async o=>o.get(a.ICommandService).executeCommand(Uo,{position:jt.BELLOW})},pn={id:Ul,type:a.CommandType.COMMAND,handler:async o=>o.get(a.ICommandService).executeCommand(Lo,{position:$n.LEFT})},fn={id:Ll,type:a.CommandType.COMMAND,handler:async o=>o.get(a.ICommandService).executeCommand(Lo,{position:$n.RIGHT})},Qo={id:Uo,type:a.CommandType.COMMAND,handler:async(o,t)=>{const{position:e}=t,n=o.get(D.DocSelectionManagerService),i=o.get(a.IUniverInstanceService),s=o.get(a.ICommandService),r=n.getRectRanges(),c=n.getActiveTextRange(),l=ht(c,r);if(l==null)return!1;const{segmentId:A}=l,d=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(A).getBody();if(d==null||u==null)return!1;const m=re(o,d.getUnitId());if(m==null)return!1;const h=m.getViewModel(),g=d==null?void 0:d.getUnitId(),p=new a.TextX,f=a.JSONX.getInstance(),S=Or(l,e,h);if(S==null)return!1;const{offset:E,colCount:C,tableId:T,insertRowIndex:R}=S,v=[],O=E+2,M=[{startOffset:O,endOffset:O,collapsed:!0}],b={id:D.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:M}};E>0&&p.push({t:a.TextXActionType.RETAIN,len:E});const N=yr(C);p.push({t:a.TextXActionType.INSERT,body:N,len:N.dataStream.length});const x=Z(d,A);v.push(f.editOp(p.serialize(),x));const U=Kt(C),F=f.insertOp(["tableSource",T,"tableRows",R],U);return v.push(F),b.params.actions=v.reduce((H,Q)=>a.JSONX.compose(H,Q),null),!!s.syncExecuteCommand(b.id,b.params)}},Xa={id:Lo,type:a.CommandType.COMMAND,handler:async(o,t)=>{var K,Y,q;const{position:e}=t,n=o.get(D.DocSelectionManagerService),i=o.get(a.IUniverInstanceService),s=o.get(a.ICommandService),r=n.getRectRanges(),c=n.getActiveTextRange(),l=ht(c,r);if(l==null)return!1;const{segmentId:A}=l,d=i.getCurrentUniverDocInstance(),u=d==null?void 0:d.getSelfOrHeaderFooterModel(A).getBody();if(d==null||u==null)return!1;const m=re(o,d.getUnitId());if(m==null)return!1;const h=m.getViewModel(),g=d==null?void 0:d.getUnitId(),p=new a.TextX,f=a.JSONX.getInstance(),S=Rr(l,e,h);if(S==null)return!1;const{offsets:E,columnIndex:C,tableId:T,rowCount:R}=S,v=[],O=E[0]+1,M=[{startOffset:O,endOffset:O,collapsed:!0}],b={id:D.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:M}};for(const z of E){p.push({t:a.TextXActionType.RETAIN,len:z});const $=br();p.push({t:a.TextXActionType.INSERT,body:$,len:$.dataStream.length})}const N=Z(d,A);v.push(f.editOp(p.serialize(),N));for(let z=0;z<R;z++){const $=Xt(),ie=f.insertOp(["tableSource",T,"tableRows",z,"tableCells",C],$);v.push(ie)}const x=d.getSnapshot(),U=x.documentStyle,{marginLeft:F=0,marginRight:V=0}=U,H=((Y=(K=U.pageSize)==null?void 0:K.width)!=null?Y:800)-F-V,Q=(q=x==null?void 0:x.tableSource)==null?void 0:q[T].tableColumns,{newColWidth:X,widths:j}=Mr(H,Q,C);for(let z=0;z<j.length;z++){const $=f.replaceOp(["tableSource",T,"tableColumns",z,"size","width","v"],Q[z].size.width.v,j[z]);v.push($)}const k=zt(X),W=f.insertOp(["tableSource",T,"tableColumns",C],k);return v.push(W),b.params.actions=v.reduce((z,$)=>a.JSONX.compose(z,$),null),!!s.syncExecuteCommand(b.id,b.params)}},pe={id:"doc-paragraph-setting.command",type:a.CommandType.COMMAND,handler:async(o,t)=>{var C,T,R,v,O;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),s=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),r=e.getDocRanges();if(!s||r.length===0||!t)return!1;const c=r[0].segmentId,l=s.getUnitId(),A=s.getSelfOrHeaderFooterModel(c),d=(T=(C=A.getBody())==null?void 0:C.paragraphs)!=null?T:[],u=(v=(R=A.getBody())==null?void 0:R.dataStream)!=null?v:"",m=(O=a.BuildTextUtils.range.getParagraphsInRanges(r,d,u))!=null?O:[],h={id:D.RichTextEditingMutation.id,params:{unitId:l,actions:[],textRanges:r}},g=new a.MemoryCursor;g.reset();const p=new a.TextX,f=a.JSONX.getInstance();for(const M of m){const{startIndex:b}=M;p.push({t:a.TextXActionType.RETAIN,len:b-g.cursor});const N={...M.paragraphStyle,...t.paragraph};p.push({t:a.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...M,paragraphStyle:N,startIndex:0}]},coverType:a.UpdateDocsAttributeType.REPLACE}),g.moveCursorTo(b+1)}const S=Z(s,c);return h.params.actions=f.editOp(p.serialize(),S),!!i.syncExecuteCommand(h.id,h.params)}},Ql=()=>{const o=I.useDependency(D.DocSelectionManagerService),t=I.useDependency(st),e=w.useMemo(()=>o.getDocRanges(),[]);return w.useEffect(()=>{e.length||t.closePanel()},[e]),e},Fl=()=>{var l,A,d,u,m;const t=I.useDependency(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),e=Ql();if(!t||e.length===0)return[];const n=e[0].segmentId,i=t.getSelfOrHeaderFooterModel(n),s=(A=(l=i.getBody())==null?void 0:l.paragraphs)!=null?A:[],r=(u=(d=i.getBody())==null?void 0:d.dataStream)!=null?u:"";return(m=a.BuildTextUtils.range.getParagraphsInRanges(e,s,r))!=null?m:[]},Hl=(o,t)=>{const e=I.useDependency(a.ICommandService),[n,i]=w.useState(()=>{var c,l;const r=o[0];return r?String((l=(c=r.paragraphStyle)==null?void 0:c.horizontalAlign)!=null?l:t):t});return[n,r=>(i(r),e.executeCommand(pe.id,{paragraph:{horizontalAlign:Number(r)}}))]},kl=o=>{const t=I.useDependency(a.ICommandService),[e,n]=w.useState(()=>{var r;const s=o[0];return s?_.getNumberUnitValue((r=s.paragraphStyle)==null?void 0:r.indentStart,0):0});return[e,s=>(n(s),t.executeCommand(pe.id,{paragraph:{indentStart:{v:s}}}))]},Vl=o=>{const t=I.useDependency(a.ICommandService),[e,n]=w.useState(()=>{var r;const s=o[0];return s?_.getNumberUnitValue((r=s.paragraphStyle)==null?void 0:r.indentEnd,0):0});return[e,s=>(n(s),t.executeCommand(pe.id,{paragraph:{indentEnd:{v:s}}}))]},Wl=o=>{const t=I.useDependency(a.ICommandService),[e,n]=w.useState(()=>{var r;const s=o[0];return s?_.getNumberUnitValue((r=s.paragraphStyle)==null?void 0:r.indentFirstLine,0):0});return[e,s=>(n(s),t.executeCommand(pe.id,{paragraph:{indentFirstLine:{v:s}}}))]},Gl=o=>{const t=I.useDependency(a.ICommandService),[e,n]=w.useState(()=>{var r;const s=o[0];return s?_.getNumberUnitValue((r=s.paragraphStyle)==null?void 0:r.hanging,0):0});return[e,s=>(n(s),t.executeCommand(pe.id,{paragraph:{hanging:{v:s}}}))]},jl=o=>{const t=I.useDependency(a.ICommandService),[e,n]=w.useState(()=>{var r;const s=o[0];return s?_.getNumberUnitValue((r=s.paragraphStyle)==null?void 0:r.spaceAbove,0):0});return[e,s=>(n(s),t.executeCommand(pe.id,{paragraph:{spaceAbove:{v:s}}}))]},Xl=o=>{const t=I.useDependency(a.ICommandService),[e,n]=w.useState(()=>{var r;const s=o[0];return s?_.getNumberUnitValue((r=s.paragraphStyle)==null?void 0:r.spaceBelow,0):0});return[e,s=>(n(s),t.executeCommand(pe.id,{paragraph:{spaceBelow:{v:s}}}))]},Kl=o=>{const t=I.useDependency(a.ICommandService),e=I.useDependency(_.IRenderManagerService),n=I.useDependency(a.IUniverInstanceService),i=w.useMemo(()=>{var g;const h=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(h)return(g=e.getRenderById(h==null?void 0:h.getUnitId()))==null?void 0:g.with(D.DocSkeletonManagerService).getSkeleton()},[]),s=w.useMemo(()=>new L.BehaviorSubject({}),[]),[r,c]=w.useState(()=>{var g,p;const h=o[0];return h&&(p=(g=h.paragraphStyle)==null?void 0:g.lineSpacing)!=null?p:1}),l=w.useRef(r),[A,d]=w.useState(()=>{var g,p;const h=o[0];return h&&(p=(g=h.paragraphStyle)==null?void 0:g.spacingRule)!=null?p:a.SpacingRule.AUTO}),u=async h=>{c(h),s.next({lineSpacing:h,spacingRule:A})},m=async h=>{if(h!==A){let g=l.current;if(h===a.SpacingRule.AT_LEAST){const p=i==null?void 0:i.findNodeByCharIndex(o[0].startIndex),f=p==null?void 0:p.parent,S=f==null?void 0:f.parent;(S==null?void 0:S.contentHeight)!==void 0&&(g=Math.max(S.contentHeight,g))}else g>5&&(g=2);l.current=r,u(g),d(h),s.next({spacingRule:h})}};return w.useEffect(()=>{const h=s.pipe(dt.filter(g=>!!Object.keys(g).length),dt.bufferTime(16),dt.filter(g=>!!g.length),dt.map(g=>g.reduce((p,f)=>(Object.keys(f).forEach(S=>{p[S]=f[S]}),p),{}))).subscribe(g=>t.executeCommand(pe.id,{paragraph:{...g}}));return()=>h.unsubscribe()},[]),{lineSpacing:[r,u],spacingRule:[A,m]}},Ke=o=>{const{value:t,onChange:e,className:n="",min:i=0,max:s=100,step:r=1}=o,c=w.useRef(null);return P.jsx(J.InputNumber,{step:r,ref:c,min:i,max:s,value:t,onChange:l=>{e(l!=null?l:0).finally(()=>{setTimeout(()=>{var A;(A=c.current)==null||A.focus()},30)})},className:n})};function zl(){const o=I.useDependency(a.LocaleService),t=w.useMemo(()=>[{label:o.t("toolbar.alignLeft"),value:String(a.HorizontalAlign.LEFT),icon:P.jsx(Qi,{})},{label:o.t("toolbar.alignCenter"),value:String(a.HorizontalAlign.CENTER),icon:P.jsx(Ui,{})},{label:o.t("toolbar.alignRight"),value:String(a.HorizontalAlign.RIGHT),icon:P.jsx(Fi,{})},{label:o.t("toolbar.alignJustify"),value:String(a.HorizontalAlign.JUSTIFIED),icon:P.jsx(bi,{})}],[]),e=Fl(),[n,i]=Hl(e,t[0].value),[s,r]=kl(e),[c,l]=Vl(e),[A,d]=Wl(e),[u,m]=Gl(e),[h,g]=jl(e),[p,f]=Xl(e),{lineSpacing:[S,E],spacingRule:[C,T]}=Kl(e),R=w.useMemo(()=>C===a.SpacingRule.AUTO?{min:1,max:5,step:S<2?.5:1}:{min:1,max:100},[C,S]);return P.jsxs("div",{children:[P.jsx("div",{className:"univer-t-4 univer-text-sm univer-font-medium",children:o.t("doc.paragraphSetting.alignment")}),P.jsx("div",{className:J.clsx("univer-mt-4 univer-box-border univer-flex univer-w-full univer-items-center univer-justify-between univer-gap-1 univer-rounded-md univer-p-1",J.borderClassName),children:t.map(v=>P.jsx(J.Tooltip,{title:v.label,placement:"bottom",children:P.jsx("span",{className:J.clsx("hover:univer-bg-black/60 univer-flex univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-bg-none univer-px-3 univer-py-1",{"univer-bg-blend-color-dodge/90":n===v.value}),onClick:()=>i(v.value),children:v.icon})},v.value))}),P.jsx("div",{className:"univer-t-4 univer-text-sm univer-font-medium",children:o.t("doc.paragraphSetting.indentation")}),P.jsxs("div",{children:[P.jsxs("div",{className:"univer-item-center univer-flex univer-justify-between",children:[P.jsxs("div",{className:"univer-mt-3 univer-text-xs",children:[o.t("doc.paragraphSetting.left"),"(px)"]}),P.jsx(Ke,{className:"univer-mt-4",value:s,onChange:v=>r(v!=null?v:0)})]}),P.jsxs("div",{className:"univer-item-center univer-flex univer-justify-between",children:[P.jsxs("div",{className:"univer-mt-3 univer-text-xs",children:[o.t("doc.paragraphSetting.right"),"(px)"]}),P.jsx(Ke,{className:"univer-mt-4",value:c,onChange:v=>l(v!=null?v:0)})]}),P.jsxs("div",{className:"univer-item-center univer-flex univer-justify-between",children:[P.jsxs("div",{className:"univer-mt-3 univer-text-xs",children:[o.t("doc.paragraphSetting.firstLine"),"(px)"]}),P.jsx(Ke,{className:"univer-mt-4",value:A,onChange:v=>d(v!=null?v:0)})]}),P.jsxs("div",{className:"univer-item-center univer-flex univer-justify-between",children:[P.jsxs("div",{className:"univer-mt-3 univer-text-xs",children:[o.t("doc.paragraphSetting.hanging"),"(px)"]}),P.jsx(Ke,{className:"univer-mt-4",value:u,onChange:v=>m(v!=null?v:0)})]})]}),P.jsx("div",{className:"univer-t-4 univer-text-sm univer-font-medium",children:o.t("doc.paragraphSetting.spacing")}),P.jsxs("div",{children:[P.jsxs("div",{className:"univer-justify-betweenuniver-item-center univer-flex",children:[P.jsxs("div",{className:"univer-mt-3 univer-text-xs",children:[o.t("doc.paragraphSetting.before"),"(px)"]}),P.jsx(Ke,{className:"univer-mt-4",value:h,onChange:v=>g(v!=null?v:0)})]}),P.jsxs("div",{className:"univer-item-center univer-flex univer-justify-between",children:[P.jsxs("div",{className:"univer-mt-3 univer-text-xs",children:[o.t("doc.paragraphSetting.after"),"(px)"]}),P.jsx(Ke,{className:"univer-mt-4",value:p,onChange:v=>f(v!=null?v:0)})]}),P.jsxs("div",{className:"item-center univer-flex univer-justify-between",children:[P.jsx("div",{className:"univer-mt-3 univer-text-xs",children:o.t("doc.paragraphSetting.lineSpace")}),P.jsxs("div",{className:"univer-mt-4 univer-flex univer-w-[162px] univer-flex-col univer-gap-1.5",children:[P.jsx(J.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=>T(Number(v))}),P.jsx(Ke,{...R,value:S,onChange:v=>E(v!=null?v:0)})]})]})]})]})}const Yl=(o,t)=>t.length===o.length&&o.some(e=>t.some(n=>n.startOffset===e.startOffset&&n.endOffset===e.endOffset));function ql(){const o=I.useDependency(a.ICommandService),t=I.useDependency(a.LocaleService),e=I.useObservable(t.currentLocale$),[n,i]=w.useState(""),s=w.useMemo(()=>a.debounce(()=>i(a.generateRandomId(4)),300),[]),r=w.useRef([]);return w.useEffect(()=>{const c=o.onCommandExecuted(l=>{if(D.SetTextSelectionsOperation.id===l.id){const A=l.params.ranges;Yl(A,r.current)||i(a.generateRandomId(4)),r.current=A}D.RichTextEditingMutation.id===l.id&&l.params.trigger!==pe.id&&s()});return()=>c.dispose()},[s]),w.useEffect(()=>{i(a.generateRandomId(4))},[e]),w.useEffect(()=>()=>s.cancel(),[s]),P.jsx(zl,{},n)}var Jl=Object.getOwnPropertyDescriptor,Zl=(o,t,e,n)=>{for(var i=n>1?void 0:n?Jl(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Fo=(o,t)=>(e,n)=>t(e,n,o);const Ka="doc_ui_paragraph-setting-panel";let st=class extends a.Disposable{constructor(t,e,n){super();B(this,"_id");this._commandService=t,this._componentManager=e,this._sidebarService=n,this._init()}_init(){this.disposeWithMe(this._componentManager.register(Ka,ql))}openPanel(){const t={header:{title:"doc.slider.paragraphSetting"},id:this._id,children:{label:Ka},width:300};this._sidebarService.open(t)}closePanel(){this._sidebarService.close(this._id)}};st=Zl([Fo(0,a.ICommandService),Fo(1,a.Inject(I.ComponentManager)),Fo(2,a.Inject(I.ISidebarService))],st);const Ho={id:"sidebar.operation.doc-paragraph-setting-panel",type:a.CommandType.OPERATION,handler:o=>(o.get(st).openPanel(),!0)},ko=o=>{const t=o.get(D.DocSelectionManagerService);return new L.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 $l(o){if(o.length<2)return!0;const t=o.map(e=>e.tableId);return t.every(e=>e===t[0])}function za(o,t,e){var s;const n=t.getRectRanges(),i=t.getActiveTextRange();if(n&&n.length&&$l(n)&&i==null){o.next(!1);return}if(i&&(n==null||n.length===0)){const{segmentId:r,startOffset:c,endOffset:l}=i,A=e.getCurrentUniverDocInstance(),d=(s=A==null?void 0:A.getSelfOrHeaderFooterModel(r).getBody())==null?void 0:s.tables;if(d&&d.length&&d.some(u=>{const{startIndex:m,endIndex:h}=u;return c>m&&c<h||l>m&&l<h})){o.next(!1);return}}o.next(!0)}const Oe=o=>{const t=o.get(D.DocSelectionManagerService),e=o.get(a.IUniverInstanceService);return new L.Observable(n=>{const i=t.textSelection$.subscribe(()=>{za(n,t,e)});return za(n,t,e),()=>i.unsubscribe()})},ed=o=>({id:ft.name,commandId:ft.id,type:I.MenuItemType.BUTTON,icon:"CopyDoubleIcon",title:"rightClick.copy",disabled$:ko(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}),td=o=>({id:Ho.id,type:I.MenuItemType.BUTTON,icon:"MenuIcon",title:"doc.menu.paragraphSetting",hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}),nd=o=>({id:$t.id,type:I.MenuItemType.BUTTON,icon:"CopyDoubleIcon",title:"rightClick.cut",disabled$:ko(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}),od=o=>({id:en.id,type:I.MenuItemType.BUTTON,icon:"PasteSpecialDoubleIcon",title:"rightClick.paste",hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}),id=o=>({id:mt.id,type:I.MenuItemType.BUTTON,icon:"PasteSpecialDoubleIcon",title:"rightClick.delete",disabled$:ko(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}),Ya="doc.menu.table-insert";function ad(o){return{id:Ya,type:I.MenuItemType.SUBITEMS,title:"table.insert",icon:"InsertDoubleIcon",hidden$:L.combineLatest(I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC),Oe(o),(t,e)=>t||e)}}function sd(o){return{id:gn.id,type:I.MenuItemType.BUTTON,title:"table.insertRowAbove",icon:"InsertRowAboveDoubleIcon",disabled$:Oe(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function rd(o){return{id:mn.id,type:I.MenuItemType.BUTTON,title:"table.insertRowBelow",icon:"InsertRowBelowDoubleIcon",disabled$:Oe(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function cd(o){return{id:pn.id,type:I.MenuItemType.BUTTON,title:"table.insertColumnLeft",icon:"LeftInsertColumnDoubleIcon",disabled$:Oe(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function ld(o){return{id:fn.id,type:I.MenuItemType.BUTTON,title:"table.insertColumnRight",icon:"RightInsertColumnDoubleIcon",disabled$:Oe(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}const qa="doc.menu.table-delete";function dd(o){return{id:qa,type:I.MenuItemType.SUBITEMS,title:"table.delete",icon:"ReduceDoubleIcon",hidden$:L.combineLatest(I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC),Oe(o),(t,e)=>t||e)}}function Ad(o){return{id:un.id,type:I.MenuItemType.BUTTON,title:"table.deleteRows",icon:"DeleteRowDoubleIcon",disabled$:Oe(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function ud(o){return{id:hn.id,type:I.MenuItemType.BUTTON,title:"table.deleteColumns",icon:"DeleteColumnDoubleIcon",disabled$:Oe(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function hd(o){return{id:at.id,type:I.MenuItemType.BUTTON,title:"table.deleteTable",icon:"GridIcon",disabled$:Oe(o),hidden$:I.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}const Ja={[I.RibbonStartGroup.FORMAT]:{[De.id]:{order:0,menuItemFactory:ic},[Be.id]:{order:1,menuItemFactory:ac},[_e.id]:{order:2,menuItemFactory:sc},[Ne.id]:{order:3,menuItemFactory:rc},[ye.id]:{order:4,menuItemFactory:cc},[Pe.id]:{order:5,menuItemFactory:lc},[de.id]:{order:5.5,menuItemFactory:uc},[ge.id]:{order:6,menuItemFactory:Ac},[We.id]:{order:7,menuItemFactory:dc},[we.id]:{order:8,menuItemFactory:hc},[Ue.id]:{order:9,menuItemFactory:bc,[et.id]:{order:0,menuItemFactory:yc}}},[I.RibbonStartGroup.LAYOUT]:{[Ct.id]:{order:2,menuItemFactory:Sc},[Tt.id]:{order:3,menuItemFactory:Ic},[yt.id]:{order:4,menuItemFactory:vc},[bt.id]:{order:5,menuItemFactory:Ec},[St.id]:{order:6,menuItemFactory:Cc},[ot.id]:{order:7,menuItemFactory:Pa},[nt.id]:{order:8,menuItemFactory:wa},[Et.id]:{order:9,menuItemFactory:Ua},[Jn.id]:{order:10,menuItemFactory:gc},[Ot.id]:{order:11,menuItemFactory:Tc},[Po.id]:{order:12,menuItemFactory:Oc}},[I.RibbonInsertGroup.MEDIA]:{[Na]:{order:2,menuItemFactory:pc,[sn.id]:{order:0,menuItemFactory:fc}}},[I.ContextMenuPosition.MAIN_AREA]:{[I.ContextMenuGroup.FORMAT]:{[ft.name]:{order:0,menuItemFactory:ed},[$t.id]:{order:1,menuItemFactory:nd},[en.id]:{order:2,menuItemFactory:od},[mt.id]:{order:3,menuItemFactory:id}},[I.ContextMenuGroup.LAYOUT]:{[Ho.id]:{order:0,menuItemFactory:td},[Ya]:{order:1,menuItemFactory:ad,[gn.id]:{order:1,menuItemFactory:sd},[mn.id]:{order:2,menuItemFactory:rd},[pn.id]:{order:3,menuItemFactory:cd},[fn.id]:{order:4,menuItemFactory:ld}},[qa]:{order:2,menuItemFactory:dd,[un.id]:{order:1,menuItemFactory:Ad},[hn.id]:{order:2,menuItemFactory:ud},[at.id]:{order:3,menuItemFactory:hd}}}},[I.ContextMenuPosition.PARAGRAPH]:{[I.ContextMenuGroup.QUICK]:{[Oo.id]:{order:0,menuItemFactory:Mc},[Ro.id]:{order:1,menuItemFactory:xc},[Mo.id]:{order:2,menuItemFactory:Dc},[xo.id]:{order:3,menuItemFactory:Bc},[Do.id]:{order:4,menuItemFactory:_c},[an.id]:{order:5,menuItemFactory:Nc},[ot.id]:{order:6,menuItemFactory:Pa},[nt.id]:{order:7,menuItemFactory:wa},[Et.id]:{order:8,menuItemFactory:Ua}},[I.ContextMenuGroup.FORMAT]:{[ho.id]:{order:0,menuItemFactory:Pc},[go.id]:{order:1,menuItemFactory:wc},[so.id]:{order:2,menuItemFactory:Uc}},[I.ContextMenuGroup.LAYOUT]:{[Qa]:{menuItemFactory:kc,[Co.id]:{order:0,menuItemFactory:Lc},[To.id]:{order:1,menuItemFactory:Qc},[yo.id]:{order:2,menuItemFactory:Fc},[fo.id]:{order:3,menuItemFactory:Hc}}}}};var gd=Object.getOwnPropertyDescriptor,md=(o,t,e,n)=>{for(var i=n>1?void 0:n?gd(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Re=(o,t)=>(e,n)=>t(e,n,o);y.DocUIController=class extends a.Disposable{constructor(t,e,n,i,s,r,c,l,A){super(),this._injector=t,this._componentManager=e,this._commandService=n,this._layoutService=i,this._menuManagerService=s,this._uiPartsService=r,this._univerInstanceService=c,this._shortcutService=l,this._configService=A,this._init()}_initCustomComponents(){[[Ji,Cr],[qi,vr],["TodoListDoubleIcon",Hi],["doc.paragraph.menu",il],["CutIcon",Ri],["DeleteIcon",Mi],[No,ec],["DocumentSettingIcon",xi]].forEach(([t,e])=>{this.disposeWithMe(this._componentManager.register(t,e))})}_initUiParts(){this.disposeWithMe(this._uiPartsService.registerComponent(I.BuiltInUIPart.FOOTER,()=>I.connectInjector(yl,this._injector))),this.disposeWithMe(this._uiPartsService.registerComponent(I.BuiltInUIPart.CONTENT,()=>I.connectInjector(_l,this._injector)))}_initMenus(){this._menuManagerService.mergeMenu(Ja)}_initShortCut(){[cl,ll,dl,Al,ul,hl,pl,fl,ml,gl,Sl,Il,sl].forEach(t=>{this.disposeWithMe(this._shortcutService.registerShortcut(t))})}_init(){this._initCustomComponents(),this._initMenus(),this._initFocusHandler(),this._initCommands(),this._initUiParts(),this._initShortCut()}_initCommands(){[Ki,Jn,Yn].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(a.UniverInstanceType.UNIVER_DOC,t=>{this._injector.get(_.IRenderManagerService).getRenderById(t).with(y.DocSelectionRenderService).focus()}))}},y.DocUIController=md([Re(0,a.Inject(a.Injector)),Re(1,a.Inject(I.ComponentManager)),Re(2,a.ICommandService),Re(3,I.ILayoutService),Re(4,I.IMenuManagerService),Re(5,I.IUIPartsService),Re(6,a.IUniverInstanceService),Re(7,I.IShortcutService),Re(8,a.IConfigService)],y.DocUIController);var pd=Object.getOwnPropertyDescriptor,fd=(o,t,e,n)=>{for(var i=n>1?void 0:n?pd(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Vo=(o,t)=>(e,n)=>t(e,n,o);const Za=1.5;y.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(L.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 N;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:l}=r,A=new ve(r,s),{contentBoxPointGroup:d}=A.getRangePointData(t,t),{left:u,top:m,height:h}=At(d),g=u+c,p=m+l,f=n.getViewport(se.VIEW_MAIN),S=this._editorService.getEditor(e);if(f==null)return;const{left:E,top:C,right:T,bottom:R}=f.getBounding().viewBound;let v=0,O=0;const M=S?(N=S.params.backScrollOffset)!=null?N:0:100;p<C?v=p-C-M:p>R-h&&(v=p-R+h+M),g<E?O=g-E:g>T-Za&&(O=g-T+Za);const b=f.transViewportScroll2ScrollValue(O,v);f.scrollByBarDeltaValue(b)}_scrollToSelection(){const t=this._textSelectionManagerService.getActiveTextRange();if(t==null)return;const{collapsed:e,startNodePosition:n}=t;e&&this.scrollToNode(n)}},y.DocBackScrollRenderController=fd([Vo(1,a.Inject(D.DocSelectionManagerService)),Vo(2,ce),Vo(3,a.Inject(D.DocSkeletonManagerService))],y.DocBackScrollRenderController);var Sd=Object.getOwnPropertyDescriptor,Id=(o,t,e,n)=>{for(var i=n>1?void 0:n?Sd(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);y.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(D.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 _.Viewport(se.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 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,r)}),new _.ScrollBar(n),t.addLayer(new _.Layer(t,[],Ut),new _.Layer(t,[],ci)),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 _.Documents(Ae.MAIN,void 0,r);c.zIndex=Dn;const l=new _.DocBackground(Ae.BACKGROUND,void 0,r);l.zIndex=Dn,this._context.mainComponent=c,n.set(Ae.MAIN,c),n.set(Ae.BACKGROUND,l),t.addObjects([c],Ut),t.addObjects([l],ri),this._editorService.getEditor(e.getUnitId())==null&&t.enableLayerCache(Ut)}_initRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(L.takeUntil(this.dispose$)).subscribe(t=>{this._create(t)})}_create(t){var l;if(!t)return;const{mainComponent:e,components:n}=this._context,i=e,s=n.get(Ae.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)){(l=this._context.mainComponent)==null||l.makeDirty();return}this._recalculateSizeBySkeleton(t)}_initCommandListener(){const t=[D.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 g;const{mainComponent:e,scene:n,unitId:i,components:s}=this._context,r=e,c=s.get(Ae.BACKGROUND),l=(g=t.getSkeletonData())==null?void 0:g.pages;if(l==null)return;let A=0,d=0;const m=this._context.unit.getSnapshot().documentStyle.documentFlavor;for(let p=0,f=l.length;p<f;p++){const S=l[p];let{pageWidth:E,pageHeight:C}=S;if(m===a.DocumentFlavor.MODERN){const T=vd(S);E=T.pageWidth,C=T.pageHeight}r.pageLayoutType===_.PageLayoutType.VERTICAL?(d+=C,d+=r.pageMarginTop,p===f-1&&(d+=r.pageMarginTop),A=Math.max(A,E)):r.pageLayoutType===_.PageLayoutType.HORIZONTAL&&(A+=E,p!==f-1&&(A+=r.pageMarginLeft),d=Math.max(d,C))}r.resize(A,d),c.resize(A,d);const h=this._editorService.getEditor(i);(!this._editorService.isEditor(i)||h!=null&&h.params.scrollBar)&&n.resize(A,d)}},y.DocRenderController=Id([rt(1,a.ICommandService),rt(2,a.Inject(y.DocSelectionRenderService)),rt(3,a.Inject(D.DocSkeletonManagerService)),rt(4,ce),rt(5,_.IRenderManagerService),rt(6,a.IUniverInstanceService)],y.DocRenderController);function vd(o){let{pageWidth:t,pageHeight:e}=o;const{marginLeft:n,marginRight:i,marginTop:s,marginBottom:r,skeDrawings:c,skeTables:l}=o;t===Number.POSITIVE_INFINITY&&(t=o.width+n+i),e===Number.POSITIVE_INFINITY&&(e=o.height+s+r);for(const A of c.values())t=Math.max(t,A.aLeft+A.width+n+i),e=Math.max(e,A.aTop+A.height+s+r);for(const A of l.values())t=Math.max(t,A.left+A.width+n+i),e=Math.max(e,A.top+A.height+s+r);return{pageWidth:t,pageHeight:e}}const Wo={id:"doc.command.select-all",type:a.CommandType.COMMAND,handler:async o=>{var h;const t=o.get(a.IUniverInstanceService),e=o.get(D.DocSelectionManagerService),n=t.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),i=e.getDocRanges(),s=(h=i.find(g=>g.isActive))!=null?h:i[0];if(n==null||s==null)return!1;const{segmentId:r}=s,c=n.getUnitId(),l=n.getSelfOrHeaderFooterModel(r).getSnapshot().body;if(l==null)return!1;const{tables:A=[],dataStream:d}=l;if(d===`\r
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/preset-docs-core",
|
|
3
|
-
"version": "0.8.1-nightly.
|
|
3
|
+
"version": "0.8.1-nightly.202506181607",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -57,16 +57,16 @@
|
|
|
57
57
|
"rxjs": ">=7.0.0"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@univerjs/design": "0.8.1-nightly.
|
|
61
|
-
"@univerjs/docs": "0.8.1-nightly.
|
|
62
|
-
"@univerjs/docs-ui": "0.8.1-nightly.
|
|
63
|
-
"@univerjs/engine-formula": "0.8.1-nightly.
|
|
64
|
-
"@univerjs/engine-render": "0.8.1-nightly.
|
|
65
|
-
"@univerjs/network": "0.8.1-nightly.
|
|
66
|
-
"@univerjs/ui": "0.8.1-nightly.
|
|
60
|
+
"@univerjs/design": "0.8.1-nightly.202506181607",
|
|
61
|
+
"@univerjs/docs": "0.8.1-nightly.202506181607",
|
|
62
|
+
"@univerjs/docs-ui": "0.8.1-nightly.202506181607",
|
|
63
|
+
"@univerjs/engine-formula": "0.8.1-nightly.202506181607",
|
|
64
|
+
"@univerjs/engine-render": "0.8.1-nightly.202506181607",
|
|
65
|
+
"@univerjs/network": "0.8.1-nightly.202506181607",
|
|
66
|
+
"@univerjs/ui": "0.8.1-nightly.202506181607"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@univerjs/core": "0.8.1-nightly.
|
|
69
|
+
"@univerjs/core": "0.8.1-nightly.202506181607",
|
|
70
70
|
"react": "18.3.1",
|
|
71
71
|
"react-dom": "18.3.1",
|
|
72
72
|
"rxjs": "7.8.2",
|