@univerjs/docs 0.1.0-beta.1 → 0.1.0-beta.2
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.
|
@@ -14,9 +14,8 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import type { Nullable } from '@univerjs/core';
|
|
17
|
-
import { LocaleService } from '@univerjs/core';
|
|
17
|
+
import { LocaleService, RxDisposable } from '@univerjs/core';
|
|
18
18
|
import { DocumentSkeleton } from '@univerjs/engine-render';
|
|
19
|
-
import type { IDisposable } from '@wendellhu/redi';
|
|
20
19
|
import { DocViewModelManagerService } from './doc-view-model-manager.service';
|
|
21
20
|
export interface IDocSkeletonManagerParam {
|
|
22
21
|
unitId: string;
|
|
@@ -26,25 +25,22 @@ export interface IDocSkeletonManagerParam {
|
|
|
26
25
|
/**
|
|
27
26
|
* This service is for worksheet build sheet skeleton.
|
|
28
27
|
*/
|
|
29
|
-
export declare class DocSkeletonManagerService
|
|
28
|
+
export declare class DocSkeletonManagerService extends RxDisposable {
|
|
30
29
|
private readonly _localeService;
|
|
31
30
|
private readonly _docViewModelManagerService;
|
|
32
31
|
private _currentSkeletonUnitId;
|
|
33
32
|
private _docSkeletonMap;
|
|
34
33
|
private readonly _currentSkeleton$;
|
|
35
34
|
readonly currentSkeleton$: import("rxjs").Observable<Nullable<IDocSkeletonManagerParam>>;
|
|
36
|
-
/**
|
|
37
|
-
* CurrentSkeletonBefore for pre-triggered logic during registration
|
|
38
|
-
*/
|
|
39
35
|
private readonly _currentSkeletonBefore$;
|
|
40
36
|
readonly currentSkeletonBefore$: import("rxjs").Observable<Nullable<IDocSkeletonManagerParam>>;
|
|
41
37
|
constructor(_localeService: LocaleService, _docViewModelManagerService: DocViewModelManagerService);
|
|
42
|
-
|
|
38
|
+
private _initialize;
|
|
43
39
|
dispose(): void;
|
|
44
40
|
getCurrent(): Nullable<IDocSkeletonManagerParam>;
|
|
45
41
|
makeDirtyCurrent(state?: boolean): void;
|
|
46
42
|
makeDirty(unitId: string, state?: boolean): void;
|
|
47
|
-
private _setCurrent;
|
|
48
43
|
getSkeletonByUnitId(unitId: string): Nullable<IDocSkeletonManagerParam>;
|
|
44
|
+
private _setCurrent;
|
|
49
45
|
private _buildSkeleton;
|
|
50
46
|
}
|
|
@@ -14,9 +14,8 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import type { Nullable } from '@univerjs/core';
|
|
17
|
-
import { IUniverInstanceService } from '@univerjs/core';
|
|
17
|
+
import { IUniverInstanceService, RxDisposable } from '@univerjs/core';
|
|
18
18
|
import { DocumentViewModel } from '@univerjs/engine-render';
|
|
19
|
-
import type { IDisposable } from '@wendellhu/redi';
|
|
20
19
|
export interface IDocumentViewModelManagerParam {
|
|
21
20
|
unitId: string;
|
|
22
21
|
docViewModel: DocumentViewModel;
|
|
@@ -24,16 +23,17 @@ export interface IDocumentViewModelManagerParam {
|
|
|
24
23
|
/**
|
|
25
24
|
* The view model manager is used to manage Doc view model. has a one-to-one correspondence with the doc skeleton.
|
|
26
25
|
*/
|
|
27
|
-
export declare class DocViewModelManagerService
|
|
26
|
+
export declare class DocViewModelManagerService extends RxDisposable {
|
|
28
27
|
private readonly _currentUniverService;
|
|
29
28
|
private _currentViewModelUnitId;
|
|
30
29
|
private _docViewModelMap;
|
|
31
30
|
private readonly _currentDocViewModel$;
|
|
32
31
|
readonly currentDocViewModel$: import("rxjs").Observable<Nullable<IDocumentViewModelManagerParam>>;
|
|
33
32
|
constructor(_currentUniverService: IUniverInstanceService);
|
|
33
|
+
private _initialize;
|
|
34
34
|
dispose(): void;
|
|
35
35
|
getCurrent(): IDocumentViewModelManagerParam | undefined;
|
|
36
36
|
getViewModel(unitId: string): DocumentViewModel | undefined;
|
|
37
|
-
|
|
37
|
+
private _setCurrent;
|
|
38
38
|
private _buildDocViewModel;
|
|
39
39
|
}
|
package/lib/umd/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(h,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("rxjs"),require("@univerjs/ui"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","rxjs","@univerjs/ui","@wendellhu/redi"],a):(h=typeof globalThis<"u"?globalThis:h||self,a(h.UniverDocs={},h.UniverCore,h.UniverEngineRender,h.rxjs,h.UniverUi,h["@wendellhu/redi"]))})(this,function(h,a,M,j,T,b){"use strict";var Wn=Object.defineProperty;var Hn=(h,a,M)=>a in h?Wn(h,a,{enumerable:!0,configurable:!0,writable:!0,value:M}):h[a]=M;var C=(h,a,M)=>(Hn(h,typeof a!="symbol"?a+"":a,M),M);var ke;function X(r,e){const n=r.getCurrentUniverDocInstance().getUnitId(),i=e.getRenderById(n);if(i==null)return;const{mainComponent:s,scene:o,engine:c}=i;return{document:s,scene:o,engine:c}}function mt(r,e){const t=e.getRenderById(r);if(t==null)return;const{mainComponent:n,scene:i,engine:s}=t;return{document:n,scene:i,engine:s}}var se=(r=>(r.MAIN="__Document_Render_Main__",r))(se||{}),ae=(r=>(r.VIEW_MAIN="viewMain",r.VIEW_TOP="viewTop",r.VIEW_LEFT="viewLeft",r.VIEW_LEFT_TOP="viewLeftTop",r))(ae||{});const Te=0,ze=2,Ge=10,gt="normalTextSelectionPluginName",be={id:"doc.operation.set-selections",type:a.CommandType.OPERATION,handler:(r,e)=>!0};var ft=Object.defineProperty,ht=Object.getOwnPropertyDescriptor,pt=(r,e,t,n)=>{for(var i=n>1?void 0:n?ht(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&ft(e,t,i),i},We=(r,e)=>(t,n)=>e(t,n,r);function He(r){const{startOffset:e,endOffset:t,collapsed:n}=r;return{startOffset:e,endOffset:t,collapsed:n}}h.TextSelectionManagerService=class extends a.RxDisposable{constructor(t,n){super();C(this,"_currentSelection",null);C(this,"_textSelectionInfo",new Map);C(this,"_textSelection$",new j.BehaviorSubject(null));C(this,"textSelection$",this._textSelection$.asObservable());this._textSelectionRenderManager=t,this._commandService=n,this._syncSelectionFromRenderService()}getCurrentSelection(){return this._currentSelection}getCurrentSelectionInfo(){return this._getTextRanges(this._currentSelection)}dispose(){this._textSelection$.complete()}refreshSelection(){this._currentSelection!=null&&this._refresh(this._currentSelection)}setCurrentSelection(t){this._currentSelection=t,this._refresh(t)}setCurrentSelectionNotRefresh(t){this._currentSelection=t}getSelections(){var t;return(t=this._getTextRanges(this._currentSelection))==null?void 0:t.textRanges}getActiveRange(){const t=this._getTextRanges(this._currentSelection);if(t==null)return;const{textRanges:n,segmentId:i,style:s}=t,o=n.find(m=>m.isActive());if(o==null)return null;const{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:g,direction:f}=o;return c==null||l==null?null:{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:g,direction:f,segmentId:i,style:s}}add(t){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:t,segmentId:"",style:M.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(t){this._currentSelection!=null&&(this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges(t))}_syncSelectionFromRenderService(){this._textSelectionRenderManager.textSelectionInner$.pipe(j.takeUntil(this.dispose$)).subscribe(t=>{t!=null&&this._replaceTextRangesWithNoRefresh(t)})}_replaceTextRangesWithNoRefresh(t){if(this._currentSelection==null)return;const n={...this._currentSelection,...t};this._replaceByParam(n),this._textSelection$.next(n);const{unitId:i,subUnitId:s,segmentId:o,style:c,textRanges:l}=n;this._commandService.executeCommand(be.id,{unitId:i,subUnitId:s,segmentId:o,style:c,ranges:l.map(He)})}_getTextRanges(t){var s;if(t==null)return;const{unitId:n,subUnitId:i=""}=t;return(s=this._textSelectionInfo.get(n))==null?void 0:s.get(i)}_refresh(t){const n=this._getTextRanges(t);this._textSelectionRenderManager.removeAllTextRanges(),n&&Array.isArray(n.textRanges)&&n.textRanges.length&&this._textSelectionRenderManager.addTextRanges(n.textRanges.map(He))}_replaceByParam(t){const{unitId:n,subUnitId:i,style:s,segmentId:o,textRanges:c}=t;this._textSelectionInfo.has(n)||this._textSelectionInfo.set(n,new Map),this._textSelectionInfo.get(n).set(i,{textRanges:c,style:s,segmentId:o})}_addByParam(t){const{unitId:n,subUnitId:i,textRanges:s,style:o,segmentId:c}=t;this._textSelectionInfo.has(n)||this._textSelectionInfo.set(n,new Map);const l=this._textSelectionInfo.get(n);l.has(i)?l.get(i).textRanges.push(...s):l.set(i,{textRanges:s,style:o,segmentId:c})}},h.TextSelectionManagerService=pt([We(0,M.ITextSelectionRenderManager),We(1,a.ICommandService)],h.TextSelectionManagerService);function oe(r,e="",t=0){const{startOffset:n,endOffset:i}=r,s=[],o=n-t,c=i-t;return o>0&&s.push({t:"r",len:o,segmentId:e}),s.push({t:"d",len:c-o,line:0,segmentId:e}),s}var St=Object.defineProperty,_t=Object.getOwnPropertyDescriptor,vt=(r,e,t,n)=>{for(var i=n>1?void 0:n?_t(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&St(e,t,i),i},Ct=(r,e)=>(t,n)=>e(t,n,r);h.DocViewModelManagerService=class{constructor(e){C(this,"_currentViewModelUnitId","");C(this,"_docViewModelMap",new Map);C(this,"_currentDocViewModel$",new j.BehaviorSubject(null));C(this,"currentDocViewModel$",this._currentDocViewModel$.asObservable());this._currentUniverService=e}dispose(){this._currentDocViewModel$.complete(),this._docViewModelMap=new Map}getCurrent(){return this._docViewModelMap.get(this._currentViewModelUnitId)}getViewModel(e){var t;return(t=this._docViewModelMap.get(e))==null?void 0:t.docViewModel}setCurrent(e){var n;const t=this._currentUniverService.getUniverDocInstance(e);if(t==null)throw new Error(`Document data model with id ${e} not found when build view model.`);if(t.getBody()!=null){if(!this._docViewModelMap.has(e)){const i=this._buildDocViewModel(t);this._docViewModelMap.set(e,{unitId:e,docViewModel:i})}if(e===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY){const i=(n=this._docViewModelMap.get(e))==null?void 0:n.docViewModel;if(i==null)return;i.reset(t)}this._currentViewModelUnitId=e,this._currentDocViewModel$.next(this.getCurrent())}}_buildDocViewModel(e){return new M.DocumentViewModel(e)}},h.DocViewModelManagerService=vt([Ct(0,a.IUniverInstanceService)],h.DocViewModelManagerService);const v={id:"doc.mutation.rich-text-editing",type:a.CommandType.MUTATION,handler:(r,e)=>{const{unitId:t,mutations:n}=e,s=r.get(a.IUniverInstanceService).getUniverDocInstance(t),c=r.get(h.DocViewModelManagerService).getViewModel(t);if(s==null||c==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${t}`);const l=s.apply(n),u=n[0].segmentId,d=s.getSelfOrHeaderFooterModel(u);return c.getSelfOrHeaderFooterViewModel(u).reset(d),{unitId:t,mutations:l}}},ce={id:"doc.command.insert-text",type:a.CommandType.COMMAND,handler:async(r,e)=>{const t=r.get(a.IUndoRedoService),n=r.get(a.ICommandService),i=r.get(h.TextSelectionManagerService),{range:s,segmentId:o,body:c,unitId:l,textRanges:u}=e,{startOffset:d,collapsed:g}=s,f={id:v.id,params:{unitId:l,mutations:[]}};g?d>0&&f.params.mutations.push({t:"r",len:d,segmentId:o}):f.params.mutations.push(...oe(s,o)),f.params.mutations.push({t:"i",body:c,len:c.dataStream.length,line:0,segmentId:o});const m=n.syncExecuteCommand(f.id,f.params);return i.replaceTextRanges(u),m?(t.pushUndoRedo({unitID:l,undoMutations:[{id:v.id,params:m}],redoMutations:[{id:v.id,params:f.params}],undo(){return n.syncExecuteCommand(v.id,m),i.replaceTextRanges([s]),!0},redo(){return n.syncExecuteCommand(v.id,f.params),i.replaceTextRanges(u),!0}}),!0):!1}};var L=(r=>(r[r.LEFT=0]="LEFT",r[r.RIGHT=1]="RIGHT",r))(L||{});const le={id:"doc.command.delete-text",type:a.CommandType.COMMAND,handler:async(r,e)=>{const t=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(h.TextSelectionManagerService),{range:s,segmentId:o,unitId:c,direction:l,textRanges:u,len:d=1}=e,{startOffset:g}=s,f={id:v.id,params:{unitId:c,mutations:[]}};g>0&&f.params.mutations.push({t:"r",len:l===0?g-d:g,segmentId:o}),f.params.mutations.push({t:"d",len:d,line:0,segmentId:o});const m=t.syncExecuteCommand(f.id,f.params);return i.replaceTextRanges(u),m&&n.pushUndoRedo({unitID:c,undoMutations:[{id:v.id,params:m}],redoMutations:[{id:v.id,params:f.params}],undo(){return t.syncExecuteCommand(v.id,m),i.replaceTextRanges([s]),!0},redo(){return t.syncExecuteCommand(v.id,f.params),i.replaceTextRanges(u),!0}}),!1}},xe={id:"doc.command.update-text",type:a.CommandType.COMMAND,handler:async(r,e)=>{const{range:t,segmentId:n,updateBody:i,coverType:s,unitId:o,textRanges:c}=e,l=r.get(a.ICommandService),u=r.get(a.IUndoRedoService),d=r.get(h.TextSelectionManagerService),g={id:v.id,params:{unitId:o,mutations:[]}},{startOffset:f,endOffset:m}=t;g.params.mutations.push({t:"r",len:f,segmentId:n}),g.params.mutations.push({t:"r",body:i,len:m-f,segmentId:n,coverType:s});const p=l.syncExecuteCommand(g.id,g.params);return d.replaceTextRanges(c),p?(u.pushUndoRedo({unitID:o,undoMutations:[{id:v.id,params:p}],redoMutations:[{id:v.id,params:g.params}],undo(){return l.syncExecuteCommand(v.id,p),d.replaceTextRanges(c),!0},redo(){return l.syncExecuteCommand(v.id,g.params),d.replaceTextRanges(c),!0}}),!0):!1}};function It(r,e){const t=[];for(let n=0,i=r.length;n<i;n++)r[n]===a.DataStreamTreeTokenType.PARAGRAPH&&t.push({startIndex:n});if(e)for(const n of t)e.bullet&&(n.bullet=a.Tools.deepClone(e.bullet)),e.paragraphStyle&&(n.paragraphStyle=a.Tools.deepClone(e.paragraphStyle));return t}const Ue={id:"doc.command.break-line",type:a.CommandType.COMMAND,handler:async r=>{var p;const e=r.get(h.TextSelectionManagerService),t=r.get(a.IUniverInstanceService),n=r.get(a.ICommandService),i=e.getActiveRange();if(i==null)return!1;const s=t.getCurrentUniverDocInstance(),o=s.getUnitId(),{startOffset:c,segmentId:l,style:u}=i,d=[{startOffset:c+1,endOffset:c+1,style:u}],f=(((p=s.getBody())==null?void 0:p.paragraphs)??[]).find(S=>S.startIndex>=c);return await n.executeCommand(ce.id,{unitId:o,body:{dataStream:a.DataStreamTreeTokenType.PARAGRAPH,paragraphs:It(a.DataStreamTreeTokenType.PARAGRAPH,f)},range:i,textRanges:d,segmentId:l})}},de={id:T.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:999,preconditions:r=>r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.FOCUSING_EDITOR),handler:async()=>!0},ue={id:T.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:999,preconditions:r=>r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.FOCUSING_EDITOR),handler:async()=>!0},me={id:T.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:999,preconditions:r=>r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.FOCUSING_EDITOR),handler:async()=>!0};var Mt=Object.defineProperty,Ot=Object.getOwnPropertyDescriptor,Rt=(r,e,t,n)=>{for(var i=n>1?void 0:n?Ot(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&Mt(e,t,i),i},Ke=(r,e)=>(t,n)=>e(t,n,r);h.DocSkeletonManagerService=class{constructor(e,t){C(this,"_currentSkeletonUnitId","");C(this,"_docSkeletonMap",new Map);C(this,"_currentSkeleton$",new j.BehaviorSubject(null));C(this,"currentSkeleton$",this._currentSkeleton$.asObservable());C(this,"_currentSkeletonBefore$",new j.BehaviorSubject(null));C(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._localeService=e,this._docViewModelManagerService=t,this.initialize()}initialize(){this._docViewModelManagerService.currentDocViewModel$.subscribe(e=>{e!=null&&this._setCurrent(e)})}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._docSkeletonMap=new Map}getCurrent(){return this.getSkeletonByUnitId(this._currentSkeletonUnitId)}makeDirtyCurrent(e=!0){this.makeDirty(this._currentSkeletonUnitId,e)}makeDirty(e,t=!0){const n=this.getSkeletonByUnitId(e);n!=null&&(n.dirty=t)}_setCurrent(e){const{unitId:t}=e;if(this._docSkeletonMap.has(t)){const n=this.getSkeletonByUnitId(t);n.skeleton.calculate(),n.dirty=!0}else{const n=this._buildSkeleton(e.docViewModel);n.calculate(),this._docSkeletonMap.set(t,{unitId:t,skeleton:n,dirty:!1})}return this._currentSkeletonUnitId=t,this._currentSkeletonBefore$.next(this.getCurrent()),this._currentSkeleton$.next(this.getCurrent()),this.getCurrent()}getSkeletonByUnitId(e){return this._docSkeletonMap.get(e)}_buildSkeleton(e){return M.DocumentSkeleton.create(e,this._localeService)}},h.DocSkeletonManagerService=Rt([Ke(0,b.Inject(a.LocaleService)),Ke(1,b.Inject(h.DocViewModelManagerService))],h.DocSkeletonManagerService);const Ye={id:"doc.command.inner-paste",type:a.CommandType.COMMAND,handler:async(r,e)=>{const{segmentId:t,body:n,textRanges:i}=e,s=r.get(a.IUndoRedoService),o=r.get(a.ICommandService),c=r.get(h.TextSelectionManagerService),l=r.get(a.IUniverInstanceService),u=c.getSelections();if(!Array.isArray(u)||u.length===0)return!1;const g=l.getCurrentUniverDocInstance().getUnitId(),f={id:v.id,params:{unitId:g,mutations:[]}},m=new a.MemoryCursor;m.reset();for(const S of u){const{startOffset:_,endOffset:I,collapsed:O}=S,x=_-m.cursor;O?f.params.mutations.push({t:"r",len:x,segmentId:t}):f.params.mutations.push(...oe(S,t,m.cursor)),f.params.mutations.push({t:"i",body:n,len:n.dataStream.length,line:0,segmentId:t}),m.reset(),m.moveCursor(I)}const p=o.syncExecuteCommand(f.id,f.params);return c.replaceTextRanges(i),p?(s.pushUndoRedo({unitID:g,undoMutations:[{id:v.id,params:p}],redoMutations:[{id:v.id,params:f.params}],undo(){return o.syncExecuteCommand(v.id,p),c.replaceTextRanges(u),!0},redo(){return o.syncExecuteCommand(v.id,f.params),c.replaceTextRanges(i),!0}}),!0):!1}},ge={id:"doc.command.inner-cut",type:a.CommandType.COMMAND,handler:async(r,e)=>{const{segmentId:t,textRanges:n}=e,i=r.get(a.IUndoRedoService),s=r.get(a.ICommandService),o=r.get(h.TextSelectionManagerService),c=r.get(a.IUniverInstanceService),l=o.getSelections();if(!Array.isArray(l)||l.length===0)return!1;const u=c.getCurrentUniverDocInstance().getUnitId(),d=c.getUniverDocInstance(u),g=a.getDocsUpdateBody(d.snapshot,t);if(g==null)return!1;const f={id:v.id,params:{unitId:u,mutations:[]}},m=new a.MemoryCursor;m.reset();for(const S of l){const{startOffset:_,endOffset:I,collapsed:O}=S,x=_-m.cursor;O?f.params.mutations.push({t:"r",len:x,segmentId:t}):f.params.mutations.push(...yt(S,g,t,m.cursor)),m.reset(),m.moveCursor(I)}const p=s.syncExecuteCommand(f.id,f.params);return o.replaceTextRanges(n),p?(i.pushUndoRedo({unitID:u,undoMutations:[{id:v.id,params:p}],redoMutations:[{id:v.id,params:f.params}],undo(){return s.syncExecuteCommand(v.id,p),o.replaceTextRanges(l),!0},redo(){return s.syncExecuteCommand(v.id,f.params),o.replaceTextRanges(n),!0}}),!0):!1}};function yt(r,e,t="",n=0){const{startOffset:i,endOffset:s}=r,o=[],{paragraphs:c=[]}=e,l=i-n,u=s-n,d=c==null?void 0:c.find(g=>g.startIndex-n>=l&&g.startIndex-n<=u);if(l>0&&o.push({t:"r",len:l,segmentId:t}),d&&d.startIndex-n>l){const g=d.startIndex-n;o.push({t:"d",len:g-l,line:0,segmentId:t}),o.push({t:"r",len:1,segmentId:t}),u>g+1&&o.push({t:"d",len:u-g-1,line:0,segmentId:t})}else o.push({t:"d",len:u-l,line:0,segmentId:t});return o}const Ee={id:"doc.command.delete-left",type:a.CommandType.COMMAND,handler:async r=>{var D;const e=r.get(h.TextSelectionManagerService),t=r.get(h.DocSkeletonManagerService),n=r.get(a.IUniverInstanceService),i=r.get(a.ICommandService),s=e.getActiveRange(),o=e.getSelections(),c=(D=t.getCurrent())==null?void 0:D.skeleton;let l;if(s==null||c==null||o==null)return!1;const u=n.getCurrentUniverDocInstance(),{startOffset:d,collapsed:g,segmentId:f,style:m}=s;if(d===0&&g)return!0;const p=c.findNodeByCharIndex(d),S=M.hasListSpan(p),_=M.isIndentBySpan(p,u.body);let I=d;const O=c.findNodeByCharIndex(d-1);if(M.isFirstSpan(p)&&O!==p&&(S===!0||_===!0)){const R=M.getParagraphBySpan(p,u.body);if(R==null)return!1;const U=R==null?void 0:R.startIndex,E={startIndex:0},P=R.paragraphStyle;if(S===!0){const y=R.paragraphStyle;y&&(E.paragraphStyle=y)}else if(_===!0){const y=R.bullet;y&&(E.bullet=y),P!=null&&(E.paragraphStyle={...P},delete E.paragraphStyle.hanging,delete E.paragraphStyle.indentStart)}const w=[{startOffset:I,endOffset:I,style:m}];l=await i.executeCommand(xe.id,{unitId:u.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...E}]},range:{startOffset:U,endOffset:U+1},textRanges:w,coverType:a.UpdateDocsAttributeType.REPLACE,segmentId:f})}else if(g===!0)if(O.content==="\r")l=await i.executeCommand(we.id,{direction:L.LEFT,range:s});else{I-=O.count;const R=[{startOffset:I,endOffset:I,style:m}];l=await i.executeCommand(le.id,{unitId:u.getUnitId(),range:s,segmentId:f,direction:L.LEFT,len:O.count,textRanges:R})}else{const R=Xe(s,o);l=await i.executeCommand(ge.id,{segmentId:f,textRanges:R})}return l}},Pe={id:"doc.command.delete-right",type:a.CommandType.COMMAND,handler:async r=>{var p;const e=r.get(h.TextSelectionManagerService),t=r.get(h.DocSkeletonManagerService),n=r.get(a.IUniverInstanceService),i=r.get(a.ICommandService),s=e.getActiveRange(),o=e.getSelections(),c=(p=t.getCurrent())==null?void 0:p.skeleton;let l;if(s==null||c==null||o==null)return!1;const u=n.getCurrentUniverDocInstance(),{startOffset:d,collapsed:g,segmentId:f,style:m}=s;if(d===u.getBody().dataStream.length-2&&g)return!0;if(g===!0){const S=c.findNodeByCharIndex(d);if(S.content==="\r")l=await i.executeCommand(we.id,{direction:L.RIGHT,range:s});else{const _=[{startOffset:d,endOffset:d,style:m}];l=await i.executeCommand(le.id,{unitId:u.getUnitId(),range:s,segmentId:f,direction:L.RIGHT,textRanges:_,len:S.count})}}else{const S=Xe(s,o);l=await i.executeCommand(ge.id,{segmentId:f,textRanges:S})}return l}},we={id:"doc.command.merge-two-paragraph",type:a.CommandType.COMMAND,handler:async(r,e)=>{var E,P,w;const t=r.get(h.TextSelectionManagerService),n=r.get(a.IUniverInstanceService),i=r.get(a.ICommandService),s=r.get(a.IUndoRedoService),{direction:o,range:c}=e,l=t.getActiveRange(),u=t.getSelections();if(l==null||u==null)return!1;const d=n.getCurrentUniverDocInstance(),{startOffset:g,collapsed:f,segmentId:m,style:p}=l;if(!f)return!1;const S=o===L.LEFT?g:g+1,_=(w=(P=(E=d.getBody())==null?void 0:E.paragraphs)==null?void 0:P.find(y=>y.startIndex>=S))==null?void 0:w.startIndex,I=Dt(d.getBody(),S,_),O=o===L.LEFT?g-1:g,x=d.getUnitId(),D=[{startOffset:O,endOffset:O,style:p}],R={id:v.id,params:{unitId:x,mutations:[]}};R.params.mutations.push({t:"r",len:o===L.LEFT?g-1:g,segmentId:m}),I.dataStream.length&&R.params.mutations.push({t:"i",body:I,len:I.dataStream.length,line:0,segmentId:m}),R.params.mutations.push({t:"r",len:1,segmentId:m}),R.params.mutations.push({t:"d",len:_+1-S,line:0,segmentId:m});const U=i.syncExecuteCommand(R.id,R.params);return t.replaceTextRanges(D),U?(s.pushUndoRedo({unitID:x,undoMutations:[{id:v.id,params:U}],redoMutations:[{id:v.id,params:R.params}],undo(){return i.syncExecuteCommand(v.id,U),t.replaceTextRanges([c]),!0},redo(){return i.syncExecuteCommand(v.id,R.params),t.replaceTextRanges(D),!0}}),!0):!1}};function Dt(r,e,t){const{textRuns:n}=r,i=r.dataStream.substring(e,t);if(n==null)return{dataStream:i};const s=[];for(const o of n){const{st:c,ed:l}=o;l<=e||c>=t||(c<e?s.push({...o,st:0,ed:l-e}):l>t?s.push({...o,st:c-e,ed:t-e}):s.push({...o,st:c-e,ed:l-e}))}return{dataStream:i,textRuns:s}}function Xe(r,e){let t=r.endOffset;for(const i of e){const{startOffset:s,endOffset:o}=i;s==null||o==null||o<=r.endOffset&&(t-=o-s)}return[{startOffset:t,endOffset:t,style:r.style}]}class Ne{constructor(){C(this,"_previousActiveRange",null);C(this,"_undoMutationParamsCache",[]);C(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}setActiveRange(e){this._previousActiveRange=e}pushUndoRedoMutationParams(e,t){this._undoMutationParamsCache.push(e),this._redoMutationParamsCache.push(t)}fetchComposedUndoRedoMutationParams(e){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null)return null;const{unitId:t}=this._undoMutationParamsCache[0],{segmentId:n,startOffset:i,collapsed:s}=this._previousActiveRange,o={unitId:t,mutations:[]},c={unitId:t,mutations:[]};return s?(o.mutations.push({t:"r",len:i,segmentId:n}),c.mutations.push({t:"r",len:i,segmentId:n})):(i>0&&o.mutations.push({t:"r",len:i,segmentId:n}),o.mutations.push(this._undoMutationParamsCache[0].mutations.find(l=>l.t==="i")),c.mutations.push(...oe(this._previousActiveRange,n))),e.length&&(o.mutations.push({t:"d",len:e.length,line:0,segmentId:n}),c.mutations.push({t:"i",body:{dataStream:e},len:e.length,line:0,segmentId:n})),{redoMutationParams:c,undoMutationParams:o,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Le={id:"doc.command.ime-input",type:a.CommandType.COMMAND,handler:async(r,e)=>{const{unitId:t,newText:n,oldTextLen:i,range:s,segmentId:o,textRanges:c,isCompositionEnd:l}=e,u=r.get(a.ICommandService),d=r.get(a.IUndoRedoService),g=r.get(h.TextSelectionManagerService),f=r.get(Ne),m={id:v.id,params:{unitId:t,mutations:[]}};s.collapsed?m.params.mutations.push({t:"r",len:s.startOffset,segmentId:o}):m.params.mutations.push(...oe(s,o)),i>0&&m.params.mutations.push({t:"d",len:i,line:0,segmentId:o}),m.params.mutations.push({t:"i",body:{dataStream:n},len:n.length,line:0,segmentId:o});const p=u.syncExecuteCommand(m.id,m.params);if(f.pushUndoRedoMutationParams(p,m.params),g.replaceTextRanges(c),l){if(p){const S=f.fetchComposedUndoRedoMutationParams(n);if(S==null)return!1;const{undoMutationParams:_,redoMutationParams:I,previousActiveRange:O}=S;return d.pushUndoRedo({unitID:t,undoMutations:[{id:v.id,params:_}],redoMutations:[{id:v.id,params:I}],undo(){return u.syncExecuteCommand(v.id,_),g.replaceTextRanges([O]),!0},redo(){return u.syncExecuteCommand(v.id,I),g.replaceTextRanges(c),!0}}),!0}}else return!!p;return!1}},G={id:"doc.command.set-inline-format-bold",type:a.CommandType.COMMAND,handler:async()=>!0},q={id:"doc.command.set-inline-format-italic",type:a.CommandType.COMMAND,handler:async()=>!0},Z={id:"doc.command.set-inline-format-underline",type:a.CommandType.COMMAND,handler:async()=>!0},J={id:"doc.command.set-inline-format-strikethrough",type:a.CommandType.COMMAND,handler:async()=>!0},A={id:"doc.command.set-inline-format-subscript",type:a.CommandType.COMMAND,handler:async()=>!0},V={id:"doc.command.set-inline-format-superscript",type:a.CommandType.COMMAND,handler:async()=>!0},W={id:"doc.command.set-inline-format-fontsize",type:a.CommandType.COMMAND,handler:async()=>!0},H={id:"doc.command.set-inline-format-font-family",type:a.CommandType.COMMAND,handler:async()=>!0},Q={id:"doc.command.set-inline-format-text-color",type:a.CommandType.COMMAND,handler:async()=>!0},qe={[G.id]:"bl",[q.id]:"it",[Z.id]:"ul",[J.id]:"st",[W.id]:"fs",[H.id]:"ff",[Q.id]:"cl",[A.id]:"va",[V.id]:"va"},Ae={id:"doc.command.set-inline-format",type:a.CommandType.COMMAND,handler:async(r,e)=>{const{segmentId:t,value:n,preCommandId:i}=e,s=r.get(a.IUndoRedoService),o=r.get(a.ICommandService),c=r.get(h.TextSelectionManagerService),l=r.get(a.IUniverInstanceService),u=c.getSelections();if(!Array.isArray(u)||u.length===0)return!1;let d=l.getCurrentUniverDocInstance(),g=d.getUnitId();g===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(d=l.getUniverDocInstance(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),g=d.getUnitId());let f;switch(i){case G.id:case q.id:case Z.id:case J.id:case A.id:case V.id:{f=bt(d.getBody().textRuns,i,u);break}case W.id:case H.id:{f=n;break}case Q.id:{f={rgb:n};break}default:throw new Error(`Unknown command: ${i} in handleInlineFormat`)}const m={id:v.id,params:{unitId:g,mutations:[]}},p=new a.MemoryCursor;p.reset();for(const I of u){const{startOffset:O,endOffset:x}=I,D={dataStream:"",textRuns:[{st:0,ed:x-O,ts:{[qe[i]]:f}}]},R=O-p.cursor;R!==0&&m.params.mutations.push({t:"r",len:R,segmentId:t}),m.params.mutations.push({t:"r",body:D,len:x-O,segmentId:t}),p.reset(),p.moveCursor(x)}const S=o.syncExecuteCommand(m.id,m.params),_=[G.id,W.id,H.id,A.id,V.id];return _.includes(i)&&c.refreshSelection(),S?(s.pushUndoRedo({unitID:g,undoMutations:[{id:v.id,params:S}],redoMutations:[{id:v.id,params:m.params}],undo(){return o.syncExecuteCommand(v.id,S),_.includes(i)&&c.refreshSelection(),!0},redo(){return o.syncExecuteCommand(v.id,m.params),_.includes(i)&&c.refreshSelection(),!0}}),!0):!1}};function Tt(r){return r!==null&&typeof r=="object"}function bt(r,e,t){let n=0,i=0;const s=qe[e];for(;n!==r.length&&i!==t.length;){const{startOffset:o,endOffset:c}=t[i],{st:l,ed:u,ts:d}=r[n];if(c<=l)i++;else if(u<=o)n++;else{if((d==null?void 0:d[s])==null){if(/bl|it/.test(s))return a.BooleanNumber.TRUE;if(/ul|st/.test(s))return{s:a.BooleanNumber.TRUE};if(/va/.test(s))return e===A.id?a.BaselineOffset.SUBSCRIPT:a.BaselineOffset.SUPERSCRIPT}if(Tt(d==null?void 0:d[s])&&d[s].s===a.BooleanNumber.FALSE)return{s:a.BooleanNumber.TRUE};if(e===A.id&&(d==null?void 0:d[s])!==a.BaselineOffset.SUBSCRIPT)return a.BaselineOffset.SUBSCRIPT;if(e===V.id&&(d==null?void 0:d[s])!==a.BaselineOffset.SUPERSCRIPT)return a.BaselineOffset.SUPERSCRIPT;if((d==null?void 0:d[s])===a.BooleanNumber.FALSE)return a.BooleanNumber.TRUE;n++}}return/bl|it/.test(s)?a.BooleanNumber.FALSE:/ul|st/.test(s)?{s:a.BooleanNumber.FALSE}:a.BaselineOffset.NORMAL}const Ze={id:"doc.command.bullet-list",type:a.CommandType.COMMAND,handler:r=>r.get(a.ICommandService).syncExecuteCommand(Be.id,{listType:a.PresetListType.BULLET_LIST})},Je={id:"doc.command.order-list",type:a.CommandType.COMMAND,handler:r=>r.get(a.ICommandService).syncExecuteCommand(Be.id,{listType:a.PresetListType.ORDER_LIST})},Be={id:"doc.command.list-operation",type:a.CommandType.COMMAND,handler:(r,e)=>{var x;const t=r.get(h.TextSelectionManagerService),n=r.get(a.IUniverInstanceService),i=r.get(a.ICommandService),s=r.get(a.IUndoRedoService),{listType:o}=e,c=n.getCurrentUniverDocInstance(),l=t.getActiveRange(),u=(x=c.getBody())==null?void 0:x.paragraphs;if(l==null||u==null)return!1;const d=xt(l,u),{segmentId:g}=l,f=c.getUnitId(),m=d.every(D=>{var R;return((R=D.bullet)==null?void 0:R.listType)===o}),p=6;let S=a.Tools.generateRandomId(p);if(d.length===1){const D=u.indexOf(d[0]),R=u[D-1],U=u[D+1];R&&R.bullet&&R.bullet.listType===o?S=R.bullet.listId:U&&U.bullet&&U.bullet.listType===o&&(S=U.bullet.listId)}const _={id:v.id,params:{unitId:f,mutations:[]}},I=new a.MemoryCursor;I.reset();for(const D of d){const{startIndex:R}=D;_.params.mutations.push({t:"r",len:R-I.cursor,segmentId:g});const U={...D.paragraphStyle,hanging:void 0,indentStart:void 0};_.params.mutations.push({t:"r",len:1,body:{dataStream:"",paragraphs:[m?{paragraphStyle:U,startIndex:0}:{...D,startIndex:0,bullet:{...D.bullet??{nestingLevel:0,textStyle:{fs:20}},listType:o,listId:S}}]},segmentId:g,coverType:a.UpdateDocsAttributeType.REPLACE}),I.moveCursorTo(R+1)}const O=i.syncExecuteCommand(_.id,_.params);return t.refreshSelection(),O&&s.pushUndoRedo({unitID:f,undoMutations:[{id:v.id,params:O}],redoMutations:[{id:v.id,params:_.params}],undo(){return i.syncExecuteCommand(v.id,O),t.refreshSelection(),!0},redo(){return i.syncExecuteCommand(v.id,_.params),t.refreshSelection(),!0}}),!0}};function xt(r,e){const{startOffset:t,endOffset:n}=r,i=[];let s=0;for(const o of e){const{startIndex:c}=o;(t>s&&t<=c||n>s&&n<=c||c>=t&&c<=n)&&i.push(o),s=c}return i}const Qe={id:"doc.command-replace-content",type:a.CommandType.COMMAND,handler:async(r,e)=>{var p;const{unitId:t,body:n,textRanges:i,segmentId:s=""}=e,o=r.get(a.IUniverInstanceService),c=r.get(a.ICommandService),l=r.get(h.TextSelectionManagerService),u=r.get(a.IUndoRedoService),d=(p=o.getUniverDocInstance(t))==null?void 0:p.getSnapshot().body,g=l.getSelections();if(d==null||!Array.isArray(g)||g.length===0)return!1;const f=tt(t,s,d,n),m=c.syncExecuteCommand(f.id,f.params);return l.replaceTextRanges(i),m?(u.pushUndoRedo({unitID:t,undoMutations:[{id:v.id,params:m}],redoMutations:[{id:v.id,params:f.params}],undo(){return c.syncExecuteCommand(v.id,m),l.replaceTextRanges(g),!0},redo(){return c.syncExecuteCommand(v.id,f.params),l.replaceTextRanges(i),!0}}),!0):!1}},et={id:"doc.command-cover-content",type:a.CommandType.COMMAND,handler:async(r,e)=>{var d;const{unitId:t,body:n,segmentId:i=""}=e,s=r.get(a.IUniverInstanceService),o=r.get(a.ICommandService),c=r.get(a.IUndoRedoService),l=(d=s.getUniverDocInstance(t))==null?void 0:d.getSnapshot().body;if(l==null)return!1;const u=tt(t,i,l,n);return o.syncExecuteCommand(u.id,u.params),c.clearUndoRedo(t),!0}};function tt(r,e,t,n){const i={id:v.id,params:{unitId:r,mutations:[]}},s=(t==null?void 0:t.dataStream.length)-2;return s>0&&i.params.mutations.push({t:"d",len:s,line:0,segmentId:e}),n.dataStream.length>0&&i.params.mutations.push({t:"i",body:n,len:n.dataStream.length,line:0,segmentId:e}),i}const B={id:"doc.operation.move-cursor",type:a.CommandType.OPERATION,handler:(r,e)=>!!e},$={id:"doc.operation.move-selection",type:a.CommandType.OPERATION,handler:(r,e)=>!!e},Ut=(r,e)=>{const t=r.get(a.IUniverInstanceService).getUniverDocInstance(e.unitId),n=(t==null?void 0:t.zoomRatio)||1;return{...a.Tools.deepClone(e),zoomRatio:n}},k={id:"doc.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(r,e)=>{const t=r.get(a.IUniverInstanceService).getUniverDocInstance(e.unitId);if(!t)return!1;const n=t.getSnapshot();return n.settings==null?n.settings={zoomRatio:e.zoomRatio}:n.settings.zoomRatio=e.zoomRatio,!0}},nt={type:a.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(r,e)=>{const t=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService);let s=i.getCurrentUniverDocInstance().getUnitId(),o=1;if(e&&(s=e.documentId??s,o=e.zoomRatio??o),!i.getUniverDocInstance(s))return!1;const l={zoomRatio:o,unitId:s},u=Ut(r,l);return t.syncExecuteCommand(k.id,l)?(n.pushUndoRedo({unitID:s,undoMutations:[{id:k.id,params:u}],redoMutations:[{id:k.id,params:l}]}),!0):!1}},it={id:"doc.operation.select-all",type:a.CommandType.COMMAND,handler:async r=>{const e=r.get(a.IUniverInstanceService),t=r.get(h.TextSelectionManagerService),n=e.getCurrentUniverDocInstance().getSnapshot().body;if(n==null)return!1;const i=[{startOffset:0,endOffset:n.dataStream.length-2}];return t.replaceTextRanges(i),!0}},Et=10,Pt=6;function wt(){return a.Tools.generateRandomId(Pt)}function Nt(r){const e=r.match(/data-copy-id="([^\s]+)"/);return e&&e[1]?e[1]:null}class Lt{constructor(){C(this,"_cache",new a.LRUMap(Et))}set(e,t){this._cache.set(e,t)}get(e){return this._cache.get(e)}clear(){this._cache.clear()}}const rt=new Lt;function At(r){const e=r.style,t={};for(let n=0;n<e.length;n++){const i=e[n],s=e.getPropertyValue(i);switch(i){case"margin-top":{const o=parseInt(s);t.spaceAbove=/pt/.test(s)?$e(o):o;break}case"margin-bottom":{const o=parseInt(s);t.spaceBelow=/pt/.test(s)?$e(o):o;break}}}return Object.getOwnPropertyNames(t).length?t:null}function $e(r){return r/.75}function Fe(r){const e=r.style,t={},n=r.tagName.toLowerCase();switch(n){case"b":case"em":case"strong":{t.bl=a.BooleanNumber.TRUE;break}case"s":{t.st={s:a.BooleanNumber.TRUE};break}case"u":{t.ul={s:a.BooleanNumber.TRUE};break}case"i":{t.it=a.BooleanNumber.TRUE;break}case"sub":case"sup":{t.va=n==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}for(let i=0;i<e.length;i++){const s=e[i],o=e.getPropertyValue(s);switch(s){case"font-family":{t.ff=o;break}case"font-size":{const c=parseInt(o);Number.isNaN(c)||(t.fs=/pt$/.test(o)?$e(c):c);break}case"font-style":{o==="italic"&&(t.it=a.BooleanNumber.TRUE);break}case"font-weight":{Number(o)>400&&(t.bl=a.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(o)?t.ul={s:a.BooleanNumber.TRUE}:/overline/.test(o)?t.ol={s:a.BooleanNumber.TRUE}:/line-through/.test(o)&&(t.st={s:a.BooleanNumber.TRUE});break}case"color":{const c=new a.ColorKit(o);c.isValid&&(t.cl={rgb:c.toRgbString()});break}case"background-color":{const c=new a.ColorKit(o);c.isValid&&(t.bg={rgb:c.toRgbString()});break}}}return t}function Bt(r){const e=new DOMParser,t=`<x-univer id="univer-root">${r}</x-univer>`;return e.parseFromString(t,"text/html").querySelector("#univer-root")}function st(r,e){const t=r.tagName.toLowerCase();return typeof e=="string"?t===e:Array.isArray(e)?e.some(n=>n===t):e(r)}const De=class De{constructor(){C(this,"_styleCache",new Map);C(this,"_styleRules",[]);C(this,"_afterProcessRules",[])}static use(e){if(this._pluginList.includes(e))throw new Error(`Univer paste plugin ${e.name} already added`);this._pluginList.push(e)}convert(e){const t=De._pluginList.find(s=>s.checkPasteType(e)),n=Bt(e),i={dataStream:"",textRuns:[]};return t&&(this._styleRules=[...t.stylesRules],this._afterProcessRules=[...t.afterProcessRules]),this._styleCache.clear(),this._process(null,n==null?void 0:n.childNodes,i),this._styleCache.clear(),this._styleRules=[],this._afterProcessRules=[],i}_process(e,t,n){var i;for(const s of t)if(s.nodeType===Node.TEXT_NODE){const o=(i=s.nodeValue)==null?void 0:i.replace(/[\r\n]/g,"");let c;e&&this._styleCache.has(e)&&(c=this._styleCache.get(e)),n.dataStream+=o,c&&Object.getOwnPropertyNames(c).length&&n.textRuns.push({st:n.dataStream.length-o.length,ed:n.dataStream.length,ts:c})}else if(s.nodeType===Node.ELEMENT_NODE){const o=e?this._styleCache.get(e):{},c=this._styleRules.find(({filter:g})=>st(s,g)),l=c?c.getStyle(s):Fe(s);this._styleCache.set(s,{...o,...l});const{childNodes:u}=s;this._process(s,u,n);const d=this._afterProcessRules.find(({filter:g})=>st(s,g));d&&d.handler(n,s)}}};C(De,"_pluginList",[]);let ee=De;const $t={name:"univer-doc-paste-plugin-lark",checkPasteType(r){return/lark-record-clipboard/i.test(r)},stylesRules:[{filter:["s"],getStyle(r){const e=Fe(r);return{st:{s:a.BooleanNumber.TRUE},...e}}}],afterProcessRules:[{filter(r){return r.tagName==="DIV"&&/ace-line/i.test(r.className)},handler(r){r.paragraphs==null&&(r.paragraphs=[]),r.paragraphs.push({startIndex:r.dataStream.length}),r.dataStream+="\r"}}]},Ft={name:"univer-doc-paste-plugin-word",checkPasteType(r){return/word|mso/i.test(r)},stylesRules:[{filter:["b"],getStyle(r){const e=Fe(r);return{bl:a.BooleanNumber.TRUE,...e}}}],afterProcessRules:[{filter(r){return r.tagName==="P"&&/mso/i.test(r.className)},handler(r,e){r.paragraphs==null&&(r.paragraphs=[]);const t={startIndex:r.dataStream.length},n=At(e);n&&(t.paragraphStyle=n),r.paragraphs.push(t),r.dataStream+="\r"}}]};function jt(r,e){const{st:t,ed:n,ts:i={}}=e,{ff:s,fs:o,it:c,bl:l,ul:u,st:d,ol:g,bg:f,cl:m,va:p}=i;let S=r.slice(t,n);const _=[];return c===a.BooleanNumber.TRUE&&(S=`<i>${S}</i>`),p===a.BaselineOffset.SUPERSCRIPT?S=`<sup>${S}</sup>`:p===a.BaselineOffset.SUBSCRIPT&&(S=`<sub>${S}</sub>`),(u==null?void 0:u.s)===a.BooleanNumber.TRUE&&(S=`<u>${S}</u>`),(d==null?void 0:d.s)===a.BooleanNumber.TRUE&&(S=`<s>${S}</s>`),l===a.BooleanNumber.TRUE&&(S=`<strong>${S}</strong>`),s&&_.push(`font-family: ${s}`),m&&_.push(`color: ${m.rgb}`),o&&_.push(`font-size: ${o}px`),g&&_.push("text-decoration: overline"),f&&_.push(`background: ${f.rgb}`),_.length?`<span style="${_.join(";")}">${S}</span>`:S}function at(r,e=!0){const{dataStream:t,textRuns:n=[],paragraphs:i=[]}=r;let s=0;const o=[],c=[];for(const l of n){const{st:u,ed:d}=l;if(u!==s&&o.push(t.slice(s,u)),o.push(jt(t,l)),s=d,e)for(const g of i){const{startIndex:f,paragraphStyle:m={}}=g;if(f>=u&&f<=d){const{spaceAbove:p,spaceBelow:S}=m,_=[];p!=null&&(typeof p=="number"?_.push(`margin-top: ${p}px`):_.push(`margin-top: ${p.v}px`)),S!=null&&(typeof S=="number"?_.push(`margin-bottom: ${S}px`):_.push(`margin-bottom: ${S.v}px`)),c.push(`<p className="UniverNormal" ${_.length?`style="${_.join(";")}"`:""}>${o.join("")}</p>`),o.length=0}}}return c.join("")+o.join("")}class Vt{convert(e){if(e.length===0)throw new Error("The bodyList length at least to be 1");if(e.length===1)return at(e[0]);let t="";for(const n of e)t+='<p className="UniverNormal">',t+=at(n,!1),t+="</p>";return t}}var kt=Object.defineProperty,zt=Object.getOwnPropertyDescriptor,Gt=(r,e,t,n)=>{for(var i=n>1?void 0:n?zt(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&kt(e,t,i),i},ot=(r,e)=>(t,n)=>e(t,n,r);ee.use(Ft),ee.use($t);function Wt(r){const e=r.replace(/\n/g,"\r"),t=[];for(let n=0;n<e.length;n++)e[n]==="\r"&&t.push({startIndex:n});return{dataStream:e,paragraphs:t}}const ct=b.createIdentifier("doc.clipboard-service");let je=class extends a.Disposable{constructor(e,t){super();C(this,"_clipboardHooks",[]);C(this,"_htmlToUDM",new ee);C(this,"_umdToHtml",new Vt);this._currentUniverService=e,this._clipboardInterfaceService=t}async queryClipboardData(){const e=await this._clipboardInterfaceService.read();if(e.length===0)return Promise.reject();try{let t="",n="";for(const s of e)for(const o of s.types)o===T.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await s.getType(o).then(c=>c&&c.text()):o===T.HTML_CLIPBOARD_MIME_TYPE&&(t=await s.getType(o).then(c=>c&&c.text()));if(!t)return Wt(n);const i=Nt(t);if(i){const s=rt.get(i);if(s)return s}return this._htmlToUDM.convert(t)}catch(t){return Promise.reject(t)}}async setClipboardData(e){const t=wt(),n=e.length>1?e.map(s=>s.dataStream).join(`
|
|
2
|
-
`):e[0].dataStream;let i=this._umdToHtml.convert(e);return e.length===1&&(i=i.replace(/(<[a-z]+)/,(s,o)=>`${o} data-copy-id="${t}"`),rt.set(t,e[0])),this._clipboardInterfaceService.write(n,i)}addClipboardHook(e){return this._clipboardHooks.push(e),a.toDisposable(()=>{const t=this._clipboardHooks.indexOf(e);t>-1&&this._clipboardHooks.splice(t,1)})}};je=Gt([ot(0,a.IUniverInstanceService),ot(1,T.IClipboardInterfaceService)],je);var Ht=Object.defineProperty,Kt=Object.getOwnPropertyDescriptor,Yt=(r,e,t,n)=>{for(var i=n>1?void 0:n?Kt(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&Ht(e,t,i),i},K=(r,e)=>(t,n)=>e(t,n,r);let fe=class extends a.Disposable{constructor(r,e,t,n,i,s){super(),this._logService=r,this._commandService=e,this._currentUniverService=t,this._docClipboardService=n,this._textSelectionManagerService=i,this._contextService=s,this._commandExecutedListener(),this.initialize()}initialize(){[de,ue,me].forEach(r=>this.disposeWithMe(this._commandService.registerAsMultipleCommand(r))),[Ye,ge].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r)))}_commandExecutedListener(){const r=[ue.id,de.id,me.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(r.includes(e.id)&&!(!this._contextService.getContextValue(a.FOCUSING_DOC)&&!this._contextService.getContextValue(a.FOCUSING_EDITOR)))switch(e.id){case me.id:{this._handlePaste();break}case de.id:{this._handleCopy();break}case ue.id:{this._handleCut();break}default:throw new Error(`Unhandled command ${e.id}`)}}))}async _handlePaste(){const{_docClipboardService:r}=this,{segmentId:e,endOffset:t,style:n}=this._textSelectionManagerService.getActiveRange()??{},i=this._textSelectionManagerService.getSelections();if(e==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),!(t==null||i==null))try{const s=await r.queryClipboardData();let o=t;for(const l of i){const{startOffset:u,endOffset:d}=l;u==null||d==null||d<=t&&(o+=s.dataStream.length-(d-u))}const c=[{startOffset:o,endOffset:o,style:n}];this._commandService.executeCommand(Ye.id,{body:s,segmentId:e,textRanges:c})}catch{this._logService.error("[DocClipboardController] clipboard is empty")}}_getDocumentBodyInRanges(){const r=this._textSelectionManagerService.getSelections(),e=this._currentUniverService.getCurrentUniverDocInstance(),{dataStream:t,textRuns:n=[],paragraphs:i=[]}=e.getBody(),s=[];if(r==null)return s;for(const o of r){const{startOffset:c,endOffset:l,collapsed:u}=o;if(u||c==null||l==null)continue;const d={dataStream:t.slice(c,l)},g=[];for(const m of n){const p=a.Tools.deepClone(m),{st:S,ed:_}=p;a.Tools.hasIntersectionBetweenTwoRanges(S,_,c,l)&&(c>=S&&c<=_?g.push({...p,st:c,ed:Math.min(l,_)}):l>=S&&l<=_?g.push({...p,st:Math.max(c,S),ed:l}):g.push(p))}g.length&&(d.textRuns=g.map(m=>{const{st:p,ed:S}=m;return{...m,st:p-c,ed:S-c}}));const f=[];for(const m of i){const{startIndex:p}=m;p>=c&&p<=l&&f.push(a.Tools.deepClone(m))}f.length&&(d.paragraphs=f.map(m=>({...m,startIndex:m.startIndex-c}))),s.push(d)}return s}async _handleCopy(){const{_docClipboardService:r}=this,e=this._getDocumentBodyInRanges();try{r.setClipboardData(e)}catch{this._logService.error("[DocClipboardController] set clipboard failed")}}async _handleCut(){const{segmentId:r,endOffset:e,style:t}=this._textSelectionManagerService.getActiveRange()??{},n=this._textSelectionManagerService.getSelections();if(r==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),!(e==null||n==null)){this._handleCopy();try{let i=e;for(const o of n){const{startOffset:c,endOffset:l}=o;c==null||l==null||l<=e&&(i-=l-c)}const s=[{startOffset:i,endOffset:i,style:t}];this._commandService.executeCommand(ge.id,{segmentId:r,textRanges:s})}catch{this._logService.error("[DocClipboardController] cut content failed")}}}};fe=Yt([a.OnLifecycle(a.LifecycleStages.Rendered,fe),K(0,a.ILogService),K(1,a.ICommandService),K(2,a.IUniverInstanceService),K(3,ct),K(4,b.Inject(h.TextSelectionManagerService)),K(5,a.IContextService)],fe);var Xt=Object.defineProperty,qt=Object.getOwnPropertyDescriptor,Zt=(r,e,t,n)=>{for(var i=n>1?void 0:n?qt(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&Xt(e,t,i),i},Ve=(r,e)=>(t,n)=>e(t,n,r);let he=class extends a.RxDisposable{constructor(r,e,t){super(),this._docSkeletonManagerService=r,this._renderManagerService=e,this._commandService=t,this._initialRenderRefresh(),this._commandExecutedListener()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(j.takeUntil(this.dispose$)).subscribe(r=>{if(r==null)return;const{skeleton:e,unitId:t}=r,n=this._renderManagerService.getRenderById(t);if(n==null)return;const{mainComponent:i}=n;i.changeSkeleton(e),this._recalculateSizeBySkeleton(n,e)})}_recalculateSizeBySkeleton(r,e){var u;const{mainComponent:t,scene:n}=r,i=t,s=(u=e.getSkeletonData())==null?void 0:u.pages;if(s==null)return;let o=0,c=0;for(let d=0,g=s.length;d<g;d++){const f=s[d],{pageWidth:m,pageHeight:p}=f;i.pageLayoutType===M.PageLayoutType.VERTICAL?(c+=p,c+=i.pageMarginTop,d===g-1&&(c+=i.pageMarginTop),o=Math.max(o,m)):i.pageLayoutType===M.PageLayoutType.HORIZONTAL&&(o+=m,d!==g-1&&(o+=i.pageMarginLeft),c=Math.max(c,p))}i.resize(o,c),[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(r.unitId)||n.resize(o,c)}_commandExecutedListener(){const r=[v.id],e=[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(r.includes(t.id)){const i=t.params,{unitId:s}=i,o=this._docSkeletonManagerService.getSkeletonByUnitId(s);if(o==null)return;const{skeleton:c}=o,l=this._renderManagerService.getRenderById(s);if(l==null)return;if(c.calculate(),e.includes(s)){(n=l.mainComponent)==null||n.makeDirty();return}this._recalculateSizeBySkeleton(l,c)}}))}};he=Zt([a.OnLifecycle(a.LifecycleStages.Rendered,he),Ve(0,b.Inject(h.DocSkeletonManagerService)),Ve(1,M.IRenderManagerService),Ve(2,a.ICommandService)],he);var Jt=Object.defineProperty,Qt=Object.getOwnPropertyDescriptor,en=(r,e,t,n)=>{for(var i=n>1?void 0:n?Qt(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&Jt(e,t,i),i},te=(r,e)=>(t,n)=>e(t,n,r);let pe=class extends a.Disposable{constructor(e,t,n,i,s){super();C(this,"_liquid",new M.Liquid);C(this,"_pageMarginCache",new Map);this._docSkeletonManagerService=e,this._currentUniverService=t,this._renderManagerService=n,this._commandService=i,this._floatingObjectManagerService=s,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh(),this._updateOnPluginChange()}_updateOnPluginChange(){this._floatingObjectManagerService.pluginUpdate$.subscribe(e=>{const t=this._docSkeletonManagerService.getCurrent();if(t==null)return;const{unitId:n,skeleton:i}=t,s=this._renderManagerService.getRenderById(n);if(s==null)return;const{mainComponent:o,components:c,scene:l}=s,u=o,{left:d,top:g}=u;e.forEach(f=>{const{unitId:m,subComponentId:p,floatingObjectId:S,floatingObject:_}=f,{left:I=0,top:O=0,width:x=0,height:D=0,angle:R,flipX:U,flipY:E,skewX:P,skewY:w}=_,y=this._pageMarginCache.get(S),F=(y==null?void 0:y.marginLeft)||0,N=(y==null?void 0:y.marginTop)||0;i==null||i.getViewModel().getDataModel().updateDrawing(S,{left:I-d-F,top:O-g-N,height:D,width:x})}),i==null||i.calculate(),o==null||o.makeDirty()})}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{skeleton:t,unitId:n}=e,i=this._renderManagerService.getRenderById(n);if(i==null)return;const{mainComponent:s}=i;s.changeSkeleton(t),this._refreshFloatingObject(n,t,i)})}_commandExecutedListener(){const e=[v.id,k.id],t=[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{var i;if(e.includes(n.id)){const s=n.params,{unitId:o}=s,c=this._docSkeletonManagerService.getCurrent();if(c==null)return;const{unitId:l,skeleton:u}=c;if(o!==l)return;const d=this._renderManagerService.getRenderById(l);if(d==null)return;if(t.includes(l)){(i=d.mainComponent)==null||i.makeDirty();return}this._refreshFloatingObject(l,u,d)}}))}_refreshFloatingObject(e,t,n){const i=t==null?void 0:t.getSkeletonData(),{mainComponent:s,scene:o}=n,c=s;if(!i)return;const{left:l,top:u,pageLayoutType:d,pageMarginLeft:g,pageMarginTop:f}=c,{pages:m}=i,p=[];o.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let S=0,_=m.length;S<_;S++){const I=m[S],{skeDrawings:O,marginLeft:x,marginTop:D}=I;this._liquid.translatePagePadding(I),O.forEach(R=>{const{aLeft:U,aTop:E,height:P,width:w,objectId:y}=R;p.push({unitId:e,subComponentId:a.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:y,floatingObject:{left:U+l+this._liquid.x,top:E+u+this._liquid.y,width:w,height:P}}),this._pageMarginCache.set(y,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.translatePage(I,d,g,f)}this._floatingObjectManagerService.BatchAddOrUpdate(p)}};pe=en([a.OnLifecycle(a.LifecycleStages.Steady,pe),te(0,b.Inject(h.DocSkeletonManagerService)),te(1,a.IUniverInstanceService),te(2,M.IRenderManagerService),te(3,a.ICommandService),te(4,a.IFloatingObjectManagerService)],pe);var tn=Object.defineProperty,nn=Object.getOwnPropertyDescriptor,rn=(r,e,t,n)=>{for(var i=n>1?void 0:n?nn(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&tn(e,t,i),i},Y=(r,e)=>(t,n)=>e(t,n,r);let Se=class extends a.Disposable{constructor(e,t,n,i,s,o){super();C(this,"_previousIMEContent","");C(this,"_previousIMERange");C(this,"_onStartSubscription");C(this,"_onUpdateSubscription");C(this,"_onEndSubscription");this._docSkeletonManagerService=e,this._currentUniverService=t,this._renderManagerService=n,this._textSelectionRenderManager=i,this._imeInputManagerService=s,this._commandService=o,this._initialize()}dispose(){var e,t,n;(e=this._onStartSubscription)==null||e.unsubscribe(),(t=this._onUpdateSubscription)==null||t.unsubscribe(),(n=this._onEndSubscription)==null||n.unsubscribe()}_initialize(){this._initialOnCompositionstart(),this._initialOnCompositionUpdate(),this._initialOnCompositionend()}_initialOnCompositionstart(){this._onStartSubscription=this._textSelectionRenderManager.onCompositionstart$.subscribe(e=>{if(e==null)return;const{activeRange:t}=e;t!=null&&(this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(a.Tools.deepClone(t)),this._previousIMERange=t)})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._textSelectionRenderManager.onCompositionupdate$.subscribe(async e=>{this._updateContent(e,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._textSelectionRenderManager.onCompositionend$.subscribe(e=>{this._updateContent(e,!1)})}async _updateContent(e,t){var p;const n=(p=this._docSkeletonManagerService.getCurrent())==null?void 0:p.skeleton;if(this._previousIMERange==null||e==null||n==null)return;const i=this._currentUniverService.getCurrentUniverDocInstance(),{event:s,activeRange:o}=e,{startOffset:c,segmentId:l,style:u}=this._previousIMERange;if(n==null||o==null)return;const g=s.data;if(g===this._previousIMEContent&&t)return;const f=g.length,m=[{startOffset:c+f,endOffset:c+f,style:u}];await this._commandService.executeCommand(Le.id,{unitId:i.getUnitId(),newText:g,oldTextLen:this._previousIMEContent.length,range:this._previousIMERange,textRanges:m,isCompositionEnd:!t,segmentId:l}),n.calculate(),t?(this._previousIMERange.collapsed||(this._previousIMERange.collapsed=!0),this._previousIMEContent=g):this._resetIME()}_resetIME(){this._previousIMEContent="",this._previousIMERange=null,this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(null)}_getDocObject(){return X(this._currentUniverService,this._renderManagerService)}};Se=rn([a.OnLifecycle(a.LifecycleStages.Rendered,Se),Y(0,b.Inject(h.DocSkeletonManagerService)),Y(1,a.IUniverInstanceService),Y(2,M.IRenderManagerService),Y(3,M.ITextSelectionRenderManager),Y(4,b.Inject(Ne)),Y(5,a.ICommandService)],Se);var sn=Object.defineProperty,an=Object.getOwnPropertyDescriptor,on=(r,e,t,n)=>{for(var i=n>1?void 0:n?an(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&sn(e,t,i),i},lt=(r,e)=>(t,n)=>e(t,n,r);let _e=class extends a.Disposable{constructor(r,e){super(),this._textSelectionManagerService=r,this._commandService=e,this._commandExecutedListener()}_commandExecutedListener(){const r=[G.id,q.id,Z.id,J.id,A.id,V.id,W.id,H.id,Q.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{r.includes(e.id)&&this._handleInlineFormat(e)}))}_handleInlineFormat(r){const{segmentId:e}=this._textSelectionManagerService.getActiveRange()??{};e!=null&&this._commandService.executeCommand(Ae.id,{segmentId:e,preCommandId:r.id,...r.params??{}})}};_e=on([a.OnLifecycle(a.LifecycleStages.Rendered,_e),lt(0,b.Inject(h.TextSelectionManagerService)),lt(1,a.ICommandService)],_e);var cn=Object.defineProperty,ln=Object.getOwnPropertyDescriptor,dn=(r,e,t,n)=>{for(var i=n>1?void 0:n?ln(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&cn(e,t,i),i},ne=(r,e)=>(t,n)=>e(t,n,r);let ve=class extends a.Disposable{constructor(e,t,n,i,s){super();C(this,"_onInputSubscription");this._docSkeletonManagerService=e,this._currentUniverService=t,this._renderManagerService=n,this._textSelectionManagerService=i,this._commandService=s,this._initialize(),this._commandExecutedListener()}dispose(){var e;(e=this._onInputSubscription)==null||e.unsubscribe()}_initialize(){}_commandExecutedListener(){const e=[B.id,$.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(!e.includes(t.id))return;const n=t.params;switch(t.id){case B.id:return this._handleMoveCursor(n.direction);case $.id:return this._handleShiftMoveSelection(n.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(e){var S;const t=this._textSelectionManagerService.getActiveRange(),n=this._textSelectionManagerService.getSelections(),i=this._currentUniverService.getCurrentUniverDocInstance(),s=(S=this._docSkeletonManagerService.getCurrent())==null?void 0:S.skeleton,o=this._getDocObject();if(t==null||s==null||o==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d,direction:g}=t;if(n.length>1){let _=1/0,I=-1/0;for(const O of n)_=Math.min(_,O.startOffset),I=Math.max(I,O.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:e===a.Direction.LEFT||e===a.Direction.UP?I:_,endOffset:e===a.Direction.LEFT||e===a.Direction.UP?_:I,style:u}]);return}const f=d||g===M.RANGE_DIRECTION.FORWARD?c:l;let m=d||g===M.RANGE_DIRECTION.FORWARD?l:c;const p=i.getBody().dataStream.length??1/0;if(e===a.Direction.LEFT||e===a.Direction.RIGHT){const _=s.findNodeByCharIndex(m-1),I=s.findNodeByCharIndex(m);m=e===a.Direction.RIGHT?m+I.count:m-((_==null?void 0:_.count)??0),m=Math.min(p-2,Math.max(0,m)),this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:m,style:u}])}else{const _=s.findNodeByCharIndex(m),I=o.document.getOffsetConfig(),O=this._getTopOrBottomPosition(s,_,e===a.Direction.DOWN);if(O==null){const D=e===a.Direction.UP?0:p-2;if(D===m)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:D,style:u}]);return}const x=new M.NodePositionConvertToCursor(I,s).getRangePointData(O,O).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:x.endOffset,style:u}])}}_handleMoveCursor(e){var f;const t=this._textSelectionManagerService.getActiveRange(),n=this._textSelectionManagerService.getSelections(),i=this._currentUniverService.getCurrentUniverDocInstance(),s=(f=this._docSkeletonManagerService.getCurrent())==null?void 0:f.skeleton,o=this._getDocObject();if(t==null||s==null||o==null||n==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d}=t,g=i.getBody().dataStream.length??1/0;if(e===a.Direction.LEFT||e===a.Direction.RIGHT){let m;if(!t.collapsed||n.length>1){let p=1/0,S=-1/0;for(const _ of n)p=Math.min(p,_.startOffset),S=Math.max(S,_.endOffset);m=e===a.Direction.LEFT?p:S}else{const p=s.findNodeByCharIndex(c-1),S=s.findNodeByCharIndex(c);e===a.Direction.LEFT?m=Math.max(0,c-((p==null?void 0:p.count)??0)):m=Math.min(g-2,l+S.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:m,endOffset:m,style:u}])}else{const m=s.findNodeByCharIndex(c),p=s.findNodeByCharIndex(l),S=o.document.getOffsetConfig(),_=this._getTopOrBottomPosition(s,e===a.Direction.UP?m:p,e===a.Direction.DOWN);if(_==null){let O;d?O=e===a.Direction.UP?0:g-2:O=e===a.Direction.UP?c:l,this._textSelectionManagerService.replaceTextRanges([{startOffset:O,endOffset:O,style:u}]);return}const I=new M.NodePositionConvertToCursor(S,s).getRangePointData(_,_).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...I,style:u}])}}_getTopOrBottomPosition(e,t,n){if(t==null)return;const i=this._getSpanLeftOffsetInLine(t),s=this._getNextOrPrevLine(t,n);if(s==null)return;const o=this._matchPositionByLeftOffset(e,s,i);if(o!=null)return{...o,isBack:!0}}_getSpanLeftOffsetInLine(e){const t=e.parent;if(t==null)return-1/0;const n=t.left,{left:i}=e;return n+i}_matchPositionByLeftOffset(e,t,n){const i={distance:1/0};for(const s of t.divides){const o=s.left;for(const c of s.spanGroup){const{left:l}=c,u=o+l,d=Math.abs(n-u);d<i.distance&&(i.span=c,i.distance=d)}}if(i.span!=null)return e.findPositionBySpan(i.span)}_getNextOrPrevLine(e,t){var p,S,_,I,O,x,D,R,U,E,P,w;const n=e.parent;if(n==null)return;const i=n.parent;if(i==null)return;const s=i.parent;if(s==null)return;const o=s.lines.indexOf(i);if(o===-1)return;let c;if(t===!0?c=s.lines[o+1]:c=s.lines[o-1],c!=null)return c;const l=s.parent;if(l==null)return;const u=l.columns.indexOf(s);if(u===-1)return;if(t===!0)c=(p=l.columns[u+1])==null?void 0:p.lines[0];else{const y=(_=(S=l.columns)==null?void 0:S[u-1])==null?void 0:_.lines;c=y==null?void 0:y[y.length-1]}if(c!=null)return c;const d=l.parent;if(d==null)return;const g=d.sections.indexOf(l);if(g===-1)return;if(t===!0)c=(O=(I=d.sections[g-1])==null?void 0:I.columns[0])==null?void 0:O.lines[0];else{const y=(D=(x=d.sections)==null?void 0:x[g-1])==null?void 0:D.columns,F=y==null?void 0:y[y.length-1],N=F==null?void 0:F.lines;c=N==null?void 0:N[N.length-1]}if(c!=null)return c;const f=d.parent;if(f==null)return;const m=f.pages.indexOf(d);if(m!==-1){if(t===!0)c=(E=(U=(R=f.pages[m+1])==null?void 0:R.sections[0])==null?void 0:U.columns[0])==null?void 0:E.lines[0];else{const y=(P=f.pages[m-1])==null?void 0:P.sections;if(y==null)return;const F=(w=y[y.length-1])==null?void 0:w.columns,N=F[F.length-1],ut=N==null?void 0:N.lines;c=ut[ut.length-1]}if(c!=null)return c}}_getDocObject(){return X(this._currentUniverService,this._renderManagerService)}};ve=dn([a.OnLifecycle(a.LifecycleStages.Rendered,ve),ne(0,b.Inject(h.DocSkeletonManagerService)),ne(1,a.IUniverInstanceService),ne(2,M.IRenderManagerService),ne(3,b.Inject(h.TextSelectionManagerService)),ne(4,a.ICommandService)],ve);var un=Object.defineProperty,mn=Object.getOwnPropertyDescriptor,gn=(r,e,t,n)=>{for(var i=n>1?void 0:n?mn(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&un(e,t,i),i},ie=(r,e)=>(t,n)=>e(t,n,r);let Ce=class extends a.Disposable{constructor(e,t,n,i,s){super();C(this,"_onInputSubscription");this._docSkeletonManagerService=e,this._currentUniverService=t,this._renderManagerService=n,this._textSelectionRenderManager=i,this._commandService=s,this._initialize(),this._commandExecutedListener()}dispose(){var e;(e=this._onInputSubscription)==null||e.unsubscribe()}_initialize(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async e=>{var p;if(e==null)return;const n=this._currentUniverService.getCurrentUniverDocInstance().getUnitId(),{event:i,content:s="",activeRange:o}=e,c=i,l=(p=this._docSkeletonManagerService.getCurrent())==null?void 0:p.skeleton;if(c.data==null||l==null||!l||!o)return;const{startOffset:u,segmentId:d,style:g}=o,f=s.length,m=[{startOffset:u+f,endOffset:u+f,style:g}];await this._commandService.executeCommand(ce.id,{unitId:n,body:{dataStream:s},range:o,textRanges:m,segmentId:d})})}_commandExecutedListener(){}_getDocObject(){return X(this._currentUniverService,this._renderManagerService)}};Ce=gn([a.OnLifecycle(a.LifecycleStages.Rendered,Ce),ie(0,b.Inject(h.DocSkeletonManagerService)),ie(1,a.IUniverInstanceService),ie(2,M.IRenderManagerService),ie(3,M.ITextSelectionRenderManager),ie(4,a.ICommandService)],Ce);var fn=Object.defineProperty,hn=Object.getOwnPropertyDescriptor,pn=(r,e,t,n)=>{for(var i=n>1?void 0:n?hn(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&fn(e,t,i),i},dt=(r,e)=>(t,n)=>e(t,n,r);const Sn="rgba(198, 198, 198, 1)",_n="rgba(255, 255, 255, 1)";let Ie=class extends a.Disposable{constructor(r,e){super(),this._renderManagerService=r,this._currentUniverService=e,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh()}_initialRenderRefresh(){this._renderManagerService.currentRender$.subscribe(r=>{var s;if(r==null||this._currentUniverService.getUniverDocInstance(r)==null)return;const e=this._renderManagerService.getRenderById(r);if(e==null)return;const{mainComponent:t}=e,n=t,i=(s=n.getSkeleton())==null?void 0:s.getPageSize();n.onPageRenderObservable.add(o=>{if([a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(r))return;const{page:c,pageLeft:l,pageTop:u,ctx:d}=o,{width:g,pageWidth:f,height:m,pageHeight:p}=c;d.save(),d.translate(l-.5,u-.5),M.Rect.drawWith(d,{width:(i==null?void 0:i.width)??f??g,height:(i==null?void 0:i.height)??p??m,strokeWidth:1,stroke:Sn,fill:_n,zIndex:3}),d.restore()})})}_commandExecutedListener(){}};Ie=pn([a.OnLifecycle(a.LifecycleStages.Rendered,Ie),dt(0,M.IRenderManagerService),dt(1,b.Inject(a.IUniverInstanceService))],Ie);var vn=Object.defineProperty,Cn=Object.getOwnPropertyDescriptor,In=(r,e,t,n)=>{for(var i=n>1?void 0:n?Cn(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&vn(e,t,i),i},z=(r,e)=>(t,n)=>e(t,n,r);let Me=class extends a.Disposable{constructor(e,t,n,i,s,o,c){super();C(this,"_moveInObserver");C(this,"_moveOutObserver");C(this,"_downObserver");C(this,"_dblClickObserver");C(this,"_tripleClickObserver");C(this,"_loadedMap",new Set);this._docSkeletonManagerService=e,this._currentUniverService=t,this._commandService=n,this._renderManagerService=i,this._textSelectionRenderManager=s,this._textSelectionManagerService=o,this._layoutService=c,this._renderManagerService.currentRender$.subscribe(l=>{l!=null&&this._currentUniverService.getUniverDocInstance(l)!=null&&(this._loadedMap.has(l)||(this._initialMain(l),this._loadedMap.add(l)))}),this._initialize()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._layoutService&&this.disposeWithMe(this._layoutService.registerContainer(this._textSelectionRenderManager.__getEditorContainer()))}dispose(){this._renderManagerService.getRenderAll().forEach(e=>{const{mainComponent:t}=e;t!=null&&(t.onPointerEnterObserver.remove(this._moveInObserver),t.onPointerLeaveObserver.remove(this._moveOutObserver),t.onPointerDownObserver.remove(this._downObserver),t.onDblclickObserver.remove(this._dblClickObserver),t.onTripleClickObserver.remove(this._tripleClickObserver))})}_initialMain(e){const t=this._getDocObjectById(e);if(t==null)return;const{document:n,scene:i}=t;this._moveInObserver=n.onPointerEnterObserver.add(()=>{n.cursor=M.CURSOR_TYPE.TEXT}),this._moveOutObserver=n.onPointerLeaveObserver.add(()=>{n.cursor=M.CURSOR_TYPE.DEFAULT,i.resetCursor()}),this._downObserver=n==null?void 0:n.onPointerDownObserver.add((s,o)=>{this._currentUniverService.getCurrentUniverDocInstance().getUnitId()!==e&&this._currentUniverService.setCurrentUniverDocInstance(e),this._textSelectionRenderManager.eventTrigger(s),s.button!==2&&o.stopPropagation()}),this._dblClickObserver=n==null?void 0:n.onDblclickObserver.add(s=>{this._textSelectionRenderManager.handleDblClick(s)}),this._tripleClickObserver=n==null?void 0:n.onTripleClickObserver.add(s=>{this._textSelectionRenderManager.handleTripleClick(s)})}_commandExecutedListener(){const e=[k.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const i=t.params,{unitId:s}=i,o=(n=this._textSelectionManagerService.getCurrentSelection())==null?void 0:n.unitId;if(s!==o)return;this._textSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t,skeleton:n}=e,i=this._renderManagerService.getRenderById(t);if(i==null)return;const{scene:s,mainComponent:o}=i;this._textSelectionRenderManager.changeRuntime(n,s,o),this._textSelectionManagerService.setCurrentSelectionNotRefresh({unitId:t,subUnitId:""})})}_getDocObjectById(e){return mt(e,this._renderManagerService)}};Me=In([a.OnLifecycle(a.LifecycleStages.Rendered,Me),z(0,b.Inject(h.DocSkeletonManagerService)),z(1,a.IUniverInstanceService),z(2,a.ICommandService),z(3,M.IRenderManagerService),z(4,M.ITextSelectionRenderManager),z(5,b.Inject(h.TextSelectionManagerService)),z(6,b.Optional(T.LayoutService))],Me);var Mn=Object.defineProperty,On=Object.getOwnPropertyDescriptor,Rn=(r,e,t,n)=>{for(var i=n>1?void 0:n?On(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&Mn(e,t,i),i},re=(r,e)=>(t,n)=>e(t,n,r);let Oe=class extends a.Disposable{constructor(e,t,n,i,s){super();C(this,"_initializedRender",new Set);this._docSkeletonManagerService=e,this._currentUniverService=t,this._commandService=n,this._renderManagerService=i,this._textSelectionManagerService=s,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._initialRenderRefresh()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t}=e,n=this._renderManagerService.getRenderById(t);if(n==null||this._initializedRender.has(t)||[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(t))return;this._initializedRender.add(t);const{scene:i}=n;this.disposeWithMe(a.toDisposable(i.onMouseWheelObserver.add(s=>{if(!s.ctrlKey)return;const o=Math.abs(s.deltaX);let c=o<40?.2:o<80?.4:.2;c*=s.deltaY>0?-1:1,i.scaleX<1&&(c/=2);const l=this._currentUniverService.getCurrentUniverDocInstance(),u=l.zoomRatio;let d=+parseFloat(`${u+c}`).toFixed(1);d=d>=4?4:d<=.1?.1:d,this._commandService.executeCommand(nt.id,{zoomRatio:d,unitId:l.getUnitId()}),s.preventDefault()})))})}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._docSkeletonManagerService.currentSkeletonBefore$.subscribe(e=>{if(e==null)return;const n=this._currentUniverService.getCurrentUniverDocInstance().zoomRatio||1;this._updateViewZoom(n,!1)})))}_commandExecutedListener(){const e=[k.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=this._currentUniverService.getCurrentUniverDocInstance(),i=t.params,{unitId:s}=i;if(s!==n.getUnitId())return;const o=n.zoomRatio||1;this._updateViewZoom(o)}}))}_updateViewZoom(e,t=!0){var i;const n=this._getDocObject();n!=null&&(n.scene.scale(e,e),this._calculatePagePosition(n,e),t&&this._textSelectionManagerService.refreshSelection(),(i=n.scene.getTransformer())==null||i.hideControl())}_calculatePagePosition(e,t){const{document:n,scene:i}=e,s=i==null?void 0:i.getParent(),{width:o,height:c,pageMarginLeft:l,pageMarginTop:u}=n;if(s==null||o===1/0||c===1/0)return;const{width:d,height:g}=s;let f=0,m=0,p=0,S=0,_=1/0;d>(o+l*2)*t?(f=d/2-o*t/2,f/=t,p=(d-l*2)/t,_=0):(f=l,p=o+l*2,_=(p-d/t)/2),g>c?(m=g/2-c/2,S=(g-u*2)/t):(m=u,S=c+u*2),i.resize(p,S+200),n.translate(f,m);const I=i.getViewport(ae.VIEW_MAIN);if(_!==1/0&&I!=null){const O=I.getBarScroll(_,0).x;I.scrollTo({x:O})}return this}_getDocObject(){return X(this._currentUniverService,this._renderManagerService)}};Oe=Rn([a.OnLifecycle(a.LifecycleStages.Rendered,Oe),re(0,b.Inject(h.DocSkeletonManagerService)),re(1,a.IUniverInstanceService),re(2,a.ICommandService),re(3,M.IRenderManagerService),re(4,b.Inject(h.TextSelectionManagerService))],Oe);const yn={id:Ue.id,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),binding:T.KeyCode.ENTER},Dn={id:Ee.id,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),binding:T.KeyCode.BACKSPACE},Tn={id:Pe.id,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),binding:T.KeyCode.DELETE},bn={id:B.id,binding:T.KeyCode.ARROW_UP,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.UP}},xn={id:B.id,binding:T.KeyCode.ARROW_DOWN,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.DOWN}},Un={id:B.id,binding:T.KeyCode.ARROW_LEFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.LEFT}},En={id:B.id,binding:T.KeyCode.ARROW_RIGHT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.RIGHT}},Pn={id:$.id,binding:T.KeyCode.ARROW_UP|T.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.UP}},wn={id:$.id,binding:T.KeyCode.ARROW_DOWN|T.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.DOWN}},Nn={id:$.id,binding:T.KeyCode.ARROW_LEFT|T.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.LEFT}},Ln={id:$.id,binding:T.KeyCode.ARROW_RIGHT|T.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.RIGHT}},An={id:it.id,binding:T.KeyCode.A|T.MetaKeys.CTRL_COMMAND,preconditions:r=>r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.FOCUSING_EDITOR)};var Bn=Object.defineProperty,$n=Object.getOwnPropertyDescriptor,Fn=(r,e,t,n)=>{for(var i=n>1?void 0:n?$n(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&Bn(e,t,i),i},Re=(r,e)=>(t,n)=>e(t,n,r);h.DocCanvasView=class extends a.RxDisposable{constructor(t,n,i,s){super();C(this,"_scene");C(this,"_currentDocumentModel");C(this,"_loadedMap",new Set);C(this,"_fps$",new j.BehaviorSubject(""));C(this,"fps$",this._fps$.asObservable());this._renderManagerService=t,this._configService=n,this._currentUniverService=i,this._docViewModelManagerService=s,this._initialize()}_initialize(){this._currentUniverService.currentDoc$.subscribe(t=>{if(t==null)return;this._currentDocumentModel=t;const n=t.getUnitId();this._docViewModelManagerService.setCurrent(n),this._loadedMap.has(n)||(this._addNewRender(),this._loadedMap.add(n))})}dispose(){this._fps$.complete()}_addNewRender(){const t=this._currentDocumentModel,n=t.getUnitId(),i=t.getContainer(),s=t.getParentRenderUnitId();if(i!=null&&s!=null)throw new Error("container or parentRenderUnitId can only exist one");i==null&&s!=null?this._renderManagerService.createRenderWithParent(n,s):this._renderManagerService.createRender(n);const o=this._renderManagerService.getRenderById(n);if(o==null)return;const{scene:c,engine:l}=o;c.openTransformer(),this._scene=c;const u=new M.Viewport(ae.VIEW_MAIN,c,{left:0,top:0,bottom:0,right:0,isWheelPreventDefaultX:!0});c.addViewport(u).attachControl(),c.on(M.EVENT_TYPE.wheel,(f,m)=>{const p=f;if(p.ctrlKey){const S=Math.abs(p.deltaX);let _=S<40?.2:S<80?.4:.2;_*=p.deltaY>0?-1:1,c.scaleX<1&&(_/=2),c.scaleX+_>4?c.scale(4,4):c.scaleX+_<.1?c.scale(.1,.1):p.preventDefault()}else u.onMouseWheel(p,m)}),this._configService.getConfig("hasScroll")!==!1&&n!==a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&new M.ScrollBar(u),c.addLayer(new M.Layer(c,[],Te),new M.Layer(c,[],ze)),this._addComponent(o),this._currentDocumentModel.getShouldRenderLoopImmediately()&&l.runRenderLoop(()=>{c.render(),this._fps$.next(Math.round(l.getFps()).toString())}),this._renderManagerService.setCurrent(n)}_addComponent(t){const n=this._scene,i=this._currentDocumentModel,s=new M.Documents(se.MAIN,void 0,{pageMarginLeft:i.documentStyle.marginLeft||0,pageMarginTop:i.documentStyle.marginTop||0});s.zIndex=Ge,t.mainComponent=s,t.components.set(se.MAIN,s),n.addObjects([s],Te)}},h.DocCanvasView=Fn([a.OnLifecycle(a.LifecycleStages.Ready,h.DocCanvasView),Re(0,M.IRenderManagerService),Re(1,a.IConfigService),Re(2,a.IUniverInstanceService),Re(3,b.Inject(h.DocViewModelManagerService))],h.DocCanvasView);var jn=Object.defineProperty,Vn=Object.getOwnPropertyDescriptor,kn=(r,e,t,n)=>{for(var i=n>1?void 0:n?Vn(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&jn(e,t,i),i},ye=(r,e)=>(t,n)=>e(t,n,r);const zn={hasScroll:!0},Gn="docs";h.UniverDocsPlugin=(ke=class extends a.Plugin{constructor(t={},n,i,s,o){super(Gn);C(this,"_config");this._injector=n,this._localeService=i,this._configService=s,this._currentUniverService=o,this._config=Object.assign(zn,t),this._initializeDependencies(n),this._initializeCommands()}initialize(){}_initializeCommands(){[B,$,Ee,Pe,G,q,Z,J,A,V,W,H,Q,Ae,Ue,ce,le,xe,Le,we,v,Qe,et,nt,k,be,it,Je,Ze,Be].forEach(t=>{this._injector.get(a.ICommandService).registerCommand(t)}),[bn,xn,En,Un,Pn,wn,Nn,Ln,An,Dn,Tn,yn].forEach(t=>{this._injector.get(T.IShortcutService).registerShortcut(t)})}onReady(){this.initialize()}_initializeDependencies(t){[[h.DocCanvasView],[h.DocSkeletonManagerService],[h.DocViewModelManagerService],[Ne],[ct,{useClass:je}],[M.ITextSelectionRenderManager,{useClass:M.TextSelectionRenderManager}],[h.TextSelectionManagerService],[he],[Ie],[Me],[Ce],[Se],[_e],[fe],[ve],[Oe],[pe]].forEach(n=>t.add(n))}},C(ke,"type",a.PluginType.Doc),ke),h.UniverDocsPlugin=kn([ye(1,b.Inject(b.Injector)),ye(2,b.Inject(a.LocaleService)),ye(3,a.IConfigService),ye(4,a.IUniverInstanceService)],h.UniverDocsPlugin),h.BreakLineCommand=Ue,h.BulletListCommand=Ze,h.CoverContentCommand=et,h.DOCS_COMPONENT_DEFAULT_Z_INDEX=Ge,h.DOCS_COMPONENT_HEADER_LAYER_INDEX=ze,h.DOCS_COMPONENT_MAIN_LAYER_INDEX=Te,h.DOCS_VIEW_KEY=se,h.DeleteCommand=le,h.DeleteLeftCommand=Ee,h.DeleteRightCommand=Pe,h.DocCopyCommand=de,h.DocCutCommand=ue,h.DocPasteCommand=me,h.IMEInputCommand=Le,h.InsertCommand=ce,h.MoveCursorOperation=B,h.MoveSelectionOperation=$,h.NORMAL_TEXT_SELECTION_PLUGIN_NAME=gt,h.OrderListCommand=Je,h.ReplaceContentCommand=Qe,h.RichTextEditingMutation=v,h.SetInlineFormatBoldCommand=G,h.SetInlineFormatCommand=Ae,h.SetInlineFormatFontFamilyCommand=H,h.SetInlineFormatFontSizeCommand=W,h.SetInlineFormatItalicCommand=q,h.SetInlineFormatStrikethroughCommand=J,h.SetInlineFormatSubscriptCommand=A,h.SetInlineFormatSuperscriptCommand=V,h.SetInlineFormatTextColorCommand=Q,h.SetInlineFormatUnderlineCommand=Z,h.SetTextSelectionsOperation=be,h.UpdateCommand=xe,h.VIEWPORT_KEY=ae,h.getDocObject=X,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(m,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("rxjs"),require("@univerjs/ui"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","rxjs","@univerjs/ui","@wendellhu/redi"],a):(m=typeof globalThis<"u"?globalThis:m||self,a(m.UniverDocs={},m.UniverCore,m.UniverEngineRender,m.rxjs,m.UniverUi,m["@wendellhu/redi"]))})(this,function(m,a,M,N,T,b){"use strict";var Wn=Object.defineProperty;var Hn=(m,a,M)=>a in m?Wn(m,a,{enumerable:!0,configurable:!0,writable:!0,value:M}):m[a]=M;var C=(m,a,M)=>(Hn(m,typeof a!="symbol"?a+"":a,M),M);var Ve;function X(r,t){const n=r.getCurrentUniverDocInstance().getUnitId(),i=t.getRenderById(n);if(i==null)return;const{mainComponent:s,scene:o,engine:c}=i;return{document:s,scene:o,engine:c}}function mt(r,t){const e=t.getRenderById(r);if(e==null)return;const{mainComponent:n,scene:i,engine:s}=e;return{document:n,scene:i,engine:s}}var se=(r=>(r.MAIN="__Document_Render_Main__",r))(se||{}),ae=(r=>(r.VIEW_MAIN="viewMain",r.VIEW_TOP="viewTop",r.VIEW_LEFT="viewLeft",r.VIEW_LEFT_TOP="viewLeftTop",r))(ae||{});const Te=0,ze=2,Ge=10,gt="normalTextSelectionPluginName",be={id:"doc.operation.set-selections",type:a.CommandType.OPERATION,handler:(r,t)=>!0};var ht=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,pt=(r,t,e,n)=>{for(var i=n>1?void 0:n?ft(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&ht(t,e,i),i},We=(r,t)=>(e,n)=>t(e,n,r);function He(r){const{startOffset:t,endOffset:e,collapsed:n}=r;return{startOffset:t,endOffset:e,collapsed:n}}m.TextSelectionManagerService=class extends a.RxDisposable{constructor(e,n){super();C(this,"_currentSelection",null);C(this,"_textSelectionInfo",new Map);C(this,"_textSelection$",new N.BehaviorSubject(null));C(this,"textSelection$",this._textSelection$.asObservable());this._textSelectionRenderManager=e,this._commandService=n,this._syncSelectionFromRenderService()}getCurrentSelection(){return this._currentSelection}getCurrentSelectionInfo(){return this._getTextRanges(this._currentSelection)}dispose(){this._textSelection$.complete()}refreshSelection(){this._currentSelection!=null&&this._refresh(this._currentSelection)}setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}setCurrentSelectionNotRefresh(e){this._currentSelection=e}getSelections(){var e;return(e=this._getTextRanges(this._currentSelection))==null?void 0:e.textRanges}getActiveRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:n,segmentId:i,style:s}=e,o=n.find(g=>g.isActive());if(o==null)return null;const{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:f,direction:h}=o;return c==null||l==null?null:{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:f,direction:h,segmentId:i,style:s}}add(e){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,segmentId:"",style:M.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e){this._currentSelection!=null&&(this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges(e))}_syncSelectionFromRenderService(){this._textSelectionRenderManager.textSelectionInner$.pipe(N.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._replaceTextRangesWithNoRefresh(e)})}_replaceTextRangesWithNoRefresh(e){if(this._currentSelection==null)return;const n={...this._currentSelection,...e};this._replaceByParam(n),this._textSelection$.next(n);const{unitId:i,subUnitId:s,segmentId:o,style:c,textRanges:l}=n;this._commandService.executeCommand(be.id,{unitId:i,subUnitId:s,segmentId:o,style:c,ranges:l.map(He)})}_getTextRanges(e){var s;if(e==null)return;const{unitId:n,subUnitId:i=""}=e;return(s=this._textSelectionInfo.get(n))==null?void 0:s.get(i)}_refresh(e){const n=this._getTextRanges(e);this._textSelectionRenderManager.removeAllTextRanges(),n&&Array.isArray(n.textRanges)&&n.textRanges.length&&this._textSelectionRenderManager.addTextRanges(n.textRanges.map(He))}_replaceByParam(e){const{unitId:n,subUnitId:i,style:s,segmentId:o,textRanges:c}=e;this._textSelectionInfo.has(n)||this._textSelectionInfo.set(n,new Map),this._textSelectionInfo.get(n).set(i,{textRanges:c,style:s,segmentId:o})}_addByParam(e){const{unitId:n,subUnitId:i,textRanges:s,style:o,segmentId:c}=e;this._textSelectionInfo.has(n)||this._textSelectionInfo.set(n,new Map);const l=this._textSelectionInfo.get(n);l.has(i)?l.get(i).textRanges.push(...s):l.set(i,{textRanges:s,style:o,segmentId:c})}},m.TextSelectionManagerService=pt([We(0,M.ITextSelectionRenderManager),We(1,a.ICommandService)],m.TextSelectionManagerService);function oe(r,t="",e=0){const{startOffset:n,endOffset:i}=r,s=[],o=n-e,c=i-e;return o>0&&s.push({t:"r",len:o,segmentId:t}),s.push({t:"d",len:c-o,line:0,segmentId:t}),s}var St=Object.defineProperty,_t=Object.getOwnPropertyDescriptor,vt=(r,t,e,n)=>{for(var i=n>1?void 0:n?_t(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&St(t,e,i),i},Ct=(r,t)=>(e,n)=>t(e,n,r);m.DocViewModelManagerService=class extends a.RxDisposable{constructor(e){super();C(this,"_currentViewModelUnitId","");C(this,"_docViewModelMap",new Map);C(this,"_currentDocViewModel$",new N.BehaviorSubject(null));C(this,"currentDocViewModel$",this._currentDocViewModel$.asObservable());this._currentUniverService=e,this._initialize()}_initialize(){this._currentUniverService.currentDoc$.pipe(N.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const n=e.getUnitId();this._setCurrent(n)})}dispose(){this._currentDocViewModel$.complete(),this._docViewModelMap.clear()}getCurrent(){return this._docViewModelMap.get(this._currentViewModelUnitId)}getViewModel(e){var n;return(n=this._docViewModelMap.get(e))==null?void 0:n.docViewModel}_setCurrent(e){var i;const n=this._currentUniverService.getUniverDocInstance(e);if(n==null)throw new Error(`Document data model with id ${e} not found when build view model.`);if(n.getBody()!=null){if(!this._docViewModelMap.has(e)){const s=this._buildDocViewModel(n);this._docViewModelMap.set(e,{unitId:e,docViewModel:s})}if(e===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY){const s=(i=this._docViewModelMap.get(e))==null?void 0:i.docViewModel;if(s==null)return;s.reset(n)}this._currentViewModelUnitId=e,this._currentDocViewModel$.next(this.getCurrent())}}_buildDocViewModel(e){return new M.DocumentViewModel(e)}},m.DocViewModelManagerService=vt([Ct(0,a.IUniverInstanceService)],m.DocViewModelManagerService);const v={id:"doc.mutation.rich-text-editing",type:a.CommandType.MUTATION,handler:(r,t)=>{const{unitId:e,mutations:n}=t,s=r.get(a.IUniverInstanceService).getUniverDocInstance(e),c=r.get(m.DocViewModelManagerService).getViewModel(e);if(s==null||c==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);if(n.length===0)throw new Error("Mutation's length should great than 0 when call RichTextEditingMutation");const l=s.apply(n),{segmentId:u}=n[0],d=s.getSelfOrHeaderFooterModel(u);return c.getSelfOrHeaderFooterViewModel(u).reset(d),{unitId:e,mutations:l}}},ce={id:"doc.command.insert-text",type:a.CommandType.COMMAND,handler:async(r,t)=>{const e=r.get(a.IUndoRedoService),n=r.get(a.ICommandService),i=r.get(m.TextSelectionManagerService),{range:s,segmentId:o,body:c,unitId:l,textRanges:u}=t,{startOffset:d,collapsed:f}=s,h={id:v.id,params:{unitId:l,mutations:[]}};f?d>0&&h.params.mutations.push({t:"r",len:d,segmentId:o}):h.params.mutations.push(...oe(s,o)),h.params.mutations.push({t:"i",body:c,len:c.dataStream.length,line:0,segmentId:o});const g=n.syncExecuteCommand(h.id,h.params);return i.replaceTextRanges(u),g?(e.pushUndoRedo({unitID:l,undoMutations:[{id:v.id,params:g}],redoMutations:[{id:v.id,params:h.params}],undo(){return n.syncExecuteCommand(v.id,g),i.replaceTextRanges([s]),!0},redo(){return n.syncExecuteCommand(v.id,h.params),i.replaceTextRanges(u),!0}}),!0):!1}};var A=(r=>(r[r.LEFT=0]="LEFT",r[r.RIGHT=1]="RIGHT",r))(A||{});const le={id:"doc.command.delete-text",type:a.CommandType.COMMAND,handler:async(r,t)=>{const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(m.TextSelectionManagerService),{range:s,segmentId:o,unitId:c,direction:l,textRanges:u,len:d=1}=t,{startOffset:f}=s,h={id:v.id,params:{unitId:c,mutations:[]}};f>0&&h.params.mutations.push({t:"r",len:l===0?f-d:f,segmentId:o}),h.params.mutations.push({t:"d",len:d,line:0,segmentId:o});const g=e.syncExecuteCommand(h.id,h.params);return i.replaceTextRanges(u),g&&n.pushUndoRedo({unitID:c,undoMutations:[{id:v.id,params:g}],redoMutations:[{id:v.id,params:h.params}],undo(){return e.syncExecuteCommand(v.id,g),i.replaceTextRanges([s]),!0},redo(){return e.syncExecuteCommand(v.id,h.params),i.replaceTextRanges(u),!0}}),!1}},xe={id:"doc.command.update-text",type:a.CommandType.COMMAND,handler:async(r,t)=>{const{range:e,segmentId:n,updateBody:i,coverType:s,unitId:o,textRanges:c}=t,l=r.get(a.ICommandService),u=r.get(a.IUndoRedoService),d=r.get(m.TextSelectionManagerService),f={id:v.id,params:{unitId:o,mutations:[]}},{startOffset:h,endOffset:g}=e;f.params.mutations.push({t:"r",len:h,segmentId:n}),f.params.mutations.push({t:"r",body:i,len:g-h,segmentId:n,coverType:s});const p=l.syncExecuteCommand(f.id,f.params);return d.replaceTextRanges(c),p?(u.pushUndoRedo({unitID:o,undoMutations:[{id:v.id,params:p}],redoMutations:[{id:v.id,params:f.params}],undo(){return l.syncExecuteCommand(v.id,p),d.replaceTextRanges(c),!0},redo(){return l.syncExecuteCommand(v.id,f.params),d.replaceTextRanges(c),!0}}),!0):!1}};function It(r,t){const e=[];for(let n=0,i=r.length;n<i;n++)r[n]===a.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:n});if(t)for(const n of e)t.bullet&&(n.bullet=a.Tools.deepClone(t.bullet)),t.paragraphStyle&&(n.paragraphStyle=a.Tools.deepClone(t.paragraphStyle));return e}const Ue={id:"doc.command.break-line",type:a.CommandType.COMMAND,handler:async r=>{var p;const t=r.get(m.TextSelectionManagerService),e=r.get(a.IUniverInstanceService),n=r.get(a.ICommandService),i=t.getActiveRange();if(i==null)return!1;const s=e.getCurrentUniverDocInstance(),o=s.getUnitId(),{startOffset:c,segmentId:l,style:u}=i,d=[{startOffset:c+1,endOffset:c+1,style:u}],h=(((p=s.getBody())==null?void 0:p.paragraphs)??[]).find(S=>S.startIndex>=c);return await n.executeCommand(ce.id,{unitId:o,body:{dataStream:a.DataStreamTreeTokenType.PARAGRAPH,paragraphs:It(a.DataStreamTreeTokenType.PARAGRAPH,h)},range:i,textRanges:d,segmentId:l})}},de={id:T.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:999,preconditions:r=>r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.FOCUSING_EDITOR),handler:async()=>!0},ue={id:T.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:999,preconditions:r=>r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.FOCUSING_EDITOR),handler:async()=>!0},me={id:T.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:999,preconditions:r=>r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.FOCUSING_EDITOR),handler:async()=>!0};var Mt=Object.defineProperty,Ot=Object.getOwnPropertyDescriptor,yt=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ot(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&Mt(t,e,i),i},Ke=(r,t)=>(e,n)=>t(e,n,r);m.DocSkeletonManagerService=class extends a.RxDisposable{constructor(e,n){super();C(this,"_currentSkeletonUnitId","");C(this,"_docSkeletonMap",new Map);C(this,"_currentSkeleton$",new N.BehaviorSubject(null));C(this,"currentSkeleton$",this._currentSkeleton$.asObservable());C(this,"_currentSkeletonBefore$",new N.BehaviorSubject(null));C(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._localeService=e,this._docViewModelManagerService=n,this._initialize()}_initialize(){this._docViewModelManagerService.currentDocViewModel$.pipe(N.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._setCurrent(e)})}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._docSkeletonMap.clear()}getCurrent(){return this.getSkeletonByUnitId(this._currentSkeletonUnitId)}makeDirtyCurrent(e=!0){this.makeDirty(this._currentSkeletonUnitId,e)}makeDirty(e,n=!0){const i=this.getSkeletonByUnitId(e);i!=null&&(i.dirty=n)}getSkeletonByUnitId(e){return this._docSkeletonMap.get(e)}_setCurrent(e){const{unitId:n}=e;if(this._docSkeletonMap.has(n)){const i=this.getSkeletonByUnitId(n);i.skeleton.calculate(),i.dirty=!0}else{const i=this._buildSkeleton(e.docViewModel);i.calculate(),this._docSkeletonMap.set(n,{unitId:n,skeleton:i,dirty:!1})}return this._currentSkeletonUnitId=n,this._currentSkeletonBefore$.next(this.getCurrent()),this._currentSkeleton$.next(this.getCurrent()),this.getCurrent()}_buildSkeleton(e){return M.DocumentSkeleton.create(e,this._localeService)}},m.DocSkeletonManagerService=yt([Ke(0,b.Inject(a.LocaleService)),Ke(1,b.Inject(m.DocViewModelManagerService))],m.DocSkeletonManagerService);const Ye={id:"doc.command.inner-paste",type:a.CommandType.COMMAND,handler:async(r,t)=>{const{segmentId:e,body:n,textRanges:i}=t,s=r.get(a.IUndoRedoService),o=r.get(a.ICommandService),c=r.get(m.TextSelectionManagerService),l=r.get(a.IUniverInstanceService),u=c.getSelections();if(!Array.isArray(u)||u.length===0)return!1;const f=l.getCurrentUniverDocInstance().getUnitId(),h={id:v.id,params:{unitId:f,mutations:[]}},g=new a.MemoryCursor;g.reset();for(const S of u){const{startOffset:_,endOffset:I,collapsed:O}=S,x=_-g.cursor;O?h.params.mutations.push({t:"r",len:x,segmentId:e}):h.params.mutations.push(...oe(S,e,g.cursor)),h.params.mutations.push({t:"i",body:n,len:n.dataStream.length,line:0,segmentId:e}),g.reset(),g.moveCursor(I)}const p=o.syncExecuteCommand(h.id,h.params);return c.replaceTextRanges(i),p?(s.pushUndoRedo({unitID:f,undoMutations:[{id:v.id,params:p}],redoMutations:[{id:v.id,params:h.params}],undo(){return o.syncExecuteCommand(v.id,p),c.replaceTextRanges(u),!0},redo(){return o.syncExecuteCommand(v.id,h.params),c.replaceTextRanges(i),!0}}),!0):!1}},ge={id:"doc.command.inner-cut",type:a.CommandType.COMMAND,handler:async(r,t)=>{const{segmentId:e,textRanges:n}=t,i=r.get(a.IUndoRedoService),s=r.get(a.ICommandService),o=r.get(m.TextSelectionManagerService),c=r.get(a.IUniverInstanceService),l=o.getSelections();if(!Array.isArray(l)||l.length===0)return!1;const u=c.getCurrentUniverDocInstance().getUnitId(),d=c.getUniverDocInstance(u),f=a.getDocsUpdateBody(d.snapshot,e);if(f==null)return!1;const h={id:v.id,params:{unitId:u,mutations:[]}},g=new a.MemoryCursor;g.reset();for(const S of l){const{startOffset:_,endOffset:I,collapsed:O}=S,x=_-g.cursor;O?h.params.mutations.push({t:"r",len:x,segmentId:e}):h.params.mutations.push(...Rt(S,f,e,g.cursor)),g.reset(),g.moveCursor(I)}const p=s.syncExecuteCommand(h.id,h.params);return o.replaceTextRanges(n),p?(i.pushUndoRedo({unitID:u,undoMutations:[{id:v.id,params:p}],redoMutations:[{id:v.id,params:h.params}],undo(){return s.syncExecuteCommand(v.id,p),o.replaceTextRanges(l),!0},redo(){return s.syncExecuteCommand(v.id,h.params),o.replaceTextRanges(n),!0}}),!0):!1}};function Rt(r,t,e="",n=0){const{startOffset:i,endOffset:s}=r,o=[],{paragraphs:c=[]}=t,l=i-n,u=s-n,d=c==null?void 0:c.find(f=>f.startIndex-n>=l&&f.startIndex-n<=u);if(l>0&&o.push({t:"r",len:l,segmentId:e}),d&&d.startIndex-n>l){const f=d.startIndex-n;o.push({t:"d",len:f-l,line:0,segmentId:e}),o.push({t:"r",len:1,segmentId:e}),u>f+1&&o.push({t:"d",len:u-f-1,line:0,segmentId:e})}else o.push({t:"d",len:u-l,line:0,segmentId:e});return o}const Ee={id:"doc.command.delete-left",type:a.CommandType.COMMAND,handler:async r=>{var D;const t=r.get(m.TextSelectionManagerService),e=r.get(m.DocSkeletonManagerService),n=r.get(a.IUniverInstanceService),i=r.get(a.ICommandService),s=t.getActiveRange(),o=t.getSelections(),c=(D=e.getCurrent())==null?void 0:D.skeleton;let l;if(s==null||c==null||o==null)return!1;const u=n.getCurrentUniverDocInstance(),{startOffset:d,collapsed:f,segmentId:h,style:g}=s;if(d===0&&f)return!0;const p=c.findNodeByCharIndex(d),S=M.hasListSpan(p),_=M.isIndentBySpan(p,u.body);let I=d;const O=c.findNodeByCharIndex(d-1);if(M.isFirstSpan(p)&&O!==p&&(S===!0||_===!0)){const y=M.getParagraphBySpan(p,u.body);if(y==null)return!1;const U=y==null?void 0:y.startIndex,E={startIndex:0},P=y.paragraphStyle;if(S===!0){const R=y.paragraphStyle;R&&(E.paragraphStyle=R)}else if(_===!0){const R=y.bullet;R&&(E.bullet=R),P!=null&&(E.paragraphStyle={...P},delete E.paragraphStyle.hanging,delete E.paragraphStyle.indentStart)}const w=[{startOffset:I,endOffset:I,style:g}];l=await i.executeCommand(xe.id,{unitId:u.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...E}]},range:{startOffset:U,endOffset:U+1},textRanges:w,coverType:a.UpdateDocsAttributeType.REPLACE,segmentId:h})}else if(f===!0)if(O.content==="\r")l=await i.executeCommand(Ne.id,{direction:A.LEFT,range:s});else{I-=O.count;const y=[{startOffset:I,endOffset:I,style:g}];l=await i.executeCommand(le.id,{unitId:u.getUnitId(),range:s,segmentId:h,direction:A.LEFT,len:O.count,textRanges:y})}else{const y=Xe(s,o);l=await i.executeCommand(ge.id,{segmentId:h,textRanges:y})}return l}},Pe={id:"doc.command.delete-right",type:a.CommandType.COMMAND,handler:async r=>{var p;const t=r.get(m.TextSelectionManagerService),e=r.get(m.DocSkeletonManagerService),n=r.get(a.IUniverInstanceService),i=r.get(a.ICommandService),s=t.getActiveRange(),o=t.getSelections(),c=(p=e.getCurrent())==null?void 0:p.skeleton;let l;if(s==null||c==null||o==null)return!1;const u=n.getCurrentUniverDocInstance(),{startOffset:d,collapsed:f,segmentId:h,style:g}=s;if(d===u.getBody().dataStream.length-2&&f)return!0;if(f===!0){const S=c.findNodeByCharIndex(d);if(S.content==="\r")l=await i.executeCommand(Ne.id,{direction:A.RIGHT,range:s});else{const _=[{startOffset:d,endOffset:d,style:g}];l=await i.executeCommand(le.id,{unitId:u.getUnitId(),range:s,segmentId:h,direction:A.RIGHT,textRanges:_,len:S.count})}}else{const S=Xe(s,o);l=await i.executeCommand(ge.id,{segmentId:h,textRanges:S})}return l}},Ne={id:"doc.command.merge-two-paragraph",type:a.CommandType.COMMAND,handler:async(r,t)=>{var E,P,w;const e=r.get(m.TextSelectionManagerService),n=r.get(a.IUniverInstanceService),i=r.get(a.ICommandService),s=r.get(a.IUndoRedoService),{direction:o,range:c}=t,l=e.getActiveRange(),u=e.getSelections();if(l==null||u==null)return!1;const d=n.getCurrentUniverDocInstance(),{startOffset:f,collapsed:h,segmentId:g,style:p}=l;if(!h)return!1;const S=o===A.LEFT?f:f+1,_=(w=(P=(E=d.getBody())==null?void 0:E.paragraphs)==null?void 0:P.find(R=>R.startIndex>=S))==null?void 0:w.startIndex,I=Dt(d.getBody(),S,_),O=o===A.LEFT?f-1:f,x=d.getUnitId(),D=[{startOffset:O,endOffset:O,style:p}],y={id:v.id,params:{unitId:x,mutations:[]}};y.params.mutations.push({t:"r",len:o===A.LEFT?f-1:f,segmentId:g}),I.dataStream.length&&y.params.mutations.push({t:"i",body:I,len:I.dataStream.length,line:0,segmentId:g}),y.params.mutations.push({t:"r",len:1,segmentId:g}),y.params.mutations.push({t:"d",len:_+1-S,line:0,segmentId:g});const U=i.syncExecuteCommand(y.id,y.params);return e.replaceTextRanges(D),U?(s.pushUndoRedo({unitID:x,undoMutations:[{id:v.id,params:U}],redoMutations:[{id:v.id,params:y.params}],undo(){return i.syncExecuteCommand(v.id,U),e.replaceTextRanges([c]),!0},redo(){return i.syncExecuteCommand(v.id,y.params),e.replaceTextRanges(D),!0}}),!0):!1}};function Dt(r,t,e){const{textRuns:n}=r,i=r.dataStream.substring(t,e);if(n==null)return{dataStream:i};const s=[];for(const o of n){const{st:c,ed:l}=o;l<=t||c>=e||(c<t?s.push({...o,st:0,ed:l-t}):l>e?s.push({...o,st:c-t,ed:e-t}):s.push({...o,st:c-t,ed:l-t}))}return{dataStream:i,textRuns:s}}function Xe(r,t){let e=r.endOffset;for(const i of t){const{startOffset:s,endOffset:o}=i;s==null||o==null||o<=r.endOffset&&(e-=o-s)}return[{startOffset:e,endOffset:e,style:r.style}]}class we{constructor(){C(this,"_previousActiveRange",null);C(this,"_undoMutationParamsCache",[]);C(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}setActiveRange(t){this._previousActiveRange=t}pushUndoRedoMutationParams(t,e){this._undoMutationParamsCache.push(t),this._redoMutationParamsCache.push(e)}fetchComposedUndoRedoMutationParams(t){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null)return null;const{unitId:e}=this._undoMutationParamsCache[0],{segmentId:n,startOffset:i,collapsed:s}=this._previousActiveRange,o={unitId:e,mutations:[]},c={unitId:e,mutations:[]};return s?(o.mutations.push({t:"r",len:i,segmentId:n}),c.mutations.push({t:"r",len:i,segmentId:n})):(i>0&&o.mutations.push({t:"r",len:i,segmentId:n}),o.mutations.push(this._undoMutationParamsCache[0].mutations.find(l=>l.t==="i")),c.mutations.push(...oe(this._previousActiveRange,n))),t.length&&(o.mutations.push({t:"d",len:t.length,line:0,segmentId:n}),c.mutations.push({t:"i",body:{dataStream:t},len:t.length,line:0,segmentId:n})),{redoMutationParams:c,undoMutationParams:o,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Le={id:"doc.command.ime-input",type:a.CommandType.COMMAND,handler:async(r,t)=>{const{unitId:e,newText:n,oldTextLen:i,range:s,segmentId:o,textRanges:c,isCompositionEnd:l}=t,u=r.get(a.ICommandService),d=r.get(a.IUndoRedoService),f=r.get(m.TextSelectionManagerService),h=r.get(we),g={id:v.id,params:{unitId:e,mutations:[]}};s.collapsed?g.params.mutations.push({t:"r",len:s.startOffset,segmentId:o}):g.params.mutations.push(...oe(s,o)),i>0&&g.params.mutations.push({t:"d",len:i,line:0,segmentId:o}),g.params.mutations.push({t:"i",body:{dataStream:n},len:n.length,line:0,segmentId:o});const p=u.syncExecuteCommand(g.id,g.params);if(h.pushUndoRedoMutationParams(p,g.params),f.replaceTextRanges(c),l){if(p){const S=h.fetchComposedUndoRedoMutationParams(n);if(S==null)return!1;const{undoMutationParams:_,redoMutationParams:I,previousActiveRange:O}=S;return d.pushUndoRedo({unitID:e,undoMutations:[{id:v.id,params:_}],redoMutations:[{id:v.id,params:I}],undo(){return u.syncExecuteCommand(v.id,_),f.replaceTextRanges([O]),!0},redo(){return u.syncExecuteCommand(v.id,I),f.replaceTextRanges(c),!0}}),!0}}else return!!p;return!1}},G={id:"doc.command.set-inline-format-bold",type:a.CommandType.COMMAND,handler:async()=>!0},q={id:"doc.command.set-inline-format-italic",type:a.CommandType.COMMAND,handler:async()=>!0},Z={id:"doc.command.set-inline-format-underline",type:a.CommandType.COMMAND,handler:async()=>!0},J={id:"doc.command.set-inline-format-strikethrough",type:a.CommandType.COMMAND,handler:async()=>!0},B={id:"doc.command.set-inline-format-subscript",type:a.CommandType.COMMAND,handler:async()=>!0},k={id:"doc.command.set-inline-format-superscript",type:a.CommandType.COMMAND,handler:async()=>!0},W={id:"doc.command.set-inline-format-fontsize",type:a.CommandType.COMMAND,handler:async()=>!0},H={id:"doc.command.set-inline-format-font-family",type:a.CommandType.COMMAND,handler:async()=>!0},Q={id:"doc.command.set-inline-format-text-color",type:a.CommandType.COMMAND,handler:async()=>!0},qe={[G.id]:"bl",[q.id]:"it",[Z.id]:"ul",[J.id]:"st",[W.id]:"fs",[H.id]:"ff",[Q.id]:"cl",[B.id]:"va",[k.id]:"va"},Ae={id:"doc.command.set-inline-format",type:a.CommandType.COMMAND,handler:async(r,t)=>{const{segmentId:e,value:n,preCommandId:i}=t,s=r.get(a.IUndoRedoService),o=r.get(a.ICommandService),c=r.get(m.TextSelectionManagerService),l=r.get(a.IUniverInstanceService),u=c.getSelections();if(!Array.isArray(u)||u.length===0)return!1;let d=l.getCurrentUniverDocInstance(),f=d.getUnitId();f===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(d=l.getUniverDocInstance(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),f=d.getUnitId());let h;switch(i){case G.id:case q.id:case Z.id:case J.id:case B.id:case k.id:{h=bt(d.getBody().textRuns,i,u);break}case W.id:case H.id:{h=n;break}case Q.id:{h={rgb:n};break}default:throw new Error(`Unknown command: ${i} in handleInlineFormat`)}const g={id:v.id,params:{unitId:f,mutations:[]}},p=new a.MemoryCursor;p.reset();for(const I of u){const{startOffset:O,endOffset:x}=I,D={dataStream:"",textRuns:[{st:0,ed:x-O,ts:{[qe[i]]:h}}]},y=O-p.cursor;y!==0&&g.params.mutations.push({t:"r",len:y,segmentId:e}),g.params.mutations.push({t:"r",body:D,len:x-O,segmentId:e}),p.reset(),p.moveCursor(x)}const S=o.syncExecuteCommand(g.id,g.params),_=[G.id,W.id,H.id,B.id,k.id];return _.includes(i)&&c.refreshSelection(),S?(s.pushUndoRedo({unitID:f,undoMutations:[{id:v.id,params:S}],redoMutations:[{id:v.id,params:g.params}],undo(){return o.syncExecuteCommand(v.id,S),_.includes(i)&&c.refreshSelection(),!0},redo(){return o.syncExecuteCommand(v.id,g.params),_.includes(i)&&c.refreshSelection(),!0}}),!0):!1}};function Tt(r){return r!==null&&typeof r=="object"}function bt(r,t,e){let n=0,i=0;const s=qe[t];for(;n!==r.length&&i!==e.length;){const{startOffset:o,endOffset:c}=e[i],{st:l,ed:u,ts:d}=r[n];if(c<=l)i++;else if(u<=o)n++;else{if((d==null?void 0:d[s])==null){if(/bl|it/.test(s))return a.BooleanNumber.TRUE;if(/ul|st/.test(s))return{s:a.BooleanNumber.TRUE};if(/va/.test(s))return t===B.id?a.BaselineOffset.SUBSCRIPT:a.BaselineOffset.SUPERSCRIPT}if(Tt(d==null?void 0:d[s])&&d[s].s===a.BooleanNumber.FALSE)return{s:a.BooleanNumber.TRUE};if(t===B.id&&(d==null?void 0:d[s])!==a.BaselineOffset.SUBSCRIPT)return a.BaselineOffset.SUBSCRIPT;if(t===k.id&&(d==null?void 0:d[s])!==a.BaselineOffset.SUPERSCRIPT)return a.BaselineOffset.SUPERSCRIPT;if((d==null?void 0:d[s])===a.BooleanNumber.FALSE)return a.BooleanNumber.TRUE;n++}}return/bl|it/.test(s)?a.BooleanNumber.FALSE:/ul|st/.test(s)?{s:a.BooleanNumber.FALSE}:a.BaselineOffset.NORMAL}const Ze={id:"doc.command.bullet-list",type:a.CommandType.COMMAND,handler:r=>r.get(a.ICommandService).syncExecuteCommand(Be.id,{listType:a.PresetListType.BULLET_LIST})},Je={id:"doc.command.order-list",type:a.CommandType.COMMAND,handler:r=>r.get(a.ICommandService).syncExecuteCommand(Be.id,{listType:a.PresetListType.ORDER_LIST})},Be={id:"doc.command.list-operation",type:a.CommandType.COMMAND,handler:(r,t)=>{var x;const e=r.get(m.TextSelectionManagerService),n=r.get(a.IUniverInstanceService),i=r.get(a.ICommandService),s=r.get(a.IUndoRedoService),{listType:o}=t,c=n.getCurrentUniverDocInstance(),l=e.getActiveRange(),u=(x=c.getBody())==null?void 0:x.paragraphs;if(l==null||u==null)return!1;const d=xt(l,u),{segmentId:f}=l,h=c.getUnitId(),g=d.every(D=>{var y;return((y=D.bullet)==null?void 0:y.listType)===o}),p=6;let S=a.Tools.generateRandomId(p);if(d.length===1){const D=u.indexOf(d[0]),y=u[D-1],U=u[D+1];y&&y.bullet&&y.bullet.listType===o?S=y.bullet.listId:U&&U.bullet&&U.bullet.listType===o&&(S=U.bullet.listId)}const _={id:v.id,params:{unitId:h,mutations:[]}},I=new a.MemoryCursor;I.reset();for(const D of d){const{startIndex:y}=D;_.params.mutations.push({t:"r",len:y-I.cursor,segmentId:f});const U={...D.paragraphStyle,hanging:void 0,indentStart:void 0};_.params.mutations.push({t:"r",len:1,body:{dataStream:"",paragraphs:[g?{paragraphStyle:U,startIndex:0}:{...D,startIndex:0,bullet:{...D.bullet??{nestingLevel:0,textStyle:{fs:20}},listType:o,listId:S}}]},segmentId:f,coverType:a.UpdateDocsAttributeType.REPLACE}),I.moveCursorTo(y+1)}const O=i.syncExecuteCommand(_.id,_.params);return e.refreshSelection(),O&&s.pushUndoRedo({unitID:h,undoMutations:[{id:v.id,params:O}],redoMutations:[{id:v.id,params:_.params}],undo(){return i.syncExecuteCommand(v.id,O),e.refreshSelection(),!0},redo(){return i.syncExecuteCommand(v.id,_.params),e.refreshSelection(),!0}}),!0}};function xt(r,t){const{startOffset:e,endOffset:n}=r,i=[];let s=-1;for(const o of t){const{startIndex:c}=o;(e>s&&e<=c||n>s&&n<=c||c>=e&&c<=n)&&i.push(o),s=c}return i}const Qe={id:"doc.command-replace-content",type:a.CommandType.COMMAND,handler:async(r,t)=>{var p;const{unitId:e,body:n,textRanges:i,segmentId:s=""}=t,o=r.get(a.IUniverInstanceService),c=r.get(a.ICommandService),l=r.get(m.TextSelectionManagerService),u=r.get(a.IUndoRedoService),d=(p=o.getUniverDocInstance(e))==null?void 0:p.getSnapshot().body,f=l.getSelections();if(d==null||!Array.isArray(f)||f.length===0)return!1;const h=tt(e,s,d,n),g=c.syncExecuteCommand(h.id,h.params);return l.replaceTextRanges(i),g?(u.pushUndoRedo({unitID:e,undoMutations:[{id:v.id,params:g}],redoMutations:[{id:v.id,params:h.params}],undo(){return c.syncExecuteCommand(v.id,g),l.replaceTextRanges(f),!0},redo(){return c.syncExecuteCommand(v.id,h.params),l.replaceTextRanges(i),!0}}),!0):!1}},et={id:"doc.command-cover-content",type:a.CommandType.COMMAND,handler:async(r,t)=>{var d;const{unitId:e,body:n,segmentId:i=""}=t,s=r.get(a.IUniverInstanceService),o=r.get(a.ICommandService),c=r.get(a.IUndoRedoService),l=(d=s.getUniverDocInstance(e))==null?void 0:d.getSnapshot().body;if(l==null)return!1;const u=tt(e,i,l,n);return o.syncExecuteCommand(u.id,u.params),c.clearUndoRedo(e),!0}};function tt(r,t,e,n){const i={id:v.id,params:{unitId:r,mutations:[]}},s=(e==null?void 0:e.dataStream.length)-2;return s>0&&i.params.mutations.push({t:"d",len:s,line:0,segmentId:t}),n.dataStream.length>0&&i.params.mutations.push({t:"i",body:n,len:n.dataStream.length,line:0,segmentId:t}),i}const $={id:"doc.operation.move-cursor",type:a.CommandType.OPERATION,handler:(r,t)=>!!t},F={id:"doc.operation.move-selection",type:a.CommandType.OPERATION,handler:(r,t)=>!!t},Ut=(r,t)=>{const e=r.get(a.IUniverInstanceService).getUniverDocInstance(t.unitId),n=(e==null?void 0:e.zoomRatio)||1;return{...a.Tools.deepClone(t),zoomRatio:n}},V={id:"doc.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(r,t)=>{const e=r.get(a.IUniverInstanceService).getUniverDocInstance(t.unitId);if(!e)return!1;const n=e.getSnapshot();return n.settings==null?n.settings={zoomRatio:t.zoomRatio}:n.settings.zoomRatio=t.zoomRatio,!0}},nt={type:a.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(r,t)=>{const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService);let s=i.getCurrentUniverDocInstance().getUnitId(),o=1;if(t&&(s=t.documentId??s,o=t.zoomRatio??o),!i.getUniverDocInstance(s))return!1;const l={zoomRatio:o,unitId:s},u=Ut(r,l);return e.syncExecuteCommand(V.id,l)?(n.pushUndoRedo({unitID:s,undoMutations:[{id:V.id,params:u}],redoMutations:[{id:V.id,params:l}]}),!0):!1}},it={id:"doc.operation.select-all",type:a.CommandType.COMMAND,handler:async r=>{const t=r.get(a.IUniverInstanceService),e=r.get(m.TextSelectionManagerService),n=t.getCurrentUniverDocInstance().getSnapshot().body;if(n==null)return!1;const i=[{startOffset:0,endOffset:n.dataStream.length-2}];return e.replaceTextRanges(i),!0}},Et=10,Pt=6;function Nt(){return a.Tools.generateRandomId(Pt)}function wt(r){const t=r.match(/data-copy-id="([^\s]+)"/);return t&&t[1]?t[1]:null}class Lt{constructor(){C(this,"_cache",new a.LRUMap(Et))}set(t,e){this._cache.set(t,e)}get(t){return this._cache.get(t)}clear(){this._cache.clear()}}const rt=new Lt;function At(r){const t=r.style,e={};for(let n=0;n<t.length;n++){const i=t[n],s=t.getPropertyValue(i);switch(i){case"margin-top":{const o=parseInt(s);e.spaceAbove=/pt/.test(s)?$e(o):o;break}case"margin-bottom":{const o=parseInt(s);e.spaceBelow=/pt/.test(s)?$e(o):o;break}}}return Object.getOwnPropertyNames(e).length?e:null}function $e(r){return r/.75}function Fe(r){const t=r.style,e={},n=r.tagName.toLowerCase();switch(n){case"b":case"em":case"strong":{e.bl=a.BooleanNumber.TRUE;break}case"s":{e.st={s:a.BooleanNumber.TRUE};break}case"u":{e.ul={s:a.BooleanNumber.TRUE};break}case"i":{e.it=a.BooleanNumber.TRUE;break}case"sub":case"sup":{e.va=n==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}for(let i=0;i<t.length;i++){const s=t[i],o=t.getPropertyValue(s);switch(s){case"font-family":{e.ff=o;break}case"font-size":{const c=parseInt(o);Number.isNaN(c)||(e.fs=/pt$/.test(o)?$e(c):c);break}case"font-style":{o==="italic"&&(e.it=a.BooleanNumber.TRUE);break}case"font-weight":{Number(o)>400&&(e.bl=a.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(o)?e.ul={s:a.BooleanNumber.TRUE}:/overline/.test(o)?e.ol={s:a.BooleanNumber.TRUE}:/line-through/.test(o)&&(e.st={s:a.BooleanNumber.TRUE});break}case"color":{const c=new a.ColorKit(o);c.isValid&&(e.cl={rgb:c.toRgbString()});break}case"background-color":{const c=new a.ColorKit(o);c.isValid&&(e.bg={rgb:c.toRgbString()});break}}}return e}function Bt(r){const t=new DOMParser,e=`<x-univer id="univer-root">${r}</x-univer>`;return t.parseFromString(e,"text/html").querySelector("#univer-root")}function st(r,t){const e=r.tagName.toLowerCase();return typeof t=="string"?e===t:Array.isArray(t)?t.some(n=>n===e):t(r)}const De=class De{constructor(){C(this,"_styleCache",new Map);C(this,"_styleRules",[]);C(this,"_afterProcessRules",[])}static use(t){if(this._pluginList.includes(t))throw new Error(`Univer paste plugin ${t.name} already added`);this._pluginList.push(t)}convert(t){const e=De._pluginList.find(s=>s.checkPasteType(t)),n=Bt(t),i={dataStream:"",textRuns:[]};return e&&(this._styleRules=[...e.stylesRules],this._afterProcessRules=[...e.afterProcessRules]),this._styleCache.clear(),this._process(null,n==null?void 0:n.childNodes,i),this._styleCache.clear(),this._styleRules=[],this._afterProcessRules=[],i}_process(t,e,n){var i;for(const s of e)if(s.nodeType===Node.TEXT_NODE){const o=(i=s.nodeValue)==null?void 0:i.replace(/[\r\n]/g,"");let c;t&&this._styleCache.has(t)&&(c=this._styleCache.get(t)),n.dataStream+=o,c&&Object.getOwnPropertyNames(c).length&&n.textRuns.push({st:n.dataStream.length-o.length,ed:n.dataStream.length,ts:c})}else if(s.nodeType===Node.ELEMENT_NODE){const o=t?this._styleCache.get(t):{},c=this._styleRules.find(({filter:f})=>st(s,f)),l=c?c.getStyle(s):Fe(s);this._styleCache.set(s,{...o,...l});const{childNodes:u}=s;this._process(s,u,n);const d=this._afterProcessRules.find(({filter:f})=>st(s,f));d&&d.handler(n,s)}}};C(De,"_pluginList",[]);let ee=De;const $t={name:"univer-doc-paste-plugin-lark",checkPasteType(r){return/lark-record-clipboard/i.test(r)},stylesRules:[{filter:["s"],getStyle(r){const t=Fe(r);return{st:{s:a.BooleanNumber.TRUE},...t}}}],afterProcessRules:[{filter(r){return r.tagName==="DIV"&&/ace-line/i.test(r.className)},handler(r){r.paragraphs==null&&(r.paragraphs=[]),r.paragraphs.push({startIndex:r.dataStream.length}),r.dataStream+="\r"}}]},Ft={name:"univer-doc-paste-plugin-word",checkPasteType(r){return/word|mso/i.test(r)},stylesRules:[{filter:["b"],getStyle(r){const t=Fe(r);return{bl:a.BooleanNumber.TRUE,...t}}}],afterProcessRules:[{filter(r){return r.tagName==="P"&&/mso/i.test(r.className)},handler(r,t){r.paragraphs==null&&(r.paragraphs=[]);const e={startIndex:r.dataStream.length},n=At(t);n&&(e.paragraphStyle=n),r.paragraphs.push(e),r.dataStream+="\r"}}]};function jt(r,t){const{st:e,ed:n,ts:i={}}=t,{ff:s,fs:o,it:c,bl:l,ul:u,st:d,ol:f,bg:h,cl:g,va:p}=i;let S=r.slice(e,n);const _=[];return c===a.BooleanNumber.TRUE&&(S=`<i>${S}</i>`),p===a.BaselineOffset.SUPERSCRIPT?S=`<sup>${S}</sup>`:p===a.BaselineOffset.SUBSCRIPT&&(S=`<sub>${S}</sub>`),(u==null?void 0:u.s)===a.BooleanNumber.TRUE&&(S=`<u>${S}</u>`),(d==null?void 0:d.s)===a.BooleanNumber.TRUE&&(S=`<s>${S}</s>`),l===a.BooleanNumber.TRUE&&(S=`<strong>${S}</strong>`),s&&_.push(`font-family: ${s}`),g&&_.push(`color: ${g.rgb}`),o&&_.push(`font-size: ${o}px`),f&&_.push("text-decoration: overline"),h&&_.push(`background: ${h.rgb}`),_.length?`<span style="${_.join(";")}">${S}</span>`:S}function at(r,t=!0){const{dataStream:e,textRuns:n=[],paragraphs:i=[]}=r;let s=0;const o=[],c=[];for(const l of n){const{st:u,ed:d}=l;if(u!==s&&o.push(e.slice(s,u)),o.push(jt(e,l)),s=d,t)for(const f of i){const{startIndex:h,paragraphStyle:g={}}=f;if(h>=u&&h<=d){const{spaceAbove:p,spaceBelow:S}=g,_=[];p!=null&&(typeof p=="number"?_.push(`margin-top: ${p}px`):_.push(`margin-top: ${p.v}px`)),S!=null&&(typeof S=="number"?_.push(`margin-bottom: ${S}px`):_.push(`margin-bottom: ${S.v}px`)),c.push(`<p className="UniverNormal" ${_.length?`style="${_.join(";")}"`:""}>${o.join("")}</p>`),o.length=0}}}return c.join("")+o.join("")}class kt{convert(t){if(t.length===0)throw new Error("The bodyList length at least to be 1");if(t.length===1)return at(t[0]);let e="";for(const n of t)e+='<p className="UniverNormal">',e+=at(n,!1),e+="</p>";return e}}var Vt=Object.defineProperty,zt=Object.getOwnPropertyDescriptor,Gt=(r,t,e,n)=>{for(var i=n>1?void 0:n?zt(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&Vt(t,e,i),i},ot=(r,t)=>(e,n)=>t(e,n,r);ee.use(Ft),ee.use($t);function Wt(r){const t=r.replace(/\n/g,"\r"),e=[];for(let n=0;n<t.length;n++)t[n]==="\r"&&e.push({startIndex:n});return{dataStream:t,paragraphs:e}}const ct=b.createIdentifier("doc.clipboard-service");let je=class extends a.Disposable{constructor(t,e){super();C(this,"_clipboardHooks",[]);C(this,"_htmlToUDM",new ee);C(this,"_umdToHtml",new kt);this._currentUniverService=t,this._clipboardInterfaceService=e}async queryClipboardData(){const t=await this._clipboardInterfaceService.read();if(t.length===0)return Promise.reject();try{let e="",n="";for(const s of t)for(const o of s.types)o===T.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await s.getType(o).then(c=>c&&c.text()):o===T.HTML_CLIPBOARD_MIME_TYPE&&(e=await s.getType(o).then(c=>c&&c.text()));if(!e)return Wt(n);const i=wt(e);if(i){const s=rt.get(i);if(s)return s}return this._htmlToUDM.convert(e)}catch(e){return Promise.reject(e)}}async setClipboardData(t){const e=Nt(),n=t.length>1?t.map(s=>s.dataStream).join(`
|
|
2
|
+
`):t[0].dataStream;let i=this._umdToHtml.convert(t);return t.length===1&&(i=i.replace(/(<[a-z]+)/,(s,o)=>`${o} data-copy-id="${e}"`),rt.set(e,t[0])),this._clipboardInterfaceService.write(n,i)}addClipboardHook(t){return this._clipboardHooks.push(t),a.toDisposable(()=>{const e=this._clipboardHooks.indexOf(t);e>-1&&this._clipboardHooks.splice(e,1)})}};je=Gt([ot(0,a.IUniverInstanceService),ot(1,T.IClipboardInterfaceService)],je);var Ht=Object.defineProperty,Kt=Object.getOwnPropertyDescriptor,Yt=(r,t,e,n)=>{for(var i=n>1?void 0:n?Kt(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&Ht(t,e,i),i},K=(r,t)=>(e,n)=>t(e,n,r);let he=class extends a.Disposable{constructor(r,t,e,n,i,s){super(),this._logService=r,this._commandService=t,this._currentUniverService=e,this._docClipboardService=n,this._textSelectionManagerService=i,this._contextService=s,this._commandExecutedListener(),this.initialize()}initialize(){[de,ue,me].forEach(r=>this.disposeWithMe(this._commandService.registerMultipleCommand(r))),[Ye,ge].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r)))}_commandExecutedListener(){const r=[ue.id,de.id,me.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(r.includes(t.id)&&!(!this._contextService.getContextValue(a.FOCUSING_DOC)&&!this._contextService.getContextValue(a.FOCUSING_EDITOR)))switch(t.id){case me.id:{this._handlePaste();break}case de.id:{this._handleCopy();break}case ue.id:{this._handleCut();break}default:throw new Error(`Unhandled command ${t.id}`)}}))}async _handlePaste(){const{_docClipboardService:r}=this,{segmentId:t,endOffset:e,style:n}=this._textSelectionManagerService.getActiveRange()??{},i=this._textSelectionManagerService.getSelections();if(t==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),!(e==null||i==null))try{const s=await r.queryClipboardData();let o=e;for(const l of i){const{startOffset:u,endOffset:d}=l;u==null||d==null||d<=e&&(o+=s.dataStream.length-(d-u))}const c=[{startOffset:o,endOffset:o,style:n}];this._commandService.executeCommand(Ye.id,{body:s,segmentId:t,textRanges:c})}catch{this._logService.error("[DocClipboardController] clipboard is empty")}}_getDocumentBodyInRanges(){const r=this._textSelectionManagerService.getSelections(),t=this._currentUniverService.getCurrentUniverDocInstance(),e=[];if(r==null)return e;for(const n of r){const{startOffset:i,endOffset:s,collapsed:o}=n;if(o||i==null||s==null)continue;const c=t.sliceBody(i,s);c!=null&&e.push(c)}return e}async _handleCopy(){const{_docClipboardService:r}=this,t=this._getDocumentBodyInRanges();try{r.setClipboardData(t)}catch{this._logService.error("[DocClipboardController] set clipboard failed")}}async _handleCut(){const{segmentId:r,endOffset:t,style:e}=this._textSelectionManagerService.getActiveRange()??{},n=this._textSelectionManagerService.getSelections();if(r==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),!(t==null||n==null)){this._handleCopy();try{let i=t;for(const o of n){const{startOffset:c,endOffset:l}=o;c==null||l==null||l<=t&&(i-=l-c)}const s=[{startOffset:i,endOffset:i,style:e}];this._commandService.executeCommand(ge.id,{segmentId:r,textRanges:s})}catch{this._logService.error("[DocClipboardController] cut content failed")}}}};he=Yt([a.OnLifecycle(a.LifecycleStages.Rendered,he),K(0,a.ILogService),K(1,a.ICommandService),K(2,a.IUniverInstanceService),K(3,ct),K(4,b.Inject(m.TextSelectionManagerService)),K(5,a.IContextService)],he);var Xt=Object.defineProperty,qt=Object.getOwnPropertyDescriptor,Zt=(r,t,e,n)=>{for(var i=n>1?void 0:n?qt(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&Xt(t,e,i),i},ke=(r,t)=>(e,n)=>t(e,n,r);let fe=class extends a.RxDisposable{constructor(r,t,e){super(),this._docSkeletonManagerService=r,this._renderManagerService=t,this._commandService=e,this._initialRenderRefresh(),this._commandExecutedListener()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(N.takeUntil(this.dispose$)).subscribe(r=>{if(r==null)return;const{skeleton:t,unitId:e}=r,n=this._renderManagerService.getRenderById(e);if(n==null)return;const{mainComponent:i}=n;i.changeSkeleton(t),this._recalculateSizeBySkeleton(n,t)})}_recalculateSizeBySkeleton(r,t){var u;const{mainComponent:e,scene:n}=r,i=e,s=(u=t.getSkeletonData())==null?void 0:u.pages;if(s==null)return;let o=0,c=0;for(let d=0,f=s.length;d<f;d++){const h=s[d],{pageWidth:g,pageHeight:p}=h;i.pageLayoutType===M.PageLayoutType.VERTICAL?(c+=p,c+=i.pageMarginTop,d===f-1&&(c+=i.pageMarginTop),o=Math.max(o,g)):i.pageLayoutType===M.PageLayoutType.HORIZONTAL&&(o+=g,d!==f-1&&(o+=i.pageMarginLeft),c=Math.max(c,p))}i.resize(o,c),[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(r.unitId)||n.resize(o,c)}_commandExecutedListener(){const r=[v.id],t=[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var n;if(r.includes(e.id)){const i=e.params,{unitId:s}=i,o=this._docSkeletonManagerService.getSkeletonByUnitId(s);if(o==null)return;const{skeleton:c}=o,l=this._renderManagerService.getRenderById(s);if(l==null)return;if(c.calculate(),t.includes(s)){(n=l.mainComponent)==null||n.makeDirty();return}this._recalculateSizeBySkeleton(l,c)}}))}};fe=Zt([a.OnLifecycle(a.LifecycleStages.Rendered,fe),ke(0,b.Inject(m.DocSkeletonManagerService)),ke(1,M.IRenderManagerService),ke(2,a.ICommandService)],fe);var Jt=Object.defineProperty,Qt=Object.getOwnPropertyDescriptor,en=(r,t,e,n)=>{for(var i=n>1?void 0:n?Qt(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&Jt(t,e,i),i},te=(r,t)=>(e,n)=>t(e,n,r);let pe=class extends a.Disposable{constructor(t,e,n,i,s){super();C(this,"_liquid",new M.Liquid);C(this,"_pageMarginCache",new Map);this._docSkeletonManagerService=t,this._currentUniverService=e,this._renderManagerService=n,this._commandService=i,this._floatingObjectManagerService=s,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh(),this._updateOnPluginChange()}_updateOnPluginChange(){this._floatingObjectManagerService.pluginUpdate$.subscribe(t=>{const e=this._docSkeletonManagerService.getCurrent();if(e==null)return;const{unitId:n,skeleton:i}=e,s=this._renderManagerService.getRenderById(n);if(s==null)return;const{mainComponent:o,components:c,scene:l}=s,u=o,{left:d,top:f}=u;t.forEach(h=>{const{unitId:g,subUnitId:p,floatingObjectId:S,floatingObject:_}=h,{left:I=0,top:O=0,width:x=0,height:D=0,angle:y,flipX:U,flipY:E,skewX:P,skewY:w}=_,R=this._pageMarginCache.get(S),j=(R==null?void 0:R.marginLeft)||0,L=(R==null?void 0:R.marginTop)||0;i==null||i.getViewModel().getDataModel().updateDrawing(S,{left:I-d-j,top:O-f-L,height:D,width:x})}),i==null||i.calculate(),o==null||o.makeDirty()})}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(t=>{if(t==null)return;const{skeleton:e,unitId:n}=t,i=this._renderManagerService.getRenderById(n);if(i==null)return;const{mainComponent:s}=i;s.changeSkeleton(e),this._refreshFloatingObject(n,e,i)})}_commandExecutedListener(){const t=[v.id,V.id],e=[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{var i;if(t.includes(n.id)){const s=n.params,{unitId:o}=s,c=this._docSkeletonManagerService.getCurrent();if(c==null)return;const{unitId:l,skeleton:u}=c;if(o!==l)return;const d=this._renderManagerService.getRenderById(l);if(d==null)return;if(e.includes(l)){(i=d.mainComponent)==null||i.makeDirty();return}this._refreshFloatingObject(l,u,d)}}))}_refreshFloatingObject(t,e,n){const i=e==null?void 0:e.getSkeletonData(),{mainComponent:s,scene:o}=n,c=s;if(!i)return;const{left:l,top:u,pageLayoutType:d,pageMarginLeft:f,pageMarginTop:h}=c,{pages:g}=i,p=[];o.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let S=0,_=g.length;S<_;S++){const I=g[S],{skeDrawings:O,marginLeft:x,marginTop:D}=I;this._liquid.translatePagePadding(I),O.forEach(y=>{const{aLeft:U,aTop:E,height:P,width:w,objectId:R}=y;p.push({unitId:t,subUnitId:a.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:R,floatingObject:{left:U+l+this._liquid.x,top:E+u+this._liquid.y,width:w,height:P}}),this._pageMarginCache.set(R,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.translatePage(I,d,f,h)}this._floatingObjectManagerService.BatchAddOrUpdate(p)}};pe=en([a.OnLifecycle(a.LifecycleStages.Steady,pe),te(0,b.Inject(m.DocSkeletonManagerService)),te(1,a.IUniverInstanceService),te(2,M.IRenderManagerService),te(3,a.ICommandService),te(4,a.IFloatingObjectManagerService)],pe);var tn=Object.defineProperty,nn=Object.getOwnPropertyDescriptor,rn=(r,t,e,n)=>{for(var i=n>1?void 0:n?nn(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&tn(t,e,i),i},Y=(r,t)=>(e,n)=>t(e,n,r);let Se=class extends a.Disposable{constructor(t,e,n,i,s,o){super();C(this,"_previousIMEContent","");C(this,"_previousIMERange");C(this,"_onStartSubscription");C(this,"_onUpdateSubscription");C(this,"_onEndSubscription");this._docSkeletonManagerService=t,this._currentUniverService=e,this._renderManagerService=n,this._textSelectionRenderManager=i,this._imeInputManagerService=s,this._commandService=o,this._initialize()}dispose(){var t,e,n;(t=this._onStartSubscription)==null||t.unsubscribe(),(e=this._onUpdateSubscription)==null||e.unsubscribe(),(n=this._onEndSubscription)==null||n.unsubscribe()}_initialize(){this._initialOnCompositionstart(),this._initialOnCompositionUpdate(),this._initialOnCompositionend()}_initialOnCompositionstart(){this._onStartSubscription=this._textSelectionRenderManager.onCompositionstart$.subscribe(t=>{if(t==null)return;const{activeRange:e}=t;e!=null&&(this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(a.Tools.deepClone(e)),this._previousIMERange=e)})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._textSelectionRenderManager.onCompositionupdate$.subscribe(async t=>{this._updateContent(t,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._textSelectionRenderManager.onCompositionend$.subscribe(t=>{this._updateContent(t,!1)})}async _updateContent(t,e){var p;const n=(p=this._docSkeletonManagerService.getCurrent())==null?void 0:p.skeleton;if(this._previousIMERange==null||t==null||n==null)return;const i=this._currentUniverService.getCurrentUniverDocInstance(),{event:s,activeRange:o}=t,{startOffset:c,segmentId:l,style:u}=this._previousIMERange;if(n==null||o==null)return;const f=s.data;if(f===this._previousIMEContent&&e)return;const h=f.length,g=[{startOffset:c+h,endOffset:c+h,style:u}];await this._commandService.executeCommand(Le.id,{unitId:i.getUnitId(),newText:f,oldTextLen:this._previousIMEContent.length,range:this._previousIMERange,textRanges:g,isCompositionEnd:!e,segmentId:l}),e?(this._previousIMERange.collapsed||(this._previousIMERange.collapsed=!0),this._previousIMEContent=f):this._resetIME()}_resetIME(){this._previousIMEContent="",this._previousIMERange=null,this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(null)}_getDocObject(){return X(this._currentUniverService,this._renderManagerService)}};Se=rn([a.OnLifecycle(a.LifecycleStages.Rendered,Se),Y(0,b.Inject(m.DocSkeletonManagerService)),Y(1,a.IUniverInstanceService),Y(2,M.IRenderManagerService),Y(3,M.ITextSelectionRenderManager),Y(4,b.Inject(we)),Y(5,a.ICommandService)],Se);var sn=Object.defineProperty,an=Object.getOwnPropertyDescriptor,on=(r,t,e,n)=>{for(var i=n>1?void 0:n?an(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&sn(t,e,i),i},lt=(r,t)=>(e,n)=>t(e,n,r);let _e=class extends a.Disposable{constructor(r,t){super(),this._textSelectionManagerService=r,this._commandService=t,this._commandExecutedListener()}_commandExecutedListener(){const r=[G.id,q.id,Z.id,J.id,B.id,k.id,W.id,H.id,Q.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{r.includes(t.id)&&this._handleInlineFormat(t)}))}_handleInlineFormat(r){const{segmentId:t}=this._textSelectionManagerService.getActiveRange()??{};t!=null&&this._commandService.executeCommand(Ae.id,{segmentId:t,preCommandId:r.id,...r.params??{}})}};_e=on([a.OnLifecycle(a.LifecycleStages.Rendered,_e),lt(0,b.Inject(m.TextSelectionManagerService)),lt(1,a.ICommandService)],_e);var cn=Object.defineProperty,ln=Object.getOwnPropertyDescriptor,dn=(r,t,e,n)=>{for(var i=n>1?void 0:n?ln(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&cn(t,e,i),i},ne=(r,t)=>(e,n)=>t(e,n,r);let ve=class extends a.Disposable{constructor(t,e,n,i,s){super();C(this,"_onInputSubscription");this._docSkeletonManagerService=t,this._currentUniverService=e,this._renderManagerService=n,this._textSelectionManagerService=i,this._commandService=s,this._initialize(),this._commandExecutedListener()}dispose(){var t;(t=this._onInputSubscription)==null||t.unsubscribe()}_initialize(){}_commandExecutedListener(){const t=[$.id,F.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!t.includes(e.id))return;const n=e.params;switch(e.id){case $.id:return this._handleMoveCursor(n.direction);case F.id:return this._handleShiftMoveSelection(n.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(t){var S;const e=this._textSelectionManagerService.getActiveRange(),n=this._textSelectionManagerService.getSelections(),i=this._currentUniverService.getCurrentUniverDocInstance(),s=(S=this._docSkeletonManagerService.getCurrent())==null?void 0:S.skeleton,o=this._getDocObject();if(e==null||s==null||o==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d,direction:f}=e;if(n.length>1){let _=1/0,I=-1/0;for(const O of n)_=Math.min(_,O.startOffset),I=Math.max(I,O.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:t===a.Direction.LEFT||t===a.Direction.UP?I:_,endOffset:t===a.Direction.LEFT||t===a.Direction.UP?_:I,style:u}]);return}const h=d||f===M.RANGE_DIRECTION.FORWARD?c:l;let g=d||f===M.RANGE_DIRECTION.FORWARD?l:c;const p=i.getBody().dataStream.length??1/0;if(t===a.Direction.LEFT||t===a.Direction.RIGHT){const _=s.findNodeByCharIndex(g-1),I=s.findNodeByCharIndex(g);g=t===a.Direction.RIGHT?g+I.count:g-((_==null?void 0:_.count)??0),g=Math.min(p-2,Math.max(0,g)),this._textSelectionManagerService.replaceTextRanges([{startOffset:h,endOffset:g,style:u}])}else{const _=s.findNodeByCharIndex(g),I=o.document.getOffsetConfig(),O=this._getTopOrBottomPosition(s,_,t===a.Direction.DOWN);if(O==null){const D=t===a.Direction.UP?0:p-2;if(D===g)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:h,endOffset:D,style:u}]);return}const x=new M.NodePositionConvertToCursor(I,s).getRangePointData(O,O).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:h,endOffset:x.endOffset,style:u}])}}_handleMoveCursor(t){var h;const e=this._textSelectionManagerService.getActiveRange(),n=this._textSelectionManagerService.getSelections(),i=this._currentUniverService.getCurrentUniverDocInstance(),s=(h=this._docSkeletonManagerService.getCurrent())==null?void 0:h.skeleton,o=this._getDocObject();if(e==null||s==null||o==null||n==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d}=e,f=i.getBody().dataStream.length??1/0;if(t===a.Direction.LEFT||t===a.Direction.RIGHT){let g;if(!e.collapsed||n.length>1){let p=1/0,S=-1/0;for(const _ of n)p=Math.min(p,_.startOffset),S=Math.max(S,_.endOffset);g=t===a.Direction.LEFT?p:S}else{const p=s.findNodeByCharIndex(c-1),S=s.findNodeByCharIndex(c);t===a.Direction.LEFT?g=Math.max(0,c-((p==null?void 0:p.count)??0)):g=Math.min(f-2,l+S.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:g,style:u}])}else{const g=s.findNodeByCharIndex(c),p=s.findNodeByCharIndex(l),S=o.document.getOffsetConfig(),_=this._getTopOrBottomPosition(s,t===a.Direction.UP?g:p,t===a.Direction.DOWN);if(_==null){let O;d?O=t===a.Direction.UP?0:f-2:O=t===a.Direction.UP?c:l,this._textSelectionManagerService.replaceTextRanges([{startOffset:O,endOffset:O,style:u}]);return}const I=new M.NodePositionConvertToCursor(S,s).getRangePointData(_,_).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...I,style:u}])}}_getTopOrBottomPosition(t,e,n){if(e==null)return;const i=this._getSpanLeftOffsetInLine(e),s=this._getNextOrPrevLine(e,n);if(s==null)return;const o=this._matchPositionByLeftOffset(t,s,i);if(o!=null)return{...o,isBack:!0}}_getSpanLeftOffsetInLine(t){const e=t.parent;if(e==null)return-1/0;const n=e.left,{left:i}=t;return n+i}_matchPositionByLeftOffset(t,e,n){const i={distance:1/0};for(const s of e.divides){const o=s.left;for(const c of s.spanGroup){const{left:l}=c,u=o+l,d=Math.abs(n-u);d<i.distance&&(i.span=c,i.distance=d)}}if(i.span!=null)return t.findPositionBySpan(i.span)}_getNextOrPrevLine(t,e){var p,S,_,I,O,x,D,y,U,E,P,w;const n=t.parent;if(n==null)return;const i=n.parent;if(i==null)return;const s=i.parent;if(s==null)return;const o=s.lines.indexOf(i);if(o===-1)return;let c;if(e===!0?c=s.lines[o+1]:c=s.lines[o-1],c!=null)return c;const l=s.parent;if(l==null)return;const u=l.columns.indexOf(s);if(u===-1)return;if(e===!0)c=(p=l.columns[u+1])==null?void 0:p.lines[0];else{const R=(_=(S=l.columns)==null?void 0:S[u-1])==null?void 0:_.lines;c=R==null?void 0:R[R.length-1]}if(c!=null)return c;const d=l.parent;if(d==null)return;const f=d.sections.indexOf(l);if(f===-1)return;if(e===!0)c=(O=(I=d.sections[f-1])==null?void 0:I.columns[0])==null?void 0:O.lines[0];else{const R=(D=(x=d.sections)==null?void 0:x[f-1])==null?void 0:D.columns,j=R==null?void 0:R[R.length-1],L=j==null?void 0:j.lines;c=L==null?void 0:L[L.length-1]}if(c!=null)return c;const h=d.parent;if(h==null)return;const g=h.pages.indexOf(d);if(g!==-1){if(e===!0)c=(E=(U=(y=h.pages[g+1])==null?void 0:y.sections[0])==null?void 0:U.columns[0])==null?void 0:E.lines[0];else{const R=(P=h.pages[g-1])==null?void 0:P.sections;if(R==null)return;const j=(w=R[R.length-1])==null?void 0:w.columns,L=j[j.length-1],ut=L==null?void 0:L.lines;c=ut[ut.length-1]}if(c!=null)return c}}_getDocObject(){return X(this._currentUniverService,this._renderManagerService)}};ve=dn([a.OnLifecycle(a.LifecycleStages.Rendered,ve),ne(0,b.Inject(m.DocSkeletonManagerService)),ne(1,a.IUniverInstanceService),ne(2,M.IRenderManagerService),ne(3,b.Inject(m.TextSelectionManagerService)),ne(4,a.ICommandService)],ve);var un=Object.defineProperty,mn=Object.getOwnPropertyDescriptor,gn=(r,t,e,n)=>{for(var i=n>1?void 0:n?mn(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&un(t,e,i),i},ie=(r,t)=>(e,n)=>t(e,n,r);let Ce=class extends a.Disposable{constructor(t,e,n,i,s){super();C(this,"_onInputSubscription");this._docSkeletonManagerService=t,this._currentUniverService=e,this._renderManagerService=n,this._textSelectionRenderManager=i,this._commandService=s,this._initialize(),this._commandExecutedListener()}dispose(){var t;(t=this._onInputSubscription)==null||t.unsubscribe()}_initialize(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async t=>{var p;if(t==null)return;const n=this._currentUniverService.getCurrentUniverDocInstance().getUnitId(),{event:i,content:s="",activeRange:o}=t,c=i,l=(p=this._docSkeletonManagerService.getCurrent())==null?void 0:p.skeleton;if(c.data==null||l==null||!l||!o)return;const{startOffset:u,segmentId:d,style:f}=o,h=s.length,g=[{startOffset:u+h,endOffset:u+h,style:f}];await this._commandService.executeCommand(ce.id,{unitId:n,body:{dataStream:s},range:o,textRanges:g,segmentId:d})})}_commandExecutedListener(){}_getDocObject(){return X(this._currentUniverService,this._renderManagerService)}};Ce=gn([a.OnLifecycle(a.LifecycleStages.Rendered,Ce),ie(0,b.Inject(m.DocSkeletonManagerService)),ie(1,a.IUniverInstanceService),ie(2,M.IRenderManagerService),ie(3,M.ITextSelectionRenderManager),ie(4,a.ICommandService)],Ce);var hn=Object.defineProperty,fn=Object.getOwnPropertyDescriptor,pn=(r,t,e,n)=>{for(var i=n>1?void 0:n?fn(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&hn(t,e,i),i},dt=(r,t)=>(e,n)=>t(e,n,r);const Sn="rgba(198, 198, 198, 1)",_n="rgba(255, 255, 255, 1)";let Ie=class extends a.Disposable{constructor(r,t){super(),this._renderManagerService=r,this._currentUniverService=t,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh()}_initialRenderRefresh(){this._renderManagerService.currentRender$.subscribe(r=>{var s;if(r==null||this._currentUniverService.getUniverDocInstance(r)==null)return;const t=this._renderManagerService.getRenderById(r);if(t==null)return;const{mainComponent:e}=t,n=e,i=(s=n.getSkeleton())==null?void 0:s.getPageSize();n.onPageRenderObservable.add(o=>{if([a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(r))return;const{page:c,pageLeft:l,pageTop:u,ctx:d}=o,{width:f,pageWidth:h,height:g,pageHeight:p}=c;d.save(),d.translate(l-.5,u-.5),M.Rect.drawWith(d,{width:(i==null?void 0:i.width)??h??f,height:(i==null?void 0:i.height)??p??g,strokeWidth:1,stroke:Sn,fill:_n,zIndex:3}),d.restore()})})}_commandExecutedListener(){}};Ie=pn([a.OnLifecycle(a.LifecycleStages.Rendered,Ie),dt(0,M.IRenderManagerService),dt(1,b.Inject(a.IUniverInstanceService))],Ie);var vn=Object.defineProperty,Cn=Object.getOwnPropertyDescriptor,In=(r,t,e,n)=>{for(var i=n>1?void 0:n?Cn(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&vn(t,e,i),i},z=(r,t)=>(e,n)=>t(e,n,r);let Me=class extends a.Disposable{constructor(t,e,n,i,s,o,c){super();C(this,"_moveInObserver");C(this,"_moveOutObserver");C(this,"_downObserver");C(this,"_dblClickObserver");C(this,"_tripleClickObserver");C(this,"_loadedMap",new Set);this._docSkeletonManagerService=t,this._currentUniverService=e,this._commandService=n,this._renderManagerService=i,this._textSelectionRenderManager=s,this._textSelectionManagerService=o,this._layoutService=c,this._renderManagerService.currentRender$.subscribe(l=>{l!=null&&this._currentUniverService.getUniverDocInstance(l)!=null&&(this._loadedMap.has(l)||(this._initialMain(l),this._loadedMap.add(l)))}),this._initialize()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._layoutService&&this.disposeWithMe(this._layoutService.registerContainer(this._textSelectionRenderManager.__getEditorContainer()))}dispose(){this._renderManagerService.getRenderAll().forEach(t=>{const{mainComponent:e}=t;e!=null&&(e.onPointerEnterObserver.remove(this._moveInObserver),e.onPointerLeaveObserver.remove(this._moveOutObserver),e.onPointerDownObserver.remove(this._downObserver),e.onDblclickObserver.remove(this._dblClickObserver),e.onTripleClickObserver.remove(this._tripleClickObserver))})}_initialMain(t){const e=this._getDocObjectById(t);if(e==null)return;const{document:n,scene:i}=e;this._moveInObserver=n.onPointerEnterObserver.add(()=>{n.cursor=M.CURSOR_TYPE.TEXT}),this._moveOutObserver=n.onPointerLeaveObserver.add(()=>{n.cursor=M.CURSOR_TYPE.DEFAULT,i.resetCursor()}),this._downObserver=n==null?void 0:n.onPointerDownObserver.add((s,o)=>{this._currentUniverService.getCurrentUniverDocInstance().getUnitId()!==t&&this._currentUniverService.setCurrentUniverDocInstance(t),this._textSelectionRenderManager.eventTrigger(s),s.button!==2&&o.stopPropagation()}),this._dblClickObserver=n==null?void 0:n.onDblclickObserver.add(s=>{this._textSelectionRenderManager.handleDblClick(s)}),this._tripleClickObserver=n==null?void 0:n.onTripleClickObserver.add(s=>{this._textSelectionRenderManager.handleTripleClick(s)})}_commandExecutedListener(){const t=[V.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var n;if(t.includes(e.id)){const i=e.params,{unitId:s}=i,o=(n=this._textSelectionManagerService.getCurrentSelection())==null?void 0:n.unitId;if(s!==o)return;this._textSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this._docSkeletonManagerService.currentSkeleton$.subscribe(t=>{if(t==null)return;const{unitId:e,skeleton:n}=t,i=this._renderManagerService.getRenderById(e);if(i==null)return;const{scene:s,mainComponent:o}=i;this._textSelectionRenderManager.changeRuntime(n,s,o),this._textSelectionManagerService.setCurrentSelectionNotRefresh({unitId:e,subUnitId:""})})}_getDocObjectById(t){return mt(t,this._renderManagerService)}};Me=In([a.OnLifecycle(a.LifecycleStages.Rendered,Me),z(0,b.Inject(m.DocSkeletonManagerService)),z(1,a.IUniverInstanceService),z(2,a.ICommandService),z(3,M.IRenderManagerService),z(4,M.ITextSelectionRenderManager),z(5,b.Inject(m.TextSelectionManagerService)),z(6,b.Optional(T.LayoutService))],Me);var Mn=Object.defineProperty,On=Object.getOwnPropertyDescriptor,yn=(r,t,e,n)=>{for(var i=n>1?void 0:n?On(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&Mn(t,e,i),i},re=(r,t)=>(e,n)=>t(e,n,r);let Oe=class extends a.Disposable{constructor(t,e,n,i,s){super();C(this,"_initializedRender",new Set);this._docSkeletonManagerService=t,this._currentUniverService=e,this._commandService=n,this._renderManagerService=i,this._textSelectionManagerService=s,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._initialRenderRefresh()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(t=>{if(t==null)return;const{unitId:e}=t,n=this._renderManagerService.getRenderById(e);if(n==null||this._initializedRender.has(e)||[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(e))return;this._initializedRender.add(e);const{scene:i}=n;this.disposeWithMe(a.toDisposable(i.onMouseWheelObserver.add(s=>{if(!s.ctrlKey)return;const o=Math.abs(s.deltaX);let c=o<40?.2:o<80?.4:.2;c*=s.deltaY>0?-1:1,i.scaleX<1&&(c/=2);const l=this._currentUniverService.getCurrentUniverDocInstance(),u=l.zoomRatio;let d=+parseFloat(`${u+c}`).toFixed(1);d=d>=4?4:d<=.1?.1:d,this._commandService.executeCommand(nt.id,{zoomRatio:d,unitId:l.getUnitId()}),s.preventDefault()})))})}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._docSkeletonManagerService.currentSkeletonBefore$.subscribe(t=>{if(t==null)return;const n=this._currentUniverService.getCurrentUniverDocInstance().zoomRatio||1;this._updateViewZoom(n,!1)})))}_commandExecutedListener(){const t=[V.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(t.includes(e.id)){const n=this._currentUniverService.getCurrentUniverDocInstance(),i=e.params,{unitId:s}=i;if(s!==n.getUnitId())return;const o=n.zoomRatio||1;this._updateViewZoom(o)}}))}_updateViewZoom(t,e=!0){var i;const n=this._getDocObject();n!=null&&(n.scene.scale(t,t),this._calculatePagePosition(n,t),e&&this._textSelectionManagerService.refreshSelection(),(i=n.scene.getTransformer())==null||i.hideControl())}_calculatePagePosition(t,e){const{document:n,scene:i}=t,s=i==null?void 0:i.getParent(),{width:o,height:c,pageMarginLeft:l,pageMarginTop:u}=n;if(s==null||o===1/0||c===1/0)return;const{width:d,height:f}=s;let h=0,g=0,p=0,S=0,_=1/0;d>(o+l*2)*e?(h=d/2-o*e/2,h/=e,p=(d-l*2)/e,_=0):(h=l,p=o+l*2,_=(p-d/e)/2),f>c?(g=f/2-c/2,S=(f-u*2)/e):(g=u,S=c+u*2),i.resize(p,S+200),n.translate(h,g);const I=i.getViewport(ae.VIEW_MAIN);if(_!==1/0&&I!=null){const O=I.getBarScroll(_,0).x;I.scrollTo({x:O})}return this}_getDocObject(){return X(this._currentUniverService,this._renderManagerService)}};Oe=yn([a.OnLifecycle(a.LifecycleStages.Rendered,Oe),re(0,b.Inject(m.DocSkeletonManagerService)),re(1,a.IUniverInstanceService),re(2,a.ICommandService),re(3,M.IRenderManagerService),re(4,b.Inject(m.TextSelectionManagerService))],Oe);const Rn={id:Ue.id,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),binding:T.KeyCode.ENTER},Dn={id:Ee.id,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),binding:T.KeyCode.BACKSPACE},Tn={id:Pe.id,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),binding:T.KeyCode.DELETE},bn={id:$.id,binding:T.KeyCode.ARROW_UP,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.UP}},xn={id:$.id,binding:T.KeyCode.ARROW_DOWN,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.DOWN}},Un={id:$.id,binding:T.KeyCode.ARROW_LEFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.LEFT}},En={id:$.id,binding:T.KeyCode.ARROW_RIGHT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.RIGHT}},Pn={id:F.id,binding:T.KeyCode.ARROW_UP|T.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.UP}},Nn={id:F.id,binding:T.KeyCode.ARROW_DOWN|T.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.DOWN}},wn={id:F.id,binding:T.KeyCode.ARROW_LEFT|T.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.LEFT}},Ln={id:F.id,binding:T.KeyCode.ARROW_RIGHT|T.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.RIGHT}},An={id:it.id,binding:T.KeyCode.A|T.MetaKeys.CTRL_COMMAND,preconditions:r=>r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.FOCUSING_EDITOR)};var Bn=Object.defineProperty,$n=Object.getOwnPropertyDescriptor,Fn=(r,t,e,n)=>{for(var i=n>1?void 0:n?$n(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&Bn(t,e,i),i},ye=(r,t)=>(e,n)=>t(e,n,r);m.DocCanvasView=class extends a.RxDisposable{constructor(e,n,i,s){super();C(this,"_scene");C(this,"_currentDocumentModel");C(this,"_loadedMap",new Set);C(this,"_fps$",new N.BehaviorSubject(""));C(this,"fps$",this._fps$.asObservable());this._renderManagerService=e,this._configService=n,this._currentUniverService=i,this._docViewModelManagerService=s,this._initialize()}_initialize(){this._currentUniverService.currentDoc$.pipe(N.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;this._currentDocumentModel=e;const n=e.getUnitId();this._loadedMap.has(n)||(this._addNewRender(),this._loadedMap.add(n))})}dispose(){this._fps$.complete()}_addNewRender(){const e=this._currentDocumentModel,n=e.getUnitId(),i=e.getContainer(),s=e.getParentRenderUnitId();if(i!=null&&s!=null)throw new Error("container or parentRenderUnitId can only exist one");i==null&&s!=null?this._renderManagerService.createRenderWithParent(n,s):this._renderManagerService.createRender(n);const o=this._renderManagerService.getRenderById(n);if(o==null)return;const{scene:c,engine:l}=o;c.openTransformer(),this._scene=c;const u=new M.Viewport(ae.VIEW_MAIN,c,{left:0,top:0,bottom:0,right:0,isWheelPreventDefaultX:!0});c.attachControl(),c.on(M.EVENT_TYPE.wheel,(h,g)=>{const p=h;if(p.ctrlKey){const S=Math.abs(p.deltaX);let _=S<40?.2:S<80?.4:.2;_*=p.deltaY>0?-1:1,c.scaleX<1&&(_/=2),c.scaleX+_>4?c.scale(4,4):c.scaleX+_<.1?c.scale(.1,.1):p.preventDefault()}else u.onMouseWheel(p,g)}),this._configService.getConfig("hasScroll")!==!1&&n!==a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&new M.ScrollBar(u),c.addLayer(new M.Layer(c,[],Te),new M.Layer(c,[],ze)),this._addComponent(o),this._currentDocumentModel.getShouldRenderLoopImmediately()&&l.runRenderLoop(()=>{c.render(),this._fps$.next(Math.round(l.getFps()).toString())}),this._renderManagerService.setCurrent(n)}_addComponent(e){const n=this._scene,i=this._currentDocumentModel,s=new M.Documents(se.MAIN,void 0,{pageMarginLeft:i.documentStyle.marginLeft||0,pageMarginTop:i.documentStyle.marginTop||0});s.zIndex=Ge,e.mainComponent=s,e.components.set(se.MAIN,s),n.addObjects([s],Te)}},m.DocCanvasView=Fn([a.OnLifecycle(a.LifecycleStages.Ready,m.DocCanvasView),ye(0,M.IRenderManagerService),ye(1,a.IConfigService),ye(2,a.IUniverInstanceService),ye(3,b.Inject(m.DocViewModelManagerService))],m.DocCanvasView);var jn=Object.defineProperty,kn=Object.getOwnPropertyDescriptor,Vn=(r,t,e,n)=>{for(var i=n>1?void 0:n?kn(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&jn(t,e,i),i},Re=(r,t)=>(e,n)=>t(e,n,r);const zn={hasScroll:!0},Gn="docs";m.UniverDocsPlugin=(Ve=class extends a.Plugin{constructor(e={},n,i,s,o){super(Gn);C(this,"_config");this._injector=n,this._localeService=i,this._configService=s,this._currentUniverService=o,this._config=Object.assign(zn,e),this._initializeDependencies(n),this._initializeCommands()}initialize(){}_initializeCommands(){[$,F,Ee,Pe,G,q,Z,J,B,k,W,H,Q,Ae,Ue,ce,le,xe,Le,Ne,v,Qe,et,nt,V,be,it,Je,Ze,Be].forEach(e=>{this._injector.get(a.ICommandService).registerCommand(e)}),[bn,xn,En,Un,Pn,Nn,wn,Ln,An,Dn,Tn,Rn].forEach(e=>{this._injector.get(T.IShortcutService).registerShortcut(e)})}onReady(){this.initialize()}_initializeDependencies(e){[[m.DocCanvasView],[m.DocSkeletonManagerService],[m.DocViewModelManagerService],[we],[ct,{useClass:je}],[M.ITextSelectionRenderManager,{useClass:M.TextSelectionRenderManager}],[m.TextSelectionManagerService],[fe],[Ie],[Me],[Ce],[Se],[_e],[he],[ve],[Oe],[pe]].forEach(n=>e.add(n))}},C(Ve,"type",a.PluginType.Doc),Ve),m.UniverDocsPlugin=Vn([Re(1,b.Inject(b.Injector)),Re(2,b.Inject(a.LocaleService)),Re(3,a.IConfigService),Re(4,a.IUniverInstanceService)],m.UniverDocsPlugin),m.BreakLineCommand=Ue,m.BulletListCommand=Ze,m.CoverContentCommand=et,m.DOCS_COMPONENT_DEFAULT_Z_INDEX=Ge,m.DOCS_COMPONENT_HEADER_LAYER_INDEX=ze,m.DOCS_COMPONENT_MAIN_LAYER_INDEX=Te,m.DOCS_VIEW_KEY=se,m.DeleteCommand=le,m.DeleteLeftCommand=Ee,m.DeleteRightCommand=Pe,m.DocCopyCommand=de,m.DocCutCommand=ue,m.DocPasteCommand=me,m.IMEInputCommand=Le,m.InsertCommand=ce,m.MoveCursorOperation=$,m.MoveSelectionOperation=F,m.NORMAL_TEXT_SELECTION_PLUGIN_NAME=gt,m.OrderListCommand=Je,m.ReplaceContentCommand=Qe,m.RichTextEditingMutation=v,m.SetInlineFormatBoldCommand=G,m.SetInlineFormatCommand=Ae,m.SetInlineFormatFontFamilyCommand=H,m.SetInlineFormatFontSizeCommand=W,m.SetInlineFormatItalicCommand=q,m.SetInlineFormatStrikethroughCommand=J,m.SetInlineFormatSubscriptCommand=B,m.SetInlineFormatSuperscriptCommand=k,m.SetInlineFormatTextColorCommand=Q,m.SetInlineFormatUnderlineCommand=Z,m.SetTextSelectionsOperation=be,m.UpdateCommand=xe,m.VIEWPORT_KEY=ae,m.getDocObject=X,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.2",
|
|
4
4
|
"description": "UniverSheet normal base-docs",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -31,30 +31,30 @@
|
|
|
31
31
|
],
|
|
32
32
|
"private": false,
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@wendellhu/redi": "^0.12.
|
|
34
|
+
"@wendellhu/redi": "^0.12.13",
|
|
35
35
|
"rxjs": "^7.8.1",
|
|
36
|
-
"@univerjs/engine-render": "0.1.0-beta.
|
|
37
|
-
"@univerjs/
|
|
38
|
-
"@univerjs/
|
|
39
|
-
"@univerjs/ui": "0.1.0-beta.
|
|
36
|
+
"@univerjs/engine-render": "0.1.0-beta.2",
|
|
37
|
+
"@univerjs/sheets": "0.1.0-beta.2",
|
|
38
|
+
"@univerjs/core": "0.1.0-beta.2",
|
|
39
|
+
"@univerjs/ui": "0.1.0-beta.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@vitest/coverage-istanbul": "^1.1.
|
|
42
|
+
"@vitest/coverage-istanbul": "^1.1.1",
|
|
43
43
|
"happy-dom": "^12.10.3",
|
|
44
44
|
"less": "^4.2.0",
|
|
45
45
|
"typescript": "^5.3.3",
|
|
46
46
|
"vite": "^5.0.10",
|
|
47
|
-
"vite-plugin-dts": "^3.
|
|
47
|
+
"vite-plugin-dts": "^3.7.0",
|
|
48
48
|
"vite-plugin-externals": "^0.6.2",
|
|
49
|
-
"vitest": "^1.1.
|
|
49
|
+
"vitest": "^1.1.1"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@wendellhu/redi": ">=0.12.12",
|
|
53
53
|
"rxjs": ">=7.0.0",
|
|
54
|
-
"@univerjs/core": "0.1.0-beta.
|
|
55
|
-
"@univerjs/engine-render": "0.1.0-beta.
|
|
56
|
-
"@univerjs/
|
|
57
|
-
"@univerjs/
|
|
54
|
+
"@univerjs/core": "0.1.0-beta.2",
|
|
55
|
+
"@univerjs/engine-render": "0.1.0-beta.2",
|
|
56
|
+
"@univerjs/sheets": "0.1.0-beta.2",
|
|
57
|
+
"@univerjs/ui": "0.1.0-beta.2"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"test": "vitest run",
|