@univerjs/docs-ui 0.4.1 → 0.4.2-nightly.202410301606

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.
Files changed (52) hide show
  1. package/lib/core-editing.command-DAmOCaTR.mjs +1905 -0
  2. package/lib/es/facade.js +109 -0
  3. package/lib/es/index.js +577 -2416
  4. package/lib/locale/en-US.js +85 -0
  5. package/lib/locale/fa-IR.js +85 -0
  6. package/lib/locale/ru-RU.js +85 -0
  7. package/lib/locale/vi-VN.js +85 -0
  8. package/lib/locale/zh-CN.js +85 -0
  9. package/lib/locale/zh-TW.js +85 -0
  10. package/lib/types/basics/paragraph.d.ts +85 -1
  11. package/lib/types/commands/commands/doc-header-footer.command.d.ts +4 -0
  12. package/lib/types/commands/commands/paragraph-align.command.d.ts +1 -1
  13. package/lib/types/commands/commands/switch-doc-mode.command.d.ts +4 -0
  14. package/lib/types/controllers/doc-header-footer.controller.d.ts +2 -0
  15. package/lib/types/controllers/menu/menu.d.ts +1 -0
  16. package/lib/types/controllers/render-controllers/doc-ime-input.controller.d.ts +5 -5
  17. package/lib/types/controllers/render-controllers/doc-input.controller.d.ts +5 -3
  18. package/lib/types/controllers/render-controllers/doc.render-controller.d.ts +2 -3
  19. package/lib/types/controllers/render-controllers/zoom.render-controller.d.ts +2 -2
  20. package/lib/types/facade/f-document.d.ts +34 -0
  21. package/lib/types/facade/f-univer.d.ts +34 -0
  22. package/lib/types/facade/index.d.ts +1 -0
  23. package/lib/types/index.d.ts +2 -4
  24. package/lib/types/locale/zh-CN.d.ts +1 -0
  25. package/lib/types/services/doc-auto-format.service.d.ts +2 -2
  26. package/lib/types/services/doc-event-manager.service.d.ts +2 -2
  27. package/lib/types/services/doc-ime-input-manager.service.d.ts +1 -1
  28. package/lib/types/services/doc-menu-style.service.d.ts +12 -0
  29. package/lib/types/services/doc-state-change-manager.service.d.ts +10 -0
  30. package/lib/types/services/editor/editor-manager.service.d.ts +63 -0
  31. package/lib/types/services/selection/text-range.d.ts +2 -2
  32. package/lib/types/views/doc-container/DocContainer.d.ts +1 -1
  33. package/lib/umd/facade.js +19 -0
  34. package/lib/umd/index.js +14 -14
  35. package/lib/umd/locale/en-US.js +1 -0
  36. package/lib/umd/locale/fa-IR.js +1 -0
  37. package/lib/umd/locale/ru-RU.js +1 -0
  38. package/lib/umd/locale/vi-VN.js +1 -0
  39. package/lib/umd/locale/zh-CN.js +1 -0
  40. package/lib/umd/locale/zh-TW.js +1 -0
  41. package/package.json +23 -21
  42. package/LICENSE +0 -176
  43. package/lib/cjs/index.js +0 -37
  44. package/lib/locale/en-US.json +0 -81
  45. package/lib/locale/fa-IR.json +0 -81
  46. package/lib/locale/ru-RU.json +0 -81
  47. package/lib/locale/vi-VN.json +0 -81
  48. package/lib/locale/zh-CN.json +0 -81
  49. package/lib/locale/zh-TW.json +0 -81
  50. package/lib/types/basics/custom-range-factory.d.ts +0 -25
  51. package/lib/types/basics/replace.d.ts +0 -20
  52. /package/lib/types/commands/commands/{delete.command.d.ts → doc-delete.command.d.ts} +0 -0
@@ -1,14 +1,16 @@
1
- import { Disposable, ICommandService, DocumentDataModel } from '@univerjs/core';
2
- import { DocSkeletonManagerService } from '@univerjs/docs';
1
+ import { DocumentDataModel, Disposable, ICommandService } from '@univerjs/core';
3
2
  import { IRenderContext, IRenderModule } from '@univerjs/engine-render';
3
+ import { DocSkeletonManagerService } from '@univerjs/docs';
4
+ import { DocMenuStyleService } from '../../services/doc-menu-style.service';
4
5
  import { DocSelectionRenderService } from '../../services/selection/doc-selection-render.service';
