@univerjs/docs 0.1.0-beta.3 → 0.1.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -2
- package/lib/es/index.js +1287 -1901
- package/lib/types/basics/retain-delete-params.d.ts +1 -1
- package/lib/types/commands/commands/ime-input.command.d.ts +2 -5
- package/lib/types/commands/commands/list.command.d.ts +4 -4
- package/lib/types/commands/mutations/core-editing.mutation.d.ts +10 -4
- package/lib/types/controllers/ime-input.controller.d.ts +3 -5
- package/lib/types/controllers/text-selection.controller.d.ts +1 -3
- package/lib/types/index.d.ts +5 -2
- package/lib/types/services/doc-skeleton-manager.service.d.ts +1 -1
- package/lib/types/services/doc-state-change-manager.service.d.ts +45 -0
- package/lib/types/services/ime-input-manager.service.d.ts +12 -1
- package/lib/types/services/text-selection-manager.service.d.ts +2 -1
- package/lib/umd/index.js +1 -2
- package/package.json +24 -15
- package/lib/types/commands/commands/clipboard.command.d.ts +0 -19
- package/lib/types/controllers/clipboard.controller.d.ts +0 -33
- package/lib/types/services/clipboard/__test__/html-and-udm-convert.spec.d.ts +0 -16
- package/lib/types/services/clipboard/clipboard.service.d.ts +0 -42
- package/lib/types/services/clipboard/copy-content-cache.d.ts +0 -25
- package/lib/types/services/clipboard/html-to-udm/converter.d.ts +0 -30
- package/lib/types/services/clipboard/html-to-udm/parse-node-style.d.ts +0 -17
- package/lib/types/services/clipboard/html-to-udm/parse-to-dom.d.ts +0 -16
- package/lib/types/services/clipboard/html-to-udm/paste-plugins/plugin-lark.d.ts +0 -18
- package/lib/types/services/clipboard/html-to-udm/paste-plugins/plugin-word.d.ts +0 -18
- package/lib/types/services/clipboard/html-to-udm/paste-plugins/type.d.ts +0 -30
- package/lib/types/services/clipboard/html-to-udm/utils.d.ts +0 -18
- package/lib/types/services/clipboard/udm-to-html/convertor.d.ts +0 -19
- package/lib/types/shortcuts/core-editing.shortcut.d.ts +0 -19
- package/lib/types/shortcuts/cursor.shortcut.d.ts +0 -25
|
@@ -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
|
|
16
|
+
import { type IDeleteAction, type IRetainAction, type ITextRange } from '@univerjs/core';
|
|
17
17
|
export declare function getRetainAndDeleteFromReplace(range: ITextRange, segmentId?: string, memoryCursor?: number): Array<IRetainAction | IDeleteAction>;
|
|
@@ -13,15 +13,12 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type { ICommand
|
|
17
|
-
import type { ITextRangeWithStyle } from '@univerjs/engine-render';
|
|
16
|
+
import type { ICommand } from '@univerjs/core';
|
|
18
17
|
export interface IIMEInputCommandParams {
|
|
19
18
|
unitId: string;
|
|
20
19
|
newText: string;
|
|
21
20
|
oldTextLen: number;
|
|
22
|
-
|
|
23
|
-
textRanges: ITextRangeWithStyle[];
|
|
21
|
+
isCompositionStart: boolean;
|
|
24
22
|
isCompositionEnd: boolean;
|
|
25
|
-
segmentId?: string;
|
|
26
23
|
}
|
|
27
24
|
export declare const IMEInputCommand: ICommand<IIMEInputCommandParams>;
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import type { ICommand } from '@univerjs/core';
|
|
17
17
|
import { PresetListType } from '@univerjs/core';
|
|
18
|
+
interface IListOperationCommandParams {
|
|
19
|
+
listType: PresetListType;
|
|
20
|
+
}
|
|
21
|
+
export declare const ListOperationCommand: ICommand<IListOperationCommandParams>;
|
|
18
22
|
interface IBulletListCommandParams {
|
|
19
23
|
}
|
|
20
24
|
export declare const BulletListCommand: ICommand<IBulletListCommandParams>;
|
|
21
25
|
interface IOrderListCommandParams {
|
|
22
26
|
}
|
|
23
27
|
export declare const OrderListCommand: ICommand<IOrderListCommandParams>;
|
|
24
|
-
interface IListOperationCommandParams {
|
|
25
|
-
listType: PresetListType;
|
|
26
|
-
}
|
|
27
|
-
export declare const ListOperationCommand: ICommand<IListOperationCommandParams>;
|
|
28
28
|
export {};
|
|
@@ -13,13 +13,19 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
17
|
-
|
|
16
|
+
import type { IMutation, IMutationCommonParams, Nullable, TextXAction } from '@univerjs/core';
|
|
17
|
+
import type { ITextRangeWithStyle } from '@univerjs/engine-render';
|
|
18
|
+
export interface IRichTextEditingMutationParams extends IMutationCommonParams {
|
|
18
19
|
unitId: string;
|
|
19
|
-
|
|
20
|
+
actions: TextXAction[];
|
|
21
|
+
textRanges: Nullable<ITextRangeWithStyle[]>;
|
|
22
|
+
prevTextRanges?: Nullable<ITextRangeWithStyle[]>;
|
|
23
|
+
noNeedSetTextRange?: boolean;
|
|
24
|
+
noHistory?: boolean;
|
|
25
|
+
isCompositionEnd?: boolean;
|
|
20
26
|
}
|
|
21
27
|
/**
|
|
22
|
-
* The core mutator to change rich text
|
|
28
|
+
* The core mutator to change rich text actions. The execution result would be undo mutation params. Could be directly
|
|
23
29
|
* send to undo redo service (will be used by the triggering command).
|
|
24
30
|
*/
|
|
25
31
|
export declare const RichTextEditingMutation: IMutation<IRichTextEditingMutationParams, IRichTextEditingMutationParams>;
|
|
@@ -14,22 +14,21 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
|
|
17
|
-
import {
|
|
17
|
+
import { ITextSelectionRenderManager } from '@univerjs/engine-render';
|
|
18
18
|
import { DocSkeletonManagerService } from '../services/doc-skeleton-manager.service';
|
|
19
19
|
import { IMEInputManagerService } from '../services/ime-input-manager.service';
|
|
20
20
|
export declare class IMEInputController extends Disposable {
|
|
21
21
|
private readonly _docSkeletonManagerService;
|
|
22
22
|
private readonly _currentUniverService;
|
|
23
|
-
private readonly _renderManagerService;
|
|
24
23
|
private readonly _textSelectionRenderManager;
|
|
25
24
|
private readonly _imeInputManagerService;
|
|
26
25
|
private readonly _commandService;
|
|
27
26
|
private _previousIMEContent;
|
|
28
|
-
private
|
|
27
|
+
private _isCompositionStart;
|
|
29
28
|
private _onStartSubscription;
|
|
30
29
|
private _onUpdateSubscription;
|
|
31
30
|
private _onEndSubscription;
|
|
32
|
-
constructor(_docSkeletonManagerService: DocSkeletonManagerService, _currentUniverService: IUniverInstanceService,
|
|
31
|
+
constructor(_docSkeletonManagerService: DocSkeletonManagerService, _currentUniverService: IUniverInstanceService, _textSelectionRenderManager: ITextSelectionRenderManager, _imeInputManagerService: IMEInputManagerService, _commandService: ICommandService);
|
|
33
32
|
dispose(): void;
|
|
34
33
|
private _initialize;
|
|
35
34
|
private _initialOnCompositionstart;
|
|
@@ -37,5 +36,4 @@ export declare class IMEInputController extends Disposable {
|
|
|
37
36
|
private _initialOnCompositionend;
|
|
38
37
|
private _updateContent;
|
|
39
38
|
private _resetIME;
|
|
40
|
-
private _getDocObject;
|
|
41
39
|
}
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
|
|
17
17
|
import { IRenderManagerService, ITextSelectionRenderManager } from '@univerjs/engine-render';
|
|
18
|
-
import { LayoutService } from '@univerjs/ui';
|
|
19
18
|
import { DocSkeletonManagerService } from '../services/doc-skeleton-manager.service';
|
|
20
19
|
import { TextSelectionManagerService } from '../services/text-selection-manager.service';
|
|
21
20
|
export declare class TextSelectionController extends Disposable {
|
|
@@ -25,14 +24,13 @@ export declare class TextSelectionController extends Disposable {
|
|
|
25
24
|
private readonly _renderManagerService;
|
|
26
25
|
private readonly _textSelectionRenderManager;
|
|
27
26
|
private readonly _textSelectionManagerService;
|
|
28
|
-
private readonly _layoutService?;
|
|
29
27
|
private _moveInObserver;
|
|
30
28
|
private _moveOutObserver;
|
|
31
29
|
private _downObserver;
|
|
32
30
|
private _dblClickObserver;
|
|
33
31
|
private _tripleClickObserver;
|
|
34
32
|
private _loadedMap;
|
|
35
|
-
constructor(_docSkeletonManagerService: DocSkeletonManagerService, _currentUniverService: IUniverInstanceService, _commandService: ICommandService, _renderManagerService: IRenderManagerService, _textSelectionRenderManager: ITextSelectionRenderManager, _textSelectionManagerService: TextSelectionManagerService
|
|
33
|
+
constructor(_docSkeletonManagerService: DocSkeletonManagerService, _currentUniverService: IUniverInstanceService, _commandService: ICommandService, _renderManagerService: IRenderManagerService, _textSelectionRenderManager: ITextSelectionRenderManager, _textSelectionManagerService: TextSelectionManagerService);
|
|
36
34
|
private _initialize;
|
|
37
35
|
dispose(): void;
|
|
38
36
|
private _initialMain;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -17,7 +17,6 @@ export type { IDocObjectParam } from './basics/component-tools';
|
|
|
17
17
|
export { getDocObject } from './basics/component-tools';
|
|
18
18
|
export * from './basics/docs-view-key';
|
|
19
19
|
export { BreakLineCommand } from './commands/commands/break-line.command';
|
|
20
|
-
export { DocCopyCommand, DocCutCommand, DocPasteCommand } from './commands/commands/clipboard.command';
|
|
21
20
|
export { DeleteCommand, type ICoverCommandParams, type IDeleteCommandParams, type IInsertCommandParams, InsertCommand, type IUpdateCommandParams, UpdateCommand, } from './commands/commands/core-editing.command';
|
|
22
21
|
export { DeleteLeftCommand, DeleteRightCommand } from './commands/commands/delete.command';
|
|
23
22
|
export { type IIMEInputCommandParams, IMEInputCommand } from './commands/commands/ime-input.command';
|
|
@@ -30,5 +29,9 @@ export { type ISetTextSelectionsOperationParams, SetTextSelectionsOperation, } f
|
|
|
30
29
|
export { type IUniverDocsConfig, UniverDocsPlugin } from './doc-plugin';
|
|
31
30
|
export { DocSkeletonManagerService } from './services/doc-skeleton-manager.service';
|
|
32
31
|
export { DocViewModelManagerService } from './services/doc-view-model-manager.service';
|
|
33
|
-
export { TextSelectionManagerService } from './services/text-selection-manager.service';
|
|
32
|
+
export { TextSelectionManagerService, serializeTextRange } from './services/text-selection-manager.service';
|
|
33
|
+
export { DocStateChangeManagerService, type IDocStateChangeParams } from './services/doc-state-change-manager.service';
|
|
34
|
+
export { IMEInputManagerService } from './services/ime-input-manager.service';
|
|
34
35
|
export { DocCanvasView } from './views/doc-canvas-view';
|
|
36
|
+
export { SelectAllOperation } from './commands/operations/select-all.operation';
|
|
37
|
+
export { CutContentCommand, InnerPasteCommand } from './commands/commands/clipboard.inner.command';
|
|
@@ -23,7 +23,7 @@ export interface IDocSkeletonManagerParam {
|
|
|
23
23
|
dirty: boolean;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
|
-
* This service is for
|
|
26
|
+
* This service is for document build and manage doc skeletons.
|
|
27
27
|
*/
|
|
28
28
|
export declare class DocSkeletonManagerService extends RxDisposable {
|
|
29
29
|
private readonly _localeService;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { Nullable, TextXAction } from '@univerjs/core';
|
|
17
|
+
import { ICommandService, IUndoRedoService, IUniverInstanceService, RxDisposable } from '@univerjs/core';
|
|
18
|
+
import type { ITextRangeWithStyle } from '@univerjs/engine-render';
|
|
19
|
+
interface IDocChangeState {
|
|
20
|
+
actions: TextXAction[];
|
|
21
|
+
textRanges: Nullable<ITextRangeWithStyle[]>;
|
|
22
|
+
}
|
|
23
|
+
export interface IDocStateChangeParams {
|
|
24
|
+
commandId: string;
|
|
25
|
+
unitId: string;
|
|
26
|
+
trigger: Nullable<string>;
|
|
27
|
+
redoState: IDocChangeState;
|
|
28
|
+
undoState: IDocChangeState;
|
|
29
|
+
noHistory?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare class DocStateChangeManagerService extends RxDisposable {
|
|
32
|
+
private _undoRedoService;
|
|
33
|
+
private readonly _commandService;
|
|
34
|
+
private readonly _univerInstanceService;
|
|
35
|
+
private readonly _docStateChange$;
|
|
36
|
+
readonly docStateChange$: import("rxjs").Observable<Nullable<IDocStateChangeParams>>;
|
|
37
|
+
private _stateCache;
|
|
38
|
+
private _timer;
|
|
39
|
+
constructor(_undoRedoService: IUndoRedoService, _commandService: ICommandService, _univerInstanceService: IUniverInstanceService);
|
|
40
|
+
setChangeState(changeState: IDocStateChangeParams): void;
|
|
41
|
+
private _initialize;
|
|
42
|
+
private _cacheChangeState;
|
|
43
|
+
private _pushHistory;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
|
@@ -17,17 +17,28 @@ import type { Nullable } from '@univerjs/core';
|
|
|
17
17
|
import type { ITextRangeWithStyle } from '@univerjs/engine-render';
|
|
18
18
|
import type { IDisposable } from '@wendellhu/redi';
|
|
19
19
|
import type { IRichTextEditingMutationParams } from '../commands/mutations/core-editing.mutation';
|
|
20
|
+
interface ICacheParams {
|
|
21
|
+
undoCache: IRichTextEditingMutationParams[];
|
|
22
|
+
redoCache: IRichTextEditingMutationParams[];
|
|
23
|
+
}
|
|
20
24
|
export declare class IMEInputManagerService implements IDisposable {
|
|
21
25
|
private _previousActiveRange;
|
|
22
26
|
private _undoMutationParamsCache;
|
|
23
27
|
private _redoMutationParamsCache;
|
|
24
28
|
clearUndoRedoMutationParamsCache(): void;
|
|
29
|
+
getUndoRedoMutationParamsCache(): {
|
|
30
|
+
undoCache: IRichTextEditingMutationParams[];
|
|
31
|
+
redoCache: IRichTextEditingMutationParams[];
|
|
32
|
+
};
|
|
33
|
+
setUndoRedoMutationParamsCache({ undoCache, redoCache }: ICacheParams): void;
|
|
34
|
+
getActiveRange(): Nullable<ITextRangeWithStyle>;
|
|
25
35
|
setActiveRange(range: Nullable<ITextRangeWithStyle>): void;
|
|
26
36
|
pushUndoRedoMutationParams(undoParams: IRichTextEditingMutationParams, redoParams: IRichTextEditingMutationParams): void;
|
|
27
|
-
fetchComposedUndoRedoMutationParams(
|
|
37
|
+
fetchComposedUndoRedoMutationParams(): {
|
|
28
38
|
redoMutationParams: IRichTextEditingMutationParams;
|
|
29
39
|
undoMutationParams: IRichTextEditingMutationParams;
|
|
30
40
|
previousActiveRange: ITextRangeWithStyle;
|
|
31
41
|
} | null;
|
|
32
42
|
dispose(): void;
|
|
33
43
|
}
|
|
44
|
+
export {};
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import type { Nullable } from '@univerjs/core';
|
|
17
17
|
import { ICommandService, RxDisposable } from '@univerjs/core';
|
|
18
|
-
import type { INodePosition, ISuccinctTextRangeParam, ITextSelectionInnerParam, ITextSelectionStyle, RANGE_DIRECTION, TextRange } from '@univerjs/engine-render';
|
|
18
|
+
import type { INodePosition, ISuccinctTextRangeParam, ITextRangeWithStyle, ITextSelectionInnerParam, ITextSelectionStyle, RANGE_DIRECTION, TextRange } from '@univerjs/engine-render';
|
|
19
19
|
import { ITextSelectionRenderManager } from '@univerjs/engine-render';
|
|
20
20
|
interface ITextSelectionManagerSearchParam {
|
|
21
21
|
unitId: string;
|
|
@@ -33,6 +33,7 @@ export interface ITextActiveRange {
|
|
|
33
33
|
}
|
|
34
34
|
interface ITextSelectionManagerInsertParam extends ITextSelectionManagerSearchParam, ITextSelectionInnerParam {
|
|
35
35
|
}
|
|
36
|
+
export declare function serializeTextRange(textRange: TextRange): ITextRangeWithStyle;
|
|
36
37
|
/**
|
|
37
38
|
* This service is for text selection.
|
|
38
39
|
*/
|
package/lib/umd/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
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,D,E){"use strict";var Gn=Object.defineProperty;var Xn=(m,a,M)=>a in m?Gn(m,a,{enumerable:!0,configurable:!0,writable:!0,value:M}):m[a]=M;var I=(m,a,M)=>(Xn(m,typeof a!="symbol"?a+"":a,M),M);var ke;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 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 De=0,ze=2,We=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},Ge=(r,t)=>(e,n)=>t(e,n,r);function Xe(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();I(this,"_currentSelection",null);I(this,"_textSelectionInfo",new Map);I(this,"_textSelection$",new N.BehaviorSubject(null));I(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:p}=o;return c==null||l==null?null:{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:f,direction:p,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(Xe)})}_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(Xe))}_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([Ge(0,M.ITextSelectionRenderManager),Ge(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},It=(r,t)=>(e,n)=>t(e,n,r);m.DocViewModelManagerService=class extends a.RxDisposable{constructor(e){super();I(this,"_currentViewModelUnitId","");I(this,"_docViewModelMap",new Map);I(this,"_currentDocViewModel$",new N.BehaviorSubject(null));I(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([It(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,p={id:v.id,params:{unitId:l,mutations:[]}},g=new a.TextX;f?d>0&&g.push({t:"r",len:d,segmentId:o}):g.push(...oe(s,o)),g.push({t:"i",body:c,len:c.dataStream.length,line:0,segmentId:o}),p.params.mutations=g.serialize();const h=n.syncExecuteCommand(p.id,p.params);return i.replaceTextRanges(u),h?(e.pushUndoRedo({unitID:l,undoMutations:[{id:v.id,params:h}],redoMutations:[{id:v.id,params:p.params}],undo(){return n.syncExecuteCommand(v.id,h),i.replaceTextRanges([s]),!0},redo(){return n.syncExecuteCommand(v.id,p.params),i.replaceTextRanges(u),!0}}),!0):!1}};var B=(r=>(r[r.LEFT=0]="LEFT",r[r.RIGHT=1]="RIGHT",r))(B||{});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,p={id:v.id,params:{unitId:c,mutations:[]}},g=new a.TextX;f>0&&g.push({t:"r",len:l===0?f-d:f,segmentId:o}),g.push({t:"d",len:d,line:0,segmentId:o}),p.params.mutations=g.serialize();const h=e.syncExecuteCommand(p.id,p.params);return i.replaceTextRanges(u),h&&n.pushUndoRedo({unitID:c,undoMutations:[{id:v.id,params:h}],redoMutations:[{id:v.id,params:p.params}],undo(){return e.syncExecuteCommand(v.id,h),i.replaceTextRanges([s]),!0},redo(){return e.syncExecuteCommand(v.id,p.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:[]}},p=new a.TextX,{startOffset:g,endOffset:h}=e;p.push({t:"r",len:g,segmentId:n}),p.push({t:"r",body:i,len:h-g,segmentId:n,coverType:s}),f.params.mutations=p.serialize();const S=l.syncExecuteCommand(f.id,f.params);return d.replaceTextRanges(c),S?(u.pushUndoRedo({unitID:o,undoMutations:[{id:v.id,params:S}],redoMutations:[{id:v.id,params:f.params}],undo(){return l.syncExecuteCommand(v.id,S),d.replaceTextRanges(c),!0},redo(){return l.syncExecuteCommand(v.id,f.params),d.replaceTextRanges(c),!0}}),!0):!1}};function Ct(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 h;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}],p=(((h=s.getBody())==null?void 0:h.paragraphs)??[]).find(S=>S.startIndex>=c);return await n.executeCommand(ce.id,{unitId:o,body:{dataStream:a.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Ct(a.DataStreamTreeTokenType.PARAGRAPH,p)},range:i,textRanges:d,segmentId:l})}},de={id:D.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:999,preconditions:r=>r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.EDITOR_ACTIVATED),handler:async()=>!0},ue={id:D.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:999,preconditions:r=>r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.EDITOR_ACTIVATED),handler:async()=>!0},me={id:D.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:999,preconditions:r=>r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.EDITOR_ACTIVATED),handler:async()=>!0};var Mt=Object.defineProperty,Ot=Object.getOwnPropertyDescriptor,Rt=(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},He=(r,t)=>(e,n)=>t(e,n,r);m.DocSkeletonManagerService=class extends a.RxDisposable{constructor(e,n){super();I(this,"_currentSkeletonUnitId","");I(this,"_docSkeletonMap",new Map);I(this,"_currentSkeleton$",new N.BehaviorSubject(null));I(this,"currentSkeleton$",this._currentSkeleton$.asObservable());I(this,"_currentSkeletonBefore$",new N.BehaviorSubject(null));I(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=Rt([He(0,E.Inject(a.LocaleService)),He(1,E.Inject(m.DocViewModelManagerService))],m.DocSkeletonManagerService);const Ke={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(),p={id:v.id,params:{unitId:f,mutations:[]}},g=new a.MemoryCursor;g.reset();const h=new a.TextX;for(const _ of u){const{startOffset:C,endOffset:O,collapsed:b}=_,x=C-g.cursor;b?h.push({t:"r",len:x,segmentId:e}):h.push(...oe(_,e,g.cursor)),h.push({t:"i",body:n,len:n.dataStream.length,line:0,segmentId:e}),g.reset(),g.moveCursor(O)}p.params.mutations=h.serialize();const S=o.syncExecuteCommand(p.id,p.params);return c.replaceTextRanges(i),S?(s.pushUndoRedo({unitID:f,undoMutations:[{id:v.id,params:S}],redoMutations:[{id:v.id,params:p.params}],undo(){return o.syncExecuteCommand(v.id,S),c.replaceTextRanges(u),!0},redo(){return o.syncExecuteCommand(v.id,p.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 p={id:v.id,params:{unitId:u,mutations:[]}},g=new a.MemoryCursor;g.reset();const h=new a.TextX;for(const _ of l){const{startOffset:C,endOffset:O,collapsed:b}=_,x=C-g.cursor;b?h.push({t:"r",len:x,segmentId:e}):h.push(...yt(_,f,e,g.cursor)),g.reset(),g.moveCursor(O)}p.params.mutations=h.serialize();const S=s.syncExecuteCommand(p.id,p.params);return o.replaceTextRanges(n),S?(i.pushUndoRedo({unitID:u,undoMutations:[{id:v.id,params:S}],redoMutations:[{id:v.id,params:p.params}],undo(){return s.syncExecuteCommand(v.id,S),o.replaceTextRanges(l),!0},redo(){return s.syncExecuteCommand(v.id,p.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(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 x;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=(x=e.getCurrent())==null?void 0:x.skeleton;let l=!0;if(s==null||c==null||o==null)return!1;const u=n.getCurrentUniverDocInstance(),{startOffset:d,collapsed:f,segmentId:p,style:g}=s,h=c.findNodeByCharIndex(d),S=M.hasListSpan(h),_=M.isIndentBySpan(h,u.getBody());let C=d;const O=c.findNodeByCharIndex(d-1);if(M.isFirstSpan(h)&&O!==h&&(S===!0||_===!0)){const R=M.getParagraphBySpan(h,u.getBody());if(R==null)return!1;const T=R==null?void 0:R.startIndex,U={startIndex:0},P=R.paragraphStyle;if(S===!0){const y=R.paragraphStyle;y&&(U.paragraphStyle=y)}else if(_===!0){const y=R.bullet;y&&(U.bullet=y),P!=null&&(U.paragraphStyle={...P},delete U.paragraphStyle.hanging,delete U.paragraphStyle.indentStart)}const w=[{startOffset:C,endOffset:C,style:g}];l=await i.executeCommand(xe.id,{unitId:u.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...U}]},range:{startOffset:T,endOffset:T+1},textRanges:w,coverType:a.UpdateDocsAttributeType.REPLACE,segmentId:p})}else if(f===!0){if(O==null)return!0;if(O.content==="\r")l=await i.executeCommand(Ne.id,{direction:B.LEFT,range:s});else{C-=O.count;const R=[{startOffset:C,endOffset:C,style:g}];l=await i.executeCommand(le.id,{unitId:u.getUnitId(),range:s,segmentId:p,direction:B.LEFT,len:O.count,textRanges:R})}}else{const R=Ye(s,o);l=await i.executeCommand(ge.id,{segmentId:p,textRanges:R})}return l}},Pe={id:"doc.command.delete-right",type:a.CommandType.COMMAND,handler:async r=>{var h;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=(h=e.getCurrent())==null?void 0:h.skeleton;let l;if(s==null||c==null||o==null)return!1;const u=n.getCurrentUniverDocInstance(),{startOffset:d,collapsed:f,segmentId:p,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:B.RIGHT,range:s});else{const _=[{startOffset:d,endOffset:d,style:g}];l=await i.executeCommand(le.id,{unitId:u.getUnitId(),range:s,segmentId:p,direction:B.RIGHT,textRanges:_,len:S.count})}}else{const S=Ye(s,o);l=await i.executeCommand(ge.id,{segmentId:p,textRanges:S})}return l}},Ne={id:"doc.command.merge-two-paragraph",type:a.CommandType.COMMAND,handler:async(r,t)=>{var P,w,y;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:p,segmentId:g,style:h}=l;if(!p)return!1;const S=o===B.LEFT?f:f+1,_=(y=(w=(P=d.getBody())==null?void 0:P.paragraphs)==null?void 0:w.find(L=>L.startIndex>=S))==null?void 0:y.startIndex,C=Tt(d.getBody(),S,_),O=o===B.LEFT?f-1:f,b=d.getUnitId(),x=[{startOffset:O,endOffset:O,style:h}],R={id:v.id,params:{unitId:b,mutations:[]}},T=new a.TextX;T.push({t:"r",len:o===B.LEFT?f-1:f,segmentId:g}),C.dataStream.length&&T.push({t:"i",body:C,len:C.dataStream.length,line:0,segmentId:g}),T.push({t:"r",len:1,segmentId:g}),T.push({t:"d",len:_+1-S,line:0,segmentId:g}),R.params.mutations=T.serialize();const U=i.syncExecuteCommand(R.id,R.params);return e.replaceTextRanges(x),U?(s.pushUndoRedo({unitID:b,undoMutations:[{id:v.id,params:U}],redoMutations:[{id:v.id,params:R.params}],undo(){return i.syncExecuteCommand(v.id,U),e.replaceTextRanges([c]),!0},redo(){return i.syncExecuteCommand(v.id,R.params),e.replaceTextRanges(x),!0}}),!0):!1}};function Tt(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 Ye(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(){I(this,"_previousActiveRange",null);I(this,"_undoMutationParamsCache",[]);I(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),p=r.get(we),g={id:v.id,params:{unitId:e,mutations:[]}},h=new a.TextX;s.collapsed?h.push({t:"r",len:s.startOffset,segmentId:o}):h.push(...oe(s,o)),i>0&&h.push({t:"d",len:i,line:0,segmentId:o}),h.push({t:"i",body:{dataStream:n},len:n.length,line:0,segmentId:o}),g.params.mutations=h.serialize();const S=u.syncExecuteCommand(g.id,g.params);if(p.pushUndoRedoMutationParams(S,g.params),f.replaceTextRanges(c),l){if(S){const _=p.fetchComposedUndoRedoMutationParams(n);if(_==null)return!1;const{undoMutationParams:C,redoMutationParams:O,previousActiveRange:b}=_;return d.pushUndoRedo({unitID:e,undoMutations:[{id:v.id,params:C}],redoMutations:[{id:v.id,params:O}],undo(){return u.syncExecuteCommand(v.id,C),f.replaceTextRanges([b]),!0},redo(){return u.syncExecuteCommand(v.id,O),f.replaceTextRanges(c),!0}}),!0}}else return!!S;return!1}},W={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},$={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},G={id:"doc.command.set-inline-format-fontsize",type:a.CommandType.COMMAND,handler:async()=>!0},X={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={[W.id]:"bl",[q.id]:"it",[Z.id]:"ul",[J.id]:"st",[G.id]:"fs",[X.id]:"ff",[Q.id]:"cl",[$.id]:"va",[V.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 p;switch(i){case W.id:case q.id:case Z.id:case J.id:case $.id:case V.id:{p=bt(d.getBody().textRuns,i,u);break}case G.id:case X.id:{p=n;break}case Q.id:{p={rgb:n};break}default:throw new Error(`Unknown command: ${i} in handleInlineFormat`)}const g={id:v.id,params:{unitId:f,mutations:[]}},h=new a.TextX,S=new a.MemoryCursor;S.reset();for(const O of u){const{startOffset:b,endOffset:x}=O,R={dataStream:"",textRuns:[{st:0,ed:x-b,ts:{[qe[i]]:p}}]},T=b-S.cursor;T!==0&&h.push({t:"r",len:T,segmentId:e}),h.push({t:"r",body:R,len:x-b,segmentId:e}),S.reset(),S.moveCursor(x)}g.params.mutations=h.serialize();const _=o.syncExecuteCommand(g.id,g.params),C=[W.id,G.id,X.id,$.id,V.id];return C.includes(i)&&c.refreshSelection(),_?(s.pushUndoRedo({unitID:f,undoMutations:[{id:v.id,params:_}],redoMutations:[{id:v.id,params:g.params}],undo(){return o.syncExecuteCommand(v.id,_),C.includes(i)&&c.refreshSelection(),!0},redo(){return o.syncExecuteCommand(v.id,g.params),C.includes(i)&&c.refreshSelection(),!0}}),!0):!1}};function Dt(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===$.id?a.BaselineOffset.SUBSCRIPT:a.BaselineOffset.SUPERSCRIPT}if(Dt(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 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,p=c.getUnitId(),g=d.every(R=>{var T;return((T=R.bullet)==null?void 0:T.listType)===o}),h=6;let S=a.Tools.generateRandomId(h);if(d.length===1){const R=u.indexOf(d[0]),T=u[R-1],U=u[R+1];T&&T.bullet&&T.bullet.listType===o?S=T.bullet.listId:U&&U.bullet&&U.bullet.listType===o&&(S=U.bullet.listId)}const _={id:v.id,params:{unitId:p,mutations:[]}},C=new a.MemoryCursor;C.reset();const O=new a.TextX;for(const R of d){const{startIndex:T}=R;O.push({t:"r",len:T-C.cursor,segmentId:f});const U={...R.paragraphStyle,hanging:void 0,indentStart:void 0};O.push({t:"r",len:1,body:{dataStream:"",paragraphs:[g?{paragraphStyle:U,startIndex:0}:{...R,startIndex:0,bullet:{...R.bullet??{nestingLevel:0,textStyle:{fs:20}},listType:o,listId:S}}]},segmentId:f,coverType:a.UpdateDocsAttributeType.REPLACE}),C.moveCursorTo(T+1)}_.params.mutations=O.serialize();const b=i.syncExecuteCommand(_.id,_.params);return e.refreshSelection(),b&&s.pushUndoRedo({unitID:p,undoMutations:[{id:v.id,params:b}],redoMutations:[{id:v.id,params:_.params}],undo(){return i.syncExecuteCommand(v.id,b),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 h;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=(h=o.getUniverDocInstance(e))==null?void 0:h.getSnapshot().body,f=l.getSelections();if(d==null||!Array.isArray(f)||f.length===0)return!1;const p=tt(e,s,d,n),g=c.syncExecuteCommand(p.id,p.params);return l.replaceTextRanges(i),g?(u.pushUndoRedo({unitID:e,undoMutations:[{id:v.id,params:g}],redoMutations:[{id:v.id,params:p.params}],undo(){return c.syncExecuteCommand(v.id,g),l.replaceTextRanges(f),!0},redo(){return c.syncExecuteCommand(v.id,p.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=new a.TextX,o=(e==null?void 0:e.dataStream.length)-2;return o>0&&s.push({t:"d",len:o,line:0,segmentId:t}),n.dataStream.length>0&&s.push({t:"i",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},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}},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}},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(k.id,l)?(n.pushUndoRedo({unitID:s,undoMutations:[{id:k.id,params:u}],redoMutations:[{id:k.id,params:l}]}),!0):!1}},it={id:"doc.operation.select-all",type:a.CommandType.COMMAND,handler:async r=>{const 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(){I(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 Te=class Te{constructor(){I(this,"_styleCache",new Map);I(this,"_styleRules",[]);I(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=Te._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)}}};I(Te,"_pluginList",[]);let ee=Te;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:p,cl:g,va:h}=i;let S=r.slice(e,n);const _=[];return c===a.BooleanNumber.TRUE&&(S=`<i>${S}</i>`),h===a.BaselineOffset.SUPERSCRIPT?S=`<sup>${S}</sup>`:h===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"),p&&_.push(`background: ${p.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:p,paragraphStyle:g={}}=f;if(p>=u&&p<=d){const{spaceAbove:h,spaceBelow:S}=g,_=[];h!=null&&(typeof h=="number"?_.push(`margin-top: ${h}px`):_.push(`margin-top: ${h.v}px`)),S!=null&&(typeof S=="number"?_.push(`margin-bottom: ${S}px`):_.push(`margin-bottom: ${S.v}px`)),c.push(`<p className="UniverNormal" ${_.length?`style="${_.join(";")}"`:""}>${o.join("")}</p>`),o.length=0}}}return c.join("")+o.join("")}class Vt{convert(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 kt=Object.defineProperty,zt=Object.getOwnPropertyDescriptor,Wt=(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&&kt(t,e,i),i},ot=(r,t)=>(e,n)=>t(e,n,r);ee.use(Ft),ee.use($t);function Gt(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=E.createIdentifier("doc.clipboard-service");let je=class extends a.Disposable{constructor(t,e){super();I(this,"_clipboardHooks",[]);I(this,"_htmlToUDM",new ee);I(this,"_umdToHtml",new Vt);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===D.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await s.getType(o).then(c=>c&&c.text()):o===D.HTML_CLIPBOARD_MIME_TYPE&&(e=await s.getType(o).then(c=>c&&c.text()));if(!e)return Gt(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=Wt([ot(0,a.IUniverInstanceService),ot(1,D.IClipboardInterfaceService)],je);var Xt=Object.defineProperty,Ht=Object.getOwnPropertyDescriptor,Kt=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ht(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},H=(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))),[Ke,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.EDITOR_ACTIVATED)))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(Ke.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=Kt([a.OnLifecycle(a.LifecycleStages.Rendered,he),H(0,a.ILogService),H(1,a.ICommandService),H(2,a.IUniverInstanceService),H(3,ct),H(4,E.Inject(m.TextSelectionManagerService)),H(5,a.IContextService)],he);var Yt=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&&Yt(t,e,i),i},Ve=(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 p=s[d],{pageWidth:g,pageHeight:h}=p;i.pageLayoutType===M.PageLayoutType.VERTICAL?(c+=h,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,h))}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),Ve(0,E.Inject(m.DocSkeletonManagerService)),Ve(1,M.IRenderManagerService),Ve(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();I(this,"_liquid",new M.Liquid);I(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(p=>{const{unitId:g,subUnitId:h,floatingObjectId:S,floatingObject:_}=p,{left:C=0,top:O=0,width:b=0,height:x=0,angle:R,flipX:T,flipY:U,skewX:P,skewY:w}=_,y=this._pageMarginCache.get(S),L=(y==null?void 0:y.marginLeft)||0,A=(y==null?void 0:y.marginTop)||0;i==null||i.getViewModel().getDataModel().updateDrawing(S,{left:C-d-L,top:O-f-A,height:x,width:b})}),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:f,pageMarginTop:p}=c,{pages:g}=i,h=[];o.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let S=0,_=g.length;S<_;S++){const C=g[S],{skeDrawings:O,marginLeft:b,marginTop:x}=C;this._liquid.translatePagePadding(C),O.forEach(R=>{const{aLeft:T,aTop:U,height:P,width:w,objectId:y}=R;h.push({unitId:t,subUnitId:a.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:y,floatingObject:{left:T+l+this._liquid.x,top:U+u+this._liquid.y,width:w,height:P}}),this._pageMarginCache.set(y,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.translatePage(C,d,f,p)}this._floatingObjectManagerService.BatchAddOrUpdate(h)}};pe=en([a.OnLifecycle(a.LifecycleStages.Steady,pe),te(0,E.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},K=(r,t)=>(e,n)=>t(e,n,r);let Se=class extends a.Disposable{constructor(t,e,n,i,s,o){super();I(this,"_previousIMEContent","");I(this,"_previousIMERange");I(this,"_onStartSubscription");I(this,"_onUpdateSubscription");I(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 h;const n=(h=this._docSkeletonManagerService.getCurrent())==null?void 0:h.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 p=f.length,g=[{startOffset:c+p,endOffset:c+p,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 Y(this._currentUniverService,this._renderManagerService)}};Se=rn([a.OnLifecycle(a.LifecycleStages.Rendered,Se),K(0,E.Inject(m.DocSkeletonManagerService)),K(1,a.IUniverInstanceService),K(2,M.IRenderManagerService),K(3,M.ITextSelectionRenderManager),K(4,E.Inject(we)),K(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=[W.id,q.id,Z.id,J.id,$.id,V.id,G.id,X.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,E.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();I(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;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 _=Number.POSITIVE_INFINITY,C=Number.NEGATIVE_INFINITY;for(const O of n)_=Math.min(_,O.startOffset),C=Math.max(C,O.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:t===a.Direction.LEFT||t===a.Direction.UP?C:_,endOffset:t===a.Direction.LEFT||t===a.Direction.UP?_:C,style:u}]);return}const p=d||f===M.RANGE_DIRECTION.FORWARD?c:l;let g=d||f===M.RANGE_DIRECTION.FORWARD?l:c;const h=i.getBody().dataStream.length??Number.POSITIVE_INFINITY;if(t===a.Direction.LEFT||t===a.Direction.RIGHT){const _=s.findNodeByCharIndex(g-1),C=s.findNodeByCharIndex(g);g=t===a.Direction.RIGHT?g+C.count:g-((_==null?void 0:_.count)??0),g=Math.min(h-2,Math.max(0,g)),this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:g,style:u}])}else{const _=s.findNodeByCharIndex(g),C=o.document.getOffsetConfig(),O=this._getTopOrBottomPosition(s,_,t===a.Direction.DOWN);if(O==null){const x=t===a.Direction.UP?0:h-2;if(x===g)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:x,style:u}]);return}const b=new M.NodePositionConvertToCursor(C,s).getRangePointData(O,O).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:b.endOffset,style:u}])}}_handleMoveCursor(t){var p;const e=this._textSelectionManagerService.getActiveRange(),n=this._textSelectionManagerService.getSelections(),i=this._currentUniverService.getCurrentUniverDocInstance(),s=(p=this._docSkeletonManagerService.getCurrent())==null?void 0:p.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??Number.POSITIVE_INFINITY;if(t===a.Direction.LEFT||t===a.Direction.RIGHT){let g;if(!e.collapsed||n.length>1){let h=Number.POSITIVE_INFINITY,S=Number.NEGATIVE_INFINITY;for(const _ of n)h=Math.min(h,_.startOffset),S=Math.max(S,_.endOffset);g=t===a.Direction.LEFT?h:S}else{const h=s.findNodeByCharIndex(c-1),S=s.findNodeByCharIndex(c);t===a.Direction.LEFT?g=Math.max(0,c-((h==null?void 0:h.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),h=s.findNodeByCharIndex(l),S=o.document.getOffsetConfig(),_=this._getTopOrBottomPosition(s,t===a.Direction.UP?g:h,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 C=new M.NodePositionConvertToCursor(S,s).getRangePointData(_,_).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...C,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 h,S,_,C,O,b,x,R,T,U,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=(h=l.columns[u+1])==null?void 0:h.lines[0];else{const y=(_=(S=l.columns)==null?void 0:S[u-1])==null?void 0:_.lines;c=y==null?void 0:y[y.length-1]}if(c!=null)return c;const d=l.parent;if(d==null)return;const f=d.sections.indexOf(l);if(f===-1)return;if(e===!0)c=(O=(C=d.sections[f-1])==null?void 0:C.columns[0])==null?void 0:O.lines[0];else{const y=(x=(b=d.sections)==null?void 0:b[f-1])==null?void 0:x.columns,L=y==null?void 0:y[y.length-1],A=L==null?void 0:L.lines;c=A==null?void 0:A[A.length-1]}if(c!=null)return c;const p=d.parent;if(p==null)return;const g=p.pages.indexOf(d);if(g!==-1){if(e===!0)c=(U=(T=(R=p.pages[g+1])==null?void 0:R.sections[0])==null?void 0:T.columns[0])==null?void 0:U.lines[0];else{const y=(P=p.pages[g-1])==null?void 0:P.sections;if(y==null)return;const L=(w=y[y.length-1])==null?void 0:w.columns,A=L[L.length-1],ut=A==null?void 0:A.lines;c=ut[ut.length-1]}if(c!=null)return c}}_getDocObject(){return Y(this._currentUniverService,this._renderManagerService)}};ve=dn([a.OnLifecycle(a.LifecycleStages.Rendered,ve),ne(0,E.Inject(m.DocSkeletonManagerService)),ne(1,a.IUniverInstanceService),ne(2,M.IRenderManagerService),ne(3,E.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 Ie=class extends a.Disposable{constructor(t,e,n,i,s){super();I(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 h;if(t==null)return;const n=this._currentUniverService.getCurrentUniverDocInstance().getUnitId(),{event:i,content:s="",activeRange:o}=t,c=i,l=(h=this._docSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(c.data==null||l==null||!l||!o)return;const{startOffset:u,segmentId:d,style:f}=o,p=s.length,g=[{startOffset:u+p,endOffset:u+p,style:f}];await this._commandService.executeCommand(ce.id,{unitId:n,body:{dataStream:s},range:o,textRanges:g,segmentId:d})})}_commandExecutedListener(){}_getDocObject(){return Y(this._currentUniverService,this._renderManagerService)}};Ie=gn([a.OnLifecycle(a.LifecycleStages.Rendered,Ie),ie(0,E.Inject(m.DocSkeletonManagerService)),ie(1,a.IUniverInstanceService),ie(2,M.IRenderManagerService),ie(3,M.ITextSelectionRenderManager),ie(4,a.ICommandService)],Ie);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 Ce=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:p,height:g,pageHeight:h}=c;d.save(),d.translate(l-.5,u-.5),M.Rect.drawWith(d,{width:(i==null?void 0:i.width)??p??f,height:(i==null?void 0:i.height)??h??g,strokeWidth:1,stroke:Sn,fill:_n,zIndex:3}),d.restore()})})}_commandExecutedListener(){}};Ce=pn([a.OnLifecycle(a.LifecycleStages.Rendered,Ce),dt(0,M.IRenderManagerService),dt(1,E.Inject(a.IUniverInstanceService))],Ce);var vn=Object.defineProperty,In=Object.getOwnPropertyDescriptor,Cn=(r,t,e,n)=>{for(var i=n>1?void 0:n?In(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();I(this,"_moveInObserver");I(this,"_moveOutObserver");I(this,"_downObserver");I(this,"_dblClickObserver");I(this,"_tripleClickObserver");I(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=[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 mt(t,this._renderManagerService)}};Me=Cn([a.OnLifecycle(a.LifecycleStages.Rendered,Me),z(0,E.Inject(m.DocSkeletonManagerService)),z(1,a.IUniverInstanceService),z(2,a.ICommandService),z(3,M.IRenderManagerService),z(4,M.ITextSelectionRenderManager),z(5,E.Inject(m.TextSelectionManagerService)),z(6,E.Optional(D.LayoutService))],Me);var Mn=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&&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();I(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=[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:f}=s;let p=0,g=0,h=0,S=0,_=1/0;d>(o+l*2)*e?(p=d/2-o*e/2,p/=e,h=(d-l*2)/e,_=0):(p=l,h=o+l*2,_=(h-d/e)/2),f>c?(g=f/2-c/2,S=(f-u*2)/e):(g=u,S=c+u*2),i.resize(h,S+200),n.translate(p,g);const C=i.getViewport(ae.VIEW_MAIN);if(_!==1/0&&C!=null){const O=C.getBarScroll(_,0).x;C.scrollTo({x:O})}return this}_getDocObject(){return Y(this._currentUniverService,this._renderManagerService)}};Oe=Rn([a.OnLifecycle(a.LifecycleStages.Rendered,Oe),re(0,E.Inject(m.DocSkeletonManagerService)),re(1,a.IUniverInstanceService),re(2,a.ICommandService),re(3,M.IRenderManagerService),re(4,E.Inject(m.TextSelectionManagerService))],Oe);const yn={id:Ue.id,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),binding:D.KeyCode.ENTER},Tn={id:Ee.id,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),binding:D.KeyCode.BACKSPACE},Dn={id:Pe.id,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),binding:D.KeyCode.DELETE},bn={id:F.id,binding:D.KeyCode.ARROW_UP,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.UP}},xn={id:F.id,binding:D.KeyCode.ARROW_DOWN,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.DOWN}},Un={id:F.id,binding:D.KeyCode.ARROW_LEFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.LEFT}},En={id:F.id,binding:D.KeyCode.ARROW_RIGHT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.RIGHT}},Pn={id:j.id,binding:D.KeyCode.ARROW_UP|D.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.UP}},Nn={id:j.id,binding:D.KeyCode.ARROW_DOWN|D.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.DOWN}},wn={id:j.id,binding:D.KeyCode.ARROW_LEFT|D.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.LEFT}},Ln={id:j.id,binding:D.KeyCode.ARROW_RIGHT|D.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.RIGHT}},An={id:it.id,binding:D.KeyCode.A|D.MetaKeys.CTRL_COMMAND,preconditions:r=>r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.EDITOR_ACTIVATED)};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},Re=(r,t)=>(e,n)=>t(e,n,r);m.DocCanvasView=class extends a.RxDisposable{constructor(e,n,i,s){super();I(this,"_scene");I(this,"_currentDocumentModel");I(this,"_loadedMap",new Set);I(this,"_fps$",new N.BehaviorSubject(""));I(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,(p,g)=>{const h=p;if(h.ctrlKey){const S=Math.abs(h.deltaX);let _=S<40?.2:S<80?.4:.2;_*=h.deltaY>0?-1:1,c.scaleX<1&&(_/=2),c.scaleX+_>4?c.scale(4,4):c.scaleX+_<.1?c.scale(.1,.1):h.preventDefault()}else u.onMouseWheel(h,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,[],De),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=We,e.mainComponent=s,e.components.set(se.MAIN,s),n.addObjects([s],De)}},m.DocCanvasView=Fn([a.OnLifecycle(a.LifecycleStages.Ready,m.DocCanvasView),Re(0,M.IRenderManagerService),Re(1,a.IConfigService),Re(2,a.IUniverInstanceService),Re(3,E.Inject(m.DocViewModelManagerService))],m.DocCanvasView);var jn=Object.defineProperty,Vn=Object.getOwnPropertyDescriptor,kn=(r,t,e,n)=>{for(var i=n>1?void 0:n?Vn(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},ye=(r,t)=>(e,n)=>t(e,n,r);const zn={hasScroll:!0},Wn="docs";m.UniverDocsPlugin=(ke=class extends a.Plugin{constructor(e={},n,i,s,o){super(Wn);I(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,j,Ee,Pe,W,q,Z,J,$,V,G,X,Q,Ae,Ue,ce,le,xe,Le,Ne,v,Qe,et,nt,k,be,it,Je,Ze,Be].forEach(e=>{this._injector.get(a.ICommandService).registerCommand(e)}),[bn,xn,En,Un,Pn,Nn,wn,Ln,An,Tn,Dn,yn].forEach(e=>{this._injector.get(D.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],[Ce],[Me],[Ie],[Se],[_e],[he],[ve],[Oe],[pe]].forEach(n=>e.add(n))}},I(ke,"type",a.PluginType.Doc),ke),m.UniverDocsPlugin=kn([ye(1,E.Inject(E.Injector)),ye(2,E.Inject(a.LocaleService)),ye(3,a.IConfigService),ye(4,a.IUniverInstanceService)],m.UniverDocsPlugin),m.BreakLineCommand=Ue,m.BulletListCommand=Ze,m.CoverContentCommand=et,m.DOCS_COMPONENT_DEFAULT_Z_INDEX=We,m.DOCS_COMPONENT_HEADER_LAYER_INDEX=ze,m.DOCS_COMPONENT_MAIN_LAYER_INDEX=De,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=F,m.MoveSelectionOperation=j,m.NORMAL_TEXT_SELECTION_PLUGIN_NAME=gt,m.OrderListCommand=Je,m.ReplaceContentCommand=Qe,m.RichTextEditingMutation=v,m.SetInlineFormatBoldCommand=W,m.SetInlineFormatCommand=Ae,m.SetInlineFormatFontFamilyCommand=X,m.SetInlineFormatFontSizeCommand=G,m.SetInlineFormatItalicCommand=q,m.SetInlineFormatStrikethroughCommand=J,m.SetInlineFormatSubscriptCommand=$,m.SetInlineFormatSuperscriptCommand=V,m.SetInlineFormatTextColorCommand=Q,m.SetInlineFormatUnderlineCommand=Z,m.SetTextSelectionsOperation=be,m.UpdateCommand=xe,m.VIEWPORT_KEY=ae,m.getDocObject=Y,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(m,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("rxjs"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","rxjs","@wendellhu/redi"],s):(m=typeof globalThis<"u"?globalThis:m||self,s(m.UniverDocs={},m.UniverCore,m.UniverEngineRender,m.rxjs,m["@wendellhu/redi"]))})(this,function(m,s,C,A,E){"use strict";var sn=Object.defineProperty;var an=(m,s,C)=>s in m?sn(m,s,{enumerable:!0,configurable:!0,writable:!0,value:C}):m[s]=C;var M=(m,s,C)=>(an(m,typeof s!="symbol"?s+"":s,C),C);var Ee;function ie(a,i){const t=a.getCurrentUniverDocInstance().getUnitId(),n=i.getRenderById(t);if(n==null)return;const{mainComponent:r,scene:o,engine:c}=n;return{document:r,scene:o,engine:c}}function Ze(a,i){const e=i.getRenderById(a);if(e==null)return;const{mainComponent:t,scene:n,engine:r}=e;return{document:t,scene:n,engine:r}}var re=(a=>(a.MAIN="__Document_Render_Main__",a))(re||{}),se=(a=>(a.VIEW_MAIN="viewMain",a.VIEW_TOP="viewTop",a.VIEW_LEFT="viewLeft",a.VIEW_LEFT_TOP="viewLeftTop",a))(se||{});const pe=0,Ue=2,Pe=10,Je="normalTextSelectionPluginName",Ie={id:"doc.operation.set-selections",type:s.CommandType.OPERATION,handler:(a,i)=>!0};var Qe=Object.defineProperty,et=Object.getOwnPropertyDescriptor,tt=(a,i,e,t)=>{for(var n=t>1?void 0:t?et(i,e):i,r=a.length-1,o;r>=0;r--)(o=a[r])&&(n=(t?o(i,e,n):o(n))||n);return t&&n&&Qe(i,e,n),n},Ne=(a,i)=>(e,t)=>i(e,t,a);function j(a){const{startOffset:i,endOffset:e,collapsed:t}=a;return{startOffset:i,endOffset:e,collapsed:t}}m.TextSelectionManagerService=class extends s.RxDisposable{constructor(e,t){super();M(this,"_currentSelection",null);M(this,"_textSelectionInfo",new Map);M(this,"_textSelection$",new A.BehaviorSubject(null));M(this,"textSelection$",this._textSelection$.asObservable());this._textSelectionRenderManager=e,this._commandService=t,this._syncSelectionFromRenderService()}getCurrentSelection(){return this._currentSelection}getCurrentSelectionInfo(){return this._getTextRanges(this._currentSelection)}dispose(){this._textSelection$.complete()}refreshSelection(){this._currentSelection!=null&&this._refresh(this._currentSelection)}setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}setCurrentSelectionNotRefresh(e){this._currentSelection=e}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:t,segmentId:n,style:r}=e,o=t.find(S=>S.isActive());if(o==null)return null;const{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:h,direction:g}=o;return c==null||l==null?null:{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:h,direction:g,segmentId:n,style:r}}add(e){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,segmentId:"",style:C.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e){this._currentSelection!=null&&(this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges(e))}_syncSelectionFromRenderService(){this._textSelectionRenderManager.textSelectionInner$.pipe(A.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._replaceTextRangesWithNoRefresh(e)})}_replaceTextRangesWithNoRefresh(e){if(this._currentSelection==null)return;const t={...this._currentSelection,...e};this._replaceByParam(t),this._textSelection$.next(t);const{unitId:n,subUnitId:r,segmentId:o,style:c,textRanges:l}=t;this._commandService.executeCommand(Ie.id,{unitId:n,subUnitId:r,segmentId:o,style:c,ranges:l.map(j)})}_getTextRanges(e){var r;if(e==null)return;const{unitId:t,subUnitId:n=""}=e;return(r=this._textSelectionInfo.get(t))==null?void 0:r.get(n)}_refresh(e){const t=this._getTextRanges(e);this._textSelectionRenderManager.removeAllTextRanges(),t&&Array.isArray(t.textRanges)&&t.textRanges.length&&this._textSelectionRenderManager.addTextRanges(t.textRanges.map(j))}_replaceByParam(e){const{unitId:t,subUnitId:n,style:r,segmentId:o,textRanges:c}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(n,{textRanges:c,style:r,segmentId:o})}_addByParam(e){const{unitId:t,subUnitId:n,textRanges:r,style:o,segmentId:c}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);const l=this._textSelectionInfo.get(t);l.has(n)?l.get(n).textRanges.push(...r):l.set(n,{textRanges:r,style:o,segmentId:c})}},m.TextSelectionManagerService=tt([Ne(0,C.ITextSelectionRenderManager),Ne(1,s.ICommandService)],m.TextSelectionManagerService);function Me(a,i="",e=0){const{startOffset:t,endOffset:n}=a,r=[],o=t-e,c=n-e;return o>0&&r.push({t:s.TextXActionType.RETAIN,len:o,segmentId:i}),r.push({t:s.TextXActionType.DELETE,len:c-o,line:0,segmentId:i}),r}var nt=Object.defineProperty,it=Object.getOwnPropertyDescriptor,rt=(a,i,e,t)=>{for(var n=t>1?void 0:t?it(i,e):i,r=a.length-1,o;r>=0;r--)(o=a[r])&&(n=(t?o(i,e,n):o(n))||n);return t&&n&&nt(i,e,n),n},st=(a,i)=>(e,t)=>i(e,t,a);m.DocViewModelManagerService=class extends s.RxDisposable{constructor(e){super();M(this,"_currentViewModelUnitId","");M(this,"_docViewModelMap",new Map);M(this,"_currentDocViewModel$",new A.BehaviorSubject(null));M(this,"currentDocViewModel$",this._currentDocViewModel$.asObservable());this._currentUniverService=e,this._initialize()}_initialize(){this._currentUniverService.currentDoc$.pipe(A.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const t=e.getUnitId();this._setCurrent(t)})}dispose(){this._currentDocViewModel$.complete(),this._docViewModelMap.clear()}getCurrent(){return this._docViewModelMap.get(this._currentViewModelUnitId)}getViewModel(e){var t;return(t=this._docViewModelMap.get(e))==null?void 0:t.docViewModel}_setCurrent(e){var n;const t=this._currentUniverService.getUniverDocInstance(e);if(t==null)throw new Error(`Document data model with id ${e} not found when build view model.`);if(t.getBody()!=null){if(!this._docViewModelMap.has(e)){const r=this._buildDocViewModel(t);this._docViewModelMap.set(e,{unitId:e,docViewModel:r})}if(e===s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY){const r=(n=this._docViewModelMap.get(e))==null?void 0:n.docViewModel;if(r==null)return;r.reset(t)}this._currentViewModelUnitId=e,this._currentDocViewModel$.next(this.getCurrent())}}_buildDocViewModel(e){return new C.DocumentViewModel(e)}},m.DocViewModelManagerService=rt([st(0,s.IUniverInstanceService)],m.DocViewModelManagerService);var at=Object.defineProperty,ot=Object.getOwnPropertyDescriptor,ct=(a,i,e,t)=>{for(var n=t>1?void 0:t?ot(i,e):i,r=a.length-1,o;r>=0;r--)(o=a[r])&&(n=(t?o(i,e,n):o(n))||n);return t&&n&&at(i,e,n),n},Ce=(a,i)=>(e,t)=>i(e,t,a);const lt=300;m.DocStateChangeManagerService=class extends s.RxDisposable{constructor(e,t,n){super();M(this,"_docStateChange$",new A.BehaviorSubject(null));M(this,"docStateChange$",this._docStateChange$.asObservable());M(this,"_stateCache",new Map);M(this,"_timer",null);this._undoRedoService=e,this._commandService=t,this._univerInstanceService=n,this._initialize()}setChangeState(e){const{trigger:t,noHistory:n}=e;t!=null&&(this._cacheChangeState(e),n||this._docStateChange$.next(e))}_initialize(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===s.UndoCommandId||e.id===s.RedoCommandId){const t=this._univerInstanceService.getCurrentUniverDocInstance();if(t==null)return;const n=t.getUnitId();this._pushHistory(n)}}))}_cacheChangeState(e){const{trigger:t,unitId:n,noHistory:r}=e;if(!(t===s.RedoCommandId||t===s.UndoCommandId||r)){if(this._stateCache.has(n)){const o=this._stateCache.get(n);o==null||o.push(e)}else this._stateCache.set(n,[e]);t===k.id||t===X.id?(this._timer&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._pushHistory(n)},lt)):this._pushHistory(n)}}_pushHistory(e){const t=this._undoRedoService,n=this._stateCache.get(e);if(!Array.isArray(n)||n.length===0)return;const r=n.length,o=n[0].commandId,c=n[0],l=n[r-1],u={unitId:e,actions:n.reduce((h,g)=>s.TextX.compose(h,g.redoState.actions),[]),textRanges:l.redoState.textRanges},d={unitId:e,actions:n.reverse().reduce((h,g)=>s.TextX.compose(h,g.undoState.actions),[]),textRanges:c.undoState.textRanges};t.pushUndoRedo({unitID:e,undoMutations:[{id:o,params:d}],redoMutations:[{id:o,params:u}]}),n.length=0}},m.DocStateChangeManagerService=ct([Ce(0,E.Inject(s.IUndoRedoService)),Ce(1,s.ICommandService),Ce(2,s.IUniverInstanceService)],m.DocStateChangeManagerService);class V{constructor(){M(this,"_previousActiveRange",null);M(this,"_undoMutationParamsCache",[]);M(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache:i=[],redoCache:e=[]}){this._undoMutationParamsCache=i,this._redoMutationParamsCache=e}getActiveRange(){return this._previousActiveRange}setActiveRange(i){this._previousActiveRange=i}pushUndoRedoMutationParams(i,e){this._undoMutationParamsCache.push(i),this._redoMutationParamsCache.push(e)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:i}=this._undoMutationParamsCache[0],e={unitId:i,actions:this._undoMutationParamsCache.reverse().reduce((n,r)=>s.TextX.compose(n,r.actions),[]),textRanges:[]};return{redoMutationParams:{unitId:i,actions:this._redoMutationParamsCache.reduce((n,r)=>s.TextX.compose(n,r.actions),[]),textRanges:[]},undoMutationParams:e,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Ae="doc.mutation.rich-text-editing",P={id:Ae,type:s.CommandType.MUTATION,handler:(a,i)=>{var D;const{unitId:e,actions:t,textRanges:n,prevTextRanges:r,trigger:o,noHistory:c,isCompositionEnd:l,noNeedSetTextRange:u}=i,h=a.get(s.IUniverInstanceService).getUniverDocInstance(e),S=a.get(m.DocViewModelManagerService).getViewModel(e),f=a.get(m.TextSelectionManagerService),_=((D=f.getSelections())!=null?D:[]).map(j),p=a.get(m.DocStateChangeManagerService),I=a.get(V);if(h==null||S==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);if(t.length===0)throw new Error("Mutation's length should great than 0 when call RichTextEditingMutation");const O=h.apply(t),{segmentId:R}=t[0],y=h.getSelfOrHeaderFooterModel(R);S.getSelfOrHeaderFooterViewModel(R).reset(y),!u&&n&&queueMicrotask(()=>{f.replaceTextRanges(n)});const b={commandId:Ae,unitId:e,trigger:o,noHistory:c,redoState:{actions:t,textRanges:n},undoState:{actions:O,textRanges:r!=null?r:_}};if(l){const x=I.fetchComposedUndoRedoMutationParams();if(x==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:T,redoMutationParams:w,previousActiveRange:N}=x;b.redoState.actions=w.actions,b.undoState.actions=T.actions,b.undoState.textRanges=[N]}return p.setChangeState(b),{unitId:e,actions:O,textRanges:_}}},k={id:"doc.command.insert-text",type:s.CommandType.COMMAND,handler:async(a,i)=>{const e=a.get(s.ICommandService),{range:t,segmentId:n,body:r,unitId:o,textRanges:c}=i,{startOffset:l,collapsed:u}=t,d={id:P.id,params:{unitId:o,actions:[],textRanges:c}},h=new s.TextX;return u?l>0&&h.push({t:s.TextXActionType.RETAIN,len:l,segmentId:n}):h.push(...Me(t,n)),h.push({t:s.TextXActionType.INSERT,body:r,len:r.dataStream.length,line:0,segmentId:n}),d.params.actions=h.serialize(),!!e.syncExecuteCommand(d.id,d.params)}};var L=(a=>(a[a.LEFT=0]="LEFT",a[a.RIGHT=1]="RIGHT",a))(L||{});const X={id:"doc.command.delete-text",type:s.CommandType.COMMAND,handler:async(a,i)=>{const e=a.get(s.ICommandService),{range:t,segmentId:n,unitId:r,direction:o,textRanges:c,len:l=1}=i,{startOffset:u}=t,d={id:P.id,params:{unitId:r,actions:[],textRanges:c}},h=new s.TextX;return u>0&&h.push({t:s.TextXActionType.RETAIN,len:o===0?u-l:u,segmentId:n}),h.push({t:s.TextXActionType.DELETE,len:l,line:0,segmentId:n}),d.params.actions=h.serialize(),!!e.syncExecuteCommand(d.id,d.params)}},Te={id:"doc.command.update-text",type:s.CommandType.COMMAND,handler:async(a,i)=>{const{range:e,segmentId:t,updateBody:n,coverType:r,unitId:o,textRanges:c}=i,l=a.get(s.ICommandService),u={id:P.id,params:{unitId:o,actions:[],textRanges:c}},d=new s.TextX,{startOffset:h,endOffset:g}=e;return d.push({t:s.TextXActionType.RETAIN,len:h,segmentId:t}),d.push({t:s.TextXActionType.RETAIN,body:n,len:g-h,segmentId:t,coverType:r}),u.params.actions=d.serialize(),!!l.syncExecuteCommand(u.id,u.params)}};function dt(a,i){const e=[];for(let t=0,n=a.length;t<n;t++)a[t]===s.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});if(i)for(const t of e)i.bullet&&(t.bullet=s.Tools.deepClone(i.bullet)),i.paragraphStyle&&(t.paragraphStyle=s.Tools.deepClone(i.paragraphStyle));return e}const we={id:"doc.command.break-line",type:s.CommandType.COMMAND,handler:async a=>{var f,v;const i=a.get(m.TextSelectionManagerService),e=a.get(s.IUniverInstanceService),t=a.get(s.ICommandService),n=i.getActiveRange();if(n==null)return!1;const r=e.getCurrentUniverDocInstance(),o=r.getUnitId(),{startOffset:c,segmentId:l,style:u}=n,d=[{startOffset:c+1,endOffset:c+1,style:u}],g=((v=(f=r.getBody())==null?void 0:f.paragraphs)!=null?v:[]).find(_=>_.startIndex>=c);return await t.executeCommand(k.id,{unitId:o,body:{dataStream:s.DataStreamTreeTokenType.PARAGRAPH,paragraphs:dt(s.DataStreamTreeTokenType.PARAGRAPH,g)},range:n,textRanges:d,segmentId:l})}};var ut=Object.defineProperty,mt=Object.getOwnPropertyDescriptor,ht=(a,i,e,t)=>{for(var n=t>1?void 0:t?mt(i,e):i,r=a.length-1,o;r>=0;r--)(o=a[r])&&(n=(t?o(i,e,n):o(n))||n);return t&&n&&ut(i,e,n),n},Le=(a,i)=>(e,t)=>i(e,t,a);m.DocSkeletonManagerService=class extends s.RxDisposable{constructor(e,t){super();M(this,"_currentSkeletonUnitId","");M(this,"_docSkeletonMap",new Map);M(this,"_currentSkeleton$",new A.BehaviorSubject(null));M(this,"currentSkeleton$",this._currentSkeleton$.asObservable());M(this,"_currentSkeletonBefore$",new A.BehaviorSubject(null));M(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._localeService=e,this._docViewModelManagerService=t,this._initialize()}_initialize(){this._docViewModelManagerService.currentDocViewModel$.pipe(A.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,t=!0){const n=this.getSkeletonByUnitId(e);n!=null&&(n.dirty=t)}getSkeletonByUnitId(e){return this._docSkeletonMap.get(e)}_setCurrent(e){const{unitId:t}=e;if(this._docSkeletonMap.has(t)){const n=this.getSkeletonByUnitId(t);n.skeleton.calculate(),n.dirty=!0}else{const n=this._buildSkeleton(e.docViewModel);n.calculate(),this._docSkeletonMap.set(t,{unitId:t,skeleton:n,dirty:!1})}return this._currentSkeletonUnitId=t,this._currentSkeletonBefore$.next(this.getCurrent()),this._currentSkeleton$.next(this.getCurrent()),this.getCurrent()}_buildSkeleton(e){return C.DocumentSkeleton.create(e,this._localeService)}},m.DocSkeletonManagerService=ht([Le(0,E.Inject(s.LocaleService)),Le(1,E.Inject(m.DocViewModelManagerService))],m.DocSkeletonManagerService);const gt={id:"doc.command.inner-paste",type:s.CommandType.COMMAND,handler:async(a,i)=>{const{segmentId:e,body:t,textRanges:n}=i,r=a.get(s.ICommandService),o=a.get(m.TextSelectionManagerService),c=a.get(s.IUniverInstanceService),l=o.getSelections();if(!Array.isArray(l)||l.length===0)return!1;const d=c.getCurrentUniverDocInstance().getUnitId(),h={id:P.id,params:{unitId:d,actions:[],textRanges:n}},g=new s.MemoryCursor;g.reset();const S=new s.TextX;for(const v of l){const{startOffset:_,endOffset:p,collapsed:I}=v,O=_-g.cursor;I?S.push({t:s.TextXActionType.RETAIN,len:O,segmentId:e}):S.push(...Me(v,e,g.cursor)),S.push({t:s.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:e}),g.reset(),g.moveCursor(p)}return h.params.actions=S.serialize(),!!r.syncExecuteCommand(h.id,h.params)}},Oe={id:"doc.command.inner-cut",type:s.CommandType.COMMAND,handler:async(a,i)=>{const{segmentId:e,textRanges:t}=i,n=a.get(s.ICommandService),r=a.get(m.TextSelectionManagerService),o=a.get(s.IUniverInstanceService),c=r.getSelections();if(!Array.isArray(c)||c.length===0)return!1;const l=o.getCurrentUniverDocInstance().getUnitId(),u=o.getUniverDocInstance(l),d=s.getDocsUpdateBody(u.snapshot,e);if(d==null)return!1;const h={id:P.id,params:{unitId:l,actions:[],textRanges:t}},g=new s.MemoryCursor;g.reset();const S=new s.TextX;for(const v of c){const{startOffset:_,endOffset:p,collapsed:I}=v,O=_-g.cursor;I?S.push({t:s.TextXActionType.RETAIN,len:O,segmentId:e}):S.push(...St(v,d,e,g.cursor)),g.reset(),g.moveCursor(p)}return h.params.actions=S.serialize(),!!n.syncExecuteCommand(h.id,h.params)}};function St(a,i,e="",t=0){const{startOffset:n,endOffset:r}=a,o=[],{paragraphs:c=[]}=i,l=n-t,u=r-t,d=c==null?void 0:c.find(h=>h.startIndex-t>=l&&h.startIndex-t<=u);if(l>0&&o.push({t:s.TextXActionType.RETAIN,len:l,segmentId:e}),d&&d.startIndex-t>l){const h=d.startIndex-t;o.push({t:s.TextXActionType.DELETE,len:h-l,line:0,segmentId:e}),o.push({t:s.TextXActionType.RETAIN,len:1,segmentId:e}),u>h+1&&o.push({t:s.TextXActionType.DELETE,len:u-h-1,line:0,segmentId:e})}else o.push({t:s.TextXActionType.DELETE,len:u-l,line:0,segmentId:e});return o}const Be={id:"doc.command.delete-left",type:s.CommandType.COMMAND,handler:async a=>{var R;const i=a.get(m.TextSelectionManagerService),e=a.get(m.DocSkeletonManagerService),t=a.get(s.IUniverInstanceService),n=a.get(s.ICommandService),r=i.getActiveRange(),o=i.getSelections(),c=(R=e.getCurrent())==null?void 0:R.skeleton;let l=!0;if(r==null||c==null||o==null)return!1;const u=t.getCurrentUniverDocInstance(),{startOffset:d,collapsed:h,segmentId:g,style:S}=r,f=c.findNodeByCharIndex(d),v=C.hasListSpan(f),_=C.isIndentBySpan(f,u.getBody());let p=d;const I=c.findNodeByCharIndex(d-1);if(C.isFirstSpan(f)&&I!==f&&(v===!0||_===!0)){const y=C.getParagraphBySpan(f,u.getBody());if(y==null)return!1;const U=y==null?void 0:y.startIndex,b={startIndex:0},D=y.paragraphStyle;if(v===!0){const T=y.paragraphStyle;T&&(b.paragraphStyle=T)}else if(_===!0){const T=y.bullet;T&&(b.bullet=T),D!=null&&(b.paragraphStyle={...D},delete b.paragraphStyle.hanging,delete b.paragraphStyle.indentStart)}const x=[{startOffset:p,endOffset:p,style:S}];l=await n.executeCommand(Te.id,{unitId:u.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...b}]},range:{startOffset:U,endOffset:U+1},textRanges:x,coverType:s.UpdateDocsAttributeType.REPLACE,segmentId:g})}else if(h===!0){if(I==null)return!0;if(I.content==="\r")l=await n.executeCommand(Re.id,{direction:L.LEFT,range:r});else{p-=I.count;const y=[{startOffset:p,endOffset:p,style:S}];l=await n.executeCommand(X.id,{unitId:u.getUnitId(),range:r,segmentId:g,direction:L.LEFT,len:I.count,textRanges:y})}}else{const y=Fe(r,o);l=await n.executeCommand(Oe.id,{segmentId:g,textRanges:y})}return l}},$e={id:"doc.command.delete-right",type:s.CommandType.COMMAND,handler:async a=>{var f;const i=a.get(m.TextSelectionManagerService),e=a.get(m.DocSkeletonManagerService),t=a.get(s.IUniverInstanceService),n=a.get(s.ICommandService),r=i.getActiveRange(),o=i.getSelections(),c=(f=e.getCurrent())==null?void 0:f.skeleton;let l;if(r==null||c==null||o==null)return!1;const u=t.getCurrentUniverDocInstance(),{startOffset:d,collapsed:h,segmentId:g,style:S}=r;if(d===u.getBody().dataStream.length-2&&h)return!0;if(h===!0){const v=c.findNodeByCharIndex(d);if(v.content==="\r")l=await n.executeCommand(Re.id,{direction:L.RIGHT,range:r});else{const _=[{startOffset:d,endOffset:d,style:S}];l=await n.executeCommand(X.id,{unitId:u.getUnitId(),range:r,segmentId:g,direction:L.RIGHT,textRanges:_,len:v.count})}}else{const v=Fe(r,o);l=await n.executeCommand(Oe.id,{segmentId:g,textRanges:v})}return l}},Re={id:"doc.command.merge-two-paragraph",type:s.CommandType.COMMAND,handler:async(a,i)=>{var b,D,x;const e=a.get(m.TextSelectionManagerService),t=a.get(s.IUniverInstanceService),n=a.get(s.ICommandService);a.get(s.IUndoRedoService);const{direction:r,range:o}=i,c=e.getActiveRange(),l=e.getSelections();if(c==null||l==null)return!1;const u=t.getCurrentUniverDocInstance(),{startOffset:d,collapsed:h,segmentId:g,style:S}=c;if(!h)return!1;const f=r===L.LEFT?d:d+1,v=(x=(D=(b=u.getBody())==null?void 0:b.paragraphs)==null?void 0:D.find(T=>T.startIndex>=f))==null?void 0:x.startIndex,_=_t(u.getBody(),f,v),p=r===L.LEFT?d-1:d,I=u.getUnitId(),O=[{startOffset:p,endOffset:p,style:S}],R={id:P.id,params:{unitId:I,actions:[],textRanges:O,prevTextRanges:[o]}},y=new s.TextX;return y.push({t:s.TextXActionType.RETAIN,len:r===L.LEFT?d-1:d,segmentId:g}),_.dataStream.length&&y.push({t:s.TextXActionType.INSERT,body:_,len:_.dataStream.length,line:0,segmentId:g}),y.push({t:s.TextXActionType.RETAIN,len:1,segmentId:g}),y.push({t:s.TextXActionType.DELETE,len:v+1-f,line:0,segmentId:g}),R.params.actions=y.serialize(),!!n.syncExecuteCommand(R.id,R.params)}};function _t(a,i,e){const{textRuns:t}=a,n=a.dataStream.substring(i,e);if(t==null)return{dataStream:n};const r=[];for(const o of t){const{st:c,ed:l}=o;l<=i||c>=e||(c<i?r.push({...o,st:0,ed:l-i}):l>e?r.push({...o,st:c-i,ed:e-i}):r.push({...o,st:c-i,ed:l-i}))}return{dataStream:n,textRuns:r}}function Fe(a,i){let e=a.endOffset;for(const n of i){const{startOffset:r,endOffset:o}=n;r==null||o==null||o<=a.endOffset&&(e-=o-r)}return[{startOffset:e,endOffset:e,style:a.style}]}const ye={id:"doc.command.ime-input",type:s.CommandType.COMMAND,handler:async(a,i)=>{const{unitId:e,newText:t,oldTextLen:n,isCompositionEnd:r,isCompositionStart:o}=i,c=a.get(s.ICommandService),l=a.get(V),u=l.getActiveRange();if(u==null)return!1;const{startOffset:d,style:h,segmentId:g}=u,S=t.length,f=[{startOffset:d+S,endOffset:d+S,collapsed:!0,style:h}],v={id:P.id,params:{unitId:e,actions:[],textRanges:f}},_=new s.TextX;!u.collapsed&&o?_.push(...Me(u,g)):_.push({t:s.TextXActionType.RETAIN,len:d,segmentId:g}),n>0&&_.push({t:s.TextXActionType.DELETE,len:n,line:0,segmentId:g}),_.push({t:s.TextXActionType.INSERT,body:{dataStream:t},len:t.length,line:0,segmentId:g}),v.params.actions=_.serialize(),v.params.noHistory=!r,v.params.isCompositionEnd=r;const p=c.syncExecuteCommand(v.id,v.params);return l.pushUndoRedoMutationParams(p,v.params),!!p}},z={id:"doc.command.set-inline-format-bold",type:s.CommandType.COMMAND,handler:async()=>!0},Y={id:"doc.command.set-inline-format-italic",type:s.CommandType.COMMAND,handler:async()=>!0},H={id:"doc.command.set-inline-format-underline",type:s.CommandType.COMMAND,handler:async()=>!0},W={id:"doc.command.set-inline-format-strikethrough",type:s.CommandType.COMMAND,handler:async()=>!0},B={id:"doc.command.set-inline-format-subscript",type:s.CommandType.COMMAND,handler:async()=>!0},G={id:"doc.command.set-inline-format-superscript",type:s.CommandType.COMMAND,handler:async()=>!0},K={id:"doc.command.set-inline-format-fontsize",type:s.CommandType.COMMAND,handler:async()=>!0},q={id:"doc.command.set-inline-format-font-family",type:s.CommandType.COMMAND,handler:async()=>!0},Z={id:"doc.command.set-inline-format-text-color",type:s.CommandType.COMMAND,handler:async()=>!0},je={[z.id]:"bl",[Y.id]:"it",[H.id]:"ul",[W.id]:"st",[K.id]:"fs",[q.id]:"ff",[Z.id]:"cl",[B.id]:"va",[G.id]:"va"},De={id:"doc.command.set-inline-format",type:s.CommandType.COMMAND,handler:async(a,i)=>{const{segmentId:e,value:t,preCommandId:n}=i,r=a.get(s.ICommandService),o=a.get(m.TextSelectionManagerService),c=a.get(s.IUniverInstanceService),l=o.getSelections();if(!Array.isArray(l)||l.length===0)return!1;let u=c.getCurrentUniverDocInstance(),d=u.getUnitId();d===s.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(u=c.getUniverDocInstance(s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),d=u.getUnitId());let h;switch(n){case z.id:case Y.id:case H.id:case W.id:case B.id:case G.id:{h=vt(u.getBody().textRuns,n,l);break}case K.id:case q.id:{h=t;break}case Z.id:{h={rgb:t};break}default:throw new Error(`Unknown command: ${n} in handleInlineFormat`)}const g={id:P.id,params:{unitId:d,actions:[],textRanges:l}},S=new s.TextX,f=new s.MemoryCursor;f.reset();for(const _ of l){const{startOffset:p,endOffset:I}=_,O={dataStream:"",textRuns:[{st:0,ed:I-p,ts:{[je[n]]:h}}]},R=p-f.cursor;R!==0&&S.push({t:s.TextXActionType.RETAIN,len:R,segmentId:e}),S.push({t:s.TextXActionType.RETAIN,body:O,len:I-p,segmentId:e}),f.reset(),f.moveCursor(I)}return g.params.actions=S.serialize(),!!r.syncExecuteCommand(g.id,g.params)}};function ft(a){return a!==null&&typeof a=="object"}function vt(a,i,e){let t=0,n=0;const r=je[i];for(;t!==a.length&&n!==e.length;){const{startOffset:o,endOffset:c}=e[n],{st:l,ed:u,ts:d}=a[t];if(c<=l)n++;else if(u<=o)t++;else{if(/bl|it/.test(r))return(d==null?void 0:d[r])===s.BooleanNumber.TRUE?s.BooleanNumber.FALSE:s.BooleanNumber.TRUE;if(/ul|st/.test(r))return ft(d==null?void 0:d[r])&&(d==null?void 0:d[r]).s===s.BooleanNumber.TRUE?{s:s.BooleanNumber.FALSE}:{s:s.BooleanNumber.TRUE};if(/va/.test(r))return i===B.id?(d==null?void 0:d[r])===s.BaselineOffset.SUBSCRIPT?s.BaselineOffset.NORMAL:s.BaselineOffset.SUBSCRIPT:(d==null?void 0:d[r])===s.BaselineOffset.SUPERSCRIPT?s.BaselineOffset.NORMAL:s.BaselineOffset.SUPERSCRIPT;t++}}return/bl|it/.test(r)?s.BooleanNumber.TRUE:/ul|st/.test(r)?{s:s.BooleanNumber.TRUE}:i===B.id?s.BaselineOffset.SUBSCRIPT:s.BaselineOffset.SUPERSCRIPT}const xe={id:"doc.command.list-operation",type:s.CommandType.COMMAND,handler:(a,i)=>{var y,U,b;const e=a.get(m.TextSelectionManagerService),t=a.get(s.IUniverInstanceService),n=a.get(s.ICommandService),{listType:r}=i,o=t.getCurrentUniverDocInstance(),c=e.getActiveRange(),l=(y=e.getSelections())!=null?y:[],u=(U=o.getBody())==null?void 0:U.paragraphs,d=l.map(j);if(c==null||u==null)return!1;const h=pt(c,u),{segmentId:g}=c,S=o.getUnitId(),f=h.every(D=>{var x;return((x=D.bullet)==null?void 0:x.listType)===r});let _=s.Tools.generateRandomId(6);if(h.length===1){const D=u.indexOf(h[0]),x=u[D-1],T=u[D+1];x&&x.bullet&&x.bullet.listType===r?_=x.bullet.listId:T&&T.bullet&&T.bullet.listType===r&&(_=T.bullet.listId)}const p={id:P.id,params:{unitId:S,actions:[],textRanges:d}},I=new s.MemoryCursor;I.reset();const O=new s.TextX;for(const D of h){const{startIndex:x}=D;O.push({t:s.TextXActionType.RETAIN,len:x-I.cursor,segmentId:g});const T={...D.paragraphStyle,hanging:void 0,indentStart:void 0};O.push({t:s.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[f?{paragraphStyle:T,startIndex:0}:{...D,startIndex:0,bullet:{...(b=D.bullet)!=null?b:{nestingLevel:0,textStyle:{fs:20}},listType:r,listId:_}}]},segmentId:g,coverType:s.UpdateDocsAttributeType.REPLACE}),I.moveCursorTo(x+1)}return p.params.actions=O.serialize(),!!n.syncExecuteCommand(p.id,p.params)}},Ve={id:"doc.command.bullet-list",type:s.CommandType.COMMAND,handler:a=>a.get(s.ICommandService).syncExecuteCommand(xe.id,{listType:s.PresetListType.BULLET_LIST})},ke={id:"doc.command.order-list",type:s.CommandType.COMMAND,handler:a=>a.get(s.ICommandService).syncExecuteCommand(xe.id,{listType:s.PresetListType.ORDER_LIST})};function pt(a,i){const{startOffset:e,endOffset:t}=a,n=[];let r=-1;for(const o of i){const{startIndex:c}=o;(e>r&&e<=c||t>r&&t<=c||c>=e&&c<=t)&&n.push(o),r=c}return n}const Xe={id:"doc.command-replace-content",type:s.CommandType.COMMAND,handler:async(a,i)=>{var S;const{unitId:e,body:t,textRanges:n,segmentId:r=""}=i,o=a.get(s.IUniverInstanceService),c=a.get(s.ICommandService),l=a.get(m.TextSelectionManagerService),u=(S=o.getUniverDocInstance(e))==null?void 0:S.getSnapshot().body,d=l.getSelections();if(u==null||!Array.isArray(d)||d.length===0)return!1;const h=Ye(e,r,u,t);return h.params.textRanges=n,!!c.syncExecuteCommand(h.id,h.params)}},ze={id:"doc.command-cover-content",type:s.CommandType.COMMAND,handler:async(a,i)=>{var d;const{unitId:e,body:t,segmentId:n=""}=i,r=a.get(s.IUniverInstanceService),o=a.get(s.ICommandService),c=a.get(s.IUndoRedoService),l=(d=r.getUniverDocInstance(e))==null?void 0:d.getSnapshot().body;if(l==null)return!1;const u=Ye(e,n,l,t);return u.params.noNeedSetTextRange=!0,u.params.noHistory=!0,o.syncExecuteCommand(u.id,u.params),c.clearUndoRedo(e),!0}};function Ye(a,i,e,t){const n={id:P.id,params:{unitId:a,actions:[],textRanges:[]}},r=new s.TextX,o=(e==null?void 0:e.dataStream.length)-2;return o>0&&r.push({t:s.TextXActionType.DELETE,len:o,line:0,segmentId:i}),t.dataStream.length>0&&r.push({t:s.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:i}),n.params.actions=r.serialize(),n}const ae={id:"doc.operation.move-cursor",type:s.CommandType.OPERATION,handler:(a,i)=>!!i},oe={id:"doc.operation.move-selection",type:s.CommandType.OPERATION,handler:(a,i)=>!!i},It=(a,i)=>{const e=a.get(s.IUniverInstanceService).getUniverDocInstance(i.unitId),t=(e==null?void 0:e.zoomRatio)||1;return{...s.Tools.deepClone(i),zoomRatio:t}},$={id:"doc.operation.set-zoom-ratio",type:s.CommandType.OPERATION,handler:(a,i)=>{const e=a.get(s.IUniverInstanceService).getUniverDocInstance(i.unitId);if(!e)return!1;const t=e.getSnapshot();return t.settings==null?t.settings={zoomRatio:i.zoomRatio}:t.settings.zoomRatio=i.zoomRatio,!0}},He={type:s.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(a,i)=>{var h,g;const e=a.get(s.ICommandService),t=a.get(s.IUndoRedoService),n=a.get(s.IUniverInstanceService);let r=n.getCurrentUniverDocInstance().getUnitId(),o=1;if(i&&(r=(h=i.documentId)!=null?h:r,o=(g=i.zoomRatio)!=null?g:o),!n.getUniverDocInstance(r))return!1;const l={zoomRatio:o,unitId:r},u=It(a,l);return e.syncExecuteCommand($.id,l)?(t.pushUndoRedo({unitID:r,undoMutations:[{id:$.id,params:u}],redoMutations:[{id:$.id,params:l}]}),!0):!1}},We={id:"doc.operation.select-all",type:s.CommandType.COMMAND,handler:async a=>{const i=a.get(s.IUniverInstanceService),e=a.get(m.TextSelectionManagerService),t=i.getCurrentUniverDocInstance().getSnapshot().body;if(t==null)return!1;const n=[{startOffset:0,endOffset:t.dataStream.length-2}];return e.replaceTextRanges(n),!0}};var Mt=Object.defineProperty,Ct=Object.getOwnPropertyDescriptor,Tt=(a,i,e,t)=>{for(var n=t>1?void 0:t?Ct(i,e):i,r=a.length-1,o;r>=0;r--)(o=a[r])&&(n=(t?o(i,e,n):o(n))||n);return t&&n&&Mt(i,e,n),n},be=(a,i)=>(e,t)=>i(e,t,a);let ce=class extends s.RxDisposable{constructor(a,i,e){super(),this._docSkeletonManagerService=a,this._renderManagerService=i,this._commandService=e,this._initialRenderRefresh(),this._commandExecutedListener()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(A.takeUntil(this.dispose$)).subscribe(a=>{if(a==null)return;const{skeleton:i,unitId:e}=a,t=this._renderManagerService.getRenderById(e);if(t==null)return;const{mainComponent:n}=t;n.changeSkeleton(i),this._recalculateSizeBySkeleton(t,i)})}_recalculateSizeBySkeleton(a,i){var u;const{mainComponent:e,scene:t}=a,n=e,r=(u=i.getSkeletonData())==null?void 0:u.pages;if(r==null)return;let o=0,c=0;for(let d=0,h=r.length;d<h;d++){const g=r[d],{pageWidth:S,pageHeight:f}=g;n.pageLayoutType===C.PageLayoutType.VERTICAL?(c+=f,c+=n.pageMarginTop,d===h-1&&(c+=n.pageMarginTop),o=Math.max(o,S)):n.pageLayoutType===C.PageLayoutType.HORIZONTAL&&(o+=S,d!==h-1&&(o+=n.pageMarginLeft),c=Math.max(c,f))}n.resize(o,c),[s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,s.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(a.unitId)||t.resize(o,c)}_commandExecutedListener(){const a=[P.id],i=[s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,s.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t;if(a.includes(e.id)){const n=e.params,{unitId:r}=n,o=this._docSkeletonManagerService.getSkeletonByUnitId(r);if(o==null)return;const{skeleton:c}=o,l=this._renderManagerService.getRenderById(r);if(l==null)return;if(c.calculate(),i.includes(r)){(t=l.mainComponent)==null||t.makeDirty();return}this._recalculateSizeBySkeleton(l,c)}}))}};ce=Tt([s.OnLifecycle(s.LifecycleStages.Rendered,ce),be(0,E.Inject(m.DocSkeletonManagerService)),be(1,C.IRenderManagerService),be(2,s.ICommandService)],ce);var Ot=Object.defineProperty,Rt=Object.getOwnPropertyDescriptor,yt=(a,i,e,t)=>{for(var n=t>1?void 0:t?Rt(i,e):i,r=a.length-1,o;r>=0;r--)(o=a[r])&&(n=(t?o(i,e,n):o(n))||n);return t&&n&&Ot(i,e,n),n},J=(a,i)=>(e,t)=>i(e,t,a);let le=class extends s.Disposable{constructor(i,e,t,n,r){super();M(this,"_liquid",new C.Liquid);M(this,"_pageMarginCache",new Map);this._docSkeletonManagerService=i,this._currentUniverService=e,this._renderManagerService=t,this._commandService=n,this._floatingObjectManagerService=r,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh(),this._updateOnPluginChange()}_updateOnPluginChange(){this._floatingObjectManagerService.pluginUpdate$.subscribe(i=>{const e=this._docSkeletonManagerService.getCurrent();if(e==null)return;const{unitId:t,skeleton:n}=e,r=this._renderManagerService.getRenderById(t);if(r==null)return;const{mainComponent:o,components:c,scene:l}=r,u=o,{left:d,top:h}=u;i.forEach(g=>{const{unitId:S,subUnitId:f,floatingObjectId:v,floatingObject:_}=g,{left:p=0,top:I=0,width:O=0,height:R=0,angle:y,flipX:U,flipY:b,skewX:D,skewY:x}=_,T=this._pageMarginCache.get(v),w=(T==null?void 0:T.marginLeft)||0,N=(T==null?void 0:T.marginTop)||0;n==null||n.getViewModel().getDataModel().updateDrawing(v,{left:p-d-w,top:I-h-N,height:R,width:O})}),n==null||n.calculate(),o==null||o.makeDirty()})}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{skeleton:e,unitId:t}=i,n=this._renderManagerService.getRenderById(t);if(n==null)return;const{mainComponent:r}=n;r.changeSkeleton(e),this._refreshFloatingObject(t,e,n)})}_commandExecutedListener(){const i=[P.id,$.id],e=[s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,s.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(i.includes(t.id)){const r=t.params,{unitId:o}=r,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)){(n=d.mainComponent)==null||n.makeDirty();return}this._refreshFloatingObject(l,u,d)}}))}_refreshFloatingObject(i,e,t){const n=e==null?void 0:e.getSkeletonData(),{mainComponent:r,scene:o}=t,c=r;if(!n)return;const{left:l,top:u,pageLayoutType:d,pageMarginLeft:h,pageMarginTop:g}=c,{pages:S}=n,f=[];o.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let v=0,_=S.length;v<_;v++){const p=S[v],{skeDrawings:I,marginLeft:O,marginTop:R}=p;this._liquid.translatePagePadding(p),I.forEach(y=>{const{aLeft:U,aTop:b,height:D,width:x,objectId:T}=y;f.push({unitId:i,subUnitId:s.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:T,floatingObject:{left:U+l+this._liquid.x,top:b+u+this._liquid.y,width:x,height:D}}),this._pageMarginCache.set(T,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.translatePage(p,d,h,g)}this._floatingObjectManagerService.BatchAddOrUpdate(f)}};le=yt([s.OnLifecycle(s.LifecycleStages.Steady,le),J(0,E.Inject(m.DocSkeletonManagerService)),J(1,s.IUniverInstanceService),J(2,C.IRenderManagerService),J(3,s.ICommandService),J(4,s.IFloatingObjectManagerService)],le);var Dt=Object.defineProperty,xt=Object.getOwnPropertyDescriptor,bt=(a,i,e,t)=>{for(var n=t>1?void 0:t?xt(i,e):i,r=a.length-1,o;r>=0;r--)(o=a[r])&&(n=(t?o(i,e,n):o(n))||n);return t&&n&&Dt(i,e,n),n},Q=(a,i)=>(e,t)=>i(e,t,a);let de=class extends s.Disposable{constructor(i,e,t,n,r){super();M(this,"_previousIMEContent","");M(this,"_isCompositionStart",!0);M(this,"_onStartSubscription");M(this,"_onUpdateSubscription");M(this,"_onEndSubscription");this._docSkeletonManagerService=i,this._currentUniverService=e,this._textSelectionRenderManager=t,this._imeInputManagerService=n,this._commandService=r,this._initialize()}dispose(){var i,e,t;(i=this._onStartSubscription)==null||i.unsubscribe(),(e=this._onUpdateSubscription)==null||e.unsubscribe(),(t=this._onEndSubscription)==null||t.unsubscribe()}_initialize(){this._initialOnCompositionstart(),this._initialOnCompositionUpdate(),this._initialOnCompositionend()}_initialOnCompositionstart(){this._onStartSubscription=this._textSelectionRenderManager.onCompositionstart$.subscribe(i=>{if(i==null)return;const{activeRange:e}=i;e!=null&&(this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(s.Tools.deepClone(e)),this._isCompositionStart=!0)})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._textSelectionRenderManager.onCompositionupdate$.subscribe(async i=>{this._updateContent(i,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._textSelectionRenderManager.onCompositionend$.subscribe(i=>{this._updateContent(i,!1)})}async _updateContent(i,e){var u;const t=(u=this._docSkeletonManagerService.getCurrent())==null?void 0:u.skeleton;if(i==null||t==null)return;const n=this._currentUniverService.getCurrentUniverDocInstance(),{event:r,activeRange:o}=i;if(t==null||o==null)return;const l=r.data;l===this._previousIMEContent&&e||(await this._commandService.executeCommand(ye.id,{unitId:n.getUnitId(),newText:l,oldTextLen:this._previousIMEContent.length,isCompositionStart:this._isCompositionStart,isCompositionEnd:!e}),e?(this._isCompositionStart&&(this._isCompositionStart=!1),this._previousIMEContent=l):this._resetIME())}_resetIME(){this._previousIMEContent="",this._isCompositionStart=!0,this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(null)}};de=bt([s.OnLifecycle(s.LifecycleStages.Rendered,de),Q(0,E.Inject(m.DocSkeletonManagerService)),Q(1,s.IUniverInstanceService),Q(2,C.ITextSelectionRenderManager),Q(3,E.Inject(V)),Q(4,s.ICommandService)],de);var Et=Object.defineProperty,Ut=Object.getOwnPropertyDescriptor,Pt=(a,i,e,t)=>{for(var n=t>1?void 0:t?Ut(i,e):i,r=a.length-1,o;r>=0;r--)(o=a[r])&&(n=(t?o(i,e,n):o(n))||n);return t&&n&&Et(i,e,n),n},Ge=(a,i)=>(e,t)=>i(e,t,a);let ue=class extends s.Disposable{constructor(a,i){super(),this._textSelectionManagerService=a,this._commandService=i,this._commandExecutedListener()}_commandExecutedListener(){const a=[z.id,Y.id,H.id,W.id,B.id,G.id,K.id,q.id,Z.id];this.disposeWithMe(this._commandService.onCommandExecuted(i=>{a.includes(i.id)&&this._handleInlineFormat(i)}))}_handleInlineFormat(a){var e,t;const{segmentId:i}=(e=this._textSelectionManagerService.getActiveRange())!=null?e:{};i!=null&&this._commandService.executeCommand(De.id,{segmentId:i,preCommandId:a.id,...(t=a.params)!=null?t:{}})}};ue=Pt([s.OnLifecycle(s.LifecycleStages.Rendered,ue),Ge(0,E.Inject(m.TextSelectionManagerService)),Ge(1,s.ICommandService)],ue);var Nt=Object.defineProperty,At=Object.getOwnPropertyDescriptor,wt=(a,i,e,t)=>{for(var n=t>1?void 0:t?At(i,e):i,r=a.length-1,o;r>=0;r--)(o=a[r])&&(n=(t?o(i,e,n):o(n))||n);return t&&n&&Nt(i,e,n),n},ee=(a,i)=>(e,t)=>i(e,t,a);let me=class extends s.Disposable{constructor(i,e,t,n,r){super();M(this,"_onInputSubscription");this._docSkeletonManagerService=i,this._currentUniverService=e,this._renderManagerService=t,this._textSelectionManagerService=n,this._commandService=r,this._initialize(),this._commandExecutedListener()}dispose(){var i;(i=this._onInputSubscription)==null||i.unsubscribe()}_initialize(){}_commandExecutedListener(){const i=[ae.id,oe.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!i.includes(e.id))return;const t=e.params;switch(e.id){case ae.id:return this._handleMoveCursor(t.direction);case oe.id:return this._handleShiftMoveSelection(t.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(i){var v,_,p;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),n=this._currentUniverService.getCurrentUniverDocInstance(),r=(v=this._docSkeletonManagerService.getCurrent())==null?void 0:v.skeleton,o=this._getDocObject();if(e==null||r==null||o==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d,direction:h}=e;if(t.length>1){let I=Number.POSITIVE_INFINITY,O=Number.NEGATIVE_INFINITY;for(const R of t)I=Math.min(I,R.startOffset),O=Math.max(O,R.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:i===s.Direction.LEFT||i===s.Direction.UP?O:I,endOffset:i===s.Direction.LEFT||i===s.Direction.UP?I:O,style:u}]);return}const g=d||h===C.RANGE_DIRECTION.FORWARD?c:l;let S=d||h===C.RANGE_DIRECTION.FORWARD?l:c;const f=(_=n.getBody().dataStream.length)!=null?_:Number.POSITIVE_INFINITY;if(i===s.Direction.LEFT||i===s.Direction.RIGHT){const I=r.findNodeByCharIndex(S-1),O=r.findNodeByCharIndex(S);S=i===s.Direction.RIGHT?S+O.count:S-((p=I==null?void 0:I.count)!=null?p:0),S=Math.min(f-2,Math.max(0,S)),this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:S,style:u}])}else{const I=r.findNodeByCharIndex(S),O=o.document.getOffsetConfig(),R=this._getTopOrBottomPosition(r,I,i===s.Direction.DOWN);if(R==null){const U=i===s.Direction.UP?0:f-2;if(U===S)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:U,style:u}]);return}const y=new C.NodePositionConvertToCursor(O,r).getRangePointData(R,R).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:y.endOffset,style:u}])}}_handleMoveCursor(i){var g,S,f;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),n=this._currentUniverService.getCurrentUniverDocInstance(),r=(g=this._docSkeletonManagerService.getCurrent())==null?void 0:g.skeleton,o=this._getDocObject();if(e==null||r==null||o==null||t==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d}=e,h=(S=n.getBody().dataStream.length)!=null?S:Number.POSITIVE_INFINITY;if(i===s.Direction.LEFT||i===s.Direction.RIGHT){let v;if(!e.collapsed||t.length>1){let _=Number.POSITIVE_INFINITY,p=Number.NEGATIVE_INFINITY;for(const I of t)_=Math.min(_,I.startOffset),p=Math.max(p,I.endOffset);v=i===s.Direction.LEFT?_:p}else{const _=r.findNodeByCharIndex(c-1),p=r.findNodeByCharIndex(c);i===s.Direction.LEFT?v=Math.max(0,c-((f=_==null?void 0:_.count)!=null?f:0)):v=Math.min(h-2,l+p.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:v,endOffset:v,style:u}])}else{const v=r.findNodeByCharIndex(c),_=r.findNodeByCharIndex(l),p=o.document.getOffsetConfig(),I=this._getTopOrBottomPosition(r,i===s.Direction.UP?v:_,i===s.Direction.DOWN);if(I==null){let R;d?R=i===s.Direction.UP?0:h-2:R=i===s.Direction.UP?c:l,this._textSelectionManagerService.replaceTextRanges([{startOffset:R,endOffset:R,style:u}]);return}const O=new C.NodePositionConvertToCursor(p,r).getRangePointData(I,I).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...O,style:u}])}}_getTopOrBottomPosition(i,e,t){if(e==null)return;const n=this._getSpanLeftOffsetInLine(e),r=this._getNextOrPrevLine(e,t);if(r==null)return;const o=this._matchPositionByLeftOffset(i,r,n);if(o!=null)return{...o,isBack:!0}}_getSpanLeftOffsetInLine(i){const e=i.parent;if(e==null)return Number.NEGATIVE_INFINITY;const t=e.left,{left:n}=i;return t+n}_matchPositionByLeftOffset(i,e,t){const n={distance:Number.POSITIVE_INFINITY};for(const r of e.divides){const o=r.left;for(const c of r.spanGroup){const{left:l}=c,u=o+l,d=Math.abs(t-u);d<n.distance&&(n.span=c,n.distance=d)}}if(n.span!=null)return i.findPositionBySpan(n.span)}_getNextOrPrevLine(i,e){var f,v,_,p,I,O,R,y,U,b,D,x;const t=i.parent;if(t==null)return;const n=t.parent;if(n==null)return;const r=n.parent;if(r==null)return;const o=r.lines.indexOf(n);if(o===-1)return;let c;if(e===!0?c=r.lines[o+1]:c=r.lines[o-1],c!=null)return c;const l=r.parent;if(l==null)return;const u=l.columns.indexOf(r);if(u===-1)return;if(e===!0)c=(f=l.columns[u+1])==null?void 0:f.lines[0];else{const T=(_=(v=l.columns)==null?void 0:v[u-1])==null?void 0:_.lines;c=T==null?void 0:T[T.length-1]}if(c!=null)return c;const d=l.parent;if(d==null)return;const h=d.sections.indexOf(l);if(h===-1)return;if(e===!0)c=(I=(p=d.sections[h-1])==null?void 0:p.columns[0])==null?void 0:I.lines[0];else{const T=(R=(O=d.sections)==null?void 0:O[h-1])==null?void 0:R.columns,w=T==null?void 0:T[T.length-1],N=w==null?void 0:w.lines;c=N==null?void 0:N[N.length-1]}if(c!=null)return c;const g=d.parent;if(g==null)return;const S=g.pages.indexOf(d);if(S!==-1){if(e===!0)c=(b=(U=(y=g.pages[S+1])==null?void 0:y.sections[0])==null?void 0:U.columns[0])==null?void 0:b.lines[0];else{const T=(D=g.pages[S-1])==null?void 0:D.sections;if(T==null)return;const w=(x=T[T.length-1])==null?void 0:x.columns,N=w[w.length-1],qe=N==null?void 0:N.lines;c=qe[qe.length-1]}if(c!=null)return c}}_getDocObject(){return ie(this._currentUniverService,this._renderManagerService)}};me=wt([s.OnLifecycle(s.LifecycleStages.Rendered,me),ee(0,E.Inject(m.DocSkeletonManagerService)),ee(1,s.IUniverInstanceService),ee(2,C.IRenderManagerService),ee(3,E.Inject(m.TextSelectionManagerService)),ee(4,s.ICommandService)],me);var Lt=Object.defineProperty,Bt=Object.getOwnPropertyDescriptor,$t=(a,i,e,t)=>{for(var n=t>1?void 0:t?Bt(i,e):i,r=a.length-1,o;r>=0;r--)(o=a[r])&&(n=(t?o(i,e,n):o(n))||n);return t&&n&&Lt(i,e,n),n},te=(a,i)=>(e,t)=>i(e,t,a);let he=class extends s.Disposable{constructor(i,e,t,n,r){super();M(this,"_onInputSubscription");this._docSkeletonManagerService=i,this._currentUniverService=e,this._renderManagerService=t,this._textSelectionRenderManager=n,this._commandService=r,this._initialize(),this._commandExecutedListener()}dispose(){var i;(i=this._onInputSubscription)==null||i.unsubscribe()}_initialize(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async i=>{var f;if(i==null)return;const t=this._currentUniverService.getCurrentUniverDocInstance().getUnitId(),{event:n,content:r="",activeRange:o}=i,c=n,l=(f=this._docSkeletonManagerService.getCurrent())==null?void 0:f.skeleton;if(c.data==null||l==null||!l||!o)return;const{startOffset:u,segmentId:d,style:h}=o,g=r.length,S=[{startOffset:u+g,endOffset:u+g,style:h}];await this._commandService.executeCommand(k.id,{unitId:t,body:{dataStream:r},range:o,textRanges:S,segmentId:d})})}_commandExecutedListener(){}_getDocObject(){return ie(this._currentUniverService,this._renderManagerService)}};he=$t([s.OnLifecycle(s.LifecycleStages.Rendered,he),te(0,E.Inject(m.DocSkeletonManagerService)),te(1,s.IUniverInstanceService),te(2,C.IRenderManagerService),te(3,C.ITextSelectionRenderManager),te(4,s.ICommandService)],he);var Ft=Object.defineProperty,jt=Object.getOwnPropertyDescriptor,Vt=(a,i,e,t)=>{for(var n=t>1?void 0:t?jt(i,e):i,r=a.length-1,o;r>=0;r--)(o=a[r])&&(n=(t?o(i,e,n):o(n))||n);return t&&n&&Ft(i,e,n),n},Ke=(a,i)=>(e,t)=>i(e,t,a);const kt="rgba(198, 198, 198, 1)",Xt="rgba(255, 255, 255, 1)";let ge=class extends s.Disposable{constructor(a,i){super(),this._renderManagerService=a,this._currentUniverService=i,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh()}_initialRenderRefresh(){this._renderManagerService.currentRender$.subscribe(a=>{var r;if(a==null||this._currentUniverService.getUniverDocInstance(a)==null)return;const i=this._renderManagerService.getRenderById(a);if(i==null)return;const{mainComponent:e}=i,t=e,n=(r=t.getSkeleton())==null?void 0:r.getPageSize();t.onPageRenderObservable.add(o=>{var v,_,p,I;if([s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,s.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(a))return;const{page:c,pageLeft:l,pageTop:u,ctx:d}=o,{width:h,pageWidth:g,height:S,pageHeight:f}=c;d.save(),d.translate(l-.5,u-.5),C.Rect.drawWith(d,{width:(_=(v=n==null?void 0:n.width)!=null?v:g)!=null?_:h,height:(I=(p=n==null?void 0:n.height)!=null?p:f)!=null?I:S,strokeWidth:1,stroke:kt,fill:Xt,zIndex:3}),d.restore()})})}_commandExecutedListener(){}};ge=Vt([s.OnLifecycle(s.LifecycleStages.Rendered,ge),Ke(0,C.IRenderManagerService),Ke(1,E.Inject(s.IUniverInstanceService))],ge);var zt=Object.defineProperty,Yt=Object.getOwnPropertyDescriptor,Ht=(a,i,e,t)=>{for(var n=t>1?void 0:t?Yt(i,e):i,r=a.length-1,o;r>=0;r--)(o=a[r])&&(n=(t?o(i,e,n):o(n))||n);return t&&n&&zt(i,e,n),n},F=(a,i)=>(e,t)=>i(e,t,a);let Se=class extends s.Disposable{constructor(i,e,t,n,r,o){super();M(this,"_moveInObserver");M(this,"_moveOutObserver");M(this,"_downObserver");M(this,"_dblClickObserver");M(this,"_tripleClickObserver");M(this,"_loadedMap",new Set);this._docSkeletonManagerService=i,this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._textSelectionRenderManager=r,this._textSelectionManagerService=o,this._renderManagerService.currentRender$.subscribe(c=>{c!=null&&this._currentUniverService.getUniverDocInstance(c)!=null&&(this._loadedMap.has(c)||(this._initialMain(c),this._loadedMap.add(c)))}),this._initialize()}_initialize(){this._skeletonListener(),this._commandExecutedListener()}dispose(){this._renderManagerService.getRenderAll().forEach(i=>{const{mainComponent:e}=i;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(i){const e=this._getDocObjectById(i);if(e==null)return;const{document:t,scene:n}=e;this._moveInObserver=t.onPointerEnterObserver.add(()=>{t.cursor=C.CURSOR_TYPE.TEXT}),this._moveOutObserver=t.onPointerLeaveObserver.add(()=>{t.cursor=C.CURSOR_TYPE.DEFAULT,n.resetCursor()}),this._downObserver=t==null?void 0:t.onPointerDownObserver.add((r,o)=>{this._currentUniverService.getCurrentUniverDocInstance().getUnitId()!==i&&this._currentUniverService.setCurrentUniverDocInstance(i),this._textSelectionRenderManager.eventTrigger(r),r.button!==2&&o.stopPropagation()}),this._dblClickObserver=t==null?void 0:t.onDblclickObserver.add(r=>{this._textSelectionRenderManager.handleDblClick(r)}),this._tripleClickObserver=t==null?void 0:t.onTripleClickObserver.add(r=>{this._textSelectionRenderManager.handleTripleClick(r)})}_commandExecutedListener(){const i=[$.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t;if(i.includes(e.id)){const n=e.params,{unitId:r}=n,o=(t=this._textSelectionManagerService.getCurrentSelection())==null?void 0:t.unitId;if(r!==o)return;this._textSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this._docSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{unitId:e,skeleton:t}=i,n=this._renderManagerService.getRenderById(e);if(n==null)return;const{scene:r,mainComponent:o}=n;this._textSelectionRenderManager.changeRuntime(t,r,o),this._textSelectionManagerService.setCurrentSelectionNotRefresh({unitId:e,subUnitId:""})})}_getDocObjectById(i){return Ze(i,this._renderManagerService)}};Se=Ht([s.OnLifecycle(s.LifecycleStages.Rendered,Se),F(0,E.Inject(m.DocSkeletonManagerService)),F(1,s.IUniverInstanceService),F(2,s.ICommandService),F(3,C.IRenderManagerService),F(4,C.ITextSelectionRenderManager),F(5,E.Inject(m.TextSelectionManagerService))],Se);var Wt=Object.defineProperty,Gt=Object.getOwnPropertyDescriptor,Kt=(a,i,e,t)=>{for(var n=t>1?void 0:t?Gt(i,e):i,r=a.length-1,o;r>=0;r--)(o=a[r])&&(n=(t?o(i,e,n):o(n))||n);return t&&n&&Wt(i,e,n),n},ne=(a,i)=>(e,t)=>i(e,t,a);let _e=class extends s.Disposable{constructor(i,e,t,n,r){super();M(this,"_initializedRender",new Set);this._docSkeletonManagerService=i,this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._textSelectionManagerService=r,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._initialRenderRefresh()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{unitId:e}=i,t=this._renderManagerService.getRenderById(e);if(t==null||this._initializedRender.has(e)||[s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,s.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(e))return;this._initializedRender.add(e);const{scene:n}=t;this.disposeWithMe(s.toDisposable(n.onMouseWheelObserver.add(r=>{if(!r.ctrlKey)return;const o=Math.abs(r.deltaX);let c=o<40?.2:o<80?.4:.2;c*=r.deltaY>0?-1:1,n.scaleX<1&&(c/=2);const l=this._currentUniverService.getCurrentUniverDocInstance(),u=l.zoomRatio;let d=+Number.parseFloat(`${u+c}`).toFixed(1);d=d>=4?4:d<=.1?.1:d,this._commandService.executeCommand(He.id,{zoomRatio:d,unitId:l.getUnitId()}),r.preventDefault()})))})}_skeletonListener(){this.disposeWithMe(s.toDisposable(this._docSkeletonManagerService.currentSkeletonBefore$.subscribe(i=>{if(i==null)return;const t=this._currentUniverService.getCurrentUniverDocInstance().zoomRatio||1;this._updateViewZoom(t,!1)})))}_commandExecutedListener(){const i=[$.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(i.includes(e.id)){const t=this._currentUniverService.getCurrentUniverDocInstance(),n=e.params,{unitId:r}=n;if(r!==t.getUnitId())return;const o=t.zoomRatio||1;this._updateViewZoom(o)}}))}_updateViewZoom(i,e=!0){var n;const t=this._getDocObject();t!=null&&(t.scene.scale(i,i),this._calculatePagePosition(t,i),e&&this._textSelectionManagerService.refreshSelection(),(n=t.scene.getTransformer())==null||n.hideControl())}_calculatePagePosition(i,e){const{document:t,scene:n}=i,r=n==null?void 0:n.getParent(),{width:o,height:c,pageMarginLeft:l,pageMarginTop:u}=t;if(r==null||o===Number.POSITIVE_INFINITY||c===Number.POSITIVE_INFINITY)return;const{width:d,height:h}=r;let g=0,S=0,f=0,v=0,_=Number.POSITIVE_INFINITY;d>(o+l*2)*e?(g=d/2-o*e/2,g/=e,f=(d-l*2)/e,_=0):(g=l,f=o+l*2,_=(f-d/e)/2),h>c?(S=h/2-c/2,v=(h-u*2)/e):(S=u,v=c+u*2),n.resize(f,v+200),t.translate(g,S);const p=n.getViewport(se.VIEW_MAIN);if(_!==Number.POSITIVE_INFINITY&&p!=null){const I=p.getBarScroll(_,0).x;p.scrollTo({x:I})}return this}_getDocObject(){return ie(this._currentUniverService,this._renderManagerService)}};_e=Kt([s.OnLifecycle(s.LifecycleStages.Rendered,_e),ne(0,E.Inject(m.DocSkeletonManagerService)),ne(1,s.IUniverInstanceService),ne(2,s.ICommandService),ne(3,C.IRenderManagerService),ne(4,E.Inject(m.TextSelectionManagerService))],_e);var qt=Object.defineProperty,Zt=Object.getOwnPropertyDescriptor,Jt=(a,i,e,t)=>{for(var n=t>1?void 0:t?Zt(i,e):i,r=a.length-1,o;r>=0;r--)(o=a[r])&&(n=(t?o(i,e,n):o(n))||n);return t&&n&&qt(i,e,n),n},fe=(a,i)=>(e,t)=>i(e,t,a);m.DocCanvasView=class extends s.RxDisposable{constructor(e,t,n,r){super();M(this,"_scene");M(this,"_currentDocumentModel");M(this,"_loadedMap",new Set);M(this,"_fps$",new A.BehaviorSubject(""));M(this,"fps$",this._fps$.asObservable());this._renderManagerService=e,this._configService=t,this._currentUniverService=n,this._docViewModelManagerService=r,this._initialize()}_initialize(){this._currentUniverService.currentDoc$.pipe(A.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;this._currentDocumentModel=e;const t=e.getUnitId();this._loadedMap.has(t)||(this._addNewRender(),this._loadedMap.add(t))})}dispose(){this._fps$.complete()}_addNewRender(){const e=this._currentDocumentModel,t=e.getUnitId(),n=e.getContainer(),r=e.getParentRenderUnitId();if(n!=null&&r!=null)throw new Error("container or parentRenderUnitId can only exist one");n==null&&r!=null?this._renderManagerService.createRenderWithParent(t,r):this._renderManagerService.createRender(t);const o=this._renderManagerService.getRenderById(t);if(o==null)return;const{scene:c,engine:l}=o;c.openTransformer(),this._scene=c;const u=new C.Viewport(se.VIEW_MAIN,c,{left:0,top:0,bottom:0,right:0,isWheelPreventDefaultX:!0});c.attachControl(),c.on(C.EVENT_TYPE.wheel,(g,S)=>{const f=g;if(f.ctrlKey){const v=Math.abs(f.deltaX);let _=v<40?.2:v<80?.4:.2;_*=f.deltaY>0?-1:1,c.scaleX<1&&(_/=2),c.scaleX+_>4?c.scale(4,4):c.scaleX+_<.1?c.scale(.1,.1):f.preventDefault()}else u.onMouseWheel(f,S)}),this._configService.getConfig("hasScroll")!==!1&&t!==s.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&new C.ScrollBar(u),c.addLayer(new C.Layer(c,[],pe),new C.Layer(c,[],Ue)),this._addComponent(o),this._currentDocumentModel.getShouldRenderLoopImmediately()&&l.runRenderLoop(()=>{c.render(),this._fps$.next(Math.round(l.getFps()).toString())}),this._renderManagerService.setCurrent(t)}_addComponent(e){const t=this._scene,n=this._currentDocumentModel,r=new C.Documents(re.MAIN,void 0,{pageMarginLeft:n.documentStyle.marginLeft||0,pageMarginTop:n.documentStyle.marginTop||0});r.zIndex=Pe,e.mainComponent=r,e.components.set(re.MAIN,r),t.addObjects([r],pe)}},m.DocCanvasView=Jt([s.OnLifecycle(s.LifecycleStages.Ready,m.DocCanvasView),fe(0,C.IRenderManagerService),fe(1,s.IConfigService),fe(2,s.IUniverInstanceService),fe(3,E.Inject(m.DocViewModelManagerService))],m.DocCanvasView);var Qt=Object.defineProperty,en=Object.getOwnPropertyDescriptor,tn=(a,i,e,t)=>{for(var n=t>1?void 0:t?en(i,e):i,r=a.length-1,o;r>=0;r--)(o=a[r])&&(n=(t?o(i,e,n):o(n))||n);return t&&n&&Qt(i,e,n),n},ve=(a,i)=>(e,t)=>i(e,t,a);const nn={hasScroll:!0},rn="docs";m.UniverDocsPlugin=(Ee=class extends s.Plugin{constructor(e={},t,n,r,o){super(rn);M(this,"_config");this._injector=t,this._localeService=n,this._configService=r,this._currentUniverService=o,this._config=Object.assign(nn,e),this._initializeDependencies(t),this._initializeCommands()}initialize(){}_initializeCommands(){[ae,oe,Be,$e,z,Y,H,W,B,G,K,q,Z,De,we,k,X,Te,ye,Re,P,Xe,ze,He,$,Ie,We,ke,Ve,xe].forEach(e=>{this._injector.get(s.ICommandService).registerCommand(e)})}onReady(){this.initialize()}_initializeDependencies(e){[[m.DocCanvasView],[m.DocSkeletonManagerService],[m.DocViewModelManagerService],[m.DocStateChangeManagerService],[V],[C.ITextSelectionRenderManager,{useClass:C.TextSelectionRenderManager}],[m.TextSelectionManagerService],[ce],[ge],[Se],[he],[de],[ue],[me],[_e],[le]].forEach(t=>e.add(t))}},M(Ee,"type",s.PluginType.Doc),Ee),m.UniverDocsPlugin=tn([ve(1,E.Inject(E.Injector)),ve(2,E.Inject(s.LocaleService)),ve(3,s.IConfigService),ve(4,s.IUniverInstanceService)],m.UniverDocsPlugin),m.BreakLineCommand=we,m.BulletListCommand=Ve,m.CoverContentCommand=ze,m.CutContentCommand=Oe,m.DOCS_COMPONENT_DEFAULT_Z_INDEX=Pe,m.DOCS_COMPONENT_HEADER_LAYER_INDEX=Ue,m.DOCS_COMPONENT_MAIN_LAYER_INDEX=pe,m.DOCS_VIEW_KEY=re,m.DeleteCommand=X,m.DeleteLeftCommand=Be,m.DeleteRightCommand=$e,m.IMEInputCommand=ye,m.IMEInputManagerService=V,m.InnerPasteCommand=gt,m.InsertCommand=k,m.MoveCursorOperation=ae,m.MoveSelectionOperation=oe,m.NORMAL_TEXT_SELECTION_PLUGIN_NAME=Je,m.OrderListCommand=ke,m.ReplaceContentCommand=Xe,m.RichTextEditingMutation=P,m.SelectAllOperation=We,m.SetInlineFormatBoldCommand=z,m.SetInlineFormatCommand=De,m.SetInlineFormatFontFamilyCommand=q,m.SetInlineFormatFontSizeCommand=K,m.SetInlineFormatItalicCommand=Y,m.SetInlineFormatStrikethroughCommand=W,m.SetInlineFormatSubscriptCommand=B,m.SetInlineFormatSuperscriptCommand=G,m.SetInlineFormatTextColorCommand=Z,m.SetInlineFormatUnderlineCommand=H,m.SetTextSelectionsOperation=Ie,m.UpdateCommand=Te,m.VIEWPORT_KEY=se,m.getDocObject=ie,m.serializeTextRange=j,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|