@univerjs/docs-ui 0.1.12 → 0.1.13-nightly.202406041140
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 +3 -3
- package/lib/es/index.js +962 -935
- package/lib/locale/en-US.json +29 -0
- package/lib/locale/ru-RU.json +29 -0
- package/lib/locale/zh-CN.json +29 -0
- package/lib/types/basics/transform-position.d.ts +4 -0
- package/lib/types/controllers/doc-editor-bridge.controller.d.ts +1 -1
- package/lib/types/controllers/doc-floating-object.controller.d.ts +3 -5
- package/lib/types/controllers/drawing.controller.d.ts +19 -0
- package/lib/types/index.d.ts +2 -1
- package/lib/types/services/doc-popup-manager.service.d.ts +29 -0
- package/lib/umd/index.js +3 -3
- package/package.json +16 -15
- package/LICENSE +0 -176
- package/lib/types/locale/index.d.ts +0 -18
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"toolbar": {
|
|
3
|
+
"undo": "Undo",
|
|
4
|
+
"redo": "Redo",
|
|
5
|
+
"font": "Font",
|
|
6
|
+
"fontSize": "Font size",
|
|
7
|
+
"bold": "Bold",
|
|
8
|
+
"italic": "Italic",
|
|
9
|
+
"strikethrough": "Strikethrough",
|
|
10
|
+
"subscript": "Subscript",
|
|
11
|
+
"superscript": "Superscript",
|
|
12
|
+
"underline": "Underline",
|
|
13
|
+
"textColor": {
|
|
14
|
+
"main": "Text color",
|
|
15
|
+
"right": "Choose color"
|
|
16
|
+
},
|
|
17
|
+
"fillColor": {
|
|
18
|
+
"main": "Text Background color",
|
|
19
|
+
"right": "Choose color"
|
|
20
|
+
},
|
|
21
|
+
"resetColor": "Reset",
|
|
22
|
+
"order": "Ordered list",
|
|
23
|
+
"unorder": "Unordered list",
|
|
24
|
+
"alignLeft": "Align Left",
|
|
25
|
+
"alignCenter": "Align Center",
|
|
26
|
+
"alignRight": "Align Right",
|
|
27
|
+
"alignJustify": "Justify"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"toolbar": {
|
|
3
|
+
"undo": "Отменить",
|
|
4
|
+
"redo": "Повторить",
|
|
5
|
+
"font": "Шрифт",
|
|
6
|
+
"fontSize": "Размер шрифта",
|
|
7
|
+
"bold": "Полужирный",
|
|
8
|
+
"italic": "Курсив",
|
|
9
|
+
"strikethrough": "Зачеркнутый",
|
|
10
|
+
"subscript": "Нижний индекс",
|
|
11
|
+
"superscript": "Верхний индекс",
|
|
12
|
+
"underline": "Подчеркнутый",
|
|
13
|
+
"textColor": {
|
|
14
|
+
"main": "Цвет текста",
|
|
15
|
+
"right": "Выбрать цвет"
|
|
16
|
+
},
|
|
17
|
+
"fillColor": {
|
|
18
|
+
"main": "Цвет фона текста",
|
|
19
|
+
"right": "Выбрать цвет"
|
|
20
|
+
},
|
|
21
|
+
"resetColor": "Сбросить",
|
|
22
|
+
"order": "Упорядоченный список",
|
|
23
|
+
"unorder": "Неупорядоченный список",
|
|
24
|
+
"alignLeft": "Выровнять по левому краю",
|
|
25
|
+
"alignCenter": "Выровнять по центру",
|
|
26
|
+
"alignRight": "Выровнять по правому краю",
|
|
27
|
+
"alignJustify": "Выровнять по ширине"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"toolbar": {
|
|
3
|
+
"undo": "撤销",
|
|
4
|
+
"redo": "重做",
|
|
5
|
+
"font": "字体",
|
|
6
|
+
"fontSize": "字号",
|
|
7
|
+
"bold": "粗体",
|
|
8
|
+
"italic": "斜体",
|
|
9
|
+
"strikethrough": "删除线",
|
|
10
|
+
"subscript": "下标",
|
|
11
|
+
"superscript": "上标",
|
|
12
|
+
"underline": "下划线",
|
|
13
|
+
"textColor": {
|
|
14
|
+
"main": "文本颜色",
|
|
15
|
+
"right": "颜色选择"
|
|
16
|
+
},
|
|
17
|
+
"fillColor": {
|
|
18
|
+
"main": "文本背景色",
|
|
19
|
+
"right": "背景色选择"
|
|
20
|
+
},
|
|
21
|
+
"resetColor": "重置颜色",
|
|
22
|
+
"order": "有序列表",
|
|
23
|
+
"unorder": "无序列表",
|
|
24
|
+
"alignLeft": "左对齐",
|
|
25
|
+
"alignCenter": "居中对齐",
|
|
26
|
+
"alignRight": "右对齐",
|
|
27
|
+
"alignJustify": "两端对齐"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { IDocDrawingPosition, ITransformState, Nullable } from '@univerjs/core';
|
|
2
|
+
|
|
3
|
+
export declare function docDrawingPositionToTransform(position: IDocDrawingPosition): Nullable<ITransformState>;
|
|
4
|
+
export declare function transformToDocDrawingPosition(transform: ITransformState, marginLeft?: number, marginTop?: number): Nullable<IDocDrawingPosition>;
|
|
@@ -20,7 +20,7 @@ export declare class DocEditorBridgeController extends Disposable {
|
|
|
20
20
|
private _initialValueChange;
|
|
21
21
|
private _valueChange;
|
|
22
22
|
/**
|
|
23
|
-
* Listen to document edits to refresh the size of the
|
|
23
|
+
* Listen to document edits to refresh the size of the formula editor.
|
|
24
24
|
*/
|
|
25
25
|
private _commandExecutedListener;
|
|
26
26
|
}
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import { Disposable, ICommandService
|
|
1
|
+
import { Disposable, ICommandService } from '@univerjs/core';
|
|
2
2
|
import { DocSkeletonManagerService } from '@univerjs/docs';
|
|
3
3
|
import { IRenderManagerService } from '@univerjs/engine-render';
|
|
4
4
|
import { IEditorService } from '@univerjs/ui';
|
|
5
5
|
|
|
6
6
|
export declare class DocFloatingObjectController extends Disposable {
|
|
7
7
|
private readonly _docSkeletonManagerService;
|
|
8
|
-
private readonly _univerInstanceService;
|
|
9
8
|
private readonly _renderManagerService;
|
|
10
9
|
private readonly _commandService;
|
|
11
|
-
private readonly _floatingObjectManagerService;
|
|
12
10
|
private readonly _editorService;
|
|
13
11
|
private _liquid;
|
|
14
12
|
private _pageMarginCache;
|
|
15
|
-
constructor(_docSkeletonManagerService: DocSkeletonManagerService,
|
|
13
|
+
constructor(_docSkeletonManagerService: DocSkeletonManagerService, _renderManagerService: IRenderManagerService, _commandService: ICommandService, _editorService: IEditorService);
|
|
16
14
|
private _initialize;
|
|
17
15
|
private _updateOnPluginChange;
|
|
18
16
|
private _initialRenderRefresh;
|
|
19
17
|
private _commandExecutedListener;
|
|
20
|
-
private
|
|
18
|
+
private _refreshDrawing;
|
|
21
19
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Disposable, ICommandService } from '@univerjs/core';
|
|
2
|
+
import { DocSkeletonManagerService } from '@univerjs/docs';
|
|
3
|
+
import { IRenderManagerService } from '@univerjs/engine-render';
|
|
4
|
+
import { IEditorService } from '@univerjs/ui';
|
|
5
|
+
|
|
6
|
+
export declare class DocFloatingObjectController extends Disposable {
|
|
7
|
+
private readonly _docSkeletonManagerService;
|
|
8
|
+
private readonly _renderManagerService;
|
|
9
|
+
private readonly _commandService;
|
|
10
|
+
private readonly _editorService;
|
|
11
|
+
private _liquid;
|
|
12
|
+
private _pageMarginCache;
|
|
13
|
+
constructor(_docSkeletonManagerService: DocSkeletonManagerService, _renderManagerService: IRenderManagerService, _commandService: ICommandService, _editorService: IEditorService);
|
|
14
|
+
private _initialize;
|
|
15
|
+
private _updateOnPluginChange;
|
|
16
|
+
private _initialRenderRefresh;
|
|
17
|
+
private _commandExecutedListener;
|
|
18
|
+
private _refreshDrawing;
|
|
19
|
+
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
export * from './basics';
|
|
17
17
|
export * from './docs-ui-plugin';
|
|
18
|
-
export { enUS, zhCN, ruRU } from './locale';
|
|
19
18
|
export { DocCanvasView } from './views/doc-canvas-view';
|
|
20
19
|
export * from './services';
|
|
20
|
+
export { DocCanvasPopManagerService } from './services/doc-popup-manager.service';
|
|
21
|
+
export { docDrawingPositionToTransform, transformToDocDrawingPosition } from './basics/transform-position';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
|
|
2
|
+
import { IRenderManagerService, BaseObject, IBoundRectNoAngle, Scene } from '@univerjs/engine-render';
|
|
3
|
+
import { IPopup, ICanvasPopupService } from '@univerjs/ui';
|
|
4
|
+
import { IDisposable } from '@wendellhu/redi';
|
|
5
|
+
|
|
6
|
+
export declare function transformBound2OffsetBound(originBound: IBoundRectNoAngle, scene: Scene): IBoundRectNoAngle;
|
|
7
|
+
export declare function transformPosition2Offset(x: number, y: number, scene: Scene): {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
};
|
|
11
|
+
export interface IDocCanvasPopup extends Pick<IPopup, 'direction' | 'excludeOutside' | 'closeOnSelfTarget' | 'componentKey' | 'offset' | 'onClickOutside'> {
|
|
12
|
+
mask?: boolean;
|
|
13
|
+
extraProps?: Record<string, any>;
|
|
14
|
+
}
|
|
15
|
+
export declare class DocCanvasPopManagerService extends Disposable {
|
|
16
|
+
private readonly _globalPopupManagerService;
|
|
17
|
+
private readonly _renderManagerService;
|
|
18
|
+
private readonly _univerInstanceService;
|
|
19
|
+
private readonly _commandService;
|
|
20
|
+
constructor(_globalPopupManagerService: ICanvasPopupService, _renderManagerService: IRenderManagerService, _univerInstanceService: IUniverInstanceService, _commandService: ICommandService);
|
|
21
|
+
private _createObjectPositionObserver;
|
|
22
|
+
/**
|
|
23
|
+
* attach a popup to canvas object
|
|
24
|
+
* @param targetObject target canvas object
|
|
25
|
+
* @param popup popup item
|
|
26
|
+
* @returns disposable
|
|
27
|
+
*/
|
|
28
|
+
attachPopupToObject(targetObject: BaseObject, popup: IDocCanvasPopup): IDisposable;
|
|
29
|
+
}
|
package/lib/umd/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(S,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/ui"),require("@univerjs/docs"),require("@wendellhu/redi/react-bindings"),require("@univerjs/engine-render"),require("react"),require("rxjs"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/ui","@univerjs/docs","@wendellhu/redi/react-bindings","@univerjs/engine-render","react","rxjs","@univerjs/design"],a):(S=typeof globalThis<"u"?globalThis:S||self,a(S.UniverDocsUi={},S.UniverCore,S["@wendellhu/redi"],S.UniverUi,S.UniverDocs,S["@wendellhu/redi/react-bindings"],S.UniverEngineRender,S.React,S.rxjs,S.UniverDesign))})(this,function(S,a,v,l,d,
|
|
1
|
+
(function(S,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/ui"),require("@univerjs/docs"),require("@wendellhu/redi/react-bindings"),require("@univerjs/engine-render"),require("react"),require("rxjs"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/ui","@univerjs/docs","@wendellhu/redi/react-bindings","@univerjs/engine-render","react","rxjs","@univerjs/design"],a):(S=typeof globalThis<"u"?globalThis:S||self,a(S.UniverDocsUi={},S.UniverCore,S["@wendellhu/redi"],S.UniverUi,S.UniverDocs,S["@wendellhu/redi/react-bindings"],S.UniverEngineRender,S.React,S.rxjs,S.UniverDesign))})(this,function(S,a,v,l,d,$e,f,Ve,M,We){"use strict";var rn=Object.defineProperty;var on=(S,a,v)=>a in S?rn(S,a,{enumerable:!0,configurable:!0,writable:!0,value:v}):S[a]=v;var O=(S,a,v)=>(on(S,typeof a!="symbol"?a+"":a,v),v);var le;const ve={undo:!0,redo:!0,font:!0,fontSize:!0,bold:!0,italic:!0,strikethrough:!0,underline:!0,textColor:!0,fillColor:!0,horizontalAlignMode:!0,verticalAlignMode:!0,textWrapMode:!0,textRotateMode:!0},Ie={outerLeft:!1,outerRight:!1,header:!0,footer:!0,innerLeft:!1,innerRight:!1,frozenHeaderLT:!1,frozenHeaderRT:!1,frozenHeaderLM:!1,frozenContent:!1,infoBar:!0,toolbar:!0},Ce={layout:{docContainerConfig:Ie,toolbarConfig:ve}},Te="DocUI";function R(n){return n.getContextValue(a.FOCUSING_DOC)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function je(n){return n.getContextValue(a.FOCUSING_DOC)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}const He={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_UP,preconditions:R,staticParameters:{direction:a.Direction.UP}},ze={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_DOWN,preconditions:R,staticParameters:{direction:a.Direction.DOWN}},Ye={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_LEFT,preconditions:R,staticParameters:{direction:a.Direction.LEFT}},Ge={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_RIGHT,preconditions:R,staticParameters:{direction:a.Direction.RIGHT}},Ke={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_UP|l.MetaKeys.SHIFT,preconditions:R,staticParameters:{direction:a.Direction.UP}},Xe={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_DOWN|l.MetaKeys.SHIFT,preconditions:R,staticParameters:{direction:a.Direction.DOWN}},qe={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_LEFT|l.MetaKeys.SHIFT,preconditions:R,staticParameters:{direction:a.Direction.LEFT}},Ze={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_RIGHT|l.MetaKeys.SHIFT,preconditions:R,staticParameters:{direction:a.Direction.RIGHT}},Je={id:d.SelectAllOperation.id,binding:l.KeyCode.A|l.MetaKeys.CTRL_COMMAND,preconditions:n=>n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&(n.getContextValue(a.FOCUSING_DOC)||n.getContextValue(a.EDITOR_ACTIVATED))};var Qe=(n,e,t,i)=>{for(var o=e,r=n.length-1,s;r>=0;r--)(s=n[r])&&(o=s(o)||o);return o},Oe=(n,e)=>(t,i)=>e(t,i,n);let de=class{constructor(n,e,t){O(this,"_docContainer");O(this,"getComponent",n=>{if(this._docContainer=n,!n.getContentRef().current)throw new Error("container is not ready")});O(this,"changeLocale",n=>{this._localeService.setLocale(n)});this._config=n,this._localeService=e,this._injector=t}getUIConfig(){return{injector:this._injector,config:this._config,changeLocale:this.changeLocale,getComponent:this.getComponent}}getContentRef(){return this._docContainer.getContentRef()}UIDidMount(n){if(this._docContainer)return n(this._docContainer)}getDocContainer(){return this._docContainer}};de=Qe([Oe(1,v.Inject(a.LocaleService)),Oe(2,v.Inject(v.Injector))],de);var et=(n,e,t,i)=>{for(var o=e,r=n.length-1,s;r>=0;r--)(s=n[r])&&(o=s(o)||o);return o},Y=(n,e)=>(t,i)=>e(t,i,n);let k=class extends a.RxDisposable{constructor(e,t,i,o,r){super();O(this,"_docContainerController");O(this,"changeLocale",e=>{this._localeService.setLocale(e)});this._localeService=t,this._injector=i,this._textSelectionRenderManager=o,this._layoutService=r,this._docContainerController=this._injector.createInstance(de,e),this._registerContainer()}_registerContainer(){this._layoutService&&this.disposeWithMe(this._layoutService.registerContainerElement(this._textSelectionRenderManager.__getEditorContainer()))}getDocContainerController(){return this._docContainerController}};k=et([Y(1,v.Inject(a.LocaleService)),Y(2,v.Inject(v.Injector)),Y(3,f.ITextSelectionRenderManager),Y(4,v.Optional(l.ILayoutService))],k);const G="UI_PLUGIN_DOCS",ue=`${G}_COLOR_PICKER_COMPONENT`,Me=`${G}_FONT_FAMILY_COMPONENT`,ye=`${G}_FONT_FAMILY_ITEM_COMPONENT`,be=`${G}_FONT_SIZE_COMPONENT`;var Re={exports:{}},K={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var ot=Ve,st=Symbol.for("react.element"),at=Symbol.for("react.fragment"),ct=Object.prototype.hasOwnProperty,lt=ot.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,dt={key:!0,ref:!0,__self:!0,__source:!0};function De(r,e,t){var n,i={},o=null,s=null;t!==void 0&&(o=""+t),e.key!==void 0&&(o=""+e.key),e.ref!==void 0&&(s=e.ref);for(n in e)ct.call(e,n)&&!dt.hasOwnProperty(n)&&(i[n]=e[n]);if(r&&r.defaultProps)for(n in e=r.defaultProps,e)i[n]===void 0&&(i[n]=e[n]);return{$$typeof:st,type:r,key:o,ref:s,props:i,_owner:lt.current}}X.Fragment=at,X.jsx=De,X.jsxs=De,Ee.exports=X;var ut=Ee.exports;const ht={docsUiCanvasBackground:"univer-docs-ui-canvas-background"},gt=()=>ut.jsx("div",{className:ht.docsUiCanvasBackground});function pt(r){const e=r.get(a.ICommandService);return{id:d.SetInlineFormatBoldCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(i=>{var s;const o=i.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=U(r);if(c==null)return;const u=(s=c.ts)==null?void 0:s.bl;t.next(u===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.UNIVER_DOC)}}function _t(r){const e=r.get(a.ICommandService);return{id:d.SetInlineFormatItalicCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(i=>{var s;const o=i.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=U(r);if(c==null)return;const u=(s=c.ts)==null?void 0:s.it;t.next(u===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.UNIVER_DOC)}}function St(r){const e=r.get(a.ICommandService);return{id:d.SetInlineFormatUnderlineCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(i=>{var s;const o=i.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=U(r);if(c==null)return;const u=(s=c.ts)==null?void 0:s.ul;t.next((u==null?void 0:u.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.UNIVER_DOC)}}function ft(r){const e=r.get(a.ICommandService);return{id:d.SetInlineFormatStrikethroughCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(i=>{var s;const o=i.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=U(r);if(c==null)return;const u=(s=c.ts)==null?void 0:s.st;t.next((u==null?void 0:u.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.UNIVER_DOC)}}function mt(r){const e=r.get(a.ICommandService);return{id:d.SetInlineFormatSubscriptCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(i=>{var s;const o=i.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=U(r);if(c==null)return;const u=(s=c.ts)==null?void 0:s.va;t.next(u===a.BaselineOffset.SUBSCRIPT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.UNIVER_DOC)}}function vt(r){const e=r.get(a.ICommandService);return{id:d.SetInlineFormatSuperscriptCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(i=>{var s;const o=i.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=U(r);if(c==null)return;const u=(s=c.ts)==null?void 0:s.va;t.next(u===a.BaselineOffset.SUPERSCRIPT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.UNIVER_DOC)}}function Ct(r){const e=r.get(a.ICommandService);return{id:d.SetInlineFormatFontFamilyCommand.id,tooltip:"toolbar.font",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,label:Me,positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_FAMILY_LIST.map(t=>({label:{name:ye,hoverable:!0},value:t.value})),value$:new b.Observable(t=>{const n=l.FONT_FAMILY_LIST[0].value,i=e.onCommandExecuted(o=>{var c;const s=o.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontFamilyCommand.id){const u=U(r);if(u==null)return;const g=(c=u.ts)==null?void 0:c.ff;t.next(g!=null?g:n)}});return t.next(n),i.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.UNIVER_DOC)}}function It(r){const e=r.get(a.ICommandService);return{id:d.SetInlineFormatFontSizeCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Re,props:{min:1,max:400}},positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_SIZE_LIST,value$:new b.Observable(t=>{const i=e.onCommandExecuted(o=>{var c;const s=o.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontSizeCommand.id){const u=U(r);if(u==null)return;const g=(c=u.ts)==null?void 0:c.fs;t.next(g!=null?g:14)}});return t.next(14),i.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.UNIVER_DOC)}}function Ot(r){const e=r.get(a.ICommandService),t=r.get(a.ThemeService);return{id:d.SetInlineFormatTextColorCommand.id,icon:"FontColor",tooltip:"toolbar.textColor.main",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON_SELECTOR,positions:[l.MenuPosition.TOOLBAR_START],selections:[{label:{name:ge,hoverable:!1}}],value$:new b.Observable(n=>{const i=t.getCurrentTheme().textColor,o=e.onCommandExecuted(s=>{if(s.id===d.SetInlineFormatTextColorCommand.id){const c=s.params.value;n.next(c!=null?c:i)}});return n.next(i),o.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.UNIVER_DOC)}}function Tt(r){const e=r.get(a.ICommandService);return{id:d.AlignLeftCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"LeftJustifyingSingle",tooltip:"toolbar.alignLeft",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(i=>{var s;const o=i.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=q(r);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.LEFT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.UNIVER_DOC)}}function bt(r){const e=r.get(a.ICommandService);return{id:d.AlignCenterCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"HorizontallySingle",tooltip:"toolbar.alignCenter",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(i=>{var s;const o=i.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=q(r);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.CENTER)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.UNIVER_DOC)}}function Mt(r){const e=r.get(a.ICommandService);return{id:d.AlignRightCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"RightJustifyingSingle",tooltip:"toolbar.alignRight",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(i=>{var s;const o=i.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=q(r);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.RIGHT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.UNIVER_DOC)}}function yt(r){const e=r.get(a.ICommandService);return{id:d.AlignJustifyCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"AlignTextBothSingle",tooltip:"toolbar.alignJustify",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(i=>{var s;const o=i.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=q(r);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.JUSTIFIED)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.UNIVER_DOC)}}function Rt(r){return{id:d.OrderListCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"OrderSingle",tooltip:"toolbar.order",positions:[l.MenuPosition.TOOLBAR_START],hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.UNIVER_DOC)}}function Et(r){return{id:d.BulletListCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"UnorderSingle",tooltip:"toolbar.unorder",positions:[l.MenuPosition.TOOLBAR_START],hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.UNIVER_DOC)}}function Dt(r){return{id:d.ResetInlineFormatTextBackgroundColorCommand.id,type:l.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:d.SetInlineFormatTextBackgroundColorCommand.id}}function Ut(r){const e=r.get(a.ICommandService),t=r.get(a.ThemeService);return{id:d.SetInlineFormatTextBackgroundColorCommand.id,tooltip:"toolbar.fillColor.main",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON_SELECTOR,positions:[l.MenuPosition.TOOLBAR_START],icon:"PaintBucket",selections:[{label:{name:ge,hoverable:!1}}],value$:new b.Observable(n=>{const i=t.getCurrentTheme().primaryColor,o=e.onCommandExecuted(s=>{if(s.id===d.SetInlineFormatTextBackgroundColorCommand.id){const c=s.params.value;n.next(c!=null?c:i)}});return n.next(i),o.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.UNIVER_DOC)}}function U(r){var u;const e=r.get(a.IUniverInstanceService),t=r.get(d.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),i=t.getActiveRange();if(n==null||i==null)return;const o=(u=n.getBody())==null?void 0:u.textRuns;if(o==null)return;const{startOffset:s}=i;return o.find(({st:g,ed:p})=>s>=g&&s<p)}function q(r){var u;const e=r.get(a.IUniverInstanceService),t=r.get(d.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),i=t.getActiveRange();if(n==null||i==null)return;const o=(u=n.getBody())==null?void 0:u.paragraphs;if(o==null)return;const{startOffset:s}=i;let c=-1;for(const g of o){const{startIndex:p}=g;if(s>c&&s<=p)return g;c=p}return null}var Pt=Object.defineProperty,Nt=Object.getOwnPropertyDescriptor,xt=(r,e,t,n)=>{for(var i=n>1?void 0:n?Nt(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&Pt(e,t,i),i},x=(r,e)=>(t,n)=>e(t,n,r);let W=class extends a.Disposable{constructor(r,e,t,n,i,o,s,c){super(),this._config=r,this._injector=e,this._componentManager=t,this._layoutService=n,this._editorService=i,this._menuService=o,this._uiPartsService=s,this._univerInstanceService=c,this._init()}_initCustomComponents(){const r=this._componentManager;this.disposeWithMe(r.register(ge,We.ColorPicker)),this.disposeWithMe(r.register(Me,l.FontFamily)),this.disposeWithMe(r.register(ye,l.FontFamilyItem)),this.disposeWithMe(r.register(Re,l.FontSize))}_initMenus(){const{menu:r={}}=this._config;[pt,_t,St,ft,mt,vt,It,Ct,Ot,Tt,bt,Mt,yt,Rt,Et,Dt,Ut].forEach(e=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e),r))})}_init(){this._initCustomComponents(),this._initMenus(),this._initDocBackground(),this._initFocusHandler()}_initDocBackground(){const r=this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC)[0].getUnitId();if(r==null)return;this._editorService.isEditor(r)||this.disposeWithMe(this._uiPartsService.registerComponent(l.BuiltInUIPart.CONTENT,()=>je.connectInjector(gt,this._injector)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(a.UniverInstanceType.UNIVER_DOC,()=>{this._injector.get(m.ITextSelectionRenderManager).focus()}))}};W=xt([a.OnLifecycle(a.LifecycleStages.Rendered,W),x(1,v.Inject(v.Injector)),x(2,v.Inject(l.ComponentManager)),x(3,l.ILayoutService),x(4,l.IEditorService),x(5,l.IMenuService),x(6,l.IUIPartsService),x(7,a.IUniverInstanceService)],W);const Lt={toolbar:{undo:"Undo",redo:"Redo",font:"Font",fontSize:"Font size",bold:"Bold",italic:"Italic",strikethrough:"Strikethrough",subscript:"Subscript",superscript:"Superscript",underline:"Underline",textColor:{main:"Text color",right:"Choose color"},fillColor:{main:"Text Background color",right:"Choose color"},resetColor:"Reset",order:"Ordered list",unorder:"Unordered list",alignLeft:"Align Left",alignCenter:"Align Center",alignRight:"Align Right",alignJustify:"Justify"}},Ue={toolbar:{undo:"撤销",redo:"重做",font:"字体",fontSize:"字号",bold:"粗体",italic:"斜体",strikethrough:"删除线",subscript:"下标",superscript:"上标",underline:"下划线",textColor:{main:"文本颜色",right:"颜色选择"},fillColor:{main:"文本背景色",right:"背景色选择"},resetColor:"重置颜色",order:"有序列表",unorder:"无序列表",alignLeft:"左对齐",alignCenter:"居中对齐",alignRight:"右对齐",alignJustify:"两端对齐"}},At={toolbar:{undo:"Отменить",redo:"Повторить",font:"Шрифт",fontSize:"Размер шрифта",bold:"Полужирный",italic:"Курсив",strikethrough:"Зачеркнутый",subscript:"Нижний индекс",superscript:"Верхний индекс",underline:"Подчеркнутый",textColor:{main:"Цвет текста",right:"Выбрать цвет"},fillColor:{main:"Цвет фона текста",right:"Выбрать цвет"},resetColor:"Сбросить",order:"Упорядоченный список",unorder:"Неупорядоченный список",alignLeft:"Выровнять по левому краю",alignCenter:"Выровнять по центру",alignRight:"Выровнять по правому краю",alignJustify:"Выровнять по ширине"}},Bt={id:d.BreakLineCommand.id,preconditions:ke,binding:l.KeyCode.ENTER},Ft={id:d.DeleteLeftCommand.id,preconditions:E,binding:l.KeyCode.BACKSPACE},$t={id:d.DeleteRightCommand.id,preconditions:E,binding:l.KeyCode.DELETE},wt=10,jt=6;function Vt(){return a.Tools.generateRandomId(jt)}function Wt(r){const e=r.match(/data-copy-id="([^\s]+)"/);return e&&e[1]?e[1]:null}class kt{constructor(){T(this,"_cache",new a.LRUMap(wt))}set(e,t){this._cache.set(e,t)}get(e){return this._cache.get(e)}clear(){this._cache.clear()}}const Pe=new kt;function pe(r){const e=r.style,t={},n=r.tagName.toLowerCase();switch(n){case"b":case"em":case"strong":{t.bl=a.BooleanNumber.TRUE;break}case"s":{t.st={s:a.BooleanNumber.TRUE};break}case"u":{t.ul={s:a.BooleanNumber.TRUE};break}case"i":{t.it=a.BooleanNumber.TRUE;break}case"sub":case"sup":{t.va=n==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}for(let i=0;i<e.length;i++){const o=e[i],s=e.getPropertyValue(o);switch(o){case"font-family":{t.ff=s;break}case"font-size":{const c=Number.parseInt(s);Number.isNaN(c)||(s.endsWith("pt")?t.fs=c:s.endsWith("px")&&(t.fs=m.pixelToPt(c)));break}case"font-style":{s==="italic"&&(t.it=a.BooleanNumber.TRUE);break}case"font-weight":{Number(s)>400&&(t.bl=a.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(s)?t.ul={s:a.BooleanNumber.TRUE}:/overline/.test(s)?t.ol={s:a.BooleanNumber.TRUE}:/line-through/.test(s)&&(t.st={s:a.BooleanNumber.TRUE});break}case"color":{const c=new a.ColorKit(s);c.isValid&&(t.cl={rgb:c.toRgbString()});break}case"background-color":{const c=new a.ColorKit(s);c.isValid&&(t.bg={rgb:c.toRgbString()});break}}}return t}function Ht(r){const e=new DOMParser,t=`<x-univer id="univer-root">${r}</x-univer>`;return e.parseFromString(t,"text/html").querySelector("#univer-root")}function Ne(r,e){const t=r.tagName.toLowerCase();return typeof e=="string"?t===e:Array.isArray(e)?e.some(n=>n===t):e(r)}const ae=class ae{constructor(){T(this,"_styleCache",new Map);T(this,"_styleRules",[]);T(this,"_afterProcessRules",[])}static use(e){if(this._pluginList.includes(e))throw new Error(`Univer paste plugin ${e.name} already added`);this._pluginList.push(e)}convert(e){const t=ae._pluginList.find(o=>o.checkPasteType(e)),n=Ht(e),i={dataStream:"",textRuns:[]};return t&&(this._styleRules=[...t.stylesRules],this._afterProcessRules=[...t.afterProcessRules]),this._styleCache.clear(),this._process(null,n==null?void 0:n.childNodes,i),this._styleCache.clear(),this._styleRules=[],this._afterProcessRules=[],i}_process(e,t,n){var i;for(const o of t)if(o.nodeType===Node.TEXT_NODE){const s=(i=o.nodeValue)==null?void 0:i.replace(/[\r\n]/g,"");let c;e&&this._styleCache.has(e)&&(c=this._styleCache.get(e)),n.dataStream+=s,c&&Object.getOwnPropertyNames(c).length&&n.textRuns.push({st:n.dataStream.length-s.length,ed:n.dataStream.length,ts:c})}else if(o.nodeType===Node.ELEMENT_NODE){const s=e?this._styleCache.get(e):{},c=this._styleRules.find(({filter:_})=>Ne(o,_)),u=c?c.getStyle(o):pe(o);this._styleCache.set(o,{...s,...u});const{childNodes:g}=o;this._process(o,g,n);const p=this._afterProcessRules.find(({filter:_})=>Ne(o,_));p&&p.handler(n,o)}}};T(ae,"_pluginList",[]);let A=ae;const xe={name:"univer-doc-paste-plugin-lark",checkPasteType(r){return/lark-record-clipboard/i.test(r)},stylesRules:[{filter:["s"],getStyle(r){const e=pe(r);return{st:{s:a.BooleanNumber.TRUE},...e}}}],afterProcessRules:[{filter(r){return r.tagName==="DIV"&&/ace-line/i.test(r.className)},handler(r){r.paragraphs==null&&(r.paragraphs=[]),r.paragraphs.push({startIndex:r.dataStream.length}),r.dataStream+="\r"}}]};function Le(r){const e=r.style,t={};for(let n=0;n<e.length;n++){const i=e[n],o=e.getPropertyValue(i);switch(i){case"margin-top":{const s=Number.parseInt(o);t.spaceAbove=/pt/.test(o)?m.ptToPixel(s):s;break}case"margin-bottom":{const s=Number.parseInt(o);t.spaceBelow=/pt/.test(o)?m.ptToPixel(s):s;break}case"line-height":{const s=Number.parseFloat(o);t.lineSpacing=s;break}}}return Object.getOwnPropertyNames(t).length?t:null}const Ae={name:"univer-doc-paste-plugin-word",checkPasteType(r){return/word|mso/i.test(r)},stylesRules:[{filter:["b"],getStyle(r){const e=pe(r);return{bl:a.BooleanNumber.TRUE,...e}}}],afterProcessRules:[{filter(r){return r.tagName==="P"&&/mso/i.test(r.className)},handler(r,e){r.paragraphs==null&&(r.paragraphs=[]);const t={startIndex:r.dataStream.length},n=Le(e);n&&(t.paragraphStyle=n),r.paragraphs.push(t),r.dataStream+="\r"}}]},Be={name:"univer-doc-paste-plugin-univer",checkPasteType(r){return/UniverNormal/i.test(r)},stylesRules:[],afterProcessRules:[{filter(r){return r.tagName==="P"&&/UniverNormal/i.test(r.className)},handler(r,e){r.paragraphs==null&&(r.paragraphs=[]);const t={startIndex:r.dataStream.length},n=Le(e);n&&(t.paragraphStyle=n),r.paragraphs.push(t),r.dataStream+="\r"}}]};function Fe(r,e){const{st:t,ed:n,ts:i={}}=e,{ff:o,fs:s,it:c,bl:u,ul:g,st:p,ol:_,bg:C,cl:f,va:I}=i;let h=r.slice(t,n);const O=[];return c===a.BooleanNumber.TRUE&&(h=`<i>${h}</i>`),I===a.BaselineOffset.SUPERSCRIPT?h=`<sup>${h}</sup>`:I===a.BaselineOffset.SUBSCRIPT&&(h=`<sub>${h}</sub>`),(g==null?void 0:g.s)===a.BooleanNumber.TRUE&&(h=`<u>${h}</u>`),(p==null?void 0:p.s)===a.BooleanNumber.TRUE&&(h=`<s>${h}</s>`),u===a.BooleanNumber.TRUE&&(h=`<strong>${h}</strong>`),o&&O.push(`font-family: ${o}`),f&&O.push(`color: ${f.rgb}`),s&&O.push(`font-size: ${s}pt`),_&&O.push("text-decoration: overline"),C&&O.push(`background: ${C.rgb}`),O.length?`<span style="${O.join("; ")};">${h}</span>`:h}function _e(r,e,t){const{dataStream:n,textRuns:i=[]}=r;let o=e;const s=[];for(const c of i){const{st:u,ed:g}=c;a.Tools.hasIntersectionBetweenTwoRanges(e,t,u,g)&&(u>o?(s.push(n.slice(o,u)),s.push(Fe(n,{...c,ed:Math.min(g,t)}))):s.push(Fe(n,{...c,st:o,ed:Math.min(g,t)}))),o=Math.max(e,Math.min(g,t))}return o!==t&&s.push(n.slice(o,t)),s.join("")}function $e(r,e=!0){var t;if(e&&((t=r.paragraphs)!=null&&t.length)){const{dataStream:n,paragraphs:i=[]}=r;let o="",s=-1;for(const c of i){const{startIndex:u,paragraphStyle:g={}}=c,{spaceAbove:p,spaceBelow:_,lineSpacing:C}=g,f=[];p!=null&&(typeof p=="number"?f.push(`margin-top: ${p}px`):f.push(`margin-top: ${p.v}px`)),_!=null&&(typeof _=="number"?f.push(`margin-bottom: ${_}px`):f.push(`margin-bottom: ${_.v}px`)),C!=null&&f.push(`line-height: ${C}`),u>s+1?o+=`<p class="UniverNormal" ${f.length?`style="${f.join("; ")};"`:""}>${_e(r,s+1,u)}</p>`:o+=`<p class="UniverNormal" ${f.length?`style="${f.join("; ")};"`:""}></p>`,s=u}return s!==n.length&&(o+=_e(r,s,n.length)),o}else return _e(r,0,r.dataStream.length)}class zt{convert(e){if(e.length===0)throw new Error("The bodyList length at least to be 1");if(e.length===1)return $e(e[0]);let t="";for(const n of e)t+='<p className="UniverNormal">',t+=$e(n,!1),t+="</p>";return t}}var Yt=Object.defineProperty,Gt=Object.getOwnPropertyDescriptor,Kt=(r,e,t,n)=>{for(var i=n>1?void 0:n?Gt(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&Yt(e,t,i),i},k=(r,e)=>(t,n)=>e(t,n,r);A.use(Ae),A.use(xe),A.use(Be);function Xt(r){const e=r.replace(/\n/g,"\r"),t=[];for(let n=0;n<e.length;n++)e[n]==="\r"&&t.push({startIndex:n});return{dataStream:e,paragraphs:t}}const H=v.createIdentifier("doc.clipboard-service");let Se=class extends a.Disposable{constructor(e,t,n,i,o){super();T(this,"_clipboardHooks",[]);T(this,"_htmlToUDM",new A);T(this,"_umdToHtml",new zt);this._univerInstanceService=e,this._logService=t,this._commandService=n,this._clipboardInterfaceService=i,this._textSelectionManagerService=o}async copy(){const e=this._getDocumentBodyInRanges();if(e.length===0)return!1;try{this._setClipboardData(e)}catch(t){return this._logService.error("[DocClipboardService] copy failed",t),!1}return!0}async cut(){return this._cut()}async paste(e){const t=await this._generateBodyFromClipboardItems(e);return this._paste(t)}async legacyPaste(e,t){const n=this._generateBodyFromHtmlAndText(e,t);return this._paste(n)}async _cut(){var o;const{segmentId:e,endOffset:t,style:n}=(o=this._textSelectionManagerService.getActiveRange())!=null?o:{},i=this._textSelectionManagerService.getSelections();if(e==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),t==null||i==null)return!1;this.copy();try{let s=t;for(const u of i){const{startOffset:g,endOffset:p}=u;g==null||p==null||p<=t&&(s-=p-g)}const c=[{startOffset:s,endOffset:s,style:n}];return this._commandService.executeCommand(d.CutContentCommand.id,{segmentId:e,textRanges:c})}catch{return this._logService.error("[DocClipboardController] cut content failed"),!1}}async _paste(e){var s;const{segmentId:t,endOffset:n,style:i}=(s=this._textSelectionManagerService.getActiveRange())!=null?s:{},o=this._textSelectionManagerService.getSelections();if(t==null&&this._logService.error("[DocClipboardController] segmentId does not exist!"),n==null||o==null)return!1;try{let c=n;for(const g of o){const{startOffset:p,endOffset:_}=g;p==null||_==null||_<=n&&(c+=e.dataStream.length-(_-p))}const u=[{startOffset:c,endOffset:c,style:i}];return this._commandService.executeCommand(d.InnerPasteCommand.id,{body:e,segmentId:t,textRanges:u})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(e){const t=Vt(),n=e.length>1?e.map(o=>o.dataStream).join(`
|
|
10
|
-
`):e[0].dataStream;let i=this._umdToHtml.convert(e);return e.length===1&&(i=i.replace(/(<[a-z]+)/,(o,s)=>`${s} data-copy-id="${t}"`),Pe.set(t,e[0])),this._clipboardInterfaceService.write(n,i)}addClipboardHook(e){return this._clipboardHooks.push(e),a.toDisposable(()=>{const t=this._clipboardHooks.indexOf(e);t>-1&&this._clipboardHooks.splice(t,1)})}_getDocumentBodyInRanges(){const e=this._textSelectionManagerService.getSelections(),t=this._univerInstanceService.getCurrentUniverDocInstance(),n=[];if(e==null||!t)return n;for(const i of e){const{startOffset:o,endOffset:s,collapsed:c}=i;if(c||o==null||s==null)continue;const u=t.sliceBody(o,s);u!=null&&n.push(u)}return n}async _generateBodyFromClipboardItems(e){try{let t="",n="";for(const i of e)for(const o of i.types)o===l.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await i.getType(o).then(s=>s&&s.text()):o===l.HTML_CLIPBOARD_MIME_TYPE&&(t=await i.getType(o).then(s=>s&&s.text()));return this._generateBodyFromHtmlAndText(t,n)}catch(t){return Promise.reject(t)}}_generateBodyFromHtmlAndText(e,t){if(!e){if(t)return Xt(t);throw new Error("[DocClipboardService] html and text cannot be both empty!")}const n=Wt(e);if(n){const i=Pe.get(n);if(i)return i}return this._htmlToUDM.convert(e)}};Se=Kt([k(0,a.IUniverInstanceService),k(1,a.ILogService),k(2,a.ICommandService),k(3,l.IClipboardInterfaceService),k(4,v.Inject(d.TextSelectionManagerService))],Se);function Z(r){return r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.EDITOR_ACTIVATED)}const fe=999,qt={id:l.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:fe,preconditions:Z,handler:async r=>r.get(H).copy()},Zt={id:l.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:fe,preconditions:Z,handler:async r=>r.get(H).cut()},Jt={id:l.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:fe,preconditions:Z,handler:async r=>{const e=r.get(H),n=await r.get(l.IClipboardInterfaceService).read();return n.length===0?!1:e.paste(n)}};var Qt=Object.defineProperty,en=Object.getOwnPropertyDescriptor,tn=(r,e,t,n)=>{for(var i=n>1?void 0:n?en(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&Qt(e,t,i),i},z=(r,e)=>(t,n)=>e(t,n,r);let J=class extends a.RxDisposable{constructor(r,e,t,n,i){super(),this._commandService=r,this._clipboardInterfaceService=e,this._docClipboardService=t,this._textSelectionRenderManager=n,this._contextService=i,this._init()}_init(){[qt,Zt,Jt].forEach(r=>this.disposeWithMe(this._commandService.registerMultipleCommand(r))),[d.InnerPasteCommand,d.CutContentCommand].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r))),this._initLegacyPasteCommand()}_initLegacyPasteCommand(){var r;(r=this._textSelectionRenderManager)==null||r.onPaste$.pipe(b.takeUntil(this.dispose$)).subscribe(e=>{var o,s;if(!Z(this._contextService))return;e.event.preventDefault();const t=e.event,n=(o=t.clipboardData)==null?void 0:o.getData("text/html"),i=(s=t.clipboardData)==null?void 0:s.getData("text/plain");this._docClipboardService.legacyPaste(n,i)})}};J=tn([a.OnLifecycle(a.LifecycleStages.Rendered,J),z(0,a.ICommandService),z(1,l.IClipboardInterfaceService),z(2,H),z(3,m.ITextSelectionRenderManager),z(4,a.IContextService)],J);var nn=Object.defineProperty,rn=Object.getOwnPropertyDescriptor,on=(r,e,t,n)=>{for(var i=n>1?void 0:n?rn(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&nn(e,t,i),i},B=(r,e)=>(t,n)=>e(t,n,r);let Q=class extends a.Disposable{constructor(e,t,n,i,o,s){super();T(this,"_initialEditors",new Set);this._univerInstanceService=e,this._docSkeletonManagerService=t,this._editorService=n,this._commandService=i,this._textSelectionRenderManager=o,this._renderManagerService=s,this._initialize()}_initialize(){this.disposeWithMe(this._editorService.resize$.subscribe(e=>{this._resize(e)})),this._editorService.getAllEditor().forEach(e=>{const t=e.editorUnitId;this._initialEditors.has(t)||(this._initialEditors.add(t),this._resize(t))}),this._commandExecutedListener(),this._initialSetValue(),this._initialBlur(),this._initialFocus(),this._initialValueChange()}_resize(e){var D,P,N;if(e==null)return;const t=this._editorService.getEditor(e);if((t==null?void 0:t.cancelDefaultResizeListener)===!0)return;const n=(D=this._docSkeletonManagerService.getSkeletonByUnitId(e))==null?void 0:D.skeleton,i=this._univerInstanceService.getUniverDocInstance(e);if(t==null||t.render==null||n==null||i==null)return;n.calculate();const{marginTop:o=0,marginBottom:s=0,marginLeft:c=0,marginRight:u=0}=i.getSnapshot().documentStyle,{scene:g,mainComponent:p}=t.render;let{actualHeight:_,actualWidth:C}=n.getActualSize();_+=o+s,C+=c+u;const{width:f,height:I}=t.getBoundingClientRect(),h=g.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);let O=h==null?void 0:h.getScrollBar();const M=Math.max(C,f),y=Math.max(_,I);g.transformByState({width:M,height:y}),p==null||p.resize(M,y),t.isSingle()?C>f?O==null?h&&new m.ScrollBar(h,{barSize:8,enableVertical:!1}):h==null||h.resetSizeAndScrollBar():(O=null,h==null||h.scrollTo({x:0,y:0}),(N=h==null?void 0:h.getScrollBar())==null||N.dispose()):_>I?O==null?h&&new m.ScrollBar(h,{enableHorizontal:!1,barSize:8}):h==null||h.resetSizeAndScrollBar():(O=null,h==null||h.scrollTo({x:0,y:0}),(P=h==null?void 0:h.getScrollBar())==null||P.dispose())}_initialSetValue(){this.disposeWithMe(this._editorService.setValue$.subscribe(e=>{this._commandService.executeCommand(d.CoverContentCommand.id,{unitId:e.editorUnitId,body:e.body,segmentId:null})}))}_initialBlur(){this.disposeWithMe(this._editorService.blur$.subscribe(()=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.blur()})),this.disposeWithMe(this._textSelectionRenderManager.onBlur$.subscribe(()=>{var i;const e=(i=this._univerInstanceService.getCurrentUniverDocInstance())==null?void 0:i.getUnitId();if(e==null)return;const t=this._editorService.getEditor(e),n=this._editorService.getFocusEditor();t==null||t.isSheetEditor()||n&&n.editorUnitId===e||this._editorService.blur()}))}_initialFocus(){this.disposeWithMe(this._editorService.focus$.subscribe(n=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges([n])}));const e=["univer-formula-search","univer-formula-help","formula-help-decorator","univer-formula-help-param"];this.disposeWithMe(b.fromEvent(window,"mousedown").subscribe(n=>{const o=n.target.classList[0]||"";if(a.checkForSubstrings(o,e)){this._editorService.changeSpreadsheetFocusState(!0),n.stopPropagation();return}this._editorService.changeSpreadsheetFocusState(!1)})),this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(n=>{const i=n.getUnitId(),o=this._renderManagerService.getRenderById(i),s=o==null?void 0:o.engine.getCanvas().getCanvasEle();s!=null&&b.fromEvent(s,"mousedown").subscribe(c=>{this._editorService.changeSpreadsheetFocusState(!0),c.stopPropagation()})})}_initialValueChange(){this.disposeWithMe(this._textSelectionRenderManager.onCompositionupdate$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onInput$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onKeydown$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onPaste$.subscribe(this._valueChange.bind(this)))}_valueChange(){var n;const e=(n=this._univerInstanceService.getCurrentUniverDocInstance())==null?void 0:n.getUnitId();if(e==null)return;const t=this._editorService.getEditor(e);t==null||t.isSheetEditor()||this._editorService.refreshValueChange(e)}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id,l.SetEditorResizeOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=t.params,{unitId:i}=n;if(this._editorService.isSheetEditor(i))return;this._resize(i),this._valueChange()}}))}};Q=on([a.OnLifecycle(a.LifecycleStages.Rendered,Q),B(0,a.IUniverInstanceService),B(1,v.Inject(d.DocSkeletonManagerService)),B(2,l.IEditorService),B(3,a.ICommandService),B(4,m.ITextSelectionRenderManager),B(5,m.IRenderManagerService)],Q);var sn=Object.defineProperty,an=Object.getOwnPropertyDescriptor,cn=(r,e,t,n)=>{for(var i=n>1?void 0:n?an(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&sn(e,t,i),i},ee=(r,e)=>(t,n)=>e(t,n,r);let te=class extends a.RxDisposable{constructor(e,t,n,i){super();T(this,"_docRenderMap",new Set);this._docSkeletonManagerService=e,this._renderManagerService=t,this._commandService=n,this._editorService=i,this._initialRenderRefresh(),this._commandExecutedListener()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(b.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)})}_create(e){if(e==null)return;const{skeleton:t,unitId:n}=e;let i=this._renderManagerService.getRenderById(n);i==null&&(this._renderManagerService.create(n),i=this._renderManagerService.getRenderById(n));const{mainComponent:o,components:s}=i,c=o,u=s.get(d.DOCS_VIEW_KEY.BACKGROUND);c.changeSkeleton(t),u.changeSkeleton(t),this._recalculateSizeBySkeleton(i,t)}_recalculateSizeBySkeleton(e,t){var C;const{mainComponent:n,scene:i,unitId:o,components:s}=e,c=n,u=s.get(d.DOCS_VIEW_KEY.BACKGROUND),g=(C=t.getSkeletonData())==null?void 0:C.pages;if(g==null)return;let p=0,_=0;for(let f=0,I=g.length;f<I;f++){const h=g[f],{pageWidth:O,pageHeight:M}=h;c.pageLayoutType===m.PageLayoutType.VERTICAL?(_+=M,_+=c.pageMarginTop,f===I-1&&(_+=c.pageMarginTop),p=Math.max(p,O)):c.pageLayoutType===m.PageLayoutType.HORIZONTAL&&(p+=O,f!==I-1&&(p+=c.pageMarginLeft),_=Math.max(_,M))}c.resize(p,_),u.resize(p,_),this._editorService.isEditor(o)||i.resize(p,_)}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const i=t.params,{unitId:o}=i,s=this._docSkeletonManagerService.getSkeletonByUnitId(o);if(s==null)return;const{skeleton:c}=s,u=this._renderManagerService.getRenderById(o);if(u==null||!!c.getViewModel().getDataModel().getSnapshot().disabled)return;if(c.calculate(),this._editorService.isEditor(o)){(n=u.mainComponent)==null||n.makeDirty();return}this._recalculateSizeBySkeleton(u,c)}}))}};te=cn([a.OnLifecycle(a.LifecycleStages.Rendered,te),ee(0,v.Inject(d.DocSkeletonManagerService)),ee(1,m.IRenderManagerService),ee(2,a.ICommandService),ee(3,l.IEditorService)],te);var ln=Object.defineProperty,dn=Object.getOwnPropertyDescriptor,un=(r,e,t,n)=>{for(var i=n>1?void 0:n?dn(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&ln(e,t,i),i},ne=(r,e)=>(t,n)=>e(t,n,r);S.DocCanvasView=class extends a.RxDisposable{constructor(t,n,i,o){super();T(this,"_scene");T(this,"_currentDocumentModel");T(this,"_fps$",new b.BehaviorSubject(""));T(this,"fps$",this._fps$.asObservable());this._renderManagerService=t,this._configService=n,this._univerInstanceService=i,this._editorService=o,this._initialize()}_initialize(){this._renderManagerService.createRender$.pipe(b.takeUntil(this.dispose$)).subscribe(t=>{this._create(t)}),this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC).pipe(b.takeUntil(this.dispose$)).subscribe(t=>{this._create(t==null?void 0:t.getUnitId())}),this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC).forEach(t=>{this._create(t.getUnitId())})}dispose(){this._fps$.complete()}_create(t){if(t==null)return;const n=this._univerInstanceService.getUniverDocInstance(t);n!=null&&(this._currentDocumentModel=n,this._renderManagerService.has(t)||this._addNewRender())}_addNewRender(){const n=this._currentDocumentModel.getUnitId();this._renderManagerService.createRender(n);const i=this._renderManagerService.getRenderById(n);if(i==null)return;const{scene:o,engine:s}=i;o.openTransformer(),this._scene=o;const c=new m.Viewport(d.VIEWPORT_KEY.VIEW_MAIN,o,{left:0,top:0,bottom:0,right:0,isWheelPreventDefaultX:!0});o.attachControl(),o.on(m.EVENT_TYPE.wheel,(p,_)=>{const C=p;if(C.ctrlKey){const f=Math.abs(C.deltaX);let I=f<40?.2:f<80?.4:.2;I*=C.deltaY>0?-1:1,o.scaleX<1&&(I/=2),o.scaleX+I>4?o.scale(4,4):o.scaleX+I<.1?o.scale(.1,.1):C.preventDefault()}else c.onMouseWheel(C,_)}),this._configService.getConfig("hasScroll")!==!1&&new m.ScrollBar(c),o.addLayer(new m.Layer(o,[],d.DOCS_COMPONENT_MAIN_LAYER_INDEX),new m.Layer(o,[],d.DOCS_COMPONENT_HEADER_LAYER_INDEX)),this._addComponent(i),this._currentDocumentModel.getShouldRenderLoopImmediately()&&s.runRenderLoop(()=>{o.render(),this._fps$.next(Math.round(s.getFps()).toString())}),this._renderManagerService.setCurrent(n)}_addComponent(t){const n=this._scene,i=this._currentDocumentModel,o={pageMarginLeft:i.documentStyle.marginLeft||0,pageMarginTop:i.documentStyle.marginTop||0},s=new m.Documents(d.DOCS_VIEW_KEY.MAIN,void 0,o),c=new m.DocBackground(d.DOCS_VIEW_KEY.BACKGROUND,void 0,o);s.zIndex=d.DOCS_COMPONENT_DEFAULT_Z_INDEX,c.zIndex=d.DOCS_COMPONENT_DEFAULT_Z_INDEX,t.mainComponent=s,t.components.set(d.DOCS_VIEW_KEY.MAIN,s),t.components.set(d.DOCS_VIEW_KEY.BACKGROUND,c),n.addObjects([s],d.DOCS_COMPONENT_MAIN_LAYER_INDEX),n.addObjects([c],d.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX),this._editorService.getEditor(i.getUnitId())==null&&n.enableLayerCache(d.DOCS_COMPONENT_MAIN_LAYER_INDEX)}},S.DocCanvasView=un([a.OnLifecycle(a.LifecycleStages.Starting,S.DocCanvasView),ne(0,m.IRenderManagerService),ne(1,a.IConfigService),ne(2,a.IUniverInstanceService),ne(3,l.IEditorService)],S.DocCanvasView);var hn=Object.defineProperty,gn=Object.getOwnPropertyDescriptor,pn=(r,e,t,n)=>{for(var i=n>1?void 0:n?gn(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&hn(e,t,i),i},F=(r,e)=>(t,n)=>e(t,n,r);let ie=class extends a.Disposable{constructor(e,t,n,i,o,s){super();T(this,"_liquid",new m.Liquid);T(this,"_pageMarginCache",new Map);this._docSkeletonManagerService=e,this._univerInstanceService=t,this._renderManagerService=n,this._commandService=i,this._floatingObjectManagerService=o,this._editorService=s,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh(),this._updateOnPluginChange()}_updateOnPluginChange(){this._floatingObjectManagerService.pluginUpdate$.subscribe(e=>{const t=this._docSkeletonManagerService.getCurrent();if(t==null)return;const{unitId:n,skeleton:i}=t,o=this._renderManagerService.getRenderById(n);if(o==null)return;const{mainComponent:s,components:c,scene:u}=o,g=s,{left:p,top:_}=g;e.forEach(C=>{const{unitId:f,subUnitId:I,floatingObjectId:h,floatingObject:O}=C,{left:M=0,top:y=0,width:D=0,height:P=0,angle:N,flipX:w,flipY:j,skewX:le,skewY:de}=O,R=this._pageMarginCache.get(h),ue=(R==null?void 0:R.marginLeft)||0,ve=(R==null?void 0:R.marginTop)||0;i==null||i.getViewModel().getDataModel().updateDrawing(h,{left:M-p-ue,top:y-_-ve,height:P,width:D})}),i==null||i.calculate(),s==null||s.makeDirty()})}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{skeleton:t,unitId:n}=e,i=this._renderManagerService.getRenderById(n);if(i==null)return;const{mainComponent:o}=i;o.changeSkeleton(t),this._refreshFloatingObject(n,t,i)})}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id,d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const i=t.params,{unitId:o}=i,s=this._docSkeletonManagerService.getCurrent();if(s==null)return;const{unitId:c,skeleton:u}=s;if(o!==c)return;const g=this._renderManagerService.getRenderById(c);if(g==null)return;if(this._editorService.isEditor(c)){(n=g.mainComponent)==null||n.makeDirty();return}this._refreshFloatingObject(c,u,g)}}))}_refreshFloatingObject(e,t,n){const i=t==null?void 0:t.getSkeletonData(),{mainComponent:o,scene:s}=n,c=o;if(!i)return;const{left:u,top:g,pageLayoutType:p,pageMarginLeft:_,pageMarginTop:C}=c,{pages:f}=i,I=[];s.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let h=0,O=f.length;h<O;h++){const M=f[h],{skeDrawings:y,marginLeft:D,marginTop:P}=M;this._liquid.translatePagePadding(M),y.forEach(N=>{const{aLeft:w,aTop:j,height:le,width:de,objectId:R,drawingOrigin:ue}=N,ve=ue.layoutType===a.PositionedObjectLayoutType.WRAP_NONE&&ue.behindDoc===a.BooleanNumber.TRUE;I.push({unitId:e,subUnitId:a.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:R,behindText:ve,floatingObject:{left:w+u+this._liquid.x,top:j+g+this._liquid.y,width:de,height:le}}),this._pageMarginCache.set(R,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.restorePagePadding(M),this._liquid.translatePage(M,p,_,C)}this._floatingObjectManagerService.batchAddOrUpdate(I)}};ie=pn([a.OnLifecycle(a.LifecycleStages.Steady,ie),F(0,v.Inject(d.DocSkeletonManagerService)),F(1,a.IUniverInstanceService),F(2,m.IRenderManagerService),F(3,a.ICommandService),F(4,a.IFloatingObjectManagerService),F(5,l.IEditorService)],ie);var _n=Object.defineProperty,Sn=Object.getOwnPropertyDescriptor,fn=(r,e,t,n)=>{for(var i=n>1?void 0:n?Sn(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&_n(e,t,i),i},$=(r,e)=>(t,n)=>e(t,n,r);let re=class extends a.Disposable{constructor(e,t,n,i,o,s){super();T(this,"_initializedRender",new Set);this._docSkeletonManagerService=e,this._univerInstanceService=t,this._commandService=n,this._renderManagerService=i,this._textSelectionManagerService=o,this._editorService=s,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._initialRenderRefresh()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t}=e,n=this._renderManagerService.getRenderById(t);if(n==null||this._initializedRender.has(t)||this._editorService.isEditor(t))return;this._initializedRender.add(t);const{scene:i}=n;this.disposeWithMe(a.toDisposable(i.onMouseWheelObserver.add(o=>{if(!o.ctrlKey)return;const s=this._univerInstanceService.getCurrentUniverDocInstance();if(!s)return;const c=Math.abs(o.deltaX);let u=c<40?.2:c<80?.4:.2;u*=o.deltaY>0?-1:1,i.scaleX<1&&(u/=2);const g=s.zoomRatio;let p=+Number.parseFloat(`${g+u}`).toFixed(1);p=p>=4?4:p<=.1?.1:p,this._commandService.executeCommand(d.SetDocZoomRatioCommand.id,{zoomRatio:p,unitId:s.getUnitId()}),o.preventDefault()})))})}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const t=this._univerInstanceService.getCurrentUniverDocInstance();if(!t)return;const n=t.zoomRatio||1;this._updateViewZoom(n,!1)})))}_commandExecutedListener(){const e=[d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=this._univerInstanceService.getCurrentUniverDocInstance();if(!n)return;const i=t.params,{unitId:o}=i;if(o!==n.getUnitId())return;const s=n.zoomRatio||1;this._updateViewZoom(s)}}))}_updateViewZoom(e,t=!0){var i;const n=this._getDocObject();n!=null&&(n.scene.scale(e,e),this._calculatePagePosition(n,e),t&&this._textSelectionManagerService.refreshSelection(),(i=n.scene.getTransformer())==null||i.hideControl())}_calculatePagePosition(e,t){const{document:n,scene:i,docBackground:o}=e,s=i==null?void 0:i.getParent(),{width:c,height:u,pageMarginLeft:g,pageMarginTop:p}=n;if(s==null||c===Number.POSITIVE_INFINITY||u===Number.POSITIVE_INFINITY)return;const{width:_,height:C}=s;let f=0,I=0,h=0,O=0,M=Number.POSITIVE_INFINITY;_>(c+g*2)*t?(f=_/2-c*t/2,f/=t,h=(_-g*2)/t,M=0):(f=g,h=c+g*2,M=(h-_/t)/2),C>u?(I=C/2-u/2,O=(C-p*2)/t):(I=p,O=u+p*2),i.resize(h,O+200),n.translate(f,I),o.translate(f,I);const y=i.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);if(M!==Number.POSITIVE_INFINITY&&y!=null){const D=y.getBarScroll(M,0).x;y.scrollTo({x:D})}return this}_getDocObject(){return d.getDocObject(this._univerInstanceService,this._renderManagerService)}};re=fn([a.OnLifecycle(a.LifecycleStages.Rendered,re),$(0,v.Inject(d.DocSkeletonManagerService)),$(1,a.IUniverInstanceService),$(2,a.ICommandService),$(3,m.IRenderManagerService),$(4,v.Inject(d.TextSelectionManagerService)),$(5,l.IEditorService)],re);var mn=Object.defineProperty,vn=Object.getOwnPropertyDescriptor,Cn=(r,e,t,n)=>{for(var i=n>1?void 0:n?vn(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&mn(e,t,i),i},L=(r,e)=>(t,n)=>e(t,n,r);let oe=class extends a.Disposable{constructor(e,t,n,i,o,s,c){super();T(this,"_loadedMap",new WeakSet);this._docSkeletonManagerService=e,this._univerInstanceService=t,this._commandService=n,this._renderManagerService=i,this._textSelectionRenderManager=o,this._textSelectionManagerService=s,this._editorService=c,this._initialize()}_initialize(){this._init(),this._skeletonListener(),this._commandExecutedListener()}_init(){this.disposeWithMe(this._renderManagerService.currentRender$.subscribe(e=>{this._create(e)})),this._renderManagerService.getRenderAll().forEach((e,t)=>{this._create(t)})}_create(e){if(e==null||this._univerInstanceService.getUniverDocInstance(e)==null)return;const t=this._getDocObjectById(e);t==null||t.document==null||this._loadedMap.has(t.document)||(this._initialMain(e),this._loadedMap.add(t.document))}_initialMain(e){const t=this._getDocObjectById(e);if(t==null)return;const{document:n,scene:i}=t;this.disposeWithMe(a.toDisposable(n.onPointerEnterObserver.add(()=>{this._isEditorReadOnly(e)||(n.cursor=m.CURSOR_TYPE.TEXT)}))),this.disposeWithMe(a.toDisposable(n.onPointerLeaveObserver.add(()=>{n.cursor=m.CURSOR_TYPE.DEFAULT,i.resetCursor()}))),this.disposeWithMe(a.toDisposable(n==null?void 0:n.onPointerDownObserver.add((o,s)=>{if(this._isEditorReadOnly(e))return;const c=this._univerInstanceService.getCurrentUniverDocInstance();(c==null?void 0:c.getUnitId())!==e&&this._univerInstanceService.setCurrentUnitForType(e),this._textSelectionRenderManager.eventTrigger(o);const{offsetX:u,offsetY:g}=o;this._editorService.getEditor(e)&&(this._setEditorFocus(e),setTimeout(()=>{this._setEditorFocus(e),this._textSelectionRenderManager.setCursorManually(u,g)},0)),o.button!==2&&s.stopPropagation()}))),this.disposeWithMe(a.toDisposable(n==null?void 0:n.onDblclickObserver.add(o=>{this._isEditorReadOnly(e)||this._textSelectionRenderManager.handleDblClick(o)}))),this.disposeWithMe(a.toDisposable(n==null?void 0:n.onTripleClickObserver.add(o=>{this._isEditorReadOnly(e)||this._textSelectionRenderManager.handleTripleClick(o)})))}_isEditorReadOnly(e){const t=this._editorService.getEditor(e);return t?t.isReadOnly():!1}_setEditorFocus(e){if(this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).length>0){const n=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);this._editorService.setOperationSheetUnitId(n.getUnitId())}this._editorService.focusStyle(e)}_commandExecutedListener(){const e=[d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const i=t.params,{unitId:o}=i,s=(n=this._textSelectionManagerService.getCurrentSelection())==null?void 0:n.unitId;if(o!==s)return;this._textSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t,skeleton:n}=e,i=this._renderManagerService.getRenderById(t);if(i==null)return;const{scene:o,mainComponent:s}=i;this._textSelectionRenderManager.changeRuntime(n,o,s),this._textSelectionManagerService.setCurrentSelectionNotRefresh({unitId:t,subUnitId:""})}))}_getDocObjectById(e){return this._univerInstanceService.getUnitType(e)!==a.UniverInstanceType.UNIVER_DOC?null:d.getDocObjectById(e,this._renderManagerService)}};oe=Cn([a.OnLifecycle(a.LifecycleStages.Rendered,oe),L(0,v.Inject(d.DocSkeletonManagerService)),L(1,a.IUniverInstanceService),L(2,a.ICommandService),L(3,m.IRenderManagerService),L(4,m.ITextSelectionRenderManager),L(5,v.Inject(d.TextSelectionManagerService)),L(6,l.IEditorService)],oe);var In=Object.defineProperty,On=Object.getOwnPropertyDescriptor,Tn=(r,e,t,n)=>{for(var i=n>1?void 0:n?On(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&In(e,t,i),i},Y=(r,e)=>(t,n)=>e(t,n,r);const we=1.5;let se=class extends a.RxDisposable{constructor(r,e,t,n,i){super(),this._docSkeletonManagerService=r,this._textSelectionManagerService=e,this._editorService=t,this._univerInstanceService=n,this._renderManagerService=i,this._init()}_init(){this._textSelectionManagerService.textSelection$.pipe(b.takeUntil(this.dispose$)).subscribe(r=>{if(r==null)return;const{isEditing:e,unitId:t}=r;e&&this._scrollToSelection(t)})}_scrollToSelection(r){var R;const e=this._textSelectionManagerService.getActiveRange(),t=this._getDocObject(),n=(R=this._docSkeletonManagerService.getCurrent())==null?void 0:R.skeleton;if(e==null||t==null||n==null)return;const{collapsed:i,startNodePosition:o}=e;if(!i)return;const s=t.document.getOffsetConfig(),{docsLeft:c,docsTop:u}=s,g=new m.NodePositionConvertToCursor(s,n),{contentBoxPointGroup:p}=g.getRangePointData(o,o),{left:_,top:C,height:f}=m.getAnchorBounding(p),I=_+c,h=C+u,O=t.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN),M=!!this._editorService.getEditor(r);if(O==null)return;const{left:y,top:D,right:P,bottom:N}=O.getBounding().viewBound;let w=0,j=0;const le=M?0:100;h<D?w=h-D:h>N-f&&(w=h-N+f+le),I<y?j=I-y:I>P-we&&(j=I-P+we);const de=O.getBarScroll(j,w);O.scrollBy(de)}_getDocObject(){return d.getDocObject(this._univerInstanceService,this._renderManagerService)}};se=Tn([a.OnLifecycle(a.LifecycleStages.Rendered,se),Y(0,v.Inject(d.DocSkeletonManagerService)),Y(1,v.Inject(d.TextSelectionManagerService)),Y(2,l.IEditorService),Y(3,a.IUniverInstanceService),Y(4,m.IRenderManagerService)],se);var bn=Object.defineProperty,Mn=Object.getOwnPropertyDescriptor,yn=(r,e,t,n)=>{for(var i=n>1?void 0:n?Mn(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&bn(e,t,i),i},me=(r,e)=>(t,n)=>e(t,n,r);S.UniverDocsUIPlugin=(ce=class extends a.Plugin{constructor(e,t,n,i){super(),this._config=e,this._injector=t,this._localeService=n,this._logService=i,this._localeService.load({zhCN:Ue}),this._config=a.Tools.deepMerge({},Oe,this._config),this._initDependencies(t),this._initializeCommands()}onRendered(){this._initModules(),this._markDocAsFocused()}_initializeCommands(){[He,ze,Ge,Ye,Ke,Xe,qe,Ze,Je,Ft,$t,Bt].forEach(e=>{this._injector.get(l.IShortcutService).registerShortcut(e)})}_initDependencies(e){[[W,{useFactory:()=>this._injector.createInstance(W,this._config)}],[J],[Q],[te],[ie],[re],[oe],[se],[V,{useFactory:()=>this._injector.createInstance(V,this._config)}],[H,{useClass:Se}],[S.DocCanvasView]].forEach(n=>{e.add(n)})}_markDocAsFocused(){const e=this._injector.get(a.IUniverInstanceService),t=this._injector.get(l.IEditorService);try{const n=e.getCurrentUniverDocInstance();if(!n)return;const i=n.getUnitId();t.isEditor(i)||e.focusUnit(n.getUnitId())}catch(n){this._logService.warn(n)}}_initModules(){this._injector.get(V)}},T(ce,"pluginName",Te),T(ce,"type",a.UniverInstanceType.UNIVER_DOC),ce),S.UniverDocsUIPlugin=yn([me(1,v.Inject(v.Injector)),me(2,v.Inject(a.LocaleService)),me(3,a.ILogService)],S.UniverDocsUIPlugin),S.DOC_UI_PLUGIN_NAME=Te,S.DefaultDocContainerConfig=Ie,S.DefaultDocUiConfig=Oe,S.DefaultToolbarConfig=Ce,S.PastePluginLark=xe,S.PastePluginUniver=Be,S.PastePluginWord=Ae,S.enUS=Lt,S.ruRU=At,S.zhCN=Ue,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
|
|
9
|
+
*/var tt=Ve,nt=Symbol.for("react.element"),it=Symbol.for("react.fragment"),rt=Object.prototype.hasOwnProperty,ot=tt.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,st={key:!0,ref:!0,__self:!0,__source:!0};function Ee(n,e,t){var i,o={},r=null,s=null;t!==void 0&&(r=""+t),e.key!==void 0&&(r=""+e.key),e.ref!==void 0&&(s=e.ref);for(i in e)rt.call(e,i)&&!st.hasOwnProperty(i)&&(o[i]=e[i]);if(n&&n.defaultProps)for(i in e=n.defaultProps,e)o[i]===void 0&&(o[i]=e[i]);return{$$typeof:nt,type:n,key:r,ref:s,props:o,_owner:ot.current}}K.Fragment=it,K.jsx=Ee,K.jsxs=Ee,Re.exports=K;var at=Re.exports;const ct={docsUiCanvasBackground:"univer-docs-ui-canvas-background"},lt=()=>at.jsx("div",{className:ct.docsUiCanvasBackground});function dt(n){const e=n.get(a.ICommandService);return{id:d.SetInlineFormatBoldCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",positions:[l.MenuPosition.TOOLBAR_START],activated$:new M.Observable(t=>{const i=e.onCommandExecuted(o=>{var s;const r=o.id;if(r===d.SetTextSelectionsOperation.id||r===d.SetInlineFormatCommand.id){const c=E(n);if(c==null)return;const u=(s=c.ts)==null?void 0:s.bl;t.next(u===a.BooleanNumber.TRUE)}});return t.next(!1),i.dispose}),hidden$:l.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_DOC)}}function ut(n){const e=n.get(a.ICommandService);return{id:d.SetInlineFormatItalicCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",positions:[l.MenuPosition.TOOLBAR_START],activated$:new M.Observable(t=>{const i=e.onCommandExecuted(o=>{var s;const r=o.id;if(r===d.SetTextSelectionsOperation.id||r===d.SetInlineFormatCommand.id){const c=E(n);if(c==null)return;const u=(s=c.ts)==null?void 0:s.it;t.next(u===a.BooleanNumber.TRUE)}});return t.next(!1),i.dispose}),hidden$:l.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_DOC)}}function ht(n){const e=n.get(a.ICommandService);return{id:d.SetInlineFormatUnderlineCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",positions:[l.MenuPosition.TOOLBAR_START],activated$:new M.Observable(t=>{const i=e.onCommandExecuted(o=>{var s;const r=o.id;if(r===d.SetTextSelectionsOperation.id||r===d.SetInlineFormatCommand.id){const c=E(n);if(c==null)return;const u=(s=c.ts)==null?void 0:s.ul;t.next((u==null?void 0:u.s)===a.BooleanNumber.TRUE)}});return t.next(!1),i.dispose}),hidden$:l.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_DOC)}}function gt(n){const e=n.get(a.ICommandService);return{id:d.SetInlineFormatStrikethroughCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",positions:[l.MenuPosition.TOOLBAR_START],activated$:new M.Observable(t=>{const i=e.onCommandExecuted(o=>{var s;const r=o.id;if(r===d.SetTextSelectionsOperation.id||r===d.SetInlineFormatCommand.id){const c=E(n);if(c==null)return;const u=(s=c.ts)==null?void 0:s.st;t.next((u==null?void 0:u.s)===a.BooleanNumber.TRUE)}});return t.next(!1),i.dispose}),hidden$:l.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_DOC)}}function pt(n){const e=n.get(a.ICommandService);return{id:d.SetInlineFormatSubscriptCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",positions:[l.MenuPosition.TOOLBAR_START],activated$:new M.Observable(t=>{const i=e.onCommandExecuted(o=>{var s;const r=o.id;if(r===d.SetTextSelectionsOperation.id||r===d.SetInlineFormatCommand.id){const c=E(n);if(c==null)return;const u=(s=c.ts)==null?void 0:s.va;t.next(u===a.BaselineOffset.SUBSCRIPT)}});return t.next(!1),i.dispose}),hidden$:l.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_DOC)}}function _t(n){const e=n.get(a.ICommandService);return{id:d.SetInlineFormatSuperscriptCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",positions:[l.MenuPosition.TOOLBAR_START],activated$:new M.Observable(t=>{const i=e.onCommandExecuted(o=>{var s;const r=o.id;if(r===d.SetTextSelectionsOperation.id||r===d.SetInlineFormatCommand.id){const c=E(n);if(c==null)return;const u=(s=c.ts)==null?void 0:s.va;t.next(u===a.BaselineOffset.SUPERSCRIPT)}});return t.next(!1),i.dispose}),hidden$:l.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_DOC)}}function St(n){const e=n.get(a.ICommandService);return{id:d.SetInlineFormatFontFamilyCommand.id,tooltip:"toolbar.font",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,label:Me,positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_FAMILY_LIST.map(t=>({label:{name:ye,hoverable:!0},value:t.value})),value$:new M.Observable(t=>{const i=l.FONT_FAMILY_LIST[0].value,o=e.onCommandExecuted(r=>{var c;const s=r.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontFamilyCommand.id){const u=E(n);if(u==null)return;const h=(c=u.ts)==null?void 0:c.ff;t.next(h!=null?h:i)}});return t.next(i),o.dispose}),hidden$:l.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_DOC)}}function mt(n){const e=n.get(a.ICommandService);return{id:d.SetInlineFormatFontSizeCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:be,props:{min:1,max:400}},positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_SIZE_LIST,value$:new M.Observable(t=>{const o=e.onCommandExecuted(r=>{var c;const s=r.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontSizeCommand.id){const u=E(n);if(u==null)return;const h=(c=u.ts)==null?void 0:c.fs;t.next(h!=null?h:14)}});return t.next(14),o.dispose}),hidden$:l.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_DOC)}}function ft(n){const e=n.get(a.ICommandService),t=n.get(a.ThemeService);return{id:d.SetInlineFormatTextColorCommand.id,icon:"FontColor",tooltip:"toolbar.textColor.main",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON_SELECTOR,positions:[l.MenuPosition.TOOLBAR_START],selections:[{label:{name:ue,hoverable:!1}}],value$:new M.Observable(i=>{const o=t.getCurrentTheme().textColor,r=e.onCommandExecuted(s=>{if(s.id===d.SetInlineFormatTextColorCommand.id){const c=s.params.value;i.next(c!=null?c:o)}});return i.next(o),r.dispose}),hidden$:l.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_DOC)}}function vt(n){const e=n.get(a.ICommandService);return{id:d.AlignLeftCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"LeftJustifyingSingle",tooltip:"toolbar.alignLeft",positions:[l.MenuPosition.TOOLBAR_START],activated$:new M.Observable(t=>{const i=e.onCommandExecuted(o=>{var s;const r=o.id;if(r===d.SetTextSelectionsOperation.id||r===d.AlignOperationCommand.id){const c=X(n);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.LEFT)}});return t.next(!1),i.dispose}),hidden$:l.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_DOC)}}function It(n){const e=n.get(a.ICommandService);return{id:d.AlignCenterCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"HorizontallySingle",tooltip:"toolbar.alignCenter",positions:[l.MenuPosition.TOOLBAR_START],activated$:new M.Observable(t=>{const i=e.onCommandExecuted(o=>{var s;const r=o.id;if(r===d.SetTextSelectionsOperation.id||r===d.AlignOperationCommand.id){const c=X(n);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.CENTER)}});return t.next(!1),i.dispose}),hidden$:l.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_DOC)}}function Ct(n){const e=n.get(a.ICommandService);return{id:d.AlignRightCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"RightJustifyingSingle",tooltip:"toolbar.alignRight",positions:[l.MenuPosition.TOOLBAR_START],activated$:new M.Observable(t=>{const i=e.onCommandExecuted(o=>{var s;const r=o.id;if(r===d.SetTextSelectionsOperation.id||r===d.AlignOperationCommand.id){const c=X(n);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.RIGHT)}});return t.next(!1),i.dispose}),hidden$:l.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_DOC)}}function Tt(n){const e=n.get(a.ICommandService);return{id:d.AlignJustifyCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"AlignTextBothSingle",tooltip:"toolbar.alignJustify",positions:[l.MenuPosition.TOOLBAR_START],activated$:new M.Observable(t=>{const i=e.onCommandExecuted(o=>{var s;const r=o.id;if(r===d.SetTextSelectionsOperation.id||r===d.AlignOperationCommand.id){const c=X(n);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.JUSTIFIED)}});return t.next(!1),i.dispose}),hidden$:l.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_DOC)}}function Ot(n){return{id:d.OrderListCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"OrderSingle",tooltip:"toolbar.order",positions:[l.MenuPosition.TOOLBAR_START],hidden$:l.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_DOC)}}function Mt(n){return{id:d.BulletListCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"UnorderSingle",tooltip:"toolbar.unorder",positions:[l.MenuPosition.TOOLBAR_START],hidden$:l.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_DOC)}}function yt(n){return{id:d.ResetInlineFormatTextBackgroundColorCommand.id,type:l.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:d.SetInlineFormatTextBackgroundColorCommand.id}}function bt(n){const e=n.get(a.ICommandService),t=n.get(a.ThemeService);return{id:d.SetInlineFormatTextBackgroundColorCommand.id,tooltip:"toolbar.fillColor.main",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON_SELECTOR,positions:[l.MenuPosition.TOOLBAR_START],icon:"PaintBucket",selections:[{label:{name:ue,hoverable:!1}}],value$:new M.Observable(i=>{const o=t.getCurrentTheme().primaryColor,r=e.onCommandExecuted(s=>{if(s.id===d.SetInlineFormatTextBackgroundColorCommand.id){const c=s.params.value;i.next(c!=null?c:o)}});return i.next(o),r.dispose}),hidden$:l.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_DOC)}}function E(n){var u;const e=n.get(a.IUniverInstanceService),t=n.get(d.TextSelectionManagerService),i=e.getCurrentUniverDocInstance(),o=t.getActiveRange();if(i==null||o==null)return;const r=(u=i.getBody())==null?void 0:u.textRuns;if(r==null)return;const{startOffset:s}=o;let c;for(let h=0;h<r.length;h++){const p=r[h],_=r[h+1];if(_&&_.st===_.ed&&s===_.st){c=_;break}if(p.st<=s&&s<=p.ed){c=p;break}}return c}function X(n){var u;const e=n.get(a.IUniverInstanceService),t=n.get(d.TextSelectionManagerService),i=e.getCurrentUniverDocInstance(),o=t.getActiveRange();if(i==null||o==null)return;const r=(u=i.getBody())==null?void 0:u.paragraphs;if(r==null)return;const{startOffset:s}=o;let c=-1;for(const h of r){const{startIndex:p}=h;if(s>c&&s<=p)return h;c=p}return null}var Rt=(n,e,t,i)=>{for(var o=e,r=n.length-1,s;r>=0;r--)(s=n[r])&&(o=s(o)||o);return o},U=(n,e)=>(t,i)=>e(t,i,n);let F=class extends a.Disposable{constructor(n,e,t,i,o,r,s,c){super(),this._config=n,this._injector=e,this._componentManager=t,this._layoutService=i,this._editorService=o,this._menuService=r,this._uiPartsService=s,this._univerInstanceService=c,this._init()}_initCustomComponents(){const n=this._componentManager;this.disposeWithMe(n.register(ue,We.ColorPicker)),this.disposeWithMe(n.register(Me,l.FontFamily)),this.disposeWithMe(n.register(ye,l.FontFamilyItem)),this.disposeWithMe(n.register(be,l.FontSize))}_initMenus(){const{menu:n={}}=this._config;[dt,ut,ht,gt,pt,_t,mt,St,ft,vt,It,Ct,Tt,Ot,Mt,yt,bt].forEach(e=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e),n))})}_init(){this._initCustomComponents(),this._initMenus(),this._initDocBackground(),this._initFocusHandler()}_initDocBackground(){const n=this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC)[0].getUnitId();if(n==null)return;this._editorService.isEditor(n)||this.disposeWithMe(this._uiPartsService.registerComponent(l.BuiltInUIPart.CONTENT,()=>$e.connectInjector(lt,this._injector)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(a.UniverInstanceType.UNIVER_DOC,()=>{this._injector.get(f.ITextSelectionRenderManager).focus()}))}};F=Rt([a.OnLifecycle(a.LifecycleStages.Rendered,F),U(1,v.Inject(v.Injector)),U(2,v.Inject(l.ComponentManager)),U(3,l.ILayoutService),U(4,l.IEditorService),U(5,l.IMenuService),U(6,l.IUIPartsService),U(7,a.IUniverInstanceService)],F);const Et={id:d.BreakLineCommand.id,preconditions:je,binding:l.KeyCode.ENTER},Dt={id:d.DeleteLeftCommand.id,preconditions:R,binding:l.KeyCode.BACKSPACE},Ut={id:d.DeleteRightCommand.id,preconditions:R,binding:l.KeyCode.DELETE},Nt=10,xt=6;function Pt(){return a.Tools.generateRandomId(xt)}function Lt(n){const e=n.match(/data-copy-id="([^\s]+)"/);return e&&e[1]?e[1]:null}class At{constructor(){O(this,"_cache",new a.LRUMap(Nt))}set(e,t){this._cache.set(e,t)}get(e){return this._cache.get(e)}clear(){this._cache.clear()}}const De=new At;function he(n){const e=n.style,t={},i=n.tagName.toLowerCase();switch(i){case"b":case"em":case"strong":{t.bl=a.BooleanNumber.TRUE;break}case"s":{t.st={s:a.BooleanNumber.TRUE};break}case"u":{t.ul={s:a.BooleanNumber.TRUE};break}case"i":{t.it=a.BooleanNumber.TRUE;break}case"sub":case"sup":{t.va=i==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}for(let o=0;o<e.length;o++){const r=e[o],s=e.getPropertyValue(r);switch(r){case"font-family":{t.ff=s;break}case"font-size":{const c=Number.parseInt(s);Number.isNaN(c)||(s.endsWith("pt")?t.fs=c:s.endsWith("px")&&(t.fs=f.pixelToPt(c)));break}case"font-style":{s==="italic"&&(t.it=a.BooleanNumber.TRUE);break}case"font-weight":{Number(s)>400&&(t.bl=a.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(s)?t.ul={s:a.BooleanNumber.TRUE}:/overline/.test(s)?t.ol={s:a.BooleanNumber.TRUE}:/line-through/.test(s)&&(t.st={s:a.BooleanNumber.TRUE});break}case"color":{const c=new a.ColorKit(s);c.isValid&&(t.cl={rgb:c.toRgbString()});break}case"background-color":{const c=new a.ColorKit(s);c.isValid&&(t.bg={rgb:c.toRgbString()});break}}}return t}function Bt(n){const e=new DOMParser,t=`<x-univer id="univer-root">${n}</x-univer>`;return e.parseFromString(t,"text/html").querySelector("#univer-root")}function Ue(n,e){const t=n.tagName.toLowerCase();return typeof e=="string"?t===e:Array.isArray(e)?e.some(i=>i===t):e(n)}const ce=class ce{constructor(){O(this,"_styleCache",new Map);O(this,"_styleRules",[]);O(this,"_afterProcessRules",[])}static use(e){if(this._pluginList.includes(e))throw new Error(`Univer paste plugin ${e.name} already added`);this._pluginList.push(e)}convert(e){const t=ce._pluginList.find(r=>r.checkPasteType(e)),i=Bt(e),o={dataStream:"",textRuns:[]};return t&&(this._styleRules=[...t.stylesRules],this._afterProcessRules=[...t.afterProcessRules]),this._styleCache.clear(),this._process(null,i==null?void 0:i.childNodes,o),this._styleCache.clear(),this._styleRules=[],this._afterProcessRules=[],o}_process(e,t,i){var o;for(const r of t)if(r.nodeType===Node.TEXT_NODE){const s=(o=r.nodeValue)==null?void 0:o.replace(/[\r\n]/g,"");let c;e&&this._styleCache.has(e)&&(c=this._styleCache.get(e)),i.dataStream+=s,c&&Object.getOwnPropertyNames(c).length&&i.textRuns.push({st:i.dataStream.length-s.length,ed:i.dataStream.length,ts:c})}else if(r.nodeType===Node.ELEMENT_NODE){const s=e?this._styleCache.get(e):{},c=this._styleRules.find(({filter:_})=>Ue(r,_)),u=c?c.getStyle(r):he(r);this._styleCache.set(r,{...s,...u});const{childNodes:h}=r;this._process(r,h,i);const p=this._afterProcessRules.find(({filter:_})=>Ue(r,_));p&&p.handler(i,r)}}};O(ce,"_pluginList",[]);let P=ce;const Ne={name:"univer-doc-paste-plugin-lark",checkPasteType(n){return/lark-record-clipboard/i.test(n)},stylesRules:[{filter:["s"],getStyle(n){const e=he(n);return{st:{s:a.BooleanNumber.TRUE},...e}}}],afterProcessRules:[{filter(n){return n.tagName==="DIV"&&/ace-line/i.test(n.className)},handler(n){n.paragraphs==null&&(n.paragraphs=[]),n.paragraphs.push({startIndex:n.dataStream.length}),n.dataStream+="\r"}}]};function xe(n){const e=n.style,t={};for(let i=0;i<e.length;i++){const o=e[i],r=e.getPropertyValue(o);switch(o){case"margin-top":{const s=Number.parseInt(r);t.spaceAbove=/pt/.test(r)?f.ptToPixel(s):s;break}case"margin-bottom":{const s=Number.parseInt(r);t.spaceBelow=/pt/.test(r)?f.ptToPixel(s):s;break}case"line-height":{const s=Number.parseFloat(r);t.lineSpacing=s;break}}}return Object.getOwnPropertyNames(t).length?t:null}const Pe={name:"univer-doc-paste-plugin-word",checkPasteType(n){return/word|mso/i.test(n)},stylesRules:[{filter:["b"],getStyle(n){const e=he(n);return{bl:a.BooleanNumber.TRUE,...e}}}],afterProcessRules:[{filter(n){return n.tagName==="P"&&/mso/i.test(n.className)},handler(n,e){n.paragraphs==null&&(n.paragraphs=[]);const t={startIndex:n.dataStream.length},i=xe(e);i&&(t.paragraphStyle=i),n.paragraphs.push(t),n.dataStream+="\r"}}]},Le={name:"univer-doc-paste-plugin-univer",checkPasteType(n){return/UniverNormal/i.test(n)},stylesRules:[],afterProcessRules:[{filter(n){return n.tagName==="P"&&/UniverNormal/i.test(n.className)},handler(n,e){n.paragraphs==null&&(n.paragraphs=[]);const t={startIndex:n.dataStream.length},i=xe(e);i&&(t.paragraphStyle=i),n.paragraphs.push(t),n.dataStream+="\r"}}]};function Ae(n,e){const{st:t,ed:i,ts:o={}}=e,{ff:r,fs:s,it:c,bl:u,ul:h,st:p,ol:_,bg:C,cl:m,va:I}=o;let g=n.slice(t,i);const T=[];return c===a.BooleanNumber.TRUE&&(g=`<i>${g}</i>`),I===a.BaselineOffset.SUPERSCRIPT?g=`<sup>${g}</sup>`:I===a.BaselineOffset.SUBSCRIPT&&(g=`<sub>${g}</sub>`),(h==null?void 0:h.s)===a.BooleanNumber.TRUE&&(g=`<u>${g}</u>`),(p==null?void 0:p.s)===a.BooleanNumber.TRUE&&(g=`<s>${g}</s>`),u===a.BooleanNumber.TRUE&&(g=`<strong>${g}</strong>`),r&&T.push(`font-family: ${r}`),m&&T.push(`color: ${m.rgb}`),s&&T.push(`font-size: ${s}pt`),_&&T.push("text-decoration: overline"),C&&T.push(`background: ${C.rgb}`),T.length?`<span style="${T.join("; ")};">${g}</span>`:g}function ge(n,e,t){const{dataStream:i,textRuns:o=[]}=n;let r=e;const s=[];for(const c of o){const{st:u,ed:h}=c;a.Tools.hasIntersectionBetweenTwoRanges(e,t,u,h)&&(u>r?(s.push(i.slice(r,u)),s.push(Ae(i,{...c,ed:Math.min(h,t)}))):s.push(Ae(i,{...c,st:r,ed:Math.min(h,t)}))),r=Math.max(e,Math.min(h,t))}return r!==t&&s.push(i.slice(r,t)),s.join("")}function Be(n,e=!0){var t;if(e&&((t=n.paragraphs)!=null&&t.length)){const{dataStream:i,paragraphs:o=[]}=n;let r="",s=-1;for(const c of o){const{startIndex:u,paragraphStyle:h={}}=c,{spaceAbove:p,spaceBelow:_,lineSpacing:C}=h,m=[];p!=null&&(typeof p=="number"?m.push(`margin-top: ${p}px`):m.push(`margin-top: ${p.v}px`)),_!=null&&(typeof _=="number"?m.push(`margin-bottom: ${_}px`):m.push(`margin-bottom: ${_.v}px`)),C!=null&&m.push(`line-height: ${C}`),u>s+1?r+=`<p class="UniverNormal" ${m.length?`style="${m.join("; ")};"`:""}>${ge(n,s+1,u)}</p>`:r+=`<p class="UniverNormal" ${m.length?`style="${m.join("; ")};"`:""}></p>`,s=u}return s!==i.length&&(r+=ge(n,s,i.length)),r}else return ge(n,0,n.dataStream.length)}class kt{convert(e){if(e.length===0)throw new Error("The bodyList length at least to be 1");if(e.length===1)return Be(e[0]);let t="";for(const i of e)t+='<p className="UniverNormal">',t+=Be(i,!1),t+="</p>";return t}}var Ft=(n,e,t,i)=>{for(var o=e,r=n.length-1,s;r>=0;r--)(s=n[r])&&(o=s(o)||o);return o},w=(n,e)=>(t,i)=>e(t,i,n);P.use(Pe),P.use(Ne),P.use(Le);function wt(n){const e=n.replace(/\n/g,"\r"),t=[];for(let i=0;i<e.length;i++)e[i]==="\r"&&t.push({startIndex:i});return{dataStream:e,paragraphs:t}}const $=v.createIdentifier("doc.clipboard-service");let pe=class extends a.Disposable{constructor(e,t,i,o,r){super();O(this,"_clipboardHooks",[]);O(this,"_htmlToUDM",new P);O(this,"_umdToHtml",new kt);this._univerInstanceService=e,this._logService=t,this._commandService=i,this._clipboardInterfaceService=o,this._textSelectionManagerService=r}async copy(){const e=this._getDocumentBodyInRanges();if(e.length===0)return!1;try{this._setClipboardData(e)}catch(t){return this._logService.error("[DocClipboardService] copy failed",t),!1}return!0}async cut(){return this._cut()}async paste(e){const t=await this._generateBodyFromClipboardItems(e);return this._paste(t)}async legacyPaste(e,t){const i=this._generateBodyFromHtmlAndText(e,t);return this._paste(i)}async _cut(){var r;const{segmentId:e,endOffset:t,style:i}=(r=this._textSelectionManagerService.getActiveRange())!=null?r:{},o=this._textSelectionManagerService.getSelections();if(e==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),t==null||o==null)return!1;this.copy();try{let s=t;for(const u of o){const{startOffset:h,endOffset:p}=u;h==null||p==null||p<=t&&(s-=p-h)}const c=[{startOffset:s,endOffset:s,style:i}];return this._commandService.executeCommand(d.CutContentCommand.id,{segmentId:e,textRanges:c})}catch{return this._logService.error("[DocClipboardController] cut content failed"),!1}}async _paste(e){var s;const{segmentId:t,endOffset:i,style:o}=(s=this._textSelectionManagerService.getActiveRange())!=null?s:{},r=this._textSelectionManagerService.getSelections();if(t==null&&this._logService.error("[DocClipboardController] segmentId does not exist!"),i==null||r==null)return!1;try{let c=i;for(const h of r){const{startOffset:p,endOffset:_}=h;p==null||_==null||_<=i&&(c+=e.dataStream.length-(_-p))}const u=[{startOffset:c,endOffset:c,style:o}];return this._commandService.executeCommand(d.InnerPasteCommand.id,{body:e,segmentId:t,textRanges:u})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(e){const t=Pt(),i=e.length>1?e.map(r=>r.dataStream).join(`
|
|
10
|
+
`):e[0].dataStream;let o=this._umdToHtml.convert(e);return e.length===1&&(o=o.replace(/(<[a-z]+)/,(r,s)=>`${s} data-copy-id="${t}"`),De.set(t,e[0])),this._clipboardInterfaceService.write(i,o)}addClipboardHook(e){return this._clipboardHooks.push(e),a.toDisposable(()=>{const t=this._clipboardHooks.indexOf(e);t>-1&&this._clipboardHooks.splice(t,1)})}_getDocumentBodyInRanges(){const e=this._textSelectionManagerService.getSelections(),t=this._univerInstanceService.getCurrentUniverDocInstance(),i=[];if(e==null||!t)return i;for(const o of e){const{startOffset:r,endOffset:s,collapsed:c}=o;if(c||r==null||s==null)continue;const u=t.sliceBody(r,s);u!=null&&i.push(u)}return i}async _generateBodyFromClipboardItems(e){try{let t="",i="";for(const o of e)for(const r of o.types)r===l.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?i=await o.getType(r).then(s=>s&&s.text()):r===l.HTML_CLIPBOARD_MIME_TYPE&&(t=await o.getType(r).then(s=>s&&s.text()));return this._generateBodyFromHtmlAndText(t,i)}catch(t){return Promise.reject(t)}}_generateBodyFromHtmlAndText(e,t){if(!e){if(t)return wt(t);throw new Error("[DocClipboardService] html and text cannot be both empty!")}const i=Lt(e);if(i){const o=De.get(i);if(o)return o}return this._htmlToUDM.convert(e)}};pe=Ft([w(0,a.IUniverInstanceService),w(1,a.ILogService),w(2,a.ICommandService),w(3,l.IClipboardInterfaceService),w(4,v.Inject(d.TextSelectionManagerService))],pe);function q(n){return n.getContextValue(a.FOCUSING_DOC)||n.getContextValue(a.EDITOR_ACTIVATED)}const _e=999,$t={id:l.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:_e,preconditions:q,handler:async n=>n.get($).copy()},Vt={id:l.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:_e,preconditions:q,handler:async n=>n.get($).cut()},Wt={id:l.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:_e,preconditions:q,handler:async n=>{const e=n.get($),i=await n.get(l.IClipboardInterfaceService).read();return i.length===0?!1:e.paste(i)}};var jt=(n,e,t,i)=>{for(var o=e,r=n.length-1,s;r>=0;r--)(s=n[r])&&(o=s(o)||o);return o},V=(n,e)=>(t,i)=>e(t,i,n);let Z=class extends a.RxDisposable{constructor(n,e,t,i,o){super(),this._commandService=n,this._clipboardInterfaceService=e,this._docClipboardService=t,this._textSelectionRenderManager=i,this._contextService=o,this._init()}_init(){[$t,Vt,Wt].forEach(n=>this.disposeWithMe(this._commandService.registerMultipleCommand(n))),[d.InnerPasteCommand,d.CutContentCommand].forEach(n=>this.disposeWithMe(this._commandService.registerCommand(n))),this._initLegacyPasteCommand()}_initLegacyPasteCommand(){var n;(n=this._textSelectionRenderManager)==null||n.onPaste$.pipe(M.takeUntil(this.dispose$)).subscribe(e=>{var r,s;if(!q(this._contextService))return;e.event.preventDefault();const t=e.event,i=(r=t.clipboardData)==null?void 0:r.getData("text/html"),o=(s=t.clipboardData)==null?void 0:s.getData("text/plain");this._docClipboardService.legacyPaste(i,o)})}};Z=jt([a.OnLifecycle(a.LifecycleStages.Rendered,Z),V(0,a.ICommandService),V(1,l.IClipboardInterfaceService),V(2,$),V(3,f.ITextSelectionRenderManager),V(4,a.IContextService)],Z);var Ht=(n,e,t,i)=>{for(var o=e,r=n.length-1,s;r>=0;r--)(s=n[r])&&(o=s(o)||o);return o},L=(n,e)=>(t,i)=>e(t,i,n);let J=class extends a.Disposable{constructor(e,t,i,o,r,s){super();O(this,"_initialEditors",new Set);this._univerInstanceService=e,this._docSkeletonManagerService=t,this._editorService=i,this._commandService=o,this._textSelectionRenderManager=r,this._renderManagerService=s,this._initialize()}_initialize(){this.disposeWithMe(this._editorService.resize$.subscribe(e=>{this._resize(e)})),this._editorService.getAllEditor().forEach(e=>{const t=e.editorUnitId;this._initialEditors.has(t)||(this._initialEditors.add(t),this._resize(t))}),this._commandExecutedListener(),this._initialSetValue(),this._initialBlur(),this._initialFocus(),this._initialValueChange()}_resize(e){var D,B,x;if(e==null)return;const t=this._editorService.getEditor(e);if((t==null?void 0:t.cancelDefaultResizeListener)===!0)return;const i=(D=this._docSkeletonManagerService.getSkeletonByUnitId(e))==null?void 0:D.skeleton,o=this._univerInstanceService.getUniverDocInstance(e);if(t==null||t.render==null||i==null||o==null)return;i.calculate();const{marginTop:r=0,marginBottom:s=0,marginLeft:c=0,marginRight:u=0}=o.getSnapshot().documentStyle,{scene:h,mainComponent:p}=t.render;let{actualHeight:_,actualWidth:C}=i.getActualSize();_+=r+s,C+=c+u;const{width:m,height:I}=t.getBoundingClientRect(),g=h.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);let T=g==null?void 0:g.getScrollBar();const y=Math.max(C,m),b=Math.max(_,I);h.transformByState({width:y,height:b}),p==null||p.resize(y,b),t.isSingle()?C>m?T==null?g&&new f.ScrollBar(g,{barSize:8,enableVertical:!1}):g==null||g.resetSizeAndScrollBar():(T=null,g==null||g.scrollTo({x:0,y:0}),(x=g==null?void 0:g.getScrollBar())==null||x.dispose()):_>I?T==null?g&&new f.ScrollBar(g,{enableHorizontal:!1,barSize:8}):g==null||g.resetSizeAndScrollBar():(T=null,g==null||g.scrollTo({x:0,y:0}),(B=g==null?void 0:g.getScrollBar())==null||B.dispose())}_initialSetValue(){this.disposeWithMe(this._editorService.setValue$.subscribe(e=>{this._commandService.executeCommand(d.CoverContentCommand.id,{unitId:e.editorUnitId,body:e.body,segmentId:null})}))}_initialBlur(){this.disposeWithMe(this._editorService.blur$.subscribe(()=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.blur()})),this.disposeWithMe(this._textSelectionRenderManager.onBlur$.subscribe(()=>{var o;const e=(o=this._univerInstanceService.getCurrentUniverDocInstance())==null?void 0:o.getUnitId();if(e==null)return;const t=this._editorService.getEditor(e),i=this._editorService.getFocusEditor();t==null||t.isSheetEditor()||i&&i.editorUnitId===e||this._editorService.blur()}))}_initialFocus(){this.disposeWithMe(this._editorService.focus$.subscribe(i=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges([i])}));const e=["univer-formula-search","univer-formula-help","formula-help-decorator","univer-formula-help-param"];this.disposeWithMe(M.fromEvent(window,"mousedown").subscribe(i=>{const r=i.target.classList[0]||"";if(a.checkForSubstrings(r,e)){this._editorService.changeSpreadsheetFocusState(!0),i.stopPropagation();return}this._editorService.changeSpreadsheetFocusState(!1)})),this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(i=>{const o=i.getUnitId(),r=this._renderManagerService.getRenderById(o),s=r==null?void 0:r.engine.getCanvas().getCanvasEle();s!=null&&M.fromEvent(s,"mousedown").subscribe(c=>{this._editorService.changeSpreadsheetFocusState(!0),c.stopPropagation()})})}_initialValueChange(){this.disposeWithMe(this._textSelectionRenderManager.onCompositionupdate$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onInput$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onKeydown$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onPaste$.subscribe(this._valueChange.bind(this)))}_valueChange(){var i;const e=(i=this._univerInstanceService.getCurrentUniverDocInstance())==null?void 0:i.getUnitId();if(e==null)return;const t=this._editorService.getEditor(e);t==null||t.isSheetEditor()||this._editorService.refreshValueChange(e)}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id,l.SetEditorResizeOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const i=t.params,{unitId:o}=i;if(this._editorService.isSheetEditor(o))return;this._resize(o),this._valueChange()}}))}};J=Ht([a.OnLifecycle(a.LifecycleStages.Rendered,J),L(0,a.IUniverInstanceService),L(1,v.Inject(d.DocSkeletonManagerService)),L(2,l.IEditorService),L(3,a.ICommandService),L(4,f.ITextSelectionRenderManager),L(5,f.IRenderManagerService)],J);var zt=(n,e,t,i)=>{for(var o=e,r=n.length-1,s;r>=0;r--)(s=n[r])&&(o=s(o)||o);return o},Q=(n,e)=>(t,i)=>e(t,i,n);let ee=class extends a.RxDisposable{constructor(e,t,i,o){super();O(this,"_docRenderMap",new Set);this._docSkeletonManagerService=e,this._renderManagerService=t,this._commandService=i,this._editorService=o,this._initialRenderRefresh(),this._commandExecutedListener()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(M.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)})}_create(e){if(e==null)return;const{skeleton:t,unitId:i}=e;let o=this._renderManagerService.getRenderById(i);o==null&&(this._renderManagerService.create(i),o=this._renderManagerService.getRenderById(i));const{mainComponent:r,components:s}=o,c=r,u=s.get(d.DOCS_VIEW_KEY.BACKGROUND);c.changeSkeleton(t),u.changeSkeleton(t),this._recalculateSizeBySkeleton(o,t)}_recalculateSizeBySkeleton(e,t){var C;const{mainComponent:i,scene:o,unitId:r,components:s}=e,c=i,u=s.get(d.DOCS_VIEW_KEY.BACKGROUND),h=(C=t.getSkeletonData())==null?void 0:C.pages;if(h==null)return;let p=0,_=0;for(let m=0,I=h.length;m<I;m++){const g=h[m],{pageWidth:T,pageHeight:y}=g;c.pageLayoutType===f.PageLayoutType.VERTICAL?(_+=y,_+=c.pageMarginTop,m===I-1&&(_+=c.pageMarginTop),p=Math.max(p,T)):c.pageLayoutType===f.PageLayoutType.HORIZONTAL&&(p+=T,m!==I-1&&(p+=c.pageMarginLeft),_=Math.max(_,y))}c.resize(p,_),u.resize(p,_),this._editorService.isEditor(r)||o.resize(p,_)}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var i;if(e.includes(t.id)){const o=t.params,{unitId:r}=o,s=this._docSkeletonManagerService.getSkeletonByUnitId(r);if(s==null)return;const{skeleton:c}=s,u=this._renderManagerService.getRenderById(r);if(u==null||!!c.getViewModel().getDataModel().getSnapshot().disabled)return;if(c.calculate(),this._editorService.isEditor(r)){(i=u.mainComponent)==null||i.makeDirty();return}this._recalculateSizeBySkeleton(u,c)}}))}};ee=zt([a.OnLifecycle(a.LifecycleStages.Rendered,ee),Q(0,v.Inject(d.DocSkeletonManagerService)),Q(1,f.IRenderManagerService),Q(2,a.ICommandService),Q(3,l.IEditorService)],ee);var Yt=(n,e,t,i)=>{for(var o=e,r=n.length-1,s;r>=0;r--)(s=n[r])&&(o=s(o)||o);return o},te=(n,e)=>(t,i)=>e(t,i,n);S.DocCanvasView=class extends a.RxDisposable{constructor(t,i,o,r){super();O(this,"_scene");O(this,"_currentDocumentModel");O(this,"_fps$",new M.BehaviorSubject(""));O(this,"fps$",this._fps$.asObservable());this._renderManagerService=t,this._configService=i,this._univerInstanceService=o,this._editorService=r,this._initialize()}_initialize(){this._renderManagerService.createRender$.pipe(M.takeUntil(this.dispose$)).subscribe(t=>{this._create(t)}),this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC).pipe(M.takeUntil(this.dispose$)).subscribe(t=>{this._create(t==null?void 0:t.getUnitId())}),this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC).forEach(t=>{this._create(t.getUnitId())})}dispose(){this._fps$.complete()}_create(t){if(t==null)return;const i=this._univerInstanceService.getUniverDocInstance(t);i!=null&&(this._currentDocumentModel=i,this._renderManagerService.has(t)||this._addNewRender())}_addNewRender(){const i=this._currentDocumentModel.getUnitId();this._renderManagerService.createRender(i);const o=this._renderManagerService.getRenderById(i);if(o==null)return;const{scene:r,engine:s}=o;this._scene=r;const c=new f.Viewport(d.VIEWPORT_KEY.VIEW_MAIN,r,{left:0,top:0,bottom:0,right:0,isRelativeX:!0,isRelativeY:!0,isWheelPreventDefaultX:!0});r.attachControl(),r.on(f.EVENT_TYPE.wheel,(p,_)=>{const C=p;if(C.ctrlKey){const m=Math.abs(C.deltaX);let I=m<40?.2:m<80?.4:.2;I*=C.deltaY>0?-1:1,r.scaleX<1&&(I/=2),r.scaleX+I>4?r.scale(4,4):r.scaleX+I<.1?r.scale(.1,.1):C.preventDefault()}else c.onMouseWheel(C,_)}),this._configService.getConfig("hasScroll")!==!1&&new f.ScrollBar(c),r.addLayer(new f.Layer(r,[],d.DOCS_COMPONENT_MAIN_LAYER_INDEX),new f.Layer(r,[],d.DOCS_COMPONENT_HEADER_LAYER_INDEX)),this._addComponent(o),this._currentDocumentModel.getShouldRenderLoopImmediately()&&s.runRenderLoop(()=>{r.render(),this._fps$.next(Math.round(s.getFps()).toString())}),this._renderManagerService.setCurrent(i)}_addComponent(t){const i=this._scene,o=this._currentDocumentModel,r={pageMarginLeft:o.documentStyle.marginLeft||0,pageMarginTop:o.documentStyle.marginTop||0},s=new f.Documents(d.DOCS_VIEW_KEY.MAIN,void 0,r),c=new f.DocBackground(d.DOCS_VIEW_KEY.BACKGROUND,void 0,r);s.zIndex=d.DOCS_COMPONENT_DEFAULT_Z_INDEX,c.zIndex=d.DOCS_COMPONENT_DEFAULT_Z_INDEX,t.mainComponent=s,t.components.set(d.DOCS_VIEW_KEY.MAIN,s),t.components.set(d.DOCS_VIEW_KEY.BACKGROUND,c),i.addObjects([s],d.DOCS_COMPONENT_MAIN_LAYER_INDEX),i.addObjects([c],d.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX),this._editorService.getEditor(o.getUnitId())==null&&i.enableLayerCache(d.DOCS_COMPONENT_MAIN_LAYER_INDEX)}},S.DocCanvasView=Yt([a.OnLifecycle(a.LifecycleStages.Starting,S.DocCanvasView),te(0,f.IRenderManagerService),te(1,a.IConfigService),te(2,a.IUniverInstanceService),te(3,l.IEditorService)],S.DocCanvasView);var Gt=(n,e,t,i)=>{for(var o=e,r=n.length-1,s;r>=0;r--)(s=n[r])&&(o=s(o)||o);return o},ne=(n,e)=>(t,i)=>e(t,i,n);let ie=class extends a.Disposable{constructor(e,t,i,o){super();O(this,"_liquid",new f.Liquid);O(this,"_pageMarginCache",new Map);this._docSkeletonManagerService=e,this._renderManagerService=t,this._commandService=i,this._editorService=o,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh(),this._updateOnPluginChange()}_updateOnPluginChange(){}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{skeleton:t,unitId:i}=e,o=this._renderManagerService.getRenderById(i);if(o==null)return;const{mainComponent:r}=o;r.changeSkeleton(t),this._refreshDrawing(i,t,o)})}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id,d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var i;if(e.includes(t.id)){const o=t.params,{unitId:r}=o,s=this._docSkeletonManagerService.getCurrent();if(s==null)return;const{unitId:c,skeleton:u}=s;if(r!==c)return;const h=this._renderManagerService.getRenderById(c);if(h==null)return;if(this._editorService.isEditor(c)){(i=h.mainComponent)==null||i.makeDirty();return}this._refreshDrawing(c,u,h)}}))}_refreshDrawing(e,t,i){const o=t==null?void 0:t.getSkeletonData(),{mainComponent:r,scene:s}=i,c=r;if(!o)return;const{left:u,top:h,pageLayoutType:p,pageMarginLeft:_,pageMarginTop:C}=c,{pages:m}=o,I=[];s.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let g=0,T=m.length;g<T;g++){const y=m[g],{skeDrawings:b,marginLeft:D,marginTop:B}=y;this._liquid.translatePagePadding(y),b.forEach(x=>{const{aLeft:j,aTop:H,height:me,width:fe,drawingId:z,drawingOrigin:we}=x,nn=we.layoutType===a.PositionedObjectLayoutType.WRAP_NONE&&we.behindDoc===a.BooleanNumber.TRUE;I.push({unitId:e,subUnitId:a.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:z,behindText:nn,floatingObject:{left:j+u+this._liquid.x,top:H+h+this._liquid.y,width:fe,height:me}}),this._pageMarginCache.set(z,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.restorePagePadding(y),this._liquid.translatePage(y,p,_,C)}}};ie=Gt([a.OnLifecycle(a.LifecycleStages.Steady,ie),ne(0,v.Inject(d.DocSkeletonManagerService)),ne(1,f.IRenderManagerService),ne(2,a.ICommandService),ne(3,l.IEditorService)],ie);var Kt=(n,e,t,i)=>{for(var o=e,r=n.length-1,s;r>=0;r--)(s=n[r])&&(o=s(o)||o);return o},A=(n,e)=>(t,i)=>e(t,i,n);let re=class extends a.Disposable{constructor(e,t,i,o,r,s){super();O(this,"_initializedRender",new Set);this._docSkeletonManagerService=e,this._univerInstanceService=t,this._commandService=i,this._renderManagerService=o,this._textSelectionManagerService=r,this._editorService=s,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._initialRenderRefresh()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t}=e,i=this._renderManagerService.getRenderById(t);if(i==null||this._initializedRender.has(t)||this._editorService.isEditor(t))return;this._initializedRender.add(t);const{scene:o}=i;this.disposeWithMe(a.toDisposable(o.onMouseWheelObserver.add(r=>{if(!r.ctrlKey)return;const s=this._univerInstanceService.getCurrentUniverDocInstance();if(!s)return;const c=Math.abs(r.deltaX);let u=c<40?.2:c<80?.4:.2;u*=r.deltaY>0?-1:1,o.scaleX<1&&(u/=2);const h=s.zoomRatio;let p=+Number.parseFloat(`${h+u}`).toFixed(1);p=p>=4?4:p<=.1?.1:p,this._commandService.executeCommand(d.SetDocZoomRatioCommand.id,{zoomRatio:p,unitId:s.getUnitId()}),r.preventDefault()})))})}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const t=this._univerInstanceService.getCurrentUniverDocInstance();if(!t)return;const i=t.zoomRatio||1;this._updateViewZoom(i,!1)})))}_commandExecutedListener(){const e=[d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const i=this._univerInstanceService.getCurrentUniverDocInstance();if(!i)return;const o=t.params,{unitId:r}=o;if(r!==i.getUnitId())return;const s=i.zoomRatio||1;this._updateViewZoom(s)}}))}_updateViewZoom(e,t=!0){var o;const i=this._getDocObject();i!=null&&(i.scene.scale(e,e),this._calculatePagePosition(i,e),t&&this._textSelectionManagerService.refreshSelection(),(o=i.scene.getTransformer())==null||o.clearSelectedObjects())}_calculatePagePosition(e,t){const{document:i,scene:o,docBackground:r}=e,s=o==null?void 0:o.getParent(),{width:c,height:u,pageMarginLeft:h,pageMarginTop:p}=i;if(s==null||c===Number.POSITIVE_INFINITY||u===Number.POSITIVE_INFINITY)return;const{width:_,height:C}=s;let m=0,I=0,g=0,T=0,y=Number.POSITIVE_INFINITY;_>(c+h*2)*t?(m=_/2-c*t/2,m/=t,g=(_-h*2)/t,y=0):(m=h,g=c+h*2,y=(g-_/t)/2),C>u?(I=C/2-u/2,T=(C-p*2)/t):(I=p,T=u+p*2),o.resize(g,T+200),i.translate(m,I),r.translate(m,I);const b=o.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);if(y!==Number.POSITIVE_INFINITY&&b!=null){const D=b.getBarScroll(y,0).x;b.scrollTo({x:D})}return this}_getDocObject(){return d.getDocObject(this._univerInstanceService,this._renderManagerService)}};re=Kt([a.OnLifecycle(a.LifecycleStages.Rendered,re),A(0,v.Inject(d.DocSkeletonManagerService)),A(1,a.IUniverInstanceService),A(2,a.ICommandService),A(3,f.IRenderManagerService),A(4,v.Inject(d.TextSelectionManagerService)),A(5,l.IEditorService)],re);var Xt=(n,e,t,i)=>{for(var o=e,r=n.length-1,s;r>=0;r--)(s=n[r])&&(o=s(o)||o);return o},N=(n,e)=>(t,i)=>e(t,i,n);let oe=class extends a.Disposable{constructor(e,t,i,o,r,s,c){super();O(this,"_loadedMap",new WeakSet);this._docSkeletonManagerService=e,this._univerInstanceService=t,this._commandService=i,this._renderManagerService=o,this._textSelectionRenderManager=r,this._textSelectionManagerService=s,this._editorService=c,this._initialize()}_initialize(){this._init(),this._skeletonListener(),this._commandExecutedListener()}_init(){this.disposeWithMe(this._renderManagerService.currentRender$.subscribe(e=>{this._create(e)})),this._renderManagerService.getRenderAll().forEach((e,t)=>{this._create(t)})}_create(e){if(e==null||this._univerInstanceService.getUniverDocInstance(e)==null)return;const t=this._getDocObjectById(e);t==null||t.document==null||this._loadedMap.has(t.document)||(this._initialMain(e),this._loadedMap.add(t.document))}_initialMain(e){const t=this._getDocObjectById(e);if(t==null)return;const{document:i,scene:o}=t;this.disposeWithMe(a.toDisposable(i.onPointerEnterObserver.add(()=>{this._isEditorReadOnly(e)||(i.cursor=f.CURSOR_TYPE.TEXT)}))),this.disposeWithMe(a.toDisposable(i.onPointerLeaveObserver.add(()=>{i.cursor=f.CURSOR_TYPE.DEFAULT,o.resetCursor()}))),this.disposeWithMe(a.toDisposable(i==null?void 0:i.onPointerDownObserver.add((r,s)=>{if(this._isEditorReadOnly(e))return;const c=this._univerInstanceService.getCurrentUniverDocInstance();(c==null?void 0:c.getUnitId())!==e&&this._univerInstanceService.setCurrentUnitForType(e),this._textSelectionRenderManager.eventTrigger(r);const{offsetX:u,offsetY:h}=r;this._editorService.getEditor(e)&&(this._setEditorFocus(e),setTimeout(()=>{this._setEditorFocus(e),this._textSelectionRenderManager.setCursorManually(u,h)},0)),r.button!==2&&s.stopPropagation()}))),this.disposeWithMe(a.toDisposable(i==null?void 0:i.onDblclickObserver.add(r=>{this._isEditorReadOnly(e)||this._textSelectionRenderManager.handleDblClick(r)}))),this.disposeWithMe(a.toDisposable(i==null?void 0:i.onTripleClickObserver.add(r=>{this._isEditorReadOnly(e)||this._textSelectionRenderManager.handleTripleClick(r)})))}_isEditorReadOnly(e){const t=this._editorService.getEditor(e);return t?t.isReadOnly():!1}_setEditorFocus(e){if(this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).length>0){const i=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);this._editorService.setOperationSheetUnitId(i.getUnitId())}this._editorService.focusStyle(e)}_commandExecutedListener(){const e=[d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var i;if(e.includes(t.id)){const o=t.params,{unitId:r}=o,s=(i=this._textSelectionManagerService.getCurrentSelection())==null?void 0:i.unitId;if(r!==s)return;this._textSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t,skeleton:i}=e,o=this._renderManagerService.getRenderById(t);if(o==null)return;const{scene:r,mainComponent:s}=o;this._textSelectionRenderManager.changeRuntime(i,r,s),this._textSelectionManagerService.setCurrentSelectionNotRefresh({unitId:t,subUnitId:""})}))}_getDocObjectById(e){return this._univerInstanceService.getUnitType(e)!==a.UniverInstanceType.UNIVER_DOC?null:d.getDocObjectById(e,this._renderManagerService)}};oe=Xt([a.OnLifecycle(a.LifecycleStages.Rendered,oe),N(0,v.Inject(d.DocSkeletonManagerService)),N(1,a.IUniverInstanceService),N(2,a.ICommandService),N(3,f.IRenderManagerService),N(4,f.ITextSelectionRenderManager),N(5,v.Inject(d.TextSelectionManagerService)),N(6,l.IEditorService)],oe);var qt=(n,e,t,i)=>{for(var o=e,r=n.length-1,s;r>=0;r--)(s=n[r])&&(o=s(o)||o);return o},W=(n,e)=>(t,i)=>e(t,i,n);const ke=1.5;let se=class extends a.RxDisposable{constructor(n,e,t,i,o){super(),this._docSkeletonManagerService=n,this._textSelectionManagerService=e,this._editorService=t,this._univerInstanceService=i,this._renderManagerService=o,this._init()}_init(){this._textSelectionManagerService.textSelection$.pipe(M.takeUntil(this.dispose$)).subscribe(n=>{if(n==null)return;const{isEditing:e,unitId:t}=n;e&&this._scrollToSelection(t)})}_scrollToSelection(n){var z;const e=this._textSelectionManagerService.getActiveRange(),t=this._getDocObject(),i=(z=this._docSkeletonManagerService.getCurrent())==null?void 0:z.skeleton;if(e==null||t==null||i==null)return;const{collapsed:o,startNodePosition:r}=e;if(!o)return;const s=t.document.getOffsetConfig(),{docsLeft:c,docsTop:u}=s,h=new f.NodePositionConvertToCursor(s,i),{contentBoxPointGroup:p}=h.getRangePointData(r,r),{left:_,top:C,height:m}=f.getAnchorBounding(p),I=_+c,g=C+u,T=t.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN),y=!!this._editorService.getEditor(n);if(T==null)return;const{left:b,top:D,right:B,bottom:x}=T.getBounding().viewBound;let j=0,H=0;const me=y?0:100;g<D?j=g-D:g>x-m&&(j=g-x+m+me),I<b?H=I-b:I>B-ke&&(H=I-B+ke);const fe=T.getBarScroll(H,j);T.scrollBy(fe)}_getDocObject(){return d.getDocObject(this._univerInstanceService,this._renderManagerService)}};se=qt([a.OnLifecycle(a.LifecycleStages.Rendered,se),W(0,v.Inject(d.DocSkeletonManagerService)),W(1,v.Inject(d.TextSelectionManagerService)),W(2,l.IEditorService),W(3,a.IUniverInstanceService),W(4,f.IRenderManagerService)],se);var Zt=(n,e,t,i)=>{for(var o=e,r=n.length-1,s;r>=0;r--)(s=n[r])&&(o=s(o)||o);return o},ae=(n,e)=>(t,i)=>e(t,i,n);function Jt(n,e){const t=Fe(n.left,n.top,e),i=Fe(n.right,n.bottom,e);return{left:t.x,top:t.y,right:i.x,bottom:i.y}}function Fe(n,e,t){const{scaleX:i,scaleY:o}=t.getAncestorScale(),r=t.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);if(!r)return{x:n,y:e};const{viewportScrollX:s,viewportScrollY:c}=r,u=(n-s)*i,h=(e-c)*o;return{x:u,y:h}}S.DocCanvasPopManagerService=class extends a.Disposable{constructor(e,t,i,o){super(),this._globalPopupManagerService=e,this._renderManagerService=t,this._univerInstanceService=i,this._commandService=o}_createObjectPositionObserver(e,t){const i=()=>{const{scene:u}=t,{left:h,top:p,width:_,height:C}=e,m={left:h,right:h+_,top:p,bottom:p+C},I=Jt(m,u);return{left:I.left,right:I.right,top:I.top,bottom:I.bottom}},o=i(),r=new M.BehaviorSubject(o),s=new a.DisposableCollection;s.add(this._commandService.onCommandExecuted(u=>{u.id===d.SetDocZoomRatioOperation.id&&r.next(i())}));const c=t.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);return s.add(c==null?void 0:c.onScrollAfterObserver.add(()=>{r.next(i())})),{position:o,position$:r,disposable:s}}attachPopupToObject(e,t){const o=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC).getUnitId(),r=this._renderManagerService.getRenderById(o);if(!r)return{dispose:()=>{}};const{position:s,position$:c,disposable:u}=this._createObjectPositionObserver(e,r),h=this._globalPopupManagerService.addPopup({...t,unitId:o,subUnitId:"default",anchorRect:s,anchorRect$:c});return{dispose:()=>{this._globalPopupManagerService.removePopup(h),c.complete(),u.dispose()}}}},S.DocCanvasPopManagerService=Zt([ae(0,v.Inject(l.ICanvasPopupService)),ae(1,f.IRenderManagerService),ae(2,a.IUniverInstanceService),ae(3,a.ICommandService)],S.DocCanvasPopManagerService);var Qt=(n,e,t,i)=>{for(var o=e,r=n.length-1,s;r>=0;r--)(s=n[r])&&(o=s(o)||o);return o},Se=(n,e)=>(t,i)=>e(t,i,n);S.UniverDocsUIPlugin=(le=class extends a.Plugin{constructor(e,t,i,o){super(),this._config=e,this._injector=t,this._localeService=i,this._logService=o,this._config=a.Tools.deepMerge({},Ce,this._config),this._initDependencies(t),this._initializeCommands()}onRendered(){this._initModules(),this._markDocAsFocused()}_initializeCommands(){[He,ze,Ge,Ye,Ke,Xe,qe,Ze,Je,Dt,Ut,Et].forEach(e=>{this._injector.get(l.IShortcutService).registerShortcut(e)})}_initDependencies(e){[[F,{useFactory:()=>this._injector.createInstance(F,this._config)}],[Z],[J],[ee],[ie],[re],[oe],[se],[k,{useFactory:()=>this._injector.createInstance(k,this._config)}],[$,{useClass:pe}],[S.DocCanvasPopManagerService],[S.DocCanvasView]].forEach(i=>{e.add(i)})}_markDocAsFocused(){const e=this._injector.get(a.IUniverInstanceService),t=this._injector.get(l.IEditorService);try{const i=e.getCurrentUniverDocInstance();if(!i)return;const o=i.getUnitId();t.isEditor(o)||e.focusUnit(i.getUnitId())}catch(i){this._logService.warn(i)}}_initModules(){this._injector.get(k)}},O(le,"pluginName",Te),O(le,"type",a.UniverInstanceType.UNIVER_DOC),le),S.UniverDocsUIPlugin=Qt([Se(1,v.Inject(v.Injector)),Se(2,v.Inject(a.LocaleService)),Se(3,a.ILogService)],S.UniverDocsUIPlugin);function en(n){return{left:n.positionH.posOffset,top:n.positionV.posOffset,width:n.size.width,height:n.size.height}}function tn(n,e=0,t=0){return{size:{width:n.width,height:n.height},positionH:{relativeFrom:a.ObjectRelativeFromH.MARGIN,posOffset:(n.left||0)-e},positionV:{relativeFrom:a.ObjectRelativeFromV.PAGE,posOffset:(n.top||0)-t},angle:n.angle||0}}S.DOC_UI_PLUGIN_NAME=Te,S.DefaultDocContainerConfig=Ie,S.DefaultDocUiConfig=Ce,S.DefaultToolbarConfig=ve,S.PastePluginLark=Ne,S.PastePluginUniver=Le,S.PastePluginWord=Pe,S.docDrawingPositionToTransform=en,S.transformToDocDrawingPosition=tn,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs-ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13-nightly.202406041140",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer normal ui-plugin-docs",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"require": "./lib/cjs/*",
|
|
35
35
|
"types": "./lib/types/index.d.ts"
|
|
36
36
|
},
|
|
37
|
+
"./locale/*": "./lib/locale/*.json",
|
|
37
38
|
"./lib/*": "./lib/*"
|
|
38
39
|
},
|
|
39
40
|
"main": "./lib/cjs/index.js",
|
|
@@ -56,27 +57,27 @@
|
|
|
56
57
|
"@wendellhu/redi": "0.15.2",
|
|
57
58
|
"react": "^16.9.0 || ^17.0.0 || ^18.0.0",
|
|
58
59
|
"rxjs": ">=7.0.0",
|
|
59
|
-
"@univerjs/
|
|
60
|
-
"@univerjs/
|
|
61
|
-
"@univerjs/docs": "0.1.
|
|
62
|
-
"@univerjs/engine-render": "0.1.
|
|
63
|
-
"@univerjs/ui": "0.1.
|
|
60
|
+
"@univerjs/design": "0.1.13-nightly.202406041140",
|
|
61
|
+
"@univerjs/core": "0.1.13-nightly.202406041140",
|
|
62
|
+
"@univerjs/docs": "0.1.13-nightly.202406041140",
|
|
63
|
+
"@univerjs/engine-render": "0.1.13-nightly.202406041140",
|
|
64
|
+
"@univerjs/ui": "0.1.13-nightly.202406041140"
|
|
64
65
|
},
|
|
65
66
|
"devDependencies": {
|
|
66
|
-
"@types/react": "^18.
|
|
67
|
+
"@types/react": "^18.3.3",
|
|
67
68
|
"@wendellhu/redi": "0.15.2",
|
|
68
69
|
"less": "^4.2.0",
|
|
69
|
-
"react": "18.
|
|
70
|
+
"react": "18.3.1",
|
|
70
71
|
"rxjs": "^7.8.1",
|
|
71
72
|
"typescript": "^5.4.5",
|
|
72
|
-
"vite": "^5.2.
|
|
73
|
+
"vite": "^5.2.12",
|
|
73
74
|
"vitest": "^1.6.0",
|
|
74
|
-
"@univerjs/core": "0.1.
|
|
75
|
-
"@univerjs/
|
|
76
|
-
"@univerjs/
|
|
77
|
-
"@univerjs/shared": "0.1.
|
|
78
|
-
"@univerjs/ui": "0.1.
|
|
79
|
-
"@univerjs/
|
|
75
|
+
"@univerjs/core": "0.1.13-nightly.202406041140",
|
|
76
|
+
"@univerjs/design": "0.1.13-nightly.202406041140",
|
|
77
|
+
"@univerjs/docs": "0.1.13-nightly.202406041140",
|
|
78
|
+
"@univerjs/shared": "0.1.13",
|
|
79
|
+
"@univerjs/ui": "0.1.13-nightly.202406041140",
|
|
80
|
+
"@univerjs/engine-render": "0.1.13-nightly.202406041140"
|
|
80
81
|
},
|
|
81
82
|
"scripts": {
|
|
82
83
|
"test": "vitest run",
|