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