@univerjs/docs 0.2.5 → 0.2.6
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 +2166 -2113
- package/lib/types/commands/mutations/docs-rename.mutation.d.ts +7 -0
- package/lib/umd/index.js +1 -1
- package/package.json +9 -9
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var bt=Object.defineProperty;var Ut=(s,o,e)=>o in s?bt(s,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[o]=e;var A=(s,o,e)=>Ut(s,typeof o!="symbol"?o+"":o,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@univerjs/core"),N=require("@univerjs/engine-render"),$=require("rxjs"),ge={id:"doc.operation.set-selections",type:n.CommandType.OPERATION,handler:(s,o)=>!0};var Pt=Object.defineProperty,wt=Object.getOwnPropertyDescriptor,Bt=(s,o,e,t)=>{for(var r=t>1?void 0:t?wt(o,e):o,a=s.length-1,i;a>=0;a--)(i=s[a])&&(r=(t?i(o,e,r):i(r))||r);return t&&r&&Pt(o,e,r),r},ze=(s,o)=>(e,t)=>o(e,t,s);function z(s){const{startOffset:o,endOffset:e,collapsed:t}=s,r={startOffset:o,endOffset:e,collapsed:t};return typeof s.isActive=="function"&&(r.isActive=s.isActive()),r}exports.TextSelectionManagerService=class extends n.RxDisposable{constructor(e,t){super();A(this,"_currentSelection",null);A(this,"_textSelectionInfo",new Map);A(this,"_textSelection$",new $.BehaviorSubject(null));A(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(r=>r.isActive())}getActiveRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:t,segmentId:r,style:a,segmentPage:i}=e,d=t.find(S=>S.isActive());if(d==null)return null;const{startOffset:c,endOffset:u,collapsed:l,startNodePosition:g,endNodePosition:m,direction:f}=d;return c==null||u==null?null:{startOffset:c,endOffset:u,collapsed:l,startNodePosition:g,endNodePosition:m,direction:f,segmentId:r,segmentPage:i,style:a}}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,r){this._currentSelection!=null&&(this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges(e,t,r))}_syncSelectionFromRenderService(){this._textSelectionRenderManager.textSelectionInner$.pipe($.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._replaceTextRangesWithNoRefresh(e)})}_replaceTextRangesWithNoRefresh(e){if(this._currentSelection==null)return;const t={...this._currentSelection,...e};this._replaceByParam(t),this._textSelection$.next(t);const{unitId:r,subUnitId:a,segmentId:i,style:d,textRanges:c,isEditing:u}=t;this._commandService.executeCommand(ge.id,{unitId:r,subUnitId:a,segmentId:i,style:d,isEditing:u,ranges:c.map(z)})}_getTextRanges(e){var a;if(e==null)return;const{unitId:t,subUnitId:r=""}=e;return(a=this._textSelectionInfo.get(t))==null?void 0:a.get(r)}_refresh(e){const t=this._getTextRanges(e);this._textSelectionRenderManager.removeAllTextRanges(),t&&Array.isArray(t.textRanges)&&t.textRanges.length&&this._textSelectionRenderManager.addTextRanges(t.textRanges.map(z))}_replaceByParam(e){const{unitId:t,subUnitId:r,style:a,segmentId:i,textRanges:d,isEditing:c,segmentPage:u}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(r,{textRanges:d,style:a,segmentId:i,isEditing:c,segmentPage:u})}_addByParam(e){const{unitId:t,subUnitId:r,textRanges:a,style:i,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(r)?l.get(r).textRanges.push(...a):l.set(r,{textRanges:a,style:i,segmentId:d,isEditing:c,segmentPage:u})}};exports.TextSelectionManagerService=Bt([ze(0,N.ITextSelectionRenderManager),ze(1,n.ICommandService)],exports.TextSelectionManagerService);var Xt=Object.defineProperty,Lt=Object.getOwnPropertyDescriptor,Ft=(s,o,e,t)=>{for(var r=t>1?void 0:t?Lt(o,e):o,a=s.length-1,i;a>=0;a--)(i=s[a])&&(r=(t?i(o,e,r):i(r))||r);return t&&r&&Xt(o,e,r),r},be=(s,o)=>(e,t)=>o(e,t,s);const He=300;exports.DocStateChangeManagerService=class extends n.RxDisposable{constructor(e,t,r){super();A(this,"_docStateChange$",new $.BehaviorSubject(null));A(this,"docStateChange$",this._docStateChange$.asObservable());A(this,"_historyStateCache",new Map);A(this,"_changeStateCache",new Map);A(this,"_historyTimer",null);A(this,"_changeStateCacheTimer",null);this._undoRedoService=e,this._commandService=t,this._univerInstanceService=r,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 r=t.getUnitId();this._pushHistory(r),this._emitChangeState(r)}}))}_cacheChangeState(e,t="history"){const{trigger:r,unitId:a,noHistory:i,debounce:d=!1}=e;if(i||r==null||t==="history"&&(r===n.RedoCommandId||r===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(a)){const l=c.get(a);l==null||l.push(e)}else c.set(a,[e]);d?t==="history"?(this._historyTimer&&clearTimeout(this._historyTimer),this._historyTimer=setTimeout(()=>{u(a)},He)):(this._changeStateCacheTimer&&clearTimeout(this._changeStateCacheTimer),this._changeStateCacheTimer=setTimeout(()=>{u(a)},He)):u(a)}_pushHistory(e){const t=this._undoRedoService,r=this._historyStateCache.get(e);if(!Array.isArray(r)||r.length===0)return;const a=r.length,i=r[0].commandId,d=r[0],c=r[a-1],u={unitId:e,actions:r.reduce((g,m)=>n.JSONX.compose(g,m.redoState.actions),null),textRanges:c.redoState.textRanges},l={unitId:e,actions:r.reverse().reduce((g,m)=>n.JSONX.compose(g,m.undoState.actions),null),textRanges:d.undoState.textRanges};t.pushUndoRedo({unitID:e,undoMutations:[{id:i,params:l}],redoMutations:[{id:i,params:u}]}),r.length=0}_emitChangeState(e){const t=this._changeStateCache.get(e);if(!Array.isArray(t)||t.length===0)return;const r=t.length,{commandId:a,trigger:i,segmentId:d,noHistory:c,debounce:u}=t[0],l=t[0],g=t[r-1],m={unitId:e,actions:t.reduce((T,I)=>n.JSONX.compose(T,I.redoState.actions),null),textRanges:g.redoState.textRanges},f={unitId:e,actions:t.reverse().reduce((T,I)=>n.JSONX.compose(T,I.undoState.actions),null),textRanges:l.undoState.textRanges},S={commandId:a,unitId:e,trigger:i,redoState:m,undoState:f,segmentId:d,noHistory:c,debounce:u};t.length=0,this._docStateChange$.next(S)}};exports.DocStateChangeManagerService=Ft([be(0,n.Inject(n.IUndoRedoService)),be(1,n.ICommandService),be(2,n.IUniverInstanceService)],exports.DocStateChangeManagerService);class Q{constructor(){A(this,"_previousActiveRange",null);A(this,"_undoMutationParamsCache",[]);A(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache:o=[],redoCache:e=[]}){this._undoMutationParamsCache=o,this._redoMutationParamsCache=e}getActiveRange(){return this._previousActiveRange}setActiveRange(o){this._previousActiveRange=o}pushUndoRedoMutationParams(o,e){this._undoMutationParamsCache.push(o),this._redoMutationParamsCache.push(e)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:o}=this._undoMutationParamsCache[0],e={unitId:o,actions:this._undoMutationParamsCache.reverse().reduce((r,a)=>n.JSONX.compose(r,a.actions),null),textRanges:[]};return{redoMutationParams:{unitId:o,actions:this._redoMutationParamsCache.reduce((r,a)=>n.JSONX.compose(r,a.actions),null),textRanges:[]},undoMutationParams:e,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}var kt=Object.defineProperty,Gt=Object.getOwnPropertyDescriptor,jt=(s,o,e,t)=>{for(var r=t>1?void 0:t?Gt(o,e):o,a=s.length-1,i;a>=0;a--)(i=s[a])&&(r=(t?i(o,e,r):i(r))||r);return t&&r&&kt(o,e,r),r},Ve=(s,o)=>(e,t)=>o(e,t,s);exports.DocSkeletonManagerService=class extends n.RxDisposable{constructor(e,t,r){super();A(this,"_skeleton");A(this,"_docViewModel");A(this,"_currentSkeleton$",new $.BehaviorSubject(null));A(this,"currentSkeleton$",this._currentSkeleton$.asObservable());A(this,"_currentSkeletonBefore$",new $.BehaviorSubject(null));A(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());A(this,"_currentViewModel$",new $.BehaviorSubject(null));A(this,"currentViewModel$",this._currentViewModel$.asObservable());this._context=e,this._localeService=t,this._univerInstanceService=r,this._init(),this._univerInstanceService.getCurrentTypeOfUnit$(n.UniverInstanceType.UNIVER_DOC).pipe($.takeUntil(this.dispose$)).subscribe(a=>{a&&a.getUnitId()===this._context.unitId&&this._update(a)})}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 r=this._skeleton;r.calculate(),this._currentSkeletonBefore$.next(r),this._currentSkeleton$.next(r),this._currentViewModel$.next(this._docViewModel)}_buildSkeleton(e){return N.DocumentSkeleton.create(e,this._localeService)}_buildDocViewModel(e){return new N.DocumentViewModel(e)}};exports.DocSkeletonManagerService=jt([Ve(1,n.Inject(n.LocaleService)),Ve(2,n.IUniverInstanceService)],exports.DocSkeletonManagerService);const Je="doc.mutation.rich-text-editing",b={id:Je,type:n.CommandType.MUTATION,handler:(s,o)=>{var M,O;const{unitId:e,segmentId:t="",actions:r,textRanges:a,prevTextRanges:i,trigger:d,noHistory:c,isCompositionEnd:u,noNeedSetTextRange:l,debounce:g}=o,m=s.get(n.IUniverInstanceService),f=s.get(N.IRenderManagerService),S=m.getUniverDocInstance(e),T=(M=f.getRenderById(e))==null?void 0:M.with(exports.DocSkeletonManagerService).getViewModel();if(S==null||T==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const I=s.get(exports.TextSelectionManagerService),h=((O=I.getCurrentSelections())!=null?O:[]).map(z),v=s.get(exports.DocStateChangeManagerService),_=s.get(Q),D=!!S.getSnapshot().disabled;if(n.JSONX.isNoop(r)||r&&r.length===0||D)return{unitId:e,actions:[],textRanges:h};const C=n.JSONX.invertWithDoc(r,S.getSnapshot());S.apply(r),T.reset(S),!l&&a&&d!=null&&queueMicrotask(()=>{I.replaceTextRanges(a,!0,o.options)});const y={commandId:Je,unitId:e,segmentId:t,trigger:d,noHistory:c,debounce:g,redoState:{actions:r,textRanges:a},undoState:{actions:C,textRanges:i!=null?i:h}};if(u){const x=_.fetchComposedUndoRedoMutationParams();if(x==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:R,redoMutationParams:E,previousActiveRange:U}=x;y.redoState.actions=E.actions,y.undoState.actions=R.actions,y.undoState.textRanges=[U]}return v.setChangeState(y),{unitId:e,actions:C,textRanges:h}}};function Z(s){return s===n.DataStreamTreeTokenType.CUSTOM_RANGE_END||s===n.DataStreamTreeTokenType.CUSTOM_RANGE_START}function Pe(s,o,e,t){return s<=e&&o>=e||s>=e&&s<=t}function we(s,o,e,t){const r=t.slice(e.startIndex+1,e.endIndex),a=Math.max(s-(e.startIndex+1),0),i=s+o-1-(e.startIndex+1);if(i<0)return!1;if(a===0&&i>=r.length)return!0;const d=r.slice(0,a)+r.slice(a+o);for(let c=0,u=d.length;c<u;c++){const l=d[c];if(!Z(l))return!1}return!0}var P=(s=>(s[s.LEFT=0]="LEFT",s[s.RIGHT=1]="RIGHT",s))(P||{});function ee(s){const{startOffset:o,endOffset:e,collapsed:t}=s,r=Math.min(o,e),a=Math.max(o,e);return{startOffset:r,endOffset:a,collapsed:t}}function Be(s,o){let{startOffset:e,endOffset:t}=ee(s);for(;o.dataStream[e-1]===n.DataStreamTreeTokenType.CUSTOM_RANGE_START;)e-=1;for(;o.dataStream[t]===n.DataStreamTreeTokenType.CUSTOM_RANGE_END;)t+=1;return{startOffset:e,endOffset:t}}function te(s,o,e=P.LEFT){var d;let{startOffset:t,endOffset:r,collapsed:a}=ee(s);if(a)if(e===P.LEFT)for(;Z(o.dataStream[t-1]);)r-=1,t-=1;else for(;Z(o.dataStream[t]);)r+=1,t+=1;else{const c=Be(s,o);t=c.startOffset,r=c.endOffset}a=t===r;const i=(d=o.customRanges)==null?void 0:d.filter(c=>!c.wholeEntity||t<=c.startIndex&&r>c.endIndex?!1:Xe(t,a?r:r-1,c.startIndex,c.endIndex));return i!=null&&i.length&&i.forEach(c=>{t=Math.min(c.startIndex,t),r=Math.max(c.endIndex+1,r)}),{...s,startOffset:t,endOffset:r,collapsed:t===r}}function fe(s,o){let{startOffset:e,endOffset:t,collapsed:r}=ee(s);if(r){for(;o.dataStream[t]===n.DataStreamTreeTokenType.CUSTOM_RANGE_END;)t+=1,e+=1;for(;o.dataStream[t-1]===n.DataStreamTreeTokenType.CUSTOM_RANGE_START;)t-=1,e-=1;return{startOffset:e,endOffset:t,collapsed:r}}else return{...Be(s,o),collapsed:!1}}function $t(s,o){if(s.startOffset===s.endOffset)return null;const e=o.customRanges;if(!e)return ee(s);let{startOffset:t,endOffset:r}=Be(s,o);for(;Z(o.dataStream[t]);){if(o.dataStream[t]===n.DataStreamTreeTokenType.CUSTOM_RANGE_START){const a=e.find(i=>i.startIndex===t);if(!a)throw new Error("No custom-range matched");if(a.endIndex===r-1)return{startOffset:t,endOffset:r,collapsed:!1};if(a.endIndex<r-1)break}t+=1}for(;Z(o.dataStream[r-1]);){if(o.dataStream[t]===n.DataStreamTreeTokenType.CUSTOM_RANGE_END){const a=e.find(i=>i.endIndex===r-1);if(!a)throw new Error("No custom-range matched");if(a.startIndex===t)return{startOffset:t,endOffset:r,collapsed:!1};if(a.startIndex>t)break}r-=1}return r<=t?null:{startOffset:t,endOffset:r,collapsed:!1}}const zt=[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 Ht(s,o,e){const t=s.slice(o,e);return zt.reduce((r,a)=>r.replaceAll(a,""),t)}function Xe(s,o,e,t){return Math.max(s,e)<=Math.min(o,t)}function Le(s,o,e="",t=0){var p;const{startOffset:r,endOffset:a}=te(s,o),i=[],{paragraphs:d=[],dataStream:c}=o,u=r-t,l=a-t,g=d==null?void 0:d.find(h=>h.startIndex-t>=u&&h.startIndex-t<l),m=(p=o.customRanges)==null?void 0:p.filter(h=>Pe(h.startIndex,h.endIndex,r,a)),f=new Set(m==null?void 0:m.filter(h=>we(r,a-r,h,c))),S=new Set;if(m==null||m.forEach(h=>{f.has(h)||(h.startIndex-t>=u&&h.startIndex-t<=l&&h.endIndex-t>l&&S.add(h.startIndex),h.endIndex-t>=u&&h.endIndex-t<=l&&h.startIndex<u&&S.add(h.endIndex))}),u>0&&i.push({t:n.TextXActionType.RETAIN,len:u,segmentId:e}),g&&g.startIndex-t>u){const h=g.startIndex-t;S.add(h)}const T=[...S].sort((h,v)=>h-v);let I=u;return T.forEach(h=>{const v=h-I;v>0&&i.push({t:n.TextXActionType.DELETE,len:v,line:0,segmentId:e}),i.push({t:n.TextXActionType.RETAIN,len:1,segmentId:e}),I=h+1}),I<l&&i.push({t:n.TextXActionType.DELETE,len:l-I,line:0,segmentId:e}),i}function Vt(s,o){var f,S;const{unitId:e,body:t}=o,a=s.get(n.IUniverInstanceService).getUnit(e),i=s.get(exports.TextSelectionManagerService);if(!a)return!1;const d=a.getBody(),c=(f=o.selection)!=null?f:i.getActiveRange();if(!c||!d)return!1;const u=(S=o.textRanges)!=null?S:[{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}},g=new n.TextX,m=n.JSONX.getInstance();return g.push(...Le(c,d)),g.push({t:n.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0}),l.params.actions=m.editOp(g.serialize()),l}var ne=(s=>(s.MAIN="__Document_Render_Main__",s.BACKGROUND="__Document_Render_Background__",s))(ne||{}),at=(s=>(s.VIEW_MAIN="viewMain",s.VIEW_TOP="viewTop",s.VIEW_LEFT="viewLeft",s.VIEW_LEFT_TOP="viewLeftTop",s))(at||{});const Jt=0,Wt=2,Yt=4,Kt=10,Zt="normalTextSelectionPluginName";function qt(s){const{mainComponent:o,scene:e,engine:t,components:r}=s,a=o,i=r.get(ne.BACKGROUND);return{document:a,docBackground:i,scene:e,engine:t}}function it(s,o){const e=s.getCurrentUnitForType(n.UniverInstanceType.UNIVER_DOC);if(!e)return null;const t=e.getUnitId(),r=o.getRenderById(t);if(r==null)return;const{mainComponent:a,scene:i,engine:d,components:c}=r,u=a,l=c.get(ne.BACKGROUND);return{document:u,docBackground:l,scene:i,engine:d}}function Qt(s,o){const e=o.getRenderById(s);if(e==null)return;const{mainComponent:t,scene:r,engine:a,components:i}=e,d=t,c=i.get(ne.BACKGROUND);return{document:d,docBackground:c,scene:r,engine:a}}class Se{constructor(){A(this,"_customRangeHooks",[])}addClipboardHook(o){return this._customRangeHooks.push(o),n.toDisposable(()=>{const e=this._customRangeHooks.indexOf(o);e>-1&&this._customRangeHooks.splice(e,1)})}copyCustomRange(o,e){let t={...e};return this._customRangeHooks.forEach(r=>{r.onCopyCustomRange&&(t=r.onCopyCustomRange(o,t))}),t}}function pe(s,o="",e,t){var T;const{startOffset:r,endOffset:a}=s,i=[],d=r-e,c=a-e,u=t.dataStream,l=(T=t.customRanges)==null?void 0:T.filter(I=>Pe(I.startIndex,I.endIndex,r,a)),g=new Set(l==null?void 0:l.filter(I=>we(r,a-r,I,u))),m=new Set;l==null||l.forEach(I=>{g.has(I)||(I.startIndex-e>=d&&I.startIndex-e<=c&&I.endIndex-e>c&&m.add(I.startIndex),I.endIndex-e>=d&&I.endIndex-e<=c&&I.startIndex<d&&m.add(I.endIndex))}),d>0&&i.push({t:n.TextXActionType.RETAIN,len:d,segmentId:o});const f=[...m].sort((I,p)=>I-p);let S=d;return f.forEach(I=>{const p=I-S;p>0&&i.push({t:n.TextXActionType.DELETE,len:p,line:0,segmentId:o}),i.push({t:n.TextXActionType.RETAIN,len:1,segmentId:o}),S=I+1}),S<c&&(i.push({t:n.TextXActionType.DELETE,len:c-S,line:0,segmentId:o}),S=c+1),{dos:i,cursor:S,retain:m.size}}function ct(s,o){var t;return(t=s.get(N.IRenderManagerService).getRenderById(o))==null?void 0:t.with(exports.DocSkeletonManagerService)}function w(s,o=""){if(!o)return["body"];const{headers:e,footers:t}=s.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[o])!=null)return["headers",o,"body"];if((t==null?void 0:t[o])!=null)return["footers",o,"body"];throw new Error("Segment id not found in headers or footers")}const dt="doc.command.insert-text",q={id:dt,type:n.CommandType.COMMAND,handler:async(s,o)=>{var M;const e=s.get(n.ICommandService),{range:t,segmentId:r,body:a,unitId:i,textRanges:d,cursorOffset:c}=o,u=s.get(exports.TextSelectionManagerService),g=s.get(n.IUniverInstanceService).getUnit(i,n.UniverInstanceType.UNIVER_DOC);if(g==null)return!1;const m=u.getActiveRange(),f=g.getSelfOrHeaderFooterModel((M=m==null?void 0:m.segmentId)!=null?M:"").getBody();if(!f)return!1;const S=fe(t,f),{startOffset:T,collapsed:I}=S,p=c!=null?c:a.dataStream.length,h=[{startOffset:T+p,endOffset:T+p,style:m==null?void 0:m.style,collapsed:I}],v={id:b.id,params:{unitId:i,actions:[],textRanges:d!=null?d:h,debounce:!0}},_=new n.TextX,D=n.JSONX.getInstance();if(I)T>0&&_.push({t:n.TextXActionType.RETAIN,len:T,segmentId:r});else{const{dos:O,retain:x}=pe(S,r,0,f);_.push(...O),d||(v.params.textRanges=[{startOffset:T+p+x,endOffset:T+p+x,collapsed:I}])}_.push({t:n.TextXActionType.INSERT,body:a,len:a.dataStream.length,line:0,segmentId:r});const C=w(g,r);return v.params.actions=D.editOp(_.serialize(),C),!!e.syncExecuteCommand(v.id,v.params)}},H={id:"doc.command.delete-text",type:n.CommandType.COMMAND,handler:async(s,o)=>{var O;const e=s.get(n.ICommandService),t=s.get(n.IUniverInstanceService),{range:r,segmentId:a,unitId:i,direction:d,len:c=1}=o,u=t.getUnit(i,n.UniverInstanceType.UNIVER_DOC),l=u==null?void 0:u.getSelfOrHeaderFooterModel(a).getBody();if(u==null||l==null)return!1;const{startOffset:g}=r,m=l.dataStream,f=d===P.LEFT?g-c:g,S=f+c-1,T=(O=l.customRanges)==null?void 0:O.filter(x=>Pe(x.startIndex,x.endIndex,f,S)),I=T==null?void 0:T.filter(x=>we(f,c,x,m)),p=[];for(let x=0;x<c;x++)p.push(f+x);I==null||I.forEach(x=>{p.push(x.startIndex,x.endIndex)}),p.sort((x,R)=>x-R);const h=p[0],v={id:b.id,params:{unitId:i,actions:[],textRanges:[{startOffset:h,endOffset:h,collapsed:!0}],debounce:!0}},_=new n.TextX,D=n.JSONX.getInstance();let C=0;for(let x=0;x<p.length;x++){const R=p[x];R-C>0&&_.push({t:n.TextXActionType.RETAIN,len:R-C,segmentId:a}),_.push({t:n.TextXActionType.DELETE,len:1,segmentId:a,line:0}),C=R+1}const y=w(u,a);return v.params.actions=D.editOp(_.serialize(),y),!!e.syncExecuteCommand(v.id,v.params)}},Fe={id:"doc.command.update-text",type:n.CommandType.COMMAND,handler:async(s,o)=>{const{range:e,segmentId:t,updateBody:r,coverType:a,unitId:i,textRanges:d}=o,c=s.get(n.ICommandService),l=s.get(n.IUniverInstanceService).getCurrentUniverDocInstance();if(l==null)return!1;const g={id:b.id,params:{unitId:i,actions:[],textRanges:d}},m=new n.TextX,f=n.JSONX.getInstance(),{startOffset:S,endOffset:T}=e;m.push({t:n.TextXActionType.RETAIN,len:S,segmentId:t}),m.push({t:n.TextXActionType.RETAIN,body:r,len:T-S,segmentId:t,coverType:a});const I=w(l,t);return g.params.actions=f.editOp(m.serialize(),I),!!c.syncExecuteCommand(g.id,g.params)}};function We(s,o){const e=[];for(let t=0,r=s.length;t<r;t++)s[t]===n.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});if(o)for(const t of e)o.bullet&&(t.bullet=n.Tools.deepClone(o.bullet)),o.paragraphStyle&&(t.paragraphStyle=n.Tools.deepClone(o.paragraphStyle));return e}const lt={id:"doc.command.break-line",type:n.CommandType.COMMAND,handler:async s=>{var S,T;const o=s.get(exports.TextSelectionManagerService),e=s.get(n.IUniverInstanceService),t=s.get(n.ICommandService),r=s.get(Se),a=o.getActiveRange();if(a==null)return!1;const{segmentId:i}=a,d=e.getCurrentUniverDocInstance(),c=d==null?void 0:d.getSelfOrHeaderFooterModel(i).getBody();if(!d||!c)return!1;const u=d.getUnitId(),{startOffset:l,endOffset:g}=fe(a,c),f=((S=c.paragraphs)!=null?S:[]).find(I=>I.startIndex>=l);if(f&&f.startIndex>g){const I=n.normalizeBody(n.getBodySlice(c,g,f.startIndex));I.customRanges=(T=I.customRanges)==null?void 0:T.map(v=>r.copyCustomRange(u,v));const p={startOffset:l,endOffset:f.startIndex,collapsed:!1};return n.updateAttributeByInsert(I,{dataStream:n.DataStreamTreeTokenType.PARAGRAPH,paragraphs:We(n.DataStreamTreeTokenType.PARAGRAPH,f)},1,0),await t.executeCommand(q.id,{unitId:u,body:I,range:p,segmentId:i,cursorOffset:1})}else return await t.executeCommand(q.id,{unitId:u,body:{dataStream:n.DataStreamTreeTokenType.PARAGRAPH,paragraphs:We(n.DataStreamTreeTokenType.PARAGRAPH,f)},range:a,segmentId:i})}},en={id:"doc.command.inner-paste",type:n.CommandType.COMMAND,handler:async(s,o)=>{const{segmentId:e,textRanges:t,body:r}=o,a=s.get(n.ICommandService),i=s.get(exports.TextSelectionManagerService),d=s.get(n.IUniverInstanceService),c=i.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 g=u.getUnitId(),m={id:b.id,params:{unitId:g,actions:[],textRanges:t}},f=new n.MemoryCursor;f.reset();const S=new n.TextX,T=n.JSONX.getInstance();for(const h of c){const{startOffset:v,endOffset:_,collapsed:D}=h,C=v-f.cursor;if(D)S.push({t:n.TextXActionType.RETAIN,len:C,segmentId:e});else{const{dos:y}=pe(h,e,f.cursor,l);S.push(...y)}S.push({t:n.TextXActionType.INSERT,body:r,len:r.dataStream.length,line:0,segmentId:e}),f.reset(),f.moveCursor(_)}const I=w(u,e);return m.params.actions=T.editOp(S.serialize(),I),!!a.syncExecuteCommand(m.id,m.params)}},ke={id:"doc.command.inner-cut",type:n.CommandType.COMMAND,handler:async(s,o)=>{var C,y,M,O;const{segmentId:e,textRanges:t}=o,r=s.get(n.ICommandService),a=s.get(exports.TextSelectionManagerService),i=s.get(n.IUniverInstanceService),d=(C=o.selections)!=null?C:a.getCurrentSelections();if(!Array.isArray(d)||d.length===0)return!1;const c=(y=i.getCurrentUniverDocInstance())==null?void 0:y.getUnitId();if(!c)return!1;const u=i.getUniverDocInstance(c),l=n.getDocsUpdateBody(u.getSnapshot(),e);if(u==null||l==null)return!1;const g={id:b.id,params:{unitId:c,actions:[],textRanges:t}},m=new n.MemoryCursor;m.reset();const f=new n.TextX,S=n.JSONX.getInstance(),T=[];for(const x of d){const{startOffset:R,endOffset:E,collapsed:U}=x;if(R==null||E==null)continue;const F=R-m.cursor;U?f.push({t:n.TextXActionType.RETAIN,len:F,segmentId:e}):f.push(...Le(x,l,e,m.cursor)),m.reset(),m.moveCursor(E)}const I=w(u,e);T.push(S.editOp(f.serialize(),I));const p=tn(l,d),h=(M=u.getDrawings())!=null?M:{},v=(O=u.getDrawingsOrder())!=null?O:[],_=p.sort((x,R)=>v.indexOf(x)>v.indexOf(R)?-1:v.indexOf(x)<v.indexOf(R)?1:0);if(_.length>0)for(const x of _){const R=h[x],E=v.indexOf(x);if(R==null||E<0)continue;const U=S.removeOp(["drawings",x],R),F=S.removeOp(["drawingsOrder",E],x);T.push(U),T.push(F)}return g.params.actions=T.reduce((x,R)=>n.JSONX.compose(x,R),null),!!r.syncExecuteCommand(g.id,g.params)}};function tn(s,o){const e=[],{customBlocks:t=[]}=s;for(const r of o){const{startOffset:a,endOffset:i}=r;if(!(a==null||i==null))for(const d of t){const{startIndex:c}=d;c>=a&&c<i&&e.push(d.blockId)}}return e}const Ie={id:"doc.command.delete-custom-block",type:n.CommandType.COMMAND,handler:async(s,o)=>{var R;const e=s.get(exports.TextSelectionManagerService),t=s.get(n.IUniverInstanceService),r=s.get(n.ICommandService),a=e.getActiveRange(),i=t.getCurrentUniverDocInstance();if(a==null||i==null)return!1;const{direction:d,range:c,unitId:u,drawingId:l}=o,{startOffset:g,segmentId:m,style:f}=a,S=d===P.LEFT?g-1:g,T=[{startOffset:S,endOffset:S,style:f}],I={id:b.id,params:{unitId:u,actions:[],textRanges:T,prevTextRanges:[c]}},p=new n.TextX,h=n.JSONX.getInstance(),v=[];g>0&&p.push({t:n.TextXActionType.RETAIN,len:d===P.LEFT?g-1:g,segmentId:m}),p.push({t:n.TextXActionType.DELETE,len:1,line:0,segmentId:m});const _=w(i,m);v.push(h.editOp(p.serialize(),_));const D=((R=i.getDrawings())!=null?R:{})[l],y=i.getDrawingsOrder().indexOf(l),M=h.removeOp(["drawings",l],D),O=h.removeOp(["drawingsOrder",y],l);return v.push(M),v.push(O),I.params.actions=v.reduce((E,U)=>n.JSONX.compose(E,U),null),!!r.syncExecuteCommand(I.id,I.params)}},he={id:"doc.command.merge-two-paragraph",type:n.CommandType.COMMAND,handler:async(s,o)=>{var R,E;const e=s.get(exports.TextSelectionManagerService),t=s.get(n.IUniverInstanceService),r=s.get(n.ICommandService),{direction:a,range:i}=o,d=e.getActiveRange(),c=e.getCurrentSelections();if(d==null||c==null)return!1;const{segmentId:u,style:l}=d,g=t.getCurrentUniverDocInstance(),m=g==null?void 0:g.getSelfOrHeaderFooterModel(u).getBody();if(!g||!m)return!1;const f=te(d,m),S=g.getUnitId(),{startOffset:T,collapsed:I}=f;if(!I)return!1;const p=a===P.LEFT?T:T+1,h=(E=(R=m.paragraphs)==null?void 0:R.find(U=>U.startIndex>=p))==null?void 0:E.startIndex,v=nn(s,S,m,p,h),_=a===P.LEFT?T-1:T,D=[{startOffset:_,endOffset:_,style:l}],C={id:b.id,params:{unitId:S,actions:[],textRanges:D,prevTextRanges:[i]}},y=new n.TextX,M=n.JSONX.getInstance();y.push({t:n.TextXActionType.RETAIN,len:a===P.LEFT?T-1:T,segmentId:u}),v.dataStream.length&&y.push({t:n.TextXActionType.INSERT,body:v,len:v.dataStream.length,line:0,segmentId:u}),y.push({t:n.TextXActionType.RETAIN,len:1,segmentId:u}),y.push({t:n.TextXActionType.DELETE,len:h+1-p,line:0,segmentId:u});const O=w(g,u);return C.params.actions=M.editOp(y.serialize(),O),!!r.syncExecuteCommand(C.id,C.params)}},ut={id:"doc.command.delete-left",type:n.CommandType.COMMAND,handler:async s=>{var M,O;const o=s.get(exports.TextSelectionManagerService),e=s.get(n.IUniverInstanceService),t=s.get(n.ICommandService);let r=!0;const a=e.getCurrentUniverDocInstance();if(!a)return!1;const i=a.getUnitId(),d=ct(s,i),c=o.getActiveRange(),u=o.getCurrentSelections(),l=d==null?void 0:d.getSkeleton();if(c==null||l==null||u==null)return!1;const{segmentId:g,style:m,segmentPage:f}=c,S=a.getSelfOrHeaderFooterModel(g).getBody();if(S==null)return!1;const T=te(c,S),{startOffset:I,collapsed:p}=T,h=l.findNodeByCharIndex(I,g,f),v=N.hasListGlyph(h),_=N.isIndentByGlyph(h,S);let D=I;const C=l.findNodeByCharIndex(I-1,g,f);if(N.isFirstGlyph(h)&&C!==h&&(v===!0||_===!0)&&p){const x=N.getParagraphByGlyph(h,S);if(x==null)return!1;const R=x==null?void 0:x.startIndex,E={startIndex:0},U=x.paragraphStyle;if(v===!0){const L=x.paragraphStyle;if(L){E.paragraphStyle=L;const{hanging:W}=L;W&&(E.paragraphStyle.indentStart=W,E.paragraphStyle.hanging=void 0)}}else if(_===!0){const L=x.bullet;L&&(E.bullet=L),U!=null&&(E.paragraphStyle={...U},delete E.paragraphStyle.hanging,delete E.paragraphStyle.indentStart)}const F=[{startOffset:D,endOffset:D,style:m}];r=await t.executeCommand(Fe.id,{unitId:a.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...E}]},range:{startOffset:R,endOffset:R+1},textRanges:F,coverType:n.UpdateDocsAttributeType.REPLACE,segmentId:g})}else if(p===!0){if(C==null)return!0;if(C.content==="\r")r=await t.executeCommand(he.id,{direction:P.LEFT,range:T});else if(C.streamType==="\b"){const x=(O=a.getSnapshot().drawings)==null?void 0:O[(M=C.drawingId)!=null?M:""];if(x==null)return!0;if(x.layoutType===n.PositionedObjectLayoutType.INLINE){const E=a.getUnitId();r=await t.executeCommand(Ie.id,{direction:P.LEFT,range:c,unitId:E,drawingId:C.drawingId})}else{const E=l.findNodeByCharIndex(I-2);if(E==null)return!0;D-=C.count,D-=E.count;const U=[{startOffset:D,endOffset:D,style:m}];r=await t.executeCommand(H.id,{unitId:a.getUnitId(),range:{...c,startOffset:c.startOffset-1,endOffset:c.endOffset-1},segmentId:g,direction:P.LEFT,len:E.count,textRanges:U})}}else D-=C.count,r=await t.executeCommand(H.id,{unitId:a.getUnitId(),range:T,segmentId:g,direction:P.LEFT,len:C.count})}else{const x=gt(T,[T]);r=await t.executeCommand(ke.id,{segmentId:g,textRanges:x,selections:[T]})}return r}},mt={id:"doc.command.delete-right",type:n.CommandType.COMMAND,handler:async s=>{var h,v;const o=s.get(exports.TextSelectionManagerService),t=s.get(n.IUniverInstanceService).getCurrentUniverDocInstance();if(!t)return!1;const r=ct(s,t.getUnitId()),a=s.get(n.ICommandService),i=o.getActiveRange(),d=o.getCurrentSelections(),c=r==null?void 0:r.getSkeleton();if(i==null||c==null||d==null)return!1;const{segmentId:u,style:l,segmentPage:g}=i,m=t==null?void 0:t.getSelfOrHeaderFooterModel(u).getBody();if(!t||!m)return!1;const f=te(i,m,P.RIGHT),{startOffset:S,endOffset:T,collapsed:I}=f;if(S===m.dataStream.length-2&&I)return!0;let p=!1;if(I===!0){const _=c.findNodeByCharIndex(S,u,g),D=c.findNodeByCharIndex(S+1);if(_.content==="\r")p=await a.executeCommand(he.id,{direction:P.RIGHT,range:i});else if(_.streamType==="\b"){const C=(v=t.getSnapshot().drawings)==null?void 0:v[(h=_.drawingId)!=null?h:""];if(C==null)return!0;if(C.layoutType===n.PositionedObjectLayoutType.INLINE){const M=t.getUnitId();p=await a.executeCommand(Ie.id,{direction:P.RIGHT,range:i,unitId:M,drawingId:_.drawingId})}else{if(D==null)return!0;const M=[{startOffset:S+1,endOffset:S+1,style:l}];p=await a.executeCommand(H.id,{unitId:t.getUnitId(),range:{...i,startOffset:S+1,endOffset:T+1},segmentId:u,direction:P.RIGHT,textRanges:M,len:D.count})}}else{const C=[{startOffset:S,endOffset:S,style:l}];p=await a.executeCommand(H.id,{unitId:t.getUnitId(),range:f,segmentId:u,direction:P.RIGHT,textRanges:C,len:_.count})}}else{const _=gt(f,[f]);p=await a.executeCommand(ke.id,{segmentId:u,textRanges:_,selections:[f]})}return p}};function nn(s,o,e,t,r){const{textRuns:a=[],customBlocks:i=[]}=e,d=e.dataStream.substring(t,r),c=s.get(Se),u={dataStream:d,customRanges:n.getCustomRangeSlice(e,t,r).customRanges.map(m=>c.copyCustomRange(o,m)),customDecorations:n.getCustomDecorationSlice(e,t,r)},l=[];for(const m of a){const{st:f,ed:S}=m;S<=t||f>=r||(f<t?l.push({...m,st:0,ed:S-t}):S>r?l.push({...m,st:f-t,ed:r-t}):l.push({...m,st:f-t,ed:S-t}))}l.length>0&&(u.textRuns=l);const g=[];for(const m of i){const{startIndex:f}=m;f>=t&&f<=r&&g.push({...m,startIndex:f-t})}return g.length>0&&(u.customBlocks=g),u}function gt(s,o){let e=s.endOffset;for(const r of o){const{startOffset:a,endOffset:i}=r;a==null||i==null||i<=s.endOffset&&(e-=i-a)}return[{startOffset:e,endOffset:e,style:s.style}]}const Ge={id:"doc.command.ime-input",type:n.CommandType.COMMAND,handler:async(s,o)=>{const{unitId:e,newText:t,oldTextLen:r,isCompositionEnd:a,isCompositionStart:i}=o,d=s.get(n.ICommandService),c=s.get(Q),l=s.get(n.IUniverInstanceService).getCurrentUniverDocInstance();if(l==null)return!1;const g=c.getActiveRange();if(!g)return!1;const{startOffset:m,style:f,segmentId:S}=g,T=l.getSelfOrHeaderFooterModel(S).getBody();if(T==null)return!1;const I=fe(g,T);Object.assign(g,I);const p=t.length,h=[{startOffset:m+p,endOffset:m+p,collapsed:!0,style:f}],v={id:b.id,params:{unitId:e,actions:[],textRanges:h}},_=new n.TextX,D=n.JSONX.getInstance();if(!g.collapsed&&i){const{dos:M,retain:O,cursor:x}=pe(g,S,0,T);_.push(...M),v.params.textRanges=[{startOffset:m+p+O,endOffset:m+p+O,collapsed:!0}]}else _.push({t:n.TextXActionType.RETAIN,len:m,segmentId:S});r>0&&_.push({t:n.TextXActionType.DELETE,len:r,line:0,segmentId:S}),_.push({t:n.TextXActionType.INSERT,body:{dataStream:t},len:t.length,line:0,segmentId:S});const C=w(l,S);v.params.actions=D.editOp(_.serialize(),C),v.params.noHistory=!a,v.params.isCompositionEnd=a;const y=d.syncExecuteCommand(v.id,v.params);return c.pushUndoRedoMutationParams(y,v.params),!!y}};function X(s,o,e,t){var a;const{segmentId:r}=(a=e.getActiveRange())!=null?a:{};return r==null?!1:t.executeCommand(je.id,{segmentId:r,preCommandId:s,...o!=null?o:{}})}const Ye="doc.command.set-inline-format-bold",Te={id:Ye,type:n.CommandType.COMMAND,handler:async(s,o)=>{const e=s.get(n.ICommandService),t=s.get(exports.TextSelectionManagerService);return X(Ye,o,t,e)}},Ke="doc.command.set-inline-format-italic",ve={id:Ke,type:n.CommandType.COMMAND,handler:async(s,o)=>{const e=s.get(n.ICommandService),t=s.get(exports.TextSelectionManagerService);return X(Ke,o,t,e)}},Ze="doc.command.set-inline-format-underline",Ce={id:Ze,type:n.CommandType.COMMAND,handler:async(s,o)=>{const e=s.get(n.ICommandService),t=s.get(exports.TextSelectionManagerService);return X(Ze,o,t,e)}},qe="doc.command.set-inline-format-strikethrough",xe={id:qe,type:n.CommandType.COMMAND,handler:async(s,o)=>{const e=s.get(n.ICommandService),t=s.get(exports.TextSelectionManagerService);return X(qe,o,t,e)}},Qe="doc.command.set-inline-format-subscript",V={id:Qe,type:n.CommandType.COMMAND,handler:async(s,o)=>{const e=s.get(n.ICommandService),t=s.get(exports.TextSelectionManagerService);return X(Qe,o,t,e)}},et="doc.command.set-inline-format-superscript",ye={id:et,type:n.CommandType.COMMAND,handler:async(s,o)=>{const e=s.get(n.ICommandService),t=s.get(exports.TextSelectionManagerService);return X(et,o,t,e)}},tt="doc.command.set-inline-format-fontsize",_e={id:tt,type:n.CommandType.COMMAND,handler:async(s,o)=>{const e=s.get(n.ICommandService),t=s.get(exports.TextSelectionManagerService);return X(tt,o,t,e)}},nt="doc.command.set-inline-format-font-family",Oe={id:nt,type:n.CommandType.COMMAND,handler:async(s,o)=>{const e=s.get(n.ICommandService),t=s.get(exports.TextSelectionManagerService);return X(nt,o,t,e)}},ot="doc.command.set-inline-format-text-color",Re={id:ot,type:n.CommandType.COMMAND,handler:async(s,o)=>{const e=s.get(n.ICommandService),t=s.get(exports.TextSelectionManagerService);return X(ot,o,t,e)}},rt="doc.command.set-inline-format-text-background-color",Me={id:rt,type:n.CommandType.COMMAND,handler:async(s,o)=>{const e=s.get(n.ICommandService),t=s.get(exports.TextSelectionManagerService);return X(rt,o,t,e)}},st="doc.command.reset-inline-format-text-background-color",De={id:st,type:n.CommandType.COMMAND,handler:async(s,o)=>{const e=s.get(n.ICommandService),t=s.get(exports.TextSelectionManagerService);return X(st,o,t,e)}},ft={[Te.id]:"bl",[ve.id]:"it",[Ce.id]:"ul",[xe.id]:"st",[_e.id]:"fs",[Oe.id]:"ff",[Re.id]:"cl",[Me.id]:"bg",[De.id]:"bg",[V.id]:"va",[ye.id]:"va"},je={id:"doc.command.set-inline-format",type:n.CommandType.COMMAND,handler:async(s,o)=>{const{segmentId:e,value:t,preCommandId:r}=o,a=s.get(n.ICommandService),i=s.get(exports.TextSelectionManagerService),d=s.get(n.IUniverInstanceService),c=i.getCurrentSelections();if(!Array.isArray(c)||c.length===0)return!1;const u=d.getCurrentUniverDocInstance();if(u==null)return!1;const l=u.getUnitId();let g;switch(r){case Te.id:case ve.id:case Ce.id:case xe.id:case V.id:case ye.id:{g=rn(u.getSelfOrHeaderFooterModel(e).getBody().textRuns,r,c);break}case _e.id:case Oe.id:{g=t;break}case Re.id:case Me.id:{g={rgb:t};break}case De.id:{g={rgb:null};break}default:throw new Error(`Unknown command: ${r} in handleInlineFormat`)}const m={id:b.id,params:{unitId:l,actions:[],textRanges:c.map(z)}},f=new n.TextX,S=n.JSONX.getInstance(),T=new n.MemoryCursor;T.reset();for(const h of c){const{startOffset:v,endOffset:_}=h,D={dataStream:"",textRuns:[{st:0,ed:_-v,ts:{[ft[r]]:g}}]},C=v-T.cursor;C!==0&&f.push({t:n.TextXActionType.RETAIN,len:C,segmentId:e}),f.push({t:n.TextXActionType.RETAIN,body:D,len:_-v,segmentId:e}),T.reset(),T.moveCursor(_)}const I=w(u,e);return m.params.actions=S.editOp(f.serialize(),I),!!a.syncExecuteCommand(m.id,m.params)}};function on(s){return s!==null&&typeof s=="object"}function rn(s,o,e){let t=0,r=0;const a=ft[o];for(;t!==s.length&&r!==e.length;){const{startOffset:i,endOffset:d}=e[r],{st:c,ed:u,ts:l}=s[t];if(d<=c)r++;else if(u<=i)t++;else{if(/bl|it/.test(a))return(l==null?void 0:l[a])===n.BooleanNumber.TRUE?n.BooleanNumber.FALSE:n.BooleanNumber.TRUE;if(/ul|st/.test(a))return on(l==null?void 0:l[a])&&(l==null?void 0:l[a]).s===n.BooleanNumber.TRUE?{s:n.BooleanNumber.FALSE}:{s:n.BooleanNumber.TRUE};if(/va/.test(a))return o===V.id?(l==null?void 0:l[a])===n.BaselineOffset.SUBSCRIPT?n.BaselineOffset.NORMAL:n.BaselineOffset.SUBSCRIPT:(l==null?void 0:l[a])===n.BaselineOffset.SUPERSCRIPT?n.BaselineOffset.NORMAL:n.BaselineOffset.SUPERSCRIPT;t++}}return/bl|it/.test(a)?n.BooleanNumber.TRUE:/ul|st/.test(a)?{s:n.BooleanNumber.TRUE}:o===V.id?n.BaselineOffset.SUBSCRIPT:n.BaselineOffset.SUPERSCRIPT}const Ee={id:"doc.command.list-operation",type:n.CommandType.COMMAND,handler:(s,o)=>{var R,E,U,F,L,W;const e=s.get(exports.TextSelectionManagerService),t=s.get(n.IUniverInstanceService),r=s.get(n.ICommandService),{listType:a}=o,i=t.getCurrentUniverDocInstance(),d=e.getActiveRange();if(i==null||d==null)return!1;const{segmentId:c}=d,u=(R=e.getCurrentSelections())!=null?R:[],l=(E=i.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:E.paragraphs,g=u.map(z);if(l==null)return!1;const m=(F=(U=i.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:U.sectionBreaks)!=null?F:[],f=It(d,l),S=i.getUnitId(),T=f.every(G=>{var B;return((B=G.bullet)==null?void 0:B.listType)===a});let p=n.Tools.generateRandomId(6);if(f.length===1){const G=l.indexOf(f[0]),B=l[G-1],k=l[G+1];B&&B.bullet&&B.bullet.listType===a?p=B.bullet.listId:k&&k.bullet&&k.bullet.listType===a&&(p=k.bullet.listId)}const h={id:b.id,params:{unitId:S,actions:[],textRanges:g}},v=new n.MemoryCursor;v.reset();const _=new n.TextX,D=n.JSONX.getInstance(),C=(L=i.getSnapshot().lists)!=null?L:{},y={...n.PRESET_LIST_TYPE,...C},{defaultTabStop:M=36}=i.getSnapshot().documentStyle;for(const G of f){const{startIndex:B,paragraphStyle:k={}}=G,{indentFirstLine:Dt,snapToGrid:Et,indentStart:Ae}=k,{hanging:Ne,indentStart:$e}=y[a].nestingLevel[0],{charSpace:At,gridType:Nt}=sn(B,m)||{charSpace:0,gridType:n.GridType.LINES},j=N.getCharSpaceApply(At,M,Nt,Et);_.push({t:n.TextXActionType.RETAIN,len:B-v.cursor,segmentId:c}),_.push({t:n.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[T?{paragraphStyle:{...k,hanging:void 0,indentStart:Ae?{v:Math.max(0,N.getNumberUnitValue(Ae,j)+N.getNumberUnitValue(Ne,j)-N.getNumberUnitValue($e,j))}:void 0},startIndex:0}:{startIndex:0,paragraphStyle:{...k,indentFirstLine:void 0,hanging:Ne,indentStart:{v:N.getNumberUnitValue($e,j)-N.getNumberUnitValue(Ne,j)+N.getNumberUnitValue(Dt,j)+N.getNumberUnitValue(Ae,j)}},bullet:{...(W=G.bullet)!=null?W:{nestingLevel:0,textStyle:{fs:20}},listType:a,listId:p}}]},segmentId:c,coverType:n.UpdateDocsAttributeType.REPLACE}),v.moveCursorTo(B+1)}const O=w(i,c);return h.params.actions=D.editOp(_.serialize(),O),!!r.syncExecuteCommand(h.id,h.params)}},St={id:"doc.command.bullet-list",type:n.CommandType.COMMAND,handler:s=>s.get(n.ICommandService).syncExecuteCommand(Ee.id,{listType:n.PresetListType.BULLET_LIST})},pt={id:"doc.command.order-list",type:n.CommandType.COMMAND,handler:s=>s.get(n.ICommandService).syncExecuteCommand(Ee.id,{listType:n.PresetListType.ORDER_LIST})};function It(s,o){const{startOffset:e,endOffset:t}=s,r=[];let a=-1;for(const i of o){const{startIndex:d}=i;(e>a&&e<=d||t>a&&t<=d||d>=e&&d<=t)&&r.push(i),a=d}return r}function sn(s,o){const e=o.sort(n.sortRulesFactory("startIndex"));for(let t=0;t<e.length;t++){const r=o[t];if(r.startIndex>=s)return r}}const ht={id:"doc.command-replace-content",type:n.CommandType.COMMAND,handler:async(s,o)=>{const{unitId:e,body:t,textRanges:r,segmentId:a="",options:i}=o,d=s.get(n.IUniverInstanceService),c=s.get(n.ICommandService),u=s.get(exports.TextSelectionManagerService),l=d.getUniverDocInstance(e),g=l==null?void 0:l.getSnapshot().body,m=u.getCurrentSelections();if(l==null||g==null||!Array.isArray(m)||m.length===0)return!1;const f=vt(e,a,l,g,t);return f.params.textRanges=r,i&&(f.params.options=i),!!c.syncExecuteCommand(f.id,f.params)}},Tt={id:"doc.command-cover-content",type:n.CommandType.COMMAND,handler:async(s,o)=>{const{unitId:e,body:t,segmentId:r=""}=o,a=s.get(n.IUniverInstanceService),i=s.get(n.ICommandService),d=s.get(n.IUndoRedoService),c=a.getUniverDocInstance(e),u=c==null?void 0:c.getSnapshot().body;if(c==null||u==null)return!1;const l=vt(e,r,c,u,t);return l.params.noNeedSetTextRange=!0,l.params.noHistory=!0,i.syncExecuteCommand(l.id,l.params),d.clearUndoRedo(e),!0}};function vt(s,o,e,t,r){const a={id:b.id,params:{unitId:s,actions:[],textRanges:[]}},i=new n.TextX,d=n.JSONX.getInstance(),c=(t==null?void 0:t.dataStream.length)-2;c>0&&i.push({t:n.TextXActionType.DELETE,len:c,line:0,segmentId:o}),r.dataStream.length>0&&i.push({t:n.TextXActionType.INSERT,body:r,len:r.dataStream.length,line:0,segmentId:o});const u=w(e,o);return a.params.actions=d.editOp(i.serialize(),u),a}n.CommandType.COMMAND;const an=(s,o)=>{const e=s.get(n.IUniverInstanceService).getUniverDocInstance(o.unitId),t=(e==null?void 0:e.zoomRatio)||1;return{...n.Tools.deepClone(o),zoomRatio:t}},K={id:"doc.operation.set-zoom-ratio",type:n.CommandType.OPERATION,handler:(s,o)=>{const e=s.get(n.IUniverInstanceService).getUniverDocInstance(o.unitId);if(!e)return!1;const t=e.getSnapshot();return t.settings==null?t.settings={zoomRatio:o.zoomRatio}:t.settings.zoomRatio=o.zoomRatio,!0}},Ct={type:n.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(s,o)=>{var g,m,f;const e=s.get(n.ICommandService),t=s.get(n.IUndoRedoService),r=s.get(n.IUniverInstanceService);let a=(g=r.getCurrentUniverDocInstance())==null?void 0:g.getUnitId();if(!a)return!1;let i=1;if(o&&(a=(m=o.documentId)!=null?m:a,i=(f=o.zoomRatio)!=null?f:i),!r.getUniverDocInstance(a))return!1;const c={zoomRatio:i,unitId:a},u=an(s,c);return e.syncExecuteCommand(K.id,c)?(t.pushUndoRedo({unitID:a,undoMutations:[{id:K.id,params:u}],redoMutations:[{id:K.id,params:c}]}),!0):!1}},ue={id:"doc.operation.move-cursor",type:n.CommandType.OPERATION,handler:(s,o)=>!!o},me={id:"doc.operation.move-selection",type:n.CommandType.OPERATION,handler:(s,o)=>!!o},xt={id:"doc.operation.select-all",type:n.CommandType.COMMAND,handler:async s=>{const o=s.get(n.IUniverInstanceService),e=s.get(exports.TextSelectionManagerService),t=o.getCurrentUniverDocInstance(),r=e.getActiveRange();if(t==null||r==null)return!1;const{segmentId:a}=r,i=t.getSelfOrHeaderFooterModel(a).getSnapshot().body;if(i==null)return!1;const d=[{startOffset:0,endOffset:i.dataStream.length-2}];return e.replaceTextRanges(d,!1),!0}};var cn=Object.defineProperty,dn=Object.getOwnPropertyDescriptor,ln=(s,o,e,t)=>{for(var r=t>1?void 0:t?dn(o,e):o,a=s.length-1,i;a>=0;a--)(i=s[a])&&(r=(t?i(o,e,r):i(r))||r);return t&&r&&cn(o,e,r),r},Y=(s,o)=>(e,t)=>o(e,t,s);let ae=class extends n.Disposable{constructor(o,e,t,r,a){super();A(this,"_previousIMEContent","");A(this,"_isCompositionStart",!0);A(this,"_onStartSubscription");A(this,"_onUpdateSubscription");A(this,"_onEndSubscription");this._univerInstanceService=o,this._renderManagerSrv=e,this._textSelectionRenderManager=t,this._imeInputManagerService=r,this._commandService=a,this._initialize()}dispose(){var o,e,t;(o=this._onStartSubscription)==null||o.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(o=>{if(o==null)return;this._resetIME();const{activeRange:e}=o;e!=null&&this._imeInputManagerService.setActiveRange(n.Tools.deepClone(e))})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._textSelectionRenderManager.onCompositionupdate$.subscribe(async o=>{this._updateContent(o,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._textSelectionRenderManager.onCompositionend$.subscribe(o=>{this._updateContent(o,!1)})}async _updateContent(o,e){var u;if(o==null)return;const t=this._univerInstanceService.getCurrentUniverDocInstance();if(!t)return;const r=(u=this._renderManagerSrv.getRenderById(t.getUnitId()))==null?void 0:u.with(exports.DocSkeletonManagerService).getSkeleton(),{event:a,activeRange:i}=o;if(r==null||i==null)return;const c=a.data;c===this._previousIMEContent&&e||(await this._commandService.executeCommand(Ge.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)}};ae=ln([n.OnLifecycle(n.LifecycleStages.Rendered,ae),Y(0,n.IUniverInstanceService),Y(1,N.IRenderManagerService),Y(2,N.ITextSelectionRenderManager),Y(3,n.Inject(Q)),Y(4,n.ICommandService)],ae);var un=Object.defineProperty,mn=Object.getOwnPropertyDescriptor,gn=(s,o,e,t)=>{for(var r=t>1?void 0:t?mn(o,e):o,a=s.length-1,i;a>=0;a--)(i=s[a])&&(r=(t?i(o,e,r):i(r))||r);return t&&r&&un(o,e,r),r},oe=(s,o)=>(e,t)=>o(e,t,s);let ie=class extends n.Disposable{constructor(o,e,t,r){super();A(this,"_onInputSubscription");this._univerInstanceService=o,this._renderManagerService=e,this._textSelectionManagerService=t,this._commandService=r,this._commandExecutedListener()}dispose(){var o;super.dispose(),(o=this._onInputSubscription)==null||o.unsubscribe()}_commandExecutedListener(){const o=[ue.id,me.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!o.includes(e.id))return;const t=e.params;switch(e.id){case ue.id:return this._handleMoveCursor(t.direction);case me.id:return this._handleShiftMoveSelection(t.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(o){var v,_,D;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getCurrentSelections(),r=this._univerInstanceService.getCurrentUniverDocInstance();if(!r)return;const a=(v=this._renderManagerService.getRenderById(r.getUnitId()))==null?void 0:v.with(exports.DocSkeletonManagerService).getSkeleton(),i=this._getDocObject();if(e==null||a==null||i==null)return;const{startOffset:d,endOffset:c,style:u,collapsed:l,direction:g,segmentId:m,startNodePosition:f,endNodePosition:S,segmentPage:T}=e;if(t.length>1){let C=Number.POSITIVE_INFINITY,y=Number.NEGATIVE_INFINITY;for(const M of t)C=Math.min(C,M.startOffset),y=Math.max(y,M.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:o===n.Direction.LEFT||o===n.Direction.UP?y:C,endOffset:o===n.Direction.LEFT||o===n.Direction.UP?C:y,style:u}],!1);return}const I=l||g===N.RANGE_DIRECTION.FORWARD?d:c;let p=l||g===N.RANGE_DIRECTION.FORWARD?c:d;const h=(_=r.getSelfOrHeaderFooterModel(m).getBody().dataStream.length)!=null?_:Number.POSITIVE_INFINITY;if(o===n.Direction.LEFT||o===n.Direction.RIGHT){const C=a.findNodeByCharIndex(p-1,m,T),y=a.findNodeByCharIndex(p,m,T);p=o===n.Direction.RIGHT?p+y.count:p-((D=C==null?void 0:C.count)!=null?D:0),p=Math.min(h-2,Math.max(0,p)),this._textSelectionManagerService.replaceTextRanges([{startOffset:I,endOffset:p,style:u}],!1)}else{const C=a.findNodeByCharIndex(p,m,T),y=i.document.getOffsetConfig(),M=l?f:g===N.RANGE_DIRECTION.FORWARD?S:f,O=this._getTopOrBottomPosition(a,C,M,o===n.Direction.DOWN);if(O==null){const R=o===n.Direction.UP?0:h-2;if(R===p)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:I,endOffset:R,style:u}],!1);return}const x=new N.NodePositionConvertToCursor(y,a).getRangePointData(O,O).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:I,endOffset:x.endOffset,style:u}],!1)}}_handleMoveCursor(o){var h,v,_,D;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getCurrentSelections(),r=this._univerInstanceService.getCurrentUniverDocInstance();if(!r)return!1;const a=(h=this._renderManagerService.getRenderById(r.getUnitId()))==null?void 0:h.with(exports.DocSkeletonManagerService).getSkeleton(),i=this._getDocObject(),d=r.getBody();if(e==null||a==null||i==null||t==null||d==null)return;const{startOffset:c,endOffset:u,style:l,collapsed:g,segmentId:m,startNodePosition:f,endNodePosition:S,segmentPage:T}=e,I=(v=r.getSelfOrHeaderFooterModel(m).getBody().dataStream.length)!=null?v:Number.POSITIVE_INFINITY,p=(_=r.getCustomRanges())!=null?_:[];if(o===n.Direction.LEFT||o===n.Direction.RIGHT){let C;if(!e.collapsed||t.length>1){let O=Number.POSITIVE_INFINITY,x=Number.NEGATIVE_INFINITY;for(const R of t)O=Math.min(O,R.startOffset),x=Math.max(x,R.endOffset);C=o===n.Direction.LEFT?O:x}else{const O=a.findNodeByCharIndex(c-1,m,T),x=a.findNodeByCharIndex(c,m,T);o===n.Direction.LEFT?C=Math.max(0,c-((D=O==null?void 0:O.count)!=null?D:0)):C=Math.min(I-2,u+x.count)}const y=[n.DataStreamTreeTokenType.CUSTOM_RANGE_START,n.DataStreamTreeTokenType.CUSTOM_RANGE_END];if(o===n.Direction.LEFT)for(;y.includes(d.dataStream[C]);)C--;else for(;y.includes(d.dataStream[C-1]);)C++;p.filter(O=>O.wholeEntity&&O.startIndex<C&&O.endIndex>=C).forEach(O=>{o===n.Direction.LEFT?C=Math.min(O.startIndex,C):C=Math.max(O.endIndex+1,C)}),this._textSelectionManagerService.replaceTextRanges([{startOffset:C,endOffset:C,style:l}],!1)}else{const C=a.findNodeByCharIndex(c,m,T),y=a.findNodeByCharIndex(u,m,T),M=i.document.getOffsetConfig(),O=this._getTopOrBottomPosition(a,o===n.Direction.UP||g?C:y,o===n.Direction.UP||g?f:S,o===n.Direction.DOWN);if(O==null){let R;g?R=o===n.Direction.UP?0:I-2:R=o===n.Direction.UP?c:u,this._textSelectionManagerService.replaceTextRanges([{startOffset:R,endOffset:R,style:l}],!1);return}const x=new N.NodePositionConvertToCursor(M,a).getRangePointData(O,O).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...x,style:l}],!1)}}_getTopOrBottomPosition(o,e,t,r){if(e==null||t==null)return;const a=this._getGlyphLeftOffsetInLine(e),i=this._getNextOrPrevLine(e,r);if(i==null)return;const d=this._matchPositionByLeftOffset(o,i,a,t);if(d!=null)return{...d,isBack:!0}}_getGlyphLeftOffsetInLine(o){const e=o.parent;if(e==null)return Number.NEGATIVE_INFINITY;const t=e.left,{left:r}=o;return t+r}_matchPositionByLeftOffset(o,e,t,r){const a={distance:Number.POSITIVE_INFINITY};for(const d of e.divides){const c=d.left;for(const u of d.glyphGroup){const{left:l}=u,g=c+l,m=Math.abs(t-g);m<a.distance&&(a.glyph=u,a.distance=m)}}if(a.glyph==null)return;const{segmentPage:i}=r;return o.findPositionByGlyph(a.glyph,i)}_getNextOrPrevLine(o,e){var S,T,I,p,h,v,_,D,C,y,M,O;const t=o.parent;if(t==null)return;const r=t.parent;if(r==null)return;const a=r.parent;if(a==null)return;const i=a.lines.indexOf(r);if(i===-1)return;let d;if(e===!0?d=a.lines[i+1]:d=a.lines[i-1],d!=null)return d;const c=a.parent;if(c==null)return;const u=c.columns.indexOf(a);if(u===-1)return;if(e===!0)d=(S=c.columns[u+1])==null?void 0:S.lines[0];else{const x=(I=(T=c.columns)==null?void 0:T[u-1])==null?void 0:I.lines;d=x==null?void 0:x[x.length-1]}if(d!=null)return d;const l=c.parent;if(l==null)return;const g=l.sections.indexOf(c);if(g===-1)return;if(e===!0)d=(h=(p=l.sections[g-1])==null?void 0:p.columns[0])==null?void 0:h.lines[0];else{const x=(_=(v=l.sections)==null?void 0:v[g-1])==null?void 0:_.columns,R=x==null?void 0:x[x.length-1],E=R==null?void 0:R.lines;d=E==null?void 0:E[E.length-1]}if(d!=null)return d;const m=l.parent;if(m==null)return;const f=m.pages.indexOf(l);if(f!==-1){if(e===!0)d=(y=(C=(D=m.pages[f+1])==null?void 0:D.sections[0])==null?void 0:C.columns[0])==null?void 0:y.lines[0];else{const x=(M=m.pages[f-1])==null?void 0:M.sections;if(x==null)return;const R=(O=x[x.length-1])==null?void 0:O.columns,E=R[R.length-1],U=E==null?void 0:E.lines;d=U[U.length-1]}if(d!=null)return d}}_getDocObject(){return it(this._univerInstanceService,this._renderManagerService)}};ie=gn([n.OnLifecycle(n.LifecycleStages.Rendered,ie),oe(0,n.IUniverInstanceService),oe(1,N.IRenderManagerService),oe(2,n.Inject(exports.TextSelectionManagerService)),oe(3,n.ICommandService)],ie);var fn=Object.defineProperty,Sn=Object.getOwnPropertyDescriptor,pn=(s,o,e,t)=>{for(var r=t>1?void 0:t?Sn(o,e):o,a=s.length-1,i;a>=0;a--)(i=s[a])&&(r=(t?i(o,e,r):i(r))||r);return t&&r&&fn(o,e,r),r},re=(s,o)=>(e,t)=>o(e,t,s);let ce=class extends n.Disposable{constructor(o,e,t,r){super();A(this,"_onInputSubscription");this._univerInstanceService=o,this._renderManagerService=e,this._textSelectionRenderManager=t,this._commandService=r,this._init()}dispose(){var o;super.dispose(),(o=this._onInputSubscription)==null||o.unsubscribe()}_init(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async o=>{var T;if(o==null)return;const e=this._univerInstanceService.getCurrentUniverDocInstance();if(!e)return;const t=e.getUnitId(),{event:r,content:a="",activeRange:i}=o,d=r,c=(T=this._renderManagerService.getRenderById(e.getUnitId()))==null?void 0:T.with(exports.DocSkeletonManagerService).getSkeleton();if(d.data==null||c==null||!c||!i)return;const{startOffset:u,segmentId:l,style:g,segmentPage:m}=i,f=a.length,S=[{startOffset:u+f,endOffset:u+f,segmentId:l,segmentPage:m,style:g}];await this._commandService.executeCommand(q.id,{unitId:t,body:{dataStream:a},textRanges:S,range:i,segmentId:l})})}};ce=pn([n.OnLifecycle(n.LifecycleStages.Rendered,ce),re(0,n.IUniverInstanceService),re(1,N.IRenderManagerService),re(2,N.ITextSelectionRenderManager),re(3,n.ICommandService)],ce);const J={id:"doc.command.align-operation",type:n.CommandType.COMMAND,handler:(s,o)=>{var D,C;const e=s.get(exports.TextSelectionManagerService),t=s.get(n.IUniverInstanceService),r=s.get(n.ICommandService),{alignType:a}=o,i=t.getCurrentUniverDocInstance(),d=e.getActiveRange();if(i==null||d==null)return!1;const{segmentId:c}=d,u=(D=e.getCurrentSelections())!=null?D:[],l=(C=i.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:C.paragraphs,g=u.map(z);if(l==null)return!1;const m=It(d,l),f=i.getUnitId(),S=m.every(y=>{var M;return((M=y.paragraphStyle)==null?void 0:M.horizontalAlign)===a}),T={id:b.id,params:{unitId:f,actions:[],textRanges:g}},I=new n.MemoryCursor;I.reset();const p=new n.TextX,h=n.JSONX.getInstance();for(const y of m){const{startIndex:M}=y;p.push({t:n.TextXActionType.RETAIN,len:M-I.cursor,segmentId:c});const O={...y.paragraphStyle,horizontalAlign:S?n.HorizontalAlign.UNSPECIFIED:a};p.push({t:n.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...y,paragraphStyle:O,startIndex:0}]},segmentId:c,coverType:n.UpdateDocsAttributeType.REPLACE}),I.moveCursorTo(M+1)}const v=w(i,c);return T.params.actions=h.editOp(p.serialize(),v),!!r.syncExecuteCommand(T.id,T.params)}},yt={id:"doc.command.align-left",type:n.CommandType.COMMAND,handler:s=>s.get(n.ICommandService).syncExecuteCommand(J.id,{alignType:n.HorizontalAlign.LEFT})},_t={id:"doc.command.align-center",type:n.CommandType.COMMAND,handler:s=>s.get(n.ICommandService).syncExecuteCommand(J.id,{alignType:n.HorizontalAlign.CENTER})},Ot={id:"doc.command.align-right",type:n.CommandType.COMMAND,handler:s=>s.get(n.ICommandService).syncExecuteCommand(J.id,{alignType:n.HorizontalAlign.RIGHT})},Rt={id:"doc.command.align-justify",type:n.CommandType.COMMAND,handler:s=>s.get(n.ICommandService).syncExecuteCommand(J.id,{alignType:n.HorizontalAlign.JUSTIFIED})};var In=Object.defineProperty,hn=Object.getOwnPropertyDescriptor,Tn=(s,o,e,t)=>{for(var r=t>1?void 0:t?hn(o,e):o,a=s.length-1,i;a>=0;a--)(i=s[a])&&(r=(t?i(o,e,r):i(r))||r);return t&&r&&In(o,e,r),r},Ue=(s,o)=>(e,t)=>o(e,t,s);let de=class extends n.Disposable{constructor(s,o,e){super(),this._commandService=s,this._textSelectionManagerService=o,this._univerInstanceService=e,this._initSelectionChange()}_transformCustomRange(s,o){var i;const{startOffset:e,endOffset:t,collapsed:r}=o,a=(i=s.getCustomRanges())==null?void 0:i.filter(d=>!d.wholeEntity||e<=d.startIndex&&t>d.endIndex?!1:r?d.startIndex<e&&d.endIndex>=t:Xe(e,t-1,d.startIndex,d.endIndex));if(a!=null&&a.length){let d=e,c=t;return a.forEach(u=>{d=Math.min(u.startIndex,d),c=Math.max(u.endIndex+1,c)}),{...o,startOffset:d,endOffset:c,collapsed:d===c}}return o}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(s=>{if(s.id===ge.id){const o=s.params,{unitId:e,ranges:t,isEditing:r}=o,a=this._univerInstanceService.getUnit(e);if(!a)return;const i=t.map(d=>this._transformCustomRange(a,d));i.some((d,c)=>t[c]!==d)&&this._textSelectionManagerService.replaceTextRanges(i,r)}}))}};de=Tn([n.OnLifecycle(n.LifecycleStages.Ready,de),Ue(0,n.ICommandService),Ue(1,n.Inject(exports.TextSelectionManagerService)),Ue(2,n.IUniverInstanceService)],de);var vn=Object.defineProperty,Cn=Object.getOwnPropertyDescriptor,xn=(s,o,e,t)=>{for(var r=t>1?void 0:t?Cn(o,e):o,a=s.length-1,i;a>=0;a--)(i=s[a])&&(r=(t?i(o,e,r):i(r))||r);return t&&r&&vn(o,e,r),r},yn=(s,o)=>(e,t)=>o(e,t,s);const _n="docs";var se;exports.UniverDocsPlugin=(se=class extends n.Plugin{constructor(o={},e){super(),this._injector=e,this._initializeDependencies(e),this._initializeCommands()}_initializeCommands(){[ue,me,ut,mt,Te,ve,Ce,xe,V,ye,_e,Oe,Re,De,Me,je,lt,q,H,Ie,Fe,Ge,he,b,ht,Tt,Ct,K,ge,xt,pt,St,Ee,yt,_t,Ot,J,Rt].forEach(o=>{this._injector.get(n.ICommandService).registerCommand(o)})}_initializeDependencies(o){[[exports.DocStateChangeManagerService],[Q],[N.ITextSelectionRenderManager,{useClass:N.TextSelectionRenderManager}],[exports.TextSelectionManagerService],[Se],[ce],[ae],[ie],[de]].forEach(e=>o.add(e))}},A(se,"pluginName",_n),A(se,"type",n.UniverInstanceType.UNIVER_DOC),se);exports.UniverDocsPlugin=xn([yn(1,n.Inject(n.Injector))],exports.UniverDocsPlugin);function On(s,o){const{range:e,rangeId:t,rangeType:r,segmentId:a}=s,i=$t(e,o);if(!i)return null;const{startOffset:d,endOffset:c}=i,u=new n.TextX;return d>0&&u.push({t:n.TextXActionType.RETAIN,len:d,segmentId:a}),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:a}),u.push({t:n.TextXActionType.INSERT,body:{dataStream:n.DataStreamTreeTokenType.CUSTOM_RANGE_END,customRanges:[{rangeId:t,rangeType:r,startIndex:-(c-d)-1,endIndex:0}]},len:1,line:0}),u}function Rn(s,o){const e={id:b.id,params:{unitId:s.unitId,actions:[],textRanges:void 0}},t=n.JSONX.getInstance(),r=On(s,o);return r?(e.params.actions=t.editOp(r.serialize()),e):!1}function Mn(s,o){var C;const{segmentId:e,rangeId:t,rangeType:r,wholeEntity:a}=o,i=s.get(exports.TextSelectionManagerService),d=s.get(n.IUniverInstanceService),c=i.getActiveRange();if(!c)return!1;const u=d.getCurrentUnitForType(n.UniverInstanceType.UNIVER_DOC);if(!u)return!1;const l=u.getBody(),g=u.getUnitId();if(!l)return!1;const{startOffset:m,endOffset:f}=ee(c),S=(C=l.customRanges)!=null?C:[],T=[];for(let y=0,M=S.length;y<M;y++){const O=S[y];if(O.rangeType===r&&Math.max(O.startIndex,m)<=Math.min(O.endIndex,f-1)&&T.push({...O}),O.startIndex>=f)break}const I=T.map(y=>[y.startIndex,y.endIndex]).flat().sort((y,M)=>y-M);let p=0;const h=new n.TextX,v=I.length?{startOffset:Math.min(I[0],m),endOffset:Math.max(I[I.length-1]+1,f)}:c;v.startOffset!==p&&(h.push({t:n.TextXActionType.RETAIN,len:v.startOffset-p,segmentId:e}),p=v.startOffset),h.push({t:n.TextXActionType.INSERT,body:{dataStream:n.DataStreamTreeTokenType.CUSTOM_RANGE_START},len:1,line:0,segmentId:e}),I.forEach((y,M)=>{y!==p&&(h.push({t:n.TextXActionType.RETAIN,len:y-p,segmentId:e}),p=y),h.push({t:n.TextXActionType.DELETE,len:1,line:0,segmentId:e}),p++}),p!==v.endOffset&&(h.push({t:n.TextXActionType.RETAIN,len:v.endOffset-p,segmentId:e}),p=v.endOffset),h.push({t:n.TextXActionType.INSERT,body:{dataStream:n.DataStreamTreeTokenType.CUSTOM_RANGE_END,customRanges:[{rangeId:t,rangeType:r,startIndex:-(v.endOffset-v.startOffset-I.length+1),endIndex:0,wholeEntity:a}]},len:1,line:0,segmentId:e});const _=n.JSONX.getInstance(),D={id:b.id,params:{unitId:g,actions:[],textRanges:void 0}};return D.params.actions=_.editOp(h.serialize()),D}function Dn(s,o){var m,f;const{unitId:e,rangeId:t,segmentId:r}=o,i=s.get(n.IUniverInstanceService).getUnit(e);if(!i)return!1;const d=(f=(m=i.getBody())==null?void 0:m.customRanges)==null?void 0:f.find(S=>S.rangeId===t);if(!d)return!1;const{startIndex:c,endIndex:u}=d,l=new n.TextX,g=u-c+1;return c>0&&l.push({t:n.TextXActionType.RETAIN,len:c,segmentId:r}),l.push({t:n.TextXActionType.DELETE,len:1,segmentId:r,line:0}),g-2>0&&l.push({t:n.TextXActionType.RETAIN,len:g-2,segmentId:r}),l.push({t:n.TextXActionType.DELETE,len:1,segmentId:r,line:0}),l}function En(s,o){const e={id:b.id,params:{unitId:o.unitId,actions:[],textRanges:void 0}},t=n.JSONX.getInstance(),r=Dn(s,o);return r?(e.params.actions=t.editOp(r.serialize()),e):!1}function Mt(s){const{unitId:o,range:e,id:t,type:r,segmentId:a}=s,{startOffset:i,endOffset:d}=e,c={id:b.id,params:{unitId:o,actions:[],textRanges:void 0}},u=new n.TextX,l=n.JSONX.getInstance();return i>0&&u.push({t:n.TextXActionType.RETAIN,len:i,segmentId:a}),u.push({t:n.TextXActionType.RETAIN,body:{dataStream:"",customDecorations:[{id:t,type:r,startIndex:0,endIndex:d-i-1}]},len:d-i,segmentId:a}),c.params.actions=l.editOp(u.serialize()),c}function An(s,o){const{segmentId:e,id:t,type:r}=o,a=s.get(exports.TextSelectionManagerService),i=s.get(n.IUniverInstanceService),d=a.getActiveRange();if(!d)return!1;const c=i.getCurrentUnitForType(n.UniverInstanceType.UNIVER_DOC);if(!c)return!1;const u=c.getBody(),l=c.getUnitId();return u?Mt({unitId:l,range:{startOffset:d.startOffset,endOffset:d.endOffset,collapsed:!0},id:t,type:r,segmentId:e}):!1}function Nn(s,o){var T,I;const{unitId:e,id:t,segmentId:r}=o,i=s.get(n.IUniverInstanceService).getUnit(e),d=i==null?void 0:i.getBody();if(!i||!d)return!1;const c=(I=(T=i.getBody())==null?void 0:T.customDecorations)==null?void 0:I.filter(p=>p.id===t);if(!(c!=null&&c.length))return!1;const u=c.map(p=>n.getBodySlice(d,p.startIndex,p.endIndex+1)),l=u.map(p=>{var v;const h=n.Tools.deepClone(p);return h.customDecorations=(v=h.customDecorations)==null?void 0:v.filter(_=>_.id!==t),h}),g={id:b.id,params:{unitId:e,actions:[],textRanges:void 0}},m=new n.TextX,f=n.JSONX.getInstance();let S=0;return c.forEach((p,h)=>{const v=l[h],_=u[h];p.startIndex!==S&&m.push({t:n.TextXActionType.RETAIN,len:p.startIndex-S,segmentId:r}),S=p.startIndex,m.push({t:n.TextXActionType.RETAIN,len:p.endIndex-p.startIndex+1,segmentId:r,body:v,oldBody:_,coverType:n.UpdateDocsAttributeType.REPLACE}),S=S+(p.endIndex-p.startIndex+1)}),g.params.actions=f.editOp(m.serialize()),g}const bn=n.createInterceptorKey("CUSTOM_RANGE"),Un=n.createInterceptorKey("CUSTOM_DECORATION"),le={CUSTOM_RANGE:bn,CUSTOM_DECORATION:Un};var Pn=Object.defineProperty,wn=Object.getOwnPropertyDescriptor,Bn=(s,o,e,t)=>{for(var r=t>1?void 0:t?wn(o,e):o,a=s.length-1,i;a>=0;a--)(i=s[a])&&(r=(t?i(o,e,r):i(r))||r);return t&&r&&Pn(o,e,r),r},Xn=(s,o)=>(e,t)=>o(e,t,s);exports.DocInterceptorService=class extends n.Disposable{constructor(e,t){super();A(this,"_interceptorsByName",new Map);this._context=e,this._docSkeletonManagerService=t,this.disposeWithMe(this._docSkeletonManagerService.currentViewModel$.subscribe(r=>{if(r){const a=r.getDataModel().getUnitId();if(a===n.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||a===n.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;this.interceptDocumentViewModel(r)}})),this.disposeWithMe(this.intercept(le.CUSTOM_RANGE,{priority:-1,handler:(r,a,i)=>i(r)}))}intercept(e,t){const r=e;this._interceptorsByName.has(r)||this._interceptorsByName.set(r,[]);const a=this._interceptorsByName.get(r);return a.push(t),this._interceptorsByName.set(r,a.sort((i,d)=>{var c,u;return((c=d.priority)!=null?c:0)-((u=i.priority)!=null?u:0)})),this.disposeWithMe(n.toDisposable(()=>n.remove(this._interceptorsByName.get(r),t)))}fetchThroughInterceptors(e){const t=e,r=this._interceptorsByName.get(t);return n.composeInterceptors(r||[])}interceptDocumentViewModel(e){const t=new n.DisposableCollection;return t.add(e.registerCustomRangeInterceptor({getCustomRange:r=>{var a;return this.fetchThroughInterceptors(le.CUSTOM_RANGE)(e.getCustomRangeRaw(r),{index:r,unitId:e.getDataModel().getUnitId(),customRanges:(a=e.getDataModel().getCustomRanges())!=null?a:[]})},getCustomDecoration:r=>{var a;return this.fetchThroughInterceptors(le.CUSTOM_DECORATION)(e.getCustomDecorationRaw(r),{index:r,unitId:e.getDataModel().getUnitId(),customDecorations:(a=e.getDataModel().getCustomDecorations())!=null?a:[]})}})),t}};exports.DocInterceptorService=Bn([n.OnLifecycle(n.LifecycleStages.Starting,exports.DocInterceptorService),Xn(1,n.Inject(exports.DocSkeletonManagerService))],exports.DocInterceptorService);const Ln=s=>s.body?s.body.dataStream.slice(0,-2).replaceAll(n.DataStreamTreeTokenType.CUSTOM_RANGE_START,"").replaceAll(n.DataStreamTreeTokenType.CUSTOM_RANGE_END,""):"";exports.AlignCenterCommand=_t;exports.AlignJustifyCommand=Rt;exports.AlignLeftCommand=yt;exports.AlignOperationCommand=J;exports.AlignRightCommand=Ot;exports.BreakLineCommand=lt;exports.BulletListCommand=St;exports.CoverContentCommand=Tt;exports.CutContentCommand=ke;exports.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX=Jt;exports.DOCS_COMPONENT_DEFAULT_Z_INDEX=Kt;exports.DOCS_COMPONENT_HEADER_LAYER_INDEX=Yt;exports.DOCS_COMPONENT_MAIN_LAYER_INDEX=Wt;exports.DOCS_VIEW_KEY=ne;exports.DOC_INTERCEPTOR_POINT=le;exports.DeleteCommand=H;exports.DeleteCustomBlockCommand=Ie;exports.DeleteLeftCommand=ut;exports.DeleteRightCommand=mt;exports.DocCustomRangeService=Se;exports.EditorInsertTextCommandId=dt;exports.IMEInputCommand=Ge;exports.IMEInputManagerService=Q;exports.InnerPasteCommand=en;exports.InsertCommand=q;exports.ListOperationCommand=Ee;exports.MergeTwoParagraphCommand=he;exports.MoveCursorOperation=ue;exports.MoveSelectionOperation=me;exports.NORMAL_TEXT_SELECTION_PLUGIN_NAME=Zt;exports.OrderListCommand=pt;exports.ReplaceContentCommand=ht;exports.ResetInlineFormatTextBackgroundColorCommand=De;exports.RichTextEditingMutation=b;exports.SelectAllOperation=xt;exports.SetDocZoomRatioCommand=Ct;exports.SetDocZoomRatioOperation=K;exports.SetInlineFormatBoldCommand=Te;exports.SetInlineFormatCommand=je;exports.SetInlineFormatFontFamilyCommand=Oe;exports.SetInlineFormatFontSizeCommand=_e;exports.SetInlineFormatItalicCommand=ve;exports.SetInlineFormatStrikethroughCommand=xe;exports.SetInlineFormatSubscriptCommand=V;exports.SetInlineFormatSuperscriptCommand=ye;exports.SetInlineFormatTextBackgroundColorCommand=Me;exports.SetInlineFormatTextColorCommand=Re;exports.SetInlineFormatUnderlineCommand=Ce;exports.SetTextSelectionsOperation=ge;exports.UpdateCommand=Fe;exports.VIEWPORT_KEY=at;exports.addCustomDecorationBySelectionFactory=An;exports.addCustomDecorationFactory=Mt;exports.addCustomRangeBySelectionFactory=Mn;exports.addCustomRangeFactory=Rn;exports.deleteCustomDecorationFactory=Nn;exports.deleteCustomRangeFactory=En;exports.getDeleteSelection=te;exports.getDocObject=it;exports.getDocObjectById=Qt;exports.getInsertSelection=fe;exports.getPlainTextFormDocument=Ln;exports.getRetainAndDeleteFromReplace=pe;exports.getRichTextEditPath=w;exports.getSelectionText=Ht;exports.isSegmentIntersects=Xe;exports.neoGetDocObject=qt;exports.replaceSelectionFactory=Vt;exports.serializeTextRange=z;
|
|
1
|
+
"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@univerjs/core"),engineRender=require("@univerjs/engine-render"),rxjs=require("rxjs"),SetTextSelectionsOperation={id:"doc.operation.set-selections",type:core.CommandType.OPERATION,handler:__name((_,__)=>!0,"handler")};var __defProp$8=Object.defineProperty,__getOwnPropDesc$8=Object.getOwnPropertyDescriptor,__decorateClass$8=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$8(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$8(target,key,result),result},"__decorateClass$8"),__decorateParam$8=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$8");function serializeTextRange(textRange){const{startOffset,endOffset,collapsed}=textRange,serializedTextRange={startOffset,endOffset,collapsed};return typeof textRange.isActive=="function"&&(serializedTextRange.isActive=textRange.isActive()),serializedTextRange}__name(serializeTextRange,"serializeTextRange");var _a;exports.TextSelectionManagerService=(_a=class extends core.RxDisposable{constructor(_textSelectionRenderManager,_commandService){super();__publicField(this,"_currentSelection",null);__publicField(this,"_textSelectionInfo",new Map);__publicField(this,"_textSelection$",new rxjs.BehaviorSubject(null));__publicField(this,"textSelection$",this._textSelection$.asObservable());this._textSelectionRenderManager=_textSelectionRenderManager,this._commandService=_commandService,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(param){this._currentSelection=param,this._refresh(param)}setCurrentSelectionNotRefresh(param){this._currentSelection=param}getCurrentSelections(){var _a10;return(_a10=this._getTextRanges(this._currentSelection))==null?void 0:_a10.textRanges}getActiveTextRange(){const selectionInfo=this._getTextRanges(this._currentSelection);if(selectionInfo==null)return;const{textRanges}=selectionInfo;return textRanges.find(textRange=>textRange.isActive())}getActiveRange(){const selectionInfo=this._getTextRanges(this._currentSelection);if(selectionInfo==null)return;const{textRanges,segmentId,style,segmentPage}=selectionInfo,activeTextRange=textRanges.find(textRange=>textRange.isActive());if(activeTextRange==null)return null;const{startOffset,endOffset,collapsed,startNodePosition,endNodePosition,direction}=activeTextRange;return startOffset==null||endOffset==null?null:{startOffset,endOffset,collapsed,startNodePosition,endNodePosition,direction,segmentId,segmentPage,style}}add(textRanges,isEditing=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges,segmentId:"",segmentPage:-1,isEditing,style:engineRender.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(textRanges,isEditing=!0,options){this._currentSelection!=null&&(this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges(textRanges,isEditing,options))}_syncSelectionFromRenderService(){this._textSelectionRenderManager.textSelectionInner$.pipe(rxjs.takeUntil(this.dispose$)).subscribe(params=>{params!=null&&this._replaceTextRangesWithNoRefresh(params)})}_replaceTextRangesWithNoRefresh(textSelectionInfo){if(this._currentSelection==null)return;const params={...this._currentSelection,...textSelectionInfo};this._replaceByParam(params),this._textSelection$.next(params);const{unitId,subUnitId,segmentId,style,textRanges,isEditing}=params;this._commandService.executeCommand(SetTextSelectionsOperation.id,{unitId,subUnitId,segmentId,style,isEditing,ranges:textRanges.map(serializeTextRange)})}_getTextRanges(param){var _a10;if(param==null)return;const{unitId,subUnitId=""}=param;return(_a10=this._textSelectionInfo.get(unitId))==null?void 0:_a10.get(subUnitId)}_refresh(param){const allTextSelectionInfo=this._getTextRanges(param);this._textSelectionRenderManager.removeAllTextRanges(),allTextSelectionInfo&&Array.isArray(allTextSelectionInfo.textRanges)&&allTextSelectionInfo.textRanges.length&&this._textSelectionRenderManager.addTextRanges(allTextSelectionInfo.textRanges.map(serializeTextRange))}_replaceByParam(insertParam){const{unitId,subUnitId,style,segmentId,textRanges,isEditing,segmentPage}=insertParam;this._textSelectionInfo.has(unitId)||this._textSelectionInfo.set(unitId,new Map),this._textSelectionInfo.get(unitId).set(subUnitId,{textRanges,style,segmentId,isEditing,segmentPage})}_addByParam(insertParam){const{unitId,subUnitId,textRanges,style,segmentId,isEditing,segmentPage}=insertParam;this._textSelectionInfo.has(unitId)||this._textSelectionInfo.set(unitId,new Map);const unitTextRange=this._textSelectionInfo.get(unitId);unitTextRange.has(subUnitId)?unitTextRange.get(subUnitId).textRanges.push(...textRanges):unitTextRange.set(subUnitId,{textRanges,style,segmentId,isEditing,segmentPage})}},__name(_a,"TextSelectionManagerService"),_a);exports.TextSelectionManagerService=__decorateClass$8([__decorateParam$8(0,engineRender.ITextSelectionRenderManager),__decorateParam$8(1,core.ICommandService)],exports.TextSelectionManagerService);var __defProp$7=Object.defineProperty,__getOwnPropDesc$7=Object.getOwnPropertyDescriptor,__decorateClass$7=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$7(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$7(target,key,result),result},"__decorateClass$7"),__decorateParam$7=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$7");const DEBOUNCE_DELAY=300;var _a2;exports.DocStateChangeManagerService=(_a2=class extends core.RxDisposable{constructor(_undoRedoService,_commandService,_univerInstanceService){super();__publicField(this,"_docStateChange$",new rxjs.BehaviorSubject(null));__publicField(this,"docStateChange$",this._docStateChange$.asObservable());__publicField(this,"_historyStateCache",new Map);__publicField(this,"_changeStateCache",new Map);__publicField(this,"_historyTimer",null);__publicField(this,"_changeStateCacheTimer",null);this._undoRedoService=_undoRedoService,this._commandService=_commandService,this._univerInstanceService=_univerInstanceService,this._initialize()}setChangeState(changeState){this._cacheChangeState(changeState,"history"),this._cacheChangeState(changeState,"collaboration")}_initialize(){this.disposeWithMe(this._commandService.beforeCommandExecuted(command=>{if(command.id===core.UndoCommandId||command.id===core.RedoCommandId){const univerDoc=this._univerInstanceService.getCurrentUniverDocInstance();if(univerDoc==null)return;const unitId=univerDoc.getUnitId();this._pushHistory(unitId),this._emitChangeState(unitId)}}))}_cacheChangeState(changeState,type="history"){const{trigger,unitId,noHistory,debounce=!1}=changeState;if(noHistory||trigger==null||type==="history"&&(trigger===core.RedoCommandId||trigger===core.UndoCommandId))return;const stateCache=type==="history"?this._historyStateCache:this._changeStateCache,cb=type==="history"?this._pushHistory.bind(this):this._emitChangeState.bind(this);if(stateCache.has(unitId)){const cacheStates=stateCache.get(unitId);cacheStates==null||cacheStates.push(changeState)}else stateCache.set(unitId,[changeState]);debounce?type==="history"?(this._historyTimer&&clearTimeout(this._historyTimer),this._historyTimer=setTimeout(()=>{cb(unitId)},DEBOUNCE_DELAY)):(this._changeStateCacheTimer&&clearTimeout(this._changeStateCacheTimer),this._changeStateCacheTimer=setTimeout(()=>{cb(unitId)},DEBOUNCE_DELAY)):cb(unitId)}_pushHistory(unitId){const undoRedoService=this._undoRedoService,cacheStates=this._historyStateCache.get(unitId);if(!Array.isArray(cacheStates)||cacheStates.length===0)return;const len=cacheStates.length,commandId=cacheStates[0].commandId,firstState=cacheStates[0],lastState=cacheStates[len-1],redoParams={unitId,actions:cacheStates.reduce((acc,cur)=>core.JSONX.compose(acc,cur.redoState.actions),null),textRanges:lastState.redoState.textRanges},undoParams={unitId,actions:cacheStates.reverse().reduce((acc,cur)=>core.JSONX.compose(acc,cur.undoState.actions),null),textRanges:firstState.undoState.textRanges};undoRedoService.pushUndoRedo({unitID:unitId,undoMutations:[{id:commandId,params:undoParams}],redoMutations:[{id:commandId,params:redoParams}]}),cacheStates.length=0}_emitChangeState(unitId){const cacheStates=this._changeStateCache.get(unitId);if(!Array.isArray(cacheStates)||cacheStates.length===0)return;const len=cacheStates.length,{commandId,trigger,segmentId,noHistory,debounce}=cacheStates[0],firstState=cacheStates[0],lastState=cacheStates[len-1],redoState={unitId,actions:cacheStates.reduce((acc,cur)=>core.JSONX.compose(acc,cur.redoState.actions),null),textRanges:lastState.redoState.textRanges},undoState={unitId,actions:cacheStates.reverse().reduce((acc,cur)=>core.JSONX.compose(acc,cur.undoState.actions),null),textRanges:firstState.undoState.textRanges},changeState={commandId,unitId,trigger,redoState,undoState,segmentId,noHistory,debounce};cacheStates.length=0,this._docStateChange$.next(changeState)}},__name(_a2,"DocStateChangeManagerService"),_a2);exports.DocStateChangeManagerService=__decorateClass$7([__decorateParam$7(0,core.Inject(core.IUndoRedoService)),__decorateParam$7(1,core.ICommandService),__decorateParam$7(2,core.IUniverInstanceService)],exports.DocStateChangeManagerService);const _IMEInputManagerService=class _IMEInputManagerService{constructor(){__publicField(this,"_previousActiveRange",null);__publicField(this,"_undoMutationParamsCache",[]);__publicField(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache=[],redoCache=[]}){this._undoMutationParamsCache=undoCache,this._redoMutationParamsCache=redoCache}getActiveRange(){return this._previousActiveRange}setActiveRange(range){this._previousActiveRange=range}pushUndoRedoMutationParams(undoParams,redoParams){this._undoMutationParamsCache.push(undoParams),this._redoMutationParamsCache.push(redoParams)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId}=this._undoMutationParamsCache[0],undoMutationParams={unitId,actions:this._undoMutationParamsCache.reverse().reduce((acc,cur)=>core.JSONX.compose(acc,cur.actions),null),textRanges:[]};return{redoMutationParams:{unitId,actions:this._redoMutationParamsCache.reduce((acc,cur)=>core.JSONX.compose(acc,cur.actions),null),textRanges:[]},undoMutationParams,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}};__name(_IMEInputManagerService,"IMEInputManagerService");let IMEInputManagerService=_IMEInputManagerService;var __defProp$6=Object.defineProperty,__getOwnPropDesc$6=Object.getOwnPropertyDescriptor,__decorateClass$6=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$6(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$6(target,key,result),result},"__decorateClass$6"),__decorateParam$6=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$6"),_a3;exports.DocSkeletonManagerService=(_a3=class extends core.RxDisposable{constructor(_context,_localeService,_univerInstanceService){super();__publicField(this,"_skeleton");__publicField(this,"_docViewModel");__publicField(this,"_currentSkeleton$",new rxjs.BehaviorSubject(null));__publicField(this,"currentSkeleton$",this._currentSkeleton$.asObservable());__publicField(this,"_currentSkeletonBefore$",new rxjs.BehaviorSubject(null));__publicField(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());__publicField(this,"_currentViewModel$",new rxjs.BehaviorSubject(null));__publicField(this,"currentViewModel$",this._currentViewModel$.asObservable());this._context=_context,this._localeService=_localeService,this._univerInstanceService=_univerInstanceService,this._init(),this._univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_DOC).pipe(rxjs.takeUntil(this.dispose$)).subscribe(documentModel=>{documentModel&&documentModel.getUnitId()===this._context.unitId&&this._update(documentModel)})}dispose(){super.dispose(),this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete()}getSkeleton(){return this._skeleton}getViewModel(){return this._docViewModel}_init(){const documentDataModel=this._context.unit;this._update(documentDataModel)}_update(documentDataModel){const unitId=this._context.unitId;if(documentDataModel.getBody()==null)return;this._docViewModel&&unitId===core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY?(this._docViewModel.reset(documentDataModel),this._context.unit=documentDataModel):this._docViewModel||(this._docViewModel=this._buildDocViewModel(documentDataModel)),this._skeleton||(this._skeleton=this._buildSkeleton(this._docViewModel));const skeleton=this._skeleton;skeleton.calculate(),this._currentSkeletonBefore$.next(skeleton),this._currentSkeleton$.next(skeleton),this._currentViewModel$.next(this._docViewModel)}_buildSkeleton(documentViewModel){return engineRender.DocumentSkeleton.create(documentViewModel,this._localeService)}_buildDocViewModel(documentDataModel){return new engineRender.DocumentViewModel(documentDataModel)}},__name(_a3,"DocSkeletonManagerService"),_a3);exports.DocSkeletonManagerService=__decorateClass$6([__decorateParam$6(1,core.Inject(core.LocaleService)),__decorateParam$6(2,core.IUniverInstanceService)],exports.DocSkeletonManagerService);const RichTextEditingMutationId="doc.mutation.rich-text-editing",RichTextEditingMutation={id:RichTextEditingMutationId,type:core.CommandType.MUTATION,handler:__name((accessor,params)=>{var _a10,_b;const{unitId,segmentId="",actions,textRanges,prevTextRanges,trigger,noHistory,isCompositionEnd,noNeedSetTextRange,debounce}=params,univerInstanceService=accessor.get(core.IUniverInstanceService),renderManagerService=accessor.get(engineRender.IRenderManagerService),documentDataModel=univerInstanceService.getUniverDocInstance(unitId),documentViewModel=(_a10=renderManagerService.getRenderById(unitId))==null?void 0:_a10.with(exports.DocSkeletonManagerService).getViewModel();if(documentDataModel==null||documentViewModel==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${unitId}`);const textSelectionManagerService=accessor.get(exports.TextSelectionManagerService),serializedSelections=((_b=textSelectionManagerService.getCurrentSelections())!=null?_b:[]).map(serializeTextRange),docStateChangeManagerService=accessor.get(exports.DocStateChangeManagerService),imeInputManagerService=accessor.get(IMEInputManagerService),disabled=!!documentDataModel.getSnapshot().disabled;if(core.JSONX.isNoop(actions)||actions&&actions.length===0||disabled)return{unitId,actions:[],textRanges:serializedSelections};const undoActions=core.JSONX.invertWithDoc(actions,documentDataModel.getSnapshot());documentDataModel.apply(actions),documentViewModel.reset(documentDataModel),!noNeedSetTextRange&&textRanges&&trigger!=null&&queueMicrotask(()=>{textSelectionManagerService.replaceTextRanges(textRanges,!0,params.options)});const changeState={commandId:RichTextEditingMutationId,unitId,segmentId,trigger,noHistory,debounce,redoState:{actions,textRanges},undoState:{actions:undoActions,textRanges:prevTextRanges!=null?prevTextRanges:serializedSelections}};if(isCompositionEnd){const historyParams=imeInputManagerService.fetchComposedUndoRedoMutationParams();if(historyParams==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams,redoMutationParams,previousActiveRange}=historyParams;changeState.redoState.actions=redoMutationParams.actions,changeState.undoState.actions=undoMutationParams.actions,changeState.undoState.textRanges=[previousActiveRange]}return docStateChangeManagerService.setChangeState(changeState),{unitId,actions:undoActions,textRanges:serializedSelections}},"handler")};function isCustomRangeSplitSymbol(text){return text===core.DataStreamTreeTokenType.CUSTOM_RANGE_END||text===core.DataStreamTreeTokenType.CUSTOM_RANGE_START}__name(isCustomRangeSplitSymbol,"isCustomRangeSplitSymbol");function isIntersecting(line1Start,line1End,line2Start,line2End){return line1Start<=line2Start&&line1End>=line2Start||line1Start>=line2Start&&line1Start<=line2End}__name(isIntersecting,"isIntersecting");function shouldDeleteCustomRange(deleteStart,deleteLen,customRange,dataStream){const dataStreamSlice=dataStream.slice(customRange.startIndex+1,customRange.endIndex),start=Math.max(deleteStart-(customRange.startIndex+1),0),end=deleteStart+deleteLen-1-(customRange.startIndex+1);if(end<0)return!1;if(start===0&&end>=dataStreamSlice.length)return!0;const result=dataStreamSlice.slice(0,start)+dataStreamSlice.slice(start+deleteLen);for(let i=0,len=result.length;i<len;i++){const letter=result[i];if(!isCustomRangeSplitSymbol(letter))return!1}return!0}__name(shouldDeleteCustomRange,"shouldDeleteCustomRange");var DeleteDirection=(DeleteDirection2=>(DeleteDirection2[DeleteDirection2.LEFT=0]="LEFT",DeleteDirection2[DeleteDirection2.RIGHT=1]="RIGHT",DeleteDirection2))(DeleteDirection||{});function normalizeSelection(selection){const{startOffset,endOffset,collapsed}=selection,start=Math.min(startOffset,endOffset),end=Math.max(startOffset,endOffset);return{startOffset:start,endOffset:end,collapsed}}__name(normalizeSelection,"normalizeSelection");function getSelectionWithSymbolMax(selection,body){let{startOffset,endOffset}=normalizeSelection(selection);for(;body.dataStream[startOffset-1]===core.DataStreamTreeTokenType.CUSTOM_RANGE_START;)startOffset-=1;for(;body.dataStream[endOffset]===core.DataStreamTreeTokenType.CUSTOM_RANGE_END;)endOffset+=1;return{startOffset,endOffset}}__name(getSelectionWithSymbolMax,"getSelectionWithSymbolMax");function getDeleteSelection(selection,body,direction=DeleteDirection.LEFT){var _a10;let{startOffset,endOffset,collapsed}=normalizeSelection(selection);if(collapsed)if(direction===DeleteDirection.LEFT)for(;isCustomRangeSplitSymbol(body.dataStream[startOffset-1]);)endOffset-=1,startOffset-=1;else for(;isCustomRangeSplitSymbol(body.dataStream[startOffset]);)endOffset+=1,startOffset+=1;else{const selectionWithSymbolMax=getSelectionWithSymbolMax(selection,body);startOffset=selectionWithSymbolMax.startOffset,endOffset=selectionWithSymbolMax.endOffset}collapsed=startOffset===endOffset;const customRanges=(_a10=body.customRanges)==null?void 0:_a10.filter(range=>!range.wholeEntity||startOffset<=range.startIndex&&endOffset>range.endIndex?!1:isSegmentIntersects(startOffset,collapsed?endOffset:endOffset-1,range.startIndex,range.endIndex));return customRanges!=null&&customRanges.length&&customRanges.forEach(range=>{startOffset=Math.min(range.startIndex,startOffset),endOffset=Math.max(range.endIndex+1,endOffset)}),{...selection,startOffset,endOffset,collapsed:startOffset===endOffset}}__name(getDeleteSelection,"getDeleteSelection");function getInsertSelection(selection,body){let{startOffset,endOffset,collapsed}=normalizeSelection(selection);if(collapsed){for(;body.dataStream[endOffset]===core.DataStreamTreeTokenType.CUSTOM_RANGE_END;)endOffset+=1,startOffset+=1;for(;body.dataStream[endOffset-1]===core.DataStreamTreeTokenType.CUSTOM_RANGE_START;)endOffset-=1,startOffset-=1;return{startOffset,endOffset,collapsed}}else return{...getSelectionWithSymbolMax(selection,body),collapsed:!1}}__name(getInsertSelection,"getInsertSelection");function getSelectionForAddCustomRange(selection,body){if(selection.startOffset===selection.endOffset)return null;const customRanges=body.customRanges;if(!customRanges)return normalizeSelection(selection);let{startOffset,endOffset}=getSelectionWithSymbolMax(selection,body);for(;isCustomRangeSplitSymbol(body.dataStream[startOffset]);){if(body.dataStream[startOffset]===core.DataStreamTreeTokenType.CUSTOM_RANGE_START){const customRange=customRanges.find(range=>range.startIndex===startOffset);if(!customRange)throw new Error("No custom-range matched");if(customRange.endIndex===endOffset-1)return{startOffset,endOffset,collapsed:!1};if(customRange.endIndex<endOffset-1)break}startOffset+=1}for(;isCustomRangeSplitSymbol(body.dataStream[endOffset-1]);){if(body.dataStream[startOffset]===core.DataStreamTreeTokenType.CUSTOM_RANGE_END){const customRange=customRanges.find(range=>range.endIndex===endOffset-1);if(!customRange)throw new Error("No custom-range matched");if(customRange.startIndex===startOffset)return{startOffset,endOffset,collapsed:!1};if(customRange.startIndex>startOffset)break}endOffset-=1}return endOffset<=startOffset?null:{startOffset,endOffset,collapsed:!1}}__name(getSelectionForAddCustomRange,"getSelectionForAddCustomRange");const tags=[core.DataStreamTreeTokenType.PARAGRAPH,core.DataStreamTreeTokenType.SECTION_BREAK,core.DataStreamTreeTokenType.TABLE_START,core.DataStreamTreeTokenType.TABLE_ROW_START,core.DataStreamTreeTokenType.TABLE_CELL_START,core.DataStreamTreeTokenType.TABLE_CELL_END,core.DataStreamTreeTokenType.TABLE_ROW_END,core.DataStreamTreeTokenType.TABLE_END,core.DataStreamTreeTokenType.CUSTOM_RANGE_START,core.DataStreamTreeTokenType.CUSTOM_RANGE_END,core.DataStreamTreeTokenType.COLUMN_BREAK,core.DataStreamTreeTokenType.PAGE_BREAK,core.DataStreamTreeTokenType.DOCS_END,core.DataStreamTreeTokenType.TAB,core.DataStreamTreeTokenType.CUSTOM_BLOCK];function getSelectionText(dataStream,start,end){const text=dataStream.slice(start,end);return tags.reduce((res,curr)=>res.replaceAll(curr,""),text)}__name(getSelectionText,"getSelectionText");function isSegmentIntersects(start,end,start2,end2){return Math.max(start,start2)<=Math.min(end,end2)}__name(isSegmentIntersects,"isSegmentIntersects");function getRetainAndDeleteAndExcludeLineBreak(selection,body,segmentId="",memoryCursor=0){var _a10;const{startOffset,endOffset}=getDeleteSelection(selection,body),dos=[],{paragraphs=[],dataStream}=body,textStart=startOffset-memoryCursor,textEnd=endOffset-memoryCursor,paragraphInRange=paragraphs==null?void 0:paragraphs.find(p=>p.startIndex-memoryCursor>=textStart&&p.startIndex-memoryCursor<textEnd),relativeCustomRanges=(_a10=body.customRanges)==null?void 0:_a10.filter(customRange=>isIntersecting(customRange.startIndex,customRange.endIndex,startOffset,endOffset)),toDeleteRanges=new Set(relativeCustomRanges==null?void 0:relativeCustomRanges.filter(customRange=>shouldDeleteCustomRange(startOffset,endOffset-startOffset,customRange,dataStream))),retainPoints=new Set;if(relativeCustomRanges==null||relativeCustomRanges.forEach(range=>{toDeleteRanges.has(range)||(range.startIndex-memoryCursor>=textStart&&range.startIndex-memoryCursor<=textEnd&&range.endIndex-memoryCursor>textEnd&&retainPoints.add(range.startIndex),range.endIndex-memoryCursor>=textStart&&range.endIndex-memoryCursor<=textEnd&&range.startIndex<textStart&&retainPoints.add(range.endIndex))}),textStart>0&&dos.push({t:core.TextXActionType.RETAIN,len:textStart,segmentId}),paragraphInRange&¶graphInRange.startIndex-memoryCursor>textStart){const paragraphIndex=paragraphInRange.startIndex-memoryCursor;retainPoints.add(paragraphIndex)}const sortedRetains=[...retainPoints].sort((pre,aft)=>pre-aft);let cursor=textStart;return sortedRetains.forEach(pos=>{const len=pos-cursor;len>0&&dos.push({t:core.TextXActionType.DELETE,len,line:0,segmentId}),dos.push({t:core.TextXActionType.RETAIN,len:1,segmentId}),cursor=pos+1}),cursor<textEnd&&dos.push({t:core.TextXActionType.DELETE,len:textEnd-cursor,line:0,segmentId}),dos}__name(getRetainAndDeleteAndExcludeLineBreak,"getRetainAndDeleteAndExcludeLineBreak");function replaceSelectionFactory(accessor,params){var _a10,_b;const{unitId,body:insertBody}=params,docDataModel=accessor.get(core.IUniverInstanceService).getUnit(unitId),textSelectionManagerService=accessor.get(exports.TextSelectionManagerService);if(!docDataModel)return!1;const body=docDataModel.getBody(),selection=(_a10=params.selection)!=null?_a10:textSelectionManagerService.getActiveRange();if(!selection||!body)return!1;const textRanges=(_b=params.textRanges)!=null?_b:[{startOffset:selection.startOffset+insertBody.dataStream.length,endOffset:selection.startOffset+insertBody.dataStream.length,collapsed:!0}],doMutation={id:RichTextEditingMutation.id,params:{unitId,actions:[],textRanges,debounce:!0}},textX=new core.TextX,jsonX=core.JSONX.getInstance();return textX.push(...getRetainAndDeleteAndExcludeLineBreak(selection,body)),textX.push({t:core.TextXActionType.INSERT,body:insertBody,len:insertBody.dataStream.length,line:0}),doMutation.params.actions=jsonX.editOp(textX.serialize()),doMutation}__name(replaceSelectionFactory,"replaceSelectionFactory");var DOCS_VIEW_KEY=(DOCS_VIEW_KEY2=>(DOCS_VIEW_KEY2.MAIN="__Document_Render_Main__",DOCS_VIEW_KEY2.BACKGROUND="__Document_Render_Background__",DOCS_VIEW_KEY2))(DOCS_VIEW_KEY||{}),VIEWPORT_KEY=(VIEWPORT_KEY2=>(VIEWPORT_KEY2.VIEW_MAIN="viewMain",VIEWPORT_KEY2.VIEW_TOP="viewTop",VIEWPORT_KEY2.VIEW_LEFT="viewLeft",VIEWPORT_KEY2.VIEW_LEFT_TOP="viewLeftTop",VIEWPORT_KEY2))(VIEWPORT_KEY||{});const DOCS_COMPONENT_BACKGROUND_LAYER_INDEX=0,DOCS_COMPONENT_MAIN_LAYER_INDEX=2,DOCS_COMPONENT_HEADER_LAYER_INDEX=4,DOCS_COMPONENT_DEFAULT_Z_INDEX=10,NORMAL_TEXT_SELECTION_PLUGIN_NAME="normalTextSelectionPluginName";function neoGetDocObject(renderContext){const{mainComponent,scene,engine,components}=renderContext,document=mainComponent,docBackground=components.get(DOCS_VIEW_KEY.BACKGROUND);return{document,docBackground,scene,engine}}__name(neoGetDocObject,"neoGetDocObject");function getDocObject(univerInstanceService,renderManagerService){const documentModel=univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_DOC);if(!documentModel)return null;const unitId=documentModel.getUnitId(),currentRender=renderManagerService.getRenderById(unitId);if(currentRender==null)return;const{mainComponent,scene,engine,components}=currentRender,document=mainComponent,docBackground=components.get(DOCS_VIEW_KEY.BACKGROUND);return{document,docBackground,scene,engine}}__name(getDocObject,"getDocObject");function getDocObjectById(unitId,renderManagerService){const currentRender=renderManagerService.getRenderById(unitId);if(currentRender==null)return;const{mainComponent,scene,engine,components}=currentRender,document=mainComponent,docBackground=components.get(DOCS_VIEW_KEY.BACKGROUND);return{document,docBackground,scene,engine}}__name(getDocObjectById,"getDocObjectById");const _DocCustomRangeService=class _DocCustomRangeService{constructor(){__publicField(this,"_customRangeHooks",[])}addClipboardHook(hook){return this._customRangeHooks.push(hook),core.toDisposable(()=>{const index=this._customRangeHooks.indexOf(hook);index>-1&&this._customRangeHooks.splice(index,1)})}copyCustomRange(unitId,range){let copy={...range};return this._customRangeHooks.forEach(hook=>{hook.onCopyCustomRange&&(copy=hook.onCopyCustomRange(unitId,copy))}),copy}};__name(_DocCustomRangeService,"DocCustomRangeService");let DocCustomRangeService=_DocCustomRangeService;function getRetainAndDeleteFromReplace(range,segmentId="",memoryCursor,body){var _a10;const{startOffset,endOffset}=range,dos=[],textStart=startOffset-memoryCursor,textEnd=endOffset-memoryCursor,dataStream=body.dataStream,relativeCustomRanges=(_a10=body.customRanges)==null?void 0:_a10.filter(customRange=>isIntersecting(customRange.startIndex,customRange.endIndex,startOffset,endOffset)),toDeleteRanges=new Set(relativeCustomRanges==null?void 0:relativeCustomRanges.filter(customRange=>shouldDeleteCustomRange(startOffset,endOffset-startOffset,customRange,dataStream))),retainPoints=new Set;relativeCustomRanges==null||relativeCustomRanges.forEach(range2=>{toDeleteRanges.has(range2)||(range2.startIndex-memoryCursor>=textStart&&range2.startIndex-memoryCursor<=textEnd&&range2.endIndex-memoryCursor>textEnd&&retainPoints.add(range2.startIndex),range2.endIndex-memoryCursor>=textStart&&range2.endIndex-memoryCursor<=textEnd&&range2.startIndex<textStart&&retainPoints.add(range2.endIndex))}),textStart>0&&dos.push({t:core.TextXActionType.RETAIN,len:textStart,segmentId});const sortedRetains=[...retainPoints].sort((pre,aft)=>pre-aft);let cursor=textStart;return sortedRetains.forEach(pos=>{const len=pos-cursor;len>0&&dos.push({t:core.TextXActionType.DELETE,len,line:0,segmentId}),dos.push({t:core.TextXActionType.RETAIN,len:1,segmentId}),cursor=pos+1}),cursor<textEnd&&(dos.push({t:core.TextXActionType.DELETE,len:textEnd-cursor,line:0,segmentId}),cursor=textEnd+1),{dos,cursor,retain:retainPoints.size}}__name(getRetainAndDeleteFromReplace,"getRetainAndDeleteFromReplace");function getCommandSkeleton(accessor,unitId){var _a10;return(_a10=accessor.get(engineRender.IRenderManagerService).getRenderById(unitId))==null?void 0:_a10.with(exports.DocSkeletonManagerService)}__name(getCommandSkeleton,"getCommandSkeleton");function getRichTextEditPath(docDataModel,segmentId=""){if(!segmentId)return["body"];const{headers,footers}=docDataModel.getSnapshot();if(headers==null&&footers==null)throw new Error("Document data model must have headers or footers when update by segment id");if((headers==null?void 0:headers[segmentId])!=null)return["headers",segmentId,"body"];if((footers==null?void 0:footers[segmentId])!=null)return["footers",segmentId,"body"];throw new Error("Segment id not found in headers or footers")}__name(getRichTextEditPath,"getRichTextEditPath");const EditorInsertTextCommandId="doc.command.insert-text",InsertCommand={id:EditorInsertTextCommandId,type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{var _a10;const commandService=accessor.get(core.ICommandService),{range,segmentId,body,unitId,textRanges:propTextRanges,cursorOffset}=params,textSelectionManagerService=accessor.get(exports.TextSelectionManagerService),docDataModel=accessor.get(core.IUniverInstanceService).getUnit(unitId,core.UniverInstanceType.UNIVER_DOC);if(docDataModel==null)return!1;const activeRange=textSelectionManagerService.getActiveRange(),originBody=docDataModel.getSelfOrHeaderFooterModel((_a10=activeRange==null?void 0:activeRange.segmentId)!=null?_a10:"").getBody();if(!originBody)return!1;const actualRange=getInsertSelection(range,originBody),{startOffset,collapsed}=actualRange,cursorMove=cursorOffset!=null?cursorOffset:body.dataStream.length,textRanges=[{startOffset:startOffset+cursorMove,endOffset:startOffset+cursorMove,style:activeRange==null?void 0:activeRange.style,collapsed}],doMutation={id:RichTextEditingMutation.id,params:{unitId,actions:[],textRanges:propTextRanges!=null?propTextRanges:textRanges,debounce:!0}},textX=new core.TextX,jsonX=core.JSONX.getInstance();if(collapsed)startOffset>0&&textX.push({t:core.TextXActionType.RETAIN,len:startOffset,segmentId});else{const{dos,retain}=getRetainAndDeleteFromReplace(actualRange,segmentId,0,originBody);textX.push(...dos),propTextRanges||(doMutation.params.textRanges=[{startOffset:startOffset+cursorMove+retain,endOffset:startOffset+cursorMove+retain,collapsed}])}textX.push({t:core.TextXActionType.INSERT,body,len:body.dataStream.length,line:0,segmentId});const path=getRichTextEditPath(docDataModel,segmentId);return doMutation.params.actions=jsonX.editOp(textX.serialize(),path),!!commandService.syncExecuteCommand(doMutation.id,doMutation.params)},"handler")},DeleteCommand={id:"doc.command.delete-text",type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{var _a10;const commandService=accessor.get(core.ICommandService),univerInstanceService=accessor.get(core.IUniverInstanceService),{range,segmentId,unitId,direction,len=1}=params,docDataModel=univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_DOC),body=docDataModel==null?void 0:docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();if(docDataModel==null||body==null)return!1;const{startOffset}=range,dataStream=body.dataStream,start=direction===DeleteDirection.LEFT?startOffset-len:startOffset,end=start+len-1,relativeCustomRanges=(_a10=body.customRanges)==null?void 0:_a10.filter(customRange=>isIntersecting(customRange.startIndex,customRange.endIndex,start,end)),toDeleteRanges=relativeCustomRanges==null?void 0:relativeCustomRanges.filter(customRange=>shouldDeleteCustomRange(start,len,customRange,dataStream)),deleteIndexes=[];for(let i=0;i<len;i++)deleteIndexes.push(start+i);toDeleteRanges==null||toDeleteRanges.forEach(range2=>{deleteIndexes.push(range2.startIndex,range2.endIndex)}),deleteIndexes.sort((pre,aft)=>pre-aft);const deleteStart=deleteIndexes[0],doMutation={id:RichTextEditingMutation.id,params:{unitId,actions:[],textRanges:[{startOffset:deleteStart,endOffset:deleteStart,collapsed:!0}],debounce:!0}},textX=new core.TextX,jsonX=core.JSONX.getInstance();let cursor=0;for(let i=0;i<deleteIndexes.length;i++){const deleteIndex=deleteIndexes[i];deleteIndex-cursor>0&&textX.push({t:core.TextXActionType.RETAIN,len:deleteIndex-cursor,segmentId}),textX.push({t:core.TextXActionType.DELETE,len:1,segmentId,line:0}),cursor=deleteIndex+1}const path=getRichTextEditPath(docDataModel,segmentId);return doMutation.params.actions=jsonX.editOp(textX.serialize(),path),!!commandService.syncExecuteCommand(doMutation.id,doMutation.params)},"handler")},UpdateCommand={id:"doc.command.update-text",type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{const{range,segmentId,updateBody,coverType,unitId,textRanges}=params,commandService=accessor.get(core.ICommandService),docDataModel=accessor.get(core.IUniverInstanceService).getCurrentUniverDocInstance();if(docDataModel==null)return!1;const doMutation={id:RichTextEditingMutation.id,params:{unitId,actions:[],textRanges}},textX=new core.TextX,jsonX=core.JSONX.getInstance(),{startOffset,endOffset}=range;textX.push({t:core.TextXActionType.RETAIN,len:startOffset,segmentId}),textX.push({t:core.TextXActionType.RETAIN,body:updateBody,len:endOffset-startOffset,segmentId,coverType});const path=getRichTextEditPath(docDataModel,segmentId);return doMutation.params.actions=jsonX.editOp(textX.serialize(),path),!!commandService.syncExecuteCommand(doMutation.id,doMutation.params)},"handler")};function generateParagraphs(dataStream,prevParagraph){const paragraphs=[];for(let i=0,len=dataStream.length;i<len;i++)dataStream[i]===core.DataStreamTreeTokenType.PARAGRAPH&¶graphs.push({startIndex:i});if(prevParagraph)for(const paragraph of paragraphs)prevParagraph.bullet&&(paragraph.bullet=core.Tools.deepClone(prevParagraph.bullet)),prevParagraph.paragraphStyle&&(paragraph.paragraphStyle=core.Tools.deepClone(prevParagraph.paragraphStyle));return paragraphs}__name(generateParagraphs,"generateParagraphs");const BreakLineCommand={id:"doc.command.break-line",type:core.CommandType.COMMAND,handler:__name(async accessor=>{var _a10,_b;const textSelectionManagerService=accessor.get(exports.TextSelectionManagerService),univerInstanceService=accessor.get(core.IUniverInstanceService),commandService=accessor.get(core.ICommandService),customRangeService=accessor.get(DocCustomRangeService),activeRange=textSelectionManagerService.getActiveRange();if(activeRange==null)return!1;const{segmentId}=activeRange,docDataModel=univerInstanceService.getCurrentUniverDocInstance(),body=docDataModel==null?void 0:docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();if(!docDataModel||!body)return!1;const unitId=docDataModel.getUnitId(),{startOffset,endOffset}=getInsertSelection(activeRange,body),prevParagraph=((_a10=body.paragraphs)!=null?_a10:[]).find(p=>p.startIndex>=startOffset);if(prevParagraph&&prevParagraph.startIndex>endOffset){const bodyAfter=core.normalizeBody(core.getBodySlice(body,endOffset,prevParagraph.startIndex));bodyAfter.customRanges=(_b=bodyAfter.customRanges)==null?void 0:_b.map(range=>customRangeService.copyCustomRange(unitId,range));const deleteRange={startOffset,endOffset:prevParagraph.startIndex,collapsed:!1};return core.updateAttributeByInsert(bodyAfter,{dataStream:core.DataStreamTreeTokenType.PARAGRAPH,paragraphs:generateParagraphs(core.DataStreamTreeTokenType.PARAGRAPH,prevParagraph)},1,0),await commandService.executeCommand(InsertCommand.id,{unitId,body:bodyAfter,range:deleteRange,segmentId,cursorOffset:1})}else return await commandService.executeCommand(InsertCommand.id,{unitId,body:{dataStream:core.DataStreamTreeTokenType.PARAGRAPH,paragraphs:generateParagraphs(core.DataStreamTreeTokenType.PARAGRAPH,prevParagraph)},range:activeRange,segmentId})},"handler")},InnerPasteCommand={id:"doc.command.inner-paste",type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{const{segmentId,textRanges,body}=params,commandService=accessor.get(core.ICommandService),textSelectionManagerService=accessor.get(exports.TextSelectionManagerService),univerInstanceService=accessor.get(core.IUniverInstanceService),selections=textSelectionManagerService.getCurrentSelections();if(!Array.isArray(selections)||selections.length===0)return!1;const docDataModel=univerInstanceService.getCurrentUniverDocInstance(),originBody=docDataModel==null?void 0:docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();if(docDataModel==null||originBody==null)return!1;const unitId=docDataModel.getUnitId(),doMutation={id:RichTextEditingMutation.id,params:{unitId,actions:[],textRanges}},memoryCursor=new core.MemoryCursor;memoryCursor.reset();const textX=new core.TextX,jsonX=core.JSONX.getInstance();for(const selection of selections){const{startOffset,endOffset,collapsed}=selection,len=startOffset-memoryCursor.cursor;if(collapsed)textX.push({t:core.TextXActionType.RETAIN,len,segmentId});else{const{dos}=getRetainAndDeleteFromReplace(selection,segmentId,memoryCursor.cursor,originBody);textX.push(...dos)}textX.push({t:core.TextXActionType.INSERT,body,len:body.dataStream.length,line:0,segmentId}),memoryCursor.reset(),memoryCursor.moveCursor(endOffset)}const path=getRichTextEditPath(docDataModel,segmentId);return doMutation.params.actions=jsonX.editOp(textX.serialize(),path),!!commandService.syncExecuteCommand(doMutation.id,doMutation.params)},"handler")},CutContentCommand={id:"doc.command.inner-cut",type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{var _a10,_b,_c,_d;const{segmentId,textRanges}=params,commandService=accessor.get(core.ICommandService),textSelectionManagerService=accessor.get(exports.TextSelectionManagerService),univerInstanceService=accessor.get(core.IUniverInstanceService),selections=(_a10=params.selections)!=null?_a10:textSelectionManagerService.getCurrentSelections();if(!Array.isArray(selections)||selections.length===0)return!1;const unitId=(_b=univerInstanceService.getCurrentUniverDocInstance())==null?void 0:_b.getUnitId();if(!unitId)return!1;const docDataModel=univerInstanceService.getUniverDocInstance(unitId),originBody=core.getDocsUpdateBody(docDataModel.getSnapshot(),segmentId);if(docDataModel==null||originBody==null)return!1;const doMutation={id:RichTextEditingMutation.id,params:{unitId,actions:[],textRanges}},memoryCursor=new core.MemoryCursor;memoryCursor.reset();const textX=new core.TextX,jsonX=core.JSONX.getInstance(),rawActions=[];for(const selection of selections){const{startOffset,endOffset,collapsed}=selection;if(startOffset==null||endOffset==null)continue;const len=startOffset-memoryCursor.cursor;collapsed?textX.push({t:core.TextXActionType.RETAIN,len,segmentId}):textX.push(...getRetainAndDeleteAndExcludeLineBreak(selection,originBody,segmentId,memoryCursor.cursor)),memoryCursor.reset(),memoryCursor.moveCursor(endOffset)}const path=getRichTextEditPath(docDataModel,segmentId);rawActions.push(jsonX.editOp(textX.serialize(),path));const removedCustomBlockIds=getCustomBlockIdsInSelections(originBody,selections),drawings=(_c=docDataModel.getDrawings())!=null?_c:{},drawingOrder=(_d=docDataModel.getDrawingsOrder())!=null?_d:[],sortedRemovedCustomBlockIds=removedCustomBlockIds.sort((a,b)=>drawingOrder.indexOf(a)>drawingOrder.indexOf(b)?-1:drawingOrder.indexOf(a)<drawingOrder.indexOf(b)?1:0);if(sortedRemovedCustomBlockIds.length>0)for(const blockId of sortedRemovedCustomBlockIds){const drawing=drawings[blockId],drawingIndex=drawingOrder.indexOf(blockId);if(drawing==null||drawingIndex<0)continue;const removeDrawingAction=jsonX.removeOp(["drawings",blockId],drawing),removeDrawingOrderAction=jsonX.removeOp(["drawingsOrder",drawingIndex],blockId);rawActions.push(removeDrawingAction),rawActions.push(removeDrawingOrderAction)}return doMutation.params.actions=rawActions.reduce((acc,cur)=>core.JSONX.compose(acc,cur),null),!!commandService.syncExecuteCommand(doMutation.id,doMutation.params)},"handler")};function getCustomBlockIdsInSelections(body,selections){const customBlockIds=[],{customBlocks=[]}=body;for(const selection of selections){const{startOffset,endOffset}=selection;if(!(startOffset==null||endOffset==null))for(const customBlock of customBlocks){const{startIndex}=customBlock;startIndex>=startOffset&&startIndex<endOffset&&customBlockIds.push(customBlock.blockId)}}return customBlockIds}__name(getCustomBlockIdsInSelections,"getCustomBlockIdsInSelections");const DeleteCustomBlockCommand={id:"doc.command.delete-custom-block",type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{var _a10;const textSelectionManagerService=accessor.get(exports.TextSelectionManagerService),univerInstanceService=accessor.get(core.IUniverInstanceService),commandService=accessor.get(core.ICommandService),activeRange=textSelectionManagerService.getActiveRange(),documentDataModel=univerInstanceService.getCurrentUniverDocInstance();if(activeRange==null||documentDataModel==null)return!1;const{direction,range,unitId,drawingId}=params,{startOffset,segmentId,style}=activeRange,cursor=direction===DeleteDirection.LEFT?startOffset-1:startOffset,textRanges=[{startOffset:cursor,endOffset:cursor,style}],doMutation={id:RichTextEditingMutation.id,params:{unitId,actions:[],textRanges,prevTextRanges:[range]}},textX=new core.TextX,jsonX=core.JSONX.getInstance(),rawActions=[];startOffset>0&&textX.push({t:core.TextXActionType.RETAIN,len:direction===DeleteDirection.LEFT?startOffset-1:startOffset,segmentId}),textX.push({t:core.TextXActionType.DELETE,len:1,line:0,segmentId});const path=getRichTextEditPath(documentDataModel,segmentId);rawActions.push(jsonX.editOp(textX.serialize(),path));const drawing=((_a10=documentDataModel.getDrawings())!=null?_a10:{})[drawingId],drawingIndex=documentDataModel.getDrawingsOrder().indexOf(drawingId),removeDrawingAction=jsonX.removeOp(["drawings",drawingId],drawing),removeDrawingOrderAction=jsonX.removeOp(["drawingsOrder",drawingIndex],drawingId);return rawActions.push(removeDrawingAction),rawActions.push(removeDrawingOrderAction),doMutation.params.actions=rawActions.reduce((acc,cur)=>core.JSONX.compose(acc,cur),null),!!commandService.syncExecuteCommand(doMutation.id,doMutation.params)},"handler")},MergeTwoParagraphCommand={id:"doc.command.merge-two-paragraph",type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{var _a10,_b;const textSelectionManagerService=accessor.get(exports.TextSelectionManagerService),univerInstanceService=accessor.get(core.IUniverInstanceService),commandService=accessor.get(core.ICommandService),{direction,range}=params,activeRange=textSelectionManagerService.getActiveRange(),ranges=textSelectionManagerService.getCurrentSelections();if(activeRange==null||ranges==null)return!1;const{segmentId,style}=activeRange,docDataModel=univerInstanceService.getCurrentUniverDocInstance(),originBody=docDataModel==null?void 0:docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();if(!docDataModel||!originBody)return!1;const actualRange=getDeleteSelection(activeRange,originBody),unitId=docDataModel.getUnitId(),{startOffset,collapsed}=actualRange;if(!collapsed)return!1;const startIndex=direction===DeleteDirection.LEFT?startOffset:startOffset+1,endIndex=(_b=(_a10=originBody.paragraphs)==null?void 0:_a10.find(p=>p.startIndex>=startIndex))==null?void 0:_b.startIndex,body=getParagraphBody(accessor,unitId,originBody,startIndex,endIndex),cursor=direction===DeleteDirection.LEFT?startOffset-1:startOffset,textRanges=[{startOffset:cursor,endOffset:cursor,style}],doMutation={id:RichTextEditingMutation.id,params:{unitId,actions:[],textRanges,prevTextRanges:[range]}},textX=new core.TextX,jsonX=core.JSONX.getInstance();textX.push({t:core.TextXActionType.RETAIN,len:direction===DeleteDirection.LEFT?startOffset-1:startOffset,segmentId}),body.dataStream.length&&textX.push({t:core.TextXActionType.INSERT,body,len:body.dataStream.length,line:0,segmentId}),textX.push({t:core.TextXActionType.RETAIN,len:1,segmentId}),textX.push({t:core.TextXActionType.DELETE,len:endIndex+1-startIndex,line:0,segmentId});const path=getRichTextEditPath(docDataModel,segmentId);return doMutation.params.actions=jsonX.editOp(textX.serialize(),path),!!commandService.syncExecuteCommand(doMutation.id,doMutation.params)},"handler")},DeleteLeftCommand={id:"doc.command.delete-left",type:core.CommandType.COMMAND,handler:__name(async accessor=>{var _a10,_b;const textSelectionManagerService=accessor.get(exports.TextSelectionManagerService),univerInstanceService=accessor.get(core.IUniverInstanceService),commandService=accessor.get(core.ICommandService);let result=!0;const docDataModel=univerInstanceService.getCurrentUniverDocInstance();if(!docDataModel)return!1;const unitId=docDataModel.getUnitId(),docSkeletonManagerService=getCommandSkeleton(accessor,unitId),activeRange=textSelectionManagerService.getActiveRange(),ranges=textSelectionManagerService.getCurrentSelections(),skeleton=docSkeletonManagerService==null?void 0:docSkeletonManagerService.getSkeleton();if(activeRange==null||skeleton==null||ranges==null)return!1;const{segmentId,style,segmentPage}=activeRange,body=docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();if(body==null)return!1;const actualRange=getDeleteSelection(activeRange,body),{startOffset,collapsed}=actualRange,curGlyph=skeleton.findNodeByCharIndex(startOffset,segmentId,segmentPage),isBullet=engineRender.hasListGlyph(curGlyph),isIndent=engineRender.isIndentByGlyph(curGlyph,body);let cursor=startOffset;const preGlyph=skeleton.findNodeByCharIndex(startOffset-1,segmentId,segmentPage);if(engineRender.isFirstGlyph(curGlyph)&&preGlyph!==curGlyph&&(isBullet===!0||isIndent===!0)&&collapsed){const paragraph=engineRender.getParagraphByGlyph(curGlyph,body);if(paragraph==null)return!1;const paragraphIndex=paragraph==null?void 0:paragraph.startIndex,updateParagraph={startIndex:0},paragraphStyle=paragraph.paragraphStyle;if(isBullet===!0){const paragraphStyle2=paragraph.paragraphStyle;if(paragraphStyle2){updateParagraph.paragraphStyle=paragraphStyle2;const{hanging}=paragraphStyle2;hanging&&(updateParagraph.paragraphStyle.indentStart=hanging,updateParagraph.paragraphStyle.hanging=void 0)}}else if(isIndent===!0){const bullet=paragraph.bullet;bullet&&(updateParagraph.bullet=bullet),paragraphStyle!=null&&(updateParagraph.paragraphStyle={...paragraphStyle},delete updateParagraph.paragraphStyle.hanging,delete updateParagraph.paragraphStyle.indentStart)}const textRanges=[{startOffset:cursor,endOffset:cursor,style}];result=await commandService.executeCommand(UpdateCommand.id,{unitId:docDataModel.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...updateParagraph}]},range:{startOffset:paragraphIndex,endOffset:paragraphIndex+1},textRanges,coverType:core.UpdateDocsAttributeType.REPLACE,segmentId})}else if(collapsed===!0){if(preGlyph==null)return!0;if(preGlyph.content==="\r")result=await commandService.executeCommand(MergeTwoParagraphCommand.id,{direction:DeleteDirection.LEFT,range:actualRange});else if(preGlyph.streamType==="\b"){const drawing=(_b=docDataModel.getSnapshot().drawings)==null?void 0:_b[(_a10=preGlyph.drawingId)!=null?_a10:""];if(drawing==null)return!0;if(drawing.layoutType===core.PositionedObjectLayoutType.INLINE){const unitId2=docDataModel.getUnitId();result=await commandService.executeCommand(DeleteCustomBlockCommand.id,{direction:DeleteDirection.LEFT,range:activeRange,unitId:unitId2,drawingId:preGlyph.drawingId})}else{const prePreGlyph=skeleton.findNodeByCharIndex(startOffset-2);if(prePreGlyph==null)return!0;cursor-=preGlyph.count,cursor-=prePreGlyph.count;const textRanges=[{startOffset:cursor,endOffset:cursor,style}];result=await commandService.executeCommand(DeleteCommand.id,{unitId:docDataModel.getUnitId(),range:{...activeRange,startOffset:activeRange.startOffset-1,endOffset:activeRange.endOffset-1},segmentId,direction:DeleteDirection.LEFT,len:prePreGlyph.count,textRanges})}}else cursor-=preGlyph.count,result=await commandService.executeCommand(DeleteCommand.id,{unitId:docDataModel.getUnitId(),range:actualRange,segmentId,direction:DeleteDirection.LEFT,len:preGlyph.count})}else{const textRanges=getTextRangesWhenDelete(actualRange,[actualRange]);result=await commandService.executeCommand(CutContentCommand.id,{segmentId,textRanges,selections:[actualRange]})}return result},"handler")},DeleteRightCommand={id:"doc.command.delete-right",type:core.CommandType.COMMAND,handler:__name(async accessor=>{var _a10,_b;const textSelectionManagerService=accessor.get(exports.TextSelectionManagerService),docDataModel=accessor.get(core.IUniverInstanceService).getCurrentUniverDocInstance();if(!docDataModel)return!1;const docSkeletonManagerService=getCommandSkeleton(accessor,docDataModel.getUnitId()),commandService=accessor.get(core.ICommandService),activeRange=textSelectionManagerService.getActiveRange(),ranges=textSelectionManagerService.getCurrentSelections(),skeleton=docSkeletonManagerService==null?void 0:docSkeletonManagerService.getSkeleton();if(activeRange==null||skeleton==null||ranges==null)return!1;const{segmentId,style,segmentPage}=activeRange,body=docDataModel==null?void 0:docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();if(!docDataModel||!body)return!1;const actualRange=getDeleteSelection(activeRange,body,DeleteDirection.RIGHT),{startOffset,endOffset,collapsed}=actualRange;if(startOffset===body.dataStream.length-2&&collapsed)return!0;let result=!1;if(collapsed===!0){const needDeleteGlyph=skeleton.findNodeByCharIndex(startOffset,segmentId,segmentPage),nextGlyph=skeleton.findNodeByCharIndex(startOffset+1);if(needDeleteGlyph.content==="\r")result=await commandService.executeCommand(MergeTwoParagraphCommand.id,{direction:DeleteDirection.RIGHT,range:activeRange});else if(needDeleteGlyph.streamType==="\b"){const drawing=(_b=docDataModel.getSnapshot().drawings)==null?void 0:_b[(_a10=needDeleteGlyph.drawingId)!=null?_a10:""];if(drawing==null)return!0;if(drawing.layoutType===core.PositionedObjectLayoutType.INLINE){const unitId=docDataModel.getUnitId();result=await commandService.executeCommand(DeleteCustomBlockCommand.id,{direction:DeleteDirection.RIGHT,range:activeRange,unitId,drawingId:needDeleteGlyph.drawingId})}else{if(nextGlyph==null)return!0;const textRanges=[{startOffset:startOffset+1,endOffset:startOffset+1,style}];result=await commandService.executeCommand(DeleteCommand.id,{unitId:docDataModel.getUnitId(),range:{...activeRange,startOffset:startOffset+1,endOffset:endOffset+1},segmentId,direction:DeleteDirection.RIGHT,textRanges,len:nextGlyph.count})}}else{const textRanges=[{startOffset,endOffset:startOffset,style}];result=await commandService.executeCommand(DeleteCommand.id,{unitId:docDataModel.getUnitId(),range:actualRange,segmentId,direction:DeleteDirection.RIGHT,textRanges,len:needDeleteGlyph.count})}}else{const textRanges=getTextRangesWhenDelete(actualRange,[actualRange]);result=await commandService.executeCommand(CutContentCommand.id,{segmentId,textRanges,selections:[actualRange]})}return result},"handler")};function getParagraphBody(accessor,unitId,body,start,end){const{textRuns:originTextRuns=[],customBlocks:originCustomBlocks=[]}=body,dataStream=body.dataStream.substring(start,end),customRangeService=accessor.get(DocCustomRangeService),bodySlice={dataStream,customRanges:core.getCustomRangeSlice(body,start,end).customRanges.map(range=>customRangeService.copyCustomRange(unitId,range)),customDecorations:core.getCustomDecorationSlice(body,start,end)},textRuns=[];for(const textRun of originTextRuns){const{st,ed}=textRun;ed<=start||st>=end||(st<start?textRuns.push({...textRun,st:0,ed:ed-start}):ed>end?textRuns.push({...textRun,st:st-start,ed:end-start}):textRuns.push({...textRun,st:st-start,ed:ed-start}))}textRuns.length>0&&(bodySlice.textRuns=textRuns);const customBlocks=[];for(const block of originCustomBlocks){const{startIndex}=block;startIndex>=start&&startIndex<=end&&customBlocks.push({...block,startIndex:startIndex-start})}return customBlocks.length>0&&(bodySlice.customBlocks=customBlocks),bodySlice}__name(getParagraphBody,"getParagraphBody");function getTextRangesWhenDelete(activeRange,ranges){let cursor=activeRange.endOffset;for(const range of ranges){const{startOffset,endOffset}=range;startOffset==null||endOffset==null||endOffset<=activeRange.endOffset&&(cursor-=endOffset-startOffset)}return[{startOffset:cursor,endOffset:cursor,style:activeRange.style}]}__name(getTextRangesWhenDelete,"getTextRangesWhenDelete");const IMEInputCommand={id:"doc.command.ime-input",type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{const{unitId,newText,oldTextLen,isCompositionEnd,isCompositionStart}=params,commandService=accessor.get(core.ICommandService),imeInputManagerService=accessor.get(IMEInputManagerService),docDataModel=accessor.get(core.IUniverInstanceService).getCurrentUniverDocInstance();if(docDataModel==null)return!1;const previousActiveRange=imeInputManagerService.getActiveRange();if(!previousActiveRange)return!1;const{startOffset,style,segmentId}=previousActiveRange,body=docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();if(body==null)return!1;const insertRange=getInsertSelection(previousActiveRange,body);Object.assign(previousActiveRange,insertRange);const len=newText.length,textRanges=[{startOffset:startOffset+len,endOffset:startOffset+len,collapsed:!0,style}],doMutation={id:RichTextEditingMutation.id,params:{unitId,actions:[],textRanges}},textX=new core.TextX,jsonX=core.JSONX.getInstance();if(!previousActiveRange.collapsed&&isCompositionStart){const{dos,retain,cursor}=getRetainAndDeleteFromReplace(previousActiveRange,segmentId,0,body);textX.push(...dos),doMutation.params.textRanges=[{startOffset:startOffset+len+retain,endOffset:startOffset+len+retain,collapsed:!0}]}else textX.push({t:core.TextXActionType.RETAIN,len:startOffset,segmentId});oldTextLen>0&&textX.push({t:core.TextXActionType.DELETE,len:oldTextLen,line:0,segmentId}),textX.push({t:core.TextXActionType.INSERT,body:{dataStream:newText},len:newText.length,line:0,segmentId});const path=getRichTextEditPath(docDataModel,segmentId);doMutation.params.actions=jsonX.editOp(textX.serialize(),path),doMutation.params.noHistory=!isCompositionEnd,doMutation.params.isCompositionEnd=isCompositionEnd;const result=commandService.syncExecuteCommand(doMutation.id,doMutation.params);return imeInputManagerService.pushUndoRedoMutationParams(result,doMutation.params),!!result},"handler")};function handleInlineFormat(preCommandId,params,textSelectionManagerService,commandService){var _a10;const{segmentId}=(_a10=textSelectionManagerService.getActiveRange())!=null?_a10:{};return segmentId==null?!1:commandService.executeCommand(SetInlineFormatCommand.id,{segmentId,preCommandId,...params!=null?params:{}})}__name(handleInlineFormat,"handleInlineFormat");const SetInlineFormatBoldCommandId="doc.command.set-inline-format-bold",SetInlineFormatBoldCommand={id:SetInlineFormatBoldCommandId,type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{const commandService=accessor.get(core.ICommandService),textSelectionManagerService=accessor.get(exports.TextSelectionManagerService);return handleInlineFormat(SetInlineFormatBoldCommandId,params,textSelectionManagerService,commandService)},"handler")},SetInlineFormatItalicCommandId="doc.command.set-inline-format-italic",SetInlineFormatItalicCommand={id:SetInlineFormatItalicCommandId,type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{const commandService=accessor.get(core.ICommandService),textSelectionManagerService=accessor.get(exports.TextSelectionManagerService);return handleInlineFormat(SetInlineFormatItalicCommandId,params,textSelectionManagerService,commandService)},"handler")},SetInlineFormatUnderlineCommandId="doc.command.set-inline-format-underline",SetInlineFormatUnderlineCommand={id:SetInlineFormatUnderlineCommandId,type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{const commandService=accessor.get(core.ICommandService),textSelectionManagerService=accessor.get(exports.TextSelectionManagerService);return handleInlineFormat(SetInlineFormatUnderlineCommandId,params,textSelectionManagerService,commandService)},"handler")},SetInlineFormatStrikethroughCommandId="doc.command.set-inline-format-strikethrough",SetInlineFormatStrikethroughCommand={id:SetInlineFormatStrikethroughCommandId,type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{const commandService=accessor.get(core.ICommandService),textSelectionManagerService=accessor.get(exports.TextSelectionManagerService);return handleInlineFormat(SetInlineFormatStrikethroughCommandId,params,textSelectionManagerService,commandService)},"handler")},SetInlineFormatSubscriptCommandId="doc.command.set-inline-format-subscript",SetInlineFormatSubscriptCommand={id:SetInlineFormatSubscriptCommandId,type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{const commandService=accessor.get(core.ICommandService),textSelectionManagerService=accessor.get(exports.TextSelectionManagerService);return handleInlineFormat(SetInlineFormatSubscriptCommandId,params,textSelectionManagerService,commandService)},"handler")},SetInlineFormatSuperscriptCommandId="doc.command.set-inline-format-superscript",SetInlineFormatSuperscriptCommand={id:SetInlineFormatSuperscriptCommandId,type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{const commandService=accessor.get(core.ICommandService),textSelectionManagerService=accessor.get(exports.TextSelectionManagerService);return handleInlineFormat(SetInlineFormatSuperscriptCommandId,params,textSelectionManagerService,commandService)},"handler")},SetInlineFormatFontSizeCommandId="doc.command.set-inline-format-fontsize",SetInlineFormatFontSizeCommand={id:SetInlineFormatFontSizeCommandId,type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{const commandService=accessor.get(core.ICommandService),textSelectionManagerService=accessor.get(exports.TextSelectionManagerService);return handleInlineFormat(SetInlineFormatFontSizeCommandId,params,textSelectionManagerService,commandService)},"handler")},SetInlineFormatFontFamilyCommandId="doc.command.set-inline-format-font-family",SetInlineFormatFontFamilyCommand={id:SetInlineFormatFontFamilyCommandId,type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{const commandService=accessor.get(core.ICommandService),textSelectionManagerService=accessor.get(exports.TextSelectionManagerService);return handleInlineFormat(SetInlineFormatFontFamilyCommandId,params,textSelectionManagerService,commandService)},"handler")},SetInlineFormatTextColorCommandId="doc.command.set-inline-format-text-color",SetInlineFormatTextColorCommand={id:SetInlineFormatTextColorCommandId,type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{const commandService=accessor.get(core.ICommandService),textSelectionManagerService=accessor.get(exports.TextSelectionManagerService);return handleInlineFormat(SetInlineFormatTextColorCommandId,params,textSelectionManagerService,commandService)},"handler")},SetInlineFormatTextBackgroundColorCommandId="doc.command.set-inline-format-text-background-color",SetInlineFormatTextBackgroundColorCommand={id:SetInlineFormatTextBackgroundColorCommandId,type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{const commandService=accessor.get(core.ICommandService),textSelectionManagerService=accessor.get(exports.TextSelectionManagerService);return handleInlineFormat(SetInlineFormatTextBackgroundColorCommandId,params,textSelectionManagerService,commandService)},"handler")},ResetInlineFormatTextBackgroundColorCommandId="doc.command.reset-inline-format-text-background-color",ResetInlineFormatTextBackgroundColorCommand={id:ResetInlineFormatTextBackgroundColorCommandId,type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{const commandService=accessor.get(core.ICommandService),textSelectionManagerService=accessor.get(exports.TextSelectionManagerService);return handleInlineFormat(ResetInlineFormatTextBackgroundColorCommandId,params,textSelectionManagerService,commandService)},"handler")},COMMAND_ID_TO_FORMAT_KEY_MAP={[SetInlineFormatBoldCommand.id]:"bl",[SetInlineFormatItalicCommand.id]:"it",[SetInlineFormatUnderlineCommand.id]:"ul",[SetInlineFormatStrikethroughCommand.id]:"st",[SetInlineFormatFontSizeCommand.id]:"fs",[SetInlineFormatFontFamilyCommand.id]:"ff",[SetInlineFormatTextColorCommand.id]:"cl",[SetInlineFormatTextBackgroundColorCommand.id]:"bg",[ResetInlineFormatTextBackgroundColorCommand.id]:"bg",[SetInlineFormatSubscriptCommand.id]:"va",[SetInlineFormatSuperscriptCommand.id]:"va"},SetInlineFormatCommand={id:"doc.command.set-inline-format",type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{const{segmentId,value,preCommandId}=params,commandService=accessor.get(core.ICommandService),textSelectionManagerService=accessor.get(exports.TextSelectionManagerService),univerInstanceService=accessor.get(core.IUniverInstanceService),selections=textSelectionManagerService.getCurrentSelections();if(!Array.isArray(selections)||selections.length===0)return!1;const docDataModel=univerInstanceService.getCurrentUniverDocInstance();if(docDataModel==null)return!1;const unitId=docDataModel.getUnitId();let formatValue;switch(preCommandId){case SetInlineFormatBoldCommand.id:case SetInlineFormatItalicCommand.id:case SetInlineFormatUnderlineCommand.id:case SetInlineFormatStrikethroughCommand.id:case SetInlineFormatSubscriptCommand.id:case SetInlineFormatSuperscriptCommand.id:{formatValue=getReverseFormatValueInSelection(docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody().textRuns,preCommandId,selections);break}case SetInlineFormatFontSizeCommand.id:case SetInlineFormatFontFamilyCommand.id:{formatValue=value;break}case SetInlineFormatTextColorCommand.id:case SetInlineFormatTextBackgroundColorCommand.id:{formatValue={rgb:value};break}case ResetInlineFormatTextBackgroundColorCommand.id:{formatValue={rgb:null};break}default:throw new Error(`Unknown command: ${preCommandId} in handleInlineFormat`)}const doMutation={id:RichTextEditingMutation.id,params:{unitId,actions:[],textRanges:selections.map(serializeTextRange)}},textX=new core.TextX,jsonX=core.JSONX.getInstance(),memoryCursor=new core.MemoryCursor;memoryCursor.reset();for(const selection of selections){const{startOffset,endOffset}=selection,body={dataStream:"",textRuns:[{st:0,ed:endOffset-startOffset,ts:{[COMMAND_ID_TO_FORMAT_KEY_MAP[preCommandId]]:formatValue}}]},len=startOffset-memoryCursor.cursor;len!==0&&textX.push({t:core.TextXActionType.RETAIN,len,segmentId}),textX.push({t:core.TextXActionType.RETAIN,body,len:endOffset-startOffset,segmentId}),memoryCursor.reset(),memoryCursor.moveCursor(endOffset)}const path=getRichTextEditPath(docDataModel,segmentId);return doMutation.params.actions=jsonX.editOp(textX.serialize(),path),!!commandService.syncExecuteCommand(doMutation.id,doMutation.params)},"handler")};function isTextDecoration(value){return value!==null&&typeof value=="object"}__name(isTextDecoration,"isTextDecoration");function getReverseFormatValueInSelection(textRuns,preCommandId,selections){let ti=0,si=0;const key=COMMAND_ID_TO_FORMAT_KEY_MAP[preCommandId];for(;ti!==textRuns.length&&si!==selections.length;){const{startOffset,endOffset}=selections[si],{st,ed,ts}=textRuns[ti];if(endOffset<=st)si++;else if(ed<=startOffset)ti++;else{if(/bl|it/.test(key))return(ts==null?void 0:ts[key])===core.BooleanNumber.TRUE?core.BooleanNumber.FALSE:core.BooleanNumber.TRUE;if(/ul|st/.test(key))return isTextDecoration(ts==null?void 0:ts[key])&&(ts==null?void 0:ts[key]).s===core.BooleanNumber.TRUE?{s:core.BooleanNumber.FALSE}:{s:core.BooleanNumber.TRUE};if(/va/.test(key))return preCommandId===SetInlineFormatSubscriptCommand.id?(ts==null?void 0:ts[key])===core.BaselineOffset.SUBSCRIPT?core.BaselineOffset.NORMAL:core.BaselineOffset.SUBSCRIPT:(ts==null?void 0:ts[key])===core.BaselineOffset.SUPERSCRIPT?core.BaselineOffset.NORMAL:core.BaselineOffset.SUPERSCRIPT;ti++}}return/bl|it/.test(key)?core.BooleanNumber.TRUE:/ul|st/.test(key)?{s:core.BooleanNumber.TRUE}:preCommandId===SetInlineFormatSubscriptCommand.id?core.BaselineOffset.SUBSCRIPT:core.BaselineOffset.SUPERSCRIPT}__name(getReverseFormatValueInSelection,"getReverseFormatValueInSelection");const ListOperationCommand={id:"doc.command.list-operation",type:core.CommandType.COMMAND,handler:__name((accessor,params)=>{var _a10,_b,_c,_d,_e,_f;const textSelectionManagerService=accessor.get(exports.TextSelectionManagerService),univerInstanceService=accessor.get(core.IUniverInstanceService),commandService=accessor.get(core.ICommandService),{listType}=params,docDataModel=univerInstanceService.getCurrentUniverDocInstance(),activeRange=textSelectionManagerService.getActiveRange();if(docDataModel==null||activeRange==null)return!1;const{segmentId}=activeRange,selections=(_a10=textSelectionManagerService.getCurrentSelections())!=null?_a10:[],paragraphs=(_b=docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody())==null?void 0:_b.paragraphs,serializedSelections=selections.map(serializeTextRange);if(paragraphs==null)return!1;const sectionBreaks=(_d=(_c=docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody())==null?void 0:_c.sectionBreaks)!=null?_d:[],currentParagraphs=getParagraphsInRange(activeRange,paragraphs),unitId=docDataModel.getUnitId(),isAlreadyList=currentParagraphs.every(paragraph=>{var _a11;return((_a11=paragraph.bullet)==null?void 0:_a11.listType)===listType});let listId=core.Tools.generateRandomId(6);if(currentParagraphs.length===1){const curIndex=paragraphs.indexOf(currentParagraphs[0]),prevParagraph=paragraphs[curIndex-1],nextParagraph=paragraphs[curIndex+1];prevParagraph&&prevParagraph.bullet&&prevParagraph.bullet.listType===listType?listId=prevParagraph.bullet.listId:nextParagraph&&nextParagraph.bullet&&nextParagraph.bullet.listType===listType&&(listId=nextParagraph.bullet.listId)}const doMutation={id:RichTextEditingMutation.id,params:{unitId,actions:[],textRanges:serializedSelections}},memoryCursor=new core.MemoryCursor;memoryCursor.reset();const textX=new core.TextX,jsonX=core.JSONX.getInstance(),customLists=(_e=docDataModel.getSnapshot().lists)!=null?_e:{},lists={...core.PRESET_LIST_TYPE,...customLists},{defaultTabStop=36}=docDataModel.getSnapshot().documentStyle;for(const paragraph of currentParagraphs){const{startIndex,paragraphStyle={}}=paragraph,{indentFirstLine,snapToGrid,indentStart}=paragraphStyle,paragraphProperties=lists[listType].nestingLevel[0].paragraphProperties||{},{hanging:listHanging,indentStart:listIndentStart}=paragraphProperties,{charSpace,gridType}=findNearestSectionBreak(startIndex,sectionBreaks)||{charSpace:0,gridType:core.GridType.LINES},charSpaceApply=engineRender.getCharSpaceApply(charSpace,defaultTabStop,gridType,snapToGrid);textX.push({t:core.TextXActionType.RETAIN,len:startIndex-memoryCursor.cursor,segmentId}),textX.push({t:core.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[isAlreadyList?{paragraphStyle:{...paragraphStyle,hanging:void 0,indentStart:indentStart?{v:Math.max(0,engineRender.getNumberUnitValue(indentStart,charSpaceApply)+engineRender.getNumberUnitValue(listHanging,charSpaceApply)-engineRender.getNumberUnitValue(listIndentStart,charSpaceApply))}:void 0},startIndex:0}:{startIndex:0,paragraphStyle:{...paragraphStyle,indentFirstLine:void 0,hanging:listHanging,indentStart:{v:engineRender.getNumberUnitValue(listIndentStart,charSpaceApply)-engineRender.getNumberUnitValue(listHanging,charSpaceApply)+engineRender.getNumberUnitValue(indentFirstLine,charSpaceApply)+engineRender.getNumberUnitValue(indentStart,charSpaceApply)}},bullet:{...(_f=paragraph.bullet)!=null?_f:{nestingLevel:0,textStyle:{fs:20}},listType,listId}}]},segmentId,coverType:core.UpdateDocsAttributeType.REPLACE}),memoryCursor.moveCursorTo(startIndex+1)}const path=getRichTextEditPath(docDataModel,segmentId);return doMutation.params.actions=jsonX.editOp(textX.serialize(),path),!!commandService.syncExecuteCommand(doMutation.id,doMutation.params)},"handler")},BulletListCommand={id:"doc.command.bullet-list",type:core.CommandType.COMMAND,handler:__name(accessor=>accessor.get(core.ICommandService).syncExecuteCommand(ListOperationCommand.id,{listType:core.PresetListType.BULLET_LIST}),"handler")},OrderListCommand={id:"doc.command.order-list",type:core.CommandType.COMMAND,handler:__name(accessor=>accessor.get(core.ICommandService).syncExecuteCommand(ListOperationCommand.id,{listType:core.PresetListType.ORDER_LIST}),"handler")};function getParagraphsInRange(activeRange,paragraphs){const{startOffset,endOffset}=activeRange,results=[];let start=-1;for(const paragraph of paragraphs){const{startIndex}=paragraph;(startOffset>start&&startOffset<=startIndex||endOffset>start&&endOffset<=startIndex||startIndex>=startOffset&&startIndex<=endOffset)&&results.push(paragraph),start=startIndex}return results}__name(getParagraphsInRange,"getParagraphsInRange");function findNearestSectionBreak(currentIndex,sectionBreaks){const sortedSectionBreaks=sectionBreaks.sort(core.sortRulesFactory("startIndex"));for(let i=0;i<sortedSectionBreaks.length;i++){const sectionBreak=sectionBreaks[i];if(sectionBreak.startIndex>=currentIndex)return sectionBreak}}__name(findNearestSectionBreak,"findNearestSectionBreak");const ReplaceContentCommand={id:"doc.command-replace-content",type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{const{unitId,body,textRanges,segmentId="",options}=params,univerInstanceService=accessor.get(core.IUniverInstanceService),commandService=accessor.get(core.ICommandService),textSelectionManagerService=accessor.get(exports.TextSelectionManagerService),docDataModel=univerInstanceService.getUniverDocInstance(unitId),prevBody=docDataModel==null?void 0:docDataModel.getSnapshot().body,selections=textSelectionManagerService.getCurrentSelections();if(docDataModel==null||prevBody==null||!Array.isArray(selections)||selections.length===0)return!1;const doMutation=getMutationParams(unitId,segmentId,docDataModel,prevBody,body);return doMutation.params.textRanges=textRanges,options&&(doMutation.params.options=options),!!commandService.syncExecuteCommand(doMutation.id,doMutation.params)},"handler")},CoverContentCommand={id:"doc.command-cover-content",type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{const{unitId,body,segmentId=""}=params,univerInstanceService=accessor.get(core.IUniverInstanceService),commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService),docDatModel=univerInstanceService.getUniverDocInstance(unitId),prevBody=docDatModel==null?void 0:docDatModel.getSnapshot().body;if(docDatModel==null||prevBody==null)return!1;const doMutation=getMutationParams(unitId,segmentId,docDatModel,prevBody,body);return doMutation.params.noNeedSetTextRange=!0,doMutation.params.noHistory=!0,commandService.syncExecuteCommand(doMutation.id,doMutation.params),undoRedoService.clearUndoRedo(unitId),!0},"handler")};function getMutationParams(unitId,segmentId,docDatModel,prevBody,body){const doMutation={id:RichTextEditingMutation.id,params:{unitId,actions:[],textRanges:[]}},textX=new core.TextX,jsonX=core.JSONX.getInstance(),deleteLen=(prevBody==null?void 0:prevBody.dataStream.length)-2;deleteLen>0&&textX.push({t:core.TextXActionType.DELETE,len:deleteLen,line:0,segmentId}),body.dataStream.length>0&&textX.push({t:core.TextXActionType.INSERT,body,len:body.dataStream.length,line:0,segmentId});const path=getRichTextEditPath(docDatModel,segmentId);return doMutation.params.actions=jsonX.editOp(textX.serialize(),path),doMutation}__name(getMutationParams,"getMutationParams");core.CommandType.COMMAND;const SetDocZoomRatioUndoMutationFactory=__name((accessor,params)=>{const documentModel=accessor.get(core.IUniverInstanceService).getUniverDocInstance(params.unitId),old=(documentModel==null?void 0:documentModel.zoomRatio)||1;return{...core.Tools.deepClone(params),zoomRatio:old}},"SetDocZoomRatioUndoMutationFactory"),SetDocZoomRatioOperation={id:"doc.operation.set-zoom-ratio",type:core.CommandType.OPERATION,handler:__name((accessor,params)=>{const documentModel=accessor.get(core.IUniverInstanceService).getUniverDocInstance(params.unitId);if(!documentModel)return!1;const documentData=documentModel.getSnapshot();return documentData.settings==null?documentData.settings={zoomRatio:params.zoomRatio}:documentData.settings.zoomRatio=params.zoomRatio,!0},"handler")},SetDocZoomRatioCommand={type:core.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:__name(async(accessor,params)=>{var _a10,_b,_c;const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService),univerInstanceService=accessor.get(core.IUniverInstanceService);let documentId=(_a10=univerInstanceService.getCurrentUniverDocInstance())==null?void 0:_a10.getUnitId();if(!documentId)return!1;let zoomRatio=1;if(params&&(documentId=(_b=params.documentId)!=null?_b:documentId,zoomRatio=(_c=params.zoomRatio)!=null?_c:zoomRatio),!univerInstanceService.getUniverDocInstance(documentId))return!1;const setZoomRatioMutationParams={zoomRatio,unitId:documentId},undoMutationParams=SetDocZoomRatioUndoMutationFactory(accessor,setZoomRatioMutationParams);return commandService.syncExecuteCommand(SetDocZoomRatioOperation.id,setZoomRatioMutationParams)?(undoRedoService.pushUndoRedo({unitID:documentId,undoMutations:[{id:SetDocZoomRatioOperation.id,params:undoMutationParams}],redoMutations:[{id:SetDocZoomRatioOperation.id,params:setZoomRatioMutationParams}]}),!0):!1},"handler")},MoveCursorOperation={id:"doc.operation.move-cursor",type:core.CommandType.OPERATION,handler:__name((accessor,params)=>!!params,"handler")},MoveSelectionOperation={id:"doc.operation.move-selection",type:core.CommandType.OPERATION,handler:__name((accessor,params)=>!!params,"handler")},SelectAllOperation={id:"doc.operation.select-all",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const univerInstanceService=accessor.get(core.IUniverInstanceService),textSelectionManagerService=accessor.get(exports.TextSelectionManagerService),docDataModel=univerInstanceService.getCurrentUniverDocInstance(),activeTextRange=textSelectionManagerService.getActiveRange();if(docDataModel==null||activeTextRange==null)return!1;const{segmentId}=activeTextRange,prevBody=docDataModel.getSelfOrHeaderFooterModel(segmentId).getSnapshot().body;if(prevBody==null)return!1;const textRanges=[{startOffset:0,endOffset:prevBody.dataStream.length-2}];return textSelectionManagerService.replaceTextRanges(textRanges,!1),!0},"handler")};var __defProp$5=Object.defineProperty,__getOwnPropDesc$5=Object.getOwnPropertyDescriptor,__decorateClass$5=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$5(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$5(target,key,result),result},"__decorateClass$5"),__decorateParam$5=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$5"),_a4;let IMEInputController=(_a4=class extends core.Disposable{constructor(_univerInstanceService,_renderManagerSrv,_textSelectionRenderManager,_imeInputManagerService,_commandService){super();__publicField(this,"_previousIMEContent","");__publicField(this,"_isCompositionStart",!0);__publicField(this,"_onStartSubscription");__publicField(this,"_onUpdateSubscription");__publicField(this,"_onEndSubscription");this._univerInstanceService=_univerInstanceService,this._renderManagerSrv=_renderManagerSrv,this._textSelectionRenderManager=_textSelectionRenderManager,this._imeInputManagerService=_imeInputManagerService,this._commandService=_commandService,this._initialize()}dispose(){var _a10,_b,_c;(_a10=this._onStartSubscription)==null||_a10.unsubscribe(),(_b=this._onUpdateSubscription)==null||_b.unsubscribe(),(_c=this._onEndSubscription)==null||_c.unsubscribe()}_initialize(){this._initialOnCompositionstart(),this._initialOnCompositionUpdate(),this._initialOnCompositionend()}_initialOnCompositionstart(){this._onStartSubscription=this._textSelectionRenderManager.onCompositionstart$.subscribe(config=>{if(config==null)return;this._resetIME();const{activeRange}=config;activeRange!=null&&this._imeInputManagerService.setActiveRange(core.Tools.deepClone(activeRange))})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._textSelectionRenderManager.onCompositionupdate$.subscribe(async config=>{this._updateContent(config,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._textSelectionRenderManager.onCompositionend$.subscribe(config=>{this._updateContent(config,!1)})}async _updateContent(config,isUpdate){var _a10;if(config==null)return;const documentModel=this._univerInstanceService.getCurrentUniverDocInstance();if(!documentModel)return;const skeleton=(_a10=this._renderManagerSrv.getRenderById(documentModel.getUnitId()))==null?void 0:_a10.with(exports.DocSkeletonManagerService).getSkeleton(),{event,activeRange}=config;if(skeleton==null||activeRange==null)return;const content=event.data;content===this._previousIMEContent&&isUpdate||(await this._commandService.executeCommand(IMEInputCommand.id,{unitId:documentModel.getUnitId(),newText:content,oldTextLen:this._previousIMEContent.length,isCompositionStart:this._isCompositionStart,isCompositionEnd:!isUpdate}),isUpdate?(this._isCompositionStart&&(this._isCompositionStart=!1),this._previousIMEContent=content):this._resetIME())}_resetIME(){this._previousIMEContent="",this._isCompositionStart=!0,this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(null)}},__name(_a4,"IMEInputController"),_a4);IMEInputController=__decorateClass$5([core.OnLifecycle(core.LifecycleStages.Rendered,IMEInputController),__decorateParam$5(0,core.IUniverInstanceService),__decorateParam$5(1,engineRender.IRenderManagerService),__decorateParam$5(2,engineRender.ITextSelectionRenderManager),__decorateParam$5(3,core.Inject(IMEInputManagerService)),__decorateParam$5(4,core.ICommandService)],IMEInputController);var __defProp$4=Object.defineProperty,__getOwnPropDesc$4=Object.getOwnPropertyDescriptor,__decorateClass$4=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$4(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$4(target,key,result),result},"__decorateClass$4"),__decorateParam$4=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$4"),_a5;let MoveCursorController=(_a5=class extends core.Disposable{constructor(_univerInstanceService,_renderManagerService,_textSelectionManagerService,_commandService){super();__publicField(this,"_onInputSubscription");this._univerInstanceService=_univerInstanceService,this._renderManagerService=_renderManagerService,this._textSelectionManagerService=_textSelectionManagerService,this._commandService=_commandService,this._commandExecutedListener()}dispose(){var _a10;super.dispose(),(_a10=this._onInputSubscription)==null||_a10.unsubscribe()}_commandExecutedListener(){const updateCommandList=[MoveCursorOperation.id,MoveSelectionOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(command=>{if(!updateCommandList.includes(command.id))return;const param=command.params;switch(command.id){case MoveCursorOperation.id:return this._handleMoveCursor(param.direction);case MoveSelectionOperation.id:return this._handleShiftMoveSelection(param.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(direction){var _a10,_b,_c;const activeRange=this._textSelectionManagerService.getActiveRange(),allRanges=this._textSelectionManagerService.getCurrentSelections(),docDataModel=this._univerInstanceService.getCurrentUniverDocInstance();if(!docDataModel)return;const skeleton=(_a10=this._renderManagerService.getRenderById(docDataModel.getUnitId()))==null?void 0:_a10.with(exports.DocSkeletonManagerService).getSkeleton(),docObject=this._getDocObject();if(activeRange==null||skeleton==null||docObject==null)return;const{startOffset,endOffset,style,collapsed,direction:rangeDirection,segmentId,startNodePosition,endNodePosition,segmentPage}=activeRange;if(allRanges.length>1){let min=Number.POSITIVE_INFINITY,max=Number.NEGATIVE_INFINITY;for(const range of allRanges)min=Math.min(min,range.startOffset),max=Math.max(max,range.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:direction===core.Direction.LEFT||direction===core.Direction.UP?max:min,endOffset:direction===core.Direction.LEFT||direction===core.Direction.UP?min:max,style}],!1);return}const anchorOffset=collapsed||rangeDirection===engineRender.RANGE_DIRECTION.FORWARD?startOffset:endOffset;let focusOffset=collapsed||rangeDirection===engineRender.RANGE_DIRECTION.FORWARD?endOffset:startOffset;const dataStreamLength=(_b=docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody().dataStream.length)!=null?_b:Number.POSITIVE_INFINITY;if(direction===core.Direction.LEFT||direction===core.Direction.RIGHT){const preGlyph=skeleton.findNodeByCharIndex(focusOffset-1,segmentId,segmentPage),curGlyph=skeleton.findNodeByCharIndex(focusOffset,segmentId,segmentPage);focusOffset=direction===core.Direction.RIGHT?focusOffset+curGlyph.count:focusOffset-((_c=preGlyph==null?void 0:preGlyph.count)!=null?_c:0),focusOffset=Math.min(dataStreamLength-2,Math.max(0,focusOffset)),this._textSelectionManagerService.replaceTextRanges([{startOffset:anchorOffset,endOffset:focusOffset,style}],!1)}else{const focusGlyph=skeleton.findNodeByCharIndex(focusOffset,segmentId,segmentPage),documentOffsetConfig=docObject.document.getOffsetConfig(),focusNodePosition=collapsed?startNodePosition:rangeDirection===engineRender.RANGE_DIRECTION.FORWARD?endNodePosition:startNodePosition,newPos=this._getTopOrBottomPosition(skeleton,focusGlyph,focusNodePosition,direction===core.Direction.DOWN);if(newPos==null){const newFocusOffset=direction===core.Direction.UP?0:dataStreamLength-2;if(newFocusOffset===focusOffset)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:anchorOffset,endOffset:newFocusOffset,style}],!1);return}const newActiveRange=new engineRender.NodePositionConvertToCursor(documentOffsetConfig,skeleton).getRangePointData(newPos,newPos).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:anchorOffset,endOffset:newActiveRange.endOffset,style}],!1)}}_handleMoveCursor(direction){var _a10,_b,_c,_d;const activeRange=this._textSelectionManagerService.getActiveRange(),allRanges=this._textSelectionManagerService.getCurrentSelections(),docDataModel=this._univerInstanceService.getCurrentUniverDocInstance();if(!docDataModel)return!1;const skeleton=(_a10=this._renderManagerService.getRenderById(docDataModel.getUnitId()))==null?void 0:_a10.with(exports.DocSkeletonManagerService).getSkeleton(),docObject=this._getDocObject(),body=docDataModel.getBody();if(activeRange==null||skeleton==null||docObject==null||allRanges==null||body==null)return;const{startOffset,endOffset,style,collapsed,segmentId,startNodePosition,endNodePosition,segmentPage}=activeRange,dataStreamLength=(_b=docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody().dataStream.length)!=null?_b:Number.POSITIVE_INFINITY,customRanges=(_c=docDataModel.getCustomRanges())!=null?_c:[];if(direction===core.Direction.LEFT||direction===core.Direction.RIGHT){let cursor;if(!activeRange.collapsed||allRanges.length>1){let min=Number.POSITIVE_INFINITY,max=Number.NEGATIVE_INFINITY;for(const range of allRanges)min=Math.min(min,range.startOffset),max=Math.max(max,range.endOffset);cursor=direction===core.Direction.LEFT?min:max}else{const preSpan=skeleton.findNodeByCharIndex(startOffset-1,segmentId,segmentPage),curSpan=skeleton.findNodeByCharIndex(startOffset,segmentId,segmentPage);direction===core.Direction.LEFT?cursor=Math.max(0,startOffset-((_d=preSpan==null?void 0:preSpan.count)!=null?_d:0)):cursor=Math.min(dataStreamLength-2,endOffset+curSpan.count)}const skipTokens=[core.DataStreamTreeTokenType.CUSTOM_RANGE_START,core.DataStreamTreeTokenType.CUSTOM_RANGE_END];if(direction===core.Direction.LEFT)for(;skipTokens.includes(body.dataStream[cursor]);)cursor--;else for(;skipTokens.includes(body.dataStream[cursor-1]);)cursor++;customRanges.filter(range=>range.wholeEntity&&range.startIndex<cursor&&range.endIndex>=cursor).forEach(range=>{direction===core.Direction.LEFT?cursor=Math.min(range.startIndex,cursor):cursor=Math.max(range.endIndex+1,cursor)}),this._textSelectionManagerService.replaceTextRanges([{startOffset:cursor,endOffset:cursor,style}],!1)}else{const startNode=skeleton.findNodeByCharIndex(startOffset,segmentId,segmentPage),endNode=skeleton.findNodeByCharIndex(endOffset,segmentId,segmentPage),documentOffsetConfig=docObject.document.getOffsetConfig(),newPos=this._getTopOrBottomPosition(skeleton,direction===core.Direction.UP||collapsed?startNode:endNode,direction===core.Direction.UP||collapsed?startNodePosition:endNodePosition,direction===core.Direction.DOWN);if(newPos==null){let cursor;collapsed?cursor=direction===core.Direction.UP?0:dataStreamLength-2:cursor=direction===core.Direction.UP?startOffset:endOffset,this._textSelectionManagerService.replaceTextRanges([{startOffset:cursor,endOffset:cursor,style}],!1);return}const newActiveRange=new engineRender.NodePositionConvertToCursor(documentOffsetConfig,skeleton).getRangePointData(newPos,newPos).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...newActiveRange,style}],!1)}}_getTopOrBottomPosition(docSkeleton,glyph,nodePosition,direction){if(glyph==null||nodePosition==null)return;const offsetLeft=this._getGlyphLeftOffsetInLine(glyph),line=this._getNextOrPrevLine(glyph,direction);if(line==null)return;const position=this._matchPositionByLeftOffset(docSkeleton,line,offsetLeft,nodePosition);if(position!=null)return{...position,isBack:!0}}_getGlyphLeftOffsetInLine(glyph){const divide=glyph.parent;if(divide==null)return Number.NEGATIVE_INFINITY;const divideLeft=divide.left,{left}=glyph;return divideLeft+left}_matchPositionByLeftOffset(docSkeleton,line,offsetLeft,nodePosition){const nearestNode={distance:Number.POSITIVE_INFINITY};for(const divide of line.divides){const divideLeft=divide.left;for(const glyph of divide.glyphGroup){const{left}=glyph,leftSide=divideLeft+left,distance=Math.abs(offsetLeft-leftSide);distance<nearestNode.distance&&(nearestNode.glyph=glyph,nearestNode.distance=distance)}}if(nearestNode.glyph==null)return;const{segmentPage}=nodePosition;return docSkeleton.findPositionByGlyph(nearestNode.glyph,segmentPage)}_getNextOrPrevLine(glyph,direction){var _a10,_b,_c,_d,_e,_f,_g,_h,_i,_j,_k,_l;const divide=glyph.parent;if(divide==null)return;const line=divide.parent;if(line==null)return;const column=line.parent;if(column==null)return;const currentLineIndex=column.lines.indexOf(line);if(currentLineIndex===-1)return;let newLine;if(direction===!0?newLine=column.lines[currentLineIndex+1]:newLine=column.lines[currentLineIndex-1],newLine!=null)return newLine;const section=column.parent;if(section==null)return;const currentColumnIndex=section.columns.indexOf(column);if(currentColumnIndex===-1)return;if(direction===!0)newLine=(_a10=section.columns[currentColumnIndex+1])==null?void 0:_a10.lines[0];else{const prevColumnLines=(_c=(_b=section.columns)==null?void 0:_b[currentColumnIndex-1])==null?void 0:_c.lines;newLine=prevColumnLines==null?void 0:prevColumnLines[prevColumnLines.length-1]}if(newLine!=null)return newLine;const page=section.parent;if(page==null)return;const currentSectionIndex=page.sections.indexOf(section);if(currentSectionIndex===-1)return;if(direction===!0)newLine=(_e=(_d=page.sections[currentSectionIndex-1])==null?void 0:_d.columns[0])==null?void 0:_e.lines[0];else{const prevColumns=(_g=(_f=page.sections)==null?void 0:_f[currentSectionIndex-1])==null?void 0:_g.columns,column2=prevColumns==null?void 0:prevColumns[prevColumns.length-1],prevColumnLines=column2==null?void 0:column2.lines;newLine=prevColumnLines==null?void 0:prevColumnLines[prevColumnLines.length-1]}if(newLine!=null)return newLine;const skeleton=page.parent;if(skeleton==null)return;const currentPageIndex=skeleton.pages.indexOf(page);if(currentPageIndex!==-1){if(direction===!0)newLine=(_j=(_i=(_h=skeleton.pages[currentPageIndex+1])==null?void 0:_h.sections[0])==null?void 0:_i.columns[0])==null?void 0:_j.lines[0];else{const prevSections=(_k=skeleton.pages[currentPageIndex-1])==null?void 0:_k.sections;if(prevSections==null)return;const prevColumns=(_l=prevSections[prevSections.length-1])==null?void 0:_l.columns,column2=prevColumns[prevColumns.length-1],prevColumnLines=column2==null?void 0:column2.lines;newLine=prevColumnLines[prevColumnLines.length-1]}if(newLine!=null)return newLine}}_getDocObject(){return getDocObject(this._univerInstanceService,this._renderManagerService)}},__name(_a5,"MoveCursorController"),_a5);MoveCursorController=__decorateClass$4([core.OnLifecycle(core.LifecycleStages.Rendered,MoveCursorController),__decorateParam$4(0,core.IUniverInstanceService),__decorateParam$4(1,engineRender.IRenderManagerService),__decorateParam$4(2,core.Inject(exports.TextSelectionManagerService)),__decorateParam$4(3,core.ICommandService)],MoveCursorController);var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3"),_a6;let NormalInputController=(_a6=class extends core.Disposable{constructor(_univerInstanceService,_renderManagerService,_textSelectionRenderManager,_commandService){super();__publicField(this,"_onInputSubscription");this._univerInstanceService=_univerInstanceService,this._renderManagerService=_renderManagerService,this._textSelectionRenderManager=_textSelectionRenderManager,this._commandService=_commandService,this._init()}dispose(){var _a10;super.dispose(),(_a10=this._onInputSubscription)==null||_a10.unsubscribe()}_init(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async config=>{var _a10;if(config==null)return;const documentModel=this._univerInstanceService.getCurrentUniverDocInstance();if(!documentModel)return;const unitId=documentModel.getUnitId(),{event,content="",activeRange}=config,e=event,skeleton=(_a10=this._renderManagerService.getRenderById(documentModel.getUnitId()))==null?void 0:_a10.with(exports.DocSkeletonManagerService).getSkeleton();if(e.data==null||skeleton==null||!skeleton||!activeRange)return;const{startOffset,segmentId,style,segmentPage}=activeRange,len=content.length,textRanges=[{startOffset:startOffset+len,endOffset:startOffset+len,segmentId,segmentPage,style}];await this._commandService.executeCommand(InsertCommand.id,{unitId,body:{dataStream:content},textRanges,range:activeRange,segmentId})})}},__name(_a6,"NormalInputController"),_a6);NormalInputController=__decorateClass$3([core.OnLifecycle(core.LifecycleStages.Rendered,NormalInputController),__decorateParam$3(0,core.IUniverInstanceService),__decorateParam$3(1,engineRender.IRenderManagerService),__decorateParam$3(2,engineRender.ITextSelectionRenderManager),__decorateParam$3(3,core.ICommandService)],NormalInputController);const AlignOperationCommand={id:"doc.command.align-operation",type:core.CommandType.COMMAND,handler:__name((accessor,params)=>{var _a10,_b;const textSelectionManagerService=accessor.get(exports.TextSelectionManagerService),univerInstanceService=accessor.get(core.IUniverInstanceService),commandService=accessor.get(core.ICommandService),{alignType}=params,docDataModel=univerInstanceService.getCurrentUniverDocInstance(),activeRange=textSelectionManagerService.getActiveRange();if(docDataModel==null||activeRange==null)return!1;const{segmentId}=activeRange,selections=(_a10=textSelectionManagerService.getCurrentSelections())!=null?_a10:[],paragraphs=(_b=docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody())==null?void 0:_b.paragraphs,serializedSelections=selections.map(serializeTextRange);if(paragraphs==null)return!1;const currentParagraphs=getParagraphsInRange(activeRange,paragraphs),unitId=docDataModel.getUnitId(),isAlreadyAligned=currentParagraphs.every(paragraph=>{var _a11;return((_a11=paragraph.paragraphStyle)==null?void 0:_a11.horizontalAlign)===alignType}),doMutation={id:RichTextEditingMutation.id,params:{unitId,actions:[],textRanges:serializedSelections}},memoryCursor=new core.MemoryCursor;memoryCursor.reset();const textX=new core.TextX,jsonX=core.JSONX.getInstance();for(const paragraph of currentParagraphs){const{startIndex}=paragraph;textX.push({t:core.TextXActionType.RETAIN,len:startIndex-memoryCursor.cursor,segmentId});const paragraphStyle={...paragraph.paragraphStyle,horizontalAlign:isAlreadyAligned?core.HorizontalAlign.UNSPECIFIED:alignType};textX.push({t:core.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...paragraph,paragraphStyle,startIndex:0}]},segmentId,coverType:core.UpdateDocsAttributeType.REPLACE}),memoryCursor.moveCursorTo(startIndex+1)}const path=getRichTextEditPath(docDataModel,segmentId);return doMutation.params.actions=jsonX.editOp(textX.serialize(),path),!!commandService.syncExecuteCommand(doMutation.id,doMutation.params)},"handler")},AlignLeftCommand={id:"doc.command.align-left",type:core.CommandType.COMMAND,handler:__name(accessor=>accessor.get(core.ICommandService).syncExecuteCommand(AlignOperationCommand.id,{alignType:core.HorizontalAlign.LEFT}),"handler")},AlignCenterCommand={id:"doc.command.align-center",type:core.CommandType.COMMAND,handler:__name(accessor=>accessor.get(core.ICommandService).syncExecuteCommand(AlignOperationCommand.id,{alignType:core.HorizontalAlign.CENTER}),"handler")},AlignRightCommand={id:"doc.command.align-right",type:core.CommandType.COMMAND,handler:__name(accessor=>accessor.get(core.ICommandService).syncExecuteCommand(AlignOperationCommand.id,{alignType:core.HorizontalAlign.RIGHT}),"handler")},AlignJustifyCommand={id:"doc.command.align-justify",type:core.CommandType.COMMAND,handler:__name(accessor=>accessor.get(core.ICommandService).syncExecuteCommand(AlignOperationCommand.id,{alignType:core.HorizontalAlign.JUSTIFIED}),"handler")};var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2"),_a7;let DocCustomRangeController=(_a7=class extends core.Disposable{constructor(_commandService,_textSelectionManagerService,_univerInstanceService){super(),this._commandService=_commandService,this._textSelectionManagerService=_textSelectionManagerService,this._univerInstanceService=_univerInstanceService,this._initSelectionChange()}_transformCustomRange(doc,selection){var _a10;const{startOffset,endOffset,collapsed}=selection,customRanges=(_a10=doc.getCustomRanges())==null?void 0:_a10.filter(range=>!range.wholeEntity||startOffset<=range.startIndex&&endOffset>range.endIndex?!1:collapsed?range.startIndex<startOffset&&range.endIndex>=endOffset:isSegmentIntersects(startOffset,endOffset-1,range.startIndex,range.endIndex));if(customRanges!=null&&customRanges.length){let start=startOffset,end=endOffset;return customRanges.forEach(range=>{start=Math.min(range.startIndex,start),end=Math.max(range.endIndex+1,end)}),{...selection,startOffset:start,endOffset:end,collapsed:start===end}}return selection}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{if(commandInfo.id===SetTextSelectionsOperation.id){const params=commandInfo.params,{unitId,ranges,isEditing}=params,doc=this._univerInstanceService.getUnit(unitId);if(!doc)return;const transformedRanges=ranges.map(range=>this._transformCustomRange(doc,range));transformedRanges.some((range,i)=>ranges[i]!==range)&&this._textSelectionManagerService.replaceTextRanges(transformedRanges,isEditing)}}))}},__name(_a7,"DocCustomRangeController"),_a7);DocCustomRangeController=__decorateClass$2([core.OnLifecycle(core.LifecycleStages.Ready,DocCustomRangeController),__decorateParam$2(0,core.ICommandService),__decorateParam$2(1,core.Inject(exports.TextSelectionManagerService)),__decorateParam$2(2,core.IUniverInstanceService)],DocCustomRangeController);const DocsRenameMutation={id:"doc.mutation.rename-doc",type:core.CommandType.MUTATION,handler:__name((accessor,params)=>{const doc=accessor.get(core.IUniverInstanceService).getUnit(params.unitId,core.UniverInstanceType.UNIVER_DOC);return doc?(doc.setName(params.name),!0):!1},"handler")};var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");const PLUGIN_NAME="DOCS_PLUGIN";var _a8;exports.UniverDocsPlugin=(_a8=class extends core.Plugin{constructor(_config={},_injector){super(),this._injector=_injector,this._initializeDependencies(_injector),this._initializeCommands()}_initializeCommands(){[MoveCursorOperation,MoveSelectionOperation,DeleteLeftCommand,DeleteRightCommand,SetInlineFormatBoldCommand,SetInlineFormatItalicCommand,SetInlineFormatUnderlineCommand,SetInlineFormatStrikethroughCommand,SetInlineFormatSubscriptCommand,SetInlineFormatSuperscriptCommand,SetInlineFormatFontSizeCommand,SetInlineFormatFontFamilyCommand,SetInlineFormatTextColorCommand,ResetInlineFormatTextBackgroundColorCommand,SetInlineFormatTextBackgroundColorCommand,SetInlineFormatCommand,BreakLineCommand,InsertCommand,DeleteCommand,DeleteCustomBlockCommand,UpdateCommand,IMEInputCommand,MergeTwoParagraphCommand,RichTextEditingMutation,ReplaceContentCommand,CoverContentCommand,SetDocZoomRatioCommand,SetDocZoomRatioOperation,SetTextSelectionsOperation,SelectAllOperation,OrderListCommand,BulletListCommand,ListOperationCommand,AlignLeftCommand,AlignCenterCommand,AlignRightCommand,AlignOperationCommand,AlignJustifyCommand,DocsRenameMutation].forEach(command=>{this._injector.get(core.ICommandService).registerCommand(command)})}_initializeDependencies(docInjector){[[exports.DocStateChangeManagerService],[IMEInputManagerService],[engineRender.ITextSelectionRenderManager,{useClass:engineRender.TextSelectionRenderManager}],[exports.TextSelectionManagerService],[DocCustomRangeService],[NormalInputController],[IMEInputController],[MoveCursorController],[DocCustomRangeController]].forEach(d=>docInjector.add(d))}},__name(_a8,"UniverDocsPlugin"),__publicField(_a8,"pluginName",PLUGIN_NAME),__publicField(_a8,"type",core.UniverInstanceType.UNIVER_DOC),_a8);exports.UniverDocsPlugin=__decorateClass$1([__decorateParam$1(1,core.Inject(core.Injector))],exports.UniverDocsPlugin);function addCustomRangeTextX(param,body){const{range,rangeId,rangeType,segmentId}=param,actualRange=getSelectionForAddCustomRange(range,body);if(!actualRange)return null;const{startOffset:start,endOffset:end}=actualRange,textX=new core.TextX;return start>0&&textX.push({t:core.TextXActionType.RETAIN,len:start,segmentId}),textX.push({t:core.TextXActionType.INSERT,body:{dataStream:core.DataStreamTreeTokenType.CUSTOM_RANGE_START},len:1,line:0}),textX.push({t:core.TextXActionType.RETAIN,body:{dataStream:""},len:end-start,segmentId}),textX.push({t:core.TextXActionType.INSERT,body:{dataStream:core.DataStreamTreeTokenType.CUSTOM_RANGE_END,customRanges:[{rangeId,rangeType,startIndex:-(end-start)-1,endIndex:0}]},len:1,line:0}),textX}__name(addCustomRangeTextX,"addCustomRangeTextX");function addCustomRangeFactory(param,body){const doMutation={id:RichTextEditingMutation.id,params:{unitId:param.unitId,actions:[],textRanges:void 0}},jsonX=core.JSONX.getInstance(),textX=addCustomRangeTextX(param,body);return textX?(doMutation.params.actions=jsonX.editOp(textX.serialize()),doMutation):!1}__name(addCustomRangeFactory,"addCustomRangeFactory");function addCustomRangeBySelectionFactory(accessor,param){var _a10;const{segmentId,rangeId,rangeType,wholeEntity}=param,textSelectionManagerService=accessor.get(exports.TextSelectionManagerService),univerInstanceService=accessor.get(core.IUniverInstanceService),selection=textSelectionManagerService.getActiveRange();if(!selection)return!1;const documentDataModel=univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_DOC);if(!documentDataModel)return!1;const body=documentDataModel.getBody(),unitId=documentDataModel.getUnitId();if(!body)return!1;const{startOffset,endOffset}=normalizeSelection(selection),customRanges=(_a10=body.customRanges)!=null?_a10:[],relativeCustomRanges=[];for(let i=0,len=customRanges.length;i<len;i++){const customRange=customRanges[i];if(customRange.rangeType===rangeType&&Math.max(customRange.startIndex,startOffset)<=Math.min(customRange.endIndex,endOffset-1)&&relativeCustomRanges.push({...customRange}),customRange.startIndex>=endOffset)break}const deletes=relativeCustomRanges.map(i=>[i.startIndex,i.endIndex]).flat().sort((pre,aft)=>pre-aft);let cursor=0;const textX=new core.TextX,range=deletes.length?{startOffset:Math.min(deletes[0],startOffset),endOffset:Math.max(deletes[deletes.length-1]+1,endOffset)}:selection;range.startOffset!==cursor&&(textX.push({t:core.TextXActionType.RETAIN,len:range.startOffset-cursor,segmentId}),cursor=range.startOffset),textX.push({t:core.TextXActionType.INSERT,body:{dataStream:core.DataStreamTreeTokenType.CUSTOM_RANGE_START},len:1,line:0,segmentId}),deletes.forEach((index,i)=>{index!==cursor&&(textX.push({t:core.TextXActionType.RETAIN,len:index-cursor,segmentId}),cursor=index),textX.push({t:core.TextXActionType.DELETE,len:1,line:0,segmentId}),cursor++}),cursor!==range.endOffset&&(textX.push({t:core.TextXActionType.RETAIN,len:range.endOffset-cursor,segmentId}),cursor=range.endOffset),textX.push({t:core.TextXActionType.INSERT,body:{dataStream:core.DataStreamTreeTokenType.CUSTOM_RANGE_END,customRanges:[{rangeId,rangeType,startIndex:-(range.endOffset-range.startOffset-deletes.length+1),endIndex:0,wholeEntity}]},len:1,line:0,segmentId});const jsonX=core.JSONX.getInstance(),doMutation={id:RichTextEditingMutation.id,params:{unitId,actions:[],textRanges:void 0}};return doMutation.params.actions=jsonX.editOp(textX.serialize()),doMutation}__name(addCustomRangeBySelectionFactory,"addCustomRangeBySelectionFactory");function deleteCustomRangeTextX(accessor,params){var _a10,_b;const{unitId,rangeId,segmentId}=params,documentDataModel=accessor.get(core.IUniverInstanceService).getUnit(unitId);if(!documentDataModel)return!1;const range=(_b=(_a10=documentDataModel.getBody())==null?void 0:_a10.customRanges)==null?void 0:_b.find(r=>r.rangeId===rangeId);if(!range)return!1;const{startIndex,endIndex}=range,textX=new core.TextX,len=endIndex-startIndex+1;return startIndex>0&&textX.push({t:core.TextXActionType.RETAIN,len:startIndex,segmentId}),textX.push({t:core.TextXActionType.DELETE,len:1,segmentId,line:0}),len-2>0&&textX.push({t:core.TextXActionType.RETAIN,len:len-2,segmentId}),textX.push({t:core.TextXActionType.DELETE,len:1,segmentId,line:0}),textX}__name(deleteCustomRangeTextX,"deleteCustomRangeTextX");function deleteCustomRangeFactory(accessor,params){const doMutation={id:RichTextEditingMutation.id,params:{unitId:params.unitId,actions:[],textRanges:void 0}},jsonX=core.JSONX.getInstance(),textX=deleteCustomRangeTextX(accessor,params);return textX?(doMutation.params.actions=jsonX.editOp(textX.serialize()),doMutation):!1}__name(deleteCustomRangeFactory,"deleteCustomRangeFactory");function addCustomDecorationFactory(param){const{unitId,range,id,type,segmentId}=param,{startOffset:start,endOffset:end}=range,doMutation={id:RichTextEditingMutation.id,params:{unitId,actions:[],textRanges:void 0}},textX=new core.TextX,jsonX=core.JSONX.getInstance();return start>0&&textX.push({t:core.TextXActionType.RETAIN,len:start,segmentId}),textX.push({t:core.TextXActionType.RETAIN,body:{dataStream:"",customDecorations:[{id,type,startIndex:0,endIndex:end-start-1}]},len:end-start,segmentId}),doMutation.params.actions=jsonX.editOp(textX.serialize()),doMutation}__name(addCustomDecorationFactory,"addCustomDecorationFactory");function addCustomDecorationBySelectionFactory(accessor,param){const{segmentId,id,type}=param,textSelectionManagerService=accessor.get(exports.TextSelectionManagerService),univerInstanceService=accessor.get(core.IUniverInstanceService),selection=textSelectionManagerService.getActiveRange();if(!selection)return!1;const documentDataModel=univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_DOC);if(!documentDataModel)return!1;const body=documentDataModel.getBody(),unitId=documentDataModel.getUnitId();return body?addCustomDecorationFactory({unitId,range:{startOffset:selection.startOffset,endOffset:selection.endOffset,collapsed:!0},id,type,segmentId}):!1}__name(addCustomDecorationBySelectionFactory,"addCustomDecorationBySelectionFactory");function deleteCustomDecorationFactory(accessor,params){var _a10,_b;const{unitId,id,segmentId}=params,documentDataModel=accessor.get(core.IUniverInstanceService).getUnit(unitId),body=documentDataModel==null?void 0:documentDataModel.getBody();if(!documentDataModel||!body)return!1;const decorations=(_b=(_a10=documentDataModel.getBody())==null?void 0:_a10.customDecorations)==null?void 0:_b.filter(d=>d.id===id);if(!(decorations!=null&&decorations.length))return!1;const oldBodySlices=decorations.map(i=>core.getBodySlice(body,i.startIndex,i.endIndex+1)),bodySlices=oldBodySlices.map(bodySlice=>{var _a11;const copy=core.Tools.deepClone(bodySlice);return copy.customDecorations=(_a11=copy.customDecorations)==null?void 0:_a11.filter(decoration=>decoration.id!==id),copy}),doMutation={id:RichTextEditingMutation.id,params:{unitId,actions:[],textRanges:void 0}},textX=new core.TextX,jsonX=core.JSONX.getInstance();let cursor=0;return decorations.forEach((decoration,i)=>{const bodySlice=bodySlices[i],oldBody=oldBodySlices[i];decoration.startIndex!==cursor&&textX.push({t:core.TextXActionType.RETAIN,len:decoration.startIndex-cursor,segmentId}),cursor=decoration.startIndex,textX.push({t:core.TextXActionType.RETAIN,len:decoration.endIndex-decoration.startIndex+1,segmentId,body:bodySlice,oldBody,coverType:core.UpdateDocsAttributeType.REPLACE}),cursor=cursor+(decoration.endIndex-decoration.startIndex+1)}),doMutation.params.actions=jsonX.editOp(textX.serialize()),doMutation}__name(deleteCustomDecorationFactory,"deleteCustomDecorationFactory");const CUSTOM_RANGE=core.createInterceptorKey("CUSTOM_RANGE"),CUSTOM_DECORATION=core.createInterceptorKey("CUSTOM_DECORATION"),DOC_INTERCEPTOR_POINT={CUSTOM_RANGE,CUSTOM_DECORATION};var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),_a9;exports.DocInterceptorService=(_a9=class extends core.Disposable{constructor(_context,_docSkeletonManagerService){super();__publicField(this,"_interceptorsByName",new Map);this._context=_context,this._docSkeletonManagerService=_docSkeletonManagerService,this.disposeWithMe(this._docSkeletonManagerService.currentViewModel$.subscribe(viewModel=>{if(viewModel){const unitId=viewModel.getDataModel().getUnitId();if(unitId===core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||unitId===core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;this.interceptDocumentViewModel(viewModel)}})),this.disposeWithMe(this.intercept(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE,{priority:-1,handler:__name((data,pos,next)=>next(data),"handler")}))}intercept(name,interceptor){const key=name;this._interceptorsByName.has(key)||this._interceptorsByName.set(key,[]);const interceptors=this._interceptorsByName.get(key);return interceptors.push(interceptor),this._interceptorsByName.set(key,interceptors.sort((a,b)=>{var _a10,_b;return((_a10=b.priority)!=null?_a10:0)-((_b=a.priority)!=null?_b:0)})),this.disposeWithMe(core.toDisposable(()=>core.remove(this._interceptorsByName.get(key),interceptor)))}fetchThroughInterceptors(name){const key=name,interceptors=this._interceptorsByName.get(key);return core.composeInterceptors(interceptors||[])}interceptDocumentViewModel(viewModel){const disposableCollection=new core.DisposableCollection;return disposableCollection.add(viewModel.registerCustomRangeInterceptor({getCustomRange:__name(index=>{var _a10;return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE)(viewModel.getCustomRangeRaw(index),{index,unitId:viewModel.getDataModel().getUnitId(),customRanges:(_a10=viewModel.getDataModel().getCustomRanges())!=null?_a10:[]})},"getCustomRange"),getCustomDecoration:__name(index=>{var _a10;return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION)(viewModel.getCustomDecorationRaw(index),{index,unitId:viewModel.getDataModel().getUnitId(),customDecorations:(_a10=viewModel.getDataModel().getCustomDecorations())!=null?_a10:[]})},"getCustomDecoration")})),disposableCollection}},__name(_a9,"DocInterceptorService"),_a9);exports.DocInterceptorService=__decorateClass([core.OnLifecycle(core.LifecycleStages.Starting,exports.DocInterceptorService),__decorateParam(1,core.Inject(exports.DocSkeletonManagerService))],exports.DocInterceptorService);const getPlainTextFormDocument=__name(data=>data.body?data.body.dataStream.slice(0,-2).replaceAll(core.DataStreamTreeTokenType.CUSTOM_RANGE_START,"").replaceAll(core.DataStreamTreeTokenType.CUSTOM_RANGE_END,""):"","getPlainTextFormDocument");exports.AlignCenterCommand=AlignCenterCommand;exports.AlignJustifyCommand=AlignJustifyCommand;exports.AlignLeftCommand=AlignLeftCommand;exports.AlignOperationCommand=AlignOperationCommand;exports.AlignRightCommand=AlignRightCommand;exports.BreakLineCommand=BreakLineCommand;exports.BulletListCommand=BulletListCommand;exports.CoverContentCommand=CoverContentCommand;exports.CutContentCommand=CutContentCommand;exports.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX=DOCS_COMPONENT_BACKGROUND_LAYER_INDEX;exports.DOCS_COMPONENT_DEFAULT_Z_INDEX=DOCS_COMPONENT_DEFAULT_Z_INDEX;exports.DOCS_COMPONENT_HEADER_LAYER_INDEX=DOCS_COMPONENT_HEADER_LAYER_INDEX;exports.DOCS_COMPONENT_MAIN_LAYER_INDEX=DOCS_COMPONENT_MAIN_LAYER_INDEX;exports.DOCS_VIEW_KEY=DOCS_VIEW_KEY;exports.DOC_INTERCEPTOR_POINT=DOC_INTERCEPTOR_POINT;exports.DeleteCommand=DeleteCommand;exports.DeleteCustomBlockCommand=DeleteCustomBlockCommand;exports.DeleteLeftCommand=DeleteLeftCommand;exports.DeleteRightCommand=DeleteRightCommand;exports.DocCustomRangeService=DocCustomRangeService;exports.EditorInsertTextCommandId=EditorInsertTextCommandId;exports.IMEInputCommand=IMEInputCommand;exports.IMEInputManagerService=IMEInputManagerService;exports.InnerPasteCommand=InnerPasteCommand;exports.InsertCommand=InsertCommand;exports.ListOperationCommand=ListOperationCommand;exports.MergeTwoParagraphCommand=MergeTwoParagraphCommand;exports.MoveCursorOperation=MoveCursorOperation;exports.MoveSelectionOperation=MoveSelectionOperation;exports.NORMAL_TEXT_SELECTION_PLUGIN_NAME=NORMAL_TEXT_SELECTION_PLUGIN_NAME;exports.OrderListCommand=OrderListCommand;exports.ReplaceContentCommand=ReplaceContentCommand;exports.ResetInlineFormatTextBackgroundColorCommand=ResetInlineFormatTextBackgroundColorCommand;exports.RichTextEditingMutation=RichTextEditingMutation;exports.SelectAllOperation=SelectAllOperation;exports.SetDocZoomRatioCommand=SetDocZoomRatioCommand;exports.SetDocZoomRatioOperation=SetDocZoomRatioOperation;exports.SetInlineFormatBoldCommand=SetInlineFormatBoldCommand;exports.SetInlineFormatCommand=SetInlineFormatCommand;exports.SetInlineFormatFontFamilyCommand=SetInlineFormatFontFamilyCommand;exports.SetInlineFormatFontSizeCommand=SetInlineFormatFontSizeCommand;exports.SetInlineFormatItalicCommand=SetInlineFormatItalicCommand;exports.SetInlineFormatStrikethroughCommand=SetInlineFormatStrikethroughCommand;exports.SetInlineFormatSubscriptCommand=SetInlineFormatSubscriptCommand;exports.SetInlineFormatSuperscriptCommand=SetInlineFormatSuperscriptCommand;exports.SetInlineFormatTextBackgroundColorCommand=SetInlineFormatTextBackgroundColorCommand;exports.SetInlineFormatTextColorCommand=SetInlineFormatTextColorCommand;exports.SetInlineFormatUnderlineCommand=SetInlineFormatUnderlineCommand;exports.SetTextSelectionsOperation=SetTextSelectionsOperation;exports.UpdateCommand=UpdateCommand;exports.VIEWPORT_KEY=VIEWPORT_KEY;exports.addCustomDecorationBySelectionFactory=addCustomDecorationBySelectionFactory;exports.addCustomDecorationFactory=addCustomDecorationFactory;exports.addCustomRangeBySelectionFactory=addCustomRangeBySelectionFactory;exports.addCustomRangeFactory=addCustomRangeFactory;exports.deleteCustomDecorationFactory=deleteCustomDecorationFactory;exports.deleteCustomRangeFactory=deleteCustomRangeFactory;exports.getDeleteSelection=getDeleteSelection;exports.getDocObject=getDocObject;exports.getDocObjectById=getDocObjectById;exports.getInsertSelection=getInsertSelection;exports.getPlainTextFormDocument=getPlainTextFormDocument;exports.getRetainAndDeleteFromReplace=getRetainAndDeleteFromReplace;exports.getRichTextEditPath=getRichTextEditPath;exports.getSelectionText=getSelectionText;exports.isSegmentIntersects=isSegmentIntersects;exports.neoGetDocObject=neoGetDocObject;exports.replaceSelectionFactory=replaceSelectionFactory;exports.serializeTextRange=serializeTextRange;
|