@univerjs/docs 0.2.3 → 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/lib/cjs/index.js +1 -1
- package/lib/es/index.js +1936 -1830
- 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 +1 -1
- package/lib/types/commands/commands/list.command.d.ts +2 -1
- package/lib/types/commands/commands/replace-content.command.d.ts +8 -1
- 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 +3 -1
- 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/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,U,j,$){"use strict";var xn=Object.defineProperty;var Dn=(m,t,U)=>t in m?xn(m,t,{enumerable:!0,configurable:!0,writable:!0,value:U}):m[t]=U;var N=(m,t,U)=>Dn(m,typeof t!="symbol"?t+"":t,U);var Re;function te(s){return s===t.DataStreamTreeTokenType.CUSTOM_RANGE_END||s===t.DataStreamTreeTokenType.CUSTOM_RANGE_START}function xe(s,a,e,n){return s<=e&&a>=e||s>=e&&s<=n}function De(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 c=i.slice(0,o)+i.slice(o+a);for(let d=0,u=c.length;d<u;d++){const l=c[d];if(!te(l))return!1}return!0}function W(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 Ee(s,a){let{startOffset:e,endOffset:n}=W(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 ne(s,a){let{startOffset:e,endOffset:n,collapsed:i}=W(s);if(i){for(;te(a.dataStream[e-1]);)n-=1,e-=1;return{startOffset:e,endOffset:n,collapsed:i}}else return{...Ee(s,a),collapsed:!1}}function Y(s,a){let{startOffset:e,endOffset:n,collapsed:i}=W(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{...Ee(s,a),collapsed:!1}}function Rt(s,a){if(s.startOffset===s.endOffset)return null;const e=a.customRanges;if(!e)return W(s);let{startOffset:n,endOffset:i}=Ee(s,a);for(;te(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(;te(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 Mt=[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 xt(s,a,e){const n=s.slice(a,e);return Mt.reduce((i,o)=>i.replaceAll(o,""),n)}var K=(s=>(s.MAIN="__Document_Render_Main__",s.BACKGROUND="__Document_Render_Background__",s))(K||{}),Fe=(s=>(s.VIEW_MAIN="viewMain",s.VIEW_TOP="viewTop",s.VIEW_LEFT="viewLeft",s.VIEW_LEFT_TOP="viewLeftTop",s))(Fe||{});const Dt=0,Et=2,At=4,Nt=10,Ut="normalTextSelectionPluginName";function bt(s){const{mainComponent:a,scene:e,engine:n,components:i}=s,o=a,r=i.get(K.BACKGROUND);return{document:o,docBackground:r,scene:e,engine:n}}function ke(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:c,components:d}=i,u=o,l=d.get(K.BACKGROUND);return{document:u,docBackground:l,scene:r,engine:c}}function Pt(s,a){const e=a.getRenderById(s);if(e==null)return;const{mainComponent:n,scene:i,engine:o,components:r}=e,c=n,d=r.get(K.BACKGROUND);return{document:c,docBackground:d,scene:i,engine:o}}const Ae={id:"doc.operation.set-selections",type:t.CommandType.OPERATION,handler:(s,a)=>!0};var wt=Object.defineProperty,Bt=Object.getOwnPropertyDescriptor,Xt=(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&&wt(a,e,i),i},Ge=(s,a)=>(e,n)=>a(e,n,s);function z(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();N(this,"_currentSelection",null);N(this,"_textSelectionInfo",new Map);N(this,"_textSelection$",new $.BehaviorSubject(null));N(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}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: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,c=n.find(S=>S.isActive());if(c==null)return null;const{startOffset:d,endOffset:u,collapsed:l,startNodePosition:f,endNodePosition:g,direction:T}=c;return d==null||u==null?null:{startOffset:d,endOffset:u,collapsed:l,startNodePosition:f,endNodePosition:g,direction:T,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:U.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e,n=!0,i){this._currentSelection!=null&&(this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges(e,n,i))}_syncSelectionFromRenderService(){this._textSelectionRenderManager.textSelectionInner$.pipe($.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:c,textRanges:d,isEditing:u}=n;this._commandService.executeCommand(Ae.id,{unitId:i,subUnitId:o,segmentId:r,style:c,isEditing:u,ranges:d.map(z)})}_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(z))}_replaceByParam(e){const{unitId:n,subUnitId:i,style:o,segmentId:r,textRanges:c,isEditing:d,segmentPage:u}=e;this._textSelectionInfo.has(n)||this._textSelectionInfo.set(n,new Map),this._textSelectionInfo.get(n).set(i,{textRanges:c,style:o,segmentId:r,isEditing:d,segmentPage:u})}_addByParam(e){const{unitId:n,subUnitId:i,textRanges:o,style:r,segmentId:c,isEditing:d,segmentPage:u}=e;this._textSelectionInfo.has(n)||this._textSelectionInfo.set(n,new Map);const l=this._textSelectionInfo.get(n);l.has(i)?l.get(i).textRanges.push(...o):l.set(i,{textRanges:o,style:r,segmentId:c,isEditing:d,segmentPage:u})}},m.TextSelectionManagerService=Xt([Ge(0,U.ITextSelectionRenderManager),Ge(1,t.ICommandService)],m.TextSelectionManagerService);function ae(s,a="",e,n){var v;const{startOffset:i,endOffset:o}=s,r=[],c=i-e,d=o-e,u=n.dataStream,l=(v=n.customRanges)==null?void 0:v.filter(I=>xe(I.startIndex,I.endIndex,i,o)),f=new Set(l==null?void 0:l.filter(I=>De(i,o-i,I,u))),g=new Set;l==null||l.forEach(I=>{f.has(I)||(I.startIndex-e>=c&&I.startIndex-e<=d&&I.endIndex-e>d&&g.add(I.startIndex),I.endIndex-e>=c&&I.endIndex-e<=d&&I.startIndex<c&&g.add(I.endIndex))}),c>0&&r.push({t:t.TextXActionType.RETAIN,len:c,segmentId:a});const T=[...g].sort((I,h)=>I-h);let S=c;return T.forEach(I=>{const h=I-S;h>0&&r.push({t:t.TextXActionType.DELETE,len:h,line:0,segmentId:a}),r.push({t:t.TextXActionType.RETAIN,len:1,segmentId:a}),S=I+1}),S<d&&(r.push({t:t.TextXActionType.DELETE,len:d-S,line:0,segmentId:a}),S=d+1),{dos:r,cursor:S,retain:g.size}}var Lt=Object.defineProperty,Ft=Object.getOwnPropertyDescriptor,kt=(s,a,e,n)=>{for(var i=n>1?void 0:n?Ft(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&&Lt(a,e,i),i},Ne=(s,a)=>(e,n)=>a(e,n,s);const je=300;m.DocStateChangeManagerService=class extends t.RxDisposable{constructor(e,n,i){super();N(this,"_docStateChange$",new $.BehaviorSubject(null));N(this,"docStateChange$",this._docStateChange$.asObservable());N(this,"_historyStateCache",new Map);N(this,"_changeStateCache",new Map);N(this,"_historyTimer",null);N(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:c=!1}=e;if(r||i==null||n==="history"&&(i===t.RedoCommandId||i===t.UndoCommandId))return;const d=n==="history"?this._historyStateCache:this._changeStateCache,u=n==="history"?this._pushHistory.bind(this):this._emitChangeState.bind(this);if(d.has(o)){const l=d.get(o);l==null||l.push(e)}else d.set(o,[e]);c?n==="history"?(this._historyTimer&&clearTimeout(this._historyTimer),this._historyTimer=setTimeout(()=>{u(o)},je)):(this._changeStateCacheTimer&&clearTimeout(this._changeStateCacheTimer),this._changeStateCacheTimer=setTimeout(()=>{u(o)},je)):u(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,c=i[0],d=i[o-1],u={unitId:e,actions:i.reduce((f,g)=>t.JSONX.compose(f,g.redoState.actions),null),textRanges:d.redoState.textRanges},l={unitId:e,actions:i.reverse().reduce((f,g)=>t.JSONX.compose(f,g.undoState.actions),null),textRanges:c.undoState.textRanges};n.pushUndoRedo({unitID:e,undoMutations:[{id:r,params:l}],redoMutations:[{id:r,params:u}]}),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:c,noHistory:d,debounce:u}=n[0],l=n[0],f=n[i-1],g={unitId:e,actions:n.reduce((v,I)=>t.JSONX.compose(v,I.redoState.actions),null),textRanges:f.redoState.textRanges},T={unitId:e,actions:n.reverse().reduce((v,I)=>t.JSONX.compose(v,I.undoState.actions),null),textRanges:l.undoState.textRanges},S={commandId:o,unitId:e,trigger:r,redoState:g,undoState:T,segmentId:c,noHistory:d,debounce:u};n.length=0,this._docStateChange$.next(S)}},m.DocStateChangeManagerService=kt([Ne(0,j.Inject(t.IUndoRedoService)),Ne(1,t.ICommandService),Ne(2,t.IUniverInstanceService)],m.DocStateChangeManagerService);class Z{constructor(){N(this,"_previousActiveRange",null);N(this,"_undoMutationParamsCache",[]);N(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 Gt=Object.defineProperty,jt=Object.getOwnPropertyDescriptor,$t=(s,a,e,n)=>{for(var i=n>1?void 0:n?jt(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&&Gt(a,e,i),i},$e=(s,a)=>(e,n)=>a(e,n,s);m.DocSkeletonManagerService=class extends t.RxDisposable{constructor(e,n,i){super();N(this,"_skeleton");N(this,"_docViewModel");N(this,"_currentSkeleton$",new $.BehaviorSubject(null));N(this,"currentSkeleton$",this._currentSkeleton$.asObservable());N(this,"_currentSkeletonBefore$",new $.BehaviorSubject(null));N(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());N(this,"_currentViewModel$",new $.BehaviorSubject(null));N(this,"currentViewModel$",this._currentViewModel$.asObservable());this._context=e,this._localeService=n,this._univerInstanceService=i,this._init(),this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_DOC).pipe($.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 U.DocumentSkeleton.create(e,this._localeService)}_buildDocViewModel(e){return new U.DocumentViewModel(e)}},m.DocSkeletonManagerService=$t([$e(1,j.Inject(t.LocaleService)),$e(2,t.IUniverInstanceService)],m.DocSkeletonManagerService);const ze="doc.mutation.rich-text-editing",b={id:ze,type:t.CommandType.MUTATION,handler:(s,a)=>{var M,D;const{unitId:e,segmentId:n="",actions:i,textRanges:o,prevTextRanges:r,trigger:c,noHistory:d,isCompositionEnd:u,noNeedSetTextRange:l,debounce:f}=a,g=s.get(t.IUniverInstanceService),T=s.get(U.IRenderManagerService),S=g.getUniverDocInstance(e),v=(M=T.getRenderById(e))==null?void 0:M.with(m.DocSkeletonManagerService).getViewModel();if(S==null||v==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const I=s.get(m.TextSelectionManagerService),p=((D=I.getCurrentSelections())!=null?D:[]).map(z),_=s.get(m.DocStateChangeManagerService),O=s.get(Z),x=!!S.getSnapshot().disabled;if(t.JSONX.isNoop(i)||i&&i.length===0||x)return{unitId:e,actions:[],textRanges:p};const C=t.JSONX.invertWithDoc(i,S.getSnapshot());S.apply(i),v.reset(S),!l&&o&&c!=null&&queueMicrotask(()=>{I.replaceTextRanges(o,!0,a.options)});const R={commandId:ze,unitId:e,segmentId:n,trigger:c,noHistory:d,debounce:f,redoState:{actions:i,textRanges:o},undoState:{actions:C,textRanges:r!=null?r:p}};if(u){const y=O.fetchComposedUndoRedoMutationParams();if(y==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:A,redoMutationParams:E,previousActiveRange:P}=y;R.redoState.actions=E.actions,R.undoState.actions=A.actions,R.undoState.textRanges=[P]}return _.setChangeState(R),{unitId:e,actions:C,textRanges:p}}};function He(s,a){var n;return(n=s.get(U.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 Ve="doc.command.insert-text",q={id:Ve,type:t.CommandType.COMMAND,handler:async(s,a)=>{var M;const e=s.get(t.ICommandService),{range:n,segmentId:i,body:o,unitId:r,textRanges:c,cursorOffset:d}=a,u=s.get(m.TextSelectionManagerService),f=s.get(t.IUniverInstanceService).getUnit(r,t.UniverInstanceType.UNIVER_DOC);if(f==null)return!1;const g=u.getActiveRange(),T=f.getSelfOrHeaderFooterModel((M=g==null?void 0:g.segmentId)!=null?M:"").getBody();if(!T)return!1;const S=Y(n,T),{startOffset:v,collapsed:I}=S,h=d!=null?d:o.dataStream.length,p=[{startOffset:v+h,endOffset:v+h,style:g==null?void 0:g.style,collapsed:I}],_={id:b.id,params:{unitId:r,actions:[],textRanges:c!=null?c:p,debounce:!0}},O=new t.TextX,x=t.JSONX.getInstance();if(I)v>0&&O.push({t:t.TextXActionType.RETAIN,len:v,segmentId:i});else{const{dos:D,retain:y}=ae(S,i,0,T);O.push(...D),c||(_.params.textRanges=[{startOffset:v+h+y,endOffset:v+h+y,collapsed:I}])}O.push({t:t.TextXActionType.INSERT,body:o,len:o.dataStream.length,line:0,segmentId:i});const C=B(f,i);return _.params.actions=x.editOp(O.serialize(),C),!!e.syncExecuteCommand(_.id,_.params)}};var w=(s=>(s[s.LEFT=0]="LEFT",s[s.RIGHT=1]="RIGHT",s))(w||{});const H={id:"doc.command.delete-text",type:t.CommandType.COMMAND,handler:async(s,a)=>{var D;const e=s.get(t.ICommandService),n=s.get(t.IUniverInstanceService),{range:i,segmentId:o,unitId:r,direction:c,len:d=1}=a,u=n.getUnit(r,t.UniverInstanceType.UNIVER_DOC),l=u==null?void 0:u.getSelfOrHeaderFooterModel(o).getBody();if(u==null||l==null)return!1;const{startOffset:f}=i,g=l.dataStream,T=c===0?f-d:f,S=T+d-1,v=(D=l.customRanges)==null?void 0:D.filter(y=>xe(y.startIndex,y.endIndex,T,S)),I=v==null?void 0:v.filter(y=>De(T,d,y,g)),h=[];for(let y=0;y<d;y++)h.push(T+y);I==null||I.forEach(y=>{h.push(y.startIndex,y.endIndex)}),h.sort((y,A)=>y-A);const p=h[0],_={id:b.id,params:{unitId:r,actions:[],textRanges:[{startOffset:p,endOffset:p,collapsed:!0}],debounce:!0}},O=new t.TextX,x=t.JSONX.getInstance();let C=0;for(let y=0;y<h.length;y++){const A=h[y];A-C>0&&O.push({t:t.TextXActionType.RETAIN,len:A-C,segmentId:o}),O.push({t:t.TextXActionType.DELETE,len:1,segmentId:o,line:0}),C=A+1}const R=B(u,o);return _.params.actions=x.editOp(O.serialize(),R),!!e.syncExecuteCommand(_.id,_.params)}},Ue={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:c}=a,d=s.get(t.ICommandService),l=s.get(t.IUniverInstanceService).getCurrentUniverDocInstance();if(l==null)return!1;const f={id:b.id,params:{unitId:r,actions:[],textRanges:c}},g=new t.TextX,T=t.JSONX.getInstance(),{startOffset:S,endOffset:v}=e;g.push({t:t.TextXActionType.RETAIN,len:S,segmentId:n}),g.push({t:t.TextXActionType.RETAIN,body:i,len:v-S,segmentId:n,coverType:o});const I=B(l,n);return f.params.actions=T.editOp(g.serialize(),I),!!d.syncExecuteCommand(f.id,f.params)}};function Je(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 We={id:"doc.command.break-line",type:t.CommandType.COMMAND,handler:async s=>{var T;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{segmentId:o}=i,r=e.getCurrentUniverDocInstance(),c=r==null?void 0:r.getSelfOrHeaderFooterModel(o).getBody();if(!r||!c)return!1;const d=r.getUnitId(),{startOffset:u,endOffset:l}=Y(i,c),g=((T=c.paragraphs)!=null?T:[]).find(S=>S.startIndex>=u);if(g&&g.startIndex>l){const S=t.normalizeBody(t.getBodySlice(c,l,g.startIndex)),v={startOffset:u,endOffset:g.startIndex,collapsed:!1};return t.updateAttributeByInsert(S,{dataStream:t.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Je(t.DataStreamTreeTokenType.PARAGRAPH,g)},1,0),await n.executeCommand(q.id,{unitId:d,body:S,range:v,segmentId:o,cursorOffset:1})}else return await n.executeCommand(q.id,{unitId:d,body:{dataStream:t.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Je(t.DataStreamTreeTokenType.PARAGRAPH,g)},range:i,segmentId:o})}},zt={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),c=s.get(t.IUniverInstanceService),d=r.getCurrentSelections();if(!Array.isArray(d)||d.length===0)return!1;const u=c.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:n}},T=new t.MemoryCursor;T.reset();const S=new t.TextX,v=t.JSONX.getInstance();for(const p of d){const{startOffset:_,endOffset:O,collapsed:x}=p,C=_-T.cursor;if(x)S.push({t:t.TextXActionType.RETAIN,len:C,segmentId:e});else{const{dos:R}=ae(p,e,T.cursor,l);S.push(...R)}S.push({t:t.TextXActionType.INSERT,body:i,len:i.dataStream.length,line:0,segmentId:e}),T.reset(),T.moveCursor(O)}const I=B(u,e);return g.params.actions=v.editOp(S.serialize(),I),!!o.syncExecuteCommand(g.id,g.params)}},be={id:"doc.command.inner-cut",type:t.CommandType.COMMAND,handler:async(s,a)=>{var C,R,M;const{segmentId:e,textRanges:n}=a,i=s.get(t.ICommandService),o=s.get(m.TextSelectionManagerService),r=s.get(t.IUniverInstanceService),c=o.getCurrentSelections();if(!Array.isArray(c)||c.length===0)return!1;const d=(C=r.getCurrentUniverDocInstance())==null?void 0:C.getUnitId();if(!d)return!1;const u=r.getUniverDocInstance(d),l=t.getDocsUpdateBody(u.getSnapshot(),e);if(u==null||l==null)return!1;const f={id:b.id,params:{unitId:d,actions:[],textRanges:n}},g=new t.MemoryCursor;g.reset();const T=new t.TextX,S=t.JSONX.getInstance(),v=[];for(const D of c){const{startOffset:y,endOffset:A,collapsed:E}=D;if(y==null||A==null)continue;const P=y-g.cursor;E?T.push({t:t.TextXActionType.RETAIN,len:P,segmentId:e}):T.push(...Vt(D,l,e,g.cursor)),g.reset(),g.moveCursor(A)}const I=B(u,e);v.push(S.editOp(T.serialize(),I));const h=Ht(l,c),p=(R=u.getDrawings())!=null?R:{},_=(M=u.getDrawingsOrder())!=null?M:[],O=h.sort((D,y)=>_.indexOf(D)>_.indexOf(y)?-1:_.indexOf(D)<_.indexOf(y)?1:0);if(O.length>0)for(const D of O){const y=p[D],A=_.indexOf(D);if(y==null||A<0)continue;const E=S.removeOp(["drawings",D],y),P=S.removeOp(["drawingsOrder",A],D);v.push(E),v.push(P)}return f.params.actions=v.reduce((D,y)=>t.JSONX.compose(D,y),null),!!i.syncExecuteCommand(f.id,f.params)}};function Ht(s,a){const e=[],{customBlocks:n=[]}=s;for(const i of a){const{startOffset:o,endOffset:r}=i;if(!(o==null||r==null))for(const c of n){const{startIndex:d}=c;d>=o&&d<r&&e.push(c.blockId)}}return e}function Vt(s,a,e="",n=0){var h;const{startOffset:i,endOffset:o}=ne(s,a),r=[],{paragraphs:c=[],dataStream:d}=a,u=i-n,l=o-n,f=c==null?void 0:c.find(p=>p.startIndex-n>=u&&p.startIndex-n<=l),g=(h=a.customRanges)==null?void 0:h.filter(p=>xe(p.startIndex,p.endIndex,i,o)),T=new Set(g==null?void 0:g.filter(p=>De(i,o-i,p,d))),S=new Set;if(g==null||g.forEach(p=>{T.has(p)||(p.startIndex-n>=u&&p.startIndex-n<=l&&p.endIndex-n>l&&S.add(p.startIndex),p.endIndex-n>=u&&p.endIndex-n<=l&&p.startIndex<u&&S.add(p.endIndex))}),u>0&&r.push({t:t.TextXActionType.RETAIN,len:u,segmentId:e}),f&&f.startIndex-n>u){const p=f.startIndex-n;S.add(p)}const v=[...S].sort((p,_)=>p-_);let I=u;return v.forEach(p=>{const _=p-I;_>0&&r.push({t:t.TextXActionType.DELETE,len:_,line:0,segmentId:e}),r.push({t:t.TextXActionType.RETAIN,len:1,segmentId:e}),I=p+1}),I<l&&r.push({t:t.TextXActionType.DELETE,len:l-I,line:0,segmentId:e}),r}const ie={id:"doc.command.delete-custom-block",type:t.CommandType.COMMAND,handler:async(s,a)=>{var y;const e=s.get(m.TextSelectionManagerService),n=s.get(t.IUniverInstanceService),i=s.get(t.ICommandService),o=e.getActiveRange(),r=n.getCurrentUniverDocInstance();if(o==null||r==null)return!1;const{direction:c,range:d,unitId:u,drawingId:l}=a,{startOffset:f,segmentId:g,style:T}=o,S=c===w.LEFT?f-1:f,v=[{startOffset:S,endOffset:S,style:T}],I={id:b.id,params:{unitId:u,actions:[],textRanges:v,prevTextRanges:[d]}},h=new t.TextX,p=t.JSONX.getInstance(),_=[];f>0&&h.push({t:t.TextXActionType.RETAIN,len:c===w.LEFT?f-1:f,segmentId:g}),h.push({t:t.TextXActionType.DELETE,len:1,line:0,segmentId:g}),_.push(p.editOp(h.serialize()));const O=((y=r.getDrawings())!=null?y:{})[l],C=r.getDrawingsOrder().indexOf(l),R=p.removeOp(["drawings",l],O),M=p.removeOp(["drawingsOrder",C],l);return _.push(R),_.push(M),I.params.actions=_.reduce((A,E)=>t.JSONX.compose(A,E),null),!!i.syncExecuteCommand(I.id,I.params)}},se={id:"doc.command.merge-two-paragraph",type:t.CommandType.COMMAND,handler:async(s,a)=>{var A,E;const e=s.get(m.TextSelectionManagerService),n=s.get(t.IUniverInstanceService),i=s.get(t.ICommandService),{direction:o,range:r}=a,c=e.getActiveRange(),d=e.getCurrentSelections();if(c==null||d==null)return!1;const{segmentId:u,style:l}=c,f=n.getCurrentUniverDocInstance(),g=f==null?void 0:f.getSelfOrHeaderFooterModel(u).getBody();if(!f||!g)return!1;const T=ne(c,g),{startOffset:S,collapsed:v}=T;if(!v)return!1;const I=o===w.LEFT?S:S+1,h=(E=(A=g.paragraphs)==null?void 0:A.find(P=>P.startIndex>=I))==null?void 0:E.startIndex,p=Jt(g,I,h),_=o===w.LEFT?S-1:S,O=f.getUnitId(),x=[{startOffset:_,endOffset:_,style:l}],C={id:b.id,params:{unitId:O,actions:[],textRanges:x,prevTextRanges:[r]}},R=new t.TextX,M=t.JSONX.getInstance();R.push({t:t.TextXActionType.RETAIN,len:o===w.LEFT?S-1:S,segmentId:u}),p.dataStream.length&&R.push({t:t.TextXActionType.INSERT,body:p,len:p.dataStream.length,line:0,segmentId:u}),R.push({t:t.TextXActionType.RETAIN,len:1,segmentId:u}),R.push({t:t.TextXActionType.DELETE,len:h+1-I,line:0,segmentId:u});const D=B(f,u);return C.params.actions=M.editOp(R.serialize(),D),!!i.syncExecuteCommand(C.id,C.params)}},Ye={id:"doc.command.delete-left",type:t.CommandType.COMMAND,handler:async s=>{var M,D;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(),c=He(s,r),d=a.getActiveRange(),u=a.getCurrentSelections(),l=c==null?void 0:c.getSkeleton();if(d==null||l==null||u==null)return!1;const{segmentId:f,style:g,segmentPage:T}=d,S=o.getSelfOrHeaderFooterModel(f).getBody();if(S==null)return!1;const v=ne(d,S),{startOffset:I,collapsed:h}=v,p=l.findNodeByCharIndex(I,f,T),_=U.hasListGlyph(p),O=U.isIndentByGlyph(p,S);let x=I;const C=l.findNodeByCharIndex(I-1,f,T);if(U.isFirstGlyph(p)&&C!==p&&(_===!0||O===!0)&&h){const y=U.getParagraphByGlyph(p,S);if(y==null)return!1;const A=y==null?void 0:y.startIndex,E={startIndex:0},P=y.paragraphStyle;if(_===!0){const k=y.paragraphStyle;if(k){E.paragraphStyle=k;const{hanging:L}=k;L&&(E.paragraphStyle.indentStart=L,E.paragraphStyle.hanging=void 0)}}else if(O===!0){const k=y.bullet;k&&(E.bullet=k),P!=null&&(E.paragraphStyle={...P},delete E.paragraphStyle.hanging,delete E.paragraphStyle.indentStart)}const Me=[{startOffset:x,endOffset:x,style:g}];i=await n.executeCommand(Ue.id,{unitId:o.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...E}]},range:{startOffset:A,endOffset:A+1},textRanges:Me,coverType:t.UpdateDocsAttributeType.REPLACE,segmentId:f})}else if(h===!0){if(C==null)return!0;if(C.content==="\r")i=await n.executeCommand(se.id,{direction:w.LEFT,range:v});else if(C.streamType==="\b"){const y=(D=o.getSnapshot().drawings)==null?void 0:D[(M=C.drawingId)!=null?M:""];if(y==null)return!0;if(y.layoutType===t.PositionedObjectLayoutType.INLINE){const E=o.getUnitId();i=await n.executeCommand(ie.id,{direction:w.LEFT,range:d,unitId:E,drawingId:C.drawingId})}else{const E=l.findNodeByCharIndex(I-2);if(E==null)return!0;x-=C.count,x-=E.count;const P=[{startOffset:x,endOffset:x,style:g}];i=await n.executeCommand(H.id,{unitId:o.getUnitId(),range:{...d,startOffset:d.startOffset-1,endOffset:d.endOffset-1},segmentId:f,direction:w.LEFT,len:E.count,textRanges:P})}}else x-=C.count,i=await n.executeCommand(H.id,{unitId:o.getUnitId(),range:v,segmentId:f,direction:w.LEFT,len:C.count})}else{const y=Ze({...d,...v},u);i=await n.executeCommand(be.id,{segmentId:f,textRanges:y})}return i}},Ke={id:"doc.command.delete-right",type:t.CommandType.COMMAND,handler:async s=>{var p,_;const a=s.get(m.TextSelectionManagerService),n=s.get(t.IUniverInstanceService).getCurrentUniverDocInstance();if(!n)return!1;const i=He(s,n.getUnitId()),o=s.get(t.ICommandService),r=a.getActiveRange(),c=a.getCurrentSelections(),d=i==null?void 0:i.getSkeleton();if(r==null||d==null||c==null)return!1;const{segmentId:u,style:l,segmentPage:f}=r,g=n==null?void 0:n.getSelfOrHeaderFooterModel(u).getBody();if(!n||!g)return!1;const T=Y(r,g),{startOffset:S,endOffset:v,collapsed:I}=T;if(S===g.dataStream.length-2&&I)return!0;let h=!1;if(I===!0){const O=d.findNodeByCharIndex(S,u,f),x=d.findNodeByCharIndex(S+1);if(O.content==="\r")h=await o.executeCommand(se.id,{direction:w.RIGHT,range:r});else if(O.streamType==="\b"){const C=(_=n.getSnapshot().drawings)==null?void 0:_[(p=O.drawingId)!=null?p:""];if(C==null)return!0;if(C.layoutType===t.PositionedObjectLayoutType.INLINE){const M=n.getUnitId();h=await o.executeCommand(ie.id,{direction:w.RIGHT,range:r,unitId:M,drawingId:O.drawingId})}else{if(x==null)return!0;const M=[{startOffset:S+1,endOffset:S+1,style:l}];h=await o.executeCommand(H.id,{unitId:n.getUnitId(),range:{...r,startOffset:S+1,endOffset:v+1},segmentId:u,direction:w.RIGHT,textRanges:M,len:x.count})}}else{const C=[{startOffset:S,endOffset:S,style:l}];h=await o.executeCommand(H.id,{unitId:n.getUnitId(),range:T,segmentId:u,direction:w.RIGHT,textRanges:C,len:O.count})}}else{const O=Ze(r,c);h=await o.executeCommand(be.id,{segmentId:u,textRanges:O})}return h}};function Jt(s,a,e){const{textRuns:n=[],customBlocks:i=[]}=s,r={dataStream:s.dataStream.substring(a,e),customRanges:t.getCustomRangeSlice(s,a,e).customRanges,customDecorations:t.getCustomDecorationSlice(s,a,e)},c=[];for(const u of n){const{st:l,ed:f}=u;f<=a||l>=e||(l<a?c.push({...u,st:0,ed:f-a}):f>e?c.push({...u,st:l-a,ed:e-a}):c.push({...u,st:l-a,ed:f-a}))}c.length>0&&(r.textRuns=c);const d=[];for(const u of i){const{startIndex:l}=u;l>=a&&l<=e&&d.push({...u,startIndex:l-a})}return d.length>0&&(r.customBlocks=d),r}function Ze(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 Pe={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,c=s.get(t.ICommandService),d=s.get(Z),l=s.get(t.IUniverInstanceService).getCurrentUniverDocInstance();if(l==null)return!1;const f=d.getActiveRange();if(!f)return!1;const{startOffset:g,style:T,segmentId:S}=f,v=l.getSelfOrHeaderFooterModel(S).getBody();if(v==null)return!1;const I=Y(f,v);Object.assign(f,I);const h=n.length,p=[{startOffset:g+h,endOffset:g+h,collapsed:!0,style:T}],_={id:b.id,params:{unitId:e,actions:[],textRanges:p}},O=new t.TextX,x=t.JSONX.getInstance();if(!f.collapsed&&r){const{dos:M,retain:D,cursor:y}=ae(f,S,0,v);O.push(...M),_.params.textRanges=[{startOffset:g+h+D,endOffset:g+h+D,collapsed:!0}]}else O.push({t:t.TextXActionType.RETAIN,len:g,segmentId:S});i>0&&O.push({t:t.TextXActionType.DELETE,len:i,line:0,segmentId:S}),O.push({t:t.TextXActionType.INSERT,body:{dataStream:n},len:n.length,line:0,segmentId:S});const C=B(l,S);_.params.actions=x.editOp(O.serialize(),C),_.params.noHistory=!o,_.params.isCompositionEnd=o;const R=c.syncExecuteCommand(_.id,_.params);return d.pushUndoRedoMutationParams(R,_.params),!!R}};function X(s,a,e,n){var o;const{segmentId:i}=(o=e.getActiveRange())!=null?o:{};return i==null?!1:n.executeCommand(we.id,{segmentId:i,preCommandId:s,...a!=null?a:{}})}const qe="doc.command.set-inline-format-bold",oe={id:qe,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(qe,a,n,e)}},Qe="doc.command.set-inline-format-italic",re={id:Qe,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(Qe,a,n,e)}},et="doc.command.set-inline-format-underline",ce={id:et,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(et,a,n,e)}},tt="doc.command.set-inline-format-strikethrough",de={id:tt,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(tt,a,n,e)}},nt="doc.command.set-inline-format-subscript",V={id:nt,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(nt,a,n,e)}},at="doc.command.set-inline-format-superscript",le={id:at,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(at,a,n,e)}},it="doc.command.set-inline-format-fontsize",ue={id:it,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(it,a,n,e)}},st="doc.command.set-inline-format-font-family",me={id:st,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(st,a,n,e)}},ot="doc.command.set-inline-format-text-color",ge={id:ot,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(ot,a,n,e)}},rt="doc.command.set-inline-format-text-background-color",fe={id:rt,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(rt,a,n,e)}},ct="doc.command.reset-inline-format-text-background-color",Se={id:ct,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(ct,a,n,e)}},dt={[oe.id]:"bl",[re.id]:"it",[ce.id]:"ul",[de.id]:"st",[ue.id]:"fs",[me.id]:"ff",[ge.id]:"cl",[fe.id]:"bg",[Se.id]:"bg",[V.id]:"va",[le.id]:"va"},we={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),c=s.get(t.IUniverInstanceService),d=r.getCurrentSelections();if(!Array.isArray(d)||d.length===0)return!1;const u=c.getCurrentUniverDocInstance();if(u==null)return!1;const l=u.getUnitId();let f;switch(i){case oe.id:case re.id:case ce.id:case de.id:case V.id:case le.id:{f=Yt(u.getSelfOrHeaderFooterModel(e).getBody().textRuns,i,d);break}case ue.id:case me.id:{f=n;break}case ge.id:case fe.id:{f={rgb:n};break}case Se.id:{f={rgb:null};break}default:throw new Error(`Unknown command: ${i} in handleInlineFormat`)}const g={id:b.id,params:{unitId:l,actions:[],textRanges:d.map(z)}},T=new t.TextX,S=t.JSONX.getInstance(),v=new t.MemoryCursor;v.reset();for(const p of d){const{startOffset:_,endOffset:O}=p,x={dataStream:"",textRuns:[{st:0,ed:O-_,ts:{[dt[i]]:f}}]},C=_-v.cursor;C!==0&&T.push({t:t.TextXActionType.RETAIN,len:C,segmentId:e}),T.push({t:t.TextXActionType.RETAIN,body:x,len:O-_,segmentId:e}),v.reset(),v.moveCursor(O)}const I=B(u,e);return g.params.actions=S.editOp(T.serialize(),I),!!o.syncExecuteCommand(g.id,g.params)}};function Wt(s){return s!==null&&typeof s=="object"}function Yt(s,a,e){let n=0,i=0;const o=dt[a];for(;n!==s.length&&i!==e.length;){const{startOffset:r,endOffset:c}=e[i],{st:d,ed:u,ts:l}=s[n];if(c<=d)i++;else if(u<=r)n++;else{if(/bl|it/.test(o))return(l==null?void 0:l[o])===t.BooleanNumber.TRUE?t.BooleanNumber.FALSE:t.BooleanNumber.TRUE;if(/ul|st/.test(o))return Wt(l==null?void 0:l[o])&&(l==null?void 0:l[o]).s===t.BooleanNumber.TRUE?{s:t.BooleanNumber.FALSE}:{s:t.BooleanNumber.TRUE};if(/va/.test(o))return a===V.id?(l==null?void 0:l[o])===t.BaselineOffset.SUBSCRIPT?t.BaselineOffset.NORMAL:t.BaselineOffset.SUBSCRIPT:(l==null?void 0:l[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===V.id?t.BaselineOffset.SUBSCRIPT:t.BaselineOffset.SUPERSCRIPT}const Ie={id:"doc.command.list-operation",type:t.CommandType.COMMAND,handler:(s,a)=>{var E,P,Me,k;const e=s.get(m.TextSelectionManagerService),n=s.get(t.IUniverInstanceService),i=s.get(t.ICommandService),{listType:o}=a,r=n.getCurrentUniverDocInstance(),c=e.getActiveRange();if(r==null||c==null)return!1;const{segmentId:d}=c,u=(E=e.getCurrentSelections())!=null?E:[],l=(P=r.getSelfOrHeaderFooterModel(d).getBody())==null?void 0:P.paragraphs,f=u.map(z);if(l==null)return!1;const g=mt(c,l),T=r.getUnitId(),S=g.every(L=>{var F;return((F=L.bullet)==null?void 0:F.listType)===o});let I=t.Tools.generateRandomId(6);if(g.length===1){const L=l.indexOf(g[0]),F=l[L-1],G=l[L+1];F&&F.bullet&&F.bullet.listType===o?I=F.bullet.listId:G&&G.bullet&&G.bullet.listType===o&&(I=G.bullet.listId)}const h={id:b.id,params:{unitId:T,actions:[],textRanges:f}},p=new t.MemoryCursor;p.reset();const _=new t.TextX,O=t.JSONX.getInstance(),x=(Me=r.getSnapshot().lists)!=null?Me:{},C={...t.PRESET_LIST_TYPE,...x},{charSpace:R,defaultTabStop:M=36,gridType:D}=r.getSnapshot().documentStyle;for(const L of g){const{startIndex:F,paragraphStyle:G={}}=L,{indentFirstLine:Rn=0,snapToGrid:Mn,indentStart:Be=0}=G,{hanging:Xe,indentStart:Ot}=C[o].nestingLevel[0],Le=U.getCharSpaceApply(R,M,D,Mn);_.push({t:t.TextXActionType.RETAIN,len:F-p.cursor,segmentId:d}),_.push({t:t.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[S?{paragraphStyle:{...G,hanging:void 0,indentStart:Be?Math.max(0,U.getNumberUnitValue(Be,Le)+Xe-Ot):void 0},startIndex:0}:{startIndex:0,paragraphStyle:{...G,indentFirstLine:void 0,hanging:Xe,indentStart:Ot-Xe+U.getNumberUnitValue(Rn,Le)+U.getNumberUnitValue(Be,Le)},bullet:{...(k=L.bullet)!=null?k:{nestingLevel:0,textStyle:{fs:20}},listType:o,listId:I}}]},segmentId:d,coverType:t.UpdateDocsAttributeType.REPLACE}),p.moveCursorTo(F+1)}const y=B(r,d);return h.params.actions=O.editOp(_.serialize(),y),!!i.syncExecuteCommand(h.id,h.params)}},lt={id:"doc.command.bullet-list",type:t.CommandType.COMMAND,handler:s=>s.get(t.ICommandService).syncExecuteCommand(Ie.id,{listType:t.PresetListType.BULLET_LIST})},ut={id:"doc.command.order-list",type:t.CommandType.COMMAND,handler:s=>s.get(t.ICommandService).syncExecuteCommand(Ie.id,{listType:t.PresetListType.ORDER_LIST})};function mt(s,a){const{startOffset:e,endOffset:n}=s,i=[];let o=-1;for(const r of a){const{startIndex:c}=r;(e>o&&e<=c||n>o&&n<=c||c>=e&&c<=n)&&i.push(r),o=c}return i}const gt={id:"doc.command-replace-content",type:t.CommandType.COMMAND,handler:async(s,a)=>{const{unitId:e,body:n,textRanges:i,segmentId:o="",options:r}=a,c=s.get(t.IUniverInstanceService),d=s.get(t.ICommandService),u=s.get(m.TextSelectionManagerService),l=c.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 T=St(e,o,l,f,n);return T.params.textRanges=i,r&&(T.params.options=r),!!d.syncExecuteCommand(T.id,T.params)}},ft={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),c=s.get(t.IUndoRedoService),d=o.getUniverDocInstance(e),u=d==null?void 0:d.getSnapshot().body;if(d==null||u==null)return!1;const l=St(e,i,d,u,n);return l.params.noNeedSetTextRange=!0,l.params.noHistory=!0,r.syncExecuteCommand(l.id,l.params),c.clearUndoRedo(e),!0}};function St(s,a,e,n,i){const o={id:b.id,params:{unitId:s,actions:[],textRanges:[]}},r=new t.TextX,c=t.JSONX.getInstance(),d=(n==null?void 0:n.dataStream.length)-2;d>0&&r.push({t:t.TextXActionType.DELETE,len:d,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 u=B(e,a);return o.params.actions=c.editOp(r.serialize(),u),o}const Kt=(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}},Q={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}},It={type:t.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(s,a)=>{var f,g,T;const e=s.get(t.ICommandService),n=s.get(t.IUndoRedoService),i=s.get(t.IUniverInstanceService);let o=(f=i.getCurrentUniverDocInstance())==null?void 0:f.getUnitId();if(!o)return!1;let r=1;if(a&&(o=(g=a.documentId)!=null?g:o,r=(T=a.zoomRatio)!=null?T:r),!i.getUniverDocInstance(o))return!1;const d={zoomRatio:r,unitId:o},u=Kt(s,d);return e.syncExecuteCommand(Q.id,d)?(n.pushUndoRedo({unitID:o,undoMutations:[{id:Q.id,params:u}],redoMutations:[{id:Q.id,params:d}]}),!0):!1}},he={id:"doc.operation.move-cursor",type:t.CommandType.OPERATION,handler:(s,a)=>!!a},pe={id:"doc.operation.move-selection",type:t.CommandType.OPERATION,handler:(s,a)=>!!a},ht={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 c=[{startOffset:0,endOffset:r.dataStream.length-2}];return e.replaceTextRanges(c,!1),!0}};var Zt=Object.defineProperty,qt=Object.getOwnPropertyDescriptor,Qt=(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&&Zt(a,e,i),i},ee=(s,a)=>(e,n)=>a(e,n,s);let Te=class extends t.Disposable{constructor(a,e,n,i,o){super();N(this,"_previousIMEContent","");N(this,"_isCompositionStart",!0);N(this,"_onStartSubscription");N(this,"_onUpdateSubscription");N(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 u;if(a==null)return;const n=this._univerInstanceService.getCurrentUniverDocInstance();if(!n)return;const i=(u=this._renderManagerSrv.getRenderById(n.getUnitId()))==null?void 0:u.with(m.DocSkeletonManagerService).getSkeleton(),{event:o,activeRange:r}=a;if(i==null||r==null)return;const d=o.data;d===this._previousIMEContent&&e||(await this._commandService.executeCommand(Pe.id,{unitId:n.getUnitId(),newText:d,oldTextLen:this._previousIMEContent.length,isCompositionStart:this._isCompositionStart,isCompositionEnd:!e}),e?(this._isCompositionStart&&(this._isCompositionStart=!1),this._previousIMEContent=d):this._resetIME())}_resetIME(){this._previousIMEContent="",this._isCompositionStart=!0,this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(null)}};Te=Qt([t.OnLifecycle(t.LifecycleStages.Rendered,Te),ee(0,t.IUniverInstanceService),ee(1,U.IRenderManagerService),ee(2,U.ITextSelectionRenderManager),ee(3,j.Inject(Z)),ee(4,t.ICommandService)],Te);var en=Object.defineProperty,tn=Object.getOwnPropertyDescriptor,nn=(s,a,e,n)=>{for(var i=n>1?void 0:n?tn(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&&en(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();N(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=[he.id,pe.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!a.includes(e.id))return;const n=e.params;switch(e.id){case he.id:return this._handleMoveCursor(n.direction);case pe.id:return this._handleShiftMoveSelection(n.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(a){var _,O,x;const e=this._textSelectionManagerService.getActiveRange(),n=this._textSelectionManagerService.getCurrentSelections(),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:c,endOffset:d,style:u,collapsed:l,direction:f,segmentId:g,startNodePosition:T,endNodePosition:S,segmentPage:v}=e;if(n.length>1){let C=Number.POSITIVE_INFINITY,R=Number.NEGATIVE_INFINITY;for(const M of n)C=Math.min(C,M.startOffset),R=Math.max(R,M.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:a===t.Direction.LEFT||a===t.Direction.UP?R:C,endOffset:a===t.Direction.LEFT||a===t.Direction.UP?C:R,style:u}],!1);return}const I=l||f===U.RANGE_DIRECTION.FORWARD?c:d;let h=l||f===U.RANGE_DIRECTION.FORWARD?d:c;const p=(O=i.getSelfOrHeaderFooterModel(g).getBody().dataStream.length)!=null?O:Number.POSITIVE_INFINITY;if(a===t.Direction.LEFT||a===t.Direction.RIGHT){const C=o.findNodeByCharIndex(h-1,g,v),R=o.findNodeByCharIndex(h,g,v);h=a===t.Direction.RIGHT?h+R.count:h-((x=C==null?void 0:C.count)!=null?x:0),h=Math.min(p-2,Math.max(0,h)),this._textSelectionManagerService.replaceTextRanges([{startOffset:I,endOffset:h,style:u}],!1)}else{const C=o.findNodeByCharIndex(h,g,v),R=r.document.getOffsetConfig(),M=l?T:f===U.RANGE_DIRECTION.FORWARD?S:T,D=this._getTopOrBottomPosition(o,C,M,a===t.Direction.DOWN);if(D==null){const A=a===t.Direction.UP?0:p-2;if(A===h)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:I,endOffset:A,style:u}],!1);return}const y=new U.NodePositionConvertToCursor(R,o).getRangePointData(D,D).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:I,endOffset:y.endOffset,style:u}],!1)}}_handleMoveCursor(a){var I,h,p;const e=this._textSelectionManagerService.getActiveRange(),n=this._textSelectionManagerService.getCurrentSelections(),i=this._univerInstanceService.getCurrentUniverDocInstance();if(!i)return!1;const o=(I=this._renderManagerService.getRenderById(i.getUnitId()))==null?void 0:I.with(m.DocSkeletonManagerService).getSkeleton(),r=this._getDocObject();if(e==null||o==null||r==null||n==null)return;const{startOffset:c,endOffset:d,style:u,collapsed:l,segmentId:f,startNodePosition:g,endNodePosition:T,segmentPage:S}=e,v=(h=i.getSelfOrHeaderFooterModel(f).getBody().dataStream.length)!=null?h:Number.POSITIVE_INFINITY;if(a===t.Direction.LEFT||a===t.Direction.RIGHT){let _;if(!e.collapsed||n.length>1){let O=Number.POSITIVE_INFINITY,x=Number.NEGATIVE_INFINITY;for(const C of n)O=Math.min(O,C.startOffset),x=Math.max(x,C.endOffset);_=a===t.Direction.LEFT?O:x}else{const O=o.findNodeByCharIndex(c-1,f,S),x=o.findNodeByCharIndex(c,f,S);a===t.Direction.LEFT?_=Math.max(0,c-((p=O==null?void 0:O.count)!=null?p:0)):_=Math.min(v-2,d+x.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:_,endOffset:_,style:u}],!1)}else{const _=o.findNodeByCharIndex(c,f,S),O=o.findNodeByCharIndex(d,f,S),x=r.document.getOffsetConfig(),C=this._getTopOrBottomPosition(o,a===t.Direction.UP?_:O,a===t.Direction.UP?g:T,a===t.Direction.DOWN);if(C==null){let M;l?M=a===t.Direction.UP?0:v-2:M=a===t.Direction.UP?c:d,this._textSelectionManagerService.replaceTextRanges([{startOffset:M,endOffset:M,style:u}],!1);return}const R=new U.NodePositionConvertToCursor(x,o).getRangePointData(C,C).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...R,style:u}],!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 c=this._matchPositionByLeftOffset(a,r,o,n);if(c!=null)return{...c,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 c of e.divides){const d=c.left;for(const u of c.glyphGroup){const{left:l}=u,f=d+l,g=Math.abs(n-f);g<o.distance&&(o.glyph=u,o.distance=g)}}if(o.glyph==null)return;const{segmentPage:r}=i;return a.findPositionByGlyph(o.glyph,r)}_getNextOrPrevLine(a,e){var S,v,I,h,p,_,O,x,C,R,M,D;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 c;if(e===!0?c=o.lines[r+1]:c=o.lines[r-1],c!=null)return c;const d=o.parent;if(d==null)return;const u=d.columns.indexOf(o);if(u===-1)return;if(e===!0)c=(S=d.columns[u+1])==null?void 0:S.lines[0];else{const y=(I=(v=d.columns)==null?void 0:v[u-1])==null?void 0:I.lines;c=y==null?void 0:y[y.length-1]}if(c!=null)return c;const l=d.parent;if(l==null)return;const f=l.sections.indexOf(d);if(f===-1)return;if(e===!0)c=(p=(h=l.sections[f-1])==null?void 0:h.columns[0])==null?void 0:p.lines[0];else{const y=(O=(_=l.sections)==null?void 0:_[f-1])==null?void 0:O.columns,A=y==null?void 0:y[y.length-1],E=A==null?void 0:A.lines;c=E==null?void 0:E[E.length-1]}if(c!=null)return c;const g=l.parent;if(g==null)return;const T=g.pages.indexOf(l);if(T!==-1){if(e===!0)c=(R=(C=(x=g.pages[T+1])==null?void 0:x.sections[0])==null?void 0:C.columns[0])==null?void 0:R.lines[0];else{const y=(M=g.pages[T-1])==null?void 0:M.sections;if(y==null)return;const A=(D=y[y.length-1])==null?void 0:D.columns,E=A[A.length-1],P=E==null?void 0:E.lines;c=P[P.length-1]}if(c!=null)return c}}_getDocObject(){return ke(this._univerInstanceService,this._renderManagerService)}};Ce=nn([t.OnLifecycle(t.LifecycleStages.Rendered,Ce),ve(0,t.IUniverInstanceService),ve(1,U.IRenderManagerService),ve(2,j.Inject(m.TextSelectionManagerService)),ve(3,t.ICommandService)],Ce);var an=Object.defineProperty,sn=Object.getOwnPropertyDescriptor,on=(s,a,e,n)=>{for(var i=n>1?void 0:n?sn(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&&an(a,e,i),i},_e=(s,a)=>(e,n)=>a(e,n,s);let ye=class extends t.Disposable{constructor(a,e,n,i){super();N(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 v;if(a==null)return;const e=this._univerInstanceService.getCurrentUniverDocInstance();if(!e)return;const n=e.getUnitId(),{event:i,content:o="",activeRange:r}=a,c=i,d=(v=this._renderManagerService.getRenderById(e.getUnitId()))==null?void 0:v.with(m.DocSkeletonManagerService).getSkeleton();if(c.data==null||d==null||!d||!r)return;const{startOffset:u,segmentId:l,style:f,segmentPage:g}=r,T=o.length,S=[{startOffset:u+T,endOffset:u+T,segmentId:l,segmentPage:g,style:f}];await this._commandService.executeCommand(q.id,{unitId:n,body:{dataStream:o},textRanges:S,range:r,segmentId:l})})}};ye=on([t.OnLifecycle(t.LifecycleStages.Rendered,ye),_e(0,t.IUniverInstanceService),_e(1,U.IRenderManagerService),_e(2,U.ITextSelectionRenderManager),_e(3,t.ICommandService)],ye);const J={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(),c=e.getActiveRange();if(r==null||c==null)return!1;const{segmentId:d}=c,u=(x=e.getCurrentSelections())!=null?x:[],l=(C=r.getSelfOrHeaderFooterModel(d).getBody())==null?void 0:C.paragraphs,f=u.map(z);if(l==null)return!1;const g=mt(c,l),T=r.getUnitId(),S=g.every(R=>{var M;return((M=R.paragraphStyle)==null?void 0:M.horizontalAlign)===o}),v={id:b.id,params:{unitId:T,actions:[],textRanges:f}},I=new t.MemoryCursor;I.reset();const h=new t.TextX,p=t.JSONX.getInstance();for(const R of g){const{startIndex:M}=R;h.push({t:t.TextXActionType.RETAIN,len:M-I.cursor,segmentId:d});const D={...R.paragraphStyle,horizontalAlign:S?t.HorizontalAlign.UNSPECIFIED:o};h.push({t:t.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...R,paragraphStyle:D,startIndex:0}]},segmentId:d,coverType:t.UpdateDocsAttributeType.REPLACE}),I.moveCursorTo(M+1)}const _=B(r,d);return v.params.actions=p.editOp(h.serialize(),_),!!i.syncExecuteCommand(v.id,v.params)}},pt={id:"doc.command.align-left",type:t.CommandType.COMMAND,handler:s=>s.get(t.ICommandService).syncExecuteCommand(J.id,{alignType:t.HorizontalAlign.LEFT})},Tt={id:"doc.command.align-center",type:t.CommandType.COMMAND,handler:s=>s.get(t.ICommandService).syncExecuteCommand(J.id,{alignType:t.HorizontalAlign.CENTER})},vt={id:"doc.command.align-right",type:t.CommandType.COMMAND,handler:s=>s.get(t.ICommandService).syncExecuteCommand(J.id,{alignType:t.HorizontalAlign.RIGHT})},Ct={id:"doc.command.align-justify",type:t.CommandType.COMMAND,handler:s=>s.get(t.ICommandService).syncExecuteCommand(J.id,{alignType:t.HorizontalAlign.JUSTIFIED})};class _t{constructor(){N(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 rn=Object.defineProperty,cn=Object.getOwnPropertyDescriptor,dn=(s,a,e,n)=>{for(var i=n>1?void 0:n?cn(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&&rn(a,e,i),i},ln=(s,a)=>(e,n)=>a(e,n,s);const un="docs";m.UniverDocsPlugin=(Re=class extends t.Plugin{constructor(a={},e){super(),this._injector=e,this._initializeDependencies(e),this._initializeCommands()}_initializeCommands(){[he,pe,Ye,Ke,oe,re,ce,de,V,le,ue,me,ge,Se,fe,we,We,q,H,ie,Ue,Pe,se,b,gt,ft,It,Q,Ae,ht,ut,lt,Ie,pt,Tt,vt,J,Ct].forEach(a=>{this._injector.get(t.ICommandService).registerCommand(a)})}_initializeDependencies(a){[[m.DocStateChangeManagerService],[Z],[U.ITextSelectionRenderManager,{useClass:U.TextSelectionRenderManager}],[m.TextSelectionManagerService],[_t],[ye],[Te],[Ce]].forEach(e=>a.add(e))}},N(Re,"pluginName",un),N(Re,"type",t.UniverInstanceType.UNIVER_DOC),Re),m.UniverDocsPlugin=dn([ln(1,j.Inject(j.Injector))],m.UniverDocsPlugin);function mn(s,a){const{range:e,rangeId:n,rangeType:i,segmentId:o}=s,r=Rt(e,a);if(!r)return null;const{startOffset:c,endOffset:d}=r,u=new t.TextX;return c>0&&u.push({t:t.TextXActionType.RETAIN,len:c,segmentId:o}),u.push({t:t.TextXActionType.INSERT,body:{dataStream:t.DataStreamTreeTokenType.CUSTOM_RANGE_START},len:1,line:0}),u.push({t:t.TextXActionType.RETAIN,body:{dataStream:""},len:d-c,segmentId:o}),u.push({t:t.TextXActionType.INSERT,body:{dataStream:t.DataStreamTreeTokenType.CUSTOM_RANGE_END,customRanges:[{rangeId:n,rangeType:i,startIndex:-(d-c)-1,endIndex:0}]},len:1,line:0}),u}function gn(s,a){const e={id:b.id,params:{unitId:s.unitId,actions:[],textRanges:void 0}},n=t.JSONX.getInstance(),i=mn(s,a);return i?(e.params.actions=n.editOp(i.serialize()),e):!1}function fn(s,a){var x;const{segmentId:e,rangeId:n,rangeType:i}=a,o=s.get(m.TextSelectionManagerService),r=s.get(t.IUniverInstanceService),c=o.getActiveRange();if(!c)return!1;const d=r.getCurrentUnitForType(t.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const u=d.getBody(),l=d.getUnitId();if(!u)return!1;const{startOffset:f,endOffset:g}=W(c),T=(x=u.customRanges)!=null?x:[],S=[];for(let C=0,R=T.length;C<R;C++){const M=T[C];if(M.rangeType===i&&Math.max(M.startIndex,f)<=Math.min(M.endIndex,g-1)&&S.push({...M}),M.startIndex>=g)break}const v=S.map(C=>[C.startIndex,C.endIndex]).flat().sort((C,R)=>C-R);let I=0;const h=new t.TextX,p=v.length?{startOffset:Math.min(v[0],f),endOffset:Math.max(v[v.length-1]+1,g)}:c;p.startOffset!==I&&(h.push({t:t.TextXActionType.RETAIN,len:p.startOffset-I,segmentId:e}),I=p.startOffset),h.push({t:t.TextXActionType.INSERT,body:{dataStream:t.DataStreamTreeTokenType.CUSTOM_RANGE_START},len:1,line:0,segmentId:e}),v.forEach((C,R)=>{C!==I&&(h.push({t:t.TextXActionType.RETAIN,len:C-I,segmentId:e}),I=C),h.push({t:t.TextXActionType.DELETE,len:1,line:0,segmentId:e}),I++}),I!==p.endOffset&&(h.push({t:t.TextXActionType.RETAIN,len:p.endOffset-I,segmentId:e}),I=p.endOffset),h.push({t:t.TextXActionType.INSERT,body:{dataStream:t.DataStreamTreeTokenType.CUSTOM_RANGE_END,customRanges:[{rangeId:n,rangeType:i,startIndex:-(p.endOffset-p.startOffset-v.length+1),endIndex:0}]},len:1,line:0,segmentId:e});const _=t.JSONX.getInstance(),O={id:b.id,params:{unitId:l,actions:[],textRanges:void 0}};return O.params.actions=_.editOp(h.serialize()),O}function Sn(s,a){var g,T;const{unitId:e,rangeId:n,segmentId:i}=a,r=s.get(t.IUniverInstanceService).getUnit(e);if(!r)return!1;const c=(T=(g=r.getBody())==null?void 0:g.customRanges)==null?void 0:T.find(S=>S.rangeId===n);if(!c)return!1;const{startIndex:d,endIndex:u}=c,l=new t.TextX,f=u-d+1;return d>0&&l.push({t:t.TextXActionType.RETAIN,len:d,segmentId:i}),l.push({t:t.TextXActionType.DELETE,len:1,segmentId:i,line:0}),f-2>0&&l.push({t:t.TextXActionType.RETAIN,len:f-2,segmentId:i}),l.push({t:t.TextXActionType.DELETE,len:1,segmentId:i,line:0}),l}function In(s,a){const e={id:b.id,params:{unitId:a.unitId,actions:[],textRanges:void 0}},n=t.JSONX.getInstance(),i=Sn(s,a);return i?(e.params.actions=n.editOp(i.serialize()),e):!1}function yt(s){const{unitId:a,range:e,id:n,type:i,segmentId:o}=s,{startOffset:r,endOffset:c}=e,d={id:b.id,params:{unitId:a,actions:[],textRanges:void 0}},u=new t.TextX,l=t.JSONX.getInstance();return r>0&&u.push({t:t.TextXActionType.RETAIN,len:r,segmentId:o}),u.push({t:t.TextXActionType.RETAIN,body:{dataStream:"",customDecorations:[{id:n,type:i,startIndex:0,endIndex:c-r-1}]},len:c-r,segmentId:o}),d.params.actions=l.editOp(u.serialize()),d}function hn(s,a){const{segmentId:e,id:n,type:i}=a,o=s.get(m.TextSelectionManagerService),r=s.get(t.IUniverInstanceService),c=o.getActiveRange();if(!c)return!1;const d=r.getCurrentUnitForType(t.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const u=d.getBody(),l=d.getUnitId();return u?yt({unitId:l,range:{startOffset:c.startOffset,endOffset:c.endOffset,collapsed:!0},id:n,type:i,segmentId:e}):!1}function pn(s,a){var v,I;const{unitId:e,id:n,segmentId:i}=a,r=s.get(t.IUniverInstanceService).getUnit(e),c=r==null?void 0:r.getBody();if(!r||!c)return!1;const d=(I=(v=r.getBody())==null?void 0:v.customDecorations)==null?void 0:I.filter(h=>h.id===n);if(!(d!=null&&d.length))return!1;const u=d.map(h=>t.getBodySlice(c,h.startIndex,h.endIndex+1)),l=u.map(h=>{var _;const p=t.Tools.deepClone(h);return p.customDecorations=(_=p.customDecorations)==null?void 0:_.filter(O=>O.id!==n),p}),f={id:b.id,params:{unitId:e,actions:[],textRanges:void 0}},g=new t.TextX,T=t.JSONX.getInstance();let S=0;return d.forEach((h,p)=>{const _=l[p],O=u[p];h.startIndex!==S&&g.push({t:t.TextXActionType.RETAIN,len:h.startIndex-S,segmentId:i}),S=h.startIndex,g.push({t:t.TextXActionType.RETAIN,len:h.endIndex-h.startIndex+1,segmentId:i,body:_,oldBody:O,coverType:t.UpdateDocsAttributeType.REPLACE}),S=S+(h.endIndex-h.startIndex+1)}),f.params.actions=T.editOp(g.serialize()),f}const Tn=t.createInterceptorKey("CUSTOM_RANGE"),vn=t.createInterceptorKey("CUSTOM_DECORATION"),Oe={CUSTOM_RANGE:Tn,CUSTOM_DECORATION:vn};var Cn=Object.defineProperty,_n=Object.getOwnPropertyDescriptor,yn=(s,a,e,n)=>{for(var i=n>1?void 0:n?_n(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&&Cn(a,e,i),i},On=(s,a)=>(e,n)=>a(e,n,s);m.DocInterceptorService=class extends t.Disposable{constructor(e,n){super();N(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(Oe.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,c)=>{var d,u;return((d=c.priority)!=null?d:0)-((u=r.priority)!=null?u: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(Oe.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(Oe.CUSTOM_DECORATION)(e.getCustomDecorationRaw(i),{index:i,unitId:e.getDataModel().getUnitId(),customDecorations:(o=e.getDataModel().getCustomDecorations())!=null?o:[]})}})),n}},m.DocInterceptorService=yn([t.OnLifecycle(t.LifecycleStages.Starting,m.DocInterceptorService),On(1,j.Inject(m.DocSkeletonManagerService))],m.DocInterceptorService),m.AlignCenterCommand=Tt,m.AlignJustifyCommand=Ct,m.AlignLeftCommand=pt,m.AlignOperationCommand=J,m.AlignRightCommand=vt,m.BreakLineCommand=We,m.BulletListCommand=lt,m.CoverContentCommand=ft,m.CutContentCommand=be,m.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX=Dt,m.DOCS_COMPONENT_DEFAULT_Z_INDEX=Nt,m.DOCS_COMPONENT_HEADER_LAYER_INDEX=At,m.DOCS_COMPONENT_MAIN_LAYER_INDEX=Et,m.DOCS_VIEW_KEY=K,m.DOC_INTERCEPTOR_POINT=Oe,m.DeleteCommand=H,m.DeleteCustomBlockCommand=ie,m.DeleteLeftCommand=Ye,m.DeleteRightCommand=Ke,m.DocCustomRangeService=_t,m.EditorInsertTextCommandId=Ve,m.IMEInputCommand=Pe,m.IMEInputManagerService=Z,m.InnerPasteCommand=zt,m.InsertCommand=q,m.ListOperationCommand=Ie,m.MergeTwoParagraphCommand=se,m.MoveCursorOperation=he,m.MoveSelectionOperation=pe,m.NORMAL_TEXT_SELECTION_PLUGIN_NAME=Ut,m.OrderListCommand=ut,m.ReplaceContentCommand=gt,m.ResetInlineFormatTextBackgroundColorCommand=Se,m.RichTextEditingMutation=b,m.SelectAllOperation=ht,m.SetDocZoomRatioCommand=It,m.SetDocZoomRatioOperation=Q,m.SetInlineFormatBoldCommand=oe,m.SetInlineFormatCommand=we,m.SetInlineFormatFontFamilyCommand=me,m.SetInlineFormatFontSizeCommand=ue,m.SetInlineFormatItalicCommand=re,m.SetInlineFormatStrikethroughCommand=de,m.SetInlineFormatSubscriptCommand=V,m.SetInlineFormatSuperscriptCommand=le,m.SetInlineFormatTextBackgroundColorCommand=fe,m.SetInlineFormatTextColorCommand=ge,m.SetInlineFormatUnderlineCommand=ce,m.SetTextSelectionsOperation=Ae,m.UpdateCommand=Ue,m.VIEWPORT_KEY=Fe,m.addCustomDecorationBySelectionFactory=hn,m.addCustomDecorationFactory=yt,m.addCustomRangeBySelectionFactory=fn,m.addCustomRangeFactory=gn,m.deleteCustomDecorationFactory=pn,m.deleteCustomRangeFactory=In,m.getDeleteSelection=ne,m.getDocObject=ke,m.getDocObjectById=Pt,m.getInsertSelection=Y,m.getRetainAndDeleteFromReplace=ae,m.getRichTextEditPath=B,m.getSelectionText=xt,m.neoGetDocObject=bt,m.serializeTextRange=z,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/
|
|
52
|
-
"@univerjs/
|
|
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
|
".": {
|