@univerjs/docs 0.1.16 → 0.2.0

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