@univerjs/docs 0.1.0-beta.2 → 0.1.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{LICENSE.txt → LICENSE} +0 -2
- package/lib/cjs/index.js +2 -2
- package/lib/es/index.js +1829 -1843
- package/lib/types/basics/retain-delete-params.d.ts +2 -2
- package/lib/types/commands/commands/clipboard.command.d.ts +2 -1
- package/lib/types/commands/mutations/core-editing.mutation.d.ts +2 -2
- package/lib/types/controllers/clipboard.controller.d.ts +9 -13
- package/lib/types/services/clipboard/clipboard.service.d.ts +20 -7
- package/lib/types/services/ime-input-manager.service.d.ts +1 -1
- package/lib/umd/index.js +2 -2
- package/package.json +31 -30
|
@@ -13,5 +13,5 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type
|
|
17
|
-
export declare function getRetainAndDeleteFromReplace(range: ITextRange, segmentId?: string, memoryCursor?: number): Array<
|
|
16
|
+
import { type IDeleteAction, type IRetainAction, type ITextRange } from '@univerjs/core';
|
|
17
|
+
export declare function getRetainAndDeleteFromReplace(range: ITextRange, segmentId?: string, memoryCursor?: number): Array<IRetainAction | IDeleteAction>;
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type { IMultiCommand } from '@univerjs/core';
|
|
16
|
+
import type { IContextService, IMultiCommand } from '@univerjs/core';
|
|
17
|
+
export declare function whenDocOrEditor(contextService: IContextService): boolean;
|
|
17
18
|
export declare const DocCopyCommand: IMultiCommand;
|
|
18
19
|
export declare const DocCutCommand: IMultiCommand;
|
|
19
20
|
export declare const DocPasteCommand: IMultiCommand;
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { type
|
|
16
|
+
import { type IMutation, type TextXAction } from '@univerjs/core';
|
|
17
17
|
export interface IRichTextEditingMutationParams {
|
|
18
18
|
unitId: string;
|
|
19
|
-
mutations:
|
|
19
|
+
mutations: TextXAction[];
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* The core mutator to change rich text mutations. The execution result would be undo mutation params. Could be directly
|
|
@@ -13,21 +13,17 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
16
|
+
import { ICommandService, IContextService, RxDisposable } from '@univerjs/core';
|
|
17
|
+
import { IClipboardInterfaceService } from '@univerjs/ui';
|
|
18
|
+
import { ITextSelectionRenderManager } from '@univerjs/engine-render';
|
|
17
19
|
import { IDocClipboardService } from '../services/clipboard/clipboard.service';
|
|
18
|
-
|
|
19
|
-
export declare class DocClipboardController extends Disposable {
|
|
20
|
-
private readonly _logService;
|
|
20
|
+
export declare class DocClipboardController extends RxDisposable {
|
|
21
21
|
private readonly _commandService;
|
|
22
|
-
private readonly
|
|
22
|
+
private readonly _clipboardInterfaceService;
|
|
23
23
|
private readonly _docClipboardService;
|
|
24
|
-
private readonly
|
|
24
|
+
private readonly _textSelectionRenderManager;
|
|
25
25
|
private readonly _contextService;
|
|
26
|
-
constructor(
|
|
27
|
-
|
|
28
|
-
private
|
|
29
|
-
private _handlePaste;
|
|
30
|
-
private _getDocumentBodyInRanges;
|
|
31
|
-
private _handleCopy;
|
|
32
|
-
private _handleCut;
|
|
26
|
+
constructor(_commandService: ICommandService, _clipboardInterfaceService: IClipboardInterfaceService, _docClipboardService: IDocClipboardService, _textSelectionRenderManager: ITextSelectionRenderManager, _contextService: IContextService);
|
|
27
|
+
private _init;
|
|
28
|
+
private _initLegacyPasteCommand;
|
|
33
29
|
}
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import
|
|
17
|
-
import { Disposable, IUniverInstanceService } from '@univerjs/core';
|
|
16
|
+
import { Disposable, ICommandService, ILogService, IUniverInstanceService } from '@univerjs/core';
|
|
18
17
|
import { IClipboardInterfaceService } from '@univerjs/ui';
|
|
19
18
|
import type { IDisposable } from '@wendellhu/redi';
|
|
19
|
+
import { TextSelectionManagerService } from '../text-selection-manager.service';
|
|
20
20
|
export interface IClipboardPropertyItem {
|
|
21
21
|
}
|
|
22
22
|
export interface IDocClipboardHook {
|
|
@@ -24,19 +24,32 @@ export interface IDocClipboardHook {
|
|
|
24
24
|
onCopyContent?(start: number, end: number): string;
|
|
25
25
|
}
|
|
26
26
|
export interface IDocClipboardService {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
copy(): Promise<boolean>;
|
|
28
|
+
cut(): Promise<boolean>;
|
|
29
|
+
paste(items: ClipboardItem[]): Promise<boolean>;
|
|
30
|
+
legacyPaste(html?: string, text?: string): Promise<boolean>;
|
|
29
31
|
addClipboardHook(hook: IDocClipboardHook): IDisposable;
|
|
30
32
|
}
|
|
31
33
|
export declare const IDocClipboardService: import("@wendellhu/redi").IdentifierDecorator<IDocClipboardService>;
|
|
32
34
|
export declare class DocClipboardService extends Disposable implements IDocClipboardService {
|
|
33
35
|
private readonly _currentUniverService;
|
|
36
|
+
private readonly _logService;
|
|
37
|
+
private readonly _commandService;
|
|
34
38
|
private readonly _clipboardInterfaceService;
|
|
39
|
+
private readonly _textSelectionManagerService;
|
|
35
40
|
private _clipboardHooks;
|
|
36
41
|
private _htmlToUDM;
|
|
37
42
|
private _umdToHtml;
|
|
38
|
-
constructor(_currentUniverService: IUniverInstanceService, _clipboardInterfaceService: IClipboardInterfaceService);
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
constructor(_currentUniverService: IUniverInstanceService, _logService: ILogService, _commandService: ICommandService, _clipboardInterfaceService: IClipboardInterfaceService, _textSelectionManagerService: TextSelectionManagerService);
|
|
44
|
+
copy(): Promise<boolean>;
|
|
45
|
+
cut(): Promise<boolean>;
|
|
46
|
+
paste(items: ClipboardItem[]): Promise<boolean>;
|
|
47
|
+
legacyPaste(html?: string, text?: string): Promise<boolean>;
|
|
48
|
+
private _cut;
|
|
49
|
+
private _paste;
|
|
50
|
+
private _setClipboardData;
|
|
41
51
|
addClipboardHook(hook: IDocClipboardHook): IDisposable;
|
|
52
|
+
private _getDocumentBodyInRanges;
|
|
53
|
+
private _generateBodyFromClipboardItems;
|
|
54
|
+
private _generateBodyFromHtmlAndText;
|
|
42
55
|
}
|
|
@@ -24,7 +24,7 @@ export declare class IMEInputManagerService implements IDisposable {
|
|
|
24
24
|
clearUndoRedoMutationParamsCache(): void;
|
|
25
25
|
setActiveRange(range: Nullable<ITextRangeWithStyle>): void;
|
|
26
26
|
pushUndoRedoMutationParams(undoParams: IRichTextEditingMutationParams, redoParams: IRichTextEditingMutationParams): void;
|
|
27
|
-
fetchComposedUndoRedoMutationParams(
|
|
27
|
+
fetchComposedUndoRedoMutationParams(): {
|
|
28
28
|
redoMutationParams: IRichTextEditingMutationParams;
|
|
29
29
|
undoMutationParams: IRichTextEditingMutationParams;
|
|
30
30
|
previousActiveRange: ITextRangeWithStyle;
|
package/lib/umd/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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"})});
|
|
1
|
+
(function(g,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):(g=typeof globalThis<"u"?globalThis:g||self,a(g.UniverDocs={},g.UniverCore,g.UniverEngineRender,g.rxjs,g.UniverUi,g["@wendellhu/redi"]))})(this,function(g,a,T,N,x,U){"use strict";var Gn=Object.defineProperty;var Yn=(g,a,T)=>a in g?Gn(g,a,{enumerable:!0,configurable:!0,writable:!0,value:T}):g[a]=T;var M=(g,a,T)=>(Yn(g,typeof a!="symbol"?a+"":a,T),T);var Xe;function Y(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 ft(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 oe=(r=>(r.MAIN="__Document_Render_Main__",r))(oe||{}),ce=(r=>(r.VIEW_MAIN="viewMain",r.VIEW_TOP="viewTop",r.VIEW_LEFT="viewLeft",r.VIEW_LEFT_TOP="viewLeftTop",r))(ce||{});const Re=0,ze=2,We=10,ht="normalTextSelectionPluginName",De={id:"doc.operation.set-selections",type:a.CommandType.OPERATION,handler:(r,t)=>!0};var pt=Object.defineProperty,St=Object.getOwnPropertyDescriptor,_t=(r,t,e,n)=>{for(var i=n>1?void 0:n?St(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&&pt(t,e,i),i},He=(r,t)=>(e,n)=>t(e,n,r);function Ge(r){const{startOffset:t,endOffset:e,collapsed:n}=r;return{startOffset:t,endOffset:e,collapsed:n}}g.TextSelectionManagerService=class extends a.RxDisposable{constructor(e,n){super();M(this,"_currentSelection",null);M(this,"_textSelectionInfo",new Map);M(this,"_textSelection$",new N.BehaviorSubject(null));M(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(h=>h.isActive());if(o==null)return null;const{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:m,direction:f}=o;return c==null||l==null?null:{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:m,direction:f,segmentId:i,style:s}}add(e){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,segmentId:"",style:T.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(De.id,{unitId:i,subUnitId:s,segmentId:o,style:c,ranges:l.map(Ge)})}_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(Ge))}_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})}},g.TextSelectionManagerService=_t([He(0,T.ITextSelectionRenderManager),He(1,a.ICommandService)],g.TextSelectionManagerService);function be(r,t="",e=0){const{startOffset:n,endOffset:i}=r,s=[],o=n-e,c=i-e;return o>0&&s.push({t:a.TextXActionType.RETAIN,len:o,segmentId:t}),s.push({t:a.TextXActionType.DELETE,len:c-o,line:0,segmentId:t}),s}var vt=Object.defineProperty,It=Object.getOwnPropertyDescriptor,Ct=(r,t,e,n)=>{for(var i=n>1?void 0:n?It(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},Mt=(r,t)=>(e,n)=>t(e,n,r);g.DocViewModelManagerService=class extends a.RxDisposable{constructor(e){super();M(this,"_currentViewModelUnitId","");M(this,"_docViewModelMap",new Map);M(this,"_currentDocViewModel$",new N.BehaviorSubject(null));M(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 T.DocumentViewModel(e)}},g.DocViewModelManagerService=Ct([Mt(0,a.IUniverInstanceService)],g.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(g.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}}},le={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(g.TextSelectionManagerService),{range:s,segmentId:o,body:c,unitId:l,textRanges:u}=t,{startOffset:d,collapsed:m}=s,f={id:v.id,params:{unitId:l,mutations:[]}},h=new a.TextX;m?d>0&&h.push({t:a.TextXActionType.RETAIN,len:d,segmentId:o}):h.push(...be(s,o)),h.push({t:a.TextXActionType.INSERT,body:c,len:c.dataStream.length,line:0,segmentId:o}),f.params.mutations=h.serialize();const p=n.syncExecuteCommand(f.id,f.params);return i.replaceTextRanges(u),p?(e.pushUndoRedo({unitID:l,undoMutations:[{id:v.id,params:p}],redoMutations:[{id:v.id,params:f.params}],undo(){return n.syncExecuteCommand(v.id,p),i.replaceTextRanges([s]),!0},redo(){return n.syncExecuteCommand(v.id,f.params),i.replaceTextRanges(u),!0}}),!0):!1}};var B=(r=>(r[r.LEFT=0]="LEFT",r[r.RIGHT=1]="RIGHT",r))(B||{});const de={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(g.TextSelectionManagerService),{range:s,segmentId:o,unitId:c,direction:l,textRanges:u,len:d=1}=t,{startOffset:m}=s,f={id:v.id,params:{unitId:c,mutations:[]}},h=new a.TextX;m>0&&h.push({t:a.TextXActionType.RETAIN,len:l===0?m-d:m,segmentId:o}),h.push({t:a.TextXActionType.DELETE,len:d,line:0,segmentId:o}),f.params.mutations=h.serialize();const p=e.syncExecuteCommand(f.id,f.params);return i.replaceTextRanges(u),p&&n.pushUndoRedo({unitID:c,undoMutations:[{id:v.id,params:p}],redoMutations:[{id:v.id,params:f.params}],undo(){return e.syncExecuteCommand(v.id,p),i.replaceTextRanges([s]),!0},redo(){return e.syncExecuteCommand(v.id,f.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(g.TextSelectionManagerService),m={id:v.id,params:{unitId:o,mutations:[]}},f=new a.TextX,{startOffset:h,endOffset:p}=e;f.push({t:a.TextXActionType.RETAIN,len:h,segmentId:n}),f.push({t:a.TextXActionType.RETAIN,body:i,len:p-h,segmentId:n,coverType:s}),m.params.mutations=f.serialize();const S=l.syncExecuteCommand(m.id,m.params);return d.replaceTextRanges(c),S?(u.pushUndoRedo({unitID:o,undoMutations:[{id:v.id,params:S}],redoMutations:[{id:v.id,params:m.params}],undo(){return l.syncExecuteCommand(v.id,S),d.replaceTextRanges(c),!0},redo(){return l.syncExecuteCommand(v.id,m.params),d.replaceTextRanges(c),!0}}),!0):!1}};function Tt(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 Ee={id:"doc.command.break-line",type:a.CommandType.COMMAND,handler:async r=>{var p,S;const t=r.get(g.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}],f=((S=(p=s.getBody())==null?void 0:p.paragraphs)!=null?S:[]).find(_=>_.startIndex>=c);return await n.executeCommand(le.id,{unitId:o,body:{dataStream:a.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Tt(a.DataStreamTreeTokenType.PARAGRAPH,f)},range:i,textRanges:d,segmentId:l})}},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(g.TextSelectionManagerService),l=r.get(a.IUniverInstanceService),u=c.getSelections();if(!Array.isArray(u)||u.length===0)return!1;const m=l.getCurrentUniverDocInstance().getUnitId(),f={id:v.id,params:{unitId:m,mutations:[]}},h=new a.MemoryCursor;h.reset();const p=new a.TextX;for(const _ of u){const{startOffset:I,endOffset:C,collapsed:y}=_,O=I-h.cursor;y?p.push({t:a.TextXActionType.RETAIN,len:O,segmentId:e}):p.push(...be(_,e,h.cursor)),p.push({t:a.TextXActionType.INSERT,body:n,len:n.dataStream.length,line:0,segmentId:e}),h.reset(),h.moveCursor(C)}f.params.mutations=p.serialize();const S=o.syncExecuteCommand(f.id,f.params);return c.replaceTextRanges(i),S?(s.pushUndoRedo({unitID:m,undoMutations:[{id:v.id,params:S}],redoMutations:[{id:v.id,params:f.params}],undo(){return o.syncExecuteCommand(v.id,S),c.replaceTextRanges(u),!0},redo(){return o.syncExecuteCommand(v.id,f.params),c.replaceTextRanges(i),!0}}),!0):!1}},ue={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(g.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),m=a.getDocsUpdateBody(d.snapshot,e);if(m==null)return!1;const f={id:v.id,params:{unitId:u,mutations:[]}},h=new a.MemoryCursor;h.reset();const p=new a.TextX;for(const _ of l){const{startOffset:I,endOffset:C,collapsed:y}=_,O=I-h.cursor;y?p.push({t:a.TextXActionType.RETAIN,len:O,segmentId:e}):p.push(...yt(_,m,e,h.cursor)),h.reset(),h.moveCursor(C)}f.params.mutations=p.serialize();const S=s.syncExecuteCommand(f.id,f.params);return o.replaceTextRanges(n),S?(i.pushUndoRedo({unitID:u,undoMutations:[{id:v.id,params:S}],redoMutations:[{id:v.id,params:f.params}],undo(){return s.syncExecuteCommand(v.id,S),o.replaceTextRanges(l),!0},redo(){return s.syncExecuteCommand(v.id,f.params),o.replaceTextRanges(n),!0}}),!0):!1}};function yt(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(m=>m.startIndex-n>=l&&m.startIndex-n<=u);if(l>0&&o.push({t:a.TextXActionType.RETAIN,len:l,segmentId:e}),d&&d.startIndex-n>l){const m=d.startIndex-n;o.push({t:a.TextXActionType.DELETE,len:m-l,line:0,segmentId:e}),o.push({t:a.TextXActionType.RETAIN,len:1,segmentId:e}),u>m+1&&o.push({t:a.TextXActionType.DELETE,len:u-m-1,line:0,segmentId:e})}else o.push({t:a.TextXActionType.DELETE,len:u-l,line:0,segmentId:e});return o}const Ot=10,Rt=6;function Dt(){return a.Tools.generateRandomId(Rt)}function bt(r){const t=r.match(/data-copy-id="([^\s]+)"/);return t&&t[1]?t[1]:null}class xt{constructor(){M(this,"_cache",new a.LRUMap(Ot))}set(t,e){this._cache.set(t,e)}get(t){return this._cache.get(t)}clear(){this._cache.clear()}}const Ke=new xt;function Et(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)?Ue(o):o;break}case"margin-bottom":{const o=parseInt(s);e.spaceBelow=/pt/.test(s)?Ue(o):o;break}}}return Object.getOwnPropertyNames(e).length?e:null}function Ue(r){return r/.75}function Pe(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)?Ue(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 Ut(r){const t=new DOMParser,e=`<x-univer id="univer-root">${r}</x-univer>`;return t.parseFromString(e,"text/html").querySelector("#univer-root")}function qe(r,t){const e=r.tagName.toLowerCase();return typeof t=="string"?e===t:Array.isArray(t)?t.some(n=>n===e):t(r)}const Oe=class Oe{constructor(){M(this,"_styleCache",new Map);M(this,"_styleRules",[]);M(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=Oe._pluginList.find(s=>s.checkPasteType(t)),n=Ut(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:m})=>qe(s,m)),l=c?c.getStyle(s):Pe(s);this._styleCache.set(s,{...o,...l});const{childNodes:u}=s;this._process(s,u,n);const d=this._afterProcessRules.find(({filter:m})=>qe(s,m));d&&d.handler(n,s)}}};M(Oe,"_pluginList",[]);let K=Oe;const Pt={name:"univer-doc-paste-plugin-lark",checkPasteType(r){return/lark-record-clipboard/i.test(r)},stylesRules:[{filter:["s"],getStyle(r){const t=Pe(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"}}]},Nt={name:"univer-doc-paste-plugin-word",checkPasteType(r){return/word|mso/i.test(r)},stylesRules:[{filter:["b"],getStyle(r){const t=Pe(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=Et(t);n&&(e.paragraphStyle=n),r.paragraphs.push(e),r.dataStream+="\r"}}]};function At(r,t){const{st:e,ed:n,ts:i={}}=t,{ff:s,fs:o,it:c,bl:l,ul:u,st:d,ol:m,bg:f,cl:h,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}`),h&&_.push(`color: ${h.rgb}`),o&&_.push(`font-size: ${o}px`),m&&_.push("text-decoration: overline"),f&&_.push(`background: ${f.rgb}`),_.length?`<span style="${_.join(";")}">${S}</span>`:S}function Ze(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(At(e,l)),s=d,t)for(const m of i){const{startIndex:f,paragraphStyle:h={}}=m;if(f>=u&&f<=d){const{spaceAbove:p,spaceBelow:S}=h,_=[];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 wt{convert(t){if(t.length===0)throw new Error("The bodyList length at least to be 1");if(t.length===1)return Ze(t[0]);let e="";for(const n of t)e+='<p className="UniverNormal">',e+=Ze(n,!1),e+="</p>";return e}}var Lt=Object.defineProperty,Bt=Object.getOwnPropertyDescriptor,$t=(r,t,e,n)=>{for(var i=n>1?void 0:n?Bt(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&&Lt(t,e,i),i},q=(r,t)=>(e,n)=>t(e,n,r);K.use(Nt),K.use(Pt);function Ft(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 Z=U.createIdentifier("doc.clipboard-service");let Ne=class extends a.Disposable{constructor(t,e,n,i,s){super();M(this,"_clipboardHooks",[]);M(this,"_htmlToUDM",new K);M(this,"_umdToHtml",new wt);this._currentUniverService=t,this._logService=e,this._commandService=n,this._clipboardInterfaceService=i,this._textSelectionManagerService=s}async copy(){const t=this._getDocumentBodyInRanges();try{this._setClipboardData(t)}catch(e){return this._logService.error("[DocClipboardService] copy failed",e),!1}return!0}async cut(){return this._cut()}async paste(t){const e=await this._generateBodyFromClipboardItems(t);return this._paste(e)}async legacyPaste(t,e){const n=this._generateBodyFromHtmlAndText(t,e);return this._paste(n)}async _cut(){var s;const{segmentId:t,endOffset:e,style:n}=(s=this._textSelectionManagerService.getActiveRange())!=null?s:{},i=this._textSelectionManagerService.getSelections();if(t==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),e==null||i==null)return!1;this.copy();try{let o=e;for(const l of i){const{startOffset:u,endOffset:d}=l;u==null||d==null||d<=e&&(o-=d-u)}const c=[{startOffset:o,endOffset:o,style:n}];return this._commandService.executeCommand(ue.id,{segmentId:t,textRanges:c})}catch{return this._logService.error("[DocClipboardController] cut content failed"),!1}}async _paste(t){var o;const{segmentId:e,endOffset:n,style:i}=(o=this._textSelectionManagerService.getActiveRange())!=null?o:{},s=this._textSelectionManagerService.getSelections();if(e==null&&this._logService.error("[DocClipboardController] segmentId does not exist!"),n==null||s==null)return!1;try{let c=n;for(const u of s){const{startOffset:d,endOffset:m}=u;d==null||m==null||m<=n&&(c+=t.dataStream.length-(m-d))}const l=[{startOffset:c,endOffset:c,style:i}];return this._commandService.executeCommand(Ye.id,{body:t,segmentId:e,textRanges:l})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(t){const e=Dt(),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}"`),Ke.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)})}_getDocumentBodyInRanges(){const t=this._textSelectionManagerService.getSelections(),e=this._currentUniverService.getCurrentUniverDocInstance(),n=[];if(t==null)return n;for(const i of t){const{startOffset:s,endOffset:o,collapsed:c}=i;if(c||s==null||o==null)continue;const l=e.sliceBody(s,o);l!=null&&n.push(l)}return n}async _generateBodyFromClipboardItems(t){try{let e="",n="";for(const i of t)for(const s of i.types)s===x.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await i.getType(s).then(o=>o&&o.text()):s===x.HTML_CLIPBOARD_MIME_TYPE&&(e=await i.getType(s).then(o=>o&&o.text()));return this._generateBodyFromHtmlAndText(e,n)}catch(e){return Promise.reject(e)}}_generateBodyFromHtmlAndText(t,e){if(!t){if(e)return Ft(e);throw new Error("[DocClipboardService] html and text cannot be both empty!")}const n=bt(t);if(n){const i=Ke.get(n);if(i)return i}return this._htmlToUDM.convert(t)}};Ne=$t([q(0,a.IUniverInstanceService),q(1,a.ILogService),q(2,a.ICommandService),q(3,x.IClipboardInterfaceService),q(4,U.Inject(g.TextSelectionManagerService))],Ne);function me(r){return r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.EDITOR_ACTIVATED)}const Ae=999,Je={id:x.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:Ae,preconditions:me,handler:async r=>r.get(Z).copy()},Qe={id:x.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:Ae,preconditions:me,handler:async r=>r.get(Z).cut()},et={id:x.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:Ae,preconditions:me,handler:async r=>{const t=r.get(Z),n=await r.get(x.IClipboardInterfaceService).read();return n.length===0?!1:t.paste(n)}};var jt=Object.defineProperty,Vt=Object.getOwnPropertyDescriptor,kt=(r,t,e,n)=>{for(var i=n>1?void 0:n?Vt(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},tt=(r,t)=>(e,n)=>t(e,n,r);g.DocSkeletonManagerService=class extends a.RxDisposable{constructor(e,n){super();M(this,"_currentSkeletonUnitId","");M(this,"_docSkeletonMap",new Map);M(this,"_currentSkeleton$",new N.BehaviorSubject(null));M(this,"currentSkeleton$",this._currentSkeleton$.asObservable());M(this,"_currentSkeletonBefore$",new N.BehaviorSubject(null));M(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 T.DocumentSkeleton.create(e,this._localeService)}},g.DocSkeletonManagerService=kt([tt(0,U.Inject(a.LocaleService)),tt(1,U.Inject(g.DocViewModelManagerService))],g.DocSkeletonManagerService);const we={id:"doc.command.delete-left",type:a.CommandType.COMMAND,handler:async r=>{var O;const t=r.get(g.TextSelectionManagerService),e=r.get(g.DocSkeletonManagerService),n=r.get(a.IUniverInstanceService),i=r.get(a.ICommandService),s=t.getActiveRange(),o=t.getSelections(),c=(O=e.getCurrent())==null?void 0:O.skeleton;let l=!0;if(s==null||c==null||o==null)return!1;const u=n.getCurrentUniverDocInstance(),{startOffset:d,collapsed:m,segmentId:f,style:h}=s,p=c.findNodeByCharIndex(d),S=T.hasListSpan(p),_=T.isIndentBySpan(p,u.getBody());let I=d;const C=c.findNodeByCharIndex(d-1);if(T.isFirstSpan(p)&&C!==p&&(S===!0||_===!0)){const D=T.getParagraphBySpan(p,u.getBody());if(D==null)return!1;const b=D==null?void 0:D.startIndex,E={startIndex:0},P=D.paragraphStyle;if(S===!0){const R=D.paragraphStyle;R&&(E.paragraphStyle=R)}else if(_===!0){const R=D.bullet;R&&(E.bullet=R),P!=null&&(E.paragraphStyle={...P},delete E.paragraphStyle.hanging,delete E.paragraphStyle.indentStart)}const A=[{startOffset:I,endOffset:I,style:h}];l=await i.executeCommand(xe.id,{unitId:u.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...E}]},range:{startOffset:b,endOffset:b+1},textRanges:A,coverType:a.UpdateDocsAttributeType.REPLACE,segmentId:f})}else if(m===!0){if(C==null)return!0;if(C.content==="\r")l=await i.executeCommand(Be.id,{direction:B.LEFT,range:s});else{I-=C.count;const D=[{startOffset:I,endOffset:I,style:h}];l=await i.executeCommand(de.id,{unitId:u.getUnitId(),range:s,segmentId:f,direction:B.LEFT,len:C.count,textRanges:D})}}else{const D=nt(s,o);l=await i.executeCommand(ue.id,{segmentId:f,textRanges:D})}return l}},Le={id:"doc.command.delete-right",type:a.CommandType.COMMAND,handler:async r=>{var p;const t=r.get(g.TextSelectionManagerService),e=r.get(g.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:m,segmentId:f,style:h}=s;if(d===u.getBody().dataStream.length-2&&m)return!0;if(m===!0){const S=c.findNodeByCharIndex(d);if(S.content==="\r")l=await i.executeCommand(Be.id,{direction:B.RIGHT,range:s});else{const _=[{startOffset:d,endOffset:d,style:h}];l=await i.executeCommand(de.id,{unitId:u.getUnitId(),range:s,segmentId:f,direction:B.RIGHT,textRanges:_,len:S.count})}}else{const S=nt(s,o);l=await i.executeCommand(ue.id,{segmentId:f,textRanges:S})}return l}},Be={id:"doc.command.merge-two-paragraph",type:a.CommandType.COMMAND,handler:async(r,t)=>{var P,A,R;const e=r.get(g.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:m,collapsed:f,segmentId:h,style:p}=l;if(!f)return!1;const S=o===B.LEFT?m:m+1,_=(R=(A=(P=d.getBody())==null?void 0:P.paragraphs)==null?void 0:A.find(w=>w.startIndex>=S))==null?void 0:R.startIndex,I=Xt(d.getBody(),S,_),C=o===B.LEFT?m-1:m,y=d.getUnitId(),O=[{startOffset:C,endOffset:C,style:p}],D={id:v.id,params:{unitId:y,mutations:[]}},b=new a.TextX;b.push({t:a.TextXActionType.RETAIN,len:o===B.LEFT?m-1:m,segmentId:h}),I.dataStream.length&&b.push({t:a.TextXActionType.INSERT,body:I,len:I.dataStream.length,line:0,segmentId:h}),b.push({t:a.TextXActionType.RETAIN,len:1,segmentId:h}),b.push({t:a.TextXActionType.DELETE,len:_+1-S,line:0,segmentId:h}),D.params.mutations=b.serialize();const E=i.syncExecuteCommand(D.id,D.params);return e.replaceTextRanges(O),E?(s.pushUndoRedo({unitID:y,undoMutations:[{id:v.id,params:E}],redoMutations:[{id:v.id,params:D.params}],undo(){return i.syncExecuteCommand(v.id,E),e.replaceTextRanges([c]),!0},redo(){return i.syncExecuteCommand(v.id,D.params),e.replaceTextRanges(O),!0}}),!0):!1}};function Xt(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 nt(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 $e{constructor(){M(this,"_previousActiveRange",null);M(this,"_undoMutationParamsCache",[]);M(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}setActiveRange(t){this._previousActiveRange=t}pushUndoRedoMutationParams(t,e){this._undoMutationParamsCache.push(t),this._redoMutationParamsCache.push(e)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:t}=this._undoMutationParamsCache[0],e={unitId:t,mutations:this._undoMutationParamsCache.reverse().reduce((i,s)=>a.TextX.compose(i,s.mutations),[])};return{redoMutationParams:{unitId:t,mutations:this._redoMutationParamsCache.reduce((i,s)=>a.TextX.compose(i,s.mutations),[])},undoMutationParams:e,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Fe={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),m=r.get(g.TextSelectionManagerService),f=r.get($e),h={id:v.id,params:{unitId:e,mutations:[]}},p=new a.TextX;s.collapsed?p.push({t:a.TextXActionType.RETAIN,len:s.startOffset,segmentId:o}):p.push(...be(s,o)),i>0&&p.push({t:a.TextXActionType.DELETE,len:i,line:0,segmentId:o}),p.push({t:a.TextXActionType.INSERT,body:{dataStream:n},len:n.length,line:0,segmentId:o}),h.params.mutations=p.serialize();const S=u.syncExecuteCommand(h.id,h.params);if(f.pushUndoRedoMutationParams(S,h.params),m.replaceTextRanges(c),l){if(S){const _=f.fetchComposedUndoRedoMutationParams();if(_==null)return!1;const{undoMutationParams:I,redoMutationParams:C,previousActiveRange:y}=_;return d.pushUndoRedo({unitID:e,undoMutations:[{id:v.id,params:I}],redoMutations:[{id:v.id,params:C}],undo(){return u.syncExecuteCommand(v.id,I),m.replaceTextRanges([y]),!0},redo(){return u.syncExecuteCommand(v.id,C),m.replaceTextRanges(c),!0}}),!0}}else return!!S;return!1}},z={id:"doc.command.set-inline-format-bold",type:a.CommandType.COMMAND,handler:async()=>!0},J={id:"doc.command.set-inline-format-italic",type:a.CommandType.COMMAND,handler:async()=>!0},Q={id:"doc.command.set-inline-format-underline",type:a.CommandType.COMMAND,handler:async()=>!0},ee={id:"doc.command.set-inline-format-strikethrough",type:a.CommandType.COMMAND,handler:async()=>!0},$={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},te={id:"doc.command.set-inline-format-text-color",type:a.CommandType.COMMAND,handler:async()=>!0},it={[z.id]:"bl",[J.id]:"it",[Q.id]:"ul",[ee.id]:"st",[W.id]:"fs",[H.id]:"ff",[te.id]:"cl",[$.id]:"va",[V.id]:"va"},je={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(g.TextSelectionManagerService),l=r.get(a.IUniverInstanceService),u=c.getSelections();if(!Array.isArray(u)||u.length===0)return!1;let d=l.getCurrentUniverDocInstance(),m=d.getUnitId();m===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(d=l.getUniverDocInstance(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),m=d.getUnitId());let f;switch(i){case z.id:case J.id:case Q.id:case ee.id:case $.id:case V.id:{f=Wt(d.getBody().textRuns,i,u);break}case W.id:case H.id:{f=n;break}case te.id:{f={rgb:n};break}default:throw new Error(`Unknown command: ${i} in handleInlineFormat`)}const h={id:v.id,params:{unitId:m,mutations:[]}},p=new a.TextX,S=new a.MemoryCursor;S.reset();for(const C of u){const{startOffset:y,endOffset:O}=C,D={dataStream:"",textRuns:[{st:0,ed:O-y,ts:{[it[i]]:f}}]},b=y-S.cursor;b!==0&&p.push({t:a.TextXActionType.RETAIN,len:b,segmentId:e}),p.push({t:a.TextXActionType.RETAIN,body:D,len:O-y,segmentId:e}),S.reset(),S.moveCursor(O)}h.params.mutations=p.serialize();const _=o.syncExecuteCommand(h.id,h.params),I=[z.id,W.id,H.id,$.id,V.id];return I.includes(i)&&c.refreshSelection(),_?(s.pushUndoRedo({unitID:m,undoMutations:[{id:v.id,params:_}],redoMutations:[{id:v.id,params:h.params}],undo(){return o.syncExecuteCommand(v.id,_),I.includes(i)&&c.refreshSelection(),!0},redo(){return o.syncExecuteCommand(v.id,h.params),I.includes(i)&&c.refreshSelection(),!0}}),!0):!1}};function zt(r){return r!==null&&typeof r=="object"}function Wt(r,t,e){let n=0,i=0;const s=it[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===$.id?a.BaselineOffset.SUBSCRIPT:a.BaselineOffset.SUPERSCRIPT}if(zt(d==null?void 0:d[s])&&d[s].s===a.BooleanNumber.FALSE)return{s:a.BooleanNumber.TRUE};if(t===$.id&&(d==null?void 0:d[s])!==a.BaselineOffset.SUBSCRIPT)return a.BaselineOffset.SUBSCRIPT;if(t===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 rt={id:"doc.command.bullet-list",type:a.CommandType.COMMAND,handler:r=>r.get(a.ICommandService).syncExecuteCommand(Ve.id,{listType:a.PresetListType.BULLET_LIST})},st={id:"doc.command.order-list",type:a.CommandType.COMMAND,handler:r=>r.get(a.ICommandService).syncExecuteCommand(Ve.id,{listType:a.PresetListType.ORDER_LIST})},Ve={id:"doc.command.list-operation",type:a.CommandType.COMMAND,handler:(r,t)=>{var O,D;const e=r.get(g.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=(O=c.getBody())==null?void 0:O.paragraphs;if(l==null||u==null)return!1;const d=Ht(l,u),{segmentId:m}=l,f=c.getUnitId(),h=d.every(b=>{var E;return((E=b.bullet)==null?void 0:E.listType)===o}),p=6;let S=a.Tools.generateRandomId(p);if(d.length===1){const b=u.indexOf(d[0]),E=u[b-1],P=u[b+1];E&&E.bullet&&E.bullet.listType===o?S=E.bullet.listId:P&&P.bullet&&P.bullet.listType===o&&(S=P.bullet.listId)}const _={id:v.id,params:{unitId:f,mutations:[]}},I=new a.MemoryCursor;I.reset();const C=new a.TextX;for(const b of d){const{startIndex:E}=b;C.push({t:a.TextXActionType.RETAIN,len:E-I.cursor,segmentId:m});const P={...b.paragraphStyle,hanging:void 0,indentStart:void 0};C.push({t:a.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[h?{paragraphStyle:P,startIndex:0}:{...b,startIndex:0,bullet:{...(D=b.bullet)!=null?D:{nestingLevel:0,textStyle:{fs:20}},listType:o,listId:S}}]},segmentId:m,coverType:a.UpdateDocsAttributeType.REPLACE}),I.moveCursorTo(E+1)}_.params.mutations=C.serialize();const y=i.syncExecuteCommand(_.id,_.params);return e.refreshSelection(),y&&s.pushUndoRedo({unitID:f,undoMutations:[{id:v.id,params:y}],redoMutations:[{id:v.id,params:_.params}],undo(){return i.syncExecuteCommand(v.id,y),e.refreshSelection(),!0},redo(){return i.syncExecuteCommand(v.id,_.params),e.refreshSelection(),!0}}),!0}};function Ht(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 at={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(g.TextSelectionManagerService),u=r.get(a.IUndoRedoService),d=(p=o.getUniverDocInstance(e))==null?void 0:p.getSnapshot().body,m=l.getSelections();if(d==null||!Array.isArray(m)||m.length===0)return!1;const f=ct(e,s,d,n),h=c.syncExecuteCommand(f.id,f.params);return l.replaceTextRanges(i),h?(u.pushUndoRedo({unitID:e,undoMutations:[{id:v.id,params:h}],redoMutations:[{id:v.id,params:f.params}],undo(){return c.syncExecuteCommand(v.id,h),l.replaceTextRanges(m),!0},redo(){return c.syncExecuteCommand(v.id,f.params),l.replaceTextRanges(i),!0}}),!0):!1}},ot={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=ct(e,i,l,n);return o.syncExecuteCommand(u.id,u.params),c.clearUndoRedo(e),!0}};function ct(r,t,e,n){const i={id:v.id,params:{unitId:r,mutations:[]}},s=new a.TextX,o=(e==null?void 0:e.dataStream.length)-2;return o>0&&s.push({t:a.TextXActionType.DELETE,len:o,line:0,segmentId:t}),n.dataStream.length>0&&s.push({t:a.TextXActionType.INSERT,body:n,len:n.dataStream.length,line:0,segmentId:t}),i.params.mutations=s.serialize(),i}const F={id:"doc.operation.move-cursor",type:a.CommandType.OPERATION,handler:(r,t)=>!!t},j={id:"doc.operation.move-selection",type:a.CommandType.OPERATION,handler:(r,t)=>!!t},Gt=(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}},k={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}},lt={type:a.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(r,t)=>{var m,f;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=(m=t.documentId)!=null?m:s,o=(f=t.zoomRatio)!=null?f:o),!i.getUniverDocInstance(s))return!1;const l={zoomRatio:o,unitId:s},u=Gt(r,l);return e.syncExecuteCommand(k.id,l)?(n.pushUndoRedo({unitID:s,undoMutations:[{id:k.id,params:u}],redoMutations:[{id:k.id,params:l}]}),!0):!1}},dt={id:"doc.operation.select-all",type:a.CommandType.COMMAND,handler:async r=>{const t=r.get(a.IUniverInstanceService),e=r.get(g.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}};var Yt=Object.defineProperty,Kt=Object.getOwnPropertyDescriptor,qt=(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&&Yt(t,e,i),i},ne=(r,t)=>(e,n)=>t(e,n,r);let ge=class extends a.RxDisposable{constructor(r,t,e,n,i){super(),this._commandService=r,this._clipboardInterfaceService=t,this._docClipboardService=e,this._textSelectionRenderManager=n,this._contextService=i,this._init()}_init(){[Je,Qe,et].forEach(r=>this.disposeWithMe(this._commandService.registerMultipleCommand(r))),[Ye,ue].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r))),this._initLegacyPasteCommand()}_initLegacyPasteCommand(){var r;this._clipboardInterfaceService.supportClipboard||(r=this._textSelectionRenderManager)==null||r.onPaste$.pipe(N.takeUntil(this.dispose$)).subscribe(t=>{var s,o;if(!me(this._contextService))return;t.event.preventDefault();const e=t.event,n=(s=e.clipboardData)==null?void 0:s.getData("text/html"),i=(o=e.clipboardData)==null?void 0:o.getData("text/plain");this._docClipboardService.legacyPaste(n,i)})}};ge=qt([a.OnLifecycle(a.LifecycleStages.Steady,ge),ne(0,a.ICommandService),ne(1,x.IClipboardInterfaceService),ne(2,Z),ne(3,T.ITextSelectionRenderManager),ne(4,a.IContextService)],ge);var Zt=Object.defineProperty,Jt=Object.getOwnPropertyDescriptor,Qt=(r,t,e,n)=>{for(var i=n>1?void 0:n?Jt(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&&Zt(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,m=s.length;d<m;d++){const f=s[d],{pageWidth:h,pageHeight:p}=f;i.pageLayoutType===T.PageLayoutType.VERTICAL?(c+=p,c+=i.pageMarginTop,d===m-1&&(c+=i.pageMarginTop),o=Math.max(o,h)):i.pageLayoutType===T.PageLayoutType.HORIZONTAL&&(o+=h,d!==m-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=Qt([a.OnLifecycle(a.LifecycleStages.Rendered,fe),ke(0,U.Inject(g.DocSkeletonManagerService)),ke(1,T.IRenderManagerService),ke(2,a.ICommandService)],fe);var en=Object.defineProperty,tn=Object.getOwnPropertyDescriptor,nn=(r,t,e,n)=>{for(var i=n>1?void 0:n?tn(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&&en(t,e,i),i},ie=(r,t)=>(e,n)=>t(e,n,r);let he=class extends a.Disposable{constructor(t,e,n,i,s){super();M(this,"_liquid",new T.Liquid);M(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:m}=u;t.forEach(f=>{const{unitId:h,subUnitId:p,floatingObjectId:S,floatingObject:_}=f,{left:I=0,top:C=0,width:y=0,height:O=0,angle:D,flipX:b,flipY:E,skewX:P,skewY:A}=_,R=this._pageMarginCache.get(S),w=(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-w,top:C-m-L,height:O,width:y})}),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,k.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:m,pageMarginTop:f}=c,{pages:h}=i,p=[];o.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let S=0,_=h.length;S<_;S++){const I=h[S],{skeDrawings:C,marginLeft:y,marginTop:O}=I;this._liquid.translatePagePadding(I),C.forEach(D=>{const{aLeft:b,aTop:E,height:P,width:A,objectId:R}=D;p.push({unitId:t,subUnitId:a.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:R,floatingObject:{left:b+l+this._liquid.x,top:E+u+this._liquid.y,width:A,height:P}}),this._pageMarginCache.set(R,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.translatePage(I,d,m,f)}this._floatingObjectManagerService.BatchAddOrUpdate(p)}};he=nn([a.OnLifecycle(a.LifecycleStages.Steady,he),ie(0,U.Inject(g.DocSkeletonManagerService)),ie(1,a.IUniverInstanceService),ie(2,T.IRenderManagerService),ie(3,a.ICommandService),ie(4,a.IFloatingObjectManagerService)],he);var rn=Object.defineProperty,sn=Object.getOwnPropertyDescriptor,an=(r,t,e,n)=>{for(var i=n>1?void 0:n?sn(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&&rn(t,e,i),i},G=(r,t)=>(e,n)=>t(e,n,r);let pe=class extends a.Disposable{constructor(t,e,n,i,s,o){super();M(this,"_previousIMEContent","");M(this,"_previousIMERange");M(this,"_onStartSubscription");M(this,"_onUpdateSubscription");M(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 m=s.data;if(m===this._previousIMEContent&&e)return;const f=m.length,h=[{startOffset:c+f,endOffset:c+f,style:u}];await this._commandService.executeCommand(Fe.id,{unitId:i.getUnitId(),newText:m,oldTextLen:this._previousIMEContent.length,range:this._previousIMERange,textRanges:h,isCompositionEnd:!e,segmentId:l}),e?(this._previousIMERange.collapsed||(this._previousIMERange.collapsed=!0),this._previousIMEContent=m):this._resetIME()}_resetIME(){this._previousIMEContent="",this._previousIMERange=null,this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(null)}_getDocObject(){return Y(this._currentUniverService,this._renderManagerService)}};pe=an([a.OnLifecycle(a.LifecycleStages.Rendered,pe),G(0,U.Inject(g.DocSkeletonManagerService)),G(1,a.IUniverInstanceService),G(2,T.IRenderManagerService),G(3,T.ITextSelectionRenderManager),G(4,U.Inject($e)),G(5,a.ICommandService)],pe);var on=Object.defineProperty,cn=Object.getOwnPropertyDescriptor,ln=(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&&on(t,e,i),i},ut=(r,t)=>(e,n)=>t(e,n,r);let Se=class extends a.Disposable{constructor(r,t){super(),this._textSelectionManagerService=r,this._commandService=t,this._commandExecutedListener()}_commandExecutedListener(){const r=[z.id,J.id,Q.id,ee.id,$.id,V.id,W.id,H.id,te.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{r.includes(t.id)&&this._handleInlineFormat(t)}))}_handleInlineFormat(r){var e,n;const{segmentId:t}=(e=this._textSelectionManagerService.getActiveRange())!=null?e:{};t!=null&&this._commandService.executeCommand(je.id,{segmentId:t,preCommandId:r.id,...(n=r.params)!=null?n:{}})}};Se=ln([a.OnLifecycle(a.LifecycleStages.Rendered,Se),ut(0,U.Inject(g.TextSelectionManagerService)),ut(1,a.ICommandService)],Se);var dn=Object.defineProperty,un=Object.getOwnPropertyDescriptor,mn=(r,t,e,n)=>{for(var i=n>1?void 0:n?un(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&&dn(t,e,i),i},re=(r,t)=>(e,n)=>t(e,n,r);let _e=class extends a.Disposable{constructor(t,e,n,i,s){super();M(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=[F.id,j.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!t.includes(e.id))return;const n=e.params;switch(e.id){case F.id:return this._handleMoveCursor(n.direction);case j.id:return this._handleShiftMoveSelection(n.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(t){var S,_,I;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:m}=e;if(n.length>1){let C=Number.POSITIVE_INFINITY,y=Number.NEGATIVE_INFINITY;for(const O of n)C=Math.min(C,O.startOffset),y=Math.max(y,O.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:t===a.Direction.LEFT||t===a.Direction.UP?y:C,endOffset:t===a.Direction.LEFT||t===a.Direction.UP?C:y,style:u}]);return}const f=d||m===T.RANGE_DIRECTION.FORWARD?c:l;let h=d||m===T.RANGE_DIRECTION.FORWARD?l:c;const p=(_=i.getBody().dataStream.length)!=null?_:Number.POSITIVE_INFINITY;if(t===a.Direction.LEFT||t===a.Direction.RIGHT){const C=s.findNodeByCharIndex(h-1),y=s.findNodeByCharIndex(h);h=t===a.Direction.RIGHT?h+y.count:h-((I=C==null?void 0:C.count)!=null?I:0),h=Math.min(p-2,Math.max(0,h)),this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:h,style:u}])}else{const C=s.findNodeByCharIndex(h),y=o.document.getOffsetConfig(),O=this._getTopOrBottomPosition(s,C,t===a.Direction.DOWN);if(O==null){const b=t===a.Direction.UP?0:p-2;if(b===h)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:b,style:u}]);return}const D=new T.NodePositionConvertToCursor(y,s).getRangePointData(O,O).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:D.endOffset,style:u}])}}_handleMoveCursor(t){var f,h,p;const e=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(e==null||s==null||o==null||n==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d}=e,m=(h=i.getBody().dataStream.length)!=null?h:Number.POSITIVE_INFINITY;if(t===a.Direction.LEFT||t===a.Direction.RIGHT){let S;if(!e.collapsed||n.length>1){let _=Number.POSITIVE_INFINITY,I=Number.NEGATIVE_INFINITY;for(const C of n)_=Math.min(_,C.startOffset),I=Math.max(I,C.endOffset);S=t===a.Direction.LEFT?_:I}else{const _=s.findNodeByCharIndex(c-1),I=s.findNodeByCharIndex(c);t===a.Direction.LEFT?S=Math.max(0,c-((p=_==null?void 0:_.count)!=null?p:0)):S=Math.min(m-2,l+I.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:S,endOffset:S,style:u}])}else{const S=s.findNodeByCharIndex(c),_=s.findNodeByCharIndex(l),I=o.document.getOffsetConfig(),C=this._getTopOrBottomPosition(s,t===a.Direction.UP?S:_,t===a.Direction.DOWN);if(C==null){let O;d?O=t===a.Direction.UP?0:m-2:O=t===a.Direction.UP?c:l,this._textSelectionManagerService.replaceTextRanges([{startOffset:O,endOffset:O,style:u}]);return}const y=new T.NodePositionConvertToCursor(I,s).getRangePointData(C,C).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...y,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 Number.NEGATIVE_INFINITY;const n=e.left,{left:i}=t;return n+i}_matchPositionByLeftOffset(t,e,n){const i={distance:Number.POSITIVE_INFINITY};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,C,y,O,D,b,E,P,A;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 m=d.sections.indexOf(l);if(m===-1)return;if(e===!0)c=(C=(I=d.sections[m-1])==null?void 0:I.columns[0])==null?void 0:C.lines[0];else{const R=(O=(y=d.sections)==null?void 0:y[m-1])==null?void 0:O.columns,w=R==null?void 0:R[R.length-1],L=w==null?void 0:w.lines;c=L==null?void 0:L[L.length-1]}if(c!=null)return c;const f=d.parent;if(f==null)return;const h=f.pages.indexOf(d);if(h!==-1){if(e===!0)c=(E=(b=(D=f.pages[h+1])==null?void 0:D.sections[0])==null?void 0:b.columns[0])==null?void 0:E.lines[0];else{const R=(P=f.pages[h-1])==null?void 0:P.sections;if(R==null)return;const w=(A=R[R.length-1])==null?void 0:A.columns,L=w[w.length-1],gt=L==null?void 0:L.lines;c=gt[gt.length-1]}if(c!=null)return c}}_getDocObject(){return Y(this._currentUniverService,this._renderManagerService)}};_e=mn([a.OnLifecycle(a.LifecycleStages.Rendered,_e),re(0,U.Inject(g.DocSkeletonManagerService)),re(1,a.IUniverInstanceService),re(2,T.IRenderManagerService),re(3,U.Inject(g.TextSelectionManagerService)),re(4,a.ICommandService)],_e);var gn=Object.defineProperty,fn=Object.getOwnPropertyDescriptor,hn=(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&&gn(t,e,i),i},se=(r,t)=>(e,n)=>t(e,n,r);let ve=class extends a.Disposable{constructor(t,e,n,i,s){super();M(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:m}=o,f=s.length,h=[{startOffset:u+f,endOffset:u+f,style:m}];await this._commandService.executeCommand(le.id,{unitId:n,body:{dataStream:s},range:o,textRanges:h,segmentId:d})})}_commandExecutedListener(){}_getDocObject(){return Y(this._currentUniverService,this._renderManagerService)}};ve=hn([a.OnLifecycle(a.LifecycleStages.Rendered,ve),se(0,U.Inject(g.DocSkeletonManagerService)),se(1,a.IUniverInstanceService),se(2,T.IRenderManagerService),se(3,T.ITextSelectionRenderManager),se(4,a.ICommandService)],ve);var pn=Object.defineProperty,Sn=Object.getOwnPropertyDescriptor,_n=(r,t,e,n)=>{for(var i=n>1?void 0:n?Sn(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&&pn(t,e,i),i},mt=(r,t)=>(e,n)=>t(e,n,r);const vn="rgba(198, 198, 198, 1)",In="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=>{var S,_,I,C;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:m,pageWidth:f,height:h,pageHeight:p}=c;d.save(),d.translate(l-.5,u-.5),T.Rect.drawWith(d,{width:(_=(S=i==null?void 0:i.width)!=null?S:f)!=null?_:m,height:(C=(I=i==null?void 0:i.height)!=null?I:p)!=null?C:h,strokeWidth:1,stroke:vn,fill:In,zIndex:3}),d.restore()})})}_commandExecutedListener(){}};Ie=_n([a.OnLifecycle(a.LifecycleStages.Rendered,Ie),mt(0,T.IRenderManagerService),mt(1,U.Inject(a.IUniverInstanceService))],Ie);var Cn=Object.defineProperty,Mn=Object.getOwnPropertyDescriptor,Tn=(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&&Cn(t,e,i),i},X=(r,t)=>(e,n)=>t(e,n,r);let Ce=class extends a.Disposable{constructor(t,e,n,i,s,o,c){super();M(this,"_moveInObserver");M(this,"_moveOutObserver");M(this,"_downObserver");M(this,"_dblClickObserver");M(this,"_tripleClickObserver");M(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=T.CURSOR_TYPE.TEXT}),this._moveOutObserver=n.onPointerLeaveObserver.add(()=>{n.cursor=T.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=[k.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 ft(t,this._renderManagerService)}};Ce=Tn([a.OnLifecycle(a.LifecycleStages.Rendered,Ce),X(0,U.Inject(g.DocSkeletonManagerService)),X(1,a.IUniverInstanceService),X(2,a.ICommandService),X(3,T.IRenderManagerService),X(4,T.ITextSelectionRenderManager),X(5,U.Inject(g.TextSelectionManagerService)),X(6,U.Optional(x.LayoutService))],Ce);var yn=Object.defineProperty,On=Object.getOwnPropertyDescriptor,Rn=(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&&yn(t,e,i),i},ae=(r,t)=>(e,n)=>t(e,n,r);let Me=class extends a.Disposable{constructor(t,e,n,i,s){super();M(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(lt.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=[k.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:m}=s;let f=0,h=0,p=0,S=0,_=1/0;d>(o+l*2)*e?(f=d/2-o*e/2,f/=e,p=(d-l*2)/e,_=0):(f=l,p=o+l*2,_=(p-d/e)/2),m>c?(h=m/2-c/2,S=(m-u*2)/e):(h=u,S=c+u*2),i.resize(p,S+200),n.translate(f,h);const I=i.getViewport(ce.VIEW_MAIN);if(_!==1/0&&I!=null){const C=I.getBarScroll(_,0).x;I.scrollTo({x:C})}return this}_getDocObject(){return Y(this._currentUniverService,this._renderManagerService)}};Me=Rn([a.OnLifecycle(a.LifecycleStages.Rendered,Me),ae(0,U.Inject(g.DocSkeletonManagerService)),ae(1,a.IUniverInstanceService),ae(2,a.ICommandService),ae(3,T.IRenderManagerService),ae(4,U.Inject(g.TextSelectionManagerService))],Me);const Dn={id:Ee.id,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),binding:x.KeyCode.ENTER},bn={id:we.id,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),binding:x.KeyCode.BACKSPACE},xn={id:Le.id,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),binding:x.KeyCode.DELETE},En={id:F.id,binding:x.KeyCode.ARROW_UP,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.UP}},Un={id:F.id,binding:x.KeyCode.ARROW_DOWN,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.DOWN}},Pn={id:F.id,binding:x.KeyCode.ARROW_LEFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.LEFT}},Nn={id:F.id,binding:x.KeyCode.ARROW_RIGHT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.RIGHT}},An={id:j.id,binding:x.KeyCode.ARROW_UP|x.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.UP}},wn={id:j.id,binding:x.KeyCode.ARROW_DOWN|x.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.DOWN}},Ln={id:j.id,binding:x.KeyCode.ARROW_LEFT|x.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.LEFT}},Bn={id:j.id,binding:x.KeyCode.ARROW_RIGHT|x.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.RIGHT}},$n={id:dt.id,binding:x.KeyCode.A|x.MetaKeys.CTRL_COMMAND,preconditions:r=>r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.EDITOR_ACTIVATED)};var Fn=Object.defineProperty,jn=Object.getOwnPropertyDescriptor,Vn=(r,t,e,n)=>{for(var i=n>1?void 0:n?jn(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&&Fn(t,e,i),i},Te=(r,t)=>(e,n)=>t(e,n,r);g.DocCanvasView=class extends a.RxDisposable{constructor(e,n,i,s){super();M(this,"_scene");M(this,"_currentDocumentModel");M(this,"_loadedMap",new Set);M(this,"_fps$",new N.BehaviorSubject(""));M(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 T.Viewport(ce.VIEW_MAIN,c,{left:0,top:0,bottom:0,right:0,isWheelPreventDefaultX:!0});c.attachControl(),c.on(T.EVENT_TYPE.wheel,(f,h)=>{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,h)}),this._configService.getConfig("hasScroll")!==!1&&n!==a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&new T.ScrollBar(u),c.addLayer(new T.Layer(c,[],Re),new T.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 T.Documents(oe.MAIN,void 0,{pageMarginLeft:i.documentStyle.marginLeft||0,pageMarginTop:i.documentStyle.marginTop||0});s.zIndex=We,e.mainComponent=s,e.components.set(oe.MAIN,s),n.addObjects([s],Re)}},g.DocCanvasView=Vn([a.OnLifecycle(a.LifecycleStages.Ready,g.DocCanvasView),Te(0,T.IRenderManagerService),Te(1,a.IConfigService),Te(2,a.IUniverInstanceService),Te(3,U.Inject(g.DocViewModelManagerService))],g.DocCanvasView);var kn=Object.defineProperty,Xn=Object.getOwnPropertyDescriptor,zn=(r,t,e,n)=>{for(var i=n>1?void 0:n?Xn(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&&kn(t,e,i),i},ye=(r,t)=>(e,n)=>t(e,n,r);const Wn={hasScroll:!0},Hn="docs";g.UniverDocsPlugin=(Xe=class extends a.Plugin{constructor(e={},n,i,s,o){super(Hn);M(this,"_config");this._injector=n,this._localeService=i,this._configService=s,this._currentUniverService=o,this._config=Object.assign(Wn,e),this._initializeDependencies(n),this._initializeCommands()}initialize(){}_initializeCommands(){[F,j,we,Le,z,J,Q,ee,$,V,W,H,te,je,Ee,le,de,xe,Fe,Be,v,at,ot,lt,k,De,dt,st,rt,Ve].forEach(e=>{this._injector.get(a.ICommandService).registerCommand(e)}),[En,Un,Nn,Pn,An,wn,Ln,Bn,$n,bn,xn,Dn].forEach(e=>{this._injector.get(x.IShortcutService).registerShortcut(e)})}onReady(){this.initialize()}_initializeDependencies(e){[[g.DocCanvasView],[g.DocSkeletonManagerService],[g.DocViewModelManagerService],[$e],[Z,{useClass:Ne}],[T.ITextSelectionRenderManager,{useClass:T.TextSelectionRenderManager}],[g.TextSelectionManagerService],[fe],[Ie],[Ce],[ve],[pe],[Se],[ge],[_e],[Me],[he]].forEach(n=>e.add(n))}},M(Xe,"type",a.PluginType.Doc),Xe),g.UniverDocsPlugin=zn([ye(1,U.Inject(U.Injector)),ye(2,U.Inject(a.LocaleService)),ye(3,a.IConfigService),ye(4,a.IUniverInstanceService)],g.UniverDocsPlugin),g.BreakLineCommand=Ee,g.BulletListCommand=rt,g.CoverContentCommand=ot,g.DOCS_COMPONENT_DEFAULT_Z_INDEX=We,g.DOCS_COMPONENT_HEADER_LAYER_INDEX=ze,g.DOCS_COMPONENT_MAIN_LAYER_INDEX=Re,g.DOCS_VIEW_KEY=oe,g.DeleteCommand=de,g.DeleteLeftCommand=we,g.DeleteRightCommand=Le,g.DocCopyCommand=Je,g.DocCutCommand=Qe,g.DocPasteCommand=et,g.IMEInputCommand=Fe,g.InsertCommand=le,g.MoveCursorOperation=F,g.MoveSelectionOperation=j,g.NORMAL_TEXT_SELECTION_PLUGIN_NAME=ht,g.OrderListCommand=st,g.ReplaceContentCommand=at,g.RichTextEditingMutation=v,g.SetInlineFormatBoldCommand=z,g.SetInlineFormatCommand=je,g.SetInlineFormatFontFamilyCommand=H,g.SetInlineFormatFontSizeCommand=W,g.SetInlineFormatItalicCommand=J,g.SetInlineFormatStrikethroughCommand=ee,g.SetInlineFormatSubscriptCommand=$,g.SetInlineFormatSuperscriptCommand=V,g.SetInlineFormatTextColorCommand=te,g.SetInlineFormatUnderlineCommand=Q,g.SetTextSelectionsOperation=De,g.UpdateCommand=xe,g.VIEWPORT_KEY=ce,g.getDocObject=Y,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.4",
|
|
4
|
+
"private": false,
|
|
4
5
|
"description": "UniverSheet normal base-docs",
|
|
5
|
-
"keywords": [],
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
|
-
"
|
|
9
|
-
"module": "./lib/es/index.js",
|
|
10
|
-
"types": "./lib/types/index.d.ts",
|
|
11
|
-
"publishConfig": {
|
|
12
|
-
"access": "public"
|
|
13
|
-
},
|
|
8
|
+
"keywords": [],
|
|
14
9
|
"exports": {
|
|
15
10
|
".": {
|
|
16
11
|
"import": "./lib/es/index.js",
|
|
@@ -23,43 +18,49 @@
|
|
|
23
18
|
"types": "./lib/types/index.d.ts"
|
|
24
19
|
}
|
|
25
20
|
},
|
|
21
|
+
"main": "./lib/cjs/index.js",
|
|
22
|
+
"module": "./lib/es/index.js",
|
|
23
|
+
"types": "./lib/types/index.d.ts",
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
26
27
|
"directories": {
|
|
27
28
|
"lib": "lib"
|
|
28
29
|
},
|
|
29
30
|
"files": [
|
|
30
31
|
"lib"
|
|
31
32
|
],
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
"rxjs": "^7.8.1",
|
|
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"
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=16.0.0",
|
|
35
|
+
"npm": ">=8.0.0"
|
|
40
36
|
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@wendellhu/redi": ">=0.12.13",
|
|
39
|
+
"rxjs": ">=7.0.0",
|
|
40
|
+
"@univerjs/core": "0.1.0-beta.4",
|
|
41
|
+
"@univerjs/sheets": "0.1.0-beta.4",
|
|
42
|
+
"@univerjs/engine-render": "0.1.0-beta.4",
|
|
43
|
+
"@univerjs/ui": "0.1.0-beta.4"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {},
|
|
41
46
|
"devDependencies": {
|
|
42
|
-
"@
|
|
43
|
-
"happy-dom": "^12.10.3",
|
|
47
|
+
"@wendellhu/redi": "^0.12.13",
|
|
44
48
|
"less": "^4.2.0",
|
|
49
|
+
"rxjs": "^7.8.1",
|
|
45
50
|
"typescript": "^5.3.3",
|
|
46
|
-
"vite": "^5.0.
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"@
|
|
53
|
-
"rxjs": ">=7.0.0",
|
|
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"
|
|
51
|
+
"vite": "^5.0.12",
|
|
52
|
+
"vitest": "^1.2.1",
|
|
53
|
+
"@univerjs/core": "0.1.0-beta.4",
|
|
54
|
+
"@univerjs/engine-render": "0.1.0-beta.4",
|
|
55
|
+
"@univerjs/shared": "0.1.0-beta.4",
|
|
56
|
+
"@univerjs/sheets": "0.1.0-beta.4",
|
|
57
|
+
"@univerjs/ui": "0.1.0-beta.4"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"test": "vitest run",
|
|
61
61
|
"test:watch": "vitest",
|
|
62
62
|
"coverage": "vitest run --coverage",
|
|
63
|
+
"lint:types": "tsc --noEmit",
|
|
63
64
|
"build": "tsc && vite build"
|
|
64
65
|
}
|
|
65
66
|
}
|