@univerjs/docs-ui 0.7.0-beta.0 → 0.7.0-beta.1

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,16 +39,15 @@ ${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+=`${Ja(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 Za{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+=Ji(n);return e}}var $a=Object.getOwnPropertyDescriptor,ec=(o,t,e,n)=>{for(var r=n>1?void 0:n?$a(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},dt=(o,t)=>(e,n)=>t(e,n,o);tt.use(qi);tt.use(Xi);tt.use(Yi);function Ir(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 Jn=class extends i.Disposable{constructor(t,e,n,r,s){super();M(this,"_clipboardHooks",[]);M(this,"_htmlToUDM",new tt);M(this,"_umdToHtml",new Za);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=pn(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(We.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(bo.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=Ga(),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}}}}Pn.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:E}=u;let C;C=Ir(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=Xa(t);if(r){const a=Pn.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&&Pn.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:lo.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])}};Jn=ec([dt(0,i.IUniverInstanceService),dt(1,i.ILogService),dt(2,i.ICommandService),dt(3,I.IClipboardInterfaceService),dt(4,i.Inject(B.DocSelectionManagerService))],Jn);function fn(o){return o.getContextValue(i.FOCUSING_DOC)||o.getContextValue(i.EDITOR_ACTIVATED)}const Bo=999,Et={id:I.CopyCommand.id,name:"doc.command.copy",type:i.CommandType.COMMAND,multi:!0,priority:Bo,preconditions:fn,handler:async o=>o.get(Be).copy()},_o={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}},Sn={id:I.CutCommand.id,name:"doc.command.cut",type:i.CommandType.COMMAND,multi:!0,priority:Bo,preconditions:fn,handler:async o=>o.get(Be).cut()},No={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}},In={id:I.PasteCommand.id,name:"doc.command.paste",type:i.CommandType.COMMAND,multi:!0,priority:Bo,preconditions:fn,handler:async o=>{const t=o.get(Be),n=await o.get(I.IClipboardInterfaceService).read();return n.length===0?!1:t.paste(n)}};var tc=Object.getOwnPropertyDescriptor,nc=(o,t,e,n)=>{for(var r=n>1?void 0:n?tc(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},wn=(o,t)=>(e,n)=>t(e,n,o);const oc=11,rc=9,Lt={ff:"Arial",fs:oc};let Te=class extends i.Disposable{constructor(t,e,n){super();M(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{...Lt};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?{...Lt}:r.getEditArea()===D.DocumentEditArea.BODY?{...Lt}:{...Lt,fs:rc}}setStyleCache(t){this._cacheStyle={...this._cacheStyle,...t}}_clearStyleCache(){this._cacheStyle=null}};Te=nc([wn(0,i.Inject(B.DocSelectionManagerService)),wn(1,i.IUniverInstanceService),wn(2,D.IRenderManagerService)],Te);function Po(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 vn={id:"doc.command.break-line",type:i.CommandType.COMMAND,handler:(o,t)=>{var L,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=(L=t==null?void 0:t.textRange)!=null?L: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,E=f.startIndex,C=s.getDefaultStyle(),y=s.getStyleCache(),R=cn(u,h,C,y),v={dataStream:i.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Po(i.DataStreamTreeTokenType.PARAGRAPH,f,l),textRuns:[{st:0,ed:1,ts:{...R.ts}}]};if(d==null)return!1;const b=e.getActiveTextRange();if(u==null)return!1;const{collapsed:x}=a,T=v.dataStream.length,_=[{startOffset:g+T,endOffset:g+T,style:b==null?void 0:b.style,collapsed:x}],O={id:B.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:_,debounce:!0}},U=new i.TextX,F=i.JSONX.getInstance();if(x)g>0&&U.push({t:i.TextXActionType.RETAIN,len:g}),U.push({t:i.TextXActionType.INSERT,body:v,len:v.dataStream.length});else{const j=i.BuildTextUtils.selection.delete([a],u,0,v);U.push(...j)}(((W=f.bullet)==null?void 0:W.listType)===i.PresetListType.CHECK_LIST_CHECKED||(H=f.paragraphStyle)!=null&&H.headingId)&&(a.endOffset<E&&U.push({t:i.TextXActionType.RETAIN,len:E-a.endOffset}),U.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})),O.params.textRanges=[{startOffset:g+T,endOffset:g+T,collapsed:x}];const k=J(d,A);return O.params.actions=F.editOp(U.serialize(),k),!!r.syncExecuteCommand(O.id,O.params)}},xt={id:"doc.command.horizontal-line",type:i.CommandType.COMMAND,handler:(o,t)=>o.get(i.ICommandService).syncExecuteCommand(vn.id,{horizontalLine:{padding:5,color:{rgb:"#CDD0D8"},width:1,dashStyle:i.DashStyleType.SOLID},textRange:t==null?void 0:t.insertRange})},Uo={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 vr="doc.command.set-inline-format-bold",_e={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-italic",Ne={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-underline",Pe={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-strikethrough",Ue={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-subscript",ye={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-superscript",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-fontsize",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-font-family",ze={id:xr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(xr,t,e)}},Or="doc.command.set-inline-format-text-color",Me={id:Or,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Or,t,e)}},Mr="doc.command.set-inline-format-text-background-color",De={id:Mr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Mr,t,e)}},Dr="doc.command.reset-inline-format-text-background-color",at={id:Dr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Dr,t,e)}},Zn={[_e.id]:"bl",[Ne.id]:"it",[Pe.id]:"ul",[Ue.id]:"st",[me.id]:"fs",[ze.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 R;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=(R=l.find(v=>v.isActive))!=null?R: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 v=c.getDefaultStyle(),b=$i(m,A,v);h=sc(b,n);break}case me.id:case ze.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(),E=new i.MemoryCursor;E.reset();for(const v of l){let{startOffset:b,endOffset:x,rangeType:T}=v;if(b==null||x==null)continue;if(T===i.DOC_RANGE_TYPE.RECT&&(b=b-1),b===x){const U=c.getStyleCache(),F=Zn[n];c.setStyleCache({[F]:(U==null?void 0:U[F])!==void 0?Zi(U,F,n):h});continue}const _={dataStream:"",textRuns:[{st:0,ed:x-b,ts:{[Zn[n]]:h}}]},O=b-E.cursor;O!==0&&f.push({t:i.TextXActionType.RETAIN,len:O}),f.push({t:i.TextXActionType.RETAIN,body:_,len:x-b}),E.reset(),E.moveCursor(x)}const C=J(u,d);return p.params.actions=S.editOp(f.serialize(),C),!!r.syncExecuteCommand(p.id,p.params)}};function ic(o){return o!==null&&typeof o=="object"}function Zi(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 ic(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 $i(o,t,e){var d,u,m,g,h,p,f,S,E,C,y,R,v,b;const{startOffset:n,endOffset:r,collapsed:s}=t;if(s){const x=(d=o.textRuns)!=null?d:[];let T=null;for(let _=x.length-1;_>=0;_--){const O=x[_];if(O.st<n&&n<=O.ed){T=O;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(x=>{var T;return(T=x==null?void 0:x.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(x=>{var T;return((T=x.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(x=>{var T;return((T=x.ts)==null?void 0:T.it)===i.BooleanNumber.TRUE})?i.BooleanNumber.TRUE:i.BooleanNumber.FALSE,c.bl=a.length&&a.every(x=>{var T;return((T=x.ts)==null?void 0:T.bl)===i.BooleanNumber.TRUE})?i.BooleanNumber.TRUE:i.BooleanNumber.FALSE,c.ul=a.length&&a.every(x=>{var T,_;return((_=(T=x.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(x=>{var T,_;return((_=(T=x.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=(E=(S=(f=a.find(x=>{var T;return((T=x.ts)==null?void 0:T.bg)!=null}))==null?void 0:f.ts)==null?void 0:S.bg)!=null?E:c.bg,c.cl=(R=(y=(C=a.find(x=>{var T;return((T=x.ts)==null?void 0:T.cl)!=null}))==null?void 0:C.ts)==null?void 0:y.cl)!=null?R:c.cl;const A=a.filter(x=>{var T;return((T=x==null?void 0:x.ts)==null?void 0:T.va)!=null});if(A.length>0&&A.length===a.length){const x=(v=A[0].ts)==null?void 0:v.va;let T=!0;for(let _=1;_<A.length;_++)if(((b=A[_].ts)==null?void 0:b.va)!==x){T=!1;break}T&&(c.va=x)}return c}function sc(o,t){const e=Zn[t];return Zi(o,e,t)}const ct={id:"doc.command.list-operation",type:i.CommandType.COMMAND,handler:(o,t)=>{var y,R,v,b,x,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=(R=(y=t.docRange)!=null?y:e.getDocRanges())!=null?R:[];if(a==null||c.length===0)return!1;const l=c[0].segmentId,A=a.getSelfOrHeaderFooterModel(l),d=(b=(v=A.getBody())==null?void 0:v.paragraphs)!=null?b:[],u=(T=(x=A.getBody())==null?void 0:x.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(),E=J(a,l);return h.params.actions=S.editOp(f.serialize(),E),!!r.syncExecuteCommand(h.id,h.params)}},Ot={id:"doc.command.change-list-type",type:i.CommandType.COMMAND,handler:(o,t)=>{var C,y,R,v,b;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=(R=(y=A.getBody())==null?void 0:y.paragraphs)!=null?R:[],u=(b=(v=A.getBody())==null?void 0:v.dataStream)!=null?b:"";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 qt={id:"doc.command.change-list-nesting-level",type:i.CommandType.COMMAND,handler:(o,t)=>{var y,R,v,b,x;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=(v=(R=d.getBody())==null?void 0:R.paragraphs)!=null?v:[],m=(x=(b=d.getBody())==null?void 0:b.dataStream)!=null?x:"";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}},E=J(a,l);return S.params.actions=p.editOp(f.serialize(),E),!!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})}},wo={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})}},Lo={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:E={}}=d,{indentFirstLine:C,snapToGrid:y,indentStart:R}=E,v=i.PRESET_LIST_TYPE[A].nestingLevel[0].paragraphProperties||{},{hanging:b,indentStart:x}=v,T=v.textStyle,{charSpace:_,gridType:O}=ac(S,f)||{charSpace:0,gridType:i.GridType.LINES},U=D.getCharSpaceApply(_,p,O,y);let k=i.Tools.generateRandomId(6);const Q=(X=(Y=s.getBody())==null?void 0:Y.paragraphs)!=null?X:[],L=Q.findIndex(ne=>ne.startIndex===d.startIndex),z=Q[L-1],W=Q[L+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:{...E,textStyle:{...E.textStyle,...T},indentFirstLine:void 0,hanging:b,indentStart:{v:D.getNumberUnitValue(x,U)-D.getNumberUnitValue(b,U)+D.getNumberUnitValue(C,U)+D.getNumberUnitValue(R,U)}},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 Qo(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 Fo={id:"doc.command.insert-bullet-list-bellow",type:i.CommandType.COMMAND,handler:o=>Qo(o,i.PresetListType.BULLET_LIST)},Ho={id:"doc.command.insert-order-list-bellow",type:i.CommandType.COMMAND,handler:o=>Qo(o,i.PresetListType.ORDER_LIST)},ko={id:"doc.command.insert-check-list-bellow",type:i.CommandType.COMMAND,handler:o=>Qo(o,i.PresetListType.CHECK_LIST)};function ac(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)}},es={id:"doc.command.quick-heading",type:i.CommandType.COMMAND,handler(o,t){var R,v,b,x;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=(v=(R=d.getBody())==null?void 0:R.paragraphs)!=null?v:[],m=(x=(b=d.getBody())==null?void 0:b.dataStream)!=null?x:"",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,E={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 E.params.actions=f.editOp(p.serialize(),C),!!s.syncExecuteCommand(E.id,E.params)}},Ln={"#":i.NamedStyleType.HEADING_1,"##":i.NamedStyleType.HEADING_2,"###":i.NamedStyleType.HEADING_3,"####":i.NamedStyleType.HEADING_4,"#####":i.NamedStyleType.HEADING_5},Vo={id:"doc.command.h1-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_1})},jo={id:"doc.command.h2-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_2})},Wo={id:"doc.command.h3-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_3})},zo={id:"doc.command.h4-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_4})},Go={id:"doc.command.h5-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_5})},Jt={id:"doc.command.normal-text-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.NORMAL_TEXT})},ts={id:"doc.command.title",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.TITLE})},ns={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 R,v,b,x;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=(v=(R=A.getBody())==null?void 0:R.paragraphs)!=null?v:[],u=(x=(b=A.getBody())==null?void 0:b.dataStream)!=null?x:"";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,E=i.JSONX.getInstance();for(const T of m){const{startIndex:_}=T;S.push({t:i.TextXActionType.RETAIN,len:_-f.cursor});const O={...T.paragraphStyle,horizontalAlign:h?i.HorizontalAlign.UNSPECIFIED:s};S.push({t:i.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...T,paragraphStyle:O,startIndex:0}]},coverType:i.UpdateDocsAttributeType.REPLACE}),f.moveCursorTo(_+1)}const C=J(a,l);return p.params.actions=E.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})},Nt={id:"doc.command.switch-mode",type:i.CommandType.COMMAND,handler:o=>{var E,C,y,R,v;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=(E=e.getRenderById(a))==null?void 0:E.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 b=s.getSnapshot(),{drawings:x={},body:T}=b,_=(y=T==null?void 0:T.customBlocks)!=null?y:[];for(const O in x){const U=x[O],F=_.find(q=>q.blockId===O);if(F==null)continue;const k=U.docTransform.positionV,{relativeFrom:Q,posOffset:L}=k;if(Q===i.ObjectRelativeFromV.PARAGRAPH)continue;const{startIndex:z}=F,W=c.findNodeByCharIndex(z,A,d),H=(R=W==null?void 0:W.parent)==null?void 0:R.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=(v=V==null?void 0:V.parent)==null?void 0:v.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:(L!=null?L:0)-K},X=h.replaceOp(["drawings",O,"docTransform","positionV"],k,Y);X&&p.push(X)}}return g.params.actions=p.reduce((b,x)=>i.JSONX.compose(b,x),null),!!t.syncExecuteCommand(g.id,g.params)}},os="COMPONENT_DOC_CREATE_TABLE_CONFIRM",cc="doc.command.create-table",Xo={id:cc,type:i.CommandType.COMMAND,handler:async(o,t)=>{var Y,X,q,ne,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,E=((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,R=i.JSONX.getInstance(),v=[],b=f+4,x=[{startOffset:b,endOffset:b,collapsed:!0}],T={id:B.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:x}};f>0&&y.push({t:i.TextXActionType.RETAIN,len:f}),y.push({t:i.TextXActionType.INSERT,body:{dataStream:i.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Po(i.DataStreamTreeTokenType.PARAGRAPH,E)},len:1});const _=c.getDefaultStyle(),O=c.getStyleCache(),U=cn(m,f,_,O),{dataStream:F,paragraphs:k,sectionBreaks:Q}=Ba(e,n),L=(ge=(ne=(q=(X=C.parent)==null?void 0:X.parent)==null?void 0:q.parent)==null?void 0:ne.parent)==null?void 0:ge.parent;if(L==null)return!1;const{pageWidth:z,marginLeft:W,marginRight:H}=L,V=yo(e,n,z-W-H);y.push({t:i.TextXActionType.INSERT,body:{dataStream:F,paragraphs:k,sectionBreaks:Q,textRuns:[{...U,st:0,ed:F.length}],tables:[{startIndex:0,endIndex:F.length,tableId:V.tableId}]},len:F.length});const j=J(u,A);v.push(R.editOp(y.serialize(),j));const G=R.insertOp(["tableSource",V.tableId],V);return v.push(G),T.params.actions=v.reduce((xe,he)=>i.JSONX.compose(xe,he),null),!!a.syncExecuteCommand(T.id,T.params)}},Qn="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:Qn,children:{label:{name:os,props:{handleRowColChange:s,tableCreateParams:r}}},width:400,title:{title:t.t("toolbar.table.insert")},onConfirm:()=>{n.executeCommand(Xo.id,r),e.close(Qn)},onClose:()=>{e.close(Qn)}}),!0}},lc=o=>{const e=Object.keys(i.PAGE_SIZE).find(n=>{const{width:r,height:s}=i.PAGE_SIZE[n];return o.width===r&&o.height===s});return e!=null?e:"A4"};function dc(o){const{hooks:t}=o,r=I.useDependency(i.IUniverInstanceService).getCurrentUnitOfType(i.UniverInstanceType.UNIVER_DOC).getDocumentStyle(),s=I.useDependency(i.LocaleService),[a,c]=P.useState(()=>{var d,u,m,g,h;return{paperSize:lc(r.pageSize),orientation:(d=r.pageOrient)!=null?d:i.PageOrientType.PORTRAIT,margins:{top:(u=r.marginTop)!=null?u:0,bottom:(m=r.marginBottom)!=null?m:0,left:(g=r.marginLeft)!=null?g:0,right:(h=r.marginRight)!=null?h:0}}});P.useEffect(()=>{t.beforeClose=()=>a,t.beforeConfirm=()=>a},[a]);const l=d=>{c(u=>({...u,paperSize:d}))},A=(d,u)=>{c(m=>({...m,margins:{...m.margins,[d]:u||0}}))};return N.jsxs("div",{className:"univer-theme univer-flex univer-flex-col univer-gap-4",children:[N.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-2",children:[N.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-[#0E111E]",children:s.t("page-settings.paper-size")}),N.jsx($.Select,{value:a.paperSize,onChange:l,options:i.PAPER_TYPES.map(d=>({label:s.t(`page-settings.page-size.${d.toLocaleLowerCase()}`),value:d}))})]}),N.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-2",children:[N.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-[#0E111E]",children:s.t("page-settings.custom-paper-size")}),N.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-2.5",children:[N.jsxs("div",{className:"univer-flex univer-gap-2.5",children:[N.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[N.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:s.t("page-settings.top")}),N.jsx($.InputNumber,{value:a.margins.top,onChange:d=>A("top",d)})]}),N.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[N.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:s.t("page-settings.bottom")}),N.jsx($.InputNumber,{value:a.margins.bottom,onChange:d=>A("bottom",d)})]})]}),N.jsxs("div",{className:"univer-flex univer-gap-2.5",children:[N.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[N.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:s.t("page-settings.left")}),N.jsx($.InputNumber,{value:a.margins.left,onChange:d=>A("left",d)})]}),N.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[N.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:s.t("page-settings.right")}),N.jsx($.InputNumber,{value:a.margins.right,onChange:d=>A("right",d)})]})]})]})]})]})}const $n="docs.component.page-setting",rs={id:"docs.command.page-setup",type:i.CommandType.COMMAND,handler:(o,t)=>{if(!t)return!1;const e=o.get(i.IUniverInstanceService),n=o.get(i.ICommandService),r=e.getCurrentUnitOfType(i.UniverInstanceType.UNIVER_DOC);if(!r)return!1;const{marginLeft:s,marginRight:a,marginBottom:c,marginTop:l,pageOrient:A,pageSize:d}=t,u=i.JSONX.getInstance(),m=r.getDocumentStyle(),{marginBottom:g,marginLeft:h,marginRight:p,marginTop:f,pageOrient:S,pageSize:E}=m,C=[];if(g===void 0){const v=u.insertOp(["documentStyle","marginBottom"],c);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","marginBottom"],g,c);v&&C.push(v)}if(h===void 0){const v=u.insertOp(["documentStyle","marginLeft"],s);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","marginLeft"],h,s);v&&C.push(v)}if(p===void 0){const v=u.insertOp(["documentStyle","marginRight"],a);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","marginRight"],p,a);v&&C.push(v)}if(f===void 0){const v=u.insertOp(["documentStyle","marginTop"],l);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","marginTop"],f,l);v&&C.push(v)}if(E===void 0){const v=u.insertOp(["documentStyle","pageSize"],d);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","pageSize"],E,d);v&&C.push(v)}if(S===void 0){const v=u.insertOp(["documentStyle","pageOrient"],A);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","pageOrient"],S,A);v&&C.push(v)}const y={id:B.RichTextEditingMutation.id,params:{unitId:r.getUnitId(),actions:[],textRanges:void 0}};return y.params.actions=C.reduce((v,b)=>i.JSONX.compose(v,b),null),!!n.syncExecuteCommand(y.id,y.params)}},Ko={id:"docs.operation.open-page-setting",type:i.CommandType.OPERATION,handler:o=>{const t=o.get(I.IConfirmService),e=o.get(i.ICommandService),n=o.get(i.LocaleService),r=t.open({id:$n,title:{label:n.t("page-settings.document-setting")},children:{label:$n},width:528,onClose:()=>{r.dispose()},onConfirm:s=>{if(r.dispose(),!s)return;const a=i.PAGE_SIZE[s.paperSize];e.executeCommand(rs.id,{pageOrient:s.orientation,marginTop:s.margins.top,marginBottom:s.margins.bottom,marginLeft:s.margins.left,marginRight:s.margins.right,pageSize:a})}});return!0}};function Ac(o){const t=o.get(i.IUniverInstanceService),e=o.get(D.IRenderManagerService);return new w.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 uc(o){const t=o.get(i.IUniverInstanceService),e=o.get(i.ICommandService);return new w.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 gc(o){const t=o.get(B.DocSelectionManagerService),e=o.get(i.IUniverInstanceService);return new w.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 ee(o){const t=o.get(B.DocSelectionManagerService);return new w.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 hc(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 w.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$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function mc(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 w.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$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function pc(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 w.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$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function fc(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 w.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$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Sc(o){const t=o.get(i.ICommandService);return{id:ye.id,type:I.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",activated$:new w.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$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Ic(o){const t=o.get(i.ICommandService);return{id:we.id,type:I.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",activated$:new w.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$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function vc(o){const t=o.get(i.ICommandService);return{id:ze.id,tooltip:"toolbar.font",type:I.MenuItemType.SELECTOR,label:Pi,selections:I.FONT_FAMILY_LIST.map(e=>({label:{name:Ui},value:e.value})),value$:new w.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===ze.id)&&r()});return r(),s.dispose}),disabled$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Ec(o){const t=o.get(i.ICommandService);return{id:me.id,type:I.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:wi,props:{min:1,max:400}},selections:I.FONT_SIZE_LIST,value$:new w.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$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Cc(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 w.Observable(e=>{const n=i.NamedStyleType.NORMAL_TEXT,r=()=>{var l,A;const a=Xe(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$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Tc(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:Co,hoverable:!1,selectable:!1}}],value$:new w.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$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function yc(o){return{id:vo.id,type:I.MenuItemType.BUTTON,icon:"HeaderFooterSingle",tooltip:"toolbar.headerFooter",hidden$:w.combineLatest(I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY),uc(o),(t,e)=>t||e)}}const bc="GridSingle",is="doc.menu.table";function Rc(o){return{id:is,type:I.MenuItemType.SUBITEMS,icon:bc,tooltip:"toolbar.table.main",disabled$:gc(o),hidden$:w.combineLatest(I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY),Ac(o),(t,e)=>t||e)}}function xc(o){return{id:En.id,title:"toolbar.table.insert",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Oc(o){const t=o.get(i.ICommandService);return{id:Mt.id,type:I.MenuItemType.BUTTON,icon:"LeftJustifyingSingle",tooltip:"toolbar.alignLeft",disabled$:ee(o),activated$:new w.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===pe.id){const c=Xe(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 Mc(o){const t=o.get(i.ICommandService);return{id:Dt.id,type:I.MenuItemType.BUTTON,icon:"HorizontallySingle",tooltip:"toolbar.alignCenter",activated$:new w.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===pe.id){const c=Xe(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.CENTER)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Dc(o){const t=o.get(i.ICommandService);return{id:Bt.id,type:I.MenuItemType.BUTTON,icon:"RightJustifyingSingle",tooltip:"toolbar.alignRight",activated$:new w.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===pe.id){const c=Xe(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.RIGHT)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Bc(o){const t=o.get(i.ICommandService);return{id:_t.id,type:I.MenuItemType.BUTTON,icon:"AlignTextBothSingle",tooltip:"toolbar.alignJustify",activated$:new w.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===pe.id){const c=Xe(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.JUSTIFIED)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function _c(o){return{id:xt.id,type:I.MenuItemType.BUTTON,icon:"ReduceSingle",tooltip:"toolbar.horizontalLine",disabled$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}const Tt=o=>new w.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(E=>{var C;return S||(S=(C=E.bullet)==null?void 0:C.listType),E.bullet&&E.bullet.listType===S})){t.next(S);return}}t.next(void 0)}))});return()=>{s.unsubscribe(),r==null||r.unsubscribe()}});function Br(o){return{id:ot.id,type:I.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:Qi,hoverable:!1,selectable:!1},value$:Tt(o)}],icon:"OrderSingle",tooltip:"toolbar.order",hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),disabled$:ee(o),activated$:Tt(o).pipe(w.map(t=>t&&t.indexOf("ORDER_LIST")===0))}}function _r(o){return{id:nt.id,type:I.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:Fi,hoverable:!1,selectable:!1},value$:Tt(o)}],icon:"UnorderSingle",tooltip:"toolbar.unorder",disabled$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),activated$:Tt(o).pipe(w.map(t=>t&&t.indexOf("BULLET_LIST")===0))}}function Nr(o){return{id:Ct.id,type:I.MenuItemType.BUTTON,icon:"TodoList",tooltip:"toolbar.checklist",disabled$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),activated$:Tt(o).pipe(w.map(t=>t&&t.indexOf("CHECK_LIST")===0))}}function Nc(o){const t=o.get(i.ICommandService),e=o.get(i.IUniverInstanceService);return{id:Nt.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 w.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 Pc(o){return{id:at.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor"}}function Uc(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:Co,hoverable:!1,selectable:!1}}],value$:new w.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$:ee(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(E=>E.isActive))!=null?h:s[0],c=n.getDefaultStyle(),l=(p=n.getStyleCache())!=null?p:{},A=Xe(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=$i(m,a,{});return i.Tools.deleteNull(g),{ts:{...c,...d,...g,...l}}}function Xe(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}function wc(o){return{id:Ko.id,type:I.MenuItemType.BUTTON,icon:"DocumentSettingSingle",tooltip:"toolbar.pageSetup",hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}const Lc={[i.NamedStyleType.HEADING_1]:Vo,[i.NamedStyleType.HEADING_2]:jo,[i.NamedStyleType.HEADING_3]:Wo,[i.NamedStyleType.HEADING_4]:zo,[i.NamedStyleType.HEADING_5]:Go,[i.NamedStyleType.NORMAL_TEXT]:Jt,[i.NamedStyleType.TITLE]:ts,[i.NamedStyleType.SUBTITLE]:ns,[i.NamedStyleType.NAMED_STYLE_TYPE_UNSPECIFIED]:Jt},ss={[i.NamedStyleType.HEADING_1]:{key:"H1Single",component:Ci},[i.NamedStyleType.HEADING_2]:{key:"H2Single",component:Ti},[i.NamedStyleType.HEADING_3]:{key:"H3Single",component:yi},[i.NamedStyleType.HEADING_4]:{key:"H4Single",component:bi},[i.NamedStyleType.HEADING_5]:{key:"H5Single",component:Ri},[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=ss[o];return n.get(r.key)||n.register(r.key,r.component),{id:Lc[o].id,type:I.MenuItemType.BUTTON,icon:r.key,tooltip:"toolbar.heading.tooltip",disabled$:ee(t),hidden$:I.getMenuHiddenObservable(t,i.UniverInstanceType.UNIVER_DOC),activated$:new w.Observable(s=>{const a=i.NamedStyleType.NORMAL_TEXT,c=()=>{var u,m;const A=Xe(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})}},Qc=Qe(i.NamedStyleType.HEADING_1),Fc=Qe(i.NamedStyleType.HEADING_2),Hc=Qe(i.NamedStyleType.HEADING_3),kc=Qe(i.NamedStyleType.HEADING_4),Vc=Qe(i.NamedStyleType.HEADING_5),jc=Qe(i.NamedStyleType.NORMAL_TEXT);Qe(i.NamedStyleType.TITLE);Qe(i.NamedStyleType.SUBTITLE);const Wc=o=>({id:_o.id,type:I.MenuItemType.BUTTON,icon:"Copy",title:"rightClick.copy"}),zc=o=>({id:No.id,type:I.MenuItemType.BUTTON,icon:"CutSingle",title:"rightClick.cut"}),Gc=o=>({id:Mo.id,type:I.MenuItemType.BUTTON,icon:"DeleteSingle",title:"rightClick.delete"}),Xc=o=>({id:Fo.id,type:I.MenuItemType.BUTTON,icon:"UnorderSingle",title:"rightClick.bulletList"}),Kc=o=>({id:Ho.id,type:I.MenuItemType.BUTTON,icon:"OrderSingle",title:"rightClick.orderList"}),Yc=o=>({id:ko.id,type:I.MenuItemType.BUTTON,icon:"TodoList",title:"rightClick.checkList"}),qc=o=>({id:Uo.id,type:I.MenuItemType.BUTTON,icon:"ReduceSingle",title:"toolbar.horizontalLine"}),as="doc.menu.insert-bellow";function Jc(o){return{id:as,type:I.MenuItemType.SUBITEMS,title:"rightClick.insertBellow"}}const eo=4,Zc=(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 $c=Object.getOwnPropertyDescriptor,el=(o,t,e,n)=>{for(var r=n>1?void 0:n?$c(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Qt=(o,t)=>(e,n)=>t(e,n,o);function cs(o,t){const e=Pr(o.left,o.top,t),n=Pr(o.right,o.bottom,t);return{left:e.x,top:e.y,right:n.x,bottom:n.y}}function Pr(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 Ur(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 Xt=(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:E}=h,C=E/p,{scaleX:y,scaleY:R}=e.getAncestorScale(),v=new ve(d,s),{borderBoxPointGroup:b}=v.getRangePointData(a,l);return ln(b).map(_=>cs(_,e)).map(_=>({left:(_.left+u*y)*C+S,right:(_.right+u*y)*C+S,top:(_.top+m*R)*C+f,bottom:(_.bottom+m*R)*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=cs(d,l),{top:p,left:f,width:S}=m,E=S/g;return{left:h.left*E+f,right:h.right*E+f,top:h.top*E+p,bottom:h.bottom*E+p}},r=n(),s=new w.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=Xt(t,e))!=null?c:[],r=new w.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=Xt(t,e);d&&r.next(d)}}));const a=e.scene.getViewport(ie.VIEW_MAIN);return a&&s.add(a.onScrollAfter$.subscribeEvent(()=>{const l=Xt(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(w.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=el([Qt(0,i.Inject(I.ICanvasPopupService)),Qt(1,D.IRenderManagerService),Qt(2,i.IUniverInstanceService),Qt(3,i.ICommandService)],exports.DocCanvasPopManagerService);var tl=Object.getOwnPropertyDescriptor,nl=(o,t,e,n)=>{for(var r=n>1?void 0:n?tl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},ol=(o,t)=>(e,n)=>t(e,n,o);const rl=(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 ln(d).map(S=>({top:S.top+l.docsTop-eo,bottom:S.bottom+l.docsTop+eo,left:S.left+l.docsLeft,right:S.right+l.docsLeft}))},wr=(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},il=(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=ln(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 He(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();M(this,"_hoverCustomRanges$",new w.BehaviorSubject([]));M(this,"hoverCustomRanges$",this._hoverCustomRanges$.pipe(w.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))));M(this,"_clickCustomRanges$",new w.Subject);M(this,"clickCustomRanges$",this._clickCustomRanges$.asObservable());M(this,"_hoverBullet$",new w.Subject);M(this,"hoverBullet$",this._hoverBullet$.pipe(w.distinctUntilChanged((e,n)=>(e==null?void 0:e.paragraph.startIndex)===(n==null?void 0:n.paragraph.startIndex)&&(e==null?void 0:e.segmentId)===(n==null?void 0:n.segmentId)&&(e==null?void 0:e.segmentPageIndex)===(n==null?void 0:n.segmentPageIndex))));M(this,"_clickBullet$",new w.Subject);M(this,"clickBullets$",this._clickBullet$.asObservable());M(this,"_hoverParagraph$",new w.BehaviorSubject(null));M(this,"hoverParagraph$",this._hoverParagraph$.pipe(w.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))));M(this,"hoverParagraphRealTime$",this._hoverParagraph$.asObservable());M(this,"_hoverParagraphLeft$",new w.BehaviorSubject(null));M(this,"hoverParagraphLeft$",this._hoverParagraphLeft$.pipe(w.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))));M(this,"hoverParagraphLeftRealTime$",this._hoverParagraphLeft$.asObservable());M(this,"_hoverTableCell$",new w.Subject);M(this,"hoverTableCell$",this._hoverTableCell$.pipe(w.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))));M(this,"hoverTableCellRealTime$",this._hoverTableCell$.asObservable());M(this,"_hoverTable$",new w.Subject);M(this,"hoverTable$",this._hoverTable$.pipe(w.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))));M(this,"hoverTableRealTime$",this._hoverTable$.asObservable());M(this,"_customRangeDirty",!0);M(this,"_bulletDirty",!0);M(this,"_paragraphDirty",!0);M(this,"_customRangeBounds",[]);M(this,"_bulletBounds",[]);M(this,"_paragraphBounds",new Map);M(this,"_paragraphLeftBounds",[]);M(this,"_tableParagraphBounds",new Map);M(this,"_segmentParagraphBounds",new Map);M(this,"_tableCellBounds",new Map);M(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(w.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(w.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}=Ur(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(w.switchMap(r=>n.pipe(w.take(1),w.map(s=>({down:r,up:s})))),w.filter(({down:r,up:s})=>r.target===s.target&&s.timeStamp-r.timeStamp<300)).subscribe(({down:r})=>{if(r.button===2)return;const s=Ur(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=rl(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=>He(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 E of h){const C=[...E.sections];if(E.skeTables){const y=Array.from(E.skeTables.values());C.push(...y.map(R=>R.rows.map(v=>v.cells.map(b=>b.sections))).flat(4))}for(const y of C)for(const R of y.columns)for(const v of R.lines)if(v.paragraphStart){const b=s.find(x=>x.startIndex===v.paragraphIndex);if(b){const x=v,T=(S=(f=(p=x==null?void 0:x.divides)==null?void 0:p[0])==null?void 0:f.glyphGroup)==null?void 0:S[0];if(!T)continue;const _=il(T,this._documents,this._skeleton,n);if(!_)continue;a.push({rect:_,segmentId:e,segmentPageIndex:n,paragraph:b})}}}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=>He(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)=>{wr(g.sections,p,f,g.pageWidth-g.marginLeft-g.marginRight).forEach(E=>{if(!u.has(E.startIndex))u.set(E.startIndex,{rect:E.rect,paragraphStart:E.paragraphStart,paragraphEnd:E.paragraphEnd,startIndex:E.startIndex,rects:[E.rect],pageIndex:h,segmentId:e,firstLine:E.fisrtLine});else{const C=u.get(E.startIndex);C&&(C.rect.bottom=E.rect.bottom,C.rects.push(E.rect))}})};for(let 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 E=S.left+f,C=S.top+p,y=E+S.width,R=C+S.height,v=S.tableId;this._tableBounds.set(v,{rect:{left:E,top:C,right:y,bottom:R},pageIndex:g,tableId:v}),S.rows.forEach((b,x)=>{b.cells.forEach((T,_)=>{const O=((h.pageHeight===1/0?0:h.pageHeight)+s.pageMarginTop)*g+S.top+s.docsTop+h.marginTop+b.top+T.marginTop,U=S.left+s.docsLeft+h.marginLeft+T.left+T.marginLeft,F=wr(T.sections,O,U,T.pageWidth-T.marginLeft-T.marginRight);let k=this._tableParagraphBounds.get(v);k||(k=[],this._tableParagraphBounds.set(v,k)),k.push(...F.map(L=>({rect:L.rect,paragraphStart:L.paragraphStart,paragraphEnd:L.paragraphEnd,startIndex:L.startIndex,pageIndex:g,segmentId:e,rowIndex:x,colIndex:_,firstLine:L.fisrtLine,tableId:v})));let Q=this._tableCellBounds.get(v);Q||(Q=[],this._tableCellBounds.set(v,Q)),Q.push({rect:{top:O,left:U,right:U+T.pageWidth-T.marginLeft-T.marginRight,bottom:O+T.pageHeight-T.marginBottom-T.marginTop},pageIndex:g,rowIndex:x,colIndex:_,tableId:v})})})}),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=>He(n,r,A.rect));if(this._hoverTable$.next(s),s){const A=(c=this._tableCellBounds.get(s.tableId))==null?void 0:c.find(m=>He(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=>He(n,r,m.rect));return u&&{...u,rects:[u.rect]}}return this._paragraphBounds.values().find(A=>A.rects.some(d=>He(n,r,d)))}_calcActiveParagraphLeft(e){this._buildParagraphBounds();const{x:n,y:r}=e;return this._paragraphLeftBounds.find(a=>He(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=nl([ol(1,i.Inject(B.DocSkeletonManagerService))],exports.DocEventManagerService);const sl=[me.id,_e.id,Ne.id,Pe.id,Ue.id,ye.id,we.id,Me.id,De.id];function al(o){const{avaliableMenus:t=sl}=o,e=I.useDependency(I.IMenuManagerService),[n,r]=P.useState([]);return P.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]),N.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}}}}Pn.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:E}=u;let C;C=Ir(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=Xa(t);if(r){const a=Pn.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&&Pn.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:lo.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])}};Jn=ec([dt(0,i.IUniverInstanceService),dt(1,i.ILogService),dt(2,i.ICommandService),dt(3,I.IClipboardInterfaceService),dt(4,i.Inject(B.DocSelectionManagerService))],Jn);function fn(o){return o.getContextValue(i.FOCUSING_DOC)||o.getContextValue(i.EDITOR_ACTIVATED)}const Bo=999,Et={id:I.CopyCommand.id,name:"doc.command.copy",type:i.CommandType.COMMAND,multi:!0,priority:Bo,preconditions:fn,handler:async o=>o.get(Be).copy()},_o={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}},Sn={id:I.CutCommand.id,name:"doc.command.cut",type:i.CommandType.COMMAND,multi:!0,priority:Bo,preconditions:fn,handler:async o=>o.get(Be).cut()},No={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}},In={id:I.PasteCommand.id,name:"doc.command.paste",type:i.CommandType.COMMAND,multi:!0,priority:Bo,preconditions:fn,handler:async o=>{const t=o.get(Be),n=await o.get(I.IClipboardInterfaceService).read();return n.length===0?!1:t.paste(n)}};var tc=Object.getOwnPropertyDescriptor,nc=(o,t,e,n)=>{for(var r=n>1?void 0:n?tc(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},wn=(o,t)=>(e,n)=>t(e,n,o);const oc=11,rc=9,Lt={ff:"Arial",fs:oc};let Te=class extends i.Disposable{constructor(t,e,n){super();M(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{...Lt};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?{...Lt}:r.getEditArea()===D.DocumentEditArea.BODY?{...Lt}:{...Lt,fs:rc}}setStyleCache(t){this._cacheStyle={...this._cacheStyle,...t}}_clearStyleCache(){this._cacheStyle=null}};Te=nc([wn(0,i.Inject(B.DocSelectionManagerService)),wn(1,i.IUniverInstanceService),wn(2,D.IRenderManagerService)],Te);function Po(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 vn={id:"doc.command.break-line",type:i.CommandType.COMMAND,handler:(o,t)=>{var L,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=(L=t==null?void 0:t.textRange)!=null?L: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,E=f.startIndex,C=s.getDefaultStyle(),y=s.getStyleCache(),R=cn(u,h,C,y),v={dataStream:i.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Po(i.DataStreamTreeTokenType.PARAGRAPH,f,l),textRuns:[{st:0,ed:1,ts:{...R.ts}}]};if(d==null)return!1;const b=e.getActiveTextRange();if(u==null)return!1;const{collapsed:x}=a,T=v.dataStream.length,_=[{startOffset:g+T,endOffset:g+T,style:b==null?void 0:b.style,collapsed:x}],O={id:B.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:_,debounce:!0}},U=new i.TextX,F=i.JSONX.getInstance();if(x)g>0&&U.push({t:i.TextXActionType.RETAIN,len:g}),U.push({t:i.TextXActionType.INSERT,body:v,len:v.dataStream.length});else{const j=i.BuildTextUtils.selection.delete([a],u,0,v);U.push(...j)}(((W=f.bullet)==null?void 0:W.listType)===i.PresetListType.CHECK_LIST_CHECKED||(H=f.paragraphStyle)!=null&&H.headingId)&&(a.endOffset<E&&U.push({t:i.TextXActionType.RETAIN,len:E-a.endOffset}),U.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})),O.params.textRanges=[{startOffset:g+T,endOffset:g+T,collapsed:x}];const k=J(d,A);return O.params.actions=F.editOp(U.serialize(),k),!!r.syncExecuteCommand(O.id,O.params)}},xt={id:"doc.command.horizontal-line",type:i.CommandType.COMMAND,handler:(o,t)=>o.get(i.ICommandService).syncExecuteCommand(vn.id,{horizontalLine:{padding:5,color:{rgb:"#CDD0D8"},width:1,dashStyle:i.DashStyleType.SOLID},textRange:t==null?void 0:t.insertRange})},Uo={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 vr="doc.command.set-inline-format-bold",_e={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-italic",Ne={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-underline",Pe={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-strikethrough",Ue={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-subscript",ye={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-superscript",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-fontsize",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-font-family",ze={id:xr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(xr,t,e)}},Or="doc.command.set-inline-format-text-color",Me={id:Or,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Or,t,e)}},Mr="doc.command.set-inline-format-text-background-color",De={id:Mr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Mr,t,e)}},Dr="doc.command.reset-inline-format-text-background-color",at={id:Dr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Dr,t,e)}},Zn={[_e.id]:"bl",[Ne.id]:"it",[Pe.id]:"ul",[Ue.id]:"st",[me.id]:"fs",[ze.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 R;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=(R=l.find(v=>v.isActive))!=null?R: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 v=c.getDefaultStyle(),b=$i(m,A,v);h=sc(b,n);break}case me.id:case ze.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(),E=new i.MemoryCursor;E.reset();for(const v of l){let{startOffset:b,endOffset:x,rangeType:T}=v;if(b==null||x==null)continue;if(T===i.DOC_RANGE_TYPE.RECT&&(b=b-1),b===x){const U=c.getStyleCache(),F=Zn[n];c.setStyleCache({[F]:(U==null?void 0:U[F])!==void 0?Zi(U,F,n):h});continue}const _={dataStream:"",textRuns:[{st:0,ed:x-b,ts:{[Zn[n]]:h}}]},O=b-E.cursor;O!==0&&f.push({t:i.TextXActionType.RETAIN,len:O}),f.push({t:i.TextXActionType.RETAIN,body:_,len:x-b}),E.reset(),E.moveCursor(x)}const C=J(u,d);return p.params.actions=S.editOp(f.serialize(),C),!!r.syncExecuteCommand(p.id,p.params)}};function ic(o){return o!==null&&typeof o=="object"}function Zi(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 ic(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 $i(o,t,e){var d,u,m,g,h,p,f,S,E,C,y,R,v,b;const{startOffset:n,endOffset:r,collapsed:s}=t;if(s){const x=(d=o.textRuns)!=null?d:[];let T=null;for(let _=x.length-1;_>=0;_--){const O=x[_];if(O.st<n&&n<=O.ed){T=O;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(x=>{var T;return(T=x==null?void 0:x.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(x=>{var T;return((T=x.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(x=>{var T;return((T=x.ts)==null?void 0:T.it)===i.BooleanNumber.TRUE})?i.BooleanNumber.TRUE:i.BooleanNumber.FALSE,c.bl=a.length&&a.every(x=>{var T;return((T=x.ts)==null?void 0:T.bl)===i.BooleanNumber.TRUE})?i.BooleanNumber.TRUE:i.BooleanNumber.FALSE,c.ul=a.length&&a.every(x=>{var T,_;return((_=(T=x.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(x=>{var T,_;return((_=(T=x.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=(E=(S=(f=a.find(x=>{var T;return((T=x.ts)==null?void 0:T.bg)!=null}))==null?void 0:f.ts)==null?void 0:S.bg)!=null?E:c.bg,c.cl=(R=(y=(C=a.find(x=>{var T;return((T=x.ts)==null?void 0:T.cl)!=null}))==null?void 0:C.ts)==null?void 0:y.cl)!=null?R:c.cl;const A=a.filter(x=>{var T;return((T=x==null?void 0:x.ts)==null?void 0:T.va)!=null});if(A.length>0&&A.length===a.length){const x=(v=A[0].ts)==null?void 0:v.va;let T=!0;for(let _=1;_<A.length;_++)if(((b=A[_].ts)==null?void 0:b.va)!==x){T=!1;break}T&&(c.va=x)}return c}function sc(o,t){const e=Zn[t];return Zi(o,e,t)}const ct={id:"doc.command.list-operation",type:i.CommandType.COMMAND,handler:(o,t)=>{var y,R,v,b,x,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=(R=(y=t.docRange)!=null?y:e.getDocRanges())!=null?R:[];if(a==null||c.length===0)return!1;const l=c[0].segmentId,A=a.getSelfOrHeaderFooterModel(l),d=(b=(v=A.getBody())==null?void 0:v.paragraphs)!=null?b:[],u=(T=(x=A.getBody())==null?void 0:x.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(),E=J(a,l);return h.params.actions=S.editOp(f.serialize(),E),!!r.syncExecuteCommand(h.id,h.params)}},Ot={id:"doc.command.change-list-type",type:i.CommandType.COMMAND,handler:(o,t)=>{var C,y,R,v,b;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=(R=(y=A.getBody())==null?void 0:y.paragraphs)!=null?R:[],u=(b=(v=A.getBody())==null?void 0:v.dataStream)!=null?b:"";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 qt={id:"doc.command.change-list-nesting-level",type:i.CommandType.COMMAND,handler:(o,t)=>{var y,R,v,b,x;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=(v=(R=d.getBody())==null?void 0:R.paragraphs)!=null?v:[],m=(x=(b=d.getBody())==null?void 0:b.dataStream)!=null?x:"";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}},E=J(a,l);return S.params.actions=p.editOp(f.serialize(),E),!!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})}},wo={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})}},Lo={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:E={}}=d,{indentFirstLine:C,snapToGrid:y,indentStart:R}=E,v=i.PRESET_LIST_TYPE[A].nestingLevel[0].paragraphProperties||{},{hanging:b,indentStart:x}=v,T=v.textStyle,{charSpace:_,gridType:O}=ac(S,f)||{charSpace:0,gridType:i.GridType.LINES},U=D.getCharSpaceApply(_,p,O,y);let k=i.Tools.generateRandomId(6);const Q=(X=(Y=s.getBody())==null?void 0:Y.paragraphs)!=null?X:[],L=Q.findIndex(ne=>ne.startIndex===d.startIndex),z=Q[L-1],W=Q[L+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:{...E,textStyle:{...E.textStyle,...T},indentFirstLine:void 0,hanging:b,indentStart:{v:D.getNumberUnitValue(x,U)-D.getNumberUnitValue(b,U)+D.getNumberUnitValue(C,U)+D.getNumberUnitValue(R,U)}},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 Qo(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 Fo={id:"doc.command.insert-bullet-list-bellow",type:i.CommandType.COMMAND,handler:o=>Qo(o,i.PresetListType.BULLET_LIST)},Ho={id:"doc.command.insert-order-list-bellow",type:i.CommandType.COMMAND,handler:o=>Qo(o,i.PresetListType.ORDER_LIST)},ko={id:"doc.command.insert-check-list-bellow",type:i.CommandType.COMMAND,handler:o=>Qo(o,i.PresetListType.CHECK_LIST)};function ac(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)}},es={id:"doc.command.quick-heading",type:i.CommandType.COMMAND,handler(o,t){var R,v,b,x;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=(v=(R=d.getBody())==null?void 0:R.paragraphs)!=null?v:[],m=(x=(b=d.getBody())==null?void 0:b.dataStream)!=null?x:"",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,E={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 E.params.actions=f.editOp(p.serialize(),C),!!s.syncExecuteCommand(E.id,E.params)}},Ln={"#":i.NamedStyleType.HEADING_1,"##":i.NamedStyleType.HEADING_2,"###":i.NamedStyleType.HEADING_3,"####":i.NamedStyleType.HEADING_4,"#####":i.NamedStyleType.HEADING_5},Vo={id:"doc.command.h1-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_1})},jo={id:"doc.command.h2-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_2})},Wo={id:"doc.command.h3-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_3})},zo={id:"doc.command.h4-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_4})},Go={id:"doc.command.h5-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_5})},Jt={id:"doc.command.normal-text-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.NORMAL_TEXT})},ts={id:"doc.command.title",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.TITLE})},ns={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 R,v,b,x;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=(v=(R=A.getBody())==null?void 0:R.paragraphs)!=null?v:[],u=(x=(b=A.getBody())==null?void 0:b.dataStream)!=null?x:"";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,E=i.JSONX.getInstance();for(const T of m){const{startIndex:_}=T;S.push({t:i.TextXActionType.RETAIN,len:_-f.cursor});const O={...T.paragraphStyle,horizontalAlign:h?i.HorizontalAlign.UNSPECIFIED:s};S.push({t:i.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...T,paragraphStyle:O,startIndex:0}]},coverType:i.UpdateDocsAttributeType.REPLACE}),f.moveCursorTo(_+1)}const C=J(a,l);return p.params.actions=E.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})},Nt={id:"doc.command.switch-mode",type:i.CommandType.COMMAND,handler:o=>{var E,C,y,R,v;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=(E=e.getRenderById(a))==null?void 0:E.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 b=s.getSnapshot(),{drawings:x={},body:T}=b,_=(y=T==null?void 0:T.customBlocks)!=null?y:[];for(const O in x){const U=x[O],F=_.find(q=>q.blockId===O);if(F==null)continue;const k=U.docTransform.positionV,{relativeFrom:Q,posOffset:L}=k;if(Q===i.ObjectRelativeFromV.PARAGRAPH)continue;const{startIndex:z}=F,W=c.findNodeByCharIndex(z,A,d),H=(R=W==null?void 0:W.parent)==null?void 0:R.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=(v=V==null?void 0:V.parent)==null?void 0:v.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:(L!=null?L:0)-K},X=h.replaceOp(["drawings",O,"docTransform","positionV"],k,Y);X&&p.push(X)}}return g.params.actions=p.reduce((b,x)=>i.JSONX.compose(b,x),null),!!t.syncExecuteCommand(g.id,g.params)}},os="COMPONENT_DOC_CREATE_TABLE_CONFIRM",cc="doc.command.create-table",Xo={id:cc,type:i.CommandType.COMMAND,handler:async(o,t)=>{var Y,X,q,ne,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,E=((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,R=i.JSONX.getInstance(),v=[],b=f+4,x=[{startOffset:b,endOffset:b,collapsed:!0}],T={id:B.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:x}};f>0&&y.push({t:i.TextXActionType.RETAIN,len:f}),y.push({t:i.TextXActionType.INSERT,body:{dataStream:i.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Po(i.DataStreamTreeTokenType.PARAGRAPH,E)},len:1});const _=c.getDefaultStyle(),O=c.getStyleCache(),U=cn(m,f,_,O),{dataStream:F,paragraphs:k,sectionBreaks:Q}=Ba(e,n),L=(ge=(ne=(q=(X=C.parent)==null?void 0:X.parent)==null?void 0:q.parent)==null?void 0:ne.parent)==null?void 0:ge.parent;if(L==null)return!1;const{pageWidth:z,marginLeft:W,marginRight:H}=L,V=yo(e,n,z-W-H);y.push({t:i.TextXActionType.INSERT,body:{dataStream:F,paragraphs:k,sectionBreaks:Q,textRuns:[{...U,st:0,ed:F.length}],tables:[{startIndex:0,endIndex:F.length,tableId:V.tableId}]},len:F.length});const j=J(u,A);v.push(R.editOp(y.serialize(),j));const G=R.insertOp(["tableSource",V.tableId],V);return v.push(G),T.params.actions=v.reduce((xe,he)=>i.JSONX.compose(xe,he),null),!!a.syncExecuteCommand(T.id,T.params)}},Qn="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:Qn,children:{label:{name:os,props:{handleRowColChange:s,tableCreateParams:r}}},width:400,title:{title:t.t("toolbar.table.insert")},onConfirm:()=>{n.executeCommand(Xo.id,r),e.close(Qn)},onClose:()=>{e.close(Qn)}}),!0}},lc=o=>{const e=Object.keys(i.PAGE_SIZE).find(n=>{const{width:r,height:s}=i.PAGE_SIZE[n];return o.width===r&&o.height===s});return e!=null?e:"A4"};function dc(o){const{hooks:t}=o,r=I.useDependency(i.IUniverInstanceService).getCurrentUnitOfType(i.UniverInstanceType.UNIVER_DOC).getDocumentStyle(),s=I.useDependency(i.LocaleService),[a,c]=P.useState(()=>{var d,u,m,g,h;return{paperSize:lc(r.pageSize),orientation:(d=r.pageOrient)!=null?d:i.PageOrientType.PORTRAIT,margins:{top:(u=r.marginTop)!=null?u:0,bottom:(m=r.marginBottom)!=null?m:0,left:(g=r.marginLeft)!=null?g:0,right:(h=r.marginRight)!=null?h:0}}});P.useEffect(()=>{t.beforeClose=()=>a,t.beforeConfirm=()=>a},[a]);const l=d=>{c(u=>({...u,paperSize:d}))},A=(d,u)=>{c(m=>({...m,margins:{...m.margins,[d]:u||0}}))};return N.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-4",children:[N.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-2",children:[N.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-900",children:s.t("page-settings.paper-size")}),N.jsx($.Select,{value:a.paperSize,onChange:l,options:i.PAPER_TYPES.map(d=>({label:s.t(`page-settings.page-size.${d.toLocaleLowerCase()}`),value:d}))})]}),N.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-2",children:[N.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-[#0E111E]",children:s.t("page-settings.custom-paper-size")}),N.jsxs("div",{className:"univer-flex univer-flex-col univer-gap-2.5",children:[N.jsxs("div",{className:"univer-flex univer-gap-2.5",children:[N.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[N.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:s.t("page-settings.top")}),N.jsx($.InputNumber,{value:a.margins.top,onChange:d=>A("top",d)})]}),N.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[N.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:s.t("page-settings.bottom")}),N.jsx($.InputNumber,{value:a.margins.bottom,onChange:d=>A("bottom",d)})]})]}),N.jsxs("div",{className:"univer-flex univer-gap-2.5",children:[N.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[N.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:s.t("page-settings.left")}),N.jsx($.InputNumber,{value:a.margins.left,onChange:d=>A("left",d)})]}),N.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-col univer-gap-2",children:[N.jsx("label",{className:"univer-text-sm univer-font-medium univer-text-gray-500",children:s.t("page-settings.right")}),N.jsx($.InputNumber,{value:a.margins.right,onChange:d=>A("right",d)})]})]})]})]})]})}const $n="docs.component.page-setting",rs={id:"docs.command.page-setup",type:i.CommandType.COMMAND,handler:(o,t)=>{if(!t)return!1;const e=o.get(i.IUniverInstanceService),n=o.get(i.ICommandService),r=e.getCurrentUnitOfType(i.UniverInstanceType.UNIVER_DOC);if(!r)return!1;const{marginLeft:s,marginRight:a,marginBottom:c,marginTop:l,pageOrient:A,pageSize:d}=t,u=i.JSONX.getInstance(),m=r.getDocumentStyle(),{marginBottom:g,marginLeft:h,marginRight:p,marginTop:f,pageOrient:S,pageSize:E}=m,C=[];if(g===void 0){const v=u.insertOp(["documentStyle","marginBottom"],c);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","marginBottom"],g,c);v&&C.push(v)}if(h===void 0){const v=u.insertOp(["documentStyle","marginLeft"],s);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","marginLeft"],h,s);v&&C.push(v)}if(p===void 0){const v=u.insertOp(["documentStyle","marginRight"],a);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","marginRight"],p,a);v&&C.push(v)}if(f===void 0){const v=u.insertOp(["documentStyle","marginTop"],l);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","marginTop"],f,l);v&&C.push(v)}if(E===void 0){const v=u.insertOp(["documentStyle","pageSize"],d);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","pageSize"],E,d);v&&C.push(v)}if(S===void 0){const v=u.insertOp(["documentStyle","pageOrient"],A);v&&C.push(v)}else{const v=u.replaceOp(["documentStyle","pageOrient"],S,A);v&&C.push(v)}const y={id:B.RichTextEditingMutation.id,params:{unitId:r.getUnitId(),actions:[],textRanges:void 0}};return y.params.actions=C.reduce((v,b)=>i.JSONX.compose(v,b),null),!!n.syncExecuteCommand(y.id,y.params)}},Ko={id:"docs.operation.open-page-setting",type:i.CommandType.OPERATION,handler:o=>{const t=o.get(I.IConfirmService),e=o.get(i.ICommandService),n=o.get(i.LocaleService),r=t.open({id:$n,title:{label:n.t("page-settings.document-setting")},children:{label:$n},width:528,onClose:()=>{r.dispose()},onConfirm:s=>{if(r.dispose(),!s)return;const a=i.PAGE_SIZE[s.paperSize];e.executeCommand(rs.id,{pageOrient:s.orientation,marginTop:s.margins.top,marginBottom:s.margins.bottom,marginLeft:s.margins.left,marginRight:s.margins.right,pageSize:a})}});return!0}};function Ac(o){const t=o.get(i.IUniverInstanceService),e=o.get(D.IRenderManagerService);return new w.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 uc(o){const t=o.get(i.IUniverInstanceService),e=o.get(i.ICommandService);return new w.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 gc(o){const t=o.get(B.DocSelectionManagerService),e=o.get(i.IUniverInstanceService);return new w.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 ee(o){const t=o.get(B.DocSelectionManagerService);return new w.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 hc(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 w.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$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function mc(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 w.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$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function pc(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 w.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$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function fc(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 w.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$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Sc(o){const t=o.get(i.ICommandService);return{id:ye.id,type:I.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",activated$:new w.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$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Ic(o){const t=o.get(i.ICommandService);return{id:we.id,type:I.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",activated$:new w.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$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function vc(o){const t=o.get(i.ICommandService);return{id:ze.id,tooltip:"toolbar.font",type:I.MenuItemType.SELECTOR,label:Pi,selections:I.FONT_FAMILY_LIST.map(e=>({label:{name:Ui},value:e.value})),value$:new w.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===ze.id)&&r()});return r(),s.dispose}),disabled$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Ec(o){const t=o.get(i.ICommandService);return{id:me.id,type:I.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:wi,props:{min:1,max:400}},selections:I.FONT_SIZE_LIST,value$:new w.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$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Cc(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 w.Observable(e=>{const n=i.NamedStyleType.NORMAL_TEXT,r=()=>{var l,A;const a=Xe(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$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Tc(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:Co,hoverable:!1,selectable:!1}}],value$:new w.Observable(n=>{const r=e.getColorFromTheme("gray.900"),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$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function yc(o){return{id:vo.id,type:I.MenuItemType.BUTTON,icon:"HeaderFooterSingle",tooltip:"toolbar.headerFooter",hidden$:w.combineLatest(I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY),uc(o),(t,e)=>t||e)}}const bc="GridSingle",is="doc.menu.table";function Rc(o){return{id:is,type:I.MenuItemType.SUBITEMS,icon:bc,tooltip:"toolbar.table.main",disabled$:gc(o),hidden$:w.combineLatest(I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY),Ac(o),(t,e)=>t||e)}}function xc(o){return{id:En.id,title:"toolbar.table.insert",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}function Oc(o){const t=o.get(i.ICommandService);return{id:Mt.id,type:I.MenuItemType.BUTTON,icon:"LeftJustifyingSingle",tooltip:"toolbar.alignLeft",disabled$:ee(o),activated$:new w.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===pe.id){const c=Xe(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 Mc(o){const t=o.get(i.ICommandService);return{id:Dt.id,type:I.MenuItemType.BUTTON,icon:"HorizontallySingle",tooltip:"toolbar.alignCenter",activated$:new w.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===pe.id){const c=Xe(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.CENTER)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Dc(o){const t=o.get(i.ICommandService);return{id:Bt.id,type:I.MenuItemType.BUTTON,icon:"RightJustifyingSingle",tooltip:"toolbar.alignRight",activated$:new w.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===pe.id){const c=Xe(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.RIGHT)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function Bc(o){const t=o.get(i.ICommandService);return{id:_t.id,type:I.MenuItemType.BUTTON,icon:"AlignTextBothSingle",tooltip:"toolbar.alignJustify",activated$:new w.Observable(e=>{const n=t.onCommandExecuted(r=>{var a;const s=r.id;if(s===B.SetTextSelectionsOperation.id||s===pe.id){const c=Xe(o);if(c==null)return;const l=(a=c.paragraphStyle)==null?void 0:a.horizontalAlign;e.next(l===i.HorizontalAlign.JUSTIFIED)}});return e.next(!1),n.dispose}),disabled$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}function _c(o){return{id:xt.id,type:I.MenuItemType.BUTTON,icon:"ReduceSingle",tooltip:"toolbar.horizontalLine",disabled$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC,void 0,i.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}}const Tt=o=>new w.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(E=>{var C;return S||(S=(C=E.bullet)==null?void 0:C.listType),E.bullet&&E.bullet.listType===S})){t.next(S);return}}t.next(void 0)}))});return()=>{s.unsubscribe(),r==null||r.unsubscribe()}});function Br(o){return{id:ot.id,type:I.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:Qi,hoverable:!1,selectable:!1},value$:Tt(o)}],icon:"OrderSingle",tooltip:"toolbar.order",hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),disabled$:ee(o),activated$:Tt(o).pipe(w.map(t=>t&&t.indexOf("ORDER_LIST")===0))}}function _r(o){return{id:nt.id,type:I.MenuItemType.BUTTON_SELECTOR,slot:!0,selections:[{label:{name:Fi,hoverable:!1,selectable:!1},value$:Tt(o)}],icon:"UnorderSingle",tooltip:"toolbar.unorder",disabled$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),activated$:Tt(o).pipe(w.map(t=>t&&t.indexOf("BULLET_LIST")===0))}}function Nr(o){return{id:Ct.id,type:I.MenuItemType.BUTTON,icon:"TodoList",tooltip:"toolbar.checklist",disabled$:ee(o),hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC),activated$:Tt(o).pipe(w.map(t=>t&&t.indexOf("CHECK_LIST")===0))}}function Nc(o){const t=o.get(i.ICommandService),e=o.get(i.IUniverInstanceService);return{id:Nt.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 w.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 Pc(o){return{id:at.id,type:I.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor"}}function Uc(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:Co,hoverable:!1,selectable:!1}}],value$:new w.Observable(n=>{const r=e.getColorFromTheme("primary.600"),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$:ee(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(E=>E.isActive))!=null?h:s[0],c=n.getDefaultStyle(),l=(p=n.getStyleCache())!=null?p:{},A=Xe(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=$i(m,a,{});return i.Tools.deleteNull(g),{ts:{...c,...d,...g,...l}}}function Xe(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}function wc(o){return{id:Ko.id,type:I.MenuItemType.BUTTON,icon:"DocumentSettingSingle",tooltip:"toolbar.pageSetup",hidden$:I.getMenuHiddenObservable(o,i.UniverInstanceType.UNIVER_DOC)}}const Lc={[i.NamedStyleType.HEADING_1]:Vo,[i.NamedStyleType.HEADING_2]:jo,[i.NamedStyleType.HEADING_3]:Wo,[i.NamedStyleType.HEADING_4]:zo,[i.NamedStyleType.HEADING_5]:Go,[i.NamedStyleType.NORMAL_TEXT]:Jt,[i.NamedStyleType.TITLE]:ts,[i.NamedStyleType.SUBTITLE]:ns,[i.NamedStyleType.NAMED_STYLE_TYPE_UNSPECIFIED]:Jt},ss={[i.NamedStyleType.HEADING_1]:{key:"H1Single",component:Ci},[i.NamedStyleType.HEADING_2]:{key:"H2Single",component:Ti},[i.NamedStyleType.HEADING_3]:{key:"H3Single",component:yi},[i.NamedStyleType.HEADING_4]:{key:"H4Single",component:bi},[i.NamedStyleType.HEADING_5]:{key:"H5Single",component:Ri},[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=ss[o];return n.get(r.key)||n.register(r.key,r.component),{id:Lc[o].id,type:I.MenuItemType.BUTTON,icon:r.key,tooltip:"toolbar.heading.tooltip",disabled$:ee(t),hidden$:I.getMenuHiddenObservable(t,i.UniverInstanceType.UNIVER_DOC),activated$:new w.Observable(s=>{const a=i.NamedStyleType.NORMAL_TEXT,c=()=>{var u,m;const A=Xe(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})}},Qc=Qe(i.NamedStyleType.HEADING_1),Fc=Qe(i.NamedStyleType.HEADING_2),Hc=Qe(i.NamedStyleType.HEADING_3),kc=Qe(i.NamedStyleType.HEADING_4),Vc=Qe(i.NamedStyleType.HEADING_5),jc=Qe(i.NamedStyleType.NORMAL_TEXT);Qe(i.NamedStyleType.TITLE);Qe(i.NamedStyleType.SUBTITLE);const Wc=o=>({id:_o.id,type:I.MenuItemType.BUTTON,icon:"Copy",title:"rightClick.copy"}),zc=o=>({id:No.id,type:I.MenuItemType.BUTTON,icon:"CutSingle",title:"rightClick.cut"}),Gc=o=>({id:Mo.id,type:I.MenuItemType.BUTTON,icon:"DeleteSingle",title:"rightClick.delete"}),Xc=o=>({id:Fo.id,type:I.MenuItemType.BUTTON,icon:"UnorderSingle",title:"rightClick.bulletList"}),Kc=o=>({id:Ho.id,type:I.MenuItemType.BUTTON,icon:"OrderSingle",title:"rightClick.orderList"}),Yc=o=>({id:ko.id,type:I.MenuItemType.BUTTON,icon:"TodoList",title:"rightClick.checkList"}),qc=o=>({id:Uo.id,type:I.MenuItemType.BUTTON,icon:"ReduceSingle",title:"toolbar.horizontalLine"}),as="doc.menu.insert-bellow";function Jc(o){return{id:as,type:I.MenuItemType.SUBITEMS,title:"rightClick.insertBellow"}}const eo=4,Zc=(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 $c=Object.getOwnPropertyDescriptor,el=(o,t,e,n)=>{for(var r=n>1?void 0:n?$c(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Qt=(o,t)=>(e,n)=>t(e,n,o);function cs(o,t){const e=Pr(o.left,o.top,t),n=Pr(o.right,o.bottom,t);return{left:e.x,top:e.y,right:n.x,bottom:n.y}}function Pr(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 Ur(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 Xt=(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:E}=h,C=E/p,{scaleX:y,scaleY:R}=e.getAncestorScale(),v=new ve(d,s),{borderBoxPointGroup:b}=v.getRangePointData(a,l);return ln(b).map(_=>cs(_,e)).map(_=>({left:(_.left+u*y)*C+S,right:(_.right+u*y)*C+S,top:(_.top+m*R)*C+f,bottom:(_.bottom+m*R)*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=cs(d,l),{top:p,left:f,width:S}=m,E=S/g;return{left:h.left*E+f,right:h.right*E+f,top:h.top*E+p,bottom:h.bottom*E+p}},r=n(),s=new w.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=Xt(t,e))!=null?c:[],r=new w.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=Xt(t,e);d&&r.next(d)}}));const a=e.scene.getViewport(ie.VIEW_MAIN);return a&&s.add(a.onScrollAfter$.subscribeEvent(()=>{const l=Xt(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(w.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=el([Qt(0,i.Inject(I.ICanvasPopupService)),Qt(1,D.IRenderManagerService),Qt(2,i.IUniverInstanceService),Qt(3,i.ICommandService)],exports.DocCanvasPopManagerService);var tl=Object.getOwnPropertyDescriptor,nl=(o,t,e,n)=>{for(var r=n>1?void 0:n?tl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},ol=(o,t)=>(e,n)=>t(e,n,o);const rl=(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 ln(d).map(S=>({top:S.top+l.docsTop-eo,bottom:S.bottom+l.docsTop+eo,left:S.left+l.docsLeft,right:S.right+l.docsLeft}))},wr=(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},il=(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=ln(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 He(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();M(this,"_hoverCustomRanges$",new w.BehaviorSubject([]));M(this,"hoverCustomRanges$",this._hoverCustomRanges$.pipe(w.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))));M(this,"_clickCustomRanges$",new w.Subject);M(this,"clickCustomRanges$",this._clickCustomRanges$.asObservable());M(this,"_hoverBullet$",new w.Subject);M(this,"hoverBullet$",this._hoverBullet$.pipe(w.distinctUntilChanged((e,n)=>(e==null?void 0:e.paragraph.startIndex)===(n==null?void 0:n.paragraph.startIndex)&&(e==null?void 0:e.segmentId)===(n==null?void 0:n.segmentId)&&(e==null?void 0:e.segmentPageIndex)===(n==null?void 0:n.segmentPageIndex))));M(this,"_clickBullet$",new w.Subject);M(this,"clickBullets$",this._clickBullet$.asObservable());M(this,"_hoverParagraph$",new w.BehaviorSubject(null));M(this,"hoverParagraph$",this._hoverParagraph$.pipe(w.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))));M(this,"hoverParagraphRealTime$",this._hoverParagraph$.asObservable());M(this,"_hoverParagraphLeft$",new w.BehaviorSubject(null));M(this,"hoverParagraphLeft$",this._hoverParagraphLeft$.pipe(w.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))));M(this,"hoverParagraphLeftRealTime$",this._hoverParagraphLeft$.asObservable());M(this,"_hoverTableCell$",new w.Subject);M(this,"hoverTableCell$",this._hoverTableCell$.pipe(w.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))));M(this,"hoverTableCellRealTime$",this._hoverTableCell$.asObservable());M(this,"_hoverTable$",new w.Subject);M(this,"hoverTable$",this._hoverTable$.pipe(w.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))));M(this,"hoverTableRealTime$",this._hoverTable$.asObservable());M(this,"_customRangeDirty",!0);M(this,"_bulletDirty",!0);M(this,"_paragraphDirty",!0);M(this,"_customRangeBounds",[]);M(this,"_bulletBounds",[]);M(this,"_paragraphBounds",new Map);M(this,"_paragraphLeftBounds",[]);M(this,"_tableParagraphBounds",new Map);M(this,"_segmentParagraphBounds",new Map);M(this,"_tableCellBounds",new Map);M(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(w.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(w.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}=Ur(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(w.switchMap(r=>n.pipe(w.take(1),w.map(s=>({down:r,up:s})))),w.filter(({down:r,up:s})=>r.target===s.target&&s.timeStamp-r.timeStamp<300)).subscribe(({down:r})=>{if(r.button===2)return;const s=Ur(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=rl(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=>He(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 E of h){const C=[...E.sections];if(E.skeTables){const y=Array.from(E.skeTables.values());C.push(...y.map(R=>R.rows.map(v=>v.cells.map(b=>b.sections))).flat(4))}for(const y of C)for(const R of y.columns)for(const v of R.lines)if(v.paragraphStart){const b=s.find(x=>x.startIndex===v.paragraphIndex);if(b){const x=v,T=(S=(f=(p=x==null?void 0:x.divides)==null?void 0:p[0])==null?void 0:f.glyphGroup)==null?void 0:S[0];if(!T)continue;const _=il(T,this._documents,this._skeleton,n);if(!_)continue;a.push({rect:_,segmentId:e,segmentPageIndex:n,paragraph:b})}}}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=>He(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)=>{wr(g.sections,p,f,g.pageWidth-g.marginLeft-g.marginRight).forEach(E=>{if(!u.has(E.startIndex))u.set(E.startIndex,{rect:E.rect,paragraphStart:E.paragraphStart,paragraphEnd:E.paragraphEnd,startIndex:E.startIndex,rects:[E.rect],pageIndex:h,segmentId:e,firstLine:E.fisrtLine});else{const C=u.get(E.startIndex);C&&(C.rect.bottom=E.rect.bottom,C.rects.push(E.rect))}})};for(let 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 E=S.left+f,C=S.top+p,y=E+S.width,R=C+S.height,v=S.tableId;this._tableBounds.set(v,{rect:{left:E,top:C,right:y,bottom:R},pageIndex:g,tableId:v}),S.rows.forEach((b,x)=>{b.cells.forEach((T,_)=>{const O=((h.pageHeight===1/0?0:h.pageHeight)+s.pageMarginTop)*g+S.top+s.docsTop+h.marginTop+b.top+T.marginTop,U=S.left+s.docsLeft+h.marginLeft+T.left+T.marginLeft,F=wr(T.sections,O,U,T.pageWidth-T.marginLeft-T.marginRight);let k=this._tableParagraphBounds.get(v);k||(k=[],this._tableParagraphBounds.set(v,k)),k.push(...F.map(L=>({rect:L.rect,paragraphStart:L.paragraphStart,paragraphEnd:L.paragraphEnd,startIndex:L.startIndex,pageIndex:g,segmentId:e,rowIndex:x,colIndex:_,firstLine:L.fisrtLine,tableId:v})));let Q=this._tableCellBounds.get(v);Q||(Q=[],this._tableCellBounds.set(v,Q)),Q.push({rect:{top:O,left:U,right:U+T.pageWidth-T.marginLeft-T.marginRight,bottom:O+T.pageHeight-T.marginBottom-T.marginTop},pageIndex:g,rowIndex:x,colIndex:_,tableId:v})})})}),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=>He(n,r,A.rect));if(this._hoverTable$.next(s),s){const A=(c=this._tableCellBounds.get(s.tableId))==null?void 0:c.find(m=>He(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=>He(n,r,m.rect));return u&&{...u,rects:[u.rect]}}return this._paragraphBounds.values().find(A=>A.rects.some(d=>He(n,r,d)))}_calcActiveParagraphLeft(e){this._buildParagraphBounds();const{x:n,y:r}=e;return this._paragraphLeftBounds.find(a=>He(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=nl([ol(1,i.Inject(B.DocSkeletonManagerService))],exports.DocEventManagerService);const sl=[me.id,_e.id,Ne.id,Pe.id,Ue.id,ye.id,we.id,Me.id,De.id];function al(o){const{avaliableMenus:t=sl}=o,e=I.useDependency(I.IMenuManagerService),[n,r]=P.useState([]);return P.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]),N.jsx("div",{className:`
43
43
  univer-box-border univer-flex univer-rounded univer-border univer-border-solid univer-border-gray-200
44
- univer-bg-white univer-py-1.5
45
- univer-shadow-[0_1px_6px_-2px_rgba(30,40,77,0.08),0_2px_6px_-1px_rgba(30,40,77,0.10)]
44
+ univer-bg-white univer-py-1.5 univer-shadow-sm
46
45
  `,children:n.map(s=>s.item&&N.jsx("div",{className:"univer-flex univer-flex-nowrap univer-gap-2 univer-px-2",children:N.jsx(I.ToolbarItem,{...s.item},s.key)},s.key))})}var cl=Object.getOwnPropertyDescriptor,ll=(o,t,e,n)=>{for(var r=n>1?void 0:n?cl(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},At=(o,t)=>(e,n)=>t(e,n,o);const Lr="univer.doc.float-menu";function dl(o,t){if(o==null||t==null)return!1;const{glyph:e,...n}=o,{glyph:r,...s}=t;return i.deepCompare(n,s)}const Al=[i.DataStreamTreeTokenType.CUSTOM_BLOCK,i.DataStreamTreeTokenType.PARAGRAPH];let Zt=class extends i.Disposable{constructor(t,e,n,r,s,a){super();M(this,"_floatMenu",null);this._context=t,this._docSelectionManagerService=e,this._docCanvasPopManagerService=n,this._componentManager=r,this._univerInstanceService=s,this._docSelectionRenderService=a,!i.isInternalEditorID(this._context.unitId)&&(this._registerFloatMenu(),this._initSelectionChange(),this.disposeWithMe(()=>{this._hideFloatMenu()}))}get floatMenu(){return this._floatMenu}_registerFloatMenu(){this.disposeWithMe(this._componentManager.register(Lr,al))}_initSelectionChange(){this.disposeWithMe(this._docSelectionRenderService.onSelectionStart$.subscribe(()=>{this._hideFloatMenu()})),this.disposeWithMe(this._docSelectionManagerService.textSelection$.subscribe(t=>{var s,a;const{unitId:e,textRanges:n}=t;if(e!==this._context.unitId)return;const r=n.length>0&&n.find(c=>!c.collapsed);if(r){if(r.startOffset===((s=this._floatMenu)==null?void 0:s.start)&&r.endOffset===((a=this._floatMenu)==null?void 0:a.end))return;this._hideFloatMenu(),this._showFloatMenu(e,r);return}this._hideFloatMenu()}))}_hideFloatMenu(){var t;(t=this._floatMenu)==null||t.disposable.dispose(),this._floatMenu=null}_showFloatMenu(t,e){var a,c,l;const n=this._univerInstanceService.getUnit(t,i.UniverInstanceType.UNIVER_DOC);if(!n||n.getDisabled())return;const r=(a=n.getBody())==null?void 0:a.dataStream[e.startOffset];if(e.endOffset-e.startOffset===1&&r&&Al.includes(r))return;const s=(l=(c=n.getBody())==null?void 0:c.customRanges)==null?void 0:l.filter(A=>A.wholeEntity);if(!(s!=null&&s.some(A=>A.startIndex===e.startOffset&&A.endIndex===e.endOffset-1)))return this._floatMenu={disposable:this._docCanvasPopManagerService.attachPopupToRange(e,{componentKey:Lr,direction:e.direction==="backward"||dl(e.startNodePosition,e.endNodePosition)?"top-center":"bottom-center",offset:[0,4]},t),start:e.startOffset,end:e.endOffset},i.toDisposable(()=>this._hideFloatMenu())}};Zt=ll([At(1,i.Inject(B.DocSelectionManagerService)),At(2,i.Inject(exports.DocCanvasPopManagerService)),At(3,i.Inject(I.ComponentManager)),At(4,i.Inject(i.IUniverInstanceService)),At(5,i.Inject(exports.DocSelectionRenderService))],Zt);var ul=Object.getOwnPropertyDescriptor,gl=(o,t,e,n)=>{for(var r=n>1?void 0:n?ul(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},ut=(o,t)=>(e,n)=>t(e,n,o);let $t=class extends i.Disposable{constructor(t,e,n,r,s,a){super();M(this,"_paragrahMenu",null);this._context=t,this._docSelectionManagerService=e,this._docEventManagerService=n,this._docPopupManagerService=r,this._docSkeletonManagerService=s,this._floatMenuService=a,!i.isInternalEditorID(this._context.unitId)&&this._init()}get activeParagraph(){var t;return(t=this._paragrahMenu)==null?void 0:t.paragraph}_isCursorInActiveParagraph(){if(!this._paragrahMenu)return!1;const t=this._docSelectionManagerService.getActiveTextRange();return!(!(t!=null&&t.collapsed)||!(t!=null&&t.collapsed)||t.startOffset<this._paragrahMenu.paragraph.paragraphStart||t.startOffset>this._paragrahMenu.paragraph.paragraphEnd)}setParagraphMenuActive(t){this._paragrahMenu&&(this._paragrahMenu.active=t,this._isCursorInActiveParagraph()||this._docSelectionManagerService.replaceDocRanges([{startOffset:this._paragrahMenu.paragraph.paragraphStart,endOffset:this._paragrahMenu.paragraph.paragraphStart}]))}_init(){const t=n=>{var s;if(this._docSkeletonManagerService.getViewModel().getEditArea()===D.DocumentEditArea.BODY&&!this._floatMenuService.floatMenu&&!this._context.unit.getDisabled()){if((s=this._paragrahMenu)!=null&&s.active)return;if(n){this.showParagraphMenu(n);return}}this.hideParagraphMenu(!0)};this.disposeWithMe(w.combineLatest([this._docEventManagerService.hoverParagraphRealTime$,this._docEventManagerService.hoverParagraphLeft$]).pipe(w.throttleTime(16)).subscribe(([n,r])=>{const s=n!=null?n:r;t(s)}));let e=0;this.disposeWithMe(this._context.scene.getViewport(ie.VIEW_MAIN).onScrollAfter$.subscribeEvent(n=>{e!==n.scrollY&&(e=n.scrollY,this.hideParagraphMenu(!0))})),this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe(()=>{this.hideParagraphMenu(!0)}))}showParagraphMenu(t){var l,A,d;if(((l=this._paragrahMenu)==null?void 0:l.paragraph.startIndex)===t.startIndex)return;this.hideParagraphMenu(!0);const e=(d=(A=this._context.unit.getBody())==null?void 0:A.dataStream)!=null?d:"",n=t?e.slice(t.paragraphStart,t.paragraphEnd):"";if(n==="\b"||n==="")return;const c=this._docPopupManagerService.attachPopupToRect(t.firstLine,{componentKey:"doc.paragraph.menu",direction:"left-center",onClickOutside:()=>{this._docSelectionManagerService.textSelection$.pipe(w.first()).subscribe(()=>{this._isCursorInActiveParagraph()||this.hideParagraphMenu(!0)})},zIndex:101},this._context.unitId);this._paragrahMenu={paragraph:t,disposable:c,active:!1}}hideParagraphMenu(t=!1){this._paragrahMenu&&(this._paragrahMenu.disposable.canDispose()||t)&&(this._paragrahMenu.disposable.dispose(),this._paragrahMenu=null)}};$t=gl([ut(1,i.Inject(B.DocSelectionManagerService)),ut(2,i.Inject(exports.DocEventManagerService)),ut(3,i.Inject(exports.DocCanvasPopManagerService)),ut(4,i.Inject(B.DocSkeletonManagerService)),ut(5,i.Inject(Zt))],$t);const hl=({popup:o})=>{var v,b;const[t,e]=P.useState(!1),n=P.useRef(null),r=I.useDependency(i.ICommandService),s=I.useDependency(I.ILayoutService),a=P.useRef(null),c=P.useRef(!1),l=I.useDependency(D.IRenderManagerService),A=I.useDependency(i.IUniverInstanceService),d=l.getRenderById(o.unitId),u=A.getUnit(o.unitId,i.UniverInstanceType.UNIVER_DOC),m=d==null?void 0:d.with($t),g=d==null?void 0:d.with(exports.DocEventManagerService),h=I.useObservable(g==null?void 0:g.hoverParagraph$),p=I.useObservable(g==null?void 0:g.hoverParagraphLeft$),f=(v=h!=null?h:p)==null?void 0:v.startIndex,S=P.useMemo(()=>{var x,T;return(T=(x=u==null?void 0:u.getBody())==null?void 0:x.paragraphs)==null?void 0:T.find(_=>_.startIndex===f)},[u,h]),E=(b=S==null?void 0:S.paragraphStyle)==null?void 0:b.namedStyleType,C=ss[E!=null?E:i.NamedStyleType.NORMAL_TEXT],y=P.useMemo(()=>new w.BehaviorSubject({left:0,right:0,top:0,bottom:0}),[]),R=()=>{e(!1),m==null||m.hideParagraphMenu(!0)};return N.jsxs(N.Fragment,{children:[N.jsxs("div",{ref:a,className:`
47
46
  univer-mr-1 univer-inline-flex univer-h-7 univer-cursor-pointer univer-items-center univer-gap-1
48
47
  univer-rounded-full univer-border univer-border-solid univer-border-gray-200 univer-px-2.5 univer-py-0
49
48
  hover:univer-bg-gray-100
50
49
  ${t?"univer-bg-gray-100":"univer-bg-white"}
51
- `,onMouseEnter:x=>{var _,O,U,F,k,Q;(_=o.onPointerEnter)==null||_.call(o,x),c.current=!0;const T=(O=a.current)==null?void 0:O.getBoundingClientRect();y.next({left:((U=T==null?void 0:T.left)!=null?U:0)-4,right:(F=T==null?void 0:T.right)!=null?F:0,top:(k=T==null?void 0:T.top)!=null?k:0,bottom:(Q=T==null?void 0:T.bottom)!=null?Q:0})},onMouseLeave:()=>{c.current=!1},onClick:()=>{e(!0),m==null||m.setParagraphMenuActive(!0)},children:[N.jsx(C.component,{className:"univer-h-4 univer-w-4 univer-text-[#181C2A]"}),N.jsx(Ei,{className:"univer-h-3 univer-w-3 univer-text-[#979DAC]"})]}),t&&N.jsx(I.RectPopup,{portal:!0,mask:!0,maskZIndex:100,anchorRect$:y,direction:"left",onMaskClick:R,children:N.jsx("section",{ref:n,onMouseEnter:x=>{var T;(T=o.onPointerEnter)==null||T.call(o,x),c.current=!0},onMouseLeave:()=>{c.current=!1},children:N.jsx(I.DesktopMenu,{style:{width:212},menuType:I.ContextMenuPosition.PARAGRAPH,onOptionSelect:x=>{const{label:T,commandId:_,value:O}=x;r&&r.executeCommand(_!=null?_:T,{value:O}),s.focus(),R()}})})})]})},ml="doc.command.tab",Ge={id:ml,type:i.CommandType.COMMAND,async handler(o,t){const n=o.get(exports.DocAutoFormatService).onAutoFormat(Ge.id,t);return(await i.sequenceExecuteAsync(n,o.get(i.ICommandService))).result}},pl="doc.command.after-space",Pt={id:pl,type:i.CommandType.COMMAND,async handler(o){const e=o.get(exports.DocAutoFormatService).onAutoFormat(Pt.id);return(await i.sequenceExecuteAsync(e,o.get(i.ICommandService))).result}},rt={id:"doc.command.enter",type:i.CommandType.COMMAND,async handler(o){const e=o.get(exports.DocAutoFormatService).onAutoFormat(rt.id);return(await i.sequenceExecuteAsync(e,o.get(i.ICommandService))).result}};function Z(o){return o.getContextValue(i.FOCUSING_DOC)&&o.getContextValue(i.FOCUSING_UNIVER_EDITOR)&&!o.getContextValue(i.FOCUSING_COMMON_DRAWINGS)}function fl(o){return o.getContextValue(i.FOCUSING_DOC)&&o.getContextValue(i.FOCUSING_UNIVER_EDITOR)&&!o.getContextValue(i.FOCUSING_COMMON_DRAWINGS)}const Sl={id:Ge.id,binding:I.KeyCode.TAB,preconditions:Z},Il={id:Ge.id,binding:I.KeyCode.TAB|I.MetaKeys.SHIFT,preconditions:Z,staticParameters:{shift:!0}},vl={id:_e.id,binding:I.KeyCode.B|I.MetaKeys.CTRL_COMMAND,preconditions:Z},El={id:Ne.id,binding:I.KeyCode.I|I.MetaKeys.CTRL_COMMAND,preconditions:Z},Cl={id:Pe.id,binding:I.KeyCode.U|I.MetaKeys.CTRL_COMMAND,preconditions:Z},Tl={id:Ue.id,binding:I.KeyCode.X|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:Z},yl={id:ye.id,binding:I.KeyCode.COMMA|I.MetaKeys.CTRL_COMMAND,preconditions:Z},bl={id:we.id,binding:I.KeyCode.PERIOD|I.MetaKeys.CTRL_COMMAND,preconditions:Z},Rl={id:Mt.id,binding:I.KeyCode.L|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:Z},xl={id:Bt.id,binding:I.KeyCode.R|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:Z},Ol={id:Dt.id,binding:I.KeyCode.E|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:Z},Ml={id:_t.id,binding:I.KeyCode.J|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:Z},Dl={id:ot.id,binding:I.KeyCode.Digit7|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:Z},Bl={id:nt.id,binding:I.KeyCode.Digit8|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:Z},Cn="docs-ui.config",Qr={layout:{docContainerConfig:$r,toolbarConfig:Zr}},_l=[50,80,100,130,150,170,200,400],Nl=[10,400];function Pl(){const o=I.useDependency(i.ICommandService),t=I.useDependency(i.IUniverInstanceService),e=P.useMemo(()=>t.getCurrentTypeOfUnit$(i.UniverInstanceType.UNIVER_DOC),[]),n=I.useObservable(e),r=P.useCallback(()=>{var A,d;if(!n)return 100;const l=((d=(A=n.getSettings())==null?void 0:A.zoomRatio)!=null?d:1)*100;return Math.round(l)},[n]),[s,a]=P.useState(()=>r());P.useEffect(()=>(a(r()),o.onCommandExecuted(A=>{if(A.id===Ae.id){const d=r();a(d)}}).dispose),[o,r]);function c(l){if(a(l),n==null)return;const A=l/100;o.executeCommand(Ae.id,{unitId:n.getUnitId(),zoomRatio:A})}return N.jsx(I.Slider,{min:Nl[0],value:s,shortcuts:_l,onChange:c})}function Ul(o){return N.jsx("section",{className:"univer-flex univer-flex-shrink-0 univer-flex-grow-0 univer-basis-[260px] univer-justify-end",children:N.jsx(Pl,{})})}function wl(){var r,s,a;const o=I.useDependency(i.IUniverInstanceService),t=I.useConfigValue(Cn),e=I.useObservable(()=>o.getCurrentTypeOfUnit$(i.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),n=(a=(s=(r=t==null?void 0:t.layout)==null?void 0:r.docContainerConfig)==null?void 0:s.footer)!=null?a:!0;return e?null:n&&N.jsxs("div",{className:"univer-box-border univer-flex univer-items-center univer-justify-between univer-px-5",children:[N.jsx("div",{}),N.jsx(Ul,{})]})}const Ll="univer-overflow-hidden univer-font-[500] univer-truncate univer-h-[24px] univer-mb-2 univer-leading-[24px] univer-ellipsis univer-cursor-pointer",Ql="univer-text-base univer-font-semibold",Fl="univer-text-sm univer-font-semibold",Hl="univer-text-sm",kl=P.forwardRef((o,t)=>{const{menus:e,onClick:n,className:r,style:s,mode:a,maxHeight:c,activeId:l,open:A,onOpenChange:d,maxWidth:u,wrapperClass:m,wrapperStyle:g,iconClass:h,iconStyle:p}=o,f=a==="side-bar",S=P.useRef(null),E=P.useRef(e);E.current=e;const C=P.useMemo(()=>({scrollTo:y=>{var O;if(!E.current||E.current.findIndex(U=>U.id===y)===-1||!S.current)return;const v=document.getElementById(`univer-side-menu-${y}`);if(!v)return;const b=v.offsetTop,x=S.current.clientHeight,T=S.current.scrollHeight-x,_=Math.max(0,Math.min(b-x/2+v.clientHeight/2,T));(O=S.current)==null||O.scrollTo({behavior:"smooth",top:_})}}),[]);return P.useImperativeHandle(t,()=>C),P.useEffect(()=>{l&&C.scrollTo(l)},[l,C]),N.jsxs("div",{className:$.clsx("univer-relative",m),style:g,children:[N.jsx("div",{onClick:()=>d==null?void 0:d(!A),className:$.clsx(`
50
+ `,onMouseEnter:x=>{var _,O,U,F,k,Q;(_=o.onPointerEnter)==null||_.call(o,x),c.current=!0;const T=(O=a.current)==null?void 0:O.getBoundingClientRect();y.next({left:((U=T==null?void 0:T.left)!=null?U:0)-4,right:(F=T==null?void 0:T.right)!=null?F:0,top:(k=T==null?void 0:T.top)!=null?k:0,bottom:(Q=T==null?void 0:T.bottom)!=null?Q:0})},onMouseLeave:()=>{c.current=!1},onClick:()=>{e(!0),m==null||m.setParagraphMenuActive(!0)},children:[N.jsx(C.component,{className:"univer-h-4 univer-w-4 univer-text-[#181C2A]"}),N.jsx(Ei,{className:"univer-h-3 univer-w-3 univer-text-[#979DAC]"})]}),t&&N.jsx(I.RectPopup,{portal:!0,mask:!0,maskZIndex:100,anchorRect$:y,direction:"left",onMaskClick:R,children:N.jsx("section",{ref:n,onMouseEnter:x=>{var T;(T=o.onPointerEnter)==null||T.call(o,x),c.current=!0},onMouseLeave:()=>{c.current=!1},children:N.jsx(I.DesktopMenu,{style:{width:212},menuType:I.ContextMenuPosition.PARAGRAPH,onOptionSelect:x=>{const{label:T,commandId:_,value:O}=x;r&&r.executeCommand(_!=null?_:T,{value:O}),s.focus(),R()}})})})]})},ml="doc.command.tab",Ge={id:ml,type:i.CommandType.COMMAND,async handler(o,t){const n=o.get(exports.DocAutoFormatService).onAutoFormat(Ge.id,t);return(await i.sequenceExecuteAsync(n,o.get(i.ICommandService))).result}},pl="doc.command.after-space",Pt={id:pl,type:i.CommandType.COMMAND,async handler(o){const e=o.get(exports.DocAutoFormatService).onAutoFormat(Pt.id);return(await i.sequenceExecuteAsync(e,o.get(i.ICommandService))).result}},rt={id:"doc.command.enter",type:i.CommandType.COMMAND,async handler(o){const e=o.get(exports.DocAutoFormatService).onAutoFormat(rt.id);return(await i.sequenceExecuteAsync(e,o.get(i.ICommandService))).result}};function Z(o){return o.getContextValue(i.FOCUSING_DOC)&&o.getContextValue(i.FOCUSING_UNIVER_EDITOR)&&!o.getContextValue(i.FOCUSING_COMMON_DRAWINGS)}function fl(o){return o.getContextValue(i.FOCUSING_DOC)&&o.getContextValue(i.FOCUSING_UNIVER_EDITOR)&&!o.getContextValue(i.FOCUSING_COMMON_DRAWINGS)}const Sl={id:Ge.id,binding:I.KeyCode.TAB,preconditions:Z},Il={id:Ge.id,binding:I.KeyCode.TAB|I.MetaKeys.SHIFT,preconditions:Z,staticParameters:{shift:!0}},vl={id:_e.id,binding:I.KeyCode.B|I.MetaKeys.CTRL_COMMAND,preconditions:Z},El={id:Ne.id,binding:I.KeyCode.I|I.MetaKeys.CTRL_COMMAND,preconditions:Z},Cl={id:Pe.id,binding:I.KeyCode.U|I.MetaKeys.CTRL_COMMAND,preconditions:Z},Tl={id:Ue.id,binding:I.KeyCode.X|I.MetaKeys.SHIFT|I.MetaKeys.CTRL_COMMAND,preconditions:Z},yl={id:ye.id,binding:I.KeyCode.COMMA|I.MetaKeys.CTRL_COMMAND,preconditions:Z},bl={id:we.id,binding:I.KeyCode.PERIOD|I.MetaKeys.CTRL_COMMAND,preconditions:Z},Rl={id:Mt.id,binding:I.KeyCode.L|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:Z},xl={id:Bt.id,binding:I.KeyCode.R|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:Z},Ol={id:Dt.id,binding:I.KeyCode.E|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:Z},Ml={id:_t.id,binding:I.KeyCode.J|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:Z},Dl={id:ot.id,binding:I.KeyCode.Digit7|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:Z},Bl={id:nt.id,binding:I.KeyCode.Digit8|I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT,preconditions:Z},Cn="docs-ui.config",Qr={layout:{docContainerConfig:$r,toolbarConfig:Zr}},_l=[50,80,100,130,150,170,200,400],Nl=[10,400];function Pl(){const o=I.useDependency(i.ICommandService),t=I.useDependency(i.IUniverInstanceService),e=P.useMemo(()=>t.getCurrentTypeOfUnit$(i.UniverInstanceType.UNIVER_DOC),[]),n=I.useObservable(e),r=P.useCallback(()=>{var A,d;if(!n)return 100;const l=((d=(A=n.getSettings())==null?void 0:A.zoomRatio)!=null?d:1)*100;return Math.round(l)},[n]),[s,a]=P.useState(()=>r());P.useEffect(()=>(a(r()),o.onCommandExecuted(A=>{if(A.id===Ae.id){const d=r();a(d)}}).dispose),[o,r]);function c(l){if(a(l),n==null)return;const A=l/100;o.executeCommand(Ae.id,{unitId:n.getUnitId(),zoomRatio:A})}return N.jsx(I.Slider,{min:Nl[0],value:s,shortcuts:_l,onChange:c})}function Ul(o){return N.jsx("section",{className:"univer-flex univer-flex-shrink-0 univer-justify-end",children:N.jsx(Pl,{})})}function wl(){var r,s,a;const o=I.useDependency(i.IUniverInstanceService),t=I.useConfigValue(Cn),e=I.useObservable(()=>o.getCurrentTypeOfUnit$(i.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),n=(a=(s=(r=t==null?void 0:t.layout)==null?void 0:r.docContainerConfig)==null?void 0:s.footer)!=null?a:!0;return e?null:n&&N.jsxs("div",{className:"univer-box-border univer-flex univer-items-center univer-justify-between univer-px-5",children:[N.jsx("div",{}),N.jsx(Ul,{})]})}const Ll="univer-overflow-hidden univer-font-[500] univer-truncate univer-h-[24px] univer-mb-2 univer-leading-[24px] univer-ellipsis univer-cursor-pointer",Ql="univer-text-base univer-font-semibold",Fl="univer-text-sm univer-font-semibold",Hl="univer-text-sm",kl=P.forwardRef((o,t)=>{const{menus:e,onClick:n,className:r,style:s,mode:a,maxHeight:c,activeId:l,open:A,onOpenChange:d,maxWidth:u,wrapperClass:m,wrapperStyle:g,iconClass:h,iconStyle:p}=o,f=a==="side-bar",S=P.useRef(null),E=P.useRef(e);E.current=e;const C=P.useMemo(()=>({scrollTo:y=>{var O;if(!E.current||E.current.findIndex(U=>U.id===y)===-1||!S.current)return;const v=document.getElementById(`univer-side-menu-${y}`);if(!v)return;const b=v.offsetTop,x=S.current.clientHeight,T=S.current.scrollHeight-x,_=Math.max(0,Math.min(b-x/2+v.clientHeight/2,T));(O=S.current)==null||O.scrollTo({behavior:"smooth",top:_})}}),[]);return P.useImperativeHandle(t,()=>C),P.useEffect(()=>{l&&C.scrollTo(l)},[l,C]),N.jsxs("div",{className:$.clsx("univer-relative",m),style:g,children:[N.jsx("div",{onClick:()=>d==null?void 0:d(!A),className:$.clsx(`
52
51
  univer-absolute univer-left-5 univer-top-4 univer-z-[100] univer-flex univer-h-8 univer-w-8
53
52
  univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-full univer-bg-white
54
53
  univer-text-gray-800
@@ -57,10 +56,9 @@ ${i.DataStreamTreeTokenType.TABLE_CELL_END}`;break}}}_processBeforeLink(t,e){ret
57
56
  univer-absolute univer-left-0 univer-top-0 univer-box-border univer-flex univer-min-w-[180px]
58
57
  univer-flex-col univer-pb-4 univer-pl-5 univer-pr-5 univer-pt-14 univer-transition-all
59
58
  univer-duration-300
60
- `,f?"":["univer-bg-white","univer-rounded-r-2xl","univer-shadow-[0px_1px_6px_-2px_rgba(30,40,77,0.08),0px_2px_6px_-1px_rgba(30,40,77,0.10)]","univer-backdrop-blur-[10px]"]),style:{...s,transform:A?"translateX(0)":"translateX(-100%)",maxHeight:c,opacity:A?1:0,maxWidth:u!=null?u:a==="side-bar"?480:180,paddingRight:a==="float"?void 0:0},children:N.jsx("div",{ref:S,className:`
59
+ `,f?"":["univer-bg-white","univer-rounded-r-2xl","univer-shadow-[0px_1px_6px_-2px_rgba(30,40,77,0.08),0px_2px_6px_-1px_rgba(30,40,77,0.10)]","univer-backdrop-blur-[10px]"]),style:{...s,transform:A?"translateX(0)":"translateX(-100%)",maxHeight:c,opacity:A?1:0,maxWidth:u!=null?u:a==="side-bar"?480:180,paddingRight:a==="float"?void 0:0},children:N.jsx("div",{ref:S,className:$.clsx(`
61
60
  univer-flex-1 univer-overflow-y-auto univer-overflow-x-hidden univer-scrollbar-none
62
- [&::-webkit-scrollbar]:univer-hidden
63
- `,children:e==null?void 0:e.map(y=>N.jsx("div",{id:`univer-side-menu-${y.id}`,className:$.clsx(Ll,{[Ql]:y.isTitle,[Fl]:y.level===1,[Hl]:y.level>1,"univer-text-gray-500":y.id!==l,"univer-text-gray-800":y.id===l}),style:{paddingLeft:(y.level-1)*12},onClick:()=>{n==null||n(y)},children:y.text},y.id))})})]})}),Vl=o=>{switch(o){case i.NamedStyleType.HEADING_1:return 1;case i.NamedStyleType.HEADING_2:return 2;case i.NamedStyleType.HEADING_3:return 3;case i.NamedStyleType.HEADING_4:return 4;case i.NamedStyleType.HEADING_5:return 5;case i.NamedStyleType.TITLE:return 1;default:return 1}};function jl(o,t,e,n){var c,l;if(!o)return;const r=Array.from(o.values()),s=r.findIndex(A=>A.paragraphStart!==A.paragraphEnd&&A.rect.top<n&&A.rect.bottom>e);if(s===-1)return;const a=r==null?void 0:r.findLastIndex(A=>A.paragraphStart!==A.paragraphEnd&&A.rect.top<n&&A.rect.bottom>e);for(let A=s;A<=a;A++){const d=r[A],u=t.get(d.startIndex);if((c=u==null?void 0:u.paragraphStyle)!=null&&c.headingId)return u.paragraphStyle.headingId}for(let A=s;A>=0;A--){const d=r[A],u=t.get(d.startIndex);if((l=u==null?void 0:u.paragraphStyle)!=null&&l.headingId)return u.paragraphStyle.headingId}}const Fr="__title";function Wl(){var t,e,n;const o=I.useConfigValue(Cn);return(n=(e=(t=o==null?void 0:o.layout)==null?void 0:t.docContainerConfig)==null?void 0:e.sideMenu)==null||n?N.jsx(zl,{}):null}function zl(){var _,O,U,F,k,Q,L,z,W;const o=I.useDependency(i.ICommandService),t=I.useDependency(i.IUniverInstanceService),e=I.useObservable(P.useMemo(()=>t.getCurrentTypeOfUnit$(i.UniverInstanceType.UNIVER_DOC),[])),n=I.useDependency(D.IRenderManagerService),r=(O=(_=e==null?void 0:e.getBody())==null?void 0:_.dataStream)!=null?O:"",[s,a]=P.useState(0),[c,l]=P.useState(void 0),A=(U=e==null?void 0:e.getUnitId())!=null?U:"",d=n.getRenderById(A),u=e==null?void 0:e.getTitle(),m=d==null?void 0:d.with(exports.DocEventManagerService),g=m==null?void 0:m.paragraphBounds,h=(k=(F=d==null?void 0:d.mainComponent)==null?void 0:F.left)!=null?k:0,p=(Q=d==null?void 0:d.engine.height)!=null?Q:0,f=(L=d==null?void 0:d.scene.scaleY)!=null?L:1,S=(W=(z=e==null?void 0:e.getBody())==null?void 0:z.paragraphs)!=null?W:[],E=P.useMemo(()=>{const H=new Map;return S.forEach(V=>{H.set(V.startIndex,V)}),H},[S]);I.useObservable(P.useMemo(()=>d!=null&&d.engine.onTransformChange$?i.fromEventSubject(d==null?void 0:d.engine.onTransformChange$).pipe(w.throttleTime(33)):w.of(null),[d==null?void 0:d.engine.onTransformChange$]));const C=h<180?"float":"side-bar",y=S==null?void 0:S.filter(H=>{var V;return((V=H.paragraphStyle)==null?void 0:V.namedStyleType)!==void 0&&H.paragraphStyle.namedStyleType!==i.NamedStyleType.SUBTITLE&&H.paragraphStyle.namedStyleType!==i.NamedStyleType.NORMAL_TEXT}).map(H=>{var Y;const V=Vl(H.paragraphStyle.namedStyleType),j=g==null?void 0:g.get(H.startIndex);if(!j)return null;const{paragraphStart:G,paragraphEnd:K}=j;return{id:H.paragraphStyle.headingId,text:i.getPlainText(r.slice(G,K)),level:V,isTitle:((Y=H.paragraphStyle)==null?void 0:Y.namedStyleType)===i.NamedStyleType.TITLE}}).filter(H=>H==null?void 0:H.text),R=I.useEvent(H=>{const V=H.viewportScrollY,j=V+p/f,G=jl(g,E,V,j);G&&l(G)}),v=y!=null&&y.find(H=>H.isTitle)?y:[...u?[{id:Fr,text:u,level:1,isTitle:!0}]:[],...y!=null?y:[]].filter(Boolean),[b,x]=P.useState(!0);P.useEffect(()=>{const H=i.debounce(a,100),V=o.onCommandExecuted(j=>{j.id===B.RichTextEditingMutation.id&&j.params.unitId===(e==null?void 0:e.getUnitId())&&H(K=>K+1)});return()=>{V.dispose()}},[o,e]),P.useEffect(()=>{const H=d==null?void 0:d.scene.getViewport(ie.VIEW_MAIN);if(!H)return;const V=i.fromEventSubject(H.onScrollAfter$).pipe(w.throttleTime(33)).subscribe(R);return()=>{V.unsubscribe()}},[d]);const T=I.useEvent(H=>{const V=d==null?void 0:d.scene.getViewport(ie.VIEW_MAIN);if(!V)return;if(H.id===Fr){V.scrollToViewportPos({viewportScrollY:0});return}const j=S.find(K=>{var Y;return((Y=K.paragraphStyle)==null?void 0:Y.headingId)===H.id});if(!j)return;const G=g==null?void 0:g.get(j.startIndex);G&&(V.scrollToViewportPos({viewportScrollY:G.rect.top}),l(H.id))});return!e||i.isInternalEditorID(A)||!(v!=null&&v.length)?null:N.jsx("div",{className:"univer-absolute univer-bottom-0 univer-left-0 univer-top-0 univer-z-[100] univer-w-[0px]",children:N.jsx(kl,{menus:v,open:b,onOpenChange:x,mode:C,maxWidth:C==="float"?void 0:Math.floor(h),wrapperClass:"univer-mt-12",activeId:c,onClick:T,maxHeight:p-48})})}const Tn={id:"doc.table.delete-rows",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(B.DocSelectionManagerService),e=o.get(i.IUniverInstanceService),n=o.get(i.ICommandService),r=t.getRectRanges(),s=t.getActiveTextRange(),a=yt(s,r);if(a==null)return!1;const{segmentId:c}=a,l=e.getCurrentUniverDocInstance(),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c).getBody();if(l==null||A==null)return!1;const d=ce(o,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),g=new i.TextX,h=i.JSONX.getInstance(),p=Hi(a,u);if(p==null)return!1;const{offset:f,rowIndexes:S,len:E,tableId:C,cursor:y,selectWholeTable:R}=p;if(R)return n.executeCommand(lt.id);const v=[],b=[{startOffset:y,endOffset:y,collapsed:!0}],x={id:B.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:b}};f>0&&g.push({t:i.TextXActionType.RETAIN,len:f}),g.push({t:i.TextXActionType.DELETE,len:E});const T=J(l,c);v.push(h.editOp(g.serialize(),T));for(const O of S.reverse()){const U=h.removeOp(["tableSource",C,"tableRows",O]);v.push(U)}return x.params.actions=v.reduce((O,U)=>i.JSONX.compose(O,U),null),!!n.syncExecuteCommand(x.id,x.params)}},yn={id:"doc.table.delete-columns",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(B.DocSelectionManagerService),e=o.get(i.IUniverInstanceService),n=o.get(i.ICommandService),r=t.getRectRanges(),s=t.getActiveTextRange(),a=yt(s,r);if(a==null)return!1;const{segmentId:c}=a,l=e.getCurrentUniverDocInstance(),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c).getBody();if(l==null||A==null)return!1;const d=ce(o,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),g=new i.TextX,h=i.JSONX.getInstance(),p=La(a,u);if(p==null)return!1;const{offsets:f,columnIndexes:S,tableId:E,cursor:C,rowCount:y,selectWholeTable:R}=p;if(R)return n.executeCommand(lt.id);const v=[],b=[{startOffset:C,endOffset:C,collapsed:!0}],x={id:B.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:b}};for(const O of f){const{retain:U,delete:F}=O;U>0&&g.push({t:i.TextXActionType.RETAIN,len:U}),g.push({t:i.TextXActionType.DELETE,len:F})}const T=J(l,c);v.push(h.editOp(g.serialize(),T)),S.reverse();for(let O=0;O<y;O++)for(const U of S){const F=h.removeOp(["tableSource",E,"tableRows",O,"tableCells",U]);v.push(F)}for(const O of S){const U=h.removeOp(["tableSource",E,"tableColumns",O]);v.push(U)}return x.params.actions=v.reduce((O,U)=>i.JSONX.compose(O,U),null),!!n.syncExecuteCommand(x.id,x.params)}},lt={id:"doc.table.delete-table",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(B.DocSelectionManagerService),e=o.get(i.IUniverInstanceService),n=o.get(i.ICommandService),r=t.getRectRanges(),s=t.getActiveTextRange(),a=yt(s,r);if(a==null)return!1;const{segmentId:c}=a,l=e.getCurrentUniverDocInstance(),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c).getBody();if(l==null||A==null)return!1;const d=ce(o,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),g=new i.TextX,h=i.JSONX.getInstance(),p=ki(a,u);if(p==null)return!1;const{offset:f,len:S,tableId:E,cursor:C}=p,y=[],R=[{startOffset:C,endOffset:C,collapsed:!0}],v={id:B.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:R}};f>0&&g.push({t:i.TextXActionType.RETAIN,len:f}),g.push({t:i.TextXActionType.DELETE,len:S});const b=J(l,c);y.push(h.editOp(g.serialize(),b));const x=h.removeOp(["tableSource",E]);return y.push(x),v.params.actions=y.reduce((_,O)=>i.JSONX.compose(_,O),null),!!n.syncExecuteCommand(v.id,v.params)}},Yo="doc.command.table-insert-row",qo="doc.command.table-insert-column",Gl="doc.command.table-insert-row-above",Xl="doc.command.table-insert-row-bellow",Kl="doc.command.table-insert-column-left",Yl="doc.command.table-insert-column-right",bn={id:Gl,type:i.CommandType.COMMAND,handler:async o=>o.get(i.ICommandService).executeCommand(Yo,{position:dn.ABOVE})},Rn={id:Xl,type:i.CommandType.COMMAND,handler:async o=>o.get(i.ICommandService).executeCommand(Yo,{position:dn.BELLOW})},xn={id:Kl,type:i.CommandType.COMMAND,handler:async o=>o.get(i.ICommandService).executeCommand(qo,{position:To.LEFT})},On={id:Yl,type:i.CommandType.COMMAND,handler:async o=>o.get(i.ICommandService).executeCommand(qo,{position:To.RIGHT})},Jo={id:Yo,type:i.CommandType.COMMAND,handler:async(o,t)=>{const{position:e}=t,n=o.get(B.DocSelectionManagerService),r=o.get(i.IUniverInstanceService),s=o.get(i.ICommandService),a=n.getRectRanges(),c=n.getActiveTextRange(),l=yt(c,a);if(l==null)return!1;const{segmentId:A}=l,d=r.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(A).getBody();if(d==null||u==null)return!1;const m=ce(o,d.getUnitId());if(m==null)return!1;const g=m.getViewModel(),h=d==null?void 0:d.getUnitId(),p=new i.TextX,f=i.JSONX.getInstance(),S=Pa(l,e,g);if(S==null)return!1;const{offset:E,colCount:C,tableId:y,insertRowIndex:R}=S,v=[],b=E+2,x=[{startOffset:b,endOffset:b,collapsed:!0}],T={id:B.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:x}};E>0&&p.push({t:i.TextXActionType.RETAIN,len:E});const _=_a(C);p.push({t:i.TextXActionType.INSERT,body:_,len:_.dataStream.length});const O=J(d,A);v.push(f.editOp(p.serialize(),O));const U=un(C),F=f.insertOp(["tableSource",y,"tableRows",R],U);return v.push(F),T.params.actions=v.reduce((Q,L)=>i.JSONX.compose(Q,L),null),!!s.syncExecuteCommand(T.id,T.params)}},ls={id:qo,type:i.CommandType.COMMAND,handler:async(o,t)=>{var G,K,Y;const{position:e}=t,n=o.get(B.DocSelectionManagerService),r=o.get(i.IUniverInstanceService),s=o.get(i.ICommandService),a=n.getRectRanges(),c=n.getActiveTextRange(),l=yt(c,a);if(l==null)return!1;const{segmentId:A}=l,d=r.getCurrentUniverDocInstance(),u=d==null?void 0:d.getSelfOrHeaderFooterModel(A).getBody();if(d==null||u==null)return!1;const m=ce(o,d.getUnitId());if(m==null)return!1;const g=m.getViewModel(),h=d==null?void 0:d.getUnitId(),p=new i.TextX,f=i.JSONX.getInstance(),S=Ua(l,e,g);if(S==null)return!1;const{offsets:E,columnIndex:C,tableId:y,rowCount:R}=S,v=[],b=E[0]+1,x=[{startOffset:b,endOffset:b,collapsed:!0}],T={id:B.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:x}};for(const X of E){p.push({t:i.TextXActionType.RETAIN,len:X});const q=Na();p.push({t:i.TextXActionType.INSERT,body:q,len:q.dataStream.length})}const _=J(d,A);v.push(f.editOp(p.serialize(),_));for(let X=0;X<R;X++){const q=An(),ne=f.insertOp(["tableSource",y,"tableRows",X,"tableCells",C],q);v.push(ne)}const O=d.getSnapshot(),U=O.documentStyle,{marginLeft:F=0,marginRight:k=0}=U,Q=((K=(G=U.pageSize)==null?void 0:G.width)!=null?K:800)-F-k,L=(Y=O==null?void 0:O.tableSource)==null?void 0:Y[y].tableColumns,{newColWidth:z,widths:W}=wa(Q,L,C);for(let X=0;X<W.length;X++){const q=f.replaceOp(["tableSource",y,"tableColumns",X,"size","width","v"],L[X].size.width.v,W[X]);v.push(q)}const H=gn(z),V=f.insertOp(["tableSource",y,"tableColumns",C],H);return v.push(V),T.params.actions=v.reduce((X,q)=>i.JSONX.compose(X,q),null),!!s.syncExecuteCommand(T.id,T.params)}},fe={id:"doc-paragraph-setting.command",type:i.CommandType.COMMAND,handler:async(o,t)=>{var C,y,R,v,b;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.getDocRanges();if(!s||a.length===0||!t)return!1;const c=a[0].segmentId,l=s.getUnitId(),A=s.getSelfOrHeaderFooterModel(c),d=(y=(C=A.getBody())==null?void 0:C.paragraphs)!=null?y:[],u=(v=(R=A.getBody())==null?void 0:R.dataStream)!=null?v:"",m=(b=i.BuildTextUtils.range.getParagraphsInRanges(a,d,u))!=null?b:[],g={id:B.RichTextEditingMutation.id,params:{unitId:l,actions:[],textRanges:a}},h=new i.MemoryCursor;h.reset();const p=new i.TextX,f=i.JSONX.getInstance();for(const x of m){const{startIndex:T}=x;p.push({t:i.TextXActionType.RETAIN,len:T-h.cursor});const _={...x.paragraphStyle,...t.paragraph};p.push({t:i.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...x,paragraphStyle:_,startIndex:0}]},coverType:i.UpdateDocsAttributeType.REPLACE}),h.moveCursorTo(T+1)}const S=J(s,c);return g.params.actions=f.editOp(p.serialize(),S),!!r.syncExecuteCommand(g.id,g.params)}},ql=()=>{const o=I.useDependency(B.DocSelectionManagerService),t=I.useDependency(it),e=P.useMemo(()=>o.getDocRanges(),[]);return P.useEffect(()=>{e.length||t.closePanel()},[e]),e},Jl=()=>{var l,A,d,u,m;const t=I.useDependency(i.IUniverInstanceService).getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),e=ql();if(!t||e.length===0)return[];const n=e[0].segmentId,r=t.getSelfOrHeaderFooterModel(n),s=(A=(l=r.getBody())==null?void 0:l.paragraphs)!=null?A:[],a=(u=(d=r.getBody())==null?void 0:d.dataStream)!=null?u:"";return(m=i.BuildTextUtils.range.getParagraphsInRanges(e,s,a))!=null?m:[]},Zl=(o,t)=>{const e=I.useDependency(i.ICommandService),[n,r]=P.useState(()=>{var c,l;const a=o[0];return a?String((l=(c=a.paragraphStyle)==null?void 0:c.horizontalAlign)!=null?l:t):t});return[n,a=>(r(a),e.executeCommand(fe.id,{paragraph:{horizontalAlign:Number(a)}}))]},$l=o=>{const t=I.useDependency(i.ICommandService),[e,n]=P.useState(()=>{var a;const s=o[0];return s?D.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.indentStart,0):0});return[e,s=>(n(s),t.executeCommand(fe.id,{paragraph:{indentStart:{v:s}}}))]},ed=o=>{const t=I.useDependency(i.ICommandService),[e,n]=P.useState(()=>{var a;const s=o[0];return s?D.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.indentEnd,0):0});return[e,s=>(n(s),t.executeCommand(fe.id,{paragraph:{indentEnd:{v:s}}}))]},td=o=>{const t=I.useDependency(i.ICommandService),[e,n]=P.useState(()=>{var a;const s=o[0];return s?D.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.indentFirstLine,0):0});return[e,s=>(n(s),t.executeCommand(fe.id,{paragraph:{indentFirstLine:{v:s}}}))]},nd=o=>{const t=I.useDependency(i.ICommandService),[e,n]=P.useState(()=>{var a;const s=o[0];return s?D.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.hanging,0):0});return[e,s=>(n(s),t.executeCommand(fe.id,{paragraph:{hanging:{v:s}}}))]},od=o=>{const t=I.useDependency(i.ICommandService),[e,n]=P.useState(()=>{var a;const s=o[0];return s?D.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.spaceAbove,0):0});return[e,s=>(n(s),t.executeCommand(fe.id,{paragraph:{spaceAbove:{v:s}}}))]},rd=o=>{const t=I.useDependency(i.ICommandService),[e,n]=P.useState(()=>{var a;const s=o[0];return s?D.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.spaceBelow,0):0});return[e,s=>(n(s),t.executeCommand(fe.id,{paragraph:{spaceBelow:{v:s}}}))]},id=o=>{const t=I.useDependency(i.ICommandService),e=I.useDependency(D.IRenderManagerService),n=I.useDependency(i.IUniverInstanceService),r=P.useMemo(()=>{var h;const g=n.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);if(g)return(h=e.getRenderById(g==null?void 0:g.getUnitId()))==null?void 0:h.with(B.DocSkeletonManagerService).getSkeleton()},[]),s=P.useMemo(()=>new w.BehaviorSubject({}),[]),[a,c]=P.useState(()=>{var h,p;const g=o[0];return g&&(p=(h=g.paragraphStyle)==null?void 0:h.lineSpacing)!=null?p:1}),l=P.useRef(a),[A,d]=P.useState(()=>{var h,p;const g=o[0];return g&&(p=(h=g.paragraphStyle)==null?void 0:h.spacingRule)!=null?p:i.SpacingRule.AUTO}),u=async g=>{c(g),s.next({lineSpacing:g,spacingRule:A})},m=async g=>{if(g!==A){let h=l.current;if(g===i.SpacingRule.AT_LEAST){const p=r==null?void 0:r.findNodeByCharIndex(o[0].startIndex),f=p==null?void 0:p.parent,S=f==null?void 0:f.parent;(S==null?void 0:S.contentHeight)!==void 0&&(h=Math.max(S.contentHeight,h))}else h>5&&(h=2);l.current=a,u(h),d(g),s.next({spacingRule:g})}};return P.useEffect(()=>{const g=s.pipe(pt.filter(h=>!!Object.keys(h).length),pt.bufferTime(16),pt.filter(h=>!!h.length),pt.map(h=>h.reduce((p,f)=>(Object.keys(f).forEach(S=>{p[S]=f[S]}),p),{}))).subscribe(h=>t.executeCommand(fe.id,{paragraph:{...h}}));return()=>g.unsubscribe()},[]),{lineSpacing:[a,u],spacingRule:[A,m]}},ke=o=>{const{value:t,onChange:e,className:n="",min:r=0,max:s=100,step:a=1}=o,c=P.useRef(null);return N.jsx($.InputNumber,{step:a,ref:c,min:r,max:s,value:t,onChange:l=>{e(l!=null?l:0).finally(()=>{setTimeout(()=>{var A;(A=c.current)==null||A.focus()},30)})},className:n})};function sd(){const o=I.useDependency(i.LocaleService),t=P.useMemo(()=>[{label:o.t("toolbar.alignLeft"),value:String(i.HorizontalAlign.LEFT),icon:N.jsx(Oi,{})},{label:o.t("toolbar.alignCenter"),value:String(i.HorizontalAlign.CENTER),icon:N.jsx(xi,{})},{label:o.t("toolbar.alignRight"),value:String(i.HorizontalAlign.RIGHT),icon:N.jsx(Di,{})},{label:o.t("toolbar.alignJustify"),value:String(i.HorizontalAlign.JUSTIFIED),icon:N.jsx(pi,{})}],[]),e=Jl(),[n,r]=Zl(e,t[0].value),[s,a]=$l(e),[c,l]=ed(e),[A,d]=td(e),[u,m]=nd(e),[g,h]=od(e),[p,f]=rd(e),{lineSpacing:[S,E],spacingRule:[C,y]}=id(e),R=P.useMemo(()=>C===i.SpacingRule.AUTO?{min:1,max:5,step:S<2?.5:1}:{min:1,max:100},[C,S]);return N.jsxs("div",{children:[N.jsx("div",{className:"univer-t-4 univer-text-[13px] univer-font-medium",children:o.t("doc.paragraphSetting.alignment")}),N.jsx("div",{className:`
61
+ `),children:e==null?void 0:e.map(y=>N.jsx("div",{id:`univer-side-menu-${y.id}`,className:$.clsx(Ll,{[Ql]:y.isTitle,[Fl]:y.level===1,[Hl]:y.level>1,"univer-text-gray-500":y.id!==l,"univer-text-gray-800":y.id===l}),style:{paddingLeft:(y.level-1)*12},onClick:()=>{n==null||n(y)},children:y.text},y.id))})})]})}),Vl=o=>{switch(o){case i.NamedStyleType.HEADING_1:return 1;case i.NamedStyleType.HEADING_2:return 2;case i.NamedStyleType.HEADING_3:return 3;case i.NamedStyleType.HEADING_4:return 4;case i.NamedStyleType.HEADING_5:return 5;case i.NamedStyleType.TITLE:return 1;default:return 1}};function jl(o,t,e,n){var c,l;if(!o)return;const r=Array.from(o.values()),s=r.findIndex(A=>A.paragraphStart!==A.paragraphEnd&&A.rect.top<n&&A.rect.bottom>e);if(s===-1)return;const a=r==null?void 0:r.findLastIndex(A=>A.paragraphStart!==A.paragraphEnd&&A.rect.top<n&&A.rect.bottom>e);for(let A=s;A<=a;A++){const d=r[A],u=t.get(d.startIndex);if((c=u==null?void 0:u.paragraphStyle)!=null&&c.headingId)return u.paragraphStyle.headingId}for(let A=s;A>=0;A--){const d=r[A],u=t.get(d.startIndex);if((l=u==null?void 0:u.paragraphStyle)!=null&&l.headingId)return u.paragraphStyle.headingId}}const Fr="__title";function Wl(){var t,e,n;const o=I.useConfigValue(Cn);return(n=(e=(t=o==null?void 0:o.layout)==null?void 0:t.docContainerConfig)==null?void 0:e.sideMenu)==null||n?N.jsx(zl,{}):null}function zl(){var _,O,U,F,k,Q,L,z,W;const o=I.useDependency(i.ICommandService),t=I.useDependency(i.IUniverInstanceService),e=I.useObservable(P.useMemo(()=>t.getCurrentTypeOfUnit$(i.UniverInstanceType.UNIVER_DOC),[])),n=I.useDependency(D.IRenderManagerService),r=(O=(_=e==null?void 0:e.getBody())==null?void 0:_.dataStream)!=null?O:"",[s,a]=P.useState(0),[c,l]=P.useState(void 0),A=(U=e==null?void 0:e.getUnitId())!=null?U:"",d=n.getRenderById(A),u=e==null?void 0:e.getTitle(),m=d==null?void 0:d.with(exports.DocEventManagerService),g=m==null?void 0:m.paragraphBounds,h=(k=(F=d==null?void 0:d.mainComponent)==null?void 0:F.left)!=null?k:0,p=(Q=d==null?void 0:d.engine.height)!=null?Q:0,f=(L=d==null?void 0:d.scene.scaleY)!=null?L:1,S=(W=(z=e==null?void 0:e.getBody())==null?void 0:z.paragraphs)!=null?W:[],E=P.useMemo(()=>{const H=new Map;return S.forEach(V=>{H.set(V.startIndex,V)}),H},[S]);I.useObservable(P.useMemo(()=>d!=null&&d.engine.onTransformChange$?i.fromEventSubject(d==null?void 0:d.engine.onTransformChange$).pipe(w.throttleTime(33)):w.of(null),[d==null?void 0:d.engine.onTransformChange$]));const C=h<180?"float":"side-bar",y=S==null?void 0:S.filter(H=>{var V;return((V=H.paragraphStyle)==null?void 0:V.namedStyleType)!==void 0&&H.paragraphStyle.namedStyleType!==i.NamedStyleType.SUBTITLE&&H.paragraphStyle.namedStyleType!==i.NamedStyleType.NORMAL_TEXT}).map(H=>{var Y;const V=Vl(H.paragraphStyle.namedStyleType),j=g==null?void 0:g.get(H.startIndex);if(!j)return null;const{paragraphStart:G,paragraphEnd:K}=j;return{id:H.paragraphStyle.headingId,text:i.getPlainText(r.slice(G,K)),level:V,isTitle:((Y=H.paragraphStyle)==null?void 0:Y.namedStyleType)===i.NamedStyleType.TITLE}}).filter(H=>H==null?void 0:H.text),R=I.useEvent(H=>{const V=H.viewportScrollY,j=V+p/f,G=jl(g,E,V,j);G&&l(G)}),v=y!=null&&y.find(H=>H.isTitle)?y:[...u?[{id:Fr,text:u,level:1,isTitle:!0}]:[],...y!=null?y:[]].filter(Boolean),[b,x]=P.useState(!0);P.useEffect(()=>{const H=i.debounce(a,100),V=o.onCommandExecuted(j=>{j.id===B.RichTextEditingMutation.id&&j.params.unitId===(e==null?void 0:e.getUnitId())&&H(K=>K+1)});return()=>{V.dispose()}},[o,e]),P.useEffect(()=>{const H=d==null?void 0:d.scene.getViewport(ie.VIEW_MAIN);if(!H)return;const V=i.fromEventSubject(H.onScrollAfter$).pipe(w.throttleTime(33)).subscribe(R);return()=>{V.unsubscribe()}},[d]);const T=I.useEvent(H=>{const V=d==null?void 0:d.scene.getViewport(ie.VIEW_MAIN);if(!V)return;if(H.id===Fr){V.scrollToViewportPos({viewportScrollY:0});return}const j=S.find(K=>{var Y;return((Y=K.paragraphStyle)==null?void 0:Y.headingId)===H.id});if(!j)return;const G=g==null?void 0:g.get(j.startIndex);G&&(V.scrollToViewportPos({viewportScrollY:G.rect.top}),l(H.id))});return!e||i.isInternalEditorID(A)||!(v!=null&&v.length)?null:N.jsx("div",{className:"univer-absolute univer-bottom-0 univer-left-0 univer-top-0 univer-z-[100] univer-w-[0px]",children:N.jsx(kl,{menus:v,open:b,onOpenChange:x,mode:C,maxWidth:C==="float"?void 0:Math.floor(h),wrapperClass:"univer-mt-12",activeId:c,onClick:T,maxHeight:p-48})})}const Tn={id:"doc.table.delete-rows",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(B.DocSelectionManagerService),e=o.get(i.IUniverInstanceService),n=o.get(i.ICommandService),r=t.getRectRanges(),s=t.getActiveTextRange(),a=yt(s,r);if(a==null)return!1;const{segmentId:c}=a,l=e.getCurrentUniverDocInstance(),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c).getBody();if(l==null||A==null)return!1;const d=ce(o,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),g=new i.TextX,h=i.JSONX.getInstance(),p=Hi(a,u);if(p==null)return!1;const{offset:f,rowIndexes:S,len:E,tableId:C,cursor:y,selectWholeTable:R}=p;if(R)return n.executeCommand(lt.id);const v=[],b=[{startOffset:y,endOffset:y,collapsed:!0}],x={id:B.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:b}};f>0&&g.push({t:i.TextXActionType.RETAIN,len:f}),g.push({t:i.TextXActionType.DELETE,len:E});const T=J(l,c);v.push(h.editOp(g.serialize(),T));for(const O of S.reverse()){const U=h.removeOp(["tableSource",C,"tableRows",O]);v.push(U)}return x.params.actions=v.reduce((O,U)=>i.JSONX.compose(O,U),null),!!n.syncExecuteCommand(x.id,x.params)}},yn={id:"doc.table.delete-columns",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(B.DocSelectionManagerService),e=o.get(i.IUniverInstanceService),n=o.get(i.ICommandService),r=t.getRectRanges(),s=t.getActiveTextRange(),a=yt(s,r);if(a==null)return!1;const{segmentId:c}=a,l=e.getCurrentUniverDocInstance(),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c).getBody();if(l==null||A==null)return!1;const d=ce(o,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),g=new i.TextX,h=i.JSONX.getInstance(),p=La(a,u);if(p==null)return!1;const{offsets:f,columnIndexes:S,tableId:E,cursor:C,rowCount:y,selectWholeTable:R}=p;if(R)return n.executeCommand(lt.id);const v=[],b=[{startOffset:C,endOffset:C,collapsed:!0}],x={id:B.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:b}};for(const O of f){const{retain:U,delete:F}=O;U>0&&g.push({t:i.TextXActionType.RETAIN,len:U}),g.push({t:i.TextXActionType.DELETE,len:F})}const T=J(l,c);v.push(h.editOp(g.serialize(),T)),S.reverse();for(let O=0;O<y;O++)for(const U of S){const F=h.removeOp(["tableSource",E,"tableRows",O,"tableCells",U]);v.push(F)}for(const O of S){const U=h.removeOp(["tableSource",E,"tableColumns",O]);v.push(U)}return x.params.actions=v.reduce((O,U)=>i.JSONX.compose(O,U),null),!!n.syncExecuteCommand(x.id,x.params)}},lt={id:"doc.table.delete-table",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(B.DocSelectionManagerService),e=o.get(i.IUniverInstanceService),n=o.get(i.ICommandService),r=t.getRectRanges(),s=t.getActiveTextRange(),a=yt(s,r);if(a==null)return!1;const{segmentId:c}=a,l=e.getCurrentUniverDocInstance(),A=l==null?void 0:l.getSelfOrHeaderFooterModel(c).getBody();if(l==null||A==null)return!1;const d=ce(o,l.getUnitId());if(d==null)return!1;const u=d.getViewModel(),m=l==null?void 0:l.getUnitId(),g=new i.TextX,h=i.JSONX.getInstance(),p=ki(a,u);if(p==null)return!1;const{offset:f,len:S,tableId:E,cursor:C}=p,y=[],R=[{startOffset:C,endOffset:C,collapsed:!0}],v={id:B.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:R}};f>0&&g.push({t:i.TextXActionType.RETAIN,len:f}),g.push({t:i.TextXActionType.DELETE,len:S});const b=J(l,c);y.push(h.editOp(g.serialize(),b));const x=h.removeOp(["tableSource",E]);return y.push(x),v.params.actions=y.reduce((_,O)=>i.JSONX.compose(_,O),null),!!n.syncExecuteCommand(v.id,v.params)}},Yo="doc.command.table-insert-row",qo="doc.command.table-insert-column",Gl="doc.command.table-insert-row-above",Xl="doc.command.table-insert-row-bellow",Kl="doc.command.table-insert-column-left",Yl="doc.command.table-insert-column-right",bn={id:Gl,type:i.CommandType.COMMAND,handler:async o=>o.get(i.ICommandService).executeCommand(Yo,{position:dn.ABOVE})},Rn={id:Xl,type:i.CommandType.COMMAND,handler:async o=>o.get(i.ICommandService).executeCommand(Yo,{position:dn.BELLOW})},xn={id:Kl,type:i.CommandType.COMMAND,handler:async o=>o.get(i.ICommandService).executeCommand(qo,{position:To.LEFT})},On={id:Yl,type:i.CommandType.COMMAND,handler:async o=>o.get(i.ICommandService).executeCommand(qo,{position:To.RIGHT})},Jo={id:Yo,type:i.CommandType.COMMAND,handler:async(o,t)=>{const{position:e}=t,n=o.get(B.DocSelectionManagerService),r=o.get(i.IUniverInstanceService),s=o.get(i.ICommandService),a=n.getRectRanges(),c=n.getActiveTextRange(),l=yt(c,a);if(l==null)return!1;const{segmentId:A}=l,d=r.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(A).getBody();if(d==null||u==null)return!1;const m=ce(o,d.getUnitId());if(m==null)return!1;const g=m.getViewModel(),h=d==null?void 0:d.getUnitId(),p=new i.TextX,f=i.JSONX.getInstance(),S=Pa(l,e,g);if(S==null)return!1;const{offset:E,colCount:C,tableId:y,insertRowIndex:R}=S,v=[],b=E+2,x=[{startOffset:b,endOffset:b,collapsed:!0}],T={id:B.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:x}};E>0&&p.push({t:i.TextXActionType.RETAIN,len:E});const _=_a(C);p.push({t:i.TextXActionType.INSERT,body:_,len:_.dataStream.length});const O=J(d,A);v.push(f.editOp(p.serialize(),O));const U=un(C),F=f.insertOp(["tableSource",y,"tableRows",R],U);return v.push(F),T.params.actions=v.reduce((Q,L)=>i.JSONX.compose(Q,L),null),!!s.syncExecuteCommand(T.id,T.params)}},ls={id:qo,type:i.CommandType.COMMAND,handler:async(o,t)=>{var G,K,Y;const{position:e}=t,n=o.get(B.DocSelectionManagerService),r=o.get(i.IUniverInstanceService),s=o.get(i.ICommandService),a=n.getRectRanges(),c=n.getActiveTextRange(),l=yt(c,a);if(l==null)return!1;const{segmentId:A}=l,d=r.getCurrentUniverDocInstance(),u=d==null?void 0:d.getSelfOrHeaderFooterModel(A).getBody();if(d==null||u==null)return!1;const m=ce(o,d.getUnitId());if(m==null)return!1;const g=m.getViewModel(),h=d==null?void 0:d.getUnitId(),p=new i.TextX,f=i.JSONX.getInstance(),S=Ua(l,e,g);if(S==null)return!1;const{offsets:E,columnIndex:C,tableId:y,rowCount:R}=S,v=[],b=E[0]+1,x=[{startOffset:b,endOffset:b,collapsed:!0}],T={id:B.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:x}};for(const X of E){p.push({t:i.TextXActionType.RETAIN,len:X});const q=Na();p.push({t:i.TextXActionType.INSERT,body:q,len:q.dataStream.length})}const _=J(d,A);v.push(f.editOp(p.serialize(),_));for(let X=0;X<R;X++){const q=An(),ne=f.insertOp(["tableSource",y,"tableRows",X,"tableCells",C],q);v.push(ne)}const O=d.getSnapshot(),U=O.documentStyle,{marginLeft:F=0,marginRight:k=0}=U,Q=((K=(G=U.pageSize)==null?void 0:G.width)!=null?K:800)-F-k,L=(Y=O==null?void 0:O.tableSource)==null?void 0:Y[y].tableColumns,{newColWidth:z,widths:W}=wa(Q,L,C);for(let X=0;X<W.length;X++){const q=f.replaceOp(["tableSource",y,"tableColumns",X,"size","width","v"],L[X].size.width.v,W[X]);v.push(q)}const H=gn(z),V=f.insertOp(["tableSource",y,"tableColumns",C],H);return v.push(V),T.params.actions=v.reduce((X,q)=>i.JSONX.compose(X,q),null),!!s.syncExecuteCommand(T.id,T.params)}},fe={id:"doc-paragraph-setting.command",type:i.CommandType.COMMAND,handler:async(o,t)=>{var C,y,R,v,b;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.getDocRanges();if(!s||a.length===0||!t)return!1;const c=a[0].segmentId,l=s.getUnitId(),A=s.getSelfOrHeaderFooterModel(c),d=(y=(C=A.getBody())==null?void 0:C.paragraphs)!=null?y:[],u=(v=(R=A.getBody())==null?void 0:R.dataStream)!=null?v:"",m=(b=i.BuildTextUtils.range.getParagraphsInRanges(a,d,u))!=null?b:[],g={id:B.RichTextEditingMutation.id,params:{unitId:l,actions:[],textRanges:a}},h=new i.MemoryCursor;h.reset();const p=new i.TextX,f=i.JSONX.getInstance();for(const x of m){const{startIndex:T}=x;p.push({t:i.TextXActionType.RETAIN,len:T-h.cursor});const _={...x.paragraphStyle,...t.paragraph};p.push({t:i.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...x,paragraphStyle:_,startIndex:0}]},coverType:i.UpdateDocsAttributeType.REPLACE}),h.moveCursorTo(T+1)}const S=J(s,c);return g.params.actions=f.editOp(p.serialize(),S),!!r.syncExecuteCommand(g.id,g.params)}},ql=()=>{const o=I.useDependency(B.DocSelectionManagerService),t=I.useDependency(it),e=P.useMemo(()=>o.getDocRanges(),[]);return P.useEffect(()=>{e.length||t.closePanel()},[e]),e},Jl=()=>{var l,A,d,u,m;const t=I.useDependency(i.IUniverInstanceService).getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),e=ql();if(!t||e.length===0)return[];const n=e[0].segmentId,r=t.getSelfOrHeaderFooterModel(n),s=(A=(l=r.getBody())==null?void 0:l.paragraphs)!=null?A:[],a=(u=(d=r.getBody())==null?void 0:d.dataStream)!=null?u:"";return(m=i.BuildTextUtils.range.getParagraphsInRanges(e,s,a))!=null?m:[]},Zl=(o,t)=>{const e=I.useDependency(i.ICommandService),[n,r]=P.useState(()=>{var c,l;const a=o[0];return a?String((l=(c=a.paragraphStyle)==null?void 0:c.horizontalAlign)!=null?l:t):t});return[n,a=>(r(a),e.executeCommand(fe.id,{paragraph:{horizontalAlign:Number(a)}}))]},$l=o=>{const t=I.useDependency(i.ICommandService),[e,n]=P.useState(()=>{var a;const s=o[0];return s?D.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.indentStart,0):0});return[e,s=>(n(s),t.executeCommand(fe.id,{paragraph:{indentStart:{v:s}}}))]},ed=o=>{const t=I.useDependency(i.ICommandService),[e,n]=P.useState(()=>{var a;const s=o[0];return s?D.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.indentEnd,0):0});return[e,s=>(n(s),t.executeCommand(fe.id,{paragraph:{indentEnd:{v:s}}}))]},td=o=>{const t=I.useDependency(i.ICommandService),[e,n]=P.useState(()=>{var a;const s=o[0];return s?D.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.indentFirstLine,0):0});return[e,s=>(n(s),t.executeCommand(fe.id,{paragraph:{indentFirstLine:{v:s}}}))]},nd=o=>{const t=I.useDependency(i.ICommandService),[e,n]=P.useState(()=>{var a;const s=o[0];return s?D.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.hanging,0):0});return[e,s=>(n(s),t.executeCommand(fe.id,{paragraph:{hanging:{v:s}}}))]},od=o=>{const t=I.useDependency(i.ICommandService),[e,n]=P.useState(()=>{var a;const s=o[0];return s?D.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.spaceAbove,0):0});return[e,s=>(n(s),t.executeCommand(fe.id,{paragraph:{spaceAbove:{v:s}}}))]},rd=o=>{const t=I.useDependency(i.ICommandService),[e,n]=P.useState(()=>{var a;const s=o[0];return s?D.getNumberUnitValue((a=s.paragraphStyle)==null?void 0:a.spaceBelow,0):0});return[e,s=>(n(s),t.executeCommand(fe.id,{paragraph:{spaceBelow:{v:s}}}))]},id=o=>{const t=I.useDependency(i.ICommandService),e=I.useDependency(D.IRenderManagerService),n=I.useDependency(i.IUniverInstanceService),r=P.useMemo(()=>{var h;const g=n.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);if(g)return(h=e.getRenderById(g==null?void 0:g.getUnitId()))==null?void 0:h.with(B.DocSkeletonManagerService).getSkeleton()},[]),s=P.useMemo(()=>new w.BehaviorSubject({}),[]),[a,c]=P.useState(()=>{var h,p;const g=o[0];return g&&(p=(h=g.paragraphStyle)==null?void 0:h.lineSpacing)!=null?p:1}),l=P.useRef(a),[A,d]=P.useState(()=>{var h,p;const g=o[0];return g&&(p=(h=g.paragraphStyle)==null?void 0:h.spacingRule)!=null?p:i.SpacingRule.AUTO}),u=async g=>{c(g),s.next({lineSpacing:g,spacingRule:A})},m=async g=>{if(g!==A){let h=l.current;if(g===i.SpacingRule.AT_LEAST){const p=r==null?void 0:r.findNodeByCharIndex(o[0].startIndex),f=p==null?void 0:p.parent,S=f==null?void 0:f.parent;(S==null?void 0:S.contentHeight)!==void 0&&(h=Math.max(S.contentHeight,h))}else h>5&&(h=2);l.current=a,u(h),d(g),s.next({spacingRule:g})}};return P.useEffect(()=>{const g=s.pipe(pt.filter(h=>!!Object.keys(h).length),pt.bufferTime(16),pt.filter(h=>!!h.length),pt.map(h=>h.reduce((p,f)=>(Object.keys(f).forEach(S=>{p[S]=f[S]}),p),{}))).subscribe(h=>t.executeCommand(fe.id,{paragraph:{...h}}));return()=>g.unsubscribe()},[]),{lineSpacing:[a,u],spacingRule:[A,m]}},ke=o=>{const{value:t,onChange:e,className:n="",min:r=0,max:s=100,step:a=1}=o,c=P.useRef(null);return N.jsx($.InputNumber,{step:a,ref:c,min:r,max:s,value:t,onChange:l=>{e(l!=null?l:0).finally(()=>{setTimeout(()=>{var A;(A=c.current)==null||A.focus()},30)})},className:n})};function sd(){const o=I.useDependency(i.LocaleService),t=P.useMemo(()=>[{label:o.t("toolbar.alignLeft"),value:String(i.HorizontalAlign.LEFT),icon:N.jsx(Oi,{})},{label:o.t("toolbar.alignCenter"),value:String(i.HorizontalAlign.CENTER),icon:N.jsx(xi,{})},{label:o.t("toolbar.alignRight"),value:String(i.HorizontalAlign.RIGHT),icon:N.jsx(Di,{})},{label:o.t("toolbar.alignJustify"),value:String(i.HorizontalAlign.JUSTIFIED),icon:N.jsx(pi,{})}],[]),e=Jl(),[n,r]=Zl(e,t[0].value),[s,a]=$l(e),[c,l]=ed(e),[A,d]=td(e),[u,m]=nd(e),[g,h]=od(e),[p,f]=rd(e),{lineSpacing:[S,E],spacingRule:[C,y]}=id(e),R=P.useMemo(()=>C===i.SpacingRule.AUTO?{min:1,max:5,step:S<2?.5:1}:{min:1,max:100},[C,S]);return N.jsxs("div",{children:[N.jsx("div",{className:"univer-t-4 univer-text-[13px] univer-font-medium",children:o.t("doc.paragraphSetting.alignment")}),N.jsx("div",{className:`
64
62
  univer-mt-4 univer-box-border univer-flex univer-w-full univer-items-center univer-justify-between
65
63
  univer-gap-1 univer-rounded-md univer-border univer-border-solid univer-border-gray-200 univer-p-1
66
64
  `,children:t.map(v=>N.jsx($.Tooltip,{title:v.label,placement:"bottom",children:N.jsx("span",{className:$.clsx(`