@univerjs/docs 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var Le=Object.defineProperty;var Be=(s,n,e)=>n in s?Le(s,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[n]=e;var C=(s,n,e)=>(Be(s,typeof n!="symbol"?n+"":n,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@univerjs/core"),D=require("@univerjs/engine-render"),b=require("rxjs"),A=require("@wendellhu/redi");function le(s,n){const t=s.getCurrentUniverDocInstance().getUnitId(),o=n.getRenderById(t);if(o==null)return;const{mainComponent:i,scene:a,engine:c}=o;return{document:i,scene:a,engine:c}}function $e(s,n){const e=n.getRenderById(s);if(e==null)return;const{mainComponent:t,scene:o,engine:i}=e;return{document:t,scene:o,engine:i}}var Me=(s=>(s.MAIN="__Document_Render_Main__",s))(Me||{}),Te=(s=>(s.VIEW_MAIN="viewMain",s.VIEW_TOP="viewTop",s.VIEW_LEFT="viewLeft",s.VIEW_LEFT_TOP="viewLeftTop",s))(Te||{});const Fe=0,Xe=2,Ve=10,je="normalTextSelectionPluginName",de={id:"doc.operation.set-selections",type:r.CommandType.OPERATION,handler:(s,n)=>!0};var ke=Object.defineProperty,ze=Object.getOwnPropertyDescriptor,He=(s,n,e,t)=>{for(var o=t>1?void 0:t?ze(n,e):n,i=s.length-1,a;i>=0;i--)(a=s[i])&&(o=(t?a(n,e,o):a(o))||o);return t&&o&&ke(n,e,o),o},_e=(s,n)=>(e,t)=>n(e,t,s);function B(s){const{startOffset:n,endOffset:e,collapsed:t}=s,o={startOffset:n,endOffset:e,collapsed:t};return typeof s.isActive=="function"&&(o.isActive=s.isActive()),o}exports.TextSelectionManagerService=class extends r.RxDisposable{constructor(e,t){super();C(this,"_currentSelection",null);C(this,"_textSelectionInfo",new Map);C(this,"_textSelection$",new b.BehaviorSubject(null));C(this,"textSelection$",this._textSelection$.asObservable());this._textSelectionRenderManager=e,this._commandService=t,this._syncSelectionFromRenderService()}getCurrentSelection(){return this._currentSelection}getCurrentSelectionInfo(){return this._getTextRanges(this._currentSelection)}dispose(){this._textSelection$.complete()}refreshSelection(){this._currentSelection!=null&&this._refresh(this._currentSelection)}setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}setCurrentSelectionNotRefresh(e){this._currentSelection=e}getSelections(){var e;return(e=this._getTextRanges(this._currentSelection))==null?void 0:e.textRanges}getActiveRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:t,segmentId:o,style:i}=e,a=t.find(S=>S.isActive());if(a==null)return null;const{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:m,direction:g}=a;return c==null||l==null?null:{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:m,direction:g,segmentId:o,style:i}}add(e,t=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,segmentId:"",isEditing:t,style:D.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(b.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._replaceTextRangesWithNoRefresh(e)})}_replaceTextRangesWithNoRefresh(e){if(this._currentSelection==null)return;const t={...this._currentSelection,...e};this._replaceByParam(t),this._textSelection$.next(t);const{unitId:o,subUnitId:i,segmentId:a,style:c,textRanges:l,isEditing:u}=t;this._commandService.executeCommand(de.id,{unitId:o,subUnitId:i,segmentId:a,style:c,isEditing:u,ranges:l.map(B)})}_getTextRanges(e){var i;if(e==null)return;const{unitId:t,subUnitId:o=""}=e;return(i=this._textSelectionInfo.get(t))==null?void 0:i.get(o)}_refresh(e){const t=this._getTextRanges(e);this._textSelectionRenderManager.removeAllTextRanges(),t&&Array.isArray(t.textRanges)&&t.textRanges.length&&this._textSelectionRenderManager.addTextRanges(t.textRanges.map(B))}_replaceByParam(e){const{unitId:t,subUnitId:o,style:i,segmentId:a,textRanges:c,isEditing:l}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(o,{textRanges:c,style:i,segmentId:a,isEditing:l})}_addByParam(e){const{unitId:t,subUnitId:o,textRanges:i,style:a,segmentId:c,isEditing:l}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);const u=this._textSelectionInfo.get(t);u.has(o)?u.get(o).textRanges.push(...i):u.set(o,{textRanges:i,style:a,segmentId:c,isEditing:l})}};exports.TextSelectionManagerService=He([_e(0,D.ITextSelectionRenderManager),_e(1,r.ICommandService)],exports.TextSelectionManagerService);function ue(s,n="",e=0){const{startOffset:t,endOffset:o}=s,i=[],a=t-e,c=o-e;return a>0&&i.push({t:r.TextXActionType.RETAIN,len:a,segmentId:n}),i.push({t:r.TextXActionType.DELETE,len:c-a,line:0,segmentId:n}),i}var Ge=Object.defineProperty,Ye=Object.getOwnPropertyDescriptor,We=(s,n,e,t)=>{for(var o=t>1?void 0:t?Ye(n,e):n,i=s.length-1,a;i>=0;i--)(a=s[i])&&(o=(t?a(n,e,o):a(o))||o);return t&&o&&Ge(n,e,o),o},Ze=(s,n)=>(e,t)=>n(e,t,s);exports.DocViewModelManagerService=class extends r.RxDisposable{constructor(e){super();C(this,"_docViewModelMap",new Map);C(this,"_currentDocViewModel$",new b.BehaviorSubject(null));C(this,"currentDocViewModel$",this._currentDocViewModel$.asObservable());this._currentUniverService=e,this._initialize()}_initialize(){this._init()}dispose(){this._currentDocViewModel$.complete(),this._docViewModelMap.clear()}_init(){this._currentUniverService.currentDoc$.pipe(b.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)}),this._currentUniverService.getAllUniverDocsInstance().forEach(e=>{this._create(e)}),this._currentUniverService.docDisposed$.pipe(b.takeUntil(this.dispose$)).subscribe(e=>{this._docViewModelMap.delete(e.getUnitId())})}_create(e){if(e==null)return;const t=e.getUnitId();this._setCurrent(t)}getAllModel(){return this._docViewModelMap}getViewModel(e){var t;return(t=this._docViewModelMap.get(e))==null?void 0:t.docViewModel}_setCurrent(e){var o;const t=this._currentUniverService.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 i=this._buildDocViewModel(t);this._docViewModelMap.set(e,{unitId:e,docViewModel:i})}if(e===r.DOCS_NORMAL_EDITOR_UNIT_ID_KEY){const i=(o=this._docViewModelMap.get(e))==null?void 0:o.docViewModel;if(i==null)return;i.reset(t)}this._currentDocViewModel$.next(this._docViewModelMap.get(e))}}_buildDocViewModel(e){return new D.DocumentViewModel(e)}};exports.DocViewModelManagerService=We([Ze(0,r.IUniverInstanceService)],exports.DocViewModelManagerService);var qe=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,Je=(s,n,e,t)=>{for(var o=t>1?void 0:t?Ke(n,e):n,i=s.length-1,a;i>=0;i--)(a=s[i])&&(o=(t?a(n,e,o):a(o))||o);return t&&o&&qe(n,e,o),o},se=(s,n)=>(e,t)=>n(e,t,s);const Qe=300;exports.DocStateChangeManagerService=class extends r.RxDisposable{constructor(e,t,o){super();C(this,"_docStateChange$",new b.BehaviorSubject(null));C(this,"docStateChange$",this._docStateChange$.asObservable());C(this,"_stateCache",new Map);C(this,"_timer",null);this._undoRedoService=e,this._commandService=t,this._univerInstanceService=o,this._initialize()}setChangeState(e){const{trigger:t,noHistory:o}=e;t!=null&&(this._cacheChangeState(e),o||this._docStateChange$.next(e))}_initialize(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===r.UndoCommandId||e.id===r.RedoCommandId){const t=this._univerInstanceService.getCurrentUniverDocInstance();if(t==null)return;const o=t.getUnitId();this._pushHistory(o)}}))}_cacheChangeState(e){const{trigger:t,unitId:o,noHistory:i}=e;if(!(t===r.RedoCommandId||t===r.UndoCommandId||i)){if(this._stateCache.has(o)){const a=this._stateCache.get(o);a==null||a.push(e)}else this._stateCache.set(o,[e]);t===k.id||t===z.id?(this._timer&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._pushHistory(o)},Qe)):this._pushHistory(o)}}_pushHistory(e){const t=this._undoRedoService,o=this._stateCache.get(e);if(!Array.isArray(o)||o.length===0)return;const i=o.length,a=o[0].commandId,c=o[0],l=o[i-1],u={unitId:e,actions:o.reduce((m,g)=>r.TextX.compose(m,g.redoState.actions),[]),textRanges:l.redoState.textRanges},d={unitId:e,actions:o.reverse().reduce((m,g)=>r.TextX.compose(m,g.undoState.actions),[]),textRanges:c.undoState.textRanges};t.pushUndoRedo({unitID:e,undoMutations:[{id:a,params:d}],redoMutations:[{id:a,params:u}]}),o.length=0}};exports.DocStateChangeManagerService=Je([se(0,A.Inject(r.IUndoRedoService)),se(1,r.ICommandService),se(2,r.IUniverInstanceService)],exports.DocStateChangeManagerService);class j{constructor(){C(this,"_previousActiveRange",null);C(this,"_undoMutationParamsCache",[]);C(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache:n=[],redoCache:e=[]}){this._undoMutationParamsCache=n,this._redoMutationParamsCache=e}getActiveRange(){return this._previousActiveRange}setActiveRange(n){this._previousActiveRange=n}pushUndoRedoMutationParams(n,e){this._undoMutationParamsCache.push(n),this._redoMutationParamsCache.push(e)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:n}=this._undoMutationParamsCache[0],e={unitId:n,actions:this._undoMutationParamsCache.reverse().reduce((o,i)=>r.TextX.compose(o,i.actions),[]),textRanges:[]};return{redoMutationParams:{unitId:n,actions:this._redoMutationParamsCache.reduce((o,i)=>r.TextX.compose(o,i.actions),[]),textRanges:[]},undoMutationParams:e,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Ie="doc.mutation.rich-text-editing",U={id:Ie,type:r.CommandType.MUTATION,handler:(s,n)=>{var R;const{unitId:e,actions:t,textRanges:o,prevTextRanges:i,trigger:a,noHistory:c,isCompositionEnd:l,noNeedSetTextRange:u}=n,m=s.get(r.IUniverInstanceService).getUniverDocInstance(e),S=s.get(exports.DocViewModelManagerService).getViewModel(e),v=s.get(exports.TextSelectionManagerService),p=((R=v.getSelections())!=null?R:[]).map(B),_=s.get(exports.DocStateChangeManagerService),h=s.get(j);if(m==null||S==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);if(t.length===0)return{unitId:e,actions:[],textRanges:p};const M=m.apply(t),{segmentId:T}=t[0],x=m.getSelfOrHeaderFooterModel(T);S.getSelfOrHeaderFooterViewModel(T).reset(x),!u&&o&&a!=null&&queueMicrotask(()=>{v.replaceTextRanges(o)});const O={commandId:Ie,unitId:e,trigger:a,noHistory:c,redoState:{actions:t,textRanges:o},undoState:{actions:M,textRanges:i!=null?i:p}};if(l){const y=h.fetchComposedUndoRedoMutationParams();if(y==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:I,redoMutationParams:P,previousActiveRange:N}=y;O.redoState.actions=P.actions,O.undoState.actions=I.actions,O.undoState.textRanges=[N]}return _.setChangeState(O),{unitId:e,actions:M,textRanges:p}}},k={id:"doc.command.insert-text",type:r.CommandType.COMMAND,handler:async(s,n)=>{const e=s.get(r.ICommandService),{range:t,segmentId:o,body:i,unitId:a,textRanges:c}=n,{startOffset:l,collapsed:u}=t,d={id:U.id,params:{unitId:a,actions:[],textRanges:c}},m=new r.TextX;return u?l>0&&m.push({t:r.TextXActionType.RETAIN,len:l,segmentId:o}):m.push(...ue(t,o)),m.push({t:r.TextXActionType.INSERT,body:i,len:i.dataStream.length,line:0,segmentId:o}),d.params.actions=m.serialize(),!!e.syncExecuteCommand(d.id,d.params)}};var w=(s=>(s[s.LEFT=0]="LEFT",s[s.RIGHT=1]="RIGHT",s))(w||{});const z={id:"doc.command.delete-text",type:r.CommandType.COMMAND,handler:async(s,n)=>{const e=s.get(r.ICommandService),{range:t,segmentId:o,unitId:i,direction:a,textRanges:c,len:l=1}=n,{startOffset:u}=t,d={id:U.id,params:{unitId:i,actions:[],textRanges:c}},m=new r.TextX;return u>0&&m.push({t:r.TextXActionType.RETAIN,len:a===0?u-l:u,segmentId:o}),m.push({t:r.TextXActionType.DELETE,len:l,line:0,segmentId:o}),d.params.actions=m.serialize(),!!e.syncExecuteCommand(d.id,d.params)}},me={id:"doc.command.update-text",type:r.CommandType.COMMAND,handler:async(s,n)=>{const{range:e,segmentId:t,updateBody:o,coverType:i,unitId:a,textRanges:c}=n,l=s.get(r.ICommandService),u={id:U.id,params:{unitId:a,actions:[],textRanges:c}},d=new r.TextX,{startOffset:m,endOffset:g}=e;return d.push({t:r.TextXActionType.RETAIN,len:m,segmentId:t}),d.push({t:r.TextXActionType.RETAIN,body:o,len:g-m,segmentId:t,coverType:i}),u.params.actions=d.serialize(),!!l.syncExecuteCommand(u.id,u.params)}};function et(s,n){const e=[];for(let t=0,o=s.length;t<o;t++)s[t]===r.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});if(n)for(const t of e)n.bullet&&(t.bullet=r.Tools.deepClone(n.bullet)),n.paragraphStyle&&(t.paragraphStyle=r.Tools.deepClone(n.paragraphStyle));return e}const xe={id:"doc.command.break-line",type:r.CommandType.COMMAND,handler:async s=>{var v,f;const n=s.get(exports.TextSelectionManagerService),e=s.get(r.IUniverInstanceService),t=s.get(r.ICommandService),o=n.getActiveRange();if(o==null)return!1;const i=e.getCurrentUniverDocInstance(),a=i.getUnitId(),{startOffset:c,segmentId:l,style:u}=o,d=[{startOffset:c+1,endOffset:c+1,style:u}],g=((f=(v=i.getBody())==null?void 0:v.paragraphs)!=null?f:[]).find(p=>p.startIndex>=c);return await t.executeCommand(k.id,{unitId:a,body:{dataStream:r.DataStreamTreeTokenType.PARAGRAPH,paragraphs:et(r.DataStreamTreeTokenType.PARAGRAPH,g)},range:o,textRanges:d,segmentId:l})}};var tt=Object.defineProperty,nt=Object.getOwnPropertyDescriptor,ot=(s,n,e,t)=>{for(var o=t>1?void 0:t?nt(n,e):n,i=s.length-1,a;i>=0;i--)(a=s[i])&&(o=(t?a(n,e,o):a(o))||o);return t&&o&&tt(n,e,o),o},ae=(s,n)=>(e,t)=>n(e,t,s);exports.DocSkeletonManagerService=class extends r.RxDisposable{constructor(e,t,o){super();C(this,"_currentSkeletonUnitId","");C(this,"_docSkeletonMap",new Map);C(this,"_currentSkeleton$",new b.BehaviorSubject(null));C(this,"currentSkeleton$",this._currentSkeleton$.asObservable());C(this,"_currentSkeletonBefore$",new b.BehaviorSubject(null));C(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._localeService=e,this._docViewModelManagerService=t,this._currentUniverService=o,this._initialize()}_initialize(){this._init()}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._docSkeletonMap.clear()}_init(){this._docViewModelManagerService.currentDocViewModel$.pipe(b.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._setCurrent(e)}),this._docViewModelManagerService.getAllModel().forEach(e=>{e!=null&&this._setCurrent(e)}),this._currentUniverService.docDisposed$.pipe(b.takeUntil(this.dispose$)).subscribe(e=>{this._docSkeletonMap.delete(e.getUnitId()),this._currentSkeletonUnitId=this._currentUniverService.getCurrentUniverDocInstance().getUnitId()})}getCurrent(){return this.getSkeletonByUnitId(this._currentSkeletonUnitId)}getAllSkeleton(){return this._docSkeletonMap}makeDirtyCurrent(e=!0){this.makeDirty(this._currentSkeletonUnitId,e)}makeDirty(e,t=!0){const o=this.getSkeletonByUnitId(e);o!=null&&(o.dirty=t)}getSkeletonByUnitId(e){return this._docSkeletonMap.get(e)}_setCurrent(e){const{unitId:t}=e;if(this._docSkeletonMap.has(t)){const o=this.getSkeletonByUnitId(t);o.skeleton.calculate(),o.dirty=!0}else{const o=this._buildSkeleton(e.docViewModel);o.calculate(),this._docSkeletonMap.set(t,{unitId:t,skeleton:o,dirty:!1})}return this._currentSkeletonUnitId=t,this._currentSkeletonBefore$.next(this.getCurrent()),this._currentSkeleton$.next(this.getCurrent()),this.getCurrent()}_buildSkeleton(e){return D.DocumentSkeleton.create(e,this._localeService)}};exports.DocSkeletonManagerService=ot([ae(0,A.Inject(r.LocaleService)),ae(1,A.Inject(exports.DocViewModelManagerService)),ae(2,r.IUniverInstanceService)],exports.DocSkeletonManagerService);const rt={id:"doc.command.inner-paste",type:r.CommandType.COMMAND,handler:async(s,n)=>{const{segmentId:e,body:t,textRanges:o}=n,i=s.get(r.ICommandService),a=s.get(exports.TextSelectionManagerService),c=s.get(r.IUniverInstanceService),l=a.getSelections();if(!Array.isArray(l)||l.length===0)return!1;const d=c.getCurrentUniverDocInstance().getUnitId(),m={id:U.id,params:{unitId:d,actions:[],textRanges:o}},g=new r.MemoryCursor;g.reset();const S=new r.TextX;for(const f of l){const{startOffset:p,endOffset:_,collapsed:h}=f,M=p-g.cursor;h?S.push({t:r.TextXActionType.RETAIN,len:M,segmentId:e}):S.push(...ue(f,e,g.cursor)),S.push({t:r.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:e}),g.reset(),g.moveCursor(_)}return m.params.actions=S.serialize(),!!i.syncExecuteCommand(m.id,m.params)}},ge={id:"doc.command.inner-cut",type:r.CommandType.COMMAND,handler:async(s,n)=>{const{segmentId:e,textRanges:t}=n,o=s.get(r.ICommandService),i=s.get(exports.TextSelectionManagerService),a=s.get(r.IUniverInstanceService),c=i.getSelections();if(!Array.isArray(c)||c.length===0)return!1;const l=a.getCurrentUniverDocInstance().getUnitId(),u=a.getUniverDocInstance(l),d=r.getDocsUpdateBody(u.snapshot,e);if(d==null)return!1;const m={id:U.id,params:{unitId:l,actions:[],textRanges:t}},g=new r.MemoryCursor;g.reset();const S=new r.TextX;for(const f of c){const{startOffset:p,endOffset:_,collapsed:h}=f,M=p-g.cursor;h?S.push({t:r.TextXActionType.RETAIN,len:M,segmentId:e}):S.push(...it(f,d,e,g.cursor)),g.reset(),g.moveCursor(_)}return m.params.actions=S.serialize(),!!o.syncExecuteCommand(m.id,m.params)}};function it(s,n,e="",t=0){const{startOffset:o,endOffset:i}=s,a=[],{paragraphs:c=[]}=n,l=o-t,u=i-t,d=c==null?void 0:c.find(m=>m.startIndex-t>=l&&m.startIndex-t<=u);if(l>0&&a.push({t:r.TextXActionType.RETAIN,len:l,segmentId:e}),d&&d.startIndex-t>l){const m=d.startIndex-t;a.push({t:r.TextXActionType.DELETE,len:m-l,line:0,segmentId:e}),a.push({t:r.TextXActionType.RETAIN,len:1,segmentId:e}),u>m+1&&a.push({t:r.TextXActionType.DELETE,len:u-m-1,line:0,segmentId:e})}else a.push({t:r.TextXActionType.DELETE,len:u-l,line:0,segmentId:e});return a}const Re={id:"doc.command.delete-left",type:r.CommandType.COMMAND,handler:async s=>{var T;const n=s.get(exports.TextSelectionManagerService),e=s.get(exports.DocSkeletonManagerService),t=s.get(r.IUniverInstanceService),o=s.get(r.ICommandService),i=n.getActiveRange(),a=n.getSelections(),c=(T=e.getCurrent())==null?void 0:T.skeleton;let l=!0;if(i==null||c==null||a==null)return!1;const u=t.getCurrentUniverDocInstance(),{startOffset:d,collapsed:m,segmentId:g,style:S}=i,v=c.findNodeByCharIndex(d),f=D.hasListSpan(v),p=D.isIndentBySpan(v,u.getBody());let _=d;const h=c.findNodeByCharIndex(d-1);if(D.isFirstSpan(v)&&h!==v&&(f===!0||p===!0)){const x=D.getParagraphBySpan(v,u.getBody());if(x==null)return!1;const E=x==null?void 0:x.startIndex,O={startIndex:0},R=x.paragraphStyle;if(f===!0){const I=x.paragraphStyle;I&&(O.paragraphStyle=I)}else if(p===!0){const I=x.bullet;I&&(O.bullet=I),R!=null&&(O.paragraphStyle={...R},delete O.paragraphStyle.hanging,delete O.paragraphStyle.indentStart)}const y=[{startOffset:_,endOffset:_,style:S}];l=await o.executeCommand(me.id,{unitId:u.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...O}]},range:{startOffset:E,endOffset:E+1},textRanges:y,coverType:r.UpdateDocsAttributeType.REPLACE,segmentId:g})}else if(m===!0){if(h==null)return!0;if(h.content==="\r")l=await o.executeCommand(Se.id,{direction:w.LEFT,range:i});else{_-=h.count;const x=[{startOffset:_,endOffset:_,style:S}];l=await o.executeCommand(z.id,{unitId:u.getUnitId(),range:i,segmentId:g,direction:w.LEFT,len:h.count,textRanges:x})}}else{const x=Oe(i,a);l=await o.executeCommand(ge.id,{segmentId:g,textRanges:x})}return l}},ye={id:"doc.command.delete-right",type:r.CommandType.COMMAND,handler:async s=>{var v;const n=s.get(exports.TextSelectionManagerService),e=s.get(exports.DocSkeletonManagerService),t=s.get(r.IUniverInstanceService),o=s.get(r.ICommandService),i=n.getActiveRange(),a=n.getSelections(),c=(v=e.getCurrent())==null?void 0:v.skeleton;let l;if(i==null||c==null||a==null)return!1;const u=t.getCurrentUniverDocInstance(),{startOffset:d,collapsed:m,segmentId:g,style:S}=i;if(d===u.getBody().dataStream.length-2&&m)return!0;if(m===!0){const f=c.findNodeByCharIndex(d);if(f.content==="\r")l=await o.executeCommand(Se.id,{direction:w.RIGHT,range:i});else{const p=[{startOffset:d,endOffset:d,style:S}];l=await o.executeCommand(z.id,{unitId:u.getUnitId(),range:i,segmentId:g,direction:w.RIGHT,textRanges:p,len:f.count})}}else{const f=Oe(i,a);l=await o.executeCommand(ge.id,{segmentId:g,textRanges:f})}return l}},Se={id:"doc.command.merge-two-paragraph",type:r.CommandType.COMMAND,handler:async(s,n)=>{var O,R,y;const e=s.get(exports.TextSelectionManagerService),t=s.get(r.IUniverInstanceService),o=s.get(r.ICommandService);s.get(r.IUndoRedoService);const{direction:i,range:a}=n,c=e.getActiveRange(),l=e.getSelections();if(c==null||l==null)return!1;const u=t.getCurrentUniverDocInstance(),{startOffset:d,collapsed:m,segmentId:g,style:S}=c;if(!m)return!1;const v=i===w.LEFT?d:d+1,f=(y=(R=(O=u.getBody())==null?void 0:O.paragraphs)==null?void 0:R.find(I=>I.startIndex>=v))==null?void 0:y.startIndex,p=st(u.getBody(),v,f),_=i===w.LEFT?d-1:d,h=u.getUnitId(),M=[{startOffset:_,endOffset:_,style:S}],T={id:U.id,params:{unitId:h,actions:[],textRanges:M,prevTextRanges:[a]}},x=new r.TextX;return x.push({t:r.TextXActionType.RETAIN,len:i===w.LEFT?d-1:d,segmentId:g}),p.dataStream.length&&x.push({t:r.TextXActionType.INSERT,body:p,len:p.dataStream.length,line:0,segmentId:g}),x.push({t:r.TextXActionType.RETAIN,len:1,segmentId:g}),x.push({t:r.TextXActionType.DELETE,len:f+1-v,line:0,segmentId:g}),T.params.actions=x.serialize(),!!o.syncExecuteCommand(T.id,T.params)}};function st(s,n,e){const{textRuns:t}=s,o=s.dataStream.substring(n,e);if(t==null)return{dataStream:o};const i=[];for(const a of t){const{st:c,ed:l}=a;l<=n||c>=e||(c<n?i.push({...a,st:0,ed:l-n}):l>e?i.push({...a,st:c-n,ed:e-n}):i.push({...a,st:c-n,ed:l-n}))}return{dataStream:o,textRuns:i}}function Oe(s,n){let e=s.endOffset;for(const o of n){const{startOffset:i,endOffset:a}=o;i==null||a==null||a<=s.endOffset&&(e-=a-i)}return[{startOffset:e,endOffset:e,style:s.style}]}const pe={id:"doc.command.ime-input",type:r.CommandType.COMMAND,handler:async(s,n)=>{const{unitId:e,newText:t,oldTextLen:o,isCompositionEnd:i,isCompositionStart:a}=n,c=s.get(r.ICommandService),l=s.get(j),u=l.getActiveRange();if(u==null)return!1;const{startOffset:d,style:m,segmentId:g}=u,S=t.length,v=[{startOffset:d+S,endOffset:d+S,collapsed:!0,style:m}],f={id:U.id,params:{unitId:e,actions:[],textRanges:v}},p=new r.TextX;!u.collapsed&&a?p.push(...ue(u,g)):p.push({t:r.TextXActionType.RETAIN,len:d,segmentId:g}),o>0&&p.push({t:r.TextXActionType.DELETE,len:o,line:0,segmentId:g}),p.push({t:r.TextXActionType.INSERT,body:{dataStream:t},len:t.length,line:0,segmentId:g}),f.params.actions=p.serialize(),f.params.noHistory=!i,f.params.isCompositionEnd=i;const _=c.syncExecuteCommand(f.id,f.params);return l.pushUndoRedoMutationParams(_,f.params),!!_}},H={id:"doc.command.set-inline-format-bold",type:r.CommandType.COMMAND,handler:async()=>!0},G={id:"doc.command.set-inline-format-italic",type:r.CommandType.COMMAND,handler:async()=>!0},Y={id:"doc.command.set-inline-format-underline",type:r.CommandType.COMMAND,handler:async()=>!0},W={id:"doc.command.set-inline-format-strikethrough",type:r.CommandType.COMMAND,handler:async()=>!0},L={id:"doc.command.set-inline-format-subscript",type:r.CommandType.COMMAND,handler:async()=>!0},Z={id:"doc.command.set-inline-format-superscript",type:r.CommandType.COMMAND,handler:async()=>!0},q={id:"doc.command.set-inline-format-fontsize",type:r.CommandType.COMMAND,handler:async()=>!0},K={id:"doc.command.set-inline-format-font-family",type:r.CommandType.COMMAND,handler:async()=>!0},J={id:"doc.command.set-inline-format-text-color",type:r.CommandType.COMMAND,handler:async()=>!0},De={[H.id]:"bl",[G.id]:"it",[Y.id]:"ul",[W.id]:"st",[q.id]:"fs",[K.id]:"ff",[J.id]:"cl",[L.id]:"va",[Z.id]:"va"},fe={id:"doc.command.set-inline-format",type:r.CommandType.COMMAND,handler:async(s,n)=>{const{segmentId:e,value:t,preCommandId:o}=n,i=s.get(r.ICommandService),a=s.get(exports.TextSelectionManagerService),c=s.get(r.IUniverInstanceService),l=a.getSelections();if(!Array.isArray(l)||l.length===0)return!1;let u=c.getCurrentUniverDocInstance(),d=u.getUnitId();d===r.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(u=c.getUniverDocInstance(r.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),d=u.getUnitId());let m;switch(o){case H.id:case G.id:case Y.id:case W.id:case L.id:case Z.id:{m=ct(u.getBody().textRuns,o,l);break}case q.id:case K.id:{m=t;break}case J.id:{m={rgb:t};break}default:throw new Error(`Unknown command: ${o} in handleInlineFormat`)}const g={id:U.id,params:{unitId:d,actions:[],textRanges:l.map(B)}},S=new r.TextX,v=new r.MemoryCursor;v.reset();for(const p of l){const{startOffset:_,endOffset:h}=p,M={dataStream:"",textRuns:[{st:0,ed:h-_,ts:{[De[o]]:m}}]},T=_-v.cursor;T!==0&&S.push({t:r.TextXActionType.RETAIN,len:T,segmentId:e}),S.push({t:r.TextXActionType.RETAIN,body:M,len:h-_,segmentId:e}),v.reset(),v.moveCursor(h)}return g.params.actions=S.serialize(),!!i.syncExecuteCommand(g.id,g.params)}};function at(s){return s!==null&&typeof s=="object"}function ct(s,n,e){let t=0,o=0;const i=De[n];for(;t!==s.length&&o!==e.length;){const{startOffset:a,endOffset:c}=e[o],{st:l,ed:u,ts:d}=s[t];if(c<=l)o++;else if(u<=a)t++;else{if(/bl|it/.test(i))return(d==null?void 0:d[i])===r.BooleanNumber.TRUE?r.BooleanNumber.FALSE:r.BooleanNumber.TRUE;if(/ul|st/.test(i))return at(d==null?void 0:d[i])&&(d==null?void 0:d[i]).s===r.BooleanNumber.TRUE?{s:r.BooleanNumber.FALSE}:{s:r.BooleanNumber.TRUE};if(/va/.test(i))return n===L.id?(d==null?void 0:d[i])===r.BaselineOffset.SUBSCRIPT?r.BaselineOffset.NORMAL:r.BaselineOffset.SUBSCRIPT:(d==null?void 0:d[i])===r.BaselineOffset.SUPERSCRIPT?r.BaselineOffset.NORMAL:r.BaselineOffset.SUPERSCRIPT;t++}}return/bl|it/.test(i)?r.BooleanNumber.TRUE:/ul|st/.test(i)?{s:r.BooleanNumber.TRUE}:n===L.id?r.BaselineOffset.SUBSCRIPT:r.BaselineOffset.SUPERSCRIPT}const he={id:"doc.command.list-operation",type:r.CommandType.COMMAND,handler:(s,n)=>{var x,E,O;const e=s.get(exports.TextSelectionManagerService),t=s.get(r.IUniverInstanceService),o=s.get(r.ICommandService),{listType:i}=n,a=t.getCurrentUniverDocInstance(),c=e.getActiveRange(),l=(x=e.getSelections())!=null?x:[],u=(E=a.getBody())==null?void 0:E.paragraphs,d=l.map(B);if(c==null||u==null)return!1;const m=lt(c,u),{segmentId:g}=c,S=a.getUnitId(),v=m.every(R=>{var y;return((y=R.bullet)==null?void 0:y.listType)===i});let p=r.Tools.generateRandomId(6);if(m.length===1){const R=u.indexOf(m[0]),y=u[R-1],I=u[R+1];y&&y.bullet&&y.bullet.listType===i?p=y.bullet.listId:I&&I.bullet&&I.bullet.listType===i&&(p=I.bullet.listId)}const _={id:U.id,params:{unitId:S,actions:[],textRanges:d}},h=new r.MemoryCursor;h.reset();const M=new r.TextX;for(const R of m){const{startIndex:y}=R;M.push({t:r.TextXActionType.RETAIN,len:y-h.cursor,segmentId:g});const I={...R.paragraphStyle,hanging:void 0,indentStart:void 0};M.push({t:r.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[v?{paragraphStyle:I,startIndex:0}:{...R,startIndex:0,bullet:{...(O=R.bullet)!=null?O:{nestingLevel:0,textStyle:{fs:20}},listType:i,listId:p}}]},segmentId:g,coverType:r.UpdateDocsAttributeType.REPLACE}),h.moveCursorTo(y+1)}return _.params.actions=M.serialize(),!!o.syncExecuteCommand(_.id,_.params)}},Ee={id:"doc.command.bullet-list",type:r.CommandType.COMMAND,handler:s=>s.get(r.ICommandService).syncExecuteCommand(he.id,{listType:r.PresetListType.BULLET_LIST})},Ae={id:"doc.command.order-list",type:r.CommandType.COMMAND,handler:s=>s.get(r.ICommandService).syncExecuteCommand(he.id,{listType:r.PresetListType.ORDER_LIST})};function lt(s,n){const{startOffset:e,endOffset:t}=s,o=[];let i=-1;for(const a of n){const{startIndex:c}=a;(e>i&&e<=c||t>i&&t<=c||c>=e&&c<=t)&&o.push(a),i=c}return o}const Ue={id:"doc.command-replace-content",type:r.CommandType.COMMAND,handler:async(s,n)=>{var S;const{unitId:e,body:t,textRanges:o,segmentId:i=""}=n,a=s.get(r.IUniverInstanceService),c=s.get(r.ICommandService),l=s.get(exports.TextSelectionManagerService),u=(S=a.getUniverDocInstance(e))==null?void 0:S.getSnapshot().body,d=l.getSelections();if(u==null||!Array.isArray(d)||d.length===0)return!1;const m=be(e,i,u,t);return m.params.textRanges=o,!!c.syncExecuteCommand(m.id,m.params)}},Ne={id:"doc.command-cover-content",type:r.CommandType.COMMAND,handler:async(s,n)=>{var d;const{unitId:e,body:t,segmentId:o=""}=n,i=s.get(r.IUniverInstanceService),a=s.get(r.ICommandService),c=s.get(r.IUndoRedoService),l=(d=i.getUniverDocInstance(e))==null?void 0:d.getSnapshot().body;if(l==null)return!1;const u=be(e,o,l,t);return u.params.noNeedSetTextRange=!0,u.params.noHistory=!0,a.syncExecuteCommand(u.id,u.params),c.clearUndoRedo(e),!0}};function be(s,n,e,t){const o={id:U.id,params:{unitId:s,actions:[],textRanges:[]}},i=new r.TextX,a=(e==null?void 0:e.dataStream.length)-2;return a>0&&i.push({t:r.TextXActionType.DELETE,len:a,line:0,segmentId:n}),t.dataStream.length>0&&i.push({t:r.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:n}),o.params.actions=i.serialize(),o}const re={id:"doc.operation.move-cursor",type:r.CommandType.OPERATION,handler:(s,n)=>!!n},ie={id:"doc.operation.move-selection",type:r.CommandType.OPERATION,handler:(s,n)=>!!n},dt=(s,n)=>{const e=s.get(r.IUniverInstanceService).getUniverDocInstance(n.unitId),t=(e==null?void 0:e.zoomRatio)||1;return{...r.Tools.deepClone(n),zoomRatio:t}},V={id:"doc.operation.set-zoom-ratio",type:r.CommandType.OPERATION,handler:(s,n)=>{const e=s.get(r.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}},Pe={type:r.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(s,n)=>{var m,g;const e=s.get(r.ICommandService),t=s.get(r.IUndoRedoService),o=s.get(r.IUniverInstanceService);let i=o.getCurrentUniverDocInstance().getUnitId(),a=1;if(n&&(i=(m=n.documentId)!=null?m:i,a=(g=n.zoomRatio)!=null?g:a),!o.getUniverDocInstance(i))return!1;const l={zoomRatio:a,unitId:i},u=dt(s,l);return e.syncExecuteCommand(V.id,l)?(t.pushUndoRedo({unitID:i,undoMutations:[{id:V.id,params:u}],redoMutations:[{id:V.id,params:l}]}),!0):!1}},we={id:"doc.operation.select-all",type:r.CommandType.COMMAND,handler:async s=>{const n=s.get(r.IUniverInstanceService),e=s.get(exports.TextSelectionManagerService),t=n.getCurrentUniverDocInstance().getSnapshot().body;if(t==null)return!1;const o=[{startOffset:0,endOffset:t.dataStream.length-2}];return e.replaceTextRanges(o,!1),!0}};var ut=Object.defineProperty,mt=Object.getOwnPropertyDescriptor,gt=(s,n,e,t)=>{for(var o=t>1?void 0:t?mt(n,e):n,i=s.length-1,a;i>=0;i--)(a=s[i])&&(o=(t?a(n,e,o):a(o))||o);return t&&o&&ut(n,e,o),o},$=(s,n)=>(e,t)=>n(e,t,s);let ee=class extends r.Disposable{constructor(n,e,t,o,i){super();C(this,"_previousIMEContent","");C(this,"_isCompositionStart",!0);C(this,"_onStartSubscription");C(this,"_onUpdateSubscription");C(this,"_onEndSubscription");this._docSkeletonManagerService=n,this._currentUniverService=e,this._textSelectionRenderManager=t,this._imeInputManagerService=o,this._commandService=i,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;const{activeRange:e}=n;e!=null&&(this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(r.Tools.deepClone(e)),this._isCompositionStart=!0)})}_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 u;const t=(u=this._docSkeletonManagerService.getCurrent())==null?void 0:u.skeleton;if(n==null||t==null)return;const o=this._currentUniverService.getCurrentUniverDocInstance(),{event:i,activeRange:a}=n;if(t==null||a==null)return;const l=i.data;l===this._previousIMEContent&&e||(await this._commandService.executeCommand(pe.id,{unitId:o.getUnitId(),newText:l,oldTextLen:this._previousIMEContent.length,isCompositionStart:this._isCompositionStart,isCompositionEnd:!e}),e?(this._isCompositionStart&&(this._isCompositionStart=!1),this._previousIMEContent=l):this._resetIME())}_resetIME(){this._previousIMEContent="",this._isCompositionStart=!0,this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(null)}};ee=gt([r.OnLifecycle(r.LifecycleStages.Rendered,ee),$(0,A.Inject(exports.DocSkeletonManagerService)),$(1,r.IUniverInstanceService),$(2,D.ITextSelectionRenderManager),$(3,A.Inject(j)),$(4,r.ICommandService)],ee);var St=Object.defineProperty,pt=Object.getOwnPropertyDescriptor,ft=(s,n,e,t)=>{for(var o=t>1?void 0:t?pt(n,e):n,i=s.length-1,a;i>=0;i--)(a=s[i])&&(o=(t?a(n,e,o):a(o))||o);return t&&o&&St(n,e,o),o},Ce=(s,n)=>(e,t)=>n(e,t,s);let te=class extends r.Disposable{constructor(s,n){super(),this._textSelectionManagerService=s,this._commandService=n,this._commandExecutedListener()}_commandExecutedListener(){const s=[H.id,G.id,Y.id,W.id,L.id,Z.id,q.id,K.id,J.id];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{s.includes(n.id)&&this._handleInlineFormat(n)}))}_handleInlineFormat(s){var e,t;const{segmentId:n}=(e=this._textSelectionManagerService.getActiveRange())!=null?e:{};n!=null&&this._commandService.executeCommand(fe.id,{segmentId:n,preCommandId:s.id,...(t=s.params)!=null?t:{}})}};te=ft([r.OnLifecycle(r.LifecycleStages.Rendered,te),Ce(0,A.Inject(exports.TextSelectionManagerService)),Ce(1,r.ICommandService)],te);var ht=Object.defineProperty,vt=Object.getOwnPropertyDescriptor,_t=(s,n,e,t)=>{for(var o=t>1?void 0:t?vt(n,e):n,i=s.length-1,a;i>=0;i--)(a=s[i])&&(o=(t?a(n,e,o):a(o))||o);return t&&o&&ht(n,e,o),o},F=(s,n)=>(e,t)=>n(e,t,s);let ne=class extends r.Disposable{constructor(n,e,t,o,i){super();C(this,"_onInputSubscription");this._docSkeletonManagerService=n,this._currentUniverService=e,this._renderManagerService=t,this._textSelectionManagerService=o,this._commandService=i,this._initialize(),this._commandExecutedListener()}dispose(){var n;(n=this._onInputSubscription)==null||n.unsubscribe()}_initialize(){}_commandExecutedListener(){const n=[re.id,ie.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!n.includes(e.id))return;const t=e.params;switch(e.id){case re.id:return this._handleMoveCursor(t.direction);case ie.id:return this._handleShiftMoveSelection(t.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(n){var f,p,_;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),o=this._currentUniverService.getCurrentUniverDocInstance(),i=(f=this._docSkeletonManagerService.getCurrent())==null?void 0:f.skeleton,a=this._getDocObject();if(e==null||i==null||a==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d,direction:m}=e;if(t.length>1){let h=Number.POSITIVE_INFINITY,M=Number.NEGATIVE_INFINITY;for(const T of t)h=Math.min(h,T.startOffset),M=Math.max(M,T.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:n===r.Direction.LEFT||n===r.Direction.UP?M:h,endOffset:n===r.Direction.LEFT||n===r.Direction.UP?h:M,style:u}],!1);return}const g=d||m===D.RANGE_DIRECTION.FORWARD?c:l;let S=d||m===D.RANGE_DIRECTION.FORWARD?l:c;const v=(p=o.getBody().dataStream.length)!=null?p:Number.POSITIVE_INFINITY;if(n===r.Direction.LEFT||n===r.Direction.RIGHT){const h=i.findNodeByCharIndex(S-1),M=i.findNodeByCharIndex(S);S=n===r.Direction.RIGHT?S+M.count:S-((_=h==null?void 0:h.count)!=null?_:0),S=Math.min(v-2,Math.max(0,S)),this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:S,style:u}],!1)}else{const h=i.findNodeByCharIndex(S),M=a.document.getOffsetConfig(),T=this._getTopOrBottomPosition(i,h,n===r.Direction.DOWN);if(T==null){const E=n===r.Direction.UP?0:v-2;if(E===S)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:E,style:u}],!1);return}const x=new D.NodePositionConvertToCursor(M,i).getRangePointData(T,T).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:x.endOffset,style:u}],!1)}}_handleMoveCursor(n){var g,S,v;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),o=this._currentUniverService.getCurrentUniverDocInstance(),i=(g=this._docSkeletonManagerService.getCurrent())==null?void 0:g.skeleton,a=this._getDocObject();if(e==null||i==null||a==null||t==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d}=e,m=(S=o.getBody().dataStream.length)!=null?S:Number.POSITIVE_INFINITY;if(n===r.Direction.LEFT||n===r.Direction.RIGHT){let f;if(!e.collapsed||t.length>1){let p=Number.POSITIVE_INFINITY,_=Number.NEGATIVE_INFINITY;for(const h of t)p=Math.min(p,h.startOffset),_=Math.max(_,h.endOffset);f=n===r.Direction.LEFT?p:_}else{const p=i.findNodeByCharIndex(c-1),_=i.findNodeByCharIndex(c);n===r.Direction.LEFT?f=Math.max(0,c-((v=p==null?void 0:p.count)!=null?v:0)):f=Math.min(m-2,l+_.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:f,style:u}],!1)}else{const f=i.findNodeByCharIndex(c),p=i.findNodeByCharIndex(l),_=a.document.getOffsetConfig(),h=this._getTopOrBottomPosition(i,n===r.Direction.UP?f:p,n===r.Direction.DOWN);if(h==null){let T;d?T=n===r.Direction.UP?0:m-2:T=n===r.Direction.UP?c:l,this._textSelectionManagerService.replaceTextRanges([{startOffset:T,endOffset:T,style:u}],!1);return}const M=new D.NodePositionConvertToCursor(_,i).getRangePointData(h,h).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...M,style:u}],!1)}}_getTopOrBottomPosition(n,e,t){if(e==null)return;const o=this._getSpanLeftOffsetInLine(e),i=this._getNextOrPrevLine(e,t);if(i==null)return;const a=this._matchPositionByLeftOffset(n,i,o);if(a!=null)return{...a,isBack:!0}}_getSpanLeftOffsetInLine(n){const e=n.parent;if(e==null)return Number.NEGATIVE_INFINITY;const t=e.left,{left:o}=n;return t+o}_matchPositionByLeftOffset(n,e,t){const o={distance:Number.POSITIVE_INFINITY};for(const i of e.divides){const a=i.left;for(const c of i.spanGroup){const{left:l}=c,u=a+l,d=Math.abs(t-u);d<o.distance&&(o.span=c,o.distance=d)}}if(o.span!=null)return n.findPositionBySpan(o.span)}_getNextOrPrevLine(n,e){var v,f,p,_,h,M,T,x,E,O,R,y;const t=n.parent;if(t==null)return;const o=t.parent;if(o==null)return;const i=o.parent;if(i==null)return;const a=i.lines.indexOf(o);if(a===-1)return;let c;if(e===!0?c=i.lines[a+1]:c=i.lines[a-1],c!=null)return c;const l=i.parent;if(l==null)return;const u=l.columns.indexOf(i);if(u===-1)return;if(e===!0)c=(v=l.columns[u+1])==null?void 0:v.lines[0];else{const I=(p=(f=l.columns)==null?void 0:f[u-1])==null?void 0:p.lines;c=I==null?void 0:I[I.length-1]}if(c!=null)return c;const d=l.parent;if(d==null)return;const m=d.sections.indexOf(l);if(m===-1)return;if(e===!0)c=(h=(_=d.sections[m-1])==null?void 0:_.columns[0])==null?void 0:h.lines[0];else{const I=(T=(M=d.sections)==null?void 0:M[m-1])==null?void 0:T.columns,P=I==null?void 0:I[I.length-1],N=P==null?void 0:P.lines;c=N==null?void 0:N[N.length-1]}if(c!=null)return c;const g=d.parent;if(g==null)return;const S=g.pages.indexOf(d);if(S!==-1){if(e===!0)c=(O=(E=(x=g.pages[S+1])==null?void 0:x.sections[0])==null?void 0:E.columns[0])==null?void 0:O.lines[0];else{const I=(R=g.pages[S-1])==null?void 0:R.sections;if(I==null)return;const P=(y=I[I.length-1])==null?void 0:y.columns,N=P[P.length-1],ve=N==null?void 0:N.lines;c=ve[ve.length-1]}if(c!=null)return c}}_getDocObject(){return le(this._currentUniverService,this._renderManagerService)}};ne=_t([r.OnLifecycle(r.LifecycleStages.Rendered,ne),F(0,A.Inject(exports.DocSkeletonManagerService)),F(1,r.IUniverInstanceService),F(2,D.IRenderManagerService),F(3,A.Inject(exports.TextSelectionManagerService)),F(4,r.ICommandService)],ne);var It=Object.defineProperty,Ct=Object.getOwnPropertyDescriptor,Mt=(s,n,e,t)=>{for(var o=t>1?void 0:t?Ct(n,e):n,i=s.length-1,a;i>=0;i--)(a=s[i])&&(o=(t?a(n,e,o):a(o))||o);return t&&o&&It(n,e,o),o},X=(s,n)=>(e,t)=>n(e,t,s);let oe=class extends r.Disposable{constructor(n,e,t,o,i){super();C(this,"_onInputSubscription");this._docSkeletonManagerService=n,this._currentUniverService=e,this._renderManagerService=t,this._textSelectionRenderManager=o,this._commandService=i,this._initialize(),this._commandExecutedListener()}dispose(){var n;(n=this._onInputSubscription)==null||n.unsubscribe()}_initialize(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async n=>{var v;if(n==null)return;const t=this._currentUniverService.getCurrentUniverDocInstance().getUnitId(),{event:o,content:i="",activeRange:a}=n,c=o,l=(v=this._docSkeletonManagerService.getCurrent())==null?void 0:v.skeleton;if(c.data==null||l==null||!l||!a)return;const{startOffset:u,segmentId:d,style:m}=a,g=i.length,S=[{startOffset:u+g,endOffset:u+g,style:m}];await this._commandService.executeCommand(k.id,{unitId:t,body:{dataStream:i},range:a,textRanges:S,segmentId:d})})}_commandExecutedListener(){}_getDocObject(){return le(this._currentUniverService,this._renderManagerService)}};oe=Mt([r.OnLifecycle(r.LifecycleStages.Rendered,oe),X(0,A.Inject(exports.DocSkeletonManagerService)),X(1,r.IUniverInstanceService),X(2,D.IRenderManagerService),X(3,D.ITextSelectionRenderManager),X(4,r.ICommandService)],oe);var Tt=Object.defineProperty,xt=Object.getOwnPropertyDescriptor,Rt=(s,n,e,t)=>{for(var o=t>1?void 0:t?xt(n,e):n,i=s.length-1,a;i>=0;i--)(a=s[i])&&(o=(t?a(n,e,o):a(o))||o);return t&&o&&Tt(n,e,o),o},Q=(s,n)=>(e,t)=>n(e,t,s);const yt={hasScroll:!0},Ot="docs";var ce;exports.UniverDocsPlugin=(ce=class extends r.Plugin{constructor(e={},t,o,i,a){super(Ot);C(this,"_config");this._injector=t,this._localeService=o,this._configService=i,this._currentUniverService=a,this._config=Object.assign(yt,e),this._initializeDependencies(t),this._initializeCommands()}initialize(){}_initializeCommands(){[re,ie,Re,ye,H,G,Y,W,L,Z,q,K,J,fe,xe,k,z,me,pe,Se,U,Ue,Ne,Pe,V,de,we,Ae,Ee,he].forEach(e=>{this._injector.get(r.ICommandService).registerCommand(e)})}onReady(){this.initialize()}_initializeDependencies(e){[[exports.DocSkeletonManagerService],[exports.DocViewModelManagerService],[exports.DocStateChangeManagerService],[j],[D.ITextSelectionRenderManager,{useClass:D.TextSelectionRenderManager}],[exports.TextSelectionManagerService],[oe],[ee],[te],[ne]].forEach(t=>e.add(t))}},C(ce,"type",r.PluginType.Doc),ce);exports.UniverDocsPlugin=Rt([Q(1,A.Inject(A.Injector)),Q(2,A.Inject(r.LocaleService)),Q(3,r.IConfigService),Q(4,r.IUniverInstanceService)],exports.UniverDocsPlugin);exports.BreakLineCommand=xe;exports.BulletListCommand=Ee;exports.CoverContentCommand=Ne;exports.CutContentCommand=ge;exports.DOCS_COMPONENT_DEFAULT_Z_INDEX=Ve;exports.DOCS_COMPONENT_HEADER_LAYER_INDEX=Xe;exports.DOCS_COMPONENT_MAIN_LAYER_INDEX=Fe;exports.DOCS_VIEW_KEY=Me;exports.DeleteCommand=z;exports.DeleteLeftCommand=Re;exports.DeleteRightCommand=ye;exports.IMEInputCommand=pe;exports.IMEInputManagerService=j;exports.InnerPasteCommand=rt;exports.InsertCommand=k;exports.MoveCursorOperation=re;exports.MoveSelectionOperation=ie;exports.NORMAL_TEXT_SELECTION_PLUGIN_NAME=je;exports.OrderListCommand=Ae;exports.ReplaceContentCommand=Ue;exports.RichTextEditingMutation=U;exports.SelectAllOperation=we;exports.SetDocZoomRatioCommand=Pe;exports.SetDocZoomRatioOperation=V;exports.SetInlineFormatBoldCommand=H;exports.SetInlineFormatCommand=fe;exports.SetInlineFormatFontFamilyCommand=K;exports.SetInlineFormatFontSizeCommand=q;exports.SetInlineFormatItalicCommand=G;exports.SetInlineFormatStrikethroughCommand=W;exports.SetInlineFormatSubscriptCommand=L;exports.SetInlineFormatSuperscriptCommand=Z;exports.SetInlineFormatTextColorCommand=J;exports.SetInlineFormatUnderlineCommand=Y;exports.SetTextSelectionsOperation=de;exports.UpdateCommand=me;exports.VIEWPORT_KEY=Te;exports.getDocObject=le;exports.getDocObjectById=$e;exports.serializeTextRange=B;
1
+ "use strict";var Le=Object.defineProperty;var Be=(s,n,e)=>n in s?Le(s,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[n]=e;var C=(s,n,e)=>(Be(s,typeof n!="symbol"?n+"":n,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@univerjs/core"),D=require("@univerjs/engine-render"),b=require("rxjs"),A=require("@wendellhu/redi");function le(s,n){const t=s.getCurrentUniverDocInstance().getUnitId(),o=n.getRenderById(t);if(o==null)return;const{mainComponent:i,scene:a,engine:c}=o;return{document:i,scene:a,engine:c}}function $e(s,n){const e=n.getRenderById(s);if(e==null)return;const{mainComponent:t,scene:o,engine:i}=e;return{document:t,scene:o,engine:i}}var Me=(s=>(s.MAIN="__Document_Render_Main__",s))(Me||{}),Te=(s=>(s.VIEW_MAIN="viewMain",s.VIEW_TOP="viewTop",s.VIEW_LEFT="viewLeft",s.VIEW_LEFT_TOP="viewLeftTop",s))(Te||{});const Fe=0,Xe=2,Ve=10,je="normalTextSelectionPluginName",de={id:"doc.operation.set-selections",type:r.CommandType.OPERATION,handler:(s,n)=>!0};var ke=Object.defineProperty,ze=Object.getOwnPropertyDescriptor,He=(s,n,e,t)=>{for(var o=t>1?void 0:t?ze(n,e):n,i=s.length-1,a;i>=0;i--)(a=s[i])&&(o=(t?a(n,e,o):a(o))||o);return t&&o&&ke(n,e,o),o},_e=(s,n)=>(e,t)=>n(e,t,s);function B(s){const{startOffset:n,endOffset:e,collapsed:t}=s,o={startOffset:n,endOffset:e,collapsed:t};return typeof s.isActive=="function"&&(o.isActive=s.isActive()),o}exports.TextSelectionManagerService=class extends r.RxDisposable{constructor(e,t){super();C(this,"_currentSelection",null);C(this,"_textSelectionInfo",new Map);C(this,"_textSelection$",new b.BehaviorSubject(null));C(this,"textSelection$",this._textSelection$.asObservable());this._textSelectionRenderManager=e,this._commandService=t,this._syncSelectionFromRenderService()}getCurrentSelection(){return this._currentSelection}getCurrentSelectionInfo(){return this._getTextRanges(this._currentSelection)}dispose(){this._textSelection$.complete()}refreshSelection(){this._currentSelection!=null&&this._refresh(this._currentSelection)}setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}setCurrentSelectionNotRefresh(e){this._currentSelection=e}getSelections(){var e;return(e=this._getTextRanges(this._currentSelection))==null?void 0:e.textRanges}getActiveRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:t,segmentId:o,style:i}=e,a=t.find(S=>S.isActive());if(a==null)return null;const{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:m,direction:g}=a;return c==null||l==null?null:{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:m,direction:g,segmentId:o,style:i}}add(e,t=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,segmentId:"",isEditing:t,style:D.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(b.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._replaceTextRangesWithNoRefresh(e)})}_replaceTextRangesWithNoRefresh(e){if(this._currentSelection==null)return;const t={...this._currentSelection,...e};this._replaceByParam(t),this._textSelection$.next(t);const{unitId:o,subUnitId:i,segmentId:a,style:c,textRanges:l,isEditing:u}=t;this._commandService.executeCommand(de.id,{unitId:o,subUnitId:i,segmentId:a,style:c,isEditing:u,ranges:l.map(B)})}_getTextRanges(e){var i;if(e==null)return;const{unitId:t,subUnitId:o=""}=e;return(i=this._textSelectionInfo.get(t))==null?void 0:i.get(o)}_refresh(e){const t=this._getTextRanges(e);this._textSelectionRenderManager.removeAllTextRanges(),t&&Array.isArray(t.textRanges)&&t.textRanges.length&&this._textSelectionRenderManager.addTextRanges(t.textRanges.map(B))}_replaceByParam(e){const{unitId:t,subUnitId:o,style:i,segmentId:a,textRanges:c,isEditing:l}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(o,{textRanges:c,style:i,segmentId:a,isEditing:l})}_addByParam(e){const{unitId:t,subUnitId:o,textRanges:i,style:a,segmentId:c,isEditing:l}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);const u=this._textSelectionInfo.get(t);u.has(o)?u.get(o).textRanges.push(...i):u.set(o,{textRanges:i,style:a,segmentId:c,isEditing:l})}};exports.TextSelectionManagerService=He([_e(0,D.ITextSelectionRenderManager),_e(1,r.ICommandService)],exports.TextSelectionManagerService);function ue(s,n="",e=0){const{startOffset:t,endOffset:o}=s,i=[],a=t-e,c=o-e;return a>0&&i.push({t:r.TextXActionType.RETAIN,len:a,segmentId:n}),i.push({t:r.TextXActionType.DELETE,len:c-a,line:0,segmentId:n}),i}var Ge=Object.defineProperty,Ye=Object.getOwnPropertyDescriptor,We=(s,n,e,t)=>{for(var o=t>1?void 0:t?Ye(n,e):n,i=s.length-1,a;i>=0;i--)(a=s[i])&&(o=(t?a(n,e,o):a(o))||o);return t&&o&&Ge(n,e,o),o},Ze=(s,n)=>(e,t)=>n(e,t,s);exports.DocViewModelManagerService=class extends r.RxDisposable{constructor(e){super();C(this,"_docViewModelMap",new Map);C(this,"_currentDocViewModel$",new b.BehaviorSubject(null));C(this,"currentDocViewModel$",this._currentDocViewModel$.asObservable());this._currentUniverService=e,this._initialize()}_initialize(){this._init()}dispose(){this._currentDocViewModel$.complete(),this._docViewModelMap.clear()}_init(){this._currentUniverService.currentDoc$.pipe(b.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)}),this._currentUniverService.getAllUniverDocsInstance().forEach(e=>{this._create(e)}),this._currentUniverService.docDisposed$.pipe(b.takeUntil(this.dispose$)).subscribe(e=>{this._docViewModelMap.delete(e.getUnitId())})}_create(e){if(e==null)return;const t=e.getUnitId();this._setCurrent(t)}getAllModel(){return this._docViewModelMap}getViewModel(e){var t;return(t=this._docViewModelMap.get(e))==null?void 0:t.docViewModel}_setCurrent(e){var o;const t=this._currentUniverService.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 i=this._buildDocViewModel(t);this._docViewModelMap.set(e,{unitId:e,docViewModel:i})}if(e===r.DOCS_NORMAL_EDITOR_UNIT_ID_KEY){const i=(o=this._docViewModelMap.get(e))==null?void 0:o.docViewModel;if(i==null)return;i.reset(t)}this._currentDocViewModel$.next(this._docViewModelMap.get(e))}}_buildDocViewModel(e){return new D.DocumentViewModel(e)}};exports.DocViewModelManagerService=We([Ze(0,r.IUniverInstanceService)],exports.DocViewModelManagerService);var qe=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,Je=(s,n,e,t)=>{for(var o=t>1?void 0:t?Ke(n,e):n,i=s.length-1,a;i>=0;i--)(a=s[i])&&(o=(t?a(n,e,o):a(o))||o);return t&&o&&qe(n,e,o),o},se=(s,n)=>(e,t)=>n(e,t,s);const Qe=300;exports.DocStateChangeManagerService=class extends r.RxDisposable{constructor(e,t,o){super();C(this,"_docStateChange$",new b.BehaviorSubject(null));C(this,"docStateChange$",this._docStateChange$.asObservable());C(this,"_stateCache",new Map);C(this,"_timer",null);this._undoRedoService=e,this._commandService=t,this._univerInstanceService=o,this._initialize()}setChangeState(e){const{trigger:t,noHistory:o}=e;t!=null&&(this._cacheChangeState(e),o||this._docStateChange$.next(e))}_initialize(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===r.UndoCommandId||e.id===r.RedoCommandId){const t=this._univerInstanceService.getCurrentUniverDocInstance();if(t==null)return;const o=t.getUnitId();this._pushHistory(o)}}))}_cacheChangeState(e){const{trigger:t,unitId:o,noHistory:i}=e;if(!(t===r.RedoCommandId||t===r.UndoCommandId||i)){if(this._stateCache.has(o)){const a=this._stateCache.get(o);a==null||a.push(e)}else this._stateCache.set(o,[e]);t===k.id||t===z.id?(this._timer&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._pushHistory(o)},Qe)):this._pushHistory(o)}}_pushHistory(e){const t=this._undoRedoService,o=this._stateCache.get(e);if(!Array.isArray(o)||o.length===0)return;const i=o.length,a=o[0].commandId,c=o[0],l=o[i-1],u={unitId:e,actions:o.reduce((m,g)=>r.TextX.compose(m,g.redoState.actions),[]),textRanges:l.redoState.textRanges},d={unitId:e,actions:o.reverse().reduce((m,g)=>r.TextX.compose(m,g.undoState.actions),[]),textRanges:c.undoState.textRanges};t.pushUndoRedo({unitID:e,undoMutations:[{id:a,params:d}],redoMutations:[{id:a,params:u}]}),o.length=0}};exports.DocStateChangeManagerService=Je([se(0,A.Inject(r.IUndoRedoService)),se(1,r.ICommandService),se(2,r.IUniverInstanceService)],exports.DocStateChangeManagerService);class j{constructor(){C(this,"_previousActiveRange",null);C(this,"_undoMutationParamsCache",[]);C(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache:n=[],redoCache:e=[]}){this._undoMutationParamsCache=n,this._redoMutationParamsCache=e}getActiveRange(){return this._previousActiveRange}setActiveRange(n){this._previousActiveRange=n}pushUndoRedoMutationParams(n,e){this._undoMutationParamsCache.push(n),this._redoMutationParamsCache.push(e)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:n}=this._undoMutationParamsCache[0],e={unitId:n,actions:this._undoMutationParamsCache.reverse().reduce((o,i)=>r.TextX.compose(o,i.actions),[]),textRanges:[]};return{redoMutationParams:{unitId:n,actions:this._redoMutationParamsCache.reduce((o,i)=>r.TextX.compose(o,i.actions),[]),textRanges:[]},undoMutationParams:e,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Ie="doc.mutation.rich-text-editing",U={id:Ie,type:r.CommandType.MUTATION,handler:(s,n)=>{var y;const{unitId:e,actions:t,textRanges:o,prevTextRanges:i,trigger:a,noHistory:c,isCompositionEnd:l,noNeedSetTextRange:u}=n,m=s.get(r.IUniverInstanceService).getUniverDocInstance(e),S=s.get(exports.DocViewModelManagerService).getViewModel(e),v=s.get(exports.TextSelectionManagerService),p=((y=v.getSelections())!=null?y:[]).map(B),_=s.get(exports.DocStateChangeManagerService),h=s.get(j);if(m==null||S==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);if(t.length===0)return{unitId:e,actions:[],textRanges:p};const M=m.apply(t),{segmentId:T}=t[0],x=m.getSelfOrHeaderFooterModel(T);S.getSelfOrHeaderFooterViewModel(T).reset(x),!u&&o&&a!=null&&queueMicrotask(()=>{v.replaceTextRanges(o)});const O={commandId:Ie,unitId:e,trigger:a,noHistory:c,redoState:{actions:t,textRanges:o},undoState:{actions:M,textRanges:i!=null?i:p}};if(l){const R=h.fetchComposedUndoRedoMutationParams();if(R==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:I,redoMutationParams:P,previousActiveRange:N}=R;O.redoState.actions=P.actions,O.undoState.actions=I.actions,O.undoState.textRanges=[N]}return _.setChangeState(O),{unitId:e,actions:M,textRanges:p}}},k={id:"doc.command.insert-text",type:r.CommandType.COMMAND,handler:async(s,n)=>{const e=s.get(r.ICommandService),{range:t,segmentId:o,body:i,unitId:a,textRanges:c}=n,{startOffset:l,collapsed:u}=t,d={id:U.id,params:{unitId:a,actions:[],textRanges:c}},m=new r.TextX;return u?l>0&&m.push({t:r.TextXActionType.RETAIN,len:l,segmentId:o}):m.push(...ue(t,o)),m.push({t:r.TextXActionType.INSERT,body:i,len:i.dataStream.length,line:0,segmentId:o}),d.params.actions=m.serialize(),!!e.syncExecuteCommand(d.id,d.params)}};var w=(s=>(s[s.LEFT=0]="LEFT",s[s.RIGHT=1]="RIGHT",s))(w||{});const z={id:"doc.command.delete-text",type:r.CommandType.COMMAND,handler:async(s,n)=>{const e=s.get(r.ICommandService),{range:t,segmentId:o,unitId:i,direction:a,textRanges:c,len:l=1}=n,{startOffset:u}=t,d={id:U.id,params:{unitId:i,actions:[],textRanges:c}},m=new r.TextX;return u>0&&m.push({t:r.TextXActionType.RETAIN,len:a===0?u-l:u,segmentId:o}),m.push({t:r.TextXActionType.DELETE,len:l,line:0,segmentId:o}),d.params.actions=m.serialize(),!!e.syncExecuteCommand(d.id,d.params)}},me={id:"doc.command.update-text",type:r.CommandType.COMMAND,handler:async(s,n)=>{const{range:e,segmentId:t,updateBody:o,coverType:i,unitId:a,textRanges:c}=n,l=s.get(r.ICommandService),u={id:U.id,params:{unitId:a,actions:[],textRanges:c}},d=new r.TextX,{startOffset:m,endOffset:g}=e;return d.push({t:r.TextXActionType.RETAIN,len:m,segmentId:t}),d.push({t:r.TextXActionType.RETAIN,body:o,len:g-m,segmentId:t,coverType:i}),u.params.actions=d.serialize(),!!l.syncExecuteCommand(u.id,u.params)}};function et(s,n){const e=[];for(let t=0,o=s.length;t<o;t++)s[t]===r.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});if(n)for(const t of e)n.bullet&&(t.bullet=r.Tools.deepClone(n.bullet)),n.paragraphStyle&&(t.paragraphStyle=r.Tools.deepClone(n.paragraphStyle));return e}const xe={id:"doc.command.break-line",type:r.CommandType.COMMAND,handler:async s=>{var v,f;const n=s.get(exports.TextSelectionManagerService),e=s.get(r.IUniverInstanceService),t=s.get(r.ICommandService),o=n.getActiveRange();if(o==null)return!1;const i=e.getCurrentUniverDocInstance(),a=i.getUnitId(),{startOffset:c,segmentId:l,style:u}=o,d=[{startOffset:c+1,endOffset:c+1,style:u}],g=((f=(v=i.getBody())==null?void 0:v.paragraphs)!=null?f:[]).find(p=>p.startIndex>=c);return await t.executeCommand(k.id,{unitId:a,body:{dataStream:r.DataStreamTreeTokenType.PARAGRAPH,paragraphs:et(r.DataStreamTreeTokenType.PARAGRAPH,g)},range:o,textRanges:d,segmentId:l})}};var tt=Object.defineProperty,nt=Object.getOwnPropertyDescriptor,ot=(s,n,e,t)=>{for(var o=t>1?void 0:t?nt(n,e):n,i=s.length-1,a;i>=0;i--)(a=s[i])&&(o=(t?a(n,e,o):a(o))||o);return t&&o&&tt(n,e,o),o},ae=(s,n)=>(e,t)=>n(e,t,s);exports.DocSkeletonManagerService=class extends r.RxDisposable{constructor(e,t,o){super();C(this,"_currentSkeletonUnitId","");C(this,"_docSkeletonMap",new Map);C(this,"_currentSkeleton$",new b.BehaviorSubject(null));C(this,"currentSkeleton$",this._currentSkeleton$.asObservable());C(this,"_currentSkeletonBefore$",new b.BehaviorSubject(null));C(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._localeService=e,this._docViewModelManagerService=t,this._currentUniverService=o,this._initialize()}_initialize(){this._init()}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._docSkeletonMap.clear()}_init(){this._docViewModelManagerService.currentDocViewModel$.pipe(b.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._setCurrent(e)}),this._docViewModelManagerService.getAllModel().forEach(e=>{e!=null&&this._setCurrent(e)}),this._currentUniverService.docDisposed$.pipe(b.takeUntil(this.dispose$)).subscribe(e=>{this._docSkeletonMap.delete(e.getUnitId()),this._currentSkeletonUnitId=this._currentUniverService.getCurrentUniverDocInstance().getUnitId()})}getCurrent(){return this.getSkeletonByUnitId(this._currentSkeletonUnitId)}getAllSkeleton(){return this._docSkeletonMap}makeDirtyCurrent(e=!0){this.makeDirty(this._currentSkeletonUnitId,e)}makeDirty(e,t=!0){const o=this.getSkeletonByUnitId(e);o!=null&&(o.dirty=t)}getSkeletonByUnitId(e){return this._docSkeletonMap.get(e)}_setCurrent(e){const{unitId:t}=e;if(this._docSkeletonMap.has(t)){const o=this.getSkeletonByUnitId(t);o.skeleton.calculate(),o.dirty=!0}else{const o=this._buildSkeleton(e.docViewModel);o.calculate(),this._docSkeletonMap.set(t,{unitId:t,skeleton:o,dirty:!1})}return this._currentSkeletonUnitId=t,this._currentSkeletonBefore$.next(this.getCurrent()),this._currentSkeleton$.next(this.getCurrent()),this.getCurrent()}_buildSkeleton(e){return D.DocumentSkeleton.create(e,this._localeService)}};exports.DocSkeletonManagerService=ot([ae(0,A.Inject(r.LocaleService)),ae(1,A.Inject(exports.DocViewModelManagerService)),ae(2,r.IUniverInstanceService)],exports.DocSkeletonManagerService);const rt={id:"doc.command.inner-paste",type:r.CommandType.COMMAND,handler:async(s,n)=>{const{segmentId:e,body:t,textRanges:o}=n,i=s.get(r.ICommandService),a=s.get(exports.TextSelectionManagerService),c=s.get(r.IUniverInstanceService),l=a.getSelections();if(!Array.isArray(l)||l.length===0)return!1;const d=c.getCurrentUniverDocInstance().getUnitId(),m={id:U.id,params:{unitId:d,actions:[],textRanges:o}},g=new r.MemoryCursor;g.reset();const S=new r.TextX;for(const f of l){const{startOffset:p,endOffset:_,collapsed:h}=f,M=p-g.cursor;h?S.push({t:r.TextXActionType.RETAIN,len:M,segmentId:e}):S.push(...ue(f,e,g.cursor)),S.push({t:r.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:e}),g.reset(),g.moveCursor(_)}return m.params.actions=S.serialize(),!!i.syncExecuteCommand(m.id,m.params)}},ge={id:"doc.command.inner-cut",type:r.CommandType.COMMAND,handler:async(s,n)=>{const{segmentId:e,textRanges:t}=n,o=s.get(r.ICommandService),i=s.get(exports.TextSelectionManagerService),a=s.get(r.IUniverInstanceService),c=i.getSelections();if(!Array.isArray(c)||c.length===0)return!1;const l=a.getCurrentUniverDocInstance().getUnitId(),u=a.getUniverDocInstance(l),d=r.getDocsUpdateBody(u.snapshot,e);if(d==null)return!1;const m={id:U.id,params:{unitId:l,actions:[],textRanges:t}},g=new r.MemoryCursor;g.reset();const S=new r.TextX;for(const f of c){const{startOffset:p,endOffset:_,collapsed:h}=f,M=p-g.cursor;h?S.push({t:r.TextXActionType.RETAIN,len:M,segmentId:e}):S.push(...it(f,d,e,g.cursor)),g.reset(),g.moveCursor(_)}return m.params.actions=S.serialize(),!!o.syncExecuteCommand(m.id,m.params)}};function it(s,n,e="",t=0){const{startOffset:o,endOffset:i}=s,a=[],{paragraphs:c=[]}=n,l=o-t,u=i-t,d=c==null?void 0:c.find(m=>m.startIndex-t>=l&&m.startIndex-t<=u);if(l>0&&a.push({t:r.TextXActionType.RETAIN,len:l,segmentId:e}),d&&d.startIndex-t>l){const m=d.startIndex-t;a.push({t:r.TextXActionType.DELETE,len:m-l,line:0,segmentId:e}),a.push({t:r.TextXActionType.RETAIN,len:1,segmentId:e}),u>m+1&&a.push({t:r.TextXActionType.DELETE,len:u-m-1,line:0,segmentId:e})}else a.push({t:r.TextXActionType.DELETE,len:u-l,line:0,segmentId:e});return a}const ye={id:"doc.command.delete-left",type:r.CommandType.COMMAND,handler:async s=>{var T;const n=s.get(exports.TextSelectionManagerService),e=s.get(exports.DocSkeletonManagerService),t=s.get(r.IUniverInstanceService),o=s.get(r.ICommandService),i=n.getActiveRange(),a=n.getSelections(),c=(T=e.getCurrent())==null?void 0:T.skeleton;let l=!0;if(i==null||c==null||a==null)return!1;const u=t.getCurrentUniverDocInstance(),{startOffset:d,collapsed:m,segmentId:g,style:S}=i,v=c.findNodeByCharIndex(d),f=D.hasListSpan(v),p=D.isIndentBySpan(v,u.getBody());let _=d;const h=c.findNodeByCharIndex(d-1);if(D.isFirstSpan(v)&&h!==v&&(f===!0||p===!0)){const x=D.getParagraphBySpan(v,u.getBody());if(x==null)return!1;const E=x==null?void 0:x.startIndex,O={startIndex:0},y=x.paragraphStyle;if(f===!0){const I=x.paragraphStyle;I&&(O.paragraphStyle=I)}else if(p===!0){const I=x.bullet;I&&(O.bullet=I),y!=null&&(O.paragraphStyle={...y},delete O.paragraphStyle.hanging,delete O.paragraphStyle.indentStart)}const R=[{startOffset:_,endOffset:_,style:S}];l=await o.executeCommand(me.id,{unitId:u.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...O}]},range:{startOffset:E,endOffset:E+1},textRanges:R,coverType:r.UpdateDocsAttributeType.REPLACE,segmentId:g})}else if(m===!0){if(h==null)return!0;if(h.content==="\r")l=await o.executeCommand(Se.id,{direction:w.LEFT,range:i});else{_-=h.count;const x=[{startOffset:_,endOffset:_,style:S}];l=await o.executeCommand(z.id,{unitId:u.getUnitId(),range:i,segmentId:g,direction:w.LEFT,len:h.count,textRanges:x})}}else{const x=Oe(i,a);l=await o.executeCommand(ge.id,{segmentId:g,textRanges:x})}return l}},Re={id:"doc.command.delete-right",type:r.CommandType.COMMAND,handler:async s=>{var v;const n=s.get(exports.TextSelectionManagerService),e=s.get(exports.DocSkeletonManagerService),t=s.get(r.IUniverInstanceService),o=s.get(r.ICommandService),i=n.getActiveRange(),a=n.getSelections(),c=(v=e.getCurrent())==null?void 0:v.skeleton;let l;if(i==null||c==null||a==null)return!1;const u=t.getCurrentUniverDocInstance(),{startOffset:d,collapsed:m,segmentId:g,style:S}=i;if(d===u.getBody().dataStream.length-2&&m)return!0;if(m===!0){const f=c.findNodeByCharIndex(d);if(f.content==="\r")l=await o.executeCommand(Se.id,{direction:w.RIGHT,range:i});else{const p=[{startOffset:d,endOffset:d,style:S}];l=await o.executeCommand(z.id,{unitId:u.getUnitId(),range:i,segmentId:g,direction:w.RIGHT,textRanges:p,len:f.count})}}else{const f=Oe(i,a);l=await o.executeCommand(ge.id,{segmentId:g,textRanges:f})}return l}},Se={id:"doc.command.merge-two-paragraph",type:r.CommandType.COMMAND,handler:async(s,n)=>{var O,y,R;const e=s.get(exports.TextSelectionManagerService),t=s.get(r.IUniverInstanceService),o=s.get(r.ICommandService);s.get(r.IUndoRedoService);const{direction:i,range:a}=n,c=e.getActiveRange(),l=e.getSelections();if(c==null||l==null)return!1;const u=t.getCurrentUniverDocInstance(),{startOffset:d,collapsed:m,segmentId:g,style:S}=c;if(!m)return!1;const v=i===w.LEFT?d:d+1,f=(R=(y=(O=u.getBody())==null?void 0:O.paragraphs)==null?void 0:y.find(I=>I.startIndex>=v))==null?void 0:R.startIndex,p=st(u.getBody(),v,f),_=i===w.LEFT?d-1:d,h=u.getUnitId(),M=[{startOffset:_,endOffset:_,style:S}],T={id:U.id,params:{unitId:h,actions:[],textRanges:M,prevTextRanges:[a]}},x=new r.TextX;return x.push({t:r.TextXActionType.RETAIN,len:i===w.LEFT?d-1:d,segmentId:g}),p.dataStream.length&&x.push({t:r.TextXActionType.INSERT,body:p,len:p.dataStream.length,line:0,segmentId:g}),x.push({t:r.TextXActionType.RETAIN,len:1,segmentId:g}),x.push({t:r.TextXActionType.DELETE,len:f+1-v,line:0,segmentId:g}),T.params.actions=x.serialize(),!!o.syncExecuteCommand(T.id,T.params)}};function st(s,n,e){const{textRuns:t}=s,o=s.dataStream.substring(n,e);if(t==null)return{dataStream:o};const i=[];for(const a of t){const{st:c,ed:l}=a;l<=n||c>=e||(c<n?i.push({...a,st:0,ed:l-n}):l>e?i.push({...a,st:c-n,ed:e-n}):i.push({...a,st:c-n,ed:l-n}))}return{dataStream:o,textRuns:i}}function Oe(s,n){let e=s.endOffset;for(const o of n){const{startOffset:i,endOffset:a}=o;i==null||a==null||a<=s.endOffset&&(e-=a-i)}return[{startOffset:e,endOffset:e,style:s.style}]}const pe={id:"doc.command.ime-input",type:r.CommandType.COMMAND,handler:async(s,n)=>{const{unitId:e,newText:t,oldTextLen:o,isCompositionEnd:i,isCompositionStart:a}=n,c=s.get(r.ICommandService),l=s.get(j),u=l.getActiveRange();if(u==null)return!1;const{startOffset:d,style:m,segmentId:g}=u,S=t.length,v=[{startOffset:d+S,endOffset:d+S,collapsed:!0,style:m}],f={id:U.id,params:{unitId:e,actions:[],textRanges:v}},p=new r.TextX;!u.collapsed&&a?p.push(...ue(u,g)):p.push({t:r.TextXActionType.RETAIN,len:d,segmentId:g}),o>0&&p.push({t:r.TextXActionType.DELETE,len:o,line:0,segmentId:g}),p.push({t:r.TextXActionType.INSERT,body:{dataStream:t},len:t.length,line:0,segmentId:g}),f.params.actions=p.serialize(),f.params.noHistory=!i,f.params.isCompositionEnd=i;const _=c.syncExecuteCommand(f.id,f.params);return l.pushUndoRedoMutationParams(_,f.params),!!_}},H={id:"doc.command.set-inline-format-bold",type:r.CommandType.COMMAND,handler:async()=>!0},G={id:"doc.command.set-inline-format-italic",type:r.CommandType.COMMAND,handler:async()=>!0},Y={id:"doc.command.set-inline-format-underline",type:r.CommandType.COMMAND,handler:async()=>!0},W={id:"doc.command.set-inline-format-strikethrough",type:r.CommandType.COMMAND,handler:async()=>!0},L={id:"doc.command.set-inline-format-subscript",type:r.CommandType.COMMAND,handler:async()=>!0},Z={id:"doc.command.set-inline-format-superscript",type:r.CommandType.COMMAND,handler:async()=>!0},q={id:"doc.command.set-inline-format-fontsize",type:r.CommandType.COMMAND,handler:async()=>!0},K={id:"doc.command.set-inline-format-font-family",type:r.CommandType.COMMAND,handler:async()=>!0},J={id:"doc.command.set-inline-format-text-color",type:r.CommandType.COMMAND,handler:async()=>!0},De={[H.id]:"bl",[G.id]:"it",[Y.id]:"ul",[W.id]:"st",[q.id]:"fs",[K.id]:"ff",[J.id]:"cl",[L.id]:"va",[Z.id]:"va"},fe={id:"doc.command.set-inline-format",type:r.CommandType.COMMAND,handler:async(s,n)=>{const{segmentId:e,value:t,preCommandId:o}=n,i=s.get(r.ICommandService),a=s.get(exports.TextSelectionManagerService),c=s.get(r.IUniverInstanceService),l=a.getSelections();if(!Array.isArray(l)||l.length===0)return!1;let u=c.getCurrentUniverDocInstance(),d=u.getUnitId();d===r.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(u=c.getUniverDocInstance(r.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),d=u.getUnitId());let m;switch(o){case H.id:case G.id:case Y.id:case W.id:case L.id:case Z.id:{m=ct(u.getBody().textRuns,o,l);break}case q.id:case K.id:{m=t;break}case J.id:{m={rgb:t};break}default:throw new Error(`Unknown command: ${o} in handleInlineFormat`)}const g={id:U.id,params:{unitId:d,actions:[],textRanges:l.map(B)}},S=new r.TextX,v=new r.MemoryCursor;v.reset();for(const p of l){const{startOffset:_,endOffset:h}=p,M={dataStream:"",textRuns:[{st:0,ed:h-_,ts:{[De[o]]:m}}]},T=_-v.cursor;T!==0&&S.push({t:r.TextXActionType.RETAIN,len:T,segmentId:e}),S.push({t:r.TextXActionType.RETAIN,body:M,len:h-_,segmentId:e}),v.reset(),v.moveCursor(h)}return g.params.actions=S.serialize(),!!i.syncExecuteCommand(g.id,g.params)}};function at(s){return s!==null&&typeof s=="object"}function ct(s,n,e){let t=0,o=0;const i=De[n];for(;t!==s.length&&o!==e.length;){const{startOffset:a,endOffset:c}=e[o],{st:l,ed:u,ts:d}=s[t];if(c<=l)o++;else if(u<=a)t++;else{if(/bl|it/.test(i))return(d==null?void 0:d[i])===r.BooleanNumber.TRUE?r.BooleanNumber.FALSE:r.BooleanNumber.TRUE;if(/ul|st/.test(i))return at(d==null?void 0:d[i])&&(d==null?void 0:d[i]).s===r.BooleanNumber.TRUE?{s:r.BooleanNumber.FALSE}:{s:r.BooleanNumber.TRUE};if(/va/.test(i))return n===L.id?(d==null?void 0:d[i])===r.BaselineOffset.SUBSCRIPT?r.BaselineOffset.NORMAL:r.BaselineOffset.SUBSCRIPT:(d==null?void 0:d[i])===r.BaselineOffset.SUPERSCRIPT?r.BaselineOffset.NORMAL:r.BaselineOffset.SUPERSCRIPT;t++}}return/bl|it/.test(i)?r.BooleanNumber.TRUE:/ul|st/.test(i)?{s:r.BooleanNumber.TRUE}:n===L.id?r.BaselineOffset.SUBSCRIPT:r.BaselineOffset.SUPERSCRIPT}const he={id:"doc.command.list-operation",type:r.CommandType.COMMAND,handler:(s,n)=>{var x,E,O;const e=s.get(exports.TextSelectionManagerService),t=s.get(r.IUniverInstanceService),o=s.get(r.ICommandService),{listType:i}=n,a=t.getCurrentUniverDocInstance(),c=e.getActiveRange(),l=(x=e.getSelections())!=null?x:[],u=(E=a.getBody())==null?void 0:E.paragraphs,d=l.map(B);if(c==null||u==null)return!1;const m=lt(c,u),{segmentId:g}=c,S=a.getUnitId(),v=m.every(y=>{var R;return((R=y.bullet)==null?void 0:R.listType)===i});let p=r.Tools.generateRandomId(6);if(m.length===1){const y=u.indexOf(m[0]),R=u[y-1],I=u[y+1];R&&R.bullet&&R.bullet.listType===i?p=R.bullet.listId:I&&I.bullet&&I.bullet.listType===i&&(p=I.bullet.listId)}const _={id:U.id,params:{unitId:S,actions:[],textRanges:d}},h=new r.MemoryCursor;h.reset();const M=new r.TextX;for(const y of m){const{startIndex:R}=y;M.push({t:r.TextXActionType.RETAIN,len:R-h.cursor,segmentId:g});const I={...y.paragraphStyle,hanging:void 0,indentStart:void 0};M.push({t:r.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[v?{paragraphStyle:I,startIndex:0}:{...y,startIndex:0,bullet:{...(O=y.bullet)!=null?O:{nestingLevel:0,textStyle:{fs:20}},listType:i,listId:p}}]},segmentId:g,coverType:r.UpdateDocsAttributeType.REPLACE}),h.moveCursorTo(R+1)}return _.params.actions=M.serialize(),!!o.syncExecuteCommand(_.id,_.params)}},Ee={id:"doc.command.bullet-list",type:r.CommandType.COMMAND,handler:s=>s.get(r.ICommandService).syncExecuteCommand(he.id,{listType:r.PresetListType.BULLET_LIST})},Ae={id:"doc.command.order-list",type:r.CommandType.COMMAND,handler:s=>s.get(r.ICommandService).syncExecuteCommand(he.id,{listType:r.PresetListType.ORDER_LIST})};function lt(s,n){const{startOffset:e,endOffset:t}=s,o=[];let i=-1;for(const a of n){const{startIndex:c}=a;(e>i&&e<=c||t>i&&t<=c||c>=e&&c<=t)&&o.push(a),i=c}return o}const Ue={id:"doc.command-replace-content",type:r.CommandType.COMMAND,handler:async(s,n)=>{var S;const{unitId:e,body:t,textRanges:o,segmentId:i=""}=n,a=s.get(r.IUniverInstanceService),c=s.get(r.ICommandService),l=s.get(exports.TextSelectionManagerService),u=(S=a.getUniverDocInstance(e))==null?void 0:S.getSnapshot().body,d=l.getSelections();if(u==null||!Array.isArray(d)||d.length===0)return!1;const m=be(e,i,u,t);return m.params.textRanges=o,!!c.syncExecuteCommand(m.id,m.params)}},Ne={id:"doc.command-cover-content",type:r.CommandType.COMMAND,handler:async(s,n)=>{var d;const{unitId:e,body:t,segmentId:o=""}=n,i=s.get(r.IUniverInstanceService),a=s.get(r.ICommandService),c=s.get(r.IUndoRedoService),l=(d=i.getUniverDocInstance(e))==null?void 0:d.getSnapshot().body;if(l==null)return!1;const u=be(e,o,l,t);return u.params.noNeedSetTextRange=!0,u.params.noHistory=!0,a.syncExecuteCommand(u.id,u.params),c.clearUndoRedo(e),!0}};function be(s,n,e,t){const o={id:U.id,params:{unitId:s,actions:[],textRanges:[]}},i=new r.TextX,a=(e==null?void 0:e.dataStream.length)-2;return a>0&&i.push({t:r.TextXActionType.DELETE,len:a,line:0,segmentId:n}),t.dataStream.length>0&&i.push({t:r.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:n}),o.params.actions=i.serialize(),o}const re={id:"doc.operation.move-cursor",type:r.CommandType.OPERATION,handler:(s,n)=>!!n},ie={id:"doc.operation.move-selection",type:r.CommandType.OPERATION,handler:(s,n)=>!!n},dt=(s,n)=>{const e=s.get(r.IUniverInstanceService).getUniverDocInstance(n.unitId),t=(e==null?void 0:e.zoomRatio)||1;return{...r.Tools.deepClone(n),zoomRatio:t}},V={id:"doc.operation.set-zoom-ratio",type:r.CommandType.OPERATION,handler:(s,n)=>{const e=s.get(r.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}},Pe={type:r.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(s,n)=>{var m,g;const e=s.get(r.ICommandService),t=s.get(r.IUndoRedoService),o=s.get(r.IUniverInstanceService);let i=o.getCurrentUniverDocInstance().getUnitId(),a=1;if(n&&(i=(m=n.documentId)!=null?m:i,a=(g=n.zoomRatio)!=null?g:a),!o.getUniverDocInstance(i))return!1;const l={zoomRatio:a,unitId:i},u=dt(s,l);return e.syncExecuteCommand(V.id,l)?(t.pushUndoRedo({unitID:i,undoMutations:[{id:V.id,params:u}],redoMutations:[{id:V.id,params:l}]}),!0):!1}},we={id:"doc.operation.select-all",type:r.CommandType.COMMAND,handler:async s=>{const n=s.get(r.IUniverInstanceService),e=s.get(exports.TextSelectionManagerService),t=n.getCurrentUniverDocInstance().getSnapshot().body;if(t==null)return!1;const o=[{startOffset:0,endOffset:t.dataStream.length-2}];return e.replaceTextRanges(o,!1),!0}};var ut=Object.defineProperty,mt=Object.getOwnPropertyDescriptor,gt=(s,n,e,t)=>{for(var o=t>1?void 0:t?mt(n,e):n,i=s.length-1,a;i>=0;i--)(a=s[i])&&(o=(t?a(n,e,o):a(o))||o);return t&&o&&ut(n,e,o),o},$=(s,n)=>(e,t)=>n(e,t,s);let ee=class extends r.Disposable{constructor(n,e,t,o,i){super();C(this,"_previousIMEContent","");C(this,"_isCompositionStart",!0);C(this,"_onStartSubscription");C(this,"_onUpdateSubscription");C(this,"_onEndSubscription");this._docSkeletonManagerService=n,this._currentUniverService=e,this._textSelectionRenderManager=t,this._imeInputManagerService=o,this._commandService=i,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(r.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 u;const t=(u=this._docSkeletonManagerService.getCurrent())==null?void 0:u.skeleton;if(n==null||t==null)return;const o=this._currentUniverService.getCurrentUniverDocInstance(),{event:i,activeRange:a}=n;if(t==null||a==null)return;const l=i.data;l===this._previousIMEContent&&e||(await this._commandService.executeCommand(pe.id,{unitId:o.getUnitId(),newText:l,oldTextLen:this._previousIMEContent.length,isCompositionStart:this._isCompositionStart,isCompositionEnd:!e}),e?(this._isCompositionStart&&(this._isCompositionStart=!1),this._previousIMEContent=l):this._resetIME())}_resetIME(){this._previousIMEContent="",this._isCompositionStart=!0,this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(null)}};ee=gt([r.OnLifecycle(r.LifecycleStages.Rendered,ee),$(0,A.Inject(exports.DocSkeletonManagerService)),$(1,r.IUniverInstanceService),$(2,D.ITextSelectionRenderManager),$(3,A.Inject(j)),$(4,r.ICommandService)],ee);var St=Object.defineProperty,pt=Object.getOwnPropertyDescriptor,ft=(s,n,e,t)=>{for(var o=t>1?void 0:t?pt(n,e):n,i=s.length-1,a;i>=0;i--)(a=s[i])&&(o=(t?a(n,e,o):a(o))||o);return t&&o&&St(n,e,o),o},Ce=(s,n)=>(e,t)=>n(e,t,s);let te=class extends r.Disposable{constructor(s,n){super(),this._textSelectionManagerService=s,this._commandService=n,this._commandExecutedListener()}_commandExecutedListener(){const s=[H.id,G.id,Y.id,W.id,L.id,Z.id,q.id,K.id,J.id];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{s.includes(n.id)&&this._handleInlineFormat(n)}))}_handleInlineFormat(s){var e,t;const{segmentId:n}=(e=this._textSelectionManagerService.getActiveRange())!=null?e:{};n!=null&&this._commandService.executeCommand(fe.id,{segmentId:n,preCommandId:s.id,...(t=s.params)!=null?t:{}})}};te=ft([r.OnLifecycle(r.LifecycleStages.Rendered,te),Ce(0,A.Inject(exports.TextSelectionManagerService)),Ce(1,r.ICommandService)],te);var ht=Object.defineProperty,vt=Object.getOwnPropertyDescriptor,_t=(s,n,e,t)=>{for(var o=t>1?void 0:t?vt(n,e):n,i=s.length-1,a;i>=0;i--)(a=s[i])&&(o=(t?a(n,e,o):a(o))||o);return t&&o&&ht(n,e,o),o},F=(s,n)=>(e,t)=>n(e,t,s);let ne=class extends r.Disposable{constructor(n,e,t,o,i){super();C(this,"_onInputSubscription");this._docSkeletonManagerService=n,this._currentUniverService=e,this._renderManagerService=t,this._textSelectionManagerService=o,this._commandService=i,this._initialize(),this._commandExecutedListener()}dispose(){var n;(n=this._onInputSubscription)==null||n.unsubscribe()}_initialize(){}_commandExecutedListener(){const n=[re.id,ie.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!n.includes(e.id))return;const t=e.params;switch(e.id){case re.id:return this._handleMoveCursor(t.direction);case ie.id:return this._handleShiftMoveSelection(t.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(n){var f,p,_;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),o=this._currentUniverService.getCurrentUniverDocInstance(),i=(f=this._docSkeletonManagerService.getCurrent())==null?void 0:f.skeleton,a=this._getDocObject();if(e==null||i==null||a==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d,direction:m}=e;if(t.length>1){let h=Number.POSITIVE_INFINITY,M=Number.NEGATIVE_INFINITY;for(const T of t)h=Math.min(h,T.startOffset),M=Math.max(M,T.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:n===r.Direction.LEFT||n===r.Direction.UP?M:h,endOffset:n===r.Direction.LEFT||n===r.Direction.UP?h:M,style:u}],!1);return}const g=d||m===D.RANGE_DIRECTION.FORWARD?c:l;let S=d||m===D.RANGE_DIRECTION.FORWARD?l:c;const v=(p=o.getBody().dataStream.length)!=null?p:Number.POSITIVE_INFINITY;if(n===r.Direction.LEFT||n===r.Direction.RIGHT){const h=i.findNodeByCharIndex(S-1),M=i.findNodeByCharIndex(S);S=n===r.Direction.RIGHT?S+M.count:S-((_=h==null?void 0:h.count)!=null?_:0),S=Math.min(v-2,Math.max(0,S)),this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:S,style:u}],!1)}else{const h=i.findNodeByCharIndex(S),M=a.document.getOffsetConfig(),T=this._getTopOrBottomPosition(i,h,n===r.Direction.DOWN);if(T==null){const E=n===r.Direction.UP?0:v-2;if(E===S)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:E,style:u}],!1);return}const x=new D.NodePositionConvertToCursor(M,i).getRangePointData(T,T).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:x.endOffset,style:u}],!1)}}_handleMoveCursor(n){var g,S,v;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),o=this._currentUniverService.getCurrentUniverDocInstance(),i=(g=this._docSkeletonManagerService.getCurrent())==null?void 0:g.skeleton,a=this._getDocObject();if(e==null||i==null||a==null||t==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d}=e,m=(S=o.getBody().dataStream.length)!=null?S:Number.POSITIVE_INFINITY;if(n===r.Direction.LEFT||n===r.Direction.RIGHT){let f;if(!e.collapsed||t.length>1){let p=Number.POSITIVE_INFINITY,_=Number.NEGATIVE_INFINITY;for(const h of t)p=Math.min(p,h.startOffset),_=Math.max(_,h.endOffset);f=n===r.Direction.LEFT?p:_}else{const p=i.findNodeByCharIndex(c-1),_=i.findNodeByCharIndex(c);n===r.Direction.LEFT?f=Math.max(0,c-((v=p==null?void 0:p.count)!=null?v:0)):f=Math.min(m-2,l+_.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:f,style:u}],!1)}else{const f=i.findNodeByCharIndex(c),p=i.findNodeByCharIndex(l),_=a.document.getOffsetConfig(),h=this._getTopOrBottomPosition(i,n===r.Direction.UP?f:p,n===r.Direction.DOWN);if(h==null){let T;d?T=n===r.Direction.UP?0:m-2:T=n===r.Direction.UP?c:l,this._textSelectionManagerService.replaceTextRanges([{startOffset:T,endOffset:T,style:u}],!1);return}const M=new D.NodePositionConvertToCursor(_,i).getRangePointData(h,h).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...M,style:u}],!1)}}_getTopOrBottomPosition(n,e,t){if(e==null)return;const o=this._getSpanLeftOffsetInLine(e),i=this._getNextOrPrevLine(e,t);if(i==null)return;const a=this._matchPositionByLeftOffset(n,i,o);if(a!=null)return{...a,isBack:!0}}_getSpanLeftOffsetInLine(n){const e=n.parent;if(e==null)return Number.NEGATIVE_INFINITY;const t=e.left,{left:o}=n;return t+o}_matchPositionByLeftOffset(n,e,t){const o={distance:Number.POSITIVE_INFINITY};for(const i of e.divides){const a=i.left;for(const c of i.spanGroup){const{left:l}=c,u=a+l,d=Math.abs(t-u);d<o.distance&&(o.span=c,o.distance=d)}}if(o.span!=null)return n.findPositionBySpan(o.span)}_getNextOrPrevLine(n,e){var v,f,p,_,h,M,T,x,E,O,y,R;const t=n.parent;if(t==null)return;const o=t.parent;if(o==null)return;const i=o.parent;if(i==null)return;const a=i.lines.indexOf(o);if(a===-1)return;let c;if(e===!0?c=i.lines[a+1]:c=i.lines[a-1],c!=null)return c;const l=i.parent;if(l==null)return;const u=l.columns.indexOf(i);if(u===-1)return;if(e===!0)c=(v=l.columns[u+1])==null?void 0:v.lines[0];else{const I=(p=(f=l.columns)==null?void 0:f[u-1])==null?void 0:p.lines;c=I==null?void 0:I[I.length-1]}if(c!=null)return c;const d=l.parent;if(d==null)return;const m=d.sections.indexOf(l);if(m===-1)return;if(e===!0)c=(h=(_=d.sections[m-1])==null?void 0:_.columns[0])==null?void 0:h.lines[0];else{const I=(T=(M=d.sections)==null?void 0:M[m-1])==null?void 0:T.columns,P=I==null?void 0:I[I.length-1],N=P==null?void 0:P.lines;c=N==null?void 0:N[N.length-1]}if(c!=null)return c;const g=d.parent;if(g==null)return;const S=g.pages.indexOf(d);if(S!==-1){if(e===!0)c=(O=(E=(x=g.pages[S+1])==null?void 0:x.sections[0])==null?void 0:E.columns[0])==null?void 0:O.lines[0];else{const I=(y=g.pages[S-1])==null?void 0:y.sections;if(I==null)return;const P=(R=I[I.length-1])==null?void 0:R.columns,N=P[P.length-1],ve=N==null?void 0:N.lines;c=ve[ve.length-1]}if(c!=null)return c}}_getDocObject(){return le(this._currentUniverService,this._renderManagerService)}};ne=_t([r.OnLifecycle(r.LifecycleStages.Rendered,ne),F(0,A.Inject(exports.DocSkeletonManagerService)),F(1,r.IUniverInstanceService),F(2,D.IRenderManagerService),F(3,A.Inject(exports.TextSelectionManagerService)),F(4,r.ICommandService)],ne);var It=Object.defineProperty,Ct=Object.getOwnPropertyDescriptor,Mt=(s,n,e,t)=>{for(var o=t>1?void 0:t?Ct(n,e):n,i=s.length-1,a;i>=0;i--)(a=s[i])&&(o=(t?a(n,e,o):a(o))||o);return t&&o&&It(n,e,o),o},X=(s,n)=>(e,t)=>n(e,t,s);let oe=class extends r.Disposable{constructor(n,e,t,o,i){super();C(this,"_onInputSubscription");this._docSkeletonManagerService=n,this._currentUniverService=e,this._renderManagerService=t,this._textSelectionRenderManager=o,this._commandService=i,this._initialize(),this._commandExecutedListener()}dispose(){var n;(n=this._onInputSubscription)==null||n.unsubscribe()}_initialize(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async n=>{var v;if(n==null)return;const t=this._currentUniverService.getCurrentUniverDocInstance().getUnitId(),{event:o,content:i="",activeRange:a}=n,c=o,l=(v=this._docSkeletonManagerService.getCurrent())==null?void 0:v.skeleton;if(c.data==null||l==null||!l||!a)return;const{startOffset:u,segmentId:d,style:m}=a,g=i.length,S=[{startOffset:u+g,endOffset:u+g,style:m}];await this._commandService.executeCommand(k.id,{unitId:t,body:{dataStream:i},range:a,textRanges:S,segmentId:d})})}_commandExecutedListener(){}_getDocObject(){return le(this._currentUniverService,this._renderManagerService)}};oe=Mt([r.OnLifecycle(r.LifecycleStages.Rendered,oe),X(0,A.Inject(exports.DocSkeletonManagerService)),X(1,r.IUniverInstanceService),X(2,D.IRenderManagerService),X(3,D.ITextSelectionRenderManager),X(4,r.ICommandService)],oe);var Tt=Object.defineProperty,xt=Object.getOwnPropertyDescriptor,yt=(s,n,e,t)=>{for(var o=t>1?void 0:t?xt(n,e):n,i=s.length-1,a;i>=0;i--)(a=s[i])&&(o=(t?a(n,e,o):a(o))||o);return t&&o&&Tt(n,e,o),o},Q=(s,n)=>(e,t)=>n(e,t,s);const Rt={hasScroll:!0},Ot="docs";var ce;exports.UniverDocsPlugin=(ce=class extends r.Plugin{constructor(e={},t,o,i,a){super(Ot);C(this,"_config");this._injector=t,this._localeService=o,this._configService=i,this._currentUniverService=a,this._config=Object.assign(Rt,e),this._initializeDependencies(t),this._initializeCommands()}initialize(){}_initializeCommands(){[re,ie,ye,Re,H,G,Y,W,L,Z,q,K,J,fe,xe,k,z,me,pe,Se,U,Ue,Ne,Pe,V,de,we,Ae,Ee,he].forEach(e=>{this._injector.get(r.ICommandService).registerCommand(e)})}onReady(){this.initialize()}_initializeDependencies(e){[[exports.DocSkeletonManagerService],[exports.DocViewModelManagerService],[exports.DocStateChangeManagerService],[j],[D.ITextSelectionRenderManager,{useClass:D.TextSelectionRenderManager}],[exports.TextSelectionManagerService],[oe],[ee],[te],[ne]].forEach(t=>e.add(t))}},C(ce,"type",r.PluginType.Doc),ce);exports.UniverDocsPlugin=yt([Q(1,A.Inject(A.Injector)),Q(2,A.Inject(r.LocaleService)),Q(3,r.IConfigService),Q(4,r.IUniverInstanceService)],exports.UniverDocsPlugin);exports.BreakLineCommand=xe;exports.BulletListCommand=Ee;exports.CoverContentCommand=Ne;exports.CutContentCommand=ge;exports.DOCS_COMPONENT_DEFAULT_Z_INDEX=Ve;exports.DOCS_COMPONENT_HEADER_LAYER_INDEX=Xe;exports.DOCS_COMPONENT_MAIN_LAYER_INDEX=Fe;exports.DOCS_VIEW_KEY=Me;exports.DeleteCommand=z;exports.DeleteLeftCommand=ye;exports.DeleteRightCommand=Re;exports.IMEInputCommand=pe;exports.IMEInputManagerService=j;exports.InnerPasteCommand=rt;exports.InsertCommand=k;exports.MoveCursorOperation=re;exports.MoveSelectionOperation=ie;exports.NORMAL_TEXT_SELECTION_PLUGIN_NAME=je;exports.OrderListCommand=Ae;exports.ReplaceContentCommand=Ue;exports.RichTextEditingMutation=U;exports.SelectAllOperation=we;exports.SetDocZoomRatioCommand=Pe;exports.SetDocZoomRatioOperation=V;exports.SetInlineFormatBoldCommand=H;exports.SetInlineFormatCommand=fe;exports.SetInlineFormatFontFamilyCommand=K;exports.SetInlineFormatFontSizeCommand=q;exports.SetInlineFormatItalicCommand=G;exports.SetInlineFormatStrikethroughCommand=W;exports.SetInlineFormatSubscriptCommand=L;exports.SetInlineFormatSuperscriptCommand=Z;exports.SetInlineFormatTextColorCommand=J;exports.SetInlineFormatUnderlineCommand=Y;exports.SetTextSelectionsOperation=de;exports.UpdateCommand=me;exports.VIEWPORT_KEY=Te;exports.getDocObject=le;exports.getDocObjectById=$e;exports.serializeTextRange=B;
package/lib/es/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var tt = Object.defineProperty;
2
2
  var nt = (r, e, t) => e in r ? tt(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
3
  var M = (r, e, t) => (nt(r, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { CommandType as v, RxDisposable as oe, ICommandService as y, TextXActionType as R, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as Ve, IUniverInstanceService as T, IUndoRedoService as ie, UndoCommandId as Ue, RedoCommandId as Ne, TextX as U, DataStreamTreeTokenType as ye, Tools as Y, LocaleService as ke, MemoryCursor as ae, getDocsUpdateBody as st, UpdateDocsAttributeType as je, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as rt, BooleanNumber as F, BaselineOffset as z, PresetListType as He, OnLifecycle as ce, LifecycleStages as le, Disposable as de, Direction as b, Plugin as ot, PluginType as it, IConfigService as at } from "@univerjs/core";
4
+ import { CommandType as v, RxDisposable as oe, ICommandService as y, TextXActionType as R, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as Ve, IUniverInstanceService as T, IUndoRedoService as ie, UndoCommandId as Ne, RedoCommandId as Ue, TextX as N, DataStreamTreeTokenType as ye, Tools as Y, LocaleService as ke, MemoryCursor as ae, getDocsUpdateBody as st, UpdateDocsAttributeType as je, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as rt, BooleanNumber as F, BaselineOffset as z, PresetListType as He, OnLifecycle as ce, LifecycleStages as le, Disposable as de, Direction as b, Plugin as ot, PluginType as it, IConfigService as at } from "@univerjs/core";
5
5
  import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE as ct, ITextSelectionRenderManager as ue, DocumentViewModel as lt, DocumentSkeleton as dt, hasListSpan as ut, isIndentBySpan as mt, isFirstSpan as gt, getParagraphBySpan as ft, RANGE_DIRECTION as we, NodePositionConvertToCursor as Le, IRenderManagerService as Ge, TextSelectionRenderManager as ht } from "@univerjs/engine-render";
6
6
  import { BehaviorSubject as W, takeUntil as Z } from "rxjs";
7
7
  import { Inject as w, Injector as pt } from "@wendellhu/redi";
@@ -267,7 +267,7 @@ let re = class extends oe {
267
267
  _initialize() {
268
268
  this.disposeWithMe(
269
269
  this._commandService.beforeCommandExecuted((e) => {
270
- if (e.id === Ue || e.id === Ne) {
270
+ if (e.id === Ne || e.id === Ue) {
271
271
  const t = this._univerInstanceService.getCurrentUniverDocInstance();
272
272
  if (t == null)
273
273
  return;
@@ -279,7 +279,7 @@ let re = class extends oe {
279
279
  }
280
280
  _cacheChangeState(e) {
281
281
  const { trigger: t, unitId: n, noHistory: s } = e;
282
- if (!(t === Ne || t === Ue || s)) {
282
+ if (!(t === Ue || t === Ne || s)) {
283
283
  if (this._stateCache.has(n)) {
284
284
  const o = this._stateCache.get(n);
285
285
  o == null || o.push(e);
@@ -296,12 +296,12 @@ let re = class extends oe {
296
296
  return;
297
297
  const s = n.length, o = n[0].commandId, i = n[0], a = n[s - 1], c = {
298
298
  unitId: e,
299
- actions: n.reduce((l, u) => U.compose(l, u.redoState.actions), []),
299
+ actions: n.reduce((l, u) => N.compose(l, u.redoState.actions), []),
300
300
  textRanges: a.redoState.textRanges
301
301
  }, d = {
302
302
  unitId: e,
303
303
  // Always need to put undoParams after redoParams, because `reverse` will change the `cacheStates` order.
304
- actions: n.reverse().reduce((l, u) => U.compose(l, u.undoState.actions), []),
304
+ actions: n.reverse().reduce((l, u) => N.compose(l, u.undoState.actions), []),
305
305
  textRanges: i.undoState.textRanges
306
306
  };
307
307
  t.pushUndoRedo({
@@ -348,13 +348,13 @@ class me {
348
348
  return null;
349
349
  const { unitId: e } = this._undoMutationParamsCache[0], t = {
350
350
  unitId: e,
351
- actions: this._undoMutationParamsCache.reverse().reduce((s, o) => U.compose(s, o.actions), []),
351
+ actions: this._undoMutationParamsCache.reverse().reduce((s, o) => N.compose(s, o.actions), []),
352
352
  textRanges: []
353
353
  // Add empty array, will never use, just fix type error
354
354
  };
355
355
  return { redoMutationParams: {
356
356
  unitId: e,
357
- actions: this._redoMutationParamsCache.reduce((s, o) => U.compose(s, o.actions), []),
357
+ actions: this._redoMutationParamsCache.reduce((s, o) => N.compose(s, o.actions), []),
358
358
  textRanges: []
359
359
  // Add empty array, will never use, just fix type error
360
360
  }, undoMutationParams: t, previousActiveRange: this._previousActiveRange };
@@ -428,7 +428,7 @@ const $e = "doc.mutation.rich-text-editing", L = {
428
428
  actions: [],
429
429
  textRanges: a
430
430
  }
431
- }, u = new U();
431
+ }, u = new N();
432
432
  return d ? c > 0 && u.push({
433
433
  t: R.RETAIN,
434
434
  len: c,
@@ -454,7 +454,7 @@ const fe = {
454
454
  actions: [],
455
455
  textRanges: a
456
456
  }
457
- }, u = new U();
457
+ }, u = new N();
458
458
  return d > 0 && u.push({
459
459
  t: R.RETAIN,
460
460
  len: i === 0 ? d - c : d,
@@ -477,7 +477,7 @@ const fe = {
477
477
  actions: [],
478
478
  textRanges: a
479
479
  }
480
- }, l = new U(), { startOffset: u, endOffset: m } = t;
480
+ }, l = new N(), { startOffset: u, endOffset: m } = t;
481
481
  return l.push({
482
482
  t: R.RETAIN,
483
483
  len: u,
@@ -529,8 +529,8 @@ const bt = {
529
529
  });
530
530
  }
531
531
  };
532
- var At = Object.defineProperty, Ut = Object.getOwnPropertyDescriptor, Nt = (r, e, t, n) => {
533
- for (var s = n > 1 ? void 0 : n ? Ut(e, t) : e, o = r.length - 1, i; o >= 0; o--)
532
+ var At = Object.defineProperty, Nt = Object.getOwnPropertyDescriptor, Ut = (r, e, t, n) => {
533
+ for (var s = n > 1 ? void 0 : n ? Nt(e, t) : e, o = r.length - 1, i; o >= 0; o--)
534
534
  (i = r[o]) && (s = (n ? i(e, t, s) : i(s)) || s);
535
535
  return n && s && At(e, t, s), s;
536
536
  }, xe = (r, e) => (t, n) => e(t, n, r);
@@ -596,7 +596,7 @@ let k = class extends oe {
596
596
  return dt.create(e, this._localeService);
597
597
  }
598
598
  };
599
- k = Nt([
599
+ k = Ut([
600
600
  xe(0, w(ke)),
601
601
  xe(1, w(J)),
602
602
  xe(2, T)
@@ -617,7 +617,7 @@ const Rn = {
617
617
  }
618
618
  }, m = new ae();
619
619
  m.reset();
620
- const g = new U();
620
+ const g = new N();
621
621
  for (const h of c) {
622
622
  const { startOffset: f, endOffset: _, collapsed: p } = h, C = f - m.cursor;
623
623
  p ? g.push({
@@ -653,7 +653,7 @@ const Rn = {
653
653
  }
654
654
  }, m = new ae();
655
655
  m.reset();
656
- const g = new U();
656
+ const g = new N();
657
657
  for (const h of a) {
658
658
  const { startOffset: f, endOffset: _, collapsed: p } = h, C = f - m.cursor;
659
659
  p ? g.push({
@@ -715,7 +715,7 @@ const Lt = {
715
715
  const O = ft(S, d.getBody());
716
716
  if (O == null)
717
717
  return !1;
718
- const N = O == null ? void 0 : O.startIndex, P = { startIndex: 0 }, E = O.paragraphStyle;
718
+ const U = O == null ? void 0 : O.startIndex, P = { startIndex: 0 }, E = O.paragraphStyle;
719
719
  if (h === !0) {
720
720
  const I = O.paragraphStyle;
721
721
  I && (P.paragraphStyle = I);
@@ -737,8 +737,8 @@ const Lt = {
737
737
  paragraphs: [{ ...P }]
738
738
  },
739
739
  range: {
740
- startOffset: N,
741
- endOffset: N + 1
740
+ startOffset: U,
741
+ endOffset: U + 1
742
742
  },
743
743
  textRanges: D,
744
744
  coverType: je.REPLACE,
@@ -851,7 +851,7 @@ const Lt = {
851
851
  textRanges: C,
852
852
  prevTextRanges: [i]
853
853
  }
854
- }, O = new U();
854
+ }, O = new N();
855
855
  return O.push({
856
856
  t: R.RETAIN,
857
857
  len: o === V.LEFT ? l - 1 : l,
@@ -937,7 +937,7 @@ const Je = {
937
937
  actions: [],
938
938
  textRanges: S
939
939
  }
940
- }, f = new U();
940
+ }, f = new N();
941
941
  !d.collapsed && i ? f.push(...De(d, m)) : f.push({
942
942
  t: R.RETAIN,
943
943
  len: l,
@@ -1050,7 +1050,7 @@ const Je = {
1050
1050
  actions: [],
1051
1051
  textRanges: c.map(q)
1052
1052
  }
1053
- }, g = new U(), S = new ae();
1053
+ }, g = new N(), S = new ae();
1054
1054
  S.reset();
1055
1055
  for (const f of c) {
1056
1056
  const { startOffset: _, endOffset: p } = f, C = {
@@ -1113,8 +1113,8 @@ const be = {
1113
1113
  id: "doc.command.list-operation",
1114
1114
  type: v.COMMAND,
1115
1115
  handler: (r, e) => {
1116
- var O, N, P;
1117
- const t = r.get(A), n = r.get(T), s = r.get(y), { listType: o } = e, i = n.getCurrentUniverDocInstance(), a = t.getActiveRange(), c = (O = t.getSelections()) != null ? O : [], d = (N = i.getBody()) == null ? void 0 : N.paragraphs, l = c.map(q);
1116
+ var O, U, P;
1117
+ const t = r.get(A), n = r.get(T), s = r.get(y), { listType: o } = e, i = n.getCurrentUniverDocInstance(), a = t.getActiveRange(), c = (O = t.getSelections()) != null ? O : [], d = (U = i.getBody()) == null ? void 0 : U.paragraphs, l = c.map(q);
1118
1118
  if (a == null || d == null)
1119
1119
  return !1;
1120
1120
  const u = jt(a, d), { segmentId: m } = a, g = i.getUnitId(), S = u.every((E) => {
@@ -1135,7 +1135,7 @@ const be = {
1135
1135
  }
1136
1136
  }, p = new ae();
1137
1137
  p.reset();
1138
- const C = new U();
1138
+ const C = new N();
1139
1139
  for (const E of u) {
1140
1140
  const { startIndex: D } = E;
1141
1141
  C.push({
@@ -1235,7 +1235,7 @@ function et(r, e, t, n) {
1235
1235
  actions: [],
1236
1236
  textRanges: []
1237
1237
  }
1238
- }, o = new U(), i = (t == null ? void 0 : t.dataStream.length) - 2;
1238
+ }, o = new N(), i = (t == null ? void 0 : t.dataStream.length) - 2;
1239
1239
  return i > 0 && o.push({
1240
1240
  t: R.DELETE,
1241
1241
  len: i,
@@ -1336,8 +1336,9 @@ let ee = class extends de {
1336
1336
  this._onStartSubscription = this._textSelectionRenderManager.onCompositionstart$.subscribe((e) => {
1337
1337
  if (e == null)
1338
1338
  return;
1339
+ this._resetIME();
1339
1340
  const { activeRange: t } = e;
1340
- t != null && (this._imeInputManagerService.clearUndoRedoMutationParamsCache(), this._imeInputManagerService.setActiveRange(Y.deepClone(t)), this._isCompositionStart = !0);
1341
+ t != null && this._imeInputManagerService.setActiveRange(Y.deepClone(t));
1341
1342
  });
1342
1343
  }
1343
1344
  _initialOnCompositionUpdate() {
@@ -1490,13 +1491,13 @@ let ne = class extends de {
1490
1491
  } else {
1491
1492
  const p = o.findNodeByCharIndex(g), C = i.document.getOffsetConfig(), x = this._getTopOrBottomPosition(o, p, e === b.DOWN);
1492
1493
  if (x == null) {
1493
- const N = e === b.UP ? 0 : S - 2;
1494
- if (N === g)
1494
+ const U = e === b.UP ? 0 : S - 2;
1495
+ if (U === g)
1495
1496
  return;
1496
1497
  this._textSelectionManagerService.replaceTextRanges([
1497
1498
  {
1498
1499
  startOffset: m,
1499
- endOffset: N,
1500
+ endOffset: U,
1500
1501
  style: d
1501
1502
  }
1502
1503
  ], !1);
@@ -1600,7 +1601,7 @@ let ne = class extends de {
1600
1601
  return e.findPositionBySpan(s.span);
1601
1602
  }
1602
1603
  _getNextOrPrevLine(e, t) {
1603
- var S, h, f, _, p, C, x, O, N, P, E, D;
1604
+ var S, h, f, _, p, C, x, O, U, P, E, D;
1604
1605
  const n = e.parent;
1605
1606
  if (n == null)
1606
1607
  return;
@@ -1650,7 +1651,7 @@ let ne = class extends de {
1650
1651
  const g = m.pages.indexOf(l);
1651
1652
  if (g !== -1) {
1652
1653
  if (t === !0)
1653
- a = (P = (N = (O = m.pages[g + 1]) == null ? void 0 : O.sections[0]) == null ? void 0 : N.columns[0]) == null ? void 0 : P.lines[0];
1654
+ a = (P = (U = (O = m.pages[g + 1]) == null ? void 0 : O.sections[0]) == null ? void 0 : U.columns[0]) == null ? void 0 : P.lines[0];
1654
1655
  else {
1655
1656
  const I = (E = m.pages[g - 1]) == null ? void 0 : E.sections;
1656
1657
  if (I == null)
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(d,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("rxjs"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","rxjs","@wendellhu/redi"],a):(d=typeof globalThis<"u"?globalThis:d||self,a(d.UniverDocs={},d.UniverCore,d.UniverEngineRender,d.rxjs,d["@wendellhu/redi"]))})(this,function(d,a,O,P,A){"use strict";var xt=Object.defineProperty;var Dt=(d,a,O)=>a in d?xt(d,a,{enumerable:!0,configurable:!0,writable:!0,value:O}):d[a]=O;var M=(d,a,O)=>(Dt(d,typeof a!="symbol"?a+"":a,O),O);var ve;function re(o,i){const t=o.getCurrentUniverDocInstance().getUnitId(),n=i.getRenderById(t);if(n==null)return;const{mainComponent:s,scene:r,engine:c}=n;return{document:s,scene:r,engine:c}}function Be(o,i){const e=i.getRenderById(o);if(e==null)return;const{mainComponent:t,scene:n,engine:s}=e;return{document:t,scene:n,engine:s}}var _e=(o=>(o.MAIN="__Document_Render_Main__",o))(_e||{}),Ie=(o=>(o.VIEW_MAIN="viewMain",o.VIEW_TOP="viewTop",o.VIEW_LEFT="viewLeft",o.VIEW_LEFT_TOP="viewLeftTop",o))(Ie||{});const $e=0,Fe=2,Xe=10,Ve="normalTextSelectionPluginName",ce={id:"doc.operation.set-selections",type:a.CommandType.OPERATION,handler:(o,i)=>!0};var ke=Object.defineProperty,je=Object.getOwnPropertyDescriptor,ze=(o,i,e,t)=>{for(var n=t>1?void 0:t?je(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&ke(i,e,n),n},Ce=(o,i)=>(e,t)=>i(e,t,o);function $(o){const{startOffset:i,endOffset:e,collapsed:t}=o,n={startOffset:i,endOffset:e,collapsed:t};return typeof o.isActive=="function"&&(n.isActive=o.isActive()),n}d.TextSelectionManagerService=class extends a.RxDisposable{constructor(e,t){super();M(this,"_currentSelection",null);M(this,"_textSelectionInfo",new Map);M(this,"_textSelection$",new P.BehaviorSubject(null));M(this,"textSelection$",this._textSelection$.asObservable());this._textSelectionRenderManager=e,this._commandService=t,this._syncSelectionFromRenderService()}getCurrentSelection(){return this._currentSelection}getCurrentSelectionInfo(){return this._getTextRanges(this._currentSelection)}dispose(){this._textSelection$.complete()}refreshSelection(){this._currentSelection!=null&&this._refresh(this._currentSelection)}setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}setCurrentSelectionNotRefresh(e){this._currentSelection=e}getSelections(){var e;return(e=this._getTextRanges(this._currentSelection))==null?void 0:e.textRanges}getActiveRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:t,segmentId:n,style:s}=e,r=t.find(f=>f.isActive());if(r==null)return null;const{startOffset:c,endOffset:l,collapsed:m,startNodePosition:u,endNodePosition:g,direction:S}=r;return c==null||l==null?null:{startOffset:c,endOffset:l,collapsed:m,startNodePosition:u,endNodePosition:g,direction:S,segmentId:n,style:s}}add(e,t=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,segmentId:"",isEditing:t,style:O.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e,t=!0){this._currentSelection!=null&&(this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges(e,t))}_syncSelectionFromRenderService(){this._textSelectionRenderManager.textSelectionInner$.pipe(P.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:n,subUnitId:s,segmentId:r,style:c,textRanges:l,isEditing:m}=t;this._commandService.executeCommand(ce.id,{unitId:n,subUnitId:s,segmentId:r,style:c,isEditing:m,ranges:l.map($)})}_getTextRanges(e){var s;if(e==null)return;const{unitId:t,subUnitId:n=""}=e;return(s=this._textSelectionInfo.get(t))==null?void 0:s.get(n)}_refresh(e){const t=this._getTextRanges(e);this._textSelectionRenderManager.removeAllTextRanges(),t&&Array.isArray(t.textRanges)&&t.textRanges.length&&this._textSelectionRenderManager.addTextRanges(t.textRanges.map($))}_replaceByParam(e){const{unitId:t,subUnitId:n,style:s,segmentId:r,textRanges:c,isEditing:l}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(n,{textRanges:c,style:s,segmentId:r,isEditing:l})}_addByParam(e){const{unitId:t,subUnitId:n,textRanges:s,style:r,segmentId:c,isEditing:l}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);const m=this._textSelectionInfo.get(t);m.has(n)?m.get(n).textRanges.push(...s):m.set(n,{textRanges:s,style:r,segmentId:c,isEditing:l})}},d.TextSelectionManagerService=ze([Ce(0,O.ITextSelectionRenderManager),Ce(1,a.ICommandService)],d.TextSelectionManagerService);function le(o,i="",e=0){const{startOffset:t,endOffset:n}=o,s=[],r=t-e,c=n-e;return r>0&&s.push({t:a.TextXActionType.RETAIN,len:r,segmentId:i}),s.push({t:a.TextXActionType.DELETE,len:c-r,line:0,segmentId:i}),s}var He=Object.defineProperty,Ge=Object.getOwnPropertyDescriptor,Ye=(o,i,e,t)=>{for(var n=t>1?void 0:t?Ge(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&He(i,e,n),n},We=(o,i)=>(e,t)=>i(e,t,o);d.DocViewModelManagerService=class extends a.RxDisposable{constructor(e){super();M(this,"_docViewModelMap",new Map);M(this,"_currentDocViewModel$",new P.BehaviorSubject(null));M(this,"currentDocViewModel$",this._currentDocViewModel$.asObservable());this._currentUniverService=e,this._initialize()}_initialize(){this._init()}dispose(){this._currentDocViewModel$.complete(),this._docViewModelMap.clear()}_init(){this._currentUniverService.currentDoc$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)}),this._currentUniverService.getAllUniverDocsInstance().forEach(e=>{this._create(e)}),this._currentUniverService.docDisposed$.pipe(P.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 n;const t=this._currentUniverService.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 s=this._buildDocViewModel(t);this._docViewModelMap.set(e,{unitId:e,docViewModel:s})}if(e===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY){const s=(n=this._docViewModelMap.get(e))==null?void 0:n.docViewModel;if(s==null)return;s.reset(t)}this._currentDocViewModel$.next(this._docViewModelMap.get(e))}}_buildDocViewModel(e){return new O.DocumentViewModel(e)}},d.DocViewModelManagerService=Ye([We(0,a.IUniverInstanceService)],d.DocViewModelManagerService);var Ze=Object.defineProperty,qe=Object.getOwnPropertyDescriptor,Ke=(o,i,e,t)=>{for(var n=t>1?void 0:t?qe(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&Ze(i,e,n),n},de=(o,i)=>(e,t)=>i(e,t,o);const Je=300;d.DocStateChangeManagerService=class extends a.RxDisposable{constructor(e,t,n){super();M(this,"_docStateChange$",new P.BehaviorSubject(null));M(this,"docStateChange$",this._docStateChange$.asObservable());M(this,"_stateCache",new Map);M(this,"_timer",null);this._undoRedoService=e,this._commandService=t,this._univerInstanceService=n,this._initialize()}setChangeState(e){const{trigger:t,noHistory:n}=e;t!=null&&(this._cacheChangeState(e),n||this._docStateChange$.next(e))}_initialize(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===a.UndoCommandId||e.id===a.RedoCommandId){const t=this._univerInstanceService.getCurrentUniverDocInstance();if(t==null)return;const n=t.getUnitId();this._pushHistory(n)}}))}_cacheChangeState(e){const{trigger:t,unitId:n,noHistory:s}=e;if(!(t===a.RedoCommandId||t===a.UndoCommandId||s)){if(this._stateCache.has(n)){const r=this._stateCache.get(n);r==null||r.push(e)}else this._stateCache.set(n,[e]);t===X.id||t===V.id?(this._timer&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._pushHistory(n)},Je)):this._pushHistory(n)}}_pushHistory(e){const t=this._undoRedoService,n=this._stateCache.get(e);if(!Array.isArray(n)||n.length===0)return;const s=n.length,r=n[0].commandId,c=n[0],l=n[s-1],m={unitId:e,actions:n.reduce((g,S)=>a.TextX.compose(g,S.redoState.actions),[]),textRanges:l.redoState.textRanges},u={unitId:e,actions:n.reverse().reduce((g,S)=>a.TextX.compose(g,S.undoState.actions),[]),textRanges:c.undoState.textRanges};t.pushUndoRedo({unitID:e,undoMutations:[{id:r,params:u}],redoMutations:[{id:r,params:m}]}),n.length=0}},d.DocStateChangeManagerService=Ke([de(0,A.Inject(a.IUndoRedoService)),de(1,a.ICommandService),de(2,a.IUniverInstanceService)],d.DocStateChangeManagerService);class F{constructor(){M(this,"_previousActiveRange",null);M(this,"_undoMutationParamsCache",[]);M(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache:i=[],redoCache:e=[]}){this._undoMutationParamsCache=i,this._redoMutationParamsCache=e}getActiveRange(){return this._previousActiveRange}setActiveRange(i){this._previousActiveRange=i}pushUndoRedoMutationParams(i,e){this._undoMutationParamsCache.push(i),this._redoMutationParamsCache.push(e)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:i}=this._undoMutationParamsCache[0],e={unitId:i,actions:this._undoMutationParamsCache.reverse().reduce((n,s)=>a.TextX.compose(n,s.actions),[]),textRanges:[]};return{redoMutationParams:{unitId:i,actions:this._redoMutationParamsCache.reduce((n,s)=>a.TextX.compose(n,s.actions),[]),textRanges:[]},undoMutationParams:e,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Me="doc.mutation.rich-text-editing",N={id:Me,type:a.CommandType.MUTATION,handler:(o,i)=>{var x;const{unitId:e,actions:t,textRanges:n,prevTextRanges:s,trigger:r,noHistory:c,isCompositionEnd:l,noNeedSetTextRange:m}=i,g=o.get(a.IUniverInstanceService).getUniverDocInstance(e),f=o.get(d.DocViewModelManagerService).getViewModel(e),_=o.get(d.TextSelectionManagerService),h=((x=_.getSelections())!=null?x:[]).map($),I=o.get(d.DocStateChangeManagerService),v=o.get(F);if(g==null||f==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);if(t.length===0)return{unitId:e,actions:[],textRanges:h};const T=g.apply(t),{segmentId:y}=t[0],R=g.getSelfOrHeaderFooterModel(y);f.getSelfOrHeaderFooterViewModel(y).reset(R),!m&&n&&r!=null&&queueMicrotask(()=>{_.replaceTextRanges(n)});const E={commandId:Me,unitId:e,trigger:r,noHistory:c,redoState:{actions:t,textRanges:n},undoState:{actions:T,textRanges:s!=null?s:h}};if(l){const D=v.fetchComposedUndoRedoMutationParams();if(D==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:C,redoMutationParams:L,previousActiveRange:b}=D;E.redoState.actions=L.actions,E.undoState.actions=C.actions,E.undoState.textRanges=[b]}return I.setChangeState(E),{unitId:e,actions:T,textRanges:h}}},X={id:"doc.command.insert-text",type:a.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(a.ICommandService),{range:t,segmentId:n,body:s,unitId:r,textRanges:c}=i,{startOffset:l,collapsed:m}=t,u={id:N.id,params:{unitId:r,actions:[],textRanges:c}},g=new a.TextX;return m?l>0&&g.push({t:a.TextXActionType.RETAIN,len:l,segmentId:n}):g.push(...le(t,n)),g.push({t:a.TextXActionType.INSERT,body:s,len:s.dataStream.length,line:0,segmentId:n}),u.params.actions=g.serialize(),!!e.syncExecuteCommand(u.id,u.params)}};var w=(o=>(o[o.LEFT=0]="LEFT",o[o.RIGHT=1]="RIGHT",o))(w||{});const V={id:"doc.command.delete-text",type:a.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(a.ICommandService),{range:t,segmentId:n,unitId:s,direction:r,textRanges:c,len:l=1}=i,{startOffset:m}=t,u={id:N.id,params:{unitId:s,actions:[],textRanges:c}},g=new a.TextX;return m>0&&g.push({t:a.TextXActionType.RETAIN,len:r===0?m-l:m,segmentId:n}),g.push({t:a.TextXActionType.DELETE,len:l,line:0,segmentId:n}),u.params.actions=g.serialize(),!!e.syncExecuteCommand(u.id,u.params)}},ue={id:"doc.command.update-text",type:a.CommandType.COMMAND,handler:async(o,i)=>{const{range:e,segmentId:t,updateBody:n,coverType:s,unitId:r,textRanges:c}=i,l=o.get(a.ICommandService),m={id:N.id,params:{unitId:r,actions:[],textRanges:c}},u=new a.TextX,{startOffset:g,endOffset:S}=e;return u.push({t:a.TextXActionType.RETAIN,len:g,segmentId:t}),u.push({t:a.TextXActionType.RETAIN,body:n,len:S-g,segmentId:t,coverType:s}),m.params.actions=u.serialize(),!!l.syncExecuteCommand(m.id,m.params)}};function Qe(o,i){const e=[];for(let t=0,n=o.length;t<n;t++)o[t]===a.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});if(i)for(const t of e)i.bullet&&(t.bullet=a.Tools.deepClone(i.bullet)),i.paragraphStyle&&(t.paragraphStyle=a.Tools.deepClone(i.paragraphStyle));return e}const Te={id:"doc.command.break-line",type:a.CommandType.COMMAND,handler:async o=>{var _,p;const i=o.get(d.TextSelectionManagerService),e=o.get(a.IUniverInstanceService),t=o.get(a.ICommandService),n=i.getActiveRange();if(n==null)return!1;const s=e.getCurrentUniverDocInstance(),r=s.getUnitId(),{startOffset:c,segmentId:l,style:m}=n,u=[{startOffset:c+1,endOffset:c+1,style:m}],S=((p=(_=s.getBody())==null?void 0:_.paragraphs)!=null?p:[]).find(h=>h.startIndex>=c);return await t.executeCommand(X.id,{unitId:r,body:{dataStream:a.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Qe(a.DataStreamTreeTokenType.PARAGRAPH,S)},range:n,textRanges:u,segmentId:l})}};var et=Object.defineProperty,tt=Object.getOwnPropertyDescriptor,nt=(o,i,e,t)=>{for(var n=t>1?void 0:t?tt(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&et(i,e,n),n},me=(o,i)=>(e,t)=>i(e,t,o);d.DocSkeletonManagerService=class extends a.RxDisposable{constructor(e,t,n){super();M(this,"_currentSkeletonUnitId","");M(this,"_docSkeletonMap",new Map);M(this,"_currentSkeleton$",new P.BehaviorSubject(null));M(this,"currentSkeleton$",this._currentSkeleton$.asObservable());M(this,"_currentSkeletonBefore$",new P.BehaviorSubject(null));M(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._localeService=e,this._docViewModelManagerService=t,this._currentUniverService=n,this._initialize()}_initialize(){this._init()}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._docSkeletonMap.clear()}_init(){this._docViewModelManagerService.currentDocViewModel$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._setCurrent(e)}),this._docViewModelManagerService.getAllModel().forEach(e=>{e!=null&&this._setCurrent(e)}),this._currentUniverService.docDisposed$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{this._docSkeletonMap.delete(e.getUnitId()),this._currentSkeletonUnitId=this._currentUniverService.getCurrentUniverDocInstance().getUnitId()})}getCurrent(){return this.getSkeletonByUnitId(this._currentSkeletonUnitId)}getAllSkeleton(){return this._docSkeletonMap}makeDirtyCurrent(e=!0){this.makeDirty(this._currentSkeletonUnitId,e)}makeDirty(e,t=!0){const n=this.getSkeletonByUnitId(e);n!=null&&(n.dirty=t)}getSkeletonByUnitId(e){return this._docSkeletonMap.get(e)}_setCurrent(e){const{unitId:t}=e;if(this._docSkeletonMap.has(t)){const n=this.getSkeletonByUnitId(t);n.skeleton.calculate(),n.dirty=!0}else{const n=this._buildSkeleton(e.docViewModel);n.calculate(),this._docSkeletonMap.set(t,{unitId:t,skeleton:n,dirty:!1})}return this._currentSkeletonUnitId=t,this._currentSkeletonBefore$.next(this.getCurrent()),this._currentSkeleton$.next(this.getCurrent()),this.getCurrent()}_buildSkeleton(e){return O.DocumentSkeleton.create(e,this._localeService)}},d.DocSkeletonManagerService=nt([me(0,A.Inject(a.LocaleService)),me(1,A.Inject(d.DocViewModelManagerService)),me(2,a.IUniverInstanceService)],d.DocSkeletonManagerService);const it={id:"doc.command.inner-paste",type:a.CommandType.COMMAND,handler:async(o,i)=>{const{segmentId:e,body:t,textRanges:n}=i,s=o.get(a.ICommandService),r=o.get(d.TextSelectionManagerService),c=o.get(a.IUniverInstanceService),l=r.getSelections();if(!Array.isArray(l)||l.length===0)return!1;const u=c.getCurrentUniverDocInstance().getUnitId(),g={id:N.id,params:{unitId:u,actions:[],textRanges:n}},S=new a.MemoryCursor;S.reset();const f=new a.TextX;for(const p of l){const{startOffset:h,endOffset:I,collapsed:v}=p,T=h-S.cursor;v?f.push({t:a.TextXActionType.RETAIN,len:T,segmentId:e}):f.push(...le(p,e,S.cursor)),f.push({t:a.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:e}),S.reset(),S.moveCursor(I)}return g.params.actions=f.serialize(),!!s.syncExecuteCommand(g.id,g.params)}},ge={id:"doc.command.inner-cut",type:a.CommandType.COMMAND,handler:async(o,i)=>{const{segmentId:e,textRanges:t}=i,n=o.get(a.ICommandService),s=o.get(d.TextSelectionManagerService),r=o.get(a.IUniverInstanceService),c=s.getSelections();if(!Array.isArray(c)||c.length===0)return!1;const l=r.getCurrentUniverDocInstance().getUnitId(),m=r.getUniverDocInstance(l),u=a.getDocsUpdateBody(m.snapshot,e);if(u==null)return!1;const g={id:N.id,params:{unitId:l,actions:[],textRanges:t}},S=new a.MemoryCursor;S.reset();const f=new a.TextX;for(const p of c){const{startOffset:h,endOffset:I,collapsed:v}=p,T=h-S.cursor;v?f.push({t:a.TextXActionType.RETAIN,len:T,segmentId:e}):f.push(...at(p,u,e,S.cursor)),S.reset(),S.moveCursor(I)}return g.params.actions=f.serialize(),!!n.syncExecuteCommand(g.id,g.params)}};function at(o,i,e="",t=0){const{startOffset:n,endOffset:s}=o,r=[],{paragraphs:c=[]}=i,l=n-t,m=s-t,u=c==null?void 0:c.find(g=>g.startIndex-t>=l&&g.startIndex-t<=m);if(l>0&&r.push({t:a.TextXActionType.RETAIN,len:l,segmentId:e}),u&&u.startIndex-t>l){const g=u.startIndex-t;r.push({t:a.TextXActionType.DELETE,len:g-l,line:0,segmentId:e}),r.push({t:a.TextXActionType.RETAIN,len:1,segmentId:e}),m>g+1&&r.push({t:a.TextXActionType.DELETE,len:m-g-1,line:0,segmentId:e})}else r.push({t:a.TextXActionType.DELETE,len:m-l,line:0,segmentId:e});return r}const ye={id:"doc.command.delete-left",type:a.CommandType.COMMAND,handler:async o=>{var y;const i=o.get(d.TextSelectionManagerService),e=o.get(d.DocSkeletonManagerService),t=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService),s=i.getActiveRange(),r=i.getSelections(),c=(y=e.getCurrent())==null?void 0:y.skeleton;let l=!0;if(s==null||c==null||r==null)return!1;const m=t.getCurrentUniverDocInstance(),{startOffset:u,collapsed:g,segmentId:S,style:f}=s,_=c.findNodeByCharIndex(u),p=O.hasListSpan(_),h=O.isIndentBySpan(_,m.getBody());let I=u;const v=c.findNodeByCharIndex(u-1);if(O.isFirstSpan(_)&&v!==_&&(p===!0||h===!0)){const R=O.getParagraphBySpan(_,m.getBody());if(R==null)return!1;const U=R==null?void 0:R.startIndex,E={startIndex:0},x=R.paragraphStyle;if(p===!0){const C=R.paragraphStyle;C&&(E.paragraphStyle=C)}else if(h===!0){const C=R.bullet;C&&(E.bullet=C),x!=null&&(E.paragraphStyle={...x},delete E.paragraphStyle.hanging,delete E.paragraphStyle.indentStart)}const D=[{startOffset:I,endOffset:I,style:f}];l=await n.executeCommand(ue.id,{unitId:m.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...E}]},range:{startOffset:U,endOffset:U+1},textRanges:D,coverType:a.UpdateDocsAttributeType.REPLACE,segmentId:S})}else if(g===!0){if(v==null)return!0;if(v.content==="\r")l=await n.executeCommand(Se.id,{direction:w.LEFT,range:s});else{I-=v.count;const R=[{startOffset:I,endOffset:I,style:f}];l=await n.executeCommand(V.id,{unitId:m.getUnitId(),range:s,segmentId:S,direction:w.LEFT,len:v.count,textRanges:R})}}else{const R=Oe(s,r);l=await n.executeCommand(ge.id,{segmentId:S,textRanges:R})}return l}},Re={id:"doc.command.delete-right",type:a.CommandType.COMMAND,handler:async o=>{var _;const i=o.get(d.TextSelectionManagerService),e=o.get(d.DocSkeletonManagerService),t=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService),s=i.getActiveRange(),r=i.getSelections(),c=(_=e.getCurrent())==null?void 0:_.skeleton;let l;if(s==null||c==null||r==null)return!1;const m=t.getCurrentUniverDocInstance(),{startOffset:u,collapsed:g,segmentId:S,style:f}=s;if(u===m.getBody().dataStream.length-2&&g)return!0;if(g===!0){const p=c.findNodeByCharIndex(u);if(p.content==="\r")l=await n.executeCommand(Se.id,{direction:w.RIGHT,range:s});else{const h=[{startOffset:u,endOffset:u,style:f}];l=await n.executeCommand(V.id,{unitId:m.getUnitId(),range:s,segmentId:S,direction:w.RIGHT,textRanges:h,len:p.count})}}else{const p=Oe(s,r);l=await n.executeCommand(ge.id,{segmentId:S,textRanges:p})}return l}},Se={id:"doc.command.merge-two-paragraph",type:a.CommandType.COMMAND,handler:async(o,i)=>{var E,x,D;const e=o.get(d.TextSelectionManagerService),t=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService);o.get(a.IUndoRedoService);const{direction:s,range:r}=i,c=e.getActiveRange(),l=e.getSelections();if(c==null||l==null)return!1;const m=t.getCurrentUniverDocInstance(),{startOffset:u,collapsed:g,segmentId:S,style:f}=c;if(!g)return!1;const _=s===w.LEFT?u:u+1,p=(D=(x=(E=m.getBody())==null?void 0:E.paragraphs)==null?void 0:x.find(C=>C.startIndex>=_))==null?void 0:D.startIndex,h=st(m.getBody(),_,p),I=s===w.LEFT?u-1:u,v=m.getUnitId(),T=[{startOffset:I,endOffset:I,style:f}],y={id:N.id,params:{unitId:v,actions:[],textRanges:T,prevTextRanges:[r]}},R=new a.TextX;return R.push({t:a.TextXActionType.RETAIN,len:s===w.LEFT?u-1:u,segmentId:S}),h.dataStream.length&&R.push({t:a.TextXActionType.INSERT,body:h,len:h.dataStream.length,line:0,segmentId:S}),R.push({t:a.TextXActionType.RETAIN,len:1,segmentId:S}),R.push({t:a.TextXActionType.DELETE,len:p+1-_,line:0,segmentId:S}),y.params.actions=R.serialize(),!!n.syncExecuteCommand(y.id,y.params)}};function st(o,i,e){const{textRuns:t}=o,n=o.dataStream.substring(i,e);if(t==null)return{dataStream:n};const s=[];for(const r of t){const{st:c,ed:l}=r;l<=i||c>=e||(c<i?s.push({...r,st:0,ed:l-i}):l>e?s.push({...r,st:c-i,ed:e-i}):s.push({...r,st:c-i,ed:l-i}))}return{dataStream:n,textRuns:s}}function Oe(o,i){let e=o.endOffset;for(const n of i){const{startOffset:s,endOffset:r}=n;s==null||r==null||r<=o.endOffset&&(e-=r-s)}return[{startOffset:e,endOffset:e,style:o.style}]}const fe={id:"doc.command.ime-input",type:a.CommandType.COMMAND,handler:async(o,i)=>{const{unitId:e,newText:t,oldTextLen:n,isCompositionEnd:s,isCompositionStart:r}=i,c=o.get(a.ICommandService),l=o.get(F),m=l.getActiveRange();if(m==null)return!1;const{startOffset:u,style:g,segmentId:S}=m,f=t.length,_=[{startOffset:u+f,endOffset:u+f,collapsed:!0,style:g}],p={id:N.id,params:{unitId:e,actions:[],textRanges:_}},h=new a.TextX;!m.collapsed&&r?h.push(...le(m,S)):h.push({t:a.TextXActionType.RETAIN,len:u,segmentId:S}),n>0&&h.push({t:a.TextXActionType.DELETE,len:n,line:0,segmentId:S}),h.push({t:a.TextXActionType.INSERT,body:{dataStream:t},len:t.length,line:0,segmentId:S}),p.params.actions=h.serialize(),p.params.noHistory=!s,p.params.isCompositionEnd=s;const I=c.syncExecuteCommand(p.id,p.params);return l.pushUndoRedoMutationParams(I,p.params),!!I}},k={id:"doc.command.set-inline-format-bold",type:a.CommandType.COMMAND,handler:async()=>!0},j={id:"doc.command.set-inline-format-italic",type:a.CommandType.COMMAND,handler:async()=>!0},z={id:"doc.command.set-inline-format-underline",type:a.CommandType.COMMAND,handler:async()=>!0},H={id:"doc.command.set-inline-format-strikethrough",type:a.CommandType.COMMAND,handler:async()=>!0},B={id:"doc.command.set-inline-format-subscript",type:a.CommandType.COMMAND,handler:async()=>!0},G={id:"doc.command.set-inline-format-superscript",type:a.CommandType.COMMAND,handler:async()=>!0},Y={id:"doc.command.set-inline-format-fontsize",type:a.CommandType.COMMAND,handler:async()=>!0},W={id:"doc.command.set-inline-format-font-family",type:a.CommandType.COMMAND,handler:async()=>!0},Z={id:"doc.command.set-inline-format-text-color",type:a.CommandType.COMMAND,handler:async()=>!0},xe={[k.id]:"bl",[j.id]:"it",[z.id]:"ul",[H.id]:"st",[Y.id]:"fs",[W.id]:"ff",[Z.id]:"cl",[B.id]:"va",[G.id]:"va"},he={id:"doc.command.set-inline-format",type:a.CommandType.COMMAND,handler:async(o,i)=>{const{segmentId:e,value:t,preCommandId:n}=i,s=o.get(a.ICommandService),r=o.get(d.TextSelectionManagerService),c=o.get(a.IUniverInstanceService),l=r.getSelections();if(!Array.isArray(l)||l.length===0)return!1;let m=c.getCurrentUniverDocInstance(),u=m.getUnitId();u===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(m=c.getUniverDocInstance(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),u=m.getUnitId());let g;switch(n){case k.id:case j.id:case z.id:case H.id:case B.id:case G.id:{g=rt(m.getBody().textRuns,n,l);break}case Y.id:case W.id:{g=t;break}case Z.id:{g={rgb:t};break}default:throw new Error(`Unknown command: ${n} in handleInlineFormat`)}const S={id:N.id,params:{unitId:u,actions:[],textRanges:l.map($)}},f=new a.TextX,_=new a.MemoryCursor;_.reset();for(const h of l){const{startOffset:I,endOffset:v}=h,T={dataStream:"",textRuns:[{st:0,ed:v-I,ts:{[xe[n]]:g}}]},y=I-_.cursor;y!==0&&f.push({t:a.TextXActionType.RETAIN,len:y,segmentId:e}),f.push({t:a.TextXActionType.RETAIN,body:T,len:v-I,segmentId:e}),_.reset(),_.moveCursor(v)}return S.params.actions=f.serialize(),!!s.syncExecuteCommand(S.id,S.params)}};function ot(o){return o!==null&&typeof o=="object"}function rt(o,i,e){let t=0,n=0;const s=xe[i];for(;t!==o.length&&n!==e.length;){const{startOffset:r,endOffset:c}=e[n],{st:l,ed:m,ts:u}=o[t];if(c<=l)n++;else if(m<=r)t++;else{if(/bl|it/.test(s))return(u==null?void 0:u[s])===a.BooleanNumber.TRUE?a.BooleanNumber.FALSE:a.BooleanNumber.TRUE;if(/ul|st/.test(s))return ot(u==null?void 0:u[s])&&(u==null?void 0:u[s]).s===a.BooleanNumber.TRUE?{s:a.BooleanNumber.FALSE}:{s:a.BooleanNumber.TRUE};if(/va/.test(s))return i===B.id?(u==null?void 0:u[s])===a.BaselineOffset.SUBSCRIPT?a.BaselineOffset.NORMAL:a.BaselineOffset.SUBSCRIPT:(u==null?void 0:u[s])===a.BaselineOffset.SUPERSCRIPT?a.BaselineOffset.NORMAL:a.BaselineOffset.SUPERSCRIPT;t++}}return/bl|it/.test(s)?a.BooleanNumber.TRUE:/ul|st/.test(s)?{s:a.BooleanNumber.TRUE}:i===B.id?a.BaselineOffset.SUBSCRIPT:a.BaselineOffset.SUPERSCRIPT}const pe={id:"doc.command.list-operation",type:a.CommandType.COMMAND,handler:(o,i)=>{var R,U,E;const e=o.get(d.TextSelectionManagerService),t=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService),{listType:s}=i,r=t.getCurrentUniverDocInstance(),c=e.getActiveRange(),l=(R=e.getSelections())!=null?R:[],m=(U=r.getBody())==null?void 0:U.paragraphs,u=l.map($);if(c==null||m==null)return!1;const g=ct(c,m),{segmentId:S}=c,f=r.getUnitId(),_=g.every(x=>{var D;return((D=x.bullet)==null?void 0:D.listType)===s});let h=a.Tools.generateRandomId(6);if(g.length===1){const x=m.indexOf(g[0]),D=m[x-1],C=m[x+1];D&&D.bullet&&D.bullet.listType===s?h=D.bullet.listId:C&&C.bullet&&C.bullet.listType===s&&(h=C.bullet.listId)}const I={id:N.id,params:{unitId:f,actions:[],textRanges:u}},v=new a.MemoryCursor;v.reset();const T=new a.TextX;for(const x of g){const{startIndex:D}=x;T.push({t:a.TextXActionType.RETAIN,len:D-v.cursor,segmentId:S});const C={...x.paragraphStyle,hanging:void 0,indentStart:void 0};T.push({t:a.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[_?{paragraphStyle:C,startIndex:0}:{...x,startIndex:0,bullet:{...(E=x.bullet)!=null?E:{nestingLevel:0,textStyle:{fs:20}},listType:s,listId:h}}]},segmentId:S,coverType:a.UpdateDocsAttributeType.REPLACE}),v.moveCursorTo(D+1)}return I.params.actions=T.serialize(),!!n.syncExecuteCommand(I.id,I.params)}},De={id:"doc.command.bullet-list",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(pe.id,{listType:a.PresetListType.BULLET_LIST})},Ee={id:"doc.command.order-list",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(pe.id,{listType:a.PresetListType.ORDER_LIST})};function ct(o,i){const{startOffset:e,endOffset:t}=o,n=[];let s=-1;for(const r of i){const{startIndex:c}=r;(e>s&&e<=c||t>s&&t<=c||c>=e&&c<=t)&&n.push(r),s=c}return n}const Ue={id:"doc.command-replace-content",type:a.CommandType.COMMAND,handler:async(o,i)=>{var f;const{unitId:e,body:t,textRanges:n,segmentId:s=""}=i,r=o.get(a.IUniverInstanceService),c=o.get(a.ICommandService),l=o.get(d.TextSelectionManagerService),m=(f=r.getUniverDocInstance(e))==null?void 0:f.getSnapshot().body,u=l.getSelections();if(m==null||!Array.isArray(u)||u.length===0)return!1;const g=Ne(e,s,m,t);return g.params.textRanges=n,!!c.syncExecuteCommand(g.id,g.params)}},Ae={id:"doc.command-cover-content",type:a.CommandType.COMMAND,handler:async(o,i)=>{var u;const{unitId:e,body:t,segmentId:n=""}=i,s=o.get(a.IUniverInstanceService),r=o.get(a.ICommandService),c=o.get(a.IUndoRedoService),l=(u=s.getUniverDocInstance(e))==null?void 0:u.getSnapshot().body;if(l==null)return!1;const m=Ne(e,n,l,t);return m.params.noNeedSetTextRange=!0,m.params.noHistory=!0,r.syncExecuteCommand(m.id,m.params),c.clearUndoRedo(e),!0}};function Ne(o,i,e,t){const n={id:N.id,params:{unitId:o,actions:[],textRanges:[]}},s=new a.TextX,r=(e==null?void 0:e.dataStream.length)-2;return r>0&&s.push({t:a.TextXActionType.DELETE,len:r,line:0,segmentId:i}),t.dataStream.length>0&&s.push({t:a.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:i}),n.params.actions=s.serialize(),n}const ee={id:"doc.operation.move-cursor",type:a.CommandType.OPERATION,handler:(o,i)=>!!i},te={id:"doc.operation.move-selection",type:a.CommandType.OPERATION,handler:(o,i)=>!!i},lt=(o,i)=>{const e=o.get(a.IUniverInstanceService).getUniverDocInstance(i.unitId),t=(e==null?void 0:e.zoomRatio)||1;return{...a.Tools.deepClone(i),zoomRatio:t}},q={id:"doc.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(o,i)=>{const e=o.get(a.IUniverInstanceService).getUniverDocInstance(i.unitId);if(!e)return!1;const t=e.getSnapshot();return t.settings==null?t.settings={zoomRatio:i.zoomRatio}:t.settings.zoomRatio=i.zoomRatio,!0}},Pe={type:a.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(o,i)=>{var g,S;const e=o.get(a.ICommandService),t=o.get(a.IUndoRedoService),n=o.get(a.IUniverInstanceService);let s=n.getCurrentUniverDocInstance().getUnitId(),r=1;if(i&&(s=(g=i.documentId)!=null?g:s,r=(S=i.zoomRatio)!=null?S:r),!n.getUniverDocInstance(s))return!1;const l={zoomRatio:r,unitId:s},m=lt(o,l);return e.syncExecuteCommand(q.id,l)?(t.pushUndoRedo({unitID:s,undoMutations:[{id:q.id,params:m}],redoMutations:[{id:q.id,params:l}]}),!0):!1}},be={id:"doc.operation.select-all",type:a.CommandType.COMMAND,handler:async o=>{const i=o.get(a.IUniverInstanceService),e=o.get(d.TextSelectionManagerService),t=i.getCurrentUniverDocInstance().getSnapshot().body;if(t==null)return!1;const n=[{startOffset:0,endOffset:t.dataStream.length-2}];return e.replaceTextRanges(n,!1),!0}};var dt=Object.defineProperty,ut=Object.getOwnPropertyDescriptor,mt=(o,i,e,t)=>{for(var n=t>1?void 0:t?ut(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&dt(i,e,n),n},K=(o,i)=>(e,t)=>i(e,t,o);let ne=class extends a.Disposable{constructor(i,e,t,n,s){super();M(this,"_previousIMEContent","");M(this,"_isCompositionStart",!0);M(this,"_onStartSubscription");M(this,"_onUpdateSubscription");M(this,"_onEndSubscription");this._docSkeletonManagerService=i,this._currentUniverService=e,this._textSelectionRenderManager=t,this._imeInputManagerService=n,this._commandService=s,this._initialize()}dispose(){var i,e,t;(i=this._onStartSubscription)==null||i.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(i=>{if(i==null)return;const{activeRange:e}=i;e!=null&&(this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(a.Tools.deepClone(e)),this._isCompositionStart=!0)})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._textSelectionRenderManager.onCompositionupdate$.subscribe(async i=>{this._updateContent(i,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._textSelectionRenderManager.onCompositionend$.subscribe(i=>{this._updateContent(i,!1)})}async _updateContent(i,e){var m;const t=(m=this._docSkeletonManagerService.getCurrent())==null?void 0:m.skeleton;if(i==null||t==null)return;const n=this._currentUniverService.getCurrentUniverDocInstance(),{event:s,activeRange:r}=i;if(t==null||r==null)return;const l=s.data;l===this._previousIMEContent&&e||(await this._commandService.executeCommand(fe.id,{unitId:n.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)}};ne=mt([a.OnLifecycle(a.LifecycleStages.Rendered,ne),K(0,A.Inject(d.DocSkeletonManagerService)),K(1,a.IUniverInstanceService),K(2,O.ITextSelectionRenderManager),K(3,A.Inject(F)),K(4,a.ICommandService)],ne);var gt=Object.defineProperty,St=Object.getOwnPropertyDescriptor,ft=(o,i,e,t)=>{for(var n=t>1?void 0:t?St(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&gt(i,e,n),n},we=(o,i)=>(e,t)=>i(e,t,o);let ie=class extends a.Disposable{constructor(o,i){super(),this._textSelectionManagerService=o,this._commandService=i,this._commandExecutedListener()}_commandExecutedListener(){const o=[k.id,j.id,z.id,H.id,B.id,G.id,Y.id,W.id,Z.id];this.disposeWithMe(this._commandService.onCommandExecuted(i=>{o.includes(i.id)&&this._handleInlineFormat(i)}))}_handleInlineFormat(o){var e,t;const{segmentId:i}=(e=this._textSelectionManagerService.getActiveRange())!=null?e:{};i!=null&&this._commandService.executeCommand(he.id,{segmentId:i,preCommandId:o.id,...(t=o.params)!=null?t:{}})}};ie=ft([a.OnLifecycle(a.LifecycleStages.Rendered,ie),we(0,A.Inject(d.TextSelectionManagerService)),we(1,a.ICommandService)],ie);var ht=Object.defineProperty,pt=Object.getOwnPropertyDescriptor,vt=(o,i,e,t)=>{for(var n=t>1?void 0:t?pt(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&ht(i,e,n),n},J=(o,i)=>(e,t)=>i(e,t,o);let ae=class extends a.Disposable{constructor(i,e,t,n,s){super();M(this,"_onInputSubscription");this._docSkeletonManagerService=i,this._currentUniverService=e,this._renderManagerService=t,this._textSelectionManagerService=n,this._commandService=s,this._initialize(),this._commandExecutedListener()}dispose(){var i;(i=this._onInputSubscription)==null||i.unsubscribe()}_initialize(){}_commandExecutedListener(){const i=[ee.id,te.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!i.includes(e.id))return;const t=e.params;switch(e.id){case ee.id:return this._handleMoveCursor(t.direction);case te.id:return this._handleShiftMoveSelection(t.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(i){var p,h,I;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),n=this._currentUniverService.getCurrentUniverDocInstance(),s=(p=this._docSkeletonManagerService.getCurrent())==null?void 0:p.skeleton,r=this._getDocObject();if(e==null||s==null||r==null)return;const{startOffset:c,endOffset:l,style:m,collapsed:u,direction:g}=e;if(t.length>1){let v=Number.POSITIVE_INFINITY,T=Number.NEGATIVE_INFINITY;for(const y of t)v=Math.min(v,y.startOffset),T=Math.max(T,y.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:i===a.Direction.LEFT||i===a.Direction.UP?T:v,endOffset:i===a.Direction.LEFT||i===a.Direction.UP?v:T,style:m}],!1);return}const S=u||g===O.RANGE_DIRECTION.FORWARD?c:l;let f=u||g===O.RANGE_DIRECTION.FORWARD?l:c;const _=(h=n.getBody().dataStream.length)!=null?h:Number.POSITIVE_INFINITY;if(i===a.Direction.LEFT||i===a.Direction.RIGHT){const v=s.findNodeByCharIndex(f-1),T=s.findNodeByCharIndex(f);f=i===a.Direction.RIGHT?f+T.count:f-((I=v==null?void 0:v.count)!=null?I:0),f=Math.min(_-2,Math.max(0,f)),this._textSelectionManagerService.replaceTextRanges([{startOffset:S,endOffset:f,style:m}],!1)}else{const v=s.findNodeByCharIndex(f),T=r.document.getOffsetConfig(),y=this._getTopOrBottomPosition(s,v,i===a.Direction.DOWN);if(y==null){const U=i===a.Direction.UP?0:_-2;if(U===f)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:S,endOffset:U,style:m}],!1);return}const R=new O.NodePositionConvertToCursor(T,s).getRangePointData(y,y).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:S,endOffset:R.endOffset,style:m}],!1)}}_handleMoveCursor(i){var S,f,_;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),n=this._currentUniverService.getCurrentUniverDocInstance(),s=(S=this._docSkeletonManagerService.getCurrent())==null?void 0:S.skeleton,r=this._getDocObject();if(e==null||s==null||r==null||t==null)return;const{startOffset:c,endOffset:l,style:m,collapsed:u}=e,g=(f=n.getBody().dataStream.length)!=null?f:Number.POSITIVE_INFINITY;if(i===a.Direction.LEFT||i===a.Direction.RIGHT){let p;if(!e.collapsed||t.length>1){let h=Number.POSITIVE_INFINITY,I=Number.NEGATIVE_INFINITY;for(const v of t)h=Math.min(h,v.startOffset),I=Math.max(I,v.endOffset);p=i===a.Direction.LEFT?h:I}else{const h=s.findNodeByCharIndex(c-1),I=s.findNodeByCharIndex(c);i===a.Direction.LEFT?p=Math.max(0,c-((_=h==null?void 0:h.count)!=null?_:0)):p=Math.min(g-2,l+I.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:p,style:m}],!1)}else{const p=s.findNodeByCharIndex(c),h=s.findNodeByCharIndex(l),I=r.document.getOffsetConfig(),v=this._getTopOrBottomPosition(s,i===a.Direction.UP?p:h,i===a.Direction.DOWN);if(v==null){let y;u?y=i===a.Direction.UP?0:g-2:y=i===a.Direction.UP?c:l,this._textSelectionManagerService.replaceTextRanges([{startOffset:y,endOffset:y,style:m}],!1);return}const T=new O.NodePositionConvertToCursor(I,s).getRangePointData(v,v).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...T,style:m}],!1)}}_getTopOrBottomPosition(i,e,t){if(e==null)return;const n=this._getSpanLeftOffsetInLine(e),s=this._getNextOrPrevLine(e,t);if(s==null)return;const r=this._matchPositionByLeftOffset(i,s,n);if(r!=null)return{...r,isBack:!0}}_getSpanLeftOffsetInLine(i){const e=i.parent;if(e==null)return Number.NEGATIVE_INFINITY;const t=e.left,{left:n}=i;return t+n}_matchPositionByLeftOffset(i,e,t){const n={distance:Number.POSITIVE_INFINITY};for(const s of e.divides){const r=s.left;for(const c of s.spanGroup){const{left:l}=c,m=r+l,u=Math.abs(t-m);u<n.distance&&(n.span=c,n.distance=u)}}if(n.span!=null)return i.findPositionBySpan(n.span)}_getNextOrPrevLine(i,e){var _,p,h,I,v,T,y,R,U,E,x,D;const t=i.parent;if(t==null)return;const n=t.parent;if(n==null)return;const s=n.parent;if(s==null)return;const r=s.lines.indexOf(n);if(r===-1)return;let c;if(e===!0?c=s.lines[r+1]:c=s.lines[r-1],c!=null)return c;const l=s.parent;if(l==null)return;const m=l.columns.indexOf(s);if(m===-1)return;if(e===!0)c=(_=l.columns[m+1])==null?void 0:_.lines[0];else{const C=(h=(p=l.columns)==null?void 0:p[m-1])==null?void 0:h.lines;c=C==null?void 0:C[C.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=(v=(I=u.sections[g-1])==null?void 0:I.columns[0])==null?void 0:v.lines[0];else{const C=(y=(T=u.sections)==null?void 0:T[g-1])==null?void 0:y.columns,L=C==null?void 0:C[C.length-1],b=L==null?void 0:L.lines;c=b==null?void 0:b[b.length-1]}if(c!=null)return c;const S=u.parent;if(S==null)return;const f=S.pages.indexOf(u);if(f!==-1){if(e===!0)c=(E=(U=(R=S.pages[f+1])==null?void 0:R.sections[0])==null?void 0:U.columns[0])==null?void 0:E.lines[0];else{const C=(x=S.pages[f-1])==null?void 0:x.sections;if(C==null)return;const L=(D=C[C.length-1])==null?void 0:D.columns,b=L[L.length-1],Le=b==null?void 0:b.lines;c=Le[Le.length-1]}if(c!=null)return c}}_getDocObject(){return re(this._currentUniverService,this._renderManagerService)}};ae=vt([a.OnLifecycle(a.LifecycleStages.Rendered,ae),J(0,A.Inject(d.DocSkeletonManagerService)),J(1,a.IUniverInstanceService),J(2,O.IRenderManagerService),J(3,A.Inject(d.TextSelectionManagerService)),J(4,a.ICommandService)],ae);var _t=Object.defineProperty,It=Object.getOwnPropertyDescriptor,Ct=(o,i,e,t)=>{for(var n=t>1?void 0:t?It(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&_t(i,e,n),n},Q=(o,i)=>(e,t)=>i(e,t,o);let se=class extends a.Disposable{constructor(i,e,t,n,s){super();M(this,"_onInputSubscription");this._docSkeletonManagerService=i,this._currentUniverService=e,this._renderManagerService=t,this._textSelectionRenderManager=n,this._commandService=s,this._initialize(),this._commandExecutedListener()}dispose(){var i;(i=this._onInputSubscription)==null||i.unsubscribe()}_initialize(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async i=>{var _;if(i==null)return;const t=this._currentUniverService.getCurrentUniverDocInstance().getUnitId(),{event:n,content:s="",activeRange:r}=i,c=n,l=(_=this._docSkeletonManagerService.getCurrent())==null?void 0:_.skeleton;if(c.data==null||l==null||!l||!r)return;const{startOffset:m,segmentId:u,style:g}=r,S=s.length,f=[{startOffset:m+S,endOffset:m+S,style:g}];await this._commandService.executeCommand(X.id,{unitId:t,body:{dataStream:s},range:r,textRanges:f,segmentId:u})})}_commandExecutedListener(){}_getDocObject(){return re(this._currentUniverService,this._renderManagerService)}};se=Ct([a.OnLifecycle(a.LifecycleStages.Rendered,se),Q(0,A.Inject(d.DocSkeletonManagerService)),Q(1,a.IUniverInstanceService),Q(2,O.IRenderManagerService),Q(3,O.ITextSelectionRenderManager),Q(4,a.ICommandService)],se);var Mt=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,yt=(o,i,e,t)=>{for(var n=t>1?void 0:t?Tt(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&Mt(i,e,n),n},oe=(o,i)=>(e,t)=>i(e,t,o);const Rt={hasScroll:!0},Ot="docs";d.UniverDocsPlugin=(ve=class extends a.Plugin{constructor(e={},t,n,s,r){super(Ot);M(this,"_config");this._injector=t,this._localeService=n,this._configService=s,this._currentUniverService=r,this._config=Object.assign(Rt,e),this._initializeDependencies(t),this._initializeCommands()}initialize(){}_initializeCommands(){[ee,te,ye,Re,k,j,z,H,B,G,Y,W,Z,he,Te,X,V,ue,fe,Se,N,Ue,Ae,Pe,q,ce,be,Ee,De,pe].forEach(e=>{this._injector.get(a.ICommandService).registerCommand(e)})}onReady(){this.initialize()}_initializeDependencies(e){[[d.DocSkeletonManagerService],[d.DocViewModelManagerService],[d.DocStateChangeManagerService],[F],[O.ITextSelectionRenderManager,{useClass:O.TextSelectionRenderManager}],[d.TextSelectionManagerService],[se],[ne],[ie],[ae]].forEach(t=>e.add(t))}},M(ve,"type",a.PluginType.Doc),ve),d.UniverDocsPlugin=yt([oe(1,A.Inject(A.Injector)),oe(2,A.Inject(a.LocaleService)),oe(3,a.IConfigService),oe(4,a.IUniverInstanceService)],d.UniverDocsPlugin),d.BreakLineCommand=Te,d.BulletListCommand=De,d.CoverContentCommand=Ae,d.CutContentCommand=ge,d.DOCS_COMPONENT_DEFAULT_Z_INDEX=Xe,d.DOCS_COMPONENT_HEADER_LAYER_INDEX=Fe,d.DOCS_COMPONENT_MAIN_LAYER_INDEX=$e,d.DOCS_VIEW_KEY=_e,d.DeleteCommand=V,d.DeleteLeftCommand=ye,d.DeleteRightCommand=Re,d.IMEInputCommand=fe,d.IMEInputManagerService=F,d.InnerPasteCommand=it,d.InsertCommand=X,d.MoveCursorOperation=ee,d.MoveSelectionOperation=te,d.NORMAL_TEXT_SELECTION_PLUGIN_NAME=Ve,d.OrderListCommand=Ee,d.ReplaceContentCommand=Ue,d.RichTextEditingMutation=N,d.SelectAllOperation=be,d.SetDocZoomRatioCommand=Pe,d.SetDocZoomRatioOperation=q,d.SetInlineFormatBoldCommand=k,d.SetInlineFormatCommand=he,d.SetInlineFormatFontFamilyCommand=W,d.SetInlineFormatFontSizeCommand=Y,d.SetInlineFormatItalicCommand=j,d.SetInlineFormatStrikethroughCommand=H,d.SetInlineFormatSubscriptCommand=B,d.SetInlineFormatSuperscriptCommand=G,d.SetInlineFormatTextColorCommand=Z,d.SetInlineFormatUnderlineCommand=z,d.SetTextSelectionsOperation=ce,d.UpdateCommand=ue,d.VIEWPORT_KEY=Ie,d.getDocObject=re,d.getDocObjectById=Be,d.serializeTextRange=$,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
1
+ (function(d,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("rxjs"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","rxjs","@wendellhu/redi"],a):(d=typeof globalThis<"u"?globalThis:d||self,a(d.UniverDocs={},d.UniverCore,d.UniverEngineRender,d.rxjs,d["@wendellhu/redi"]))})(this,function(d,a,R,P,U){"use strict";var xt=Object.defineProperty;var Dt=(d,a,R)=>a in d?xt(d,a,{enumerable:!0,configurable:!0,writable:!0,value:R}):d[a]=R;var M=(d,a,R)=>(Dt(d,typeof a!="symbol"?a+"":a,R),R);var ve;function re(o,i){const t=o.getCurrentUniverDocInstance().getUnitId(),n=i.getRenderById(t);if(n==null)return;const{mainComponent:s,scene:r,engine:c}=n;return{document:s,scene:r,engine:c}}function Be(o,i){const e=i.getRenderById(o);if(e==null)return;const{mainComponent:t,scene:n,engine:s}=e;return{document:t,scene:n,engine:s}}var _e=(o=>(o.MAIN="__Document_Render_Main__",o))(_e||{}),Ie=(o=>(o.VIEW_MAIN="viewMain",o.VIEW_TOP="viewTop",o.VIEW_LEFT="viewLeft",o.VIEW_LEFT_TOP="viewLeftTop",o))(Ie||{});const $e=0,Fe=2,Xe=10,Ve="normalTextSelectionPluginName",ce={id:"doc.operation.set-selections",type:a.CommandType.OPERATION,handler:(o,i)=>!0};var ke=Object.defineProperty,je=Object.getOwnPropertyDescriptor,ze=(o,i,e,t)=>{for(var n=t>1?void 0:t?je(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&ke(i,e,n),n},Ce=(o,i)=>(e,t)=>i(e,t,o);function $(o){const{startOffset:i,endOffset:e,collapsed:t}=o,n={startOffset:i,endOffset:e,collapsed:t};return typeof o.isActive=="function"&&(n.isActive=o.isActive()),n}d.TextSelectionManagerService=class extends a.RxDisposable{constructor(e,t){super();M(this,"_currentSelection",null);M(this,"_textSelectionInfo",new Map);M(this,"_textSelection$",new P.BehaviorSubject(null));M(this,"textSelection$",this._textSelection$.asObservable());this._textSelectionRenderManager=e,this._commandService=t,this._syncSelectionFromRenderService()}getCurrentSelection(){return this._currentSelection}getCurrentSelectionInfo(){return this._getTextRanges(this._currentSelection)}dispose(){this._textSelection$.complete()}refreshSelection(){this._currentSelection!=null&&this._refresh(this._currentSelection)}setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}setCurrentSelectionNotRefresh(e){this._currentSelection=e}getSelections(){var e;return(e=this._getTextRanges(this._currentSelection))==null?void 0:e.textRanges}getActiveRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:t,segmentId:n,style:s}=e,r=t.find(f=>f.isActive());if(r==null)return null;const{startOffset:c,endOffset:l,collapsed:m,startNodePosition:u,endNodePosition:g,direction:S}=r;return c==null||l==null?null:{startOffset:c,endOffset:l,collapsed:m,startNodePosition:u,endNodePosition:g,direction:S,segmentId:n,style:s}}add(e,t=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,segmentId:"",isEditing:t,style:R.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(P.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:n,subUnitId:s,segmentId:r,style:c,textRanges:l,isEditing:m}=t;this._commandService.executeCommand(ce.id,{unitId:n,subUnitId:s,segmentId:r,style:c,isEditing:m,ranges:l.map($)})}_getTextRanges(e){var s;if(e==null)return;const{unitId:t,subUnitId:n=""}=e;return(s=this._textSelectionInfo.get(t))==null?void 0:s.get(n)}_refresh(e){const t=this._getTextRanges(e);this._textSelectionRenderManager.removeAllTextRanges(),t&&Array.isArray(t.textRanges)&&t.textRanges.length&&this._textSelectionRenderManager.addTextRanges(t.textRanges.map($))}_replaceByParam(e){const{unitId:t,subUnitId:n,style:s,segmentId:r,textRanges:c,isEditing:l}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(n,{textRanges:c,style:s,segmentId:r,isEditing:l})}_addByParam(e){const{unitId:t,subUnitId:n,textRanges:s,style:r,segmentId:c,isEditing:l}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);const m=this._textSelectionInfo.get(t);m.has(n)?m.get(n).textRanges.push(...s):m.set(n,{textRanges:s,style:r,segmentId:c,isEditing:l})}},d.TextSelectionManagerService=ze([Ce(0,R.ITextSelectionRenderManager),Ce(1,a.ICommandService)],d.TextSelectionManagerService);function le(o,i="",e=0){const{startOffset:t,endOffset:n}=o,s=[],r=t-e,c=n-e;return r>0&&s.push({t:a.TextXActionType.RETAIN,len:r,segmentId:i}),s.push({t:a.TextXActionType.DELETE,len:c-r,line:0,segmentId:i}),s}var He=Object.defineProperty,Ge=Object.getOwnPropertyDescriptor,Ye=(o,i,e,t)=>{for(var n=t>1?void 0:t?Ge(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&He(i,e,n),n},We=(o,i)=>(e,t)=>i(e,t,o);d.DocViewModelManagerService=class extends a.RxDisposable{constructor(e){super();M(this,"_docViewModelMap",new Map);M(this,"_currentDocViewModel$",new P.BehaviorSubject(null));M(this,"currentDocViewModel$",this._currentDocViewModel$.asObservable());this._currentUniverService=e,this._initialize()}_initialize(){this._init()}dispose(){this._currentDocViewModel$.complete(),this._docViewModelMap.clear()}_init(){this._currentUniverService.currentDoc$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)}),this._currentUniverService.getAllUniverDocsInstance().forEach(e=>{this._create(e)}),this._currentUniverService.docDisposed$.pipe(P.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 n;const t=this._currentUniverService.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 s=this._buildDocViewModel(t);this._docViewModelMap.set(e,{unitId:e,docViewModel:s})}if(e===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY){const s=(n=this._docViewModelMap.get(e))==null?void 0:n.docViewModel;if(s==null)return;s.reset(t)}this._currentDocViewModel$.next(this._docViewModelMap.get(e))}}_buildDocViewModel(e){return new R.DocumentViewModel(e)}},d.DocViewModelManagerService=Ye([We(0,a.IUniverInstanceService)],d.DocViewModelManagerService);var Ze=Object.defineProperty,qe=Object.getOwnPropertyDescriptor,Ke=(o,i,e,t)=>{for(var n=t>1?void 0:t?qe(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&Ze(i,e,n),n},de=(o,i)=>(e,t)=>i(e,t,o);const Je=300;d.DocStateChangeManagerService=class extends a.RxDisposable{constructor(e,t,n){super();M(this,"_docStateChange$",new P.BehaviorSubject(null));M(this,"docStateChange$",this._docStateChange$.asObservable());M(this,"_stateCache",new Map);M(this,"_timer",null);this._undoRedoService=e,this._commandService=t,this._univerInstanceService=n,this._initialize()}setChangeState(e){const{trigger:t,noHistory:n}=e;t!=null&&(this._cacheChangeState(e),n||this._docStateChange$.next(e))}_initialize(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===a.UndoCommandId||e.id===a.RedoCommandId){const t=this._univerInstanceService.getCurrentUniverDocInstance();if(t==null)return;const n=t.getUnitId();this._pushHistory(n)}}))}_cacheChangeState(e){const{trigger:t,unitId:n,noHistory:s}=e;if(!(t===a.RedoCommandId||t===a.UndoCommandId||s)){if(this._stateCache.has(n)){const r=this._stateCache.get(n);r==null||r.push(e)}else this._stateCache.set(n,[e]);t===X.id||t===V.id?(this._timer&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._pushHistory(n)},Je)):this._pushHistory(n)}}_pushHistory(e){const t=this._undoRedoService,n=this._stateCache.get(e);if(!Array.isArray(n)||n.length===0)return;const s=n.length,r=n[0].commandId,c=n[0],l=n[s-1],m={unitId:e,actions:n.reduce((g,S)=>a.TextX.compose(g,S.redoState.actions),[]),textRanges:l.redoState.textRanges},u={unitId:e,actions:n.reverse().reduce((g,S)=>a.TextX.compose(g,S.undoState.actions),[]),textRanges:c.undoState.textRanges};t.pushUndoRedo({unitID:e,undoMutations:[{id:r,params:u}],redoMutations:[{id:r,params:m}]}),n.length=0}},d.DocStateChangeManagerService=Ke([de(0,U.Inject(a.IUndoRedoService)),de(1,a.ICommandService),de(2,a.IUniverInstanceService)],d.DocStateChangeManagerService);class F{constructor(){M(this,"_previousActiveRange",null);M(this,"_undoMutationParamsCache",[]);M(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache:i=[],redoCache:e=[]}){this._undoMutationParamsCache=i,this._redoMutationParamsCache=e}getActiveRange(){return this._previousActiveRange}setActiveRange(i){this._previousActiveRange=i}pushUndoRedoMutationParams(i,e){this._undoMutationParamsCache.push(i),this._redoMutationParamsCache.push(e)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:i}=this._undoMutationParamsCache[0],e={unitId:i,actions:this._undoMutationParamsCache.reverse().reduce((n,s)=>a.TextX.compose(n,s.actions),[]),textRanges:[]};return{redoMutationParams:{unitId:i,actions:this._redoMutationParamsCache.reduce((n,s)=>a.TextX.compose(n,s.actions),[]),textRanges:[]},undoMutationParams:e,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Me="doc.mutation.rich-text-editing",N={id:Me,type:a.CommandType.MUTATION,handler:(o,i)=>{var x;const{unitId:e,actions:t,textRanges:n,prevTextRanges:s,trigger:r,noHistory:c,isCompositionEnd:l,noNeedSetTextRange:m}=i,g=o.get(a.IUniverInstanceService).getUniverDocInstance(e),f=o.get(d.DocViewModelManagerService).getViewModel(e),_=o.get(d.TextSelectionManagerService),h=((x=_.getSelections())!=null?x:[]).map($),I=o.get(d.DocStateChangeManagerService),v=o.get(F);if(g==null||f==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);if(t.length===0)return{unitId:e,actions:[],textRanges:h};const T=g.apply(t),{segmentId:y}=t[0],O=g.getSelfOrHeaderFooterModel(y);f.getSelfOrHeaderFooterViewModel(y).reset(O),!m&&n&&r!=null&&queueMicrotask(()=>{_.replaceTextRanges(n)});const E={commandId:Me,unitId:e,trigger:r,noHistory:c,redoState:{actions:t,textRanges:n},undoState:{actions:T,textRanges:s!=null?s:h}};if(l){const D=v.fetchComposedUndoRedoMutationParams();if(D==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:C,redoMutationParams:L,previousActiveRange:b}=D;E.redoState.actions=L.actions,E.undoState.actions=C.actions,E.undoState.textRanges=[b]}return I.setChangeState(E),{unitId:e,actions:T,textRanges:h}}},X={id:"doc.command.insert-text",type:a.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(a.ICommandService),{range:t,segmentId:n,body:s,unitId:r,textRanges:c}=i,{startOffset:l,collapsed:m}=t,u={id:N.id,params:{unitId:r,actions:[],textRanges:c}},g=new a.TextX;return m?l>0&&g.push({t:a.TextXActionType.RETAIN,len:l,segmentId:n}):g.push(...le(t,n)),g.push({t:a.TextXActionType.INSERT,body:s,len:s.dataStream.length,line:0,segmentId:n}),u.params.actions=g.serialize(),!!e.syncExecuteCommand(u.id,u.params)}};var w=(o=>(o[o.LEFT=0]="LEFT",o[o.RIGHT=1]="RIGHT",o))(w||{});const V={id:"doc.command.delete-text",type:a.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(a.ICommandService),{range:t,segmentId:n,unitId:s,direction:r,textRanges:c,len:l=1}=i,{startOffset:m}=t,u={id:N.id,params:{unitId:s,actions:[],textRanges:c}},g=new a.TextX;return m>0&&g.push({t:a.TextXActionType.RETAIN,len:r===0?m-l:m,segmentId:n}),g.push({t:a.TextXActionType.DELETE,len:l,line:0,segmentId:n}),u.params.actions=g.serialize(),!!e.syncExecuteCommand(u.id,u.params)}},ue={id:"doc.command.update-text",type:a.CommandType.COMMAND,handler:async(o,i)=>{const{range:e,segmentId:t,updateBody:n,coverType:s,unitId:r,textRanges:c}=i,l=o.get(a.ICommandService),m={id:N.id,params:{unitId:r,actions:[],textRanges:c}},u=new a.TextX,{startOffset:g,endOffset:S}=e;return u.push({t:a.TextXActionType.RETAIN,len:g,segmentId:t}),u.push({t:a.TextXActionType.RETAIN,body:n,len:S-g,segmentId:t,coverType:s}),m.params.actions=u.serialize(),!!l.syncExecuteCommand(m.id,m.params)}};function Qe(o,i){const e=[];for(let t=0,n=o.length;t<n;t++)o[t]===a.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});if(i)for(const t of e)i.bullet&&(t.bullet=a.Tools.deepClone(i.bullet)),i.paragraphStyle&&(t.paragraphStyle=a.Tools.deepClone(i.paragraphStyle));return e}const Te={id:"doc.command.break-line",type:a.CommandType.COMMAND,handler:async o=>{var _,p;const i=o.get(d.TextSelectionManagerService),e=o.get(a.IUniverInstanceService),t=o.get(a.ICommandService),n=i.getActiveRange();if(n==null)return!1;const s=e.getCurrentUniverDocInstance(),r=s.getUnitId(),{startOffset:c,segmentId:l,style:m}=n,u=[{startOffset:c+1,endOffset:c+1,style:m}],S=((p=(_=s.getBody())==null?void 0:_.paragraphs)!=null?p:[]).find(h=>h.startIndex>=c);return await t.executeCommand(X.id,{unitId:r,body:{dataStream:a.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Qe(a.DataStreamTreeTokenType.PARAGRAPH,S)},range:n,textRanges:u,segmentId:l})}};var et=Object.defineProperty,tt=Object.getOwnPropertyDescriptor,nt=(o,i,e,t)=>{for(var n=t>1?void 0:t?tt(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&et(i,e,n),n},me=(o,i)=>(e,t)=>i(e,t,o);d.DocSkeletonManagerService=class extends a.RxDisposable{constructor(e,t,n){super();M(this,"_currentSkeletonUnitId","");M(this,"_docSkeletonMap",new Map);M(this,"_currentSkeleton$",new P.BehaviorSubject(null));M(this,"currentSkeleton$",this._currentSkeleton$.asObservable());M(this,"_currentSkeletonBefore$",new P.BehaviorSubject(null));M(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._localeService=e,this._docViewModelManagerService=t,this._currentUniverService=n,this._initialize()}_initialize(){this._init()}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._docSkeletonMap.clear()}_init(){this._docViewModelManagerService.currentDocViewModel$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._setCurrent(e)}),this._docViewModelManagerService.getAllModel().forEach(e=>{e!=null&&this._setCurrent(e)}),this._currentUniverService.docDisposed$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{this._docSkeletonMap.delete(e.getUnitId()),this._currentSkeletonUnitId=this._currentUniverService.getCurrentUniverDocInstance().getUnitId()})}getCurrent(){return this.getSkeletonByUnitId(this._currentSkeletonUnitId)}getAllSkeleton(){return this._docSkeletonMap}makeDirtyCurrent(e=!0){this.makeDirty(this._currentSkeletonUnitId,e)}makeDirty(e,t=!0){const n=this.getSkeletonByUnitId(e);n!=null&&(n.dirty=t)}getSkeletonByUnitId(e){return this._docSkeletonMap.get(e)}_setCurrent(e){const{unitId:t}=e;if(this._docSkeletonMap.has(t)){const n=this.getSkeletonByUnitId(t);n.skeleton.calculate(),n.dirty=!0}else{const n=this._buildSkeleton(e.docViewModel);n.calculate(),this._docSkeletonMap.set(t,{unitId:t,skeleton:n,dirty:!1})}return this._currentSkeletonUnitId=t,this._currentSkeletonBefore$.next(this.getCurrent()),this._currentSkeleton$.next(this.getCurrent()),this.getCurrent()}_buildSkeleton(e){return R.DocumentSkeleton.create(e,this._localeService)}},d.DocSkeletonManagerService=nt([me(0,U.Inject(a.LocaleService)),me(1,U.Inject(d.DocViewModelManagerService)),me(2,a.IUniverInstanceService)],d.DocSkeletonManagerService);const it={id:"doc.command.inner-paste",type:a.CommandType.COMMAND,handler:async(o,i)=>{const{segmentId:e,body:t,textRanges:n}=i,s=o.get(a.ICommandService),r=o.get(d.TextSelectionManagerService),c=o.get(a.IUniverInstanceService),l=r.getSelections();if(!Array.isArray(l)||l.length===0)return!1;const u=c.getCurrentUniverDocInstance().getUnitId(),g={id:N.id,params:{unitId:u,actions:[],textRanges:n}},S=new a.MemoryCursor;S.reset();const f=new a.TextX;for(const p of l){const{startOffset:h,endOffset:I,collapsed:v}=p,T=h-S.cursor;v?f.push({t:a.TextXActionType.RETAIN,len:T,segmentId:e}):f.push(...le(p,e,S.cursor)),f.push({t:a.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:e}),S.reset(),S.moveCursor(I)}return g.params.actions=f.serialize(),!!s.syncExecuteCommand(g.id,g.params)}},ge={id:"doc.command.inner-cut",type:a.CommandType.COMMAND,handler:async(o,i)=>{const{segmentId:e,textRanges:t}=i,n=o.get(a.ICommandService),s=o.get(d.TextSelectionManagerService),r=o.get(a.IUniverInstanceService),c=s.getSelections();if(!Array.isArray(c)||c.length===0)return!1;const l=r.getCurrentUniverDocInstance().getUnitId(),m=r.getUniverDocInstance(l),u=a.getDocsUpdateBody(m.snapshot,e);if(u==null)return!1;const g={id:N.id,params:{unitId:l,actions:[],textRanges:t}},S=new a.MemoryCursor;S.reset();const f=new a.TextX;for(const p of c){const{startOffset:h,endOffset:I,collapsed:v}=p,T=h-S.cursor;v?f.push({t:a.TextXActionType.RETAIN,len:T,segmentId:e}):f.push(...at(p,u,e,S.cursor)),S.reset(),S.moveCursor(I)}return g.params.actions=f.serialize(),!!n.syncExecuteCommand(g.id,g.params)}};function at(o,i,e="",t=0){const{startOffset:n,endOffset:s}=o,r=[],{paragraphs:c=[]}=i,l=n-t,m=s-t,u=c==null?void 0:c.find(g=>g.startIndex-t>=l&&g.startIndex-t<=m);if(l>0&&r.push({t:a.TextXActionType.RETAIN,len:l,segmentId:e}),u&&u.startIndex-t>l){const g=u.startIndex-t;r.push({t:a.TextXActionType.DELETE,len:g-l,line:0,segmentId:e}),r.push({t:a.TextXActionType.RETAIN,len:1,segmentId:e}),m>g+1&&r.push({t:a.TextXActionType.DELETE,len:m-g-1,line:0,segmentId:e})}else r.push({t:a.TextXActionType.DELETE,len:m-l,line:0,segmentId:e});return r}const ye={id:"doc.command.delete-left",type:a.CommandType.COMMAND,handler:async o=>{var y;const i=o.get(d.TextSelectionManagerService),e=o.get(d.DocSkeletonManagerService),t=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService),s=i.getActiveRange(),r=i.getSelections(),c=(y=e.getCurrent())==null?void 0:y.skeleton;let l=!0;if(s==null||c==null||r==null)return!1;const m=t.getCurrentUniverDocInstance(),{startOffset:u,collapsed:g,segmentId:S,style:f}=s,_=c.findNodeByCharIndex(u),p=R.hasListSpan(_),h=R.isIndentBySpan(_,m.getBody());let I=u;const v=c.findNodeByCharIndex(u-1);if(R.isFirstSpan(_)&&v!==_&&(p===!0||h===!0)){const O=R.getParagraphBySpan(_,m.getBody());if(O==null)return!1;const A=O==null?void 0:O.startIndex,E={startIndex:0},x=O.paragraphStyle;if(p===!0){const C=O.paragraphStyle;C&&(E.paragraphStyle=C)}else if(h===!0){const C=O.bullet;C&&(E.bullet=C),x!=null&&(E.paragraphStyle={...x},delete E.paragraphStyle.hanging,delete E.paragraphStyle.indentStart)}const D=[{startOffset:I,endOffset:I,style:f}];l=await n.executeCommand(ue.id,{unitId:m.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...E}]},range:{startOffset:A,endOffset:A+1},textRanges:D,coverType:a.UpdateDocsAttributeType.REPLACE,segmentId:S})}else if(g===!0){if(v==null)return!0;if(v.content==="\r")l=await n.executeCommand(Se.id,{direction:w.LEFT,range:s});else{I-=v.count;const O=[{startOffset:I,endOffset:I,style:f}];l=await n.executeCommand(V.id,{unitId:m.getUnitId(),range:s,segmentId:S,direction:w.LEFT,len:v.count,textRanges:O})}}else{const O=Re(s,r);l=await n.executeCommand(ge.id,{segmentId:S,textRanges:O})}return l}},Oe={id:"doc.command.delete-right",type:a.CommandType.COMMAND,handler:async o=>{var _;const i=o.get(d.TextSelectionManagerService),e=o.get(d.DocSkeletonManagerService),t=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService),s=i.getActiveRange(),r=i.getSelections(),c=(_=e.getCurrent())==null?void 0:_.skeleton;let l;if(s==null||c==null||r==null)return!1;const m=t.getCurrentUniverDocInstance(),{startOffset:u,collapsed:g,segmentId:S,style:f}=s;if(u===m.getBody().dataStream.length-2&&g)return!0;if(g===!0){const p=c.findNodeByCharIndex(u);if(p.content==="\r")l=await n.executeCommand(Se.id,{direction:w.RIGHT,range:s});else{const h=[{startOffset:u,endOffset:u,style:f}];l=await n.executeCommand(V.id,{unitId:m.getUnitId(),range:s,segmentId:S,direction:w.RIGHT,textRanges:h,len:p.count})}}else{const p=Re(s,r);l=await n.executeCommand(ge.id,{segmentId:S,textRanges:p})}return l}},Se={id:"doc.command.merge-two-paragraph",type:a.CommandType.COMMAND,handler:async(o,i)=>{var E,x,D;const e=o.get(d.TextSelectionManagerService),t=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService);o.get(a.IUndoRedoService);const{direction:s,range:r}=i,c=e.getActiveRange(),l=e.getSelections();if(c==null||l==null)return!1;const m=t.getCurrentUniverDocInstance(),{startOffset:u,collapsed:g,segmentId:S,style:f}=c;if(!g)return!1;const _=s===w.LEFT?u:u+1,p=(D=(x=(E=m.getBody())==null?void 0:E.paragraphs)==null?void 0:x.find(C=>C.startIndex>=_))==null?void 0:D.startIndex,h=st(m.getBody(),_,p),I=s===w.LEFT?u-1:u,v=m.getUnitId(),T=[{startOffset:I,endOffset:I,style:f}],y={id:N.id,params:{unitId:v,actions:[],textRanges:T,prevTextRanges:[r]}},O=new a.TextX;return O.push({t:a.TextXActionType.RETAIN,len:s===w.LEFT?u-1:u,segmentId:S}),h.dataStream.length&&O.push({t:a.TextXActionType.INSERT,body:h,len:h.dataStream.length,line:0,segmentId:S}),O.push({t:a.TextXActionType.RETAIN,len:1,segmentId:S}),O.push({t:a.TextXActionType.DELETE,len:p+1-_,line:0,segmentId:S}),y.params.actions=O.serialize(),!!n.syncExecuteCommand(y.id,y.params)}};function st(o,i,e){const{textRuns:t}=o,n=o.dataStream.substring(i,e);if(t==null)return{dataStream:n};const s=[];for(const r of t){const{st:c,ed:l}=r;l<=i||c>=e||(c<i?s.push({...r,st:0,ed:l-i}):l>e?s.push({...r,st:c-i,ed:e-i}):s.push({...r,st:c-i,ed:l-i}))}return{dataStream:n,textRuns:s}}function Re(o,i){let e=o.endOffset;for(const n of i){const{startOffset:s,endOffset:r}=n;s==null||r==null||r<=o.endOffset&&(e-=r-s)}return[{startOffset:e,endOffset:e,style:o.style}]}const fe={id:"doc.command.ime-input",type:a.CommandType.COMMAND,handler:async(o,i)=>{const{unitId:e,newText:t,oldTextLen:n,isCompositionEnd:s,isCompositionStart:r}=i,c=o.get(a.ICommandService),l=o.get(F),m=l.getActiveRange();if(m==null)return!1;const{startOffset:u,style:g,segmentId:S}=m,f=t.length,_=[{startOffset:u+f,endOffset:u+f,collapsed:!0,style:g}],p={id:N.id,params:{unitId:e,actions:[],textRanges:_}},h=new a.TextX;!m.collapsed&&r?h.push(...le(m,S)):h.push({t:a.TextXActionType.RETAIN,len:u,segmentId:S}),n>0&&h.push({t:a.TextXActionType.DELETE,len:n,line:0,segmentId:S}),h.push({t:a.TextXActionType.INSERT,body:{dataStream:t},len:t.length,line:0,segmentId:S}),p.params.actions=h.serialize(),p.params.noHistory=!s,p.params.isCompositionEnd=s;const I=c.syncExecuteCommand(p.id,p.params);return l.pushUndoRedoMutationParams(I,p.params),!!I}},k={id:"doc.command.set-inline-format-bold",type:a.CommandType.COMMAND,handler:async()=>!0},j={id:"doc.command.set-inline-format-italic",type:a.CommandType.COMMAND,handler:async()=>!0},z={id:"doc.command.set-inline-format-underline",type:a.CommandType.COMMAND,handler:async()=>!0},H={id:"doc.command.set-inline-format-strikethrough",type:a.CommandType.COMMAND,handler:async()=>!0},B={id:"doc.command.set-inline-format-subscript",type:a.CommandType.COMMAND,handler:async()=>!0},G={id:"doc.command.set-inline-format-superscript",type:a.CommandType.COMMAND,handler:async()=>!0},Y={id:"doc.command.set-inline-format-fontsize",type:a.CommandType.COMMAND,handler:async()=>!0},W={id:"doc.command.set-inline-format-font-family",type:a.CommandType.COMMAND,handler:async()=>!0},Z={id:"doc.command.set-inline-format-text-color",type:a.CommandType.COMMAND,handler:async()=>!0},xe={[k.id]:"bl",[j.id]:"it",[z.id]:"ul",[H.id]:"st",[Y.id]:"fs",[W.id]:"ff",[Z.id]:"cl",[B.id]:"va",[G.id]:"va"},he={id:"doc.command.set-inline-format",type:a.CommandType.COMMAND,handler:async(o,i)=>{const{segmentId:e,value:t,preCommandId:n}=i,s=o.get(a.ICommandService),r=o.get(d.TextSelectionManagerService),c=o.get(a.IUniverInstanceService),l=r.getSelections();if(!Array.isArray(l)||l.length===0)return!1;let m=c.getCurrentUniverDocInstance(),u=m.getUnitId();u===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(m=c.getUniverDocInstance(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),u=m.getUnitId());let g;switch(n){case k.id:case j.id:case z.id:case H.id:case B.id:case G.id:{g=rt(m.getBody().textRuns,n,l);break}case Y.id:case W.id:{g=t;break}case Z.id:{g={rgb:t};break}default:throw new Error(`Unknown command: ${n} in handleInlineFormat`)}const S={id:N.id,params:{unitId:u,actions:[],textRanges:l.map($)}},f=new a.TextX,_=new a.MemoryCursor;_.reset();for(const h of l){const{startOffset:I,endOffset:v}=h,T={dataStream:"",textRuns:[{st:0,ed:v-I,ts:{[xe[n]]:g}}]},y=I-_.cursor;y!==0&&f.push({t:a.TextXActionType.RETAIN,len:y,segmentId:e}),f.push({t:a.TextXActionType.RETAIN,body:T,len:v-I,segmentId:e}),_.reset(),_.moveCursor(v)}return S.params.actions=f.serialize(),!!s.syncExecuteCommand(S.id,S.params)}};function ot(o){return o!==null&&typeof o=="object"}function rt(o,i,e){let t=0,n=0;const s=xe[i];for(;t!==o.length&&n!==e.length;){const{startOffset:r,endOffset:c}=e[n],{st:l,ed:m,ts:u}=o[t];if(c<=l)n++;else if(m<=r)t++;else{if(/bl|it/.test(s))return(u==null?void 0:u[s])===a.BooleanNumber.TRUE?a.BooleanNumber.FALSE:a.BooleanNumber.TRUE;if(/ul|st/.test(s))return ot(u==null?void 0:u[s])&&(u==null?void 0:u[s]).s===a.BooleanNumber.TRUE?{s:a.BooleanNumber.FALSE}:{s:a.BooleanNumber.TRUE};if(/va/.test(s))return i===B.id?(u==null?void 0:u[s])===a.BaselineOffset.SUBSCRIPT?a.BaselineOffset.NORMAL:a.BaselineOffset.SUBSCRIPT:(u==null?void 0:u[s])===a.BaselineOffset.SUPERSCRIPT?a.BaselineOffset.NORMAL:a.BaselineOffset.SUPERSCRIPT;t++}}return/bl|it/.test(s)?a.BooleanNumber.TRUE:/ul|st/.test(s)?{s:a.BooleanNumber.TRUE}:i===B.id?a.BaselineOffset.SUBSCRIPT:a.BaselineOffset.SUPERSCRIPT}const pe={id:"doc.command.list-operation",type:a.CommandType.COMMAND,handler:(o,i)=>{var O,A,E;const e=o.get(d.TextSelectionManagerService),t=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService),{listType:s}=i,r=t.getCurrentUniverDocInstance(),c=e.getActiveRange(),l=(O=e.getSelections())!=null?O:[],m=(A=r.getBody())==null?void 0:A.paragraphs,u=l.map($);if(c==null||m==null)return!1;const g=ct(c,m),{segmentId:S}=c,f=r.getUnitId(),_=g.every(x=>{var D;return((D=x.bullet)==null?void 0:D.listType)===s});let h=a.Tools.generateRandomId(6);if(g.length===1){const x=m.indexOf(g[0]),D=m[x-1],C=m[x+1];D&&D.bullet&&D.bullet.listType===s?h=D.bullet.listId:C&&C.bullet&&C.bullet.listType===s&&(h=C.bullet.listId)}const I={id:N.id,params:{unitId:f,actions:[],textRanges:u}},v=new a.MemoryCursor;v.reset();const T=new a.TextX;for(const x of g){const{startIndex:D}=x;T.push({t:a.TextXActionType.RETAIN,len:D-v.cursor,segmentId:S});const C={...x.paragraphStyle,hanging:void 0,indentStart:void 0};T.push({t:a.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[_?{paragraphStyle:C,startIndex:0}:{...x,startIndex:0,bullet:{...(E=x.bullet)!=null?E:{nestingLevel:0,textStyle:{fs:20}},listType:s,listId:h}}]},segmentId:S,coverType:a.UpdateDocsAttributeType.REPLACE}),v.moveCursorTo(D+1)}return I.params.actions=T.serialize(),!!n.syncExecuteCommand(I.id,I.params)}},De={id:"doc.command.bullet-list",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(pe.id,{listType:a.PresetListType.BULLET_LIST})},Ee={id:"doc.command.order-list",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(pe.id,{listType:a.PresetListType.ORDER_LIST})};function ct(o,i){const{startOffset:e,endOffset:t}=o,n=[];let s=-1;for(const r of i){const{startIndex:c}=r;(e>s&&e<=c||t>s&&t<=c||c>=e&&c<=t)&&n.push(r),s=c}return n}const Ae={id:"doc.command-replace-content",type:a.CommandType.COMMAND,handler:async(o,i)=>{var f;const{unitId:e,body:t,textRanges:n,segmentId:s=""}=i,r=o.get(a.IUniverInstanceService),c=o.get(a.ICommandService),l=o.get(d.TextSelectionManagerService),m=(f=r.getUniverDocInstance(e))==null?void 0:f.getSnapshot().body,u=l.getSelections();if(m==null||!Array.isArray(u)||u.length===0)return!1;const g=Ne(e,s,m,t);return g.params.textRanges=n,!!c.syncExecuteCommand(g.id,g.params)}},Ue={id:"doc.command-cover-content",type:a.CommandType.COMMAND,handler:async(o,i)=>{var u;const{unitId:e,body:t,segmentId:n=""}=i,s=o.get(a.IUniverInstanceService),r=o.get(a.ICommandService),c=o.get(a.IUndoRedoService),l=(u=s.getUniverDocInstance(e))==null?void 0:u.getSnapshot().body;if(l==null)return!1;const m=Ne(e,n,l,t);return m.params.noNeedSetTextRange=!0,m.params.noHistory=!0,r.syncExecuteCommand(m.id,m.params),c.clearUndoRedo(e),!0}};function Ne(o,i,e,t){const n={id:N.id,params:{unitId:o,actions:[],textRanges:[]}},s=new a.TextX,r=(e==null?void 0:e.dataStream.length)-2;return r>0&&s.push({t:a.TextXActionType.DELETE,len:r,line:0,segmentId:i}),t.dataStream.length>0&&s.push({t:a.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:i}),n.params.actions=s.serialize(),n}const ee={id:"doc.operation.move-cursor",type:a.CommandType.OPERATION,handler:(o,i)=>!!i},te={id:"doc.operation.move-selection",type:a.CommandType.OPERATION,handler:(o,i)=>!!i},lt=(o,i)=>{const e=o.get(a.IUniverInstanceService).getUniverDocInstance(i.unitId),t=(e==null?void 0:e.zoomRatio)||1;return{...a.Tools.deepClone(i),zoomRatio:t}},q={id:"doc.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(o,i)=>{const e=o.get(a.IUniverInstanceService).getUniverDocInstance(i.unitId);if(!e)return!1;const t=e.getSnapshot();return t.settings==null?t.settings={zoomRatio:i.zoomRatio}:t.settings.zoomRatio=i.zoomRatio,!0}},Pe={type:a.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(o,i)=>{var g,S;const e=o.get(a.ICommandService),t=o.get(a.IUndoRedoService),n=o.get(a.IUniverInstanceService);let s=n.getCurrentUniverDocInstance().getUnitId(),r=1;if(i&&(s=(g=i.documentId)!=null?g:s,r=(S=i.zoomRatio)!=null?S:r),!n.getUniverDocInstance(s))return!1;const l={zoomRatio:r,unitId:s},m=lt(o,l);return e.syncExecuteCommand(q.id,l)?(t.pushUndoRedo({unitID:s,undoMutations:[{id:q.id,params:m}],redoMutations:[{id:q.id,params:l}]}),!0):!1}},be={id:"doc.operation.select-all",type:a.CommandType.COMMAND,handler:async o=>{const i=o.get(a.IUniverInstanceService),e=o.get(d.TextSelectionManagerService),t=i.getCurrentUniverDocInstance().getSnapshot().body;if(t==null)return!1;const n=[{startOffset:0,endOffset:t.dataStream.length-2}];return e.replaceTextRanges(n,!1),!0}};var dt=Object.defineProperty,ut=Object.getOwnPropertyDescriptor,mt=(o,i,e,t)=>{for(var n=t>1?void 0:t?ut(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&dt(i,e,n),n},K=(o,i)=>(e,t)=>i(e,t,o);let ne=class extends a.Disposable{constructor(i,e,t,n,s){super();M(this,"_previousIMEContent","");M(this,"_isCompositionStart",!0);M(this,"_onStartSubscription");M(this,"_onUpdateSubscription");M(this,"_onEndSubscription");this._docSkeletonManagerService=i,this._currentUniverService=e,this._textSelectionRenderManager=t,this._imeInputManagerService=n,this._commandService=s,this._initialize()}dispose(){var i,e,t;(i=this._onStartSubscription)==null||i.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(i=>{if(i==null)return;this._resetIME();const{activeRange:e}=i;e!=null&&this._imeInputManagerService.setActiveRange(a.Tools.deepClone(e))})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._textSelectionRenderManager.onCompositionupdate$.subscribe(async i=>{this._updateContent(i,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._textSelectionRenderManager.onCompositionend$.subscribe(i=>{this._updateContent(i,!1)})}async _updateContent(i,e){var m;const t=(m=this._docSkeletonManagerService.getCurrent())==null?void 0:m.skeleton;if(i==null||t==null)return;const n=this._currentUniverService.getCurrentUniverDocInstance(),{event:s,activeRange:r}=i;if(t==null||r==null)return;const l=s.data;l===this._previousIMEContent&&e||(await this._commandService.executeCommand(fe.id,{unitId:n.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)}};ne=mt([a.OnLifecycle(a.LifecycleStages.Rendered,ne),K(0,U.Inject(d.DocSkeletonManagerService)),K(1,a.IUniverInstanceService),K(2,R.ITextSelectionRenderManager),K(3,U.Inject(F)),K(4,a.ICommandService)],ne);var gt=Object.defineProperty,St=Object.getOwnPropertyDescriptor,ft=(o,i,e,t)=>{for(var n=t>1?void 0:t?St(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&gt(i,e,n),n},we=(o,i)=>(e,t)=>i(e,t,o);let ie=class extends a.Disposable{constructor(o,i){super(),this._textSelectionManagerService=o,this._commandService=i,this._commandExecutedListener()}_commandExecutedListener(){const o=[k.id,j.id,z.id,H.id,B.id,G.id,Y.id,W.id,Z.id];this.disposeWithMe(this._commandService.onCommandExecuted(i=>{o.includes(i.id)&&this._handleInlineFormat(i)}))}_handleInlineFormat(o){var e,t;const{segmentId:i}=(e=this._textSelectionManagerService.getActiveRange())!=null?e:{};i!=null&&this._commandService.executeCommand(he.id,{segmentId:i,preCommandId:o.id,...(t=o.params)!=null?t:{}})}};ie=ft([a.OnLifecycle(a.LifecycleStages.Rendered,ie),we(0,U.Inject(d.TextSelectionManagerService)),we(1,a.ICommandService)],ie);var ht=Object.defineProperty,pt=Object.getOwnPropertyDescriptor,vt=(o,i,e,t)=>{for(var n=t>1?void 0:t?pt(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&ht(i,e,n),n},J=(o,i)=>(e,t)=>i(e,t,o);let ae=class extends a.Disposable{constructor(i,e,t,n,s){super();M(this,"_onInputSubscription");this._docSkeletonManagerService=i,this._currentUniverService=e,this._renderManagerService=t,this._textSelectionManagerService=n,this._commandService=s,this._initialize(),this._commandExecutedListener()}dispose(){var i;(i=this._onInputSubscription)==null||i.unsubscribe()}_initialize(){}_commandExecutedListener(){const i=[ee.id,te.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!i.includes(e.id))return;const t=e.params;switch(e.id){case ee.id:return this._handleMoveCursor(t.direction);case te.id:return this._handleShiftMoveSelection(t.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(i){var p,h,I;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),n=this._currentUniverService.getCurrentUniverDocInstance(),s=(p=this._docSkeletonManagerService.getCurrent())==null?void 0:p.skeleton,r=this._getDocObject();if(e==null||s==null||r==null)return;const{startOffset:c,endOffset:l,style:m,collapsed:u,direction:g}=e;if(t.length>1){let v=Number.POSITIVE_INFINITY,T=Number.NEGATIVE_INFINITY;for(const y of t)v=Math.min(v,y.startOffset),T=Math.max(T,y.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:i===a.Direction.LEFT||i===a.Direction.UP?T:v,endOffset:i===a.Direction.LEFT||i===a.Direction.UP?v:T,style:m}],!1);return}const S=u||g===R.RANGE_DIRECTION.FORWARD?c:l;let f=u||g===R.RANGE_DIRECTION.FORWARD?l:c;const _=(h=n.getBody().dataStream.length)!=null?h:Number.POSITIVE_INFINITY;if(i===a.Direction.LEFT||i===a.Direction.RIGHT){const v=s.findNodeByCharIndex(f-1),T=s.findNodeByCharIndex(f);f=i===a.Direction.RIGHT?f+T.count:f-((I=v==null?void 0:v.count)!=null?I:0),f=Math.min(_-2,Math.max(0,f)),this._textSelectionManagerService.replaceTextRanges([{startOffset:S,endOffset:f,style:m}],!1)}else{const v=s.findNodeByCharIndex(f),T=r.document.getOffsetConfig(),y=this._getTopOrBottomPosition(s,v,i===a.Direction.DOWN);if(y==null){const A=i===a.Direction.UP?0:_-2;if(A===f)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:S,endOffset:A,style:m}],!1);return}const O=new R.NodePositionConvertToCursor(T,s).getRangePointData(y,y).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:S,endOffset:O.endOffset,style:m}],!1)}}_handleMoveCursor(i){var S,f,_;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),n=this._currentUniverService.getCurrentUniverDocInstance(),s=(S=this._docSkeletonManagerService.getCurrent())==null?void 0:S.skeleton,r=this._getDocObject();if(e==null||s==null||r==null||t==null)return;const{startOffset:c,endOffset:l,style:m,collapsed:u}=e,g=(f=n.getBody().dataStream.length)!=null?f:Number.POSITIVE_INFINITY;if(i===a.Direction.LEFT||i===a.Direction.RIGHT){let p;if(!e.collapsed||t.length>1){let h=Number.POSITIVE_INFINITY,I=Number.NEGATIVE_INFINITY;for(const v of t)h=Math.min(h,v.startOffset),I=Math.max(I,v.endOffset);p=i===a.Direction.LEFT?h:I}else{const h=s.findNodeByCharIndex(c-1),I=s.findNodeByCharIndex(c);i===a.Direction.LEFT?p=Math.max(0,c-((_=h==null?void 0:h.count)!=null?_:0)):p=Math.min(g-2,l+I.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:p,style:m}],!1)}else{const p=s.findNodeByCharIndex(c),h=s.findNodeByCharIndex(l),I=r.document.getOffsetConfig(),v=this._getTopOrBottomPosition(s,i===a.Direction.UP?p:h,i===a.Direction.DOWN);if(v==null){let y;u?y=i===a.Direction.UP?0:g-2:y=i===a.Direction.UP?c:l,this._textSelectionManagerService.replaceTextRanges([{startOffset:y,endOffset:y,style:m}],!1);return}const T=new R.NodePositionConvertToCursor(I,s).getRangePointData(v,v).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...T,style:m}],!1)}}_getTopOrBottomPosition(i,e,t){if(e==null)return;const n=this._getSpanLeftOffsetInLine(e),s=this._getNextOrPrevLine(e,t);if(s==null)return;const r=this._matchPositionByLeftOffset(i,s,n);if(r!=null)return{...r,isBack:!0}}_getSpanLeftOffsetInLine(i){const e=i.parent;if(e==null)return Number.NEGATIVE_INFINITY;const t=e.left,{left:n}=i;return t+n}_matchPositionByLeftOffset(i,e,t){const n={distance:Number.POSITIVE_INFINITY};for(const s of e.divides){const r=s.left;for(const c of s.spanGroup){const{left:l}=c,m=r+l,u=Math.abs(t-m);u<n.distance&&(n.span=c,n.distance=u)}}if(n.span!=null)return i.findPositionBySpan(n.span)}_getNextOrPrevLine(i,e){var _,p,h,I,v,T,y,O,A,E,x,D;const t=i.parent;if(t==null)return;const n=t.parent;if(n==null)return;const s=n.parent;if(s==null)return;const r=s.lines.indexOf(n);if(r===-1)return;let c;if(e===!0?c=s.lines[r+1]:c=s.lines[r-1],c!=null)return c;const l=s.parent;if(l==null)return;const m=l.columns.indexOf(s);if(m===-1)return;if(e===!0)c=(_=l.columns[m+1])==null?void 0:_.lines[0];else{const C=(h=(p=l.columns)==null?void 0:p[m-1])==null?void 0:h.lines;c=C==null?void 0:C[C.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=(v=(I=u.sections[g-1])==null?void 0:I.columns[0])==null?void 0:v.lines[0];else{const C=(y=(T=u.sections)==null?void 0:T[g-1])==null?void 0:y.columns,L=C==null?void 0:C[C.length-1],b=L==null?void 0:L.lines;c=b==null?void 0:b[b.length-1]}if(c!=null)return c;const S=u.parent;if(S==null)return;const f=S.pages.indexOf(u);if(f!==-1){if(e===!0)c=(E=(A=(O=S.pages[f+1])==null?void 0:O.sections[0])==null?void 0:A.columns[0])==null?void 0:E.lines[0];else{const C=(x=S.pages[f-1])==null?void 0:x.sections;if(C==null)return;const L=(D=C[C.length-1])==null?void 0:D.columns,b=L[L.length-1],Le=b==null?void 0:b.lines;c=Le[Le.length-1]}if(c!=null)return c}}_getDocObject(){return re(this._currentUniverService,this._renderManagerService)}};ae=vt([a.OnLifecycle(a.LifecycleStages.Rendered,ae),J(0,U.Inject(d.DocSkeletonManagerService)),J(1,a.IUniverInstanceService),J(2,R.IRenderManagerService),J(3,U.Inject(d.TextSelectionManagerService)),J(4,a.ICommandService)],ae);var _t=Object.defineProperty,It=Object.getOwnPropertyDescriptor,Ct=(o,i,e,t)=>{for(var n=t>1?void 0:t?It(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&_t(i,e,n),n},Q=(o,i)=>(e,t)=>i(e,t,o);let se=class extends a.Disposable{constructor(i,e,t,n,s){super();M(this,"_onInputSubscription");this._docSkeletonManagerService=i,this._currentUniverService=e,this._renderManagerService=t,this._textSelectionRenderManager=n,this._commandService=s,this._initialize(),this._commandExecutedListener()}dispose(){var i;(i=this._onInputSubscription)==null||i.unsubscribe()}_initialize(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async i=>{var _;if(i==null)return;const t=this._currentUniverService.getCurrentUniverDocInstance().getUnitId(),{event:n,content:s="",activeRange:r}=i,c=n,l=(_=this._docSkeletonManagerService.getCurrent())==null?void 0:_.skeleton;if(c.data==null||l==null||!l||!r)return;const{startOffset:m,segmentId:u,style:g}=r,S=s.length,f=[{startOffset:m+S,endOffset:m+S,style:g}];await this._commandService.executeCommand(X.id,{unitId:t,body:{dataStream:s},range:r,textRanges:f,segmentId:u})})}_commandExecutedListener(){}_getDocObject(){return re(this._currentUniverService,this._renderManagerService)}};se=Ct([a.OnLifecycle(a.LifecycleStages.Rendered,se),Q(0,U.Inject(d.DocSkeletonManagerService)),Q(1,a.IUniverInstanceService),Q(2,R.IRenderManagerService),Q(3,R.ITextSelectionRenderManager),Q(4,a.ICommandService)],se);var Mt=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,yt=(o,i,e,t)=>{for(var n=t>1?void 0:t?Tt(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(n=(t?r(i,e,n):r(n))||n);return t&&n&&Mt(i,e,n),n},oe=(o,i)=>(e,t)=>i(e,t,o);const Ot={hasScroll:!0},Rt="docs";d.UniverDocsPlugin=(ve=class extends a.Plugin{constructor(e={},t,n,s,r){super(Rt);M(this,"_config");this._injector=t,this._localeService=n,this._configService=s,this._currentUniverService=r,this._config=Object.assign(Ot,e),this._initializeDependencies(t),this._initializeCommands()}initialize(){}_initializeCommands(){[ee,te,ye,Oe,k,j,z,H,B,G,Y,W,Z,he,Te,X,V,ue,fe,Se,N,Ae,Ue,Pe,q,ce,be,Ee,De,pe].forEach(e=>{this._injector.get(a.ICommandService).registerCommand(e)})}onReady(){this.initialize()}_initializeDependencies(e){[[d.DocSkeletonManagerService],[d.DocViewModelManagerService],[d.DocStateChangeManagerService],[F],[R.ITextSelectionRenderManager,{useClass:R.TextSelectionRenderManager}],[d.TextSelectionManagerService],[se],[ne],[ie],[ae]].forEach(t=>e.add(t))}},M(ve,"type",a.PluginType.Doc),ve),d.UniverDocsPlugin=yt([oe(1,U.Inject(U.Injector)),oe(2,U.Inject(a.LocaleService)),oe(3,a.IConfigService),oe(4,a.IUniverInstanceService)],d.UniverDocsPlugin),d.BreakLineCommand=Te,d.BulletListCommand=De,d.CoverContentCommand=Ue,d.CutContentCommand=ge,d.DOCS_COMPONENT_DEFAULT_Z_INDEX=Xe,d.DOCS_COMPONENT_HEADER_LAYER_INDEX=Fe,d.DOCS_COMPONENT_MAIN_LAYER_INDEX=$e,d.DOCS_VIEW_KEY=_e,d.DeleteCommand=V,d.DeleteLeftCommand=ye,d.DeleteRightCommand=Oe,d.IMEInputCommand=fe,d.IMEInputManagerService=F,d.InnerPasteCommand=it,d.InsertCommand=X,d.MoveCursorOperation=ee,d.MoveSelectionOperation=te,d.NORMAL_TEXT_SELECTION_PLUGIN_NAME=Ve,d.OrderListCommand=Ee,d.ReplaceContentCommand=Ae,d.RichTextEditingMutation=N,d.SelectAllOperation=be,d.SetDocZoomRatioCommand=Pe,d.SetDocZoomRatioOperation=q,d.SetInlineFormatBoldCommand=k,d.SetInlineFormatCommand=he,d.SetInlineFormatFontFamilyCommand=W,d.SetInlineFormatFontSizeCommand=Y,d.SetInlineFormatItalicCommand=j,d.SetInlineFormatStrikethroughCommand=H,d.SetInlineFormatSubscriptCommand=B,d.SetInlineFormatSuperscriptCommand=G,d.SetInlineFormatTextColorCommand=Z,d.SetInlineFormatUnderlineCommand=z,d.SetTextSelectionsOperation=ce,d.UpdateCommand=ue,d.VIEWPORT_KEY=Ie,d.getDocObject=re,d.getDocObjectById=Be,d.serializeTextRange=$,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/docs",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "private": false,
5
5
  "description": "UniverSheet normal base-docs",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -48,22 +48,22 @@
48
48
  "npm": ">=8.0.0"
49
49
  },
50
50
  "peerDependencies": {
51
- "@wendellhu/redi": "^0.13.0",
51
+ "@wendellhu/redi": "0.13.0",
52
52
  "rxjs": ">=7.0.0",
53
- "@univerjs/core": "0.1.2",
54
- "@univerjs/engine-render": "0.1.2"
53
+ "@univerjs/core": "0.1.3",
54
+ "@univerjs/engine-render": "0.1.3"
55
55
  },
56
56
  "dependencies": {},
57
57
  "devDependencies": {
58
58
  "@wendellhu/redi": "^0.13.0",
59
59
  "less": "^4.2.0",
60
60
  "rxjs": "^7.8.1",
61
- "typescript": "^5.3.3",
62
- "vite": "^5.1.4",
61
+ "typescript": "^5.4.2",
62
+ "vite": "^5.1.6",
63
63
  "vitest": "^1.3.1",
64
- "@univerjs/engine-render": "0.1.2",
65
- "@univerjs/core": "0.1.2",
66
- "@univerjs/shared": "0.1.2"
64
+ "@univerjs/shared": "0.1.3",
65
+ "@univerjs/core": "0.1.3",
66
+ "@univerjs/engine-render": "0.1.3"
67
67
  },
68
68
  "scripts": {
69
69
  "test": "vitest run",