@univerjs/docs-ui 0.6.10-nightly.202504101607 → 0.6.10-nightly.202504121606

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -39,7 +39,7 @@ ${i.DataStreamTreeTokenType.TABLE_CELL_END}`;break}}}_processBeforeLink(t,e){ret
39
39
  `)||(r+=`\r
40
40
  `,e.push({startIndex:r.length-2}),n.push({startIndex:r.length-1}),t.dataStream=r,t.paragraphs=e,t.sectionBreaks=n);const s={html:""},a=D.parseDataStreamToTree(r).sectionList;for(const c of a)$e(c,o,s);return s.html}function $e(o,t,e){var n,r;switch(o.nodeType){case i.DataStreamTreeNodeType.SECTION_BREAK:{for(const s of o.children)$e(s,t,e);break}case i.DataStreamTreeNodeType.PARAGRAPH:{const{children:s,startIndex:a,endIndex:c}=o,l=(r=(n=t.body)==null?void 0:n.paragraphs.find(h=>h.startIndex===c))!=null?r:{},{paragraphStyle:A={}}=l,{spaceAbove:d,spaceBelow:u,lineSpacing:m}=A,g=[];if(d!=null&&(typeof d=="number"?g.push(`margin-top: ${d}px`):g.push(`margin-top: ${d.v}px`)),u!=null&&(typeof u=="number"?g.push(`margin-bottom: ${u}px`):g.push(`margin-bottom: ${u.v}px`)),m!=null&&g.push(`line-height: ${m}`),e.html+=`<p class="UniverNormal" ${g.length?`style="${g.join("; ")};"`:""}>`,s.length)for(const h of s)$e(h,t,e);e.html+=`${Va(t,a,c)}</p>`;break}case i.DataStreamTreeNodeType.TABLE:{const{children:s}=o;e.html+='<table class="UniverTable" style="width: 100%; border-collapse: collapse;"><tbody>';for(const a of s)$e(a,t,e);e.html+="</tbody></table>";break}case i.DataStreamTreeNodeType.TABLE_ROW:{const{children:s}=o;e.html+='<tr class="UniverTableRow">';for(const a of s)$e(a,t,e);e.html+="</tr>";break}case i.DataStreamTreeNodeType.TABLE_CELL:{const{children:s}=o;e.html+='<td class="UniverTableCell">';for(const a of s)$e(a,t,e);e.html+="</td>";break}default:throw new Error(`Unknown node type: ${o.nodeType}`)}}class Wa{convert(t){if(t.length===0)throw new Error("The bodyList length at least to be 1");let e="";for(const n of i.Tools.deepClone(t))e+=ja(n);return e}}var za=Object.getOwnPropertyDescriptor,Ga=(o,t,e,n)=>{for(var r=n>1?void 0:n?za(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},dt=(o,t)=>(e,n)=>t(e,n,o);tt.use(zi);tt.use(Vi);tt.use(Wi);function fr(o,t,e){var s,a,c;const n=i.getBodySlice(o,t,e+2),r=i.DataStreamTreeTokenType.TABLE_START+i.DataStreamTreeTokenType.TABLE_ROW_START+i.DataStreamTreeTokenType.TABLE_CELL_START+n.dataStream+i.DataStreamTreeTokenType.TABLE_CELL_END+i.DataStreamTreeTokenType.TABLE_ROW_END+i.DataStreamTreeTokenType.TABLE_END;return n.dataStream=r,(s=n.textRuns)==null||s.forEach(l=>{const{st:A,ed:d}=l;l.st=A+3,l.ed=d+3}),(a=n.tables)==null||a.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 Be=i.createIdentifier("doc.clipboard-service");let qn=class extends i.Disposable{constructor(t,e,n,r,s){super();x(this,"_clipboardHooks",[]);x(this,"_htmlToUDM",new tt);x(this,"_umdToHtml",new Wa);this._univerInstanceService=t,this._logService=e,this._commandService=n,this._clipboardInterfaceService=r,this._docSelectionManagerService=s}async copy(t=i.SliceBodyType.copy,e){var c,l;const{newSnapshotList:n=[],needCache:r=!1,snapshot:s,ranges:a}=(c=this._getDocumentBodyInRanges(t,e))!=null?c:{};if(n.length===0||s==null)return!1;try{const A=!!((l=a==null?void 0:a[0])!=null&&l.segmentId);this._setClipboardData(n,!A&&r)}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:r}=t;const s=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),a=(s==null?void 0:s.getUnitId())||"";!e&&!n&&r.length&&(e=await this._createImagePasteHtml(r));const c=this._genDocDataFromHtmlAndText(e,n,a);if(a===i.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)if(n){const l=i.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===i.DOC_RANGE_TYPE.TEXT))!=null?c:this._docSelectionManagerService.getTextRanges())!=null?l:[],n=(d=(A=t==null?void 0:t.filter(m=>m.rangeType===i.DOC_RANGE_TYPE.RECT))!=null?A:this._docSelectionManagerService.getRectRanges())!=null?d:[],{segmentId:r,endOffset:s,style:a}=(u=e[0])!=null?u:{};if(r==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),e.length===0&&n.length===0)return!1;this.copy(i.SliceBodyType.cut,t);try{let m=0;if(n.length>0)m=mn(e,n);else if(s!=null){m=s;for(const h of e){const{startOffset:p,endOffset:f}=h;p==null||f==null||f<=s&&(m-=f-p)}}const g=[{startOffset:m,endOffset:m,style:a}];return this._commandService.executeCommand(je.id,{segmentId:r,textRanges:g,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=i.normalizeBody(e);if(!((d=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC))==null?void 0:d.getUnitId()))return!1;this._clipboardHooks.forEach(g=>{g.onBeforePaste&&(n=g.onBeforePaste(n))}),n.customRanges=(u=n.customRanges)==null?void 0:u.map(i.BuildTextUtils.customRange.copyCustomRange),(m=n.paragraphs)==null||m.forEach(g=>{var h;(h=g.paragraphStyle)!=null&&h.headingId&&(g.paragraphStyle.headingId=i.generateRandomId(6))});const s=this._docSelectionManagerService.getActiveTextRange(),{segmentId:a,endOffset:c,style:l}=s||{},A=this._docSelectionManagerService.getTextRanges();if(a==null&&this._logService.error("[DocClipboardController] segmentId does not exist!"),c==null||A==null)return!1;try{let g=c;for(const p of A){const{startOffset:f,endOffset:S}=p;f==null||S==null||S<=c&&(g+=n.dataStream.length-(S-f))}const h=[{startOffset:g,endOffset:g,style:l}];return this._commandService.executeCommand(To.id,{doc:{...t,body:n},segmentId:a,textRanges:h})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(t,e=!0){var a,c,l,A;const n=La(),r=(t.length>1?t.map(d=>{var u;return((u=d.body)==null?void 0:u.dataStream)||""}).join(`
41
41
  `):((a=t[0].body)==null?void 0:a.dataStream)||"").replaceAll(i.DataStreamTreeTokenType.TABLE_START,"").replaceAll(i.DataStreamTreeTokenType.TABLE_END,"").replaceAll(i.DataStreamTreeTokenType.TABLE_ROW_START,"").replaceAll(i.DataStreamTreeTokenType.TABLE_ROW_END,"").replaceAll(i.DataStreamTreeTokenType.TABLE_CELL_START,"").replaceAll(i.DataStreamTreeTokenType.TABLE_CELL_END,"").replaceAll(`\r
42
- `," ");let s=this._umdToHtml.convert(t);if(t.length===1&&e){s=s.replace(/(<[a-z]+)/,(m,g)=>`${g} 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:g}=m,h=(A=d.drawings)==null?void 0:A[g];if(h){const p=i.Tools.generateRandomId(6);m.blockId=p,u.drawings[p]={...i.Tools.deepClone(h),drawingId:p}}}}Nn.set(n,u)}return this._clipboardInterfaceService.write(r,s)}addClipboardHook(t){return this._clipboardHooks.push(t),i.toDisposable(()=>{const e=this._clipboardHooks.indexOf(t);e>-1&&this._clipboardHooks.splice(e,1)})}_getDocumentBodyInRanges(t,e){var d;const n=this._univerInstanceService.getCurrentUniverDocInstance(),r=e!=null?e:this._docSelectionManagerService.getDocRanges(),s=[];let a=!0;if(n==null||r.length===0)return;const c=r[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 r){const{startOffset:m,endOffset:g,collapsed:h,rangeType:p}=u;if(h||m==null||g==null)continue;if(p===i.DOC_RANGE_TYPE.RECT){a=!1;const{spanEntireRow:v}=u;let C;C=fr(l,m,g),s.push(C);continue}const f={startOffset:m,endOffset:g},S=n.getSelfOrHeaderFooterModel(c).sliceBody(f.startOffset,f.endOffset,t);S!=null&&s.push(S)}return{newSnapshotList:s.map(u=>({...A,body:u})),needCache:a,snapshot:A,ranges:r}}}async _genDocDataFromClipboardItems(t){try{let e="",n="";const r=[];for(const s of t)for(const a of s.types)switch(a){case I.PLAIN_TEXT_CLIPBOARD_MIME_TYPE:{n=await s.getType(a).then(c=>c&&c.text());break}case I.HTML_CLIPBOARD_MIME_TYPE:{e=await s.getType(a).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(a),l=new File([c],`pasted_image.${a.split("/")[1]}`,{type:a});r.push(l);break}}return!e&&!n&&r.length&&(e=await this._createImagePasteHtml(r)),this._genDocDataFromHtmlAndText(e,n)}catch(e){return Promise.reject(e)}}_genDocDataFromHtmlAndText(t,e,n){if(!t){if(e)return{body:i.BuildTextUtils.transform.fromPlainText(e)};throw new Error("[DocClipboardService] html and text cannot be both empty!")}const r=Qa(t);if(r){const a=Nn.get(r);if(a)return a}if(!n){const a=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);n=(a==null?void 0:a.getUnitId())||""}const s=this._htmlToUDM.convert(t,{unitId:n});return r&&Nn.set(r,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:ao.ImageSourceType.BASE64})},d.readAsDataURL(A)})},r=A=>{const d=new Image,u=500;return new Promise(m=>{d.src=typeof A=="string"?A:URL.createObjectURL(A),d.onload=()=>{const g=Math.min(u,d.naturalWidth),h=d.naturalHeight/d.naturalWidth;m({width:g,height:g*h})}})},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:g=100}=await r(A),h=`paste_image_id_${d}`,p=e.body,f=e.drawings;p.dataStream+="\b",(S=p.customBlocks)==null||S.push({startIndex:d,blockId:h}),f[h]={drawingId:h,unitId:"",subUnitId:"",imageSourceType:u.imageSourceType,title:"",source:u.source,description:"",layoutType:i.PositionedObjectLayoutType.INLINE,drawingType:i.DrawingTypeEnum.DRAWING_IMAGE,transform:{width:m,height:g,angle:0},docTransform:{angle:0,size:{width:m,height:g},positionH:{relativeFrom:i.ObjectRelativeFromH.CHARACTER,posOffset:0},positionV:{relativeFrom:i.ObjectRelativeFromV.LINE,posOffset:0}}}})),this._umdToHtml.convert([e])}};qn=Ga([dt(0,i.IUniverInstanceService),dt(1,i.ILogService),dt(2,i.ICommandService),dt(3,I.IClipboardInterfaceService),dt(4,i.Inject(B.DocSelectionManagerService))],qn);function pn(o){return o.getContextValue(i.FOCUSING_DOC)||o.getContextValue(i.EDITOR_ACTIVATED)}const Mo=999,Et={id:I.CopyCommand.id,name:"doc.command.copy",type:i.CommandType.COMMAND,multi:!0,priority:Mo,preconditions:pn,handler:async o=>o.get(Be).copy()},Do={id:"doc.command.copy-current-paragraph",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(Be),e=bt(o);return e?t.copy(i.SliceBodyType.copy,[{startOffset:e.paragraphStart,endOffset:e.paragraphEnd+1,collapsed:!1}]):!1}},fn={id:I.CutCommand.id,name:"doc.command.cut",type:i.CommandType.COMMAND,multi:!0,priority:Mo,preconditions:pn,handler:async o=>o.get(Be).cut()},Bo={id:"doc.command.cut-current-paragraph",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(Be),e=bt(o);return e?t.cut([{startOffset:e.paragraphStart,endOffset:e.paragraphEnd+1,collapsed:!1,rangeType:i.DOC_RANGE_TYPE.TEXT}]):!1}},Sn={id:I.PasteCommand.id,name:"doc.command.paste",type:i.CommandType.COMMAND,multi:!0,priority:Mo,preconditions:pn,handler:async o=>{const t=o.get(Be),n=await o.get(I.IClipboardInterfaceService).read();return n.length===0?!1:t.paste(n)}};var Xa=Object.getOwnPropertyDescriptor,Ka=(o,t,e,n)=>{for(var r=n>1?void 0:n?Xa(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Un=(o,t)=>(e,n)=>t(e,n,o);const Ya=11,qa=9,wt={ff:"Arial",fs:Ya};let Te=class extends i.Disposable{constructor(t,e,n){super();x(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 a;const t=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);if(t==null)return{...wt};const e=t==null?void 0:t.getUnitId(),n=(a=this._renderManagerService.getRenderById(e))==null?void 0:a.with(B.DocSkeletonManagerService),r=n==null?void 0:n.getViewModel();return r==null?{...wt}:r.getEditArea()===D.DocumentEditArea.BODY?{...wt}:{...wt,fs:qa}}setStyleCache(t){this._cacheStyle={...this._cacheStyle,...t}}_clearStyleCache(){this._cacheStyle=null}};Te=Ka([Un(0,i.Inject(B.DocSelectionManagerService)),Un(1,i.IUniverInstanceService),Un(2,D.IRenderManagerService)],Te);function _o(o,t,e){const n=[];for(let r=0,s=o.length;r<s;r++)o[r]===i.DataStreamTreeTokenType.PARAGRAPH&&n.push({startIndex:r});if(t)for(const r of n)t.bullet&&(r.bullet=i.Tools.deepClone(t.bullet)),t.paragraphStyle&&(r.paragraphStyle=i.Tools.deepClone(t.paragraphStyle),delete r.paragraphStyle.borderBottom,t.paragraphStyle.headingId&&(r.paragraphStyle.headingId=i.generateRandomId(6)));if(e)for(const r of n)r.paragraphStyle||(r.paragraphStyle={}),r.paragraphStyle.borderBottom=e;return n}const In={id:"doc.command.break-line",type:i.CommandType.COMMAND,handler:(o,t)=>{var w,z,W,H,V;const e=o.get(B.DocSelectionManagerService),n=o.get(i.IUniverInstanceService),r=o.get(i.ICommandService),s=o.get(Te),a=(w=t==null?void 0:t.textRange)!=null?w:e.getActiveTextRange(),c=e.getRectRanges();if(a==null)return!1;if(c&&c.length){const{startOffset:j}=a;return e.replaceDocRanges([{startOffset:j,endOffset:j}]),!0}const{horizontalLine:l}=t!=null?t:{},{segmentId:A}=a,d=n.getCurrentUnitForType(i.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:g,endOffset:h}=a,f=((z=u.paragraphs)!=null?z:[]).find(j=>j.startIndex>=g);if(!f)return!1;const S=g===f.startIndex,v=f.startIndex,C=s.getDefaultStyle(),y=s.getStyleCache(),b=an(u,h,C,y),E={dataStream:i.DataStreamTreeTokenType.PARAGRAPH,paragraphs:_o(i.DataStreamTreeTokenType.PARAGRAPH,f,l),textRuns:[{st:0,ed:1,ts:{...b.ts}}]};if(d==null)return!1;const R=e.getActiveTextRange();if(u==null)return!1;const{collapsed:O}=a,T=E.dataStream.length,_=[{startOffset:g+T,endOffset:g+T,style:R==null?void 0:R.style,collapsed:O}],M={id:B.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:_,debounce:!0}},N=new i.TextX,F=i.JSONX.getInstance();if(O)g>0&&N.push({t:i.TextXActionType.RETAIN,len:g}),N.push({t:i.TextXActionType.INSERT,body:E,len:E.dataStream.length});else{const j=i.BuildTextUtils.selection.delete([a],u,0,E);N.push(...j)}(((W=f.bullet)==null?void 0:W.listType)===i.PresetListType.CHECK_LIST_CHECKED||(H=f.paragraphStyle)!=null&&H.headingId)&&(a.endOffset<v&&N.push({t:i.TextXActionType.RETAIN,len:v-a.endOffset}),N.push({t:i.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...f,paragraphStyle:{...f.paragraphStyle,...S?{headingId:void 0,namedStyleType:void 0}:null},startIndex:0,bullet:(V=f.paragraphStyle)!=null&&V.headingId?void 0:{...f.bullet,listType:i.PresetListType.CHECK_LIST}}]},coverType:i.UpdateDocsAttributeType.REPLACE})),M.params.textRanges=[{startOffset:g+T,endOffset:g+T,collapsed:O}];const k=J(d,A);return M.params.actions=F.editOp(N.serialize(),k),!!r.syncExecuteCommand(M.id,M.params)}},xt={id:"doc.command.horizontal-line",type:i.CommandType.COMMAND,handler:(o,t)=>o.get(i.ICommandService).syncExecuteCommand(In.id,{horizontalLine:{padding:5,color:{rgb:"#CDD0D8"},width:1,dashStyle:i.DashStyleType.SOLID},textRange:t==null?void 0:t.insertRange})},No={id:"doc.command.insert-horizontal-line-bellow",type:i.CommandType.COMMAND,handler:o=>{const t=o.get(i.ICommandService),e=bt(o);return e?t.syncExecuteCommand(xt.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 Sr="doc.command.set-inline-format-bold",_e={id:Sr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Sr,t,e)}},Ir="doc.command.set-inline-format-italic",Ne={id:Ir,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Ir,t,e)}},vr="doc.command.set-inline-format-underline",Pe={id:vr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(vr,t,e)}},Er="doc.command.set-inline-format-strikethrough",Ue={id:Er,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Er,t,e)}},Cr="doc.command.set-inline-format-subscript",ye={id:Cr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Cr,t,e)}},Tr="doc.command.set-inline-format-superscript",we={id:Tr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Tr,t,e)}},yr="doc.command.set-inline-format-fontsize",me={id:yr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(yr,t,e)}},br="doc.command.set-inline-format-font-family",We={id:br,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(br,t,e)}},Rr="doc.command.set-inline-format-text-color",Me={id:Rr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Rr,t,e)}},xr="doc.command.set-inline-format-text-background-color",De={id:xr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(xr,t,e)}},Or="doc.command.reset-inline-format-text-background-color",at={id:Or,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Or,t,e)}},Jn={[_e.id]:"bl",[Ne.id]:"it",[Pe.id]:"ul",[Ue.id]:"st",[me.id]:"fs",[We.id]:"ff",[Me.id]:"cl",[De.id]:"bg",[at.id]:"bg",[ye.id]:"va",[we.id]:"va"},be={id:"doc.command.set-inline-format",type:i.CommandType.COMMAND,handler:async(o,t)=>{var b;const{value:e,preCommandId:n}=t,r=o.get(i.ICommandService),s=o.get(B.DocSelectionManagerService),a=o.get(i.IUniverInstanceService),c=o.get(Te),l=s.getDocRanges(),A=(b=l.find(E=>E.isActive))!=null?b:l[0];if(l.length===0)return!1;const{segmentId:d}=l[0],u=a.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);if(u==null)return!1;const m=u.getSelfOrHeaderFooterModel(d).getBody();if(m==null)return!1;const g=u.getUnitId();let h;switch(n){case _e.id:case Ne.id:case Pe.id:case Ue.id:case ye.id:case we.id:{const E=c.getDefaultStyle(),R=Xi(m,A,E);h=Za(R,n);break}case me.id:case We.id:{h=e;break}case Me.id:case De.id:{h={rgb:e};break}case at.id:{h={rgb:null};break}default:throw new Error(`Unknown command: ${n} in handleInlineFormat`)}const p={id:B.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:l}},f=new i.TextX,S=i.JSONX.getInstance(),v=new i.MemoryCursor;v.reset();for(const E of l){let{startOffset:R,endOffset:O,rangeType:T}=E;if(R==null||O==null)continue;if(T===i.DOC_RANGE_TYPE.RECT&&(R=R-1),R===O){const N=c.getStyleCache(),F=Jn[n];c.setStyleCache({[F]:(N==null?void 0:N[F])!==void 0?Gi(N,F,n):h});continue}const _={dataStream:"",textRuns:[{st:0,ed:O-R,ts:{[Jn[n]]:h}}]},M=R-v.cursor;M!==0&&f.push({t:i.TextXActionType.RETAIN,len:M}),f.push({t:i.TextXActionType.RETAIN,body:_,len:O-R}),v.reset(),v.moveCursor(O)}const C=J(u,d);return p.params.actions=S.editOp(f.serialize(),C),!!r.syncExecuteCommand(p.id,p.params)}};function Ja(o){return o!==null&&typeof o=="object"}function Gi(o,t,e){if(/bl|it/.test(t))return(o==null?void 0:o[t])===i.BooleanNumber.TRUE?i.BooleanNumber.FALSE:i.BooleanNumber.TRUE;if(/ul|st/.test(t))return Ja(o==null?void 0:o[t])&&(o==null?void 0:o[t]).s===i.BooleanNumber.TRUE?{s:i.BooleanNumber.FALSE}:{s:i.BooleanNumber.TRUE};if(/va/.test(t))return e===ye.id?(o==null?void 0:o[t])===i.BaselineOffset.SUBSCRIPT?i.BaselineOffset.NORMAL:i.BaselineOffset.SUBSCRIPT:(o==null?void 0:o[t])===i.BaselineOffset.SUPERSCRIPT?i.BaselineOffset.NORMAL:i.BaselineOffset.SUPERSCRIPT}function Xi(o,t,e){var d,u,m,g,h,p,f,S,v,C,y,b,E,R;const{startOffset:n,endOffset:r,collapsed:s}=t;if(s){const O=(d=o.textRuns)!=null?d:[];let T=null;for(let _=O.length-1;_>=0;_--){const M=O[_];if(M.st<n&&n<=M.ed){T=M;break}}return T!=null&&T.ts?{...e,...T.ts}:e}const{textRuns:a=[]}=i.getBodySlice(o,n,r),c=i.Tools.deepClone(e),l=a.map(O=>{var T;return(T=O==null?void 0:O.ts)==null?void 0:T.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=(g=(m=(u=a.find(O=>{var T;return((T=O.ts)==null?void 0:T.ff)!=null}))==null?void 0:u.ts)==null?void 0:m.ff)!=null?g:c.ff,c.it=a.length&&a.every(O=>{var T;return((T=O.ts)==null?void 0:T.it)===i.BooleanNumber.TRUE})?i.BooleanNumber.TRUE:i.BooleanNumber.FALSE,c.bl=a.length&&a.every(O=>{var T;return((T=O.ts)==null?void 0:T.bl)===i.BooleanNumber.TRUE})?i.BooleanNumber.TRUE:i.BooleanNumber.FALSE,c.ul=a.length&&a.every(O=>{var T,_;return((_=(T=O.ts)==null?void 0:T.ul)==null?void 0:_.s)===i.BooleanNumber.TRUE})?(h=a[0].ts)==null?void 0:h.ul:c.ul,c.st=a.length&&a.every(O=>{var T,_;return((_=(T=O.ts)==null?void 0:T.st)==null?void 0:_.s)===i.BooleanNumber.TRUE})?(p=a[0].ts)==null?void 0:p.st:c.st,c.bg=(v=(S=(f=a.find(O=>{var T;return((T=O.ts)==null?void 0:T.bg)!=null}))==null?void 0:f.ts)==null?void 0:S.bg)!=null?v:c.bg,c.cl=(b=(y=(C=a.find(O=>{var T;return((T=O.ts)==null?void 0:T.cl)!=null}))==null?void 0:C.ts)==null?void 0:y.cl)!=null?b:c.cl;const A=a.filter(O=>{var T;return((T=O==null?void 0:O.ts)==null?void 0:T.va)!=null});if(A.length>0&&A.length===a.length){const O=(E=A[0].ts)==null?void 0:E.va;let T=!0;for(let _=1;_<A.length;_++)if(((R=A[_].ts)==null?void 0:R.va)!==O){T=!1;break}T&&(c.va=O)}return c}function Za(o,t){const e=Jn[t];return Gi(o,e,t)}const ct={id:"doc.command.list-operation",type:i.CommandType.COMMAND,handler:(o,t)=>{var y,b,E,R,O,T;const e=o.get(B.DocSelectionManagerService),n=o.get(i.IUniverInstanceService),r=o.get(i.ICommandService),s=t.listType,a=n.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),c=(b=(y=t.docRange)!=null?y:e.getDocRanges())!=null?b:[];if(a==null||c.length===0)return!1;const l=c[0].segmentId,A=a.getSelfOrHeaderFooterModel(l),d=(R=(E=A.getBody())==null?void 0:E.paragraphs)!=null?R:[],u=(T=(O=A.getBody())==null?void 0:O.dataStream)!=null?T:"";if(!d.length)return!1;const m=i.BuildTextUtils.range.getParagraphsInRanges(c,d,u),g=a.getUnitId(),h={id:B.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:c,isEditing:!1}};new i.MemoryCursor().reset();const f=i.BuildTextUtils.paragraph.bullet.switch({paragraphs:m,listType:s,document:a,segmentId:l}),S=i.JSONX.getInstance(),v=J(a,l);return h.params.actions=S.editOp(f.serialize(),v),!!r.syncExecuteCommand(h.id,h.params)}},Ot={id:"doc.command.change-list-type",type:i.CommandType.COMMAND,handler:(o,t)=>{var C,y,b,E,R;const e=o.get(B.DocSelectionManagerService),n=o.get(i.IUniverInstanceService),r=o.get(i.ICommandService),{listType:s}=t,a=n.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),c=(C=t.docRange)!=null?C:e.getDocRanges();if(a==null||c==null||!c.length)return!1;const{segmentId:l}=c[0],A=a.getSelfOrHeaderFooterModel(l),d=(b=(y=A.getBody())==null?void 0:y.paragraphs)!=null?b:[],u=(R=(E=A.getBody())==null?void 0:E.dataStream)!=null?R:"";if(!d.length)return!1;const m=i.BuildTextUtils.range.getParagraphsInRanges(c,d,u),g=a.getUnitId(),h=i.BuildTextUtils.paragraph.bullet.set({paragraphs:m,listType:s,segmentId:l,document:a});if(!h)return!1;const p=i.JSONX.getInstance(),f={id:B.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:c,isEditing:!1}},S=J(a,l);return f.params.actions=p.editOp(h.serialize(),S),!!r.syncExecuteCommand(f.id,f.params)}};var It=(o=>(o[o.increase=1]="increase",o[o.decrease=-1]="decrease",o))(It||{});const Yt={id:"doc.command.change-list-nesting-level",type:i.CommandType.COMMAND,handler:(o,t)=>{var y,b,E,R,O;if(!t)return!1;const{type:e}=t,n=o.get(B.DocSelectionManagerService),r=o.get(i.IUniverInstanceService),s=o.get(i.ICommandService),a=r.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),c=n.getActiveTextRange();if(a==null||c==null)return!1;const{segmentId:l}=c,A=(y=n.getDocRanges())!=null?y:[],d=a.getSelfOrHeaderFooterModel(l),u=(E=(b=d.getBody())==null?void 0:b.paragraphs)!=null?E:[],m=(O=(R=d.getBody())==null?void 0:R.dataStream)!=null?O:"";if(!u.length)return!1;const g=i.BuildTextUtils.range.getParagraphsInRange(c,u,m),h=a.getUnitId(),p=i.JSONX.getInstance(),f=i.BuildTextUtils.paragraph.bullet.changeNestLevel({paragraphs:g,type:e,segmentId:l,document:a}),S={id:B.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:A,isEditing:!1}},v=J(a,l);return S.params.actions=p.editOp(f.serialize(),v),!!s.syncExecuteCommand(S.id,S.params)}},nt={id:"doc.command.bullet-list",type:i.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(i.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(Ot.id,{listType:t.value,docRange:t.docRange}):e.syncExecuteCommand(ct.id,{listType:i.PresetListType.BULLET_LIST,docRange:t==null?void 0:t.docRange})}},Ct={id:"doc.command.check-list",type:i.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(i.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(Ot.id,{listType:t.value,docRange:t.docRange}):e.syncExecuteCommand(ct.id,{listType:i.PresetListType.CHECK_LIST,docRange:t==null?void 0:t.docRange})}},Po={id:"doc.command.toggle-check-list",type:i.CommandType.COMMAND,handler:(o,t)=>{var p;if(!t)return!1;const e=o.get(i.IUniverInstanceService),n=o.get(i.ICommandService),{index:r,segmentId:s,textRanges:a}=t,c=e.getCurrentUnitForType(i.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:B.RichTextEditingMutation.id,params:{unitId:A,actions:[],textRanges:a!=null?a:[],segmentId:s,isEditing:!1}},u=i.BuildTextUtils.paragraph.bullet.toggleChecklist({document:c,paragraphIndex:r,segmentId:s});if(!u)return!1;const m=i.JSONX.getInstance(),g=J(c,s);return d.params.actions=m.editOp(u.serialize(),g),!!n.syncExecuteCommand(d.id,d.params)}},ot={id:"doc.command.order-list",type:i.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(i.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(Ot.id,{listType:t.value}):e.syncExecuteCommand(ct.id,{listType:i.PresetListType.ORDER_LIST})}},Uo={id:"doc.command.quick-list",type:i.CommandType.COMMAND,handler(o,t){var G,K,Y,X,q;if(!t)return!1;const e=o.get(B.DocSelectionManagerService),n=o.get(i.IUniverInstanceService),r=o.get(i.ICommandService),s=n.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),a=e.getActiveTextRange();if(s==null||a==null)return!1;const{segmentId:c,startOffset:l}=a,{listType:A,paragraph:d}=t,{paragraphStart:u,paragraphEnd:m}=d,g=new i.TextX,h=i.JSONX.getInstance(),{defaultTabStop:p=36}=s.getSnapshot().documentStyle,f=(K=(G=s.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:G.sectionBreaks)!=null?K:[],{startIndex:S,paragraphStyle:v={}}=d,{indentFirstLine:C,snapToGrid:y,indentStart:b}=v,E=i.PRESET_LIST_TYPE[A].nestingLevel[0].paragraphProperties||{},{hanging:R,indentStart:O}=E,T=E.textStyle,{charSpace:_,gridType:M}=$a(S,f)||{charSpace:0,gridType:i.GridType.LINES},N=D.getCharSpaceApply(_,p,M,y);let k=i.Tools.generateRandomId(6);const Q=(X=(Y=s.getBody())==null?void 0:Y.paragraphs)!=null?X:[],w=Q.findIndex(ee=>ee.startIndex===d.startIndex),z=Q[w-1],W=Q[w+1];z&&z.bullet&&z.bullet.listType.indexOf(A)===0?k=z.bullet.listId:W&&W.bullet&&W.bullet.listType.indexOf(A)===0&&(k=W.bullet.listId);const H={id:B.RichTextEditingMutation.id,params:{unitId:s.getUnitId(),actions:[],textRanges:[{startOffset:u,endOffset:u,collapsed:!0}],isEditing:!1}};g.push({t:i.TextXActionType.RETAIN,len:u}),g.push({t:i.TextXActionType.DELETE,len:l-u}),m>l&&g.push({t:i.TextXActionType.RETAIN,len:m-l}),g.push({t:i.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{startIndex:0,paragraphStyle:{...v,textStyle:{...v.textStyle,...T},indentFirstLine:void 0,hanging:R,indentStart:{v:D.getNumberUnitValue(O,N)-D.getNumberUnitValue(R,N)+D.getNumberUnitValue(C,N)+D.getNumberUnitValue(b,N)}},bullet:{...(q=d.bullet)!=null?q:{nestingLevel:0,textStyle:{fs:20}},listType:A,listId:k}}]}});const V=J(s,c);return H.params.actions=h.editOp(g.serialize(),V),!!r.syncExecuteCommand(H.id,H.params)}};function wo(o,t){var d,u;const e=o.get(i.ICommandService),n=bt(o);if(!n)return!1;const r=o.get(i.IUniverInstanceService).getCurrentUnitOfType(i.UniverInstanceType.UNIVER_DOC);if(!r)return!1;const s=i.BuildTextUtils.selection.replace({doc:r,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:i.Tools.generateRandomId(6),nestingLevel:((u=n.bullet)==null?void 0:u.listType)===t?n.bullet.nestingLevel:0}}]}});if(!s)return!1;const a={id:B.RichTextEditingMutation.id,params:{unitId:r.getUnitId(),actions:[],textRanges:[{startOffset:n.startIndex+1,endOffset:n.startIndex+1,collapsed:!0}],isEditing:!1}},c=i.JSONX.getInstance(),l=J(r);return a.params.actions=c.editOp(s.serialize(),l),!!e.syncExecuteCommand(a.id,a.params)}const Lo={id:"doc.command.insert-bullet-list-bellow",type:i.CommandType.COMMAND,handler:o=>wo(o,i.PresetListType.BULLET_LIST)},Qo={id:"doc.command.insert-order-list-bellow",type:i.CommandType.COMMAND,handler:o=>wo(o,i.PresetListType.ORDER_LIST)},Fo={id:"doc.command.insert-check-list-bellow",type:i.CommandType.COMMAND,handler:o=>wo(o,i.PresetListType.CHECK_LIST)};function $a(o,t){const e=t.sort(i.sortRulesFactory("startIndex"));for(let n=0;n<e.length;n++){const r=t[n];if(r.startIndex>=o)return r}}const le={id:"doc.command.set-paragraph-named-style",type:i.CommandType.COMMAND,handler(o,t){var h;if(!t)return!1;const n=o.get(i.IUniverInstanceService).getCurrentUnitOfType(i.UniverInstanceType.UNIVER_DOC);if(!n)return!1;const r=n.getUnitId(),s=o.get(B.DocSelectionManagerService),a=(h=t.textRanges)!=null?h:s.getTextRanges({unitId:r,subUnitId:r});if(!(a!=null&&a.length))return!1;const c=a[0].segmentId,l=i.BuildTextUtils.paragraph.style.set({document:n.getSelfOrHeaderFooterModel(c),textRanges:a,style:{namedStyleType:t.value,headingId:!t.value||t.value===i.NamedStyleType.NORMAL_TEXT?void 0:i.generateRandomId(6),spaceAbove:void 0,spaceBelow:void 0},paragraphTextRun:{}}),A={id:B.RichTextEditingMutation.id,params:{actions:[],textRanges:a,unitId:r,segmentId:c}},d=i.JSONX.getInstance(),u=J(n,c);return A.params.actions=d.editOp(l.serialize(),u),!!o.get(i.ICommandService).syncExecuteCommand(A.id,A.params)}},Ki={id:"doc.command.quick-heading",type:i.CommandType.COMMAND,handler(o,t){var b,E,R,O;if(!t)return!1;const{value:e}=t,n=o.get(B.DocSelectionManagerService),r=o.get(i.IUniverInstanceService),s=o.get(i.ICommandService),a=r.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),c=n.getActiveTextRange();if(a==null||c==null||!c.collapsed)return!1;const{segmentId:l,startOffset:A}=c,d=a.getSelfOrHeaderFooterModel(l),u=(E=(b=d.getBody())==null?void 0:b.paragraphs)!=null?E:[],m=(O=(R=d.getBody())==null?void 0:R.dataStream)!=null?O:"",g=i.BuildTextUtils.paragraph.util.getParagraphsInRange(c,u,m)[0];if(!g)return!1;const{paragraphStart:h}=g,p=new i.TextX,f=i.JSONX.getInstance(),{paragraphStyle:S={}}=g,v={id:B.RichTextEditingMutation.id,params:{unitId:a.getUnitId(),actions:[],textRanges:[{startOffset:h,endOffset:h,collapsed:!0}],isEditing:!1}};p.push({t:i.TextXActionType.RETAIN,len:h}),i.BuildTextUtils.paragraph.style.set({textRanges:[c],document:a,style:{...S,headingId:i.generateRandomId(6),namedStyleType:e},cursor:A,deleteLen:A-h,textX:p,paragraphTextRun:{}});const C=J(a,l);return v.params.actions=f.editOp(p.serialize(),C),!!s.syncExecuteCommand(v.id,v.params)}},wn={"#":i.NamedStyleType.HEADING_1,"##":i.NamedStyleType.HEADING_2,"###":i.NamedStyleType.HEADING_3,"####":i.NamedStyleType.HEADING_4,"#####":i.NamedStyleType.HEADING_5},Ho={id:"doc.command.h1-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_1})},ko={id:"doc.command.h2-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_2})},Vo={id:"doc.command.h3-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_3})},jo={id:"doc.command.h4-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_4})},Wo={id:"doc.command.h5-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_5})},qt={id:"doc.command.normal-text-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.NORMAL_TEXT})},Yi={id:"doc.command.title",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.TITLE})},qi={id:"doc.command.subtitle-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.SUBTITLE})},pe={id:"doc.command.align-action",type:i.CommandType.COMMAND,handler:(o,t)=>{var b,E,R,O;const e=o.get(B.DocSelectionManagerService),n=o.get(i.IUniverInstanceService),r=o.get(i.ICommandService),{alignType:s}=t,a=n.getCurrentUniverDocInstance();if(a==null)return!1;const c=e.getDocRanges();if(c.length===0)return!1;const l=c[0].segmentId,A=a.getSelfOrHeaderFooterModel(l),d=(E=(b=A.getBody())==null?void 0:b.paragraphs)!=null?E:[],u=(O=(R=A.getBody())==null?void 0:R.dataStream)!=null?O:"";if(d==null)return!1;const m=i.BuildTextUtils.range.getParagraphsInRanges(c,d,u),g=a.getUnitId(),h=m.every(T=>{var _;return((_=T.paragraphStyle)==null?void 0:_.horizontalAlign)===s}),p={id:B.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:c}},f=new i.MemoryCursor;f.reset();const S=new i.TextX,v=i.JSONX.getInstance();for(const T of m){const{startIndex:_}=T;S.push({t:i.TextXActionType.RETAIN,len:_-f.cursor});const M={...T.paragraphStyle,horizontalAlign:h?i.HorizontalAlign.UNSPECIFIED:s};S.push({t:i.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...T,paragraphStyle:M,startIndex:0}]},coverType:i.UpdateDocsAttributeType.REPLACE}),f.moveCursorTo(_+1)}const C=J(a,l);return p.params.actions=v.editOp(S.serialize(),C),!!r.syncExecuteCommand(p.id,p.params)}},Mt={id:"doc.command.align-left",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(pe.id,{alignType:i.HorizontalAlign.LEFT})},Dt={id:"doc.command.align-center",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(pe.id,{alignType:i.HorizontalAlign.CENTER})},Bt={id:"doc.command.align-right",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(pe.id,{alignType:i.HorizontalAlign.RIGHT})},_t={id:"doc.command.align-justify",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(pe.id,{alignType:i.HorizontalAlign.JUSTIFIED})},vn={id:"doc.command.switch-mode",type:i.CommandType.COMMAND,handler:async o=>{var v,C,y,b,E;const t=o.get(i.ICommandService),e=o.get(D.IRenderManagerService),n=o.get(B.DocSelectionManagerService),s=o.get(i.IUniverInstanceService).getCurrentUniverDocInstance();if(s==null)return!1;const a=s.getUnitId(),c=(v=e.getRenderById(a))==null?void 0:v.with(B.DocSkeletonManagerService).getSkeleton(),l=(C=e.getRenderById(a))==null?void 0:C.with(exports.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(),g={id:B.RichTextEditingMutation.id,params:{unitId:a,actions:[],textRanges:u===i.DocumentFlavor.TRADITIONAL&&A?[]:m}},h=i.JSONX.getInstance(),p=[];let f;if(u===void 0?f=h.insertOp(["documentStyle","documentFlavor"],i.DocumentFlavor.MODERN):u===i.DocumentFlavor.MODERN?f=h.replaceOp(["documentStyle","documentFlavor"],u,i.DocumentFlavor.TRADITIONAL):f=h.replaceOp(["documentStyle","documentFlavor"],u,i.DocumentFlavor.MODERN),f)p.push(f);else return!1;if(u!==i.DocumentFlavor.MODERN){const R=s.getSnapshot(),{drawings:O={},body:T}=R,_=(y=T==null?void 0:T.customBlocks)!=null?y:[];for(const M in O){const N=O[M],F=_.find(q=>q.blockId===M);if(F==null)continue;const k=N.docTransform.positionV,{relativeFrom:Q,posOffset:w}=k;if(Q===i.ObjectRelativeFromV.PARAGRAPH)continue;const{startIndex:z}=F,W=c.findNodeByCharIndex(z,A,d),H=(b=W==null?void 0:W.parent)==null?void 0:b.parent,V=H==null?void 0:H.parent,j=V==null?void 0:V.lines.find(q=>q.paragraphIndex===(H==null?void 0:H.paragraphIndex)&&q.paragraphStart),G=(E=V==null?void 0:V.parent)==null?void 0:E.parent;if(W==null||H==null||j==null||V==null||G==null)continue;let K=0;Q===i.ObjectRelativeFromV.LINE?K-=H.top:Q===i.ObjectRelativeFromV.PAGE&&(K+=G.marginTop),K+=j.top;const Y={...k,relativeFrom:i.ObjectRelativeFromV.PARAGRAPH,posOffset:(w!=null?w:0)-K},X=h.replaceOp(["drawings",M,"docTransform","positionV"],k,Y);X&&p.push(X)}}return g.params.actions=p.reduce((R,O)=>i.JSONX.compose(R,O),null),!!t.syncExecuteCommand(g.id,g.params)}},Ji="COMPONENT_DOC_CREATE_TABLE_CONFIRM",ec="doc.command.create-table",zo={id:ec,type:i.CommandType.COMMAND,handler:async(o,t)=>{var Y,X,q,ee,ge;const{rowCount:e,colCount:n}=t,r=o.get(B.DocSelectionManagerService),s=o.get(i.IUniverInstanceService),a=o.get(i.ICommandService),c=o.get(Te),l=r.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 g=u.getUnitId(),h=ce(o,g),p=h==null?void 0:h.getSkeleton();if(p==null)return!1;const{startOffset:f}=l,v=((Y=m.paragraphs)!=null?Y:[]).find(xe=>xe.startIndex>=f),C=p.findNodeByCharIndex(f,A,d);if(C==null)return!1;const y=new i.TextX,b=i.JSONX.getInstance(),E=[],R=f+4,O=[{startOffset:R,endOffset:R,collapsed:!0}],T={id:B.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:O}};f>0&&y.push({t:i.TextXActionType.RETAIN,len:f}),y.push({t:i.TextXActionType.INSERT,body:{dataStream:i.DataStreamTreeTokenType.PARAGRAPH,paragraphs:_o(i.DataStreamTreeTokenType.PARAGRAPH,v)},len:1});const _=c.getDefaultStyle(),M=c.getStyleCache(),N=an(m,f,_,M),{dataStream:F,paragraphs:k,sectionBreaks:Q}=Ca(e,n),w=(ge=(ee=(q=(X=C.parent)==null?void 0:X.parent)==null?void 0:q.parent)==null?void 0:ee.parent)==null?void 0:ge.parent;if(w==null)return!1;const{pageWidth:z,marginLeft:W,marginRight:H}=w,V=Co(e,n,z-W-H);y.push({t:i.TextXActionType.INSERT,body:{dataStream:F,paragraphs:k,sectionBreaks:Q,textRuns:[{...N,st:0,ed:F.length}],tables:[{startIndex:0,endIndex:F.length,tableId:V.tableId}]},len:F.length});const j=J(u,A);E.push(b.editOp(y.serialize(),j));const G=b.insertOp(["tableSource",V.tableId],V);return E.push(G),T.params.actions=E.reduce((xe,he)=>i.JSONX.compose(xe,he),null),!!a.syncExecuteCommand(T.id,T.params)}},Ln="doc.component.create-table-confirm",En={id:"doc.operation.create-table",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(i.LocaleService),e=o.get(I.IConfirmService),n=o.get(i.ICommandService),r={rowCount:3,colCount:5},s=(a,c)=>{r.rowCount=a,r.colCount=c};return await e.open({id:Ln,children:{label:{name:Ji,props:{handleRowColChange:s,tableCreateParams:r}}},width:400,title:{title:t.t("toolbar.table.insert")},onConfirm:()=>{n.executeCommand(zo.id,r),e.close(Ln)},onClose:()=>{e.close(Ln)}}),!0}};function tc(o){const t=o.get(i.IUniverInstanceService),e=o.get(D.IRenderManagerService);return new P.Observable(n=>{const r=t.focused$.subscribe(s=>{if(s==null||t.getUnitType(s)!==i.UniverInstanceType.UNIVER_DOC)return n.next(!0);const c=e.getRenderById(s);if(c==null)return n.next(!0);c.with(B.DocSkeletonManagerService).getViewModel().editAreaChange$.subscribe(A=>{n.next(A===D.DocumentEditArea.HEADER||A===D.DocumentEditArea.FOOTER)})});return()=>r.unsubscribe()})}function nc(o){const t=o.get(i.IUniverInstanceService),e=o.get(i.ICommandService);return new P.Observable(n=>{const r=e.onCommandExecuted(l=>{if(l.id===B.RichTextEditingMutation.id){const{unitId:A}=l.params,d=t.getUnit(A);if(d==null){n.next(!0);return}const{documentStyle:u}=d.getSnapshot();n.next((u==null?void 0:u.documentFlavor)!==i.DocumentFlavor.TRADITIONAL)}}),s=t.focused$.subscribe(l=>{if(l==null)return n.next(!0);const A=t.getUniverDocInstance(l),d=A==null?void 0:A.getSnapshot().documentStyle.documentFlavor;n.next(d!==i.DocumentFlavor.TRADITIONAL)}),a=t.getCurrentUniverDocInstance();if(a==null)return n.next(!0);const c=a==null?void 0:a.getSnapshot().documentStyle.documentFlavor;return n.next(c!==i.DocumentFlavor.TRADITIONAL),()=>{r.dispose(),s.unsubscribe()}})}function oc(o){const t=o.get(B.DocSelectionManagerService),e=o.get(i.IUniverInstanceService);return new P.Observable(n=>{const r=t.textSelection$.subscribe(s=>{if(s==null){n.next(!0);return}const{textRanges:a}=s;if(a.length!==1){n.next(!0);return}const c=a[0],{collapsed:l,startNodePosition:A,startOffset:d}=c;if(!l||d==null){n.next(!0);return}const u=e.getCurrentUniverDocInstance();if(u==null){n.next(!0);return}const m=ce(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()=>r.unsubscribe()})}function $(o){const t=o.get(B.DocSelectionManagerService);return new P.Observable(e=>{const n=t.textSelection$.subscribe(r=>{if(r==null){e.next(!0);return}const{textRanges:s,rectRanges:a}=r;if(s.length===0&&a.length===0){e.next(!0);return}e.next(!1)});return()=>n.unsubscribe()})}function rc(o){const t=o.get(i.ICommandService);return{id:_e.id,type:I.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",activated$:new P.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const a=(c=s.ts)==null?void 0:c.bl;e.next(a===i.BooleanNumber.TRUE)},r=t.onCommandExecuted(s=>{const a=s.id;(a===B.SetTextSelectionsOperation.id||a===be.id)&&n()});return n(),r.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function ic(o){const t=o.get(i.ICommandService);return{id:Ne.id,type:I.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",activated$:new P.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const a=(c=s.ts)==null?void 0:c.it;e.next(a===i.BooleanNumber.TRUE)},r=t.onCommandExecuted(s=>{const a=s.id;(a===B.SetTextSelectionsOperation.id||a===be.id)&&n()});return n(),r.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function sc(o){const t=o.get(i.ICommandService);return{id:Pe.id,type:I.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",activated$:new P.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const a=(c=s.ts)==null?void 0:c.ul;e.next((a==null?void 0:a.s)===i.BooleanNumber.TRUE)},r=t.onCommandExecuted(s=>{const a=s.id;(a===B.SetTextSelectionsOperation.id||a===be.id)&&n()});return n(),r.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function ac(o){const t=o.get(i.ICommandService);return{id:Ue.id,type:I.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",activated$:new P.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const a=(c=s.ts)==null?void 0:c.st;e.next((a==null?void 0:a.s)===i.BooleanNumber.TRUE)},r=t.onCommandExecuted(s=>{const a=s.id;(a===B.SetTextSelectionsOperation.id||a===be.id)&&n()});return n(),r.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function cc(o){const t=o.get(i.ICommandService);return{id:ye.id,type:I.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",activated$:new P.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const a=(c=s.ts)==null?void 0:c.va;e.next(a===i.BaselineOffset.SUBSCRIPT)},r=t.onCommandExecuted(s=>{const a=s.id;(a===B.SetTextSelectionsOperation.id||a===be.id)&&n()});return n(),r.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function lc(o){const t=o.get(i.ICommandService);return{id:we.id,type:I.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",activated$:new P.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const a=(c=s.ts)==null?void 0:c.va;e.next(a===i.BaselineOffset.SUPERSCRIPT)},r=t.onCommandExecuted(s=>{const a=s.id;(a===B.SetTextSelectionsOperation.id||a===be.id)&&n()});return n(),r.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function dc(o){const t=o.get(i.ICommandService);return{id:We.id,tooltip:"toolbar.font",type:I.MenuItemType.SELECTOR,label:Mi,selections:I.FONT_FAMILY_LIST.map(e=>({label:{name:Di},value:e.value})),value$:new P.Observable(e=>{const n=i.DEFAULT_STYLES.ff,r=()=>{var l;const a=Le(o);if(a==null){e.next(n);return}const c=(l=a.ts)==null?void 0:l.ff;e.next(c!=null?c:n)},s=t.onCommandExecuted(a=>{const c=a.id;(c===B.SetTextSelectionsOperation.id||c===We.id)&&r()});return r(),s.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Ac(o){const t=o.get(i.ICommandService);return{id:me.id,type:I.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Bi,props:{min:1,max:400}},selections:I.FONT_SIZE_LIST,value$:new P.Observable(e=>{const n=i.DEFAULT_STYLES.fs,r=()=>{var l;const a=Le(o);if(a==null){e.next(n);return}const c=(l=a.ts)==null?void 0:l.fs;e.next(c!=null?c:n)},s=t.onCommandExecuted(a=>{const c=a.id;(c===B.SetTextSelectionsOperation.id||c===me.id)&&r()});return r(),s.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function uc(o){const t=o.get(i.ICommandService);return{id:le.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 P.Observable(e=>{const n=i.NamedStyleType.NORMAL_TEXT,r=()=>{var l,A;const a=Ge(o);if(a==null){e.next(n);return}const c=(A=(l=a.paragraphStyle)==null?void 0:l.namedStyleType)!=null?A:n;e.next(c)},s=t.onCommandExecuted(a=>{const c=a.id;(c===B.SetTextSelectionsOperation.id||c===me.id)&&r()});return r(),s.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function gc(o){const t=o.get(i.ICommandService),e=o.get(i.ThemeService);return{id:Me.id,icon:"FontColor",tooltip:"toolbar.textColor.main",type:I.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:vo,hoverable:!1,selectable:!1}}],value$:new P.Observable(n=>{const r=e.getCurrentTheme().textColor,s=t.onCommandExecuted(a=>{if(a.id===Me.id){const c=a.params.value;n.next(c!=null?c:r)}});return n.next(r),s.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function hc(o){return{id:So.id,type:I.MenuItemType.BUTTON,icon:"HeaderFooterSingle",tooltip:"toolbar.headerFooter",hidden$:P.combineLatest(I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY),nc(o),(t,e)=>t||e)}}const mc="GridSingle",Zi="doc.menu.table";function pc(o){return{id:Zi,type:I.MenuItemType.SUBITEMS,icon:mc,tooltip:"toolbar.table.main",disabled$:oc(o),hidden$:P.combineLatest(I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY),tc(o),(t,e)=>t||e)}}function fc(o){return{id:En.id,title:"toolbar.table.insert",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Sc(o){const t=o.get(i.ICommandService);return{id:Mt.id,type:I.MenuItemType.BUTTON,icon:"LeftJustifyingSingle",tooltip:"toolbar.alignLeft",disabled$:$(o),activated$:new P.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===pe.id){const c=Ge(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.LEFT)}});return e.next(!1),n.dispose}),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Ic(o){const t=o.get(i.ICommandService);return{id:Dt.id,type:I.MenuItemType.BUTTON,icon:"HorizontallySingle",tooltip:"toolbar.alignCenter",activated$:new P.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===pe.id){const c=Ge(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.CENTER)}});return e.next(!1),n.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function vc(o){const t=o.get(i.ICommandService);return{id:Bt.id,type:I.MenuItemType.BUTTON,icon:"RightJustifyingSingle",tooltip:"toolbar.alignRight",activated$:new P.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===pe.id){const c=Ge(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.RIGHT)}});return e.next(!1),n.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Ec(o){const t=o.get(i.ICommandService);return{id:_t.id,type:I.MenuItemType.BUTTON,icon:"AlignTextBothSingle",tooltip:"toolbar.alignJustify",activated$:new P.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===pe.id){const c=Ge(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.JUSTIFIED)}});return e.next(!1),n.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Cc(o){return{id:xt.id,type:I.MenuItemType.BUTTON,icon:"ReduceSingle",tooltip:"toolbar.horizontalLine",disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}const Tt=o=>new P.Observable(t=>{const e=o.get(i.IUniverInstanceService),n=o.get(B.DocSelectionManagerService);let r;const s=e.focused$.subscribe(a=>{if(r==null||r.unsubscribe(),a==null)return;const c=e.getUniverDocInstance(a);c!=null&&(r=n.textSelection$.subscribe(()=>{var d,u,m,g,h;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=i.BuildTextUtils.range.getParagraphsInRange(A,(m=(u=p.getBody())==null?void 0:u.paragraphs)!=null?m:[],(h=(g=p.getBody())==null?void 0:g.dataStream)!=null?h:"");let S;if(f.every(v=>{var C;return S||(S=(C=v.bullet)==null?void 0:C.listType),v.bullet&&v.bullet.listType===S})){t.next(S);return}}t.next(void 0)}))});return()=>{s.unsubscribe(),r==null||r.unsubscribe()}});function Mr(o){return{id:ot.id,type:I.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:Ni,hoverable:!1,selectable:!1},value$:Tt(o)}],icon:"OrderSingle",tooltip:"toolbar.order",hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),disabled$:$(o),activated$:Tt(o).pipe(P.map(t=>t&&t.indexOf("ORDER_LIST")===0))}}function Dr(o){return{id:nt.id,type:I.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:Pi,hoverable:!1,selectable:!1},value$:Tt(o)}],icon:"UnorderSingle",tooltip:"toolbar.unorder",disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),activated$:Tt(o).pipe(P.map(t=>t&&t.indexOf("BULLET_LIST")===0))}}function Br(o){return{id:Ct.id,type:I.MenuItemType.BUTTON,icon:"TodoList",tooltip:"toolbar.checklist",disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),activated$:Tt(o).pipe(P.map(t=>t&&t.indexOf("CHECK_LIST")===0))}}function Tc(o){const t=o.get(i.ICommandService),e=o.get(i.IUniverInstanceService);return{id:vn.id,type:I.MenuItemType.BUTTON,icon:"KeyboardSingle",tooltip:"toolbar.documentFlavor",hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY),activated$:new P.Observable(n=>{var a;const r=t.onCommandExecuted(c=>{var l;if(c.id===B.RichTextEditingMutation.id){const A=e.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);n.next(((l=A==null?void 0:A.getSnapshot())==null?void 0:l.documentStyle.documentFlavor)===i.DocumentFlavor.MODERN)}}),s=e.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);return n.next(((a=s==null?void 0:s.getSnapshot())==null?void 0:a.documentStyle.documentFlavor)===i.DocumentFlavor.MODERN),()=>r.dispose()})}}function yc(o){return{id:at.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor"}}function bc(o){const t=o.get(i.ICommandService),e=o.get(i.ThemeService);return{id:De.id,tooltip:"toolbar.fillColor.main",type:I.MenuItemType.BUTTON_SELECTOR,icon:"PaintBucket",selections:[{label:{name:vo,hoverable:!1,selectable:!1}}],value$:new P.Observable(n=>{const r=e.getCurrentTheme().primaryColor,s=t.onCommandExecuted(a=>{if(a.id===De.id){const c=a.params.value;n.next(c!=null?c:r)}});return n.next(r),s.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Le(o){var h,p,f,S;const t=o.get(i.IUniverInstanceService),e=o.get(B.DocSelectionManagerService),n=o.get(Te),r=t.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),s=e.getDocRanges(),a=(h=s.find(v=>v.isActive))!=null?h: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?i.NAMED_STYLE_MAP[(S=A==null?void 0:A.paragraphStyle)==null?void 0:S.namedStyleType]:null;if(r==null||a==null)return{ts:{...c,...d,...l}};const{segmentId:u}=a,m=r.getSelfOrHeaderFooterModel(u).getBody();if(m==null)return{ts:{...c,...d,...l}};const g=Xi(m,a,{});return i.Tools.deleteNull(g),{ts:{...c,...d,...g,...l}}}function Ge(o){var d,u;const t=o.get(i.IUniverInstanceService),e=o.get(B.DocSelectionManagerService),n=t.getCurrentUniverDocInstance(),r=e.getDocRanges(),s=(d=r.find(m=>m.isActive))!=null?d:r[0];if(n==null||s==null)return;const{startOffset:a,segmentId:c}=s,l=(u=n.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:u.paragraphs;if(l==null)return;let A=-1;for(const m of l){const{startIndex:g}=m;if(a>A&&a<=g)return m;A=g}return null}const Rc={[i.NamedStyleType.HEADING_1]:Ho,[i.NamedStyleType.HEADING_2]:ko,[i.NamedStyleType.HEADING_3]:Vo,[i.NamedStyleType.HEADING_4]:jo,[i.NamedStyleType.HEADING_5]:Wo,[i.NamedStyleType.NORMAL_TEXT]:qt,[i.NamedStyleType.TITLE]:Yi,[i.NamedStyleType.SUBTITLE]:qi,[i.NamedStyleType.NAMED_STYLE_TYPE_UNSPECIFIED]:qt},$i={[i.NamedStyleType.HEADING_1]:{key:"H1Single",component:Si},[i.NamedStyleType.HEADING_2]:{key:"H2Single",component:Ii},[i.NamedStyleType.HEADING_3]:{key:"H3Single",component:vi},[i.NamedStyleType.HEADING_4]:{key:"H4Single",component:Ei},[i.NamedStyleType.HEADING_5]:{key:"H5Single",component:Ci},[i.NamedStyleType.NORMAL_TEXT]:{key:"TextTypeSingle",component:ft},[i.NamedStyleType.TITLE]:{key:"TextTypeSingle",component:ft},[i.NamedStyleType.SUBTITLE]:{key:"TextTypeSingle",component:ft},[i.NamedStyleType.NAMED_STYLE_TYPE_UNSPECIFIED]:{key:"TextTypeSingle",component:ft}},Qe=o=>t=>{const e=t.get(i.ICommandService),n=t.get(I.ComponentManager),r=$i[o];return n.get(r.key)||n.register(r.key,r.component),{id:Rc[o].id,type:I.MenuItemType.BUTTON,icon:r.key,tooltip:"toolbar.heading.tooltip",disabled$:$(t),hidden$:I.getMenuHiddenObservable(t,i.UniverInstanceType.UNIVER_DOC),activated$:new P.Observable(s=>{const a=i.NamedStyleType.NORMAL_TEXT,c=()=>{var u,m;const A=Ge(t);if(A==null){s.next(a===o);return}const d=(m=(u=A.paragraphStyle)==null?void 0:u.namedStyleType)!=null?m:a;s.next(d===o)},l=e.onCommandExecuted(A=>{const d=A.id;(d===B.SetTextSelectionsOperation.id||d===me.id)&&c()});return c(),l.dispose})}},xc=Qe(i.NamedStyleType.HEADING_1),Oc=Qe(i.NamedStyleType.HEADING_2),Mc=Qe(i.NamedStyleType.HEADING_3),Dc=Qe(i.NamedStyleType.HEADING_4),Bc=Qe(i.NamedStyleType.HEADING_5),_c=Qe(i.NamedStyleType.NORMAL_TEXT);Qe(i.NamedStyleType.TITLE);Qe(i.NamedStyleType.SUBTITLE);const Nc=o=>({id:Do.id,type:I.MenuItemType.BUTTON,icon:"Copy",title:"rightClick.copy"}),Pc=o=>({id:Bo.id,type:I.MenuItemType.BUTTON,icon:"CutSingle",title:"rightClick.cut"}),Uc=o=>({id:xo.id,type:I.MenuItemType.BUTTON,icon:"DeleteSingle",title:"rightClick.delete"}),wc=o=>({id:Lo.id,type:I.MenuItemType.BUTTON,icon:"UnorderSingle",title:"rightClick.bulletList"}),Lc=o=>({id:Qo.id,type:I.MenuItemType.BUTTON,icon:"OrderSingle",title:"rightClick.orderList"}),Qc=o=>({id:Fo.id,type:I.MenuItemType.BUTTON,icon:"TodoList",title:"rightClick.checkList"}),Fc=o=>({id:No.id,type:I.MenuItemType.BUTTON,icon:"ReduceSingle",title:"toolbar.horizontalLine"}),es="doc.menu.insert-bellow";function Hc(o){return{id:es,type:I.MenuItemType.SUBITEMS,title:"rightClick.insertBellow"}}const Zn=4,kc=(o,t)=>{const e=o.get(i.IUniverInstanceService).getUniverDocInstance(t.unitId),n=(e==null?void 0:e.zoomRatio)||1;return{...i.Tools.deepClone(t),zoomRatio:n}},Ae={id:"doc.operation.set-zoom-ratio",type:i.CommandType.OPERATION,handler:(o,t)=>{const e=o.get(i.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 Vc=Object.getOwnPropertyDescriptor,jc=(o,t,e,n)=>{for(var r=n>1?void 0:n?Vc(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Lt=(o,t)=>(e,n)=>t(e,n,o);function ts(o,t){const e=_r(o.left,o.top,t),n=_r(o.right,o.bottom,t);return{left:e.x,top:e.y,right:n.x,bottom:n.y}}function _r(o,t,e){const{scaleX:n,scaleY:r}=e.getAncestorScale(),s=e.getViewport(ie.VIEW_MAIN);if(!s)return{x:o,y:t};const{viewportScrollX:a,viewportScrollY:c}=s,l=(o-a)*n,A=(t-c)*r;return{x:l,y:A}}function Nr(o,t,e){const{scaleX:n,scaleY:r}=e.getAncestorScale(),s=e.getViewport(ie.VIEW_MAIN);if(!s)return{x:o,y:t};const{viewportScrollX:a,viewportScrollY:c}=s,l=o/n+a,A=t/r+c;return{x:l,y:A}}const Gt=(o,t)=>{const{scene:e,mainComponent:n,engine:r}=t,s=t.with(B.DocSkeletonManagerService).getSkeleton(),a=s.findNodePositionByCharIndex(o.startOffset,!0,o.segmentId,o.segmentPage),c=o.collapsed?o.startOffset:o.endOffset-1,l=s.findNodePositionByCharIndex(c,!0,o.segmentId,o.segmentPage),A=n;if(!l||!a)return;const d=A.getOffsetConfig(),{docsLeft:u,docsTop:m}=d,g=r.getCanvasElement(),h=g.getBoundingClientRect(),p=D.pxToNum(g.style.width),{top:f,left:S,width:v}=h,C=v/p,{scaleX:y,scaleY:b}=e.getAncestorScale(),E=new ve(d,s),{borderBoxPointGroup:R}=E.getRangePointData(a,l);return cn(R).map(_=>ts(_,e)).map(_=>({left:(_.left+u*y)*C+S,right:(_.right+u*y)*C+S,top:(_.top+m*b)*C+f,bottom:(_.bottom+m*b)*C+f}))};exports.DocCanvasPopManagerService=class extends i.Disposable{constructor(t,e,n,r){super(),this._globalPopupManagerService=t,this._renderManagerService=e,this._univerInstanceService=n,this._commandService=r}_createRectPositionObserver(t,e){const n=()=>{const{scene:l,engine:A}=e,d=typeof t=="function"?t():t,u=A.getCanvasElement(),m=u.getBoundingClientRect(),g=D.pxToNum(u.style.width),h=ts(d,l),{top:p,left:f,width:S}=m,v=S/g;return{left:h.left*v+f,right:h.right*v+f,top:h.top*v+p,bottom:h.bottom*v+p}},r=n(),s=new P.BehaviorSubject(r),a=new i.DisposableCollection;a.add(this._commandService.onCommandExecuted(l=>{if(l.id===Ae.id||l.id===B.RichTextEditingMutation.id){const A=n();A&&s.next(A)}}));const c=e.scene.getViewport(ie.VIEW_MAIN);return c&&a.add(c.onScrollAfter$.subscribeEvent(()=>{s.next(n())})),{position:r,position$:s,disposable:a}}_createObjectPositionObserver(t,e){const n=()=>{const{left:r,top:s,width:a,height:c}=t;return{left:r,right:r+a,top:s,bottom:s+c}};return this._createRectPositionObserver(n,e)}_createRangePositionObserver(t,e){var c;const n=(c=Gt(t,e))!=null?c:[],r=new P.BehaviorSubject(n),s=new i.DisposableCollection;s.add(this._commandService.onCommandExecuted(l=>{if((l.id===Ae.id||l.id===B.RichTextEditingMutation.id)&&l.params.unitId===e.unitId){const d=Gt(t,e);d&&r.next(d)}}));const a=e.scene.getViewport(ie.VIEW_MAIN);return a&&s.add(a.onScrollAfter$.subscribeEvent(()=>{const l=Gt(t,e);l&&r.next(l)})),{positions:n,positions$:r,disposable:s}}attachPopupToRect(t,e,n){const r=this._renderManagerService.getRenderById(n);if(!r)throw new Error(`Current render not found, unitId: ${n}`);const{position:s,position$:a,disposable:c}=this._createRectPositionObserver(t,r),l=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:s,anchorRect$:a,canvasElement:r.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(l),a.complete(),c.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==l}}attachPopupToObject(t,e,n){const r=this._renderManagerService.getRenderById(n);if(!r)throw new Error(`Current render not found, unitId: ${n}`);const{position:s,position$:a,disposable:c}=this._createObjectPositionObserver(t,r),l=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:s,anchorRect$:a,canvasElement:r.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(l),a.complete(),c.dispose()},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:a}=e,c=this._renderManagerService.getRenderById(n);if(!c)throw new Error(`Current render not found, unitId: ${n}`);const{positions:l,positions$:A,disposable:d}=this._createRangePositionObserver(t,c),u=A.pipe(P.map(g=>s.includes("top")?g[0]:g[g.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(g=>s.includes(g))&&l.length>1&&a!=null?a:s,canvasElement:c.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(m),A.complete(),d.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==m}}};exports.DocCanvasPopManagerService=jc([Lt(0,i.Inject(I.ICanvasPopupService)),Lt(1,D.IRenderManagerService),Lt(2,i.IUniverInstanceService),Lt(3,i.ICommandService)],exports.DocCanvasPopManagerService);var Wc=Object.getOwnPropertyDescriptor,zc=(o,t,e,n)=>{for(var r=n>1?void 0:n?Wc(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Gc=(o,t)=>(e,n)=>t(e,n,o);const Xc=(o,t,e,n)=>{var m,g,h,p,f;const r=e.findNodePositionByCharIndex(o.startOffset,!0,o.segmentId,n),s=e.getSkeletonData();let a=o.endOffset-1;if(o.segmentId){const S=(f=Array.from((g=(m=s==null?void 0:s.skeFooters.get(o.segmentId))==null?void 0:m.values())!=null?g:[])[0])!=null?f:Array.from((p=(h=s==null?void 0:s.skeHeaders.get(o.segmentId))==null?void 0:h.values())!=null?p:[])[0];S&&(a=Math.min(S.ed,a))}const c=e.findNodePositionByCharIndex(a,!0,o.segmentId,n);if(!c||!r)return;const l=t.getOffsetConfig(),A=new ve(l,e),{borderBoxPointGroup:d}=A.getRangePointData(r,c);return cn(d).map(S=>({top:S.top+l.docsTop-Zn,bottom:S.bottom+l.docsTop+Zn,left:S.left+l.docsLeft,right:S.right+l.docsLeft}))},Pr=(o,t,e,n)=>{const r=[];for(const s of o){const a=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&&(r.push(d),d=null);const g={top:t+a+u.top,left:e+l,right:e+l+A,bottom:t+a+u.top+u.lineHeight};d={paragraphStart:u.st,paragraphEnd:m,startIndex:m,rect:g,fisrtLine:{top:t+a+u.top+u.marginTop+u.paddingTop,left:e+l,right:e+l+A,bottom:t+a+u.top+u.marginTop+u.paddingTop+u.contentHeight}}}else d&&d.startIndex===m&&(d.rect.bottom=t+a+u.top+u.lineHeight)}d&&r.push(d)}}return r},Kc=(o,t,e,n=-1)=>{const r=e.findPositionByGlyph(o,n);if(!r)return;const s=t.getOffsetConfig(),a={...r,isBack:!0},c=new ve(s,e),{borderBoxPointGroup:l}=c.getRangePointData(a,a),d=cn(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 Fe(o,t,e){const{left:n,right:r,top:s,bottom:a}=e;return o>=n&&o<=r&&t>=s&&t<=a}exports.DocEventManagerService=class extends i.Disposable{constructor(e,n){super();x(this,"_hoverCustomRanges$",new P.BehaviorSubject([]));x(this,"hoverCustomRanges$",this._hoverCustomRanges$.pipe(P.distinctUntilChanged((e,n)=>e.length===n.length&&e.every((r,s)=>n[s].range.rangeId===r.range.rangeId&&n[s].segmentId===r.segmentId&&n[s].segmentPageIndex===r.segmentPageIndex&&n[s].range.startIndex===r.range.startIndex))));x(this,"_clickCustomRanges$",new P.Subject);x(this,"clickCustomRanges$",this._clickCustomRanges$.asObservable());x(this,"_hoverBullet$",new P.Subject);x(this,"hoverBullet$",this._hoverBullet$.pipe(P.distinctUntilChanged((e,n)=>(e==null?void 0:e.paragraph.startIndex)===(n==null?void 0:n.paragraph.startIndex)&&(e==null?void 0:e.segmentId)===(n==null?void 0:n.segmentId)&&(e==null?void 0:e.segmentPageIndex)===(n==null?void 0:n.segmentPageIndex))));x(this,"_clickBullet$",new P.Subject);x(this,"clickBullets$",this._clickBullet$.asObservable());x(this,"_hoverParagraph$",new P.BehaviorSubject(null));x(this,"hoverParagraph$",this._hoverParagraph$.pipe(P.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))));x(this,"hoverParagraphRealTime$",this._hoverParagraph$.asObservable());x(this,"_hoverParagraphLeft$",new P.BehaviorSubject(null));x(this,"hoverParagraphLeft$",this._hoverParagraphLeft$.pipe(P.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))));x(this,"hoverParagraphLeftRealTime$",this._hoverParagraphLeft$.asObservable());x(this,"_hoverTableCell$",new P.Subject);x(this,"hoverTableCell$",this._hoverTableCell$.pipe(P.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))));x(this,"hoverTableCellRealTime$",this._hoverTableCell$.asObservable());x(this,"_hoverTable$",new P.Subject);x(this,"hoverTable$",this._hoverTable$.pipe(P.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))));x(this,"hoverTableRealTime$",this._hoverTable$.asObservable());x(this,"_customRangeDirty",!0);x(this,"_bulletDirty",!0);x(this,"_paragraphDirty",!0);x(this,"_customRangeBounds",[]);x(this,"_bulletBounds",[]);x(this,"_paragraphBounds",new Map);x(this,"_paragraphLeftBounds",[]);x(this,"_tableParagraphBounds",new Map);x(this,"_segmentParagraphBounds",new Map);x(this,"_tableCellBounds",new Map);x(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=D.CURSOR_TYPE.TEXT;this.disposeWithMe(this.hoverCustomRanges$.subscribe(n=>{n.length?(e=this._context.scene.getCursor(),this._context.scene.setCursor(D.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(i.fromEventSubject(this._context.engine.onTransformChange$).pipe(P.filter(e=>e.type===D.TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize)).subscribe(()=>{this._customRangeDirty=!0,this._bulletDirty=!0,this._paragraphDirty=!0}))}_initEvents(){this.disposeWithMe(i.fromEventSubject(this._context.scene.onPointerMove$).pipe(P.throttleTime(30)).subscribe(r=>{if(r.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:a}=Nr(r.offsetX,r.offsetY,this._context.scene);this._hoverCustomRanges$.next(this._calcActiveRanges({x:s,y:a})),this._hoverParagraph$.next(this._calcActiveParagraph({x:s,y:a})),this._hoverParagraphLeft$.next(this._calcActiveParagraphLeft({x:s,y:a})),this._hoverBullet$.next(this._calcActiveBullet({x:s,y:a}))})),this.disposeWithMe(this._context.scene.onPointerEnter$.subscribeEvent(()=>{this._hoverBullet$.next(null),this._hoverCustomRanges$.next([])}));const e=i.fromEventSubject(this._context.mainComponent.onPointerDown$),n=i.fromEventSubject(this._context.scene.onPointerUp$);this.disposeWithMe(e.pipe(P.switchMap(r=>n.pipe(P.take(1),P.map(s=>({down:r,up:s})))),P.filter(({down:r,up:s})=>r.target===s.target&&s.timeStamp-r.timeStamp<300)).subscribe(({down:r})=>{if(r.button===2)return;const s=Nr(r.offsetX,r.offsetY,this._context.scene),a=this._calcActiveRanges(s);a.length&&this._clickCustomRanges$.next(a.pop());const c=this._calcActiveBullet(s);c&&this._clickBullet$.next(c)}))}_buildCustomRangeBoundsBySegment(e,n=-1){var a,c,l;const r=(l=(c=(a=this._context.unit.getSelfOrHeaderFooterModel(e))==null?void 0:a.getBody())==null?void 0:c.customRanges)!=null?l:[],s=[];return r.forEach(A=>{const d={startOffset:A.startIndex,endOffset:A.endIndex+1,segmentId:e},u=Xc(d,this._documents,this._skeleton,n);if(!u)return null;s.push({customRange:A,rects:u,segmentId:e,segmentPageIndex:n})}),s}_buildCustomRangeBounds(){var n;if(!this._customRangeDirty)return;this._customRangeDirty=!1;const e=[];e.push(...this._buildCustomRangeBoundsBySegment()),(n=this._skeleton.getSkeletonData())==null||n.pages.forEach((r,s)=>{r.headerId&&e.push(...this._buildCustomRangeBoundsBySegment(r.headerId,s)),r.footerId&&e.push(...this._buildCustomRangeBoundsBySegment(r.footerId,s))}),this._customRangeBounds=e}_calcActiveRanges(e){this._buildCustomRangeBounds();const{x:n,y:r}=e;return this._customRangeBounds.filter(a=>a.rects.some(c=>Fe(n,r,c))).map(a=>({segmentId:a.segmentId,range:a.customRange,segmentPageIndex:a.segmentPageIndex,rects:a.rects}))}_buildBulletBoundsBySegment(e,n=-1){var A,d,u,m,g;const r=(A=this._context.unit.getSelfOrHeaderFooterModel(e))==null?void 0:A.getBody(),s=((d=r==null?void 0:r.paragraphs)!=null?d:[]).filter(h=>h.bullet&&h.bullet.listType.indexOf("CHECK_LIST")===0),a=[],c=this._skeleton.getSkeletonData();if(!c)return a;const l=h=>{var p,f,S;for(const v of h){const C=[...v.sections];if(v.skeTables){const y=Array.from(v.skeTables.values());C.push(...y.map(b=>b.rows.map(E=>E.cells.map(R=>R.sections))).flat(4))}for(const y of C)for(const b of y.columns)for(const E of b.lines)if(E.paragraphStart){const R=s.find(O=>O.startIndex===E.paragraphIndex);if(R){const O=E,T=(S=(f=(p=O==null?void 0:O.divides)==null?void 0:p[0])==null?void 0:f.glyphGroup)==null?void 0:S[0];if(!T)continue;const _=Kc(T,this._documents,this._skeleton,n);if(!_)continue;a.push({rect:_,segmentId:e,segmentPageIndex:n,paragraph:R})}}}return a};if(e){const h=(g=(u=c.skeFooters.get(e))==null?void 0:u.values())!=null?g:(m=c.skeHeaders.get(e))==null?void 0:m.values();return h?l(Array.from(h)):a}return l(c.pages)}_buildBulletBounds(){var e;this._bulletDirty&&(this._bulletDirty=!1,this._bulletBounds=[],this._bulletBounds.push(...this._buildBulletBoundsBySegment()),(e=this._skeleton.getSkeletonData())==null||e.pages.forEach((n,r)=>{n.headerId&&this._bulletBounds.push(...this._buildBulletBoundsBySegment(n.headerId,r)),n.footerId&&this._bulletBounds.push(...this._buildBulletBoundsBySegment(n.footerId,r))}))}_calcActiveBullet(e){this._buildBulletBounds();const{x:n,y:r}=e;return this._bulletBounds.find(a=>Fe(n,r,a.rect))}_buildParagraphBoundsBySegment(e){var c,l,A;const n=this._skeleton.getSkeletonData(),s=this._documents.getOffsetConfig();if(!n)return null;const a=d=>{const u=new Map,m=(g,h,p,f)=>{Pr(g.sections,p,f,g.pageWidth-g.marginLeft-g.marginRight).forEach(v=>{if(!u.has(v.startIndex))u.set(v.startIndex,{rect:v.rect,paragraphStart:v.paragraphStart,paragraphEnd:v.paragraphEnd,startIndex:v.startIndex,rects:[v.rect],pageIndex:h,segmentId:e,firstLine:v.fisrtLine});else{const C=u.get(v.startIndex);C&&(C.rect.bottom=v.rect.bottom,C.rects.push(v.rect))}})};for(let g=0;g<d.length;g++){const h=d[g],p=((h.pageHeight===1/0?0:h.pageHeight)+s.pageMarginTop)*g+h.marginTop+s.docsTop,f=h.marginLeft+s.docsLeft;h.skeTables&&Array.from(h.skeTables.values()).forEach(S=>{const v=S.left+f,C=S.top+p,y=v+S.width,b=C+S.height,E=S.tableId;this._tableBounds.set(E,{rect:{left:v,top:C,right:y,bottom:b},pageIndex:g,tableId:E}),S.rows.forEach((R,O)=>{R.cells.forEach((T,_)=>{const M=((h.pageHeight===1/0?0:h.pageHeight)+s.pageMarginTop)*g+S.top+s.docsTop+h.marginTop+R.top+T.marginTop,N=S.left+s.docsLeft+h.marginLeft+T.left+T.marginLeft,F=Pr(T.sections,M,N,T.pageWidth-T.marginLeft-T.marginRight);let k=this._tableParagraphBounds.get(E);k||(k=[],this._tableParagraphBounds.set(E,k)),k.push(...F.map(w=>({rect:w.rect,paragraphStart:w.paragraphStart,paragraphEnd:w.paragraphEnd,startIndex:w.startIndex,pageIndex:g,segmentId:e,rowIndex:O,colIndex:_,firstLine:w.fisrtLine,tableId:E})));let Q=this._tableCellBounds.get(E);Q||(Q=[],this._tableCellBounds.set(E,Q)),Q.push({rect:{top:M,left:N,right:N+T.pageWidth-T.marginLeft-T.marginRight,bottom:M+T.pageHeight-T.marginBottom-T.marginTop},pageIndex:g,rowIndex:O,colIndex:_,tableId:E})})})}),m(h,g,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?a(Array.from(d)):null}return a(n.pages)}_buildParagraphBounds(){var n,r;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 a;this._segmentParagraphBounds.set(s,(a=this._buildParagraphBoundsBySegment(s))!=null?a:new Map)};(r=this._skeleton.getSkeletonData())==null||r.pages.forEach(s=>{s.headerId&&e(s.headerId),s.footerId&&e(s.footerId)})}_calcActiveParagraph(e){var c,l;this._buildParagraphBounds();const{x:n,y:r}=e,s=Array.from(this._tableBounds.values()).find(A=>Fe(n,r,A.rect));if(this._hoverTable$.next(s),s){const A=(c=this._tableCellBounds.get(s.tableId))==null?void 0:c.find(m=>Fe(n,r,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=>Fe(n,r,m.rect));return u&&{...u,rects:[u.rect]}}return this._paragraphBounds.values().find(A=>A.rects.some(d=>Fe(n,r,d)))}_calcActiveParagraphLeft(e){this._buildParagraphBounds();const{x:n,y:r}=e;return this._paragraphLeftBounds.find(a=>Fe(n,r,a.rect))}get paragraphBounds(){return this._buildParagraphBounds(),this._paragraphBounds}};exports.DocEventManagerService=zc([Gc(1,i.Inject(B.DocSkeletonManagerService))],exports.DocEventManagerService);const Yc=[me.id,_e.id,Ne.id,Pe.id,Ue.id,ye.id,we.id,Me.id,De.id];function qc(o){const{avaliableMenus:t=Yc}=o,e=I.useDependency(I.IMenuManagerService),[n,r]=U.useState([]);return U.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)}r(l)}s();const a=e.menuChanged$.subscribe(s);return()=>{a.unsubscribe()}},[e]),L.jsx("div",{className:`
42
+ `," ");let s=this._umdToHtml.convert(t);if(t.length===1&&e){s=s.replace(/(<[a-z]+)/,(m,g)=>`${g} 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:g}=m,h=(A=d.drawings)==null?void 0:A[g];if(h){const p=i.Tools.generateRandomId(6);m.blockId=p,u.drawings[p]={...i.Tools.deepClone(h),drawingId:p}}}}Nn.set(n,u)}return this._clipboardInterfaceService.write(r,s)}addClipboardHook(t){return this._clipboardHooks.push(t),i.toDisposable(()=>{const e=this._clipboardHooks.indexOf(t);e>-1&&this._clipboardHooks.splice(e,1)})}_getDocumentBodyInRanges(t,e){var d;const n=this._univerInstanceService.getCurrentUniverDocInstance(),r=e!=null?e:this._docSelectionManagerService.getDocRanges(),s=[];let a=!0;if(n==null||r.length===0)return;const c=r[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 r){const{startOffset:m,endOffset:g,collapsed:h,rangeType:p}=u;if(h||m==null||g==null)continue;if(p===i.DOC_RANGE_TYPE.RECT){a=!1;const{spanEntireRow:v}=u;let C;C=fr(l,m,g),s.push(C);continue}const f={startOffset:m,endOffset:g},S=n.getSelfOrHeaderFooterModel(c).sliceBody(f.startOffset,f.endOffset,t);S!=null&&s.push(S)}return{newSnapshotList:s.map(u=>({...A,body:u})),needCache:a,snapshot:A,ranges:r}}}async _genDocDataFromClipboardItems(t){try{let e="",n="";const r=[];for(const s of t)for(const a of s.types)switch(a){case I.PLAIN_TEXT_CLIPBOARD_MIME_TYPE:{n=await s.getType(a).then(c=>c&&c.text());break}case I.HTML_CLIPBOARD_MIME_TYPE:{e=await s.getType(a).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(a),l=new File([c],`pasted_image.${a.split("/")[1]}`,{type:a});r.push(l);break}}return!e&&!n&&r.length&&(e=await this._createImagePasteHtml(r)),this._genDocDataFromHtmlAndText(e,n)}catch(e){return Promise.reject(e)}}_genDocDataFromHtmlAndText(t,e,n){if(!t){if(e)return{body:i.BuildTextUtils.transform.fromPlainText(e)};throw new Error("[DocClipboardService] html and text cannot be both empty!")}const r=Qa(t);if(r){const a=Nn.get(r);if(a)return a}if(!n){const a=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);n=(a==null?void 0:a.getUnitId())||""}const s=this._htmlToUDM.convert(t,{unitId:n});return r&&Nn.set(r,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:ao.ImageSourceType.BASE64})},d.readAsDataURL(A)})},r=A=>{const d=new Image,u=500;return new Promise(m=>{d.src=typeof A=="string"?A:URL.createObjectURL(A),d.onload=()=>{const g=Math.min(u,d.naturalWidth),h=d.naturalHeight/d.naturalWidth;m({width:g,height:g*h})}})},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:g=100}=await r(A),h=`paste_image_id_${d}`,p=e.body,f=e.drawings;p.dataStream+="\b",(S=p.customBlocks)==null||S.push({startIndex:d,blockId:h}),f[h]={drawingId:h,unitId:"",subUnitId:"",imageSourceType:u.imageSourceType,title:"",source:u.source,description:"",layoutType:i.PositionedObjectLayoutType.INLINE,drawingType:i.DrawingTypeEnum.DRAWING_IMAGE,transform:{width:m,height:g,angle:0},docTransform:{angle:0,size:{width:m,height:g},positionH:{relativeFrom:i.ObjectRelativeFromH.CHARACTER,posOffset:0},positionV:{relativeFrom:i.ObjectRelativeFromV.LINE,posOffset:0}}}})),this._umdToHtml.convert([e])}};qn=Ga([dt(0,i.IUniverInstanceService),dt(1,i.ILogService),dt(2,i.ICommandService),dt(3,I.IClipboardInterfaceService),dt(4,i.Inject(B.DocSelectionManagerService))],qn);function pn(o){return o.getContextValue(i.FOCUSING_DOC)||o.getContextValue(i.EDITOR_ACTIVATED)}const Mo=999,Et={id:I.CopyCommand.id,name:"doc.command.copy",type:i.CommandType.COMMAND,multi:!0,priority:Mo,preconditions:pn,handler:async o=>o.get(Be).copy()},Do={id:"doc.command.copy-current-paragraph",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(Be),e=bt(o);return e?t.copy(i.SliceBodyType.copy,[{startOffset:e.paragraphStart,endOffset:e.paragraphEnd+1,collapsed:!1}]):!1}},fn={id:I.CutCommand.id,name:"doc.command.cut",type:i.CommandType.COMMAND,multi:!0,priority:Mo,preconditions:pn,handler:async o=>o.get(Be).cut()},Bo={id:"doc.command.cut-current-paragraph",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(Be),e=bt(o);return e?t.cut([{startOffset:e.paragraphStart,endOffset:e.paragraphEnd+1,collapsed:!1,rangeType:i.DOC_RANGE_TYPE.TEXT}]):!1}},Sn={id:I.PasteCommand.id,name:"doc.command.paste",type:i.CommandType.COMMAND,multi:!0,priority:Mo,preconditions:pn,handler:async o=>{const t=o.get(Be),n=await o.get(I.IClipboardInterfaceService).read();return n.length===0?!1:t.paste(n)}};var Xa=Object.getOwnPropertyDescriptor,Ka=(o,t,e,n)=>{for(var r=n>1?void 0:n?Xa(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Un=(o,t)=>(e,n)=>t(e,n,o);const Ya=11,qa=9,wt={ff:"Arial",fs:Ya};let Te=class extends i.Disposable{constructor(t,e,n){super();x(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 a;const t=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);if(t==null)return{...wt};const e=t==null?void 0:t.getUnitId(),n=(a=this._renderManagerService.getRenderById(e))==null?void 0:a.with(B.DocSkeletonManagerService),r=n==null?void 0:n.getViewModel();return r==null?{...wt}:r.getEditArea()===D.DocumentEditArea.BODY?{...wt}:{...wt,fs:qa}}setStyleCache(t){this._cacheStyle={...this._cacheStyle,...t}}_clearStyleCache(){this._cacheStyle=null}};Te=Ka([Un(0,i.Inject(B.DocSelectionManagerService)),Un(1,i.IUniverInstanceService),Un(2,D.IRenderManagerService)],Te);function _o(o,t,e){const n=[];for(let r=0,s=o.length;r<s;r++)o[r]===i.DataStreamTreeTokenType.PARAGRAPH&&n.push({startIndex:r});if(t)for(const r of n)t.bullet&&(r.bullet=i.Tools.deepClone(t.bullet)),t.paragraphStyle&&(r.paragraphStyle=i.Tools.deepClone(t.paragraphStyle),delete r.paragraphStyle.borderBottom,t.paragraphStyle.headingId&&(r.paragraphStyle.headingId=i.generateRandomId(6)));if(e)for(const r of n)r.paragraphStyle||(r.paragraphStyle={}),r.paragraphStyle.borderBottom=e;return n}const In={id:"doc.command.break-line",type:i.CommandType.COMMAND,handler:(o,t)=>{var w,z,W,H,V;const e=o.get(B.DocSelectionManagerService),n=o.get(i.IUniverInstanceService),r=o.get(i.ICommandService),s=o.get(Te),a=(w=t==null?void 0:t.textRange)!=null?w:e.getActiveTextRange(),c=e.getRectRanges();if(a==null)return!1;if(c&&c.length){const{startOffset:j}=a;return e.replaceDocRanges([{startOffset:j,endOffset:j}]),!0}const{horizontalLine:l}=t!=null?t:{},{segmentId:A}=a,d=n.getCurrentUnitForType(i.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:g,endOffset:h}=a,f=((z=u.paragraphs)!=null?z:[]).find(j=>j.startIndex>=g);if(!f)return!1;const S=g===f.startIndex,v=f.startIndex,C=s.getDefaultStyle(),y=s.getStyleCache(),b=an(u,h,C,y),E={dataStream:i.DataStreamTreeTokenType.PARAGRAPH,paragraphs:_o(i.DataStreamTreeTokenType.PARAGRAPH,f,l),textRuns:[{st:0,ed:1,ts:{...b.ts}}]};if(d==null)return!1;const R=e.getActiveTextRange();if(u==null)return!1;const{collapsed:O}=a,T=E.dataStream.length,_=[{startOffset:g+T,endOffset:g+T,style:R==null?void 0:R.style,collapsed:O}],M={id:B.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:_,debounce:!0}},N=new i.TextX,F=i.JSONX.getInstance();if(O)g>0&&N.push({t:i.TextXActionType.RETAIN,len:g}),N.push({t:i.TextXActionType.INSERT,body:E,len:E.dataStream.length});else{const j=i.BuildTextUtils.selection.delete([a],u,0,E);N.push(...j)}(((W=f.bullet)==null?void 0:W.listType)===i.PresetListType.CHECK_LIST_CHECKED||(H=f.paragraphStyle)!=null&&H.headingId)&&(a.endOffset<v&&N.push({t:i.TextXActionType.RETAIN,len:v-a.endOffset}),N.push({t:i.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...f,paragraphStyle:{...f.paragraphStyle,...S?{headingId:void 0,namedStyleType:void 0}:null},startIndex:0,bullet:(V=f.paragraphStyle)!=null&&V.headingId?void 0:{...f.bullet,listType:i.PresetListType.CHECK_LIST}}]},coverType:i.UpdateDocsAttributeType.REPLACE})),M.params.textRanges=[{startOffset:g+T,endOffset:g+T,collapsed:O}];const k=J(d,A);return M.params.actions=F.editOp(N.serialize(),k),!!r.syncExecuteCommand(M.id,M.params)}},xt={id:"doc.command.horizontal-line",type:i.CommandType.COMMAND,handler:(o,t)=>o.get(i.ICommandService).syncExecuteCommand(In.id,{horizontalLine:{padding:5,color:{rgb:"#CDD0D8"},width:1,dashStyle:i.DashStyleType.SOLID},textRange:t==null?void 0:t.insertRange})},No={id:"doc.command.insert-horizontal-line-bellow",type:i.CommandType.COMMAND,handler:o=>{const t=o.get(i.ICommandService),e=bt(o);return e?t.syncExecuteCommand(xt.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 Sr="doc.command.set-inline-format-bold",_e={id:Sr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Sr,t,e)}},Ir="doc.command.set-inline-format-italic",Ne={id:Ir,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Ir,t,e)}},vr="doc.command.set-inline-format-underline",Pe={id:vr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(vr,t,e)}},Er="doc.command.set-inline-format-strikethrough",Ue={id:Er,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Er,t,e)}},Cr="doc.command.set-inline-format-subscript",ye={id:Cr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Cr,t,e)}},Tr="doc.command.set-inline-format-superscript",we={id:Tr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Tr,t,e)}},yr="doc.command.set-inline-format-fontsize",me={id:yr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(yr,t,e)}},br="doc.command.set-inline-format-font-family",We={id:br,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(br,t,e)}},Rr="doc.command.set-inline-format-text-color",Me={id:Rr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Rr,t,e)}},xr="doc.command.set-inline-format-text-background-color",De={id:xr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(xr,t,e)}},Or="doc.command.reset-inline-format-text-background-color",at={id:Or,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Or,t,e)}},Jn={[_e.id]:"bl",[Ne.id]:"it",[Pe.id]:"ul",[Ue.id]:"st",[me.id]:"fs",[We.id]:"ff",[Me.id]:"cl",[De.id]:"bg",[at.id]:"bg",[ye.id]:"va",[we.id]:"va"},be={id:"doc.command.set-inline-format",type:i.CommandType.COMMAND,handler:async(o,t)=>{var b;const{value:e,preCommandId:n}=t,r=o.get(i.ICommandService),s=o.get(B.DocSelectionManagerService),a=o.get(i.IUniverInstanceService),c=o.get(Te),l=s.getDocRanges(),A=(b=l.find(E=>E.isActive))!=null?b:l[0];if(l.length===0)return!1;const{segmentId:d}=l[0],u=a.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);if(u==null)return!1;const m=u.getSelfOrHeaderFooterModel(d).getBody();if(m==null)return!1;const g=u.getUnitId();let h;switch(n){case _e.id:case Ne.id:case Pe.id:case Ue.id:case ye.id:case we.id:{const E=c.getDefaultStyle(),R=Xi(m,A,E);h=Za(R,n);break}case me.id:case We.id:{h=e;break}case Me.id:case De.id:{h={rgb:e};break}case at.id:{h={rgb:null};break}default:throw new Error(`Unknown command: ${n} in handleInlineFormat`)}const p={id:B.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:l}},f=new i.TextX,S=i.JSONX.getInstance(),v=new i.MemoryCursor;v.reset();for(const E of l){let{startOffset:R,endOffset:O,rangeType:T}=E;if(R==null||O==null)continue;if(T===i.DOC_RANGE_TYPE.RECT&&(R=R-1),R===O){const N=c.getStyleCache(),F=Jn[n];c.setStyleCache({[F]:(N==null?void 0:N[F])!==void 0?Gi(N,F,n):h});continue}const _={dataStream:"",textRuns:[{st:0,ed:O-R,ts:{[Jn[n]]:h}}]},M=R-v.cursor;M!==0&&f.push({t:i.TextXActionType.RETAIN,len:M}),f.push({t:i.TextXActionType.RETAIN,body:_,len:O-R}),v.reset(),v.moveCursor(O)}const C=J(u,d);return p.params.actions=S.editOp(f.serialize(),C),!!r.syncExecuteCommand(p.id,p.params)}};function Ja(o){return o!==null&&typeof o=="object"}function Gi(o,t,e){if(/bl|it/.test(t))return(o==null?void 0:o[t])===i.BooleanNumber.TRUE?i.BooleanNumber.FALSE:i.BooleanNumber.TRUE;if(/ul|st/.test(t))return Ja(o==null?void 0:o[t])&&(o==null?void 0:o[t]).s===i.BooleanNumber.TRUE?{s:i.BooleanNumber.FALSE}:{s:i.BooleanNumber.TRUE};if(/va/.test(t))return e===ye.id?(o==null?void 0:o[t])===i.BaselineOffset.SUBSCRIPT?i.BaselineOffset.NORMAL:i.BaselineOffset.SUBSCRIPT:(o==null?void 0:o[t])===i.BaselineOffset.SUPERSCRIPT?i.BaselineOffset.NORMAL:i.BaselineOffset.SUPERSCRIPT}function Xi(o,t,e){var d,u,m,g,h,p,f,S,v,C,y,b,E,R;const{startOffset:n,endOffset:r,collapsed:s}=t;if(s){const O=(d=o.textRuns)!=null?d:[];let T=null;for(let _=O.length-1;_>=0;_--){const M=O[_];if(M.st<n&&n<=M.ed){T=M;break}}return T!=null&&T.ts?{...e,...T.ts}:e}const{textRuns:a=[]}=i.getBodySlice(o,n,r),c=i.Tools.deepClone(e),l=a.map(O=>{var T;return(T=O==null?void 0:O.ts)==null?void 0:T.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=(g=(m=(u=a.find(O=>{var T;return((T=O.ts)==null?void 0:T.ff)!=null}))==null?void 0:u.ts)==null?void 0:m.ff)!=null?g:c.ff,c.it=a.length&&a.every(O=>{var T;return((T=O.ts)==null?void 0:T.it)===i.BooleanNumber.TRUE})?i.BooleanNumber.TRUE:i.BooleanNumber.FALSE,c.bl=a.length&&a.every(O=>{var T;return((T=O.ts)==null?void 0:T.bl)===i.BooleanNumber.TRUE})?i.BooleanNumber.TRUE:i.BooleanNumber.FALSE,c.ul=a.length&&a.every(O=>{var T,_;return((_=(T=O.ts)==null?void 0:T.ul)==null?void 0:_.s)===i.BooleanNumber.TRUE})?(h=a[0].ts)==null?void 0:h.ul:c.ul,c.st=a.length&&a.every(O=>{var T,_;return((_=(T=O.ts)==null?void 0:T.st)==null?void 0:_.s)===i.BooleanNumber.TRUE})?(p=a[0].ts)==null?void 0:p.st:c.st,c.bg=(v=(S=(f=a.find(O=>{var T;return((T=O.ts)==null?void 0:T.bg)!=null}))==null?void 0:f.ts)==null?void 0:S.bg)!=null?v:c.bg,c.cl=(b=(y=(C=a.find(O=>{var T;return((T=O.ts)==null?void 0:T.cl)!=null}))==null?void 0:C.ts)==null?void 0:y.cl)!=null?b:c.cl;const A=a.filter(O=>{var T;return((T=O==null?void 0:O.ts)==null?void 0:T.va)!=null});if(A.length>0&&A.length===a.length){const O=(E=A[0].ts)==null?void 0:E.va;let T=!0;for(let _=1;_<A.length;_++)if(((R=A[_].ts)==null?void 0:R.va)!==O){T=!1;break}T&&(c.va=O)}return c}function Za(o,t){const e=Jn[t];return Gi(o,e,t)}const ct={id:"doc.command.list-operation",type:i.CommandType.COMMAND,handler:(o,t)=>{var y,b,E,R,O,T;const e=o.get(B.DocSelectionManagerService),n=o.get(i.IUniverInstanceService),r=o.get(i.ICommandService),s=t.listType,a=n.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),c=(b=(y=t.docRange)!=null?y:e.getDocRanges())!=null?b:[];if(a==null||c.length===0)return!1;const l=c[0].segmentId,A=a.getSelfOrHeaderFooterModel(l),d=(R=(E=A.getBody())==null?void 0:E.paragraphs)!=null?R:[],u=(T=(O=A.getBody())==null?void 0:O.dataStream)!=null?T:"";if(!d.length)return!1;const m=i.BuildTextUtils.range.getParagraphsInRanges(c,d,u),g=a.getUnitId(),h={id:B.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:c,isEditing:!1}};new i.MemoryCursor().reset();const f=i.BuildTextUtils.paragraph.bullet.switch({paragraphs:m,listType:s,document:a,segmentId:l}),S=i.JSONX.getInstance(),v=J(a,l);return h.params.actions=S.editOp(f.serialize(),v),!!r.syncExecuteCommand(h.id,h.params)}},Ot={id:"doc.command.change-list-type",type:i.CommandType.COMMAND,handler:(o,t)=>{var C,y,b,E,R;const e=o.get(B.DocSelectionManagerService),n=o.get(i.IUniverInstanceService),r=o.get(i.ICommandService),{listType:s}=t,a=n.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),c=(C=t.docRange)!=null?C:e.getDocRanges();if(a==null||c==null||!c.length)return!1;const{segmentId:l}=c[0],A=a.getSelfOrHeaderFooterModel(l),d=(b=(y=A.getBody())==null?void 0:y.paragraphs)!=null?b:[],u=(R=(E=A.getBody())==null?void 0:E.dataStream)!=null?R:"";if(!d.length)return!1;const m=i.BuildTextUtils.range.getParagraphsInRanges(c,d,u),g=a.getUnitId(),h=i.BuildTextUtils.paragraph.bullet.set({paragraphs:m,listType:s,segmentId:l,document:a});if(!h)return!1;const p=i.JSONX.getInstance(),f={id:B.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:c,isEditing:!1}},S=J(a,l);return f.params.actions=p.editOp(h.serialize(),S),!!r.syncExecuteCommand(f.id,f.params)}};var It=(o=>(o[o.increase=1]="increase",o[o.decrease=-1]="decrease",o))(It||{});const Yt={id:"doc.command.change-list-nesting-level",type:i.CommandType.COMMAND,handler:(o,t)=>{var y,b,E,R,O;if(!t)return!1;const{type:e}=t,n=o.get(B.DocSelectionManagerService),r=o.get(i.IUniverInstanceService),s=o.get(i.ICommandService),a=r.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),c=n.getActiveTextRange();if(a==null||c==null)return!1;const{segmentId:l}=c,A=(y=n.getDocRanges())!=null?y:[],d=a.getSelfOrHeaderFooterModel(l),u=(E=(b=d.getBody())==null?void 0:b.paragraphs)!=null?E:[],m=(O=(R=d.getBody())==null?void 0:R.dataStream)!=null?O:"";if(!u.length)return!1;const g=i.BuildTextUtils.range.getParagraphsInRange(c,u,m),h=a.getUnitId(),p=i.JSONX.getInstance(),f=i.BuildTextUtils.paragraph.bullet.changeNestLevel({paragraphs:g,type:e,segmentId:l,document:a}),S={id:B.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:A,isEditing:!1}},v=J(a,l);return S.params.actions=p.editOp(f.serialize(),v),!!s.syncExecuteCommand(S.id,S.params)}},nt={id:"doc.command.bullet-list",type:i.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(i.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(Ot.id,{listType:t.value,docRange:t.docRange}):e.syncExecuteCommand(ct.id,{listType:i.PresetListType.BULLET_LIST,docRange:t==null?void 0:t.docRange})}},Ct={id:"doc.command.check-list",type:i.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(i.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(Ot.id,{listType:t.value,docRange:t.docRange}):e.syncExecuteCommand(ct.id,{listType:i.PresetListType.CHECK_LIST,docRange:t==null?void 0:t.docRange})}},Po={id:"doc.command.toggle-check-list",type:i.CommandType.COMMAND,handler:(o,t)=>{var p;if(!t)return!1;const e=o.get(i.IUniverInstanceService),n=o.get(i.ICommandService),{index:r,segmentId:s,textRanges:a}=t,c=e.getCurrentUnitForType(i.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:B.RichTextEditingMutation.id,params:{unitId:A,actions:[],textRanges:a!=null?a:[],segmentId:s,isEditing:!1}},u=i.BuildTextUtils.paragraph.bullet.toggleChecklist({document:c,paragraphIndex:r,segmentId:s});if(!u)return!1;const m=i.JSONX.getInstance(),g=J(c,s);return d.params.actions=m.editOp(u.serialize(),g),!!n.syncExecuteCommand(d.id,d.params)}},ot={id:"doc.command.order-list",type:i.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(i.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(Ot.id,{listType:t.value}):e.syncExecuteCommand(ct.id,{listType:i.PresetListType.ORDER_LIST})}},Uo={id:"doc.command.quick-list",type:i.CommandType.COMMAND,handler(o,t){var G,K,Y,X,q;if(!t)return!1;const e=o.get(B.DocSelectionManagerService),n=o.get(i.IUniverInstanceService),r=o.get(i.ICommandService),s=n.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),a=e.getActiveTextRange();if(s==null||a==null)return!1;const{segmentId:c,startOffset:l}=a,{listType:A,paragraph:d}=t,{paragraphStart:u,paragraphEnd:m}=d,g=new i.TextX,h=i.JSONX.getInstance(),{defaultTabStop:p=36}=s.getSnapshot().documentStyle,f=(K=(G=s.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:G.sectionBreaks)!=null?K:[],{startIndex:S,paragraphStyle:v={}}=d,{indentFirstLine:C,snapToGrid:y,indentStart:b}=v,E=i.PRESET_LIST_TYPE[A].nestingLevel[0].paragraphProperties||{},{hanging:R,indentStart:O}=E,T=E.textStyle,{charSpace:_,gridType:M}=$a(S,f)||{charSpace:0,gridType:i.GridType.LINES},N=D.getCharSpaceApply(_,p,M,y);let k=i.Tools.generateRandomId(6);const Q=(X=(Y=s.getBody())==null?void 0:Y.paragraphs)!=null?X:[],w=Q.findIndex(ee=>ee.startIndex===d.startIndex),z=Q[w-1],W=Q[w+1];z&&z.bullet&&z.bullet.listType.indexOf(A)===0?k=z.bullet.listId:W&&W.bullet&&W.bullet.listType.indexOf(A)===0&&(k=W.bullet.listId);const H={id:B.RichTextEditingMutation.id,params:{unitId:s.getUnitId(),actions:[],textRanges:[{startOffset:u,endOffset:u,collapsed:!0}],isEditing:!1}};g.push({t:i.TextXActionType.RETAIN,len:u}),g.push({t:i.TextXActionType.DELETE,len:l-u}),m>l&&g.push({t:i.TextXActionType.RETAIN,len:m-l}),g.push({t:i.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{startIndex:0,paragraphStyle:{...v,textStyle:{...v.textStyle,...T},indentFirstLine:void 0,hanging:R,indentStart:{v:D.getNumberUnitValue(O,N)-D.getNumberUnitValue(R,N)+D.getNumberUnitValue(C,N)+D.getNumberUnitValue(b,N)}},bullet:{...(q=d.bullet)!=null?q:{nestingLevel:0,textStyle:{fs:20}},listType:A,listId:k}}]}});const V=J(s,c);return H.params.actions=h.editOp(g.serialize(),V),!!r.syncExecuteCommand(H.id,H.params)}};function wo(o,t){var d,u;const e=o.get(i.ICommandService),n=bt(o);if(!n)return!1;const r=o.get(i.IUniverInstanceService).getCurrentUnitOfType(i.UniverInstanceType.UNIVER_DOC);if(!r)return!1;const s=i.BuildTextUtils.selection.replace({doc:r,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:i.Tools.generateRandomId(6),nestingLevel:((u=n.bullet)==null?void 0:u.listType)===t?n.bullet.nestingLevel:0}}]}});if(!s)return!1;const a={id:B.RichTextEditingMutation.id,params:{unitId:r.getUnitId(),actions:[],textRanges:[{startOffset:n.startIndex+1,endOffset:n.startIndex+1,collapsed:!0}],isEditing:!1}},c=i.JSONX.getInstance(),l=J(r);return a.params.actions=c.editOp(s.serialize(),l),!!e.syncExecuteCommand(a.id,a.params)}const Lo={id:"doc.command.insert-bullet-list-bellow",type:i.CommandType.COMMAND,handler:o=>wo(o,i.PresetListType.BULLET_LIST)},Qo={id:"doc.command.insert-order-list-bellow",type:i.CommandType.COMMAND,handler:o=>wo(o,i.PresetListType.ORDER_LIST)},Fo={id:"doc.command.insert-check-list-bellow",type:i.CommandType.COMMAND,handler:o=>wo(o,i.PresetListType.CHECK_LIST)};function $a(o,t){const e=t.sort(i.sortRulesFactory("startIndex"));for(let n=0;n<e.length;n++){const r=t[n];if(r.startIndex>=o)return r}}const le={id:"doc.command.set-paragraph-named-style",type:i.CommandType.COMMAND,handler(o,t){var h;if(!t)return!1;const n=o.get(i.IUniverInstanceService).getCurrentUnitOfType(i.UniverInstanceType.UNIVER_DOC);if(!n)return!1;const r=n.getUnitId(),s=o.get(B.DocSelectionManagerService),a=(h=t.textRanges)!=null?h:s.getTextRanges({unitId:r,subUnitId:r});if(!(a!=null&&a.length))return!1;const c=a[0].segmentId,l=i.BuildTextUtils.paragraph.style.set({document:n.getSelfOrHeaderFooterModel(c),textRanges:a,style:{namedStyleType:t.value,headingId:!t.value||t.value===i.NamedStyleType.NORMAL_TEXT?void 0:i.generateRandomId(6),spaceAbove:void 0,spaceBelow:void 0},paragraphTextRun:{}}),A={id:B.RichTextEditingMutation.id,params:{actions:[],textRanges:a,unitId:r,segmentId:c}},d=i.JSONX.getInstance(),u=J(n,c);return A.params.actions=d.editOp(l.serialize(),u),!!o.get(i.ICommandService).syncExecuteCommand(A.id,A.params)}},Ki={id:"doc.command.quick-heading",type:i.CommandType.COMMAND,handler(o,t){var b,E,R,O;if(!t)return!1;const{value:e}=t,n=o.get(B.DocSelectionManagerService),r=o.get(i.IUniverInstanceService),s=o.get(i.ICommandService),a=r.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),c=n.getActiveTextRange();if(a==null||c==null||!c.collapsed)return!1;const{segmentId:l,startOffset:A}=c,d=a.getSelfOrHeaderFooterModel(l),u=(E=(b=d.getBody())==null?void 0:b.paragraphs)!=null?E:[],m=(O=(R=d.getBody())==null?void 0:R.dataStream)!=null?O:"",g=i.BuildTextUtils.paragraph.util.getParagraphsInRange(c,u,m)[0];if(!g)return!1;const{paragraphStart:h}=g,p=new i.TextX,f=i.JSONX.getInstance(),{paragraphStyle:S={}}=g,v={id:B.RichTextEditingMutation.id,params:{unitId:a.getUnitId(),actions:[],textRanges:[{startOffset:h,endOffset:h,collapsed:!0}],isEditing:!1}};p.push({t:i.TextXActionType.RETAIN,len:h}),i.BuildTextUtils.paragraph.style.set({textRanges:[c],document:a,style:{...S,headingId:i.generateRandomId(6),namedStyleType:e},cursor:A,deleteLen:A-h,textX:p,paragraphTextRun:{}});const C=J(a,l);return v.params.actions=f.editOp(p.serialize(),C),!!s.syncExecuteCommand(v.id,v.params)}},wn={"#":i.NamedStyleType.HEADING_1,"##":i.NamedStyleType.HEADING_2,"###":i.NamedStyleType.HEADING_3,"####":i.NamedStyleType.HEADING_4,"#####":i.NamedStyleType.HEADING_5},Ho={id:"doc.command.h1-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_1})},ko={id:"doc.command.h2-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_2})},Vo={id:"doc.command.h3-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_3})},jo={id:"doc.command.h4-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_4})},Wo={id:"doc.command.h5-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_5})},qt={id:"doc.command.normal-text-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.NORMAL_TEXT})},Yi={id:"doc.command.title",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.TITLE})},qi={id:"doc.command.subtitle-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.SUBTITLE})},pe={id:"doc.command.align-action",type:i.CommandType.COMMAND,handler:(o,t)=>{var b,E,R,O;const e=o.get(B.DocSelectionManagerService),n=o.get(i.IUniverInstanceService),r=o.get(i.ICommandService),{alignType:s}=t,a=n.getCurrentUniverDocInstance();if(a==null)return!1;const c=e.getDocRanges();if(c.length===0)return!1;const l=c[0].segmentId,A=a.getSelfOrHeaderFooterModel(l),d=(E=(b=A.getBody())==null?void 0:b.paragraphs)!=null?E:[],u=(O=(R=A.getBody())==null?void 0:R.dataStream)!=null?O:"";if(d==null)return!1;const m=i.BuildTextUtils.range.getParagraphsInRanges(c,d,u),g=a.getUnitId(),h=m.every(T=>{var _;return((_=T.paragraphStyle)==null?void 0:_.horizontalAlign)===s}),p={id:B.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:c}},f=new i.MemoryCursor;f.reset();const S=new i.TextX,v=i.JSONX.getInstance();for(const T of m){const{startIndex:_}=T;S.push({t:i.TextXActionType.RETAIN,len:_-f.cursor});const M={...T.paragraphStyle,horizontalAlign:h?i.HorizontalAlign.UNSPECIFIED:s};S.push({t:i.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...T,paragraphStyle:M,startIndex:0}]},coverType:i.UpdateDocsAttributeType.REPLACE}),f.moveCursorTo(_+1)}const C=J(a,l);return p.params.actions=v.editOp(S.serialize(),C),!!r.syncExecuteCommand(p.id,p.params)}},Mt={id:"doc.command.align-left",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(pe.id,{alignType:i.HorizontalAlign.LEFT})},Dt={id:"doc.command.align-center",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(pe.id,{alignType:i.HorizontalAlign.CENTER})},Bt={id:"doc.command.align-right",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(pe.id,{alignType:i.HorizontalAlign.RIGHT})},_t={id:"doc.command.align-justify",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(pe.id,{alignType:i.HorizontalAlign.JUSTIFIED})},vn={id:"doc.command.switch-mode",type:i.CommandType.COMMAND,handler:async o=>{var v,C,y,b,E;const t=o.get(i.ICommandService),e=o.get(D.IRenderManagerService),n=o.get(B.DocSelectionManagerService),s=o.get(i.IUniverInstanceService).getCurrentUniverDocInstance();if(s==null)return!1;const a=s.getUnitId(),c=(v=e.getRenderById(a))==null?void 0:v.with(B.DocSkeletonManagerService).getSkeleton(),l=(C=e.getRenderById(a))==null?void 0:C.with(exports.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(),g={id:B.RichTextEditingMutation.id,params:{unitId:a,actions:[],textRanges:u===i.DocumentFlavor.TRADITIONAL&&A?[]:m}},h=i.JSONX.getInstance(),p=[];let f;if(u===void 0?f=h.insertOp(["documentStyle","documentFlavor"],i.DocumentFlavor.MODERN):u===i.DocumentFlavor.MODERN?f=h.replaceOp(["documentStyle","documentFlavor"],u,i.DocumentFlavor.TRADITIONAL):f=h.replaceOp(["documentStyle","documentFlavor"],u,i.DocumentFlavor.MODERN),f)p.push(f);else return!1;if(u!==i.DocumentFlavor.MODERN){const R=s.getSnapshot(),{drawings:O={},body:T}=R,_=(y=T==null?void 0:T.customBlocks)!=null?y:[];for(const M in O){const N=O[M],F=_.find(q=>q.blockId===M);if(F==null)continue;const k=N.docTransform.positionV,{relativeFrom:Q,posOffset:w}=k;if(Q===i.ObjectRelativeFromV.PARAGRAPH)continue;const{startIndex:z}=F,W=c.findNodeByCharIndex(z,A,d),H=(b=W==null?void 0:W.parent)==null?void 0:b.parent,V=H==null?void 0:H.parent,j=V==null?void 0:V.lines.find(q=>q.paragraphIndex===(H==null?void 0:H.paragraphIndex)&&q.paragraphStart),G=(E=V==null?void 0:V.parent)==null?void 0:E.parent;if(W==null||H==null||j==null||V==null||G==null)continue;let K=0;Q===i.ObjectRelativeFromV.LINE?K-=H.top:Q===i.ObjectRelativeFromV.PAGE&&(K+=G.marginTop),K+=j.top;const Y={...k,relativeFrom:i.ObjectRelativeFromV.PARAGRAPH,posOffset:(w!=null?w:0)-K},X=h.replaceOp(["drawings",M,"docTransform","positionV"],k,Y);X&&p.push(X)}}return g.params.actions=p.reduce((R,O)=>i.JSONX.compose(R,O),null),!!t.syncExecuteCommand(g.id,g.params)}},Ji="COMPONENT_DOC_CREATE_TABLE_CONFIRM",ec="doc.command.create-table",zo={id:ec,type:i.CommandType.COMMAND,handler:async(o,t)=>{var Y,X,q,ee,ge;const{rowCount:e,colCount:n}=t,r=o.get(B.DocSelectionManagerService),s=o.get(i.IUniverInstanceService),a=o.get(i.ICommandService),c=o.get(Te),l=r.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 g=u.getUnitId(),h=ce(o,g),p=h==null?void 0:h.getSkeleton();if(p==null)return!1;const{startOffset:f}=l,v=((Y=m.paragraphs)!=null?Y:[]).find(xe=>xe.startIndex>=f),C=p.findNodeByCharIndex(f,A,d);if(C==null)return!1;const y=new i.TextX,b=i.JSONX.getInstance(),E=[],R=f+4,O=[{startOffset:R,endOffset:R,collapsed:!0}],T={id:B.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:O}};f>0&&y.push({t:i.TextXActionType.RETAIN,len:f}),y.push({t:i.TextXActionType.INSERT,body:{dataStream:i.DataStreamTreeTokenType.PARAGRAPH,paragraphs:_o(i.DataStreamTreeTokenType.PARAGRAPH,v)},len:1});const _=c.getDefaultStyle(),M=c.getStyleCache(),N=an(m,f,_,M),{dataStream:F,paragraphs:k,sectionBreaks:Q}=Ca(e,n),w=(ge=(ee=(q=(X=C.parent)==null?void 0:X.parent)==null?void 0:q.parent)==null?void 0:ee.parent)==null?void 0:ge.parent;if(w==null)return!1;const{pageWidth:z,marginLeft:W,marginRight:H}=w,V=Co(e,n,z-W-H);y.push({t:i.TextXActionType.INSERT,body:{dataStream:F,paragraphs:k,sectionBreaks:Q,textRuns:[{...N,st:0,ed:F.length}],tables:[{startIndex:0,endIndex:F.length,tableId:V.tableId}]},len:F.length});const j=J(u,A);E.push(b.editOp(y.serialize(),j));const G=b.insertOp(["tableSource",V.tableId],V);return E.push(G),T.params.actions=E.reduce((xe,he)=>i.JSONX.compose(xe,he),null),!!a.syncExecuteCommand(T.id,T.params)}},Ln="doc.component.create-table-confirm",En={id:"doc.operation.create-table",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(i.LocaleService),e=o.get(I.IConfirmService),n=o.get(i.ICommandService),r={rowCount:3,colCount:5},s=(a,c)=>{r.rowCount=a,r.colCount=c};return await e.open({id:Ln,children:{label:{name:Ji,props:{handleRowColChange:s,tableCreateParams:r}}},width:400,title:{title:t.t("toolbar.table.insert")},onConfirm:()=>{n.executeCommand(zo.id,r),e.close(Ln)},onClose:()=>{e.close(Ln)}}),!0}};function tc(o){const t=o.get(i.IUniverInstanceService),e=o.get(D.IRenderManagerService);return new P.Observable(n=>{const r=t.focused$.subscribe(s=>{if(s==null||t.getUnitType(s)!==i.UniverInstanceType.UNIVER_DOC)return n.next(!0);const c=e.getRenderById(s);if(c==null)return n.next(!0);c.with(B.DocSkeletonManagerService).getViewModel().editAreaChange$.subscribe(A=>{n.next(A===D.DocumentEditArea.HEADER||A===D.DocumentEditArea.FOOTER)})});return()=>r.unsubscribe()})}function nc(o){const t=o.get(i.IUniverInstanceService),e=o.get(i.ICommandService);return new P.Observable(n=>{const r=e.onCommandExecuted(l=>{if(l.id===B.RichTextEditingMutation.id){const{unitId:A}=l.params,d=t.getUnit(A);if(d==null){n.next(!0);return}const{documentStyle:u}=d.getSnapshot();n.next((u==null?void 0:u.documentFlavor)!==i.DocumentFlavor.TRADITIONAL)}}),s=t.focused$.subscribe(l=>{if(l==null)return n.next(!0);const A=t.getUniverDocInstance(l),d=A==null?void 0:A.getSnapshot().documentStyle.documentFlavor;n.next(d!==i.DocumentFlavor.TRADITIONAL)}),a=t.getCurrentUniverDocInstance();if(a==null)return n.next(!0);const c=a==null?void 0:a.getSnapshot().documentStyle.documentFlavor;return n.next(c!==i.DocumentFlavor.TRADITIONAL),()=>{r.dispose(),s.unsubscribe()}})}function oc(o){const t=o.get(B.DocSelectionManagerService),e=o.get(i.IUniverInstanceService);return new P.Observable(n=>{const r=t.textSelection$.subscribe(s=>{if(s==null){n.next(!0);return}const{textRanges:a}=s;if(a.length!==1){n.next(!0);return}const c=a[0],{collapsed:l,startNodePosition:A,startOffset:d}=c;if(!l||d==null){n.next(!0);return}const u=e.getCurrentUniverDocInstance();if(u==null){n.next(!0);return}const m=ce(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()=>r.unsubscribe()})}function $(o){const t=o.get(B.DocSelectionManagerService);return new P.Observable(e=>{const n=t.textSelection$.subscribe(r=>{if(r==null){e.next(!0);return}const{textRanges:s,rectRanges:a}=r;if(s.length===0&&a.length===0){e.next(!0);return}e.next(!1)});return()=>n.unsubscribe()})}function rc(o){const t=o.get(i.ICommandService);return{id:_e.id,type:I.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",activated$:new P.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const a=(c=s.ts)==null?void 0:c.bl;e.next(a===i.BooleanNumber.TRUE)},r=t.onCommandExecuted(s=>{const a=s.id;(a===B.SetTextSelectionsOperation.id||a===be.id)&&n()});return n(),r.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function ic(o){const t=o.get(i.ICommandService);return{id:Ne.id,type:I.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",activated$:new P.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const a=(c=s.ts)==null?void 0:c.it;e.next(a===i.BooleanNumber.TRUE)},r=t.onCommandExecuted(s=>{const a=s.id;(a===B.SetTextSelectionsOperation.id||a===be.id)&&n()});return n(),r.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function sc(o){const t=o.get(i.ICommandService);return{id:Pe.id,type:I.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",activated$:new P.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const a=(c=s.ts)==null?void 0:c.ul;e.next((a==null?void 0:a.s)===i.BooleanNumber.TRUE)},r=t.onCommandExecuted(s=>{const a=s.id;(a===B.SetTextSelectionsOperation.id||a===be.id)&&n()});return n(),r.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function ac(o){const t=o.get(i.ICommandService);return{id:Ue.id,type:I.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",activated$:new P.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const a=(c=s.ts)==null?void 0:c.st;e.next((a==null?void 0:a.s)===i.BooleanNumber.TRUE)},r=t.onCommandExecuted(s=>{const a=s.id;(a===B.SetTextSelectionsOperation.id||a===be.id)&&n()});return n(),r.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function cc(o){const t=o.get(i.ICommandService);return{id:ye.id,type:I.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",activated$:new P.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const a=(c=s.ts)==null?void 0:c.va;e.next(a===i.BaselineOffset.SUBSCRIPT)},r=t.onCommandExecuted(s=>{const a=s.id;(a===B.SetTextSelectionsOperation.id||a===be.id)&&n()});return n(),r.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function lc(o){const t=o.get(i.ICommandService);return{id:we.id,type:I.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",activated$:new P.Observable(e=>{const n=()=>{var c;const s=Le(o);if(s==null){e.next(!1);return}const a=(c=s.ts)==null?void 0:c.va;e.next(a===i.BaselineOffset.SUPERSCRIPT)},r=t.onCommandExecuted(s=>{const a=s.id;(a===B.SetTextSelectionsOperation.id||a===be.id)&&n()});return n(),r.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function dc(o){const t=o.get(i.ICommandService);return{id:We.id,tooltip:"toolbar.font",type:I.MenuItemType.SELECTOR,label:Mi,selections:I.FONT_FAMILY_LIST.map(e=>({label:{name:Di},value:e.value})),value$:new P.Observable(e=>{const n=i.DEFAULT_STYLES.ff,r=()=>{var l;const a=Le(o);if(a==null){e.next(n);return}const c=(l=a.ts)==null?void 0:l.ff;e.next(c!=null?c:n)},s=t.onCommandExecuted(a=>{const c=a.id;(c===B.SetTextSelectionsOperation.id||c===We.id)&&r()});return r(),s.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Ac(o){const t=o.get(i.ICommandService);return{id:me.id,type:I.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Bi,props:{min:1,max:400}},selections:I.FONT_SIZE_LIST,value$:new P.Observable(e=>{const n=i.DEFAULT_STYLES.fs,r=()=>{var l;const a=Le(o);if(a==null){e.next(n);return}const c=(l=a.ts)==null?void 0:l.fs;e.next(c!=null?c:n)},s=t.onCommandExecuted(a=>{const c=a.id;(c===B.SetTextSelectionsOperation.id||c===me.id)&&r()});return r(),s.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function uc(o){const t=o.get(i.ICommandService);return{id:le.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 P.Observable(e=>{const n=i.NamedStyleType.NORMAL_TEXT,r=()=>{var l,A;const a=Ge(o);if(a==null){e.next(n);return}const c=(A=(l=a.paragraphStyle)==null?void 0:l.namedStyleType)!=null?A:n;e.next(c)},s=t.onCommandExecuted(a=>{const c=a.id;(c===B.SetTextSelectionsOperation.id||c===me.id)&&r()});return r(),s.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function gc(o){const t=o.get(i.ICommandService),e=o.get(i.ThemeService);return{id:Me.id,icon:"FontColor",tooltip:"toolbar.textColor.main",type:I.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:vo,hoverable:!1,selectable:!1}}],value$:new P.Observable(n=>{const r=e.getCurrentTheme().textColor,s=t.onCommandExecuted(a=>{if(a.id===Me.id){const c=a.params.value;n.next(c!=null?c:r)}});return n.next(r),s.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function hc(o){return{id:So.id,type:I.MenuItemType.BUTTON,icon:"HeaderFooterSingle",tooltip:"toolbar.headerFooter",hidden$:P.combineLatest(I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY),nc(o),(t,e)=>t||e)}}const mc="GridSingle",Zi="doc.menu.table";function pc(o){return{id:Zi,type:I.MenuItemType.SUBITEMS,icon:mc,tooltip:"toolbar.table.main",disabled$:oc(o),hidden$:P.combineLatest(I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY),tc(o),(t,e)=>t||e)}}function fc(o){return{id:En.id,title:"toolbar.table.insert",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Sc(o){const t=o.get(i.ICommandService);return{id:Mt.id,type:I.MenuItemType.BUTTON,icon:"LeftJustifyingSingle",tooltip:"toolbar.alignLeft",disabled$:$(o),activated$:new P.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===pe.id){const c=Ge(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.LEFT)}});return e.next(!1),n.dispose}),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Ic(o){const t=o.get(i.ICommandService);return{id:Dt.id,type:I.MenuItemType.BUTTON,icon:"HorizontallySingle",tooltip:"toolbar.alignCenter",activated$:new P.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===pe.id){const c=Ge(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.CENTER)}});return e.next(!1),n.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function vc(o){const t=o.get(i.ICommandService);return{id:Bt.id,type:I.MenuItemType.BUTTON,icon:"RightJustifyingSingle",tooltip:"toolbar.alignRight",activated$:new P.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===pe.id){const c=Ge(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.RIGHT)}});return e.next(!1),n.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Ec(o){const t=o.get(i.ICommandService);return{id:_t.id,type:I.MenuItemType.BUTTON,icon:"AlignTextBothSingle",tooltip:"toolbar.alignJustify",activated$:new P.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===pe.id){const c=Ge(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.JUSTIFIED)}});return e.next(!1),n.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Cc(o){return{id:xt.id,type:I.MenuItemType.BUTTON,icon:"ReduceSingle",tooltip:"toolbar.horizontalLine",disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}const Tt=o=>new P.Observable(t=>{const e=o.get(i.IUniverInstanceService),n=o.get(B.DocSelectionManagerService);let r;const s=e.focused$.subscribe(a=>{if(r==null||r.unsubscribe(),a==null)return;const c=e.getUniverDocInstance(a);c!=null&&(r=n.textSelection$.subscribe(()=>{var d,u,m,g,h;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=i.BuildTextUtils.range.getParagraphsInRange(A,(m=(u=p.getBody())==null?void 0:u.paragraphs)!=null?m:[],(h=(g=p.getBody())==null?void 0:g.dataStream)!=null?h:"");let S;if(f.every(v=>{var C;return S||(S=(C=v.bullet)==null?void 0:C.listType),v.bullet&&v.bullet.listType===S})){t.next(S);return}}t.next(void 0)}))});return()=>{s.unsubscribe(),r==null||r.unsubscribe()}});function Mr(o){return{id:ot.id,type:I.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:Ni,hoverable:!1,selectable:!1},value$:Tt(o)}],icon:"OrderSingle",tooltip:"toolbar.order",hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),disabled$:$(o),activated$:Tt(o).pipe(P.map(t=>t&&t.indexOf("ORDER_LIST")===0))}}function Dr(o){return{id:nt.id,type:I.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:Pi,hoverable:!1,selectable:!1},value$:Tt(o)}],icon:"UnorderSingle",tooltip:"toolbar.unorder",disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),activated$:Tt(o).pipe(P.map(t=>t&&t.indexOf("BULLET_LIST")===0))}}function Br(o){return{id:Ct.id,type:I.MenuItemType.BUTTON,icon:"TodoList",tooltip:"toolbar.checklist",disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),activated$:Tt(o).pipe(P.map(t=>t&&t.indexOf("CHECK_LIST")===0))}}function Tc(o){const t=o.get(i.ICommandService),e=o.get(i.IUniverInstanceService);return{id:vn.id,type:I.MenuItemType.BUTTON,icon:"KeyboardSingle",tooltip:"toolbar.documentFlavor",hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY),activated$:new P.Observable(n=>{var a;const r=t.onCommandExecuted(c=>{var l;if(c.id===B.RichTextEditingMutation.id){const A=e.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);n.next(((l=A==null?void 0:A.getSnapshot())==null?void 0:l.documentStyle.documentFlavor)===i.DocumentFlavor.MODERN)}}),s=e.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);return n.next(((a=s==null?void 0:s.getSnapshot())==null?void 0:a.documentStyle.documentFlavor)===i.DocumentFlavor.MODERN),()=>r.dispose()})}}function yc(o){return{id:at.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor"}}function bc(o){const t=o.get(i.ICommandService),e=o.get(i.ThemeService);return{id:De.id,tooltip:"toolbar.fillColor.main",type:I.MenuItemType.BUTTON_SELECTOR,icon:"PaintBucket",selections:[{label:{name:vo,hoverable:!1,selectable:!1}}],value$:new P.Observable(n=>{const r=e.getCurrentTheme().primaryColor,s=t.onCommandExecuted(a=>{if(a.id===De.id){const c=a.params.value;n.next(c!=null?c:r)}});return n.next(r),s.dispose}),disabled$:$(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Le(o){var h,p,f,S;const t=o.get(i.IUniverInstanceService),e=o.get(B.DocSelectionManagerService),n=o.get(Te),r=t.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),s=e.getDocRanges(),a=(h=s.find(v=>v.isActive))!=null?h: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?i.NAMED_STYLE_MAP[(S=A==null?void 0:A.paragraphStyle)==null?void 0:S.namedStyleType]:null;if(r==null||a==null)return{ts:{...c,...d,...l}};const{segmentId:u}=a,m=r.getSelfOrHeaderFooterModel(u).getBody();if(m==null)return{ts:{...c,...d,...l}};const g=Xi(m,a,{});return i.Tools.deleteNull(g),{ts:{...c,...d,...g,...l}}}function Ge(o){var d,u;const t=o.get(i.IUniverInstanceService),e=o.get(B.DocSelectionManagerService),n=t.getCurrentUniverDocInstance(),r=e.getDocRanges(),s=(d=r.find(m=>m.isActive))!=null?d:r[0];if(n==null||s==null)return;const{startOffset:a,segmentId:c}=s,l=(u=n.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:u.paragraphs;if(l==null)return;let A=-1;for(const m of l){const{startIndex:g}=m;if(a>A&&a<=g)return m;A=g}return null}const Rc={[i.NamedStyleType.HEADING_1]:Ho,[i.NamedStyleType.HEADING_2]:ko,[i.NamedStyleType.HEADING_3]:Vo,[i.NamedStyleType.HEADING_4]:jo,[i.NamedStyleType.HEADING_5]:Wo,[i.NamedStyleType.NORMAL_TEXT]:qt,[i.NamedStyleType.TITLE]:Yi,[i.NamedStyleType.SUBTITLE]:qi,[i.NamedStyleType.NAMED_STYLE_TYPE_UNSPECIFIED]:qt},$i={[i.NamedStyleType.HEADING_1]:{key:"H1Single",component:Si},[i.NamedStyleType.HEADING_2]:{key:"H2Single",component:Ii},[i.NamedStyleType.HEADING_3]:{key:"H3Single",component:vi},[i.NamedStyleType.HEADING_4]:{key:"H4Single",component:Ei},[i.NamedStyleType.HEADING_5]:{key:"H5Single",component:Ci},[i.NamedStyleType.NORMAL_TEXT]:{key:"TextTypeSingle",component:ft},[i.NamedStyleType.TITLE]:{key:"TextTypeSingle",component:ft},[i.NamedStyleType.SUBTITLE]:{key:"TextTypeSingle",component:ft},[i.NamedStyleType.NAMED_STYLE_TYPE_UNSPECIFIED]:{key:"TextTypeSingle",component:ft}},Qe=o=>t=>{const e=t.get(i.ICommandService),n=t.get(I.ComponentManager),r=$i[o];return n.get(r.key)||n.register(r.key,r.component),{id:Rc[o].id,type:I.MenuItemType.BUTTON,icon:r.key,tooltip:"toolbar.heading.tooltip",disabled$:$(t),hidden$:I.getMenuHiddenObservable(t,i.UniverInstanceType.UNIVER_DOC),activated$:new P.Observable(s=>{const a=i.NamedStyleType.NORMAL_TEXT,c=()=>{var u,m;const A=Ge(t);if(A==null){s.next(a===o);return}const d=(m=(u=A.paragraphStyle)==null?void 0:u.namedStyleType)!=null?m:a;s.next(d===o)},l=e.onCommandExecuted(A=>{const d=A.id;(d===B.SetTextSelectionsOperation.id||d===me.id)&&c()});return c(),l.dispose})}},xc=Qe(i.NamedStyleType.HEADING_1),Oc=Qe(i.NamedStyleType.HEADING_2),Mc=Qe(i.NamedStyleType.HEADING_3),Dc=Qe(i.NamedStyleType.HEADING_4),Bc=Qe(i.NamedStyleType.HEADING_5),_c=Qe(i.NamedStyleType.NORMAL_TEXT);Qe(i.NamedStyleType.TITLE);Qe(i.NamedStyleType.SUBTITLE);const Nc=o=>({id:Do.id,type:I.MenuItemType.BUTTON,icon:"Copy",title:"rightClick.copy"}),Pc=o=>({id:Bo.id,type:I.MenuItemType.BUTTON,icon:"CutSingle",title:"rightClick.cut"}),Uc=o=>({id:xo.id,type:I.MenuItemType.BUTTON,icon:"DeleteSingle",title:"rightClick.delete"}),wc=o=>({id:Lo.id,type:I.MenuItemType.BUTTON,icon:"UnorderSingle",title:"rightClick.bulletList"}),Lc=o=>({id:Qo.id,type:I.MenuItemType.BUTTON,icon:"OrderSingle",title:"rightClick.orderList"}),Qc=o=>({id:Fo.id,type:I.MenuItemType.BUTTON,icon:"TodoList",title:"rightClick.checkList"}),Fc=o=>({id:No.id,type:I.MenuItemType.BUTTON,icon:"ReduceSingle",title:"toolbar.horizontalLine"}),es="doc.menu.insert-bellow";function Hc(o){return{id:es,type:I.MenuItemType.SUBITEMS,title:"rightClick.insertBellow"}}const Zn=4,kc=(o,t)=>{const e=o.get(i.IUniverInstanceService).getUniverDocInstance(t.unitId),n=(e==null?void 0:e.zoomRatio)||1;return{...i.Tools.deepClone(t),zoomRatio:n}},Ae={id:"doc.operation.set-zoom-ratio",type:i.CommandType.OPERATION,handler:(o,t)=>{const e=o.get(i.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 Vc=Object.getOwnPropertyDescriptor,jc=(o,t,e,n)=>{for(var r=n>1?void 0:n?Vc(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Lt=(o,t)=>(e,n)=>t(e,n,o);function ts(o,t){const e=_r(o.left,o.top,t),n=_r(o.right,o.bottom,t);return{left:e.x,top:e.y,right:n.x,bottom:n.y}}function _r(o,t,e){const{scaleX:n,scaleY:r}=e.getAncestorScale(),s=e.getViewport(ie.VIEW_MAIN);if(!s)return{x:o,y:t};const{viewportScrollX:a,viewportScrollY:c}=s,l=(o-a)*n,A=(t-c)*r;return{x:l,y:A}}function Nr(o,t,e){const{scaleX:n,scaleY:r}=e.getAncestorScale(),s=e.getViewport(ie.VIEW_MAIN);if(!s)return{x:o,y:t};const{viewportScrollX:a,viewportScrollY:c}=s,l=o/n+a,A=t/r+c;return{x:l,y:A}}const Gt=(o,t)=>{const{scene:e,mainComponent:n,engine:r}=t,s=t.with(B.DocSkeletonManagerService).getSkeleton(),a=s.findNodePositionByCharIndex(o.startOffset,!0,o.segmentId,o.segmentPage),c=o.collapsed?o.startOffset:o.endOffset-1,l=s.findNodePositionByCharIndex(c,!0,o.segmentId,o.segmentPage),A=n;if(!l||!a)return;const d=A.getOffsetConfig(),{docsLeft:u,docsTop:m}=d,g=r.getCanvasElement(),h=g.getBoundingClientRect(),p=D.pxToNum(g.style.width),{top:f,left:S,width:v}=h,C=v/p,{scaleX:y,scaleY:b}=e.getAncestorScale(),E=new ve(d,s),{borderBoxPointGroup:R}=E.getRangePointData(a,l);return cn(R).map(_=>ts(_,e)).map(_=>({left:(_.left+u*y)*C+S,right:(_.right+u*y)*C+S,top:(_.top+m*b)*C+f,bottom:(_.bottom+m*b)*C+f}))};exports.DocCanvasPopManagerService=class extends i.Disposable{constructor(t,e,n,r){super(),this._globalPopupManagerService=t,this._renderManagerService=e,this._univerInstanceService=n,this._commandService=r}_createRectPositionObserver(t,e){const n=()=>{const{scene:l,engine:A}=e,d=typeof t=="function"?t():t,u=A.getCanvasElement(),m=u.getBoundingClientRect(),g=D.pxToNum(u.style.width),h=ts(d,l),{top:p,left:f,width:S}=m,v=S/g;return{left:h.left*v+f,right:h.right*v+f,top:h.top*v+p,bottom:h.bottom*v+p}},r=n(),s=new P.BehaviorSubject(r),a=new i.DisposableCollection;a.add(this._commandService.onCommandExecuted(l=>{if(l.id===Ae.id||l.id===B.RichTextEditingMutation.id){const A=n();A&&s.next(A)}}));const c=e.scene.getViewport(ie.VIEW_MAIN);return c&&a.add(c.onScrollAfter$.subscribeEvent(()=>{s.next(n())})),{position:r,position$:s,disposable:a}}_createObjectPositionObserver(t,e){const n=()=>{const{left:r,top:s,width:a,height:c}=t;return{left:r,right:r+a,top:s,bottom:s+c}};return this._createRectPositionObserver(n,e)}_createRangePositionObserver(t,e){var c;const n=(c=Gt(t,e))!=null?c:[],r=new P.BehaviorSubject(n),s=new i.DisposableCollection;s.add(this._commandService.onCommandExecuted(l=>{if((l.id===Ae.id||l.id===B.RichTextEditingMutation.id)&&l.params.unitId===e.unitId){const d=Gt(t,e);d&&r.next(d)}}));const a=e.scene.getViewport(ie.VIEW_MAIN);return a&&s.add(a.onScrollAfter$.subscribeEvent(()=>{const l=Gt(t,e);l&&r.next(l)})),{positions:n,positions$:r,disposable:s}}attachPopupToRect(t,e,n){const r=this._renderManagerService.getRenderById(n);if(!r)throw new Error(`Current render not found, unitId: ${n}`);const{position:s,position$:a,disposable:c}=this._createRectPositionObserver(t,r),l=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:s,anchorRect$:a,canvasElement:r.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(l),a.complete(),c.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==l}}attachPopupToObject(t,e,n){const r=this._renderManagerService.getRenderById(n);if(!r)throw new Error(`Current render not found, unitId: ${n}`);const{position:s,position$:a,disposable:c}=this._createObjectPositionObserver(t,r),l=this._globalPopupManagerService.addPopup({...e,unitId:n,subUnitId:"default",anchorRect:s,anchorRect$:a,canvasElement:r.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(l),a.complete(),c.dispose()},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:a}=e,c=this._renderManagerService.getRenderById(n);if(!c)throw new Error(`Current render not found, unitId: ${n}`);const{positions:l,positions$:A,disposable:d}=this._createRangePositionObserver(t,c),u=A.pipe(P.map(g=>s.includes("top")?g[0]:g[g.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(g=>s.includes(g))&&l.length>1&&a!=null?a:s,canvasElement:c.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(m),A.complete(),d.dispose()},canDispose:()=>this._globalPopupManagerService.activePopupId!==m}}};exports.DocCanvasPopManagerService=jc([Lt(0,i.Inject(I.ICanvasPopupService)),Lt(1,D.IRenderManagerService),Lt(2,i.IUniverInstanceService),Lt(3,i.ICommandService)],exports.DocCanvasPopManagerService);var Wc=Object.getOwnPropertyDescriptor,zc=(o,t,e,n)=>{for(var r=n>1?void 0:n?Wc(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Gc=(o,t)=>(e,n)=>t(e,n,o);const Xc=(o,t,e,n)=>{var m,g,h,p,f;const r=e.findNodePositionByCharIndex(o.startOffset,!0,o.segmentId,n),s=e.getSkeletonData();let a=o.endOffset-1;if(o.segmentId){const S=(f=Array.from((g=(m=s==null?void 0:s.skeFooters.get(o.segmentId))==null?void 0:m.values())!=null?g:[])[0])!=null?f:Array.from((p=(h=s==null?void 0:s.skeHeaders.get(o.segmentId))==null?void 0:h.values())!=null?p:[])[0];S&&(a=Math.min(S.ed,a))}const c=e.findNodePositionByCharIndex(a,!0,o.segmentId,n);if(!c||!r)return;const l=t.getOffsetConfig(),A=new ve(l,e),{borderBoxPointGroup:d}=A.getRangePointData(r,c);return cn(d).map(S=>({top:S.top+l.docsTop-Zn,bottom:S.bottom+l.docsTop+Zn,left:S.left+l.docsLeft,right:S.right+l.docsLeft}))},Pr=(o,t,e,n)=>{const r=[];for(const s of o){const a=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&&(r.push(d),d=null);const g={top:t+a+u.top,left:e+l,right:e+l+A,bottom:t+a+u.top+u.lineHeight};d={paragraphStart:u.st,paragraphEnd:m,startIndex:m,rect:g,fisrtLine:{top:t+a+u.top+u.marginTop+u.paddingTop,left:e+l,right:e+l+A,bottom:t+a+u.top+u.marginTop+u.paddingTop+u.contentHeight}}}else d&&d.startIndex===m&&(d.rect.bottom=t+a+u.top+u.lineHeight)}d&&r.push(d)}}return r},Kc=(o,t,e,n=-1)=>{const r=e.findPositionByGlyph(o,n);if(!r)return;const s=t.getOffsetConfig(),a={...r,isBack:!0},c=new ve(s,e),{borderBoxPointGroup:l}=c.getRangePointData(a,a),d=cn(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 Fe(o,t,e){const{left:n,right:r,top:s,bottom:a}=e;return o>=n&&o<=r&&t>=s&&t<=a}exports.DocEventManagerService=class extends i.Disposable{constructor(e,n){super();x(this,"_hoverCustomRanges$",new P.BehaviorSubject([]));x(this,"hoverCustomRanges$",this._hoverCustomRanges$.pipe(P.distinctUntilChanged((e,n)=>e.length===n.length&&e.every((r,s)=>n[s].range.rangeId===r.range.rangeId&&n[s].segmentId===r.segmentId&&n[s].segmentPageIndex===r.segmentPageIndex&&n[s].range.startIndex===r.range.startIndex))));x(this,"_clickCustomRanges$",new P.Subject);x(this,"clickCustomRanges$",this._clickCustomRanges$.asObservable());x(this,"_hoverBullet$",new P.Subject);x(this,"hoverBullet$",this._hoverBullet$.pipe(P.distinctUntilChanged((e,n)=>(e==null?void 0:e.paragraph.startIndex)===(n==null?void 0:n.paragraph.startIndex)&&(e==null?void 0:e.segmentId)===(n==null?void 0:n.segmentId)&&(e==null?void 0:e.segmentPageIndex)===(n==null?void 0:n.segmentPageIndex))));x(this,"_clickBullet$",new P.Subject);x(this,"clickBullets$",this._clickBullet$.asObservable());x(this,"_hoverParagraph$",new P.BehaviorSubject(null));x(this,"hoverParagraph$",this._hoverParagraph$.pipe(P.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))));x(this,"hoverParagraphRealTime$",this._hoverParagraph$.asObservable());x(this,"_hoverParagraphLeft$",new P.BehaviorSubject(null));x(this,"hoverParagraphLeft$",this._hoverParagraphLeft$.pipe(P.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))));x(this,"hoverParagraphLeftRealTime$",this._hoverParagraphLeft$.asObservable());x(this,"_hoverTableCell$",new P.Subject);x(this,"hoverTableCell$",this._hoverTableCell$.pipe(P.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))));x(this,"hoverTableCellRealTime$",this._hoverTableCell$.asObservable());x(this,"_hoverTable$",new P.Subject);x(this,"hoverTable$",this._hoverTable$.pipe(P.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))));x(this,"hoverTableRealTime$",this._hoverTable$.asObservable());x(this,"_customRangeDirty",!0);x(this,"_bulletDirty",!0);x(this,"_paragraphDirty",!0);x(this,"_customRangeBounds",[]);x(this,"_bulletBounds",[]);x(this,"_paragraphBounds",new Map);x(this,"_paragraphLeftBounds",[]);x(this,"_tableParagraphBounds",new Map);x(this,"_segmentParagraphBounds",new Map);x(this,"_tableCellBounds",new Map);x(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=D.CURSOR_TYPE.TEXT;this.disposeWithMe(this.hoverCustomRanges$.subscribe(n=>{n.length?(e=this._context.scene.getCursor(),this._context.scene.setCursor(D.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(i.fromEventSubject(this._context.engine.onTransformChange$).pipe(P.filter(e=>e.type===D.TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize)).subscribe(()=>{this._customRangeDirty=!0,this._bulletDirty=!0,this._paragraphDirty=!0}))}_initEvents(){this.disposeWithMe(i.fromEventSubject(this._context.scene.onPointerMove$).pipe(P.throttleTime(30)).subscribe(r=>{if(r.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:a}=Nr(r.offsetX,r.offsetY,this._context.scene);this._hoverCustomRanges$.next(this._calcActiveRanges({x:s,y:a})),this._hoverParagraph$.next(this._calcActiveParagraph({x:s,y:a})),this._hoverParagraphLeft$.next(this._calcActiveParagraphLeft({x:s,y:a})),this._hoverBullet$.next(this._calcActiveBullet({x:s,y:a}))})),this.disposeWithMe(this._context.scene.onPointerEnter$.subscribeEvent(()=>{this._hoverBullet$.next(null),this._hoverCustomRanges$.next([])}));const e=i.fromEventSubject(this._context.mainComponent.onPointerDown$),n=i.fromEventSubject(this._context.scene.onPointerUp$);this.disposeWithMe(e.pipe(P.switchMap(r=>n.pipe(P.take(1),P.map(s=>({down:r,up:s})))),P.filter(({down:r,up:s})=>r.target===s.target&&s.timeStamp-r.timeStamp<300)).subscribe(({down:r})=>{if(r.button===2)return;const s=Nr(r.offsetX,r.offsetY,this._context.scene),a=this._calcActiveRanges(s);a.length&&this._clickCustomRanges$.next(a.pop());const c=this._calcActiveBullet(s);c&&this._clickBullet$.next(c)}))}_buildCustomRangeBoundsBySegment(e,n=-1){var a,c,l;const r=(l=(c=(a=this._context.unit.getSelfOrHeaderFooterModel(e))==null?void 0:a.getBody())==null?void 0:c.customRanges)!=null?l:[],s=[];return r.forEach(A=>{const d={startOffset:A.startIndex,endOffset:A.endIndex+1,segmentId:e},u=Xc(d,this._documents,this._skeleton,n);if(!u)return null;s.push({customRange:A,rects:u,segmentId:e,segmentPageIndex:n})}),s}_buildCustomRangeBounds(){var n;if(!this._customRangeDirty)return;this._customRangeDirty=!1;const e=[];e.push(...this._buildCustomRangeBoundsBySegment()),(n=this._skeleton.getSkeletonData())==null||n.pages.forEach((r,s)=>{r.headerId&&e.push(...this._buildCustomRangeBoundsBySegment(r.headerId,s)),r.footerId&&e.push(...this._buildCustomRangeBoundsBySegment(r.footerId,s))}),this._customRangeBounds=e}_calcActiveRanges(e){this._buildCustomRangeBounds();const{x:n,y:r}=e;return this._customRangeBounds.filter(a=>a.rects.some(c=>Fe(n,r,c))).map(a=>({segmentId:a.segmentId,range:a.customRange,segmentPageIndex:a.segmentPageIndex,rects:a.rects}))}_buildBulletBoundsBySegment(e,n=-1){var A,d,u,m,g;const r=(A=this._context.unit.getSelfOrHeaderFooterModel(e))==null?void 0:A.getBody(),s=((d=r==null?void 0:r.paragraphs)!=null?d:[]).filter(h=>h.bullet&&h.bullet.listType.indexOf("CHECK_LIST")===0),a=[],c=this._skeleton.getSkeletonData();if(!c)return a;const l=h=>{var p,f,S;for(const v of h){const C=[...v.sections];if(v.skeTables){const y=Array.from(v.skeTables.values());C.push(...y.map(b=>b.rows.map(E=>E.cells.map(R=>R.sections))).flat(4))}for(const y of C)for(const b of y.columns)for(const E of b.lines)if(E.paragraphStart){const R=s.find(O=>O.startIndex===E.paragraphIndex);if(R){const O=E,T=(S=(f=(p=O==null?void 0:O.divides)==null?void 0:p[0])==null?void 0:f.glyphGroup)==null?void 0:S[0];if(!T)continue;const _=Kc(T,this._documents,this._skeleton,n);if(!_)continue;a.push({rect:_,segmentId:e,segmentPageIndex:n,paragraph:R})}}}return a};if(e){const h=(g=(u=c.skeFooters.get(e))==null?void 0:u.values())!=null?g:(m=c.skeHeaders.get(e))==null?void 0:m.values();return h?l(Array.from(h)):a}return l(c.pages)}_buildBulletBounds(){var e;this._bulletDirty&&(this._bulletDirty=!1,this._bulletBounds=[],this._bulletBounds.push(...this._buildBulletBoundsBySegment()),(e=this._skeleton.getSkeletonData())==null||e.pages.forEach((n,r)=>{n.headerId&&this._bulletBounds.push(...this._buildBulletBoundsBySegment(n.headerId,r)),n.footerId&&this._bulletBounds.push(...this._buildBulletBoundsBySegment(n.footerId,r))}))}_calcActiveBullet(e){this._buildBulletBounds();const{x:n,y:r}=e;return this._bulletBounds.find(a=>Fe(n,r,a.rect))}_buildParagraphBoundsBySegment(e){var c,l,A;const n=this._skeleton.getSkeletonData(),s=this._documents.getOffsetConfig();if(!n)return null;const a=d=>{const u=new Map,m=(g,h,p,f)=>{Pr(g.sections,p,f,g.pageWidth-g.marginLeft-g.marginRight).forEach(v=>{if(!u.has(v.startIndex))u.set(v.startIndex,{rect:v.rect,paragraphStart:v.paragraphStart,paragraphEnd:v.paragraphEnd,startIndex:v.startIndex,rects:[v.rect],pageIndex:h,segmentId:e,firstLine:v.fisrtLine});else{const C=u.get(v.startIndex);C&&(C.rect.bottom=v.rect.bottom,C.rects.push(v.rect))}})};for(let g=0;g<d.length;g++){const h=d[g],p=((h.pageHeight===1/0?0:h.pageHeight)+s.pageMarginTop)*g+h.marginTop+s.docsTop,f=h.marginLeft+s.docsLeft;h.skeTables&&Array.from(h.skeTables.values()).forEach(S=>{const v=S.left+f,C=S.top+p,y=v+S.width,b=C+S.height,E=S.tableId;this._tableBounds.set(E,{rect:{left:v,top:C,right:y,bottom:b},pageIndex:g,tableId:E}),S.rows.forEach((R,O)=>{R.cells.forEach((T,_)=>{const M=((h.pageHeight===1/0?0:h.pageHeight)+s.pageMarginTop)*g+S.top+s.docsTop+h.marginTop+R.top+T.marginTop,N=S.left+s.docsLeft+h.marginLeft+T.left+T.marginLeft,F=Pr(T.sections,M,N,T.pageWidth-T.marginLeft-T.marginRight);let k=this._tableParagraphBounds.get(E);k||(k=[],this._tableParagraphBounds.set(E,k)),k.push(...F.map(w=>({rect:w.rect,paragraphStart:w.paragraphStart,paragraphEnd:w.paragraphEnd,startIndex:w.startIndex,pageIndex:g,segmentId:e,rowIndex:O,colIndex:_,firstLine:w.fisrtLine,tableId:E})));let Q=this._tableCellBounds.get(E);Q||(Q=[],this._tableCellBounds.set(E,Q)),Q.push({rect:{top:M,left:N,right:N+T.pageWidth-T.marginLeft-T.marginRight,bottom:M+T.pageHeight-T.marginBottom-T.marginTop},pageIndex:g,rowIndex:O,colIndex:_,tableId:E})})})}),m(h,g,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?a(Array.from(d)):null}return a(n.pages)}_buildParagraphBounds(){var n,r;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 a;this._segmentParagraphBounds.set(s,(a=this._buildParagraphBoundsBySegment(s))!=null?a:new Map)};(r=this._skeleton.getSkeletonData())==null||r.pages.forEach(s=>{s.headerId&&e(s.headerId),s.footerId&&e(s.footerId)})}_calcActiveParagraph(e){var c,l;this._buildParagraphBounds();const{x:n,y:r}=e,s=Array.from(this._tableBounds.values()).find(A=>Fe(n,r,A.rect));if(this._hoverTable$.next(s),s){const A=(c=this._tableCellBounds.get(s.tableId))==null?void 0:c.find(m=>Fe(n,r,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=>Fe(n,r,m.rect));return u&&{...u,rects:[u.rect]}}return this._paragraphBounds.values().find(A=>A.rects.some(d=>Fe(n,r,d)))}_calcActiveParagraphLeft(e){this._buildParagraphBounds();const{x:n,y:r}=e;return this._paragraphLeftBounds.find(a=>Fe(n,r,a.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)}};exports.DocEventManagerService=zc([Gc(1,i.Inject(B.DocSkeletonManagerService))],exports.DocEventManagerService);const Yc=[me.id,_e.id,Ne.id,Pe.id,Ue.id,ye.id,we.id,Me.id,De.id];function qc(o){const{avaliableMenus:t=Yc}=o,e=I.useDependency(I.IMenuManagerService),[n,r]=U.useState([]);return U.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)}r(l)}s();const a=e.menuChanged$.subscribe(s);return()=>{a.unsubscribe()}},[e]),L.jsx("div",{className:`
43
43
  univer-box-border univer-flex univer-rounded univer-border univer-border-solid univer-border-gray-200
44
44
  univer-bg-white univer-py-1.5
45
45
  univer-shadow-[0_1px_6px_-2px_rgba(30,40,77,0.08),0_2px_6px_-1px_rgba(30,40,77,0.10)]
package/lib/es/index.js CHANGED
@@ -8559,6 +8559,11 @@ let Dt = class extends ge {
8559
8559
  get paragraphBounds() {
8560
8560
  return this._buildParagraphBounds(), this._paragraphBounds;
8561
8561
  }
8562
+ findParagraphBoundByIndex(e) {
8563
+ this._buildParagraphBounds();
8564
+ const t = this._paragraphBounds.get(e);
8565
+ return t || Array.from(this._tableParagraphBounds.values()).flat().find((r) => r.startIndex === e);
8566
+ }
8562
8567
  };
8563
8568
  Dt = Qu([
8564
8569
  Uu(1, j(ue))
package/lib/index.js CHANGED
@@ -8559,6 +8559,11 @@ let Dt = class extends ge {
8559
8559
  get paragraphBounds() {
8560
8560
  return this._buildParagraphBounds(), this._paragraphBounds;
8561
8561
  }
8562
+ findParagraphBoundByIndex(e) {
8563
+ this._buildParagraphBounds();
8564
+ const t = this._paragraphBounds.get(e);
8565
+ return t || Array.from(this._tableParagraphBounds.values()).flat().find((r) => r.startIndex === e);
8566
+ }
8562
8567
  };
8563
8568
  Dt = Qu([
8564
8569
  Uu(1, j(ue))
@@ -126,5 +126,6 @@ export declare class DocEventManagerService extends Disposable implements IRende
126
126
  private _calcActiveParagraph;
127
127
  private _calcActiveParagraphLeft;
128
128
  get paragraphBounds(): Map<number, IMutiPageParagraphBound>;
129
+ findParagraphBoundByIndex(index: number): IMutiPageParagraphBound | ITableParagraphBound | undefined;
129
130
  }
130
131
  export {};