@univerjs/docs 0.1.11 → 0.1.13

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
@@ -1 +1 @@
1
- "use strict";var ct=Object.defineProperty;var lt=(r,n,e)=>n in r?ct(r,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[n]=e;var T=(r,n,e)=>(lt(r,typeof n!="symbol"?n+"":n,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@univerjs/core"),y=require("@univerjs/engine-render"),w=require("rxjs"),L=require("@wendellhu/redi");var oe=(r=>(r.MAIN="__Document_Render_Main__",r.BACKGROUND="__Document_Render_Background__",r))(oe||{}),Xe=(r=>(r.VIEW_MAIN="viewMain",r.VIEW_TOP="viewTop",r.VIEW_LEFT="viewLeft",r.VIEW_LEFT_TOP="viewLeftTop",r))(Xe||{});const dt=0,ut=2,mt=4,gt=10,St="normalTextSelectionPluginName";function Ve(r,n){const e=r.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);if(!e)return null;const t=e.getUnitId(),o=n.getRenderById(t);if(o==null)return;const{mainComponent:a,scene:s,engine:c,components:l}=o,d=a,u=l.get(oe.BACKGROUND);return{document:d,docBackground:u,scene:s,engine:c}}function pt(r,n){const e=n.getRenderById(r);if(e==null)return;const{mainComponent:t,scene:o,engine:a,components:s}=e,c=t,l=s.get(oe.BACKGROUND);return{document:c,docBackground:l,scene:o,engine:a}}const Ie={id:"doc.operation.set-selections",type:i.CommandType.OPERATION,handler:(r,n)=>!0};var ft=Object.defineProperty,ht=Object.getOwnPropertyDescriptor,vt=(r,n,e,t)=>{for(var o=t>1?void 0:t?ht(n,e):n,a=r.length-1,s;a>=0;a--)(s=r[a])&&(o=(t?s(n,e,o):s(o))||o);return t&&o&&ft(n,e,o),o},De=(r,n)=>(e,t)=>n(e,t,r);function X(r){const{startOffset:n,endOffset:e,collapsed:t}=r,o={startOffset:n,endOffset:e,collapsed:t};return typeof r.isActive=="function"&&(o.isActive=r.isActive()),o}exports.TextSelectionManagerService=class extends i.RxDisposable{constructor(e,t){super();T(this,"_currentSelection",null);T(this,"_textSelectionInfo",new Map);T(this,"_textSelection$",new w.BehaviorSubject(null));T(this,"textSelection$",this._textSelection$.asObservable());this._textSelectionRenderManager=e,this._commandService=t,this._syncSelectionFromRenderService()}getCurrentSelection(){return this._currentSelection}getCurrentSelectionInfo(){return this._getTextRanges(this._currentSelection)}dispose(){this._textSelection$.complete()}refreshSelection(){this._currentSelection!=null&&this._refresh(this._currentSelection)}setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}setCurrentSelectionNotRefresh(e){this._currentSelection=e}getSelections(){var e;return(e=this._getTextRanges(this._currentSelection))==null?void 0:e.textRanges}getActiveRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:t,segmentId:o,style:a}=e,s=t.find(S=>S.isActive());if(s==null)return null;const{startOffset:c,endOffset:l,collapsed:d,startNodePosition:u,endNodePosition:m,direction:g}=s;return c==null||l==null?null:{startOffset:c,endOffset:l,collapsed:d,startNodePosition:u,endNodePosition:m,direction:g,segmentId:o,style:a}}add(e,t=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,segmentId:"",isEditing:t,style:y.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e,t=!0){this._currentSelection!=null&&(this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges(e,t))}_syncSelectionFromRenderService(){this._textSelectionRenderManager.textSelectionInner$.pipe(w.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._replaceTextRangesWithNoRefresh(e)})}_replaceTextRangesWithNoRefresh(e){if(this._currentSelection==null)return;const t={...this._currentSelection,...e};this._replaceByParam(t),this._textSelection$.next(t);const{unitId:o,subUnitId:a,segmentId:s,style:c,textRanges:l,isEditing:d}=t;this._commandService.executeCommand(Ie.id,{unitId:o,subUnitId:a,segmentId:s,style:c,isEditing:d,ranges:l.map(X)})}_getTextRanges(e){var a;if(e==null)return;const{unitId:t,subUnitId:o=""}=e;return(a=this._textSelectionInfo.get(t))==null?void 0:a.get(o)}_refresh(e){const t=this._getTextRanges(e);this._textSelectionRenderManager.removeAllTextRanges(),t&&Array.isArray(t.textRanges)&&t.textRanges.length&&this._textSelectionRenderManager.addTextRanges(t.textRanges.map(X))}_replaceByParam(e){const{unitId:t,subUnitId:o,style:a,segmentId:s,textRanges:c,isEditing:l}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(o,{textRanges:c,style:a,segmentId:s,isEditing:l})}_addByParam(e){const{unitId:t,subUnitId:o,textRanges:a,style:s,segmentId:c,isEditing:l}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);const d=this._textSelectionInfo.get(t);d.has(o)?d.get(o).textRanges.push(...a):d.set(o,{textRanges:a,style:s,segmentId:c,isEditing:l})}};exports.TextSelectionManagerService=vt([De(0,y.ITextSelectionRenderManager),De(1,i.ICommandService)],exports.TextSelectionManagerService);function Ce(r,n="",e=0){const{startOffset:t,endOffset:o}=r,a=[],s=t-e,c=o-e;return s>0&&a.push({t:i.TextXActionType.RETAIN,len:s,segmentId:n}),a.push({t:i.TextXActionType.DELETE,len:c-s,line:0,segmentId:n}),a}var It=Object.defineProperty,Ct=Object.getOwnPropertyDescriptor,_t=(r,n,e,t)=>{for(var o=t>1?void 0:t?Ct(n,e):n,a=r.length-1,s;a>=0;a--)(s=r[a])&&(o=(t?s(n,e,o):s(o))||o);return t&&o&&It(n,e,o),o},Mt=(r,n)=>(e,t)=>n(e,t,r);exports.DocViewModelManagerService=class extends i.RxDisposable{constructor(e){super();T(this,"_docViewModelMap",new Map);T(this,"_currentDocViewModel$",new w.BehaviorSubject(null));T(this,"currentDocViewModel$",this._currentDocViewModel$.asObservable());this._univerInstanceService=e,this._initialize()}_initialize(){this._init()}dispose(){this._currentDocViewModel$.complete(),this._docViewModelMap.clear()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(i.UniverInstanceType.UNIVER_DOC).pipe(w.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)}),this._univerInstanceService.getAllUnitsForType(i.UniverInstanceType.UNIVER_DOC).forEach(e=>{this._create(e)}),this._univerInstanceService.getTypeOfUnitDisposed$(i.UniverInstanceType.UNIVER_DOC).pipe(w.takeUntil(this.dispose$)).subscribe(e=>{this._docViewModelMap.delete(e.getUnitId())})}_create(e){if(e==null)return;const t=e.getUnitId();this._setCurrent(t)}getAllModel(){return this._docViewModelMap}getViewModel(e){var t;return(t=this._docViewModelMap.get(e))==null?void 0:t.docViewModel}_setCurrent(e){var o;const t=this._univerInstanceService.getUniverDocInstance(e);if(t==null)throw new Error(`Document data model with id ${e} not found when build view model.`);if(t.getBody()!=null){if(!this._docViewModelMap.has(e)){const a=this._buildDocViewModel(t);this._docViewModelMap.set(e,{unitId:e,docViewModel:a})}if(e===i.DOCS_NORMAL_EDITOR_UNIT_ID_KEY){const a=(o=this._docViewModelMap.get(e))==null?void 0:o.docViewModel;if(a==null)return;a.reset(t)}this._currentDocViewModel$.next(this._docViewModelMap.get(e))}}_buildDocViewModel(e){return new y.DocumentViewModel(e)}};exports.DocViewModelManagerService=_t([Mt(0,i.IUniverInstanceService)],exports.DocViewModelManagerService);var Tt=Object.defineProperty,xt=Object.getOwnPropertyDescriptor,yt=(r,n,e,t)=>{for(var o=t>1?void 0:t?xt(n,e):n,a=r.length-1,s;a>=0;a--)(s=r[a])&&(o=(t?s(n,e,o):s(o))||o);return t&&o&&Tt(n,e,o),o},he=(r,n)=>(e,t)=>n(e,t,r);const Rt=300;exports.DocStateChangeManagerService=class extends i.RxDisposable{constructor(e,t,o){super();T(this,"_docStateChange$",new w.BehaviorSubject(null));T(this,"docStateChange$",this._docStateChange$.asObservable());T(this,"_stateCache",new Map);T(this,"_timer",null);this._undoRedoService=e,this._commandService=t,this._univerInstanceService=o,this._initialize()}setChangeState(e){const{trigger:t,noHistory:o}=e;t!=null&&(this._cacheChangeState(e),o||this._docStateChange$.next(e))}_initialize(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===i.UndoCommandId||e.id===i.RedoCommandId){const t=this._univerInstanceService.getCurrentUniverDocInstance();if(t==null)return;const o=t.getUnitId();this._pushHistory(o)}}))}_cacheChangeState(e){const{trigger:t,unitId:o,noHistory:a}=e;if(!(t===i.RedoCommandId||t===i.UndoCommandId||a)){if(this._stateCache.has(o)){const s=this._stateCache.get(o);s==null||s.push(e)}else this._stateCache.set(o,[e]);t===Z.id||t===K.id?(this._timer&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._pushHistory(o)},Rt)):this._pushHistory(o)}}_pushHistory(e){const t=this._undoRedoService,o=this._stateCache.get(e);if(!Array.isArray(o)||o.length===0)return;const a=o.length,s=o[0].commandId,c=o[0],l=o[a-1],d={unitId:e,actions:o.reduce((m,g)=>i.TextX.compose(m,g.redoState.actions),[]),textRanges:l.redoState.textRanges},u={unitId:e,actions:o.reverse().reduce((m,g)=>i.TextX.compose(m,g.undoState.actions),[]),textRanges:c.undoState.textRanges};t.pushUndoRedo({unitID:e,undoMutations:[{id:s,params:u}],redoMutations:[{id:s,params:d}]}),o.length=0}};exports.DocStateChangeManagerService=yt([he(0,L.Inject(i.IUndoRedoService)),he(1,i.ICommandService),he(2,i.IUniverInstanceService)],exports.DocStateChangeManagerService);class W{constructor(){T(this,"_previousActiveRange",null);T(this,"_undoMutationParamsCache",[]);T(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache:n=[],redoCache:e=[]}){this._undoMutationParamsCache=n,this._redoMutationParamsCache=e}getActiveRange(){return this._previousActiveRange}setActiveRange(n){this._previousActiveRange=n}pushUndoRedoMutationParams(n,e){this._undoMutationParamsCache.push(n),this._redoMutationParamsCache.push(e)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:n}=this._undoMutationParamsCache[0],e={unitId:n,actions:this._undoMutationParamsCache.reverse().reduce((o,a)=>i.TextX.compose(o,a.actions),[]),textRanges:[]};return{redoMutationParams:{unitId:n,actions:this._redoMutationParamsCache.reduce((o,a)=>i.TextX.compose(o,a.actions),[]),textRanges:[]},undoMutationParams:e,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Ee="doc.mutation.rich-text-editing",N={id:Ee,type:i.CommandType.MUTATION,handler:(r,n)=>{var U;const{unitId:e,actions:t,textRanges:o,prevTextRanges:a,trigger:s,noHistory:c,isCompositionEnd:l,noNeedSetTextRange:d}=n,m=r.get(i.IUniverInstanceService).getUniverDocInstance(e),S=r.get(exports.DocViewModelManagerService).getViewModel(e),h=r.get(exports.TextSelectionManagerService),p=((U=h.getSelections())!=null?U:[]).map(X),v=r.get(exports.DocStateChangeManagerService),I=r.get(W);if(m==null||S==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const M=!!m.getSnapshot().disabled;if(t.length===0||M)return{unitId:e,actions:[],textRanges:p};const C=m.apply(t),{segmentId:_}=t[0],R=m.getSelfOrHeaderFooterModel(_);S.getSelfOrHeaderFooterViewModel(_).reset(R),!d&&o&&s!=null&&queueMicrotask(()=>{h.replaceTextRanges(o)});const D={commandId:Ee,unitId:e,trigger:s,noHistory:c,redoState:{actions:t,textRanges:o},undoState:{actions:C,textRanges:a!=null?a:p}};if(l){const x=I.fetchComposedUndoRedoMutationParams();if(x==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:E,redoMutationParams:A,previousActiveRange:$}=x;D.redoState.actions=A.actions,D.undoState.actions=E.actions,D.undoState.textRanges=[$]}return v.setChangeState(D),{unitId:e,actions:C,textRanges:p}}},Z={id:"doc.command.insert-text",type:i.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(i.ICommandService),{range:t,segmentId:o,body:a,unitId:s,textRanges:c}=n,{startOffset:l,collapsed:d}=t,u={id:N.id,params:{unitId:s,actions:[],textRanges:c}},m=new i.TextX;return d?l>0&&m.push({t:i.TextXActionType.RETAIN,len:l,segmentId:o}):m.push(...Ce(t,o)),m.push({t:i.TextXActionType.INSERT,body:a,len:a.dataStream.length,line:0,segmentId:o}),u.params.actions=m.serialize(),!!e.syncExecuteCommand(u.id,u.params)}};var F=(r=>(r[r.LEFT=0]="LEFT",r[r.RIGHT=1]="RIGHT",r))(F||{});const K={id:"doc.command.delete-text",type:i.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(i.ICommandService),{range:t,segmentId:o,unitId:a,direction:s,textRanges:c,len:l=1}=n,{startOffset:d}=t,u={id:N.id,params:{unitId:a,actions:[],textRanges:c}},m=new i.TextX;return d>0&&m.push({t:i.TextXActionType.RETAIN,len:s===0?d-l:d,segmentId:o}),m.push({t:i.TextXActionType.DELETE,len:l,line:0,segmentId:o}),u.params.actions=m.serialize(),!!e.syncExecuteCommand(u.id,u.params)}},_e={id:"doc.command.update-text",type:i.CommandType.COMMAND,handler:async(r,n)=>{const{range:e,segmentId:t,updateBody:o,coverType:a,unitId:s,textRanges:c}=n,l=r.get(i.ICommandService),d={id:N.id,params:{unitId:s,actions:[],textRanges:c}},u=new i.TextX,{startOffset:m,endOffset:g}=e;return u.push({t:i.TextXActionType.RETAIN,len:m,segmentId:t}),u.push({t:i.TextXActionType.RETAIN,body:o,len:g-m,segmentId:t,coverType:a}),d.params.actions=u.serialize(),!!l.syncExecuteCommand(d.id,d.params)}};function Ot(r,n){const e=[];for(let t=0,o=r.length;t<o;t++)r[t]===i.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});if(n)for(const t of e)n.bullet&&(t.bullet=i.Tools.deepClone(n.bullet)),n.paragraphStyle&&(t.paragraphStyle=i.Tools.deepClone(n.paragraphStyle));return e}const ze={id:"doc.command.break-line",type:i.CommandType.COMMAND,handler:async r=>{var h,f;const n=r.get(exports.TextSelectionManagerService),e=r.get(i.IUniverInstanceService),t=r.get(i.ICommandService),o=n.getActiveRange();if(o==null)return!1;const a=e.getCurrentUniverDocInstance();if(!a)return!1;const s=a.getUnitId(),{startOffset:c,segmentId:l,style:d}=o,u=[{startOffset:c+1,endOffset:c+1,style:d}],g=((f=(h=a.getBody())==null?void 0:h.paragraphs)!=null?f:[]).find(p=>p.startIndex>=c);return await t.executeCommand(Z.id,{unitId:s,body:{dataStream:i.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Ot(i.DataStreamTreeTokenType.PARAGRAPH,g)},range:o,textRanges:u,segmentId:l})}};var Dt=Object.defineProperty,Et=Object.getOwnPropertyDescriptor,At=(r,n,e,t)=>{for(var o=t>1?void 0:t?Et(n,e):n,a=r.length-1,s;a>=0;a--)(s=r[a])&&(o=(t?s(n,e,o):s(o))||o);return t&&o&&Dt(n,e,o),o},ve=(r,n)=>(e,t)=>n(e,t,r);exports.DocSkeletonManagerService=class extends i.RxDisposable{constructor(e,t,o){super();T(this,"_currentSkeletonUnitId","");T(this,"_docSkeletonMap",new Map);T(this,"_currentSkeleton$",new w.BehaviorSubject(null));T(this,"currentSkeleton$",this._currentSkeleton$.asObservable());T(this,"_currentSkeletonBefore$",new w.BehaviorSubject(null));T(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._localeService=e,this._docViewModelManagerService=t,this._univerInstanceService=o,this._initialize()}_initialize(){this._init()}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._docSkeletonMap.clear()}_init(){this._docViewModelManagerService.currentDocViewModel$.pipe(w.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._setCurrent(e)}),this._docViewModelManagerService.getAllModel().forEach(e=>{e!=null&&this._setCurrent(e)}),this._univerInstanceService.getTypeOfUnitDisposed$(i.UniverInstanceType.UNIVER_DOC).pipe(w.takeUntil(this.dispose$)).subscribe(e=>{var t,o;this._docSkeletonMap.delete(e.getUnitId()),this._currentSkeletonUnitId=(o=(t=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC))==null?void 0:t.getUnitId())!=null?o:""})}getCurrent(){return this.getSkeletonByUnitId(this._currentSkeletonUnitId)}getAllSkeleton(){return this._docSkeletonMap}makeDirtyCurrent(e=!0){this.makeDirty(this._currentSkeletonUnitId,e)}makeDirty(e,t=!0){const o=this.getSkeletonByUnitId(e);o!=null&&(o.dirty=t)}getSkeletonByUnitId(e){return this._docSkeletonMap.get(e)}_setCurrent(e){const{unitId:t}=e;if(this._docSkeletonMap.has(t)){const o=this.getSkeletonByUnitId(t);o.skeleton.calculate(),o.dirty=!0}else{const o=this._buildSkeleton(e.docViewModel);o.calculate(),this._docSkeletonMap.set(t,{unitId:t,skeleton:o,dirty:!1})}return this._currentSkeletonUnitId=t,this._currentSkeletonBefore$.next(this.getCurrent()),this._currentSkeleton$.next(this.getCurrent()),this.getCurrent()}_buildSkeleton(e){return y.DocumentSkeleton.create(e,this._localeService)}};exports.DocSkeletonManagerService=At([ve(0,L.Inject(i.LocaleService)),ve(1,L.Inject(exports.DocViewModelManagerService)),ve(2,i.IUniverInstanceService)],exports.DocSkeletonManagerService);const Nt={id:"doc.command.inner-paste",type:i.CommandType.COMMAND,handler:async(r,n)=>{const{segmentId:e,body:t,textRanges:o}=n,a=r.get(i.ICommandService),s=r.get(exports.TextSelectionManagerService),c=r.get(i.IUniverInstanceService),l=s.getSelections();if(!Array.isArray(l)||l.length===0)return!1;const d=c.getCurrentUniverDocInstance();if(!d)return!1;const u=d.getUnitId(),m={id:N.id,params:{unitId:u,actions:[],textRanges:o}},g=new i.MemoryCursor;g.reset();const S=new i.TextX;for(const f of l){const{startOffset:p,endOffset:v,collapsed:I}=f,M=p-g.cursor;I?S.push({t:i.TextXActionType.RETAIN,len:M,segmentId:e}):S.push(...Ce(f,e,g.cursor)),S.push({t:i.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:e}),g.reset(),g.moveCursor(v)}return m.params.actions=S.serialize(),!!a.syncExecuteCommand(m.id,m.params)}},Me={id:"doc.command.inner-cut",type:i.CommandType.COMMAND,handler:async(r,n)=>{var f;const{segmentId:e,textRanges:t}=n,o=r.get(i.ICommandService),a=r.get(exports.TextSelectionManagerService),s=r.get(i.IUniverInstanceService),c=a.getSelections();if(!Array.isArray(c)||c.length===0)return!1;const l=(f=s.getCurrentUniverDocInstance())==null?void 0:f.getUnitId();if(!l)return!1;const d=s.getUniverDocInstance(l),u=i.getDocsUpdateBody(d.snapshot,e);if(u==null)return!1;const m={id:N.id,params:{unitId:l,actions:[],textRanges:t}},g=new i.MemoryCursor;g.reset();const S=new i.TextX;for(const p of c){const{startOffset:v,endOffset:I,collapsed:M}=p,C=v-g.cursor;M?S.push({t:i.TextXActionType.RETAIN,len:C,segmentId:e}):S.push(...Ut(p,u,e,g.cursor)),g.reset(),g.moveCursor(I)}return m.params.actions=S.serialize(),!!o.syncExecuteCommand(m.id,m.params)}};function Ut(r,n,e="",t=0){const{startOffset:o,endOffset:a}=r,s=[],{paragraphs:c=[]}=n,l=o-t,d=a-t,u=c==null?void 0:c.find(m=>m.startIndex-t>=l&&m.startIndex-t<=d);if(l>0&&s.push({t:i.TextXActionType.RETAIN,len:l,segmentId:e}),u&&u.startIndex-t>l){const m=u.startIndex-t;s.push({t:i.TextXActionType.DELETE,len:m-l,line:0,segmentId:e}),s.push({t:i.TextXActionType.RETAIN,len:1,segmentId:e}),d>m+1&&s.push({t:i.TextXActionType.DELETE,len:d-m-1,line:0,segmentId:e})}else s.push({t:i.TextXActionType.DELETE,len:d-l,line:0,segmentId:e});return s}const je={id:"doc.command.delete-left",type:i.CommandType.COMMAND,handler:async r=>{var C;const n=r.get(exports.TextSelectionManagerService),e=r.get(exports.DocSkeletonManagerService),t=r.get(i.IUniverInstanceService),o=r.get(i.ICommandService),a=n.getActiveRange(),s=n.getSelections(),c=(C=e.getCurrent())==null?void 0:C.skeleton;let l=!0;if(a==null||c==null||s==null)return!1;const d=t.getCurrentUniverDocInstance();if(!d)return!1;const{startOffset:u,collapsed:m,segmentId:g,style:S}=a,h=c.findNodeByCharIndex(u),f=y.hasListGlyph(h),p=y.isIndentByGlyph(h,d.getBody());let v=u;const I=c.findNodeByCharIndex(u-1);if(y.isFirstGlyph(h)&&I!==h&&(f===!0||p===!0)&&m){const _=y.getParagraphByGlyph(h,d.getBody());if(_==null)return!1;const R=_==null?void 0:_.startIndex,O={startIndex:0},D=_.paragraphStyle;if(f===!0){const x=_.paragraphStyle;if(x){O.paragraphStyle=x;const{hanging:E}=x;E&&(O.paragraphStyle.indentStart=E,O.paragraphStyle.hanging=void 0)}}else if(p===!0){const x=_.bullet;x&&(O.bullet=x),D!=null&&(O.paragraphStyle={...D},delete O.paragraphStyle.hanging,delete O.paragraphStyle.indentStart)}const U=[{startOffset:v,endOffset:v,style:S}];l=await o.executeCommand(_e.id,{unitId:d.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...O}]},range:{startOffset:R,endOffset:R+1},textRanges:U,coverType:i.UpdateDocsAttributeType.REPLACE,segmentId:g})}else if(m===!0){if(I==null)return!0;if(I.content==="\r")l=await o.executeCommand(Te.id,{direction:F.LEFT,range:a});else{v-=I.count;const _=[{startOffset:v,endOffset:v,style:S}];l=await o.executeCommand(K.id,{unitId:d.getUnitId(),range:a,segmentId:g,direction:F.LEFT,len:I.count,textRanges:_})}}else{const _=He(a,s);l=await o.executeCommand(Me.id,{segmentId:g,textRanges:_})}return l}},Ge={id:"doc.command.delete-right",type:i.CommandType.COMMAND,handler:async r=>{var h;const n=r.get(exports.TextSelectionManagerService),e=r.get(exports.DocSkeletonManagerService),t=r.get(i.IUniverInstanceService),o=r.get(i.ICommandService),a=n.getActiveRange(),s=n.getSelections(),c=(h=e.getCurrent())==null?void 0:h.skeleton;let l;if(a==null||c==null||s==null)return!1;const d=t.getCurrentUniverDocInstance();if(!d)return!1;const{startOffset:u,collapsed:m,segmentId:g,style:S}=a;if(u===d.getBody().dataStream.length-2&&m)return!0;if(m===!0){const f=c.findNodeByCharIndex(u);if(f.content==="\r")l=await o.executeCommand(Te.id,{direction:F.RIGHT,range:a});else{const p=[{startOffset:u,endOffset:u,style:S}];l=await o.executeCommand(K.id,{unitId:d.getUnitId(),range:a,segmentId:g,direction:F.RIGHT,textRanges:p,len:f.count})}}else{const f=He(a,s);l=await o.executeCommand(Me.id,{segmentId:g,textRanges:f})}return l}},Te={id:"doc.command.merge-two-paragraph",type:i.CommandType.COMMAND,handler:async(r,n)=>{var O,D,U;const e=r.get(exports.TextSelectionManagerService),t=r.get(i.IUniverInstanceService),o=r.get(i.ICommandService),{direction:a,range:s}=n,c=e.getActiveRange(),l=e.getSelections();if(c==null||l==null)return!1;const d=t.getCurrentUniverDocInstance();if(!d)return!1;const{startOffset:u,collapsed:m,segmentId:g,style:S}=c;if(!m)return!1;const h=a===F.LEFT?u:u+1,f=(U=(D=(O=d.getBody())==null?void 0:O.paragraphs)==null?void 0:D.find(x=>x.startIndex>=h))==null?void 0:U.startIndex,p=bt(d.getBody(),h,f),v=a===F.LEFT?u-1:u,I=d.getUnitId(),M=[{startOffset:v,endOffset:v,style:S}],C={id:N.id,params:{unitId:I,actions:[],textRanges:M,prevTextRanges:[s]}},_=new i.TextX;return _.push({t:i.TextXActionType.RETAIN,len:a===F.LEFT?u-1:u,segmentId:g}),p.dataStream.length&&_.push({t:i.TextXActionType.INSERT,body:p,len:p.dataStream.length,line:0,segmentId:g}),_.push({t:i.TextXActionType.RETAIN,len:1,segmentId:g}),_.push({t:i.TextXActionType.DELETE,len:f+1-h,line:0,segmentId:g}),C.params.actions=_.serialize(),!!o.syncExecuteCommand(C.id,C.params)}};function bt(r,n,e){const{textRuns:t}=r,o=r.dataStream.substring(n,e);if(t==null)return{dataStream:o};const a=[];for(const s of t){const{st:c,ed:l}=s;l<=n||c>=e||(c<n?a.push({...s,st:0,ed:l-n}):l>e?a.push({...s,st:c-n,ed:e-n}):a.push({...s,st:c-n,ed:l-n}))}return{dataStream:o,textRuns:a}}function He(r,n){let e=r.endOffset;for(const o of n){const{startOffset:a,endOffset:s}=o;a==null||s==null||s<=r.endOffset&&(e-=s-a)}return[{startOffset:e,endOffset:e,style:r.style}]}const xe={id:"doc.command.ime-input",type:i.CommandType.COMMAND,handler:async(r,n)=>{const{unitId:e,newText:t,oldTextLen:o,isCompositionEnd:a,isCompositionStart:s}=n,c=r.get(i.ICommandService),l=r.get(W),d=l.getActiveRange();if(d==null)return!1;const{startOffset:u,style:m,segmentId:g}=d,S=t.length,h=[{startOffset:u+S,endOffset:u+S,collapsed:!0,style:m}],f={id:N.id,params:{unitId:e,actions:[],textRanges:h}},p=new i.TextX;!d.collapsed&&s?p.push(...Ce(d,g)):p.push({t:i.TextXActionType.RETAIN,len:u,segmentId:g}),o>0&&p.push({t:i.TextXActionType.DELETE,len:o,line:0,segmentId:g}),p.push({t:i.TextXActionType.INSERT,body:{dataStream:t},len:t.length,line:0,segmentId:g}),f.params.actions=p.serialize(),f.params.noHistory=!a,f.params.isCompositionEnd=a;const v=c.syncExecuteCommand(f.id,f.params);return l.pushUndoRedoMutationParams(v,f.params),!!v}};function b(r,n,e,t){var a;const{segmentId:o}=(a=e.getActiveRange())!=null?a:{};return o==null?!1:t.executeCommand(ye.id,{segmentId:o,preCommandId:r,...n!=null?n:{}})}const Ae="doc.command.set-inline-format-bold",ie={id:Ae,type:i.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(i.ICommandService),t=r.get(exports.TextSelectionManagerService);return b(Ae,n,t,e)}},Ne="doc.command.set-inline-format-italic",re={id:Ne,type:i.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(i.ICommandService),t=r.get(exports.TextSelectionManagerService);return b(Ne,n,t,e)}},Ue="doc.command.set-inline-format-underline",ae={id:Ue,type:i.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(i.ICommandService),t=r.get(exports.TextSelectionManagerService);return b(Ue,n,t,e)}},be="doc.command.set-inline-format-strikethrough",se={id:be,type:i.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(i.ICommandService),t=r.get(exports.TextSelectionManagerService);return b(be,n,t,e)}},Pe="doc.command.set-inline-format-subscript",V={id:Pe,type:i.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(i.ICommandService),t=r.get(exports.TextSelectionManagerService);return b(Pe,n,t,e)}},we="doc.command.set-inline-format-superscript",ce={id:we,type:i.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(i.ICommandService),t=r.get(exports.TextSelectionManagerService);return b(we,n,t,e)}},Le="doc.command.set-inline-format-fontsize",le={id:Le,type:i.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(i.ICommandService),t=r.get(exports.TextSelectionManagerService);return b(Le,n,t,e)}},Be="doc.command.set-inline-format-font-family",de={id:Be,type:i.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(i.ICommandService),t=r.get(exports.TextSelectionManagerService);return b(Be,n,t,e)}},Fe="doc.command.set-inline-format-text-color",ue={id:Fe,type:i.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(i.ICommandService),t=r.get(exports.TextSelectionManagerService);return b(Fe,n,t,e)}},$e="doc.command.set-inline-format-text-background-color",me={id:$e,type:i.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(i.ICommandService),t=r.get(exports.TextSelectionManagerService);return b($e,n,t,e)}},ke="doc.command.reset-inline-format-text-background-color",ge={id:ke,type:i.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(i.ICommandService),t=r.get(exports.TextSelectionManagerService);return b(ke,n,t,e)}},Ye={[ie.id]:"bl",[re.id]:"it",[ae.id]:"ul",[se.id]:"st",[le.id]:"fs",[de.id]:"ff",[ue.id]:"cl",[me.id]:"bg",[ge.id]:"bg",[V.id]:"va",[ce.id]:"va"},ye={id:"doc.command.set-inline-format",type:i.CommandType.COMMAND,handler:async(r,n)=>{const{segmentId:e,value:t,preCommandId:o}=n,a=r.get(i.ICommandService),s=r.get(exports.TextSelectionManagerService),c=r.get(i.IUniverInstanceService),l=s.getSelections();if(!Array.isArray(l)||l.length===0)return!1;let d=c.getCurrentUniverDocInstance();if(!d)return!1;let u=d.getUnitId();u===i.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(d=c.getUniverDocInstance(i.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),u=d.getUnitId());let m;switch(o){case ie.id:case re.id:case ae.id:case se.id:case V.id:case ce.id:{m=wt(d.getBody().textRuns,o,l);break}case le.id:case de.id:{m=t;break}case ue.id:case me.id:{m={rgb:t};break}case ge.id:{m={rgb:null};break}default:throw new Error(`Unknown command: ${o} in handleInlineFormat`)}const g={id:N.id,params:{unitId:u,actions:[],textRanges:l.map(X)}},S=new i.TextX,h=new i.MemoryCursor;h.reset();for(const p of l){const{startOffset:v,endOffset:I}=p,M={dataStream:"",textRuns:[{st:0,ed:I-v,ts:{[Ye[o]]:m}}]},C=v-h.cursor;C!==0&&S.push({t:i.TextXActionType.RETAIN,len:C,segmentId:e}),S.push({t:i.TextXActionType.RETAIN,body:M,len:I-v,segmentId:e}),h.reset(),h.moveCursor(I)}return g.params.actions=S.serialize(),!!a.syncExecuteCommand(g.id,g.params)}};function Pt(r){return r!==null&&typeof r=="object"}function wt(r,n,e){let t=0,o=0;const a=Ye[n];for(;t!==r.length&&o!==e.length;){const{startOffset:s,endOffset:c}=e[o],{st:l,ed:d,ts:u}=r[t];if(c<=l)o++;else if(d<=s)t++;else{if(/bl|it/.test(a))return(u==null?void 0:u[a])===i.BooleanNumber.TRUE?i.BooleanNumber.FALSE:i.BooleanNumber.TRUE;if(/ul|st/.test(a))return Pt(u==null?void 0:u[a])&&(u==null?void 0:u[a]).s===i.BooleanNumber.TRUE?{s:i.BooleanNumber.FALSE}:{s:i.BooleanNumber.TRUE};if(/va/.test(a))return n===V.id?(u==null?void 0:u[a])===i.BaselineOffset.SUBSCRIPT?i.BaselineOffset.NORMAL:i.BaselineOffset.SUBSCRIPT:(u==null?void 0:u[a])===i.BaselineOffset.SUPERSCRIPT?i.BaselineOffset.NORMAL:i.BaselineOffset.SUPERSCRIPT;t++}}return/bl|it/.test(a)?i.BooleanNumber.TRUE:/ul|st/.test(a)?{s:i.BooleanNumber.TRUE}:n===V.id?i.BaselineOffset.SUBSCRIPT:i.BaselineOffset.SUPERSCRIPT}const Re={id:"doc.command.list-operation",type:i.CommandType.COMMAND,handler:(r,n)=>{var x,E,A,$;const e=r.get(exports.TextSelectionManagerService),t=r.get(i.IUniverInstanceService),o=r.get(i.ICommandService),{listType:a}=n,s=t.getCurrentUniverDocInstance();if(!s)return!1;const c=e.getActiveRange(),l=(x=e.getSelections())!=null?x:[],d=(E=s.getBody())==null?void 0:E.paragraphs,u=l.map(X);if(c==null||d==null)return!1;const m=Ke(c,d),{segmentId:g}=c,S=s.getUnitId(),h=m.every(k=>{var P;return((P=k.bullet)==null?void 0:P.listType)===a});let p=i.Tools.generateRandomId(6);if(m.length===1){const k=d.indexOf(m[0]),P=d[k-1],B=d[k+1];P&&P.bullet&&P.bullet.listType===a?p=P.bullet.listId:B&&B.bullet&&B.bullet.listType===a&&(p=B.bullet.listId)}const v={id:N.id,params:{unitId:S,actions:[],textRanges:u}},I=new i.MemoryCursor;I.reset();const M=new i.TextX,C=(A=s.getSnapshot().lists)!=null?A:{},_={...i.PRESET_LIST_TYPE,...C},{charSpace:R,defaultTabStop:O=36,gridType:D}=s.getSnapshot().documentStyle;for(const k of m){const{startIndex:P,paragraphStyle:B={}}=k,{indentFirstLine:at=0,snapToGrid:st,indentStart:Se=0}=B,{hanging:pe,indentStart:Oe}=_[a].nestingLevel[0],fe=y.getCharSpaceApply(R,O,D,st);M.push({t:i.TextXActionType.RETAIN,len:P-I.cursor,segmentId:g}),M.push({t:i.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[h?{paragraphStyle:{...B,hanging:void 0,indentStart:Se?Math.max(0,y.getNumberUnitValue(Se,fe)+pe-Oe):void 0},startIndex:0}:{startIndex:0,paragraphStyle:{...B,indentFirstLine:void 0,hanging:pe,indentStart:Oe-pe+y.getNumberUnitValue(at,fe)+y.getNumberUnitValue(Se,fe)},bullet:{...($=k.bullet)!=null?$:{nestingLevel:0,textStyle:{fs:20}},listType:a,listId:p}}]},segmentId:g,coverType:i.UpdateDocsAttributeType.REPLACE}),I.moveCursorTo(P+1)}return v.params.actions=M.serialize(),!!o.syncExecuteCommand(v.id,v.params)}},We={id:"doc.command.bullet-list",type:i.CommandType.COMMAND,handler:r=>r.get(i.ICommandService).syncExecuteCommand(Re.id,{listType:i.PresetListType.BULLET_LIST})},Ze={id:"doc.command.order-list",type:i.CommandType.COMMAND,handler:r=>r.get(i.ICommandService).syncExecuteCommand(Re.id,{listType:i.PresetListType.ORDER_LIST})};function Ke(r,n){const{startOffset:e,endOffset:t}=r,o=[];let a=-1;for(const s of n){const{startIndex:c}=s;(e>a&&e<=c||t>a&&t<=c||c>=e&&c<=t)&&o.push(s),a=c}return o}const z={id:"doc.command.align-operation",type:i.CommandType.COMMAND,handler:(r,n)=>{var M,C;const e=r.get(exports.TextSelectionManagerService),t=r.get(i.IUniverInstanceService),o=r.get(i.ICommandService),{alignType:a}=n,s=t.getCurrentUniverDocInstance();if(!s)return!1;const c=e.getActiveRange(),l=(M=e.getSelections())!=null?M:[],d=(C=s.getBody())==null?void 0:C.paragraphs,u=l.map(X);if(c==null||d==null)return!1;const m=Ke(c,d),{segmentId:g}=c,S=s.getUnitId(),h=m.every(_=>{var R;return((R=_.paragraphStyle)==null?void 0:R.horizontalAlign)===a}),f={id:N.id,params:{unitId:S,actions:[],textRanges:u}},p=new i.MemoryCursor;p.reset();const v=new i.TextX;for(const _ of m){const{startIndex:R}=_;v.push({t:i.TextXActionType.RETAIN,len:R-p.cursor,segmentId:g});const O={..._.paragraphStyle,horizontalAlign:h?i.HorizontalAlign.UNSPECIFIED:a};v.push({t:i.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{..._,paragraphStyle:O,startIndex:0}]},segmentId:g,coverType:i.UpdateDocsAttributeType.REPLACE}),p.moveCursorTo(R+1)}return f.params.actions=v.serialize(),!!o.syncExecuteCommand(f.id,f.params)}},qe={id:"doc.command.align-left",type:i.CommandType.COMMAND,handler:r=>r.get(i.ICommandService).syncExecuteCommand(z.id,{alignType:i.HorizontalAlign.LEFT})},Je={id:"doc.command.align-center",type:i.CommandType.COMMAND,handler:r=>r.get(i.ICommandService).syncExecuteCommand(z.id,{alignType:i.HorizontalAlign.CENTER})},Qe={id:"doc.command.align-right",type:i.CommandType.COMMAND,handler:r=>r.get(i.ICommandService).syncExecuteCommand(z.id,{alignType:i.HorizontalAlign.RIGHT})},et={id:"doc.command.align-justify",type:i.CommandType.COMMAND,handler:r=>r.get(i.ICommandService).syncExecuteCommand(z.id,{alignType:i.HorizontalAlign.JUSTIFIED})},tt={id:"doc.command-replace-content",type:i.CommandType.COMMAND,handler:async(r,n)=>{var S;const{unitId:e,body:t,textRanges:o,segmentId:a=""}=n,s=r.get(i.IUniverInstanceService),c=r.get(i.ICommandService),l=r.get(exports.TextSelectionManagerService),d=(S=s.getUniverDocInstance(e))==null?void 0:S.getSnapshot().body,u=l.getSelections();if(d==null||!Array.isArray(u)||u.length===0)return!1;const m=ot(e,a,d,t);return m.params.textRanges=o,!!c.syncExecuteCommand(m.id,m.params)}},nt={id:"doc.command-cover-content",type:i.CommandType.COMMAND,handler:async(r,n)=>{var u;const{unitId:e,body:t,segmentId:o=""}=n,a=r.get(i.IUniverInstanceService),s=r.get(i.ICommandService),c=r.get(i.IUndoRedoService),l=(u=a.getUniverDocInstance(e))==null?void 0:u.getSnapshot().body;if(l==null)return!1;const d=ot(e,o,l,t);return d.params.noNeedSetTextRange=!0,d.params.noHistory=!0,s.syncExecuteCommand(d.id,d.params),c.clearUndoRedo(e),!0}};function ot(r,n,e,t){const o={id:N.id,params:{unitId:r,actions:[],textRanges:[]}},a=new i.TextX,s=(e==null?void 0:e.dataStream.length)-2;return s>0&&a.push({t:i.TextXActionType.DELETE,len:s,line:0,segmentId:n}),t.dataStream.length>0&&a.push({t:i.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:n}),o.params.actions=a.serialize(),o}const te={id:"doc.operation.move-cursor",type:i.CommandType.OPERATION,handler:(r,n)=>!!n},ne={id:"doc.operation.move-selection",type:i.CommandType.OPERATION,handler:(r,n)=>!!n},Lt=(r,n)=>{const e=r.get(i.IUniverInstanceService).getUniverDocInstance(n.unitId),t=(e==null?void 0:e.zoomRatio)||1;return{...i.Tools.deepClone(n),zoomRatio:t}},Y={id:"doc.operation.set-zoom-ratio",type:i.CommandType.OPERATION,handler:(r,n)=>{const e=r.get(i.IUniverInstanceService).getUniverDocInstance(n.unitId);if(!e)return!1;const t=e.getSnapshot();return t.settings==null?t.settings={zoomRatio:n.zoomRatio}:t.settings.zoomRatio=n.zoomRatio,!0}},it={type:i.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(r,n)=>{var m,g,S;const e=r.get(i.ICommandService),t=r.get(i.IUndoRedoService),o=r.get(i.IUniverInstanceService);let a=(m=o.getCurrentUniverDocInstance())==null?void 0:m.getUnitId();if(!a)return!1;let s=1;if(n&&(a=(g=n.documentId)!=null?g:a,s=(S=n.zoomRatio)!=null?S:s),!o.getUniverDocInstance(a))return!1;const l={zoomRatio:s,unitId:a},d=Lt(r,l);return e.syncExecuteCommand(Y.id,l)?(t.pushUndoRedo({unitID:a,undoMutations:[{id:Y.id,params:d}],redoMutations:[{id:Y.id,params:l}]}),!0):!1}},rt={id:"doc.operation.select-all",type:i.CommandType.COMMAND,handler:async r=>{const n=r.get(i.IUniverInstanceService),e=r.get(exports.TextSelectionManagerService),t=n.getCurrentUniverDocInstance();if(!t)return!1;const o=t.getSnapshot().body;if(o==null)return!1;const a=[{startOffset:0,endOffset:o.dataStream.length-2}];return e.replaceTextRanges(a,!1),!0}};var Bt=Object.defineProperty,Ft=Object.getOwnPropertyDescriptor,$t=(r,n,e,t)=>{for(var o=t>1?void 0:t?Ft(n,e):n,a=r.length-1,s;a>=0;a--)(s=r[a])&&(o=(t?s(n,e,o):s(o))||o);return t&&o&&Bt(n,e,o),o},j=(r,n)=>(e,t)=>n(e,t,r);let J=class extends i.Disposable{constructor(n,e,t,o,a){super();T(this,"_previousIMEContent","");T(this,"_isCompositionStart",!0);T(this,"_onStartSubscription");T(this,"_onUpdateSubscription");T(this,"_onEndSubscription");this._docSkeletonManagerService=n,this._univerInstanceService=e,this._textSelectionRenderManager=t,this._imeInputManagerService=o,this._commandService=a,this._initialize()}dispose(){var n,e,t;(n=this._onStartSubscription)==null||n.unsubscribe(),(e=this._onUpdateSubscription)==null||e.unsubscribe(),(t=this._onEndSubscription)==null||t.unsubscribe()}_initialize(){this._initialOnCompositionstart(),this._initialOnCompositionUpdate(),this._initialOnCompositionend()}_initialOnCompositionstart(){this._onStartSubscription=this._textSelectionRenderManager.onCompositionstart$.subscribe(n=>{if(n==null)return;this._resetIME();const{activeRange:e}=n;e!=null&&this._imeInputManagerService.setActiveRange(i.Tools.deepClone(e))})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._textSelectionRenderManager.onCompositionupdate$.subscribe(async n=>{this._updateContent(n,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._textSelectionRenderManager.onCompositionend$.subscribe(n=>{this._updateContent(n,!1)})}async _updateContent(n,e){var d;const t=(d=this._docSkeletonManagerService.getCurrent())==null?void 0:d.skeleton;if(n==null||t==null)return;const o=this._univerInstanceService.getCurrentUniverDocInstance();if(!o)return;const{event:a,activeRange:s}=n;if(t==null||s==null)return;const l=a.data;l===this._previousIMEContent&&e||(await this._commandService.executeCommand(xe.id,{unitId:o.getUnitId(),newText:l,oldTextLen:this._previousIMEContent.length,isCompositionStart:this._isCompositionStart,isCompositionEnd:!e}),e?(this._isCompositionStart&&(this._isCompositionStart=!1),this._previousIMEContent=l):this._resetIME())}_resetIME(){this._previousIMEContent="",this._isCompositionStart=!0,this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(null)}};J=$t([i.OnLifecycle(i.LifecycleStages.Rendered,J),j(0,L.Inject(exports.DocSkeletonManagerService)),j(1,i.IUniverInstanceService),j(2,y.ITextSelectionRenderManager),j(3,L.Inject(W)),j(4,i.ICommandService)],J);var kt=Object.defineProperty,Xt=Object.getOwnPropertyDescriptor,Vt=(r,n,e,t)=>{for(var o=t>1?void 0:t?Xt(n,e):n,a=r.length-1,s;a>=0;a--)(s=r[a])&&(o=(t?s(n,e,o):s(o))||o);return t&&o&&kt(n,e,o),o},G=(r,n)=>(e,t)=>n(e,t,r);let Q=class extends i.Disposable{constructor(n,e,t,o,a){super();T(this,"_onInputSubscription");this._docSkeletonManagerService=n,this._univerInstanceService=e,this._renderManagerService=t,this._textSelectionManagerService=o,this._commandService=a,this._commandExecutedListener()}dispose(){var n;super.dispose(),(n=this._onInputSubscription)==null||n.unsubscribe()}_commandExecutedListener(){const n=[te.id,ne.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!n.includes(e.id))return;const t=e.params;switch(e.id){case te.id:return this._handleMoveCursor(t.direction);case ne.id:return this._handleShiftMoveSelection(t.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(n){var f,p,v;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),o=this._univerInstanceService.getCurrentUniverDocInstance();if(!o)return;const a=(f=this._docSkeletonManagerService.getCurrent())==null?void 0:f.skeleton,s=this._getDocObject();if(e==null||a==null||s==null)return;const{startOffset:c,endOffset:l,style:d,collapsed:u,direction:m}=e;if(t.length>1){let I=Number.POSITIVE_INFINITY,M=Number.NEGATIVE_INFINITY;for(const C of t)I=Math.min(I,C.startOffset),M=Math.max(M,C.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:n===i.Direction.LEFT||n===i.Direction.UP?M:I,endOffset:n===i.Direction.LEFT||n===i.Direction.UP?I:M,style:d}],!1);return}const g=u||m===y.RANGE_DIRECTION.FORWARD?c:l;let S=u||m===y.RANGE_DIRECTION.FORWARD?l:c;const h=(p=o.getBody().dataStream.length)!=null?p:Number.POSITIVE_INFINITY;if(n===i.Direction.LEFT||n===i.Direction.RIGHT){const I=a.findNodeByCharIndex(S-1),M=a.findNodeByCharIndex(S);S=n===i.Direction.RIGHT?S+M.count:S-((v=I==null?void 0:I.count)!=null?v:0),S=Math.min(h-2,Math.max(0,S)),this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:S,style:d}],!1)}else{const I=a.findNodeByCharIndex(S),M=s.document.getOffsetConfig(),C=this._getTopOrBottomPosition(a,I,n===i.Direction.DOWN);if(C==null){const R=n===i.Direction.UP?0:h-2;if(R===S)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:R,style:d}],!1);return}const _=new y.NodePositionConvertToCursor(M,a).getRangePointData(C,C).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:_.endOffset,style:d}],!1)}}_handleMoveCursor(n){var g,S,h;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),o=this._univerInstanceService.getCurrentUniverDocInstance();if(!o)return!1;const a=(g=this._docSkeletonManagerService.getCurrent())==null?void 0:g.skeleton,s=this._getDocObject();if(e==null||a==null||s==null||t==null)return;const{startOffset:c,endOffset:l,style:d,collapsed:u}=e,m=(S=o.getBody().dataStream.length)!=null?S:Number.POSITIVE_INFINITY;if(n===i.Direction.LEFT||n===i.Direction.RIGHT){let f;if(!e.collapsed||t.length>1){let p=Number.POSITIVE_INFINITY,v=Number.NEGATIVE_INFINITY;for(const I of t)p=Math.min(p,I.startOffset),v=Math.max(v,I.endOffset);f=n===i.Direction.LEFT?p:v}else{const p=a.findNodeByCharIndex(c-1),v=a.findNodeByCharIndex(c);n===i.Direction.LEFT?f=Math.max(0,c-((h=p==null?void 0:p.count)!=null?h:0)):f=Math.min(m-2,l+v.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:f,style:d}],!1)}else{const f=a.findNodeByCharIndex(c),p=a.findNodeByCharIndex(l),v=s.document.getOffsetConfig(),I=this._getTopOrBottomPosition(a,n===i.Direction.UP?f:p,n===i.Direction.DOWN);if(I==null){let C;u?C=n===i.Direction.UP?0:m-2:C=n===i.Direction.UP?c:l,this._textSelectionManagerService.replaceTextRanges([{startOffset:C,endOffset:C,style:d}],!1);return}const M=new y.NodePositionConvertToCursor(v,a).getRangePointData(I,I).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...M,style:d}],!1)}}_getTopOrBottomPosition(n,e,t){if(e==null)return;const o=this._getSpanLeftOffsetInLine(e),a=this._getNextOrPrevLine(e,t);if(a==null)return;const s=this._matchPositionByLeftOffset(n,a,o);if(s!=null)return{...s,isBack:!0}}_getSpanLeftOffsetInLine(n){const e=n.parent;if(e==null)return Number.NEGATIVE_INFINITY;const t=e.left,{left:o}=n;return t+o}_matchPositionByLeftOffset(n,e,t){const o={distance:Number.POSITIVE_INFINITY};for(const a of e.divides){const s=a.left;for(const c of a.glyphGroup){const{left:l}=c,d=s+l,u=Math.abs(t-d);u<o.distance&&(o.glyph=c,o.distance=u)}}if(o.glyph!=null)return n.findPositionByGlyph(o.glyph)}_getNextOrPrevLine(n,e){var h,f,p,v,I,M,C,_,R,O,D,U;const t=n.parent;if(t==null)return;const o=t.parent;if(o==null)return;const a=o.parent;if(a==null)return;const s=a.lines.indexOf(o);if(s===-1)return;let c;if(e===!0?c=a.lines[s+1]:c=a.lines[s-1],c!=null)return c;const l=a.parent;if(l==null)return;const d=l.columns.indexOf(a);if(d===-1)return;if(e===!0)c=(h=l.columns[d+1])==null?void 0:h.lines[0];else{const x=(p=(f=l.columns)==null?void 0:f[d-1])==null?void 0:p.lines;c=x==null?void 0:x[x.length-1]}if(c!=null)return c;const u=l.parent;if(u==null)return;const m=u.sections.indexOf(l);if(m===-1)return;if(e===!0)c=(I=(v=u.sections[m-1])==null?void 0:v.columns[0])==null?void 0:I.lines[0];else{const x=(C=(M=u.sections)==null?void 0:M[m-1])==null?void 0:C.columns,E=x==null?void 0:x[x.length-1],A=E==null?void 0:E.lines;c=A==null?void 0:A[A.length-1]}if(c!=null)return c;const g=u.parent;if(g==null)return;const S=g.pages.indexOf(u);if(S!==-1){if(e===!0)c=(O=(R=(_=g.pages[S+1])==null?void 0:_.sections[0])==null?void 0:R.columns[0])==null?void 0:O.lines[0];else{const x=(D=g.pages[S-1])==null?void 0:D.sections;if(x==null)return;const E=(U=x[x.length-1])==null?void 0:U.columns,A=E[E.length-1],$=A==null?void 0:A.lines;c=$[$.length-1]}if(c!=null)return c}}_getDocObject(){return Ve(this._univerInstanceService,this._renderManagerService)}};Q=Vt([i.OnLifecycle(i.LifecycleStages.Rendered,Q),G(0,L.Inject(exports.DocSkeletonManagerService)),G(1,i.IUniverInstanceService),G(2,y.IRenderManagerService),G(3,L.Inject(exports.TextSelectionManagerService)),G(4,i.ICommandService)],Q);var zt=Object.defineProperty,jt=Object.getOwnPropertyDescriptor,Gt=(r,n,e,t)=>{for(var o=t>1?void 0:t?jt(n,e):n,a=r.length-1,s;a>=0;a--)(s=r[a])&&(o=(t?s(n,e,o):s(o))||o);return t&&o&&zt(n,e,o),o},H=(r,n)=>(e,t)=>n(e,t,r);let ee=class extends i.Disposable{constructor(n,e,t,o,a){super();T(this,"_onInputSubscription");this._docSkeletonManagerService=n,this._univerInstanceService=e,this._renderManagerService=t,this._textSelectionRenderManager=o,this._commandService=a,this._init()}dispose(){var n;super.dispose(),(n=this._onInputSubscription)==null||n.unsubscribe()}_init(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async n=>{var h;if(n==null)return;const e=this._univerInstanceService.getCurrentUniverDocInstance();if(!e)return;const t=e.getUnitId(),{event:o,content:a="",activeRange:s}=n,c=o,l=(h=this._docSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(c.data==null||l==null||!l||!s)return;const{startOffset:d,segmentId:u,style:m}=s,g=a.length,S=[{startOffset:d+g,endOffset:d+g,style:m}];await this._commandService.executeCommand(Z.id,{unitId:t,body:{dataStream:a},range:s,textRanges:S,segmentId:u})})}};ee=Gt([i.OnLifecycle(i.LifecycleStages.Rendered,ee),H(0,L.Inject(exports.DocSkeletonManagerService)),H(1,i.IUniverInstanceService),H(2,y.IRenderManagerService),H(3,y.ITextSelectionRenderManager),H(4,i.ICommandService)],ee);var Ht=Object.defineProperty,Yt=Object.getOwnPropertyDescriptor,Wt=(r,n,e,t)=>{for(var o=t>1?void 0:t?Yt(n,e):n,a=r.length-1,s;a>=0;a--)(s=r[a])&&(o=(t?s(n,e,o):s(o))||o);return t&&o&&Ht(n,e,o),o},Zt=(r,n)=>(e,t)=>n(e,t,r);const Kt="docs";var q;exports.UniverDocsPlugin=(q=class extends i.Plugin{constructor(n={},e){super(),this._injector=e,this._initializeDependencies(e),this._initializeCommands()}_initializeCommands(){[te,ne,je,Ge,ie,re,ae,se,V,ce,le,de,ue,ge,me,ye,ze,Z,K,_e,xe,Te,N,tt,nt,it,Y,Ie,rt,Ze,We,Re,qe,Je,Qe,z,et].forEach(n=>{this._injector.get(i.ICommandService).registerCommand(n)})}_initializeDependencies(n){[[exports.DocSkeletonManagerService],[exports.DocViewModelManagerService],[exports.DocStateChangeManagerService],[W],[y.ITextSelectionRenderManager,{useClass:y.TextSelectionRenderManager}],[exports.TextSelectionManagerService],[ee],[J],[Q]].forEach(e=>n.add(e))}},T(q,"pluginName",Kt),T(q,"type",i.UniverInstanceType.UNIVER_DOC),q);exports.UniverDocsPlugin=Wt([Zt(1,L.Inject(L.Injector))],exports.UniverDocsPlugin);exports.AlignCenterCommand=Je;exports.AlignJustifyCommand=et;exports.AlignLeftCommand=qe;exports.AlignOperationCommand=z;exports.AlignRightCommand=Qe;exports.BreakLineCommand=ze;exports.BulletListCommand=We;exports.CoverContentCommand=nt;exports.CutContentCommand=Me;exports.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX=dt;exports.DOCS_COMPONENT_DEFAULT_Z_INDEX=gt;exports.DOCS_COMPONENT_HEADER_LAYER_INDEX=mt;exports.DOCS_COMPONENT_MAIN_LAYER_INDEX=ut;exports.DOCS_VIEW_KEY=oe;exports.DeleteCommand=K;exports.DeleteLeftCommand=je;exports.DeleteRightCommand=Ge;exports.IMEInputCommand=xe;exports.IMEInputManagerService=W;exports.InnerPasteCommand=Nt;exports.InsertCommand=Z;exports.MoveCursorOperation=te;exports.MoveSelectionOperation=ne;exports.NORMAL_TEXT_SELECTION_PLUGIN_NAME=St;exports.OrderListCommand=Ze;exports.ReplaceContentCommand=tt;exports.ResetInlineFormatTextBackgroundColorCommand=ge;exports.RichTextEditingMutation=N;exports.SelectAllOperation=rt;exports.SetDocZoomRatioCommand=it;exports.SetDocZoomRatioOperation=Y;exports.SetInlineFormatBoldCommand=ie;exports.SetInlineFormatCommand=ye;exports.SetInlineFormatFontFamilyCommand=de;exports.SetInlineFormatFontSizeCommand=le;exports.SetInlineFormatItalicCommand=re;exports.SetInlineFormatStrikethroughCommand=se;exports.SetInlineFormatSubscriptCommand=V;exports.SetInlineFormatSuperscriptCommand=ce;exports.SetInlineFormatTextBackgroundColorCommand=me;exports.SetInlineFormatTextColorCommand=ue;exports.SetInlineFormatUnderlineCommand=ae;exports.SetTextSelectionsOperation=Ie;exports.UpdateCommand=_e;exports.VIEWPORT_KEY=Xe;exports.getDocObject=Ve;exports.getDocObjectById=pt;exports.serializeTextRange=X;
1
+ "use strict";var lt=Object.defineProperty;var dt=(r,n,e)=>n in r?lt(r,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[n]=e;var T=(r,n,e)=>(dt(r,typeof n!="symbol"?n+"":n,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),y=require("@univerjs/engine-render"),w=require("rxjs"),L=require("@wendellhu/redi");var oe=(r=>(r.MAIN="__Document_Render_Main__",r.BACKGROUND="__Document_Render_Background__",r))(oe||{}),Ve=(r=>(r.VIEW_MAIN="viewMain",r.VIEW_TOP="viewTop",r.VIEW_LEFT="viewLeft",r.VIEW_LEFT_TOP="viewLeftTop",r))(Ve||{});const ut=0,mt=2,gt=4,St=10,pt="normalTextSelectionPluginName";function je(r,n){const e=r.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC);if(!e)return null;const t=e.getUnitId(),i=n.getRenderById(t);if(i==null)return;const{mainComponent:a,scene:s,engine:c,components:l}=i,d=a,u=l.get(oe.BACKGROUND);return{document:d,docBackground:u,scene:s,engine:c}}function ft(r,n){const e=n.getRenderById(r);if(e==null)return;const{mainComponent:t,scene:i,engine:a,components:s}=e,c=t,l=s.get(oe.BACKGROUND);return{document:c,docBackground:l,scene:i,engine:a}}const Ie={id:"doc.operation.set-selections",type:o.CommandType.OPERATION,handler:(r,n)=>!0};var ht=Object.defineProperty,vt=Object.getOwnPropertyDescriptor,It=(r,n,e,t)=>{for(var i=t>1?void 0:t?vt(n,e):n,a=r.length-1,s;a>=0;a--)(s=r[a])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&ht(n,e,i),i},Ee=(r,n)=>(e,t)=>n(e,t,r);function k(r){const{startOffset:n,endOffset:e,collapsed:t}=r,i={startOffset:n,endOffset:e,collapsed:t};return typeof r.isActive=="function"&&(i.isActive=r.isActive()),i}exports.TextSelectionManagerService=class extends o.RxDisposable{constructor(e,t){super();T(this,"_currentSelection",null);T(this,"_textSelectionInfo",new Map);T(this,"_textSelection$",new w.BehaviorSubject(null));T(this,"textSelection$",this._textSelection$.asObservable());this._textSelectionRenderManager=e,this._commandService=t,this._syncSelectionFromRenderService()}getCurrentSelection(){return this._currentSelection}getCurrentSelectionInfo(){return this._getTextRanges(this._currentSelection)}dispose(){this._textSelection$.complete()}refreshSelection(){this._currentSelection!=null&&this._refresh(this._currentSelection)}setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}setCurrentSelectionNotRefresh(e){this._currentSelection=e}getSelections(){var e;return(e=this._getTextRanges(this._currentSelection))==null?void 0:e.textRanges}getActiveTextRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:t}=e;return t.find(i=>i.isActive())}getActiveRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:t,segmentId:i,style:a}=e,s=t.find(S=>S.isActive());if(s==null)return null;const{startOffset:c,endOffset:l,collapsed:d,startNodePosition:u,endNodePosition:g,direction:m}=s;return c==null||l==null?null:{startOffset:c,endOffset:l,collapsed:d,startNodePosition:u,endNodePosition:g,direction:m,segmentId:i,style:a}}add(e,t=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,segmentId:"",isEditing:t,style:y.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e,t=!0){this._currentSelection!=null&&(this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges(e,t))}_syncSelectionFromRenderService(){this._textSelectionRenderManager.textSelectionInner$.pipe(w.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._replaceTextRangesWithNoRefresh(e)})}_replaceTextRangesWithNoRefresh(e){if(this._currentSelection==null)return;const t={...this._currentSelection,...e};this._replaceByParam(t),this._textSelection$.next(t);const{unitId:i,subUnitId:a,segmentId:s,style:c,textRanges:l,isEditing:d}=t;this._commandService.executeCommand(Ie.id,{unitId:i,subUnitId:a,segmentId:s,style:c,isEditing:d,ranges:l.map(k)})}_getTextRanges(e){var a;if(e==null)return;const{unitId:t,subUnitId:i=""}=e;return(a=this._textSelectionInfo.get(t))==null?void 0:a.get(i)}_refresh(e){const t=this._getTextRanges(e);this._textSelectionRenderManager.removeAllTextRanges(),t&&Array.isArray(t.textRanges)&&t.textRanges.length&&this._textSelectionRenderManager.addTextRanges(t.textRanges.map(k))}_replaceByParam(e){const{unitId:t,subUnitId:i,style:a,segmentId:s,textRanges:c,isEditing:l}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(i,{textRanges:c,style:a,segmentId:s,isEditing:l})}_addByParam(e){const{unitId:t,subUnitId:i,textRanges:a,style:s,segmentId:c,isEditing:l}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);const d=this._textSelectionInfo.get(t);d.has(i)?d.get(i).textRanges.push(...a):d.set(i,{textRanges:a,style:s,segmentId:c,isEditing:l})}};exports.TextSelectionManagerService=It([Ee(0,y.ITextSelectionRenderManager),Ee(1,o.ICommandService)],exports.TextSelectionManagerService);function Ce(r,n="",e=0){const{startOffset:t,endOffset:i}=r,a=[],s=t-e,c=i-e;return s>0&&a.push({t:o.TextXActionType.RETAIN,len:s,segmentId:n}),a.push({t:o.TextXActionType.DELETE,len:c-s,line:0,segmentId:n}),a}var Ct=Object.defineProperty,_t=Object.getOwnPropertyDescriptor,Mt=(r,n,e,t)=>{for(var i=t>1?void 0:t?_t(n,e):n,a=r.length-1,s;a>=0;a--)(s=r[a])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&Ct(n,e,i),i},Tt=(r,n)=>(e,t)=>n(e,t,r);exports.DocViewModelManagerService=class extends o.RxDisposable{constructor(e){super();T(this,"_docViewModelMap",new Map);T(this,"_currentDocViewModel$",new w.BehaviorSubject(null));T(this,"currentDocViewModel$",this._currentDocViewModel$.asObservable());this._univerInstanceService=e,this._initialize()}_initialize(){this._init()}dispose(){this._currentDocViewModel$.complete(),this._docViewModelMap.clear()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_DOC).pipe(w.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)}),this._univerInstanceService.getAllUnitsForType(o.UniverInstanceType.UNIVER_DOC).forEach(e=>{this._create(e)}),this._univerInstanceService.getTypeOfUnitDisposed$(o.UniverInstanceType.UNIVER_DOC).pipe(w.takeUntil(this.dispose$)).subscribe(e=>{this._docViewModelMap.delete(e.getUnitId())})}_create(e){if(e==null)return;const t=e.getUnitId();this._setCurrent(t)}getAllModel(){return this._docViewModelMap}getViewModel(e){var t;return(t=this._docViewModelMap.get(e))==null?void 0:t.docViewModel}_setCurrent(e){var i;const t=this._univerInstanceService.getUniverDocInstance(e);if(t==null)throw new Error(`Document data model with id ${e} not found when build view model.`);if(t.getBody()!=null){if(!this._docViewModelMap.has(e)){const a=this._buildDocViewModel(t);this._docViewModelMap.set(e,{unitId:e,docViewModel:a})}if(e===o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY){const a=(i=this._docViewModelMap.get(e))==null?void 0:i.docViewModel;if(a==null)return;a.reset(t)}this._currentDocViewModel$.next(this._docViewModelMap.get(e))}}_buildDocViewModel(e){return new y.DocumentViewModel(e)}};exports.DocViewModelManagerService=Mt([Tt(0,o.IUniverInstanceService)],exports.DocViewModelManagerService);var xt=Object.defineProperty,yt=Object.getOwnPropertyDescriptor,Ot=(r,n,e,t)=>{for(var i=t>1?void 0:t?yt(n,e):n,a=r.length-1,s;a>=0;a--)(s=r[a])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&xt(n,e,i),i},he=(r,n)=>(e,t)=>n(e,t,r);const Rt=300;exports.DocStateChangeManagerService=class extends o.RxDisposable{constructor(e,t,i){super();T(this,"_docStateChange$",new w.BehaviorSubject(null));T(this,"docStateChange$",this._docStateChange$.asObservable());T(this,"_stateCache",new Map);T(this,"_timer",null);this._undoRedoService=e,this._commandService=t,this._univerInstanceService=i,this._initialize()}setChangeState(e){const{trigger:t,noHistory:i}=e;t!=null&&(this._cacheChangeState(e),i||this._docStateChange$.next(e))}_initialize(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===o.UndoCommandId||e.id===o.RedoCommandId){const t=this._univerInstanceService.getCurrentUniverDocInstance();if(t==null)return;const i=t.getUnitId();this._pushHistory(i)}}))}_cacheChangeState(e){const{trigger:t,unitId:i,noHistory:a}=e;if(!(t===o.RedoCommandId||t===o.UndoCommandId||a)){if(this._stateCache.has(i)){const s=this._stateCache.get(i);s==null||s.push(e)}else this._stateCache.set(i,[e]);t===W.id||t===Z.id?(this._timer&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._pushHistory(i)},Rt)):this._pushHistory(i)}}_pushHistory(e){const t=this._undoRedoService,i=this._stateCache.get(e);if(!Array.isArray(i)||i.length===0)return;const a=i.length,s=i[0].commandId,c=i[0],l=i[a-1],d={unitId:e,actions:i.reduce((g,m)=>o.JSONX.compose(g,m.redoState.actions),null),textRanges:l.redoState.textRanges},u={unitId:e,actions:i.reverse().reduce((g,m)=>o.JSONX.compose(g,m.undoState.actions),null),textRanges:c.undoState.textRanges};t.pushUndoRedo({unitID:e,undoMutations:[{id:s,params:u}],redoMutations:[{id:s,params:d}]}),i.length=0}};exports.DocStateChangeManagerService=Ot([he(0,L.Inject(o.IUndoRedoService)),he(1,o.ICommandService),he(2,o.IUniverInstanceService)],exports.DocStateChangeManagerService);class Y{constructor(){T(this,"_previousActiveRange",null);T(this,"_undoMutationParamsCache",[]);T(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache:n=[],redoCache:e=[]}){this._undoMutationParamsCache=n,this._redoMutationParamsCache=e}getActiveRange(){return this._previousActiveRange}setActiveRange(n){this._previousActiveRange=n}pushUndoRedoMutationParams(n,e){this._undoMutationParamsCache.push(n),this._redoMutationParamsCache.push(e)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:n}=this._undoMutationParamsCache[0],e={unitId:n,actions:this._undoMutationParamsCache.reverse().reduce((i,a)=>o.JSONX.compose(i,a.actions),null),textRanges:[]};return{redoMutationParams:{unitId:n,actions:this._redoMutationParamsCache.reduce((i,a)=>o.JSONX.compose(i,a.actions),null),textRanges:[]},undoMutationParams:e,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Ae="doc.mutation.rich-text-editing",N={id:Ae,type:o.CommandType.MUTATION,handler:(r,n)=>{var U;const{unitId:e,segmentId:t="",actions:i,textRanges:a,prevTextRanges:s,trigger:c,noHistory:l,isCompositionEnd:d,noNeedSetTextRange:u}=n,m=r.get(o.IUniverInstanceService).getUniverDocInstance(e),v=r.get(exports.DocViewModelManagerService).getViewModel(e),p=r.get(exports.TextSelectionManagerService),I=((U=p.getSelections())!=null?U:[]).map(k),h=r.get(exports.DocStateChangeManagerService),M=r.get(Y);if(m==null||v==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const _=!!m.getSnapshot().disabled;if(o.JSONX.isNoop(i)||i&&i.length===0||_)return{unitId:e,actions:[],textRanges:I};const C=o.JSONX.invertWithDoc(i,m.getSnapshot());m.apply(i);const R=m.getSelfOrHeaderFooterModel(t);v.getSelfOrHeaderFooterViewModel(t).reset(R),!u&&a&&c!=null&&queueMicrotask(()=>{p.replaceTextRanges(a)});const D={commandId:Ae,unitId:e,segmentId:t,trigger:c,noHistory:l,redoState:{actions:i,textRanges:a},undoState:{actions:C,textRanges:s!=null?s:I}};if(d){const x=M.fetchComposedUndoRedoMutationParams();if(x==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:E,redoMutationParams:A,previousActiveRange:X}=x;D.redoState.actions=A.actions,D.undoState.actions=E.actions,D.undoState.textRanges=[X]}return h.setChangeState(D),{unitId:e,actions:C,textRanges:I}}},W={id:"doc.command.insert-text",type:o.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(o.ICommandService),{range:t,segmentId:i,body:a,unitId:s,textRanges:c}=n,{startOffset:l,collapsed:d}=t,u={id:N.id,params:{unitId:s,actions:[],textRanges:c}},g=new o.TextX,m=o.JSONX.getInstance();return d?l>0&&g.push({t:o.TextXActionType.RETAIN,len:l,segmentId:i}):g.push(...Ce(t,i)),g.push({t:o.TextXActionType.INSERT,body:a,len:a.dataStream.length,line:0,segmentId:i}),u.params.actions=m.editOp(g.serialize()),!!e.syncExecuteCommand(u.id,u.params)}};var F=(r=>(r[r.LEFT=0]="LEFT",r[r.RIGHT=1]="RIGHT",r))(F||{});const Z={id:"doc.command.delete-text",type:o.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(o.ICommandService),{range:t,segmentId:i,unitId:a,direction:s,textRanges:c,len:l=1}=n,{startOffset:d}=t,u={id:N.id,params:{unitId:a,actions:[],textRanges:c}},g=new o.TextX,m=o.JSONX.getInstance();return d>0&&g.push({t:o.TextXActionType.RETAIN,len:s===0?d-l:d,segmentId:i}),g.push({t:o.TextXActionType.DELETE,len:l,line:0,segmentId:i}),u.params.actions=m.editOp(g.serialize()),!!e.syncExecuteCommand(u.id,u.params)}},_e={id:"doc.command.update-text",type:o.CommandType.COMMAND,handler:async(r,n)=>{const{range:e,segmentId:t,updateBody:i,coverType:a,unitId:s,textRanges:c}=n,l=r.get(o.ICommandService),d={id:N.id,params:{unitId:s,actions:[],textRanges:c}},u=new o.TextX,g=o.JSONX.getInstance(),{startOffset:m,endOffset:S}=e;return u.push({t:o.TextXActionType.RETAIN,len:m,segmentId:t}),u.push({t:o.TextXActionType.RETAIN,body:i,len:S-m,segmentId:t,coverType:a}),d.params.actions=g.editOp(u.serialize()),!!l.syncExecuteCommand(d.id,d.params)}};function Dt(r,n){const e=[];for(let t=0,i=r.length;t<i;t++)r[t]===o.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});if(n)for(const t of e)n.bullet&&(t.bullet=o.Tools.deepClone(n.bullet)),n.paragraphStyle&&(t.paragraphStyle=o.Tools.deepClone(n.paragraphStyle));return e}const ze={id:"doc.command.break-line",type:o.CommandType.COMMAND,handler:async r=>{var v,p;const n=r.get(exports.TextSelectionManagerService),e=r.get(o.IUniverInstanceService),t=r.get(o.ICommandService),i=n.getActiveRange();if(i==null)return!1;const a=e.getCurrentUniverDocInstance();if(!a)return!1;const s=a.getUnitId(),{startOffset:c,segmentId:l,style:d}=i,u=[{startOffset:c+1,endOffset:c+1,style:d}],m=((p=(v=a.getBody())==null?void 0:v.paragraphs)!=null?p:[]).find(f=>f.startIndex>=c);return await t.executeCommand(W.id,{unitId:s,body:{dataStream:o.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Dt(o.DataStreamTreeTokenType.PARAGRAPH,m)},range:i,textRanges:u,segmentId:l})}};var Et=Object.defineProperty,At=Object.getOwnPropertyDescriptor,Nt=(r,n,e,t)=>{for(var i=t>1?void 0:t?At(n,e):n,a=r.length-1,s;a>=0;a--)(s=r[a])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&Et(n,e,i),i},ve=(r,n)=>(e,t)=>n(e,t,r);exports.DocSkeletonManagerService=class extends o.RxDisposable{constructor(e,t,i){super();T(this,"_currentSkeletonUnitId","");T(this,"_docSkeletonMap",new Map);T(this,"_currentSkeleton$",new w.BehaviorSubject(null));T(this,"currentSkeleton$",this._currentSkeleton$.asObservable());T(this,"_currentSkeletonBefore$",new w.BehaviorSubject(null));T(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._localeService=e,this._docViewModelManagerService=t,this._univerInstanceService=i,this._initialize()}_initialize(){this._init()}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._docSkeletonMap.clear()}_init(){this._docViewModelManagerService.currentDocViewModel$.pipe(w.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._setCurrent(e)}),this._docViewModelManagerService.getAllModel().forEach(e=>{e!=null&&this._setCurrent(e)}),this._univerInstanceService.getTypeOfUnitDisposed$(o.UniverInstanceType.UNIVER_DOC).pipe(w.takeUntil(this.dispose$)).subscribe(e=>{var t,i;this._docSkeletonMap.delete(e.getUnitId()),this._currentSkeletonUnitId=(i=(t=this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC))==null?void 0:t.getUnitId())!=null?i:""})}getCurrent(){return this.getSkeletonByUnitId(this._currentSkeletonUnitId)}getAllSkeleton(){return this._docSkeletonMap}makeDirtyCurrent(e=!0){this.makeDirty(this._currentSkeletonUnitId,e)}makeDirty(e,t=!0){const i=this.getSkeletonByUnitId(e);i!=null&&(i.dirty=t)}getSkeletonByUnitId(e){return this._docSkeletonMap.get(e)}_setCurrent(e){const{unitId:t}=e;if(this._docSkeletonMap.has(t)){const i=this.getSkeletonByUnitId(t);i.skeleton.calculate(),i.dirty=!0}else{const i=this._buildSkeleton(e.docViewModel);i.calculate(),this._docSkeletonMap.set(t,{unitId:t,skeleton:i,dirty:!1})}return this._currentSkeletonUnitId=t,this._currentSkeletonBefore$.next(this.getCurrent()),this._currentSkeleton$.next(this.getCurrent()),this.getCurrent()}_buildSkeleton(e){return y.DocumentSkeleton.create(e,this._localeService)}};exports.DocSkeletonManagerService=Nt([ve(0,L.Inject(o.LocaleService)),ve(1,L.Inject(exports.DocViewModelManagerService)),ve(2,o.IUniverInstanceService)],exports.DocSkeletonManagerService);const Ut={id:"doc.command.inner-paste",type:o.CommandType.COMMAND,handler:async(r,n)=>{const{segmentId:e,body:t,textRanges:i}=n,a=r.get(o.ICommandService),s=r.get(exports.TextSelectionManagerService),c=r.get(o.IUniverInstanceService),l=s.getSelections();if(!Array.isArray(l)||l.length===0)return!1;const d=c.getCurrentUniverDocInstance();if(!d)return!1;const u=d.getUnitId(),g={id:N.id,params:{unitId:u,actions:[],textRanges:i}},m=new o.MemoryCursor;m.reset();const S=new o.TextX,v=o.JSONX.getInstance();for(const f of l){const{startOffset:I,endOffset:h,collapsed:M}=f,_=I-m.cursor;M?S.push({t:o.TextXActionType.RETAIN,len:_,segmentId:e}):S.push(...Ce(f,e,m.cursor)),S.push({t:o.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:e}),m.reset(),m.moveCursor(h)}return g.params.actions=v.editOp(S.serialize()),!!a.syncExecuteCommand(g.id,g.params)}},Me={id:"doc.command.inner-cut",type:o.CommandType.COMMAND,handler:async(r,n)=>{var f;const{segmentId:e,textRanges:t}=n,i=r.get(o.ICommandService),a=r.get(exports.TextSelectionManagerService),s=r.get(o.IUniverInstanceService),c=a.getSelections();if(!Array.isArray(c)||c.length===0)return!1;const l=(f=s.getCurrentUniverDocInstance())==null?void 0:f.getUnitId();if(!l)return!1;const d=s.getUniverDocInstance(l),u=o.getDocsUpdateBody(d.getSnapshot(),e);if(u==null)return!1;const g={id:N.id,params:{unitId:l,actions:[],textRanges:t}},m=new o.MemoryCursor;m.reset();const S=new o.TextX,v=o.JSONX.getInstance();for(const I of c){const{startOffset:h,endOffset:M,collapsed:_}=I,C=h-m.cursor;_?S.push({t:o.TextXActionType.RETAIN,len:C,segmentId:e}):S.push(...bt(I,u,e,m.cursor)),m.reset(),m.moveCursor(M)}return g.params.actions=v.editOp(S.serialize()),!!i.syncExecuteCommand(g.id,g.params)}};function bt(r,n,e="",t=0){const{startOffset:i,endOffset:a}=r,s=[],{paragraphs:c=[]}=n,l=i-t,d=a-t,u=c==null?void 0:c.find(g=>g.startIndex-t>=l&&g.startIndex-t<=d);if(l>0&&s.push({t:o.TextXActionType.RETAIN,len:l,segmentId:e}),u&&u.startIndex-t>l){const g=u.startIndex-t;s.push({t:o.TextXActionType.DELETE,len:g-l,line:0,segmentId:e}),s.push({t:o.TextXActionType.RETAIN,len:1,segmentId:e}),d>g+1&&s.push({t:o.TextXActionType.DELETE,len:d-g-1,line:0,segmentId:e})}else s.push({t:o.TextXActionType.DELETE,len:d-l,line:0,segmentId:e});return s}const Ge={id:"doc.command.delete-left",type:o.CommandType.COMMAND,handler:async r=>{var _;const n=r.get(exports.TextSelectionManagerService),e=r.get(exports.DocSkeletonManagerService),t=r.get(o.IUniverInstanceService),i=r.get(o.ICommandService),a=n.getActiveRange(),s=n.getSelections(),c=(_=e.getCurrent())==null?void 0:_.skeleton;let l=!0;if(a==null||c==null||s==null)return!1;const d=t.getCurrentUniverDocInstance();if(!d)return!1;const{startOffset:u,collapsed:g,segmentId:m,style:S}=a,v=c.findNodeByCharIndex(u),p=y.hasListGlyph(v),f=y.isIndentByGlyph(v,d.getBody());let I=u;const h=c.findNodeByCharIndex(u-1);if(y.isFirstGlyph(v)&&h!==v&&(p===!0||f===!0)&&g){const C=y.getParagraphByGlyph(v,d.getBody());if(C==null)return!1;const R=C==null?void 0:C.startIndex,O={startIndex:0},D=C.paragraphStyle;if(p===!0){const x=C.paragraphStyle;if(x){O.paragraphStyle=x;const{hanging:E}=x;E&&(O.paragraphStyle.indentStart=E,O.paragraphStyle.hanging=void 0)}}else if(f===!0){const x=C.bullet;x&&(O.bullet=x),D!=null&&(O.paragraphStyle={...D},delete O.paragraphStyle.hanging,delete O.paragraphStyle.indentStart)}const U=[{startOffset:I,endOffset:I,style:S}];l=await i.executeCommand(_e.id,{unitId:d.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...O}]},range:{startOffset:R,endOffset:R+1},textRanges:U,coverType:o.UpdateDocsAttributeType.REPLACE,segmentId:m})}else if(g===!0){if(h==null)return!0;if(h.content==="\r")l=await i.executeCommand(Te.id,{direction:F.LEFT,range:a});else{I-=h.count;const C=[{startOffset:I,endOffset:I,style:S}];l=await i.executeCommand(Z.id,{unitId:d.getUnitId(),range:a,segmentId:m,direction:F.LEFT,len:h.count,textRanges:C})}}else{const C=Je(a,s);l=await i.executeCommand(Me.id,{segmentId:m,textRanges:C})}return l}},He={id:"doc.command.delete-right",type:o.CommandType.COMMAND,handler:async r=>{var v;const n=r.get(exports.TextSelectionManagerService),e=r.get(exports.DocSkeletonManagerService),t=r.get(o.IUniverInstanceService),i=r.get(o.ICommandService),a=n.getActiveRange(),s=n.getSelections(),c=(v=e.getCurrent())==null?void 0:v.skeleton;let l;if(a==null||c==null||s==null)return!1;const d=t.getCurrentUniverDocInstance();if(!d)return!1;const{startOffset:u,collapsed:g,segmentId:m,style:S}=a;if(u===d.getBody().dataStream.length-2&&g)return!0;if(g===!0){const p=c.findNodeByCharIndex(u);if(p.content==="\r")l=await i.executeCommand(Te.id,{direction:F.RIGHT,range:a});else{const f=[{startOffset:u,endOffset:u,style:S}];l=await i.executeCommand(Z.id,{unitId:d.getUnitId(),range:a,segmentId:m,direction:F.RIGHT,textRanges:f,len:p.count})}}else{const p=Je(a,s);l=await i.executeCommand(Me.id,{segmentId:m,textRanges:p})}return l}},Te={id:"doc.command.merge-two-paragraph",type:o.CommandType.COMMAND,handler:async(r,n)=>{var D,U,x;const e=r.get(exports.TextSelectionManagerService),t=r.get(o.IUniverInstanceService),i=r.get(o.ICommandService),{direction:a,range:s}=n,c=e.getActiveRange(),l=e.getSelections();if(c==null||l==null)return!1;const d=t.getCurrentUniverDocInstance();if(!d)return!1;const{startOffset:u,collapsed:g,segmentId:m,style:S}=c;if(!g)return!1;const v=a===F.LEFT?u:u+1,p=(x=(U=(D=d.getBody())==null?void 0:D.paragraphs)==null?void 0:U.find(E=>E.startIndex>=v))==null?void 0:x.startIndex,f=Pt(d.getBody(),v,p),I=a===F.LEFT?u-1:u,h=d.getUnitId(),M=[{startOffset:I,endOffset:I,style:S}],_={id:N.id,params:{unitId:h,actions:[],textRanges:M,prevTextRanges:[s]}},C=new o.TextX,R=o.JSONX.getInstance();return C.push({t:o.TextXActionType.RETAIN,len:a===F.LEFT?u-1:u,segmentId:m}),f.dataStream.length&&C.push({t:o.TextXActionType.INSERT,body:f,len:f.dataStream.length,line:0,segmentId:m}),C.push({t:o.TextXActionType.RETAIN,len:1,segmentId:m}),C.push({t:o.TextXActionType.DELETE,len:p+1-v,line:0,segmentId:m}),_.params.actions=R.editOp(C.serialize()),!!i.syncExecuteCommand(_.id,_.params)}};function Pt(r,n,e){const{textRuns:t}=r,i=r.dataStream.substring(n,e);if(t==null)return{dataStream:i};const a=[];for(const s of t){const{st:c,ed:l}=s;l<=n||c>=e||(c<n?a.push({...s,st:0,ed:l-n}):l>e?a.push({...s,st:c-n,ed:e-n}):a.push({...s,st:c-n,ed:l-n}))}return{dataStream:i,textRuns:a}}function Je(r,n){let e=r.endOffset;for(const i of n){const{startOffset:a,endOffset:s}=i;a==null||s==null||s<=r.endOffset&&(e-=s-a)}return[{startOffset:e,endOffset:e,style:r.style}]}const xe={id:"doc.command.ime-input",type:o.CommandType.COMMAND,handler:async(r,n)=>{const{unitId:e,newText:t,oldTextLen:i,isCompositionEnd:a,isCompositionStart:s}=n,c=r.get(o.ICommandService),l=r.get(Y),d=l.getActiveRange();if(d==null)return!1;const{startOffset:u,style:g,segmentId:m}=d,S=t.length,v=[{startOffset:u+S,endOffset:u+S,collapsed:!0,style:g}],p={id:N.id,params:{unitId:e,actions:[],textRanges:v}},f=new o.TextX,I=o.JSONX.getInstance();!d.collapsed&&s?f.push(...Ce(d,m)):f.push({t:o.TextXActionType.RETAIN,len:u,segmentId:m}),i>0&&f.push({t:o.TextXActionType.DELETE,len:i,line:0,segmentId:m}),f.push({t:o.TextXActionType.INSERT,body:{dataStream:t},len:t.length,line:0,segmentId:m}),p.params.actions=I.editOp(f.serialize()),p.params.noHistory=!a,p.params.isCompositionEnd=a;const h=c.syncExecuteCommand(p.id,p.params);return l.pushUndoRedoMutationParams(h,p.params),!!h}};function b(r,n,e,t){var a;const{segmentId:i}=(a=e.getActiveRange())!=null?a:{};return i==null?!1:t.executeCommand(ye.id,{segmentId:i,preCommandId:r,...n!=null?n:{}})}const Ne="doc.command.set-inline-format-bold",ie={id:Ne,type:o.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(o.ICommandService),t=r.get(exports.TextSelectionManagerService);return b(Ne,n,t,e)}},Ue="doc.command.set-inline-format-italic",re={id:Ue,type:o.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(o.ICommandService),t=r.get(exports.TextSelectionManagerService);return b(Ue,n,t,e)}},be="doc.command.set-inline-format-underline",ae={id:be,type:o.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(o.ICommandService),t=r.get(exports.TextSelectionManagerService);return b(be,n,t,e)}},Pe="doc.command.set-inline-format-strikethrough",se={id:Pe,type:o.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(o.ICommandService),t=r.get(exports.TextSelectionManagerService);return b(Pe,n,t,e)}},we="doc.command.set-inline-format-subscript",V={id:we,type:o.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(o.ICommandService),t=r.get(exports.TextSelectionManagerService);return b(we,n,t,e)}},Le="doc.command.set-inline-format-superscript",ce={id:Le,type:o.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(o.ICommandService),t=r.get(exports.TextSelectionManagerService);return b(Le,n,t,e)}},Be="doc.command.set-inline-format-fontsize",le={id:Be,type:o.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(o.ICommandService),t=r.get(exports.TextSelectionManagerService);return b(Be,n,t,e)}},Fe="doc.command.set-inline-format-font-family",de={id:Fe,type:o.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(o.ICommandService),t=r.get(exports.TextSelectionManagerService);return b(Fe,n,t,e)}},Xe="doc.command.set-inline-format-text-color",ue={id:Xe,type:o.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(o.ICommandService),t=r.get(exports.TextSelectionManagerService);return b(Xe,n,t,e)}},$e="doc.command.set-inline-format-text-background-color",me={id:$e,type:o.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(o.ICommandService),t=r.get(exports.TextSelectionManagerService);return b($e,n,t,e)}},ke="doc.command.reset-inline-format-text-background-color",ge={id:ke,type:o.CommandType.COMMAND,handler:async(r,n)=>{const e=r.get(o.ICommandService),t=r.get(exports.TextSelectionManagerService);return b(ke,n,t,e)}},Ye={[ie.id]:"bl",[re.id]:"it",[ae.id]:"ul",[se.id]:"st",[le.id]:"fs",[de.id]:"ff",[ue.id]:"cl",[me.id]:"bg",[ge.id]:"bg",[V.id]:"va",[ce.id]:"va"},ye={id:"doc.command.set-inline-format",type:o.CommandType.COMMAND,handler:async(r,n)=>{const{segmentId:e,value:t,preCommandId:i}=n,a=r.get(o.ICommandService),s=r.get(exports.TextSelectionManagerService),c=r.get(o.IUniverInstanceService),l=s.getSelections();if(!Array.isArray(l)||l.length===0)return!1;let d=c.getCurrentUniverDocInstance();if(!d)return!1;let u=d.getUnitId();u===o.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(d=c.getUniverDocInstance(o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),u=d.getUnitId());let g;switch(i){case ie.id:case re.id:case ae.id:case se.id:case V.id:case ce.id:{g=Lt(d.getBody().textRuns,i,l);break}case le.id:case de.id:{g=t;break}case ue.id:case me.id:{g={rgb:t};break}case ge.id:{g={rgb:null};break}default:throw new Error(`Unknown command: ${i} in handleInlineFormat`)}const m={id:N.id,params:{unitId:u,actions:[],textRanges:l.map(k)}},S=new o.TextX,v=o.JSONX.getInstance(),p=new o.MemoryCursor;p.reset();for(const I of l){const{startOffset:h,endOffset:M}=I,_={dataStream:"",textRuns:[{st:0,ed:M-h,ts:{[Ye[i]]:g}}]},C=h-p.cursor;C!==0&&S.push({t:o.TextXActionType.RETAIN,len:C,segmentId:e}),S.push({t:o.TextXActionType.RETAIN,body:_,len:M-h,segmentId:e}),p.reset(),p.moveCursor(M)}return m.params.actions=v.editOp(S.serialize()),!!a.syncExecuteCommand(m.id,m.params)}};function wt(r){return r!==null&&typeof r=="object"}function Lt(r,n,e){let t=0,i=0;const a=Ye[n];for(;t!==r.length&&i!==e.length;){const{startOffset:s,endOffset:c}=e[i],{st:l,ed:d,ts:u}=r[t];if(c<=l)i++;else if(d<=s)t++;else{if(/bl|it/.test(a))return(u==null?void 0:u[a])===o.BooleanNumber.TRUE?o.BooleanNumber.FALSE:o.BooleanNumber.TRUE;if(/ul|st/.test(a))return wt(u==null?void 0:u[a])&&(u==null?void 0:u[a]).s===o.BooleanNumber.TRUE?{s:o.BooleanNumber.FALSE}:{s:o.BooleanNumber.TRUE};if(/va/.test(a))return n===V.id?(u==null?void 0:u[a])===o.BaselineOffset.SUBSCRIPT?o.BaselineOffset.NORMAL:o.BaselineOffset.SUBSCRIPT:(u==null?void 0:u[a])===o.BaselineOffset.SUPERSCRIPT?o.BaselineOffset.NORMAL:o.BaselineOffset.SUPERSCRIPT;t++}}return/bl|it/.test(a)?o.BooleanNumber.TRUE:/ul|st/.test(a)?{s:o.BooleanNumber.TRUE}:n===V.id?o.BaselineOffset.SUBSCRIPT:o.BaselineOffset.SUPERSCRIPT}const Oe={id:"doc.command.list-operation",type:o.CommandType.COMMAND,handler:(r,n)=>{var E,A,X,Re;const e=r.get(exports.TextSelectionManagerService),t=r.get(o.IUniverInstanceService),i=r.get(o.ICommandService),{listType:a}=n,s=t.getCurrentUniverDocInstance();if(!s)return!1;const c=e.getActiveRange(),l=(E=e.getSelections())!=null?E:[],d=(A=s.getBody())==null?void 0:A.paragraphs,u=l.map(k);if(c==null||d==null)return!1;const g=Ke(c,d),{segmentId:m}=c,S=s.getUnitId(),v=g.every($=>{var P;return((P=$.bullet)==null?void 0:P.listType)===a});let f=o.Tools.generateRandomId(6);if(g.length===1){const $=d.indexOf(g[0]),P=d[$-1],B=d[$+1];P&&P.bullet&&P.bullet.listType===a?f=P.bullet.listId:B&&B.bullet&&B.bullet.listType===a&&(f=B.bullet.listId)}const I={id:N.id,params:{unitId:S,actions:[],textRanges:u}},h=new o.MemoryCursor;h.reset();const M=new o.TextX,_=o.JSONX.getInstance(),C=(X=s.getSnapshot().lists)!=null?X:{},R={...o.PRESET_LIST_TYPE,...C},{charSpace:O,defaultTabStop:D=36,gridType:U}=s.getSnapshot().documentStyle;for(const $ of g){const{startIndex:P,paragraphStyle:B={}}=$,{indentFirstLine:st=0,snapToGrid:ct,indentStart:Se=0}=B,{hanging:pe,indentStart:De}=R[a].nestingLevel[0],fe=y.getCharSpaceApply(O,D,U,ct);M.push({t:o.TextXActionType.RETAIN,len:P-h.cursor,segmentId:m}),M.push({t:o.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[v?{paragraphStyle:{...B,hanging:void 0,indentStart:Se?Math.max(0,y.getNumberUnitValue(Se,fe)+pe-De):void 0},startIndex:0}:{startIndex:0,paragraphStyle:{...B,indentFirstLine:void 0,hanging:pe,indentStart:De-pe+y.getNumberUnitValue(st,fe)+y.getNumberUnitValue(Se,fe)},bullet:{...(Re=$.bullet)!=null?Re:{nestingLevel:0,textStyle:{fs:20}},listType:a,listId:f}}]},segmentId:m,coverType:o.UpdateDocsAttributeType.REPLACE}),h.moveCursorTo(P+1)}return I.params.actions=_.editOp(M.serialize()),!!i.syncExecuteCommand(I.id,I.params)}},We={id:"doc.command.bullet-list",type:o.CommandType.COMMAND,handler:r=>r.get(o.ICommandService).syncExecuteCommand(Oe.id,{listType:o.PresetListType.BULLET_LIST})},Ze={id:"doc.command.order-list",type:o.CommandType.COMMAND,handler:r=>r.get(o.ICommandService).syncExecuteCommand(Oe.id,{listType:o.PresetListType.ORDER_LIST})};function Ke(r,n){const{startOffset:e,endOffset:t}=r,i=[];let a=-1;for(const s of n){const{startIndex:c}=s;(e>a&&e<=c||t>a&&t<=c||c>=e&&c<=t)&&i.push(s),a=c}return i}const j={id:"doc.command.align-operation",type:o.CommandType.COMMAND,handler:(r,n)=>{var _,C;const e=r.get(exports.TextSelectionManagerService),t=r.get(o.IUniverInstanceService),i=r.get(o.ICommandService),{alignType:a}=n,s=t.getCurrentUniverDocInstance();if(!s)return!1;const c=e.getActiveRange(),l=(_=e.getSelections())!=null?_:[],d=(C=s.getBody())==null?void 0:C.paragraphs,u=l.map(k);if(c==null||d==null)return!1;const g=Ke(c,d),{segmentId:m}=c,S=s.getUnitId(),v=g.every(R=>{var O;return((O=R.paragraphStyle)==null?void 0:O.horizontalAlign)===a}),p={id:N.id,params:{unitId:S,actions:[],textRanges:u}},f=new o.MemoryCursor;f.reset();const I=new o.TextX,h=o.JSONX.getInstance();for(const R of g){const{startIndex:O}=R;I.push({t:o.TextXActionType.RETAIN,len:O-f.cursor,segmentId:m});const D={...R.paragraphStyle,horizontalAlign:v?o.HorizontalAlign.UNSPECIFIED:a};I.push({t:o.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...R,paragraphStyle:D,startIndex:0}]},segmentId:m,coverType:o.UpdateDocsAttributeType.REPLACE}),f.moveCursorTo(O+1)}return p.params.actions=h.editOp(I.serialize()),!!i.syncExecuteCommand(p.id,p.params)}},qe={id:"doc.command.align-left",type:o.CommandType.COMMAND,handler:r=>r.get(o.ICommandService).syncExecuteCommand(j.id,{alignType:o.HorizontalAlign.LEFT})},Qe={id:"doc.command.align-center",type:o.CommandType.COMMAND,handler:r=>r.get(o.ICommandService).syncExecuteCommand(j.id,{alignType:o.HorizontalAlign.CENTER})},et={id:"doc.command.align-right",type:o.CommandType.COMMAND,handler:r=>r.get(o.ICommandService).syncExecuteCommand(j.id,{alignType:o.HorizontalAlign.RIGHT})},tt={id:"doc.command.align-justify",type:o.CommandType.COMMAND,handler:r=>r.get(o.ICommandService).syncExecuteCommand(j.id,{alignType:o.HorizontalAlign.JUSTIFIED})},nt={id:"doc.command-replace-content",type:o.CommandType.COMMAND,handler:async(r,n)=>{var S;const{unitId:e,body:t,textRanges:i,segmentId:a=""}=n,s=r.get(o.IUniverInstanceService),c=r.get(o.ICommandService),l=r.get(exports.TextSelectionManagerService),d=(S=s.getUniverDocInstance(e))==null?void 0:S.getSnapshot().body,u=l.getSelections();if(d==null||!Array.isArray(u)||u.length===0)return!1;const g=it(e,a,d,t);return g.params.textRanges=i,!!c.syncExecuteCommand(g.id,g.params)}},ot={id:"doc.command-cover-content",type:o.CommandType.COMMAND,handler:async(r,n)=>{var u;const{unitId:e,body:t,segmentId:i=""}=n,a=r.get(o.IUniverInstanceService),s=r.get(o.ICommandService),c=r.get(o.IUndoRedoService),l=(u=a.getUniverDocInstance(e))==null?void 0:u.getSnapshot().body;if(l==null)return!1;const d=it(e,i,l,t);return d.params.noNeedSetTextRange=!0,d.params.noHistory=!0,s.syncExecuteCommand(d.id,d.params),c.clearUndoRedo(e),!0}};function it(r,n,e,t){const i={id:N.id,params:{unitId:r,actions:[],textRanges:[]}},a=new o.TextX,s=o.JSONX.getInstance(),c=(e==null?void 0:e.dataStream.length)-2;return c>0&&a.push({t:o.TextXActionType.DELETE,len:c,line:0,segmentId:n}),t.dataStream.length>0&&a.push({t:o.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:n}),i.params.actions=s.editOp(a.serialize()),i}const te={id:"doc.operation.move-cursor",type:o.CommandType.OPERATION,handler:(r,n)=>!!n},ne={id:"doc.operation.move-selection",type:o.CommandType.OPERATION,handler:(r,n)=>!!n},Bt=(r,n)=>{const e=r.get(o.IUniverInstanceService).getUniverDocInstance(n.unitId),t=(e==null?void 0:e.zoomRatio)||1;return{...o.Tools.deepClone(n),zoomRatio:t}},J={id:"doc.operation.set-zoom-ratio",type:o.CommandType.OPERATION,handler:(r,n)=>{const e=r.get(o.IUniverInstanceService).getUniverDocInstance(n.unitId);if(!e)return!1;const t=e.getSnapshot();return t.settings==null?t.settings={zoomRatio:n.zoomRatio}:t.settings.zoomRatio=n.zoomRatio,!0}},rt={type:o.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(r,n)=>{var g,m,S;const e=r.get(o.ICommandService),t=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService);let a=(g=i.getCurrentUniverDocInstance())==null?void 0:g.getUnitId();if(!a)return!1;let s=1;if(n&&(a=(m=n.documentId)!=null?m:a,s=(S=n.zoomRatio)!=null?S:s),!i.getUniverDocInstance(a))return!1;const l={zoomRatio:s,unitId:a},d=Bt(r,l);return e.syncExecuteCommand(J.id,l)?(t.pushUndoRedo({unitID:a,undoMutations:[{id:J.id,params:d}],redoMutations:[{id:J.id,params:l}]}),!0):!1}},at={id:"doc.operation.select-all",type:o.CommandType.COMMAND,handler:async r=>{const n=r.get(o.IUniverInstanceService),e=r.get(exports.TextSelectionManagerService),t=n.getCurrentUniverDocInstance();if(!t)return!1;const i=t.getSnapshot().body;if(i==null)return!1;const a=[{startOffset:0,endOffset:i.dataStream.length-2}];return e.replaceTextRanges(a,!1),!0}};var Ft=Object.defineProperty,Xt=Object.getOwnPropertyDescriptor,$t=(r,n,e,t)=>{for(var i=t>1?void 0:t?Xt(n,e):n,a=r.length-1,s;a>=0;a--)(s=r[a])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&Ft(n,e,i),i},z=(r,n)=>(e,t)=>n(e,t,r);let q=class extends o.Disposable{constructor(n,e,t,i,a){super();T(this,"_previousIMEContent","");T(this,"_isCompositionStart",!0);T(this,"_onStartSubscription");T(this,"_onUpdateSubscription");T(this,"_onEndSubscription");this._docSkeletonManagerService=n,this._univerInstanceService=e,this._textSelectionRenderManager=t,this._imeInputManagerService=i,this._commandService=a,this._initialize()}dispose(){var n,e,t;(n=this._onStartSubscription)==null||n.unsubscribe(),(e=this._onUpdateSubscription)==null||e.unsubscribe(),(t=this._onEndSubscription)==null||t.unsubscribe()}_initialize(){this._initialOnCompositionstart(),this._initialOnCompositionUpdate(),this._initialOnCompositionend()}_initialOnCompositionstart(){this._onStartSubscription=this._textSelectionRenderManager.onCompositionstart$.subscribe(n=>{if(n==null)return;this._resetIME();const{activeRange:e}=n;e!=null&&this._imeInputManagerService.setActiveRange(o.Tools.deepClone(e))})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._textSelectionRenderManager.onCompositionupdate$.subscribe(async n=>{this._updateContent(n,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._textSelectionRenderManager.onCompositionend$.subscribe(n=>{this._updateContent(n,!1)})}async _updateContent(n,e){var d;const t=(d=this._docSkeletonManagerService.getCurrent())==null?void 0:d.skeleton;if(n==null||t==null)return;const i=this._univerInstanceService.getCurrentUniverDocInstance();if(!i)return;const{event:a,activeRange:s}=n;if(t==null||s==null)return;const l=a.data;l===this._previousIMEContent&&e||(await this._commandService.executeCommand(xe.id,{unitId:i.getUnitId(),newText:l,oldTextLen:this._previousIMEContent.length,isCompositionStart:this._isCompositionStart,isCompositionEnd:!e}),e?(this._isCompositionStart&&(this._isCompositionStart=!1),this._previousIMEContent=l):this._resetIME())}_resetIME(){this._previousIMEContent="",this._isCompositionStart=!0,this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(null)}};q=$t([o.OnLifecycle(o.LifecycleStages.Rendered,q),z(0,L.Inject(exports.DocSkeletonManagerService)),z(1,o.IUniverInstanceService),z(2,y.ITextSelectionRenderManager),z(3,L.Inject(Y)),z(4,o.ICommandService)],q);var kt=Object.defineProperty,Vt=Object.getOwnPropertyDescriptor,jt=(r,n,e,t)=>{for(var i=t>1?void 0:t?Vt(n,e):n,a=r.length-1,s;a>=0;a--)(s=r[a])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&kt(n,e,i),i},G=(r,n)=>(e,t)=>n(e,t,r);let Q=class extends o.Disposable{constructor(n,e,t,i,a){super();T(this,"_onInputSubscription");this._docSkeletonManagerService=n,this._univerInstanceService=e,this._renderManagerService=t,this._textSelectionManagerService=i,this._commandService=a,this._commandExecutedListener()}dispose(){var n;super.dispose(),(n=this._onInputSubscription)==null||n.unsubscribe()}_commandExecutedListener(){const n=[te.id,ne.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!n.includes(e.id))return;const t=e.params;switch(e.id){case te.id:return this._handleMoveCursor(t.direction);case ne.id:return this._handleShiftMoveSelection(t.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(n){var p,f,I;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),i=this._univerInstanceService.getCurrentUniverDocInstance();if(!i)return;const a=(p=this._docSkeletonManagerService.getCurrent())==null?void 0:p.skeleton,s=this._getDocObject();if(e==null||a==null||s==null)return;const{startOffset:c,endOffset:l,style:d,collapsed:u,direction:g}=e;if(t.length>1){let h=Number.POSITIVE_INFINITY,M=Number.NEGATIVE_INFINITY;for(const _ of t)h=Math.min(h,_.startOffset),M=Math.max(M,_.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:n===o.Direction.LEFT||n===o.Direction.UP?M:h,endOffset:n===o.Direction.LEFT||n===o.Direction.UP?h:M,style:d}],!1);return}const m=u||g===y.RANGE_DIRECTION.FORWARD?c:l;let S=u||g===y.RANGE_DIRECTION.FORWARD?l:c;const v=(f=i.getBody().dataStream.length)!=null?f:Number.POSITIVE_INFINITY;if(n===o.Direction.LEFT||n===o.Direction.RIGHT){const h=a.findNodeByCharIndex(S-1),M=a.findNodeByCharIndex(S);S=n===o.Direction.RIGHT?S+M.count:S-((I=h==null?void 0:h.count)!=null?I:0),S=Math.min(v-2,Math.max(0,S)),this._textSelectionManagerService.replaceTextRanges([{startOffset:m,endOffset:S,style:d}],!1)}else{const h=a.findNodeByCharIndex(S),M=s.document.getOffsetConfig(),_=this._getTopOrBottomPosition(a,h,n===o.Direction.DOWN);if(_==null){const R=n===o.Direction.UP?0:v-2;if(R===S)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:m,endOffset:R,style:d}],!1);return}const C=new y.NodePositionConvertToCursor(M,a).getRangePointData(_,_).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:m,endOffset:C.endOffset,style:d}],!1)}}_handleMoveCursor(n){var m,S,v;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),i=this._univerInstanceService.getCurrentUniverDocInstance();if(!i)return!1;const a=(m=this._docSkeletonManagerService.getCurrent())==null?void 0:m.skeleton,s=this._getDocObject();if(e==null||a==null||s==null||t==null)return;const{startOffset:c,endOffset:l,style:d,collapsed:u}=e,g=(S=i.getBody().dataStream.length)!=null?S:Number.POSITIVE_INFINITY;if(n===o.Direction.LEFT||n===o.Direction.RIGHT){let p;if(!e.collapsed||t.length>1){let f=Number.POSITIVE_INFINITY,I=Number.NEGATIVE_INFINITY;for(const h of t)f=Math.min(f,h.startOffset),I=Math.max(I,h.endOffset);p=n===o.Direction.LEFT?f:I}else{const f=a.findNodeByCharIndex(c-1),I=a.findNodeByCharIndex(c);n===o.Direction.LEFT?p=Math.max(0,c-((v=f==null?void 0:f.count)!=null?v:0)):p=Math.min(g-2,l+I.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:p,style:d}],!1)}else{const p=a.findNodeByCharIndex(c),f=a.findNodeByCharIndex(l),I=s.document.getOffsetConfig(),h=this._getTopOrBottomPosition(a,n===o.Direction.UP?p:f,n===o.Direction.DOWN);if(h==null){let _;u?_=n===o.Direction.UP?0:g-2:_=n===o.Direction.UP?c:l,this._textSelectionManagerService.replaceTextRanges([{startOffset:_,endOffset:_,style:d}],!1);return}const M=new y.NodePositionConvertToCursor(I,a).getRangePointData(h,h).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...M,style:d}],!1)}}_getTopOrBottomPosition(n,e,t){if(e==null)return;const i=this._getSpanLeftOffsetInLine(e),a=this._getNextOrPrevLine(e,t);if(a==null)return;const s=this._matchPositionByLeftOffset(n,a,i);if(s!=null)return{...s,isBack:!0}}_getSpanLeftOffsetInLine(n){const e=n.parent;if(e==null)return Number.NEGATIVE_INFINITY;const t=e.left,{left:i}=n;return t+i}_matchPositionByLeftOffset(n,e,t){const i={distance:Number.POSITIVE_INFINITY};for(const a of e.divides){const s=a.left;for(const c of a.glyphGroup){const{left:l}=c,d=s+l,u=Math.abs(t-d);u<i.distance&&(i.glyph=c,i.distance=u)}}if(i.glyph!=null)return n.findPositionByGlyph(i.glyph)}_getNextOrPrevLine(n,e){var v,p,f,I,h,M,_,C,R,O,D,U;const t=n.parent;if(t==null)return;const i=t.parent;if(i==null)return;const a=i.parent;if(a==null)return;const s=a.lines.indexOf(i);if(s===-1)return;let c;if(e===!0?c=a.lines[s+1]:c=a.lines[s-1],c!=null)return c;const l=a.parent;if(l==null)return;const d=l.columns.indexOf(a);if(d===-1)return;if(e===!0)c=(v=l.columns[d+1])==null?void 0:v.lines[0];else{const x=(f=(p=l.columns)==null?void 0:p[d-1])==null?void 0:f.lines;c=x==null?void 0:x[x.length-1]}if(c!=null)return c;const u=l.parent;if(u==null)return;const g=u.sections.indexOf(l);if(g===-1)return;if(e===!0)c=(h=(I=u.sections[g-1])==null?void 0:I.columns[0])==null?void 0:h.lines[0];else{const x=(_=(M=u.sections)==null?void 0:M[g-1])==null?void 0:_.columns,E=x==null?void 0:x[x.length-1],A=E==null?void 0:E.lines;c=A==null?void 0:A[A.length-1]}if(c!=null)return c;const m=u.parent;if(m==null)return;const S=m.pages.indexOf(u);if(S!==-1){if(e===!0)c=(O=(R=(C=m.pages[S+1])==null?void 0:C.sections[0])==null?void 0:R.columns[0])==null?void 0:O.lines[0];else{const x=(D=m.pages[S-1])==null?void 0:D.sections;if(x==null)return;const E=(U=x[x.length-1])==null?void 0:U.columns,A=E[E.length-1],X=A==null?void 0:A.lines;c=X[X.length-1]}if(c!=null)return c}}_getDocObject(){return je(this._univerInstanceService,this._renderManagerService)}};Q=jt([o.OnLifecycle(o.LifecycleStages.Rendered,Q),G(0,L.Inject(exports.DocSkeletonManagerService)),G(1,o.IUniverInstanceService),G(2,y.IRenderManagerService),G(3,L.Inject(exports.TextSelectionManagerService)),G(4,o.ICommandService)],Q);var zt=Object.defineProperty,Gt=Object.getOwnPropertyDescriptor,Ht=(r,n,e,t)=>{for(var i=t>1?void 0:t?Gt(n,e):n,a=r.length-1,s;a>=0;a--)(s=r[a])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&zt(n,e,i),i},H=(r,n)=>(e,t)=>n(e,t,r);let ee=class extends o.Disposable{constructor(n,e,t,i,a){super();T(this,"_onInputSubscription");this._docSkeletonManagerService=n,this._univerInstanceService=e,this._renderManagerService=t,this._textSelectionRenderManager=i,this._commandService=a,this._init()}dispose(){var n;super.dispose(),(n=this._onInputSubscription)==null||n.unsubscribe()}_init(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async n=>{var v;if(n==null)return;const e=this._univerInstanceService.getCurrentUniverDocInstance();if(!e)return;const t=e.getUnitId(),{event:i,content:a="",activeRange:s}=n,c=i,l=(v=this._docSkeletonManagerService.getCurrent())==null?void 0:v.skeleton;if(c.data==null||l==null||!l||!s)return;const{startOffset:d,segmentId:u,style:g}=s,m=a.length,S=[{startOffset:d+m,endOffset:d+m,style:g}];await this._commandService.executeCommand(W.id,{unitId:t,body:{dataStream:a},range:s,textRanges:S,segmentId:u})})}};ee=Ht([o.OnLifecycle(o.LifecycleStages.Rendered,ee),H(0,L.Inject(exports.DocSkeletonManagerService)),H(1,o.IUniverInstanceService),H(2,y.IRenderManagerService),H(3,y.ITextSelectionRenderManager),H(4,o.ICommandService)],ee);var Jt=Object.defineProperty,Yt=Object.getOwnPropertyDescriptor,Wt=(r,n,e,t)=>{for(var i=t>1?void 0:t?Yt(n,e):n,a=r.length-1,s;a>=0;a--)(s=r[a])&&(i=(t?s(n,e,i):s(i))||i);return t&&i&&Jt(n,e,i),i},Zt=(r,n)=>(e,t)=>n(e,t,r);const Kt="docs";var K;exports.UniverDocsPlugin=(K=class extends o.Plugin{constructor(n={},e){super(),this._injector=e,this._initializeDependencies(e),this._initializeCommands()}_initializeCommands(){[te,ne,Ge,He,ie,re,ae,se,V,ce,le,de,ue,ge,me,ye,ze,W,Z,_e,xe,Te,N,nt,ot,rt,J,Ie,at,Ze,We,Oe,qe,Qe,et,j,tt].forEach(n=>{this._injector.get(o.ICommandService).registerCommand(n)})}_initializeDependencies(n){[[exports.DocSkeletonManagerService],[exports.DocViewModelManagerService],[exports.DocStateChangeManagerService],[Y],[y.ITextSelectionRenderManager,{useClass:y.TextSelectionRenderManager}],[exports.TextSelectionManagerService],[ee],[q],[Q]].forEach(e=>n.add(e))}},T(K,"pluginName",Kt),T(K,"type",o.UniverInstanceType.UNIVER_DOC),K);exports.UniverDocsPlugin=Wt([Zt(1,L.Inject(L.Injector))],exports.UniverDocsPlugin);exports.AlignCenterCommand=Qe;exports.AlignJustifyCommand=tt;exports.AlignLeftCommand=qe;exports.AlignOperationCommand=j;exports.AlignRightCommand=et;exports.BreakLineCommand=ze;exports.BulletListCommand=We;exports.CoverContentCommand=ot;exports.CutContentCommand=Me;exports.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX=ut;exports.DOCS_COMPONENT_DEFAULT_Z_INDEX=St;exports.DOCS_COMPONENT_HEADER_LAYER_INDEX=gt;exports.DOCS_COMPONENT_MAIN_LAYER_INDEX=mt;exports.DOCS_VIEW_KEY=oe;exports.DeleteCommand=Z;exports.DeleteLeftCommand=Ge;exports.DeleteRightCommand=He;exports.IMEInputCommand=xe;exports.IMEInputManagerService=Y;exports.InnerPasteCommand=Ut;exports.InsertCommand=W;exports.MoveCursorOperation=te;exports.MoveSelectionOperation=ne;exports.NORMAL_TEXT_SELECTION_PLUGIN_NAME=pt;exports.OrderListCommand=Ze;exports.ReplaceContentCommand=nt;exports.ResetInlineFormatTextBackgroundColorCommand=ge;exports.RichTextEditingMutation=N;exports.SelectAllOperation=at;exports.SetDocZoomRatioCommand=rt;exports.SetDocZoomRatioOperation=J;exports.SetInlineFormatBoldCommand=ie;exports.SetInlineFormatCommand=ye;exports.SetInlineFormatFontFamilyCommand=de;exports.SetInlineFormatFontSizeCommand=le;exports.SetInlineFormatItalicCommand=re;exports.SetInlineFormatStrikethroughCommand=se;exports.SetInlineFormatSubscriptCommand=V;exports.SetInlineFormatSuperscriptCommand=ce;exports.SetInlineFormatTextBackgroundColorCommand=me;exports.SetInlineFormatTextColorCommand=ue;exports.SetInlineFormatUnderlineCommand=ae;exports.SetTextSelectionsOperation=Ie;exports.UpdateCommand=_e;exports.VIEWPORT_KEY=Ve;exports.getDocObject=je;exports.getDocObjectById=ft;exports.serializeTextRange=k;