5
6
  export declare class DocInputController extends Disposable implements IRenderModule {
6
7
  private readonly _context;
7
8
  private readonly _docSelectionRenderService;
8
9
  private readonly _docSkeletonManagerService;
9
10
  private readonly _commandService;
11
+ private readonly _docMenuStyleService;
10
12
  private _onInputSubscription;
11
- constructor(_context: IRenderContext<DocumentDataModel>, _docSelectionRenderService: DocSelectionRenderService, _docSkeletonManagerService: DocSkeletonManagerService, _commandService: ICommandService);
13
+ constructor(_context: IRenderContext<DocumentDataModel>, _docSelectionRenderService: DocSelectionRenderService, _docSkeletonManagerService: DocSkeletonManagerService, _commandService: ICommandService, _docMenuStyleService: DocMenuStyleService);
12
14
  dispose(): void;
13
15
  private _init;
14
16
  private _initialNormalInput;
@@ -1,18 +1,17 @@
1
- import { DocumentDataModel, ICommandService, IContextService, IUniverInstanceService, RxDisposable } from '@univerjs/core';
1
+ import { DocumentDataModel, ICommandService, IUniverInstanceService, RxDisposable } from '@univerjs/core';
2
2
  import { IRenderContext, IRenderModule, IRenderManagerService } from '@univerjs/engine-render';
3
3
  import { DocSkeletonManagerService } from '@univerjs/docs';
4
4
  import { IEditorService } from '../../services/editor/editor-manager.service';
5
5
  import { DocSelectionRenderService } from '../../services/selection/doc-selection-render.service';
6
6
  export declare class DocRenderController extends RxDisposable implements IRenderModule {
7
7
  private readonly _context;
8
- private readonly _contextService;
9
8
  private readonly _commandService;
10
9
  private readonly _docSelectionRenderService;
11
10
  private readonly _docSkeletonManagerService;
12
11
  private readonly _editorService;
13
12
  private readonly _renderManagerService;
14
13
  private readonly _univerInstanceService;
15
- constructor(_context: IRenderContext<DocumentDataModel>, _contextService: IContextService, _commandService: ICommandService, _docSelectionRenderService: DocSelectionRenderService, _docSkeletonManagerService: DocSkeletonManagerService, _editorService: IEditorService, _renderManagerService: IRenderManagerService, _univerInstanceService: IUniverInstanceService);
14
+ constructor(_context: IRenderContext<DocumentDataModel>, _commandService: ICommandService, _docSelectionRenderService: DocSelectionRenderService, _docSkeletonManagerService: DocSkeletonManagerService, _editorService: IEditorService, _renderManagerService: IRenderManagerService, _univerInstanceService: IUniverInstanceService);
16
15
  reRender(unitId: string): void;
17
16
  private _addNewRender;
18
17
  private _addComponent;
@@ -1,6 +1,6 @@
1
- import { Disposable, ICommandService, IContextService, IUniverInstanceService, DocumentDataModel } from '@univerjs/core';
2
- import { DocSelectionManagerService, DocSkeletonManagerService } from '@univerjs/docs';
1
+ import { DocumentDataModel, Disposable, ICommandService, IContextService, IUniverInstanceService } from '@univerjs/core';
3
2
  import { IRenderContext, IRenderModule } from '@univerjs/engine-render';
3
+ import { DocSelectionManagerService, DocSkeletonManagerService } from '@univerjs/docs';
4
4
  import { DocPageLayoutService } from '../../services/doc-page-layout.service';
5
5
  import { IEditorService } from '../../services/editor/editor-manager.service';
6
6
  export declare class DocZoomRenderController extends Disposable implements IRenderModule {
@@ -0,0 +1,34 @@
1
+ import { DocumentDataModel, IDocumentData, ICommandService, Injector, IResourceManagerService, IUniverInstanceService } from '@univerjs/core';
2
+ import { IRenderManagerService } from '@univerjs/engine-render';
3
+ export declare class FDocument {
4
+ private readonly _documentDataModel;
5
+ protected readonly _injector: Injector;
6
+ private readonly _univerInstanceService;
7
+ private readonly _commandService;
8
+ private readonly _resourceManagerService;
9
+ private readonly _renderManagerService;
10
+ readonly id: string;
11
+ constructor(_documentDataModel: DocumentDataModel, _injector: Injector, _univerInstanceService: IUniverInstanceService, _commandService: ICommandService, _resourceManagerService: IResourceManagerService, _renderManagerService: IRenderManagerService);
12
+ getId(): string;
13
+ getName(): string;
14
+ getSnapshot(): IDocumentData;
15
+ undo(): Promise<boolean>;
16
+ redo(): Promise<boolean>;
17
+ /**
18
+ * Adds the specified text to the end of this text region.
19
+ * @param text
20
+ */
21
+ appendText(text: string): Promise<boolean>;
22
+ /**
23
+ * Sets the selection to a specified text range in the document.
24
+ *
25
+ * @param startOffset - The starting offset of the selection in the document.
26
+ * @param endOffset - The ending offset of the selection in the document.
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * document.setSelection(10, 20);
31
+ * ```
32
+ */
33
+ setSelection(startOffset: number, endOffset: number): void;
34
+ }
@@ -0,0 +1,34 @@
1
+ import { IDocumentData, FUniver } from '@univerjs/core';
2
+ import { FDocument } from './f-document';
3
+ interface IFUniverDocsUIMixin {
4
+ /**
5
+ * Create a new document and get the API handler of that document.
6
+ *
7
+ * @param {Partial<IDocumentData>} data The snapshot of the document.
8
+ * @returns {FDocument} FDocument API instance.
9
+ */
10
+ createUniverDoc(data: Partial<IDocumentData>): FDocument;
11
+ /**
12
+ * Get the document API handler by the document id.
13
+ *
14
+ * @param {string} id The document id.
15
+ * @returns {FDocument | null} The document API instance.
16
+ */
17
+ getUniverDoc(id: string): FDocument | null;
18
+ /**
19
+ * Get the currently focused Univer document.
20
+ *
21
+ * @returns {FDocument | null} The currently focused Univer document.
22
+ */
23
+ getActiveDocument(): FDocument | null;
24
+ }
25
+ export declare class FUniverDocsMixin extends FUniver implements IFUniverDocsUIMixin {
26
+ createUniverDoc(data: Partial<IDocumentData>): FDocument;
27
+ getActiveDocument(): FDocument | null;
28
+ getUniverDoc(id: string): FDocument | null;
29
+ }
30
+ declare module '@univerjs/core' {
31
+ interface FUniver extends IFUniverDocsUIMixin {
32
+ }
33
+ }
34
+ export {};
@@ -0,0 +1 @@
1
+ export { FDocument } from './f-document';
@@ -18,10 +18,8 @@ export * from './basics';
18
18
  export type { IDocObjectParam } from './basics/component-tools';
19
19
  export { getDocObject, getDocObjectById, neoGetDocObject } from './basics/component-tools';
20
20
  export { addCustomDecorationBySelectionFactory, addCustomDecorationFactory, deleteCustomDecorationFactory } from './basics/custom-decoration-factory';
21
- export { addCustomRangeBySelectionFactory, addCustomRangeFactory, deleteCustomRangeFactory } from './basics/custom-range-factory';
22
21
  export * from './basics/docs-view-key';
23
22
  export { hasParagraphInTable } from './basics/paragraph';
24
- export { replaceSelectionFactory } from './basics/replace';
25
23
  export { docDrawingPositionToTransform, transformToDocDrawingPosition } from './basics/transform-position';
26
24
  export { getCommandSkeleton, getRichTextEditPath } from './commands/util';
27
25
  export { TextEditor } from './components/editor/TextEditor';
@@ -60,8 +58,8 @@ export { CutContentCommand, InnerPasteCommand } from './commands/commands/clipbo
60
58
  export type { IInnerCutCommandParams } from './commands/commands/clipboard.inner.command';
61
59
  export { getCustomBlockIdsInSelections, getCutActionsFromDocRanges } from './commands/commands/clipboard.inner.command';
62
60
  export { DeleteCommand, EditorInsertTextCommandId, type ICoverCommandParams, type IDeleteCommandParams, type IInsertCommandParams, InsertCommand, type IUpdateCommandParams, UpdateCommand, } from './commands/commands/core-editing.command';
63
- export { DeleteCustomBlockCommand, DeleteLeftCommand, DeleteRightCommand, type IDeleteCustomBlockParams, MergeTwoParagraphCommand } from './commands/commands/delete.command';
64
- export { getCursorWhenDelete } from './commands/commands/delete.command';
61
+ export { DeleteCustomBlockCommand, DeleteLeftCommand, DeleteRightCommand, type IDeleteCustomBlockParams, MergeTwoParagraphCommand } from './commands/commands/doc-delete.command';
62
+ export { getCursorWhenDelete } from './commands/commands/doc-delete.command';
65
63
  export { IMEInputCommand } from './commands/commands/ime-input.command';
66
64
  export { ResetInlineFormatTextBackgroundColorCommand, SetInlineFormatBoldCommand, SetInlineFormatCommand, SetInlineFormatFontFamilyCommand, SetInlineFormatFontSizeCommand, SetInlineFormatItalicCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatSubscriptCommand, SetInlineFormatSuperscriptCommand, SetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextColorCommand, SetInlineFormatUnderlineCommand, } from './commands/commands/inline-format.command';
67
65
  export { getParagraphsInRange, getParagraphsInRanges } from './commands/commands/list.command';
@@ -43,6 +43,7 @@ declare const locale: {
43
43
  order: string;
44
44
  unorder: string;
45
45
  checklist: string;
46
+ documentFlavor: string;
46
47
  alignLeft: string;
47
48
  alignCenter: string;
48
49
  alignRight: string;
@@ -1,6 +1,6 @@
1
- import { Disposable, IUniverInstanceService, DocumentDataModel, ICommandInfo, ICustomRange, IDisposable, IParagraphRange, Nullable } from '@univerjs/core';
2
- import { DocSelectionManagerService } from '@univerjs/docs';
1
+ import { DocumentDataModel, ICommandInfo, ICustomRange, IDisposable, IParagraphRange, Nullable, Disposable, IUniverInstanceService } from '@univerjs/core';
3
2
  import { ITextRangeWithStyle } from '@univerjs/engine-render';
3
+ import { DocSelectionManagerService } from '@univerjs/docs';
4
4
  export interface IAutoFormatContext {
5
5
  unit: DocumentDataModel;
6
6
  selection: ITextRangeWithStyle;
@@ -1,6 +1,6 @@
1
- import { Disposable, DocumentDataModel, ICustomRange, IParagraph, Nullable } from '@univerjs/core';
2
- import { DocSkeletonManagerService } from '@univerjs/docs';
1
+ import { DocumentDataModel, ICustomRange, IParagraph, Nullable, Disposable } from '@univerjs/core';
3
2
  import { Documents, DocumentSkeleton, IBoundRectNoAngle, IDocumentSkeletonGlyph, IRenderContext, IRenderModule } from '@univerjs/engine-render';
3
+ import { DocSkeletonManagerService } from '@univerjs/docs';
4
4
  export declare const calcDocGlyphPosition: (glyph: IDocumentSkeletonGlyph, documents: Documents, skeleton: DocumentSkeleton, pageIndex?: number) => IBoundRectNoAngle | undefined;
5
5
  interface ICustomRangeActive {
6
6
  range: ICustomRange;
@@ -1,4 +1,4 @@
1
- import { RxDisposable, DocumentDataModel, Nullable } from '@univerjs/core';
1
+ import { DocumentDataModel, Nullable, RxDisposable } from '@univerjs/core';
2
2
  import { IRichTextEditingMutationParams } from '@univerjs/docs';
3
3
  import { IRenderContext, IRenderModule, ITextRangeWithStyle } from '@univerjs/engine-render';
4
4
  interface ICacheParams {
@@ -0,0 +1,12 @@
1
+ import { ITextStyle, Nullable, Disposable } from '@univerjs/core';
2
+ import { DocSelectionManagerService } from '@univerjs/docs';
3
+ export declare class DocMenuStyleService extends Disposable {
4
+ private readonly _textSelectionManagerService;
5
+ private _cacheStyle;
6
+ constructor(_textSelectionManagerService: DocSelectionManagerService);
7
+ private _init;
8
+ private _listenDocRangeChange;
9
+ getStyleCache(): Nullable<ITextStyle>;
10
+ setStyleCache(style: ITextStyle): void;
11
+ private _clearStyleCache;
12
+ }
@@ -1,6 +1,10 @@
1
1
  import { Nullable, ICommandService, IUndoRedoService, IUniverInstanceService, RxDisposable } from '@univerjs/core';
2
2
  import { DocStateEmitService, IDocStateChangeParams } from '@univerjs/docs';
3
3
  import { IRenderManagerService } from '@univerjs/engine-render';
4
+ interface IStateCache {
5
+ history: IDocStateChangeParams[];
6
+ collaboration: IDocStateChangeParams[];
7
+ }
4
8
  export declare class DocStateChangeManagerService extends RxDisposable {
5
9
  private _undoRedoService;
6
10
  private readonly _commandService;
@@ -14,6 +18,11 @@ export declare class DocStateChangeManagerService extends RxDisposable {
14
18
  private _historyTimer;
15
19
  private _changeStateCacheTimer;
16
20
  constructor(_undoRedoService: IUndoRedoService, _commandService: ICommandService, _univerInstanceService: IUniverInstanceService, _docStateEmitService: DocStateEmitService, _renderManagerService: IRenderManagerService);
21
+ getStateCache(unitId: string): {
22
+ history: IDocStateChangeParams[];
23
+ collaboration: IDocStateChangeParams[];
24
+ };
25
+ setStateCache(unitId: string, cache: IStateCache): void;
17
26
  private _setChangeState;
18
27
  private _initialize;
19
28
  private _listenDocStateChange;
@@ -21,3 +30,4 @@ export declare class DocStateChangeManagerService extends RxDisposable {
21
30
  private _pushHistory;
22
31
  private _emitChangeState;
23
32
  }
33
+ export {};
@@ -12,14 +12,29 @@ export interface IEditorInputFormulaParam {
12
12
  editorUnitId: string;
13
13
  formulaString: string;
14
14
  }
15
+ /**
16
+ * @deprecated
17
+ */
15
18
  export interface IEditorService {
16
19
  getEditor(id?: string): Readonly<Nullable<Editor>>;
17
20
  register(config: IEditorConfigParams, container: HTMLDivElement): IDisposable;
21
+ /**
22
+ * @deprecated
23
+ */
18
24
  isVisible(id: string): Nullable<boolean>;
19
25
  inputFormula$: Observable<IEditorInputFormulaParam>;
26
+ /**
27
+ * @deprecated
28
+ */
20
29
  setFormula(formulaString: string): void;
21
30
  resize$: Observable<string>;
31
+ /**
32
+ * @deprecated
33
+ */
22
34
  resize(id: string): void;
35
+ /**
36
+ * @deprecated
37
+ */
23
38
  getAllEditor(): Map<string, Editor>;
24
39
  /**
25
40
  * The sheet currently being operated on will determine
@@ -36,27 +51,75 @@ export interface IEditorService {
36
51
  isEditor(editorUnitId: string): boolean;
37
52
  isSheetEditor(editorUnitId: string): boolean;
38
53
  closeRangePrompt$: Observable<unknown>;
54
+ /**
55
+ * @deprecated
56
+ */
39
57
  closeRangePrompt(): void;
40
58
  blur$: Observable<unknown>;
59
+ /**
60
+ * @deprecated
61
+ */
41
62
  blur(): void;
42
63
  focus$: Observable<ISuccinctDocRangeParam>;
64
+ /**
65
+ * @deprecated
66
+ */
43
67
  focus(editorUnitId?: string): void;
44
68
  setValue$: Observable<IEditorSetValueParam>;
45
69
  valueChange$: Observable<Readonly<Editor>>;
70
+ /**
71
+ * @deprecated
72
+ */
46
73
  setValue(val: string, editorUnitId?: string): void;
74
+ /**
75
+ * @deprecated
76
+ */
47
77
  setValueNoRefresh(val: string, editorUnitId?: string): void;
78
+ /**
79
+ * @deprecated
80
+ */
48
81
  setRichValue(body: IDocumentBody, editorUnitId?: string): void;
82
+ /**
83
+ * @deprecated
84
+ */
49
85
  getFirstEditor(): Editor;
50
86
  focusStyle$: Observable<Nullable<string>>;
87
+ /**
88
+ * @deprecated
89
+ */
51
90
  focusStyle(editorUnitId: Nullable<string>): void;
91
+ /**
92
+ * @deprecated
93
+ */
52
94
  refreshValueChange(editorId: string): void;
95
+ /**
96
+ * @deprecated
97
+ */
53
98
  checkValueLegality(editorId: string): boolean;
99
+ /**
100
+ * @deprecated
101
+ */
54
102
  getValue(id: string): Nullable<string>;
103
+ /**
104
+ * @deprecated
105
+ */
55
106
  getRichValue(id: string): Nullable<IDocumentBody>;
107
+ /**
108
+ * @deprecated
109
+ */
56
110
  changeSpreadsheetFocusState(state: boolean): void;
111
+ /**
112
+ * @deprecated
113
+ */
57
114
  getSpreadsheetFocusState(): boolean;
115
+ /**
116
+ * @deprecated
117
+ */
58
118
  selectionChangingState(): boolean;
59
119
  singleSelection$: Observable<boolean>;
120
+ /**
121
+ * @deprecated
122
+ */
60
123
  singleSelection(state: boolean): void;
61
124
  setFocusId(id: Nullable<string>): void;
62
125
  getFocusId(): Nullable<string>;
@@ -1,5 +1,5 @@
1
- import { DOC_RANGE_TYPE, RANGE_DIRECTION, Nullable } from '@univerjs/core';
2
- import { Rect, Documents, DocumentSkeleton, INodePosition, IPoint, ISuccinctDocRangeParam, ITextSelectionStyle, Scene, ThinScene } from '@univerjs/engine-render';
1
+ import { Nullable, DOC_RANGE_TYPE, RANGE_DIRECTION } from '@univerjs/core';
2
+ import { Documents, DocumentSkeleton, INodePosition, IPoint, ISuccinctDocRangeParam, ITextSelectionStyle, Scene, ThinScene, Rect } from '@univerjs/engine-render';
3
3
  import { IDocRange } from './range-interface';
4
4
  export declare const TEXT_RANGE_LAYER_INDEX = 3;
5
5
  export declare function cursorConvertToTextRange(scene: Scene, range: ISuccinctDocRangeParam, docSkeleton: DocumentSkeleton, document: Documents): Nullable<TextRange>;
@@ -1,5 +1,5 @@
1
- import { default as React, Component } from 'react';
2
1
  import { IUniverDocsUIConfig } from '../../controllers/config.schema';
2
+ import { default as React, Component } from 'react';
3
3
  interface IBaseDocContainerProps {
4
4
  config: IUniverDocsUIConfig;
5
5
  changeLocale: (locale: string) => void;
@@ -0,0 +1,19 @@
1
+ (function(O,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/docs"),require("@univerjs/ui"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","@univerjs/docs","@univerjs/ui","rxjs"],u):(O=typeof globalThis<"u"?globalThis:O||self,u(O.UniverDocsUiFacade={},O.UniverCore,O.UniverEngineRender,O.UniverDocs,O.UniverUi,O.rxjs))})(this,function(O,u,I,j,bt,N){"use strict";var Zt=Object.defineProperty;var te=(O,u,I)=>u in O?Zt(O,u,{enumerable:!0,configurable:!0,writable:!0,value:I}):O[u]=I;var _=(O,u,I)=>te(O,typeof u!="symbol"?u+"":u,I);var ft=(c=>(c[c.LEFT=0]="LEFT",c[c.RIGHT=1]="RIGHT",c))(ft||{});function et(c,t=""){if(!t)return["body"];const{headers:e,footers:n}=c.getSnapshot();if(e==null&&n==null)throw new Error("Document data model must have headers or footers when update by segment id");if((e==null?void 0:e[t])!=null)return["headers",t,"body"];if((n==null?void 0:n[t])!=null)return["footers",t,"body"];throw new Error("Segment id not found in headers or footers")}const Ot={id:"doc.command.insert-text",type:u.CommandType.COMMAND,handler:async(c,t)=>{var w;const e=c.get(u.ICommandService),{range:n,segmentId:s,body:o,unitId:i,cursorOffset:r,extendLastRange:a}=t,l=c.get(j.DocSelectionManagerService),d=c.get(u.IUniverInstanceService).getUnit(i,u.UniverInstanceType.UNIVER_DOC);if(d==null)return!1;const g=l.getActiveTextRange(),p=d.getSelfOrHeaderFooterModel((w=g==null?void 0:g.segmentId)!=null?w:"").getBody();if(p==null)return!1;const P=a?u.BuildTextUtils.selection.getDeleteSelection(n,p):u.BuildTextUtils.selection.getInsertSelection(n,p),{startOffset:m,collapsed:R}=P,f=r!=null?r:o.dataStream.length,S=[{startOffset:m+f,endOffset:m+f,style:g==null?void 0:g.style,collapsed:R}],C={id:j.RichTextEditingMutation.id,params:{unitId:i,actions:[],textRanges:S,debounce:!0}},E=new u.TextX,F=u.JSONX.getInstance();if(R)m>0&&E.push({t:u.TextXActionType.RETAIN,len:m});else{const{dos:B,retain:v}=u.BuildTextUtils.selection.getDeleteActions(P,s,0,p);E.push(...B),C.params.textRanges=[{startOffset:m+f+v,endOffset:m+f+v,collapsed:R}]}E.push({t:u.TextXActionType.INSERT,body:o,len:o.dataStream.length});const x=et(d,s);return C.params.actions=F.editOp(E.serialize(),x),!!e.syncExecuteCommand(C.id,C.params)}};u.CommandType.COMMAND,u.CommandType.COMMAND;var J=(c=>(c[c.page=0]="page",c[c.section=1]="section",c[c.column=2]="column",c[c.line=3]="line",c[c.divide=4]="divide",c[c.glyph=5]="glyph",c))(J||{});const q={page:0,section:1,column:2,line:3,divide:4,glyph:5};function nt(c,t){return c.page>t.page?!1:c.page<t.page?!0:c.section>t.section?!1:c.section<t.section?!0:c.column>t.column?!1:c.column<t.column?!0:c.line>t.line?!1:c.line<t.line?!0:c.divide>t.divide?!1:c.divide<t.divide?!0:c.glyph>t.glyph?!1:(c.glyph<t.glyph,!0)}function st(c,t){return nt(c,t)?{start:c,end:t}:{start:t,end:c}}function gt(c){const t=c.length;if(t===0)return;const e=c[0],n=c[t-1],s=c.length===1&&e.collapsed;return{startOffset:e.startOffset,endOffset:n.endOffset,collapsed:s}}function Nt(c,t,e,n){let s=n,o=n;for(let i=0;i<c.length;i++){const a=c[i].count;i<t&&(s+=a),i<e&&(o+=a)}return{startOffset:s,endOffset:o}}function ot(c){const{startX:t,startY:e,endX:n,endY:s}=c,o=[];return o.push({x:t,y:e}),o.push({x:n,y:e}),o.push({x:n,y:s}),o.push({x:t,y:s}),o.push({x:t,y:e}),o}class _t{constructor(t,e){_(this,"_liquid",new I.Liquid);_(this,"_currentStartState",{page:0,section:0,column:0,line:0,divide:0,glyph:0});_(this,"_currentEndState",{page:0,section:0,column:0,line:0,divide:0,glyph:0});this._documentOffsetConfig=t,this._docSkeleton=e}getRangePointData(t,e){const n=[],s=[],o=[];if(t==null||e==null)return{borderBoxPointGroup:n,contentBoxPointGroup:s,cursorList:o};if(!this._isValidPosition(t,e))throw new Error(`
2
+ Invalid positions in NodePositionConvertToCursor,
3
+ they are not in the same segment page when in header or footer.`);const{start:r,end:a}=st(t,e);return this._selectionIterator(r,a,(l,h,d,g,p,P)=>{const{lineHeight:m,asc:R,paddingTop:f,marginTop:S,marginBottom:C}=P,{glyphGroup:E,st:F}=p;if(E.length===0)return;const{x,y}=this._liquid;let w,B;const v=E[l],T=E[h],k=E[l-1],b=(v==null?void 0:v.left)||0,D=(v==null?void 0:v.width)||0,A=(T==null?void 0:T.left)||0,M=(T==null?void 0:T.width)||0,L=(v==null?void 0:v.glyphType)===I.GlyphType.LIST,{startOffset:U,endOffset:G}=Nt(E,l,h,F),$=r.glyph===l&&d?r.isBack:!0,X=a.glyph===h&&g?a.isBack:!1,tt=r===a,Y=$&&k!=null?k:v;if(l===0&&h===E.length-1)w={startX:x+b+(L?D:0),startY:y,endX:x+A+(X?0:M),endY:y+m-S-C},B={startX:x+b+(L?D:0),startY:y+f+R-Y.bBox.ba,endX:x+A+(X?0:M),endY:y+f+R+Y.bBox.bd};else{const z=$&&!L;w={startX:x+b+(z?0:D),startY:y,endX:x+A+(X?0:M),endY:y+m-S-C},B={startX:x+b+(z?0:D),startY:y+f+R-Y.bBox.ba,endX:x+A+(X?0:M),endY:y+f+R+Y.bBox.bd}}n.push(ot(w)),s.push(ot(B)),o.push({startOffset:$?U:U+v.count,endOffset:X?G:G+T.count,collapsed:tt})}),{borderBoxPointGroup:n,contentBoxPointGroup:s,cursorList:o}}_isValidPosition(t,e){const{segmentPage:n,pageType:s}=t,{segmentPage:o,pageType:i}=e;return s!==i?!1:s===I.DocumentSkeletonPageType.HEADER||s===I.DocumentSkeletonPageType.FOOTER?n===o:!0}_resetCurrentNodePositionState(){this._currentStartState={page:0,section:0,column:0,line:0,divide:0,glyph:0},this._currentEndState={page:0,section:0,column:0,line:0,divide:0,glyph:0}}_setNodePositionState(t=0,e,n,s){s===e?this._currentStartState[t]=1:this._currentStartState[t]=0,s===n?this._currentEndState[t]=2:this._currentEndState[t]=0}_checkPreviousNodePositionState(t,e=!0){let n=t,s;for(;n>=0;){const o=J[n];let i;if(e?i=this._currentStartState[o]:i=this._currentEndState[o],i===void 0)return;if(s===void 0&&(s=i),i!==s)return 0;n--}return s}_getSelectionRuler(t,e,n,s,o){let i=0,r=s;const a=J[t],l=J[t+1];if(l===null||a===null)return{start_next:i,end_next:r};const h=e[a],d=n[a];this._setNodePositionState(a,h,d,o);const g=this._checkPreviousNodePositionState(t),p=this._checkPreviousNodePositionState(t,!1);return g===1&&(i=e[l]),p===2&&(r=n[l]),{start_next:i,end_next:r}}_selectionIterator(t,e,n){var E,F;const s=this._docSkeleton;if(!s)return[];const{pageType:o,path:i}=t;this._liquid.reset();const r=s.getSkeletonData();if(r==null)return[];const{pages:a,skeHeaders:l,skeFooters:h}=r,{page:d,segmentPage:g}=t,{page:p,segmentPage:P}=e;if(this._resetCurrentNodePositionState(),this._documentOffsetConfig==null)return[];const{pageLayoutType:m,pageMarginLeft:R,pageMarginTop:f}=this._documentOffsetConfig,S=o===I.DocumentSkeletonPageType.BODY||o===I.DocumentSkeletonPageType.CELL?d:g;for(let x=0;x<S;x++){const y=a[x];this._liquid.translatePage(y,m,R,f)}const C=o===I.DocumentSkeletonPageType.BODY||o===I.DocumentSkeletonPageType.CELL?p:P;for(let x=S;x<=C;x++){const y=a[x],{headerId:w,footerId:B,pageWidth:v}=y;let T=y;if(o===I.DocumentSkeletonPageType.HEADER?T=(E=l.get(w))==null?void 0:E.get(v):o===I.DocumentSkeletonPageType.FOOTER?T=(F=h.get(B))==null?void 0:F.get(v):o===I.DocumentSkeletonPageType.CELL&&(T=I.getPageFromPath(r,i)),T==null){this._liquid.translatePage(y,m,R,f);continue}const k=T.sections,{start_next:b,end_next:D}=this._getSelectionRuler(q.page,t,e,k.length-1,o===I.DocumentSkeletonPageType.BODY||o===I.DocumentSkeletonPageType.CELL?x:0);switch(this._liquid.translateSave(),o){case I.DocumentSkeletonPageType.HEADER:this._liquid.translatePagePadding({...T,marginLeft:y.marginLeft});break;case I.DocumentSkeletonPageType.FOOTER:{const A=y.pageHeight-T.height-T.marginBottom;this._liquid.translate(y.marginLeft,A);break}case I.DocumentSkeletonPageType.CELL:{this._liquid.translatePagePadding(y);const A=T.parent,M=A.parent,{left:L}=T,{top:U,left:G}=M,{top:$}=A;this._liquid.translate(G+L,U+$),this._liquid.translatePagePadding(T);break}default:this._liquid.translatePagePadding(y);break}for(let A=b;A<=D;A++){const M=k[A],L=M.columns,{start_next:U,end_next:G}=this._getSelectionRuler(q.section,t,e,L.length-1,A);this._liquid.translateSection(M);for(let $=U;$<=G;$++){const X=L[$],tt=X.lines,{start_next:Y,end_next:z}=this._getSelectionRuler(q.column,t,e,tt.length-1,$);this._liquid.translateColumn(X);for(let V=Y;V<=z;V++){const ht=tt[V],{divides:Tt}=ht,{start_next:Ct,end_next:yt}=this._getSelectionRuler(q.line,t,e,Tt.length-1,V);this._liquid.translateSave(),this._liquid.translateLine(ht,!0,!1);for(let W=Ct;W<=yt;W++){const dt=Tt[W];this._liquid.translateSave(),this._liquid.translateDivide(dt);const{glyphGroup:zt}=dt,{start_next:Jt,end_next:Qt}=this._getSelectionRuler(q.divide,t,e,zt.length-1,W);let xt=!1,Et=!1;x===S&&A===b&&$===U&&V===Y&&W===Ct&&(xt=!0),x===C&&A===D&&$===G&&V===z&&W===yt&&(Et=!0),n&&n(Jt,Qt,xt,Et,dt,ht,X,M,T),this._liquid.translateRestore()}this._liquid.translateRestore()}}}this._liquid.translateRestore(),this._liquid.translatePage(y,m,R,f)}}}function wt(c,t){const{path:e}=c,{path:n}=t;if(e.length!==n.length||e.indexOf("cells")===-1)return!1;const s=e.indexOf("skeTables")+1,o=e.indexOf("rows")+1,i=e.indexOf("cells")+1,r=I.getTableIdAndSliceIndex(e[s]).tableId,a=I.getTableIdAndSliceIndex(n[s]).tableId;if(r!==a)return!1;const l=e[o],h=n[o],d=e[i],g=n[i];return!(l===h&&d===g)}function pt(c,t){const{path:e}=c,{path:n}=t;return e.indexOf("cells")===-1||n.indexOf("cells")===-1?!1:u.Tools.diffValue(e,n)}function Q(c,t){if(pt(c,t))return nt(c,t);const{path:e}=c,{path:n}=t,s=e[e.length-5],o=n[n.length-5];if(s!==o&&typeof s=="string"&&typeof o=="string"){const h=s.split("#-#")[1],d=o.split("#-#")[1];return+h<+d}const i=e[e.length-3],r=n[n.length-3],a=e[e.length-1],l=n[n.length-1];return i<r?!0:i>r?!1:a<=l}function At(c){return c.sections[0].columns[0].lines[0].divides[0].glyphGroup[0]}function Lt(c){const{sections:t}=c,e=t[t.length-1],n=e.columns[e.columns.length-1],s=n.lines[n.lines.length-1],i=s.divides[s.divides.length-1].glyphGroup;return i[i.length-2]}class mt{constructor(t,e){_(this,"_liquid",new I.Liquid);this._documentOffsetConfig=t,this._docSkeleton=e}getRangePointData(t,e){const n=[],o=this._docSkeleton.getSkeletonData();if(o==null)return;const{pages:i}=o,{segmentPage:r,page:a,pageType:l}=t,{segmentPage:h,page:d}=e,g=this._getTableRectRangeInfo(t,e);if(g==null)return;const{tableId:p,startRowIndex:P,startColumnIndex:m,endRowIndex:R,endColumnIndex:f}=g;this._liquid.reset();const{pageLayoutType:S,pageMarginLeft:C,pageMarginTop:E}=this._documentOffsetConfig,F=l===I.DocumentSkeletonPageType.BODY||l===I.DocumentSkeletonPageType.CELL?a:r;for(let y=0;y<F;y++){const w=i[y];this._liquid.translatePage(w,S,C,E)}const x=l===I.DocumentSkeletonPageType.BODY||l===I.DocumentSkeletonPageType.CELL?d:h;for(let y=F;y<=x;y++){const w=i[y];this._liquid.translatePagePadding(w);const{skeTables:B}=w;let v=null;for(const[b,D]of B.entries())b.startsWith(p)&&(v=D);if(v==null){this._liquid.restorePagePadding(w),this._liquid.translatePage(w,S,C,E);continue}this._liquid.translateSave(),this._liquid.translate(0,v.top);const{x:T,y:k}=this._liquid;for(const b of v.rows)if(b.index>=P&&b.index<=R){const D=b.cells[m],A=b.cells[f],M={startX:T+D.left,startY:k+b.top,endX:T+A.left+A.pageWidth,endY:k+b.top+b.height};n.push(ot(M))}this._liquid.translateRestore(),this._liquid.restorePagePadding(w),this._liquid.translatePage(w,S,C,E)}return{pointGroup:n,startRow:P,startColumn:m,endRow:R,endColumn:f,tableId:p}}getNodePositionGroup(t,e){const n=[],s=Q(t,e),o=s?t:e,i=s?e:t,{segmentPage:r}=o,a=this._getTableRectRangeInfo(o,i);if(a==null)return;const{tableId:l,pages:h,startRowIndex:d,startColumnIndex:g,endRowIndex:p,endColumnIndex:P}=a,m=[];for(const f of h){const{skeTables:S}=f;for(const[C,E]of S.entries())C.startsWith(l)&&m.push(E)}if(m.length===0)return;for(const f of m)this._collectPositionGroup(f,n,d,p,g,P,r,s);const R=m[0].rows[0].cells.length;if(g===0&&P===R-1){const f=n[0],S=n[n.length-1];n.length=0,n.push({anchor:s?f.anchor:S.anchor,focus:s?S.focus:f.focus})}return n}_collectPositionGroup(t,e,n,s,o,i,r,a){for(let l=0;l<t.rows.length;l++){const h=t.rows[l];if(h.index<n)continue;if(h.index>s)break;const d=h.cells[o],g=h.cells[i],p=At(d),P=Lt(g);if(p==null||P==null)continue;const m=this._docSkeleton.findPositionByGlyph(p,r),R=this._docSkeleton.findPositionByGlyph(P,r);if(m==null||R==null)continue;const f=a?m:R,S=a?R:m;e.push({anchor:{...f,isBack:!0},focus:{...S,isBack:!0}})}}_getTableRectRangeInfo(t,e){const s=this._docSkeleton.getSkeletonData();if(s==null)return;const{pages:o}=s,{path:i}=t,{path:r}=e,a=I.getPageFromPath(s,i),l=I.getPageFromPath(s,r);if(a==null||l==null)return;const h=a.segmentId,d=a.parent.index,g=a.parent.cells.indexOf(a),p=(l==null?void 0:l.parent).index,P=(l==null?void 0:l.parent).cells.indexOf(l);return{pages:o,tableId:h,startCell:a,endCell:l,startRowIndex:d,startColumnIndex:g,endRowIndex:p,endColumnIndex:P}}}const Dt="__TestSelectionRange__",Bt="__TestSelectionAnchor__",St=6,it=500,kt=500,rt=3;function at(c){const t=c[0],e=t[0],n=t[2],{x:s,y:o}=e,{x:i,y:r}=n;return{left:s,top:o,width:i-s,height:r-o}}class H{constructor(t,e,n,s,o,i=I.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,r="",a=-1){_(this,"rangeType",u.DOC_RANGE_TYPE.TEXT);_(this,"_current",!1);_(this,"_rangeShape");_(this,"_anchorShape");_(this,"_cursorList",[]);_(this,"_anchorBlinkTimer",null);this._scene=t,this._document=e,this._docSkeleton=n,this.anchorNodePosition=s,this.focusNodePosition=o,this.style=i,this._segmentId=r,this._segmentPage=a,this._anchorBlink(),this.refresh()}_anchorBlink(){setTimeout(()=>{this._anchorShape&&this._anchorShape.visible&&this.deactivateStatic()},it),this._anchorBlinkTimer=setInterval(()=>{this._anchorShape&&this._anchorShape.visible&&(this.activeStatic(),setTimeout(()=>{this.deactivateStatic()},it))},kt+it)}get startOffset(){var s;const{startOffset:t}=(s=gt(this._cursorList))!=null?s:{},e=this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId).getBody();if(t==null||e==null)return t;const n=e.dataStream.length-2;return Math.min(n,t)}get endOffset(){var s;const{endOffset:t}=(s=gt(this._cursorList))!=null?s:{},e=this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId).getBody();if(t==null||e==null)return t;const n=e.dataStream.length-2;return Math.min(t,n)}get collapsed(){const{startOffset:t,endOffset:e}=this;return t!=null&&t===e}get startNodePosition(){if(this.anchorNodePosition==null)return null;if(this.focusNodePosition==null)return this.anchorNodePosition;const{start:t}=st(this.anchorNodePosition,this.focusNodePosition);return t}get endNodePosition(){if(this.anchorNodePosition==null)return this.focusNodePosition;if(this.focusNodePosition==null)return null;const{end:t}=st(this.anchorNodePosition,this.focusNodePosition);return t}get direction(){const{collapsed:t,anchorNodePosition:e,focusNodePosition:n}=this;return t||e==null||n==null?u.RANGE_DIRECTION.NONE:nt(e,n)?u.RANGE_DIRECTION.FORWARD:u.RANGE_DIRECTION.BACKWARD}get segmentId(){return this._segmentId}get segmentPage(){return this._segmentPage}getAbsolutePosition(){const t=this.anchorNodePosition,e=this.focusNodePosition;if(this._isEmpty())return;const n=this._document.getOffsetConfig(),{docsLeft:s,docsTop:o}=n,i=new _t(n,this._docSkeleton);if(this._isCollapsed()){const{contentBoxPointGroup:h,cursorList:d}=i.getRangePointData(t,t);if(this._setCursorList(d),h.length===0)return;const g=at(h);return{...g,left:g.left+s,top:g.top+o}}const{borderBoxPointGroup:r,cursorList:a}=i.getRangePointData(t,e);if(this._setCursorList(a),r.length===0)return;const l=at(r);return{...l,left:l.left+s,top:l.top+o}}getAnchor(){return this._anchorShape}activeStatic(){var t,e;(e=this._anchorShape)==null||e.setProps({stroke:((t=this.style)==null?void 0:t.strokeActive)||I.getColor(u.COLORS.black,1)})}deactivateStatic(){var t,e;(e=this._anchorShape)==null||e.setProps({stroke:((t=this.style)==null?void 0:t.stroke)||I.getColor(u.COLORS.black,0)})}isActive(){return this._current===!0}activate(){this._current=!0}deactivate(){this._current=!1}dispose(){var t,e;(t=this._rangeShape)==null||t.dispose(),this._rangeShape=null,(e=this._anchorShape)==null||e.dispose(),this._anchorShape=null,this._anchorBlinkTimer&&(clearInterval(this._anchorBlinkTimer),this._anchorBlinkTimer=null)}isIntersection(t){const{startOffset:e,endOffset:n}=this,{startOffset:s,endOffset:o}=t;return e==null||n==null||s==null||o==null?!1:e<=o&&n>=s}refresh(){var d,g;const{_document:t,_docSkeleton:e}=this,n=this.anchorNodePosition,s=this.focusNodePosition;if((d=this._anchorShape)==null||d.hide(),(g=this._rangeShape)==null||g.hide(),this._isEmpty())return;const o=t.getOffsetConfig(),{docsLeft:i,docsTop:r}=o,a=new _t(o,e);if(this._isCollapsed()){const{contentBoxPointGroup:p,cursorList:P}=a.getRangePointData(n,n);if(this._setCursorList(P),p.length>0){const m=e.findGlyphByPosition(n);this._createOrUpdateAnchor(p,i,r,m)}return}const{borderBoxPointGroup:l,cursorList:h}=a.getRangePointData(n,s);this._setCursorList(h),l.length>0&&this._createOrUpdateRange(l,i,r)}_isEmpty(){return this.anchorNodePosition==null&&this.focusNodePosition==null}_isCollapsed(){const t=this.anchorNodePosition,e=this.focusNodePosition;if(t!=null&&e==null)return!0;if(t==null||e==null)return!1;const n=Object.keys(q);for(const s of n){const o=t[s],i=e[s];if(o!==i)return!1}return t.isBack===e.isBack}_createOrUpdateRange(t,e,n){var i;if(this._rangeShape){this._rangeShape.translate(e,n),this._rangeShape.updatePointGroup(t),this._rangeShape.show();return}const s=.3,o=new I.RegularPolygon(Dt+u.Tools.generateRandomId(St),{pointsGroup:t,fill:((i=this.style)==null?void 0:i.fill)||I.getColor(u.COLORS.black,s),left:e,top:n,evented:!1,debounceParentDirty:!1});this._rangeShape=o,this._scene.addObject(o,rt)}_createOrUpdateAnchor(t,e,n,s){var m,R,f;const o=at(t),{left:i}=o;let{top:r,height:a}=o;const l=14;a<l&&(r-=l-a,a=l);const h=12;let d=i+e;const g=r+n,p=((m=s==null?void 0:s.ts)==null?void 0:m.it)===u.BooleanNumber.TRUE;if(p&&(d+=a*Math.tan(h*Math.PI/180)/2),this._anchorShape){this._anchorShape.transformByState({left:d,top:g,height:a}),this._anchorShape.show(),p?this._anchorShape.skew(-h,0):this._anchorShape.skew(0,0);return}const P=new I.Rect(Bt+u.Tools.generateRandomId(St),{left:d,top:g,height:a,strokeWidth:((R=this.style)==null?void 0:R.strokeWidth)||1.5,stroke:((f=this.style)==null?void 0:f.strokeActive)||I.getColor(u.COLORS.black,1),evented:!1});p&&P.skew(-h,0),this._anchorShape=P,this._scene.addObject(P,rt)}_setCursorList(t){t.length!==0&&(this._cursorList=t)}}const Mt="__DocTableRectRange__",$t=6;function vt(c,t,e,n,s,o=I.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,i="",r=-1){const a=t.getOffsetConfig(),h=new mt(a,e).getNodePositionGroup(n,s);return(h!=null?h:[]).map(d=>new It(c,t,e,d.anchor,d.focus,o,i,r))}class It{constructor(t,e,n,s,o,i=I.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,r="",a=-1){_(this,"rangeType",u.DOC_RANGE_TYPE.RECT);_(this,"_rangeShape");_(this,"_current",!1);_(this,"_startRow");_(this,"_startCol");_(this,"_endRow");_(this,"_endCol");_(this,"_tableId");this._scene=t,this._document=e,this._docSkeleton=n,this.anchorNodePosition=s,this.focusNodePosition=o,this.style=i,this._segmentId=r,this._segmentPage=a,this.refresh()}get startOffset(){const{startNodePosition:t}=this;return this._docSkeleton.findCharIndexByPosition(t)}get endOffset(){const{endNodePosition:t}=this;return this._docSkeleton.findCharIndexByPosition(t)}get collapsed(){return!1}get startRow(){return this._startRow}get startColumn(){return this._startCol}get endRow(){return this._endRow}get endColumn(){return this._endCol}get tableId(){return this._tableId}get segmentId(){return this._segmentId}get segmentPage(){return this._segmentPage}get spanEntireRow(){var i;const e=(i=this._docSkeleton.getViewModel().getSnapshot().tableSource)==null?void 0:i[this._tableId],{_startCol:n,_endCol:s}=this;if(e==null)throw new Error("Table is not found.");const{tableColumns:o}=e;return n===0&&s===o.length-1}get spanEntireColumn(){var i;const e=(i=this._docSkeleton.getViewModel().getSnapshot().tableSource)==null?void 0:i[this._tableId],{_startRow:n,_endRow:s}=this;if(e==null)throw new Error("Table is not found.");const{tableRows:o}=e;return n===0&&s===o.length-1}get spanEntireTable(){return this.spanEntireRow&&this.spanEntireColumn}get startNodePosition(){const{anchorNodePosition:t,focusNodePosition:e}=this;return Q(t,e)?t:e}get endNodePosition(){const{anchorNodePosition:t,focusNodePosition:e}=this;return Q(t,e)?e:t}get direction(){const{anchorNodePosition:t,focusNodePosition:e}=this;return Q(t,e)?u.RANGE_DIRECTION.FORWARD:u.RANGE_DIRECTION.BACKWARD}isActive(){return this._current===!0}activate(){this._current=!0}deactivate(){this._current=!1}dispose(){var t;(t=this._rangeShape)==null||t.dispose(),this._rangeShape=null}isIntersection(t){const{startRow:e,startColumn:n,endRow:s,endColumn:o}=this,{startRow:i,startColumn:r,endRow:a,endColumn:l}=t,h={left:n,top:e,right:o,bottom:s},d={left:r,top:i,right:l,bottom:a};return u.Rectangle.hasIntersectionBetweenTwoRect(h,d)}refresh(){var R;(R=this._rangeShape)==null||R.hide();const{startNodePosition:t,endNodePosition:e,_document:n,_docSkeleton:s}=this,o=n.getOffsetConfig(),{docsLeft:i,docsTop:r}=o,l=new mt(o,s).getRangePointData(t,e);if(l==null)return;const{pointGroup:h=[],startRow:d,endRow:g,startColumn:p,endColumn:P,tableId:m}=l;(h==null?void 0:h.length)>0&&this._createOrUpdateRange(h,i,r),this._updateTableInfo(d,g,p,P,m)}_updateTableInfo(t,e,n,s,o){this._startRow=t,this._endRow=e,this._startCol=n,this._endCol=s,this._tableId=o}_createOrUpdateRange(t,e,n){var i;if(this._rangeShape){this._rangeShape.translate(e,n),this._rangeShape.updatePointGroup(t),this._rangeShape.show();return}const s=.3,o=new I.RegularPolygon(Mt+u.Tools.generateRandomId($t),{pointsGroup:t,fill:((i=this.style)==null?void 0:i.fill)||I.getColor(u.COLORS.black,s),left:e,top:n,evented:!1,debounceParentDirty:!1});this._rangeShape=o,this._scene.addObject(o,rt)}}function Rt(c,t,e,n,s,o,i,r,a=!0,l=!0){const h=s.findNodePositionByCharIndex(c,a,i,r),d=s.findNodePositionByCharIndex(t,l,i,r);if(!(h==null||d==null))return new H(e,n,s,h,d,o,i,r)}function Ft(c,t,e,n,s,o,i,r){const a=s.findNodePositionByCharIndex(c,!0,i,r),l=s.findNodePositionByCharIndex(t,!0,i,r);if(!(a==null||l==null))return new It(e,n,s,a,l,o,i,r)}function Ut(c,t,e,n,s,o,i,r){const a=s.findNodePositionByCharIndex(c,!0,i,r),l=s.findNodePositionByCharIndex(t,!0,i,r);if(!(a==null||l==null))return ct(a,l,e,n,s,o,i,r)}function ct(c,t,e,n,s,o,i,r){const a=[],l=[],h=[e,n,s,c,t,o,i,r];if(pt(c,t))return a.push(new H(...h)),{textRanges:a,rectRanges:l};if(wt(c,t)){const C=vt(...h);return l.push(...C),{textRanges:a,rectRanges:l}}const d=s.getViewModel().getSelfOrHeaderFooterViewModel(i),g=s.findCharIndexByPosition(c),p=s.findCharIndexByPosition(t);if(g==null||p==null)return;const P=g<=p?u.RANGE_DIRECTION.FORWARD:u.RANGE_DIRECTION.BACKWARD,m=Math.min(g,p),R=Math.max(g,p);let f=m,S=R;for(const C of d.children)for(const E of C.children){const{startIndex:F,endIndex:x,children:y}=E,w=y[0];let B=!1;if(w){const{startIndex:v,endIndex:T,children:k}=w;let b=null,D=null;const A=k.find(L=>L.startIndex<=m&&L.endIndex>=m),M=k.find(L=>L.startIndex<=R&&L.endIndex>=R);if(m>v&&m<T)b=s.findNodePositionByCharIndex(A.startIndex+2,!0,i,r),D=s.findNodePositionByCharIndex(T-4,!0,i,r),f=T+1;else if(R>v&&R<T)b=s.findNodePositionByCharIndex(v+3,!0,i,r),D=s.findNodePositionByCharIndex(M.endIndex-3,!0,i,r),S=v-1,B=!0;else if(v>m&&T<R){if(b=s.findNodePositionByCharIndex(v+3,!0,i,r),D=s.findNodePositionByCharIndex(T-4,!0,i,r),f<=v-1){const L=s.findNodePositionByCharIndex(f,!0,i,r),U=s.findNodePositionByCharIndex(v-1,!1,i,r),G=P===u.RANGE_DIRECTION.FORWARD?L:U,$=P===u.RANGE_DIRECTION.FORWARD?U:L;a.push(new H(e,n,s,G,$,o,i,r))}f=T+1}if(b&&D){const L=P===u.RANGE_DIRECTION.FORWARD?b:D,U=P===u.RANGE_DIRECTION.FORWARD?D:b;l.push(...vt(e,n,s,L,U,o,i,r))}}if(S>=F&&S<=x||B){const v=s.findNodePositionByCharIndex(f,!0,i,r),T=s.findNodePositionByCharIndex(S,!B,i,r),k=P===u.RANGE_DIRECTION.FORWARD?v:T,b=P===u.RANGE_DIRECTION.FORWARD?T:v;if(l.length&&u.Tools.diffValue(k,b))continue;a.push(new H(e,n,s,k,b,o,i,r))}}return{textRanges:a,rectRanges:l}}function Gt(c){const t=c==null?void 0:c.getCanvasElement();if(!t)return{left:0,top:0};const{top:e,left:n}=I.getOffsetRectForDom(t);return{left:n,top:e}}function Pt(c){var a;const t=(a=c.parent)==null?void 0:a.parent,e=t==null?void 0:t.parent;if(t==null||e==null)return;const{paragraphIndex:n}=t,s=e.lines.filter(l=>l.paragraphIndex===n);let o=-1,i="",r=!1;for(const l of s)for(const h of l.divides)for(const d of h.glyphGroup)r||(o+=d.count),d===c&&(r=!0),i+=d.count>0?d.content:"";return{st:s[0].st,ed:n,content:i,nodeIndex:o}}function lt(c){const{startOffset:t,endOffset:e,collapsed:n,rangeType:s,startNodePosition:o,endNodePosition:i,direction:r,segmentId:a,segmentPage:l}=c;return{startOffset:t,endOffset:e,collapsed:n,rangeType:s,startNodePosition:o,endNodePosition:i,direction:r,segmentId:a,segmentPage:l,isActive:c.isActive()}}function Xt(c){const t=lt(c),{startRow:e,startColumn:n,endRow:s,endColumn:o,tableId:i,spanEntireRow:r,spanEntireColumn:a,spanEntireTable:l}=c;return{...t,startRow:e,startColumn:n,endRow:s,endColumn:o,tableId:i,spanEntireRow:r,spanEntireColumn:a,spanEntireTable:l}}var Yt=Object.defineProperty,qt=Object.getOwnPropertyDescriptor,Ht=(c,t,e,n)=>{for(var s=n>1?void 0:n?qt(t,e):t,o=c.length-1,i;o>=0;o--)(i=c[o])&&(s=(n?i(t,e,s):i(s))||s);return n&&s&&Yt(t,e,s),s},Z=(c,t)=>(e,n)=>t(e,n,c);let ut=class extends u.RxDisposable{constructor(t,e,n,s,o){super();_(this,"_onInputBefore$",new N.Subject);_(this,"onInputBefore$",this._onInputBefore$.asObservable());_(this,"_onKeydown$",new N.Subject);_(this,"onKeydown$",this._onKeydown$.asObservable());_(this,"_onInput$",new N.Subject);_(this,"onInput$",this._onInput$.asObservable());_(this,"_onCompositionstart$",new N.BehaviorSubject(null));_(this,"onCompositionstart$",this._onCompositionstart$.asObservable());_(this,"_onCompositionupdate$",new N.BehaviorSubject(null));_(this,"onCompositionupdate$",this._onCompositionupdate$.asObservable());_(this,"_onCompositionend$",new N.BehaviorSubject(null));_(this,"onCompositionend$",this._onCompositionend$.asObservable());_(this,"_onSelectionStart$",new N.BehaviorSubject(null));_(this,"onSelectionStart$",this._onSelectionStart$.asObservable());_(this,"_onPaste$",new N.Subject);_(this,"onPaste$",this._onPaste$.asObservable());_(this,"_textSelectionInner$",new N.BehaviorSubject(null));_(this,"textSelectionInner$",this._textSelectionInner$.asObservable());_(this,"_onFocus$",new N.Subject);_(this,"onFocus$",this._onFocus$.asObservable());_(this,"_onBlur$",new N.Subject);_(this,"onBlur$",this._onBlur$.asObservable());_(this,"_onPointerDown$",new N.Subject);_(this,"onPointerDown$",this._onPointerDown$.asObservable());_(this,"_container");_(this,"_inputParent");_(this,"_input");_(this,"_scrollTimers",[]);_(this,"_rangeList",[]);_(this,"_rangeListCache",[]);_(this,"_rectRangeList",[]);_(this,"_rectRangeListCache",[]);_(this,"_anchorNodePosition",null);_(this,"_focusNodePosition",null);_(this,"_currentSegmentId","");_(this,"_currentSegmentPage",-1);_(this,"_selectionStyle",I.NORMAL_TEXT_SELECTION_PLUGIN_STYLE);_(this,"_viewPortObserverMap",new Map);_(this,"_isIMEInputApply",!1);_(this,"_scenePointerMoveSubs",[]);_(this,"_scenePointerUpSubs",[]);_(this,"_editorFocusing",!0);_(this,"_reserveRanges",!1);this._context=t,this._layoutService=e,this._logService=n,this._univerInstanceService=s,this._docSkeletonManagerService=o,this._initDOM(),this._registerContainer(),this._setSystemHighlightColorToStyle(),this._listenCurrentUnitChange()}_listenCurrentUnitChange(){this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_DOC).pipe(N.takeUntil(this.dispose$)).subscribe(t=>{if(t==null)return;t.getUnitId()!==this._context.unitId&&!this._reserveRanges&&this.removeAllRanges()})}get activeViewPort(){return this._context.scene.getViewports()[0]}setSegment(t){this._currentSegmentId=t}getSegment(){return this._currentSegmentId}setSegmentPage(t){this._currentSegmentPage=t}getSegmentPage(){return this._currentSegmentPage}setReserveRangesStatus(t){this._reserveRanges=t}_setRangeStyle(t=I.NORMAL_TEXT_SELECTION_PLUGIN_STYLE){this._selectionStyle=t}addDocRanges(t,e=!0,n){const{_currentSegmentId:s,_currentSegmentPage:o,_selectionStyle:i}=this,{scene:r,mainComponent:a}=this._context,l=a,h=this._docSkeletonManagerService.getSkeleton();for(const d of t){const{startOffset:g,endOffset:p,rangeType:P,startNodePosition:m,endNodePosition:R}=d;if(P===u.DOC_RANGE_TYPE.RECT){const f=Ft(g,p,r,l,h,i,s,o);f&&this._addRectRanges([f])}else if(P===u.DOC_RANGE_TYPE.TEXT){let f=null;m&&R?f=Rt(m.isBack?g:g-1,R.isBack?p:p-1,r,l,h,i,s,o,m.isBack,R.isBack):f=Rt(g,p,r,l,h,i,s,o),f&&this._addTextRange(f)}else{const f=Ut(g,p,r,l,h,i,s,o);if(f==null)continue;const{textRanges:S,rectRanges:C}=f;for(const E of S)this._addTextRange(E);this._addRectRanges(C)}}this._textSelectionInner$.next({textRanges:this._getAllTextRanges(),rectRanges:this._getAllRectRanges(),segmentId:s,segmentPage:o,style:i,isEditing:e,options:n}),this._updateInputPosition(n==null?void 0:n.forceFocus)}setCursorManually(t,e){const n=this._findNodeByCoord(t,e,{strict:!0,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage}),s=this._getNodePosition(n);if(s==null){this._removeAllRanges();return}(n==null?void 0:n.node.streamType)===u.DataStreamTreeTokenType.PARAGRAPH&&(s.isBack=!0),this._createTextRangeByAnchorPosition(s),this._textSelectionInner$.next({textRanges:this._getAllTextRanges(),rectRanges:this._getAllRectRanges(),segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage,style:this._selectionStyle,isEditing:!1})}sync(){this._updateInputPosition()}activate(t,e,n=!1){const s=this._input===document.activeElement||document.activeElement===document.body||document.activeElement===null;this._container.style.left=`${t}px`,this._container.style.top=`${e}px`,this._container.style.zIndex="1000",(s||n)&&this.focus()}hasFocus(){return document.activeElement===this._input}focus(){this._editorFocusing&&this._input.focus()}blur(){this._input.blur()}focusEditor(){this._editorFocusing=!0,this.focus()}blurEditor(){this._editorFocusing=!1,this.blur()}deactivate(){this._container.style.left="0px",this._container.style.top="0px"}__handleDblClick(t){const{offsetX:e,offsetY:n}=t,s=this._findNodeByCoord(e,n,{strict:!1,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage});if(s==null||s.node==null)return;const o=Pt(s.node);if(o==null)return;const{content:i,st:r,nodeIndex:a}=o;if(a===-1||Intl.Segmenter==null)return;const h=new Intl.Segmenter(void 0,{granularity:"word"}).segment(i);let d=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;for(const{segment:p,index:P,isWordLike:m}of h)if(P<=a&&a<P+p.length&&m){d=P+r,g=P+r+p.length;break}if(Number.isFinite(d)&&Number.isFinite(g)){this.removeAllRanges();const p=[{startOffset:d,endOffset:g}];this.addDocRanges(p,!1,{forceFocus:!0})}}__handleTripleClick(t){const{offsetX:e,offsetY:n}=t,s=this._findNodeByCoord(e,n,{strict:!1,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage});if(s==null||s.node==null)return;const o=Pt(s.node);if(o==null)return;this.removeAllRanges();const{st:i,ed:r}=o,a=[{startOffset:i,endOffset:r}];this.addDocRanges(a,!1,{forceFocus:!0})}__onPointDown(t){var m,R;this._editorFocusing=!0;const{scene:e,mainComponent:n}=this._context,s=this._docSkeletonManagerService.getSkeleton(),{offsetX:o,offsetY:i}=t,r=this._findNodeByCoord(o,i,{strict:!1,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage}),a=this._getNodePosition(r);if(a==null||r==null){this._removeAllRanges();return}(r==null?void 0:r.node.streamType)===u.DataStreamTreeTokenType.PARAGRAPH&&(a.isBack=!0);const l=this._textSelectionInner$.value;if(r&&t.button===2&&l){const f=s.findCharIndexByPosition(a);if(typeof f=="number"&&l.textRanges.some(S=>S.startOffset<=f&&S.endOffset>f)||typeof f=="number"&&l.rectRanges.some(S=>S.startOffset<=f&&S.endOffset>=f))return}const{segmentId:h,segmentPage:d}=r;h&&this._currentSegmentId&&h!==this._currentSegmentId&&this.setSegment(h),h&&d!==this._currentSegmentPage&&this.setSegmentPage(d),this._anchorNodePosition=a,t.shiftKey&&this._getActiveRangeInstance()?this._updateActiveRangePosition(a):t.ctrlKey?this._removeAllCollapsedTextRanges():this._isEmpty()||this._removeAllRanges(),e.disableObjectsEvent();const g=I.ScrollTimer.create(e);this._scrollTimers.push(g),g.startScroll(o,i),this._onSelectionStart$.next((m=this._getActiveRangeInstance())==null?void 0:m.startNodePosition),(R=e.getTransformer())==null||R.clearSelectedObjects();let p=o,P=i;this._scenePointerMoveSubs.push(e.onPointerMove$.subscribeEvent(f=>{const{offsetX:S,offsetY:C}=f;e.setCursor(I.CURSOR_TYPE.TEXT),!(Math.sqrt((S-p)**2+(C-P)**2)<3)&&(this._moving(S,C),g.scrolling(S,C,()=>{this._moving(S,C)}),p=S,P=C)})),this._scenePointerUpSubs.push(e.onPointerUp$.subscribeEvent(()=>{if([...this._scenePointerMoveSubs,...this._scenePointerUpSubs].forEach(S=>{S.unsubscribe()}),e.enableObjectsEvent(),this._anchorNodePosition&&!this._focusNodePosition){if(t.ctrlKey){this._disposeScrollTimers();return}const S=new H(e,n,s,this._anchorNodePosition,void 0,this._selectionStyle,this._currentSegmentId,this._currentSegmentPage);this._addTextRange(S)}else if(this._anchorNodePosition&&this._focusNodePosition){for(const S of this._rangeListCache)t.ctrlKey?S.collapsed?S.dispose():this._addTextRange(S):this._addTextRange(S);this._addRectRanges(this._rectRangeListCache),this._rangeListCache=[],this._rectRangeListCache=[]}this._anchorNodePosition=null,this._focusNodePosition=null;const f={textRanges:this._getAllTextRanges(),rectRanges:this._getAllRectRanges(),segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage,style:this._selectionStyle,isEditing:!1};this._textSelectionInner$.next(f),this._disposeScrollTimers(),this._updateInputPosition(!0)}))}removeAllRanges(){this._removeAllRanges(),this.deactivate()}getActiveTextRange(){return this._getActiveRangeInstance()}_disposeScrollTimers(){this._scrollTimers.forEach(t=>{t==null||t.dispose()}),this._scrollTimers=[]}_setSystemHighlightColorToStyle(){const{r:t,g:e,b:n,a:s}=I.getSystemHighlightColor(),o={strokeWidth:1.5,stroke:"rgba(0, 0, 0, 0)",strokeActive:"rgba(0, 0, 0, 1)",fill:`rgba(${t}, ${e}, ${n}, ${s!=null?s:.3})`};this._setRangeStyle(o)}_getAllTextRanges(){return this._rangeList.map(lt)}_getAllRectRanges(){return this._rectRangeList.map(Xt)}_getActiveRange(){const t=this._rangeList.find(s=>s.isActive());if(t==null)return null;const{startOffset:e,endOffset:n}=t;return e==null||n==null?null:lt(t)}_getActiveRangeInstance(){return this._rangeList.find(t=>t.isActive())}dispose(){super.dispose(),this._detachEvent(),this._removeAllRanges(),this._container.remove()}_initDOM(){const{unitId:t}=this._context,e=document.createElement("div");e.style.position="fixed",e.style.left="0px",e.style.top="0px",e.id=`univer-doc-selection-container-${t}`;const n=document.createElement("div"),s=document.createElement("div");n.appendChild(s),e.appendChild(n),this._container=e,this._inputParent=n,this._input=s,this._initInput(),this._initInputEvents(),document.body.appendChild(e)}_registerContainer(){this.disposeWithMe(this._layoutService.registerContainerElement(this._container))}_initInput(){this._inputParent.style.cssText=`
4
+ position:absolute;
5
+ height:1px;
6
+ width:1px;
7
+ overflow: hidden;
8
+ `,this._input.contentEditable="true",this._input.classList.add("univer-editor"),this._input.style.cssText=`
9
+ position: absolute;
10
+ overflow: hidden;
11
+ opacity: 1;
12
+ background: #000;
13
+ color: transparent;
14
+ outline: none;
15
+ z-index: -2;
16
+ caret-color: transparent;
17
+ white-space: pre-wrap;
18
+ user-select: text;
19
+ `}_getNodePosition(t){if(t==null)return;const{node:e,ratioX:n,segmentPage:s}=t,i=this._docSkeletonManagerService.getSkeleton().findPositionByGlyph(e,s);if(i==null)return;const a=n<.5;return{...i,isBack:a}}_interactTextRanges(t){const e=[];for(const n of this._rangeList){if(t.some(s=>s.isIntersection(n))){n.dispose();continue}e.push(n)}this._rangeList=e}_interactRectRanges(t){const e=[];for(const n of this._rectRangeList){if(t.some(s=>s.isIntersection(n))){n.dispose();continue}e.push(n)}this._rectRangeList=e}_removeCollapsedTextRange(){const t=this._rangeList;this._rangeList=[];for(const e of t)e.collapsed?e.dispose():this._rangeList.push(e)}_removeAllRanges(){this._removeAllTextRanges(),this._removeAllRectRanges()}_removeAllCacheRanges(){this._rangeListCache.forEach(t=>{t.dispose()}),this._rectRangeListCache.forEach(t=>{t.dispose()}),this._rangeListCache=[],this._rectRangeListCache=[]}_removeAllTextRanges(){this._rangeList.forEach(t=>{t.dispose()}),this._rangeList=[]}_removeAllRectRanges(){this._rectRangeList.forEach(t=>{t.dispose()}),this._rectRangeList=[]}_removeAllCollapsedTextRanges(){for(const t of this._rangeList)t.collapsed&&t.dispose()}_deactivateAllTextRanges(){this._rangeList.forEach(t=>{t.deactivate()})}_deactivateAllRectRanges(){this._rectRangeList.forEach(t=>{t.deactivate()})}_addTextRangesToCache(t){this._rangeListCache.push(...t)}_addTextRange(t){this._deactivateAllTextRanges(),t.activate(),this._rangeList.push(t)}_addRectRangesToCache(t){this._rectRangeListCache.push(...t)}_addRectRanges(t){t.length!==0&&(this._deactivateAllRectRanges(),t[t.length-1].activate(),this._rectRangeList.push(...t))}_createTextRangeByAnchorPosition(t){this._removeAllRanges();const{scene:e,mainComponent:n}=this._context,s=this._docSkeletonManagerService.getSkeleton(),o=new H(e,n,s,t,void 0,this._selectionStyle,this._currentSegmentId,this._currentSegmentPage);this._addTextRange(o)}_updateActiveRangePosition(t){const e=this._getActiveRangeInstance();if(e==null||e.anchorNodePosition==null){this._logService.error("[DocSelectionRenderService] _updateActiveRangeFocusPosition: active range has no anchor");return}this._removeAllRanges(),this._anchorNodePosition=e.anchorNodePosition,this._focusNodePosition=t;const{scene:n,mainComponent:s}=this._context,o=this._docSkeletonManagerService.getSkeleton(),{_anchorNodePosition:i,_focusNodePosition:r,_selectionStyle:a,_currentSegmentId:l,_currentSegmentPage:h}=this;if(i==null||r==null||s==null)return;const d=ct(i,r,n,s,o,a,l,h);if(d==null)return;const{textRanges:g,rectRanges:p}=d;this._addTextRangesToCache(g),this._addRectRangesToCache(p),this.deactivate()}_isEmpty(){return this._rangeList.length===0&&this._rectRangeList.length===0}_getCanvasOffset(){var e;const t=(e=this._context.scene)==null?void 0:e.getEngine();return Gt(t)}_updateInputPosition(t=!1){const e=this._getActiveRangeInstance(),n=e==null?void 0:e.getAnchor();if(!n||n&&!n.visible||this.activeViewPort==null){this.focus();return}const{left:s,top:o}=n,i=this.activeViewPort.getAbsoluteVector(I.Vector2.FromArray([s,o])),{x:r,y:a}=i;let{left:l,top:h}=this._getCanvasOffset();l+=r,h+=a,this.activate(l,h,t)}_moving(t,e){var S,C;const n=this._findNodeByCoord(t,e,{strict:!0,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage}),s=this._getNodePosition(n);if(!s||n==null)return;const o=n==null?void 0:n.node.parent,i=o==null?void 0:o.glyphGroup[o.glyphGroup.indexOf(n.node)+1];(n==null?void 0:n.node.streamType)===u.DataStreamTreeTokenType.PARAGRAPH&&(i==null?void 0:i.streamType)===u.DataStreamTreeTokenType.SECTION_BREAK&&(s.isBack=!0),this._focusNodePosition=s,this._removeAllCacheRanges();const{_anchorNodePosition:r,_focusNodePosition:a,_selectionStyle:l,_currentSegmentId:h,_currentSegmentPage:d}=this,{scene:g,mainComponent:p}=this._context,P=this._docSkeletonManagerService.getSkeleton();if(r==null||a==null||p==null)return;const m=ct(r,a,g,p,P,l,h,d);if(m==null)return;const{textRanges:R,rectRanges:f}=m;this._rangeList.length>0&&R.length>0&&this._interactTextRanges(R),this._rectRangeList.length>0&&f.length>0&&this._interactRectRanges(f),this._addTextRangesToCache(R),this._addRectRangesToCache(f),this.deactivate(),(C=(S=this._context.scene)==null?void 0:S.getEngine())==null||C.setRemainCapture()}__attachScrollEvent(){const t=this.activeViewPort;if(!t)return;const{unitId:e}=this._context;if(this._viewPortObserverMap.has(e))return;const n=t.onScrollAfter$.subscribeEvent(o=>{if(!o.viewport)return;const r=this._getActiveRangeInstance();r==null||r.activeStatic()}),s=t.onScrollEnd$.subscribeEvent(o=>{const i=o.viewport;if(!i)return;const r=i.getBounding(),a=this._getActiveRangeInstance(),l=a==null?void 0:a.getAnchor();if(!(!l||l&&!l.visible)){if(r){const{left:h,top:d,right:g,bottom:p}=r.viewBound;if(l.left<h||l.left>g||l.top<d||l.top>p){a==null||a.deactivateStatic();return}}this._updateInputPosition()}});this._viewPortObserverMap.set(e,{scrollBefore:n,scrollStop:s})}_initInputEvents(){this.disposeWithMe(N.fromEvent(this._input,"keydown").subscribe(t=>{this._isIMEInputApply||this._eventHandle(t,e=>{this._onKeydown$.next(e)})})),this.disposeWithMe(N.fromEvent(this._input,"input").subscribe(t=>{if(!(t.inputType==="historyUndo"||t.inputType==="historyRedo")){if(this._rectRangeList.length>0)return t.stopPropagation(),t.preventDefault();this._isIMEInputApply||this._eventHandle(t,e=>{this._onInputBefore$.next(e),this._onInput$.next(e)})}})),this.disposeWithMe(N.fromEvent(this._input,"compositionstart").subscribe(t=>{if(this._rectRangeList.length>0)return t.stopPropagation(),t.preventDefault();this._isIMEInputApply=!0,this._eventHandle(t,e=>{this._onCompositionstart$.next(e)})})),this.disposeWithMe(N.fromEvent(this._input,"compositionend").subscribe(t=>{this._isIMEInputApply=!1,this._eventHandle(t,e=>{this._onCompositionend$.next(e)})})),this.disposeWithMe(N.fromEvent(this._input,"compositionupdate").subscribe(t=>{this._eventHandle(t,e=>{this._onInputBefore$.next(e),this._onCompositionupdate$.next(e)})})),this.disposeWithMe(N.fromEvent(this._input,"paste").subscribe(t=>{this._eventHandle(t,e=>{this._onPaste$.next(e)})})),this.disposeWithMe(N.fromEvent(this._input,"focus").subscribe(t=>{this._eventHandle(t,e=>{this._onFocus$.next(e)})})),this.disposeWithMe(N.fromEvent(this._input,"blur").subscribe(t=>{this._eventHandle(t,e=>{this._onBlur$.next(e)})}))}_eventHandle(t,e){const n=this._input.textContent||"";this._input.innerHTML="";const s=this._getActiveRange(),o=this._getAllTextRanges();e({event:t,content:n,activeRange:s,rangeList:o})}_getTransformCoordForDocumentOffset(t,e){const n=this._context.mainComponent,{documentTransform:s}=n.getOffsetConfig();if(this.activeViewPort==null||s==null)return;const o=this.activeViewPort.transformVector2SceneCoord(I.Vector2.FromArray([t,e]));if(o)return s.clone().invert().applyPoint(o)}_findNodeByCoord(t,e,n){const s=this._getTransformCoordForDocumentOffset(t,e);if(s==null)return;const o=this._context.mainComponent,i=this._docSkeletonManagerService.getSkeleton(),{pageLayoutType:r=I.PageLayoutType.VERTICAL,pageMarginLeft:a,pageMarginTop:l}=o.getOffsetConfig();return i.findNodeByCoord(s,r,a,l,n)}_detachEvent(){this._onInputBefore$.complete(),this._onKeydown$.complete(),this._onInput$.complete(),this._onCompositionstart$.complete(),this._onCompositionupdate$.complete(),this._onCompositionend$.complete(),this._onSelectionStart$.complete(),this._textSelectionInner$.complete(),this._onPaste$.complete(),this._onFocus$.complete(),this._onBlur$.complete(),this._onPointerDown$.complete()}};ut=Ht([Z(1,bt.ILayoutService),Z(2,u.ILogService),Z(3,u.IUniverInstanceService),Z(4,u.Inject(j.DocSkeletonManagerService))],ut);var Vt=Object.defineProperty,Wt=Object.getOwnPropertyDescriptor,jt=(c,t,e,n)=>{for(var s=n>1?void 0:n?Wt(t,e):t,o=c.length-1,i;o>=0;o--)(i=c[o])&&(s=(n?i(t,e,s):i(s))||s);return n&&s&&Vt(t,e,s),s},K=(c,t)=>(e,n)=>t(e,n,c);O.FDocument=class{constructor(t,e,n,s,o,i){_(this,"id");this._documentDataModel=t,this._injector=e,this._univerInstanceService=n,this._commandService=s,this._resourceManagerService=o,this._renderManagerService=i,this.id=this._documentDataModel.getUnitId()}getId(){return this._documentDataModel.getUnitId()}getName(){return this.getSnapshot().title||""}getSnapshot(){const t=this._resourceManagerService.getResourcesByType(this.id,u.UniverInstanceType.UNIVER_DOC),e=this._documentDataModel.getSnapshot();return e.resources=t,e}undo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.executeCommand(u.UndoCommand.id)}redo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.executeCommand(u.RedoCommand.id)}appendText(t){const e=this.id,{body:n}=this.getSnapshot();if(!n)throw new Error("The document body is empty");const s=n.dataStream.length-2,o={startOffset:s,endOffset:s,collapsed:!0,segmentId:""},{segmentId:i}=o;return this._commandService.executeCommand(Ot.id,{unitId:e,body:{dataStream:t},range:o,segmentId:i})}setSelection(t,e){var s;const n=(s=this._renderManagerService.getRenderById(this.getId()))==null?void 0:s.with(ut);n==null||n.removeAllRanges(),n==null||n.addDocRanges([{startOffset:t,endOffset:e,rangeType:u.DOC_RANGE_TYPE.TEXT}],!0)}},O.FDocument=jt([K(1,u.Inject(u.Injector)),K(2,u.IUniverInstanceService),K(3,u.ICommandService),K(4,u.IResourceManagerService),K(5,I.IRenderManagerService)],O.FDocument);class Kt extends u.FUniver{createUniverDoc(t){const e=this._univerInstanceService.createUnit(u.UniverInstanceType.UNIVER_DOC,t);return this._injector.createInstance(O.FDocument,e)}getActiveDocument(){const t=this._univerInstanceService.getCurrentUnitForType(u.UniverInstanceType.UNIVER_DOC);return t?this._injector.createInstance(O.FDocument,t):null}getUniverDoc(t){const e=this._univerInstanceService.getUniverDocInstance(t);return e?this._injector.createInstance(O.FDocument,e):null}}u.FUniver.extend(Kt),Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});