@univerjs/docs 0.1.0-beta.5 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +1000 -1357
- package/lib/types/commands/operations/text-selection.operation.d.ts +3 -2
- package/lib/types/controllers/text-selection.controller.d.ts +2 -6
- package/lib/types/index.d.ts +3 -2
- package/lib/types/services/doc-skeleton-manager.service.d.ts +5 -2
- package/lib/types/services/doc-view-model-manager.service.d.ts +3 -2
- package/lib/types/services/text-selection-manager.service.d.ts +2 -2
- package/lib/umd/index.js +1 -1
- package/package.json +6 -6
- package/lib/types/controllers/doc-render.controller.d.ts +0 -27
- package/lib/types/controllers/floating-object.controller.d.ts +0 -33
- package/lib/types/controllers/page-render.controller.d.ts +0 -25
- package/lib/types/controllers/zoom.controller.d.ts +0 -36
- package/lib/types/views/doc-canvas-view.d.ts +0 -34
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var qe=Object.defineProperty;var Ze=(s,r,e)=>r in s?qe(s,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[r]=e;var I=(s,r,e)=>(Ze(s,typeof r!="symbol"?r+"":r,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),C=require("@univerjs/engine-render"),N=require("rxjs"),b=require("@wendellhu/redi");function pe(s,r){const t=s.getCurrentUniverDocInstance().getUnitId(),n=r.getRenderById(t);if(n==null)return;const{mainComponent:i,scene:a,engine:c}=n;return{document:i,scene:a,engine:c}}function Je(s,r){const e=r.getRenderById(s);if(e==null)return;const{mainComponent:t,scene:n,engine:i}=e;return{document:t,scene:n,engine:i}}var ge=(s=>(s.MAIN="__Document_Render_Main__",s))(ge||{}),_e=(s=>(s.VIEW_MAIN="viewMain",s.VIEW_TOP="viewTop",s.VIEW_LEFT="viewLeft",s.VIEW_LEFT_TOP="viewLeftTop",s))(_e||{});const Me=0,Le=2,Be=10,Qe="normalTextSelectionPluginName",Ce={id:"doc.operation.set-selections",type:o.CommandType.OPERATION,handler:(s,r)=>!0};var et=Object.defineProperty,tt=Object.getOwnPropertyDescriptor,nt=(s,r,e,t)=>{for(var n=t>1?void 0:t?tt(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&et(r,e,n),n},Ue=(s,r)=>(e,t)=>r(e,t,s);function z(s){const{startOffset:r,endOffset:e,collapsed:t}=s;return{startOffset:r,endOffset:e,collapsed:t}}exports.TextSelectionManagerService=class extends o.RxDisposable{constructor(e,t){super();I(this,"_currentSelection",null);I(this,"_textSelectionInfo",new Map);I(this,"_textSelection$",new N.BehaviorSubject(null));I(this,"textSelection$",this._textSelection$.asObservable());this._textSelectionRenderManager=e,this._commandService=t,this._syncSelectionFromRenderService()}getCurrentSelection(){return this._currentSelection}getCurrentSelectionInfo(){return this._getTextRanges(this._currentSelection)}dispose(){this._textSelection$.complete()}refreshSelection(){this._currentSelection!=null&&this._refresh(this._currentSelection)}setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}setCurrentSelectionNotRefresh(e){this._currentSelection=e}getSelections(){var e;return(e=this._getTextRanges(this._currentSelection))==null?void 0:e.textRanges}getActiveRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:t,segmentId:n,style:i}=e,a=t.find(h=>h.isActive());if(a==null)return null;const{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:m,direction:g}=a;return c==null||l==null?null:{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:m,direction:g,segmentId:n,style:i}}add(e){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,segmentId:"",style:C.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e){this._currentSelection!=null&&(this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges(e))}_syncSelectionFromRenderService(){this._textSelectionRenderManager.textSelectionInner$.pipe(N.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._replaceTextRangesWithNoRefresh(e)})}_replaceTextRangesWithNoRefresh(e){if(this._currentSelection==null)return;const t={...this._currentSelection,...e};this._replaceByParam(t),this._textSelection$.next(t);const{unitId:n,subUnitId:i,segmentId:a,style:c,textRanges:l}=t;this._commandService.executeCommand(Ce.id,{unitId:n,subUnitId:i,segmentId:a,style:c,ranges:l.map(z)})}_getTextRanges(e){var i;if(e==null)return;const{unitId:t,subUnitId:n=""}=e;return(i=this._textSelectionInfo.get(t))==null?void 0:i.get(n)}_refresh(e){const t=this._getTextRanges(e);this._textSelectionRenderManager.removeAllTextRanges(),t&&Array.isArray(t.textRanges)&&t.textRanges.length&&this._textSelectionRenderManager.addTextRanges(t.textRanges.map(z))}_replaceByParam(e){const{unitId:t,subUnitId:n,style:i,segmentId:a,textRanges:c}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(n,{textRanges:c,style:i,segmentId:a})}_addByParam(e){const{unitId:t,subUnitId:n,textRanges:i,style:a,segmentId:c}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);const l=this._textSelectionInfo.get(t);l.has(n)?l.get(n).textRanges.push(...i):l.set(n,{textRanges:i,style:a,segmentId:c})}};exports.TextSelectionManagerService=nt([Ue(0,C.ITextSelectionRenderManager),Ue(1,o.ICommandService)],exports.TextSelectionManagerService);function Te(s,r="",e=0){const{startOffset:t,endOffset:n}=s,i=[],a=t-e,c=n-e;return a>0&&i.push({t:o.TextXActionType.RETAIN,len:a,segmentId:r}),i.push({t:o.TextXActionType.DELETE,len:c-a,line:0,segmentId:r}),i}var rt=Object.defineProperty,it=Object.getOwnPropertyDescriptor,ot=(s,r,e,t)=>{for(var n=t>1?void 0:t?it(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&rt(r,e,n),n},st=(s,r)=>(e,t)=>r(e,t,s);exports.DocViewModelManagerService=class extends o.RxDisposable{constructor(e){super();I(this,"_currentViewModelUnitId","");I(this,"_docViewModelMap",new Map);I(this,"_currentDocViewModel$",new N.BehaviorSubject(null));I(this,"currentDocViewModel$",this._currentDocViewModel$.asObservable());this._currentUniverService=e,this._initialize()}_initialize(){this._currentUniverService.currentDoc$.pipe(N.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const t=e.getUnitId();this._setCurrent(t)})}dispose(){this._currentDocViewModel$.complete(),this._docViewModelMap.clear()}getCurrent(){return this._docViewModelMap.get(this._currentViewModelUnitId)}getViewModel(e){var t;return(t=this._docViewModelMap.get(e))==null?void 0:t.docViewModel}_setCurrent(e){var n;const t=this._currentUniverService.getUniverDocInstance(e);if(t==null)throw new Error(`Document data model with id ${e} not found when build view model.`);if(t.getBody()!=null){if(!this._docViewModelMap.has(e)){const i=this._buildDocViewModel(t);this._docViewModelMap.set(e,{unitId:e,docViewModel:i})}if(e===o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY){const i=(n=this._docViewModelMap.get(e))==null?void 0:n.docViewModel;if(i==null)return;i.reset(t)}this._currentViewModelUnitId=e,this._currentDocViewModel$.next(this.getCurrent())}}_buildDocViewModel(e){return new C.DocumentViewModel(e)}};exports.DocViewModelManagerService=ot([st(0,o.IUniverInstanceService)],exports.DocViewModelManagerService);var at=Object.defineProperty,ct=Object.getOwnPropertyDescriptor,lt=(s,r,e,t)=>{for(var n=t>1?void 0:t?ct(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&at(r,e,n),n},fe=(s,r)=>(e,t)=>r(e,t,s);const dt=300;exports.DocStateChangeManagerService=class extends o.RxDisposable{constructor(e,t,n){super();I(this,"_docStateChange$",new N.BehaviorSubject(null));I(this,"docStateChange$",this._docStateChange$.asObservable());I(this,"_stateCache",new Map);I(this,"_timer",null);this._undoRedoService=e,this._commandService=t,this._univerInstanceService=n,this._initialize()}setChangeState(e){const{trigger:t,noHistory:n}=e;t!=null&&(this._cacheChangeState(e),n||this._docStateChange$.next(e))}_initialize(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===o.UndoCommandId||e.id===o.RedoCommandId){const t=this._univerInstanceService.getCurrentUniverDocInstance();if(t==null)return;const n=t.getUnitId();this._pushHistory(n)}}))}_cacheChangeState(e){const{trigger:t,unitId:n,noHistory:i}=e;if(!(t===o.RedoCommandId||t===o.UndoCommandId||i)){if(this._stateCache.has(n)){const a=this._stateCache.get(n);a==null||a.push(e)}else this._stateCache.set(n,[e]);t===H.id||t===W.id?(this._timer&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._pushHistory(n)},dt)):this._pushHistory(n)}}_pushHistory(e){const t=this._undoRedoService,n=this._stateCache.get(e);if(!Array.isArray(n)||n.length===0)return;const i=n.length,a=n[0].commandId,c=n[0],l=n[i-1],u={unitId:e,actions:n.reduce((m,g)=>o.TextX.compose(m,g.redoState.actions),[]),textRanges:l.redoState.textRanges},d={unitId:e,actions:n.reverse().reduce((m,g)=>o.TextX.compose(m,g.undoState.actions),[]),textRanges:c.undoState.textRanges};t.pushUndoRedo({unitID:e,undoMutations:[{id:a,params:d}],redoMutations:[{id:a,params:u}]}),n.length=0}};exports.DocStateChangeManagerService=lt([fe(0,b.Inject(o.IUndoRedoService)),fe(1,o.ICommandService),fe(2,o.IUniverInstanceService)],exports.DocStateChangeManagerService);class Y{constructor(){I(this,"_previousActiveRange",null);I(this,"_undoMutationParamsCache",[]);I(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache:r=[],redoCache:e=[]}){this._undoMutationParamsCache=r,this._redoMutationParamsCache=e}getActiveRange(){return this._previousActiveRange}setActiveRange(r){this._previousActiveRange=r}pushUndoRedoMutationParams(r,e){this._undoMutationParamsCache.push(r),this._redoMutationParamsCache.push(e)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:r}=this._undoMutationParamsCache[0],e={unitId:r,actions:this._undoMutationParamsCache.reverse().reduce((n,i)=>o.TextX.compose(n,i.actions),[]),textRanges:[]};return{redoMutationParams:{unitId:r,actions:this._redoMutationParamsCache.reduce((n,i)=>o.TextX.compose(n,i.actions),[]),textRanges:[]},undoMutationParams:e,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Pe="doc.mutation.rich-text-editing",U={id:Pe,type:o.CommandType.MUTATION,handler:(s,r)=>{var x;const{unitId:e,actions:t,textRanges:n,prevTextRanges:i,trigger:a,noHistory:c,isCompositionEnd:l,noNeedSetTextRange:u}=r,m=s.get(o.IUniverInstanceService).getUniverDocInstance(e),h=s.get(exports.DocViewModelManagerService).getViewModel(e),p=s.get(exports.TextSelectionManagerService),S=((x=p.getSelections())!=null?x:[]).map(z),f=s.get(exports.DocStateChangeManagerService),v=s.get(Y);if(m==null||h==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);if(t.length===0)throw new Error("Mutation's length should great than 0 when call RichTextEditingMutation");const T=m.apply(t),{segmentId:O}=t[0],R=m.getSelfOrHeaderFooterModel(O);h.getSelfOrHeaderFooterViewModel(O).reset(R),!u&&n&&queueMicrotask(()=>{p.replaceTextRanges(n)});const D={commandId:Pe,unitId:e,trigger:a,noHistory:c,redoState:{actions:t,textRanges:n},undoState:{actions:T,textRanges:i!=null?i:S}};if(l){const y=v.fetchComposedUndoRedoMutationParams();if(y==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:M,redoMutationParams:A,previousActiveRange:P}=y;D.redoState.actions=A.actions,D.undoState.actions=M.actions,D.undoState.textRanges=[P]}return f.setChangeState(D),{unitId:e,actions:T,textRanges:S}}},H={id:"doc.command.insert-text",type:o.CommandType.COMMAND,handler:async(s,r)=>{const e=s.get(o.ICommandService),{range:t,segmentId:n,body:i,unitId:a,textRanges:c}=r,{startOffset:l,collapsed:u}=t,d={id:U.id,params:{unitId:a,actions:[],textRanges:c}},m=new o.TextX;return u?l>0&&m.push({t:o.TextXActionType.RETAIN,len:l,segmentId:n}):m.push(...Te(t,n)),m.push({t:o.TextXActionType.INSERT,body:i,len:i.dataStream.length,line:0,segmentId:n}),d.params.actions=m.serialize(),!!e.syncExecuteCommand(d.id,d.params)}};var w=(s=>(s[s.LEFT=0]="LEFT",s[s.RIGHT=1]="RIGHT",s))(w||{});const W={id:"doc.command.delete-text",type:o.CommandType.COMMAND,handler:async(s,r)=>{const e=s.get(o.ICommandService),{range:t,segmentId:n,unitId:i,direction:a,textRanges:c,len:l=1}=r,{startOffset:u}=t,d={id:U.id,params:{unitId:i,actions:[],textRanges:c}},m=new o.TextX;return u>0&&m.push({t:o.TextXActionType.RETAIN,len:a===0?u-l:u,segmentId:n}),m.push({t:o.TextXActionType.DELETE,len:l,line:0,segmentId:n}),d.params.actions=m.serialize(),!!e.syncExecuteCommand(d.id,d.params)}},Oe={id:"doc.command.update-text",type:o.CommandType.COMMAND,handler:async(s,r)=>{const{range:e,segmentId:t,updateBody:n,coverType:i,unitId:a,textRanges:c}=r,l=s.get(o.ICommandService),u={id:U.id,params:{unitId:a,actions:[],textRanges:c}},d=new o.TextX,{startOffset:m,endOffset:g}=e;return d.push({t:o.TextXActionType.RETAIN,len:m,segmentId:t}),d.push({t:o.TextXActionType.RETAIN,body:n,len:g-m,segmentId:t,coverType:i}),u.params.actions=d.serialize(),!!l.syncExecuteCommand(u.id,u.params)}};function ut(s,r){const e=[];for(let t=0,n=s.length;t<n;t++)s[t]===o.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});if(r)for(const t of e)r.bullet&&(t.bullet=o.Tools.deepClone(r.bullet)),r.paragraphStyle&&(t.paragraphStyle=o.Tools.deepClone(r.paragraphStyle));return e}const $e={id:"doc.command.break-line",type:o.CommandType.COMMAND,handler:async s=>{var p,_;const r=s.get(exports.TextSelectionManagerService),e=s.get(o.IUniverInstanceService),t=s.get(o.ICommandService),n=r.getActiveRange();if(n==null)return!1;const i=e.getCurrentUniverDocInstance(),a=i.getUnitId(),{startOffset:c,segmentId:l,style:u}=n,d=[{startOffset:c+1,endOffset:c+1,style:u}],g=((_=(p=i.getBody())==null?void 0:p.paragraphs)!=null?_:[]).find(S=>S.startIndex>=c);return await t.executeCommand(H.id,{unitId:a,body:{dataStream:o.DataStreamTreeTokenType.PARAGRAPH,paragraphs:ut(o.DataStreamTreeTokenType.PARAGRAPH,g)},range:n,textRanges:d,segmentId:l})}};var mt=Object.defineProperty,gt=Object.getOwnPropertyDescriptor,ht=(s,r,e,t)=>{for(var n=t>1?void 0:t?gt(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&mt(r,e,n),n},Ne=(s,r)=>(e,t)=>r(e,t,s);exports.DocSkeletonManagerService=class extends o.RxDisposable{constructor(e,t){super();I(this,"_currentSkeletonUnitId","");I(this,"_docSkeletonMap",new Map);I(this,"_currentSkeleton$",new N.BehaviorSubject(null));I(this,"currentSkeleton$",this._currentSkeleton$.asObservable());I(this,"_currentSkeletonBefore$",new N.BehaviorSubject(null));I(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._localeService=e,this._docViewModelManagerService=t,this._initialize()}_initialize(){this._docViewModelManagerService.currentDocViewModel$.pipe(N.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._setCurrent(e)})}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._docSkeletonMap.clear()}getCurrent(){return this.getSkeletonByUnitId(this._currentSkeletonUnitId)}makeDirtyCurrent(e=!0){this.makeDirty(this._currentSkeletonUnitId,e)}makeDirty(e,t=!0){const n=this.getSkeletonByUnitId(e);n!=null&&(n.dirty=t)}getSkeletonByUnitId(e){return this._docSkeletonMap.get(e)}_setCurrent(e){const{unitId:t}=e;if(this._docSkeletonMap.has(t)){const n=this.getSkeletonByUnitId(t);n.skeleton.calculate(),n.dirty=!0}else{const n=this._buildSkeleton(e.docViewModel);n.calculate(),this._docSkeletonMap.set(t,{unitId:t,skeleton:n,dirty:!1})}return this._currentSkeletonUnitId=t,this._currentSkeletonBefore$.next(this.getCurrent()),this._currentSkeleton$.next(this.getCurrent()),this.getCurrent()}_buildSkeleton(e){return C.DocumentSkeleton.create(e,this._localeService)}};exports.DocSkeletonManagerService=ht([Ne(0,b.Inject(o.LocaleService)),Ne(1,b.Inject(exports.DocViewModelManagerService))],exports.DocSkeletonManagerService);const St={id:"doc.command.inner-paste",type:o.CommandType.COMMAND,handler:async(s,r)=>{const{segmentId:e,body:t,textRanges:n}=r,i=s.get(o.ICommandService),a=s.get(exports.TextSelectionManagerService),c=s.get(o.IUniverInstanceService),l=a.getSelections();if(!Array.isArray(l)||l.length===0)return!1;const d=c.getCurrentUniverDocInstance().getUnitId(),m={id:U.id,params:{unitId:d,actions:[],textRanges:n}},g=new o.MemoryCursor;g.reset();const h=new o.TextX;for(const _ of l){const{startOffset:S,endOffset:f,collapsed:v}=_,T=S-g.cursor;v?h.push({t:o.TextXActionType.RETAIN,len:T,segmentId:e}):h.push(...Te(_,e,g.cursor)),h.push({t:o.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:e}),g.reset(),g.moveCursor(f)}return m.params.actions=h.serialize(),!!i.syncExecuteCommand(m.id,m.params)}},Re={id:"doc.command.inner-cut",type:o.CommandType.COMMAND,handler:async(s,r)=>{const{segmentId:e,textRanges:t}=r,n=s.get(o.ICommandService),i=s.get(exports.TextSelectionManagerService),a=s.get(o.IUniverInstanceService),c=i.getSelections();if(!Array.isArray(c)||c.length===0)return!1;const l=a.getCurrentUniverDocInstance().getUnitId(),u=a.getUniverDocInstance(l),d=o.getDocsUpdateBody(u.snapshot,e);if(d==null)return!1;const m={id:U.id,params:{unitId:l,actions:[],textRanges:t}},g=new o.MemoryCursor;g.reset();const h=new o.TextX;for(const _ of c){const{startOffset:S,endOffset:f,collapsed:v}=_,T=S-g.cursor;v?h.push({t:o.TextXActionType.RETAIN,len:T,segmentId:e}):h.push(...pt(_,d,e,g.cursor)),g.reset(),g.moveCursor(f)}return m.params.actions=h.serialize(),!!n.syncExecuteCommand(m.id,m.params)}};function pt(s,r,e="",t=0){const{startOffset:n,endOffset:i}=s,a=[],{paragraphs:c=[]}=r,l=n-t,u=i-t,d=c==null?void 0:c.find(m=>m.startIndex-t>=l&&m.startIndex-t<=u);if(l>0&&a.push({t:o.TextXActionType.RETAIN,len:l,segmentId:e}),d&&d.startIndex-t>l){const m=d.startIndex-t;a.push({t:o.TextXActionType.DELETE,len:m-l,line:0,segmentId:e}),a.push({t:o.TextXActionType.RETAIN,len:1,segmentId:e}),u>m+1&&a.push({t:o.TextXActionType.DELETE,len:u-m-1,line:0,segmentId:e})}else a.push({t:o.TextXActionType.DELETE,len:u-l,line:0,segmentId:e});return a}const je={id:"doc.command.delete-left",type:o.CommandType.COMMAND,handler:async s=>{var O;const r=s.get(exports.TextSelectionManagerService),e=s.get(exports.DocSkeletonManagerService),t=s.get(o.IUniverInstanceService),n=s.get(o.ICommandService),i=r.getActiveRange(),a=r.getSelections(),c=(O=e.getCurrent())==null?void 0:O.skeleton;let l=!0;if(i==null||c==null||a==null)return!1;const u=t.getCurrentUniverDocInstance(),{startOffset:d,collapsed:m,segmentId:g,style:h}=i,p=c.findNodeByCharIndex(d),_=C.hasListSpan(p),S=C.isIndentBySpan(p,u.getBody());let f=d;const v=c.findNodeByCharIndex(d-1);if(C.isFirstSpan(p)&&v!==p&&(_===!0||S===!0)){const R=C.getParagraphBySpan(p,u.getBody());if(R==null)return!1;const E=R==null?void 0:R.startIndex,D={startIndex:0},x=R.paragraphStyle;if(_===!0){const M=R.paragraphStyle;M&&(D.paragraphStyle=M)}else if(S===!0){const M=R.bullet;M&&(D.bullet=M),x!=null&&(D.paragraphStyle={...x},delete D.paragraphStyle.hanging,delete D.paragraphStyle.indentStart)}const y=[{startOffset:f,endOffset:f,style:h}];l=await n.executeCommand(Oe.id,{unitId:u.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...D}]},range:{startOffset:E,endOffset:E+1},textRanges:y,coverType:o.UpdateDocsAttributeType.REPLACE,segmentId:g})}else if(m===!0){if(v==null)return!0;if(v.content==="\r")l=await n.executeCommand(xe.id,{direction:w.LEFT,range:i});else{f-=v.count;const R=[{startOffset:f,endOffset:f,style:h}];l=await n.executeCommand(W.id,{unitId:u.getUnitId(),range:i,segmentId:g,direction:w.LEFT,len:v.count,textRanges:R})}}else{const R=Ve(i,a);l=await n.executeCommand(Re.id,{segmentId:g,textRanges:R})}return l}},Fe={id:"doc.command.delete-right",type:o.CommandType.COMMAND,handler:async s=>{var p;const r=s.get(exports.TextSelectionManagerService),e=s.get(exports.DocSkeletonManagerService),t=s.get(o.IUniverInstanceService),n=s.get(o.ICommandService),i=r.getActiveRange(),a=r.getSelections(),c=(p=e.getCurrent())==null?void 0:p.skeleton;let l;if(i==null||c==null||a==null)return!1;const u=t.getCurrentUniverDocInstance(),{startOffset:d,collapsed:m,segmentId:g,style:h}=i;if(d===u.getBody().dataStream.length-2&&m)return!0;if(m===!0){const _=c.findNodeByCharIndex(d);if(_.content==="\r")l=await n.executeCommand(xe.id,{direction:w.RIGHT,range:i});else{const S=[{startOffset:d,endOffset:d,style:h}];l=await n.executeCommand(W.id,{unitId:u.getUnitId(),range:i,segmentId:g,direction:w.RIGHT,textRanges:S,len:_.count})}}else{const _=Ve(i,a);l=await n.executeCommand(Re.id,{segmentId:g,textRanges:_})}return l}},xe={id:"doc.command.merge-two-paragraph",type:o.CommandType.COMMAND,handler:async(s,r)=>{var D,x,y;const e=s.get(exports.TextSelectionManagerService),t=s.get(o.IUniverInstanceService),n=s.get(o.ICommandService);s.get(o.IUndoRedoService);const{direction:i,range:a}=r,c=e.getActiveRange(),l=e.getSelections();if(c==null||l==null)return!1;const u=t.getCurrentUniverDocInstance(),{startOffset:d,collapsed:m,segmentId:g,style:h}=c;if(!m)return!1;const p=i===w.LEFT?d:d+1,_=(y=(x=(D=u.getBody())==null?void 0:D.paragraphs)==null?void 0:x.find(M=>M.startIndex>=p))==null?void 0:y.startIndex,S=_t(u.getBody(),p,_),f=i===w.LEFT?d-1:d,v=u.getUnitId(),T=[{startOffset:f,endOffset:f,style:h}],O={id:U.id,params:{unitId:v,actions:[],textRanges:T,prevTextRanges:[a]}},R=new o.TextX;return R.push({t:o.TextXActionType.RETAIN,len:i===w.LEFT?d-1:d,segmentId:g}),S.dataStream.length&&R.push({t:o.TextXActionType.INSERT,body:S,len:S.dataStream.length,line:0,segmentId:g}),R.push({t:o.TextXActionType.RETAIN,len:1,segmentId:g}),R.push({t:o.TextXActionType.DELETE,len:_+1-p,line:0,segmentId:g}),O.params.actions=R.serialize(),!!n.syncExecuteCommand(O.id,O.params)}};function _t(s,r,e){const{textRuns:t}=s,n=s.dataStream.substring(r,e);if(t==null)return{dataStream:n};const i=[];for(const a of t){const{st:c,ed:l}=a;l<=r||c>=e||(c<r?i.push({...a,st:0,ed:l-r}):l>e?i.push({...a,st:c-r,ed:e-r}):i.push({...a,st:c-r,ed:l-r}))}return{dataStream:n,textRuns:i}}function Ve(s,r){let e=s.endOffset;for(const n of r){const{startOffset:i,endOffset:a}=n;i==null||a==null||a<=s.endOffset&&(e-=a-i)}return[{startOffset:e,endOffset:e,style:s.style}]}const ye={id:"doc.command.ime-input",type:o.CommandType.COMMAND,handler:async(s,r)=>{const{unitId:e,newText:t,oldTextLen:n,isCompositionEnd:i,isCompositionStart:a}=r,c=s.get(o.ICommandService),l=s.get(Y),u=l.getActiveRange();if(u==null)return!1;const{startOffset:d,style:m,segmentId:g}=u,h=t.length,p=[{startOffset:d+h,endOffset:d+h,collapsed:!0,style:m}],_={id:U.id,params:{unitId:e,actions:[],textRanges:p}},S=new o.TextX;!u.collapsed&&a?S.push(...Te(u,g)):S.push({t:o.TextXActionType.RETAIN,len:d,segmentId:g}),n>0&&S.push({t:o.TextXActionType.DELETE,len:n,line:0,segmentId:g}),S.push({t:o.TextXActionType.INSERT,body:{dataStream:t},len:t.length,line:0,segmentId:g}),_.params.actions=S.serialize(),_.params.noHistory=!i,_.params.isCompositionEnd=i;const f=c.syncExecuteCommand(_.id,_.params);return l.pushUndoRedoMutationParams(f,_.params),!!f}},G={id:"doc.command.set-inline-format-bold",type:o.CommandType.COMMAND,handler:async()=>!0},K={id:"doc.command.set-inline-format-italic",type:o.CommandType.COMMAND,handler:async()=>!0},q={id:"doc.command.set-inline-format-underline",type:o.CommandType.COMMAND,handler:async()=>!0},Z={id:"doc.command.set-inline-format-strikethrough",type:o.CommandType.COMMAND,handler:async()=>!0},B={id:"doc.command.set-inline-format-subscript",type:o.CommandType.COMMAND,handler:async()=>!0},J={id:"doc.command.set-inline-format-superscript",type:o.CommandType.COMMAND,handler:async()=>!0},Q={id:"doc.command.set-inline-format-fontsize",type:o.CommandType.COMMAND,handler:async()=>!0},ee={id:"doc.command.set-inline-format-font-family",type:o.CommandType.COMMAND,handler:async()=>!0},te={id:"doc.command.set-inline-format-text-color",type:o.CommandType.COMMAND,handler:async()=>!0},ke={[G.id]:"bl",[K.id]:"it",[q.id]:"ul",[Z.id]:"st",[Q.id]:"fs",[ee.id]:"ff",[te.id]:"cl",[B.id]:"va",[J.id]:"va"},De={id:"doc.command.set-inline-format",type:o.CommandType.COMMAND,handler:async(s,r)=>{const{segmentId:e,value:t,preCommandId:n}=r,i=s.get(o.ICommandService),a=s.get(exports.TextSelectionManagerService),c=s.get(o.IUniverInstanceService),l=a.getSelections();if(!Array.isArray(l)||l.length===0)return!1;let u=c.getCurrentUniverDocInstance(),d=u.getUnitId();d===o.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(u=c.getUniverDocInstance(o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),d=u.getUnitId());let m;switch(n){case G.id:case K.id:case q.id:case Z.id:case B.id:case J.id:{m=vt(u.getBody().textRuns,n,l);break}case Q.id:case ee.id:{m=t;break}case te.id:{m={rgb:t};break}default:throw new Error(`Unknown command: ${n} in handleInlineFormat`)}const g={id:U.id,params:{unitId:d,actions:[],textRanges:l}},h=new o.TextX,p=new o.MemoryCursor;p.reset();for(const S of l){const{startOffset:f,endOffset:v}=S,T={dataStream:"",textRuns:[{st:0,ed:v-f,ts:{[ke[n]]:m}}]},O=f-p.cursor;O!==0&&h.push({t:o.TextXActionType.RETAIN,len:O,segmentId:e}),h.push({t:o.TextXActionType.RETAIN,body:T,len:v-f,segmentId:e}),p.reset(),p.moveCursor(v)}return g.params.actions=h.serialize(),!!i.syncExecuteCommand(g.id,g.params)}};function ft(s){return s!==null&&typeof s=="object"}function vt(s,r,e){let t=0,n=0;const i=ke[r];for(;t!==s.length&&n!==e.length;){const{startOffset:a,endOffset:c}=e[n],{st:l,ed:u,ts:d}=s[t];if(c<=l)n++;else if(u<=a)t++;else{if(/bl|it/.test(i))return(d==null?void 0:d[i])===o.BooleanNumber.TRUE?o.BooleanNumber.FALSE:o.BooleanNumber.TRUE;if(/ul|st/.test(i))return ft(d==null?void 0:d[i])&&(d==null?void 0:d[i]).s===o.BooleanNumber.TRUE?{s:o.BooleanNumber.FALSE}:{s:o.BooleanNumber.TRUE};if(/va/.test(i))return r===B.id?(d==null?void 0:d[i])===o.BaselineOffset.SUBSCRIPT?o.BaselineOffset.NORMAL:o.BaselineOffset.SUBSCRIPT:(d==null?void 0:d[i])===o.BaselineOffset.SUPERSCRIPT?o.BaselineOffset.NORMAL:o.BaselineOffset.SUPERSCRIPT;t++}}return/bl|it/.test(i)?o.BooleanNumber.TRUE:/ul|st/.test(i)?{s:o.BooleanNumber.TRUE}:r===B.id?o.BaselineOffset.SUBSCRIPT:o.BaselineOffset.SUPERSCRIPT}const be={id:"doc.command.list-operation",type:o.CommandType.COMMAND,handler:(s,r)=>{var R,E,D;const e=s.get(exports.TextSelectionManagerService),t=s.get(o.IUniverInstanceService),n=s.get(o.ICommandService),{listType:i}=r,a=t.getCurrentUniverDocInstance(),c=e.getActiveRange(),l=(R=e.getSelections())!=null?R:[],u=(E=a.getBody())==null?void 0:E.paragraphs,d=l.map(z);if(c==null||u==null)return!1;const m=It(c,u),{segmentId:g}=c,h=a.getUnitId(),p=m.every(x=>{var y;return((y=x.bullet)==null?void 0:y.listType)===i});let S=o.Tools.generateRandomId(6);if(m.length===1){const x=u.indexOf(m[0]),y=u[x-1],M=u[x+1];y&&y.bullet&&y.bullet.listType===i?S=y.bullet.listId:M&&M.bullet&&M.bullet.listType===i&&(S=M.bullet.listId)}const f={id:U.id,params:{unitId:h,actions:[],textRanges:d}},v=new o.MemoryCursor;v.reset();const T=new o.TextX;for(const x of m){const{startIndex:y}=x;T.push({t:o.TextXActionType.RETAIN,len:y-v.cursor,segmentId:g});const M={...x.paragraphStyle,hanging:void 0,indentStart:void 0};T.push({t:o.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[p?{paragraphStyle:M,startIndex:0}:{...x,startIndex:0,bullet:{...(D=x.bullet)!=null?D:{nestingLevel:0,textStyle:{fs:20}},listType:i,listId:S}}]},segmentId:g,coverType:o.UpdateDocsAttributeType.REPLACE}),v.moveCursorTo(y+1)}return f.params.actions=T.serialize(),!!n.syncExecuteCommand(f.id,f.params)}},Xe={id:"doc.command.bullet-list",type:o.CommandType.COMMAND,handler:s=>s.get(o.ICommandService).syncExecuteCommand(be.id,{listType:o.PresetListType.BULLET_LIST})},ze={id:"doc.command.order-list",type:o.CommandType.COMMAND,handler:s=>s.get(o.ICommandService).syncExecuteCommand(be.id,{listType:o.PresetListType.ORDER_LIST})};function It(s,r){const{startOffset:e,endOffset:t}=s,n=[];let i=-1;for(const a of r){const{startIndex:c}=a;(e>i&&e<=c||t>i&&t<=c||c>=e&&c<=t)&&n.push(a),i=c}return n}const Ye={id:"doc.command-replace-content",type:o.CommandType.COMMAND,handler:async(s,r)=>{var h;const{unitId:e,body:t,textRanges:n,segmentId:i=""}=r,a=s.get(o.IUniverInstanceService),c=s.get(o.ICommandService),l=s.get(exports.TextSelectionManagerService),u=(h=a.getUniverDocInstance(e))==null?void 0:h.getSnapshot().body,d=l.getSelections();if(u==null||!Array.isArray(d)||d.length===0)return!1;const m=We(e,i,u,t);return m.params.textRanges=n,!!c.syncExecuteCommand(m.id,m.params)}},He={id:"doc.command-cover-content",type:o.CommandType.COMMAND,handler:async(s,r)=>{var d;const{unitId:e,body:t,segmentId:n=""}=r,i=s.get(o.IUniverInstanceService),a=s.get(o.ICommandService),c=s.get(o.IUndoRedoService),l=(d=i.getUniverDocInstance(e))==null?void 0:d.getSnapshot().body;if(l==null)return!1;const u=We(e,n,l,t);return u.params.noNeedSetTextRange=!0,u.params.noHistory=!0,a.syncExecuteCommand(u.id,u.params),c.clearUndoRedo(e),!0}};function We(s,r,e,t){const n={id:U.id,params:{unitId:s,actions:[],textRanges:[]}},i=new o.TextX,a=(e==null?void 0:e.dataStream.length)-2;return a>0&&i.push({t:o.TextXActionType.DELETE,len:a,line:0,segmentId:r}),t.dataStream.length>0&&i.push({t:o.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:r}),n.params.actions=i.serialize(),n}const he={id:"doc.operation.move-cursor",type:o.CommandType.OPERATION,handler:(s,r)=>!!r},Se={id:"doc.operation.move-selection",type:o.CommandType.OPERATION,handler:(s,r)=>!!r},Mt=(s,r)=>{const e=s.get(o.IUniverInstanceService).getUniverDocInstance(r.unitId),t=(e==null?void 0:e.zoomRatio)||1;return{...o.Tools.deepClone(r),zoomRatio:t}},L={id:"doc.operation.set-zoom-ratio",type:o.CommandType.OPERATION,handler:(s,r)=>{const e=s.get(o.IUniverInstanceService).getUniverDocInstance(r.unitId);if(!e)return!1;const t=e.getSnapshot();return t.settings==null?t.settings={zoomRatio:r.zoomRatio}:t.settings.zoomRatio=r.zoomRatio,!0}},Ge={type:o.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(s,r)=>{var m,g;const e=s.get(o.ICommandService),t=s.get(o.IUndoRedoService),n=s.get(o.IUniverInstanceService);let i=n.getCurrentUniverDocInstance().getUnitId(),a=1;if(r&&(i=(m=r.documentId)!=null?m:i,a=(g=r.zoomRatio)!=null?g:a),!n.getUniverDocInstance(i))return!1;const l={zoomRatio:a,unitId:i},u=Mt(s,l);return e.syncExecuteCommand(L.id,l)?(t.pushUndoRedo({unitID:i,undoMutations:[{id:L.id,params:u}],redoMutations:[{id:L.id,params:l}]}),!0):!1}},Ke={id:"doc.operation.select-all",type:o.CommandType.COMMAND,handler:async s=>{const r=s.get(o.IUniverInstanceService),e=s.get(exports.TextSelectionManagerService),t=r.getCurrentUniverDocInstance().getSnapshot().body;if(t==null)return!1;const n=[{startOffset:0,endOffset:t.dataStream.length-2}];return e.replaceTextRanges(n),!0}};var Ct=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,Ot=(s,r,e,t)=>{for(var n=t>1?void 0:t?Tt(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Ct(r,e,n),n},ve=(s,r)=>(e,t)=>r(e,t,s);let ie=class extends o.RxDisposable{constructor(s,r,e){super(),this._docSkeletonManagerService=s,this._renderManagerService=r,this._commandService=e,this._initialRenderRefresh(),this._commandExecutedListener()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(N.takeUntil(this.dispose$)).subscribe(s=>{if(s==null)return;const{skeleton:r,unitId:e}=s,t=this._renderManagerService.getRenderById(e);if(t==null)return;const{mainComponent:n}=t;n.changeSkeleton(r),this._recalculateSizeBySkeleton(t,r)})}_recalculateSizeBySkeleton(s,r){var u;const{mainComponent:e,scene:t}=s,n=e,i=(u=r.getSkeletonData())==null?void 0:u.pages;if(i==null)return;let a=0,c=0;for(let d=0,m=i.length;d<m;d++){const g=i[d],{pageWidth:h,pageHeight:p}=g;n.pageLayoutType===C.PageLayoutType.VERTICAL?(c+=p,c+=n.pageMarginTop,d===m-1&&(c+=n.pageMarginTop),a=Math.max(a,h)):n.pageLayoutType===C.PageLayoutType.HORIZONTAL&&(a+=h,d!==m-1&&(a+=n.pageMarginLeft),c=Math.max(c,p))}n.resize(a,c),[o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,o.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(s.unitId)||t.resize(a,c)}_commandExecutedListener(){const s=[U.id],r=[o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,o.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t;if(s.includes(e.id)){const n=e.params,{unitId:i}=n,a=this._docSkeletonManagerService.getSkeletonByUnitId(i);if(a==null)return;const{skeleton:c}=a,l=this._renderManagerService.getRenderById(i);if(l==null)return;if(c.calculate(),r.includes(i)){(t=l.mainComponent)==null||t.makeDirty();return}this._recalculateSizeBySkeleton(l,c)}}))}};ie=Ot([o.OnLifecycle(o.LifecycleStages.Rendered,ie),ve(0,b.Inject(exports.DocSkeletonManagerService)),ve(1,C.IRenderManagerService),ve(2,o.ICommandService)],ie);var Rt=Object.defineProperty,xt=Object.getOwnPropertyDescriptor,yt=(s,r,e,t)=>{for(var n=t>1?void 0:t?xt(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Rt(r,e,n),n},j=(s,r)=>(e,t)=>r(e,t,s);let oe=class extends o.Disposable{constructor(r,e,t,n,i){super();I(this,"_liquid",new C.Liquid);I(this,"_pageMarginCache",new Map);this._docSkeletonManagerService=r,this._currentUniverService=e,this._renderManagerService=t,this._commandService=n,this._floatingObjectManagerService=i,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh(),this._updateOnPluginChange()}_updateOnPluginChange(){this._floatingObjectManagerService.pluginUpdate$.subscribe(r=>{const e=this._docSkeletonManagerService.getCurrent();if(e==null)return;const{unitId:t,skeleton:n}=e,i=this._renderManagerService.getRenderById(t);if(i==null)return;const{mainComponent:a,components:c,scene:l}=i,u=a,{left:d,top:m}=u;r.forEach(g=>{const{unitId:h,subUnitId:p,floatingObjectId:_,floatingObject:S}=g,{left:f=0,top:v=0,width:T=0,height:O=0,angle:R,flipX:E,flipY:D,skewX:x,skewY:y}=S,M=this._pageMarginCache.get(_),A=(M==null?void 0:M.marginLeft)||0,P=(M==null?void 0:M.marginTop)||0;n==null||n.getViewModel().getDataModel().updateDrawing(_,{left:f-d-A,top:v-m-P,height:O,width:T})}),n==null||n.calculate(),a==null||a.makeDirty()})}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(r=>{if(r==null)return;const{skeleton:e,unitId:t}=r,n=this._renderManagerService.getRenderById(t);if(n==null)return;const{mainComponent:i}=n;i.changeSkeleton(e),this._refreshFloatingObject(t,e,n)})}_commandExecutedListener(){const r=[U.id,L.id],e=[o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,o.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(r.includes(t.id)){const i=t.params,{unitId:a}=i,c=this._docSkeletonManagerService.getCurrent();if(c==null)return;const{unitId:l,skeleton:u}=c;if(a!==l)return;const d=this._renderManagerService.getRenderById(l);if(d==null)return;if(e.includes(l)){(n=d.mainComponent)==null||n.makeDirty();return}this._refreshFloatingObject(l,u,d)}}))}_refreshFloatingObject(r,e,t){const n=e==null?void 0:e.getSkeletonData(),{mainComponent:i,scene:a}=t,c=i;if(!n)return;const{left:l,top:u,pageLayoutType:d,pageMarginLeft:m,pageMarginTop:g}=c,{pages:h}=n,p=[];a.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let _=0,S=h.length;_<S;_++){const f=h[_],{skeDrawings:v,marginLeft:T,marginTop:O}=f;this._liquid.translatePagePadding(f),v.forEach(R=>{const{aLeft:E,aTop:D,height:x,width:y,objectId:M}=R;p.push({unitId:r,subUnitId:o.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:M,floatingObject:{left:E+l+this._liquid.x,top:D+u+this._liquid.y,width:y,height:x}}),this._pageMarginCache.set(M,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.translatePage(f,d,m,g)}this._floatingObjectManagerService.BatchAddOrUpdate(p)}};oe=yt([o.OnLifecycle(o.LifecycleStages.Steady,oe),j(0,b.Inject(exports.DocSkeletonManagerService)),j(1,o.IUniverInstanceService),j(2,C.IRenderManagerService),j(3,o.ICommandService),j(4,o.IFloatingObjectManagerService)],oe);var Dt=Object.defineProperty,bt=Object.getOwnPropertyDescriptor,Et=(s,r,e,t)=>{for(var n=t>1?void 0:t?bt(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Dt(r,e,n),n},F=(s,r)=>(e,t)=>r(e,t,s);let se=class extends o.Disposable{constructor(r,e,t,n,i){super();I(this,"_previousIMEContent","");I(this,"_isCompositionStart",!0);I(this,"_onStartSubscription");I(this,"_onUpdateSubscription");I(this,"_onEndSubscription");this._docSkeletonManagerService=r,this._currentUniverService=e,this._textSelectionRenderManager=t,this._imeInputManagerService=n,this._commandService=i,this._initialize()}dispose(){var r,e,t;(r=this._onStartSubscription)==null||r.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(r=>{if(r==null)return;const{activeRange:e}=r;e!=null&&(this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(o.Tools.deepClone(e)),this._isCompositionStart=!0)})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._textSelectionRenderManager.onCompositionupdate$.subscribe(async r=>{this._updateContent(r,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._textSelectionRenderManager.onCompositionend$.subscribe(r=>{this._updateContent(r,!1)})}async _updateContent(r,e){var u;const t=(u=this._docSkeletonManagerService.getCurrent())==null?void 0:u.skeleton;if(r==null||t==null)return;const n=this._currentUniverService.getCurrentUniverDocInstance(),{event:i,activeRange:a}=r;if(t==null||a==null)return;const l=i.data;l===this._previousIMEContent&&e||(await this._commandService.executeCommand(ye.id,{unitId:n.getUnitId(),newText:l,oldTextLen:this._previousIMEContent.length,isCompositionStart:this._isCompositionStart,isCompositionEnd:!e}),e?(this._isCompositionStart&&(this._isCompositionStart=!1),this._previousIMEContent=l):this._resetIME())}_resetIME(){this._previousIMEContent="",this._isCompositionStart=!0,this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(null)}};se=Et([o.OnLifecycle(o.LifecycleStages.Rendered,se),F(0,b.Inject(exports.DocSkeletonManagerService)),F(1,o.IUniverInstanceService),F(2,C.ITextSelectionRenderManager),F(3,b.Inject(Y)),F(4,o.ICommandService)],se);var Ut=Object.defineProperty,Pt=Object.getOwnPropertyDescriptor,Nt=(s,r,e,t)=>{for(var n=t>1?void 0:t?Pt(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Ut(r,e,n),n},Ae=(s,r)=>(e,t)=>r(e,t,s);let ae=class extends o.Disposable{constructor(s,r){super(),this._textSelectionManagerService=s,this._commandService=r,this._commandExecutedListener()}_commandExecutedListener(){const s=[G.id,K.id,q.id,Z.id,B.id,J.id,Q.id,ee.id,te.id];this.disposeWithMe(this._commandService.onCommandExecuted(r=>{s.includes(r.id)&&this._handleInlineFormat(r)}))}_handleInlineFormat(s){var e,t;const{segmentId:r}=(e=this._textSelectionManagerService.getActiveRange())!=null?e:{};r!=null&&this._commandService.executeCommand(De.id,{segmentId:r,preCommandId:s.id,...(t=s.params)!=null?t:{}})}};ae=Nt([o.OnLifecycle(o.LifecycleStages.Rendered,ae),Ae(0,b.Inject(exports.TextSelectionManagerService)),Ae(1,o.ICommandService)],ae);var At=Object.defineProperty,wt=Object.getOwnPropertyDescriptor,Lt=(s,r,e,t)=>{for(var n=t>1?void 0:t?wt(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&At(r,e,n),n},V=(s,r)=>(e,t)=>r(e,t,s);let ce=class extends o.Disposable{constructor(r,e,t,n,i){super();I(this,"_onInputSubscription");this._docSkeletonManagerService=r,this._currentUniverService=e,this._renderManagerService=t,this._textSelectionManagerService=n,this._commandService=i,this._initialize(),this._commandExecutedListener()}dispose(){var r;(r=this._onInputSubscription)==null||r.unsubscribe()}_initialize(){}_commandExecutedListener(){const r=[he.id,Se.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!r.includes(e.id))return;const t=e.params;switch(e.id){case he.id:return this._handleMoveCursor(t.direction);case Se.id:return this._handleShiftMoveSelection(t.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(r){var _,S,f;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),n=this._currentUniverService.getCurrentUniverDocInstance(),i=(_=this._docSkeletonManagerService.getCurrent())==null?void 0:_.skeleton,a=this._getDocObject();if(e==null||i==null||a==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d,direction:m}=e;if(t.length>1){let v=Number.POSITIVE_INFINITY,T=Number.NEGATIVE_INFINITY;for(const O of t)v=Math.min(v,O.startOffset),T=Math.max(T,O.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:r===o.Direction.LEFT||r===o.Direction.UP?T:v,endOffset:r===o.Direction.LEFT||r===o.Direction.UP?v:T,style:u}]);return}const g=d||m===C.RANGE_DIRECTION.FORWARD?c:l;let h=d||m===C.RANGE_DIRECTION.FORWARD?l:c;const p=(S=n.getBody().dataStream.length)!=null?S:Number.POSITIVE_INFINITY;if(r===o.Direction.LEFT||r===o.Direction.RIGHT){const v=i.findNodeByCharIndex(h-1),T=i.findNodeByCharIndex(h);h=r===o.Direction.RIGHT?h+T.count:h-((f=v==null?void 0:v.count)!=null?f:0),h=Math.min(p-2,Math.max(0,h)),this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:h,style:u}])}else{const v=i.findNodeByCharIndex(h),T=a.document.getOffsetConfig(),O=this._getTopOrBottomPosition(i,v,r===o.Direction.DOWN);if(O==null){const E=r===o.Direction.UP?0:p-2;if(E===h)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:E,style:u}]);return}const R=new C.NodePositionConvertToCursor(T,i).getRangePointData(O,O).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:R.endOffset,style:u}])}}_handleMoveCursor(r){var g,h,p;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),n=this._currentUniverService.getCurrentUniverDocInstance(),i=(g=this._docSkeletonManagerService.getCurrent())==null?void 0:g.skeleton,a=this._getDocObject();if(e==null||i==null||a==null||t==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d}=e,m=(h=n.getBody().dataStream.length)!=null?h:Number.POSITIVE_INFINITY;if(r===o.Direction.LEFT||r===o.Direction.RIGHT){let _;if(!e.collapsed||t.length>1){let S=Number.POSITIVE_INFINITY,f=Number.NEGATIVE_INFINITY;for(const v of t)S=Math.min(S,v.startOffset),f=Math.max(f,v.endOffset);_=r===o.Direction.LEFT?S:f}else{const S=i.findNodeByCharIndex(c-1),f=i.findNodeByCharIndex(c);r===o.Direction.LEFT?_=Math.max(0,c-((p=S==null?void 0:S.count)!=null?p:0)):_=Math.min(m-2,l+f.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:_,endOffset:_,style:u}])}else{const _=i.findNodeByCharIndex(c),S=i.findNodeByCharIndex(l),f=a.document.getOffsetConfig(),v=this._getTopOrBottomPosition(i,r===o.Direction.UP?_:S,r===o.Direction.DOWN);if(v==null){let O;d?O=r===o.Direction.UP?0:m-2:O=r===o.Direction.UP?c:l,this._textSelectionManagerService.replaceTextRanges([{startOffset:O,endOffset:O,style:u}]);return}const T=new C.NodePositionConvertToCursor(f,i).getRangePointData(v,v).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...T,style:u}])}}_getTopOrBottomPosition(r,e,t){if(e==null)return;const n=this._getSpanLeftOffsetInLine(e),i=this._getNextOrPrevLine(e,t);if(i==null)return;const a=this._matchPositionByLeftOffset(r,i,n);if(a!=null)return{...a,isBack:!0}}_getSpanLeftOffsetInLine(r){const e=r.parent;if(e==null)return Number.NEGATIVE_INFINITY;const t=e.left,{left:n}=r;return t+n}_matchPositionByLeftOffset(r,e,t){const n={distance:Number.POSITIVE_INFINITY};for(const i of e.divides){const a=i.left;for(const c of i.spanGroup){const{left:l}=c,u=a+l,d=Math.abs(t-u);d<n.distance&&(n.span=c,n.distance=d)}}if(n.span!=null)return r.findPositionBySpan(n.span)}_getNextOrPrevLine(r,e){var p,_,S,f,v,T,O,R,E,D,x,y;const t=r.parent;if(t==null)return;const n=t.parent;if(n==null)return;const i=n.parent;if(i==null)return;const a=i.lines.indexOf(n);if(a===-1)return;let c;if(e===!0?c=i.lines[a+1]:c=i.lines[a-1],c!=null)return c;const l=i.parent;if(l==null)return;const u=l.columns.indexOf(i);if(u===-1)return;if(e===!0)c=(p=l.columns[u+1])==null?void 0:p.lines[0];else{const M=(S=(_=l.columns)==null?void 0:_[u-1])==null?void 0:S.lines;c=M==null?void 0:M[M.length-1]}if(c!=null)return c;const d=l.parent;if(d==null)return;const m=d.sections.indexOf(l);if(m===-1)return;if(e===!0)c=(v=(f=d.sections[m-1])==null?void 0:f.columns[0])==null?void 0:v.lines[0];else{const M=(O=(T=d.sections)==null?void 0:T[m-1])==null?void 0:O.columns,A=M==null?void 0:M[M.length-1],P=A==null?void 0:A.lines;c=P==null?void 0:P[P.length-1]}if(c!=null)return c;const g=d.parent;if(g==null)return;const h=g.pages.indexOf(d);if(h!==-1){if(e===!0)c=(D=(E=(R=g.pages[h+1])==null?void 0:R.sections[0])==null?void 0:E.columns[0])==null?void 0:D.lines[0];else{const M=(x=g.pages[h-1])==null?void 0:x.sections;if(M==null)return;const A=(y=M[M.length-1])==null?void 0:y.columns,P=A[A.length-1],Ee=P==null?void 0:P.lines;c=Ee[Ee.length-1]}if(c!=null)return c}}_getDocObject(){return pe(this._currentUniverService,this._renderManagerService)}};ce=Lt([o.OnLifecycle(o.LifecycleStages.Rendered,ce),V(0,b.Inject(exports.DocSkeletonManagerService)),V(1,o.IUniverInstanceService),V(2,C.IRenderManagerService),V(3,b.Inject(exports.TextSelectionManagerService)),V(4,o.ICommandService)],ce);var Bt=Object.defineProperty,$t=Object.getOwnPropertyDescriptor,jt=(s,r,e,t)=>{for(var n=t>1?void 0:t?$t(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Bt(r,e,n),n},k=(s,r)=>(e,t)=>r(e,t,s);let le=class extends o.Disposable{constructor(r,e,t,n,i){super();I(this,"_onInputSubscription");this._docSkeletonManagerService=r,this._currentUniverService=e,this._renderManagerService=t,this._textSelectionRenderManager=n,this._commandService=i,this._initialize(),this._commandExecutedListener()}dispose(){var r;(r=this._onInputSubscription)==null||r.unsubscribe()}_initialize(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async r=>{var p;if(r==null)return;const t=this._currentUniverService.getCurrentUniverDocInstance().getUnitId(),{event:n,content:i="",activeRange:a}=r,c=n,l=(p=this._docSkeletonManagerService.getCurrent())==null?void 0:p.skeleton;if(c.data==null||l==null||!l||!a)return;const{startOffset:u,segmentId:d,style:m}=a,g=i.length,h=[{startOffset:u+g,endOffset:u+g,style:m}];await this._commandService.executeCommand(H.id,{unitId:t,body:{dataStream:i},range:a,textRanges:h,segmentId:d})})}_commandExecutedListener(){}_getDocObject(){return pe(this._currentUniverService,this._renderManagerService)}};le=jt([o.OnLifecycle(o.LifecycleStages.Rendered,le),k(0,b.Inject(exports.DocSkeletonManagerService)),k(1,o.IUniverInstanceService),k(2,C.IRenderManagerService),k(3,C.ITextSelectionRenderManager),k(4,o.ICommandService)],le);var Ft=Object.defineProperty,Vt=Object.getOwnPropertyDescriptor,kt=(s,r,e,t)=>{for(var n=t>1?void 0:t?Vt(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Ft(r,e,n),n},we=(s,r)=>(e,t)=>r(e,t,s);const Xt="rgba(198, 198, 198, 1)",zt="rgba(255, 255, 255, 1)";let de=class extends o.Disposable{constructor(s,r){super(),this._renderManagerService=s,this._currentUniverService=r,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh()}_initialRenderRefresh(){this._renderManagerService.currentRender$.subscribe(s=>{var i;if(s==null||this._currentUniverService.getUniverDocInstance(s)==null)return;const r=this._renderManagerService.getRenderById(s);if(r==null)return;const{mainComponent:e}=r,t=e,n=(i=t.getSkeleton())==null?void 0:i.getPageSize();t.onPageRenderObservable.add(a=>{var _,S,f,v;if([o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,o.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(s))return;const{page:c,pageLeft:l,pageTop:u,ctx:d}=a,{width:m,pageWidth:g,height:h,pageHeight:p}=c;d.save(),d.translate(l-.5,u-.5),C.Rect.drawWith(d,{width:(S=(_=n==null?void 0:n.width)!=null?_:g)!=null?S:m,height:(v=(f=n==null?void 0:n.height)!=null?f:p)!=null?v:h,strokeWidth:1,stroke:Xt,fill:zt,zIndex:3}),d.restore()})})}_commandExecutedListener(){}};de=kt([o.OnLifecycle(o.LifecycleStages.Rendered,de),we(0,C.IRenderManagerService),we(1,b.Inject(o.IUniverInstanceService))],de);var Yt=Object.defineProperty,Ht=Object.getOwnPropertyDescriptor,Wt=(s,r,e,t)=>{for(var n=t>1?void 0:t?Ht(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Yt(r,e,n),n},$=(s,r)=>(e,t)=>r(e,t,s);let ue=class extends o.Disposable{constructor(r,e,t,n,i,a){super();I(this,"_moveInObserver");I(this,"_moveOutObserver");I(this,"_downObserver");I(this,"_dblClickObserver");I(this,"_tripleClickObserver");I(this,"_loadedMap",new Set);this._docSkeletonManagerService=r,this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._textSelectionRenderManager=i,this._textSelectionManagerService=a,this._renderManagerService.currentRender$.subscribe(c=>{c!=null&&this._currentUniverService.getUniverDocInstance(c)!=null&&(this._loadedMap.has(c)||(this._initialMain(c),this._loadedMap.add(c)))}),this._initialize()}_initialize(){this._skeletonListener(),this._commandExecutedListener()}dispose(){this._renderManagerService.getRenderAll().forEach(r=>{const{mainComponent:e}=r;e!=null&&(e.onPointerEnterObserver.remove(this._moveInObserver),e.onPointerLeaveObserver.remove(this._moveOutObserver),e.onPointerDownObserver.remove(this._downObserver),e.onDblclickObserver.remove(this._dblClickObserver),e.onTripleClickObserver.remove(this._tripleClickObserver))})}_initialMain(r){const e=this._getDocObjectById(r);if(e==null)return;const{document:t,scene:n}=e;this._moveInObserver=t.onPointerEnterObserver.add(()=>{t.cursor=C.CURSOR_TYPE.TEXT}),this._moveOutObserver=t.onPointerLeaveObserver.add(()=>{t.cursor=C.CURSOR_TYPE.DEFAULT,n.resetCursor()}),this._downObserver=t==null?void 0:t.onPointerDownObserver.add((i,a)=>{this._currentUniverService.getCurrentUniverDocInstance().getUnitId()!==r&&this._currentUniverService.setCurrentUniverDocInstance(r),this._textSelectionRenderManager.eventTrigger(i),i.button!==2&&a.stopPropagation()}),this._dblClickObserver=t==null?void 0:t.onDblclickObserver.add(i=>{this._textSelectionRenderManager.handleDblClick(i)}),this._tripleClickObserver=t==null?void 0:t.onTripleClickObserver.add(i=>{this._textSelectionRenderManager.handleTripleClick(i)})}_commandExecutedListener(){const r=[L.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t;if(r.includes(e.id)){const n=e.params,{unitId:i}=n,a=(t=this._textSelectionManagerService.getCurrentSelection())==null?void 0:t.unitId;if(i!==a)return;this._textSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this._docSkeletonManagerService.currentSkeleton$.subscribe(r=>{if(r==null)return;const{unitId:e,skeleton:t}=r,n=this._renderManagerService.getRenderById(e);if(n==null)return;const{scene:i,mainComponent:a}=n;this._textSelectionRenderManager.changeRuntime(t,i,a),this._textSelectionManagerService.setCurrentSelectionNotRefresh({unitId:e,subUnitId:""})})}_getDocObjectById(r){return Je(r,this._renderManagerService)}};ue=Wt([o.OnLifecycle(o.LifecycleStages.Rendered,ue),$(0,b.Inject(exports.DocSkeletonManagerService)),$(1,o.IUniverInstanceService),$(2,o.ICommandService),$(3,C.IRenderManagerService),$(4,C.ITextSelectionRenderManager),$(5,b.Inject(exports.TextSelectionManagerService))],ue);var Gt=Object.defineProperty,Kt=Object.getOwnPropertyDescriptor,qt=(s,r,e,t)=>{for(var n=t>1?void 0:t?Kt(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Gt(r,e,n),n},X=(s,r)=>(e,t)=>r(e,t,s);let me=class extends o.Disposable{constructor(r,e,t,n,i){super();I(this,"_initializedRender",new Set);this._docSkeletonManagerService=r,this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._textSelectionManagerService=i,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._initialRenderRefresh()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(r=>{if(r==null)return;const{unitId:e}=r,t=this._renderManagerService.getRenderById(e);if(t==null||this._initializedRender.has(e)||[o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,o.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(e))return;this._initializedRender.add(e);const{scene:n}=t;this.disposeWithMe(o.toDisposable(n.onMouseWheelObserver.add(i=>{if(!i.ctrlKey)return;const a=Math.abs(i.deltaX);let c=a<40?.2:a<80?.4:.2;c*=i.deltaY>0?-1:1,n.scaleX<1&&(c/=2);const l=this._currentUniverService.getCurrentUniverDocInstance(),u=l.zoomRatio;let d=+Number.parseFloat(`${u+c}`).toFixed(1);d=d>=4?4:d<=.1?.1:d,this._commandService.executeCommand(Ge.id,{zoomRatio:d,unitId:l.getUnitId()}),i.preventDefault()})))})}_skeletonListener(){this.disposeWithMe(o.toDisposable(this._docSkeletonManagerService.currentSkeletonBefore$.subscribe(r=>{if(r==null)return;const t=this._currentUniverService.getCurrentUniverDocInstance().zoomRatio||1;this._updateViewZoom(t,!1)})))}_commandExecutedListener(){const r=[L.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(r.includes(e.id)){const t=this._currentUniverService.getCurrentUniverDocInstance(),n=e.params,{unitId:i}=n;if(i!==t.getUnitId())return;const a=t.zoomRatio||1;this._updateViewZoom(a)}}))}_updateViewZoom(r,e=!0){var n;const t=this._getDocObject();t!=null&&(t.scene.scale(r,r),this._calculatePagePosition(t,r),e&&this._textSelectionManagerService.refreshSelection(),(n=t.scene.getTransformer())==null||n.hideControl())}_calculatePagePosition(r,e){const{document:t,scene:n}=r,i=n==null?void 0:n.getParent(),{width:a,height:c,pageMarginLeft:l,pageMarginTop:u}=t;if(i==null||a===Number.POSITIVE_INFINITY||c===Number.POSITIVE_INFINITY)return;const{width:d,height:m}=i;let g=0,h=0,p=0,_=0,S=Number.POSITIVE_INFINITY;d>(a+l*2)*e?(g=d/2-a*e/2,g/=e,p=(d-l*2)/e,S=0):(g=l,p=a+l*2,S=(p-d/e)/2),m>c?(h=m/2-c/2,_=(m-u*2)/e):(h=u,_=c+u*2),n.resize(p,_+200),t.translate(g,h);const f=n.getViewport(_e.VIEW_MAIN);if(S!==Number.POSITIVE_INFINITY&&f!=null){const v=f.getBarScroll(S,0).x;f.scrollTo({x:v})}return this}_getDocObject(){return pe(this._currentUniverService,this._renderManagerService)}};me=qt([o.OnLifecycle(o.LifecycleStages.Rendered,me),X(0,b.Inject(exports.DocSkeletonManagerService)),X(1,o.IUniverInstanceService),X(2,o.ICommandService),X(3,C.IRenderManagerService),X(4,b.Inject(exports.TextSelectionManagerService))],me);var Zt=Object.defineProperty,Jt=Object.getOwnPropertyDescriptor,Qt=(s,r,e,t)=>{for(var n=t>1?void 0:t?Jt(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Zt(r,e,n),n},ne=(s,r)=>(e,t)=>r(e,t,s);exports.DocCanvasView=class extends o.RxDisposable{constructor(e,t,n,i){super();I(this,"_scene");I(this,"_currentDocumentModel");I(this,"_loadedMap",new Set);I(this,"_fps$",new N.BehaviorSubject(""));I(this,"fps$",this._fps$.asObservable());this._renderManagerService=e,this._configService=t,this._currentUniverService=n,this._docViewModelManagerService=i,this._initialize()}_initialize(){this._currentUniverService.currentDoc$.pipe(N.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;this._currentDocumentModel=e;const t=e.getUnitId();this._loadedMap.has(t)||(this._addNewRender(),this._loadedMap.add(t))})}dispose(){this._fps$.complete()}_addNewRender(){const e=this._currentDocumentModel,t=e.getUnitId(),n=e.getContainer(),i=e.getParentRenderUnitId();if(n!=null&&i!=null)throw new Error("container or parentRenderUnitId can only exist one");n==null&&i!=null?this._renderManagerService.createRenderWithParent(t,i):this._renderManagerService.createRender(t);const a=this._renderManagerService.getRenderById(t);if(a==null)return;const{scene:c,engine:l}=a;c.openTransformer(),this._scene=c;const u=new C.Viewport(_e.VIEW_MAIN,c,{left:0,top:0,bottom:0,right:0,isWheelPreventDefaultX:!0});c.attachControl(),c.on(C.EVENT_TYPE.wheel,(g,h)=>{const p=g;if(p.ctrlKey){const _=Math.abs(p.deltaX);let S=_<40?.2:_<80?.4:.2;S*=p.deltaY>0?-1:1,c.scaleX<1&&(S/=2),c.scaleX+S>4?c.scale(4,4):c.scaleX+S<.1?c.scale(.1,.1):p.preventDefault()}else u.onMouseWheel(p,h)}),this._configService.getConfig("hasScroll")!==!1&&t!==o.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&new C.ScrollBar(u),c.addLayer(new C.Layer(c,[],Me),new C.Layer(c,[],Le)),this._addComponent(a),this._currentDocumentModel.getShouldRenderLoopImmediately()&&l.runRenderLoop(()=>{c.render(),this._fps$.next(Math.round(l.getFps()).toString())}),this._renderManagerService.setCurrent(t)}_addComponent(e){const t=this._scene,n=this._currentDocumentModel,i=new C.Documents(ge.MAIN,void 0,{pageMarginLeft:n.documentStyle.marginLeft||0,pageMarginTop:n.documentStyle.marginTop||0});i.zIndex=Be,e.mainComponent=i,e.components.set(ge.MAIN,i),t.addObjects([i],Me)}};exports.DocCanvasView=Qt([o.OnLifecycle(o.LifecycleStages.Ready,exports.DocCanvasView),ne(0,C.IRenderManagerService),ne(1,o.IConfigService),ne(2,o.IUniverInstanceService),ne(3,b.Inject(exports.DocViewModelManagerService))],exports.DocCanvasView);var en=Object.defineProperty,tn=Object.getOwnPropertyDescriptor,nn=(s,r,e,t)=>{for(var n=t>1?void 0:t?tn(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&en(r,e,n),n},re=(s,r)=>(e,t)=>r(e,t,s);const rn={hasScroll:!0},on="docs";var Ie;exports.UniverDocsPlugin=(Ie=class extends o.Plugin{constructor(e={},t,n,i,a){super(on);I(this,"_config");this._injector=t,this._localeService=n,this._configService=i,this._currentUniverService=a,this._config=Object.assign(rn,e),this._initializeDependencies(t),this._initializeCommands()}initialize(){}_initializeCommands(){[he,Se,je,Fe,G,K,q,Z,B,J,Q,ee,te,De,$e,H,W,Oe,ye,xe,U,Ye,He,Ge,L,Ce,Ke,ze,Xe,be].forEach(e=>{this._injector.get(o.ICommandService).registerCommand(e)})}onReady(){this.initialize()}_initializeDependencies(e){[[exports.DocCanvasView],[exports.DocSkeletonManagerService],[exports.DocViewModelManagerService],[exports.DocStateChangeManagerService],[Y],[C.ITextSelectionRenderManager,{useClass:C.TextSelectionRenderManager}],[exports.TextSelectionManagerService],[ie],[de],[ue],[le],[se],[ae],[ce],[me],[oe]].forEach(t=>e.add(t))}},I(Ie,"type",o.PluginType.Doc),Ie);exports.UniverDocsPlugin=nn([re(1,b.Inject(b.Injector)),re(2,b.Inject(o.LocaleService)),re(3,o.IConfigService),re(4,o.IUniverInstanceService)],exports.UniverDocsPlugin);exports.BreakLineCommand=$e;exports.BulletListCommand=Xe;exports.CoverContentCommand=He;exports.CutContentCommand=Re;exports.DOCS_COMPONENT_DEFAULT_Z_INDEX=Be;exports.DOCS_COMPONENT_HEADER_LAYER_INDEX=Le;exports.DOCS_COMPONENT_MAIN_LAYER_INDEX=Me;exports.DOCS_VIEW_KEY=ge;exports.DeleteCommand=W;exports.DeleteLeftCommand=je;exports.DeleteRightCommand=Fe;exports.IMEInputCommand=ye;exports.IMEInputManagerService=Y;exports.InnerPasteCommand=St;exports.InsertCommand=H;exports.MoveCursorOperation=he;exports.MoveSelectionOperation=Se;exports.NORMAL_TEXT_SELECTION_PLUGIN_NAME=Qe;exports.OrderListCommand=ze;exports.ReplaceContentCommand=Ye;exports.RichTextEditingMutation=U;exports.SelectAllOperation=Ke;exports.SetInlineFormatBoldCommand=G;exports.SetInlineFormatCommand=De;exports.SetInlineFormatFontFamilyCommand=ee;exports.SetInlineFormatFontSizeCommand=Q;exports.SetInlineFormatItalicCommand=K;exports.SetInlineFormatStrikethroughCommand=Z;exports.SetInlineFormatSubscriptCommand=B;exports.SetInlineFormatSuperscriptCommand=J;exports.SetInlineFormatTextColorCommand=te;exports.SetInlineFormatUnderlineCommand=q;exports.SetTextSelectionsOperation=Ce;exports.UpdateCommand=Oe;exports.VIEWPORT_KEY=_e;exports.getDocObject=pe;exports.serializeTextRange=z;
|
|
1
|
+
"use strict";var $e=Object.defineProperty;var Fe=(s,n,e)=>n in s?$e(s,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[n]=e;var I=(s,n,e)=>(Fe(s,typeof n!="symbol"?n+"":n,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@univerjs/core"),R=require("@univerjs/engine-render"),P=require("rxjs"),E=require("@wendellhu/redi");function ue(s,n){const t=s.getCurrentUniverDocInstance().getUnitId(),r=n.getRenderById(t);if(r==null)return;const{mainComponent:o,scene:a,engine:c}=r;return{document:o,scene:a,engine:c}}function Xe(s,n){const e=n.getRenderById(s);if(e==null)return;const{mainComponent:t,scene:r,engine:o}=e;return{document:t,scene:r,engine:o}}var xe=(s=>(s.MAIN="__Document_Render_Main__",s))(xe||{}),Re=(s=>(s.VIEW_MAIN="viewMain",s.VIEW_TOP="viewTop",s.VIEW_LEFT="viewLeft",s.VIEW_LEFT_TOP="viewLeftTop",s))(Re||{});const je=0,ke=2,Ve=10,ze="normalTextSelectionPluginName",me={id:"doc.operation.set-selections",type:i.CommandType.OPERATION,handler:(s,n)=>!0};var He=Object.defineProperty,Ge=Object.getOwnPropertyDescriptor,We=(s,n,e,t)=>{for(var r=t>1?void 0:t?Ge(n,e):n,o=s.length-1,a;o>=0;o--)(a=s[o])&&(r=(t?a(n,e,r):a(r))||r);return t&&r&&He(n,e,r),r},Me=(s,n)=>(e,t)=>n(e,t,s);function k(s){const{startOffset:n,endOffset:e,collapsed:t}=s,r={startOffset:n,endOffset:e,collapsed:t};return typeof s.isActive=="function"&&(r.isActive=s.isActive()),r}exports.TextSelectionManagerService=class extends i.RxDisposable{constructor(e,t){super();I(this,"_currentSelection",null);I(this,"_textSelectionInfo",new Map);I(this,"_textSelection$",new P.BehaviorSubject(null));I(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:r,style:o}=e,a=t.find(S=>S.isActive());if(a==null)return null;const{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:m,direction:g}=a;return c==null||l==null?null:{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:m,direction:g,segmentId:r,style:o}}add(e,t=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,segmentId:"",isEditing:t,style:R.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e,t=!0){this._currentSelection!=null&&(this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges(e,t))}_syncSelectionFromRenderService(){this._textSelectionRenderManager.textSelectionInner$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._replaceTextRangesWithNoRefresh(e)})}_replaceTextRangesWithNoRefresh(e){if(this._currentSelection==null)return;const t={...this._currentSelection,...e};this._replaceByParam(t),this._textSelection$.next(t);const{unitId:r,subUnitId:o,segmentId:a,style:c,textRanges:l,isEditing:u}=t;this._commandService.executeCommand(me.id,{unitId:r,subUnitId:o,segmentId:a,style:c,isEditing:u,ranges:l.map(k)})}_getTextRanges(e){var o;if(e==null)return;const{unitId:t,subUnitId:r=""}=e;return(o=this._textSelectionInfo.get(t))==null?void 0:o.get(r)}_refresh(e){const t=this._getTextRanges(e);this._textSelectionRenderManager.removeAllTextRanges(),t&&Array.isArray(t.textRanges)&&t.textRanges.length&&this._textSelectionRenderManager.addTextRanges(t.textRanges.map(k))}_replaceByParam(e){const{unitId:t,subUnitId:r,style:o,segmentId:a,textRanges:c,isEditing:l}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(r,{textRanges:c,style:o,segmentId:a,isEditing:l})}_addByParam(e){const{unitId:t,subUnitId:r,textRanges:o,style:a,segmentId:c,isEditing:l}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);const u=this._textSelectionInfo.get(t);u.has(r)?u.get(r).textRanges.push(...o):u.set(r,{textRanges:o,style:a,segmentId:c,isEditing:l})}};exports.TextSelectionManagerService=We([Me(0,R.ITextSelectionRenderManager),Me(1,i.ICommandService)],exports.TextSelectionManagerService);function ge(s,n="",e=0){const{startOffset:t,endOffset:r}=s,o=[],a=t-e,c=r-e;return a>0&&o.push({t:i.TextXActionType.RETAIN,len:a,segmentId:n}),o.push({t:i.TextXActionType.DELETE,len:c-a,line:0,segmentId:n}),o}var Ye=Object.defineProperty,Ze=Object.getOwnPropertyDescriptor,qe=(s,n,e,t)=>{for(var r=t>1?void 0:t?Ze(n,e):n,o=s.length-1,a;o>=0;o--)(a=s[o])&&(r=(t?a(n,e,r):a(r))||r);return t&&r&&Ye(n,e,r),r},Ke=(s,n)=>(e,t)=>n(e,t,s);exports.DocViewModelManagerService=class extends i.RxDisposable{constructor(e){super();I(this,"_docViewModelMap",new Map);I(this,"_currentDocViewModel$",new P.BehaviorSubject(null));I(this,"currentDocViewModel$",this._currentDocViewModel$.asObservable());this._currentUniverService=e,this._initialize()}_initialize(){this._init()}dispose(){this._currentDocViewModel$.complete(),this._docViewModelMap.clear()}_init(){this._currentUniverService.currentDoc$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)}),this._currentUniverService.getAllUniverDocsInstance().forEach(e=>{this._create(e)}),this._currentUniverService.docDisposed$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{this._docViewModelMap.delete(e.getUnitId())})}_create(e){if(e==null)return;const t=e.getUnitId();this._setCurrent(t)}getAllModel(){return this._docViewModelMap}getViewModel(e){var t;return(t=this._docViewModelMap.get(e))==null?void 0:t.docViewModel}_setCurrent(e){var r;const t=this._currentUniverService.getUniverDocInstance(e);if(t==null)throw new Error(`Document data model with id ${e} not found when build view model.`);if(t.getBody()!=null){if(!this._docViewModelMap.has(e)){const o=this._buildDocViewModel(t);this._docViewModelMap.set(e,{unitId:e,docViewModel:o})}if(e===i.DOCS_NORMAL_EDITOR_UNIT_ID_KEY){const o=(r=this._docViewModelMap.get(e))==null?void 0:r.docViewModel;if(o==null)return;o.reset(t)}this._currentDocViewModel$.next(this._docViewModelMap.get(e))}}_buildDocViewModel(e){return new R.DocumentViewModel(e)}};exports.DocViewModelManagerService=qe([Ke(0,i.IUniverInstanceService)],exports.DocViewModelManagerService);var Je=Object.defineProperty,Qe=Object.getOwnPropertyDescriptor,et=(s,n,e,t)=>{for(var r=t>1?void 0:t?Qe(n,e):n,o=s.length-1,a;o>=0;o--)(a=s[o])&&(r=(t?a(n,e,r):a(r))||r);return t&&r&&Je(n,e,r),r},ce=(s,n)=>(e,t)=>n(e,t,s);const tt=300;exports.DocStateChangeManagerService=class extends i.RxDisposable{constructor(e,t,r){super();I(this,"_docStateChange$",new P.BehaviorSubject(null));I(this,"docStateChange$",this._docStateChange$.asObservable());I(this,"_stateCache",new Map);I(this,"_timer",null);this._undoRedoService=e,this._commandService=t,this._univerInstanceService=r,this._initialize()}setChangeState(e){const{trigger:t,noHistory:r}=e;t!=null&&(this._cacheChangeState(e),r||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 r=t.getUnitId();this._pushHistory(r)}}))}_cacheChangeState(e){const{trigger:t,unitId:r,noHistory:o}=e;if(!(t===i.RedoCommandId||t===i.UndoCommandId||o)){if(this._stateCache.has(r)){const a=this._stateCache.get(r);a==null||a.push(e)}else this._stateCache.set(r,[e]);t===z.id||t===H.id?(this._timer&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._pushHistory(r)},tt)):this._pushHistory(r)}}_pushHistory(e){const t=this._undoRedoService,r=this._stateCache.get(e);if(!Array.isArray(r)||r.length===0)return;const o=r.length,a=r[0].commandId,c=r[0],l=r[o-1],u={unitId:e,actions:r.reduce((m,g)=>i.TextX.compose(m,g.redoState.actions),[]),textRanges:l.redoState.textRanges},d={unitId:e,actions:r.reverse().reduce((m,g)=>i.TextX.compose(m,g.undoState.actions),[]),textRanges:c.undoState.textRanges};t.pushUndoRedo({unitID:e,undoMutations:[{id:a,params:d}],redoMutations:[{id:a,params:u}]}),r.length=0}};exports.DocStateChangeManagerService=et([ce(0,E.Inject(i.IUndoRedoService)),ce(1,i.ICommandService),ce(2,i.IUniverInstanceService)],exports.DocStateChangeManagerService);class V{constructor(){I(this,"_previousActiveRange",null);I(this,"_undoMutationParamsCache",[]);I(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((r,o)=>i.TextX.compose(r,o.actions),[]),textRanges:[]};return{redoMutationParams:{unitId:n,actions:this._redoMutationParamsCache.reduce((r,o)=>i.TextX.compose(r,o.actions),[]),textRanges:[]},undoMutationParams:e,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Ce="doc.mutation.rich-text-editing",b={id:Ce,type:i.CommandType.MUTATION,handler:(s,n)=>{var y;const{unitId:e,actions:t,textRanges:r,prevTextRanges:o,trigger:a,noHistory:c,isCompositionEnd:l,noNeedSetTextRange:u}=n,m=s.get(i.IUniverInstanceService).getUniverDocInstance(e),S=s.get(exports.DocViewModelManagerService).getViewModel(e),v=s.get(exports.TextSelectionManagerService),h=((y=v.getSelections())!=null?y:[]).map(k),_=s.get(exports.DocStateChangeManagerService),f=s.get(V);if(m==null||S==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);if(t.length===0)return{unitId:e,actions:[],textRanges:h};const C=m.apply(t),{segmentId:T}=t[0],x=m.getSelfOrHeaderFooterModel(T);S.getSelfOrHeaderFooterViewModel(T).reset(x),!u&&r&&a!=null&&queueMicrotask(()=>{v.replaceTextRanges(r)});const D={commandId:Ce,unitId:e,trigger:a,noHistory:c,redoState:{actions:t,textRanges:r},undoState:{actions:C,textRanges:o!=null?o:h}};if(l){const O=f.fetchComposedUndoRedoMutationParams();if(O==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:M,redoMutationParams:N,previousActiveRange:A}=O;D.redoState.actions=N.actions,D.undoState.actions=M.actions,D.undoState.textRanges=[A]}return _.setChangeState(D),{unitId:e,actions:C,textRanges:h}}},z={id:"doc.command.insert-text",type:i.CommandType.COMMAND,handler:async(s,n)=>{const e=s.get(i.ICommandService),{range:t,segmentId:r,body:o,unitId:a,textRanges:c}=n,{startOffset:l,collapsed:u}=t,d={id:b.id,params:{unitId:a,actions:[],textRanges:c}},m=new i.TextX;return u?l>0&&m.push({t:i.TextXActionType.RETAIN,len:l,segmentId:r}):m.push(...ge(t,r)),m.push({t:i.TextXActionType.INSERT,body:o,len:o.dataStream.length,line:0,segmentId:r}),d.params.actions=m.serialize(),!!e.syncExecuteCommand(d.id,d.params)}};var w=(s=>(s[s.LEFT=0]="LEFT",s[s.RIGHT=1]="RIGHT",s))(w||{});const H={id:"doc.command.delete-text",type:i.CommandType.COMMAND,handler:async(s,n)=>{const e=s.get(i.ICommandService),{range:t,segmentId:r,unitId:o,direction:a,textRanges:c,len:l=1}=n,{startOffset:u}=t,d={id:b.id,params:{unitId:o,actions:[],textRanges:c}},m=new i.TextX;return u>0&&m.push({t:i.TextXActionType.RETAIN,len:a===0?u-l:u,segmentId:r}),m.push({t:i.TextXActionType.DELETE,len:l,line:0,segmentId:r}),d.params.actions=m.serialize(),!!e.syncExecuteCommand(d.id,d.params)}},Se={id:"doc.command.update-text",type:i.CommandType.COMMAND,handler:async(s,n)=>{const{range:e,segmentId:t,updateBody:r,coverType:o,unitId:a,textRanges:c}=n,l=s.get(i.ICommandService),u={id:b.id,params:{unitId:a,actions:[],textRanges:c}},d=new i.TextX,{startOffset:m,endOffset:g}=e;return d.push({t:i.TextXActionType.RETAIN,len:m,segmentId:t}),d.push({t:i.TextXActionType.RETAIN,body:r,len:g-m,segmentId:t,coverType:o}),u.params.actions=d.serialize(),!!l.syncExecuteCommand(u.id,u.params)}};function nt(s,n){const e=[];for(let t=0,r=s.length;t<r;t++)s[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 ye={id:"doc.command.break-line",type:i.CommandType.COMMAND,handler:async s=>{var v,p;const n=s.get(exports.TextSelectionManagerService),e=s.get(i.IUniverInstanceService),t=s.get(i.ICommandService),r=n.getActiveRange();if(r==null)return!1;const o=e.getCurrentUniverDocInstance(),a=o.getUnitId(),{startOffset:c,segmentId:l,style:u}=r,d=[{startOffset:c+1,endOffset:c+1,style:u}],g=((p=(v=o.getBody())==null?void 0:v.paragraphs)!=null?p:[]).find(h=>h.startIndex>=c);return await t.executeCommand(z.id,{unitId:a,body:{dataStream:i.DataStreamTreeTokenType.PARAGRAPH,paragraphs:nt(i.DataStreamTreeTokenType.PARAGRAPH,g)},range:r,textRanges:d,segmentId:l})}};var rt=Object.defineProperty,it=Object.getOwnPropertyDescriptor,ot=(s,n,e,t)=>{for(var r=t>1?void 0:t?it(n,e):n,o=s.length-1,a;o>=0;o--)(a=s[o])&&(r=(t?a(n,e,r):a(r))||r);return t&&r&&rt(n,e,r),r},le=(s,n)=>(e,t)=>n(e,t,s);exports.DocSkeletonManagerService=class extends i.RxDisposable{constructor(e,t,r){super();I(this,"_currentSkeletonUnitId","");I(this,"_docSkeletonMap",new Map);I(this,"_currentSkeleton$",new P.BehaviorSubject(null));I(this,"currentSkeleton$",this._currentSkeleton$.asObservable());I(this,"_currentSkeletonBefore$",new P.BehaviorSubject(null));I(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._localeService=e,this._docViewModelManagerService=t,this._currentUniverService=r,this._initialize()}_initialize(){this._init()}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._docSkeletonMap.clear()}_init(){this._docViewModelManagerService.currentDocViewModel$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._setCurrent(e)}),this._docViewModelManagerService.getAllModel().forEach(e=>{e!=null&&this._setCurrent(e)}),this._currentUniverService.docDisposed$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{this._docSkeletonMap.delete(e.getUnitId()),this._currentSkeletonUnitId=this._currentUniverService.getCurrentUniverDocInstance().getUnitId()})}getCurrent(){return this.getSkeletonByUnitId(this._currentSkeletonUnitId)}getAllSkeleton(){return this._docSkeletonMap}makeDirtyCurrent(e=!0){this.makeDirty(this._currentSkeletonUnitId,e)}makeDirty(e,t=!0){const r=this.getSkeletonByUnitId(e);r!=null&&(r.dirty=t)}getSkeletonByUnitId(e){return this._docSkeletonMap.get(e)}_setCurrent(e){const{unitId:t}=e;if(this._docSkeletonMap.has(t)){const r=this.getSkeletonByUnitId(t);r.skeleton.calculate(),r.dirty=!0}else{const r=this._buildSkeleton(e.docViewModel);r.calculate(),this._docSkeletonMap.set(t,{unitId:t,skeleton:r,dirty:!1})}return this._currentSkeletonUnitId=t,this._currentSkeletonBefore$.next(this.getCurrent()),this._currentSkeleton$.next(this.getCurrent()),this.getCurrent()}_buildSkeleton(e){return R.DocumentSkeleton.create(e,this._localeService)}};exports.DocSkeletonManagerService=ot([le(0,E.Inject(i.LocaleService)),le(1,E.Inject(exports.DocViewModelManagerService)),le(2,i.IUniverInstanceService)],exports.DocSkeletonManagerService);const st={id:"doc.command.inner-paste",type:i.CommandType.COMMAND,handler:async(s,n)=>{const{segmentId:e,body:t,textRanges:r}=n,o=s.get(i.ICommandService),a=s.get(exports.TextSelectionManagerService),c=s.get(i.IUniverInstanceService),l=a.getSelections();if(!Array.isArray(l)||l.length===0)return!1;const d=c.getCurrentUniverDocInstance().getUnitId(),m={id:b.id,params:{unitId:d,actions:[],textRanges:r}},g=new i.MemoryCursor;g.reset();const S=new i.TextX;for(const p of l){const{startOffset:h,endOffset:_,collapsed:f}=p,C=h-g.cursor;f?S.push({t:i.TextXActionType.RETAIN,len:C,segmentId:e}):S.push(...ge(p,e,g.cursor)),S.push({t:i.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:e}),g.reset(),g.moveCursor(_)}return m.params.actions=S.serialize(),!!o.syncExecuteCommand(m.id,m.params)}},he={id:"doc.command.inner-cut",type:i.CommandType.COMMAND,handler:async(s,n)=>{const{segmentId:e,textRanges:t}=n,r=s.get(i.ICommandService),o=s.get(exports.TextSelectionManagerService),a=s.get(i.IUniverInstanceService),c=o.getSelections();if(!Array.isArray(c)||c.length===0)return!1;const l=a.getCurrentUniverDocInstance().getUnitId(),u=a.getUniverDocInstance(l),d=i.getDocsUpdateBody(u.snapshot,e);if(d==null)return!1;const m={id:b.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:h,endOffset:_,collapsed:f}=p,C=h-g.cursor;f?S.push({t:i.TextXActionType.RETAIN,len:C,segmentId:e}):S.push(...at(p,d,e,g.cursor)),g.reset(),g.moveCursor(_)}return m.params.actions=S.serialize(),!!r.syncExecuteCommand(m.id,m.params)}};function at(s,n,e="",t=0){const{startOffset:r,endOffset:o}=s,a=[],{paragraphs:c=[]}=n,l=r-t,u=o-t,d=c==null?void 0:c.find(m=>m.startIndex-t>=l&&m.startIndex-t<=u);if(l>0&&a.push({t:i.TextXActionType.RETAIN,len:l,segmentId:e}),d&&d.startIndex-t>l){const m=d.startIndex-t;a.push({t:i.TextXActionType.DELETE,len:m-l,line:0,segmentId:e}),a.push({t:i.TextXActionType.RETAIN,len:1,segmentId:e}),u>m+1&&a.push({t:i.TextXActionType.DELETE,len:u-m-1,line:0,segmentId:e})}else a.push({t:i.TextXActionType.DELETE,len:u-l,line:0,segmentId:e});return a}const Oe={id:"doc.command.delete-left",type:i.CommandType.COMMAND,handler:async s=>{var T;const n=s.get(exports.TextSelectionManagerService),e=s.get(exports.DocSkeletonManagerService),t=s.get(i.IUniverInstanceService),r=s.get(i.ICommandService),o=n.getActiveRange(),a=n.getSelections(),c=(T=e.getCurrent())==null?void 0:T.skeleton;let l=!0;if(o==null||c==null||a==null)return!1;const u=t.getCurrentUniverDocInstance(),{startOffset:d,collapsed:m,segmentId:g,style:S}=o,v=c.findNodeByCharIndex(d),p=R.hasListSpan(v),h=R.isIndentBySpan(v,u.getBody());let _=d;const f=c.findNodeByCharIndex(d-1);if(R.isFirstSpan(v)&&f!==v&&(p===!0||h===!0)){const x=R.getParagraphBySpan(v,u.getBody());if(x==null)return!1;const U=x==null?void 0:x.startIndex,D={startIndex:0},y=x.paragraphStyle;if(p===!0){const M=x.paragraphStyle;M&&(D.paragraphStyle=M)}else if(h===!0){const M=x.bullet;M&&(D.bullet=M),y!=null&&(D.paragraphStyle={...y},delete D.paragraphStyle.hanging,delete D.paragraphStyle.indentStart)}const O=[{startOffset:_,endOffset:_,style:S}];l=await r.executeCommand(Se.id,{unitId:u.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...D}]},range:{startOffset:U,endOffset:U+1},textRanges:O,coverType:i.UpdateDocsAttributeType.REPLACE,segmentId:g})}else if(m===!0){if(f==null)return!0;if(f.content==="\r")l=await r.executeCommand(pe.id,{direction:w.LEFT,range:o});else{_-=f.count;const x=[{startOffset:_,endOffset:_,style:S}];l=await r.executeCommand(H.id,{unitId:u.getUnitId(),range:o,segmentId:g,direction:w.LEFT,len:f.count,textRanges:x})}}else{const x=Ee(o,a);l=await r.executeCommand(he.id,{segmentId:g,textRanges:x})}return l}},De={id:"doc.command.delete-right",type:i.CommandType.COMMAND,handler:async s=>{var v;const n=s.get(exports.TextSelectionManagerService),e=s.get(exports.DocSkeletonManagerService),t=s.get(i.IUniverInstanceService),r=s.get(i.ICommandService),o=n.getActiveRange(),a=n.getSelections(),c=(v=e.getCurrent())==null?void 0:v.skeleton;let l;if(o==null||c==null||a==null)return!1;const u=t.getCurrentUniverDocInstance(),{startOffset:d,collapsed:m,segmentId:g,style:S}=o;if(d===u.getBody().dataStream.length-2&&m)return!0;if(m===!0){const p=c.findNodeByCharIndex(d);if(p.content==="\r")l=await r.executeCommand(pe.id,{direction:w.RIGHT,range:o});else{const h=[{startOffset:d,endOffset:d,style:S}];l=await r.executeCommand(H.id,{unitId:u.getUnitId(),range:o,segmentId:g,direction:w.RIGHT,textRanges:h,len:p.count})}}else{const p=Ee(o,a);l=await r.executeCommand(he.id,{segmentId:g,textRanges:p})}return l}},pe={id:"doc.command.merge-two-paragraph",type:i.CommandType.COMMAND,handler:async(s,n)=>{var D,y,O;const e=s.get(exports.TextSelectionManagerService),t=s.get(i.IUniverInstanceService),r=s.get(i.ICommandService);s.get(i.IUndoRedoService);const{direction:o,range:a}=n,c=e.getActiveRange(),l=e.getSelections();if(c==null||l==null)return!1;const u=t.getCurrentUniverDocInstance(),{startOffset:d,collapsed:m,segmentId:g,style:S}=c;if(!m)return!1;const v=o===w.LEFT?d:d+1,p=(O=(y=(D=u.getBody())==null?void 0:D.paragraphs)==null?void 0:y.find(M=>M.startIndex>=v))==null?void 0:O.startIndex,h=ct(u.getBody(),v,p),_=o===w.LEFT?d-1:d,f=u.getUnitId(),C=[{startOffset:_,endOffset:_,style:S}],T={id:b.id,params:{unitId:f,actions:[],textRanges:C,prevTextRanges:[a]}},x=new i.TextX;return x.push({t:i.TextXActionType.RETAIN,len:o===w.LEFT?d-1:d,segmentId:g}),h.dataStream.length&&x.push({t:i.TextXActionType.INSERT,body:h,len:h.dataStream.length,line:0,segmentId:g}),x.push({t:i.TextXActionType.RETAIN,len:1,segmentId:g}),x.push({t:i.TextXActionType.DELETE,len:p+1-v,line:0,segmentId:g}),T.params.actions=x.serialize(),!!r.syncExecuteCommand(T.id,T.params)}};function ct(s,n,e){const{textRuns:t}=s,r=s.dataStream.substring(n,e);if(t==null)return{dataStream:r};const o=[];for(const a of t){const{st:c,ed:l}=a;l<=n||c>=e||(c<n?o.push({...a,st:0,ed:l-n}):l>e?o.push({...a,st:c-n,ed:e-n}):o.push({...a,st:c-n,ed:l-n}))}return{dataStream:r,textRuns:o}}function Ee(s,n){let e=s.endOffset;for(const r of n){const{startOffset:o,endOffset:a}=r;o==null||a==null||a<=s.endOffset&&(e-=a-o)}return[{startOffset:e,endOffset:e,style:s.style}]}const fe={id:"doc.command.ime-input",type:i.CommandType.COMMAND,handler:async(s,n)=>{const{unitId:e,newText:t,oldTextLen:r,isCompositionEnd:o,isCompositionStart:a}=n,c=s.get(i.ICommandService),l=s.get(V),u=l.getActiveRange();if(u==null)return!1;const{startOffset:d,style:m,segmentId:g}=u,S=t.length,v=[{startOffset:d+S,endOffset:d+S,collapsed:!0,style:m}],p={id:b.id,params:{unitId:e,actions:[],textRanges:v}},h=new i.TextX;!u.collapsed&&a?h.push(...ge(u,g)):h.push({t:i.TextXActionType.RETAIN,len:d,segmentId:g}),r>0&&h.push({t:i.TextXActionType.DELETE,len:r,line:0,segmentId:g}),h.push({t:i.TextXActionType.INSERT,body:{dataStream:t},len:t.length,line:0,segmentId:g}),p.params.actions=h.serialize(),p.params.noHistory=!o,p.params.isCompositionEnd=o;const _=c.syncExecuteCommand(p.id,p.params);return l.pushUndoRedoMutationParams(_,p.params),!!_}},G={id:"doc.command.set-inline-format-bold",type:i.CommandType.COMMAND,handler:async()=>!0},W={id:"doc.command.set-inline-format-italic",type:i.CommandType.COMMAND,handler:async()=>!0},Y={id:"doc.command.set-inline-format-underline",type:i.CommandType.COMMAND,handler:async()=>!0},Z={id:"doc.command.set-inline-format-strikethrough",type:i.CommandType.COMMAND,handler:async()=>!0},L={id:"doc.command.set-inline-format-subscript",type:i.CommandType.COMMAND,handler:async()=>!0},q={id:"doc.command.set-inline-format-superscript",type:i.CommandType.COMMAND,handler:async()=>!0},K={id:"doc.command.set-inline-format-fontsize",type:i.CommandType.COMMAND,handler:async()=>!0},J={id:"doc.command.set-inline-format-font-family",type:i.CommandType.COMMAND,handler:async()=>!0},Q={id:"doc.command.set-inline-format-text-color",type:i.CommandType.COMMAND,handler:async()=>!0},Ue={[G.id]:"bl",[W.id]:"it",[Y.id]:"ul",[Z.id]:"st",[K.id]:"fs",[J.id]:"ff",[Q.id]:"cl",[L.id]:"va",[q.id]:"va"},ve={id:"doc.command.set-inline-format",type:i.CommandType.COMMAND,handler:async(s,n)=>{const{segmentId:e,value:t,preCommandId:r}=n,o=s.get(i.ICommandService),a=s.get(exports.TextSelectionManagerService),c=s.get(i.IUniverInstanceService),l=a.getSelections();if(!Array.isArray(l)||l.length===0)return!1;let u=c.getCurrentUniverDocInstance(),d=u.getUnitId();d===i.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(u=c.getUniverDocInstance(i.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),d=u.getUnitId());let m;switch(r){case G.id:case W.id:case Y.id:case Z.id:case L.id:case q.id:{m=dt(u.getBody().textRuns,r,l);break}case K.id:case J.id:{m=t;break}case Q.id:{m={rgb:t};break}default:throw new Error(`Unknown command: ${r} in handleInlineFormat`)}const g={id:b.id,params:{unitId:d,actions:[],textRanges:l}},S=new i.TextX,v=new i.MemoryCursor;v.reset();for(const h of l){const{startOffset:_,endOffset:f}=h,C={dataStream:"",textRuns:[{st:0,ed:f-_,ts:{[Ue[r]]:m}}]},T=_-v.cursor;T!==0&&S.push({t:i.TextXActionType.RETAIN,len:T,segmentId:e}),S.push({t:i.TextXActionType.RETAIN,body:C,len:f-_,segmentId:e}),v.reset(),v.moveCursor(f)}return g.params.actions=S.serialize(),!!o.syncExecuteCommand(g.id,g.params)}};function lt(s){return s!==null&&typeof s=="object"}function dt(s,n,e){let t=0,r=0;const o=Ue[n];for(;t!==s.length&&r!==e.length;){const{startOffset:a,endOffset:c}=e[r],{st:l,ed:u,ts:d}=s[t];if(c<=l)r++;else if(u<=a)t++;else{if(/bl|it/.test(o))return(d==null?void 0:d[o])===i.BooleanNumber.TRUE?i.BooleanNumber.FALSE:i.BooleanNumber.TRUE;if(/ul|st/.test(o))return lt(d==null?void 0:d[o])&&(d==null?void 0:d[o]).s===i.BooleanNumber.TRUE?{s:i.BooleanNumber.FALSE}:{s:i.BooleanNumber.TRUE};if(/va/.test(o))return n===L.id?(d==null?void 0:d[o])===i.BaselineOffset.SUBSCRIPT?i.BaselineOffset.NORMAL:i.BaselineOffset.SUBSCRIPT:(d==null?void 0:d[o])===i.BaselineOffset.SUPERSCRIPT?i.BaselineOffset.NORMAL:i.BaselineOffset.SUPERSCRIPT;t++}}return/bl|it/.test(o)?i.BooleanNumber.TRUE:/ul|st/.test(o)?{s:i.BooleanNumber.TRUE}:n===L.id?i.BaselineOffset.SUBSCRIPT:i.BaselineOffset.SUPERSCRIPT}const _e={id:"doc.command.list-operation",type:i.CommandType.COMMAND,handler:(s,n)=>{var x,U,D;const e=s.get(exports.TextSelectionManagerService),t=s.get(i.IUniverInstanceService),r=s.get(i.ICommandService),{listType:o}=n,a=t.getCurrentUniverDocInstance(),c=e.getActiveRange(),l=(x=e.getSelections())!=null?x:[],u=(U=a.getBody())==null?void 0:U.paragraphs,d=l.map(k);if(c==null||u==null)return!1;const m=ut(c,u),{segmentId:g}=c,S=a.getUnitId(),v=m.every(y=>{var O;return((O=y.bullet)==null?void 0:O.listType)===o});let h=i.Tools.generateRandomId(6);if(m.length===1){const y=u.indexOf(m[0]),O=u[y-1],M=u[y+1];O&&O.bullet&&O.bullet.listType===o?h=O.bullet.listId:M&&M.bullet&&M.bullet.listType===o&&(h=M.bullet.listId)}const _={id:b.id,params:{unitId:S,actions:[],textRanges:d}},f=new i.MemoryCursor;f.reset();const C=new i.TextX;for(const y of m){const{startIndex:O}=y;C.push({t:i.TextXActionType.RETAIN,len:O-f.cursor,segmentId:g});const M={...y.paragraphStyle,hanging:void 0,indentStart:void 0};C.push({t:i.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[v?{paragraphStyle:M,startIndex:0}:{...y,startIndex:0,bullet:{...(D=y.bullet)!=null?D:{nestingLevel:0,textStyle:{fs:20}},listType:o,listId:h}}]},segmentId:g,coverType:i.UpdateDocsAttributeType.REPLACE}),f.moveCursorTo(O+1)}return _.params.actions=C.serialize(),!!r.syncExecuteCommand(_.id,_.params)}},be={id:"doc.command.bullet-list",type:i.CommandType.COMMAND,handler:s=>s.get(i.ICommandService).syncExecuteCommand(_e.id,{listType:i.PresetListType.BULLET_LIST})},Ae={id:"doc.command.order-list",type:i.CommandType.COMMAND,handler:s=>s.get(i.ICommandService).syncExecuteCommand(_e.id,{listType:i.PresetListType.ORDER_LIST})};function ut(s,n){const{startOffset:e,endOffset:t}=s,r=[];let o=-1;for(const a of n){const{startIndex:c}=a;(e>o&&e<=c||t>o&&t<=c||c>=e&&c<=t)&&r.push(a),o=c}return r}const Pe={id:"doc.command-replace-content",type:i.CommandType.COMMAND,handler:async(s,n)=>{var S;const{unitId:e,body:t,textRanges:r,segmentId:o=""}=n,a=s.get(i.IUniverInstanceService),c=s.get(i.ICommandService),l=s.get(exports.TextSelectionManagerService),u=(S=a.getUniverDocInstance(e))==null?void 0:S.getSnapshot().body,d=l.getSelections();if(u==null||!Array.isArray(d)||d.length===0)return!1;const m=we(e,o,u,t);return m.params.textRanges=r,!!c.syncExecuteCommand(m.id,m.params)}},Ne={id:"doc.command-cover-content",type:i.CommandType.COMMAND,handler:async(s,n)=>{var d;const{unitId:e,body:t,segmentId:r=""}=n,o=s.get(i.IUniverInstanceService),a=s.get(i.ICommandService),c=s.get(i.IUndoRedoService),l=(d=o.getUniverDocInstance(e))==null?void 0:d.getSnapshot().body;if(l==null)return!1;const u=we(e,r,l,t);return u.params.noNeedSetTextRange=!0,u.params.noHistory=!0,a.syncExecuteCommand(u.id,u.params),c.clearUndoRedo(e),!0}};function we(s,n,e,t){const r={id:b.id,params:{unitId:s,actions:[],textRanges:[]}},o=new i.TextX,a=(e==null?void 0:e.dataStream.length)-2;return a>0&&o.push({t:i.TextXActionType.DELETE,len:a,line:0,segmentId:n}),t.dataStream.length>0&&o.push({t:i.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:n}),r.params.actions=o.serialize(),r}const se={id:"doc.operation.move-cursor",type:i.CommandType.OPERATION,handler:(s,n)=>!!n},ae={id:"doc.operation.move-selection",type:i.CommandType.OPERATION,handler:(s,n)=>!!n},mt=(s,n)=>{const e=s.get(i.IUniverInstanceService).getUniverDocInstance(n.unitId),t=(e==null?void 0:e.zoomRatio)||1;return{...i.Tools.deepClone(n),zoomRatio:t}},$={id:"doc.operation.set-zoom-ratio",type:i.CommandType.OPERATION,handler:(s,n)=>{const e=s.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}},Le={type:i.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(s,n)=>{var m,g;const e=s.get(i.ICommandService),t=s.get(i.IUndoRedoService),r=s.get(i.IUniverInstanceService);let o=r.getCurrentUniverDocInstance().getUnitId(),a=1;if(n&&(o=(m=n.documentId)!=null?m:o,a=(g=n.zoomRatio)!=null?g:a),!r.getUniverDocInstance(o))return!1;const l={zoomRatio:a,unitId:o},u=mt(s,l);return e.syncExecuteCommand($.id,l)?(t.pushUndoRedo({unitID:o,undoMutations:[{id:$.id,params:u}],redoMutations:[{id:$.id,params:l}]}),!0):!1}},Be={id:"doc.operation.select-all",type:i.CommandType.COMMAND,handler:async s=>{const n=s.get(i.IUniverInstanceService),e=s.get(exports.TextSelectionManagerService),t=n.getCurrentUniverDocInstance().getSnapshot().body;if(t==null)return!1;const r=[{startOffset:0,endOffset:t.dataStream.length-2}];return e.replaceTextRanges(r,!1),!0}};var gt=Object.defineProperty,St=Object.getOwnPropertyDescriptor,ht=(s,n,e,t)=>{for(var r=t>1?void 0:t?St(n,e):n,o=s.length-1,a;o>=0;o--)(a=s[o])&&(r=(t?a(n,e,r):a(r))||r);return t&&r&>(n,e,r),r},F=(s,n)=>(e,t)=>n(e,t,s);let te=class extends i.Disposable{constructor(n,e,t,r,o){super();I(this,"_previousIMEContent","");I(this,"_isCompositionStart",!0);I(this,"_onStartSubscription");I(this,"_onUpdateSubscription");I(this,"_onEndSubscription");this._docSkeletonManagerService=n,this._currentUniverService=e,this._textSelectionRenderManager=t,this._imeInputManagerService=r,this._commandService=o,this._initialize()}dispose(){var n,e,t;(n=this._onStartSubscription)==null||n.unsubscribe(),(e=this._onUpdateSubscription)==null||e.unsubscribe(),(t=this._onEndSubscription)==null||t.unsubscribe()}_initialize(){this._initialOnCompositionstart(),this._initialOnCompositionUpdate(),this._initialOnCompositionend()}_initialOnCompositionstart(){this._onStartSubscription=this._textSelectionRenderManager.onCompositionstart$.subscribe(n=>{if(n==null)return;const{activeRange:e}=n;e!=null&&(this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(i.Tools.deepClone(e)),this._isCompositionStart=!0)})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._textSelectionRenderManager.onCompositionupdate$.subscribe(async n=>{this._updateContent(n,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._textSelectionRenderManager.onCompositionend$.subscribe(n=>{this._updateContent(n,!1)})}async _updateContent(n,e){var u;const t=(u=this._docSkeletonManagerService.getCurrent())==null?void 0:u.skeleton;if(n==null||t==null)return;const r=this._currentUniverService.getCurrentUniverDocInstance(),{event:o,activeRange:a}=n;if(t==null||a==null)return;const l=o.data;l===this._previousIMEContent&&e||(await this._commandService.executeCommand(fe.id,{unitId:r.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)}};te=ht([i.OnLifecycle(i.LifecycleStages.Rendered,te),F(0,E.Inject(exports.DocSkeletonManagerService)),F(1,i.IUniverInstanceService),F(2,R.ITextSelectionRenderManager),F(3,E.Inject(V)),F(4,i.ICommandService)],te);var pt=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,vt=(s,n,e,t)=>{for(var r=t>1?void 0:t?ft(n,e):n,o=s.length-1,a;o>=0;o--)(a=s[o])&&(r=(t?a(n,e,r):a(r))||r);return t&&r&&pt(n,e,r),r},Te=(s,n)=>(e,t)=>n(e,t,s);let ne=class extends i.Disposable{constructor(s,n){super(),this._textSelectionManagerService=s,this._commandService=n,this._commandExecutedListener()}_commandExecutedListener(){const s=[G.id,W.id,Y.id,Z.id,L.id,q.id,K.id,J.id,Q.id];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{s.includes(n.id)&&this._handleInlineFormat(n)}))}_handleInlineFormat(s){var e,t;const{segmentId:n}=(e=this._textSelectionManagerService.getActiveRange())!=null?e:{};n!=null&&this._commandService.executeCommand(ve.id,{segmentId:n,preCommandId:s.id,...(t=s.params)!=null?t:{}})}};ne=vt([i.OnLifecycle(i.LifecycleStages.Rendered,ne),Te(0,E.Inject(exports.TextSelectionManagerService)),Te(1,i.ICommandService)],ne);var _t=Object.defineProperty,It=Object.getOwnPropertyDescriptor,Mt=(s,n,e,t)=>{for(var r=t>1?void 0:t?It(n,e):n,o=s.length-1,a;o>=0;o--)(a=s[o])&&(r=(t?a(n,e,r):a(r))||r);return t&&r&&_t(n,e,r),r},X=(s,n)=>(e,t)=>n(e,t,s);let re=class extends i.Disposable{constructor(n,e,t,r,o){super();I(this,"_onInputSubscription");this._docSkeletonManagerService=n,this._currentUniverService=e,this._renderManagerService=t,this._textSelectionManagerService=r,this._commandService=o,this._initialize(),this._commandExecutedListener()}dispose(){var n;(n=this._onInputSubscription)==null||n.unsubscribe()}_initialize(){}_commandExecutedListener(){const n=[se.id,ae.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!n.includes(e.id))return;const t=e.params;switch(e.id){case se.id:return this._handleMoveCursor(t.direction);case ae.id:return this._handleShiftMoveSelection(t.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(n){var p,h,_;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),r=this._currentUniverService.getCurrentUniverDocInstance(),o=(p=this._docSkeletonManagerService.getCurrent())==null?void 0:p.skeleton,a=this._getDocObject();if(e==null||o==null||a==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d,direction:m}=e;if(t.length>1){let f=Number.POSITIVE_INFINITY,C=Number.NEGATIVE_INFINITY;for(const T of t)f=Math.min(f,T.startOffset),C=Math.max(C,T.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:n===i.Direction.LEFT||n===i.Direction.UP?C:f,endOffset:n===i.Direction.LEFT||n===i.Direction.UP?f:C,style:u}],!1);return}const g=d||m===R.RANGE_DIRECTION.FORWARD?c:l;let S=d||m===R.RANGE_DIRECTION.FORWARD?l:c;const v=(h=r.getBody().dataStream.length)!=null?h:Number.POSITIVE_INFINITY;if(n===i.Direction.LEFT||n===i.Direction.RIGHT){const f=o.findNodeByCharIndex(S-1),C=o.findNodeByCharIndex(S);S=n===i.Direction.RIGHT?S+C.count:S-((_=f==null?void 0:f.count)!=null?_:0),S=Math.min(v-2,Math.max(0,S)),this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:S,style:u}],!1)}else{const f=o.findNodeByCharIndex(S),C=a.document.getOffsetConfig(),T=this._getTopOrBottomPosition(o,f,n===i.Direction.DOWN);if(T==null){const U=n===i.Direction.UP?0:v-2;if(U===S)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:U,style:u}],!1);return}const x=new R.NodePositionConvertToCursor(C,o).getRangePointData(T,T).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:x.endOffset,style:u}],!1)}}_handleMoveCursor(n){var g,S,v;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),r=this._currentUniverService.getCurrentUniverDocInstance(),o=(g=this._docSkeletonManagerService.getCurrent())==null?void 0:g.skeleton,a=this._getDocObject();if(e==null||o==null||a==null||t==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d}=e,m=(S=r.getBody().dataStream.length)!=null?S:Number.POSITIVE_INFINITY;if(n===i.Direction.LEFT||n===i.Direction.RIGHT){let p;if(!e.collapsed||t.length>1){let h=Number.POSITIVE_INFINITY,_=Number.NEGATIVE_INFINITY;for(const f of t)h=Math.min(h,f.startOffset),_=Math.max(_,f.endOffset);p=n===i.Direction.LEFT?h:_}else{const h=o.findNodeByCharIndex(c-1),_=o.findNodeByCharIndex(c);n===i.Direction.LEFT?p=Math.max(0,c-((v=h==null?void 0:h.count)!=null?v:0)):p=Math.min(m-2,l+_.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:p,style:u}],!1)}else{const p=o.findNodeByCharIndex(c),h=o.findNodeByCharIndex(l),_=a.document.getOffsetConfig(),f=this._getTopOrBottomPosition(o,n===i.Direction.UP?p:h,n===i.Direction.DOWN);if(f==null){let T;d?T=n===i.Direction.UP?0:m-2:T=n===i.Direction.UP?c:l,this._textSelectionManagerService.replaceTextRanges([{startOffset:T,endOffset:T,style:u}],!1);return}const C=new R.NodePositionConvertToCursor(_,o).getRangePointData(f,f).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...C,style:u}],!1)}}_getTopOrBottomPosition(n,e,t){if(e==null)return;const r=this._getSpanLeftOffsetInLine(e),o=this._getNextOrPrevLine(e,t);if(o==null)return;const a=this._matchPositionByLeftOffset(n,o,r);if(a!=null)return{...a,isBack:!0}}_getSpanLeftOffsetInLine(n){const e=n.parent;if(e==null)return Number.NEGATIVE_INFINITY;const t=e.left,{left:r}=n;return t+r}_matchPositionByLeftOffset(n,e,t){const r={distance:Number.POSITIVE_INFINITY};for(const o of e.divides){const a=o.left;for(const c of o.spanGroup){const{left:l}=c,u=a+l,d=Math.abs(t-u);d<r.distance&&(r.span=c,r.distance=d)}}if(r.span!=null)return n.findPositionBySpan(r.span)}_getNextOrPrevLine(n,e){var v,p,h,_,f,C,T,x,U,D,y,O;const t=n.parent;if(t==null)return;const r=t.parent;if(r==null)return;const o=r.parent;if(o==null)return;const a=o.lines.indexOf(r);if(a===-1)return;let c;if(e===!0?c=o.lines[a+1]:c=o.lines[a-1],c!=null)return c;const l=o.parent;if(l==null)return;const u=l.columns.indexOf(o);if(u===-1)return;if(e===!0)c=(v=l.columns[u+1])==null?void 0:v.lines[0];else{const M=(h=(p=l.columns)==null?void 0:p[u-1])==null?void 0:h.lines;c=M==null?void 0:M[M.length-1]}if(c!=null)return c;const d=l.parent;if(d==null)return;const m=d.sections.indexOf(l);if(m===-1)return;if(e===!0)c=(f=(_=d.sections[m-1])==null?void 0:_.columns[0])==null?void 0:f.lines[0];else{const M=(T=(C=d.sections)==null?void 0:C[m-1])==null?void 0:T.columns,N=M==null?void 0:M[M.length-1],A=N==null?void 0:N.lines;c=A==null?void 0:A[A.length-1]}if(c!=null)return c;const g=d.parent;if(g==null)return;const S=g.pages.indexOf(d);if(S!==-1){if(e===!0)c=(D=(U=(x=g.pages[S+1])==null?void 0:x.sections[0])==null?void 0:U.columns[0])==null?void 0:D.lines[0];else{const M=(y=g.pages[S-1])==null?void 0:y.sections;if(M==null)return;const N=(O=M[M.length-1])==null?void 0:O.columns,A=N[N.length-1],Ie=A==null?void 0:A.lines;c=Ie[Ie.length-1]}if(c!=null)return c}}_getDocObject(){return ue(this._currentUniverService,this._renderManagerService)}};re=Mt([i.OnLifecycle(i.LifecycleStages.Rendered,re),X(0,E.Inject(exports.DocSkeletonManagerService)),X(1,i.IUniverInstanceService),X(2,R.IRenderManagerService),X(3,E.Inject(exports.TextSelectionManagerService)),X(4,i.ICommandService)],re);var Ct=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,xt=(s,n,e,t)=>{for(var r=t>1?void 0:t?Tt(n,e):n,o=s.length-1,a;o>=0;o--)(a=s[o])&&(r=(t?a(n,e,r):a(r))||r);return t&&r&&Ct(n,e,r),r},j=(s,n)=>(e,t)=>n(e,t,s);let ie=class extends i.Disposable{constructor(n,e,t,r,o){super();I(this,"_onInputSubscription");this._docSkeletonManagerService=n,this._currentUniverService=e,this._renderManagerService=t,this._textSelectionRenderManager=r,this._commandService=o,this._initialize(),this._commandExecutedListener()}dispose(){var n;(n=this._onInputSubscription)==null||n.unsubscribe()}_initialize(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async n=>{var v;if(n==null)return;const t=this._currentUniverService.getCurrentUniverDocInstance().getUnitId(),{event:r,content:o="",activeRange:a}=n,c=r,l=(v=this._docSkeletonManagerService.getCurrent())==null?void 0:v.skeleton;if(c.data==null||l==null||!l||!a)return;const{startOffset:u,segmentId:d,style:m}=a,g=o.length,S=[{startOffset:u+g,endOffset:u+g,style:m}];await this._commandService.executeCommand(z.id,{unitId:t,body:{dataStream:o},range:a,textRanges:S,segmentId:d})})}_commandExecutedListener(){}_getDocObject(){return ue(this._currentUniverService,this._renderManagerService)}};ie=xt([i.OnLifecycle(i.LifecycleStages.Rendered,ie),j(0,E.Inject(exports.DocSkeletonManagerService)),j(1,i.IUniverInstanceService),j(2,R.IRenderManagerService),j(3,R.ITextSelectionRenderManager),j(4,i.ICommandService)],ie);var Rt=Object.defineProperty,yt=Object.getOwnPropertyDescriptor,Ot=(s,n,e,t)=>{for(var r=t>1?void 0:t?yt(n,e):n,o=s.length-1,a;o>=0;o--)(a=s[o])&&(r=(t?a(n,e,r):a(r))||r);return t&&r&&Rt(n,e,r),r},B=(s,n)=>(e,t)=>n(e,t,s);let oe=class extends i.Disposable{constructor(n,e,t,r,o,a){super();I(this,"_loadedMap",new WeakSet);this._docSkeletonManagerService=n,this._currentUniverService=e,this._commandService=t,this._renderManagerService=r,this._textSelectionRenderManager=o,this._textSelectionManagerService=a,this._initialize()}_initialize(){this._init(),this._skeletonListener(),this._commandExecutedListener()}_init(){this.disposeWithMe(this._renderManagerService.currentRender$.subscribe(n=>{this._create(n)})),this._renderManagerService.getRenderAll().forEach((n,e)=>{this._create(e)})}_create(n){if(n==null||this._currentUniverService.getUniverDocInstance(n)==null)return;const e=this._getDocObjectById(n);e==null||e.document==null||this._loadedMap.has(e.document)||(this._initialMain(n),this._loadedMap.add(e.document))}_initialMain(n){const e=this._getDocObjectById(n);if(e==null)return;const{document:t,scene:r}=e;this.disposeWithMe(i.toDisposable(t.onPointerEnterObserver.add(()=>{t.cursor=R.CURSOR_TYPE.TEXT}))),this.disposeWithMe(i.toDisposable(t.onPointerLeaveObserver.add(()=>{t.cursor=R.CURSOR_TYPE.DEFAULT,r.resetCursor()}))),this.disposeWithMe(i.toDisposable(t==null?void 0:t.onPointerDownObserver.add((o,a)=>{this._currentUniverService.getCurrentUniverDocInstance().getUnitId()!==n&&this._currentUniverService.setCurrentUniverDocInstance(n),this._textSelectionRenderManager.eventTrigger(o),o.button!==2&&a.stopPropagation()}))),this.disposeWithMe(i.toDisposable(t==null?void 0:t.onDblclickObserver.add(o=>{this._textSelectionRenderManager.handleDblClick(o)}))),this.disposeWithMe(i.toDisposable(t==null?void 0:t.onTripleClickObserver.add(o=>{this._textSelectionRenderManager.handleTripleClick(o)})))}_commandExecutedListener(){const n=[$.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t;if(n.includes(e.id)){const r=e.params,{unitId:o}=r,a=(t=this._textSelectionManagerService.getCurrentSelection())==null?void 0:t.unitId;if(o!==a)return;this._textSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe(n=>{if(n==null)return;const{unitId:e,skeleton:t}=n,r=this._renderManagerService.getRenderById(e);if(r==null)return;const{scene:o,mainComponent:a}=r;this._textSelectionRenderManager.changeRuntime(t,o,a),this._textSelectionManagerService.setCurrentSelectionNotRefresh({unitId:e,subUnitId:""})}))}_getDocObjectById(n){return Xe(n,this._renderManagerService)}};oe=Ot([i.OnLifecycle(i.LifecycleStages.Rendered,oe),B(0,E.Inject(exports.DocSkeletonManagerService)),B(1,i.IUniverInstanceService),B(2,i.ICommandService),B(3,R.IRenderManagerService),B(4,R.ITextSelectionRenderManager),B(5,E.Inject(exports.TextSelectionManagerService))],oe);var Dt=Object.defineProperty,Et=Object.getOwnPropertyDescriptor,Ut=(s,n,e,t)=>{for(var r=t>1?void 0:t?Et(n,e):n,o=s.length-1,a;o>=0;o--)(a=s[o])&&(r=(t?a(n,e,r):a(r))||r);return t&&r&&Dt(n,e,r),r},ee=(s,n)=>(e,t)=>n(e,t,s);const bt={hasScroll:!0},At="docs";var de;exports.UniverDocsPlugin=(de=class extends i.Plugin{constructor(e={},t,r,o,a){super(At);I(this,"_config");this._injector=t,this._localeService=r,this._configService=o,this._currentUniverService=a,this._config=Object.assign(bt,e),this._initializeDependencies(t),this._initializeCommands()}initialize(){}_initializeCommands(){[se,ae,Oe,De,G,W,Y,Z,L,q,K,J,Q,ve,ye,z,H,Se,fe,pe,b,Pe,Ne,Le,$,me,Be,Ae,be,_e].forEach(e=>{this._injector.get(i.ICommandService).registerCommand(e)})}onReady(){this.initialize()}_initializeDependencies(e){[[exports.DocSkeletonManagerService],[exports.DocViewModelManagerService],[exports.DocStateChangeManagerService],[V],[R.ITextSelectionRenderManager,{useClass:R.TextSelectionRenderManager}],[exports.TextSelectionManagerService],[oe],[ie],[te],[ne],[re]].forEach(t=>e.add(t))}},I(de,"type",i.PluginType.Doc),de);exports.UniverDocsPlugin=Ut([ee(1,E.Inject(E.Injector)),ee(2,E.Inject(i.LocaleService)),ee(3,i.IConfigService),ee(4,i.IUniverInstanceService)],exports.UniverDocsPlugin);exports.BreakLineCommand=ye;exports.BulletListCommand=be;exports.CoverContentCommand=Ne;exports.CutContentCommand=he;exports.DOCS_COMPONENT_DEFAULT_Z_INDEX=Ve;exports.DOCS_COMPONENT_HEADER_LAYER_INDEX=ke;exports.DOCS_COMPONENT_MAIN_LAYER_INDEX=je;exports.DOCS_VIEW_KEY=xe;exports.DeleteCommand=H;exports.DeleteLeftCommand=Oe;exports.DeleteRightCommand=De;exports.IMEInputCommand=fe;exports.IMEInputManagerService=V;exports.InnerPasteCommand=st;exports.InsertCommand=z;exports.MoveCursorOperation=se;exports.MoveSelectionOperation=ae;exports.NORMAL_TEXT_SELECTION_PLUGIN_NAME=ze;exports.OrderListCommand=Ae;exports.ReplaceContentCommand=Pe;exports.RichTextEditingMutation=b;exports.SelectAllOperation=Be;exports.SetDocZoomRatioCommand=Le;exports.SetDocZoomRatioOperation=$;exports.SetInlineFormatBoldCommand=G;exports.SetInlineFormatCommand=ve;exports.SetInlineFormatFontFamilyCommand=J;exports.SetInlineFormatFontSizeCommand=K;exports.SetInlineFormatItalicCommand=W;exports.SetInlineFormatStrikethroughCommand=Z;exports.SetInlineFormatSubscriptCommand=L;exports.SetInlineFormatSuperscriptCommand=q;exports.SetInlineFormatTextColorCommand=Q;exports.SetInlineFormatUnderlineCommand=Y;exports.SetTextSelectionsOperation=me;exports.UpdateCommand=Se;exports.VIEWPORT_KEY=Re;exports.getDocObject=ue;exports.serializeTextRange=k;
|