@univerjs/docs 0.1.10 → 0.1.11

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