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